[Flash/PHP] Online game concept, will this work?

Joined
Apr 29, 2005
Messages
6,400
Reaction score
130
So I'm planning on creating a small mmo with the client being written in flash and the server php. I need some advice on the server though, as I'm not sure if my current ideas are as efficient as possible.

There will be 3 servers, which will basically be php scripts running in a infinite loop. More on this later.
The three servers will be:
  • Login server, receives log in requests, checks them against a mysql database.
  • World server, Handles npcs and events.
  • Character server, everything the player does gets sent to this server.

As with every almost every mmo, I'm planning on using packets. Though, how exactly I'm going to send these packets is still a bit difficult. My idea for sending packets to the server is the following:

  1. Something happens
  2. Client sends request to a php script, request will work with get data, ?action=move&player=whatever, a simple example.
  3. The script writes a line with the following format to a .txt: file: "1.move whatever end-of-string-character". Every server has it's own .txt file
  4. As I mentioned before, the servers will be running in an infinite loop, so every time the loop begins, it will check the txt file for a new request (Hence the number at the begin of the line) and responds accordingly. Usually this is sending a response packet.

How I am going to send packets from the server to the client is still something I need to figure out. Suggestions are welcome.

The examples I give are simplified ofcourse, the real server will have a lot more than 2 variables.

Please give your insights on my concept. If you know what you're talking about at least.
 
So I'm planning on creating a small mmo with the client being written in flash and the server php. I need some advice on the server though, as I'm not sure if my current ideas are as efficient as possible.

There will be 3 servers, which will basically be php scripts running in a infinite loop. More on this later.
The three servers will be:
  • Login server, receives log in requests, checks them against a mysql database.
  • World server, Handles npcs and events.
  • Character server, everything the player does gets sent to this server.

As with every almost every mmo, I'm planning on using packets. Though, how exactly I'm going to send these packets is still a bit difficult. My idea for sending packets to the server is the following:

  1. Something happens
  2. Client sends request to a php script, request will work with get data, ?action=move&player=whatever, a simple example.
  3. The script writes a line with the following format to a .txt: file: "1.move whatever end-of-string-character". Every server has it's own .txt file
  4. As I mentioned before, the servers will be running in an infinite loop, so every time the loop begins, it will check the txt file for a new request (Hence the number at the begin of the line) and responds accordingly. Usually this is sending a response packet.

How I am going to send packets from the server to the client is still something I need to figure out. Suggestions are welcome.

The examples I give are simplified ofcourse, the real server will have a lot more than 2 variables.

Please give your insights on my concept. If you know what you're talking about at least.

Anything's possible, if you have the patience to do it.(This does not include flying without wings, breathing underwater with no oxygen tanks, etc.)
 
The function behind the concept is very sophisticated compared to the existing web-based MMOs. Even the functions behind executable based MMO game is fairly sophisticated, yet less sophisticated than creating it flash based.

My suggestion is to use Java for the server and flash for the client. I can provide you examples consisting online communication mainly used for MMO game types with Java.

With an MMO game written as executable, includes dll to sustain online communication functions. With flash, I can't see that happening; flash involving dlls to supply the communication function. A dll is necessary as a substitute for the default online communication which windows provide, simply because it gives more flexibility and power.
 
The function behind the concept is very sophisticated compared to the existing web-based MMOs. Even the functions behind executable based MMO game is fairly sophisticated, yet less sophisticated than creating it flash based.

My suggestion is to use Java for the server and flash for the client. I can provide you examples consisting online communication mainly used for MMO game types with Java.

With an MMO game written as executable, includes dll to sustain online communication functions. With flash, I can't see that happening; flash involving dlls to supply the communication function. A dll is necessary as a substitute for the default online communication which windows provide, simply because it gives more flexibility and power.

I don't really care about the client tbh, for all I care it's written in visualbasic. Though I'd really like the server to be in php, as php is quite a powerful language and can be used for much more than only web scripting.

I've already started on the character server which is looking pretty solid except for the fact that I still need to find a way to send packets, though I'm sure I'll figure this out eventually.

My only concern is that it seems to make quite a hit on the CPU usage, because the moment the character server is activated the CPU usage immediately shoots to 50%. Because of this I'm thinking about switching to lighttp as it.

So if I could just find out how to let php send out packets I'm all set for writing a mmo server in php.

P.S Do you think my way of letting php handle incoming packets i.e saving them to a text file first and then reading them from is good, or do you think there's a better way for this?
 
Is it going to be like Stick Arena or more of an RPG type feel? It's certainly doable with XML (I imagine you're using PHP to play with SQL->XML conversions). You don't really need a .dll for a flash game. I don't know much on the matter, as I don't make MMO's. I have made a simple multi-player game by going through some tutorials with Flash AS2 + some weird server that came with some framework files.

If you've ever played Stick Arena, you'd know how often it gets hacked and how that fucks up the whole game.. Flash is cool, but idk.. it turned out to be harder than I thought when I wanted to do a similar project. Not to mention I have no idea how to secure a flash game.. (Could be easy, but it appears to be hard since Stick Arena has been around so long yet still gets scripted up the ass) Good luck though ;)
 
I found this function on programmers heaven.

PHP:
<?php

function spk($packet){
$result='';
foreach(str_split($packet,2) as $byte){
$result.=chr(hexdec($byte));
}
return $result;
}
//hex code of the bytes i want to send:
$packet= spk("32CD54AB13C664000000641B0002000400000001000000FF000000");
$host="192.168.0.53";
$port=900;
$sock = socket_create(AF_INET, SOCK_RAW, SOL_UDP);
echo socket_sendto($sock, $packet, strlen($packet), 0, $host, $port)." bytes";
socket_close($sock);
?>

