Skip to content
This repository was archived by the owner on Apr 27, 2019. It is now read-only.

Commit 7e858c8

Browse files
committed
Retooled warpy.
1 parent b44889c commit 7e858c8

2 files changed

Lines changed: 82 additions & 69 deletions

File tree

plugins/warpy_plugin/warpy_plugin.py

Lines changed: 81 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
from base_plugin import SimpleCommandPlugin
22
from core_plugins.player_manager import permissions, UserLevels
33
from packets import warp_command_write, Packets
4-
from utility_functions import build_packet, move_ship_to_coords
5-
4+
from utility_functions import build_packet, move_ship_to_coords, extract_name
65

76
class Warpy(SimpleCommandPlugin):
87
"""
98
Plugin that allows privileged players to warp around as they like.
109
"""
1110
name = "warpy_plugin"
1211
depends = ['command_dispatcher', 'player_manager']
13-
commands = ["warp", "move_ship", "move_other_ship"]
12+
commands = ["warp", "move_ship"]
1413
auto_activate = True
1514

1615
def activate(self):
@@ -19,12 +18,43 @@ def activate(self):
1918

2019
@permissions(UserLevels.ADMIN)
2120
def warp(self, name):
22-
"""Warps you to a player. Syntax: /warp [player name]"""
21+
"""Warps you to a player's ship, or a player to another player's ship. Syntax: /warp [player name] OR /warp [player 1] [player 2]"""
22+
if len(name) == 0:
23+
self.protocol.send_chat_message(self.warp.__doc__)
24+
return
25+
try:
26+
first_name, rest = extract_name(name)
27+
except ValueError:
28+
self.protocol.send_chat_message(self.warp.__doc__)
29+
return
30+
if rest is None or len(rest)==0:
31+
self.warp_self_to_player([first_name])
32+
else:
33+
try:
34+
second_name = extract_name(rest)[0]
35+
except ValueError:
36+
self.protocol.send_chat_message(self.warp.__doc__)
37+
return
38+
self.warp_player_to_player(first_name, second_name)
39+
40+
@permissions(UserLevels.ADMIN)
41+
def move_ship(self, location):
42+
"""Move your ship to another player or specific coordinates. Syntax: /move_ship [player_name] OR /move_ship [from player] [to player]"""
43+
try:
44+
first_name, rest = extract_name(location)
45+
if rest is None:
46+
self.move_own_ship_to_player(first_name)
47+
else:
48+
self.move_player_ship_to_other(first_name, extract_name(rest)[0])
49+
except ValueError:
50+
self.protocol.send_chat_message(self.move_ship.__doc__)
51+
52+
53+
def warp_self_to_player(self, name):
2354
self.logger.debug("Warp command called by %s to %s", self.protocol.player.name, name)
2455
name = " ".join(name)
2556
target_player = self.player_manager.get_logged_in_by_name(name)
2657
if target_player is not None:
27-
target_protocol = self.protocol.factory.protocols[target_player.protocol]
2858
if target_player is not self.protocol.player:
2959
warp_packet = build_packet(Packets.WARP_COMMAND,
3060
warp_command_write(t="WARP_OTHER_SHIP",
@@ -37,68 +67,51 @@ def warp(self, name):
3767
self.protocol.send_chat_message("No player by the name %s found." % name)
3868
self.protocol.send_chat_message(self.warp.__doc__)
3969

40-
@permissions(UserLevels.ADMIN)
41-
def move_ship(self, location):
42-
"""Move your ship to another player or specific coordinates. Syntax: /move_ship [player_name] OR /move_ship [sector] [x] [y] [z] [planet_number] [satellite_number]"""
43-
self.logger.debug("move_ship called by %s to %s", self.protocol.player.name, ":".join(location))
44-
try:
45-
if len(location) == 0:
46-
raise
47-
elif len(location) == 5 and location[2].isnum():
48-
sector, x, y, z, planet, satellite = location
49-
x, y, z, planet, satellite = map(int, (x, y, z, planet, satellite))
50-
warp_packet = build_packet(Packets.WARP_COMMAND,
51-
warp_command_write(t="MOVE_SHIP", sector=sector, x=x, y=y, z=z,
52-
planet=planet,
53-
satellite=satellite, player="".encode('utf-8')))
54-
self.protocol.client_protocol.transport.write(warp_packet)
55-
return
70+
def warp_player_to_player(self, from_string, to_string):
71+
self.logger.debug("Warp player-to-player command called by %s: %s to %s", self.protocol.player.name, from_string, to_string)
72+
from_player = self.player_manager.get_logged_in_by_name(from_string)
73+
to_player = self.player_manager.get_logged_in_by_name(to_string)
74+
if from_player is not None:
75+
if to_player is not None:
76+
from_protocol = self.protocol.factory.protocols[from_player.protocol]
77+
if from_player is not to_player:
78+
warp_packet = build_packet(Packets.WARP_COMMAND,
79+
warp_command_write(t="WARP_OTHER_SHIP",
80+
player=to_player.name.encode('utf-8')))
81+
else:
82+
warp_packet = build_packet(Packets.WARP_COMMAND,
83+
warp_command_write(t='WARP_UP'))
84+
from_protocol.client_protocol.transport.write(warp_packet)
5685
else:
57-
name = " ".join(location)
58-
target_player = self.player_manager.get_logged_in_by_name(name)
59-
if target_player is None: raise
60-
coords = target_player.planet
61-
if coords is None: raise
62-
sector, x, y, z, planet, satellite = coords.split(":")
63-
x, y, z, planet, satellite = map(int, (x, y, z, planet, satellite))
64-
warp_packet = build_packet(Packets.WARP_COMMAND,
65-
warp_command_write(t="MOVE_SHIP", sector=sector, x=x, y=y, z=z,
66-
planet=planet,
67-
satellite=satellite, player="".encode('utf-8')))
68-
self.protocol.client_protocol.transport.write(warp_packet)
69-
except:
70-
self.logger.exception("Unknown error in move_ship command.", exc_info=True)
71-
self.protocol.send_chat_message(self.move_ship.__doc__)
86+
self.protocol.send_chat_message("No player by the name %s found." % to_string)
87+
self.protocol.send_chat_message(self.warp.__doc__)
88+
return
89+
else:
90+
self.protocol.send_chat_message("No player by the name %s found." % from_string)
91+
self.protocol.send_chat_message(self.warp.__doc__)
92+
93+
def move_player_ship(self, protocol, location):
94+
satellite = int(location.pop())
95+
planet = int(location.pop())
96+
z = int(location.pop())
97+
y = int(location.pop())
98+
x = int(location.pop())
99+
sector = location.pop()
100+
move_ship_to_coords(protocol, sector, x, y, z, planet, satellite)
101+
protocol.send_chat_message(
102+
"You have been moved to a different planet by %s" % self.protocol.player.colored_name(
103+
self.config.colors))
104+
105+
def move_own_ship_to_player(self, player_name):
106+
pass
107+
108+
def move_player_ship_to_other(self, from_player, to_player):
109+
f = self.player_manager.get_logged_in_by_name(from_player)
110+
t = self.player_manager.get_logged_in_by_name(to_player)
111+
if f is None or t is None:
112+
raise ValueError
113+
if t.planet == u"":
114+
self.protocol.send_chat_message("Sorry, we don't have a tracked planet location for %s. Perhaps they haven't warped to a planet since logging in?" % to_player)
115+
return
116+
self.move_player_ship(self.protocol.factory.protocols[f.protocol], t.planet.split(":"))
72117

73-
@permissions(UserLevels.ADMIN)
74-
def move_other_ship(self, data):
75-
"""Moves another players ship. Usage: /move_other_ship [player] [coordinates in format alpha:12345:122:5:0] OR /move_other_ship [player] (to warp the players ship to your current location."""
76-
self.logger.debug("move_other_ship called by %s to %s", self.protocol.player.name, ":".join(data))
77-
try:
78-
if len(data) < 6 and len(data) != 1: raise
79-
if len(data) >= 6:
80-
satellite = int(data.pop())
81-
planet = int(data.pop())
82-
z = int(data.pop())
83-
y = int(data.pop())
84-
x = int(data.pop())
85-
sector = data.pop()
86-
player = data
87-
target_player = self.player_manager.get_logged_in_by_name(player)
88-
if target_player is None: raise
89-
tp_protocol = self.protocol.factory.protocols[target_player.protocol]
90-
move_ship_to_coords(tp_protocol, sector, x, y, z, planet, satellite)
91-
self.protocol.factory.protocols[player.protocol].send_chat_message(
92-
"You have been moved to a different planet by %s" % self.protocol.player.colored_name(
93-
self.config.colors))
94-
else:
95-
target_player = self.player_manager.get_logged_in_by_name(" ".join(data))
96-
tp_protocol = self.protocol.factory.protocols[target_player.protocol]
97-
coords = self.protocol.player.planet.split(":")
98-
move_ship_to_coords(tp_protocol, *coords)
99-
self.protocol.factory.protocols[target_player.protocol].send_chat_message(
100-
"You have been moved to a different planet by %s" % self.protocol.player.colored_name(
101-
self.config.colors))
102-
except:
103-
self.logger.exception("Unknown error in move_other_ship command.", exc_info=True)
104-
self.protocol.send_chat_message(self.move_other_ship.__doc__)

utility_functions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def __str__(self):
5050

5151
def move_ship_to_coords(protocol, sector, x, y, z, planet, satellite):
5252
logger.info("Moving %s's ship to coordinates: %s", protocol.player.name,
53-
":".join((sector, x, y, z, planet, satellite)))
53+
":".join((sector, str(x), str(y), str(z), str(planet), str(satellite))))
5454
x, y, z, planet, satellite = map(int, (x, y, z, planet, satellite))
5555
warp_packet = build_packet(packets.Packets.WARP_COMMAND,
5656
packets.warp_command_write(t="MOVE_SHIP", sector=sector, x=x, y=y, z=z,

0 commit comments

Comments
 (0)