Esempio n. 1
0
        private void NotifyDiscord(Configuration.Limit limit, BaseNetworkable entity, BasePlayer player)
        {
            var discord = limit.Webhook;

            if (string.IsNullOrEmpty(discord.Webhook) || DiscordMessages == null || !DiscordMessages.IsLoaded)
            {
                return;
            }

            object fields = new[]
            {
                new
                {
                    name  = discord.PlayerTitle,
                    value = discord.Player.Replace("{name}", player?.displayName ?? "Unknown")
                            .Replace("{id}", player?.UserIDString ?? "0"),
                    inline = discord.Inline
                },
                new
                {
                    name  = discord.EntityTitle,
                    value = discord.Entity.Replace("{shortname}", entity.ShortPrefabName)
                            .Replace("{id}", entity.net.ID.ToString()).Replace("{type}", limit.Name),
                    inline = discord.Inline
                },
                new
                {
                    name   = discord.PositionTitle,
                    value  = discord.Position.Replace("{position}", FormattedCoordinates(entity.transform.position)),
                    inline = discord.Inline
                }
            };

            DiscordMessages.CallHook("API_SendFancyMessage", discord.Webhook, discord.Title, discord.Color, JsonConvert.SerializeObject(fields));
        }
Esempio n. 2
0
        private void NotifyDeauthorize(Configuration.Limit limit, BaseEntity entity, BasePlayer basePlayer)
        {
            if (limit.NotifyPlayer)
            {
                var player = basePlayer?.IPlayer;
                if (player != null && player.IsConnected)
                {
                    player.Message(GetMsg("Notify: Deauthorize Player", player.Id));
                }
            }

            if (limit.NotifyOwner)
            {
                var player = players.FindPlayerById(entity.OwnerID.ToString());
                if (player != null && player.IsConnected)
                {
                    var sb = new StringBuilder(GetMsg("Notify: Deauthorize Owner", player.Id));
                    sb.Replace("{position}", entity.transform.position.ToString());
                    sb.Replace("{type}", limit.Name);
                    sb.Replace("{name}", basePlayer?.displayName ?? "Unknown");

                    player.Message(sb.ToString());
                }
            }

            NotifyLog(limit, entity, basePlayer);
            NotifyDiscord(limit, entity, basePlayer);
        }
Esempio n. 3
0
        private void NotifyLog(Configuration.Limit limit, BaseNetworkable entity, BasePlayer player)
        {
            if (!limit.File)
            {
                return;
            }

            var builder = new StringBuilder(_config.LogFormat);

            builder.Replace("{time}", DateTime.Now.ToLongTimeString());
            builder.Replace("{name}", player?.displayName ?? "Unknown");
            builder.Replace("{id}", player?.UserIDString ?? "0");
            builder.Replace("{shortname}", entity.ShortPrefabName);
            builder.Replace("{entid}", entity.net.ID.ToString());
            builder.Replace("{type}", limit.Name);
            builder.Replace("{position}", FormattedCoordinates(entity.transform.position));

            LogToFile("Log", builder.ToString(), this);
        }