php - How would I interconnect a server with a game launcher in Java? -
i'm working on game in java. creating launcher game , wrapping .exe wrapper. need getting game connect sort of server , check if credentials user true:
- username real.
- password matches listed username.
- user has bought game (true/false) aka user premium?
it has work website uses php , html. when user creates account, stored both in website, , in game server itself. also, if there's update game, automatically updates getting files server.
the concept rather similiar games minecraft , planetside 2.
depending on complexity or level of interaction require, done simple making request particular page on web server, , supplying necessary information in query string (alternatively use post).
// construct query string proper username , password url url = new url("http://www.yoursite.com/verify.php?username=happy&password=pants"); try (bufferedreader in = new bufferedreader(new inputstreamreader(url.openstream()))) { stringbuilder sb = new stringbuilder(); (string s; (s = in.readline()) != null;) sb.append(s); switch (sb.tostring().trim()) { case "welcome": joptionpane.showmessagedialog(null, "welcome!"); // proceed game break; case "shut , pay me": joptionpane.showmessagedialog(null, "you owe me money first!"); break; case "no such user": joptionpane.showmessagedialog(null, "go away!"); // recursively delete files... break; } }
where verify.php has php code looks like
// set database stuff... // query database $query = sprintf("select * friends users username='%s' , password='%s'", mysqli_real_escape_string($_get["username"]), mysqli_real_escape_string($_get["password"])); if (($result = mysqli_query($query)) && ($row = mysqli_fetch_assoc($result))) { if ($row["license"] == "premium") { echo "welcome"; } else { echo "shut , pay me"; } } else { echo "no such user"; }
but basic example of could do, , shouldn't followed verbatim. shouldn't pass these values through query string of url (perhaps prefer post rather here), , above else shouldn't store or pass password in plain text either (i.e., hash first using md5, sha1, or hash of choice). did sake of simplicity.
for more complex, might require 1 of other methods you've been given, such use of sockets, web services, etc.
if you'd more information on working urls in java, can found here. or if you'd more information on php's mysqli, can here, or substitute own package of choice pear.