Exemplo n.º 1
0
        private void OnReceiveCompleted(Object source, ReceiveCompletedEventArgs asyncResult)
        {
            try
            {
                MessageQueue mq = (MessageQueue)source;

                if (mq != null)
                {
                    try
                    {
                        System.Messaging.Message message = null;
                        try
                        {
                            message = mq.EndReceive(asyncResult.AsyncResult);
                        }
                        catch (Exception ex)
                        {
                            log.Error(ex.Message);
                        }
                        if (message != null)
                        {
                            MessageBean messageBean = message.Body as MessageBean;
                            if (messageBean != null)
                            {
                                if (messageBean.MessageType == MessageTypeEnum.FAULT)
                                {
                                    FaultFrameDecoded tmp = new FaultFrameDecoded();
                                    tmp.Parse(messageBean.Message);
                                    SingletonStatsHistory.GetInstance().AddFault(tmp);
                                    log.InfoFormat("Fault: {0}", tmp.ToString());
                                }
                                else
                                {
                                    StatusFrameDecoded tmp = new StatusFrameDecoded();
                                    tmp.Parse(messageBean.Message);
                                    SingletonStatsHistory.GetInstance().AddStatus(tmp);
                                    log.InfoFormat("Status: {0}", tmp.ToString());
                                }
                            }
                            else
                            {
                                log.Info("Message vino null");
                            }
                        }
                    }
                    finally
                    {
                        if (isRunning)
                        {
                            mq.BeginReceive();
                        }
                    }
                }
                return;
            }
            catch (Exception exc)
            {
                log.Error(exc.Message);
            }
        }
Exemplo n.º 2
0
 public void TransferMessage(MessageBean message)
 {
     if (client != null)
     {
         client.Send(CodeUtil.encode(message));
     }
 }
Exemplo n.º 3
0
        private void PublishMsgInternal(MessageBean m)
        {
            String topic = "";
            int    qos   = 0;

            if (m.type == MessageType.System)
            {
                // topic += "1000/";
                topic = "EnterRoomholoview";
                qos   = 1;
            }
            else if (m.type == MessageType.Group)
            {
                //topic += "2000/";
                topic = m.targetId;
            }
            else
            {
                return;
            }
            //topic += m.targetId;
            if (mqttClient == null)
            {
                return;
            }
            ushort msgid = mqttClient.Publish(topic, m.msg, (byte)qos, false);

            m.msgId = msgid;

            lock (MessageSendingQueueLock)
            {
                messageSendingQueue.Add(m);
            }
        }
Exemplo n.º 4
0
 public static void ActionMessage(IOSession session, int messageid, byte[] buffer)
 {
     log.Debug("message id :" + messageid);
     //验证是否注册消息
     if (MessageHandlers.ContainsKey(messageid))
     {
         //获取消息体
         MessageBean ins = MessageHandlers[messageid];
         //
         object obj = Activator.CreateInstance(ins.Handler);
         //
         if (obj is TcpHandler)
         {
             TcpHandler objhandler = (obj as TcpHandler);
             if (objhandler != null)
             {
                 objhandler.Session = session;
                 //拷贝字节数组
                 byte[] msgbuf = new byte[buffer.Length - 4];
                 for (int i = 0; i < msgbuf.Length; i++)
                 {
                     msgbuf[i] = buffer[i + 4];
                 }
                 //创建消息
                 objhandler.Message = MessageHelper.MessageDeserialize(msgbuf, ins.MsgInstance);
                 //将消息放入执行线程
                 Net.Sz.Framework.SzThreading.ThreadPool.AddTask(ins.ThreadID, objhandler);
                 return;
             }
         }
     }
     log.Error("尚未注册的消息:" + messageid);
 }
Exemplo n.º 5
0
    public static MessageBean formatRankInfoMessagae() {
        MessageBean message = new MessageBean();
        message.operationCode = OperationCode.RANK_INFO;
        message.statusCode = StatusCode.SUCCESS;

        return message;
    }
Exemplo n.º 6
0
 public static MessageBean formatChessDoneMessage(BLOKUSChessDoneInfo chessDoneInfoTemp) {
     MessageBean message = new MessageBean();
     message.operationCode = OperationCode.CHESS_DONE;
     message.statusCode = StatusCode.SUCCESS;
     message.data = ProtobufHelper.SerializerToBytes(chessDoneInfoTemp);
     return message;
 }
