Example #1
0
        // --------------- Join game handlers -----------------
        // queue
        private void OnServerJoinSoloQueueRequest(NetworkMessage netMsg)
        {
            ClientJoinSoloQueueRequestMessage msg = netMsg.ReadMessage <ClientJoinSoloQueueRequestMessage>();

            Debug.Log("Server received JoinSoloQueue request from " + msg.userId + " " + msg.userName);
            User u = usersByName[msg.userName];

            if (u.isIdentified)
            {
                if (soloQueue.queueUser(u))
                {
                    GameLogicServer newgame = soloQueue.checkQueue();
                    if (newgame != null)
                    {
                        games[newgame.gameId] = newgame;
                        ServerSendNewGameDataToPlayers(newgame);
                    }
                    else
                    {
                        ServerJoinSoloQueueResponseMessage responseMsg = new ServerJoinSoloQueueResponseMessage();
                        responseMsg.joinedQueue = true;
                        netMsg.conn.Send(ServerJoinSoloQueueResponseMessage.ID, responseMsg);
                    }
                }
            }
            else
            {
                ServerJoinSoloQueueResponseMessage responseMsg = new ServerJoinSoloQueueResponseMessage();
                responseMsg.joinedQueue = false;
                netMsg.conn.Send(ServerJoinSoloQueueResponseMessage.ID, responseMsg);
            }
        }
Example #2
0
        // --------------- Actions handlers -----------------
        void OnServerRegisterTurnActions(NetworkMessage netMsg)
        {
            ClientRegisterTurnActionsMessage msg = netMsg.ReadMessage <ClientRegisterTurnActionsMessage>();

            Debug.Log("Server received OnServerRegisterTurnAction " + msg.userName);
            GameLogicServer game = games[msg.gameId];

            game.registerPlayerAction(game.getPlayerByUserId(msg.userId), msg.actions);
        }
Example #3
0
        // --------------- Turns handlers -----------------

        private void OnServerReadyToPlay(NetworkMessage netMsg)
        {
            ClientReadyToPlayMessage msg = netMsg.ReadMessage <ClientReadyToPlayMessage>();

            Debug.Log("Server received OnServerReadyToPlay from user " + msg.userName + " in game " + msg.gameId);
            GameLogicServer game = games[msg.gameId];

            game.registerPlayerReady(game.getPlayerByUserId(msg.userId));
        }
Example #4
0
        private void StartNewTurn(GameLogicServer game, long startTurnTimestamp)
        {
            ServerStartNewTurnMessage msgOut = new ServerStartNewTurnMessage();

            msgOut.startTurnTimestamp = startTurnTimestamp;
            foreach (Player p in game.players.Values)
            {
                p.user.connection.Send(ServerStartNewTurnMessage.ID, msgOut);
            }
            Debug.Log("Server sent StartNewTurn " + game.gameId);
        }
Example #5
0
 public void ServerStartTurnMessage(GameLogicServer game, long startTurnTimestamp)
 {
     if (game.currentTurn == 0)
     {
         StartGame(game, startTurnTimestamp);
     }
     else
     {
         StartNewTurn(game, startTurnTimestamp);
     }
 }
Example #6
0
        private Player CreatePlayer(User u, GameLogicServer game)
        {
            Player p = new Player();

            u.player     = p;
            p.user       = u;
            p.playerId   = u.userId;
            p.playerName = u.userName;
            game.createPlayer(p);
            game.preparingPlayersNumber++;
            return(p);
        }
Example #7
0
        public void SyncTurnActions(GameLogicServer game)
        {
            ServerSyncTurnActionsMessage msg = new ServerSyncTurnActionsMessage();

            Debug.Log("Server sent SyncTurnActions");
            msg.actions = game.generateTurnActionsJSON();
            foreach (Player player in game.players.Values)
            {
                User u = player.user;
                u.connection.Send(ServerSyncTurnActionsMessage.ID, msg);
            }
        }
Example #8
0
        public GameLogicServer checkQueue()
        {
            operationOnQueue.WaitOne();
            if (queue.Count >= 1)
            {
                User u2 = queue[queue.Count - 1];
                foreach (User u1 in queue)
                {
                    if (canMatch(u1, u2))
                    {
                        // dequeue players
                        queue.Remove(u1);
                        if (!forceSoloGame) // if non solo game
                        {
                            queue.Remove(u2);
                        }
                        u1.isQueued = false;
                        if (!forceSoloGame) // if non solo game
                        {
                            u2.isQueued = false;
                        }

                        // create game
                        GameLogicServer newGame = GameLogicServer.createGame();
                        u1.player = CreatePlayer(u1, newGame);
                        if (!forceSoloGame) // if non solo game
                        {
                            u2.player = CreatePlayer(u2, newGame);
                        }

                        operationOnQueue.ReleaseMutex();
                        return(newGame);
                    }
                    else if (u1.timeSpentInQueue > DELAY_BEFORE_MATCH_IA)     // too long, match with IA

                    {
                    }
                }
            }
            operationOnQueue.ReleaseMutex();
            return(null);
        }
Example #9
0
 public void init(GameLogicServer value)
 {
     this.setGameLogicServer(value);
 }