Skip to content

Commit 3a1371c

Browse files
Add sfx command w/ sfx spam delay as well and gm/cm/mod bypass
sfx command also respects broadcast rules
1 parent 704a044 commit 3a1371c

File tree

2 files changed

+51
-3
lines changed

2 files changed

+51
-3
lines changed

server/client_manager.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1943,6 +1943,14 @@ def need_call_time(self):
19431943
def need_call_time(self, value):
19441944
self.server.client_manager.set_spam_delay(self.ipid, "need_call", value)
19451945

1946+
@property
1947+
def sfx_time(self):
1948+
return self.server.client_manager.get_spam_delay(self.ipid, "sfx")
1949+
1950+
@sfx_time.setter
1951+
def sfx_time(self, value):
1952+
self.server.client_manager.set_spam_delay(self.ipid, "sfx", value)
1953+
19461954
@property
19471955
def ip(self):
19481956
"""Get an anonymized version of the IP address."""
@@ -2219,6 +2227,12 @@ def set_need_call_delay(self):
22192227
except:
22202228
self.need_call_time = round(time.time() * 1000 + 60000)
22212229

2230+
def set_sfx_delay(self):
2231+
"""Begin the sfx cooldown."""
2232+
# 3 second delay by default
2233+
sfx_delay = 3000
2234+
self.sfx_time = round(time.time() * 1000.0 + sfx_delay)
2235+
22222236
def can_call_case(self):
22232237
"""Whether or not the client can currently announce a case."""
22242238
return (time.time() * 1000.0 - self.case_call_time) > 0
@@ -2227,6 +2241,10 @@ def can_call_need(self):
22272241
"""Whether or not the client can currently call a need."""
22282242
return (time.time() * 1000.0 - self.need_call_time) > 0
22292243

2244+
def can_sfx(self):
2245+
"""Whether or not the client can currently play an sfx."""
2246+
return (time.time() * 1000.0 - self.sfx_time) > 0
2247+
22302248
def disemvowel_message(self, message):
22312249
"""Disemvowel a chat message."""
22322250
message = re.sub("[aeiou]", "", message, flags=re.IGNORECASE)

server/commands/roleplay.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,8 +1136,38 @@ def ooc_cmd_sfx(client, arg):
11361136
raise ArgumentError(
11371137
"sound_path can't be empty. Usage: /sfx [sound_path]"
11381138
)
1139-
client.area.send_command("RT", arg)
1140-
client.area.broadcast_ooc(f"has played '{arg}'.")
1139+
is_mod = client.is_mod or client in client.area.owners
1140+
# Only incur cooldowns etc. on mods.
1141+
if not is_mod:
1142+
if client.char_id <= -1 or client.char_id == None:
1143+
raise ClientError(
1144+
"You can't play sfx when you're a spectator and not a CM/GM!"
1145+
)
1146+
if not client.can_sfx():
1147+
raise ClientError(
1148+
"You need to wait before playing sfx again!"
1149+
)
1150+
target_areas = [client.area]
1151+
if len(client.broadcast_list) > 0 and is_mod:
1152+
try:
1153+
a_list = ", ".join([str(a.id)
1154+
for a in client.broadcast_list])
1155+
client.send_ooc(f"Broadcasting to areas {a_list}")
1156+
target_areas = client.broadcast_list
1157+
except:
1158+
client.send_ooc(
1159+
"Your broadcast list is invalid! Do /clear_broadcast to reset it and /broadcast <id(s)> to set a new one."
1160+
)
1161+
return
1162+
for area in target_areas:
1163+
# Plays on unused music layer 3 (max channel)
1164+
area.send_command("MC", f"../general/{arg}", -1, "", 0, 3, 0)
1165+
area.broadcast_ooc(f"[{client.id}] {client.showname} has played sfx '{arg}'.")
1166+
for a in area.broadcast_list:
1167+
# Plays on unused music layer 3 (max channel)
1168+
a.send_command("MC", f"../general/{arg}", -1, "", 0, 3, 0)
1169+
a.broadcast_ooc(f"[{client.id}] {client.showname} has played sfx '{arg}'.")
1170+
client.set_sfx_delay()
11411171
database.log_area(
1142-
"sfx", client, client.area, message=f"has played {arg}"
1172+
"sfx", client, client.area, message=f"has played sfx {arg}"
11431173
)

0 commit comments

Comments
 (0)