mirror of
https://github.com/evennia/evennia.git
synced 2026-03-31 21:17:17 +02:00
Can now log in to a character selection screen. Lots more testing required before one-char-per-session works.
This commit is contained in:
parent
c0d634fe8c
commit
f1767251c6
6 changed files with 41 additions and 27 deletions
|
|
@ -696,7 +696,7 @@ class CmdOOCLook(MuxCommandOOC, CmdLook):
|
|||
characters = player.get_all_characters() # get all characters
|
||||
string = "You are logged in as {g%s{n." % player.key
|
||||
string += " Use {w@ic <character>{n to enter the game."
|
||||
string += "\n\nAvailable character%s:" % (characters.count() > 1 and "s" or "")
|
||||
string += "\n\nAvailable character%s:" % (len(characters) > 1 and "s" or "")
|
||||
for char in characters:
|
||||
csessid = char.sessid
|
||||
if csessid:
|
||||
|
|
|
|||
|
|
@ -282,7 +282,8 @@ class ObjectDB(TypedObject):
|
|||
def __sessid_del(self):
|
||||
"Deleter. Allows for del self.player"
|
||||
del_field_cache(self, "sessid")
|
||||
player = property(__sessid_get, __sessid_set, __sessid_del)
|
||||
sessid = property(__sessid_get, __sessid_set, __sessid_del)
|
||||
|
||||
# location property (wraps db_location)
|
||||
#@property
|
||||
def __location_get(self):
|
||||
|
|
|
|||
|
|
@ -369,6 +369,15 @@ class PlayerDB(TypedObject):
|
|||
"""
|
||||
Evennia -> User
|
||||
This is the main route for sending data back to the user from the server.
|
||||
|
||||
outgoing_string (string) - text data to send
|
||||
from_obj (Object/Player) - source object of message to send
|
||||
data (dict) - arbitrary data object containing eventual protocol-specific options
|
||||
sessid - the session id of the session to send to. If not given, return to
|
||||
all sessions connected to this player. This is usually only
|
||||
relevant when using msg() directly from a player-command (from
|
||||
a command on a Character, the character automatically stores and
|
||||
handles the sessid).
|
||||
"""
|
||||
if from_obj:
|
||||
# call hook
|
||||
|
|
@ -389,11 +398,12 @@ class PlayerDB(TypedObject):
|
|||
session.msg(outgoing_string, data)
|
||||
else:
|
||||
# if no session was specified, send to them all
|
||||
for sess in _GA(self, 'get_sessions'):
|
||||
for sess in _GA(self, 'get_all_sessions')():
|
||||
sess.msg(outgoing_string, data)
|
||||
|
||||
def inmsg(self, ingoing_string, sessid):
|
||||
"""
|
||||
User -> Evennia
|
||||
This is the reverse of msg - used by sessions to relay
|
||||
messages/data back into the game. It is normally not called
|
||||
from inside game code but only by the serversessions directly.
|
||||
|
|
@ -433,6 +443,10 @@ class PlayerDB(TypedObject):
|
|||
set_prop_cache(self, "_characters", cache)
|
||||
# call hooks
|
||||
character.at_init()
|
||||
if character:
|
||||
# start (persistent) scripts on this object
|
||||
#ScriptDB.objects.validate(obj=character)
|
||||
pass
|
||||
if character.db.FIRST_LOGIN:
|
||||
character.at_first_login()
|
||||
del character.db.FIRST_LOGIN
|
||||
|
|
@ -446,6 +460,8 @@ class PlayerDB(TypedObject):
|
|||
"""
|
||||
char = _GA(self, "get_character")(sessid=sessid)
|
||||
if char:
|
||||
# call hook before disconnecting
|
||||
character.at_disconnect()
|
||||
del char.sessid
|
||||
# update cache
|
||||
cache = get_prop_cache(self, "_characters") or {}
|
||||
|
|
@ -457,11 +473,11 @@ class PlayerDB(TypedObject):
|
|||
"""
|
||||
Return session with given sessid connected to this player.
|
||||
"""
|
||||
return SESSIONS.get_session_from_player(self, sessid=sessid)
|
||||
return SESSIONS.sessions_from_player(self, sessid=sessid)
|
||||
|
||||
def get_all_sessions(self):
|
||||
"Return all sessions connected to this player"
|
||||
return SESSIONS.get_session_from_player(self)
|
||||
return SESSIONS.sessions_from_player(self)
|
||||
|
||||
def get_character(self, sessid=None, character=None):
|
||||
"""
|
||||
|
|
@ -479,7 +495,7 @@ class PlayerDB(TypedObject):
|
|||
# try to return a character with a given sessid
|
||||
char = cache.get(sessid)
|
||||
if not char:
|
||||
char = _GA(self, "db_objs").filter(player=self, sessid=sessid) or None
|
||||
char = _GA(self, "db_objs").filter(db_player=self, db_sessid=sessid) or None
|
||||
if char:
|
||||
cache[sessid] = char[0]
|
||||
set_prop_cache(self, "_characters", cache)
|
||||
|
|
|
|||
|
|
@ -88,16 +88,20 @@ class Player(TypeClass):
|
|||
|
||||
## methods inherited from database model
|
||||
|
||||
def msg(self, outgoing_string, from_obj=None, data=None):
|
||||
def msg(self, outgoing_string, from_obj=None, data=None, sessid=None):
|
||||
"""
|
||||
Evennia -> User
|
||||
This is the main route for sending data back to the user from the server.
|
||||
|
||||
outgoing_string (string) - text data to send
|
||||
from_obj (Object/Player) - source object of message to send
|
||||
data (?) - arbitrary data object containing eventual protocol-specific options
|
||||
|
||||
"""
|
||||
data (dict) - arbitrary data object containing eventual protocol-specific options
|
||||
sessid - the session id of the session to send to. If not given, return to
|
||||
all sessions connected to this player. This is usually only
|
||||
relevant when using msg() directly from a player-command (from
|
||||
a command on a Character, the character automatically stores and
|
||||
handles the sessid).
|
||||
"""
|
||||
self.dbobj.msg(outgoing_string, from_obj=from_obj, data=data)
|
||||
|
||||
def swap_character(self, new_character, delete_old_character=False):
|
||||
|
|
@ -293,8 +297,7 @@ class Player(TypeClass):
|
|||
"""
|
||||
# Character.at_post_login also looks around. Only use
|
||||
# this as a backup when logging in without a character
|
||||
if not self.character:
|
||||
self.execute_cmd("look")
|
||||
self.execute_cmd("look")
|
||||
|
||||
def at_disconnect(self, reason=None):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -57,10 +57,6 @@ class ServerSession(Session):
|
|||
self.cmdset.update(init_mode=True)
|
||||
return
|
||||
|
||||
character = self.get_character()
|
||||
if character:
|
||||
# start (persistent) scripts on this object
|
||||
ScriptDB.objects.validate(obj=character)
|
||||
|
||||
def session_login(self, player):
|
||||
"""
|
||||
|
|
@ -103,7 +99,7 @@ class ServerSession(Session):
|
|||
self.log(_('Logged in: %(self)s') % {'self': self})
|
||||
|
||||
# start (persistent) scripts on this object
|
||||
ScriptDB.objects.validate(obj=self.player.character)
|
||||
#ScriptDB.objects.validate(obj=self.player.character)
|
||||
|
||||
#add session to connected list
|
||||
self.sessionhandler.login(self)
|
||||
|
|
@ -117,10 +113,10 @@ class ServerSession(Session):
|
|||
accounts.
|
||||
"""
|
||||
if self.logged_in:
|
||||
player = self.get_player()
|
||||
character = self.get_character()
|
||||
if character:
|
||||
character.at_disconnect()
|
||||
sessid = self.sessid
|
||||
player = self.player
|
||||
if player.get_character(sessid):
|
||||
player.disconnect_session_from_character(sessid)
|
||||
uaccount = player.user
|
||||
uaccount.last_login = datetime.now()
|
||||
uaccount.save()
|
||||
|
|
@ -140,10 +136,7 @@ class ServerSession(Session):
|
|||
Returns the in-game character associated with this session.
|
||||
This returns the typeclass of the object.
|
||||
"""
|
||||
player = self.get_player()
|
||||
if player:
|
||||
return player.character
|
||||
return None
|
||||
return self.logged_in and self.player.get_character(self.sessid) or None
|
||||
|
||||
def log(self, message, channel=True):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -500,6 +500,7 @@ def create_player(name, email, password,
|
|||
# call hook method (may override default permissions)
|
||||
new_player.at_player_creation()
|
||||
|
||||
print
|
||||
# custom given arguments potentially overrides the hook
|
||||
if permissions:
|
||||
new_player.permissions = permissions
|
||||
|
|
@ -521,7 +522,7 @@ def create_player(name, email, password,
|
|||
player=new_player, report_to=report_to)
|
||||
return new_character
|
||||
return new_player
|
||||
except Exception, e:
|
||||
except Exception:
|
||||
# a failure in creating the character
|
||||
if not user:
|
||||
# in there was a failure we clean up everything we can
|
||||
|
|
@ -538,7 +539,7 @@ def create_player(name, email, password,
|
|||
del new_character
|
||||
except Exception:
|
||||
pass
|
||||
raise e
|
||||
raise
|
||||
|
||||
# alias
|
||||
player = create_player
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue