コード例 #1
0
        private void startGame(PreGame game, IIncommingMessage rawMsg = null)
        {
            string spawnCode = SpawnersModule.singleton.createNewRoomFromPreGame(game.getPeers(), game.generateGameSettings(), game.specs.roomID);

            if (string.IsNullOrEmpty(spawnCode))   // We encountered some kind of error when spawning a new gameRoom
            {
                if (rawMsg != null)
                {
                    rawMsg.Respond("Server error during game startup", ResponseStatus.Error);
                }
                return;
            }
            moveGameToActiveGames(game);

            game.specs.spawnCode = spawnCode;
            PreGameStartedMsg msg = new PreGameStartedMsg()
            {
                specs = game.specs, slots = game.getPlayerSlots()
            };

            //Debug.LogError("Starting game: " + game.specs.roomID + " with: " + game.getPeers().Count + " peers." + "  Tournament: " + game.specs.tournamentRoundID.col + "." + game.specs.tournamentRoundID.row);

            GamesData.totallGamesPlayed++;
            game.onpreGameStarted();
            game.getPeers().ForEach(p => { p.SendMessage((short)ServerCommProtocl.GameRoomInvite, msg); });

            if (rawMsg != null)
            {
                rawMsg.Respond(ResponseStatus.Success);
                UserDataModule.onGameStarted(game);
            }
        }
コード例 #2
0
        private PreGame createGame(PreGameSpecs specs, IPeer gameHost)
        {
            specs.roomID = generatePreGameID();
            PreGame newGame = new PreGame(gameHost, specs, spectatorModule);

            addGameToPreGameDicts(newGame, specs.roomID);

            return(newGame);
        }
コード例 #3
0
        private bool findGame(string key, out PreGame game, IIncommingMessage rawMsg = null)
        {
            if (allGamesDict.TryGetValue(key, out game))
            {
                return(true);
            }

            if (rawMsg != null)
            {
                rawMsg.Respond("Could not find matching game", ResponseStatus.Error);
            }

            game = null;
            return(false);
        }
コード例 #4
0
 private void moveGameToActiveGames(PreGame game)
 {
     if (allGames.Contains(game))
     {
         allPreGamesList.Remove(game);
     }
     if (currentPreGames.ContainsKey(game.specs.roomID))
     {
         currentPreGames.Remove(game.specs.roomID);
     }
     if (activeGames.ContainsKey(game.specs.roomID) == false)
     {
         activeGames.Add(game.specs.roomID, game); //Adding the game to the active pool, so it can be re-started easily.
     }
 }
コード例 #5
0
        public static void removeGame(PreGame game, string roomID)
        {
            if (game.state == PreGameState.Lobby)
            {
                singleton.currentPreGames.Remove(roomID);
                singleton.allPreGamesList.Remove(game);
            }
            else
            {
                singleton.activeGames.Remove(roomID);
            }

            singleton.allGames.Remove(game);
            singleton.allGamesDict.Remove(roomID);
            game.onRemoved();
        }
コード例 #6
0
 private void addGameToPreGameDicts(PreGame game, string roomID)
 {
     if (currentPreGames.ContainsKey(roomID) == false)
     {
         currentPreGames.Add(roomID, game);
     }
     if (allGamesDict.ContainsKey(roomID) == false)
     {
         allGamesDict.Add(roomID, game);
     }
     if (allGames.Contains(game) == false)
     {
         allGames.Add(game);
     }
     if (allPreGamesList.Contains(game) == false)
     {
         allPreGamesList.Add(game);
     }
 }
コード例 #7
0
        private void handleRestartGame(IIncommingMessage rawMsg)
        {
            if (activeGames.ContainsKey(rawMsg.AsString()) == false)
            {
                rawMsg.Respond("Could not find matching game", ResponseStatus.Error);
                return;
            }
            PreGame targetGame = activeGames[rawMsg.AsString()];

            if (targetGame.containsPeer(rawMsg.Peer) == false || targetGame.specs.canRestart == false)
            {
                return;
            }

            targetGame.updatePeerReady(rawMsg.Peer, true);
            if (targetGame.canGameStart())
            {
                startGame(targetGame, rawMsg);
            }
        }
コード例 #8
0
 public static void startTournamentgame(PreGame game)
 {
     singleton.startGame(game);
 }
コード例 #9
0
 public static void onGameStarted(PreGame game)
 {
     theDB.insertNewGameStarted(DateTime.Now.Ticks, game.specs.type.ToString(), playersToString(game.getPlayerInfo()));
 }