mirror of
https://github.com/ptitSeb/Serious-Engine
synced 2024-11-22 10:20:26 +01:00
First attempt at porting GameAgent code.
This commit is contained in:
parent
8ea00b12d2
commit
7d118bd249
|
@ -19,9 +19,28 @@
|
|||
|
||||
#include <Engine/GameAgent/GameAgent.h>
|
||||
|
||||
#pragma comment(lib, "wsock32.lib")
|
||||
#ifdef PLATFORM_UNIX
|
||||
#include <fcntl.h>
|
||||
#include <netdb.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <errno.h>
|
||||
#define INVALID_SOCKET -1
|
||||
#define SOCKET_ERROR -1
|
||||
#define closesocket close
|
||||
typedef int SOCKET;
|
||||
typedef struct hostent HOSTENT;
|
||||
typedef struct sockaddr_in SOCKADDR_IN;
|
||||
typedef struct sockaddr SOCKADDR;
|
||||
#define WSAGetLastError() (INDEX) errno
|
||||
#endif
|
||||
|
||||
#ifdef PLATFORM_WIN32
|
||||
#pragma comment(lib, "wsock32.lib")
|
||||
WSADATA* _wsaData = NULL;
|
||||
#endif
|
||||
|
||||
SOCKET _socket = NULL;
|
||||
|
||||
sockaddr_in* _sin = NULL;
|
||||
|
@ -42,6 +61,7 @@ extern CTString ga_strServer = "master1.croteam.org";
|
|||
void _uninitWinsock();
|
||||
void _initializeWinsock(void)
|
||||
{
|
||||
#ifdef PLATFORM_WIN32
|
||||
if(_wsaData != NULL && _socket != NULL) {
|
||||
return;
|
||||
}
|
||||
|
@ -61,6 +81,7 @@ void _initializeWinsock(void)
|
|||
_uninitWinsock();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
// get the host IP
|
||||
hostent* phe = gethostbyname(ga_strServer);
|
||||
|
@ -95,20 +116,37 @@ void _initializeWinsock(void)
|
|||
}
|
||||
|
||||
// set the socket to be nonblocking
|
||||
#ifdef PLATFORM_WIN32
|
||||
DWORD dwNonBlocking = 1;
|
||||
if(ioctlsocket(_socket, FIONBIO, &dwNonBlocking) != 0) {
|
||||
CPrintF("Error setting socket to nonblocking!\n");
|
||||
_uninitWinsock();
|
||||
return;
|
||||
}
|
||||
#else
|
||||
int flags = fcntl(_socket, F_GETFL);
|
||||
int failed = flags;
|
||||
if (failed != -1) {
|
||||
flags |= O_NONBLOCK;
|
||||
failed = fcntl(_socket, F_SETFL, flags);
|
||||
}
|
||||
|
||||
if (failed == -1) {
|
||||
CPrintF("Error setting socket to nonblocking!\n");
|
||||
_uninitWinsock();
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void _uninitWinsock()
|
||||
{
|
||||
if(_wsaData != NULL) {
|
||||
closesocket(_socket);
|
||||
#ifdef PLATFORM_WIN32
|
||||
delete _wsaData;
|
||||
_wsaData = NULL;
|
||||
#endif
|
||||
}
|
||||
_socket = NULL;
|
||||
}
|
||||
|
@ -329,6 +367,8 @@ extern void GameAgent_EnumUpdate(void)
|
|||
switch(_szBuffer[0]) {
|
||||
case 's':
|
||||
{
|
||||
// !!! FIXME: serialize this and byteswap it. --ryan.
|
||||
#pragma pack(1)
|
||||
struct sIPPort {
|
||||
UBYTE bFirst;
|
||||
UBYTE bSecond;
|
||||
|
@ -336,6 +376,8 @@ extern void GameAgent_EnumUpdate(void)
|
|||
UBYTE bFourth;
|
||||
USHORT iPort;
|
||||
};
|
||||
#pragma pack()
|
||||
|
||||
sIPPort* pServers = (sIPPort*)(_szBuffer + 1);
|
||||
while(iLen - ((CHAR*)pServers - _szBuffer) >= sizeof(sIPPort)) {
|
||||
sIPPort ip = *pServers;
|
||||
|
|
|
@ -274,12 +274,9 @@ ENGINEGRAPHICSSRCS := Engine/Graphics/Adapter.cpp \
|
|||
ENGINENETWORKSRCS := Engine/Network/ActionBuffer.cpp \
|
||||
Engine/Network/NetworkMessage.cpp \
|
||||
Engine/Network/Server.cpp \
|
||||
Engine/Network/GameSpy.cpp \
|
||||
Engine/Network/Buffer.cpp \
|
||||
Engine/Network/NetworkProfile.cpp \
|
||||
Engine/Network/GameSpyEnum.cpp \
|
||||
Engine/Network/SessionState.cpp \
|
||||
Engine/Network/GameSpyKeys.cpp \
|
||||
Engine/Network/PlayerBuffer.cpp \
|
||||
Engine/Network/MessageDispatcher.cpp \
|
||||
Engine/Network/PlayerSource.cpp \
|
||||
|
@ -291,13 +288,7 @@ ENGINENETWORKSRCS := Engine/Network/ActionBuffer.cpp \
|
|||
Engine/Network/CommunicationInterface.cpp \
|
||||
Engine/Network/Diff.cpp
|
||||
|
||||
|
||||
ENGINEGAMESPYSRCS := Engine/gamespy/darray.c \
|
||||
Engine/gamespy/gqueryreporting.c \
|
||||
Engine/gamespy/gserver.c \
|
||||
Engine/gamespy/gserverlist.c \
|
||||
Engine/gamespy/hashtable.c \
|
||||
Engine/gamespy/nonport.c
|
||||
ENGINEGAMEAGENTSRCS := Engine/GameAgent/GameAgent.cpp
|
||||
|
||||
ENGINETERRAINSRCS := Engine/Terrain/ArrayHolder.cpp \
|
||||
Engine/Terrain/Terrain.cpp \
|
||||
|
@ -309,10 +300,6 @@ ENGINETERRAINSRCS := Engine/Terrain/ArrayHolder.cpp \
|
|||
Engine/Terrain/TerrainRender.cpp \
|
||||
Engine/Terrain/TerrainTile.cpp
|
||||
|
||||
|
||||
# this code is included in Engine/gamespy/gqueryreporting, too...
|
||||
#ENGINEGAMESPYSRCS += Engine/gamespy/gutil.c
|
||||
|
||||
ENGINERENDERINGSRCS := Engine/Rendering/Render.cpp \
|
||||
Engine/Rendering/RenderProfile.cpp \
|
||||
Engine/Rendering/SelectOnRender.cpp
|
||||
|
@ -390,7 +377,7 @@ ENGINESRCS := Engine/Engine.cpp \
|
|||
$(ENGINESOUNDSRCS) \
|
||||
$(ENGINETEMPLATESSRCS) \
|
||||
$(ENGINEWORLDSRCS) \
|
||||
$(ENGINEGAMESPYSRCS) \
|
||||
$(ENGINEGAMEAGENTSRCS) \
|
||||
$(ENGINEZLIBSRCS)
|
||||
|
||||
OBJS1 := $(ENGINESRCS:.c=.o)
|
||||
|
@ -844,7 +831,7 @@ $(BINDIR) :
|
|||
mkdir -p $(BINDIR)/Engine/Templates
|
||||
mkdir -p $(BINDIR)/Engine/World
|
||||
mkdir -p $(BINDIR)/Engine/Terrain
|
||||
mkdir -p $(BINDIR)/Engine/gamespy
|
||||
mkdir -p $(BINDIR)/Engine/GameAgent
|
||||
mkdir -p $(BINDIR)/Engine/zlib
|
||||
mkdir -p $(BINDIR)/DedicatedServer
|
||||
mkdir -p $(BINDIR)/Entities
|
||||
|
|
Loading…
Reference in New Issue
Block a user