From 8c845510a46f6a28ef3f7e4c94ea426ffbd8f094 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Fri, 23 Nov 2018 00:01:16 -0500 Subject: [PATCH 01/20] Update version to 2.1.21 --- CMakeLists.txt | 2 +- appveyor.yml | 2 +- src/doomdef.h | 8 ++++---- src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj | 4 ++-- src/sdl12/macosx/Srb2mac.xcodeproj/project.pbxproj | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index eb91866f0..e927b236e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.0) project(SRB2 - VERSION 2.1.20 + VERSION 2.1.21 LANGUAGES C) if(${PROJECT_SOURCE_DIR} MATCHES ${PROJECT_BINARY_DIR}) diff --git a/appveyor.yml b/appveyor.yml index 69913cfc8..061613c4d 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,4 +1,4 @@ -version: 2.1.20.{branch}-{build} +version: 2.1.21.{branch}-{build} os: MinGW environment: diff --git a/src/doomdef.h b/src/doomdef.h index ff09144ed..e23cb264e 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -150,9 +150,9 @@ extern FILE *logstream; // we use comprevision and compbranch instead. #else #define VERSION 201 // Game version -#define SUBVERSION 20 // more precise version number -#define VERSIONSTRING "v2.1.20" -#define VERSIONSTRINGW L"v2.1.20" +#define SUBVERSION 21 // more precise version number +#define VERSIONSTRING "v2.1.21" +#define VERSIONSTRINGW L"v2.1.21" // Hey! If you change this, add 1 to the MODVERSION below! // Otherwise we can't force updates! #endif @@ -214,7 +214,7 @@ extern FILE *logstream; // it's only for detection of the version the player is using so the MS can alert them of an update. // Only set it higher, not lower, obviously. // Note that we use this to help keep internal testing in check; this is why v2.1.0 is not version "1". -#define MODVERSION 25 +#define MODVERSION 26 // ========================================================================= diff --git a/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj b/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj index eaac87deb..6eabee56b 100644 --- a/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj +++ b/src/sdl/macosx/Srb2mac.xcodeproj/project.pbxproj @@ -1214,7 +1214,7 @@ C01FCF4B08A954540054247B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - CURRENT_PROJECT_VERSION = 2.1.20; + CURRENT_PROJECT_VERSION = 2.1.21; GCC_PREPROCESSOR_DEFINITIONS = ( "$(inherited)", NORMALSRB2, @@ -1226,7 +1226,7 @@ C01FCF4C08A954540054247B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - CURRENT_PROJECT_VERSION = 2.1.20; + CURRENT_PROJECT_VERSION = 2.1.21; GCC_ENABLE_FIX_AND_CONTINUE = NO; GCC_GENERATE_DEBUGGING_SYMBOLS = NO; GCC_PREPROCESSOR_DEFINITIONS = ( diff --git a/src/sdl12/macosx/Srb2mac.xcodeproj/project.pbxproj b/src/sdl12/macosx/Srb2mac.xcodeproj/project.pbxproj index 574161c68..93f63309c 100644 --- a/src/sdl12/macosx/Srb2mac.xcodeproj/project.pbxproj +++ b/src/sdl12/macosx/Srb2mac.xcodeproj/project.pbxproj @@ -1214,7 +1214,7 @@ C01FCF4B08A954540054247B /* Debug */ = { isa = XCBuildConfiguration; buildSettings = { - CURRENT_PROJECT_VERSION = 2.1.20; + CURRENT_PROJECT_VERSION = 2.1.21; GCC_PREPROCESSOR_DEFINITIONS = ( "$(inherited)", NORMALSRB2, @@ -1226,7 +1226,7 @@ C01FCF4C08A954540054247B /* Release */ = { isa = XCBuildConfiguration; buildSettings = { - CURRENT_PROJECT_VERSION = 2.1.20; + CURRENT_PROJECT_VERSION = 2.1.21; GCC_ENABLE_FIX_AND_CONTINUE = NO; GCC_GENERATE_DEBUGGING_SYMBOLS = NO; GCC_PREPROCESSOR_DEFINITIONS = ( From cabe9871e32df7454a5c0074a10d3b3007694b1b Mon Sep 17 00:00:00 2001 From: Wolfy Date: Fri, 10 Nov 2017 23:34:37 -0600 Subject: [PATCH 02/20] Multiple admins # Conflicts: # src/d_netcmd.c # src/d_netcmd.h --- src/command.c | 4 +- src/d_clisrv.c | 32 +++++++----- src/d_clisrv.h | 4 +- src/d_netcmd.c | 117 +++++++++++++++++++++++++++++++------------ src/d_netcmd.h | 28 ++++++++++- src/dehacked.c | 6 +-- src/doomstat.h | 3 +- src/f_finale.c | 2 +- src/hu_stuff.c | 20 ++++---- src/lua_consolelib.c | 4 +- src/m_menu.c | 4 +- src/r_things.c | 4 +- 12 files changed, 157 insertions(+), 71 deletions(-) diff --git a/src/command.c b/src/command.c index f77fb5a4d..e49cc12b5 100644 --- a/src/command.c +++ b/src/command.c @@ -1220,7 +1220,7 @@ static void Got_NetVar(UINT8 **p, INT32 playernum) char *svalue; UINT8 stealth = false; - if (playernum != serverplayer && playernum != adminplayer && !serverloading) + if (playernum != serverplayer && !IsPlayerAdmin(playernum) && !serverloading) { // not from server or remote admin, must be hacked/buggy client CONS_Alert(CONS_WARNING, M_GetText("Illegal netvar command received from %s\n"), player_names[playernum]); @@ -1349,7 +1349,7 @@ static void CV_SetCVar(consvar_t *var, const char *value, boolean stealth) // send the value of the variable XBOXSTATIC UINT8 buf[128]; UINT8 *p = buf; - if (!(server || (adminplayer == consoleplayer))) + if (!(server || (IsPlayerAdmin(consoleplayer)))) { CONS_Printf(M_GetText("Only the server or admin can change: %s %s\n"), var->name, var->string); return; diff --git a/src/d_clisrv.c b/src/d_clisrv.c index f48920bbd..331872dac 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1365,15 +1365,19 @@ static boolean SV_SendServerConfig(INT32 node) netbuffer->u.servercfg.gamestate = (UINT8)gamestate; netbuffer->u.servercfg.gametype = (UINT8)gametype; netbuffer->u.servercfg.modifiedgame = (UINT8)modifiedgame; - netbuffer->u.servercfg.adminplayer = (SINT8)adminplayer; // we fill these structs with FFs so that any players not in game get sent as 0xFFFF // which is nice and easy for us to detect memset(netbuffer->u.servercfg.playerskins, 0xFF, sizeof(netbuffer->u.servercfg.playerskins)); memset(netbuffer->u.servercfg.playercolor, 0xFF, sizeof(netbuffer->u.servercfg.playercolor)); + memset(netbuffer->u.servercfg.adminplayers, -1, sizeof(netbuffer->u.servercfg.adminplayers)); + for (i = 0; i < MAXPLAYERS; i++) { + if (i < 4) + netbuffer->u.servercfg.adminplayers[i] = (SINT8)adminplayers[i]; + if (!playeringame[i]) continue; netbuffer->u.servercfg.playerskins[i] = (UINT8)players[i].skin; @@ -2042,7 +2046,7 @@ static void CL_ConnectToServer(boolean viams) G_SetGamestate(GS_WAITINGPLAYERS); wipegamestate = GS_WAITINGPLAYERS; - adminplayer = -1; + ClearAdminPlayers(); pnumnodes = 1; oldtic = I_GetTime() - 1; #ifndef NONET @@ -2421,8 +2425,10 @@ static void CL_RemovePlayer(INT32 playernum) // Reset the name sprintf(player_names[playernum], "Player %d", playernum+1); - if (playernum == adminplayer) - adminplayer = -1; // don't stay admin after you're gone + if (IsPlayerAdmin(playernum)) + { + RemoveAdminPlayer(playernum); // don't stay admin after you're gone + } if (playernum == displayplayer) displayplayer = consoleplayer; // don't look through someone's view who isn't there @@ -2540,7 +2546,7 @@ static void Command_Nodes(void) if (I_GetNodeAddress && (address = I_GetNodeAddress(playernode[i])) != NULL) CONS_Printf(" - %s", address); - if (i == adminplayer) + if (IsPlayerAdmin(i)) CONS_Printf(M_GetText(" (verified admin)")); if (players[i].spectator) @@ -2565,7 +2571,7 @@ static void Command_Ban(void) return; } - if (server || adminplayer == consoleplayer) + if (server || IsPlayerAdmin(consoleplayer)) { XBOXSTATIC UINT8 buf[3 + MAX_REASONLENGTH]; UINT8 *p = buf; @@ -2631,7 +2637,7 @@ static void Command_Kick(void) return; } - if (server || adminplayer == consoleplayer) + if (server || IsPlayerAdmin(consoleplayer)) { XBOXSTATIC UINT8 buf[3 + MAX_REASONLENGTH]; UINT8 *p = buf; @@ -2688,7 +2694,7 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) pnum = READUINT8(*p); msg = READUINT8(*p); - if (pnum == serverplayer && playernum == adminplayer) + if (pnum == serverplayer && IsPlayerAdmin(playernum)) { CONS_Printf(M_GetText("Server is being shut down remotely. Goodbye!\n")); @@ -2699,7 +2705,7 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum) } // Is playernum authorized to make this kick? - if (playernum != serverplayer && playernum != adminplayer + if (playernum != serverplayer && !IsPlayerAdmin(playernum) && !(playerpernode[playernode[playernum]] == 2 && nodetoplayer2[playernode[playernum]] == pnum)) { @@ -3036,7 +3042,7 @@ void D_QuitNetGame(void) } D_CloseConnection(); - adminplayer = -1; + ClearAdminPlayers(); DEBFILE("===========================================================================\n" " Log finish\n" @@ -3067,7 +3073,7 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum) INT16 node, newplayernum; boolean splitscreenplayer; - if (playernum != serverplayer && playernum != adminplayer) + if (playernum != serverplayer && !IsPlayerAdmin(playernum)) { // protect against hacked/buggy client CONS_Alert(CONS_WARNING, M_GetText("Illegal add player command received from %s\n"), player_names[playernum]); @@ -3592,7 +3598,9 @@ 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; - adminplayer = netbuffer->u.servercfg.adminplayer; + for (j = 0; j < 4; 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 e7f1e8433..b2d91075c 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -282,7 +282,7 @@ typedef struct UINT8 gametype; UINT8 modifiedgame; - SINT8 adminplayer; // Needs to be signed + SINT8 adminplayers[4]; // 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 adminplayer; + SINT8 adminplayers[4]; tic_t time; tic_t leveltime; char servername[MAXSERVERNAME]; diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 3a7c54996..4d4852cb3 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -317,6 +317,7 @@ consvar_t cv_overtime = {"overtime", "Yes", CV_NETVAR, CV_YesNo, NULL, 0, NULL, consvar_t cv_rollingdemos = {"rollingdemos", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_timetic = {"timerres", "Normal", CV_SAVE, timetic_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; // use tics in display +consvar_t cv_resetmusic = {"resetmusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; static CV_PossibleValue_t pointlimit_cons_t[] = {{0, "MIN"}, {999999990, "MAX"}, {0, NULL}}; consvar_t cv_pointlimit = {"pointlimit", "0", CV_NETVAR|CV_CALL|CV_NOINIT, pointlimit_cons_t, @@ -365,7 +366,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 adminplayer = -1; +INT32 adminplayers[] = { -1, -1, -1, -1 }; // Hardcoded to four admins for now. /// \warning Keep this up-to-date if you add/remove/rename net text commands const char *netxcmdnames[MAXNETXCMD - 1] = @@ -665,6 +666,8 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_ghost_guest); COM_AddCommand("displayplayer", Command_Displayplayer_f); + COM_AddCommand("tunes", Command_Tunes_f); + CV_RegisterVar(&cv_resetmusic); // FIXME: not to be here.. but needs be done for config loading CV_RegisterVar(&cv_usegamma); @@ -1005,7 +1008,7 @@ UINT8 CanChangeSkin(INT32 playernum) return true; // Force skin in effect. - if (client && (cv_forceskin.value != -1) && !(adminplayer == playernum && serverplayer == -1)) + if (client && (cv_forceskin.value != -1) && !(IsPlayerAdmin(playernum) && serverplayer == -1)) return false; // Can change skin in intermission and whatnot. @@ -1156,7 +1159,7 @@ static void SendNameAndColor(void) snacpending++; // Don't change name if muted - if (cv_mute.value && !(server || adminplayer == consoleplayer)) + if (cv_mute.value && !(server || IsPlayerAdmin(consoleplayer))) CV_StealthSet(&cv_playername, player_names[consoleplayer]); else // Cleanup name if changing it CleanupPlayerName(consoleplayer, cv_playername.zstring); @@ -1563,7 +1566,7 @@ void D_MapChange(INT32 mapnum, INT32 newgametype, boolean pultmode, boolean rese mapchangepending = 0; // spawn the server if needed // reset players if there is a new one - if (!(adminplayer == consoleplayer)) + if (!IsPlayerAdmin(consoleplayer)) { if (SV_SpawnServer()) buf[0] &= ~(1<<1); @@ -1621,7 +1624,7 @@ static void Command_Map_f(void) return; } - if (client && !(adminplayer == consoleplayer)) + if (client && !IsPlayerAdmin(consoleplayer)) { CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); return; @@ -1750,7 +1753,7 @@ static void Got_Mapcmd(UINT8 **cp, INT32 playernum) INT32 resetplayer = 1, lastgametype; UINT8 skipprecutscene, FLS; - if (playernum != serverplayer && playernum != adminplayer) + if (playernum != serverplayer && !IsPlayerAdmin(playernum)) { CONS_Alert(CONS_WARNING, M_GetText("Illegal map change received from %s\n"), player_names[playernum]); if (server) @@ -1848,7 +1851,7 @@ static void Command_Pause(void) else WRITEUINT8(cp, 0); - if (cv_pause.value || server || (adminplayer == consoleplayer)) + if (cv_pause.value || server || (IsPlayerAdmin(consoleplayer))) { if (modeattacking || !(gamestate == GS_LEVEL || gamestate == GS_INTERMISSION)) { @@ -1866,7 +1869,7 @@ static void Got_Pause(UINT8 **cp, INT32 playernum) UINT8 dedicatedpause = false; const char *playername; - if (netgame && !cv_pause.value && playernum != serverplayer && playernum != adminplayer) + if (netgame && !cv_pause.value && playernum != serverplayer && !IsPlayerAdmin(playernum)) { CONS_Alert(CONS_WARNING, M_GetText("Illegal pause command received from %s\n"), player_names[playernum]); if (server) @@ -1995,7 +1998,7 @@ static void Got_RandomSeed(UINT8 **cp, INT32 playernum) */ static void Command_Clearscores_f(void) { - if (!(server || (adminplayer == consoleplayer))) + if (!(server || (IsPlayerAdmin(consoleplayer)))) return; SendNetXCmd(XD_CLEARSCORES, NULL, 1); @@ -2015,7 +2018,7 @@ static void Got_Clearscores(UINT8 **cp, INT32 playernum) INT32 i; (void)cp; - if (playernum != serverplayer && playernum != adminplayer) + if (playernum != serverplayer && !IsPlayerAdmin(playernum)) { CONS_Alert(CONS_WARNING, M_GetText("Illegal clear scores command received from %s\n"), player_names[playernum]); if (server) @@ -2236,7 +2239,7 @@ static void Command_ServerTeamChange_f(void) UINT16 usvalue; NetPacket.value.l = NetPacket.value.b = 0; - if (!(server || (adminplayer == consoleplayer))) + if (!(server || (IsPlayerAdmin(consoleplayer)))) { CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); return; @@ -2383,7 +2386,7 @@ static void Got_Teamchange(UINT8 **cp, INT32 playernum) if (NetPacket.packet.verification) // Special marker that the server sent the request { - if (playernum != serverplayer && (playernum != adminplayer)) + if (playernum != serverplayer && (!IsPlayerAdmin(playernum))) { CONS_Alert(CONS_WARNING, M_GetText("Illegal team change received from player %s\n"), player_names[playernum]); if (server) @@ -2422,7 +2425,7 @@ static void Got_Teamchange(UINT8 **cp, INT32 playernum) } else { - if (playernum != serverplayer && (playernum != adminplayer)) + if (playernum != serverplayer && (!IsPlayerAdmin(playernum))) { CONS_Alert(CONS_WARNING, M_GetText("Illegal team change received from player %s\n"), player_names[playernum]); if (server) @@ -2746,6 +2749,53 @@ static void Got_Login(UINT8 **cp, INT32 playernum) #endif } +boolean IsPlayerAdmin(INT32 playernum) +{ + INT32 i; + for (i = 0; i < 4; i++) + if (playernum == adminplayers[i]) + return true; + + return false; +} + +void SetAdminPlayer(INT32 playernum) +{ + INT32 i; + for (i = 0; i < 4; i++) + { + if (playernum == adminplayers[i]) + return; // Player is already admin + + if (adminplayers[i] == -1) + { + adminplayers[i] = playernum; // Set the player to a free spot + 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++) + adminplayers[i] = -1; +} + +void RemoveAdminPlayer(INT32 playernum) +{ + INT32 i; + for (i = 0; i < 4; i++) + if (playernum == adminplayers[i]) + adminplayers[i] = -1; +} + static void Command_Verify_f(void) { XBOXSTATIC char buf[8]; // Should be plenty @@ -2794,7 +2844,7 @@ static void Got_Verification(UINT8 **cp, INT32 playernum) return; } - adminplayer = num; + SetAdminPlayer(num); if (num != consoleplayer) return; @@ -2813,7 +2863,7 @@ static void Command_MotD_f(void) return; } - if (!(server || (adminplayer == consoleplayer))) + if (!(server || (IsPlayerAdmin(consoleplayer)))) { CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); return; @@ -2860,7 +2910,7 @@ static void Got_MotD_f(UINT8 **cp, INT32 playernum) if (!isprint(mymotd[i]) || mymotd[i] == ';') kick = true; - if ((playernum != serverplayer && playernum != adminplayer) || kick) + if ((playernum != serverplayer && !IsPlayerAdmin(playernum)) || kick) { CONS_Alert(CONS_WARNING, M_GetText("Illegal motd change received from %s\n"), player_names[playernum]); if (server) @@ -2897,7 +2947,7 @@ static void Command_RunSOC(void) else fn = COM_Argv(1); - if (netgame && !(server || consoleplayer == adminplayer)) + if (netgame && !(server || IsPlayerAdmin(consoleplayer))) { CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); return; @@ -2923,7 +2973,7 @@ static void Got_RunSOCcmd(UINT8 **cp, INT32 playernum) char filename[256]; filestatus_t ncs = FS_NOTFOUND; - if (playernum != serverplayer && playernum != adminplayer) + if (playernum != serverplayer && !IsPlayerAdmin(playernum)) { CONS_Alert(CONS_WARNING, M_GetText("Illegal runsoc command received from %s\n"), player_names[playernum]); if (server) @@ -2994,7 +3044,7 @@ static void Command_Addfile(void) if (!musiconly) { // ... But only so long as they contain nothing more then music and sprites. - if (netgame && !(server || adminplayer == consoleplayer)) + if (netgame && !(server || IsPlayerAdmin(consoleplayer))) { CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); return; @@ -3069,7 +3119,7 @@ static void Command_Addfile(void) WRITEMEM(buf_p, md5sum, 16); } - if (adminplayer == consoleplayer) // Request to add file + if (IsPlayerAdmin(consoleplayer)) // Request to add file SendNetXCmd(XD_REQADDFILE, buf, buf_p - buf); else SendNetXCmd(XD_ADDFILE, buf, buf_p - buf); @@ -3118,7 +3168,7 @@ static void Got_RequestAddfilecmd(UINT8 **cp, INT32 playernum) UINT8 md5sum[16]; boolean kick = false; boolean toomany = false; - INT32 i; + INT32 i,j; size_t packetsize = 0; serverinfo_pak *dummycheck = NULL; @@ -3137,7 +3187,7 @@ static void Got_RequestAddfilecmd(UINT8 **cp, INT32 playernum) if (!isprint(filename[i]) || filename[i] == ';') kick = true; - if ((playernum != serverplayer && playernum != adminplayer) || kick) + if ((playernum != serverplayer && !IsPlayerAdmin(playernum)) || kick) { XBOXSTATIC UINT8 buf[2]; @@ -3176,8 +3226,9 @@ static void Got_RequestAddfilecmd(UINT8 **cp, INT32 playernum) CONS_Printf("%s",message); - if (adminplayer) - COM_BufAddText(va("sayto %d %s", adminplayer, message)); + for (j = 0; j < 4; j++) + if (adminplayers[j]) + COM_BufAddText(va("sayto %d %s", adminplayers[j], message)); return; } @@ -3571,7 +3622,7 @@ void D_GameTypeChanged(INT32 lastgametype) if (playeringame[i]) players[i].ctfteam = 0; - if (server || (adminplayer == consoleplayer)) + if (server || (IsPlayerAdmin(consoleplayer))) { CV_StealthSetValue(&cv_teamscramble, 0); teamscramble = 0; @@ -3654,7 +3705,7 @@ static void TeamScramble_OnChange(void) if (!cv_teamscramble.value) teamscramble = 0; - if (!G_GametypeHasTeams() && (server || consoleplayer == adminplayer)) + if (!G_GametypeHasTeams() && (server || IsPlayerAdmin(consoleplayer))) { CONS_Alert(CONS_NOTICE, M_GetText("This command cannot be used in this gametype.\n")); CV_StealthSetValue(&cv_teamscramble, 0); @@ -3833,7 +3884,7 @@ static void Command_ExitLevel_f(void) { if (!(netgame || (multiplayer && gametype != GT_COOP)) && !cv_debug) CONS_Printf(M_GetText("This only works in a netgame.\n")); - else if (!(server || (adminplayer == consoleplayer))) + else if (!(server || (IsPlayerAdmin(consoleplayer)))) CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); else if (gamestate != GS_LEVEL || demoplayback) CONS_Printf(M_GetText("You must be in a level to use this.\n")); @@ -3849,7 +3900,7 @@ static void Got_ExitLevelcmd(UINT8 **cp, INT32 playernum) if (gameaction == ga_completed) return; - if (playernum != serverplayer && playernum != adminplayer) + if (playernum != serverplayer && !IsPlayerAdmin(playernum)) { CONS_Alert(CONS_WARNING, M_GetText("Illegal exitlevel command received from %s\n"), player_names[playernum]); if (server) @@ -3954,7 +4005,7 @@ static void Command_Cheats_f(void) { if (COM_CheckParm("off")) { - if (!(server || (adminplayer == consoleplayer))) + if (!(server || (IsPlayerAdmin(consoleplayer)))) CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); else CV_ResetCheatNetVars(); @@ -3964,7 +4015,7 @@ static void Command_Cheats_f(void) if (CV_CheatsEnabled()) { CONS_Printf(M_GetText("At least one CHEAT-marked variable has been changed -- Cheats are enabled.\n")); - if (server || (adminplayer == consoleplayer)) + if (server || (IsPlayerAdmin(consoleplayer))) CONS_Printf(M_GetText("Type CHEATS OFF to reset all cheat variables to default.\n")); } else @@ -4033,7 +4084,7 @@ static void Command_Archivetest_f(void) */ static void ForceSkin_OnChange(void) { - if ((server || adminplayer == consoleplayer) && (cv_forceskin.value < -1 || cv_forceskin.value >= numskins)) + if ((server || IsPlayerAdmin(consoleplayer)) && (cv_forceskin.value < -1 || cv_forceskin.value >= numskins)) { if (cv_forceskin.value == -2) CV_SetValue(&cv_forceskin, numskins-1); @@ -4063,7 +4114,7 @@ static void ForceSkin_OnChange(void) //Allows the player's name to be changed if cv_mute is off. static void Name_OnChange(void) { - if (cv_mute.value && !(server || adminplayer == consoleplayer)) + if (cv_mute.value && !(server || IsPlayerAdmin(consoleplayer))) { CONS_Alert(CONS_NOTICE, M_GetText("You may not change your name when chat is muted.\n")); CV_StealthSet(&cv_playername, player_names[consoleplayer]); @@ -4186,7 +4237,7 @@ static void Color2_OnChange(void) */ static void Mute_OnChange(void) { - if (server || (adminplayer == consoleplayer)) + if (server || (IsPlayerAdmin(consoleplayer))) return; if (cv_mute.value) diff --git a/src/d_netcmd.h b/src/d_netcmd.h index d0bac3d5e..8632a3089 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -38,6 +38,7 @@ extern consvar_t cv_joyport2; #endif extern consvar_t cv_joyscale; extern consvar_t cv_joyscale2; +extern consvar_t cv_controlperkey; // splitscreen with second mouse extern consvar_t cv_mouse2port; @@ -45,6 +46,11 @@ extern consvar_t cv_usemouse2; #if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) extern consvar_t cv_mouse2opt; #endif +extern consvar_t cv_invertmouse2; +extern consvar_t cv_alwaysfreelook2; +extern consvar_t cv_mousemove2; +extern consvar_t cv_mousesens2; +extern consvar_t cv_mouseysens2; // normally in p_mobj but the .h is not read extern consvar_t cv_itemrespawntime; @@ -70,6 +76,9 @@ extern consvar_t cv_autobalance; extern consvar_t cv_teamscramble; extern consvar_t cv_scrambleonchange; +extern consvar_t cv_useranalog, cv_useranalog2; +extern consvar_t cv_analog, cv_analog2; + extern consvar_t cv_netstat; #ifdef WALLSPLATS extern consvar_t cv_splats; @@ -99,6 +108,8 @@ extern consvar_t cv_startinglives; // for F_finale.c extern consvar_t cv_rollingdemos; +extern consvar_t cv_resetmusic; + extern consvar_t cv_ringslinger, cv_soundtest; extern consvar_t cv_specialrings, cv_powerstones, cv_matchboxes, cv_competitionboxes; @@ -109,7 +120,17 @@ extern consvar_t cv_maxping; extern consvar_t cv_skipmapcheck; -extern consvar_t cv_sleep; +extern consvar_t cv_sleep, cv_screenshot_option, cv_screenshot_folder; + +extern consvar_t cv_moviemode; + +extern consvar_t cv_zlib_level, cv_zlib_memory, cv_zlib_strategy; + +extern consvar_t cv_zlib_window_bits, cv_zlib_levela, cv_zlib_memorya; + +extern consvar_t cv_zlib_strategya, cv_zlib_window_bitsa; + +extern consvar_t cv_apng_delay; typedef enum { @@ -190,6 +211,11 @@ void Command_ExitGame_f(void); void Command_Retry_f(void); void D_GameTypeChanged(INT32 lastgametype); // not a real _OnChange function anymore void D_MapChange(INT32 pmapnum, INT32 pgametype, boolean pultmode, boolean presetplayers, INT32 pdelay, boolean pskipprecutscene, boolean pfromlevelselect); +void ObjectPlace_OnChange(void); +boolean IsPlayerAdmin(INT32 playernum); +void SetAdminPlayer(INT32 playernum); +void ClearAdminPlayers(void); +void RemoveAdminPlayer(INT32 playernum); void ItemFinder_OnChange(void); void D_SetPassword(const char *pw); diff --git a/src/dehacked.c b/src/dehacked.c index 632ddd4ac..2d0176421 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -8270,9 +8270,9 @@ static inline int lib_getenum(lua_State *L) LUA_PushUserdata(L, &players[serverplayer], META_PLAYER); return 1; } else if (fastcmp(word,"admin")) { - if (!playeringame[adminplayer] || adminplayer == serverplayer) - return 0; - LUA_PushUserdata(L, &players[adminplayer], META_PLAYER); + //if (!playeringame[adminplayer] || IsPlayerAdmin(serverplayer)) + //return 0; + //LUA_PushUserdata(L, &players[adminplayer], META_PLAYER); return 1; } else if (fastcmp(word,"emeralds")) { lua_pushinteger(L, emeralds); diff --git a/src/doomstat.h b/src/doomstat.h index 53db6eb25..08903b154 100644 --- a/src/doomstat.h +++ b/src/doomstat.h @@ -476,7 +476,8 @@ extern consvar_t cv_timetic; // display high resolution timer 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 adminplayer, serverplayer; +extern INT32 serverplayer; +extern INT32 adminplayers[4]; /// \note put these in d_clisrv outright? diff --git a/src/f_finale.c b/src/f_finale.c index a50e4a5be..387e8fdd7 100644 --- a/src/f_finale.c +++ b/src/f_finale.c @@ -1848,7 +1848,7 @@ void F_CutsceneTicker(void) for (i = 0; i < MAXPLAYERS; i++) { - if (netgame && i != serverplayer && i != adminplayer) + if (netgame && i != serverplayer && !IsPlayerAdmin(i)) continue; if (players[i].cmd.buttons & BT_USE) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index 646bdcbad..482035b81 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -347,14 +347,14 @@ static void DoSayCommand(SINT8 target, size_t usedargs, UINT8 flags) numwords = COM_Argc() - usedargs; I_Assert(numwords > 0); - if (cv_mute.value && !(server || adminplayer == consoleplayer)) + if (cv_mute.value && !(server || IsPlayerAdmin(consoleplayer))) { CONS_Alert(CONS_NOTICE, M_GetText("The chat is muted. You can't say anything at the moment.\n")); return; } // Only servers/admins can CSAY. - if(!server && adminplayer != consoleplayer) + if(!server && IsPlayerAdmin(consoleplayer)) flags &= ~HU_CSAY; // We handle HU_SERVER_SAY, not the caller. @@ -448,7 +448,7 @@ static void Command_CSay_f(void) return; } - if(!server && adminplayer != consoleplayer) + if(!server && !IsPlayerAdmin(consoleplayer)) { CONS_Alert(CONS_NOTICE, M_GetText("Only servers and admins can use csay.\n")); return; @@ -477,7 +477,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) msg = (char *)*p; SKIPSTRING(*p); - if ((cv_mute.value || flags & (HU_CSAY|HU_SERVER_SAY)) && playernum != serverplayer && playernum != adminplayer) + if ((cv_mute.value || flags & (HU_CSAY|HU_SERVER_SAY)) && playernum != serverplayer && !IsPlayerAdmin(playernum)) { CONS_Alert(CONS_WARNING, cv_mute.value ? M_GetText("Illegal say command received from %s while muted\n") : M_GetText("Illegal csay command received from non-admin %s\n"), @@ -575,7 +575,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) // Give admins and remote admins their symbols. if (playernum == serverplayer) tempchar = (char *)Z_Calloc(strlen(cstart) + strlen(adminchar) + 1, PU_STATIC, NULL); - else if (playernum == adminplayer) + else if (IsPlayerAdmin(playernum)) tempchar = (char *)Z_Calloc(strlen(cstart) + strlen(remotechar) + 1, PU_STATIC, NULL); if (tempchar) { @@ -710,7 +710,7 @@ static void HU_queueChatChar(char c) } while (c); // last minute mute check - if (cv_mute.value && !(server || adminplayer == consoleplayer)) + if (cv_mute.value && !(server || IsPlayerAdmin(consoleplayer))) { CONS_Alert(CONS_NOTICE, M_GetText("The chat is muted. You can't say anything at the moment.\n")); return; @@ -768,9 +768,9 @@ boolean HU_Responder(event_t *ev) { // enter chat mode if ((ev->data1 == gamecontrol[gc_talkkey][0] || ev->data1 == gamecontrol[gc_talkkey][1]) - && netgame && (!cv_mute.value || server || (adminplayer == consoleplayer))) + && netgame && (!cv_mute.value || server || IsPlayerAdmin(consoleplayer))) { - if (cv_mute.value && !(server || adminplayer == consoleplayer)) + if (cv_mute.value && !(server || IsPlayerAdmin(consoleplayer))) return false; chat_on = true; w_chat[0] = 0; @@ -778,9 +778,9 @@ boolean HU_Responder(event_t *ev) return true; } if ((ev->data1 == gamecontrol[gc_teamkey][0] || ev->data1 == gamecontrol[gc_teamkey][1]) - && netgame && (!cv_mute.value || server || (adminplayer == consoleplayer))) + && netgame && (!cv_mute.value || server || (IsPlayerAdmin(consoleplayer)))) { - if (cv_mute.value && !(server || adminplayer == consoleplayer)) + if (cv_mute.value && !(server || IsPlayerAdmin(consoleplayer))) return false; chat_on = true; w_chat[0] = 0; diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index 3239b7c5e..72105f04c 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -55,7 +55,7 @@ void Got_Luacmd(UINT8 **cp, INT32 playernum) lua_pop(gL, 1); // pop flags // requires server/admin and the player is not one of them - if ((flags & 1) && playernum != serverplayer && playernum != adminplayer) + if ((flags & 1) && playernum != serverplayer && !IsPlayerAdmin(playernum)) goto deny; lua_rawgeti(gL, -1, 1); // push function from command info table @@ -133,7 +133,7 @@ void COM_Lua_f(void) UINT8 argc; lua_pop(gL, 1); // pop command info table - if (flags & 1 && !server && adminplayer != playernum) // flag 1: only server/admin can use this command. + if (flags & 1 && !server && !IsPlayerAdmin(playernum)) // flag 1: only server/admin can use this command. { CONS_Printf(M_GetText("Only the server or a remote admin can use this.\n")); return; diff --git a/src/m_menu.c b/src/m_menu.c index c9adbfb9c..2bdbb2f85 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -2576,7 +2576,7 @@ void M_StartControlPanel(void) MPauseMenu[mpause_switchteam].status = IT_DISABLED; MPauseMenu[mpause_psetup].status = IT_DISABLED; - if ((server || adminplayer == consoleplayer)) + if ((server || IsPlayerAdmin(consoleplayer))) { MPauseMenu[mpause_switchmap].status = IT_STRING | IT_CALL; if (G_GametypeHasTeams()) @@ -3917,7 +3917,7 @@ static void M_Options(INT32 choice) (void)choice; // if the player is not admin or server, disable server options - OP_MainMenu[5].status = (Playing() && !(server || adminplayer == consoleplayer)) ? (IT_GRAYEDOUT) : (IT_STRING|IT_SUBMENU); + OP_MainMenu[5].status = (Playing() && !(server || IsPlayerAdmin(consoleplayer))) ? (IT_GRAYEDOUT) : (IT_STRING|IT_SUBMENU); // if the player is playing _at all_, disable the erase data options OP_DataOptionsMenu[1].status = (Playing()) ? (IT_GRAYEDOUT) : (IT_STRING|IT_SUBMENU); diff --git a/src/r_things.c b/src/r_things.c index ee2d8a9bf..a3bfb7aa9 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -2441,7 +2441,7 @@ void SetPlayerSkin(INT32 playernum, const char *skinname) if (P_IsLocalPlayer(player)) CONS_Alert(CONS_WARNING, M_GetText("Skin '%s' not found.\n"), skinname); - else if(server || adminplayer == consoleplayer) + else if(server || IsPlayerAdmin(consoleplayer)) CONS_Alert(CONS_WARNING, M_GetText("Player %d (%s) skin '%s' not found\n"), playernum, player_names[playernum], skinname); SetPlayerSkinByNum(playernum, 0); @@ -2499,7 +2499,7 @@ void SetPlayerSkinByNum(INT32 playernum, INT32 skinnum) if (P_IsLocalPlayer(player)) CONS_Alert(CONS_WARNING, M_GetText("Skin %d not found\n"), skinnum); - else if(server || adminplayer == consoleplayer) + else if(server || IsPlayerAdmin(consoleplayer)) CONS_Alert(CONS_WARNING, "Player %d (%s) skin %d not found\n", playernum, player_names[playernum], skinnum); SetPlayerSkinByNum(playernum, 0); // not found put the sonic skin } From 42fc67a639f0bff9779f90f6f3de111b1c227146 Mon Sep 17 00:00:00 2001 From: Wolfy Date: Thu, 7 Dec 2017 22:45:39 -0600 Subject: [PATCH 03/20] 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 From a71644f2308f29a9879df08dc489eafda93068ce Mon Sep 17 00:00:00 2001 From: TehRealSalt Date: Wed, 7 Nov 2018 18:07:34 -0500 Subject: [PATCH 04/20] IsPlayerAdmin support, since admin was removed # Conflicts: # src/lua_baselib.c --- src/dehacked.c | 8 ++++---- src/lua_baselib.c | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/dehacked.c b/src/dehacked.c index 2d0176421..094329668 100644 --- a/src/dehacked.c +++ b/src/dehacked.c @@ -8269,10 +8269,10 @@ static inline int lib_getenum(lua_State *L) return 0; LUA_PushUserdata(L, &players[serverplayer], META_PLAYER); return 1; - } else if (fastcmp(word,"admin")) { - //if (!playeringame[adminplayer] || IsPlayerAdmin(serverplayer)) - //return 0; - //LUA_PushUserdata(L, &players[adminplayer], META_PLAYER); + } else if (fastcmp(word,"admin")) { // BACKWARDS COMPATIBILITY HACK: This was replaced with IsPlayerAdmin(), but some 2.1 Lua scripts still use the admin variable. It now points to the first admin player in the array. + if (!playeringame[adminplayers[0]] || IsPlayerAdmin(serverplayer)) + return 0; + LUA_PushUserdata(L, &players[adminplayers[0]], META_PLAYER); return 1; } else if (fastcmp(word,"emeralds")) { lua_pushinteger(L, emeralds); diff --git a/src/lua_baselib.c b/src/lua_baselib.c index e8e8fd020..892974bdc 100644 --- a/src/lua_baselib.c +++ b/src/lua_baselib.c @@ -20,6 +20,9 @@ #include "m_random.h" #include "s_sound.h" #include "g_game.h" +#include "hu_stuff.h" +#include "console.h" +#include "d_netcmd.h" // IsPlayerAdmin #include "lua_script.h" #include "lua_libs.h" @@ -93,6 +96,16 @@ static int lib_evalMath(lua_State *L) return 1; } +static int lib_isPlayerAdmin(lua_State *L) +{ + player_t *player = *((player_t **)luaL_checkudata(L, 1, META_PLAYER)); + //HUDSAFE + if (!player) + return LUA_ErrInvalid(L, "player_t"); + lua_pushboolean(L, IsPlayerAdmin(player-players)); + return 1; +} + // M_RANDOM ////////////// @@ -1983,6 +1996,7 @@ static int lib_gTicsToMilliseconds(lua_State *L) static luaL_Reg lib[] = { {"print", lib_print}, {"EvalMath", lib_evalMath}, + {"IsPlayerAdmin", lib_isPlayerAdmin}, // m_random {"P_RandomFixed",lib_pRandomFixed}, From 66dde279b3c0928607988da48c004c87abacc8f5 Mon Sep 17 00:00:00 2001 From: wolfy852 Date: Thu, 29 Nov 2018 07:15:54 -0600 Subject: [PATCH 05/20] Fix a quick merge mistake. --- src/sdl/Srb2SDL-vc10.vcxproj | 1 + 1 file changed, 1 insertion(+) diff --git a/src/sdl/Srb2SDL-vc10.vcxproj b/src/sdl/Srb2SDL-vc10.vcxproj index 6c2d0a5ee..467d2829b 100644 --- a/src/sdl/Srb2SDL-vc10.vcxproj +++ b/src/sdl/Srb2SDL-vc10.vcxproj @@ -24,6 +24,7 @@ Win32Proj Srb2SDL 8.1 + Srb2Win From beb58c55aca1e3e9ac7356dde9ad242b9fd78a61 Mon Sep 17 00:00:00 2001 From: wolfy852 Date: Thu, 29 Nov 2018 07:30:06 -0600 Subject: [PATCH 06/20] I must be some kind of idiot. --- src/d_netcmd.c | 84 +++----------------------------------------------- src/d_netcmd.h | 24 +-------------- 2 files changed, 5 insertions(+), 103 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 092cfe4f1..4eff0325e 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -128,7 +128,6 @@ 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); @@ -320,8 +319,6 @@ consvar_t cv_overtime = {"overtime", "Yes", CV_NETVAR, CV_YesNo, NULL, 0, NULL, consvar_t cv_rollingdemos = {"rollingdemos", "On", CV_SAVE, CV_OnOff, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_timetic = {"timerres", "Normal", CV_SAVE, timetic_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; // use tics in display -consvar_t cv_resetmusic = {"resetmusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; - static CV_PossibleValue_t pointlimit_cons_t[] = {{0, "MIN"}, {999999990, "MAX"}, {0, NULL}}; consvar_t cv_pointlimit = {"pointlimit", "0", CV_NETVAR|CV_CALL|CV_NOINIT, pointlimit_cons_t, PointLimit_OnChange, 0, NULL, NULL, 0, 0, NULL}; @@ -585,7 +582,6 @@ void D_RegisterServerCommands(void) */ void D_RegisterClientCommands(void) { - const char *username; INT32 i; for (i = 0; i < MAXSKINCOLORS; i++) @@ -642,8 +638,6 @@ 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) @@ -674,8 +668,6 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_ghost_guest); COM_AddCommand("displayplayer", Command_Displayplayer_f); - COM_AddCommand("tunes", Command_Tunes_f); - CV_RegisterVar(&cv_resetmusic); // FIXME: not to be here.. but needs be done for config loading CV_RegisterVar(&cv_usegamma); @@ -1374,9 +1366,9 @@ void SendWeaponPref(void) XBOXSTATIC UINT8 buf[1]; buf[0] = 0; - if (players[consoleplayer].pflags & PF_FLIPCAM) + if (cv_flipcam.value) buf[0] |= 1; - if (players[consoleplayer].pflags & PF_ANALOGMODE) + if (cv_analog.value) buf[0] |= 2; SendNetXCmd(XD_WEAPONPREF, buf, 1); } @@ -1386,9 +1378,9 @@ void SendWeaponPref2(void) XBOXSTATIC UINT8 buf[1]; buf[0] = 0; - if (players[secondarydisplayplayer].pflags & PF_FLIPCAM) + if (cv_flipcam2.value) buf[0] |= 1; - if (players[secondarydisplayplayer].pflags & PF_ANALOGMODE) + if (cv_analog2.value) buf[0] |= 2; SendNetXCmd2(XD_WEAPONPREF, buf, 1); } @@ -3986,74 +3978,6 @@ 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 f7bb39d2d..e29a1d9f4 100644 --- a/src/d_netcmd.h +++ b/src/d_netcmd.h @@ -38,7 +38,6 @@ extern consvar_t cv_joyport2; #endif extern consvar_t cv_joyscale; extern consvar_t cv_joyscale2; -extern consvar_t cv_controlperkey; // splitscreen with second mouse extern consvar_t cv_mouse2port; @@ -46,11 +45,6 @@ extern consvar_t cv_usemouse2; #if (defined (__unix__) && !defined (MSDOS)) || defined (UNIXCOMMON) extern consvar_t cv_mouse2opt; #endif -extern consvar_t cv_invertmouse2; -extern consvar_t cv_alwaysfreelook2; -extern consvar_t cv_mousemove2; -extern consvar_t cv_mousesens2; -extern consvar_t cv_mouseysens2; // normally in p_mobj but the .h is not read extern consvar_t cv_itemrespawntime; @@ -76,9 +70,6 @@ extern consvar_t cv_autobalance; extern consvar_t cv_teamscramble; extern consvar_t cv_scrambleonchange; -extern consvar_t cv_useranalog, cv_useranalog2; -extern consvar_t cv_analog, cv_analog2; - extern consvar_t cv_netstat; #ifdef WALLSPLATS extern consvar_t cv_splats; @@ -108,8 +99,6 @@ extern consvar_t cv_startinglives; // for F_finale.c extern consvar_t cv_rollingdemos; -extern consvar_t cv_resetmusic; - extern consvar_t cv_ringslinger, cv_soundtest; extern consvar_t cv_specialrings, cv_powerstones, cv_matchboxes, cv_competitionboxes; @@ -120,17 +109,7 @@ extern consvar_t cv_maxping; extern consvar_t cv_skipmapcheck; -extern consvar_t cv_sleep, cv_screenshot_option, cv_screenshot_folder; - -extern consvar_t cv_moviemode; - -extern consvar_t cv_zlib_level, cv_zlib_memory, cv_zlib_strategy; - -extern consvar_t cv_zlib_window_bits, cv_zlib_levela, cv_zlib_memorya; - -extern consvar_t cv_zlib_strategya, cv_zlib_window_bitsa; - -extern consvar_t cv_apng_delay; +extern consvar_t cv_sleep; typedef enum { @@ -212,7 +191,6 @@ void Command_ExitGame_f(void); void Command_Retry_f(void); void D_GameTypeChanged(INT32 lastgametype); // not a real _OnChange function anymore void D_MapChange(INT32 pmapnum, INT32 pgametype, boolean pultmode, boolean presetplayers, INT32 pdelay, boolean pskipprecutscene, boolean pfromlevelselect); -void ObjectPlace_OnChange(void); boolean IsPlayerAdmin(INT32 playernum); void SetAdminPlayer(INT32 playernum); void ClearAdminPlayers(void); From 08d3587eac29bc297d8c5fef436ac74e49ec4824 Mon Sep 17 00:00:00 2001 From: wolfy852 Date: Sun, 2 Dec 2018 08:57:35 -0600 Subject: [PATCH 07/20] Fix a dumb mistake --- src/d_clisrv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 4529aa65e..708416594 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -321,7 +321,7 @@ typedef struct UINT8 cheatsenabled; UINT8 isdedicated; UINT8 fileneedednum; - SINT8 adminplayers[MAXPLAYERS]; + SINT8 adminplayers; tic_t time; tic_t leveltime; char servername[MAXSERVERNAME]; From fb8b5fe749059271727e156671f49a11741d15f2 Mon Sep 17 00:00:00 2001 From: wolfy852 Date: Sun, 2 Dec 2018 09:08:05 -0600 Subject: [PATCH 08/20] s --- src/d_clisrv.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.h b/src/d_clisrv.h index 708416594..b615c04c2 100644 --- a/src/d_clisrv.h +++ b/src/d_clisrv.h @@ -321,7 +321,7 @@ typedef struct UINT8 cheatsenabled; UINT8 isdedicated; UINT8 fileneedednum; - SINT8 adminplayers; + SINT8 adminplayer; tic_t time; tic_t leveltime; char servername[MAXSERVERNAME]; From 05a8bbe056c6c35506900f1c68a19c5037e88e96 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 4 Dec 2018 18:54:36 +0000 Subject: [PATCH 09/20] Fix the game being basically broken due to multi-admin, by porting over some missing changes from Kart --- src/d_clisrv.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 5ab067b6c..918b11d95 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2981,6 +2981,7 @@ void SV_ResetServer(void) playeringame[i] = false; playernode[i] = UINT8_MAX; sprintf(player_names[i], "Player %d", i + 1); + adminplayers[i] = -1; // Populate the entire adminplayers array with -1. } mynode = 0; @@ -3288,10 +3289,6 @@ 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) From c642015b81154ea2a6c1aeb4232343de00ba8e2a Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Tue, 4 Dec 2018 21:09:28 +0000 Subject: [PATCH 10/20] Fix motd being broken for admins It turns out the game was sending the full size of the motd buffer (254) rather than just the size of the string made, therefore sending a load of garbage and making the game apparently execute unknown or illegal net commands --- src/d_netcmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index c8e33a57b..290183e28 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -2965,7 +2965,7 @@ static void Command_MotD_f(void) } if ((netgame || multiplayer) && client) - SendNetXCmd(XD_SETMOTD, mymotd, sizeof(motd)); + SendNetXCmd(XD_SETMOTD, mymotd, i); // send the actual size of the motd string, not the full buffer's size else { strcpy(motd, mymotd); From b03da283903f36372b871ad3be53c4c85b44631f Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 5 Dec 2018 11:43:33 -0500 Subject: [PATCH 11/20] Add various flags to version string --- src/d_netcmd.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 62 insertions(+), 2 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 290183e28..736e10f32 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3421,10 +3421,70 @@ static void Command_ListWADS_f(void) static void Command_Version_f(void) { #ifdef DEVELOP - CONS_Printf("Sonic Robo Blast 2 %s-%s (%s %s)\n", compbranch, comprevision, compdate, comptime); + CONS_Printf("Sonic Robo Blast 2 %s-%s (%s %s) ", compbranch, comprevision, compdate, comptime); #else - CONS_Printf("Sonic Robo Blast 2 %s (%s %s %s)\n", VERSIONSTRING, compdate, comptime, comprevision); + CONS_Printf("Sonic Robo Blast 2 %s (%s %s %s) ", VERSIONSTRING, compdate, comptime, comprevision); #endif + + // Base library +#ifdef HAVE_SDL + CONS_Printf("SDL "); +#else +#ifdef _WIN32 + CONS_Printf("DD "); +#endif +#endif + + // OS + // Would be nice to use SDL_GetPlatform for this +#ifdef _WIN32 + CONS_Printf("Windows "); +#else +#ifdef LINUX + CONS_Printf("Linux "); +#else +#ifdef MACOSX + CONS_Printf("macOS" ); +#else +#ifdef UNIXCOMMON + CONS_Printf("Unix (Common) "); +#else + CONS_Printf("Other OS "); +#endif +#endif +#endif +#endif + + // Bitness +#ifdef _WIN64 + CONS_Printf("x64 "); +#else +#ifdef _WIN32 + CONS_Printf("x86 "); +#else +#ifdef NONX86 + CONS_Printf("Non-x86 "); +#else +#ifdef LINUX + CONS_Printf("x86 "); +#else + CONS_Printf("Bits Unknown "); +#endif +#endif +#endif +#endif + + // No ASM? +#ifdef NOASM + CONS_Printf("\205NOASM \200"); +#endif + + // Debug build +#ifdef _DEBUG + CONS_Printf("\205DEBUG \200"); +#endif + + CONS_Printf("\n"); } #ifdef UPDATE_ALERT From f5e6db5f5691f6808531ee4c2d062204c0627200 Mon Sep 17 00:00:00 2001 From: Monster Iestyn Date: Wed, 5 Dec 2018 17:39:02 +0000 Subject: [PATCH 12/20] Fix 64-bit build-using admins not being able to kick players besides themselves, by not checking sendingsavegame[] code at all if not the server it turns out playernode[pn] is typically 255 in the above situation, so sendingsavegame[playernode[pn]] goes out of bounds ...but goodness knows why 32-bit builds didn't suffer the same bug, seems to have been pure luck --- src/d_clisrv.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 918b11d95..cd8367af8 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -2650,13 +2650,16 @@ static void Command_Kick(void) if (pn == -1 || pn == 0) return; - // Special case if we are trying to kick a player who is downloading the game state: - // trigger a timeout instead of kicking them, because a kick would only - // take effect after they have finished downloading - if (sendingsavegame[playernode[pn]]) + if (server) { - Net_ConnectionTimeout(playernode[pn]); - return; + // Special case if we are trying to kick a player who is downloading the game state: + // trigger a timeout instead of kicking them, because a kick would only + // take effect after they have finished downloading + if (sendingsavegame[playernode[pn]]) + { + Net_ConnectionTimeout(playernode[pn]); + return; + } } WRITESINT8(p, pn); From d576ed31e0b8124c209d76dc40a3320f1c296fdd Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 5 Dec 2018 12:55:05 -0500 Subject: [PATCH 13/20] _WINDOWS instead of _WIN32 for DD --- src/d_netcmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 736e10f32..a3604ac9e 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3430,7 +3430,7 @@ static void Command_Version_f(void) #ifdef HAVE_SDL CONS_Printf("SDL "); #else -#ifdef _WIN32 +#ifdef _WINDOWS CONS_Printf("DD "); #endif #endif From a0938bdd24e5cb94bbd043158ca592ff756bb5f7 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 5 Dec 2018 13:00:42 -0500 Subject: [PATCH 14/20] Make the ifdefs cleaner --- src/d_netcmd.c | 34 ++++++++++------------------------ 1 file changed, 10 insertions(+), 24 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index a3604ac9e..2e5db3ea3 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3427,51 +3427,37 @@ static void Command_Version_f(void) #endif // Base library -#ifdef HAVE_SDL +#if defined( HAVE_SDL) CONS_Printf("SDL "); -#else -#ifdef _WINDOWS +#elif defined(_WINDOWS) CONS_Printf("DD "); -#endif #endif // OS // Would be nice to use SDL_GetPlatform for this -#ifdef _WIN32 +#if defined(_WIN32) CONS_Printf("Windows "); -#else -#ifdef LINUX +#elif defined(LINUX) CONS_Printf("Linux "); -#else -#ifdef MACOSX +#elif defined(MACOSX) CONS_Printf("macOS" ); -#else -#ifdef UNIXCOMMON +#elif defined(UNIXCOMMON) CONS_Printf("Unix (Common) "); #else CONS_Printf("Other OS "); -#endif -#endif -#endif #endif // Bitness -#ifdef _WIN64 +#if defined(_WIN64) CONS_Printf("x64 "); -#else -#ifdef _WIN32 +#elif defined(_WIN32) CONS_Printf("x86 "); -#else -#ifdef NONX86 +#elif defined(NONX86) CONS_Printf("Non-x86 "); -#else -#ifdef LINUX +#elif defined(LINUX) CONS_Printf("x86 "); #else CONS_Printf("Bits Unknown "); -#endif -#endif -#endif #endif // No ASM? From e30832216fdc8f486307c734b1348629d420e655 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 5 Dec 2018 13:06:56 -0500 Subject: [PATCH 15/20] More concise bitness check --- src/d_netcmd.c | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 2e5db3ea3..951959311 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3448,17 +3448,12 @@ static void Command_Version_f(void) #endif // Bitness -#if defined(_WIN64) - CONS_Printf("x64 "); -#elif defined(_WIN32) - CONS_Printf("x86 "); -#elif defined(NONX86) - CONS_Printf("Non-x86 "); -#elif defined(LINUX) - CONS_Printf("x86 "); -#else - CONS_Printf("Bits Unknown "); -#endif + if (sizeof(void*) == 4) + CONS_Printf("32-bit "); + else if (sizeof(void*) == 8) + CONS_Printf("64-bit "); + else // 16-bit? 128-bit? + CONS_Printf("Bits Unknown "); // No ASM? #ifdef NOASM From 41ca8bb24af7ccba61c79a147e12901dd4edb7ae Mon Sep 17 00:00:00 2001 From: mazmazz Date: Wed, 5 Dec 2018 13:08:25 -0500 Subject: [PATCH 16/20] Hex instead of octal colors --- src/d_netcmd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 951959311..385cde3bc 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -3457,12 +3457,12 @@ static void Command_Version_f(void) // No ASM? #ifdef NOASM - CONS_Printf("\205NOASM \200"); + CONS_Printf("\x85" "NOASM " "\x80"); #endif // Debug build #ifdef _DEBUG - CONS_Printf("\205DEBUG \200"); + CONS_Printf("\x85" "DEBUG " "\x80"); #endif CONS_Printf("\n"); From 0e0ccf2ae633c1d8f3fa49e4f1a888abe55e6346 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 6 Dec 2018 05:26:28 -0500 Subject: [PATCH 17/20] Change 2p controller defaults --- src/g_game.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index be36dde08..67f482e36 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -422,7 +422,7 @@ consvar_t cv_lookaxis2 = {"joyaxis2_look", "RStick.Y", CV_SAVE, joyaxis_cons_t, consvar_t cv_fireaxis2 = {"joyaxis2_fire", "LAnalog", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_firenaxis2 = {"joyaxis2_firenormal", "RAnalog", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; #else -consvar_t cv_turnaxis2 = {"joyaxis2_turn", "X-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_turnaxis2 = {"joyaxis2_turn", "X-Rudder", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_moveaxis2 = {"joyaxis2_move", "Y-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; #ifdef _arch_dreamcast consvar_t cv_sideaxis2 = {"joyaxis2_side", "Triggers", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; @@ -432,13 +432,13 @@ consvar_t cv_lookaxis2 = {"joyaxis2_look", "Alt Y-Axis", CV_SAVE, joyaxis_cons_t #elif defined (_PSP) consvar_t cv_sideaxis2 = {"joyaxis2_side", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; #else -consvar_t cv_sideaxis2 = {"joyaxis2_side", "Z-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_sideaxis2 = {"joyaxis2_side", "X-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; #endif #ifndef _XBOX -consvar_t cv_lookaxis2 = {"joyaxis2_look", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_lookaxis2 = {"joyaxis2_look", "Y-Rudder-", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; #endif -consvar_t cv_fireaxis2 = {"joyaxis2_fire", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_firenaxis2 = {"joyaxis2_firenormal", "None", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_fireaxis2 = {"joyaxis2_fire", "Z-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_firenaxis2 = {"joyaxis2_firenormal", "Z-Axis-", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; #endif From d488dd0763d428c8fe3a62863da062b572f10373 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 6 Dec 2018 05:55:56 -0500 Subject: [PATCH 18/20] Move joyaxis_fire default to right trigger --- src/g_game.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 67f482e36..43d4d7734 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -410,8 +410,8 @@ consvar_t cv_lookaxis = {"joyaxis_look", "Y-Axis", CV_SAVE, joyaxis_cons_t, NULL consvar_t cv_lookaxis = {"joyaxis_look", "Y-Rudder-", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; #endif #endif -consvar_t cv_fireaxis = {"joyaxis_fire", "Z-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_firenaxis = {"joyaxis_firenormal", "Z-Axis-", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_fireaxis = {"joyaxis_fire", "Z-Axis-", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_firenaxis = {"joyaxis_firenormal", "Z-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; #endif #if defined (_WII) || defined (WMINPUT) @@ -437,8 +437,8 @@ consvar_t cv_sideaxis2 = {"joyaxis2_side", "X-Axis", CV_SAVE, joyaxis_cons_t, NU #ifndef _XBOX consvar_t cv_lookaxis2 = {"joyaxis2_look", "Y-Rudder-", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; #endif -consvar_t cv_fireaxis2 = {"joyaxis2_fire", "Z-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_firenaxis2 = {"joyaxis2_firenormal", "Z-Axis-", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_fireaxis2 = {"joyaxis2_fire", "Z-Axis-", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_firenaxis2 = {"joyaxis2_firenormal", "Z-Axis", CV_SAVE, joyaxis_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; #endif From 5e6e0d539b30f09915cdef114636edbcc62ad994 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 6 Dec 2018 06:50:18 -0500 Subject: [PATCH 19/20] Use proper DD define for use_joystick --- src/d_netcmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 385cde3bc..434675a75 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -242,7 +242,7 @@ INT32 cv_debug; consvar_t cv_usemouse = {"use_mouse", "On", CV_SAVE|CV_CALL,usemouse_cons_t, I_StartupMouse, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_usemouse2 = {"use_mouse2", "Off", CV_SAVE|CV_CALL,usemouse_cons_t, I_StartupMouse2, 0, NULL, NULL, 0, 0, NULL}; -#if defined (DC) || defined (_XBOX) || defined (WMINPUT) || defined (_WII) || defined(HAVE_SDL) || defined(_WIN32) //joystick 1 and 2 +#if defined (DC) || defined (_XBOX) || defined (WMINPUT) || defined (_WII) || defined(HAVE_SDL) || defined(_WINDOWS) //joystick 1 and 2 consvar_t cv_usejoystick = {"use_joystick", "1", CV_SAVE|CV_CALL, usejoystick_cons_t, I_InitJoystick, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_usejoystick2 = {"use_joystick2", "2", CV_SAVE|CV_CALL, usejoystick_cons_t, From c4f035dfa9ab1cd5f34bcbe997b5305d669c6a27 Mon Sep 17 00:00:00 2001 From: mazmazz Date: Thu, 6 Dec 2018 10:54:58 -0500 Subject: [PATCH 20/20] Controller hotplugging by always keeping joy subsystem on (thanks WOLFS) (with log messages) --- src/m_menu.c | 2 +- src/m_menu.h | 5 +- src/sdl/i_system.c | 213 ++++++++++++++++++++++----------------------- src/sdl/i_video.c | 35 ++++++++ src/sdl/sdlmain.h | 4 + 5 files changed, 148 insertions(+), 111 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 1e1b1e696..a4c62c0f3 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -6761,7 +6761,7 @@ static void M_DrawJoystick(void) } } -static void M_SetupJoystickMenu(INT32 choice) +void M_SetupJoystickMenu(INT32 choice) { INT32 i = 0; const char *joyNA = "Unavailable"; diff --git a/src/m_menu.h b/src/m_menu.h index de76a2710..3066a261c 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -69,7 +69,6 @@ void M_QuitResponse(INT32 ch); // Determines whether to show a level in the list boolean M_CanShowLevelInList(INT32 mapnum, INT32 gt); - // flags for items in the menu // menu handle (what we do when key is pressed #define IT_TYPE 14 // (2+4+8) @@ -171,6 +170,10 @@ extern menu_t *currentMenu; extern menu_t MainDef; extern menu_t SP_LoadDef; +// Call upon joystick hotplug +void M_SetupJoystickMenu(INT32 choice); +extern menu_t OP_JoystickSetDef; + // Stuff for customizing the player select screen typedef struct { diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 50c3018aa..b18ea9571 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -843,7 +843,7 @@ static UINT64 lastjoyhats = 0; */ -static void I_ShutdownJoystick(void) +void I_ShutdownJoystick(void) { INT32 i; event_t event; @@ -877,14 +877,8 @@ static void I_ShutdownJoystick(void) joystick_started = 0; JoyReset(&JoyInfo); - if (!joystick_started && !joystick2_started && SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK) - { - SDL_QuitSubSystem(SDL_INIT_JOYSTICK); - if (cv_usejoystick.value == 0) - { - I_OutputMsg("I_Joystick: SDL's Joystick system has been shutdown\n"); - } - } + + // don't shut down the subsystem here, because hotplugging } void I_GetJoystickEvents(void) @@ -1031,37 +1025,20 @@ static int joy_open(const char *fname) int num_joy = 0; int i; - if (joystick_started == 0 && joystick2_started == 0) + if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) { - if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) - { - CONS_Printf(M_GetText("Couldn't initialize joystick: %s\n"), SDL_GetError()); - return -1; - } - else - { - num_joy = SDL_NumJoysticks(); - } + CONS_Printf(M_GetText("Joystick subsystem not started\n")); + return -1; + } - if (num_joy < joyindex) - { - CONS_Printf(M_GetText("Cannot use joystick #%d/(%s), it doesn't exist\n"),joyindex,fname); - for (i = 0; i < num_joy; i++) - CONS_Printf("#%d/(%s)\n", i+1, SDL_JoystickNameForIndex(i)); - I_ShutdownJoystick(); - return -1; - } - } - else - { - JoyReset(&JoyInfo); - //I_ShutdownJoystick(); - //joy_open(fname); - } + JoyReset(&JoyInfo); + + if (joyindex <= 0) + return 0; num_joy = SDL_NumJoysticks(); - if (joyindex <= 0 || num_joy == 0 || JoyInfo.oldjoy == joyindex) + if (num_joy == 0 || JoyInfo.oldjoy == joyindex) { // I_OutputMsg("Unable to use that joystick #(%s), non-number\n",fname); if (num_joy != 0) @@ -1069,10 +1046,20 @@ static int joy_open(const char *fname) CONS_Printf(M_GetText("Found %d joysticks on this system\n"), num_joy); for (i = 0; i < num_joy; i++) CONS_Printf("#%d/(%s)\n", i+1, SDL_JoystickNameForIndex(i)); + + if (num_joy < joyindex) + { + CONS_Printf(M_GetText("Cannot use joystick #%d/(%s), it doesn't exist\n"),joyindex,fname); + for (i = 0; i < num_joy; i++) + CONS_Printf("#%d/(%s)\n", i+1, SDL_JoystickNameForIndex(i)); + return 0; + } } else + { CONS_Printf("%s", M_GetText("Found no joysticks on this system\n")); - if (joyindex <= 0 || num_joy == 0) return 0; + return 0; + } } JoyInfo.dev = SDL_JoystickOpen(joyindex-1); @@ -1080,7 +1067,6 @@ static int joy_open(const char *fname) if (JoyInfo.dev == NULL) { CONS_Printf(M_GetText("Couldn't open joystick: %s\n"), SDL_GetError()); - I_ShutdownJoystick(); return -1; } else @@ -1092,7 +1078,6 @@ static int joy_open(const char *fname) /* if (joyaxes<2) { I_OutputMsg("Not enought axes?\n"); - I_ShutdownJoystick(); return 0; }*/ @@ -1127,7 +1112,7 @@ static UINT64 lastjoy2hats = 0; \return void */ -static void I_ShutdownJoystick2(void) +void I_ShutdownJoystick2(void) { INT32 i; event_t event; @@ -1161,14 +1146,8 @@ static void I_ShutdownJoystick2(void) joystick2_started = 0; JoyReset(&JoyInfo2); - if (!joystick_started && !joystick2_started && SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK) - { - SDL_QuitSubSystem(SDL_INIT_JOYSTICK); - if (cv_usejoystick2.value == 0) - { - DEBFILE("I_Joystick2: SDL's Joystick system has been shutdown\n"); - } - } + + // don't shut down the subsystem here, because hotplugging } void I_GetJoystick2Events(void) @@ -1317,35 +1296,20 @@ static int joy_open2(const char *fname) int num_joy = 0; int i; - if (joystick_started == 0 && joystick2_started == 0) + if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) { - if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) - { - CONS_Printf(M_GetText("Couldn't initialize joystick: %s\n"), SDL_GetError()); - return -1; - } - else - num_joy = SDL_NumJoysticks(); + CONS_Printf(M_GetText("Joystick subsystem not started\n")); + return -1; + } - if (num_joy < joyindex) - { - CONS_Printf(M_GetText("Cannot use joystick #%d/(%s), it doesn't exist\n"),joyindex,fname); - for (i = 0; i < num_joy; i++) - CONS_Printf("#%d/(%s)\n", i+1, SDL_JoystickNameForIndex(i)); - I_ShutdownJoystick2(); - return -1; - } - } - else - { - JoyReset(&JoyInfo2); - //I_ShutdownJoystick(); - //joy_open(fname); - } + JoyReset(&JoyInfo2); + + if (joyindex <= 0) + return 0; num_joy = SDL_NumJoysticks(); - if (joyindex <= 0 || num_joy == 0 || JoyInfo2.oldjoy == joyindex) + if (num_joy == 0 || JoyInfo2.oldjoy == joyindex) { // I_OutputMsg("Unable to use that joystick #(%s), non-number\n",fname); if (num_joy != 0) @@ -1353,18 +1317,27 @@ static int joy_open2(const char *fname) CONS_Printf(M_GetText("Found %d joysticks on this system\n"), num_joy); for (i = 0; i < num_joy; i++) CONS_Printf("#%d/(%s)\n", i+1, SDL_JoystickNameForIndex(i)); + + if (num_joy < joyindex) + { + CONS_Printf(M_GetText("Cannot use joystick #%d/(%s), it doesn't exist\n"),joyindex,fname); + for (i = 0; i < num_joy; i++) + CONS_Printf("#%d/(%s)\n", i+1, SDL_JoystickNameForIndex(i)); + return 0; + } } else + { CONS_Printf("%s", M_GetText("Found no joysticks on this system\n")); - if (joyindex <= 0 || num_joy == 0) return 0; + return 0; + } } JoyInfo2.dev = SDL_JoystickOpen(joyindex-1); - if (!JoyInfo2.dev) + if (JoyInfo2.dev == NULL) { CONS_Printf(M_GetText("Couldn't open joystick2: %s\n"), SDL_GetError()); - I_ShutdownJoystick2(); return -1; } else @@ -1373,10 +1346,9 @@ static int joy_open2(const char *fname) JoyInfo2.axises = SDL_JoystickNumAxes(JoyInfo2.dev); if (JoyInfo2.axises > JOYAXISSET*2) JoyInfo2.axises = JOYAXISSET*2; -/* if (joyaxes < 2) +/* if (joyaxes<2) { I_OutputMsg("Not enought axes?\n"); - I_ShutdownJoystick2(); return 0; }*/ @@ -1401,57 +1373,89 @@ static int joy_open2(const char *fname) // void I_InitJoystick(void) { - I_ShutdownJoystick(); - SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); - if (!strcmp(cv_usejoystick.string, "0") || M_CheckParm("-nojoy")) + //I_ShutdownJoystick(); + if (M_CheckParm("-nojoy")) return; - if (joy_open(cv_usejoystick.string) != -1) + + if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) + { + CONS_Printf("Initing joy system\n"); + if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) + { + CONS_Printf(M_GetText("Couldn't initialize joystick: %s\n"), SDL_GetError()); + return; + } + else + SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); + } + + if (strcmp(cv_usejoystick.string, "0") && joy_open(cv_usejoystick.string) != -1) + { JoyInfo.oldjoy = atoi(cv_usejoystick.string); + joystick_started = 1; + } else { + if (JoyInfo.oldjoy) + I_ShutdownJoystick(); cv_usejoystick.value = 0; - return; + joystick_started = 0; } - joystick_started = 1; } void I_InitJoystick2(void) { - I_ShutdownJoystick2(); - SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); - if (!strcmp(cv_usejoystick2.string, "0") || M_CheckParm("-nojoy")) + //I_ShutdownJoystick2(); + if (M_CheckParm("-nojoy")) return; - if (joy_open2(cv_usejoystick2.string) != -1) + + if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) + { + CONS_Printf("Initing joy system\n"); + if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) == -1) + { + CONS_Printf(M_GetText("Couldn't initialize joystick: %s\n"), SDL_GetError()); + return; + } + else + SDL_SetHintWithPriority("SDL_XINPUT_ENABLED", "0", SDL_HINT_OVERRIDE); + } + + if (strcmp(cv_usejoystick2.string, "0") && joy_open2(cv_usejoystick2.string) != -1) + { JoyInfo2.oldjoy = atoi(cv_usejoystick2.string); + joystick2_started = 1; + } else { + if (JoyInfo2.oldjoy) + I_ShutdownJoystick2(); cv_usejoystick2.value = 0; - return; + joystick2_started = 0; } - joystick2_started = 1; + } static void I_ShutdownInput(void) { + // Yes, the name is misleading: these send neutral events to + // clean up the unplugged joystick's input + // Note these methods are internal to this file, not called elsewhere. + I_ShutdownJoystick(); + I_ShutdownJoystick2(); + if (SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK) { - JoyReset(&JoyInfo); - JoyReset(&JoyInfo2); + CONS_Printf("Shutting down joy system\n"); SDL_QuitSubSystem(SDL_INIT_JOYSTICK); + I_OutputMsg("I_Joystick: SDL's Joystick system has been shutdown\n"); } - } INT32 I_NumJoys(void) { INT32 numjoy = 0; - if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) - { - if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) != -1) - numjoy = SDL_NumJoysticks(); - SDL_QuitSubSystem(SDL_INIT_JOYSTICK); - } - else + if (SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK) numjoy = SDL_NumJoysticks(); return numjoy; } @@ -1461,18 +1465,9 @@ static char joyname[255]; // MAX_PATH; joystick name is straight from the driver const char *I_GetJoyName(INT32 joyindex) { const char *tempname = NULL; + joyname[0] = 0; joyindex--; //SDL's Joystick System starts at 0, not 1 - if (SDL_WasInit(SDL_INIT_JOYSTICK) == 0) - { - if (SDL_InitSubSystem(SDL_INIT_JOYSTICK) != -1) - { - tempname = SDL_JoystickNameForIndex(joyindex); - if (tempname) - strncpy(joyname, tempname, 255); - } - SDL_QuitSubSystem(SDL_INIT_JOYSTICK); - } - else + if (SDL_WasInit(SDL_INIT_JOYSTICK) == SDL_INIT_JOYSTICK) { tempname = SDL_JoystickNameForIndex(joyindex); if (tempname) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 2c199c2d0..835ba1660 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -116,6 +116,9 @@ static INT32 firstEntry = 0; // Total mouse motion X/Y offsets static INT32 mousemovex = 0, mousemovey = 0; +// Keep track of joy unplugged count +static INT32 joyunplugcount = 0; + // SDL vars static SDL_Surface *vidSurface = NULL; static SDL_Surface *bufSurface = NULL; @@ -882,6 +885,38 @@ void I_GetEvent(void) case SDL_JOYBUTTONDOWN: Impl_HandleJoystickButtonEvent(evt.jbutton, evt.type); break; + case SDL_JOYDEVICEADDED: + CONS_Printf("Joy device %d added\n", evt.jdevice.which); + + // recounts hotplugged joysticks + I_InitJoystick(); + I_InitJoystick2(); + + // update the menu + if (currentMenu == &OP_JoystickSetDef) + M_SetupJoystickMenu(0); + break; + case SDL_JOYDEVICEREMOVED: + { + // every time a device is unplugged, the "which" index increments by 1? + INT32 deviceIdx = evt.jdevice.which - joyunplugcount++; + + CONS_Printf("Joy device %d removed%s\n", deviceIdx, + (JoyInfo.oldjoy-1 == deviceIdx) ? " was first joystick" : + (JoyInfo2.oldjoy-1 == deviceIdx) ? " was second joystick" : ""); + + // I_ShutdownJoystick doesn't shut down the subsystem + // It just fires neutral joy events to clean up the unplugged joy + if (JoyInfo.oldjoy-1 == deviceIdx) + I_ShutdownJoystick(); + if (JoyInfo2.oldjoy-1 == deviceIdx) + I_ShutdownJoystick2(); + + // update the menu + if (currentMenu == &OP_JoystickSetDef) + M_SetupJoystickMenu(0); + } + break; case SDL_QUIT: I_Quit(); M_QuitResponse('y'); diff --git a/src/sdl/sdlmain.h b/src/sdl/sdlmain.h index d12daaa8a..4acbce209 100644 --- a/src/sdl/sdlmain.h +++ b/src/sdl/sdlmain.h @@ -67,6 +67,10 @@ extern SDLJoyInfo_t JoyInfo; */ extern SDLJoyInfo_t JoyInfo2; +// So we can call this from i_video event loop +void I_ShutdownJoystick(void); +void I_ShutdownJoystick2(void); + void I_GetConsoleEvents(void); void SDLforceUngrabMouse(void);