Merge branch 'master' into feature/jsonForWords
This commit is contained in:
@@ -9,6 +9,7 @@ using static SharedClientServer.JSONConvert;
|
||||
namespace Client
|
||||
{
|
||||
public delegate void LobbyCallback(int id);
|
||||
public delegate void LobbyJoinCallback(bool isHost);
|
||||
class Client : ObservableObject
|
||||
{
|
||||
private TcpClient tcpClient;
|
||||
@@ -21,7 +22,7 @@ namespace Client
|
||||
private string username;
|
||||
public Callback OnSuccessfullConnect;
|
||||
public Callback OnLobbiesListReceived;
|
||||
public Callback OnLobbyJoinSuccess;
|
||||
public LobbyJoinCallback OnLobbyJoinSuccess;
|
||||
public Callback OnLobbiesReceivedAndWaitingForHost;
|
||||
public LobbyCallback OnLobbyCreated;
|
||||
public LobbyCallback OnLobbyLeave;
|
||||
@@ -128,7 +129,8 @@ namespace Client
|
||||
OnLobbyCreated?.Invoke(lobbyCreatedID);
|
||||
break;
|
||||
case LobbyIdentifier.JOIN_SUCCESS:
|
||||
OnLobbyJoinSuccess?.Invoke();
|
||||
|
||||
OnLobbyJoinSuccess?.Invoke(JSONConvert.GetLobbyJoinIsHost(payload));
|
||||
break;
|
||||
case LobbyIdentifier.LEAVE:
|
||||
int lobbyLeaveID = JSONConvert.GetLobbyID(payload);
|
||||
|
||||
@@ -85,14 +85,14 @@ namespace Client
|
||||
|
||||
private void joinLobby()
|
||||
{
|
||||
// lobby die je wilt joinen verwijderen
|
||||
// nieuwe binnengekregen lobby toevoegen
|
||||
|
||||
client.OnLobbyJoinSuccess = OnLobbyJoinSuccess;
|
||||
client.SendMessage(JSONConvert.ConstructLobbyJoinMessage(SelectedLobby.ID));
|
||||
}
|
||||
|
||||
private void OnLobbyJoinSuccess()
|
||||
private void OnLobbyJoinSuccess(bool isHost)
|
||||
{
|
||||
ClientData.Instance.User.Host = isHost;
|
||||
startGameInLobby();
|
||||
}
|
||||
|
||||
|
||||
@@ -183,6 +183,10 @@ namespace Server.Models
|
||||
int id = JSONConvert.GetLobbyID(payload);
|
||||
ServerCommunication.INSTANCE.JoinLobby(this.User, id);
|
||||
sendMessage(JSONConvert.ConstructLobbyJoinSuccessMessage());
|
||||
|
||||
bool isHost;
|
||||
ServerCommunication.INSTANCE.JoinLobby(this.User,id, out isHost);
|
||||
sendMessage(JSONConvert.ConstructLobbyJoinSuccessMessage(isHost));
|
||||
ServerCommunication.INSTANCE.sendToAll(JSONConvert.ConstructLobbyListMessage(ServerCommunication.INSTANCE.lobbies.ToArray()));
|
||||
|
||||
//Task.Run(SendLobbyData);
|
||||
|
||||
@@ -202,12 +202,18 @@ namespace Server.Models
|
||||
return lobby.ID;
|
||||
}
|
||||
|
||||
public void JoinLobby(User user, int id)
|
||||
public void JoinLobby(User user, int id, out bool isHost)
|
||||
{
|
||||
isHost = false;
|
||||
foreach (Lobby l in lobbies)
|
||||
{
|
||||
if (l.ID == id)
|
||||
{
|
||||
if (l.Users.Count == 0)
|
||||
{
|
||||
user.Host = true;
|
||||
isHost = true;
|
||||
}
|
||||
AddToLobby(l, user);
|
||||
Debug.WriteLine($"{user.Username} joined lobby with id {id}");
|
||||
break;
|
||||
|
||||
@@ -136,9 +136,16 @@ namespace SharedClientServer
|
||||
return dynamicAsObject.ToObject<Lobby>();
|
||||
}
|
||||
|
||||
public static byte[] ConstructLobbyJoinSuccessMessage()
|
||||
public static byte[] ConstructLobbyJoinSuccessMessage(bool isHost)
|
||||
{
|
||||
return GetMessageToSend(LOBBY, new { identifier = LobbyIdentifier.JOIN_SUCCESS});
|
||||
return GetMessageToSend(LOBBY, new { identifier = LobbyIdentifier.JOIN_SUCCESS,
|
||||
host = isHost});
|
||||
}
|
||||
|
||||
public static bool GetLobbyJoinIsHost(byte[] json)
|
||||
{
|
||||
dynamic payload = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json));
|
||||
return payload.host;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
Reference in New Issue
Block a user