1
+ """
2
+ /rapid [player] will put the player in rapid mode, speeding up all tools
3
+ including weapons.
4
+
5
+ RAPID_BLOCK_DELAY determines how fast block placement should be.
6
+ Lowering this value is not recommended except for local use. Ping to the server
7
+ is the effective lower limit: if this value is set to 0.1 (0.1 seconds = 100ms),
8
+ users with ping above that won't have the same advantage as the rest of the
9
+ players.
10
+
11
+ Set ALWAYS_RAPID to TRUE to automatically get rapid when you login.
12
+
13
+ Mantainer: hompy
14
+ """
15
+
16
+ from twisted .internet .reactor import callLater
17
+ from twisted .internet .task import LoopingCall
18
+ from pyspades .server import set_tool
19
+ from pyspades .constants import *
20
+ from commands import add , admin , get_player , name
21
+
22
+ ALWAYS_RAPID = False
23
+ RAPID_INTERVAL = 0.08
24
+ RAPID_BLOCK_DELAY = 0.26
25
+
26
+ @name ('rapid' )
27
+ @admin
28
+ def toggle_rapid (connection , player = None ):
29
+ protocol = connection .protocol
30
+ if player is not None :
31
+ player = get_player (protocol , player )
32
+ elif connection in protocol .players :
33
+ player = connection
34
+ else :
35
+ raise ValueError ()
36
+
37
+ player .rapid = rapid = not player .rapid
38
+ player .rapid_hack_detect = not rapid
39
+ if rapid :
40
+ player .rapid_loop = LoopingCall (resend_tool , player )
41
+ else :
42
+ if player .rapid_loop and player .rapid_loop .running :
43
+ player .rapid_loop .stop ()
44
+ player .rapid_loop = None
45
+
46
+ message = 'now rapid' if rapid else 'no longer rapid'
47
+ player .send_chat ("You're %s" % message )
48
+ if connection is not player and connection in protocol .players :
49
+ connection .send_chat ('%s is %s' % (player .name , message ))
50
+ protocol .irc_say ('* %s is %s' % (player .name , message ))
51
+
52
+ def resend_tool (player ):
53
+ set_tool .player_id = player .player_id
54
+ set_tool .value = player .tool
55
+ if player .weapon_object .shoot :
56
+ player .protocol .send_contained (set_tool )
57
+ else :
58
+ player .send_contained (set_tool )
59
+
60
+ add (toggle_rapid )
61
+
62
+ @name ('srap' )
63
+ @admin
64
+ def toggle_rapid_silent (connection , player = None ):
65
+ protocol = connection .protocol
66
+ if player is not None :
67
+ player = get_player (protocol , player )
68
+ elif connection in protocol .players :
69
+ player = connection
70
+ else :
71
+ raise ValueError ()
72
+
73
+ player .rapid = rapid = not player .rapid
74
+ player .rapid_hack_detect = not rapid
75
+ if rapid :
76
+ player .rapid_loop = LoopingCall (resend_tool , player )
77
+ else :
78
+ if player .rapid_loop and player .rapid_loop .running :
79
+ player .rapid_loop .stop ()
80
+ player .rapid_loop = None
81
+
82
+ message = 'now rapid' if rapid else 'no longer rapid'
83
+ if connection is not player and connection in protocol .players :
84
+ connection .send_chat ('%s is %s' % (player .name , message ))
85
+ protocol .irc_say ('* %s is %s' % (player .name , message ))
86
+
87
+ add (toggle_rapid_silent )
88
+
89
+
90
+ def apply_script (protocol , connection , config ):
91
+ class RapidConnection (connection ):
92
+ rapid = False
93
+ rapid_loop = None
94
+
95
+ def on_login (self , name ):
96
+ self .rapid = ALWAYS_RAPID
97
+ self .rapid_hack_detect = not self .rapid
98
+ connection .on_login (self , name )
99
+
100
+ def on_reset (self ):
101
+ if self .rapid_loop and self .rapid_loop .running :
102
+ self .rapid_loop .stop ()
103
+ connection .on_reset (self )
104
+
105
+ def on_disconnect (self ):
106
+ self .rapid = False
107
+ if self .rapid_loop and self .rapid_loop .running :
108
+ self .rapid_loop .stop ()
109
+ self .rapid_loop = None
110
+ connection .on_disconnect (self )
111
+
112
+ def on_block_build (self , x , y , z ):
113
+ if self .rapid :
114
+ delay = max (0.0 , RAPID_BLOCK_DELAY - self .latency / 1000.0 )
115
+ if delay > 0.0 :
116
+ callLater (delay , resend_tool , self )
117
+ else :
118
+ resend_tool (self )
119
+ connection .on_block_build (self , x , y , z )
120
+
121
+ def on_grenade_thrown (self , grenade ):
122
+ if self .rapid :
123
+ resend_tool (self )
124
+ connection .on_grenade_thrown (self , grenade )
125
+
126
+ def on_shoot_set (self , fire ):
127
+ if self .rapid and self .rapid_loop :
128
+ if not self .rapid_loop .running and fire :
129
+ self .rapid_loop .start (RAPID_INTERVAL )
130
+ elif self .rapid_loop .running and not fire :
131
+ self .rapid_loop .stop ()
132
+ connection .on_shoot_set (self , fire )
133
+
134
+ return protocol , RapidConnection
0 commit comments