本文整理汇总了Python中src.server.sessionhandler.SESSIONS类的典型用法代码示例。如果您正苦于以下问题:Python SESSIONS类的具体用法?Python SESSIONS怎么用?Python SESSIONS使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SESSIONS类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setUp
def setUp(self):
"sets up testing environment"
settings.DEFAULT_HOME = "#2"
# print "creating player %i: %s" % (self.CID, self.__class__.__name__)
self.player = create.create_player(
"TestPlayer%i" % self.CID, "[email protected]", "testpassword", typeclass=TestPlayerClass
)
self.player2 = create.create_player(
"TestPlayer%ib" % self.CID, "[email protected]", "testpassword", typeclass=TestPlayerClass
)
self.room1 = create.create_object("src.objects.objects.Room", key="Room%i" % self.CID, nohome=True)
self.room1.db.desc = "room_desc"
self.room2 = create.create_object("src.objects.objects.Room", key="Room%ib" % self.CID)
self.obj1 = create.create_object(TestObjectClass, key="Obj%i" % self.CID, location=self.room1, home=self.room1)
self.obj2 = create.create_object(TestObjectClass, key="Obj%ib" % self.CID, location=self.room1, home=self.room1)
self.char1 = create.create_object(
TestCharacterClass, key="Char%i" % self.CID, location=self.room1, home=self.room1
)
self.char1.permissions.add("Immortals")
self.char2 = create.create_object(
TestCharacterClass, key="Char%ib" % self.CID, location=self.room1, home=self.room1
)
self.char1.player = self.player
self.char2.player = self.player2
self.script = create.create_script("src.scripts.scripts.Script", key="Script%i" % self.CID)
self.player.permissions.add("Immortals")
# set up a fake session
global SESSIONS
session = ServerSession()
session.init_session("telnet", ("localhost", "testmode"), SESSIONS)
session.sessid = self.CID
SESSIONS.portal_connect(session.get_sync_data())
SESSIONS.login(SESSIONS.session_from_sessid(self.CID), self.player, testmode=True)
开发者ID:Zurriel,项目名称:evennia,代码行数:35,代码来源:tests.py
示例2: start
def start(self, ev_channel=None, rss_url=None, rss_rate=None):
"""
Start by telling the portal to start a new RSS session
ev_channel - key of the Evennia channel to connect to
rss_url - full URL to the RSS feed to subscribe to
rss_update_rate - how often for the feedreader to update
"""
global _SESSIONS
if not _SESSIONS:
from src.server.sessionhandler import SESSIONS as _SESSIONS
if ev_channel:
# connect to Evennia channel
channel = search.channel_search(ev_channel)
if not channel:
raise RuntimeError("Evennia Channel '%s' not found." % ev_channel)
channel = channel[0]
self.db.ev_channel = channel
if rss_url:
self.db.rss_url = rss_url
if rss_rate:
self.db.rss_rate = rss_rate
# instruct the server and portal to create a new session with
# the stored configuration
configdict = {"uid": self.dbid, "url": self.db.rss_url, "rate": self.db.rss_rate}
_SESSIONS.start_bot_session("src.server.portal.rss.RSSBotFactory", configdict)
开发者ID:TheWhiteOx,项目名称:evennia,代码行数:27,代码来源:bots.py
示例3: at_repeat
def at_repeat(self):
"called every 60 seconds"
global _SESSIONS
if not _SESSIONS:
from src.server.sessionhandler import SESSIONS as _SESSIONS
#print "session check!"
#print "ValidateSessions run"
_SESSIONS.validate_sessions()
开发者ID:reddcoin-project,项目名称:ReddConnect,代码行数:8,代码来源:scripts.py
示例4: func
def func(self):
"Implements command"
if not self.args:
self.caller.msg("Usage: @wall <message>")
return
message = '%s shouts "%s"' % (self.caller.name, self.args)
self.msg("Announcing to all connected players ...")
SESSIONS.announce_all(message)
开发者ID:Aumnren,项目名称:evennia,代码行数:8,代码来源:admin.py
示例5: func
def func(self):
"""
Get all connected players by polling session.
"""
caller = self.caller
session_list = SESSIONS.get_sessions()
if self.cmdstring == "doing":
show_session_data = False
else:
show_session_data = caller.check_permstring("Immortals") or caller.check_permstring("Wizards")
if show_session_data:
table = [["Player Name"], ["On for"], ["Idle"], ["Room"], ["Cmds"], ["Host"]]
else:
table = [["Player Name"], ["On for"], ["Idle"]]
for session in session_list:
if not session.logged_in:
continue
delta_cmd = time.time() - session.cmd_last_visible
delta_conn = time.time() - session.conn_time
plr_pobject = session.get_character()
if not plr_pobject:
plr_pobject = session.get_player()
show_session_data = False
table = [["Player Name"], ["On for"], ["Idle"]]
if show_session_data:
table[0].append(plr_pobject.name[:25])
table[1].append(utils.time_format(delta_conn, 0))
table[2].append(utils.time_format(delta_cmd, 1))
table[3].append(plr_pobject.location and plr_pobject.location.id or "None")
table[4].append(session.cmd_total)
table[5].append(session.address[0])
else:
table[0].append(plr_pobject.name[:25])
table[1].append(utils.time_format(delta_conn,0))
table[2].append(utils.time_format(delta_cmd,1))
stable = []
for row in table: # prettify values
stable.append([str(val).strip() for val in row])
ftable = utils.format_table(stable, 5)
string = ""
for ir, row in enumerate(ftable):
if ir == 0:
string += "\n" + "{w%s{n" % ("".join(row))
else:
string += "\n" + "".join(row)
nplayers = (SESSIONS.player_count())
if nplayers == 1:
string += '\nOne player logged in.'
else:
string += '\n%d players logged in.' % nplayers
caller.msg(string)
开发者ID:abbacode,项目名称:avaloria,代码行数:58,代码来源:general.py
示例6: func
def func(self):
"""
Reload the system.
"""
reason = ""
if self.args:
reason = "(Reason: %s) " % self.args.rstrip(".")
SESSIONS.announce_all(" Server restarting %s..." % reason)
SESSIONS.server.shutdown(mode='reload')
开发者ID:AHecky3,项目名称:evennia,代码行数:9,代码来源:system.py
示例7: func
def func(self):
"""
Get all connected players by polling session.
"""
player = self.player
session_list = SESSIONS.get_sessions()
session_list = sorted(session_list, key=lambda o: o.player.key)
if self.cmdstring == "doing":
show_session_data = False
else:
show_session_data = player.check_permstring("Immortals") or player.check_permstring("Wizards")
nplayers = (SESSIONS.player_count())
if show_session_data:
# privileged info
table = prettytable.PrettyTable(["{wPlayer Name",
"{wOn for",
"{wIdle",
"{wPuppeting",
"{wRoom",
"{wCmds",
"{wProtocol",
"{wHost"])
for session in session_list:
if not session.logged_in: continue
delta_cmd = time.time() - session.cmd_last_visible
delta_conn = time.time() - session.conn_time
player = session.get_player()
puppet = session.get_puppet()
location = puppet.location.key if puppet else "None"
table.add_row([utils.crop(player.name, width=25),
utils.time_format(delta_conn, 0),
utils.time_format(delta_cmd, 1),
utils.crop(puppet.key if puppet else "None", width=25),
utils.crop(location, width=25),
session.cmd_total,
session.protocol_key,
isinstance(session.address, tuple) and session.address[0] or session.address])
else:
# unprivileged
table = prettytable.PrettyTable(["{wPlayer name", "{wOn for", "{wIdle"])
for session in session_list:
if not session.logged_in:
continue
delta_cmd = time.time() - session.cmd_last_visible
delta_conn = time.time() - session.conn_time
player = session.get_player()
table.add_row([utils.crop(player.key, width=25),
utils.time_format(delta_conn, 0),
utils.time_format(delta_cmd, 1)])
isone = nplayers == 1
string = "{wPlayers:{n\n%s\n%s unique account%s logged in." % (table, "One" if isone else nplayers, "" if isone else "s")
self.msg(string)
开发者ID:RetroRodent,项目名称:evennia,代码行数:57,代码来源:player.py
示例8: func
def func(self):
"Define function"
try:
session = self.caller.sessions[0]
except Exception:
return
self.caller.msg('Shutting down server ...')
announcement = "\nServer is being SHUT DOWN!\n"
if self.args:
announcement += "%s\n" % self.args
logger.log_infomsg('Server shutdown by %s.' % self.caller.name)
SESSIONS.announce_all(announcement)
SESSIONS.portal_shutdown()
SESSIONS.server.shutdown(mode='shutdown')
开发者ID:abbacode,项目名称:avaloria,代码行数:14,代码来源:system.py
示例9: func
def func(self):
switches = [switch.lower() for switch in self.switches]
character = self.character
if self.cmdstring.lower() == 'ws':
if not switches and not self.args:
if not character:
self.msg("{RYou have no location. (See {rhelp @char{R for more information)")
return
if not character.location:
self.msg("{RYou don't seem to have any specific location.")
return
self.display_users([ con for con in character.location.contents if utils.inherits_from(con, "src.objects.objects.Character") ])
return
else:
if (not switches or switches == ['characters']) and not self.args:
characters = set()
for session in SESSIONS.get_sessions():
character = session.get_character()
if character:
character = character.typeclass
characters.add(character)
self.display_users(characters)
return
if switches == ['players'] and not self.args:
players = set()
for session in SESSIONS.get_sessions():
player = session.get_player()
if player:
player = player.typeclass
players.add(player)
self.display_users(players)
return
if switches == ['far'] and self.args:
target = match(self.args)
if not target:
self.msg('%cnNo match found for "' + self.args + "'")
return
self.display_users([target])
return
if switches == ['room'] and not self.args:
if not character:
self.msg("{RYou have no location. (See {rhelp @char{R for more information)")
return
if not character.location:
self.msg("{RYou don't seem to have any specific location.")
return
self.display_users([ con for con in character.location.contents if utils.inherits_from(con, "src.objects.objects.Character") ])
return
self.msg("Invalid '%s' command. See 'help %s' for usage" % (self.cmdstring, self.key))
开发者ID:dbenoy,项目名称:latitude,代码行数:49,代码来源:sys_who.py
示例10: func
def func(self):
"Define function"
try:
# Only allow shutdown if caller has session
self.caller.sessions[0]
except Exception:
return
self.msg("Shutting down server ...")
announcement = "\nServer is being SHUT DOWN!\n"
if self.args:
announcement += "%s\n" % self.args
logger.log_infomsg("Server shutdown by %s." % self.caller.name)
SESSIONS.announce_all(announcement)
SESSIONS.portal_shutdown()
SESSIONS.server.shutdown(mode="shutdown")
开发者ID:no-space,项目名称:evennia,代码行数:15,代码来源:system.py
示例11: msg
def msg(self, text=None, from_obj=None, sessid=0, **kwargs):
"""
Emits something to a session attached to the object.
message (str): The message to send
from_obj (obj): object that is sending.
data (object): an optional data object that may or may not
be used by the protocol.
sessid (int): sessid to relay to, if any.
If set to 0 (default), use either from_obj.sessid (if set) or self.sessid automatically
If None, echo to all connected sessions
"""
global _SESSIONS
if not _SESSIONS:
from src.server.sessionhandler import SESSIONS as _SESSIONS
text = to_str(text, force_string=True) if text else ""
if "data" in kwargs:
# deprecation warning
logger.log_depmsg("ObjectDB.msg(): 'data'-dict keyword is deprecated. Use **kwargs instead.")
data = kwargs.pop("data")
if isinstance(data, dict):
kwargs.update(data)
if from_obj:
# call hook
try:
_GA(from_obj, "at_msg_send")(text=text, to_obj=self, **kwargs)
except Exception:
pass
session = _SESSIONS.session_from_sessid(sessid if sessid else _GA(self, "sessid"))
if session:
session.msg(text=text, **kwargs)
开发者ID:Aumnren,项目名称:evennia,代码行数:35,代码来源:models.py
示例12: func
def func(self):
"""
Contructs the desired loop based on switches.
"""
construction = [ self.get_name, self.get_online_time, self.get_idle_time, self.get_status, self.get_location ]
self.switches = [ switch.lower() for switch in self.switches ]
if not getattr(self.caller, 'locks', None) or not \
('wiz' in self.switches and self.caller.locks.check_lockstring(self.caller, 'admin:perm(Immortals)')):
self.admin = False # This is a session, not a player.
construction.append(self.get_doing)
else:
construction.append(self.get_host)
self.admin = True
header = ''
separator = ' '
for function in construction:
header += '%s%s{n' % (function.color, function.title)
padding = function.spacing - len(function.title)
header += separator * padding
self.caller.msg(header)
users = [ [session, ''] for session in SESSIONS.get_sessions() if check_ignores(self.caller, [session.get_character()], silent=True) ]
if not self.admin:
users = [ user for user in users if user[Who.SESSION].get_character() ]
for user in users:
for function in construction:
user[Who.STRING] += function.color + "%%-%ss" % function.spacing % function(user[Who.SESSION]) + '{n'
self.caller.msg(user[Who.STRING])
开发者ID:Kelketek,项目名称:wintersoasis,代码行数:31,代码来源:who.py
示例13: get_all_connections
def get_all_connections(self, channel, online=False):
"""
Return the connections of all players listening
to this channel. If Online is true, it only returns
connected players.
"""
global _SESSIONS
if not _SESSIONS:
from src.server.sessionhandler import SESSIONS as _SESSIONS
PlayerChannelConnection = ContentType.objects.get(app_label="comms",
model="playerchannelconnection").model_class()
ExternalChannelConnection = ContentType.objects.get(app_label="comms",
model="externalchannelconnection").model_class()
players = []
if online:
session_list = _SESSIONS.get_sessions()
unique_online_users = set(sess.uid for sess in session_list if sess.logged_in)
online_players = (sess.get_player() for sess in session_list if sess.uid in unique_online_users)
for player in online_players:
players.extend(PlayerChannelConnection.objects.filter(
db_player=player.dbobj, db_channel=channel.dbobj))
else:
players.extend(PlayerChannelConnection.objects.get_all_connections(channel))
external_connections = ExternalChannelConnection.objects.get_all_connections(channel)
return itertools.chain(players, external_connections)
开发者ID:Aumnren,项目名称:evennia,代码行数:28,代码来源:managers.py
示例14: func
def func(self):
player = self.player
character = self.character
# Check arguments
message = self.args
if not message:
self.msg("{R[Invalid '{r%s{R' command. See '{rhelp %s{R' for usage]" % (self.cmdstring, self.key))
return
# Format the message
if character:
# If we have a character, then we can use the 'say' routines to format the message.
if message.startswith(':'):
message = character.speech_pose(message[1:])
elif message.startswith('"'):
message = character.speech_say(message[1:])
else:
message = character.speech_say(message)
else:
# If we have no character, we'll have to take care of the formatting
if message.startswith(':'):
message = '{b' + player.key + '{n ' + message[1:].replace('{', '{{').replace('%', '%%')
elif message.startswith('"'):
message = '{b' + player.key + '{n: ' + message[1:].replace('{', '{{').replace('%', '%%')
else:
message = '{b' + player.key + '{n: ' + message.replace('{', '{{').replace('%', '%%')
message = "{Y[ {cShout {Y| {n%s {Y]" % (message)
# Send it
for session in SESSIONS.get_sessions():
session_sessid = session.sessid
session_player = session.get_player()
if not session_player:
continue
session_player.msg(message, sessid=session_sessid)
开发者ID:dbenoy,项目名称:latitude,代码行数:33,代码来源:sys_wall.py
示例15: at_repeat
def at_repeat(self):
"""
Calls subscriptions every self.interval seconds
"""
for (func_key, sessid, interval, args, kwargs) in self.ndb.subscriptions.values():
session = SESSIONS.session_from_sessid(sessid)
OOB_HANDLER.execute_cmd(session, func_key, *args, **kwargs)
开发者ID:Aumnren,项目名称:evennia,代码行数:7,代码来源:oobhandler.py
示例16: get_session
def get_session(self, sessid):
"""
Return session with given sessid connected to this player.
"""
global _SESSIONS
if not _SESSIONS:
from src.server.sessionhandler import SESSIONS as _SESSIONS
return _SESSIONS.session_from_player(self, sessid)
开发者ID:Aumnren,项目名称:evennia,代码行数:8,代码来源:models.py
示例17: webclient
def webclient(request):
"""
Webclient page template loading.
"""
# as an example we send the number of connected players to the template
pagevars = {'num_players_connected': SESSIONS.player_count()}
context_instance = RequestContext(request)
return render_to_response('webclient.html', pagevars, context_instance)
开发者ID:Kelketek,项目名称:wintersoasis,代码行数:9,代码来源:views.py
示例18: get_session
def get_session(self, sessid):
"""
Return session with given sessid connected to this player.
note that the sessionhandler also accepts sessid as an iterable.
"""
global _SESSIONS
if not _SESSIONS:
from src.server.sessionhandler import SESSIONS as _SESSIONS
return _SESSIONS.session_from_player(self, sessid)
开发者ID:RetroRodent,项目名称:evennia,代码行数:9,代码来源:models.py
示例19: _callback
def _callback(self):
"See original for more info"
for key, (_, args, kwargs) in self.subscriptions.items():
# args = (sessid, callback_function)
session = SESSIONS.session_from_sessid(args[0])
try:
# execute the oob callback
yield args[1](OOB_HANDLER, session, *args[2:], **kwargs)
except Exception:
logger.log_trace()
开发者ID:AHecky3,项目名称:evennia,代码行数:10,代码来源:oobhandler.py
示例20: func
def func(self):
if self.args and self.args.isdigit():
self.show_whereare(int(self.args))
elif not self.args and not self.switches:
# Default threshold is 5% of the server's population
characters = 0
for session in SESSIONS.get_sessions():
if session.get_character():
characters += 1
self.show_whereare(characters / 20)
else:
self.msg("{R[Invalid '{r%s{R' command. See '{rhelp %s{R' for usage]" % (self.cmdstring, self.key))
开发者ID:dbenoy,项目名称:latitude,代码行数:12,代码来源:sys_whereare.py
注:本文中的src.server.sessionhandler.SESSIONS类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论