Huge overhaul in the way objects and sessions are used with commands. We now pass all commands through objects (aside from unlogged commands), which means session.msg() is now deprecated for any use other than unlogged out.

As a side-effect of all of this, logging in more than once acts as behaves now. Also, this will allow things/rooms/exits (IE: not players) or un-logged in players to run commands or be forced to run them via @fo. All of this will bring us more in-line with MUX behavior.
This commit is contained in:
Greg Taylor 2009-01-24 20:30:46 +00:00
parent 50f4d04096
commit 9407eb0ee4
20 changed files with 680 additions and 712 deletions

View file

@ -100,30 +100,29 @@ class ObjectManager(models.Manager):
return [prospect for prospect in searchlist if prospect.name_match(ostring, match_type=match_type)]
def standard_plr_objsearch(self, session, ostring, search_contents=True,
def standard_objsearch(self, source_object, ostring, search_contents=True,
search_location=True, dbref_only=False,
limit_types=False):
"""
Perform a standard object search via a player session, handling multiple
Perform a standard object search, handling multiple
results and lack thereof gracefully.
session: (SessionProtocol) Reference to the player's session.
source_object: (Object) The Object doing the searching
ostring: (str) The string to match object names against.
"""
pobject = session.get_pobject()
results = self.local_and_global_search(pobject, ostring,
results = self.local_and_global_search(source_object, ostring,
search_contents=search_contents,
search_location=search_location,
dbref_only=dbref_only,
limit_types=limit_types)
if len(results) > 1:
session.msg("More than one match found (please narrow target):")
source_object.emit_to("More than one match found (please narrow target):")
for result in results:
session.msg(" %s" % (result.get_name(),))
source_object.emit_to(" %s" % (result.get_name(),))
return False
elif len(results) == 0:
session.msg("I don't see that here.")
source_object.emit_to("I don't see that here.")
return False
else:
return results[0]
@ -182,11 +181,11 @@ class ObjectManager(models.Manager):
except IndexError:
return None
def is_dbref(self, dbstring):
def is_dbref(self, dbstring, require_pound=True):
"""
Is the input a well-formed dbref number?
"""
return util_object.is_dbref(dbstring)
return util_object.is_dbref(dbstring, require_pound=require_pound)
def dbref_search(self, dbref_string, limit_types=False):
"""

View file

@ -136,14 +136,14 @@ class Object(models.Model):
"""
BEGIN COMMON METHODS
"""
def get_session(self):
def get_sessions(self):
"""
Returns the session object for a player, or None if none exists.
Returns a list of sessions matching this object.
"""
if self.is_player():
return session_mgr.session_from_object(self)
return session_mgr.sessions_from_object(self)
else:
return None
return []
def emit_to(self, message):
"""
@ -155,11 +155,17 @@ class Object(models.Model):
if not self.is_player():
return False
session = self.get_session()
if session:
sessions = self.get_sessions()
for session in sessions:
session.msg(ansi.parse_ansi(message))
else:
return False
def execute_cmd(self, command_str, session=None):
"""
Do something as this object.
"""
# The Command object has all of the methods for parsing and preparing
# for searching and execution. Send it to the handler once populated.
cmdhandler.handle(cmdhandler.Command(self, command_str, session=session))
def emit_to_contents(self, message, exclude=None):
"""
@ -223,7 +229,7 @@ class Object(models.Model):
else:
return False
def user_has_perm(self, perm):
def has_perm(self, perm):
"""
Checks to see whether a user has the specified permission or is a super
user.
@ -241,7 +247,7 @@ class Object(models.Model):
else:
return False
def user_has_perm_list(self, perm_list):
def has_perm_list(self, perm_list):
"""
Checks to see whether a user has the specified permission or is a super
user. This form accepts an iterable of strings representing permissions,
@ -292,7 +298,7 @@ class Object(models.Model):
# When builder_override is enabled, a builder permission means
# the object controls the other.
if builder_override and not other_obj.is_player() and self.user_has_perm('genperms.builder'):
if builder_override and not other_obj.is_player() and self.has_perm('genperms.builder'):
return True
# They've failed to meet any of the above conditions.
@ -442,8 +448,8 @@ class Object(models.Model):
"""
# See if we need to kick the player off.
session = self.get_session()
if session:
sessions = self.get_sessions()
for session in sessions:
session.msg("You have been destroyed, goodbye.")
session.handle_close()
@ -655,12 +661,11 @@ class Object(models.Model):
Is this object a connected player?
"""
if self.is_player():
if self.get_session():
if self.get_sessions():
return True
else:
return False
else:
return False
# No matches or not a player
return False
def get_owner(self):
"""
@ -798,9 +803,7 @@ class Object(models.Model):
if self.location.is_player():
self.location.emit_to("%s is now in your inventory." % (self.get_name()))
session = self.get_session()
if force_look and self.is_player() and session:
self.get_session().execute_cmd('look')
self.execute_cmd('look')
def dbref_match(self, oname):
"""
@ -920,7 +923,7 @@ class CommChannel(models.Model):
name = models.CharField(max_length=255)
ansi_name = models.CharField(max_length=255)
owner = models.ForeignKey(Object, related_name="chan_owner")
description = models.CharField(max_length=80)
description = models.CharField(max_length=80, blank=True, null=True)
is_joined_by_default = models.BooleanField(default=False)
req_grp = models.ManyToManyField(Group, blank=True, null=True)
@ -1023,4 +1026,7 @@ class CommChannelMessage(models.Model):
class CommChannelMessageAdmin(admin.ModelAdmin):
list_display = ('channel', 'message')
admin.site.register(CommChannelMessage, CommChannelMessageAdmin)
admin.site.register(CommChannelMessage, CommChannelMessageAdmin)
# Deferred imports are poopy. This will require some thought to fix.
from src import cmdhandler

View file

@ -2,13 +2,17 @@
Utility functions for the Object class. These functions should not import
any models or modify the database.
"""
def is_dbref(dbstring):
def is_dbref(dbstring, require_pound=True):
"""
Is the input a well-formed dbref number?
"""
# Strip the leading # sign if it's there.
if dbstring.startswith("#"):
dbstring = dbstring[1:]
else:
if require_pound:
# The pound sign was required and it didn't have it, fail out.
return False
try:
# If this fails, it's probably not valid.