wpf sucks v2
This commit is contained in:
@@ -22,11 +22,13 @@ namespace Client
|
|||||||
public Client()
|
public Client()
|
||||||
{
|
{
|
||||||
this.tcpClient = new TcpClient();
|
this.tcpClient = new TcpClient();
|
||||||
|
Debug.WriteLine("Starting connect to server");
|
||||||
tcpClient.BeginConnect("localhost", Port, new AsyncCallback(OnConnect), null);
|
tcpClient.BeginConnect("localhost", Port, new AsyncCallback(OnConnect), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnConnect(IAsyncResult ar)
|
private void OnConnect(IAsyncResult ar)
|
||||||
{
|
{
|
||||||
|
Debug.Write("finished connecting to server");
|
||||||
this.tcpClient.EndConnect(ar);
|
this.tcpClient.EndConnect(ar);
|
||||||
this.stream = tcpClient.GetStream();
|
this.stream = tcpClient.GetStream();
|
||||||
this.stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnReadComplete),null);
|
this.stream.BeginRead(buffer, 0, buffer.Length, new AsyncCallback(OnReadComplete),null);
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ namespace Client
|
|||||||
_model = new Model();
|
_model = new Model();
|
||||||
ButtonCommand = new RelayCommand(() =>
|
ButtonCommand = new RelayCommand(() =>
|
||||||
{
|
{
|
||||||
ClickCheck();
|
Client client = new Client();
|
||||||
});
|
});
|
||||||
|
|
||||||
_lobbies = new List<Lobby>();
|
_lobbies = new List<Lobby>();
|
||||||
|
|||||||
@@ -17,6 +17,6 @@ namespace Server.Models
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int ClientsConnected{ get { return ServerCommunication.INSTANCE.ClientsConnected; } }
|
public int ClientsConnected{ get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -15,9 +15,10 @@ namespace Server.Models
|
|||||||
private TcpListener listener;
|
private TcpListener listener;
|
||||||
private List<ServerClient> serverClients;
|
private List<ServerClient> serverClients;
|
||||||
public bool Started = false;
|
public bool Started = false;
|
||||||
public int ClientsConnected { get { return serverClients.Count; } }
|
|
||||||
public List<Lobby> lobbies;
|
public List<Lobby> lobbies;
|
||||||
private Dictionary<Lobby, List<ServerClient>> serverClientsInlobbies;
|
private Dictionary<Lobby, List<ServerClient>> serverClientsInlobbies;
|
||||||
|
public int ClientsConnected { get; set; }
|
||||||
|
public Action newClientAction;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// use a padlock object to make sure the singleton is thread-safe
|
/// use a padlock object to make sure the singleton is thread-safe
|
||||||
@@ -33,6 +34,7 @@ namespace Server.Models
|
|||||||
serverClients = new List<ServerClient>();
|
serverClients = new List<ServerClient>();
|
||||||
lobbies = new List<Lobby>();
|
lobbies = new List<Lobby>();
|
||||||
serverClientsInlobbies = new Dictionary<Lobby, List<ServerClient>>();
|
serverClientsInlobbies = new Dictionary<Lobby, List<ServerClient>>();
|
||||||
|
ClientsConnected = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -62,6 +64,7 @@ namespace Server.Models
|
|||||||
Debug.WriteLine($"================================================\nStarted Accepting clients at {DateTime.Now}\n================================================");
|
Debug.WriteLine($"================================================\nStarted Accepting clients at {DateTime.Now}\n================================================");
|
||||||
Started = true;
|
Started = true;
|
||||||
// when we have accepted a tcp client, call the onclientconnected callback method
|
// when we have accepted a tcp client, call the onclientconnected callback method
|
||||||
|
|
||||||
listener.BeginAcceptTcpClient(new AsyncCallback(OnClientConnected), null);
|
listener.BeginAcceptTcpClient(new AsyncCallback(OnClientConnected), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -72,10 +75,12 @@ namespace Server.Models
|
|||||||
private void OnClientConnected(IAsyncResult ar)
|
private void OnClientConnected(IAsyncResult ar)
|
||||||
{
|
{
|
||||||
// stop the acceptation
|
// stop the acceptation
|
||||||
TcpClient tcpClient = listener.EndAcceptTcpClient(ar);
|
var tcpClient = listener.EndAcceptTcpClient(ar);
|
||||||
Console.WriteLine($"Got connection from {tcpClient.Client.RemoteEndPoint}");
|
Debug.WriteLine($"Got connection from {tcpClient.Client.RemoteEndPoint}");
|
||||||
|
newClientAction.Invoke();
|
||||||
// create a new serverclient object and add it to the list
|
// create a new serverclient object and add it to the list
|
||||||
serverClients.Add(new ServerClient(tcpClient));
|
serverClients.Add(new ServerClient(tcpClient));
|
||||||
|
ClientsConnected++;
|
||||||
//start listening for new tcp clients
|
//start listening for new tcp clients
|
||||||
listener.BeginAcceptTcpClient(new AsyncCallback(OnClientConnected), null);
|
listener.BeginAcceptTcpClient(new AsyncCallback(OnClientConnected), null);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ namespace Server.ViewModels
|
|||||||
{
|
{
|
||||||
class MainViewModel : ObservableObject
|
class MainViewModel : ObservableObject
|
||||||
{
|
{
|
||||||
private ServerCommunication serverCommunication;
|
public ServerCommunication serverCommunication { get; set; }
|
||||||
public ICommand ServerStartCommand { get; set; }
|
public ICommand ServerStartCommand { get; set; }
|
||||||
public Information InformationModel { get; set; }
|
public Information InformationModel { get; set; }
|
||||||
private MainWindow mainWindow;
|
private MainWindow mainWindow;
|
||||||
@@ -28,6 +28,11 @@ namespace Server.ViewModels
|
|||||||
InformationModel = new Information();
|
InformationModel = new Information();
|
||||||
InformationModel.CanStartServer = true;
|
InformationModel.CanStartServer = true;
|
||||||
InformationModel.ServerOnline = false;
|
InformationModel.ServerOnline = false;
|
||||||
|
InformationModel.ClientsConnected = 0;
|
||||||
|
serverCommunication.newClientAction = () =>
|
||||||
|
{
|
||||||
|
InformationModel.ClientsConnected++;
|
||||||
|
};
|
||||||
//BitmapImage onlineImg = new BitmapImage(new Uri(@"/img/online.png",UriKind.Relative));
|
//BitmapImage onlineImg = new BitmapImage(new Uri(@"/img/online.png",UriKind.Relative));
|
||||||
//BitmapImage offlineImg = new BitmapImage(new Uri(@"/img/offline.png", UriKind.Relative));
|
//BitmapImage offlineImg = new BitmapImage(new Uri(@"/img/offline.png", UriKind.Relative));
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user