<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh">
	<id>https://game.etao.net/w/index.php?action=history&amp;feed=atom&amp;title=Marauroa_Chat_Tutorial%2FHTML5_Client</id>
	<title>Marauroa Chat Tutorial/HTML5 Client - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://game.etao.net/w/index.php?action=history&amp;feed=atom&amp;title=Marauroa_Chat_Tutorial%2FHTML5_Client"/>
	<link rel="alternate" type="text/html" href="https://game.etao.net/w/index.php?title=Marauroa_Chat_Tutorial/HTML5_Client&amp;action=history"/>
	<updated>2026-05-06T10:26:14Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.43.0</generator>
	<entry>
		<id>https://game.etao.net/w/index.php?title=Marauroa_Chat_Tutorial/HTML5_Client&amp;diff=152&amp;oldid=prev</id>
		<title>2022年6月8日 (三) 01:09 183.246.21.52</title>
		<link rel="alternate" type="text/html" href="https://game.etao.net/w/index.php?title=Marauroa_Chat_Tutorial/HTML5_Client&amp;diff=152&amp;oldid=prev"/>
		<updated>2022-06-08T01:09:18Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{Navigation for Marauroa Top|Using}}&lt;br /&gt;
{{Navigation for Marauroa Users}}&lt;br /&gt;
{{Marauroa Chat Tutorial}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;div style=&amp;quot;padding: 1em; border: 2px solid #AA0; width: 70%&amp;quot;&amp;gt;&lt;br /&gt;
HTML5 support in Marauroa is in development. We are looking for feedback to stabilize the API and improve the documentation on it.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
HTML5 客户端工作在现代浏览器中，无需在本地安装任何插件或其他软件。 因此，它不是用Java编写的，而是用JavaScript编写的。虽然JavaScript有一个相似的名称，但它是与Java完全不同。&lt;br /&gt;
== HTML Code ==&lt;br /&gt;
&lt;br /&gt;
我们通过创建一个 HTML 页面来启动我们的 HTML 5 客户端，该页面由一个用于聊天日志的输出区域和一个用于输入文本的小输入字段组成。 我们使用 CSS 规则使页面看起来更漂亮。 我们使用的是 Marauroa 的开发版本，它由几个 JS 文件组成。 最终版本将包含一个文件以减少启动时间。&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;html4strict&amp;quot;&amp;gt;&lt;br /&gt;
&amp;lt;!doctype html&amp;gt;&lt;br /&gt;
&amp;lt;html&amp;gt;&amp;lt;head&amp;gt;&lt;br /&gt;
    &amp;lt;title&amp;gt;Marautoa Chat Tutoral Client in HTML 5&amp;lt;/title&amp;gt;&lt;br /&gt;
    &amp;lt;style type=&amp;quot;text/css&amp;quot;&amp;gt;&lt;br /&gt;
        body {font-family: &amp;quot;Arial&amp;quot;}&lt;br /&gt;
        #chat {border: 1px solid #000; padding:0.5em; overflow-y: scroll}&lt;br /&gt;
        #chat p {margin: 0}&lt;br /&gt;
        p.logclient {color: #888}&lt;br /&gt;
        p.logerror {color: #F00}&lt;br /&gt;
    &amp;lt;/style&amp;gt;&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;!-- low level communication --&amp;gt;&lt;br /&gt;
    &amp;lt;script src=&amp;quot;json.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;lt;script src=&amp;quot;/socket.io/socket.io.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;lt;!-- Marauroa --&amp;gt;&lt;br /&gt;
    &amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;marauroa.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;client-framework.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;message-factory.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;perception.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;rpfactory.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
    &amp;lt;!-- Out code --&amp;gt;&lt;br /&gt;
    &amp;lt;script type=&amp;quot;text/javascript&amp;quot; src=&amp;quot;chatclient.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;&lt;br /&gt;
&amp;lt;/head&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;lt;body&amp;gt;&lt;br /&gt;
    &amp;lt;h1&amp;gt;Marautoa Chat Tutoral Client in HTML 5&amp;lt;/h1&amp;gt;&lt;br /&gt;
    &amp;lt;!-- input field for text --&amp;gt;&lt;br /&gt;
    &amp;lt;form id=&amp;quot;form&amp;quot; onsubmit=&amp;quot;ui.chatBar.send(); return false&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;input type=&amp;quot;text&amp;quot; name=&amp;quot;chatbar&amp;quot; id=&amp;quot;chatbar&amp;quot; style=&amp;quot;width:90%&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;input type=&amp;quot;submit&amp;quot; value=&amp;quot;Send&amp;quot;&amp;gt;&lt;br /&gt;
    &amp;lt;/form&amp;gt;&lt;br /&gt;
    &amp;lt;!-- Chat history --&amp;gt;&lt;br /&gt;
    &amp;lt;div id=&amp;quot;chat&amp;quot; style=&amp;quot;height:200px&amp;quot;&amp;gt;&lt;br /&gt;
        &amp;lt;noscript&amp;gt;JavaScript is required by the Web Client.&amp;lt;/noscript&amp;gt;&lt;br /&gt;
    &amp;lt;/div&amp;gt;&lt;br /&gt;
&amp;lt;/body&amp;gt;&amp;lt;/html&amp;gt;&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Implementing the client Framework ==&lt;br /&gt;
&lt;br /&gt;
作为第一步，我们想使用 marauroa.clientFramework 连接到服务器。 请注意，我们对主机和端口使用“null”，这意味着我们连接到下载客户端的同一服务器。 连接到服务器可能需要一两秒钟，因此我们会向用户提供一些反馈。&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
function startClient() {&lt;br /&gt;
	ui.chatLog.addLine(&amp;quot;client&amp;quot;, &amp;quot;Client loaded. Connecting...&amp;quot;);&lt;br /&gt;
	var body = document.getElementById(&amp;quot;body&amp;quot;)&lt;br /&gt;
	body.style.cursor = &amp;quot;wait&amp;quot;;&lt;br /&gt;
	marauroa.clientFramework.connect(null, null);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
现在我们能够连接到服务器，我们想要接收和处理事件。 用 Java 的话来说，我们实现了 ClientFramework 的一个子类。 然而，在 JavaScript 中，我们可以重新定义我们感兴趣的方法:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
&lt;br /&gt;
	/** display a message to the chat window on disconnect. */&lt;br /&gt;
	marauroa.clientFramework.onDisconnect = function(reason, error){&lt;br /&gt;
		ui.chatLog.addLine(&amp;quot;error&amp;quot;, &amp;quot;Disconnected: &amp;quot; + error);&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
	/** on failed login, open a message box and disable the user interface */&lt;br /&gt;
	marauroa.clientFramework.onLoginFailed = function(reason, text) {&lt;br /&gt;
		alert(&amp;quot;Login failed. Please check your password and try again.&amp;quot;);&lt;br /&gt;
		marauroa.clientFramework.close();&lt;br /&gt;
		document.getElementById(&amp;quot;chatbar&amp;quot;).disabled = true;&lt;br /&gt;
		document.getElementById(&amp;quot;chat&amp;quot;).style.backgroundColor = &amp;quot;#AAA&amp;quot;;&lt;br /&gt;
	}&lt;br /&gt;
&lt;br /&gt;
        /** Automatically pick the first character associated with this account and enable the chat controls */&lt;br /&gt;
	marauroa.clientFramework.onAvailableCharacterDetails = function(characters) {&lt;br /&gt;
		marauroa.clientFramework.chooseCharacter(marauroa.util.first(characters).a.name);&lt;br /&gt;
&lt;br /&gt;
		var body = document.getElementById(&amp;quot;body&amp;quot;)&lt;br /&gt;
		body.style.cursor = &amp;quot;auto&amp;quot;;&lt;br /&gt;
		ui.chatLog.addLine(&amp;quot;client&amp;quot;, &amp;quot;Ready...&amp;quot;);&lt;br /&gt;
	}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Handling actions ==&lt;br /&gt;
&lt;br /&gt;
到目前为止，我们的客户端能够连接到基于 Marauroa 的服务器并显示一些基本反馈。 有一个聊天消息的输入字段。 现在我们要将这些消息发送到服务器。&lt;br /&gt;
&lt;br /&gt;
为了保持我们的代码结构良好，我们创建了一个名为“ui”的对象和一个名为“chatbar”的子对象。 对于 Java 开发人员：虽然 Java 是一种基于类的编程语言，但 JavaScript 是基于原型的。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
/** user interface package */&lt;br /&gt;
ui = {&lt;br /&gt;
        /** methods for the chat input box */&lt;br /&gt;
	chatBar: {&lt;br /&gt;
                /** clear the chat window */&lt;br /&gt;
		clear: function() {&lt;br /&gt;
			document.getElementById(&amp;#039;chatbar&amp;#039;).value = &amp;#039;&amp;#039;;&lt;br /&gt;
		},&lt;br /&gt;
&lt;br /&gt;
                /** send a message to the server */&lt;br /&gt;
		send: function() {&lt;br /&gt;
			var val = document.getElementById(&amp;#039;chatbar&amp;#039;).value;&lt;br /&gt;
&lt;br /&gt;
			// create an RPAction object of type &amp;quot;chat&amp;quot; with the message.&lt;br /&gt;
			var action = {&lt;br /&gt;
				&amp;quot;type&amp;quot;: &amp;quot;chat&amp;quot;,&lt;br /&gt;
				&amp;quot;text&amp;quot;: val;&lt;br /&gt;
			};&lt;br /&gt;
&lt;br /&gt;
			// send the message to the server and clear the input field&lt;br /&gt;
			marauroa.clientFramework.sendAction(action);&lt;br /&gt;
			this.clear();&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Handling perceptions ==&lt;br /&gt;
&lt;br /&gt;
在我们将所有内容放在一起之前，还剩下一件：我们需要听取服务器发送的感知并将聊天显示在我们的日志窗口中。&lt;br /&gt;
&lt;br /&gt;
在本教程中，聊天消息不仅仅是事件，还包括对象。 这允许我们将它们存储到数据库中，并允许后期客户端读取历史记录。 通常我们会使用 marauroa.rpobjectFactory 来创建具有正确原型（“Player”、“Item”、“Creature”...）的对象，因为它们是从服务器传输过来的. You can have a look at this [http://arianne.cvs.sf.net/viewvc/arianne/stendhal/srcjs/stendhal-entities.js?revision=1.14&amp;amp;view=markup file of the experimental Stendhal HTML5 client], to learn how the rpobjectFactory is used.&lt;br /&gt;
&lt;br /&gt;
对于这个非常简单的聊天客户端，我们只对聊天对象感兴趣。 因此，我们现在跳过这一步，直接处理新对象的感知事件:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;javascript&amp;quot;&amp;gt;&lt;br /&gt;
marauroa.perceptionListener.onAdded = function(object) {&lt;br /&gt;
	if (object.has(&amp;quot;text&amp;quot;)) {&lt;br /&gt;
		ui.chatLog.addLine(&amp;quot;text&amp;quot;, object.get(&amp;quot;from&amp;quot;) + &amp;quot;* : &amp;quot; + object.get(&amp;quot;text&amp;quot;));&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
ui: {&lt;br /&gt;
	chatLog: {&lt;br /&gt;
		addLine: function(type, msg) {&lt;br /&gt;
			var e = document.createElement(&amp;#039;p&amp;#039;);&lt;br /&gt;
			e.className = &amp;quot;log&amp;quot; + ui.escapeHTML(type);&lt;br /&gt;
			e.innerHTML = ui.escapeHTML(msg);&lt;br /&gt;
			document.getElementById(&amp;#039;chat&amp;#039;).appendChild(e);&lt;br /&gt;
			document.getElementById(&amp;#039;chat&amp;#039;).scrollTop = 1000000;&lt;br /&gt;
		},&lt;br /&gt;
&lt;br /&gt;
		clear: function() {&lt;br /&gt;
			document.getElementById(&amp;quot;chat&amp;quot;).innerHTML = &amp;quot;&amp;quot;;&lt;br /&gt;
		}&lt;br /&gt;
&lt;br /&gt;
		/** HTML code escaping */&lt;br /&gt;
		escapeHTML: function(msg){&lt;br /&gt;
			return msg.replace(/&amp;lt;/g, &amp;#039;&amp;amp;lt;&amp;#039;).replace(/&amp;gt;/g, &amp;#039;&amp;amp;gt;&amp;#039;).replace(/&amp;quot;/g, &amp;#039;&amp;amp;quot;&amp;#039;).replace(&amp;quot;\n&amp;quot;, &amp;quot;&amp;lt;br&amp;gt;&amp;quot;);&lt;br /&gt;
		}&lt;br /&gt;
	}&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
注意：将所有内容放在一起时，您需要将上一节中的“ui”包与此处定义的包合并。&lt;br /&gt;
&lt;br /&gt;
== Deployment ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Sorry, this part is still a bit messy. We promise to make it as easy as the traditional Marauroa version in the future.&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Instead of the official download version of marauroa, you need to download the current development version directly from git.&lt;br /&gt;
&lt;br /&gt;
Check out Marauroa, Branch &amp;#039;&amp;#039;perception_json&amp;#039;&amp;#039; into a new project:&lt;br /&gt;
* File -&amp;gt; Import&lt;br /&gt;
* Git -&amp;gt; Projects from Git&lt;br /&gt;
* Clone URI: git://arianne.git.sourceforge.net/gitroot/arianne/marauroa&lt;br /&gt;
* Make sure that both &amp;quot;src&amp;quot; and &amp;quot;srcexternal&amp;quot; are marked as source code folders.&lt;br /&gt;
&lt;br /&gt;
Follow the instructions from the previous pages to setup your Marauroa server, with these little changes:&lt;br /&gt;
* Add all the additional libraries to the classpath.&lt;br /&gt;
* Create a Run Configuration, that launches &amp;#039;&amp;#039;marauroa.server.net.web.WebSocketServer&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
Create or reuse your server.ini&lt;br /&gt;
* Edit server.ini to add these lines, replacing &amp;quot;accountname&amp;quot; with the name of your account for testing:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;ini&amp;quot;&amp;gt;&lt;br /&gt;
http_port=8080&lt;br /&gt;
debug_fake_web_username=accountname&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
* Launch the WebSocketServer run configuration&lt;br /&gt;
* Visit &amp;lt;nowiki&amp;gt;http://localhost:8080/chat.html&amp;lt;/nowiki&amp;gt;&lt;br /&gt;
* Best to do this using firefox, with firebug extension installed (if you will be developing or studying the client)&lt;br /&gt;
&lt;br /&gt;
== Next Steps ==&lt;br /&gt;
&lt;br /&gt;
Congratulations, you completed this tutorial. The final sections will list some ideas for [[Marauroa Chat Tutorial/Next Steps|further steps to improve]].&lt;br /&gt;
&lt;br /&gt;
[[Category:Marauroa]]&lt;br /&gt;
{{#breadcrumbs: [[Marauroa]] | [[Navigation for Marauroa Users|Using]] | [[Marauroa Chat Tutorial|Tutorial]] | [[Marauroa Chat Tutorial/Swing Client|Swing Client]]}}&lt;/div&gt;</summary>
		<author><name>183.246.21.52</name></author>
	</entry>
</feed>