Exemple #1
0
function user_create_character($character_data)
{
    array_walk($character_data, 'array_sanitize');
    $cnf = fullConfig();
    if ($character_data['sex'] == 1) {
        $outfit_type = $cnf['maleOutfitId'];
    } else {
        $outfit_type = $cnf['femaleOutfitId'];
    }
    // This is TFS 0.2 compatible import data with Znote AAC mysql schema
    $import_data = array('name' => $character_data['name'], 'group_id' => 1, 'account_id' => $character_data['account_id'], 'level' => $cnf['level'], 'vocation' => $character_data['vocation'], 'health' => $cnf['health'], 'healthmax' => $cnf['health'], 'experience' => 0, 'lookbody' => $cnf['lookBody'], 'lookfeet' => $cnf['lookFeet'], 'lookhead' => $cnf['lookHead'], 'looklegs' => $cnf['lookLegs'], 'looktype' => $outfit_type, 'lookaddons' => 0, 'maglevel' => 0, 'mana' => $cnf['mana'], 'manamax' => $cnf['mana'], 'manaspent' => 0, 'soul' => $cnf['soul'], 'town_id' => $character_data['town_id'], 'posx' => $cnf['default_pos']['x'], 'posy' => $cnf['default_pos']['y'], 'posz' => $cnf['default_pos']['z'], 'conditions' => '', 'cap' => $cnf['cap'], 'sex' => $character_data['sex'], 'lastlogin' => 0, 'lastip' => $character_data['lastip'], 'save' => 1, 'skull' => 0, 'skulltime' => 0, 'rank_id' => 0, 'guildnick' => '', 'lastlogout' => 0, 'blessings' => 0, 'direction' => 0, 'loss_experience' => 10, 'loss_mana' => 10, 'loss_skills' => 10, 'premend' => 0, 'online' => 0, 'balance' => 0);
    // TFS 1.0 rules
    if (Config('TFSVersion') === 'TFS_10') {
        unset($import_data['rank_id']);
        unset($import_data['guildnick']);
        unset($import_data['direction']);
        unset($import_data['loss_experience']);
        unset($import_data['loss_mana']);
        unset($import_data['loss_skills']);
        unset($import_data['loss_mana']);
        unset($import_data['premend']);
        unset($import_data['online']);
    }
    // Set correct experience for level
    $import_data['experience'] = level_to_experience($import_data['level']);
    // If you are no vocation (id 0), use these details instead:
    if ($character_data['vocation'] === '0') {
        $import_data['level'] = $cnf['nvlevel'];
        $import_data['experience'] = level_to_experience($cnf['nvlevel']);
        $import_data['health'] = $cnf['nvHealth'];
        $import_data['healthmax'] = $cnf['nvHealth'];
        $import_data['cap'] = $cnf['nvCap'];
        $import_data['mana'] = $cnf['nvMana'];
        $import_data['manamax'] = $cnf['nvMana'];
        $import_data['soul'] = $cnf['nvSoul'];
        if ($cnf['nvForceTown'] == 1) {
            $import_data['town_id'] = $cnf['nvTown'];
        }
    }
    $fields = array_keys($import_data);
    // Fetch select fields
    $data = array_values($import_data);
    // Fetch insert data
    $fields_sql = implode("`, `", $fields);
    // Convert array into SQL compatible string
    $data_sql = implode("', '", $data);
    // Convert array into SQL compatible string
    echo 1;
    mysql_insert("INSERT INTO `players`(`{$fields_sql}`) VALUES ('{$data_sql}');");
    $created = time();
    $charid = user_character_id($import_data['name']);
    echo 2;
    mysql_insert("INSERT INTO `znote_players`(`player_id`, `created`, `hide_char`, `comment`) VALUES ('{$charid}', '{$created}', '0', '');");
}
Exemple #2
0
 /**
  * Create player.
  *
  * @param  none
  * @access public
  * @return bool $status
  **/
 public function create()
 {
     // If player already have an id, the player already exist.
     if (is_null($this->_playerdata['id']) && is_string($this->_playerdata['name'])) {
         // Confirm player does not exist
         $name = format_character_name($this->_playerdata['name']);
         $name = validate_name($name);
         $name = sanitize($name);
         $exist = mysql_select_single("SELECT `id` FROM `players` WHERE `name`='{$name}' LIMIT 1;");
         if ($exist !== false) {
             $this->errors[] = "A player with the name [{$name}] already exist.";
             return false;
         }
         $config = fullConfig();
         if (user_character_exist($_POST['name']) !== false) {
             $errors[] = 'Sorry, that character name already exist.';
         }
         if (!preg_match("/^[a-zA-Z_ ]+\$/", $_POST['name'])) {
             $errors[] = 'Your name may only contain a-z, A-Z and spaces.';
         }
         if (strlen($_POST['name']) < $config['minL'] || strlen($_POST['name']) > $config['maxL']) {
             $errors[] = 'Your character name must be between ' . $config['minL'] . ' - ' . $config['maxL'] . ' characters long.';
         }
         // name restriction
         $resname = explode(" ", $_POST['name']);
         foreach ($resname as $res) {
             if (in_array(strtolower($res), $config['invalidNameTags'])) {
                 $errors[] = 'Your username contains a restricted word.';
             } else {
                 if (strlen($res) == 1) {
                     $errors[] = 'Too short words in your name.';
                 }
             }
         }
         // Validate vocation id
         if (!in_array((int) $_POST['selected_vocation'], $config['available_vocations'])) {
             $errors[] = 'Permission Denied. Wrong vocation.';
         }
         // Validate town id
         if (!in_array((int) $_POST['selected_town'], $config['available_towns'])) {
             $errors[] = 'Permission Denied. Wrong town.';
         }
         // Validate gender id
         if (!in_array((int) $_POST['selected_gender'], array(0, 1))) {
             $errors[] = 'Permission Denied. Wrong gender.';
         }
         if (vocation_id_to_name($_POST['selected_vocation']) === false) {
             $errors[] = 'Failed to recognize that vocation, does it exist?';
         }
         if (town_id_to_name($_POST['selected_town']) === false) {
             $errors[] = 'Failed to recognize that town, does it exist?';
         }
         if (gender_exist($_POST['selected_gender']) === false) {
             $errors[] = 'Failed to recognize that gender, does it exist?';
         }
         // Char count
         $char_count = user_character_list_count($session_user_id);
         if ($char_count >= $config['max_characters']) {
             $errors[] = 'Your account is not allowed to have more than ' . $config['max_characters'] . ' characters.';
         }
         if (validate_ip(getIP()) === false && $config['validate_IP'] === true) {
             $errors[] = 'Failed to recognize your IP address. (Not a valid IPv4 address).';
         }
         echo "create player";
         // Make sure all neccesary values are set
         //Register
         $character_data = array('name' => format_character_name($_POST['name']), 'account_id' => $session_user_id, 'vocation' => $_POST['selected_vocation'], 'town_id' => $_POST['selected_town'], 'sex' => $_POST['selected_gender'], 'lastip' => ip2long(getIP()), 'created' => time());
         array_walk($character_data, 'array_sanitize');
         $cnf = fullConfig();
         if ($character_data['sex'] == 1) {
             $outfit_type = $cnf['maleOutfitId'];
         } else {
             $outfit_type = $cnf['femaleOutfitId'];
         }
         // Create the player
     } else {
         echo "Player already exist.";
         return false;
     }
 }