[FIX] fixed the broadcast for the chat messages.

This commit is contained in:
Dogukan
2020-10-21 22:40:36 +02:00
parent 0f01354b72
commit d5d6d59690
3 changed files with 25 additions and 8 deletions

View File

@@ -24,6 +24,7 @@ namespace Client
public Callback OnLobbyJoinSuccess;
public Callback OnLobbiesReceivedAndWaitingForHost;
public OnLobbyCreated OnLobbyCreated;
private ClientData data = ClientData.Instance;
public Lobby[] Lobbies { get; set; }
public Client(string username)
@@ -81,6 +82,7 @@ namespace Client
byte[] payload = new byte[message.Length - 5];
Array.Copy(message, 5, payload, 0, message.Length - 5);
Debug.WriteLine("[CLIENT] GOT STRING" + Encoding.ASCII.GetString(payload));
switch (id)
{
case JSONConvert.LOGIN:
@@ -92,6 +94,11 @@ namespace Client
string textUsername = combo.Item1;
string textMsg = combo.Item2;
if(textUsername != data.User.Username)
{
ViewModels.ViewModelGame.HandleIncomingMsg(textUsername, textMsg);
}
//TODO display username and message in chat window
Debug.WriteLine("[CLIENT] INCOMING MESSAGE!");
Debug.WriteLine("[CLIENT] User name: {0}\t User message: {1}", textUsername, textMsg);

View File

@@ -20,13 +20,13 @@ namespace Client.ViewModels
private Point currentPoint = new Point();
private Color color;
public ObservableCollection<string> Messages { get; } = new ObservableCollection<string>();
public static ObservableCollection<string> Messages { get; } = new ObservableCollection<string>();
private dynamic _payload;
private string _username;
public string _username;
private string _message;
public string _message;
public string Message
{
get
@@ -120,7 +120,13 @@ namespace Client.ViewModels
data.Client.SendMessage(JSONConvert.GetMessageToSend(JSONConvert.MESSAGE, _payload));
}
public static void HandleIncomingMsg(string username, string message)
{
Application.Current.Dispatcher.Invoke(delegate
{
Messages.Add($"{username}: {message}");
});
}
}
}