2024-12-14 15:17:58 +00:00
|
|
|
|
namespace lib;
|
|
|
|
|
|
|
|
|
|
public enum RequestType {
|
|
|
|
|
Register = 1,
|
|
|
|
|
ConfirmRegister = 2,
|
2024-12-17 18:41:30 +00:00
|
|
|
|
Login = 3,
|
|
|
|
|
GetMessages = 4,
|
|
|
|
|
GetUserKey = 5,
|
|
|
|
|
SendMessage = 6,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static class Request {
|
|
|
|
|
public static byte[] CreateRequest(RequestType Type, ref byte counter, byte[] data) {
|
|
|
|
|
if(data.Length > 13) {
|
|
|
|
|
throw new Exception("extra data is too long");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
byte[] msg = new byte[128];
|
|
|
|
|
msg[0] = 0; // version
|
|
|
|
|
msg[1] = (byte)Type;
|
|
|
|
|
msg[2] = counter;
|
|
|
|
|
if(counter == byte.MaxValue) {
|
|
|
|
|
counter = 0;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
counter += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// insert data 3..16
|
|
|
|
|
Array.Copy(data, 0, msg, 3, data.Length);
|
|
|
|
|
return msg;
|
|
|
|
|
}
|
2024-12-14 15:17:58 +00:00
|
|
|
|
}
|