Welcome Guest ( Log In | Register )



2 Pages V   1 2 >  
Reply to this topicStart new topic
> Browser Game Specific Non N00b Question
Supa Comix
post Aug 9 2007, 09:35 PM
Post #1


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 24
Joined: 9-August 07
Member No.: 23,954



Right me and my mate have begun planning to make a browser game (omg yes another guy wanting to do it). I know php, java, ajax, html, vb, C++ etc to a certain level like amateur. but thats not the point.

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?
Go to the top of the page
 
+Quote Post
faulty.lee
post Aug 10 2007, 01:24 AM
Post #2


Premium Member
Group Icon

Group: [HOSTED]
Posts: 495
Joined: 5-November 06
Member No.: 17,016



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.
Go to the top of the page
 
+Quote Post
kelvinmaki
post Aug 10 2007, 12:05 PM
Post #3


Advanced Member
Group Icon

Group: Members
Posts: 170
Joined: 30-July 07
Member No.: 23,704



QUOTE(faulty.lee @ Aug 10 2007, 01:24 AM) *
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.


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
Go to the top of the page
 
+Quote Post
Supa Comix
post Aug 11 2007, 12:18 PM
Post #4


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 24
Joined: 9-August 07
Member No.: 23,954



Right i did have a quick shufty around google as well as on the crontab stuff and i found out that my webhoster does not support cron functions. Is there any other way that people know? Preferably free ones...

The server is apache (dunno if that helps or not...)
Go to the top of the page
 
+Quote Post
faulty.lee
post Aug 11 2007, 12:51 PM
Post #5


Premium Member
Group Icon

Group: [HOSTED]
Posts: 495
Joined: 5-November 06
Member No.: 17,016



Cron is part of linux. Thus all linux server will have cron built in. It's just the matter whether they let you have access to it or not. Those are usually left for premium services. If it's a windows server, then you're out of luck. Apache can be windows based or linux based.

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
Go to the top of the page
 
+Quote Post
dserban
post Aug 11 2007, 12:56 PM
Post #6


Premium Member
Group Icon

Group: [HOSTED]
Posts: 286
Joined: 17-June 07
Member No.: 22,702



I think PHP function fsockopen() is the answer to your question, check out this article:

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.
Go to the top of the page
 
+Quote Post
dserban
post Aug 11 2007, 01:02 PM
Post #7


Premium Member
Group Icon

Group: [HOSTED]
Posts: 286
Joined: 17-June 07
Member No.: 22,702



From what I know about the architecture of Apache / PHP and from what I understand from your description, it sounds like you need to use an asynchronous call to a PHP script that does only database work (or otherwise invisible work) in an infinite loop, with a "sleep 500 miliseconds" statement or whatever frequency you want for your housekeeping activities.

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.
Go to the top of the page
 
+Quote Post
faulty.lee
post Aug 11 2007, 01:07 PM
Post #8


Premium Member
Group Icon

Group: [HOSTED]
Posts: 495
Joined: 5-November 06
Member No.: 17,016



Yes, that sounds good, but another thing is that most server restrict access to fsockopen(), because with the right coding, you can do virtually anything with it. Super powerful.
Go to the top of the page
 
+Quote Post
Supa Comix
post Aug 11 2007, 01:54 PM
Post #9


Newbie [ Level 2 ]
Group Icon

Group: Members
Posts: 24
Joined: 9-August 07
Member No.: 23,954



Thanks people. I had a look at this Asynchronous Processing With PHP thing and i found that i didn't fully understand it. How would i set it up to, for example, do:

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!
Go to the top of the page
 
+Quote Post
dserban
post Aug 11 2007, 02:06 PM
Post #10


Premium Member
Group Icon

Group: [HOSTED]
Posts: 286
Joined: 17-June 07
Member No.: 22,702



Remember what I said ...
QUOTE(dserban @ Aug 11 2007, 02:02 PM) *
PHP script that does only database work (or otherwise invisible work) in an infinite loop

... 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.

This post has been edited by dserban: Aug 11 2007, 02:07 PM
Go to the top of the page
 
+Quote Post

2 Pages V   1 2 >
Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics


 



- Lo-Fi Version Time is now: 13th October 2008 - 09:27 PM