mirror of
https://github.com/evennia/evennia.git
synced 2026-03-18 13:56:30 +01:00
235 lines
No EOL
14 KiB
HTML
235 lines
No EOL
14 KiB
HTML
|
||
<!DOCTYPE html>
|
||
|
||
<html>
|
||
<head>
|
||
<meta charset="utf-8" />
|
||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
|
||
|
||
<title>evennia.commands.cmdhandler — Evennia 3.x documentation</title>
|
||
<link rel="stylesheet" href="../_static/nature.css" type="text/css" />
|
||
<link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
|
||
<script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
|
||
<script src="../_static/jquery.js"></script>
|
||
<script src="../_static/underscore.js"></script>
|
||
<script src="../_static/doctools.js"></script>
|
||
<script src="../_static/language_data.js"></script>
|
||
<link rel="shortcut 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="evennia.commands.cmdparser" href="evennia.commands.cmdparser.html" />
|
||
<link rel="prev" title="evennia.commands" href="evennia.commands.html" />
|
||
</head><body>
|
||
|
||
|
||
<div class="admonition important">
|
||
<p class="first admonition-title">Note</p>
|
||
<p class="last">You are reading an old version of the Evennia documentation. <a href="https://www.evennia.com/docs/latest/index.html">The latest version is here</a></p>.
|
||
</div>
|
||
|
||
|
||
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<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="evennia.commands.cmdparser.html" title="evennia.commands.cmdparser"
|
||
accesskey="N">next</a> |</li>
|
||
<li class="right" >
|
||
<a href="evennia.commands.html" title="evennia.commands"
|
||
accesskey="P">previous</a> |</li>
|
||
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 3.x</a> »</li>
|
||
<li class="nav-item nav-item-1"><a href="../Evennia-API.html" >API Summary</a> »</li>
|
||
<li class="nav-item nav-item-2"><a href="evennia-api.html" >evennia</a> »</li>
|
||
<li class="nav-item nav-item-3"><a href="evennia.html" >evennia</a> »</li>
|
||
<li class="nav-item nav-item-4"><a href="evennia.commands.html" accesskey="U">evennia.commands</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">evennia.commands.cmdhandler</a></li>
|
||
</ul>
|
||
</div>
|
||
|
||
<div class="document">
|
||
|
||
<div class="documentwrapper">
|
||
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
||
<div class="sphinxsidebarwrapper">
|
||
<p class="logo"><a href="../index.html">
|
||
<img class="logo" src="../_static/evennia_logo.png" alt="Logo"/>
|
||
</a></p>
|
||
<div 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" />
|
||
<input type="submit" value="Go" />
|
||
</form>
|
||
</div>
|
||
</div>
|
||
<script>$('#searchbox').show(0);</script>
|
||
<h4>Previous topic</h4>
|
||
<p class="topless"><a href="evennia.commands.html"
|
||
title="previous chapter">evennia.commands</a></p>
|
||
<h4>Next topic</h4>
|
||
<p class="topless"><a href="evennia.commands.cmdparser.html"
|
||
title="next chapter">evennia.commands.cmdparser</a></p>
|
||
<div role="note" aria-label="source link">
|
||
<!--h3>This Page</h3-->
|
||
<ul class="this-page-menu">
|
||
<li><a href="../_sources/api/evennia.commands.cmdhandler.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>
|
||
</div>
|
||
</div>
|
||
<div class="bodywrapper">
|
||
<div class="body" role="main">
|
||
|
||
<section id="module-evennia.commands.cmdhandler">
|
||
<span id="evennia-commands-cmdhandler"></span><h1>evennia.commands.cmdhandler<a class="headerlink" href="#module-evennia.commands.cmdhandler" title="Permalink to this headline">¶</a></h1>
|
||
<p>Command handler</p>
|
||
<p>This module contains the infrastructure for accepting commands on the
|
||
command line. The processing of a command works as follows:</p>
|
||
<ol class="arabic">
|
||
<li><p>The calling object (caller) is analyzed based on its callertype.</p></li>
|
||
<li><p>Cmdsets are gathered from different sources:
|
||
- object cmdsets: all objects at caller’s location are scanned for non-empty</p>
|
||
<blockquote>
|
||
<div><p>cmdsets. This includes cmdsets on exits.</p>
|
||
</div></blockquote>
|
||
<ul class="simple">
|
||
<li><p>caller: the caller is searched for its own currently active cmdset.</p></li>
|
||
<li><p>account: lastly the cmdsets defined on caller.account are added.</p></li>
|
||
</ul>
|
||
</li>
|
||
<li><p>The collected cmdsets are merged together to a combined, current cmdset.</p></li>
|
||
<li><p>If the input string is empty -> check for CMD_NOINPUT command in
|
||
current cmdset or fallback to error message. Exit.</p></li>
|
||
<li><p>The Command Parser is triggered, using the current cmdset to analyze the
|
||
input string for possible command matches.</p></li>
|
||
<li><p>If multiple matches are found -> check for CMD_MULTIMATCH in current
|
||
cmdset, or fallback to error message. Exit.</p></li>
|
||
<li><p>If no match was found -> check for CMD_NOMATCH in current cmdset or
|
||
fallback to error message. Exit.</p></li>
|
||
<li><p>At this point we have found a normal command. We assign useful variables to it that
|
||
will be available to the command coder at run-time.</p></li>
|
||
<li><p>We have a unique cmdobject, primed for use. Call all hooks:
|
||
<strong>at_pre_cmd()</strong>, <strong>cmdobj.parse()</strong>, <strong>cmdobj.func()</strong> and finally <strong>at_post_cmd()</strong>.</p></li>
|
||
<li><p>Return deferred that will fire with the return from <strong>cmdobj.func()</strong> (unused by default).</p></li>
|
||
</ol>
|
||
<dl class="py function">
|
||
<dt id="evennia.commands.cmdhandler.cmdhandler">
|
||
<code class="sig-prename descclassname">evennia.commands.cmdhandler.</code><code class="sig-name descname">cmdhandler</code><span class="sig-paren">(</span><em class="sig-param"><span class="n">called_by</span></em>, <em class="sig-param"><span class="n">raw_string</span></em>, <em class="sig-param"><span class="n">_testing</span><span class="o">=</span><span class="default_value">False</span></em>, <em class="sig-param"><span class="n">callertype</span><span class="o">=</span><span class="default_value">'session'</span></em>, <em class="sig-param"><span class="n">session</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">cmdobj</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="n">cmdobj_key</span><span class="o">=</span><span class="default_value">None</span></em>, <em class="sig-param"><span class="o">**</span><span class="n">kwargs</span></em><span class="sig-paren">)</span><a class="reference internal" href="../_modules/evennia/commands/cmdhandler.html#cmdhandler"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.commands.cmdhandler.cmdhandler" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>This is the main mechanism that handles any string sent to the engine.</p>
|
||
<dl class="field-list simple">
|
||
<dt class="field-odd">Parameters</dt>
|
||
<dd class="field-odd"><ul class="simple">
|
||
<li><p><strong>called_by</strong> (<a class="reference internal" href="evennia.server.session.html#evennia.server.session.Session" title="evennia.server.session.Session"><em>Session</em></a><em>, </em><em>Account</em><em> or </em><em>Object</em>) – Object from which this
|
||
command was called. which this was called from. What this is
|
||
depends on the game state.</p></li>
|
||
<li><p><strong>raw_string</strong> (<em>str</em>) – The command string as given on the command line.</p></li>
|
||
<li><p><strong>_testing</strong> (<em>bool</em><em>, </em><em>optional</em>) – Used for debug purposes and decides if we
|
||
should actually execute the command or not. If True, the
|
||
command instance will be returned.</p></li>
|
||
<li><p><strong>callertype</strong> (<em>str</em><em>, </em><em>optional</em>) – One of “session”, “account” or
|
||
“object”. These are treated in decending order, so when the
|
||
Session is the caller, it will merge its own cmdset into
|
||
cmdsets from both Account and eventual puppeted Object (and
|
||
cmdsets in its room etc). An Account will only include its own
|
||
cmdset and the Objects and so on. Merge order is the same
|
||
order, so that Object cmdsets are merged in last, giving them
|
||
precendence for same-name and same-prio commands.</p></li>
|
||
<li><p><strong>session</strong> (<a class="reference internal" href="evennia.server.session.html#evennia.server.session.Session" title="evennia.server.session.Session"><em>Session</em></a><em>, </em><em>optional</em>) – Relevant if callertype is “account” - the session will help
|
||
retrieve the correct cmdsets from puppeted objects.</p></li>
|
||
<li><p><strong>cmdobj</strong> (<a class="reference internal" href="evennia.commands.command.html#evennia.commands.command.Command" title="evennia.commands.command.Command"><em>Command</em></a><em>, </em><em>optional</em>) – If given a command instance, this will be executed using
|
||
<strong>called_by</strong> as the caller, <strong>raw_string</strong> representing its arguments and (optionally)
|
||
<strong>cmdobj_key</strong> as its input command name. No cmdset lookup will be performed but
|
||
all other options apply as normal. This allows for running a specific Command
|
||
within the command system mechanism.</p></li>
|
||
<li><p><strong>cmdobj_key</strong> (<em>string</em><em>, </em><em>optional</em>) – Used together with <strong>cmdobj</strong> keyword to specify
|
||
which cmdname should be assigned when calling the specified Command instance. This
|
||
is made available as <strong>self.cmdstring</strong> when the Command runs.
|
||
If not given, the command will be assumed to be called as <strong>cmdobj.key</strong>.</p></li>
|
||
</ul>
|
||
</dd>
|
||
<dt class="field-even">Keyword Arguments</dt>
|
||
<dd class="field-even"><p><strong>kwargs</strong> (<em>any</em>) – other keyword arguments will be assigned as named variables on the
|
||
retrieved command object <em>before</em> it is executed. This is unused
|
||
in default Evennia but may be used by code to set custom flags or
|
||
special operating conditions for a command as it executes.</p>
|
||
</dd>
|
||
<dt class="field-odd">Returns</dt>
|
||
<dd class="field-odd"><p><em>deferred (Deferred)</em> – This deferred is fired with the return
|
||
value of the command’s <strong>func</strong> method. This is not used in
|
||
default Evennia.</p>
|
||
</dd>
|
||
</dl>
|
||
</dd></dl>
|
||
|
||
<dl class="py exception">
|
||
<dt id="evennia.commands.cmdhandler.InterruptCommand">
|
||
<em class="property">exception </em><code class="sig-prename descclassname">evennia.commands.cmdhandler.</code><code class="sig-name descname">InterruptCommand</code><a class="reference internal" href="../_modules/evennia/commands/command.html#InterruptCommand"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#evennia.commands.cmdhandler.InterruptCommand" title="Permalink to this definition">¶</a></dt>
|
||
<dd><p>Bases: <code class="xref py py-class docutils literal notranslate"><span class="pre">Exception</span></code></p>
|
||
<p>Cleanly interrupt a command.</p>
|
||
</dd></dl>
|
||
|
||
</section>
|
||
|
||
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
<div class="related" role="navigation" aria-label="related navigation">
|
||
<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="evennia.commands.cmdparser.html" title="evennia.commands.cmdparser"
|
||
>next</a> |</li>
|
||
<li class="right" >
|
||
<a href="evennia.commands.html" title="evennia.commands"
|
||
>previous</a> |</li>
|
||
<li class="nav-item nav-item-0"><a href="../index.html">Evennia 3.x</a> »</li>
|
||
<li class="nav-item nav-item-1"><a href="../Evennia-API.html" >API Summary</a> »</li>
|
||
<li class="nav-item nav-item-2"><a href="evennia-api.html" >evennia</a> »</li>
|
||
<li class="nav-item nav-item-3"><a href="evennia.html" >evennia</a> »</li>
|
||
<li class="nav-item nav-item-4"><a href="evennia.commands.html" >evennia.commands</a> »</li>
|
||
<li class="nav-item nav-item-this"><a href="">evennia.commands.cmdhandler</a></li>
|
||
</ul>
|
||
</div>
|
||
|
||
|
||
<div class="admonition important">
|
||
<p class="first admonition-title">Note</p>
|
||
<p class="last">You are reading an old version of the Evennia documentation. <a href="https://www.evennia.com/docs/latest/index.html">The latest version is here</a></p>.
|
||
</div>
|
||
|
||
|
||
<div class="footer" role="contentinfo">
|
||
© Copyright 2023, The Evennia developer community.
|
||
Created using <a href="https://www.sphinx-doc.org/">Sphinx</a> 3.2.1.
|
||
</div>
|
||
</body>
|
||
</html> |