public List <Page> CreateOpProfilePages(OpProfile op)
        {
            string      img   = $"{s3.Url}avatars/{op.OperatorCode}.png";
            List <Page> pages = new List <Page>();

            if (op.BasicFile != null)
            {
                DiscordEmbed embed = new DiscordEmbedBuilder()
                                     .WithTitle($"[{op.Rarity}★] {op.Name} - Basic File ")
                                     .WithThumbnail(img, 60, 60)
                                     .WithDescription($"{Formatter.Bold("CV:")} {op.Cv}\n" +
                                                      $"{Formatter.Bold("Artist:")} {op.Artist}\n" +
                                                      $"{Formatter.Bold("Code Name:")} {op.BasicFile.CodeName}\n" +
                                                      $"{Formatter.Bold("Gender:")} {op.BasicFile.Gender}\n" +
                                                      $"{Formatter.Bold("Combat Experience:")} {op.BasicFile.CombatExperience}\n" +
                                                      $"{Formatter.Bold("Place of Birth:")} {op.BasicFile.PlaceOfBirth}\n" +
                                                      $"{Formatter.Bold("Date of Birth:")} {op.BasicFile.DateOfBirth}\n" +
                                                      $"{Formatter.Bold("Race:")} {op.BasicFile.Race}\n" +
                                                      $"{Formatter.Bold("Height:")} {op.BasicFile.Height}\n" +
                                                      $"{Formatter.Bold("Infection Status:")} {op.BasicFile.InfectionStatus}\n")
                                     .Build();
                pages.Add(new Page {
                    Embed = embed
                });
            }
            if (op.PhysicalExam != null)
            {
                DiscordEmbed embed = new DiscordEmbedBuilder()
                                     .WithTitle($"[{op.Rarity}★] {op.Name} - Physical Exam")
                                     .WithThumbnail(img, 60, 60)
                                     .WithDescription($"{Formatter.Bold("Physical Strength:")} {op.PhysicalExam.PhysicalStrength}\n" +
                                                      $"{Formatter.Bold("Mobility:")} {op.PhysicalExam.Mobility}\n" +
                                                      $"{Formatter.Bold("Physical Resilience:")} {op.PhysicalExam.PhysicalResilience}\n" +
                                                      $"{Formatter.Bold("Tactical Acumen:")} {op.PhysicalExam.TacticalAcumen}\n" +
                                                      $"{Formatter.Bold("Combat Skill:")} {op.PhysicalExam.CombatSkill}\n" +
                                                      $"{Formatter.Bold("Originium Adaptability:")} {op.PhysicalExam.TacticalAcumen}\n")
                                     .Build();
                pages.Add(new Page {
                    Embed = embed
                });
            }
            if (op.Profiles != null && op.Profiles.Any())
            {
                foreach (Profile p in op.Profiles)
                {
                    DiscordEmbed embed = new DiscordEmbedBuilder()
                                         .WithTitle($"[{op.Rarity}★] {op.Name} - {p.Title}")
                                         .WithThumbnail(img, 60, 60)
                                         .WithDescription($"{p.Text}")
                                         .Build();
                    pages.Add(new Page {
                        Embed = embed
                    });
                }
            }
            return(pages);
        }
        public async Task GetOpeatorFiles(CommandContext ctx, [Description("Operator's name")] string name)
        {
            try
            {
                OpProfile op = await operatorService.GetOperatorProfile(name);

                if (op is null)
                {
                    await ctx.RespondAsync("Operator not found.");
                }
                var         itr   = ctx.Client.GetInteractivity();
                List <Page> pages = embedService.CreateOpProfilePages(op);
                await itr.SendPaginatedMessageAsync(ctx.Channel, ctx.User, pages, timeoutoverride : TimeSpan.FromMinutes(5));
            }
            catch (Exception e)
            {
                await ctx.RespondAsync($"An error occurred:{e.Message}");
            }
        }
