Exemplo n.º 1
0
        public static void RemoveAgentMessageHandler(MsgCode protocolCode, Action <byte[]> handler)
        {
            if (!simulateBattle)
            {
                switch (battleType)
                {
                case BattleType.BattleP1vsP1:
                case BattleType.BattleP2vsP2:
                {
                    NetworkManager.RemoveServerMessageHandler(ServerType.BattleServer, protocolCode, handler);
                    break;
                }

                case BattleType.Tutorial:
                case BattleType.Survival:
                case BattleType.Tranining:
                {
                    LocalBattleMessageManager.RemoveLocalMessageHandler(protocolCode, handler);
                    break;
                }

                case BattleType.NoBattle:
                {
                    DebugUtils.LogWarning(DebugUtils.Type.Battle, "Preview mode!");
                    break;
                }

                default:
                {
                    DebugUtils.LogError(DebugUtils.Type.Battle, "Can't handle this battleType now! type = " + battleType);
                    break;
                }
                }
            }
            else
            {
                SimulateBattleMessageManager.RemoveSimulateMessageHandler(protocolCode, handler);
            }
        }
Exemplo n.º 2
0
        public static void SendRequest(MsgCode protocolCode, byte[] data, Action onRequestSuccess = null, Action onResquestFailed = null, int resendTimes = 1)
        {
            // data package analyze
            MessageAnalyze(protocolCode, data);

            if (!simulateBattle)
            {
                switch (battleType)
                {
                case BattleType.BattleP1vsP1:
                case BattleType.BattleP2vsP2:
                {
                    DebugUtils.Log(DebugUtils.Type.MessageAnalyze, string.Format("send message, msgcode {0}, length {1}", protocolCode, data.Length));
                    NetworkManager.SendRequest(protocolCode, data, ClientType.Tcp, onRequestSuccess, onResquestFailed, resendTimes);
                    break;
                }

                case BattleType.Survival:
                case BattleType.Tranining:
                case BattleType.Tutorial:
                {
                    LocalBattleMessageManager.SendRequest(protocolCode, data, onRequestSuccess);
                    break;
                }

                default:
                {
                    DebugUtils.LogError(DebugUtils.Type.Battle, "Can't handle this battleType now! type = " + battleType);
                    break;
                }
                }
            }
            else
            {
                SimulateBattleMessageManager.SendRequest(protocolCode, data, onRequestSuccess);
            }
        }