Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by UrgotMachine · Aug 12, 2012 at 02:10 AM · timerchatcooldown

.js Timer to prevent chatflood?

Settin' up a school interactive chatroom, and wanted to prevent flooding of the RPC, how do I create in javascript a timer, that functions as a cooldown on your chat, e.g. having at least 1½ seconds between posts at best?

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Bunny83 · Aug 12, 2012 at 02:32 AM

It depends on how the chat works. If you have an authoriative server the check has to be implemented only on the server but it can't be removed (or bypassed). If you have a "normal" network setup, so each client send the rpc to all others itself you can implement it on the sending or receiving part. The easiest way is in the sending part but that could be bypassed. The other way would be that each client holds a timer for each other peer and refuses the receiving when it's too frequent.

The usual way is to use a simple float variable that stores the timestamp of the last message. You can simply check when the last one has been sent / received and refuse sending / receiving when it's faster than the allowed time.

Example:

 // UnityScript:
 public var cooldown : float = 1.5
 private var lastTimeStamp : float = 0.0;
 
 function SendMessage(text : String)
 {
     if(Time.time > lastTimeStamp + cooldown)
     {
         networkView.RPC(/*Send your message here*/);
         lastTimeStamp = Time.time;
     }
 }
Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image UrgotMachine · Aug 12, 2012 at 09:35 AM 0
Share

Someone please change this to an answer, it worked almost perfectly, just had to change 'time.time' to 'Time.time' but else than that, the idea of storing the time of last message, and checking if the new message is over the old timer + cooldown worked perfectly. Another solved unity thread, for people to find help from in the future.

avatar image Bunny83 · Aug 12, 2012 at 11:41 AM 0
Share

I'm a bit confused. This is an answer ;) And yes, my shift key sometimes won't work, sorry i will fix it. I will also add a cooldown variable since magic numbers are bad in general ;)

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

8 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

how to make a button click able after a few seconds 2 Answers

Usage timer/weapon cooldown... 3 Answers

Very Very Precise Timer ? 0 Answers

How to add a cooldown sort of thing. 1 Answer

C# Weapon overheat Buildup/Cooldown 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges