47 lines
1.5 KiB
Lua
47 lines
1.5 KiB
Lua
local Players = game:GetService("Players")
|
|
local DataStoreService = game:GetService("DataStoreService")
|
|
local DataStore = DataStoreService:GetDataStore("bannedUsers")
|
|
local HttpService = game:GetService("HttpService")
|
|
local banMsg = "NOTICE\nYou have been banned from this game. If you believe this is a mistake, please contact the game owner."
|
|
local apiBase = "https://bans.kcadev.org/"
|
|
|
|
-- Function to check the player's user ID on join
|
|
local function onPlayerAdded(player)
|
|
local userId = player.UserId
|
|
-- ask the api if the user id is banned, if it times out in 5 seconds, check the datastore, if they aren't in the datastore assume they aren't banned
|
|
local success, response = pcall(function()
|
|
return HttpService:GetAsync(apiBase .. "api/v1/check/" .. tostring(game.PlaceId) .. "/" .. tostring(userId), true)
|
|
end)
|
|
|
|
local banned = false
|
|
local reason = "No reason provided"
|
|
|
|
if success then
|
|
local data = HttpService:JSONDecode(response)
|
|
if data.banned then
|
|
banned = true
|
|
reason = data.reason
|
|
DataStore:SetAsync(userId, reason)
|
|
end
|
|
else
|
|
local success, response = pcall(function()
|
|
return DataStore:GetAsync(userId)
|
|
end)
|
|
|
|
if success then
|
|
if response then
|
|
banned = true
|
|
reason = response
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Check if the user ID is in the bannedPlayers table
|
|
if banned then
|
|
local text = "\n" .. banMsg .. "\nReason: " .. reason;
|
|
player:Kick(text)
|
|
end
|
|
end
|
|
|
|
-- Connect the function to the PlayerAdded event
|
|
Players.PlayerAdded:Connect(onPlayerAdded) |