mirror of
https://github.com/evennia/evennia.git
synced 2026-04-02 05:57:16 +02:00
Moving some of the login tasks out of sessions.py and into the BasicPlayer script parent. Also, added seconds to the 'time' command, which I apparently forgot.
This commit is contained in:
parent
b12ba45cc7
commit
cf18029be1
7 changed files with 69 additions and 23 deletions
|
|
@ -135,6 +135,15 @@ class Object(models.Model):
|
|||
"""
|
||||
BEGIN COMMON METHODS
|
||||
"""
|
||||
def get_session(self):
|
||||
"""
|
||||
Returns the session object for a player, or None if none exists.
|
||||
"""
|
||||
if self.is_player():
|
||||
return session_mgr.session_from_object(self)
|
||||
else:
|
||||
return None
|
||||
|
||||
def emit_to(self, message):
|
||||
"""
|
||||
Emits something to any sessions attached to the object.
|
||||
|
|
@ -636,7 +645,11 @@ class Object(models.Model):
|
|||
Returns an object's script parent.
|
||||
"""
|
||||
if not self.scriptlink:
|
||||
self.scriptlink = scripthandler.scriptlink(self, self.get_attribute_value('__parent', 'basicobject'))
|
||||
if self.is_player():
|
||||
script_to_load = 'player/basicplayer'
|
||||
else:
|
||||
script_to_load = 'basicobject'
|
||||
self.scriptlink = scripthandler.scriptlink(self, self.get_attribute_value('__parent', script_to_load))
|
||||
|
||||
if self.scriptlink:
|
||||
# If the scriptlink variable can't be populated, this will fail
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ def cmd_time(cdat):
|
|||
Server local time.
|
||||
"""
|
||||
session = cdat['session']
|
||||
session.msg('Current server time : %s' % (time.strftime('%a %b %d %H:%M %Y (%Z)', time.localtime(),)))
|
||||
session.msg('Current server time : %s' % (time.strftime('%a %b %d %H:%M:%S %Y (%Z)', time.localtime(),)))
|
||||
|
||||
def cmd_uptime(cdat):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -198,6 +198,15 @@ def get_cwho_list(channel_name, return_muted=False):
|
|||
"""
|
||||
sess_list = session_mgr.get_session_list()
|
||||
return [sess for sess in sess_list if plr_has_channel(sess, channel_name, return_muted)]
|
||||
|
||||
def load_object_channels(pobject):
|
||||
"""
|
||||
Parse JSON dict of a user's channel list from their CHANLIST attribute.
|
||||
"""
|
||||
chan_list = pobject.get_attribute_value("__CHANLIST")
|
||||
if chan_list:
|
||||
session = session_mgr.session_from_object(pobject)
|
||||
session.channels_subscribed = simplejson.loads(chan_list)
|
||||
|
||||
def send_cmessage(channel_name, message):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ default. It will have the necessary outline for developers to sub-class and over
|
|||
"""
|
||||
from src import ansi
|
||||
|
||||
class BasicObject:
|
||||
class BasicObject(object):
|
||||
def __init__(self, source_obj):
|
||||
"""
|
||||
Get our ducks in a row.
|
||||
|
|
|
|||
0
src/scripts/player/__init__.py
Normal file
0
src/scripts/player/__init__.py
Normal file
39
src/scripts/player/basicplayer.py
Normal file
39
src/scripts/player/basicplayer.py
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
"""
|
||||
The basic Player object script parent.
|
||||
"""
|
||||
import time
|
||||
|
||||
from src import comsys
|
||||
from src.scripts.basicobject import BasicObject
|
||||
|
||||
class BasicPlayer(BasicObject):
|
||||
def at_pre_login(self):
|
||||
"""
|
||||
Everything done here takes place before the player is actually
|
||||
'logged in', in a sense that they're not ready to send logged in
|
||||
commands or receive communication.
|
||||
"""
|
||||
pobject = self.source_obj
|
||||
session = pobject.get_session()
|
||||
|
||||
# Load the player's channels from their JSON __CHANLIST attribute.
|
||||
comsys.load_object_channels(pobject)
|
||||
pobject.set_attribute("Last", "%s" % (time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()),))
|
||||
pobject.set_attribute("Lastsite", "%s" % (session.address[0],))
|
||||
pobject.set_flag("CONNECTED", True)
|
||||
|
||||
def at_post_login(self):
|
||||
"""
|
||||
The user is now logged in. This is what happens right after the moment
|
||||
they are 'connected'.
|
||||
"""
|
||||
pobject = self.source_obj
|
||||
session = pobject.get_session()
|
||||
|
||||
session.msg("You are now logged in as %s." % (pobject.name,))
|
||||
pobject.get_location().emit_to_contents("%s has connected." %
|
||||
(pobject.get_name(show_dbref=False),), exclude=pobject)
|
||||
session.execute_cmd("look")
|
||||
|
||||
def class_factory(source_obj):
|
||||
return BasicPlayer(source_obj)
|
||||
|
|
@ -8,7 +8,6 @@ from datetime import datetime
|
|||
|
||||
from twisted.conch.telnet import StatefulTelnetProtocol
|
||||
|
||||
from django.utils import simplejson
|
||||
from django.contrib.auth.models import User
|
||||
|
||||
from apps.objects.models import Object
|
||||
|
|
@ -69,14 +68,6 @@ class SessionProtocol(StatefulTelnetProtocol):
|
|||
"""
|
||||
logger.log_infomsg('Disconnect: %s' % (self,))
|
||||
self.handle_close()
|
||||
|
||||
def load_user_channels(self):
|
||||
"""
|
||||
Parse JSON dict of a user's channel list from their CHANLIST attribute.
|
||||
"""
|
||||
chan_list = self.get_pobject().get_attribute_value("__CHANLIST")
|
||||
if chan_list:
|
||||
self.channels_subscribed = simplejson.loads(chan_list)
|
||||
|
||||
def lineReceived(self, data):
|
||||
"""
|
||||
|
|
@ -121,7 +112,7 @@ class SessionProtocol(StatefulTelnetProtocol):
|
|||
result = Object.objects.get(id=self.uid)
|
||||
return result
|
||||
except:
|
||||
return False
|
||||
return None
|
||||
|
||||
def game_connect_screen(self):
|
||||
"""
|
||||
|
|
@ -150,21 +141,15 @@ class SessionProtocol(StatefulTelnetProtocol):
|
|||
self.conn_time = time.time()
|
||||
pobject = self.get_pobject()
|
||||
session_mgr.disconnect_duplicate_session(self)
|
||||
pobject.set_flag("CONNECTED", True)
|
||||
|
||||
self.msg("You are now logged in as %s." % (self.name,))
|
||||
pobject.get_location().emit_to_contents("%s has connected." % (pobject.get_name(show_dbref=False),), exclude=pobject)
|
||||
self.execute_cmd("look")
|
||||
|
||||
pobject.get_scriptlink().at_pre_login()
|
||||
pobject.get_scriptlink().at_post_login()
|
||||
|
||||
logger.log_infomsg("Login: %s" % (self,))
|
||||
|
||||
# Update their account's last login time.
|
||||
user.last_login = datetime.now()
|
||||
user.save()
|
||||
pobject.set_attribute("Last", "%s" % (time.strftime("%a %b %d %H:%M:%S %Y", time.localtime()),))
|
||||
pobject.set_attribute("Lastsite", "%s" % (self.address[0],))
|
||||
|
||||
# Load their channel selection from a JSON-encoded string attribute.
|
||||
self.load_user_channels()
|
||||
|
||||
def msg(self, message):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue