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

CSNetMgr.c File Reference

#include <assert.h>
#include <Windows.H>
#include <objbase.h>
#include "CSNetMgr.h"
#include "NetPlay.h"
#include "BaseType.h"
#include "Ram.h"
#include "ErrorLog.h"
#include <InitGuid.h>

Go to the source code of this file.

Compounds

struct  geCSNetMgr

Defines

#define PACKET_HEADER_SIZE   1
#define NET_TIMEOUT   15000
#define BUFFER_SIZE   20000

Typedefs

typedef geCSNetMgr geCSNetMgr

Functions

 DEFINE_GUID (GENESIS_GUID, 0x33925241, 0x0, 0x11d0, 0x80, 0x63, 0x0, 0xa0, 0xc9, 0xa, 0xe8, 0x91)
BOOL geCSNetMgr_ProcessSystemMessage (geCSNetMgr *M, geCSNetMgr_NetID IdTo, LPDPMSG_GENERIC lpMsg, geCSNetMgr_NetMsgType *Type, geCSNetMgr_NetClient *Client)
geBoolean geCSNetMgr_IsValid (geCSNetMgr *M)
GENESISAPI geCSNetMgr *GENESISCC geCSNetMgr_Create (void)
GENESISAPI void GENESISCC geCSNetMgr_Destroy (geCSNetMgr **ppM)
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 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_WeAreTheServer (geCSNetMgr *M)
GENESISAPI geBoolean GENESISCC geCSNetMgr_StartSession (geCSNetMgr *M, const char *SessionName, const char *PlayerName)
GENESISAPI geBoolean GENESISCC geCSNetMgr_FindSession (geCSNetMgr *M, const char *IPAdress, geCSNetMgr_NetSession **SessionList, int32 *SessionNum)
GENESISAPI geBoolean GENESISCC geCSNetMgr_JoinSession (geCSNetMgr *M, const char *Name, const geCSNetMgr_NetSession *Session)
GENESISAPI geBoolean GENESISCC geCSNetMgr_StopSession (geCSNetMgr *M)
GENESISAPI geBoolean GENESISCC geCSNetMgr_SendToServer (geCSNetMgr *M, BOOL Guaranteed, uint8 *Data, int32 DataSize)
GENESISAPI geBoolean GENESISCC geCSNetMgr_SendToClient (geCSNetMgr *M, geCSNetMgr_NetID To, BOOL Guaranteed, uint8 *Data, int32 DataSize)

Variables

geBoolean NetSession = GE_FALSE
geBoolean WeAreTheServer = GE_FALSE
DPID OurPlayerId
DPID ServerId
uint8 Packet [BUFFER_SIZE]
geCSNetMgr_NetClient gClient


Define Documentation

#define BUFFER_SIZE   20000
 

Definition at line 55 of file CSNetMgr.c.

Referenced by geCSNetMgr_JoinSession(), geCSNetMgr_ProcessSystemMessage(), geCSNetMgr_ReceiveAllMessages(), geCSNetMgr_ReceiveFromClient(), geCSNetMgr_ReceiveFromServer(), geCSNetMgr_ReceiveSystemMessage(), geCSNetMgr_SendToClient(), and geCSNetMgr_SendToServer().

#define NET_TIMEOUT   15000
 

Definition at line 41 of file CSNetMgr.c.

Referenced by geCSNetMgr_JoinSession().

#define PACKET_HEADER_SIZE   1
 

Definition at line 39 of file CSNetMgr.c.

Referenced by geCSNetMgr_ProcessSystemMessage(), geCSNetMgr_ReceiveAllMessages(), geCSNetMgr_ReceiveFromClient(), geCSNetMgr_ReceiveFromServer(), geCSNetMgr_SendToClient(), and geCSNetMgr_SendToServer().


Typedef Documentation

typedef struct geCSNetMgr geCSNetMgr
 


Function Documentation

DEFINE_GUID GENESIS_GUID  ,
0x33925241  ,
0x0  ,
0x11d0  ,
0x80  ,
0x63  ,
0x0  ,
0xa0  ,
0xc9  ,
0xa  ,
0xe8  ,
0x91 
 

GENESISAPI geCSNetMgr* GENESISCC geCSNetMgr_Create void   ) 
 

Definition at line 82 of file CSNetMgr.c.

References GE_RAM_ALLOCATE_STRUCT, geErrorLog_Add, GENESISAPI, GENESISCC, NULL, and geCSNetMgr::Valid.

Referenced by NetMgr_Create().

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.

References GE_FALSE, geCSNetMgr_IsValid(), GENESISAPI, GENESISCC, geRam_Free, and NULL.

