Commands
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() |