Example #1
0
        private object makeJson(EB.Sparx.ChatMessage msg)
        {
            Hashtable json       = Johny.HashtablePool.Claim();
            Hashtable attributes = Johny.HashtablePool.Claim();

            attributes.Add("vip_level", msg.vipLevel);
            attributes.Add("quality", msg.quality);
            attributes.Add("is_audio", msg.isAudio);
            attributes.Add("name", msg.name);
            attributes.Add("head_icon", msg.icon);
            attributes.Add("head_frame", msg.frame);
            attributes.Add("battle_rating", msg.battleRating);
            attributes.Add("uid", msg.uid);
            attributes.Add("level", msg.level);
            attributes.Add("channel_type", msg.channelType);
            attributes.Add("audio", msg.audioClip);
            attributes.Add("alliance_name", msg.allianceName);
            json.Add("uid", msg.uid);
            json.Add("attributes", attributes);
            json.Add("name", msg.name);
            json.Add("ts", msg.ts);
            json.Add("lower", msg.lower);
            json.Add("channel", msg.channel);
            json.Add("locale", msg.ip);
            json.Add("filtered", msg.text);
            json.Add("id", msg.id);
            json.Add("text", msg.text);
            json.Add("lang", msg.language);
            msg.json = json;
            return(json);
        }
Example #2
0
        static StackObject *Ctor_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *__ret = ILIntepreter.Minus(__esp, 0);

            var result_of_this_method = new EB.Sparx.ChatMessage();

            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Example #3
0
        private void AddMessage(EB.Sparx.ChatMessage msg)
        {
            ChatItem item = Use();

            ChatUIMessage uimsg   = new ChatUIMessage(msg);
            var           channel = ChatRule.STR2CHANNEL[msg.channelType];

            uimsg.Channel           = channel;
            uimsg.ChannelSpriteName = ChatRule.CHANNEL2ICON.ContainsKey(channel) ? ChatRule.CHANNEL2ICON[channel] : "";
            item.SetItemData(uimsg);
        }
Example #4
0
 public void SaveData(EB.Sparx.ChatMessage msg)
 {
     if (AddChatHistory(msg))
     {
         ChatHistoryData hd = new ChatHistoryData();
         hd.id      = LTChatManager.Instance.GetTargetId(msg.uid, msg.privateUid);
         hd.content = EB.JSON.Stringify(msg.json);
         hd.ts      = msg.ts;
         SaveData(hd);
     }
 }
Example #5
0
        public void OnSendBtnClick()
        {
            FusionAudio.PostEvent("UI/General/ButtonClick");
            bool   privateChannel = true;
            string inputStr       = inputLabel.value.Trim();
            string privateTarget  = string.Empty;

            if (!ChatController.instance.CanSend(inputStr))
            {
                EB.Debug.LogWarning("OnSendBtnClick: can't send");
                return;
            }

            float leftTime = SparxHub.Instance.ChatManager.GetLastSendTime("private") +
                             GetSendInterval(GetCurChannelType()) - Time.realtimeSinceStartup;

            if (leftTime > 0)
            {
                var ht = Johny.HashtablePool.Claim();
                ht.Add("0", Mathf.CeilToInt(leftTime).ToString());
                MessageTemplateManager.ShowMessage(902100, ht, null);
                EB.Debug.LogWarning("OnSendBtnClick: time limited");
                return;
            }

            inputStr = EB.ProfanityFilter.Filter(inputLabel.label.text);
            // 如果在别人的黑名单里面或者别人在自己的黑名单里面,该消息只做本地显示,不向服务器上发
            if (FriendManager.Instance.CheckBeblack(ChatController.instance.TargetPrivateUid) ||
                FriendManager.Instance.CheckBlacklist(ChatController.instance.TargetPrivateUid))
            {
                EB.Sparx.ChatMessage msg =
                    ChatController.instance.NewChatMessage(ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_PRIVATE, inputStr);
                msg.privateUid  = ChatController.instance.TargetPrivateUid;
                msg.privateName = ChatController.instance.TargetPrivateName;
                SparxHub.Instance.ChatManager.OnMessages(new EB.Sparx.ChatMessage[] { msg });
                inputLabel.value = string.Empty;
            }
            else if (privateChannel)
            {
                ChatController.instance.RequestSendChat(ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_PRIVATE, inputStr,
                                                        ChatController.instance.TargetPrivateUid, ChatController.instance.TargetPrivateName);
                inputLabel.value = privateTarget;

                LaunchChat();
            }
            else
            {
                EB.Debug.LogError("happen error! channel not is private");
            }

            mInvalid = true;
        }
