[ADD] add constant identifiers to JSONConvert and made serverclient and client use them
This commit is contained in:
@@ -72,10 +72,10 @@ namespace Client
|
||||
Array.Copy(message, 1, payload, 0, message.Length - 1);
|
||||
switch (id)
|
||||
{
|
||||
case 0x01:
|
||||
case JSONConvert.LOGIN:
|
||||
// json log in username data
|
||||
break;
|
||||
case 0x02:
|
||||
case JSONConvert.MESSAGE:
|
||||
// json message data
|
||||
(string, string) combo = JSONConvert.GetUsernameAndMessage(payload);
|
||||
string textUsername = combo.Item1;
|
||||
@@ -84,11 +84,11 @@ namespace Client
|
||||
|
||||
break;
|
||||
|
||||
case 0x03:
|
||||
case JSONConvert.LOBBY:
|
||||
// lobby data
|
||||
//TODO fill lobby with the data received
|
||||
break;
|
||||
case 0x04:
|
||||
case JSONConvert.CANVAS:
|
||||
// canvas data
|
||||
break;
|
||||
default:
|
||||
|
||||
@@ -91,7 +91,7 @@ namespace Server.Models
|
||||
switch(id)
|
||||
{
|
||||
|
||||
case 0x01:
|
||||
case JSONConvert.LOGIN:
|
||||
// json log in username data
|
||||
string uName = JSONConvert.GetUsernameLogin(message);
|
||||
if (uName != null)
|
||||
@@ -102,7 +102,7 @@ namespace Server.Models
|
||||
|
||||
}
|
||||
break;
|
||||
case 0x02:
|
||||
case JSONConvert.MESSAGE:
|
||||
// json message data
|
||||
(string, string) combo = JSONConvert.GetUsernameAndMessage(payload);
|
||||
string textUsername = combo.Item1;
|
||||
@@ -111,10 +111,10 @@ namespace Server.Models
|
||||
// todo handle sending to all except this user the username and message to display in chat
|
||||
break;
|
||||
|
||||
case 0x03:
|
||||
case JSONConvert.LOBBY:
|
||||
// lobby data
|
||||
break;
|
||||
case 0x04:
|
||||
case JSONConvert.CANVAS:
|
||||
// canvas data
|
||||
// todo send canvas data to all other serverclients in lobby
|
||||
break;
|
||||
|
||||
@@ -7,6 +7,10 @@ namespace SharedClientServer
|
||||
{
|
||||
class JSONConvert
|
||||
{
|
||||
public const byte LOGIN = 0x01;
|
||||
public const byte MESSAGE = 0x02;
|
||||
public const byte LOBBY = 0x03;
|
||||
public const byte CANVAS = 0x04;
|
||||
public static (string,string) GetUsernameAndMessage(byte[] json)
|
||||
{
|
||||
string msg = Encoding.ASCII.GetString(json);
|
||||
@@ -21,6 +25,11 @@ namespace SharedClientServer
|
||||
return payload.username;
|
||||
}
|
||||
|
||||
public static byte[] GetUsernameMessage(string username)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// constructs a message that can be sent to the clients or server
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user