Skip to content
This repository has been archived by the owner on Jun 11, 2020. It is now read-only.

Prevent follow notifications spam #711

Merged
merged 1 commit into from Feb 3, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 20 additions & 0 deletions CoreScriptsRoot/ServerCoreScripts/ServerSocialScript.lua
Expand Up @@ -17,6 +17,9 @@ local RunService = game:GetService('RunService')

local GET_MULTI_FOLLOW = "user/multi-following-exists"

-- Maximum amount of follow notifications that a player is allowed to send to another player.
local MAX_FOLLOW_NOTIFICATIONS_BETWEEN = 5

local PlayerToRelationshipMap = {}

--[[ Remotes ]]--
Expand Down Expand Up @@ -152,6 +155,9 @@ function RemoteFunc_GetFollowRelationships.OnServerInvoke(player)
end
end

-- Map: { UserId -> { UserId -> NumberOfNotificationsSent } }
local FollowNotificationsBetweenMap = {}

-- client fires event to server on new follow
RemoteEvent_NewFollower.OnServerEvent:connect(function(player1, player2, player1FollowsPlayer2)
if player1FollowsPlayer2 == nil then
Expand All @@ -163,6 +169,18 @@ RemoteEvent_NewFollower.OnServerEvent:connect(function(player1, player2, player1
local user1map = PlayerToRelationshipMap[userId1]
local user2map = PlayerToRelationshipMap[userId2]

local sentNotificationsMap = FollowNotificationsBetweenMap[userId1]
if sentNotificationsMap[userId2] then
sentNotificationsMap[userId2] = sentNotificationsMap[userId2] + 1
if sentNotificationsMap[userId2] > MAX_FOLLOW_NOTIFICATIONS_BETWEEN then
-- This player is likely trying to spam the other player with notifications.
-- We won't send any more.
return
end
else
sentNotificationsMap[userId2] = 1
end

if user1map then
local relationTable = user1map[userId2]
if relationTable then
Expand Down Expand Up @@ -194,6 +212,7 @@ end)

local function onPlayerAdded(newPlayer)
local uid = newPlayer.UserId
FollowNotificationsBetweenMap[uid] = {}
if uid > 0 then
local uidStr = tostring(uid)
local result = getFollowRelationshipsAsync(uid)
Expand All @@ -212,5 +231,6 @@ Players.PlayerRemoving:connect(function(prevPlayer)
local uid = tostring(prevPlayer.UserId)
if PlayerToRelationshipMap[uid] then
PlayerToRelationshipMap[uid] = nil
FollowNotificationsBetweenMap[uid] = nil
end
end)