示例#1
0
 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 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 function lost()
 {
     $log = KLogger::instance(KLOGGER_PATH . "processors/", KLogger::DEBUG);
     $log->logInfo("usergameaction > lost > start userId : " . $this->userId . " opponentId : " . $this->opponentId . " action : " . $this->action_ . " time : " . $this->time . " room groupId : " . $this->roomGroupId . " gameId : " . $this->gameId . " normal : " . $this->normal . " type : " . $this->type . " double : " . $this->double);
     if (!empty($this->userId)) {
         $user = GameUsers::getGameUserById($this->userId);
         if (!empty($user)) {
             $userId = $user->getUserId();
             if (!empty($userId)) {
                 $user->getUserLevel();
                 $opponent = GameUsers::getGameUserById($this->opponentId);
                 $opponentId = null;
                 if (!empty($opponent)) {
                     $opponentId = $opponent->getUserId();
                     $opponent->getUserLevel();
                 }
                 $result = GameUtils::gameResult($user, $opponent, $this->roomGroupId, $this->action_, $this->gameId, $this->double, $this->normal, $this->type, $this->time);
                 if (!empty($result) && $result->success) {
                     $log->logInfo("usergameaction > lost > success ");
                 } else {
                     $log->logError("usergameaction > lost > error :  " . $result->result);
                 }
                 unset($userId);
                 unset($user);
             } else {
                 $log->logError("usergameaction > lost > user Id is empty ");
             }
         } else {
             $log->logError("usergameaction > lost > user Id is empty ");
         }
     } else {
         $log->logError("usergameaction > lost > user Id is empty ");
     }
 }
示例#4
0
 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;
 }
示例#6
0
        $quantity = $_GET['quantity'];
    }
}
if ($quantity < 1) {
    $quantity = 1;
}
if (!UtilFunctions::checkUserSession($userId)) {
    $result->result = "401 : auth error";
    header("HTTP/1.1 401 Unauthorized");
    echo json_encode($result);
    exit(1);
}
$log = KLogger::instance(KLOGGER_PATH . "apis/", KLogger::DEBUG);
$error = false;
if (!empty($userId)) {
    $user = GameUsers::getGameUserById($userId);
    if (empty($user)) {
        $error = false;
        $log->logError(LanguageUtils::getText("LANG_API_USER_EMPTY"));
        $result->result = LanguageUtils::getText("LANG_API_USER_EMPTY");
    } else {
        $error = true;
    }
} else {
    $log->logError(LanguageUtils::getText("LANG_API_USER_ID_EMPTY"));
    $result->result = LanguageUtils::getText("LANG_API_USER_ID_EMPTY");
}
if ($error) {
    $error = false;
    if (!empty($itemCode)) {
        $itemCode = str_replace("/", "", $itemCode);
示例#7
0
    exit(1);
}
$log = KLogger::instance(KLOGGER_PATH . "apis/", KLogger::DEBUG);
if (empty($action) || !empty($action) && $action != GameUtils::$GAME_RESULT_ACTION_WIN && $action != GameUtils::$GAME_RESULT_ACTION_LOST) {
    $log->logError("Unknown Action");
    $result->result = "Unknown Action";
    echo json_encode($result);
    exit(1);
}
if (!empty($userId)) {
    $user = GameUsers::getGameUserById($userId);
    if (!empty($user)) {
        $userId = $user->getUserId();
        if (!empty($userId)) {
            $user->getUserLevel();
            $opponent = GameUsers::getGameUserById($opponentId);
            $opponentId = null;
            if (!empty($opponent)) {
                $opponentId = $opponent->getUserId();
                $opponent->getUserLevel();
            }
            $log->logInfo("gameResult : userId > " . $userId . " opponentId > " . $opponentId . " roomgroupId > " . $roomGroupId . " gameId > " . $gameId . " double > " . $double . " normal > " . $normal . " type > " . $type);
            $result = GameUtils::gameResult($user, $opponent, $roomGroupId, $action, $gameId, $double, $normal, $type);
            unset($userId);
            unset($user);
        } else {
            $log->logError("User not found");
            $result->result = "User not found";
        }
    } else {
        $log->logError("User not found");
示例#8
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);
        }
    }
