Planeshift

client.h

Go to the documentation of this file.
00001 /*
00002  * client.h - Author: Keith Fulton
00003  *
00004  * Copyright (C) 2001 Atomic Blue ([email protected], http://www.atomicblue.org)
00005  *
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation (version 2 of the License)
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00017  */
00018 
00019 #ifndef __CLIENT_H__
00020 #define __CLIENT_H__
00021 
00022 //=============================================================================
00023 // Crystal Space Includes
00024 //=============================================================================
00025 #include <csutil/ref.h>
00026 #include <csutil/csstring.h>
00027 #include <csutil/weakreferenced.h>
00028 
00029 //=============================================================================
00030 // Project Space Includes
00031 //=============================================================================
00032 #include "net/netbase.h"
00033 #include "util/psconst.h"
00034 #include "bulkobjects/buffable.h"
00035 
00036 //=============================================================================
00037 // Local Includes
00038 //=============================================================================
00039 
00040 class Client;
00041 class psCharacter;
00042 class gemObject;
00043 class gemActor;
00044 class gemNPC;
00045 class psPath;
00046 
00047 class FloodBuffRow
00048 {
00049 public:
00050     FloodBuffRow(uint8_t chtType, csString txt, csString rcpt, unsigned int newticks);
00051     FloodBuffRow() : chatType(0), ticks(0) {}
00052     uint8_t chatType;
00053     csString text;
00054     csString recipient;
00055     unsigned int ticks;
00056 };
00057 
00058 class MuteBuffable : public ClampedPositiveBuffable<int>
00059 {
00060 public:
00061     void Initialize(Client* c)
00062     {
00063         cli = c;
00064     }
00065 
00066 protected:
00067     Client* cli;
00068     virtual void OnChange();
00069 };
00070 
00071 enum TARGET_TYPES
00072 {
00073     TARGET_NONE     = 0x01, /* Also Area */
00074     TARGET_ITEM     = 0x04,
00075     TARGET_SELF     = 0x08,
00076     TARGET_FRIEND   = 0x10,
00077     TARGET_FOE      = 0x20,
00078     TARGET_DEAD     = 0x40
00079 };
00080 
00081 enum CheatFlags // will have more of these as Paladin gets better
00082 {
00083     NO_CHEAT   = 0x00,
00084     MOVE_CHEAT = 0x01
00085 };
00086 
00087 struct OrderedMessageChannel;
00088 
00095 class Client : protected NetBase::Connection, public CS::Utility::WeakReferenced
00096 {
00097 public:
00102     Client();
00103 
00104 
00105     ~Client();
00106 
00107     bool Initialize(LPSOCKADDR_IN addr, uint32_t clientnum);
00108     bool Disconnect();
00109 
00115     void SetAllowedToDisconnect(bool allowed);
00116 
00122     bool AllowDisconnect();
00123 
00126     bool ZombieAllowDisconnect();
00127 
00129     void SetMute(bool flag)
00130     {
00131         mute.SetBase(flag ? 1 : 0);
00132     }
00133     bool IsMute()
00134     {
00135         return (mute.Current() > 0);
00136     }
00137     MuteBuffable &GetBuffableMute()
00138     {
00139         return mute;
00140     }
00141 
00149     void SetName(const char* n);
00150 
00157     const char* GetName();
00158 
00159     // Additional Entity information
00160     void SetActor(gemActor* myactor);
00161     gemActor* GetActor() const
00162     {
00163         return actor;
00164     }
00165     psCharacter* GetCharacterData();
00166 
00167     // Get / Set Familiar information;
00168     void SetFamiliar(gemActor* familiar);
00169     gemActor* GetFamiliar();
00170 
00171     // Get / Set Pet information;
00172     void AddPet(gemActor* pet);
00173     void RemovePet(size_t index);
00174     gemActor* GetPet(size_t index);
00175     size_t GetNumPets();
00176 
00178     bool IsMyPet(gemActor* other) const;
00179 
00181     bool IsAlive() const;
00182 
00184     bool ValidateDistanceToTarget(float range);
00185 
00186     // Target information
00187     void SetTargetObject(gemObject* object, bool updateClientGUI=false);
00188     gemObject* GetTargetObject() const;
00189 
00190     // Targeted mesh information - i.e. for adding action locations
00191     void SetMesh(csString nextMesh)
00192     {
00193         mesh = nextMesh;
00194     }
00195     csString GetMesh() const
00196     {
00197         return mesh;
00198     }
00199 
00204     int GetTargetClientID();
00205 
00206     uint32_t GetClientNum() const
00207     {
00208         return clientnum;
00209     }
00210 
00212     AccountID GetAccountID()
00213     {
00214         return accountID;
00215     }
00216     void SetAccountID(AccountID id)
00217     {
00218         accountID = id;
00219     }
00220 
00222     PID GetPID()
00223     {
00224         return playerID;
00225     }
00226     void SetPID(PID id)
00227     {
00228         playerID = id;
00229     }
00230 
00231     int GetExchangeID()
00232     {
00233         return exchangeID;
00234     }
00235     void SetExchangeID(int ID)
00236     {
00237         exchangeID = ID;
00238     }
00239 
00241     int GetSecurityLevel() const
00242     {
00243         return securityLevel;
00244     }
00245     void SetSecurityLevel(int level)
00246     {
00247         securityLevel=level;
00248     }
00249 
00250     bool IsGM() const;
00251 
00253     int GetGuildID();
00255     int GetAllianceID();
00256 
00257     void SetReady(bool rdy)
00258     {
00259         ready = rdy;
00260     }
00261     bool IsReady()
00262     {
00263         return ready;
00264     }
00265 
00274     static void GetTargetTypeName(int32_t targetType, csString &targetDesc);
00275 
00280     bool IsZombie()
00281     {
00282         return zombie;
00283     }
00284 
00286     void SetSuperClient(bool flag)
00287     {
00288         superclient = flag;
00289     }
00290     bool IsSuperClient()
00291     {
00292         return superclient;
00293     }
00294     bool IsPlayerClient()
00295     {
00296         return (!superclient);
00297     }
00298 
00302     void GetIPAddress(char* addrStr, socklen_t size);
00303     csString GetIPAddress();
00304 
00305     csString GetIPRange(int octets=3);
00306 
00307     static csString GetIPRange(const char* ipaddr, int octets=3);
00308 
00309     NetBase::Connection* GetConnection() const
00310     {
00311         return (NetBase::Connection*)this;
00312     }
00313 
00314     const SOCKADDR_IN &GetAddress() const
00315     {
00316         return addr;
00317     }
00318 
00319     csRef<NetPacketQueueRefCount> outqueue;
00320 
00321     unsigned int GetAccountTotalOnlineTime();
00322 
00323     void AddDuelClient(uint32_t clientnum);
00324     void RemoveDuelClient(Client* client);
00325     void ClearAllDuelClients();
00326     int GetDuelClientCount();
00327     int GetDuelClient(int id);
00328     bool IsDuelClient(uint32_t clientnum);
00329     void AnnounceToDuelClients(gemActor* attacker, const char* event);
00330 
00332     void FloodControl(uint8_t chatType, const csString &newMessage, const csString &recipient);
00333 
00334     void SetAdvisorPoints(int p)
00335     {
00336         advisorPoints = p;
00337     }
00338     void IncrementAdvisorPoints(int n=1)
00339     {
00340         advisorPoints += n;
00341     }
00342     int GetAdvisorPoints()
00343     {
00344         return advisorPoints;
00345     }
00346 
00348     void SetAdvisor(bool advisor)
00349     {
00350         isAdvisor = advisor;
00351     }
00352     bool GetAdvisor()
00353     {
00354         return isAdvisor;
00355     }
00356     void SetAdvisorBan(bool ban);
00357     bool IsAdvisorBanned();
00358 
00360     csTicks accumulatedLag;
00361 
00362     // Invite flood control
00363     csTicks GetLastInviteTime()
00364     {
00365         return lastInviteTime;
00366     }
00367     void SetLastInviteTime(csTicks time)
00368     {
00369         lastInviteTime = time;
00370     }
00371     bool GetLastInviteResult()
00372     {
00373         return lastInviteResult;
00374     }
00375     void SetLastInviteResult(bool result)
00376     {
00377         lastInviteResult = result;
00378     }
00379     bool HasBeenWarned()
00380     {
00381         return hasBeenWarned;
00382     }
00383     void SetWarned()
00384     {
00385         hasBeenWarned = true;
00386     }
00387     bool HasBeenPenalized()
00388     {
00389         return hasBeenPenalized;
00390     }
00391     void SetPenalized(bool value)
00392     {
00393         hasBeenPenalized = value;
00394     }
00395     int GetSpamPoints()
00396     {
00397         return spamPoints;
00398     }
00399     void SetSpamPoints(int points)
00400     {
00401         spamPoints = points;    // For setting on account load
00402     }
00403     void IncrementSpamPoints()
00404     {
00405         if(spamPoints<4) spamPoints++;
00406     }
00407     void DecrementSpamPoints()
00408     {
00409         if(spamPoints>0) spamPoints--;
00410     }
00411 
00413     void WaypointSetPath(csString &path, int index)
00414     {
00415         waypointPathName = path;
00416         waypointPathIndex = index;
00417     }
00418     csString &WaypointGetPathName()
00419     {
00420         return waypointPathName;
00421     }
00422     int WaypointGetPathIndex()
00423     {
00424         return waypointPathIndex;
00425     }
00426     int WaypointGetNewPathIndex()
00427     {
00428         return waypointPathIndex++;
00429     }
00430 
00431     psPath* PathGetPath()
00432     {
00433         return pathPath;
00434     }
00435     void PathSetPath(psPath* path)
00436     {
00437         pathPath = path;
00438     }
00439 
00440     void PathSetIsDisplaying(iSector* sector);
00441     void PathClearDisplaying();
00442     csList<iSector*>::Iterator GetPathDisplaying();
00443     bool PathIsDisplaying();
00444 
00445     // Online edit of waypoints
00446     void WaypointSetIsDisplaying(iSector* sector);
00447     void WaypointClearDisplaying();
00448     csList<iSector*>::Iterator GetWaypointDisplaying();
00449     bool WaypointIsDisplaying();
00450 
00451 
00453     void LocationSetIsDisplaying(iSector* sector);
00454     void LocationClearDisplaying();
00455     csList<iSector*>::Iterator GetLocationDisplaying();
00456     bool LocationIsDisplaying();
00457 
00458     void SetSelectedLocationID(int id)
00459     {
00460         selectedLocationID = id;
00461     }
00462     int GetSelectedLocationID()
00463     {
00464         return selectedLocationID;
00465     }
00466 
00467 
00469     void CountDetectedCheat()
00470     {
00471         if(detectedCheatCount < 10000) detectedCheatCount++;
00472     }
00473     unsigned int GetDetectedCheatCount()
00474     {
00475         return detectedCheatCount;
00476     }
00478     void SetCheatMask(CheatFlags mask,bool flag);
00479     bool GetCheatMask(CheatFlags mask)
00480     {
00481         return (cheatMask & mask) != 0;
00482     }
00483 
00485     OrderedMessageChannel* GetOrderedMessageChannel(msgtype mtype);
00486 
00487     // FIXME: Ugly hack here as a temporary workaround for client-side issue that causes the server
00488     // to be flooded with inventory/glyph requests. Remove after all clients have been updated
00489     // to stop flooding.
00490     csTicks lastInventorySend;
00491     csTicks lastGlyphSend;
00492 
00494     void SetBuddyListHide(bool hide)
00495     {
00496         isBuddyListHiding = hide;
00497     }
00498     bool GetBuddyListHide()
00499     {
00500         return isBuddyListHiding;
00501     }
00502 
00503 protected:
00504 
00509     bool zombie;
00510     csTicks zombietimeout;
00511 
00517     bool allowedToDisconnect;
00518 
00520     int exchangeID;
00521 
00523     gemActor* actor;
00524 
00525     csArray<PID> pets;
00526     csString mesh;
00527     bool ready;
00528 
00530     csHash<OrderedMessageChannel*> orderedMessages;
00531 
00532     bool isAdvisor;         
00533 
00535     MuteBuffable mute;
00536 
00537     AccountID accountID;
00538     PID playerID;
00539     int  securityLevel;
00540     bool superclient;
00541     csArray<gemNPC*> listeningNpc;
00542     csString name;
00543 
00544     csArray<uint32_t> duel_clients;
00545 
00546     // Flood control
00547     static const int floodWarn = 3;                     
00548     static const int floodMax  = 5;                     
00549     static const unsigned int floodForgiveTime = 10000; 
00550     FloodBuffRow floodHistory[floodMax];
00551     int nextFloodHistoryIndex;
00552 
00553     int spamPoints;
00554     int advisorPoints;
00555 
00556     void SaveAccountData();
00557 
00558     // Invite flood
00559     csTicks lastInviteTime;
00560     bool lastInviteResult;
00561     bool hasBeenWarned;
00562     bool hasBeenPenalized;
00563 
00564     // Path edit global vars for client
00565     csString waypointPathName;
00566     int waypointPathIndex;
00567 
00568     psPath* pathPath;
00569 
00570     int selectedLocationID;
00571 
00573     csList<iSector*> waypointDisplaySectors;
00574     csList<iSector*> pathDisplaySectors;
00575     csList<iSector*> locationDisplaySectors;
00576 
00577 private:
00579     unsigned int detectedCheatCount;
00580 
00582     int cheatMask;
00583 
00585     bool isBuddyListHiding;
00586 };
00587 
00588 #endif