Example #6
0
        static StackObject *Add_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 2);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            EB.Sparx.ChatMessage @item = (EB.Sparx.ChatMessage) typeof(EB.Sparx.ChatMessage).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 2);
            System.Collections.Generic.List <EB.Sparx.ChatMessage> instance_of_this_method = (System.Collections.Generic.List <EB.Sparx.ChatMessage>) typeof(System.Collections.Generic.List <EB.Sparx.ChatMessage>).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            instance_of_this_method.Add(@item);

            return(__ret);
        }
Example #7
0
 public bool AddChatHistory(EB.Sparx.ChatMessage msg, ChatRule.CHAT_CHANNEL channel)
 {
     if (!AllChatHistoryDic.ContainsKey(channel))
     {
         List <EB.Sparx.ChatMessage> msgList = new List <EB.Sparx.ChatMessage>();
         msgList.Add(msg);
         AllChatHistoryDic.Add(channel, msgList);
         return(true);
     }
     else
     {
         if (AllChatHistoryDic[channel].Count >= ChatHudController.MaxHistoryCount)
         {
             //EB.Debug.Log("remove msg channel=" + channel);
             AllChatHistoryDic[channel].RemoveAt(0);
         }
         AllChatHistoryDic[channel].Add(msg);
         return(true);
     }
 }
Example #8
0
        /// <summary>
        /// 通过好友id找到聊天记录,一次获取七天的聊天信息
        /// </summary>
        /// <param name="id"></param>
        public void GetChatHistory(long uid, Action <List <EB.Sparx.ChatMessage> > del)
        {
            if (ChatHistoryDic.ContainsKey(uid))
            {
                del(ChatHistoryDic[uid]);
                return;
            }

            //List<EB.Sparx.ChatMessage> msgs = new List<EB.Sparx.ChatMessage>();
            GetHistoryByID(uid, delegate(List <ChatHistoryData> list)
            {
                if (list == null)
                {
                    del(new List <EB.Sparx.ChatMessage>());
                    return;
                }

                for (int i = 0; i < list.Count; i++)
                {
                    if (!string.IsNullOrEmpty(list[i].content) && list[i].content != "null")
                    {
                        EB.Sparx.ChatMessage msg = EB.Sparx.ChatMessage.Parse(EB.JSON.Parse(list[i].content));
                        AddChatHistory(msg);
                    }
                    //msgs.Add(msg);
                }

                if (ChatHistoryDic.ContainsKey(uid))
                {
                    ChatHistoryDic[uid].Sort(delegate(EB.Sparx.ChatMessage x, EB.Sparx.ChatMessage y)
                    {
                        return((int)(x.ts - y.ts));
                    });
                    del(ChatHistoryDic[uid]);
                }
                else
                {
                    del(new List <EB.Sparx.ChatMessage>());
                }
            });
        }
Example #9
0
        /// <summary>
        /// 通过好友频道找到聊天记录,一次获取七天的聊天信息
        /// </summary>
        /// <param name="id"></param>
        public void GetAllChatHistory(ChatRule.CHAT_CHANNEL channel, Action <List <EB.Sparx.ChatMessage> > del)
        {
            if (AllChatHistoryDic.ContainsKey(channel))
            {
                del(AllChatHistoryDic[channel]);
                return;
            }

            GetHistoryByChannel(channel, delegate(List <AllChatHistoryData> list)
            {
                if (list == null)
                {
                    del(new List <EB.Sparx.ChatMessage>());
                    return;
                }

                for (int i = 0; i < list.Count; i++)
                {
                    object json = EB.JSON.Parse(list[i].content);
                    if (json != null)
                    {
                        EB.Sparx.ChatMessage msg = EB.Sparx.ChatMessage.Parse(json);
                        AddChatHistory(msg, channel);
                    }
                }

                if (AllChatHistoryDic.ContainsKey(channel))
                {
                    AllChatHistoryDic[channel].Sort(delegate(EB.Sparx.ChatMessage x, EB.Sparx.ChatMessage y)
                    {
                        return((int)(x.ts - y.ts));
                    });
                    del(AllChatHistoryDic[channel]);
                }
                else
                {
                    del(new List <EB.Sparx.ChatMessage>());
                }
            });
        }
Example #10
0
        public bool AddChatHistory(EB.Sparx.ChatMessage msg)
        {
            long targetId = LTChatManager.Instance.GetTargetId(msg.uid, msg.privateUid);

            if (!ChatHistoryDic.ContainsKey(targetId))
            {
                List <EB.Sparx.ChatMessage> msgList = new List <EB.Sparx.ChatMessage>();
                msgList.Add(msg);
                ChatHistoryDic.Add(targetId, msgList);
                return(true);
            }
            else
            {
                if (ChatHistoryDic[targetId].Count > 50)
                {
                    EB.Debug.Log("remove msg targetId={0}", targetId);
                    ChatHistoryDic[targetId].RemoveAt(0);
                }
                ChatHistoryDic[targetId].Add(msg);
                return(true);
            }
        }
