コード例 #1
0
 /**
  * get single GameUserLoginLog instance from a DOMElement
  *
  * @param DOMElement $node
  * @return GameUserLoginLog
  */
 public static function fromDOMElement(DOMElement $node)
 {
     $o = new GameUserLoginLog();
     $o->assignByHash(self::domNodeToHash($node, self::$FIELD_NAMES, self::$DEFAULT_VALUES, self::$FIELD_TYPES));
     $o->notifyPristine();
     return $o;
 }
コード例 #2
0
 public static function getUserDailyBonus($userId)
 {
     $result = array();
     if (!empty($userId)) {
         try {
             $SQL = "SELECT * FROM " . TBL_GAME_USER_LOGIN_LOG . " WHERE userId=" . DBUtils::mysql_escape($userId, 1) . " GROUP BY date ORDER BY date DESC LIMIT 0,7";
             $dailies = GameUserLoginLog::findBySql(DBUtils::getConnection(), $SQL);
             $dailyBonusConstants = BonusUtils::getDailyBonusConstants();
             $good = 1;
             if (!empty($dailies) && sizeof($dailies) > 1) {
                 for ($i = 1; $i < sizeof($dailies); $i++) {
                     $current = $dailies[$i];
                     $prev = $dailies[$i - 1];
                     if (!empty($current) && !empty($prev)) {
                         $diffs = UtilFunctions::dateDiff(intval($prev->time), intval($current->time));
                         if ($diffs['year'] > 0 || $diffs['month'] > 0 || $diffs['month'] > 0 || $diffs['day'] > 1) {
                             break;
                         } else {
                             $currentD = date("d", $current->time);
                             $prevD = date("d", $prev->time);
                             if ($diffs['day'] == 1 && $diffs["hour"] <= 0 && $diffs["minute"] <= 0 && $diffs["second"] <= 0) {
                                 $good++;
                             } else {
                                 if ($currentD != $prevD) {
                                     $good++;
                                 } else {
                                     break;
                                 }
                             }
                         }
                     } else {
                         break;
                     }
                 }
             }
             for ($i = 0; $i < 7; $i++) {
                 $dailybonus = new stdClass();
                 if (!empty($dailyBonusConstants) && sizeof($dailyBonusConstants) > $i) {
                     $tmp = $dailyBonusConstants[$i];
                     if (!empty($tmp)) {
                         $dailybonus = $tmp;
                     }
                 } else {
                     $dailybonus->order = $i + 1;
                     $dailybonus->coin = ($i + 1) * 100;
                 }
                 if ($i < $good) {
                     $dailybonus->active = true;
                 } else {
                     $dailybonus->active = false;
                 }
                 array_push($result, $dailybonus);
             }
         } catch (Exception $exc) {
             error_log($exc->getTraceAsString());
         }
     }
     return $result;
 }
コード例 #3
0
    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);
        }
    }