public ActionResult IpAddresses(string ipAddress = null) { var model = new PlayerInfoModel(); if (ipAddress != null) { using (var db = new DBConnection()) { model.IpAddresses = db.EvaluateTable("select * from account_login where ipaddress = '{0}' order by datetime desc limit 100", DBConnection.AddSlashes(ipAddress)); } } return View(model); }
public static void SetSession(Hashtable accountRow) { var account = Account.Load(accountRow); if (account == null) throw new Exception("Unable to log into null account."); account.SessionKey = System.Web.HttpContext.Current.Session.SessionID; System.Web.HttpContext.Current.Session["Account"] = account; var agent = System.Web.HttpContext.Current.Request.UserAgent; if (agent.Length > 250) agent = agent.Substring(0, 250); using (var db = new DBConnection()) { db.Execute("update account set last_on = {0}, num_logins = num_logins + 1 where id = {1}", Utility.UnixTimestamp(DateTime.UtcNow), account.Id); //if (!account.IsAdmin) db.Execute("insert ignore into account_login (account_id, datetime, ipaddress, browser, adminused) values ({0}, {1}, '{2}', '{3}', 'False')", account.Id, Utility.UnixTimestamp(DateTime.UtcNow), DBConnection.AddSlashes(System.Web.HttpContext.Current.Request.UserHostAddress), DBConnection.AddSlashes(agent)); foreach (var message in db.EvaluateTable("select distinct(from_id), account.Name from message join account on account.Id = from_id where to_id = {0} and readflag = 'False'", account.Id)) { AddChatWindow((int)message["from_id"], (string)message["Name"]); } db.Execute("update message set readflag = 'True' where to_id = {0}", account.Id); } var existingAccount = GameServer.GetOnlineAccount(account.Id); if (existingAccount == null) { if (account != null) { lock (GameServer.OnlineAccounts) { GameServer.OnlineAccounts.Add(account); } } else throw new Exception("Account record was null. This should never happen."); } else existingAccount.SessionKey = System.Web.HttpContext.Current.Session.SessionID; }
public ActionResult LoadChatMessages(int targetId, string targetName) { if (!LoggedIn) return null; using (var db = new DBConnection()) { var result = new ArrayList(); foreach (var message in db.EvaluateTable("select to_id, from_id, text from message where (to_id = {0} and from_id = {1}) or (to_id = {1} and from_id = {0}) order by id desc limit 20", targetId, Account.Id)) { result.Add(new { name = (int)message["from_id"] == Account.Id ? "Me" : targetName, text = (string)message["text"] }); } result.Reverse(); AddChatWindow(targetId, targetName); return Json(result); } }
public ActionResult PlayerInfo(int id) { if (id <= 0) return HttpNotFound(); var model = new PlayerInfoModel(); using (var db = new DBConnection()) { model.Account = Account.Load(db.EvaluateRow("select * from account where id = {0}", id)); if (model.Account == null) return HttpNotFound(); if (LoggedIn && Account.Id == id) // use freshest account record Account = model.Account; if (IsSet("ShowLoginHistory")) model.IpAddresses = db.EvaluateTable("select * from account_login where account_id = " + id + " order by datetime desc limit 100"); if (IsSet("KillAccount") && Account.IsAdmin) { db.Execute("update account set disabled_by = " + Account.Id + " where id=" + id); ViewBag.ErrorMessage = "Account Disabled"; } if (id > 1) model.Games = GameServer.GetPlayerGames(id, IsSet("AllGames")); else model.Games = new List<Game>(); } return View("PlayerInfo", model); }