Fix up mapcluster functionality for windows.

git-svn-id: https://svn.code.sf.net/p/fteqw/code/trunk@6150 fc73d0e0-1445-4013-8a0c-d673dee63da5
This commit is contained in:
Spoike 2022-01-08 09:59:46 +00:00
parent 2dd5f25ddf
commit 495abcbe7b
6 changed files with 39 additions and 92 deletions

View file

@ -3224,7 +3224,7 @@ void CL_ConnectionlessPacket (void)
{
if (CL_IsPendingServerAddress(&net_from))
{
if (!NET_EnsureRoute(cls.sockets, "redir", cls.servername, &net_from))
if (!NET_EnsureRoute(cls.sockets, "redir", cls.servername, &adr))
Con_Printf ("Unable to redirect to %s\n", data);
else
{

View file

@ -2176,50 +2176,7 @@ char *Sys_ConsoleInput (void)
#ifdef SUBSERVERS
if (SSV_IsSubServer())
{
DWORD avail;
static char text[1024];
static int textpos = 0;
HANDLE input = GetStdHandle(STD_INPUT_HANDLE);
for (;;)
{
if (!PeekNamedPipe(input, NULL, 0, NULL, &avail, NULL))
{
SV_FinalMessage("Cluster shut down\n");
Cmd_ExecuteString("quit force", RESTRICT_LOCAL);
}
else if (avail)
{
if (avail > sizeof(text)-1-textpos)
avail = sizeof(text)-1-textpos;
if (ReadFile(input, text+textpos, avail, &avail, NULL))
{
textpos += avail;
while(textpos >= 2)
{
unsigned short len = text[0] | (text[1]<<8);
if (textpos >= len && len >= 2)
{
memcpy(net_message.data, text+2, len-2);
net_message.cursize = len-2;
MSG_BeginReading (msg_nullnetprim);
SSV_ReadFromControlServer();
memmove(text, text+len, textpos - len);
textpos -= len;
}
else
break;
}
}
}
else
break;
}
return NULL;
}
#endif
@ -2380,8 +2337,11 @@ qboolean Sys_InitTerminal (void)
houtput = GetStdHandle (STD_OUTPUT_HANDLE);
}
if (hinput)
{
GetConsoleMode(hinput, &m);
SetConsoleMode(hinput, m | 0x40 | 0x80);
}
return true;
}
@ -4322,8 +4282,9 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
{
isDedicated = isClusterSlave = true;
#ifdef _DEBUG
MessageBox(0, "New cluster slave starting\nAttach to process now, if desired.", "FTEQW", 0);
MessageBox(0, "New cluster slave starting\nAttach to process now, if desired.", "FTEQW Debug Build", 0);
#endif
SSV_SetupControlPipe(Sys_GetStdInOutStream());
}
#endif
#endif

View file

@ -474,7 +474,16 @@ static int QDECL Sys_MSV_ReadBytes (struct vfsfile_s *file, void *buffer, int by
DWORD avail;
//trying to do this stuff without blocking is a real pain.
if (!PeekNamedPipe(s->inpipe, NULL, 0, NULL, &avail, NULL))
{
/*switch(GetLastError())
{
case ERROR_BROKEN_PIPE:
case ERROR_PIPE_NOT_CONNECTED:
case ERROR_INVALID_HANDLE:
break;
}*/
return -1; //EOF
}
if (avail)
{
if (avail > bytestoread)
@ -551,12 +560,20 @@ vfsfile_t *Sys_ForkServer(void)
return &ctx->pub;
}
void Sys_InstructMaster(sizebuf_t *cmd)
vfsfile_t *Sys_GetStdInOutStream(void)
{
//FIXME: this is blocking. this is bad if the target is also blocking while trying to write to us.
HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE);
DWORD written = 0;
WriteFile(output, cmd->data, cmd->cursize, &written, NULL);
winsubserver_t *ctx = Z_Malloc(sizeof(*ctx));
ctx->inpipe = GetStdHandle(STD_INPUT_HANDLE);
ctx->outpipe = GetStdHandle(STD_OUTPUT_HANDLE);
//cause some errors if something else uses them (also avoid problems when closing).
SetStdHandle(STD_INPUT_HANDLE, NULL);
SetStdHandle(STD_OUTPUT_HANDLE, NULL);
ctx->pub.ReadBytes = Sys_MSV_ReadBytes;
ctx->pub.WriteBytes = Sys_MSV_WriteBytes;
ctx->pub.Close = Sys_MSV_Close;
return &ctx->pub;
}
#endif

View file

@ -1240,7 +1240,6 @@ void SSV_SavePlayerStats(client_t *cl, int reason); //initial, periodic (in case
void SSV_RequestShutdown(void); //asks the cluster to not send us new players
vfsfile_t *Sys_ForkServer(void);
void Sys_InstructMaster(sizebuf_t *cmd); //first two bytes will always be the length of the data
vfsfile_t *Sys_GetStdInOutStream(void); //obtains a bi-directional pipe for reading/writing via stdin/stdout. make sure the system code won't be using it.
qboolean MSV_NewNetworkedNode(vfsfile_t *stream, qbyte *reqstart, qbyte *buffered, size_t buffersize, const char *remoteaddr); //call to register a pipe to a newly discovered node.

View file

@ -1241,8 +1241,15 @@ void MSV_PollSlaves(void)
}
if (error)
{
error = isClusterSlave;
SSV_SetupControlPipe(NULL);
inbuffersize = 0;
if (error)
{
SV_FinalMessage("Cluster shut down\n");
Cmd_ExecuteString("quit\n", RESTRICT_LOCAL);
}
}
}
else if (msv_loop_to_ss)

View file

@ -921,46 +921,7 @@ char *Sys_ConsoleInput (void)
#ifdef SUBSERVERS
if (SSV_IsSubServer())
{
DWORD avail;
static char text[1024];
static int textpos = 0;
HANDLE input = GetStdHandle(STD_INPUT_HANDLE);
if (!PeekNamedPipe(input, NULL, 0, NULL, &avail, NULL))
{
SV_FinalMessage("Cluster shut down\n");
Cmd_ExecuteString("quit force", RESTRICT_LOCAL);
}
else if (avail)
{
if (avail > sizeof(text)-1-textpos)
avail = sizeof(text)-1-textpos;
if (ReadFile(input, text+textpos, avail, &avail, NULL))
{
textpos += avail;
while(textpos >= 2)
{
unsigned short len = text[0] | (text[1]<<8);
if (textpos >= len && len >= 2)
{
memcpy(net_message.data, text+2, len-2);
net_message.cursize = len-2;
MSG_BeginReading (msg_nullnetprim);
SSV_ReadFromControlServer();
memmove(text, text+len, textpos - len);
textpos -= len;
}
else
break;
}
}
}
return NULL;
}
#endif
if (isPlugin)
@ -1670,6 +1631,8 @@ int main (int argc, char **argv)
#ifdef SUBSERVERS
isClusterSlave = COM_CheckParm("-clusterslave");
if (isClusterSlave)
SSV_SetupControlPipe(Sys_GetStdInOutStream());
#endif
#ifdef USESERVICE
if (!SSV_IsSubServer() && StartServiceCtrlDispatcher( DispatchTable))