示例#9
0
            $tag = $_GET["tag"];
            $str = $tag . " " . $orderBy;
            $userList = GameUsers::getUserListOrderBy($str, ($pageNumber - 1) * 100, 100);
            if ($orderBy == "DESC") {
                $orderBy = "ASC";
            } else {
                $orderBy = "DESC";
            }
        } else {
            if ($action == "activate" || $action == "deactivate") {
                $value = $action == "activate" ? 1 : 0;
                $id = -1;
                if (isset($_GET["userId"])) {
                    $id = $_GET["userId"];
                }
                $_user = GameUsers::getGameUserById($id);
                if (!empty($_user)) {
                    $_user->setActive($value);
                    $_user->updateToDatabase(DBUtils::getConnection());
                }
                $userList = GameUsers::getUserList(($pageNumber - 1) * 100, 100);
            }
        }
    }
} else {
    $userList = GameUsers::getUserList(($pageNumber - 1) * 100, 100);
    if (sizeof($userList) == 0) {
        $pageNumber = $pageNumber - 1;
        $userList = GameUsers::getUserList(($pageNumber - 1) * 100, 100);
    }
}
 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 ");
     }
 }
示例#11
0
                    <td style ="color: #7ba29a; font-weight: bold;">User Level(past)</td>
                    <td style ="color: #7ba29a; font-weight: bold;">Product Id</td>
                    <!--<td style ="color: #7ba29a; font-weight: bold;">Status</td>-->
                    <!--<td style ="color: #7ba29a; font-weight: bold;">Quantity</td>-->
                    <td style ="color: #7ba29a; font-weight: bold;">Coin</td>
                    <td style ="color: #7ba29a; font-weight: bold;">Amount</td>
                    <td style ="color: #7ba29a; font-weight: bold;">Currency</td>
                    <td style ="color: #7ba29a; font-weight: bold;">Time</td>
                </tr>
                <?php 
if (!empty($paymentList)) {
    $payment = new GameUserFbProductLog();
    $paymentTotal = 0;
    for ($i = 0; $i < sizeof($paymentList); $i++) {
        $payment = $paymentList[$i];
        $user = GameUsers::getGameUserById($payment->getUserId());
        $paymentTotal = $paymentTotal + $payment->getAmount();
        ?>
                        <tr>
                            <!--<td style ="color: #7ba29a; font-weight: bold;"><?php 
        echo $payment->getRequestId();
        ?>
</td> -->
                            <td style ="color: #7ba29a; font-weight: bold;"><?php 
        echo $payment->getUserId();
        ?>
</td> 
                            <td style ="color: #7ba29a; font-weight: bold;"><?php 
        echo $user->getUserFirstname() . " " . $user->getUserLastname();
        ?>
</td>
示例#12
0
        $useItem = $_GET['useItem'];
    }
}
if (!UtilFunctions::checkUserSession($userId)) {
    $result->result = "401 : auth error";
    header("HTTP/1.1 401 Unauthorized");
    echo json_encode($result);
    exit(1);
}
$log = KLogger::instance(KLOGGER_PATH . "apis/", KLogger::DEBUG);
$error = false;
if (!empty($userId)) {
    $user = GameUsers::getGameUserById($userId);
    if ($userId != $toUserId) {
        if (!empty($toUserId)) {
            $toUser = GameUsers::getGameUserById($toUserId);
            $error = true;
        } else {
            $log->logError(LanguageUtils::getText("LANG_API_TO_USER_ID_EMPTY"));
            $result->result = LanguageUtils::getText("LANG_API_TO_USER_ID_EMPTY");
        }
    } else {
        $toUser = $user;
        $error = true;
    }
} else {
    $log->logError(LanguageUtils::getText("LANG_API_USER_ID_EMPTY"));
    $result->result = LanguageUtils::getText("LANG_API_USER_ID_EMPTY");
}
if ($error) {
    $error = false;