Referenced by NetMgr_FreeAllObjects().

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 geBoolean GENESISCC geCSNetMgr_FindSession geCSNetMgr M,
const char *  IPAdress,
geCSNetMgr_NetSession **  SessionList,
int32 SessionNum
 

Definition at line 480 of file CSNetMgr.c.

References GE_FALSE, GE_TRUE, geBoolean, geCSNetMgr_IsValid(), GENESISAPI, GENESISCC, InitNetPlay(), NetPlayEnumSession(), NetSession, and WeAreTheServer.

Referenced by NetMgr_JoinSession().

00481 {
00482         assert( geCSNetMgr_IsValid(M)!=GE_FALSE );
00483 
00484         NetSession = GE_FALSE;
00485         WeAreTheServer = GE_FALSE;
00486 
00487         if (!InitNetPlay((LPGUID)&GENESIS_GUID))
00488                 return GE_FALSE;
00489 
00490         if(!NetPlayEnumSession((char*)IPAdress, (SESSION_DESC**)SessionList, SessionNum) )
00491                 return GE_FALSE;
00492 
00493         return( GE_TRUE );
00494 }

GENESISAPI geCSNetMgr_NetID GENESISCC geCSNetMgr_GetAllPlayerID geCSNetMgr M  ) 
 

Definition at line 423 of file CSNetMgr.c.

References GE_FALSE, geCSNetMgr_IsValid(), geCSNetMgr_NetID, GENESISAPI, and GENESISCC.

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.

References GE_FALSE, geCSNetMgr_IsValid(), geCSNetMgr_NetID, GENESISAPI, GENESISCC, and OurPlayerId.

Referenced by NetMgr_GetOurID().

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.

References GE_FALSE, geCSNetMgr_IsValid(), geCSNetMgr_NetID, GENESISAPI, GENESISCC, and ServerId.

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

geBoolean geCSNetMgr_IsValid geCSNetMgr M  ) 
 

Definition at line 71 of file CSNetMgr.c.

References GE_FALSE, GE_TRUE, geBoolean, NULL, and geCSNetMgr::Valid.

Referenced by geCSNetMgr_Destroy(), geCSNetMgr_FindSession(), geCSNetMgr_GetAllPlayerID(), geCSNetMgr_GetOurID(), geCSNetMgr_GetServerID(), geCSNetMgr_JoinSession(), geCSNetMgr_ProcessSystemMessage(), geCSNetMgr_ReceiveAllMessages(), geCSNetMgr_ReceiveFromClient(), geCSNetMgr_ReceiveFromServer(), geCSNetMgr_ReceiveSystemMessage(), geCSNetMgr_SendToClient(), geCSNetMgr_SendToServer(), geCSNetMgr_StartSession(), geCSNetMgr_StopSession(), and geCSNetMgr_WeAreTheServer().

00072 {
00073         if ( M == NULL )
00074                 return GE_FALSE;
00075 
00076         if ( M->Valid != M )
00077                 return GE_FALSE;
00078 
00079         return GE_TRUE;
00080 }

GENESISAPI geBoolean GENESISCC geCSNetMgr_JoinSession geCSNetMgr M,
const char *  Name,
const geCSNetMgr_NetSession *  Session
 

Definition at line 499 of file CSNetMgr.c.

References BUFFER_SIZE, DWORD, GE_FALSE, GE_TRUE, geBoolean, geCSNetMgr_IsValid(), geErrorLog_AddString, GENESISAPI, GENESISCC, NET_MSG_SERVER_ID, NET_TIMEOUT, NetPlayCreatePlayer(), NetPlayJoinSession(), NetPlayReceive(), NetSession, NULL, OurPlayerId, Packet, ServerId, uint32, and WeAreTheServer.

Referenced by NetMgr_JoinSession().

