コード例 #1
0
function subscribe_handler($redis, $chan, $msg)
{
    print_r($msg . "---\r\n");
    helper_log("redis submsg: " . $msg);
    switch ($chan) {
        case 'userinfo_chan':
            userinfo_chan($msg);
            break;
        case 'chan-2':
            break;
        case 'chan-3':
            break;
    }
}
コード例 #2
0
ファイル: helper.php プロジェクト: letmefly/php_ramb
function helper_receiveMsg()
{
    $postdata = file_get_contents("php://input");
    if ($postdata == '') {
        helper_log('[helper] post data is blank..');
        return '';
    }
    $private_key = "bnhgdcctuiphnfrkn112512";
    $msgRaw = json_decode($postdata, true);
    $msgJson = $msgRaw['msg'];
    $msgSigh = $msgRaw['sign'];
    if (md5($msgJson . $private_key) != $msgSigh) {
        return null;
    }
    $msg64 = base64_decode($msgJson);
    $msg = json_decode($msg64, true);
    return $msg;
}
コード例 #3
0
ファイル: register.php プロジェクト: letmefly/php_ramb
<?php

include_once 'helper.php';
include_once 'gamedata.php';
$registerInfo = helper_receiveMsg();
$userId = $registerInfo['userId'];
$pw = $registerInfo['pw'];
$name = $registerInfo['name'];
$icon = $registerInfo['icon'];
//helper_sendMsg(array('ret' => 'GameData configuration error'));exit();
$gameData = new GameData();
if (!$gameData) {
    helper_sendMsg(array('ret' => 'GameData configuration error'));
    helper_log('gameData init fail');
    exit;
}
//helper_sendMsg(array('ret' => 'GameData configuration error 2'));exit();
$userInfo = $gameData->getUserInfo($userId);
// not exist, create a new user
$reward = null;
if (!$userInfo) {
    $returnCode = $gameData->userNameCheck($name);
    if ($returnCode) {
        helper_sendMsg(array('ret' => 'error', 'code' => $returnCode['code'], 'msg' => $returnCode['msg']));
        exit;
    }
    $gameData->addNewUser(array('userId' => $userId, 'pw' => $pw, 'name' => $name, 'icon' => $icon));
    $reward = array('item' => 'coin', 'count' => 1000);
} else {
    helper_sendMsg(array('ret' => 'error', 'code' => 1000));
    exit;
コード例 #4
0
ファイル: gamedata.php プロジェクト: letmefly/php_ramb
 private function updateUserInfo($updateInfo)
 {
     if (!$updateInfo || !isset($updateInfo['USERID'])) {
         helper_log("[updateUserInfo] param invalid");
         return;
     }
     $userId = $updateInfo['USERID'];
     // 1. update userinfo memcache
     $userInfo = $this->getUserInfo($userId);
     foreach ($updateInfo as $key => $value) {
         $userInfo[$key] = $value;
     }
     $this->ssdb->hset($this->USER_HASH, $this->PREFIX . $userId, json_encode($userInfo));
     // 2. update score rank memchache
     if ($updateInfo['SCORE']) {
         $this->ssdb->zset($this->todayRank(), $userId, intval($updateInfo['SCORE']));
     }
 }
コード例 #5
0
ファイル: gamedata.php プロジェクト: letmefly/php_ramb
 private function updateUserInfo($updateInfo)
 {
     if (!$updateInfo || !isset($updateInfo['USERID'])) {
         helper_log("[updateUserInfo] param invalid");
         return;
     }
     $userId = $updateInfo['USERID'];
     // 1. update userinfo memcache
     $userInfo = $this->getUserInfo($userId);
     foreach ($updateInfo as $key => $value) {
         $userInfo[$key] = $value;
     }
     // $this->redis->set($this->PREFIX . $userId, json_encode($userInfo));
     $this->redis->hSet($this->USER_HASH, $this->PREFIX . $userId, json_encode($userInfo));
     // 2. update score rank memchache
     if ($updateInfo['SCORE']) {
         $this->redis->zAdd($this->SCORE_RANK, intval($updateInfo['SCORE']), $userId);
         if ($updateInfo['SCORE'] > $userInfo['MAXSCORE']) {
             $this->redis->zAdd($this->MAX_SCORE_RANK, intval($updateInfo['SCORE']), $userId);
             $userInfo['MAXSCORE'] = $updateInfo['SCORE'];
             // update maxscore
             $updateInfo['MAXSCORE'] = $updateInfo['SCORE'];
         }
         // $this->redis->set($this->PREFIX . $userId, json_encode($userInfo));
         $this->redis->hSet($this->USER_HASH, $this->PREFIX . $userId, json_encode($userInfo));
     }
     // 3. update login rank memcache
     if ($updateInfo['LOGINTIMES']) {
         $this->redis->zAdd($this->LOGIN_RANK, intval($updateInfo['LOGINTIMES']), $userId);
     }
     // 2. update mysql async
     $this->redis->publish('userinfo_chan', json_encode($updateInfo));
 }
コード例 #6
0
ファイル: db.php プロジェクト: letmefly/php_ramb
 public function updateAllUser($userInfo)
 {
     if (!$this->connect) {
         helper_log("connect invalid");
         return false;
     }
     $sql = helper_getUpdateSQL("op_user", null, $userInfo);
     if (!mysql_query($sql, $this->connect)) {
         helper_log("updateUser failed");
         return false;
     }
     return true;
 }