Beispiel #1
0
        public async Task Async(string csv, ReadRowEnding expected, string valueSep = ",")
        {
            var opts = Options.CreateBuilder(Options.Default).WithReadRowEnding(ReadRowEnding.Detect).WithValueSeparator(valueSep).BuildInternal();

            await RunAsyncReaderVariants <_Test>(
                opts,
                async (config, getReader) =>
            {
                var configForced = config as AsyncCountingAndForcingConfig <_Test>;
                var configCancel = config as AsyncCancelControlConfig <_Test>;
                var cInner       = (ConcreteBoundConfiguration <_Test>)(configForced?.Inner ?? configCancel?.Inner ?? config);

                await using (var str = await getReader(csv))
                {
                    var stateMachine = new ReaderStateMachine();
                    var charLookup   = CharacterLookup.MakeCharacterLookup(cInner.Options, out _);
                    using (var detector = new RowEndingDetector(stateMachine, cInner.Options, MemoryPool <char> .Shared, charLookup, str, cInner.Options.ValueSeparator.AsMemory()))
                    {
                        if (configForced != null)
                        {
                            configForced.Set(detector);
                        }

                        var detect = await detector.DetectAsync(CancellationToken.None);
                        Assert.True(detect.HasValue);
                        Assert.Equal(expected, detect.Value.Ending);
                    }
                }
            },
                cancellable : false
                );
        }
Beispiel #2
0
        public void CommentsAsFirstRecord(string csv, ReadRowEnding expected)
        {
            Assert.StartsWith("#", csv);

            var config =
                (ConcreteBoundConfiguration <_Test>)
                Configuration.For <_Test>(
                    Options.CreateBuilder(Options.Default)
                    .WithReadRowEnding(ReadRowEnding.Detect)
                    .WithCommentCharacter('#')
                    .WithValueSeparator(",")
                    .BuildInternal()
                    );

            using (var str = new StringReader(csv))
            {
                var charLookup = CharacterLookup.MakeCharacterLookup(config.Options, out _);
                {
                    var detector = new RowEndingDetector(new ReaderStateMachine(), config.Options, MemoryPool <char> .Shared, charLookup, new TextReaderAdapter(str), config.Options.ValueSeparator.AsMemory());
                    var detect   = detector.Detect();
                    Assert.True(detect.HasValue);
                    Assert.Equal(expected, detect.Value.Ending);
                }
            }
        }
Beispiel #3
0
        public CensusEventService(DiscordSocketClient client, CharacterLookup lookup, IDbService db)
        {
            _client = client;
            _db     = db;
            _lookup = lookup;

            _cemUnverifiedMembers = new List <ulong>();
        }
Beispiel #4
0
        public IActionResult PostProfile([FromBody] CharacterLookup character)
        {
            Profile ProfileFactory() => _raiderIo.Get(character.region, character.realm, character.name, "gear", "mythic_plus_scores", "mythic_plus_best_runs:all");

            var profile = _cache.GetOrAdd($"{character.region}/{character.realm}/{character.name}", ProfileFactory, _cacheExpiration());

            return(Ok(profile));
        }
Beispiel #5
0
 /// <summary>
 /// Checks string for any characters that are not registered with <see cref="CharacterLookup"/>
 /// </summary>
 /// <param name="lookup"></param>
 /// <param name="str">The string to check.</param>
 /// <returns>Returns true if all characters in <paramref name="str"/> are registered in the <see cref="CharacterLookup"/></returns>
 public static bool PassesCharacterCheck(this CharacterLookup lookup, string str)
 {
     foreach (var c in str)
     {
         if (!lookup.Value[c])
         {
             return(false);
         }
     }
     return(true);
 }
Beispiel #6
0
        /// <summary>
        /// Checks the <paramref name="str"/> for characters that are not registered as true in the <see cref="CharacterLookup"/>
        /// </summary>
        /// <param name="lookup"></param>
        /// <param name="str">The string to check.</param>
        /// <returns>List of characters in the string that were registered as false</returns>
        public static IEnumerable <char> UnregisteredCharactersFromString(this CharacterLookup lookup, string str)
        {
            var result = new List <char>();

            foreach (var c in str)
            {
                if (!lookup.Value[c])
                {
                    result.Add(c);
                }
            }
            return(result.Distinct());
        }
        public override void Draw()
        {
            ClearPixels();

            if (gameEnded)
            {
                SetPixels(PixelColor.GetSingleColorMap(Program.TableWidth, Program.TableHeight, players[winnerId].GetColor(0.5f)));

                char[] curChar = Convert.ToString((long)CharacterLookup.GetCharUlong((winnerId + 1).ToString()[0]), 2).ToCharArray();
                Array.Reverse(curChar);
                for (int y = 0; y < CharacterLookup.characterHeight; y++)
                {
                    for (int x = 0; x < CharacterLookup.characterWidth; x++)
                    {
                        int index = x + (y * CharacterLookup.characterWidth);
                        if (curChar.Length > index && curChar[index] == '1')
                        {
                            SetPixel(x + 2, y + 1, PixelColor.WHITE);
                        }
                    }
                }

                gameOverScreenTime += updateSpeed;
                if (gameOverScreenTime > 5000)
                {
                    Close();
                }

                return;
            }

            for (int i = 0; i < players.Length; i++)
            {
                players[i].Update();
                SetPixel(players[i].GetPosition(), players[i].color);
            }

            foreach (Projectile p in projectiles)
            {
                p.Update();
                SetPixel(p.position, PixelColor.RED);

                for (int i = 0; i < players.Length; i++)
                {
                    if (p.position.IsTheSame(players[i].GetPosition()))
                    {
                        players[i].Kill(this);
                    }
                }
            }
        }
