Jump to content
  • Advertisement
Sign in to follow this  

Javascript Is Our Javascript Code Viewable by Browsers, etc.

Recommended Posts

Posted (edited)

I am getting very interested in the very popular JavaScript.  I would like to create games with it.   One thing that concerns me is the availability of the webpages' code to others.  I would really like to watch some movies on JavaScript but I don't know how to feel about people being able to copy my code (or for that matter if it is possible.)  Am I being unrealistic?  Are there means to make the code unreadable by the occasional viewer?  Perhaps it is just html5 and css3 that can be viewed with google chrome's view source and I am confused.

Thanks in Advance,

Josheir

Edited by Josheir

Share this post


Link to post
Share on other sites
Advertisement

Well I don't mind people looking and learning but I also don't want to be pirated on something that took a long time to code.  I know it's the in thing to give in the world of computers but profit is real too.  I love to program and share but I also am considering a Masters in Business.

I seem to remember back in the day that some server side language could be used to produce the client side code so it didn't show up.  Maybe it was PHP.

Thank you,

Josheir

Share this post


Link to post
Share on other sites
Posted (edited)

Anything that runs on the local machine of the user can and will be cracked. Stuff running in a browser is not an exception to that rule.

The only solution is thus to keep any code you don't want to be cracked to yourself. In online games, this is fairly easy, keep the code at the server, and only send the results to the user. This is what PHP was doing too, it got expanded to a .html page by executing it on the server, and the client received and displayed the resulting html file.

Javascript got in the picture, because it runs on pretty much every browser (if not all browsers, but you know better than me), and it allows to execute any code when you hovered at some spot, or when you clicked somewhere. It gives programmable GUIs in the browser, which is much faster in interacting with the user (no need to bother the server for adding a drop-down menu, or change a single picture to acknowledge you can click it), etc.

From there it got worse, people are now writing non-trivial javascript code, and program games in the browser ;)

 

Write the game in such a way that a player needs a server you control to play the game. Javascript is the tool for making the browser "alive and interacting", ie a programmed GUI which does very little other than passing data between server and client display. Of course "very little" varies between "trivial" and "near impossible", depending on your game and the distribution of work between client and server :)

Edited by Alberth

Share this post


Link to post
Share on other sites

If it's running in the browser, I can see it.

If it's running in the browser, it needs a server, or what's the point of running in a thin client like a browser?

If it's running on the server, you can prevent people from seeing it.

If you're worried about piracy, keep important parts of your game on the server.  Let people copy the stuff on the browser, it's useless without the non-copyable server code.

Folks these days get confused by modern JavaScript "frameworks" because they end up obscuring what runs on the server and what runs on the client browser.  You just have to deep-learn your any-idiot-can-now-program tools to understand what's really going on under the hood.

Share this post


Link to post
Share on other sites
Posted (edited)

All Javascript client code can be viewed by users. The only tool you have is code obfuscator, but that really doesn't change much, only add an extra layer of inconvenience.

edit: You actually do want to use obfuscator, or minifier as some people call it. Since it compacts your code, remove whitespaces and trim names, it can significantly reduce download time and thus make your game load up faster.

Edited by alnite

Share this post


Link to post
Share on other sites

Could someone give me an example of a web browser game that would use a server to keep the important parts on it?  I'm not quite getting it.  

And are there any other solutions, Java for example?

Thanks,

Josheir

Share this post


Link to post
Share on other sites
Posted (edited)

I have a hard time getting what you don't get, but let's try :)

 

Say you have a game, with a nifty path-find algorithm that you don't want to fall in the wrong hands. Now you have 2 choices.

1. Implement the algorithm in javascript, and run it in the browser. Gives nice and speedy feedback. Player happy and cracker also happy, as he can just see how you did it, and copy it.

2. Implement it in whatever language at your server. Local browser has to send a request for a path to the server, server runs nifty algorithm, server returns computed path. Bit more slow, player still happy with nifty path, cracker less happy, as he only has input and output of the algorithm, and not the algorithm itself, unless he cracks your server.

 

You can also use this to avoid cheating.

Say you have a builder game, where you produce goods of some kind. It is precious stuff, and it costs time to make it, so a good target for cracking. Now you have (at least) 2 choices.

1. Implement the entire production in the browser, and send only to the server "I produced X amounts of goods". Player happy, and cracker happy, as he can send "I made a 1000000 stuff" every 5 milli seconds to your server.

2. Implement timing of production in the server. Browser sends only "production started at factory X", server sends "production ended at factory X, Y goodies added". Player happy, as he can still make goods, cracker less happy, as he can only send "started factory X", where X has to exist, and has no further powers to force the server into believing the production ended 5 milli seconds later.

 

Both examples move the actual game logic to the server, and only perform GUI interaction in the browser. A cracker may even fully implement the browser code by himself, but it won't do him much good, as game progress is under control by the server.

An extreme view is that the entire game is running at your server, where you provide a nice graphical GUI at the player machine as a bonus, since most people prefer to click at a tile, rather than typing "<productionstart time="56567467636"><factory x="21" y="54"><production type="foo"/></factory></productionstart>" for some weird reason ;)

Edited by Alberth

Share this post


Link to post
Share on other sites
10 hours ago, Josheir said:

Could someone give me an example of a web browser game that would use a server to keep the important parts on it?  I'm not quite getting it.  

And are there any other solutions, Java for example?

For the example, all games that have an online processing components have this. In a web game like Slither or Generals the client receives data from the server and displays it, and the client accepts data from the player and transmits it.  In Slither the game clients aren't coordinating all the motion and collision. In Generals the game clients aren't increasing the numbers or maintaining who owns whatever squares.

The game servers only transmit the things the player can sees. Instead of the client getting all information and only selectively displaying what the player should see, the player only has the data they can see and has no other extra data. The game client does not know what every square is doing, or what ever player is doing, or what moves are queued, or what else is going on within the game. In Slither that means the client doesn't have data for snakes that are distant. In Generals that means the client doesn't have data for distant tiles or data for queued moves except the ones made by the local player. The server knows all the information, but the game clients are never presented it with it.

 

 

For the protections you're talking about, if the game is entirely transferred to the client it cannot be protected. If a player downloads all the pieces to play, then an attacker can also download all the pieces to play. They can save those files and serve them from their own web sites.

This has been done by many unscrupulous people. Many Flash games, Java applets, and other web-based programs have been copied from one site to another site because it was all present. Some require changing a few assets to point to different web sites, but that is easily modified.

Java doesn't help. If you create a Java applet the files can be downloaded by a legitimate user, saved to disk, then used by an unscrupulous actor.  Compiled Java can be opened by anyone with the right tools. Languages that support Reflection mean that compilation includes all the original names. If you're using a language that supports reflection features, like Java, C#, compiled JavaScript, and more, an obfuscator can help rename everything so it isn't immediately visible through reflection; instead of seeing that something is called GameObject they see it is called TQxV or some other random-generated names. That doesn't help very much, but can slow people down slightly.  Heavily-compiled languages like C++ perform even stronger operations to remove names, and they are also easily reverse engineered by people with the right tools.

 

The only viable solution to keeping the game from being taken is to never give them access in the first place. That generally means the client is a viewer for data, and the server is a producer of the data. The player can have all the access to they client they want. An attacker can make a fake client that responds exactly the same way as the legitimate client, they can have full knowledge of the communications protocols, of what is being sent across the wire and why, but even with full knowledge of how the client works they still couldn't do the server processing. That's the only known way to have those protections.

Share this post


Link to post
Share on other sites
Posted (edited)
13 hours ago, Alberth said:

I have a hard time getting what you don't get, but let's try

The game I am considering and almost made once does not have a lot of behind the scenes programming.  So, I wanted to understand with an example, which you did.  Thank you.

Now, according to frob even a C++ stand alone game can be pirated, which was another option for my project.  I haven't been on Steam lately, but my understanding is there are plenty of games programmed with C++.  I wonder what their philosophy is.  I don't think they all have 'upgrades' on the server?

 

