Пример #1
0
        public bool CheckLogin(Client cl, string Username, string Password)
        {
            DataTable DT = DB.QueryCmd("SELECT * FROM clients WHERE name='" + Username + "';");
            DataRowCollection DR = DT.Rows;
            if (DR.Count == 0)
            {
                cl.Send(new Packet("Msg", new string[] { "Server", "Username not found." }));
            }
            else
            {
                if (((string)DR[0]["pass"]).Equals(Password)) //can't use == on strings
                {
                    CS.SysLog(string.Format("Client {0} has successfully logged in as {1}", cl.Name, Username));
                    cl.Name = Username;
                    cl.Send(new Packet("Msg", new string[] { "Server", "Successfully logged in!" }));
                    cl.Send(new Packet("Name", cl.Name));

                    return true;
                }
                else
                {
                    cl.Send(new Packet("Msg", new string[] { "Server", "Incorrect password!" }));
                    return false;
                }

            }

            //check query

            return true;
        }
Пример #2
0
        void Listener_OnAccept(object sender)
        {
            Client C = new Client((TcpClient)sender);
            C.OnRecv += new Client.PacketReceivedEventHandler(C_OnRecv);
            Clients.Add(C);
            string n = "Unregistered";

            int x = 0;
            string Name = n;
            while (Clients.HasName(Name))
            {
                x++;
                Name = n + x;
            }
            C.Name = Name;

            TryChat("[Server] Accepted client " + C.Name + "(" + C.IP + ")");
            C.Send(new Packet("msg", new string[] {Vars.GetS("Servername"), "You have connected successfully.\n" + Vars.GetS("motd")}));
        }
Пример #3
0
 public bool Register(Client cl, string Username, string Password)
 {
     Dictionary<string, object> Extras = new Dictionary<string,object>();
     cl.Name = Username;
     DataTable DT = DB.QueryCmd("SELECT * FROM clients WHERE name='" + Username + "';");
     if (DT.Rows.Count != 0)
     {
         cl.Send(new Packet("Msg", new string[] { "Server", "Username already registered." }));
     }
     else
     {
         Dictionary<string, object> Vals = new Dictionary<string,object>();
         Vals.Add("name", Username);
         Vals.Add("pass", Password);
         DB.Insert("clients", Vals);
         cl.Send(new Packet("Msg", new string[] { "Server", "You have successfully registered " + Username + "!." }));
     }
     return true;
 }