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 (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); Con_Printf ("Unable to redirect to %s\n", data);
else else
{ {

View File

@ -2176,50 +2176,7 @@ char *Sys_ConsoleInput (void)
#ifdef SUBSERVERS #ifdef SUBSERVERS
if (SSV_IsSubServer()) 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; return NULL;
}
#endif #endif
@ -2380,8 +2337,11 @@ qboolean Sys_InitTerminal (void)
houtput = GetStdHandle (STD_OUTPUT_HANDLE); houtput = GetStdHandle (STD_OUTPUT_HANDLE);
} }
GetConsoleMode(hinput, &m); if (hinput)
SetConsoleMode(hinput, m | 0x40 | 0x80); {
GetConsoleMode(hinput, &m);
SetConsoleMode(hinput, m | 0x40 | 0x80);
}
return true; return true;
} }
@ -4322,8 +4282,9 @@ int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLin
{ {
isDedicated = isClusterSlave = true; isDedicated = isClusterSlave = true;
#ifdef _DEBUG #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 #endif
SSV_SetupControlPipe(Sys_GetStdInOutStream());
} }
#endif #endif
#endif #endif

View File

@ -474,7 +474,16 @@ static int QDECL Sys_MSV_ReadBytes (struct vfsfile_s *file, void *buffer, int by
DWORD avail; DWORD avail;
//trying to do this stuff without blocking is a real pain. //trying to do this stuff without blocking is a real pain.
if (!PeekNamedPipe(s->inpipe, NULL, 0, NULL, &avail, NULL)) 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 return -1; //EOF
}
if (avail) if (avail)
{ {
if (avail > bytestoread) if (avail > bytestoread)
@ -551,12 +560,20 @@ vfsfile_t *Sys_ForkServer(void)
return &ctx->pub; 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. winsubserver_t *ctx = Z_Malloc(sizeof(*ctx));
HANDLE output = GetStdHandle(STD_OUTPUT_HANDLE); ctx->inpipe = GetStdHandle(STD_INPUT_HANDLE);
DWORD written = 0; ctx->outpipe = GetStdHandle(STD_OUTPUT_HANDLE);
WriteFile(output, cmd->data, cmd->cursize, &written, NULL);
//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 #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 void SSV_RequestShutdown(void); //asks the cluster to not send us new players
vfsfile_t *Sys_ForkServer(void); 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. 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. 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) if (error)
{ {
error = isClusterSlave;
SSV_SetupControlPipe(NULL); SSV_SetupControlPipe(NULL);
inbuffersize = 0; inbuffersize = 0;
if (error)
{
SV_FinalMessage("Cluster shut down\n");
Cmd_ExecuteString("quit\n", RESTRICT_LOCAL);
}
} }
} }
else if (msv_loop_to_ss) else if (msv_loop_to_ss)

View File

@ -921,46 +921,7 @@ char *Sys_ConsoleInput (void)
#ifdef SUBSERVERS #ifdef SUBSERVERS
if (SSV_IsSubServer()) 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; return NULL;
}
#endif #endif
if (isPlugin) if (isPlugin)
@ -1670,6 +1631,8 @@ int main (int argc, char **argv)
#ifdef SUBSERVERS #ifdef SUBSERVERS
isClusterSlave = COM_CheckParm("-clusterslave"); isClusterSlave = COM_CheckParm("-clusterslave");
if (isClusterSlave)
SSV_SetupControlPipe(Sys_GetStdInOutStream());
#endif #endif
#ifdef USESERVICE #ifdef USESERVICE
if (!SSV_IsSubServer() && StartServiceCtrlDispatcher( DispatchTable)) if (!SSV_IsSubServer() && StartServiceCtrlDispatcher( DispatchTable))