Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

CSNetMgr.h File Reference

#include "BaseType.h"

Go to the source code of this file.

Compounds

struct  geCSNetMgr_NetClient

Defines

#define MAX_CLIENT_NAME   256

Typedefs

typedef geCSNetMgr geCSNetMgr
typedef uint32 geCSNetMgr_NetID

Enumerations

enum  geCSNetMgr_NetMsgType {
  NET_MSG_NONE, NET_MSG_USER, NET_MSG_CREATE_CLIENT, NET_MSG_DESTROY_CLIENT,
  NET_MSG_HOST, NET_MSG_SESSIONLOST, NET_MSG_SERVER_ID
}

Functions

GENESISAPI geCSNetMgr *GENESISCC geCSNetMgr_Create (void)
GENESISAPI void GENESISCC geCSNetMgr_Destroy (geCSNetMgr **ppM)
GENESISAPI geCSNetMgr_NetID
GENESISCC 
geCSNetMgr_GetServerID (geCSNetMgr *M)
GENESISAPI geCSNetMgr_NetID
GENESISCC 
geCSNetMgr_GetOurID (geCSNetMgr *M)
GENESISAPI geCSNetMgr_NetID
GENESISCC 
geCSNetMgr_GetAllPlayerID (geCSNetMgr *M)
GENESISAPI geBoolean GENESISCC geCSNetMgr_ReceiveFromServer (geCSNetMgr *M, geCSNetMgr_NetMsgType *Type, int32 *Size, uint8 **Data)
GENESISAPI geBoolean GENESISCC geCSNetMgr_ReceiveFromClient (geCSNetMgr *M, geCSNetMgr_NetMsgType *Type, geCSNetMgr_NetID *IdClient, int32 *Size, uint8 **Data)
GENESISAPI geBoolean GENESISCC geCSNetMgr_ReceiveSystemMessage (geCSNetMgr *M, geCSNetMgr_NetID IdFor, geCSNetMgr_NetMsgType *Type, geCSNetMgr_NetClient *Client)
GENESISAPI geBoolean GENESISCC geCSNetMgr_ReceiveAllMessages (geCSNetMgr *M, geCSNetMgr_NetID *IdFrom, geCSNetMgr_NetID *IdTo, geCSNetMgr_NetMsgType *Type, int32 *Size, uint8 **Data)
GENESISAPI geBoolean GENESISCC geCSNetMgr_WeAreTheServer (geCSNetMgr *M)
GENESISAPI geBoolean GENESISCC geCSNetMgr_StartSession (geCSNetMgr *M, const char *SessionName, const char *PlayerName)
GENESISAPI geBoolean GENESISCC geCSNetMgr_StopSession (geCSNetMgr *M)
GENESISAPI geBoolean GENESISCC geCSNetMgr_SendToServer (geCSNetMgr *M, geBoolean Guaranteed, uint8 *Data, int32 DataSize)
GENESISAPI geBoolean GENESISCC geCSNetMgr_SendToClient (geCSNetMgr *M, geCSNetMgr_NetID To, geBoolean Guaranteed, uint8 *Data, int32 DataSize)


Define Documentation

#define MAX_CLIENT_NAME   256
 

Definition at line 41 of file CSNetMgr.h.

Referenced by geCSNetMgr_ProcessSystemMessage(), and geCSNetMgr_StartSession().


Typedef Documentation

typedef struct geCSNetMgr geCSNetMgr
 

Definition at line 38 of file CSNetMgr.h.

typedef uint32 geCSNetMgr_NetID
 

Definition at line 40 of file CSNetMgr.h.

Referenced by geCSNetMgr_GetAllPlayerID(), geCSNetMgr_GetOurID(), geCSNetMgr_GetServerID(), NetMgr_GetOurID(), NetMgr_ReceiveClientMessage(), and ReadClientMessages().


Enumeration Type Documentation

enum geCSNetMgr_NetMsgType
 

Enumeration values:
NET_MSG_NONE 
NET_MSG_USER 
NET_MSG_CREATE_CLIENT 
NET_MSG_DESTROY_CLIENT 
NET_MSG_HOST 
NET_MSG_SESSIONLOST 
NET_MSG_SERVER_ID 

Definition at line 44 of file CSNetMgr.h.

Referenced by Client_ReadServerMessages(), and ReadClientMessages().

00045 {
00046         NET_MSG_NONE,                                   // No msg
00047         NET_MSG_USER,                                   // User message
00048         NET_MSG_CREATE_CLIENT,                  // A new client has joined in
00049         NET_MSG_DESTROY_CLIENT,                 // An existing client has left
00050         NET_MSG_HOST,                                   // We are the server now
00051         NET_MSG_SESSIONLOST,                    // Connection was lost
00052         NET_MSG_SERVER_ID,                              // Internal, for hand shaking process
00053 } geCSNetMgr_NetMsgType;


