mirror of
https://github.com/jiojciojsioe3/a3cjroijsiojiorj.git
synced 2024-11-24 11:51:50 +08:00
allow 2p url config, origin limiting for server
This commit is contained in:
parent
0c39e54d90
commit
7f511abb4f
3
app.py
3
app.py
@ -135,7 +135,8 @@ def get_config(credentials=False):
|
||||
'accounts': take_config('ACCOUNTS'),
|
||||
'custom_js': take_config('CUSTOM_JS'),
|
||||
'plugins': take_config('PLUGINS') and [x for x in take_config('PLUGINS') if x['url']],
|
||||
'preview_type': take_config('PREVIEW_TYPE') or 'mp3'
|
||||
'preview_type': take_config('PREVIEW_TYPE') or 'mp3',
|
||||
'multiplayer_url': take_config('MULTIPLAYER_URL')
|
||||
}
|
||||
if credentials:
|
||||
google_credentials = take_config('GOOGLE_CREDENTIALS')
|
||||
|
@ -4,6 +4,9 @@ ASSETS_BASEURL = '/assets/'
|
||||
# The full URL base song URL, with trailing slash.
|
||||
SONGS_BASEURL = '/songs/'
|
||||
|
||||
# Multiplayer websocket URL. Defaults to /p2 if blank.
|
||||
MULTIPLAYER_URL = ''
|
||||
|
||||
# The email address to display in the "About Simulator" menu.
|
||||
EMAIL = None
|
||||
|
||||
|
@ -32,7 +32,7 @@ class P2Connection{
|
||||
if(this.closed && !this.disabled){
|
||||
this.closed = false
|
||||
var wsProtocol = location.protocol == "https:" ? "wss:" : "ws:"
|
||||
this.socket = new WebSocket(wsProtocol + "//" + location.host + "/p2")
|
||||
this.socket = new WebSocket(gameConfig.multiplayer_url ? gameConfig.multiplayer_url : wsProtocol + "//" + location.host + "/p2")
|
||||
pageEvents.race(this.socket, "open", "close").then(response => {
|
||||
if(response.type === "open"){
|
||||
return this.openEvent()
|
||||
|
10
server.py
10
server.py
@ -1,11 +1,17 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
import argparse
|
||||
import asyncio
|
||||
import websockets
|
||||
import json
|
||||
import random
|
||||
import sys
|
||||
|
||||
parser = argparse.ArgumentParser(description='Run the taiko-web multiplayer server.')
|
||||
parser.add_argument('port', type=int, metavar='PORT', nargs='?', default=34802, help='Port to listen on.')
|
||||
parser.add_argument('-o', '--allow-origin', action='append', help='Limit incoming connections to the specified origin. Can be specified multiple times.')
|
||||
args = parser.parse_args()
|
||||
|
||||
server_status = {
|
||||
"waiting": {},
|
||||
"users": [],
|
||||
@ -372,11 +378,11 @@ async def connection(ws, path):
|
||||
elif user["action"] == "invite" and user["session"] in server_status["invites"]:
|
||||
del server_status["invites"][user["session"]]
|
||||
|
||||
port = int(sys.argv[1]) if len(sys.argv) > 1 else 34802
|
||||
port = args.port
|
||||
print('Starting server on port %d' % port)
|
||||
loop = asyncio.get_event_loop()
|
||||
tasks = asyncio.gather(
|
||||
websockets.serve(connection, "localhost", port)
|
||||
websockets.serve(connection, "localhost", port, origins=args.allow_origin)
|
||||
)
|
||||
try:
|
||||
loop.run_until_complete(tasks)
|
||||
|
Loading…
Reference in New Issue
Block a user