public Expectant(ClientDialog client, TimeSpan timeControl, int wantedRating) { this.client = client; this.timeControl = timeControl; this.wantedRating = wantedRating; this.GetExpectantRating(); }
protected override void HandleClient(ClientDialog client) { try { while (true) { Message request = client.ReceiveMessage(); switch (request.Title) { case "AUTHENTICATE": if (UserConfiguration.LoginDataMatch((LoginUserData)request.Payload["LoginData"])) { client.Username = ((LoginUserData)request.Payload["LoginData"]).Username; } break; case "MESSAGE": string[] receivers_usernames = (string[])request.Payload["Receivers"]; ClientDialog[] receivers = new ClientDialog[receivers_usernames.Length]; for (int i = 0; i < receivers.Length; i++) { for (int j = 0; j < this.clients.Count; j++) { if (receivers_usernames[i] == this.clients[j].Username) { this.clients[j].SendMessage("MESSAGE", ("Sender", client.Username), ("Content", request.Payload["Message"])); } } } break; case "EXPECT": /*if (this.expectant == null) this.expectant = client; * else * { * this.expectant.SendMessage("MESSAGE", ("Sender", client.Username), ("Content", request.Payload["Message"])); * this.expectant = null; * } * break;*/ case "UNEXPECT": //if (this.expectant == client) this.expectant = null; break; case "DISCONNECT": client.Dispose(); throw new SocketException(); } } } catch (SocketException) { this.clients.Remove(client); } }
protected override void HandleClient(ClientDialog client) { IPEndPoint remoteIPEndPoint = client.Socket.RemoteEndPoint as IPEndPoint; Console.WriteLine($"Connection request from {client.IPEndPoint.Address}:{client.IPEndPoint.Port} has been accepted"); UserConfiguration userConfiguration = new UserConfiguration(client); try { while (true) { Message request = client.ReceiveMessage(); switch (request.Title) { case "SIGNUP": userConfiguration.SignUp((EditableUserData)request.Payload["EditableData"]); break; case "LOGIN": userConfiguration.LogIn((LoginUserData)request.Payload["LoginData"]); break; case "DISCONNECT": client.Dispose(); throw new SocketException(); } } } catch (Exception ex) when(ex is SocketException || ex is NullReferenceException) { if (client.Authenticated) { userConfiguration.MarkOffline(); } this.clients.Remove(client); Console.WriteLine($"{client.IPEndPoint.Address}:{client.IPEndPoint.Port} disconnected"); } }
private void BeginAcceptingClients() { Thread accepting = new Thread(() => { while (true) { Socket socket = this.tcpListener.AcceptSocket(); ClientDialog clientDialog = new ClientDialog(socket); this.clients.Add(clientDialog); /* ClientHandler clientHandler = new ClientHandler(clientDialog); * clientHandler.HandleClient();*/ Thread handling = new Thread(() => { HandleClient(clientDialog); }); handling.Start(); } }); accepting.Start(); }
public UserConfiguration(ClientDialog client) { this.client = client; }
protected abstract void HandleClient(ClientDialog clientDialog);