private void WsOnDecode(string message)
        {
            Debug.WriteLine(message);
            JObject obj = DouyuSedes.Deserialize(message) as JObject;

            if (obj.ContainsKey("type"))
            {
                string type = obj["type"].Value <string>();
                switch (type)
                {
                case "chatmsg":
                {
                    ChatMessage chatMessage = new ChatMessage
                    {
                        Time     = DateTimeOffset.FromUnixTimeMilliseconds(obj["cst"].Value <long>()).LocalDateTime,
                        Username = obj["nn"].Value <string>(),
                        Content  = obj["txt"].Value <string>(),
                        Color    = obj.ContainsKey("col") ? (ChatMessageColor)obj["col"].Value <int>() : ChatMessageColor.White,
                        Level    = obj["level"].Value <int>()
                    };
                    OnChatMessage.Invoke(chatMessage);
                    break;
                }
                }
                if (callbacks.ContainsKey(type))
                {
                    callbacks[type](obj);
                }
            }
        }
Пример #2
0
        private IntPtr HandlePrintMessageDetour(IntPtr manager, XivChatType chattype, IntPtr pSenderName, IntPtr pMessage,
                                                uint senderid, IntPtr parameter)
        {
            IntPtr retVal = IntPtr.Zero;

            try {
                var senderName = StdString.ReadFromPointer(pSenderName);
                var message    = StdString.ReadFromPointer(pMessage);

                Log.Debug($"HandlePrintMessageDetour {manager} - [{chattype}] [{BitConverter.ToString(message.RawData).Replace("-", " ")}] {message.Value} from {senderName.Value}");
                // Log.Debug($"Got message bytes {BitConverter.ToString(messageBytes.Bytes).Replace("-", " ")}");

                var originalMessageData = (byte[])message.RawData.Clone();

                // Call events
                var isHandled = false;
                OnChatMessage?.Invoke(chattype, senderid, ref senderName, ref message, ref isHandled);

                var            messagePtr      = pMessage;
                OwnedStdString allocatedString = null;

                if (!FastByteArrayCompare(originalMessageData, message.RawData))
                {
                    allocatedString = this.dalamud.Framework.Libc.NewString(message.RawData);
                    Log.Debug(
                        $"HandlePrintMessageDetour String modified: {originalMessageData}({messagePtr}) -> {message}({allocatedString.Address})");
                    messagePtr = allocatedString.Address;
                }

                // Print the original chat if it's handled.
                if (!isHandled)
                {
                    retVal = this.printMessageHook.Original(manager, chattype, pSenderName, messagePtr, senderid, parameter);
                }

                if (this.baseAddress == IntPtr.Zero)
                {
                    this.baseAddress = manager;
                }

                allocatedString?.Dispose();
            } catch (Exception ex) {
                Log.Error(ex, "Exception on OnChatMessage hook.");
                retVal = this.printMessageHook.Original(manager, chattype, pSenderName, pMessage, senderid, parameter);
            }

            return(retVal);
        }
Пример #3
0
        /// <summary>
        /// IRC event: a raw message was received by us.
        /// This is where custom parsing needs to take place.
        /// </summary>
        private void Client_RawMessageReceived(object sender, IrcRawMessageEventArgs e)
        {
            TmiLog.Debug("<<<", e.RawContent);

            if (e.RawContent.StartsWith('@'))
            {
                // Looks like a TMI message with state info that we can parse & process
                var tmiMsg = TmiMessageParser.Parse(e.RawContent);

                if (tmiMsg is TmiChatMessage)
                {
                    if (OnChatMessage != null)
                    {
                        OnChatMessage.Invoke(this, new TmiChatMessageEventArgs((TmiChatMessage)tmiMsg));
                    }
                }
            }
        }
Пример #4
0
        private void MessageHandler(IRCMessage message)
        {
            //Console.WriteLine($"> {message.IRCReply}:  {message.RawParameters}");
            switch (message.Command)
            {
            case "PING":
                SendRawMessage("PONG :tmi.twitch.tv");     // SO twitch doesnt mark as inactive and disconnect us
                break;

            case "PRIVMSG":
                OnChatMessage?.Invoke(ChatMessage.Factory(message));
                break;

            default:
                Console.WriteLine("> UNHANDLED REPLY COMMAND  " + message.Command);
                break;
            }
        }
