Jump to content


Photo

Add online highscores to your HTML5 games


  • Please log in to reply
57 replies to this topic

#31 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9397 posts
  • Version:Unknown

Posted 07 December 2011 - 04:32 AM

Some browsers just down support cross domain requests, so as much as YoYo may want to have a database set up for everyone to use, it's just not going to work. I doubt they are working on HTML5 online highscores, and I would rather their efforts were placed elsewhere.

As for the PHP scripts, yes, there's heaps of additional things you could get it to do, this tutorial is just to get you started ;)
  • 0

#32 kburkhart84

kburkhart84

    Firehammer Games

  • GMC Member
  • 1910 posts
  • Version:GM:Studio

Posted 07 December 2011 - 02:52 PM

Some browsers just down support cross domain requests, so as much as YoYo may want to have a database set up for everyone to use, it's just not going to work. I doubt they are working on HTML5 online highscores, and I would rather their efforts were placed elsewhere.

As for the PHP scripts, yes, there's heaps of additional things you could get it to do, this tutorial is just to get you started ;)


Actually, I was figuring Yoyo could use SQLite if they wanted to implement the thing. It wouldn't work cross-domain either most likely, but it doesn't require a database, rather creates a file in the server space, so it would make sense for them to do it that way. I agree that there are better things they can and should be doing though.
  • 0

#33 True Valhalla

True Valhalla

    ಠ_ಠ

  • Retired Staff
  • 5258 posts
  • Version:GM:Studio

Posted 11 December 2011 - 01:41 AM

I've never really understood the appeal of stand-alone high score systems like this, because they are too vulnerable to exploitation. Are there any counter-measures which stop clients sending fake scores..? Is that even possible without server side verification of their game session along their way?

I'd love to use this, but a flaw like that can make high score systems pointless.
  • 0

#34 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9397 posts
  • Version:Unknown

Posted 11 December 2011 - 02:33 AM

The highscore itself is encrypted to some extent. The name is sent in plain text. To be able to submit a score, the user needs to know the security key, which GM does a good job of hiding with it's obfuscation.

One thing that could be added is a system to check that the score hasn't already been submitted, which is kinda half set up. Currently the system stores the code used for submission, but something would need to be added to stop the same score having the same code. I'd probably add the linux time stamp (or some other date) to the score, so you would submit string(score)+"|"+timestamp. The system already has the ability to include the | in the string being encrypted. You would then take the output and split off the score in the PHP script, and also check that the same code hasn't already been submitted.

That would stop the same code being used to submit the same score multiple times, but not stop the same score being submitted twice if it were earned. It would also make the encryption slightly harder to hack, as it introduces something which the player has no knowledge of it's value.

That's about as good as I know, but I'm not sure if much else can be done without moving everything client side (which would probably be too slow for an HTML5 game).

Personally, I haven't had any trouble with hackers (that I know of :whistle:). I'd look into further options if it became an issue.

In reality, it's risk free. If people hack it, I'll delete the cheat scores. If lots of people hack it, I'll just remove the online high scores. But why not have online high scores if it encourages more people to play? There's no money at stake, the most I have to lose is the online highscores, which I otherwise wouldn't have added. I really don't understand why you would shy away from them simply because of the potential actions of a few?
  • 0

#35 True Valhalla

True Valhalla

    ಠ_ಠ

  • Retired Staff
  • 5258 posts
  • Version:GM:Studio

Posted 11 December 2011 - 02:51 AM

I really don't understand why you would shy away from them simply because of the potential actions of a few?


They're the ones that you need to watch out for though ;) Of course, for high scores it's not really a big issue.
  • 0

#36 metaaldetectie

metaaldetectie

    GMC Member

  • New Member
  • 4 posts

Posted 01 January 2012 - 02:14 PM

The high score works fine only I find it annoying that if you don't fill in a name you have an empty field.

Is there a possibility with gml or php to require filling out a name, so you have to fill in something.
  • 0

#37 kburkhart84

kburkhart84

    Firehammer Games

  • GMC Member
  • 1910 posts
  • Version:GM:Studio

Posted 01 January 2012 - 06:09 PM

The high score works fine only I find it annoying that if you don't fill in a name you have an empty field.

Is there a possibility with gml or php to require filling out a name, so you have to fill in something.


Why don't you do it the easy way? In the script where you are receiving the name, when enter is pressed, make sure it is not empty. If it is, either do nothing(expecting a name), display a message that they need to type a name, or simply put a substitute. You do this in the gml, not in the PHP, simply because it is easier than modifying the PHP, unless you know what you are doing.
  • 0

#38 metaaldetectie

metaaldetectie

    GMC Member

  • New Member
  • 4 posts

Posted 01 January 2012 - 08:24 PM

