-
Notifications
You must be signed in to change notification settings - Fork 13
/
jail.py
145 lines (134 loc) · 6.07 KB
/
jail.py
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
"""
Jail script by PXYC
/jail <player> [reason] jails a player. Default reason is "None"
/free <player> frees a player.
/jailed [player] checks if a player is jailed. If no arguments are entered, it lists jailed players.
/jailbreak frees all jailed players.
"""
from pyspades.common import to_coordinates, coordinates
from commands import add, admin, get_player, join_arguments, name, alias
from pyspades.constants import *
jail_location = 0, 0, 0 # x, y, z of the jail
jail_coords = [ ] # e.g. ["B4", "B5"]
jail_list = []
@name('jail')
@alias('j')
@admin
def jail_player(connection, value = None, *args):
protocol = connection.protocol # Meh
player = get_player(protocol, value) # Get player
reason = join_arguments(args[0:]) # Convert reason args into one string
if player not in protocol.players:
raise ValueError() # If player doesn't exist, raise error
else:
if player.jailed:
return 'Player ' + player.name + ' is already jailed!' # Player is already jailed!
elif not player.jailed:
player.jailed = True # Set player to jailed
player.reason = reason
player.squad = None
player.squad_pref = None
player.set_location(jail_location) # Move player to jail
connection.protocol.send_chat("%s was sent to jail by %s for reason(s): %s" % (player.name, connection.name, reason)) # Message
connection.protocol.irc_say("* %s jailed %s for reason: %s" % (connection.name, player.name, reason)) # Message
jail_list.append(player.name)
add(jail_player) # Add command
@name('jailed')
def is_jailed(connection, value = None):
if value is None:
if not jail_list:
return 'No jailed players.'
else:
return "Jailed players: " + ", ".join(jail_list)
elif value is not None:
protocol = connection.protocol
player = get_player(protocol, value)
if player not in protocol.players:
raise ValueError()
else:
if player.jailed:
return 'Player %s jailed for: %s' % (player.name, player.reason)
else:
return 'Player %s is not jailed.' % (player.name)
add(is_jailed)
@name('free')
@admin
def free_from_jail(connection, value):
protocol = connection.protocol # Meh
player = get_player(protocol, value) # Get player
if player not in protocol.players:
raise ValueError() # Errors again
else:
if not player.jailed: # If player isn't jailed
return 'Player ' + player.name + ' is not jailed!' # Message
elif player.jailed: # If player is jailed
player.jailed = False # Player is not jailed anymore
player.kill() # Kill the player
connection.protocol.send_chat("%s was freed from jail by %s" % (player.name, connection.name)) # Message
connection.protocol.irc_say('* %s was freed from jail by %s' % (player.name, connection.name)) # Message
jail_list.remove(player.name)
add(free_from_jail)
@name('jailbreak')
@admin
def free_all(connection):
protocol = connection.protocol
for playersJailed in jail_list:
player = get_player(protocol, playersJailed)
player.kill()
player.jailed = False
player.reason = None
jail_list.remove(playersJailed)
return 'All players freed.'
add(free_all)
def apply_script(protocol, connection, config):
class JailConnection(connection):
jailed = False
def on_spawn_location(self, pos):
if self.jailed:
return jail_location
return connection.on_spawn_location(self, pos)
def on_block_build_attempt(self, x, y, z):
x, y, z = self.get_location()
coord = to_coordinates(x, y)
if self.jailed:
self.send_chat("You can't build when you're jailed! You were jailed for %s" % (self.reason))
return False
elif coord in jail_coords and not self.user_types.admin: # Stuff
self.send_chat("You can't build near the jail, %s!" % self.name)
return False
return connection.on_block_build_attempt(self, x, y, z)
def on_block_destroy(self, x, y, z, mode):
x, y, z = self.get_location()
coord = to_coordinates(x, y)
if self.jailed:
self.send_chat("You can't destroy blocks when you're in jail! You were jailed for: %s" % (self.reason))
return False
elif coord in jail_coords and not self.user_types.admin:
self.send_chat("Stop trying to destroy the jail, %s!" % self.name)
return False
return connection.on_block_destroy(self, x, y, z, mode)
def on_line_build_attempt(self, points):
x, y, z = self.get_location()
coord = to_coordinates(x, y)
if self.jailed:
self.send_chat("You can't build when you're jailed! You were jailed for: %s" % (self.reason))
return False
elif coord in jail_coords and not self.user_types.admin:
self.send_chat("You can't build near the jail, %s!" % self.name)
return False
return connection.on_line_build_attempt(self, points)
def on_hit(self, hit_amount, player, type, grenade):
if self.jailed:
if self.name == player.name:
self.send_chat("Suicide isn't an option!")
return False
else:
self.send_chat("You can't hit people when you're jailed! You were jailed for: %s" % (self.reason))
return False
return connection.on_hit(self, hit_amount, player, type, grenade)
def on_disconnect(self):
if self.jailed:
jail_list.remove(self.name)
self.jailed = False
return connection.on_disconnect(self)
return protocol, JailConnection