[AD
D] added lobby add methods
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Collections.Generic;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Net.Sockets;
|
using System.Net.Sockets;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using static SharedClientServer.JSONConvert;
|
||||||
|
|
||||||
namespace Server.Models
|
namespace Server.Models
|
||||||
{
|
{
|
||||||
@@ -121,6 +122,7 @@ namespace Server.Models
|
|||||||
|
|
||||||
case JSONConvert.LOBBY:
|
case JSONConvert.LOBBY:
|
||||||
// lobby data
|
// lobby data
|
||||||
|
LobbyIdentifier l = JSONConvert.GetLobbyIdentifier(payload);
|
||||||
break;
|
break;
|
||||||
case JSONConvert.CANVAS:
|
case JSONConvert.CANVAS:
|
||||||
// canvas data
|
// canvas data
|
||||||
|
|||||||
@@ -14,11 +14,12 @@ namespace SharedClientServer
|
|||||||
public const byte LOBBY = 0x03;
|
public const byte LOBBY = 0x03;
|
||||||
public const byte CANVAS = 0x04;
|
public const byte CANVAS = 0x04;
|
||||||
|
|
||||||
enum LobbyIdentifier
|
public enum LobbyIdentifier
|
||||||
{
|
{
|
||||||
HOST,
|
HOST,
|
||||||
ADD,
|
JOIN,
|
||||||
LEAVE,
|
LEAVE,
|
||||||
|
LIST,
|
||||||
REQUEST
|
REQUEST
|
||||||
}
|
}
|
||||||
public static (string,string) GetUsernameAndMessage(byte[] json)
|
public static (string,string) GetUsernameAndMessage(byte[] json)
|
||||||
@@ -43,12 +44,46 @@ namespace SharedClientServer
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] ConstructLobbyDataMessage(Lobby lobby)
|
public static byte[] ConstructLobbyRequestMessage()
|
||||||
{
|
{
|
||||||
return null;
|
return GetMessageToSend(LOBBY, new
|
||||||
|
{
|
||||||
|
identifier = LobbyIdentifier.REQUEST
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static byte[] ConstructLobbyListMessage(Lobby[] lobbiesList)
|
||||||
|
{
|
||||||
|
return GetMessageToSend(LOBBY, new
|
||||||
|
{
|
||||||
|
identifier = LobbyIdentifier.LIST,
|
||||||
|
lobbies = lobbiesList
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] ConstructLobbyJoinMessage(int lobbyID)
|
||||||
|
{
|
||||||
|
return GetMessageToSend(LOBBY, new
|
||||||
|
{
|
||||||
|
identifier = LobbyIdentifier.JOIN,
|
||||||
|
id = lobbyID
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] ConstructLobbyLeaveMessage(int lobbyID)
|
||||||
|
{
|
||||||
|
return GetMessageToSend(LOBBY, new
|
||||||
|
{
|
||||||
|
identifier = LobbyIdentifier.LEAVE,
|
||||||
|
id = lobbyID
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static int GetLobbyID(byte[] json)
|
||||||
|
{
|
||||||
|
dynamic payload = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json));
|
||||||
|
return payload.id;
|
||||||
|
}
|
||||||
|
|
||||||
/// <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
|
||||||
@@ -70,5 +105,11 @@ namespace SharedClientServer
|
|||||||
Array.Copy(BitConverter.GetBytes(payloadBytes.Length+5),0,res,0,4);
|
Array.Copy(BitConverter.GetBytes(payloadBytes.Length+5),0,res,0,4);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static LobbyIdentifier GetLobbyIdentifier(byte[] json)
|
||||||
|
{
|
||||||
|
dynamic payload = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json));
|
||||||
|
return payload.identifier;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user