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.Verify(query["guid"], query["password"]); byte[] status; if (acc == null) { status = Encoding.UTF8.GetBytes("<Error>Bad login</Error>"); } else { var cmd = db.CreateQuery(); cmd.CommandText = "UPDATE accounts SET password=SHA1(@password) WHERE id=@accId;"; cmd.Parameters.AddWithValue("@accId", acc.AccountId); cmd.Parameters.AddWithValue("@password", query["newPassword"]); if (cmd.ExecuteNonQuery() > 0) status = Encoding.UTF8.GetBytes("<Success />"); else status = Encoding.UTF8.GetBytes("<Error>Internal error</Error>"); } context.Response.OutputStream.Write(status, 0, status.Length); } }
public override void HandleRequest(HttpListenerContext context) { NameValueCollection query; using (var rdr = new StreamReader(context.Request.InputStream)) query = HttpUtility.ParseQueryString(rdr.ReadToEnd()); using (var db = new Database(Program.Settings.GetValue("conn"))) { string username = query["guid"]; string error = query["text"]; string errors = @"errors"; if (!Directory.Exists(errors)) { Directory.CreateDirectory(errors); } using (var writer = new StreamWriter(errors + @"\clientError", true)) { writer.WriteLine(username + " Sent Error : \n\r" + error); } byte[] status = Encoding.UTF8.GetBytes("<Success/>"); context.Response.OutputStream.Write(status, 0, status.Length); } }
protected override void HandleRequest() { StreamWriter wtr = new StreamWriter(Context.Response.OutputStream); if (Query.AllKeys.Length > 0) { using (Database db = new Database()) { Account acc = db.Verify(Query["guid"], Query["password"], Program.GameData); if (CheckAccount(acc, db, false)) { foreach (ItemCostItem item in Prices) { if (item.Type == Query["skinType"] && item.Puchasable == 1) { if (!acc.OwnedSkins.Contains(int.Parse(Query["skinType"]))) { acc.OwnedSkins.Add(int.Parse(Query["skinType"])); db.UpdateCredit(acc, -item.Price); MySqlCommand cmd = db.CreateQuery(); cmd.CommandText = "UPDATE accounts SET ownedSkins=@ownedSkins WHERE uuid=@uuid AND password=SHA1(@password)"; cmd.Parameters.AddWithValue("@ownedSkins", Utils.GetCommaSepString(acc.OwnedSkins.ToArray())); cmd.Parameters.AddWithValue("@uuid", Query["guid"]); cmd.Parameters.AddWithValue("@password", Query["password"]); if (cmd.ExecuteNonQuery() == 0) wtr.WriteLine("<Error>Unable to purchase</Error>"); } } } } } } }
protected override void HandleRequest() { using (var db = new Database()) { if (Account == null) BadLogin(); else { var cmd = db.CreateQuery(); cmd.CommandText = "SELECT fame FROM stats WHERE accId=@accId;"; cmd.Parameters.AddWithValue("@accId", Account.AccountId); if ((int)cmd.ExecuteScalar() < 5000) WriteErrorLine("Not enough fame"); else { cmd = db.CreateQuery(); cmd.CommandText = "UPDATE stats set fame = MIN(fame - 5000, 0) WHERE accId=@accId;"; cmd.Parameters.AddWithValue("@accId", Account.AccountId); if (cmd.ExecuteNonQuery() > 0) { cmd = db.CreateQuery(); cmd.CommandText = "UPDATE accounts SET maxCharSlot = maxCharSlot + 1 WHERE id=@accId;"; cmd.Parameters.AddWithValue("@accId", Account.AccountId); if (cmd.ExecuteNonQuery() > 0) Success(); else WriteErrorLine("Internal Error"); } else WriteErrorLine("Internal Error"); } } } }
protected override void HandleRequest() { using (Database db = new Database()) { try { Account acc = db.Verify(Query["guid"], Query["password"], Program.GameData); string classType = Program.GameData.ObjectTypeToId[ushort.Parse(Query["classType"])]; if (CheckAccount(acc, db)) { int price = Program.GameData.ObjectDescs[ushort.Parse(Query["classType"])].UnlockCost; if (acc.Credits < price) return; db.UpdateCredit(acc, -price); MySqlCommand cmd = db.CreateQuery(); cmd.CommandText = "UPDATE unlockedclasses SET available='unrestricted' WHERE accId=@accId AND class=@class;"; cmd.Parameters.AddWithValue("@accId", acc.AccountId); cmd.Parameters.AddWithValue("@class", classType); cmd.ExecuteNonQuery(); } } catch (Exception e) { using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream)) { wtr.WriteLine("<Error>Invalid classType"); wtr.Flush(); wtr.WriteLine(e); } } } }
public bool IsUserInLegends() { //Week using (var db = new Database()) { var cmd = db.CreateQuery(); cmd.CommandText = "SELECT * FROM death WHERE (time >= DATE_SUB(NOW(), INTERVAL 1 WEEK)) ORDER BY totalFame DESC LIMIT 10;"; using (var rdr = cmd.ExecuteReader()) while (rdr.Read()) if (rdr.GetString("accId") == AccountId) return true; } //Month using (var db = new Database()) { var cmd = db.CreateQuery(); cmd.CommandText = "SELECT * FROM death WHERE (time >= DATE_SUB(NOW(), INTERVAL 1 MONTH)) ORDER BY totalFame DESC LIMIT 10;"; using (var rdr = cmd.ExecuteReader()) while (rdr.Read()) if (rdr.GetString("accId") == AccountId) return true; } //All Time using (var db = new Database()) { var cmd = db.CreateQuery(); cmd.CommandText = "SELECT * FROM death WHERE TRUE ORDER BY totalFame DESC LIMIT 10;"; using (var rdr = cmd.ExecuteReader()) while (rdr.Read()) if (rdr.GetString("accId") == AccountId) return true; } return false; }
public Chars GetChars(string guid, string password, XmlData data) { using (var db = new Database()) { Account a = db.Verify(guid, password, data); if (a != null) { if (a.Banned) return null; } Chars chrs = new Chars { Characters = new List<Char>(), NextCharId = 2, MaxNumChars = 1, Account = a, }; db.GetCharData(chrs.Account, chrs); db.LoadCharacters(chrs.Account, chrs); chrs.News = db.GetNews(Program.GameData, chrs.Account); chrs.OwnedSkins = Utils.GetCommaSepString(chrs.Account.OwnedSkins.ToArray()); return chrs; } }
public void FreeDatabase(Database db) { lock (requestLock) { databases[db] = true; } }
public bool CheckAccount(Account acc, Database db, bool checkAccInUse=true) { if (acc == null && !String.IsNullOrWhiteSpace(Query["password"])) { WriteErrorLine("Account credentials not valid"); return false; } else if (acc == null && String.IsNullOrWhiteSpace(Query["password"])) return true; if (acc.Banned) { using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream)) wtr.WriteLine("<Error>Account under maintenance</Error>"); Context.Response.Close(); return false; } if (checkAccInUse) { int? timeout = 0; if (db.CheckAccountInUse(acc, ref timeout)) { if (timeout != null) using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream)) wtr.WriteLine("<Error>Account in use. (" + timeout + " seconds until timeout.)</Error>"); else using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream)) wtr.WriteLine("<Error>Account in use.</Error>"); Context.Response.Close(); return false; } } return true; }
protected override void HandleRequest() { using (var db = new Database()) { if (!IsUsername(Query["newGUID"])) WriteErrorLine("Invalid Username"); else { if (db.HasUuid(Query["guid"]) && db.Verify(Query["guid"], "") != null) { if (db.HasUuid(Query["newGUID"])) WriteErrorLine("Username is already taken"); else { var cmd = db.CreateQuery(); cmd.CommandText = "UPDATE accounts SET uuid=@newUuid, name=@newUuid, password=SHA1(@password), guest=FALSE WHERE uuid=@uuid, name=@name;"; cmd.Parameters.AddWithValue("@uuid", Query["guid"]); cmd.Parameters.AddWithValue("@newUuid", Query["newGUID"]); cmd.Parameters.AddWithValue("@password", Query["newPassword"]); if (cmd.ExecuteNonQuery() > 0) Success(); else WriteErrorLine("Internal Error"); } } else { if (db.Register(Query["newGUID"], Query["newPassword"], false) != null) Success(); else WriteErrorLine("Internal Error"); } } } }
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)); } }
protected override void HandleRequest() { using (var db = new Database()) { var acc = db.Verify(Query["guid"], Query["password"]); byte[] status; if (acc == null) { status = Encoding.UTF8.GetBytes("<Error>Bad login</Error>"); } else { var cmd = db.CreateQuery(); object exescala; cmd.CommandText = "SELECT COUNT(name) FROM accounts WHERE name=@name;"; cmd.Parameters.AddWithValue("@name", Query["name"]); exescala = cmd.ExecuteScalar(); if (int.Parse(exescala.ToString()) > 0) status = Encoding.UTF8.GetBytes("<Error>Duplicated name</Error>"); else { cmd = db.CreateQuery(); cmd.CommandText = "UPDATE accounts SET name=@name, namechosen=TRUE WHERE id=@accId;"; cmd.Parameters.AddWithValue("@accId", acc.AccountId); cmd.Parameters.AddWithValue("@name", Query["name"]); if (cmd.ExecuteNonQuery() != 0) status = Encoding.UTF8.GetBytes("<Success />"); else status = Encoding.UTF8.GetBytes("<Error>Internal error</Error>"); } } Context.Response.OutputStream.Write(status, 0, status.Length); } }
protected override void HandleRequest() { using (Database db = new Database()) { Account acc = db.Verify(Query["guid"], Query["password"], Program.GameData); if (CheckAccount(acc, db)) { if (acc.VerifiedEmail || !Program.Settings.GetValue<bool>("verifyEmail")) return; string authKey = Database.GenerateRandomString(128); var cmd = db.CreateQuery(); cmd.CommandText = "UPDATE accounts SET uuid=@newGuid, authToken=@newAuthToken WHERE uuid=@oldGuid;"; cmd.Parameters.AddWithValue("@newGuid", Query["newGuid"]); cmd.Parameters.AddWithValue("@newAuthToken", authKey); cmd.Parameters.AddWithValue("@oldGuid", Query["guid"]); cmd.Parameters.AddWithValue("@password", Query["password"]); cmd.ExecuteNonQuery(); MailMessage message = new MailMessage(); message.To.Add(Query["newGuid"]); message.IsBodyHtml = true; message.Subject = "Please verify your account."; message.From = new MailAddress(Program.Settings.GetValue<string>("serverEmail", "")); message.Body = "<center>Please verify your email via this <a href=\"" + Program.Settings.GetValue<string>("serverDomain", "localhost") + "/account/validateEmail?authToken=" + authKey + "\" target=\"_blank\">link</a>.</center>"; Program.SendEmail(message, true); } } }
protected override void HandleRequest() { using (Database db = new Database()) { string authKey = Database.GenerateRandomString(128); var cmd = db.CreateQuery(); cmd.CommandText = "UPDATE accounts SET authToken=@authToken WHERE uuid=@email;"; cmd.Parameters.AddWithValue("@authToken", authKey); cmd.Parameters.AddWithValue("@email", Query["guid"]); if (cmd.ExecuteNonQuery() == 1) { MailMessage message = new MailMessage(); message.To.Add(Query["guid"]); message.Subject = "Forgot Password"; message.From = new MailAddress(Program.Settings.GetValue<string>("serverEmail", ""), "Forgot Passowrd"); message.Body = emailBody. Replace("{RPLINK}", String.Format("{0}/{1}{2}", Program.Settings.GetValue<string>("serverDomain", "localhost"), "account/resetPassword?authToken=", authKey)). Replace("{SUPPORTLINK}", String.Format("{0}", Program.Settings.GetValue<string>("supportLink", "localhost"))). Replace("{SERVERDOMAIN}", Program.Settings.GetValue<string>("serverDomain", "localhost")); Program.SendEmail(message, true); } else using (StreamWriter wtr = new StreamWriter(Context.Response.OutputStream)) wtr.Write("<Error>Error.accountNotFound</Error>"); } }
private static void Main(string[] args) { XmlConfigurator.ConfigureAndWatch(new FileInfo("log4net_server.config")); Thread.CurrentThread.CurrentCulture = CultureInfo.InvariantCulture; Thread.CurrentThread.Name = "Entry"; Database = new Database(); GameData = new XmlData(); InstanceId = Guid.NewGuid().ToString(); Console.CancelKeyPress += (sender, e) => e.Cancel = true; if (RunPreCheck(port)) { listener = new HttpListener(); listener.Prefixes.Add($"http://*:{port}/"); listener.Start(); listener.BeginGetContext(ListenerCallback, null); Logger.Info($"Listening at port {port}..."); } else Logger.Error($"Port {port} is occupied"); while (Console.ReadKey(true).Key != ConsoleKey.Escape) ; Logger.Info("Terminating..."); while (currentRequests.Count > 0) ; listener?.Stop(); }
public virtual void Buy(Player player) { if (ObjectType == 0x0505) //Vault chest { //if (new Database().ReadVault(player.Client.Account).Chests.Count < 64) //{ if (TryDeduct(player)) { var chest = new Database().CreateChest(player.Client.Account); (Owner as Vault).AddChest(chest, this); player.Client.SendPacket(new BuyResultPacket() { Result = 0, Message = "Vault Chest Get!" }); } else player.Client.SendPacket(new BuyResultPacket() { Result = BUY_NO_FAME, Message = "Not enough fame!" }); /*} else { player.Client.SendPacket(new BuyResultPacket() { Result = 0, Message = "You have a full vault!" }); }*/ } }
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.Verify(query["guid"], query["password"]); if (acc == null) { var status = Encoding.UTF8.GetBytes("<Error>Bad login</Error>"); context.Response.OutputStream.Write(status, 0, status.Length); } else { XmlSerializer serializer = new XmlSerializer(acc.GetType(), new XmlRootAttribute(acc.GetType().Name) { Namespace = "" }); XmlWriterSettings xws = new XmlWriterSettings(); xws.OmitXmlDeclaration = true; xws.Encoding = Encoding.UTF8; XmlWriter xtw = XmlWriter.Create(context.Response.OutputStream, xws); serializer.Serialize(xtw, acc, acc.Namespaces); } } }
public override void HandleRequest(HttpListenerContext context) { NameValueCollection query; using (var rdr = new StreamReader(context.Request.InputStream)) query = HttpUtility.ParseQueryString(rdr.ReadToEnd()); using (var db = new Database(Program.Settings.GetValue("conn"))) { Account acc = db.Verify(query["guid"], query["password"]); byte[] status; if (acc == null) { status = Encoding.UTF8.GetBytes("<Error>Account credentials not valid</Error>"); } else { MySqlCommand cmd = db.CreateQuery(); cmd.CommandText = "SELECT beginnerPackageTimeLeft FROM accounts WHERE uuid=@uuid"; cmd.Parameters.AddWithValue("@uuid", query["guid"]); object result = cmd.ExecuteScalar(); status = Encoding.UTF8.GetBytes("<BeginnerPackageTimeLeft>" + result + "</BeginnerPackageTimeLeft>"); } context.Response.OutputStream.Write(status, 0, status.Length); } }
private List<globalNews_struct> GetGlobalNews(Database db) { List<globalNews_struct> ret = new List<globalNews_struct>(); var cmd = db.CreateQuery(); cmd.CommandText = "SELECT * FROM globalNews WHERE endTime >= now();"; using (var rdr = cmd.ExecuteReader()) { while (rdr.Read()) { ret.Add(new globalNews_struct { slot = rdr.GetInt32("slot"), linkType = rdr.GetInt32("linkType"), title = rdr.GetString("title"), image = rdr.GetString("image"), priority = rdr.GetInt32("priority"), linkDetail = rdr.GetString("linkDetail"), platform = rdr.GetString("platform"), startTime = long.Parse(Database.DateTimeToUnixTimestamp(rdr.GetDateTime("startTime")).ToString() + "000"), endTime = long.Parse(Database.DateTimeToUnixTimestamp(rdr.GetDateTime("endTime")).ToString() + "000") }); } } return ret; }
public void HandleRequest(HttpListenerContext context) { NameValueCollection query; using (StreamReader rdr = new StreamReader(context.Request.InputStream)) query = HttpUtility.ParseQueryString(rdr.ReadToEnd()); using (var db1 = new Database()) { chrs = new Chars() { Characters = new List<Char>() { }, NextCharId = 2, MaxNumChars = 1, Account = db1.Verify(query["guid"], query["password"]), Servers = new List<ServerItem>() { new ServerItem() { Name = "EUSouth", Lat = 22.28, Long = 114.16, DNS = db.confreader.getservers(false).ToString(), //127.0.0.1, CHANGE THIS TO LET YOUR FRIENDS CONNECT Usage = 0.2, AdminOnly = false } //new ServerItem() //{ // Name = "Admin Realm", // Lat = 22.28, // Long = 114.16, // DNS = "127.0.0.1", // Usage = 0.2, // AdminOnly = true //} } }; if (chrs.Account != null) { db1.GetCharData(chrs.Account, chrs); db1.LoadCharacters(chrs.Account, chrs); chrs.News = db1.GetNews(chrs.Account); } else { chrs.Account = Database.CreateGuestAccount(query["guid"]); chrs.News = db1.GetNews(null); } MemoryStream ms = new MemoryStream(); XmlSerializer serializer = new XmlSerializer(chrs.GetType(), new XmlRootAttribute(chrs.GetType().Name) { Namespace = "" }); XmlWriterSettings xws = new XmlWriterSettings(); xws.OmitXmlDeclaration = true; xws.Encoding = Encoding.UTF8; XmlWriter xtw = XmlWriter.Create(context.Response.OutputStream, xws); serializer.Serialize(xtw, chrs, chrs.Namespaces); } }
public int Level() { using (var dbx = new Database()) { var id = dbx.GetGuildId(Guild); return dbx.GetGuildLevel(id); } }
public int Level() { using (var db = new Database()) { int id = db.GetGuildId(this.Guild); return db.GetGuildLevel(id); } }
protected override void HandleRequest() { using (Database db = new Database()) { string jsonCode = String.Empty; string status = "Invalid code."; var cmd = db.CreateQuery(); cmd.CommandText = "SELECT * FROM giftCodes WHERE code=@code"; cmd.Parameters.AddWithValue("@code", Query["code"]); using (var rdr = cmd.ExecuteReader()) while (rdr.Read()) jsonCode = rdr.GetString("content"); var list = ParseContents(jsonCode); if (list.Count > 0) { status = String.Empty; foreach (var i in list) status += (i + "</br>"); } byte[] res = new byte[0]; if (status.IsNullOrWhiteSpace() || status == "Invalid code.") { res = Encoding.UTF8.GetBytes( $@"<html> <head> <title>Check Giftcode</title> </head> <body style='background: #333333'> <h1 style='color: #EEEEEE; text-align: center'> {status} </h1> </body> </html>"); } else { res = Encoding.UTF8.GetBytes( $@"<html> <head> <title>Check Giftcode</title> </head> <body style='background: #333333'> <h1 style='color: #EEEEEE; text-align: center'> Your Giftcode contains the following Items: </h1> <h3 style='color: #EEEEEE; text-align: center'> {status} </h3> </body> </html>"); } Context.Response.OutputStream.Write(res, 0, res.Length); } }
protected override void HandleRequest() { string result = ""; using (Database dbx = new Database()) { Account acc = dbx.Verify(Query["guid"], Query["password"], Program.GameData); if (String.IsNullOrEmpty(Query["guid"]) || String.IsNullOrEmpty(Query["password"]) || String.IsNullOrEmpty(Query["type"]) || acc == null) { Context.Response.StatusCode = 400; result = "<Error>Invalid GUID/password combination</Error>"; } else { string[][] ranks = dbx.GetArenaLeaderboards(Query["type"], acc); result += "<ArenaRecords>"; foreach (string[] i in ranks) { MySqlCommand cmd = dbx.CreateQuery(); cmd.CommandText = "select skin, tex1, tex2, items, charType, petId from characters where charid = @charid"; cmd.Parameters.AddWithValue("@charid", i[2]); string skin, tex1, tex2, inventory, cclass, petid; skin = tex1 = tex2 = inventory = cclass = petid = null; using (MySqlDataReader drdr = cmd.ExecuteReader()) { while (drdr.Read()) { skin = drdr.GetString("skin"); tex1 = drdr.GetString("tex1"); tex2 = drdr.GetString("tex2"); inventory = drdr.GetString("items"); cclass = drdr.GetString("charType"); petid = drdr.GetString("petId"); } } var _pet = dbx.GetPet(int.Parse(petid), acc); result += $"<Record><WaveNumber>{i[0]}</WaveNumber><Time>{i[4]}</Time><PlayData><CharacterData>"; if (acc.Guild.Name != null) result += $@"<GuildName>{acc.Guild.Name}</GuildName><GuildRank>{acc.Guild.Rank}</GuildRank>"; result += $"<Id>{i[2]}</Id><Texture>{skin}</Texture><Tex1>{tex1}</Tex1><Tex2>{tex2}</Tex2><Inventory>{inventory}</Inventory><Name>{acc.Name}</Name><Class>{cclass}</Class></CharacterData>"; result += "<Pet name=\"" + _pet.SkinName + "\" type=\"" + _pet.Type + "\" instanceId=\"" + _pet.InstanceId + "\" rarity=\"" + _pet.Rarity + "\" maxAbilityPower=\"" + _pet.MaxAbilityPower + "\" skin=\"" + _pet.Skin + "\" family=\"" + "Farm" + "\"><Abilities>"; for (int e = 0; e < 3; e++) result += "<Ability type=\"" + _pet.Abilities[e].Type + "\" power=\"" + _pet.Abilities[e].Power + "\" points=\"" + _pet.Abilities[e].Points + "\"/>"; result += "</Abilities></Pet></PlayData></Record>"; } result += "</ArenaRecords>"; } } byte[] buf = Encoding.UTF8.GetBytes(result); Context.Response.ContentType = "text/*"; Context.Response.OutputStream.Write(buf, 0, buf.Length); }
protected override void HandleRequest() { using (var db = new Database()) { List<ServerItem> filteredServers = null; Account a = db.Verify(Query["guid"], Query["password"]); if (a != null) { if (a.Banned) { filteredServers = YoureBanned(); } else { filteredServers = GetServersForRank(a.Rank); } } else { filteredServers = GetServersForRank(0); } Chars chrs = new Chars() { Characters = new List<Char>() { }, NextCharId = 2, MaxNumChars = 1, Account = db.Verify(Query["guid"], Query["password"]), Servers = filteredServers }; Account dvh = null; if (chrs.Account != null) { db.GetCharData(chrs.Account, chrs); db.LoadCharacters(chrs.Account, chrs); chrs.News = db.GetNews(chrs.Account); dvh = chrs.Account; } else { chrs.Account = Database.CreateGuestAccount(Query["guid"]); chrs.News = db.GetNews(null); } MemoryStream ms = new MemoryStream(); XmlSerializer serializer = new XmlSerializer(chrs.GetType(), new XmlRootAttribute(chrs.GetType().Name) { Namespace = "" }); XmlWriterSettings xws = new XmlWriterSettings(); xws.OmitXmlDeclaration = true; xws.Encoding = Encoding.UTF8; XmlWriter xtw = XmlWriter.Create(Context.Response.OutputStream, xws); serializer.Serialize(xtw, chrs, chrs.Namespaces); } }
public override void HandleRequest(HttpListenerContext context) { NameValueCollection query; using (var rdr = new StreamReader(context.Request.InputStream)) query = HttpUtility.ParseQueryString(rdr.ReadToEnd()); using (var db = new Database(Program.Settings.GetValue("conn"))) { Account acc = db.Verify(query["guid"], query["password"]); byte[] status; if (acc == null) status = Encoding.UTF8.GetBytes("<Error>Account credentials not valid</Error>"); else { try { status = Encoding.UTF8.GetBytes(db.GetGuildBoard(acc)); } catch (Exception e) { status = Encoding.UTF8.GetBytes("<Error>" + e.Message + "</Error>"); } } context.Response.OutputStream.Write(status, 0, status.Length); } }
public override void HandleRequest(HttpListenerContext context) { NameValueCollection query; using (var rdr = new StreamReader(context.Request.InputStream)) query = HttpUtility.ParseQueryString(rdr.ReadToEnd()); using (var db = new Database(Program.Settings.GetValue("conn"))) { Account acc = db.Verify(query["guid"], query["password"]); byte[] status; if (acc == null) status = Encoding.UTF8.GetBytes("<Error>Account credentials not valid</Error>"); else { MySqlCommand cmd = db.CreateQuery(); cmd.CommandText = @"DELETE FROM characters WHERE accId = @accId AND charId = @charId;"; cmd.Parameters.AddWithValue("@accId", acc.AccountId); cmd.Parameters.AddWithValue("@charId", query["charId"]); if (cmd.ExecuteNonQuery() > 0) status = Encoding.UTF8.GetBytes("<Success />"); else status = Encoding.UTF8.GetBytes("<Error>Internal Error</Error>"); } context.Response.OutputStream.Write(status, 0, status.Length); } }
public void HandleRequest(HttpListenerContext context) { NameValueCollection query; using (var rdr = new StreamReader(context.Request.InputStream)) query = HttpUtility.ParseQueryString(rdr.ReadToEnd()); using (var db = new Database()) { List<ServerItem> filteredServers = null; Account a = db.Verify(query["guid"], query["password"]); if (a != null) { if (a.Banned) { filteredServers = YoureBanned(); } else { filteredServers = GetServersForRank(a.Rank); } } else { filteredServers = GetServersForRank(0); } var chrs = new Chars { Characters = new List<Char>(), NextCharId = 2, MaxNumChars = 1, Account = db.Verify(query["guid"], query["password"]), Servers = filteredServers }; Account dvh = null; if (chrs.Account != null) { db.GetCharData(chrs.Account, chrs); db.LoadCharacters(chrs.Account, chrs); chrs.News = db.GetNews(chrs.Account); dvh = chrs.Account; } else { chrs.Account = Database.CreateGuestAccount(query["guid"]); chrs.News = db.GetNews(null); } var ms = new MemoryStream(); var serializer = new XmlSerializer(chrs.GetType(), new XmlRootAttribute(chrs.GetType().Name) {Namespace = ""}); var xws = new XmlWriterSettings(); xws.OmitXmlDeclaration = true; xws.Encoding = Encoding.UTF8; XmlWriter xtw = XmlWriter.Create(context.Response.OutputStream, xws); serializer.Serialize(xtw, chrs, chrs.Namespaces); db.Dispose(); } }
public void HandleRequest(HttpListenerContext context) { NameValueCollection query; using (var rdr = new StreamReader(context.Request.InputStream)) query = HttpUtility.ParseQueryString(rdr.ReadToEnd()); using (var db = new Database()) { Account acc = db.Verify(query["guid"], query["password"]); byte[] status; if (acc == null) status = Encoding.UTF8.GetBytes("<Error>Bad login</Error>"); else { try { status = Encoding.UTF8.GetBytes(db.HttpGetGuildMembers(Convert.ToInt32(query["num"]), Convert.ToInt32(query["offset"]), acc)); } catch { status = Encoding.UTF8.GetBytes("<Error>Guild member error</Error>"); } } context.Response.OutputStream.Write(status, 0, status.Length); context.Response.Close(); } }
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)); } }