|
|
Browser Game Specific Non N00b Question | ||
Discussion by Supa Comix with 17 Replies.
Last Update: August 12, 2007, 10:33 pm | |||
![]() |
|
|
I have been thinking about a lot of things an apart from the sheer hugeness of the size of such a project i'd like to know how the game functions in the background. With games such as ogame you have things happening in the background, fleets moving, attacks happening etc. I'd like to know how i'd get into sorting all that out. How i'd get attacks to function at the right time, how fleets get to their destination. How buildings finish, basically how the databases update themselves without anyone actually being online. Like the running whilst everyones asleep. That's the one problem i've got with such a project how i'd get it to work in the background... i've looked through other tutorials and scanned the forums nothing seems to be what i'd like to know.
Does anyone know?
Just a suggestion. Maybe someone who had really wrote one could drop a bit of tips here also.
QUOTE (faulty)
I've never wrote anything similar, but from what I know, you need to have a running timeline for your game. And everything will have an endtime, at which it should have been done, like in your case "get attacks to function at the right time, how fleets get to their destination. How buildings finish". Then you can have cron or configure crontab http://en.wikipedia.org/wiki/Crontab to call a php script every minute. The smallest is minute for cron. You can look for other similar scheduler which can have smaller timestep, but that also means you can't use standard linux web server. So whenever you script run, it checks for the endtime, then take action on those which is expired then decide on what to do next.Just a suggestion. Maybe someone who had really wrote one could drop a bit of tips here also.
Link: view Post: 108902
Acutally what Lee said were quite right. I've done some cron that run in the background on certain time from the web server. The cron job are just scheduler that will execute those php codes to the time you specified. You can schedule a game engine to run at the background and update some specified data in the database. Eg. A soccer match engine can be program to run when the cron job starts and end 90mins later. every minute will run some kind of script that update the database. So even if there's anyone online, they can see the what happen without you (Administrator) clicking for it to execute.
But I think that's not the only way to do it. Maybe you can google and try finding some better and effective solutions out there.
Cheers
The server is apache (dunno if that helps or not...)
For some server, you can request the hosting company to help you install the cron job, maybe you can give it a shot
Another way can i think of is to run an update script whenever someone view the page. The script will check the current time and compare with it's last run time, and update the events properly. That way, if only when ppl is looking at your page, then it's data is updated. The trick here is just comparing the time, and applying the changes depending on time difference.
There's few thing you need to take note. If you game is complex, then it might take a while to update the events. If it happens that no one logon for the past few days, then it will take a long time to first show the page. There's a duration limit to which your script can run. Normally it's 30sec, to prevent problematic script from running indefinitely, taking up all the cpu cycle along.
Let see if anyone else came up with a better idea
http://robert.accettura.com/archives/2006/...ssing-with-php/
and I'll be back with an architectural explanation of what I think your solution will be.
Apache spawns a new process in the operating system for every PHP script you invoke via browser.
The whole thing works on the basis of the request-response paradigm, but for your purposes, you need to separate the request part from the response part.
So you have this infinite loop housekeeping script handy and you invoke it with fsockopen once (and only once!!!).
fsockopen does the request part, after which you simply omit capturing the response and close your browser window - voila, you have your housekeeping process running in the background.
If you invoke it several times, you might have several instances of this script running at the same time, killing your server and stepping on each other's toes, crossing wires etc.
CODE
print " - This is a test!";At one minute intervals?
What pages would i need to construct etc? Sorry for all the questions but im really having trouble getting my head around this!
QUOTE (dserban)
PHP script that does only database work (or otherwise invisible work) in an infinite loopLink: view Post: 108973
... emphasis on "invisible" ...
The PHP script I was talking about has no way of communicating with any browser, so the idea that it would print something does not make any logical sense.
It is a PHP script that does not take any input and as well does not produce any output. It's a script that is supposed to run in the background and update database tables in real time based on what online players happen to be doing as they interact with your system.
The browser that is connected to your game system might actually run a combination of JavaScript and AJAX to provide interactivity between the online actions of the player and the ever-changing situation in the database tables, which is being continuously worked on by the background script.
Seriously, if you really need to do such a complex game, it's worth to buy a hosting with enough supporting features. If you game is not that complex, as not requiring too much processing, then you can try the event update on every page viewing method i mentioned earlier.
It's also good to look into other's works. There's a few opensource online game. Try sourceforge.net
If you can't find a hosting platform for your game, I would recommend - at least in a first stage - running the game on your own PC at home and giving your gaming buddies access to it. The only thing you need to do is open a port or two for direct access from the Internet.
The ports you probably need to open are 80 for Apache and 3306 in extreme cases.
Even with those ports open, you still have the option of controlling which IP addresses (your gaming buddies' PCs) can connect to your online game, even by using the brain-dead built-in firewall that comes bundled with Windows XP SP2.
QUOTE (dserban)
Remember what I said ...... emphasis on "invisible" ...
The PHP script I was talking about has no way of communicating with any browser, so the idea that it would print something does not make any logical sense.
It is a PHP script that does not take any input and as well does not produce any output. It's a script that is supposed to run in the background and update database tables in real time based on what online players happen to be doing as they interact with your system.
The browser that is connected to your game system might actually run a combination of JavaScript and AJAX to provide interactivity between the online actions of the player and the ever-changing situation in the database tables, which is being continuously worked on by the background script.
Link: view Post: 108976
Yeah it needs to be invisible and it will just update database/tables in the background. I just need to know how i'd go about setting that up. What pages i need etc. Where i'd need to put the code into update the tables etc. How would i go about getting to start, how i'd get it to do that infinite loop every 500 milliseconds... As soon as i know that i'll be happy
[thanks for the help ur giving me btw... most appreciated!]
http://www.php.net/function.fsockopen
Look a 10th of the way down at the example code posted by:
jbr at ya-right dot com
There is a sequence of code that looks like this
CODE
if ( ( $io = fsockopen( "www.yahoo.com", 80, $errno, $errstr, 5 ) ) !== false ){
$send = "GET / HTTP/1.1\r\n";
$send .= "Host: www.yahoo.com\r\n";
$send .= "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.2.1) Gecko/20021204\r\n";
$send .= "Referer: http://www.yahoo.com/\r\n";
$send .= "Accept: text/xml,application/xml,application/xhtml+xml,";
$send .= "text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,";
$send .= "image/jpeg,image/gif;q=0.2,text/css,*/*;q=0.1\r\n";
$send .= "Accept-Language: en-us, en;q=0.50\r\n";
$send .= "Accept-Encoding: gzip, deflate, compress;q=0.9\r\n";
$send .= "Connection: Close\r\n\r\n";
fputs ( $io, $send );
... this is the request part (fputs). But then he goes on to use fgets, which is the response part. That you don't need to do ... in fact it's a bad idea to attempt it.
Now instead of $send .= "Host: www.yahoo.com\r\n"; you would obviously have $send .= "Host: link-to-PHP-invisible-housekeeping-script\r\n";
Your PHP invisible housekeeping script either reacts to the actions of the online gamers which are reflected in the database as table entries, or otherwise generates random events based on rules you preset - like a Pacman that keeps popping out of random places at random intervals trying to eat you alive if you're not careful. That you need to program yourself, and you need to define how those two things interact by defining the data model correctly.
$send .= "Referer: http://www.yahoo.com/\r\n";
I would replace the http://www.yahoo.com with my own website address i assume?
Actually you only need something like this:
CODE
$send = "GET / HTTP/1.1\r\n";$send .= "Host: http://gameserver/housekeeping.php\r\n";
$send .= "Connection: Close\r\n\r\n";
But after taking a better look at the code I gave you, I realize now that you also need to replace fsockopen( "www.yahoo.com" ... ) with fsockopen( "<IP-address-of-your-game-server>" ... )
QUOTE (dserban)
Ummmmmmmm ... no.Actually you only need something like this:
CODE
$send = "GET / HTTP/1.1\r\n";$send .= "Host: http://gameserver/housekeeping.php\r\n";
$send .= "Connection: Close\r\n\r\n";
But after taking a better look at the code I gave you, I realize now that you also need to replace fsockopen( "www.yahoo.com" ... ) with fsockopen( "<IP-address-of-your-game-server>" ... )
Link: view Post: 108997
right and i'd need to use the above code when someone logs in?
The idea is that you need to kick-start this house keeping process and have only one instance of it running at any point in time.
I can imagine that you would have an administration / superuser section for your game, where you pull all kinds of levers to control the game.
The above code would be part of a page in this administration section called "Kick-start housekeeping process".
The link to this page would be active if the process is not already running, and would be greyed out or missing altogether if it is.
Or something to that effect, it's really up to your imagination, personal preference and talent for designing systems.
Similar Topics:
More Linux Questions [mandriva]
Liquid Webtoy A Fluid Similation...
How I Use Ie Vs. How I Use Firefox ...
Can Someone Please Lend A Hand? Php need direction (4)
|
(2) Easily Making A Game
|
HOME 





Scottland Interactive Quiz #1 - Question 2
Scottland Interactive Quiz #1 - Question 8
Scottland Interactive Quiz #1 - Question 7
Scottland Interactive Quiz #1 - Question 3
Scottland Interactive Quiz #1 - Question 10
Scottland Interactive Quiz #1 - Question 9

