• Login
  • Register
  • Zoek
This Thread
  • Everywhere
  • This Thread
  • This Forum
  • Articles
  • Pages
  • Forum
  • Filebase Entry
  • More Options

ICTscripters

Dé plek voor IT

Dé plek voor IT

Login

Geavanceerde opties
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
  3. ICT Nieuws
  4. Blog
  5. Marktplaats
    1. Werk
    2. Advertenties
    3. Domeinnamen
    4. Websites
    5. Design & lay-outs
    6. Scripts
    7. Overige
  6. Design
  7. Leden
    1. Actieve bezoekers
    2. Team
    3. Leden zoeken
  8. Downloads
  9. Goedkope domeinnamen
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
  3. ICT Nieuws
  4. Blog
  5. Marktplaats
    1. Werk
    2. Advertenties
    3. Domeinnamen
    4. Websites
    5. Design & lay-outs
    6. Scripts
    7. Overige
  6. Design
  7. Leden
    1. Actieve bezoekers
    2. Team
    3. Leden zoeken
  8. Downloads
  9. Goedkope domeinnamen
  1. Home
  2. Forum
    1. Alle berichten
    2. Recente activiteiten
  3. ICT Nieuws
  4. Blog
  5. Marktplaats
    1. Werk
    2. Advertenties
    3. Domeinnamen
    4. Websites
    5. Design & lay-outs
    6. Scripts
    7. Overige
  6. Design
  7. Leden
    1. Actieve bezoekers
    2. Team
    3. Leden zoeken
  8. Downloads
  9. Goedkope domeinnamen
  1. Dé plek voor IT - ICTscripters
  2. Forum
  3. Games
  4. Criminals & Maffiagames
  5. Uitbreidingen en Overige
  6. Archief
  7. Criminolz

Forum

  • Het Grote Vibe Code Topic

    Syntax 25 maart 2026 om 11:46
  • PWYL source gezocht

    Syntax 25 maart 2026 om 11:44
  • Ictscripters Chat

    Frenzo.Brouwer 9 maart 2026 om 21:31
  • Help testers nodig voor android app Urgent

    Servertjee 20 februari 2026 om 12:07
  • Partner Gezocht om meerdere NFT Collecties op Open Sea te Plaatsen

    Servertjee 20 februari 2026 om 12:06
  • Afspraken systeem met planbeperking

    Jeffrey.Hoekman 20 februari 2026 om 11:52
  • Developer Gezocht

    Servertjee 19 februari 2026 om 17:31
  • Na 15 jaar terug van weggeweest: iCriminals.nl is terug (BETA)!

    Servertjee 18 februari 2026 om 16:57

Marktplaats

  • Domeinportfolio uitkuis

    Syntax 19 maart 2026 om 10:18
  • Heel wat sterke domeinen > 2 letters, 3 letters, premiums

    Michael DW 11 maart 2026 om 12:12
  • 367 Nieuwe Domeinnamen Februari 2026

    shiga 1 maart 2026 om 14:50

problemen met poker script

  • sjoepie
  • 12 oktober 2010 om 18:37
  • sjoepie
    Beginner
    Berichten
    3
    • 12 oktober 2010 om 18:37
    • #1

    goede Avond,

    ik heb een probleem met me poker script heb hem namelijk van iemand gekregen voor de vendetta source alleen als ik iets wil beginnen doet die niks kunnen jullie helpen wat er mis is

    PHP
    <center><img src="images/geluksrad.png"></center>
    <link rel="stylesheet" type="text/css" href="style.css">
    <?php
        error_reporting(E_ALL);
    	include("config.php");
    	$dbres = mysql_query("SELECT *,UNIX_TIMESTAMP(`pc`) AS `pc`,UNIX_TIMESTAMP(`transport`) AS `transport`,UNIX_TIMESTAMP(`bc2`) AS `bc2`,UNIX_TIMESTAMP(`slaap`) AS `slaap`,UNIX_TIMESTAMP(`kc`) AS `kc`,UNIX_TIMESTAMP(`start`) AS `start`,UNIX_TIMESTAMP(`crime`) AS `crime`,UNIX_TIMESTAMP(`ac`) AS `ac` FROM `users` WHERE `login`='{$_SESSION['login']}'");  
    	$data    = mysql_fetch_object($dbres);
      if(! check_login()) {
        header("Location: login.php");
        exit;
      }
    if ($jisin == 1) { header("Location: jisin.php"); }
    
    
    
    
    
    
    
    
    /*if (!in_array($_SESSION['login'], array('Josh', 'sjoepcoup', 'Josh-Tester', 'Josh-Tester2','vladykx','panza','ptest1','pokerAdict'))) {
    	die('Under Construction Few Bugs Found');
    }*/
    
    
    
    
    $login = $_SESSION['login'];
    $time = time();
    $maxante = 999999999;
    $maxmaxraise = 0;
    $maxraisesperturn = 2;
    $timelimit = 120;
    $message = '';
    $types = array('c', 'd', 'h', 's');
    $fulltypes = array('c' => 'club', 'd' => 'diamond', 'h' => 'heart', 's' => 'spade');
    mt_srand($time);
    echo "$style";
    
    
    $action = $_GET['action'];
    $game = getGame();
    
    
    if ($game && isGameOn() && (int)$game['lastmove'] < ($time - $timelimit)) {
    	foldPlayer($game['current']);
    }
    
    
    if ((int)$game['allin']) {
    	$action = 'game';
    }
    elseif ($action == 'game' && (!$game || !(int)$game['allin'])) {
    	$action = null;
    }
    
    
    switch ($action) {
    	case 'joinleave':
    		if ($_POST['leave'] == 'Leave'){
    			$message = removePlayer($login);
    		}
    		elseif ($_POST['join'] == 'Join') {
    			$password = $_POST['password'];
    			$id = (int)$_GET['id'];
    
    
    			if (strlen($password)) {
    				$password = md5($password);
    			}
    
    
    			if (!$id) {
    				$message = 'Hacking Attempt?!';
    			}
    			else {
    				$message = addPlayer($id, $password);
    				if ($game && (int)$game['allin']) {
    					showGame($message);
    					break;
    				}
    			}
    		}
    		showGames($message);
    	break;
    	case 'start':
    		if ($_POST['start'] == 'Start!') {
    			$ante = (int)$_POST['ante'];
    			$maxraise = (int)$_POST['maxraise'];
    			$password = $_POST['password'];
    			$message = false;
    			
    			if ($maxante && $ante > $maxante) {
    				$message = 'Ante\'s too big. Largest allowed: &pound;'.$maxante;
    			}
    			elseif ($ante <= 0) {
    				$message = 'Ante\'s too small. Has to be at least &pound;1';
    			}
    
    
    			if ($maxmaxraise && $maxraise > $maxmaxraise) {
    				$message = 'Max raise is too big. Largest allowed: &pound;'.$maxmaxraise;
    			}
    			elseif ($maxraise <= 0) {
    				$maxraise = 'null';
    			}
    
    
    			if (strlen($password)) {
    				$password = "'".md5($password)."'";
    			}
    			else {
    				$password = 'null';
    			}
    
    
    			$user = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE login='{$login}'"));
    			if ((int)$user['zak'] <= $ante) {
    				$message = 'You don\'t have enough zak to start with that ante';
    			}
    			elseif ((int)$user['inpoker']) {
    				$message = 'You\'re already in a poker game';
    			}
    			
    			if ((int)$game['poker'] && $action=='start') {
    				$message = "You're already in a game";
    			}
    
    
    			if (!$message) {
    				$message = insertGame( $ante, $maxraise, $password );
    			}
    
    
    		}
    		showGames($message);
    	break;
    	case 'game':
    		$gaction = $_POST['gmact'];
    
    
    		switch ($gaction) {
    			case 'Raise':
    				if (isAllowedRaise()) {
    					$amount = (int)$_POST['amount'];
    					$message = raiseGame($amount);
    				}
    				showGame($message);
    			break;
    			case 'Call':
    				if (isAllowedCall()) {
    					$message = callGame();
    				}
    				showGame($message);
    			break;
    			case 'Check':
    				if (isAllowedCheck()) {
    					$message = checkGame();
    				}
    				showGame($message);
    			break;
    			case 'Swap':
    				if (isAllowedSwap()) {
    					$cards = $_POST['card'];
    
    
    					$message = swapCards($cards);
    				}
    				showGame($message);
    			break;
    			case 'Fold':
    				if (isAllowedFold()) {
    					$message = foldPlayer($_SESSION['login']);
    				}
    				showGames($message);
    			break;
    			case 'Leave':
    				if (strlen($game['winners'])) {
    					$message = leaveGame();
    				}
    				showGames($message);
    			break;
    			default:
    				showGame();
    			break;
    		}
    	break;
    	default:
    		showGames();
    	break;
    }
    
    
    
    
    function showGames($message = false) {
    	global $game;
    	$result = mysql_query('SELECT * FROM poker');
    
    
    	$join = "<input name='join' type='submit' value='Join' />";
    	$leave = "<input name='leave' type='submit' value='Leave' />";
    	$pwd = "<input name='password' type='password' />";
    
    
    	echo ($message?"<div align='center' class='error'>{$message}</div>":'');
    	echo "<table width=70% cellspacing=0 cellpadding=2 rules=none align=center border=1 bordercolor=black class=thinline bordercolor=#000000 bgcolor=#808080 style=\"border-collapse: collapse\" >
    			<tr><td colspan=10 background='../includes/grad.jpg' height='21'><div align=center>Poker</div></td></tr>
    			<tr class='headr'><th bgcolor='white'><font color=black>Game </th><th bgcolor='White'><font color=black>Player 1</th><th bgcolor='white'><font color=black>Player 2</th><th bgcolor='White'><font color=black>Player 3 </th><th bgcolor='white'><font color=black>Player 4</th><th bgcolor='White'><font color=black>Ante </th><th bgcolor='white'><font color=black>Max raise </th><th bgcolor='White'><font color=black>Pot </th><th bgcolor='white'><font color=black>Join / Leave </th><th bgcolor='White'><font color=black>Password </th></tr>";
    	
    	if (mysql_num_rows($result)) {
    		while ($sgame = mysql_fetch_array($result)) {
    			$status = explode(':', $sgame['status']);
    			for ($k=0;$k<=4;$k++) {
    				$player[$k] = (int)$status[$k]?$sgame['player'.($k+1)]:"<strike>{$sgame['player'.($k+1)]}</strike>";
    			}
    			echo "<form action='newpoker.php?action=joinleave&id={$sgame['id']}' method='POST'><tr class='text'><td># {$sgame['id']}</td><td>{$player[0]}</td><td>{$player[1]}</td><td>{$player[2]}</td><td>{$player[3]}</td><td align='center'>&pound;{$sgame['ante']}</td><td align='center'>".($sgame['maxraise']?'&pound;'.$sgame['maxraise']:'Not Set')."</td><td align='center'>&pound;{$sgame['pot']}</td><td align='center'>".($game['poker']==$sgame['id']?$leave:(isJoin($sgame)?$join:'x'))."</td><td align='center'>".(!$game['poker']?($sgame['password']?$pwd:'Not Set'):'x')."</td></tr></form>";
    		}
    	}
    	else {
    		echo "<tr><td colspan='10' align='center'>No Games!</td></tr>";
    	}
    
    
    	echo "</table>";
    
    
    	echo "<br /><table width=25% cellspacing=0 cellpadding=2 align=center border=1 bordercolor=black class=thinline bordercolor=#000000 bgcolor=#808080 style=\'border-collapse: collapse\" >
    			<tr><td colspan=10 background='../includes/grad.jpg' height='21'><div align=center>Start a Game</div></td></tr>
    			<form method='post' action='newpoker.php?action=start'>
    
    
    			<tr><td height='1' colspan='2' bgcolor='black'></td></tr>
    			<tr class='headr'><th colspan='2' bgcolor='white'>Create a new game:</th></tr>
    			<tr><td height='1' bgcolor='black' colspan='2'></td></tr>
    			<tr><td>Ante: </td><td><input type='text' name='ante' maxlength='10' /></td></tr>
    			<tr><td>Max raise: </td><td><input type='text' name='maxraise' maxlength='10' /></td></tr>
    			<tr><td colspan='2'><font size='1'><i><center>Leave blank to have no max raise.</center></i></font></td></tr>
    			<tr><td>Password: </td><td><input type='text' name='password' maxlength='10' /></td></tr>
    
    
    			<tr><td colspan='2'><font size='1'><i><center>Leave box empty to leave game unlocked.</center></i></font></td></tr>
    			<tr><td align='center' colspan='2'><input type='submit' name='start' value='Start!' /></td></tr>
    			</form>
    		</table>
    <br>
    <table cellspacing=0 cellpadding=2 align=center border=1 bordercolor=black class=thinline bordercolor=#000000 bgcolor=#808080 style=border-collapse: collapse >
    			<tr><td colspan=10 background='includes/grad.jpg' height='21'><div align=center>Types of hands from best to worst</div></td></tr>
    			<tr><td colspan='2' bgcolor='black' height='1'></td></tr>
    			<tr><td align='left'>Royal Flush</td><td align='left'><b><img src='images/cards/spade.gif'>A-<img src='images/cards/spade.gif'>K-<img src='images/cards/spade.gif'>Q-<img src='images/cards/spade.gif'>J-<img src='images/cards/spade.gif'>10</b></td></tr>
    
    
    			<tr><td align='left'>Straight Flush</td><td align='left'><b><img src='images/cards/heart.gif'>8-<img src='images/cards/heart.gif'>7-<img src='images/cards/heart.gif'>6-<img src='images/cards/heart.gif'>5-<img src='images/cards/heart.gif'>4</b></td></tr>
    			<tr><td align='left'>4 Of A Kind</td><td align='left'><b><img src='images/cards/club.gif'>K-<img src='images/cards/diamond.gif'>K-<img src='images/cards/spade.gif'>K-<img src='images/cards/heart.gif'>K-x</b></td></tr>
    			<tr><td align='left'>Full House</td><td align='left'><b><img src='images/cards/club.gif'>K-<img src='images/cards/spade.gif'>K-<img src='images/cards/heart.gif'>K-<img src='images/cards/diamond.gif'>J-<img src='images/cards/spade.gif'>-J</b></td></tr>
    
    
    			<tr><td align='left'>Flush</td><td align='left'><b><img src='images/cards/diamond.gif'>2-<img src='images/cards/diamond.gif'>5-<img src='images/cards/diamond.gif'>8-<img src='images/cards/diamond.gif'>Q-<img src='images/cards/diamond.gif'>A</b></td></tr>
    			<tr><td align='left'>Straight</td><td align='left'><b><img src='images/cards/club.gif'>4-<img src='images/cards/diamond.gif'>5-<img src='images/cards/spade.gif'>6-<img src='images/cards/heart.gif'>7-<img src='images/cards/club.gif'>8</b></td></tr>
    			<tr><td align='left'>3 Of A Kind</td><td align='left'><b><img src='images/cards/diamond.gif'>7-<img src='images/cards/club.gif'>7-x-<img src='images/cards/heart.gif'>7-x</b></td></tr>
    
    
    			<tr><td align='left'>2 Pair</td><td align='left'><b><img src='images/cards/diamond.gif'>J-<img src='images/cards/spade.gif'>J-<img src='images/cards/heart.gif'>2-<img src='images/cards/diamond.gif'>2-x</b></td></tr>
    			<tr><td align='left'>Pair</td><td align='left'><b>x-x-<img src='images/cards/club.gif'>A-x-<img src='images/cards/spade.gif'>A</b></td></tr>
    			<tr><td align='left'>High Card</td><td><b>x-x-x-x-x</b></td></tr>
    		</table>";
    
    
    	echo "<br>";
    }
    
    
    function showGame($message = false) {
    	global $fulltypes, $game;
    
    
    	$raise = isAllowedRaise()?"<td><input type='text' name='amount' maxlength='10' /> <input type='submit' name='gmact' value='Raise' /></td>":'';
    	$check = isAllowedCheck()?"<td><input type='submit' name='gmact' value='Check' /></td>":'';
    	$call = isAllowedCall()?"<td><input type='submit' name='gmact' value='Call' /></td>":'';
    	$swap = isAllowedSwap()?"<td><input type='submit' name='gmact' value='Swap' /></td>":'';
    	$fold = isAllowedFold()?"<td><input type='submit' name='gmact' value='Fold' /></td>":'';
    	$exit = !isGameOn()?"<td><input type='submit' name='gmact' value='Leave' /></td>":'';
    	$status = explode(':', $game['status']);
    
    
    	echo "<head><meta http-equiv='Refresh' content='30'></head>";
    	echo ($message?"<div align='center' class='error'>{$message}</div>":'');
    	if (strlen($game['winners'])) {
    		$winners = explode ('/', $game['winners']);
    		echo "<br /><table cellspacing=0 cellpadding=2 align=center border=1 bordercolor=black class=thinline bordercolor=#000000 bgcolor=#808080 style=\"border-collapse: collapse\" >
    						<tr valign='top'><td>
    							<table cellspacing=0 cellpadding=2 align=center border=1 bordercolor=black class=thinline bordercolor=#000000 bgcolor=#808080 style=\"border-collapse: collapse\" >
    								<tr><td colspan=10 background='includes/grad.jpg' height='21'><div align=center>Winers</div></td></tr>
    								<tr><td align='center'>login</td><td align='center'>Amount</td></tr>";
    
    
    		foreach ($winners as $winner) {
    			$win = explode(':', $winner);
    			echo "<tr><td align='center'>{$win[0]} ({$win[2]})</td><td align='center'>&pound;{$win[1]}</td></tr>";
    		}
    
    
    		echo "</table></td></tr></table><br />";
    	}
    
    
    	echo "<form action='newpoker.php?action=game' method='POST'><table cellspacing=0 cellpadding=2 align=center border=1 bordercolor=black class=thinline bordercolor=#000000 bgcolor=#808080 style=\"border-collapse: collapse\" >
    					<tr><td colspan=10 background='../includes/grad.jpg' height='21'><div align=center>Poker</div></td></tr>
    					<tr><td colspan='5' height=1 bgcolor='black'></td></tr>
    					<tr><td colspan='5' align='center' height='100px' bgcolor='Blue'>";
    
    
    	for ($i=1;$i<=4;$i++) {
    		$me = ($game['player'.$i] == $_SESSION['login']);
    
    
    		if ($game['current']==$game['player'.$i]) {
    			$player = "<b>>></b> <a href='profile.php?viewuser={$game['player'.$i]}'><b><font color='Blue'>{$game['player'.$i]}</font></b></a> <b><<</b> (&pound;{$game['zak'.$i]})";
    		}
    		elseif (!$status[$i-1]) {
    			$player = "<strike><a href='profile.php?viewuser={$game['player'.$i]}'>{$game['player'.$i]}</a> (&pound;{$game['zak'.$i]})</strike>";
    		}
    		else {
    			$player = "<a href='profile.php?viewuser={$game['player'.$i]}'>{$game['player'.$i]}</a> (&pound;{$game['zak'.$i]})";
    		}
    
    
    		echo "<table>
    					<tr><td colspan='5' bgcolor='red' align='center' style='color: #000000'>{$player}</td></tr><tr>";
    
    
    		if ($me || (strlen($game['winners']) && $status[$i-1] != '0') ) {
    			$hand = new hand($game['cards'.$i]);
    			foreach ($hand->cards as $key => $card) {
    				$swp = isAllowedSwap()?"<br /><input type='checkbox' name='card[{$key}]' value='1' />":'';
    				echo "<td align='center'><img src='images/cards/{$fulltypes[$hand->types[$key]]}/{$hand->values[$key]}.gif' border='0' />{$swp}</td>";
    			}
    		}
    		else {
    			for ($j=0;$j<=4;$j++){
    				echo "<td align='center'><img src='images/cards/cardback/cardback.gif' border='0' /> </td>";
    			}
    		}
    
    
    		echo "</tr></table>";
    	}
    
    
    
    
    	echo "<tr><td><table><tr>{$raise}{$check}{$call}{$swap}{$fold}{$exit}</tr></table></td></tr></table></form>";
    
    
    	if (!strlen($game['winners'])) {
    		echo "<br /><table cellspacing=0 cellpadding=2 align=center border=1 bordercolor=black class=thinline bordercolor=#000000 bgcolor=#808080 style=\"border-collapse: collapse\" >
    						<tr valign='top'><td>
    							<table cellspacing=0 cellpadding=2 align=center border=1 bordercolor=black class=thinline bordercolor=#000000 bgcolor=#808080 style=\"border-collapse: collapse\" >
    								<tr><td colspan=10 background='../includes/grad.jpg' height='21'><div align=center>Game Statistics</div></td></tr>
    								<tr><td>Turn:</td><td>{$game['current']}</td></tr>
    								<tr><td>Turn time left:</td><td>".(getTimeLeft())."</td></tr>
    								<tr><td>Pot:</td><td>&pound;{$game['pot']}</td></tr>
    								<tr><td>Max raise:</td><td>".($game['maxraise']?"&pound;{$game['maxraise']}":'Not Set')."</td></tr>
    								<tr><td colspan='2'>Cards swapped</td></tr>
    								<ul><tr><td><li>{$game['player1']}</td><td>{$status[4]}</li></td></tr>
    								<tr><td><li>{$game['player2']}</td><td>{$status[5]}</li></td></tr>
    								<tr><td><li>{$game['player3']}</td><td>{$status[6]}</li></td></tr>
    								<tr><td><li>{$game['player4']}</td><td>{$status[7]}</li></td></tr></ul>
    								<tr><td>zak:</td><td>&pound;{$game['zak']}</td></tr>
    							</table>
    						</td></tr>
    					</table>";
    	}
    }
    
    
    function insertGame( $ante, $maxraise, $password ) {
    	global $game;
    	$deck = ToSqlDeck(compileDeck());
    	$login = $_SESSION['login'];
    	mysql_query("INSERT INTO `poker` (player1, zak1, deck, ante, pot, password, current, maxraise, status, created) VALUES('{$login}', {$ante}, '{$deck}', {$ante}, {$ante}, {$password}, '{$login}', {$maxraise}, '1:1:1:1:0:0:0:0',UNIX_TIMESTAMP())");
    	if (mysql_affected_rows() > 0) {
    		$id = mysql_insert_id();
    		mysql_query("UPDATE users SET zak=zak-{$ante}, poker={$id} WHERE login='{$login}'");
    		$game = getGame();
    	}
    	return 'Game successfully created';
    }
    
    
    function compileDeck() {
    	global $types;
    	$deck = array();
    
    
    	foreach ($types as $type) {
    		for ($i=2;$i<=14;$i++) {
    			$deck[$type][] = $i;
    		}
    	}
    
    
    	return $deck;
    }
    
    
    function ToSqlDeck($arr) {
    	$str = array();
    	foreach ($arr as $type => $cards) {
    		foreach ($cards as $card) {
    			$str[] = $type.'-'.$card;
    		}
    	}
    	return implode('/', $str);
    }
    
    
    function FromSqlDeck($str) {
    	$arr = array();
    	$str = explode('/', $str);
    
    
    	foreach ($str as $cards) {
    		$card = explode('-', $cards);
    		$arr[$card[0]][] = (int)$card[1];
    	}
    
    
    	return $arr;
    }
    
    
    function drawCard(&$deck) {
    	$types = array_keys($deck);
    	$type = $types[mt_rand(0, count($types)-1)];
    	$card = mt_rand(0, count($deck[$type])-1);
    	$rtrn = $deck[$type][$card];
    
    
    	unset($deck[$type][$card]);
    	$deck[$type] = array_values($deck[$type]);
    	if (!count($deck[$type])) {
    		unset($deck[$type]);
    	}
    
    
    	return ($type.'-'.$rtrn);
    }
    
    
    function initGame() {
    	global $game;
    	$deck = FromSqlDeck($game['deck']);
    
    
    	for ($i=0;$i<=4;$i++) {
    		$player[$i] = new hand();
    		$player[$i]->addcard(drawCard($deck));
    		$player[$i]->addcard(drawCard($deck));
    		$player[$i]->addcard(drawCard($deck));
    		$player[$i]->addcard(drawCard($deck));
    		$player[$i]->addcard(drawCard($deck));
    		$player[$i] = $player[$i]->ToSql();
    	}
    
    
    	$deck = ToSqlDeck($deck);
    
    
    	mysql_query("UPDATE poker SET allin=1, lastmove=UNIX_TIMESTAMP(), cards1='{$player[1]}', cards2='{$player[2]}', cards3='{$player[3]}', cards4='{$player[4]}', deck='{$deck}' WHERE id={$game['id']}");
    	$game = getGame();
    	return true;
    }
    
    
    function addPlayer($id, $password) {
    	$avab = 0;
    
    
    	$game = mysql_fetch_array(mysql_query("SELECT p.*, u.poker, u.zak FROM poker p left join users u on (u.login='{$_SESSION['login']}') WHERE p.id={$id}"));
    
    
    	if ((int)$game['id'] != $id) {
    		return 'Hack Attempt?!';
    	}
    
    
    	if ((int)$game['poker']) {
    		return 'You\'re already in a poker game';
    	}
    
    
    	if ((int)$game['zak'] < (int)$game['ante']) {
    		return 'You don\'t have enough zak to enter';
    	}
    
    
    	if ($game['password'] && $game['password'] != $password) {
    		return 'Incorrect password';
    	}
    
    
    	for ($i=1;$i<=4;$i++) {
    		if (!$game['player'.$i]) {
    			$avab = $i;
    			break;
    		}
    	}
    
    
    	if (!$avab) {
    		return 'The game is full';
    	}
    
    
    	mysql_query("UPDATE poker p inner join users u on (u.login='{$_SESSION['login']}') SET p.player{$avab}='{$_SESSION['login']}', p.zak{$avab}=ante, p.pot=p.pot+ante, u.zak=u.zak-p.ante, u.poker={$id} WHERE u.zak>=p.ante AND p.id={$id} AND p.player{$avab} IS NULL");
    
    
    	if (mysql_affected_rows() > 0) {
    		global $game;
    		$game = getGame();
    
    
    		if ($avab == 4) {
    			initGame();
    		}
    
    
    		return 'Successfully joined the game';
    	}
    	else {
    		return 'The game is full';
    	}
    }
    
    
    function removePlayer($login) {
    	$noplayers = true;
    	$remove = 0;
    	$success = false;
    	global $game;
    
    
    	if (!$game) {
    		return 'You\'re not in any games';
    	}
    	elseif((int)$game['allin']) {
    		return 'Hack Attempt?!';
    	}
    
    
    	for ($i=1;$i<=4;$i++) {
    		if ($game['player'.$i] == $login) {
    			$remove = $i;
    		}
    		elseif($game['player'.$i]) {
    			$noplayers = false;
    			$game['player'.$i] = "'".$game['player'.$i]."'";
    		}
    		elseif(!$game['player'.$i]) {
    			$game['player'.$i] = 'null';
    			$game['zak'.$i] = 'null';
    		}
    	}
    
    
    	if ($noplayers) {
    		mysql_query('DELETE FROM poker WHERE id='.$game['id']);
    		mysql_query("UPDATE users SET poker=null WHERE login='{$login}'");
    	}
    	elseif ($remove) {
    		while ($remove < 4) {
    			$game['player'.$remove] = $game['player'.($remove+1)];
    			$game['zak'.$remove] = $game['zak'.($remove+1)];
    			$remove++;
    		}
    
    
    		$game['player'.$i] = 'null';
    		$game['zak'.$i] = 'null';
    
    
    		mysql_query("UPDATE poker p left join users u on (u.login='{$login}') SET p.current={$game['player1']}, p.player1={$game['player1']}, p.player2={$game['player2']}, p.player3={$game['player3']}, p.player4={$game['player4']}, p.zak1={$game['zak1']}, p.zak2={$game['zak2']}, p.zak3={$game['zak3']}, p.zak4={$game['zak4']}, u.poker=NULL WHERE p.id=u.poker");
    	}
    
    
    	$game = getGame();
    	return 'Successfully left game';
    }
    
    
    function leaveGame() {
    	global $game;
    	$delete = true;
    
    
    	$number = getPlayerByValue($_SESSION['login']);
    
    
    	$status = explode(':', $game['status']);
    	$status[$number-1] = '3';
    
    
    	for ($i=0;$i<4;$i++) {
    		if ($status[$i] == '1') {
    			$delete = false;
    			break;
    		}
    	}
    
    
    	$status = implode(':', $status);
    
    
    	if ($delete) {
    		mysql_query("UPDATE users SET poker=NULL WHERE login='{$_SESSION['login']}'");
    		mysql_query("DELETE FROM poker WHERE id={$game['id']}");
    	}
    	else {
    		mysql_query("UPDATE poker p inner join users u on (u.login='{$_SESSION['login']}') SET p.status='{$status}', u.poker=NULL WHERE p.id=u.poker");
    	}
    
    
    	if (mysql_affected_rows() > 0) {
    		$game = getGame();
    		return 'Successfully left the game';
    	}
    	else {
    		return 'You\'re not in a poker game';
    	}
    }
    
    
    function raiseGame($amount) {
    	global $game, $maxmaxraise;
    	$amount = (int)$amount;
    	$current = getCurrent();
    	$callamount = ((int)$game['raiseamount']>((int)$game['zak'.$current]-(int)$game['ante'])?((int)$game['raiseamount']-((int)$game['zak'.$current]-(int)$game['ante'])+$amount):$amount);
    	$status = explode(':', $game['status']);
    
    
    	$next = $current;
    	do {
    		$next = getNext($next);
    	} while($next != false && $status[$next-1] == '2' && $next != $current);
    
    
    	if ($amount <= 0) {
    		return 'You have to raise at least &pound;1';
    	}
    	elseif ((int)$game['zak'] < $callamount) {
    		return 'You don\'t have enough zak';
    	}
    	elseif ((int)$game['maxraise'] && $amount > (int)$game['maxraise']) {
    		return 'Your raise exceedes max raise';
    	}
    	if ($maxmaxraise && $amount > $maxmaxraise) {
    		return 'You can only raise upto &pound;'.$maxmaxraise;
    	}
    	elseif (!$next || $next == $current) {
    		return checkForWin($game?false:$game['id']);
    	}
    
    
    	mysql_query("UPDATE poker p inner join users u on (u.login='{$game['player'.$current]}') SET p.zak{$current}=p.zak{$current}+{$callamount}, p.pot=p.pot+{$callamount}, p.raiseamount=p.raiseamount+{$amount}, u.zak=u.zak-{$callamount}, p.currentraise=p.currentraise+1, p.lastmove=UNIX_TIMESTAMP(), p.current=p.player{$next} WHERE p.id=u.poker AND u.zak>={$callamount}");
    
    
    	if (mysql_affected_rows() > 0) {
    		$game = getGame();
    		return 'You raised &pound;'.$amount;
    	}
    	else {
    		return 'You don\'t have enough zak';
    	}
    }
    
    
    function checkGame() {
    	global $game;
    	$current = getCurrent();
    	$status = explode(':', $game['status']);
    	if (((int)$game['swapstart'] && $current == (int)$game['swapstart']) || (!(int)$game['swapstart'] && $current == 4)) {
    		$game['stage'] = (int)$game['stage'] + 1;
    	}
    	
    	$next = $current;
    	do {
    		$next = getNextSwapStart($next);
    		if ($next && $status[$next-1] == '0' && (((int)$game['swapstart'] && $next == $game['swapstart']) || (!(int)$game['swapstart'] && $next == 4))) {
    			$game['stage'] = (int)$game['stage'] + 1;
    		}
    	} while($next != false && $next != $current && $status[$next-1] == '0');
    	
    	if (!$next || $next == $current) {
    		return checkForWin($game?false:$game['id']);
    	}
    	mysql_query("UPDATE poker p inner join users u on (u.login='{$_SESSION['login']}') SET p.stage={$game['stage']}, p.current=p.player{$next}, p.lastmove=UNIX_TIMESTAMP() WHERE p.id=u.poker");
    	
    	if (mysql_affected_rows() > 0) {
    		$game = getGame();
    		checkForWin($game?false:$game['id']);
    		return 'Successfully checked';
    	}
    	else {
    		return 'You\'re not in a poker game';
    	}
    }
    
    
    function swapCards($cards) {
    	global $game;
    	$deck = FromSqlDeck($game['deck']);
    	$current = getCurrent();
    	$swps = count($cards);
    	$status = explode(':', $game['status']);
    	$status[($current-1)+4] = $swps;
    
    
    	if (((int)$game['swapstart'] && $current == (int)$game['swapstart']) || (!(int)$game['swapstart'] && $current == 4)) {
    		$game['stage'] = (int)$game['stage'] + 1;
    	}
    	
    	$next = $current;
    	do {
    		$next = getNextSwapStart($next);
    		if ($next && $status[$next-1] == '0' && (((int)$game['swapstart'] && $next == (int)$game['swapstart']) || (!(int)$game['swapstart'] && $next == 4))) {
    			$game['stage'] = (int)$game['stage'] + 1;
    		}
    	} while($next != false && ((((int)$game['stage'] == 0 || (int)$game['stage'] == 2) && $status[$next-1] == '2') || $status[$next-1]=='0') && $next != $current);
    	
    	if (!$next || $next == $current) {
    		return checkForWin($game?false:$game['id']);
    	}
    
    
    	for ($i=0;$i<$swps;$i++) {
    		$draws[] = drawCard($deck);
    	}
    
    
    	$hand = new hand($game['cards'.$current]);
    	$hand->changecards($cards, $draws);
    	$hand = $hand->ToSql();
    	$deck = ToSqlDeck($deck);
    	$status = implode(':', $status);
    
    
    	mysql_query("UPDATE poker p inner join users u on (u.login='{$_SESSION['login']}') SET p.status='{$status}', p.cards{$current}='{$hand}', p.deck='{$deck}', p.stage={$game['stage']}, p.current=p.player{$next}, p.lastmove=UNIX_TIMESTAMP() WHERE p.id=u.poker");
    
    
    	if (mysql_affected_rows() > 0) {
    		$game = getGame();
    		return 'Successfully swapped cards';
    	}
    	else {
    		return 'You\'re not in a poker game';
    	}
    }
    
    
    function callGame() {
    	global $game;
    	$current = getCurrent();
    	$stage = (int)$game['stage'];
    	$swapstart = (int)$game['swapstart'];
    	$currentraise = (int)$game['currentraise'];
    	$callamount = (int)$game['raiseamount']-((int)$game['zak'.$current]-(int)$game['ante']);
    	$status = explode(':', $game['status']);
    
    
    	$next = $current;
    	do {
    		$next = getNext($next);
    	} while($next != false && $status[$next-1] == '2' && $next != $current);
    
    
    	if (!$next || $next == $current) {
    		return checkForWin($game?false:$game['id']);
    	}
    	elseif ((int)$game['raiseamount'] == ((int)$game['zak'.$next]-(int)$game['ante'])) {
    		$currentraise = 0;
    		$swapstart = ($next==1?4:$next-1);
    		$stage++;
    	}
    
    
    	$status[$current-1] = '2';
    	$status = implode(':', $status);
    	mysql_query("UPDATE poker p inner join users u on (u.login='{$_SESSION['login']}') SET p.swapstart={$swapstart}, u.zak=IF(u.zak<={$callamount},0,u.zak-{$callamount}), p.zak{$current}=IF(u.zak<={$callamount},p.zak{$current}+u.zak,p.zak{$current}+{$callamount}), p.status=IF(u.zak<={$callamount},'{$status}',p.status), p.pot=IF(u.zak<={$callamount},p.pot+u.zak,p.pot+{$callamount}), p.currentraise={$currentraise}, p.stage={$stage}, p.current=p.player{$next}, p.lastmove=UNIX_TIMESTAMP() WHERE p.id=u.poker");
    
    
    	if (mysql_affected_rows() > 0) {
    		$game = getGame();
    		$status = explode(':', $game['status']);
    		checkForWin($game?false:$game['id']);
    		return ($status[$current-1]=='2'?'You went all in!':'You called!');
    	}
    	else {
    		return 'You\'re not in a poker game';
    	}
    }
    
    
    function foldPlayer($who) {
    	global $game, $time;
    
    
    	$number = getPlayerByValue($who);
    
    
    	$status = explode(':', $game['status']);
    	$status[$number-1] = '0';
    	$status = implode(':', $status);
    	$stage = (int)$game['stage'];
    
    
    	if ($game['current'] == $who) {
    		$n = $number;
    		do {
    			$n = getNext($n);
    		} while($n != false && (($stage == 0 || $stage == 2) && $status[$n-1] == '2') && $n != $number);
    		
    		if (!$n || $n == $number) {
    			return checkForWin($game?false:$game['id']);
    		}
    		$next = $game['player'.$n];
    		$lastmove = $time;
    	}
    	else {
    		$next = $game['current'];
    		$lastmove = $game['lastmove'];
    	}
    
    
    	if ($stage == 2 && $next == $game['swapstart']) {
    		$stage++;
    	}
    
    
    	mysql_query("UPDATE poker p inner join users u on (u.login='{$who}') SET p.stage={$stage}, p.status='{$status}', u.poker=NULL, p.current='{$next}', p.lastmove={$lastmove} WHERE p.id=u.poker");
    	if (mysql_affected_rows() > 0) {
    		checkForWin($game['id']);
    
    
    		return 'Successfully folded';
    	}
    	else {
    		return 'You\'re not in a poker game';
    	}
    }
    
    
    function getCurrent() {
    	global $game;
    
    
    	for ($i=1;$i<=4;$i++){
    		if ($game['player'.$i] == $game['current']) {
    			return $i;
    		}
    	}
    
    
    	return false;
    }
    
    
    function getPlayerByValue($login) {
    	global $game;
    
    
    	for ($i=1;$i<=4;$i++){
    		if ($game['player'.$i] == $login) {
    			return $i;
    		}
    	}
    
    
    	return false;
    }
    
    
    function getNext($next) {
    	global $game;
    	$statuses = explode(':', $game['status']);
    	$i = 0;
    
    
    	if ($next > 4) {
    		return false;
    	}
    	
    	do {
    		$next = ($next==4?1:$next+1);
    		$i++;
    		if ($i >= 4) {
    			return false;
    		}
    	} while ((int)$statuses[$next-1] == 0);
    
    
    	return $next;
    }
    
    
    function getNextSwapStart($next) {
    	if ($next > 4) {
    		return false;
    	}
    
    
    	return ($next==4?1:$next+1);
    }
    
    
    class hand {
    	var $cards;
    	var $values;
    	var $types;
    
    
    	function hand($string = false) {
    		$cards = array();
    		if ($string) {
    			$this->FromSql($string);
    		}
    	}
    
    
    	function addcard($card) {
    		$this->cards[] = $card;
    		$card = explode('-', $card);
    		$this->values[] = (int)$card[1];
    		$this->types[] = $card[0];
    	}
    
    
    	function changecard($i, $card) {
    		$this->cards[$i] = $card;
    		$card = explode('-', $card);
    		$this->values[$i] = (int)$card[1];
    		$this->types[$i] = $card[0];
    	}
    
    
    	function changecards($cards, $draws) {
    		if (!$cards) {
    			return;
    		}
    		foreach ($cards as $card => $temp) {
    			if ($temp == '1') {
    				$this->changecard($card, current($draws));
    				next($draws);
    			}
    		}
    	}
    
    
    	function ToSql() {
    		return implode('/', $this->cards);
    	}
    
    
    	function FromSql($string) {
    		$this->cards = explode('/', $string);
    		foreach ($this->cards as $card) {
    			$card = explode('-', $card);
    			$this->values[] = (int)$card[1];
    			$this->types[] = $card[0];
    		}
    	}
    
    
    	function getValue() {
    		$tempcards = MySort($this->cards);
    		$total = count($tempcards);
    		/************************************************************************/
    		// IS Royal Flush //
    		$found = true;
    		if ($tempcards[0]['card'] == 10) {
    			for($i=1;$i<$total;$i++) {
    				if ($tempcards[$i]['card'] != $tempcards[$i-1]['card']+1 || $tempcards[$i]['type'] != $tempcards[$i-1]['type']) {
    					$found=false;
    					break;
    				}
    			}
    		}
    		else {
    			$found = false;
    		}
    		if ($found) {
    			return array('value' => 9, 'highcards' => array('h' => $tempcards[$i]['card'], 'l' => 0));
    		}
    		// IS Royal Flush //
    		/************************************************************************/
    		// IS Straight Flush //
    		$found = true;
    		for($i=1;$i<$total;$i++) {
    			if (($tempcards[$i]['card'] != $tempcards[$i-1]['card']+1 && !($i == ($total-1) && $tempcards[$i]['card'] != 14)) || $tempcards[$i]['type'] != $tempcards[$i-1]['type']) {
    				$found=false;
    				break;
    			}
    		}
    		if ($found) {
    			return array('value' => 8, 'highcards' => array('h' => $tempcards[$i]['card'], 'l' => 0));
    		}
    		//-IS Straight Flush-//
    /************************************************************************/
    		// IS Four of A Kind //
    		$count = 0;
    		$card = 0;
    		for($i=2;$i<$total;$i++) {
    			if ($tempcards[$i]['card'] == $tempcards[$i-1]['card'] && $tempcards[$i]['card'] == $tempcards[$i-2]['card']) {
    				$count++;
    				$card=$tempcards[$i]['card'];
    			}
    		}
    		if ($count == 2) {
    			return array('value' => 7, 'highcards' => array('h' => $card, 'l' => 0));
    		}
    		//-IS Four of A Kind-//
    /************************************************************************/
    		// IS Full House //
    		$count = 0;
    		$high = 0;
    		$low = 0;
    		for($i=1;$i<$total;$i++) {
    			if ($tempcards[$i]['card'] == $tempcards[$i-1]['card']) {
    				$count++;
    				if ($i > 1 && $tempcards[$i]['card'] == $tempcards[$i-2]['card'] ) {
    					$high = $tempcards[$i]['card'];
    				}
    				else {
    					$low = $tempcards[$i]['card'];
    				}
    			}
    		}
    		if ($count == 3) {
    			return array('value' => 6, 'highcards' => array('h' => $high, 'l' => $low));
    		}
    		//-IS Full House-//
    /************************************************************************/
    		// IS Flush //
    		$found = true;
    		for($i=1;$i<$total;$i++) {
    			if ($tempcards[$i]['type'] != $tempcards[$i-1]['type']) {
    				$found=false;
    				break;
    			}
    		}
    		if ($found) {
    			return array('value' => 5, 'highcards' => $tempcards);
    		}
    		//-IS Flush-//
    /************************************************************************/
    		// IS Straight //
    		$found = true;
    
    
    		for($i=1;$i<$total;$i++) {
    			if ($tempcards[$i]['card'] != $tempcards[$i-1]['card']+1 && !($i == ($total-1) && $tempcards[$i]['card'] == 14)) {
    				$found=false;
    				break;
    			}
    		}
    		if ($found) {
    			return array('value' => 4, 'highcards' => array('h' => $tempcards[$i]['card'], 'l' => 0));
    		}
    		//-IS Straight-//
    /************************************************************************/
    		// IS Three of a Kind //
    		$count = 0;
    		$card = 0;
    		for($i=2;$i<$total;$i++) {
    			if ($tempcards[$i]['card'] == $tempcards[$i-1]['card'] && $tempcards[$i]['card'] == $tempcards[$i-2]['card']) {
    				$count++;
    				$card=$tempcards[$i]['card'];
    			}
    		}
    		if ($count == 1) {
    			return array('value' => 3, 'highcards' => array('h' => $card, 'l' => 0));
    		}
    		//-IS Three of a Kind-//
    /************************************************************************/
    		// IS Two Pair //
    		$count = 0;
    		$card = array();
    		for($i=1;$i<$total;$i++) {
    			if ($tempcards[$i]['card'] == $tempcards[$i-1]['card']) {
    				$count++;
    				$card[] = $tempcards[$i]['card'];
    			}
    		}
    		if ($count == 2) {
    			return array('value' => 2, 'highcards' => array('h' => $card[1], 'l' => $card[0]));
    		}
    		//-IS Two Pair-//
    /************************************************************************/
    		// IS Pair //
    		$found = false;
    		$card = 0;
    		for($i=1;$i<$total;$i++) {
    			if ($tempcards[$i]['card'] == $tempcards[$i-1]['card']) {
    				$found = true;
    				$card = $tempcards[$i]['card'];
    				break;
    			}
    		}
    		if ($found) {
    			return array('value' => 1, 'highcards' => array('h' => $card, 'l' => 0));
    		}
    		//-IS Pair-//
    /************************************************************************/
    		// High Card //
    		return array('value' => 0, 'highcards' => $tempcards);
    		//-High Card-//
    /************************************************************************/
    	}
    }
    
    
    function isAllInSituation() {
    	global $game;
    	$status = explode(':', $status);
    	for ($i=0;$i<4;$i++) {
    		if ($status[$i] == '2') {
    			return true;
    		}
    	}
    	return false;
    }
    
    
    function amountOfNormalPlayers() {
    	global $game;
    	$status = explode(':', $game['status']);
    	$j = 0;
    	for ($i=0;$i<4;$i++) {
    		if ($status[$i] == '1') {
    			$j++;
    		}
    	}
    	return $j;
    }
    
    
    function isAllowedRaise() {
    	global $maxraisesperturn, $game;
    	if(isGameOn($game) && ((int)$game['stage']==0 || (int)$game['stage']==2) && isMyTurn($game) && (int)$game['currentraise'] < $maxraisesperturn && !isAllInSituation() && amountOfNormalPlayers() > 1) {
    		return true;
    	}
    	else {
    		return false;
    	}
    }
    
    
    function isAllowedCheck() {
    	global $game;
    	if (isGameOn($game) && !(int)$game['currentraise'] && ((int)$game['stage']==0 || (int)$game['stage']==2) && isMyTurn($game)) {
    		return true;
    	}
    	else {
    		return false;
    	}
    }
    
    
    function isAllowedCall() {
    	global $game;
    	if (isGameOn($game) && (int)$game['currentraise'] && ((int)$game['stage']==0 || (int)$game['stage']==2) && isMyTurn($game)) {
    		return true;
    	}
    	else {
    		return false;
    	}
    }
    
    
    function isAllowedSwap() {
    	global $game;
    	if (isGameOn($game) && (int)$game['stage']==1 && isMyTurn($game)) {
    		return true;
    	}
    	else {
    		return false;
    	}
    }
    
    
    function isAllowedFold() {
    	global $game;
    	if (isGameOn($game)) {
    		return true;
    	}
    	else {
    		return false;
    	}
    }
    
    
    
    
    function isGameOn($sgame = false) {
    	if (!$sgame) {
    		global $game;
    	}
    	else {
    		$game = $sgame;
    	}
    	
    	if ((int)$game['allin'] && !strlen($game['winners']) && (int)$game['stage'] < 3 && in_array($_SESSION['login'], array($game['player1'], $game['player2'], $game['player3'], $game['player4']))) {
    		return true;
    	}
    	else {
    		return false;
    	}
    }
    
    
    function isJoin($sgame) {
    	global $game;
    
    
    	if (!($game && (int)$game['poker']) && !(int)$sgame['allin'] && !strlen($sgame['winners']) && (int)$sgame['stage'] < 3 && !in_array($_SESSION['login'], array($sgame['player1'], $sgame['player2'], $sgame['player3'], $sgame['player4']))) {
    		return true;		
    	}
    	else {
    		return false;
    	}
    }
    
    
    function isMyTurn() {
    	global $game;
    	if ($game['current'] == $_SESSION['login']) {
    		return true;
    	}
    	else {
    		return false;
    	}
    }
    
    
    function getGame() {
    	return mysql_fetch_array(mysql_query("SELECT p.*, u.poker, u.zak FROM poker p left join users u on (u.login='{$_SESSION['login']}') WHERE p.id=u.poker"));
    }
    
    
    function getHandRank($value) {
    	switch ($value) {
    		case 9: return 'Royal Flush';
    		case 8: return 'Straight Flush';
    		case 7: return 'Four of a Kind';
    		case 6: return 'Full House';
    		case 5: return 'Flush';
    		case 4: return 'Straight';
    		case 3: return 'Three of a Kind';
    		case 2: return 'Two Pair';
    		case 1: return 'Pair';
    		case 0: return 'High Card';
    		default: return 'Not Shown';
    	}
    }
    
    
    function mySort($array) {
       $result=array();
       $t=array();
       $rtrn=array();
       foreach($array as $var => $v){
           $set = false;
           $t[$var] = explode('-', $v);
           $val = (int)$t[$var][1];
           foreach($result as $var2 => $val2){
               if($set==false){
                   if($val<$val2){
                       $temp=array();
                       foreach($result as $var3 => $val3){
                           if($var3==$var2) $set=true;
                           if($set){
                               $temp[$var3]=$val3;
                               unset($result[$var3]);
                           }
                       }
                       $result[$var]=$val;
                       foreach($temp as $var3 => $val3){
                           $result[$var3]=$val3;
                       }
                   }
               }
           }
           if(!$set){
               $result[$var]=$val;
           }
       }
       $i=0;
       foreach ($result as $var => $val) {
         $rtrn[$i] = array('type' => $t[$var][0], 'card' => (int)$t[$var][1]);
         $i++;
       }
       return $rtrn;
    }
    
    
    function getLowest() {
    	global $game;
    	$lowest = false;
    		
    	for ($i=1;$i<=4;$i++) {
    		$m = (int)$game['zak'.$i];
    		$lowest = $lowest!==false?($m<$lowest?$m:$lowest):$m;
    	}
    	
    	return $lowest;
    }
    
    
    function getTimeLeft() {
    	global $game, $timelimit, $time;
    	$seconds = (int)$game['lastmove']+$timelimit-$time;
    	$minutes = 0;
    
    
    	if ($seconds > 60) {
    		$minutes = floor($seconds/60);
    		$seconds = $seconds - ($minutes*60);
    	}
    
    
    	$minutes = '0'.$minutes;
    	$seconds = $seconds < 10?'0'.$seconds:$seconds;
    
    
    	return $minutes.':'.$seconds;
    }
    
    
    function checkForWin($id = false) {
    	global $game;
    
    
    	if ($id) {
    		$game = mysql_fetch_array(mysql_query("SELECT p.*, u.poker, u.zak FROM poker p left join users u on (u.login='{$_SESSION['login']}') WHERE p.id={$id}"));
    	}
    	
    	$status = explode(':', $game['status']);
    	$nxt = getPlayerByValue($game['current']);
    
    
    	do {
    		$nxt = getNext($nxt);
    	} while( $nxt != false && (($game['stage'] == '0' || $game['stage'] == '2') && $status[$nxt-1] == '2') && $nxt != $current );
    	
    	if ($nxt == false || $game['player'.$nxt] == $game['current']) {
    		return grantWinners(array($game['current'] => $game['pot']), array($game['current'] => -1));
    	}
    	elseif((int)$game['stage'] == 3 || ((int)$stage == 2 && isAllInSituation() && amountOfNormalPlayers() < 2)) {
    		$winners = calcWinners();
    		$winners2 = calcGrant($winners);
    		return grantWinners($winners2, $winners['hands']);
    	}
    
    
    	return false;
    }
    
    
    function grantWinners($winners, $hands) {
    	global $game;
    	$i = 0;
    	$tables = array();
    	$values = array();
    	$where = array();
    	$win = array();
    	foreach ($winners as $winner => $amount) {
    		$tables[] = " users users{$i}";
    		$values[] = " users{$i}.zak=users{$i}.zak+{$amount}";
    		$where[] = " users{$i}.login='{$winner}' ";
    		$win[] = "{$winner}:{$amount}:".getHandRank($hands[$winner]);
    		$i++;
    	}
    	$sql = "UPDATE ".implode(',', $tables)." left join poker p on (p.id=users0.poker) SET ".implode(',', $values).", p.winners='".implode('/', $win)."' WHERE ".implode('AND', $where);
    
    
    	mysql_query($sql);
    	if (mysql_affected_rows() > 0) {
    		$game = getGame();
    		return true;
    	}
    	else {
    		return false;
    	}
    }
    
    
    function calcWinners() {
    	// hand->getValue() => array: value => 0 to 8 (High card => Straight Flush), highcards => array: In Two Pair/Full House 2 cards, rest 1 card to compare when same rank.
    	// Note: When winner is "allin"-er then another winner is looked for. In cases of "normal" player winner or part winners, the normal winner/partwinner takes all/rest of the zak.
    	global $game;
    	$done = true;
    	$winners = false;
    	$status = explode(':', $game['status']);
    	$iterations = 0;
    	$cards = $game;
    	$totalhands = array();
    
    
    	for ($j=1;$j<=4;$j++) {
    		if ($status[$j-1] == '0') {
    			unset($cards['cards'.$j]);
    		}
    	}
    
    
    	do {
    		$hands = array();
    		$top = array('value' => 0, 'highcards' => array('h' => 0, 'l' => 0));
    		$potentialwinners = array();
    
    
    		for ($i=1;$i<=4;$i++) {
    			if (!$cards['cards'.$i]){
    				continue;
    			}
    			if ($iterations > 0 && $status[$i-1] == '2') {
    				unset($cards['cards'.$i]);
    				continue;
    			}
    			$hand = new hand($cards['cards'.$i]);
    			$hands[$i] = $hand->getValue();
    
    
    			$c = compareHands($hands[$i], $top);
    			if ($c > 0) {
    				$top = $hands[$i];
    				if ($c == 2) {
    					$potentialwinners[] = $i;
    					if ($status[$i-1] == '1') {
    						$done = true;
    					}
    				}
    				else {
    					$potentialwinners = array($i);
    					if ($status[$i-1] == '2') {
    						$done = false;
    					}
    					else {
    						$done = true;
    					}
    				}
    			}
    		}
    
    
    		foreach ($potentialwinners as $key => $wn) {
    			unset($cards['cards'.$wn]);
    			$winners[] = $game['player'.$wn];
    			$totalhands[$game['player'.$wn]] = $hands[$wn]['value'];
    		}
    
    
    		$iterations++;
    		//$winners = ($winners?array_merge($winners, $potentialwinners):$potentialwinners);
    
    
    		if ($iterations > 2 || count($cards) == 0) {
    			break;
    		}
    
    
    	} while (!$done);
    
    
    	return array('winners' => $winners, 'iterations' => $iterations, 'hands' => $totalhands);
    }
    
    
    function compareHands($hand1, $hand2) {
    	// 1 => 1st better, 0 => second better, 2 => both the same.
    	if ($hand1['value'] != $hand2['value']) {
    		return (int)($hand1['value']>$hand2['value']);
    	}
    
    
    	if ($hand1['value'] == 0 || $hand1['value'] == 5) {
    		// Flush || High Card //
    		for ($i=count($hand1['highcards'])-1;$i>=0;$i--) {
    			if ($hand1['highcards'][$i]['card'] != $hand2['highcards'][$i]['card']) {
    				return (int)($hand1['highcards'][$i]['card'] > $hand2['highcards'][$i]['card']);
    			}
    		}
    
    
    		return 2;
    	}
    
    
    	if ($hand1['highcards']['h'] != $hand2['highcards']['h']) {
    		return (int)($hand1['highcards']['h'] > $hand2['highcards']['h']);
    	}
    
    
    	if ($hand1['highcards']['l'] != $hand2['highcards']['l']) {
    		return (int)($hand1['highcards']['l'] > $hand2['highcards']['l']);
    	}
    
    
    	return 2;
    }
    
    
    function calcGrant($winners) {
    	global $game;
    	$status = explode(':', $game['status']);
    	$players = $winners['winners'];
    	$iterations = $winners['iterations'];
    	$normal = array();
    	$alliners = array();
    	$rtrn = array();
    	
    	$lowest = getLowest();
    	
    	$mainpot = $lowest*4;
    	$sidepot = array();
    	$totalsidepot = (int)$game['pot'] - $mainpot;
    	$winnerssidepot = 0;
    	$cp = count($players);
    
    
    	foreach ($players as $player) {
    		$n = getPlayerByValue($player);
    		$sidepot[$player] = ((int)$game['zak'.$n]-$lowest);
    		$winnerssidepot += $sidepot[$player];
    		if ($status[$n-1] == '2') {
    			$alliners[] = $player;
    		}
    		else {
    			$normal[] = $player;
    		}
    	}
    
    
    	$cn = count($normal);
    	$ca = count($alliners);
    
    
    	if ($iterations == 1) {
    		foreach ($players as $player) {
    			$rtrn[$player] = (int)floor($mainpot/$cp) + (int)floor(($sidepot[$player]/$winnerssidepot)*$totalsidepot);
    		}
    		return  $rtrn;
    	}
    	else {
    		foreach($alliners as $alliner) {
    			$rtrn[$alliner] = (int)floor($mainpot/$ca) + (int)floor(($sidepot[$alliner]/$winnerssidepot)*$totalsidepot);
    		}
    		
    		foreach ($normal as $snormal) {
    			$rtrn[$snormal] = (int)floor(($sidepot[$snormal]/$winnerssidepot)*$totalsidepot);
    		}
    		return  $rtrn;
    	}
    
    
    	return false;
    }
    
    
    //update poker p, users u set p.player4=null, u.poker=null, p.allin=0 where login='pokerAdict' and p.id=u.poker
    	//update users u left join poker p on (p.id=u.poker) set u.poker=null, p.player4=null, p.cards1=null, p.cards2=null, p.cards3=null, p.cards4=null, p.allin=0 where u.login='pokerAdict'
    	//update users u left join poker p on (p.id=u.poker) set u.poker=null, p.player4=null, p.cards1=null, p.cards2=null, p.cards3=null, p.cards4=null, p.allin=0 where u.login='pokerAdict'
    	/*delete from poker;
    	update users set poker=null where login in ('Owner', 'mupparion',  'pokerAdict');*/
    
    
    	/*
    	all "2" => share between them
    "2" and 1 normal => "2" gets first pot, normal gets sidepot || "2" and normal shares first pot, normal gets sidepot
    normal and "2" => share first pot, normal share sidepot
    "2" and >1 normal => "2" gets first pot, normal gets sidepot || "2" and normal shares first pot, normal gets sidepot
    all normal => share between them*/
    ?>
    Toon Meer
  • sjoepie
    Beginner
    Berichten
    3
    • 12 oktober 2010 om 18:38
    • #2

    ik bedoel als je een spel wilt opstarten doet die niks hij zegt spel is goed maar hij zet niks in de data base

  • Superior
    Master
    Berichten
    1.947
    • 12 oktober 2010 om 18:41
    • #3

    Lijn: 082
    Lijn: 104
    Lijn: 471
    Lijn: 563
    Lijn: 613
    Lijn: 696


    Dat zijn sowieso al fouten die je zou moeten zien met de juiste editor :)

