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/externalconsole1.xml
8  */
9 /**
10  * Packets regarding the server's console and commands.
11  */
12 module sul.protocol.externalconsole1.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.externalconsole1.types;
25 
26 static if(__traits(compiles, { import sul.metadata.externalconsole1; })) import sul.metadata.externalconsole1;
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"];
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 	public pure nothrow @safe @nogc this() {}
75 
76 	public pure nothrow @safe @nogc this(string node, ulong timestamp=ulong.init, string logger=string.init, string message=string.init) {
77 		this.node = node;
78 		this.timestamp = timestamp;
79 		this.logger = logger;
80 		this.message = message;
81 	}
82 
83 	public pure nothrow @safe ubyte[] encode(bool writeId=true)() {
84 		_buffer.length = 0;
85 		static if(writeId){ writeBigEndianUbyte(ID); }
86 		writeBigEndianUshort(cast(ushort)node.length); writeString(node);
87 		writeBigEndianUlong(timestamp);
88 		writeBigEndianUshort(cast(ushort)logger.length); writeString(logger);
89 		writeBigEndianUshort(cast(ushort)message.length); writeString(message);
90 		return _buffer;
91 	}
92 
93 	public pure nothrow @safe void decode(bool readId=true)() {
94 		static if(readId){ ubyte _id; _id=readBigEndianUbyte(); }
95 		ushort b9z=readBigEndianUshort(); node=readString(b9z);
96 		timestamp=readBigEndianUlong();
97 		ushort b9zv=readBigEndianUshort(); logger=readString(b9zv);
98 		ushort bvcfz=readBigEndianUshort(); message=readString(bvcfz);
99 	}
100 
101 	public static pure nothrow @safe ConsoleMessage fromBuffer(bool readId=true)(ubyte[] buffer) {
102 		ConsoleMessage ret = new ConsoleMessage();
103 		ret._buffer = buffer;
104 		ret.decode!readId();
105 		return ret;
106 	}
107 
108 	public override string toString() {
109 		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) ~ ")";
110 	}
111 
112 }
113 
114 /**
115  * Executes a command remotely if the server allows it. If not a Permission Denied
116  * is sent back. A good implementation of the external console client should never
117  * send this packet if remoteCommands field in Welcome.Accepted is not true.
118  */
119 class Command : Buffer {
120 
121 	public enum ubyte ID = 5;
122 
123 	public enum bool CLIENTBOUND = false;
124 	public enum bool SERVERBOUND = true;
125 
126 	public enum string[] FIELDS = ["command"];
127 
128 	/**
129 	 * Command to execute on the server.
130 	 */
131 	public string command;
132 
133 	public pure nothrow @safe @nogc this() {}
134 
135 	public pure nothrow @safe @nogc this(string command) {
136 		this.command = command;
137 	}
138 
139 	public pure nothrow @safe ubyte[] encode(bool writeId=true)() {
140 		_buffer.length = 0;
141 		static if(writeId){ writeBigEndianUbyte(ID); }
142 		writeBigEndianUshort(cast(ushort)command.length); writeString(command);
143 		return _buffer;
144 	}
145 
146 	public pure nothrow @safe void decode(bool readId=true)() {
147 		static if(readId){ ubyte _id; _id=readBigEndianUbyte(); }
148 		ushort y9bfz=readBigEndianUshort(); command=readString(y9bfz);
149 	}
150 
151 	public static pure nothrow @safe Command fromBuffer(bool readId=true)(ubyte[] buffer) {
152 		Command ret = new Command();
153 		ret._buffer = buffer;
154 		ret.decode!readId();
155 		return ret;
156 	}
157 
158 	public override string toString() {
159 		return "Command(command: " ~ std.conv.to!string(this.command) ~ ")";
160 	}
161 
162 }
163 
164 /**
165  * Bodyless packet only sent in response to Command when the server doesn't allow the
166  * execution of remote commands through the external console. A good implementation
167  * of the external console client should never receive this packet avoiding the use
168  * of the Command packet when the remoteCommands field is false.
169  */
170 class PermissionDenied : Buffer {
171 
172 	public enum ubyte ID = 6;
173 
174 	public enum bool CLIENTBOUND = true;
175 	public enum bool SERVERBOUND = false;
176 
177 	public enum string[] FIELDS = [];
178 
179 	public pure nothrow @safe ubyte[] encode(bool writeId=true)() {
180 		_buffer.length = 0;
181 		static if(writeId){ writeBigEndianUbyte(ID); }
182 		return _buffer;
183 	}
184 
185 	public pure nothrow @safe void decode(bool readId=true)() {
186 		static if(readId){ ubyte _id; _id=readBigEndianUbyte(); }
187 	}
188 
189 	public static pure nothrow @safe PermissionDenied fromBuffer(bool readId=true)(ubyte[] buffer) {
190 		PermissionDenied ret = new PermissionDenied();
191 		ret._buffer = buffer;
192 		ret.decode!readId();
193 		return ret;
194 	}
195 
196 	public override string toString() {
197 		return "PermissionDenied()";
198 	}
199 
200 }
201