Esempio n. 1
0
        private void LOGIN_Packet(Socket s, string username, string password)
        {
            int   Error  = 0;
            ulong userID = ExecuteLogin(username, password, Database, ref Error);

            if (userID == 0)
            {
                Console.WriteLine("MSG_WARNING", "Login attempt failed. username="******" password="******" and Error = " + Error);
                SendData(s, "LOGIN;0;" + Error);
                return;
            }
            else
            {
                for (int i = 0; i < ClientList.Count; i++)
                {
                    if (ClientList[i]._Socket == s)
                    {
                        ClientList[i].IsActive = true;
                    }
                }
                Console.WriteLine("MSG_INFO", "Account logged in UserID = " + userID);
            }
            SendData(s, "LOGIN;" + GetAllCharactersAndInfo((int)userID, Database) + MyEncryption.CreateCharacterHash(userID.ToString()));
        }
Esempio n. 2
0
        public Character(ulong playerID, MySQLHandler GlobalMysql, Socket s, Items itemsDB)
        {
            MYSQL = GlobalMysql;
            // Equipment and Storage goes here.
            // equipment = new CharacterEquipment(playerID, GlobalMysql);
            // storage = new CharacterStorage(playerID, GlobalMysql);
            _skillList    = new List <Skill>();
            AllSkills     = new Skills(MYSQL);
            ItemsDB       = itemsDB;
            _socketClient = s;

            // Entire item list for all items in database
            _equipmentList = new List <Item>();

            if (MYSQL.Connection.State != ConnectionState.Open)
            {
                try
                {
                    MYSQL.Connection.Open();
                }
                catch
                {
                    // err
                }
            }


            MySqlCommand query = MYSQL.Connection.CreateCommand();

            query.CommandText = "SELECT * FROM `characters` WHERE `characters`.`id` = " + playerID;
            // 0,10;     1,30;2,30;
            lock (GlobalMysql)
            {
                try
                {
                    using (MySqlDataReader reader = query.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            name        = reader.GetString("name");
                            level       = reader.GetInt32("level");
                            id          = reader.GetUInt64("id");
                            str         = reader.GetUInt32("str");
                            dex         = reader.GetUInt32("dex");
                            _int        = reader.GetUInt32("_int");
                            luck        = reader.GetUInt32("luck");
                            maxhp       = reader.GetUInt32("maxhp");
                            maxmp       = reader.GetUInt32("maxmp");
                            curhp       = reader.GetUInt32("curhp");
                            curmp       = reader.GetUInt32("curmp");
                            mapid       = reader.GetInt32("mapid");
                            _maxwave    = reader.GetInt32("wavenumber");
                            skillpoints = reader.GetUInt32("skillpoints");
                            statpoints  = reader.GetUInt32("statpoints");
                            exp         = reader.GetInt32("exp");
                            gold        = reader.GetUInt32("gold");
                            hash        = MyEncryption.CreateCharacterHash(reader.GetString("account_id"));
                            this.Id     = id;
                            accID       = reader.GetInt32("account_id");

                            // skill stuff
                            string[] tmpactiveskill  = reader.GetString("active_skill").Split(',');
                            int[]    tmpactiveskills = new int[4];
                            string[] skillids        = reader.GetString("skill_id").Split(',');
                            int[]    skillidlist     = new int[11];
                            int      skillCounter    = 0;
                            string[] skilllevel      = reader.GetString("skill_level").Split(',');
                            int[]    skilllevels     = new int[11];
                            foreach (string _skillid in skillids)
                            {
                                if (skillCounter >= 10)
                                {
                                    break;
                                }
                                int tempID;
                                int val = Int32.TryParse(_skillid, out tempID) ? tempID : 0;
                                if (val == 0)
                                {
                                    continue;
                                }
                                skillidlist[skillCounter] = val;
                                skillCounter++;
                            }
                            skillCounter = 0;
                            foreach (string _skilllevel in skilllevel)
                            {
                                if (skillCounter >= 10)
                                {
                                    break;
                                }
                                int tempID;
                                int val = Int32.TryParse(_skilllevel, out tempID) ? tempID : 0;
                                if (val == 0)
                                {
                                    continue;
                                }
                                skilllevels[skillCounter] = val;
                                skillCounter++;
                            }
                            skillCounter = 0;
                            foreach (string _tmpactiveskill in tmpactiveskill)
                            {
                                if (skillCounter > 3)
                                {
                                    break;
                                }
                                int tempID;
                                int val = Int32.TryParse(_tmpactiveskill, out tempID) ? tempID : 0;
                                if (val == 0)
                                {
                                    continue;
                                }
                                tmpactiveskills[skillCounter] = val;
                                skillCounter++;
                            }

                            for (int i = 0; i < skillidlist.Count(); i++)
                            {
                                Skill skill = AllSkills.GetSkillByID(skillidlist[i]);
                                if (skill == null)
                                {
                                    continue;
                                }
                                for (int j = 0; j < tmpactiveskills.Count(); j++)
                                {
                                    if (tmpactiveskills[j] == skill.Id)
                                    {
                                        skill.Active = true;
                                    }
                                }
                                skill.Level = skilllevels[i];
                                //Skill skill = new Skill(skillidlist[i], AllSkills.SkillList[j].Attack, skilllevels[i], AllSkills.SkillList[j].Name);
                                _skillList.Add(skill);
                            }
                        }
                    }
                }
                catch (MySqlException e)
                {
                    MessageBox.Show(e.ToString(), "Server can't start.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
            // Items Now
            // fill up the list
            for (int i = 0; i < MAX_SLOTS; i++)
            {
                _equipmentList.Add(new Item());
            }
            query.CommandText = "SELECT * FROM `character_items` WHERE `ownerID` = " + (int)id + " ORDER BY slot DESC";
            try
            {
                using (MySqlDataReader reader = query.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        Item tmpItem = new Item();
                        tmpItem         = ItemsDB.GetItemByID(reader.GetInt32("itemid"));
                        tmpItem.Slot    = reader.GetInt32("slot");
                        tmpItem.Amount  = reader.GetInt32("amount");
                        tmpItem.Power   = reader.GetInt32("attack");
                        tmpItem.Defense = reader.GetInt32("defense");
                        tmpItem.HP      = reader.GetInt32("hp");
                        tmpItem.Stat1   = reader.GetInt32("extra_stat1");
                        tmpItem.Stat2   = reader.GetInt32("extra_stat2");
                        if (tmpItem.ID != -1)
                        {
                            //_equipmentList.Add(tmpItem);
                            _equipmentList[tmpItem.Slot] = tmpItem;
                        }
                        else
                        {
                            MessageBox.Show("Invalid item", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                        }
                    }
                }
            }
            catch (MySqlException e)
            {
                MessageBox.Show("Error while loading items for charid = " + id + " \n\n\n" + e.ToString(), "Charater.cs Error - Failed to load items", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }

            LastSave = (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalSeconds;
        }