From 2f26e1d12a53a080150b4b51274cba81dd0e2666 Mon Sep 17 00:00:00 2001 From: TimeServ Date: Tue, 14 Mar 2006 02:54:54 +0000 Subject: [PATCH] fix sv_ftp logic git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@2117 fc73d0e0-1445-4013-8a0c-d673dee63da5 --- engine/http/ftpserver.c | 17 ++++++++++++----- engine/http/iwebiface.c | 12 +++++++++--- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/engine/http/ftpserver.c b/engine/http/ftpserver.c index 514ccb705..8a4e5f979 100644 --- a/engine/http/ftpserver.c +++ b/engine/http/ftpserver.c @@ -17,6 +17,7 @@ int ftpfilelistsocket; char *COM_ParseOut (char *data, char *out, int outlen); static iwboolean ftpserverinitied = false; +iwboolean ftpserverfailed = false; static int ftpserversocket; @@ -44,7 +45,7 @@ typedef struct FTPclient_s{ FTPclient_t *FTPclient; -void FTP_ServerInit(void) +qboolean FTP_ServerInit(void) { struct sockaddr_in address; unsigned long _true = true; @@ -53,12 +54,16 @@ void FTP_ServerInit(void) if ((ftpserversocket = socket (PF_INET, SOCK_STREAM, IPPROTO_TCP)) == -1) { - Sys_Error ("FTP_TCP_OpenSocket: socket:", strerror(qerrno)); + Con_Printf ("FTP_TCP_OpenSocket: socket: %s\n", strerror(qerrno)); + ftpserverfailed = true; + return false; } if (ioctlsocket (ftpserversocket, FIONBIO, &_true) == -1) { Sys_Error ("FTP_TCP_OpenSocket: ioctl FIONBIO:", strerror(qerrno)); + ftpserverfailed = true; + return false; } address.sin_family = AF_INET; @@ -77,8 +82,10 @@ void FTP_ServerInit(void) if( bind (ftpserversocket, (void *)&address, sizeof(address)) == -1) { + Con_Printf("FTP_ServerInit: failed to bind socket\n"); closesocket(ftpserversocket); - return; + ftpserverfailed = true; + return false; } listen(ftpserversocket, 3); @@ -87,7 +94,7 @@ void FTP_ServerInit(void) IWebPrintf("FTP server is running\n"); - return; + return true; } void FTP_ServerShutdown(void) @@ -747,7 +754,7 @@ unsigned long _true = true; if (!ftpserverinitied) { if (ftpserverwanted) - FTP_ServerInit(); + return FTP_ServerInit(); return false; } else if (!ftpserverwanted) diff --git a/engine/http/iwebiface.c b/engine/http/iwebiface.c index 0fe3bb59e..1a4afb5f3 100644 --- a/engine/http/iwebiface.c +++ b/engine/http/iwebiface.c @@ -68,8 +68,8 @@ int main(int argc, char **argv) { FTP_ServerRun(1); HTTP_ServerPoll(1); - if (httpserverfailed) - Sys_Error("HTTP server failed"); + if (ftpserverfailed || httpserverfailed) + Sys_Error("FTP/HTTP server failed"); Sleep(1); } } @@ -370,10 +370,16 @@ void IWebInit(void) void IWebRun(void) { #ifdef WEBSERVER - extern qboolean httpserverfailed; + extern qboolean httpserverfailed, ftpserverfailed; FTP_ServerRun(ftpserver.value!= 0); HTTP_ServerPoll(httpserver.value!=0); + if (ftpserverfailed) + { + Con_Printf("FTP Server failed to load, setting %s to 0\n", ftpserver.name); + Cvar_SetValue(&ftpserver, 0); + ftpserverfailed = false; + } if (httpserverfailed) { Con_Printf("HTTP Server failed to load, setting %s to 0\n", httpserver.name);