Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (516)
Games in Android Showcase (122)
games submitted by our members
Games in WIP (577)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Patching/Updating games - How would it work?  (Read 4024 times)
0 Members and 1 Guest are viewing this topic.
Offline AppleSauce
« Posted 2014-06-11 19:13:33 »

If I had a jar file on multiple computers, how would I connect to all of them and edit files they have to update them like a patch? Would I search the whole computer for that file and delete it and replace it with the new file? Or perhaps change its' class files?
Offline trollwarrior1
« Reply #1 - Posted 2014-06-11 19:16:09 »

HAAAAAAAAAAAA you wish. Only hackers can do such things.

What you should do, is before running the game, connect to your game server or something like that, check the version of client's program against version of server's program. If the version doesn't match, you need to download files from the server, so that client has up to date files.

Did you seriously never notice how games patch up? Like when you start a game it says checking for updates? And if updates are available it downloads those updates and installs them? (Not games, all software does this)
Offline BurntPizza
« Reply #2 - Posted 2014-06-11 19:21:46 »

This topic has been discussed at length before (both on this forum and elsewhere), there is no need to ask "how does it work?" when the information's already been given to you.

This is also a deployment issue, meaning it is irrelevant until you have a game to deploy; you should focus on you actual project instead of side-projects like these (although I know it's hard not to), as doing so is the fastest way to lose motivation and burn out on a project.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline AppleSauce
« Reply #3 - Posted 2014-06-11 19:26:02 »


Did you seriously never notice how games patch up? Like when you start a game it says checking for updates? And if updates are available it downloads those updates and installs them? (Not games, all software does this)


Woah woah woah! I noticed this, I just don't know how it works bub :p.

HAAAAAAAAAAAA you wish. Only hackers can do such things.

What you should do, is before running the game, connect to your game server or something like that, check the version of client's program against version of server's program. If the version doesn't match, you need to download files from the server, so that client has up to date files.

How would you send files to a server? I think I understand how but I'm not sure.

This topic has been discussed at length before (both on this forum and elsewhere), there is no need to ask "how does it work?" when the information's already been given to you.

This is also a deployment issue, meaning it is irrelevant until you have a game to deploy; you should focus on you actual project instead of side-projects like these (although I know it's hard not to), as doing so is the fastest way to lose motivation and burn out on a project.

But I didn't understand the previous posts.
Offline AppleSauce
« Reply #4 - Posted 2014-06-11 19:30:20 »

Oh! I think I got it! Maybe the server will send the newer jar to the client and delete the original version, replacing it with the new one. Either that or the files inside of the jar get replaced. If I'm correct, I'll write this down for when I do need to use it.
Offline quew8

JGO Coder


Medals: 31



« Reply #5 - Posted 2014-06-11 19:35:44 »

For overwriting individual files in a zip archive (such as a .jar file) you can use ZipOutputStream and there is even a JarOutputStream especially for jar files. So there isn't even the requirement to download whole jar files.
Offline trollwarrior1
« Reply #6 - Posted 2014-06-11 19:47:48 »

I think you misunderstand something.. You need to have a pre-game client. It would check the version of your game. If the version is older than the server specified version, your pre-game client would download the newest .jar file from the server and replace your current version .jar with the newly downloaded .jar

Then, pre-game client would start the .jar as usual.
Offline AppleSauce
« Reply #7 - Posted 2014-06-11 19:50:08 »

So I would neeed only one client? The pre-game-client to check for the updates?
Offline trollwarrior1
« Reply #8 - Posted 2014-06-11 19:54:47 »

* Player opens GameLauncher.exe; (Which is actually the place to start your game)
* A window opens up that says information of what the GameLauncher.exe is currently doing;
* GameLauncher.exe connects to your game server;
* GameLauncher.exe requests the version of the game currently loaded on the server;
* If the version received from game server matches the version of Game.jar, GameLauncher.exe starts up Game.jar;
* If the version received from game server doesn't match the version of Game.jar, GameLauncher.exe download Game.jar FROM the game server, replaces old Game.jar and starts up newly downloaded Game.jar

Should be completely clear now.
Offline AppleSauce
« Reply #9 - Posted 2014-06-11 20:07:35 »

Amazing! Based off your LICENSE text file, would I be able to use this in my own project as long as I have the license shown?
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline opiop65

JGO Kernel


Medals: 156
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #10 - Posted 2014-06-11 21:35:47 »

Who is that question directed at?

Offline AppleSauce
« Reply #11 - Posted 2014-06-11 22:06:26 »

Who is that question directed at?

trollwarior
Offline opiop65

JGO Kernel


Medals: 156
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #12 - Posted 2014-06-11 22:10:48 »

Well what license are you talking about? He just gave you an idea, I don't see any shared code.

Offline AppleSauce
« Reply #13 - Posted 2014-06-11 22:34:29 »

Well what license are you talking about? He just gave you an idea, I don't see any shared code.

In one of his recent post he had a Launcher Program that linked to this post.
Offline Endos
« Reply #14 - Posted 2014-06-12 10:25:30 »

You can also use Java Web Start to do it automatically for you: http://examples.javacodegeeks.com/java-basics/web-start/java-web-start-getting-started/

Bored Birds - End with your boredom for Android
Retroships - Space Shooter for Android
Ultimate - 2D Side-Scrolling Platformer project
Offline princec

JGO Kernel


Medals: 409
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #15 - Posted 2014-06-12 11:27:18 »

WebStart's surprisingly crap though. And presupposes you've got a working system JVM installed in the first place.

Cas Smiley

Offline AppleSauce
« Reply #16 - Posted 2014-06-12 23:35:53 »

I should probably be ashamed of not know about Java webstart but does it scan the clients files?
Online Cero
« Reply #17 - Posted 2014-06-13 00:19:33 »

I should probably be ashamed of not know about Java webstart but does it scan the clients files?
No you shouldnt, its completely obsolete and not worth your time :)

Offline ra4king

JGO Kernel


Medals: 353
Projects: 3
Exp: 5 years


I'm the King!


« Reply #18 - Posted 2014-06-13 00:47:43 »

I should probably be ashamed of not know about Java webstart but does it scan the clients files?
I don't understand why you have this notion of scanning files? There is no scanning and searching. The updater is in the same directory as the game, and it simply replaces all files (the entire JAR files get replaced too, it's pointless to replace individual class files) that need updating.

