Esempio n. 1
0
 void _chat_ExceptionEvent(Vha.Net.Chat chat, Exception e)
 {
     if (this.ExceptionEvent != null)
     {
         this.ExceptionEvent(this, e);
     }
 }
Esempio n. 2
0
        void _chat_PrivateChannelRequestEvent(Vha.Net.Chat chat, PrivateChannelRequestEventArgs e)
        {
            // Check for ignores
            if (this.Ignores.Contains(e.Character))
            {
                return;
            }
            // Some sensible checks
            PrivateChannel channel = e.GetPrivateChannel();
            bool           error   = false;

            lock (this._privateChannels)
            {
                error = this._privateChannels.ContainsKey(e.CharacterID);
            }
            if (error)
            {
                this.Write(MessageClass.Error, "Unexpected invite to private channel from: " + e.Character);
                return;
            }
            // Dispatch invite event
            PrivateChannelInviteEventArgs args = new PrivateChannelInviteEventArgs(e, channel);

            if (this.PrivateChannelInviteEvent != null)
            {
                this.PrivateChannelInviteEvent(this, args);
            }
        }
Esempio n. 3
0
 void _chat_SystemMessageEvent(Vha.Net.Chat chat, SystemMessageEventArgs e)
 {
     // Descramble message
     MDB.Message message = null;
     try { message = MDB.Parser.Decode((int)e.CategoryID, (int)e.MessageID, e.Arguments, null); }
     catch (Exception ex)
     {
         this.Write(MessageClass.Error, "Error while decoding message: " + ex.Message);
     }
     // Apply ignore filter to "received offline message from" messages
     if (e.MessageID == (uint)SystemMessageType.IncommingOfflineMessage)
     {
         string character = message.Arguments[(int)IncomingOfflineMessageArgs.Name].ToString();
         // Check ignored characters list
         if (this.Ignores.Contains(character))
         {
             return;
         }
     }
     // Failed to get the entry
     if (message == null || string.IsNullOrEmpty(message.Value))
     {
         this.Write(MessageClass.Error, "Unknown system message " + e.CategoryID + ":" + e.MessageID);
         return;
     }
     // Dispatch message
     this.Write(MessageClass.SystemMessage, message.Value);
 }
Esempio n. 4
0
        void _chat_PrivateMessageEvent(Vha.Net.Chat chat, PrivateMessageEventArgs e)
        {
            // Check for ignores
            if (this.Ignores.Contains(e.Character))
            {
                return;
            }
            // Treat 'null-characters' as broadcasts
            if (e.CharacterID == 0)
            {
                this.Write(MessageClass.BroadcastMessage, e.Message);
                return;
            }
            // Dispatch message
            MessageSource source = new MessageSource(MessageType.Character, null, e.Character, e.Outgoing);

            this.Write(source, MessageClass.PrivateMessage, e.Message);
            // Add to recent friends
            Friend friend = this.GetFriend(e.Character);

            if (friend != null)
            {
                return;
            }
            this.Chat.SendFriendAdd(e.CharacterID, "\0");
        }
Esempio n. 5
0
        void _chat_ChannelMessageEvent(Vha.Net.Chat chat, ChannelMessageEventArgs e)
        {
            Channel channel = this.GetChannel(e.Channel);

            // Check if channel is muted
            if (channel != null && (channel.Flags & ChannelFlags.Muted) != 0)
            {
                return;
            }
            // Check for ignores
            if (this.Ignores.Contains(e.Character))
            {
                return;
            }
            // Descramble
            string message = e.Message;

            if (e.Message.StartsWith("~"))
            {
                MDB.Message parsedMessage = null;
                try { parsedMessage = MDB.Parser.Decode(e.Message); }
                catch (Exception) { } // Errors are fine here, if it's not a valid message, we'll display the original
                if (parsedMessage != null && !string.IsNullOrEmpty(parsedMessage.Value))
                {
                    message = parsedMessage.Value;
                }
            }
            // Dispatch message
            MessageSource source = new MessageSource(MessageType.Channel, e.Channel, e.Character, e.Character == this.Character);

            this.Write(source, this.GetChannelClass(e.Channel), message);
        }
Esempio n. 6
0
        void _chat_FriendStatusEvent(Vha.Net.Chat chat, FriendStatusEventArgs e)
        {
            // Ignore invalid friends
            if (string.IsNullOrEmpty(e.Character))
            {
                return;
            }
            // Handle friend update
            Friend friend = e.GetFriend();
            Friend previousFriend = null;
            bool   added, updated;

            lock (this._friends)
            {
                added = !this._friends.ContainsKey(e.CharacterID);
                if (added)
                {
                    this._friends.Add(e.CharacterID, friend);
                }
                updated = !this._friends[e.CharacterID].Equals(friend);
                if (updated)
                {
                    previousFriend = this._friends[e.CharacterID];
                }
                this._friends[e.CharacterID] = friend;
            }
            if (this.FriendAddedEvent != null && added)
            {
                this.FriendAddedEvent(this, new FriendEventArgs(friend, previousFriend, true));
            }
            if (this.FriendUpdatedEvent != null && updated)
            {
                this.FriendUpdatedEvent(this, new FriendEventArgs(friend, previousFriend, false));
            }
        }
