private void instantReadTCPMsg(ReceivedLocalMessage msg)
        {
            if (msg.message == "JUMP")
            {
                localPlayer.activateJump();
            }

            MainThread.fireEventAtMainThread(() => {
                print("Sending msg");
                TCPLocalConnection.sendMessage(formatBoard());
            });
        }
Пример #2
0
 public void takeInput(ReceivedLocalMessage msg)
 {
     try {
         MainThread.fireEventAtMainThread(() => {
             logic.playMove(int.Parse(msg.message.Trim()));
         }
                                          );
     } catch {
         Debug.LogError("Could not handle move: " + msg.message);
     }
     //playMove ();
 }
    private void checkTCPInput()
    {
        if (readTCPInput == null)
        {
            return;
        }

        while (TCPMessageQueue.hasUnread)
        {
            ReceivedLocalMessage m = TCPMessageQueue.popMessage();
            readTCPInput(m.message);
        }
    }
Пример #4
0
    public static ReceivedLocalMessage popMessage()
    {
        ReceivedLocalMessage msg = messages [0];

        messages.RemoveAt(0);

        if (messages.Count <= 0)
        {
            hasUnread = false;
        }

        return(msg);
    }
Пример #5
0
    //Could possibly be more optimized later, trying to not check for null every msg, might be benefitical
    public static void addMessage(string message, int playerID)
    {
        message = message.Trim();
        ReceivedLocalMessage newMsg = new ReceivedLocalMessage(message, playerID);

        messages.Add(newMsg);
        hasUnread = true;

        if (readMsgInstant != null)
        {
            readMsgInstant(newMsg);
        }
    }
Пример #6
0
        protected virtual void readTCPMsg(ReceivedLocalMessage inMsg)
        {
            APIMsgConclusion outMsg = apiRouter.handleIncomingMsg(inMsg.message);

            if (outMsg.target == MsgTarget.Server)
            {
                onOutgoingLocalMsg(outMsg.msg, ClientPlayersHandler.sendFromCurrentPlayer());
                isListeningForTCP = false;
            }
            else if (outMsg.target == MsgTarget.Player)
            {
                ClientPlayersHandler.getCurrentPlayer().takeInput(outMsg.msg);
            }
        }
        //Since we assume that there is only one bot from the local player we override
        protected override void readTCPMsg(ReceivedLocalMessage msg)
        {
            if (isGameOver)
            {
                return;
            }

            List <TCPCommand> playerCommands = SoldiersTCPProtocol.convertMsgToCommands(msg.message);

            if (playerCommands.Count == 0)
            {
                RealtimeTCPController.requestBoard(convertColorToTeam(localPlayerColor), true);
                return;
            }

            PlayerCommands outMsg = new PlayerCommands(localPlayerColor, playerCommands);

            sendServerMsg(outMsg, (short)SoldiersProtocol.MsgType.playerCommands);
            RealtimeTCPController.requestBoard(0, true);
        }
Пример #8
0
        private void readTCPMessage(ReceivedLocalMessage msg)
        {
            try {
                string[] words = msg.message.Split(' ');
                int      x     = int.Parse(words[0]);
                int      y     = int.Parse(words[1]);

                if (gameController.isInRange(x, y))
                {
                    bool hit = gameController.samplePixel(x, y);
                    TCPLocalConnection.sendMessage(hit ? "HIT" : "MISS");
                }
                else
                {
                    TCPLocalConnection.sendMessage("OUT OF BOUNDS");
                }
            } catch (Exception e) {
                Debug.LogError(e.Message);
                TCPLocalConnection.sendMessage("Invalid Message");
            }
        }
        private void readTCPMessage(ReceivedLocalMessage msg)
        {
            if (gameStarted == false)
            {
                return;
            }

            foreach (string c in msg.message.Trim().Split('|'))
            {
                try {
                    string[] words = c.Trim().ToLower().Split(' ');
                    if (words.Length < 3 || (words[0] != "s" && words[0] != "c"))
                    {
                        continue;
                    }
                    ActionType type = words[0] == "s" ? ActionType.Swap : ActionType.Compare;

                    int[] param = new int[words.Length - 1];
                    for (int i = 0; i < words.Length - 1; i++)
                    {
                        param[i] = int.Parse(words[i + 1]);
                        if (controller.isInRange(param[i]) == false)
                        {
                            continue;
                        }
                    }

                    theAnimator.addAction(new SortAction()
                    {
                        type = type, indexes = new List <int>()
                        {
                            param[0], param[1]
                        }
                    });
                }
                catch (Exception e) { Debug.LogError(e.Message); }
            }
        }
Пример #10
0
        protected override void readTCPMsg(ReceivedLocalMessage msg)
        {
            if (msg.message.Length == 0)
            {
                RealtimeTCPController.requestBoard(convertColorToTeam(localPlayerColor), true);
                return;
            }
            APIMsgConclusion conclusion = APIRouter.handleIncomingMsg(msg.message);

            if (conclusion.target == MsgTarget.Server)
            {
                int dir = -1;
                if (parseCommandMsg(msg.message, out dir))
                {
                    sendServerMsg(new GameCommand(localPlayerColor, dir), (short)SnakeProtocol.MsgType.playerCommands);
                }

                RealtimeTCPController.requestBoard(convertColorToTeam(localPlayerColor), true);
            }
            else if (conclusion.status == ResponseStatus.Success && conclusion.target == MsgTarget.Player)
            {
                ClientPlayersHandler.getPlayerFromColor(localPlayerColor).takeInput(conclusion.msg);
            }
        }
Пример #11
0
        protected override void readTCPMsg(ReceivedLocalMessage msg)
        {
            if (waitingForInput == false)
            {
                return;
            }

            int[] start = new int[2], target = new int[2];
            if (validInput(msg.message, ref start, ref target) == false)
            {
                requestMove(lastBoardMsg);
                return;
            }

            if (lastBoardMsg.updateNumber % 2 != 0)
            {
                ClientUtil.rotateCoords(lastBoardMsg.board.GetLength(1), ref start, ref target);
            }

            string outString = ClientUtil.moveToString(start, target);

            onOutgoingLocalMsg(outString, lastBoardMsg.updateNumber % 2 == 0 ? PlayerColor.White : PlayerColor.Black);
            waitingForInput = false;
        }
        protected override void readTCPMsg(ReceivedLocalMessage msg)
        {
            if (isGameOver)
            {
                return;
            }
            if (msg.message.Length == 0)
            {
                RealtimeTCPController.requestBoard(BombermanOverlord.convertColorToTeam(localPlayerColor), true);
                return;
            }

            PlayerCommand outMsg = new PlayerCommand(localPlayerColor, -1);

            parseInputMoveDir(msg.message, ref outMsg);
            parseDropBomb(msg.message, ref outMsg);
            if (outMsg.moveDir >= 0 || outMsg.dropBomb)
            {
                sendServerMsg(outMsg, (short)BombermanProtocol.MsgType.playerCommands);
            }


            RealtimeTCPController.requestBoard(BombermanOverlord.convertColorToTeam(localPlayerColor), true);
        }
Пример #13
0
        private void readTCPMsg(ReceivedLocalMessage inMsg)
        {
            APIMsgConclusion outMsg = APIRouter.handleIncomingMsg(inMsg.message);

            TCPLocalConnection.sendMessage(outMsg.msg);
        }
Пример #14
0
 protected override void readTCPMsg(ReceivedLocalMessage msg)
 {
     print("Got TCP msg: " + msg.message);
 }