Jump to content

Online Multiplayer game with PHP/MYSQL


Jerred121

Recommended Posts

I currently making a relatively simple turn-based strategy game (kind of like a rock, paper, scissors game) in flash and I have no idea as to what I should use as a socket (or like a socket) to relay players' interactions from one client to another.  I have researched various APIs like nonoba and SmartFoxServer, etc but they either force their own interface on you or charge an arm and a leg.  I've read that java would achieve what I want, but I just don't know enough about java, sockets or networking to make sense of any of it, let alone trying to utilize it.

 

So I am thinking about using php and a mysql database since I am familiar with them, but I'm concerned about performance even though the game would not be very demanding as it is basically just passing values from client to client via php/mysql.

 

Little info on the game:

  • 3-6 players per room.
  • I have no idea as to how many rooms would be necessary, of course that will be determined by its popularity.
  • The timing is what will concern me, as it must be accurate -1 min intervals or less if all of the players make their selections sooner, but they must all be in sync.
  • I only see about 6-10, small (<20 characters/per) variables needing to be passed per player - so if it were 10 variables, in a room with six players, player 1 would send 10 variables and receive 50 back

 

Another option, that I admittedly haven't researched yet, is an xml socket, but I have no idea how to accomplish this and am concern with performance with that as well - probably just because I'm ignorant about it.  :confused:

 

So what do you guys think?  Think php/mysql could handle this?  Or do I need to learn another language/API?  Any input would be greatly appreciated.

Link to comment
Share on other sites

To be honest, this is a php forum so imagine replies will be biased towards the use of php.

 

From a performance standpoint, I don't see any issue at all. Facebook is run on php and mysql - performance can be tuned and ultimately is determined by the environment you execute the code in.

 

One major thing which will determine speed is the location and hardware of the server, and the amount of servers you have. You might need servers for the application, separate servers for the database, maybe even a master -> slave setup. You can of course grow this as your app grows.

 

You said it yourself, it won't be very demanding. Unless you're going to get a bazillion hits a day and you only have 1 server, and a database table with 100 million rows which you're performing complex queries on, I don't think you have much to worry about ;)

 

My advice, which I think is VERY important, is code your flash application so that you can switch out the server-side programming. That way, if something does come up and php and mysql will not suffice (doubtful), you can easily switch it with another programming language.

Link to comment
Share on other sites

if yer using java/javascript/flash these are run clientside (mostly)

php is serverside.

 

so your app must communicate with the webserver, javascript has jquery which is popular and easy as well as ajax.

 

the serverside, php script, just returns information tat the app needs usually with a GET request. these scripts usually post information as xml or plain text.

 

pseudo app code:

function get_oppenent_respnse()
{
     return = file_get_contents("http://my.server.com/playerresponse.php?myid=x&table=y");
}

 

while server side u would have

<?php
   header('Content-type: text/plain');
  $id=isset($_GET['myid'])?intval($_GET['myid']):FALSE;
  $table=isset($_GET['table'])?intval($_GET['table']):FALSE;
  if($id && $table) {
       $row=sql_query("SELECT * responses WHERE table=$table and to=$myid");
       echo "$row[from]:$row[response]";
}

 

its just designing the interation between client and server.

 

 

Link to comment
Share on other sites

if yer using java/javascript/flash these are run clientside (mostly)

php is serverside.

 

so your app must communicate with the webserver, javascript has jquery which is popular and easy as well as ajax.

 

the serverside, php script, just returns information tat the app needs usually with a GET request. these scripts usually post information as xml or plain text.

 

pseudo app code:

function get_oppenent_respnse()
{
     return = file_get_contents("http://my.server.com/playerresponse.php?myid=x&table=y");
}

 

while server side u would have

<?php
   header('Content-type: text/plain');
  $id=isset($_GET['myid'])?intval($_GET['myid']):FALSE;
  $table=isset($_GET['table'])?intval($_GET['table']):FALSE;
  if($id && $table) {
       $row=sql_query("SELECT * responses WHERE table=$table and to=$myid");
       echo "$row[from]:$row[response]";
}

 

its just designing the interation between client and server.

 

He's not asking specifically how to do it. He's asking should he use php vs another server-side solution.

Link to comment
Share on other sites

