diff --git a/myaccount.php b/myaccount.php index 22e3c21..dcc8a0b 100644 --- a/myaccount.php +++ b/myaccount.php @@ -1,52 +1,6 @@ shop!"; -} -// end -// Change character sex -if (!empty($_POST['change_gender'])) { - if (!Token::isValid($_POST['token'])) { - exit(); - } - if (user_character_account_id($_POST['change_gender']) === $session_user_id) { - $char_name = sanitize($_POST['change_gender']); - $char_id = (int)user_character_id($char_name); - $account_id = user_character_account_id($char_name); - - if ($config['TFSVersion'] == 'TFS_10') { - $chr_data = user_is_online_10($char_id); - } else $chr_data = user_character_data($char_id, 'online'); - - if ($chr_data['online'] != 1) { - // Verify that we are not messing around with data - if ($account_id != $user_data['id']) die("wtf? Something went wrong, try relogging."); - - // Fetch character tickets - $tickets = shop_account_gender_tickets($account_id); - if ($tickets !== false || $config['free_sex_change'] == true) { - // They are allowed to change gender - $last = false; - $infinite = false; - $tks = 0; - // Do we have any infinite tickets? - foreach ($tickets as $ticket) { - if ($ticket['count'] == 0) $infinite = true; - else if ($ticket > 0 && $infinite === false) $tks += (int)$ticket['count']; +// Handle POST +if (!empty($_POST['selected_character'])) { + if (!empty($_POST['action'])) { + // Validate token + if (!Token::isValid($_POST['token'])) { + exit(); + } + // Sanitize values + $action = getValue($_POST['action']); + $char_name = getValue($_POST['selected_character']); + + // Handle actions + switch($action) { + // Change character comment PAGE2 (Success). + case 'update_comment': + if (user_character_account_id($char_name) === $session_user_id) { + user_update_comment(user_character_id($char_name), getValue($_POST['comment'])); + echo 'Successfully updated comment.'; } - if ($infinite === true) $tks = 0; - $dbid = (int)$tickets[0]['id']; - // If they dont have unlimited tickets, remove a count from their ticket. - if ($tickets[0]['count'] > 1) { // Decrease count - $tks--; - $tkr = ((int)$tickets[0]['count'] - 1); - shop_update_row_count($dbid, $tkr); - } else if ($tickets[0]['count'] == 1) { // Delete record - shop_delete_row_order($dbid); - $tks--; + break; + // end + // Hide character + case 'toggle_hide': + $hide = (user_character_hide($char_name) == 1 ? 0 : 1); + if (user_character_account_id($char_name) === $session_user_id) { + user_character_set_hide(user_character_id($char_name), $hide); } - - // Change character gender: - // - user_character_change_gender($char_name); - echo 'You have successfully changed gender on character '. $char_name .'.'; - if ($tks > 0) echo '
You have '. $tks .' gender change tickets left.'; - else if ($infinite !== true) echo '
You are out of tickets.'; - } else echo 'You don\'t have any character gender tickets, buy them in the SHOP!'; - } else echo 'Your character must be offline.'; + break; + // end + // DELETE character + case 'delete_character': + if (user_character_account_id($char_name) === $session_user_id) { + $charid = user_character_id($char_name); + if ($charid !== false) { + if ($config['TFSVersion'] === 'TFS_10') { + if (!user_is_online_10($charid)) { + if (guild_leader_gid($charid) === false) user_delete_character_soft($charid); + else echo 'Character is leader of a guild, you must disband the guild or change leadership before deleting character.'; + } else echo 'Character must be offline first.'; + } else { + $chr_data = user_character_data($charid, 'online'); + if ($chr_data['online'] != 1) { + if (guild_leader_gid($charid) === false) user_delete_character_soft($charid); + else echo 'Character is leader of a guild, you must disband the guild or change leadership before deleting character.'; + } else echo 'Character must be offline first.'; + } + } + } + break; + // end + // CHANGE character name + case 'change_name': + $oldname = $char_name; + $newname = getValue($_POST['newName']); + + // Check if user is online + $player = false; + if ($config['TFSVersion'] === 'TFS_10') { + $player = mysql_select_single("SELECT `id`, `account_id` FROM `players` WHERE `name` = '$oldname'"); + $player['online'] = (user_is_online_10($player['id'])) ? 1 : 0; + } else $player = mysql_select_single("SELECT `id`, `account_id`, `online` FROM `players` WHERE `name` = '$oldname'"); + + // Check if player has bough ticket + $order = mysql_select_single("SELECT `id`, `account_id` FROM `znote_shop_orders` WHERE `type`='4' LIMIT 1;"); + if ($order !== false) { + // Check if player and account matches + if ($session_user_id == $player['account_id'] && $session_user_id == $order['account_id']) { + // Check if new name is not occupied + $exist = mysql_select_single("SELECT `id` FROM `players` WHERE `name`='$newname';"); + if (!$exist) { + // Check if new name follow rules + $newname = validate_name($newname); + if ($newname !== false) { + $error = false; + // name restriction + $resname = explode(" ", $_POST['name']); + foreach($resname as $res) { + if(in_array(strtolower($res), $config['invalidNameTags'])) { + $error = true; + } + else if(strlen($res) == 1) { + $error = true; + } + } + // Check name for illegal characters. + function checkNewNameForIllegal($name) { + if (preg_match('#^[\0-9åäö&()+%/*$€é,.\'"-]*$#i', $name)) { + return true; + } + return false; + } + if (checkNewNameForIllegal($newname)) { + $error = true; + echo 'This name contains illegal characters.'; + } + if ($error === false) { + // Change the name! + mysql_update("UPDATE `players` SET `name`='$newname' WHERE `id`='".$player['id']."' LIMIT 1;"); + mysql_delete("DELETE FROM `znote_shop_orders` WHERE `id`='".$order['id']."' LIMIT 1;"); + } + } else echo 'Name validation failed, use another name.'; + } else echo 'The character name you wish to change to already exist.'; + } else echo 'Failed to sync your account. :|'; + } else echo 'Did not find any name change tickets, but them in our shop!'; + break; + // end + // Change character sex + case 'change_gender': + if (user_character_account_id($char_name) === $session_user_id) { + $char_id = (int)user_character_id($char_name); + $account_id = user_character_account_id($char_name); + + if ($config['TFSVersion'] == 'TFS_10') { + $chr_data = user_is_online_10($char_id); + } else $chr_data = user_character_data($char_id, 'online'); + + if ($chr_data['online'] != 1) { + // Verify that we are not messing around with data + if ($account_id != $user_data['id']) die("wtf? Something went wrong, try relogging."); + + // Fetch character tickets + $tickets = shop_account_gender_tickets($account_id); + if ($tickets !== false || $config['free_sex_change'] == true) { + // They are allowed to change gender + $last = false; + $infinite = false; + $tks = 0; + // Do we have any infinite tickets? + foreach ($tickets as $ticket) { + if ($ticket['count'] == 0) $infinite = true; + else if ($ticket > 0 && $infinite === false) $tks += (int)$ticket['count']; + } + if ($infinite === true) $tks = 0; + $dbid = (int)$tickets[0]['id']; + // If they dont have unlimited tickets, remove a count from their ticket. + if ($tickets[0]['count'] > 1) { // Decrease count + $tks--; + $tkr = ((int)$tickets[0]['count'] - 1); + shop_update_row_count($dbid, $tkr); + } else if ($tickets[0]['count'] == 1) { // Delete record + shop_delete_row_order($dbid); + $tks--; + } + + // Change character gender: + // + user_character_change_gender($char_name); + echo 'You have successfully changed gender on character '. $char_name .'.'; + if ($tks > 0) echo '
You have '. $tks .' gender change tickets left.'; + else if ($infinite !== true) echo '
You are out of tickets.'; + } else echo 'You don\'t have any character gender tickets, buy them in the SHOP!'; + } else echo 'Your character must be offline.'; + } + break; + // end + // Change character comment PAGE1: + case 'change_comment': + $render_page = false; // Regular "myaccount" page should not render + if (user_character_account_id($char_name) === $session_user_id) { + $comment_data = user_znote_character_data(user_character_id($char_name), 'comment'); + ?> + +

Change comment on:

+
+ +
+ - -

Change comment on:

-
- -
- new DateTime()) echo 'CAUTION! Your character with name ' . $delete['character_name'] . ' will be deleted on ' . $delete['time'] . '. Cancel this operation.
'; @@ -216,6 +218,8 @@ if (!empty($_POST['selected_comment'])) { $char_count--; } } + } + ?>

My account

@@ -223,7 +227,6 @@ if (!empty($_POST['selected_comment'])) { You have days remaining premium account.

Character List: characters.

- -
- -
- -
- -
- -
- -
- -
- -
- -
- -
- - - create one?'; - } - //Done. + ?> + + + + + + + + + + + + + create one?'; } ?>
+ + +