[9276] | 1 | /* |
---|
| 2 | orxonox - the future of 3D-vertical-scrollers |
---|
| 3 | |
---|
| 4 | Copyright (C) 2004 orx |
---|
| 5 | |
---|
| 6 | This program is free software; you can redistribute it and/or modify |
---|
| 7 | it under the terms of the GNU General Public License as published by |
---|
| 8 | the Free Software Foundation; either version 2, or (at your option) |
---|
| 9 | any later version. |
---|
| 10 | |
---|
| 11 | ### File Specific: |
---|
| 12 | main-programmer: Patrick Boenzli |
---|
| 13 | */ |
---|
| 14 | |
---|
| 15 | |
---|
| 16 | #include "network_node.h" |
---|
| 17 | |
---|
[9277] | 18 | #include "debug.h" |
---|
[9276] | 19 | |
---|
[9277] | 20 | |
---|
| 21 | /** |
---|
| 22 | * constructor |
---|
| 23 | */ |
---|
[9284] | 24 | NetworkNode::NetworkNode(PeerInfo* pInfo) |
---|
[9277] | 25 | { |
---|
| 26 | this->playerNumber = 0; |
---|
[9284] | 27 | this->peerInfo = pInfo; |
---|
[9277] | 28 | } |
---|
[9276] | 29 | |
---|
| 30 | |
---|
[9277] | 31 | /** |
---|
| 32 | * deconstructor |
---|
| 33 | */ |
---|
[9276] | 34 | NetworkNode::~NetworkNode() |
---|
| 35 | {} |
---|
| 36 | |
---|
[9277] | 37 | |
---|
| 38 | /** |
---|
| 39 | * adds a client |
---|
| 40 | */ |
---|
| 41 | void NetworkNode::addClient(PeerInfo* node) |
---|
| 42 | { |
---|
| 43 | this->clientList.push_back(node); |
---|
| 44 | this->playerNumber++; |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | /** |
---|
| 48 | * adds a proxy server |
---|
| 49 | */ |
---|
[9292] | 50 | void NetworkNode::addActiveProxyServer(PeerInfo* node) |
---|
[9277] | 51 | { |
---|
[9292] | 52 | this->activeProxyServerList.push_back(node); |
---|
[9277] | 53 | this->playerNumber++; |
---|
| 54 | } |
---|
| 55 | |
---|
| 56 | /** |
---|
[9292] | 57 | * adds a proxy server |
---|
| 58 | */ |
---|
| 59 | void NetworkNode::addPassiveProxyServer(PeerInfo* node) |
---|
| 60 | { |
---|
| 61 | this->passiveProxyServerList.push_back(node); |
---|
| 62 | } |
---|
| 63 | |
---|
| 64 | /** |
---|
[9277] | 65 | * adds a master server |
---|
| 66 | */ |
---|
| 67 | void NetworkNode::addMasterServer(PeerInfo* node) |
---|
| 68 | { |
---|
| 69 | this->masterServerList.push_back(node); |
---|
| 70 | this->playerNumber++; |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | /** |
---|
| 74 | * removes a client |
---|
| 75 | */ |
---|
| 76 | void NetworkNode::removeClient(PeerInfo* node) |
---|
| 77 | { |
---|
| 78 | std::list<PeerInfo*>::iterator it = this->clientList.begin(); |
---|
| 79 | for(; it != this->clientList.end(); it++) |
---|
| 80 | { |
---|
| 81 | if( *it == node) |
---|
| 82 | { |
---|
| 83 | this->clientList.erase(it); |
---|
| 84 | this->playerNumber--; |
---|
| 85 | return; |
---|
| 86 | } |
---|
| 87 | } |
---|
| 88 | |
---|
| 89 | PRINTF(2)("Could not remove client from the list, very strange..."); |
---|
| 90 | } |
---|
| 91 | |
---|
| 92 | /** |
---|
| 93 | * removes a proxy server |
---|
| 94 | */ |
---|
[9292] | 95 | void NetworkNode::removeActiveProxyServer(PeerInfo* node) |
---|
[9277] | 96 | { |
---|
[9292] | 97 | std::list<PeerInfo*>::iterator it = this->activeProxyServerList.begin(); |
---|
| 98 | for(; it != this->activeProxyServerList.end(); it++) |
---|
[9277] | 99 | { |
---|
| 100 | if( *it == node) |
---|
| 101 | { |
---|
[9292] | 102 | this->activeProxyServerList.erase(it); |
---|
[9277] | 103 | this->playerNumber--; |
---|
| 104 | return; |
---|
| 105 | } |
---|
| 106 | } |
---|
| 107 | |
---|
| 108 | PRINTF(2)("Could not remove proxy server from the list, very strange..."); |
---|
| 109 | } |
---|
| 110 | |
---|
| 111 | /** |
---|
[9292] | 112 | * removes a proxy server |
---|
| 113 | */ |
---|
| 114 | void NetworkNode::removePassiveProxyServer(PeerInfo* node) |
---|
| 115 | { |
---|
| 116 | std::list<PeerInfo*>::iterator it = this->passiveProxyServerList.begin(); |
---|
| 117 | for(; it != this->passiveProxyServerList.end(); it++) |
---|
| 118 | { |
---|
| 119 | if( *it == node) |
---|
| 120 | { |
---|
| 121 | this->passiveProxyServerList.erase(it); |
---|
| 122 | return; |
---|
| 123 | } |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | PRINTF(2)("Could not remove proxy server from the list, very strange..."); |
---|
| 127 | } |
---|
| 128 | |
---|
| 129 | /** |
---|
[9277] | 130 | * removes a master server |
---|
| 131 | */ |
---|
| 132 | void NetworkNode::removeMasterServer(PeerInfo* node) |
---|
| 133 | { |
---|
| 134 | std::list<PeerInfo*>::iterator it = this->masterServerList.begin(); |
---|
| 135 | for(; it != this->masterServerList.end(); it++) |
---|
| 136 | { |
---|
| 137 | if( *it == node) |
---|
| 138 | { |
---|
| 139 | this->masterServerList.erase(it); |
---|
| 140 | this->playerNumber--; |
---|
| 141 | return; |
---|
| 142 | } |
---|
| 143 | } |
---|
| 144 | |
---|
| 145 | PRINTF(2)("Could not remove client from the list, very strange..."); |
---|
| 146 | } |
---|
[9288] | 147 | |
---|
| 148 | |
---|
[9300] | 149 | /** |
---|
| 150 | * @param index index to the client |
---|
| 151 | * @return the client in the list or NULL if none |
---|
| 152 | */ |
---|
| 153 | PeerInfo* NetworkNode::getClient(int index) |
---|
| 154 | { |
---|
| 155 | if( this->clientList.size() < index) |
---|
| 156 | return NULL; |
---|
[9288] | 157 | |
---|
[9300] | 158 | std::list<PeerInfo*>::iterator it = this->clientList.begin(); |
---|
| 159 | for(int i = 0; it != this->clientList.end(); it++, i++) |
---|
| 160 | { |
---|
| 161 | if( i == index) |
---|
| 162 | return (*it); |
---|
| 163 | } |
---|
| 164 | |
---|
| 165 | return NULL; |
---|
| 166 | } |
---|
| 167 | |
---|
| 168 | |
---|
[9288] | 169 | /** |
---|
[9300] | 170 | * @param index index to the client |
---|
| 171 | * @return the active proxy server in the list or NULL if none |
---|
| 172 | */ |
---|
| 173 | PeerInfo* NetworkNode::getActiveProxyServer(int index) |
---|
| 174 | { |
---|
| 175 | if( this->activeProxyServerList.size() < index) |
---|
| 176 | return NULL; |
---|
| 177 | |
---|
| 178 | std::list<PeerInfo*>::iterator it = this->activeProxyServerList.begin(); |
---|
| 179 | for(int i = 0; it != this->activeProxyServerList.end(); it++, i++) |
---|
| 180 | { |
---|
| 181 | if( i == index) |
---|
| 182 | return (*it); |
---|
| 183 | } |
---|
| 184 | |
---|
| 185 | return NULL; |
---|
| 186 | } |
---|
| 187 | |
---|
| 188 | |
---|
| 189 | /** |
---|
| 190 | * @param index index to the client |
---|
| 191 | * @return the passive proxy server in the list or NULL if none |
---|
| 192 | */ |
---|
| 193 | PeerInfo* NetworkNode::getPassiveProxyServer(int index) |
---|
| 194 | { |
---|
| 195 | if( this->passiveProxyServerList.size() < index) |
---|
| 196 | return NULL; |
---|
| 197 | |
---|
| 198 | std::list<PeerInfo*>::iterator it = this->passiveProxyServerList.begin(); |
---|
| 199 | for(int i = 0; it != this->passiveProxyServerList.end(); it++, i++) |
---|
| 200 | { |
---|
| 201 | if( i == index) |
---|
| 202 | return (*it); |
---|
| 203 | } |
---|
| 204 | |
---|
| 205 | return NULL; |
---|
| 206 | } |
---|
| 207 | |
---|
| 208 | |
---|
| 209 | /** |
---|
| 210 | * @param index index to the client |
---|
| 211 | * @return the master server in the list or NULL if none |
---|
| 212 | */ |
---|
| 213 | PeerInfo* NetworkNode::getMasterServer(int index) |
---|
| 214 | { |
---|
| 215 | if( this->masterServerList.size() < index) |
---|
| 216 | return NULL; |
---|
| 217 | |
---|
| 218 | std::list<PeerInfo*>::iterator it = this->masterServerList.begin(); |
---|
| 219 | for(int i = 0; it != this->masterServerList.end(); it++, i++) |
---|
| 220 | { |
---|
| 221 | if( i == index) |
---|
| 222 | return (*it); |
---|
| 223 | } |
---|
| 224 | |
---|
| 225 | return NULL; |
---|
| 226 | } |
---|
| 227 | |
---|
| 228 | |
---|
| 229 | /** |
---|
[9288] | 230 | * debug function |
---|
| 231 | * @param depth: depth in the tree |
---|
| 232 | */ |
---|
| 233 | void NetworkNode::debug(int depth) |
---|
| 234 | { |
---|
| 235 | PRINT(0)(" = %s\n", this->peerInfo->getNodeTypeString().c_str()); |
---|
| 236 | |
---|
[9289] | 237 | PRINT(0)(" master servers: %i\n", this->masterServerList.size()); |
---|
[9288] | 238 | std::list<PeerInfo*>::iterator it = this->masterServerList.begin(); |
---|
| 239 | for(; it != this->masterServerList.end(); it++) |
---|
| 240 | { |
---|
[9334] | 241 | IP* ip = &(*it)->ip; |
---|
[9338] | 242 | PRINT(0)(" - ms, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str()); |
---|
[9288] | 243 | } |
---|
| 244 | |
---|
[9308] | 245 | PRINT(0)(" proxy servers active: %i\n", this->activeProxyServerList.size()); |
---|
[9292] | 246 | it = this->activeProxyServerList.begin(); |
---|
| 247 | for(; it != this->activeProxyServerList.end(); it++) |
---|
[9288] | 248 | { |
---|
[9334] | 249 | IP* ip = &(*it)->ip; |
---|
[9338] | 250 | PRINT(0)(" - ps-a, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str()); |
---|
[9288] | 251 | } |
---|
| 252 | |
---|
[9308] | 253 | PRINT(0)(" proxy servers passive: %i\n", this->passiveProxyServerList.size()); |
---|
| 254 | it = this->passiveProxyServerList.begin(); |
---|
| 255 | for(; it != this->passiveProxyServerList.end(); it++) |
---|
| 256 | { |
---|
[9334] | 257 | IP* ip = &(*it)->ip; |
---|
[9338] | 258 | PRINT(0)(" - ps-p, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str()); |
---|
[9308] | 259 | } |
---|
| 260 | |
---|
[9289] | 261 | PRINT(0)(" clients: %i\n", this->clientList.size()); |
---|
[9288] | 262 | it = this->clientList.begin(); |
---|
| 263 | for(; it != this->clientList.end(); it++) |
---|
| 264 | { |
---|
[9334] | 265 | IP* ip = &(*it)->ip; |
---|
[9338] | 266 | PRINT(0)(" - client, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str()); |
---|
[9288] | 267 | } |
---|
| 268 | } |
---|
| 269 | |
---|