public override void OnMessage(object sender, ResponseMessage e) { if (Debug) { Console.WriteLine(e.Text); } FChatEventParser.HandleSpecialEvents(e.Text, DefaultFChatEventHandler.ReceivedFChatEvent, DefaultFChatEventHandler.ReceivedChatCommand); }
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); }