sendMsg function
Send a message with the given message ID and message payload. Returns a boolean that specifies if the command was successful.
Implementation
bool sendMsg(int msgID, String msg) {
if (rconSck == null) {
return false;
}
// Example login data: (u__ refers to the type of unsigned integer)
// 0d00 0000 | dec0 ad0b | 0300 0000 | 3132 3300 00
// len u32 | pid u32 | cmdid u32 | payload/password u8
int payloadLen = 10 + msg.length;
Uint32List headerAs32 = Uint32List(3);
var headerBD = ByteData.view(headerAs32.buffer);
headerBD.setUint32(0, payloadLen, Endian.little);
headerBD.setUint32(4, requestID, Endian.little);
headerBD.setUint32(8, msgID, Endian.little);
Uint8List header = headerAs32.buffer.asUint8List();
Uint8List passwordAsIntList = Uint8List.fromList(msg.codeUnits);
Uint8List suffix = Uint8List(2);
var suffixBD = ByteData.view(suffix.buffer);
suffixBD.setUint8(0, 0);
suffixBD.setUint8(1, 0);
BytesBuilder bBuilder = BytesBuilder();
bBuilder.add(header);
bBuilder.add(passwordAsIntList);
bBuilder.add(suffix);
Uint8List payload = bBuilder.toBytes();
rconSck!.add(payload);
print("mc_rcon: sent payload ($payload) on socket");
return true;
}