Exemplo n.º 1
0
        public void FetchPenguinDetails(MySqlDataReader reader, AutoResetEvent evnt)
        {
            var details = reader.GetDictFromReader();

            this.coins            = int.Parse(details["Coins"]);
            this.avatar           = details["Avatar"];
            this.avatarAttributes = details["AvatarAttributes"];
            this.RegistrationDate = int.Parse(details["RegistrationDate"]);
            this.moderator        = bool.Parse(details["Moderator"]);
            this.epf       = details["EPF"].Split(',').ToList();
            this.inventory = new Inventory(details["Inventory"], "%", this);

            long one_day     = 24 * 60 * 60;
            long currentTmsp = (long)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0)).TotalSeconds;

            this.age = (int)Math.Floor((decimal)((currentTmsp - this.RegistrationDate) / one_day));

            /* Membership days:
             * if age <= 3 months = 3 x 30.5 = 91.5, then membership = age / 10 * 30.5
             * if age > 3 months <= 13 months, then membership = age/10 * 3
             * if age > 13, then membership = floor((age - 365) * 100 / 365)
             */

            this.membershipDays = (int)(this.age <= 91.5 ? Math.Floor((decimal)(this.age * 10 / 365)) :
                                        this.age > 91.5 & this.age <= 396.5 ? Math.Floor((decimal)(this.age * 3 / 10)) :
                                        Math.Floor((decimal)((this.age - 365) * 100 / 365)));

            // ToDo : Stamps

            evnt.Set();
        }
Exemplo n.º 2
0
        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();
        }
Exemplo n.º 3
0
        public void CompleteLogin(MySqlDataReader reader, Penguin client, dynamic body)
        {
            var details = reader.GetDictFromReader();
            //"101|OP1-{AB-ERTS-972H}-09-K|valid22|f54fb87b5b1e6120e28c5bbf1a6ca862|NULL|45|2"
            var nick = ((string)body.login.nick.Value).Split(char.Parse("|"));

            client.swid     = nick[1];
            client.username = client.nickname = ((string)nick[2]).preetify();
            string password = nick[3];

            if (client.username.ToLower() != details["Username"].ToLower() || password != details["ConfirmationHash"] ||
                client.swid != details["SWID"] || password == "")
            {
                client.send("e", "101", "#2");
                Airtower.disposeClient(false, client.getSocket());
                return;
            }

            var pword = body.login.pword.Value.Split(char.Parse("#"));

            if (pword[0] != String.Format("{0}{1}", (password + GetPenguinRandomKey(client)).md5().swap(16), password) || pword[1] != details["LoginKey"] || pword[0] == "" ||
                pword[1] == "")
            {
                client.send("e", "101", "#3");
                Airtower.disposeClient(false, client.getSocket());
                return;
            }

            client.send("l", "$loggedin");
            return;
        }
Exemplo n.º 4
0
        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());
        }
Exemplo n.º 5
0
        public void FetchPenguinCache(MySqlDataReader reader, AutoResetEvent Evnt)
        {
            var           _dict   = reader.GetDictFromReader();
            List <String> details = (_dict["Cache"]).Split(new char[] { ';' }).ToList();

            this.Cache["PlayerWidget"] = ListValue(details, 0);
            this.Cache["MapCategory"]  = ListValue(details, 1);
            this.Cache["Igloo"]        = ListValue(details, 2);
            this.Cache["GAS"]          = ListValue(details, 3);

            this.Cache["NX"] = _dict["nx"];

            Evnt.Set();
        }
Exemplo n.º 6
0
        public void FetchClothings(MySqlDataReader reader, AutoResetEvent evnt)
        {
            var details = reader.GetDictFromReader();

            this.color = details["Color"];
            this.head  = details["Head"];
            this.face  = details["Face"];
            this.neck  = details["Neck"];
            this.body  = details["Body"];
            this.hand  = details["Hand"];
            this.feet  = details["Feet"];
            this.bg    = details["Photo"];
            this.pin   = details["Flag"];

            evnt.Set();
        }