Skip to content

Commit 577fd29

Browse files
Merge pull request #194 from Crystalwarrior:scuffed-sfx-command
Add an /sfx command
2 parents 83109a9 + 3a1371c commit 577fd29

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
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: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"ooc_cmd_format_timer",
3939
"ooc_cmd_timer_interval",
4040
"ooc_cmd_ooc_actions",
41+
"ooc_cmd_sfx",
4142
]
4243

4344

@@ -1124,3 +1125,49 @@ def ooc_cmd_ooc_actions(client, arg):
11241125
if client.ooc_actions:
11251126
stat = "now see"
11261127
client.send_ooc(f"You will {stat} actions in OOC.")
1128+
1129+
1130+
def ooc_cmd_sfx(client, arg):
1131+
"""
1132+
Play a sound effect directly without associating it with an emote.
1133+
Usage: /sfx [sound_path]
1134+
"""
1135+
if arg == "":
1136+
raise ArgumentError(
1137+
"sound_path can't be empty. Usage: /sfx [sound_path]"
1138+
)
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()
1171+
database.log_area(
1172+
"sfx", client, client.area, message=f"has played sfx {arg}"
1173+
)

0 commit comments

Comments
 (0)