00500 {
00501 
00502         uint32  StartTime;
00503         DWORD   BSize = BUFFER_SIZE;
00504 
00505         WeAreTheServer = GE_FALSE;
00506         NetSession = GE_FALSE;
00507 
00508         assert( geCSNetMgr_IsValid(M)!=GE_FALSE );
00509 
00510         if (!NetPlayJoinSession( (SESSION_DESC*)Session) )
00511         {
00512                 geErrorLog_AddString(-1, "geCSNetMgr_JoinSession:  NetPlayJoinSession failed.\n", NULL);
00513                 return GE_FALSE;
00514         }
00515 
00516         if (!NetPlayCreatePlayer(&OurPlayerId, (char*)Name, NULL, NULL, 0, GE_FALSE))
00517         {
00518                 geErrorLog_AddString(-1, "geCSNetMgr_JoinSession:  NetPlayCreatePlayer failed.\n", NULL);
00519                 return GE_FALSE;
00520         }
00521 
00522         //Clients must wait until they get a Server Id.
00523         //  All other System messages. are ignored, until this happens.
00524         //  The only system message that should come before this is
00525         //  Create Client message.  Since Clients don't need this message
00526         //  this should not be a problem.
00527 
00528         StartTime = timeGetTime();
00529 #if 1
00530         while( NET_TIMEOUT > (timeGetTime() -  StartTime) )
00531         {
00532                 DPID    IdFrom, IdTo;
00533                 HRESULT Result;
00534 
00535                 BSize = BUFFER_SIZE;
00536 
00537                 IdFrom = IdTo = 0;
00538 
00539                 Result = NetPlayReceive(&IdFrom, &IdTo, DPRECEIVE_ALL, &Packet, &BSize);
00540                 
00541                 if (Result == DP_OK)
00542                 {
00543                         if (BSize > 0)
00544                         {
00545                                 if( (IdFrom != DPID_SYSMSG) &&(Packet[0] == NET_MSG_SERVER_ID)  )
00546                                 {
00547                                         memcpy( &ServerId, &Packet[1], sizeof( ServerId ) );
00548                                         NetSession = GE_TRUE;
00549                                         return GE_TRUE;
00550                                 }
00551                         }
00552                 }
00553                 else if (Result != DPERR_NOMESSAGES)
00554                         return GE_FALSE;
00555         }
00556 #else
00557         NetSession = GE_TRUE;
00558         ServerId = DPID_SERVERPLAYER;
00559         return( GE_TRUE);
00560 #endif
00561 
00562         return( GE_FALSE);
00563 }       

geBoolean geCSNetMgr_ProcessSystemMessage geCSNetMgr M,
geCSNetMgr_NetID  IdTo,
LPDPMSG_GENERIC  lpMsg,
geCSNetMgr_NetMsgType Type,
geCSNetMgr_NetClient Client
[static]
 

Definition at line 265 of file CSNetMgr.c.

References BUFFER_SIZE, DWORD, GE_FALSE, GE_TRUE, geBoolean, geCSNetMgr_IsValid(), geCSNetMgr_NetClient::Id, MAX_CLIENT_NAME, geCSNetMgr_NetClient::Name, NET_MSG_CREATE_CLIENT, NET_MSG_DESTROY_CLIENT, NET_MSG_HOST, NET_MSG_NONE, NET_MSG_SERVER_ID, NET_MSG_SESSIONLOST, NetPlaySend(), Packet, PACKET_HEADER_SIZE, ServerId, and WeAreTheServer.

Referenced by geCSNetMgr_ReceiveAllMessages(), and geCSNetMgr_ReceiveSystemMessage().

00266 {
00267         DWORD dwSize;
00268 
00269         assert( geCSNetMgr_IsValid(M)!=GE_FALSE );
00270 
00271         *Type = NET_MSG_NONE;
00272 
00273         switch( lpMsg->dwType)
00274     {
00275                 case DPSYS_CREATEPLAYERORGROUP:
00276         {
00277                         if(WeAreTheServer && IdTo == ServerId)
00278             {
00279                                 LPDPMSG_CREATEPLAYERORGROUP lpAddMsg = (LPDPMSG_CREATEPLAYERORGROUP) lpMsg;
00280                                 
00281                                 // Don't broadcast the server being created...
00282                                 if( lpAddMsg->dpId == ServerId )
00283                                         return GE_TRUE;
00284 
00285                                 // Name the player, and return it as a NET_MSG_CREATE_CLIENT message
00286                                 *Type = NET_MSG_CREATE_CLIENT;
00287 
00288                                 strncpy(Client->Name, lpAddMsg->dpnName.lpszShortNameA, MAX_CLIENT_NAME);
00289                                 Client->Id = lpAddMsg->dpId;
00290                                 
00291                                 // The client is waiting for this message, so send it now.
00292                                 // It contains our ServerId, which the client needs...
00293                                 dwSize = sizeof( ServerId ) + PACKET_HEADER_SIZE;
00294 
00295                                 assert(dwSize < BUFFER_SIZE);
00296 
00297                                 Packet[0] = NET_MSG_SERVER_ID;
00298                                 memcpy( &Packet[1], &ServerId, sizeof( ServerId ) );
00299 
00300                                 // Fire it off...
00301                                 if (NetPlaySend( ServerId, Client->Id, DPSEND_GUARANTEED, (void*)&Packet, dwSize ) != DP_OK)
00302                                         return GE_FALSE;
00303             }
00304 
00305                         break;
00306         }
00307 
00308                 case DPSYS_DESTROYPLAYERORGROUP:
00309         {
00310             if (WeAreTheServer && IdTo == ServerId)
00311                         {
00312                                 LPDPMSG_DESTROYPLAYERORGROUP lpDestroyMsg = (LPDPMSG_DESTROYPLAYERORGROUP)lpMsg;
00313 
00314                                 Client->Id = lpDestroyMsg->dpId;
00315                                 *Type = NET_MSG_DESTROY_CLIENT;
00316                         }
00317                         
00318                         break;
00319         }
00320 
00321                 case DPSYS_HOST:
00322         {           
00323             WeAreTheServer = GE_TRUE;
00324                         *Type = NET_MSG_HOST;
00325                         break;
00326         }
00327 
00328                 case DPSYS_SESSIONLOST:
00329                 {
00330                         *Type = NET_MSG_SESSIONLOST;
00331                         break;
00332                 }
00333 
00334     }
00335 
00336         return GE_TRUE;
00337 }

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.

