CEL: Crystal Entity Layer: physicallayer/nettypes.h Source File (CEL: Crystal Entity Layer Public API Reference)

| ## Public API Reference

- Main Page
- Classes
- Files

# 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
    00050 enum celNetworkGameType
    00051 {
    00052   CEL_NET_UNDEF = 0,
    00053   CEL_NET_SINGLEPLAYER,
    00054   CEL_NET_LOCAL,
    00055   CEL_NET_PUBLIC,
    00056   CEL_NET_PLAYBACK
    00057 };
    00058
    00060 // TODO: these types must be changed if there are more than 256 values
    00061 typedef uint8 celClientEventType;
    00062 typedef uint8 celServerEventType;
    00063 typedef uint8 celNetworkLinkType;
    00064
    00082 enum celPlayerNetworkState
    00083 {
    00084   CEL_NET_PLAYER_UNDEF = 0,
    00085   CEL_NET_PLAYER_NOT_CONNECTED,
    00086   CEL_NET_PLAYER_CONNECTING,
    00087   CEL_NET_PLAYER_PLAYING,
    00088   CEL_NET_PLAYER_DISCONNECTED,
    00089   CEL_NET_PLAYER_UNREACHABLE,
    00090   CEL_NET_PLAYER_LOST
    00091 };
    00092
    00128 enum celServerNetworkState
    00129 {
    00130   CEL_NET_SERVER_UNDEF = 0,
    00131   CEL_NET_SERVER_NOT_CONNECTED,
    00132   CEL_NET_SERVER_INVALID_HOSTNAME,
    00133   CEL_NET_SERVER_TRYING_CONNECTION,
    00134   CEL_NET_SERVER_CONNECTING,
    00135   CEL_NET_SERVER_REJECTED_BAD_GAME,
    00136   CEL_NET_SERVER_REJECTED_BAD_PROTOCOL,
    00137   CEL_NET_SERVER_REJECTED_BAD_PASSWORD,
    00138   CEL_NET_SERVER_REJECTED_SINGLEPLAYER,
    00139   CEL_NET_SERVER_REJECTED_UNAUTHORIZED,
    00140   CEL_NET_SERVER_REJECTED_MAX_PLAYERS,
    00141   CEL_NET_SERVER_LOADING_DATA,
    00142   CEL_NET_SERVER_PLAYING,
    00143   CEL_NET_SERVER_DISCONNECTED,
    00144   CEL_NET_SERVER_UNREACHABLE,
    00145   CEL_NET_SERVER_LOST,
    00146   CEL_NET_SERVER_KICKED
    00147 };
    00148
    00152 class celGameInfo
    00153 {
    00154  public:
    00156   uint32 game_id;
    00157
    00159   csString game_name;
    00160
    00162   csString hostname;
    00163
    00165   uint8 ip_address[32];
    00166
    00168   uint16 port_nb;
    00169
    00171   size_t max_players;
    00172
    00174   size_t current_num_players;
    00175
    00177   csString password;
    00178
    00183   csRef<iCelDataBuffer> custom_data;
    00184
    00185   celGameInfo ()
    00186   {
    00187     game_id = 0;
    00188     memset (ip_address, 0, 32);
    00189     port_nb = 0;
    00190     max_players = 0;
    00191     current_num_players = 0;
    00192     custom_data = 0;
    00193   }
    00194
    00198   bool MatchFilter (celGameInfo* filter);
    00199
    00206   int Compare (celGameInfo* other, celGameInfoList* filters);
    00207 };
    00208
    00212 class celGameInfoList
    00213 {
    00214  public:
    00215   virtual size_t GetCount () const = 0;
    00216   virtual celGameInfo* Get (size_t index) const = 0;
    00217   virtual size_t Add (celGameInfo* player) = 0;
    00218   virtual bool Remove (celGameInfo* player) = 0;
    00219   virtual bool Remove (size_t n) = 0;
    00220   virtual void RemoveAll () = 0;
    00221   virtual size_t Find (celGameInfo* player) const = 0;
    00222
    00227   void Filter (celGameInfo* game_info);
    00228
    00233   void Sort (celGameInfoList* filters);
    00234 };
    00235
    00239 class celPlayer
    00240 {
    00241  public:
    00243   uint32 player_id;
    00244
    00246   csString player_name;
    00247
    00249   csString hostname;
    00250
    00252   uint8 ip_address[32];
    00253
    00255   uint16 port_nb;
    00256
    00257   celPlayer ()
    00258   {
    00259     player_id = 0;
    00260     memset (ip_address, 0, 32);
    00261     port_nb = 0;
    00262   }
    00263
    00264   bool operator == (const celPlayer& other) const
    00265   {
    00266     return hostname.Compare(other.hostname) && port_nb == other.port_nb;
    00267   }
    00268
    00269   void PrintDebugInfo ()
    00270   {
    00271     printf("Player data:\n");
    00272     printf("\tID: %d\n", player_id);
    00273     printf("\tname: %s\n", player_name.GetData());
    00274     printf("\thostname: %s\n", hostname.GetData());
    00275     printf("\taddress: ");
    00276     int i = 0;
    00277     for ( ; i < 32; i++)
    00278       printf("%d", ip_address[i]);
    00279     printf("\n");
    00280     printf("\tport: %d\n", port_nb);
    00281   }
    00282 };
    00283
    00284 SCF_VERSION (iCelPlayerList, 0, 0, 1);
    00285
    00289 struct iCelPlayerList
    00290 {
    00291  public:
    00292   virtual size_t GetCount () const = 0;
    00293   virtual celPlayer* Get (size_t index) const = 0;
    00294   virtual size_t Add (celPlayer* player) = 0;
    00295   virtual bool Remove (celPlayer* player) = 0;
    00296   virtual bool Remove (size_t n) = 0;
    00297   virtual void RemoveAll () = 0;
    00298   virtual size_t Find (celPlayer* player) const = 0;
    00299   //virtual bool Contains (celPlayer* player) = 0;
    00300 };
    00301
    00305 class celServerEventData
    00306 {
    00307  public:
    00311   celServerEventType event_type;
    00312
    00316   csTicks event_time;
    00317
    00321   csRef<iCelDataBuffer> event_data;
    00322
    00327   bool reliable;
    00328 };
    00329
    00333 class celClientEventData
    00334 {
    00335  public:
    00339   celClientEventType event_type;
    00340
    00344   csTicks event_time;
    00345
    00349   csRef<iCelDataBuffer> event_data;
    00350
    00354   bool reliable;
    00355
    00356   celClientEventData () :
    00357     event_type (0),
    00358     event_time (0),
    00359     event_data (0),
    00360     reliable (true)
    00361     {}
    00362
    00363   celClientEventData (celClientEventData &event) :
    00364     event_type (event.event_type),
    00365     event_time (event.event_time),
    00366     event_data (event.event_data),
    00367     reliable (event.reliable)
    00368     {}
    00369 };
    00370
    00374 class celNetworkLinkData
    00375 {
    00376  public:
    00380   celNetworkLinkType link_type;
    00381
    00385   csRef<iCelEntity> linked_entity;
    00386
    00390   csBitArray persistence_mask;
    00391
    00397   csTicks period;
    00398
    00399   celNetworkLinkData () {}
    00400
    00401   celNetworkLinkData (celNetworkLinkType _link_type, iCelEntity* _linked_entity,
    00402                       csBitArray _persistence_mask, csTicks _period) :
    00403     link_type (_link_type),
    00404     linked_entity (_linked_entity),
    00405     persistence_mask (_persistence_mask),
    00406     period (_period)
    00407     {}
    00408
    00409   ~celNetworkLinkData () {}
    00410 };
    00411
    00416 struct celNetworkServerStats
    00417 {
    00418   // The latency of the network transmission to the player
    00419   csTicks latency;
    00420   // The state of the connection
    00421   celServerNetworkState network_state;
    00422   // Instant flow of the data sent by the client, in bytes per second
    00423   size_t incoming_bandwidth;
    00424   // Instant flow of the data sent by the server to this client, in bytes
    00425   // per second
    00426   size_t outgoing_bandwidth;
    00427 };
    00428
    00433 struct celNetworkPlayerStats
    00434 {
    00435   // The latency of the network transmission to the player
    00436   csTicks latency;
    00437   // Instant flow of the data sent by the client, in bytes per second
    00438   size_t incoming_bandwidth;
    00439   // Instant flow of the data sent by the server to this client, in bytes
    00440   // per second
    00441   size_t outgoing_bandwidth;
    00442 };
    00443
    00448 struct celNetworkPlayerTotalStats
    00449 {
    00450   // Instant flow of all the data sent by the clients, in bytes per second
    00451   size_t total_incoming_bandwidth;
    00452   // Instant flow of all the data sent by the server to the clients, in bytes
    00453   // per second
    00454   size_t total_outgoing_bandwidth;
    00455 };
    00456
    00457 #endif // __CEL_PL_NETTYPES__