Skip to content

Commit

Permalink
Merge pull request #38 from th3-z/master-fixes
Browse files Browse the repository at this point in the history
Master fixes
  • Loading branch information
Stephen720 authored Mar 9, 2018
2 parents afd43ea + 77f794a commit b76f8be
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 74 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.example -crlf
2 changes: 1 addition & 1 deletion build.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
cd magicked_admin
python setup.py build -b ../bin
python3 setup.py build -b ../bin
cd ..
2 changes: 2 additions & 0 deletions magicked_admin/chatbot/chatbot.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ def recieveMessage(self, username, message, admin=False):
self.command_handler(username, args, admin)

def command_handler(self, username, args, admin=False):
if args == None or len(args) == 0:
return
if args[0] in self.commands.command_map:
command = self.commands.command_map[args[0]]
response = command.execute(username, args, admin)
Expand Down
6 changes: 3 additions & 3 deletions magicked_admin/chatbot/commands/command_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ def generate_map(self):
'restart':CommandRestart(self.server),
'toggle_pass':CommandTogglePassword(self.server),
'silent':CommandSilent(self.server, self.chatbot),
'length':CommandLength(self.server, adminOnly=False),
'difficulty':CommandDifficulty(self.server, adminOnly=False),
'length':CommandLength(self.server),
'difficulty':CommandDifficulty(self.server),
'players':CommandPlayers(self.server, adminOnly=False),
'game':CommandGame(self.server, adminOnly=False),
'help':CommandHelp(self.server, adminOnly=False),
Expand All @@ -43,4 +43,4 @@ def generate_map(self):
'stats':CommandStats(self.server, adminOnly=False)
}

return map
return map
3 changes: 1 addition & 2 deletions magicked_admin/chatbot/commands/info_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ def execute(self, username, args, admin):
if not self.authorise(admin):
return self.not_auth_message
return "Player commands:\n !dosh, !kills, !top_dosh, " + \
"!top_kills, !difficulty, !length," + \
"!stats, !me, !info"
"!top_kills, !stats, !me, !info"

class CommandInfo(Command):
def __init__(self, server, adminOnly = True):
Expand Down
27 changes: 10 additions & 17 deletions magicked_admin/config/magicked_admin.conf.example
Original file line number Diff line number Diff line change
@@ -1,17 +1,10 @@
[server_one]
address = 127.0.0.1:8080
username = bot_username
password = bot_password
game_password = game_password
motd_scoreboard = True
map_autochange = True
multiadmin_enabled = True

[server_two]
address = 127.0.0.1:8081
username = bot_username
password = bot_password
game_password = game_password
motd_scoreboard = False
map_autochange = True
multiadmin_enabled = False
[server_one]
address = 127.0.0.1:8080
username = Admin
password = 123
game_password = game_password
motd_scoreboard = False
scoreboard_type = kills
map_autochange = False
multiadmin_enabled = False

1 change: 0 additions & 1 deletion magicked_admin/config/server_one.init.example
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
start_wc 1 say I'm a bot, type !help for usage
start_tc 10 say test
20 changes: 9 additions & 11 deletions magicked_admin/config/server_one.motd.example
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
kf.znel.org:2300 :: 173.199.74.63:23000 :: United Kingdom

Welcome to our server. To benefit from the server's increased tick rate its required that you raise your client's tick rate.

Top Players (total dosh):
1. %PLR [%SCR] 2. %PLR [%SCR] 3. %PLR [%SCR]
4. %PLR [%SCR] 5. %PLR [%SCR] 6. %PLR [%SCR]
7. %PLR [%SCR] 8. %PLR [%SCR] 9. %PLR [%SCR]

Have fun and good luck!

Welcome to our server.

Top Players (total dosh):
1. %PLR [%SCR] 2. %PLR [%SCR] 3. %PLR [%SCR]
4. %PLR [%SCR] 5. %PLR [%SCR] 6. %PLR [%SCR]
7. %PLR [%SCR] 8. %PLR [%SCR] 9. %PLR [%SCR]

Have fun and good luck!

62 changes: 31 additions & 31 deletions magicked_admin/database/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,62 +46,62 @@ def top_dosh(self):
return all_rows

def player_dosh(self, username):
self.cur.execute('SELECT (dosh) FROM players WHERE username="{un}"'.\
format(un=username))
self.cur.execute('SELECT (dosh) FROM players WHERE username=?',
(username,))
all_rows = self.cur.fetchall()
if all_rows:
return int(all_rows[0][0])
else:
return 0

def player_dosh_spent(self, username):
self.cur.execute('SELECT (dosh_spent) FROM players WHERE username="{un}"'.\
format(un=username))
self.cur.execute('SELECT (dosh_spent) FROM players WHERE username=?',
(username,))
all_rows = self.cur.fetchall()
if all_rows:
return int(all_rows[0][0])
else:
return 0

def player_kills(self, username):
self.cur.execute('SELECT (kills) FROM players WHERE username="{un}"'.\
format(un=username))
self.cur.execute('SELECT (kills) FROM players WHERE username=?',
(username,))
all_rows = self.cur.fetchall()
if all_rows:
return int(all_rows[0][0])
else:
return 0

def player_deaths(self, username):
self.cur.execute('SELECT (deaths) FROM players WHERE username="{un}"'.\
format(un=username))
self.cur.execute('SELECT (deaths) FROM players WHERE username=?',
(username,))
all_rows = self.cur.fetchall()
if all_rows:
return int(all_rows[0][0])
else:
return 0

