コード例 #1
0
ファイル: LoginHandler.cs プロジェクト: Times-0/Times
        public void HandlePenguinBanned(MySqlDataReader reader, Penguin client, AutoResetEvent evnt)
        {
            if (!reader.HasRows)
            {
                client.banned = false;
                evnt.Set();
                return;
            }

            var  details     = reader.GetDictFromReader();
            long timestamp   = long.Parse(details["till"]);
            long currentTmsp = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;

            if (timestamp > currentTmsp)
            {
                client.banned = true;
                string hoursban = (Math.Round((timestamp - currentTmsp) / 3600.0)).ToString();
                client.send("e", "601", hoursban);
                Airtower.disposeClient(false, client.getSocket());
            }
            else
            {
                client.banned = false;
                MySQLStatement stmt = new MySQLStatement("UPDATE `banned` SET `till` = '0' AND `b_by`='' AND `reason`='' WHERE `ID` = @id", new Dictionary <string, dynamic> {
                    { "@id", client.id }
                });
                Server.Utils.MySQL.MySQL.getCurrentMySQLObject().MySQLCallback(stmt);
            }

            evnt.Set();
        }
コード例 #2
0
ファイル: LoginHandler.cs プロジェクト: Times-0/Times
        public void ContinuePrimaryLogin(MySqlDataReader reader, Penguin client, dynamic data)
        {
            if (!reader.HasRows || GetPenguinRandomKey(client) == null)
            {
                client.send("e", "101");
                Airtower.disposeClient(false, client.getSocket());
                return;
            }

            var penguin_details = reader.GetDictFromReader();

            string password = Cryptography.GenerateLoginHash(penguin_details["Password"], GetPenguinRandomKey(client));

            if (password != client.password)
            {
                client.send("e", "101");
                Airtower.disposeClient(false, client.getSocket());
                return;
            }

            client.id = penguin_details["ID"];
            // Handle Banned
            MySQLStatement stmt = new MySQLStatement("");

            stmt.parameters = new Dictionary <string, dynamic> {
                { "@id", client.id }
            };
            AutoResetEvent evnt = new AutoResetEvent(false);

            stmt.statement = "SELECT `till` FROM `banned` WHERE `ID` = @id";
            Server.Utils.MySQL.MySQL.getCurrentMySQLObject().MySQLCallback(stmt, Server.Utils.Events.EventDelegate.create(this, "HandlePenguinBanned"), client, evnt);

            evnt.WaitOne();

            if (client.banned)
            {
                return;
            }

            string ConfHash = GetPenguinRandomKey(client).md5() + "-" + penguin_details["Password"].GetHashCode().ToString().md5();

            Shell.getCurrentShell().getCurmbs("Login")["HashKey"][client][1] = ConfHash;

            stmt.statement         = "UPDATE `penguins` SET `LoginKey` = @lk, `ConfirmationHash` = @ch WHERE `ID` = @id";
            stmt.parameters["@lk"] = ConfHash;
            stmt.parameters["@ch"] = password;

            Server.Utils.MySQL.MySQL.getCurrentMySQLObject().MySQLCallback(stmt);

            string users_bar = Math.Floor((double)(Airtower.Clients.Values.Where(i => i.PORT == 9875).ToList().Count * 5 / 550)).ToString();

            client.send("l",
                        string.Format("{0}|{1}|{2}|{3}|NULL|45|2", new object[] { client.id, penguin_details["SWID"],
                                                                                  client.username, password }), ConfHash, ConfHash.md5(),
                        string.Format("100,{0}", users_bar), penguin_details["Email"]);

            Airtower.disposeClient(false, client.getSocket());
        }
コード例 #3
0
ファイル: LoginHandler.cs プロジェクト: Times-0/Times
        public void HandleLogin(Penguin client, dynamic body)
        {
            if (body == null)
            {
                return;
            }
            if (body.login == null)
            {
                return;
            }
            if (body.login.pword == null)
            {
                return;
            }
            if (body.login.nick == null)
            {
                return;
            }
            if (GetPenguinRandomKey(client) == null)
            {
                return;
            }

            client.nickname = client.username = (String)body.login.nick.ToString();
            client.password = body.login.pword.ToString();

            if (Airtower.ServerType.ContainsKey(client.PORT))
            {
                MySQLStatement statement = new MySQLStatement();

                if ((body.login.pword.ToString()).Contains("#") && Airtower.ServerType[client.PORT] == 0)
                {
                    // World login
                    statement.statement  = "SELECT `ID`, `Password`, `Email`, `SWID` FROM `Penguins` WHERE `ID` = @val";
                    statement.parameters = new Dictionary <string, dynamic> {
                        { "@val", client.username.Split(char.Parse("|"))[0] }
                    };
                    Server.Utils.MySQL.MySQL.getCurrentMySQLObject().MySQLCallback(statement, Server.Utils.Events.EventDelegate.create(this, "ContinueWorldLogin"), client, body);
                }
                else
                if (Airtower.ServerType[client.PORT] == -1)
                {
                    // Primary login
                    statement.statement  = "SELECT `ID`, `Password`, `Email`, `SWID` FROM `Penguins` WHERE `Username` = @val";
                    statement.parameters = new Dictionary <string, dynamic> {
                        { "@val", client.username }
                    };
                    Server.Utils.MySQL.MySQL.getCurrentMySQLObject().MySQLCallback(statement, Server.Utils.Events.EventDelegate.create(this, "ContinuePrimaryLogin"), client, body);
                }

                statement = null;
            }
        }
