Esempio n. 1
0
        public static void Load()
        {
            if (hour == DateTime.Now.Hour)
            {
                return;
            }
            hour = (short)DateTime.Now.Hour;

            UserByEXP.Clear();
            UserByWins.Clear();
            UserByKills.Clear();

            ClanByEXP.Clear();
            ClanByWins.Clear();
            ClanByMembers.Clear();

            DataTable dt = DB.RunReader("SELECT * FROM users WHERE rank < 4 AND rank > 0 AND banned != '1' ORDER BY exp DESC LIMIT 0, 100");

            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];
                if (row != null)
                {
                    RankingList.User usr = new RankingList.User();
                    usr.nickname = row["nickname"].ToString();
                    int clanId         = int.Parse(row["clanid"].ToString());
                    Game_Server.Clan c = Managers.ClanManager.GetClan(clanId);
                    if (clanId >= 0 && c != null)
                    {
                        usr.clanname   = c.name;
                        usr.claniconid = (int)c.iconid;
                    }
                    else
                    {
                        usr.clanname   = "NULL";
                        usr.claniconid = -1;
                    }
                    usr.exp    = uint.Parse(row["exp"].ToString());
                    usr.kills  = uint.Parse(row["kills"].ToString());
                    usr.deaths = uint.Parse(row["deaths"].ToString());
                    usr.wins   = uint.Parse(row["wonMatchs"].ToString());
                    usr.loses  = uint.Parse(row["lostMatchs"].ToString());

                    UserByEXP.Add(usr);
                }
            }
            dt = DB.RunReader("SELECT * FROM users WHERE rank < 4 AND rank > 0 AND banned != '1' ORDER BY wonMatchs DESC LIMIT 0, 100");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];
                if (row != null)
                {
                    RankingList.User usr = new RankingList.User();
                    usr.nickname = row["nickname"].ToString();
                    int clanId         = int.Parse(row["clanid"].ToString());
                    Game_Server.Clan c = Managers.ClanManager.GetClan(clanId);
                    if (clanId >= 0 && c != null)
                    {
                        usr.clanname   = c.name;
                        usr.claniconid = (int)c.iconid;
                    }
                    else
                    {
                        usr.clanname   = "NULL";
                        usr.claniconid = -1;
                    }
                    usr.exp    = uint.Parse(row["exp"].ToString());
                    usr.kills  = uint.Parse(row["kills"].ToString());
                    usr.deaths = uint.Parse(row["deaths"].ToString());
                    usr.wins   = uint.Parse(row["wonMatchs"].ToString());
                    usr.loses  = uint.Parse(row["lostMatchs"].ToString());

                    UserByWins.Add(usr);
                }
            }

            dt = DB.RunReader("SELECT * FROM users WHERE rank < 4 AND rank > 0 AND banned != '1' ORDER BY kills DESC LIMIT 0, 100");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];
                if (row != null)
                {
                    RankingList.User usr = new RankingList.User();
                    usr.nickname = row["nickname"].ToString();
                    int clanId         = int.Parse(row["clanid"].ToString());
                    Game_Server.Clan c = Managers.ClanManager.GetClan(clanId);
                    if (clanId >= 0 && c != null)
                    {
                        usr.clanname   = c.name;
                        usr.claniconid = (int)c.iconid;
                    }
                    else
                    {
                        usr.clanname   = "NULL";
                        usr.claniconid = -1;
                    }
                    usr.exp    = uint.Parse(row["exp"].ToString());
                    usr.kills  = uint.Parse(row["kills"].ToString());
                    usr.deaths = uint.Parse(row["deaths"].ToString());
                    usr.wins   = uint.Parse(row["wonMatchs"].ToString());
                    usr.loses  = uint.Parse(row["lostMatchs"].ToString());

                    UserByKills.Add(usr);
                }
            }


            dt = DB.RunReader("SELECT * FROM clans ORDER BY exp DESC LIMIT 0, 100");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];
                if (row != null)
                {
                    RankingList.Clan clan = new RankingList.Clan();
                    clan.id         = uint.Parse(row["iconid"].ToString());
                    clan.name       = row["name"].ToString();
                    clan.claniconid = int.Parse(row["iconid"].ToString());
                    clan.wins       = uint.Parse(row["win"].ToString());
                    clan.loses      = uint.Parse(row["lose"].ToString());
                    clan.exp        = uint.Parse(row["exp"].ToString());
                    clan.usercount  = uint.Parse(row["count"].ToString());

                    ClanByEXP.Add(clan);
                }
            }


            dt = DB.RunReader("SELECT * FROM clans ORDER BY win DESC LIMIT 0, 100");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];
                if (row != null)
                {
                    RankingList.Clan clan = new RankingList.Clan();
                    clan.id         = uint.Parse(row["iconid"].ToString());
                    clan.name       = row["name"].ToString();
                    clan.claniconid = int.Parse(row["iconid"].ToString());
                    clan.wins       = uint.Parse(row["win"].ToString());
                    clan.loses      = uint.Parse(row["lose"].ToString());
                    clan.exp        = uint.Parse(row["exp"].ToString());
                    clan.usercount  = uint.Parse(row["count"].ToString());

                    ClanByWins.Add(clan);
                }
            }


            dt = DB.RunReader("SELECT * FROM clans ORDER BY count DESC LIMIT 0, 100");
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                DataRow row = dt.Rows[i];
                if (row != null)
                {
                    RankingList.Clan clan = new RankingList.Clan();
                    clan.id         = uint.Parse(row["iconid"].ToString());
                    clan.name       = row["name"].ToString();
                    clan.claniconid = int.Parse(row["iconid"].ToString());
                    clan.wins       = uint.Parse(row["win"].ToString());
                    clan.loses      = uint.Parse(row["lose"].ToString());
                    clan.exp        = uint.Parse(row["exp"].ToString());
                    clan.usercount  = uint.Parse(row["count"].ToString());

                    ClanByMembers.Add(clan);
                }
            }
        }
Esempio n. 2
0
        public SP_RankingList(ushort tab, ushort page, ushort sortType)
        {
            newPacket(30816);
            addBlock(tab);
            addBlock(page);
            addBlock(sortType);

            if (tab == 0) // User
            {
                List <RankingList.User> type = new List <RankingList.User>();
                switch (sortType)
                {
                case 0:
                {
                    type = RankingList.UserByEXP;
                    break;
                }

                case 1:
                {
                    type = RankingList.UserByWins;
                    break;
                }

                case 2:
                {
                    type = RankingList.UserByKills;
                    break;
                }
                }

                ushort maxPages = (ushort)(type.Count / 10);
                if (page >= maxPages)
                {
                    page = maxPages;
                }

                int index = page * 10;

                int pCount = (type.Count - index) > 10 ? 10 : (type.Count - index);
                if (pCount < 0)
                {
                    pCount = 0;
                }

                addBlock(pCount);

                for (int i = index; i < index + pCount; i++)
                {
                    RankingList.User u = type[i];
                    if (u != null)
                    {
                        addBlock(i + 1);
                        addBlock(100);
                        addBlock(u.exp);
                        addBlock(u.kills);
                        addBlock(u.deaths);
                        addBlock(u.wins);
                        addBlock(u.loses);
                        addBlock(u.claniconid);
                        addBlock(u.nickname);
                        addBlock(u.clanname);
                    }
                }
            }
            else if (tab == 1) // Clan
            {
                List <RankingList.Clan> type = new List <RankingList.Clan>();
                switch (sortType)
                {
                case 0:
                {
                    type = RankingList.ClanByEXP;
                    break;
                }

                case 1:
                {
                    type = RankingList.ClanByWins;
                    break;
                }

                case 2:
                {
                    type = RankingList.ClanByMembers;
                    break;
                }
                }

                ushort maxPages = (ushort)(type.Count / 10);
                if (page >= maxPages)
                {
                    page = maxPages;
                }
                int index = page * 10;

                int pCount = (type.Count - index) > 10 ? 10 : (type.Count - index);
                if (pCount < 0)
                {
                    pCount = 0;
                }

                addBlock(pCount);

                for (int i = index; i < index + pCount; i++)
                {
                    RankingList.Clan u = type[i];
                    if (u != null)
                    {
                        addBlock(i + 1);
                        addBlock(u.GetRank());
                        addBlock(u.exp);
                        addBlock(u.wins);
                        addBlock(u.loses);
                        addBlock(u.usercount);
                        addBlock(u.claniconid);
                        addBlock(u.name);
                    }
                }
            }
        }