2023-12-11 07:39:53 -05:00
|
|
|
from django.db import models
|
|
|
|
|
2023-12-23 06:54:33 -05:00
|
|
|
from channels.generic.websocket import WebsocketConsumer
|
|
|
|
import json
|
|
|
|
|
2023-12-23 12:30:45 -05:00
|
|
|
from transcendence.abstract.AbstractRoom import AbstractRoom
|
|
|
|
from transcendence.abstract.AbstractRoomManager import AbstractRoomManager
|
|
|
|
from transcendence.abstract.AbstractRoomMember import AbstractRoomMember
|
2023-12-23 06:54:33 -05:00
|
|
|
|
2023-12-23 12:30:45 -05:00
|
|
|
# Create your models here.
|
|
|
|
class Waiter(AbstractRoomMember):
|
|
|
|
pass
|
2023-12-23 06:54:33 -05:00
|
|
|
|
2023-12-23 12:30:45 -05:00
|
|
|
class WaitingRoom(AbstractRoom):
|
2023-12-23 06:54:33 -05:00
|
|
|
|
2023-12-23 12:30:45 -05:00
|
|
|
def __init__(self, room_manager,mode):
|
|
|
|
super().__init__(room_manager)
|
|
|
|
self.mode = mode
|
2023-12-23 06:54:33 -05:00
|
|
|
|
2023-12-23 10:47:22 -05:00
|
|
|
def append(self, waiter: Waiter):
|
2023-12-23 12:30:45 -05:00
|
|
|
tmp: Waiter = self.get_member_by_user_id(waiter.user_id)
|
2023-12-23 10:47:22 -05:00
|
|
|
if (tmp is not None):
|
|
|
|
tmp.send("Connection close: Another connection open with the same user id.")
|
|
|
|
self.remove(tmp)
|
2023-12-23 06:54:33 -05:00
|
|
|
waiter.accept()
|
2023-12-23 12:30:45 -05:00
|
|
|
self._member_list.append(waiter)
|
2023-12-23 06:54:33 -05:00
|
|
|
|
2023-12-23 12:30:45 -05:00
|
|
|
class WaitingRoomManager(AbstractRoomManager):
|
2023-12-23 06:54:33 -05:00
|
|
|
|
|
|
|
def get(self, mode: int):
|
2023-12-23 12:30:45 -05:00
|
|
|
for waiting_room in self._room_list:
|
|
|
|
waiting_room: WaitingRoom
|
|
|
|
if (waiting_room.mode == mode):
|
2023-12-23 06:54:33 -05:00
|
|
|
return waiting_room
|
|
|
|
tmp: WaitingRoom = WaitingRoom(self, mode)
|
2023-12-23 12:30:45 -05:00
|
|
|
super().append(tmp)
|
2023-12-23 06:54:33 -05:00
|
|
|
return tmp
|
|
|
|
|
|
|
|
normal: WaitingRoomManager = WaitingRoomManager()
|