Function Documentation

GENESISAPI geCSNetMgr* GENESISCC geCSNetMgr_Create void   ) 
 

Definition at line 82 of file CSNetMgr.c.

00083 {
00084         geCSNetMgr *M;
00085 
00086         M = GE_RAM_ALLOCATE_STRUCT(geCSNetMgr);
00087         
00088         if ( M == NULL)
00089         {
00090                 geErrorLog_Add(-1, NULL); //FIXME
00091                 return NULL;
00092         }
00093 
00094         M->Valid = M;
00095 
00096         return M;
00097 }

GENESISAPI void GENESISCC geCSNetMgr_Destroy geCSNetMgr **  ppM  ) 
 

Definition at line 100 of file CSNetMgr.c.

00101 {
00102         assert( ppM != NULL );
00103         assert( geCSNetMgr_IsValid(*ppM)!=GE_FALSE );
00104         
00105         (*ppM) -> Valid = 0;
00106         geRam_Free(*ppM);
00107         *ppM = NULL;    
00108 };

GENESISAPI geCSNetMgr_NetID GENESISCC geCSNetMgr_GetAllPlayerID geCSNetMgr M  ) 
 

Definition at line 423 of file CSNetMgr.c.

00424 {
00425         assert( geCSNetMgr_IsValid(M)!=GE_FALSE );
00426         return(DPID_ALLPLAYERS);
00427 }

GENESISAPI geCSNetMgr_NetID GENESISCC geCSNetMgr_GetOurID geCSNetMgr M  ) 
 

Definition at line 414 of file CSNetMgr.c.

00415 {
00416         assert( geCSNetMgr_IsValid(M)!=GE_FALSE );
00417         return(OurPlayerId);
00418 }

GENESISAPI geCSNetMgr_NetID GENESISCC geCSNetMgr_GetServerID geCSNetMgr M  ) 
 

Definition at line 405 of file CSNetMgr.c.

00406 {
00407         assert( geCSNetMgr_IsValid(M)!=GE_FALSE );
00408         return(ServerId);
00409 }

GENESISAPI geBoolean GENESISCC geCSNetMgr_ReceiveAllMessages geCSNetMgr M,
geCSNetMgr_NetID IdFrom,
geCSNetMgr_NetID IdTo,
geCSNetMgr_NetMsgType Type,
int32 Size,
uint8 **  Data
 

Definition at line 342 of file CSNetMgr.c.

00343 {
00344         DWORD                           BSize = BUFFER_SIZE;
00345         HRESULT                         Result;
00346 
00347         assert( geCSNetMgr_IsValid(M)!=GE_FALSE );
00348 
00349         *Size = 0;
00350         *Data = NULL;
00351         *Type = NET_MSG_NONE;
00352 
00353         if (!NetSession)
00354                 return GE_FALSE;
00355         
00356     *IdFrom = 0;
00357         *IdTo = 0;
00358         //*IdTo = ServerId;
00359 
00360         Result = NetPlayReceive((DPID*)IdFrom, (DPID*)IdTo, DPRECEIVE_ALL, &Packet, &BSize);
00361         //Result = NetPlayReceive((DPID*)IdFrom, (DPID*)IdTo, DPRECEIVE_TOPLAYER, &Packet, &BSize);
00362 
00363         if (*IdTo != ServerId)
00364                 return GE_TRUE;
00365 
00366         if (Result != DP_OK)
00367         {
00368                 if (Result == DPERR_NOMESSAGES)
00369                         return GE_TRUE;         // Not an error, there is simply no msg's. (*Size will == 0, so they will know)
00370 
00371                 return GE_FALSE;
00372         }
00373 
00374         if (BSize > 0)
00375         {
00376                 if (*IdFrom == DPID_SYSMSG)
00377                 {
00378                         // IdTo used to be DPID_ALLPLAYERS...
00379                         // Had to change to IdTo so it would work correctly.
00380                         if (!geCSNetMgr_ProcessSystemMessage(M, *IdTo, (LPDPMSG_GENERIC)&Packet, Type, &gClient))
00381                                 return GE_FALSE;
00382 
00383                         if (*Type != NET_MSG_NONE)
00384                         {
00385                                 *Size = sizeof( geCSNetMgr_NetClient );
00386                                 *Data = (uint8*)&gClient;
00387                         }
00388                 }
00389                 else
00390                 {       
00391                         *Type = Packet[0];
00392                         *Size = BSize - PACKET_HEADER_SIZE;
00393                         *Data = (uint8*)&Packet[1];
00394                         return GE_TRUE;
00395                 }
00396         }
00397 
00398     return GE_TRUE;
00399 }

