Some streamlining and cleanup.
This commit is contained in:
parent
2cd8c50f3d
commit
43f2167e74
3 changed files with 49 additions and 43 deletions
|
|
@ -54,8 +54,16 @@ class Object(models.Model):
|
||||||
type = models.SmallIntegerField(choices=OBJECT_TYPES)
|
type = models.SmallIntegerField(choices=OBJECT_TYPES)
|
||||||
description = models.TextField(blank=True)
|
description = models.TextField(blank=True)
|
||||||
location = models.ForeignKey('self', related_name="olocation", blank=True, null=True)
|
location = models.ForeignKey('self', related_name="olocation", blank=True, null=True)
|
||||||
content = models.ManyToManyField("Object", related_name="contents", blank=True, null=True)
|
|
||||||
attrib = models.ManyToManyField(Attribute, related_name="attributes", blank=True, null=True)
|
# Rather than keeping another relation for this, we're just going to use
|
||||||
|
# foreign keys and populate each object's contents and attribute lists at
|
||||||
|
# server startup. It'll keep some of the tables more simple, but at the
|
||||||
|
# cost of a little bit more memory usage. No biggy.
|
||||||
|
|
||||||
|
# A list of objects located inside the object.
|
||||||
|
contents_list = []
|
||||||
|
# A dictionary of attributes assocated with the object. The keys are the
|
||||||
|
# attribute's names.
|
||||||
attrib_list = {}
|
attrib_list = {}
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
|
@ -76,19 +84,3 @@ class Object(models.Model):
|
||||||
|
|
||||||
class Admin:
|
class Admin:
|
||||||
list_display = ('name',)
|
list_display = ('name',)
|
||||||
"""
|
|
||||||
class Player(models.Model):
|
|
||||||
#
|
|
||||||
# Model representation of our players.
|
|
||||||
#
|
|
||||||
# Link back to our Django User class for password, username, email, etc.
|
|
||||||
account = models.ForeignKey(User)
|
|
||||||
location = models.ForeignKey(Object, related_name="plocation")
|
|
||||||
is_connected = models.BooleanField()
|
|
||||||
last_connected = models.DateTimeField()
|
|
||||||
contents = models.ManyToManyField(Object)
|
|
||||||
attributes = models.ManyToManyField(Attribute)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return "%s(%d)" % (self.name, self.id,)
|
|
||||||
"""
|
|
||||||
|
|
|
||||||
|
|
@ -23,21 +23,21 @@ class GenCommands:
|
||||||
player_loc = session.player_loc
|
player_loc = session.player_loc
|
||||||
player_loc_obj = server.object_list[player_loc]
|
player_loc_obj = server.object_list[player_loc]
|
||||||
|
|
||||||
retval = "%s%s%s%s\n\r%s\n\r" % (
|
retval = "%s%s%s%s\n\r%s" % (
|
||||||
ansi["normal"],
|
ansi["normal"],
|
||||||
ansi["hilite"],
|
ansi["hilite"],
|
||||||
player_loc_obj.name,
|
player_loc_obj.name,
|
||||||
ansi["normal"],
|
ansi["normal"],
|
||||||
player_loc_obj.description,
|
player_loc_obj.description,
|
||||||
)
|
)
|
||||||
session.push(retval)
|
session.msg(retval)
|
||||||
|
|
||||||
def do_quit(self, cdat):
|
def do_quit(self, cdat):
|
||||||
"""
|
"""
|
||||||
Gracefully disconnect the user as per his own request.
|
Gracefully disconnect the user as per his own request.
|
||||||
"""
|
"""
|
||||||
session = cdat['session']
|
session = cdat['session']
|
||||||
session.push("Quitting!\n\r")
|
session.msg("Quitting!")
|
||||||
session.handle_close()
|
session.handle_close()
|
||||||
|
|
||||||
def do_who(self, cdat):
|
def do_who(self, cdat):
|
||||||
|
|
@ -50,9 +50,9 @@ class GenCommands:
|
||||||
retval = "Player Name\n\r"
|
retval = "Player Name\n\r"
|
||||||
for player in session_list:
|
for player in session_list:
|
||||||
retval += '%s\n\r' % (player,)
|
retval += '%s\n\r' % (player,)
|
||||||
retval += '%d Players logged in.\n\r' % (len(session_list),)
|
retval += '%d Players logged in.' % (len(session_list),)
|
||||||
|
|
||||||
session.push(retval)
|
session.msg(retval)
|
||||||
|
|
||||||
def do_say(self, cdat):
|
def do_say(self, cdat):
|
||||||
"""
|
"""
|
||||||
|
|
@ -63,11 +63,11 @@ class GenCommands:
|
||||||
speech = cdat['uinput']['splitted'][1:]
|
speech = cdat['uinput']['splitted'][1:]
|
||||||
players_present = [player for player in session_list if player.player_loc == session.player_loc and player != session]
|
players_present = [player for player in session_list if player.player_loc == session.player_loc and player != session]
|
||||||
|
|
||||||
retval = "You say, '%s'\n\r" % (''.join(speech),)
|
retval = "You say, '%s'" % (''.join(speech),)
|
||||||
for player in players_present:
|
for player in players_present:
|
||||||
player.push("%s says, '%s'\n\r" % (session.name, speech,))
|
player.msg("%s says, '%s'" % (session.name, speech,))
|
||||||
|
|
||||||
session.push(retval)
|
session.msg(retval)
|
||||||
|
|
||||||
def do_version(self, cdat):
|
def do_version(self, cdat):
|
||||||
"""
|
"""
|
||||||
|
|
@ -76,8 +76,8 @@ class GenCommands:
|
||||||
session = cdat['session']
|
session = cdat['session']
|
||||||
retval = "-"*50 +"\n\r"
|
retval = "-"*50 +"\n\r"
|
||||||
retval += "Evennia %s\n\r" % (settings.EVENNIA_VERSION,)
|
retval += "Evennia %s\n\r" % (settings.EVENNIA_VERSION,)
|
||||||
retval += "-"*50 +"\n\r"
|
retval += "-"*50
|
||||||
session.push(retval)
|
session.msg(retval)
|
||||||
|
|
||||||
class StaffCommands:
|
class StaffCommands:
|
||||||
"""
|
"""
|
||||||
|
|
@ -92,7 +92,7 @@ class StaffCommands:
|
||||||
roomname = ''.join(uinput[1:])
|
roomname = ''.join(uinput[1:])
|
||||||
|
|
||||||
if roomname == '':
|
if roomname == '':
|
||||||
session.push("You must supply a room name!")
|
session.msg("You must supply a room name!")
|
||||||
else:
|
else:
|
||||||
newroom = Object()
|
newroom = Object()
|
||||||
newroom.name = roomname
|
newroom.name = roomname
|
||||||
|
|
@ -106,9 +106,9 @@ class StaffCommands:
|
||||||
server = cdat['server']
|
server = cdat['server']
|
||||||
|
|
||||||
nextfree = server.get_nextfree_dbnum()
|
nextfree = server.get_nextfree_dbnum()
|
||||||
retval = "Next free object number: %s\n\r" % (nextfree,)
|
retval = "Next free object number: %s" % (nextfree,)
|
||||||
|
|
||||||
session.push(retval)
|
session.msg(retval)
|
||||||
|
|
||||||
class UnLoggedInCommands:
|
class UnLoggedInCommands:
|
||||||
"""
|
"""
|
||||||
|
|
@ -126,11 +126,11 @@ class UnLoggedInCommands:
|
||||||
account = User.objects.filter(username=uname)
|
account = User.objects.filter(username=uname)
|
||||||
user = account[0]
|
user = account[0]
|
||||||
|
|
||||||
autherror = "Invalid username or password!\n\r"
|
autherror = "Invalid username or password!"
|
||||||
if account.count() == 0:
|
if account.count() == 0:
|
||||||
session.push(autherror)
|
session.msg(autherror)
|
||||||
if not user.check_password(password):
|
if not user.check_password(password):
|
||||||
session.push(autherror)
|
session.msg(autherror)
|
||||||
else:
|
else:
|
||||||
uname = user.username
|
uname = user.username
|
||||||
session.login(user)
|
session.login(user)
|
||||||
|
|
@ -147,9 +147,9 @@ class UnLoggedInCommands:
|
||||||
account = User.objects.filter(username=uname)
|
account = User.objects.filter(username=uname)
|
||||||
|
|
||||||
if not account.count() == 0:
|
if not account.count() == 0:
|
||||||
session.push("There is already a player with that name!\n\r")
|
session.msg("There is already a player with that name!")
|
||||||
elif len(password) < 3:
|
elif len(password) < 3:
|
||||||
session.push("Your password must be 3 characters or longer.\n\r")
|
session.msg("Your password must be 3 characters or longer.")
|
||||||
else:
|
else:
|
||||||
server.create_user(session, uname, email, password)
|
server.create_user(session, uname, email, password)
|
||||||
|
|
||||||
|
|
@ -160,7 +160,7 @@ class UnLoggedInCommands:
|
||||||
version will be a bit more complicated.
|
version will be a bit more complicated.
|
||||||
"""
|
"""
|
||||||
session = cdat['session']
|
session = cdat['session']
|
||||||
session.push("Disconnecting...\n\r")
|
session.msg("Disconnecting...")
|
||||||
session.handle_close()
|
session.handle_close()
|
||||||
|
|
||||||
# We'll use this for our getattr() in the Handler class.
|
# We'll use this for our getattr() in the Handler class.
|
||||||
|
|
@ -229,5 +229,5 @@ class Handler:
|
||||||
raise UnknownCommand
|
raise UnknownCommand
|
||||||
|
|
||||||
except UnknownCommand:
|
except UnknownCommand:
|
||||||
session.push("Unknown command.\n\r")
|
session.msg("Unknown command.")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@ class PlayerSession(async_chat):
|
||||||
self.data = []
|
self.data = []
|
||||||
self.sock = sock
|
self.sock = sock
|
||||||
self.logged_in = False
|
self.logged_in = False
|
||||||
self.user = None
|
self.pobject = None
|
||||||
# The time the user last issued a command.
|
# The time the user last issued a command.
|
||||||
self.cmd_last = time.time()
|
self.cmd_last = time.time()
|
||||||
# Total number of commands issued.
|
# Total number of commands issued.
|
||||||
|
|
@ -74,20 +74,34 @@ class PlayerSession(async_chat):
|
||||||
buffer += """Please type one of the following to begin:\n\r
|
buffer += """Please type one of the following to begin:\n\r
|
||||||
connect <username> <password>\n\r
|
connect <username> <password>\n\r
|
||||||
create <username> <email> <password>\n\r"""
|
create <username> <email> <password>\n\r"""
|
||||||
buffer += '-'*50 + '\n\r'
|
buffer += '-'*50
|
||||||
session.push(buffer)
|
session.msg(buffer)
|
||||||
|
|
||||||
def login(self, user):
|
def login(self, user):
|
||||||
"""
|
"""
|
||||||
After the user has authenticated, handle logging him in.
|
After the user has authenticated, handle logging him in.
|
||||||
"""
|
"""
|
||||||
self.user = user
|
self.pobject = user
|
||||||
self.name = user.username
|
self.name = user.username
|
||||||
self.logged_in = True
|
self.logged_in = True
|
||||||
self.conn_time = time.time()
|
self.conn_time = time.time()
|
||||||
self.push("Logging in as %s.\n\r" % (self.name,))
|
self.msg("Logging in as %s." % (self.name,))
|
||||||
print "Login: %s" % (self,)
|
print "Login: %s" % (self,)
|
||||||
|
|
||||||
|
def msg(self, message):
|
||||||
|
"""
|
||||||
|
Sends a message with the newline/return included. Use this instead of
|
||||||
|
directly calling push().
|
||||||
|
"""
|
||||||
|
self.push("%s\n\r" % (message,))
|
||||||
|
|
||||||
|
def msg_no_nl(self, message):
|
||||||
|
"""
|
||||||
|
Sends a message without the newline/return included. Use this instead of
|
||||||
|
directly calling push().
|
||||||
|
"""
|
||||||
|
self.push("%s" % (message,))
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
"""
|
"""
|
||||||
String representation of the user session class. We use
|
String representation of the user session class. We use
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue