public void OnGameStart(ServerGame game, ServerClient opponent) { _Opponent = opponent; GameStart start = new GameStart(game.GameConfiguration, PlayerState.GetBaseArmy(), Opponent.PlayerState.GetBaseArmy(), Opponent.Name, PlayerState.ReinforcementPoints); QueueMessage(new ServerToClientMessage(start)); }
public bool OnJoinGameRequest(ServerClient client, JoinGameRequest request, out ServerGame game) { if (request.IsPrivate) { string key = request.PrivateKey; if (!PrivateGames.TryGetValue(key, out game)) { return(false); } PrivateGames.Remove(key); } else { string key = request.Owner; if (!PublicGames.TryGetValue(key, out game)) { return(false); } PublicGames.Remove(key); } ActiveGames.Add(game); game.StartDeploymentTimer(); return(true); }
void CancelGame(ServerClient client) { ServerGame game = client.Game; if (game.IsPrivate) { PrivateGames.Remove(game.Owner.Name); } else { PublicGames.Remove(game.PrivateKey); } }
public CreateGameReply OnCreateGameRequest(ServerClient client, CreateGameRequest request, out ServerGame game) { Map map = GetMap(request.GameConfiguration.Map); if (map == null) { throw new ServerClientException("No such map"); } ValidateGameConfiguration(request.GameConfiguration); if (request.IsPrivate) { string privateKey = GeneratePrivateKey(); game = new ServerGame(this, client, true, privateKey, request.GameConfiguration, map); PrivateGames[privateKey] = game; return(new CreateGameReply(privateKey)); } else { game = new ServerGame(this, client, false, null, request.GameConfiguration, map); PublicGames[client.Name] = game; return(new CreateGameReply()); } }
public bool OnJoinGameRequest(ServerClient client, JoinGameRequest request, out ServerGame game) { if (request.IsPrivate) { string key = request.PrivateKey; if (!PrivateGames.TryGetValue(key, out game)) return false; PrivateGames.Remove(key); } else { string key = request.Owner; if (!PublicGames.TryGetValue(key, out game)) return false; PublicGames.Remove(key); } ActiveGames.Add(game); game.StartDeploymentTimer(); return true; }
public void OnGameEnd(ServerGame game, GameOutcomeType outcome, ServerClient winner = null) { ActiveGames.Remove(game); game.EndGame(new GameEndBroadcast(outcome, winner)); }
public CreateGameReply OnCreateGameRequest(ServerClient client, CreateGameRequest request, out ServerGame game) { Map map = GetMap(request.GameConfiguration.Map); if (map == null) throw new ServerClientException("No such map"); ValidateGameConfiguration(request.GameConfiguration); if (request.IsPrivate) { string privateKey = GeneratePrivateKey(); game = new ServerGame(this, client, true, privateKey, request.GameConfiguration, map); PrivateGames[privateKey] = game; return new CreateGameReply(privateKey); } else { game = new ServerGame(this, client, false, null, request.GameConfiguration, map); PublicGames[client.Name] = game; return new CreateGameReply(); } }