foo
This commit is contained in:
699
code-snippets/twitch_extension/api.php
Normal file
699
code-snippets/twitch_extension/api.php
Normal file
@@ -0,0 +1,699 @@
|
||||
<?php
|
||||
|
||||
//require('/home/zino/projects/pkrstarsbot/var_www/pkrstarsbot/extension/src/vendor/autoload.php');
|
||||
require_once('/home/zino/projects/pkrstarsbot/libs/lcobucci/vendor/autoload.php');
|
||||
use Lcobucci\JWT\Parser;
|
||||
use Lcobucci\JWT\Builder;
|
||||
use Lcobucci\JWT\Signer\Key;
|
||||
use Lcobucci\JWT\Signer\Hmac\Sha256;
|
||||
|
||||
$regex = array(
|
||||
"3bet" => '(BET|RAISE),(?:(?!RAISE,|BET,)\w+,)*RAISE,(?:(?!RAISE,|BET,)\w+,)*raise',
|
||||
"3bet_possibility" => '(BET|RAISE),(?:(?!RAISE,|BET,)\w+,)*RAISE,(?:(?!RAISE,|BET,)\w+,)*(?!raise,)[a-z]+,',
|
||||
);
|
||||
|
||||
// $GLOBALS['secret'] = 'aaGvh1AhYa8+S1xv6kfKfon87nfqvFAEjT5CjwxmW4dBg='; // offline
|
||||
$GLOBALS['secret'] = 'Gvh1AhYa8+S1xv6kfKfon87nfqvFAEjT5CjwxmW4dBg='; // offline
|
||||
// $GLOBALS['secret'] = 'yilWKdOs5dAERDjBzH8MGriwNXY1cgQ3LVx16gxP36Q='; // online
|
||||
|
||||
add_action( 'rest_api_init', 'register_api_extension' );
|
||||
function register_api_extension() {
|
||||
|
||||
register_rest_route('extension/v1', 'foobar', [
|
||||
'methods' => 'POST',
|
||||
'callback' => 'foobar',
|
||||
'args' => array(
|
||||
'token' => array(
|
||||
'required' => true,
|
||||
),
|
||||
'channelID' => array(
|
||||
'required' => true,
|
||||
'validate_callback' => 'validate_channelID',
|
||||
),
|
||||
'userID' => array(
|
||||
'required' => false,
|
||||
'validate_callback' => 'validate_userID',
|
||||
),
|
||||
'betrounds' => array(
|
||||
'required' => true,
|
||||
'validate_callback' => 'validate_betrounds',
|
||||
),
|
||||
),
|
||||
'permission_callback' => 'validate_token',
|
||||
] );
|
||||
|
||||
register_rest_route('extension/v1', 'af', [
|
||||
'methods' => 'POST',
|
||||
'callback' => 'af',
|
||||
'args' => array(
|
||||
'token' => array(
|
||||
'required' => true,
|
||||
),
|
||||
'channelID' => array(
|
||||
'required' => true,
|
||||
'validate_callback' => 'validate_channelID',
|
||||
),
|
||||
'userID' => array(
|
||||
'required' => false,
|
||||
'validate_callback' => 'validate_userID',
|
||||
),
|
||||
'betrounds' => array(
|
||||
'required' => true,
|
||||
'validate_callback' => 'validate_betrounds',
|
||||
),
|
||||
'streamdelay' => array(
|
||||
'required' => false,
|
||||
'validate_callback' => 'validate_numeric',
|
||||
),
|
||||
),
|
||||
'permission_callback' => 'validate_token',
|
||||
] );
|
||||
|
||||
register_rest_route('extension/v1', '3bet', [
|
||||
'methods' => 'POST',
|
||||
'callback' => 'threebet',
|
||||
'args' => array(
|
||||
'token' => array(
|
||||
'required' => true,
|
||||
),
|
||||
'channelID' => array(
|
||||
'required' => true,
|
||||
'validate_callback' => 'validate_channelID',
|
||||
),
|
||||
'userID' => array(
|
||||
'required' => false,
|
||||
'validate_callback' => 'validate_userID',
|
||||
),
|
||||
'betrounds' => array(
|
||||
'required' => true,
|
||||
'validate_callback' => 'validate_betrounds',
|
||||
),
|
||||
'streamdelay' => array(
|
||||
'required' => false,
|
||||
'validate_callback' => 'validate_numeric',
|
||||
),
|
||||
),
|
||||
'permission_callback' => 'validate_token',
|
||||
] );
|
||||
|
||||
register_rest_route('extension/v1', 'blinds', [
|
||||
'methods' => 'POST',
|
||||
'callback' => 'blinds',
|
||||
'args' => array(
|
||||
'token' => array(
|
||||
'required' => true,
|
||||
),
|
||||
'channelID' => array(
|
||||
'required' => true,
|
||||
'validate_callback' => 'validate_channelID',
|
||||
),
|
||||
'userID' => array(
|
||||
'required' => false,
|
||||
'validate_callback' => 'validate_userID',
|
||||
),
|
||||
'streamdelay' => array(
|
||||
'required' => false,
|
||||
'validate_callback' => 'validate_numeric',
|
||||
),
|
||||
),
|
||||
'permission_callback' => 'validate_token',
|
||||
] );
|
||||
|
||||
register_rest_route('extension/v1', 'tournamentwinnings', [
|
||||
'methods' => 'POST',
|
||||
'callback' => 'tournamentwinnings',
|
||||
'args' => array(
|
||||
'token' => array(
|
||||
'required' => true,
|
||||
),
|
||||
'channelID' => array(
|
||||
'required' => true,
|
||||
'validate_callback' => 'validate_channelID',
|
||||
),
|
||||
'userID' => array(
|
||||
'required' => false,
|
||||
'validate_callback' => 'validate_userID',
|
||||
),
|
||||
'streamdelay' => array(
|
||||
'required' => false,
|
||||
'validate_callback' => 'validate_numeric',
|
||||
),
|
||||
),
|
||||
'permission_callback' => 'validate_token',
|
||||
] );
|
||||
|
||||
register_rest_route('extension/v1', 'bountywinnings', [
|
||||
'methods' => 'POST',
|
||||
'callback' => 'bountywinnings',
|
||||
'args' => array(
|
||||
'token' => array(
|
||||
'required' => true,
|
||||
),
|
||||
'channelID' => array(
|
||||
'required' => true,
|
||||
'validate_callback' => 'validate_channelID',
|
||||
),
|
||||
'userID' => array(
|
||||
'required' => false,
|
||||
'validate_callback' => 'validate_userID',
|
||||
),
|
||||
'streamdelay' => array(
|
||||
'required' => false,
|
||||
'validate_callback' => 'validate_numeric',
|
||||
),
|
||||
),
|
||||
'permission_callback' => 'validate_token',
|
||||
] );
|
||||
|
||||
// register_rest_route('extension/v1', 'streamdelay', [
|
||||
// 'methods' => 'POST',
|
||||
// 'callback' => 'streamdelay',
|
||||
// 'args' => array(
|
||||
// 'delay' => array(
|
||||
// 'validate_callback' => 'validate_numeric',
|
||||
// ),
|
||||
// 'dbuserid' => array(
|
||||
// 'validate_callback' => 'validate_numeric',
|
||||
// ),
|
||||
// ),
|
||||
// 'permission_callback' => function() {
|
||||
// return is_user_logged_in();
|
||||
// },
|
||||
// ] );
|
||||
|
||||
// register_rest_route('client/v1', 'dbuserid', [
|
||||
// 'methods' => 'POST',
|
||||
// 'callback' => 'dbuserid',
|
||||
// 'args' => array(
|
||||
// 'email' => array(
|
||||
// 'validate_callback' => 'validate_emailaddress',
|
||||
// ),
|
||||
// ),
|
||||
// 'permission_callback' => function() {
|
||||
// return is_user_logged_in();
|
||||
// },
|
||||
// ] );
|
||||
|
||||
|
||||
// register_rest_route('client/v1', 'logoutuser', [
|
||||
// 'methods' => 'POST',
|
||||
// 'callback' => 'logoutuser',
|
||||
// 'permission_callback' => function() {
|
||||
// return is_user_logged_in();
|
||||
// },
|
||||
// ] );
|
||||
}
|
||||
|
||||
function bountywinnings($request) {
|
||||
$token = $request["token"];
|
||||
$channelID = $request["channelID"];
|
||||
$userID = $request["userID"];
|
||||
$streamdelay = $request["streamdelay"];
|
||||
|
||||
if (!$userID)
|
||||
$userID = getUserIDbyChannelID($channelID);
|
||||
|
||||
if (!$streamdelay)
|
||||
$streamdelay = get_streamdelay($userID);
|
||||
|
||||
$wpdb = connect_to_server('zinomedia');
|
||||
|
||||
// Play money
|
||||
$query = "SELECT SUM(pkrstarsbot.showdown.AMOUNT) AS SUM_BOUNTY_WINNINGS FROM pkrstarsbot.hands INNER JOIN pkrstarsbot.showdown ON pkrstarsbot.hands.HandID = pkrstarsbot.showdown.HandID INNER JOIN pkrstarsbot.tournaments ON pkrstarsbot.hands.TournamentID = pkrstarsbot.tournaments.TournamentID WHERE (showdown.`ACTION` = 19 OR showdown.`ACTION` = 31) AND tournaments.CURRENCY IS NULL AND showdown.UserID = $userID";
|
||||
$rows = $wpdb->get_results($query);
|
||||
$winnings_playmoney = $rows[0]->SUM_BOUNTY_WINNINGS;
|
||||
|
||||
if (!$winnings_playmoney)
|
||||
$winnings_playmoney = 0;
|
||||
|
||||
// Real money blinds
|
||||
$query = "SELECT SUM(pkrstarsbot.showdown.AMOUNT) AS SUM_BOUNTY_WINNINGS FROM pkrstarsbot.hands INNER JOIN pkrstarsbot.showdown ON pkrstarsbot.hands.HandID = pkrstarsbot.showdown.HandID INNER JOIN pkrstarsbot.tournaments ON pkrstarsbot.hands.TournamentID = pkrstarsbot.tournaments.TournamentID WHERE (showdown.`ACTION` = 19 OR showdown.`ACTION` = 31) AND tournaments.CURRENCY IS NOT NULL AND showdown.UserID = $userID";
|
||||
$rows = $wpdb->get_results($query);
|
||||
$winnings_realmoney = $rows[0]->SUM_BOUNTY_WINNINGS;
|
||||
|
||||
if (!$winnings_realmoney)
|
||||
$winnings_realmoney = 0;
|
||||
|
||||
// Response
|
||||
$responseData = array("winnings_realmoney" => $winnings_realmoney, "winnings_playmoney" => $winnings_playmoney);
|
||||
$response = new WP_REST_Response($responseData);
|
||||
$response->set_status(200);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
function tournamentwinnings($request) {
|
||||
$token = $request["token"];
|
||||
$channelID = $request["channelID"];
|
||||
$userID = $request["userID"];
|
||||
$streamdelay = $request["streamdelay"];
|
||||
|
||||
if (!$userID)
|
||||
$userID = getUserIDbyChannelID($channelID);
|
||||
|
||||
if (!$streamdelay)
|
||||
$streamdelay = get_streamdelay($userID);
|
||||
|
||||
$wpdb = connect_to_server('zinomedia');
|
||||
|
||||
// Play money
|
||||
$query = "SELECT SUM(pkrstarsbot.showdown.AMOUNT_RECEIVED) AS SUM_AMOUNT_RECEIVED FROM pkrstarsbot.hands INNER JOIN pkrstarsbot.showdown ON pkrstarsbot.hands.HandID = pkrstarsbot.showdown.HandID INNER JOIN pkrstarsbot.tournaments ON pkrstarsbot.hands.TournamentID = pkrstarsbot.tournaments.TournamentID WHERE showdown.`ACTION` = 30 AND tournaments.CURRENCY IS NULL AND showdown.UserID = $userID";
|
||||
$rows = $wpdb->get_results($query);
|
||||
$winnings_playmoney = $rows[0]->SUM_AMOUNT_RECEIVED;
|
||||
|
||||
if (!$winnings_playmoney)
|
||||
$winnings_playmoney = 0;
|
||||
|
||||
// Real money blinds
|
||||
$query = "SELECT SUM(pkrstarsbot.showdown.AMOUNT_RECEIVED) AS SUM_AMOUNT_RECEIVED FROM pkrstarsbot.hands INNER JOIN pkrstarsbot.showdown ON pkrstarsbot.hands.HandID = pkrstarsbot.showdown.HandID INNER JOIN pkrstarsbot.tournaments ON pkrstarsbot.hands.TournamentID = pkrstarsbot.tournaments.TournamentID WHERE showdown.`ACTION` = 30 AND tournaments.CURRENCY IS NOT NULL AND showdown.UserID = $userID";
|
||||
$rows = $wpdb->get_results($query);
|
||||
$winnings_realmoney = $rows[0]->SUM_AMOUNT_RECEIVED;
|
||||
|
||||
if (!$winnings_realmoney)
|
||||
$winnings_realmoney = 0;
|
||||
|
||||
// Response
|
||||
$responseData = array("winnings_realmoney" => $winnings_realmoney, "winnings_playmoney" => $winnings_playmoney);
|
||||
$response = new WP_REST_Response($responseData);
|
||||
$response->set_status(200);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
function blinds($request) {
|
||||
$token = $request["token"];
|
||||
$channelID = $request["channelID"];
|
||||
$userID = $request["userID"];
|
||||
$streamdelay = $request["streamdelay"];
|
||||
|
||||
if (!$userID)
|
||||
$userID = getUserIDbyChannelID($channelID);
|
||||
|
||||
if (!$streamdelay)
|
||||
$streamdelay = get_streamdelay($userID);
|
||||
|
||||
$wpdb = connect_to_server('zinomedia');
|
||||
|
||||
// Play money blinds
|
||||
$query = "SELECT SUM(pkrstarsbot.hands.SMALL_BLIND) AS SMALL_BLIND, SUM(pkrstarsbot.hands.BIG_BLIND) AS BIG_BLIND FROM pkrstarsbot.hands INNER JOIN pkrstarsbot.tournaments ON pkrstarsbot.hands.TournamentID = pkrstarsbot.tournaments.TournamentID WHERE hands.UserID = $userID AND tournaments.TournamentID = hands.TournamentID AND tournaments.CURRENCY IS NULL";
|
||||
$rows = $wpdb->get_results($query);
|
||||
$big_blind_play = $rows[0]->BIG_BLIND;
|
||||
$small_blind_play = $rows[0]->SMALL_BLIND;
|
||||
if ($small_blind_play && $big_blind_play) {
|
||||
$total_play = $big_blind_play + $small_blind_play;
|
||||
}
|
||||
else {
|
||||
$small_blind_real = 0;
|
||||
$big_blind_real = 0;
|
||||
$total_real = 0;
|
||||
}
|
||||
|
||||
// Real money blinds
|
||||
$query = "SELECT SUM(pkrstarsbot.hands.SMALL_BLIND) AS SMALL_BLIND, SUM(pkrstarsbot.hands.BIG_BLIND) AS BIG_BLIND FROM pkrstarsbot.hands INNER JOIN pkrstarsbot.tournaments ON pkrstarsbot.hands.TournamentID = pkrstarsbot.tournaments.TournamentID WHERE hands.UserID = $userID AND tournaments.TournamentID = hands.TournamentID AND tournaments.CURRENCY IS NOT NULL";
|
||||
$rows = $wpdb->get_results($query);
|
||||
$big_blind_real = $rows[0]->BIG_BLIND;
|
||||
$small_blind_real = $rows[0]->SMALL_BLIND;
|
||||
if ($small_blind_real && $big_blind_real) {
|
||||
$total_real = $big_blind_real + $small_blind_real;
|
||||
}
|
||||
else {
|
||||
$small_blind_real = 0;
|
||||
$big_blind_real = 0;
|
||||
$total_real = 0;
|
||||
}
|
||||
|
||||
|
||||
// Response
|
||||
$responseData = array("small_blind_play" => $small_blind_play, "big_blind_play" => $big_blind_play, "total_play" => $total_play, "small_blind_real" => $small_blind_real, "big_blind_real" => $big_blind_real, "total_real" => $total_real);
|
||||
$response = new WP_REST_Response($responseData);
|
||||
$response->set_status(200);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
function build_action_strings($rows, $ownplayerID, &$action_strings) {
|
||||
$handID = 0;
|
||||
$action_string;
|
||||
// $action_strings = array();
|
||||
foreach($rows as $row) {
|
||||
if ($handID != $row->HandID) {
|
||||
if ($action_string)
|
||||
array_push($action_strings, $action_string);
|
||||
|
||||
$action_string = '';
|
||||
$handID = $row->HandID;
|
||||
$unique_handIDs++;
|
||||
}
|
||||
$action = $row->ACTION_TYPE;
|
||||
|
||||
if ($row->NAME == $ownplayerID)
|
||||
$action = strtolower($action);
|
||||
|
||||
$action .= ",";
|
||||
$action_string .= $action;
|
||||
}
|
||||
|
||||
return $action_strings;
|
||||
}
|
||||
|
||||
function threebet($request) {
|
||||
$token = $request["token"];
|
||||
$channelID = $request["channelID"];
|
||||
$userID = $request["userID"];
|
||||
$betrounds = $request["betrounds"];
|
||||
$streamdelay = $request["streamdelay"];
|
||||
|
||||
if (!$userID)
|
||||
$userID = getUserIDbyChannelID($channelID);
|
||||
|
||||
if (!$streamdelay)
|
||||
$streamdelay = get_streamdelay($userID);
|
||||
|
||||
$ownplayerID = get_ownplayerID($userID);
|
||||
|
||||
$wpdb = connect_to_server('zinomedia');
|
||||
|
||||
|
||||
$action_strings = array();
|
||||
$query;
|
||||
$unique_handIDs = 0;
|
||||
foreach ($betrounds as $betround) {
|
||||
$query = "SELECT at.ACTION_TYPE, f.ActionNr, f.HandID, f.`ACTION`, f.NAME FROM pkrstarsbot.$betround f INNER JOIN pkrstarsbot.action_type at ON at.ID = f.`ACTION` WHERE f.UserID = $userID AND (at.ACTION_TYPE = 'RAISE' OR at.ACTION_TYPE = 'CALL' OR at.ACTION_TYPE = 'BET' OR at.ACTION_TYPE = 'FOLD') GROUP BY at.ACTION_TYPE, f.ActionNr, f.HandID, f.`ACTION`, f.NAME ORDER BY f.HandID, f.ActionNr";
|
||||
$rows = $wpdb->get_results($query);
|
||||
build_action_strings($rows, $ownplayerID, $action_strings);
|
||||
}
|
||||
|
||||
$threebet_count = 0;
|
||||
$threebet_possibility_count = 0;
|
||||
foreach ($action_strings as $action_string) {
|
||||
if (preg_match($regex["3bet"], $action_string))
|
||||
$thereebet_count++;
|
||||
|
||||
if (preg_match($regex["3bet_overall"], $action_string))
|
||||
$thereebet_possibility_count++;
|
||||
}
|
||||
|
||||
// 3bet
|
||||
$threebet = 0;
|
||||
if ($threebet_possibility_count != 0)
|
||||
$threebet = round((( $threebet_count / $threebet_possibility_count ) * 100), 1);
|
||||
|
||||
// Response
|
||||
$responseData = array("unique_handids" => $unique_handIDs, "query" => $query, "action_strings" => $action_strings, "3bet_count" => $threebet_count, "3bet_possibility" => $threebet_possibility_count, "threebet" => $threebet);
|
||||
$response = new WP_REST_Response($responseData);
|
||||
$response->set_status(200);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
// function threebet($request) {
|
||||
// $token = $request["token"];
|
||||
// $channelID = $request["channelID"];
|
||||
// $userID = $request["userID"];
|
||||
// $betrounds = $request["betrounds"];
|
||||
// $streamdelay = $request["streamdelay"];
|
||||
|
||||
// if (!$userID)
|
||||
// $userID = getUserIDbyChannelID($channelID);
|
||||
|
||||
// if (!$streamdelay)
|
||||
// $streamdelay = get_streamdelay($userID);
|
||||
|
||||
// $ownplayerID = get_ownplayerID($userID);
|
||||
|
||||
// $wpdb = connect_to_server('zinomedia');
|
||||
|
||||
|
||||
|
||||
// $ownplayer3bet = 0;
|
||||
// $ownplayer3betPossibility = 0;
|
||||
// $unqique_handIDs = 0;
|
||||
// $skip = array();
|
||||
// $query; // delete
|
||||
// $handIDs = array(); // delete
|
||||
// foreach ($betrounds as $betround) { // holecards, flop, turn or river
|
||||
// // $query = "SELECT action_type.ACTION_TYPE, $betround.ActionNr, $betround.HandID, hands.OWN_PLAYER, player.Name FROM hands INNER JOIN $betround ON $betround.HandID = hands.HandID AND hands.UserID = $betround.UserID INNER JOIN action_type ON $betround.ACTION = action_type.ID INNER JOIN player ON hands.OWN_PLAYER = player.ID WHERE hands.UserID = $userID AND (action_type.ACTION_TYPE = 'CALL' OR action_type.ACTION_TYPE = 'RAISE' OR action_type.ACTION_TYPE = 'BET') AND hands.SYNCED = 1 AND hands.TimeStamp <= Now() - INTERVAL 0 Second GROUP BY hands.TableNameID, hands.TournamentID, hands.SYNCED, action_type.ACTION_TYPE, $betround.ActionNr, $betround.HandID, hands.OWN_PLAYER, player.Name ORDER BY $betround.HandID, $betround.ActionNr;";
|
||||
// $query = "SELECT at.ACTION_TYPE, f.ActionNr, f.HandID, f.`ACTION`, f.NAME FROM pkrstarsbot.$betround f INNER JOIN pkrstarsbot.action_type at ON at.ID = f.`ACTION` WHERE f.UserID = 38 AND (at.ACTION_TYPE = 'RAISE' OR at.ACTION_TYPE = 'CALL' OR at.ACTION_TYPE = 'BET' OR at.ACTION_TYPE = 'FOLD') GROUP BY at.ACTION_TYPE, f.ActionNr, f.HandID, f.`ACTION`, f.NAME ORDER BY f.HandID, f.ActionNr";
|
||||
// $rows = $wpdb->get_results($query);
|
||||
|
||||
// $handIDs = array_merge(array_column($rows, 'HandID'), $handIDs); // delete
|
||||
|
||||
// $handID = 0;
|
||||
// foreach($rows as $row) {
|
||||
|
||||
// if ($skip[$row->HandID]) {
|
||||
// continue;
|
||||
// }
|
||||
|
||||
// if ($handID != $row->HandID) { // new hand
|
||||
// $handID = $row->HandID;
|
||||
// $raise = 0;
|
||||
// $bet = 0;
|
||||
// $unique_handIDs++;
|
||||
// }
|
||||
|
||||
// // own player folds before bet or raise of someone else = skip hands with same ID
|
||||
// if (!$bet || !$raise) {
|
||||
// if ($row->ACTION_TYPE == 'FOLD' && $row->NAME == $ownplayerID) {
|
||||
// $skip[$row->HandID] = 1;
|
||||
// continue;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // Flag if someone else bets or raises
|
||||
// if ($row->ACTION_TYPE == 'BET' && $row->NAME != $ownplayerID) // flop, turn, river | note: betting does not exist in holecards
|
||||
// $bet++;
|
||||
|
||||
// if ($row->ACTION_TYPE == 'RAISE' && $row->NAME != $ownplayerID) // holecards, flop, turn, river
|
||||
// $raise++;
|
||||
|
||||
// // 3bet holecards only
|
||||
// if ( $bet == 0 || $raise == 2 ) {
|
||||
// $ownplayer3betPossibility++;
|
||||
// if ( $row->NAME == $ownplayerID && $row->ACTION_TYPE == 'RAISE' ) {
|
||||
// $ownplayer3bet++;
|
||||
// }
|
||||
// }
|
||||
|
||||
// // 3bet flop, turn & river
|
||||
// if ( $bet == 1 || $raise == 1 ) {
|
||||
// $ownplayer3betPossibility++;
|
||||
// if ( $row->NAME == $ownplayerID && $row->ACTION_TYPE == 'RAISE' ) {
|
||||
// $ownplayer3bet++;
|
||||
// }
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
// $unique_handIDscheck = count(array_unique($handIDs)); // delete
|
||||
|
||||
// // Response
|
||||
// $responseData = array("ownplayer3bet" => $ownplayer3bet, "ownplayer3betpossibility" => $ownplayer3betPossibility, "unique_handids" => $unique_handIDs, "query" => $query, "unique_handids_check" => $unique_handIDscheck);
|
||||
// $response = new WP_REST_Response($responseData);
|
||||
// $response->set_status(200);
|
||||
|
||||
// return $response;
|
||||
// }
|
||||
|
||||
function validate_numeric($param, $request, $key) {
|
||||
return is_numeric($param);
|
||||
}
|
||||
|
||||
function validate_betrounds($param, $request, $key) {
|
||||
if (validate_array($param) && !array_diff($param, array("holecards", "flop", "turn", "river")))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
function validate_array($array) {
|
||||
if (is_array($array) && !empty($array))
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
function af($request) {
|
||||
$token = $request["token"];
|
||||
$channelID = $request["channelID"];
|
||||
$userID = $request["userID"];
|
||||
$betrounds = $request["betrounds"];
|
||||
$streamdelay = $request["streamdelay"];
|
||||
|
||||
if (!$userID)
|
||||
$userID = getUserIDbyChannelID($channelID);
|
||||
|
||||
if (!$streamdelay)
|
||||
$streamdelay = get_streamdelay($userID);
|
||||
|
||||
$wpdb = connect_to_server('zinomedia');
|
||||
// $betround = "flop";
|
||||
// $query = "SELECT action_type.ACTION_TYPE, flop.ActionNr, flop.HandID, hands.OWN_PLAYER, player.Name FROM hands INNER JOIN flop ON flop.HandID = hands.HandID AND hands.UserID = flop.UserID INNER JOIN action_type ON flop.ACTION = action_type.ID INNER JOIN player ON hands.OWN_PLAYER = player.ID WHERE hands.UserID = 38 AND (action_type.ACTION_TYPE = 'CALL' OR action_type.ACTION_TYPE = 'RAISE' OR action_type.ACTION_TYPE = 'BET') AND hands.SYNCED = 1 AND hands.TimeStamp <= Now() - INTERVAL 0 Second GROUP BY hands.TableNameID, hands.TournamentID, hands.SYNCED, action_type.ACTION_TYPE, flop.ActionNr, flop.HandID, hands.OWN_PLAYER, player.Name ORDER BY flop.HandID, flop.ActionNr;";
|
||||
|
||||
// $betrounds = array('flop', 'turn', 'river');
|
||||
$needed = array( "CALL", "RAISE", "BET" );
|
||||
|
||||
$handIDs = array();
|
||||
foreach ($betrounds as $betround) {
|
||||
// $query = "SELECT action_type.ACTION_TYPE, $betround.ActionNr, $betround.HandID, hands.OWN_PLAYER, player.Name FROM hands INNER JOIN $betround ON $betround.HandID = hands.HandID AND hands.UserID = $betround.UserID INNER JOIN action_type ON $betround.ACTION = action_type.ID INNER JOIN player ON hands.OWN_PLAYER = player.ID WHERE hands.UserID = $userID AND (action_type.ACTION_TYPE = 'CALL' OR action_type.ACTION_TYPE = 'RAISE' OR action_type.ACTION_TYPE = 'BET') AND hands.SYNCED = 1 AND hands.TimeStamp <= Now() - INTERVAL 0 Second GROUP BY hands.TableNameID, hands.TournamentID, hands.SYNCED, action_type.ACTION_TYPE, $betround.ActionNr, $betround.HandID, hands.OWN_PLAYER, player.Name ORDER BY $betround.HandID, $betround.ActionNr;";
|
||||
$query = "SELECT action_type.ACTION_TYPE, $betround.HandID FROM hands INNER JOIN $betround ON $betround.HandID = hands.HandID AND hands.UserID = $betround.UserID INNER JOIN action_type ON $betround.ACTION = action_type.ID INNER JOIN player ON hands.OWN_PLAYER = player.ID WHERE hands.UserID = $userID AND (action_type.ACTION_TYPE = 'CALL' OR action_type.ACTION_TYPE = 'RAISE' OR action_type.ACTION_TYPE = 'BET') AND hands.SYNCED = 1 AND hands.TimeStamp <= Now() - INTERVAL $streamdelay Second GROUP BY hands.TableNameID, hands.TournamentID, hands.SYNCED, action_type.ACTION_TYPE, $betround.ActionNr, $betround.HandID, hands.OWN_PLAYER, player.Name ORDER BY $betround.HandID, $betround.ActionNr;";
|
||||
|
||||
$rows = $wpdb->get_results($query);
|
||||
$count[$betround] = count_associative_array($rows, $needed);
|
||||
$handIDs = array_merge(array_column($rows, 'HandID'), $handIDs);
|
||||
}
|
||||
|
||||
// Uniqie handIDs
|
||||
$unique_handIDs = count(array_unique($handIDs));
|
||||
|
||||
// Count together
|
||||
foreach($betrounds as $betround) {
|
||||
foreach($count[$betround] as $action => $value) {
|
||||
$count["overall_calculated"][$action] += $value;
|
||||
}
|
||||
}
|
||||
|
||||
// ( Total Times Bet + Total Times Raised ) / (Total Times Called )
|
||||
$af = round( ( $count["overall_calculated"]["BET"] + $count["overall_calculated"]["RAISE"] ) / $count["overall_calculated"]["CALL"], 1);
|
||||
|
||||
// Response
|
||||
// $responseData = array("AF" => $af, "UNIQUE_HANDIDS" => $unique_handIDs, "OVERALL_CALCULATED" => $count["overall_calculated"]);
|
||||
$responseData = array("af" => $af, "unique_handids" => $unique_handIDs);
|
||||
$response = new WP_REST_Response($responseData);
|
||||
$response->set_status(200);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
function count_associative_array($rows, $needed) {
|
||||
$count = array();
|
||||
foreach ($rows as $row) {
|
||||
if (in_array($row->ACTION_TYPE, $needed)) {
|
||||
$count[$row->ACTION_TYPE]++;
|
||||
}
|
||||
}
|
||||
|
||||
return $count;
|
||||
}
|
||||
|
||||
function validate_userID($param, $request, $key) {
|
||||
if (!is_numeric($param))
|
||||
return false;
|
||||
|
||||
$wpdb = connect_to_server('zinomedia');
|
||||
|
||||
if ( $wpdb->get_var( $wpdb->prepare( "SELECT 1 FROM `reg_users` WHERE `userID` = %d", $param )) )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
function getUserIDbyChannelID($channelID) {
|
||||
$wpdb = connect_to_server('zinomedia');
|
||||
|
||||
return $wpdb->get_var( $wpdb->prepare( "SELECT `ID` FROM `reg_users` WHERE `channelID` = %d", $channelID ));
|
||||
}
|
||||
|
||||
function get_ownplayerID($userID) {
|
||||
$wpdb = connect_to_server('zinomedia');
|
||||
|
||||
return $wpdb->get_var( $wpdb->prepare( "SELECT hands.OWN_PLAYER FROM hands WHERE hands.UserID = %d LIMIT 1;", $userID ));
|
||||
}
|
||||
|
||||
|
||||
function get_streamdelay($userID) {
|
||||
$wpdb = connect_to_server('zinomedia');
|
||||
|
||||
return $wpdb->get_var( $wpdb->prepare( "SELECT Value FROM pkrstarsbot.config_user WHERE UserID = %d AND `Key` = 'DelaySeconds';", $userID ));
|
||||
}
|
||||
|
||||
function validate_channelID($param, $request, $key) {
|
||||
if (!is_numeric($param))
|
||||
return false;
|
||||
|
||||
$wpdb = connect_to_server('zinomedia');
|
||||
|
||||
if ( $wpdb->get_var( $wpdb->prepare( "SELECT 1 FROM `reg_users` WHERE `channelID` = %d", $param )) )
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
function validate_token($request) {
|
||||
// return true;
|
||||
|
||||
$token = $request["token"];
|
||||
|
||||
try {
|
||||
$token = (new Parser())->parse((string) $token);
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// $token = (new Parser())->parse((string) $token);
|
||||
$signer = new Sha256();
|
||||
|
||||
$result = (bool) $token->verify($signer, base64_decode($GLOBALS['secret']));
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
function foobar($request) {
|
||||
$value = $request["betrounds"];
|
||||
$response = new WP_REST_Response($value);
|
||||
$response->set_status(200);
|
||||
return $response;
|
||||
}
|
||||
|
||||
// function validate_emailaddress($param, $request, $key) {
|
||||
// return filter_var($param, FILTER_VALIDATE_EMAIL) !== false;
|
||||
// // return true;
|
||||
// }
|
||||
|
||||
// function validate_numeric($param, $request, $key) {
|
||||
// return is_numeric($param);
|
||||
// // return true;
|
||||
// }
|
||||
|
||||
// function logoutuser() {
|
||||
// wp_logout();
|
||||
// $response = new WP_REST_Response("foobar");
|
||||
// $response->set_status(200);
|
||||
// return $response;
|
||||
// }
|
||||
|
||||
// function dbuserid($request) {
|
||||
// $email = $request->get_param('email');
|
||||
|
||||
// $wpdb = connect_to_server('zinomedia');
|
||||
// $db_user_id = $wpdb->get_var( $wpdb->prepare( "SELECT ID from reg_users where EMail = %s", $email ) );
|
||||
|
||||
// $response = new WP_REST_Response($db_user_id);
|
||||
// $response->set_status(200);
|
||||
// return $response;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
// function streamdelay($request) {
|
||||
// $parameter = $request->get_params();
|
||||
// $delay = $request->get_param('delay');
|
||||
// $db_user_id = $request->get_param('db_user_id');
|
||||
|
||||
// $wpdb = connect_to_server('zinomedia');
|
||||
// $wpdb->update('config_user',
|
||||
// array(
|
||||
// 'Value' => $delay,
|
||||
// ),
|
||||
// array(
|
||||
// "UserID" => $db_user_id,
|
||||
// )
|
||||
// );
|
||||
|
||||
// $response = new WP_REST_Response($parameter);
|
||||
// $response->set_status(200);
|
||||
// return $response;
|
||||
// }
|
||||
Reference in New Issue
Block a user