[PHP]Understanding how to implement server behavior?

Started by
2 comments, last by CC Ricers 9 years, 4 months ago

My inspiration for my server queries and question is my love for poker.

So let me start by saying that I'm currently developing a local poker system on my machine.

Right now I have the basic's down, generating hands, being able to determine best hands e.t.c.

This is all in PHP.

What I have started to question is, although I want just a basic system that can simulate a game between 2 players (That would be my machine on 2 different tabs).

I want to understand how to develop a server system for this.

My current "idea" of how this all would work, would be:

A "sever" is hosting a current table, waiting for players to join.

Two players join, currency is taken from their "bank" and the server now knows that the table is full and should begin a game.

Things happen in the server such as dishing out cards, allowing players to bet/check/fold e.t.c

At the end of a round one (or more) of the players accrue chips and then the process resets until all but one player remains.

I'm not really sure how I would go about processing server commands on a local system or how players would interact.

But I'm just looking for some guidance to get me on the right track.

I know I'm not asking for anything easy, but any knowledge would be very helpful right now.

Thank you, for taking time to read this and hopefully help me! :)

Advertisement

Hello Jackson,

this is actually easy. In traditional php everything that is php runs on the server and if you want to run anything

on the client you use JavaScript and HTML. If you want two parties to communicate you do this by keeping

a session and save the clients session and related data in a database.

It sounds like you are missing some basic knowledge of the technology you are using. My advise is, step back

and build some more basic applications like a chat before you move to bigger applications.

I also advise getting to know the technology very well, maybe do some tutorials on codeacademy and get a good reference for the programming languages you are trying to use.

Regards

Henry

If you get serious with this, you have to consider transactions and the security of the system. In a real poker system such as those used by online gambling there are lots of checks in place to ensure that you can't abuse a race condition to for example log in twice in a very short timeframe from two PCs and withdraw currency twice, leaving the account in the red.

By default MySQL's transaction support is set to a pretty poor setting and you will probably want to tweak it and make sure you set the right values in your my.cnf to ensure transactional integrity as well as using MYISAM tables.

Of course, if you're doing this for fun, don't worry too much for now, but it is something to consider!

As glportal suggested, you could use sessions. It's probably the easiest way to get into hosting different users with PHP. I was using this years ago when I was practicing making websites that store user information and take logins.

Since the game needs to update at certain times, like when cards are drawn, you'd need to choose an approach. Either AJAX works, or refresh the whole page with the new information (more crude, though). I prefer using AJAX to communicate between players in sending information.

New game in progress: Project SeedWorld

My development blog: Electronic Meteor

This topic is closed to new replies.

Advertisement