コード例 #1
0
        protected override void ExecuteDetails()
        {
            //This handles the Heartbeat and ack responce from GM.
            base.ExecuteDetails();

            //Get the game and passoff data
            LobbyAppState lobAppState = (LobbyAppState)SubSystem.appState;
            LobbyGame game = lobAppState.getGame(this.gameID);

            //Starting Official Passoff.
            //Handling GameId to player1
            Envelope envToPlayer1 = new Envelope(new GameIdMessage(this.gameID,game.Pl1.Id,game.Pl2.Id,game.GM.TCPEP.ToString(),game.Pl1.name,game.Pl2.name,false,false,false,false, new Identifier(this.SubSystem.ProcessID, SubSystem.GetNextSeqNumber()), this.ConversationId), null, Player1EP, IsTcpConversation);
            Envelope recievedFromPlayer1 = DoReliableRequestReply(envToPlayer1, this.ExceptedReplyType);
            if (recievedFromPlayer1 == null)
            {
                Logger.Error($"{this.GetType()}-{this.ConversationId}, Failed to recieve Env from player1. Ending Conversation Early.");
                return; //ending conversation early.
            }
            this.ProcessValidResponse(recievedFromPlayer1);

            //Handling GameId to player2
            Envelope envToPlayer2 = new Envelope(new GameIdMessage(this.gameID, game.Pl1.Id, game.Pl2.Id, game.GM.TCPEP.ToString(), game.Pl1.name, game.Pl2.name, false, false, false, false, new Identifier(this.SubSystem.ProcessID, SubSystem.GetNextSeqNumber()), this.ConversationId), null, Player2EP, IsTcpConversation);
            Envelope recievedFromPlayer2 = DoReliableRequestReply(envToPlayer2, this.ExceptedReplyType);
            if (recievedFromPlayer2 == null)
            {
                Logger.Error($"{this.GetType()}-{this.ConversationId}, Failed to recieve Env from player2. Ending Conversation Early.");
                return; //ending conversation early.
            }
            this.ProcessValidResponse(recievedFromPlayer2);

            //Conversation ends in success.
            this.State = PossibleState.Successed;
            Logger.Info("Pass off ended in success!");
        }
コード例 #2
0
ファイル: GameController.cs プロジェクト: SeanDunlop/ChessApi
        public IEnumerable <LobbyGame> GetGames()
        {
            List <Game>      games = reader.getOpenGames();
            List <LobbyGame> lgs   = new List <LobbyGame>();

            foreach (Game g in games)
            {
                LobbyGame lg = new LobbyGame();
                User      u;
                if (g.playerW == -1)
                {
                    u            = reader.getUser(g.playerB);
                    lg.gameId    = g.gameId;
                    lg.hostName  = u.username;
                    lg.hostElo   = u.elo;
                    lg.hostColor = "Black";
                }
                else
                {
                    u            = reader.getUser(g.playerW);
                    lg.gameId    = g.gameId;
                    lg.hostName  = u.username;
                    lg.hostElo   = u.elo;
                    lg.hostColor = "White";
                }
                lgs.Add(lg);
            }
            return(lgs);
        }
コード例 #3
0
    private static void UpdatedGame(Message m)
    {
        print("Received: updated_game_lobby");

        LobbyGame g = m.payload["game"].ToObject <LobbyGame>();

        MenuServerLobby.UpdateGame(g);
        MenuGameLobby.UpdateGameIfActive(g);
    }
コード例 #4
0
    public static void UpdateGameIfActive(LobbyGame _game)
    {
        if (game != null && game.id != _game.id)
        {
            return;
        }

        game       = _game;
        updateGame = true;
    }
コード例 #5
0
        public LobbyGame getGame(short gameID)
        {
            LobbyGame game = null;

            //if (GamesBeingPlayed.TryGetValue(gameID, out game))
            //{
            //    return game;
            //}
            //return null;
            GamesBeingPlayed.TryGetValue(gameID, out game);
            return(game);
        }
コード例 #6
0
        public async Task <GenericResponse <LobbyGame> > SaveAsync(LobbyGame lobbyGame)
        {
            try{
                await lobbyGameRepository.AddAsync(lobbyGame);

                await unityOfWork.CompleteAsync();

                return(new GenericResponse <LobbyGame>(lobbyGame));
            }
            catch (Exception ex) {
                return(new GenericResponse <LobbyGame>($"Error while saving lobby game. Message:{ex.Message}"));
            }
        }
コード例 #7
0
    private static void LeftGame(Message m)
    {
        print("Received: left_game_lobby");

        LobbyGame g = m.payload["game"].ToObject <LobbyGame>();

        MenuServerLobby.UpdateGame(g);
        MenuGameLobby.UpdateGameIfActive(g);

        if (m.payload["player"].ToObject <LobbyPlayer>().id == NetworkManager.my_id)
        {
            MenuGameLobby.leftGame = true;
        }
    }
コード例 #8
0
    public static void UpdateGame(LobbyGame _game)
    {
        int idx = GetGameIndex(_game.id);

        if (idx >= 0)
        {
            if (_game.players.Count == 0)
            {
                games.RemoveAt(idx);
            }
            else
            {
                games[idx] = _game;
            }
            updateGames = true;
        }
    }