Exemple #3
0
        void Profile_Update(OpProfile profile)
        {
            // if self or in uplink chain, update profile
            List<ulong> uplinks = new List<ulong>();
            uplinks.Add(UserID);
            uplinks.AddRange(Core.Trust.GetUplinkIDs(UserID, ProjectID));

            if (!uplinks.Contains(profile.UserID))
                return;

            // get fields from profile

            // if temp/id dir exists use it
            // clear temp/id dir
            // extract files to temp dir

            // get html
            // insert fields into html

            // display

            string tempPath = Profiles.ExtractPath;

            // create if needed, clear of pre-existing data
            if (!Directory.Exists(tempPath))
                Directory.CreateDirectory(tempPath);

            // get the profile for this display
            profile = Profiles.GetProfile(UserID);

            if (profile == null)
                return;

            // not secure
            else
            {
                string[] files = Directory.GetFiles(tempPath);

                foreach (string path in files)
                    File.Delete(path);
            }

            string template = LoadProfile(Profiles, profile, tempPath, TextFields, FileFields);

            if (template == null)
            {
                template = @"<html>
                            <body>
                                <table width=""100%"" height=""100%"">
                                    <tr valign=""middle"">
                                        <td align=""center"">
                                        <b>Unable to Load</b>
                                        </td>
                                    </tr>
                                </table>
                            </body>
                        </html>";
            }

            string html = FleshTemplate(Profiles, profile.UserID, ProjectID, template, TextFields, FileFields);

            Browser.SetDocNoClick(html);
        }
Exemple #4
0
        private static string LoadProfile(ProfileService service, OpProfile profile, string tempPath, Dictionary<string, string> textFields, Dictionary<string, string> fileFields)
        {
            string template = null;

            textFields.Clear();
            textFields["local_help"] = (profile.UserID == service.Core.UserID) ? "<font size=2>Right-click or click <a href='http://edit'>here</a> to Edit</font>" : "";

            if(fileFields != null)
                fileFields.Clear();

            if (!profile.Loaded)
                service.LoadProfile(profile.UserID);

            try
            {
                using (TaggedStream stream = new TaggedStream(service.GetFilePath(profile), service.Core.GuiProtocol))
                using (IVCryptoStream crypto = IVCryptoStream.Load(stream, profile.File.Header.FileKey))
                {
                    int buffSize = 4096;
                    byte[] buffer = new byte[4096];
                    long bytesLeft = profile.EmbeddedStart;
                    while (bytesLeft > 0)
                    {
                        int readSize = (bytesLeft > (long)buffSize) ? buffSize : (int)bytesLeft;
                        int read = crypto.Read(buffer, 0, readSize);
                        bytesLeft -= (long)read;
                    }

                    // load file
                    foreach (ProfileAttachment attached in profile.Attached)
                    {
                        if (attached.Name.StartsWith("template"))
                        {
                            byte[] html = new byte[attached.Size];
                            crypto.Read(html, 0, (int)attached.Size);

                            UTF8Encoding utf = new UTF8Encoding();
                            template = utf.GetString(html);
                        }

                        else if (attached.Name.StartsWith("fields"))
                        {
                            byte[] data = new byte[attached.Size];
                            crypto.Read(data, 0, (int)attached.Size);

                            int start = 0, length = data.Length;
                            G2ReadResult streamStatus = G2ReadResult.PACKET_GOOD;

                            while (streamStatus == G2ReadResult.PACKET_GOOD)
                            {
                                G2ReceivedPacket packet = new G2ReceivedPacket();
                                packet.Root = new G2Header(data);

                                streamStatus = G2Protocol.ReadNextPacket(packet.Root, ref start, ref length);

                                if (streamStatus != G2ReadResult.PACKET_GOOD)
                                    break;

                                if (packet.Root.Name == ProfilePacket.Field)
                                {
                                    ProfileField field = ProfileField.Decode(packet.Root);

                                    if (field.Value == null)
                                        continue;

                                    if (field.FieldType == ProfileFieldType.Text)
                                        textFields[field.Name] = UTF8Encoding.UTF8.GetString(field.Value);
                                    else if (field.FieldType == ProfileFieldType.File && fileFields != null)
                                        fileFields[field.Name] = UTF8Encoding.UTF8.GetString(field.Value);
                                }
                            }
                        }

                        else if (attached.Name.StartsWith("file=") && fileFields != null)
                        {
                            string name = attached.Name.Substring(5);

                            try
                            {
                                string fileKey = null;
                                foreach (string key in fileFields.Keys)
                                    if (name == fileFields[key])
                                    {
                                        fileKey = key;
                                        break;
                                    }

                                fileFields[fileKey] = tempPath + Path.DirectorySeparatorChar + name;

                                using (FileStream extract = new FileStream(fileFields[fileKey], FileMode.CreateNew, FileAccess.Write))
                                {
                                    long remaining = attached.Size;
                                    byte[] buff = new byte[2096];

                                    while (remaining > 0)
                                    {
                                        int read = (remaining > 2096) ? 2096 : (int)remaining;
                                        remaining -= read;

                                        crypto.Read(buff, 0, read);
                                        extract.Write(buff, 0, read);
                                    }
                                }
                            }
                            catch
                            { }
                        }
                    }
                }
            }
            catch (Exception)
            {
            }

            return template;
        }