Jump to content
SubSpace Forum Network

Recommended Posts

Posted (edited)

Due to the amount of multiline output my new bot is expected to generate, I want to throttle it's output, but I also want to build a responsible queuing system that allows those who have cause the least spam in the past x seconds priority in the queue over the people who have caused the bot to spam a lot. For example, let's say there's an item listing command that fits on 5 lines. If someone is checking their items multiple times in succession, they'll quickly be the cause of a backlog of messages. Instead of cutting that person off, I just want to give any new messages they generate a low priority so that they aren't slowing the bot down for others.

 

I'm thinking that I'm going to need a collection to hold the queue of messages and another collection to hold the current priority order of players. When an output message is generated, responsibility is !@#$%^&*igned (most likely to the same person who's it's sending the private message to). It then checks to see if that player is !@#$%^&*igned a lower than normal priority and then loads the message into the queue accordingly.

 

Does this sound like the best way to go about doing it or would their be a simpler approach that would achieve the same goal? And what types of java collections would be the best fit here? (there's so many to choose from)

Edited by Arry
Posted
Well, I'm not worried about slowing down the bot as much as I'm worried about fitting in under the server's spam limitations (before getting silenced). The logjam is definitely going to be how much the server will let me send, not how fast my bot can process incoming requests
Posted

What you could do is use a PriorityQueue object with a custom Comparator (or whatever it's called). Basically, the queue will sort items based on where the Comparator says they should go. Then, just make the Comparator keep track of how many messages the users are receiving. As a user receives more messages, their priority goes down.

 

From there, you'd make an object that implements the MessageHandler interface and insert it to the outbound chain of the CNConnection you want to throttle. What it would have to do is keep track of how many outbound messages have gone out, then queue messages as it reaches it's limit. Read the details on the MessageHandler interface and the postMessage and sendMessage functions in CNConnection for details on how to piece it all together.

Posted (edited)
Wouldn't I have to have a separate thread that would continually check the queue to see if it had messages and if it was safe to send then send any messages that are waiting? Edited by Arry
Posted
Using another thread would allow you to guarantee that the messages will go out eventually. If you don't use another thread, you run the risk of leaving messages in the queue until the send method is called again.
Posted (edited)
I'm making progress on this, but I think I'm going to run into a problem using PriorityQueue.... when a player has multiple messages in the queue, those messages need to be maintained in the order they were originally trying to be sent. I'm thinking that PriorityQueue will not garuntee order among equal items (in this case that's messages queued to the same player), and there's nothing internal to the message string that tells me the order it arrived. I'm going to have to verify this, but I think I'm going to need to compensate for this somehow. Edited by Arry
Posted
Yeah, if I was just trying to throttle I could use something like that. But I'm also trying to prioritize the Queued messages (spammers last). I'm going to make one that just throttles too, but I think it's unfair that one person could use several multiline output messages and everyone else has to wait till the Queue is cleared. Rather, I want people who haven't recieved many private messages (IE the ones who are sending commands with multiline responses) to be the able to skip ahead of people who are bogging up the queue with their many messages.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...