00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
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
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
00278
00279
00280
00281
00282
00283
00284
00285 printf("\tport: %d\n", port_nb);
00286 }
00287 };
00288
00292 struct iCelPlayerList : public virtual iBase
00293 {
00294 SCF_INTERFACE (iCelPlayerList, 0, 0, 1);
00295
00296 virtual size_t GetCount () const = 0;
00297 virtual celPlayer* Get (size_t index) const = 0;
00298 virtual size_t Add (celPlayer* player) = 0;
00299 virtual bool Remove (celPlayer* player) = 0;
00300 virtual bool Remove (size_t n) = 0;
00301 virtual void RemoveAll () = 0;
00302 virtual size_t Find (celPlayer* player) const = 0;
00303
00304 };
00305
00309 class celServerEventData
00310 {
00311 public:
00315 celServerEventType event_type;
00316
00320 csTicks event_time;
00321
00325 csRef<iCelDataBuffer> event_data;
00326
00331 bool reliable;
00332 };
00333
00337 class celClientEventData
00338 {
00339 public:
00343 celClientEventType event_type;
00344
00348 csTicks event_time;
00349
00353 csRef<iCelDataBuffer> event_data;
00354
00358 bool reliable;
00359
00360 celClientEventData () :
00361 event_type (0),
00362 event_time (0),
00363 event_data (0),
00364 reliable (true)
00365 {}
00366
00367 celClientEventData (celClientEventData &event) :
00368 event_type (event.event_type),
00369 event_time (event.event_time),
00370 event_data (event.event_data),
00371 reliable (event.reliable)
00372 {}
00373 };
00374
00378 class celNetworkLinkData
00379 {
00380 public:
00384 celNetworkLinkType link_type;
00385
00389 csRef<iCelEntity> linked_entity;
00390
00394 csBitArray persistence_mask;
00395
00401 csTicks period;
00402
00403 celNetworkLinkData () {}
00404
00405 celNetworkLinkData (celNetworkLinkType _link_type, iCelEntity* _linked_entity,
00406 csBitArray _persistence_mask, csTicks _period) :
00407 link_type (_link_type),
00408 linked_entity (_linked_entity),
00409 persistence_mask (_persistence_mask),
00410 period (_period)
00411 {}
00412
00413 ~celNetworkLinkData () {}
00414 };
00415
00420 struct celNetworkServerStats
00421 {
00422
00423 csTicks latency;
00424
00425 celServerNetworkState network_state;
00426
00427 size_t incoming_bandwidth;
00428
00429
00430 size_t outgoing_bandwidth;
00431 };
00432
00437 struct celNetworkPlayerStats
00438 {
00439
00440 csTicks latency;
00441
00442 size_t incoming_bandwidth;
00443
00444
00445 size_t outgoing_bandwidth;
00446 };
00447
00452 struct celNetworkPlayerTotalStats
00453 {
00454
00455 size_t total_incoming_bandwidth;
00456
00457
00458 size_t total_outgoing_bandwidth;
00459 };
00460
00461 #endif // __CEL_PL_NETTYPES__