Ejemplo n.º 1
0
 public function Tables($forceReload = FALSE)
 {
     if ($this->_Tables == NULL || $forceReload == TRUE) {
         require_once drupal_get_path('module', 'os_poker') . "/poker.class.php";
         $this->_Tables = CPoker::FindUserTable($this->_user->uid);
     }
     return $this->_Tables;
 }
Ejemplo n.º 2
0
 public static function GiveItem($item_id, $targets, $debug = FALSE)
 {
     require_once drupal_get_path('module', 'os_poker') . "/scheduler.class.php";
     require_once drupal_get_path('module', 'os_poker') . "/user.class.php";
     $user = CUserManager::instance()->CurrentUser();
     try {
         if (!is_array($targets) || count($targets) == 0) {
             throw new Exception(t('Bad parameter: !cause', array('!cause' => is_array($targets) ? t('$target is empty') : t('$targer is not an array'))));
         }
         $rawTargets = CUserManager::instance()->UserList($targets);
         $targets = array_filter($rawTargets, "_os_poker_user_accepts_gifts");
         $ntargets = count($targets);
         if ($ntargets == 0) {
             throw new Exception(t('No one of targets accepts gifts'));
         }
         $item = new CItem($item_id);
         //check if the item really exists
         /*
          ** User must pay !
          */
         $nchips = $user->Chips();
         $price = $item->price * $ntargets;
         if (bccomp($nchips, $price) < 0) {
             throw new Exception(t('User doesn\'t have enough money (!uc vs !cn needed).', array('!uc' => $nchips, '!cn' => $price)));
         }
         $sql = "INSERT INTO `{poker_operation}`\n\t\t\t\t   (`id_item`, `uid`, `source_uid`, `tstamp`)\n\t\t\t\t   VALUES ";
         foreach ($targets as $target) {
             $fields[] = "(%d, %d, %d, %s)";
             $values[] = $item->id_item;
             $values[] = $target->uid;
             $values[] = $user->uid;
             $values[] = "NOW()";
         }
         $sql .= implode(", ", $fields);
         $res = db_query($sql, $values);
         if ($res == FALSE) {
             throw new Exception(t('DB error : !message', array("!message" => db_error())));
         }
         /*
          ** Expiry
          */
         $operation_id = db_last_insert_id("{poker_operation}", "id_operation");
         $ttl = $item->ttl;
         if ($operation_id && !empty($ttl)) {
             //$operation_id -= (count($targets) - 1);
             foreach ($targets as $target) {
                 $gift = array('item' => $item->name, 'receiver' => $target->uid, 'sender' => $user->uid);
                 if ($target->ActiveItem() <= 0) {
                     $target->ActivateItem($operation_id, $gift);
                 } else {
                     //Send gift notification, even if the item is not activated
                     foreach ($target->Tables() as $table) {
                         foreach (CPoker::UsersAtTable($table->serial) as $notified_uid) {
                             CScheduler::instance()->RegisterTask(new CGiftNotificationMessage(), $notified_uid, array('live'), "-1 day", $gift);
                         }
                     }
                 }
                 CScheduler::instance()->RegisterTask(new CItemExpiry(), $target->uid, 'live', $ttl, array("id_operation" => $operation_id));
                 ++$operation_id;
                 $args["symbol"] = $item->picture;
                 $args["text"] = t("You just receive a !gift from !user", array("!gift" => substr($item->name, 0, 30), "!user" => $user->profile_nickname));
                 if (_os_poker_user_accepts_gifts($user)) {
                     $args["links"] = l(t("Send a gift in return"), "poker/shop/shop/1/buddy/" . $user->uid);
                 }
                 CMessageSpool::instance()->SendMessage($target->uid, $args);
             }
         }
         /*
          ** User must pay !
          */
         $user->SubChips($price);
         $user->Save();
     } catch (Exception $e) {
         if ($debug == TRUE) {
             throw $e;
         }
         return FALSE;
     }
     return TRUE;
 }
