Exemple #1
0
        protected override void initHandlers()
        {
            apiRouter = new Connect4APIRouter();

            connectionToServer.RegisterHandler((short)CommProtocol.MsgType.boardUpdate, requestMove);
            connectionToServer.RegisterHandler((short)CommProtocol.MsgType.playerInit, initSettings);
            connectionToServer.RegisterHandler((short)CommProtocol.MsgType.RPCMove, handleRPCMove);
            connectionToServer.RegisterHandler((short)CommProtocol.MsgType.gameInfo, handleGameStatus);
            connectionToServer.RegisterHandler((short)ServerCommProtocl.PlayerJoinedGameRoom, handlePlayerJoinedRoom);
            connectionToServer.RegisterHandler((short)ServerCommProtocl.PlayerLeftGameRoom, handlePlayerLeftRoom);
            connectionToServer.RegisterHandler((short)ServerCommProtocl.PlayerTimerInit, handlePlayerTimerInit);
            connectionToServer.RegisterHandler((short)ServerCommProtocl.PlayerTimerCommand, handlePlayerTimerCommand);
            StartCoroutine(findAndInitRenderer <Renderer>((x) => localRenderer = x));
            StartCoroutine(handleNetworkMsgQueue());

            //Quick hack
            humanControlls = localRenderer.gameObject.GetComponent <Connect4HumanControlls>();
            humanControlls.init((move) => {
                onOutgoingLocalMsg(move.ToString(), ClientPlayersHandler.sendFromCurrentPlayer());
                humanControlls.endPlayerTurn();
            });
            if (ClientPlayersHandler.hasLocalHumanPlayer())
            {
                ClientPlayersHandler.getLocalHumanPlayer().onHumanTakeInput = () => {
                    humanControlls.startPlayerTurn();
                }
            }
            ;

            TCPMessageQueue.readMsgInstant = ((msg) => {
                TCPMessageQueue.popMessage();
                readTCPMsg(msg);
            });
        }
    private void checkTCPInput()
    {
        if (readTCPInput == null)
        {
            return;
        }

        while (TCPMessageQueue.hasUnread)
        {
            ReceivedLocalMessage m = TCPMessageQueue.popMessage();
            readTCPInput(m.message);
        }
    }
Exemple #3
0
    private void listenForMessage()
    {
        while (clientConnected == false)
        {
            Thread.Sleep(1000);
        }

        Byte[] bytes = new Byte[2048 * 10];
        String data  = null;

        while (closeClient == false)
        {
            int i;
            data = null;

            while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
            {
                data = Encoding.ASCII.GetString(bytes, 0, i);
                TCPMessageQueue.addMessage(data, id);
            }

            Thread.Sleep(100);
        }
    }