Ejemplo n.º 1
0
        //-------------[ Get Messages ]---------------------//
        private RetrievedMessage BuildRetrievedMessage(Answer answer)
        {
            RetrievedMessage message = new RetrievedMessage();

            message.cursorId     = answer.Want <long>("id");
            message.messageType  = answer.Want <byte>("mtype");
            message.attrs        = answer.Want <string>("attrs");
            message.modifiedTime = answer.Want <long>("mtime");

            object originalMessage = answer.Want("msg");

            if (!CheckBinaryType(originalMessage))
            {
                message.stringMessage = (string)Convert.ChangeType(originalMessage, TypeCode.String);
            }
            else
            {
                message.binaryMessage = (byte[])originalMessage;
            }

            if (message.messageType >= 40 && message.messageType <= 50)
            {
                RTMClient.BuildFileInfo(message, errorRecorder);
            }

            return(message);
        }
Ejemplo n.º 2
0
        //===========================[ Session Functions ]=========================//
        internal static void RegisterSession(Int64 connectionId, RTMClient client)
        {
            CheckRoutineInit();

            lock (interLocker)
            {
                rtmClients.Add(connectionId, client);
            }
        }
        private RTMMessage BuildRTMMessage(Quest quest, long from, long to, long mid)
        {
            RTMMessage rtmMessage = new RTMMessage
            {
                fromUid      = from,
                toId         = to,
                messageId    = mid,
                messageType  = quest.Want <byte>("mtype"),
                attrs        = quest.Want <string>("attrs"),
                modifiedTime = quest.Want <long>("mtime")
            };

            if (rtmMessage.messageType == (byte)MessageType.Chat)
            {
                rtmMessage.translatedInfo = ProcessChatMessage(quest);
                if (rtmMessage.translatedInfo != null)
                {
                    if (rtmMessage.translatedInfo.targetText.Length > 0)
                    {
                        rtmMessage.stringMessage = rtmMessage.translatedInfo.targetText;
                    }
                    else
                    {
                        rtmMessage.stringMessage = rtmMessage.translatedInfo.sourceText;
                    }
                }
            }
            else if (rtmMessage.messageType == (byte)MessageType.Cmd)
            {
                rtmMessage.stringMessage = quest.Want <string>("msg");
            }
            else if (rtmMessage.messageType >= 40 && rtmMessage.messageType <= 50)
            {
                rtmMessage.stringMessage = quest.Want <string>("msg");
                RTMClient.BuildFileInfo(rtmMessage, errorRecorder);
            }
            else
            {
                MessageInfo messageInfo = BuildMessageInfo(quest);
                if (messageInfo.isBinary)
                {
                    rtmMessage.binaryMessage = messageInfo.binaryData;
                }
                else
                {
                    rtmMessage.stringMessage = messageInfo.message;
                }
            }

            return(rtmMessage);
        }
Ejemplo n.º 4
0
        internal static void CloseSession(Int64 connectionId)
        {
            RTMClient client = null;

            lock (interLocker)
            {
                rtmClients.TryGetValue(connectionId, out client);
            }

            if (client != null)
            {
                client.Close();
            }
        }
Ejemplo n.º 5
0
        /*
         * internal static byte[] ConvertStringToByteArray(string data)
         * {
         *  //-- Please refer com.fpnn.msgpack.MsgPacker::UnpackString(...)
         *
         *  UTF8Encoding utf8Encoding = new UTF8Encoding(false, true);     //-- NO BOM.
         *  return utf8Encoding.GetBytes(data);
         * }
         */

        //===========================[ History Messages Utilities ]=========================//
        private HistoryMessageResult BuildHistoryMessageResult(long toId, Answer answer)
        {
            HistoryMessageResult result = new HistoryMessageResult();

            result.count        = answer.Want <int>("num");
            result.lastCursorId = answer.Want <long>("lastid");
            result.beginMsec    = answer.Want <long>("begin");
            result.endMsec      = answer.Want <long>("end");
            result.messages     = new List <HistoryMessage>();

            List <object> messages = (List <object>)answer.Want("msgs");

            foreach (List <object> items in messages)
            {
                bool deleted = (bool)Convert.ChangeType(items[4], TypeCode.Boolean);
                if (deleted)
                {
                    continue;
                }

                HistoryMessage message = new HistoryMessage();
                message.cursorId    = (long)Convert.ChangeType(items[0], TypeCode.Int64);
                message.fromUid     = (long)Convert.ChangeType(items[1], TypeCode.Int64);
                message.toId        = toId;
                message.messageType = (byte)Convert.ChangeType(items[2], TypeCode.Byte);
                message.messageId   = (long)Convert.ChangeType(items[3], TypeCode.Int64);

                if (!CheckBinaryType(items[5]))
                {
                    message.stringMessage = (string)Convert.ChangeType(items[5], TypeCode.String);
                }
                else
                {
                    message.binaryMessage = (byte[])items[5];
                }

                message.attrs        = (string)Convert.ChangeType(items[6], TypeCode.String);
                message.modifiedTime = (long)Convert.ChangeType(items[7], TypeCode.Int64);

                if (message.messageType >= 40 && message.messageType <= 50)
                {
                    RTMClient.BuildFileInfo(message, errorRecorder);
                }

                result.messages.Add(message);
            }
            result.count = result.messages.Count;
            return(result);
        }