Participate now!

Heb je nog geen account? Registreer je nu en word deel van onze community!

Maak een account aan Login

ICT Nieuws

  • Samsung zal miljoenen verdienen aan Apple iPhone Fold dankzij zijn 12GB RAM

    ICTscripters 11 maart 2026 om 22:42
  • Apple heeft zojuist iOS 26.4 Beta 4 vrijgegeven: hier is de verwachte lanceerdatum.

    ICTscripters 11 maart 2026 om 12:01
  • Kritieke kwetsbaarheid in Nginx UI bedreigt gevoelige data

    ICTscripters 10 maart 2026 om 18:29

Blogs

  • Functioneel ontwerp

    Dees 28 december 2014 om 12:38
  • Access Control List implementatie in PHP/MySQL - deel 1/2

    FangorN 28 december 2018 om 12:35
  • Access Control List implementatie in PHP/MySQL - deel 2/2

    FangorN 29 december 2018 om 12:37
  1. Marktplaats
  2. Design
  3. Voorwaarden
  4. Ons team
  5. Leden
  6. Geschiedenis
  7. Regels
  8. Links
  9. Privacy Policy
ICTscripters ©2005 - 2026 , goedkope hosting door DiMoWeb.com, BE0558.915.582
Sponsors: Beste kattenhotel provincie Antwerpen | Beste Zetes eid kaartlezer webshop
Style: Nexus by cls-design
Stylename
Nexus
Manufacturer
cls-design
Licence
Commercial styles
Help
Supportforum
Visit cls-design