Esempio n. 7
0
 void _chat_LoginErrorEvent(Vha.Net.Chat chat, LoginErrorEventArgs e)
 {
     // Notify listeners of the error
     if (this.ErrorEvent != null)
     {
         this.ErrorEvent(this, new Events.ErrorEventArgs(ErrorType.Login, e.Error));
     }
 }
Esempio n. 8
0
        void _chat_PrivateChannelMessageEvent(Vha.Net.Chat chat, PrivateChannelMessageEventArgs e)
        {
            // Check for ignores
            if (this.Ignores.Contains(e.Character))
            {
                return;
            }
            // Dispatch message
            MessageSource source = new MessageSource(MessageType.PrivateChannel, e.Channel, e.Character, e.Character == this.Character);

            this.Write(source, MessageClass.PrivateChannel, e.Message);
        }
Esempio n. 9
0
        void _chat_LoginOKEvent(Vha.Net.Chat chat, EventArgs e)
        {
            // Prevent duplicate events
            if (this._state == ContextState.Connected)
            {
                return;
            }
            // Update state
            ContextState previousState = this._state;

            this._state = ContextState.Connected;
            // This tastes like more
            this._chat.AutoReconnect = true;
            // Notify state change
            if (this.StateEvent != null)
            {
                this.StateEvent(this, new StateEventArgs(this._state, previousState));
            }
        }
Esempio n. 10
0
        void _chat_FriendRemovedEvent(Vha.Net.Chat chat, CharacterIDEventArgs e)
        {
            Friend friend  = null;
            bool   removed = false;

            lock (this._friends)
            {
                if (this._friends.ContainsKey(e.CharacterID))
                {
                    removed = true;
                    friend  = this._friends[e.CharacterID];
                    this._friends.Remove(e.CharacterID);
                }
            }
            if (this.FriendRemovedEvent != null && removed)
            {
                this.FriendRemovedEvent(this, new FriendEventArgs(friend, friend, false));
            }
        }
Esempio n. 11
0
        void _chat_LoginCharlistEvent(Vha.Net.Chat chat, LoginChararacterListEventArgs e)
        {
            // Only fire the character selection event when no character has been pre-selected
            if (string.IsNullOrEmpty(chat.Character))
            {
                // Create event arguments
                List <Character> characters = new List <Character>();
                Dictionary <Character, LoginCharacter> charactersMap = new Dictionary <Character, LoginCharacter>();
                foreach (LoginCharacter c in e.CharacterList)
                {
                    Character character = new Character(c.Name, c.ID, c.Level, c.IsOnline);
                    characters.Add(character);
                    charactersMap.Add(character, c);
                }
                SelectCharacterEventArgs args = new SelectCharacterEventArgs(characters.ToArray());
                // Fire event
                if (this.SelectCharacterEvent != null)
                {
                    this.SelectCharacterEvent(this, args);
                }
                // Login
                if (args.Character != null && charactersMap.ContainsKey(args.Character))
                {
                    this._character   = args.Character.Name;
                    this._characterID = args.Character.ID;
                    this._chat.SendLoginCharacter(charactersMap[args.Character]);

                    // Mark as 'recently used'
                    OptionsAccount acc = this.Options.GetAccount(this.Account, true);
                    acc.Name      = this.Options.LastAccount = this._account;
                    acc.Dimension = this.Options.LastDimension = this._dimension;
                    acc.Character = this._character;
                    this.Options.Save();
                }
                else
                {
                    // If no character was selected, there's no reason to remain connected
                    this._chat.Disconnect(true);
                    return;
                }
            }
        }
Esempio n. 12
0
        void _chat_ChannelStatusEvent(Vha.Net.Chat chat, ChannelStatusEventArgs e)
        {
            Channel channel = e.GetChannel();
            Channel previousChannel = null;
            bool    joined, updated;

            lock (this._channels)
            {
                joined = !this._channels.ContainsKey(e.ID);
                if (joined)
                {
                    this._channels.Add(e.ID, channel);
                }
                updated = !this._channels[e.ID].Equals(channel);
                if (updated)
                {
                    previousChannel = this._channels[e.ID];
                }
                this._channels[e.ID] = channel;
            }
            // Detect organization
            if (e.Type == ChannelType.Organization)
            {
                this._organization   = e.Name;
                this._organizationID = (UInt32)e.ID.IntValue();
            }
            // Fire events
            if (this.ChannelJoinEvent != null && joined)
            {
                this.ChannelJoinEvent(this, new ChannelEventArgs(channel, previousChannel, true));
            }
            if (this.ChannelUpdatedEvent != null && updated)
            {
                this.ChannelUpdatedEvent(this, new ChannelEventArgs(channel, previousChannel, false));
            }
        }
