Ejemplo n.º 1
0
 public static function CheckRewards($action, $source, $targets)
 {
     $player = CUserManager::instance()->User($source);
     if ($player) {
         $rew = $player->Rewards();
         switch ($action) {
             case "invite":
                 $invites = $player->Invites();
                 if (count($invites["accepted"]) >= 50) {
                     CPoker::GiveReward("reward63", $player, $rew);
                 }
                 if (count($invites["accepted"]) >= 25) {
                     CPoker::GiveReward("reward52", $player, $rew);
                 }
                 if (count($invites["accepted"]) >= 5) {
                     CPoker::GiveReward("reward37", $player, $rew);
                 }
                 if (count($invites["accepted"]) >= 2) {
                     CPoker::GiveReward("reward17", $player, $rew);
                 }
                 break;
             case "buddy":
                 $buddies = $player->Buddies(FALSE, TRUE);
                 if (count($buddies) >= 100) {
                     CPoker::GiveReward("reward62", $player, $rew);
                 }
                 if (count($buddies) >= 50) {
                     CPoker::GiveReward("reward51", $player, $rew);
                 }
                 if (count($buddies) >= 10) {
                     CPoker::GiveReward("reward36", $player, $rew);
                 }
                 if (count($buddies) >= 5) {
                     CPoker::GiveReward("reward16", $player, $rew);
                 }
                 break;
             case "sit":
                 $buddies = $player->Buddies();
                 CPoker::GiveReward("reward1", $player, $rew);
                 if ($rew["reward18"]["value"] == 0) {
                     foreach ($buddies as $buddy) {
                         if (in_array($buddy, $targets)) {
                             CPoker::GiveReward("reward18", $player, $rew);
                         }
                     }
                 }
                 break;
             case "chips":
                 $chips = $player->Chips();
                 if (bccomp($chips, "1000000") >= 0 || bccomp($targets['chips'], "1000000") >= 0) {
                     CPoker::GiveReward("reward40", $player, $rew);
                 }
                 break;
             default:
                 break;
         }
         /* global check at each CheckRewards for Strike! */
         $all_rewards = CPoker::GetRewards();
         if ($player->GetNumRewards() == count($all_rewards) - 1) {
             CPoker::GiveReward("reward57", $player, $rew);
         }
     }
 }
Ejemplo n.º 2
0
 public function Rewards($forceReload = FALSE)
 {
     if ($this->_Rewards == NULL || $forceReload == TRUE) {
         require_once drupal_get_path('module', 'os_poker') . "/poker.class.php";
         $this->_Rewards = CPoker::GetRewards();
         foreach ($this->_Rewards as $key => $value) {
             if (isset($this->_vars[$key])) {
                 $this->_Rewards[$key]["value"] = $this->_vars[$key];
             }
         }
     }
     return $this->_Rewards;
 }
