示例#1
0
        public override void Events_ReceivedTriggeringEvent(object sender, Entities.EventHandlers.ReceivedEventEventArgs e)
        {
            var triggered = true;

            switch (e.Event.GetType().Name)
            {
            case nameof(FChatSharpLib.Entities.Events.Server.JoinChannel):
                var jchEvent = (FChatSharpLib.Entities.Events.Server.JoinChannel)e.Event;
                State.AddCharacterInChannel(jchEvent.channel, jchEvent.character.identity);
                break;

            case nameof(FChatSharpLib.Entities.Events.Server.InitialChannelData):
                var ichEvent = (FChatSharpLib.Entities.Events.Server.InitialChannelData)e.Event;
                foreach (var character in ichEvent.users)
                {
                    State.AddCharacterInChannel(ichEvent.channel, character.identity);
                }
                break;

            case nameof(FChatSharpLib.Entities.Events.Server.ConnectedUsers):
                var conEvent = (FChatSharpLib.Entities.Events.Server.ConnectedUsers)e.Event;
                State.IsBotReady = true;
                break;

            case nameof(FChatSharpLib.Entities.Events.Server.ListConnectedUsers):
                var listEvent = (FChatSharpLib.Entities.Events.Server.ListConnectedUsers)e.Event;
                foreach (var characterState in listEvent.characters)
                {
                    var existingState = State.CharactersInfos.GetValueOrDefault(characterState.Character.ToLower());
                    if (existingState == null)
                    {
                        State.CharactersInfos.TryAdd(characterState.Character.ToLower(), characterState);
                    }
                    else
                    {
                        existingState.Gender     = characterState.Gender;
                        existingState.Status     = characterState.Status;
                        existingState.StatusText = characterState.StatusText;
                    }
                }
                break;

            case nameof(FChatSharpLib.Entities.Events.Server.StatusChanged):
                var staEvent    = (FChatSharpLib.Entities.Events.Server.StatusChanged)e.Event;
                var charInfoSta = State.CharactersInfos.GetValueOrDefault(staEvent.character.ToLower());
                charInfoSta.Status     = FChatEventParser.GetEnumEquivalent <StatusEnum>(staEvent.status.ToLower());
                charInfoSta.StatusText = charInfoSta.StatusText;
                break;

            case nameof(FChatSharpLib.Entities.Events.Server.OnlineNotification):
                var nlnEvent    = (FChatSharpLib.Entities.Events.Server.OnlineNotification)e.Event;
                var charInfoNln = State.CharactersInfos.GetValueOrDefault(nlnEvent.identity.ToLower());
                if (charInfoNln == null)
                {
                    charInfoNln = new CharacterState()
                    {
                        Character = nlnEvent.identity,
                        Gender    = FChatEventParser.GetEnumEquivalent <GenderEnum>(nlnEvent.gender.ToLower()),
                        Status    = FChatEventParser.GetEnumEquivalent <StatusEnum>(nlnEvent.status.ToLower())
                    };
                    State.CharactersInfos.TryAdd(charInfoNln.Character.ToLower(), charInfoNln);
                }
                break;

            case nameof(FChatSharpLib.Entities.Events.Server.OfflineNotification):
                var flnEvent    = (FChatSharpLib.Entities.Events.Server.OfflineNotification)e.Event;
                var charInfoFln = State.CharactersInfos.Remove(flnEvent.character.ToLower(), out var removedCharacter);
                State.ChannelsInfo.Values.ToList().ForEach(x => x.CharactersInfo.RemoveAll(y => y.Character.ToLower() == flnEvent.character.ToLower()));
                break;

            case nameof(FChatSharpLib.Entities.Events.Server.LeaveChannel):
                var lchEvent = (FChatSharpLib.Entities.Events.Server.LeaveChannel)e.Event;
                State.ChannelsInfo.GetValueOrDefault(lchEvent.channel.ToLower())?.CharactersInfo.RemoveAll(y => y.Character.ToLower() == lchEvent.character.ToLower());
                if (this.IsSelf(lchEvent.character))
                {
                    State.ChannelsInfo.TryRemove(lchEvent.channel.ToLower(), out var x);
                }
                break;

            case nameof(FChatSharpLib.Entities.Events.Server.ChannelOperators):
                var colEvent = (FChatSharpLib.Entities.Events.Server.ChannelOperators)e.Event;
                State.ChannelsInfo.GetValueOrDefault(colEvent.channel.ToLower()).Operators = colEvent.oplist;
                break;

            case nameof(FChatSharpLib.Entities.Events.Server.AddedChanOP):
                var coaEvent = (FChatSharpLib.Entities.Events.Server.AddedChanOP)e.Event;
                State.ChannelsInfo.GetValueOrDefault(coaEvent.channel.ToLower()).Operators.Add(coaEvent.character);
                break;

            case nameof(FChatSharpLib.Entities.Events.Server.RemovedChanOP):
                var corEvent = (FChatSharpLib.Entities.Events.Server.RemovedChanOP)e.Event;
                State.ChannelsInfo.GetValueOrDefault(corEvent.channel.ToLower()).Operators.RemoveAll(x => x == corEvent.character.ToLower());
                break;

            case nameof(FChatSharpLib.Entities.Events.Server.Ping):
                SendPing(null);
                break;

            case nameof(FChatSharpLib.Entities.Events.Server.VariableReceived):
                var varEvent = (FChatSharpLib.Entities.Events.Server.VariableReceived)e.Event;
                switch (varEvent.variable)
                {
                case "msg_flood":
                    Events.SetFloodLimit(double.Parse(varEvent.value, CultureInfo.InvariantCulture));
                    break;

                default:
                    break;
                }
                break;

            default:
                triggered = false;
                break;
            }

            if (triggered)
            {
                DefaultFChatEventHandler.ReceivedStateUpdate?.Invoke(this, new Entities.EventHandlers.ReceivedStateUpdateEventArgs()
                {
                    State = State
                });
            }

            base.Events_ReceivedTriggeringEvent(sender, e);
        }