Exemplo n.º 7
0
        private void startTask()
        {
            Task sendTask = new Task(async() =>
            {
                while (loop)
                {
                    MessageBean m = null;
                    lock (MessageQueueLock)
                    {
                        if (messageQueue.Count > 0)
                        {
                            m = messageQueue.Dequeue();
                        }
                    }

                    if (m != null)
                    {
                        PublishMsgInternal(m);
                    }
                    else
                    {
                        await Task.Delay(10);
                    }
                }
            });

            sendTask.Start();
        }
Exemplo n.º 8
0
    private void judgeAround(int x, int y)
    {
        bool judgeSuccess = false;
        int  lastX        = x;
        int  lastY        = y;

        if (judgeOverall(x, y))
        {
            judgeSuccess = true;
        }
        else
        {
            foreach (ChessPoint point in getAroundPoints(x, y))
            {
                if (judgeOverall(point.x, point.y))
                {
                    judgeSuccess = true;
                    lastX        = point.x;
                    lastY        = point.y;
                    break;
                }
            }
        }

        if (judgeSuccess)
        {
            MessageBean         message       = MessageFormater.formatChessDoneMessage(lastX, lastY, CurrentSquareName, CurrentSquare.rotationFlag, CurrentSquare.symmetryFlag, CurrentSquare.model);
            BLOKUSChessDoneInfo chessDoneInfo = ProtobufHelper.DederializerFromBytes <BLOKUSChessDoneInfo>(message.data);
            GameObject.Find("BlokusUIController").GetComponent <BlokusUIController>().tryChess(chessDoneInfo);
            //  chessDone(chessDoneInfo);
        }
    }
Exemplo n.º 9
0
 private void chessDone(MessageBean message)
 {
     if (message.statusCode == StatusCode.SUCCESS)
     {
         BLOKUSChessDoneInfo bLOKUSChessDoneInfo = ProtobufHelper.DederializerFromBytes <BLOKUSChessDoneInfo>(message.data);
         GameObject.Find("BlokusController").SendMessage("chessDone", bLOKUSChessDoneInfo);
     }
 }
Exemplo n.º 10
0
 private void chatInGame(MessageBean message)
 {
     if (message.statusCode == StatusCode.SUCCESS)
     {
         BLOKUSChatMessage bLOKUSChatMessage = ProtobufHelper.DederializerFromBytes <BLOKUSChatMessage>(message.data);
         GameObject.Find("BlokusUIController").SendMessage("chatInGame", bLOKUSChatMessage.chatMessage);
     }
 }
Exemplo n.º 11
0
 private void RoomList(MessageBean message)
 {
     if (message.statusCode == StatusCode.SUCCESS)
     {
         BLOKUSRoomList bLOKUSRoomList = ProtobufHelper.DederializerFromBytes <BLOKUSRoomList>(message.data);
         GameObject.Find("UIController").SendMessage("OnRoomListUpdate", bLOKUSRoomList);
     }
 }
Exemplo n.º 12
0
 private void rankInfo(MessageBean message)
 {
     if (message.statusCode == StatusCode.SUCCESS)
     {
         BLOKUSRankInfo bLOKUSRankInfo = ProtobufHelper.DederializerFromBytes <BLOKUSRankInfo>(message.data);
         GameObject.Find("UIController").SendMessage("updateRankInfo", bLOKUSRankInfo);
     }
 }
Exemplo n.º 13
0
 private void profile(MessageBean message)
 {
     if (message.statusCode == StatusCode.SUCCESS)
     {
         BLOKUSProfile bLOKUSProfile = ProtobufHelper.DederializerFromBytes <BLOKUSProfile>(message.data);
         GameObject.Find("UIController").SendMessage("onShowProfile", bLOKUSProfile);
     }
 }
Exemplo n.º 14
0
 private void initPlayerInfoInGame(MessageBean message)
 {
     if (message.statusCode == StatusCode.SUCCESS)
     {
         BLOKUSRoomPlayerList bLOKUSRoomPlayerList = ProtobufHelper.DederializerFromBytes <BLOKUSRoomPlayerList>(message.data);
         GameObject.Find("BlokusUIController").SendMessage("InitBlokusRoomUIInfo", bLOKUSRoomPlayerList);
     }
 }
