update webhost
This commit is contained in:
parent
53744be44c
commit
ddc7be0794
|
@ -57,7 +57,7 @@ class Client(Endpoint):
|
||||||
|
|
||||||
class Context(Node):
|
class Context(Node):
|
||||||
def __init__(self, host: str, port: int, password: str, location_check_points: int, hint_cost: int,
|
def __init__(self, host: str, port: int, password: str, location_check_points: int, hint_cost: int,
|
||||||
item_cheat: bool, forfeit_mode: str = "disabled", remaining_mode: str = "disabled"):
|
item_cheat: bool, forfeit_mode: str = "disabled", remaining_mode: str = "disabled", auto_shutdown=0):
|
||||||
super(Context, self).__init__()
|
super(Context, self).__init__()
|
||||||
self.data_filename = None
|
self.data_filename = None
|
||||||
self.save_filename = None
|
self.save_filename = None
|
||||||
|
@ -88,7 +88,9 @@ class Context(Node):
|
||||||
typing.Tuple[int, int], datetime.datetime] = {} # datetime of last connection
|
typing.Tuple[int, int], datetime.datetime] = {} # datetime of last connection
|
||||||
self.client_game_state: typing.Dict[typing.Tuple[int, int], int] = collections.defaultdict(int)
|
self.client_game_state: typing.Dict[typing.Tuple[int, int], int] = collections.defaultdict(int)
|
||||||
self.er_hint_data: typing.Dict[int, typing.Dict[int, str]] = {}
|
self.er_hint_data: typing.Dict[int, typing.Dict[int, str]] = {}
|
||||||
|
self.auto_shutdown = 0
|
||||||
self.commandprocessor = ServerCommandProcessor(self)
|
self.commandprocessor = ServerCommandProcessor(self)
|
||||||
|
self.embedded_blacklist = {"host", "port"}
|
||||||
|
|
||||||
def load(self, multidatapath: str, use_embedded_server_options: bool = False):
|
def load(self, multidatapath: str, use_embedded_server_options: bool = False):
|
||||||
with open(multidatapath, 'rb') as f:
|
with open(multidatapath, 'rb') as f:
|
||||||
|
@ -111,10 +113,10 @@ class Context(Node):
|
||||||
self._set_options(server_options)
|
self._set_options(server_options)
|
||||||
|
|
||||||
def _set_options(self, server_options: dict):
|
def _set_options(self, server_options: dict):
|
||||||
blacklist = {"host", "port"}
|
|
||||||
sentinel = object()
|
sentinel = object()
|
||||||
for key, value in server_options.items():
|
for key, value in server_options.items():
|
||||||
if key not in blacklist:
|
if key not in self.blacklist:
|
||||||
current = getattr(self, key, sentinel)
|
current = getattr(self, key, sentinel)
|
||||||
if current is not sentinel:
|
if current is not sentinel:
|
||||||
logging.debug(f"Setting server option {key} to {value} from supplied multidata")
|
logging.debug(f"Setting server option {key} to {value} from supplied multidata")
|
||||||
|
@ -1061,6 +1063,9 @@ def parse_args() -> argparse.Namespace:
|
||||||
disabled: !remaining is never available
|
disabled: !remaining is never available
|
||||||
goal: !remaining can be used after goal completion
|
goal: !remaining can be used after goal completion
|
||||||
''')
|
''')
|
||||||
|
parser.add_argument('--auto_shutdown', default=defaults["auto_shutdown"], type=int,
|
||||||
|
help="automatically shut down the server after this many minutes without new location checks. "
|
||||||
|
"0 to keep running. Not yet implemented.")
|
||||||
parser.add_argument('--use_embedded_options', action="store_true",
|
parser.add_argument('--use_embedded_options', action="store_true",
|
||||||
help='retrieve forfeit, remaining and hint options from the multidata file,'
|
help='retrieve forfeit, remaining and hint options from the multidata file,'
|
||||||
' instead of host.yaml')
|
' instead of host.yaml')
|
||||||
|
@ -1068,11 +1073,15 @@ def parse_args() -> argparse.Namespace:
|
||||||
return args
|
return args
|
||||||
|
|
||||||
|
|
||||||
|
async def auto_shutdown(ctx):
|
||||||
|
# to be implemented soon
|
||||||
|
pass
|
||||||
|
|
||||||
async def main(args: argparse.Namespace):
|
async def main(args: argparse.Namespace):
|
||||||
logging.basicConfig(format='[%(asctime)s] %(message)s', level=getattr(logging, args.loglevel.upper(), logging.INFO))
|
logging.basicConfig(format='[%(asctime)s] %(message)s', level=getattr(logging, args.loglevel.upper(), logging.INFO))
|
||||||
|
|
||||||
ctx = Context(args.host, args.port, args.password, args.location_check_points, args.hint_cost,
|
ctx = Context(args.host, args.port, args.password, args.location_check_points, args.hint_cost,
|
||||||
not args.disable_item_cheat, args.forfeit_mode, args.remaining_mode)
|
not args.disable_item_cheat, args.forfeit_mode, args.remaining_mode, args.auto_shutdown)
|
||||||
|
|
||||||
data_filename = args.multidata
|
data_filename = args.multidata
|
||||||
|
|
||||||
|
|
|
@ -49,7 +49,7 @@ class Multiworld():
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
if self.process and self.process.is_alive():
|
if self.process and self.process.is_alive():
|
||||||
return
|
return False
|
||||||
logging.info(f"Spinning up {self.multidata}")
|
logging.info(f"Spinning up {self.multidata}")
|
||||||
self.process = multiprocessing.Process(group=None, target=run_server_process,
|
self.process = multiprocessing.Process(group=None, target=run_server_process,
|
||||||
args=(self.port, self.multidata),
|
args=(self.port, self.multidata),
|
||||||
|
@ -82,15 +82,7 @@ def upload_multidata():
|
||||||
file.save(os.path.join(multidata_folder, filename))
|
file.save(os.path.join(multidata_folder, filename))
|
||||||
return redirect(url_for('host_multidata',
|
return redirect(url_for('host_multidata',
|
||||||
filename=filename))
|
filename=filename))
|
||||||
return '''
|
return render_template("upload_multidata.html")
|
||||||
<!doctype html>
|
|
||||||
<title>Upload Multidata</title>
|
|
||||||
<h1>Upload Multidata</h1>
|
|
||||||
<form method=post enctype=multipart/form-data>
|
|
||||||
<input type=file name=file>
|
|
||||||
<input type=submit value=Upload>
|
|
||||||
</form>
|
|
||||||
'''
|
|
||||||
|
|
||||||
|
|
||||||
portlock = threading.Lock()
|
portlock = threading.Lock()
|
||||||
|
@ -147,13 +139,13 @@ def run_server_process(port: int, multidata: str):
|
||||||
ctx = Context("", port, "", 1, 1000,
|
ctx = Context("", port, "", 1, 1000,
|
||||||
True, "enabled", "goal")
|
True, "enabled", "goal")
|
||||||
ctx.load(multidata, True)
|
ctx.load(multidata, True)
|
||||||
|
ctx.auto_shutdown = 24 * 60 * 60 # 24 hours
|
||||||
ctx.init_save()
|
ctx.init_save()
|
||||||
|
|
||||||
ctx.server = websockets.serve(functools.partial(server, ctx=ctx), ctx.host, ctx.port, ping_timeout=None,
|
ctx.server = websockets.serve(functools.partial(server, ctx=ctx), ctx.host, ctx.port, ping_timeout=None,
|
||||||
ping_interval=None)
|
ping_interval=None)
|
||||||
|
|
||||||
logging.info('Hosting game at %s:%d (%s)' % (name, ctx.port,
|
logging.info(f'Hosting game at {name}:{ctx.port} (Password: {bool(ctx.password)})')
|
||||||
'No password' if not ctx.password else 'Password: %s' % ctx.password))
|
|
||||||
await ctx.server
|
await ctx.server
|
||||||
while ctx.running:
|
while ctx.running:
|
||||||
await asyncio.sleep(1)
|
await asyncio.sleep(1)
|
||||||
|
|
|
@ -13,7 +13,7 @@ Hosting {{ filename }} at {{ name }}:{{ port }}
|
||||||
|
|
||||||
xmlhttp.onreadystatechange = function () {
|
xmlhttp.onreadystatechange = function () {
|
||||||
if (this.readyState == 4 && this.status == 200) {
|
if (this.readyState == 4 && this.status == 200) {
|
||||||
myFunction(this.responseText);
|
document.getElementById("logger").innerText = this.responseText;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -23,10 +23,6 @@ Hosting {{ filename }} at {{ name }}:{{ port }}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function myFunction(text) {
|
|
||||||
document.getElementById("logger").innerText = text;
|
|
||||||
}
|
|
||||||
|
|
||||||
request_new();
|
request_new();
|
||||||
window.setInterval(request_new, 3000);
|
window.setInterval(request_new, 3000);
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
<!doctype html>
|
||||||
|
<title>Upload Multidata</title>
|
||||||
|
<h1>Upload Multidata</h1>
|
||||||
|
<form method=post enctype=multipart/form-data>
|
||||||
|
<input type=file name=file>
|
||||||
|
<input type=submit value=Upload>
|
||||||
|
</form>
|
|
@ -34,6 +34,8 @@ server_options:
|
||||||
# "goal" -> client can ask for remaining items after goal completion
|
# "goal" -> client can ask for remaining items after goal completion
|
||||||
# warning: only Berserker's Multiworld clients of version 2.1+ send game beaten information
|
# warning: only Berserker's Multiworld clients of version 2.1+ send game beaten information
|
||||||
remaining_mode: "goal"
|
remaining_mode: "goal"
|
||||||
|
# automatically shut down the server after this many minutes without new location checks, 0 to keep running
|
||||||
|
auto_shutdown: 0
|
||||||
#options for MultiMystery.py
|
#options for MultiMystery.py
|
||||||
multi_mystery_options:
|
multi_mystery_options:
|
||||||
#teams, however, note that there is currently no way to supply names for teams 2+ through MultiMystery
|
#teams, however, note that there is currently no way to supply names for teams 2+ through MultiMystery
|
||||||
|
|
Loading…
Reference in New Issue