GENESISAPI geBoolean GENESISCC geCSNetMgr_ReceiveFromClient geCSNetMgr M,
geCSNetMgr_NetMsgType Type,
geCSNetMgr_NetID IdClient,
int32 Size,
uint8 **  Data
 

Definition at line 174 of file CSNetMgr.c.

00175 {
00176         DPID                            IdTo;
00177         DWORD                           BSize = BUFFER_SIZE;
00178         HRESULT                         Result;
00179 
00180         *Size = 0;
00181         *Data = NULL;
00182         *Type = NET_MSG_NONE;
00183 
00184         assert( geCSNetMgr_IsValid(M)!=GE_FALSE );
00185         
00186         if (!NetSession)
00187                 return GE_FALSE;
00188         
00189         // Empty out all the system msg's first
00190         if (!geCSNetMgr_ReceiveSystemMessage(M, ServerId, Type, &gClient))
00191                 return GE_FALSE;
00192 
00193         if (*Type != NET_MSG_NONE)
00194         {
00195                 *Size = sizeof( geCSNetMgr_NetClient );
00196                 *Data = (uint8*)&gClient;
00197                 return( GE_TRUE );
00198         }
00199 
00200         // Find the client player
00201         IdTo = ServerId;
00202 
00203     Result = NetPlayReceive((DPID*)IdClient, &IdTo, DPRECEIVE_TOPLAYER, (uint8*)&Packet, &BSize);
00204 
00205         if (Result != DP_OK)
00206         {
00207                 if (Result == DPERR_NOMESSAGES)
00208                         return GE_TRUE;         // Not an error, there is simply no msg's. (*Size will == 0, so they will know)
00209 
00210                 return GE_FALSE;
00211         }
00212 
00213         if (BSize > 0)
00214         {
00215                 *Type = Packet[0];
00216                 *Size = BSize - PACKET_HEADER_SIZE;
00217                 *Data = (uint8*)&Packet[1];
00218         }
00219 
00220     return GE_TRUE;     
00221 }

GENESISAPI geBoolean GENESISCC geCSNetMgr_ReceiveFromServer geCSNetMgr M,
geCSNetMgr_NetMsgType Type,
int32 Size,
uint8 **  Data
 

Definition at line 113 of file CSNetMgr.c.

00114 {
00115         DPID                            IdTo;
00116         DWORD                           BSize = BUFFER_SIZE;
00117         HRESULT                         Result;
00118 
00119         *Size = 0;
00120         *Data = NULL;
00121         *Type = NET_MSG_NONE;
00122         
00123         assert( geCSNetMgr_IsValid(M)!=GE_FALSE );
00124 
00125         if (!NetSession)
00126         {
00127                 geErrorLog_AddString(-1, "geCSNetMgr_ReceiveFromServer:  No net session.\n", NULL);
00128                 return GE_FALSE;
00129         }
00130 
00131 #if 1
00132         // Empty out all the system msg's first
00133         if (!geCSNetMgr_ReceiveSystemMessage(M, OurPlayerId, Type, &gClient))
00134         {
00135                 geErrorLog_AddString(-1, "geCSNetMgr_ReceiveFromServer:  geCSNetMgr_ReceiveSystemMessage failed.\n", NULL);
00136                 return GE_FALSE;
00137         }
00138 
00139         if (*Type != NET_MSG_NONE)
00140         {
00141                 *Size = sizeof( geCSNetMgr_NetClient );
00142                 *Data = (uint8*)&gClient;
00143                 return( GE_TRUE );
00144         }
00145 #endif
00146 
00147         // Find the server player
00148         IdTo = 0;
00149 
00150         Result = NetPlayReceive(&ServerId, &IdTo, DPRECEIVE_FROMPLAYER, (uint8*)&Packet, &BSize);
00151 
00152         if (Result != DP_OK)
00153         {
00154                 if (Result == DPERR_NOMESSAGES)
00155                         return GE_TRUE;         // Not an error, there is simply no msg's. (*Size will == 0, so they will know)
00156 
00157                 geErrorLog_AddString(-1, "geCSNetMgr_ReceiveFromServer:  NetPlayReceive failed.\n", NULL);
00158                 return GE_FALSE;
00159         }
00160 
00161         if (BSize > 0)
00162         {
00163                 *Type = Packet[0];
00164                 *Size = BSize - PACKET_HEADER_SIZE;
00165                 *Data = (uint8*)&Packet[1];
00166         }
00167 
00168     return GE_TRUE;
00169 }

GENESISAPI geBoolean GENESISCC geCSNetMgr_ReceiveSystemMessage geCSNetMgr M,
geCSNetMgr_NetID  IdFor,
geCSNetMgr_NetMsgType Type,
geCSNetMgr_NetClient Client
 

Definition at line 226 of file CSNetMgr.c.

