sorry if my question is a bit ambiguous, I'll explain what i want to do.
i want to run a game on a webserver. its a turn based game, some of you people might have come across it.
Its a game called mafia: http://mafiascum.net/wiki/index.php?title=Newbie_Guide.
I know how it needs to work in terms of a mysql database a server side scripting language etc etc.
What i am not sure about is whats the best way to get a script to activate when the game starts, and be able to run a script every 3 minutes to update the game status:
once 10 people join the game starts
people vote during a 3 minute period. (votes would be stored in a database)
after 3 minutes a script needs to run to calculate the votes and remove a player
then 1 and a half minutes later the script needs to run again.
This cycle of 3 minutes, 1 and a half minutes need to repeat until a certain condition is met, i.e all players but 2 are dead or something.
when players refresh the page they need to be updated on the games status.
Ive read about sockets, and wonder if this might be a good path to take. would sockets be able to send json back to the clients? so that jquery can then update the client with game results.
Ideally i would like the the front end to be done in jquery and the backend script processing to be done by php or something.
How open would this be? in terms of people trying to cheat by sending attacks such as post variables sqli attacks etc etc.
Its quite a broad question, and i am sure there is more than one approcah so is more than one correct answer, but i would be intrested on peoples thoughts on how they would go about developing it.
Thanks for your time :)
I would simply use a CRON job or similar on the backend to update the status every x seconds as you have suggested.
To trigger a game start, simply fire off a PHP command to set your CRON job running.
This way the timing is controlled behind the scenes on the server, and you are free to update the status of the game using jQuery to your actual players.
Related
We have a process in which several site servers send data to a central server (through a Linked Server). A new site has seen the job duration more than double in three weeks, and a couple of the other sites often fail due to run time overlap.
It is a two step process:
Insert new records
Update changed records
The insert only takes a few seconds, but the update takes anywhere from 5 to 20 minutes, depending on the site. I am able to change the query that drives the update and get it down to only a couple seconds, but still when put into an UPDATE statement it takes several minutes.
I am leaning towards moving the jobs to a single job on the central server, so it is a pull operation which, based on the testing I have done, should be much faster. However, my question is: What is considered "best practice" in this situation? I am going to have to change quite a bit to get this working properly, so I might as well do it right.
I'm desinging a web based game. In this game almost all actions will take certain amounth of time but i'm not sure about where to store and execute the actions.
For example a character want to go to A to B and let's say this will take 30 secs. In my character table there is a column called Location, witch is storing Id of current place. So i must change this Id after 30 seconds.
The best solution i could me so far is creating SQL jobs. Since i don't have envoirment to test how 100.000 Sql jobs will effect the server performance, i wanted to ask is there any other ways or should i stick to Sql jobs?
PS: Logic is mostly same with other web based games, any direct example from others games about how they handle such things will be appreciated
Using sql database will cause you alot of pain later on because is not ideal for what you are attempting https://gamedev.stackexchange.com/questions/40215/use-a-sql-database-for-a-desktop-game
only use sql if you want to store vast amount of login details other than that use something similiar to couchbase
nosql database
http://www.couchbase.com/why-nosql/nosql-database
just my 2 cents hope i helped
You don't need any job for this.
If we stay at the example above then we can say that every place where our character is can have additional information (in an extra table where the places and the characters are connected) such as when start the validity of the record:
Player A is at Brighton from 2014-05-01T00:00:00 to NULL
but he is moving to London which takes 30 secs
Player A is at London from 2014-06-09T10:30:30 to NULL and the
previous place record will be closed (set the to value) with the
current from date (2014-06-09T10:30:30).
I implemented a simple scheduling mechanism using only ASP.NET. You can find a proof of concept at http://weblogs.asp.net/ricardoperes/using-the-asp-net-cache-as-a-scheduler.
Our web app automatically emails us when a page execution goes beyond a second or two with timings for running each SQL statement. We track what pages each user is browsing on each page load and this query sometimes takes a couple of seconds to run (we get a number of these automatic emails telling us a page has taken longer than a couple of seconds at the same time).
UPDATE whosonline
SET datetime = GETDATE(),
url = '/user/thepage'
WHERE username = 'companyname\theusername (0123456789)'
Any ideas what could be causing this? Normally it runs in a split second but say every week or so it takes about 2 or 3 seconds for probably a timespan of 10 seconds.
This is a very broad question and there could be a number of reasons:
Is there a pattern to what day/time in the week this happens? Maybe your db machine has just come up
How many users do you have? Are there indexes to the database?
What about the database cache? Is it configured?
How do you know it's a database delay and not a network delay? Have you tried accessing from the local database server and seen if the delays happen there too?
If you have access to SQL Profiler, you might want to run that on the statement to see if anything is happening on the server that might be causing issues. I'd also check the execution path in Management Studio/Query Analyzer if you can as well. Otherwise, if those don't turn up anything it probably is something to do with the web-side of things, not SQL.
I'm not sure how to do this...
I have a database which contains a messages and categories tables.
The categories table has a field which has a count of the number of messages related to it.
Sometimes however I need to deactivate (active = 0) a message, at the moment this doesn't then update the category table... I will implement this is in the end but for the time I would just like to run a script perhaps daily that goes through all the categories, counts up the messages and updates the field.
What the best way of doing this?
Thanks in advance
Chris
If you are happy to do this manually you can create a Rake task. Push to Heroku, then execute using "heroku rake".
You could also use delayed_job, which Heroku supports. This does however cost you money $0.05 an hour. Given that it won't run very often or for very long, might be quite cheap.
The only other way I have done this stuff is to make a controller that wraps the logic and then call this. You can use one of the many and various ping services to trigger the call (these services are generally setup to request a page in your site) or setup a cron to use wget or curl to make the request.
I'm developing a Flash game in ActionScript 2, and the issue if that this game has to count the time securely.
It can't count the time from the Date class because the Flash Player takes the time from the local computer, and the user can change the local time so the time reported would be fake.
I haven't considerend to take the time from the server because there's a 3WH (3 way handshake) time and it would not be practical.
What do you sugest me??
You cannot perform secure computations on the user's system. They can manipulate it.
If that is a problem, your only real choice is to do it on the server. Of course, they could sandbox your app and fake a server conversation, so that's not entirely secure from within the client, but in most cases that won't cause a big problem since it should just affect that user (unless the data from the manipulated/forged server connection is then sent somewhere to affect other users).
When you are developing games that run on a system that you do not control there is basically no solution, you can make it hard for people but you can never be certain unless you basically modify your game to run on the server for all important parts. Even if you would make the game call the server for the time only people can insert a proxy and fake the response...
So is you really want to be sure no one messes with the game you have to make it run on the server (I know, lots of the time this is unwanted and/or impossible). In all other cases you can make it hard (obfuscate game code, encrypt communication) but never impossible - see google for lots of suggestions on making it hard, or see here and here.
The best way of solving the issue is to remove the incentive for players to cheat, so they simply won't try it at all -- of course lots of the time this is really hard.
See also: Cheat Engine, in case you didn't know about that one.