console_api.html 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. <!DOCTYPE html>
  2. <html class="writer-html5" lang="en" >
  3. <head>
  4. <meta charset="utf-8" /><meta name="generator" content="Docutils 0.17.1: http://docutils.sourceforge.net/" />
  5. <meta property="article:modified_time" content="2017-10-28T12:25:25+00:00" /><meta property="og:title" content="Console API" />
  6. <meta property="og:type" content="website" />
  7. <meta property="og:url" content="https://docs.crownengine.org/html/latest/hackers/console_api.html" />
  8. <meta property="og:site_name" content="Crown 0.60.0 Manual" />
  9. <meta property="og:description" content="Any number of clients can connect to the engine via TCP/IP and communicate with simple JSON API. The default port number is 10001 as defined by CROWN_DEFAULT_CONSOLE_PORT. You can change the port number with--console-port option. TCP protocol: Every message starts with u32 hea..." />
  10. <meta name="description" content="Any number of clients can connect to the engine via TCP/IP and communicate with simple JSON API. The default port number is 10001 as defined by CROWN_DEFAULT_CONSOLE_PORT. You can change the port number with--console-port option. TCP protocol: Every message starts with u32 hea..." />
  11. <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  12. <title>Console API &mdash; Crown 0.60.0 Manual 0.61.0 documentation</title>
  13. <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
  14. <link rel="stylesheet" href="../_static/css/theme.css" type="text/css" />
  15. <link rel="stylesheet" href="../_static/css/custom.css" type="text/css" />
  16. <link rel="shortcut icon" href="../_static/org.crownengine.Crown.svg"/>
  17. <link rel="canonical" href="https://docs.crownengine.org/html/latest/hackers/console_api.html" />
  18. <!--[if lt IE 9]>
  19. <script src="../_static/js/html5shiv.min.js"></script>
  20. <![endif]-->
  21. <script data-url_root="../" id="documentation_options" src="../_static/documentation_options.js"></script>
  22. <script src="../_static/jquery.js"></script>
  23. <script src="../_static/underscore.js"></script>
  24. <script src="../_static/doctools.js"></script>
  25. <script src="../_static/js/theme.js"></script>
  26. <link rel="index" title="Index" href="../genindex.html" />
  27. <link rel="search" title="Search" href="../search.html" />
  28. <link rel="copyright" title="Copyright" href="../copyright.html" />
  29. <link rel="prev" title="Building" href="building.html" />
  30. </head>
  31. <body class="wy-body-for-nav">
  32. <div class="wy-grid-for-nav">
  33. <nav data-toggle="wy-nav-shift" class="wy-nav-side">
  34. <div class="wy-side-scroll">
  35. <div class="wy-side-nav-search" >
  36. <a href="../index.html">
  37. <img src="../_static/org.crownengine.Crown.svg" class="logo" alt="Logo"/>
  38. </a>
  39. <div class="version">
  40. Crown 0.60.0 Manual
  41. </div>
  42. <div role="search">
  43. <form id="rtd-search-form" class="wy-form" action="../search.html" method="get">
  44. <input type="text" name="q" placeholder="Search docs" />
  45. <input type="hidden" name="check_keywords" value="yes" />
  46. <input type="hidden" name="area" value="default" />
  47. </form>
  48. </div>
  49. </div><div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="Navigation menu">
  50. <ul class="current">
  51. <li class="toctree-l1"><a class="reference internal" href="../changelog.html">Changelog</a></li>
  52. <li class="toctree-l1"><a class="reference internal" href="../introduction.html">Introduction</a></li>
  53. <li class="toctree-l1"><a class="reference internal" href="../installing_crown/index.html">Installing Crown</a></li>
  54. <li class="toctree-l1"><a class="reference internal" href="../getting_started/index.html">Getting Started</a></li>
  55. <li class="toctree-l1"><a class="reference internal" href="../importing_resources/index.html">Importing Resources</a></li>
  56. <li class="toctree-l1"><a class="reference internal" href="../gameplay/index.html">Writing Gameplay</a></li>
  57. <li class="toctree-l1"><a class="reference internal" href="../deploying/index.html">Deploying</a></li>
  58. <li class="toctree-l1"><a class="reference internal" href="../reference/index.html">Reference</a></li>
  59. <li class="toctree-l1"><a class="reference internal" href="../lua_api.html">Lua API reference</a></li>
  60. <li class="toctree-l1"><a class="reference internal" href="../glossary.html">Glossary</a></li>
  61. <li class="toctree-l1"><a class="reference internal" href="../copyright.html">License</a></li>
  62. <li class="toctree-l1 current"><a class="reference internal" href="index.html">Hackers</a><ul class="current">
  63. <li class="toctree-l2"><a class="reference internal" href="building.html">Building</a></li>
  64. <li class="toctree-l2 current"><a class="current reference internal" href="#">Console API</a><ul>
  65. <li class="toctree-l3"><a class="reference internal" href="#tcp-protocol">TCP protocol</a></li>
  66. <li class="toctree-l3"><a class="reference internal" href="#json-messages">JSON messages</a></li>
  67. <li class="toctree-l3"><a class="reference internal" href="#execute-lua-scripts">Execute Lua scripts</a></li>
  68. </ul>
  69. </li>
  70. </ul>
  71. </li>
  72. </ul>
  73. </div>
  74. </div>
  75. </nav>
  76. <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"><nav class="wy-nav-top" aria-label="Mobile navigation menu" >
  77. <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
  78. <a href="../index.html">Crown 0.60.0 Manual</a>
  79. </nav>
  80. <div class="wy-nav-content">
  81. <div class="rst-content">
  82. <div role="navigation" aria-label="Page navigation">
  83. <ul class="wy-breadcrumbs">
  84. <li><a href="../index.html" class="icon icon-home"></a> &raquo;</li>
  85. <li><a href="index.html">Hackers</a> &raquo;</li>
  86. <li>Console API</li>
  87. <li class="wy-breadcrumbs-aside">
  88. <a href="../_sources/hackers/console_api.rst.txt" rel="nofollow"> View page source</a>
  89. </li>
  90. </ul>
  91. <hr/>
  92. </div>
  93. <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
  94. <div itemprop="articleBody">
  95. <section id="console-api">
  96. <h1>Console API<a class="headerlink" href="#console-api" title="Permalink to this headline">¶</a></h1>
  97. <p>Any number of clients can connect to the engine via TCP/IP and communicate
  98. with simple JSON API. The default port number is 10001 as defined by <code class="docutils literal notranslate"><span class="pre">CROWN_DEFAULT_CONSOLE_PORT</span></code>.
  99. You can change the port number with <code class="docutils literal notranslate"><span class="pre">--console-port</span></code> option.</p>
  100. <section id="tcp-protocol">
  101. <h2>TCP protocol<a class="headerlink" href="#tcp-protocol" title="Permalink to this headline">¶</a></h2>
  102. <p>Every message starts with u32 header containing the size in bytes of the
  103. following JSON message.</p>
  104. </section>
  105. <section id="json-messages">
  106. <h2>JSON messages<a class="headerlink" href="#json-messages" title="Permalink to this headline">¶</a></h2>
  107. <p>Every JSON message has a <code class="docutils literal notranslate"><span class="pre">type</span></code> key which identifies its type.
  108. Sending messages with unknown <code class="docutils literal notranslate"><span class="pre">type</span></code> will result with an error message:</p>
  109. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
  110. <span class="s2">&quot;type&quot;</span> <span class="p">:</span> <span class="s2">&quot;error&quot;</span><span class="p">,</span>
  111. <span class="s2">&quot;message&quot;</span> <span class="p">:</span> <span class="s2">&quot;Unknown command&quot;</span>
  112. <span class="p">}</span>
  113. </pre></div>
  114. </div>
  115. </section>
  116. <section id="execute-lua-scripts">
  117. <h2>Execute Lua scripts<a class="headerlink" href="#execute-lua-scripts" title="Permalink to this headline">¶</a></h2>
  118. <p>Executing Lua script is as simple as sending the following message:</p>
  119. <div class="highlight-default notranslate"><div class="highlight"><pre><span></span><span class="p">{</span>
  120. <span class="s2">&quot;type&quot;</span> <span class="p">:</span> <span class="s2">&quot;script&quot;</span><span class="p">,</span>
  121. <span class="s2">&quot;script&quot;</span> <span class="p">:</span> <span class="s2">&quot;print(&#39;Hello, world!&#39;)&quot;</span>
  122. <span class="p">}</span>
  123. </pre></div>
  124. </div>
  125. <p>All the tools are controlled by sending simple Lua scripts to them.</p>
  126. </section>
  127. </section>
  128. </div>
  129. </div>
  130. <footer><div class="rst-footer-buttons" role="navigation" aria-label="Footer">
  131. <a href="building.html" class="btn btn-neutral float-left" title="Building" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a>
  132. </div>
  133. <hr/>
  134. <div role="contentinfo">
  135. <p>&#169; <a href="../copyright.html">Copyright</a> Except where otherwise noted, content on this page is licensed under a CC-BY-SA 4.0 Int. License.
  136. <span class="lastupdated">Last updated on Oct 28, 2017.
  137. </span></p>
  138. </div>
  139. Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
  140. <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
  141. provided by <a href="https://readthedocs.org">Read the Docs</a>.
  142. </footer>
  143. </div>
  144. </div>
  145. </section>
  146. </div>
  147. <script>
  148. jQuery(function () {
  149. SphinxRtdTheme.Navigation.enable(true);
  150. });
  151. </script>
  152. <!-- Theme Analytics -->
  153. <script async src="https://www.googletagmanager.com/gtag/js?id=G-XNVGCMNDZH"></script>
  154. <script>
  155. window.dataLayer = window.dataLayer || [];
  156. function gtag(){dataLayer.push(arguments);}
  157. gtag('js', new Date());
  158. gtag('config', 'G-XNVGCMNDZH', {
  159. 'anonymize_ip': true,
  160. });
  161. </script>
  162. </body>
  163. </html>