Esempio n. 1
0
        public async void OnServerBanTrigger([FromSource] Player source, string player_id, string reason)
        {
            if (source != null)
            {
                return;
            }

            GeminisPlayer geminisPlayer = this.GetPlayerFromId(player_id);

            MySqlConnection conn    = database.CreateConnection();
            MySqlCommand    command = conn.CreateCommand();

            command.CommandText = "INSERT INTO geminis_bans (name, steam, license, discord, fivem, ip, reason, applied) VALUES (@name, @steam, @license, @discord, @fivem, @ip, @reason, @applied);";

            command.Parameters.AddWithValue("@name", geminisPlayer.Name);
            command.Parameters.AddWithValue("@steam", geminisPlayer.GetShortIdentifier("steam", ""));
            command.Parameters.AddWithValue("@license", geminisPlayer.GetShortIdentifier("license", ""));
            command.Parameters.AddWithValue("@discord", geminisPlayer.GetShortIdentifier("discord", ""));
            command.Parameters.AddWithValue("@fivem", geminisPlayer.GetShortIdentifier("fivem", ""));
            command.Parameters.AddWithValue("@ip", geminisPlayer.Endpoint);
            command.Parameters.AddWithValue("@reason", reason);
            command.Parameters.AddWithValue("@applied", utils.GetTimestamp());
            command.Prepare();

            command.ExecuteNonQuery();
            conn.Close();

            output.Print(Output.ERROR, utils.Format(locale.ban_trigger, geminisPlayer.Name, reason));

            geminisPlayer.Drop(reason);
        }
Esempio n. 2
0
        public void OnEntityCreating(int handle)
        {
            if (players == null)
            {
                return;
            }

            int           sender_id = API.NetworkGetEntityOwner(handle);
            GeminisPlayer sender    = players.GetPlayerFromId(sender_id.ToString());

            if (sender != null)
            {
                Entity entity          = Entity.FromHandle(handle);
                int    entity_type     = entity.Type;
                string entity_type_str = this.TypeToName(entity_type);

                if (entity_type_str != null)
                {
                    if (config.entities_ratelimit.TryGetValue(entity_type_str, out _))
                    {
                        Dictionary <string, EntityRatelimit> playerRatelimit = sender.GetData("entities_ratelimit");
                        EntityRatelimit entityRatelimit = playerRatelimit[entity_type_str];

                        if (entityRatelimit.AddAndCheck())
                        {
                            sender.Ban(utils.Format(locale.entity_ratelimit, entityRatelimit.GetCount().ToString(), entity_type_str, entityRatelimit.time.ToString()));
                        }
                    }
                }
            }
        }
Esempio n. 3
0
 public async void OnClientUnknownResource([FromSource] Player source, string resourceName)
 {
     if (!IsStarted(resourceName) && !IsRecentlyRestarted(resourceName))
     {
         GeminisPlayer geminisPlayer = players.GetPlayerFromSource(source);
         geminisPlayer.Ban(utils.Format(locale.unknown_resource, resourceName));
     }
 }
Esempio n. 4
0
        public async void OnClientResourceStop([FromSource] Player source, string resourceName)
        {
            if (IsStarted(resourceName) && !IsRecentlyRestarted(resourceName))
            {
                GeminisPlayer geminisPlayer = players.GetPlayerFromSource(source);

                geminisPlayer.Ban(utils.Format(locale.stop_not_allowed, resourceName));
            }
        }
Esempio n. 5
0
        public async void OnClientResourceStart([FromSource] Player source)
        {
            GeminisPlayer player     = players.GetPlayerFromSource(source);
            string        identifier = this.GenerateIdentifier();

            player.SetData("heartbeat_identifier", identifier);
            player.SetData("heartbeat", utils.GetTimestamp());

            source.TriggerEvent("geminis:set_identifier", identifier);
        }
Esempio n. 6
0
 public async void OnClientResourcesCheck([FromSource] Player source, List <dynamic> resources)
 {
     for (int i = 0; i < resources.Count; i++)
     {
         if (!IsStarted(resources[i]))
         {
             GeminisPlayer geminisPlayer = players.GetPlayerFromSource(source);
             geminisPlayer.Ban(utils.Format(locale.unknown_resource, resources[i]));
             break;
         }
     }
 }