Ejemplo n.º 3
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.º 4
0
function os_poker_shop_page($tab, $category = NULL, $target_type = NULL, $target_id = NULL, $subtarget_id = NULL)
{
    $content = "";
    if ($tab == NULL || $tab == "shop") {
        require_once drupal_get_path('module', 'os_poker') . "/user.class.php";
        require_once drupal_get_path('module', 'os_poker') . "/shop.class.php";
        require_once drupal_get_path('module', 'os_poker') . "/poker.class.php";
        $subtarget = NULL;
        $buddies = NULL;
        $cats = CShop::ListCategories();
        if ($target_type == NULL) {
            $target_type = "self";
        }
        if ($category == NULL) {
            $vcats = array_keys($cats);
            if (count($vcats) > 0) {
                $category = $vcats[0];
            }
        }
        $prods = CShop::ListItems($category);
        if (isset($_GET["list"]) && $_GET["list"] == "items" && !empty($_GET["ajax"])) {
            return print theme('os_poker_item_list', $prods);
        }
        $current_user = CUserManager::instance()->CurrentUser();
        $buddies = array_filter($current_user->Buddies(TRUE), "_os_poker_user_accepts_gifts");
        switch ($target_type) {
            case "table":
                $target = array_filter(CPoker::UsersAtTable($target_id, TRUE), "_os_poker_user_accepts_gifts");
                if ($subtarget_id) {
                    $subtarget = CUserManager::instance()->User($subtarget_id);
                }
                $merge = array_merge(array(), $target, $buddies);
                $special = array();
                foreach ($merge as $u) {
                    $special[$u->uid] = $u->uid;
                }
                $special = array_unique(array_keys($special));
                break;
            case "buddy":
                $target = $buddies;
                $subtarget = CUserManager::instance()->User($target_id);
                break;
            case "self":
                $target = $buddies;
                $subtarget = $current_user;
                break;
        }
        if (!empty($_POST["shop_action"]) && !empty($_POST["shop_item"])) {
            $action = $_POST["shop_action"];
            $success = TRUE;
            switch ($action) {
                case "subtarget":
                    if ($subtarget->uid == $current_user->uid) {
                        $success = CShop::BuyItem($_POST["shop_item"], empty($_POST["shop_item_activate"]) ? FALSE : !!$_POST["shop_item_activate"]);
                        watchdog('os_poker', ' buy: ' . $success);
                    } else {
                        $success = CShop::GiveItem($_POST["shop_item"], array($subtarget));
                        watchdog('os_poker', ' giveItem: ' . $success);
                    }
                    break;
                case "target":
                    $success = CShop::GiveItem($_POST["shop_item"], $target);
                    watchdog('os_poker', ' target: ' . $success);
                    break;
                case "special":
                    $success = CShop::GiveItem($_POST["shop_item"], $special);
                    watchdog('os_poker', ' spezial: ' . $success);
                    break;
            }
            if ($success == FALSE) {
                $error = theme('poker_error_message', "<h1>" . t("Sorry !") . "</h1>" . t("You don't have enough Chips."));
            } else {
                if ($target_type == 'table') {
                    watchdog('os_poker', ' goto');
                    drupal_goto('poker/closebox');
                }
            }
        }
        $params = array("categories" => $cats, "current_category" => $category, "items" => $prods, "current_user" => $current_user, "target_type" => $target_type, "target" => $target, "subtarget" => $subtarget, "target_id" => $target_id, "subtarget_id" => $subtarget_id, "buddies" => $buddies, "special" => $special, "error" => $error);
        $content = theme('os_poker_shop', $params);
    } else {
        if ($tab == "get_chips") {
            $content = theme('os_poker_shop_get_chips', drupal_get_form('chips_paypal_form'), $params);
        }
    }
    return theme('os_poker_shop_tabs', $tab, $content);
}
Ejemplo n.º 5
0
function os_poker_online_users($return_hash = FALSE, $refresh = FALSE)
{
    static $user_hash;
    if (!$refresh && is_array($user_hash)) {
        return $return_hash ? $user_hash : count($user_hash);
    }
    // FROM modules/user.module, user_block (3)
    // Count users active within the defined period.
    $interval = time() - variable_get('user_block_seconds_online', 900);
    // Perform database queries to gather online user lists.  We use s.timestamp
    // rather than u.access because it is much faster.
    $anonymous_count = sess_count($interval);
    $authenticated_users = db_query('SELECT DISTINCT u.uid, u.name, s.timestamp FROM {users} u INNER JOIN {sessions} s ON u.uid = s.uid WHERE s.timestamp >= %d AND s.uid > 0 ORDER BY s.timestamp DESC', $interval);
    $authenticated_count = 0;
    $items = array();
    $user_hash = array();
    while ($account = db_fetch_object($authenticated_users)) {
        $user_hash[$account->uid] = 'drupal';
        $authenticated_count++;
    }
    // We also check the users playing at table, since the drupal time out and jpoker timeout are different
    $players = CPoker::PlayingUsers();
    foreach ($players as $player_uid) {
        if (!isset($user_hash[$player_uid])) {
            $user_hash[$player_uid] = 'table';
            $authenticated_count++;
        }
    }
    // If the current user just logged in, he may not have a session entry. Check manually
    $current_user = CUserManager::instance()->CurrentUser();
    if (!empty($current_user->uid) && !isset($user_hash[$current_user->uid])) {
        $user_has[$current_user->uid] = 'self';
        $authenticated_count++;
    }
    if ($return_hash) {
        return $user_hash;
    }
    return $authenticated_count;
}
Ejemplo n.º 6
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);
}
Ejemplo n.º 7
0
function os_poker_buddy_search_form($form_state)
{
    // Access log settings:
    $form['online_only'] = array('#type' => 'checkbox', '#title' => t('Search Online player only!'), '#default_value' => variable_get('online_only', 0));
    $form['profile_nickname'] = array('#type' => 'textfield', '#title' => t('Nickname'), '#size' => 30, '#maxlength' => 64);
    $form['mail'] = array('#type' => 'textfield', '#title' => t('E-mail'), '#size' => 30, '#maxlength' => 64);
    $sex_options = array(NULL => "--", "Male" => t("Male"), "Female" => t("Female"));
    $form['profile_gender'] = array('#type' => 'select', '#title' => t('Gender'), '#options' => $sex_options);
    $level_options = CPoker::GetStatus();
    $level_options[-1] = '--';
    $form['level'] = array('#type' => 'select', '#title' => t('Level'), '#options' => $level_options, '#default_value' => -1);
    $form['profile_city'] = array('#type' => 'textfield', '#title' => t('City'), '#size' => 30, '#maxlength' => 64);
    $form['profile_country'] = array('#type' => 'select', '#title' => t('Country'), '#multiple' => false, '#options' => _os_poker_country_options());
    $form['submit'] = array('#type' => 'submit', '#value' => t('Send'), '#attributes' => array("style" => "display:none;"));
    $form['f_submit'] = array('#type' => 'markup', '#value' => '<div class="clear"></div><div onclick="javascript:os_poker_submit(this, \'os-poker-buddy-search-form\');" ' . " class='poker_submit'" . " ><div class='pre'>&nbsp;</div><div class='label'>" . t("Search") . "</div></div>");
    return $form;
}