Compare commits
12 Commits
lobbies
...
feature/se
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
35ded2b5ea | ||
|
|
0f01354b72 | ||
|
|
61577e0df7 | ||
|
|
298bd760e5 | ||
|
|
c4c97a3fbe | ||
|
|
a4e45b1a6b | ||
|
|
4f07eeb95a | ||
|
|
74f8e868f6 | ||
|
|
381c142eaa | ||
|
|
2aeca40aa4 | ||
|
|
4d161391b1 | ||
|
|
7dbdcc8bcc |
@@ -72,14 +72,15 @@ namespace Client
|
||||
}
|
||||
|
||||
stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnReadComplete), null);
|
||||
|
||||
}
|
||||
|
||||
private void handleData(byte[] message)
|
||||
{
|
||||
byte id = message[4];
|
||||
|
||||
byte[] payload = new byte[message.Length - 5];
|
||||
Array.Copy(message, 5, payload, 0, message.Length - 5);
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case JSONConvert.LOGIN:
|
||||
@@ -90,8 +91,10 @@ namespace Client
|
||||
(string, string) combo = JSONConvert.GetUsernameAndMessage(payload);
|
||||
string textUsername = combo.Item1;
|
||||
string textMsg = combo.Item2;
|
||||
//TODO display username and message in chat window
|
||||
|
||||
//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);
|
||||
break;
|
||||
|
||||
case JSONConvert.LOBBY:
|
||||
@@ -118,9 +121,11 @@ namespace Client
|
||||
}
|
||||
//TODO fill lobby with the data received
|
||||
break;
|
||||
|
||||
case JSONConvert.CANVAS:
|
||||
// canvas data
|
||||
break;
|
||||
|
||||
default:
|
||||
Debug.WriteLine("[CLIENT] Received weird identifier: " + id);
|
||||
break;
|
||||
|
||||
@@ -30,6 +30,7 @@ namespace Client
|
||||
private User _user;
|
||||
private Client _client;
|
||||
private Lobby _lobby;
|
||||
private string _message;
|
||||
|
||||
private ClientData()
|
||||
{
|
||||
@@ -55,5 +56,17 @@ namespace Client
|
||||
set { _lobby = value; }
|
||||
}
|
||||
|
||||
public String Message
|
||||
{
|
||||
get
|
||||
{
|
||||
return _message;
|
||||
}
|
||||
set
|
||||
{
|
||||
_message = value;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,126 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
|
||||
namespace Client.ViewModels
|
||||
{
|
||||
class ViewModelGame : INotifyPropertyChanged
|
||||
{
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
}
|
||||
}
|
||||
|
||||
using Client.Views;
|
||||
using GalaSoft.MvvmLight.Command;
|
||||
using SharedClientServer;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Shapes;
|
||||
|
||||
namespace Client.ViewModels
|
||||
{
|
||||
class ViewModelGame : INotifyPropertyChanged
|
||||
{
|
||||
private ClientData data = ClientData.Instance;
|
||||
|
||||
public event PropertyChangedEventHandler PropertyChanged;
|
||||
|
||||
private Point currentPoint = new Point();
|
||||
private Color color;
|
||||
|
||||
public ObservableCollection<string> Messages { get; } = new ObservableCollection<string>();
|
||||
|
||||
private dynamic _payload;
|
||||
|
||||
private string _username;
|
||||
|
||||
private string _message;
|
||||
public string Message
|
||||
{
|
||||
get
|
||||
{
|
||||
return _message;
|
||||
}
|
||||
set
|
||||
{
|
||||
_message = value;
|
||||
}
|
||||
}
|
||||
public ICommand OnKeyDown { get; set; }
|
||||
|
||||
public void Canvas_MouseDown(MouseButtonEventArgs e, GameWindow window)
|
||||
{
|
||||
if (e.ButtonState == MouseButtonState.Pressed)
|
||||
{
|
||||
currentPoint = e.GetPosition(window.CanvasForPaint);
|
||||
}
|
||||
}
|
||||
|
||||
public void Canvas_MouseMove(MouseEventArgs e, GameWindow window)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
double[] coordinates = new double[4];
|
||||
Line line = new Line();
|
||||
|
||||
line.Stroke = new SolidColorBrush(color);
|
||||
//line.Stroke = SystemColors.WindowFrameBrush;
|
||||
line.X1 = currentPoint.X;
|
||||
line.Y1 = currentPoint.Y;
|
||||
line.X2 = e.GetPosition(window.CanvasForPaint).X;
|
||||
line.Y2 = e.GetPosition(window.CanvasForPaint).Y;
|
||||
coordinates[0] = line.X1;
|
||||
coordinates[1] = line.Y1;
|
||||
coordinates[2] = line.X2;
|
||||
coordinates[3] = line.Y2;
|
||||
currentPoint = e.GetPosition(window.CanvasForPaint);
|
||||
|
||||
window.CanvasForPaint.Children.Add(line);
|
||||
data.Client.SendMessage(JSONConvert.GetMessageToSend(0x04, coordinates));
|
||||
}
|
||||
}
|
||||
|
||||
public void Color_Picker(RoutedPropertyChangedEventArgs<Color?> e, GameWindow window)
|
||||
{
|
||||
Color colorSelected = new Color();
|
||||
colorSelected.A = 255;
|
||||
colorSelected.R = window.ClrPcker_Background.SelectedColor.Value.R;
|
||||
colorSelected.G = window.ClrPcker_Background.SelectedColor.Value.G;
|
||||
colorSelected.B = window.ClrPcker_Background.SelectedColor.Value.B;
|
||||
color = colorSelected;
|
||||
}
|
||||
|
||||
|
||||
public ViewModelGame()
|
||||
{
|
||||
if (_payload == null)
|
||||
{
|
||||
_message = "";
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
//_message = data.Message;
|
||||
//_username = data.User.Username;
|
||||
//Messages.Add($"{data.User.Username}: {Message}");
|
||||
}
|
||||
OnKeyDown = new RelayCommand(ChatBox_KeyDown);
|
||||
}
|
||||
|
||||
private void ChatBox_KeyDown()
|
||||
{
|
||||
//if enter then clear textbox and send message.
|
||||
if (Message != string.Empty) AddMessage(Message);
|
||||
Message = string.Empty;
|
||||
}
|
||||
|
||||
internal void AddMessage(string message)
|
||||
{
|
||||
Messages.Add($"{data.User.Username}: {message}");
|
||||
|
||||
_payload = new
|
||||
{
|
||||
username = data.User.Username,
|
||||
message = message
|
||||
};
|
||||
|
||||
//Broadcast the message after adding it to the list!
|
||||
data.Client.SendMessage(JSONConvert.GetMessageToSend(JSONConvert.MESSAGE, _payload));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,8 +48,13 @@
|
||||
</Border>
|
||||
|
||||
<Grid Grid.Column="2" Grid.Row="1">
|
||||
<TextBox Name="SentMessage" IsReadOnly="True"/>
|
||||
<TextBox x:Name="ChatBox" Keyboard.KeyDown="ChatBox_KeyDown" Width="200" Height="50" ToolTip="Message goes here" ToolTipService.IsEnabled="True" VerticalAlignment="Bottom" HorizontalAlignment="Left"/>
|
||||
<ListBox Name ="TextBox" ItemsSource="{Binding Path=Messages}" Margin="0,0,0,69"/>
|
||||
|
||||
<TextBox Name="ChatBox" Text="{Binding Message, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Margin="0,465,0,0">
|
||||
<TextBox.InputBindings>
|
||||
<KeyBinding Key="Return" Command="{Binding OnKeyDown}"/>
|
||||
</TextBox.InputBindings>
|
||||
</TextBox>
|
||||
</Grid>
|
||||
|
||||
</Grid>
|
||||
|
||||
@@ -19,54 +19,24 @@ namespace Client.Views
|
||||
public partial class GameWindow : Window
|
||||
{
|
||||
ClientData data = ClientData.Instance;
|
||||
private ViewModelGame viewModel;
|
||||
public GameWindow()
|
||||
{
|
||||
DataContext = new ViewModelGame();
|
||||
this.viewModel = new ViewModelGame();
|
||||
DataContext = this.viewModel;
|
||||
InitializeComponent();
|
||||
|
||||
}
|
||||
Point currentPoint = new Point();
|
||||
|
||||
|
||||
private void CanvasForPaint_MouseDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if (e.ButtonState == MouseButtonState.Pressed)
|
||||
{
|
||||
currentPoint = e.GetPosition(CanvasForPaint);
|
||||
}
|
||||
|
||||
this.viewModel.Canvas_MouseDown(e, this);
|
||||
}
|
||||
|
||||
private void CanvasForPaint_MouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed)
|
||||
{
|
||||
Line line = new Line();
|
||||
|
||||
|
||||
line.Stroke = new SolidColorBrush(color);
|
||||
//line.Stroke = SystemColors.WindowFrameBrush;
|
||||
line.X1 = currentPoint.X;
|
||||
line.Y1 = currentPoint.Y;
|
||||
line.X2 = e.GetPosition(CanvasForPaint).X;
|
||||
line.Y2 = e.GetPosition(CanvasForPaint).Y;
|
||||
|
||||
currentPoint = e.GetPosition(CanvasForPaint);
|
||||
|
||||
CanvasForPaint.Children.Add(line);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Color color;
|
||||
|
||||
private void ClrPcker_Background_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs<Color> e)
|
||||
{
|
||||
Color colorSelected = new Color();
|
||||
colorSelected.A = 255;
|
||||
colorSelected.R = ClrPcker_Background.SelectedColor.Value.R;
|
||||
colorSelected.G = ClrPcker_Background.SelectedColor.Value.G;
|
||||
colorSelected.B = ClrPcker_Background.SelectedColor.Value.B;
|
||||
color = colorSelected;
|
||||
viewModel.Canvas_MouseMove(e, this);
|
||||
}
|
||||
|
||||
private void CanvasReset_Click(object sender, RoutedEventArgs e)
|
||||
@@ -82,41 +52,11 @@ namespace Client.Views
|
||||
// var deepCopy = System.Windows.Markup.XamlReader.Parse(xaml) as UIElement;
|
||||
// TEST.Children.Add(deepCopy);
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
private void ClrPcker_Background_SelectedColorChanged_1(object sender, RoutedPropertyChangedEventArgs<Color?> e)
|
||||
{
|
||||
Color colorSelected = new Color();
|
||||
colorSelected.A = 255;
|
||||
colorSelected.R = ClrPcker_Background.SelectedColor.Value.R;
|
||||
colorSelected.G = ClrPcker_Background.SelectedColor.Value.G;
|
||||
colorSelected.B = ClrPcker_Background.SelectedColor.Value.B;
|
||||
color = colorSelected;
|
||||
}
|
||||
|
||||
private void ChatBox_KeyDown(object sender, KeyEventArgs e)
|
||||
{
|
||||
//if enter then clear textbox and send message.
|
||||
if (e.Key.Equals(Key.Enter))
|
||||
{
|
||||
WriteToChat(ChatBox.Text);
|
||||
ChatBox.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Writes the current client's message to the chatbox.
|
||||
*/
|
||||
private void WriteToChat(string message)
|
||||
{
|
||||
string user = data.User.Username;
|
||||
SentMessage.AppendText($"{user}: {message}\n");
|
||||
}
|
||||
|
||||
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
{
|
||||
|
||||
viewModel.Color_Picker(e, this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,8 +32,6 @@ namespace Client
|
||||
|
||||
private void Button_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
|
||||
|
||||
using Client;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using SharedClientServer;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
@@ -18,6 +20,7 @@ namespace Server.Models
|
||||
private byte[] totalBuffer = new byte[1024];
|
||||
private int totalBufferReceived = 0;
|
||||
public User User { get; set; }
|
||||
private ServerCommunication serverCom = ServerCommunication.INSTANCE;
|
||||
|
||||
|
||||
/// <summary>
|
||||
@@ -84,6 +87,7 @@ namespace Server.Models
|
||||
// start reading for a new message
|
||||
stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnRead), null);
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -118,7 +122,11 @@ namespace Server.Models
|
||||
string textUsername = combo.Item1;
|
||||
string textMsg = combo.Item2;
|
||||
|
||||
Debug.WriteLine("[SERVERCLIENT] User name: {0}\t User message: {1}", textUsername, textMsg);
|
||||
|
||||
// todo handle sending to all except this user the username and message to display in chat
|
||||
serverCom.SendToLobby(ServerCommunication.INSTANCE.GetLobbyForUser(User),payload);
|
||||
Debug.WriteLine("Payload has been sent!");
|
||||
break;
|
||||
|
||||
case JSONConvert.LOBBY:
|
||||
@@ -127,6 +135,7 @@ namespace Server.Models
|
||||
handleLobbyMessage(payload,l);
|
||||
break;
|
||||
case JSONConvert.CANVAS:
|
||||
Debug.WriteLine("GOT A MESSAGE FROM THE CLIENT ABOUT THE CANVAS!!!");
|
||||
// canvas data
|
||||
// todo send canvas data to all other serverclients in lobby
|
||||
break;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
using Client;
|
||||
using Client;
|
||||
using SharedClientServer;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -18,6 +18,5 @@ namespace SharedClientServer
|
||||
Array.Copy(stringAsBytes, 0, res, 1, stringAsBytes.Length);
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@ namespace SharedClientServer
|
||||
private string _username;
|
||||
private int _score;
|
||||
private bool _host;
|
||||
private string _message;
|
||||
|
||||
[JsonConstructor]
|
||||
public User(string username, int score, bool host)
|
||||
|
||||
Reference in New Issue
Block a user