[ADD] added hosting a lobby

This commit is contained in:
Sem van der Hoeven
2020-10-20 22:16:19 +02:00
parent 671951c35b
commit 7b30911cd7
6 changed files with 93 additions and 17 deletions

View File

@@ -46,6 +46,25 @@ namespace SharedClientServer
});
}
#region lobby messages
public static byte[] ConstructLobbyHostMessage()
{
return GetMessageToSend(LOBBY, new
{
identifier = LobbyIdentifier.HOST
});
}
public static byte[] ConstructLobbyHostCreatedMessage(Lobby l)
{
return GetMessageToSend(LOBBY, new
{
identifier = LobbyIdentifier.HOST,
lobby = l
}) ;
}
public static byte[] ConstructLobbyRequestMessage()
{
return GetMessageToSend(LOBBY, new
@@ -80,6 +99,11 @@ namespace SharedClientServer
id = lobbyID
});
}
public static LobbyIdentifier GetLobbyIdentifier(byte[] json)
{
dynamic payload = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json));
return payload.identifier;
}
public static Lobby[] GetLobbiesFromMessage(byte[] json)
{
@@ -95,6 +119,15 @@ namespace SharedClientServer
return payload.id;
}
public static Lobby GetLobby(byte[] json)
{
dynamic payload = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json));
JObject dynamicAsObject = payload.lobby;
return dynamicAsObject.ToObject<Lobby>();
}
#endregion
/// <summary>
/// constructs a message that can be sent to the clients or server
/// </summary>
@@ -116,10 +149,6 @@ namespace SharedClientServer
return res;
}
public static LobbyIdentifier GetLobbyIdentifier(byte[] json)
{
dynamic payload = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json));
return payload.identifier;
}
}
}