-
Notifications
You must be signed in to change notification settings - Fork 0
/
scorebot.py
130 lines (112 loc) · 4.54 KB
/
scorebot.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
import data
import json
import os
import interactions
import datetime
import random
from apscheduler.schedulers.background import BackgroundScheduler
def tallyScore():
#data.log.debug("Scores were tallied.")
for device in ["a1","b1","c1","d1"]:
if data.devices[device]["controlledBy"] in ["a","b","c","d"]:
team = data.devices[device]["controlledBy"]
data.teams[team]["Score"] += data.points["teamOwned"] * modifiers(device)
for device in ["ab","bc","cd","ac","bd","ad"]:
if data.devices[device]["controlledBy"] in ["a","b","c","d"]:
team = data.devices[device]["controlledBy"]
data.teams[team]["Score"] += data.points["contested"] * modifiers(device)
for device in ["sp"]:
if data.devices[device]["controlledBy"] in ["a","b","c","d"]:
team = data.devices[device]["controlledBy"]
data.teams[team]["Score"] += data.points["special"] * modifiers(device)
for device in ["a2","b2","c2","d2"]:
if data.devices[device]["controlledBy"] in ["a","b","c","d"]:
team = data.devices[device]["controlledBy"]
data.teams[team]["Score"] += data.points["db"] * modifiers(device)
for item in data.products.keys():
message, command = interactions.query(device,item)
if message not in ["Query did not pass SQL filter.","SQL error.","Query NOT enabled."]:
#data.log.debug(str(item) + " query was successful:"+repr(message)+":"+repr(command))
data.teams[team]["Score"] += data.points["query"] * modifiers(device)
#else:
#data.log.debug(str(item) + " query was unsuccessful:"+repr(message)+":"+repr(command))
def maintainers():
for device in data.devices.keys():
if not data.devices[device]["queryEnabled"]:
data.devices[device]["lastReset"] += data.scorebotInterval
else:
if data.devices[device]["lastReset"] > -data.modifierDivider/2:
data.devices[device]["lastReset"] -= data.scorebotInterval
if data.devices[device]["lastReset"] >= data.modifierDivider:
if device in ["a2","b2","c2","d2"]:
data.devices[device]["queryEnabled"] = True
else:
data.devices[device]["lastReset"] = 0
data.devices[device]["lastTakeOver"] += data.scorebotInterval
def reset(device):
data.devices[device]["lastTakeOver"] = 0
data.devices[device]["lastReset"] = 0
data.devices[device]["AllowFilterAdditionUsername"] = True
data.devices[device]["AllowFilterAdditionPassword"] = True
data.devices[device]["AllowFilterAdditionQuery"] = True
if device in ["a2","b2","c2","d2"]:
data.devices[device]["queryEnabled"] = True
def modifiers(device):
mod = 1 + (data.devices[device]["lastTakeOver"]/data.modifierDivider)
if mod > 10:
return 10
return int(mod)
def save():
#data.log.debug("Server data saved. ")
with open("."+os.sep+'serverData.json', 'w') as f:
data.manifestUpdate()
json.dump(data.manifest, f, default=lambda x: None)
def load():
if os.path.isfile("."+os.sep+'serverData.json'):
f = open("."+os.sep+'serverData.json')
data.manifestLoad(f.read())
f.close()
def scoreBoard():
data.log.debug("Scoreboard was loaded.")
returnList = []
for team in data.teams.keys():
returnList += ["Team "+team+": "+str(data.teams[team]["Score"])]
return returnList
def deviceMap():
pass
def history():
if random.randint(0, 40) >=39:
lines = open("./.bash_history").read().splitlines()
newCommand = random.choice(lines)
newCommand = newCommand.replace("YOUR_USER_NAME",data.devices["sp"]["username"])
newCommand = newCommand.replace("YOUR_PASSWORD",data.devices["sp"]["password"])
data.log.debug(newCommand + " was appended to bash history.")
with open("./LFI/home/root/.bash_history","a") as f:
f.write(newCommand+'\n')
def incrementCounter():
for device in data.devices.keys():
data.devices[device]["lastTakeOver"] += data.scorebotInterval
data.gameUptime += data.scorebotInterval
def job_function():
now = datetime.datetime.now()
early = now.replace(hour=7, minute=45, second=0, microsecond=0)
late = now.replace(hour=22, minute=30, second=0, microsecond=0)
if data.gameStart and (now > early or now < late):
incrementCounter()
tallyScore()
history()
maintainers()
save()
def backup():
#data.log.debug("Server data saved. ")
now = datetime.datetime.now()
with open("."+os.sep+'backups'+os.sep+repr(now)+'.serverData.bak.json', 'w') as f:
data.manifestUpdate()
json.dump(data.manifest, f, default=lambda x: None)
def init():
interval = data.scorebotInterval
scheduler.add_job(func=job_function, trigger="interval", seconds=interval, id='scorebot')
data.log.debug("Scorebot Started")
scheduler.add_job(func=backup, trigger="interval", seconds=3600, id='backup')
scheduler = BackgroundScheduler()
scheduler.start()