void MessageRead() { for (int i = 0; i < users.Count; i++) { if (users[i].stream.DataAvailable) { object str = formatter.Deserialize(users[i].tcpClient.GetStream()); CallData data; //if (str is CallData) // data = (CallData)str; data = JsonConvert.DeserializeObject <CallData>((string)str); switch (data.methodName) { case "SendUsers": SendUsers(i, data.data); break; case "Disconect": Disconect(i, data.data); break; case "ActivateRMD": ActivateRMD(i, data.data); break; } } } #region егистрируем новых пользователей for (int i = 0; i < unnamed_clients.Count; i++) { if (unnamed_clients[i].GetStream().DataAvailable) { NetworkStream str = unnamed_clients[i].GetStream(); var reg_data = (RegistryMessage)formatter.Deserialize(str); TcpClient client = unnamed_clients[i]; users.Add(new User(reg_data.name, ref client)); NewClient.Invoke(users.Last()); unnamed_clients.RemoveAt(i); i--; } } #endregion }
/// <summary> /// Creates or gets a travian client. /// </summary> /// <param name="a">Account to be associated.</param> /// <param name="host">Host address.</param> /// <returns>Travian client.</returns> public TravianClient CreateTravianClient(Account a, string host) { if (TravianClients.ContainsKey(a.Username)) { return(TravianClients[a.Username]); } var tc = new TravianClient(a, GetClient(a.Username, host)); TravianClients.Add(a.Username, tc); if (NewClient != null) { NewClient.Invoke(tc); } return(tc); }
private void Handshake(Socket socket) { // 1 byte protocol // 1 byte encryption mode // 1 byte compression mode (legacy) // 64 bytes sha256 hash password // = 67 bytes byte[] req = new byte[67]; int rec = socket.Receive(req); // Ensure the correct amount of bytes are received if (rec == req.Length) { byte protocol = req[0], enc = req[1], comp = req[2]; string password = Encoding.ASCII.GetString(req.Skip(3).ToArray()); if (password == Password || password == PersonalPassword) { Client c = new Client((Protocol)protocol, socket, password, (CryptoServiceAlgorithm)enc); SendResponse(socket, 1); NewClient?.Invoke(this, c); Logger.Info($"New {c}"); } else { SendResponse(socket, 0); socket.Dispose(); Logger.Info($"Rejected socket for incorrect password {socket.RemoteEndPoint}"); } } else if (rec == 1 && req[0] == 255) { // Check if client is online Logger.Info($"Updated server status for {socket.RemoteEndPoint}"); } else { Logger.Info($"Rejected socket for incorrect password {socket.RemoteEndPoint}"); SendResponse(socket, 0); socket.Dispose(); } }
protected virtual void OnNewClient(Device device) { NewClient?.Invoke(this, new NewClientEventArgs(device)); }
public static void Fire_NewClient(Object sender, ClsStringEventArgs args) { NewClient?.Invoke(sender, args); }