Example #11
0
 public void SaveData(EB.Sparx.ChatMessage msg, ChatRule.CHAT_CHANNEL channel)
 {
     if (AddChatHistory(msg, channel))
     {
         //世界聊天没必要保存到本地
         if (channel == ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_WORLD)
         {
             return;
         }
         AllChatHistoryData hd = new AllChatHistoryData();
         hd.channel = channel;
         if (msg.json != null)
         {
             hd.content = EB.JSON.Stringify(msg.json);
         }
         else
         {
             hd.content = EB.JSON.Stringify(makeJson(msg));
         }
         hd.ts = msg.ts;
         SaveData(hd);
     }
 }
Example #12
0
        private void EndRecord()
        {
            if (Microphone.devices.Length <= 0)
            {
                EB.Debug.LogWarning("EndRecord: their is no microphone devices");
                return;
            }

            if (audioRecord == null)
            {
                EB.Debug.LogWarning("EndRecord: audio clip is null");
                return;
            }

            if (string.IsNullOrEmpty(microphoneDevice))
            {
                EB.Debug.LogWarning("EndRecord: invalid microphone device");
                return;
            }

            int samplePos = audioRecord.samples;

            if (Microphone.IsRecording(microphoneDevice))
            {
                samplePos = Microphone.GetPosition(microphoneDevice);
                Microphone.End(microphoneDevice);
            }

            int limit = Mathf.FloorToInt(AudioWraper.MINLENGTH * AudioWraper.FREQUENCY);

            if (samplePos < limit)
            {
                MessageTemplateManager.ShowMessage(902102);
                EB.Debug.LogWarning("EndRecord: too short, {0} < {1}", samplePos, limit);
                audioRecord      = null;
                microphoneDevice = string.Empty;
                FusionAudio.ResumeMusic(pausedMusic);
                pausedMusic = string.Empty;
                return;
            }

            ChatRule.CHAT_CHANNEL channelType = GetCurChannelType();
            if (channelType == ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_NONE)
            {
                EB.Debug.LogWarning("EndRecord: invalid channel");
                audioRecord      = null;
                microphoneDevice = string.Empty;
                FusionAudio.ResumeMusic(pausedMusic);
                pausedMusic = string.Empty;
                return;
            }

            bool privateChannel = true;

            string channelStr = ChatRule.CHANNEL2STR[channelType];
            float  leftTime   = SparxHub.Instance.ChatManager.GetLastSendTime(channelStr) + GetSendInterval(channelType) -
                                Time.realtimeSinceStartup;

            if (leftTime > 0)
            {
                var ht = Johny.HashtablePool.Claim();
                ht.Add("0", Mathf.CeilToInt(leftTime).ToString());
                MessageTemplateManager.ShowMessage(902100, ht, null);
                EB.Debug.LogWarning("EndRecord: time limited");
                audioRecord      = null;
                microphoneDevice = string.Empty;
                FusionAudio.ResumeMusic(pausedMusic);
                pausedMusic = string.Empty;
                return;
            }

            // 如果在别人的黑名单里面或者别人在自己的黑名单里面,该消息只做本地显示,不向服务器上发
            if (FriendManager.Instance.CheckBeblack(ChatController.instance.TargetPrivateUid) ||
                FriendManager.Instance.CheckBlacklist(ChatController.instance.TargetPrivateUid))
            {
                EB.Sparx.ChatMessage msg =
                    ChatController.instance.NewChatMessage(ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_PRIVATE, string.Empty);
                msg.privateUid  = ChatController.instance.TargetPrivateUid;
                msg.privateName = ChatController.instance.TargetPrivateName;
                msg.isAudio     = true;
                msg.audioClip   = audioRecord;
                SparxHub.Instance.ChatManager.OnMessages(new EB.Sparx.ChatMessage[] { msg });
            }
            else if (privateChannel)
            {
                ChatController.instance.RequestSendChat(channelType, audioRecord, samplePos,
                                                        ChatController.instance.TargetPrivateUid, ChatController.instance.TargetPrivateName);

                LaunchChat();
            }
            else
            {
                ChatController.instance.RequestSendChat(channelType, audioRecord, samplePos);
            }

            audioRecord      = null;
            microphoneDevice = string.Empty;
            FusionAudio.ResumeMusic(pausedMusic);
            pausedMusic = string.Empty;
            mInvalid    = true;
        }