Planeshift
netmanager.h
Go to the documentation of this file.
1 /*
2  * netmanager.h by Matze Braun <matze@braunis.de> and
3  * Keith Fulton <keith@paqrat.com>
4  *
5  * Copyright (C) 2001-3 Atomic Blue (info@planeshift.it, http://www.atomicblue.org)
6  *
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation (version 2 of the License)
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  *
19  */
20 #ifndef __NETMANAGER_H__
21 #define __NETMANAGER_H__
22 
23 //=============================================================================
24 // Crystal Space Includes
25 //=============================================================================
26 #include <csutil/threading/thread.h>
27 
28 //=============================================================================
29 // Project Includes
30 //=============================================================================
31 #include "net/netbase.h"
32 
33 //=============================================================================
34 // Local Includes
35 //=============================================================================
36 #include "clients.h"
37 
38 class CacheManager;
39 
49 class NetManager : public NetBase
50 {
51 public:
52  NetManager();
53  ~NetManager();
54 
71  bool Initialize(CacheManager* cachemanager, int client_firstmsg, int npcclient_firstmsg, int timeout=15000);
72 
73  static NetManager* Create(CacheManager* cacheManager, int client_firstmsg, int npcclient_firstmsg, int timeout=15000);
74 
75  static void Destroy();
76 
98  virtual void Broadcast(MsgEntry* me, int scope,int guild=-1);
99 
116  virtual void Multicast(MsgEntry* me, const csArray<PublishDestination> &multi, uint32_t except, float range);
117 
124  void CheckLinkDead(void);
125 
132  {
133  return &clients;
134  }
135 
142  Client* GetClient(int cnum);
143 
150  Client* GetAnyClient(int cnum);
151 
161  virtual bool SendMessage(MsgEntry* me);
162 
167  bool SendMessageDelayed(MsgEntry* me, csTicks delay);
168 
177  void Run();
178 
179 protected:
180 
189  virtual Connection* GetConnByIP(LPSOCKADDR_IN addr);
190 
199  virtual Connection* GetConnByNum(uint32_t clientnum);
200 
216  virtual bool HandleUnknownClient(LPSOCKADDR_IN addr, MsgEntry* msg);
217 
218 private:
222  void CheckResendPkts(void);
223 
225  ClientConnectionSet clients;
226 
228  int port;
229 
231  int timeout;
232 
234  uint32_t client_firstmsg;
236  uint32_t npcclient_firstmsg;
237 
239  bool stop_network;
240 };
241 
244 #endif
This class holds data for a connection.
Definition: netbase.h:684
virtual Connection * GetConnByIP(LPSOCKADDR_IN addr)
Returns a NetManager::Connection from the given IP address.
virtual void Broadcast(MsgEntry *me, int scope, int guild=-1)
This broadcasts the same msg out to a bunch of Clients.
The structure of 1 queue entry (pointer to a message)
Definition: message.h:143
Client * GetClient(int cnum)
Gets a client with the specified id.
#define LPSOCKADDR_IN
Definition: sockuni.h:70
virtual bool HandleUnknownClient(LPSOCKADDR_IN addr, MsgEntry *msg)
Handles/connects a new client from an unknown IP address.
static void Destroy()
void CheckLinkDead(void)
Checks for and deletes link dead clients.
bool SendMessageDelayed(MsgEntry *me, csTicks delay)
Queues the message for sending later, so the calling classes don&#39;t have to all manage this themselves...
void Run()
This is the main thread function.
virtual Connection * GetConnByNum(uint32_t clientnum)
Returns a NetManager::Connection from the given client number.
virtual void Multicast(MsgEntry *me, const csArray< PublishDestination > &multi, uint32_t except, float range)
Sends the given message me to all the clients in the list.
This class acts as a base for client/server net classes.
Definition: netbase.h:116
This class collects data of a netclient.
Definition: client.h:95
virtual bool SendMessage(MsgEntry *me)
Sends the given message to the client listed in the message.
Client * GetAnyClient(int cnum)
Gets a client with the specified id.
bool Initialize(CacheManager *cachemanager, int client_firstmsg, int npcclient_firstmsg, int timeout=15000)
Initialize the network thread.
ClientConnectionSet * GetConnections()
Gets a list of all connected clients.
Definition: netmanager.h:131
This is the network thread handling packets sending/receiving to/from network other threads can regis...
Definition: netmanager.h:49
This class manages the caching of data that is unchanging during server operation.
Definition: cachemanager.h:234
This class is a list of several CLient objects, it&#39;s designed for finding clients very fast based on ...
Definition: clients.h:58
static NetManager * Create(CacheManager *cacheManager, int client_firstmsg, int npcclient_firstmsg, int timeout=15000)