import os
import time
import re
import math
from datetime import datetime
file_path = os.path.join(os.getenv('LOCALAPPDATA'), '..\LocalLow\Boundless Dynamics, LLC\VTOLVR\Player.log')
print('File written in \AppData\LocalLow\TheBoat')
if not os.path.exists(os.path.join(os.getenv('LOCALAPPDATA'), '..\LocalLow\TheBoat')):
os.makedirs(os.path.join(os.getenv('LOCALAPPDATA'), '..\LocalLow\TheBoat'))
current_time = datetime.now().strftime("%Y-%m-%d_%H-%M-%S")
write_path = os.path.join(os.getenv('LOCALAPPDATA'), '..\LocalLow\TheBoat\hop_' + current_time + ".log")
game_log_file = open(file_path, "r", encoding="utf8")
output_log_file = open(write_path, mode="a+", encoding="utf8")
output_log_file.write("")
#output_log_file.write(os.path.join(os.getenv('LOCALAPPDATA'), 'TheBoat'))
game_log = []
connection_log = []
mission_state = "none"
class pilot:
def __init__(self, name):
self.name = name
con_time = 0
last_conn = datetime.now()
def disconnect(self):
if (self.last_conn != 0):
connection_time = datetime.now() - self.last_conn
self.con_time = connection_time.total_seconds() + self.con_time
#add time since last join to total time in seconds
self.last_conn = 0
def get_name(self):
return self.name
def __str__(self):
con_hour = math.floor(self.con_time / (60 * 60))
con_min = math.floor(self.con_time / 60) - con_hour * 60
con_sec = math.floor(self.con_time) - (con_hour * (60 * 60) + con_min * 60)
con_out = ""
con_out += " " + str(con_hour) + " hour"
if con_hour != 1:
con_out += "s"
con_out += " " + str(con_min) + " minute"
if con_min != 1:
con_out += "s"
con_out += " " + str(con_sec) + " second"
if con_sec != 1:
con_out += "s"
return self.name + " connected for : " + con_out
def time_dif(start, end):
mission_time = end - start
mission_hours = math.floor(mission_time.total_seconds() / (60 * 60))
mission_minutes = math.floor(mission_time.total_seconds() / 60) - mission_hours * 60
mission_seconds = math.floor(mission_time.total_seconds()) - (mission_hours * (60 * 60) + mission_minutes * 60)
output = ""
output += " " + str(mission_hours) + " hour"
if mission_hours != 1:
output += "s"
output += " " + str(mission_minutes) + " minute"
if mission_minutes != 1:
output += "s"
output += " " + str(mission_seconds) + " second"
if mission_seconds != 1:
output += "s"
return output
def connect_user(user):
test_u = re.search("(.{1,20}? has disconnected)", user)
userName = re.split("( has d?i?s?connected)", user)[0]
try: test_u = test_u.group()
#if user is connecting this fails and goes to the exception
except AttributeError:
if userName not in connection_log:
connection_log.append(pilot(userName))
#adds username to connection log
return True
else:
for pilots in connection_log:
if pilots.get_name() == userName:
#checks if username is in the connection log
pilots.disconnect()
#removes username from connection log
return True
return False
while (True):
#game_log_file = open(file_path, "r")
if len(game_log_file.read().splitlines()) > len(game_log):
arr_len = len(game_log)
i = 1
game_log_file.seek(0, 0)
for line in game_log_file.read().splitlines():
if arr_len < i:
#OPERATE HERE
#print(line)
con = re.search("log_(.{1,20}? has d?i?s?connected)", line)
#player connect / disconnect
nmp = re.search("(Launching Multiplayer game for .*?:).*", line)
#lobby started with mission and map
begin_scenario = re.search("(Beginning the scenario at .*?).*", line)
#begin mission
end_mission = re.search("(Endmission - .*?).*", line)
#end mission
close_lobby = re.search("(LeaveLobby\(\).*?).*", line)
#close lobby
if con != None:
con = con.group()[4:]
current_time = datetime.now().strftime("%Y/%m/%d %H:%M:%S")
if connect_user(con):
print(current_time + " " + con)
output_log_file.write(current_time + " " + con + "\n")
output_log_file.flush()
elif nmp != None:
nmp = nmp.group().split("Multiplayer game for ")[1]
nmp = nmp.split(":", 1)[1]
current_time = datetime.now().strftime("%Y/%m/%d %H:%M:%S")
if mission_state == "started":
for pilots in connection_log:
pilots.disconnect()
print(pilots)
connection_log = []
print("Previous mission did not end!")
elif mission_state == "finished":
for pilots in connection_log:
pilots.disconnect()
print(pilots)
connection_log = []
print("New mission started without lobby close.")
print(current_time + " " + nmp)
output_log_file.write(current_time + " " + nmp + "\n")
output_log_file.flush()
mission_state = "lobby"
elif begin_scenario != None:
begin_scenario = begin_scenario.group()
mission_start_time = datetime.now()
#mission_start_time = datetime(2024, 1, 16, 10, 2, 6, 800) #used for testing, YYYY M D H m s ms
current_time = datetime.now().strftime("%Y/%m/%d %H:%M:%S")
print(current_time + " " + begin_scenario)
output_log_file.write(current_time + " " + begin_scenario + "\n")
output_log_file.flush()
mission_state = "started"
elif end_mission != None:
end_mission = end_mission.group()
current_time = datetime.now().strftime("%Y/%m/%d %H:%M:%S")
try: mission_start_time
except NameError:
print(current_time + " " + end_mission + " : ended with no start time set, joined after mission start?")
else:
print(current_time + " " + end_mission + " : lasting " + time_dif(mission_start_time, datetime.now()))
output_log_file.write(current_time + " " + end_mission + " : lasting " + time_dif(mission_start_time, datetime.now()) + "\n")
output_log_file.flush()
mission_state = "finished"
elif close_lobby != None:
close_lobby = close_lobby.group()
current_time = datetime.now().strftime("%Y/%m/%d %H:%M:%S")
try: mission_start_time
except NameError:
print(current_time + " " + close_lobby + " : ended with no start time set, joined after mission start?")
print("user : connection length :: users may be missing and time might be unreliable!")
else:
print(current_time + " " + close_lobby + " : lasting " + time_dif(mission_start_time, datetime.now()))
output_log_file.write(current_time + " " + close_lobby + " : lasting " + time_dif(mission_start_time, datetime.now()) + "\n")
print("user : connection length")
for pilots in connection_log:
pilots.disconnect()
print(pilots)
connection_log = []
output_log_file.flush()
mission_state = "none"
#/OPERATE HERE
game_log.append(line)
#print(connection_log)
i += 1
#print("longer: " + str(i))
game_log_file.seek(0, 0)
time.sleep(1)