From bdf8f9857846b7c20c8e096d4564121b8a0f9e53 Mon Sep 17 00:00:00 2001 From: Dev <90421310+EstatoDeviato@users.noreply.github.com> Date: Thu, 12 Dec 2024 13:00:11 +0100 Subject: [PATCH 1/5] add area message command --- server/commands/areas.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/server/commands/areas.py b/server/commands/areas.py index 4783cd26..5f2d81be 100644 --- a/server/commands/areas.py +++ b/server/commands/areas.py @@ -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): @@ -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 + """ + 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!") From ee0b29417e6a31ab863736973fdd3d1a6b84416e Mon Sep 17 00:00:00 2001 From: Dev <90421310+EstatoDeviato@users.noreply.github.com> Date: Thu, 12 Dec 2024 13:03:37 +0100 Subject: [PATCH 2/5] refresh area message when a player join or exit from an area --- server/client_manager.py | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/server/client_manager.py b/server/client_manager.py index 36f658bc..6f133a95 100644 --- a/server/client_manager.py +++ b/server/client_manager.py @@ -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 @@ -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. From b654e3788e26c8311c1e8b04ddec27661a476bcd Mon Sep 17 00:00:00 2001 From: Dev <90421310+EstatoDeviato@users.noreply.github.com> Date: Thu, 12 Dec 2024 13:07:06 +0100 Subject: [PATCH 3/5] add area message variable to area --- server/area.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/server/area.py b/server/area.py index f3eb941f..0cb6be7e 100644 --- a/server/area.py +++ b/server/area.py @@ -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.""" @@ -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() @@ -676,6 +684,7 @@ 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 return area def new_client(self, client): From f34d726ec4addaf2fbaec296ed84ded0f6106ebc Mon Sep 17 00:00:00 2001 From: Dev <90421310+EstatoDeviato@users.noreply.github.com> Date: Thu, 12 Dec 2024 13:09:52 +0100 Subject: [PATCH 4/5] add area message command to doc --- docs/commands.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/commands.md b/docs/commands.md index 494e096c..301191d2 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -169,6 +169,13 @@ * **auto\_pair** `` - Set the max of players displayed on the screen. - Depends on the /area_pref auto_pair setting +* **area\_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. From 70db549bc324b4be0eb296d61e4b1d797df1cd09 Mon Sep 17 00:00:00 2001 From: Dev <90421310+EstatoDeviato@users.noreply.github.com> Date: Thu, 12 Dec 2024 13:11:24 +0100 Subject: [PATCH 5/5] Update area.py --- server/area.py | 1 + 1 file changed, 1 insertion(+) diff --git a/server/area.py b/server/area.py index 0cb6be7e..340b73b8 100644 --- a/server/area.py +++ b/server/area.py @@ -685,6 +685,7 @@ def save(self): 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):