mirror of
https://github.com/evgen-app/chess_rpg_backend.git
synced 2024-11-22 09:37:05 +03:00
fixed jit, added info massage on adding to queue
This commit is contained in:
parent
8fcbeaf8d8
commit
339d691172
|
@ -207,4 +207,15 @@ class PlayerAuthSession(models.Model):
|
||||||
player = models.OneToOneField(
|
player = models.OneToOneField(
|
||||||
Player, unique_for_month=True, on_delete=models.CASCADE
|
Player, unique_for_month=True, on_delete=models.CASCADE
|
||||||
)
|
)
|
||||||
jit = models.CharField(max_length=30, default=generate_charset(30))
|
jit = models.CharField(max_length=30)
|
||||||
|
|
||||||
|
def save(
|
||||||
|
self, force_insert=False, force_update=False, using=None, update_fields=None
|
||||||
|
):
|
||||||
|
self.jit = generate_charset(30)
|
||||||
|
super(PlayerAuthSession, self).save(
|
||||||
|
force_insert=force_insert,
|
||||||
|
force_update=force_update,
|
||||||
|
using=using,
|
||||||
|
update_fields=update_fields,
|
||||||
|
)
|
||||||
|
|
|
@ -31,6 +31,7 @@ class QueueConsumer(AsyncWebsocketConsumer):
|
||||||
{"type": "ERROR", "message": "data is not JSON serializable"}
|
{"type": "ERROR", "message": "data is not JSON serializable"}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if data:
|
if data:
|
||||||
# TODO move to external function/class
|
# TODO move to external function/class
|
||||||
if "type" not in data:
|
if "type" not in data:
|
||||||
|
@ -61,6 +62,14 @@ class QueueConsumer(AsyncWebsocketConsumer):
|
||||||
)
|
)
|
||||||
if deck:
|
if deck:
|
||||||
await self.queue_connector(deck)
|
await self.queue_connector(deck)
|
||||||
|
await self.send(
|
||||||
|
text_data=json.dumps(
|
||||||
|
{
|
||||||
|
"type": "INFO",
|
||||||
|
"message": f"added to queue deck with score {self.scope['score']}",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
else:
|
else:
|
||||||
await self.send(
|
await self.send(
|
||||||
text_data=json.dumps(
|
text_data=json.dumps(
|
||||||
|
@ -84,15 +93,15 @@ class QueueConsumer(AsyncWebsocketConsumer):
|
||||||
@sync_to_async
|
@sync_to_async
|
||||||
def queue_connector(self, deck):
|
def queue_connector(self, deck):
|
||||||
try:
|
try:
|
||||||
queue = PlayerInQueue.objects.get(
|
queue = PlayerInQueue.objects.get(player_id=self.scope["player"])
|
||||||
player_id=self.scope["player"]
|
queue.score = deck.score()
|
||||||
).score = deck.score()
|
|
||||||
except PlayerInQueue.DoesNotExist:
|
except PlayerInQueue.DoesNotExist:
|
||||||
queue = PlayerInQueue.objects.create(
|
queue = PlayerInQueue.objects.create(
|
||||||
player_id=self.scope["player"], score=deck.score()
|
player_id=self.scope["player"], score=deck.score()
|
||||||
)
|
)
|
||||||
|
|
||||||
self.scope["queue"] = queue
|
self.scope["queue"] = queue.id
|
||||||
|
self.scope["score"] = queue.score
|
||||||
|
|
||||||
async def chat_message(self, event):
|
async def chat_message(self, event):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -6,7 +6,7 @@ from game.models import Player
|
||||||
|
|
||||||
class PlayerInQueue(models.Model):
|
class PlayerInQueue(models.Model):
|
||||||
# TODO use redis for storing
|
# TODO use redis for storing
|
||||||
player = models.ForeignKey(Player, unique=True, on_delete=models.CASCADE)
|
player = models.OneToOneField(Player, unique=True, on_delete=models.CASCADE)
|
||||||
score = models.IntegerField()
|
score = models.IntegerField()
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user