Exemplo n.º 1
0
        private static List<ATPlayer> SearchPlayerByName(string name, bool exact = false)
        {
            List<ATPlayer> ReturnList = new List<ATPlayer>();
            lock (PlayerList)
            {
                foreach (ATPlayer player in PlayerList)
                {
                    if ((exact && player.AccountName == name) || (!exact && player.AccountName.ToLower().StartsWith(name.ToLower())))
                        ReturnList.Add(player);
                    else
                    {
                        foreach (string nick in player.Nicknames)
                        {
                            if ((exact && nick == name) || (!exact && nick.ToLower().StartsWith(name.ToLower())))
                                ReturnList.Add(player);
                        }
                    }
                }
            }
            string query;
            if (exact)
                query = String.Format("SELECT * from PlayerData WHERE Username = '******' OR Nicknames LIKE '%\"{0}\"%'", name);
            else
                query = String.Format("SELECT * from PlayerData WHERE Username LIKE '%{0}%' OR Nicknames LIKE '%{0}%'", name.ToLower());
            QueryResult reader = AdminToolsMain.db.QueryReader(query);
            while (reader.Reader.Read())
            {
                bool found = false;
                foreach (ATPlayer ply in ReturnList)
                {
                    if ((exact && ply.AccountName == reader.Get<String>("Username")) || (!exact && ply.AccountName.ToLower() == reader.Get<String>("Username").ToLower()))
                    {
                        found = true;
                        break;
                    }
                }
                if (!found)
                {
                    ATPlayer newplayer = new ATPlayer(-1);
                    newplayer.UserID = reader.Get<int>("UserID");
                    newplayer.AccountName = reader.Get<String>("Username");
                    newplayer.Nicknames = JsonConvert.DeserializeObject<List<String>>(reader.Get<String>("Nicknames"));
                    newplayer.IP = JsonConvert.DeserializeObject<List<String>>(reader.Get<String>("IPs"));
                    newplayer.LastSeen = new DateTime(reader.Get<long>("LastSeen"));
                    ReturnList.Add(newplayer);

                }
            }
            return ReturnList;
        }
Exemplo n.º 2
0
 private static List<ATPlayer> SearchPlayerByUserID(int userid)
 {
     List<ATPlayer> ReturnList = new List<ATPlayer>();
     lock (PlayerList)
     {
         foreach (ATPlayer player in PlayerList)
         {
             if (player.UserID == userid)
                 ReturnList.Add(player);
         }
     }
     QueryResult reader = AdminToolsMain.db.QueryReader("SELECT * from PlayerData WHERE UserID = @0", userid);
     while (reader.Reader.Read())
     {
         bool found = false;
         foreach (ATPlayer ply in ReturnList)
         {
             if (ply.UserID == reader.Get<int>("UserID"))
             {
                 found = true;
                 break;
             }
         }
         if (!found)
         {
             ATPlayer newplayer = new ATPlayer(-1);
             newplayer.UserID = reader.Get<int>("UserID");
             newplayer.AccountName = reader.Get<String>("Username");
             newplayer.Nicknames = JsonConvert.DeserializeObject<List<String>>(reader.Get<String>("Nicknames"));
             newplayer.IP = JsonConvert.DeserializeObject<List<String>>(reader.Get<String>("IPs"));
             newplayer.LastSeen = new DateTime(reader.Get<long>("LastSeen"));
             ReturnList.Add(newplayer);
         }
     }
     return ReturnList;
 }
Exemplo n.º 3
0
 private static List<ATPlayer> SearchPlayerByIP(string ip)
 {
     List<ATPlayer> ReturnList = new List<ATPlayer>();
     lock (PlayerList)
     {
         foreach (ATPlayer player in PlayerList)
         {
             foreach (string i in player.IP)
             {
                 if (i == ip)
                     ReturnList.Add(player);
             }
         }
     }
     string query = String.Format("SELECT * from PlayerData WHERE IPs LIKE '%\"{0}\"%'", ip);
     QueryResult reader = AdminToolsMain.db.QueryReader(query);
     while (reader.Reader.Read())
     {
         bool found = false;
         foreach (ATPlayer ply in ReturnList)
         {
             if (ply.UserID == reader.Get<int>("UserID"))
             {
                 found = true;
                 break;
             }
         }
         if (!found)
         {
             ATPlayer newplayer = new ATPlayer(-1);
             newplayer.UserID = reader.Get<int>("UserID");
             newplayer.AccountName = reader.Get<String>("Username");
             newplayer.Nicknames = JsonConvert.DeserializeObject<List<String>>(reader.Get<String>("Nicknames"));
             newplayer.IP = JsonConvert.DeserializeObject<List<String>>(reader.Get<String>("IPs"));
             newplayer.LastSeen = new DateTime(reader.Get<long>("LastSeen"));
             ReturnList.Add(newplayer);
         }
     }
     return ReturnList;
 }