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 #if !defined(__INCLUDE_NetServerTCP3h_INCLUDE__) 00022 #define __INCLUDE_NetServerTCP3h_INCLUDE__ 00023 00024 #include <net/NetServerTCP3Destination.h> 00025 #include <map> 00026 00027 class NetServerTCP3 : 00028 public NetInterface, 00029 public NetMessageHandlerI 00030 { 00031 public: 00032 NetServerTCP3(); 00033 virtual ~NetServerTCP3(); 00034 00035 // NetInterface 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 // NetMessageHandlerI 00052 virtual void processMessage(NetMessage &message); 00053 00054 protected: 00055 friend class NetServerTCP3Destination; 00056 00057 NetMessageHandler outgoingMessageHandler_; 00058 NetMessageHandler incomingMessageHandler_; 00059 TCPsocket serverSock_; 00060 SDLNet_SocketSet serverSockSet_; 00061 SDL_Thread *sendRecvThread_; 00062 bool stopped_; 00063 std::map<unsigned int, NetServerTCP3Destination *> destinations_; 00064 std::list<NetServerTCP3Destination *> finishedDestinations_; 00065 unsigned int serverDestinationId_; 00066 unsigned int nextDestinationId_; 00067 00068 void checkNewConnections(); 00069 void checkClients(); 00070 bool startProcessing(); 00071 00072 void actualSendRecvFunc(); 00073 static int sendRecvThreadFunc(void *); 00074 00075 void destroyDestination(unsigned int destinationId, 00076 NetMessage::DisconnectFlags type); 00077 unsigned int addDestination(TCPsocket &socket); 00078 }; 00079 00080 #endif // __INCLUDE_NetServerTCP3h_INCLUDE__
1.5.3