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

Commit be8da30

Browse files
author
Marv Cool
committed
Merge branch 'master' into random_acts_of_bug_squashing
2 parents 15477bd + 2a23222 commit be8da30

14 files changed

Lines changed: 211 additions & 58 deletions

File tree

core_plugins/player_manager/manager.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,17 @@ class Player(Base):
4444
client_id = Column(Integer)
4545
ip = Column(String)
4646
plugin_storage = Column(String)
47+
planet = Column(String)
48+
on_ship = Column(Boolean)
49+
50+
4751
ips = relationship("IPAddress", order_by="IPAddress.id", backref="players")
4852

4953
def colored_name(self, colors):
5054
color = colors[str(UserLevels(self.access_level)).split(".")[1].lower()]
5155
return color + self.name + colors["default"]
5256

53-
def storage(self,store=None):
57+
def storage(self, store=None):
5458
caller = inspect.stack()[1][0].f_locals["self"].__class__.name
5559
try:
5660
plugin_storage = json.loads(self.plugin_storage)
@@ -67,6 +71,7 @@ def storage(self,store=None):
6771
except (ValueError, KeyError, TypeError):
6872
return {}
6973

74+
7075
class IPAddress(Base):
7176
__tablename__ = 'ips'
7277
id = Column(Integer, primary_key=True, autoincrement=True)
@@ -116,7 +121,9 @@ def fetch_or_create(self, uuid, name, ip, protocol=None):
116121
logged_in=False,
117122
protocol=protocol,
118123
client_id=-1,
119-
ip=ip)
124+
ip=ip,
125+
planet="",
126+
on_ship=True)
120127
player.ips = [IPAddress(ip=ip)]
121128
self.session.add(player)
122129
if uuid == self.config.owner_uuid:

core_plugins/player_manager/plugin.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
from manager import PlayerManager, Banned
66
from packets import client_connect, connect_response
77
import packets
8+
from utility_functions import build_packet, Planet
89

910

1011
class PlayerManagerPlugin(BasePlugin):
@@ -24,7 +25,7 @@ def on_client_connect(self, data):
2425
protocol=self.protocol.id)
2526
return True
2627
except (AlreadyLoggedIn, Banned) as e:
27-
ban_packet = self.protocol.build_packet(
28+
ban_packet = build_packet(
2829
packets.Packets.CLIENT_DISCONNECT,
2930
packets.connect_response().build(
3031
Container(
@@ -51,5 +52,19 @@ def after_connect_response(self, data):
5152
self.protocol.player.name, self.protocol.player.uuid,
5253
self.protocol.transport.getHost().host))
5354

55+
def after_world_start(self, data):
56+
world_start = packets.Variant("").parse(data.data)
57+
coords = world_start['config']['coordinate']
58+
if coords is not None:
59+
parent_system = coords['parentSystem']
60+
location = parent_system['location']
61+
l = location['data']
62+
self.protocol.player.on_ship = False
63+
planet = Planet(parent_system['sector'], l[0], l[1], l[2],
64+
coords['planetaryOrbitNumber'], coords['satelliteOrbitNumber'])
65+
self.protocol.player.planet = str(planet)
66+
else:
67+
self.protocol.player.on_ship = True
68+
5469
def on_client_disconnect(self, player):
55-
self.protocol.player.logged_in = False
70+
self.protocol.player.logged_in = False

packets/data_types.py

Lines changed: 31 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
from construct import Construct, Struct, Enum, Byte, Switch, BFloat64, Flag, \
2-
Array, LazyBound, Field, String, Container
1+
from construct import Construct, Struct, Byte, BFloat64, Flag, \
2+
Array, LazyBound, String, Container
33
from construct.core import _read_stream, _write_stream, Adapter
44

55

@@ -74,33 +74,32 @@ def _decode(self, obj, context):
7474
VLQ("length"),
7575
Array(lambda ctx: ctx.length,
7676
LazyBound("data",
77-
lambda: variant())))
78-
79-
dict_variant = Struct("data",
80-
VLQ("length"),
81-
Array(lambda ctx: ctx.length,
82-
Struct("dict",
83-
star_string("key"),
84-
LazyBound("value", lambda: variant()))))
85-
86-
variant = lambda name="variant": Struct(name,
87-
Enum(Byte("type"),
88-
NULL=1,
89-
DOUBLE=2,
90-
BOOL=3,
91-
SVLQ=4,
92-
STRING=5,
93-
VARIANT=6,
94-
DICT=7
95-
),
96-
Switch("data", lambda ctx: ctx.type,
97-
{
98-
"DOUBLE": BFloat64("data"),
99-
"BOOL": Flag("data"),
100-
"SVLQ": SignedVLQ("data"),
101-
"STRING": star_string(
102-
"data"),
103-
"VARIANT": variant_variant,
104-
"DICT": dict_variant
105-
},
106-
default=Field("null", 0)))
77+
lambda: Variant(""))))
78+
79+
class dict_variant(Construct):
80+
def _parse(self, stream, context):
81+
l = VLQ("").parse_stream(stream)
82+
c = {}
83+
for x in range(l):
84+
key = star_string("").parse_stream(stream)
85+
value = Variant("").parse_stream(stream)
86+
c[key] = value
87+
return c
88+
89+
class Variant(Construct):
90+
def _parse(self, stream, context):
91+
x = Byte("").parse_stream(stream)
92+
if x == 1:
93+
return None
94+
elif x == 2:
95+
return BFloat64("").parse_stream(stream)
96+
elif x == 3:
97+
return Flag("").parse_stream(stream)
98+
elif x == 4:
99+
return SignedVLQ("").parse_stream(stream)
100+
elif x == 5:
101+
return star_string().parse_stream(stream)
102+
elif x == 6:
103+
return variant_variant.parse_stream(stream)
104+
elif x == 7:
105+
return dict_variant("").parse_stream(stream)

