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

13567

Comments

  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited February 2014
    Just finished redoing about 2 hours of GS work after the last saved project refused to open any more. That's the problem with working with the nightly build (more likely to get corrupted I guess).

    Luckily I do 'save as' pretty regularly so wasn't too bad but still frustrating having to go through the same bit of trial and error to get a rule working (because I couldn't remember the correct setup) or repeating the same slow licking of attributes to build up a rule. Anyway all back up and running now, back to where I was on the last vid.

    Also re-written the first of my PHP scripts to be use PDO mysql and not the old one... that's one down 7 or 8 to go... and is a particularly unsatisfying job... Progress is on stand still whilst I slowly go over the old work and update these scripts.

    ... and... 'Save as'.

    Edit: Now have my 2nd script working... the login functionality is back up and running and future proof.
  • EireStudiosEireStudios Member Posts: 451
    @StormyStudio‌
    Hi Jon, I have a quick question for you mate. My gym app is using mysql and php, does that mean I will run into problems because I'm not using the PDO mysql? I just don't want to rewrite everything, it was hard enough to get the mysql to work!

    Also well done on everything your doing, you seem to be getting very handy with all this server work :)
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited February 2014
    @StormyStudio‌
    Hi Jon, I have a quick question for you mate. My gym app is using mysql and php, does that mean I will run into problems because I'm not using the PDO mysql? I just don't want to rewrite everything, it was hard enough to get the mysql to work!

    Also well done on everything your doing, you seem to be getting very handy with all this server work :)
    Hey... It would seem to depend on a few things. If you're never going to update the PHP install on your server past the current one you should be ok. But that depends where you host it and if you control the server or not. i.e. my website space is running on a normal web domain host and they emailed recently saying they were updating PHP and I should check to make sure it won't break my site... (I never checked, and it never broke... I win that round.. )

    mySQL is going to be phased out by PHP as it's very old, and things have moved on. It is advised new projects are created with a different option i.e. mySQLi or PDO...

    Here's a good explanation of what is going on and tries to help you know whether you should update your code.

    http://stackoverflow.com/questions/13944956/the-mysql-extension-is-deprecated-and-will-be-removed-in-the-future-use-mysqli/13944958#13944958

    PDO seems to be easier to move to than mySQLi ... but take a look at both and see what you prefer... I was only stumbling through with mySQL so makes sense for me to learn a new one before I get too far.

    I'm only on my 2nd script with PDO now... it does seem more secure and creates cleaner code.

    PM me if you decide to change your code to PDO... I might be able to help as I imagine we both started our code off with Jon Mulcahys original files.

    You only need to update bits of code that are dealing with the server.

    ie. connecting to server, instead of your current PHP script you can use this:

    // connect to server

    /*** mysql hostname ***/
    $dsn = 'mysql:host=localhost;dbname=game1';

    /*** mysql username ***/
    $username = 'root';

    /*** mysql password ***/
    $password = 'root';

    /*** connected to server ***/

    $db = new PDO($dsn, $username, $password);


    .....
    Here's a very handy walkthrough on updating your mySQL script:
    http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers

    As for 'being handy with this server work', thanks.. I keep reading a lot and about 2% of it sinks in. I'm definitely enjoying the challenge at the moment, and their is an end goal.. 'my game' that I'm hoping to make.

    You'll have to share a vid of your app once it's done.
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    I've just put together a useful list of PHP code to work with PDO...
    These are the main bits of code I'm adapting to work with my scripts. I'll add one for creating bigger (multidimensional) arrays later.

    http://stormystudio.com/blog/?p=310
  • EireStudiosEireStudios Member Posts: 451
    @StormyStudio‌
    Hi Jon, I have a quick question for you mate. My gym app is using mysql and php, does that mean I will run into problems because I'm not using the PDO mysql? I just don't want to rewrite everything, it was hard enough to get the mysql to work!

    Also well done on everything your doing, you seem to be getting very handy with all this server work :)
    Hey... It would seem to depend on a few things. If you're never going to update the PHP install on your server past the current one you should be ok. But that depends where you host it and if you control the server or not. i.e. my website space is running on a normal web domain host and they emailed recently saying they were updating PHP and I should check to make sure it won't break my site... (I never checked, and it never broke... I win that round.. )

    mySQL is going to be phased out by PHP as it's very old, and things have moved on. It is advised new projects are created with a different option i.e. mySQLi or PDO...

    Here's a good explanation of what is going on and tries to help you know whether you should update your code.

    http://stackoverflow.com/questions/13944956/the-mysql-extension-is-deprecated-and-will-be-removed-in-the-future-use-mysqli/13944958#13944958

    PDO seems to be easier to move to than mySQLi ... but take a look at both and see what you prefer... I was only stumbling through with mySQL so makes sense for me to learn a new one before I get too far.

    I'm only on my 2nd script with PDO now... it does seem more secure and creates cleaner code.

    PM me if you decide to change your code to PDO... I might be able to help as I imagine we both started our code off with Jon Mulcahys original files.

    You only need to update bits of code that are dealing with the server.

    ie. connecting to server, instead of your current PHP script you can use this:

    // connect to server

    /*** mysql hostname ***/
    $dsn = 'mysql:host=localhost;dbname=game1';

    /*** mysql username ***/
    $username = 'root';

    /*** mysql password ***/
    $password = 'root';

    /*** connected to server ***/

    $db = new PDO($dsn, $username, $password);


    .....
    Here's a very handy walkthrough on updating your mySQL script:
    http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers

    As for 'being handy with this server work', thanks.. I keep reading a lot and about 2% of it sinks in. I'm definitely enjoying the challenge at the moment, and their is an end goal.. 'my game' that I'm hoping to make.

    You'll have to share a vid of your app once it's done.
    Thanks for the info man, very helpful! I'll definitely be using PDO for the same reason as yourself, I'm only starting to learn mysql so I might as well change now and keep up with current trend ;)

    Ya as soon as I'm done with my app I'll post a video, but I think I'm a long way from that stage yet! I have 2 apps, a trainer app and a client app, with the trainer app the trainer can search clients and see their weekly weight-ins, submit new weekly stats and check the clients food diary to see if they have been eating the right foods, they can also send pm's to the client of send a global message to all clients for any updates on the gym! With the client app they can register, login, check their weekly stats, write into their food diary, pm staff and there is also a loyalty card added, every time they train the trainer types their own unique code into their phone to add a "tick" (I'm working on doing this from the trainer app) my next bit of a hurdle is trying to get the clients to book-in to specific classes at certain times, and for the trainer to check who is booked on for a specific class, but I'm finding it hard to get my head around where exactly to start without making my server and app too bloated!
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited February 2014

    but I'm finding it hard to get my head around where exactly to start without making my server and app too bloated!
    Sometimes I look at my setup thinking there must be a slimmer way to do all this, to save risking having it all grow crazily and be bloated.

    Earlier I managed to write a dodgy bit of code and when trying to login it generated over 150,000 entries into my database in a bout 30 seconds... I could hear my laptop fan speeding up a lot.
    .... I turned off the local server... fixed the code and all was ok...
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    edited February 2014
    haha gotta love loops :)
    I have a huge project in mind around this async stuff. it's very intimidating to figure it out before starting to code, I don't want to miss anything!
  • EireStudiosEireStudios Member Posts: 451
    @StormyStudio‌ Ya its not so much the size really I'm finding it harder to get the date and time from GS and sending it to a table, then getting it from the table back to the trainer & client app in time and date format, I've never really worked with time and dates in GS so i just don't know if its going to be possible, but then again I haven't looked into it too much awhile because I'm still adding other features before I try and work it out, but the bits I did look into looked complicated @-)
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited February 2014
    @EireStudios... same here.. never really touched time before.
    I'm going to log all time stuff using the time functions on the server...

    There's a load you can do with PHP time.. too much if anything.
    http://uk3.php.net/time

    $time1 = time();

    But if you need to be able to keep track of the time in GS when the user is out of signal and can't send and request time with the server you might need to do some clever thinking.

    Once you've got it sorted though, I reckon you might as well have a crack at time travel, it can't be that much harder.

    ...

    Oh I've successfully updated 6 scripts to be PDO friendly now... so back to where I was... just my 3 facebook integration scripts to check and update, but I'll save those for another day when I get round to adding them to my menu setup.
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    Quick small update...

    Nothing too crazy.

    I've added the needed rules so if the player has no network connection (or the server is down). The game stops trying to connect after 7 seconds and tells the user 'The game requires a working connection using EDGE, 3G, 4G, Carrier Pigeon or Wifi'. They can then press 'retry' or 'close'.

    The message box pops up when using 'auto login', 'registering', or 'logging in'. I'll need to create a similar pop up if the same occurs when attempting to send or retrieve any data with the server.

    Also added some simple sounds and button scaling when buttons are pressed.. a tiny bit of polish to get the ball rolling there.
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    I'm half way through a two player battleship game and man the logic trees are pretty extensive. The real trick is not the coding but thinking it all through so the coding is slim and efficient. The predefined functions for playtogether help keep it generic but that is only good for one table per player the rest I had to build my own player recognition system to keep the global network tables from crossing it's more code than I wanted to see as I requires both options but oh well. Multiplayer is a whole different type of logic from what we're used to in GS. I find game level attributes almost useless for the most part. A lot of cross matching table info et... But I'm really getting the flow of it.
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited March 2014
    @FryingBaconStudios‌
    I'm looking forward to seeing what you've made. I'm yet to reach the gameplay part in mine. Still perfecting logging in, registering, connecting and creating the start of game instances.

    I've got the gameplay prototype I made in the Autumn ready for building into this. It got as far as a working pass n play version. It will need building again from scratch but that was always expected.

    Good luck with yours, I think there will be many months before this thing is finished. So much testing is required just with what I've made so far and it's really only a menu system so far.
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited March 2014
    Another quick update (pretty chuffed with what you can get done in a lunch break).

    I've added the needed code to my load user games script to work out the time from their last move (or the time since it was created).

    It is then displayed in the desirable way of
    '2 hours ago'
    '9 minutes ago'
    '36 seconds ago'
    'Just created'

    image

    There's a handy bit of code that takes my saved Unix time stamp and compares it against the current time. Then breaks the answer down into the required text string.
    It isn't entirely accurate as it assumes all months are 30 days but works perfectly for what I need. I've reworked it a bit for my own needs but here is my source:

    http://itfeast.blogspot.co.uk/2013/08/php-convert-timestamp-into-facebook.html?showComment=1393936782820#c4101207542893708772
  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    Yeah I don't think people realize yet that with multiplayer, even with playtogether you have to build your own lobby system for seeing what games are active or who is looking for a match et... My setup for that is pretty basic but I need to build it out more to show when games are active and to indicate when someone is looking for a match.
  • jonmulcahyjonmulcahy Member, Sous Chef Posts: 10,408
    yea, even with detailed tutorials this is not going to be a feat for most people. it is going to require a ton of preplanning, implementation and maintenance. i think it's just a question of when the first complaint is posted about how it's too difficult to use :)
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    @jonmulcahy ... it's too bloody hard can someone just make it all work with one drag and drop attribute. pleeeeeaaaaassssseeeee!!!

    :-)


    ....
    @FryingBaconStudios I definitely agree that most of the same menu and game tracking setup needs to be done if you use Playstogether or your own server. I've not entirely ruled out playstogether yet. I quite like the control of being able to do what you want on the server side but the advantages may not be worth the effort of controlling and paying for your own server. We'll see....

    It's far too daunting to be honest to myself and admit I've probably only done 1% of the multiplayer game setup so far. So as long as I can tackle one tiny element of this beast each day I'll remain pleased with how it's all coming along... whether I'll still be thinking that in Decemeber is a different matter.

    ... this evenings update...

    I'm remaking my scrollable current games menu... I seem to be going back over the exact maths equation problems I had with my first build of the menu last year... there must be a cleaner way to do it.


    Hitting the hay... tired square eyes... and teething wee ones are the bain of game design... night all.



  • The_Gamesalad_GuruThe_Gamesalad_Guru Member Posts: 9,922
    yea, even with detailed tutorials this is not going to be a feat for most people. it is going to require a ton of preplanning, implementation and maintenance. i think it's just a question of when the first complaint is posted about how it's too difficult to use :)
    I was thinking the same thing Jon....lol
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited March 2014
    I'm now on the 5th version of my scrollable current games menu.

    I ditched the original as the code was too heavy and their were a couple of bugs.

    I then had a working version that spawned all the needed buttons, but again seems overly heavy and there are obvious limits on how many buttons you would want to spawn.

    I'm setting it up to keep the code as simple as possible, stop buttons scrolling out of the edge of the project, allow the scrollable list to grow and shrink with the number of current games, add a nice bounce animation, build in some inertia (I love that word for some reason, in the same way I like 'conglomerate'.. just sounds cool.. anyway I digress), plus allow for an infinite number of things to scroll through.

    I'm setting it up with 10 buttons that loop around as you scroll and have their button numbers update (button number references the index of a row in a table) so you could spin through an infinite number of rows in a table. Though in actual fact you're only seeing the same 10 actors. This approach seems like it will be the most useful for other sections. Especially if I can create a scrollable list of facebook/email friends to invite.

    So far it's working well... can spin through the same buttons and they loop around infinitely... now I need to update the numbers they reference depending on where they are in their scrolled loop...

    I have no idea if that makes any sense to anyone else... but in my sleep deprived mind it works.
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited March 2014

    Below is a little video showing my scrolling 'current games' menu system. Should work well for any large scrollable menus which reference tables.

    • There are only 10 actual button actors that loop around seamlessly showing an infinite number of buttons which reference rows in a table. ( I have ten as I might make the scroll box show more than 4 buttons eventually).

    • It automatically scales with the number of rows in a table (in this case Active Games),

    • Cool bounce if you drag to high or too low. (will add an update games function if you drag up)

    • Nice motion inertia/roll from a swipe. It varies the distance/speed of the roll depending on the swipe speed. The swipe speed is detected accurately.

    • The inertia/roll will only roll within the area of the number of buttons... i.e. if it wants to roll further than the last button, it will roll to the last button instead.

    • It automatically adjusts where it is going to roll to (or bounce back to) so that 4 buttons always align perfectly after a fast or slow swipe.

    night all.

  • beefy_clyrobeefy_clyro Member Posts: 5,394

    Looking sweet bro! Wish I thought of doing a scrolling menu like that for something I was working on! Just looping through and changing accordingly! D'oh

  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited March 2014

    @beefy_clyro ... thanks, I know it's only a little scrolling menu... but it's a pretty clever little scrolling menu :-)

  • tatiangtatiang Member, Sous Chef, PRO, Senior Sous-Chef Posts: 11,949

    @StormyStudio‌ Impressive video!

    New to GameSalad? (FAQs)   |   Tutorials   |   Templates   |   Greenleaf Games   |   Educator & Certified GameSalad User

  • Braydon_SFXBraydon_SFX Member, Sous Chef, Bowlboy Sidekick Posts: 9,273

    @StormyStudio‌ super clever! Nice stuff!

  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited March 2014

    Short video update:

    Showing the addition of an update feature for the current games menu. When you scroll up and release touch it updates the current games.

    • It only updates if you scroll up and release.
    • If you scroll up it say 'Update Games', when you release is says 'Updating Games' and a little spinning loader icon appears.
    • Once updated it interpolates back down to show game 1.
    • You can scroll up see the text 'Update Games?' and scroll back with out releasing and it won't update.
    • If there's no server connection (i.e. no signal on the device) it won't update (and won't delete the current list of active games.)
    • I had to add some timers in the update as it updates so damn quickly with the local server the spinning loader icon was up for a nth of second. I'll delete the unnecessary timers when it's published.

    I'll worry about making it all look prettier later.

  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited March 2014

    Progress is about to slow down further
    The day job just got very busy for the next 3 months, I'll be heading up a 3d animation for a cool client (3d physics, modelling, animation, texturing and high expectations). So I can see progress on this slowing down as I struggle to keep my mind in gear, hopefully not.

    Tiny update:
    When you select a button from the current games menu, the needed data (well the data I have so far) is copied over to a 'current game' table for updating by the player.

    Fixed some bugs that broke my login system after moving from nightly to Release Candidate.

    Next on the list for this... New Random Game are you player 1 or 2

    When a player (player1) starts a new random game it will check there are no current random games to join and create a new one. Once successfully created on the server.. the player is sent into the main game scene to play their first move...

    When another player (player2) starts a random game, the server script will search to see if there are any random games out there to join, (where the 1st move has been played already). If it finds one it will add player 2's id as the 'player 2' and the player is sent into the main game scene, which will be loaded with the move already made by player 1..
    ...

    just getting it straight in my boggled mind before I start updating the PHP scripts.

    ...

    Edit: Just starting writing the code... it is amazing that my PHP scripting is properly sinking in now, just managed to write 4 lines of code with 0 errors and it did what it was supposed to. Even if this project never gets finished (it hopefully will) I've still learnt so so so much in the process... some PHP scripting skills, basic server management, Amazon Web services, read up lots on security, serious planning for complicated flows and lots of multiplayer dreaming..

  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited March 2014

    Another small step... completed the above

    When creating a new random opponent game, it now searches the game database for any games to join. And when it finds one it adds the player as the player 2 and sends the game info back to GameSalad. If it does'nt find one it carries on as before and creates a new game and the player is set as player 1.

    I might add in a 'name' input when registering along with email, so I can display the name of the opponent on the 'current game button'.

    When we get facebook, I should be able to get the users name with that automatically.

    Also learnt a little bit about how to make my script a bit more secure (stop SQL injection)... I can see another boring re-write coming up on some of this code again.

    I've got two nights being in charge of the kids coming up, so my wife can P.A.R.T.Y. Which means I'll get a bit further along with this... unless I start watching Game of Thrones :-/

  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    • When searching for current games, it now searches the player 1 and player 2 fields.
    • It now brings in the opponents email address when joining a game (I'll change it to a players name later once I've added a name input in registration).
  • StormyStudioStormyStudio United KingdomMember Posts: 3,989
    edited March 2014

    I've just been looking into the email register setup for popular async game 'SongPop'

    There are some interesting ideas worth looking at and err.. 'borrowing'.

    Here's how it breaks it down.. (when not registering with Facebook).

    Register with Email:

    • Enter Email address:

    • Enter Username: ( it automatically inserts what is found before the @ in the email address to try and help recommend a username,).

    • Press 'send'

    • Pop up message appears: Is this email address correct 'shows the email address'… press 'yes' or 'no'.

    • Registered and able to play the game. (* note .. no password entered.... yet).

    • A validation email is sent out

    • If they validate they get free coins to spend in app store. This is mentioned in the email, also if you're not yet validated and look in account settings in the game, (It reminds you to validate email, send again, or connect with Facebook.

    • After validating (I used link in the email on a Mac) it recommends you setup a password… once done… it says 'play the game'.. (if validated on a PC/mac it sends you to Facebook and asks if you'd like to install the facebook App…)..

    • Back in the mobile game, in account settings, there is now an option to change your password, or 'Connect with facebook'. *So you can still connect your email registered account with facebook after registering.

    • In profile settings, there is an option to share your username with the world, tweet it, email it out, or text it. *So still able to build up a friends list without using facebook.

    text it: it writes out a text message ready for you to send saying:
    Do you want to play a music quiz game with me? Check out my Music Profile on SongPop http://'address for SongPop profile'.. . My username is *******

    Twitter: writes out a tweet ready to send.
    Are you ready to rock? My SongPop username is ********* and address to my profile page on songPops website.

    E-mail writes out an email ready to send.
    Will you play SongPop with me?
    My username is **********. You can challenge me on SongPop by visiting my Music Profile http://www. 'address to my song pop profile'.

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

    then from the main menu you can 'Start a Challenge!'

    Choose from 3 random recommended opponents (selected as they match your skill level).

    Or enter an opponents email address or username.

    ( I entered a random username, it went onto the main game screen, then a notification popped up, saying that player already has too many challenges... and cancelled that game).

    ........

    All really nicely implemented and allows you to play before you even validate the email making for a pretty small pain barrier to play. You'll then validate and add a password. Making your account more secure plus allowing you to play/register on other devices).

    Also by receiving 250 credits for validating your email your then more likely to check out the in game store and it introduces the notion spending credits and benefiting from a purchase, which has obvious benefits as the player now knows the store exists and how to use it.

    Love the little username trick where it automatically inserts what is found before the @ in the email address to try and help recommend a username. Gonna give that a go using our new text string abilities in GS.

    ...any way thought I'd share incase it's of interest to any one else as well. So many complicated flows just to get your player into a game.

    Let me know if you've seen any other nice registration flows which are'nt using facebook.

    Edit: Played it a bit more... they do a really good job of making you feel like the opponent is playing at the same time, by showing when they play their move on the same song... though they've obviously played some time in the past.

  • StormyStudioStormyStudio United KingdomMember Posts: 3,989

    Got the rules working, so a suggested username is generated by building up a text string just using the letters before the '@' symbol in the given email address.

    First time I've used SubString and TextFind functions, cool stuff though.

Sign In or Register to comment.