コード例 #4
0
        public void Add(Item item)
        {
            if (!this.ItemExists(item.id))
            {
                this.items.Add(item);
            }

            if (this.penguin == null)
            {
                return;
            }

            string         Items     = this.Join("%");
            MySQLStatement statement = new MySQLStatement("UPDATE `penguins` SET `Inventory` = @inv WHERE `ID` = @id");

            statement.parameters["@inv"] = Items;
            statement.parameters["@id"]  = this.penguin.id;

            MySQL.getCurrentMySQLObject().MySQLCallback(statement);
        }
コード例 #5
0
        public void JoinPenguinToServer(Penguin client, string[] data)
        {
            string id   = data[0];
            string hash = data[1];

            if (id != client.id)
            {
                Airtower.disposeClient(false, client.getSocket());
                return;
            }

            MySQLStatement stmt = new MySQLStatement("SELECT `ConfirmationHash` FROM `penguins` WHERE `ID` = @id", new Dictionary <string, dynamic> {
                { "@id", client.id }
            });
            string confirmationHash = (MySQL.getCurrentMySQLObject().ExecuteAndFetch(stmt).GetDictFromReader())["ConfirmationHash"];

            stmt = null;

            if (hash != confirmationHash)
            {
                Airtower.disposeClient(false, client.getSocket());
                return;
            }

            AutoResetEvent get_details = new AutoResetEvent(false);

            client.LoadPenguinDetails(get_details);
            get_details.WaitOne();
            client.GenerateString();
            client.send(Airtower.JOIN_WORLD, "1", client.epf[0], (client.moderator ? 1 : 0).ToString());

            client.doXT = true;

            var puffle_data = client.PuffleData();

            client.send(Airtower.GET_MY_PLAYER_PUFFLES, puffle_data.join("%"));

            /* TO ADD STAMPS*/
            client.send(Airtower.GET_PLAYER + "s", client.epf[0], "");

            client.send(Airtower.LOAD_PLAYER,
                        (new List <string> {
                client.ToString(),
                client.coins.ToString(),
                "0",                                                                                           // Safe-Game mode ? 0 -> no, 1 -> yes
                "1024",                                                                                        // Egg timer
                ((DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds - 2 * 60 * 60).ToString(), // Penguin Standard Time
                client.age.ToString(),
                "0",                                                                                           // Banned age
                client.age.ToString(),                                                                         // Penguin's days old
                client.membershipDays.ToString(),
                "",
                client.Cache["PlayerWidget"],     // Has opened PlayerWidget - Cache
                client.Cache["MapCategory"],
                client.Cache["Igloo"],
            }).join("%"));

            client.send("glr", "");
            client.send("spts", client.id, client.avatar, client.avatarAttributes);

            EventDispatcher._dispatcher.updateListeners("JS#{JOINED}", client);

            ((GeneralRoom)(CacheHandler.Rooms["100"])).Add(client, true);
        }
コード例 #6
0
ファイル: LoginHandler.cs プロジェクト: Times-0/Times
        public void ContinueWorldLogin(MySqlDataReader reader, Penguin client, dynamic body)
        {
            if (!reader.HasRows || GetPenguinRandomKey(client) == null)
            {
                client.send("e", "101", "#1");
                Airtower.disposeClient(false, client.getSocket());
                return;
            }

            if (body == null)
            {
                return;
            }
            if (body.login == null)
            {
                return;
            }
            if (body.login.pword == null)
            {
                return;
            }
            if (body.login.nick == null)
            {
                return;
            }
            if (GetPenguinRandomKey(client) == null)
            {
                return;
            }

            string[] userInfo = body.login.nick.Value.Split(char.Parse("|"));
            if (userInfo[0].userInServer(9875))
            {
                client.send("e", "3");
                Airtower.disposeClient(false, client.getSocket());
                return;
            }

            client.id = userInfo[0];

            MySQLStatement stmt = new MySQLStatement("");

            AutoResetEvent banEvent = new AutoResetEvent(false);

            stmt.statement  = "SELECT `till` FROM `banned` WHERE `ID` = @id";
            stmt.parameters = new Dictionary <string, dynamic> {
                { "@id", client.id }
            };
            Server.Utils.MySQL.MySQL.getCurrentMySQLObject().MySQLCallback(stmt, Server.Utils.Events.EventDelegate.create(this, "HandlePenguinBanned"), client, banEvent);

            banEvent.WaitOne();

            if (client.banned)
            {
                return;
            }

            stmt.statement = "SELECT `ID`, `Username`, `Password`, `Email`, `SWID`, `LoginKey`, `ConfirmationHash` FROM `Penguins` WHERE `ID` = @id";
            Server.Utils.MySQL.MySQL.getCurrentMySQLObject().MySQLCallback(stmt, Server.Utils.Events.EventDelegate.create(this, "CompleteLogin"), client, body);
            stmt = null;
        }