JavaScript Node.js – How to Design a Server-Side Heartbeat with Node.js

javascriptnode.js

I would post this on https://stackoverflow.com/, but figured I am not looking for code, just an idea how to accomplish this.

I have a gameserver that interacts with nodejs and uses the websocket module. It works great, there is one problem:

When a user is joining a game and the map gets loaded, a user could easily press F12, go into Chrome dev tools and remove the overflow:hidden css attribute, thus.. revealing the rest of the map. (A Web-based map hack!). My map dimensions are 3000×3000 + in size.

I need some type of way to to send something to nodejs every xx seconds and then nodejs needs to send back a token with that request as well to keep that css attribute at overflow:hidden and if the data being sent is manipulated in anyway, I can then shut down that player's connection.

Doing this method, I would use the setInterval with Javascript to create the heartbeat. Am I going about this the right way?

Edit: And yes, this will require more bandwidth, but well worth it imo.

Best Answer

You'd be better off using that extra bandwidth to spoon feed the map to the users as they discover it.

As you've noticed, anything client side can be easily hacked. You might think of a fancy way to encrypt the data, but you'd still have to send the decrypt keys to the browser.

For that matter, you don't really know if you're talking to a browser at all - you're just sending data over a TCP port to a computer that kind of maybe sort of looks like it might be a common web browser.

Related Topic