From 43f2167e748e50c1eaf26e0be0020d9e4492def3 Mon Sep 17 00:00:00 2001 From: Greg Taylor Date: Tue, 28 Nov 2006 22:40:27 +0000 Subject: [PATCH] Some streamlining and cleanup. --- evennia/trunk/apps/objects/models.py | 28 +++++++------------ evennia/trunk/cmdhandler.py | 40 ++++++++++++++-------------- evennia/trunk/sessions.py | 24 +++++++++++++---- 3 files changed, 49 insertions(+), 43 deletions(-) diff --git a/evennia/trunk/apps/objects/models.py b/evennia/trunk/apps/objects/models.py index 7ca62a39ac..158850ce2c 100755 --- a/evennia/trunk/apps/objects/models.py +++ b/evennia/trunk/apps/objects/models.py @@ -54,8 +54,16 @@ class Object(models.Model): type = models.SmallIntegerField(choices=OBJECT_TYPES) description = models.TextField(blank=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 = {} def __str__(self): @@ -76,19 +84,3 @@ class Object(models.Model): class Admin: 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,) -""" diff --git a/evennia/trunk/cmdhandler.py b/evennia/trunk/cmdhandler.py index f27b217cf1..af4dac3ed1 100755 --- a/evennia/trunk/cmdhandler.py +++ b/evennia/trunk/cmdhandler.py @@ -23,21 +23,21 @@ class GenCommands: player_loc = session.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["hilite"], player_loc_obj.name, ansi["normal"], player_loc_obj.description, ) - session.push(retval) + session.msg(retval) def do_quit(self, cdat): """ Gracefully disconnect the user as per his own request. """ session = cdat['session'] - session.push("Quitting!\n\r") + session.msg("Quitting!") session.handle_close() def do_who(self, cdat): @@ -50,9 +50,9 @@ class GenCommands: retval = "Player Name\n\r" for player in session_list: 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): """ @@ -63,11 +63,11 @@ class GenCommands: speech = cdat['uinput']['splitted'][1:] 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: - 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): """ @@ -76,8 +76,8 @@ class GenCommands: session = cdat['session'] retval = "-"*50 +"\n\r" retval += "Evennia %s\n\r" % (settings.EVENNIA_VERSION,) - retval += "-"*50 +"\n\r" - session.push(retval) + retval += "-"*50 + session.msg(retval) class StaffCommands: """ @@ -92,7 +92,7 @@ class StaffCommands: roomname = ''.join(uinput[1:]) if roomname == '': - session.push("You must supply a room name!") + session.msg("You must supply a room name!") else: newroom = Object() newroom.name = roomname @@ -106,9 +106,9 @@ class StaffCommands: server = cdat['server'] 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: """ @@ -126,11 +126,11 @@ class UnLoggedInCommands: account = User.objects.filter(username=uname) user = account[0] - autherror = "Invalid username or password!\n\r" + autherror = "Invalid username or password!" if account.count() == 0: - session.push(autherror) + session.msg(autherror) if not user.check_password(password): - session.push(autherror) + session.msg(autherror) else: uname = user.username session.login(user) @@ -147,9 +147,9 @@ class UnLoggedInCommands: account = User.objects.filter(username=uname) 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: - session.push("Your password must be 3 characters or longer.\n\r") + session.msg("Your password must be 3 characters or longer.") else: server.create_user(session, uname, email, password) @@ -160,7 +160,7 @@ class UnLoggedInCommands: version will be a bit more complicated. """ session = cdat['session'] - session.push("Disconnecting...\n\r") + session.msg("Disconnecting...") session.handle_close() # We'll use this for our getattr() in the Handler class. @@ -229,5 +229,5 @@ class Handler: raise UnknownCommand except UnknownCommand: - session.push("Unknown command.\n\r") + session.msg("Unknown command.") diff --git a/evennia/trunk/sessions.py b/evennia/trunk/sessions.py index 0e286fe1f7..cacbcd519a 100755 --- a/evennia/trunk/sessions.py +++ b/evennia/trunk/sessions.py @@ -21,7 +21,7 @@ class PlayerSession(async_chat): self.data = [] self.sock = sock self.logged_in = False - self.user = None + self.pobject = None # The time the user last issued a command. self.cmd_last = time.time() # Total number of commands issued. @@ -74,19 +74,33 @@ class PlayerSession(async_chat): buffer += """Please type one of the following to begin:\n\r connect \n\r create \n\r""" - buffer += '-'*50 + '\n\r' - session.push(buffer) + buffer += '-'*50 + session.msg(buffer) def login(self, user): """ After the user has authenticated, handle logging him in. """ - self.user = user + self.pobject = user self.name = user.username self.logged_in = True 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,) + + 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): """