diff --git a/evennia/trunk/apps/objects/models.py b/evennia/trunk/apps/objects/models.py index aa24fea824..daaa6246e9 100755 --- a/evennia/trunk/apps/objects/models.py +++ b/evennia/trunk/apps/objects/models.py @@ -56,6 +56,10 @@ class Object(models.Model): # attribute's names. This lets us look up and manipulate attributes really # easily. attrib_list = {} + + # We keep a separate list of active flags in memory so we can store some of + # the non-saved flags such as CONNECTED. + flags_active = [] def __cmp__(self, other): """ @@ -73,12 +77,25 @@ class Object(models.Model): """ BEGIN COMMON METHODS - """ + """ + def load_flags(self): + """ + Toss the flags from self.flags into our flags_active list, where we + pull from. + """ + self.flags_active = self.flags.split() + + def get_name(self): + """ + Returns an object's name. + """ + return self.name + def get_flags(self): """ Returns an object's flag list. """ - return self.flags + return ' '.join(self.flags_active) def has_flag(self, flag): """ @@ -86,7 +103,7 @@ class Object(models.Model): flag: (str) Flag name """ - return flag in self.flags.split() + return flag in self.flags_active def set_flag(self, flag, value): """ @@ -95,17 +112,20 @@ class Object(models.Model): flag: (str) Flag name value: (bool) Set (True) or un-set (False) """ + flag = flag.upper() 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) + self.flags_active.remove(flag) # Not all flags are saved, such as CONNECTED. # Don't waste queries on these things. if flag not in global_defines.NOSAVE_FLAGS: + flag_templist = self.flags.split() + flag_templist.remove(flag) + + self.flags = ' '.join(flag_templist) self.save() elif value == False and not has_flag: # Object doesn't have the flag to begin with. @@ -114,11 +134,13 @@ class Object(models.Model): # 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) + # Add the flag to our active, memory-resident list no matter what. + self.flags_active.append(flag) if flag not in global_defines.NOSAVE_FLAGS: + flag_templist = self.flags.split() + flag_templist.append(flag) + + self.flags = ' '.join(flag_templist) self.save() def get_owner(self): diff --git a/evennia/trunk/commands_staff.py b/evennia/trunk/commands_staff.py index 62c58c4dd0..60f3721baa 100644 --- a/evennia/trunk/commands_staff.py +++ b/evennia/trunk/commands_staff.py @@ -5,7 +5,10 @@ import commands_general import cmdhandler """ -Restricted staff commands. +Staff commands may be a bad description for this file, but it'll do for now. +Any command here is prefixed by an '@' sign, usually denoting a builder, staff +or otherwise manipulative command that doesn't fall within the scope of +normal gameplay. """ def cmd_dig(cdat): @@ -128,7 +131,66 @@ def cmd_teleport(cdat): pobject.move_to(server, results[0]) commands_general.cmd_look(cdat) - #session.msg("Args: %s\n\rEqargs: %s" % (args, eq_args,)) +def cmd_set(cdat): + """ + Sets flags or attributes on objects. + """ + session = cdat['session'] + pobject = session.pobject + server = cdat['server'] + args = cdat['uinput']['splitted'][1:] + + if len(args) == 0: + session.msg("Set what?") + return + + # There's probably a better way to do this. Break the arguments (minus + # the root command) up so we have two items in the list, 0 being the victim, + # 1 being the list of flags or the attribute/value pair. + eq_args = ' '.join(args).split('=') + + if len(eq_args) < 2: + session.msg("Set what?") + return + + victim = functions_db.local_and_global_search(pobject, eq_args[0], searcher=pobject) + + if len(victim) == 0: + session.msg("I don't see that here.") + return + elif len(victim) > 1: + session.msg("I don't know which one you mean!") + return + + victim = victim[0] + attrib_args = eq_args[1].split(':') + + if len(attrib_args) > 1: + # We're dealing with an attribute/value pair. + attrib_name = attrib_args[0].upper() + attrib_value = ' '.join(attrib_args[1:]) + session.msg("%s - %s set." % (victim.get_name(), attrib_name)) + else: + # Flag manipulation form. + flag_list = eq_args[1].split() + + for flag in flag_list: + flag = flag.upper() + if flag[0] == '!': + # We're un-setting the flag. + flag = flag[1:] + if not functions_db.modifiable_flag(flag): + session.msg("You can't set/unset the flag - %s." % (flag,)) + else: + session.msg('%s - %s cleared.' % (victim.get_name(), flag.upper(),)) + victim.set_flag(flag, False) + else: + # We're setting the flag. + if not functions_db.modifiable_flag(flag): + session.msg("You can't set/unset the flag - %s." % (flag,)) + else: + session.msg('%s - %s set.' % (victim.get_name(), flag.upper(),)) + victim.set_flag(flag, True) def cmd_find(cdat): """ diff --git a/evennia/trunk/functions_db.py b/evennia/trunk/functions_db.py index 6758f7e047..372880d8f6 100644 --- a/evennia/trunk/functions_db.py +++ b/evennia/trunk/functions_db.py @@ -1,7 +1,16 @@ import sets from django.contrib.auth.models import User from apps.objects.models import Object -import functions_db +import global_defines + +def modifiable_flag(flagname): + """ + Check to see if a particular flag is modifiable. + """ + if flagname not in global_defines.NOSET_FLAGS: + return True + else: + return False def get_nextfree_dbnum(): """ diff --git a/evennia/trunk/global_defines.py b/evennia/trunk/global_defines.py index 2393bd9c85..c4458f47b8 100644 --- a/evennia/trunk/global_defines.py +++ b/evennia/trunk/global_defines.py @@ -13,3 +13,5 @@ OBJECT_TYPES = ( SERVER_FLAGS = ["CONNECTED"] # These flags are not saved. NOSAVE_FLAGS = ["CONNECTED"] +# These flags can't be modified by players. +NOSET_FLAGS = ["CONNECTED"] diff --git a/evennia/trunk/server.py b/evennia/trunk/server.py index f285d05ab7..5030e6808e 100755 --- a/evennia/trunk/server.py +++ b/evennia/trunk/server.py @@ -60,6 +60,7 @@ class Server(dispatcher): """ object_list = Object.objects.all() for object in object_list: + object.load_flags() dbnum = object.id self.object_list[dbnum] = object print ' Objects Loaded: %d' % (len(self.object_list),)