Exemplo n.º 15
0
    public static List <MessageBean> decode(byte[] data, int totalLength)
    {
        Debug.Log("total length:" + totalLength);

        //for (int i = 0; i < totalLength; i++) {
        //    Debug.Log(i + "  bbbbbbbb:    " + data[i]);
        //}

        List <MessageBean> messages = new List <MessageBean>();
        int index = 0;


        //index point to data next start position
        while (index < totalLength)
        {
            if (tempLength != 0 && tempData != null)
            {
                byte[] temp = new byte[totalLength + tempLength];
                Array.Copy(tempData, 0, temp, 0, tempLength);
                Array.Copy(data, 0, temp, tempLength, totalLength);
                data         = temp;
                totalLength += tempLength;
                tempLength   = 0;
                tempData     = null;
            }


            if (totalLength < 8)
            {
                Debug.Log("head less 8 bytes!");
                tempLength = totalLength;
                tempData   = new byte[totalLength];
                Array.Copy(data, index, tempData, 0, totalLength);
                return(messages);
            }

            int length = readInt(data, 0 + index);

            if (totalLength < length + 8)
            {
                Debug.Log("total length less 8+length!");
                tempLength = totalLength;
                tempData   = new byte[totalLength];
                Array.Copy(data, index, tempData, 0, totalLength);
                return(messages);
            }

            MessageBean message = new MessageBean();
            message.operationCode = readShort(data, 4 + index);
            message.statusCode    = readShort(data, 6 + index);
            message.data          = readBytes(data, 8 + index, length);
            messages.Add(message);
            index       += (8 + length);
            totalLength -= (8 + length);
            Debug.Log("index :" + index);
        }
        return(messages);
    }
Exemplo n.º 16
0
        public static void RegisterMessage(int messageid, long threadid, Type handler, ProtoBuf.IExtensible msgInstance)
        {
            log.Debug("注册消息处理器 id: " + messageid + " type: " + handler.Name + " msgInstance:" + msgInstance.GetType().Name);

            MessageHandlers[messageid] = new MessageBean()
            {
                MsgId = messageid, ThreadID = threadid, Handler = handler, MsgInstance = msgInstance
            };
        }
Exemplo n.º 17
0
    internal static MessageBean formatChatInRoomMessage(string str) {
        MessageBean message = new MessageBean();
        message.operationCode = OperationCode.CHAT_IN_ROOM;
        message.statusCode = StatusCode.SUCCESS;

        BLOKUSChatMessage bLOKUSChatMessage = new BLOKUSChatMessage();
        bLOKUSChatMessage.chatMessage = str;
        message.data = ProtobufHelper.SerializerToBytes(bLOKUSChatMessage);
        return message;
    }
Exemplo n.º 18
0
    public static MessageBean formatJoinRoomMessage(string roomName) {
        MessageBean message = new MessageBean();
        message.operationCode = OperationCode.JOIN_ROOM;
        message.statusCode = StatusCode.SUCCESS;

        BLOKUSRoomName bLOKUSRoomName = new BLOKUSRoomName();
        bLOKUSRoomName.roomName = roomName;
        message.data = ProtobufHelper.SerializerToBytes(bLOKUSRoomName);
        return message;
    }
Exemplo n.º 19
0
    public static MessageBean formatGiveUpMessage(int myColor) {
        MessageBean message = new MessageBean();
        message.operationCode = OperationCode.GIVE_UP;
        message.statusCode = StatusCode.SUCCESS;

        BLOKUSColor bLOKUSColor = new BLOKUSColor();
        bLOKUSColor.color = myColor;
        message.data = ProtobufHelper.SerializerToBytes(bLOKUSColor);
        return message;
    }
Exemplo n.º 20
0
    public static MessageBean formatCheckVersionMessage(string version) {
        MessageBean message = new MessageBean();
        message.operationCode = OperationCode.CHECK_VERSION;
        message.statusCode = StatusCode.SUCCESS;

        BLOKUSVersion bLOKUSVersion = new BLOKUSVersion();
        bLOKUSVersion.version = version;
        message.data = ProtobufHelper.SerializerToBytes(bLOKUSVersion);
        return message;
    }
Exemplo n.º 21
0
    public static MessageBean formatReadyMessage(string account, string roomName) {
        MessageBean message = new MessageBean();
        message.operationCode = OperationCode.READY;
        message.statusCode = StatusCode.SUCCESS;

        //BLOKUSChooseColor bLOKUSChooseColor = new BLOKUSChooseColor();
        //bLOKUSChooseColor.account = account;
        //bLOKUSChooseColor.roomName = roomName;
        //message.data = ProtobufHelper.SerializerToBytes(bLOKUSChooseColor);
        return message;
    }