Пример #5
0
        void HandleServerChatMessage(PacketReader reader)
        {
            ChatType type = (ChatType)reader.ReadByte();
            Language language;
            UInt64   targetGUID;
            UInt64   targetGUIDOther;
            UInt32   messageLength;
            string   channelName = null;
            string   message;

            language = (Language)reader.ReadUInt32();

            targetGUID = reader.ReadUInt64();

            reader.ReadUInt32(); // Some flags

            channelName = type == ChatType.CHAT_TYPE_CHANNEL ? reader.ReadCString() : null;

            targetGUIDOther = reader.ReadUInt64();
            messageLength   = reader.ReadUInt32();
            message         = reader.ReadCString();
            reader.ReadByte(); // chattag

            PlayerName result = PlayerNameList.Find((PlayerName name) => { return(name.GUID == targetGUID); });

            var args = new ChatArgs
            {
                Type        = type,
                Message     = message,
                ChannelName = channelName != null ? channelName : string.Empty,
                Name        = result != null ? result.Name : string.Empty
            };

            OnChatMessage?.Invoke(null, args);

            if (targetGUID > 0)
            {
                PacketWriter writer = new PacketWriter(Opcodes.CMSG_NAME_QUERY);
                writer.Write(targetGUID);
                Send(writer);
            }
        }
Пример #6
0
        void HandleGamemasterServerChatMessage(PacketReader reader)
        {
            ChatType type       = (ChatType)reader.ReadByte();
            Language language   = (Language)reader.ReadUInt32();
            UInt64   senderGUID = reader.ReadUInt64();

            reader.ReadUInt32(); // Always 0

            UInt32 senderNameLenght = reader.ReadUInt32();
            string senderName       = reader.ReadCString();

            UInt64 receiverGUID  = reader.ReadUInt64();
            UInt32 messageLength = reader.ReadUInt32();

            string message = reader.ReadCString();

            OnChatMessage?.Invoke(this, new ChatArgs
            {
                Type        = type,
                Message     = message,
                Name        = senderName,
                ChannelName = null
            });
        }
