Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  Autoupdater  (Read 4919 times)
0 Members and 1 Guest are viewing this topic.
Offline roland
« Posted 2012-01-01 05:17:28 »

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



Offline sproingie

JGO Kernel


Medals: 202



« Reply #1 - Posted 2012-01-01 05:42:12 »

You're reinventing JNLP and GetDown.  You might want to investigate those two before pursuing your own solution.
Offline roland
« Reply #2 - Posted 2012-01-01 06:07:41 »

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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Z-Man
« Reply #3 - Posted 2012-01-01 07:14:09 »

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 Grin
Offline roland
« Reply #4 - Posted 2012-01-01 09:45:12 »

Thanks for the reply, Z-Man.
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.
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
Offline ra4king

JGO Kernel


Medals: 347
Projects: 3
Exp: 5 years


I'm the King!


« Reply #5 - Posted 2012-01-01 13:20:51 »

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.

Offline roland
« Reply #6 - Posted 2012-01-02 01:24:20 »

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 :/

Does Runnable.exec to call "java -jar <file>.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?
Offline ra4king

JGO Kernel


Medals: 347
Projects: 3
Exp: 5 years


I'm the King!


« Reply #7 - Posted 2012-01-02 08:02:04 »

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

Offline roland
« Reply #8 - Posted 2012-01-02 09:41:53 »

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  Smiley
Offline Cero
« Reply #9 - Posted 2012-01-03 00:51:18 »

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

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline BoBear2681

JGO Coder


Medals: 18



« Reply #10 - Posted 2012-01-03 02:56:22 »

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.
Offline Riven
« League of Dukes »

JGO Overlord


Medals: 801
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #11 - Posted 2012-01-03 03:01:10 »

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 Smiley

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline roland
« Reply #12 - Posted 2012-01-03 04:10:22 »

It's finished now Smiley 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?

1  
2  
3  
4  
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.



Offline BoBear2681

JGO Coder


Medals: 18



« Reply #13 - Posted 2012-01-03 13:46:48 »

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?

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.
Offline ra4king

JGO Kernel


Medals: 347
Projects: 3
Exp: 5 years


I'm the King!


« Reply #14 - Posted 2012-01-03 13:55:07 »

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

Offline Cero
« Reply #15 - Posted 2012-01-03 13:57:26 »

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.

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

Offline ra4king

JGO Kernel


Medals: 347
Projects: 3
Exp: 5 years


I'm the King!


« Reply #16 - Posted 2012-01-03 14:06:27 »

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

Offline Damocles
« Reply #17 - Posted 2012-01-03 14:09:20 »

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?

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.

Offline Cero
« Reply #18 - Posted 2012-01-03 14:49:40 »

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

Offline Cero
« Reply #19 - Posted 2012-01-03 15:01:06 »

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

Offline roland
« Reply #20 - Posted 2012-01-04 03:10:55 »

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
What about linux / mac?
I didn't know you could convert a bat to an .exe  Shocked Huh
Offline Shazer2

Junior Member


Medals: 3


Aspiring developer.


« Reply #21 - Posted 2012-01-04 03:12:04 »

http://download.cnet.com/Bat-To-Exe-Converter/3000-2069_4-10555897.html

That might help, roland.

"When you want to be successful as bad as you want to breathe, then you will be successful." - Eric Thomas
Offline roland
« Reply #22 - Posted 2012-01-04 03:18:06 »

Thanks, this looks like a better way to go - if theres something similar on mac and linux.
Offline Damocles
« Reply #23 - Posted 2012-01-04 12:13:00 »

Nice little prog,

here a better download link (directly from the maker and without the cnet crap)

Bat To Exe Converter:
http://www.f2ko.de/programs.php?lang=en&pid=b2e

Offline Cero
« Reply #24 - Posted 2012-01-04 15:06:34 »

I always use batch to exe

well on linux you just change the bat to a .sh file, which can be run potentially - put packages on ubuntu and stuff - its all complicated

I asked about Mac and I think it was Eli Delventhal who said, its really easy to do with an app maker or something which is already there

also - since mac is unix stuff also, this batch file, (optionally renamed to .sh, you dont really have to) will work there aswell
of course you gotta always have your private jvm and stuff

Offline BoBear2681

JGO Coder


Medals: 18



« Reply #25 - Posted 2012-01-04 15:39:21 »

On OS X, you really want to create a .app bundle.  Most OS X users are not savvy enough to unzip & run a shell script.  Like Cero said, .app bundles are discussed on this forum.  Here's the first thread I found, but there may be better ones.

I'd bet big money that most folks running Linux are geeky enough to be cool with running a shell script from the command line, so the lowest common denominator approach of a zip file/.sh script is probably sufficient there.  Doing anything more is just icing on the cake.
Offline roland
« Reply #26 - Posted 2012-01-04 22:01:21 »

How do you ship your game with a private JVM?
and all you need to do is rename .bat to .sh? I thought the syntax inside would be different too?
what does the inside of your .bat file look like Cero?
Offline ra4king

JGO Kernel


Medals: 347
Projects: 3
Exp: 5 years


I'm the King!


« Reply #27 - Posted 2012-01-04 22:17:01 »

You ship the private JVM by doing just that, bundle the jre folder in your program files.

And no, there is no syntax difference because it's just 1 command: java + parameters.

Offline BoBear2681

JGO Coder


Medals: 18



« Reply #28 - Posted 2012-01-04 23:52:38 »

Actually there will be differences.  Any path separators (e.g. in the relative path to java in your packaged JVM) should be switched to '/' from '\'.  You'll also want to start your shell script with a shebang:

1  
2  
#!/bin/sh
./jvm/bin/java -jar whatever.jar


Also, your script would ideally come pre-chmodd'd 755, though I'm not sure that the zip file format preserves file permissions across all *nixes.
Offline Cero
« Reply #29 - Posted 2012-01-05 02:19:05 »

How do you ship your game with a private JVM?

you just put a jre folder in your game folder strucutre when shipping.


and all you need to do is rename .bat to .sh? I thought the syntax inside would be different too?
what does the inside of your .bat file look like Cero?

bobear and r4king said it

normally the batch just runs on linux, but if you ship it you should really do a proper shell script, which is nothing more than what bobear wrote.
you put in jvm arguments and game arguments and there you go

in case of autoupdater you have simply 2 calls, one after another

Pages: [1] 2
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

Pippogeek (37 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (42 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (61 views)
2014-09-21 02:42:18

BurntPizza (30 views)
2014-09-21 01:30:30

moogie (36 views)
2014-09-21 00:26:15

UprightPath (49 views)
2014-09-20 20:14:06

BurntPizza (52 views)
2014-09-19 03:14:18
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!