Added Socket typedef

This commit is contained in:
jsalmon3 2003-09-30 01:53:03 +00:00
parent 7d4a583f6b
commit 0ea35f4c13
14 changed files with 134 additions and 129 deletions

View file

@ -308,7 +308,7 @@ global void CreateGame(char* filename, WorldMap* map)
SyncHash = 0;
InitSyncRand();
if (NetworkFildes != -1) { // Prepare network play
if (NetworkFildes != (Socket)-1) { // Prepare network play
DebugLevel0Fn("Client setup: Calling InitNetwork2\n");
InitNetwork2();
} else {
@ -414,16 +414,14 @@ global void CreateGame(char* filename, WorldMap* map)
LoadUnitTypes();
LoadDecorations();
IfDebug(
DebugLevel0("Graphics uses %d bytes (%d KB, %d MB)\n"
_C_ AllocatedGraphicMemory
_C_ AllocatedGraphicMemory / 1024
_C_ AllocatedGraphicMemory / 1024 / 1024);
DebugLevel0("Compressed graphics uses %d bytes (%d KB, %d MB)\n"
_C_ CompressedGraphicMemory
_C_ CompressedGraphicMemory / 1024
_C_ CompressedGraphicMemory / 1024 / 1024);
);
DebugLevel0("Graphics uses %d bytes (%d KB, %d MB)\n" _C_
AllocatedGraphicMemory _C_
AllocatedGraphicMemory / 1024 _C_
AllocatedGraphicMemory / 1024 / 1024);
DebugLevel0("Compressed graphics uses %d bytes (%d KB, %d MB)\n" _C_
CompressedGraphicMemory _C_
CompressedGraphicMemory / 1024 _C_
CompressedGraphicMemory / 1024 / 1024);
CreateMinimap(); // create minimap for pud
InitMap(); // setup draw functions
@ -442,16 +440,14 @@ global void CreateGame(char* filename, WorldMap* map)
MapUnitSounds();
#ifdef WITH_SOUND
IfDebug(
DebugLevel0("Sounds uses %d bytes (%d KB, %d MB)\n"
_C_ AllocatedSoundMemory
_C_ AllocatedSoundMemory / 1024
_C_ AllocatedSoundMemory / 1024 / 1024);
DebugLevel0("Compressed sounds uses %d bytes (%d KB, %d MB)\n"
_C_ CompressedSoundMemory
_C_ CompressedSoundMemory / 1024
_C_ CompressedSoundMemory / 1024 / 1024);
);
DebugLevel0("Sounds uses %d bytes (%d KB, %d MB)\n" _C_
AllocatedSoundMemory _C_
AllocatedSoundMemory / 1024 _C_
AllocatedSoundMemory / 1024 / 1024);
DebugLevel0("Compressed sounds uses %d bytes (%d KB, %d MB)\n" _C_
CompressedSoundMemory _C_
CompressedSoundMemory / 1024 _C_
CompressedSoundMemory / 1024 / 1024);
#endif
//

View file

@ -116,6 +116,12 @@ typedef struct _OLD_INTERFACE_INFO
(int)(((ad) >> 24) & 0xff), (int)(((ad) >> 16) & 0xff), \
(int)(((ad) >> 8) & 0xff), (int)((ad) & 0xff)
#ifdef USE_WIN32
typedef SOCKET Socket;
#else
typedef int Socket;
#endif
/*----------------------------------------------------------------------------
-- Declarations
----------------------------------------------------------------------------*/
@ -140,34 +146,34 @@ extern void NetExit(void);
/// Resolve host in name or or colon dot notation.
extern unsigned long NetResolveHost(const char* host);
/// Get local IP from network file descriptor
extern int NetSocketAddr(const int sock);
extern int NetSocketAddr(const Socket sock);
/// Open a UDP Socket port.
extern int NetOpenUDP(int port);
extern Socket NetOpenUDP(int port);
/// Open a TCP Socket port.
extern int NetOpenTCP(int port);
extern Socket NetOpenTCP(int port);
/// Close a UDP socket port.
extern void NetCloseUDP(int sockfd);
extern void NetCloseUDP(Socket sockfd);
/// Close a TCP socket port.
extern void NetCloseTCP(int sockfd);
extern void NetCloseTCP(Socket sockfd);
/// Set socket to non-blocking
extern int NetSetNonBlocking(int sockfd);
extern int NetSetNonBlocking(Socket sockfd);
/// Open a TCP connection.
extern int NetConnectTCP(int sockfd,unsigned long addr,int port);
extern int NetConnectTCP(Socket sockfd,unsigned long addr,int port);
/// Send through a UPD socket to a host:port.
extern int NetSendUDP(int sockfd,unsigned long host,int port
extern int NetSendUDP(Socket sockfd,unsigned long host,int port
,const void* buf,int len);
/// Send through a TCP socket
extern int NetSendTCP(int sockfd,const void* buf,int len);
extern int NetSendTCP(Socket sockfd,const void* buf,int len);
/// Wait for socket ready.
extern int NetSocketReady(int sockfd,int timeout);
extern int NetSocketReady(Socket sockfd,int timeout);
/// Receive from a UDP socket.
extern int NetRecvUDP(int sockfd,void* buf,int len);
extern int NetRecvUDP(Socket sockfd,void* buf,int len);
/// Receive from a TCP socket.
extern int NetRecvTCP(int sockfd,void* buf,int len);
extern int NetRecvTCP(Socket sockfd,void* buf,int len);
/// Listen for connections on a TCP socket
extern int NetListenTCP(int sockfd);
extern int NetListenTCP(Socket sockfd);
/// Accept a connection on a TCP socket
extern int NetAcceptTCP(int sockfd);
extern Socket NetAcceptTCP(Socket sockfd);
//@}

View file

@ -40,6 +40,7 @@
#include "unittype.h"
#include "unit.h"
#include "upgrade.h"
#include "net_lowlevel.h"
/*----------------------------------------------------------------------------
-- Defines
@ -165,7 +166,7 @@ typedef struct _network_packet_ {
----------------------------------------------------------------------------*/
extern int NetworkNumInterfaces; /// Network number of interfaces
extern int NetworkFildes; /// Network file descriptor
extern Socket NetworkFildes; /// Network file descriptor
extern int NetworkInSync; /// Network is in sync
extern int NetworkUpdates; /// Network update each # game cycles
extern int NetworkLag; /// Network lag (# game cycles)

View file

@ -146,7 +146,7 @@ global void CommandLog(const char* name,const Unit* unit,int flag,
fprintf(LogFile," 'comment\t\"Generated by Stratagus Version " VERSION "\"\n");
fprintf(LogFile," 'comment\t\"Visit http://Stratagus.Org for more information\"\n");
fprintf(LogFile," 'comment\t\"$Id$\"\n");
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
fprintf(LogFile," 'type\t\"%s\"\n","single-player");
fprintf(LogFile," 'race\t%d\n",GameSettings.Presets[0].Race);
} else {
@ -692,7 +692,7 @@ global void MultiPlayerReplayEachCycle(void)
*/
global void SendCommandStopUnit(Unit* unit)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("stop",unit,FlushCommands,-1,-1,NoUnitP,NULL,-1);
CommandStopUnit(unit);
} else {
@ -708,7 +708,7 @@ global void SendCommandStopUnit(Unit* unit)
*/
global void SendCommandStandGround(Unit* unit,int flush)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("stand-ground",unit,flush,-1,-1,NoUnitP,NULL,-1);
CommandStandGround(unit,flush);
} else {
@ -725,7 +725,7 @@ global void SendCommandStandGround(Unit* unit,int flush)
*/
global void SendCommandFollow(Unit* unit,Unit* dest,int flush)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("follow",unit,flush,-1,-1,dest,NULL,-1);
CommandFollow(unit,dest,flush);
} else {
@ -743,7 +743,7 @@ global void SendCommandFollow(Unit* unit,Unit* dest,int flush)
*/
global void SendCommandMove(Unit* unit,int x,int y,int flush)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("move",unit,flush,x,y,NoUnitP,NULL,-1);
CommandMove(unit,x,y,flush);
} else {
@ -762,7 +762,7 @@ global void SendCommandMove(Unit* unit,int x,int y,int flush)
*/
global void SendCommandRepair(Unit* unit,int x,int y,Unit* dest,int flush)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("repair",unit,flush,x,y,dest,NULL,-1);
CommandRepair(unit,x,y,dest,flush);
} else {
@ -781,7 +781,7 @@ global void SendCommandRepair(Unit* unit,int x,int y,Unit* dest,int flush)
*/
global void SendCommandAttack(Unit* unit,int x,int y,Unit* attack,int flush)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("attack",unit,flush,x,y,attack,NULL,-1);
CommandAttack(unit,x,y,attack,flush);
} else {
@ -799,7 +799,7 @@ global void SendCommandAttack(Unit* unit,int x,int y,Unit* attack,int flush)
*/
global void SendCommandAttackGround(Unit* unit,int x,int y,int flush)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("attack-ground",unit,flush,x,y,NoUnitP,NULL,-1);
CommandAttackGround(unit,x,y,flush);
} else {
@ -817,7 +817,7 @@ global void SendCommandAttackGround(Unit* unit,int x,int y,int flush)
*/
global void SendCommandPatrol(Unit* unit,int x,int y,int flush)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("patrol",unit,flush,x,y,NoUnitP,NULL,-1);
CommandPatrolUnit(unit,x,y,flush);
} else {
@ -836,7 +836,7 @@ global void SendCommandPatrol(Unit* unit,int x,int y,int flush)
*/
global void SendCommandBoard(Unit* unit,int x,int y,Unit* dest,int flush)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("board",unit,flush,x,y,dest,NULL,-1);
CommandBoard(unit,dest,flush);
} else {
@ -855,7 +855,7 @@ global void SendCommandBoard(Unit* unit,int x,int y,Unit* dest,int flush)
*/
global void SendCommandUnload(Unit* unit,int x,int y,Unit* what,int flush)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("unload",unit,flush,x,y,what,NULL,-1);
CommandUnload(unit,x,y,what,flush);
} else {
@ -875,7 +875,7 @@ global void SendCommandUnload(Unit* unit,int x,int y,Unit* what,int flush)
global void SendCommandBuildBuilding(Unit* unit,int x,int y
,UnitType* what,int flush)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("build",unit,flush,x,y,NoUnitP,what->Ident,-1);
CommandBuildBuilding(unit,x,y,what,flush);
} else {
@ -892,7 +892,7 @@ global void SendCommandBuildBuilding(Unit* unit,int x,int y
global void SendCommandCancelBuilding(Unit* unit,Unit* worker)
{
// FIXME: currently unit and worker are same?
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("cancel-build",unit,FlushCommands,-1,-1,worker,NULL,-1);
CommandCancelBuilding(unit,worker);
} else {
@ -911,7 +911,7 @@ global void SendCommandCancelBuilding(Unit* unit,Unit* worker)
*/
global void SendCommandResourceLoc(Unit* unit,int x,int y,int flush)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("resource-loc",unit,flush,x,y,NoUnitP,NULL,-1);
CommandResourceLoc(unit,x,y,flush);
} else {
@ -928,7 +928,7 @@ global void SendCommandResourceLoc(Unit* unit,int x,int y,int flush)
*/
global void SendCommandResource(Unit* unit,Unit* dest,int flush)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("resource",unit,flush,-1,-1,dest,NULL,-1);
CommandResource(unit,dest,flush);
} else {
@ -945,7 +945,7 @@ global void SendCommandResource(Unit* unit,Unit* dest,int flush)
*/
global void SendCommandReturnGoods(Unit* unit,Unit* goal,int flush)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("return",unit,flush,-1,-1,goal,NULL,-1);
CommandReturnGoods(unit,goal,flush);
} else {
@ -962,7 +962,7 @@ global void SendCommandReturnGoods(Unit* unit,Unit* goal,int flush)
*/
global void SendCommandTrainUnit(Unit* unit,UnitType* what,int flush)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("train",unit,flush,-1,-1,NoUnitP,what->Ident,-1);
CommandTrainUnit(unit,what,flush);
} else {
@ -979,7 +979,7 @@ global void SendCommandTrainUnit(Unit* unit,UnitType* what,int flush)
*/
global void SendCommandCancelTraining(Unit* unit,int slot,const UnitType* type)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("cancel-train",unit,FlushCommands,-1,-1,NoUnitP,
type ? type->Ident : NULL,slot);
CommandCancelTraining(unit,slot,type);
@ -998,7 +998,7 @@ global void SendCommandCancelTraining(Unit* unit,int slot,const UnitType* type)
*/
global void SendCommandUpgradeTo(Unit* unit,UnitType* what,int flush)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("upgrade-to",unit,flush,-1,-1,NoUnitP,what->Ident,-1);
CommandUpgradeTo(unit,what,flush);
} else {
@ -1013,7 +1013,7 @@ global void SendCommandUpgradeTo(Unit* unit,UnitType* what,int flush)
*/
global void SendCommandCancelUpgradeTo(Unit* unit)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("cancel-upgrade-to",unit,FlushCommands
,-1,-1,NoUnitP,NULL,-1);
CommandCancelUpgradeTo(unit);
@ -1032,7 +1032,7 @@ global void SendCommandCancelUpgradeTo(Unit* unit)
*/
global void SendCommandResearch(Unit* unit,Upgrade* what,int flush)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("research",unit,flush,-1,-1,NoUnitP,what->Ident,-1);
CommandResearch(unit,what,flush);
} else {
@ -1048,7 +1048,7 @@ global void SendCommandResearch(Unit* unit,Upgrade* what,int flush)
*/
global void SendCommandCancelResearch(Unit* unit)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("cancel-research",unit,FlushCommands,-1,-1,NoUnitP,NULL,-1);
CommandCancelResearch(unit);
} else {
@ -1068,7 +1068,7 @@ global void SendCommandCancelResearch(Unit* unit)
*/
global void SendCommandDemolish(Unit* unit,int x,int y,Unit* attack,int flush)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("demolish",unit,flush,x,y,attack,NULL,-1);
CommandDemolish(unit,x,y,attack,flush);
} else {
@ -1089,7 +1089,7 @@ global void SendCommandDemolish(Unit* unit,int x,int y,Unit* attack,int flush)
global void SendCommandSpellCast(Unit* unit,int x,int y,Unit* dest,int spellid
,int flush)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("spell-cast",unit,flush,x,y,dest,NULL,spellid);
CommandSpellCast(unit,x,y,dest,SpellTypeById(spellid),flush);
} else {
@ -1107,7 +1107,7 @@ global void SendCommandSpellCast(Unit* unit,int x,int y,Unit* dest,int spellid
*/
global void SendCommandAutoSpellCast(Unit* unit,int spellid,int on)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
CommandLog("auto-spell-cast",unit,FlushCommands,on,-1,NoUnitP
,NULL,spellid);
CommandAutoSpellCast(unit,on?SpellTypeById(spellid):NULL);
@ -1126,7 +1126,7 @@ global void SendCommandAutoSpellCast(Unit* unit,int spellid,int on)
*/
global void SendCommandDiplomacy(int player,int state,int opponent)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
switch( state ) {
case DiplomacyNeutral:
CommandLog("diplomacy",NoUnitP,0,player,opponent,
@ -1161,7 +1161,7 @@ global void SendCommandDiplomacy(int player,int state,int opponent)
*/
global void SendCommandSharedVision(int player,int state,int opponent)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
if( state==0 ) {
CommandLog("shared-vision",NoUnitP,0,player,opponent,
NoUnitP,"0",-1);

View file

@ -161,7 +161,7 @@ global void NetExit(void)
**
** @param sockfd Socket fildes
*/
global void NetCloseUDP(int sockfd)
global void NetCloseUDP(Socket sockfd)
{
closesocket(sockfd);
}
@ -171,7 +171,7 @@ global void NetCloseUDP(int sockfd)
**
** @param sockfd Socket fildes
*/
global void NetCloseTCP(int sockfd)
global void NetCloseTCP(Socket sockfd)
{
closesocket(sockfd);
}
@ -200,7 +200,7 @@ global void NetExit(void)
**
** @param sockfd Socket fildes
*/
global void NetCloseUDP(int sockfd)
global void NetCloseUDP(Socket sockfd)
{
close(sockfd);
}
@ -210,7 +210,7 @@ global void NetCloseUDP(int sockfd)
**
** @param sockfd Socket fildes
*/
global void NetCloseTCP(int sockfd)
global void NetCloseTCP(Socket sockfd)
{
close(sockfd);
}
@ -225,7 +225,7 @@ global void NetCloseTCP(int sockfd)
** @return 0 for success, -1 for error
*/
#ifdef USE_WINSOCK
global int NetSetNonBlocking(int sockfd)
global int NetSetNonBlocking(Socket sockfd)
{
unsigned long opt;
@ -233,7 +233,7 @@ global int NetSetNonBlocking(int sockfd)
return ioctlsocket(sockfd,FIONBIO,&opt);
}
#else
global int NetSetNonBlocking(int sockfd)
global int NetSetNonBlocking(Socket sockfd)
{
int flags;
@ -282,7 +282,7 @@ global unsigned long NetResolveHost(const char* host)
// I also found a way for winsock1.1 (= win95), but
// that one was too complex to start with.. -> trouble
// Lookout for INTRFC.EXE on the MS web site...
global int NetSocketAddr(const int sock)
global int NetSocketAddr(const Socket sock)
{
INTERFACE_INFO localAddr[MAX_LOC_IP]; // Assume there will be no more than MAX_LOC_IP interfaces
DWORD bytesReturned;
@ -292,7 +292,7 @@ global int NetSocketAddr(const int sock)
int numLocalAddr;
nif = 0;
if (sock != -1) {
if (sock != (Socket)-1) {
wsError = WSAIoctl(sock, SIO_GET_INTERFACE_LIST, NULL, 0, &localAddr,
sizeof(localAddr), &bytesReturned, NULL, NULL);
if (wsError == SOCKET_ERROR) {
@ -323,7 +323,7 @@ global int NetSocketAddr(const int sock)
// ARI: I knew how to write this for a unix environment,
// but am quite certain that porting this can cause you
// trouble..
global int NetSocketAddr(const int sock)
global int NetSocketAddr(const Socket sock)
{
char buf[4096], *cp, *cplim;
struct ifconf ifc;
@ -332,7 +332,7 @@ global int NetSocketAddr(const int sock)
int i, nif;
nif = 0;
if (sock != -1) {
if (sock != (Socket)-1) {
ifc.ifc_len = sizeof(buf);
ifc.ifc_buf = buf;
if (ioctl(sock, SIOCGIFCONF, (char *)&ifc) < 0) {
@ -400,7 +400,7 @@ global int NetSocketAddr(const int sock)
}
#else // } !unix
// Beos?? Mac??
global int NetSocketAddr(const int sock)
global int NetSocketAddr(const Socket sock)
{
NetLocalAddrs[0] = htonl(0x7f000001);
return 1;
@ -415,9 +415,9 @@ global int NetSocketAddr(const int sock)
**
** @return If success the socket fildes, -1 otherwise.
*/
global int NetOpenUDP(int port)
global Socket NetOpenUDP(int port)
{
int sockfd;
Socket sockfd;
// open the socket
sockfd=socket(AF_INET, SOCK_DGRAM, 0);
@ -453,14 +453,14 @@ global int NetOpenUDP(int port)
**
** @return If success the socket fildes, -1 otherwise
*/
global int NetOpenTCP(int port)
global Socket NetOpenTCP(int port)
{
int sockfd;
Socket sockfd;
sockfd=socket(AF_INET, SOCK_STREAM, 0);
DebugLevel3Fn(" socket %d\n" _C_ sockfd);
if( sockfd==INVALID_SOCKET ) {
return -1;
return (Socket)-1;
}
// bind local port
if( port ) {
@ -478,7 +478,7 @@ global int NetOpenTCP(int port)
if( bind(sockfd,(struct sockaddr*)&sock_addr,sizeof(sock_addr))<0 ) {
fprintf(stderr,"Couldn't bind to local port\n");
NetCloseTCP(sockfd);
return -1;
return (Socket)-1;
}
DebugLevel3Fn(" bind ok\n");
NetLastHost=sock_addr.sin_addr.s_addr;
@ -497,7 +497,7 @@ global int NetOpenTCP(int port)
**
** @return 0 if success, -1 if failure
*/
global int NetConnectTCP(int sockfd,unsigned long addr,int port)
global int NetConnectTCP(Socket sockfd,unsigned long addr,int port)
{
struct sockaddr_in sa;
#ifndef __BEOS__
@ -535,7 +535,7 @@ global int NetConnectTCP(int sockfd,unsigned long addr,int port)
**
** @return 1 if data is available, 0 if not, -1 if failure.
*/
global int NetSocketReady(int sockfd,int timeout)
global int NetSocketReady(Socket sockfd,int timeout)
{
int retval;
struct timeval tv;
@ -591,7 +591,7 @@ global int NetSocketReady(int sockfd,int timeout)
**
** @return Number of bytes placed in buffer, or -1 if failure.
*/
global int NetRecvUDP(int sockfd,void* buf,int len)
global int NetRecvUDP(Socket sockfd,void* buf,int len)
{
int n;
int l;
@ -624,7 +624,7 @@ global int NetRecvUDP(int sockfd,void* buf,int len)
**
** @return Number of bytes placed in buffer or -1 if failure.
*/
global int NetRecvTCP(int sockfd,void* buf,int len)
global int NetRecvTCP(Socket sockfd,void* buf,int len)
{
NetLastSocket=sockfd;
return recv(sockfd,buf,len,0);
@ -641,7 +641,7 @@ global int NetRecvTCP(int sockfd,void* buf,int len)
**
** @return Number of bytes sent.
*/
global int NetSendUDP(int sockfd,unsigned long host,int port
global int NetSendUDP(Socket sockfd,unsigned long host,int port
,const void* buf,int len)
{
int n;
@ -666,7 +666,7 @@ global int NetSendUDP(int sockfd,unsigned long host,int port
**
** @return Number of bytes sent.
*/
global int NetSendTCP(int sockfd,const void* buf,int len)
global int NetSendTCP(Socket sockfd,const void* buf,int len)
{
return send(sockfd,buf,len,0);
}
@ -678,7 +678,7 @@ global int NetSendTCP(int sockfd,const void* buf,int len)
**
** @return 0 for success, -1 for error
*/
global int NetListenTCP(int sockfd)
global int NetListenTCP(Socket sockfd)
{
return listen(sockfd,PlayerMax);
}
@ -690,7 +690,7 @@ global int NetListenTCP(int sockfd)
**
** @return If success the new socket fildes, -1 otherwise.
*/
global int NetAcceptTCP(int sockfd)
global Socket NetAcceptTCP(Socket sockfd)
{
struct sockaddr_in sa;
int len;

View file

@ -272,7 +272,7 @@ typedef struct _network_command_queue_ {
//----------------------------------------------------------------------------
global int NetworkNumInterfaces; /// Network number of interfaces
global int NetworkFildes = -1; /// Network file descriptor
global Socket NetworkFildes = -1; /// Network file descriptor
global int NetworkInSync = 1; /// Network is in sync
global int NetworkUpdates = 5; /// Network update each # game cycles
global int NetworkLag = 10; /// Network lag in # game cycles
@ -432,7 +432,7 @@ global void InitNetwork1(void)
port = NetworkPort;
for (i = 0; i < 10; ++i) {
NetworkFildes = NetOpenUDP(port + i);
if (NetworkFildes != -1) {
if (NetworkFildes != (Socket)-1) {
break;
}
if (i == 9) {
@ -483,7 +483,7 @@ global void InitNetwork1(void)
*/
global void ExitNetwork1(void)
{
if (NetworkFildes == -1) { // No network running
if (NetworkFildes == (Socket)-1) { // No network running
return;
}
#ifdef DEBUG
@ -665,7 +665,7 @@ global void NetworkEvent(void)
int i;
unsigned long n;
if (NetworkFildes == -1) {
if (NetworkFildes == (Socket)-1) {
NetworkInSync = 1;
return;
}
@ -882,7 +882,7 @@ global void NetworkChatMessage(const char *msg)
const char *cp;
int n;
if (NetworkFildes != -1) {
if (NetworkFildes != (Socket)-1) {
cp = msg;
n = strlen(msg);
while (n >= (int)sizeof(ncm->Text)) {
@ -1152,7 +1152,7 @@ local void NetworkSyncCommands(void)
*/
global void NetworkCommands(void)
{
if (NetworkFildes != -1) {
if (NetworkFildes != (Socket)-1) {
//
// Send messages to all clients (other players)
//

View file

@ -272,7 +272,7 @@ local void DrawMenuButtonArea(void)
TheUI.MenuButtonGraphic.Graphic->Height,
TheUI.MenuButtonGraphicX, TheUI.MenuButtonGraphicY);
}
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
if( TheUI.MenuButton.X!=-1 ) {
DrawMenuButton(TheUI.MenuButton.Button,
(ButtonAreaUnderCursor==ButtonAreaMenu
@ -656,7 +656,7 @@ global void UpdateDisplay(void)
}
}
if(MustRedraw&RedrawMenuButton ) {
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
if( TheUI.MenuButton.X!=-1 ) {
InvalidateAreaAndCheckCursor(
TheUI.MenuButton.X,TheUI.MenuButton.Y,
@ -778,7 +778,7 @@ global void GameMainLoop(void)
showtip=0;
RealVideoSyncSpeed = VideoSyncSpeed;
if( NetworkFildes==-1 ) { // Don't show them for net play
if( NetworkFildes==(Socket)-1 ) { // Don't show them for net play
showtip=ShowTips;
}

View file

@ -46,6 +46,7 @@
#if defined(_MSC_VER) && !defined(_WIN32_WCE)
#define DrawIcon WinDrawIcon
#define EndMenu WinEndMenu
#include <winsock2.h>
#include <windows.h>
#undef DrawIcon
#undef EndMenu
@ -1267,7 +1268,7 @@ global void LoadPud(const char* pud,WorldMap* map)
Players[o].Type != PlayerComputer) ) {
pawn:
if (t != WC_UnitGoldMine && t != WC_UnitOilPatch) {
if (NetworkFildes == -1
if (NetworkFildes == (Socket)-1
&& ReplayGameType != ReplayMultiPlayer
&& o == ThisPlayer->Player) {
s = GameSettings.Presets[0].Race;

View file

@ -1065,7 +1065,7 @@ global void MenuLoop(char* filename, WorldMap* map)
//
// Network part 1 (port set-up)
//
if( NetworkFildes!=-1 ) {
if( NetworkFildes!=(Socket)-1 ) {
ExitNetwork1();
}
InitNetwork1();
@ -1110,7 +1110,7 @@ global void MenuLoop(char* filename, WorldMap* map)
}
strcpy(CurrentMapPath,filename);
}
if( NetworkFildes!=-1 && NetPlayers<2 ) {
if( NetworkFildes!=(Socket)-1 && NetPlayers<2 ) {
ExitNetwork1();
}

View file

@ -162,7 +162,7 @@ global int ButtonCheckUnitsAnd(const Unit* unit, const ButtonAction* button)
global int ButtonCheckNetwork(const Unit* unit __attribute__((unused)),
const ButtonAction* button __attribute__((unused)))
{
return NetworkFildes != -1;
return NetworkFildes != (Socket)-1;
}
/**
@ -177,7 +177,7 @@ global int ButtonCheckNetwork(const Unit* unit __attribute__((unused)),
global int ButtonCheckNoNetwork(const Unit* unit __attribute__((unused)),
const ButtonAction* button __attribute__((unused)))
{
return NetworkFildes == -1;
return NetworkFildes == (Socket)-1;
}
/**

View file

@ -338,7 +338,7 @@ global void UiTogglePause(void)
*/
local void UiEnterMenu(void)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
GamePaused=1;
SetStatusLine("Game Paused");
}
@ -350,7 +350,7 @@ local void UiEnterMenu(void)
*/
local void UiEnterHelpMenu(void)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
GamePaused=1;
SetStatusLine("Game Paused");
}
@ -362,7 +362,7 @@ local void UiEnterHelpMenu(void)
*/
local void UiEnterOptionsMenu(void)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
GamePaused=1;
SetStatusLine("Game Paused");
}
@ -374,7 +374,7 @@ local void UiEnterOptionsMenu(void)
*/
local void UiEnterSoundOptionsMenu(void)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
GamePaused=1;
SetStatusLine("Game Paused");
}
@ -386,7 +386,7 @@ local void UiEnterSoundOptionsMenu(void)
*/
local void UiEnterSpeedOptionsMenu(void)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
GamePaused=1;
SetStatusLine("Game Paused");
}
@ -398,7 +398,7 @@ local void UiEnterSpeedOptionsMenu(void)
*/
local void UiEnterPreferencesOptionsMenu(void)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
GamePaused=1;
SetStatusLine("Game Paused");
}
@ -411,11 +411,11 @@ local void UiEnterPreferencesOptionsMenu(void)
local void UiEnterSaveGameMenu(void)
{
// Disable save menu in multiplayer and replays
if (NetworkFildes != -1 || ReplayGameType != ReplayNone) {
if (NetworkFildes != (Socket)-1 || ReplayGameType != ReplayNone) {
return;
}
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
GamePaused=1;
SetStatusLine("Game Paused");
}
@ -428,11 +428,11 @@ local void UiEnterSaveGameMenu(void)
local void UiEnterLoadGameMenu(void)
{
// Disable load menu in multiplayer
if (NetworkFildes != -1) {
if (NetworkFildes != (Socket)-1) {
return;
}
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
GamePaused=1;
SetStatusLine("Game Paused");
}
@ -444,7 +444,7 @@ local void UiEnterLoadGameMenu(void)
*/
local void UiExitConfirmMenu(void)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
GamePaused=1;
SetStatusLine("Game Paused");
}
@ -456,7 +456,7 @@ local void UiExitConfirmMenu(void)
*/
local void UiQuitToMenuConfirmMenu(void)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
GamePaused=1;
SetStatusLine("Game Paused");
}
@ -468,7 +468,7 @@ local void UiQuitToMenuConfirmMenu(void)
*/
local void UiRestartConfirmMenu(void)
{
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
GamePaused=1;
SetStatusLine("Game Paused");
}
@ -1121,7 +1121,7 @@ local int InputKey(int key)
CommandLog("input", NoUnitP,FlushCommands,-1,-1,NoUnitP,Input,-1);
CclCommand(Input);
}
} else if (NetworkFildes==-1) {
} else if (NetworkFildes==(Socket)-1) {
if (!GameObserve && !GamePaused) {
int ret;
ret = HandleCheats(Input);

View file

@ -1532,14 +1532,14 @@ global void LoadGameMenu(void)
local void GameMenuInit(Menuitem *mi __attribute__((unused)))
{
// Disable save menu in multiplayer and replays
if (NetworkFildes != -1 || ReplayGameType != ReplayNone) {
if (NetworkFildes != (Socket)-1 || ReplayGameType != ReplayNone) {
mi->menu->Items[1].flags |= MenuButtonDisabled;
} else {
mi->menu->Items[1].flags &= ~MenuButtonDisabled;
}
// Disable load menu in multiplayer
if (NetworkFildes != -1) {
if (NetworkFildes != (Socket)-1) {
mi->menu->Items[2].flags |= MenuButtonDisabled;
} else {
mi->menu->Items[2].flags &= ~MenuButtonDisabled;
@ -2148,7 +2148,7 @@ local void PreferencesInit(Menuitem *mi __attribute__((unused)))
}
// Not available in net games or replays
if (NetworkFildes == -1 && ReplayGameType == ReplayNone) {
if (NetworkFildes == (Socket)-1 && ReplayGameType == ReplayNone) {
menu->Items[1].flags = MI_ENABLED;
} else {
menu->Items[1].flags = MI_DISABLED;
@ -7130,7 +7130,7 @@ local void InitPlayerRaces(Menuitem *mi)
}
}
++n;
mi->d.pulldown.options = (unsigned char **)malloc(n * sizeof(char *));
mi->d.pulldown.options = (unsigned char **)malloc(n * sizeof(unsigned char *));
for (i = 0, n = 0; i < PlayerRaces.Count; ++i) {
if (PlayerRaces.Visible[i]) {
mi->d.pulldown.options[n++] = strdup(PlayerRaces.Display[i]);

View file

@ -386,7 +386,7 @@ local void HandleMouseOn(int x,int y)
//
// Handle buttons
//
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
if( TheUI.MenuButton.X!=-1 ) {
if( x>=TheUI.MenuButton.X
&& x<=TheUI.MenuButton.X+TheUI.MenuButton.Width
@ -1622,7 +1622,7 @@ global void UIHandleButtonUp(unsigned button)
&& (ButtonUnderCursor==ButtonUnderMenu
|| ButtonUnderCursor==ButtonUnderNetworkMenu) ) {
// FIXME: Not if, in input mode.
if( NetworkFildes==-1 ) {
if( NetworkFildes==(Socket)-1 ) {
GamePaused=1;
SetStatusLine("Game Paused");
}

View file

@ -622,8 +622,9 @@ global void WaitEventsOneFrame(const EventCallback* callbacks)
struct timeval tv;
fd_set rfds;
fd_set wfds;
int maxfd;
Socket maxfd;
int i;
int s;
SDL_Event event[1];
Uint32 ticks;
@ -690,7 +691,7 @@ global void WaitEventsOneFrame(const EventCallback* callbacks)
//
// Network
//
if (NetworkFildes != -1) {
if (NetworkFildes != (Socket)-1) {
if (NetworkFildes > maxfd) {
maxfd = NetworkFildes;
}
@ -710,7 +711,7 @@ global void WaitEventsOneFrame(const EventCallback* callbacks)
#endif
#if 0
maxfd = select(maxfd + 1, &rfds, &wfds, NULL,
s = select(maxfd + 1, &rfds, &wfds, NULL,
(i = SDL_PollEvent(event)) ? &tv : NULL);
#else
// QUICK HACK to fix the event/timer problem
@ -720,7 +721,7 @@ global void WaitEventsOneFrame(const EventCallback* callbacks)
// The event handling of SDL is wrong designed = polling only.
// There is hope on SDL 1.3 which will have this fixed.
maxfd = select(maxfd + 1, &rfds, &wfds, NULL, &tv);
s = select(maxfd + 1, &rfds, &wfds, NULL, &tv);
i = SDL_PollEvent(event);
#endif
@ -728,7 +729,7 @@ global void WaitEventsOneFrame(const EventCallback* callbacks)
SdlDoEvent(callbacks, event);
}
if (maxfd > 0) {
if (s > 0) {
#ifndef USE_SDLA
//
// Sound
@ -742,7 +743,7 @@ global void WaitEventsOneFrame(const EventCallback* callbacks)
//
// Network
//
if (NetworkFildes != -1 && FD_ISSET(NetworkFildes, &rfds) ) {
if (NetworkFildes != (Socket)-1 && FD_ISSET(NetworkFildes, &rfds) ) {
callbacks->NetworkEvent();
}
}
@ -750,7 +751,7 @@ global void WaitEventsOneFrame(const EventCallback* callbacks)
//
// No more input and time for frame over: return
//
if (!i && maxfd <= 0 && VideoInterrupts) {
if (!i && s <= 0 && VideoInterrupts) {
break;
}
}