Пример #7
0
        internal void PushCommand(Command cmd)
        {
            if (cmd.Source == CommandSource.Client)
            {
                return;
            }

            switch (cmd.Token)
            {
            case "JCH":
            {
                var jch = cmd as Server_JCH_ChannelJoin;

                var character = Connection.GetOrCreateCharacter(jch.Character.Identity);

                if (!_Characters.Contains(character))
                {
                    _Characters.Add(character);
                }

                if (!string.IsNullOrEmpty(jch.Title))
                {
                    _Title = jch.Title;
                    Joined = true;
                }
                else
                {
                    OnUserJoin?.Invoke(this, new ChannelUserEntryEventArgs(this, character, jch));
                }
            }
                return;

            case "LCH":
            {
                var lch = cmd as Server_LCH_ChannelLeave;

                var character = GetCharacter(lch.Character);
                _Characters.Remove(character);

                if (character.Name == Connection.LocalCharacter.Name)
                {
                    Dispose();
                }
                else
                {
                    OnUserLeave?.Invoke(this, new ChannelUserEntryEventArgs(this, character, lch));
                }
            }
                return;

            case "ICH":
            {
                var ich = cmd as Server_ICH_ChannelInitialData;

                _ChannelMode = ich.Mode;
                Joined       = true;

                foreach (var user in ich.Users)
                {
                    var ch = GetCharacter(user.Identity);
                    if (!_Characters.Contains(ch))
                    {
                        _Characters.Add(ch);
                    }
                }
            }
                return;

            case "COL":
            {
                var col = cmd as Server_COL_ChannelGetOPs;

                foreach (var op in col.OPs)
                {
                    if (!string.IsNullOrWhiteSpace(op))
                    {
                        _OPs.Add(GetCharacter(op));
                    }
                }
            }
                return;

            case "CDS":
            {
                var cds = cmd as Server_CDS_ChannelChangeDescription;

                OnDescriptionChange?.Invoke(this, new ChannelEntryEventArgs <string>(this, cds.Description, cds));
                _Description = cds.Description;
            }
                return;

            case "RMO":
            {
                var rmo = cmd as Server_RMO_ChannelSetMode;

                OnModeChange?.Invoke(this, new ChannelEntryEventArgs <ChannelMode>(this, rmo.Mode, rmo));
                _ChannelMode = rmo.Mode;
            }
                return;

            case "CSO":
            {
                var cso = cmd as Server_CSO_ChannelSetOwner;

                OnOwnerChange?.Invoke(this, new ChannelEntryEventArgs <Character>(this, GetCharacter(cso.Character), cso));
                _OwnerName = cso.Character;
            }
                return;

            case "RST":
            {
                var rst = cmd as Server_RST_ChannelSetStatus;

                OnStatusChange?.Invoke(this, new ChannelEntryEventArgs <ChannelStatus>(this, rst.Status, rst));
                _Status = rst.Status;
            }
                return;

            case "COA":
            {
                var coa = cmd as Server_COA_ChannelMakeOP;

                var character = GetCharacter(coa.Character);
                _OPs.Add(character);

                OnOPAdded?.Invoke(this, new ChannelUserEntryEventArgs(this, character, coa));
            }
                return;

            case "COR":
            {
                var cor = cmd as Server_COR_ChannelRemoveOP;

                var character = GetCharacter(cor.Character);
                _OPs.Remove(character);

                OnOPRemoved?.Invoke(this, new ChannelUserEntryEventArgs(this, character, cor));
            }
                return;

            case "CKU":
            {
                var cku = cmd as Server_CKU_ChannelKickCharacter;

                var character = GetCharacter(cku.Character);
                _Characters.Remove(character);

                OnUserKicked?.Invoke(this, new ChannelAdminActionEventArgs(this, character, GetCharacter(cku.OP), cku));
            }
                return;

            case "CBU":
            {
                var cbu = cmd as Server_CBU_ChannelBanCharacter;

                var character = GetCharacter(cbu.Character);
                _Characters.Remove(character);

                _Banlist.Add(character);

                OnUserBanned?.Invoke(this, new ChannelAdminActionEventArgs(this, character, GetCharacter(cbu.OP), cbu));
            }
                return;

            case "CUB":
            {
                var cub = cmd as Server_CUB_ChannelUnbanCharacter;

                var character = GetCharacter(cub.Character);

                _Banlist.Remove(character);

                OnUserUnbanned?.Invoke(this, new ChannelAdminActionEventArgs(this, character, GetCharacter(cub.OP), cub));
            }
                return;

            case "CTU":
            {
                var ctu = cmd as Server_CTU_ChannelTimeoutCharacter;

                var character = GetCharacter(ctu.Character);
                _Characters.Remove(character);

                OnUserTimedout?.Invoke(this, new ChannelAdminActionEventArgs(this, character, GetCharacter(ctu.OP), ctu));
            }
                return;

            case "MSG":
            {
                var msg = cmd as Server_MSG_ChannelChatMessage;
                OnChatMessage?.Invoke(this, new ChannelUserMessageEventArgs(this, GetCharacter(msg.Character), msg.Message, msg));
            } return;

            case "LRP":
            {
                var lrp = cmd as Server_LRP_ChannelLFRPMessage;
                OnLFRPMessage?.Invoke(this, new ChannelUserMessageEventArgs(this, GetCharacter(lrp.Character), lrp.AD, lrp));
            } return;

            case "RLL":
            {
                var rll = cmd as Server_RLL_ChannelRollMessage;
                OnRollMessage?.Invoke(this, new ChannelUserMessageEventArgs(this, GetCharacter(rll.Character), rll.Message, rll));
            } return;

            case "SYS":
            {
                var sys = cmd as Server_SYS_ChatSYSMessage;
                OnSYSMessage?.Invoke(this, new ChannelEntryEventArgs <string>(this, sys.Message, sys));
            } return;
            }
        }