Beispiel #8
0
        public NecServer(NecSetting setting)
        {
            _running = false;
            Setting  = new NecSetting(setting);

            NecromancyBot = new NecromancyBot(setting);
            NecromancyBot.AddSingleton(this);

            Instances         = new InstanceGenerator();
            Instances64       = new InstanceGenerator64();
            Clients           = new ClientLookup();
            Characters        = new CharacterLookup();
            Maps              = new MapLookup();
            Chat              = new ChatManager(this);
            Router            = new PacketRouter();
            Database          = new NecDatabaseBuilder().Build(Setting.DatabaseSettings);
            SettingRepository = new SettingRepository(Setting.RepositoryFolder).Initialize();
            _authConsumer     = new NecQueueConsumer(ServerType.Auth, Setting, Setting.AuthSocketSettings);
            _authConsumer.ClientDisconnected += AuthClientDisconnected;
            _msgConsumer = new NecQueueConsumer(ServerType.Msg, Setting, Setting.MsgSocketSettings);
            _msgConsumer.ClientDisconnected += MsgClientDisconnected;
            _areaConsumer = new NecQueueConsumer(ServerType.Area, Setting, Setting.AreaSocketSettings);
            _areaConsumer.ClientDisconnected += AreaClientDisconnected;

            _authServer = new AsyncEventServer(
                Setting.ListenIpAddress,
                Setting.AuthPort,
                _authConsumer,
                Setting.AuthSocketSettings
                );

            _msgServer = new AsyncEventServer(
                Setting.ListenIpAddress,
                Setting.MsgPort,
                _msgConsumer,
                Setting.MsgSocketSettings
                );

            _areaServer = new AsyncEventServer(
                Setting.ListenIpAddress,
                Setting.AreaPort,
                _areaConsumer,
                Setting.AreaSocketSettings
                );

            LoadChatCommands();
            LoadSettingRepository();
            LoadHandler();
            LoadCharacterRepository();
        }
Beispiel #9
0
        /// <summary>
        /// Removes all characters marked as false from string
        /// </summary>
        /// <param name="lookup"></param>
        /// <param name="str"></param>
        /// <returns></returns>
        public static string CleanString(this CharacterLookup lookup, string str)
        {
            char[] buffer = new char[str.Length];
            int    index  = 0;

            foreach (char c in str)
            {
                if (lookup.Value[c])
                {
                    buffer[index] = c;
                    index++;
                }
            }
            return(new string(buffer, 0, index));
        }
Beispiel #10
0
        public override void Draw()
        {
            ClearPixels();

            for (int i = 0; i < text.Length; i++)
            {
                char[] curChar = Convert.ToString((long)CharacterLookup.GetCharUlong(text[i]), 2).ToCharArray();
                Array.Reverse(curChar);
                for (int y = 0; y < CharacterLookup.characterHeight; y++)
                {
                    for (int x = 0; x < CharacterLookup.characterWidth; x++)
                    {
                        int index = x + (y * CharacterLookup.characterWidth);
                        if (curChar.Length > index && curChar[index] == '1')
                        {
                            SetPixel(x + scrollPosition + i * 7, y + 1, GetColor(index, x, y));
                        }
                    }
                }
            }

            colorFade += 0.01;

            if (nextScroll > scrollSpeed)
            {
                nextScroll = 0;

                scrollPosition -= 1;
                if (scrollPosition < text.Length * -7)
                {
                    scrollPosition = 9;
                }
            }
            else
            {
                nextScroll++;
            }
        }