packets/packet_types.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from construct import *
22
from enum import IntEnum
3-
from data_types import SignedVLQ, VLQ, variant, star_string
3+
from data_types import SignedVLQ, VLQ, Variant, star_string
44

55

66
class Direction(IntEnum):
@@ -38,7 +38,7 @@ class Packets(IntEnum):
3838
REQUEST_DROP = 26
3939
SPAWN_ENTITY = 27
4040
ENTITY_INTERACT = 28
41-
CONNECT_WIRE = 39
41+
CONNECT_WIRE = 29
4242
DISCONNECT_ALL_WIRES = 30
4343
OPEN_CONTAINER = 31
4444
CLOSE_CONTAINER = 32
@@ -119,7 +119,7 @@ def _decode(self, obj, context):
119119
VLQ("asset_digest_length"),
120120
String("asset_digest",
121121
lambda ctx: ctx.asset_digest_length),
122-
variant("claim"),
122+
Variant("claim"),
123123
Flag("uuid_exists"),
124124
If(lambda ctx: ctx.uuid_exists is True,
125125
HexAdapter(Field("uuid", 16))
@@ -200,7 +200,7 @@ def _decode(self, obj, context):
200200
Array(lambda ctx: ctx.count,
201201
Struct("properties",
202202
star_string("key"),
203-
variant("value"))))
203+
Variant("value"))))
204204

