Ejemplo n.º 1
0
        private void SendReport(IPlayer reporter, IPlayer suspect, string subject, string message)
        {
            var authorIconURL = string.Empty;
            var author        = _config.IsReporterIcon ? reporter : suspect;

            if (_config.AuthorIcon)
            {
                authorIconURL = PluginData.UserCache.Find(author.Id)?.ImageURL ?? string.Empty;
                UpdateCachedImage(author); // Won't get update now but will be for any other reports for this user
            }

            const string type = "rich";
            var          body = new WebhookBody
            {
                Embeds = new[]
                {
                    new EmbedBody
                    {
                        Title       = _config.EmbedTitle,
                        Description = _config.EmbedDescription,
                        Type        = type,
                        Color       = _config.EmbedColor,
                        Author      = new EmbedBody.AuthorBody
                        {
                            AuthorIconURL = authorIconURL,
                            AuthorURL     = string.Format(SteamProfile, author.Id),
                            Name          = author.Name
                        },
                        Fields = new[]
                        {
                            new EmbedBody.FieldBody
                            {
                                Name   = GetMsg("Webhook: Report Subject"),
                                Value  = subject,
                                Inline = false
                            },
                            new EmbedBody.FieldBody
                            {
                                Name  = GetMsg("Webhook: Report Message"),
                                Value = string.IsNullOrEmpty(message)
                                    ? GetMsg("Webhook: Report Message If Empty")
                                    : message,
                                Inline = false
                            },
                            new EmbedBody.FieldBody
                            {
                                Name  = GetMsg("Webhook: Reporter Data Title"),
                                Value =
                                    FormatUserDetails(new StringBuilder(GetMsg("Webhook: Reporter Data")), reporter),
                                Inline = false
                            },
                            new EmbedBody.FieldBody
                            {
                                Name   = GetMsg("Webhook: Suspect Data Title"),
                                Value  = FormatUserDetails(new StringBuilder(GetMsg("Webhook: Suspect Data")), suspect),
                                Inline = false
                            }
                        }
                    }
                }
            };

            #if RUST
            if (_config.ShowCombatlog && suspect.Object is BasePlayer)
            {
                var events = CombatLog.Get(((BasePlayer)suspect.Object).userID).ToArray();
                for (var i = 1; i <= _config.CombatlogEntries && i <= events.Length; i++)
                {
                    var combat = events[events.Length - i];

                    Array.Resize(ref body.Embeds, 1 + i);
                    body.Embeds[i] = new EmbedBody
                    {
                        Title  = GetMsg("Webhook: Combatlog Title").Replace("{n}", $"{i}"),
                        Type   = type,
                        Color  = _config.EmbedColor,
                        Fields = new[]
                        {
                            new EmbedBody.FieldBody
                            {
                                Name   = GetMsg("Webhook: Combatlog Attacker Title"),
                                Value  = combat.attacker,
                                Inline = true
                            },
                            new EmbedBody.FieldBody
                            {
                                Name   = GetMsg("Webhook: Combatlog Target Title"),
                                Value  = combat.target,
                                Inline = true
                            },
                            new EmbedBody.FieldBody
                            {
                                Name   = GetMsg("Webhook: Combatlog Time Title"),
                                Value  = (UnityEngine.Time.realtimeSinceStartup - combat.time).ToString("0.0s"),
                                Inline = true
                            },
                            new EmbedBody.FieldBody
                            {
                                Name   = GetMsg("Webhook: Combatlog Weapon Title"),
                                Value  = combat.weapon,
                                Inline = true
                            },
                            new EmbedBody.FieldBody
                            {
                                Name   = GetMsg("Webhook: Combatlog Ammo Title"),
                                Value  = combat.ammo,
                                Inline = true
                            },
                            new EmbedBody.FieldBody
                            {
                                Name   = GetMsg("Webhook: Combatlog Distance Title"),
                                Value  = combat.distance.ToString("0.0m"),
                                Inline = true
                            },
                            new EmbedBody.FieldBody
                            {
                                Name   = GetMsg("Webhook: Combatlog Old HP Title"),
                                Value  = combat.health_old.ToString("0.0"),
                                Inline = true
                            },
                            new EmbedBody.FieldBody
                            {
                                Name   = GetMsg("Webhook: Combatlog New HP Title"),
                                Value  = combat.health_new.ToString("0.0"),
                                Inline = true
                            },
                            new EmbedBody.FieldBody
                            {
                                Name   = GetMsg("Webhook: Combatlog Info Title"),
                                Value  = string.IsNullOrEmpty(combat.info) ? "none" : combat.info,
                                Inline = true
                            }
                        }
                    };
                }
            }
            #endif

            webrequest.Enqueue(_config.Webhook, JObject.FromObject(body).ToString(),
                               (code, result) => SetCooldown(reporter), this, RequestMethod.POST,
                               new Dictionary <string, string> {
                { "Content-Type", "application/json" }
            });
        }
