mirror of
https://github.com/Lost-MSth/Arcaea-server.git
synced 2026-02-04 21:47:28 +08:00
Rearrange Link Play module
- Try to ensure thread safety by using TCP socket
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
from multiprocessing import Pipe
|
||||
|
||||
from core.error import ArcError
|
||||
from core.linkplay import LocalMultiPlayer, Player, Room
|
||||
from core.linkplay import Player, RemoteMultiPlayer, Room
|
||||
from core.sql import Connect
|
||||
from flask import Blueprint, request
|
||||
from setting import Config
|
||||
@@ -11,24 +9,23 @@ from .func import arc_try, success_return
|
||||
|
||||
bp = Blueprint('multiplayer', __name__, url_prefix='/multiplayer')
|
||||
|
||||
conn1, conn2 = Pipe()
|
||||
|
||||
|
||||
@bp.route('/me/room/create', methods=['POST']) # 创建房间
|
||||
@auth_required(request)
|
||||
@arc_try
|
||||
def room_create(user_id):
|
||||
if not Config.UDP_PORT or Config.UDP_PORT == '':
|
||||
raise ArcError('The local udp server is down.', 151, status=404)
|
||||
if not Config.LINK_PLAY_HOST:
|
||||
raise ArcError('The link play server is unavailable.', 151, status=404)
|
||||
|
||||
with Connect() as c:
|
||||
x = LocalMultiPlayer(conn1)
|
||||
x = RemoteMultiPlayer()
|
||||
user = Player(c, user_id)
|
||||
user.get_song_unlock(request.json['clientSongMap'])
|
||||
x.create_room(user)
|
||||
r = x.to_dict()
|
||||
r['endPoint'] = request.host.split(
|
||||
':')[0] if Config.LINK_PLAY_HOST == '' else Config.LINK_PLAY_HOST
|
||||
r['port'] = int(Config.UDP_PORT)
|
||||
':')[0] if Config.LINK_PLAY_DISPLAY_HOST == '' else Config.LINK_PLAY_DISPLAY_HOST
|
||||
r['port'] = int(Config.LINK_PLAY_UDP_PORT)
|
||||
return success_return(r)
|
||||
|
||||
|
||||
@@ -36,11 +33,11 @@ def room_create(user_id):
|
||||
@auth_required(request)
|
||||
@arc_try
|
||||
def room_join(user_id, room_code):
|
||||
if not Config.UDP_PORT or Config.UDP_PORT == '':
|
||||
raise ArcError('The local udp server is down.', 151, status=404)
|
||||
if not Config.LINK_PLAY_HOST:
|
||||
raise ArcError('The link play server is unavailable.', 151, status=404)
|
||||
|
||||
with Connect() as c:
|
||||
x = LocalMultiPlayer(conn1)
|
||||
x = RemoteMultiPlayer()
|
||||
user = Player(c, user_id)
|
||||
user.get_song_unlock(request.json['clientSongMap'])
|
||||
room = Room()
|
||||
@@ -48,8 +45,8 @@ def room_join(user_id, room_code):
|
||||
x.join_room(room, user)
|
||||
r = x.to_dict()
|
||||
r['endPoint'] = request.host.split(
|
||||
':')[0] if Config.LINK_PLAY_HOST == '' else Config.LINK_PLAY_HOST
|
||||
r['port'] = int(Config.UDP_PORT)
|
||||
':')[0] if Config.LINK_PLAY_DISPLAY_HOST == '' else Config.LINK_PLAY_DISPLAY_HOST
|
||||
r['port'] = int(Config.LINK_PLAY_UDP_PORT)
|
||||
return success_return(r)
|
||||
|
||||
|
||||
@@ -57,16 +54,16 @@ def room_join(user_id, room_code):
|
||||
@auth_required(request)
|
||||
@arc_try
|
||||
def multiplayer_update(user_id):
|
||||
if not Config.UDP_PORT or Config.UDP_PORT == '':
|
||||
raise ArcError('The local udp server is down.', 151, status=404)
|
||||
if not Config.LINK_PLAY_HOST:
|
||||
raise ArcError('The link play server is unavailable.', 151, status=404)
|
||||
|
||||
with Connect() as c:
|
||||
x = LocalMultiPlayer(conn1)
|
||||
x = RemoteMultiPlayer()
|
||||
user = Player(c, user_id)
|
||||
user.token = int(request.json['token'])
|
||||
x.update_room(user)
|
||||
r = x.to_dict()
|
||||
r['endPoint'] = request.host.split(
|
||||
':')[0] if Config.LINK_PLAY_HOST == '' else Config.LINK_PLAY_HOST
|
||||
r['port'] = int(Config.UDP_PORT)
|
||||
':')[0] if Config.LINK_PLAY_DISPLAY_HOST == '' else Config.LINK_PLAY_DISPLAY_HOST
|
||||
r['port'] = int(Config.LINK_PLAY_UDP_PORT)
|
||||
return success_return(r)
|
||||
|
||||
Reference in New Issue
Block a user