\[ALPHA\] FTC dice / coinflip game
-
[quote name=“iawgoM” post=“43766” timestamp=“1386936729”]
Btw. there is already something similar here: [url=http://www.ftcgames.eu/]http://www.ftcgames.eu/[/url]Pozdrav! :)
[/quote]Thanks for that! Ive made a tonne in winnings on the lucky 7 :D
-
So I noticed the page is kinda refreshing constantly. That can’t be good for server load.
Have you considered using WebSockets for the updates, so the server can push when there’s a change? socket.io makes this really trivial to do.
-
[quote name=“FTClover” post=“47166” timestamp=“1387832960”]
[quote author=iawgoM link=topic=5931.msg43766#msg43766 date=1386936729]
Btw. there is already something similar here: [url=http://www.ftcgames.eu/]http://www.ftcgames.eu/[/url]Pozdrav! :)
[/quote]Thanks for that! Ive made a tonne in winnings on the lucky 7 :D
[/quote]:o But I still need to buy a turkey. :‘( :’( :'(
[quote author=Kevlar link=topic=5931.msg47176#msg47176 date=1387834036]
So I noticed the page is kinda refreshing constantly. That can’t be good for server load.Have you considered using WebSockets for the updates, so the server can push when there’s a change? socket.io makes this really trivial to do.
[/quote]As you can see this was my ‘roll your own’ approach :D
I looked at (and even started) something called comet? (I think that was the name) but I got lost as it seemed overly complex for what I wanted to achieve (quickly) and had other things I wanted to prioritize.If you recommend sockets.io I will certainly take a look in the new year and yes CPU is @ 102% most of the time :o
Thanks!
-
It’s good start to implement:
- some sleep in your while true php code
- split the game handlers into different processes
- execute async tasks in the background via exec
Refreshing the site on ~5 sec. it’s annoying only for the user for server is nothing on small load :)
-
[quote name=“UKMark” post=“47196” timestamp=“1387837794”]
[quote author=FTClover link=topic=5931.msg47166#msg47166 date=1387832960]
[quote author=iawgoM link=topic=5931.msg43766#msg43766 date=1386936729]
Btw. there is already something similar here: [url=http://www.ftcgames.eu/]http://www.ftcgames.eu/[/url]Pozdrav! :)
[/quote]Thanks for that! Ive made a tonne in winnings on the lucky 7 :D
[/quote]:o But I still need to buy a turkey. :‘( :’( :'(
[quote author=Kevlar link=topic=5931.msg47176#msg47176 date=1387834036]
So I noticed the page is kinda refreshing constantly. That can’t be good for server load.Have you considered using WebSockets for the updates, so the server can push when there’s a change? socket.io makes this really trivial to do.
[/quote]As you can see this was my ‘roll your own’ approach :D
I looked at (and even started) something called comet? (I think that was the name) but I got lost as it seemed overly complex for what I wanted to achieve (quickly) and had other things I wanted to prioritize.If you recommend sockets.io I will certainly take a look in the new year and yes CPU is @ 102% most of the time :o
Thanks!
[/quote]Comet is an umbrella term for HTTP Streaming technologies. I’m not sure which framework you were looking into, but sockets.io couldn’t be simpler:
Server side:
io.sockets.emit(“newBet”, “{betData:…}”);Client side:
io.on(“connect”, function(socket){
socket.on(“newBet”, function(newBet){
//insert page rendering code here.
};
});
io.connect(“http://serverUrl.com”) -
[quote name=“slavco” post=“47199” timestamp=“1387838347”]
It’s good start to implement:- some sleep in your while true php code
- split the game handlers into different processes
- execute async tasks in the background via exec
Refreshing the site on ~5 sec. it’s annoying only for the user for server is nothing on small load :)
[/quote]Yes sleep works well to stop the constant polling BUT when testing we found it would fail on multiple bets in a single TX. :( (system can currently handle 3 at the minute, 5 if spread accross both games)
I already run separate processes for each game, maybe I will split for each address also.
Will look into exec.I have thought about redesigning the whole game engines to use a DB and then maybe just poll once every 10 seconds, verify tx in db add/remove it - run game or quit etc…Not sure whether users would appreciate that sort of delay with a dice game though. Plus it would probably cause other issues too. :-\
-
[quote name=“Kevlar” post=“47200” timestamp=“1387838612”]
[quote author=UKMark link=topic=5931.msg47196#msg47196 date=1387837794]
[quote author=Kevlar link=topic=5931.msg47176#msg47176 date=1387834036]
So I noticed the page is kinda refreshing constantly. That can’t be good for server load.
Have you considered using WebSockets for the updates, so the server can push when there’s a change? socket.io makes this really trivial to do.
[/quote]As you can see this was my ‘roll your own’ approach :D
I looked at (and even started) something called comet? (I think that was the name) but I got lost as it seemed overly complex for what I wanted to achieve (quickly) and had other things I wanted to prioritize.If you recommend sockets.io I will certainly take a look in the new year and yes CPU is @ 102% most of the time :o
Thanks!
[/quote]Comet is an umbrella term for HTTP Streaming technologies. I’m not sure which framework you were looking into, but sockets.io couldn’t be simpler:
Server side:
io.sockets.emit(“newBet”, “{betData:…}”);Client side:
io.on(“connect”, function(socket){
socket.on(“newBet”, function(newBet){
//insert page rendering code here.
};
});
io.connect(“http://serverUrl.com”)
[/quote]Seems very simple, will look into it cheers.
-
There you go gringo :) https://github.com/Slavco/dicestart you can use it on raspberry pi as game calculator and have separate site for the play addresses anouncement ( shared hosting is too much for it ;) )
-
[quote name=“slavco” post=“47322” timestamp=“1387898026”]
There you go gringo :) https://github.com/Slavco/dicestart you can use it on raspberry pi as game calculator and have separate site for the play addresses anouncement ( shared hosting is too much for it ;) )
[/quote]Nice work gringo! 8)
-
[quote name=“slavco” post=“47322” timestamp=“1387898026”]
There you go gringo :) https://github.com/Slavco/dicestart you can use it on raspberry pi as game calculator and have separate site for the play addresses anouncement ( shared hosting is too much for it ;) )
[/quote]You write VERY good code. It’s clean, easy to read, and easy to understand. As one experienced coder to another who takes great pride in his art, the highest compliment I could pay you is that it’s indistinguishable from something I would write. Very nicely done.
I have but one criticism: Your heads/tails scripts have entirely too much in common (namely practically their entire contents), and should be refactored to a common include with only the part that changes in separate files, so both heads.php and tails.php would start with an include of common functions.
Other than that, it’s solid work and you should be proud. Keep it up!
-
[quote name=“Kevlar” post=“47354” timestamp=“1387909764”]
[quote author=slavco link=topic=5931.msg47322#msg47322 date=1387898026]
There you go gringo :) https://github.com/Slavco/dicestart you can use it on raspberry pi as game calculator and have separate site for the play addresses anouncement ( shared hosting is too much for it ;) )
[/quote]You write VERY good code. It’s clean, easy to read, and easy to understand. As one experienced coder to another who takes great pride in his art, the highest compliment I could pay you is that it’s indistinguishable from something I would write. Very nicely done.
I have but one criticism: Your heads/tails scripts have entirely too much in common (namely practically their entire contents), and should be refactored to a common include with only the part that changes in separate files, so both heads.php and tails.php would start with an include of common functions.
Other than that, it’s solid work and you should be proud. Keep it up!
[/quote]Thanks a lot Kevlar. I keep the code most simple only because I want everyone to understand it and ofc. used some tricks to make project easy to scale ( exec change to gearman/rabbitmq/something similar call ).
Good notice about duplicate code at head / tail script ( only senior could point at that from first code check ) but I have put it for reason also. I have put the code that only because to give example how anyone in easy way could create it’s own game and to find the logic how to add all the needed settings in the configuration file.
From Readme.md
[quote author=slavco]
How to create your game: If you can’t figure out from play/coinflip/head.php or tail.php manual soon
[/quote]Anyway good thing is that now I’ll have some free time and I’ll use it on Link project ( yup I’m updated and very big fan of the protocol ) :) . I know everything about it but haven’t try it and that’s why I was off discussion.
Also, thanks UKMark and wish you luck optimizing your project
-
[quote name=“slavco” post=“47374” timestamp=“1387916061”]
Also, thanks UKMark and wish you luck optimizing your project
[/quote]And you also:
[code]foreach ($ftc->listtransactions($key,1) as $transaction) {
if ($transaction[‘category’] == ‘receive’) {
$info[‘account’] = $transaction[‘account’];
$info[‘address’] = $transaction[‘address’];
$info[‘amount’] = $transaction[‘amount’];
$info[‘txid’] = $transaction[‘txid’];
$txdetails = $ftc->getrawtransaction($transaction[‘txid’],1);
$getvin = $txdetails[‘vin’][‘0’][‘txid’];
$sender = $txdetails[‘vin’][‘0’][‘vout’];
$txdetails = $ftc->getrawtransaction($getvin,1);
$address = $txdetails[‘vout’][$sender][‘scriptPubKey’][‘addresses’][‘0’];
}
}[/code] -
[quote name=“iawgoM” post=“43766” timestamp=“1386936729”]
Btw. there is already something similar here: [url=http://www.ftcgames.eu/]http://www.ftcgames.eu/[/url]Pozdrav! :)
[/quote]Who made ftcgames.eu?
-
[quote name=“FTClover” post=“47412” timestamp=“1387928132”]
[quote author=iawgoM link=topic=5931.msg43766#msg43766 date=1386936729]
Btw. there is already something similar here: [url=http://www.ftcgames.eu/]http://www.ftcgames.eu/[/url]Pozdrav! :)
[/quote]Who made ftcgames.eu?
[/quote]IawgoM made the front end, I made the back end.