Planeshift

netmanager.h

Go to the documentation of this file.
00001 /*
00002  * netmanager.h by Matze Braun <[email protected]> and
00003  *                 Keith Fulton <[email protected]>
00004  *
00005  * Copyright (C) 2001-3 Atomic Blue ([email protected], http://www.atomicblue.org)
00006  *
00007  *
00008  * This program is free software; you can redistribute it and/or
00009  * modify it under the terms of the GNU General Public License
00010  * as published by the Free Software Foundation (version 2 of the License)
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00018  *
00019  */
00020 #ifndef __NETMANAGER_H__
00021 #define __NETMANAGER_H__
00022 
00023 //=============================================================================
00024 // Crystal Space Includes
00025 //=============================================================================
00026 #include <csutil/threading/thread.h>
00027 
00028 //=============================================================================
00029 // Project Includes
00030 //=============================================================================
00031 #include "net/netbase.h"
00032 
00033 //=============================================================================
00034 // Local Includes
00035 //=============================================================================
00036 #include "clients.h"
00037 
00038 class CacheManager;
00039 
00049 class NetManager : public NetBase
00050 {
00051 public:
00052     NetManager();
00053     ~NetManager();
00054 
00071     bool Initialize(CacheManager* cachemanager, int client_firstmsg, int npcclient_firstmsg, int timeout=15000);
00072 
00073     static NetManager* Create(CacheManager* cacheManager, int client_firstmsg, int npcclient_firstmsg, int timeout=15000);
00074 
00075     static void Destroy();
00076 
00098     virtual void Broadcast(MsgEntry* me, int scope,int guild=-1);
00099 
00116     virtual void Multicast(MsgEntry* me, const csArray<PublishDestination> &multi, uint32_t except, float range);
00117 
00124     void CheckLinkDead(void);
00125 
00131     ClientConnectionSet* GetConnections()
00132     {
00133         return &clients;
00134     }
00135 
00142     Client* GetClient(int cnum);
00143 
00150     Client* GetAnyClient(int cnum);
00151 
00161     virtual bool SendMessage(MsgEntry* me);
00162 
00167     bool SendMessageDelayed(MsgEntry* me, csTicks delay);
00168 
00177     void Run();
00178 
00179 protected:
00180 
00189     virtual Connection* GetConnByIP(LPSOCKADDR_IN addr);
00190 
00199     virtual Connection* GetConnByNum(uint32_t clientnum);
00200 
00216     virtual bool HandleUnknownClient(LPSOCKADDR_IN addr, MsgEntry* msg);
00217 
00218 private:
00222     void CheckResendPkts(void);
00223 
00225     ClientConnectionSet clients;
00226 
00228     int port;
00229 
00231     int timeout;
00232 
00234     uint32_t client_firstmsg;
00236     uint32_t npcclient_firstmsg;
00237 
00239     bool stop_network;
00240 };
00241 
00244 #endif