Changeset 9494 in orxonox.OLD
- Timestamp:
- Jul 27, 2006, 10:44:28 AM (18 years ago)
- Location:
- trunk/src
- Files:
-
- 2 deleted
- 47 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/lib/collision_detection/aabb_tree_node.cc
r9406 r9494 66 66 { 67 67 this->depth = depth; 68 69 this->init(); 68 70 } 69 71 … … 87 89 88 90 this->owner = NULL; 89 90 /* debug ids */91 if( this->nodePrev)92 this->treeIndex = 100 * this->depth + this->nodePrev->getID();93 else94 this->treeIndex = 0;95 91 } 96 92 -
trunk/src/lib/network/Makefile.am
r9406 r9494 28 28 proxy/network_settings.cc \ 29 29 \ 30 30 monitor/connection_monitor.cc \ 31 31 monitor/network_monitor.cc \ 32 32 monitor/network_node.cc \ 33 monitor/network_stats_widget.cc \ 33 34 \ 34 35 synchronizeable_var/synchronizeable_var.cc \ … … 77 78 proxy/network_settings.cc \ 78 79 \ 79 monitor/connection_monitor.h \ 80 monitor/network_monitor.h \ 81 monitor/network_node.h \ 80 monitor/connection_monitor.h \ 81 monitor/network_monitor.h \ 82 monitor/network_node.h \ 83 monitor/network_stats_widget.h \ 82 84 \ 83 85 synchronizeable_var/synchronizeable_var.h \ -
trunk/src/lib/network/README.NETWORK
r9406 r9494 1 2 3 4 WORKING_STACK: 5 ============== 6 - it works to connecto to a master server which is connected to a proxy itself 7 8 9 10 UNSOLVED: 11 ========= 12 - what if the proxy server gets a new client and wants to add it to the game? There are some problems waiting in the network game manager 13 - actualy the whole message sending system won't work in this network topic. proxys have to relay messages to clients 14 - the clients cant get its ip in the handleHandshakes without throuwing sigseg 15 1 16 2 17 … … 8 23 9 24 UserId: 25 ======= 10 26 containing the id of a user (==client). This id must be unique within a orxonox network its used especialy in the NetworkStream for node identification and also in the Synchronizeable base class for permissions checking (PERMISSION_OWNER) 11 WARNING: 12 There is some correlation between userids and the maxplayer, do not touch this. 27 28 the connections belonging tu toe userId's are stored in the NetworkStream::peers std::map. As a keyvalue the userId's are used. Therefore the usage of this peers map is very delicate. Don't ever try to add anything you are not sure about the id stuff. 29 30 There are some reserved id's, don't mess with them: 31 0 : Master Server 32 1 : First Proxy Server 33 2 : Second Proxy Server 34 3 : Third Proxy Server 35 4 : Fourth Proxy Server 36 . 37 . 38 . 39 NET_MAX_PROXY The maximal number of proxy servers 40 NET_MAX... + 1 First Client 41 NET_MAX... + 2 Second Client 42 . 43 . 44 . 45 NET_MAX_CONNECTION Last client 46 47 The proxy server ids are assigned as stated in the data/trunk/config/network_settings.conf, the first proxy server in the list gets the id NET_ID_PROXY_01 and so on. 48 13 49 14 50 15 51 uniqueId: 52 ========= 16 53 uniqueId is an id (unique :D) for each synchronizeable to be identified in a network. the number space for uniqueIds goes from 0 to maxplayers - 1 17 54 18 55 56 permissions: 57 ============ 58 Each synchronizeable variable has some write permissions. this permission systems allows to manage which network nodes are able to write the variables. 59 PERMISSION_MASTER_SERVER : only the master server can write this variable 60 PERMISSION_PROXY_SERVER : only the proxy server can write this variable 61 PERMISSION_OWNER : only the owner can write this variable 62 PERMISSION_ALL : all clients can write this variable 63 64 65 66 67 19 68 NetworkStream PeerInfo list: (peers) 69 ===================================== 20 70 The network node with the offset 0 is always the server to which the client must connect to (in case there are connections to other hosts at the same time). 71 72 73 -
trunk/src/lib/network/handshake.cc
r9406 r9494 76 76 remoteState.orxId = 0; 77 77 remoteState.version = 0; 78 remoteState.nodeType = NET_ CLIENT;78 remoteState.nodeType = NET_UNASSIGNED; 79 79 remoteState.canDel = 0; 80 80 -
trunk/src/lib/network/handshake.h
r9406 r9494 49 49 /* functions indicating states of the handshake */ 50 50 /** @returns true if the handshake is completed */ 51 inline bool completed() { return localState.completed != 0 && remoteState.completed != 0; }51 inline bool completed() const { return localState.completed != 0 && remoteState.completed != 0; } 52 52 /** @returns true if no error has occured until now */ 53 inline bool ok() { return localState.error == 0 && remoteState.error == 0; }53 inline bool ok() const { return localState.error == 0 && remoteState.error == 0; } 54 54 /** stops the handshake and reject the other side with @param reason: string describing the reason */ 55 55 inline void doReject( std::string reason ){ localState.error = 1; localState.errorString = "the server rejected your connection ["+ reason +"]"; } 56 56 /** @returns true if the handshake is finished and the instances can be deleted */ 57 inline bool canDel() { return localState.canDel == 1 && remoteState.canDel == 1; }57 inline bool canDel() const { return localState.canDel == 1 && remoteState.canDel == 1; } 58 58 /** @returns true if the local state can be removed*/ 59 inline bool allowDel() { return localState.canDel == 1; }59 inline bool allowDel() const { return localState.canDel == 1; } 60 60 /** marks the handshake to be deleted */ 61 inline void del() { localState.canDel = 1; }61 inline void del() { localState.canDel = 1; } 62 62 63 63 64 64 /* the actual informations exchanged in the handshake */ 65 65 /** @returns the host id of the remote host */ 66 inline int getHostId() { return remoteState.hostId; }66 inline int getHostId() const { return remoteState.hostId; } 67 67 /** @returns the unique id of the network game manager*/ 68 inline int getNetworkGameManagerId() { return remoteState.networkManagerId; }68 inline int getNetworkGameManagerId() const { return remoteState.networkManagerId; } 69 69 /** @returns the unique id of the message manager */ 70 inline int getMessageManagerId() { return remoteState.messageManagerId; }70 inline int getMessageManagerId() const { return remoteState.messageManagerId; } 71 71 /** @returns the node type of the remote host */ 72 inline int getRemoteNodeType() { return this->remoteState.nodeType; }72 inline int getRemoteNodeType() const { return this->remoteState.nodeType; } 73 73 74 74 /** sets @param nick the prefereded nick name */ 75 75 inline void setPreferedNickName( const std::string & nick ){ localState.preferedNickName = nick; } 76 76 /** @returns the prefered nick name */ 77 inline std::string getPreferedNickName(){ return remoteState.preferedNickName; }77 inline const std::string& getPreferedNickName() const { return remoteState.preferedNickName; } 78 78 79 79 /** @returns if true the local client should reconnect to a proxy server from the proxy server list */ 80 inline bool redirect() { return this->redirectProxy;}80 inline bool redirect() const { return this->redirectProxy; } 81 81 /** @param flag: indicating if the client should be redirected */ 82 82 inline void setRedirect(bool flag) { if( SharedNetworkData::getInstance()->isClient()) return; this->redirectProxy = (int)flag; } … … 85 85 inline void setProxy1Address(IP address) { if( SharedNetworkData::getInstance()->isClient()) return; this->proxy1 = address; } 86 86 /** @returns the address of the proxy server 1 if any */ 87 inline IP getProxy1Address() { return this->proxy1; }87 inline IP getProxy1Address() const { return this->proxy1; } 88 88 /** @param address: the address of the proxy server 2 if any */ 89 89 inline void setProxy2Address(IP address) { if( SharedNetworkData::getInstance()->isClient()) return; this->proxy2 = address; } 90 90 /** @returns the address of the proxy server 2 if any */ 91 inline IP getProxy2Address() { return this->proxy2; }91 inline IP getProxy2Address() const { return this->proxy2; } 92 92 93 93 -
trunk/src/lib/network/ip.cc
r9406 r9494 111 111 IP::IP(unsigned int first, unsigned int second, unsigned int third, unsigned int fourth, int port) 112 112 { 113 this->_host = (f irst<< 24) +114 ( second << 16) +115 ( third << 8) +116 fourth;113 this->_host = (fourth << 24) + 114 (third << 16) + 115 (second << 8) + 116 (first); 117 117 this->_port = port; 118 118 } … … 185 185 IPaddress ipaddr; 186 186 187 SDLNet_ResolveHost(&ipaddr, NULL, 2000);188 189 return IP(ipaddr .host, port);187 SDLNet_ResolveHost(&ipaddr, ip.c_str(), port); 188 189 return IP(ipaddr); 190 190 } 191 191 else … … 255 255 /** 256 256 * @brief converts a IP into a String (without port). 257 * @param ipthe IP to put into the string.257 * @param host the IP to put into the string. 258 258 * @param port -1 if not wanted 259 259 * @return the string of the ip. 260 260 */ 261 std::string IP::ipToString(int ip, int port)262 { 263 MultiType part0((int) ( ip & 0xFF000000) >> 24);264 MultiType part1((int) ( ip & 0x00FF0000) >> 16);265 MultiType part2((int) ( ip & 0x0000FF00) >> 8);266 MultiType part3((int) ( ip & 0x000000FF));261 std::string IP::ipToString(int host, int port) 262 { 263 MultiType part0((int) ((host & 0xFF000000) >> 24)); 264 MultiType part1((int) ((host & 0x00FF0000) >> 16)); 265 MultiType part2((int) ((host & 0x0000FF00) >> 8)); 266 MultiType part3((int) ((host & 0x000000FF) )); 267 267 268 268 std::string addr = part3.getString() + "." + part2.getString() + "." + 269 269 part1.getString() + "." + part0.getString(); 270 270 271 if (port != -1)272 addr += ":" + MultiType(port).getString();273 271 return addr; 274 272 } -
trunk/src/lib/network/ip.h
r9406 r9494 54 54 55 55 static std::string ipToString(const IPaddress& ipaddr); 56 static std::string ipToString(int ip, int port = -1);56 static std::string ipToString(int host, int port = -1); 57 57 58 58 static void setDefaultPort(int defaultPort); -
trunk/src/lib/network/message_manager.cc
r9406 r9494 320 320 if ( 321 321 recieverType == RT_ALL_ME || 322 recieverType == RT_ALL_ NOT_ME ||322 recieverType == RT_ALL_BUT_ME || 323 323 recieverType == RT_USER && it->first == reciever || 324 324 recieverType == RT_NOT_USER && it->first != reciever || 325 recieverType == RT_SERVER && getNetworkStream()->isUserMasterServer( it->first ) 325 recieverType == RT_SERVER && getNetworkStream()->isUserMasterServer( it->first ) || 326 recieverType == RT_SERVER && getNetworkStream()->isUserProxyServerActive( it->first ) 326 327 ) 327 328 { -
trunk/src/lib/network/message_manager.h
r9008 r9494 26 26 27 27 28 enum MessageId 28 enum MessageId 29 29 { 30 30 TESTMESSAGEID = 1, … … 40 40 enum RecieverType 41 41 { 42 RT_ALL_ NOT_ME = 1, //!< message is sent to all users42 RT_ALL_BUT_ME = 1, //!< message is sent to all users but myself 43 43 RT_ALL_ME, //!< message is sent to all users 44 44 RT_USER, //!< message is only sent to reciever … … 52 52 MP_HIGHBANDWIDTH = 1, //!< fast and reliable but uses a lot of bandwidth 53 53 MP_LOWBANDWIDTH, //!< may take a long time to arrive. reliable 54 MP_UNRELIABLE //!< unreliable. low bandwidth 54 MP_UNRELIABLE //!< unreliable. low bandwidth 55 55 }; 56 56 … … 88 88 public: 89 89 inline static MessageManager * getInstance(){ if (!singletonRef) singletonRef = new MessageManager(); return singletonRef; } 90 90 91 91 virtual ~MessageManager(); 92 92 93 93 bool registerMessageHandler( MessageId messageId, MessageCallback cb, void * someData ); 94 94 95 95 void sendMessage( MessageId messageId, byte * data, int dataLength, RecieverType recieverType, int reciever, MessagePriority messagePriority ); 96 96 … … 100 100 virtual void handleSentState( int userId, int stateId, int fromStateId ){} 101 101 virtual void handleRecvState( int userId, int stateId, int fromStateId ){} 102 102 103 103 void initUser( int userId ); 104 104 … … 110 110 111 111 int newNumber; //!< used to create unique message numbers 112 std::list<NetworkMessage> incomingMessageBuffer; 112 std::list<NetworkMessage> incomingMessageBuffer; 113 113 114 114 }; -
trunk/src/lib/network/monitor/connection_monitor.cc
r9406 r9494 32 32 /* set the class id for the base object and add ist to class list*/ 33 33 this->setClassID(CL_CONNECTION_MONITOR, "ConnectionMonitor"); 34 34 35 35 this->userId = userId; 36 36 this->ping = 0; … … 43 43 this->nZIncomingPackets = 0; 44 44 this->nZOutgoingPackets = 0; 45 45 46 46 this->lastPacketTick = 0; 47 47 this->lastPrintTick = 0; … … 64 64 { 65 65 nOutgoingPackets++; 66 66 67 67 // for ping calculation 68 68 sentStateTicks[stateId] = tick; 69 69 70 70 // calculate bandwidth 71 71 outgoingUnzippedPacketHistory[tick] = length; 72 72 outgoingUnzippedBandWidth = calculateBandWidth( outgoingUnzippedPacketHistory, tick ); 73 73 74 74 //NETPRINTF(n)("UNZIPPED UPSTREAM: user: %d bandwidth %f\n", userId, outgoingUnzippedBandWidth ); 75 75 76 76 // count zero bytes 77 77 //int nZeroBytes = 0; 78 78 79 79 //for ( int i = 0; i < length; i++ ) 80 80 // if ( data[i] == '\0' ) 81 81 // nZeroBytes++; 82 82 83 83 //NETPRINTF(n)( "ZEROBYTES: %d (%f%%)\n", nZeroBytes, ((float)100)*nZeroBytes/length ); 84 84 } … … 94 94 { 95 95 nIncomingPackets++; 96 96 97 97 lastPacketTick = tick; 98 98 99 99 // calculate ping 100 100 if ( sentStateTicks.find( ackedState ) != sentStateTicks.end() ) … … 102 102 ackDelay.push_back( tick - sentStateTicks[ackedState] ); 103 103 } 104 104 105 105 while ( sentStateTicks.begin() != sentStateTicks.end() && sentStateTicks.begin()->first <= ackedState ) 106 106 sentStateTicks.erase( sentStateTicks.begin() ); 107 107 108 108 while ( ackDelay.size() > N_PACKETS_FOR_PING ) 109 109 ackDelay.erase( ackDelay.begin() ); 110 110 111 111 ping = 0; 112 112 113 113 for ( std::list<int>::iterator it = ackDelay.begin(); it != ackDelay.end(); it++ ) 114 114 ping += *it; 115 115 116 116 if ( ackDelay.size() == 0 ) 117 117 ping = -1; 118 118 else 119 119 ping /= ackDelay.size(); 120 120 121 121 //NETPRINTF(n)("PING: user: %d ping: %d\n", userId, ping ); 122 122 123 123 // calculate bandwidth 124 124 incomingUnzippedPacketHistory[tick] = length; 125 125 incomingUnzippedBandWidth = calculateBandWidth( incomingUnzippedPacketHistory, tick ); 126 126 127 127 //NETPRINTF(n)("UNZIPPED DOWNSTREAM: user: %d bandwidth %f\n", userId, incomingUnzippedBandWidth ); 128 128 129 129 } 130 130 131 131 /** 132 132 * remove old packets 133 * @param packetHistory 134 * @param tick 133 * @param packetHistory 134 * @param tick 135 135 */ 136 136 void ConnectionMonitor::removeOldPackets( std::map< int, int > & packetHistory, int tick ) … … 149 149 { 150 150 removeOldPackets( packetHistory, tick ); 151 151 152 152 float res = 0.0f; 153 153 #if 0 … … 157 157 res += it->second; 158 158 } 159 159 160 160 if ( packetHistory.size() <= 1 || tick - packetHistory.begin()->first == 0 ) 161 161 res = 0.0f; 162 162 else 163 163 res /= (float)(tick - packetHistory.begin()->first); 164 164 165 165 res *= 1000.0f; 166 166 #endif 167 167 168 for ( std::map<int,int>:: iterator it = packetHistory.begin(); it != packetHistory.end(); it++ )168 for ( std::map<int,int>::const_iterator it = packetHistory.begin(); it != packetHistory.end(); it++ ) 169 169 { 170 170 res += it->second; 171 171 } 172 172 173 173 if ( packetHistory.size() <= 1 ) 174 174 res = 0.0f; 175 175 else 176 176 res /= (float)(tick - packetHistory.begin()->first); 177 177 178 178 res *= 1000.0f; 179 179 … … 191 191 { 192 192 nZOutgoingPackets++; 193 193 194 194 // calculate bandwidth 195 195 outgoingZippedPacketHistory[tick] = length; 196 196 outgoingZippedBandWidth = calculateBandWidth( outgoingZippedPacketHistory, tick ); 197 197 198 198 //NETPRINTF(n)("UPSTREAM: user: %d bandwidth %f nOutgoingPackets %d\n", userId, outgoingZippedBandWidth, nOutgoingPackets ); 199 199 … … 216 216 { 217 217 nZIncomingPackets++; 218 218 219 219 // calculate bandwidth 220 220 incomingZippedPacketHistory[tick] = length; 221 221 incomingZippedBandWidth = calculateBandWidth( incomingZippedPacketHistory, tick ); 222 222 223 223 //NETPRINTF(n)("DOWNSTREAM: user: %d bandwidth %f nIncomingPackets %d\n", userId, incomingZippedBandWidth, nIncomingPackets ); 224 224 225 225 } 226 226 … … 230 230 * @return true if last packet recieved \< NOW() - SECS_TO_TIMEOUT 231 231 */ 232 bool ConnectionMonitor::hasTimedOut( ) 232 bool ConnectionMonitor::hasTimedOut( ) const 233 233 { 234 234 if ( lastPacketTick + SECS_TO_TIMEOUT*1000 < SDL_GetTicks() && nIncomingPackets > 0 ) 235 235 return true; 236 236 237 237 if ( nIncomingPackets == 0 && nOutgoingPackets >= NETWORK_FREQUENCY*SECS_TO_TIMEOUT ) 238 238 return true; 239 239 240 240 return false; 241 241 } … … 246 246 * prints bandwith usage, ping and other important things to telnet-console 247 247 */ 248 void ConnectionMonitor::printStatis( ) 248 void ConnectionMonitor::printStatis( ) const 249 249 { 250 250 NETPRINT(n)("============NETWORKSTATS FOR USER %d============\n", userId); -
trunk/src/lib/network/monitor/connection_monitor.h
r9406 r9494 31 31 void calculatePing(); 32 32 33 bool hasTimedOut() ;33 bool hasTimedOut() const; 34 34 35 void printStatis(); 35 void printStatis() const; 36 float getIncomingUnzippedBandWidth() const { return incomingUnzippedBandWidth; } 37 float getOutgoingUnzippedBandWidth() const { return outgoingUnzippedBandWidth; } 38 float getIncomingZippedBandWidth() const { return incomingZippedBandWidth; } 39 float getOutgoingZippedBandWidth() const { return outgoingZippedBandWidth; } 36 40 37 41 private: -
trunk/src/lib/network/monitor/network_monitor.cc
r9406 r9494 31 31 32 32 33 SHELL_COMMAND(showGUI, NetworkMonitor, showGUI); 34 SHELL_COMMAND(hideGUI, NetworkMonitor, hideGUI); 33 #include "network_stats_widget.h" 34 35 SHELL_COMMAND(gui, NetworkMonitor, toggleGUI) 36 ->setAlias("ProxyGui"); 35 37 SHELL_COMMAND(debug, NetworkMonitor, debug); 36 38 … … 57 59 { 58 60 // assuming that the config files are already read we get the proxy servers 59 std::vector<IP address*>* proxyList = NetworkSettings::getInstance()->getProxyList();60 std::vector<IP address*>::iterator it = proxyList->begin();61 std::vector<IP>* proxyList = NetworkSettings::getInstance()->getProxyList(); 62 std::vector<IP>::iterator it = proxyList->begin(); 61 63 // create a peer info class and a network node class for each new proxy and add them to the passive list 62 64 for(; it < proxyList->end(); it++) 63 65 { 64 66 PeerInfo* peer = new PeerInfo(); 65 peer->ip = *(*it);67 peer->ip = (*it); 66 68 peer->nodeType = NET_PROXY_SERVER_ACTIVE; 67 69 peer->userId = -1; … … 72 74 } 73 75 } 76 this->box = NULL; 74 77 } 75 78 … … 119 122 * @param ip ip of the new node 120 123 */ 121 void NetworkMonitor::addNode( IPip, int nodeType)124 void NetworkMonitor::addNode(const IP& ip, int nodeType) 122 125 { 123 126 PeerInfo* pInfo = new PeerInfo(); … … 140 143 if( pInfo->isClient()) 141 144 this->localNode->addClient(pInfo); 142 else if( pInfo->isProxyServer ())145 else if( pInfo->isProxyServerActive()) 143 146 { 144 147 this->localNode->addActiveProxyServer(pInfo); … … 166 169 if( pInfo->isClient()) 167 170 node->addClient(pInfo); 168 else if( pInfo->isProxyServer ())171 else if( pInfo->isProxyServerActive()) 169 172 node->addActiveProxyServer(pInfo); 170 173 else if( pInfo->isMasterServer()) … … 176 179 * @returns the proxy server of the first choice 177 180 */ 178 PeerInfo* NetworkMonitor::getFirstChoiceProxy() 181 PeerInfo* NetworkMonitor::getFirstChoiceProxy() const 179 182 { 180 183 // return the fist proxy in the list … … 186 189 * @returns the proxy server of second choice 187 190 */ 188 PeerInfo* NetworkMonitor::getSecondChoiceProxy() 191 PeerInfo* NetworkMonitor::getSecondChoiceProxy() const 189 192 { 190 193 // return the second server in the list … … 196 199 * this displays the network monitor gui 197 200 */ 198 void NetworkMonitor:: showGUI()201 void NetworkMonitor::toggleGUI() 199 202 { 200 203 if (this->box == NULL) … … 202 205 this->box = new OrxGui::GLGuiBox(OrxGui::Vertical); 203 206 { 204 OrxGui::GLGuiBox* waterColorBox = new OrxGui::GLGuiBox(OrxGui::Horizontal); 205 { 206 OrxGui::GLGuiText* waterColorText = new OrxGui::GLGuiText(); 207 waterColorText->setText("NetworkMonitor"); 208 waterColorBox->pack(waterColorText); 209 } 210 this->box->pack(waterColorBox); 207 NetworkStatsWidget* netStats = new NetworkStatsWidget(this); 208 this->box->pack(netStats); 209 211 210 } 212 211 213 212 this->box->showAll(); 214 213 this->box->setAbsCoor2D(300, 40); 215 OrxGui::GLGuiHandler::getInstance()->activate(); 216 // OrxGui::GLGuiHandler::getInstance()->activateCursor(); 217 } 218 } 219 220 221 /** 222 * hides the network monitor gui again 223 */ 224 void NetworkMonitor::hideGUI() 225 { 226 if( this->box == NULL) 227 return; 228 229 OrxGui::GLGuiHandler::getInstance()->deactivate(); 230 // OrxGui::GLGuiHandler::getInstance()->deactivateCursor(); 231 232 delete this->box; 233 this->box = NULL; 234 } 235 214 } 215 else 216 { 217 delete this->box; 218 this->box = NULL; 219 } 220 } 236 221 237 222 /** … … 255 240 * prints out the debug informations 256 241 */ 257 void NetworkMonitor::debug() 242 void NetworkMonitor::debug() const 258 243 { 259 244 PRINT(0)("================================= Network Monitor::debug() =====\n"); 260 245 PRINT(0)(" I am: %s\n", this->localNode->getPeerInfo()->getNodeTypeString().c_str()); 261 PRINT(0)(" Total count of network connections: %i\n", this->playerNumber); 246 PRINT(0)(" Total count of network connections: %i\n", this->connectionNumber); 247 PRINT(0)(" Total count of players: %i\n", this->playerNumber); 262 248 PRINT(0)(" Max players on this server: %i\n", SharedNetworkData::getInstance()->getMaxPlayer()); 263 249 264 std::list<NetworkNode*>:: iterator it = this->nodeList.begin();250 std::list<NetworkNode*>::const_iterator it = this->nodeList.begin(); 265 251 for(; it != this->nodeList.end(); it++) 266 252 { -
trunk/src/lib/network/monitor/network_monitor.h
r9406 r9494 37 37 38 38 void addNode(PeerInfo* pInfo); 39 void addNode( IPip, int nodeType);39 void addNode(const IP& ip, int nodeType); 40 40 void addNode(NetworkNode* node) { this->nodeList.push_back(node); } 41 41 void addNode(NetworkNode* node, PeerInfo* pInfo); … … 55 55 inline void removeMasterServer(NetworkNode* node, PeerInfo* pInfo) { node->removeMasterServer(pInfo); } 56 56 57 PeerInfo* getFirstChoiceProxy(); 58 PeerInfo* getSecondChoiceProxy(); 57 PeerInfo* getFirstChoiceProxy() const; 58 PeerInfo* getSecondChoiceProxy() const; 59 /** @returns the local node */ 60 inline NetworkNode* getLocalNode() const { return this->localNode; }; 59 61 60 62 /** @returns the active proxy server list of the localnode */ 61 inline std::list<PeerInfo*> getActiveProxyServer() { return this->localNode->getActiveProxyServer(); }63 inline std::list<PeerInfo*> getActiveProxyServer() const { return this->localNode->getActiveProxyServer(); } 62 64 63 65 /* slots admin and info interface */ 64 66 /** @returns the total number of players in this game (including all proxy servers etc)*/ 65 inline int getPlayerNumber() { return this->playerNumber; }67 inline int getPlayerNumber() const { return this->playerNumber; } 66 68 67 69 /** @returns true if there are still free network slots available at the local node*/ 68 inline bool gotFreeSlots() { return (this->localNode->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer())?true:false; }70 inline bool gotFreeSlots() const { return (this->localNode->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer()); } 69 71 /** @param node node to be checked for slots @returns true if there are still free network slots available at this node */ 70 inline bool gotFreeSlots(NetworkNode* node) { return (node->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer())?true:false; }72 inline bool gotFreeSlots(NetworkNode* node) const { return (node->getPlayerNumber() < SharedNetworkData::getInstance()->getMaxPlayer()); } 71 73 72 74 /** @returns true if the next client should be reconnected to some other proxy server with more connections */ 73 inline bool isReconnectNextClient() { return (this->localNode->getPlayerNumber() >= SharedNetworkData::getInstance()->getMaxPlayer())?true:false; }75 inline bool isReconnectNextClient() const { return (this->localNode->getPlayerNumber() >= SharedNetworkData::getInstance()->getMaxPlayer()); } 74 76 77 inline const std::list<NetworkNode*>& getNodeList() const { return this->nodeList; }; 75 78 76 void showGUI(); 77 void hideGUI(); 79 void toggleGUI(); 78 80 79 81 void process(); 80 void debug() ;82 void debug() const; 81 83 82 84 -
trunk/src/lib/network/monitor/network_node.cc
r9406 r9494 152 152 * @return the client in the list or NULL if none 153 153 */ 154 PeerInfo* NetworkNode::getClient(int index) 154 PeerInfo* NetworkNode::getClient(int index) const 155 155 { 156 156 if( this->clientList.size() < index) 157 157 return NULL; 158 158 159 std::list<PeerInfo*>:: iterator it = this->clientList.begin();159 std::list<PeerInfo*>::const_iterator it = this->clientList.begin(); 160 160 for(int i = 0; it != this->clientList.end(); it++, i++) 161 161 { … … 172 172 * @return the active proxy server in the list or NULL if none 173 173 */ 174 PeerInfo* NetworkNode::getActiveProxyServer(int index) 174 PeerInfo* NetworkNode::getActiveProxyServer(int index) const 175 175 { 176 176 if( this->activeProxyServerList.size() < index) 177 177 return NULL; 178 178 179 std::list<PeerInfo*>:: iterator it = this->activeProxyServerList.begin();179 std::list<PeerInfo*>::const_iterator it = this->activeProxyServerList.begin(); 180 180 for(int i = 0; it != this->activeProxyServerList.end(); it++, i++) 181 181 { … … 192 192 * @return the passive proxy server in the list or NULL if none 193 193 */ 194 PeerInfo* NetworkNode::getPassiveProxyServer(int index) 194 PeerInfo* NetworkNode::getPassiveProxyServer(int index) const 195 195 { 196 196 if( this->passiveProxyServerList.size() < index) 197 197 return NULL; 198 198 199 std::list<PeerInfo*>:: iterator it = this->passiveProxyServerList.begin();199 std::list<PeerInfo*>::const_iterator it = this->passiveProxyServerList.begin(); 200 200 for(int i = 0; it != this->passiveProxyServerList.end(); it++, i++) 201 201 { … … 212 212 * @return the master server in the list or NULL if none 213 213 */ 214 PeerInfo* NetworkNode::getMasterServer(int index) 214 PeerInfo* NetworkNode::getMasterServer(int index) const 215 215 { 216 216 if( this->masterServerList.size() < index) 217 217 return NULL; 218 218 219 std::list<PeerInfo*>:: iterator it = this->masterServerList.begin();219 std::list<PeerInfo*>::const_iterator it = this->masterServerList.begin(); 220 220 for(int i = 0; it != this->masterServerList.end(); it++, i++) 221 221 { … … 232 232 * @param depth: depth in the tree 233 233 */ 234 void NetworkNode::debug(int depth) 234 void NetworkNode::debug(int depth) const 235 235 { 236 236 PRINT(0)(" = %s\n", this->peerInfo->getNodeTypeString().c_str()); 237 237 238 238 PRINT(0)(" master servers: %i\n", this->masterServerList.size()); 239 std::list<PeerInfo*>:: iterator it = this->masterServerList.begin();239 std::list<PeerInfo*>::const_iterator it = this->masterServerList.begin(); 240 240 for(; it != this->masterServerList.end(); it++) 241 241 { -
trunk/src/lib/network/monitor/network_node.h
r9406 r9494 32 32 void removeMasterServer(PeerInfo* node); 33 33 34 PeerInfo* getClient(int index) ;35 PeerInfo* getActiveProxyServer(int index) ;36 PeerInfo* getPassiveProxyServer(int index) ;37 PeerInfo* getMasterServer(int index) ;34 PeerInfo* getClient(int index) const; 35 PeerInfo* getActiveProxyServer(int index) const; 36 PeerInfo* getPassiveProxyServer(int index) const; 37 PeerInfo* getMasterServer(int index) const; 38 38 39 39 /** @returns the master server list */ 40 inline std::list<PeerInfo*> getMasterServer() { return this->masterServerList; }40 inline std::list<PeerInfo*> getMasterServer() const { return this->masterServerList; } 41 41 /** @returns the active proxy server list */ 42 inline std::list<PeerInfo*> getActiveProxyServer() { return this->activeProxyServerList; }42 inline std::list<PeerInfo*> getActiveProxyServer() const { return this->activeProxyServerList; } 43 43 /** @returns the passive proxy server list */ 44 inline std::list<PeerInfo*> getPassiveProxyServer() { return this->passiveProxyServerList; }44 inline std::list<PeerInfo*> getPassiveProxyServer() const { return this->passiveProxyServerList; } 45 45 /** @returns the client list */ 46 inline std::list<PeerInfo*> getClient() { return this->clientList; }46 inline std::list<PeerInfo*> getClient() const { return this->clientList; } 47 47 48 48 49 49 /** @returns the number of players */ 50 inline int getPlayerNumber() { return this->playerNumber; }50 inline int getPlayerNumber() const { return this->playerNumber; } 51 51 /** @returns the node type of this node */ 52 inline int getNodeType() { return this->peerInfo->nodeType; }52 inline int getNodeType() const { return this->peerInfo->nodeType; } 53 53 /** @returns the peer info of this node */ 54 inline PeerInfo* getPeerInfo() { return this->peerInfo; }54 inline PeerInfo* getPeerInfo() const { return this->peerInfo; } 55 55 56 void debug(int depth) ;56 void debug(int depth) const; 57 57 58 58 … … 60 60 int playerNumber; //!< localy direct connected player number 61 61 int connectionNumber; //!< number of connections ( can but musn't be equal players) 62 PeerInfo* peerInfo; //!< the peer information aabout this node62 PeerInfo* peerInfo; //!< the peer information about this node 63 63 64 64 /* network nodes directly connected to this node */ -
trunk/src/lib/network/netdefs.h
r9406 r9494 43 43 44 44 45 46 45 47 //!< enum indicating the type of the node 46 48 typedef enum { 47 NET_MASTER_SERVER, 49 NET_UNASSIGNED = -1, 50 51 NET_MASTER_SERVER = 0, 48 52 NET_PROXY_SERVER_ACTIVE, 49 53 NET_PROXY_SERVER_PASSIVE, … … 54 58 } NodeType; 55 59 60 56 61 //!< enum indicating the type of the network connection (2 protocols supported) 57 62 typedef enum ConnectionType { … … 60 65 }; 61 66 62 //!< the type of the user id (special number never used elsewhere) 67 68 //!< the type of the unique id (special number never used elsewhere) 63 69 typedef enum { 64 70 NET_UID_UNASSIGNED = -1, 71 72 NET_UID_HANDSHAKE = 0, 73 65 74 66 75 NET_UID_NUMBER 67 76 } UidType; 68 77 78 79 //!< the network id list 80 typedef enum nodeId { 81 NET_ID_UNASSIGNED =-1, 82 83 NET_ID_MASTER_SERVER = 0, 84 85 NET_ID_PROXY_SERVER_01 = 1, 86 NET_ID_PROXY_SERVER_02, 87 NET_ID_PROXY_SERVER_03, 88 NET_ID_PROXY_SERVER_04, 89 NET_ID_PROXY_SERVER_05, 90 NET_ID_PROXY_SERVER_06, 91 NET_ID_PROXY_SERVER_07, 92 NET_ID_PROXY_SERVER_08 = 8, 93 94 NET_ID_PROXY_MAX = 8, 95 96 NET_ID_CLIENT_01 = 9, 97 NET_ID_CLIENT_02, 98 NET_ID_CLIENT_03, 99 NET_ID_CLIENT_04, 100 NET_ID_CLIENT_05, 101 NET_ID_CLIENT_06, 102 NET_ID_CLIENT_07, 103 NET_ID_CLIENT_08, 104 NET_ID_CLIENT_09, 105 NET_ID_CLIENT_10, 106 NET_ID_CLIENT_11, 107 NET_ID_CLIENT_12, 108 NET_ID_CLIENT_13, 109 NET_ID_CLIENT_14, 110 NET_ID_CLIENT_15, 111 NET_ID_CLIENT_16, 112 NET_ID_CLIENT_17, 113 NET_ID_CLIENT_18, 114 NET_ID_CLIENT_19, 115 NET_ID_CLIENT_20, 116 NET_ID_CLIENT_21, 117 NET_ID_CLIENT_22, 118 NET_ID_CLIENT_23, 119 NET_ID_CLIENT_24, 120 NET_ID_CLIENT_25, 121 NET_ID_CLIENT_26, 122 NET_ID_CLIENT_27, 123 NET_ID_CLIENT_28, 124 NET_ID_CLIENT_29, 125 NET_ID_CLIENT_30, 126 NET_ID_CLIENT_31, 127 NET_ID_CLIENT_32, 128 NET_ID_CLIENT_33, 129 NET_ID_CLIENT_34, 130 NET_ID_CLIENT_35, 131 NET_ID_CLIENT_36, 132 NET_ID_CLIENT_37, 133 NET_ID_CLIENT_38, 134 NET_ID_CLIENT_39, 135 NET_ID_CLIENT_40, 136 137 NET_ID_CLIENT_MAX = 40 138 }; 69 139 #endif /* _NETDEFS_H */ -
trunk/src/lib/network/nettypes.h
r9406 r9494 5 5 typedef unsigned char byte; 6 6 7 8 //!< this are the network write variable permissions 9 typedef enum netPermissions { 10 PERMISSION_MASTER_SERVER = 1, 11 PERMISSION_PROXY_SERVER = 2, 12 PERMISSION_OWNER = 4, 13 PERMISSION_ALL = 8 14 }; 15 16 7 17 #endif /* __NET_TYPES_H */ -
trunk/src/lib/network/network_game_manager.cc
r9406 r9494 91 91 bool NetworkGameManager::signalNewPlayer( int userId ) 92 92 { 93 assert( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer ());93 assert( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServerActive()); 94 94 assert( State::getGameRules() ); 95 95 assert( State::getGameRules()->isA( CL_NETWORK_GAME_RULES ) ); … … 168 168 bool NetworkGameManager::delSynchronizeableHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 169 169 { 170 if ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer()) 171 { 172 PRINTF(2)("Recieved DeleteSynchronizeable message from client %d!\n", userId); 170 171 PRINTF(0)(" del synchronizeable\n"); 172 173 if ( SharedNetworkData::getInstance()->isMasterServer() || 174 SharedNetworkData::getInstance()->isProxyServerActive() && SharedNetworkData::getInstance()->isUserClient(userId)) 175 { 176 PRINTF(0)("Recieved DeleteSynchronizeable message from client %d!\n", userId); 173 177 return true; 174 178 } … … 213 217 assert( Converter::intToByteArray( uniqueId, buf, INTSIZE ) == INTSIZE ); 214 218 215 MessageManager::getInstance()->sendMessage( MSGID_DELETESYNCHRONIZEABLE, buf, INTSIZE, RT_ALL_ NOT_ME, 0, MP_HIGHBANDWIDTH );219 MessageManager::getInstance()->sendMessage( MSGID_DELETESYNCHRONIZEABLE, buf, INTSIZE, RT_ALL_BUT_ME, 0, MP_HIGHBANDWIDTH ); 216 220 } 217 221 … … 229 233 bool NetworkGameManager::preferedTeamHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 230 234 { 231 assert( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer ());235 assert( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServerActive()); 232 236 233 237 int teamId = 0; … … 261 265 void NetworkGameManager::prefereTeam( int teamId ) 262 266 { 263 if ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer())267 if ( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/) 264 268 setPreferedTeam( SharedNetworkData::getInstance()->getHostID(), teamId ); 265 269 else … … 305 309 { 306 310 PRINTF(0)("NetworkGameManager::chatMessageHandler %d %d\n", userId, SharedNetworkData::getInstance()->getHostID() ); 307 if ( (SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer()) && userId != SharedNetworkData::getInstance()->getHostID() )308 { 309 MessageManager::getInstance()->sendMessage( messageId, data, dataLength, RT_ALL_ NOT_ME, 0, MP_HIGHBANDWIDTH );311 if ( (SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/) && userId != SharedNetworkData::getInstance()->getHostID() ) 312 { 313 MessageManager::getInstance()->sendMessage( messageId, data, dataLength, RT_ALL_BUT_ME, 0, MP_HIGHBANDWIDTH ); 310 314 } 311 315 … … 347 351 assert( Converter::stringToByteArray(message, buf+2*INTSIZE, message.length()+INTSIZE) == message.length()+INTSIZE ); 348 352 349 if ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer())353 if ( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/) 350 354 MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_ME, 0, MP_HIGHBANDWIDTH ); 351 355 else 352 MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_ NOT_ME, 0, MP_HIGHBANDWIDTH );356 MessageManager::getInstance()->sendMessage( MSGID_CHATMESSAGE, buf, message.length()+3*INTSIZE, RT_ALL_BUT_ME, 0, MP_HIGHBANDWIDTH ); 353 357 354 358 -
trunk/src/lib/network/network_manager.cc
r9406 r9494 101 101 /** 102 102 * creates a new NetworkStream of server type 103 * @param port: number of the TCP port 103 * @param clientPort: number of the TCP/UDP port for client connections 104 * @param proxyPort: number of the TCP/UDP port for proxy connections 104 105 */ 105 106 int NetworkManager::createMasterServer(unsigned int port) … … 110 111 // create the network stream 111 112 this->networkStream = new NetworkStream(NET_MASTER_SERVER); 112 this->networkStream->createServer( port );113 this->networkStream->createServer( port, port + 1); 113 114 114 115 // start the network game manager … … 129 130 NetworkSettings::getInstance()->loadData(); 130 131 131 // create the network stream 132 this->networkStream = new NetworkStream(NET_PROXY_SERVER_ACTIVE); 133 this->networkStream->createServer( port); 134 // and connect to the master server for synchronization 135 // this->networkStream->connectToMasterServer(NetworkSettings::getInstance()->getMasterAddr()); 136 // and to the other proxy servers 137 132 // create the network stream af 133 this->networkStream = new NetworkStream(NET_PROXY_SERVER_ACTIVE ); 134 // first connect to the master server for synchronization 135 this->networkStream->connectToMasterServer(NetworkSettings::getInstance()->getMasterAddr().ipString(), 10000); 136 // start the handshake with the master server 137 this->networkStream->startHandshake(NET_ID_MASTER_SERVER); 138 139 // then start the server 140 this->networkStream->createServer( port, port +1); 141 142 143 // and to the other proxy servers also, this would be very nice if its works 138 144 139 145 140 146 // start the network game manager 141 this->networkStream->createNetworkGameManager();147 //this->networkStream->createNetworkGameManager(); 142 148 143 149 … … 165 171 this->networkStream->startHandshake(); 166 172 167 PRINTF(0)("Created Network Client ");173 PRINTF(0)("Created Network Client\n"); 168 174 return 1; 169 175 } -
trunk/src/lib/network/network_manager.h
r9406 r9494 17 17 18 18 19 /* forward declarations for the header file (include the header via #include "bla.h" in the source file) */ 19 20 20 class NetworkStream; 21 21 class Synchronizeable; 22 template<typename> 23 class tList; 22 24 23 25 24 /* and here is the class itsself*/ -
trunk/src/lib/network/network_stream.cc
r9406 r9494 65 65 this->init(); 66 66 /* initialize the references */ 67 this->pInfo->nodeType = NET_ CLIENT;67 this->pInfo->nodeType = NET_UNASSIGNED; 68 68 } 69 69 … … 79 79 case NET_MASTER_SERVER: 80 80 // init the shared network data 81 SharedNetworkData::getInstance()->setHostID(0); 82 // SharedNetworkData::getInstance()->setNodeType(NET_MASTER_SERVER); 81 SharedNetworkData::getInstance()->setHostID(NET_ID_MASTER_SERVER); 83 82 break; 84 85 83 case NET_PROXY_SERVER_ACTIVE: 86 84 // init the shared network data 87 SharedNetworkData::getInstance()->setHostID(0); 88 // SharedNetworkData::getInstance()->setNodeType(NET_PROXY_SERVER_ACTIVE); 85 SharedNetworkData::getInstance()->setHostID(NET_ID_PROXY_SERVER_01); 89 86 break; 90 87 case NET_PROXY_SERVER_PASSIVE: 91 // init the shared network data 92 SharedNetworkData::getInstance()->setHostID(0); 93 // SharedNetworkData::getInstance()->setNodeType(NET_PROXY_SERVER_PASSIVE); 88 // init the shared network data 89 SharedNetworkData::getInstance()->setHostID(NET_ID_PROXY_SERVER_01); 94 90 break; 95 91 case NET_CLIENT: 96 // SharedNetworkData::getInstance()->setNodeType(NET_CLIENT);92 SharedNetworkData::getInstance()->setHostID(NET_ID_UNASSIGNED); 97 93 break; 98 94 } … … 115 111 /* set the class id for the base object */ 116 112 this->setClassID(CL_NETWORK_STREAM, "NetworkStream"); 117 this->serverSocket = NULL; 113 this->clientSocket = NULL; 114 this->proxySocket = NULL; 118 115 this->networkGameManager = NULL; 119 116 this->networkMonitor = NULL; … … 124 121 this->pInfo->lastRecvedState = 0; 125 122 123 this->bRedirect = false; 126 124 127 125 this->currentState = 0; … … 142 140 NetworkStream::~NetworkStream() 143 141 { 144 if ( this->serverSocket ) 145 { 146 serverSocket->close(); 147 delete serverSocket; 148 serverSocket = NULL; 142 if ( this->clientSocket ) 143 { 144 clientSocket->close(); 145 delete clientSocket; 146 clientSocket = NULL; 147 } 148 if ( this->proxySocket) 149 { 150 proxySocket->close(); 151 delete proxySocket; 152 proxySocket = NULL; 149 153 } 150 154 for ( PeerList::iterator i = peers.begin(); i!=peers.end(); i++) … … 187 191 void NetworkStream::connectToMasterServer(std::string host, int port) 188 192 { 189 int node = this->peers.size(); 193 int node = NET_ID_MASTER_SERVER; 194 // this create the new node in the peers map 190 195 this->peers[node].socket = new UdpSocket( host, port ); 191 this->peers[node].userId = 0;196 this->peers[node].userId = NET_ID_MASTER_SERVER; 192 197 193 198 this->peers[node].nodeType = NET_MASTER_SERVER; 194 this->peers[node].connectionMonitor = new ConnectionMonitor( 0);199 this->peers[node].connectionMonitor = new ConnectionMonitor( NET_ID_MASTER_SERVER ); 195 200 this->peers[node].ip = this->peers[node].socket->getRemoteAddress(); 196 201 } … … 202 207 * @param port: the port number 203 208 */ 204 void NetworkStream::connectToProxyServer(std::string host, int port) 205 { 206 int node = this->peers.size(); 207 this->peers[node].socket = new UdpSocket( host, port ); 208 this->peers[node].userId = 0; 209 210 this->peers[node].nodeType = NET_PROXY_SERVER_ACTIVE; 211 this->peers[node].connectionMonitor = new ConnectionMonitor( 0 ); 212 this->peers[node].ip = this->peers[node].socket->getRemoteAddress(); 209 void NetworkStream::connectToProxyServer(int proxyId, std::string host, int port) 210 { 211 PRINTF(0)("connect to proxy %s, this is proxyId %i\n", host.c_str(), proxyId); 212 213 // this creates the new proxyId in the peers map 214 this->peers[proxyId].socket = new UdpSocket( host, port ); 215 this->peers[proxyId].userId = proxyId; 216 217 this->peers[proxyId].nodeType = NET_PROXY_SERVER_ACTIVE; 218 this->peers[proxyId].connectionMonitor = new ConnectionMonitor( proxyId ); 219 this->peers[proxyId].ip = this->peers[proxyId].socket->getRemoteAddress(); 213 220 } 214 221 … … 218 225 * @param port: interface port for all clients 219 226 */ 220 void NetworkStream::createServer(int port) 221 { 222 this->serverSocket = new UdpServerSocket(port); 227 void NetworkStream::createServer(int clientPort, int proxyPort) 228 { 229 PRINTF(0)(" Creating new Server: listening for clients on port %i and for proxies on port %i", clientPort, proxyPort); 230 this->clientSocket= new UdpServerSocket(clientPort); 231 this->proxySocket = new UdpServerSocket(proxyPort); 223 232 } 224 233 … … 240 249 * handsakes are always initialized from the client side first. this starts the handshake and therefore is only 241 250 * executed as client 242 */ 243 void NetworkStream::startHandshake() 251 * @param userId: start handshake for this user id (optional, default == 0) 252 */ 253 void NetworkStream::startHandshake(int userId) 244 254 { 245 255 Handshake* hs = new Handshake(this->pInfo->nodeType); 246 hs->setUniqueID( 0 ); 247 assert( peers[0].handshake == NULL ); 248 peers[0].handshake = hs; 256 // fake the unique id 257 hs->setUniqueID( NET_UID_HANDSHAKE ); 258 assert( peers[userId].handshake == NULL ); 259 peers[userId].handshake = hs; 249 260 250 261 // set the preferred nick name … … 259 270 * it all over the network and creating it on the other platforms (if and only if it is a 260 271 * server 272 * @param sync: the synchronizeable to add 261 273 */ 262 274 void NetworkStream::connectSynchronizeable(Synchronizeable& sync) … … 264 276 this->synchronizeables.push_back(&sync); 265 277 sync.setNetworkStream( this ); 266 267 // this->bActive = true;268 278 } 269 279 … … 271 281 /** 272 282 * removes the synchronizeable from the list of synchronized entities 283 * @param sync: the syncronizeable to remove 273 284 */ 274 285 void NetworkStream::disconnectSynchronizeable(Synchronizeable& sync) … … 302 313 } 303 314 304 if ( this->pInfo->isMasterServer())315 if ( SharedNetworkData::getInstance()->isMasterServer()) 305 316 { 306 317 // execute everytthing the master server shoudl do 307 if ( serverSocket ) 308 serverSocket->update(); 318 if ( this->clientSocket ) 319 this->clientSocket->update(); 320 if( this->proxySocket) 321 this->proxySocket->update(); 309 322 310 323 this->updateConnectionList(); 311 324 } 312 else if( this->pInfo->isProxyServer()) 313 { 314 // execute everything the proxy server should do 315 if ( serverSocket ) 316 serverSocket->update(); 325 else if( SharedNetworkData::getInstance()->isProxyServerActive()) 326 { 327 //execute everything the proxy server should do 328 if ( this->clientSocket ) 329 this->clientSocket->update(); 330 if( this->proxySocket) 331 this->proxySocket->update(); 317 332 318 333 this->updateConnectionList(); 319 334 } 320 else 335 336 #warning make this more modular: every proxy/master server connection should be watched for termination 337 if( !SharedNetworkData::getInstance()->isMasterServer()) 321 338 { 322 339 // check if the connection is ok else terminate and remove 323 if ( peers[0].socket && ( !peers[0].socket->isOk() || peers[0].connectionMonitor->hasTimedOut() ) ) 324 { 340 if ( !peers.empty() && peers[NET_ID_MASTER_SERVER].socket && 341 ( !peers[NET_ID_MASTER_SERVER].socket->isOk() || 342 peers[NET_ID_MASTER_SERVER].connectionMonitor->hasTimedOut() ) ) 343 { 344 this->handleDisconnect( NET_ID_MASTER_SERVER); 325 345 PRINTF(1)("lost connection to server\n"); 326 327 peers[0].socket->disconnectServer(); 328 delete peers[0].socket; 329 peers[0].socket = NULL; 330 331 if ( peers[0].handshake ) 332 delete peers[0].handshake; 333 peers[0].handshake = NULL; 334 335 if ( peers[0].connectionMonitor ) 336 delete peers[0].connectionMonitor; 337 peers[0].connectionMonitor = NULL; 338 } 339 } 340 341 cleanUpOldSyncList(); 342 handleHandshakes(); 346 } 347 // check if there is a redirection command 348 if( this->bRedirect) 349 { 350 this->handleReconnect( NET_ID_MASTER_SERVER); 351 } 352 } 353 354 this->cleanUpOldSyncList(); 355 this->handleHandshakes(); 343 356 344 357 // update the network monitor … … 347 360 // order of up/downstream is important!!!! 348 361 // don't change it 349 handleDownstream( tick ); 350 handleUpstream( tick ); 351 } 352 353 354 /** 355 * if we are a NET_MASTER_SERVER or NET_PROXY_SERVER_ACTIVE update the connection list to accept new 356 * connections (clients) also start the handsake for the new clients 362 this->handleDownstream( tick ); 363 this->handleUpstream( tick ); 364 } 365 366 367 /** 368 * @brief handles incoming connections 369 * 370 * if we are a NET_MASTER_SERVER or NET_PROXY_SERVER_ACTIVE update the connection list to accept new connections (clients) 371 * start and initialize the handsake for the new clients 357 372 */ 358 373 void NetworkStream::updateConnectionList( ) … … 360 375 //check for new connections 361 376 362 NetworkSocket* tempNetworkSocket = serverSocket->getNewSocket();363 364 // we got new network node 365 if ( tempNetworkSocket)366 { 367 int clientId;368 // if there is a list of free client id slots, take these 369 if ( freeSocketSlots.size() > 0 )370 {371 clientId = freeSocketSlots.back();372 freeSocketSlots.pop_back();373 }374 else375 {376 clientId = 1;377 378 for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ )379 if ( it->first >= clientId )380 clientId = it->first +1;381 } 382 peers[clientId].socket = tempNetworkSocket;383 384 385 // create new handshake and init its variables386 peers[clientId].handshake = new Handshake(this->pInfo->nodeType, clientId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID());387 peers[clientId].handshake->setUniqueID(clientId);388 389 peers[clientId].connectionMonitor = new ConnectionMonitor( clientId ); 390 peers[clientId].userId = clientId;391 392 PRINTF(0)("num sync: %d\n", synchronizeables.size()); 393 394 // get the proxy server informations and write them to the handshake, if any (proxy)395 assert( this->networkMonitor != NULL);396 PeerInfo* pi = this->networkMonitor->getFirstChoiceProxy(); 397 if( pi != NULL) 398 {399 peers[clientId].handshake->setProxy1Address( pi->ip);400 }401 pi = this->networkMonitor->getSecondChoiceProxy(); 402 if( pi != NULL)403 peers[clientId].handshake->setProxy2Address( pi->ip);404 405 // check if the connecting client should reconnect to a proxy server406 peers[clientId].handshake->setRedirect(/*this->networkMonitor->isReconnectNextClient()*/false);407 408 // the connecting node of course is a client409 peers[clientId].nodeType = NET_CLIENT;410 peers[clientId].ip = peers[clientId].socket->getRemoteAddress();411 412 413 // check if there are too many clients connected (DEPRECATED: new: the masterserver sends a list of proxy servers)414 // if ( clientId > SharedNetworkData::getInstance()->getMaxPlayer() ) 415 // { 416 // // peers[clientId].handshake->setRedirect(true); 417 // // 418 // // peers[clientId].handshake->doReject( "too many connections" ); 419 // PRINTF(0)("Will reject client %d because there are to many connections!\n", clientId); 420 // } 421 // else 422 // { 423 // PRINTF(0)("New Client: %d\n", clientId); 424 // } 425 PRINTF(0)("New Client: %d\n", clientId);426 427 428 }429 377 NetworkSocket* tempNetworkSocket = NULL; 378 int userId; 379 380 if( this->clientSocket != NULL) 381 { 382 tempNetworkSocket = this->clientSocket->getNewSocket(); 383 384 // we got new NET_CLIENT connecting 385 if ( tempNetworkSocket ) 386 { 387 // determine the network node id 388 if ( freeSocketSlots.size() > 0 ) 389 { 390 userId = freeSocketSlots.back(); 391 freeSocketSlots.pop_back(); 392 } 393 else 394 { 395 userId = 1; 396 397 for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ ) 398 if ( it->first >= userId ) 399 userId = it->first + 1; 400 } 401 // this creates a new entry in the peers list 402 peers[userId].socket = tempNetworkSocket; 403 peers[userId].nodeType = NET_CLIENT; 404 405 // handle the newly connected client 406 this->handleConnect(userId); 407 408 PRINTF(0)("New Client: %d\n", userId); 409 } 410 } 411 412 413 if( this->proxySocket != NULL) 414 { 415 tempNetworkSocket = this->proxySocket->getNewSocket(); 416 417 // we got new NET_PROXY_SERVER_ACTIVE connecting 418 if ( tempNetworkSocket ) 419 { 420 // determine the network node id 421 if ( freeSocketSlots.size() > 0 ) 422 { 423 userId = freeSocketSlots.back(); 424 freeSocketSlots.pop_back(); 425 } 426 else 427 { 428 userId = 1; 429 430 for ( PeerList::iterator it = peers.begin(); it != peers.end(); it++ ) 431 if ( it->first >= userId ) 432 userId = it->first + 1; 433 } 434 435 // this creates a new entry in the peers list 436 peers[userId].socket = tempNetworkSocket; 437 peers[userId].nodeType = NET_PROXY_SERVER_ACTIVE; 438 439 // handle the newly connected proxy server 440 this->handleConnect(userId); 441 442 PRINTF(0)("New proxy connected: %d\n", userId); 443 } 444 } 430 445 431 446 … … 446 461 PRINTF(0)("Client is gone: %d (%s)\n", it->second.userId, reason.c_str()); 447 462 448 449 // clean up the network data 450 it->second.socket->disconnectServer(); 451 delete it->second.socket; 452 it->second.socket = NULL; 453 454 // remove the old connectin monitor 455 if ( it->second.connectionMonitor ) 456 delete it->second.connectionMonitor; 457 it->second.connectionMonitor = NULL; 458 459 // remove the handshake 460 if ( it->second.handshake ) 461 delete it->second.handshake; 462 it->second.handshake = NULL; 463 464 // and cleanup the user infos 465 for ( SynchronizeableList::iterator it2 = synchronizeables.begin(); it2 != synchronizeables.end(); it2++ ) 466 { 467 (*it2)->cleanUpUser( it->second.userId ); 468 } 469 470 NetworkGameManager::getInstance()->signalLeftPlayer(it->second.userId); 471 472 freeSocketSlots.push_back( it->second.userId ); 473 474 PeerList::iterator delit = it; 463 this->handleDisconnect( it->second.userId); 464 475 465 it++; 476 477 peers.erase( delit );478 479 466 continue; 480 467 } … … 487 474 488 475 476 /** 477 * this handles new connections 478 * @param userId: the id of the new user node 479 */ 480 void NetworkStream::handleConnect( int userId) 481 { 482 // create new handshake and init its variables 483 peers[userId].handshake = new Handshake(this->pInfo->nodeType, userId, this->networkGameManager->getUniqueID(), MessageManager::getInstance()->getUniqueID()); 484 peers[userId].handshake->setUniqueID(userId); 485 486 peers[userId].connectionMonitor = new ConnectionMonitor( userId ); 487 peers[userId].userId = userId; 488 489 PRINTF(0)("num sync: %d\n", synchronizeables.size()); 490 491 // get the proxy server informations and write them to the handshake, if any (proxy) 492 assert( this->networkMonitor != NULL); 493 PeerInfo* pi = this->networkMonitor->getFirstChoiceProxy(); 494 if( pi != NULL) 495 { 496 peers[userId].handshake->setProxy1Address( pi->ip); 497 } 498 pi = this->networkMonitor->getSecondChoiceProxy(); 499 if( pi != NULL) 500 peers[userId].handshake->setProxy2Address( pi->ip); 501 502 // check if the connecting client should reconnect to a proxy server 503 if( SharedNetworkData::getInstance()->isMasterServer()) 504 peers[userId].handshake->setRedirect(/*this->networkMonitor->isReconnectNextClient()*/false); 505 506 // the connecting node of course is a client 507 peers[userId].ip = peers[userId].socket->getRemoteAddress(); 508 } 509 510 511 512 /** 513 * some debug output 514 */ 489 515 void NetworkStream::debug() 490 516 { … … 492 518 PRINT(0)(" Host ist Master Server with ID: %i\n", this->pInfo->userId); 493 519 } 494 else if( SharedNetworkData::getInstance()->isProxyServer ()) {520 else if( SharedNetworkData::getInstance()->isProxyServerActive()) { 495 521 PRINT(0)(" Host ist Proxy Server with ID: %i\n", this->pInfo->userId); 496 522 } … … 541 567 if ( it->second.handshake->ok() ) 542 568 { 543 // the server gave it free for deletion 569 // write the first informations into the node so they can be read from there for case differentiation 570 it->second.nodeType = it->second.handshake->getRemoteNodeType(); 571 572 // the counter part didn't mark it free for deletion yet 544 573 if ( !it->second.handshake->allowDel() ) 545 574 { 546 547 if ( this->pInfo->isClient() ) 575 // make sure this is a connection: 576 // - client <==> master server 577 // - proxy server <==> master server 578 if( SharedNetworkData::getInstance()->isClient() || SharedNetworkData::getInstance()->isProxyServerActive() && it->second.isMasterServer()) 548 579 { 580 PRINTF(0)("Handshake: i am in client role\n"); 581 549 582 SharedNetworkData::getInstance()->setHostID( it->second.handshake->getHostId() ); 550 583 this->pInfo->userId = SharedNetworkData::getInstance()->getHostID(); 551 584 552 it->second.nodeType = it->second.handshake->getRemoteNodeType(); 553 it->second.ip = it->second.socket->getRemoteAddress(); 585 #warning the ip address is not set here because it results in a segfault when connecting to a proxy server => trace this later 586 // it->second.ip = it->second.socket->getRemoteAddress(); 587 588 // it->second.nodeType = it->second.handshake->getRemoteNodeType(); 589 // it->second.ip = it->second.socket->getRemoteAddress(); 554 590 // add the new server to the nodes list (it can be a NET_MASTER_SERVER or NET_PROXY_SERVER) 555 591 this->networkMonitor->addNode(&it->second); … … 560 596 561 597 // now check if the server accepted the connection 562 if( it->second.handshake->redirect()) 563 this->handleReconnect( it->second.userId); 598 if( SharedNetworkData::getInstance()->isClient() && it->second.handshake->redirect() ) 599 { 600 this->bRedirect = true; 601 } 564 602 565 603 // create the new network game manager and init it … … 570 608 } 571 609 572 573 610 PRINT(0)("handshake finished id=%d\n", it->second.handshake->getNetworkGameManagerId()); 574 611 it->second.handshake->del(); 612 575 613 } 576 614 else … … 580 618 { 581 619 582 if ( this->pInfo->isMasterServer() )620 if ( SharedNetworkData::getInstance()->isMasterServer() ) 583 621 { 584 it->second.nodeType = it->second.handshake->getRemoteNodeType();585 622 it->second.ip = it->second.socket->getRemoteAddress(); 586 623 … … 594 631 } 595 632 } 596 else if ( this->pInfo->isProxyServer() )633 else if ( SharedNetworkData::getInstance()->isProxyServerActive() && it->second.isClient() ) 597 634 { 598 it->second.nodeType = it->second.handshake->getRemoteNodeType(); 635 PRINTF(0)("Handshake: i am in server role\n"); 636 599 637 it->second.ip = it->second.socket->getRemoteAddress(); 600 638 … … 632 670 void NetworkStream::handleReconnect(int userId) 633 671 { 672 this->bRedirect = false; 673 PeerInfo* pInfo = &this->peers[userId]; 674 634 675 PRINTF(0)("===============================================\n"); 635 676 PRINTF(0)("Client is redirected to the other proxy servers\n"); 677 PRINTF(0)(" user id: %i\n", userId); 678 PRINTF(0)(" connecting to: %s\n", this->networkMonitor->getFirstChoiceProxy()->ip.ipString().c_str()); 636 679 PRINTF(0)("===============================================\n"); 637 638 return;639 640 PeerInfo* pInfo = &this->peers[userId];641 642 // reject the server643 pInfo->handshake->doReject( "redirected to different server");644 680 645 681 // flush the old synchronization states, since the numbering could be completely different 646 682 pInfo->lastAckedState = 0; 647 683 pInfo->lastRecvedState = 0; 648 // not sure if this works as expected 649 if( pInfo->handshake)650 delete pInfo->handshake;684 685 // temp save the ip address here 686 IP proxyIP = pInfo->handshake->getProxy1Address(); 651 687 652 688 // disconnect from the current server and reconnect to proxy server 653 pInfo->socket->reconnectToServer( pInfo->handshake->getProxy1Address().ipString(), pInfo->handshake->getProxy1Address().port()); 689 this->handleDisconnect( userId); 690 this->connectToProxyServer(NET_ID_PROXY_SERVER_01, proxyIP.ipString(), 9999); 691 #warning the ports are not yet integrated correctly in the ip class 654 692 655 693 // and restart the handshake 656 this->startHandshake(); 657 } 694 this->startHandshake( userId); 695 } 696 697 698 /** 699 * handles the disconnect event 700 * @param userId id of the user to remove 701 */ 702 void NetworkStream::handleDisconnect( int userId ) 703 { 704 peers[userId].socket->disconnectServer(); 705 delete peers[userId].socket; 706 peers[userId].socket = NULL; 707 708 if ( peers[userId].handshake ) 709 delete peers[userId].handshake; 710 peers[userId].handshake = NULL; 711 712 if ( peers[userId].connectionMonitor ) 713 delete peers[userId].connectionMonitor; 714 peers[userId].connectionMonitor = NULL; 715 716 717 for ( SynchronizeableList::iterator it2 = synchronizeables.begin(); it2 != synchronizeables.end(); it2++ ) { 718 (*it2)->cleanUpUser( userId ); 719 } 720 721 if( SharedNetworkData::getInstance()->isMasterServer()) 722 NetworkGameManager::getInstance()->signalLeftPlayer(userId); 723 724 this->freeSocketSlots.push_back( userId ); 725 726 peers.erase( userId); 727 } 728 658 729 659 730 660 731 /** 661 732 * handle upstream network traffic 733 * @param tick: seconds elapsed since last update 662 734 */ 663 735 void NetworkStream::handleUpstream( int tick ) … … 698 770 699 771 // do not include synchronizeables with uninit id and syncs that don't want to be synchronized 700 if ( !sync.beSynchronized() || sync.getUniqueID() < 0)772 if ( !sync.beSynchronized() || sync.getUniqueID() <= NET_UID_UNASSIGNED ) 701 773 continue; 702 774 … … 706 778 707 779 // if we are a server (both master and proxy servers) and this is not our handshake 708 if ( ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer() ) && sync.getLeafClassID() == CL_HANDSHAKE && sync.getUniqueID() != peer->second.userId ) 780 if ( ( SharedNetworkData::getInstance()->isMasterServer() || 781 SharedNetworkData::getInstance()->isProxyServerActive() && peer->second.isClient()) 782 && sync.getLeafClassID() == CL_HANDSHAKE && sync.getUniqueID() != peer->second.userId ) 709 783 continue; 710 784 … … 720 794 721 795 // server fakes uniqueid == 0 for handshake 722 if ( ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer() ) && 796 if ( ( SharedNetworkData::getInstance()->isMasterServer() || 797 SharedNetworkData::getInstance()->isProxyServerActive() && peer->second.isClient() ) && 723 798 sync.getUniqueID() <= SharedNetworkData::getInstance()->getMaxPlayer() + 1) // plus one to handle one client more than the max to redirect it 724 799 n = Converter::intToByteArray( 0, buf + offset, UDP_PACKET_SIZE - offset ); … … 760 835 Synchronizeable & sync = **it; 761 836 762 if ( !sync.beSynchronized() || sync.getUniqueID() < 0 ) 837 // again exclude all unwanted syncs 838 if ( !sync.beSynchronized() || sync.getUniqueID() <= NET_UID_UNASSIGNED) 763 839 continue; 764 840 … … 771 847 // now compress the data with the zip library 772 848 int compLength = 0; 773 if ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer()) 849 if ( SharedNetworkData::getInstance()->isMasterServer() || 850 SharedNetworkData::getInstance()->isProxyServerActive()) 774 851 compLength = Zip::getInstance()->zip( buf, offset, compBuf, UDP_PACKET_SIZE, dictServer ); 775 852 else … … 888 965 } 889 966 890 // if the node we got this unknown sync from is a client we ignore it (since it has no rights to create a new sync) 891 if ( peers[peer->second.userId].isClient() ) 967 // if the node we got this unknown sync we ignore it if: 968 // - the remote host is a client 969 // - the remote host is a proxy server and we are master server 970 // (since it has no rights to create a new sync) 971 if ( peers[peer->second.userId].isClient() || 972 (peers[peer->second.userId].isProxyServerActive() && SharedNetworkData::getInstance()->isMasterServer())) 892 973 { 893 974 offset += syncDataLength; … … 960 1041 Synchronizeable & sync = **it; 961 1042 962 if ( !sync.beSynchronized() || sync.getUniqueID() < 0)1043 if ( !sync.beSynchronized() || sync.getUniqueID() <= NET_UID_UNASSIGNED ) 963 1044 continue; 964 1045 -
trunk/src/lib/network/network_stream.h
r9406 r9494 42 42 43 43 void connectToMasterServer(std::string host, int port); 44 void connectToProxyServer( std::string host, int port);45 void createServer(int port);44 void connectToProxyServer(int proxyId, std::string host, int port); 45 void createServer(int clientPort, int proxyPort); 46 46 47 47 void createNetworkGameManager(); 48 void startHandshake( );48 void startHandshake(int userId = NET_ID_MASTER_SERVER); 49 49 50 50 /* synchronizeable interface */ … … 55 55 56 56 /* functions for the peerInfo information retreival */ 57 /** @returns true if this userId is activated at this client false if not*/ 57 58 inline bool isUserIdActive( int userID ) { return (peers.find(userID) != peers.end()); } 59 /** @returns true if this userId is a local client */ 60 inline bool isUserLocal( int userID) { return this->isUserIdActive(userID); } 61 /** @returns true if this user is a master server */ 58 62 inline bool isUserMasterServer( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isMasterServer(); } 59 inline bool isUserProxyServer( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isProxyServer(); } 63 /** @returns true if this user is a proxy server */ 64 inline bool isUserProxyServerActive( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isProxyServerActive(); } 65 /** @returns true if this user is a client */ 60 66 inline bool isUserClient( int userID ){ if ( !isUserIdActive(userID) ) return false; return peers[userID].isClient(); } 61 67 … … 80 86 81 87 void updateConnectionList(); 88 82 89 /* handle processes */ 83 90 void handleHandshakes(); … … 87 94 /* handle events*/ 88 95 void handleNewClient( int userId ); 96 97 void handleConnect( int userId); 89 98 void handleReconnect( int userId ); 99 void handleDisconnect( int userId ); 90 100 91 101 void writeToNewDict( byte * data, int length, bool upstream ); … … 102 112 NetworkMonitor* networkMonitor; //!< the network monitor 103 113 NetworkGameManager* networkGameManager; //!< reference to the network game manager 104 ServerSocket* serverSocket; //!< the listening socket of the server 114 ServerSocket* clientSocket; //!< the listening socket of the server 115 ServerSocket* proxySocket; //!< socket for proxy connections 105 116 106 117 std::map<int,int> oldSynchronizeables; //!< used to save recently deleted sync ids to not recreate them … … 113 124 int dictServer; //!< the zip dict for the server 114 125 int dictClient; //!< the zip dict for the client 126 127 bool bRedirect; //!< true if the master server sent a redirect command 115 128 }; 116 129 #endif /* _NETWORK_STREAM */ -
trunk/src/lib/network/peer_info.cc
r9406 r9494 54 54 55 55 56 std::string PeerInfo::getNodeTypeString() 56 const std::string& PeerInfo::getNodeTypeString() const 57 57 { 58 switch( this->nodeType) 59 { 60 case NET_CLIENT: 61 return std::string("client"); 62 case NET_PROXY_SERVER_ACTIVE: 63 return std::string("proxy server active"); 64 case NET_PROXY_SERVER_PASSIVE: 65 return std::string("proxy server passive"); 66 case NET_MASTER_SERVER: 67 return std::string("master server"); 68 } 58 return PeerInfo::nodeTypeToString( this->nodeType ); 59 // the above does the same, and is faster in it. (there is no case where node is uninit i hope!) 60 } 69 61 70 return std::string("node is uninit"); 62 const std::string& PeerInfo::nodeTypeToString(unsigned int type) 63 { 64 return PeerInfo::nodeNames[type]; 71 65 } 66 67 68 const std::string PeerInfo::nodeNames[] = 69 { 70 71 "maser server", 72 "proxy server active", 73 "proxy server passive", 74 "client", 75 "node is not initialized" 76 }; -
trunk/src/lib/network/peer_info.h
r9406 r9494 22 22 23 23 24 inline bool isMasterServer() { return this->nodeType == NET_MASTER_SERVER; }25 inline bool isProxyServer (){ return this->nodeType == NET_PROXY_SERVER_ACTIVE; }26 inline bool isProxyServer Passive(){ return this->nodeType == NET_PROXY_SERVER_PASSIVE; }27 inline bool isClient() { return this->nodeType == NET_CLIENT; }24 inline bool isMasterServer() const { return this->nodeType == NET_MASTER_SERVER; } 25 inline bool isProxyServerActive() const { return this->nodeType == NET_PROXY_SERVER_ACTIVE; } 26 inline bool isProxyServerActivePassive() const { return this->nodeType == NET_PROXY_SERVER_PASSIVE; } 27 inline bool isClient() const { return this->nodeType == NET_CLIENT; } 28 28 29 std::string getNodeTypeString(); 29 const std::string& getNodeTypeString() const; 30 static const std::string& nodeTypeToString(unsigned int type); 31 30 32 31 33 … … 41 43 int lastAckedState; //!< last acked state synchronized state 42 44 int lastRecvedState; //!< last received state 45 46 static const std::string nodeNames[]; 47 43 48 }; 44 49 -
trunk/src/lib/network/player_stats.cc
r9406 r9494 191 191 void PlayerStats::setNickName( std::string nick ) 192 192 { 193 if ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer())193 if ( SharedNetworkData::getInstance()->isMasterServer()) 194 194 { 195 195 this->nickName = nick; -
trunk/src/lib/network/proxy/network_settings.cc
r9406 r9494 40 40 // suggest a good standard max players value 41 41 this->maxPlayer = 10; 42 43 // this->loadData();44 42 } 45 43 … … 53 51 54 52 // remove all unused proxy data again 55 for( int i = 0; i < this->proxies.size(); i++)53 for(unsigned int i = 0; i < this->proxies.size(); i++) 56 54 { 57 IP address*ip = this->proxies.back();55 IP ip = this->proxies.back(); 58 56 this->proxies.pop_back(); 59 delete ip;60 57 } 61 58 } … … 104 101 105 102 LoadParam(root, "max-player", this, NetworkSettings, setMaxPlayer); 103 LoadParam(root, "max-player-saturation", this, NetworkSettings, setMaxPlayerSaturation); 106 104 107 105 … … 140 138 return; 141 139 142 IPaddress *ip = new IPaddress; 143 144 SDLNet_ResolveHost( ip, proxyAddr.c_str(), 9999 ); 145 146 this->proxies.push_back(ip); 140 this->proxies.push_back(IP(proxyAddr, 9999)); 147 141 } 148 142 -
trunk/src/lib/network/proxy/network_settings.h
r9406 r9494 37 37 inline void setMaxPlayer(int number) { this->maxPlayer = number; } 38 38 /** @returns teh max number of players */ 39 int getMaxPlayer() { return this->maxPlayer; } 39 int getMaxPlayer() const { return this->maxPlayer; } 40 /** sets the @param saturation: a threshold in percente when the proxy servers should be activated to be able to redirect the clients */ 41 inline void setMaxPlayerSaturation(float saturation) { this->maxPlayerSaturation = saturation; } 42 40 43 41 44 void setMasterAddr(const std::string& masterAddr); 42 45 /** @returns the address of the master server read from the network config file */ 43 inline IP getMasterAddr(){ return this->masterServer; }46 inline const IP& getMasterAddr() const { return this->masterServer; } 44 47 45 48 void setProxyAddr(const std::string& proxyAddr); 46 49 /** @returns the list of proxy servers from the init file */ 47 inline std::vector<IP address*>* getProxyList() { return &this->proxies; }50 inline std::vector<IP>* getProxyList() { return &this->proxies; } 48 51 49 52 … … 53 56 54 57 private: 55 static NetworkSettings* singletonRef; //!< Pointer to the only instance of this Class 58 static NetworkSettings* singletonRef; //!< Pointer to the only instance of this Class 59 56 60 int maxPlayer; //!< maximal number of players 57 std::vector<IPaddress*> proxies; //!< all registered proxies 61 float maxPlayerSaturation; //!< the saturation level from where on the proxy server should be activated 62 63 std::vector<IP> proxies; //!< all registered proxies 58 64 IP masterServer; //!< master server ip address 59 65 -
trunk/src/lib/network/shared_network_data.cc
r9406 r9494 20 20 #include "state.h" 21 21 22 #include "network_stream.h" 23 22 24 #include "debug.h" 23 25 … … 34 36 this->setClassID(CL_SHARED_NETWORK_DATA, "SharedNetworkData"); 35 37 36 this->nodeType = NET_ CLIENT;38 this->nodeType = NET_MASTER_SERVER; 37 39 this->hostID = -1; 38 40 this->defaultSyncStream = NULL; … … 51 53 SharedNetworkData::singletonRef = NULL; 52 54 } 55 56 57 58 /** @return true if this user is connected to the local host */ 59 bool SharedNetworkData::isUserLocal( int userID) 60 { 61 return this->defaultSyncStream->isUserLocal(userID); 62 } 63 64 65 /** @returns true if this user is a master server */ 66 bool SharedNetworkData::isUserMasterServer( int userID ) 67 { 68 return this->defaultSyncStream->isUserMasterServer(userID); 69 } 70 71 72 /** @returns true if this user is a proxy server */ 73 bool SharedNetworkData::isUserProxyServerActive( int userID ) 74 { 75 return this->defaultSyncStream->isUserProxyServerActive(userID); 76 } 77 78 79 /** @returns true if this user is a client */ 80 bool SharedNetworkData::isUserClient( int userID ) 81 { 82 return this->defaultSyncStream->isUserClient(userID); 83 } -
trunk/src/lib/network/shared_network_data.h
r9406 r9494 14 14 #define NET_MAX_CONNECTIONS 2 15 15 16 class NetworkStream; 16 17 17 class Synchronizeable; 18 18 … … 28 28 29 29 /** @returns the next uniqueID free for an object */ 30 inline int getNewUniqueID() { return ( this->nodeType != NET_CLIENT)?this->newUniqueID++:-1; }30 inline int getNewUniqueID() { return ( isMasterServer())?this->newUniqueID++:-1; } 31 31 /** sets the @param newUniqueID: the new offset for the next unique id */ 32 32 inline void setNewUniqueID(int newUniqueID) { this->newUniqueID = newUniqueID; } 33 33 34 /** sets the game server flag @param bGameServer true if it is a game server */ 35 inline void setNodeType(int nodeType) { this->nodeType = nodeType; } 34 36 /** @returns true is this node is a master server */ 35 37 inline bool isMasterServer() { return this->nodeType == NET_MASTER_SERVER; } 36 38 /** @returns true is this node is a proxy server */ 37 inline bool isProxyServer () { return this->nodeType == NET_PROXY_SERVER_ACTIVE; }39 inline bool isProxyServerActive() { return this->nodeType == NET_PROXY_SERVER_ACTIVE; } 38 40 /** @returns true is this node is a client*/ 39 41 inline bool isClient() { return this->nodeType == NET_CLIENT; } 40 /** sets the game server flag @param bGameServer true if it is a game server */ 41 inline void setNodeType(int nodeType) { this->nodeType = nodeType; } 42 43 /** @return true if this user is connected to the local host */ 44 bool isUserLocal( int userID); 45 /** @returns true if this user is a master server */ 46 bool isUserMasterServer( int userID ); 47 /** @returns true if this user is a proxy server */ 48 bool isUserProxyServerActive( int userID ); 49 /** @returns true if this user is a client */ 50 bool isUserClient( int userID ); 51 42 52 43 53 /** @returns the maximum number of players for this server */ -
trunk/src/lib/network/synchronizeable.cc
r9406 r9494 72 72 this->networkStream->disconnectSynchronizeable(*this); 73 73 74 if ( (SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer() ) 74 // remove the message manager only by the server 75 if ( (SharedNetworkData::getInstance()->isMasterServer() ) 75 76 && this->beSynchronized() && this->getUniqueID() > 0 && !this->isA( CL_MESSAGE_MANAGER ) ) 76 77 NetworkGameManager::getInstance()->removeSynchronizeable( this->getUniqueID() ); … … 213 214 hasPermission = true; 214 215 // now check PROXY_SERVER permissions 215 else if( SharedNetworkData::getInstance()->isProxyServer () && (*it)->checkPermission( PERMISSION_MASTER_SERVER ))216 else if( SharedNetworkData::getInstance()->isProxyServerActive() && (*it)->checkPermission( PERMISSION_PROXY_SERVER )) 216 217 hasPermission = true; 217 218 // now check OWNER permissions … … 222 223 hasPermission = true; 223 224 // SPECIAL: get write permissions if i am master server and i am able to overwrite the client stuff 225 #warning this could probably override also clients that are connected to another proxy: the master server overwrites it 224 226 else if( SharedNetworkData::getInstance()->isMasterServer() && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER )) 225 227 hasPermission = true; 226 228 // SPECIAL: get write permissions if i am proxy server and i am able to overwrite the client stuff 227 else if( SharedNetworkData::getInstance()->isProxyServer() && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER )) 229 else if( SharedNetworkData::getInstance()->isProxyServerActive() && this->networkStream->isUserClient(userId) 230 && this->owner != userId && (*it)->checkPermission( PERMISSION_OWNER ) ) 228 231 hasPermission = true; 229 232 else … … 354 357 hasPermission = true; 355 358 // now check PROXY_SERVER permissions 356 else if( this->networkStream->isUserProxyServer( userId ) && (*it)->checkPermission( PERMISSION_MASTER_SERVER )) 359 else if( this->networkStream->isUserProxyServerActive( userId ) && (*it)->checkPermission( PERMISSION_MASTER_SERVER ) 360 && SharedNetworkData::getInstance()->isClient()) 357 361 hasPermission = true; 358 362 // now check OWNER permissions … … 366 370 hasPermission = true; 367 371 // SPECIAL: get write permissions if im sending to a proxy server that does not own this sync 368 else if( this->networkStream->isUserProxyServer( userId ) && this->owner != SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER )) 372 else if( this->networkStream->isUserProxyServerActive( userId ) && SharedNetworkData::getInstance()->isClient() 373 && this->owner != SharedNetworkData::getInstance()->getHostID() && (*it)->checkPermission( PERMISSION_OWNER )) 369 374 hasPermission = true; 370 375 else … … 388 393 else 389 394 { 390 // PRINTF(0)("DONT SET VAR BECAUSE OF PERMISSION: %s %d %d %d %d %d %d\n", (*it)->getName().c_str(), (*it)->checkPermission( PERMISSION_MASTER_SERVER ), (*it)->checkPermission( PERMISSION_OWNER ), (*it)->checkPermission( PERMISSION_ALL ), networkStream->isUserServer( userId ), this->owner, userId );395 // PRINTF(0)("DONT SET VAR BECAUSE OF PERMISSION: %s perm: %d %d %d - %d %d %d\n", (*it)->getName().c_str(), (*it)->checkPermission( PERMISSION_MASTER_SERVER ), (*it)->checkPermission( PERMISSION_OWNER ), (*it)->checkPermission( PERMISSION_ALL ), networkStream->isUserMasterServer( userId ), this->owner, userId ); 391 396 n = (*it)->getSizeFromBuf( stateTo->data + i, stateTo->dataLength - i ); 392 397 //NETPRINTF(0)("%s::setvar %s %d\n", getClassCName(), (*it)->getName().c_str(), n); … … 416 421 void Synchronizeable::registerVar( SynchronizeableVar * var ) 417 422 { 418 //PRINTF(0)("ADDING VAR: %s\n", var->getName().c_str());419 423 syncVarList.push_back( var ); 420 424 } … … 428 432 int Synchronizeable::registerVarId( SynchronizeableVar * var ) 429 433 { 430 //PRINTF(0)("ADDING VAR: %s\n", var->getName().c_str());431 434 syncVarList.push_back( var ); 432 435 var->setWatched( true ); -
trunk/src/lib/network/synchronizeable_var/synchronizeable_var.h
r9406 r9494 10 10 #include <string> 11 11 12 enum { 13 PERMISSION_MASTER_SERVER = 1, 14 PERMISSION_PROXY_SERVER = 2, 15 PERMISSION_OWNER = 4, 16 PERMISSION_ALL = 8 17 }; 12 18 13 19 14 class SynchronizeableVar { -
trunk/src/lib/network/tcp_server_socket.cc
r9406 r9494 126 126 } 127 127 128 129 128 130 void TcpServerSocket::close( ) 129 131 { -
trunk/src/lib/network/udp_server_socket.cc
r8802 r9494 94 94 } 95 95 96 96 97 /** 97 98 * stop listening on server … … 220 221 if ( !socket ) 221 222 return false; 222 223 223 224 assert( networkPacket.length <= UDP_PACKET_SIZE ); 224 225 … … 232 233 return false; 233 234 } 234 235 235 236 return true; 236 237 } … … 244 245 int newConn = 0; 245 246 247 // iterate through all newly received packets and assign them to the users packet buffer 246 248 for ( res = SDLNet_UDP_Recv( socket, packet ); res == 1; res = SDLNet_UDP_Recv( socket, packet ) ) 247 249 { … … 250 252 251 253 if ( packet->len <= 0 ) 252 continue; 253 254 for ( userId =0; userId < (int)userList.size(); userId++ ) 255 if ( userList[userId].addr.host == packet->address.host && userList[userId].addr.port == packet->address.port && userList[userId].randomByte == ( packet->data[0] & 0xFC ) ) 254 continue; 255 256 // search the user id this backet belongs to 257 for ( userId = 0; userId < (int)userList.size(); userId++ ) 258 { 259 if ( userList[userId].addr.host == packet->address.host && 260 userList[userId].addr.port == packet->address.port && 261 userList[userId].randomByte == ( packet->data[0] & 0xFC ) ) 256 262 break; 257 263 } 264 265 // is it a new packet initializing a new connecion? 258 266 if ( userId >= (int)userList.size() ) 259 267 { … … 271 279 break; 272 280 273 initUser( userId, packet->address, packet->data[0] & 0xFC );281 this->initUser( userId, packet->address, packet->data[0] & 0xFC ); 274 282 UdpSocket * sock = new UdpSocket( this, packet->address, userId, packet->data[0] & 0xFC ); 275 283 newSocketList.push_back( sock ); … … 277 285 } 278 286 279 //add new packet to packetbuffer 280 287 288 // add new packet to packetbuffer 281 289 NetworkPacket networkPacket; 282 290 networkPacket.length = packet->len; -
trunk/src/lib/network/udp_server_socket.h
r9246 r9494 33 33 typedef std::vector<NetworkPacketList> PacketBuffer; 34 34 35 36 //!< informations struct for each user 35 37 struct UserInfo 36 38 { 37 IPaddress addr;38 byte randomByte;39 IPaddress addr; //!< ip address of this user 40 byte randomByte; //!< random byte of this user 39 41 }; 42 40 43 41 44 typedef std::vector<UserInfo> UserList; … … 43 46 typedef std::list<UdpSocket*> UdpSocketList; 44 47 48 49 //!< the upd server socket listening for incoming connections 45 50 class UdpServerSocket : public ServerSocket 46 51 { … … 49 54 virtual ~UdpServerSocket(); 50 55 56 /* server socket manipulations */ 51 57 virtual bool listen( unsigned int port ); 52 53 58 virtual NetworkSocket* getNewSocket( void ); 54 55 59 virtual void close(); 56 60 57 61 virtual void update(); 58 62 63 /* network traffic interface */ 64 NetworkPacket getPacket( int userId ); 65 void removeUser( int userId ); 66 bool sendPacket( NetworkPacket networkPacket, int userId ); 67 68 69 private: 59 70 void removeUserPackets( int userId ); 60 void removeUser( int userId );61 NetworkPacket getPacket( int userId );62 bool sendPacket( NetworkPacket networkPacket, int userId );63 71 int getPacketCount( int childId ); 64 72 void initUser( int childId, IPaddress ip, byte randomByte ); 65 73 74 66 75 private: 67 UDPsocket socket; //!< will be uses to send/recieve data68 UDPpacket * packet; //!< packet structure to recieve packet69 PacketBuffer packetBuffer; //!< will store recieved packets for UdpSockets70 UserList userList; //!< contains information about clients71 UdpSocketList newSocketList; //!< contains new socket76 UDPsocket socket; //!< will be used to send/recieve data to/from clients 77 UDPpacket * packet; //!< packet structure to recieve packet 78 PacketBuffer packetBuffer; //!< will store recieved packets for UdpSockets 79 UserList userList; //!< contains information about clients 80 UdpSocketList newSocketList; //!< contains new socket 72 81 73 82 }; -
trunk/src/lib/network/zip.h
r8623 r9494 21 21 22 22 //! A class for compressing/uncompressing packes. 23 class Zip 23 class Zip 24 24 { 25 25 public: … … 27 27 /** @returns a Pointer to the only object of this Class */ 28 28 inline static Zip* getInstance(void) { if (!singletonRef) singletonRef = new Zip(); return singletonRef; }; 29 29 30 30 int loadDictionary( std::string name ); 31 31 int zip( byte * from, int fromLength, byte * to, int maxLength, int dict = 0 ); 32 32 int unZip( byte * from, int fromLength, byte * to, int maxLength ); 33 33 34 34 int getDictCount(){ return dicts.size(); } 35 35 … … 37 37 Zip(); 38 38 static Zip* singletonRef; 39 39 40 40 std::vector<DictionaryEntry> dicts; 41 41 }; 42 42 43 #endif /* _ PROTO_SINGLETON_H */43 #endif /* _ZIP_H */ -
trunk/src/story_entities/game_world.cc
r9406 r9494 414 414 double currentFrame = Timer::getNow(); 415 415 416 if (currentFrame - this->lastFrame < .01) 417 { 418 SDL_Delay(1000.0 * (0.01 - (currentFrame - lastFrame))); 419 currentFrame = Timer::getNow(); 420 } 421 422 416 423 frameTimesIndex = this->cycle % TICK_SMOOTH_VALUE; 417 424 this->frameTimes[frameTimesIndex] = currentFrame - this->lastFrame; … … 469 476 this->dataTank->objectManager->getObjectList(OM_GROUP_00_PROJ)); 470 477 CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_01), 471 this->dataTank->objectManager->getObjectList(OM_GROUP_00));478 this->dataTank->objectManager->getObjectList(OM_GROUP_00)); 472 479 473 480 CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_01), 474 this->dataTank->objectManager->getObjectList(OM_GROUP_02));481 this->dataTank->objectManager->getObjectList(OM_GROUP_02)); 475 482 CDEngine::getInstance()->checkCollisions(this->dataTank->objectManager->getObjectList(OM_GROUP_02), 476 this->dataTank->objectManager->getObjectList(OM_GROUP_01_PROJ));483 this->dataTank->objectManager->getObjectList(OM_GROUP_01_PROJ)); 477 484 478 485 … … 513 520 { 514 521 515 522 // if this server is a dedicated server the game workd does not need to be drawn 516 523 if( !GraphicsEngine::getInstance()->isDedicated()) 517 524 { 518 // render the reflection texture519 this->renderPassReflection();520 // redner the refraction texture521 this->renderPassRefraction();525 // render the reflection texture 526 this->renderPassReflection(); 527 // redner the refraction texture 528 this->renderPassRefraction(); 522 529 } 523 530 // render all -
trunk/src/story_entities/multi_player_world_data.cc
r9406 r9494 112 112 const TiXmlElement* element = NULL; 113 113 114 if( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer())114 if( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/) 115 115 { 116 116 /* load the spawning points */ … … 148 148 element = element->FirstChildElement(); 149 149 150 if( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer())150 if( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/) 151 151 { 152 152 while( element != NULL) … … 206 206 207 207 208 if( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer())208 if( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/) 209 209 { 210 210 this->localPlayer = new Player(); … … 284 284 285 285 // create server playable 286 if ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer())286 if ( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/) 287 287 { 288 288 NetworkGameManager::getInstance()->signalNewPlayer( 0 ); -
trunk/src/subprojects/network/network_unit_test.cc
r9406 r9494 276 276 for(;;) 277 277 { 278 MessageManager::getInstance()->sendMessage( TESTMESSAGEID, (byte*)"server to client", 18, RT_ALL_ NOT_ME, 0, MP_HIGHBANDWIDTH );278 MessageManager::getInstance()->sendMessage( TESTMESSAGEID, (byte*)"server to client", 18, RT_ALL_BUT_ME, 0, MP_HIGHBANDWIDTH ); 279 279 netMan->synchronize( 100 ); 280 280 SDL_Delay(100); … … 323 323 { 324 324 netMan->synchronize( 100 ); 325 MessageManager::getInstance()->sendMessage( TESTMESSAGEID, (byte*)"client to server", 18, RT_ALL_ NOT_ME, 0, MP_HIGHBANDWIDTH );325 MessageManager::getInstance()->sendMessage( TESTMESSAGEID, (byte*)"client to server", 18, RT_ALL_BUT_ME, 0, MP_HIGHBANDWIDTH ); 326 326 ss = dynamic_cast<SimpleSync*>(ClassList::getObject( "Server", CL_SIMPLE_SYNC ) ); 327 327 SDL_Delay(100); -
trunk/src/util/Makefile.am
r9406 r9494 26 26 animation/animation_player.cc \ 27 27 \ 28 track/pilot_node.cc \ 29 \ 30 network_stats_widget.cc 28 track/pilot_node.cc 31 29 32 30 # track/track_manager.cc \ … … 54 52 animation/t_animation.h \ 55 53 \ 56 track/pilot_node.h \ 57 \ 58 network_stats_widget.h 59 54 track/pilot_node.h 60 55 61 56 # track/track_manager.h \ -
trunk/src/util/game_rules.cc
r9406 r9494 87 87 void GameRules::registerKill(const Kill& kill) 88 88 { 89 if ( SharedNetworkData::getInstance()->isClient() )89 if ( SharedNetworkData::getInstance()->isClient() || SharedNetworkData::getInstance()->isProxyServerActive()) 90 90 return; 91 91 -
trunk/src/util/multiplayer_team_deathmatch.cc
r9406 r9494 152 152 box->setAbsCoor2D( 300, 100 ); 153 153 154 OrxGui::GLGuiPushButton * buttonSpectator = new OrxGui::GLGuiPushButton("Spectator"); 155 box->pack( buttonSpectator ); 156 buttonSpectator->released.connect(this, &MultiplayerTeamDeathmatch::onButtonSpectator); 157 158 OrxGui::GLGuiPushButton * buttonRandom = new OrxGui::GLGuiPushButton("Random"); 159 box->pack( buttonRandom ); 160 buttonRandom->released.connect(this, &MultiplayerTeamDeathmatch::onButtonRandom); 161 162 OrxGui::GLGuiPushButton * buttonTeam0 = new OrxGui::GLGuiPushButton("Blue Team"); 163 box->pack( buttonTeam0 ); 164 buttonTeam0->released.connect(this, &MultiplayerTeamDeathmatch::onButtonTeam0); 165 166 OrxGui::GLGuiPushButton * buttonTeam1 = new OrxGui::GLGuiPushButton("Red Team"); 167 box->pack( buttonTeam1 ); 168 buttonTeam1->released.connect(this, &MultiplayerTeamDeathmatch::onButtonTeam1); 154 if( SharedNetworkData::getInstance()->isClient() || SharedNetworkData::getInstance()->isProxyServerActive()) 155 { 156 OrxGui::GLGuiPushButton * buttonSpectator = new OrxGui::GLGuiPushButton("Spectator"); 157 box->pack( buttonSpectator ); 158 buttonSpectator->released.connect(this, &MultiplayerTeamDeathmatch::onButtonSpectator); 159 160 OrxGui::GLGuiPushButton * buttonRandom = new OrxGui::GLGuiPushButton("Random"); 161 box->pack( buttonRandom ); 162 buttonRandom->released.connect(this, &MultiplayerTeamDeathmatch::onButtonRandom); 163 164 OrxGui::GLGuiPushButton * buttonTeam0 = new OrxGui::GLGuiPushButton("Blue Team"); 165 box->pack( buttonTeam0 ); 166 buttonTeam0->released.connect(this, &MultiplayerTeamDeathmatch::onButtonTeam0); 167 168 OrxGui::GLGuiPushButton * buttonTeam1 = new OrxGui::GLGuiPushButton("Red Team"); 169 box->pack( buttonTeam1 ); 170 buttonTeam1->released.connect(this, &MultiplayerTeamDeathmatch::onButtonTeam1); 171 } 172 else 173 { 174 OrxGui::GLGuiText* text = new OrxGui::GLGuiText(); 175 text->setText("Server Mode: not able to play at this node"); 176 box->pack( text); 177 } 178 169 179 170 180 if ( bShowTeamChange ) … … 204 214 assignPlayable(); 205 215 206 if ( SharedNetworkData::getInstance()->isClient() )216 if ( SharedNetworkData::getInstance()->isClient() || SharedNetworkData::getInstance()->isProxyServerActive()) 207 217 return; 208 218 … … 268 278 void MultiplayerTeamDeathmatch::checkGameRules() 269 279 { 270 if ( SharedNetworkData::getInstance()->isClient() )280 if ( SharedNetworkData::getInstance()->isClient() || SharedNetworkData::getInstance()->isProxyServerActive()) 271 281 return; 272 282 … … 296 306 297 307 if ( team == 0 || team == 1 ) 298 return CL_ FPS_PLAYER;308 return CL_TURBINE_HOVER; 299 309 300 310 assert( false ); … … 303 313 std::string MultiplayerTeamDeathmatch::getPlayableModelFileName( int userId, int team, ClassID classId ) 304 314 { 315 if (classId == CL_TURBINE_HOVER) 316 return "models/ships/hoverglider_mainbody.obj"; 305 317 if ( team == 0 ) 306 318 return "models/creatures/doom_guy.md2"; -
trunk/src/world_entities/creatures/fps_player.cc
r9406 r9494 287 287 //dealing damage 288 288 289 if ( State::isOnline() && (SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer()))289 if ( State::isOnline() && (SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/)) 290 290 { 291 291 this->damageTicker -= time; -
trunk/src/world_entities/space_ships/space_ship.cc
r9406 r9494 310 310 void SpaceShip::collidesWith(WorldEntity* entity, const Vector& location) 311 311 { 312 Playable::collidesWith(entity, location); 313 314 if( entity->isA(CL_PROJECTILE) && entity != ref) 315 { 316 if ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer()) 317 { 318 //TODO handle this 319 } 320 } 321 PRINTF(3)("collision %s vs %s @ (%f,%f,%f)\n", this->getClassCName(), entity->getClassCName(), location.x, location.y, location.z); 312 322 313 } 323 314 -
trunk/src/world_entities/space_ships/turbine_hover.cc
r8623 r9494 126 126 this->cameraNode.addNodeFlags(PNODE_PROHIBIT_CHILD_DELETE); 127 127 //this->cameraNode.setParentMode(PNODE_ROTATE_MOVEMENT); 128 //this->cameraNode.setParent(this); 128 this->cameraNode.setParent(this); 129 this->cameraNode.setRelCoor(0,5,0); 129 130 130 131 // rotors … … 211 212 this->getWeaponManager().getFixedTarget()->setParent(&this->cameraNode); 212 213 this->getWeaponManager().getFixedTarget()->setRelCoor(1000,0,0); 213 214 214 215 registerVar( new SynchronizeableBool( &bForward, &bForward, "bForward", PERMISSION_OWNER ) ); 215 216 registerVar( new SynchronizeableBool( &bBackward, &bBackward, "bBackward", PERMISSION_OWNER ) ); … … 218 219 registerVar( new SynchronizeableBool( &bAscend, &bAscend, "bAscend", PERMISSION_OWNER ) ); 219 220 registerVar( new SynchronizeableBool( &bDescend, &bDescend, "bDescend", PERMISSION_OWNER ) ); 220 //registerVar( new SynchronizeableQuaternion( &direction, &direction, "direction", PERMISSION_OWNER ) );221 registerVar( new SynchronizeableQuaternion( &direction, &direction, "direction", PERMISSION_OWNER ) ); 221 222 registerVar( new SynchronizeableFloat( &cameraLook, &cameraLook, "cameraLook", PERMISSION_OWNER ) ); 222 223 registerVar( new SynchronizeableFloat( &rotation, &rotation, "rotation", PERMISSION_OWNER ) ); … … 294 295 295 296 // spaceship controlled movement 297 298 // TRYING TO FIX PNode. 299 //this->cameraNode.setRelCoor(Vector(0.0f, 5.0f, 0.0f));//, 30.0f); 300 //this->cameraNode.setRelDir(Quaternion(this->smoothRotator *10.0, Vector(0,1,0))); 301 296 302 this->movement(dt); 297 303 this->rotorCycle += this->rotorSpeed * dt; 298 299 // TRYING TO FIX PNode. 300 this->cameraNode.setAbsCoorSoft(this->getAbsCoor() + Vector(0.0f, 5.0f, 0.0f), 30.0f); 301 this->cameraNode.setRelDirSoft(this->getAbsDir(), 30.0f); 302 } 304 } 305 306 307 #include "shared_network_data.h" 303 308 304 309 /** … … 349 354 350 355 this->velocity += (accelerationDir - damping)* dt; 351 this->shiftCoor (this->velocity * dt); 356 //if (this->getOwner() != SharedNetworkData::getInstance()->getHostID()) 357 this->shiftCoor (this->velocity * dt); 352 358 353 359 // limit the maximum rotation speed. … … 362 368 } 363 369 364 this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5); 370 //if (this->getOwner() != SharedNetworkData::getInstance()->getHostID()) 371 this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5); 365 372 366 373 this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); … … 407 414 408 415 case Playable::Vertical: 409 {410 accel.z = 0;411 Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration);412 accelerationDir.z=0;416 { 417 accel.z = 0; 418 Vector accelerationDir = this->getAbsDir().apply(accel * this->acceleration); 419 accelerationDir.z=0; 413 420 414 421 // this is the air friction (necessary for a smooth control) 415 Vector damping = (this->velocity * this->airFriction);416 417 this->velocity += (accelerationDir - damping)* dt;418 this->shiftCoor (this->velocity * dt);419 420 this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5);421 422 this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5);423 this->rotorNodeLeft.setRelDirSoft(Quaternion(-accel.x * .07+this->rotation + cameraLook, Vector(0,0,1)), 5);424 425 this->wingNodeRight.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5);426 this->rotorNodeRight.setRelDirSoft(Quaternion(-accel.x*.07 -this->rotation + cameraLook, Vector(0,0,1)), 5);427 }428 break;422 Vector damping = (this->velocity * this->airFriction); 423 424 this->velocity += (accelerationDir - damping)* dt; 425 this->shiftCoor (this->velocity * dt); 426 427 this->setRelDirSoft(this->direction * Quaternion(-cameraLook, Vector(0,0,1)), 5); 428 429 this->wingNodeLeft.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); 430 this->rotorNodeLeft.setRelDirSoft(Quaternion(-accel.x * .07+this->rotation + cameraLook, Vector(0,0,1)), 5); 431 432 this->wingNodeRight.setRelDirSoft(Quaternion(accel.z * .05 +this->rotation, Vector(1,0,0)), 5); 433 this->rotorNodeRight.setRelDirSoft(Quaternion(-accel.x*.07 -this->rotation + cameraLook, Vector(0,0,1)), 5); 434 } 435 break; 429 436 default: 430 437 PRINTF(2)("Playmode %s Not Implemented\n", Playable::playmodeToString(this->getPlaymode()).c_str()); -
trunk/src/world_entities/spawning_point.cc
r9406 r9494 178 178 } 179 179 180 if ( found && SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer())180 if ( found && SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/) 181 181 this->sendRespawnMessage( it->entity->getUniqueID() ); 182 182 … … 201 201 * Just override this function with whatever you want to be drawn. 202 202 */ 203 void SpawningPoint::draw() 203 void SpawningPoint::draw() const 204 204 { 205 205 } … … 213 213 assert( Converter::intToByteArray( uniqueId, buf + INTSIZE, INTSIZE ) == INTSIZE ); 214 214 215 MessageManager::getInstance()->sendMessage( MSGID_RESPAWN, buf, 2*INTSIZE, RT_ALL_ NOT_ME, 0, MP_HIGHBANDWIDTH );215 MessageManager::getInstance()->sendMessage( MSGID_RESPAWN, buf, 2*INTSIZE, RT_ALL_BUT_ME, 0, MP_HIGHBANDWIDTH ); 216 216 } 217 217 218 218 bool SpawningPoint::respawnMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ) 219 219 { 220 if ( SharedNetworkData::getInstance()->isMasterServer() || SharedNetworkData::getInstance()->isProxyServer())220 if ( SharedNetworkData::getInstance()->isMasterServer() /*|| SharedNetworkData::getInstance()->isProxyServerActive()*/) 221 221 { 222 222 PRINTF(2)("server received spawn message!\n"); -
trunk/src/world_entities/spawning_point.h
r9008 r9494 50 50 virtual void loadParams(const TiXmlElement* root); 51 51 52 inline int getTeamId() { return this->teamId; }53 inline void setTeamId( int teamId ) { this->teamId = teamId; }52 inline int getTeamId() const { return this->teamId; } 53 inline void setTeamId( int teamId ) { this->teamId = teamId; } 54 54 55 55 void pushEntity(Playable* entity, float delay = 0); … … 63 63 64 64 virtual void tick(float dt); 65 virtual void draw() ;65 virtual void draw() const; 66 66 67 67 68 68 private: 69 69 void spawn(Playable* entity); 70 70 71 71 void sendRespawnMessage( int uniqueId ); 72 72 static bool respawnMessageHandler( MessageId messageId, byte * data, int dataLength, void * someData, int userId ); -
trunk/src/world_entities/world_entity.cc
r9406 r9494 257 257 bool WorldEntity::buildObbTree(int depth) 258 258 { 259 if (this->obbTree) 259 if( this->obbTree != NULL) 260 { 260 261 delete this->obbTree; 262 this->obbTree = NULL; 263 } 261 264 262 265 if (this->models[0] != NULL) … … 280 283 this->aabbNode = new AABBTreeNode(); 281 284 this->aabbNode->spawnBVTree(this->models[0]); 285 } 286 else 287 { 288 PRINTF(1)("could not create aabb bounding box, because no model was loaded yet\n"); 289 this->aabbNode = NULL; 290 return false; 282 291 } 283 292 return true;
Note: See TracChangeset
for help on using the changeset viewer.