References BUFFER_SIZE, DWORD, gClient, GE_FALSE, GE_TRUE, geBoolean, geCSNetMgr_IsValid(), geCSNetMgr_ProcessSystemMessage(), GENESISAPI, GENESISCC, NET_MSG_NONE, NetPlayReceive(), NetSession, NULL, Packet, PACKET_HEADER_SIZE, ServerId, and uint8.

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.

References BUFFER_SIZE, DWORD, gClient, GE_FALSE, GE_TRUE, geBoolean, geCSNetMgr_IsValid(), geCSNetMgr_ReceiveSystemMessage(), GENESISAPI, GENESISCC, NET_MSG_NONE, NetPlayReceive(), NetSession, NULL, Packet, PACKET_HEADER_SIZE, ServerId, and uint8.

Referenced by NetMgr_ReceiveClientMessage().

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.

References BUFFER_SIZE, DWORD, gClient, GE_FALSE, GE_TRUE, geBoolean, geCSNetMgr_IsValid(), geCSNetMgr_ReceiveSystemMessage(), geErrorLog_AddString, GENESISAPI, GENESISCC, NET_MSG_NONE, NetPlayReceive(), NetSession, NULL, OurPlayerId, Packet, PACKET_HEADER_SIZE, ServerId, and uint8.

Referenced by NetMgr_ReceiveServerMessage().

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.

References BUFFER_SIZE, DWORD, GE_FALSE, GE_TRUE, geBoolean, geCSNetMgr_IsValid(), geCSNetMgr_ProcessSystemMessage(), GENESISAPI, GENESISCC, NET_MSG_NONE, NetPlayReceive(), NetSession, and Packet.

Referenced by geCSNetMgr_ReceiveFromClient(), and geCSNetMgr_ReceiveFromServer().

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,
BOOL  Guaranteed,
uint8 Data,
int32  DataSize
 

Definition at line 629 of file CSNetMgr.c.

References BUFFER_SIZE, DWORD, GE_FALSE, GE_TRUE, geBoolean, geCSNetMgr_IsValid(), GENESISAPI, GENESISCC, NET_MSG_USER, NetPlaySend(), NetSession, Packet, PACKET_HEADER_SIZE, and ServerId.

00630 {
00631     DWORD           dwFlags = 0;
00632 
00633         assert( geCSNetMgr_IsValid(M)!=GE_FALSE );
00634         assert(DataSize+PACKET_HEADER_SIZE < BUFFER_SIZE);
00635         
00636         if (!NetSession)
00637                 return GE_FALSE;
00638         
00639         if( DataSize+PACKET_HEADER_SIZE >= BUFFER_SIZE )
00640                 return GE_FALSE;
00641 
00642         if (Guaranteed)
00643                 dwFlags |= DPSEND_GUARANTEED;
00644         
00645         memcpy( &Packet[1], Data, DataSize );
00646         DataSize += PACKET_HEADER_SIZE;
00647         Packet[0] = NET_MSG_USER;
00648 
00649         if (NetPlaySend(ServerId, To, dwFlags, (void*)&Packet, DataSize) != DP_OK)
00650                 return GE_FALSE;
00651         
00652         return GE_TRUE;
00653 }

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

Definition at line 600 of file CSNetMgr.c.

References BUFFER_SIZE, DWORD, GE_FALSE, GE_TRUE, geBoolean, geCSNetMgr_IsValid(), GENESISAPI, GENESISCC, NET_MSG_USER, NetPlaySend(), NetSession, OurPlayerId, Packet, PACKET_HEADER_SIZE, and ServerId.

00601 {
00602     DWORD           dwFlags = 0;
00603 
00604         assert( geCSNetMgr_IsValid(M)!=GE_FALSE );
00605         assert(DataSize+PACKET_HEADER_SIZE < BUFFER_SIZE);
00606 
00607         if (!NetSession)
00608                 return GE_FALSE;
00609 
00610         if( DataSize+PACKET_HEADER_SIZE >= BUFFER_SIZE )
00611                 return GE_FALSE;
00612         
00613         if (Guaranteed)
00614                 dwFlags |= DPSEND_GUARANTEED;
00615 
00616         memcpy( &Packet[1], Data, DataSize );
00617         DataSize += PACKET_HEADER_SIZE;
00618         Packet[0] = NET_MSG_USER;
00619 
00620         if (NetPlaySend(OurPlayerId, ServerId, dwFlags, (void*)&Packet, DataSize) != DP_OK)
00621                 return GE_FALSE;
00622         
00623         return GE_TRUE;
00624 }

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

Definition at line 441 of file CSNetMgr.c.

References GE_FALSE, GE_TRUE, geBoolean, geCSNetMgr_IsValid(), geErrorLog_AddString, GENESISAPI, GENESISCC, InitNetPlay(), MAX_CLIENT_NAME, NetPlayCreatePlayer(), NetPlayCreateSession(), NetSession, NULL, OurPlayerId, ServerId, and WeAreTheServer.

Referenced by NetMgr_StartSession().

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.

References DeInitNetPlay(), GE_FALSE, GE_TRUE, geBoolean, geCSNetMgr_IsValid(), GENESISAPI, GENESISCC, NetPlayDestroyPlayer(), NetSession, OurPlayerId, ServerId, and WeAreTheServer.

Referenced by NetMgr_FreeAllObjects().

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.

References GE_FALSE, geBoolean, geCSNetMgr_IsValid(), GENESISAPI, GENESISCC, and WeAreTheServer.

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


Variable Documentation

geCSNetMgr_NetClient gClient [static]
 

Definition at line 60 of file CSNetMgr.c.

Referenced by geCSNetMgr_ReceiveAllMessages(), geCSNetMgr_ReceiveFromClient(), and geCSNetMgr_ReceiveFromServer().

geBoolean NetSession = GE_FALSE [static]
 

Definition at line 50 of file CSNetMgr.c.

Referenced by geCSNetMgr_FindSession(), geCSNetMgr_JoinSession(), geCSNetMgr_ReceiveAllMessages(), geCSNetMgr_ReceiveFromClient(), geCSNetMgr_ReceiveFromServer(), geCSNetMgr_ReceiveSystemMessage(), geCSNetMgr_SendToClient(), geCSNetMgr_SendToServer(), geCSNetMgr_StartSession(), and geCSNetMgr_StopSession().

DPID OurPlayerId [static]
 

Definition at line 52 of file CSNetMgr.c.

Referenced by geCSNetMgr_GetOurID(), geCSNetMgr_JoinSession(), geCSNetMgr_ReceiveFromServer(), geCSNetMgr_SendToServer(), geCSNetMgr_StartSession(), and geCSNetMgr_StopSession().

uint8 Packet[BUFFER_SIZE] [static]
 

Definition at line 58 of file CSNetMgr.c.

Referenced by geCSNetMgr_JoinSession(), geCSNetMgr_ProcessSystemMessage(), geCSNetMgr_ReceiveAllMessages(), geCSNetMgr_ReceiveFromClient(), geCSNetMgr_ReceiveFromServer(), geCSNetMgr_ReceiveSystemMessage(), geCSNetMgr_SendToClient(), and geCSNetMgr_SendToServer().

DPID ServerId [static]
 

Definition at line 53 of file CSNetMgr.c.

Referenced by geCSNetMgr_GetServerID(), geCSNetMgr_JoinSession(), geCSNetMgr_ProcessSystemMessage(), geCSNetMgr_ReceiveAllMessages(), geCSNetMgr_ReceiveFromClient(), geCSNetMgr_ReceiveFromServer(), geCSNetMgr_SendToClient(), geCSNetMgr_SendToServer(), geCSNetMgr_StartSession(), and geCSNetMgr_StopSession().

geBoolean WeAreTheServer = GE_FALSE [static]
 

Definition at line 51 of file CSNetMgr.c.

Referenced by geCSNetMgr_FindSession(), geCSNetMgr_JoinSession(), geCSNetMgr_ProcessSystemMessage(), geCSNetMgr_StartSession(), geCSNetMgr_StopSession(), and geCSNetMgr_WeAreTheServer().


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