forked from MEDVEDx64/FunkyStore
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rcon.py
55 lines (46 loc) · 1.27 KB
/
rcon.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
import mcrcon
import threading
from config import config
from time import sleep
def get_rcon():
rcfg = config['rconServer']
r = mcrcon.MCRcon()
r.connect(rcfg['host'], rcfg['port'])
r.login(rcfg['password'])
return r
class DetachedRconExecutor(threading.Thread):
def __init__(self):
super(DetachedRconExecutor, self).__init__()
self.rcon = get_rcon()
def execute(self):
pass
def run(self):
try:
self.execute()
finally:
self.rcon.disconnect()
class AnyCommandExecutor(DetachedRconExecutor):
def __init__(self, cmd):
super(AnyCommandExecutor, self).__init__()
self.cmd = cmd
def execute(self):
self.rcon.command(self.cmd)
class Teleporter(AnyCommandExecutor):
def __init__(self, nick, x, y, z):
super(Teleporter, self).__init__('tp ' + nick + ' ' + str(x) + ' ' + str(y) + ' ' + str(z))
class ItemSender(DetachedRconExecutor):
def __init__(self, nick, item_id, amount=1, data=0):
super(ItemSender, self).__init__()
self.nick = nick
self.item_id = item_id
self.amount = amount
self.data = data
def execute(self):
amount_left = self.amount
while amount_left > 0:
c = 64
if amount_left < 64:
c = amount_left
amount_left -= c
self.rcon.command('give ' + self.nick + ' ' + self.item_id + ' ' + str(c) + ' ' + self.data)
sleep(0.5)