Autoupdater

Hi, I am interested in making an autoupdater for my game.

I was thinking, having a “launcher.jar” file, this is the only file you need to run the game. If you don’t have a file it will download it.
When you double click on launcher.jar, it contacts a main server (using TCP) and requests the current game version.

Inside my main game.jar file, there will be a version variable. If the version doesn’t match or the game.jar file doesn’t exist, the launcher will hash every file in the game directory (MD5?) and send the hashes to the server. If any hashes are different/missing, the server will send those files to the client and the client will replace all the old files.

The launcher.jar will then launch the game by calling a method inside the game.jar file.
If the game.jar file is updated, the launcher will have to close and restart before the game is played? since launcher.jar depends on game.jar.

Can anyone see any improvements/problems with my idea?

Thanks,
roland

You’re reinventing JNLP and GetDown. You might want to investigate those two before pursuing your own solution.

Thanks for the reply, in this I think I would like to do it myself though.

You shouldn’t have to re-download files that have the same hash i.e. if the hash matches one of the hashes on the server, don’t download it. So delete the files that don’t match, then download the files that are missing. As for the version and having to restart the launcher, if you just check to see if the .jar exists and check the hashes (don’t look for a version variable) then you can load the game.jar after you’ve checked/updated everything. That way when you try to load the game.jar, it should be there as long as everything went ok. You could also just have everything needed for the game (besides the launcher of course) inside the game.jar, then check the hash of the jar against the hash of the jar on the server and download it if needed. OR you could JUST have a version variable in the launcher that tracks the current version on the local filesystem and download an update if the version on the server is different. The last two options sound the easiest to me. That was more of a brainstorm than actually helpful, sorry ;D

Thanks for the reply, Z-Man.

If I am running launcher.jar and download a new version of launcher.jar (that has a different version value), how do I replace the old version that I am currently running with the new version? That’s why I thought the version should be in a different jar file.

I could not have a version variable as you said but that would mean I would have to rehash everything each time the game starts which would be annoying, especially when there are lots and lots of files it would take a long time.

I also can’t have the resources in the jar file as I want it to be able to be modded easily

You replace the launcher.jar, use Runnable.exec to call “java -jar launcher.jar” and then System.exit(0).

EDIT: Never mind, forgot that the jar file will be locked by the JVM. What you can do is run another jar file that updates the launcher.jar using the above steps.

Ok, I only ever want to run one file though: Launcher.jar. I think i’ll have to put the version in a text file :confused:

Does Runnable.exec to call “java -jar .jar” work the same on all OS’s?
Edit: although I don’t want to exec “game.jar” because then people could just run it without having the latest update=bad
Edit2: using Runnable.exec seems the best way to run game.jar from launcher.jar. Is there a way to execute game.jar from launcher.jar without game.jar being able to be executed by itself?
Could I pass an argument in the exec command, eg a ‘key’ which only the launcher and game.jar know, so if you execute it without the key it doesn’t work
Edit 3: The ‘key’ idea works well although it must be really easy to crack if someone wanted to, but then again they can crack anything on the client side right?
when I use exec “game.jar” it works, but if i put game.jar inside a directory called “game” and then use exec “java -jar game/game.jar” it doesn’t work. Does anyone know why?

Try doing “java -jar ./game/game.jar”.

The key idea would need to be something public since yes it is really easy to figure out. For example in Windows’ Task Manager, I could choose to see the command that opened the application. The path to the executable and the arguments are both visible.

However, think about it, why would anyone go through all the trouble just to run game.jar by itself? :wink:

Haha that’s true, unless somebody didn’t want to update and somehow got an advantage from not updating :emo:

OK I must be doing something else wrong, ./game/game.jar and game/game.jar both work, but when I try to put my key on the end as an argument, it stops working. It’s something else in my program so I’ll try to figure it out. Thanks :slight_smile:

somewhat interested in this - we planned on doing this
but apart from the code, one problem was also - you would have to have a server for these updates - all that traffic and stuff
so we decided for now, just to do classic pc games patches

but its still a possibility - so keep us posted on this =D

Out of curiosity, why don’t you want to do as Sproingie suggested and use an already-built solution? You’re re-inventing the wheel.

One thing to consider is that not all users will have “java” on their PATH (in fact, most won’t if you’re targeting non-technical people), in which case just executing “java” as the executable may not work. You’ll probably have to either divine the java install location on the system, or ship a JVM and always use that.

There, fixed that for you :slight_smile:

It’s finished now :slight_smile: I didn’t want to use JNLP, I wanted complete control over the files. Anyway, I wanted to make my own version so I knew what was happening. I don’t have java on my path - it still works. (When I run bat files, I have to type “c://program files(x86)/java/…/java -jar file.jar”) but when I use exec I don’t need to?


C:\...\test\game>java -jar game.jar
'java' is not recognized as an internal or external command,
operable program or batch file.
Press any key to continue . . .

Cero: Downloading patches annoy some people quite a lot. From what I’ve seen, some people just can’t be bothered going to a website and downloading patches (Especially if they are frequent). Hosting a server will cost quite a lot yes so maybe it’s not the best option, but there is another way. You can use HTTP post and php scripts (php will do MD5 hashing etc) and download the files from there. As long as your webhost has enough bandwidth this should be fine. Then again i guess if the game is good enough it doesn’t matter how you do it because people will download it anyway.

I’m fairly certain that on Windows Java gets magically set up to work fairly well even if it’s not on the PATH (gets a link put in some system folder somewhere?). In any case, I’d still be wary even if it works for you. I’m pretty sure you won’t be as lucky getting it to work on *nix without it being on the user’s PATH.

On Windows systems, java.exe, javaw.exe, and javaws.exe are put in C:\Windows\System32

because its very java-ish - which I dont want
in the end out game is just an exe, nobody immediately sees java - this is important
also JNLP doesnt work like I want this thing here to work
and I need more control

not looked too deeply into getdown, but spiral knights used it I think

Hmm I’m seeing this quite frequently…why are you embarrassed to be using Java?

I think you aim to implement an autoupdate similar to how minecraft does it.
Im shure there are some technical autopsies on the web on how this is managed.

[quote]Hmm I’m seeing this quite frequently…why are you embarrassed to be using Java?
[/quote]
Its about usability and looking professional.
JNLP does not, it looks freakish.
I can understand the aim to hide the backend from the user, as its of no interest to the game to
bother the user with such details.

Its a consumer product, not a commercial back-end application.

I talked about this before and Damocles just said it

first of all its about hiding technology - the user doesnt want to be confronted with any of that - he just dbl clicked the shortcut or exe, and the game comes up
I would just repeat Damocles now

the other thing is “Java is slow and stupid” - People hate java
especially people who have no idea what they are talking about, like to judge things based on a mainstream opinion
notch still gets questions like “why java - I hear its horribly slow” “java sucks”

and in fact - when I distribute a game, using a private JVM, it is, for all intents and purposes, a native binary just like any other C++ program, because I just call java.exe with some parameters; and wrapping it is even better
so under the hood there may be java - but nobody cares

I dont care what kind of cylinders the engine of my car has - and I especially dont wanna know if there is some controversy about its performance

but as I said its also about control - I would want to have really reliable mmorpg-style autoupdater

btw roland

I personally wouldnt need all that exec

I use batch files anyway, which I eventually compile to exe files

in the batch I can just say “run autoupdater” and then next line “run game” which runs it afterwards