Offline AppleSauce
« Reply #19 - Posted 2014-06-13 02:11:07 »

I should probably be ashamed of not know about Java webstart but does it scan the clients files?
I don't understand why you have this notion of scanning files? There is no scanning and searching. The updater is in the same directory as the game, and it simply replaces all files (the entire JAR files get replaced too, it's pointless to replace individual class files) that need updating.

I should have said the jar file. I really don't know how I'm going to send a jar file with server side programming though.
Online LiquidNitrogen
« Reply #20 - Posted 2014-06-13 02:12:44 »

i think the client would just get it with http or ftp. seems like thatd be easiest

Offline ra4king

JGO Kernel


Medals: 353
Projects: 3
Exp: 5 years


I'm the King!


« Reply #21 - Posted 2014-06-13 02:17:13 »

You don't send files. You have the files on the server, the updater queries for a version from the server, and downloads the new files using HTTP or FTP.

Offline Jacob Pickens
« Reply #22 - Posted 2014-06-13 21:06:24 »

Basically, what you would do, is have a file on server. (Dropbox, etc.)

You would have a version file on the server, and a version file in the updater jar. When the jar launches you would have to download the version.txt from the server and compare that data to your version.txt. (I have source code to show in a minute)

If the versions do not match, update.

What you would do is then download the new game files from the server and they will replace the old ones. (You would also need to update the version file in the jar to the correct version so that it doesn't constantly download the same update)

Now, your going to run into a problem if your resources for your jar are packaged outside of the jar and in a folder. There is no way for the updater to know that there is a new resource file because it has never heard of it before. (Atleast, from what i've learned there isn't a way) So what I do is if im going to package a game with an auto-updater I put a few empty sprite sheets that it download automatically just incase you add more art. Now, I haven't found a way with sound. I would suspect that you could just package everthing in the jar but, whatever.

Hope this helps.

Heres a little code:

TextFile Reader Class (Only reads one line)
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;

public class TextFile {

   private static String line;
   
   public static String readFile(String path) {
      BufferedReader file;
      try {
         file = new BufferedReader(new FileReader(path));
         line = file.readLine();
         file.close();
      } catch (IOException e) {
         e.printStackTrace();
      }
     
      return line;
   }
   
   public static void writeFile(String path, String text) {
      FileWriter file;
      try {
         file = new FileWriter(path);
         file.write(text);
         file.close();
      } catch (IOException e) {
         e.printStackTrace();
      }
   }
   
}


Updater Class
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;

import javax.swing.JOptionPane;

public class Updater {

   private static String currentVersion, newVersion;
   public static int update = 0;
   
   public static void checkForUpdate(boolean isAuto) {
      currentVersion = TextFile.readFile("./version.txt"); //Change this to a read file later
     
      try {
         URL site = new URL("https://raw.githubusercontent.com/JacobPickens/ecsl-version/master/version.txt");
         ReadableByteChannel rbc = Channels.newChannel(site.openStream());
         FileOutputStream fos = new FileOutputStream("./version.txt");
         fos.getChannel().transferFrom(rbc, 0, 1 << 24);
         fos.close();
      } catch(IOException e) {
         e.printStackTrace();
      }
     
      newVersion = TextFile.readFile("./version.txt");
     
      if(currentVersion.equals(newVersion)) {
         TextFile.writeFile("./version.txt", newVersion);
         
         try {
            URL site = new URL("http://i.imgur.com/A67BGOv.gif?1");
            ReadableByteChannel rbc = Channels.newChannel(site.openStream());
            FileOutputStream fos = new FileOutputStream("./img.gif");
            fos.getChannel().transferFrom(rbc, 0, 1 << 24);
            fos.close();
         } catch(IOException e) {
            e.printStackTrace();
         }
      }
   }
   
   public static void finishUpdate() {
      JOptionPane.showMessageDialog(null, "Game has been updated to " + newVersion, "Update Completed", JOptionPane.INFORMATION_MESSAGE);
      System.exit(0);
   }
   
   public static void doNotUpdate() {
      JOptionPane.showMessageDialog(null, "No Update Found", "Updater", JOptionPane.INFORMATION_MESSAGE);
      return;
   }
   
}
Offline opiop65

JGO Kernel


Medals: 156
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #23 - Posted 2014-06-13 21:30:32 »

Jacob, why can't you check if your resource files have changed? Its easy. First off, there's some fundamental changes I would make to how you're pulling updates.

Check the version against the server. If the server tells you to update the game, request an update text file from the server. The text file will contain a list of resources, including class files and actual image/sound files and where they are located on the server. The client will receive the text file, then request the new files to be downloaded. This way you can switch servers easily. If you send the URL of the file on the server, the client won't care what server its downloading from or where. All it knows is that it needs to request a file from the URL specified.

Much more flexible than just guessing what files you need to be updated.

Offline AppleSauce
« Reply #24 - Posted 2014-06-13 21:33:20 »

Thanks! That makes a lot of sense. I was wondering how to transfer files wireless.(wirelessly isn't a word?) But yeah, this helps.

Jacob, why can't you check if your resource files have changed? Its easy. First off, there's some fundamental changes I would make to how you're pulling updates.

Check the version against the server. If the server tells you to update the game, request an update text file from the server. The text file will contain a list of resources, including class files and actual image/sound files and where they are located on the server. The client will receive the text file, then request the new files to be downloaded. This way you can switch servers easily. If you send the URL of the file on the server, the client won't care what server its downloading from or where. All it knows is that it needs to request a file from the URL specified.

Much more flexible than just guessing what files you need to be updated.
e resources in to one text file?

By a list of resources, do you mean somehow compressing all of th
Offline opiop65

JGO Kernel


Medals: 156
Projects: 7
Exp: 3 years


JumpButton Studios


« Reply #25 - Posted 2014-06-13 21:38:19 »

No... You can't "compress" files into a text file.

What I meant was have a list of URLs of where the files are located. For instance:
www.yourwebsite.com/yourgame/resources/image.PNG

And so on.

Pages: [1]
  ignore  |  Print  
 
 

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

TehJavaDev (32 views)
2014-10-27 03:28:38

TehJavaDev (26 views)
2014-10-27 03:27:51

DarkCart (41 views)
2014-10-26 19:37:11

Luminem (22 views)
2014-10-26 10:17:50

Luminem (27 views)
2014-10-26 10:14:04

theagentd (33 views)
2014-10-25 15:46:29

Longarmx (61 views)
2014-10-17 03:59:02

Norakomi (58 views)
2014-10-16 15:22:06

Norakomi (47 views)
2014-10-16 15:20:20

lcass (43 views)
2014-10-15 16:18:58
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!