Difference between revisions of "Commands"
(→Server Side Command API) |
(→Console Fired Commands) |
||
Line 194: | Line 194: | ||
==Console Fired Commands== | ==Console Fired Commands== | ||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | |||
+ | <syntaxhighlight lang="javascript" line start="100" highlight="5" enclose="div"> | ||
+ | |||
+ | </syntaxhighlight> | ||
==GM Only Commands== | ==GM Only Commands== |
Revision as of 18:01, 13 October 2013
Contents |
Introduction
In Lugdunon, commands are what drive the game state. Any action that occurs should result in a command being generated to be handled in the update loop. Commands are also the method in which the client and server communicate. Commands are specific to a given server, and are loaded from the classpath based on their inclusion in the WORLD/etc/commands.json file.
Commands are referenced in code by their unique command id. Programmatically, commands are referenced by a short int opcode, meaning that commands are limited to at most 215-1 (32767). With the exception of of net.lugdunon.command.core.ErrorCommand, net.lugdunon.command.core.GetServerStatusCommand, and net.lugdunon.command.core.ConnectToServerCommand the opcode for a command is dynamically assigned at server start and should never be relied upon to remain the same value across server instances.
A command exists as a single instance, loaded and initialized upon server start for server-side commands and upon client connect for client-side commands. Commands are referenced in code via their command id, a unique string that identifies a specific command. How to call commands on the server and client will be examined towards the end of this article.
A quick word about DataView, EnhancedDataInput/OutputStream, and String length
All traffic that passes between the client and server via commands is packaged and unpackaged using an extended version of the default DataView on the client and extended versions of the java.io.DataInputStream and java.io.DataOutputStream on the server side. The enhancements amount to providing an analogue of the java data io functionality in the client as well as providing a method for writing UTF strings with lengths > 216-1. Listed below are the mappings of calls between the client and the server:
Client (Dataview) | Server (net.lugdunon.io.EnhancedCharacterInputStream) | |
---|---|---|
readInt8() | ⇄ | readByte() |
readUint8() | ⇄ | readUnsignedByte() |
readInt16() | ⇄ | readShort() |
readUint16() | ⇄ | readUnsignedShort() |
readInt32() | ⇄ | readInt() |
readUint32() | ⇄ | readInt() |
readFloat32() | ⇄ | readFloat() |
readFloat64() | ⇄ | readDouble() |
readBoolean() | ⇄ | readBoolean() |
readString() | ⇄ | readUTF() |
readLargeString() | ⇄ | readLargeUTF() |
Client (Dataview) | Server (net.lugdunon.io.EnhancedCharacterOutputStream) | |
---|---|---|
writeInt8() | ⇄ | writeByte() |
writeUint8() | ⇄ | writeUnsignedByte() |
writeInt16() | ⇄ | writeShort() |
writeUint16() | ⇄ | writeUnsignedShort() |
writeInt32() | ⇄ | writeInt() |
writeUint32() | ⇄ | writeInt() |
writeFloat32() | ⇄ | writeFloat() |
writeFloat64() | ⇄ | writeDouble() |
writeBoolean() | ⇄ | writeBoolean() |
writeString() | ⇄ | writeUTF() |
writeLargeString() | ⇄ | writeLargeUTF() |
One last thing to note. When determining the actual length (in bytes) of a string as it is written using the DataView.writeString() and DataView.writeLargeString() it is necessary to use the String.lengthInBytes() and String.largeLengthInBytes() functions to determine the actual length.
Client Side Command API
On the client-side, commands extend the net.lugdunon.command.core.Command javascript class. There are a few default functions that require overriding:
- /**
- * Accepts a parameter containing any data used to populate this command call.
- *
- * @param {Object} initData
- */
- net.lugdunon.command.core.Command.prototype.opInit=function(initData){};
- /**
- * Returns the length (in bytes) of the command call's data.
- *
- * @returns {Number}
- */
- net.lugdunon.command.core.Command.prototype.getCommandLength=function(){return(0);};
- /**
- * Where the command call's data is actually written to the dataView object passed in.
- *
- * @param {DataView} dataView
- */
- net.lugdunon.command.core.Command.prototype.buildCommand=function(dataView){};
- /**
- * Where a command that has come in from the server is processed. The response parameter is a DataView object for reading in the response data.
- *
- * @param {DataView} response
- */
- net.lugdunon.command.core.Command.prototype.commandReponse=function(response){};