Skip to content

Commit

Permalink
Merge branch 'personal'
Browse files Browse the repository at this point in the history
  • Loading branch information
0n1udra committed May 21, 2022
2 parents 0c2a327 + 29405a4 commit 48976a8
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
11 changes: 6 additions & 5 deletions source/backend_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,10 +253,10 @@ async def server_rcon(command=''):

global server_active

server_rcon_client = mctools.RCONClient(server_ip, port=slime_vars.rcon_port)
server_rcon_client = mctools.RCONClient(slime_vars.server_ip, port=slime_vars.rcon_port)
try: server_rcon_client.login(slime_vars.rcon_pass)
except ConnectionError:
lprint(ctx, f"Error Connecting to RCON: {server_ip} : {slime_vars.rcon_port}")
lprint(ctx, f"Error Connecting to RCON: {slime_vars.server_ip} : {slime_vars.rcon_port}")
server_active = False
return False
else:
Expand Down Expand Up @@ -287,6 +287,7 @@ async def server_status(discord_msg=False):
else:
# server_command will send a discord message if server is inactive, so it's unneeded here.
lprint(ctx, "Server Status: Inactive")
if discord_msg: await channel_send("**Server INACTIVE** :red_circle:")
server_active = False

def server_start():
Expand Down Expand Up @@ -357,7 +358,7 @@ def ping_server():
global server_active

try:
ping = mctools.PINGClient(server_ip)
ping = mctools.PINGClient(slime_vars.server_url, slime_vars.server_port)
stats = ping.get_stats()
ping.stop()
except ConnectionRefusedError:
Expand All @@ -373,7 +374,7 @@ def ping_url():

ping = subprocess.Popen(['ping', '-c', '2', slime_vars.server_url], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
ping_out, ping_error = ping.communicate()
if server_ip in str(ping_out):
if slime_vars.server_ip in str(ping_out):
return 'working'
return 'inactive'

Expand Down Expand Up @@ -449,7 +450,7 @@ async def get_player_list():
if not response: return False

# Gets data from RCON response or reads server log for line containing player names.
if slime_vars.use_rcon is True: log_data = response
if slime_vars.use_rcon is True: log_data = response[0]
else:
await asyncio.sleep(1)
log_data = server_log('players online')
Expand Down
3 changes: 2 additions & 1 deletion source/slime_bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,8 @@ async def players(self, ctx):
else:
new_player_list = []
for i in player_list[0]:
new_player_list.append(f'**{i}** ({await backend_functions.get_location(i)}')
player_location = await backend_functions.get_location(i)
new_player_list.append(f'**{i.strip()}** ({player_location if player_location else "Location N/A"})')
await ctx.send(player_list[1] + '\n' + '\n'.join(new_player_list))
await ctx.send("-----END-----")

Expand Down
5 changes: 3 additions & 2 deletions source/slime_vars.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

# Server URL or IP address. In case you're using a DDNS or something.
server_url = 'arcpy.asuscomm.com'
server_port = 25566

# ========== Interfacing Options
# Local file access allows for server files/folders manipulation,for features like backup/restore world saves, editing server.properties file, and read server log.
Expand All @@ -28,7 +29,7 @@
tmux_session_name = 'sess'

# Use RCON to send commands to server. You won't be able to use some features like reading server logs.
use_rcon = False
use_rcon = True
rcon_pass = 'rconpass420'
rcon_port = 25575

Expand Down Expand Up @@ -88,7 +89,7 @@
server_log_file = f"{server_path}/logs/latest.log"
bot_log_file = f"{bot_files_path}/bot_log.txt"
updatable_mc = ['vanilla', 'papermc']
server_ip = '' # Will be updated by get_ip function in backend_functions.py on bot startup.
server_ip = server_url # Will be updated by get_ip function in backend_functions.py on bot startup.

if use_rcon is True: import mctools, re
if server_files_access is True: import shutil, fileinput, json

0 comments on commit 48976a8

Please sign in to comment.