Ejemplo n.º 6
0
        //===========================[ Relogin Functions ]=========================//
        internal static void DelayRelogin(RTMClient client, long triggeredMs)
        {
            CheckRoutineInit();

            lock (interLocker)
            {
                try
                {
                    reloginClients.Add(client, triggeredMs);
                }
                catch (ArgumentException)
                {
                    //-- Do nothing.
                }
            }
        }
Ejemplo n.º 7
0
        internal static ClientStatus GetClientStatus(Int64 connectionId)
        {
            RTMClient client = null;

            lock (interLocker)
            {
                rtmClients.TryGetValue(connectionId, out client);
            }

            if (client != null)
            {
                return(client.Status);
            }
            else
            {
                return(ClientStatus.Closed);
            }
        }
        private MessageInfo BuildMessageInfo(Quest quest)
        {
            MessageInfo info = new MessageInfo();

            object message = quest.Want("msg");

            info.isBinary = RTMClient.CheckBinaryType(message);
            if (info.isBinary)
            {
                info.binaryData = (byte[])message;
            }
            else
            {
                info.message = (string)message;
            }

            return(info);
        }
        public Answer PushBroadcastMessage(Int64 connectionId, string endpoint, Quest quest)
        {
            AdvanceAnswer.SendAnswer(new Answer(quest));

            if (questProcessor == null)
            {
                return(null);
            }

            long from = quest.Want <long>("from");
            long mid  = quest.Want <long>("mid");

            if (duplicatedFilter.CheckBroadcastMessage(from, mid) == false)
            {
                return(null);
            }

            byte   mtype = quest.Want <byte>("mtype");
            string attrs = quest.Want <string>("attrs");
            long   mtime = quest.Want <long>("mtime");

            if (mtype == RTMClient.MessageMType_Chat)
            {
                TranslatedMessage tm = ProcessChatMessage(quest, out string orginialMessage);
                if (tm == null)
                {
                    questProcessor.PushBroadcastChat(from, mid, orginialMessage, attrs, mtime);
                }
                else
                {
                    questProcessor.PushBroadcastChat(from, mid, tm, attrs, mtime);
                }

                return(null);
            }

            MessageInfo messageInfo = BuildMessageInfo(quest);

            if (mtype == RTMClient.MessageMType_Audio)
            {
                byte[] audioData = messageInfo.binaryData;

                if (!messageInfo.isBinary)
                {
                    audioData = RTMClient.ConvertStringToByteArray(messageInfo.message);
                }

                questProcessor.PushBroadcastAudio(from, mid, audioData, attrs, mtime);
                return(null);
            }

            if (mtype == RTMClient.MessageMType_Cmd)
            {
                questProcessor.PushBroadcastCmd(from, mid, messageInfo.message, attrs, mtime);
            }
            else if (mtype >= 40 && mtype <= 50)
            {
                questProcessor.PushBroadcastFile(from, mtype, mid, messageInfo.message, attrs, mtime);
            }
            else
            {
                if (messageInfo.isBinary)
                {
                    questProcessor.PushBroadcastMessage(from, mtype, mid, messageInfo.binaryData, attrs, mtime);
                }
                else
                {
                    questProcessor.PushBroadcastMessage(from, mtype, mid, messageInfo.message, attrs, mtime);
                }
            }

            return(null);
        }