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 | |
---|
18 | #include "debug.h" |
---|
19 | |
---|
20 | |
---|
21 | /** |
---|
22 | * constructor |
---|
23 | */ |
---|
24 | NetworkNode::NetworkNode(PeerInfo* pInfo) |
---|
25 | { |
---|
26 | this->playerNumber = 0; |
---|
27 | this->peerInfo = pInfo; |
---|
28 | } |
---|
29 | |
---|
30 | |
---|
31 | /** |
---|
32 | * deconstructor |
---|
33 | */ |
---|
34 | NetworkNode::~NetworkNode() |
---|
35 | {} |
---|
36 | |
---|
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 | */ |
---|
50 | void NetworkNode::addActiveProxyServer(PeerInfo* node) |
---|
51 | { |
---|
52 | this->activeProxyServerList.push_back(node); |
---|
53 | this->playerNumber++; |
---|
54 | } |
---|
55 | |
---|
56 | /** |
---|
57 | * adds a proxy server |
---|
58 | */ |
---|
59 | void NetworkNode::addPassiveProxyServer(PeerInfo* node) |
---|
60 | { |
---|
61 | this->passiveProxyServerList.push_back(node); |
---|
62 | } |
---|
63 | |
---|
64 | /** |
---|
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 | */ |
---|
95 | void NetworkNode::removeActiveProxyServer(PeerInfo* node) |
---|
96 | { |
---|
97 | std::list<PeerInfo*>::iterator it = this->activeProxyServerList.begin(); |
---|
98 | for(; it != this->activeProxyServerList.end(); it++) |
---|
99 | { |
---|
100 | if( *it == node) |
---|
101 | { |
---|
102 | this->activeProxyServerList.erase(it); |
---|
103 | this->playerNumber--; |
---|
104 | return; |
---|
105 | } |
---|
106 | } |
---|
107 | |
---|
108 | PRINTF(2)("Could not remove proxy server from the list, very strange..."); |
---|
109 | } |
---|
110 | |
---|
111 | /** |
---|
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 | /** |
---|
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 | } |
---|
147 | |
---|
148 | |
---|
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; |
---|
157 | |
---|
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 | |
---|
169 | /** |
---|
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 | /** |
---|
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 | |
---|
237 | PRINT(0)(" master servers: %i\n", this->masterServerList.size()); |
---|
238 | std::list<PeerInfo*>::iterator it = this->masterServerList.begin(); |
---|
239 | for(; it != this->masterServerList.end(); it++) |
---|
240 | { |
---|
241 | IP* ip = &(*it)->ip; |
---|
242 | PRINT(0)(" - ms, id: %i (%s:9999)\n", (*it)->userId, ip->ipString().c_str()); |
---|
243 | } |
---|
244 | |
---|
245 | PRINT(0)(" proxy servers active: %i\n", this->activeProxyServerList.size()); |
---|
246 | it = this->activeProxyServerList.begin(); |
---|
247 | for(; it != this->activeProxyServerList.end(); it++) |
---|
248 | { |
---|
249 | IP* ip = &(*it)->ip; |
---|
250 | PRINT(0)(" - ps-a, id: %i (%s:9999)\n", (*it)->userId, ip->ipString().c_str()); |
---|
251 | } |
---|
252 | |
---|
253 | PRINT(0)(" proxy servers passive: %i\n", this->passiveProxyServerList.size()); |
---|
254 | it = this->passiveProxyServerList.begin(); |
---|
255 | for(; it != this->passiveProxyServerList.end(); it++) |
---|
256 | { |
---|
257 | IP* ip = &(*it)->ip; |
---|
258 | PRINT(0)(" - ps-p, id: %i (%s:9999)\n", (*it)->userId, ip->ipString().c_str()); |
---|
259 | } |
---|
260 | |
---|
261 | PRINT(0)(" clients: %i\n", this->clientList.size()); |
---|
262 | it = this->clientList.begin(); |
---|
263 | for(; it != this->clientList.end(); it++) |
---|
264 | { |
---|
265 | IP* ip = &(*it)->ip; |
---|
266 | PRINT(0)(" - client, id: %i (%s:9999)\n", (*it)->userId, ip->ipString().c_str()); |
---|
267 | } |
---|
268 | } |
---|
269 | |
---|