client stuff

This commit is contained in:
shinichi
2020-09-23 12:00:40 +02:00
parent a52f1ea7ed
commit 797fb16465
2 changed files with 134 additions and 3 deletions

58
Client/DataParser.cs Normal file
View File

@@ -0,0 +1,58 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
namespace Client
{
class DataParser
{
public static byte[] GetLoginJson(string mUsername, string mPassword)
{
dynamic json = new
{
identifier = "LOGIN",
data = new
{
username = mUsername,
password = mPassword,
}
};
return Encoding.ASCII.GetBytes(JsonConvert.SerializeObject(json));
}
public static bool getJsonIdentifier(byte[] bytes, out string identifier)
{
if (bytes.Length <= 5)
{
throw new ArgumentException("bytes to short");
}
byte messageId = bytes[4];
if (messageId == 1)
{
dynamic json = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(bytes.Skip(5).ToArray()));
identifier = json.identifier;
return true;
}
else
{
identifier = "";
return false;
}
}
public static bool isRawData(byte[] bytes)
{
if (bytes.Length <= 5)
{
throw new ArgumentException("bytes to short");
}
return bytes[5] == 0x02;
}
}
}