Menu
CoddyTech

클라이언트를 절대 신뢰하지 마세요

Coddy의 Roblox 게임: 펫 시뮬레이터 코스 레슨. 20개 중 7번째.

플레이어는 자신의 기기를 제어하므로, 악용자는 원하는 만큼 빠르게 어디서든 무엇이든 보내 어떤 원격 이벤트든 실행할 수 있습니다. 맵 반대편에서 Hit:FireServer(pile)을 초당 100번 호출하면 게임의 모든 더미가 비워집니다.

그러므로 서버는 요청을 처리하기 전에 모두 확인합니다:

  • 실제 더미인지 (workspace.Piles 안의 Instance인지),
  • 플레이어가 더미에서 Settings.Reach 이내에 있는지,
  • 그리고 플레이어가 마지막으로 타격한 지 최소 Settings.HitCooldown초가 지났는지.
if typeof(pile) ~= "Instance" or pile.Parent ~= piles then
	return
end

Check를 누르면 테스트에서 악용자가 할 법한 동작을 수행합니다. 작성하는 모든 원격 이벤트의 원칙은 다음과 같습니다. 클라이언트가 요청하고, 서버가 결정합니다.

challenge icon

챌린지

중급

공정한 플레이어라면 할 수 없는 타격을 서버가 거부하도록 하세요.

  1. Hit 처리기의 시작 부분에서, pile이 부모가 piles인 Instance가 아니면 반환하세요.
  2. 플레이어의 HumanoidRootPart가 없거나 더미에서 Settings.Reach 스터드보다 멀리 떨어져 있으면 반환하세요.
  3. local lastHit = {}를 유지하세요. Settings.HitCooldown초보다 짧은 시간 전에 타격했다면 반환하고, 그렇지 않으면 time()을 저장하세요.

‘플레이’를 누르고 멀리서 더미를 클릭하세요. 아무 일도 일어나지 않습니다. 그런 다음 ‘확인’을 누르세요.

직접 해보기

local Players = game:GetService("Players")
local ServerStorage = game:GetService("ServerStorage")
local Settings = require(game.ReplicatedStorage.Settings)

local remotes = game.ReplicatedStorage.Remotes
local piles = workspace.Piles
local pileSpot = {} -- 각 동전 더미 -> 그 더미가 놓인 자리

print("A Meadow pile gives " .. Settings.PileValue .. " coins")

-- 모든 플레이어의 리더보드에 Coins가 추가됩니다
Players.PlayerAdded:Connect(function(player)
	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local coins = Instance.new("IntValue")
	coins.Name = "Coins"
	coins.Parent = leaderstats
end)

-- 자리에 놓인 동전 더미: ServerStorage.CoinPile의 복제본으로, 체력
-- 과 가치를 속성으로 가집니다
local function spawnPile(spot)
	local pile = ServerStorage.CoinPile:Clone()
	pile.Position = spot.Position
	pile:SetAttribute("MaxHealth", Settings.PileHealth)
	pile:SetAttribute("Health", Settings.PileHealth)
	pile:SetAttribute("Value", Settings.PileValue)
	pileSpot[pile] = spot
	pile.Parent = piles
	return pile
end

-- 한 번 공격하면 동전 더미의 체력이 1 감소합니다;
-- 체력이 0이 되면 동전 더미가 부서지고 가치만큼 코인을 지급합니다
local function hitPile(player, pile)
	local health = pile:GetAttribute("Health") - 1
	if health > 0 then
		pile:SetAttribute("Health", health)
		return
	end
	player.leaderstats.Coins.Value += pile:GetAttribute("Value")
	local spot = pileSpot[pile]
	pileSpot[pile] = nil
	pile:Destroy()
	-- 몇 초 후 같은 자리에 새 동전 더미가 생성됩니다
	task.delay(Settings.RespawnTime, spawnPile, spot)
end

-- Meadow의 모든 자리에 동전 더미를 생성합니다
for _, spot in workspace.Zones.Meadow.Spawns:GetChildren() do
	spawnPile(spot)
end

-- 클라이언트가 동전 더미를 공격하도록 요청합니다
remotes.Hit.OnServerEvent:Connect(function(player, pile)
	-- Lesson 7: Never Trust the Client가 여기에 들어갑니다
	hitPile(player, pile)
end)

Roblox 게임: 펫 시뮬레이터의 모든 레슨

직접 연습해 보세요: Roblox 플레이그라운드