Beispiel #11
0
        private static async Task HandlerAddAsync(DiscordSocketClient client, IDbService db, CharacterLookup lodestone, Cacheable <IUserMessage, ulong> message, Cacheable <IMessageChannel, ulong> cchannel, SocketReaction reaction)
        {
            var ichannel = await cchannel.GetOrDownloadAsync();

            if (ichannel is SocketGuildChannel channel)
            {
                var guild  = channel.Guild;
                var member = guild.GetUser(reaction.UserId) ?? (IGuildUser)await client.Rest.GetGuildUserAsync(guild.Id, reaction.UserId);

                var disConfig = db.Guilds.FirstOrDefault(g => g.Id == guild.Id);
                if (disConfig == null)
                {
                    return;
                }
                if (ichannel.Id == 590757405927669769 && reaction.Emote is Emote emote && disConfig.RoleEmotes.TryGetValue(emote.Id.ToString(), out var roleIdString))
                {
                    var roleId  = ulong.Parse(roleIdString);
                    var role    = member.Guild.GetRole(roleId);
                    var dbEntry = db.Users.FirstOrDefault(u => u.DiscordId == reaction.UserId);

                    if (roleId is BozjaRole or EurekaRole)
                    {
                        if (dbEntry == null)
                        {
                            await member.SendMessageAsync("You are not currently registered in the system (potential data loss).\n" +
                                                          "Please register again in `#welcome` before adding one of these roles.");

                            Log.Information("User {User} tried to get a content role and is not registered.");
                            return;
                        }

                        if (!CrystalWorlds.List.Contains(dbEntry.World))
                        {
                            await member.SendMessageAsync("Characters outside of Crystal (see <https://na.finalfantasyxiv.com/lodestone/worldstatus/>) may not access our scheduling tools.");

                            return;
                        }

                        var data = await lodestone.GetCharacter(ulong.Parse(dbEntry.LodestoneId));

                        var highestCombatLevel = 0;
                        foreach (var classJob in data["ClassJobs"].ToObject <CharacterLookup.ClassJob[]>())
                        {
                            // Skip non-DoW/DoM or BLU
                            if (classJob.JobID is >= 8 and <= 18 or 36)
                            {
                                continue;
                            }
                            if (classJob.Level > highestCombatLevel)
                            {
                                highestCombatLevel = classJob.Level;
                            }
                        }

                        if (roleId == BozjaRole && highestCombatLevel < 80)
                        {
                            await member.SendMessageAsync("You must be at least level 80 to access that category.");

                            return;
                        }

                        if (roleId == EurekaRole && highestCombatLevel < 70)
                        {
                            await member.SendMessageAsync("You must be at least level 70 to access that category.");

                            return;
                        }

                        // 60 is already the minimum requirement to register.

                        await member.AddRoleAsync(role);

                        Log.Information("Role {Role} was added to {DiscordUser}", role.Name, member.ToString());
                    }
                }
                else if (guild.Id == 550702475112480769 && ichannel.Id is 552643167808258060 or 768886934084648960 && reaction.Emote.Name == "✅")
                {
                    await member.SendMessageAsync($"You have begun the verification process. Your **Discord account ID** is `{member.Id}`.\n"
                                                  + "Please add this somewhere in your FFXIV Lodestone Character Profile.\n"
                                                  + "You can edit your account description here: https://na.finalfantasyxiv.com/lodestone/my/setting/profile/\n\n"
                                                  + $"After you have put your Discord account ID in your Lodestone profile, please use `{db.Config.Prefix}verify` to get your clear role.\n"
                                                  + "The Lodestone may not immediately update following updates to your achievements, so please wait a few hours and try again if this is the case.");
                }
            }
Beispiel #12
0
 public static Task HandlerAdd(DiscordSocketClient client, IDbService db, CharacterLookup lodestone, Cacheable <IUserMessage, ulong> message, Cacheable <IMessageChannel, ulong> cchannel, SocketReaction reaction)
 {
     Task.Run(() => HandlerAddAsync(client, db, lodestone, message, cchannel, reaction));
     return(Task.CompletedTask);
 }
Beispiel #13
0
 public UnitTests(IServiceProvider serviceProvider, ITestOutputHelper outputHelper, CharacterLookup characterLookup)
 {
     this.serviceProvider = serviceProvider;
     this.outputHelper    = outputHelper;
     this.characterLookup = characterLookup;
 }
        public override void Draw()
        {
            ClearPixels();
            DateTime now    = DateTime.Now;
            int      second = now.Second;
            int      minute = now.Minute;
            int      hour   = now.Hour;

            if (toggleTime < 50)
            {
                //Hour
                char[] curChar = Convert.ToString((long)CharacterLookup.GetCharUlong((hour).ToString()[0]), 2).ToCharArray();
                Array.Reverse(curChar);
                for (int y = 0; y < CharacterLookup.characterHeight; y++)
                {
                    for (int x = 0; x < CharacterLookup.characterWidth; x++)
                    {
                        int index = x + (y * CharacterLookup.characterWidth);
                        if (curChar.Length > index && curChar[index] == '1')
                        {
                            SetPixel(x - 1, y + 1, PixelColor.YELLOW);
                        }
                    }
                }

                curChar = Convert.ToString((long)CharacterLookup.GetCharUlong((hour).ToString()[0]), 2).ToCharArray();
                Array.Reverse(curChar);
                for (int y = 0; y < CharacterLookup.characterHeight; y++)
                {
                    for (int x = 0; x < CharacterLookup.characterWidth; x++)
                    {
                        int index = x + (y * CharacterLookup.characterWidth);
                        if (curChar.Length > index && curChar[index] == '1')
                        {
                            SetPixel(x + 4, y + 1, PixelColor.YELLOW);
                        }
                    }
                }
            }
            else
            {
                //Minute
                for (int i = 0; i < minute; i++)
                {
                    SetPixelAtTime(i, PixelColor.WHITE);
                }

                //Second
                if (secondBlink)
                {
                    SetPixelAtTime(second, PixelColor.RED);
                }
                secondBlink = !secondBlink;
            }

            if (toggleTime > 100)
            {
                toggleTime = 0;
            }
            toggleTime++;
        }