Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Area message Command (NEW KFO CLIENT) #167

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@
* **auto\_pair** `<double/triple>`
- Set the max of players displayed on the screen.
- Depends on the /area_pref auto_pair setting
* **area\_message** `<message>`
- Set a fixed message for an area.
- To disable just do /area_message.
- {areaname} in the message will show area's name
- {playercount} will show the number of the players in the area
- {playerlist} will show the list of the players in the area
- {desc} will show area desc
## Casing
* **doc** `[url]`
- Show or change the link for the current case document.
Expand Down
10 changes: 10 additions & 0 deletions server/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,10 @@ def __init__(self, area_manager, name):
self.auto_pair_max = "triple"
self.auto_pair_cycle = False

# Area message stuff
self.can_area_message = True
self.area_message = ""

@property
def name(self):
"""Area's name string. Abbreviation is also updated according to this."""
Expand Down Expand Up @@ -598,6 +602,10 @@ def load(self, area):
self.auto_pair_max = area["auto_pair_max"]
if "auto_pair_cycle" in area:
self.auto_pair_cycle = area["auto_pair_cycle"]
if "can_area_message" in area:
self.can_area_message = area["can_area_message"]
if "area_message" in area:
self.area_message = area["area_message"]

def save(self):
area = OrderedDict()
Expand Down Expand Up @@ -676,6 +684,8 @@ def save(self):
area["auto_pair"] = self.auto_pair
area["auto_pair_max"] = self.auto_pair_max
area["auto_pair_cycle"] = self.auto_pair_cycle
area["can_area_message"] = self.can_area_message
area["area_message"] = self.area_message
return area

def new_client(self, client):
Expand Down
40 changes: 40 additions & 0 deletions server/client_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -972,6 +972,27 @@ def set_area(self, area, target_pos=""):

self.area.trigger("join", self)

if self.area.area_message == "":
self.send_command("AD", "")
else:
msg = self.area.area_message
if "{areaname}" in msg:
msg = msg.replace("{areaname}", self.area.name)
if "{desc}" in msg:
msg = msg.replace("{desc}", self.area.desc)
if "{playercount}" in msg or "{playerlist}" in msg:
if "{playercount}" in msg:
msg = msg.replace("{playercount}", str(len(self.area.clients)))
if "{playerlist}" in msg:
playerlist = ", ".join(
f"[{c.id}] {c.showname}" for c in self.area.clients
)
msg = msg.replace("{playerlist}", playerlist)
for c in self.area.clients:
c.send_command("AD", msg)
else:
self.send_command("AD", msg)

def can_access_area(self, area):
return (
self.area == area
Expand Down Expand Up @@ -2133,6 +2154,25 @@ def remove_client(self, client):
],
)

if client.area.area_message != "":
msg = client.area.area_message
if "{playerlist}" in msg or "{playercount}" in msg:
if "{areaname}" in msg:
msg = msg.replace("{areaname}", client.area.name)
if "{desc}" in msg:
msg = msg.replace("{desc}", client.area.desc)
if "{playercount}" in msg:
msg = msg.replace(
"{playercount}", str(len(client.area.clients))
)
if "{playerlist}" in msg:
playerlist = ", ".join(
f"[{c.id}] {c.showname}" for c in self.area.clients
)
msg = msg.replace("{playerlist}", playerlist)
for c in self.area.clients:
c.send_command("AD", msg)

def get_targets(self, client, key, value, local=False, single=False, all_hub=False):
"""
Find players by a combination of identifying data.
Expand Down
38 changes: 38 additions & 0 deletions server/commands/areas.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"ooc_cmd_edit_ambience",
"ooc_cmd_lights",
"ooc_cmd_auto_pair",
"ooc_cmd_area_message",
]

def ooc_cmd_overlay(client, arg):
Expand Down Expand Up @@ -858,3 +859,40 @@ def ooc_cmd_auto_pair(client, arg):
client.send_ooc("Pairing will show a maximum of 3 characters on screen now")
else:
client.send_ooc("Pairing will show a maximum of 2 characters on screen now")


def ooc_cmd_area_message(client, arg):
"""
Set a fixed message for an area.
To disable just do /area_message.
{areaname} in the message will show area's name
{playercount} will show the number of the players in the area
{playerlist} will show the list of the players in the area
{desc} will show area desc
Usage: /area_message <message>
"""
if client not in client.area.owners and not client.is_mod:
raise AreaError("You cannot modify area message unless you are at least CM!")
if not client.area.can_area_message:
raise AreaError("You cannot modify area message in this area!")
if len(arg) == 0:
client.area.area_message = ""
for c in client.area.clients:
c.send_command("AD", "")
c.send_ooc("Area message has been disabled!")
else:
client.area.area_message = arg
if "{areaname}" in arg:
arg = arg.replace("{areaname}", client.area.name)
if "{desc}" in arg:
arg = arg.replace("{desc}", client.area.desc)
if "{playercount}" in arg:
arg = arg.replace("{playercount}", str(len(client.area.clients)))
if "{playerlist}" in arg:
playerlist = ", ".join(
f"[{c.id}] {c.showname}" for c in client.area.clients
)
arg = arg.replace("{playerlist}", playerlist)
for c in client.area.clients:
c.send_command("AD", arg)
c.send_ooc("Area message has been changed!")
Loading