public void RequestSendChat(ChatRule.CHAT_CHANNEL _eChannel, string _content) { var msg = NewChatMessage(_eChannel, _content); var ht = Johny.HashtablePool.Claim(); ht.Add("name", msg.name); ht.Add("uid", msg.uid); ht.Add("level", msg.level); ht.Add("vip_level", msg.vipLevel); ht.Add("head_icon", msg.icon); ht.Add("head_frame", msg.frame); ht.Add("quality", msg.quality); ht.Add("battle_rating", msg.battleRating); ht.Add("alliance_name", msg.allianceName); ht.Add("month_vip_type", msg.monthVipType); ht.Add("worldId", LoginManager.Instance.LocalUser.WorldId); ht.Add("server_name", LoginManager.Instance.GetDefaultGameWorld(LoginManager.Instance.LocalUser.WorldId).Name); SparxHub.Instance.ChatManager.SendText(msg.channel, msg.text, ht, delegate(string error, object param) { if (!string.IsNullOrEmpty(error)) { EB.Debug.LogError("RequestSendChat:{0}", error); } }); TaskSystem.RequestChatTaskFinish(_eChannel); }
public void RequestJoinChat(ChatRule.CHAT_CHANNEL _eChannel) { var cm = SparxHub.Instance.ChatManager; string channelType = ChatRule.CHANNEL2STR[_eChannel]; if (cm.IsJoined(channelType)) { return; } string channel = FullChannelStringForJoin(_eChannel); cm.Join(channel, null, delegate(string error, object param) { if (!string.IsNullOrEmpty(error)) { EB.Debug.LogWarning("RequestJoinChat:{0}", error); return; } if (_eChannel == ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_PRIVATE) { return; } if (ChatRule.IS_NEED_REQUEST_HISTORY[_eChannel]) { RequestChatHistory(_eChannel); } }); }
private void OnHandleAsyncMessage(EB.Sparx.ChatMessage[] msgs) { ChatRule.CHAT_CHANNEL channelType = GetCurChannelType(); string channel = ChatRule.CHANNEL2STR[channelType]; List <EB.Sparx.ChatMessage> channelMsgs = new List <EB.Sparx.ChatMessage>(); for (int i = 0, len = msgs.Length; i < len; ++i) { var msg = msgs[i]; if (msg.channelType == channel) { channelMsgs.Add(msg); } } if (channelMsgs.Count > 0) { EB.Sparx.ChatMessage[] msgArr = channelMsgs.ToArray(); EB.Sparx.ChatMessage[] curTargetMsgs = System.Array.FindAll(msgArr, m => m.privateUid == ChatController.instance.TargetPrivateUid || m.uid == ChatController.instance.TargetPrivateUid); if (curTargetMsgs.Length > 0) { AddMessages(curTargetMsgs); } } }
public void RequestSendChat(ChatRule.CHAT_CHANNEL _eChannel, AudioClip _audio, int samplePos, long privateUid, string privateName) { var msg = NewChatMessage(_eChannel, string.Empty); var ht = Johny.HashtablePool.Claim(); ht.Add("name", msg.name); ht.Add("uid", msg.uid); ht.Add("level", msg.level); ht.Add("vip_level", msg.vipLevel); ht.Add("head_icon", msg.icon); ht.Add("head_frame", msg.frame); ht.Add("quality", msg.quality); ht.Add("battle_rating", msg.battleRating); ht.Add("alliance_name", msg.allianceName); ht.Add("private_uid", privateUid); ht.Add("private_name", privateName); ht.Add("month_vip_type", msg.monthVipType); ht.Add("worldId", LoginManager.Instance.LocalUser.WorldId); ht.Add("server_name", LoginManager.Instance.GetDefaultGameWorld(LoginManager.Instance.LocalUser.WorldId).Name); SparxHub.Instance.ChatManager.SendAudio(msg.channel, _audio, samplePos, ht, delegate(string error, object param) { if (!string.IsNullOrEmpty(error)) { //eResponseCodeUIExtensions.ShowErrorDialogue(EB.Localizer.GetString("ID_SPARX_NETWORK_ERROR")); EB.Debug.LogError("RequestSendChat:{0}", error); } }); TaskSystem.RequestChatTaskFinish(_eChannel); }
public void OpenChatTalkUI() { ChatRule.CHAT_CHANNEL channelType = ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_WORLD; int userlevel = BalanceResourceUtil.GetUserLevel(); int chatlevel = BalanceResourceUtil.GetChatLevel(); if (userlevel < chatlevel) { var ht = Johny.HashtablePool.Claim(); ht.Add("0", chatlevel); MessageTemplateManager.ShowMessage(902014, ht, null); return; } 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("OpenChatTalkUI: time limited"); return; } talkUI.CustomSetActive(true); StartRecord(); }
public override void Awake() { base.Awake(); var t = mDMono.transform; tab = t.GetComponent <UIToggle>(); newMessage = t.FindEx("NewMessageSprite").gameObject; if (mDMono.FloatParamList != null) { var count = mDMono.FloatParamList.Count; if (count > 0) { sendInterval = mDMono.FloatParamList[0]; } } if (mDMono.StringParamList != null) { var count = mDMono.StringParamList.Count; if (count > 0) { channelType = (ChatRule.CHAT_CHANNEL)Enum.Parse(typeof(ChatRule.CHAT_CHANNEL), mDMono.StringParamList[0]); } } }
private void GetHistoryByChannel(ChatRule.CHAT_CHANNEL channel, LocalDataReadDelegate del) { string folderNameWithChannel = folderName + "/" + channel; if (!GetIsHaveHistory()) { Directory.CreateDirectory(folderName); } if (!Directory.Exists(folderNameWithChannel)) { if (del != null) { del(new List <AllChatHistoryData>()); } return; } string[] fileArr = Directory.GetFiles(folderNameWithChannel); List <string> fileList = fileArr.ToList <string>(); fileList.Sort(delegate(string left, string right) { int length = left.Length; string leftFile = left.Substring(length - 8, 8); string rightFile = right.Substring(length - 8, 8); int sizeLeft, sizeRight; int.TryParse(leftFile, out sizeLeft); int.TryParse(rightFile, out sizeRight); return(sizeLeft - sizeRight); }); if (fileList.Count > maxFileCount) { int count = fileList.Count; for (int i = 0; i < count - maxFileCount; i++) { string path = fileList[0]; fileList.RemoveAt(0); File.Delete(path); } } Queue <string> fileQueue = new Queue <string>(); for (int i = fileList.Count - 1; i >= 0; --i) { fileQueue.Enqueue(fileList[i]); } if (fileQueue.Count > 0) { GetData(fileQueue, del); } }
public void RequestChatHistory(ChatRule.CHAT_CHANNEL _eChannel) { string channel = FullChannelStringForJoin(_eChannel); SparxHub.Instance.ChatManager.History(channel, null, delegate(string error, object param) { if (!string.IsNullOrEmpty(error)) { EB.Debug.LogWarning("RequestChatHistory:{0}", error); } }); }
public EB.Sparx.ChatMessage NewChatMessage(ChatRule.CHAT_CHANNEL _eChannel, string _content) { EB.Sparx.ChatMessage msg = new EB.Sparx.ChatMessage(); msg.channel = FullChannelStringForSend(_eChannel); msg.channelType = ChatRule.CHANNEL2STR[_eChannel]; msg.name = LoginManager.Instance.LocalUser.Name; msg.vipLevel = LoginManager.Instance.LocalUser.Vip; msg.icon = LTMainHudManager.Instance.UserHeadIcon; // LoginManager.Instance.LocalUser.Icon; msg.frame = LTMainHudManager.Instance.UserLeaderHeadFrameStr; msg.uid = LoginManager.Instance.LocalUser.Id.Value; msg.text = _content; msg.monthVipType = 0; bool isSilverVip = LTChargeManager.Instance.IsSilverVIP(); bool isGoldVip = LTChargeManager.Instance.IsGoldVIP(); if (isSilverVip && !isGoldVip) { msg.monthVipType = 1; } else if (!isSilverVip && isGoldVip) { msg.monthVipType = 2; } else if (isSilverVip && isGoldVip) { msg.monthVipType = 3; } string templateId; DataLookupsCache.Instance.SearchDataByID("playstate.MainLand.template_id", out templateId); //Hotfix_LT.Data.HeroStatTemplate charTpl = Hotfix_LT.Data.CharacterTemplateManager.Instance.GetHeroStat(templateId); msg.quality = 0; //charTpl.quality_level; msg.allianceName = AlliancesManager.Instance.Detail.Name; //string teamIdDataId = string.Format("userTeam.current_team"); //string teamId = string.Empty; //if (DataLookupsCache.Instance.SearchDataByID(teamIdDataId, out teamId)) //{ // msg.battleRating = AttributesManager.CalcTeamFightWithEquipedEquipment(teamId); //} msg.battleRating = 0; DataLookupsCache.Instance.SearchDataByID("level", out msg.level); return(msg); }
public void SetHasNewMessage(ChatRule.CHAT_CHANNEL cHAT_CHANNEL, bool isHas = true) { switch (cHAT_CHANNEL) { case ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_SYSTEM: hasNewSysMessage = isHas; break; case ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_WORLD: hasNewWorldMessage = isHas; break; case ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_ALLIANCE: hasNewAllianceMessage = isHas; break; case ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_TEAM: hasNewTeamMessage = isHas; break; case ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_NATION: hasNewNationMessage = isHas; break; } }
private string FullChannelStringForSend(ChatRule.CHAT_CHANNEL _eChannel) { string channel = ""; if (ChatRule.CHANNEL2STR.ContainsKey(_eChannel)) { channel = ChatRule.CHANNEL2STR[_eChannel]; } else { EB.Debug.LogError("ChatRule.CHANNEL2STR not ContainsKey _eChannel ={0}", _eChannel); } if (_eChannel == ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_TEAM) { } else if (_eChannel == ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_WORLD) { int id = LoginManager.Instance.LocalUser.RealmId; if (id <= 0) { id = LoginManager.Instance.LocalUser.WorldId; } channel += string.Format("_{0}", id); } else if (_eChannel == ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_PRIVATE) { channel += string.Format("_{0}", ChatController.instance.TargetPrivateUid); } else if (_eChannel == ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_ALLIANCE) { channel += string.Format("_{0}", AlliancesManager.Instance.Account.AllianceId); } else if (_eChannel == ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_NATION) { channel += string.Format("_{0}", NationManager.Instance.Account.NationName); } else if (_eChannel == ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_ALLIANCEWAR) { channel += string.Format("_{0}_{1}", LTLegionWarManager.Instance.SemiFinalField, LTLegionWarManager.Instance.FieldType); } return(channel); }
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); } }
private void AddMessagesCoroutine(EB.Sparx.ChatMessage[] msgs) { ChatUIMessage[] uiMsgs = new ChatUIMessage[msgs.Length]; for (int i = 0; i < msgs.Length; ++i) { uiMsgs[i] = new ChatUIMessage(msgs[i]); ChatRule.CHAT_CHANNEL channel = ChatRule.STR2CHANNEL[msgs[i].channelType]; uiMsgs[i].Channel = channel; uiMsgs[i].ChannelSpriteName = ChatRule.CHANNEL2ICON.ContainsKey(channel) ? ChatRule.CHANNEL2ICON[channel] : ""; } if (mActive.Count == 0 && mPool.Count == 0) { SetChatItem(); } TabDynaScroll.SetItemData(uiMsgs, MaxHistoryCount); }
/// <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>()); } }); }
public static void RequestChatTaskFinish(ChatRule.CHAT_CHANNEL _eChannel) { if (_eChannel == ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_WORLD) { IDictionary tasks = null; DataLookupsCache.Instance.SearchDataByID <IDictionary>("tasks", out tasks); if (tasks == null) { return; } string task_state = ""; int task_id = 0; var iter = tasks.GetEnumerator(); while (iter.MoveNext()) { IDictionary task = iter.Value as IDictionary; eTaskType type = (eTaskType)System.Enum.Parse(typeof(eTaskType), task["task_type"].ToString()); if (eTaskType.Normal != type && eTaskType.Week != type) { continue; } task_state = EB.Dot.String("state", iter.Value, ""); if (task_state != "running") { continue; } task_id = int.Parse(iter.Key.ToString()); var tpl = Hotfix_LT.Data.TaskTemplateManager.Instance.GetTask(task_id); if (tpl == null || tpl.target_parameter_1 != "4") { continue; } LTHotfixManager.GetManager <TaskManager>().RequestChatTaskFinish(task_id, null); break; } } }
public void RequestLeaveChat(ChatRule.CHAT_CHANNEL _eChannel) { var cm = SparxHub.Instance.ChatManager; string channelType = ChatRule.CHANNEL2STR[_eChannel]; if (!cm.IsJoined(channelType)) { return; } string channel = FullChannelStringForJoin(_eChannel); cm.Leave(channel, null, delegate(string error, object param) { if (!string.IsNullOrEmpty(error)) { EB.Debug.LogWarning("RequestLeaveChat:{0}", error); return; } }); }
private void OnHandleAsyncMessage(EB.Sparx.ChatMessage[] msgs) { ChatRule.CHAT_CHANNEL channelType = ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_PRIVATE; string privateChannel = ChatRule.CHANNEL2STR[channelType]; for (int i = 0, len = msgs.Length; i < len; ++i) { var msg = msgs[i]; if (msg.channelType == privateChannel) { Info.LastMessageTs = msg.ts; Info.NewestSendId = LTChatManager.Instance.GetTargetId(msg.uid, msg.privateUid); ChatHistory.SaveData(msg); if (msg.privateUid == LoginManager.Instance.LocalUserId.Value) { Info.AddUnreadMessageId(Info.NewestSendId); } Messenger.Raise(Hotfix_LT.EventName.FriendMessageEvent, msg.uid); } } }
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); } }
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; }
private int GetSendInterval(ChatRule.CHAT_CHANNEL channel) { return(sendInterval); }
private float GetSendInterval(ChatRule.CHAT_CHANNEL channel) { return(10f); }
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 = ChatRule.CHAT_CHANNEL.CHAT_CHANNEL_WORLD; bool privateChannel = false; 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 (privateChannel) { ChatController.instance.RequestSendChat(channelType, audioRecord, samplePos, ChatController.instance.TargetPrivateUid, ChatController.instance.TargetPrivateName); } else { ChatController.instance.RequestSendChat(channelType, audioRecord, samplePos); } audioRecord = null; microphoneDevice = string.Empty; FusionAudio.ResumeMusic(pausedMusic); pausedMusic = string.Empty; }