0

Is it at all possible to use javascript server side and thus not shown in page source for certain core calculations?

I'm developing a game, and one crucial part of the code needs to be only calculated server side then passed back to client.

My entire game is in Javascript - but most of it is client side which is fine except this one particular function which needs to hidden from view to prevent cheats.

Is this possible - if so how would I set up server side JS ?

John Slegers
  • 45,213
  • 22
  • 199
  • 169
Sir
  • 8,135
  • 17
  • 83
  • 146

4 Answers4

5

You'll want to look at node.js. Node.js allows you to run javascript code on the server and is very easy to get up and running to accept and respond to http requests. You'll probably also want to take a look at expressjs which makes implementing a Node.js server even easier.

Bill
  • 25,119
  • 8
  • 94
  • 125
  • Nope, the javascript that is running on Node.js is server side, nothing is visible to the client except what you include in the response. – Bill May 06 '12 at 03:55
3

There are a variety of ways of doing server side scripting. Node.js is one solution, but even PHP, Ruby, or Python will let you do server side calculations.

It doesn't matter though, because if your game is heavily client side JS, anyone with a greasemonkey plugin installed can cheat.

Umbrella
  • 4,733
  • 2
  • 22
  • 31
  • No because all calculations will be done server side with JS - server side code such as php is not editable with client plugins :P – Sir May 06 '12 at 03:55
  • They don't have to edit your server side code to cheat. They just have to run some custom client side code. – Umbrella May 06 '12 at 03:56
  • The most they would do then is change the visual output but the not the numbers stored in my database. – Sir May 06 '12 at 03:58
  • Dave, they don't need to change the function itself, at some point the resulting value of the server side script is gonna be passed to the client side and that's where anyone can change it. – Delta May 06 '12 at 04:00
  • Well, I certainly hope so, but if your entire game save one function is client side JS, it's very likely they'll find some way to cheat. Perhaps by exploiting what isn't server side, perhaps by sending false data to your one server side function. – Umbrella May 06 '12 at 04:01
0

I would do an AJAX request. Submit raw data to the server and get back the completed data. Use a server side language (PHP) to do the secure calculations. JavaScript on the server side is a real crap shoot.

iambriansreed
  • 21,935
  • 6
  • 63
  • 79
0

I would also recommend you to check out NowJS (http://nowjs.com/) which will allow you to easily call server functions from client (without exposing their source code).

now.calculateGameScore(function(data){ ... });