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

Commit 57628af

Browse files
committed
Massive reformatting to get closer to PEP-8
1 parent 8755345 commit 57628af

14 files changed

Lines changed: 146 additions & 70 deletions

File tree

base_plugin.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,6 @@ def activate(self):
367367
self.plugins['command_dispatcher'].register(alias, command)
368368

369369

370-
371370
def deactivate(self):
372371
super(SimpleCommandPlugin, self).deactivate()
373372
for command in self.commands:

config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ def save(self):
3232
except Exception as e:
3333
self.logger.critical("Tried to save the configuration file, failed.\n%s", str(e))
3434
raise
35+
3536
def __getattr__(self, item):
3637
if item != "config":
3738
if item in self.config:

core_plugins/player_manager/manager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
ForeignKey, Boolean, func
1212
from sqlalchemy.ext.declarative import declarative_base
1313
from twisted.words.ewords import AlreadyLoggedIn
14+
1415
logger = logging.getLogger("starrypy.player_manager.manager")
1516

1617
Base = declarative_base()
@@ -47,7 +48,6 @@ class Player(Base):
4748
planet = Column(String)
4849
on_ship = Column(Boolean)
4950

50-
5151
ips = relationship("IPAddress", order_by="IPAddress.id", backref="players")
5252

5353
def colored_name(self, colors):

packet_stream.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import zlib
33
import packets
44

5+
56
class Packet(object):
67
def __init__(self, packet_id, payload_size, data, original_data, direction, compressed=False):
78
self.id = packet_id
@@ -14,6 +15,7 @@ def __init__(self, packet_id, payload_size, data, original_data, direction, comp
1415

1516
class PacketStream(object):
1617
logger = logging.getLogger('starrypy.packet_stream.PacketStream')
18+
1719
def __init__(self, protocol):
1820
self._stream = ""
1921
self.id = None
@@ -45,7 +47,7 @@ def start_packet(self):
4547
self.compressed = True
4648
else:
4749
self.compressed = False
48-
self.header_length = 1+len(packets.SignedVLQ("").build(packet_header.payload_size))
50+
self.header_length = 1 + len(packets.SignedVLQ("").build(packet_header.payload_size))
4951
self.packet_size = self.payload_size + self.header_length
5052
return True
5153
except:
@@ -59,13 +61,13 @@ def check_packet(self):
5961
if not self._stream:
6062
self._stream = ""
6163
p_parsed = packets.packet().parse(p)
62-
if self.compressed and len(p_parsed.data) > 1000:
64+
if self.compressed:
6365
try:
6466
z = zlib.decompressobj()
6567
p_parsed.data = z.decompress(p_parsed.data)
6668
except zlib.error:
6769
self.logger.warning("Decompression error in check_packet.")
68-
pass
70+
raise
6971
packet = Packet(packet_id=p_parsed.id, payload_size=p_parsed.payload_size, data=p_parsed.data,
7072
original_data=p, direction=self.direction)
7173

packets/data_types.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
class SignedVLQ(Construct):
88
logger = logging.getLogger('starrypy.packets.SignedVLQ')
9+
910
def _parse(self, stream, context):
1011
value = 0
1112
while True:
@@ -29,9 +30,9 @@ def _build(self, obj, stream, context):
2930
raise
3031

3132

32-
3333
class VLQ(Construct):
3434
logger = logging.getLogger('starrypy.packets.SignedVLQ')
35+
3536
def _parse(self, stream, context):
3637
value = 0
3738
while True:
@@ -81,6 +82,7 @@ def _decode(self, obj, context):
8182
LazyBound("data",
8283
lambda: Variant(""))))
8384

85+
8486
class dict_variant(Construct):
8587
def _parse(self, stream, context):
8688
l = VLQ("").parse_stream(stream)
@@ -91,6 +93,7 @@ def _parse(self, stream, context):
9193
c[key] = value
9294
return c
9395

96+
9497
class Variant(Construct):
9598
def _parse(self, stream, context):
9699
x = Byte("").parse_stream(stream)

packets/packet_types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ def _decode(self, obj, context):
123123
Flag("uuid_exists"),
124124
If(lambda ctx: ctx.uuid_exists is True,
125125
HexAdapter(Field("uuid", 16))
126-
),
126+
),
127127
star_string("name"),
128128
star_string("species"),
129129
VLQ("shipworld_length"),

plugin_manager.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from base_plugin import BasePlugin
1313
from config import ConfigurationManager
1414

15+
1516
class DuplicatePluginError(Exception):
1617
"""
1718
Raised when there is a plugin of the same name/class already instantiated.
@@ -33,6 +34,7 @@ class MissingDependency(PluginNotFound):
3334

3435
class PluginManager(object):
3536
logger = logging.getLogger('starrypy.plugin_manager.PluginManager')
37+
3638
def __init__(self, base_class=BasePlugin):
3739
"""
3840
Initializes the plugin manager. When called, with will first attempt
@@ -107,7 +109,6 @@ def reload_plugins(self):
107109
raise
108110

109111

