From b59718d3ad48a7c7711dffac9415a9770552d41c Mon Sep 17 00:00:00 2001 From: Wolfy Date: Thu, 7 Dec 2017 22:45:39 -0600 Subject: [PATCH] Remove hardcoded limit on admins # Conflicts: # src/d_netcmd.c --- src/d_clisrv.c | 10 ++- src/d_clisrv.h | 4 +- src/d_netcmd.c | 164 +++++++++++++++++++++++++++++++---- src/d_netcmd.h | 5 +- src/doomstat.h | 2 +- src/sdl/Srb2SDL-vc10.vcxproj | 1 - 6 files changed, 158 insertions(+), 28 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 331872dac..807b26cf1 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1375,8 +1375,7 @@ static boolean SV_SendServerConfig(INT32 node) for (i = 0; i < MAXPLAYERS; i++) { - if (i < 4) - netbuffer->u.servercfg.adminplayers[i] = (SINT8)adminplayers[i]; + netbuffer->u.servercfg.adminplayers[i] = (SINT8)adminplayers[i]; if (!playeringame[i]) continue; @@ -3275,6 +3274,10 @@ boolean Playing(void) boolean SV_SpawnServer(void) { + INT32 i; + for (i = 0; i < MAXPLAYERS; i++) + adminplayers[i] = -1; // Populate the entire adminplayers array with -1. + if (demoplayback) G_StopDemo(); // reset engine parameter if (metalplayback) @@ -3598,9 +3601,8 @@ static void HandlePacketFromAwayNode(SINT8 node) maketic = gametic = neededtic = (tic_t)LONG(netbuffer->u.servercfg.gametic); gametype = netbuffer->u.servercfg.gametype; modifiedgame = netbuffer->u.servercfg.modifiedgame; - for (j = 0; j < 4; j++) + for (j = 0; j < MAXPLAYERS; j++) adminplayers[j] = netbuffer->u.servercfg.adminplayers[j]; - j = 0; memcpy(server_context, netbuffer->u.servercfg.server_context, 8); } diff --git a/src/d_clisrv.h b/src/d_clisrv.h index b2d91075c..4529aa65e 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -282,7 +282,7 @@ typedef struct UINT8 gametype; UINT8 modifiedgame; - SINT8 adminplayers[4]; // Needs to be signed + SINT8 adminplayers[MAXPLAYERS]; // Needs to be signed char server_context[8]; // Unique context id, generated at server startup. @@ -321,7 +321,7 @@ typedef struct UINT8 cheatsenabled; UINT8 isdedicated; UINT8 fileneedednum; - SINT8 adminplayers[4]; + SINT8 adminplayers[MAXPLAYERS]; tic_t time; tic_t leveltime; char servername[MAXSERVERNAME]; diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 4d4852cb3..092cfe4f1 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -128,6 +128,7 @@ FUNCNORETURN static ATTRNORETURN void Command_Quit_f(void); static void Command_Playintro_f(void); static void Command_Displayplayer_f(void); +static void Command_Tunes_f(void); static void Command_ExitLevel_f(void); static void Command_Showmap_f(void); @@ -144,7 +145,9 @@ static void Command_Changepassword_f(void); static void Command_Login_f(void); static void Got_Login(UINT8 **cp, INT32 playernum); static void Got_Verification(UINT8 **cp, INT32 playernum); +static void Got_Removal(UINT8 **cp, INT32 playernum); static void Command_Verify_f(void); +static void Command_RemoveAdmin_f(void); static void Command_MotD_f(void); static void Got_MotD_f(UINT8 **cp, INT32 playernum); @@ -366,7 +369,7 @@ consvar_t cv_sleep = {"cpusleep", "-1", CV_SAVE, sleeping_cons_t, NULL, -1, NULL INT16 gametype = GT_COOP; boolean splitscreen = false; boolean circuitmap = false; -INT32 adminplayers[] = { -1, -1, -1, -1 }; // Hardcoded to four admins for now. +INT32 adminplayers[MAXPLAYERS]; /// \warning Keep this up-to-date if you add/remove/rename net text commands const char *netxcmdnames[MAXNETXCMD - 1] = @@ -428,8 +431,10 @@ void D_RegisterServerCommands(void) COM_AddCommand("password", Command_Changepassword_f); RegisterNetXCmd(XD_LOGIN, Got_Login); COM_AddCommand("login", Command_Login_f); // useful in dedicated to kick off remote admin - COM_AddCommand("verify", Command_Verify_f); + COM_AddCommand("promote", Command_Verify_f); RegisterNetXCmd(XD_VERIFIED, Got_Verification); + COM_AddCommand("demote", Command_RemoveAdmin_f); + RegisterNetXCmd(XD_DEMOTED, Got_Removal); COM_AddCommand("motd", Command_MotD_f); RegisterNetXCmd(XD_SETMOTD, Got_MotD_f); // For remote admin @@ -580,6 +585,7 @@ void D_RegisterServerCommands(void) */ void D_RegisterClientCommands(void) { + const char *username; INT32 i; for (i = 0; i < MAXSKINCOLORS; i++) @@ -636,6 +642,8 @@ void D_RegisterClientCommands(void) #endif // register these so it is saved to config + if ((username = I_GetUserName())) + cv_playername.defaultvalue = username; CV_RegisterVar(&cv_playername); CV_RegisterVar(&cv_playercolor); CV_RegisterVar(&cv_skin); // r_things.c (skin NAME) @@ -1366,9 +1374,9 @@ void SendWeaponPref(void) XBOXSTATIC UINT8 buf[1]; buf[0] = 0; - if (cv_flipcam.value) + if (players[consoleplayer].pflags & PF_FLIPCAM) buf[0] |= 1; - if (cv_analog.value) + if (players[consoleplayer].pflags & PF_ANALOGMODE) buf[0] |= 2; SendNetXCmd(XD_WEAPONPREF, buf, 1); } @@ -1378,9 +1386,9 @@ void SendWeaponPref2(void) XBOXSTATIC UINT8 buf[1]; buf[0] = 0; - if (cv_flipcam2.value) + if (players[secondarydisplayplayer].pflags & PF_FLIPCAM) buf[0] |= 1; - if (cv_analog2.value) + if (players[secondarydisplayplayer].pflags & PF_ANALOGMODE) buf[0] |= 2; SendNetXCmd2(XD_WEAPONPREF, buf, 1); } @@ -2742,7 +2750,7 @@ static void Got_Login(UINT8 **cp, INT32 playernum) if (!memcmp(sentmd5, finalmd5, 16)) { CONS_Printf(M_GetText("%s passed authentication.\n"), player_names[playernum]); - COM_BufInsertText(va("verify %d\n", playernum)); // do this immediately + COM_BufInsertText(va("promote %d\n", playernum)); // do this immediately } else CONS_Printf(M_GetText("Password from %s failed.\n"), player_names[playernum]); @@ -2752,7 +2760,7 @@ static void Got_Login(UINT8 **cp, INT32 playernum) boolean IsPlayerAdmin(INT32 playernum) { INT32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAXPLAYERS; i++) if (playernum == adminplayers[i]) return true; @@ -2762,7 +2770,7 @@ boolean IsPlayerAdmin(INT32 playernum) void SetAdminPlayer(INT32 playernum) { INT32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAXPLAYERS; i++) { if (playernum == adminplayers[i]) return; // Player is already admin @@ -2773,25 +2781,21 @@ void SetAdminPlayer(INT32 playernum) break; // End the loop now. If it keeps going, the same player might get assigned to two slots. } - if (i == 3 && adminplayers[i] != -1) // End of the loop and all slots are full - { - adminplayers[0] = playernum; // Overwrite the first slot - break; - } + } } void ClearAdminPlayers(void) { INT32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAXPLAYERS; i++) adminplayers[i] = -1; } void RemoveAdminPlayer(INT32 playernum) { INT32 i; - for (i = 0; i < 4; i++) + for (i = 0; i < MAXPLAYERS; i++) if (playernum == adminplayers[i]) adminplayers[i] = -1; } @@ -2810,7 +2814,7 @@ static void Command_Verify_f(void) if (COM_Argc() != 2) { - CONS_Printf(M_GetText("verify : give admin privileges to a node\n")); + CONS_Printf(M_GetText("promote : give admin privileges to a node\n")); return; } @@ -2852,6 +2856,62 @@ static void Got_Verification(UINT8 **cp, INT32 playernum) CONS_Printf(M_GetText("You are now a server administrator.\n")); } +static void Command_RemoveAdmin_f(void) +{ + XBOXSTATIC char buf[8]; // Should be plenty + char *temp; + INT32 playernum; + + if (client) + { + CONS_Printf(M_GetText("Only the server can use this.\n")); + return; + } + + if (COM_Argc() != 2) + { + CONS_Printf(M_GetText("demote : remove admin privileges from a node\n")); + return; + } + + strlcpy(buf, COM_Argv(1), sizeof(buf)); + + playernum = atoi(buf); + + temp = buf; + + WRITEUINT8(temp, playernum); + + if (playeringame[playernum]) + SendNetXCmd(XD_DEMOTED, buf, 1); +} + +static void Got_Removal(UINT8 **cp, INT32 playernum) +{ + INT16 num = READUINT8(*cp); + + if (playernum != serverplayer) // it's not from the server (hacker or bug) + { + CONS_Alert(CONS_WARNING, M_GetText("Illegal demotion received from %s (serverplayer is %s)\n"), player_names[playernum], player_names[serverplayer]); + if (server) + { + XBOXSTATIC UINT8 buf[2]; + + buf[0] = (UINT8)playernum; + buf[1] = KICK_MSG_CON_FAIL; + SendNetXCmd(XD_KICK, &buf, 2); + } + return; + } + + RemoveAdminPlayer(num); + + if (num != consoleplayer) + return; + + CONS_Printf(M_GetText("You are no longer a server administrator.\n")); +} + static void Command_MotD_f(void) { size_t i, j; @@ -3226,7 +3286,7 @@ static void Got_RequestAddfilecmd(UINT8 **cp, INT32 playernum) CONS_Printf("%s",message); - for (j = 0; j < 4; j++) + for (j = 0; j < MAXPLAYERS; j++) if (adminplayers[j]) COM_BufAddText(va("sayto %d %s", adminplayers[j], message)); @@ -3926,6 +3986,74 @@ static void Command_Displayplayer_f(void) CONS_Printf(M_GetText("Displayplayer is %d\n"), displayplayer); } +static void Command_Tunes_f(void) +{ + const char *tunearg; + UINT16 tunenum, track = 0; + const size_t argc = COM_Argc(); + + if (argc < 2) //tunes slot ... + { + CONS_Printf("tunes [track] [speed] / <-show> / <-default> / <-none>:\n"); + CONS_Printf(M_GetText("Play an arbitrary music lump. If a map number is used, 'MAP##M' is played.\n")); + CONS_Printf(M_GetText("If the format supports multiple songs, you can specify which one to play.\n\n")); + CONS_Printf(M_GetText("* With \"-show\", shows the currently playing tune and track.\n")); + CONS_Printf(M_GetText("* With \"-default\", returns to the default music for the map.\n")); + CONS_Printf(M_GetText("* With \"-none\", any music playing will be stopped.\n")); + return; + } + + tunearg = COM_Argv(1); + tunenum = (UINT16)atoi(tunearg); + track = 0; + + if (!strcasecmp(tunearg, "-show")) + { + CONS_Printf(M_GetText("The current tune is: %s [track %d]\n"), + mapmusname, (mapmusflags & MUSIC_TRACKMASK)); + return; + } + if (!strcasecmp(tunearg, "-none")) + { + S_StopMusic(); + return; + } + else if (!strcasecmp(tunearg, "-default")) + { + tunearg = mapheaderinfo[gamemap-1]->musname; + track = mapheaderinfo[gamemap-1]->mustrack; + } + else if (!tunearg[2] && toupper(tunearg[0]) >= 'A' && toupper(tunearg[0]) <= 'Z') + tunenum = (UINT16)M_MapNumber(tunearg[0], tunearg[1]); + + if (tunenum && tunenum >= 1036) + { + CONS_Alert(CONS_NOTICE, M_GetText("Valid music slots are 1 to 1035.\n")); + return; + } + if (!tunenum && strlen(tunearg) > 6) // This is automatic -- just show the error just in case + CONS_Alert(CONS_NOTICE, M_GetText("Music name too long - truncated to six characters.\n")); + + if (argc > 2) + track = (UINT16)atoi(COM_Argv(2))-1; + + if (tunenum) + snprintf(mapmusname, 7, "%sM", G_BuildMapName(tunenum)); + else + strncpy(mapmusname, tunearg, 7); + mapmusname[6] = 0; + mapmusflags = (track & MUSIC_TRACKMASK); + + S_ChangeMusic(mapmusname, mapmusflags, true); + + if (argc > 3) + { + float speed = (float)atof(COM_Argv(3)); + if (speed > 0.0f) + S_SpeedMusic(speed); + } +} + /** Quits a game and returns to the title screen. * */ diff --git a/src/d_netcmd.h b/src/d_netcmd.h index 8632a3089..f7bb39d2d 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -154,9 +154,10 @@ typedef enum XD_DELFILE, // 18 XD_SETMOTD, // 19 XD_SUICIDE, // 20 + XD_DEMOTED, // 21 #ifdef HAVE_BLUA - XD_LUACMD, // 21 - XD_LUAVAR, // 22 + XD_LUACMD, // 22 + XD_LUAVAR, // 23 #endif MAXNETXCMD } netxcmd_t; diff --git a/src/doomstat.h b/src/doomstat.h index 08903b154..203b43190 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -477,7 +477,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 ticcmd_t netcmds[BACKUPTICS][MAXPLAYERS]; extern INT32 serverplayer; -extern INT32 adminplayers[4]; +extern INT32 adminplayers[MAXPLAYERS]; /// \note put these in d_clisrv outright? diff --git a/src/sdl/Srb2SDL-vc10.vcxproj b/src/sdl/Srb2SDL-vc10.vcxproj index 467d2829b..6c2d0a5ee 100644 --- a/src/sdl/Srb2SDL-vc10.vcxproj +++ b/src/sdl/Srb2SDL-vc10.vcxproj @@ -24,7 +24,6 @@ Win32Proj Srb2SDL 8.1 - Srb2Win