Esempio n. 13
0
        void _chat_PrivateChannelStatusEvent(Vha.Net.Chat chat, PrivateChannelStatusEventArgs e)
        {
            PrivateChannel channel = e.GetPrivateChannel();

            // Handle locally
            if (e.Local)
            {
                bool joined = false;
                bool left   = false;
                lock (this._guests)
                {
                    if (this._guests.Contains(e.CharacterID) && !e.Join)
                    {
                        left = true;
                        this._guests.Remove(e.CharacterID);
                    }
                    else if (!this._guests.Contains(e.CharacterID) && e.Join)
                    {
                        joined = true;
                        this._guests.Add(e.CharacterID);
                    }
                }
                // Dispatch events
                if (this.CharacterJoinEvent != null && joined)
                {
                    this.CharacterJoinEvent(this, new PrivateChannelEventArgs(channel, e.Character, true, true));
                }
                if (this.CharacterLeaveEvent != null && left)
                {
                    this.CharacterLeaveEvent(this, new PrivateChannelEventArgs(channel, e.Character, false, true));
                }
            }
            // Handle remote
            else
            {
                // Handle other characters
                if (e.CharacterID != this.CharacterID)
                {
                }
                // Handle the local character
                else
                {
                    bool joined = false;
                    bool left   = false;
                    lock (this._privateChannels)
                    {
                        if (this._privateChannels.ContainsKey(e.ChannelID) && !e.Join)
                        {
                            left = true;
                            this._privateChannels.Remove(e.ChannelID);
                        }
                        else if (!this._privateChannels.ContainsKey(e.ChannelID) && e.Join)
                        {
                            joined = true;
                            this._privateChannels.Add(e.ChannelID, channel);
                        }
                    }
                    // Dispatch events
                    if (joined)
                    {
                        if (this.PrivateChannelJoinEvent != null)
                        {
                            this.PrivateChannelJoinEvent(this, new PrivateChannelEventArgs(channel, e.Character, true, false));
                        }
                    }
                    else if (left)
                    {
                        if (this.PrivateChannelLeaveEvent != null)
                        {
                            this.PrivateChannelLeaveEvent(this, new PrivateChannelEventArgs(channel, e.Character, false, false));
                        }
                    }
                    else
                    {
                        // Nothing happened, don't bother writing that message!
                        return;
                    }
                }
            }
            // Send messages
            if (e.Join)
            {
                this.Write(new MessageSource(MessageType.PrivateChannel, e.Channel, null, false), MessageClass.PrivateChannel,
                           e.Character + " joined the channel");
            }
            else
            {
                this.Write(new MessageSource(MessageType.PrivateChannel, e.Channel, null, false), MessageClass.PrivateChannel,
                           e.Character + " left the channel");
            }
        }
Esempio n. 14
0
        void _chat_StateChangeEvent(Vha.Net.Chat chat, StateChangeEventArgs e)
        {
            ContextState state         = this._state;
            ContextState previousState = this._state;

            lock (this)
            {
                // Translate state
                switch (e.State)
                {
                case ChatState.CharacterSelect:
                    state = ContextState.CharacterSelection;
                    break;

                case ChatState.Connecting:
                case ChatState.Login:
                    state = ContextState.Connecting;
                    break;

                case ChatState.Connected:
                    state = ContextState.Connected;
                    break;

                case ChatState.Disconnected:
                case ChatState.Error:
                    state = ContextState.Disconnected;
                    this._disconnecting = false;
                    break;

                case ChatState.Reconnecting:
                    state = ContextState.Reconnecting;
                    break;
                }
                // No state change? We stopped caring!
                if (previousState == state)
                {
                    return;
                }
                // Handle state change
                switch (state)
                {
                case ContextState.CharacterSelection:
                    this._character   = this._chat.Character;
                    this._characterID = this._chat.ID;
                    break;

                case ContextState.Disconnected:
                    lock (this._messageHistory)
                        this._messageHistory.Clear();
                    this._chat.AutoReconnect = false;
                    this._chat.ClearEvents();
                    this._chat      = null;
                    this._dimension = null;
                    this._account   = null;
                    this._character = null;
                    // Fall through to the next case
                    goto case ContextState.Reconnecting;

                case ContextState.Reconnecting:
                    this._organization   = null;
                    this._organizationID = 0;
                    this._characterID    = 0;
                    lock (this._friends)
                        this._friends.Clear();
                    lock (this._channels)
                        this._channels.Clear();
                    lock (this._privateChannels)
                        this._privateChannels.Clear();
                    lock (this._guests)
                        this._guests.Clear();
                    break;
                }
            }
            // Notify state change
            this._state = state;
            if (this.StateEvent != null)
            {
                this.StateEvent(this, new StateEventArgs(this._state, previousState));
            }
        }
Esempio n. 15
0
 void _chat_BroadcastMessageEvent(Vha.Net.Chat chat, BroadcastMessageEventArgs e)
 {
     // Dispatch message
     this.Write(MessageClass.BroadcastMessage, e.Message);
 }