public void AddUser(TcpClient connectedClient, List <Client> clientsList, Rooms rooms) { UniversalStream stream = new UniversalStream(connectedClient); while (!connectedClient.GetStream().DataAvailable) { } string data = stream.Read(); if (new Regex("^GET").IsMatch(data)) { stream.Type = ClientType.Web; stream.WriteHandshake(data); while (!connectedClient.GetStream().DataAvailable) { } data = stream.Read(); } if (stream.Type == ClientType.Web) { data = stream.Decode(); } Request req = JsonConvert.DeserializeObject <Request>(data); if (dbmanager.CreateNewLogin(req.modul, req.data, req.command)) { Client cl = clientsList.Find(c => c.name == req.modul); if (cl == null) { Client client = new Client(connectedClient, req.modul, stream); clientsList.Add(client); if (client.name == "admin") { Thread tr = new Thread(delegate() { ForAdmin(client, rooms); }); tr.Start(); } Thread.Sleep(100); req.data = client.name; req.modul = "ok"; stream.Write(JsonConvert.SerializeObject(req)); } else { req.modul = "badlogin"; stream.Write(JsonConvert.SerializeObject(req)); } } else { req.modul = "badlogin"; stream.Write(JsonConvert.SerializeObject(req)); } }
public void AddUser(TcpClient tcpclient, List <Client> clientsList, Rooms rooms) { Client client = new Client(tcpclient); string[] logpass = client.GetLogPass(); if (dbmanager.CreateNewLogin(logpass[0], logpass[1], logpass[2])) { for (int i = 0; i < clientsList.Count; i++) { if (clientsList[i].name == logpass[0]) { return; } } clientsList.Add(client); if (client.name == "admin") { Thread tr = new Thread(delegate() { ForAdmin(client, rooms); }); tr.Start(); } StreamWriter sw = new StreamWriter(tcpclient.GetStream()); Request req; if (logpass[0] == "admin") { req = new Request("ok", null, "admin"); } else { req = new Request("ok", null, logpass[0]); } sw.WriteLine(JsonConvert.SerializeObject(req)); sw.Flush(); } }