private void HandleRequestConnectMessage(ClientPacket protocolPacket, IClientProtocol protocol, IPAddress address) { var client = Clients.FirstOrDefault(x => x.Id == protocolPacket.Id) as CClient; if (client != null) { return; } var port = int.Parse(protocol.DataJson); if (!CConstant.UdpListenerPort.Contains(port)) { return; } client = new CClient() { Id = protocolPacket.Id, Name = protocolPacket.Name, Port = port, Address = address, }; client.CalculateChecksum(); client.Refresh(); lock (Clients) { Clients.Add(client); } RunOnUiThread(delegate { ClientNew?.Invoke(client); ClientsChanged?.Invoke(Clients); var generator = new Random(); var r = generator.Next(1, 1000000); var passcode = r.ToString().PadLeft(6, '0'); client.Passcode = passcode; }); var responseProtocol = new ServerProtocol() { Message = ServerMessage.RequestPasscode }; SendServerPacket(ServerPacketType.Protocol, JsonConvert.SerializeObject(responseProtocol), client); RunOnUiThread(delegate { client.State = ClientState.WaitingPasscode; }); }
public ServerNew(int port) { members = new List <IPEndPoint>(); client = new ClientNew(port); }