39 lines
1.1 KiB
Python
39 lines
1.1 KiB
Python
from django.db import models
|
|
|
|
from channels.generic.websocket import WebsocketConsumer
|
|
import json
|
|
|
|
from transcendence.abstract.AbstractRoom import AbstractRoom
|
|
from transcendence.abstract.AbstractRoomManager import AbstractRoomManager
|
|
from transcendence.abstract.AbstractRoomMember import AbstractRoomMember
|
|
|
|
# Create your models here.
|
|
class Waiter(AbstractRoomMember):
|
|
pass
|
|
|
|
class WaitingRoom(AbstractRoom):
|
|
|
|
def __init__(self, room_manager,mode):
|
|
super().__init__(room_manager)
|
|
self.mode = mode
|
|
|
|
def append(self, waiter: Waiter):
|
|
tmp: Waiter = self.get_member_by_user_id(waiter.user_id)
|
|
if (tmp is not None):
|
|
tmp.send("Connection close: Another connection open with the same user id.")
|
|
self.remove(tmp)
|
|
waiter.accept()
|
|
self._member_list.append(waiter)
|
|
|
|
class WaitingRoomManager(AbstractRoomManager):
|
|
|
|
def get(self, mode: int):
|
|
for waiting_room in self._room_list:
|
|
waiting_room: WaitingRoom
|
|
if (waiting_room.mode == mode):
|
|
return waiting_room
|
|
tmp: WaitingRoom = WaitingRoom(self, mode)
|
|
super().append(tmp)
|
|
return tmp
|
|
|
|
normal: WaitingRoomManager = WaitingRoomManager() |