def player_logins(self, username):
self.cur.execute('SELECT (logins) FROM players WHERE username="{un}"'.\
format(un=username))
self.cur.execute('SELECT (logins) FROM players WHERE username=?',
(username,))
all_rows = self.cur.fetchall()
if all_rows:
return int(all_rows[0][0])
else:
return 0

def player_time(self, username):
self.cur.execute('SELECT (time_online) FROM players WHERE username="{un}"'.\
format(un=username))
self.cur.execute('SELECT (time_online) FROM players WHERE username=?',
(username,))
all_rows = self.cur.fetchall()
if all_rows:
return int(all_rows[0][0])
else:
return 0

def player_health_lost(self, username):
self.cur.execute('SELECT (health_lost) FROM players WHERE username="{un}"'.\
format(un=username))
self.cur.execute('SELECT (health_lost) FROM players WHERE username=?',
(username,))
all_rows = self.cur.fetchall()
if all_rows:
return int(all_rows[0][0])
Expand All @@ -118,30 +118,30 @@ def load_player(self, player):
player.total_time = self.player_time(player.username)

def save_player(self, player, final=False):
self.cur.execute("INSERT OR IGNORE INTO players (username) VALUES (?)",\
(player.username,))

self.cur.execute("UPDATE players SET dosh_spent = ? WHERE username = ?",\
(player.total_dosh_spent, player.username))
self.cur.execute("UPDATE players SET dosh = ? WHERE username = ?",\
(player.total_dosh, player.username))
self.cur.execute("UPDATE players SET kills = ? WHERE username = ?",\
(player.total_kills, player.username))
self.cur.execute("UPDATE players SET deaths = ? WHERE username = ?",\
(player.total_deaths, player.username))
self.cur.execute("UPDATE players SET health_lost = ? WHERE username = ?",\
(player.total_health_lost, player.username))
self.cur.execute("UPDATE players SET logins = ? WHERE username = ?",\
(player.total_logins, player.username))
self.cur.execute("INSERT OR IGNORE INTO players (username) VALUES (?)",
(player.username,))

self.cur.execute("UPDATE players SET dosh_spent = ? WHERE username = ?",
(player.total_dosh_spent, player.username))
self.cur.execute("UPDATE players SET dosh = ? WHERE username = ?",
(player.total_dosh, player.username))
self.cur.execute("UPDATE players SET kills = ? WHERE username = ?",
(player.total_kills, player.username))
self.cur.execute("UPDATE players SET deaths = ? WHERE username = ?",
(player.total_deaths, player.username))
self.cur.execute("UPDATE players SET health_lost = ? WHERE username = ?",
(player.total_health_lost, player.username))
self.cur.execute("UPDATE players SET logins = ? WHERE username = ?",
(player.total_logins, player.username))

if final:
now = datetime.datetime.now()
elapsed_time = now - player.session_start
seconds = elapsed_time.total_seconds()
new_time = player.total_time + seconds

self.cur.execute("UPDATE players SET time_online = ? WHERE username = ?",\
(new_time, player.username))
self.cur.execute("UPDATE players SET time_online = ? WHERE username = ?",
(new_time, player.username))

self.conn.commit()

Expand Down
3 changes: 2 additions & 1 deletion magicked_admin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ def run(self):
password = config[server_name]["password"]
game_password = config[server_name]["game_password"]
motd_scoreboard = str_to_bool(config[server_name]["motd_scoreboard"])
scoreboard_type = config[server_name]["scoreboard_type"]
map_autochange = str_to_bool(config[server_name]["map_autochange"])
multiadmin_enabled = str_to_bool(config[server_name]["multiadmin_enabled"])

Expand All @@ -47,7 +48,7 @@ def run(self):
self.watchdogs.append(wd)

if motd_scoreboard:
motd_updater = MotdUpdater(server)
motd_updater = MotdUpdater(server, scoreboard_type)
motd_updater.start()
self.motd_updaters.append(motd_updater)

Expand Down
11 changes: 9 additions & 2 deletions magicked_admin/server/managers/motd_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

class MotdUpdater(threading.Thread):

def __init__(self, server):
def __init__(self, server, scoreboard_type):
self.server = server

self.scoreboard_type = scoreboard_type
self.time_interval = 5 * 60
self.motd = self.load_motd()

Expand Down Expand Up @@ -56,7 +57,13 @@ def load_motd(self):
return motd

def render_motd(self, src_motd):
scores = self.server.database.top_kills()
if self.scoreboard_type in ['kills','Kills','kill','Kill']:
scores = self.server.database.top_kills()
elif self.scoreboard_type in ['Dosh','dosh']:
scores = self.server.database.top_dosh()
else:
print("ERROR: Bad configuration, scoreboard_type. Options are: dosh, kills")
return

for player in scores:
name = player[0].replace("<","&lt;")
Expand Down
14 changes: 9 additions & 5 deletions magicked_admin/setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
import sys
from cx_Freeze import setup, Executable

# Dependencies are automatically detected, but it might need fine tuning.


# GUI applications require a different base on Windows (the default is for a
# console application).
base = None

includefiles = [
('database/server_schema.sql','database/server_schema.sql'),
('config/magicked_admin.conf.example','magicked_admin.conf'),
('config/server_one.init.example','server_one.init'),
('config/server_one.motd.example','server_one.motd')
]

build_exe_options={
"packages": ["os", "queue", "idna", "lxml", "requests", "encodings"],
"excludes": ["tkinter"],
"includes": [],
"include_files": [],
"include_files": includefiles,
"include_msvcr": True,
"zip_include_packages": "*",
"zip_exclude_packages": ""
Expand All @@ -28,4 +32,4 @@
icon="icon.ico"
)
]
)
)

0 comments on commit b76f8be

Please sign in to comment.