Making a P2P game or anything else using PHP...
Moderator: General Moderators
-
The-Master
- Forum Commoner
- Posts: 45
- Joined: Sun Aug 07, 2005 9:51 am
- Location: Israel
Making a P2P game or anything else using PHP...
Hi, recently i got the idea of making a text-based browser game using PHP, but, the game will be directly between the players(Peer2Peer), for example if one player challenges another it will auto redirect him to the game script... i thought of using socket for this great idea... if you have any other suggestion i'll be glad to hear...
if some of you are intrested in PHP+Socket check this:
http://www.zend.com/pecl/tutorials/sock ... c=0&view=1
if some of you are intrested in PHP+Socket check this:
http://www.zend.com/pecl/tutorials/sock ... c=0&view=1
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
-
The-Master
- Forum Commoner
- Posts: 45
- Joined: Sun Aug 07, 2005 9:51 am
- Location: Israel
well both are nice, it doesn't matter, but real-time is better 
if you know anything that can provide this great feature, i'll be more than happy to hear 'bout it!
the DB is ready and the registration, login, members list, some game info and graphics are ready but the game itself is yet to be made...
if you know anything that can provide this great feature, i'll be more than happy to hear 'bout it!
the DB is ready and the registration, login, members list, some game info and graphics are ready but the game itself is yet to be made...
Your PHP code is still running on the server, in order to open a socket on a machine the code has to be running on that machine, that would mean either writing a client side application in java for example and opening the socket locally, which eliminates the need for PHP, what you could do however with PHP is have each client connected to the server and have the server relay messages to the appropriate client
-
The-Master
- Forum Commoner
- Posts: 45
- Joined: Sun Aug 07, 2005 9:51 am
- Location: Israel
that sounds nice but i don't know how to write java applications... but i like the idea of a client side application.
it may be possible to open a socket at the same machine that the code is running on if i find a host that provides this service but minwhile the application is the only way.
is there some other language usable to make a client side application?
if not, do you know a site or a book that can teach me to write Java applications?
it may be possible to open a socket at the same machine that the code is running on if i find a host that provides this service but minwhile the application is the only way.
is there some other language usable to make a client side application?
if not, do you know a site or a book that can teach me to write Java applications?
-
Charles256
- DevNet Resident
- Posts: 1375
- Joined: Fri Sep 16, 2005 9:06 pm
-
The-Master
- Forum Commoner
- Posts: 45
- Joined: Sun Aug 07, 2005 9:51 am
- Location: Israel
k thanks! i found some cool thing using men's best friend!(google):
http://java.sun.com/j2ee/releases/
this may be my solution!
by the way are you talking about http://www.priadoblender.com ?
http://java.sun.com/j2ee/releases/
this may be my solution!
by the way are you talking about http://www.priadoblender.com ?
-
The-Master
- Forum Commoner
- Posts: 45
- Joined: Sun Aug 07, 2005 9:51 am
- Location: Israel
well in the start of my project i didn't want to even look at other languages such as Java i wanted pure PHP, the game is highly featured and it's all written in PHP until i got to the battle part of it... php didn't provide the feature i needed... so i turned to other languages... i just need to make one small application using java, nothing fancy... if i'll learn the basics of java i am ready to go...
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
I have read that this http://www.heroesmini.com/ is a PHP/Ajax application. You might want to look at it for ideas/inspiration.
(#10850)
-
The-Master
- Forum Commoner
- Posts: 45
- Joined: Sun Aug 07, 2005 9:51 am
- Location: Israel
i found the way! this is it! just need to test it!
the way is:
i make a table named "battle" wich consists 3 rows:
*battle int(11) ===> this is a 0/1(yes/no) row wich tells us if the player is in-battle or out of battle...
*attacker char(50) ===> this tells us the name of the player attacking someone(only for someone who is being attacked).
*defencer char(5) ===> this tells us the name of the player defending(the one who is being attacked) this is only for attacking players.
*when someone is entering a battle his "battle" row in the DB changes to "1" wich means in-battle.
*whenever the battle is ended both "attacker" and "defender" are unset in the DB...
and the main code:
and all the vars of the player stats(race, class, HP, MP, etc...) will be set to a session in the defender and the attacker side from the $_GET['enemy'] thing...
you think this will work? if you do any suggestions to improve?
the way is:
i make a table named "battle" wich consists 3 rows:
*battle int(11) ===> this is a 0/1(yes/no) row wich tells us if the player is in-battle or out of battle...
*attacker char(50) ===> this tells us the name of the player attacking someone(only for someone who is being attacked).
*defencer char(5) ===> this tells us the name of the player defending(the one who is being attacked) this is only for attacking players.
*when someone is entering a battle his "battle" row in the DB changes to "1" wich means in-battle.
*whenever the battle is ended both "attacker" and "defender" are unset in the DB...
and the main code:
Code: Select all
// pull data from table "battle"
if($battle == 1) {
// redirect the player to the "battle.php" page...
}
elseif($attacker != "") {
// redirect the player to the "defend.php?enemy=$attacker" page...
}
elseif($defender != "") {
// redirect the player to the "attack.php?enemy=$defender" page...
}
else {
// go to main game page...
}you think this will work? if you do any suggestions to improve?
First, if you have a column in mysql that is only 0 or 1, I suggest using the ENUM datatype (since you'll never need 4,000,000 [or whatever the INT type goes up to unsigned] in that column).
Second, here is the simple answer: For now, web-based PHP applications have no real-time abilities.
You can somewhat get around this by using the XMLHttpRequest (or the corresponding activex [module? - i forget the technical name] for IE) object in Javascript. Using this, you could
1) have the relevant information about a battle saved on the server (XML file/database/whatever)
2) have the XMLHttpRequest object query the server every few seconds (using setTimeout in JS)
3) if there has been a change then the server should respond with the necessary information
4) use JS to update the page as necessary
Making a web-based game with PHP/MySQL/Javascript is a concept I've been toying around with theoretically (I haven't put together anything in code yet). The limitations of the technologies mean that you could probably come up with a nice game that is a turn-based/real-time hybrid (I think). It would be like a fast-paced turn-based game.
One thing to keep in mind though is that the more times you're connecting to your server, the more of a performance hit it will be. I can imagine a disaster in the situation where a lot of people are playing against each other and the server is getting swamped with update requests from the browser.
All of the stuff I just talked about is well-documented by the way, just look up AJAX.
Second, here is the simple answer: For now, web-based PHP applications have no real-time abilities.
You can somewhat get around this by using the XMLHttpRequest (or the corresponding activex [module? - i forget the technical name] for IE) object in Javascript. Using this, you could
1) have the relevant information about a battle saved on the server (XML file/database/whatever)
2) have the XMLHttpRequest object query the server every few seconds (using setTimeout in JS)
3) if there has been a change then the server should respond with the necessary information
4) use JS to update the page as necessary
Making a web-based game with PHP/MySQL/Javascript is a concept I've been toying around with theoretically (I haven't put together anything in code yet). The limitations of the technologies mean that you could probably come up with a nice game that is a turn-based/real-time hybrid (I think). It would be like a fast-paced turn-based game.
One thing to keep in mind though is that the more times you're connecting to your server, the more of a performance hit it will be. I can imagine a disaster in the situation where a lot of people are playing against each other and the server is getting swamped with update requests from the browser.
All of the stuff I just talked about is well-documented by the way, just look up AJAX.