Пример #8
0
        private IntPtr HandlePrintMessageDetour(IntPtr manager, XivChatType chattype, IntPtr pSenderName, IntPtr pMessage,
                                                uint senderid, IntPtr parameter)
        {
            var retVal = IntPtr.Zero;

            try {
                var sender  = StdString.ReadFromPointer(pSenderName);
                var message = StdString.ReadFromPointer(pMessage);

                var parsedSender  = this.dalamud.SeStringManager.Parse(sender.RawData);
                var parsedMessage = this.dalamud.SeStringManager.Parse(message.RawData);

                Log.Verbose("[CHATGUI][{0}][{1}]", parsedSender.TextValue, parsedMessage.TextValue);

                //Log.Debug($"HandlePrintMessageDetour {manager} - [{chattype}] [{BitConverter.ToString(message.RawData).Replace("-", " ")}] {message.Value} from {senderName.Value}");

                var originalMessageData = (byte[])message.RawData.Clone();
                var oldEdited           = parsedMessage.Encode();

                // Call events
                var isHandled = false;
                OnCheckMessageHandled?.Invoke(chattype, senderid, ref parsedSender, ref parsedMessage, ref isHandled);

                if (!isHandled)
                {
                    OnChatMessage?.Invoke(chattype, senderid, ref parsedSender, ref parsedMessage, ref isHandled);
                    OnChatMessageRaw?.Invoke(chattype, senderid, ref sender, ref message, ref isHandled);
                }

                var newEdited = parsedMessage.Encode();

                if (!FastByteArrayCompare(oldEdited, newEdited))
                {
                    Log.Verbose("SeString was edited, taking precedence over StdString edit.");
                    message.RawData = newEdited;
                    Log.Debug($"\nOLD: {BitConverter.ToString(originalMessageData)}\nNEW: {BitConverter.ToString(newEdited)}");
                }

                var            messagePtr      = pMessage;
                OwnedStdString allocatedString = null;

                if (!FastByteArrayCompare(originalMessageData, message.RawData))
                {
                    allocatedString = this.dalamud.Framework.Libc.NewString(message.RawData);
                    Log.Debug(
                        $"HandlePrintMessageDetour String modified: {originalMessageData}({messagePtr}) -> {message}({allocatedString.Address})");
                    messagePtr = allocatedString.Address;
                }

                // Print the original chat if it's handled.
                if (isHandled)
                {
                    OnChatMessageHandled?.Invoke(chattype, senderid, parsedSender, parsedMessage);
                }
                else
                {
                    retVal = this.printMessageHook.Original(manager, chattype, pSenderName, messagePtr, senderid, parameter);
                    OnChatMessageUnhandled?.Invoke(chattype, senderid, parsedSender, parsedMessage);
                }

                if (this.baseAddress == IntPtr.Zero)
                {
                    this.baseAddress = manager;
                }

                allocatedString?.Dispose();
            } catch (Exception ex) {
                Log.Error(ex, "Exception on OnChatMessage hook.");
                retVal = this.printMessageHook.Original(manager, chattype, pSenderName, pMessage, senderid, parameter);
            }

            return(retVal);
        }
Пример #9
0
 public void EmitMessage(TwitchChatMessage msg)
 {
     OnChatMessage?.Invoke(this, new Ps2EventArgs <TwitchChatMessage>(msg));
 }
Пример #10
0
 public void FireOnChatMessage(string message)
 {
     OnChatMessage?.Invoke(message);
 }
Пример #11
0
        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());
            }
        }
