public function log() { $log = KLogger::instance(KLOGGER_PATH . "processors/", KLogger::DEBUG); $log->logInfo("userxplog > log > start userId : " . $this->userId . " xp : " . $this->xp . " type : " . $this->type . " time : " . $this->time . " gameId : " . $this->gameId . " result : " . $this->result . " opponentId : " . $this->opponentId); if (!empty($this->userId)) { $userXPLog = new GameUserXpLog(); $userXPLog->setUserId($this->userId); $userXPLog->setXp($this->xp); $userXPLog->setTime($this->time); $userXPLog->setType($this->type); $userXPLog->setGameId($this->gameId); $userXPLog->setResult($this->result); $userXPLog->setOpponentId($this->opponentId); try { $user = GameUsers::getGameUserById($this->userId); if (!empty($user)) { $userXPLog->setUserLevel($user->userLevelNumber); $userXPLog->setUserCoin($user->coins); //$userCoinLog->setUserSpentCoin($user->opponentId); } } catch (Exception $exc) { $log->logError("userxplog > log > User Error : " . $exc->getTraceAsString()); } try { $userXPLog->insertIntoDatabase(DBUtils::getConnection()); $log->logInfo("userxplog > log > Success"); } catch (Exception $exc) { $log->logError("userxplog > log > Error : " . $exc->getTraceAsString()); } } else { $log->logError("userxplog > log > user Id is empty "); } }
public static function autoLogin($rememberme = true) { if (isset($_SESSION["userId"])) { $userId = $_SESSION["userId"]; $user = GameUsers::getGameUserById($userId); if (!empty($user)) { UtilFunctions::storeSessionUser($user, $rememberme); return $user; } } if (isset($_COOKIE["auth"]) && false) { $cookie = $_COOKIE["auth"]; $arr = explode('&', $cookie); $userName = substr($arr[0], 4); $hash = substr($arr[1], 5); $user = GameUsers::getGameUserByUserName($userName); if (!empty($user)) { if ($hash == md5($user->getPassword())) { $user->setLastLoginDate(time()); $user->setLoginCount($user->getLoginCount() + 1); $user->updateToDatabase(DBUtils::getConnection()); Queue::checkUserFriends($user->userId); UtilFunctions::storeSessionUser($user, $rememberme); return $user; } else { UtilFunctions::forgetMe(); } } } return false; }
public static function setConstant($key, $value = null) { if (!empty($key)) { GameConstantUtil::setCacheConstant($key, $value); $setting = GameConstants::findByExample(DBUtils::getConnection(), GameConstants::create()->setKey_($key)); if (!empty($setting)) { if (sizeof($setting) > 0) { $setting = $setting[0]; $k = $setting->getKey_(); if (empty($k)) { $setting = null; } } else { $setting = null; } } if (!empty($setting)) { $setting->setValue_($value); } else { $setting = GameConstants::create(); $setting->setKey_($key); $setting->setValue_($value); } $setting->updateInsertToDatabase(DBUtils::getConnection()); } return false; }
public static function gameResult(GameUsers $user, GameUsers $opponent, $roomGroupId, $action, $gameId = null, $double = 0, $normal = true, $type = null, $time = null) { $result = new FunctionResult(); $result->success = false; if (!empty($user) && !empty($action)) { if (empty($action) || !empty($action) && $action != GameUtils::$GAME_RESULT_ACTION_WIN && $action != GameUtils::$GAME_RESULT_ACTION_LOST) { $result->result = "Unknown Action"; return $result; } GameUtils::updateXP($user, $opponent, $roomGroupId, $action, $gameId, $double, $normal, $type, $time); GameUtils::updateCoin($user, $opponent, $roomGroupId, $action, $gameId, $double, $normal, $type, $time); GameUtils::updateCounts($user, $opponent, $roomGroupId, $action, $gameId, $double, $normal, $type, $time); if ($action == GameUtils::$GAME_RESULT_ACTION_WIN && ($type == GameUtils::$GAME_RESULT_ACTION_TYPE_LEFT || $type == GameUtils::$GAME_RESULT_ACTION_TYPE_TIMESUP) && !empty($opponent)) { if (empty($time)) { $time = time(); } Queue::userLostConnLost($opponent->userId, $user->userId, $roomGroupId, GameUtils::$GAME_RESULT_ACTION_LOST, $gameId, $double, $normal, $type, $time); } try { $user->updateToDatabase(DBUtils::getConnection()); $result->success = true; $result->result = new stdClass(); $result->result->user = $user; } catch (Exception $exc) { $result->success = true; $result->result = $exc->getTraceAsString(); } return $result; } else { $result->result = "User not found"; return $result; } }
public function checkFriends() { $log = KLogger::instance(KLOGGER_PATH . "processors/", KLogger::DEBUG); $log->logInfo("user > checkFriends > start userId : " . $this->userId); $user = GameUsers::getGameUserById($this->userId); if (!empty($user)) { $userId = $user->userId; if (!empty($userId)) { $fbFriends = FriendUtils::getUserFacebookFriends($user); if (!empty($fbFriends) && sizeof($fbFriends) > 0) { $fbFriendIds = null; foreach ($fbFriends as $fbFriend) { if (!empty($fbFriend) && isset($fbFriend["id"])) { if (empty($fbFriendIds)) { $fbFriendIds = $fbFriend["id"]; } else { $fbFriendIds = $fbFriendIds . "," . $fbFriend["id"]; } } } $fbFriendUserIds = FriendUtils::getUserIdsFromFacebookIds($fbFriendIds); if (!empty($fbFriendUserIds)) { $friendIds = FriendUtils::getUserFriendIds($userId); foreach ($fbFriendUserIds as $fbFriendId) { if (!empty($fbFriendId)) { $add = false; if (!empty($friendIds) && sizeof($friendIds) > 0) { if (!in_array($fbFriendId, $friendIds)) { $add = true; } } else { $add = true; } if ($add) { $friend = new GameUserFriends(); $friend->setUserId($this->userId); $friend->setType("facebook"); $friend->setFriendId($fbFriendId); try { $friend->insertIntoDatabase(DBUtils::getConnection()); } catch (Exception $exc) { error_log("userclass>checkFriends userId : " . $this->userId . " friend Id : " . $fbFriendId . " Error : " . $exc->getMessage() . " Trace :" . $exc->getTraceAsString()); } } } } } } } } $log->logInfo("user > checkFriends > end userId : " . $this->userId); }
public static function updateUserImage($userId) { $result = new FunctionResult(); $result->success = false; if (!empty($userId)) { $user = GameUsers::getGameUserById($userId); if (!empty($user)) { $tmpImgPath = UserProfileImageUtils::downloadFBProfileImage($user->facebookId); $profileImageUrl = null; if (!empty($tmpImgPath)) { try { $s3 = new S3(AWS_API_KEY, AWS_SECRET_KEY); $s3->setEndpoint(AWS_S3_ENDPOINT); $imageName = "pi_" . $userId . ".png"; $s3Name = "profile.images/" . $userId . "/" . $imageName; $res = $s3->putObjectFile($tmpImgPath, AWS_S3_BUCKET, $s3Name, S3::ACL_PUBLIC_READ); if ($res) { $profileImageUrl = 'http://' . AWS_S3_BUCKET . '.s3.amazonaws.com/' . $s3Name; try { unlink($tmpImgPath); } catch (Exception $exc) { error_log($exc->getTraceAsString()); } } else { $result->result = json_encode($res); } } catch (Exception $exc) { $result->result = $exc->getTraceAsString(); } } else { $profileImageUrl = USER_DEFAULT_IMAGE_URL; } if (!empty($profileImageUrl)) { $user->setProfilePicture($profileImageUrl); try { $user->updateToDatabase(DBUtils::getConnection()); $result->success = true; $result->result = null; } catch (Exception $exc) { $result->result = $exc->getTraceAsString(); } } } else { $result->result = "user not found"; } } else { $result->result = "user id empty"; } return $result; }
public static function useRequest($id, $used = 1) { if (!empty($id)) { try { $req = GameFbRequest::findById(DBUtils::getConnection(), $id); if (!empty($req)) { $req->setUsed($used); $req->setUsedTime(time()); $req->updateToDatabase(DBUtils::getConnection()); } } catch (Exception $exc) { error_log($exc->getTraceAsString()); } } }
public static function getRoomGroupById($id) { if (!empty($id)) { $roomGroups = GameRoomGroups::findById(DBUtils::getConnection(), $id); if (count($roomGroups) > 0) { $roomGroup = $roomGroups[0]; unset($roomGroups); if (!empty($roomGroup)) { $roomGroupId = $roomGroup->roomGroupId; if (!empty($roomGroupId)) { return $roomGroup; } } } } return null; }
public static function getRecordByUserId($userId) { if (!empty($userId)) { $records = GameLeaderboardDaily::findByExample(DBUtils::getConnection(), GameLeaderboardDaily::create()->setUserId($userId)); if (count($records) > 0) { $record = $records[0]; unset($records); if (!empty($record)) { $recId = $record->getId(); if (!empty($recId)) { return $record; } } } } return null; }
public static function getUserLevelByName($levelName) { if (!empty($levelName)) { $userLevels = GameUserLevel::findByExample(DBUtils::getConnection(), GameUserLevel::create()->setLevelName($levelName)); if (count($userLevels) > 0) { $userLevel = $userLevels[0]; unset($userLevels); if (!empty($userLevel)) { $userLevelId = $userLevel->levelId; if (!empty($userLevelId)) { return $userLevel; } } } } return null; }
public static function insertLog($userId) { if (!empty($userId)) { $log = GameUserLoginLog::create(); $log->setUserId($userId); if (isset($_SERVER['HTTP_USER_AGENT'])) { $log->setBrowser($_SERVER['HTTP_USER_AGENT']); } $log->setTime(time()); $log->setDate(date("Ymd")); if (isset($_SERVER['REMOTE_ADDR'])) { $log->setIp($_SERVER['REMOTE_ADDR']); } try { $log->insertIntoDatabase(DBUtils::getConnection()); } catch (Exception $exc) { error_log($exc->getTraceAsString()); } } }
public static function getGameItemByCode($itemCode) { if (!empty($itemCode)) { $gameItems = GameItems::findByExample(DBUtils::getConnection(), GameItems::create()->setActive(1)->setItemCode($itemCode)); if (count($gameItems) > 0) { $gameItem = $gameItems[0]; unset($gameItems); if (!empty($gameItem)) { $itemId = $gameItem->getId(); if (!empty($itemId)) { return $gameItem; } } } } return null; }
if (empty($user->userFirstname)) { $errorHTML .= "<p/>Enter User First Name"; } if (empty($user->userLastname)) { $errorHTML .= "<p/>Enter User Last Name"; } if (empty($user->password)) { $user->setPassword(DBUtils::get_uuid()); } if (empty($errorHTML)) { if (empty($user->registerDate)) { $user->setRegisterDate(time()); } $user->updateInsertToDatabase(DBUtils::getConnection()); $bot->setUserId($user->userId); $bot->updateInsertToDatabase(DBUtils::getConnection()); try { $const = "v1.3_" . date("Ymd"); GameConstantUtil::setConstant("constant.bot.version", $const); } catch (Exception $exc) { error_log($exc->getMessage()); error_log($exc->getTraceAsString()); } header("Location: " . HOSTNAME . "admin/bots.php"); exit(1); } } $page_var = "bots"; include_once __ROOT__ . 'admin/admin_header_layout.php'; ?>
public static function getDailyBonusConstants() { try { $SQL = "SELECT * FROM " . TBL_GAME_CONSTANTS . " WHERE key_='" . BonusUtils::$CONSTANT_DAILYBONUS . "1' OR key_='" . BonusUtils::$CONSTANT_DAILYBONUS . "2' OR" . " key_='" . BonusUtils::$CONSTANT_DAILYBONUS . "3' OR key_='" . BonusUtils::$CONSTANT_DAILYBONUS . "4' OR key_='" . BonusUtils::$CONSTANT_DAILYBONUS . "5' OR" . " key_='" . BonusUtils::$CONSTANT_DAILYBONUS . "6' OR key_='" . BonusUtils::$CONSTANT_DAILYBONUS . "7' ORDER BY key_ ASC"; $dailyBonuses = GameConstants::findBySql(DBUtils::getConnection(), $SQL); $result = array(); for ($i = 1; $i < 8; $i++) { $dailybonus = new stdClass(); $dailybonus->order = $i; if (!empty($dailyBonuses) && sizeof($dailyBonuses) >= $i) { $tmp = $dailyBonuses[$i - 1]; if ($tmp != null) { $dailybonus->coin = $tmp->getValue_(); } } if (empty($dailybonus->coin)) { $dailybonus->coin = $i * 100; } array_push($result, $dailybonus); } return $result; } catch (Exception $exc) { var_dump($exc); error_log($exc->getTraceAsString()); } $result = array(); for ($i = 1; $i < 8; $i++) { $dailybonus = new stdClass(); $dailybonus->order = $i; $dailybonus->coin = $i * 100; array_push($result, $dailybonus); } return $result; }
} if (strtoupper($orderBy) == "ASC") { $orderBy = "ASC"; } else { $orderBy = "DESC"; } $sortBy = "time"; if (isset($_GET["sortBy"])) { $sortBy = $_GET["sortBy"]; } else { if (isset($_POST["sortBy"])) { $sortBy = $_POST["sortBy"]; } } $SQL = "SELECT * FROM " . TBL_GAME_USER_FEEDBACK . " ORDER BY " . $sortBy . " " . $orderBy . " LIMIT " . ($page - 1) * $pageCount . "," . $pageCount; $feedBackList = GameUserFeeedback::findBySql(DBUtils::getConnection(), $SQL); $total_feedback = GameUserFeeedback::getTotalCount(); $max_page = intval($total_feedback / $pageCount); if ($total_feedback % $pageCount > 0) { $max_page++; } $queryString = ""; if (isset($_GET) && sizeof($_GET) > 0) { foreach ($_GET as $key => $value) { if ($key != "page") { $queryString = $queryString . "&" . $key . "=" . $value; } } } if (strtoupper($orderBy) == "ASC") { $orderBy = "DESC";
<?php define("__ROOT__", __DIR__ . "/../"); require_once __ROOT__ . 'config/constants.php'; require_once __ROOT__ . 'utils/Functions.php'; require_once __ROOT__ . 'vendors/KLogger.php'; include_once __ROOT__ . "models/GameBots.class.php"; $result = new FunctionResult(); $result->success = false; if (isset($_GET["sessionId"]) && !empty($_GET["sessionId"])) { session_id($_GET["sessionId"]); } session_start(); session_write_close(); $gameBots = GameBots::findByExample(DBUtils::getConnection(), GameBots::create()->setActive(1)); if (empty($gameBots)) { $gameBots = array(); } $result->success = true; $result->result = new stdClass(); $result->result->bots = $gameBots; echo json_encode($result); exit(1);
public function index() { if (defined("SERVER_PROD")) { if (!SERVER_PROD) { $this->user = GameUsers::getGameUserById(2); LanguageUtils::setLocale($this->user->language); if (!empty($this->user) && $this->user->active == 0) { $this->redirect("banned"); exit(1); } return; } } $facebook = new Facebook(array('appId' => FB_APP_ID, 'secret' => FB_APP_SECRET, 'cookie' => true)); $login_req = true; $this->user = UtilFunctions::autoLogin(); if (!empty($this->user)) { $facebook->setAccessToken($this->user->getOauthToken()); try { $fbUser = $facebook->api("/me"); if (!empty($fbUser) && !empty($fbUser['id'])) { $login_req = false; } } catch (Exception $exc) { $this->log->logError($exc->getTraceAsString()); } } else { $login_req = true; if (isset($_GET['error']) || isset($_GET['error_reason']) || isset($_GET['error_description'])) { if ($_GET['error_description']) { $this->addError($_GET['error_description']); } if (isset($_GET['error_reason'])) { $this->addError(isset($_GET['error_reason'])); } echo "<p> Error : " . $_GET['error_reason'] . "</p>"; echo "<p> Please Refresh Page ! </p>"; exit(1); } else { $facebook = new Facebook(array('appId' => FB_APP_ID, 'secret' => FB_APP_SECRET, 'cookie' => true)); try { $fbUser = $facebook->api("/me"); } catch (Exception $exc) { $this->log->logError($exc->getTraceAsString()); } if (!empty($fbUser) && !empty($fbUser['id'])) { $this->user = GameUsers::getGameUserByFBId($fbUser['id']); if (!empty($this->user)) { $this->user->setOauthToken($facebook->getAccessToken()); $this->user->setLastLoginDate(time()); $this->user->setLoginCount($this->user->getLoginCount() + 1); $this->user->updateToDatabase(DBUtils::getConnection()); Queue::checkUserFriends($this->user->userId); UtilFunctions::storeSessionUser($this->user); $login_req = false; } else { $result = GameUsers::createGameUser($fbUser, $facebook->getAccessToken()); if ($result->success) { $this->user = $result->result; if (!empty($result)) { $userId = $this->user->getUserId(); if (!empty($userId)) { Queue::checkUserFriends($this->user->userId); UtilFunctions::storeSessionUser($this->user); $login_req = false; $this->newUser = "******"; } } else { $this->addError(LANG_FACEBOOK_USER_CREATE_ERROR_UNKNOWN_ERROR); } } else { if (!empty($result->result)) { foreach ($result->result as $value) { $this->addError($value); } } else { $this->addError(LANG_FACEBOOK_USER_CREATE_ERROR_UNKNOWN_ERROR); } } unset($result); } } if (!$login_req && !empty($this->user)) { GameUserLoginLog::insertLog($this->user->userId); } } } if (!$login_req) { if (!empty($this->user) && $this->user->active == 0) { $this->redirect("banned"); exit(1); } } if ($login_req) { UtilFunctions::forgetMe(); $params = array('scope' => FB_SCOPE, 'redirect_uri' => FB_CALLBACK_URL); $login_url = $facebook->getLoginUrl($params); if (isset($_SERVER['QUERY_STRING'])) { if (strpos($login_url, "?")) { $login_url . "&" . $_SERVER['QUERY_STRING']; } else { $login_url . "?" . $_SERVER['QUERY_STRING']; } } ?> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head></head> <body><script>top.location.href='<?php echo $login_url; ?> ';</script></body> </html> <?php exit(1); } else { $this->dailyBonus = BonusUtils::getDailyBonusPrice($this->user); if (isset($_GET['request_ids']) && !empty($_GET['request_ids'])) { $this->fbRequests = FacebookRequestUtils::getFacebookGiftRequest($this->user, $_GET['request_ids']); } LanguageUtils::setLocale($this->user->language); } }
public function add() { $log = KLogger::instance(KLOGGER_PATH . "processors/", KLogger::DEBUG); $log->logInfo("leaderboard > add > start userId : " . $this->userId . " diff Coin : " . $this->difCoin . " time : " . $this->time); if (!empty($this->userId)) { $user = GameUsers::getGameUserById($this->userId); if (!empty($user)) { $userId = $user->getUserId(); if (!empty($userId)) { $daily = GameLeaderboardDaily::getRecordByUserId($userId); if (empty($daily)) { $daily = new GameLeaderboardDaily(); $daily->setId(-1); $daily->setUserId($userId); $daily->setCoins(0); } $daily->setLastPlayed($this->time); $weekly = GameLeaderboardWeekly::getRecordByUserId($userId); if (empty($weekly)) { $weekly = new GameLeaderboardWeekly(); $weekly->setId(-1); $weekly->setUserId($userId); $weekly->setCoins(0); } $weekly->setLastPlayed($this->time); $dCoins = $daily->getCoins() + (int) $this->difCoin; if ($dCoins < 0) { $dCoins = 0; } $daily->setCoins($dCoins); try { $daily->updateInsertToDatabase(DBUtils::getConnection()); $log->logInfo("leaderboard > add > daily success "); } catch (Exception $exc) { $log->logError("leaderboard > add > error daily : " . $exc->getMessage() . " detail : " . $exc->getTraceAsString()); } $wCoins = $weekly->getCoins() + (int) $this->difCoin; if ($wCoins < 0) { $wCoins = 0; } $weekly->setCoins($wCoins); try { $weekly->updateInsertToDatabase(DBUtils::getConnection()); $log->logInfo("leaderboard > add > weekly success "); } catch (Exception $exc) { $log->logError("leaderboard > add > error weekly : " . $exc->getMessage() . " detail : " . $exc->getTraceAsString()); } $log->logInfo("leaderboard > add > finished "); unset($dCoins); unset($wCoins); unset($user); unset($userId); unset($weekly); unset($daily); } else { $log->logError("leaderboard > add > user found Id is empty"); } } else { $log->logError("leaderboard > add > user Id not found"); } } else { $log->logError("leaderboard > add > user Id is empty "); } }
public static function createGameUser($fbUser, $accessToken) { $result = new FunctionResult(); $errors = array(); if (empty($fbUser) || empty($fbUser['id'])) { array_push($errors, LanguageUtils::getText("LANG_FACEBOOK_USER_CREATE_ERROR_USER_EMPTY")); $result->success = false; $result->result = $errors; unset($errors); return $result; } if (empty($accessToken)) { array_push($errors, LanguageUtils::getText("LANG_FACEBOOK_USER_CREATE_ERROR_TOKEN_EMPTY")); $result->success = false; $result->result = $errors; unset($errors); return $result; } $user = GameUsers::create(); $user->setActive(1); $user->setFacebookId($fbUser['id']); $user->setOauthToken($accessToken); $user->setCoins(GameConstantUtil::getConstant(GameUsers::$CONSTANT_USER_FIRST_COIN)); if (isset($fbUser['username'])) { $user->setUserName($fbUser['username']); } else { $user->setUserName($fbUser['id']); } if (isset($fbUser['first_name'])) { $user->setUserFirstname($fbUser['first_name']); } if (isset($fbUser['last_name'])) { $user->setUserLastname($fbUser['last_name']); } if (isset($fbUser['email'])) { $user->setUserMail($fbUser['email']); } $time = time(); $user->setRegisterDate($time); $user->setLastLoginDate($time); $user->setLoginCount(1); if (isset($fbUser['gender'])) { if ($fbUser['gender'] == "male") { $user->setGender(1); } else { if ($fbUser['gender'] == "female") { $user->setGender(0); } } } if (isset($fbUser['birthday'])) { $user->setBirtday($fbUser['birthday']); $user->setBirthdayDate(DBUtils::facebookBirthDayConverter($fbUser['birthday'])); } $user->setPassword(DBUtils::get_uuid()); $user->setUserXP(0); $level = GameUserLevel::getUserLevel(0); if (!empty($level)) { $user->setUserLevelNumber($level->levelNumber); } $user->setWinGameCount(0); $user->setLostGameCount(0); $user->setWinCountQuitGame(0); $user->setWinCountConnectionLostGame(0); $user->setWinCountDoubleGame(0); $user->setLostCountQuitGame(0); $user->setLostCountConnectionLostGame(0); $user->setLostCountDoubleGame(0); $user->insertIntoDatabase(DBUtils::getConnection()); $result->success = true; $result->result = $user; Queue::updateUserImage($user->userId); unset($user); return $result; }
} if (strtoupper($orderBy) == "ASC") { $orderBy = "ASC"; } else { $orderBy = "DESC"; } $sortBy = "time"; if (isset($_GET["sortBy"])) { $sortBy = $_GET["sortBy"]; } else { if (isset($_POST["sortBy"])) { $sortBy = $_POST["sortBy"]; } } $SQL = "SELECT * FROM " . TBL_GAME_ERROR_REPORT . " ORDER BY " . $sortBy . " " . $orderBy . " LIMIT " . ($page - 1) * $pageCount . "," . $pageCount; $errorList = GameErrorReport::findBySql(DBUtils::getConnection(), $SQL); $total_erros = GameErrorReport::getTotalCount(); $max_page = intval($total_erros / $pageCount); if ($total_erros % $pageCount > 0) { $max_page++; } $queryString = ""; if (isset($_GET) && sizeof($_GET) > 0) { foreach ($_GET as $key => $value) { if ($key != "page") { $queryString = $queryString . "&" . $key . "=" . $value; } } } if (strtoupper($orderBy) == "ASC") { $orderBy = "DESC";
<?php define("__ROOT__", __DIR__ . "/../"); require_once __ROOT__ . 'config/constants.php'; require_once __ROOT__ . 'utils/Functions.php'; require_once __ROOT__ . "models/GameFbRealTime.class.php"; $fb = new GameFbRealTime(); $fb->setGetData(json_encode($_GET)); $fb->setPostData(json_encode($_POST)); $fb->setTime(time()); $fb->insertIntoDatabase(DBUtils::getConnection()); if (isset($_GET["hub_challenge"])) { echo $_GET["hub_challenge"]; }
public static function getUserItem($userId, $itemCode) { if (!empty($userId) && !empty($itemCode)) { $items = GameUserItems::findByExample(DBUtils::getConnection(), GameUserItems::create()->setItemCode($itemCode)->setUserId($userId)); if (!empty($items)) { if (is_array($items) && sizeof($items) > 0) { return $items[0]; } else { return $items; } } } return null; }
public static function getFacebookGiftRequest($user, $requestIds) { if (!empty($user) && !empty($requestIds)) { $day = intval(GameConstantUtil::getConstant(FacebookRequestUtils::$CONSTANT_REQUEST_GIFT_TIME)); if ($day <= 0) { $day = 7; } $coin = intval(GameConstantUtil::getConstant(FacebookRequestUtils::$CONSTANT_REQUEST_GIFT_COIN)); if ($day <= 0) { $day = FacebookRequestUtils::$CONSTANT_REQUEST_GIFT_COIN_DEFAULT; } $SQL = "SELECT * FROM " . TBL_GAME_FB_REQUEST . " WHERE `to`='" . DBUtils::mysql_escape($user->facebookId) . "' AND used=0 AND type='" . FacebookRequestUtils::$CONSTANT_REQUEST_TYPE_GIFT . "' AND requestId IN (" . $requestIds . ") ORDER BY `time` DESC"; $fbRequests = GameFbRequest::findBySql(DBUtils::getConnection(), $SQL); $userArray = array(); if (!empty($fbRequests) && sizeof($fbRequests) > 0) { for ($i = sizeof($fbRequests) - 1; $i >= 0; $i--) { $req = $fbRequests[$i]; $req->coin = $coin; if (!empty($req)) { $usrArr = $userArray[$req->userId]; if (empty($usrArr)) { $usrArr = array(); array_push($usrArr, $req); } else { $last = $usrArr[sizeof($usrArr) - 1]; if (intval(date("Ymd", $req->time)) - intval(date("Ymd", $last->time)) >= 7) { array_push($usrArr, $req); } else { GameFbRequest::useRequest($req->getId(), 2); } } $userArray[$req->userId] = $usrArr; } } } unset($fbRequests); $result = array(); foreach ($userArray as $userReq) { if (!empty($userReq) && sizeof($userReq) > 0) { try { $coin = 0; $obj = new stdClass(); $tmp = GameUsers::findById(DBUtils::getConnection(), $userReq[0]->userId); if (!empty($tmp)) { $obj->user = new stdClass(); $obj->user->userId = $tmp->userId; $obj->user->userName = $tmp->userName; $obj->user->userFirstname = $tmp->userFirstname; $obj->user->userLastname = $tmp->userLastname; $obj->user->facebookId = $tmp->facebookId; $obj->user->userXP = $tmp->userXP; $obj->user->userLevelNumber = $tmp->userLevelNumber; $obj->user->coins = $tmp->coins; $ids = ""; foreach ($userReq as $req) { if (!empty($req)) { GameFbRequest::useRequest($req->getId()); $coin = $coin + intval($req->coin); if (!empty($ids)) { $ids = $ids . "," . $req->requestId; } else { $ids = $ids . "" . $req->requestId; } } } $obj->coin = $coin; $obj->ids = $ids; $obj->type = FacebookRequestUtils::$CONSTANT_REQUEST_TYPE_GIFT; array_push($result, $obj); } } catch (Exception $exc) { error_log($exc->getTraceAsString()); } } } unset($userArray); foreach ($result as $value) { if (!empty($value)) { $time = time(); $user->setCoins($user->getCoins() + $value->coin); $user->updateToDatabase(DBUtils::getConnection()); $userCoinLog = new GameUserCoinLog(); $userCoinLog->setUserId($user->userId); $userCoinLog->setCoin($user->getCoins()); $userCoinLog->setDifCoin($value->coin); $userCoinLog->setTime($time); $userCoinLog->setType(FacebookRequestUtils::$CONSTANT_REQUEST_TYPE_GIFT); $userCoinLog->setAdd(1); $userCoinLog->setResult(FacebookRequestUtils::$CONSTANT_REQUEST_TYPE_GIFT . "->" . $value->user->userId . "->" . $value->ids); $userCoinLog->setOpponentId($value->user->userId); $userCoinLog->setUserLevel($user->userLevelNumber); //$userCoinLog->setUserSpentCoin($user->opponentId); try { $userCoinLog->insertIntoDatabase(DBUtils::getConnection()); } catch (Exception $exc) { error_log($exc->getTraceAsString()); } Queue::addUserLeaderBoard($user->userId, $value->coin, $time); } } } return base64_encode(json_encode($requestIds)); }
session_id($_GET["sessionId"]); } session_start(); session_write_close(); $userId = null; if (isset($_GET['userId'])) { $userId = $_GET['userId']; } if (!UtilFunctions::checkUserSession($userId)) { $result->result = "401 : auth error"; header("HTTP/1.1 401 Unauthorized"); echo json_encode($result); exit(1); } if (!empty($userId)) { $roomGroups = GameRoomGroups::findByExample(DBUtils::getConnection(), GameRoomGroups::create()); if (empty($roomGroups)) { $roomGroups = array(); } else { $tmp = array(); foreach ($roomGroups as $room) { if (!empty($room) && $room->roomGroupId != "default") { array_push($tmp, $room); } } $roomGroups = $tmp; unset($tmp); } $result->success = true; $result->result = new stdClass(); $result->result->roomGroups = $roomGroups;
if (isset($_GET['messageCode'])) { $messageCode = $_GET['messageCode']; } else { if (isset($_POST['messageCode'])) { $messageCode = $_POST['messageCode']; } } $gameFBRequest = new GameFbRequest(); $gameFBRequest->setRequestId($requestId); $gameFBRequest->setUserId($userId); $gameFBRequest->setMessageCode($messageCode); $gameFBRequest->setTime(time()); $gameFBRequest->setTo($to); $gameFBRequest->setType($type); $gameFBRequest->setUsed(0); $gameFBRequest->setUsedTime(null); try { $gameFBRequest->insertIntoDatabase(DBUtils::getConnection()); $result->success = true; } catch (Exception $exc) { error_log($exc->getTraceAsString()); $result->success = false; $result->result = new stdClass(); $result->result->code = $exc->getCode(); $result->result->file = $exc->getFile(); $result->result->line = $exc->getLine(); $result->result->msg = $exc->getMessage(); $result->result->trace = $exc->getTraceAsString(); } echo json_encode($result); exit(1);
public static function getFBProductLogs($start, $end) { $SQL = "SELECT * FROM " . TBL_GAME_USER_FB_PRODUCT_LOG . " WHERE userId NOT IN(" . ADMIN_EXCEPT_USERS . ") AND type='buy_product' AND time BETWEEN " . $start . " AND " . $end . " ORDER BY time"; $array = GameUserFbProductLog::findBySql(DBUtils::getConnection(), $SQL); return $array; }
if (isset($_GET['userId'])) { $userId = $_GET['userId']; } else { if (isset($_POST['userId'])) { $userId = $_POST['userId']; } } $email = ""; if (isset($_GET['email'])) { $email = $_GET['email']; } else { if (isset($_POST['email'])) { $email = $_POST['email']; } } $message = ""; if (isset($_GET['message'])) { $message = $_GET['message']; } else { if (isset($_POST['message'])) { $message = $_POST['message']; } } $feedback = new GameUserFeeedback(); $feedback->setUserId($userId); $feedback->setMessage($message); $feedback->setEmail(strtolower($email)); $feedback->setTime(time()); $feedback->insertIntoDatabase(DBUtils::getConnection()); //$html = "<body><h2>User Id : " . $userId . "</h2><h3>Email : " . $email . "</h3><h4>" . $message . "</h4></body>"; //MailUtil::sendSESFromHtml($html, AWS_SES_API_TO_ADMIN, "TavlaMania FeedBack");
array_push($messages, ""); array_push($messages, ""); array_push($messages, "User(" . $user->userId . "-" . $user->userName . ") Start"); $userFBId = $user->getFacebookId(); if (!empty($userFBId)) { $QUERY = "SELECT page_id FROM page_fan WHERE uid = " . $userFBId . " and page_id =580982095281317"; array_push($messages, "User(" . $user->userId . "-" . $user->userName . ") Facebook Like Status SQL :" . $QUERY); try { $params = array('method' => 'fql.query', 'query' => $QUERY); $result = $facebook->api($params); if (!empty($result) && sizeof($result) > 0) { $result = $result[0]; if (!empty($result) && sizeof($result) > 0) { if ($user->getSocialBonusLike() != 1) { $user->setSocialBonusLike(1); $user->updateToDatabase(DBUtils::getConnection()); } array_push($messages, "User(" . $user->userId . "-" . $user->userName . ") Facebook Like Status Done !"); } else { array_push($messages, "User(" . $user->userId . "-" . $user->userName . ") Facebook Like Status Response Empty 2 :'" . json_encode($result) . "'"); } } else { array_push($messages, "User(" . $user->userId . "-" . $user->userName . ") Facebook Like Status Response Empty :'" . json_encode($result) . "'"); } } catch (Exception $exc) { array_push($messages, "User(" . $user->userId . "-" . $user->userName . ") Facebook Like Status Error :" . $exc->getMessage()); } } else { array_push($messages, "User(" . $user->userId . "-" . $user->userName . ") Facebook Id empty "); } } else {