when enter is pressed, make sure it is not empty. If it is, either do nothing(expecting a name), display a message that they need to type a name, or simply put a substitute.


Can you give me an example in gml?
  • 0

#39 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9397 posts
  • Version:Unknown

Posted 01 January 2012 - 11:03 PM


if (global.name != "")

{

  submit();

}

else

{

  show_message("Please enter your name");

}


  • 0

#40 mikebio

mikebio

    GMC Member

  • New Member
  • 18 posts
  • Version:GM:HTML5

Posted 28 January 2012 - 08:36 PM

This all seems a bit too complicated. I just purchased this with hopes that the game I am trying to make would be less complicated but now I am not too sure.

I want a homescreen that the user can enter his/her name and then hit go. If the name exists in a database, then it will pull up the users previous score. If not, then it will create the user with whatever name was entered.

This is being done as a closed study, and that is why I do not have a password.

Can you help with this Dave? You seem to know what you are talking about! I have the DB and table created (with 2 columns: name, score). I am just confused on the whole GM extensions and scripts and like I said, it all seems too complicated. I read your code but just couldn't understand a lot of it (such as strip_tags(mysql_real_escape_string))

Hope you can help,

Thanks,
  • 0

#41 kburkhart84

kburkhart84

    Firehammer Games

  • GMC Member
  • 1910 posts
  • Version:GM:Studio

Posted 28 January 2012 - 09:18 PM

I'm not Dave :), but I can tell you that this extension was not made for what it looks like you are looking for.

My recommendation would be to learn a little PHP and MySQL. I don't know enough myself, mainly because I don't really need to learn any, but I DO know that what you want isn't that complicated once you have the basics of PHP and MySQL down.

Visit w3schools.com for a bunch of tutorials on HTML, PHP, MySQL, and a few other things.
  • 0

#42 mikebio

mikebio

    GMC Member

  • New Member
  • 18 posts
  • Version:GM:HTML5

Posted 28 January 2012 - 10:58 PM

I'm not Dave :), but I can tell you that this extension was not made for what it looks like you are looking for.

My recommendation would be to learn a little PHP and MySQL. I don't know enough myself, mainly because I don't really need to learn any, but I DO know that what you want isn't that complicated once you have the basics of PHP and MySQL down.

Visit w3schools.com for a bunch of tutorials on HTML, PHP, MySQL, and a few other things.


Hey thanks for the reply! I do know PHP and MySQL quite well... but the problem is I am new to Game Maker. I just can't seem to get everything talking to each other! Actually, I have to go read some GM tutorials because I don't even know how to get text from a user! I have the "Please Enter Your Name" done but that's about it!
  • 0

#43 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9397 posts
  • Version:Unknown

Posted 29 January 2012 - 01:21 AM

The download contains a "Davejax" extension, this can be used to make the AJAX call from GM to your PHP script. You say you know PHP/MySQL quite well, have you set up scripts to retrieve and send the name and score and have it do what you want? If you have that side sorted, the GM side is not hard to set up.

To get text from a user, use the variable "keyboard_string". When the player types something, whatever they type is stored in this variable. Use draw_text to draw it's value on the screen so the player can see what they are typing.

mysql_real_escape_string() is a sanitising function to stop hacking via SQL injection. It just adds escape characters before things like ' and " so if the player tries to trick your query into doing something it shouldn't then this helps to stop it.

string_tags() stops players from entering HTML code as a name, causing the page to display differently, or injecting javascript, etc.
  • 0

#44 mikebio

mikebio

    GMC Member

  • New Member
  • 18 posts
  • Version:GM:HTML5

Posted 29 January 2012 - 06:18 PM

The download contains a "Davejax" extension, this can be used to make the AJAX call from GM to your PHP script. You say you know PHP/MySQL quite well, have you set up scripts to retrieve and send the name and score and have it do what you want? If you have that side sorted, the GM side is not hard to set up.

To get text from a user, use the variable "keyboard_string". When the player types something, whatever they type is stored in this variable. Use draw_text to draw it's value on the screen so the player can see what they are typing.

mysql_real_escape_string() is a sanitising function to stop hacking via SQL injection. It just adds escape characters before things like ' and " so if the player tries to trick your query into doing something it shouldn't then this helps to stop it.

string_tags() stops players from entering HTML code as a name, causing the page to display differently, or injecting javascript, etc.


