[FIX] fix users not being sent with lobbies
This commit is contained in:
@@ -99,6 +99,7 @@ namespace Client
|
|||||||
switch (lobbyIdentifier)
|
switch (lobbyIdentifier)
|
||||||
{
|
{
|
||||||
case LobbyIdentifier.LIST:
|
case LobbyIdentifier.LIST:
|
||||||
|
Debug.WriteLine("got lobbies list");
|
||||||
Lobbies = JSONConvert.GetLobbiesFromMessage(payload);
|
Lobbies = JSONConvert.GetLobbiesFromMessage(payload);
|
||||||
OnLobbiesListReceived?.Invoke();
|
OnLobbiesListReceived?.Invoke();
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -72,13 +72,25 @@ namespace Client
|
|||||||
|
|
||||||
private void updateLobbies()
|
private void updateLobbies()
|
||||||
{
|
{
|
||||||
|
Debug.WriteLine("updating lobbies...");
|
||||||
Lobby[] lobbiesArr = client.Lobbies;
|
Lobby[] lobbiesArr = client.Lobbies;
|
||||||
Application.Current.Dispatcher.Invoke(delegate
|
Application.Current.Dispatcher.Invoke(delegate
|
||||||
{
|
{
|
||||||
foreach (Lobby lobby in lobbiesArr)
|
|
||||||
|
for (int i = 0; i < lobbiesArr.Length; i++)
|
||||||
{
|
{
|
||||||
_lobbies.Add(lobby);
|
Lobby lobby = lobbiesArr[i];
|
||||||
|
Debug.WriteLine(lobby.PlayersIn);
|
||||||
|
if (i < _lobbies.Count && _lobbies[i].ID == lobby.ID)
|
||||||
|
{
|
||||||
|
_lobbies[i].Set(lobby);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
_lobbies.Add(lobbiesArr[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -149,11 +149,13 @@ namespace Server.Models
|
|||||||
Lobby created = ServerCommunication.INSTANCE.HostForLobby(this.User);
|
Lobby created = ServerCommunication.INSTANCE.HostForLobby(this.User);
|
||||||
Debug.WriteLine("[SERVERCLIENT] created lobby");
|
Debug.WriteLine("[SERVERCLIENT] created lobby");
|
||||||
sendMessage(JSONConvert.ConstructLobbyHostCreatedMessage(created));
|
sendMessage(JSONConvert.ConstructLobbyHostCreatedMessage(created));
|
||||||
|
sendMessage(JSONConvert.ConstructLobbyListMessage(ServerCommunication.INSTANCE.lobbies.ToArray()));
|
||||||
break;
|
break;
|
||||||
case LobbyIdentifier.JOIN:
|
case LobbyIdentifier.JOIN:
|
||||||
int id = JSONConvert.GetLobbyID(payload);
|
int id = JSONConvert.GetLobbyID(payload);
|
||||||
ServerCommunication.INSTANCE.JoinLobby(this.User,id);
|
ServerCommunication.INSTANCE.JoinLobby(this.User,id);
|
||||||
sendMessage(JSONConvert.ConstructLobbyJoinSuccessMessage());
|
sendMessage(JSONConvert.ConstructLobbyJoinSuccessMessage());
|
||||||
|
sendMessage(JSONConvert.ConstructLobbyListMessage(ServerCommunication.INSTANCE.lobbies.ToArray()));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -129,6 +129,7 @@ namespace Server.Models
|
|||||||
{
|
{
|
||||||
bool succ;
|
bool succ;
|
||||||
l.AddUser(user, out succ);
|
l.AddUser(user, out succ);
|
||||||
|
Debug.WriteLine("[SERVERCOMM] added user to lobby, now contains " + l.PlayersIn);
|
||||||
if (!succ)
|
if (!succ)
|
||||||
{
|
{
|
||||||
// TODO send lobby full message
|
// TODO send lobby full message
|
||||||
|
|||||||
@@ -110,8 +110,14 @@ namespace SharedClientServer
|
|||||||
{
|
{
|
||||||
dynamic payload = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json));
|
dynamic payload = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json));
|
||||||
JArray lobbiesArray = payload.lobbies;
|
JArray lobbiesArray = payload.lobbies;
|
||||||
Debug.WriteLine(lobbiesArray.ToString());
|
Debug.WriteLine("[JSONCONVERT] got lobbies from message" + lobbiesArray.ToString());
|
||||||
return lobbiesArray.ToObject<Lobby[]>();
|
Lobby[] lobbiesTemp = lobbiesArray.ToObject<Lobby[]>();
|
||||||
|
Debug.WriteLine("lobbies in array: ");
|
||||||
|
foreach (Lobby l in lobbiesTemp)
|
||||||
|
{
|
||||||
|
Debug.WriteLine("players: " + l.PlayersIn);
|
||||||
|
}
|
||||||
|
return lobbiesTemp;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GetLobbyID(byte[] json)
|
public static int GetLobbyID(byte[] json)
|
||||||
|
|||||||
@@ -68,12 +68,25 @@ namespace Client
|
|||||||
set { _playersIn = value; }
|
set { _playersIn = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Set(Lobby lobby)
|
||||||
|
{
|
||||||
|
this._id = lobby._id;
|
||||||
|
this._users = lobby._users;
|
||||||
|
this._maxPlayers = lobby._maxPlayers;
|
||||||
|
}
|
||||||
|
|
||||||
public int MaxPlayers
|
public int MaxPlayers
|
||||||
{
|
{
|
||||||
get { return _maxPlayers; }
|
get { return _maxPlayers; }
|
||||||
set { _maxPlayers = value; }
|
set { _maxPlayers = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public List<User> Users
|
||||||
|
{
|
||||||
|
get { return _users; }
|
||||||
|
set { _users = value; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using System;
|
using Newtonsoft.Json;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
|
||||||
@@ -10,6 +11,7 @@ namespace SharedClientServer
|
|||||||
private int _score;
|
private int _score;
|
||||||
private bool _host;
|
private bool _host;
|
||||||
|
|
||||||
|
[JsonConstructor]
|
||||||
public User(string username, int score, bool host)
|
public User(string username, int score, bool host)
|
||||||
{
|
{
|
||||||
_username = username;
|
_username = username;
|
||||||
|
|||||||
Reference in New Issue
Block a user