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 | this->connectionNumber++; |
---|
46 | } |
---|
47 | |
---|
48 | /** |
---|
49 | * adds a proxy server |
---|
50 | */ |
---|
51 | void NetworkNode::addActiveProxyServer(PeerInfo* node) |
---|
52 | { |
---|
53 | this->activeProxyServerList.push_back(node); |
---|
54 | this->connectionNumber++; |
---|
55 | } |
---|
56 | |
---|
57 | /** |
---|
58 | * adds a proxy server |
---|
59 | */ |
---|
60 | void NetworkNode::addPassiveProxyServer(PeerInfo* node) |
---|
61 | { |
---|
62 | this->passiveProxyServerList.push_back(node); |
---|
63 | } |
---|
64 | |
---|
65 | /** |
---|
66 | * adds a master server |
---|
67 | */ |
---|
68 | void NetworkNode::addMasterServer(PeerInfo* node) |
---|
69 | { |
---|
70 | this->masterServerList.push_back(node); |
---|
71 | this->playerNumber++; |
---|
72 | } |
---|
73 | |
---|
74 | /** |
---|
75 | * removes a client |
---|
76 | */ |
---|
77 | void NetworkNode::removeClient(PeerInfo* node) |
---|
78 | { |
---|
79 | std::list<PeerInfo*>::iterator it = this->clientList.begin(); |
---|
80 | for(; it != this->clientList.end(); it++) |
---|
81 | { |
---|
82 | if( *it == node) |
---|
83 | { |
---|
84 | this->clientList.erase(it); |
---|
85 | this->playerNumber--; |
---|
86 | return; |
---|
87 | } |
---|
88 | } |
---|
89 | |
---|
90 | PRINTF(2)("Could not remove client from the list, very strange..."); |
---|
91 | } |
---|
92 | |
---|
93 | /** |
---|
94 | * removes a proxy server |
---|
95 | */ |
---|
96 | void NetworkNode::removeActiveProxyServer(PeerInfo* node) |
---|
97 | { |
---|
98 | std::list<PeerInfo*>::iterator it = this->activeProxyServerList.begin(); |
---|
99 | for(; it != this->activeProxyServerList.end(); it++) |
---|
100 | { |
---|
101 | if( *it == node) |
---|
102 | { |
---|
103 | this->activeProxyServerList.erase(it); |
---|
104 | this->playerNumber--; |
---|
105 | return; |
---|
106 | } |
---|
107 | } |
---|
108 | |
---|
109 | PRINTF(2)("Could not remove proxy server from the list, very strange..."); |
---|
110 | } |
---|
111 | |
---|
112 | /** |
---|
113 | * removes a proxy server |
---|
114 | */ |
---|
115 | void NetworkNode::removePassiveProxyServer(PeerInfo* node) |
---|
116 | { |
---|
117 | std::list<PeerInfo*>::iterator it = this->passiveProxyServerList.begin(); |
---|
118 | for(; it != this->passiveProxyServerList.end(); it++) |
---|
119 | { |
---|
120 | if( *it == node) |
---|
121 | { |
---|
122 | this->passiveProxyServerList.erase(it); |
---|
123 | return; |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | PRINTF(2)("Could not remove proxy server from the list, very strange..."); |
---|
128 | } |
---|
129 | |
---|
130 | /** |
---|
131 | * removes a master server |
---|
132 | */ |
---|
133 | void NetworkNode::removeMasterServer(PeerInfo* node) |
---|
134 | { |
---|
135 | std::list<PeerInfo*>::iterator it = this->masterServerList.begin(); |
---|
136 | for(; it != this->masterServerList.end(); it++) |
---|
137 | { |
---|
138 | if( *it == node) |
---|
139 | { |
---|
140 | this->masterServerList.erase(it); |
---|
141 | this->playerNumber--; |
---|
142 | return; |
---|
143 | } |
---|
144 | } |
---|
145 | |
---|
146 | PRINTF(2)("Could not remove client from the list, very strange..."); |
---|
147 | } |
---|
148 | |
---|
149 | |
---|
150 | /** |
---|
151 | * @param index index to the client |
---|
152 | * @return the client in the list or NULL if none |
---|
153 | */ |
---|
154 | PeerInfo* NetworkNode::getClient(int index) |
---|
155 | { |
---|
156 | if( this->clientList.size() < index) |
---|
157 | return NULL; |
---|
158 | |
---|
159 | std::list<PeerInfo*>::iterator it = this->clientList.begin(); |
---|
160 | for(int i = 0; it != this->clientList.end(); it++, i++) |
---|
161 | { |
---|
162 | if( i == index) |
---|
163 | return (*it); |
---|
164 | } |
---|
165 | |
---|
166 | return NULL; |
---|
167 | } |
---|
168 | |
---|
169 | |
---|
170 | /** |
---|
171 | * @param index index to the client |
---|
172 | * @return the active proxy server in the list or NULL if none |
---|
173 | */ |
---|
174 | PeerInfo* NetworkNode::getActiveProxyServer(int index) |
---|
175 | { |
---|
176 | if( this->activeProxyServerList.size() < index) |
---|
177 | return NULL; |
---|
178 | |
---|
179 | std::list<PeerInfo*>::iterator it = this->activeProxyServerList.begin(); |
---|
180 | for(int i = 0; it != this->activeProxyServerList.end(); it++, i++) |
---|
181 | { |
---|
182 | if( i == index) |
---|
183 | return (*it); |
---|
184 | } |
---|
185 | |
---|
186 | return NULL; |
---|
187 | } |
---|
188 | |
---|
189 | |
---|
190 | /** |
---|
191 | * @param index index to the client |
---|
192 | * @return the passive proxy server in the list or NULL if none |
---|
193 | */ |
---|
194 | PeerInfo* NetworkNode::getPassiveProxyServer(int index) |
---|
195 | { |
---|
196 | if( this->passiveProxyServerList.size() < index) |
---|
197 | return NULL; |
---|
198 | |
---|
199 | std::list<PeerInfo*>::iterator it = this->passiveProxyServerList.begin(); |
---|
200 | for(int i = 0; it != this->passiveProxyServerList.end(); it++, i++) |
---|
201 | { |
---|
202 | if( i == index) |
---|
203 | return (*it); |
---|
204 | } |
---|
205 | |
---|
206 | return NULL; |
---|
207 | } |
---|
208 | |
---|
209 | |
---|
210 | /** |
---|
211 | * @param index index to the client |
---|
212 | * @return the master server in the list or NULL if none |
---|
213 | */ |
---|
214 | PeerInfo* NetworkNode::getMasterServer(int index) |
---|
215 | { |
---|
216 | if( this->masterServerList.size() < index) |
---|
217 | return NULL; |
---|
218 | |
---|
219 | std::list<PeerInfo*>::iterator it = this->masterServerList.begin(); |
---|
220 | for(int i = 0; it != this->masterServerList.end(); it++, i++) |
---|
221 | { |
---|
222 | if( i == index) |
---|
223 | return (*it); |
---|
224 | } |
---|
225 | |
---|
226 | return NULL; |
---|
227 | } |
---|
228 | |
---|
229 | |
---|
230 | /** |
---|
231 | * debug function |
---|
232 | * @param depth: depth in the tree |
---|
233 | */ |
---|
234 | void NetworkNode::debug(int depth) |
---|
235 | { |
---|
236 | PRINT(0)(" = %s\n", this->peerInfo->getNodeTypeString().c_str()); |
---|
237 | |
---|
238 | PRINT(0)(" master servers: %i\n", this->masterServerList.size()); |
---|
239 | std::list<PeerInfo*>::iterator it = this->masterServerList.begin(); |
---|
240 | for(; it != this->masterServerList.end(); it++) |
---|
241 | { |
---|
242 | IP* ip = &(*it)->ip; |
---|
243 | PRINT(0)(" - ms, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str()); |
---|
244 | } |
---|
245 | |
---|
246 | PRINT(0)(" proxy servers active: %i\n", this->activeProxyServerList.size()); |
---|
247 | it = this->activeProxyServerList.begin(); |
---|
248 | for(; it != this->activeProxyServerList.end(); it++) |
---|
249 | { |
---|
250 | IP* ip = &(*it)->ip; |
---|
251 | PRINT(0)(" - ps-a, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str()); |
---|
252 | } |
---|
253 | |
---|
254 | PRINT(0)(" proxy servers passive: %i\n", this->passiveProxyServerList.size()); |
---|
255 | it = this->passiveProxyServerList.begin(); |
---|
256 | for(; it != this->passiveProxyServerList.end(); it++) |
---|
257 | { |
---|
258 | IP* ip = &(*it)->ip; |
---|
259 | PRINT(0)(" - ps-p, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str()); |
---|
260 | } |
---|
261 | |
---|
262 | PRINT(0)(" clients: %i\n", this->clientList.size()); |
---|
263 | it = this->clientList.begin(); |
---|
264 | for(; it != this->clientList.end(); it++) |
---|
265 | { |
---|
266 | IP* ip = &(*it)->ip; |
---|
267 | PRINT(0)(" - client, id: %i (%s)\n", (*it)->userId, ip->ipString().c_str()); |
---|
268 | } |
---|
269 | } |
---|
270 | |
---|