Difference between revisions of "Commands"

From LugdunonWiki
Jump to: navigation, search
(Console Fired Commands)
(Invoking Commands on the Client)
Line 212: Line 212:
  
 
==Invoking Commands on the Client==
 
==Invoking Commands on the Client==
 +
 +
 +
 +
 +
 +
 +
 +
 +
<syntaxhighlight lang="javascript" line start="100" highlight="5" enclose="div">
 +
 +
</syntaxhighlight>

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:


  1. /**
  2.  * Accepts a parameter containing any data used to populate this command call.
  3.  *
  4.  * @param {Object} initData
  5.  */
  6. net.lugdunon.command.core.Command.prototype.opInit=function(initData){};
  7.  
  8. /**
  9.  * Returns the length (in bytes) of the command call's data.
  10.  *
  11.  * @returns {Number}
  12.  */
  13. net.lugdunon.command.core.Command.prototype.getCommandLength=function(){return(0);};
  14.  
  15. /**
  16.  * Where the command call's data is actually written to the dataView object passed in.
  17.  *
  18.  * @param {DataView} dataView
  19.  */
  20. net.lugdunon.command.core.Command.prototype.buildCommand=function(dataView){};
  21.  
  22. /**
  23.  * 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.
  24.  *
  25.  * @param {DataView} response
  26.  */
  27. net.lugdunon.command.core.Command.prototype.commandReponse=function(response){};

Server Side Command API

  1.  

Console Fired Commands

  1.  

GM Only Commands

Server Invoked Commands

Invoking Commands on the Client

  1.