mirror of
https://github.com/evgen-app/chess_rpg_backend.git
synced 2024-11-25 11:04:03 +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, 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"}
|
||||
)
|
||||
)
|
||||
|
||||
if data:
|
||||
# TODO move to external function/class
|
||||
if "type" not in data:
|
||||
|
@ -61,6 +62,14 @@ class QueueConsumer(AsyncWebsocketConsumer):
|
|||
)
|
||||
if 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:
|
||||
await self.send(
|
||||
text_data=json.dumps(
|
||||
|
@ -84,15 +93,15 @@ class QueueConsumer(AsyncWebsocketConsumer):
|
|||
@sync_to_async
|
||||
def queue_connector(self, deck):
|
||||
try:
|
||||
queue = PlayerInQueue.objects.get(
|
||||
player_id=self.scope["player"]
|
||||
).score = deck.score()
|
||||
queue = PlayerInQueue.objects.get(player_id=self.scope["player"])
|
||||
queue.score = deck.score()
|
||||
except PlayerInQueue.DoesNotExist:
|
||||
queue = PlayerInQueue.objects.create(
|
||||
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):
|
||||
pass
|
||||
|
|
|
@ -6,7 +6,7 @@ from game.models import Player
|
|||
|
||||
class PlayerInQueue(models.Model):
|
||||
# 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()
|
||||
|
||||
def __str__(self):
|
||||
|
|
Loading…
Reference in New Issue
Block a user