-
Notifications
You must be signed in to change notification settings - Fork 37
Expand file tree
/
Copy pathspecies_whitelist.py
More file actions
56 lines (45 loc) · 1.89 KB
/
species_whitelist.py
File metadata and controls
56 lines (45 loc) · 1.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
"""
StarryPy species whitelist plugin
Prevents players with unknown species from joining the server.
This is necessary due to a year+ old "bug" detailed here:
https://community.playstarbound.com/threads/119569/
Original Authors: GermaniumSystem
"""
from base_plugin import BasePlugin
from data_parser import ConnectFailure
from packets import packets
from pparser import build_packet
class SpeciesWhitelist(BasePlugin):
name = "species_whitelist"
depends = ["player_manager"]
default_config = {"enabled": False,
"allowed_species": [
"apex",
"avian",
"glitch",
"floran",
"human",
"hylotl",
"penguin",
"novakid"
]}
def activate(self):
super().activate()
self.enabled = self.config.get_plugin_config(self.name)["enabled"]
self.allowed_species = self.config.get_plugin_config(self.name)["allowed_species"]
def on_client_connect(self, data, connection):
if not self.enabled:
return True
species = data['parsed']['species']
if species not in self.allowed_species:
self.logger.warn("Aborting connection - player's species ({}) "
"is not in whitelist.".format(species))
rejection_packet = build_packet(packets['connect_failure'],
ConnectFailure.build(dict(reason="^red;Connection "
"aborted!\n\n^orange;Your species ({}) is not "
"allowed on this server.\n^green;Please use a "
"different character.".format(species))))
yield from connection.raw_write(rejection_packet)
connection.die()
return False
return True