public Client(string name, TcpClient user, string status, UniversalStream stream) { this.name = name; this.user = user; this.status = status; this.stream = stream; }
private void ConnectionLoop() { serverListener.Start(); LogManager.AddToLog("server", "started"); Thread ThreadListen = new Thread(new ThreadStart(Receive)); ThreadListen.Start(); while (true) { try { var connectedClient = serverListener.AcceptTcpClient(); UniversalStream stream = new UniversalStream(connectedClient); while (!connectedClient.GetStream().DataAvailable) { } string data = stream.Read(); if (new Regex("^GET").IsMatch(data)) { stream.WriteHandshake(data); stream.Type = UniversalStream.ClientType.Web; while (!connectedClient.GetStream().DataAvailable) { } data = stream.Read(); } if (stream.Type == UniversalStream.ClientType.Web) { data = stream.Decode(); } data = data.Replace("\r\n", ""); string[] input = data.Split(','); if (input[0] == "sendpassword") { if (dbmanager.SendPassword(input[1])) { stream.Write("forgotpasssuccess"); } else { stream.Write("forgotpassrefuse"); } } if (input[0] == "foreign") { Client cl = connectionList.clientList.Find(c => c.name == input[1]); if (cl == null) { connectionList.AddList(new Client(input[1], connectedClient, input[2], stream)); } LogManager.AddToLog(input[1], data); } else if (dbmanager.RA(input[0], input[1], input[2], input[3])) { Client cl = connectionList.clientList.Find(c => c.name == input[1]); if (cl == null) { connectionList.AddList(new Client(input[1], connectedClient, input[3], stream)); } LogManager.AddToLog(input[1], data); } else { stream.Write("loginrefuse"); connectedClient.Close(); } Thread.Sleep(50); } catch (Exception ex) { CrashManager.CrashReportToFile(ex.StackTrace + ex.Message, ex.InnerException?.ToString()); } } }