Ejemplo n.º 2
0
        string GetCombatLog(ulong steamid, int count)
        {
            var storage = CombatLog.Get(steamid);

            TextTable textTable = new TextTable();

            textTable.AddColumn("time");
            textTable.AddColumn("attacker");
            textTable.AddColumn("id");
            textTable.AddColumn("target");
            textTable.AddColumn("id");
            textTable.AddColumn("weapon");
            textTable.AddColumn("ammo");
            textTable.AddColumn("area");
            textTable.AddColumn("distance");
            textTable.AddColumn("old_hp");
            textTable.AddColumn("new_hp");
            textTable.AddColumn("info");

            int num  = storage.Count - count;
            int num1 = ConVar.Server.combatlogdelay;
            int num2 = 0;

            foreach (CombatLog.Event evt in storage)
            {
                if (num <= 0)
                {
                    float single = Time.realtimeSinceStartup - evt.time;
                    if (single < (float)num1)
                    {
                        num2++;
                    }
                    else
                    {
                        string str  = single.ToString("0.0s");
                        string str1 = evt.attacker == "you" ? GetNameFromId(steamid.ToString()) : evt.attacker;

                        string str2 = storedData.Players.ContainsKey((uint)evt.attacker_id) ? GetNameFromId(storedData.Players[(uint)evt.attacker_id].ToString()) : evt.attacker_id.ToString();

                        string str3 = evt.target == "you" ? GetNameFromId(steamid.ToString()) : evt.target;

                        string str4 = storedData.Players.ContainsKey((uint)evt.target_id) ? GetNameFromId(storedData.Players[(uint)evt.target_id].ToString()) : evt.target_id.ToString();

                        string str5  = evt.weapon;
                        string str6  = evt.ammo;
                        string lower = HitAreaUtil.Format(evt.area).ToLower();
                        string str7  = evt.distance.ToString("0.0m");
                        string str8  = evt.health_old.ToString("0.0");
                        string str9  = evt.health_new.ToString("0.0");
                        string str10 = evt.info;
                        textTable.AddRow(new string[] { str, str1, str2, str3, str4, str5, str6, lower, str7, str8, str9, str10 });
                    }
                }
                else
                {
                    num--;
                }
            }

            string str11 = textTable.ToString();

            if (num2 > 0)
            {
                string   str12    = str11;
                object[] objArray = new object[] { str12, "+ ", num2, " ", null };
                objArray[4] = (num2 <= 1 ? "event" : "events");
                str11       = string.Concat(objArray);
                str12       = str11;
                object[] objArray1 = new object[] { str12, " in the last ", num1, " ", null };
                objArray1[4] = (num1 <= 1 ? "second" : "seconds");
                str11        = string.Concat(objArray1);
            }
            return(str11);
        }
Ejemplo n.º 3
0
 public void Init()
 {
     this.storage = CombatLog.Get(this.player.userID);
 }