ID:160253
 
I'm currently building an anti-spam system for a game,and I have set up a variable which gains 1 value each a user posts a messege on the world say,now,How do I make it undo the user's action if it detecs spam?
Arochimaro wrote:
I'm currently building an anti-spam system for a game,and I have set up a variable which gains 1 value each a user posts a messege on the world say,now,How do I make it undo the user's action if it detecs spam?

Run the check before the action is completed.

The logical theory is:
User attempts to do this.
Proc checks this and makes sure it's OK to do so.
if proc says it's fine:
  Go ahead.
Otherwise:
  Cancel the operation.
In response to Tiberath
mob/var/spam = 0

mob/verb/World_Say(msg as test)
spam = spam + 1
spawn(5) src.Spam_Check()
world << "[usr] : [msg]"

mob/proc/Spam_Check()
if(spam > 4)
usr << "No spamming is allowed!"
return


So it should be something like this? This isn't the actual system,I wrote it how you suggested...
In response to Arochimaro
Arochimaro wrote:
> mob/var/spam = 0
>
> mob/verb/World_Say(msg as test)
> spam = spam + 1
> spawn(5) src.Spam_Check()
> world << "[usr] : [msg]"
>
> mob/proc/Spam_Check()
> if(spam > 4)
> usr << "No spamming is allowed!"
> return
>
>

So it should be something like this? This isn't the actual system,I wrote it how you suggested...

Your system doesn't work for a few reasons.

One there's nothing to decrease the spam count, so after sending five messages, it'll never go back to normal.

You're using a spawn(5) there for no apparent reason at all, when it should be an if() statement.

No using usr in procs.

The overall look of what your code should be like is something like this:
mob
verb
say(msg as text)
if(some_kind_of_spam_check()) //This is relying on some_kind_of_spam_check() returning 1 if it's ok and 0 if it's not.
world << "[src.name] says: [msg]"


As for myself, I've never actually tried to write an anti spam proc before, so I'm not entirely sure how one would go about it. I imagine following a set of logic guild lines would produce something. Those being:
User attempts to do something
Increment a variable
Check if the variable is greater than a specific set amount
If not -> Let the action take place
Otherwise -> Inform them they can not.

Procedure receives request to compare variable with static value
return 1 if legal
return 0 if not legal

Procedure to decrease the variable after a specific amount of time.

Well, that's my logical theory anyway. I could be overlooking something (no doubt someone will correct me if I'm mistaken). But anyway, logical thought pattens wont help you unless you have a good grasp on what you're doing.

There's an interesting article in Dream Makers that should help you out. I recommend reading it, don't by shy if it's hard to understand at first, reread it a couple of times and you should be able to get what you need.

Dream Tutor: The Other Mystery Meat.

In response to Arochimaro
Arochimaro wrote:
> mob/var/spam = 0
>
> mob/verb/World_Say(msg as test)
> spam = spam + 1
> spawn(5) src.Spam_Check()
> world << "[usr] : [msg]"
>
> mob/proc/Spam_Check()
> if(spam > 4)
> usr << "No spamming is allowed!"
> return
>
>

So it should be something like this? This isn't the actual system,I wrote it how you suggested...
mob/var/muted = 0
mob/var/spam = 0

mob/verb/World_Say(msg as TEXT)//not test

if(usr.muted != 0)
usr << "You are muted"
else
spam += 1
if(spam >= *number of messages allowed*)
usr.muted = 1
spawn(*time till automatically unmuted*)
usr.muted = 0


Note that this doesn't check for amount of messages in a certain amount of time, only how many messages. Give them a one minute mute or something to get the point across, the player may have a lot to say and a short char limit, but in that case they can always use whisper;)
In response to Morpholic
Your verb also doesn't display the message.

It will also receive the compile time error "error: Bad input type: TEXT".

Types are case sensitive, my friend.