Fear of reaching data store limit saving messages

I have an in game messaging system, that saves messages players send to each other (which can be destroyed once a player has read) however, I fear an exploiter could use this to cause data caps to be reached.

I put in place a system that prevents too many messages, so you can only have 10 messages in your inbox at once saved, however, their lengths aren’t set. So in theory, somebody could send you a message with a million words ye? Would this then cause data store caps to be reached? and if you so, what would be my best solution?

I thought of setting a word cap, but that could still cause a ton of data requiring saving. For example, let’s say:

100 character cap on message.

You can get 5 messages from each player, and upto 10 seperate players. So that’d max out at

100 * 5 * 10 = 5000

Which I mean, out of a data store cap of 260,000 I’d imagine 5,000 ain’t the end of the world?

But is there a better way?

Small chunket of the code

if #Data.Messages >= 10 then return 'Inbox full!' end -- User has too many messages (from 10 different users)
	
	local FoundUser = false
	
	for i, v in pairs(Data.Messages) do
		if i == player.Name then -- Already got a message from that player
			print('Already has a message', #v)
			-- Check to make sure they don't have a ton of messages from same player
			if #v >= 5 then
				return 'Inbox full!'
			else
				-- All good, send the message
				table.insert(Data['Messages'][i], FilteredMessage)
				FoundUser = true
				
				break
			end
		end
	end
	
	if not FoundUser then
		Data.Messages[player.Name] = {FilteredMessage}
	end

You can limit the length of a string with this:

if #myString > 100 then
    myString = myString:Sub(1,100)
end

(not tested, wrote it here, let me know if it works)

Of course you can replace 100 with a different value, such as 25000

Yes, you can hit the cap if a large message is sent since you need to store the raw text for the message to be visible anyway. Imposing a character cap is your best solution and typically any messaging software incorporates that kind of limitation anyway.

If your inbox limitation is 5 messages per player and a maximum of 10 players, that’s 50 messages total, with an 100 character limit per message being 5000 total possible characters ever being allowed in your message partitions. That math adds up. This data cap, if hit, is only worth 1.92% of a player’s allowed DataStore characters per value which is hardly anything. You could double the character cap to 200 for more hearty messages and that’d still only be worth 3.85% of your CPV.

Doesn’t seem like there’s a better way, I think what you’re doing now is fine. Just make sure to impose the limitation on both the client and the server. The client will impose it for instantaneous feedback and the server will forcefully truncate any message above your character count for input sanitisation.

1 Like