309 lines
8.2 KiB
PHP
309 lines
8.2 KiB
PHP
<?php
|
|
class Character Extends Module
|
|
{
|
|
protected $_rawdata;
|
|
|
|
/**
|
|
* get character by character_id
|
|
* note?: this function may cause excessive load on the database.
|
|
* @param mixed $character_id
|
|
* @return Character|array|object|null
|
|
*/
|
|
public static function getCharacter($character_id)
|
|
{
|
|
global $g5;
|
|
if (isset($g5["connect_db"]) && isset($g5["character_table"])) {
|
|
$character = new Character($character_id);
|
|
if ($character->getError() === 0) {
|
|
return $character;
|
|
}
|
|
}
|
|
|
|
return ["error" => "DB에 연결하지 못했습니다."];
|
|
}
|
|
|
|
/**
|
|
* get character by character_id (compatilbe name for avocado)
|
|
* @param mixed $character_id
|
|
* @return Character|array|object|null
|
|
*/
|
|
public static function get_character($character_id)
|
|
{
|
|
return self::getCharacter($character_id);
|
|
}
|
|
|
|
/**
|
|
* get character by name
|
|
* @param mixed $character_name
|
|
* @return Character|null
|
|
*/
|
|
public static function getCharacterByName($character_name)
|
|
{
|
|
global $g5;
|
|
|
|
$character_name = addslashes($character_name);
|
|
$character = sql_fetch("SELECT ch_id FROM {$g5["character_table"]} WHERE ch_name = '{$character_name}'");
|
|
|
|
if ($character) {
|
|
return new Character(intval($character["ch_id"]));
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
public static function get_character_by_name($character_name)
|
|
{
|
|
return self::getCharacterByName($character_name);
|
|
}
|
|
|
|
/**
|
|
* get character name by character_id
|
|
* @param mixed $character_id
|
|
* @return string
|
|
*/
|
|
public static function getName($character_id)
|
|
{
|
|
global $g5;
|
|
if (isset($g5["connect_db"]) && isset($g5["character_table"])) {
|
|
$data = sql_fetch("SELECT ch.ch_name FROM {$g5['character_table']} ch WHERE ch.ch_id = '{$character_id}'");
|
|
if (!empty($data)) {
|
|
return $data["ch_name"];
|
|
} else {
|
|
return "캐릭터를 찾을 수 없습니다.";
|
|
}
|
|
}
|
|
|
|
return "DB에 연결하지 못했습니다.";
|
|
}
|
|
|
|
/**
|
|
* get character name by character_id (compatilbe name for avocado)
|
|
* @param mixed $character_id
|
|
* @return string
|
|
*/
|
|
public static function get_character_name($character_id)
|
|
{
|
|
return self::getName($character_id);
|
|
}
|
|
|
|
/**
|
|
* get character name by member_id
|
|
* @param mixed $member_id
|
|
* @return string
|
|
*/
|
|
public static function getNameByMemberID($member_id)
|
|
{
|
|
global $g5;
|
|
if (isset($g5["connect_db"]) && isset($g5["character_table"]) && isset($g5["member_table"])) {
|
|
$data = sql_fetch("SELECT ch.ch_name FROM {$g5["character_table"]} ch, {$g5["member_table"]} mb WHERE mb.mb_id = '{$member_id}' AND ch.mb_id = mb.mb_id");
|
|
if (!empty($data)) {
|
|
return $data["ch_name"];
|
|
} else {
|
|
return "캐릭터를 찾을 수 없습니다.";
|
|
}
|
|
}
|
|
|
|
return "DB에 연결하지 못했습니다.";
|
|
}
|
|
|
|
/**
|
|
* get character name by member_id (compatible name for avocadoedition)
|
|
* @param mixed $member_id
|
|
* @return string
|
|
*/
|
|
public static function get_member_character_name($member_id)
|
|
{
|
|
return self::getNameByMemberID($member_id);
|
|
}
|
|
|
|
public static function getInfoList($character_id)
|
|
{
|
|
global $g5;
|
|
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)) {
|
|
$info_list[$r["ar_code"]] = $r["av_value"];
|
|
}
|
|
}
|
|
|
|
return $info_list;
|
|
}
|
|
|
|
/**
|
|
* get character info (compatible name for avocadoedition)
|
|
* @param int|string $character_id
|
|
* @param string $extra_code
|
|
* @return string
|
|
*/
|
|
public static function getInfo($character_id, $extra_code)
|
|
{
|
|
global $g5;
|
|
if (isset($g5["connect_db"]) && isset($g5["character_table"]) && isset($g5["value_table"])) {
|
|
$data = sql_fetch("SELECT av_value FROM {$g5["value_table"]} WHERE ch_id = '{$character_id}' AND ar_code = '{$extra_code}'");
|
|
if (!empty($data)) {
|
|
|
|
} else {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
return "DB에 연결하지 못했습니다.";
|
|
}
|
|
|
|
/**
|
|
* get character info (compatible name for avocadoedition)
|
|
* @param int|string $character_id
|
|
* @param string $extra_code
|
|
* @return string
|
|
*/
|
|
public static function get_character_info($character_id, $extra_code)
|
|
{
|
|
return self::getInfo($character_id, $extra_code);
|
|
}
|
|
|
|
/**
|
|
* get character list
|
|
* @param string $side
|
|
* @param string $class
|
|
* @param string $state
|
|
* @return array
|
|
*/
|
|
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;
|
|
}
|
|
|
|
return $character;
|
|
}
|
|
|
|
/**
|
|
* get character list (compatible name for avocadoedition)
|
|
* @param string $side
|
|
* @param string $class
|
|
* @param string $state
|
|
* @return array
|
|
*/
|
|
public static function get_character_list($side = "", $class = "", $state = "승인")
|
|
{
|
|
return self::getList($side, $class, $state);
|
|
}
|
|
|
|
/**
|
|
* get character thumb
|
|
* @param mixed $character_id
|
|
* @return string
|
|
*/
|
|
public static function getHead($character_id)
|
|
{
|
|
global $g5;
|
|
if (isset($g5["connect_db"]) && isset($g5["character_table"])) {
|
|
$data = sql_fetch("SELECT ch.ch_thumb FROM {$g5['character_table']} ch WHERE ch.ch_id = '{$character_id}'");
|
|
if (!empty($data)) {
|
|
return $data["ch_thumb"];
|
|
} else {
|
|
return "";
|
|
}
|
|
}
|
|
|
|
return "";
|
|
}
|
|
|
|
/**
|
|
* get character thumb (compatible name for avocadoedition)
|
|
* @param mixed $character_id
|
|
* @return string
|
|
*/
|
|
public static function get_character_head($character_id)
|
|
{
|
|
return self::getHead($character_id);
|
|
}
|
|
|
|
/**
|
|
* 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 "";
|
|
}
|
|
|
|
/**
|
|
* get member name (compatible name for avocadoedition)
|
|
* @param mixed $member_id
|
|
* @return mixed
|
|
*/
|
|
public static function get_member_name($member_id)
|
|
{
|
|
return self::getMemberName($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"]
|
|
)) {
|
|
$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']}'");
|
|
}
|
|
}
|
|
}
|
|
|
|
public static function resetSearchCount()
|
|
{
|
|
global $g5, $character;
|
|
|
|
if ($character["ch_id"]) {
|
|
if ($character["ch_search_date"] != G5_TIME_YMD) {
|
|
$time = G5_TIME_YMD;
|
|
sql_query("UPDATE {$g5["character_table"]} SET ch_search = 0, ch_search_date = '{$time}' WHERE ch_id = '{$character['ch_id']}'");
|
|
$character["ch_search"] = 0;
|
|
$character["ch_search_date"] = G5_TIME_YMD;
|
|
}
|
|
}
|
|
}
|
|
|
|
public function __construct($character_id)
|
|
{
|
|
global $g5;
|
|
parent::__construct();
|
|
|
|
if (isset($g5["connect_db"]) && isset($g5["character_table"])) {
|
|
$this->_rawdata = sql_fetch("SELECT ch.ch_name FROM {$g5['character_table']} ch WHERE ch.ch_id = '{$character_id}'");
|
|
if (!empty($this->rawdata)) {
|
|
parent::init($this->_rawdata);
|
|
} else {
|
|
$this->setError(2);
|
|
}
|
|
} else {
|
|
$this->setError(1);
|
|
}
|
|
}
|
|
}
|