Add twitch hyperlinking to webhost
This commit is contained in:
parent
e0e13ac59e
commit
6f9f5cbe14
|
@ -34,6 +34,7 @@ CLIENT_PLAYING = 0
|
|||
CLIENT_GOAL = 1
|
||||
|
||||
|
||||
|
||||
class Client(Endpoint):
|
||||
version: typing.List[int] = [0, 0, 0]
|
||||
tags: typing.List[str] = []
|
||||
|
@ -47,7 +48,7 @@ class Client(Endpoint):
|
|||
self.send_index = 0
|
||||
self.tags = []
|
||||
self.version = [0, 0, 0]
|
||||
self.messageprocessor = ClientMessageProcessor(ctx, self)
|
||||
self.messageprocessor = client_message_processor(ctx, self)
|
||||
self.ctx = weakref.ref(ctx)
|
||||
|
||||
@property
|
||||
|
@ -97,6 +98,7 @@ class Context(Node):
|
|||
self.auto_save_interval = 60 # in seconds
|
||||
self.auto_saver_thread = None
|
||||
self.save_dirty = False
|
||||
self.tags = ['Berserker']
|
||||
|
||||
def load(self, multidatapath: str, use_embedded_server_options: bool = False):
|
||||
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],
|
||||
# tags are for additional features in the communication.
|
||||
# Name them by feature or fork, as you feel is appropriate.
|
||||
'tags': ['Berserker'],
|
||||
'tags': ctx.tags,
|
||||
'version': Utils._version_tuple,
|
||||
'forfeit_mode': ctx.forfeit_mode,
|
||||
'remaining_mode': ctx.remaining_mode,
|
||||
'hint_cost' : ctx.hint_cost,
|
||||
'hint_cost': ctx.hint_cost,
|
||||
'location_check_points': ctx.location_check_points
|
||||
}]])
|
||||
|
||||
|
@ -1214,6 +1216,9 @@ async def main(args: argparse.Namespace):
|
|||
if ctx.shutdown_task:
|
||||
await ctx.shutdown_task
|
||||
|
||||
|
||||
client_message_processor = ClientMessageProcessor
|
||||
|
||||
if __name__ == '__main__':
|
||||
try:
|
||||
asyncio.run(main(parse_args()))
|
||||
|
|
|
@ -11,10 +11,25 @@ import random
|
|||
from WebHost import LOGS_FOLDER
|
||||
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
|
||||
|
||||
|
||||
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):
|
||||
def output(self, text: str):
|
||||
logging.info(text)
|
||||
|
@ -24,6 +39,8 @@ class WebHostContext(Context):
|
|||
def __init__(self):
|
||||
super(WebHostContext, self).__init__("", 0, "", 1, 40, True, "enabled", "enabled", 0)
|
||||
self.main_loop = asyncio.get_running_loop()
|
||||
self.video = {}
|
||||
self.tags = ["Berserker", "WebHost"]
|
||||
|
||||
def listen_to_db_commands(self):
|
||||
cmdprocessor = DBCommandProcessor(self)
|
||||
|
@ -63,6 +80,10 @@ class WebHostContext(Context):
|
|||
Room.get(id=self.room_id).multisave = self.get_save()
|
||||
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():
|
||||
return random.randint(49152, 65535)
|
||||
|
|
|
@ -64,7 +64,12 @@
|
|||
{% for player, items in players.items() %}
|
||||
<tr>
|
||||
<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 %}
|
||||
|
||||
{% if items[id] %}
|
||||
|
|
|
@ -235,11 +235,16 @@ def get_tracker(tracker: UUID):
|
|||
player_names[(team, player)] = name
|
||||
|
||||
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,
|
||||
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,
|
||||
multi_items=multi_items, checks_done=checks_done, ordered_areas=ordered_areas,
|
||||
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:
|
||||
flash("Could not load multidata. File may be corrupted or incompatible.")
|
||||
else:
|
||||
seed = Seed(multidata=multidata, owner=session["_id"], private=False)
|
||||
seed = Seed(multidata=multidata, owner=session["_id"])
|
||||
commit() # place into DB and generate ids
|
||||
return redirect(url_for("view_seed", seed=seed.id))
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue