#include <Windows.h>#include <Assert.h>#include <stdio.h>#include "Genesis.h"#include "Errorlog.h"#include "Ram.h"#include "NetMgr.h"#include "Buffer.h"Go to the source code of this file.
Compounds | |
| struct | NetMgr |
Typedefs | |
| typedef NetMgr | NetMgr |
Functions | |
| NetMgr * | NetMgr_Create (geBoolean UseLocalBuffers) |
| void | NetMgr_Destroy (NetMgr *NMgr) |
| void | NetMgr_FreeAllObjects (NetMgr *NMgr) |
| geBoolean | NetMgr_IsValid (NetMgr *NMgr) |
| geBoolean | NetMgr_StartSession (NetMgr *NMgr, const char *SessionName, const char *PlayerName) |
| geBoolean | NetMgr_JoinSession (NetMgr *NMgr, const char *IPAddress, const char *PlayerName) |
| geCSNetMgr_NetID | NetMgr_GetOurID (NetMgr *NMgr) |
| geBoolean | NetMgr_SendServerMessage (NetMgr *NMgr, Buffer_Data *Buffer, geBoolean G) |
| geBoolean | NetMgr_SendClientMessage (NetMgr *NMgr, geCSNetMgr_NetID NetID, Buffer_Data *Buffer, geBoolean G) |
| geBoolean | NetMgr_ReceiveServerMessage (NetMgr *NMgr, geCSNetMgr_NetMsgType *Type, Buffer_Data *Buffer) |
| geBoolean | NetMgr_ReceiveClientMessage (NetMgr *NMgr, geCSNetMgr_NetMsgType *MsgType, geCSNetMgr_NetID *ClientID, Buffer_Data *Buffer) |
| void | NetMgr_ResetClientBuffer (NetMgr *NMgr) |
| void | NetMgr_ResetServerBuffer (NetMgr *NMgr) |
|
|
|
|
|
Definition at line 49 of file NetMgr.c. References Buffer_Set(), NetMgr::ClientBuffer, NetMgr::ClientToServerBuffer, NetMgr::CSNetMgr, GE_RAM_ALLOCATE_STRUCT, geCSNetMgr_Create(), geErrorLog_AddString, NetMgr_FreeAllObjects(), NETMGR_LOCAL_MSG_BUFFER_SIZE, NULL, NetMgr::SelfCheck1, NetMgr::SelfCheck2, NetMgr::ServerBuffer, NetMgr::ServerToClientBuffer, and NetMgr::UseLocalBuffers. Referenced by Host_Create().
00050 {
00051 NetMgr *NMgr;
00052
00053 NMgr = GE_RAM_ALLOCATE_STRUCT(NetMgr);
00054
00055 if (!NMgr)
00056 {
00057 geErrorLog_AddString(-1, "NetMgr_Create: Could not create NetMgr object.", NULL);
00058 return NULL;
00059 }
00060
00061 memset(NMgr, 0 , sizeof(NetMgr));
00062
00063 // Setup local message buffers...
00064 Buffer_Set(&NMgr->ClientToServerBuffer, NMgr->ClientBuffer, NETMGR_LOCAL_MSG_BUFFER_SIZE);
00065 Buffer_Set(&NMgr->ServerToClientBuffer, NMgr->ServerBuffer, NETMGR_LOCAL_MSG_BUFFER_SIZE);
00066
00067 NMgr->UseLocalBuffers = UseLocalBuffers;
00068
00069 if (!UseLocalBuffers)
00070 {
00071 NMgr->CSNetMgr = geCSNetMgr_Create();
00072
00073 if (!NMgr->CSNetMgr)
00074 {
00075 geErrorLog_AddString(-1,"NetMgr_Create Could not create geCSNeMgr...\n", NULL);
00076 NetMgr_FreeAllObjects(NMgr);
00077 return NULL;
00078 }
00079 }
00080
00081 NMgr->SelfCheck1 = NMgr;
00082 NMgr->SelfCheck2 = NMgr;
00083
00084 return NMgr;
00085 }
|
|
|
Definition at line 90 of file NetMgr.c. References NetMgr_FreeAllObjects(), and NetMgr_IsValid(). Referenced by Host_DestroyAllObjects().
00091 {
00092 assert(NetMgr_IsValid(NMgr));
00093
00094 NetMgr_FreeAllObjects(NMgr);
00095 }
|
|
|
Definition at line 100 of file NetMgr.c. References NetMgr::CSNetMgr, GE_FALSE, geCSNetMgr_Destroy(), geCSNetMgr_StopSession(), geRam_Free, NULL, and NetMgr::UseLocalBuffers. Referenced by NetMgr_Create(), and NetMgr_Destroy().
00101 {
00102 assert(NMgr);
00103
00104 if (NMgr->CSNetMgr)
00105 {
00106 assert(NMgr->UseLocalBuffers == GE_FALSE);
00107 geCSNetMgr_StopSession(NMgr->CSNetMgr);
00108 geCSNetMgr_Destroy(&NMgr->CSNetMgr);
00109 }
00110
00111 NMgr->CSNetMgr = NULL;
00112
00113 geRam_Free(NMgr);
00114 }
|
|
|
Definition at line 192 of file NetMgr.c. References NetMgr::CSNetMgr, geCSNetMgr_GetOurID(), geCSNetMgr_NetID, and NetMgr_IsValid(). Referenced by Host_Create().
00193 {
00194 assert(NetMgr_IsValid(NMgr));
00195
00196 return geCSNetMgr_GetOurID(NMgr->CSNetMgr);
00197 }
|
|
|
Definition at line 119 of file NetMgr.c. References GE_FALSE, GE_TRUE, geBoolean, geErrorLog_AddString, NULL, NetMgr::SelfCheck1, and NetMgr::SelfCheck2. Referenced by NetMgr_Destroy(), NetMgr_GetOurID(), NetMgr_JoinSession(), NetMgr_ReceiveServerMessage(), NetMgr_SendClientMessage(), NetMgr_SendServerMessage(), and NetMgr_StartSession().
00120 {
00121 if (!NMgr)
00122 {
00123 geErrorLog_AddString(-1, "NetMgr_IsValid: NULL NetMgr object.", NULL);
00124 return GE_FALSE;
00125 }
00126
00127 if (NMgr->SelfCheck1 != NMgr)
00128 {
00129 geErrorLog_AddString(-1, "NetMgr_IsValid: NMgr->SeflfCheck1 != NMgr", NULL);
00130 return GE_FALSE;
00131 }
00132
00133 if (NMgr->SelfCheck2 != NMgr)
00134 {
00135 geErrorLog_AddString(-1, "NetMgr_IsValid: NMgr->SelfCheck2 != NMgr", NULL);
00136 return GE_FALSE;
00137 }
00138
00139 return GE_TRUE;
00140 }
|
|
||||||||||||||||
|
Definition at line 160 of file NetMgr.c. References NetMgr::CSNetMgr, GE_FALSE, GE_TRUE, geBoolean, geCSNetMgr_FindSession(), geCSNetMgr_JoinSession(), geErrorLog_AddString, int32, NetMgr_IsValid(), NULL, and NetMgr::UseLocalBuffers. Referenced by Host_Create().
00161 {
00162 geCSNetMgr_NetSession *SessionList;
00163 int32 NumSessions;
00164
00165 assert(NetMgr_IsValid(NMgr));
00166 assert(NMgr->UseLocalBuffers == GE_FALSE);
00167
00168 if (!geCSNetMgr_FindSession(NMgr->CSNetMgr, IPAddress, &SessionList, &NumSessions))
00169 {
00170 geErrorLog_AddString(-1, "NetMgr_JoinSession: geCSNetMgr_JoinSession failed...", NULL);
00171 return GE_FALSE;
00172 }
00173
00174 if (!NumSessions)
00175 {
00176 geErrorLog_AddString(-1, "NetMgr_JoinSession: Could not find a session at address:", IPAddress);
00177 return GE_FALSE;
00178 }
00179
00180 if (!geCSNetMgr_JoinSession(NMgr->CSNetMgr, PlayerName, &SessionList[0]))
00181 {
00182 geErrorLog_AddString(-1, "NetMgr_JoinSession: Could not join a session at address:", IPAddress);
00183 return GE_FALSE;
00184 }
00185
00186 return GE_TRUE;
00187 }
|
|
||||||||||||||||||||
|
Definition at line 279 of file NetMgr.c. References NetMgr::ClientToServerBuffer, NetMgr::CSNetMgr, Buffer_Data::Data, GE_FALSE, GE_TRUE, geBoolean, geCSNetMgr_NetID, geCSNetMgr_ReceiveFromClient(), NET_MSG_NONE, NET_MSG_USER, NETMGR_SINGLE_PLAYER_NETID, Buffer_Data::Pos, Buffer_Data::Size, and NetMgr::UseLocalBuffers. Referenced by ReadClientMessages().
00280 {
00281 if (NMgr->UseLocalBuffers)
00282 {
00283 *ClientID = NETMGR_SINGLE_PLAYER_NETID;
00284 *MsgType = NET_MSG_USER;
00285
00286 Buffer->Size = NMgr->ClientToServerBuffer.Pos;
00287 Buffer->Data = NMgr->ClientToServerBuffer.Data;
00288 NMgr->ClientToServerBuffer.Pos = 0;
00289
00290 if (!Buffer->Size)
00291 *MsgType = NET_MSG_NONE;
00292 }
00293 else
00294 {
00295 geCSNetMgr_NetID ToID;
00296
00297 //if (!geCSNetMgr_ReceiveAllMessages(NMgr->CSNetMgr, ClientID, &ToID, MsgType, &Buffer->Size, &Buffer->Data))
00298 // return GE_FALSE;
00299 if (!geCSNetMgr_ReceiveFromClient(NMgr->CSNetMgr, MsgType, ClientID, &Buffer->Size, &Buffer->Data))
00300 return GE_FALSE;
00301 }
00302
00303 return GE_TRUE; // Got a message for'em
00304 }
|
|
||||||||||||||||
|
Definition at line 249 of file NetMgr.c. References NetMgr::CSNetMgr, Buffer_Data::Data, GE_FALSE, GE_TRUE, geBoolean, geCSNetMgr_ReceiveFromServer(), NET_MSG_NONE, NET_MSG_USER, NetMgr_IsValid(), Buffer_Data::Pos, NetMgr::ServerToClientBuffer, Buffer_Data::Size, and NetMgr::UseLocalBuffers. Referenced by Client_ReadServerMessages().
00250 {
00251 assert(NetMgr_IsValid(NMgr));
00252
00253 if (NMgr->UseLocalBuffers)
00254 {
00255 *Type = NET_MSG_USER;
00256
00257 // Use the short-curcuit buffers for local messages
00258 Buffer->Size = NMgr->ServerToClientBuffer.Pos;
00259 Buffer->Data = NMgr->ServerToClientBuffer.Data;
00260
00261 NMgr->ServerToClientBuffer.Pos = 0;
00262
00263 if (!Buffer->Size)
00264 *Type = NET_MSG_NONE;
00265 }
00266 else
00267 {
00268 // Use real message system if in real network mode
00269 if (!geCSNetMgr_ReceiveFromServer(NMgr->CSNetMgr, Type, &Buffer->Size, &Buffer->Data))
00270 return GE_FALSE;
00271 }
00272
00273 return GE_TRUE;
00274 }
|
|
|
Definition at line 309 of file NetMgr.c. References NetMgr::ClientToServerBuffer, and Buffer_Data::Pos. Referenced by Host_Frame().
00310 {
00311 NMgr->ClientToServerBuffer.Pos = 0;
00312 }
|
|
|
Definition at line 317 of file NetMgr.c. References Buffer_Data::Pos, and NetMgr::ServerToClientBuffer. Referenced by Host_Frame().
00318 {
00319 NMgr->ServerToClientBuffer.Pos = 0;
00320 }
|
|
||||||||||||||||||||
|
||||||||||||||||
|
Definition at line 203 of file NetMgr.c. References Buffer_FillBuffer(), NetMgr::ClientToServerBuffer, NetMgr::CSNetMgr, Buffer_Data::Data, G, GE_FALSE, GE_TRUE, geBoolean, geCSNetMgr_SendToServer(), NetMgr_IsValid(), Buffer_Data::Pos, and NetMgr::UseLocalBuffers. Referenced by Client_ChangeNetState(), and Client_SendMove().
00204 {
00205 assert(NetMgr_IsValid(NMgr));
00206
00207 if (NMgr->UseLocalBuffers)
00208 {
00209 if (!Buffer_FillBuffer(&NMgr->ClientToServerBuffer, Buffer))
00210 return GE_FALSE;
00211 }
00212 else
00213 {
00214 if (!geCSNetMgr_SendToServer(NMgr->CSNetMgr, G, Buffer->Data, Buffer->Pos))
00215 return GE_FALSE;
00216 }
00217
00218 return GE_TRUE;
00219 }
|
|
||||||||||||||||
|
Definition at line 145 of file NetMgr.c. References NetMgr::CSNetMgr, GE_FALSE, GE_TRUE, geBoolean, geCSNetMgr_StartSession(), NetMgr_IsValid(), and NetMgr::UseLocalBuffers. Referenced by Host_Create().
00146 {
00147 assert(NetMgr_IsValid(NMgr));
00148
00149 assert(NMgr->UseLocalBuffers == GE_FALSE);
00150
00151 if (!geCSNetMgr_StartSession(NMgr->CSNetMgr, SessionName, PlayerName))
00152 return GE_FALSE;
00153
00154 return GE_TRUE;
00155 }
|
1.3.2