Creating your own asynchronous server... •--•

StormyStudioStormyStudio United KingdomMember Posts: 3,989
edited July 2014 in Working with GS (Mac)
Afternoon world.

Since there may be a few of us trying to setup our own async game server systems. I thought I'd start a general thread to discuss any problems/progress people are having and keep a running update on what I've got working, or what problems I hit..

I'm trying to do it, I think @jonmulcahy is too... is anyone else tinkering away?

It's possible to do it now we have the SEND/RECEIVE TABLE URL behaviours (currently in the nightly release for Pro members).

WHAT I'VE GOT GOING ON SO FAR
- Access to facebook friends list or users details, using Facebook access tokens (Tutorial on this is on forum if interested)
- basic user registeration system working where a player can enter a user name and a password. If its a unique name its added to a players database table, if not a message is sent back to GS so they can try another name.
(Edit .1) - Now have unique 23 character gamer ids created and saved to players database and sent out to GameSalad.
- I've posted a few thing about multiplayer and some drawn process flow ideas on my blog.
(Edit.2) - Passwords are encrypted as soon as they arrive at my database, and the encrypted password is stored... so can be used for verficiation when they login. Yet to create the login side.

How's anyone else getting along on this?
«134567

Comments

  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited February 2014
    Update.. I now have it so when a new user registers a unique 23 character gamer id is generated (which is also checked to make sure it's not already in use (though unlikely), if it is it creates another). The id is sent back with the 'registered successfully message' and the id saved alongside their username and password on my database... time for a cuppa tea.

    Also passwords are now fully encrypted into a long string..
    This link Jon Mulcahy pointed me to has been a great help, along with google.
    http://php.about.com/od/security/
  • EireStudiosEireStudios Member Posts: 451
    I'm currently knee deep in creating a gym booking in app for a friend but I'm keeping an eye on your progress with great interest. I'm going to be making a login system myself once I get a few basic things done so I might have some questions on the whole security and password hashing when I get around to it ;) best of luck with everything man, sounds like your making great progress so far :)
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited February 2014
    UPDATE MY LOGIN SCRIPT IS WORKING

    After re-writing my 'Login' script twice and a lot of bug testing and fixing it is actually now working.

    So I can register a new unique username and have it saved on the database and now I can send login details to the server and have them approved or denied.

    Login Proces Flow:
    Username and password typed into boxes in gamesalad game.
    Player presses 'login'
    Username and password sent to php file on my server
    file is encoded into a readable format
    (the password is encrypted as it is encoded)
    username is firstly checked to see if it exists,
    then it finds the table row number of that user
    then it compares the encrypted password just sent, to the one stored alongside the username on the database.

    a separate table on my database is updated with a value.

    Back in gamesalad once it has successfully sent the username and password it waits 0.4 seconds then requests the table from the database that has the value of success or failure in .

    (One thing I need to read up on, is how to prevent an error where two people might be trying to log in at exactly the same time, will the php script only run for one? …etc)



    Slow progress… but progress all the same.

    Next is to make my basic setup a little prettier and smarter. Some things can be done directly in game salad i.e.:

    -Make the player enter their password twice to register, (check these are the same before sending)
    - Save login details so your automatically logged in when you load the game. (if registered/logged in successfully previously)
    - Log Out Button, have rules in gamesalad that will forget the saved login details. So to login the player would have to type a username and password again.


    … I'll post a vid when its further along and looking a little smarter… but I'll save that for another night.
  • EireStudiosEireStudios Member Posts: 451
    Could you shed some light on something for me mate, how did you search the table for the username and when you have found the username how did you get the row number? Also can the row number then be saved as an attribute? I've been trying to do this today with table search but I'm having a bit of trouble understanding it! :(
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited February 2014
    @EireStudios mine is an adaptation of the code on this page.
    http://php.about.com/od/finishedphp1/ss/php_login_code_4.htm

    The bit with:

    $check = mysql_query("SELECT * FROM users WHERE username = '".$_POST['username']."'")or die(mysql_error());

    That is searching the tables call 'users' for a username.


    then the this line makes an array and calls in $info out of what was found with the above code.

    while($info = mysql_fetch_array( $check ))



    Then this bit checks that the submitted password does'nt match the password in the array just collected.


    //gives error if the password is wrong

    if ($_POST['pass'] != $info['password']) {

    die('Incorrect password, please try again.');

    }



    .........
    .........


    It took a quite a long time and lots of googling to get my head around each function being used in the scripts on that link.

    I hope that is a help...

    Also in the above bits of code the '$_POST' variable is what they've called their incoming array, if your making used ot Jon Mulcahys setup for getting a JSON from gamesalad you'll be reading your data a little differently.. i.e. you'll have separated out a $username and $password variable it wont be held in an array still.

    ....

    Mental stuff.. only makes a little sense to me as I'd been trying learn Unity (Java) Scripting whilst waiting for multiplayer to come to GameSalad.

    Just shout if you want any help... I'll do my best, but learning as I go too... I'm pretty sure I started using GameSalad 4 years ago to avoid learning this stuff... ah well needs must.


    ...
    Oh and as for saving the row number as an attribute (variable in PHP). I tried but failed but might work now my script is functioning properly. I think in the above script the row number is stored in $check, but its an array that can't be easily displayed and so would need to be serialzed.. (I don't understand this stuff yet though.. just seen it in my travels)
    ...



  • EireStudiosEireStudios Member Posts: 451
    Cool thanks man, that makes some sense but I'm sure it will make a lot more sense while I'm playing around with it! This is a real learning curve for me also but I must say I'm really enjoying it :)
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    Yeah I'm enjoying the challenge of learning this stuff... very satisfying when something finally clicks (getting that facebook access stuff working previously was particularly cool).

    Though a lot of the time it does seem close to impossible and I'm still only on the login screen for my game. Also I realize I might need to learn more about server management, (if the game does well and has lots of players).. and server management does sound like a particularly hard and boring side of game design.

    I'm now using 'Komodo Edit 8' to code in, it's free and has a cool dark interface option..
    one day hopefully it will all make sense and I'll feel like ruddy Neo...

  • beefy_clyrobeefy_clyro Member Posts: 5,394
    I am keeping an eye on this and seeing how people overcome stuff. I am working on an app for my company which links to all our help sheets and help videos. Currently i'm just storing all this data inside tables from within the app.

    What I would eventually like to do is send a request from GameSalad upon launch to check the server, copy the table from there so any new help sheets or video will add dynamically as we add them to our site.

    No idea how feasible this is at the moment or where to even begin
  • zweg25zweg25 Member Posts: 738
    ur on top of this stormy! nice
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited February 2014
    Well this evening.. I made the gamesalad bits a little prettier and smarter..

    Here's a video showing my Registration and Login setup in action.



    It will eventually lead into an updated version of this menu I created back in October…

    Old menu I was developing in October


    Also at some point I'll need to make the dreaded custom keyboard… fingers crossed GameSalad improve theirs so I don't have to.
  • jorkosjorkos Member, PRO Posts: 353
    Thanks @StormyStudio for sharing this work in progress!! Does anyone know if there is a clean GS template for keyboard entry so that it can look like the standard iOS text entry?
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited February 2014
    Thanks @StormyStudio for sharing this work in progress!! Does anyone know if there is a clean GS template for keyboard entry so that it can look like the standard iOS text entry?
    I was searching for that very thing earlier… I could'nt find one.

    The one currently in GS does pop up the iOS keyboard but it's accompanied by the big white box and no control over how many letters are entered.. (I assume it still does this).
  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273
    Well this evening.. I made the gamesalad bits a little prettier and smarter..

    Here's a video showing my Registration and Login setup in action.



    It will eventually lead into an updated version of this menu I created back in October…

    Old menu I was developing in October


    Also at some point I'll need to make the dreaded custom keyboard… fingers crossed GameSalad improve theirs so I don't have to.
    Dude! You rock like a bolder! That's quite impressive! I'd pay to get my hands on that. :D
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited February 2014
    @Braydon_SFX thanks. Always good to Rock!*!*!*!

    It's yours for 1 million dollars!!

    ...Tricky one to pack up and sell to someone as you need setup the server stuff or explain how to... I guess as this stuff get's resolved people can start offering a full service... setup server, update PHP files, integrate with a GS project.

    ...

    Next to add is a 'loading wheel'... that can run whilst it retrieves the outcome. At the moment it's pretty instant from my local server, but I'm assuming once on a phone with dodgy 3G signal and a distant server the wait will be a bit longer.

    Also I need to build in some other outcomes e.g:
    - "No internet connection on device" (if user/login info is not successfully sent)
    - "Problem with the server" (if no outcome is received from Server)
    - Any more ?

    Then if logged in, send the user onto the main menu. If successfully registered either sent onto the main menu (with a welcome pop up), a tutorial, or straight into a random opponent game.
    ...
    ...
    Then onto retrieving and making game info tables...

    ...
    ...
    Also last night finally figured out how to make my game project more about skill and less about luck... (only took me about a years worth of thinking... must have been a slow year)
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited February 2014
    not much new progress on this. I've been reading up a lot on making a scalable server on Amazons AWS service... cool, powerful and very very geeky... and most of all hopefully relatively cheap.

    Added needed code so the users game ID is saved once they're logged in. This can then be used to load their game data (once I figure out the best way to do that).

    Other problems on the horizon... working out what to do when the players closes the game on their device and comes back. We don't have a way to know if a game has been reloaded (if not fully shut down), so either I need to have the game check the user is logged in (still has connection) every couple of minutes, or only when the game needs to send or receive data.

    Also need to look at the most streamlined way of integrating facebook a little more.
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited February 2014
    Quick Update...
    Sorting out the create new game instance functionality. Have it so in the game menu you press new game (once logged in), choose 'play random opponent' it sends new game table to the server... this generates a unique Game instance ID, checks it is definately unique... then adds it to the 'All active Games Table'... it has info like Player1's ID, what version of the game they're running (to stop any compatibility issues in the future), invitation status...and a selection of other things...

    What I'm struggling with is keeping track of the time, when moves are played, games started etc.... I know we have access to time in GameSalad... but this won't take your world position into account so could cause problems if someone is playing in Mumbai against someone in Brazil (random example).... so probably needs to be kept track of on the server side and not in Game... Hmm.. not sure how best to do this... any thoughts from someone else very welcome
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    could you do something crazy like upon account registration compare the local time against UTC time and store the difference on the server. then you could code all game logic against UTC time, but add/subtract the offset.
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    as a side note, while I've been finishing up a few kids games and porting some apps to the 100% indie store, I've also been looking at hosted servers. I came across digital ocean.

    https://www.digitalocean.com/

    looks pretty cool and only $5 a month. I signed up last night, i think i'm going to create a droplet on them this week just to play around with.
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    as a side note, while I've been finishing up a few kids games and porting some apps to the 100% indie store, I've also been looking at hosted servers. I came across digital ocean.

    https://www.digitalocean.com/

    looks pretty cool and only $5 a month. I signed up last night, i think i'm going to create a droplet on them this week just to play around with.
    Oooh worth a look... will read UP about them on the weekend.

    Cheers Jon..
  • tylerglessnertylerglessner Member Posts: 246
    Eagerly awaiting your opinions on digital ocean guys! @StormyStudio @jonmulcahy
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited February 2014
    Digital Ocean looks good and a little simpler to get your head around than Amazons AWS that I've been reading up on… but since I've kinda got a solid server on Amazon up and running and still think its cheaper (though more confusing) I'll stick with that.

    I think with Digital Ocean you'll still have to do some server setting up using Terminal to install what you need i.e. PHP and MySQL though I may be wrong. (Digital Oceans promo video does subtlety show the terminal window doing stuff right at the end…)… There pricing is a little more straight forward to understand...

    As for my time issue with my game… think I've sorted it… I can use time() in PHP which gives the Epoch time in seconds from a set date (1970 I think)… so that can be used globally… the if needed I can work out the difference between last move and current Epoch time and so display 'its been 2hrs since your last move' or what ever is called for.

    Info on PHP time and date here
    http://php.about.com/od/learnphp/p/php_calendars.htm
    and here
    http://www.sitepoint.com/working-with-dates-and-times/
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited February 2014
    ... and on to the next hurdle...

    Not sure if I'm over thinking this one... and maybe I just need to wait for the send and receive attribute ability rather than the current send/receive table .
    ...........................................................................................
    Current setup...

    1. Players presses a 'New Random Game' button.
    2. This updates a Table in GS with the users Id, and 8 other columns (some blank).
    3. It is sent to my Server
    4. It's read through, unique game id generated, time stamps added and it's all stored in my 'Main-Games-Table'.
    5. It's also stored in a 'NewGamesTable' on the database (which can be regularly cleared once the data has been read back by GS)
    ....
    6. Then I want to get the table back to GS.
    7. So I use GET to retrieve the table... this brings the whole table back with no way to tell the PHP file I only want the row that is specific to the generated game ID, or user ID.
    8. So it brings back the 'NewGamesTable' and I have to pick out the row I want in GS (if it's brought more than one back).
    9. I then send another Table back to the server to confirm I've received the needed data, so it can go in and remove the row from the 'NewGamesTable' to stop it ever getting too large... and cause unnecessary bandwidth usage.


    Seems like the only route at the moment but could seem a little much if accessing a table that thousands of others players are also writing to when they're exchanging game state data... with their opponent.

    Is there a sleeker way to achieve this?
  • freshworksplayfreshworksplay Member, PRO Posts: 67
    Using some sort of a temp table a possibility ?
  • freshworksplayfreshworksplay Member, PRO Posts: 67
    Please let me know if i could help with some hosting environment for FREE. (for testing purposes) Our main business is web hosting. So let me know your needs and w'll check what we could do. Hosting is based in EU!
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited February 2014
    Using some sort of a temp table a possibility ?
    That's sort of how I've got it set up... I'll need to make quite a lot of different temp tables so they're fit for purpose. As to share the data to and from GS and the server I need to input the exact header and footer in the PHP file which relates to the GS table and the table on the Server has predefined types for each column (i.e. integer, Text etc)...
    Please let me know if i could help with some hosting environment for FREE. (for testing purposes) Our main business is web hosting. So let me know your needs and w'll check what we could do. Hosting is based in EU!
    Thanks for the offer, but it's all being run locally at the moment and then I've either got a server setup on Amazon or with the same host I use for my website.


  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    now if we only have push notifications enabled, we could use the 'our own server' to manage a push notification server (no small feat) and take care of it all our selves.
  • JamieOneilJamieOneil Member Posts: 877
    as a side note, while I've been finishing up a few kids games and porting some apps to the 100% indie store, I've also been looking at hosted servers. I came across digital ocean.

    https://www.digitalocean.com/

    looks pretty cool and only $5 a month. I signed up last night, i think i'm going to create a droplet on them this week just to play around with.
    I might try using Digital Ocean when I start testing, I have used it in the past for something completely unrelated to GS but I'm going to look at other options first.

    It's interesting to see what people have been able to do with this new feature, I have been waiting a while for it too come and now it has I have finally, after all these years, decided to invest in a Pro membership. Can't wait to get involved!
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited February 2014
    I've got it working now so that the a new game instances details are saved on the server and sent back to GameSalad. The GS game then sends a success call back to the server which removes the imported row from a temporary data table, to save ever sending unnecessary data next time the table is requested by a player.

    Now I'm only getting the one row back from my newGamesTable on the server which is fine (as I'm the only one making new games), but to ensure it's future proof I want to search the imported table in GS and find the row number that matches my player1's ID… so I can delete the other rows that might refer to someone else's game who happens to be requesting the table at the same time. (Now I know the answer at the moment is row 1, but I still need the rules there to work.

    So I'm trying out the new Table function tableSearch()… but it's not playing ball. it returns a 0… when I know it should be returning row 1.

    Here's how my search is written out..

    tableSearch( game.NewGamesTable ," game.Gamer_ID ","column",1,1,40,"exact")

    Which should search my newly imported table, for the Players ID, in column, 1, between rows 1 to 40. And return the row number for me…. it does not… any thoughts?

    (I'll ask this in the nightlys thread as well, since the new function was introduced there)

    … I guess I could use loop instead to search but I hear its a lot slower.
  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    So I'm trying out the new Table function tableSearch()… but it's not playing ball. it returns a 0… when I know it should be returning row 1.

    Here's how my search is written out..

    tableSearch( game.NewGamesTable ," game.Gamer_ID ","column",1,1,40,"exact")

    Which should search my newly imported table, for the Players ID, in column, 1, between rows 1 to 40. And return the row number for me…. it does not… any thoughts?
    Posted in the Nightly thread, but will also answer here: Your "column" bit shouldn't be there. Replace it with "Col" instead.
Sign In or Register to comment.