reason the code was pseudo code The code does not work, but it helps ppl see some how code would intereact with each other.

So I'm not shure why you posted here if yer reply has nothing to do with the topic. You are not helping, nor are u posting a query.

Troll forums are on other websites not here.

 

] I have researched various APIs like nonoba and SmartFoxServer, etc but they either force their own interface on you or charge an arm and a leg.  I've read that java would achieve what I want, but I just don't know enough about java, sockets or networking to make sense of any of it, let alone trying to utilize it.

 

also the reason i posted that javascritpt has jquery. If yer client app has a means to communicate with a web server, than its just a matter of designing the protocol. thats all any api does.

 

Link to comment
Share on other sites

Thanks for the replies.  You make some good points Anti, particularly about getting a biased opinion here - maybe it's because that's what I wanted to hear.  I would feel much more comfortable righting my serverside code in php, but people just have a natural tenancy to remain in their comfort zone, and that's what worries me.  I don't want to invest all of this time and effort into something that isn't practical.

 

i'll definitely take your advice about slimming down the dependencies that flash has in relation to whatever server-side solution I choose.  I'm still research all of this though, and I haven't yet made up my mind.  I'm starting to reconsider flash all together, however I want the play to be able customize their character - like shirt color, hair type/color etc...

Link to comment
Share on other sites

reason the code was pseudo code The code does not work, but it helps ppl see some how code would intereact with each other.

So I'm not shure why you posted here if yer reply has nothing to do with the topic. You are not helping, nor are u posting a query.

Troll forums are on other websites not here.

 

] I have researched various APIs like nonoba and SmartFoxServer, etc but they either force their own interface on you or charge an arm and a leg.  I've read that java would achieve what I want, but I just don't know enough about java, sockets or networking to make sense of any of it, let alone trying to utilize it.

 

also the reason i posted that javascritpt has jquery. If yer client app has a means to communicate with a web server, than its just a matter of designing the protocol. thats all any api does.

 

Wow, I'd hate to seriously question you. I make a passing remark is all. He wasn't looking for code - you're reply actually had little to do with the topic. We are speaking generally here. Sometimes people question you - get over it.

 

Yeh, Jerred, I think the most important thing is you make sure you don't restrict what server-side solution you can use. To be honest, I think flash is a good idea. The only other one would be javascript. If you're requiring real time interaction with your app you're definitely going to want to use one of these. The animation and graphical aspect of the game will determine which will be best. For example, if you want some advanced animation or lots of moving graphics, javascript will just not suffice.

 

Link to comment
Share on other sites

Well, now I'm actually considering php and ajax.  What turn me off of this previously is the quality of games I have seen come out of php...  The game doesn't require really any animation, but if I wanted to enhance that aspect later, I would be restricting myself with php/ajax...  I currently looking into image manipulation with php, it seems as though I could use this to allow the player to customize their character...  Like so have a base model of a head with no eyes, mouth and nose - allow the user to change the base color (skin tone) and then have a selection of images for the eyes, mouth and nose for the user to choose from.  Any animations would basically be eyes shifting/closing.  This is an entirely new concept for me so I'll have to research it thoroughly.

 

Essentially, what my real issue is, the communication protocol (whatever you want to call it) - I wasn't expecting this to be easy, but it appears that a relatively advanced knowledge of another language and internet communication is required.

Link to comment
Share on other sites

Hmm...thing is, an eye blinking is advanced animation that javascript will not do. Using php to recreate an image based on user selection of small things like nose etc will not work too good either. Instead, you would create a 'sprite' with all possible noses, heads, hats etc etc. If you have each element as a new file, you can even automate the integration of any new elements into your app. The app would scan the character elements directory and add the new options to character customization.

 

If your game runs in php, it is almost a given you would at least start with mysql as the database. However, if you do run the game using ajax, then you are stuck with the web; it isn't as portable as flash. Guess these are just some of the things you'll have to weigh up.

 

My honest opinion (now with info about blinking eyes ;)) is flash + abstract database connection where you can plug in php, or java servlet, or .net or anything. Maybe start with php and if it starts causing problems switch it out.

 

Oh, and some great games have been done using php and flash. Zynga poker and I think their other games on facebook use flash and php in the backend.

 

Oh - an animated gif would do a decent blinking animation I guess!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.