コード例 #9
0
        public async Task <GenericResponse <LobbyGame> > UpdateAsync(LobbyGame lobbyGame)
        {
            var existLobbyGame = await lobbyGameRepository.FindByIdAsync(lobbyGame.Id);

            if (existLobbyGame == null)
            {
                return(new GenericResponse <LobbyGame>("Lobby game not found!"));
            }

            try
            {
                lobbyGameRepository.Update(lobbyGame);
                await unityOfWork.CompleteAsync();

                return(new GenericResponse <LobbyGame>(lobbyGame));
            }
            catch (Exception ex)
            {
                return(new GenericResponse <LobbyGame>($"Error when updating lobby game: {ex.Message}"));
            }
        }
コード例 #10
0
        private async Task <GameResponse> StartNewGameInternalAsync(string connectionId, StartNewGameRequest request)
        {
            if (!UsersByConnectionId.ContainsKey(connectionId))
            {
                Logger.LogError($"Got new game message for unknown connection id '{connectionId}'");
                return(GameResponse.Failure("Connection not found"));
            }

            var user = UsersByConnectionId[connectionId];

            var existingGame = FindGameForUser(user.Name);

            if (existingGame != null)
            {
                Logger.LogError($"Got new game message for user already in game '{user.Name}' '{existingGame.Name}'");
                return(GameResponse.Failure("You are already in a game so cannot start a new one"));
            }

            if (request.QuickJoin)
            {
                var pendingGame = GamesById.Values.OrderBy(g => g.Started).FirstOrDefault(game => game.CanQuickJoin(game.GameType));
                if (pendingGame != null)
                {
                }

                return(GameResponse.Succeeded(pendingGame));
            }

            var newGame = new LobbyGame(user.Name, request);

            newGame.NewGame(user);
            GamesById.Add(newGame.Id, newGame);

            await subscriber.PublishAsync(RedisChannels.NewGame, JsonConvert.SerializeObject(newGame));

            return(GameResponse.Succeeded(newGame));
        }
コード例 #11
0
    public void UpdateGameList(List <LobbyGame> games, MenuServerLobby lobby)
    {
        content.sizeDelta = new Vector2(0, games.Count * rowSize);

        foreach (Transform child in SpawnPoint)
        {
            Destroy(child.gameObject);
        }

        for (int i = 0; i < games.Count; i++)
        {
            LobbyGame game = games[i];

            float      spawnY   = i * rowSize;
            Vector3    pos      = new Vector3(10, -spawnY, 0);
            GameObject listItem = Instantiate(item, pos, SpawnPoint.rotation);

            listItem.transform.SetParent(SpawnPoint, false);
            listItem.GetComponent <ItemDetail>().SetText(game.name, game.players.Count);
            listItem.GetComponent <Button>().onClick.AddListener(() => {
                lobby.SetSelectedGame(listItem, game.id);
            });
        }
    }
コード例 #12
0
ファイル: UIController.cs プロジェクト: gamesFTW/card-game
        private async void UpdateGames()
        {
            var lobbyGames = this.transform.Find("LobbyGames");

            foreach (Transform child in lobbyGames)
            {
                GameObject.Destroy(child.gameObject);
            }

            GamesData gamesData = await LobbyServerApi.GetGames <GamesData>();

            foreach (GameData game in gamesData.Games)
            {
                GameObject lobbyGame = Instantiate <GameObject>(this.lobbyGame, lobbyGames);
                lobbyGame.transform.SetParent(lobbyGames.transform);

                LobbyGame lobbyGameComponent = lobbyGame.GetComponent <LobbyGame>();

                lobbyGameComponent.lobbyGameId  = game._id;
                lobbyGameComponent.gameServerId = game.gameServerId;
                lobbyGameComponent.deckName1    = game.deckName1;
                lobbyGameComponent.deckName2    = game.deckName2;
            }
        }
コード例 #13
0
 public static void NewGame(LobbyGame _game)
 {
     games.Add(_game);
     updateGames = true;
 }
コード例 #14
0
ファイル: UIController.cs プロジェクト: gamesFTW/card-game
        private async void OnDeleteGameHandler(LobbyGame lobbyGame)
        {
            await LobbyServerApi.DeleteGame(lobbyGame.lobbyGameId);

            UpdateGames();
        }
コード例 #15
0
 public void Delete(LobbyGame lobbyGame)
 {
     context.LobbyGames.Remove(lobbyGame);
 }
コード例 #16
0
 public async Task AddAsync(LobbyGame lobbyGame)
 {
     await context.LobbyGames.AddAsync(lobbyGame);
 }
コード例 #17
0
 public static GameResponse Succeeded(LobbyGame game)
 {
     return(new GameResponse {
         Success = true, Game = game
     });
 }
コード例 #18
0
        protected async Task SendGameStateAsync(LobbyGame game)
        {
            var gameSummary = game.ToGameSummary();

            await Clients.Group(gameSummary.Id).GameState(gameSummary);
        }
コード例 #19
0
 public void Update(LobbyGame lobbyGame)
 {
     context.LobbyGames.Update(lobbyGame);
 }
コード例 #20
0
 protected override Message CreateFirstMessage()
 {
     LobbyGame game = ((LobbyAppState)SubSystem.appState).getGame(this.gameID);
     Logger.Debug($"Creating first message of playerID");
     return new PlayerIdMessage(this.gameID, game.Pl1.Id, game.Pl2.Id, game.Pl1.EP.ToString(), game.Pl2.EP.ToString(), game.Pl1.name, game.Pl2.name, false, false, false, false, new Identifier(this.SubSystem.ProcessID, SubSystem.GetNextSeqNumber()), this.ConversationId);
 }
コード例 #21
0
 public static void UpdateGame(LobbyGame _game)
 {
     game       = _game;
     updateGame = true;
 }