| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
function game_character_character_activate($node) {
|
| 5 |
global $user;
|
| 6 |
game_character_set_active($user->uid, $node);
|
| 7 |
drupal_set_message(t("The game character %title is now active.", array('%title' => $node->title)));
|
| 8 |
drupal_goto('node/'. $node->nid);
|
| 9 |
}
|
| 10 |
|
| 11 |
function game_character_character_inactivate($node) {
|
| 12 |
global $user;
|
| 13 |
db_query("DELETE FROM {game_characters} WHERE nid=%d AND uid=%d", $node->nid, $user->uid);
|
| 14 |
unset($_SESSION['game_character_active']);
|
| 15 |
drupal_set_message(t("The game character %title is now inactive.", array('%title' => $node->title)));
|
| 16 |
drupal_goto('node/'. $node->nid);
|
| 17 |
}
|
| 18 |
|
| 19 |
/**
|
| 20 |
* @file
|
| 21 |
* Page callbacks for the Game character module.
|
| 22 |
*/
|
| 23 |
|
| 24 |
/**
|
| 25 |
* Page callback for game_character/claim/%node/[$claim].
|
| 26 |
* If the user is anonymous, this will set the user's active character as
|
| 27 |
* the claimed character, if the system allows.
|
| 28 |
* If the user has the permission to claim the character, and the system
|
| 29 |
* allows, it will also set the ownership of the node to that user.
|
| 30 |
* @param $node
|
| 31 |
* The node to be claimed. It is already checked for validity in the menu
|
| 32 |
* callback process, so will be denied if this is not a game character
|
| 33 |
* node, or the user is unable to play game characters.
|
| 34 |
* Note the node must also be owned by an anonymous user.
|
| 35 |
* @param $claim
|
| 36 |
* (optional) If not given, this defaults to the claim in the database for
|
| 37 |
* the user's session variable.
|
| 38 |
* This must be a hash code presented at the time of node creation,
|
| 39 |
* or displayed by a game character administrator. Otherwise, it will be
|
| 40 |
* access denied.
|
| 41 |
*/
|
| 42 |
function game_character_character_claim($node, $claim = NULL) {
|
| 43 |
global $user;
|
| 44 |
|
| 45 |
// If no claim code is given, one last chance given if we have the character active in session.
|
| 46 |
if (is_null($claim) && variable_get('game_character_store_active_in_session', TRUE)) {
|
| 47 |
$active = $_SESSION['game_character_active'];
|
| 48 |
$claim = db_result(db_query("SELECT claim FROM {game_character_claims} WHERE nid=%d", $active));
|
| 49 |
}
|
| 50 |
|
| 51 |
// The claim code must match what's in the database.
|
| 52 |
if ($claim != db_result(db_query("SELECT claim FROM {game_character_claims} WHERE nid=%d", $node->nid))) {
|
| 53 |
drupal_access_denied();
|
| 54 |
}
|
| 55 |
|
| 56 |
// Transfer ownership of the node if allowed, and the user is logged in.
|
| 57 |
if (variable_get('game_character_allow_claim_ownership', TRUE) && $user->uid) {
|
| 58 |
$node->uid = $user->uid;
|
| 59 |
node_save($node);
|
| 60 |
game_character_set_active($user->uid, $node);
|
| 61 |
drupal_set_message(t("You have claimed the game character %title as your own.", array('%title' => $node->title)));
|
| 62 |
drupal_goto('node/'. $node->nid);
|
| 63 |
}
|
| 64 |
|
| 65 |
// Simply set the character as active for the user if we're still here and allowed.
|
| 66 |
if (variable_get('game_character_allow_claims', TRUE)) {
|
| 67 |
game_character_set_active($user->uid, $node);
|
| 68 |
drupal_set_message(t("%title is now your active game character.", array('%title' => $node->title)));
|
| 69 |
drupal_goto('node/'. $node->nid);
|
| 70 |
}
|
| 71 |
|
| 72 |
// No can do.
|
| 73 |
drupal_access_denied();
|
| 74 |
}
|