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

/pm now works if target is in a different hub #112

Merged
merged 4 commits into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
57 changes: 31 additions & 26 deletions server/client_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -1933,7 +1933,7 @@ def remove_client(self, client):
],
)

def get_targets(self, client, key, value, local=False, single=False):
def get_targets(self, client, key, value, local=False, single=False, all_hub=False):
"""
Find players by a combination of identifying data.
Possible keys: player ID, OOC name, character name, HDID, IPID,
Expand All @@ -1944,36 +1944,41 @@ def get_targets(self, client, key, value, local=False, single=False):
:param value: data identifying a client
:param local: search in current area only (Default value = False)
:param single: search only a single user (Default value = False)
:param all_hub: search in all hubs (Default value = False)
"""
areas = None
if local:
areas = [client.area]
else:
areas = client.area.area_manager.areas
targets = []
if key == TargetType.ALL:
for nkey in range(6):
targets += self.get_targets(client, nkey, value, local)
for area in areas:
for client in area.clients:
if key == TargetType.IP:
if value.lower().startswith(client.ip.lower()):
targets.append(client)
elif key == TargetType.OOC_NAME:
if value.lower().startswith(client.name.lower()) and client.name:
targets.append(client)
elif key == TargetType.CHAR_NAME:
if value.lower().startswith(client.char_name.lower()):
targets.append(client)
elif key == TargetType.ID:
if client.id == value:
targets.append(client)
elif key == TargetType.IPID:
if client.ipid == value:
targets.append(client)
elif key == TargetType.AFK:
if client in area.afkers:
targets.append(client)
if all_hub and not local:
hubs = self.server.hub_manager.hubs
else:
hubs = [client.area.area_manager]
for hub in hubs:
if local:
areas = [client.area]
else:
areas = hub.areas
for area in areas:
for client in area.clients:
if key == TargetType.IP:
if value.lower().startswith(client.ip.lower()):
targets.append(client)
elif key == TargetType.OOC_NAME:
if value.lower().startswith(client.name.lower()) and client.name:
targets.append(client)
elif key == TargetType.CHAR_NAME:
if value.lower().startswith(client.char_name.lower()):
targets.append(client)
elif key == TargetType.ID:
if client.id == value:
targets.append(client)
elif key == TargetType.IPID:
if client.ipid == value:
targets.append(client)
elif key == TargetType.AFK:
if client in area.afkers:
targets.append(client)
return targets

def get_muted_clients(self):
Expand Down
3 changes: 2 additions & 1 deletion server/commands/messaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def ooc_cmd_pm(client, arg):
"""
Send a private message to another online user. These messages are not
logged by the server owner.
The Target Types <ooc-name> and <char-name> work only if the target is in the same area.
Usage: /pm <id|ooc-name|char-name> <message>
"""
args = arg.split()
Expand All @@ -152,7 +153,7 @@ def ooc_cmd_pm(client, arg):
key = TargetType.CHAR_NAME
if len(targets) == 0 and args[0].isdigit():
targets = client.server.client_manager.get_targets(
client, TargetType.ID, int(args[0]), False
client, TargetType.ID, int(args[0]), False, False, True
Crystalwarrior marked this conversation as resolved.
Show resolved Hide resolved
)
key = TargetType.ID
if len(targets) == 0:
Expand Down
Loading