In short, What do I need to do to win (besides what we said)?  Do I need to think a certain way?  I want to make some revenue.

 

Josheir

Edited by Josheir

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Advertisement
  • Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By Adrian Bigaj
      Hello!

      The game: https://www.combo-clicks.com/
      DEV blog (so everyone can read the journey and some history):
      http://www.combo-clicks-dev.com/
      TL;DR
      Feedback for Combo Clicks and also IDEAS for future games will be super appreciated (Hyper Casuals done in 3-4 weeks, each game with React Native).
      I will try to post on my blog atleast on weekly basis (both for gamers and developers) 
      Thank you!




    • By rouman
      Hi I tried to make some game in canvas JS.
      But dont know how to make sound effects like laser beam, I just add autoplay to some laser.wav and it is terrible.
      I need not fixed time. Each voise should have random time like 2s, 3s, or 10s?
      How to replace sound with another sound but not just replace but to make it slowly like animated.
      Is there such ablity or any library?
      Maybe some knew tutorial or book about sound game effects.
      myHobby.bmp
    • By Josheir
      I took a hiatus of sorts and am thinking about switching from C++ to JavaScript.  It seemed like there was always a great response when I was into C++ here.  Where is the hottest area/areas for JavaScript questions.  I never had a question not responded to before!
       
      Thanks,
      Josheir    
    • By Josheir
      I am considering writing a JavaScript browser game that uses three windows.  What I am wondering is after the initial load of the game will the web pages be ready and therefore quick enough for any user.  One problem would be that the third window would open and close so does this mean that there is a necessary reload of that seperate third window page code and images by the browser that would slow it down?
       
      Thank you; it would be a fun project,
      Josheir
    • By BigBadMick
      Hey everybody,
      I'm currently working on a simple HTML5 game and my javascript collision detection function isn't working. The game features a little man that runs from side to side at the bottom of the screen, while a meteor falls from the sky. The function is supposed to detect a collision between meteor and man.
      In the routine, the top left corner of the man is at (player.x, player.y) and the top left corner of the meteor is at (meteor.x, meteor.y). The man is 25 pixels wide by 35 pixels tall. The meteor is 50 pixels wide by 50 pixels tall.
      Any idea where I've screwed in up this function?
      // ============================================================================= // Check for a collision between the 50 x 50 meteor and the 25 wide x 35 tall // main character // // Main character is drawn at 540 and is 35 tall, so the top of the character // is at y = 540 and the bottom is at y = 575. // // Function returns 1 if there has been a collision between the main // character and the meteor, otherwise it returns 0. // ============================================================================= function check_for_meteor_player_collision () { // edge positions for player and meteor var player_top = player.y; var player_bottom = player.y + 34; var player_left = player.x; var player_right = player.x + 24; var meteor_top = meteor.y; var meteor_bottom = meteor.y + 49; var meteor_left = meteor.x; var meteor_right = meteor.x + 49; var vertical_overlap = 0; var horizontal_overlap = 0; // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Check for vertical overlap // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Check if meteor bottom overlaps player if ((meteor_bottom >= player_top) && (meteor_bottom <= player_bottom)) { vertical_overlap = 1; } // Check if meteor top overlaps player if ((meteor_top >= player_top) && (meteor_top <= player_bottom)) { vertical_overlap = 1; } // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Check for horizontal overlap // ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // Check if meteor left side overlaps player if ((meteor_left >= player_left) && (meteor_left <= player_right)) { horizontal_overlap = 1; } // Check if meteor right side overlaps player if ((meteor_right >= player_left) && (meteor_right <= player_right)) { horizontal_overlap = 1; } // console.log("vertical_overlap = " + vertical_overlap); // console.log("horizontal_overlap = " + horizontal_overlap) // If we've got both a vertical overlap and a horizontal overlap, // we've got a collision if ((vertical_overlap == 1) && (horizontal_overlap == 1)) { return 1; } // if we've fallen through, we haven't detected a collision return 0; } // =============================================================================  
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!