编辑“︁
NetworkDesign
”︁(章节)
跳转到导航
跳转到搜索
警告:
您没有登录。如果您进行任何编辑,您的IP地址会公开展示。如果您
登录
或
创建账号
,您的编辑会以您的用户名署名,此外还有其他益处。
反垃圾检查。
不要
加入这个!
==Messages== Marauroa使用消息在客户端和服务器之间进行通信。 从客户端发送到服务器的消息以C2S为前缀,从服务器发送到客户端的消息以S2C为前缀. 每个消息都在包marauroa.common.net.message中的Java类中实现。 您可以在 [http://stendhalgame.org/jenkins/job/marauroa_HEAD/javadoc/marauroa/common/net/message/package-summary.html javadoc] 中查找有关每条消息的详细信息. 如果要将Marauroa移植到另一种编程语言,则需要知道如何精确地序列化消息. 最简单的学习方法是查看 [http://arianne.cvs.sf.net/viewvc/arianne/marauroa/src/marauroa/common/net/message source code] 中的 readObject() 和 writeObject() 方法. 游戏有不同的客户端状态:已连接,已登录,游戏中,已退出。 不同状态下的有效消息也不同: === 已连接状态 === [[Image:messages-connected.png|thumb|Messages used to securely login.]] 由于安全性要求,登录过程有点复杂。 不要害怕,只要遵循以下的步骤即可. 一旦建立了TCP连接,客户端就会使用以下命令向服务器请求RSA公钥 [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageC2SLoginRequestKey.java C2SLoginRequestKey]. 服务器检查每个消息中隐式包含的协议版本. 如果兼容,它会回复一个 [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageS2CLoginSendKey.java S2CLoginSendKey] 包含 RSA 公钥. 它由两个字节数组组成: 第一个包含 'n' 的值, 第二个包含 'e' 的值. 客户端计算 nonce (随机数) 并将其哈希值作为字节数组发送到服务器 [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageC2SLoginSendPromise.java C2SLoginPromise] . 服务器会记住客户端的随机数,并在 [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageS2CLoginSendNonce.java S2CLoginSendNonce] 回复服务器的nonce. 差不多可以了: 客户端现在拥有了实际发送消息所需的所有信息。 [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageC2SLoginSendNonceNameAndPassword.java C2SLoginSendNonceNameAndPassword]: Its nonce, the username and the value rsaCrypt(xor(xor(client nonce, server nonce), password)). The first field is a bytes array containing the client nonce, the second one a string containing the username and the third one a byte array containing the encrypted password. On reception, the server checks that the hash he received at first is the hash of the nonce he just received. It then decodes the password field, and having the value of the client nonce and its nonce, it gets the value of the password. The [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageS2CLoginNACK.java S2CLoginNACK] message is sent from the server to the client to tell the client that its login request was rejected because the username or password is wrong, the account was banned or the server is full. The included result object will tell which of the cases prevented the login. If the username/password combination, however, is correct then the Server must send a [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageS2CLoginACK.java S2CLoginACK] message to tell the client that the message has been correctly processed. It contains information about the last login, so that the user is able to recognize unauthorized usage of his account. The client state is changed to "logged in" in this case. {{br}} === State logged in === [[Image:messages-loggedin.png|thumb|Selecting a character and transmitting world meta data.]] The logging in stuff was complicated. But luckily things are getting much easier now. After the login completed successfully the server sends a [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageS2CServerInfo.java S2CServerInfo] message. It tells the client about what kind of server is running, and details on how to contact the server administrator (e.g. their email address). The message is composed of a List of strings of the form "attribute=value". In addition this message also contains the list of defined RPClasses. Directly afterwards a [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageS2CCharacterList.java S2CCharacterList] message is sent from the server to the client. It offers a choice of character to play with. This feature models the behavior of having several characters associated with a single account. Each character name must be unique at server level, and it is assigned when the character is created. Now the client picks one of the offered characters. Games that do not support multiple characters can pick the one that matches the account name. The choice is transmitted to the server using a [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageC2SChooseCharacter.java C2SChooseCharacter] message. The name of the character must be one of the names listed in the character list. The server will check the selected character and reply for a [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageS2CChooseCharacterNACK.java S2CChooseCharacterNACK] if the choice was invalid. This implies that the client should send another C2SChooseCharacter message. If the selection, however, was successful, a [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageS2CChooseCharacterACK.java ChooseCharacterACK] message is sent and the client state changed to "in game". {{br}} === 游戏中 === [[Image:messages-game.png|thumb|Messages sent while the game is active.]] ==== 常规消息 ==== The [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageS2CPerception.java S2CPerception] message is a message sent from the server to the client to notify the client about changes to the objects that exist near it. The message is based on the idea explained in the [[RolePlayingDesign#Perceptions|Delta Perception]] document. The message is composed of: * A type that can be DELTA or TOTAL * A string indicating the name of the zone the perception is related to. * A time stamp value that will be just one unit bigger than the previous perception * A List of RPObject that contains added object * A List of RPObject that contains modified added object attributes * A List of RPObject that contains modified deleted object attributes * A List of RPObject that contains deleted object * A RPObject that describes the things the rest of players don't see about OUR own object. Read the Delta perception algorithm to understand what it is for. The client sends [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageC2SKeepAlive.java C2SKeepAlive] messages regularly. If there has been no keep alive message for some time, the server will timeout the client. ==== 静态内容传输 ==== Perceptions are about dynamic content. But most games have some static data, too. Like maps, tilesets, sounds. The RPManager keeps track of situation in which the client might need some of this static data. A common case is the movement of the client from one zone to another. If the RPManager detects such a situation, it will offer the new content to the client using a [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageS2CTransferREQ.java S2CTransferREQ] message. The message is composed of an array of [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/TransferContent.java TransferContent] objects containing the name of each resource, its timestamp (or checksum) and if the resource is cacheable or not. The clients replies with a [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageC2STransferACK.java C2STransferACK] acknowledging the offer. The message is composed of an array of TransferContent objects containing all the name of each resource and a flag indicating ack or not. Note: The C2STransferACK message is always sent, even if all flags indicate that no transfer should take place. If the clients has acknowledged the need for content to be transfer, the server sends a [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageS2CTransfer.java S2CTransfer]. The message contains a again an an array of TransferContent objects. This time, however, the actual data is included as well. ==== 动作 ==== Actions are commands sent from the client to the server using a [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageC2SAction.java C2SAction] message. Example for commands are "move to the right", "look at that object", "attack that rat". It is up to the server to decide whether to execute the action or reject it. {{br}} === 退出登录 === [[Image:messages-logout.png|thumb|The client sends a logout request and the server accepts or denies it.]] If the player is in some kind of combat it is often desirable to prevent him from saving his live by logging out. Therefore the client sends a logout request to the server and the game server can decide whether to accept or reject it. Of course the user can close the client window or force a disconnect of his Internet connection. But in these cases he will simple stay in a game unattended until the timeout anyway. The clients indicates that it wants to finish the session by sending a [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageC2SLogout.java C2SLogout]. The server can reply with a [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageS2CLogoutNACK.java S2CLogoutNACK] to reject the logout request. Or it confirms the request with a [https://sourceforge.net/p/arianne/marauroa/ci/master/tree/src/marauroa/common/net/message/MessageS2CLogoutACK.java S2CLogoutACK]. In this case the client state is changed to logged out. {{br}}
摘要:
请注意,所有对gamedev的贡献均可能会被其他贡献者编辑、修改或删除。如果您不希望您的文字作品被随意编辑,请不要在此提交。
您同时也向我们承诺,您提交的内容为您自己所创作,或是复制自公共领域或类似自由来源(详情请见
Gamedev:著作权
)。
未经许可,请勿提交受著作权保护的作品!
取消
编辑帮助
(在新窗口中打开)
导航菜单
个人工具
未登录
讨论
贡献
创建账号
登录
命名空间
页面
讨论
不转换
不转换
简体
繁體
大陆简体
香港繁體
澳門繁體
大马简体
新加坡简体
臺灣正體
查看
阅读
编辑
查看历史
更多
搜索
导航
首页
最近更改
随机页面
MediaWiki帮助
工具
链入页面
相关更改
特殊页面
页面信息