Ejemplo n.º 3
0
function _os_poker_process_message_unsafe()
{
    static $poker_server_events = array('NONE', 'HAND', 'TOURNEY', 'BUY_IN', 'REFILL', 'PRIZE', 'REGISTER', 'UNREGISTER', 'LEAVE', 'SEAT', 'TOURNEY_START');
    $current_user = CUserManager::instance()->CurrentUser();
    $resp = array("errorMsg" => NULL, "error" => FALSE, "messages" => array());
    $message_type = trim(isset($_GET["type"]) ? trim($_GET["type"]) : "noop");
    if ($message_type == "os_poker_reward") {
        /* Reward message is a special message which comes without a current user context 
        		   args[0] = reward number
        		   args[1] = player serial
        		   args[2] = time_stamp
        		*/
        $all_rewards = CPoker::GetRewards();
        $params = json_decode($_GET['args'], TRUE);
        CPoker::ShowReward("reward" . $params[0], $params[1], $all_rewards);
        $resp["messages"][] = array("type" => "noop", "body" => NULL);
    }
    if ($current_user && $current_user->uid != 0) {
        switch ($message_type) {
            case "os_poker_sit_down":
                CPoker::CheckRewards("sit", $current_user->uid, json_decode($_GET["players"], TRUE));
                $resp["messages"][] = array("type" => "noop", "body" => NULL);
                break;
            case "os_poker_daily_gift":
                if ($current_user->DailyGift()) {
                    $resp["messages"][] = array('type' => 'os_poker_gift_sent', 'body' => array('text' => t('You have sent !amount free chips to !count buddies', array('!count' => count($current_user->Buddies()), '!amount' => 100))));
                } else {
                    $resp["messages"][] = array("type" => "noop", "body" => NULL);
                }
                break;
            case "os_poker_load_messagebox":
                CScheduler::instance()->Trigger("inbox");
                $mbox = CScheduler::instance()->GetUnreadTasks("inbox");
                $mboxsize = count($mbox);
                if ($_GET["msgcount"] != $mboxsize) {
                    $resp["messages"][] = array("type" => "os_poker_messagebox", "body" => array("inbox" => $mboxsize, "picture" => $base_path . drupal_get_path('module', 'os_poker') . "/images/mailbox.png"));
                } else {
                    $resp["messages"][] = array("type" => "noop", "body" => NULL);
                }
                break;
            case "os_poker_challenge_user":
                //TODO: limit challenge to 1 per sender/receiver
                if (isset($_GET["challengetarget"])) {
                    $target_user = CUserManager::instance()->User($_GET["challengetarget"]);
                    if ($target_user && $target_user->uid != 0 && $current_user->uid != $target_user->uid) {
                        //Wait for symbol, text, link
                        $args["symbol"] = 'chips';
                        $args["text"] = t("You just receive a headsup challenge from !user", array("!user" => $current_user->profile_nickname));
                        $args["links"] = "<a class='noreplace' href='javascript:void(0);' onclick='javascript:parent.os_poker_start_challenge(" . $current_user->uid . ", " . $target_user->uid . ");'>" . t("Accept") . "</a>/<a href='javascript:void(0);' >" . t("Refuse") . "</a>";
                        CMessageSpool::instance()->SendMessage($target_user->uid, $args);
                        $notification = array('text' => t("You just challenged !user", array("!user" => $target_user->profile_nickname ? $target_user->profile_nickname : variable_get('anonymous', t('Anonymous')))), 'title' => t('Challenge'));
                        CMessageSpool::instance()->SendInstantMessage($notification);
                        $resp["messages"][] = array("type" => "os_poker_notify", "body" => $notification);
                    }
                }
                break;
            case "os_poker_activate_item":
                if (isset($_GET["id_item"]) && is_numeric($_GET["id_item"])) {
                    $current_user->ActivateItem($_GET["id_item"]);
                } else {
                    trigger_error(t('Invalid item ID: %item_id', array('%item_id' => isset($_GET["id_item"]) ? $_GET["id_item"] : 'undefined')), E_USER_ERROR);
                }
                break;
            case "os_poker_invite_user":
                if (isset($_GET["target"])) {
                    $target_user = CUserManager::instance()->User($_GET["target"]);
                    if ($target_user && $target_user->uid != 0 && $current_user->uid != $target_user->uid) {
                        $tables = $current_user->Tables();
                        if (count($tables) > 0) {
                            $args["symbol"] = 'chips';
                            $args["text"] = t("!user is playing at table !table come and join", array("!user" => $current_user->profile_nickname, "!table" => $tables[0]->name));
                            //TODO : Check $_GET["online"] to send mail
                            CMessageSpool::instance()->SendMessage($target_user->uid, $args);
                            $notification = array('text' => t("You just invited !user to play", array("!user" => $target_user->profile_nickname ? $target_user->profile_nickname : variable_get('anonymous', t('Anonymous')))), 'title' => t('Invitation'));
                            CMessageSpool::instance()->SendInstantMessage($notification);
                            $resp["messages"][] = array("type" => "os_poker_notify", "body" => $notification);
                        }
                    }
                }
                break;
            case 'os_poker_trigger_error':
                trigger_error("Message triggered error.", E_USER_ERROR);
                break;
            case 'os_poker_trigger_exception':
                throw new Exception('Message triggered exception.');
                break;
            default:
                $resp["messages"][] = array("type" => "noop", "body" => NULL);
                break;
        }
    }
    if (in_array(drupal_strtoupper($message_type), $poker_server_events)) {
        if (preg_match('/\\[([^,]+),([^,]+),([^,]+)\\]/', $_GET['args'], $args)) {
            array_shift($args);
        }
        //Event setn from the poker server
        //TODO Authenticate the request... how ?
        switch ($message_type) {
            case 'BUY_IN':
                list($uid, $game_id, $amount) = $args;
                if (user_load($uid)) {
                    CScheduler::instance()->RegisterTask(new CUpdateUserChipsCount(), $uid, array('live'));
                    $resp["messages"][] = array("type" => "debug", "body" => t('Recevied BUY_IN for user !uid', array('!uid' => $uid)));
                } else {
                    trigger_error(t('Invalid user ID: %uid', array('%uid' => $uid)), E_USER_ERROR);
                }
                break;
            case 'TOURNEY_START':
                list($tourney_serial, $dummy1, $dummy2) = $args;
                $tourney_users = CPoker::TourneyRegisteredUsers($tourney_serial);
                foreach ($tourney_users as $tourney_user) {
                    if (user_load($tourney_user->user_serial)) {
                        CScheduler::instance()->RegisterTask(new CTourneyNotificationMessage(), $tourney_user->user_serial, array('live'), "-1 day", array($tourney_serial, $tourney_user->description_short, $tourney_user->table_serial));
                        $resp["messages"][] = array("type" => "debug", "body" => t('Recevied tourney start notification for user !uid', array('!uid' => $tourney_user->user_serial)));
                    }
                }
                break;
            case 'HAND':
            case 'TOURNEY':
            case 'REFILL':
            case 'PRIZE':
            case 'REGISTER':
            case 'UNREGISTER':
            case 'LEAVE':
            case 'SEAT':
            case 'NONE':
                $resp["messages"][] = array("type" => "noop", "body" => NULL);
                break;
        }
    } else {
        if (!$resp["messages"]) {
            $resp["messages"][] = array("type" => "noop", "body" => NULL);
        }
    }
    _os_poker_process_message_set_header();
    print json_encode($resp);
}