Game Lobby in PHP/MySQL - php

I'm creating a mobile game on various mobile platforms and have decided to use PHP/MySQL as the back end and communicate with this via JSON. (The game will be text based).
I'm lacking on idea's on how to implement this, the sort of logic i'm after is as follows;
User will need to register an account
User will enter the game lobby looking for an open slot
If there is a suitable game ready and waiting (not full and waiting for new players) then join
If not create a new game and await players
I was thinking of having 20 players for each game and only allowing the game to start when there's 3 or more players waiting. When there's 3 or more players waiting there would be a count down of say 60 seconds until the game began.
Now i know some of this might need to be done on the client side. I'm struggling on where to start!! So any idea's, code samples or links to reading material that may help would be very much appreciated.
thanks!

Based on comments, I'm guessing you're looking for some ideas on database schema, like Brad Christie suggests. So I'm going to start with that.
First, you'll need a table for the players. I'm guessing you already have one of those, but you'll probably want to include a field for the game ID that they're in.
Next, you'll need a table for the games. This is where you store information on the game itself, including whether it's active. To get the player count, you simply query the list of players with that game's ID. You could also keep track of player count and update it whenever the player leaves or joins the game, depending on a few factors.
Now, the game lobby itself. The exact method here really depends on how you want it to function. You can either use AJAX to keep a list of currently active games up to date (and set up some sort of chat system to let players talk while waiting), or you can use the game lobby as routing page. If you go the latter route, then query the active games, automatically dump the player into one that meets your criteria, then send the user to the 'main game page'.
Hopefully this will give you a solid outline on how to start. I'm afraid I can't help you much more unless I know more about your requirements.

For register a user you simply need a form and save that form in your database. When the user logs in the you query the database matching the password and user name.

Related

General questions about database

I would like to create e-learning platform. So users will have a lot of things to choose (mostly available to view only for them) like:
add note
add movies to favorite
rate the instructor
And few options that auto save for each user like:
unanswered questions
wrong answer questions
movies in progress (user saw only 2 min from 5)
So what database or method I schould use for store that kind of data?
I do not want to use cookies because it needs to be save on user account and not on browser. User need to have that all on every browser or mobile device.
I wondering about json but...if I do so each user I'd will be available to view...so schould I use MySQL?
I would recommend that you build your own data logger, what i mean by this is build yourself a place to store every users data like an eManager if you would like.
Once this has been built you can then assign the eLearning courses using an ID to each of the users profile on your "eManager". Allowing you too keep track of each users progress etc.
The "eManager" could also save the users notes/wrong answers/unanswered questions, you could create surveys with a slider rating to rate the user. Honestly the limit is endless.
You can receive the data in two different ways:
(Personal) Either you can request that your users email you requesting a username and you generate a password and send it out to the user.
(Commercial) You build your eManager to recieve the data from the website which isnt too difficult to do.
It will be a long process and to answer your question in a different view practice SQL/PHP that would be your base make sure you can run more advanced query's and can confidently edit your DB etc.
Anymore questions just let me know, thanks.

Getting Operation statistics of CSGO using steam web api

I want to fetch all Operations' statistics of Counter-Strike: Global Offensive for any user by his/her steam64 ID. I have found an api request url which returns a list of achievements for this user by app id.
http://api.steampowered.com/ISteamUserStats/GetPlayerAchievements/v0001/?appid=730&key=<<API KEY>>&steamid=<<STEAM64 ID>>
But it doesn't return any operation's statistics as far as i see. Experts, please help me to fetch all Operations' statistics of CSGO.
Achievements and operations are completly different things:
Achievements - Virtual badges you get during the game, for every game, triggered by the game itself
Operations - Paid set of missions (...), only in CS:GO, triggered by whether you got the operation or not
You can check if somebody took part in an operation by looking in his inventory (there should be a coin/ medal to identify) but the individual stats arenĀ“t accessible by the Web API.
If you still figure out a way to achieve this, please post this here.

Best way to save user view counts for advertisements in PHP & REST API

I have a REST API built with PHP & MySQL for storing ads.
My database contains an ads table and a users table.
I want to bump the view count for every ad once a user is viewing it (only once, if he views it for the 2nd time, I don't want to raise the count again).
Also, how do I go about setting up a service for the client? Psychologically it seems very aggressive to make a server request each time a user is watching an ad, it could get to hundreds of requests at the same time.
Thanks! :)

How to build chat rooms attached for a single user profile?

I have a simple php user profile system that works like this: When user is registered he gets a specific url ?user. Therefore, other visitors can access his page.
What I want it to include chat application on users profile pages. But, every single user should have its own chat.
Which approach is the best, as I am a beginner in this? Should I put the messages from chat into the database or should I work with some log.txt files?
Any good tutorial for this would be helpful.
I found some tutorial for you: http://tutorialzine.com/2010/10/ajax-web-chat-php-mysql/
- looks like it could help you.
The only thing you need to adjust is to add room column in WEBCHAT_LINES table - that will be the unique name of the user, into which's chat room the chat line belongs. Then, when new chat line will be sent, you must save it to DB with apropriate room identificator. When you display the messages in chat, you must filter the results in each room to show only the lines for this particular room.
If you haven't use database before, there are plenty tutorials about mysql around the internet - it's not that difficult.
Good luck! And use Google when you'll have some doubts.

PHP/MYSQL help for giving notifications to all users(followers) even millions of them

I want to make a system in PHP/MYSQL through which users of a site can follow/unfollow other users of the same site and when a user do some activity then that user's all followers should get a notification.
I know that I can create a seperate db tables called notifications and insert row in it for each user who needs to be notified separably like Facebook did, but i will not restrict users (i.e. on Facebook you cannot have more then 5000 friends), on my site users can follow any amount of users they wish, and if some user have 1 million followers then on my server his each and every activity will let my server down.
So how to accomplish this task, what kind of design do I need to use for my Mysql database, in what way do I need to call those rows so that i can send notifications to all followers of the user and the server also never let down.
The follower pulls the notifications from the users he follows. That way, a notification is a single row in a table. The rational is, that while I might have millions of followers, the number of people that I follow is quite small (probably less than 1000).
Also: think about a caching strategy.
Use a combination of your suggestion and the answer and comments from Oswald.
The author creates an update, which will then add records to the notifications table(s). If the author has 10,000 followers, then there are 10,000 entries. This will become quite large, and optimization, caching, etc... will need to be used.
The follower then connects at some interval (via a client similar to Facebook web or hand held) and pulls their notifications. In this case, I get notifications from my last visit or all my authors. Again, this may be 10,000 rows as you indicated, but with better keys, the retrieval will be quick, since you get notifications for the follower only (their ID). Once received, delete the pending notifications.
The second alternative would be to modify the notifications to simply have an entry for the author, and the post, and a date. The follower connects, queries for new postings since his last search, and then filter them by author. Try to remove as many records as possible in the first query, then attempt the filter as a second query or cached reference search. Do not try to link both queries as you will kill the database server. Using keys/indexes to get the smallest set first.
If the follower has a few authors, query for author updates first, then after the date. Otherwise, search after the date then by authors.

Categories