110-
111112
def activate_plugins(self):
112113
for plugin in self.plugins:
113114
if plugin.auto_activate:
@@ -139,7 +140,8 @@ def do(self, protocol, command, data):
139140
res = True
140141
return_values.append(res)
141142
except Exception as e:
142-
self.logger.exception("Error in plugin %s with function %s.", str(plugin), command, exc_info=True)
143+
self.logger.exception("Error in plugin %s with function %s.", str(plugin), command,
144+
exc_info=True)
143145
return all(return_values)
144146

145147
def get_by_name(self, name):

plugins/admin_commands_plugin/admin_command_plugin.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ def who(self, data):
4444

4545
def planet(self, data):
4646
"""Displays who is on your current planet."""
47-
who = [w.colored_name(self.config.colors) for w in self.player_manager.who() if w.planet == self.protocol.player.planet and not w.on_ship]
47+
who = [w.colored_name(self.config.colors) for w in self.player_manager.who() if
48+
w.planet == self.protocol.player.planet and not w.on_ship]
4849
self.protocol.send_chat_message("Players on your current planet: %s" % " ".join(who))
4950

5051
@permissions(UserLevels.ADMIN)
@@ -56,7 +57,7 @@ def whois(self, data):
5657
self.protocol.send_chat_message(
5758
"Name: %s\nUserlevel: %s\nUUID: %s\nIP address: %s\nCurrent planet: %s""" % (
5859
info.colored_name(self.config.colors), UserLevels(info.access_level), info.uuid, info.ip,
59-
info.planet))
60+
info.planet))
6061
else:
6162
self.protocol.send_chat_message("Player not found!")
6263
return False
@@ -79,16 +80,17 @@ def promote(self, data):
7980
elif rank == "guest":
8081
self.make_guest(player)
8182
else:
82-
self.protocol.send_chat_message("No such rank!\n"+self.promote.__doc__)
83+
self.protocol.send_chat_message("No such rank!\n" + self.promote.__doc__)
8384
return
8485

8586
self.protocol.send_chat_message("%s: %s -> %s" % (
8687
player.colored_name(self.config.colors), str(UserLevels(old_rank)).split(".")[1],
8788
rank.upper()))
88-
self.protocol.factory.protocols[player.protocol].send_chat_message("%s has promoted you to %s" % (
89-
player.colored_name(self.config.colors), rank.upper()))
89+
self.protocol.factory.protocols[player.protocol].send_chat_message(
90+
"%s has promoted you to %s" % (
91+
player.colored_name(self.config.colors), rank.upper()))
9092
else:
91-
self.protocol.send_chat_message("Player not found!\n"+self.promote.__doc__)
93+
self.protocol.send_chat_message("Player not found!\n" + self.promote.__doc__)
9294
return
9395
else:
9496
self.protocol.send_chat_message(self.promote.__doc__)
@@ -129,7 +131,8 @@ def kick(self, data):
129131
(self.protocol.player.name,
130132
info.name,
131133
" ".join(reason)))
132-
self.logger.info("%s kicked %s (reason: %s", self.protocol.player.name, info.name, " ".join(reason))
134+
self.logger.info("%s kicked %s (reason: %s", self.protocol.player.name, info.name,
135+
" ".join(reason))
133136
return False
134137

135138
@permissions(UserLevels.ADMIN)
@@ -176,9 +179,10 @@ def give_item(self, data):
176179
give_item_to_player(target_protocol, item_name, item_count)
177180
target_protocol.send_chat_message(
178181
"%s has given you: %s (count: %s)" % (
179-
self.protocol.player.name, item_name, item_count))
182+
self.protocol.player.name, item_name, item_count))
180183
self.protocol.send_chat_message("Sent the item(s).")
181-
self.logger.info("%s gave %s %s (count: %s)", self.protocol.player.name, name, item_name, item_count)
184+
self.logger.info("%s gave %s %s (count: %s)", self.protocol.player.name, name, item_name,
185+
item_count)
182186
else:
183187
self.protocol.send_chat_message("You have to give an item name.")
184188
else:

plugins/admin_messenger.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
from base_plugin import BasePlugin
2+
from core_plugins.player_manager import UserLevels
3+
import packets
4+
5+
6+
class AdminMessenger(BasePlugin):
7+
"""Adds support to message moderators/admins/owner with a ## prefixed message."""
8+
name = "admin_messenger"
9+
depends = ['player_manager']
10+
auto_activate = True
11+
12+
def on_chat_sent(self, data):
13+
data = packets.chat_sent().parse(data.data)
14+
if data.message[:2] == "##":
15+
self.message_admins(data)
16+
return False
17+
return True
18+
19+
def message_admins(self, message):
20+
for protocol in self.protocol.factory.protocols.itervalues():
21+
if protocol.player.access_level >= UserLevels.MODERATOR:
22+
protocol.send_chat_message(
23+
"Received an admin message from %s: %s." % (self.protocol.player.name,
24+
message.message[2:]))
25+
self.logger.info("Received an admin message from %s. Message: %s", self.protocol.player.name,
26+
message.message[2:])

plugins/new_player_greeter_plugin/new_player_greeter_plugin.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from base_plugin import BasePlugin
32
from utility_functions import give_item_to_player
43

0 commit comments

Comments
 (0)