텍스트 필터링

*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.

다양한 소스와 입력에 적용되는 텍스트 필터링 은 사용자가 부적절한 언어와 전화번호와 같은 개인 식별 정보를 볼 수 없도록 합니다.Roblox는 경험 내 텍스트 채팅을 통해 지나간 메시지와 같은 일반적인 텍스트 출력을 자동으로 필터링하지만, 당신은 명시적으로 제어할 수 없는 모든 표시된 텍스트를 필터링해야 합니다 .

시나리오 필터링

텍스트는 다양한 시나리오에서 수집되고/표시될 수 있으며 포함:

  • 사용자의 텍스트 입력 을 수집하는 경험, 키보드/키패드 인터페이스와 같은 사용자 지정 GUI, 또는 3D 공간에서 상호 작용 가능한 키보드 모델.

  • 랜덤 문자에서 단어를 생성하고 사용자에게 표시하는 경험으로, 부적절한 단어가 생성될 가능성이 있습니다.

  • 경험에서 표시되는 콘텐츠를 검색하기 위해 외부 웹 서버에 연결하는 경험.종종 외부 사이트의 콘텐츠를 제어할 수 없으며 제3자가 정보를 편집할 수 있습니다.

  • 사용자의 펫 이름과 같은 텍스트를 저장하는 경험은 데이터 저장소에서 저장된 텍스트에 필터링해야 하는 부적절한 단어가 포함될 수 있으며, 검색할 때 필터링해야 합니다.

필터링 프로세스

경험 내 텍스트를 필터링하여 텍스트의 문자열과 텍스트를 만든 사용자의 를 입력으로 가져옵니다.다른 시나리오에서 호출할 수 있는 두 가지 추가 메서드가 있는 TextFilterResult 개체를 반환합니다:

입력의 컨텍스트에서 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
-- 필터링을 위해 서버에 텍스트 입력을 보내는 원격 이벤트
local inputRemoteEvent = ReplicatedStorage:FindFirstChild("InputRemoteEvent")
-- 초점 손실 및 입력 누르기 이벤트 처리기
local function onFocusLost(enterPressed, inputObject)
if enterPressed then
print("SUBMITTED:", 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")
-- 필터링을 위해 클라이언트로부터 텍스트 입력을 받는 원격 이벤트
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("Error generating TextFilterResult:", errorMessage)
end
end
-- 클라이언트가 텍스트박스에서 입력을 제출할 때 해고됨
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("FILTERED:", filteredText)
else
warn("Error filtering text!")
end
end
end
end
inputRemoteEvent.OnServerEvent:Connect(onInputReceived)