00227 {
00228         DPID                            SystemId, IdTo;
00229         DWORD                           BSize = BUFFER_SIZE;
00230         HRESULT                         Result;
00231 
00232         assert( geCSNetMgr_IsValid(M)!=GE_FALSE );
00233 
00234         *Type = NET_MSG_NONE;
00235 
00236         if (!NetSession)
00237                 return GE_FALSE;
00238 
00239         // Find system messages
00240         SystemId = DPID_SYSMSG;
00241         IdTo = IdFor;
00242 
00243         Result = NetPlayReceive(&SystemId,&IdTo, DPRECEIVE_FROMPLAYER | DPRECEIVE_TOPLAYER, &Packet, &BSize);
00244 
00245         if (Result != DP_OK)
00246         {
00247                 if (Result == DPERR_NOMESSAGES)
00248                         return GE_TRUE;         // Not an error, there is simply no msg's. (*Size will == 0, so they will know)
00249 
00250                 return GE_FALSE;
00251         }
00252 
00253         if (BSize > 0)
00254         {
00255                 if (!geCSNetMgr_ProcessSystemMessage(M, IdFor, (LPDPMSG_GENERIC)&Packet, Type, Client))
00256                         return GE_FALSE;
00257         }
00258 
00259     return GE_TRUE;
00260 }

GENESISAPI geBoolean GENESISCC geCSNetMgr_SendToClient geCSNetMgr M,
geCSNetMgr_NetID  To,
geBoolean  Guaranteed,
uint8 Data,
int32  DataSize
 

GENESISAPI geBoolean GENESISCC geCSNetMgr_SendToServer geCSNetMgr M,
geBoolean  Guaranteed,
uint8 Data,
int32  DataSize
 

GENESISAPI geBoolean GENESISCC geCSNetMgr_StartSession geCSNetMgr M,
const char *  SessionName,
const char *  PlayerName
 

Definition at line 441 of file CSNetMgr.c.

00442 {
00443         char            Name2[MAX_CLIENT_NAME];
00444 
00445         assert( geCSNetMgr_IsValid(M)!=GE_FALSE );
00446         assert(PlayerName);
00447 
00448         NetSession = GE_FALSE;
00449         WeAreTheServer = GE_FALSE;
00450 
00451         if (!InitNetPlay((LPGUID)&GENESIS_GUID))
00452                 return GE_FALSE;
00453 
00454         if (!NetPlayCreateSession((char*)SessionName, 16))
00455                 return GE_FALSE;
00456         
00457         if (!NetPlayCreatePlayer(&ServerId, "Server", NULL, NULL, 0, GE_TRUE))
00458         {
00459                 geErrorLog_AddString(-1, "geCSNetMgr_StartSession:  NetPlayCreatePlayer failed for server player.\n", NULL);
00460                 return GE_FALSE;
00461         }
00462 
00463         strncpy(Name2, PlayerName, MAX_CLIENT_NAME);
00464 
00465         if (!NetPlayCreatePlayer(&OurPlayerId, Name2, NULL, NULL, 0, GE_FALSE))
00466         {
00467                 geErrorLog_AddString(-1, "geCSNetMgr_StartSession:  NetPlayCreatePlayer failed for client player.\n", NULL);
00468                 return GE_FALSE;
00469         }
00470 
00471         WeAreTheServer = GE_TRUE;
00472         NetSession = GE_TRUE;
00473 
00474         return GE_TRUE;
00475 }       

GENESISAPI geBoolean GENESISCC geCSNetMgr_StopSession geCSNetMgr M  ) 
 

Definition at line 568 of file CSNetMgr.c.

00569 {
00570         assert( geCSNetMgr_IsValid(M)!=GE_FALSE );
00571 
00572         if (NetSession)
00573         {
00574                 NetSession = GE_FALSE;
00575         
00576                 if (WeAreTheServer)             // If we are the server, then free the server player
00577                 {
00578                         if (!NetPlayDestroyPlayer(ServerId))
00579                                 return GE_FALSE;
00580                 }
00581 
00582                 if (!NetPlayDestroyPlayer(OurPlayerId))
00583                         return GE_FALSE;
00584 
00585                 if (!DeInitNetPlay())
00586                 {
00587                         //AFX_CPrintf("AFX_DestroyNetSession: There was a problem while De-Intializing NetPlay.\n");
00588                         return GE_FALSE;
00589                 }
00590 
00591         }
00592 
00593         WeAreTheServer = GE_FALSE;
00594         return GE_TRUE;
00595 }

GENESISAPI geBoolean GENESISCC geCSNetMgr_WeAreTheServer geCSNetMgr M  ) 
 

Definition at line 432 of file CSNetMgr.c.

00433 {
00434         assert( geCSNetMgr_IsValid(M)!=GE_FALSE );
00435         return (WeAreTheServer);
00436 }


Generated on Tue Sep 30 12:37:14 2003 for GTestAndEngine by doxygen 1.3.2