Skip to content

Commit

Permalink
fix #specmute to require auth or admin
Browse files Browse the repository at this point in the history
  • Loading branch information
sauerbraten committed May 17, 2023
1 parent e6cb272 commit c1015cf
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 26 deletions.
6 changes: 3 additions & 3 deletions patches/bans.patch
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@ index cafe106..cef1b76 100644
--- src/p1xbraten/remote_commands.cpp
+++ src/p1xbraten/remote_commands.cpp
@@ -27,6 +27,11 @@ namespace server {
: "spectators are not unmuted (use #specmute 1 to mute)");
return true; }
else if(sscanf(cmd, "specmute %d", &ival) == 1) { setspecmute(ival!=0); return true; }
else if(!strcmp(cmd, "mutespec") || !strcmp(cmd, "mutespecs") || !strcmp(cmd, "specmute"))
{ queryspecmute(sender); return true; }
else if(sscanf(cmd, "specmute %d", &ival) == 1) { setspecmute(sender, ival!=0); return true; }
+ else if(sscanf(cmd, "getip %d", &ival) == 1) { getip(sender, ival); return true; }
+ else if(sscanf(cmd, "ban %15s %d", sval, &ival) == 2) { addban(sender, sval, ival); return true; }
+ else if(sscanf(cmd, "ban %15s", sval) == 1) { addban(sender, sval); return true; }
Expand Down
34 changes: 21 additions & 13 deletions patches/managed_games.patch
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ index 02277f9..b37ef32 100644
extern const char *mastermodename(int n, const char *unknown = "unknown");
extern void startintermission();
extern void stopdemo();
@@ -1189,6 +1203,43 @@ namespace server
@@ -1189,6 +1203,44 @@ namespace server
extern int msgsizelookup(int msg);
extern bool serveroption(const char *arg);
extern bool delayspawn(int type);
Expand All @@ -113,8 +113,9 @@ index 02277f9..b37ef32 100644
+ extern int gamelimitnextmatch;
+#define DEFAULT_GAMELIMIT (10*60*1000)
+ extern void probeforclientdemoupload(packetbuf &p);
+ extern void setspecmute(bool on);
+ extern void setupmanagedgame(clientinfo *referee, bool specmute = false, char *duration = NULL);
+ extern void setspecmute(clientinfo *ci, bool on);
+ extern void queryspecmute(clientinfo *ci);
+ extern void setupmanagedgame(clientinfo *ci, bool specmute = false, char *duration = NULL);
+ extern void startmanagedgame();
+ extern void cleanupmanagedgame();
+ extern void onspawn(clientinfo *ci);
Expand Down Expand Up @@ -392,7 +393,7 @@ new file mode 100644
index 0000000..1c1b1d7
--- /dev/null
+++ src/p1xbraten/managed_games.cpp
@@ -0,0 +1,271 @@
@@ -0,0 +1,281 @@
+#include "game.h"
+
+#ifndef STANDALONE
Expand Down Expand Up @@ -430,15 +431,25 @@ index 0000000..1c1b1d7
+ bool specmute = false, specmutenextmatch = false;
+ int gamelimitnextmatch = DEFAULT_GAMELIMIT;
+
+ void setspecmute(bool on)
+ void queryspecmute(clientinfo *ci)
+ {
+ if(!ci || (ci->privilege<=PRIV_AUTH && !ci->local)) return;
+ sendf(ci->clientnum, 1, "ris", N_SERVMSG, specmute
+ ? "spectators are muted (use #specmute 0 to unmute)"
+ : "spectators are not muted (use #specmute 1 to mute)"
+ );
+ }
+
+ void setspecmute(clientinfo *ci, bool on)
+ {
+ if(!ci || (ci->privilege<=PRIV_AUTH && !ci->local)) return;
+ specmute = on;
+ sendf(-1, 1, "ris", N_SERVMSG, specmute ? "spectators muted" : "spectators unmuted");
+ }
+
+ void setupmanagedgame(clientinfo *referee, bool mutespecs, char *duration)
+ void setupmanagedgame(clientinfo *ci, bool mutespecs, char *duration)
+ {
+ if(!referee || (!referee->privilege && !referee->local)) return;
+ if(!ci || (!ci->privilege && !ci->local)) return;
+
+ if(mastermode < MM_LOCKED) { mastermode = MM_LOCKED; sendf(-1, 1, "rii", N_MASTERMODE, mastermode); }
+
Expand Down Expand Up @@ -669,7 +680,7 @@ new file mode 100644
index 0000000..e71f710
--- /dev/null
+++ src/p1xbraten/remote_commands.cpp
@@ -0,0 +1,31 @@
@@ -0,0 +1,28 @@
+#include "game.h"
+
+namespace server {
Expand All @@ -692,11 +703,8 @@ index 0000000..e71f710
+ else if(!strcmp(cmd, "tourney")) { setupmanagedgame(sender, true); return true; }
+ else if(sscanf(cmd, "tourney %5s", sval) == 1) { setupmanagedgame(sender, true, sval); return true; }
+ else if(!strcmp(cmd, "mutespec") || !strcmp(cmd, "mutespecs") || !strcmp(cmd, "specmute"))
+ { sendf(sender->clientnum, 1, "ris", N_SERVMSG, specmute
+ ? "spectators are muted (use #specmute 0 to unmute)"
+ : "spectators are not unmuted (use #specmute 1 to mute)");
+ return true; }
+ else if(sscanf(cmd, "specmute %d", &ival) == 1) { setspecmute(ival!=0); return true; }
+ { queryspecmute(sender); return true; }
+ else if(sscanf(cmd, "specmute %d", &ival) == 1) { setspecmute(sender, ival!=0); return true; }
+ return false;
+ }
+
Expand Down
5 changes: 3 additions & 2 deletions src/fpsgame/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -1252,8 +1252,9 @@ namespace server
extern int gamelimitnextmatch;
#define DEFAULT_GAMELIMIT (10*60*1000)
extern void probeforclientdemoupload(packetbuf &p);
extern void setspecmute(bool on);
extern void setupmanagedgame(clientinfo *referee, bool specmute = false, char *duration = NULL);
extern void setspecmute(clientinfo *ci, bool on);
extern void queryspecmute(clientinfo *ci);
extern void setupmanagedgame(clientinfo *ci, bool specmute = false, char *duration = NULL);
extern void startmanagedgame();
extern void cleanupmanagedgame();
extern void onspawn(clientinfo *ci);
Expand Down
16 changes: 13 additions & 3 deletions src/p1xbraten/managed_games.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,25 @@ namespace server {
bool specmute = false, specmutenextmatch = false;
int gamelimitnextmatch = DEFAULT_GAMELIMIT;

void setspecmute(bool on)
void queryspecmute(clientinfo *ci)
{
if(!ci || (ci->privilege<=PRIV_AUTH && !ci->local)) return;
sendf(ci->clientnum, 1, "ris", N_SERVMSG, specmute
? "spectators are muted (use #specmute 0 to unmute)"
: "spectators are not muted (use #specmute 1 to mute)"
);
}

void setspecmute(clientinfo *ci, bool on)
{
if(!ci || (ci->privilege<=PRIV_AUTH && !ci->local)) return;
specmute = on;
sendf(-1, 1, "ris", N_SERVMSG, specmute ? "spectators muted" : "spectators unmuted");
}

void setupmanagedgame(clientinfo *referee, bool mutespecs, char *duration)
void setupmanagedgame(clientinfo *ci, bool mutespecs, char *duration)
{
if(!referee || (!referee->privilege && !referee->local)) return;
if(!ci || (!ci->privilege && !ci->local)) return;

if(mastermode < MM_LOCKED) { mastermode = MM_LOCKED; sendf(-1, 1, "rii", N_MASTERMODE, mastermode); }

Expand Down
7 changes: 2 additions & 5 deletions src/p1xbraten/remote_commands.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,8 @@ namespace server {
else if(!strcmp(cmd, "tourney")) { setupmanagedgame(sender, true); return true; }
else if(sscanf(cmd, "tourney %5s", sval) == 1) { setupmanagedgame(sender, true, sval); return true; }
else if(!strcmp(cmd, "mutespec") || !strcmp(cmd, "mutespecs") || !strcmp(cmd, "specmute"))
{ sendf(sender->clientnum, 1, "ris", N_SERVMSG, specmute
? "spectators are muted (use #specmute 0 to unmute)"
: "spectators are not unmuted (use #specmute 1 to mute)");
return true; }
else if(sscanf(cmd, "specmute %d", &ival) == 1) { setspecmute(ival!=0); return true; }
{ queryspecmute(sender); return true; }
else if(sscanf(cmd, "specmute %d", &ival) == 1) { setspecmute(sender, ival!=0); return true; }
else if(sscanf(cmd, "getip %d", &ival) == 1) { getip(sender, ival); return true; }
else if(sscanf(cmd, "ban %15s %d", sval, &ival) == 2) { addban(sender, sval, ival); return true; }
else if(sscanf(cmd, "ban %15s", sval) == 1) { addban(sender, sval); return true; }
Expand Down

0 comments on commit c1015cf

Please sign in to comment.