00001 //////////////////////////////////////////////////////////////////////////////// 00002 // Scorched3D (c) 2000-2009 00003 // 00004 // This file is part of Scorched3D. 00005 // 00006 // Scorched3D is free software; you can redistribute it and/or modify 00007 // it under the terms of the GNU General Public License as published by 00008 // the Free Software Foundation; either version 2 of the License, or 00009 // (at your option) any later version. 00010 // 00011 // Scorched3D 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 // 00016 // You should have received a copy of the GNU General Public License 00017 // along with Scorched3D; if not, write to the Free Software 00018 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00019 //////////////////////////////////////////////////////////////////////////////// 00020 00021 #ifndef __INCLUDE_netServer_h_INCLUDE__ 00022 #define __INCLUDE_netServer_h_INCLUDE__ 00023 00024 #include <net/NetInterface.h> 00025 #include <net/NetServerTCPProtocol.h> 00026 #include <net/NetServerTCPRead.h> 00027 #include <list> 00028 #include <map> 00029 00030 class NetServerTCP : public NetInterface 00031 { 00032 public: 00033 NetServerTCP(NetServerTCPProtocol *protocol); 00034 virtual ~NetServerTCP(); 00035 00036 virtual bool started(); 00037 virtual bool connect(const char *hostName, int portNo); 00038 virtual bool start(int portNo); 00039 virtual void stop(); 00040 00041 virtual int processMessages(); 00042 virtual void setMessageHandler(NetMessageHandlerI *handler); 00043 00044 virtual void disconnectAllClients(); 00045 virtual void disconnectClient(unsigned int client); 00046 virtual void sendMessageServer(NetBuffer &buffer, 00047 unsigned int flags = 0); 00048 virtual void sendMessageDest(NetBuffer &buffer, 00049 unsigned int destination, unsigned int flags = 0); 00050 00051 protected: 00052 NetServerTCPProtocol *protocol_; 00053 TCPsocket server_; 00054 unsigned int lastId_; 00055 unsigned int firstDestination_; 00056 SDLNet_SocketSet sockSet_; 00057 std::map<unsigned int, NetServerTCPRead *> connections_; 00058 SDL_mutex *setMutex_; 00059 NetMessageHandler messageHandler_; 00060 bool checkDeleted_; 00061 00062 static int threadFunc(void *); 00063 00064 bool pollIncoming(); 00065 bool pollDeleted(); 00066 void addClient(TCPsocket client); 00067 void sendMessage(unsigned int client, NetMessage *message); 00068 unsigned int getIpAddress(unsigned int destination); 00069 00070 private: 00071 00072 NetServerTCP(const NetServerTCP &); 00073 const NetServerTCP & operator=(const NetServerTCP &); 00074 00075 }; 00076 00077 #endif // __INCLUDE_netServer_h_INCLUDE__ 00078
1.5.3