[ADDITION] added a new property to the user (may be removed later on), and made a check for the random word

This commit is contained in:
Dogukan
2020-10-23 15:47:52 +02:00
parent b14a7691b5
commit ec08fbfced
3 changed files with 39 additions and 18 deletions

View File

@@ -22,6 +22,7 @@ namespace Server.Models
private NetworkStream stream;
private byte[] buffer = new byte[2048];
private byte[] totalBuffer = new byte[2048];
private string _randomWord = "";
private int totalBufferReceived = 0;
public User User { get; set; }
private ServerCommunication serverCom = ServerCommunication.INSTANCE;
@@ -145,6 +146,11 @@ namespace Server.Models
message = textMsg
};
if (textMsg == _randomWord && !string.IsNullOrEmpty(_randomWord))
{
Debug.WriteLine($"[SERVERCLIENT] word has been guessed! {User.Username} + Word: {_randomWord}");
}
//Sends the incomming message to be broadcast to all of the clients inside the current lobby.
serverCom.SendToLobby(serverCom.GetLobbyForUser(User), JSONConvert.GetMessageToSend(JSONConvert.MESSAGE, packet));
break;
@@ -234,11 +240,11 @@ namespace Server.Models
ServerCommunication.INSTANCE.sendToAll(JSONConvert.ConstructLobbyListMessage(ServerCommunication.INSTANCE.lobbies.ToArray()));
OnMessageReceivedOk = () =>
{
_randomWord = JSONConvert.SendRandomWord("WordsForGame.json");
serverCom.sendToAll(JSONConvert.GetMessageToSend(JSONConvert.RANDOMWORD, new
{
id = serverCom.GetLobbyForUser(User).ID,
word = JSONConvert.SendRandomWord("WordsForGame.json")
word = _randomWord
}));
OnMessageReceivedOk = null;
};