diff --git a/evennia/trunk/apps/objects/models.py b/evennia/trunk/apps/objects/models.py index ebfabc8af0..c96be6418e 100755 --- a/evennia/trunk/apps/objects/models.py +++ b/evennia/trunk/apps/objects/models.py @@ -43,12 +43,13 @@ class Object(models.Model): """ name = models.CharField(maxlength=255) - owner = models.ForeignKey('self', related_name="obj_owner") + owner = models.ForeignKey('self', related_name="obj_owner", blank=True, null=True) zone = models.ForeignKey('self', related_name="obj_zone", blank=True, null=True) home = models.ForeignKey('self', related_name="obj_home", blank=True, null=True) type = models.SmallIntegerField(choices=global_defines.OBJECT_TYPES) description = models.TextField(blank=True) location = models.ForeignKey('self', related_name="obj_location", blank=True, null=True) + flags = models.TextField(blank=True) date_created = models.DateField(editable=False, auto_now_add=True) # Rather than keeping another relation for this, we're just going to use @@ -57,7 +58,9 @@ class Object(models.Model): # cost of a little bit more memory usage. No biggy. # A list of objects located inside the object. - contents_list = [] + # TODO: Re-activate this once we get the contents loader working. + # contents_list = [] + # A dictionary of attributes assocated with the object. The keys are the # attribute's names. attrib_list = {} @@ -78,7 +81,71 @@ class Object(models.Model): """ BEGIN COMMON METHODS - """ + """ + def get_flags(self): + """ + Returns an object's flag list. + """ + return self.flags + + def has_flag(self, flag): + """ + Does our object have a certain flag? + """ + return flag in self.flags.split() + + def set_flag(self, flag, value): + """ + Add a flag to our object's flag list. + """ + has_flag = self.has_flag(flag) + + if value == False and has_flag: + # The flag is there and we want to un-set it. + flags_list = self.flags.split() + flags_list.remove(flag) + self.flags = ' '.join(flags_list) + + # Not all flags are saved, such as CONNECTED. + # Don't waste queries on these things. + if flag not in global_defines.NOSAVE_FLAGS: + self.save() + elif value == False and not has_flag: + # Object doesn't have the flag to begin with. + pass + elif value == True and has_flag: + # We've already go it. + pass + else: + # Add the flag. + flags_list = self.flags.split() + flags_list.append(flag.upper()) + self.flags = ' '.join(flags_list) + if flag not in global_defines.NOSAVE_FLAGS: + self.save() + + def get_owner(self): + """ + Returns an object's owner. + """ + # Players always own themselves. + if self.is_player(): + return self + else: + return self.owner + + def get_home(self): + """ + Returns an object's home. + """ + return self.home + + def get_location(self): + """ + Returns an object's location. + """ + return self.location + def get_attribute(self, attrib): """ Returns the value of an attribute on an object. @@ -100,6 +167,12 @@ class Object(models.Model): something horribly long with the load routine right now. """ return list(Object.objects.filter(location__id=self.id)) + + def get_zone(self): + """ + Returns the object that is marked as this object's zone. + """ + return self.zone def move_to(self, server, target): """ diff --git a/evennia/trunk/commands_general.py b/evennia/trunk/commands_general.py index b4dcea936a..3873603c51 100644 --- a/evennia/trunk/commands_general.py +++ b/evennia/trunk/commands_general.py @@ -102,8 +102,9 @@ def cmd_examine(cdat): target_obj.flag_string(), ansi["normal"], )) - session.msg("Type: %s Flags: " % (target_obj.get_type(),)) - session.msg("Zone: ") + session.msg("Type: %s Flags: %s" % (target_obj.get_type(), target_obj.get_flags())) + session.msg("Owner: %s " % (target_obj.get_owner(),)) + session.msg("Zone: %s" % (target_obj.get_zone(),)) for attribute in target_obj.attrib_list: session.msg("%s%s%s: %s" % (ansi["hilite"], attribute, ansi["normal"], target_obj.get_attribute(attribute))) @@ -133,8 +134,8 @@ def cmd_examine(cdat): session.msg('%s' %(exit,)) if not target_obj.is_room(): - session.msg("Home: ") - session.msg("Location: %s" % (target_obj.location,)) + session.msg("Home: %s" % (target_obj.get_home(),)) + session.msg("Location: %s" % (target_obj.get_location(),)) def cmd_quit(cdat): """ diff --git a/evennia/trunk/commands_staff.py b/evennia/trunk/commands_staff.py index 75a6b217de..62c58c4dd0 100644 --- a/evennia/trunk/commands_staff.py +++ b/evennia/trunk/commands_staff.py @@ -1,5 +1,6 @@ from apps.objects.models import Object import functions_db +import functions_general import commands_general import cmdhandler @@ -141,19 +142,31 @@ def cmd_find(cdat): session.msg("No search pattern given.") return - memory_based = True - - if memory_based: - results = functions_db.list_search_object_namestr(server.object_list.values(), searchstring) + results = functions_db.list_search_object_namestr(server.object_list.values(), searchstring) - if len(results) > 0: - session.msg("Name matches for: %s" % (searchstring,)) - for result in results: - session.msg(" %s" % (result,)) - session.msg("%d matches returned." % (len(results),)) - else: - session.msg("No name matches found for: %s" % (searchstring,)) + if len(results) > 0: + session.msg("Name matches for: %s" % (searchstring,)) + for result in results: + session.msg(" %s" % (result,)) + session.msg("%d matches returned." % (len(results),)) + else: + session.msg("No name matches found for: %s" % (searchstring,)) +def cmd_wall(cdat): + """ + Announces a message to all connected players. + """ + session = cdat['session'] + server = cdat['server'] + wallstring = ' '.join(cdat['uinput']['splitted'][1:]) + + if wallstring == '': + session.msg("Announce what?") + return + + message = "%s shouts \"%s\"" % (session.pobject.name, wallstring) + functions_general.announce_all(server, message) + def cmd_shutdown(cdat): """ Shut the server down gracefully. diff --git a/evennia/trunk/commands_unloggedin.py b/evennia/trunk/commands_unloggedin.py index fc1027a964..cb1322879c 100644 --- a/evennia/trunk/commands_unloggedin.py +++ b/evennia/trunk/commands_unloggedin.py @@ -15,14 +15,20 @@ def cmd_connect(cdat): password = cdat['uinput']['splitted'][2] account = User.objects.filter(username=uname) - user = account[0] autherror = "Invalid username or password!" + # No username match if account.count() == 0: session.msg(autherror) + return + + # We have at least one result, so we can check hte password. + user = account[0] + if not user.check_password(password): session.msg(autherror) else: + user = account[0] uname = user.username session.login(user) @@ -31,6 +37,7 @@ def cmd_create(cdat): Handle the creation of new accounts. """ session = cdat['session'] + server = session.server uname = cdat['uinput']['splitted'][1] email = cdat['uinput']['splitted'][2] password = cdat['uinput']['splitted'][3] diff --git a/evennia/trunk/functions_db.py b/evennia/trunk/functions_db.py index 9ef4b8d4d4..6758f7e047 100644 --- a/evennia/trunk/functions_db.py +++ b/evennia/trunk/functions_db.py @@ -111,21 +111,23 @@ def create_object(server, odat): new_object.name = odat["name"] new_object.type = odat["type"] - #if odat["home"]: - # new_object.home = odat["home"] - #else: - # new_object.home = odat["location"] - - #if odat["owner"].zone: - # new_object.zone = odat["owner"].zone - #else: - # new_object.zone = None - - #if odat["type"] is 1: - # new_object.owner = new_object - #else: - # new_object.owner = odat["owner"] + # If this is a player, set him to own himself. + if odat["type"] == 1: + new_object.owner = None + new_object.zone = None + else: + new_object.owner = odat["owner"] + if new_object.owner.zone: + new_object.zone = new_object.owner.zone + + # If we have a 'home' key, use that for our home value. Otherwise use + # the location key. + if odat.get("home",False): + new_object.home = odat["home"] + else: + new_object.home = odat["location"] + new_object.save() # Add the object to our server's dictionary of objects. diff --git a/evennia/trunk/global_defines.py b/evennia/trunk/global_defines.py index d82e8c8023..2393bd9c85 100644 --- a/evennia/trunk/global_defines.py +++ b/evennia/trunk/global_defines.py @@ -7,3 +7,9 @@ OBJECT_TYPES = ( (4, 'EXIT'), (5, 'GARBAGE'), ) + +# This is a list of flags that the server actually uses. Anything not in this +# list is a custom flag. +SERVER_FLAGS = ["CONNECTED"] +# These flags are not saved. +NOSAVE_FLAGS = ["CONNECTED"] diff --git a/evennia/trunk/sessions.py b/evennia/trunk/sessions.py index 4f456798da..8f455b6885 100755 --- a/evennia/trunk/sessions.py +++ b/evennia/trunk/sessions.py @@ -57,6 +57,7 @@ class PlayerSession(async_chat): """ Break the connection and do some accounting. """ + self.pobject.set_flag("CONNECTED", False) async_chat.handle_close(self) self.logged_in = False self.server.remove_session(self) @@ -83,7 +84,8 @@ class PlayerSession(async_chat): self.name = user.username self.logged_in = True self.conn_time = time.time() - + self.pobject.set_flag("CONNECTED", True) + self.msg("You are now logged in as %s." % (self.name,)) cdat = {"session": self, "uinput":'look', "server": self.server} cmdhandler.handle(cdat)