A more efficient proxy...
Well I've been playing around with Ikulip's java source code that I've updated to the current build of rotmg. As a first project, I decided to use the source to make a multibox character sync'er. That is, to get all the multiboxer characters to sync up and follow each other. To do this, I ended up using a client modified specifically for the proxy to handle the actual movement of the characters (added new packets to it and routines for dealing with them including the follow routine) while having the proxy reroute the location of my leader to all my followers. I wanted to get it to sync up as close as possible which means I needed to transfer that location information quickly to the follower clients. Well I quickly found out that Ikulip's proxy wasn't going to be as quick as I wanted even with removal of all the unneeded code.
The proxy does what a proxy should do, read in a packet, interpret it, make decisions/changes based on that packet (which includes sending other packets if needed), and send it out to its destination modified or not (if it was determined not to block the packet). The problem with this, as it applies to my project, packets are sent in at irregular time intervals, sometimes far longer than I wanted to wait to request a new position update from my leader client. I couldn't use this procedural loop to request the position updates. My solution was to make a separate thread that sent out a new position update requests to the leader client at regular intervals which eventually worked after dealing with threading related issues with the use of variables (this is really my first experience with threading).
The other problem I ran into is that I needed to send out packets quickly. The queuing system setup in the proxy is far too slow to get updates out to the followers (relies on the irregular input of packets). Ikulip mostly used the socket output stream directly, bypassing the queuing system, to send out packets. This works as long as one didn't try to cross threads to send out information. By cross threads I mean if one received a packet from the server (meaning your currently in the "server to client" thread) one shouldn't try to write a packet to the server using the "client to server" thread. The reason one doesn't want to do this is because the packets need encrypting and only one packet can be encrypted at a time. I needed to cross threads so that I could update my followers as to the whereabouts of my leader quickly. So my solution was to create another thread to handle the output of packets and this worked well.
Now after playing around with this I noticed that when the proxy is loaded with many clients and cpu usage starts to rise to 100%, shit hits the fan. Everything starts to bounce around (much like how @
flyrocket's oryxdom would lag when around many objects, although to a lesser extent). So I figure this problem can fall into either of two categories, a) when the cpu hits 100% your fucked no matter what you do, or b) there is something wrong with how the proxy handles the packets. I'm hoping it is the latter and can be fixed. One idea I had was to create yet another thread that only reads in packets to a queue although I don't see much advantage to this as you'll need to look at them one by one anyways unless yet more threads are created to deal with multiple packets at a time. Anyone here have experience with this sort of stuff and can shed some light on what can be done to combat this lag?