205205
update_world_properties_write = lambda dictionary: update_world_properties().build(
206206
Container(

plugin_manager.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def deactivate_plugins(self):
103103
for plugin in self.plugins:
104104
plugin.deactivate()
105105

106-
def do(self, protocol, command, data=None):
106+
def do(self, protocol, command, data):
107107
"""
108108
Runs a command across all currently loaded plugins.
109109
@@ -116,13 +116,16 @@ def do(self, protocol, command, data=None):
116116
"""
117117
return_values = []
118118
for plugin in self.plugins:
119-
if not plugin.active:
120-
continue
121-
plugin.protocol = protocol
122-
res = getattr(plugin, command, lambda _: True)(data)
123-
if res is None:
124-
res = True
125-
return_values.append(res)
119+
try:
120+
if not plugin.active:
121+
continue
122+
plugin.protocol = protocol
123+
res = getattr(plugin, command, lambda _: True)(data)
124+
if res is None:
125+
res = True
126+
return_values.append(res)
127+
except Exception as e:
128+
print "Error in plugin %s with function %s: %s" % (str(plugin), command, str(e))
126129
return all(return_values)
127130

128131
def get_by_name(self, name):

plugins/admin_commands_plugin/admin_command_plugin.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ def who(self, data):
4242
self.protocol.send_chat_message("Players online: %s" % " ".join(who))
4343
return False
4444

45+
def planet(self, data):
46+
"""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]
48+
self.protocol.send_chat_message("Players on your current planet: %s" % " ".join(who))
49+
4550
@permissions(UserLevels.ADMIN)
4651
def whois(self, data):
4752
name = " ".join(data)
@@ -61,7 +66,7 @@ def promote(self, data):
6166
name = " ".join(data[:-1])
6267
rank = data[-1].lower()
6368
player = self.player_manager.get_by_name(name)
64-
if player != None:
69+
if player is not None:
6570
old_rank = player.access_level
6671
if rank == "admin":
6772
self.make_admin(player)
@@ -75,9 +80,11 @@ def promote(self, data):
7580
self.protocol.send_chat_message("No such rank!\n"+usage)
7681
return
7782

78-
self.protocol.send_chat_message("%s: %s -> %s\n" % (
83+
self.protocol.send_chat_message("%s: %s -> %s" % (
7984
player.colored_name(self.config.colors), str(UserLevels(old_rank)).split(".")[1],
8085
rank.upper()))
86+
self.protocol.factory.protocols[player.protocol].send_chat_message("%s has promoted you to %s" % (
87+
player.colored_name(self.config.colors), rank.upper()))
8188
else:
8289
self.protocol.send_chat_message("Player not found!\n"+usage)
8390
return

plugins/announcer_plugin/announcer_plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,14 @@ def activate(self):
1313

1414
def after_connect_response(self, data):
1515
try:
16-
self.protocol.factory.broadcast (
16+
self.protocol.factory.broadcast(
1717
self.protocol.player.colored_name(self.config.colors) + " joined.", 0, "", "Announcer")
1818
except AttributeError as e:
1919
print "Attribute error: %s" % str(e)
2020
except Exception as e:
2121
print e
2222

23-
def after_client_disconnect(self, data):
23+
def on_client_disconnect(self, data):
2424
self.protocol.factory.broadcast(self.protocol.player.colored_name(self.config.colors) + " left.", 0,
2525
"", "Announcer")
2626

plugins/colored_names/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from colored_names import ColoredNames
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from base_plugin import BasePlugin
2+
from core_plugins.player_manager import permissions, UserLevels
3+
from packets import warp_command_write, Packets
4+
from packets.packet_types import chat_received, Packets
5+
from utility_functions import build_packet
6+
7+
8+
class ColoredNames(BasePlugin):
9+
"""
10+
Plugin that brings colors to player names in the chat box.
11+
"""
12+
name = "colored_names_plugin"
13+
depends = ['player_manager']
14+
auto_activate = True
15+
16+
def activate(self):
17+
super(ColoredNames, self).activate()
18+
self.player_manager = self.plugins['player_manager'].player_manager
19+
20+
def on_chat_received(self, data):
21+
try:
22+
p = chat_received().parse(data.data)
23+
sender = self.player_manager.get_logged_in_by_name(p.name)
24+
p.name = sender.colored_name(self.config.colors)
25+
self.protocol.transport.write(build_packet(Packets.CHAT_RECEIVED, chat_received().build(p)))
26+
except Exception as e:
27+
print e
28+
return True
29+
30+
return False
31+

plugins/planet_protect/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from planet_protect_plugin import PlanetProtectPlugin

0 commit comments

Comments
 (0)