1 /*
2  * This file was automatically generated by sel-utils and
3  * released under the MIT License.
4  * 
5  * License: https://github.com/sel-project/sel-utils/blob/master/LICENSE
6  * Repository: https://github.com/sel-project/sel-utils
7  * Generated from https://github.com/sel-project/sel-utils/blob/master/xml/protocol/externalconsole2.xml
8  */
9 /**
10  * Packets regarding the server's console and commands.
11  */
12 module sul.protocol.externalconsole2.connected;
13 
14 import std.bitmanip : write, peek;
15 static import std.conv;
16 import std.system : Endian;
17 import std.typetuple : TypeTuple;
18 import std.typecons : Tuple;
19 import std.uuid : UUID;
20 
21 import sul.utils.buffer;
22 import sul.utils.var;
23 
24 static import sul.protocol.externalconsole2.types;
25 
26 static if(__traits(compiles, { import sul.metadata.externalconsole2; })) import sul.metadata.externalconsole2;
27 
28 alias Packets = TypeTuple!(ConsoleMessage, Command, PermissionDenied);
29 
30 /**
31  * Logs a message from the server's console. It may be the output of a command, a debug
32  * message or any other message that the server retains able to be seen by the External
33  * Console.
34  */
35 class ConsoleMessage : Buffer {
36 
37 	public enum ubyte ID = 4;
38 
39 	public enum bool CLIENTBOUND = true;
40 	public enum bool SERVERBOUND = false;
41 
42 	public enum string[] FIELDS = ["node", "timestamp", "logger", "message", "commandId"];
43 
44 	/**
45 	 * Name of the node that created the log or an empty string if the log was created
46 	 * by the hub or by a server that isn't based on the hub-node layout.
47 	 */
48 	public string node;
49 
50 	/**
51 	 * Unix timestamp in milliseconds that indicates the exact time when the log was generated
52 	 * by the server.
53 	 * The logs may not arrive in order when the server uses the hub-node layout or some
54 	 * other kind of proxy because the logs created by the nodes have an additional latency
55 	 * (the one between the hub, or proxy, and the node).
56 	 */
57 	public ulong timestamp;
58 
59 	/**
60 	 * Name of the logger. It may be the world name if the log was generated by a world's
61 	 * message (like a broadcast or a chat message), the name of plugin (for example `plugin\test`)
62 	 * or the name of the package/module/class that generated the log (like `math.vector`
63 	 * or `event.world.player`).
64 	 */
65 	public string logger;
66 
67 	/**
68 	 * The logged message. It may contain Minecraft's formatting codes which should be
69 	 * translated into appropriate colours and formatting (bold, italic and strikethrough)
70 	 * by the client implementation of the external console.
71 	 */
72 	public string message;
73 
74 	/**
75 	 * Identifier given in Command.commandId if the log was generated by a command sent
76 	 * by the external console or -1 if the log was not related to a command sent from
77 	 * the external console.
78 	 */
79 	public int commandId;
80 
81 	public pure nothrow @safe @nogc this() {}
82 
83 	public pure nothrow @safe @nogc this(string node, ulong timestamp=ulong.init, string logger=string.init, string message=string.init, int commandId=int.init) {
84 		this.node = node;
85 		this.timestamp = timestamp;
86 		this.logger = logger;
87 		this.message = message;
88 		this.commandId = commandId;
89 	}
90 
91 	public pure nothrow @safe ubyte[] encode(bool writeId=true)() {
92 		_buffer.length = 0;
93 		static if(writeId){ writeBigEndianUbyte(ID); }
94 		writeBigEndianUshort(cast(ushort)node.length); writeString(node);
95 		writeBigEndianUlong(timestamp);
96 		writeBigEndianUshort(cast(ushort)logger.length); writeString(logger);
97 		writeBigEndianUshort(cast(ushort)message.length); writeString(message);
98 		writeBigEndianInt(commandId);
99 		return _buffer;
100 	}
101 
102 	public pure nothrow @safe void decode(bool readId=true)() {
103 		static if(readId){ ubyte _id; _id=readBigEndianUbyte(); }
104 		ushort b9z=readBigEndianUshort(); node=readString(b9z);
105 		timestamp=readBigEndianUlong();
106 		ushort b9zv=readBigEndianUshort(); logger=readString(b9zv);
107 		ushort bvcfz=readBigEndianUshort(); message=readString(bvcfz);
108 		commandId=readBigEndianInt();
109 	}
110 
111 	public static pure nothrow @safe ConsoleMessage fromBuffer(bool readId=true)(ubyte[] buffer) {
112 		ConsoleMessage ret = new ConsoleMessage();
113 		ret._buffer = buffer;
114 		ret.decode!readId();
115 		return ret;
116 	}
117 
118 	public override string toString() {
119 		return "ConsoleMessage(node: " ~ std.conv.to!string(this.node) ~ ", timestamp: " ~ std.conv.to!string(this.timestamp) ~ ", logger: " ~ std.conv.to!string(this.logger) ~ ", message: " ~ std.conv.to!string(this.message) ~ ", commandId: " ~ std.conv.to!string(this.commandId) ~ ")";
120 	}
121 
122 }
123 
124 /**
125  * Executes a command remotely if the server allows it. If not a Permission Denied
126  * is sent back. A good implementation of the external console client should never
127  * send this packet if remoteCommands field in Welcome.Accepted is not true.
128  */
129 class Command : Buffer {
130 
131 	public enum ubyte ID = 5;
132 
133 	public enum bool CLIENTBOUND = false;
134 	public enum bool SERVERBOUND = true;
135 
136 	public enum string[] FIELDS = ["command", "commandId"];
137 
138 	/**
139 	 * Command to execute on the server.
140 	 */
141 	public string command;
142 
143 	/**
144 	 * Identifier for the command that will be sent in ConsoleMessage.commandId if the
145 	 * command generates an output.
146 	 */
147 	public uint commandId;
148 
149 	public pure nothrow @safe @nogc this() {}
150 
151 	public pure nothrow @safe @nogc this(string command, uint commandId=uint.init) {
152 		this.command = command;
153 		this.commandId = commandId;
154 	}
155 
156 	public pure nothrow @safe ubyte[] encode(bool writeId=true)() {
157 		_buffer.length = 0;
158 		static if(writeId){ writeBigEndianUbyte(ID); }
159 		writeBigEndianUshort(cast(ushort)command.length); writeString(command);
160 		writeBigEndianUint(commandId);
161 		return _buffer;
162 	}
163 
164 	public pure nothrow @safe void decode(bool readId=true)() {
165 		static if(readId){ ubyte _id; _id=readBigEndianUbyte(); }
166 		ushort y9bfz=readBigEndianUshort(); command=readString(y9bfz);
167 		commandId=readBigEndianUint();
168 	}
169 
170 	public static pure nothrow @safe Command fromBuffer(bool readId=true)(ubyte[] buffer) {
171 		Command ret = new Command();
172 		ret._buffer = buffer;
173 		ret.decode!readId();
174 		return ret;
175 	}
176 
177 	public override string toString() {
178 		return "Command(command: " ~ std.conv.to!string(this.command) ~ ", commandId: " ~ std.conv.to!string(this.commandId) ~ ")";
179 	}
180 
181 }
182 
183 /**
184  * Bodyless packet only sent in response to Command when the server doesn't allow the
185  * execution of remote commands through the external console. A good implementation
186  * of the external console client should never receive this packet avoiding the use
187  * of the Command packet when the remoteCommands field is false.
188  */
189 class PermissionDenied : Buffer {
190 
191 	public enum ubyte ID = 6;
192 
193 	public enum bool CLIENTBOUND = true;
194 	public enum bool SERVERBOUND = false;
195 
196 	public enum string[] FIELDS = [];
197 
198 	public pure nothrow @safe ubyte[] encode(bool writeId=true)() {
199 		_buffer.length = 0;
200 		static if(writeId){ writeBigEndianUbyte(ID); }
201 		return _buffer;
202 	}
203 
204 	public pure nothrow @safe void decode(bool readId=true)() {
205 		static if(readId){ ubyte _id; _id=readBigEndianUbyte(); }
206 	}
207 
208 	public static pure nothrow @safe PermissionDenied fromBuffer(bool readId=true)(ubyte[] buffer) {
209 		PermissionDenied ret = new PermissionDenied();
210 		ret._buffer = buffer;
211 		ret.decode!readId();
212 		return ret;
213 	}
214 
215 	public override string toString() {
216 		return "PermissionDenied()";
217 	}
218 
219 }
220