From 15b67c7038bd2fd456b9678194ba2f7f149c24c4 Mon Sep 17 00:00:00 2001 From: Arcturus Date: Tue, 8 Oct 2024 08:02:48 +0900 Subject: [PATCH] rework characters --- AvocadoAmber/adm/character_delete.php | 23 +- AvocadoAmber/adm/character_form_update.php | 41 +-- AvocadoAmber/adm/character_list_update.php | 28 +- AvocadoAmber/adm/couple_list.php | 5 +- AvocadoAmber/adm/couple_update.php | 27 +- AvocadoAmber/adm/exp_list_delete.php | 10 +- AvocadoAmber/adm/exp_update.php | 16 +- AvocadoAmber/adm/inventory_update.php | 14 +- AvocadoAmber/adm/title_has_list.php | 2 +- AvocadoAmber/adm/title_has_update.php | 15 +- AvocadoAmber/ajax/_search_character.php | 21 +- AvocadoAmber/ajax/_search_member.php | 2 +- .../classes/character/character.class.php | 328 +++++++++++++++--- AvocadoAmber/classes/member/member.class.php | 24 ++ AvocadoAmber/classes/module.class.php | 13 + AvocadoAmber/couple/index.php | 4 +- AvocadoAmber/extend/character.lib.php | 2 +- AvocadoAmber/extend/exp.lib.php | 7 +- AvocadoAmber/extend/rank.lib.php | 3 +- AvocadoAmber/member/closet.php | 4 +- AvocadoAmber/member/viewer.php | 2 +- .../mypage/character/character_delete.php | 31 +- .../mypage/character/character_form.php | 10 +- .../character/character_form_update.php | 48 ++- AvocadoAmber/mypage/character/index.php | 15 +- .../mypage/character/relation_update.php | 25 +- .../mypage/character/title_update.php | 7 +- AvocadoAmber/mypage/money/money_update.php | 7 +- 28 files changed, 450 insertions(+), 284 deletions(-) create mode 100644 AvocadoAmber/classes/member/member.class.php diff --git a/AvocadoAmber/adm/character_delete.php b/AvocadoAmber/adm/character_delete.php index e2a5bdd..bd6a327 100644 --- a/AvocadoAmber/adm/character_delete.php +++ b/AvocadoAmber/adm/character_delete.php @@ -4,30 +4,9 @@ include_once "./_common.php"; check_demo(); auth_check($auth[$sub_menu], "d"); -$ch = sql_fetch("select * from {$g5['character_table']} where ch_id = '{$ch_id}'"); -if (!$ch['ch_id']) { +if (!Character::delete($ch_id)) { alert("{$ch['ch_id']} : 캐릭터 자료가 존재하지 않습니다."); -} else { - - $prev_file_path = str_replace(G5_URL, G5_PATH, $ch['ch_thumb']); - @unlink($prev_file_path); - $prev_file_path = str_replace(G5_URL, G5_PATH, $ch['ch_head']); - @unlink($prev_file_path); - $prev_file_path = str_replace(G5_URL, G5_PATH, $ch['ch_body']); - @unlink($prev_file_path); - - sql_query("DELETE FROM {$g5['character_table']} where ch_id = '{$ch['ch_id']}' "); - sql_query("DELETE FROM {$g5['value_table']} where ch_id = '{$ch['ch_id']}' "); - sql_query("DELETE FROM {$g5['exp_table']} where ch_id = '{$ch['ch_id']}' "); - sql_query("DELETE FROM {$g5['title_has_table']} where ch_id = '{$ch['ch_id']}' "); - sql_query("DELETE FROM {$g5['closthes_table']} where ch_id = '{$ch['ch_id']}' "); - sql_query("DELETE FROM {$g5['inventory_table']} where ch_id = '{$ch['ch_id']}' "); - - $sql = " update {$g5['member_table']} - set ch_id = '' - where mb_id = '{$ch['mb_id']}' and ch_id = '{$ch['ch_id']}' "; - sql_query($sql); } goto_url("./character_list.php?$qstr"); diff --git a/AvocadoAmber/adm/character_form_update.php b/AvocadoAmber/adm/character_form_update.php index 85b2b74..f337eda 100644 --- a/AvocadoAmber/adm/character_form_update.php +++ b/AvocadoAmber/adm/character_form_update.php @@ -1,39 +1,6 @@ sql_insert_id()]; -} - -function update_character($ch_id, $data, $old_data) -{ - global $g5, $ad; - $sql = "UPDATE {$g5['character_table']} SET " . implode(', ', array_map(function ($k, $v) { - return "{$k} = '" . sql_real_escape_string($v) . "'"; - }, array_keys($data), $data)) . " WHERE ch_id = '" . sql_real_escape_string($ch_id) . "'"; - sql_query($sql); - - $file_fields = ['thumb', 'head', 'body']; - foreach ($file_fields as $field) { - if ($ad["ad_use_{$field}"] && !$ad["ad_url_{$field}"] && $old_data["ch_{$field}"] != $data["ch_{$field}"]) { - $prev_file_path = str_replace(G5_URL, G5_PATH, $old_data["ch_{$field}"]); - @unlink($prev_file_path); - } - } -} - -function update_member_character($mb_id, $ch_id) -{ - global $g5; - sql_query("UPDATE {$g5['member_table']} SET ch_id = '" . sql_real_escape_string($ch_id) . "' WHERE mb_id = '" . sql_real_escape_string($mb_id) . "'"); -} - function insert_default_clothes($ch_id, $ch_body) { global $g5; @@ -177,9 +144,9 @@ foreach ($file_fields as $field => $file_key) { } if ($w == '') { - $result = insert_character($character_data); + $result = Character::createFromAdminPage($character_data); $ch_id = $result['ch_id']; - update_member_character($mb['mb_id'], $ch_id); + Character::setMemberMainCharacter($mb['mb_id'], $ch_id); if (isset($character_data['ch_body'])) { insert_default_clothes($ch_id, $character_data['ch_body']); } @@ -188,8 +155,8 @@ if ($w == '') { if (!$ch['ch_id']) { alert("캐릭터 정보가 존재하지 않습니다."); } - update_character($ch_id, $character_data, $ch); - update_member_character($mb['mb_id'], $ch_id); + Character::updateFromAdminPage($ch_id, $character_data); + Character::setMemberMainCharacter($mb['mb_id'], $ch_id); if (isset($character_data['ch_body'])) { update_or_insert_default_clothes($ch_id, $character_data['ch_body']); } diff --git a/AvocadoAmber/adm/character_list_update.php b/AvocadoAmber/adm/character_list_update.php index 5cb60f0..906c291 100644 --- a/AvocadoAmber/adm/character_list_update.php +++ b/AvocadoAmber/adm/character_list_update.php @@ -17,13 +17,12 @@ if ($_POST['act_button'] == "선택수정") { if (!$ch['ch_id']) { $msg .= $ch['ch_id'] . ' : 캐릭터 자료가 존재하지 않습니다.\\n'; } else { - $sql = " update {$g5['character_table']} - set ch_type = '{$_POST['ch_type'][$k]}', - ch_side = '{$_POST['ch_side'][$k]}', - ch_class = '{$_POST['ch_class'][$k]}', - ch_state = '{$_POST['ch_state'][$k]}' - where ch_id = '{$_POST['ch_id'][$k]}' "; - sql_query($sql); + Character::update($_POST["ch_id"][$k], [ + "ch_type" => $_POST["ch_type"][$k], + "ch_side" => $_POST["ch_side"][$k], + "ch_class" => $_POST["ch_class"][$k], + "ch_state" => $_POST["ch_state"][$k] + ]); } } } else if ($_POST['act_button'] == "선택승인") { @@ -34,10 +33,9 @@ if ($_POST['act_button'] == "선택수정") { if (!$ch['ch_id']) { $msg .= $ch['ch_id'] . ' : 캐릭터 자료가 존재하지 않습니다.\\n'; } else { - $sql = " update {$g5['character_table']} - set ch_state = '승인' - where ch_id = '{$_POST['ch_id'][$k]}' "; - sql_query($sql); + Character::update($_POST["ch_id"][$k], [ + "ch_state" => "승인" + ]); } } } else if ($_POST['act_button'] == "선택삭제") { @@ -48,10 +46,10 @@ if ($_POST['act_button'] == "선택수정") { if (!$ch['ch_id']) { $msg .= $ch['ch_id'] . ' : 캐릭터 자료가 존재하지 않습니다.\\n'; } else { - $sql = " update {$g5['character_table']} - set ch_state = '삭제' - where ch_id = '{$_POST['ch_id'][$k]}' "; - sql_query($sql); + Character::update($_POST["ch_id"][$k], [ + "ch_state" => "삭제" + ]); + $sql = " update {$g5['member_table']} set ch_id = '' where mb_id = '{$ch['mb_id']}' and ch_id = '{$ch['ch_id']}' "; diff --git a/AvocadoAmber/adm/couple_list.php b/AvocadoAmber/adm/couple_list.php index aef4b2d..dfc02c0 100644 --- a/AvocadoAmber/adm/couple_list.php +++ b/AvocadoAmber/adm/couple_list.php @@ -91,8 +91,9 @@ $colspan = 5; diff --git a/AvocadoAmber/adm/couple_update.php b/AvocadoAmber/adm/couple_update.php index 1c2136f..17cad5b 100644 --- a/AvocadoAmber/adm/couple_update.php +++ b/AvocadoAmber/adm/couple_update.php @@ -9,27 +9,28 @@ auth_check($auth[$sub_menu], 'w'); check_token(); if (!$co_left && $ch_name_left) { - $ch = sql_fetch("select ch_id, ch_name, ch_exp from {$g5['character_table']} where ch_name = '{$ch_name_left}'"); - $co_left = $ch['ch_id']; - - if (!$co_left) + $ch = Character::getDetailByName($ch_name_left, ["ch_name", "ch_exp"]); + if (empty($co_left)) { alert("존재하지 않는 캐릭터 입니다."); + } } if (!$co_right && $ch_name_right) { - $ch = sql_fetch("select ch_id, ch_name, ch_exp from {$g5['character_table']} where ch_name = '{$ch_name_right}'"); - $co_right = $ch['ch_id']; - - if (!$co_right) + $ch = Character::getDetailByName($ch_name_right, ["ch_name", "ch_exp"]); + + if (empty($ch)) { alert("존재하지 않는 캐릭터 입니다."); + } } -$sql_common = " co_left = '{$_POST['co_left']}', - co_right = '{$_POST['co_right']}', - co_order = '{$_POST['co_order']}', - co_date = '{$_POST['co_date']}' "; +$sql_common = " + co_left = '{$_POST['co_left']}', + co_right = '{$_POST['co_right']}', + co_order = '{$_POST['co_order']}', + co_date = '{$_POST['co_date']}' "; -$sql = " insert into {$g5['couple_table']} +$sql = "INSERT INTO {$g5['couple_table']} set $sql_common "; + sql_query($sql); goto_url('./couple_list.php?' . $qstr); diff --git a/AvocadoAmber/adm/exp_list_delete.php b/AvocadoAmber/adm/exp_list_delete.php index f0fdca5..3d4f959 100644 --- a/AvocadoAmber/adm/exp_list_delete.php +++ b/AvocadoAmber/adm/exp_list_delete.php @@ -13,8 +13,8 @@ for ($i = 0; $i < $count; $i++) { // 실제 번호를 넘김 $k = $_POST['chk'][$i]; $ch_id = $_POST['ch_id'][$k]; - $ch = sql_fetch("select ch_id, ch_name, ch_exp, ch_rank, ch_point from {$g5['character_table']} where ch_id = '{$ch_id}'"); - + $ch = Character::getDetail($ch_id, ["ch_id", "ch_name", "ch_exp", "ch_rank", "ch_point"]); + // 포인트 내역정보 $sql = " select * from {$g5['exp_table']} where ex_id = '{$_POST['ex_id'][$k]}' "; $row = sql_fetch($sql); @@ -35,16 +35,14 @@ for ($i = 0; $i < $count; $i++) { // 포인트 UPDATE $sum_point = get_exp_sum($ch_id); - $sql = " update {$g5['character_table']} set ch_exp = '$sum_point' where ch_id = '{$ch_id}' "; - sql_query($sql); + Character::update($ch_id, ["ch_exp" => $sum_point]); $rank_info = get_rank_exp($sum_point, $ch_id); // 기존 랭크에서 변동이 있을 경우에만 실행 if ($ch['ch_rank'] != $rank_info['rank']) { $state_point = $ch['ch_point'] + $rank_info['add_point']; // 스탯 포인트 변동 사항 및 랭크 변동사항 저장 - $rank_up_sql = " update {$g5['character_table']} set ch_rank = '{$rank_info['rank']}', ch_point = '{$state_point}' where ch_id = '$ch_id' "; - sql_query($rank_up_sql); + Character::update($ch_id, ["ch_rank" => $rank_info["rank"], "ch_point" => $state_point]); } } diff --git a/AvocadoAmber/adm/exp_update.php b/AvocadoAmber/adm/exp_update.php index dc1baa6..79d5677 100644 --- a/AvocadoAmber/adm/exp_update.php +++ b/AvocadoAmber/adm/exp_update.php @@ -15,25 +15,17 @@ if ($ex_point < 0) { if ($take_type == 'A') { // 전체지급 - $sql_common = " from {$g5['character_table']} "; - $sql_search = " where ch_state = '승인' "; - $sql = " select * {$sql_common} {$sql_search} "; - $result = sql_query($sql); - - for ($i = 0; $ch = sql_fetch_array($result); $i++) { - if (($ex_point < 0) && ($ex_point * (-1) > $ch['ch_exp'])) - continue; - + foreach(Character::getList() as $chara) { + if (($ex_point < 0) && ($ex_point * (-1) > $chara['ch_exp'])) continue; insert_exp($ch['ch_id'], $ex_point, $ex_content, $action); } - } else { // 개별지급 if (!$ch_id && $ch_name) { - $ch = sql_fetch("select ch_id, ch_name, ch_exp from {$g5['character_table']} where ch_name = '{$ch_name}'"); + $ch = Character::getDetailByName($ch_name, ["ch_name", "ch_exp"]); $ch_id = $ch['ch_id']; } else { - $ch = sql_fetch("select ch_id, ch_name, ch_exp from {$g5['character_table']} where ch_id = '{$ch_id}'"); + $ch = Character::getDetail($ch_id, ["ch_name", "ch_exp"]); } if (!$ch['ch_id']) diff --git a/AvocadoAmber/adm/inventory_update.php b/AvocadoAmber/adm/inventory_update.php index 1f0f949..f9dbe6a 100644 --- a/AvocadoAmber/adm/inventory_update.php +++ b/AvocadoAmber/adm/inventory_update.php @@ -6,7 +6,6 @@ include_once './_common.php'; auth_check($auth[$sub_menu], 'w'); - check_token(); if (!$it_id && $it_name) { @@ -25,22 +24,17 @@ if (!$it_id && $it_name) { $item_count = $item_count ? $item_count : 1; if ($take_type == 'A') { - // 전체지급 - $sql_common = " from {$g5['character_table']} "; - $sql_search = " where ch_state = '승인' "; - $sql = " select ch_id, ch_name {$sql_common} {$sql_search} "; - $result = sql_query($sql); - - for ($i = 0; $ch = sql_fetch_array($result); $i++) { + $list = Character::getListDetailWithCondition(["ch_id", "ch_name"]); + foreach($list as $ch) { Item::giveItem($ch['ch_id'], $it_id, $it, $item_count, "시스템 지급"); } } else { // 개별지급 if (!$ch_id && $ch_name) { - $ch = sql_fetch("select ch_id, ch_name from {$g5['character_table']} where ch_name = '{$ch_name}'"); + $ch = Character::getDetailByName($ch_name, ["ch_name"]); $ch_id = $ch['ch_id']; } else { - $ch = sql_fetch("select ch_id, ch_name from {$g5['character_table']} where ch_id = '{$ch_id}'"); + $ch = Character::getDetail($ch_id, ["ch_name"]); } if (!$ch['ch_id']) { diff --git a/AvocadoAmber/adm/title_has_list.php b/AvocadoAmber/adm/title_has_list.php index 33d8022..ddc2d53 100644 --- a/AvocadoAmber/adm/title_has_list.php +++ b/AvocadoAmber/adm/title_has_list.php @@ -188,7 +188,7 @@ $frm_submit = '
for ($i = 0; $row = sql_fetch_array($result); $i++) { $bg = 'bg' . ($i % 2); $ti = sql_fetch("select * from {$g5['title_table']} where ti_id = '{$row['ti_id']}'"); - $ch = sql_fetch("select ch_name, ch_title from {$g5['character_table']} where ch_id = '{$row['ch_id']}'"); + $ch = Character::getDetail($row["ch_id"], ["ch_name", "ch_title"]); ?> diff --git a/AvocadoAmber/adm/title_has_update.php b/AvocadoAmber/adm/title_has_update.php index ec236c0..af19f5d 100644 --- a/AvocadoAmber/adm/title_has_update.php +++ b/AvocadoAmber/adm/title_has_update.php @@ -25,15 +25,9 @@ if (!$ti['ti_id']) { if ($take_type == 'A') { // 전체지급 - $sql_common = " from {$g5['character_table']} "; - $sql_search = " where ch_state = '승인' "; - $sql = " select ch_id, ch_name {$sql_common} {$sql_search} "; - $result = sql_query($sql); - - for ($i = 0; $ch = sql_fetch_array($result); $i++) { - + foreach(Character::getList() as $ch) { // 동일 타이틀 중복 지급 여부 체크 - $m_ti = sql_fetch("select count(*) as cnt from {$g5['title_has_table']} where ti_id = '{$ti_id}' and ch_id = '{$ch['ch_id']}'"); + $m_ti = sql_fetch("SELECT count(*) AS cnt FROM {$g5['title_has_table']} WHERE ti_id = '{$ti_id}' AND ch_id = '{$ch['ch_id']}'"); if (!$m_ti['cnt']) { $sql = " insert into {$g5['title_has_table']} @@ -41,6 +35,7 @@ if ($take_type == 'A') { ch_name = '{$ch['ch_name']}', ti_id = '{$ti['ti_id']}', hi_use = '1'"; + sql_query($sql); } } @@ -48,10 +43,10 @@ if ($take_type == 'A') { } else { // 개별지급 if (!$ch_id && $ch_name) { - $ch = sql_fetch("select ch_id, ch_name from {$g5['character_table']} where ch_name = '{$ch_name}'"); + $ch = Character::getDetailByName($ch_name, ["ch_name"]); $ch_id = $ch['ch_id']; } else { - $ch = sql_fetch("select ch_id, ch_name from {$g5['character_table']} where ch_id = '{$ch_id}'"); + $ch = Character::getDetail($ch_id, ["ch_name"]); } if (!$ch['ch_id']) diff --git a/AvocadoAmber/ajax/_search_character.php b/AvocadoAmber/ajax/_search_character.php index 8aff8c1..73c9d40 100644 --- a/AvocadoAmber/ajax/_search_character.php +++ b/AvocadoAmber/ajax/_search_character.php @@ -12,14 +12,23 @@ if (!$is_member) { } else { echo ""; diff --git a/AvocadoAmber/ajax/_search_member.php b/AvocadoAmber/ajax/_search_member.php index ae17a91..3343357 100644 --- a/AvocadoAmber/ajax/_search_member.php +++ b/AvocadoAmber/ajax/_search_member.php @@ -14,7 +14,7 @@ if (!$is_member) { $sql = " select mb_nick, mb_name, mb_id, ch_id from {$g5['member_table']} where mb_name like '%{$keyword}%' and mb_level > 1 order by mb_nick asc"; $result = sql_query($sql); for ($i = 0; $row = sql_fetch_array($result); $i++) { - $ch = sql_fetch("select ch_thumb, ch_name from {$g5['character_table']} where ch_id = '{$row['ch_id']}'"); + $ch = Character::getDetail($row['ch_id'], ["ch_thumb", "ch_name"]); ?>
  • $value) { + if (in_array($key, $columnNames)) { + $filteredData[$key] = $value; + } + } + return $filteredData; + } + + private static function prepareSetParts($filteredData) + { + $setParts = []; + foreach ($filteredData as $key => $value) { + $escapedValue = sql_real_escape_string($value); + $setParts[] = "{$key} = '{$escapedValue}'"; + } + return implode(', ', $setParts); + } + + /** + * 사용자 입력에 이 함수를 사용하지 마세요. 값 검증이 별도로 없으므로 심각한 위험을 초래할 수 있습니다. + * 단순 조회에는 기존 함수를 사용하세요. 코드의 복잡도가 증가할 수 있습니다. + * @param array $req_columns + * @param array $condition + * @return array|bool|null + */ + public static function getDetailWithCondition($req_columns = [], $condition = []) + { + global $g5; + if (!isset($g5["connect_db"]) || !isset($g5["character_table"])) { + return []; + } + + // 이름이나 id 조건이 없으면 단일 캐릭터 조회가 안 되므로 빈 값 반환 + if (!isset($condition['ch_id']) && !isset($condition['ch_name'])) { + return []; + } + + $table_columns = self::getTableColumns($g5["character_table"]); + $valid_columns = []; + if (!empty($req_columns)) { + foreach ($req_columns as $column) { + if (in_array($column, $table_columns)) { + $valid_columns[] = $column; + } + } + } + + $columns = !empty($valid_columns) ? implode(", ", $valid_columns) : "ch.ch_id"; + + $where_conditions = []; + foreach ($condition as $field => $value) { + if (is_array($value) && count($value) == 2) { + $operator = $value[1]; + $where_conditions[] = "ch.{$field} {$operator} '" . sql_real_escape_string($value[0]) . "'"; + } else { + $where_conditions[] = "ch.{$field} = '" . sql_real_escape_string($value) . "'"; + } + } + $where_clause = implode(" AND ", $where_conditions); + + $sql = "SELECT {$columns} FROM {$g5["character_table"]} ch WHERE {$where_clause} LIMIT 1"; + $result = sql_fetch($sql); + + return $result ?: []; + } + /** + * 사용자 입력에 이 함수를 사용하지 마세요. 값 검증이 별도로 없으므로 심각한 위험을 초래할 수 있습니다. + * 단순 조회에는 기존 함수를 사용하세요. 코드의 복잡도가 증가할 수 있습니다. + * @param array $req_columns + * @param array $condition + * @param array $req_order + * @return array + */ + public static function getListDetailWithCondition($req_columns = [], $condition = ["ch_state" => ["승인", "="]], $req_order = ["ch_id" => "ASC"]) + { + global $g5; + if (!isset($g5["connect_db"]) || !isset($g5["character_table"])) { + return []; + } + + $characters = []; + $table_columns = self::getTableColumns($g5["character_table"]); + + $valid_columns = []; + if (!empty($req_columns)) { + foreach ($req_columns as $column) { + if (in_array($column, $table_columns)) { + $valid_columns[] = $column; + } + } + } + $columns = !empty($valid_columns) ? implode(", ", $valid_columns) : "*"; + + // condition 설정 + $where_conditions = []; + foreach ($condition as $field => $value) { + if (in_array($field, $table_columns)) { + if (is_array($value) && count($value) == 2) { + $operator = $value[1]; + $where_conditions[] = "{$field} {$operator} '" . sql_real_escape_string($value[0]) . "'"; + } else { + $where_conditions[] = "{$field} = '" . sql_real_escape_string($value) . "'"; + } + } + } + $where_clause = implode(" AND ", $where_conditions); + + // 정렬 순서 설정 + $order_parts = []; + foreach ($req_order as $field => $direction) { + if (in_array($field, $table_columns)) { + $order_parts[] = "{$field} {$direction}"; + } + } + $order = implode(", ", $order_parts); + + // sql 생성 + $sql = "SELECT {$columns} FROM {$g5["character_table"]} WHERE {$where_clause} ORDER BY {$order}"; + $result = sql_query($sql); + + // 결과 생성 + while ($row = sql_fetch_array($result)) { + $characters[] = $row; + } + + return $characters; + } + + public static function update($character_id, $data) + { + global $g5; + + if ($character_id && (is_array($data) || is_object($data))) { + $character_id = intval($character_id); + $prepare = is_array($data) ? $data : (array) $data; + + $columnNames = self::getTableColumns($g5['character_table']); + $filteredData = self::filterData($prepare, $columnNames); + + if (!empty($filteredData)) { + $updateParts = self::prepareSetParts($filteredData); + $sql = "UPDATE {$g5['character_table']} SET {$updateParts} WHERE ch_id = '{$character_id}'"; + sql_query($sql); + } + } + } + + public static function insert($data) + { + global $g5; + + if (is_array($data) || is_object($data)) { + $prepare = is_array($data) ? $data : (array) $data; + + $columnNames = self::getTableColumns($g5['character_table']); + $filteredData = self::filterData($prepare, $columnNames); + + if (!empty($filteredData)) { + $insertParts = self::prepareSetParts($filteredData); + $sql = "INSERT INTO {$g5['character_table']} SET {$insertParts}"; + sql_query($sql); + + return sql_insert_id(); + } + } + } + public static function exists($character_id) { global $g5; @@ -30,22 +200,75 @@ class Character Extends Module @unlink($prev_file_path); $prev_file_path = str_replace(G5_URL, G5_PATH, $ch['ch_body']); @unlink($prev_file_path); - } catch(Exception $x) { + } catch (Exception $x) { } - + sql_query("DELETE FROM {$g5['character_table']} WHERE ch_id = '{$character_id}' "); sql_query("DELETE FROM {$g5['value_table']} WHERE ch_id = '{$character_id}' "); sql_query("DELETE FROM {$g5['exp_table']} WHERE ch_id = '{$character_id}' "); sql_query("DELETE FROM {$g5['title_has_table']} WHERE ch_id = '{$character_id}' "); sql_query("DELETE FROM {$g5['closthes_table']} WHERE ch_id = '{$character_id}' "); sql_query("DELETE FROM {$g5['inventory_table']} WHERE ch_id = '{$character_id}' "); - + $mb_id = self::getMemberID($character_id); - $sql = "UPDATE {$g5['member_table']} SET ch_id = '' WHERE mb_id = '{$mb_id}' AND ch_id = '{$mb_id}' "; - - sql_query($sql); + + self::setMemberMainCharacter($mb_id); + + return true; } + + return false; + } + + public static function setMemberMainCharacter($member_id, $character_id = "") + { + global $g5; + + $sql = "UPDATE {$g5['member_table']} SET ch_id = '{$character_id}' WHERE mb_id = '{$member_id}'"; + sql_query($sql); + } + + public static function createFromAdminPage($data) + { + global $g5; + $sql = "INSERT INTO {$g5['character_table']} SET " . implode(', ', array_map(function ($k, $v) { + return "{$k} = '" . sql_real_escape_string($v) . "'"; + }, array_keys($data), $data)); + sql_query($sql); + return ['ch_id' => sql_insert_id()]; + } + + public static function updateFromAdminPage($character_id, $data) + { + global $g5; + $ad = sql_fetch("SELECT * FROM {$g5['article_default_table']}"); + $ch = self::getCharacter($character_id); + + $sql = "UPDATE {$g5['character_table']} SET " . implode(', ', array_map(function ($k, $v) { + return "{$k} = '" . sql_real_escape_string($v) . "'"; + }, array_keys($data), $data)) . " WHERE ch_id = '" . sql_real_escape_string($character_id) . "'"; + sql_query($sql); + + $file_fields = ['thumb', 'head', 'body']; + foreach ($file_fields as $field) { + if ($ad["ad_use_{$field}"] && !$ad["ad_url_{$field}"] && $ch["ch_{$field}"] != $data["ch_{$field}"]) { + $prev_file_path = str_replace(G5_URL, G5_PATH, $ch["ch_{$field}"]); + @unlink($prev_file_path); + } + } + } + + public static function getDetailByName($character_name, $req_columns) + { + $character_name = sql_real_escape_string($character_name); + return self::getDetailWithCondition($req_columns, ["ch_name" => [$character_name, "="]]); + } + + public static function getDetail($character_id, $req_columns) + { + $character_id = intval($character_id); + return self::getDetailWithCondition($req_columns, ["ch_id" => [$character_id, "="]]); } public static function getImages($character_id) @@ -57,7 +280,7 @@ class Character Extends Module return $data; } } - + return []; } @@ -77,7 +300,7 @@ class Character Extends Module return $character->getLegacy(); } } - + return ["error" => "DB에 연결하지 못했습니다."]; } @@ -131,7 +354,7 @@ class Character Extends Module return "캐릭터를 찾을 수 없습니다."; } } - + return "DB에 연결하지 못했습니다."; } @@ -161,7 +384,7 @@ class Character Extends Module return "캐릭터를 찾을 수 없습니다."; } } - + return "DB에 연결하지 못했습니다."; } @@ -181,7 +404,7 @@ class Character Extends Module if (isset($g5["connect_db"]) && isset($g5["character_table"]) && isset($g5["value_table"])) { $info_list = []; $rawdata = sql_query("SELECT ar_code, av_value FROM {$g5["value_table"]} WHERE ch_id = '{$character_id}'"); - while($r = sql_fetch_array($rawdata)) { + while ($r = sql_fetch_array($rawdata)) { $info_list[$r["ar_code"]] = $r["av_value"]; } } @@ -221,6 +444,31 @@ class Character Extends Module return self::getInfo($character_id, $extra_code); } + public static function getCountByMemberID($member_id) + { + global $g5; + $member_id = intval($member_id); + + return (int) sql_fetch("SELECT count(ch_id) AS cnt FROM {$g5["character_table"]} WHERE mb_id = '{$member_id}'")["cnt"]; + } + + public static function getListByMemberID($member_id) + { + global $g5; + + $member_id = intval($member_id); + $characters = []; + + $sql = "SELECT * FROM {$g5["character_table"]} WHERE mb_id = '{$member_id}' AND ch_state != '삭제' ORDER BY ch_id ASC"; + + $res = sql_query($sql); + while ($r = sql_fetch_array($res)) { + $characters[] = $r; + } + + return $characters; + } + /** * get character list * @param string $side @@ -230,21 +478,15 @@ class Character Extends Module */ public static function getList($side = "", $class = "", $state = "승인") { - global $g5; - - $character = []; - $s = ''; - $s .= $side ? " and ch_side = '{$side}' " : ""; - $s .= $class ? " and ch_class = '{$class}' " : ""; - - $sql = "SELECT * FROM {$g5["character_table"]} WHERE ch_state = '{$state}' {$s} ORDER BY ch_id ASC"; - - $res = sql_query($sql); - while($r = sql_fetch_array($res)) { - $character[] = $r; + $condition = ["ch_state" => [$state, "="]]; + if ($side) { + $condition["ch_side"] = [$side, "="]; + } + if ($class) { + $condition["ch_class"] = [$class, "="]; } - return $character; + return self::getListDetailWithCondition([], $condition); } /** @@ -275,7 +517,7 @@ class Character Extends Module return ""; } } - + return ""; } @@ -300,27 +542,7 @@ class Character Extends Module return ""; } } - - return ""; - } - /** - * get member name - * @param mixed $member_id - * @return mixed - */ - public static function getMemberName($member_id) - { - global $g5; - if (isset($g5["connect_db"]) && isset($g5["member_table"])) { - $data = sql_fetch("SELECT mb.mb_nick FROM {$g5['member_table']} mb WHERE mb.mb_nick = '{$member_id}'"); - if (!empty($data)) { - return $data["mb_nick"]; - } else { - return ""; - } - } - return ""; } @@ -331,19 +553,21 @@ class Character Extends Module */ public static function get_member_name($member_id) { - return self::getMemberName($member_id); + return Member::getName($member_id); } public static function fixMemberCharacter() { global $g5, $is_member, $member, $character; - if (isset($g5["connect_db"]) && isset($g5["member_table"]) && isset($g5["character_table"]) && $is_member && ( - $member["mb_id"] != $character["mb_id"] || $member["ch_id"] == "" || !$character["ch_id"] - )) { + if ( + isset($g5["connect_db"]) && isset($g5["member_table"]) && isset($g5["character_table"]) && $is_member && ( + $member["mb_id"] != $character["mb_id"] || $member["ch_id"] == "" || !$character["ch_id"] + ) + ) { $character_sql = "SELECT * FROM {$g5["character_table"]} where mb_id = '{$member['mb_id']}' limit 0, 1"; $character = sql_fetch($character_sql); - + if ($character['ch_id']) { sql_query("UPDATE {$g5["member_table"]} SET ch_id = '{$character['ch_id']}' WHERE mb_id = '{$member['mb_id']}'"); } @@ -352,7 +576,7 @@ class Character Extends Module public static function resetSearchCount() { - global $g5, $character; + global $g5, $character; if ($character["ch_id"]) { if ($character["ch_search_date"] != G5_TIME_YMD) { diff --git a/AvocadoAmber/classes/member/member.class.php b/AvocadoAmber/classes/member/member.class.php new file mode 100644 index 0000000..dc95892 --- /dev/null +++ b/AvocadoAmber/classes/member/member.class.php @@ -0,0 +1,24 @@ +createdAt = microtime(true); diff --git a/AvocadoAmber/couple/index.php b/AvocadoAmber/couple/index.php index 2c3e5ec..fc8a097 100644 --- a/AvocadoAmber/couple/index.php +++ b/AvocadoAmber/couple/index.php @@ -13,8 +13,8 @@ $list = []; for ($i = 0; $co = sql_fetch_array($result); $i++) { $list[$i] = $co; - $ch_left = sql_fetch("select ch_name, ch_thumb, mb_id from {$g5['character_table']} where ch_id = '{$co['co_left']}'"); - $ch_right = sql_fetch("select ch_name, ch_thumb, mb_id from {$g5['character_table']} where ch_id = '{$co['co_right']}'"); + $ch_left = Character::getDetail($co['co_left'], ["ch_name", "ch_thumb", "mb_id"]); + $ch_right = Character::getDetail($co['co_right'], ["ch_name", "ch_thumb", "mb_id"]); $ch_left['ch_name'] = explode(' ', $ch_left['ch_name']); $ch_left['ch_name'] = $ch_left['ch_name'][0]; diff --git a/AvocadoAmber/extend/character.lib.php b/AvocadoAmber/extend/character.lib.php index 6999cc8..160ed43 100644 --- a/AvocadoAmber/extend/character.lib.php +++ b/AvocadoAmber/extend/character.lib.php @@ -90,7 +90,7 @@ function get_character_head($ch_id) function get_member_name($mb_id) { - return Character::getMemberName($mb_id); + return Member::getName($mb_id); } function get_character($ch_id) diff --git a/AvocadoAmber/extend/exp.lib.php b/AvocadoAmber/extend/exp.lib.php index 54e3170..5dc6c60 100644 --- a/AvocadoAmber/extend/exp.lib.php +++ b/AvocadoAmber/extend/exp.lib.php @@ -41,18 +41,15 @@ function insert_exp($ch_id, $exp, $content = '', $rel_action = '') sql_query($sql); // 경험치 UPDATE - $sql = " update {$g5['character_table']} set ch_exp = '$ex_ch_exp' where ch_id = '$ch_id' "; - sql_query($sql); + Character::update($ch_id, ["ch_exp" => intval($ex_ch_exp)]); $rank_info = get_rank_exp($ex_ch_exp, $ch_id); // 기존 랭크에서 변동이 있을 경우에만 실행 if ($ch['ch_rank'] != $rank_info['rank']) { - $state_point = $ch['ch_point'] + $rank_info['add_point']; // 스탯 포인트 변동 사항 및 랭크 변동사항 저장 - $rank_up_sql = " update {$g5['character_table']} set ch_rank = '{$rank_info['rank']}', ch_point = '{$state_point}' where ch_id = '$ch_id' "; - sql_query($rank_up_sql); + Character::update($ch_id, ["ch_rank" => $rank_info['rank'], "ch_point" => $state_point]); } return 1; diff --git a/AvocadoAmber/extend/rank.lib.php b/AvocadoAmber/extend/rank.lib.php index 8320aa3..d3e6c07 100644 --- a/AvocadoAmber/extend/rank.lib.php +++ b/AvocadoAmber/extend/rank.lib.php @@ -28,7 +28,8 @@ function get_rank_exp($exp, $ch_id) global $g5; $result = []; - $ch = sql_fetch("SELECT ch_rank FROM {$g5['character_table']} where ch_id = '{$ch_id}'"); + $ch = Character::getDetail($ch_id, ["ch_rank"]); + $ch_rank = sql_fetch("SELECT * FROM {$g5['level_table']} where lv_id = '{$ch['ch_rank']}'"); $level = sql_fetch("SELECT * FROM {$g5['level_table']} where lv_exp <= {$exp} ORDER BY lv_exp DESC limit 0, 1"); diff --git a/AvocadoAmber/member/closet.php b/AvocadoAmber/member/closet.php index 65c41ae..5344750 100644 --- a/AvocadoAmber/member/closet.php +++ b/AvocadoAmber/member/closet.php @@ -1,6 +1,8 @@ $config['cf_character_count']) { + if ($ch > $config['cf_character_count']) { alert("생성 가능한 캐릭터 갯수를 초과하였습니다.", "./index.php"); } + $ch = []; + $ch['ch_state'] = '수정중'; $ch['ch_type'] = 'main'; $ch['mb_id'] = $member['mb_id']; $ch['ch_point'] = $config['cf_status_point']; } else { - $ch = sql_fetch("select * from {$g5['character_table']} where ch_id = '{$ch_id}'"); + $ch = Character::getCharacter($ch_id); if (empty($ch)) { alert("캐릭터 내역이 존재하지 않습니다."); } + if (!$is_mod_character && !$is_admin) { if ($in['ch_id'] != $ch['ch_id'] || $in['it_type'] != '프로필수정') { alert("캐릭터 수정 기간이 아닙니다."); diff --git a/AvocadoAmber/mypage/character/character_form_update.php b/AvocadoAmber/mypage/character/character_form_update.php index 2581a36..911867e 100644 --- a/AvocadoAmber/mypage/character/character_form_update.php +++ b/AvocadoAmber/mypage/character/character_form_update.php @@ -25,25 +25,22 @@ $character_image_url = G5_DATA_URL . "/character/" . $mb_id; @mkdir($character_image_path, G5_DIR_PERMISSION); @chmod($character_image_path, G5_DIR_PERMISSION); - -$sql_article = ""; - // 기본 데이터 등록 $ad = sql_fetch("select * from {$g5['article_default_table']}"); -$sql_article .= " - ch_state = '{$ch_state}', - ch_type = '{$ch_type}', - mb_id = '{$mb_id}', - ch_side = '{$ch_side}', - ch_class = '{$ch_class}', - ch_name = '{$ch_name}', - ch_point = '{$ch_point}' -"; + +$sql_data = [ + "ch_state" => $ch_state, + "ch_type" => $ch_type, + "mb_id" => $mb_id, + "ch_side" => $ch_side, + "ch_class" => $ch_class, + "ch_name" => $ch_name, + "ch_point" => $ch_point +]; // 이미지 등록 // -- 두상 if ($ad['ad_use_thumb']) { - if ($_FILES['ch_thumb_file']['name']) { // 확장자 따기 $exp = explode(".", $_FILES['ch_thumb_file']['name']); @@ -63,7 +60,7 @@ if ($ad['ad_use_thumb']) { } } - $sql_article .= " , ch_thumb = '{$ch_thumb}'"; + $sql_data["ch_thumb"] = $ch_thumb; } // -- 흉상 if ($ad['ad_use_head']) { @@ -86,7 +83,7 @@ if ($ad['ad_use_head']) { } } - $sql_article .= " , ch_head = '{$ch_head}'"; + $sql_data["ch_head"] = $ch_head; } // -- 전신 if ($ad['ad_use_body']) { @@ -108,17 +105,17 @@ if ($ad['ad_use_body']) { alert("이미지 경로가 올바르지 않습니다."); } } - $sql_article .= " , ch_body = '{$ch_body}'"; + + $sql_data["ch_body"] = $ch_body; } if ($w == '') { - $sql = " insert into {$g5['character_table']} set {$sql_article}"; - sql_query($sql); + $ch_id = Character::insert($sql_data); - $ch_id = sql_insert_id(); - if ($mb['ch_id'] == "") + if ($mb['ch_id'] == "") { sql_query("update {$g5['member_table']} set ch_id = '{$ch_id}' where mb_id = '{$mb['mb_id']}'"); + } if ($ch_body) { $sql = " insert into {$g5['closthes_table']} @@ -133,7 +130,7 @@ if ($w == '') { } else { // 기존 캐릭터 데이터 호출 - $ch = get_character($ch_id); + $ch = Character::getCharacter($ch_id); if (!$ch['ch_id']) alert("캐릭터 정보가 존재하지 않습니다."); @@ -155,11 +152,7 @@ if ($w == '') { @unlink($prev_file_path); } - - $sql = " update {$g5['character_table']} - set {$sql_article} - where ch_id = '{$ch_id}'"; - sql_query($sql); + Character::update($ch_id, $sql_data); if ($mb['ch_id'] == "") sql_query("update {$g5['member_table']} set ch_id = '{$ch_id}' where mb_id = '{$mb['mb_id']}'"); @@ -272,5 +265,4 @@ if ($in_id && !$in['it_use_ever']) { delete_inventory($in_id); } -goto_url('./viewer.php?ch_id=' . $ch_id, false); -?> +goto_url('./viewer.php?ch_id=' . $ch_id); diff --git a/AvocadoAmber/mypage/character/index.php b/AvocadoAmber/mypage/character/index.php index f2f8897..2e61eb4 100644 --- a/AvocadoAmber/mypage/character/index.php +++ b/AvocadoAmber/mypage/character/index.php @@ -2,17 +2,9 @@ include_once './_common.php'; include_once './_head.php'; -$ch_array = []; -$character_result = sql_query("select * from {$g5['character_table']} where mb_id = '{$member['mb_id']}' and ch_state != '삭제'"); -for ($i = 0; $row = sql_fetch_array($character_result); $i++) { - $ch_array[$i] = $row; -} +$ch_array = Character::getListByMemberID($member['mb_id']); -if ($i == 1) { - //goto_url('./viewer.php?ch_id='.$ch_array[0]['ch_id']); -} ?> -
    @@ -34,8 +26,8 @@ if ($i == 1) { - + + @@ -43,7 +35,6 @@ if ($i == 1) {
    -
    getLegacy() : []; $_POST['re_ch_id'] = $re_ch['ch_id']; } - $sql = " insert into {$g5['relation_table']} - set ch_id = '{$_POST['ch_id']}', - re_ch_id = '{$_POST['re_ch_id']}', - rm_like = '{$_POST['rm_like']}', - rm_link = '{$_POST['rm_link']}', - rm_order = '{$_POST['rm_order']}', - rm_memo = '{$_POST['rm_memo']}'"; - sql_query($sql); - + if (isset($re_ch['ch_id'])) { + $sql = " insert into {$g5['relation_table']} + set ch_id = '{$_POST['ch_id']}', + re_ch_id = '{$_POST['re_ch_id']}', + rm_like = '{$_POST['rm_like']}', + rm_link = '{$_POST['rm_link']}', + rm_order = '{$_POST['rm_order']}', + rm_memo = '{$_POST['rm_memo']}'"; + sql_query($sql); + } } else if ($w == 'u') { // 수정사항 $sql = " update {$g5['relation_table']} @@ -32,7 +34,6 @@ if ($w == '') { where rm_id = '{$_POST['rm_id']}' "; sql_query($sql); - } goto_url('./viewer.php?ch_id=' . $ch_id); diff --git a/AvocadoAmber/mypage/character/title_update.php b/AvocadoAmber/mypage/character/title_update.php index bda2359..1a049af 100644 --- a/AvocadoAmber/mypage/character/title_update.php +++ b/AvocadoAmber/mypage/character/title_update.php @@ -1,7 +1,6 @@ $ti_id]); + echo "Y"; diff --git a/AvocadoAmber/mypage/money/money_update.php b/AvocadoAmber/mypage/money/money_update.php index 044801f..d494c0f 100644 --- a/AvocadoAmber/mypage/money/money_update.php +++ b/AvocadoAmber/mypage/money/money_update.php @@ -8,11 +8,12 @@ if ($point > 0) { alert("소지" . $config['cf_money'] . " 보다 많은 " . $config['cf_money'] . j($config['cf_money'], '은') . " 보낼 수 없습니다."); } if (!$ch_id) { - $re_ch = sql_fetch("select * from {$g5['character_table']} where ch_name = '{$ch_name}'"); + $re_ch = Character::getCharacterByName($ch_name); } else { - $re_ch = get_character($ch_id); + $re_ch = Character::getCharacter($ch_id); } - $recv_name = get_member_name($re_ch['mb_id']); + + $recv_name = Member::getName($re_ch['mb_id']); if (!$recv_name) { alert("상대를 확인할 수 없습니다.");