Пример #1
0
        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));
            }
        }
Пример #2
0
 public string Read()
 {
     return(us.Read());
 }