Exemplo n.º 22
0
    public static MessageBean formatLoginMessage(string accountText, string password) {
        BLOKUSAccount account = new BLOKUSAccount();
        account.account = accountText;
        account.password = password;

        MessageBean message = new MessageBean();
        message.operationCode = OperationCode.LOGIN;
        message.statusCode = StatusCode.SUCCESS;
        message.data = ProtobufHelper.SerializerToBytes(account);
        return message;
    }
Exemplo n.º 23
0
    public static MessageBean formatProfileMessage(string account) {

        MessageBean message = new MessageBean();
        message.operationCode = OperationCode.PROFILE;
        message.statusCode = StatusCode.SUCCESS;

        BLOKUSGameAccount gameAccount = new BLOKUSGameAccount();
        gameAccount.account = account;
        message.data = ProtobufHelper.SerializerToBytes(gameAccount);
        return message;
    }
Exemplo n.º 24
0
    //private void connectSuccess() {
    //    MessageBean message = new MessageBean();
    //    message.operationCode = OperationCode.CONNECT_SUCCESS;
    //    message.statusCode = StatusCode.SUCCESS;

    //    List<MessageBean> list = new List<MessageBean>();
    //    list.Add(message);
    //    MessageQueue.put(list);
    //}

    private void disconnect()
    {
        MessageBean message = new MessageBean();

        message.operationCode = OperationCode.DISCONNECT;
        message.statusCode    = StatusCode.SUCCESS;
        List <MessageBean> list = new List <MessageBean>();

        list.Add(message);
        MessageQueue.put(list);
    }
Exemplo n.º 25
0
 private void register(MessageBean message)
 {
     if (message.statusCode == StatusCode.SUCCESS)
     {
         GameObject.Find("UIController").SendMessage("registerSuccess");
     }
     else
     {
         GameObject.Find("UIController").SendMessage("registerFail");
     }
 }
Exemplo n.º 26
0
 private void giveUp(MessageBean message)
 {
     if (message.statusCode == StatusCode.SUCCESS)
     {
         BLOKUSColor bLOKUSColor = ProtobufHelper.DederializerFromBytes <BLOKUSColor>(message.data);
         LoseParam   loseParam   = new LoseParam {
             color = bLOKUSColor.color, gameEvent = GameEvent.GIVE_UP
         };
         GameObject.Find("BlokusUIController").SendMessage("lose", loseParam);
     }
 }
Exemplo n.º 27
0
 private void startBlokus(MessageBean message)
 {
     if (message.statusCode == StatusCode.SUCCESS)
     {
         GameObject.Find("BlokusRoomUIController").SendMessage("StartBlokus");
     }
     else
     {
         //GameObject.Find("UIController").SendMessage("createRoomFail");
     }
 }
Exemplo n.º 28
0
    public static MessageBean createRoom(string roomName, int gameType) {
        MessageBean message = new MessageBean();
        message.operationCode = OperationCode.CREATE_ROOM;
        message.statusCode = StatusCode.SUCCESS;

        BLOKUSCreateRoom bLOKUSCreateRoom = new BLOKUSCreateRoom();
        bLOKUSCreateRoom.roomName = roomName;
        bLOKUSCreateRoom.gameType = gameType;

        message.data = ProtobufHelper.SerializerToBytes(bLOKUSCreateRoom);
        return message;
    }
Exemplo n.º 29
0
    public static MessageBean chooseColor(string account, string roomName, int color) {
        MessageBean message = new MessageBean();
        message.operationCode = OperationCode.CHOOSE_COLOR;
        message.statusCode = StatusCode.SUCCESS;

        BLOKUSColor bLOKUSColor = new BLOKUSColor();
        //bLOKUSColor.account = account;
        //bLOKUSColor.roomName = roomName;
        bLOKUSColor.color = color;
        message.data = ProtobufHelper.SerializerToBytes(bLOKUSColor);
        return message;
    }
Exemplo n.º 30
0
    internal static MessageBean formatRegisterMessage(string account, string password) {

        MessageBean message = new MessageBean();
        message.operationCode = OperationCode.REGISTER;
        message.statusCode = StatusCode.SUCCESS;

        BLOKUSGameAccount gameAccount = new BLOKUSGameAccount();
        gameAccount.account = account;
        gameAccount.password = password;
        message.data = ProtobufHelper.SerializerToBytes(gameAccount);
        return message;
    }