2024-10-04 11:52:42 +09:00
< ? php
class Character Extends Module
{
protected $_rawdata ;
2024-10-07 10:35:20 +09:00
public static function exists ( $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 true ;
} else {
return false ;
}
}
return false ;
}
public static function delete ( $character_id )
{
global $g5 ;
if ( self :: exists ( $character_id )) {
try {
$ch = self :: getImages ( $character_id );
$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 );
} 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 );
}
}
public static function getImages ( $character_id )
{
global $g5 ;
if ( isset ( $g5 [ " connect_db " ]) && isset ( $g5 [ " character_table " ])) {
$data = sql_fetch ( " SELECT ch.ch_thumb, ch.ch_head, ch.ch_body FROM { $g5 [ " character_table " ] } ch WHERE ch.ch_id = ' { $character_id } ' " );
if ( ! empty ( $data )) {
return $data ;
}
}
return [];
}
2024-10-04 11:52:42 +09:00
/**
* 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 ;
2024-10-07 10:35:20 +09:00
2024-10-04 11:52:42 +09:00
if ( isset ( $g5 [ " connect_db " ]) && isset ( $g5 [ " character_table " ])) {
$character = new Character ( $character_id );
if ( $character -> getError () === 0 ) {
2024-10-07 10:35:20 +09:00
return $character -> getLegacy ();
2024-10-04 11:52:42 +09:00
}
}
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 );
}
2024-10-07 10:35:20 +09:00
public static function getMemberID ( $character_id )
{
global $g5 ;
if ( isset ( $g5 [ " connect_db " ]) && isset ( $g5 [ " character_table " ])) {
$data = sql_fetch ( " SELECT ch.mb_id FROM { $g5 [ 'character_table' ] } ch WHERE ch.ch_id = ' { $character_id } ' " );
if ( ! empty ( $data )) {
return $data [ " mb_id " ];
} else {
return " " ;
}
}
return " " ;
}
2024-10-04 11:52:42 +09:00
/**
* 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 " ])) {
2024-10-07 10:35:20 +09:00
$this -> _rawdata = sql_fetch ( " SELECT * FROM { $g5 [ 'character_table' ] } ch WHERE ch.ch_id = ' { $character_id } ' " );
if ( ! empty ( $this -> _rawdata )) {
2024-10-04 11:52:42 +09:00
parent :: init ( $this -> _rawdata );
} else {
$this -> setError ( 2 );
}
} else {
$this -> setError ( 1 );
}
}
2024-10-07 10:35:20 +09:00
public function getLegacy ()
{
return $this -> _rawdata ;
}
2024-10-04 11:52:42 +09:00
}