-
Notifications
You must be signed in to change notification settings - Fork 13
/
rapid.py
134 lines (111 loc) · 4.49 KB
/
rapid.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
"""
/rapid [player] will put the player in rapid mode, speeding up all tools
including weapons.
RAPID_BLOCK_DELAY determines how fast block placement should be.
Lowering this value is not recommended except for local use. Ping to the server
is the effective lower limit: if this value is set to 0.1 (0.1 seconds = 100ms),
users with ping above that won't have the same advantage as the rest of the
players.
Set ALWAYS_RAPID to TRUE to automatically get rapid when you login.
Mantainer: hompy
"""
from twisted.internet.reactor import callLater
from twisted.internet.task import LoopingCall
from pyspades.server import set_tool
from pyspades.constants import *
from commands import add, admin, get_player, name
ALWAYS_RAPID = False
RAPID_INTERVAL = 0.08
RAPID_BLOCK_DELAY = 0.26
@name('rapid')
@admin
def toggle_rapid(connection, player = None):
protocol = connection.protocol
if player is not None:
player = get_player(protocol, player)
elif connection in protocol.players:
player = connection
else:
raise ValueError()
player.rapid = rapid = not player.rapid
player.rapid_hack_detect = not rapid
if rapid:
player.rapid_loop = LoopingCall(resend_tool, player)
else:
if player.rapid_loop and player.rapid_loop.running:
player.rapid_loop.stop()
player.rapid_loop = None
message = 'now rapid' if rapid else 'no longer rapid'
player.send_chat("You're %s" % message)
if connection is not player and connection in protocol.players:
connection.send_chat('%s is %s' % (player.name, message))
protocol.irc_say('* %s is %s' % (player.name, message))
def resend_tool(player):
set_tool.player_id = player.player_id
set_tool.value = player.tool
if player.weapon_object.shoot:
player.protocol.send_contained(set_tool)
else:
player.send_contained(set_tool)
add(toggle_rapid)
@name('srap')
@admin
def toggle_rapid_silent(connection, player = None):
protocol = connection.protocol
if player is not None:
player = get_player(protocol, player)
elif connection in protocol.players:
player = connection
else:
raise ValueError()
player.rapid = rapid = not player.rapid
player.rapid_hack_detect = not rapid
if rapid:
player.rapid_loop = LoopingCall(resend_tool, player)
else:
if player.rapid_loop and player.rapid_loop.running:
player.rapid_loop.stop()
player.rapid_loop = None
message = 'now rapid' if rapid else 'no longer rapid'
if connection is not player and connection in protocol.players:
connection.send_chat('%s is %s' % (player.name, message))
protocol.irc_say('* %s is %s' % (player.name, message))
add(toggle_rapid_silent)
def apply_script(protocol, connection, config):
class RapidConnection(connection):
rapid = False
rapid_loop = None
def on_login(self, name):
self.rapid = ALWAYS_RAPID
self.rapid_hack_detect = not self.rapid
connection.on_login(self, name)
def on_reset(self):
if self.rapid_loop and self.rapid_loop.running:
self.rapid_loop.stop()
connection.on_reset(self)
def on_disconnect(self):
self.rapid = False
if self.rapid_loop and self.rapid_loop.running:
self.rapid_loop.stop()
self.rapid_loop = None
connection.on_disconnect(self)
def on_block_build(self, x, y, z):
if self.rapid:
delay = max(0.0, RAPID_BLOCK_DELAY - self.latency / 1000.0)
if delay > 0.0:
callLater(delay, resend_tool, self)
else:
resend_tool(self)
connection.on_block_build(self, x, y, z)
def on_grenade_thrown(self, grenade):
if self.rapid:
resend_tool(self)
connection.on_grenade_thrown(self, grenade)
def on_shoot_set(self, fire):
if self.rapid and self.rapid_loop:
if not self.rapid_loop.running and fire:
self.rapid_loop.start(RAPID_INTERVAL)
elif self.rapid_loop.running and not fire:
self.rapid_loop.stop()
connection.on_shoot_set(self, fire)
return protocol, RapidConnection