Planeshift
client.h
Go to the documentation of this file.
1 /*
2  * client.h - Author: Keith Fulton
3  *
4  * Copyright (C) 2001 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
5  *
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation (version 2 of the License)
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17  */
18 
19 #ifndef __CLIENT_H__
20 #define __CLIENT_H__
21 
22 //=============================================================================
23 // Crystal Space Includes
24 //=============================================================================
25 #include <csutil/ref.h>
26 #include <csutil/csstring.h>
27 #include <csutil/weakreferenced.h>
28 
29 //=============================================================================
30 // Project Space Includes
31 //=============================================================================
32 #include "net/netbase.h"
33 #include "util/psconst.h"
34 #include "bulkobjects/buffable.h"
35 
36 //=============================================================================
37 // Local Includes
38 //=============================================================================
39 
40 class Client;
41 class psCharacter;
42 class gemObject;
43 class gemActor;
44 class gemNPC;
45 class psPath;
46 
48 {
49 public:
50  FloodBuffRow(uint8_t chtType, csString txt, csString rcpt, unsigned int newticks);
51  FloodBuffRow() : chatType(0), ticks(0) {}
52  uint8_t chatType;
53  csString text;
54  csString recipient;
55  unsigned int ticks;
56 };
57 
59 {
60 public:
61  void Initialize(Client* c)
62  {
63  cli = c;
64  }
65 
66 protected:
68  virtual void OnChange();
69 };
70 
72 {
73  TARGET_NONE = 0x01, /* Also Area */
74  TARGET_ITEM = 0x04,
75  TARGET_SELF = 0x08,
76  TARGET_FRIEND = 0x10,
77  TARGET_FOE = 0x20,
78  TARGET_DEAD = 0x40
79 };
80 
81 enum CheatFlags // will have more of these as Paladin gets better
82 {
83  NO_CHEAT = 0x00,
84  MOVE_CHEAT = 0x01
85 };
86 
88 
95 class Client : protected NetBase::Connection, public CS::Utility::WeakReferenced
96 {
97 public:
102  Client();
103 
104 
105  ~Client();
106 
107  bool Initialize(LPSOCKADDR_IN addr, uint32_t clientnum);
108  bool Disconnect();
109 
115  void SetAllowedToDisconnect(bool allowed);
116 
122  bool AllowDisconnect();
123 
126  bool ZombieAllowDisconnect();
127 
129  void SetMute(bool flag)
130  {
131  mute.SetBase(flag ? 1 : 0);
132  }
133  bool IsMute()
134  {
135  return (mute.Current() > 0);
136  }
138  {
139  return mute;
140  }
141 
149  void SetName(const char* n);
150 
157  const char* GetName();
158 
159  // Additional Entity information
160  void SetActor(gemActor* myactor);
162  {
163  return actor;
164  }
165  psCharacter* GetCharacterData();
166 
167  // Get / Set Familiar information;
168  void SetFamiliar(gemActor* familiar);
169  gemActor* GetFamiliar();
170 
171  // Get / Set Pet information;
172  void AddPet(gemActor* pet);
173  void RemovePet(size_t index);
174  gemActor* GetPet(size_t index);
175  size_t GetNumPets();
176 
178  bool IsMyPet(gemActor* other) const;
179 
181  bool IsAlive() const;
182 
184  bool ValidateDistanceToTarget(float range);
185 
186  // Target information
187  void SetTargetObject(gemObject* object, bool updateClientGUI=false);
188  gemObject* GetTargetObject() const;
189 
190  // Targeted mesh information - i.e. for adding action locations
191  void SetMesh(csString nextMesh)
192  {
193  mesh = nextMesh;
194  }
195  csString GetMesh() const
196  {
197  return mesh;
198  }
199 
204  int GetTargetClientID();
205 
206  uint32_t GetClientNum() const
207  {
208  return clientnum;
209  }
210 
212  AccountID GetAccountID()
213  {
214  return accountID;
215  }
216  void SetAccountID(AccountID id)
217  {
218  accountID = id;
219  }
220 
222  PID GetPID()
223  {
224  return playerID;
225  }
226  void SetPID(PID id)
227  {
228  playerID = id;
229  }
230 
232  {
233  return exchangeID;
234  }
235  void SetExchangeID(int ID)
236  {
237  exchangeID = ID;
238  }
239 
241  int GetSecurityLevel() const
242  {
243  return securityLevel;
244  }
245  void SetSecurityLevel(int level)
246  {
247  securityLevel=level;
248  }
249 
250  bool IsGM() const;
251 
253  int GetGuildID();
255  int GetAllianceID();
256 
258  void SetReady(bool rdy)
259  {
260  ready = rdy;
261  }
262  bool IsReady()
263  {
264  return ready;
265  }
266 
275  static void GetTargetTypeName(int32_t targetType, csString &targetDesc);
276 
281  bool IsZombie()
282  {
283  return zombie;
284  }
285 
287  void SetSuperClient(bool flag)
288  {
289  superclient = flag;
290  }
292  {
293  return superclient;
294  }
296  {
297  return (!superclient);
298  }
299 
303  void GetIPAddress(char* addrStr, socklen_t size);
304  csString GetIPAddress();
305 
306  csString GetIPRange(int octets=3);
307 
308  static csString GetIPRange(const char* ipaddr, int octets=3);
309 
311  {
312  return (NetBase::Connection*)this;
313  }
314 
315  const SOCKADDR_IN &GetAddress() const
316  {
317  return addr;
318  }
319 
320  csRef<NetPacketQueueRefCount> outqueue;
321 
322  unsigned int GetAccountTotalOnlineTime();
323 
324  void AddDuelClient(uint32_t clientnum);
325  void RemoveDuelClient(Client* client);
326  void ClearAllDuelClients();
327  int GetDuelClientCount();
328  int GetDuelClient(int id);
329  bool IsDuelClient(uint32_t clientnum);
330  void AnnounceToDuelClients(gemActor* attacker, const char* event);
331 
333  void FloodControl(uint8_t chatType, const csString &newMessage, const csString &recipient);
334 
335  void SetAdvisorPoints(int p)
336  {
337  advisorPoints = p;
338  }
340  {
341  advisorPoints += n;
342  }
344  {
345  return advisorPoints;
346  }
347 
349  void SetAdvisor(bool advisor)
350  {
351  isAdvisor = advisor;
352  }
353  bool GetAdvisor()
354  {
355  return isAdvisor;
356  }
357  void SetAdvisorBan(bool ban);
358  bool IsAdvisorBanned();
359 
361  csTicks accumulatedLag;
362 
363  // Invite flood control
365  {
366  return lastInviteTime;
367  }
368  void SetLastInviteTime(csTicks time)
369  {
370  lastInviteTime = time;
371  }
373  {
374  return lastInviteResult;
375  }
376  void SetLastInviteResult(bool result)
377  {
378  lastInviteResult = result;
379  }
381  {
382  return hasBeenWarned;
383  }
384  void SetWarned()
385  {
386  hasBeenWarned = true;
387  }
389  {
390  return hasBeenPenalized;
391  }
392  void SetPenalized(bool value)
393  {
394  hasBeenPenalized = value;
395  }
397  {
398  return spamPoints;
399  }
400  void SetSpamPoints(int points)
401  {
402  spamPoints = points; // For setting on account load
403  }
405  {
406  if(spamPoints<4) spamPoints++;
407  }
409  {
410  if(spamPoints>0) spamPoints--;
411  }
412 
414  void WaypointSetPath(csString &path, int index)
415  {
416  waypointPathName = path;
417  waypointPathIndex = index;
418  }
420  {
421  return waypointPathName;
422  }
424  {
425  return waypointPathIndex;
426  }
428  {
429  return waypointPathIndex++;
430  }
431 
433  {
434  return pathPath;
435  }
436  void PathSetPath(psPath* path)
437  {
438  pathPath = path;
439  }
440 
441  void PathSetIsDisplaying(iSector* sector);
442  void PathClearDisplaying();
443  csList<iSector*>::Iterator GetPathDisplaying();
444  bool PathIsDisplaying();
445 
446  // Online edit of waypoints
447  void WaypointSetIsDisplaying(iSector* sector);
448  void WaypointClearDisplaying();
449  csList<iSector*>::Iterator GetWaypointDisplaying();
450  bool WaypointIsDisplaying();
451 
452 
454  void LocationSetIsDisplaying(iSector* sector);
455  void LocationClearDisplaying();
456  csList<iSector*>::Iterator GetLocationDisplaying();
457  bool LocationIsDisplaying();
458 
460  {
461  selectedLocationID = id;
462  }
464  {
465  return selectedLocationID;
466  }
467 
468 
471  {
472  if(detectedCheatCount < 10000) detectedCheatCount++;
473  }
474  unsigned int GetDetectedCheatCount()
475  {
476  return detectedCheatCount;
477  }
479  void SetCheatMask(CheatFlags mask,bool flag);
481  {
482  return (cheatMask & mask) != 0;
483  }
484 
486  OrderedMessageChannel* GetOrderedMessageChannel(msgtype mtype);
487 
488  // FIXME: Ugly hack here as a temporary workaround for client-side issue that causes the server
489  // to be flooded with inventory/glyph requests. Remove after all clients have been updated
490  // to stop flooding.
492  csTicks lastGlyphSend;
493 
495  void SetBuddyListHide(bool hide)
496  {
497  isBuddyListHiding = hide;
498  }
500  {
501  return isBuddyListHiding;
502  }
503 
504 protected:
505 
510  bool zombie;
511  csTicks zombietimeout;
512 
519 
522 
525 
526  csArray<PID> pets;
527  csString mesh;
528  bool ready;
529 
531  csHash<OrderedMessageChannel*> orderedMessages;
532 
533  bool isAdvisor;
534 
537 
538  AccountID accountID;
539  PID playerID;
542  csArray<gemNPC*> listeningNpc;
543  csString name;
544 
545  csArray<uint32_t> duel_clients;
546 
547  // Flood control
548  static const int floodWarn = 3;
549  static const int floodMax = 5;
550  static const unsigned int floodForgiveTime = 10000;
551  FloodBuffRow floodHistory[floodMax];
553 
556 
557  void SaveAccountData();
558 
559  // Invite flood
560  csTicks lastInviteTime;
564 
565  // Path edit global vars for client
568 
570 
572 
574  csList<iSector*> waypointDisplaySectors;
575  csList<iSector*> pathDisplaySectors;
576  csList<iSector*> locationDisplaySectors;
577 
578 private:
580  unsigned int detectedCheatCount;
581 
583  int cheatMask;
584 
586  bool isBuddyListHiding;
587 };
588 
589 #endif
bool IsMute()
Definition: client.h:133
void CountDetectedCheat()
Give a warning to the client silently. Capped at 10000.
Definition: client.h:470
This class holds data for a connection.
Definition: netbase.h:684
int exchangeID
Currently active id of Exchange object managed by Exchange Manager, or 0 if no exchange is active...
Definition: client.h:521
gemActor * actor
Pointer to the gemActor object played by this client once a character is logged in and in-game...
Definition: client.h:524
int selectedLocationID
Definition: client.h:571
int WaypointGetPathIndex()
Definition: client.h:423
bool superclient
Definition: client.h:541
int nextFloodHistoryIndex
Definition: client.h:552
PID GetPID()
The player number for this client.
Definition: client.h:222
bool IsZombie()
A zombie client is a client that is prevented from disconnecting because of combat, spellcasting, or defeted.
Definition: client.h:281
csArray< PID > pets
Definition: client.h:526
csTicks accumulatedLag
For cheat detection.
Definition: client.h:361
const SOCKADDR_IN & GetAddress() const
Definition: client.h:315
csString GetMesh() const
Definition: client.h:195
Definition: pspath.h:152
csList< iSector * > pathDisplaySectors
Definition: client.h:575
csString mesh
Definition: client.h:527
csString text
Definition: client.h:53
TARGET_TYPES
Definition: client.h:71
const char * GetName(int id)
int securityLevel
Definition: client.h:540
void SetBuddyListHide(bool hide)
Change whether hiding from buddylists.
Definition: client.h:495
uint32_t GetClientNum() const
Definition: client.h:206
AccountID accountID
Definition: client.h:538
A special form of buffable that is clamped to always return a positive number.
Definition: buffable.h:278
bool GetAdvisor()
Definition: client.h:353
bool HasBeenWarned()
Definition: client.h:380
#define LPSOCKADDR_IN
Definition: sockuni.h:70
void PathSetPath(psPath *path)
Definition: client.h:436
void SetAdvisorPoints(int p)
Definition: client.h:335
psPath * pathPath
Definition: client.h:569
bool lastInviteResult
Definition: client.h:561
void SetWarned()
Definition: client.h:384
void SetSpamPoints(int points)
Definition: client.h:400
bool ready
Definition: client.h:528
MuteBuffable mute
mute flag
Definition: client.h:536
NetBase::Connection * GetConnection() const
Definition: client.h:310
void SetMesh(csString nextMesh)
Definition: client.h:191
csTicks GetLastInviteTime()
Definition: client.h:364
int GetExchangeID()
Definition: client.h:231
csTicks zombietimeout
Definition: client.h:511
bool zombie
A zombie client is a client where the player has disconnected, but still active due to not finished c...
Definition: client.h:510
void SetReady(bool rdy)
Sets the player state to ready. For example ready to receive chat messages.
Definition: client.h:258
void SetSuperClient(bool flag)
Allow distinguishing superclients from regular player clients.
Definition: client.h:287
csRef< NetPacketQueueRefCount > outqueue
Definition: client.h:320
void SetLastInviteTime(csTicks time)
Definition: client.h:368
Any semi-autonomous object, either a player or an NPC.
Definition: gem.h:1170
int advisorPoints
Definition: client.h:555
Client * cli
Definition: client.h:67
csArray< uint32_t > duel_clients
Definition: client.h:545
void SetSecurityLevel(int level)
Definition: client.h:245
void Initialize(Client *c)
Definition: client.h:61
PID playerID
Definition: client.h:539
csTicks lastInviteTime
Definition: client.h:560
uint8_t chatType
Definition: client.h:52
int GetAdvisorPoints()
Definition: client.h:343
int WaypointGetNewPathIndex()
Definition: client.h:427
bool IsPlayerClient()
Definition: client.h:295
bool IsReady()
Definition: client.h:262
void SetLastInviteResult(bool result)
Definition: client.h:376
int GetSpamPoints()
Definition: client.h:396
void SetSelectedLocationID(int id)
Definition: client.h:459
csString waypointPathName
Definition: client.h:566
int GetSelectedLocationID()
Definition: client.h:463
void SetPenalized(bool value)
Definition: client.h:392
csList< iSector * > waypointDisplaySectors
Sectors where client is doing online editing.
Definition: client.h:574
int spamPoints
Definition: client.h:554
This class collects data of a netclient.
Definition: client.h:95
bool hasBeenPenalized
Definition: client.h:563
uint8_t msgtype
Definition: message.h:56
csTicks lastGlyphSend
Definition: client.h:492
void void Initialize(iObjectRegistry *object_reg)
unsigned int ticks
Definition: client.h:55
#define SOCKADDR_IN
Definition: sockuni.h:58
bool GetBuddyListHide()
Definition: client.h:499
Definition: gem.h:1910
csHash< OrderedMessageChannel * > orderedMessages
This collection stores queues of ordered messages while we&#39;re waiting for an out of order one to arri...
Definition: client.h:531
psPath * PathGetPath()
Definition: client.h:432
bool hasBeenWarned
Definition: client.h:562
unsigned int GetDetectedCheatCount()
Definition: client.h:474
int GetSecurityLevel() const
The security level of this player.
Definition: client.h:241
csArray< gemNPC * > listeningNpc
Definition: client.h:542
#define socklen_t
Definition: sockwin.h:38
void SetAdvisor(bool advisor)
Set this client&#39;s advisor status.
Definition: client.h:349
void SetAccountID(AccountID id)
Definition: client.h:216
This class holds the structure for guaranteed inbound ordering of certain message types...
Definition: msghandler.h:80
bool HasBeenPenalized()
Definition: client.h:388
void IncrementAdvisorPoints(int n=1)
Definition: client.h:339
A gemObject is any solid, graphical object visible in PS with normal physics and normal collision det...
Definition: gem.h:314
CheatFlags
Definition: client.h:81
int waypointPathIndex
Definition: client.h:567
csString recipient
Definition: client.h:54
void DecrementSpamPoints()
Definition: client.h:408
void SetPID(PID id)
Definition: client.h:226
bool GetLastInviteResult()
Definition: client.h:372
bool IsSuperClient()
Definition: client.h:291
bool isAdvisor
Store if this client is acting as an advisor.
Definition: client.h:533
bool GetCheatMask(CheatFlags mask)
Definition: client.h:480
csTicks lastInventorySend
Definition: client.h:491
AccountID GetAccountID()
The account number for this client.
Definition: client.h:212
void SetExchangeID(int ID)
Definition: client.h:235
csString name
Definition: client.h:543
bool allowedToDisconnect
Server set this flag when the player isn&#39;t casting spells, fighting or doing anythinge else that shou...
Definition: client.h:518
void IncrementSpamPoints()
Definition: client.h:404
csString & WaypointGetPathName()
Definition: client.h:419
FloodBuffRow()
Definition: client.h:51
void WaypointSetPath(csString &path, int index)
Online edit of paths.
Definition: client.h:414
gemActor * GetActor() const
Definition: client.h:161
MuteBuffable & GetBuffableMute()
Definition: client.h:137
csList< iSector * > locationDisplaySectors
Definition: client.h:576
void SetMute(bool flag)
SetMute is the function that toggles the muted flag.
Definition: client.h:129