Planeshift
|
00001 /* 00002 * connection.h by Matze Braun <[email protected]> 00003 * 00004 * Copyright (C) 2002 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 __CONNECTION_H__ 00020 #define __CONNECTION_H__ 00021 00022 #include <csutil/threading/thread.h> 00023 00024 #include "net/netbase.h" 00025 00026 struct iObjectRegistry; 00027 00042 class psNetConnection : public NetBase, public CS::Threading::Runnable 00043 { 00044 public: 00046 psNetConnection(int queueLength = 100); 00048 virtual ~psNetConnection(); 00049 00051 bool Initialize(iObjectRegistry* object_reg); 00052 00063 bool Connect(const char *server, int port); 00064 00067 void DisConnect(); 00068 00070 virtual void Broadcast (MsgEntry* me, int scope, int guildID); 00071 00073 virtual void Multicast (MsgEntry* me, const csArray<PublishDestination>& multi, uint32_t except, float range); 00074 00076 virtual void IncRef () 00077 {} 00079 virtual void DecRef () 00080 {} 00081 00082 virtual int GetRefCount() { return 1; } 00083 00084 protected: 00086 virtual Connection *GetConnByIP (LPSOCKADDR_IN addr); 00088 virtual Connection *GetConnByNum (uint32_t clientnum); 00090 virtual bool HandleUnknownClient (LPSOCKADDR_IN addr, MsgEntry *data); 00091 00099 void CheckLinkDead (csTicks time); 00100 00106 MsgQueue *inQueue; 00107 00109 Connection *server; 00110 iObjectRegistry* object_reg; 00111 00113 bool shouldRun; 00114 00116 void Run (); 00117 00118 private: 00120 csRef<CS::Threading::Thread> thread; 00121 }; 00122 00125 #endif