GetAccount() public method

public GetAccount ( int id ) : Account
id int
return Account
Example #1
0
        protected override void HandleRequest()
        {
            using (Database db = new Database())
            {
                Account acc = db.GetAccount(Query["accountId"], Program.GameData);
                Char chr = db.LoadCharacter(acc, int.Parse(Query["charId"]));

                MySqlCommand cmd = db.CreateQuery();
                cmd.CommandText = @"SELECT time, killer, firstBorn FROM death WHERE accId=@accId AND chrId=@charId;";
                cmd.Parameters.AddWithValue("@accId", Query["accountId"]);
                cmd.Parameters.AddWithValue("@charId", Query["charId"]);
                int time;
                string killer;
                bool firstBorn;
                using (MySqlDataReader rdr = cmd.ExecuteReader())
                {
                    rdr.Read();
                    time = Database.DateTimeToUnixTimestamp(rdr.GetDateTime("time"));
                    killer = rdr.GetString("killer");
                    firstBorn = rdr.GetBoolean("firstBorn");
                }

                using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream))
                    wtr.Write(chr.FameStats.Serialize(Program.GameData, acc, chr, time, killer, firstBorn));
            }
        }
Example #2
0
        public override void HandleRequest(HttpListenerContext context)
        {
            NameValueCollection query;
            using (var rdr = new StreamReader(context.Request.InputStream))
                query = HttpUtility.ParseQueryString(rdr.ReadToEnd());

            if (query.AllKeys.Length == 0)
            {
                string queryString = string.Empty;
                string currUrl = context.Request.RawUrl;
                int iqs = currUrl.IndexOf('?');
                if (iqs >= 0)
                {
                    query =
                        HttpUtility.ParseQueryString((iqs < currUrl.Length - 1)
                            ? currUrl.Substring(iqs + 1)
                            : String.Empty);
                }
            }

            using (var db = new Database(Program.Settings.GetValue("conn")))
            {
                Account acc = db.GetAccount(int.Parse(query["accountId"]));
                Char chr = db.LoadCharacter(acc, int.Parse(query["charId"]));

                MySqlCommand cmd = db.CreateQuery();
                cmd.CommandText = @"SELECT time, killer, firstBorn FROM death WHERE accId=@accId AND chrId=@charId;";
                cmd.Parameters.AddWithValue("@accId", query["accountId"]);
                cmd.Parameters.AddWithValue("@charId", query["charId"]);
                int time;
                string killer;
                bool firstBorn;
                using (MySqlDataReader rdr = cmd.ExecuteReader())
                {
                    rdr.Read();
                    time = Database.DateTimeToUnixTimestamp(rdr.GetDateTime("time"));
                    killer = rdr.GetString("killer");
                    firstBorn = rdr.GetBoolean("firstBorn");
                }

                using (var wtr = new StreamWriter(context.Response.OutputStream))
                    wtr.Write(chr.FameStats.Serialize(Program.GameData, acc, chr, time, killer, firstBorn));
            }
        }
Example #3
0
 protected override void HandleRequest()
 {
     using (var db = new Database())
     {
         var acc = db.GetAccount(int.Parse(Query["accountId"]));
         var chr = db.LoadCharacter(acc, int.Parse(Query["charId"]));
         var cmd = db.CreateQuery();
         cmd.CommandText = "SELECT time, killer, firstBorn FROM death WHERE accId=@accId AND chrId=@charId;";
         int time; string killer; bool firstBorn;
         using (var rdr = cmd.ExecuteReader())
         {
             rdr.Read();
             time = Database.DateTimeToUnixTimestamp(rdr.GetDateTime("time"));
             killer = rdr.GetString("killer");
             firstBorn = rdr.GetBoolean("firstBorn");
         }
         WriteLine(chr.FameStats.Serialize(acc, chr, time, killer, firstBorn));
     }
 }
        public void GuildRemove(RealmTime t, GuildRemovePacket pkt)
        {
            var pname = pkt.Name;
            try
            {
                var p = RealmManager.FindPlayer(pname);
                if (p != null && p.Guild == Guild)
                {
                    var db = new Database();
                    var g = db.ChangeGuild(p.Client.Account, p.Client.Account.Guild.Id, p.GuildRank, p.Client.Account.Guild.Fame, true);
                    p.Guild = "";
                    p.GuildRank = 0;
                    p.Client.Account.Guild = g;
                    p.UpdateCount++;
                    if (p != this)
                    {
                        p.SendGuild("You have been kicked from the guild.");
                        foreach (var pl in RealmManager.GuildMembersOf(Guild))
                            pl.SendGuild(p.nName + " has been kicked from the guild by " + nName + ".");
                    }
                    else
                    {
                        p.SendGuild("You have left the guild.");
                        foreach (var pl in RealmManager.GuildMembersOf(Guild))
                            pl.SendGuild(nName + " has left the guild.");
                    }
                }
                else
                {
                    try
                    {
                        var db = new Database();
                        var other = db.GetAccount(pname);
                        if (other.Guild.Name == Guild)
                        {
                            db.ChangeGuild(other, other.Guild.Id, other.Guild.Rank, other.Guild.Fame, true);
                            foreach (var pl in RealmManager.GuildMembersOf(Guild))
                                pl.SendGuild(pname + " has been kicked from the guild by " + nName + ".");
                        }
                    }
                    catch (Exception e)
                    {
                        psr.SendPacket(new TextPacket()
                        {
                            BubbleTime = 0,
                            Stars = -1,
                            Name = "*Error*",
                            Text = e.Message
                        });
                    }
                }

            }
            catch (Exception e)
            {
                psr.SendPacket(new TextPacket()
                {
                    BubbleTime = 0,
                    Stars = -1,
                    Name = "*Error*",
                    Text = e.Message
                });
            }
        }
 public void ChangeGuildRank(RealmTime t, ChangeGuildRankPacket pkt)
 {
     var pname = pkt.Name;
     var rank = pkt.GuildRank;
     if (GuildRank >= 20)
     {
         var other = RealmManager.FindPlayer(pname);
         if (other != null && other.Guild == Guild)
         {
             var rankname = ResolveRankName(other.GuildRank);
             var rankname2 = ResolveRankName(rank);
             other.GuildRank = rank;
             other.Client.Account.Guild.Rank = rank;
             new Database().ChangeGuild(other.Client.Account, other.Client.Account.Guild.Id, other.GuildRank, other.Client.Account.Guild.Fame, false);
             other.UpdateCount++;
             foreach (var p in RealmManager.GuildMembersOf(Guild))
             {
                 p.Client.SendPacket(new TextPacket()
                 {
                     BubbleTime = 0,
                     Stars = -1,
                     Name = "",
                     Recipient = "*Guild*",
                     Text = other.Client.Account.Name + " has been demoted to " + rankname2 + "."
                 });
             }
         }
         else
         {
             try
             {
                 var db = new Database();
                 var acc = db.GetAccount(pname);
                 if (acc.Guild.Name == Guild)
                 {
                     var rankname = ResolveRankName(acc.Guild.Rank);
                     var rankname2 = ResolveRankName(rank);
                     db.ChangeGuild(acc, acc.Guild.Id, rank, acc.Guild.Fame, false);
                     foreach (var p in RealmManager.GuildMembersOf(Guild))
                     {
                         p.Client.SendPacket(new TextPacket()
                         {
                             BubbleTime = 0,
                             Stars = -1,
                             Name = "",
                             Recipient = "*Guild*",
                             Text = acc.Name + " has been promoted to " + rankname2 + "."
                         });
                     }
                 }
                 else
                 {
                     psr.SendPacket(new TextPacket()
                     {
                         BubbleTime = 0,
                         Stars = -1,
                         Name = "*Error*",
                         Text = "You can only change a player in your guild."
                     });
                 }
             }
             catch (Exception e)
             {
                 psr.SendPacket(new TextPacket()
                 {
                     BubbleTime = 0,
                     Stars = -1,
                     Name = "*Error*",
                     Text = e.Message
                 });
             }
         }
     }
     else
     {
         psr.SendPacket(new TextPacket()
         {
             BubbleTime = 0,
             Stars = -1,
             Name = "",
             Text = "Members and initiates cannot promote!"
         });
     }
 }