Dave do you think we can exchange email address and get this sorted out? I have tried following this tutorial as well (http://gmc.yoyogames...howtopic=520198) but still no luck. I don't need anything too complicated (as described) but I do need this for my PhD research.

I have the main page setup so that a user can enter a name and it is saved as a global variable called name (global.name). I have the database with the table called game, 2 columns (name, qc).

Basically once the user enters his/her name, I just want to get the qc value from that user name. If the name doesn't exist, then insert the name into the table. It is not that complicated, but I can't solve this with GM.

I am confused on what I need. I have a php file called dbcon.php that has
<?
   // database variables
   $dbHost = "localhost";
   $dbName = "<name here>";
   $dbUser = "<user here>";
   $dbPass = "<password here>";

   // database connection functions
   function dbConnect() {
      global $dbCon, $dbHost, $dbName, $dbUser, $dbPass;
      $dbCon = mysql_connect($dbHost,$dbUser,$dbPass);

      return mysql_select_db($dbName);
   }
   
   function dbClose() {
      global $dbCon, $dbHost, $dbName, $dbUser, $dbPass;
      mysql_close($dbCon);
      unset($dbCon);
   }
?>

What should my javascript file look like? Honestly, at this point I'll give anyone access to my DB and everything just to get this working. Thanks,

Mike
  • 0

#45 holgersson1988

holgersson1988

    GMC Member

  • GMC Member
  • 151 posts
  • Version:GM:Studio

Posted 22 March 2012 - 09:33 AM

This was really helpful. Is it possible to make it work from the Windows runner? Still using GM:HTML5 but running in windows mode.

Thanks for the post!

/Holgersson Entertainment¨
@HolgEntertain
  • 0

#46 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9397 posts
  • Version:Unknown

Posted 22 March 2012 - 07:13 PM

If you can use DLLs in GMHTML5 (haven't tried) then use 39DLL and check out the HTTP tutorial.

It's definitely doable in GM8. 1.
  • 0

#47 GerardoLegend

GerardoLegend

    GMC Member

  • GMC Member
  • 9 posts
  • Version:GM:Studio

Posted 26 March 2012 - 12:29 PM

Hi Dave!

I don't want to be of any trouble but I followed step by step your tutorial and I hit a dead end. Just to inform you before - I also have 1and1 hosting, so things are a tad bit tricky.

My issue is after I plug my ip address in with the scripts, in which are easy to follow, I'm thinking it would work out but the highscores aren't showing. Everything is in the same domain, yet I wonder if I did something wrong? The php files are in their own directory withing the same domain. As for my html5 game, even though the game is in the same domain with the scripts in its own directory, the high scores don't draw.

I did check to see if the tables had any data submitted by my test, and it looks like it does but somehow the game doesn't draw it.

again, I followed your tutorial step by step. the database is there, the tables are there, the key is there, the php with my db info is there. . . ugh.

here is your example live on my domain: My link (which is in the same directory of the php files)

I just get nothing. :confused:
  • 0

#48 GerardoLegend

GerardoLegend

    GMC Member

  • GMC Member
  • 9 posts
  • Version:GM:Studio

Posted 26 March 2012 - 09:13 PM

Also, When I tried to clear the php header, I didn't know exactly what should I replace it with.

I'm confused if I should replace it with header("Content-type: text/plain"); or header("location: www.darkzeta.com");

I've never programmed in PHP, and I don't know what is what even if I read about the basics, I need examples to see what does what. I see that headers have lots of definitions. which one is the right one for your highscore example if I need to replace the header with something else?
  • 0

#49 GerardoLegend

GerardoLegend

    GMC Member

  • GMC Member
  • 9 posts
  • Version:GM:Studio

Posted 27 March 2012 - 02:34 AM

update---

Well I finally have the database being updated by the html5/ajax/php combo! But I still don't see the results in my game.

I went in to redo step by step of the tutorial. What I messed up in the submit part is the gamed01. I got confused with with it, but now I understand it better.

update02-----

FINALLY I got it going ::lmao:: . damn. I derp really bad. Like super retarded derp that lasted 48 hours. ugh. It was a god damn typo on the address part of the getscores(); script. highscore isn't plural. lol

but I learned a valuable lesson doing this with php and game maker.

Thank you dave for the tutorial and ignoring me. lol Be on the look out for your name on the credits page/NES manual/ingame.
  • 0

#50 Dangerous_Dave

Dangerous_Dave

    GMC Member

  • Global Moderators
  • 9397 posts
  • Version:Unknown

Posted 27 March 2012 - 03:50 AM

Haha you posted at 1:30AM my time, then I was at work all day, and have only just got home! :P

Great to see you got it working, I probably shouldn't mention that if you want more secure high scores, you can use the Playtomic API with a wrapper extension... :whistle:
  • 0

#51 nujuat

nujuat

    Alex Tritt Games

  • GMC Member
  • 267 posts
  • Version:GM:Studio

Posted 26 April 2012 - 10:38 PM

Thanks a lot Dangerous Dave! I just got my new game "synced" with my new database on my new site. Hopefully I will release it soon. But yeah, thanks for the tutorial!
  • 0

#52 Vallo92

Vallo92

    GMC Member

  • GMC Member
  • 57 posts
  • Version:GM:Studio

Posted 01 February 2013 - 04:06 PM

Thanks!
  • 0

#53 ShaunS

ShaunS

    GMC Member

  • GMC Member
  • 89 posts
  • Version:Unknown

Posted 02 August 2013 - 12:02 AM

I just started using this method since Playtomic bit the dust. 

 

It works great! Only for some reason Internet Explorer hates it. The game sends scores just fine. The database receives them and does its thing.

 

Receiving scores from the database however only works for every browser (seriously, all of them) other than IE.  (Ver 10 used, debug mode allowed me to test in 9/8/7 'Modes' which also all failed.)

 

Weirdly, the browser is getting the data absolutely fine.  If I look in the debug at the GET request, the response body is filled with scores in the expected format: "name|score|name|score" etc. But the 'code' variable that this information is sent to is totally empty. Even before splitting up the data, the data just never makes it into the game. 

 

It's as if the game is refusing to wait for the js script to return a value before carrying on and therefore never getting filled? I haven't a clue.

 

I don't know if this is on my end, YoYo's end, or Internet Explorer's end. It's making me pull my hair out.


  • 0

#54 ShaunS

ShaunS

    GMC Member

  • GMC Member
  • 89 posts
  • Version:Unknown

Posted 05 August 2013 - 09:21 AM

Nobody have any ideas? I don't know if this is a GM bug, an IE bug or a My Game bug.


  • 0

#55 demkaio

demkaio

    GMC Member

  • New Member
  • 15 posts
  • Version:GM:Studio

Posted 03 September 2013 - 08:42 AM

Thanks Dave, great tutorial.

 

I am having some trouble however, my high scores do not seem to draw in game.

As far as I can tell the scores are submitted, I can see names loaded onto the table.

They just dont seem to be drawn ingame.

 

Ive followed the tutorial 3 times now, I can see what I am doing wrong.

 

Any Ideas?

 

Cheers

 

 

edit** Running your demo also doesnt seem to draw scores :S


Edited by demkaio, 03 September 2013 - 08:44 AM.

  • 0

#56 Noritox

Noritox

    GMC Member

  • GMC Member
  • 279 posts
  • Version:GM:Studio

Posted 16 November 2013 - 05:03 PM

Having the same issue as Demkaio. I had this working on another game, but that was over a year ago. Wondering if a GM Update made this method no longer work?

 

EDIT - I fixed it. GM Is handling arrays differently now.

 

Here's how to fix this script.

Open your scripts and open getscores.

Find this

for (i=0; i<num; i+=1)
{
  name[i] = explodearray[i*2];
  num[i]  = explodearray[i*2+1];
}

Change num[i] to num2[i]

 

Now goto your objects and open the object viewscores, open the script in your draw event and find this code

for (i=0; i<count; i+=1)
{
  draw_set_halign(fa_left);
  draw_text(30, 70+i*30, " "+string(name[i]));
  draw_set_halign(fa_right);
  draw_text(360,70+i*30," "+string(num[i]));
}

Change num[i] to num2[i]

 

And that is all you need to do to fix this method.

 

 

The problem?

In simple terms: He was using num as a variable and num[] as an array. When GM Seen num being used outside of an array it wouldn't work.. :)

 

Hope this helps someone.


Edited by Noritox, 16 November 2013 - 05:29 PM.

  • 0

#57 beeproductions

beeproductions

    Helping gmc users

  • GMC Member
  • 1309 posts
  • Version:GM:Studio

Posted 19 January 2014 - 12:56 AM

For some reason doesn't work:(..tried everything..got my db connected as intended..got my sql structure imported from the archive..deleted/installed the gex again..double checked the code..and still nada

 

http://seneka-studio...m/skill/rr.html <-Try it out..no errors but no score submit aswell. :-|

 

Using GM:Studio professional v1.2.1224


Edited by beeproductions, 19 January 2014 - 12:58 AM.

  • 0

#58 _175771

_175771

    GMC Member

  • GMC Member
  • 30 posts
  • Version:Unknown

Posted 24 March 2014 - 07:29 AM

Unfortunately I'm having trouble with this. For some strange reason numbers being sent to the data base are saved as other numbers.

As an example any 1's are saved as 8 so the score 15 becomes 85 :(

a score of 71 becomes 58. I have triple checked to make sure nothing weird is happening to the score value sometime before being handled by the extension. 

One more example= 18 becomes 88

 

I have no idea what is causing this. I am currently using the default example file and nothing else. 

The only thing I did differently  than was instructed was I named my own database and changed the $dbDatabase database name in the php file to match


Edited by _175771, 24 March 2014 - 07:49 AM.

  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users