示例#2
0
        public virtual void Events_ReceivedTriggeringEvent(object sender, Entities.EventHandlers.ReceivedEventEventArgs e)
        {
            switch (e.Event.GetType().Name)
            {
            case nameof(FChatSharpLib.Entities.Events.Server.JoinChannel):
                var jchEvent = (FChatSharpLib.Entities.Events.Server.JoinChannel)e.Event;
                UserJoinedChannel?.Invoke(this, jchEvent);
                break;

            case nameof(FChatSharpLib.Entities.Events.Server.InitialChannelData):
                var ichEvent = (FChatSharpLib.Entities.Events.Server.InitialChannelData)e.Event;
                BotJoinedChannel?.Invoke(this, ichEvent);
                if (numberOfChannelsToTreatAsNewlyCreatedChannel > 0)
                {
                    numberOfChannelsToTreatAsNewlyCreatedChannel--;
                    BotCreatedChannel?.Invoke(this, ichEvent);
                }
                break;

            case nameof(FChatSharpLib.Entities.Events.Server.ConnectedUsers):
                var conEvent = (FChatSharpLib.Entities.Events.Server.ConnectedUsers)e.Event;
                BotConnected?.Invoke(this, new Entities.EventHandlers.ReceivedStateUpdateEventArgs()
                {
                    State = State
                });
                break;

            case nameof(FChatSharpLib.Entities.Events.Server.StatusChanged):
                var staEvent = (FChatSharpLib.Entities.Events.Server.StatusChanged)e.Event;
                UserChangedStatus?.Invoke(this, staEvent);
                break;

            case nameof(FChatSharpLib.Entities.Events.Server.OnlineNotification):
                var nlnEvent = (FChatSharpLib.Entities.Events.Server.OnlineNotification)e.Event;
                UserLoggedOn?.Invoke(this, nlnEvent);
                break;

            case nameof(FChatSharpLib.Entities.Events.Server.OfflineNotification):
                var flnEvent = (FChatSharpLib.Entities.Events.Server.OfflineNotification)e.Event;
                UserLoggedOff?.Invoke(this, flnEvent);
                break;

            case nameof(FChatSharpLib.Entities.Events.Server.LeaveChannel):
                var lchEvent = (FChatSharpLib.Entities.Events.Server.LeaveChannel)e.Event;
                UserLeftChannel?.Invoke(this, lchEvent);
                break;

            case nameof(FChatSharpLib.Entities.Events.Server.AddedChanOP):
                var coaEvent = (FChatSharpLib.Entities.Events.Server.AddedChanOP)e.Event;
                AddedOPInChannel?.Invoke(this, coaEvent);
                break;

            case nameof(FChatSharpLib.Entities.Events.Server.RemovedChanOP):
                var corEvent = (FChatSharpLib.Entities.Events.Server.RemovedChanOP)e.Event;
                RemovedOPInChannel?.Invoke(this, corEvent);
                break;

            case nameof(Entities.Events.Server.RollResult):
                var rllEvent = (FChatSharpLib.Entities.Events.Server.RollResult)e.Event;
                RollResultReceived?.Invoke(this, rllEvent);
                break;

            case nameof(Entities.Events.Server.Message):
                var msgEvent = (FChatSharpLib.Entities.Events.Server.Message)e.Event;
                ChannelMessageReceived?.Invoke(this, msgEvent);
                break;

            case nameof(Entities.Events.Server.PrivateMessage):
                var prvEvent = (FChatSharpLib.Entities.Events.Server.PrivateMessage)e.Event;
                PrivateMessageReceived?.Invoke(this, prvEvent);
                break;

            default:
                break;
            }
        }