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>
|
#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;
|
WSADATA* _wsaData = NULL;
|
||||||
|
#endif
|
||||||
|
|
||||||
SOCKET _socket = NULL;
|
SOCKET _socket = NULL;
|
||||||
|
|
||||||
sockaddr_in* _sin = NULL;
|
sockaddr_in* _sin = NULL;
|
||||||
|
@ -42,6 +61,7 @@ extern CTString ga_strServer = "master1.croteam.org";
|
||||||
void _uninitWinsock();
|
void _uninitWinsock();
|
||||||
void _initializeWinsock(void)
|
void _initializeWinsock(void)
|
||||||
{
|
{
|
||||||
|
#ifdef PLATFORM_WIN32
|
||||||
if(_wsaData != NULL && _socket != NULL) {
|
if(_wsaData != NULL && _socket != NULL) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -61,6 +81,7 @@ void _initializeWinsock(void)
|
||||||
_uninitWinsock();
|
_uninitWinsock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// get the host IP
|
// get the host IP
|
||||||
hostent* phe = gethostbyname(ga_strServer);
|
hostent* phe = gethostbyname(ga_strServer);
|
||||||
|
@ -95,20 +116,37 @@ void _initializeWinsock(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the socket to be nonblocking
|
// set the socket to be nonblocking
|
||||||
|
#ifdef PLATFORM_WIN32
|
||||||
DWORD dwNonBlocking = 1;
|
DWORD dwNonBlocking = 1;
|
||||||
if(ioctlsocket(_socket, FIONBIO, &dwNonBlocking) != 0) {
|
if(ioctlsocket(_socket, FIONBIO, &dwNonBlocking) != 0) {
|
||||||
CPrintF("Error setting socket to nonblocking!\n");
|
CPrintF("Error setting socket to nonblocking!\n");
|
||||||
_uninitWinsock();
|
_uninitWinsock();
|
||||||
return;
|
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()
|
void _uninitWinsock()
|
||||||
{
|
{
|
||||||
if(_wsaData != NULL) {
|
if(_wsaData != NULL) {
|
||||||
closesocket(_socket);
|
closesocket(_socket);
|
||||||
|
#ifdef PLATFORM_WIN32
|
||||||
delete _wsaData;
|
delete _wsaData;
|
||||||
_wsaData = NULL;
|
_wsaData = NULL;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
_socket = NULL;
|
_socket = NULL;
|
||||||
}
|
}
|
||||||
|
@ -329,6 +367,8 @@ extern void GameAgent_EnumUpdate(void)
|
||||||
switch(_szBuffer[0]) {
|
switch(_szBuffer[0]) {
|
||||||
case 's':
|
case 's':
|
||||||
{
|
{
|
||||||
|
// !!! FIXME: serialize this and byteswap it. --ryan.
|
||||||
|
#pragma pack(1)
|
||||||
struct sIPPort {
|
struct sIPPort {
|
||||||
UBYTE bFirst;
|
UBYTE bFirst;
|
||||||
UBYTE bSecond;
|
UBYTE bSecond;
|
||||||
|
@ -336,6 +376,8 @@ extern void GameAgent_EnumUpdate(void)
|
||||||
UBYTE bFourth;
|
UBYTE bFourth;
|
||||||
USHORT iPort;
|
USHORT iPort;
|
||||||
};
|
};
|
||||||
|
#pragma pack()
|
||||||
|
|
||||||
sIPPort* pServers = (sIPPort*)(_szBuffer + 1);
|
sIPPort* pServers = (sIPPort*)(_szBuffer + 1);
|
||||||
while(iLen - ((CHAR*)pServers - _szBuffer) >= sizeof(sIPPort)) {
|
while(iLen - ((CHAR*)pServers - _szBuffer) >= sizeof(sIPPort)) {
|
||||||
sIPPort ip = *pServers;
|
sIPPort ip = *pServers;
|
||||||
|
|
|
@ -274,12 +274,9 @@ ENGINEGRAPHICSSRCS := Engine/Graphics/Adapter.cpp \
|
||||||
ENGINENETWORKSRCS := Engine/Network/ActionBuffer.cpp \
|
ENGINENETWORKSRCS := Engine/Network/ActionBuffer.cpp \
|
||||||
Engine/Network/NetworkMessage.cpp \
|
Engine/Network/NetworkMessage.cpp \
|
||||||
Engine/Network/Server.cpp \
|
Engine/Network/Server.cpp \
|
||||||
Engine/Network/GameSpy.cpp \
|
|
||||||
Engine/Network/Buffer.cpp \
|
Engine/Network/Buffer.cpp \
|
||||||
Engine/Network/NetworkProfile.cpp \
|
Engine/Network/NetworkProfile.cpp \
|
||||||
Engine/Network/GameSpyEnum.cpp \
|
|
||||||
Engine/Network/SessionState.cpp \
|
Engine/Network/SessionState.cpp \
|
||||||
Engine/Network/GameSpyKeys.cpp \
|
|
||||||
Engine/Network/PlayerBuffer.cpp \
|
Engine/Network/PlayerBuffer.cpp \
|
||||||
Engine/Network/MessageDispatcher.cpp \
|
Engine/Network/MessageDispatcher.cpp \
|
||||||
Engine/Network/PlayerSource.cpp \
|
Engine/Network/PlayerSource.cpp \
|
||||||
|
@ -291,13 +288,7 @@ ENGINENETWORKSRCS := Engine/Network/ActionBuffer.cpp \
|
||||||
Engine/Network/CommunicationInterface.cpp \
|
Engine/Network/CommunicationInterface.cpp \
|
||||||
Engine/Network/Diff.cpp
|
Engine/Network/Diff.cpp
|
||||||
|
|
||||||
|
ENGINEGAMEAGENTSRCS := Engine/GameAgent/GameAgent.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
|
|
||||||
|
|
||||||
ENGINETERRAINSRCS := Engine/Terrain/ArrayHolder.cpp \
|
ENGINETERRAINSRCS := Engine/Terrain/ArrayHolder.cpp \
|
||||||
Engine/Terrain/Terrain.cpp \
|
Engine/Terrain/Terrain.cpp \
|
||||||
|
@ -309,10 +300,6 @@ ENGINETERRAINSRCS := Engine/Terrain/ArrayHolder.cpp \
|
||||||
Engine/Terrain/TerrainRender.cpp \
|
Engine/Terrain/TerrainRender.cpp \
|
||||||
Engine/Terrain/TerrainTile.cpp
|
Engine/Terrain/TerrainTile.cpp
|
||||||
|
|
||||||
|
|
||||||
# this code is included in Engine/gamespy/gqueryreporting, too...
|
|
||||||
#ENGINEGAMESPYSRCS += Engine/gamespy/gutil.c
|
|
||||||
|
|
||||||
ENGINERENDERINGSRCS := Engine/Rendering/Render.cpp \
|
ENGINERENDERINGSRCS := Engine/Rendering/Render.cpp \
|
||||||
Engine/Rendering/RenderProfile.cpp \
|
Engine/Rendering/RenderProfile.cpp \
|
||||||
Engine/Rendering/SelectOnRender.cpp
|
Engine/Rendering/SelectOnRender.cpp
|
||||||
|
@ -390,7 +377,7 @@ ENGINESRCS := Engine/Engine.cpp \
|
||||||
$(ENGINESOUNDSRCS) \
|
$(ENGINESOUNDSRCS) \
|
||||||
$(ENGINETEMPLATESSRCS) \
|
$(ENGINETEMPLATESSRCS) \
|
||||||
$(ENGINEWORLDSRCS) \
|
$(ENGINEWORLDSRCS) \
|
||||||
$(ENGINEGAMESPYSRCS) \
|
$(ENGINEGAMEAGENTSRCS) \
|
||||||
$(ENGINEZLIBSRCS)
|
$(ENGINEZLIBSRCS)
|
||||||
|
|
||||||
OBJS1 := $(ENGINESRCS:.c=.o)
|
OBJS1 := $(ENGINESRCS:.c=.o)
|
||||||
|
@ -844,7 +831,7 @@ $(BINDIR) :
|
||||||
mkdir -p $(BINDIR)/Engine/Templates
|
mkdir -p $(BINDIR)/Engine/Templates
|
||||||
mkdir -p $(BINDIR)/Engine/World
|
mkdir -p $(BINDIR)/Engine/World
|
||||||
mkdir -p $(BINDIR)/Engine/Terrain
|
mkdir -p $(BINDIR)/Engine/Terrain
|
||||||
mkdir -p $(BINDIR)/Engine/gamespy
|
mkdir -p $(BINDIR)/Engine/GameAgent
|
||||||
mkdir -p $(BINDIR)/Engine/zlib
|
mkdir -p $(BINDIR)/Engine/zlib
|
||||||
mkdir -p $(BINDIR)/DedicatedServer
|
mkdir -p $(BINDIR)/DedicatedServer
|
||||||
mkdir -p $(BINDIR)/Entities
|
mkdir -p $(BINDIR)/Entities
|
||||||
|
|
Loading…
Reference in New Issue
Block a user