Ejemplo n.º 1
0
 function addContact($name)
 {
     global $db;
     // check username
     $player = getPlayerByName($name);
     // no such player or diplicate entry
     if (!$player) {
         return CONTACTS_ERROR_NOSUCHPLAYER;
     } else {
         $sql = $db->prepare("SELECT *\n                           FROM " . CONTACTS_TABLE . "\n                           WHERE contactplayerID = :contactplayerID\n                             AND playerID = :playerID");
         $sql->bindValue('contactplayerID', $player['playerID'], PDO::PARAM_INT);
         $sql->bindParam('playerID', $_SESSION['player']->playerID, PDO::PARAM_INT);
         if (!$sql->execute()) {
             return CONTACTS_ERROR_INSERTFAILED;
         }
         if ($sql->fetch(PDO::FETCH_ASSOC)) {
             return CONTACTS_ERROR_DUPLICATE_ENTRY;
         }
     }
     // no more than CONTACTS_MAX should be inserted
     if (sizeof($this->getContacts()) >= CONTACTS_MAX) {
         return CONTACTS_ERROR_MAXREACHED;
     }
     // insert player
     $sql = $db->prepare("INSERT INTO " . CONTACTS_TABLE . " (playerID, contactplayerID)\n                         VALUES (:playerID, :contactID)");
     $sql->bindParam('playerID', $_SESSION['player']->playerID, PDO::PARAM_INT);
     $sql->bindParam('contactID', $player['playerID'], PDO::PARAM_INT);
     if (!$sql->execute()) {
         return CONTACTS_ERROR_INSERTFAILED;
     }
     return CONTACTS_NOERROR;
 }
Ejemplo n.º 2
0
 function addContact($name)
 {
     global $db, $params;
     // check username
     $player = getPlayerByName($name);
     // no such player
     if (!sizeof($player)) {
         return CONTACTS_ERROR_NOSUCHPLAYER;
     }
     // no more than CONTACTS_MAX should be inserted
     if (sizeof($this->getContacts()) >= CONTACTS_MAX) {
         return CONTACTS_ERROR_MAXREACHED;
     }
     // insert player
     $sql = sprintf("INSERT INTO `Contacts` (`playerID`, `contactplayerID`) " . "VALUES ('%d', '%d')", $params->SESSION->player->playerID, $player['playerID']);
     if (!$db->query($sql)) {
         return CONTACTS_ERROR_INSERTFAILED;
     }
     return CONTACTS_NOERROR;
 }
Ejemplo n.º 3
0
 switch ($_GET["action"]) {
     case "getPlayer":
         if (isset($_GET["id"])) {
             //Get player by id
             $value = getPlayer($_GET["id"]);
             if ($value == false) {
                 $value = array("error" => "No player");
             }
         } else {
             $value = array("error" => "Missing argument");
         }
         break;
     case "getPlayerByName":
         if (isset($_GET["username"])) {
             //Get player by name
             $value = getPlayerByName($_GET['username']);
         } else {
             $value = array("error" => "Missing argument");
         }
         break;
     case "reportPlayer":
         if (isset($_GET["id"]) && isset($_GET["reporting_id"]) && isset($_GET["report"]) && isset($_GET['apikey'])) {
             if ($_GET['apikey'] == _API_KEY_) {
                 //Get player by id
                 $value = reportPlayer($_GET['id'], $_GET["report"], $_GET["reporting_id"]);
             } else {
                 $value = array("error" => "Invalid API key");
             }
         } else {
             $value = array("error" => "Missing argument");
         }
Ejemplo n.º 4
0
function Module_Awards_decorate_player()
{
    global $db_game, $params;
    // init msgs
    $msgs = array();
    // open template
    $template = tmpl_open("modules/Module_Awards/templates/decorate_player.ihtml");
    // get all awards
    $awards = award_lib_get_awards($db_game);
    // no awards yet
    if (!sizeof($awards)) {
        $msgs[] = "There are no awards.. Create at least one first...";
    } else {
        // choose player
        if (isset($params->decorate_choose)) {
            // empty name
            if (empty($params->decoratePlayer)) {
                $msgs[] = "A player's name must be filled in!";
            } else {
                // get Player
                $player = getPlayerByName($db_game, $params->decoratePlayer);
                if (!sizeof($player)) {
                    $msgs[] = "No such player: '{$params->decoratePlayer}'!";
                } else {
                    // get awards
                    $p_awards = award_lib_get_player_awards($db_game, $player['playerID']);
                    // create array from packed awards field of that player
                    if (!empty($p_awards)) {
                        $p_awards = explode('|', $p_awards);
                    } else {
                        $p_awards = array();
                    }
                    $p_awards = array_unique($p_awards);
                    $p_awards = array_filter($p_awards, create_function('$tag', 'return ereg("^[0-9a-zA-Z]+$", $tag);'));
                    foreach ($awards as $award) {
                        if (in_array($award['tag'], $p_awards)) {
                            $award['CHOSEN'] = array('dummy' => "");
                        }
                        tmpl_iterate($template, "/FORM_DECORATE/AWARD");
                        tmpl_set($template, "/FORM_DECORATE/AWARD", $award);
                    }
                    tmpl_set($template, "/FORM_DECORATE", $player);
                }
            }
            // decorated
        } else {
            if (isset($params->decorator)) {
                $playerID = (int) $params->decoratePlayerID;
                if (!award_lib_decorate($db_game, $playerID, $params->decorateAward)) {
                    $msgs[] = "Error while decorating '{$params->decoratePlayer}'!";
                } else {
                    $msgs[] = "'{$params->decoratePlayer}' decorated!";
                    //////
                    // get Player
                    $player = getPlayerByName($db_game, $params->decoratePlayer);
                    if (!sizeof($player)) {
                        $msgs[] = "No such player: '{$params->decoratePlayer}'!";
                    } else {
                        // get awards
                        $p_awards = award_lib_get_player_awards($db_game, $player['playerID']);
                        // create array from packed awards field of that player
                        if (!empty($p_awards)) {
                            $p_awards = explode('|', $p_awards);
                        } else {
                            $p_awards = array();
                        }
                        $p_awards = array_unique($p_awards);
                        $p_awards = array_filter($p_awards, create_function('$tag', 'return ereg("^[0-9a-zA-Z]+$", $tag);'));
                        foreach ($awards as $award) {
                            if (in_array($award['tag'], $p_awards)) {
                                $award['CHOSEN'] = array('dummy' => "");
                            }
                            tmpl_iterate($template, "/FORM_DECORATE/AWARD");
                            tmpl_set($template, "/FORM_DECORATE/AWARD", $award);
                        }
                        tmpl_set($template, "/FORM_DECORATE", $player);
                    }
                    //////
                }
            }
        }
        tmpl_set($template, "/FORM_CHOOSE/name", $params->decoratePlayer);
    }
    // show messages
    if (sizeof($msgs)) {
        foreach ($msgs as $msg) {
            tmpl_iterate($template, "MESSAGE");
            tmpl_set($template, "MESSAGE/message", $msg);
        }
    }
    return tmpl_parse($template);
}