Пример #12
0
        public Multiplayer(string Server, string Channel, string Username)
        {
            this.Channel  = Channel;
            this.Username = Username;

            socket = new WebSocket(Server);

            socket.OnOpen += (sender, e) =>
            {
                MessageConnect connect = new MessageConnect()
                {
                    Channel  = this.Channel,
                    Username = this.Username,
                    Version  = Shared.Version
                };

                socket.Send(JsonConvert.SerializeObject(connect));
            };

            socket.OnClose += (sender, e) =>
            {
                if (!ManualClose && !string.IsNullOrWhiteSpace(e.Reason))
                {
                    OnConnectionFailed?.Invoke(this, new ConnectionFailedEventArgs());
                }
            };

            socket.OnMessage += (sender, e) =>
            {
                MessageType messageType = JsonConvert.DeserializeObject <MessageType>(e.Data);
                if (messageType.Type == 0) // Connection Successful
                {
                    MessageConnectionSuccessful connectionSuccessful = JsonConvert.DeserializeObject <MessageConnectionSuccessful>(e.Data);

                    IsHost = connectionSuccessful.IsHost;

                    ConnectionSuccessfulEventArgs succ = new ConnectionSuccessfulEventArgs()
                    {
                        IsHost       = connectionSuccessful.IsHost,
                        HostUsername = connectionSuccessful.HostUsername
                    };

                    OnConnectionSuccessful?.Invoke(this, succ);
                }
                else if (messageType.Type == 1) // Username in use
                {
                    OnUsernameInUse?.Invoke(this, new UsernameInUseEventArgs());
                    socket.Close();
                }
                else if (messageType.Type == 2) // Host left the channel
                {
                    OnHostLeftChannel?.Invoke(this, new HostLeftChannelEventArgs());
                    socket.Close();
                }
                else if (messageType.Type == 3)
                {
                    MessageVersionMismatch mismatch = JsonConvert.DeserializeObject <MessageVersionMismatch>(e.Data);

                    var args = new VersionMismatchEventArgs()
                    {
                        Version = mismatch.Version
                    };

                    OnVersionMismatch?.Invoke(this, args);
                }
                // -------
                else if (messageType.Type == 10) // User Joined
                {
                    MessageUserJoined user = JsonConvert.DeserializeObject <MessageUserJoined>(e.Data);

                    var args = new UserJoinedEventArgs()
                    {
                        Username = user.Username
                    };

                    OnUserJoined?.Invoke(this, args);
                }
                else if (messageType.Type == 11) // User Left
                {
                    MessageUserLeft user = JsonConvert.DeserializeObject <MessageUserLeft>(e.Data);

                    var args = new UserLeftEventArgs()
                    {
                        Username = user.Username
                    };

                    OnUserLeft?.Invoke(this, args);
                }
                else if (messageType.Type == 12) // Chat Message
                {
                    MessageChatMessage chatMessage = JsonConvert.DeserializeObject <MessageChatMessage>(e.Data);

                    var args = new ChatMessageEventArgs()
                    {
                        Username = chatMessage.Username,
                        Message  = chatMessage.Message
                    };

                    OnChatMessage?.Invoke(this, args);
                }
                // -------
                else if (messageType.Type == 20) // Time Update
                {
                    MessageTimeUpdate timeUpdate = JsonConvert.DeserializeObject <MessageTimeUpdate>(e.Data);

                    var args = new TimeUpdateEventArgs()
                    {
                        Remaining = timeUpdate.Remaining,
                        Total     = timeUpdate.Total
                    };

                    OnTimeUpdate?.Invoke(this, args);
                }
                else if (messageType.Type == 21) // Send Effect
                {
                    MessageEffect effect = JsonConvert.DeserializeObject <MessageEffect>(e.Data);

                    var args = new EffectEventArgs()
                    {
                        Word     = effect.Word,
                        Duration = effect.Duration,
                        Voter    = effect.Voter,
                        Seed     = effect.Seed
                    };

                    OnEffect?.Invoke(this, args);
                }
                else if (messageType.Type == 22) // Votes
                {
                    MessageVotes votes = JsonConvert.DeserializeObject <MessageVotes>(e.Data);

                    var args = new VotesEventArgs()
                    {
                        Effects    = votes.Effects,
                        Votes      = votes.Votes,
                        LastChoice = votes.LastChoice
                    };

                    OnVotes?.Invoke(this, args);
                }
            };
        }
Пример #13
0
 public override Task <EmptyResponse> ChatMessage(ChatMessageRequest request, ServerCallContext context)
 {
     OnChatMessage?.Invoke(this, request);
     return(Task.FromResult(new EmptyResponse()));
 }
Пример #14
-1
        static private unsafe void OnLobbyChatMessageRecievedAPI(LobbyChatMsg_t callback)
        {
            SteamId       steamid       = default;
            ChatEntryType chatEntryType = default;
            var           buffer        = Helpers.TakeBuffer(1024 * 4);

            fixed(byte *p = buffer)
            {
                var readData = Internal.GetLobbyChatEntry(callback.SteamIDLobby, (int)callback.ChatID, ref steamid, (IntPtr)p, buffer.Length, ref chatEntryType);

                if (readData > 0)
                {
                    OnChatMessage?.Invoke(new Lobby(callback.SteamIDLobby), new Friend(steamid), Encoding.UTF8.GetString(buffer, 0, readData));
                }
            }
        }