From ff15a9896cbd663d2d9f8caafa48a94d4a829b73 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 29 Mar 2019 22:00:47 -0700 Subject: [PATCH 01/12] Grab mouse on window focus Window focus does not necessarily imply mouse movement. --- src/sdl/i_video.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 9fbe57b3..74f78980 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -359,6 +359,14 @@ static INT32 Impl_SDL_Scancode_To_Keycode(SDL_Scancode code) return 0; } +static void SDLdoGrabMouse(void) +{ + SDL_ShowCursor(SDL_DISABLE); + SDL_SetWindowGrab(window, SDL_TRUE); + if (SDL_SetRelativeMouseMode(SDL_TRUE) == 0) // already warps mouse if successful + wrapmouseok = SDL_TRUE; // TODO: is wrapmouseok or HalfWarpMouse needed anymore? +} + static void SDLdoUngrabMouse(void) { SDL_ShowCursor(SDL_ENABLE); @@ -629,6 +637,9 @@ static void Impl_HandleWindowEvent(SDL_WindowEvent evt) //else firsttimeonmouse = SDL_FALSE; capslock = !!( SDL_GetModState() & KMOD_CAPS );// in case CL changes + + if (USE_MOUSEINPUT) + SDLdoGrabMouse(); } else if (!mousefocus && !kbfocus) { @@ -708,9 +719,7 @@ static void Impl_HandleMouseMotionEvent(SDL_MouseMotionEvent evt) // -- Monster Iestyn if (SDL_GetMouseFocus() == window && SDL_GetKeyboardFocus() == window) { - SDL_SetWindowGrab(window, SDL_TRUE); - if (SDL_SetRelativeMouseMode(SDL_TRUE) == 0) // already warps mouse if successful - wrapmouseok = SDL_TRUE; // TODO: is wrapmouseok or HalfWarpMouse needed anymore? + SDLdoGrabMouse(); } } } @@ -1277,7 +1286,7 @@ void I_StartupMouse(void) else firsttimeonmouse = SDL_FALSE; if (cv_usemouse.value) - return; + SDLdoGrabMouse(); else SDLdoUngrabMouse(); } From 42d47a10f3008e74b70944474864f5c6dd9c8c7e Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 8 Apr 2019 15:48:20 -0700 Subject: [PATCH 02/12] "NEWPING" might as well be the only ping --- src/d_clisrv.c | 16 ------------ src/d_clisrv.h | 8 ------ src/d_net.c | 66 ++++---------------------------------------------- src/d_netcmd.c | 4 --- src/d_netcmd.h | 2 -- src/doomdef.h | 3 --- src/doomstat.h | 2 -- src/m_menu.c | 2 -- 8 files changed, 5 insertions(+), 98 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index e227ce2e..4f5e762d 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -91,12 +91,10 @@ tic_t jointimeout = (3*TICRATE); static boolean sendingsavegame[MAXNETNODES]; // Are we sending the savegame? static tic_t freezetimeout[MAXNETNODES]; // Until when can this node freeze the server before getting a timeout? -#ifdef NEWPING UINT16 pingmeasurecount = 1; UINT32 realpingtable[MAXPLAYERS]; //the base table of ping where an average will be sent to everyone. UINT32 playerpingtable[MAXPLAYERS]; //table of player latency values. tic_t servermaxping = 800; // server's max ping. Defaults to 800 -#endif SINT8 nodetoplayer[MAXNETNODES]; SINT8 nodetoplayer2[MAXNETNODES]; // say the numplayer for this node if any (splitscreen) SINT8 nodetoplayer3[MAXNETNODES]; // say the numplayer for this node if any (splitscreen == 2) @@ -3094,12 +3092,10 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) HU_AddChatText(va("\x82*%s has been kicked (Go away)", player_names[pnum]), false); kickreason = KR_KICK; break; -#ifdef NEWPING case KICK_MSG_PING_HIGH: HU_AddChatText(va("\x82*%s left the game (Broke ping limit)", player_names[pnum]), false); kickreason = KR_PINGLIMIT; break; -#endif case KICK_MSG_CON_FAIL: HU_AddChatText(va("\x82*%s left the game (Synch Failure)", player_names[pnum]), false); kickreason = KR_SYNCH; @@ -3172,10 +3168,8 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) D_StartTitle(); if (msg == KICK_MSG_CON_FAIL) M_StartMessage(M_GetText("Server closed connection\n(Synch failure)\nPress ESC\n"), NULL, MM_NOTHING); -#ifdef NEWPING else if (msg == KICK_MSG_PING_HIGH) M_StartMessage(M_GetText("Server closed connection\n(Broke ping limit)\nPress ESC\n"), NULL, MM_NOTHING); -#endif else if (msg == KICK_MSG_BANNED) M_StartMessage(M_GetText("You have been banned by the server\n\nPress ESC\n"), NULL, MM_NOTHING); else if (msg == KICK_MSG_CUSTOM_KICK) @@ -4630,7 +4624,6 @@ FILESTAMP resynch_local_inprogress = true; CL_AcknowledgeResynch(&netbuffer->u.resynchpak); break; -#ifdef NEWPING case PT_PING: // Only accept PT_PING from the server. if (node != servernode) @@ -4660,7 +4653,6 @@ FILESTAMP } break; -#endif case PT_SERVERCFG: break; case PT_FILEFRAGMENT: @@ -5298,7 +5290,6 @@ void TryRunTics(tic_t realtics) } } -#ifdef NEWPING /* Ping Update except better: We call this once per second and check for people's pings. If their ping happens to be too high, we increment some timer and kick them out. @@ -5382,11 +5373,9 @@ static inline void PingUpdate(void) pingmeasurecount = 1; //Reset count } -#endif static tic_t gametime = 0; -#ifdef NEWPING static void UpdatePingTable(void) { INT32 i; @@ -5401,7 +5390,6 @@ static void UpdatePingTable(void) pingmeasurecount++; } } -#endif // Handle timeouts to prevent definitive freezes from happenning static void HandleNodeTimeouts(void) @@ -5426,9 +5414,7 @@ void NetKeepAlive(void) if (realtics <= 0) // nothing new to update return; -#ifdef NEWPING UpdatePingTable(); -#endif if (server) CL_SendClientKeepAlive(); @@ -5475,9 +5461,7 @@ void NetUpdate(void) gametime = nowtime; -#ifdef NEWPING UpdatePingTable(); -#endif if (client) maketic = neededtic; diff --git a/src/d_clisrv.h b/src/d_clisrv.h index f3a9011e..f4db8512 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -93,9 +93,7 @@ typedef enum PT_NODETIMEOUT, // Packet sent to self if the connection times out. PT_RESYNCHING, // Packet sent to resync players. // Blocks game advance until synched. -#ifdef NEWPING PT_PING, // Packet sent to tell clients the other client's latency to server. -#endif NUMPACKETTYPE } packettype_t; @@ -473,9 +471,7 @@ typedef struct msaskinfo_pak msaskinfo; // 22 bytes plrinfo playerinfo[MAXPLAYERS]; // 576 bytes(?) plrconfig playerconfig[MAXPLAYERS]; // (up to) 528 bytes(?) -#ifdef NEWPING UINT32 pingtable[MAXPLAYERS+1]; // 68 bytes -#endif } u; // This is needed to pack diff packet types data together } ATTRPACK doomdata_t; @@ -509,9 +505,7 @@ extern consvar_t cv_playbackspeed; #define KICK_MSG_PLAYER_QUIT 3 #define KICK_MSG_TIMEOUT 4 #define KICK_MSG_BANNED 5 -#ifdef NEWPING #define KICK_MSG_PING_HIGH 6 -#endif #define KICK_MSG_CUSTOM_KICK 7 #define KICK_MSG_CUSTOM_BAN 8 @@ -536,12 +530,10 @@ extern SINT8 servernode; void Command_Ping_f(void); extern tic_t connectiontimeout; extern tic_t jointimeout; -#ifdef NEWPING extern UINT16 pingmeasurecount; extern UINT32 realpingtable[MAXPLAYERS]; extern UINT32 playerpingtable[MAXPLAYERS]; extern tic_t servermaxping; -#endif extern consvar_t #ifdef VANILLAJOINNEXTROUND diff --git a/src/d_net.c b/src/d_net.c index 9f719967..9cff9278 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -185,22 +185,10 @@ typedef struct UINT8 nextacknum; UINT8 flags; -#ifndef NEWPING - // jacobson tcp timeout evaluation algorithm (Karn variation) - fixed_t ping; - fixed_t varping; - INT32 timeout; // computed with ping and varping -#endif } node_t; static node_t nodes[MAXNETNODES]; -#ifndef NEWPING -#define PINGDEFAULT ((200*TICRATE*FRACUNIT)/1000) -#define VARPINGDEFAULT ((50*TICRATE*FRACUNIT)/1000) -#define TIMEOUT(p,v) (p+4*v+FRACUNIT/2)>>FRACBITS; -#else -#define NODETIMEOUT 14 //What the above boiled down to... -#endif +#define NODETIMEOUT 14 #ifndef NONET // return <0 if a < b (mod 256) @@ -320,19 +308,7 @@ static UINT8 GetAcktosend(INT32 node) static void RemoveAck(INT32 i) { INT32 node = ackpak[i].destinationnode; -#ifndef NEWPING - fixed_t trueping = (I_GetTime() - ackpak[i].senttime)<>FRACBITS,(double)FIXED_TO_FLOAT(nodes[node].ping),(double)FIXED_TO_FLOAT(nodes[node].varping),nodes[node].timeout)); -#else DEBFILE(va("Remove ack %d\n",ackpak[i].acknum)); -#endif ackpak[i].acknum = 0; if (nodes[node].flags & NF_CLOSE) Net_CloseConnection(node); @@ -519,11 +495,7 @@ void Net_AckTicker(void) { const INT32 nodei = ackpak[i].destinationnode; node_t *node = &nodes[nodei]; -#ifdef NEWPING if (ackpak[i].acknum && ackpak[i].senttime + NODETIMEOUT < I_GetTime()) -#else - if (ackpak[i].acknum && ackpak[i].senttime + node->timeout < I_GetTime()) -#endif { if (ackpak[i].resentnum > 10 && (node->flags & NF_CLOSE)) { @@ -534,13 +506,8 @@ void Net_AckTicker(void) ackpak[i].acknum = 0; continue; } -#ifdef NEWPING DEBFILE(va("Resend ack %d, %u<%d at %u\n", ackpak[i].acknum, ackpak[i].senttime, NODETIMEOUT, I_GetTime())); -#else - DEBFILE(va("Resend ack %d, %u<%d at %u\n", ackpak[i].acknum, ackpak[i].senttime, - node->timeout, I_GetTime())); -#endif M_Memcpy(netbuffer, ackpak[i].pak.raw, ackpak[i].length); ackpak[i].senttime = I_GetTime(); ackpak[i].resentnum++; @@ -658,11 +625,6 @@ void Net_WaitAllAckReceived(UINT32 timeout) static void InitNode(node_t *node) { node->acktosend_head = node->acktosend_tail = 0; -#ifndef NEWPING - node->ping = PINGDEFAULT; - node->varping = VARPINGDEFAULT; - node->timeout = TIMEOUT(node->ping, node->varping); -#endif node->firstacktosend = 0; node->nextacknum = 1; node->remotefirstack = 0; @@ -854,9 +816,7 @@ static const char *packettypename[NUMPACKETTYPE] = "CLIENTJOIN", "NODETIMEOUT", "RESYNCHING", -#ifdef NEWPING "PING" -#endif }; static void DebugPrintpacket(const char *header) @@ -1412,28 +1372,12 @@ boolean D_CheckNetGame(void) void Command_Ping_f(void) { -#ifndef NEWPING - if(server) + INT32 i; + for (i = 0; i < MAXPLAYERS;i++) { -#endif - INT32 i; - for (i = 0; i < MAXPLAYERS;i++) - { -#ifndef NEWPING - const INT32 node = playernode[i]; - if (playeringame[i] && node != 0) - CONS_Printf(M_GetText("%.2d : %s\n %d tics, %d ms.\n"), i, player_names[i], - GetLag(node), G_TicsToMilliseconds(GetLag(node))); -#else - if (playeringame[i] && i != 0) - CONS_Printf(M_GetText("%.2d : %s\n %d ms\n"), i, player_names[i], playerpingtable[i]); -#endif - } -#ifndef NEWPING + if (playeringame[i] && i != 0) + CONS_Printf(M_GetText("%.2d : %s\n %d ms\n"), i, player_names[i], playerpingtable[i]); } - else - CONS_Printf(M_GetText("Only the server can use this.\n")); -#endif } void D_CloseConnection(void) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 08bf3318..0173b5db 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -434,7 +434,6 @@ static CV_PossibleValue_t nettimeout_cons_t[] = {{TICRATE/7, "MIN"}, {60*TICRATE consvar_t cv_nettimeout = {"nettimeout", "105", CV_CALL|CV_SAVE, nettimeout_cons_t, NetTimeout_OnChange, 0, NULL, NULL, 0, 0, NULL}; //static CV_PossibleValue_t jointimeout_cons_t[] = {{5*TICRATE, "MIN"}, {60*TICRATE, "MAX"}, {0, NULL}}; consvar_t cv_jointimeout = {"jointimeout", "105", CV_CALL|CV_SAVE, nettimeout_cons_t, JoinTimeout_OnChange, 0, NULL, NULL, 0, 0, NULL}; -#ifdef NEWPING static CV_PossibleValue_t maxping_cons_t[] = {{0, "MIN"}, {1000, "MAX"}, {0, NULL}}; consvar_t cv_maxping = {"maxping", "800", CV_SAVE, maxping_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -445,7 +444,6 @@ consvar_t cv_pingtimeout = {"pingtimeout", "10", CV_SAVE, pingtimeout_cons_t, NU static CV_PossibleValue_t showping_cons_t[] = {{0, "Off"}, {1, "Always"}, {2, "Warning"}, {0, NULL}}; consvar_t cv_showping = {"showping", "Always", CV_SAVE, showping_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -#endif // Intermission time Tails 04-19-2002 static CV_PossibleValue_t inttime_cons_t[] = {{0, "MIN"}, {3600, "MAX"}, {0, NULL}}; consvar_t cv_inttime = {"inttime", "20", CV_NETVAR, inttime_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -674,11 +672,9 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_skipmapcheck); CV_RegisterVar(&cv_sleep); -#ifdef NEWPING CV_RegisterVar(&cv_maxping); CV_RegisterVar(&cv_pingtimeout); CV_RegisterVar(&cv_showping); -#endif #ifdef SEENAMES CV_RegisterVar(&cv_allowseenames); diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 166c5e00..e6c327ab 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -143,11 +143,9 @@ extern consvar_t cv_ringslinger, cv_soundtest; extern consvar_t cv_specialrings, cv_powerstones, cv_matchboxes, cv_competitionboxes; -#ifdef NEWPING extern consvar_t cv_maxping; extern consvar_t cv_pingtimeout; extern consvar_t cv_showping; -#endif extern consvar_t cv_skipmapcheck; diff --git a/src/doomdef.h b/src/doomdef.h index 6664ff51..51052a0b 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -601,9 +601,6 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; /// Polyobject fake flat code #define POLYOBJECTS_PLANES -/// Improved way of dealing with ping values and a ping limit. -#define NEWPING - /// See name of player in your crosshair #define SEENAMES diff --git a/src/doomstat.h b/src/doomstat.h index 834b3a7c..4b0c2e3e 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -543,9 +543,7 @@ extern consvar_t cv_forceskin; // force clients to use the server's skin extern consvar_t cv_downloading; // allow clients to downloading WADs. extern consvar_t cv_nettimeout; // SRB2Kart: Advanced server options menu extern consvar_t cv_jointimeout; -#ifdef NEWPING extern consvar_t cv_maxping; -#endif extern ticcmd_t netcmds[BACKUPTICS][MAXPLAYERS]; extern INT32 serverplayer; extern INT32 adminplayers[MAXPLAYERS]; diff --git a/src/m_menu.c b/src/m_menu.c index 3ad076ff..afb085c4 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2331,10 +2331,8 @@ static void M_ChangeCvar(INT32 choice) choice *= (TICRATE/7); else if (cv == &cv_maxsend) choice *= 512; -#ifdef NEWPING else if (cv == &cv_maxping) choice *= 50; -#endif #endif CV_AddValue(cv,choice); } From e746e540757ab4d77734bfdc585c19baecc81803 Mon Sep 17 00:00:00 2001 From: James R Date: Mon, 8 Apr 2019 15:57:23 -0700 Subject: [PATCH 03/12] Replace ping command with a condensed and sorted version --- src/d_net.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/src/d_net.c b/src/d_net.c index 9cff9278..94b11d51 100644 --- a/src/d_net.c +++ b/src/d_net.c @@ -1370,13 +1370,72 @@ boolean D_CheckNetGame(void) return ret; } +struct pingcell +{ + INT32 num; + INT32 ms; +}; + +static int pingcellcmp(const void *va, const void *vb) +{ + const struct pingcell *a, *b; + a = va; + b = vb; + return ( a->ms - b->ms ); +} + +/* +New ping command formatted nicely to present ping in +ascending order. And with equally spaced columns. +The caller's ping is presented at the bottom too, for +convenience. +*/ + void Command_Ping_f(void) { + struct pingcell pingv[MAXPLAYERS]; + INT32 pingc; + + int name_width = 0; + int ms_width = 0; + + int n; INT32 i; - for (i = 0; i < MAXPLAYERS;i++) + + pingc = 0; + for (i = 1; i < MAXPLAYERS; ++i) + if (playeringame[i]) { - if (playeringame[i] && i != 0) - CONS_Printf(M_GetText("%.2d : %s\n %d ms\n"), i, player_names[i], playerpingtable[i]); + n = strlen(player_names[i]); + if (n > name_width) + name_width = n; + + n = playerpingtable[i]; + if (n > ms_width) + ms_width = n; + + pingv[pingc].num = i; + pingv[pingc].ms = playerpingtable[i]; + pingc++; + } + + if (ms_width < 10) ms_width = 1; + else if (ms_width < 100) ms_width = 2; + else ms_width = 3; + + qsort(pingv, pingc, sizeof (struct pingcell), &pingcellcmp); + + for (i = 0; i < pingc; ++i) + { + CONS_Printf("%02d : %-*s %*d ms\n", + pingv[i].num, + name_width, player_names[pingv[i].num], + ms_width, pingv[i].ms); + } + + if (!server && playeringame[consoleplayer]) + { + CONS_Printf("\nYour ping is %d ms\n", playerpingtable[consoleplayer]); } } From fe7220bb20132092a44fcb79f3ed68de5c9348d1 Mon Sep 17 00:00:00 2001 From: fickleheart Date: Fri, 12 Apr 2019 00:46:52 -0500 Subject: [PATCH 04/12] Allow argument substitution in aliases --- src/command.c | 44 +++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 41 insertions(+), 3 deletions(-) diff --git a/src/command.c b/src/command.c index a5d45bc1..543df6ce 100644 --- a/src/command.c +++ b/src/command.c @@ -537,10 +537,48 @@ static void COM_ExecuteString(char *ptext) { CONS_Alert(CONS_WARNING, M_GetText("Alias recursion cycle detected!\n")); recursion = 0; - return; } - recursion++; - COM_BufInsertText(a->value); + else + { + char buf[1024]; + char *write = buf, *read = a->value, *seek = read; + + while (*seek != '\0') + { + if (*seek == '$') + { + memcpy(write, read, seek-read); + write += seek-read; + + seek++; + + if (*seek >= '1' && *seek <= '9') + { + if (com_argc > (size_t)(*seek - '0')) + { + memcpy(write, com_argv[*seek - '0'], strlen(com_argv[*seek - '0'])); + write += strlen(com_argv[*seek - '0']); + } + seek++; + } + else + { + *write = '$'; + write++; + } + + read = seek; + } + else + seek++; + } + memcpy(write, read, seek-read); + write += seek-read; + *write = '\0'; + + recursion++; + COM_BufInsertText(buf); + } return; } } From 3286d9ac9384556b515db327439ac05dc75b8db4 Mon Sep 17 00:00:00 2001 From: fickleheart Date: Sat, 13 Apr 2019 10:16:54 -0500 Subject: [PATCH 05/12] Use strchr? --- src/command.c | 45 +++++++++++++++++++-------------------------- 1 file changed, 19 insertions(+), 26 deletions(-) diff --git a/src/command.c b/src/command.c index 543df6ce..8e2d0037 100644 --- a/src/command.c +++ b/src/command.c @@ -543,38 +543,31 @@ static void COM_ExecuteString(char *ptext) char buf[1024]; char *write = buf, *read = a->value, *seek = read; - while (*seek != '\0') + while ((seek = strchr(seek, '$')) != NULL) { - if (*seek == '$') + memcpy(write, read, seek-read); + write += seek-read; + + seek++; + + if (*seek >= '1' && *seek <= '9') { - memcpy(write, read, seek-read); - write += seek-read; - + if (com_argc > (size_t)(*seek - '0')) + { + memcpy(write, com_argv[*seek - '0'], strlen(com_argv[*seek - '0'])); + write += strlen(com_argv[*seek - '0']); + } seek++; - - if (*seek >= '1' && *seek <= '9') - { - if (com_argc > (size_t)(*seek - '0')) - { - memcpy(write, com_argv[*seek - '0'], strlen(com_argv[*seek - '0'])); - write += strlen(com_argv[*seek - '0']); - } - seek++; - } - else - { - *write = '$'; - write++; - } - - read = seek; } else - seek++; + { + *write = '$'; + write++; + } + + read = seek; } - memcpy(write, read, seek-read); - write += seek-read; - *write = '\0'; + WRITESTRING(write, read); recursion++; COM_BufInsertText(buf); From 451ff30a7a0e7a004547d2e81467974a15004b6c Mon Sep 17 00:00:00 2001 From: fickleheart Date: Sat, 13 Apr 2019 10:25:56 -0500 Subject: [PATCH 06/12] Preserve quote and etc in aliases --- src/command.c | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/command.c b/src/command.c index 8e2d0037..7d7a357a 100644 --- a/src/command.c +++ b/src/command.c @@ -594,8 +594,6 @@ static void COM_ExecuteString(char *ptext) static void COM_Alias_f(void) { cmdalias_t *a; - char cmd[1024]; - size_t i, c; if (COM_Argc() < 3) { @@ -608,19 +606,9 @@ static void COM_Alias_f(void) com_alias = a; a->name = Z_StrDup(COM_Argv(1)); - - // copy the rest of the command line - cmd[0] = 0; // start out with a null string - c = COM_Argc(); - for (i = 2; i < c; i++) - { - strcat(cmd, COM_Argv(i)); - if (i != c) - strcat(cmd, " "); - } - strcat(cmd, "\n"); - - a->value = Z_StrDup(cmd); + // Just use arg 2 if it's the only other argument, in case the alias is wrapped in quotes (backward compat, or multiple commands in one string). + // Otherwise pull the whole string and seek to the end of the alias name. The strctr is in case the alias is quoted. + a->value = Z_StrDup(COM_Argc() == 3 ? COM_Argv(2) : (strchr(COM_Args() + strlen(a->name), ' ') + 1)); } /** Prints a line of text to the console. From 4d739fe7a5bab34d9e6b7477cdb990841eae5643 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 26 Apr 2019 12:59:21 -0700 Subject: [PATCH 07/12] Unfuck MS connecting and error reporting Reconnect if the socket is closed. Report the proper error from SO_ERROR and report an error from getsockopt. --- src/mserv.c | 48 +++++++++++++++++++++++++----------------------- 1 file changed, 25 insertions(+), 23 deletions(-) diff --git a/src/mserv.c b/src/mserv.c index f5c4fa88..eb1e6302 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -661,11 +661,19 @@ FUNCMATH static const char *int2str(INT32 n) #ifndef NONET static INT32 ConnectionFailed(void) { + time(&MSLastPing); con_state = MSCS_FAILED; CONS_Alert(CONS_ERROR, M_GetText("Connection to Master Server failed\n")); CloseConnection(); return MS_CONNECT_ERROR; } + +static INT32 ConnectionFailedwerrno(int no) +{ + CONS_Alert(CONS_ERROR, M_GetText("Master Server socket error: %s\n"), + strerror(no)); + return ConnectionFailed(); +} #endif /** Tries to register the local game server on the master server. @@ -682,44 +690,41 @@ static INT32 AddToMasterServer(boolean firstadd) msg_server_t *info = (msg_server_t *)msg.buffer; INT32 room = -1; fd_set tset; - time_t timestamp = time(NULL); UINT32 signature, tmp; const char *insname; + if (socket_fd == ERRSOCKET)/* Woah, our socket was closed! */ + { + if (MS_Connect(GetMasterServerIP(), GetMasterServerPort(), 0)) + return ConnectionFailedwerrno(errno); + } + M_Memcpy(&tset, &wset, sizeof (tset)); res = select(255, NULL, &tset, NULL, &select_timeout); - if (res != ERRSOCKET && !res) + if (res == 0)/* nothing selected */ { - if (retry++ > 30) // an about 30 second timeout + /* + Timeout next call because SendPingToMasterServer + (our calling function) already calls this once + every two minutes. + */ + if (retry++ == 1) { retry = 0; CONS_Alert(CONS_ERROR, M_GetText("Master Server timed out\n")); - MSLastPing = timestamp; return ConnectionFailed(); } return MS_CONNECT_ERROR; } retry = 0; - if (res == ERRSOCKET) - { - if (MS_Connect(GetMasterServerIP(), GetMasterServerPort(), 0)) - { - CONS_Alert(CONS_ERROR, M_GetText("Master Server socket error #%u: %s\n"), errno, strerror(errno)); - MSLastPing = timestamp; - return ConnectionFailed(); - } - } // so, the socket is writable, but what does that mean, that the connection is // ok, or bad... let see that! j = (socklen_t)sizeof (i); - getsockopt(socket_fd, SOL_SOCKET, SO_ERROR, (char *)&i, &j); + if (getsockopt(socket_fd, SOL_SOCKET, SO_ERROR, (char *)&i, &j) == ERRSOCKET) + return ConnectionFailedwerrno(errno); if (i) // it was bad - { - CONS_Alert(CONS_ERROR, M_GetText("Master Server socket error #%u: %s\n"), errno, strerror(errno)); - MSLastPing = timestamp; - return ConnectionFailed(); - } + return ConnectionFailedwerrno(i); #ifdef PARANOIA if (ms_RoomId <= 0) @@ -752,15 +757,12 @@ static INT32 AddToMasterServer(boolean firstadd) msg.length = (UINT32)sizeof (msg_server_t); msg.room = 0; if (MS_Write(&msg) < 0) - { - MSLastPing = timestamp; return ConnectionFailed(); - } if(con_state != MSCS_REGISTERED) CONS_Printf(M_GetText("Master Server update successful.\n")); - MSLastPing = timestamp; + time(&MSLastPing); con_state = MSCS_REGISTERED; CloseConnection(); #endif From aa4ce2b2d12abb7b2f4e6a52fcde35e39a8278af Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 26 Apr 2019 13:06:26 -0700 Subject: [PATCH 08/12] Check error on select --- src/mserv.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mserv.c b/src/mserv.c index eb1e6302..1b0b41be 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -701,6 +701,8 @@ static INT32 AddToMasterServer(boolean firstadd) M_Memcpy(&tset, &wset, sizeof (tset)); res = select(255, NULL, &tset, NULL, &select_timeout); + if (res == -1) + return ConnectionFailedwerrno(errno); if (res == 0)/* nothing selected */ { /* From fc8ebe83fcb7642a09e06d84c6e506812643cb70 Mon Sep 17 00:00:00 2001 From: James R Date: Fri, 26 Apr 2019 13:08:35 -0700 Subject: [PATCH 09/12] Force of habit --- src/mserv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mserv.c b/src/mserv.c index 1b0b41be..5d10aa3c 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -701,7 +701,7 @@ static INT32 AddToMasterServer(boolean firstadd) M_Memcpy(&tset, &wset, sizeof (tset)); res = select(255, NULL, &tset, NULL, &select_timeout); - if (res == -1) + if (res == ERRSOCKET) return ConnectionFailedwerrno(errno); if (res == 0)/* nothing selected */ { From 848bb10c364735677266e94a86ed5b0031ae92d6 Mon Sep 17 00:00:00 2001 From: James R Date: Sat, 27 Apr 2019 17:28:29 -0700 Subject: [PATCH 10/12] Move some cvars out of D_ClientServerInit and save them --- src/d_clisrv.c | 12 +++--------- src/d_netcmd.c | 8 ++++++++ 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index f3b07d34..901879ec 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -3199,15 +3199,15 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) static CV_PossibleValue_t netticbuffer_cons_t[] = {{0, "MIN"}, {3, "MAX"}, {0, NULL}}; consvar_t cv_netticbuffer = {"netticbuffer", "1", CV_SAVE, netticbuffer_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_allownewplayer = {"allowjoin", "On", CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; +consvar_t cv_allownewplayer = {"allowjoin", "On", CV_SAVE|CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; #ifdef VANILLAJOINNEXTROUND -consvar_t cv_joinnextround = {"joinnextround", "Off", CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; /// \todo not done +consvar_t cv_joinnextround = {"joinnextround", "Off", CV_SAVE|CV_NETVAR, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; /// \todo not done #endif static CV_PossibleValue_t maxplayers_cons_t[] = {{2, "MIN"}, {MAXPLAYERS, "MAX"}, {0, NULL}}; consvar_t cv_maxplayers = {"maxplayers", "8", CV_SAVE, maxplayers_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t resynchattempts_cons_t[] = {{0, "MIN"}, {20, "MAX"}, {0, NULL}}; consvar_t cv_resynchattempts = {"resynchattempts", "5", CV_SAVE, resynchattempts_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL }; -consvar_t cv_blamecfail = {"blamecfail", "Off", 0, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; +consvar_t cv_blamecfail = {"blamecfail", "Off", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL }; // max file size to send to a player (in kilobytes) static CV_PossibleValue_t maxsend_cons_t[] = {{0, "MIN"}, {51200, "MAX"}, {0, NULL}}; @@ -3250,12 +3250,6 @@ void D_ClientServerInit(void) RegisterNetXCmd(XD_ADDPLAYER, Got_AddPlayer); RegisterNetXCmd(XD_REMOVEPLAYER, Got_RemovePlayer); #ifndef NONET - CV_RegisterVar(&cv_allownewplayer); -#ifdef VANILLAJOINNEXTROUND - CV_RegisterVar(&cv_joinnextround); -#endif - CV_RegisterVar(&cv_showjoinaddress); - CV_RegisterVar(&cv_blamecfail); #ifdef DUMPCONSISTENCY CV_RegisterVar(&cv_dumpconsistency); #endif diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 08bf3318..574c39d0 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -667,6 +667,14 @@ void D_RegisterServerCommands(void) CV_RegisterVar(&cv_maxsend); CV_RegisterVar(&cv_noticedownload); CV_RegisterVar(&cv_downloadspeed); +#ifndef NONET + CV_RegisterVar(&cv_allownewplayer); +#ifdef VANILLAJOINNEXTROUND + CV_RegisterVar(&cv_joinnextround); +#endif + CV_RegisterVar(&cv_showjoinaddress); + CV_RegisterVar(&cv_blamecfail); +#endif COM_AddCommand("ping", Command_Ping_f); CV_RegisterVar(&cv_nettimeout); From 031ffbf304256dc79a581547af41a11fc334ddee Mon Sep 17 00:00:00 2001 From: toaster Date: Sun, 28 Apr 2019 19:26:11 +0100 Subject: [PATCH 11/12] Completely untested -encore parameter for the map command; inverts cvar value. --- src/d_netcmd.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 08bf3318..bd0d6fb2 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2204,12 +2204,14 @@ static void Command_Map_f(void) const char *mapname; size_t i; INT32 j, newmapnum; - boolean newresetplayers; + boolean newresetplayers, newencoremode; INT32 newgametype = gametype; - // max length of command: map map03 -gametype coop -noresetplayers -force - // 1 2 3 4 5 6 + // max length of command: map map03 -gametype race -noresetplayers -force -encore + // 1 2 3 4 5 6 7 // = 8 arg max + // i don't know whether this is intrinsic to the system or just someone being weird but + // "noresetplayers" is pretty useless for kart if it turns out this is too close to the limit if (COM_Argc() < 2 || COM_Argc() > 8) { CONS_Printf(M_GetText("map [-gametype [-force]: warp to map\n")); @@ -2292,6 +2294,21 @@ static void Command_Map_f(void) } } + // new encoremode value + // use cvar by default + + newencoremode = (boolean)cv_kartencore.value; + + if (COM_CheckParm("-encore")) + { + if (!M_SecretUnlocked(SECRET_ENCORE) && !newencoremode) + { + CONS_Alert(CONS_NOTICE, M_GetText("You haven't unlocked Encore Mode yet!\n")); + return; + } + newencoremode = !newencoremode; + } + if (!(i = COM_CheckParm("-force")) && newgametype == gametype) // SRB2Kart newresetplayers = false; // if not forcing and gametypes is the same @@ -2322,7 +2339,7 @@ static void Command_Map_f(void) } fromlevelselect = false; - D_MapChange(newmapnum, newgametype, (boolean)cv_kartencore.value, newresetplayers, 0, false, false); + D_MapChange(newmapnum, newgametype, newencoremode, newresetplayers, 0, false, false); } /** Receives a map command and changes the map. From 103e67bbaaad22100f4d5bbd314813ff9e514a77 Mon Sep 17 00:00:00 2001 From: James R Date: Tue, 30 Apr 2019 13:03:13 -0700 Subject: [PATCH 12/12] Fix differing signedness compare --- src/mserv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mserv.c b/src/mserv.c index 5d10aa3c..29aa99fa 100644 --- a/src/mserv.c +++ b/src/mserv.c @@ -693,7 +693,7 @@ static INT32 AddToMasterServer(boolean firstadd) UINT32 signature, tmp; const char *insname; - if (socket_fd == ERRSOCKET)/* Woah, our socket was closed! */ + if (socket_fd == (SOCKET_TYPE)ERRSOCKET)/* Woah, our socket was closed! */ { if (MS_Connect(GetMasterServerIP(), GetMasterServerPort(), 0)) return ConnectionFailedwerrno(errno);