다양한 소스와 입력에 적용되는 텍스트 필터링은 사용자가 부적절한 언어와 전화번호와 같은 개인 식별 정보를 보지 못하게 합니다. Roblox는 인-경험 텍스트 채팅을 통해 전달된 메시지와 같은 일반 텍스트 출력을 자동으로 필터링하지만, 명시적으로 제어할 수 없는 모든 표시된 텍스트에 대한 필터링은 귀하의 책임입니다.
필터 시나리오
텍스트는 다음과 같은 다양한 시나리오에서 사용자에게 수집되고/또는 표시될 수 있습니다:
무작위 문자의 조합으로 단어를 생성하고 이를 사용자에게 표시하는 경험, 이는 부적절한 단어를 생성할 가능성이 있습니다.
외부 웹 서버에 연결하여 경험 내에 표시되는 콘텐츠를 가져오는 경험. 종종 외부 사이트의 콘텐츠를 제어할 수 없으며, 제3자가 정보를 수정할 수 있습니다.
데이터 저장소를 사용하여 사용자의 애완동물 이름과 같은 텍스트를 저장하는 경험, 여기서 저장된 텍스트는 검색 시 필터링해야 하는 부적절한 단어를 포함할 수 있습니다.
필터링 프로세스
TextService:FilterStringAsync()는 텍스트 문자열과 해당 텍스트를 생성한 사용자의 UserId를 입력으로 하여 인-경험 텍스트를 필터링합니다. 이는 두 가지 추가 메서드를 가진 TextFilterResult 객체를 반환합니다:
- TextFilterResult:GetNonChatStringForBroadcastAsync()는 경험 내 모든 사용자에게 표시되는 텍스트를 필터링하는 데 사용되며, 서버의 모든 사용자에게 표시되는 간판에 메시지를 작성하도록 하는 대화 상자와 같은 경우에 사용됩니다.
- TextFilterResult:GetNonChatStringForUserAsync()는 나이 및 기타 세부정보를 기반으로 특정 사용자에게 필터링된 텍스트를 표시합니다.
TextBox 입력의 맥락에서, 다음 예제는 FocusLost 이벤트에서 입력을 수집하고 이를 RemoteEvent를 통해 서버에 전송합니다. 서버에서는 먼저 FilterStringAsync()를 통해 필터링한 다음, GetNonChatStringForBroadcastAsync()를 통해 텍스트가 3D 세계의 SurfaceGui와 같은 서버 측 개체에 모든 사용자에게 표시될 것으로 예상됩니다.
텍스트 입력 필터링 - 클라이언트 스크립트
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local textBox = script.Parent
textBox.ClearTextOnFocus = false
textBox.PlaceholderText = "..."
textBox.TextXAlignment = Enum.TextXAlignment.Left
textBox.TextScaled = true
-- 필터링을 위해 서버에 텍스트 입력을 전송하는 RemoteEvent
local inputRemoteEvent = ReplicatedStorage:FindFirstChild("InputRemoteEvent")
-- 포커스가 잃어질 때와 Enter 키가 눌릴 때의 이벤트 핸들러
local function onFocusLost(enterPressed, inputObject)
if enterPressed then
print("전송됨:", textBox.Text)
if inputRemoteEvent then
inputRemoteEvent:FireServer(textBox.Text)
end
end
end
textBox.FocusLost:Connect(onFocusLost)
텍스트 입력 필터링 - 서버 스크립트
local TextService = game:GetService("TextService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
-- 필터링을 위해 클라이언트로부터 텍스트 입력을 수신하는 RemoteEvent
local inputRemoteEvent = ReplicatedStorage:FindFirstChild("InputRemoteEvent")
local function getFilterResult(text, fromUserId)
local filterResult
local success, errorMessage = pcall(function()
filterResult = TextService:FilterStringAsync(text, fromUserId)
end)
if success then
return filterResult
else
warn("TextFilterResult 생성 오류:", errorMessage)
end
end
-- 클라이언트가 TextBox에서 입력을 제출할 때 호출됨
local function onInputReceived(player, text)
if text ~= "" then
local filterResult = getFilterResult(text, player.UserId)
if filterResult then
local success, filteredText = pcall(function()
return filterResult:GetNonChatStringForBroadcastAsync()
end)
if success then
print("필터링됨:", filteredText)
else
warn("텍스트 필터링 오류!")
end
end
end
end
inputRemoteEvent.OnServerEvent:Connect(onInputReceived)