physicallayer/nettypes.h
00001 /* 00002 Crystal Space Entity Layer 00003 Copyright (C) 2005 by Christian Van Brussel 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Library General Public 00007 License as published by the Free Software Foundation; either 00008 version 2 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Library General Public License for more details. 00014 00015 You should have received a copy of the GNU Library General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 */ 00019 00020 #ifndef __CEL_PL_NETTYPES__ 00021 #define __CEL_PL_NETTYPES__ 00022 00023 #include "cstypes.h" 00024 #include "csutil/scf.h" 00025 #include "csutil/csstring.h" 00026 #include "csutil/bitarray.h" 00027 00028 #include "physicallayer/persist.h" 00029 #include "physicallayer/entity.h" 00030 #include "celtool/persisthelper.h" 00031 00032 struct iCelEntity; 00033 class celGameInfoList; 00034 struct celGameInfoListIterator; 00035 struct iCelGameServer; 00036 struct iCelGameClient; 00037 class csBitArray; 00038 struct celPlayerListIterator; 00039 00048 enum celNetworkGameType 00049 { 00050 CEL_NET_UNDEF = 0, 00051 CEL_NET_SINGLEPLAYER, 00052 CEL_NET_LOCAL, 00053 CEL_NET_PUBLIC, 00054 CEL_NET_PLAYBACK 00055 }; 00056 00058 // TODO: these types must be changed if there are more than 256 values 00059 typedef uint8 celClientEventType; 00060 typedef uint8 celServerEventType; 00061 typedef uint8 celNetworkLinkType; 00062 00078 enum celPlayerNetworkState 00079 { 00080 CEL_NET_PLAYER_UNDEF = 0, 00081 CEL_NET_PLAYER_NOT_CONNECTED, 00082 CEL_NET_PLAYER_CONNECTING, 00083 CEL_NET_PLAYER_PLAYING, 00084 CEL_NET_PLAYER_DISCONNECTED, 00085 CEL_NET_PLAYER_UNREACHABLE, 00086 CEL_NET_PLAYER_LOST 00087 }; 00088 00122 enum celServerNetworkState 00123 { 00124 CEL_NET_SERVER_UNDEF = 0, 00125 CEL_NET_SERVER_NOT_CONNECTED, 00126 CEL_NET_SERVER_INVALID_HOSTNAME, 00127 CEL_NET_SERVER_TRYING_CONNECTION, 00128 CEL_NET_SERVER_CONNECTING, 00129 CEL_NET_SERVER_REJECTED_BAD_GAME, 00130 CEL_NET_SERVER_REJECTED_BAD_PROTOCOL, 00131 CEL_NET_SERVER_REJECTED_BAD_PASSWORD, 00132 CEL_NET_SERVER_REJECTED_SINGLEPLAYER, 00133 CEL_NET_SERVER_REJECTED_UNAUTHORIZED, 00134 CEL_NET_SERVER_REJECTED_MAX_PLAYERS, 00135 CEL_NET_SERVER_LOADING_DATA, 00136 CEL_NET_SERVER_PLAYING, 00137 CEL_NET_SERVER_DISCONNECTED, 00138 CEL_NET_SERVER_UNREACHABLE, 00139 CEL_NET_SERVER_LOST, 00140 CEL_NET_SERVER_KICKED 00141 }; 00142 00146 class celGameInfo 00147 { 00148 public: 00150 uint32 game_id; 00151 00153 csString game_name; 00154 00156 csString hostname; 00157 00159 uint8 ip_address[32]; 00160 00162 uint16 port_nb; 00163 00165 size_t max_players; 00166 00168 size_t current_num_players; 00169 00171 csString password; 00172 00177 csRef<iCelDataBuffer> custom_data; 00178 00179 celGameInfo () 00180 { 00181 game_id = 0; 00182 memset (ip_address, 0, 32); 00183 port_nb = 0; 00184 max_players = 0; 00185 current_num_players = 0; 00186 custom_data = 0; 00187 } 00188 00192 bool MatchFilter (celGameInfo* filter); 00193 00200 int Compare (celGameInfo* other, celGameInfoList* filters); 00201 }; 00202 00206 class celGameInfoList 00207 { 00208 public: 00209 virtual ~celGameInfoList () = 0; 00210 virtual size_t GetCount () const = 0; 00211 virtual celGameInfo* Get (size_t index) const = 0; 00212 virtual size_t Add (celGameInfo* player) = 0; 00213 virtual bool Remove (celGameInfo* player) = 0; 00214 virtual bool Remove (size_t n) = 0; 00215 virtual void RemoveAll () = 0; 00216 virtual size_t Find (celGameInfo* player) const = 0; 00217 00222 void Filter (celGameInfo* game_info); 00223 00228 void Sort (celGameInfoList* filters); 00229 }; 00230 00234 class celPlayer 00235 { 00236 public: 00237 virtual ~celPlayer () {} 00238 00240 uint32 player_id; 00241 00243 csString player_name; 00244 00246 csString hostname; 00247 00249 uint8 ip_address[32]; 00250 00252 uint16 port_nb; 00253 00254 celPlayer () 00255 { 00256 player_id = 0; 00257 memset (ip_address, 0, 32); 00258 port_nb = 0; 00259 } 00260 00261 bool operator == (const celPlayer& other) const 00262 { 00263 return hostname.Compare(other.hostname) && port_nb == other.port_nb; 00264 } 00265 00266 void PrintDebugInfo () 00267 { 00268 printf("Player data:\n"); 00269 printf("\tID: %d\n", player_id); 00270 printf("\tname: %s\n", player_name.GetData()); 00271 printf("\thostname: %s\n", hostname.GetData()); 00272 printf("\taddress: "); 00273 int i = 0; 00274 for ( ; i < 32; i++) 00275 printf("%d", ip_address[i]); 00276 printf("\n"); 00277 printf("\tport: %d\n", port_nb); 00278 } 00279 }; 00280 00284 struct iCelPlayerList : public virtual iBase 00285 { 00286 SCF_INTERFACE (iCelPlayerList, 0, 0, 1); 00287 00288 virtual ~iCelPlayerList () = 0; 00289 virtual size_t GetCount () const = 0; 00290 virtual celPlayer* Get (size_t index) const = 0; 00291 virtual size_t Add (celPlayer* player) = 0; 00292 virtual bool Remove (celPlayer* player) = 0; 00293 virtual bool Remove (size_t n) = 0; 00294 virtual void RemoveAll () = 0; 00295 virtual size_t Find (celPlayer* player) const = 0; 00296 //virtual bool Contains (celPlayer* player) = 0; 00297 }; 00298 00302 class celServerEventData 00303 { 00304 public: 00308 celServerEventType event_type; 00309 00313 csTicks event_time; 00314 00318 csRef<iCelDataBuffer> event_data; 00319 00324 bool reliable; 00325 }; 00326 00330 class celClientEventData 00331 { 00332 public: 00336 celClientEventType event_type; 00337 00341 csTicks event_time; 00342 00346 csRef<iCelDataBuffer> event_data; 00347 00351 bool reliable; 00352 00353 celClientEventData () : 00354 event_type (0), 00355 event_time (0), 00356 event_data (0), 00357 reliable (true) 00358 {} 00359 00360 celClientEventData (celClientEventData &event) : 00361 event_type (event.event_type), 00362 event_time (event.event_time), 00363 event_data (event.event_data), 00364 reliable (event.reliable) 00365 {} 00366 }; 00367 00371 class celNetworkLinkData 00372 { 00373 public: 00377 celNetworkLinkType link_type; 00378 00382 csRef<iCelEntity> linked_entity; 00383 00387 csBitArray persistence_mask; 00388 00394 csTicks period; 00395 00396 celNetworkLinkData () {} 00397 00398 celNetworkLinkData (celNetworkLinkType _link_type, iCelEntity* _linked_entity, 00399 csBitArray _persistence_mask, csTicks _period) : 00400 link_type (_link_type), 00401 linked_entity (_linked_entity), 00402 persistence_mask (_persistence_mask), 00403 period (_period) 00404 {} 00405 00406 ~celNetworkLinkData () {} 00407 }; 00408 00413 struct celNetworkServerStats 00414 { 00415 // The latency of the network transmission to the player 00416 csTicks latency; 00417 // The state of the connection 00418 celServerNetworkState network_state; 00419 // Instant flow of the data sent by the client, in bytes per second 00420 size_t incoming_bandwidth; 00421 // Instant flow of the data sent by the server to this client, in bytes 00422 // per second 00423 size_t outgoing_bandwidth; 00424 }; 00425 00430 struct celNetworkPlayerStats 00431 { 00432 // The latency of the network transmission to the player 00433 csTicks latency; 00434 // Instant flow of the data sent by the client, in bytes per second 00435 size_t incoming_bandwidth; 00436 // Instant flow of the data sent by the server to this client, in bytes 00437 // per second 00438 size_t outgoing_bandwidth; 00439 }; 00440 00445 struct celNetworkPlayerTotalStats 00446 { 00447 // Instant flow of all the data sent by the clients, in bytes per second 00448 size_t total_incoming_bandwidth; 00449 // Instant flow of all the data sent by the server to the clients, in bytes 00450 // per second 00451 size_t total_outgoing_bandwidth; 00452 }; 00453 00454 #endif // __CEL_PL_NETTYPES__
Generated for CEL: Crystal Entity Layer 1.4.1 by doxygen 1.7.1