Planeshift
clients.h
Go to the documentation of this file.
1 /*
2  * clients.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 __CLIENTS_H__
20 #define __CLIENTS_H__
21 
22 #include <csutil/hash.h>
23 #include <csutil/threading/thread.h>
24 
25 #include "client.h"
26 
27 class ClientIterator;
28 class iResultRow;
29 
31 {
32 public:
33  SockAddress(const SOCKADDR_IN &sock);
34  bool operator< (const SockAddress &other) const;
35 private:
36  // Define a few operators as privat so that we know
37  // that they are not used.
38  bool operator> (const SockAddress &other) const;
39  bool operator= (const SockAddress &other) const;
40  bool operator== (const SockAddress &other) const;
41 
42 #ifdef INCLUDE_IPV6_SUPPORT
43  SOCKADDR_IN addr;
44 #else
45  uint32_t port;
46  uint32_t addr;
47 #endif
48 };
49 
50 template<> class csHashComputer<SockAddress> :
51  public csHashComputerStruct<SockAddress> {};
52 
59 {
60 public:
61  typedef csHash<Client*, SockAddress> AddressHash;
62 protected:
63  friend class ClientIterator;
64 
65  AddressHash addrHash;
66  csHash<Client*> hash;
67  csPDelArray<Client> toDelete;
68  CS::Threading::RecursiveMutex mutex;
69 
70 public:
73 
74  bool Initialize();
75 
76  Client* Add(LPSOCKADDR_IN addr);
77 
78  // Delete all clients marked to be deleted
79  void SweepDelete();
80 
81  // Mark this client as ready to be deleted
82  void MarkDelete(Client* client);
83 
85  size_t Count(void) const;
86 
88  size_t CountReadyPlayers() const;
89 
91  Client* FindAny(uint32_t id);
93  Client* Find(uint32_t id);
95  Client* Find(const char* name);
97  Client* FindPlayer(PID playerID);
99  Client* FindAccount(AccountID accountID, uint32_t excludeClient = 0);
101  Client* Find(LPSOCKADDR_IN addr);
102 
103  csRef<NetPacketQueueRefCount> FindQueueAny(uint32_t id);
104 };
105 
107 {
108 public:
110  ~ClientIterator();
111 
112 private:
113 
115  CS::Threading::RecursiveMutex &mutex;
116 };
117 
118 
119 #endif
SockAddress(const SOCKADDR_IN &sock)
bool operator<(const SockAddress &other) const
CS::Threading::RecursiveMutex mutex
Definition: clients.h:68
#define LPSOCKADDR_IN
Definition: sockuni.h:70
csPDelArray< Client > toDelete
Definition: clients.h:67
csHash< Client *, SockAddress > AddressHash
Definition: clients.h:61
This class collects data of a netclient.
Definition: client.h:95
void void Initialize(iObjectRegistry *object_reg)
csHash< Client * > hash
Definition: clients.h:66
#define SOCKADDR_IN
Definition: sockuni.h:58
This class is a list of several CLient objects, it&#39;s designed for finding clients very fast based on ...
Definition: clients.h:58
AddressHash addrHash
Definition: clients.h:65