Example #6
0
 public void ChangeRank(GuildRankChangePacket pkt)
 {
     using(Database dbx = new Database())
     {
         if (psr.Account.Guild.Name == "")
         {
             psr.SendPacket(new TextPacket()
             {
                 BubbleTime = 0,
                 Name = "",
                 Stars = -1,
                 Text = "You don't have a guild!"
             });
             return;
         }
         switch (psr.Account.Guild.Rank)
         {
             case 0:
                 psr.SendPacket(new TextPacket()
                 {
                     BubbleTime = 0,
                     Name = "",
                     Stars = -1,
                     Text = "Only officers, leaders and founders can promote/demote other members!"
                 });
                 return;
             case 10:
                 psr.SendPacket(new TextPacket()
                 {
                     BubbleTime = 0,
                     Name = "",
                     Stars = -1,
                     Text = "Only officers, leaders and founders can promote/demote other members!"
                });
               return;
             case 20:
                 switch (pkt.Rank)
                 {
                     case 0:
                         dbx.ChangeGuildRank(pkt.Name, pkt.Rank);
                         foreach (var i in RealmManager.Clients.Values)
                         {
                             if (i.Account.Guild.Name == psr.Account.Guild.Name && i.Account.Guild.Id == psr.Account.Guild.Id)
                             {
                                 psr.SendPacket(new TextPacket()
                                 {
                                     BubbleTime = 0,
                                     Name = "",
                                     Stars = -1,
                                     Text = dbx.ChangeRankTextBuilder(psr.Account, dbx.GetAccount(pkt.Name), pkt.Rank)
                                 });
                             }
                         }
                         return;
                     case 10:
                         if (dbx.GetAccount(pkt.Name).Guild.Rank == psr.Account.Guild.Rank)
                         {
                             psr.SendPacket(new TextPacket()
                             {
                                 BubbleTime = 0,
                                 Name = "",
                                 Stars = -1,
                                 Text = "You can't demote members with your same rank!"
                             });
                             return;
                         }
                         dbx.ChangeGuildRank(pkt.Name, pkt.Rank);
                         foreach (var i in RealmManager.Clients.Values)
                         {
                             if (i.Account.Guild.Name == psr.Account.Guild.Name && i.Account.Guild.Id == psr.Account.Guild.Id)
                             {
                                 psr.SendPacket(new TextPacket()
                                 {
                                     BubbleTime = 0,
                                     Name = "",
                                     Stars = -1,
                                     Text = dbx.ChangeRankTextBuilder(psr.Account, dbx.GetAccount(pkt.Name), pkt.Rank)
                                 });
                             }
                         }
                         return;
                     case 20:
                         psr.SendPacket(new TextPacket()
                         {
                             BubbleTime = 0,
                             Name = "",
                             Stars = -1,
                             Text = "Only leaders and founders can promote other members to officers!"
                         });
                         return;
                     case 30:
                         psr.SendPacket(new TextPacket()
                         {
                             BubbleTime = 0,
                             Name = "",
                             Stars = -1,
                             Text = "Only leaders and founders can promote other members to leaders!"
                         });
                         return;
                     case 40:
                         psr.SendPacket(new TextPacket()
                         {
                             BubbleTime = 0,
                             Name = "",
                             Stars = -1,
                             Text = "You can't promote someone to founder!"
                         });
                         return;
                 }
                 return;
             case 30:
                 switch (pkt.Rank)
                 {
                     case 0:
                         dbx.ChangeGuildRank(pkt.Name, pkt.Rank);
                         foreach (var i in RealmManager.Clients.Values)
                         {
                             if (i.Account.Guild.Name == psr.Account.Guild.Name && i.Account.Guild.Id == psr.Account.Guild.Id)
                             {
                                 psr.SendPacket(new TextPacket()
                                 {
                                     BubbleTime = 0,
                                     Name = "",
                                     Stars = -1,
                                     Text = dbx.ChangeRankTextBuilder(psr.Account, dbx.GetAccount(pkt.Name), pkt.Rank)
                                 });
                             }
                         }
                         return;
                     case 10:
                         dbx.ChangeGuildRank(pkt.Name, pkt.Rank);
                         foreach (var i in RealmManager.Clients.Values)
                         {
                             if (i.Account.Guild.Name == psr.Account.Guild.Name && i.Account.Guild.Id == psr.Account.Guild.Id)
                             {
                                 psr.SendPacket(new TextPacket()
                                 {
                                     BubbleTime = 0,
                                     Name = "",
                                     Stars = -1,
                                     Text = dbx.ChangeRankTextBuilder(psr.Account, dbx.GetAccount(pkt.Name), pkt.Rank)
                                 });
                             }
                         }
                         return;
                     case 20:
                         if (dbx.GetAccount(pkt.Name).Guild.Rank == psr.Account.Guild.Rank)
                         {
                             psr.SendPacket(new TextPacket()
                             {
                                 BubbleTime = 0,
                                 Name = "",
                                 Stars = -1,
                                 Text = "You can't demote members with your same rank!"
                             });
                             return;
                         }
                         dbx.ChangeGuildRank(pkt.Name, pkt.Rank);
                         foreach (var i in RealmManager.Clients.Values)
                         {
                             if (i.Account.Guild.Name == psr.Account.Guild.Name && i.Account.Guild.Id == psr.Account.Guild.Id)
                             {
                                 psr.SendPacket(new TextPacket()
                                 {
                                     BubbleTime = 0,
                                     Name = "",
                                     Stars = -1,
                                     Text = dbx.ChangeRankTextBuilder(psr.Account, dbx.GetAccount(pkt.Name), pkt.Rank)
                                 });
                             }
                         }
                         return;
                     case 30:
                         dbx.ChangeGuildRank(pkt.Name, pkt.Rank);
                         foreach (var i in RealmManager.Clients.Values)
                         {
                             if (i.Account.Guild.Name == psr.Account.Guild.Name && i.Account.Guild.Id == psr.Account.Guild.Id)
                             {
                                 psr.SendPacket(new TextPacket()
                                 {
                                     BubbleTime = 0,
                                     Name = "",
                                     Stars = -1,
                                     Text = dbx.ChangeRankTextBuilder(psr.Account, dbx.GetAccount(pkt.Name), pkt.Rank)
                                 });
                             }
                         }
                         return;
                     case 40:
                         psr.SendPacket(new TextPacket()
                         {
                             BubbleTime = 0,
                             Name = "",
                             Stars = -1,
                             Text = "You can't promote someone to founder!"
                         });
                         return;
                 }
                 return;
             case 40:
                 switch (pkt.Rank)
                 {
                     case 0:
                         dbx.ChangeGuildRank(pkt.Name, pkt.Rank);
                         foreach (var i in RealmManager.Clients.Values)
                         {
                             if (i.Account.Guild.Name == psr.Account.Guild.Name && i.Account.Guild.Id == psr.Account.Guild.Id)
                             {
                                 psr.SendPacket(new TextPacket()
                                 {
                                     BubbleTime = 0,
                                     Name = "",
                                     Stars = -1,
                                     Text = dbx.ChangeRankTextBuilder(psr.Account, dbx.GetAccount(pkt.Name), pkt.Rank)
                                 });
                             }
                         }
                         return;
                     case 10:
                         dbx.ChangeGuildRank(pkt.Name, pkt.Rank);
                         foreach (var i in RealmManager.Clients.Values)
                         {
                             if (i.Account.Guild.Name == psr.Account.Guild.Name && i.Account.Guild.Id == psr.Account.Guild.Id)
                             {
                                 psr.SendPacket(new TextPacket()
                                 {
                                     BubbleTime = 0,
                                     Name = "",
                                     Stars = -1,
                                     Text = dbx.ChangeRankTextBuilder(psr.Account, dbx.GetAccount(pkt.Name), pkt.Rank)
                                 });
                             }
                         }
                         return;
                     case 20:
                         dbx.ChangeGuildRank(pkt.Name, pkt.Rank);
                         foreach (var i in RealmManager.Clients.Values)
                         {
                             if (i.Account.Guild.Name == psr.Account.Guild.Name && i.Account.Guild.Id == psr.Account.Guild.Id)
                             {
                                 psr.SendPacket(new TextPacket()
                                 {
                                     BubbleTime = 0,
                                     Name = "",
                                     Stars = -1,
                                     Text = dbx.ChangeRankTextBuilder(psr.Account, dbx.GetAccount(pkt.Name), pkt.Rank)
                                 });
                             }
                         }
                         return;
                     case 30:
                         if (dbx.GetAccount(pkt.Name).Guild.Rank == psr.Account.Guild.Rank)
                         {
                             psr.SendPacket(new TextPacket()
                             {
                                 BubbleTime = 0,
                                 Name = "",
                                 Stars = -1,
                                 Text = "You can't demote members with your same rank!"
                             });
                             return;
                         }
                         dbx.ChangeGuildRank(pkt.Name, pkt.Rank);
                         foreach (var i in RealmManager.Clients.Values)
                         {
                             if (i.Account.Guild.Name == psr.Account.Guild.Name && i.Account.Guild.Id == psr.Account.Guild.Id)
                             {
                                 psr.SendPacket(new TextPacket()
                                 {
                                     BubbleTime = 0,
                                     Name = "",
                                     Stars = -1,
                                     Text = dbx.ChangeRankTextBuilder(psr.Account, dbx.GetAccount(pkt.Name), pkt.Rank)
                                 });
                             }
                         }
                         return;
                     case 40:
                         psr.SendPacket(new TextPacket()
                         {
                             BubbleTime = 0,
                             Name = "",
                             Stars = -1,
                             Text = "You can't promote someone to founder!"
                         });
                         return;
                 }
                 return;
           }
      }
 }
