Ejemplo n.º 1
0
        // Load All Container Arrays from  SQL
        void LoadFromSQL(string tablename)
        {
            // Empty the Array first
            for (int i = 0; i < Items.Length; i++)
            {
                Items[i] = null;
            }
            SqlWrapper sql = new SqlWrapper();
            DataTable  dt  = sql.ReadDatatable("SELECT * FROM " + tablename + " WHERE container=" + Type + " AND ID=" + Instance);

            foreach (DataRow row in dt.Rows)
            {
                int place = (Int32)row["placement"];
                if (place < NumberOfSlots)
                {
                    if (((Int32)row["type"] != 0) && ((Int32)row["instance"] != 0))
                    {
                        // Do stuff with instanced items
                        // Create item from lowid/highid interpolated by QL and read stats from sql
                    }
                    else
                    {
                        ContainerEntry ce = new ContainerEntry();
                        ce.LowID      = (Int32)row["lowid"];
                        ce.HighID     = (Int32)row["highid"];
                        ce.QL         = (Int32)row["quality"];
                        ce.Amount     = (Int32)row["multiplecount"];
                        ce.Flags      = (uint)row["flags"];
                        ce.InstanceID = 0;
                        ce.Type       = 0;
                        Items[place]  = ce;
                    }
                }
            }
        }
        /// <summary>
        /// Read and send back Player name lookup packet
        /// </summary>
        /// <param name="client">
        /// Client sending
        /// </param>
        /// <param name="packet">
        /// Packet data
        /// </param>
        public static void Read(Client client, byte[] packet)
        {
            PacketReader reader = new PacketReader(ref packet);

            reader.ReadUInt16(); // packet ID
            reader.ReadUInt16(); // data length
            uint playerId = uint.MaxValue;
            string playerName = reader.ReadString();
            client.Server.Debug(
                client, "{0} >> PlayerNameLookup: PlayerName: {1}", client.Character.characterName, playerName);
            reader.Finish();

            SqlWrapper ms = new SqlWrapper();
            string sqlQuery = "SELECT `ID` FROM `characters` WHERE `Name` = " + "'" + playerName + "'";
            DataTable dt = ms.ReadDatatable(sqlQuery);
            if (dt.Rows.Count > 0)
            {
                // Yes, this double cast is correct
                playerId = (uint)(int)dt.Rows[0][0];
            }

            byte[] namelookup = NameLookupResult.Create(playerId, playerName);
            client.Send(namelookup);
            client.KnownClients.Add(playerId);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="charId"></param>
        /// <returns></returns>
        public static List<ItemsEntry> LoadItems(int charId)
        {
            List<ItemsEntry> items = new List<ItemsEntry>();
            SqlWrapper sqlWrapper = new SqlWrapper();
            try
            {
                string sqlQuery =
                    "SELECT `Placement`, `Flags`, `MultipleCount`, `Type`, `Instance`, `LowID`, `HighID`, `Quality`, `Nothing` FROM `inventory` WHERE ID = "
                    + "'" + charId + "' ORDER BY Placement ASC";
                DataTable dataTable = sqlWrapper.ReadDatatable(sqlQuery);

                foreach (DataRow itemRow in dataTable.Rows)
                {
                    ItemsEntry itemEntry = new ItemsEntry();
                    itemEntry.Placement = (Int32)itemRow["Placement"];
                    itemEntry.Flags = (Int16)itemRow["Flags"];
                    itemEntry.MultipleCount = (Int16)itemRow["MultipleCount"];
                    itemEntry.ItemType = (Int32)itemRow["Type"];
                    itemEntry.Instance = (Int32)itemRow["Instance"];
                    itemEntry.LowId = (Int32)itemRow["LowID"];
                    itemEntry.HighId = (Int32)itemRow["HighID"];
                    itemEntry.Quality = (Int32)itemRow["Quality"];
                    itemEntry.Nothing = (Int32)itemRow["Nothing"];

                    items.Add(itemEntry);
                }
            }
            catch (Exception e)
            {
                sqlWrapper.sqlclose();
                Console.WriteLine("Error: CharacterID: " + charId + "Message: " + e.Message);
            }
            return items;
        }
 // Load All Container Arrays from  SQL
 void LoadFromSQL(string tablename)
 {
     // Empty the Array first
     for (int i = 0; i < Items.Length; i++)
         Items[i] = null;
     SqlWrapper sql = new SqlWrapper();
     DataTable dt = sql.ReadDatatable("SELECT * FROM " + tablename + " WHERE container=" + Type + " AND ID=" + Instance);
     foreach (DataRow row in dt.Rows)
     {
         int place = (Int32)row["placement"];
         if (place < NumberOfSlots)
         {
             if (((Int32)row["type"] != 0) && ((Int32)row["instance"] != 0))
             {
                 // Do stuff with instanced items
                 // Create item from lowid/highid interpolated by QL and read stats from sql
             }
             else
             {
                 ContainerEntry ce = new ContainerEntry();
                 ce.LowID = (Int32)row["lowid"];
                 ce.HighID = (Int32)row["highid"];
                 ce.QL = (Int32)row["quality"];
                 ce.Amount = (Int32)row["multiplecount"];
                 ce.Flags = (uint)row["flags"];
                 ce.InstanceID = 0;
                 ce.Type = 0;
                 Items[place] = ce;
             }
         }
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// </summary>
        /// <param name="orgId">
        /// </param>
        /// <param name="excludePresident">
        /// </param>
        /// <returns>
        /// </returns>
        public static List<int> GetOrgMembers(uint orgId, bool excludePresident)
        {
            // Stat #5 == Clan == OrgID
            // Stat #48 == ClanLevel == Org Rank (0 is president)
            SqlWrapper mySql = new SqlWrapper();
            List<int> orgMembers = new List<int>();
            string pres = string.Empty;

            if (excludePresident)
            {
                pres = " AND `ID` NOT IN (SELECT `ID` FROM `characters_stats` WHERE `Stat` = '48' AND `Value` = '0')";
            }

            DataTable dt =
                mySql.ReadDatatable(
                    "SELECT `ID` FROM `characters_stats` WHERE `Stat` = '5' AND `Value` = '" + orgId + "'" + pres);

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow row in dt.Rows)
                {
                    orgMembers.Add((Int32)row[0]);
                }
            }

            return orgMembers;
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="guildID"></param>
        /// <returns></returns>
        public static List <GuildEntry> GetGuildInfo(int guildID)
        {
            List <GuildEntry> Guild    = new List <GuildEntry>();
            SqlWrapper        ms       = new SqlWrapper();
            string            SqlQuery = "SELECT * FROM `organizations` WHERE ID=" + "'" + guildID + "'";
            DataTable         dt       = ms.ReadDatatable(SqlQuery);

            foreach (DataRow row in dt.Rows)
            {
                GuildEntry guildEntry = new GuildEntry();
                guildEntry.guildID        = (UInt32)row["ID"];
                guildEntry.creation       = (DateTime)row["creation"];
                guildEntry.Name           = (string)row["Name"];
                guildEntry.LeaderID       = (Int32)row["LeaderID"];
                guildEntry.GovernmentForm = (Int32)row["GovernmentForm"];
                guildEntry.Description    = (string)row["Description"];
                guildEntry.Objective      = (string)row["Objective"];
                guildEntry.History        = (string)row["History"];
                guildEntry.Tax            = (Int32)row["Tax"];
                guildEntry.Bank           = (UInt64)row["Bank"];
                guildEntry.Comission      = (Int32)row["Comission"];
                guildEntry.ContractsID    = (Int32)row["ContractsID"];
                guildEntry.TowerFieldID   = (Int32)row["TowerfieldID"];
                Guild.Add(guildEntry);
            }
            return(Guild);
        }
 /// <summary>
 /// 
 /// </summary>
 /// <param name="guildID"></param>
 /// <returns></returns>
 public static List<GuildEntry> GetGuildInfo(int guildID)
 {
     List<GuildEntry> Guild = new List<GuildEntry>();
     SqlWrapper ms = new SqlWrapper();
     string SqlQuery = "SELECT * FROM `organizations` WHERE ID=" + "'" + guildID + "'";
     DataTable dt = ms.ReadDatatable(SqlQuery);
     foreach (DataRow row in dt.Rows)
     {
         GuildEntry guildEntry = new GuildEntry();
         guildEntry.guildID = (UInt32) row["ID"];
         guildEntry.creation = (DateTime) row["creation"];
         guildEntry.Name = (string) row["Name"];
         guildEntry.LeaderID = (Int32) row["LeaderID"];
         guildEntry.GovernmentForm = (Int32) row["GovernmentForm"];
         guildEntry.Description = (string) row["Description"];
         guildEntry.Objective = (string) row["Objective"];
         guildEntry.History = (string) row["History"];
         guildEntry.Tax = (Int32) row["Tax"];
         guildEntry.Bank = (UInt64) row["Bank"];
         guildEntry.Comission = (Int32) row["Comission"];
         guildEntry.ContractsID = (Int32) row["ContractsID"];
         guildEntry.TowerFieldID = (Int32) row["TowerfieldID"];
         Guild.Add(guildEntry);
     }
     return Guild;
 }
        public static int CacheAllFromDB()
        {
            int c = 0;
            SqlWrapper ms = new SqlWrapper();
            DataTable dt = ms.ReadDatatable("SELECT * FROM doors");

            foreach (DataRow row in dt.Rows)
            {
                Doors door = new Doors();
                door.ID = (Int32)row["ID"];
                door.Coordinates.x = (Single)row["X"];
                door.Coordinates.y = (Single)row["Y"];
                door.Coordinates.z = (Single)row["Z"];
                door.hX = (Single)row["hx"];
                door.hY = (Single)row["hy"];
                door.hZ = (Single)row["hz"];
                door.hW = (Single)row["hw"];

                door.teleport_to_ID = (Int32)row["toid"];
                door.teleport_to_PlayField = (Int32)(UInt32)row["toplayfield"];
                door.proxy = (Boolean)row["proxy"];
                door.playfield = (Int32)(UInt32)row["playfield"];
                Program.zoneServer.Doors.Add(door);
                c++;
            }
            return c;
        }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public bool ReadName()
        {
            DataTable dt = mySql.ReadDatatable("SELECT `Name`  FROM `mobspawns` WHERE ID = '" + mobId + "' LIMIT 1");

            if (dt.Rows.Count == 0)
            {
                return(false);
            }
            mobName = (string)dt.Rows[0][0];
            return(true);
        }
        /// <summary>
        /// Read login 
        /// </summary>
        /// <param name="recvLogin">
        /// Username sent by client
        /// </param>
        public void GetLoginFlags(string recvLogin)
        {
            string sqlQuery = "SELECT Flags FROM login WHERE Username = "******"'" + recvLogin + "'";
            SqlWrapper ms = new SqlWrapper();
            DataTable dt = ms.ReadDatatable(sqlQuery);

            foreach (DataRow row in dt.Rows)
            {
                this.flagsL = (Int32)row[0];
            }
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="recvLogin"></param>
        public void GetLoginName(string recvLogin)
        {
            string SqlQuery = "SELECT Username FROM login WHERE Username = "******"'" + recvLogin + "'";
            SqlWrapper ms = new SqlWrapper();
            DataTable dt = ms.ReadDatatable(SqlQuery);

            foreach (DataRow row in dt.Rows)
            {
                this.loginN = (string)row[0];
            }
        }
        /// <summary>
        /// Returns the Password hash
        /// </summary>
        /// <param name="recvLogin">
        /// Username received from the client
        /// </param>
        public void GetLoginPassword(string recvLogin)
        {
            string sqlQuery = "SELECT `Password` FROM `login` WHERE `Username` = " + "'" + recvLogin + "'";
            SqlWrapper ms = new SqlWrapper();
            DataTable dt = ms.ReadDatatable(sqlQuery);

            foreach (DataRow row in dt.Rows)
            {
                this.passwdL = (string)row[0];
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Read org and character names from DB
        /// </summary>
        public bool ReadNames()
        {
            DataTable dt =
                mySql.ReadDatatable("SELECT `Name`, `FirstName`, `LastName` FROM `characters` WHERE ID = '" + characterId +
                                    "' LIMIT 1");

            if (dt.Rows.Count > 0)
            {
                characterName      = (string)dt.Rows[0][0];
                characterFirstName = (string)dt.Rows[0][1];
                characterLastName  = (string)dt.Rows[0][2];
            }
            else
            {
                return(false);
            }

            // Read stat# 5 (Clan) - OrgID from character stats table
            dt =
                mySql.ReadDatatable("SELECT `Value` FROM `characters_stats` WHERE ID = " + characterId +
                                    " AND Stat = 5 LIMIT 1");

            if (dt.Rows.Count > 0)
            {
                _orgId = (Int32)dt.Rows[0][0];
            }
            if (_orgId == 0)
            {
                orgName = string.Empty;
            }
            else
            {
                List <GuildEntry> m_Guild = GuildInfo.GetGuildInfo(_orgId);

                foreach (GuildEntry ge in m_Guild)
                {
                    orgName = ge.Name;
                }
            }
            return(true);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="recvLogin"></param>
        public void GetCharacterZone(string recvLogin)
        {
            string sqlQuery = "SELECT `playfield` FROM `characters` WHERE Username = "******"'" + recvLogin + "'";
            SqlWrapper ms = new SqlWrapper();
            DataTable dt = ms.ReadDatatable(sqlQuery);

            foreach (DataRow datarow2 in dt.Rows)
            {
                this.playfield = (Int32)datarow2["playfield"];
                this.zone = BitConverter.GetBytes(this.playfield);
            }
        }
Ejemplo n.º 15
0
        private string GetLoginPassword(string RecvLogin)
        {
            SqlWrapper ms      = new SqlWrapper();
            string     PasswdL = string.Empty;
            DataTable  dt      = ms.ReadDatatable("SELECT Password FROM login WHERE Username = "******"'" + RecvLogin + "'");

            foreach (DataRow row in dt.Rows)
            {
                PasswdL = (string)row[0];
            }
            return(PasswdL);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Read name packet
        /// </summary>
        /// <param name="charId">
        /// The character Id.
        /// </param>
        /// <returns>
        /// The name of the character
        /// </returns>
        public string GetCharacterName(int charId)
        {
            string sqlQuery = string.Format("SELECT `Name` FROM `characters` WHERE `ID` = '{0}'", charId);
            SqlWrapper ms = new SqlWrapper();
            DataTable dt = ms.ReadDatatable(sqlQuery);
            if (dt.Rows.Count > 0)
            {
                this.name1 = (string)dt.Rows[0][0];
            }

            return this.name1;
        }
        public static List<UploadedNanoEntry> UploadedNanos(int charId)
        {
            List<UploadedNanoEntry> uploadedNano = new List<UploadedNanoEntry>();
            SqlWrapper ms = new SqlWrapper();
            string sqlQuery = "SELECT `NanoProgramID` FROM `uploadednanos` WHERE CharID = " + "'" + charId + "'";
            DataTable dt = ms.ReadDatatable(sqlQuery);

            foreach (DataRow nanoRow in dt.Rows)
            {
                uploadedNano.Add(new UploadedNanoEntry { NanoProgramId = (Int32)nanoRow["NanoProgramID"] });
            }
            return uploadedNano;
        }
Ejemplo n.º 18
0
        public void readOwnerfromSql()
        {
            SqlWrapper ms = new SqlWrapper();

            DataTable dt =
                ms.ReadDatatable(
                    "SELECT * FROM " + this.GetSqlTablefromDynelType() + "owner WHERE ID=" + this.Id.ToString());
            if (dt.Rows.Count > 0)
            {
                //TODO: Add Pet code here
                // Owner = FindCharacterByID(ms.myreader.GetInt32("owner");
            }
        }
Ejemplo n.º 19
0
        // LoadRecentMsgsList unused?

        /// <summary>
        /// The load recent msgs list.
        /// </summary>
        /// <param name="charId">
        /// The char Id.
        /// </param>
        /// <returns>
        /// List of received messages
        /// </returns>
        public static Collection<RecentMsgsEntry> LoadRecentMsgsList(uint charId)
        {
            Collection<RecentMsgsEntry> reciviedMsgsList = new Collection<RecentMsgsEntry>();
            SqlWrapper ms = new SqlWrapper();
            string sqlQuery = "SELECT `ReceivedID` FROM `receivedmsgs` WHERE PlayerID =" + "'" + charId + "'";
            DataTable dt = ms.ReadDatatable(sqlQuery);
            foreach (DataRow msgsRow in dt.Rows)
            {
                RecentMsgsEntry rme = new RecentMsgsEntry { ReceivedId = uint.Parse(msgsRow["ReceivedID"].ToString()) };
                reciviedMsgsList.Add(rme);
            }

            return reciviedMsgsList;
        }
 public static bool IsOnline(int id)
 {
     SqlWrapper sql = new SqlWrapper();
     DataTable dt = sql.ReadDatatable("SELECT * FROM characters WHERE ID = " + id + ";");
     if (dt.Rows.Count == 0)
     {
         throw new CharacterDoesNotExistException("Character does not exist: " + id);
     }
     if ((Int16)dt.Rows[0]["Online"] == 1)
     {
         return true;
     }
     return false;
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="recvLogin"></param>
        public void GetCharacterName(string recvLogin)
        {
            string sqlQuery = "SELECT `Name`, `Breed`, `Profession` FROM `characters` WHERE Username = "******"'"
                              + recvLogin + "'";
            SqlWrapper ms = new SqlWrapper();
            DataTable dt = ms.ReadDatatable(sqlQuery);

            foreach (DataRow datarow1 in dt.Rows)
            {
                this.name = Encoding.ASCII.GetBytes(datarow1["Name"].ToString().PadRight(11, '\u0000'));
                this.cbreedint = int.Parse(datarow1["Breed"].ToString());
                this.breed = BitConverter.GetBytes(this.cbreedint);
                this.cprofint = int.Parse(datarow1["Profession"].ToString());
                this.prof = BitConverter.GetBytes(this.cprofint);
            }
        }
Ejemplo n.º 22
0
        /// <summary>
        /// The load buddy list.
        /// </summary>
        /// <param name="charId">
        /// The char Id.
        /// </param>
        /// <returns>
        /// Buddy list
        /// </returns>
        public static Collection<BuddyListEntry> LoadBuddyList(int charId)
        {
            Collection<BuddyListEntry> buddyList = new Collection<BuddyListEntry>();
            SqlWrapper ms = new SqlWrapper();
            string sqlQuery = "SELECT `BuddyID` FROM `buddylist` WHERE PlayerID = " + "'" + charId + "'";
            DataTable dt = ms.ReadDatatable(sqlQuery);

            foreach (DataRow buddyRow in dt.Rows)
            {
                BuddyListEntry buddylistentry = new BuddyListEntry();
                buddylistentry.BuddyId = uint.Parse(buddyRow["BuddyID"].ToString());
                buddyList.Add(buddylistentry);
            }

            return buddyList;
        }
        public static void CacheAllFromDB()
        {
            SqlWrapper wrapper = new SqlWrapper();
            DataTable dt = wrapper.ReadDatatable("SELECT * FROM mobdroptable");

            DataRowCollection drc = dt.Rows;
            foreach (DataRow row in drc)
            {
                FullDropList.Add(
                    new LootItem(
                        row[0].ToString(),
                        row[1].ToString(),
                        row[2].ToString(),
                        row[3].ToString(),
                        row[4].ToString(),
                        row[5].ToString()));
            }
        }
Ejemplo n.º 24
0
        /// <summary>
        /// The execute command.
        /// </summary>
        /// <param name="client">
        /// The client.
        /// </param>
        /// <param name="target">
        /// The target.
        /// </param>
        /// <param name="args">
        /// The args.
        /// </param>
        public override void ExecuteCommand(Client client, Identity target, string[] args)
        {
            if (args.Length >= 2)
            {
                if (args[1].ToLower() == "list")
                {
                    string filter = string.Empty;
                    if (args.Length > 2)
                    {
                        for (int i = 2; i < args.Length; i++)
                        {
                            if (filter.Length > 0)
                            {
                                filter = filter + " AND ";
                            }

                            if (filter.Length == 0)
                            {
                                filter = "WHERE ";
                            }

                            filter = filter + "name like '%" + args[i] + "%' ";
                        }
                    }

                    SqlWrapper sql = new SqlWrapper();
                    DataTable dt =
                        sql.ReadDatatable("SELECT Hash, Name FROM mobtemplate " + filter + " order by Name ASC");
                    client.SendChatText("List of mobtemplates: ");
                    foreach (DataRow row in dt.Rows)
                    {
                        client.SendChatText(row[0] + " " + row[1]);
                    }
                    return;
                }
            }

            if (args.Length == 3)
            {
                NonPlayerCharacterHandler.SpawnMonster(client, args[1], uint.Parse(args[2]));
                return;
            }
            this.CommandHelp(client);
        }
Ejemplo n.º 25
0
        /// <summary>
        /// Check if a certain character is on the clients authenticated account
        /// </summary>
        /// <param name="UserName">Client Username</param>
        /// <param name="CharacterID">Client CharacterId</param>
        public bool IsCharacterOnAccount(string UserName, UInt32 CharacterID)
        {
            SqlWrapper mySql = new SqlWrapper();

            DataTable dt = mySql.ReadDatatable("SELECT `Username` FROM `characters` WHERE ID = " + CharacterID);

            if (dt.Rows.Count == 0)
            {
                return(false);
            }
            else
            {
                if (UserName.ToLower() == ((string)dt.Rows[0][0]).ToLower())
                {
                    return(true);
                }
                return(false);
            }
            return(false); // I hope this works otherwise turn it true?
        }
Ejemplo n.º 26
0
 public override void ExecuteCommand(Client client, Identity target, string[] args)
 {
     if ((args.Length == 2) && (args[1].ToLower() != "list"))
     {
         VendorHandler.SpawnVendor(client, args[1]);
     }
     else
     {
         if (args.Length >= 2)
         {
             string filter = "";
             if (args.Length > 2)
             {
                 for (int i = 2; i < args.Length; i++)
                 {
                     if (filter.Length > 0)
                     {
                         filter = filter + " AND ";
                     }
                     if (filter.Length == 0)
                     {
                         filter = "WHERE ";
                     }
                     filter = filter + "name like '%" + args[i] + "%' ";
                 }
             }
             SqlWrapper sql = new SqlWrapper();
             DataTable dt =
                 sql.ReadDatatable("SELECT Hash, Name FROM vendortemplate " + filter + " order by Name ASC");
             client.SendChatText("List of vendortemplates: ");
             foreach (DataRow row in dt.Rows)
             {
                 client.SendChatText(row[0] + " " + row[1]);
             }
         }
     }
 }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="accountName"></param>
        /// <returns></returns>
        public static List<CharacterEntry> LoadCharacters(string accountName)
        {
            List<CharacterEntry> characters = new List<CharacterEntry>();
            SqlWrapper ms = new SqlWrapper();

            string SqlQuery =
                "SELECT `characters`.`ID`, `characters`.`Name`, `characters`.`playfield`, (SELECT `Value` FROM `characters_stats` WHERE `characters`.`ID` = `characters_stats`.`ID` AND `Stat` = 54) as level, (SELECT `Value` FROM `characters_stats` WHERE `characters`.`ID` = `characters_stats`.`ID` AND `Stat` = 4) as breed, (SELECT `Value` FROM `characters_stats` WHERE `characters`.`ID` = `characters_stats`.`ID` AND `Stat` = 59) as gender, (SELECT `Value` FROM `characters_stats` WHERE `characters`.`ID` = `characters_stats`.`ID` AND `Stat` = 60) as profession FROM `characters` WHERE `characters`.Username = '******'";
            DataTable dt = ms.ReadDatatable(SqlQuery);

            foreach (DataRow row in dt.Rows)
            {
                CharacterEntry charentry = new CharacterEntry();
                charentry.Id = (Int32)row["ID"];
                charentry.Name = ((string)row["Name"]).PadRight(11, '\u0000');
                charentry.Playfield = (Int32)row["playfield"];
                charentry.Level = (Int32)row["level"];
                charentry.Breed = (Int32)row["breed"];
                charentry.Gender = (Int32)row["gender"];
                charentry.Profession = (Int32)row["profession"];
                characters.Add(charentry);
            }
            return characters;
        }
Ejemplo n.º 28
0
        /// <summary>
        /// Read stat from Sql
        /// </summary>
        public void ReadStatFromSql()
        {
            if (this.DoNotDontWriteToSql)
            {
                return;
            }
            SqlWrapper sql = new SqlWrapper();
            int id = this.parent.Id;
            DataTable dt =
                sql.ReadDatatable(
                    "SELECT Value FROM " + this.parent.GetSqlTablefromDynelType() + " WHERE ID=" + id + " AND Stat="
                    + this.StatNumber + ";");

            if (dt.Rows.Count > 0)
            {
                this.Value = (Int32)dt.Rows[0][0];
            }
        }
Ejemplo n.º 29
0
 /// <summary>
 /// Read all stats from Sql
 /// </summary>
 public void ReadStatsfromSql()
 {
     SqlWrapper sql = new SqlWrapper();
     DataTable dt =
         sql.ReadDatatable(
             "SELECT Stat,Value FROM " + this.flags.Parent.GetSqlTablefromDynelType() + "_stats WHERE ID="
             + this.flags.Parent.Id); // Using Flags to address parent object
     foreach (DataRow row in dt.Rows)
     {
         this.SetBaseValue((Int32)row[0], (UInt32)((Int32)row[1]));
     }
 }
Ejemplo n.º 30
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="packet"></param>
        /// <param name="client"></param>
        public static void Read(byte[] packet, Client client)
        {
            PacketReader reader = new PacketReader(packet);

            Header header = reader.PopHeader();
            reader.PopByte();
            byte cmd = reader.PopByte();
            Identity target = reader.PopIdentity();
            int unknown = reader.PopInt();
            string cmdStr = "";
            byte CmdByte = 0;

            #region cmd args
            switch (cmd)
            {
                case 1:
                case 7:
                case 9:
                case 13:
                case 17:
                case 19:
                case 20:
                case 21:
                case 23:
                case 24:
                case 25:
                case 26:
                case 27:
                case 28:
                    short cmdStrLen = reader.PopShort();
                    cmdStr = reader.PopString(cmdStrLen);
                    break;
                case 10:
                    CmdByte = reader.PopByte();
                    break;
                default:
                    break;
            }
            reader.Finish();
            #endregion

            SqlWrapper ms = new SqlWrapper();
            DataTable dt;

            #region cmd handlers
            switch (cmd)
            {
                    #region /org create <name>
                case 1:
                    {
                        // org create
                        /* client wants to create organization
                         * name of org is CmdStr
                         */

                        string sqlQuery = "SELECT * FROM organizations WHERE Name='" + cmdStr + "'";
                        string guildName = null;
                        uint orgID = 0;
                        dt = ms.ReadDatatable(sqlQuery);
                        if (dt.Rows.Count > 0)
                        {
                            guildName = (string)dt.Rows[0]["Name"];
                        }

                        if (guildName == null)
                        {
                            client.SendChatText("You have created the guild: " + cmdStr);

                            string currentDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                            string sqlQuery2 =
                                "INSERT INTO organizations (Name, creation, LeaderID, GovernmentForm) VALUES ('"
                                + cmdStr + "', '" + currentDate + "', '" + client.Character.Id + "', '0')";
                            ms.SqlInsert(sqlQuery2);
                            string sqlQuery3 = "SELECT * FROM organizations WHERE Name='" + cmdStr + "'";
                            dt = ms.ReadDatatable(sqlQuery3);
                            if (dt.Rows.Count > 0)
                            {
                                orgID = (UInt32)dt.Rows[0]["ID"];
                            }

                            // Make sure the order of these next two lines is not swapped -NV
                            client.Character.Stats.ClanLevel.Set(0);
                            client.Character.OrgId = orgID;
                            break;
                        }
                        else
                        {
                            client.SendChatText("This guild already <font color=#DC143C>exists</font>");
                            break;
                        }
                    }
                    #endregion

                    #region /org ranks
                case 2:
                    // org ranks
                    //Displays Org Rank Structure.
                    /* Select governingform from DB, Roll through display from GovForm */
                    if (client.Character.OrgId == 0)
                    {
                        client.SendChatText("You're not in an organization!");
                        break;
                    }
                    string ranksSql = "SELECT GovernmentForm FROM organizations WHERE ID = " + client.Character.OrgId;
                    int governingForm = -1;
                    dt = ms.ReadDatatable(ranksSql);
                    if (dt.Rows.Count > 0)
                    {
                        governingForm = (Int32)dt.Rows[0]["GovernmentForm"];
                    }
                    client.SendChatText("Current Rank Structure: " + GetRankList(governingForm));
                    break;
                    #endregion

                    #region /org contract
                case 3:
                    // org contract
                    break;
                    #endregion

                    #region unknown org command 4
                case 4:
                    Console.WriteLine("Case 4 Started");
                    break;
                    #endregion

                    #region /org info
                case 5:
                    {
                        Client tPlayer = null;
                        if ((tPlayer = FindClient.FindClientById(target.Instance)) != null)
                        {
                            string orgDescription = "", orgObjective = "", orgHistory = "", orgLeaderName = "";
                            int orgGoverningForm = 0, orgLeaderID = 0;
                            dt = ms.ReadDatatable("SELECT * FROM organizations WHERE ID=" + tPlayer.Character.OrgId);

                            if (dt.Rows.Count > 0)
                            {
                                orgDescription = (string)dt.Rows[0]["Description"];
                                orgObjective = (string)dt.Rows[0]["Objective"];
                                orgHistory = (string)dt.Rows[0]["History"];
                                orgGoverningForm = (Int32)dt.Rows[0]["GovernmentForm"];
                                orgLeaderID = (Int32)dt.Rows[0]["LeaderID"];
                            }

                            dt = ms.ReadDatatable("SELECT Name FROM characters WHERE ID=" + orgLeaderID);
                            if (dt.Rows.Count > 0)
                            {
                                orgLeaderName = (string)dt.Rows[0][0];
                            }

                            string textGovForm = null;
                            if (orgGoverningForm == 0)
                            {
                                textGovForm = "Department";
                            }
                            else if (orgGoverningForm == 1)
                            {
                                textGovForm = "Faction";
                            }
                            else if (orgGoverningForm == 2)
                            {
                                textGovForm = "Republic";
                            }
                            else if (orgGoverningForm == 3)
                            {
                                textGovForm = "Monarchy";
                            }
                            else if (orgGoverningForm == 4)
                            {
                                textGovForm = "Anarchism";
                            }
                            else if (orgGoverningForm == 5)
                            {
                                textGovForm = "Feudalism";
                            }
                            else
                            {
                                textGovForm = "Department";
                            }
                            string orgRank = GetRank(orgGoverningForm, tPlayer.Character.Stats.ClanLevel.StatBaseValue);
                            PacketWriter packetWriter = new PacketWriter();
                            packetWriter.PushBytes(new byte[] { 0xDF, 0xDF });
                            packetWriter.PushShort(10);
                            packetWriter.PushShort(1);
                            packetWriter.PushShort(0);
                            packetWriter.PushInt(3086);
                            packetWriter.PushInt(client.Character.Id);
                            packetWriter.PushInt(0x64582A07);
                            packetWriter.PushIdentity(50000, tPlayer.Character.Id);
                            packetWriter.PushByte(0);
                            packetWriter.PushByte(2); // OrgServer case 0x02 (Org Info)
                            packetWriter.PushInt(0);
                            packetWriter.PushInt(0);
                            packetWriter.PushInt(0xDEAA); // Type (org)
                            packetWriter.PushUInt(tPlayer.Character.OrgId); // org ID
                            packetWriter.PushShort((short)tPlayer.Character.OrgName.Length);
                            packetWriter.PushBytes(Encoding.ASCII.GetBytes(tPlayer.Character.OrgName));
                            packetWriter.PushShort((short)orgDescription.Length);
                            packetWriter.PushBytes(Encoding.ASCII.GetBytes(orgDescription));
                            packetWriter.PushShort((short)orgObjective.Length);
                            packetWriter.PushBytes(Encoding.ASCII.GetBytes(orgObjective));
                            packetWriter.PushShort((short)orgHistory.Length);
                            packetWriter.PushBytes(Encoding.ASCII.GetBytes(orgHistory));
                            packetWriter.PushShort((short)textGovForm.Length);
                            packetWriter.PushBytes(Encoding.ASCII.GetBytes(textGovForm));
                            packetWriter.PushShort((short)orgLeaderName.Length);
                            packetWriter.PushBytes(Encoding.ASCII.GetBytes(orgLeaderName));
                            packetWriter.PushShort((short)orgRank.Length);
                            packetWriter.PushBytes(Encoding.ASCII.GetBytes(orgRank));
                            packetWriter.Push3F1Count(0);
                            byte[] reply = packetWriter.Finish();

                            client.SendCompressed(reply);
                        }
                    }
                    break;
                    #endregion

                    #region /org disband
                case 6:
                    break;
                    #endregion

                    #region /org startvote <text> <duration> <entries>
                case 7:
                    // org startvote <"text"> <duration(minutes)> <entries>
                    // arguments (<text> <duration> and <entries>) are in CmdStr
                    break;
                    #endregion

                    #region /org vote info
                case 8:
                    // org vote info
                    break;
                    #endregion

                    #region /org vote <entry>
                case 9:
                    // <entry> is CmdStr
                    break;
                    #endregion

                    #region /org promote
                case 10:
                    {
                        // some arg in CmdByte. No idea what it is

                        //create the target namespace t_promote
                        Client toPromote = null;
                        string promoteSql = "";
                        int targetOldRank = -1;
                        int targetNewRank = -1;
                        int newPresRank = -1;
                        int oldPresRank = 0;
                        if ((toPromote = FindClient.FindClientById(target.Instance)) != null)
                        {
                            //First we check if target is in the same org as you
                            if (toPromote.Character.OrgId != client.Character.OrgId)
                            {
                                //not in same org
                                client.SendChatText("Target is not in your organization!");
                                break;
                            }
                            //Target is in same org, are you eligible to promote?  Promoter Rank has to be TargetRank-2 or == 0
                            if ((client.Character.Stats.ClanLevel.Value
                                 == (toPromote.Character.Stats.ClanLevel.Value - 2))
                                || (client.Character.Stats.ClanLevel.Value == 0))
                            {
                                //Promoter is eligible. Start the process

                                //First we get the details about the org itself
                                promoteSql = "SELECT * FROM organizations WHERE ID = " + client.Character.OrgId;
                                dt = ms.ReadDatatable(promoteSql);

                                int promoteGovForm = -1;
                                string promotedToRank = "";
                                string demotedFromRank = "";

                                if (dt.Rows.Count > 0)
                                {
                                    promoteGovForm = (Int32)dt.Rows[0]["GovernmentForm"];
                                }

                                //Check if new rank == 0, if so, demote promoter
                                if ((targetOldRank - 1) == 0)
                                {
                                    /* This is a bit more complex.  Here we need to promote new president first
                                         * then we go about demoting old president
                                         * finally we set the new leader in Sql
                                         * Reset OrgName to set changes
                                         */

                                    // Set new President's Rank
                                    targetOldRank = toPromote.Character.Stats.ClanLevel.Value;
                                    targetNewRank = targetOldRank - 1;
                                    promotedToRank = GetRank(promoteGovForm, (uint)targetNewRank);
                                    toPromote.Character.Stats.ClanLevel.Set(targetNewRank);
                                    // Demote the old president
                                    oldPresRank = client.Character.Stats.ClanLevel.Value;
                                    newPresRank = oldPresRank + 1;
                                    demotedFromRank = GetRank(promoteGovForm, (uint)newPresRank);
                                    client.Character.Stats.ClanLevel.Set(newPresRank);
                                    //Change the leader id in Sql
                                    string newLeadSql = "UPDATE organizations SET LeaderID = " + toPromote.Character.Id
                                                        + " WHERE ID = " + toPromote.Character.OrgId;
                                    ms.SqlUpdate(newLeadSql);
                                    client.SendChatText(
                                        "You've passed leadership of the organization to: " + toPromote.Character.Name);
                                    toPromote.SendChatText(
                                        "You've been promoted to the rank of " + promotedToRank + " by "
                                        + client.Character.Name);
                                    break;
                                }
                                else
                                {
                                    //Just Promote
                                    targetOldRank = toPromote.Character.Stats.ClanLevel.Value;
                                    targetNewRank = targetOldRank - 1;
                                    promotedToRank = GetRank(promoteGovForm, (uint)targetNewRank);
                                    toPromote.Character.Stats.ClanLevel.Set(targetNewRank);
                                    client.SendChatText(
                                        "You've promoted " + toPromote.Character.Name + " to " + promotedToRank);
                                    toPromote.SendChatText(
                                        "You've been promoted to the rank of " + promotedToRank + " by "
                                        + client.Character.Name);
                                }
                            }
                            else
                            {
                                //Promoter not eligible to promote
                                client.SendChatText(
                                    "Your Rank is not high enough to promote " + toPromote.Character.Name);
                                break;
                            }
                        }
                        break;
                    }
                    #endregion

                    #region /org demote
                case 11:
                    // demote target player
                    //create the target namespace t_demote
                    Client toDemote = null;
                    string demoteSql = "";
                    int targetCurRank = -1;
                    int targetNewerRank = -1;
                    if ((toDemote = FindClient.FindClientById(target.Instance)) != null)
                    {
                        //First we check if target is in the same org as you
                        if (toDemote.Character.OrgId != client.Character.OrgId)
                        {
                            //not in same org
                            client.SendChatText("Target is not in your organization!");
                            break;
                        }
                        //Target is in same org, are you eligible to demote?  Promoter Rank has to be TargetRank-2 or == 0
                        if ((client.Character.Stats.GMLevel.Value == (toDemote.Character.Stats.ClanLevel.Value - 2))
                            || (client.Character.Stats.ClanLevel.Value == 0))
                        {
                            //Promoter is eligible. Start the process

                            //First we get the details about the org itself
                            demoteSql = "SELECT GovernmentForm FROM organizations WHERE ID = " + client.Character.OrgId;
                            dt = ms.ReadDatatable(demoteSql);
                            int demoteGovForm = -1;
                            string demotedToRank = "";
                            if (dt.Rows.Count > 0)
                            {
                                demoteGovForm = (Int32)dt.Rows[0]["GovernmentForm"];
                            }

                            //Check whether new rank would be lower than lowest for current govform
                            if ((targetCurRank + 1) > GetLowestRank(demoteGovForm))
                            {
                                client.SendChatText("You can't demote character any lower!");
                                break;
                            }
                            targetCurRank = toDemote.Character.Stats.GMLevel.Value;
                            targetNewerRank = targetCurRank + 1;
                            demotedToRank = GetRank(demoteGovForm, (uint)targetNewerRank);
                            toDemote.Character.Stats.ClanLevel.Set(targetNewerRank);
                            client.SendChatText("You've demoted " + toDemote.Character.Name + " to " + demotedToRank);
                            toDemote.SendChatText(
                                "You've been demoted to the rank of " + demotedToRank + " by " + client.Character.Name);
                            break;
                        }
                        else
                        {
                            //Promoter not eligible to promote
                            client.SendChatText("Your Rank is not high enough to demote " + toDemote.Character.Name);
                            break;
                        }
                    }
                    break;
                    #endregion

                    #region unknown org command 12
                case 12:
                    Console.WriteLine("Case 12 Started");
                    break;
                    #endregion

                    #region /org kick <name>
                case 13:
                    // kick <name> from org
                    // <name> is CmdStr

                    //create the t_player Client namespace, using CmdStr to find character id, in replacement of target.Instance
                    uint kickedFrom = client.Character.OrgId;
                    string kickeeSql = "SELECT * FROM characters WHERE Name = '" + cmdStr + "'";
                    int kickeeId = 0;
                    dt = ms.ReadDatatable(kickeeSql);
                    if (dt.Rows.Count > 0)
                    {
                        kickeeId = (Int32)dt.Rows[0]["ID"];
                    }

                    Client targetPlayer = null;
                    if ((targetPlayer = FindClient.FindClientById(kickeeId)) != null)
                    {
                        //Check if CmdStr is actually part of the org
                        uint kickeeOrgId = targetPlayer.Character.OrgId;
                        if (kickeeOrgId != client.Character.OrgId)
                        {
                            //Not part of Org. break out.
                            client.SendChatText(cmdStr + "is not a member of your organization!");
                            break;
                        }

                        //They are part of the org, so begin the processing...
                        //First we check if the player is online...
                        string onlineSql = "SELECT online FROM characters WHERE ID = " + client.Character.Id;
                        dt = ms.ReadDatatable(onlineSql);
                        int onlineStatus = 0;
                        if (dt.Rows.Count > 0)
                        {
                            onlineStatus = (Int32)dt.Rows[0][0];
                        }

                        if (onlineStatus == 0)
                        {
                            //Player isn't online. Org Kicks are processed in a different method
                            // TODO: Offline Org KICK
                            break;
                        }

                        //Player is online. Start the kick.
                        targetPlayer.Character.Stats.ClanLevel.Set(0);
                        targetPlayer.Character.OrgId = 0;
                        string kickedFromSql = "SELECT Name FROM organizations WHERE ID = " + client.Character.OrgId;
                        dt = ms.ReadDatatable(kickedFromSql);
                        string kickedFromName = "";
                        if (dt.Rows.Count > 0)
                        {
                            kickedFromName = (string)dt.Rows[0][0];
                        }
                        targetPlayer.SendChatText("You've been kicked from the organization " + kickedFromName);
                    }
                    // TODO: Offline Org KICK
                    break;
                    #endregion

                    #region /org invite
                case 14:
                    {
                        Client tPlayer = null;
                        if ((tPlayer = FindClient.FindClientById(target.Instance)) != null)
                        {
                            PacketWriter writer = new PacketWriter();
                            writer.PushBytes(new byte[] { 0xDF, 0xDF });
                            writer.PushShort(10);
                            writer.PushShort(1);
                            writer.PushShort(0);
                            writer.PushInt(3086); //Sender
                            writer.PushInt(tPlayer.Character.Id); //Receiver
                            writer.PushInt(0x64582A07); //Packet ID
                            writer.PushIdentity(50000, tPlayer.Character.Id); //Target Identity
                            writer.PushByte(0);
                            writer.PushByte(5); //OrgServer Case 0x05 (Invite)
                            writer.PushInt(0);
                            writer.PushInt(0);
                            writer.PushIdentity(0xDEAA, (int)client.Character.OrgId); // Type (org)
                            writer.PushShort((short)client.Character.OrgName.Length);
                            writer.PushBytes(Encoding.ASCII.GetBytes(client.Character.OrgName));
                            writer.PushInt(0);
                            byte[] reply = writer.Finish();

                            tPlayer.SendCompressed(reply);
                        }
                    }
                    break;
                    #endregion

                    #region Org Join
                case 15:
                    {
                        //target.Instance holds the OrgID of the Org wishing to be joined.
                        int orgIdtoJoin = target.Instance;
                        string JoinSql = "SELECT * FROM organizations WHERE ID = '" + orgIdtoJoin + "' LIMIT 1";
                        int gov_form = 0;
                        dt = ms.ReadDatatable(JoinSql);
                        if (dt.Rows.Count > 0)
                        {
                            gov_form = (Int32)dt.Rows[0]["GovernmentForm"];
                        }

                        // Make sure the order of these next two lines is not swapped -NV
                        client.Character.Stats.ClanLevel.Set(GetLowestRank(gov_form));
                        client.Character.OrgId = (uint)orgIdtoJoin;
                    }
                    break;
                    #endregion

                    #region /org leave
                case 16:
                    // org leave
                    // TODO: Disband org if it was leader that left org. -Suiv-
                    // I don't think a Disband happens if leader leaves. I don't think leader -can- leave without passing lead to another
                    // Something worth testing on Testlive perhaps ~Chaz
                    // Just because something happens on TL, doesnt mean its a good idea. Really tbh id prefer it if you had to explicitly type /org disband to disband rather than /org leave doing it... -NV
                    // Agreeing with NV.  Org Leader can't leave without passing lead on.  org disband requires /org disband to specifically be issued, with a Yes/No box.
                    string LeaveSql = "SELECT * FROM organizations WHERE ID = " + client.Character.OrgId;
                    int govern_form = 0;
                    dt = ms.ReadDatatable(LeaveSql);
                    if (dt.Rows.Count > 0)
                    {
                        govern_form = (Int32)dt.Rows[0]["GovernmentForm"];
                    }

                    if ((client.Character.Stats.ClanLevel.Value == 0) && (govern_form != 4))
                    {
                        client.SendChatText(
                            "Organization Leader cannot leave organization without Disbanding or Passing Leadership!");
                    }
                    else
                    {
                        client.Character.OrgId = 0;
                        client.SendChatText("You left the guild");
                    }
                    break;
                    #endregion

                    #region /org tax | /org tax <tax>
                case 17:
                    // gets or sets org tax
                    // <tax> is CmdStr
                    // if no <tax>, then just send chat text with current tax info

                    if (cmdStr == null)
                    {
                        client.SendChatText("The current organization tax rate is: ");
                        break;
                    }
                    else
                    {
                        break;
                    }
                    #endregion

                    #region /org bank
                case 18:
                    {
                        // org bank
                        dt = ms.ReadDatatable("SELECT * FROM organizations WHERE ID=" + client.Character.OrgId);
                        if (dt.Rows.Count > 0)
                        {
                            UInt64 bank_credits = (UInt64)dt.Rows[0]["Bank"];
                            client.SendChatText("Your bank has " + bank_credits + " credits in its account");
                        }
                    }
                    break;
                    #endregion

                    #region /org bank add <cash>
                case 19:
                    {
                        if (client.Character.OrgId == 0)
                        {
                            client.SendChatText("You are not in an organisation.");

                            break;
                        }

                        // org bank add <cash>
                        int minuscredits_fromplayer = Convert.ToInt32(cmdStr);
                        int characters_credits = client.Character.Stats.Cash.Value;

                        if (characters_credits < minuscredits_fromplayer)
                        {
                            client.SendChatText("You do not have enough Credits");
                        }
                        else
                        {
                            int total_Creditsspent = characters_credits - minuscredits_fromplayer;
                            client.Character.Stats.Cash.Set(total_Creditsspent);

                            ms.SqlUpdate(
                                "UPDATE `organizations` SET `Bank` = `Bank` + " + minuscredits_fromplayer
                                + " WHERE `ID` = " + client.Character.OrgId);
                            client.SendChatText("You have donated " + minuscredits_fromplayer + " to the organization");
                        }
                    }

                    break;
                    #endregion

                    #region /org bank remove <cash>
                case 20:
                    // org bank remove <cash>
                    // <cash> is CmdStr
                    // player wants to take credits from org bank
                    // only leader can do that
                    if ((client.Character.Stats.ClanLevel.Value != 0) || (client.Character.OrgId == 0))
                    {
                        client.SendChatText("You're not the leader of an Organization");
                        break;
                    }
                    int removeCredits = Convert.ToInt32(cmdStr);
                    long orgBank = 0;
                    dt = ms.ReadDatatable("SELECT Bank FROM organizations WHERE ID = " + client.Character.OrgId);
                    if (dt.Rows.Count > 0)
                    {
                        orgBank = (Int64)dt.Rows[0][0];
                    }
                    if (removeCredits > orgBank)
                    {
                        client.SendChatText("Not enough credits in Organization Bank!");
                        break;
                    }
                    else
                    {
                        long neworgbank = orgBank - removeCredits;
                        int existingcreds = 0;
                        existingcreds = client.Character.Stats.Cash.Value;
                        int newcreds = existingcreds + removeCredits;
                        ms.SqlUpdate(
                            "UPDATE organizations SET Bank = " + neworgbank + " WHERE ID = " + client.Character.OrgId);
                        client.Character.Stats.Cash.Set(newcreds);
                        client.SendChatText("You've removed " + removeCredits + " credits from the organization bank");
                    }
                    break;
                    #endregion

                    #region /org bank paymembers <cash>
                case 21:
                    // <cash> is CmdStr
                    // give <cash> credits to every org member
                    // credits are taken from org bank
                    // only leader can do it
                    break;
                    #endregion

                    #region /org debt
                case 22:
                    // send player text about how big is his/her tax debt to org
                    break;
                    #endregion

                    #region /org history <text>
                case 23:
                    {
                        if (client.Character.Stats.ClanLevel.Value == 0)
                        {
                            // org history <history text>
                            ms.SqlUpdate(
                                "UPDATE organizations SET history = '" + cmdStr + "' WHERE ID = '"
                                + client.Character.OrgId + "'");
                            client.SendChatText("History Updated");
                        }
                        else
                        {
                            client.SendChatText("You must be the Organization Leader to perform this command!");
                        }
                    }
                    break;
                    #endregion

                    #region /org objective <text>
                case 24:
                    {
                        if (client.Character.Stats.ClanLevel.Value == 0)
                        {
                            // org objective <objective text>
                            ms.SqlUpdate(
                                "UPDATE organizations SET objective = '" + cmdStr + "' WHERE ID = '"
                                + client.Character.OrgId + "'");
                            client.SendChatText("Objective Updated");
                        }
                        else
                        {
                            client.SendChatText("You must be the Organization Leader to perform this command!");
                        }
                    }
                    break;
                    #endregion

                    #region /org description <text>
                case 25:
                    {
                        if (client.Character.Stats.ClanLevel.Value == 0)
                        {
                            // org description <description text>
                            ms.SqlUpdate(
                                "UPDATE organizations SET description = '" + cmdStr + "' WHERE ID = '"
                                + client.Character.OrgId + "'");
                            client.SendChatText("Description Updated");
                        }
                        else
                        {
                            client.SendChatText("You must be the Organization Leader to perform this command!");
                        }
                    }
                    break;
                    #endregion

                    #region /org name <text>
                case 26:
                    {
                        // org name <name>
                        /* Renames Organization
                         * Checks for Existing Orgs with similar name to stop crash
                         * Chaz
                         */
                        if (client.Character.Stats.ClanLevel.Value == 0)
                        {
                            string SqlQuery26 = "SELECT * FROM organizations WHERE Name LIKE '" + cmdStr + "' LIMIT 1";
                            string CurrentOrg = null;
                            dt = ms.ReadDatatable(SqlQuery26);
                            if (dt.Rows.Count > 0)
                            {
                                CurrentOrg = (string)dt.Rows[0]["Name"];
                            }

                            if (CurrentOrg == null)
                            {
                                string SqlQuery27 = "UPDATE organizations SET Name = '" + cmdStr + "' WHERE ID = '"
                                                    + client.Character.OrgId + "'";
                                ms.SqlUpdate(SqlQuery27);
                                client.SendChatText("Organization Name Changed to: " + cmdStr);

                                // Forces reloading of org name and the like
                                // XXXX TODO: Make it reload for all other members in the org
                                client.Character.OrgId = client.Character.OrgId;
                                break;
                            }
                            else
                            {
                                client.SendChatText("An Organization already exists with that name");
                                break;
                            }
                        }
                        else
                        {
                            client.SendChatText("You must be the organization leader to perform this command!");
                        }
                        break;
                    }
                    #endregion

                    #region /org governingform <text>
                case 27:
                    {
                        // org governingform <form>
                        /* Current Governing Forms:
                         * Department, Faction, Republic, Monarchy, Anarchism, Feudalism
                         */
                        //Check on whether your President or not
                        if (client.Character.Stats.ClanLevel.Value == 0)
                        {
                            //first we drop the case on the input, just to be sure.
                            Int32 GovFormNum = -1;
                            if (cmdStr == null)
                            {
                                //list gov forms
                                client.SendChatText(
                                    "List of Accepted Governing Forms is: department, faction, republic, monarchy, anarchism, feudalism");
                                break;
                            }
                            //was correct input passed?
                            switch (cmdStr.ToLower())
                            {
                                case "department":
                                    GovFormNum = 0;
                                    break;
                                case "faction":
                                    GovFormNum = 1;
                                    break;
                                case "republic":
                                    GovFormNum = 2;
                                    break;
                                case "monarchy":
                                    GovFormNum = 3;
                                    break;
                                case "anarchism":
                                    GovFormNum = 4;
                                    break;
                                case "feudalism":
                                    GovFormNum = 5;
                                    break;
                                default:
                                    client.SendChatText(cmdStr + " Is an invalid Governing Form!");
                                    client.SendChatText(
                                        "Accepted Governing Forms are: department, faction, republic, monarchy, anarchism, feudalism");
                                    break;
                            }
                            if (GovFormNum != -1)
                            {
                                ms.SqlUpdate(
                                    "UPDATE organizations SET GovernmentForm = '" + GovFormNum + "' WHERE ID = '"
                                    + client.Character.OrgId + "'");
                                foreach (int currentCharId in OrgMisc.GetOrgMembers(client.Character.OrgId, true))
                                {
                                    client.Character.Stats.ClanLevel.Set(GetLowestRank(GovFormNum));
                                }
                                client.SendChatText("Governing Form is now: " + cmdStr);
                                break;
                            }
                        }
                        else
                        {
                            //Haha! You're not the org leader!
                            client.SendChatText("You must be the Org Leader to perform this command");
                            break;
                        }
                    }
                    break;
                    #endregion

                    #region /org stopvote <text>
                case 28:
                    // <text> is CmdStr
                    break;
                    #endregion

                    #region unknown command
                default:
                    break;
                    #endregion
            }
            #endregion

            reader.Finish();
        }
        public static void Read(byte[] packet, Client client)
        {
            SqlWrapper mys = new SqlWrapper();

            // Packet Reader Unknown Values are Returning 0 Integers, Unable to Store Needed Packet data To Reply.

            #region PacketReader
            PacketReader packetReader = new PacketReader(packet);
            Header m_header = packetReader.PopHeader(); // 0 - 28
            byte unknown = packetReader.PopByte(); // 29
            int actionNum = packetReader.PopInt(); // 30 - 33
            int unknown1 = packetReader.PopInt(); // 34 - 37
            Identity m_ident = packetReader.PopIdentity(); // 38 - 35
            int unknown2 = packetReader.PopInt(); // 36 - 39
            int unknown3 = packetReader.PopInt(); // 40 - 43
            short unknown4 = packetReader.PopShort(); // 44 - 45
            #endregion

            switch (actionNum)
            {
                    #region Cast nano
                case 19: // Cast nano
                    {
                        // CastNanoSpell
                        PacketWriter castNanoSpell = new PacketWriter();
                        castNanoSpell.PushByte(0xDF);
                        castNanoSpell.PushByte(0xDF);
                        castNanoSpell.PushShort(10);
                        castNanoSpell.PushShort(1);
                        castNanoSpell.PushShort(0);
                        castNanoSpell.PushInt(3086);
                        castNanoSpell.PushInt(client.Character.Id);
                        castNanoSpell.PushInt(0x25314D6D);
                        castNanoSpell.PushIdentity(50000, client.Character.Id);
                        castNanoSpell.PushByte(0);
                        castNanoSpell.PushInt(unknown3); // Nano ID
                        castNanoSpell.PushIdentity(m_ident); // Target
                        castNanoSpell.PushInt(0);
                        castNanoSpell.PushIdentity(50000, client.Character.Id); // Caster
                        byte[] castNanoSpellA = castNanoSpell.Finish();
                        Announce.Playfield(client.Character.PlayField, castNanoSpellA);

                        // CharacterAction 107
                        PacketWriter characterAction107 = new PacketWriter();
                        characterAction107.PushByte(0xDF);
                        characterAction107.PushByte(0xDF);
                        characterAction107.PushShort(10);
                        characterAction107.PushShort(1);
                        characterAction107.PushShort(0);
                        characterAction107.PushInt(3086);
                        characterAction107.PushInt(client.Character.Id);
                        characterAction107.PushInt(0x5E477770);
                        characterAction107.PushIdentity(50000, client.Character.Id);
                        characterAction107.PushByte(0);
                        characterAction107.PushInt(107);
                        characterAction107.PushInt(0);
                        characterAction107.PushInt(0);
                        characterAction107.PushInt(0);
                        characterAction107.PushInt(1);
                        characterAction107.PushInt(unknown3);
                        characterAction107.PushShort(0);
                        byte[] characterAction107A = characterAction107.Finish();
                        Announce.Playfield(client.Character.PlayField, characterAction107A);

                        // CharacterAction 98
                        PacketWriter characterAction98 = new PacketWriter();
                        characterAction98.PushByte(0xDF);
                        characterAction98.PushByte(0xDF);
                        characterAction98.PushShort(10);
                        characterAction98.PushShort(1);
                        characterAction98.PushShort(0);
                        characterAction98.PushInt(3086);
                        characterAction98.PushInt(client.Character.Id);
                        characterAction98.PushInt(0x5E477770);
                        characterAction98.PushIdentity(m_ident);
                        characterAction98.PushByte(0);
                        characterAction98.PushInt(98);
                        characterAction98.PushInt(0);
                        characterAction98.PushInt(0xCF1B);
                        characterAction98.PushInt(unknown3);
                        characterAction98.PushInt(client.Character.Id);
                        characterAction98.PushInt(0x249F0); // duration?
                        characterAction98.PushShort(0);
                        byte[] characterAction98A = characterAction98.Finish();
                        Announce.Playfield(client.Character.PlayField, characterAction98A);
                    }
                    break;
                    #endregion

                    #region search
                    /* this is here to prevent server crash that is caused by
                 * search action if server doesn't reply if something is
                 * found or not */
                case 66: // If action == search
                    {
                        /* Msg 110:136744723 = "No hidden objects found." */
                        client.SendFeedback(110, 136744723);
                    }
                    break;
                    #endregion

                    #region info
                case 105: // If action == Info Request
                    {
                        Client tPlayer = null;
                        if ((tPlayer = FindClient.FindClientById(m_ident.Instance)) != null)
                        {
                            #region Titles
                            uint LegacyScore = tPlayer.Character.Stats.PvpRating.StatBaseValue;
                            string LegacyTitle = null;
                            if (LegacyScore < 1400)
                            {
                                LegacyTitle = "";
                            }
                            else if (LegacyScore < 1500)
                            {
                                LegacyTitle = "Freshman";
                            }
                            else if (LegacyScore < 1600)
                            {
                                LegacyTitle = "Rookie";
                            }
                            else if (LegacyScore < 1700)
                            {
                                LegacyTitle = "Apprentice";
                            }
                            else if (LegacyScore < 1800)
                            {
                                LegacyTitle = "Novice";
                            }
                            else if (LegacyScore < 1900)
                            {
                                LegacyTitle = "Neophyte";
                            }
                            else if (LegacyScore < 2000)
                            {
                                LegacyTitle = "Experienced";
                            }
                            else if (LegacyScore < 2100)
                            {
                                LegacyTitle = "Expert";
                            }
                            else if (LegacyScore < 2300)
                            {
                                LegacyTitle = "Master";
                            }
                            else if (LegacyScore < 2500)
                            {
                                LegacyTitle = "Champion";
                            }
                            else
                            {
                                LegacyTitle = "Grand Master";
                            }
                            #endregion

                            int orgGoverningForm = 0;
                            SqlWrapper ms = new SqlWrapper();
                            DataTable dt =
                                ms.ReadDatatable(
                                    "SELECT `GovernmentForm` FROM organizations WHERE ID=" + tPlayer.Character.OrgId);

                            if (dt.Rows.Count > 0)
                            {
                                orgGoverningForm = (Int32)dt.Rows[0][0];
                            }

                            string orgRank = OrgClient.GetRank(
                                orgGoverningForm, tPlayer.Character.Stats.ClanLevel.StatBaseValue);
                            // Uses methods in ZoneEngine\PacketHandlers\OrgClient.cs
                            /* Known packetFlags--
                             * 0x40 - No org | 0x41 - Org | 0x43 - Org and towers | 0x47 - Org, towers, player has personal towers | 0x50 - No pvp data shown
                             * Bitflags--
                             * Bit0 = hasOrg, Bit1 = orgTowers, Bit2 = personalTowers, Bit3 = (Int32) time until supression changes (Byte) type of supression level?, Bit4 = noPvpDataShown, Bit5 = hasFaction, Bit6 = ?, Bit 7 = null.
                            */
                            byte packetFlags = 0x40; // Player has no Org
                            if (tPlayer.Character.OrgId != 0)
                            {
                                packetFlags = 0x41; // Player has Org, no towers
                            }
                            PacketWriter infoPacket = new PacketWriter();

                            // Start packet header
                            infoPacket.PushByte(0xDF);
                            infoPacket.PushByte(0xDF);
                            infoPacket.PushShort(10);
                            infoPacket.PushShort(1);
                            infoPacket.PushShort(0);
                            infoPacket.PushInt(3086); // sender (server ID)
                            infoPacket.PushInt(client.Character.Id); // receiver 
                            infoPacket.PushInt(0x4D38242E); // packet ID
                            infoPacket.PushIdentity(50000, tPlayer.Character.Id); // affected identity
                            infoPacket.PushByte(0); // ?
                            // End packet header

                            infoPacket.PushByte(packetFlags); // Based on flags above
                            infoPacket.PushByte(1); // esi_001?
                            infoPacket.PushByte((byte)tPlayer.Character.Stats.Profession.Value); // Profession
                            infoPacket.PushByte((byte)tPlayer.Character.Stats.Level.Value); // Level
                            infoPacket.PushByte((byte)tPlayer.Character.Stats.TitleLevel.Value); // Titlelevel
                            infoPacket.PushByte((byte)tPlayer.Character.Stats.VisualProfession.Value);
                            // Visual Profession
                            infoPacket.PushShort(0); // Side XP Bonus
                            infoPacket.PushUInt(tPlayer.Character.Stats.Health.Value); // Current Health (Health)
                            infoPacket.PushUInt(tPlayer.Character.Stats.Life.Value); // Max Health (Life)
                            infoPacket.PushInt(0); // BreedHostility?
                            infoPacket.PushUInt(tPlayer.Character.OrgId); // org ID
                            infoPacket.PushShort((short)tPlayer.Character.FirstName.Length);
                            infoPacket.PushBytes(Encoding.ASCII.GetBytes(tPlayer.Character.FirstName));
                            infoPacket.PushShort((short)tPlayer.Character.LastName.Length);
                            infoPacket.PushBytes(Encoding.ASCII.GetBytes(tPlayer.Character.LastName));
                            infoPacket.PushShort((short)LegacyTitle.Length);
                            infoPacket.PushBytes(Encoding.ASCII.GetBytes(LegacyTitle));
                            infoPacket.PushShort(0); // Title 2

                            // If receiver is in the same org as affected identity, whom is not orgless, send org rank and city playfield
                            if ((client.Character.OrgId == tPlayer.Character.OrgId) && (tPlayer.Character.OrgId != 0))
                            {
                                infoPacket.PushShort((short)orgRank.Length);
                                infoPacket.PushBytes(Encoding.ASCII.GetBytes(orgRank));
                                infoPacket.PushInt(0);
                                //infoPacket.PushIdentity(0, 0); // City (50201, Playfield) // Pushed 1 zero to much and screwed info for characters in orgs, but I´ll leave it for later just incase.
                            }

                            infoPacket.PushUInt(tPlayer.Character.Stats.InvadersKilled.Value); // Invaders Killed
                            infoPacket.PushUInt(tPlayer.Character.Stats.KilledByInvaders.Value); // Killed by Invaders
                            infoPacket.PushUInt(tPlayer.Character.Stats.AlienLevel.Value); // Alien Level
                            infoPacket.PushUInt(tPlayer.Character.Stats.PvpDuelKills.Value); // Pvp Duel Kills 
                            infoPacket.PushUInt(tPlayer.Character.Stats.PvpDuelDeaths.Value); // Pvp Duel Deaths
                            infoPacket.PushUInt(tPlayer.Character.Stats.PvpProfessionDuelDeaths.Value);
                            // Pvp Profession Duel Kills 
                            infoPacket.PushUInt(tPlayer.Character.Stats.PvpRankedSoloKills.Value); // Pvp Solo Kills
                            infoPacket.PushUInt(tPlayer.Character.Stats.PvpRankedSoloDeaths.Value); // Pvp Team Kills
                            infoPacket.PushUInt(tPlayer.Character.Stats.PvpSoloScore.Value); // Pvp Solo Score
                            infoPacket.PushUInt(tPlayer.Character.Stats.PvpTeamScore.Value); // Pvp Team Score
                            infoPacket.PushUInt(tPlayer.Character.Stats.PvpDuelScore.Value); // Pvp Duel Score

                            byte[] infoPacketA = infoPacket.Finish();
                            client.SendCompressed(infoPacketA);
                        }
                        else
                        {
                            NonPlayerCharacterClass npc =
                                (NonPlayerCharacterClass)FindDynel.FindDynelById(m_ident.Type, m_ident.Instance);
                            if (npc != null)
                            {
                                PacketWriter infoPacket = new PacketWriter();

                                // Start packet header
                                infoPacket.PushByte(0xDF);
                                infoPacket.PushByte(0xDF);
                                infoPacket.PushShort(10);
                                infoPacket.PushShort(1);
                                infoPacket.PushShort(0);
                                infoPacket.PushInt(3086); // sender (server ID)
                                infoPacket.PushInt(client.Character.Id); // receiver 
                                infoPacket.PushInt(0x4D38242E); // packet ID
                                infoPacket.PushIdentity(50000, npc.Id); // affected identity
                                infoPacket.PushByte(0); // ?
                                // End packet header

                                infoPacket.PushByte(0x50); // npc's just have 0x50
                                infoPacket.PushByte(1); // esi_001?
                                infoPacket.PushByte((byte)npc.Stats.Profession.Value); // Profession
                                infoPacket.PushByte((byte)npc.Stats.Level.Value); // Level
                                infoPacket.PushByte((byte)npc.Stats.TitleLevel.Value); // Titlelevel
                                infoPacket.PushByte((byte)npc.Stats.VisualProfession.Value); // Visual Profession

                                infoPacket.PushShort(0); // no idea for npc's
                                infoPacket.PushUInt(npc.Stats.Health.Value); // Current Health (Health)
                                infoPacket.PushUInt(npc.Stats.Life.Value); // Max Health (Life)
                                infoPacket.PushInt(0); // BreedHostility?
                                infoPacket.PushUInt(0); // org ID
                                infoPacket.PushShort(0);
                                infoPacket.PushShort(0);
                                infoPacket.PushShort(0);
                                infoPacket.PushShort(0);
                                infoPacket.PushInt(0x499602d2);
                                infoPacket.PushInt(0x499602d2);
                                infoPacket.PushInt(0x499602d2);
                                byte[] infoPacketA = infoPacket.Finish();
                                client.SendCompressed(infoPacketA);
                            }
                        }
                    }
                    break;
                    #endregion

                    #region logout
                case 120: // If action == Logout
                    {
                        //Start 30 second logout timer if client is not a GM (statid 215)
                        if (client.Character.Stats.GMLevel.Value == 0)
                        {
                            client.startLogoutTimer();
                        }
                        else // If client is a GM, disconnect without timer
                        {
                            client.Server.DisconnectClient(client);
                        }
                    }
                    break;
                case 121: // If action == Stop Logout
                    {
                        //Stop current logout timer and send stop logout packet
                        client.Character.UpdateMoveType((byte)client.Character.PreviousMoveMode);
                        client.CancelLogOut();
                    }
                    break;
                    #endregion

                    #region stand
                case 87: // If action == Stand
                    {
                        client.Character.UpdateMoveType(37);
                        //Send stand up packet, and cancel timer/send stop logout packet if timer is enabled
                        client.StandCancelLogout();
                    }
                    break;
                    #endregion

                    #region Team
                case 22: //Kick Team Member
                    {
                    }
                    break;
                case 24: //Leave Team
                    {
                        TeamClass team = new TeamClass();
                        team.LeaveTeam(client);
                    }
                    break;
                case 25: //Transfer Team Leadership
                    {
                    }
                    break;
                case 26: //Team Join Request
                    {
                        // Send Team Invite Request To Target Player

                        TeamClass team = new TeamClass();
                        team.SendTeamRequest(client, m_ident);
                    }
                    break;
                case 28: //Request Reply
                    {
                        // Check if positive or negative response

                        // if positive

                        TeamClass team = new TeamClass();
                        uint teamID = TeamClass.GenerateNewTeamId(client, m_ident);

                        // Destination Client 0 = Sender, 1 = Reciever

                        // Reciever Packets
                        ///////////////////

                        // CharAction 15
                        team.TeamRequestReply(client, m_ident);
                        // CharAction 23
                        team.TeamRequestReplyCharacterAction23(client, m_ident);

                        // TeamMember Packet
                        team.TeamReplyPacketTeamMember(1, client, m_ident, "Member1");
                        // TeamMemberInfo Packet
                        team.TeamReplyPacketTeamMemberInfo(1, client, m_ident);
                        // TeamMember Packet
                        team.TeamReplyPacketTeamMember(1, client, m_ident, "Member2");

                        // Sender Packets
                        /////////////////

                        // TeamMember Packet
                        team.TeamReplyPacketTeamMember(0, client, m_ident, "Member1");
                        // TeamMemberInfo Packet
                        team.TeamReplyPacketTeamMemberInfo(0, client, m_ident);
                        // TeamMember Packet
                        team.TeamReplyPacketTeamMember(0, client, m_ident, "Member2");
                    }
                    break;
                    #endregion

                    #region Delete Item
                case 0x70:
                    mys.SqlDelete(
                        "DELETE FROM " + client.Character.GetSqlTablefromDynelType() + "inventory WHERE placement="
                        + m_ident.Instance.ToString() + " AND container=" + m_ident.Type.ToString());
                    InventoryEntries i_del = client.Character.GetInventoryAt(m_ident.Instance);
                    client.Character.Inventory.Remove(i_del);
                    byte[] action2 = new byte[0x37];
                    Array.Copy(packet, action2, 0x37);
                    action2[8] = 0x00;
                    action2[9] = 0x00;
                    action2[10] = 0x0C;
                    action2[11] = 0x0E;
                    client.SendCompressed(action2);
                    break;
                    #endregion

                    #region Split item
                case 0x34:
                    int nextid = client.Character.GetNextFreeInventory(m_ident.Type);
                    InventoryEntries i = client.Character.GetInventoryAt(m_ident.Instance);
                    i.Item.MultipleCount -= unknown3;
                    InventoryEntries i2 = new InventoryEntries();
                    i2.Item = i.Item.ShallowCopy();
                    i2.Item.MultipleCount = unknown3;
                    i2.Placement = nextid;
                    client.Character.Inventory.Add(i2);
                    client.Character.WriteInventoryToSql();
                    break;
                    #endregion

                    #region Join item
                case 0x35:
                    InventoryEntries j1 = client.Character.GetInventoryAt(m_ident.Instance);
                    InventoryEntries j2 = client.Character.GetInventoryAt(unknown3);
                    j1.Item.MultipleCount += j2.Item.MultipleCount;
                    client.Character.Inventory.Remove(j2);
                    client.Character.WriteInventoryToSql();

                    byte[] joined = new byte[0x37];
                    Array.Copy(packet, joined, 0x37);
                    joined[8] = 0x00;
                    joined[9] = 0x00;
                    joined[10] = 0x0C;
                    joined[11] = 0x0E;
                    client.SendCompressed(joined);
                    break;
                    #endregion

                    #region Sneak Action
                    // ###################################################################################
                    // Spandexpants: This is all i have done so far as to make sneak turn on and off, 
                    // currently i cannot find a missing packet or link which tells the server the player
                    // has stopped sneaking, hidden packet or something, will come back to later.
                    // ###################################################################################

                    // Sneak Packet Received

                case 163:
                    {
                        PacketWriter Sneak = new PacketWriter();
                        // TODO: IF SNEAKING IS ALLOWED RUN THIS CODE.
                        // Send Action 162 : Enable Sneak
                        Sneak.PushByte(0xDF);
                        Sneak.PushByte(0xDF);
                        Sneak.PushShort(0xA);
                        Sneak.PushShort(1);
                        Sneak.PushShort(0);
                        Sneak.PushInt(3086); // Send 
                        Sneak.PushInt(client.Character.Id); // Reciever
                        Sneak.PushInt(0x5e477770); // Packet ID
                        Sneak.PushIdentity(50000, client.Character.Id); // TYPE / ID
                        Sneak.PushInt(0);
                        Sneak.PushByte(0xA2); // Action ID
                        Sneak.PushInt(0);
                        Sneak.PushInt(0);
                        Sneak.PushInt(0);
                        Sneak.PushInt(0);
                        Sneak.PushInt(0);
                        Sneak.PushShort(0);
                        byte[] sneakpacket = Sneak.Finish();
                        client.SendCompressed(sneakpacket);
                        // End of Enable sneak
                        // TODO: IF SNEAKING IS NOT ALLOWED SEND REJECTION PACKET
                    }
                    break;
                    #endregion

                    #region Use Item on Item
                case 81:
                    {
                        Identity item1 = new Identity();
                        Identity item2 = new Identity();

                        item1.Type = m_ident.Type;
                        item1.Instance = m_ident.Instance;

                        item2.Type = unknown2;
                        item2.Instance = unknown3;

                        Tradeskill cts = new Tradeskill(client, item1.Instance, item2.Instance);
                        cts.ClickBuild();
                        break;
                    }
                    #endregion

                    #region Change Visual Flag
                case 166:
                    {
                        client.Character.Stats.VisualFlags.Set(unknown3);
                        // client.SendChatText("Setting Visual Flag to "+unknown3.ToString());
                        AppearanceUpdate.AnnounceAppearanceUpdate(client.Character);
                        break;
                    }
                    #endregion

                    #region Tradeskill Source Changed
                case 0xdc:
                    TradeSkillReceiver.TradeSkillSourceChanged(client, unknown2, unknown3);
                    break;
                    #endregion

                    #region Tradeskill Target Changed
                case 0xdd:
                    TradeSkillReceiver.TradeSkillTargetChanged(client, unknown2, unknown3);
                    break;
                    #endregion

                    #region Tradeskill Build Pressed
                case 0xde:
                    TradeSkillReceiver.TradeSkillBuildPressed(client, m_ident.Instance);
                    break;
                    #endregion

                    #region default
                default:
                    {
                        byte[] action = new byte[0x37];
                        Array.Copy(packet, action, 0x37);
                        action[8] = 0x00;
                        action[9] = 0x00;
                        action[10] = 0x0C;
                        action[11] = 0x0E;
                        Announce.Playfield(client.Character.PlayField, action);
                    }
                    break;
                    #endregion
            }
            packetReader.Finish();
        }
 public bool LoadTemplate(string hash)
 {
     SqlWrapper sqlWrapper = new SqlWrapper();
     DataTable dataTable = sqlWrapper.ReadDatatable("SELECT * from vendortemplate WHERE HASH='" + hash + "'");
     if (dataTable.Rows.Count > 0)
     {
         this.TemplateId = (Int32)dataTable.Rows[0]["itemtemplate"];
         this.Name = (string)dataTable.Rows[0]["Name"];
         AOItem item = ItemHandler.GetItemTemplate(this.TemplateId);
         foreach (AOItemAttribute ia in item.Stats)
         {
             this.Stats.SetStatValueByName(ia.Stat, (uint)ia.Value);
         }
         sqlWrapper.sqlclose();
         this.FillInventory();
         return true;
     }
     return false;
 }
 private string GetLoginPassword(string RecvLogin)
 {
     SqlWrapper ms = new SqlWrapper();
     string PasswdL = string.Empty;
     DataTable dt = ms.ReadDatatable("SELECT Password FROM login WHERE Username = "******"'" + RecvLogin + "'");
     foreach (DataRow row in dt.Rows)
     {
         PasswdL = (string) row[0];
     }
     return PasswdL;
 }
        /// <summary>
        /// Check if a certain character is on the clients authenticated account
        /// </summary>
        /// <param name="UserName">Client Username</param>
        /// <param name="CharacterID">Client CharacterId</param>
        public bool IsCharacterOnAccount(string UserName, UInt32 CharacterID)
        {
            SqlWrapper mySql = new SqlWrapper();

            DataTable dt = mySql.ReadDatatable("SELECT `Username` FROM `characters` WHERE ID = " + CharacterID);
            if (dt.Rows.Count == 0)
            {
                return false;
            }
            else
            {
                if (UserName.ToLower() == ((string) dt.Rows[0][0]).ToLower())
                {
                    return true;
                }
                return false;
            }
            return false; // I hope this works otherwise turn it true?
        }
Ejemplo n.º 35
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="client"></param>
        /// <param name="accountName"></param>
        public void SendPacket(Client client, string accountName)
        {
            #region Expansions Checker
            Int32 expansions = 0;
            Int32 allowedCharacters = 0;
            /* This checks your expansions and
               number of characters allowed (num. of chars doesn't work)*/
            string sqlQuery = "SELECT `Expansions`,`Allowed_Characters` FROM `login` WHERE Username = '******'";
            SqlWrapper ms = new SqlWrapper();
            DataTable dt = ms.ReadDatatable(sqlQuery);
            if (dt.Rows.Count > 0)
            {
                expansions = Int32.Parse((string)dt.Rows[0][0]);
                allowedCharacters = (Int32)dt.Rows[0][1];
            }
            #endregion

            List<CharacterEntry> characters = CharacterList.LoadCharacters(accountName);
            PacketWriter pwriter = new PacketWriter();

            pwriter.PushByte(0xDF);
            pwriter.PushByte(0xDF);
            pwriter.PushShort(1); // packet type
            pwriter.PushShort(1); // ?
            pwriter.PushShort(0); // packet length (writer will take care of this)
            pwriter.PushInt(1);
            pwriter.PushInt(0x615B);
            pwriter.PushInt(0xE);
            pwriter.PushInt(characters.Count); // number of characters
            foreach (CharacterEntry character in characters)
            {
                pwriter.PushInt(4); // ?
                pwriter.PushInt(character.Id); // character ID

                // PlayfieldProxy starts
                pwriter.PushByte(0x61); // PlayfieldProxy version
                pwriter.PushIdentity(0xC79D, character.Playfield);
                pwriter.PushInt(1);
                pwriter.PushInt(0);
                pwriter.PushIdentity(0, 0);
                // PlayfieldProxy ends
                // TODO: what is it?
                pwriter.PushInt(1); // ?

                // CharacterInfo starts
                pwriter.PushInt(4); // CharacterInfo version
                // if CharacterInfo version == 2
                {
                    // pwriter.PushInt(character.Breed);
                    // pwriter.PushInt(character.Gender);
                    // pwriter.PushBytes(Encoding.ASCII.GetBytes(character.Name.PadRight(0x20,char.MinValue)));
                }
                // else
                {
                    pwriter.PushInt(character.Id); // character ID
                    {
                        // if there is problem with name
                        //pwriter.PushInt(256); //(will set name to "ERROR-CHANGE-NAME")

                        // if name is ok
                        pwriter.PushInt(character.Name.Length);
                        pwriter.PushBytes(Encoding.ASCII.GetBytes(character.Name));
                    }
                    pwriter.PushInt(character.Breed);
                    pwriter.PushInt(character.Gender);
                    pwriter.PushInt(character.Profession);
                    pwriter.PushInt(character.Level);
                    {
                        // lets just leave it like that for now..
                        string areaName = "area unknown";
                        pwriter.PushInt(areaName.Length);
                        pwriter.PushBytes(Encoding.ASCII.GetBytes(areaName));
                    }
                    // TODO: What are these?
                    pwriter.PushInt(0); // ?
                    pwriter.PushInt(0); // some string (int is string length)
                    // if CharacterVersion > 3
                    {
                        // TODO: what are these 3 ints?
                        pwriter.PushInt(0); // ?
                        pwriter.PushInt(0); // ?
                        pwriter.PushInt(0); // ?
                    }
                    // CharacterInfo ends
                }
            }
            // TODO: find out what this really is
            pwriter.PushInt(allowedCharacters); // not really allowed characters..
            pwriter.PushInt(expansions);

            byte[] reply = pwriter.Finish();
            client.Send(reply);
        }
 public void FillInventory()
 {
     List<ShopInv> shopinvs = new List<ShopInv>();
     int place = 0;
     Random r = new Random();
     string like = "";
     SqlWrapper sqlWrapper = new SqlWrapper();
     DataTable dt = sqlWrapper.ReadDatatable("SELECT * from vendortemplate where HASH='" + this.Hash + "'");
     foreach (DataRow row in dt.Rows)
     {
         ShopInv shopInventory = new ShopInv
             { Hash = (string)row["ShopInvHash"], MinQl = (Int32)row["minQL"], MaxQl = (Int32)row["maxQL"] };
         shopinvs.Add(shopInventory);
         if (like != "")
         {
             like += "OR ";
         }
         like += "HASH LIKE '%" + shopInventory.Hash + "%' ";
     }
     if (like != "")
     {
         this.Inventory.Clear();
         dt = sqlWrapper.ReadDatatable("SELECT * from shopinventorytemplates where " + like + "and active = 1");
         foreach (DataRow row in dt.Rows)
         {
             string thisHash = (string)row["Hash"];
             foreach (ShopInv si in shopinvs)
             {
                 if (si.Hash == thisHash)
                 {
                     int minQl = (Int32)row["minql"];
                     int maxQl = (Int32)row["maxql"];
                     // Dont add Items that are not between si.minQL and si.maxQL
                     if ((minQl <= si.MaxQl) && (maxQl >= si.MinQl))
                     {
                         InventoryEntries inventoryEntry = new InventoryEntries
                             {
                                 Container = 104,
                                 Placement = place++,
                                 Item =
                                     {
                                         LowID = (Int32)row["lowid"],
                                         HighID = (Int32)row["highid"],
                                         MultipleCount = (Int32)row["multiplecount"],
                                         Nothing = 0,
                                         Quality =
                                             Math.Min(
                                                 Math.Max(Convert.ToInt32(r.Next(si.MinQl, si.MaxQl)), minQl),
                                                 maxQl)
                                     }
                             };
                         this.Inventory.Add(inventoryEntry);
                     }
                 }
             }
         }
     }
 }