Пример #1
0
    public void OnReceive()
    {
        if (messageQueue.Count > 0)
        {
            MarsMessage message = messageQueue.Dequeue();
            if (message == null)
            {
                Debug.LogFormat("消息={)},消息队列情况长度={1}", message, messageQueue.Count);
                return;
            }
            switch (message.cmd)
            {
            case MessageConst.Battle.RESP_MOVE_CHESS:
                Debug.Log("移动棋子");
                RespMoveChess respMoveChess = ProtobufTool.DeSerialize <RespMoveChess>(message.data);
                ReceiveChessMove(respMoveChess);
                break;

            case MessageConst.Battle.RESP_CURRENT_GO_INFO:
                Debug.Log("当前行动信息");
                RespCurrentGoInfo respCurrentGoInfo = ProtobufTool.DeSerialize <RespCurrentGoInfo>(message.data);
                ReceiveGoInfo(respCurrentGoInfo);
                break;

            default:
                break;
            }
        }
    }
Пример #2
0
    public void Handle(int cmd, byte[] data)
    {
        switch (cmd)
        {
        case MessageConst.Tips.TIPS_RESP_RESULT:
            GameTips gameTips = ProtobufTool.DeSerialize <GameTips>(data);
            message.Enqueue(gameTips);
            break;

        default:
            break;
        }
    }
Пример #3
0
        private void UpdateDataFeedProducts3(byte[] message)
        {
            Thread.Sleep(10000);
            JobRabbitMQ jobReceived = ProtobufTool.DeSerialize <JobRabbitMQ>(message);

            if (jobReceived.JobName == "UpdateDatafeed")
            {
                if (jobReceived.JobType == 1)
                {
                    Log.InfoFormat("Consumer3 worked with CompanyID = {0}", jobReceived.JobInformation);
                    QT.Entities.Server.ConnectionString = connectionString;
                    CompanyFunctions companyfuncition = new CompanyFunctions();
                    Company          company          = new Company(Common.Obj2Int64(jobReceived.JobInformation));
                    cancelUpdateDataFeedTokenSource = new CancellationTokenSource();
                    companyfuncition.UpdateDataFeedProducts(company, cancelUpdateDataFeedTokenSource);
                }
            }
        }
Пример #4
0
    public void Handle(int cmd, byte[] data)
    {
        switch (cmd)
        {
        case MessageConst.Room.RESP_BEGIN_MATCH:
            RespBeginMatch respBeginMatch = ProtobufTool.DeSerialize <RespBeginMatch>(data);
            BeginMatch(respBeginMatch.beginTime);
            break;

        case MessageConst.Room.RESP_CANEL_MATCH:
            RespCancelMatch respCancelMatch = ProtobufTool.DeSerialize <RespCancelMatch>(data);
            CancelMatch(respCancelMatch.gameResultEnum);
            break;

        default:
            break;
        }
    }
Пример #5
0
    public void Handle(int cmd, byte[] data)
    {
        switch (cmd)
        {
        case MessageConst.Login.RESP_CREATE_ROLE:
            //CreateRole createRole = ProtobufTool.DeSerialize<CreateRole>(data);
            actions.Enqueue(CreateRole);
            break;

        case MessageConst.Login.RESP_ENTER_GAME:
            EnterGame enterGame = ProtobufTool.DeSerialize <EnterGame>(data);
            PlayerManager.self.player        = enterGame.player;
            PlayerManager.self.statusManager = new PlayerStatusManager();
            actions.Enqueue(LoginSuccess);
            break;

        default:
            break;
        }
    }
Пример #6
0
        private void ReceiveHead(IAsyncResult ar)
        {
            int count = (int)ar.AsyncState;

            count += socket.EndReceive(ar);
            //如果头数据长度不够,继续读
            if (count < headlen)
            {
                socket.BeginReceive(head, count, headlen - count, SocketFlags.None, new AsyncCallback(ReceiveHead), count);
            }
            else
            {
                //处理一下高低字节位问题
                byte[] realBytesLen = new byte[headlen];
                for (int i = 0; i < headlen; i++)
                {
                    realBytesLen[i] = head[headlen - 1 - i];
                }
                int    length = ByteUtil.byteArray2Int(realBytesLen, 0);
                byte[] data   = new byte[length];//声明接受数组
                count = 0;
                while (count < length)
                {
                    int tempLength = socket.Receive(data, count, length - count, SocketFlags.None);
                    count += tempLength;
                }
                socket.BeginReceive(head, 0, headlen, SocketFlags.None, new AsyncCallback(ReceiveHead), 0);
                MarsMessage msg = ProtobufTool.DeSerialize <MarsMessage>(data);
                //心跳消息直接在本类处理
                if (msg.messageType == 1)
                {
                    Pong pong = ProtobufTool.DeSerialize <Pong>(msg.data);
                    Pong(pong);
                }
                else
                {
                    MessageDispatcher.Receive(msg);
                }
            }
        }
Пример #7
0
    public void Handle(int cmd, byte[] data)
    {
        switch (cmd)
        {
        case MessageConst.Battle.RESP_GAME_INIT:    //初始化游戏
            Debug.Log("开始初始化游戏...");
            RespGameInit respGameInit = ProtobufTool.DeSerialize <RespGameInit>(data);
            BattleStatus.INSTANCE.respGameInit = respGameInit;
            PlayerManager.self.statusManager.Switch(BattleStatus.INSTANCE);
            actions.Enqueue(GameInit);
            break;

        case MessageConst.Battle.RESP_MOVE_CHESS:
            RespMoveChess respMoveChess = ProtobufTool.DeSerialize <RespMoveChess>(data);
            break;

        case MessageConst.Battle.RESP_CURRENT_GO_INFO:
            RespCurrentGoInfo respCurrentGoInfo = ProtobufTool.DeSerialize <RespCurrentGoInfo>(data);
            break;

        default:
            break;
        }
    }