public ActionResult Create(Game model) { if (ModelState.IsValid) { GameServer.SaveNewGame(model); model.Join(Account.Id, Account.Name, Account.Rating); GameServer.PlayerJoined(model, Account.Id); return Redirect("/Game-" + model.Id + "/"); } // If we got this far, something failed, redisplay form return View(model); }
internal static void Say(Game game, Ship ship, string message) { if (game != null && ship != null) { var groupName = GetShipGroupName(game.Id, ship.Id); var context = GlobalHost.ConnectionManager.GetHubContext<GameHub>(); context.Clients.Group(groupName).addMessage(0, "System", message); } }
public static void SaveNewGame(Game game) { using (var db = CreateDB()) { db.ExecuteWithParams("insert into game (Status, Serialized, Private) values (@Status, @Serialized, @Private) ", new { Status = game.Status, Serialized = game.Save(), @Private = (game.IsPrivate ? 1 : 0) }); game.Id = (int)db.LastInsertID; if (String.IsNullOrEmpty(game.GameName)) game.GameName = "Game #" + game.Id; } // save the new id SaveGame(game); // insert into cache HttpContext.Current.Cache[game.Id.ToString()] = game; }
void Initalize(int id) { game = GameServer.GetGame(id); if (game == null) { Response.RedirectPermanent("/", true); Response.End(); return; } if (LoggedIn) { player = game.GetPlayer(Account.Id); } if (player != null) { player.SessionId = Request.Cookies["ASP.Net_SessionId"].Value; } else { player = game.GetPlayer(Request.Cookies["ASP.Net_SessionId"].Value); } if (player == null) player = game.Players[0]; ViewBag.Player = player; }
public static void SaveGame(Game game) { using (var db = CreateDB()) { db.ExecuteWithParams("update game set Status = @Status, Serialized = @Serialized, Private = @Private where id = @Id", new { Id = game.Id, Status = game.Status, Serialized = game.Save(), @Private = (game.IsPrivate ? 1 : 0) }); } }
public static void PlayerUnjoined(Game game, int accountId) { using (var db = CreateDB()) { db.Execute("delete from player where game_id = {0} and account_id = {1}", game.Id, accountId); if (game.Players.Count <= 0) KillGame(game.Id); } }
public static void PlayerJoined(Game game, int accountId) { SaveGame(game); using (var db = CreateDB()) { db.Execute("delete from player where game_id = {0} and account_id = {1} and isInvite = 1", game.Id, accountId); db.Execute("insert into player (game_id, account_id) values ({0}, {1}) ", game.Id, accountId); } }
public static void PlayerInvited(Game game, Account account) { SaveGame(game); using (var db = CreateDB()) { db.Execute("insert into player (game_id, account_id, isInvite) values ({0}, {1}, 1) ", game.Id, account.Id); } }
public static void EmailAllPlayers(Game game, string subject, string message, bool isGameStart = false) { using (var db = new DBConnection()) { foreach (var player in game.Players) { if (GetOnlineAccount(player.AccountId) == null) { var accountRow = db.EvaluateRow("select name, email, forward_emails from account where id = {0}", player.AccountId); if (accountRow != null) { string forwardEmails = (string)accountRow["forward_emails"]; if (isGameStart && forwardEmails == "GameStarts") SendEmail((string)accountRow["email"], (string)accountRow["name"], subject, message); else { if (forwardEmails == "All" || forwardEmails == "AllGame") SendEmail((string)accountRow["email"], (string)accountRow["name"], subject, message); } } } } } }