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