[ADDITION] servercommunication towards the client.
Still in progress not functional because of a null exception when receiving the broadcast message.
This commit is contained in:
@@ -69,7 +69,7 @@ namespace Client
|
|||||||
|
|
||||||
private void handleData(byte[] message)
|
private void handleData(byte[] message)
|
||||||
{
|
{
|
||||||
byte id = message[0];
|
byte id = message[4];
|
||||||
byte[] payload = new byte[message.Length - 1];
|
byte[] payload = new byte[message.Length - 1];
|
||||||
Array.Copy(message, 1, payload, 0, message.Length - 1);
|
Array.Copy(message, 1, payload, 0, message.Length - 1);
|
||||||
switch (id)
|
switch (id)
|
||||||
@@ -83,7 +83,8 @@ namespace Client
|
|||||||
string textUsername = combo.Item1;
|
string textUsername = combo.Item1;
|
||||||
string textMsg = combo.Item2;
|
string textMsg = combo.Item2;
|
||||||
//TODO display username and message in chat window
|
//TODO display username and message in chat window
|
||||||
Debug.WriteLine("Message username: {0}\t Message: {1}", textUsername, textMsg);
|
|
||||||
|
Debug.WriteLine("[CLIENT] User name: {0}\t User message: {1}", textUsername, textMsg);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JSONConvert.LOBBY:
|
case JSONConvert.LOBBY:
|
||||||
|
|||||||
@@ -33,15 +33,15 @@ namespace Client.ViewModels
|
|||||||
|
|
||||||
public ViewModelGame()
|
public ViewModelGame()
|
||||||
{
|
{
|
||||||
if (_payload == null)
|
//if (_payload == null)
|
||||||
{
|
//{
|
||||||
_message = "";
|
// _message = "";
|
||||||
}
|
//}
|
||||||
else
|
//else
|
||||||
{
|
//{
|
||||||
_message = _payload.message;
|
// _message = _payload.message;
|
||||||
_username = _payload.username;
|
// _username = _payload.username;
|
||||||
}
|
//}
|
||||||
OnKeyDown = new RelayCommand(ChatBox_KeyDown);
|
OnKeyDown = new RelayCommand(ChatBox_KeyDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
using Newtonsoft.Json.Linq;
|
||||||
using SharedClientServer;
|
using SharedClientServer;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@@ -16,6 +17,7 @@ namespace Server.Models
|
|||||||
private byte[] totalBuffer = new byte[1024];
|
private byte[] totalBuffer = new byte[1024];
|
||||||
private int totalBufferReceived = 0;
|
private int totalBufferReceived = 0;
|
||||||
public User User { get; set; }
|
public User User { get; set; }
|
||||||
|
private ServerCommunication serverCom = ServerCommunication.INSTANCE;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -116,7 +118,17 @@ namespace Server.Models
|
|||||||
string textUsername = combo.Item1;
|
string textUsername = combo.Item1;
|
||||||
string textMsg = combo.Item2;
|
string textMsg = combo.Item2;
|
||||||
|
|
||||||
|
Debug.WriteLine("[SERVERCLIENT] User name: {0}\t User message: {1}", textUsername, textMsg);
|
||||||
|
|
||||||
|
dynamic dataPacket = new
|
||||||
|
{
|
||||||
|
username = textUsername,
|
||||||
|
message = textMsg
|
||||||
|
};
|
||||||
|
|
||||||
// todo handle sending to all except this user the username and message to display in chat
|
// todo handle sending to all except this user the username and message to display in chat
|
||||||
|
//serverCom.SendToAllExcept();
|
||||||
|
serverCom.sendToAll(JSONConvert.GetMessageToSend(JSONConvert.MESSAGE, dataPacket));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JSONConvert.LOBBY:
|
case JSONConvert.LOBBY:
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ namespace SharedClientServer
|
|||||||
public static (string,string) GetUsernameAndMessage(byte[] json)
|
public static (string,string) GetUsernameAndMessage(byte[] json)
|
||||||
{
|
{
|
||||||
string msg = Encoding.ASCII.GetString(json);
|
string msg = Encoding.ASCII.GetString(json);
|
||||||
|
Debug.WriteLine("Sent data: {0}", msg);
|
||||||
dynamic payload = JsonConvert.DeserializeObject(msg);
|
dynamic payload = JsonConvert.DeserializeObject(msg);
|
||||||
|
|
||||||
return (payload.username, payload.message);
|
return (payload.username, payload.message);
|
||||||
@@ -49,7 +50,6 @@ namespace SharedClientServer
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/// <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
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user