Ugh, i know it isn't much help but I was hoping that this would at least give you a base that you could build on
 
P.S Do you think my way of letting php handle incoming packets i.e saving them to a text file first and then reading them from is good, or do you think there's a better way for this?

Contemporary-wise it can handle the process I believe.

I found this function on programmers heaven.

PHP:
<?php

function spk($packet){
$result='';
foreach(str_split($packet,2) as $byte){
$result.=chr(hexdec($byte));
}
return $result;
}
//hex code of the bytes i want to send:
$packet= spk("32CD54AB13C664000000641B0002000400000001000000FF000000");
$host="192.168.0.53";
$port=900;
$sock = socket_create(AF_INET, SOCK_RAW, SOL_UDP);
echo socket_sendto($sock, $packet, strlen($packet), 0, $host, $port)." bytes";
socket_close($sock);
?>

Ugh, i know it isn't much help but I was hoping that this would at least give you a base that you could build on

That's perfectly what exactly I have imagined.
 
Is it going to be like Stick Arena or more of an RPG type feel? It's certainly doable with XML (I imagine you're using PHP to play with SQL->XML conversions). You don't really need a .dll for a flash game. I don't know much on the matter, as I don't make MMO's. I have made a simple multi-player game by going through some tutorials with Flash AS2 + some weird server that came with some framework files.

If you've ever played Stick Arena, you'd know how often it gets hacked and how that fucks up the whole game.. Flash is cool, but idk.. it turned out to be harder than I thought when I wanted to do a similar project. Not to mention I have no idea how to secure a flash game.. (Could be easy, but it appears to be hard since Stick Arena has been around so long yet still gets scripted up the ass) Good luck though ;)

I was thinking of making a pokemon mmorpg, where players can battle, trade pokemon etc.

As I mentioned above, I do not care much about the client, I'm thinking of whipping up a simple client in visualbasic. If I ever can get over the feeling that I'm sodomizing a child whenever I work with VB that is.

I found this function on programmers heaven.

PHP:
<?php

function spk($packet){
$result='';
foreach(str_split($packet,2) as $byte){
$result.=chr(hexdec($byte));
}
return $result;
}
//hex code of the bytes i want to send:
$packet= spk("32CD54AB13C664000000641B0002000400000001000000FF000000");
$host="192.168.0.53";
$port=900;
$sock = socket_create(AF_INET, SOCK_RAW, SOL_UDP);
echo socket_sendto($sock, $packet, strlen($packet), 0, $host, $port)." bytes";
socket_close($sock);
?>

Ugh, i know it isn't much help but I was hoping that this would at least give you a base that you could build on

That is EXACTLY what I need, thanks a lot.
 
Pieman, please keep us updated with this project of yours. I'm very interested with the outcome, I'm also in the breech of creating server for an online game and I hope I could use this method to implement the wholesome server functions.
 
I have good news and bad news

The good news, the character server processes 1000 queued packages in 0.807 seconds which is quite fast.

The bad news, when it does this it takes around 70%~ of the cpu and this is without having added the mysql query and package sender yet.

If someone knows how to reduce the cpu usage, please tell me.
 
Try implementing the reception this case: only activate the loop when it receives packets.

Ah thanks, I now know how I'm going to tackle the problem it.

Like I mentioned in my opening post, data gets written to the text file with a normal http link, now instead of writing the data to a .txt file, the script includes the character server and so immediately sends the packets and updates the database.

Now to prevent process stacking, the maximum number of simultaneously running character servers will be 5. Any packets sent on top of that get written to the initial text file and are distributed over the already running mini character servers.

Though I can't imagine of this ever happening, because the time it takes to send a packet to the server and for it to respond is like 0.0002 seconds.

This should dramatically decrease CPU usage. Thanks IQstim. :):

And added bonus will be that it won't have to mess with ini settings any more to get the infinite loop, so it will be able to run on normal web servers. :):
 
Your welcome. :)

Though I can't imagine of this ever happening, because the time it takes to send a packet to the server and for it to respond is like 0.0002 seconds.

I assume 0.0002 is nearly contemporary for a person's average time duration to think about his actions whether to present a 'Pokedex' or attack another Pokemon. Quite similarly like chess, and I'm sure players will patiently wait for his turn.

0.0002 isn't merely noticeable in my opinion, unless the server runs slowly due to connection load or just general preferences; connection load which in this case I presume 50 players means 50 times the figure, it can't be 100% on load all the time as other clients stops (to think or wait) while other clients sends packets, so lets assume 60% of '50' is the upper limit of the CPU usage while on server run-time. 50 x 0.0002 = 0.01, which isn't bad for a turn-based game.

And also, how many packets has been sent resulting the server to respond in 0.0002 second? The figure might vary due to the number of packets.
 
I was thinking of making a pokemon mmorpg, where players can battle, trade pokemon etc.

As I mentioned above, I do not care much about the client, I'm thinking of whipping up a simple client in visualbasic. If I ever can get over the feeling that I'm sodomizing a child whenever I work with VB that is.



That is EXACTLY what I need, thanks a lot.
I suggest making the client web server based like flash. This way players can play from any location. I would not suggest making the client in Java because it makes an unrefined GUI compared to flash (hardly a comparison at all).

Flash based is my suggestion in short. Plus, there are similar games to this written both in VB and Java lmao; I've played both. Bring in something new aye?
 
Back