Add twitch hyperlinking to webhost
This commit is contained in:
parent
e0e13ac59e
commit
6f9f5cbe14
|
@ -34,6 +34,7 @@ CLIENT_PLAYING = 0
|
||||||
CLIENT_GOAL = 1
|
CLIENT_GOAL = 1
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Client(Endpoint):
|
class Client(Endpoint):
|
||||||
version: typing.List[int] = [0, 0, 0]
|
version: typing.List[int] = [0, 0, 0]
|
||||||
tags: typing.List[str] = []
|
tags: typing.List[str] = []
|
||||||
|
@ -47,7 +48,7 @@ class Client(Endpoint):
|
||||||
self.send_index = 0
|
self.send_index = 0
|
||||||
self.tags = []
|
self.tags = []
|
||||||
self.version = [0, 0, 0]
|
self.version = [0, 0, 0]
|
||||||
self.messageprocessor = ClientMessageProcessor(ctx, self)
|
self.messageprocessor = client_message_processor(ctx, self)
|
||||||
self.ctx = weakref.ref(ctx)
|
self.ctx = weakref.ref(ctx)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -97,6 +98,7 @@ class Context(Node):
|
||||||
self.auto_save_interval = 60 # in seconds
|
self.auto_save_interval = 60 # in seconds
|
||||||
self.auto_saver_thread = None
|
self.auto_saver_thread = None
|
||||||
self.save_dirty = False
|
self.save_dirty = False
|
||||||
|
self.tags = ['Berserker']
|
||||||
|
|
||||||
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:
|
||||||
|
@ -329,11 +331,11 @@ async def on_client_connected(ctx: Context, client: Client):
|
||||||
in ctx.endpoints if client.auth],
|
in ctx.endpoints if client.auth],
|
||||||
# tags are for additional features in the communication.
|
# tags are for additional features in the communication.
|
||||||
# Name them by feature or fork, as you feel is appropriate.
|
# Name them by feature or fork, as you feel is appropriate.
|
||||||
'tags': ['Berserker'],
|
'tags': ctx.tags,
|
||||||
'version': Utils._version_tuple,
|
'version': Utils._version_tuple,
|
||||||
'forfeit_mode': ctx.forfeit_mode,
|
'forfeit_mode': ctx.forfeit_mode,
|
||||||
'remaining_mode': ctx.remaining_mode,
|
'remaining_mode': ctx.remaining_mode,
|
||||||
'hint_cost' : ctx.hint_cost,
|
'hint_cost': ctx.hint_cost,
|
||||||
'location_check_points': ctx.location_check_points
|
'location_check_points': ctx.location_check_points
|
||||||
}]])
|
}]])
|
||||||
|
|
||||||
|
@ -1214,6 +1216,9 @@ async def main(args: argparse.Namespace):
|
||||||
if ctx.shutdown_task:
|
if ctx.shutdown_task:
|
||||||
await ctx.shutdown_task
|
await ctx.shutdown_task
|
||||||
|
|
||||||
|
|
||||||
|
client_message_processor = ClientMessageProcessor
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
asyncio.run(main(parse_args()))
|
asyncio.run(main(parse_args()))
|
||||||
|
|
|
@ -11,10 +11,25 @@ import random
|
||||||
from WebHost import LOGS_FOLDER
|
from WebHost import LOGS_FOLDER
|
||||||
from .models import *
|
from .models import *
|
||||||
|
|
||||||
from MultiServer import Context, server, auto_shutdown, ServerCommandProcessor
|
from MultiServer import Context, server, auto_shutdown, ServerCommandProcessor, ClientMessageProcessor
|
||||||
from Utils import get_public_ipv4, get_public_ipv6
|
from Utils import get_public_ipv4, get_public_ipv6
|
||||||
|
|
||||||
|
|
||||||
|
class CustomClientMessageProcessor(ClientMessageProcessor):
|
||||||
|
def _cmd_video(self, platform, user):
|
||||||
|
if platform.lower().startswith("t"): # twitch
|
||||||
|
self.ctx.video[self.client.team, self.client.slot] = "Twitch", user
|
||||||
|
self.ctx.save()
|
||||||
|
self.output(f"Registered Twitch Stream https://www.twitch.tv/{user}")
|
||||||
|
|
||||||
|
|
||||||
|
# inject
|
||||||
|
import MultiServer
|
||||||
|
|
||||||
|
MultiServer.client_message_processor = CustomClientMessageProcessor
|
||||||
|
del (MultiServer)
|
||||||
|
|
||||||
|
|
||||||
class DBCommandProcessor(ServerCommandProcessor):
|
class DBCommandProcessor(ServerCommandProcessor):
|
||||||
def output(self, text: str):
|
def output(self, text: str):
|
||||||
logging.info(text)
|
logging.info(text)
|
||||||
|
@ -24,6 +39,8 @@ class WebHostContext(Context):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(WebHostContext, self).__init__("", 0, "", 1, 40, True, "enabled", "enabled", 0)
|
super(WebHostContext, self).__init__("", 0, "", 1, 40, True, "enabled", "enabled", 0)
|
||||||
self.main_loop = asyncio.get_running_loop()
|
self.main_loop = asyncio.get_running_loop()
|
||||||
|
self.video = {}
|
||||||
|
self.tags = ["Berserker", "WebHost"]
|
||||||
|
|
||||||
def listen_to_db_commands(self):
|
def listen_to_db_commands(self):
|
||||||
cmdprocessor = DBCommandProcessor(self)
|
cmdprocessor = DBCommandProcessor(self)
|
||||||
|
@ -63,6 +80,10 @@ class WebHostContext(Context):
|
||||||
Room.get(id=self.room_id).multisave = self.get_save()
|
Room.get(id=self.room_id).multisave = self.get_save()
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def get_save(self) -> dict:
|
||||||
|
d = super(WebHostContext, self).get_save()
|
||||||
|
d["video"] = [(tuple(playerslot), videodata) for playerslot, videodata in self.video.items()]
|
||||||
|
return d
|
||||||
|
|
||||||
def get_random_port():
|
def get_random_port():
|
||||||
return random.randint(49152, 65535)
|
return random.randint(49152, 65535)
|
||||||
|
|
|
@ -64,7 +64,12 @@
|
||||||
{% for player, items in players.items() %}
|
{% for player, items in players.items() %}
|
||||||
<tr>
|
<tr>
|
||||||
<td class="table-info">{{ loop.index }}</td>
|
<td class="table-info">{{ loop.index }}</td>
|
||||||
<td class="table-info">{{ player_names[(team, loop.index)] }}</td>
|
{% if (team, loop.index) in video %}
|
||||||
|
<td class="table-info"><a target="_blank"
|
||||||
|
href="https://www.twitch.tv/{{ video[(team, loop.index)][1] }}">{{ player_names[(team, loop.index)] }}
|
||||||
|
📺</a></td>
|
||||||
|
{% else %}
|
||||||
|
<td class="table-info">{{ player_names[(team, loop.index)] }}</td>{% endif %}
|
||||||
{% for id in tracking_ids %}
|
{% for id in tracking_ids %}
|
||||||
|
|
||||||
{% if items[id] %}
|
{% if items[id] %}
|
||||||
|
|
|
@ -235,11 +235,16 @@ def get_tracker(tracker: UUID):
|
||||||
player_names[(team, player)] = name
|
player_names[(team, player)] = name
|
||||||
|
|
||||||
for (team, player), alias in room.multisave.get("name_aliases", []):
|
for (team, player), alias in room.multisave.get("name_aliases", []):
|
||||||
player_names[team, player] = alias
|
player_names[(team, player)] = alias
|
||||||
|
|
||||||
|
video = {}
|
||||||
|
for (team, player), data in room.multisave.get("video", []):
|
||||||
|
video[(team, player)] = data
|
||||||
|
|
||||||
return render_template("tracker.html", inventory=inventory, get_item_name_from_id=get_item_name_from_id,
|
return render_template("tracker.html", inventory=inventory, get_item_name_from_id=get_item_name_from_id,
|
||||||
lookup_id_to_name=Items.lookup_id_to_name, player_names=player_names,
|
lookup_id_to_name=Items.lookup_id_to_name, player_names=player_names,
|
||||||
tracking_names=tracking_names, tracking_ids=tracking_ids, room=room, icons=icons,
|
tracking_names=tracking_names, tracking_ids=tracking_ids, room=room, icons=icons,
|
||||||
multi_items=multi_items, checks_done=checks_done, ordered_areas=ordered_areas,
|
multi_items=multi_items, checks_done=checks_done, ordered_areas=ordered_areas,
|
||||||
checks_in_area=checks_in_area, activity_timers=activity_timers,
|
checks_in_area=checks_in_area, activity_timers=activity_timers,
|
||||||
key_locations=key_locations, small_key_ids=small_key_ids, big_key_ids=big_key_ids)
|
key_locations=key_locations, small_key_ids=small_key_ids, big_key_ids=big_key_ids,
|
||||||
|
video=video)
|
||||||
|
|
|
@ -64,7 +64,7 @@ def upload_game():
|
||||||
except:
|
except:
|
||||||
flash("Could not load multidata. File may be corrupted or incompatible.")
|
flash("Could not load multidata. File may be corrupted or incompatible.")
|
||||||
else:
|
else:
|
||||||
seed = Seed(multidata=multidata, owner=session["_id"], private=False)
|
seed = Seed(multidata=multidata, owner=session["_id"])
|
||||||
commit() # place into DB and generate ids
|
commit() # place into DB and generate ids
|
||||||
return redirect(url_for("view_seed", seed=seed.id))
|
return redirect(url_for("view_seed", seed=seed.id))
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue