Compare commits
32 Commits
feature/pl
...
feature/te
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f8dfc0f9c | ||
|
|
5ac4b59e38 | ||
|
|
3c1f1a0028 | ||
|
|
e7b40d7e64 | ||
|
|
27e70d1ec0 | ||
|
|
0e6a2bab59 | ||
|
|
125f4c0410 | ||
|
|
b9b217622a | ||
|
|
2d4540e28e | ||
|
|
052f07db93 | ||
|
|
898b579ca9 | ||
|
|
39ded8524b | ||
|
|
398ba1d5bd | ||
|
|
8ca4efc296 | ||
|
|
3015c0312f | ||
|
|
3c0f5018db | ||
|
|
9558c75eab | ||
|
|
ec08fbfced | ||
|
|
87ebdeef58 | ||
|
|
bf09dba850 | ||
|
|
b14a7691b5 | ||
|
|
7df48ab322 | ||
|
|
6512518fb7 | ||
|
|
80d970da35 | ||
|
|
2c7bf3e217 | ||
|
|
92f57a87bc | ||
|
|
da5528c7b2 | ||
|
|
c16f7cf68f | ||
|
|
5c2dea3ab4 | ||
|
|
24eb43239b | ||
|
|
335d17838c | ||
|
|
242c435ac7 |
@@ -21,6 +21,7 @@ namespace Client
|
|||||||
public delegate void CanvasReset();
|
public delegate void CanvasReset();
|
||||||
public delegate void LobbyCallback(int id);
|
public delegate void LobbyCallback(int id);
|
||||||
|
|
||||||
|
|
||||||
class Client : ObservableObject
|
class Client : ObservableObject
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -48,6 +49,7 @@ namespace Client
|
|||||||
private ClientData data = ClientData.Instance;
|
private ClientData data = ClientData.Instance;
|
||||||
public CanvasDataReceived CanvasDataReceived;
|
public CanvasDataReceived CanvasDataReceived;
|
||||||
public CanvasReset CReset;
|
public CanvasReset CReset;
|
||||||
|
public HandleIncomingPlayer UpdateUserScores;
|
||||||
public Lobby[] Lobbies { get; set; }
|
public Lobby[] Lobbies { get; set; }
|
||||||
|
|
||||||
public Client(string username)
|
public Client(string username)
|
||||||
@@ -68,9 +70,10 @@ namespace Client
|
|||||||
OnSuccessfullConnect?.Invoke();
|
OnSuccessfullConnect?.Invoke();
|
||||||
OnLobbyUpdate = updateGameLobby;
|
OnLobbyUpdate = updateGameLobby;
|
||||||
SendMessage(JSONConvert.ConstructUsernameMessage(username));
|
SendMessage(JSONConvert.ConstructUsernameMessage(username));
|
||||||
this.stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnReadComplete),null);
|
this.stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnReadComplete), null);
|
||||||
|
|
||||||
} catch (Exception e)
|
}
|
||||||
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("Can't connect, retrying...");
|
Debug.WriteLine("Can't connect, retrying...");
|
||||||
tcpClient.BeginConnect("localhost", Port, new AsyncCallback(OnConnect), null);
|
tcpClient.BeginConnect("localhost", Port, new AsyncCallback(OnConnect), null);
|
||||||
@@ -92,7 +95,6 @@ namespace Client
|
|||||||
throw new OutOfMemoryException("buffer too small");
|
throw new OutOfMemoryException("buffer too small");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Array.Copy(buffer, 0, totalBuffer, totalBufferReceived, amountReceived);
|
Array.Copy(buffer, 0, totalBuffer, totalBufferReceived, amountReceived);
|
||||||
totalBufferReceived += amountReceived;
|
totalBufferReceived += amountReceived;
|
||||||
|
|
||||||
@@ -112,10 +114,11 @@ namespace Client
|
|||||||
|
|
||||||
ar.AsyncWaitHandle.WaitOne();
|
ar.AsyncWaitHandle.WaitOne();
|
||||||
stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnReadComplete), null);
|
stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnReadComplete), null);
|
||||||
} catch (IOException e)
|
}
|
||||||
|
catch (IOException e)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("[CLIENT] server not responding! got error: " + e.Message);
|
Debug.WriteLine("[CLIENT] server not responding! got error: " + e.Message);
|
||||||
OnServerDisconnect?.Invoke();
|
OnServerDisconnect?.Invoke();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,11 +141,16 @@ namespace Client
|
|||||||
string textUsername = combo.Item1;
|
string textUsername = combo.Item1;
|
||||||
string textMsg = combo.Item2;
|
string textMsg = combo.Item2;
|
||||||
|
|
||||||
if(textUsername != data.User.Username)
|
if (textUsername != data.User.Username)
|
||||||
{
|
{
|
||||||
IncomingMsg?.Invoke(textUsername, textMsg);
|
IncomingMsg?.Invoke(textUsername, textMsg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (textMsg == data.User.RandomWord && !string.IsNullOrEmpty(data.User.RandomWord))
|
||||||
|
{
|
||||||
|
Debug.WriteLine($"[CLIENT] word has been guessed! {data.User.Username} + Word: {data.User.RandomWord}");
|
||||||
|
}
|
||||||
|
|
||||||
//TODO display username and message in chat window
|
//TODO display username and message in chat window
|
||||||
Debug.WriteLine("[CLIENT] INCOMING MESSAGE!");
|
Debug.WriteLine("[CLIENT] INCOMING MESSAGE!");
|
||||||
Debug.WriteLine("[CLIENT] User name: {0}\t User message: {1}", textUsername, textMsg);
|
Debug.WriteLine("[CLIENT] User name: {0}\t User message: {1}", textUsername, textMsg);
|
||||||
@@ -190,40 +198,57 @@ namespace Client
|
|||||||
|
|
||||||
case JSONConvert.CANVAS_WRITING:
|
case JSONConvert.CANVAS_WRITING:
|
||||||
CanvasDataReceived?.Invoke(JSONConvert.getCoordinates(payload), JSONConvert.getCanvasDrawingColor(payload));
|
CanvasDataReceived?.Invoke(JSONConvert.getCoordinates(payload), JSONConvert.getCanvasDrawingColor(payload));
|
||||||
// we hebben gedrawed, dus stuur dat we weer kunnen drawen
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
||||||
case JSONConvert.RANDOMWORD:
|
case JSONConvert.RANDOMWORD:
|
||||||
//Flag byte for receiving the random word.
|
//Flag byte for receiving the random word.
|
||||||
int lobbyId = JSONConvert.GetLobbyID(payload);
|
int lobbyId = JSONConvert.GetLobbyID(payload);
|
||||||
string randomWord = JSONConvert.GetRandomWord(payload);
|
data.User.RandomWord = JSONConvert.GetRandomWord(payload);
|
||||||
|
data.User.TurnToDraw = true; // Dit is test code, dit kan weg zodra alles lopende is.
|
||||||
if (data.Lobby?.ID == lobbyId)
|
if (data.Lobby?.ID == lobbyId && data.User.TurnToDraw)
|
||||||
RandomWord?.Invoke(randomWord);
|
RandomWord?.Invoke(data.User.RandomWord);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
Debug.WriteLine("[CLIENT] Received weird identifier: " + id);
|
Debug.WriteLine("[CLIENT] Received weird identifier: " + id);
|
||||||
break;
|
break;
|
||||||
|
case JSONConvert.GAME:
|
||||||
|
switch (JSONConvert.GetGameCommand(payload))
|
||||||
|
{
|
||||||
|
case JSONConvert.GameCommand.TIMER_ELAPSED:
|
||||||
|
int lobbyElapsedID = JSONConvert.GetLobbyID(payload);
|
||||||
|
|
||||||
|
//todo set next round
|
||||||
|
break;
|
||||||
|
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
SendMessage(JSONConvert.GetMessageToSend(JSONConvert.MESSAGE_RECEIVED,null));
|
SendMessage(JSONConvert.GetMessageToSend(JSONConvert.MESSAGE_RECEIVED, null));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Updates the current lobby with the joining players,
|
||||||
|
* their player score is also tracked and should always be zero.
|
||||||
|
*/
|
||||||
private void updateGameLobby()
|
private void updateGameLobby()
|
||||||
{
|
{
|
||||||
|
Debug.WriteLine("[CLIENT] updating game lobby");
|
||||||
foreach (var item in Lobbies)
|
foreach (var item in Lobbies)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("[CLIENT] lobby data: {0}", item.Users.Count);
|
Debug.WriteLine("[CLIENT] lobby data: {0}", item.Users.Count);
|
||||||
if (item.ID == data.Lobby?.ID)
|
if (item.ID == data.Lobby?.ID)
|
||||||
IncomingPlayer?.Invoke(item);
|
{
|
||||||
|
//IncomingPlayer?.Invoke(item);
|
||||||
|
UpdateUserScores?.Invoke(item as Lobby);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void SendMessage(byte[] message)
|
public void SendMessage(byte[] message)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("[CLIENT] sending message " + Encoding.ASCII.GetString(message));
|
Debug.WriteLine("[CLIENT] sending message " + Encoding.ASCII.GetString(message));
|
||||||
|
|||||||
37
Client/ViewModels/LoginViewModel.cs
Normal file
37
Client/ViewModels/LoginViewModel.cs
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
using SharedClientServer;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
using System.Windows;
|
||||||
|
|
||||||
|
namespace Client.ViewModels
|
||||||
|
{
|
||||||
|
|
||||||
|
class LoginViewModel
|
||||||
|
{
|
||||||
|
ClientData data = ClientData.Instance;
|
||||||
|
private Window window;
|
||||||
|
|
||||||
|
public LoginViewModel(Window window)
|
||||||
|
{
|
||||||
|
this.window = window;
|
||||||
|
}
|
||||||
|
public void UsernameEntered(string name) {
|
||||||
|
User user = new User(name);
|
||||||
|
|
||||||
|
Client client = new Client(user.Username);
|
||||||
|
client.OnSuccessfullConnect = () =>
|
||||||
|
{
|
||||||
|
// because we need to start the main window on a UI thread, we need to let the dispatcher handle it, which will execute the code on the ui thread
|
||||||
|
Application.Current.Dispatcher.Invoke(delegate {
|
||||||
|
data.User = user;
|
||||||
|
data.Client = client;
|
||||||
|
client.SendMessage(JSONConvert.ConstructLobbyRequestMessage());
|
||||||
|
MainWindow startWindow = new MainWindow();
|
||||||
|
startWindow.Show();
|
||||||
|
window.Close();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -61,6 +61,7 @@ namespace Client
|
|||||||
Debug.WriteLine("attempting to host game for " + ClientData.Instance.User.Username);
|
Debug.WriteLine("attempting to host game for " + ClientData.Instance.User.Username);
|
||||||
client.SendMessage(JSONConvert.ConstructLobbyHostMessage());
|
client.SendMessage(JSONConvert.ConstructLobbyHostMessage());
|
||||||
client.OnLobbyCreated = becomeHostForLobby;
|
client.OnLobbyCreated = becomeHostForLobby;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void becomeHostForLobby(int id)
|
private void becomeHostForLobby(int id)
|
||||||
@@ -68,6 +69,7 @@ namespace Client
|
|||||||
Debug.WriteLine($"got host succes with data {id} ");
|
Debug.WriteLine($"got host succes with data {id} ");
|
||||||
wantToBeHost = true;
|
wantToBeHost = true;
|
||||||
wantToBeHostId = id;
|
wantToBeHostId = id;
|
||||||
|
ClientData.Instance.User.Host = true;
|
||||||
client.OnLobbiesReceivedAndWaitingForHost = hostLobbiesReceived;
|
client.OnLobbiesReceivedAndWaitingForHost = hostLobbiesReceived;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -112,7 +114,7 @@ namespace Client
|
|||||||
|
|
||||||
private void updateLobbies()
|
private void updateLobbies()
|
||||||
{
|
{
|
||||||
Debug.WriteLine("updating lobbies...");
|
Debug.WriteLine("[VIEWMODEL] updating lobbies...");
|
||||||
Lobby[] lobbiesArr = client.Lobbies;
|
Lobby[] lobbiesArr = client.Lobbies;
|
||||||
Application.Current.Dispatcher.Invoke(delegate
|
Application.Current.Dispatcher.Invoke(delegate
|
||||||
{
|
{
|
||||||
@@ -122,6 +124,11 @@ namespace Client
|
|||||||
foreach (Lobby l in lobbiesArr)
|
foreach (Lobby l in lobbiesArr)
|
||||||
{
|
{
|
||||||
_lobbies.Add(l);
|
_lobbies.Add(l);
|
||||||
|
Lobby clientLobby = ClientData.Instance.Lobby;
|
||||||
|
if (l.ID == clientLobby?.ID)
|
||||||
|
{
|
||||||
|
clientLobby = l;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -8,8 +8,8 @@ using System.ComponentModel;
|
|||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Timers;
|
using System.Timers;
|
||||||
using System.Windows;
|
using System.Windows;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
using System.Windows.Shapes;
|
using System.Windows.Shapes;
|
||||||
|
|
||||||
namespace Client.ViewModels
|
namespace Client.ViewModels
|
||||||
@@ -32,8 +32,9 @@ namespace Client.ViewModels
|
|||||||
|
|
||||||
private dynamic _payload;
|
private dynamic _payload;
|
||||||
|
|
||||||
public string _username;
|
public string _username;
|
||||||
|
|
||||||
|
|
||||||
public string _message;
|
public string _message;
|
||||||
public string Message
|
public string Message
|
||||||
{
|
{
|
||||||
@@ -48,19 +49,12 @@ namespace Client.ViewModels
|
|||||||
}
|
}
|
||||||
|
|
||||||
private string _randomWord;
|
private string _randomWord;
|
||||||
|
|
||||||
public string RandomWord
|
public string RandomWord
|
||||||
{
|
{
|
||||||
get { return _randomWord; }
|
get { return _randomWord; }
|
||||||
set { _randomWord = value; }
|
set { _randomWord = value; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string Word
|
|
||||||
{
|
|
||||||
get;
|
|
||||||
set;
|
|
||||||
}
|
|
||||||
|
|
||||||
public bool IsHost
|
public bool IsHost
|
||||||
{
|
{
|
||||||
get { return data.User.Host; }
|
get { return data.User.Host; }
|
||||||
@@ -69,17 +63,6 @@ namespace Client.ViewModels
|
|||||||
public ViewModelGame(GameWindow window)
|
public ViewModelGame(GameWindow window)
|
||||||
{
|
{
|
||||||
this.window = window;
|
this.window = window;
|
||||||
if (_payload == null)
|
|
||||||
{
|
|
||||||
_message = "";
|
|
||||||
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//_message = data.Message;
|
|
||||||
//_username = data.User.Username;
|
|
||||||
//Messages.Add($"{data.User.Username}: {Message}");
|
|
||||||
}
|
|
||||||
|
|
||||||
buffer = new double[maxLines][];
|
buffer = new double[maxLines][];
|
||||||
linesQueue = new Queue<double[][]>();
|
linesQueue = new Queue<double[][]>();
|
||||||
@@ -91,6 +74,17 @@ namespace Client.ViewModels
|
|||||||
data.Client.RandomWord = HandleRandomWord;
|
data.Client.RandomWord = HandleRandomWord;
|
||||||
data.Client.IncomingMsg = HandleIncomingMsg;
|
data.Client.IncomingMsg = HandleIncomingMsg;
|
||||||
data.Client.IncomingPlayer = HandleIncomingPlayer;
|
data.Client.IncomingPlayer = HandleIncomingPlayer;
|
||||||
|
data.Client.UpdateUserScores = UpdateUserScores;
|
||||||
|
|
||||||
|
Application.Current.Dispatcher.Invoke(delegate
|
||||||
|
{
|
||||||
|
Messages.Clear();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
queueTimer = new Timer(50);
|
||||||
|
queueTimer.Start();
|
||||||
|
queueTimer.Elapsed += sendArrayFromQueue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ICommand OnKeyDown { get; set; }
|
public ICommand OnKeyDown { get; set; }
|
||||||
@@ -99,10 +93,7 @@ namespace Client.ViewModels
|
|||||||
|
|
||||||
public void BeginGame()
|
public void BeginGame()
|
||||||
{
|
{
|
||||||
|
|
||||||
queueTimer = new Timer(50);
|
|
||||||
queueTimer.Start();
|
|
||||||
queueTimer.Elapsed += sendArrayFromQueue;
|
|
||||||
data.Client.SendMessage(JSONConvert.ConstructGameStartData(data.Lobby.ID));
|
data.Client.SendMessage(JSONConvert.ConstructGameStartData(data.Lobby.ID));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +101,7 @@ namespace Client.ViewModels
|
|||||||
private void CanvasResetLocal()
|
private void CanvasResetLocal()
|
||||||
{
|
{
|
||||||
this.window.CanvasForPaint.Children.Clear();
|
this.window.CanvasForPaint.Children.Clear();
|
||||||
data.Client.SendMessage(JSONConvert.GetMessageToSend(JSONConvert.CANVAS, JSONConvert.CANVAS_RESET));
|
data.Client.SendMessage(JSONConvert.ConstructCanvasReset());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -203,7 +194,10 @@ namespace Client.ViewModels
|
|||||||
|
|
||||||
private void CanvasResetData()
|
private void CanvasResetData()
|
||||||
{
|
{
|
||||||
this.window.CanvasForPaint.Children.Clear();
|
Application.Current.Dispatcher.Invoke(delegate
|
||||||
|
{
|
||||||
|
this.window.CanvasForPaint.Children.Clear();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ChatBox_KeyDown()
|
private void ChatBox_KeyDown()
|
||||||
@@ -227,7 +221,7 @@ namespace Client.ViewModels
|
|||||||
data.Client.SendMessage(JSONConvert.GetMessageToSend(JSONConvert.MESSAGE, _payload));
|
data.Client.SendMessage(JSONConvert.GetMessageToSend(JSONConvert.MESSAGE, _payload));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void HandleIncomingMsg(string username, string message)
|
public void HandleIncomingMsg(string username, string message)
|
||||||
{
|
{
|
||||||
Application.Current.Dispatcher.Invoke(delegate
|
Application.Current.Dispatcher.Invoke(delegate
|
||||||
{
|
{
|
||||||
@@ -240,12 +234,12 @@ namespace Client.ViewModels
|
|||||||
data.Client.SendMessage(JSONConvert.ConstructLobbyLeaveMessage(data.Lobby.ID));
|
data.Client.SendMessage(JSONConvert.ConstructLobbyLeaveMessage(data.Lobby.ID));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void HandleRandomWord(string randomWord)
|
public void HandleRandomWord(string randomWord)
|
||||||
{
|
{
|
||||||
Debug.WriteLine("[CLIENT] Reached the handle random word method!");
|
Debug.WriteLine("[CLIENT] Reached the handle random word method!");
|
||||||
Application.Current.Dispatcher.Invoke(delegate
|
Application.Current.Dispatcher.Invoke(delegate
|
||||||
{
|
{
|
||||||
Word = randomWord;
|
RandomWord = randomWord;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
public void HandleIncomingPlayer(Lobby lobby)
|
public void HandleIncomingPlayer(Lobby lobby)
|
||||||
@@ -255,9 +249,34 @@ namespace Client.ViewModels
|
|||||||
Players.Clear();
|
Players.Clear();
|
||||||
foreach (var item in lobby.Users)
|
foreach (var item in lobby.Users)
|
||||||
{
|
{
|
||||||
Players.Add(item.Username);
|
Players.Add(item.Username + "\n" + item.Score);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void UpdateUserScores(Lobby newLobby) {
|
||||||
|
Debug.WriteLine("[GAME] updating user scores");
|
||||||
|
List<User> newUsers = newLobby.Users;
|
||||||
|
// go over all users in current lobby
|
||||||
|
foreach (User user in data.Lobby?.Users)
|
||||||
|
{
|
||||||
|
// check with all users in new lobby
|
||||||
|
foreach (User newUser in newUsers)
|
||||||
|
{
|
||||||
|
// and update the score
|
||||||
|
if (newUser.Username == user.Username)
|
||||||
|
{
|
||||||
|
Debug.WriteLine($"[GAME] setting score of {user.Username} to {newUser.Score}. it was {user.Score}");
|
||||||
|
user.Score = newUser.Score;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// update all the scores in the player list
|
||||||
|
HandleIncomingPlayer(newLobby);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -38,14 +38,12 @@
|
|||||||
<xctk:ColorPicker Name="ClrPcker_Background" SelectedColorChanged="ClrPcker_Background_SelectedColorChanged_1" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Height="22" Width="100"/>
|
<xctk:ColorPicker Name="ClrPcker_Background" SelectedColorChanged="ClrPcker_Background_SelectedColorChanged_1" Grid.Column="1" HorizontalAlignment="Left" VerticalAlignment="Center" Height="22" Width="100"/>
|
||||||
|
|
||||||
|
|
||||||
<Label Name="GuessWord" Grid.Row="0" Grid.Column="1" Content="{Binding Path=RandomWord, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
|
<Label Name="GuessWord" Grid.Row="0" Grid.Column="2" Content="{Binding Path=RandomWord, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="20"/>
|
||||||
|
|
||||||
<Label Grid.Row="0" Grid.Column="2" FontSize="20" Content="" VerticalAlignment="Center" HorizontalAlignment="Center"/>
|
<Button Name="CanvasReset" Command="{Binding ButtonResetCanvas}" Grid.Row="0" Grid.Column="3" Content="RESET"/>
|
||||||
|
|
||||||
<Button Name="CanvasReset" Click="CanvasReset_Click" Grid.Row="0" Grid.Column="3" Content="RESET"/>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|
||||||
<Button Name="StartGame" Grid.Row="0" Grid.Column="2" Content="Start Game" FontSize="20" Command="{Binding ButtonStartGame}" IsEnabled="{Binding IsHost}"/>
|
|
||||||
|
|
||||||
|
|
||||||
<Border Grid.Row="1" Grid.Column="1" Margin ="10,10,10,10" BorderBrush="Black" BorderThickness ="2.5">
|
<Border Grid.Row="1" Grid.Column="1" Margin ="10,10,10,10" BorderBrush="Black" BorderThickness ="2.5">
|
||||||
|
|||||||
@@ -24,8 +24,6 @@
|
|||||||
<Label Grid.Row="2" FontSize="15" Content="(max amount of characters for the username is 10)"/>
|
<Label Grid.Row="2" FontSize="15" Content="(max amount of characters for the username is 10)"/>
|
||||||
|
|
||||||
<TextBox Name="usernameTextbox" Grid.Row="1" Grid.Column="1" MaxLength="69" FontSize="30" VerticalAlignment="Center" HorizontalAlignment="Left" Width="250"/>
|
<TextBox Name="usernameTextbox" Grid.Row="1" Grid.Column="1" MaxLength="69" FontSize="30" VerticalAlignment="Center" HorizontalAlignment="Left" Width="250"/>
|
||||||
<Button Content="ENTER" Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Right" Width="100" Height="40" Click="Button_EnterUsername"/>
|
<Button Name="LoginButton" Content="ENTER" Grid.Column="1" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Right" Width="100" Height="40" Click="Button_EnterUsername"/>
|
||||||
|
|
||||||
<Label Grid.Row="3" Grid.Column="0" Content="Tip of the century: base64 != UTF8!" FontSize="20" FontWeight="Bold"/>
|
|
||||||
</Grid>
|
</Grid>
|
||||||
</Window>
|
</Window>
|
||||||
|
|||||||
@@ -27,8 +27,12 @@ namespace Client.Views
|
|||||||
|
|
||||||
private void Button_EnterUsername(object sender, RoutedEventArgs e)
|
private void Button_EnterUsername(object sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
User user = new User(usernameTextbox.Text);
|
string name = usernameTextbox.Text;
|
||||||
|
if (name == string.Empty) return;
|
||||||
|
User user = new User(name);
|
||||||
|
|
||||||
Client client = new Client(user.Username);
|
Client client = new Client(user.Username);
|
||||||
|
LoginButton.IsEnabled = false;
|
||||||
client.OnSuccessfullConnect = () =>
|
client.OnSuccessfullConnect = () =>
|
||||||
{
|
{
|
||||||
// because we need to start the main window on a UI thread, we need to let the dispatcher handle it, which will execute the code on the ui thread
|
// because we need to start the main window on a UI thread, we need to let the dispatcher handle it, which will execute the code on the ui thread
|
||||||
@@ -42,6 +46,7 @@ namespace Client.Views
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
12
Eindproject/Client2/Client2.csproj
Normal file
12
Eindproject/Client2/Client2.csproj
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\Client\Client.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
14
Eindproject/Client2/Program.cs
Normal file
14
Eindproject/Client2/Program.cs
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
|
namespace Client2
|
||||||
|
{
|
||||||
|
class Program
|
||||||
|
{
|
||||||
|
static void Main(string[] args)
|
||||||
|
{
|
||||||
|
Client.App app = new Client.App();
|
||||||
|
app.Run();
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -9,6 +9,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Client", "..\Client\Client.
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SharedClientServer", "..\SharedClientServer\SharedClientServer.shproj", "{6D26F969-9CB1-414F-AC3E-7253D449AC5A}"
|
Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "SharedClientServer", "..\SharedClientServer\SharedClientServer.shproj", "{6D26F969-9CB1-414F-AC3E-7253D449AC5A}"
|
||||||
EndProject
|
EndProject
|
||||||
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Tests", "Tests\Tests.csproj", "{4CB2CD76-07D9-44D0-A559-A7A301621D30}"
|
||||||
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||||
..\SharedClientServer\SharedClientServer.projitems*{67a9bf1a-d317-47ca-9f07-c3480d1360ff}*SharedItemsImports = 5
|
..\SharedClientServer\SharedClientServer.projitems*{67a9bf1a-d317-47ca-9f07-c3480d1360ff}*SharedItemsImports = 5
|
||||||
@@ -28,6 +30,10 @@ Global
|
|||||||
{83768EDB-097E-4089-A5DE-208CB252D1A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
{83768EDB-097E-4089-A5DE-208CB252D1A0}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
{83768EDB-097E-4089-A5DE-208CB252D1A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
{83768EDB-097E-4089-A5DE-208CB252D1A0}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
{83768EDB-097E-4089-A5DE-208CB252D1A0}.Release|Any CPU.Build.0 = Release|Any CPU
|
{83768EDB-097E-4089-A5DE-208CB252D1A0}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
{4CB2CD76-07D9-44D0-A559-A7A301621D30}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{4CB2CD76-07D9-44D0-A559-A7A301621D30}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{4CB2CD76-07D9-44D0-A559-A7A301621D30}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{4CB2CD76-07D9-44D0-A559-A7A301621D30}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
EndGlobalSection
|
EndGlobalSection
|
||||||
GlobalSection(SolutionProperties) = preSolution
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
HideSolutionNode = FALSE
|
HideSolutionNode = FALSE
|
||||||
|
|||||||
10
Eindproject/TestHelper/Helper.cs
Normal file
10
Eindproject/TestHelper/Helper.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
using SharedClientServer;
|
||||||
|
using System;
|
||||||
|
|
||||||
|
namespace TestHelper
|
||||||
|
{
|
||||||
|
public class Helper
|
||||||
|
{
|
||||||
|
public static JSONConvert JSONConvert;
|
||||||
|
}
|
||||||
|
}
|
||||||
14
Eindproject/TestHelper/TestHelper.csproj
Normal file
14
Eindproject/TestHelper/TestHelper.csproj
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<OutputType>Exe</OutputType>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<Import Project="..\..\SharedClientServer\SharedClientServer.projitems" Label="Shared" />
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
77
Eindproject/Tests/JSONConvertGetMessageToSendTest.cs
Normal file
77
Eindproject/Tests/JSONConvertGetMessageToSendTest.cs
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using SharedClientServer;
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Text;
|
||||||
|
using Xunit.Sdk;
|
||||||
|
|
||||||
|
namespace Tests
|
||||||
|
{
|
||||||
|
|
||||||
|
[TestClass]
|
||||||
|
public class JSONConvertGetMessageToSendTest
|
||||||
|
{
|
||||||
|
|
||||||
|
private byte[] testArray1()
|
||||||
|
{
|
||||||
|
byte identifier = 0x01;
|
||||||
|
dynamic payload = new
|
||||||
|
{
|
||||||
|
value = "test"
|
||||||
|
};
|
||||||
|
|
||||||
|
byte[] result = JSONConvert.GetMessageToSend(identifier, payload);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TestGetMessageToSendLength()
|
||||||
|
{
|
||||||
|
|
||||||
|
byte identifier = 0x01;
|
||||||
|
dynamic payload = new
|
||||||
|
{
|
||||||
|
value = "test"
|
||||||
|
};
|
||||||
|
string payloadToJson = JsonConvert.SerializeObject(payload);
|
||||||
|
byte[] payloadToBytes = Encoding.UTF8.GetBytes(payloadToJson);
|
||||||
|
|
||||||
|
byte[] result = JSONConvert.GetMessageToSend(identifier, payload);
|
||||||
|
Assert.AreEqual(payloadToBytes.Length + 5, result.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TestGetMessageToSendIdentifier()
|
||||||
|
{
|
||||||
|
byte[] result = testArray1();
|
||||||
|
Assert.AreEqual(0x01, result[4]);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TestGetMessageToSendMessageLength()
|
||||||
|
{
|
||||||
|
|
||||||
|
byte identifier = 0x01;
|
||||||
|
dynamic payload = new
|
||||||
|
{
|
||||||
|
value = "test"
|
||||||
|
};
|
||||||
|
|
||||||
|
string json = JsonConvert.SerializeObject(payload);
|
||||||
|
byte[] payloadBytes = Encoding.UTF8.GetBytes(json);
|
||||||
|
byte[] res = new byte[payloadBytes.Length + 5];
|
||||||
|
Array.Copy(payloadBytes, 0, res, 5, payloadBytes.Length);
|
||||||
|
res[4] = identifier;
|
||||||
|
Array.Copy(BitConverter.GetBytes(payloadBytes.Length + 5), 0, res, 0, 4);
|
||||||
|
int lengthTest = BitConverter.ToInt32(res, 0);
|
||||||
|
byte[] result = testArray1();
|
||||||
|
int lengthResult = BitConverter.ToInt32(result, 0);
|
||||||
|
|
||||||
|
Assert.AreEqual(lengthTest, lengthResult);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
59
Eindproject/Tests/JSONConvertRandomWord.cs
Normal file
59
Eindproject/Tests/JSONConvertRandomWord.cs
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using SharedClientServer;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Tests
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class JSONConvertRandomWord
|
||||||
|
{
|
||||||
|
public byte[] GetPayload(byte[] message)
|
||||||
|
{
|
||||||
|
byte[] payload = new byte[message.Length - 5];
|
||||||
|
Array.Copy(message, 5, payload, 0, message.Length - 5);
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte[] RandomWord()
|
||||||
|
{
|
||||||
|
byte identifier = 0x07;
|
||||||
|
dynamic payload = new
|
||||||
|
{
|
||||||
|
word = "teacher"
|
||||||
|
};
|
||||||
|
|
||||||
|
byte[] res = JSONConvert.GetMessageToSend(identifier, payload);
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public dynamic GetDynamic(byte[] payload)
|
||||||
|
{
|
||||||
|
return JsonConvert.DeserializeObject(Encoding.UTF8.GetString(GetPayload(payload)));
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TestSendRandomWord()
|
||||||
|
{
|
||||||
|
string randomWord = JSONConvert.SendRandomWord("WordsForGame.json");
|
||||||
|
|
||||||
|
string result = "teacher";
|
||||||
|
|
||||||
|
Assert.AreEqual(result, randomWord);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TestGetRandomWord()
|
||||||
|
{
|
||||||
|
byte[] data = GetPayload(RandomWord());
|
||||||
|
string result = JSONConvert.GetRandomWord(data);
|
||||||
|
|
||||||
|
string word = "teacher";
|
||||||
|
|
||||||
|
Assert.AreEqual(word, result);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
89
Eindproject/Tests/JSONConvertUserMessages.cs
Normal file
89
Eindproject/Tests/JSONConvertUserMessages.cs
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using SharedClientServer;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Text;
|
||||||
|
|
||||||
|
namespace Tests
|
||||||
|
{
|
||||||
|
[TestClass]
|
||||||
|
public class JSONConvertUserMessages
|
||||||
|
{
|
||||||
|
|
||||||
|
public byte[] GetPayload(byte[] message)
|
||||||
|
{
|
||||||
|
byte[] payload = new byte[message.Length - 5];
|
||||||
|
Array.Copy(message, 5, payload, 0, message.Length - 5);
|
||||||
|
return payload;
|
||||||
|
}
|
||||||
|
|
||||||
|
public dynamic GetDynamic(byte[] payload)
|
||||||
|
{
|
||||||
|
return JsonConvert.DeserializeObject(Encoding.UTF8.GetString(GetPayload(payload)));
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] ComboArray()
|
||||||
|
{
|
||||||
|
byte identifier = 0x02;
|
||||||
|
dynamic payload = new
|
||||||
|
{
|
||||||
|
username = "testName",
|
||||||
|
message = "message"
|
||||||
|
};
|
||||||
|
|
||||||
|
byte[] result = JSONConvert.GetMessageToSend(identifier, payload);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private byte[] LoginArray()
|
||||||
|
{
|
||||||
|
byte identifier = 0x01;
|
||||||
|
dynamic payload = new
|
||||||
|
{
|
||||||
|
username = "testname"
|
||||||
|
};
|
||||||
|
|
||||||
|
byte[] result = JSONConvert.GetMessageToSend(identifier, payload);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TestGetUsernameAndMessage()
|
||||||
|
{
|
||||||
|
byte[] data = GetPayload(ComboArray());
|
||||||
|
(string,string) result = JSONConvert.GetUsernameAndMessage(data);
|
||||||
|
|
||||||
|
(string, string) testCombo = ("testName", "message");
|
||||||
|
|
||||||
|
Assert.AreEqual(testCombo, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TestGetUsernameLogin()
|
||||||
|
{
|
||||||
|
byte[] data = GetPayload(LoginArray());
|
||||||
|
string result = JSONConvert.GetUsernameLogin(data);
|
||||||
|
string username = "testname";
|
||||||
|
|
||||||
|
Assert.AreEqual(username, result);
|
||||||
|
}
|
||||||
|
|
||||||
|
[TestMethod]
|
||||||
|
public void TestConstructUsernameMessage()
|
||||||
|
{
|
||||||
|
byte[] res = JSONConvert.ConstructUsernameMessage("testname");
|
||||||
|
dynamic payload = GetDynamic(res);
|
||||||
|
|
||||||
|
string username = "testname";
|
||||||
|
|
||||||
|
Assert.AreEqual(0x01, res[4]);
|
||||||
|
Assert.AreEqual(username, (string)payload.username);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
35
Eindproject/Tests/Tests.csproj
Normal file
35
Eindproject/Tests/Tests.csproj
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
<Project Sdk="Microsoft.NET.Sdk">
|
||||||
|
|
||||||
|
<PropertyGroup>
|
||||||
|
<TargetFramework>netcoreapp3.1</TargetFramework>
|
||||||
|
|
||||||
|
<IsPackable>false</IsPackable>
|
||||||
|
</PropertyGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<None Remove="resources\WordsForGame.json" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Content Include="resources\WordsForGame.json">
|
||||||
|
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||||
|
</Content>
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Extended.Wpf.Toolkit" Version="4.0.1" />
|
||||||
|
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
|
||||||
|
<PackageReference Include="MSTest.TestAdapter" Version="2.1.2" />
|
||||||
|
<PackageReference Include="MSTest.TestFramework" Version="2.1.2" />
|
||||||
|
<PackageReference Include="coverlet.collector" Version="1.3.0">
|
||||||
|
<PrivateAssets>all</PrivateAssets>
|
||||||
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
|
</PackageReference>
|
||||||
|
<PackageReference Include="xunit.extensibility.execution" Version="2.4.1" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<ProjectReference Include="..\..\Client\Client.csproj" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
</Project>
|
||||||
31
Eindproject/Tests/resources/WordsForGame.json
Normal file
31
Eindproject/Tests/resources/WordsForGame.json
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"filename": "wordsForGame",
|
||||||
|
"words": [
|
||||||
|
"teacher",
|
||||||
|
"love",
|
||||||
|
"engineer",
|
||||||
|
"supermarket",
|
||||||
|
"disaster",
|
||||||
|
"studio",
|
||||||
|
"restaurant",
|
||||||
|
"music",
|
||||||
|
"chocolate",
|
||||||
|
"dirt",
|
||||||
|
"thought",
|
||||||
|
"virus",
|
||||||
|
"lieutenant",
|
||||||
|
"painter",
|
||||||
|
"kiwi",
|
||||||
|
"power ranger",
|
||||||
|
"computer",
|
||||||
|
"people",
|
||||||
|
"candidate",
|
||||||
|
"security guard",
|
||||||
|
"Canada",
|
||||||
|
"teeth",
|
||||||
|
"army",
|
||||||
|
"airport",
|
||||||
|
"president",
|
||||||
|
"bedroom"
|
||||||
|
]
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ using System.Net.Sockets;
|
|||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using System.Timers;
|
||||||
using static SharedClientServer.JSONConvert;
|
using static SharedClientServer.JSONConvert;
|
||||||
|
|
||||||
namespace Server.Models
|
namespace Server.Models
|
||||||
@@ -22,7 +23,9 @@ namespace Server.Models
|
|||||||
private NetworkStream stream;
|
private NetworkStream stream;
|
||||||
private byte[] buffer = new byte[2048];
|
private byte[] buffer = new byte[2048];
|
||||||
private byte[] totalBuffer = new byte[2048];
|
private byte[] totalBuffer = new byte[2048];
|
||||||
|
private string _randomWord = "";
|
||||||
private int totalBufferReceived = 0;
|
private int totalBufferReceived = 0;
|
||||||
|
private Dictionary<System.Timers.Timer, int> lobbyTimers;
|
||||||
public User User { get; set; }
|
public User User { get; set; }
|
||||||
private ServerCommunication serverCom = ServerCommunication.INSTANCE;
|
private ServerCommunication serverCom = ServerCommunication.INSTANCE;
|
||||||
private Callback OnMessageReceivedOk;
|
private Callback OnMessageReceivedOk;
|
||||||
@@ -34,6 +37,7 @@ namespace Server.Models
|
|||||||
/// <param name="client">the TcpClient object to use</param>
|
/// <param name="client">the TcpClient object to use</param>
|
||||||
public ServerClient(TcpClient client)
|
public ServerClient(TcpClient client)
|
||||||
{
|
{
|
||||||
|
lobbyTimers = new Dictionary<System.Timers.Timer, int>();
|
||||||
Debug.WriteLine("[SERVERCLIENT] making new instance and starting");
|
Debug.WriteLine("[SERVERCLIENT] making new instance and starting");
|
||||||
tcpClient = client;
|
tcpClient = client;
|
||||||
stream = tcpClient.GetStream();
|
stream = tcpClient.GetStream();
|
||||||
@@ -145,6 +149,11 @@ namespace Server.Models
|
|||||||
message = textMsg
|
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.
|
//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));
|
serverCom.SendToLobby(serverCom.GetLobbyForUser(User), JSONConvert.GetMessageToSend(JSONConvert.MESSAGE, packet));
|
||||||
break;
|
break;
|
||||||
@@ -167,13 +176,14 @@ namespace Server.Models
|
|||||||
coords = JSONConvert.getCoordinates(payload),
|
coords = JSONConvert.getCoordinates(payload),
|
||||||
color = JSONConvert.getCanvasDrawingColor(payload)
|
color = JSONConvert.getCanvasDrawingColor(payload)
|
||||||
};
|
};
|
||||||
serverCom.SendToLobby(serverCom.GetLobbyForUser(User),JSONConvert.GetMessageToSend(JSONConvert.CANVAS,canvasData));
|
//serverCom.SendToLobby(serverCom.GetLobbyForUser(User),JSONConvert.GetMessageToSend(JSONConvert.CANVAS,canvasData));
|
||||||
|
serverCom.SendCanvasDataToLobby(serverCom.GetLobbyForUser(User), User.Username, JSONConvert.GetMessageToSend(JSONConvert.CANVAS, canvasData));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case JSONConvert.CANVAS_RESET:
|
case JSONConvert.CANVAS_RESET:
|
||||||
dynamic canvasDataForReset = new
|
dynamic canvasDataForReset = new
|
||||||
{
|
{
|
||||||
type = JSONConvert.GetCanvasMessageType(payload)
|
canvasType = JSONConvert.GetCanvasMessageType(payload)
|
||||||
};
|
};
|
||||||
serverCom.SendToLobby(serverCom.GetLobbyForUser(User), JSONConvert.GetMessageToSend(CANVAS, canvasDataForReset));
|
serverCom.SendToLobby(serverCom.GetLobbyForUser(User), JSONConvert.GetMessageToSend(CANVAS, canvasDataForReset));
|
||||||
break;
|
break;
|
||||||
@@ -186,14 +196,35 @@ namespace Server.Models
|
|||||||
|
|
||||||
case JSONConvert.GAME:
|
case JSONConvert.GAME:
|
||||||
Debug.WriteLine("[SERVERCLIENT] Got a message about the game logic");
|
Debug.WriteLine("[SERVERCLIENT] Got a message about the game logic");
|
||||||
string command = JSONConvert.GetGameCommand(payload);
|
GameCommand command = JSONConvert.GetGameCommand(payload);
|
||||||
switch (command)
|
switch (command)
|
||||||
{
|
{
|
||||||
case "startGame":
|
case GameCommand.START_GAME:
|
||||||
int lobbyID = JSONConvert.GetStartGameLobbyID(payload);
|
int lobbyID = JSONConvert.GetStartGameLobbyID(payload);
|
||||||
serverCom.CloseALobby(lobbyID);
|
serverCom.CloseALobby(lobbyID);
|
||||||
|
//todo start a timer for this lobby
|
||||||
|
Debug.WriteLine("[SERVERCLIENT] making timer for lobby " + lobbyID);
|
||||||
|
System.Timers.Timer lobbyTimer = new System.Timers.Timer(60 * 1000);
|
||||||
|
this.lobbyTimers.Add(lobbyTimer, lobbyID);
|
||||||
|
lobbyTimer.Elapsed += LobbyTimer_Elapsed;
|
||||||
|
lobbyTimer.Start();
|
||||||
ServerCommunication.INSTANCE.sendToAll(JSONConvert.ConstructLobbyListMessage(ServerCommunication.INSTANCE.lobbies.ToArray()));
|
ServerCommunication.INSTANCE.sendToAll(JSONConvert.ConstructLobbyListMessage(ServerCommunication.INSTANCE.lobbies.ToArray()));
|
||||||
break;
|
break;
|
||||||
|
case GameCommand.TIMER_ELAPSED:
|
||||||
|
|
||||||
|
break;
|
||||||
|
case GameCommand.NEXT_ROUND:
|
||||||
|
// The next round has been started, so we can start the timer again
|
||||||
|
lobbyID = JSONConvert.GetLobbyID(payload);
|
||||||
|
foreach (System.Timers.Timer timer in lobbyTimers.Keys)
|
||||||
|
{
|
||||||
|
if (lobbyTimers[timer] == lobbyID)
|
||||||
|
{
|
||||||
|
timer.Start();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -211,6 +242,17 @@ namespace Server.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void LobbyTimer_Elapsed(object sender, ElapsedEventArgs e)
|
||||||
|
{
|
||||||
|
System.Timers.Timer timer = sender as System.Timers.Timer;
|
||||||
|
int lobbyID = lobbyTimers[timer];
|
||||||
|
Debug.WriteLine("[SERVERCLIENT] timer elapsed for lobby " + lobbyID);
|
||||||
|
serverCom.SendToLobby(lobbyID, JSONConvert.ConstructGameTimerElapsedMessage(lobbyID));
|
||||||
|
timer.Stop();
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private void handleLobbyMessage(byte[] payload, LobbyIdentifier l)
|
private void handleLobbyMessage(byte[] payload, LobbyIdentifier l)
|
||||||
{
|
{
|
||||||
switch (l)
|
switch (l)
|
||||||
@@ -234,11 +276,11 @@ namespace Server.Models
|
|||||||
ServerCommunication.INSTANCE.sendToAll(JSONConvert.ConstructLobbyListMessage(ServerCommunication.INSTANCE.lobbies.ToArray()));
|
ServerCommunication.INSTANCE.sendToAll(JSONConvert.ConstructLobbyListMessage(ServerCommunication.INSTANCE.lobbies.ToArray()));
|
||||||
OnMessageReceivedOk = () =>
|
OnMessageReceivedOk = () =>
|
||||||
{
|
{
|
||||||
|
_randomWord = JSONConvert.SendRandomWord("WordsForGame.json");
|
||||||
serverCom.sendToAll(JSONConvert.GetMessageToSend(JSONConvert.RANDOMWORD, new
|
serverCom.sendToAll(JSONConvert.GetMessageToSend(JSONConvert.RANDOMWORD, new
|
||||||
{
|
{
|
||||||
id = serverCom.GetLobbyForUser(User).ID,
|
id = serverCom.GetLobbyForUser(User).ID,
|
||||||
word = JSONConvert.SendRandomWord("WordsForGame.json")
|
word = _randomWord
|
||||||
}));
|
}));
|
||||||
OnMessageReceivedOk = null;
|
OnMessageReceivedOk = null;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -142,7 +142,7 @@ namespace Server.Models
|
|||||||
{
|
{
|
||||||
foreach (ServerClient sc in serverClientsInlobbies[l])
|
foreach (ServerClient sc in serverClientsInlobbies[l])
|
||||||
{
|
{
|
||||||
Debug.WriteLine("[SERVERCLIENT] Sending message");
|
Debug.WriteLine("[SERVERCLIENT] Sending message to lobby");
|
||||||
sc.sendMessage(message);
|
sc.sendMessage(message);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
@@ -150,6 +150,22 @@ namespace Server.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SendToLobby(int lobbyID, byte[] message)
|
||||||
|
{
|
||||||
|
foreach (Lobby l in lobbies)
|
||||||
|
{
|
||||||
|
if (l.ID == lobbyID)
|
||||||
|
{
|
||||||
|
foreach (ServerClient sc in serverClientsInlobbies[l])
|
||||||
|
{
|
||||||
|
Debug.WriteLine("[SERVERCLIENT] Sending message to lobby");
|
||||||
|
sc.sendMessage(message);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void SendCanvasDataToLobby(Lobby lobby, string username, byte[] message)
|
public void SendCanvasDataToLobby(Lobby lobby, string username, byte[] message)
|
||||||
{
|
{
|
||||||
foreach (Lobby l in lobbies)
|
foreach (Lobby l in lobbies)
|
||||||
@@ -158,7 +174,8 @@ namespace Server.Models
|
|||||||
{
|
{
|
||||||
foreach (ServerClient sc in serverClientsInlobbies[l])
|
foreach (ServerClient sc in serverClientsInlobbies[l])
|
||||||
{
|
{
|
||||||
sc.sendMessage(message);
|
if (sc.User.Username != username)
|
||||||
|
sc.sendMessage(message);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -261,6 +278,10 @@ namespace Server.Models
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (l.Users.Count != 0)
|
||||||
|
{
|
||||||
|
l.Users[0].Host = true;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,15 @@
|
|||||||
using Client;
|
using Client;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Linq;
|
using Newtonsoft.Json.Linq;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Diagnostics;
|
||||||
using System.Diagnostics;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Text;
|
||||||
using System.Text;
|
using System.Windows.Media;
|
||||||
using System.Windows.Media;
|
|
||||||
|
|
||||||
namespace SharedClientServer
|
namespace SharedClientServer
|
||||||
{
|
{
|
||||||
class JSONConvert
|
public class JSONConvert
|
||||||
{
|
{
|
||||||
public const byte LOGIN = 0x01;
|
public const byte LOGIN = 0x01;
|
||||||
public const byte MESSAGE = 0x02;
|
public const byte MESSAGE = 0x02;
|
||||||
@@ -23,7 +21,6 @@ namespace SharedClientServer
|
|||||||
|
|
||||||
public const int CANVAS_WRITING = 0;
|
public const int CANVAS_WRITING = 0;
|
||||||
public const int CANVAS_RESET = 1;
|
public const int CANVAS_RESET = 1;
|
||||||
|
|
||||||
|
|
||||||
public enum LobbyIdentifier
|
public enum LobbyIdentifier
|
||||||
{
|
{
|
||||||
@@ -35,14 +32,29 @@ namespace SharedClientServer
|
|||||||
REQUEST
|
REQUEST
|
||||||
}
|
}
|
||||||
|
|
||||||
public static (string,string) GetUsernameAndMessage(byte[] json)
|
public enum GameCommand
|
||||||
|
{
|
||||||
|
START_GAME,
|
||||||
|
TIMER_ELAPSED,
|
||||||
|
NEXT_ROUND
|
||||||
|
}
|
||||||
|
|
||||||
|
public static (string, string) GetUsernameAndMessage(byte[] json)
|
||||||
{
|
{
|
||||||
string msg = Encoding.UTF8.GetString(json);
|
string msg = Encoding.UTF8.GetString(json);
|
||||||
dynamic payload = JsonConvert.DeserializeObject(msg);
|
dynamic payload = JsonConvert.DeserializeObject(msg);
|
||||||
|
|
||||||
return (payload.username, payload.message);
|
return (payload.username, payload.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static byte[] ConstructCanvasResetMessage()
|
||||||
|
{
|
||||||
|
return GetMessageToSend(CANVAS, new
|
||||||
|
{
|
||||||
|
canvasType = CANVAS_RESET
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
public static string GetUsernameLogin(byte[] json)
|
public static string GetUsernameLogin(byte[] json)
|
||||||
{
|
{
|
||||||
dynamic payload = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(json));
|
dynamic payload = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(json));
|
||||||
@@ -73,7 +85,7 @@ namespace SharedClientServer
|
|||||||
{
|
{
|
||||||
identifier = LobbyIdentifier.HOST,
|
identifier = LobbyIdentifier.HOST,
|
||||||
id = lobbyID
|
id = lobbyID
|
||||||
}) ;
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static byte[] ConstructLobbyRequestMessage()
|
public static byte[] ConstructLobbyRequestMessage()
|
||||||
@@ -87,13 +99,12 @@ namespace SharedClientServer
|
|||||||
public static byte[] ConstructLobbyListMessage(Lobby[] lobbiesList)
|
public static byte[] ConstructLobbyListMessage(Lobby[] lobbiesList)
|
||||||
{
|
{
|
||||||
return GetMessageToSend(LOBBY, new
|
return GetMessageToSend(LOBBY, new
|
||||||
{
|
{
|
||||||
identifier = LobbyIdentifier.LIST,
|
identifier = LobbyIdentifier.LIST,
|
||||||
lobbies = lobbiesList
|
lobbies = lobbiesList
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static byte[] ConstructLobbyJoinMessage(int lobbyID)
|
public static byte[] ConstructLobbyJoinMessage(int lobbyID)
|
||||||
{
|
{
|
||||||
return GetMessageToSend(LOBBY, new
|
return GetMessageToSend(LOBBY, new
|
||||||
@@ -110,7 +121,8 @@ namespace SharedClientServer
|
|||||||
identifier = LobbyIdentifier.LEAVE,
|
identifier = LobbyIdentifier.LEAVE,
|
||||||
id = lobbyID
|
id = lobbyID
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static LobbyIdentifier GetLobbyIdentifier(byte[] json)
|
public static LobbyIdentifier GetLobbyIdentifier(byte[] json)
|
||||||
{
|
{
|
||||||
dynamic payload = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(json));
|
dynamic payload = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(json));
|
||||||
@@ -146,8 +158,11 @@ namespace SharedClientServer
|
|||||||
|
|
||||||
public static byte[] ConstructLobbyJoinSuccessMessage(bool isHost)
|
public static byte[] ConstructLobbyJoinSuccessMessage(bool isHost)
|
||||||
{
|
{
|
||||||
return GetMessageToSend(LOBBY, new { identifier = LobbyIdentifier.JOIN_SUCCESS,
|
return GetMessageToSend(LOBBY, new
|
||||||
host = isHost});
|
{
|
||||||
|
identifier = LobbyIdentifier.JOIN_SUCCESS,
|
||||||
|
host = isHost
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool GetLobbyJoinIsHost(byte[] json)
|
public static bool GetLobbyJoinIsHost(byte[] json)
|
||||||
@@ -156,11 +171,10 @@ namespace SharedClientServer
|
|||||||
return payload.host;
|
return payload.host;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion lobby messages
|
||||||
|
|
||||||
public static byte[] ConstructCanvasDataSend(int typeToSend, double[][] buffer, Color colorToSend)
|
public static byte[] ConstructCanvasDataSend(int typeToSend, double[][] buffer, Color colorToSend)
|
||||||
{
|
{
|
||||||
|
|
||||||
return GetMessageToSend(CANVAS, new
|
return GetMessageToSend(CANVAS, new
|
||||||
{
|
{
|
||||||
canvasType = typeToSend,
|
canvasType = typeToSend,
|
||||||
@@ -177,6 +191,15 @@ namespace SharedClientServer
|
|||||||
coords = buffer,
|
coords = buffer,
|
||||||
color = colorToSend
|
color = colorToSend
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static byte[] ConstructCanvasReset()
|
||||||
|
{
|
||||||
|
dynamic payload = new
|
||||||
|
{
|
||||||
|
canvasType = CANVAS_RESET
|
||||||
|
};
|
||||||
|
return GetMessageToSend(CANVAS, payload);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int GetCanvasMessageType(byte[] json)
|
public static int GetCanvasMessageType(byte[] json)
|
||||||
@@ -205,15 +228,23 @@ namespace SharedClientServer
|
|||||||
|
|
||||||
public static byte[] ConstructGameStartData(int lobbyID)
|
public static byte[] ConstructGameStartData(int lobbyID)
|
||||||
{
|
{
|
||||||
string startGame = "startGame";
|
|
||||||
return GetMessageToSend(GAME, new
|
return GetMessageToSend(GAME, new
|
||||||
{
|
{
|
||||||
command = startGame,
|
command = GameCommand.START_GAME,
|
||||||
lobbyToStart = lobbyID
|
lobbyToStart = lobbyID
|
||||||
}); ;
|
}); ;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetGameCommand(byte[] payload)
|
public static byte[] ConstructGameTimerElapsedMessage(int lobbyID)
|
||||||
|
{
|
||||||
|
return GetMessageToSend(GAME, new
|
||||||
|
{
|
||||||
|
command = GameCommand.TIMER_ELAPSED,
|
||||||
|
id = lobbyID
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public static GameCommand GetGameCommand(byte[] payload)
|
||||||
{
|
{
|
||||||
dynamic json = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(payload));
|
dynamic json = JsonConvert.DeserializeObject(Encoding.UTF8.GetString(payload));
|
||||||
return json.command;
|
return json.command;
|
||||||
@@ -243,13 +274,14 @@ namespace SharedClientServer
|
|||||||
// put the identifier at the start of the payload part
|
// put the identifier at the start of the payload part
|
||||||
res[4] = identifier;
|
res[4] = identifier;
|
||||||
// put the length of the payload at the start of the res array
|
// put the length of the payload at the start of the res array
|
||||||
Array.Copy(BitConverter.GetBytes(payloadBytes.Length+5),0,res,0,4);
|
Array.Copy(BitConverter.GetBytes(payloadBytes.Length + 5), 0, res, 0, 4);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This method sends a random word from the json file, this happens when the client joins a lobby.
|
* This method sends a random word from the json file, this happens when the client joins a lobby.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static string SendRandomWord(string filename)
|
public static string SendRandomWord(string filename)
|
||||||
{
|
{
|
||||||
dynamic words;
|
dynamic words;
|
||||||
@@ -258,29 +290,27 @@ namespace SharedClientServer
|
|||||||
string projDir = Directory.GetParent(workingDir).Parent.Parent.FullName;
|
string projDir = Directory.GetParent(workingDir).Parent.Parent.FullName;
|
||||||
string filePath = projDir += $@"\resources\{filename}";
|
string filePath = projDir += $@"\resources\{filename}";
|
||||||
|
|
||||||
using(StreamReader reader = new StreamReader(filePath))
|
using (StreamReader reader = new StreamReader(filePath))
|
||||||
{
|
{
|
||||||
string json = reader.ReadToEnd();
|
string json = reader.ReadToEnd();
|
||||||
words = JsonConvert.DeserializeObject(json);
|
words = JsonConvert.DeserializeObject(json);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int index = random.Next(0, 24);
|
int index = random.Next(0, 24);
|
||||||
|
|
||||||
Debug.WriteLine($"[SERVERCLIENT] Sending random words {words}");
|
Debug.WriteLine($"[SERVERCLIENT] Sending random words {words}");
|
||||||
|
|
||||||
return words.words[index];
|
return words.words[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Client gets the payload and retrieves the word from the payload
|
* Client gets the payload and retrieves the word from the payload
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static string GetRandomWord(byte[] json)
|
public static string GetRandomWord(byte[] json)
|
||||||
{
|
{
|
||||||
dynamic payload = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json));
|
dynamic payload = JsonConvert.DeserializeObject(Encoding.ASCII.GetString(json));
|
||||||
return payload.word;
|
return payload.word;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,7 @@ using System.Text;
|
|||||||
|
|
||||||
namespace Client
|
namespace Client
|
||||||
{
|
{
|
||||||
internal class Lobby : INotifyPropertyChanged
|
public class Lobby : INotifyPropertyChanged
|
||||||
{
|
{
|
||||||
public event PropertyChangedEventHandler PropertyChanged;
|
public event PropertyChangedEventHandler PropertyChanged;
|
||||||
|
|
||||||
|
|||||||
@@ -10,4 +10,4 @@
|
|||||||
<PropertyGroup />
|
<PropertyGroup />
|
||||||
<Import Project="SharedClientServer.projitems" Label="Shared" />
|
<Import Project="SharedClientServer.projitems" Label="Shared" />
|
||||||
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
|
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\CodeSharing\Microsoft.CodeSharing.CSharp.targets" />
|
||||||
</Project>
|
</Project>
|
||||||
@@ -6,13 +6,14 @@ using System.Text;
|
|||||||
|
|
||||||
namespace SharedClientServer
|
namespace SharedClientServer
|
||||||
{
|
{
|
||||||
class User : IEquatable<User>
|
public class User : IEquatable<User>
|
||||||
{
|
{
|
||||||
private string _username;
|
private string _username;
|
||||||
private int _score;
|
private int _score;
|
||||||
private bool _host;
|
private bool _host;
|
||||||
private bool _turnToDraw;
|
private bool _turnToDraw;
|
||||||
private string _message;
|
private string _message;
|
||||||
|
private string _randomWord;
|
||||||
|
|
||||||
[JsonConstructor]
|
[JsonConstructor]
|
||||||
public User(string username, int score, bool host, bool turnToDraw)
|
public User(string username, int score, bool host, bool turnToDraw)
|
||||||
@@ -90,5 +91,10 @@ namespace SharedClientServer
|
|||||||
get { return _turnToDraw; }
|
get { return _turnToDraw; }
|
||||||
set { _turnToDraw = value; }
|
set { _turnToDraw = value; }
|
||||||
}
|
}
|
||||||
|
public string RandomWord
|
||||||
|
{
|
||||||
|
get { return _randomWord; }
|
||||||
|
set { _randomWord = value; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user