Example #7
0
 public void RemoveFromGuild(GuildRemovePacket pkt)
 {
     try
     {
         if (pkt.Name != psr.Account.Name)
         {
             if (psr.Account.Guild == null || psr.Account.Guild.Name == "")
             {
                 psr.SendPacket(new TextPacket()
                 {
                     Name = "",
                     Stars = -1,
                     BubbleTime = 0,
                     Text = "You don't have a guild!"
                 });
                 return;
             }
             using (Database dbx = new Database())
             {
                 var cmd = dbx.CreateQuery();
                 cmd.CommandText = "UPDATE accounts SET guild='0', guildRank='-1' WHERE id=@id";
                 cmd.Parameters.AddWithValue("@id", dbx.GetAccount(pkt.Name).AccountId);
                 if (cmd.ExecuteNonQuery() == 0)
                 {
                     psr.SendPacket(new TextPacket()
                     {
                         Name = "",
                         Stars = -1,
                         BubbleTime = 0,
                         Text = "Unable to remove guild from account data!"
                     });
                     return;
                 }
                 else
                 {
                     var members = dbx.GetGuildMembers(psr.Account);
                     if (!members.Contains(dbx.GetAccount(pkt.Name).AccountId))
                     {
                         psr.SendPacket(new TextPacket()
                         {
                             Name = "",
                             Stars = -1,
                             BubbleTime = 0,
                             Text = "Unable to find account in guild's members list!"
                         });
                         return;
                     }
                     members.Remove(dbx.GetAccount(pkt.Name).AccountId);
                     var newmembers = Utils.GetCommaSepString<int>(members.ToArray());
                     if (members.Count == 0)
                     {
                         if (dbx.RemoveGuild(psr.Account) == false)
                         {
                             psr.SendPacket(new TextPacket()
                             {
                                 Name = "",
                                 Stars = -1,
                                 BubbleTime = 0,
                                 Text = "Unable to delete guild!"
                             });
                             return;
                         }
                     }
                     else
                     {
                         if (dbx.RemoveFromGuildMembers(psr.Account) == false)
                         {
                             psr.SendPacket(new TextPacket()
                             {
                                 Name = "",
                                 Stars = -1,
                                 BubbleTime = 0,
                                 Text = "Unable to remove account from guild's members list!"
                             });
                             return;
                         }
                     }
                     foreach (var i in RealmManager.Clients.Values)
                     {
                         if (i.Account.Guild.Name == psr.Account.Guild.Name && i.Account.Guild.Id == psr.Account.Guild.Id)
                         {
                             i.SendPacket(new TextPacket()
                             {
                                 Name = "",
                                 BubbleTime = 0,
                                 Stars = -1,
                                 Text = pkt.Name + " has been removed from the guild by " + psr.Account.Name + "."
                             });
                         }
                     }
                     psr.Account.Guild = new Guild()
                     {
                         Id = 0,
                         Name = "",
                         Rank = -1
                     };
                     UpdateCount++;
                     return;
                 }
             }
         }
         else
         {
             if (psr.Account.Guild == null || psr.Account.Guild.Name == "")
             {
                 psr.SendPacket(new TextPacket()
                 {
                     BubbleTime = 0,
                     Name = "",
                     Stars = -1,
                     Text = "You don't have a guild!"
                 });
                 return;
             }
             using (Database dbx = new Database())
             {
                 var cmd = dbx.CreateQuery();
                 cmd.CommandText = "UPDATE accounts SET guild='0', guildRank='-1' WHERE id=@id";
                 cmd.Parameters.AddWithValue("@id", psr.Account.AccountId);
                 if (cmd.ExecuteNonQuery() == 0)
                 {
                     psr.SendPacket(new TextPacket()
                     {
                         BubbleTime = 0,
                         Name = "",
                         Stars = -1,
                         Text = "Unable to remove guild from account data!"
                     });
                     return;
                 }
                 else
                 {
                     var members = dbx.GetGuildMembers(psr.Account);
                     if (!members.Contains(psr.Account.AccountId))
                     {
                         psr.SendPacket(new TextPacket()
                         {
                             BubbleTime = 0,
                             Name = "",
                             Stars = -1,
                             Text = "Unable to find account in guild's members list!"
                         });
                         return;
                     }
                     members.Remove(psr.Account.AccountId);
                     var newmembers = Utils.GetCommaSepString<int>(members.ToArray());
                     if (newmembers.Length == 0)
                     {
                         if (dbx.RemoveGuild(psr.Account) == false)
                         {
                             psr.SendPacket(new TextPacket()
                             {
                                 BubbleTime = 0,
                                 Name = "",
                                 Stars = -1,
                                 Text = "Unable to delete guild!"
                             });
                             return;
                         }
                     }
                     else
                     {
                         if (dbx.RemoveFromGuildMembers(psr.Account) == false)
                         {
                             psr.SendPacket(new TextPacket()
                             {
                                 BubbleTime = 0,
                                 Name = "",
                                 Stars = -1,
                                 Text = "Unable to remove account from guild's members list!"
                             });
                             return;
                         }
                     }
                     foreach (var i in RealmManager.Clients.Values)
                     {
                         if (i.Account.Guild.Name == psr.Account.Guild.Name && i.Account.Guild.Id == psr.Account.Guild.Id)
                         {
                             i.SendPacket(new TextPacket()
                             {
                                 Name = "",
                                 BubbleTime = 0,
                                 Stars = -1,
                                 Text = psr.Account.Name + " left the guild."
                             });
                         }
                     }
                     psr.Account.Guild = new Guild()
                     {
                         Id = 0,
                         Name = "",
                         Rank = -1
                     };
                     UpdateCount++;
                     psr.SendPacket(new TextPacket()
                     {
                         BubbleTime = 0,
                         Name = "",
                         Stars = -1,
                         Text = "You left the guild."
                     });
                     return;
                 }
             }
         }
     }
     catch
     {
         psr.SendPacket(new TextPacket()
         {
             Name = "",
             Stars = -1,
             BubbleTime = 0,
             Text = "Error removing the player from the guild!"
         });
         return;
     }
 }
 public Account GetAccount(XmlData data)
 {
     using (var db = new Database())
         return db.GetAccount(accId, data);
 }
