rename the project
This commit is contained in:
parent
f9bf3a566e
commit
0db73216b3
@ -6,7 +6,7 @@ import sys
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Run administrative tasks."""
|
"""Run administrative tasks."""
|
||||||
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'trancendence.settings')
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'transcendence.settings')
|
||||||
try:
|
try:
|
||||||
from django.core.management import execute_from_command_line
|
from django.core.management import execute_from_command_line
|
||||||
except ImportError as exc:
|
except ImportError as exc:
|
||||||
|
53
transcendence/abstract/AbstractRoom.py
Normal file
53
transcendence/abstract/AbstractRoom.py
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
from .AbstractRoomMember import AbstractRoomMember
|
||||||
|
|
||||||
|
class AbstractRoom:
|
||||||
|
|
||||||
|
def __init__(self, room_manager):
|
||||||
|
self._member_list: [AbstractRoomMember] = []
|
||||||
|
self.room_manager = room_manager
|
||||||
|
|
||||||
|
def broadcast(self, detail: str, data: dict = {}):
|
||||||
|
for member in self._member_list:
|
||||||
|
member: AbstractRoomMember
|
||||||
|
member.send(detail, data)
|
||||||
|
|
||||||
|
def clear(self):
|
||||||
|
self._member_list.clear()
|
||||||
|
|
||||||
|
def get_member_by_socket(self, socket: WebsocketConsumer):
|
||||||
|
for member in self._member_list:
|
||||||
|
member: AbstractRoomMember
|
||||||
|
if (member.socket is socket):
|
||||||
|
return member
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_member_by_user_id(self, user_id: int):
|
||||||
|
for member in self._member_list:
|
||||||
|
member: AbstractRoomMember
|
||||||
|
if (member.user_id == user_id):
|
||||||
|
return member
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def append(self, member: AbstractRoomMember):
|
||||||
|
tmp: AbstractRoomMember = self.get_member_by_user_id(member.user_id)
|
||||||
|
if (tmp is not None):
|
||||||
|
tmp.send("Connection close: Another connection open with the same user id.")
|
||||||
|
self.remove(tmp)
|
||||||
|
member.accept()
|
||||||
|
self._member_list.append(waiter)
|
||||||
|
|
||||||
|
def remove(self, member: AbstractRoomMember):
|
||||||
|
self._member_list.remove(member)
|
||||||
|
waiter.disconnect()
|
||||||
|
|
||||||
|
def empty(self):
|
||||||
|
for _ in self._waiter_list:
|
||||||
|
return False
|
||||||
|
return True
|
||||||
|
|
||||||
|
def get_users_id(self):
|
||||||
|
return [waiter.user_id for waiter in self._waiter_list]
|
||||||
|
|
||||||
|
def __len__(self):
|
||||||
|
return len(self._waiter_list)
|
18
transcendence/abstract/AbstractRoomManager.py
Normal file
18
transcendence/abstract/AbstractRoomManager.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from .AbstractRoom import AbstractRoom
|
||||||
|
|
||||||
|
class AbstractRoomManager:
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
self._room_list: [AbstractRoom] = []
|
||||||
|
|
||||||
|
def get(self, mode: int):
|
||||||
|
for room in self._room_list:
|
||||||
|
room: A
|
||||||
|
if (waiting_room._mode == mode):
|
||||||
|
return waiting_room
|
||||||
|
tmp: WaitingRoom = WaitingRoom(self, mode)
|
||||||
|
self._waiting_rooms.append(tmp)
|
||||||
|
return tmp
|
||||||
|
|
||||||
|
def remove(self, waiting_room: WaitingRoom):
|
||||||
|
self._waiting_rooms.remove(waiting_room)
|
16
transcendence/abstract/AbstractRoomMember.py
Normal file
16
transcendence/abstract/AbstractRoomMember.py
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
class AbstractRoomMember:
|
||||||
|
|
||||||
|
def __init__(self, user_id: int, socket: WebsocketConsumer):
|
||||||
|
self.user_id: int = user_id
|
||||||
|
self.socket: WebsocketConsumer = socket
|
||||||
|
|
||||||
|
def send(self, detail: str, data: dict = {}):
|
||||||
|
raw_data: dict = {"detail": detail}
|
||||||
|
raw_data.update(data)
|
||||||
|
self.socket.send(text_data=json.dumps(raw_data))
|
||||||
|
|
||||||
|
def accept(self):
|
||||||
|
self.socket.accept()
|
||||||
|
|
||||||
|
def disconnect(self):
|
||||||
|
self.socket.disconnect(200)
|
@ -1,5 +1,5 @@
|
|||||||
"""
|
"""
|
||||||
Django settings for trancendence project.
|
Django settings for transcendence project.
|
||||||
|
|
||||||
Generated by 'django-admin startproject' using Django 4.2.6.
|
Generated by 'django-admin startproject' using Django 4.2.6.
|
||||||
|
|
||||||
@ -61,7 +61,7 @@ INSTALLED_APPS = [
|
|||||||
'django.contrib.staticfiles',
|
'django.contrib.staticfiles',
|
||||||
]
|
]
|
||||||
|
|
||||||
ASGI_APPLICATION = 'trancendence.asgi.application'
|
ASGI_APPLICATION = 'transcendence.asgi.application'
|
||||||
|
|
||||||
CHANNEL_LAYERS = {
|
CHANNEL_LAYERS = {
|
||||||
'default' :{
|
'default' :{
|
||||||
@ -81,7 +81,7 @@ MIDDLEWARE = [
|
|||||||
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
||||||
]
|
]
|
||||||
|
|
||||||
ROOT_URLCONF = 'trancendence.urls'
|
ROOT_URLCONF = 'transcendence.urls'
|
||||||
|
|
||||||
TEMPLATES = [
|
TEMPLATES = [
|
||||||
{
|
{
|
||||||
@ -99,7 +99,7 @@ TEMPLATES = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
WSGI_APPLICATION = 'trancendence.wsgi.application'
|
WSGI_APPLICATION = 'transcendence.wsgi.application'
|
||||||
|
|
||||||
|
|
||||||
# Database
|
# Database
|
Loading…
Reference in New Issue
Block a user