wpf sucks v2

This commit is contained in:
Sem van der Hoeven
2020-10-13 14:15:38 +02:00
parent fd3b926316
commit 245130a648
5 changed files with 18 additions and 6 deletions

View File

@@ -15,9 +15,10 @@ namespace Server.Models
private TcpListener listener;
private List<ServerClient> serverClients;
public bool Started = false;
public int ClientsConnected { get { return serverClients.Count; } }
public List<Lobby> lobbies;
private Dictionary<Lobby, List<ServerClient>> serverClientsInlobbies;
public int ClientsConnected { get; set; }
public Action newClientAction;
/// <summary>
/// use a padlock object to make sure the singleton is thread-safe
@@ -33,6 +34,7 @@ namespace Server.Models
serverClients = new List<ServerClient>();
lobbies = new List<Lobby>();
serverClientsInlobbies = new Dictionary<Lobby, List<ServerClient>>();
ClientsConnected = 0;
}
/// <summary>
@@ -62,6 +64,7 @@ namespace Server.Models
Debug.WriteLine($"================================================\nStarted Accepting clients at {DateTime.Now}\n================================================");
Started = true;
// when we have accepted a tcp client, call the onclientconnected callback method
listener.BeginAcceptTcpClient(new AsyncCallback(OnClientConnected), null);
}
@@ -72,10 +75,12 @@ namespace Server.Models
private void OnClientConnected(IAsyncResult ar)
{
// stop the acceptation
TcpClient tcpClient = listener.EndAcceptTcpClient(ar);
Console.WriteLine($"Got connection from {tcpClient.Client.RemoteEndPoint}");
var tcpClient = listener.EndAcceptTcpClient(ar);
Debug.WriteLine($"Got connection from {tcpClient.Client.RemoteEndPoint}");
newClientAction.Invoke();
// create a new serverclient object and add it to the list
serverClients.Add(new ServerClient(tcpClient));
ClientsConnected++;
//start listening for new tcp clients
listener.BeginAcceptTcpClient(new AsyncCallback(OnClientConnected), null);
}