Example #9
0
 public Account GetAccount(XmlData data)
 {
     using (var db = new Database())
         return(db.GetAccount(accId, data));
 }
Example #10
0
        protected override void HandleRequest()
        {
            byte[] status = null;

            string span = "";
            switch (Query["timespan"])
            {
                case "week":
                    span = "(time >= DATE_SUB(NOW(), INTERVAL 1 WEEK))";
                    break;
                case "month":
                    span = "(time >= DATE_SUB(NOW(), INTERVAL 1 MONTH))";
                    break;
                case "all":
                    span = "TRUE";
                    break;
                default:
                    status = Encoding.UTF8.GetBytes("<Error>Invalid fame list</Error>");
                    break;
            }
            string ac = "FALSE";
            if (Query["accountId"] != null)
                ac = "(accId=@accId AND chrId=@charId)";

            if (status == null)
            {
                XmlDocument doc = new XmlDocument();
                XmlElement root = doc.CreateElement("FameList");

                XmlAttribute spanAttr = doc.CreateAttribute("timespan");
                spanAttr.Value = Query["timespan"];
                root.Attributes.Append(spanAttr);

                doc.AppendChild(root);

                using (Database db = new Database())
                {
                    MySqlCommand cmd = db.CreateQuery();
                    cmd.CommandText = @"SELECT * FROM death WHERE " + span + @" OR " + ac +
                                      @" ORDER BY totalFame DESC LIMIT 20;";
                    if (Query["accountId"] != null)
                    {
                        cmd.Parameters.AddWithValue("@accId", Query["accountId"]);
                        cmd.Parameters.AddWithValue("@charId", Query["charId"]);
                    }
                    using (MySqlDataReader rdr = cmd.ExecuteReader())
                    {
                        while (rdr.Read())
                        {
                            XmlElement elem = doc.CreateElement("FameListElem");

                            int accId = rdr.GetInt32("accId");
                            XmlAttribute accIdAttr = doc.CreateAttribute("accountId");
                            accIdAttr.Value = accId.ToString();
                            elem.Attributes.Append(accIdAttr);
                            XmlAttribute chrIdAttr = doc.CreateAttribute("charId");
                            chrIdAttr.Value = rdr.GetInt32("chrId").ToString();
                            elem.Attributes.Append(chrIdAttr);

                            root.AppendChild(elem);

                            XmlElement nameElem = doc.CreateElement("Name");
                            nameElem.InnerText = String.Empty;
                            elem.AppendChild(nameElem);
                            XmlElement objTypeElem = doc.CreateElement("ObjectType");
                            objTypeElem.InnerText = rdr.GetString("charType");
                            elem.AppendChild(objTypeElem);
                            XmlElement tex1Elem = doc.CreateElement("Tex1");
                            tex1Elem.InnerText = rdr.GetString("tex1");
                            elem.AppendChild(tex1Elem);
                            XmlElement tex2Elem = doc.CreateElement("Tex2");
                            tex2Elem.InnerText = rdr.GetString("tex2");
                            elem.AppendChild(tex2Elem);
                            XmlElement skinElem = doc.CreateElement("Texture");
                            skinElem.InnerText = rdr.GetString("skin");
                            elem.AppendChild(skinElem);
                            XmlElement equElem = doc.CreateElement("Equipment");
                            equElem.InnerText = rdr.GetString("items");
                            elem.AppendChild(equElem);
                            XmlElement fameElem = doc.CreateElement("TotalFame");
                            fameElem.InnerText = rdr.GetString("totalFame");
                            elem.AppendChild(fameElem);
                        }
                    }

                    XmlNodeList list = doc.SelectNodes("/FameList/FameListElem");

                    foreach (XmlNode node in list)
                    {
                        foreach (XmlNode xnode in node.ChildNodes)
                        {
                            if (xnode.Name == "Name")
                                xnode.InnerText = db.GetAccount(node.Attributes["accountId"].Value, Program.GameData).Name;
                        }
                    }
                }

                XmlWriterSettings settings = new XmlWriterSettings();
                settings.OmitXmlDeclaration = true;
                using (XmlWriter wtr = XmlWriter.Create(Context.Response.OutputStream))
                    doc.Save(wtr);
            }
        }