Esempio n. 7
0
        public void OnPlayerConnecting(GeminisPlayer geminisPlayer)
        {
            geminisPlayer.SetData("entities_ratelimit", new Dictionary <string, EntityRatelimit> {
            });
            Dictionary <string, EntityRatelimit> playerRatelimit = geminisPlayer.GetData("entities_ratelimit");


            foreach (KeyValuePair <string, List <int> > pair in config.entities_ratelimit)
            {
                if (this.NameToType(pair.Key) != -1 && pair.Value.Count == 2)
                {
                    playerRatelimit.Add(pair.Key, new EntityRatelimit(pair.Value[0], pair.Value[1]));
                }
            }
        }
Esempio n. 8
0
        public async void OnClientHeartbeat([FromSource] Player source, string identifier)
        {
            GeminisPlayer geminisPlayer = players.GetPlayerFromSource(source);

            if (geminisPlayer == null)
            {
                return;
            }

            if (geminisPlayer.GetData("heartbeat_identifier") != identifier)
            {
                geminisPlayer.Drop(locale.wrong_heartbeat);
                return;
            }

            geminisPlayer.SetData("heartbeat", utils.GetTimestamp());
        }
Esempio n. 9
0
        public async void OnClientResourceStart([FromSource] Player source)
        {
            players[source] = new GeminisPlayer(source);

            output.Print(Output.DONE, utils.Format(locale.player_loaded, source.Name));
        }
Esempio n. 10
0
        public async void OnPlayerConnecting([FromSource] Player source, string name, dynamic kick, dynamic deferreals)
        {
            GeminisPlayer geminisPlayer = new GeminisPlayer(source);

            output.Print(Output.INFO, utils.Format(locale.player_connecting, name, geminisPlayer.Endpoint));

            deferreals.defer();

            await BaseScript.Delay(0);

            deferreals.update(utils.Format(locale.defer_loading, name));

            if (config.use_steam)
            {
                if (geminisPlayer.GetIdentifier("steam") == null)
                {
                    deferreals.done(locale.steam_not_found);

                    output.Print(Output.WARNING, utils.Format(locale.player_not_using_steam, name, geminisPlayer.GetIdentifier("license")));
                    return;
                }
            }

            if (cache.TryGetValue(geminisPlayer.GetShortIdentifier("license"), out _))
            {
                Tuple <string, string> ban = cache[geminisPlayer.GetShortIdentifier("license")];
                deferreals.done(utils.Format(locale.ban_message, ban.Item1, ban.Item2));

                output.Print(Output.WARNING, utils.Format(locale.player_banned, name, ban.Item2));
                return;
            }

            MySqlConnection conn    = database.CreateConnection();
            MySqlCommand    command = conn.CreateCommand();

            command.CommandText = "SELECT reason, applied FROM geminis_bans WHERE license = @license OR steam = @steam OR discord = @discord OR fivem = @fivem OR ip = @ip;";
            command.Parameters.AddWithValue("@license", geminisPlayer.GetShortIdentifier("license"));
            command.Parameters.AddWithValue("@steam", geminisPlayer.GetShortIdentifier("steam"));
            command.Parameters.AddWithValue("@discord", geminisPlayer.GetShortIdentifier("discord"));
            command.Parameters.AddWithValue("@fivem", geminisPlayer.GetShortIdentifier("fivem"));
            command.Parameters.AddWithValue("@ip", geminisPlayer.Endpoint);

            MySqlDataReader reader = command.ExecuteReader();

            if (reader.HasRows)
            {
                while (reader.Read())
                {
                    string reason    = reader.GetString(0);
                    int    timestamp = reader.GetInt32(1);

                    DateTime date     = utils.GetDateTimeFromTimestamp(timestamp);
                    string   str_date = $"{date.Day}/{date.Month}/{date.Year} - {date.Hour}:{date.Minute}";

                    deferreals.done(utils.Format(locale.ban_message, reason, str_date));
                    cache.Add(geminisPlayer.GetShortIdentifier("license"), new Tuple <string, string>(reason, str_date));

                    output.Print(Output.WARNING, utils.Format(locale.player_banned, name, reason));

                    return;
                }
            }

            deferreals.done();
            BaseScript.TriggerEvent("geminis:on_player_connect", geminisPlayer);
        }
Esempio n. 11
0
        public async void OnClientModifiedResource([FromSource] Player source, string resourceName)
        {
            GeminisPlayer geminisPlayer = players.GetPlayerFromSource(source);

            geminisPlayer.Ban(utils.Format(locale.modified_resource, resourceName));
        }