//MQTT连接成功 private void OnMqttConnected() { MqttConnected = true; try { //订阅 _mqttClient?.SubscribeAsync(new TopicFilter() { Topic = SubscribeTopic, QualityOfServiceLevel = MqttQualityOfServiceLevel.ExactlyOnce }); } catch (Exception e) { OnErrorMessage?.Invoke(e.Message); } //发送心跳数据 PublishHeartbeat(); //创建守护定时器,DaemonInterval秒后执行 _daemonTimer = new Timer(DaemonFunc, null, TimeSpan.FromSeconds(DaemonInterval), Timeout.InfiniteTimeSpan); _connAction?.Invoke(true); }
private void OnPublishMessage(string message) { try { var msg = new MqttApplicationMessage() { Topic = PublishTopic, Payload = MessageEncoding.GetBytes(message), QualityOfServiceLevel = MqttQualityOfServiceLevel.ExactlyOnce, Retain = false }; _mqttClient?.PublishAsync(msg); } catch (Exception e) { OnErrorMessage?.Invoke(e.Message); } }
/// <summary> /// Inspects the log level of the event data and triggers the corresponding event if there is a listener. /// </summary> /// <param name="e">The <see cref="LogEventArgs"/> instance containing the event data.</param> internal static void RaiseException(LogEventArgs e) { if (MuteMessages) { return; } if (e != null) { switch (e.LogLevel) { case LogLevelType.Verbose: OnVerboseMessage?.Invoke(e); break; case LogLevelType.Debug: OnDebugMessage?.Invoke(e); break; case LogLevelType.Info: OnInfoMessage?.Invoke(e); break; case LogLevelType.Warn: OnWarnMessage?.Invoke(e); break; case LogLevelType.Error: OnErrorMessage?.Invoke(e); break; case LogLevelType.Fatal: OnFatalMessage?.Invoke(e); break; } } }
/// <summary> /// 异步连接MQTT /// </summary> /// <returns></returns> private async Task ConnectAsync() { // create client instance _mqttClient = new MqttFactory().CreateMqttClient() as MqttClient; if (_mqttClient == null) { return; } _mqttClient.ApplicationMessageReceivedHandler = new MqttApplicationMessageReceivedHandlerDelegate(e => { OnMessageReceived(e); }); _mqttClient.ConnectedHandler = new MqttClientConnectedHandlerDelegate(e => { OnMqttConnected(); }); _mqttClient.DisconnectedHandler = new MqttClientDisconnectedHandlerDelegate(e => { OnMqttDisconnected(); }); try { var willMsg = new MqttApplicationMessage() { Topic = PublishTopic, Payload = MessageEncoding.GetBytes(WillMessage ?? string.Empty), QualityOfServiceLevel = MqttQualityOfServiceLevel.ExactlyOnce, Retain = false }; var options = new MqttClientOptionsBuilder() .WithTcpServer(BrokerAddress, BrokerPort) .WithCredentials(BrokerUserName, BrokerPassword) .WithClientId(_clientId) .WithWillMessage(willMsg) .WithCleanSession() .Build(); await _mqttClient.ConnectAsync(options); } catch (Exception e) { MqttConnected = false; OnErrorMessage?.Invoke(e.Message); } }
public void Stop() { //移除守护定时器 _daemonTimer?.Dispose(); _daemonTimer = null; _publishHelper.Stop(); _publishHelper.OnPublishMessage -= OnPublishMessage; try { //退出时,断开连接 _mqttClient?.DisconnectAsync(); _mqttClient?.Dispose(); _mqttClient = null; } catch (Exception e) { OnErrorMessage?.Invoke(e.Message); } }
private void PublishHeartbeat() { if (!EnableHeartBeat) { return; } try { var msg = new MqttApplicationMessage() { Topic = HeartbeatTopic, Payload = new byte[] { 0 }, QualityOfServiceLevel = MqttQualityOfServiceLevel.AtMostOnce, Retain = false }; _mqttClient?.PublishAsync(msg); } catch (Exception e) { OnErrorMessage?.Invoke(e.Message); } }
private static void ErrorWrite(string v) { Debug.WriteLine(v); OnErrorMessage?.Invoke(null, v); }
private void OnMqttErrorMessage(string message) { OnErrorMessage?.Invoke(message); }
/// <summary> /// Emensagem de erro /// </summary> /// <param name="ex">erro</param> protected virtual void OnErrorMessageHadle(Exception ex) { //Invoke event OnErrorMessage?.Invoke(ex); }
private void AddDefaultHandlers() { // Meta _Handlers["!!!"] += (_, c) => { var err = c as Server_Meta_Failed; Debug.WriteLine("Invalid command recieved: {0} - {2}\n{1}", err.CMDToken, err.Data, err.Exception); }; _Handlers["???"] += (_, c) => { var err = c as Server_Meta_Unknown; Debug.WriteLine("Unknown command recieved: {0}\n{1}", err.CMDToken, err.Data); }; // Connection related _Handlers["CON"] += (_, c) => { var con = c as Server_CON_ChatConnectedUsers; _Variables.SetVariable("__connected", con.ConnectedUsers); }; _Handlers["ERR"] += (_, c) => { var err = c as Server_ERR_ChatError; OnErrorMessage?.Invoke(this, new CommandEventArgs(err)); }; _Handlers["HLO"] += (_, c) => { var hlo = c as Server_HLO_ChatHello; // TODO: Properly report server hello. Debug.WriteLine($"Hello: {hlo.Message}"); }; _Handlers["IDN"] += (_, c) => { var idn = c as Server_IDN_ChatIdentify; _Identified = true; Debug.WriteLine($"Identified as {idn.Character}"); // TODO: Handle identifying properly OnIdentified?.Invoke(this, EventArgs.Empty); }; _Handlers["PIN"] += (_, c) => { if (AutoPing) { SendCommand(new Client_PIN_ChatPing()); } }; _Handlers["SYS"] += (_, c) => { var sys = c as Server_SYS_ChatSYSMessage; if (!string.IsNullOrEmpty(sys.Channel)) { var chan = GetChannel(sys.Channel); chan.PushCommand(sys); OnChannelSYSMessage?.Invoke(this, new ChannelEntryEventArgs <string>(chan, sys.Message, sys)); } else { OnSYSMessage?.Invoke(this, new CommandEventArgs(sys)); } }; _Handlers["UPT"] += (_, c) => { var upt = c as Server_UPT_ChatUptime; _Variables.SetVariable("__boot_time", upt.StartTime); _Variables.SetVariable("__users", upt.CurrentUsers); _Variables.SetVariable("__channels", upt.Channels); _Variables.SetVariable("__connections", upt.AcceptedConnections); _Variables.SetVariable("__peak", upt.PeakUsers); foreach (var name in new[] { "__boot_time", "__users", "__channels", "__connections", "__peak" }) { OnServerVariableUpdate?.Invoke(this, new ServerVariableEventArgs(name, _Variables[name])); } }; _Handlers["VAR"] += (_, c) => { var var = c as Server_VAR_ChatVariable; _Variables.SetVariable(var.Name, var.Value); OnServerVariableUpdate?.Invoke(this, new ServerVariableEventArgs(var.Name, var.Value)); }; // Chat OP related _Handlers["ADL"] += (_, c) => { var adl = c as Server_ADL_ChatListOPs; _ChatOPs.Clear(); _ChatOPs.AddRange(adl.OPs.Select(n => GetCharacter(n))); Debug.WriteLine($"Recieved OP list with {adl.OPs.Length} entries."); }; _Handlers["AOP"] += (_, c) => { var aop = c as Server_AOP_ChatAddOP; var character = GetCharacter(aop.Character); _ChatOPs.Add(character); OnOPAdded?.Invoke(this, new CharacterEntryEventArgs(character, aop)); }; _Handlers["DOP"] += (_, c) => { var dop = c as Server_DOP_ChatRemoveOP; var character = GetCharacter(dop.Character); _ChatOPs.Remove(character); OnOPRemoved?.Invoke(this, new CharacterEntryEventArgs(character, dop)); }; // Channel list related _Handlers["CHA"] += (_, c) => { var cha = c as Server_CHA_ChatListPublicChannels; // TODO: Do this properly, sync only changes _OfficialChannels.Clear(); _OfficialChannels.AddRange(cha.Channels.Select(C => new KnownChannel { UserCount = C.Count, ID = C.Name, Title = C.Name, Mode = C.Mode })); OnOfficialListUpdate?.Invoke(this, EventArgs.Empty); }; _Handlers["ORS"] += (_, c) => { var ors = c as Server_ORS_ChatListPrivateChannels; // TODO: Do this properly, sync only changes _PrivateChannels.Clear(); _PrivateChannels.AddRange(ors.Channels.Select(C => new KnownChannel { UserCount = C.Count, ID = C.ID, Title = C.Title })); OnPrivateListUpdate?.Invoke(this, EventArgs.Empty); }; // Character list related _Handlers["FRL"] += (_, c) => { var frl = c as Server_FRL_ChatListFriends; _Friends.AddRange(frl.FriendsAndBookmarks.Select(ch => GetOrCreateCharacter(ch))); _Bookmarks.AddRange(frl.FriendsAndBookmarks.Select(ch => GetOrCreateCharacter(ch))); Debug.WriteLine($"Recieved {frl.FriendsAndBookmarks.Length} friends and bookmarks"); OnFriendsListUpdate?.Invoke(this, EventArgs.Empty); }; _Handlers["IGN"] += (_, c) => { var ign = c as Server_IGN_ChatListIgnores; // TODO: Handle ignores switch (ign.Action) { case Server_IGN_ChatListIgnores.IgnoreAction.Init: Debug.WriteLine($"Initial ignore list received. {ign.Characters.Length} entries."); break; case Server_IGN_ChatListIgnores.IgnoreAction.Add: Debug.WriteLine($"TODO: Add {ign.Character} to ignore list."); break; case Server_IGN_ChatListIgnores.IgnoreAction.Delete: Debug.WriteLine($"TODO: Remove {ign.Character} from ignore list."); break; } // TODO OnIgnoreListUpdate?.Invoke(this, EventArgs.Empty); }; _Handlers["LIS"] += (_, c) => { var lis = c as Server_LIS_ChatListUsers; foreach (var character in lis.CharacterData) { var charObj = GetOrCreateCharacter(character[0]); charObj.Gender = JsonEnumConverter.Convert <Genders>(character[1]); charObj.Status = JsonEnumConverter.Convert <CharacterStatus>(character[2]); charObj.StatusMessage = character[3]; } }; // Channel entry related _Handlers["JCH"] += (_, c) => { var jch = c as Server_JCH_ChannelJoin; var chan = GetChannel(jch.Channel); if (jch.Character.Identity != LocalCharacter.Name) { OnChannelUserJoin?.Invoke(this, new ChannelUserEntryEventArgs(chan, GetCharacter(jch.Character.Identity), jch)); } }; _Handlers["LCH"] += (_, c) => { var lch = c as Server_LCH_ChannelLeave; var chan = GetChannel(lch.Channel); if (lch.Character == LocalCharacter.Name) { OnChannelLeave?.Invoke(this, new ChannelEntryEventArgs(chan, lch)); } else { OnChannelUserLeave?.Invoke(this, new ChannelUserEntryEventArgs(chan, GetCharacter(lch.Character), lch)); } }; _Handlers["ICH"] += (_, c) => { var ich = c as Server_ICH_ChannelInitialData; var chan = GetOrCreateChannel(ich.Channel); OnChannelJoin?.Invoke(this, new ChannelEntryEventArgs(chan, ich)); }; // Channel admin related _Handlers["CKU"] += (_, c) => { var cku = c as Server_CKU_ChannelKickCharacter; var chan = GetChannel(cku.Channel); OnChannelUserKicked?.Invoke(this, new ChannelAdminActionEventArgs(chan, GetCharacter(cku.Character), GetCharacter(cku.OP), cku)); }; _Handlers["CBU"] += (_, c) => { var cbu = c as Server_CBU_ChannelBanCharacter; var chan = GetChannel(cbu.Channel); OnChannelUserBanned?.Invoke(this, new ChannelAdminActionEventArgs(chan, GetCharacter(cbu.Character), GetCharacter(cbu.OP), cbu)); }; _Handlers["CUB"] += (_, c) => { var cub = c as Server_CUB_ChannelUnbanCharacter; var chan = GetChannel(cub.Channel); OnChannelUserUnbanned?.Invoke(this, new ChannelAdminActionEventArgs(chan, GetCharacter(cub.Character), GetCharacter(cub.OP), cub)); }; _Handlers["CTU"] += (_, c) => { var ctu = c as Server_CTU_ChannelTimeoutCharacter; var chan = GetChannel(ctu.Channel); OnChannelUserTimedout?.Invoke(this, new ChannelAdminActionEventArgs(chan, GetCharacter(ctu.Character), GetCharacter(ctu.OP), ctu)); }; // Channel status related _Handlers["CDS"] += (_, c) => { var cds = c as Server_CDS_ChannelChangeDescription; var chan = GetChannel(cds.Channel); OnChannelDescriptionChange?.Invoke(this, new ChannelEntryEventArgs <string>(chan, cds.Description, cds)); }; _Handlers["RMO"] += (_, c) => { var rmo = c as Server_RMO_ChannelSetMode; var chan = GetChannel(rmo.Channel); OnChannelModeChange?.Invoke(this, new ChannelEntryEventArgs <ChannelMode>(chan, rmo.Mode, rmo)); }; _Handlers["CSO"] += (_, c) => { var cso = c as Server_CSO_ChannelSetOwner; var chan = GetChannel(cso.Channel); OnChannelOwnerChange?.Invoke(this, new ChannelEntryEventArgs <Character>(chan, GetCharacter(cso.Character), cso)); }; _Handlers["RST"] += (_, c) => { var rst = c as Server_RST_ChannelSetStatus; var chan = GetChannel(rst.Channel); OnChannelStatusChange?.Invoke(this, new ChannelEntryEventArgs <ChannelStatus>(chan, rst.Status, rst)); }; // Channel admin related _Handlers["COA"] += (_, c) => { var coa = c as Server_COA_ChannelMakeOP; var chan = GetChannel(coa.Channel); OnChannelOPAdded?.Invoke(this, new ChannelUserEntryEventArgs(chan, GetCharacter(coa.Character), coa)); }; _Handlers["COR"] += (_, c) => { var cor = c as Server_COR_ChannelRemoveOP; var chan = GetChannel(cor.Channel); chan.PushCommand(cor); OnChannelOPRemoved?.Invoke(this, new ChannelUserEntryEventArgs(chan, GetCharacter(cor.Character), cor)); }; // Channel message related _Handlers["MSG"] += (_, c) => { var msg = c as Server_MSG_ChannelChatMessage; var chan = GetChannel(msg.Channel); OnChannelChatMessage?.Invoke(this, new ChannelUserMessageEventArgs(chan, GetCharacter(msg.Character), msg.Message, msg)); }; _Handlers["LRP"] += (_, c) => { var lrp = c as Server_LRP_ChannelLFRPMessage; var chan = GetChannel(lrp.Channel); OnChannelLFRPMessage?.Invoke(this, new ChannelUserMessageEventArgs(chan, GetCharacter(lrp.Character), lrp.AD, lrp)); }; _Handlers["RLL"] += (_, c) => { var rll = c as Server_RLL_ChannelRollMessage; var chan = GetChannel(rll.Channel); OnChannelRollMessage?.Invoke(this, new ChannelUserMessageEventArgs(chan, GetCharacter(rll.Character), rll.Message, rll)); }; // Character entry related _Handlers["FLN"] += (_, c) => { var fln = c as Server_FLN_CharacterOffline; var character = GetCharacter(fln.Character); if (character == null) { character = new Character(this, new libflist.Character(FListClient, fln.Character)); OnCharacterOffline?.Invoke(this, new CharacterEntryEventArgs(character, fln)); return; } OnCharacterOffline?.Invoke(this, new CharacterEntryEventArgs(character, fln)); character.Status = CharacterStatus.Offline; foreach (var chan in _Channels.Where(C => C.Characters.Contains(character))) { chan.PushCommand(new Server_LCH_ChannelLeave { Channel = chan.ID, Character = character.Name }); } }; _Handlers["NLN"] += (_, c) => { var nln = c as Server_NLN_CharacterOnline; var character = GetOrCreateCharacter(nln.CharacterName); character.Gender = nln.Gender; character.Status = nln.Status; OnCharacterOnline?.Invoke(this, new CharacterEntryEventArgs(character, nln)); }; _Handlers["PRI"] += (_, c) => { var pri = c as Server_PRI_CharacterChatMessage; var character = GetCharacter(pri.Character); character.IsTyping = TypingStatus.Clear; OnCharacterChatMessage?.Invoke(this, new CharacterMessageEventArgs(character, pri.Message, pri)); }; _Handlers["STA"] += (_, c) => { var sta = c as Server_STA_CharacterStatus; var character = GetCharacter(sta.Character); character.Status = sta.Status; character.StatusMessage = sta.Message; OnCharacterStatusChange?.Invoke(this, new CharacterEntryEventArgs <CharacterStatus>(character, sta.Status, sta)); }; _Handlers["TPN"] += (_, c) => { var tpn = c as Server_TPN_CharacterTypingStatus; var character = GetCharacter(tpn.Character); character.IsTyping = tpn.Status; OnCharacterTypingChange?.Invoke(this, new CharacterEntryEventArgs <TypingStatus>(character, tpn.Status, tpn)); }; /* * // Character admin events * public event EventHandler<AdminActionEventArgs> OnCharacterKicked; * public event EventHandler<AdminActionEventArgs> OnCharacterBanned; * public event EventHandler<AdminActionEventArgs> OnCharacterUnbanned; * public event EventHandler<AdminActionEventArgs> OnCharacterTimedout; */ }
private void _evaluteEvent(string parEvent, object[] parArgs) { if (OnEvent != null) { var args = new OnEventArgs(parEvent, parArgs); OnEvent.Invoke(this, args); } //Console.WriteLine(parEvent); //OUTPUTAssist.PrintEvent(parEvent, parArgs); if (parEvent == "PLAYER_TARGET_CHANGED") { OnTargetChange?.Invoke(this, new EventArgs()); } else if (parEvent == "QUEST_FINISHED") { if (QuestFrame.IsOpen) { QuestFrame.Destroy(); } if (QuestGreetingFrame.IsOpen) { QuestGreetingFrame.Destroy(); } } else if (parEvent == "QUEST_PROGRESS" || parEvent == "QUEST_COMPLETE" || parEvent == "QUEST_DETAIL") { DirectX.Instance.Execute(QuestFrame.Create, 100); } else if (parEvent == "QUEST_GREETING") { DirectX.Instance.Execute(QuestGreetingFrame.Create, 100); } else if (parEvent == "UNIT_LEVEL") { if ((string)parArgs[0] != "player") { return; } LevelUp?.Invoke(this, new EventArgs()); } else if (parEvent == "PLAYER_MONEY") { OnMoneyChange?.Invoke(this, new EventArgs()); } else if (parEvent == "CHAT_MSG_LOOT") { // You receive loot: |cff9d9d9d|Hitem:7098:0:0:0|h[Splintered Tusk]|h|rx2. if (OnLoot == null) { return; } var arg1 = (string)parArgs[0]; var argArr = arg1.Split('|'); var itemId = Convert.ToInt32(argArr[2].Split(':')[1]); var itemName = argArr[3].Substring(2, argArr[3].Length - 3); var itemCount = 1; if (argArr[5].Length != 2) { itemCount = Convert.ToInt32(argArr[5].Substring(2, argArr[5].Length - 3)); } OnLoot.Invoke(this, new OnLootArgs(itemId, itemName, itemCount)); } else if (parEvent == "OPEN_STATUS_DIALOG") { if (OnWrongLogin == null) { return; } if (parArgs.Length != 2) { return; } if ((string)parArgs[0] != "OKAY") { return; } if ((string)parArgs[1] != "The information you have entered is not valid.") { return; } OnWrongLogin.Invoke(this, new EventArgs()); } else if (parEvent == "UPDATE_SELECTED_CHARACTER") { OnCharacterListLoaded?.Invoke(this, new EventArgs()); } else if (parEvent == "UPDATE_STATUS_DIALOG") { if (InServerQueue == null) { return; } if (parArgs.Length != 2) { return; } if (!((string)parArgs[0]).Contains("Position in queue:")) { return; } if ((string)parArgs[1] != "Change Realm") { return; } InServerQueue.Invoke(this, new EventArgs()); } else if (parEvent == "GET_PREFERRED_REALM_INFO") { OnChooseRealm?.Invoke(this, new EventArgs()); } else if (parEvent == "DISCONNECTED_FROM_SERVER") { OnDisconnect?.Invoke(this, new EventArgs()); } else if (parEvent == "UI_ERROR_MESSAGE") { OnErrorMessage?.Invoke(this, new OnUiMessageArgs((string)parArgs[0])); } else if (parEvent == "UI_INFO_MESSAGE") { OnUiMessage?.Invoke(this, new OnUiMessageArgs((string)parArgs[0])); } else if (parEvent == "CHAT_MSG_SYSTEM") { OnSystemMessage?.Invoke(this, new OnUiMessageArgs((string)parArgs[0])); } else if (parEvent == "PLAYER_REGEN_ENABLED") { OnFightStop?.Invoke(this, new EventArgs()); } else if (parEvent == "PLAYER_REGEN_DISABLED") { OnFightStart?.Invoke(this, new EventArgs()); } else if (parEvent == "CHAT_MSG_COMBAT_HOSTILE_DEATH") { if (OnUnitKilled == null) { return; } if (!((string)parArgs[0]).Contains("You have")) { return; } OnUnitKilled.Invoke(this, new EventArgs()); } else if (parEvent == "CHAT_MSG_SAY") { if (OnChatMessage == null) { return; } var unitName = (string)parArgs[1]; var chatType = "Say"; var chatTag = (string)parArgs[5]; var chatMessage = (string)parArgs[0]; var args = new ChatMessageArgs(Enums.ChatSenderType.Player, chatTag, unitName, chatType, chatMessage); OnChatMessage.Invoke(this, args); } else if (parEvent == "CHAT_MSG_MONSTER_SAY") { if (OnChatMessage == null) { return; } var unitName = (string)parArgs[1]; var chatType = "Say"; var chatTag = (string)parArgs[5]; var chatMessage = (string)parArgs[0]; var args = new ChatMessageArgs(Enums.ChatSenderType.Npc, chatTag, unitName, chatType, chatMessage); OnChatMessage.Invoke(this, args); } else if (parEvent == "CHAT_MSG_MONSTER_YELL") { if (OnChatMessage == null) { return; } var unitName = (string)parArgs[1]; var chatType = "Yell"; var chatTag = (string)parArgs[5]; var chatMessage = (string)parArgs[0]; var args = new ChatMessageArgs(Enums.ChatSenderType.Npc, chatTag, unitName, chatType, chatMessage); OnChatMessage.Invoke(this, args); } else if (parEvent == "CHAT_MSG_YELL") { if (OnChatMessage == null) { return; } var unitName = (string)parArgs[1]; var chatType = "Yell"; var chatTag = (string)parArgs[5]; var chatMessage = (string)parArgs[0]; var args = new ChatMessageArgs(Enums.ChatSenderType.Player, chatTag, unitName, chatType, chatMessage); OnChatMessage.Invoke(this, args); } else if (parEvent == "CHAT_MSG_CHANNEL") { if (OnChatMessage == null) { return; } var unitName = (string)parArgs[1]; var chatType = "Channel " + (int)parArgs[7]; var chatTag = (string)parArgs[5]; var chatMessage = (string)parArgs[0]; var args = new ChatMessageArgs(Enums.ChatSenderType.Player, chatTag, unitName, chatType, chatMessage); OnChatMessage.Invoke(this, args); } else if (parEvent == "CHAT_MSG_RAID") { if (OnChatMessage == null) { return; } var unitName = (string)parArgs[1]; var chatType = "Raid"; var chatTag = (string)parArgs[5]; var chatMessage = (string)parArgs[0]; var args = new ChatMessageArgs(Enums.ChatSenderType.Player, chatTag, unitName, chatType, chatMessage); OnChatMessage.Invoke(this, args); } else if (parEvent == "CHAT_MSG_GUILD") { if (OnChatMessage == null) { return; } var unitName = (string)parArgs[1]; var chatTag = (string)parArgs[5]; var chatMessage = (string)parArgs[0]; var args = new ChatMessageArgs(Enums.ChatSenderType.Player, chatTag, unitName, "Guild", chatMessage); OnChatMessage.Invoke(this, args); } else if (parEvent == "CHAT_MSG_PARTY") { if (OnChatMessage == null) { return; } var unitName = (string)parArgs[1]; var chatType = "Party"; var chatTag = (string)parArgs[5]; var chatMessage = (string)parArgs[0]; var args = new ChatMessageArgs(Enums.ChatSenderType.Player, chatTag, unitName, chatType, chatMessage); OnChatMessage.Invoke(this, args); } else if (parEvent == "CHAT_MSG_WHISPER") { if (OnChatMessage == null) { return; } var unitName = (string)parArgs[1]; var chatType = "Whisper"; var chatTag = (string)parArgs[5]; var chatMessage = (string)parArgs[0]; var args = new ChatMessageArgs(Enums.ChatSenderType.Player, chatTag, unitName, chatType, chatMessage); OnChatMessage.Invoke(this, args); } else if (parEvent == "DUEL_REQUESTED") { OnDuelRequest?.Invoke(this, new OnRequestArgs((string)parArgs[0])); } else if (parEvent == "GUILD_INVITE_REQUEST") { if (OnGuildInvite == null) { return; } var player = (string)parArgs[0]; var guild = (string)parArgs[1]; OnGuildInvite.Invoke(this, new GuildInviteArgs(player, guild)); } else if (parEvent == "TRADE_SHOW") { OnTradeShow?.Invoke(this, new EventArgs()); } else if (parEvent == "PARTY_INVITE_REQUEST") { OnPartyInvite?.Invoke(this, new OnRequestArgs((string)parArgs[0])); } else if (parEvent == "PLAYER_DEAD") { OnDeath?.Invoke(this, new EventArgs()); } else if (parEvent == "PLAYER_UNGHOST") { OnResurrect?.Invoke(this, new EventArgs()); } else if (parEvent == "CORPSE_IN_RANGE") { OnCorpseInRange?.Invoke(this, new EventArgs()); } else if (parEvent == "CORPSE_OUT_OF_RANGE") { OnCorpseOutOfRange?.Invoke(this, new EventArgs()); } else if (parEvent == "LOOT_OPENED") { LOOT_HANDLE(LootState.SHOW); } else if (parEvent == "LOOT_CLOSED") { LOOT_HANDLE(LootState.CLOSE); } else if (parEvent == "UNIT_AURA") { AuraChanged?.Invoke(this, new AuraChangedArgs((string)parArgs[0])); } else if (parEvent == "CHAT_MSG_SKILL") { OnSkillMessage?.Invoke(this, new OnUiMessageArgs((string)parArgs[0])); } else if (parEvent == "CHAT_MSG_COMBAT_XP_GAIN") { if (OnXpGain == null) { return; } var str = (string)parArgs[0]; var regex = new Regex("(?i)you gain [0-9]+"); var match = regex.Match(str); regex = new Regex("[0-9]+"); str = regex.Match(match.Value).Value; OnXpGain?.Invoke(this, new OnXpGainArgs(Convert.ToInt32(str))); } else if (parEvent == "UNIT_MODEL_CHANGED") { } else if (parEvent == "GOSSIP_SHOW") { GOSSIP_SHOW(); } else if (parEvent == "GOSSIP_CLOSED") { GOSSIP_CLOSED(); } else if (parEvent == "MERCHANT_SHOW") { Console.WriteLine("MERCHANT_SHOW occured"); MERCHANT_HANDLE(MerchantState.SHOW); } else if (parEvent == "MERCHANT_CLOSED") { MERCHANT_HANDLE(MerchantState.CLOSE); } else if (parEvent == "TAXIMAP_OPENED") { TAXIMAP_OPENED(); } else if (parEvent == "TAXIMAP_CLOSED") { TAXIMAP_CLOSED(); } else if (parEvent == "TRAINER_SHOW") { TRAINER_SHOW(); } else if (parEvent == "TRAINER_CLOSED") { TRAINER_CLOSED(); } else if (parEvent == "BANKFRAME_OPENED") { OnBankFrameOpen?.Invoke(this, new EventArgs()); } else if (parEvent == "BANKFRAME_CLOSED") { OnBankFrameClosed?.Invoke(this, new EventArgs()); } else if (parEvent == "MAIL_SHOW") { OnMailboxOpen?.Invoke(this, new EventArgs()); } else if (parEvent == "MAIL_CLOSED") { OnMailboxClosed?.Invoke(this, new EventArgs()); } }
/// <summary> /// 错误信息 /// </summary> /// <param name="msg"></param> private void ErrorMsg(string msg) { //Console.WriteLine(msg); OnErrorMessage?.Invoke(msg); }
private void v_ReceivedMessage(object peer) { NetIncomingMessage msg = Server.ReadMessage(); switch (msg.MessageType) { case NetIncomingMessageType.Error: OnError?.Invoke(msg.ReadString()); break; case NetIncomingMessageType.StatusChanged: OnClientStatusChanged?.Invoke(msg.SenderConnection, msg.SenderConnection.Status); if (msg.SenderConnection.Status == NetConnectionStatus.Connected) { OnClientConnected?.Invoke(msg.SenderConnection); } break; case NetIncomingMessageType.ConnectionApproval: v_HandleConnectionAuth(msg); break; case NetIncomingMessageType.Data: v_HandlePacket(msg); break; case NetIncomingMessageType.DiscoveryRequest: if (!DiscoveryResponse(msg, Server, out NetOutgoingMessage resp)) { break; } Server.SendDiscoveryResponse(resp, msg.SenderEndPoint); break; case NetIncomingMessageType.VerboseDebugMessage: case NetIncomingMessageType.DebugMessage: OnDebugMessage?.Invoke(msg.ReadString()); break; case NetIncomingMessageType.WarningMessage: OnWarningMessage?.Invoke(msg.ReadString()); break; case NetIncomingMessageType.ErrorMessage: OnErrorMessage?.Invoke(msg.ReadString()); break; } Server.Recycle(msg); }