mirror of
https://github.com/evennia/evennia.git
synced 2026-03-16 21:06:30 +01:00
288 lines
No EOL
23 KiB
HTML
288 lines
No EOL
23 KiB
HTML
<!DOCTYPE html>
|
||
|
||
<html lang="en" data-content_root="../">
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="viewport" content="width=device-width, initial-scale=1" />
|
||
|
||
<title>Sessions — Evennia latest documentation</title>
|
||
<link rel="stylesheet" type="text/css" href="../_static/pygments.css?v=d75fae25" />
|
||
<link rel="stylesheet" type="text/css" href="../_static/nature.css?v=279e0f84" />
|
||
<link rel="stylesheet" type="text/css" href="../_static/custom.css?v=e4a91a55" />
|
||
<script src="../_static/documentation_options.js?v=c6e86fd7"></script>
|
||
<script src="../_static/doctools.js?v=9bcbadda"></script>
|
||
<script src="../_static/sphinx_highlight.js?v=dc90522c"></script>
|
||
<link rel="icon" href="../_static/favicon.ico"/>
|
||
<link rel="index" title="Index" href="../genindex.html" />
|
||
<link rel="search" title="Search" href="../search.html" />
|
||
<link rel="next" title="Typeclasses" href="Typeclasses.html" />
|
||
<link rel="prev" title="Portal And Server" href="Portal-And-Server.html" />
|
||
</head><body>
|
||
<div class="related" role="navigation" aria-label="Related">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="General Index"
|
||
accesskey="I">index</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python Module Index"
|
||
>modules</a> |</li>
|
||
<li class="right" >
|
||
<a href="Typeclasses.html" title="Typeclasses"
|
||
accesskey="N">next</a> |</li>
|
||
<li class="right" >
|
||
<a href="Portal-And-Server.html" title="Portal And Server"
|
||
accesskey="P">previous</a> |</li>
|
||
<li class="nav-item nav-item-0"><a href="../index.html">Evennia</a> »</li>
|
||
<li class="nav-item nav-item-1"><a href="Components-Overview.html" accesskey="U">Core Components</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">Sessions</a></li>
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="document">
|
||
<div class="documentwrapper">
|
||
<div class="bodywrapper">
|
||
<div class="body" role="main">
|
||
|
||
<section class="tex2jax_ignore mathjax_ignore" id="sessions">
|
||
<h1>Sessions<a class="headerlink" href="#sessions" title="Link to this heading">¶</a></h1>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span>┌──────┐ │ ┌───────┐ ┌───────┐ ┌──────┐
|
||
│Client├─┼──►│Session├───►│Account├──►│Object│
|
||
└──────┘ │ └───────┘ └───────┘ └──────┘
|
||
^
|
||
</pre></div>
|
||
</div>
|
||
<p>An Evennia <em>Session</em> represents one single established connection to the server. Depending on the
|
||
Evennia session, it is possible for a person to connect multiple times, for example using different
|
||
clients in multiple windows. Each such connection is represented by a session object.</p>
|
||
<p>A session object has its own <a class="reference internal" href="Command-Sets.html"><span class="std std-doc">cmdset</span></a>, usually the “unloggedin” cmdset. This is what is used to show the login screen and to handle commands to create a new account (or <a class="reference internal" href="Accounts.html"><span class="std std-doc">Account</span></a> in evennia lingo) read initial help and to log into the game with an existing account. A session object can either be “logged in” or not. Logged in means that the user has authenticated. When this happens the session is associated with an Account object (which is what holds account-centric stuff). The account can then in turn puppet any number of objects/characters.</p>
|
||
<p>A Session is not <em>persistent</em> - it is not a <a class="reference internal" href="Typeclasses.html"><span class="std std-doc">Typeclass</span></a> and has no connection to the database. The Session will go away when a user disconnects and you will lose any custom data on it if the server reloads. The <code class="docutils literal notranslate"><span class="pre">.db</span></code> handler on Sessions is there to present a uniform API (so you can assume <code class="docutils literal notranslate"><span class="pre">.db</span></code> exists even if you don’t know if you receive an Object or a Session), but this is just an alias to <code class="docutils literal notranslate"><span class="pre">.ndb</span></code>. So don’t store any data on Sessions that you can’t afford to lose in a reload.</p>
|
||
<section id="working-with-sessions">
|
||
<h2>Working with Sessions<a class="headerlink" href="#working-with-sessions" title="Link to this heading">¶</a></h2>
|
||
<section id="properties-on-sessions">
|
||
<h3>Properties on Sessions<a class="headerlink" href="#properties-on-sessions" title="Link to this heading">¶</a></h3>
|
||
<p>Here are some important properties available on (Server-)Sessions</p>
|
||
<ul class="simple">
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">sessid</span></code> - The unique session-id. This is an integer starting from 1.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">address</span></code> - The connected client’s address. Different protocols give different information here.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">logged_in</span></code> - <code class="docutils literal notranslate"><span class="pre">True</span></code> if the user authenticated to this session.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">account</span></code> - The <a class="reference internal" href="Accounts.html"><span class="std std-doc">Account</span></a> this Session is attached to. If not logged in yet, this is <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">puppet</span></code> - The <a class="reference internal" href="Objects.html"><span class="std std-doc">Character/Object</span></a> currently puppeted by this Account/Session combo. If not logged in or in OOC mode, this is <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">ndb</span></code> - The <a class="reference internal" href="Attributes.html"><span class="std std-doc">Non-persistent Attribute</span></a> handler.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">db</span></code> - As noted above, Sessions don’t have regular Attributes. This is an alias to <code class="docutils literal notranslate"><span class="pre">ndb</span></code>.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">cmdset</span></code> - The Session’s <a class="reference internal" href="Command-Sets.html"><span class="std std-doc">CmdSetHandler</span></a></p></li>
|
||
</ul>
|
||
<p>Session statistics are mainly used internally by Evennia.</p>
|
||
<ul class="simple">
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">conn_time</span></code> - How long this Session has been connected</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">cmd_last</span></code> - Last active time stamp. This will be reset by sending <code class="docutils literal notranslate"><span class="pre">idle</span></code> keepalives.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">cmd_last_visible</span></code> - last active time stamp. This ignores <code class="docutils literal notranslate"><span class="pre">idle</span></code> keepalives and representes the
|
||
last time this session was truly visibly active.</p></li>
|
||
<li><p><code class="docutils literal notranslate"><span class="pre">cmd_total</span></code> - Total number of Commands passed through this Session.</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="returning-data-to-the-session">
|
||
<h3>Returning data to the session<a class="headerlink" href="#returning-data-to-the-session" title="Link to this heading">¶</a></h3>
|
||
<p>When you use <code class="docutils literal notranslate"><span class="pre">msg()</span></code> to return data to a user, the object on which you call the <code class="docutils literal notranslate"><span class="pre">msg()</span></code> matters. The
|
||
<code class="docutils literal notranslate"><span class="pre">MULTISESSION_MODE</span></code> also matters, especially if greater than 1.</p>
|
||
<p>For example, if you use <code class="docutils literal notranslate"><span class="pre">account.msg("hello")</span></code> there is no way for evennia to know which session it
|
||
should send the greeting to. In this case it will send it to all sessions. If you want a specific
|
||
session you need to supply its session to the <code class="docutils literal notranslate"><span class="pre">msg</span></code> call (<code class="docutils literal notranslate"><span class="pre">account.msg("hello",</span> <span class="pre">session=mysession)</span></code>).</p>
|
||
<p>On the other hand, if you call the <code class="docutils literal notranslate"><span class="pre">msg()</span></code> message on a puppeted object, like
|
||
<code class="docutils literal notranslate"><span class="pre">character.msg("hello")</span></code>, the character already knows the session that controls it - it will
|
||
cleverly auto-add this for you (you can specify a different session if you specifically want to send
|
||
stuff to another session).</p>
|
||
<p>Finally, there is a wrapper for <code class="docutils literal notranslate"><span class="pre">msg()</span></code> on all command classes: <code class="docutils literal notranslate"><span class="pre">command.msg()</span></code>. This will
|
||
transparently detect which session was triggering the command (if any) and redirects to that session
|
||
(this is most often what you want). If you are having trouble redirecting to a given session,
|
||
<code class="docutils literal notranslate"><span class="pre">command.msg()</span></code> is often the safest bet.</p>
|
||
<p>You can get the <code class="docutils literal notranslate"><span class="pre">session</span></code> in two main ways:</p>
|
||
<ul class="simple">
|
||
<li><p><a class="reference internal" href="Accounts.html"><span class="std std-doc">Accounts</span></a> and <a class="reference internal" href="Objects.html"><span class="std std-doc">Objects</span></a> (including Characters) have a <code class="docutils literal notranslate"><span class="pre">sessions</span></code> property.
|
||
This is a <em>handler</em> that tracks all Sessions attached to or puppeting them. Use e.g.
|
||
<code class="docutils literal notranslate"><span class="pre">accounts.sessions.get()</span></code> to get a list of Sessions attached to that entity.</p></li>
|
||
<li><p>A Command instance has a <code class="docutils literal notranslate"><span class="pre">session</span></code> property that always points back to the Session that triggered
|
||
it (it’s always a single one). It will be <code class="docutils literal notranslate"><span class="pre">None</span></code> if no session is involved, like when a mob or
|
||
script triggers the Command.</p></li>
|
||
</ul>
|
||
</section>
|
||
<section id="customizing-the-session-object">
|
||
<h3>Customizing the Session object<a class="headerlink" href="#customizing-the-session-object" title="Link to this heading">¶</a></h3>
|
||
<p>When would one want to customize the Session object? Consider for example a character creation system: You might decide to keep this on the out-of-character level. This would mean that you create the character at the end of some sort of menu choice. The actual char-create cmdset would then normally be put on the account. This works fine as long as you are <code class="docutils literal notranslate"><span class="pre">MULTISESSION_MODE</span></code> below 2. For higher modes, replacing the Account cmdset will affect <em>all</em> your connected sessions, also those not involved in character creation. In this case you want to instead put the char-create cmdset on the Session level - then all other sessions will keep working normally despite you creating a new character in one of them.</p>
|
||
<p>By default, the session object gets the <code class="docutils literal notranslate"><span class="pre">commands.default_cmdsets.UnloggedinCmdSet</span></code> when the user first connects. Once the session is authenticated it has <em>no</em> default sets. To add a “logged-in” cmdset to the Session, give the path to the cmdset class with <code class="docutils literal notranslate"><span class="pre">settings.CMDSET_SESSION</span></code>. This set
|
||
will then henceforth always be present as soon as the account logs in.</p>
|
||
<p>To customize further you can completely override the Session with your own subclass. To replace the default Session class, change <code class="docutils literal notranslate"><span class="pre">settings.SERVER_SESSION_CLASS</span></code> to point to your custom class. This is a dangerous practice and errors can easily make your game unplayable. Make sure to take heed of the <a class="reference internal" href="../api/evennia.server.session.html#evennia-server-session"><span class="std std-ref">original</span></a> and make your changes carefully.</p>
|
||
</section>
|
||
</section>
|
||
<section id="portal-and-server-sessions">
|
||
<h2>Portal and Server Sessions<a class="headerlink" href="#portal-and-server-sessions" title="Link to this heading">¶</a></h2>
|
||
<p><em>Note: This is considered an advanced topic. You don’t need to know this on a first read-through.</em></p>
|
||
<p>Evennia is split into two parts, the <a class="reference internal" href="Portal-And-Server.html"><span class="std std-doc">Portal and the Server</span></a>. Each side tracks its own Sessions, syncing them to each other.</p>
|
||
<p>The “Session” we normally refer to is actually the <code class="docutils literal notranslate"><span class="pre">ServerSession</span></code>. Its counter-part on the Portal
|
||
side is the <code class="docutils literal notranslate"><span class="pre">PortalSession</span></code>. Whereas the server sessions deal with game states, the portal session
|
||
deals with details of the connection-protocol itself. The two are also acting as backups of critical
|
||
data such as when the server reboots.</p>
|
||
<p>New Account connections are listened for and handled by the Portal using the [protocols](Portal-And- Server) it understands (such as telnet, ssh, webclient etc). When a new connection is established, a <code class="docutils literal notranslate"><span class="pre">PortalSession</span></code> is created on the Portal side. This session object looks different depending on which protocol is used to connect, but all still have a minimum set of attributes that are generic to all sessions.</p>
|
||
<p>These common properties are piped from the Portal, through the AMP connection, to the Server, which is now informed a new connection has been established. On the Server side, a <code class="docutils literal notranslate"><span class="pre">ServerSession</span></code> object is created to represent this. There is only one type of <code class="docutils literal notranslate"><span class="pre">ServerSession</span></code>; It looks the same regardless of how the Account connects.</p>
|
||
<p>From now on, there is a one-to-one match between the <code class="docutils literal notranslate"><span class="pre">ServerSession</span></code> on one side of the AMP
|
||
connection and the <code class="docutils literal notranslate"><span class="pre">PortalSession</span></code> on the other. Data arriving to the Portal Session is sent on to
|
||
its mirror Server session and vice versa.</p>
|
||
<p>During certain situations, the portal- and server-side sessions are
|
||
“synced” with each other:</p>
|
||
<ul class="simple">
|
||
<li><p>The Player closes their client, killing the Portal Session. The Portal syncs with the Server to
|
||
make sure the corresponding Server Session is also deleted.</p></li>
|
||
<li><p>The Player quits from inside the game, killing the Server Session. The Server then syncs with the
|
||
Portal to make sure to close the Portal connection cleanly.</p></li>
|
||
<li><p>The Server is rebooted/reset/shutdown - The Server Sessions are copied over (“saved”) to the
|
||
Portal side. When the Server comes back up, this data is returned by the Portal so the two are again
|
||
in sync. This way an Account’s login status and other connection-critical things can survive a
|
||
server reboot (assuming the Portal is not stopped at the same time, obviously).</p></li>
|
||
</ul>
|
||
<section id="sessionhandlers">
|
||
<h3>Sessionhandlers<a class="headerlink" href="#sessionhandlers" title="Link to this heading">¶</a></h3>
|
||
<p>Both the Portal and Server each have a <em>sessionhandler</em> to manage the connections. These handlers
|
||
are global entities contain all methods for relaying data across the AMP bridge. All types of
|
||
Sessions hold a reference to their respective Sessionhandler (the property is called
|
||
<code class="docutils literal notranslate"><span class="pre">sessionhandler</span></code>) so they can relay data. See <a class="reference internal" href="../Concepts/Protocols.html"><span class="std std-doc">protocols</span></a> for more info on building new protocols.</p>
|
||
<p>To get all Sessions in the game (i.e. all currently connected clients), you access the server-side Session handler, which you get by</p>
|
||
<div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span><span class="w"> </span><span class="nn">evennia.server.sessionhandler</span><span class="w"> </span><span class="kn">import</span> <span class="n">SESSION_HANDLER</span>
|
||
</pre></div>
|
||
</div>
|
||
<blockquote>
|
||
<div><p>Note: The <code class="docutils literal notranslate"><span class="pre">SESSION_HANDLER</span></code> singleton has an older alias <code class="docutils literal notranslate"><span class="pre">SESSIONS</span></code> that is commonly seen in various places as well.</p>
|
||
</div></blockquote>
|
||
<p>See the <a class="reference internal" href="../api/evennia.server.sessionhandler.html#evennia-server-sessionhandler"><span class="std std-ref">sessionhandler.py</span></a> module for details on the capabilities of the <code class="docutils literal notranslate"><span class="pre">ServerSessionHandler</span></code>.</p>
|
||
</section>
|
||
</section>
|
||
</section>
|
||
|
||
|
||
<div class="clearer"></div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="sphinxsidebar" role="navigation" aria-label="Main">
|
||
<div class="sphinxsidebarwrapper">
|
||
<p class="logo"><a href="../index.html">
|
||
<img class="logo" src="../_static/evennia_logo.png" alt="Logo of Evennia"/>
|
||
</a></p>
|
||
<search id="searchbox" style="display: none" role="search">
|
||
<h3 id="searchlabel">Quick search</h3>
|
||
<div class="searchformwrapper">
|
||
<form class="search" action="../search.html" method="get">
|
||
<input type="text" name="q" aria-labelledby="searchlabel" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"/>
|
||
<input type="submit" value="Go" />
|
||
</form>
|
||
</div>
|
||
</search>
|
||
<script>document.getElementById('searchbox').style.display = "block"</script>
|
||
<h3><a href="../index.html">Table of Contents</a></h3>
|
||
<ul>
|
||
<li><a class="reference internal" href="#">Sessions</a><ul>
|
||
<li><a class="reference internal" href="#working-with-sessions">Working with Sessions</a><ul>
|
||
<li><a class="reference internal" href="#properties-on-sessions">Properties on Sessions</a></li>
|
||
<li><a class="reference internal" href="#returning-data-to-the-session">Returning data to the session</a></li>
|
||
<li><a class="reference internal" href="#customizing-the-session-object">Customizing the Session object</a></li>
|
||
</ul>
|
||
</li>
|
||
<li><a class="reference internal" href="#portal-and-server-sessions">Portal and Server Sessions</a><ul>
|
||
<li><a class="reference internal" href="#sessionhandlers">Sessionhandlers</a></li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
|
||
<div>
|
||
<h4>Previous topic</h4>
|
||
<p class="topless"><a href="Portal-And-Server.html"
|
||
title="previous chapter">Portal And Server</a></p>
|
||
</div>
|
||
<div>
|
||
<h4>Next topic</h4>
|
||
<p class="topless"><a href="Typeclasses.html"
|
||
title="next chapter">Typeclasses</a></p>
|
||
</div>
|
||
<div role="note" aria-label="source link">
|
||
<!--h3>This Page</h3-->
|
||
<ul class="this-page-menu">
|
||
<li><a href="../_sources/Components/Sessions.md.txt"
|
||
rel="nofollow">Show Page Source</a></li>
|
||
</ul>
|
||
</div><h3>Links</h3>
|
||
<ul>
|
||
<li><a href="https://www.evennia.com/docs/latest/index.html">Documentation Top</a> </li>
|
||
<li><a href="https://www.evennia.com">Evennia Home</a> </li>
|
||
<li><a href="https://github.com/evennia/evennia">Github</a> </li>
|
||
<li><a href="http://games.evennia.com">Game Index</a> </li>
|
||
<li>
|
||
<a href="https://discord.gg/AJJpcRUhtF">Discord</a> -
|
||
<a href="https://github.com/evennia/evennia/discussions">Discussions</a> -
|
||
<a href="https://evennia.blogspot.com/">Blog</a>
|
||
</li>
|
||
</ul>
|
||
<h3>Doc Versions</h3>
|
||
<ul>
|
||
|
||
<li>
|
||
<a href="https://www.evennia.com/docs/latest/index.html">latest (main branch)</a>
|
||
</li>
|
||
|
||
|
||
<li>
|
||
<a href="https://www.evennia.com/docs/5.x/index.html">v5.0.0 branch (outdated)</a>
|
||
</li>
|
||
|
||
<li>
|
||
<a href="https://www.evennia.com/docs/4.x/index.html">v4.0.0 branch (outdated)</a>
|
||
</li>
|
||
|
||
<li>
|
||
<a href="https://www.evennia.com/docs/3.x/index.html">v3.0.0 branch (outdated)</a>
|
||
</li>
|
||
|
||
<li>
|
||
<a href="https://www.evennia.com/docs/2.x/index.html">v2.0.0 branch (outdated)</a>
|
||
</li>
|
||
|
||
<li>
|
||
<a href="https://www.evennia.com/docs/1.x/index.html">v1.0.0 branch (outdated)</a>
|
||
</li>
|
||
|
||
<li>
|
||
<a href="https://www.evennia.com/docs/0.x/index.html">v0.9.5 branch (outdated)</a>
|
||
</li>
|
||
|
||
</ul>
|
||
|
||
</div>
|
||
</div>
|
||
<div class="clearer"></div>
|
||
</div>
|
||
<div class="related" role="navigation" aria-label="Related">
|
||
<h3>Navigation</h3>
|
||
<ul>
|
||
<li class="right" style="margin-right: 10px">
|
||
<a href="../genindex.html" title="General Index"
|
||
>index</a></li>
|
||
<li class="right" >
|
||
<a href="../py-modindex.html" title="Python Module Index"
|
||
>modules</a> |</li>
|
||
<li class="right" >
|
||
<a href="Typeclasses.html" title="Typeclasses"
|
||
>next</a> |</li>
|
||
<li class="right" >
|
||
<a href="Portal-And-Server.html" title="Portal And Server"
|
||
>previous</a> |</li>
|
||
<li class="nav-item nav-item-0"><a href="../index.html">Evennia</a> »</li>
|
||
<li class="nav-item nav-item-1"><a href="Components-Overview.html" >Core Components</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">Sessions</a></li>
|
||
</ul>
|
||
</div>
|
||
<div class="footer" role="contentinfo">
|
||
© Copyright 2024, The Evennia developer community.
|
||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 8.2.3.
|
||
</div>
|
||
</body>
|
||
</html> |