add a Character manager operation to log everyone out
this is without penalty Signed-off-by: Brian S. Stephan <bss@incorporeal.org>
This commit is contained in:
parent
04e09af8a9
commit
27fcecd8aa
@ -52,6 +52,16 @@ class Game(models.Model):
|
||||
class CharacterManager(models.Manager):
|
||||
"""Query manager for creating a Character and taking operations relevant to the game."""
|
||||
|
||||
def log_out_everyone(self):
|
||||
"""Log out every logged in character.
|
||||
|
||||
This is probably being called on shutdown or another situation when we can't monitor state, so we'll
|
||||
just recreate it whenever it is we come back online.
|
||||
"""
|
||||
self.filter(enabled=True,
|
||||
status=Character.CHARACTER_STATUS_LOGGED_IN).update(status=Character.CHARACTER_STATUS_OFFLINE)
|
||||
logger.info("ALL::ALL: logged out all currently online or logged in characters")
|
||||
|
||||
def register(self, name: str, game: Game, password: str, hostmask: str, character_class: str):
|
||||
"""Create a character, with guardrails.
|
||||
|
||||
|
@ -44,6 +44,20 @@ class CharacterTest(TestCase):
|
||||
assert char.status == Character.CHARACTER_STATUS_OFFLINE
|
||||
assert char.last_login == logout_time
|
||||
|
||||
def test_log_out_everyone(self):
|
||||
"""Test logging out everyone in the database."""
|
||||
game = Game.objects.get(pk=1)
|
||||
# make some data
|
||||
Character.objects.register('loe1', game, 'test', 'loe1', 'log_out_everyone_tester')
|
||||
Character.objects.register('loe2', game, 'test', 'loe2', 'log_out_everyone_tester')
|
||||
Character.objects.register('loe3', game, 'test', 'loe3', 'log_out_everyone_tester')
|
||||
|
||||
assert Character.objects.filter(status=Character.CHARACTER_STATUS_LOGGED_IN).count() >= 3
|
||||
|
||||
Character.objects.log_out_everyone()
|
||||
|
||||
assert Character.objects.filter(status=Character.CHARACTER_STATUS_LOGGED_IN).count() == 0
|
||||
|
||||
def test_cant_log_out_offline(self):
|
||||
"""Test that we error if trying to log out a character already offline."""
|
||||
char = Character.objects.get(pk=1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user