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/hncom1.xml
8  */
9 module sul.protocol.hncom1.types;
10 
11 import std.bitmanip : write, peek;
12 static import std.conv;
13 import std.system : Endian;
14 import std.typecons : Tuple;
15 import std.uuid : UUID;
16 
17 import sul.utils.buffer;
18 import sul.utils.var;
19 
20 static if(__traits(compiles, { import sul.metadata.hncom1; })) import sul.metadata.hncom1;
21 
22 /**
23  * Internet protocol address. Could be either version 4 or 6.
24  */
25 struct Address {
26 
27 	public enum string[] FIELDS = ["bytes", "port"];
28 
29 	/**
30 	 * Bytes of the address. The length may be 4 (for ipv4 addresses) or 16 (for ipv6 addresses).
31 	 * The byte order is always big-endian (network order).
32 	 */
33 	public ubyte[] bytes;
34 
35 	/**
36 	 * Port of the address.
37 	 */
38 	public ushort port;
39 
40 	public pure nothrow @safe void encode(Buffer buffer) {
41 		with(buffer) {
42 			writeBytes(varuint.encode(cast(uint)bytes.length)); writeBytes(bytes);
43 			writeBigEndianUshort(port);
44 		}
45 	}
46 
47 	public pure nothrow @safe void decode(Buffer buffer) {
48 		with(buffer) {
49 			bytes.length=varuint.decode(_buffer, &_index); if(_buffer.length>=_index+bytes.length){ bytes=_buffer[_index.._index+bytes.length].dup; _index+=bytes.length; }
50 			port=readBigEndianUshort();
51 		}
52 	}
53 
54 	public string toString() {
55 		return "Address(bytes: " ~ std.conv.to!string(this.bytes) ~ ", port: " ~ std.conv.to!string(this.port) ~ ")";
56 	}
57 
58 }
59 
60 /**
61  * Indicates a game and informations about its accepted protocols.
62  */
63 struct Game {
64 
65 	// type
66 	public enum ubyte POCKET = 1;
67 	public enum ubyte MINECRAFT = 2;
68 	public enum ubyte CONSOLE = 3;
69 
70 	public enum string[] FIELDS = ["type", "protocols"];
71 
72 	/**
73 	 * Identifier of the game.
74 	 */
75 	public ubyte type;
76 
77 	/**
78 	 * Protocols accepted by the server for the game. They should be ordered from oldest
79 	 * to newest.
80 	 */
81 	public uint[] protocols;
82 
83 	public pure nothrow @safe void encode(Buffer buffer) {
84 		with(buffer) {
85 			writeBigEndianUbyte(type);
86 			writeBytes(varuint.encode(cast(uint)protocols.length)); foreach(cjd9bx;protocols){ writeBytes(varuint.encode(cjd9bx)); }
87 		}
88 	}
89 
90 	public pure nothrow @safe void decode(Buffer buffer) {
91 		with(buffer) {
92 			type=readBigEndianUbyte();
93 			protocols.length=varuint.decode(_buffer, &_index); foreach(ref cjd9bx;protocols){ cjd9bx=varuint.decode(_buffer, &_index); }
94 		}
95 	}
96 
97 	public string toString() {
98 		return "Game(type: " ~ std.conv.to!string(this.type) ~ ", protocols: " ~ std.conv.to!string(this.protocols) ~ ")";
99 	}
100 
101 }
102 
103 /**
104  * Indicates a game and informations about it.
105  */
106 struct GameInfo {
107 
108 	public enum string[] FIELDS = ["game", "motd", "port"];
109 
110 	/**
111 	 * Informations about the the game and the protocols used.
112 	 */
113 	public sul.protocol.hncom1.types.Game game;
114 
115 	/**
116 	 * "Message of the day" which is displayed in the game's server list. It may contain
117 	 * Minecraft formatting codes.
118 	 */
119 	public string motd;
120 
121 	/**
122 	 * Port, or main port if the server allows the connection from multiple ports, where
123 	 * the socket is listening for connections.
124 	 */
125 	public ushort port;
126 
127 	public pure nothrow @safe void encode(Buffer buffer) {
128 		with(buffer) {
129 			game.encode(bufferInstance);
130 			writeBytes(varuint.encode(cast(uint)motd.length)); writeString(motd);
131 			writeBigEndianUshort(port);
132 		}
133 	}
134 
135 	public pure nothrow @safe void decode(Buffer buffer) {
136 		with(buffer) {
137 			game.decode(bufferInstance);
138 			uint b9z=varuint.decode(_buffer, &_index); motd=readString(b9z);
139 			port=readBigEndianUshort();
140 		}
141 	}
142 
143 	public string toString() {
144 		return "GameInfo(game: " ~ std.conv.to!string(this.game) ~ ", motd: " ~ std.conv.to!string(this.motd) ~ ", port: " ~ std.conv.to!string(this.port) ~ ")";
145 	}
146 
147 }
148 
149 /**
150  * A plugin loaded on the node. It may be used by the hub to display the plugins loaded
151  * on the server in queries.
152  */
153 struct Plugin {
154 
155 	public enum string[] FIELDS = ["name", "vers"];
156 
157 	/**
158 	 * Name of the plugin.
159 	 */
160 	public string name;
161 
162 	/**
163 	 * Version of the plugin, usually in the format `major.minor[.release] [alpha|beta]`.
164 	 */
165 	public string vers;
166 
167 	public pure nothrow @safe void encode(Buffer buffer) {
168 		with(buffer) {
169 			writeBytes(varuint.encode(cast(uint)name.length)); writeString(name);
170 			writeBytes(varuint.encode(cast(uint)vers.length)); writeString(vers);
171 		}
172 	}
173 
174 	public pure nothrow @safe void decode(Buffer buffer) {
175 		with(buffer) {
176 			uint bfz=varuint.decode(_buffer, &_index); name=readString(bfz);
177 			uint dvc=varuint.decode(_buffer, &_index); vers=readString(dvc);
178 		}
179 	}
180 
181 	public string toString() {
182 		return "Plugin(name: " ~ std.conv.to!string(this.name) ~ ", vers: " ~ std.conv.to!string(this.vers) ~ ")";
183 	}
184 
185 }
186 
187 /**
188  * Player's skin that will be sent to Minecraft: Pocket Edition clients.
189  * If the server only allows Minecraft players this type's fields should be empty.
190  */
191 struct Skin {
192 
193 	public enum string[] FIELDS = ["name", "data"];
194 
195 	/**
196 	 * Name of the skin.
197 	 */
198 	public string name;
199 
200 	/**
201 	 * RGBA map of the skin colours. Length should be, if the skin is not empty, 8192 (64x32)
202 	 * or 16384 (64x64) bytes.
203 	 */
204 	public ubyte[] data;
205 
206 	public pure nothrow @safe void encode(Buffer buffer) {
207 		with(buffer) {
208 			writeBytes(varuint.encode(cast(uint)name.length)); writeString(name);
209 			writeBytes(varuint.encode(cast(uint)data.length)); writeBytes(data);
210 		}
211 	}
212 
213 	public pure nothrow @safe void decode(Buffer buffer) {
214 		with(buffer) {
215 			uint bfz=varuint.decode(_buffer, &_index); name=readString(bfz);
216 			data.length=varuint.decode(_buffer, &_index); if(_buffer.length>=_index+data.length){ data=_buffer[_index.._index+data.length].dup; _index+=data.length; }
217 		}
218 	}
219 
220 	public string toString() {
221 		return "Skin(name: " ~ std.conv.to!string(this.name) ~ ", data: " ~ std.conv.to!string(this.data) ~ ")";
222 	}
223 
224 }
225