Fix compile error at macOS (#9)

* Fix compile error at macOS
* If fixing some of the whitespace in this file with this patch, might as well go the whole way?
* > 0 to != NULL
This commit is contained in:
Rongjian Zhang 2018-06-03 15:37:39 +08:00 committed by Brad Smith
parent 458eb30f3d
commit 211c7972a9
1 changed files with 733 additions and 701 deletions

View File

@ -114,7 +114,7 @@ int LoadConfigFile(char *fn)
if(fp=fopen(fn,"rb"))
{
char buf[256];
while(fgets(buf, 256, fp) > 0)
while(fgets(buf, 256, fp) != NULL)
{
if(!strncasecmp(buf,"maxclients",strlen("maxclients")))
sscanf(buf,"%*s %d",&ServerConfig.MaxClients);
@ -140,7 +140,6 @@ int LoadConfigFile(char *fn)
}
}
}
else
{
printf("Cannot load configuration file %s.\n", fn);
@ -238,6 +237,7 @@ static int CheckNBTCPReceive(ClientEntry *client) throw(int)
{
if(!client->nbtcplen)
throw(1); /* Should not happen. */
int l;
while(l = recv(client->TCPSocket, client->nbtcp + client->nbtcphas, client->nbtcplen - client->nbtcphas, MSG_NOSIGNAL))
@ -298,10 +298,16 @@ static int CheckNBTCPReceive(ClientEntry *client) throw(int)
{
EndNBTCPReceive(client);
if(len)
{
StartNBTCPReceive(client,NBTCP_COMMAND | cmd,len);
else /* Woops. Client probably tried to send a text message of 0 length. Or maybe a 0-length cheat file? Better be safe! */
}
else
{
/* Woops. Client probably tried to send a text message of 0 length.
Or maybe a 0-length cheat file? Better be safe! */
StartNBTCPReceive(client,NBTCP_UPDATEDATA,client->localplayers);
}
}
else throw(1);
return(1);
}
@ -325,12 +331,15 @@ static int CheckNBTCPReceive(ClientEntry *client) throw(int)
free(ma);
}
else
{
SendToAll((GameEntry*)client->game, tocmd, client->nbtcp, len);
}
EndNBTCPReceive(client);
StartNBTCPReceive(client,NBTCP_UPDATEDATA,client->localplayers);
return(1);
}
case NBTCP_LOGINLEN:len = de32(client->nbtcp);
case NBTCP_LOGINLEN:
len = de32(client->nbtcp);
if(len > 1024 || len < (16 + 16 + 64 + 1))
throw(1);
EndNBTCPReceive(client);
@ -398,6 +407,7 @@ static int CheckNBTCPReceive(ClientEntry *client) throw(int)
GameEntry *tg=(GameEntry *)client->game;
for(x=0; x<tg->MaxPlayers; x++)
{
if(tg->Players[x] && tg->IsUnique[x])
{
if(tg->Players[x] != client)
@ -405,7 +415,8 @@ static int CheckNBTCPReceive(ClientEntry *client) throw(int)
try
{
TextToClient(tg->Players[x], "* Player %s has just connected as: %s",MakeMPS(client),client->nickname);
} catch(int i)
}
catch(int i)
{
KillClient(tg->Players[x]);
}
@ -415,6 +426,7 @@ static int CheckNBTCPReceive(ClientEntry *client) throw(int)
TextToClient(client, "* You(Player %s) have just connected as: %s",MakeMPS(client),client->nickname);
}
}
}
EndNBTCPReceive(client);
StartNBTCPReceive(client,NBTCP_UPDATEDATA,client->localplayers);
return(1);
@ -433,6 +445,7 @@ static char *CleanNick(char *nick)
for(x=0; x<strlen(nick); x++)
if(nick[x] == '<' || nick[x] == '>' || nick[x] == '*' || (nick[x] < 0x20))
nick[x] = 0;
if(!strlen(nick))
{
free(nick);
@ -449,8 +462,10 @@ static int NickUnique(ClientEntry *client)
for(x=0; x<game->MaxPlayers; x++)
if(game->Players[x] && client != game->Players[x])
if(!strcasecmp(client->nickname, game->Players[x]->nickname))
return(0);
return(1);
}
@ -458,6 +473,7 @@ static int MakeSendTCP(ClientEntry *client, uint8 *data, uint32 len) throw(int)
{
if(send(client->TCPSocket, data, len, MSG_NOSIGNAL) != len)
throw(1);
return(1);
}
@ -487,7 +503,6 @@ static void SendToAll(GameEntry *game, int cmd, uint8 *data, uint32 len) throw(i
{
KillClient(game->Players[x]);
}
}
}
@ -563,6 +578,7 @@ static void KillClient(ClientEntry *client)
time_t curtime = time(0);
printf("Unassigned client %d disconnected on %s",client->id, ctime(&curtime));
}
if(client->nbtcp)
free(client->nbtcp);
@ -571,6 +587,7 @@ static void KillClient(ClientEntry *client)
if(client->TCPSocket != -1)
close(client->TCPSocket);
memset(client, 0, sizeof(ClientEntry));
client->TCPSocket = -1;
@ -583,13 +600,14 @@ static void AddClientToGame(ClientEntry *client, uint8 id[16], uint8 extra[64])
int wg;
GameEntry *game,*fegame;
retry:
retry:
game = NULL;
fegame = NULL;
/* First, find an available game. */
for(wg=0; wg<ServerConfig.MaxClients; wg++)
{
if(!Games[wg].MaxPlayers && !fegame)
{
if(!fegame)
@ -600,6 +618,7 @@ static void AddClientToGame(ClientEntry *client, uint8 id[16], uint8 extra[64])
game = &Games[wg];
break;
}
}
if(!game) /* Hmm, no game found. Guess we'll have to create one. */
{
@ -611,7 +630,6 @@ static void AddClientToGame(ClientEntry *client, uint8 id[16], uint8 extra[64])
memcpy(game->ExtraInfo, extra, 64);
}
int n;
for(n = 0; n < game->MaxPlayers; n++)
if(game->Players[n])
@ -638,6 +656,7 @@ static void AddClientToGame(ClientEntry *client, uint8 id[16], uint8 extra[64])
int instancecount = client->localplayers;
for(n=0; n<game->MaxPlayers; n++)
{
if(!game->Players[n])
{
game->Players[n] = client;
@ -649,6 +668,7 @@ static void AddClientToGame(ClientEntry *client, uint8 id[16], uint8 extra[64])
if(!instancecount)
break;
}
}
/* Game is full. */
if(n == game->MaxPlayers)
@ -668,13 +688,13 @@ static void AddClientToGame(ClientEntry *client, uint8 id[16], uint8 extra[64])
int main(int argc, char *argv[])
{
struct sockaddr_in sockin;
socklen_t sockin_len;
int i;
char* pass = 0;
/* If we can't load the default config file, use some defined values */
if(!LoadConfigFile(DEFAULT_CONFIG)) {
if(!LoadConfigFile(DEFAULT_CONFIG))
{
ServerConfig.Port = DEFAULT_PORT;
ServerConfig.MaxClients = DEFAULT_MAX;
ServerConfig.ConnectTimeout = DEFAULT_TIMEOUT;
@ -682,10 +702,10 @@ int main(int argc, char *argv[])
}
char* configfile = 0;
for(i=1; i<argc ;i++)
{
if(!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h")) {
if(!strcmp(argv[i], "--help") || !strcmp(argv[i], "-h"))
{
printf("Usage: %s [OPTION]...\n" ,argv[0]);
printf("Begins the FCE Ultra game server with given options.\n");
printf("This server will first look in %s for options. If that \nfile does not exist, it will use the defaults given here. Any argument given \ndirectly will override any default values.\n\n", DEFAULT_CONFIG);
@ -700,7 +720,8 @@ int main(int argc, char *argv[])
printf("-c\t--configfile\tLoads the given configuration file.\n");
return -1;
}
if(!strcmp(argv[i], "--port") || !strcmp(argv[i], "-p")) {
if(!strcmp(argv[i], "--port") || !strcmp(argv[i], "-p"))
{
i++;
if(argc == i)
{
@ -710,9 +731,11 @@ int main(int argc, char *argv[])
ServerConfig.Port = atoi(argv[i]);
continue;
}
if(!strcmp(argv[i], "--password") || !strcmp(argv[i], "-w")) {
if(!strcmp(argv[i], "--password") || !strcmp(argv[i], "-w"))
{
i++;
if(argc == i) {
if(argc == i)
{
printf("Please specify a password.\n");
return -1;
}
@ -725,46 +748,56 @@ int main(int argc, char *argv[])
puts("Password required to log in.");
continue;
}
if(!strcmp(argv[i], "--maxclients") || !strcmp(argv[i], "-m")) {
if(!strcmp(argv[i], "--maxclients") || !strcmp(argv[i], "-m"))
{
i++;
if(argc == i) {
if(argc == i)
{
printf("Please specify the maximium ammount of clients.\n");
return -1;
}
ServerConfig.MaxClients = atoi(argv[i]);
continue;
}
if(!strcmp(argv[i], "--timeout") || !strcmp(argv[i], "-t")) {
if(!strcmp(argv[i], "--timeout") || !strcmp(argv[i], "-t"))
{
i++;
if(argc == i) {
if(argc == i)
{
printf("Please specify the conenction timeout time in seconds.\n");
return -1;
}
ServerConfig.ConnectTimeout = atoi(argv[i]);
continue;
}
if(!strcmp(argv[i], "--framedivisor") || !strcmp(argv[i], "-f")) {
if(!strcmp(argv[i], "--framedivisor") || !strcmp(argv[i], "-f"))
{
i++;
if(argc == i) {
if(argc == i)
{
printf("Please specify a framedivisor.\n");
return -1;
}
ServerConfig.FrameDivisor = atoi(argv[i]);
continue;
}
if(!strcmp(argv[i], "--configfile") || !strcmp(argv[i], "-c")) {
if(!strcmp(argv[i], "--configfile") || !strcmp(argv[i], "-c"))
{
i++;
if(argc == i) {
if(argc == i)
{
printf("Please specify a configfile to load.\n");
return -1;
}
if(!LoadConfigFile(argv[i])) {
if(!LoadConfigFile(argv[i]))
{
puts("Error loading configuration file.");
exit(-1);
}
continue;
}
if(!strcmp(argv[i], "--version") || !strcmp(argv[i], "-v")) {
if(!strcmp(argv[i], "--version") || !strcmp(argv[i], "-v"))
{
printf("FCE Ultra network server version %s\n", VERSION);
return 0;
}
@ -774,7 +807,6 @@ int main(int argc, char *argv[])
return -1;
}
Games = (GameEntry *)malloc(sizeof(GameEntry) * ServerConfig.MaxClients);
Clients = (ClientEntry *)malloc(sizeof(ClientEntry) * ServerConfig.MaxClients);
@ -783,7 +815,6 @@ int main(int argc, char *argv[])
{
int x;
for(x=0; x<ServerConfig.MaxClients; x++)
Clients[x].TCPSocket = -1;
}
@ -875,6 +906,7 @@ int main(int argc, char *argv[])
{
KillClient(&Clients[n]);
}
int whichgame;
for(whichgame = 0; whichgame < ServerConfig.MaxClients; whichgame ++)
{