Example #11
-1
        public void HandleRequest(HttpListenerContext context)
        {
            NameValueCollection query;
            using (StreamReader rdr = new StreamReader(context.Request.InputStream))
                query = HttpUtility.ParseQueryString(rdr.ReadToEnd());
            using (var db = new Database())
            {
                var acc = db.GetAccount(int.Parse(query["accountId"]));
                var chr = db.LoadCharacter(acc, int.Parse(query["charId"]));

                var cmd = db.CreateQuery();
                cmd.CommandText = @"SELECT time, killer, firstBorn FROM death WHERE accId=@accId AND chrId=@charId;";
                cmd.Parameters.AddWithValue("@accId", query["accountId"]);
                cmd.Parameters.AddWithValue("@charId", query["charId"]);
                int time;
                string killer;
                bool firstBorn;
                using (var rdr = cmd.ExecuteReader())
                {
                    rdr.Read();
                    time = Database.DateTimeToUnixTimestamp(rdr.GetDateTime("time"));
                    killer = rdr.GetString("killer");
                    firstBorn = rdr.GetBoolean("firstBorn");
                }

                using (StreamWriter wtr = new StreamWriter(context.Response.OutputStream))
                    wtr.Write(chr.FameStats.Serialize(acc, chr, time, killer, firstBorn));
            }
        }