head	1.2;
access;
symbols;
locks; strict;
comment	@# @;


1.2
date	2004.12.05.03.17.52;	author comfuture;	state Exp;
branches;
next	1.1;

1.1
date	2004.11.24.12.25.15;	author comfuture;	state Exp;
branches;
next	;


desc
@@


1.2
log
@3ȸ ڵ佺Ʈ ۾
@
text
@<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
/**
* 파일명: RPC/index.php
* 작성일: 2004-10-25
* 작성자: 거친마루
* 설  명: XML_RPC 서버 
*****************************************************************
* 
*/

require_once "XML/RPC/Server.php";
header('Content-type: text/xml');

$SERVER = new XML_RPC_Server(
	array(
		'hello' => array('function'=>'hello'),
		'test.hello' => array('function'=>'hello'),
		'server.list' => array('function'=>'server_list'),
		'news.summery' => array('function' => 'news_summery'),
		'auth.login' => array('function' => 'auth_login'),
		'user.info' => array('function' => 'user_info')
	),
	true
);

// {{{ Methods

function hello($params) {
	$p = $params->getParam(0);
	$name = $p->scalarval();
	return new XML_RPC_Response(new XML_RPC_Value('Hello, '.$name,'string'));
}

function server_list($params) {
	return new XML_RPC_Response(
		new XML_RPC_Value(array(
			new XML_RPC_Value('server1.simin.h-9.net'),
			new XML_RPC_Value('server2.simin.h-9.net'),
			new XML_RPC_Value('server3.simin.h-9.net')
		),'array')
	);
}

function news_summery($params) {
	/*
	$arr = array();
	for ($i = 3; $i >= 1; $i--) {
		$arr[] = array(
			'url' => 'http://simin.h-9.net/?act=news.read&id='.$i,
			'date' => date("Y-m-d H:i:s"),
			'title' => $i.' 번째 테스트 뉴스입니다',
			'content' => "조만장자 마이더스, 시민쾌걸Online에 기부금 100억 투척!!!\r\n세상에 이럴수가... 명색이 시민쾌걸을 빛내는 게임인데, 펭돌이 용돈보다도 적은 액수를 내놓다니...\r\n게임 제작에 참여한 사람들은 끝내 오열을 참지 못하며 분개했다..."
		);
	}
	*/

	require_once "lib/class.DB.php";
	$DB = DB::Connection(getConnectionString());

	$data = $DB->sqlFetchAll("
		SELECT
			idx, reg_date date, title, content
		FROM
			simin_news
		ORDER BY
			reg_date DESC
		LIMIT 3
	",MYSQL_ASSOC);
	@@array_walk($data,'cb_format_news');
	$response = new XML_RPC_Response(XML_RPC_encode($data));
	return $response;
}

function auth_login($params) {
	$p1 = $params->getParam(0);
	$p2 = $params->getParam(1);
	if ($p1) $user = $p1->scalarval();
	if ($p2) $pass = $p2->scalarval();

	if (!$user || !$pass) {
		$msg = array(
			'code' => '01',
			'message' => 'Error! some parameter is not valid'
		);
		return new XML_RPC_Response(XML_RPC_encode($msg));
	} else {
		require_once "lib/class.DB.php";
		$DB = DB::Connection(getConnectionString());
		$cnt = $DB->sqlFetchOne("
			SELECT
				COUNT(*)
			FROM
				simin_user
			WHERE
				user='$user' AND pass='$pass'
		");
		if ($cnt > 0) {
			$msg = array(
				'code' => '00',
				'message' => 'Success'
			);
		} else {
			$msg = array(
				'code' => '02',
				'message' => 'No such user'
			);
		}
		return new XML_RPC_Response(XML_RPC_encode($msg));
	}
}

function user_info($params) {
	$p1 = $params->getParam(0);
	if ($p1) $user = $p1->scalarval();

	require_once "lib/class.DB.php";
	$DB = DB::Connection(getConnectionString());
	$DB->config['fetch_mode'] = MYSQL_ASSOC;

	$info = $DB->sqlFetch("
		SELECT
			*
		FROM
			simin_user
		WHERE
			simin_user.user = '$user'
	");

	return new XML_RPC_Response(XML_RPC_encode($info));
}


/**
* string getConnectionString(void)
* 
* 설정파일에서 db connection을 만들어 리턴합니다.
* 
*/
function getConnectionString($dsn='default') {
	$conf = @@parse_ini_file('conf/database.conf.php',true);
	$str = $conf[$dsn]['dbms'].'://'.$conf[$dsn]['user'].':'.$conf[$dsn]['pass'].'@@'.$conf[$dsn]['host'].'/'.$conf[$dsn]['db'];
	return $str;
}

//==-- callbacks --==//
function cb_format_news(&$arr) {
	$arr['url'] = 'http://simin.h-9.net/?act=news.read&id='.$arr['idx'];
	$arr['content'] = preg_replace('/\s+/',' ',strip_tags($arr['content']));
//	$arr['content'] = mb_substr($arr['content'],0,10);
	unset($arr['idx']);	// cleanup junk keys..
}
// }}}
?>
두의 결과를 한번에 기록할것인가
function game_putscore($params) {
	$p0 = $params->getParam(0);
	$p1 = $params->getParam(1);

	$user = $p0->scalarval();
	$userid = $p1->scalarval();
	
	// TODO: 게임 결과 기록 (게임머니, 이벤트로그 업데이트, 랭킹 (가끔) 업데이트)
}

// 게임 랭킹 얻어오기
function game_getrank($params) {
	$p0 = $params->getParam(0);
	$p1 = $params->getParam(1);

	$offset = $p0->scalarval();
	$num = $p1->scalarval();

	$DB = DB::Connection(getConnectionString());
	
	$sql = "
		SELECT
			*
		FROM
			simin_rank
		ORDER BY
			rank
		LIMIT $offset, $num
	";

	if ($list = $DB->sqlFetchAll($sql)) {
		return new XML_RPC_Response(XML_RPC_encode($list));
	} else {
		return new XML_RPC_Response(XML_RPC_encode(array(
				'code' => '05',
				'message' => 'Rank is Empty'
		)));
	}
}

// gc
function game_cleanup($params) {
	// 룸 정보 클린업
	return new XML_RPC_Response(XML_RPC_encode(true));
}

// }}}

/**
* string getConnectionString(void)
* 
* 설정파일에서 db connection을 만들어 리턴합니다.
* 
*/
function getConnectionString($dsn='default') {
	$conf = @@parse_ini_file('conf/database.conf.php',true);
	$str = $conf[$dsn]['dbms'].'://'.$conf[$dsn]['user'].':'.$conf[$dsn]['pass'].'@@'.$conf[$dsn]['host'].'/'.$conf[$dsn]['db'];
	return $str;
}
// }}}
?>
@


1.1
log
@ù Ʈ
@
text
@d1 169
a169 10
<?php
/* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
/**
* 파일명: RPC/index.php
* 작성일: 2004-10-25
* 작성자: 거친마루
* 설  명: XML_RPC 서버 
*****************************************************************
* 
*/
d171 2
a172 2
require_once "XML/RPC/Server.php";
header('Content-type: text/xml');
a173 44
$SERVER = new XML_RPC_Server(
	array(
		'hello' => array('function'=>'hello'),
		'test.hello' => array('function'=>'hello'),
		'server.list' => array('function'=>'server_list'),
		'news.summery' => array('function' => 'news_summery'),
		'auth.login' => array('function' => 'auth_login'),
		'user.info' => array('function' => 'user_info')
	),
	true
);

// {{{ Methods

function hello($params) {
	$p = $params->getParam(0);
	$name = $p->scalarval();
	return new XML_RPC_Response(new XML_RPC_Value('Hello, '.$name,'string'));
}

function server_list($params) {
	return new XML_RPC_Response(
		new XML_RPC_Value(array(
			new XML_RPC_Value('server1.simin.h-9.net'),
			new XML_RPC_Value('server2.simin.h-9.net'),
			new XML_RPC_Value('server3.simin.h-9.net')
		),'array')
	);
}

function news_summery($params) {
	/*
	$arr = array();
	for ($i = 3; $i >= 1; $i--) {
		$arr[] = array(
			'url' => 'http://simin.h-9.net/?act=news.read&id='.$i,
			'date' => date("Y-m-d H:i:s"),
			'title' => $i.' 번째 테스트 뉴스입니다',
			'content' => "조만장자 마이더스, 시민쾌걸Online에 기부금 100억 투척!!!\r\n세상에 이럴수가... 명색이 시민쾌걸을 빛내는 게임인데, 펭돌이 용돈보다도 적은 액수를 내놓다니...\r\n게임 제작에 참여한 사람들은 끝내 오열을 참지 못하며 분개했다..."
		);
	}
	*/

	require_once "lib/class.DB.php";
d175 2
a176 2

	$data = $DB->sqlFetchAll("
d178 1
a178 1
			idx, reg_date date, title, content
d180 1
a180 1
			simin_news
d182 3
a184 7
			reg_date DESC
		LIMIT 3
	",MYSQL_ASSOC);
	@@array_walk($data,'cb_format_news');
	$response = new XML_RPC_Response(XML_RPC_encode($data));
	return $response;
}
d186 2
a187 12
function auth_login($params) {
	$p1 = $params->getParam(0);
	$p2 = $params->getParam(1);
	if ($p1) $user = $p1->scalarval();
	if ($p2) $pass = $p2->scalarval();

	if (!$user || !$pass) {
		$msg = array(
			'code' => '01',
			'message' => 'Error! some parameter is not valid'
		);
		return new XML_RPC_Response(XML_RPC_encode($msg));
d189 4
a192 22
		require_once "lib/class.DB.php";
		$DB = DB::Connection(getConnectionString());
		$cnt = $DB->sqlFetchOne("
			SELECT
				COUNT(*)
			FROM
				simin_user
			WHERE
				user='$user' AND pass='$pass'
		");
		if ($cnt > 0) {
			$msg = array(
				'code' => '00',
				'message' => 'Success'
			);
		} else {
			$msg = array(
				'code' => '02',
				'message' => 'No such user'
			);
		}
		return new XML_RPC_Response(XML_RPC_encode($msg));
d196 4
a199 18
function user_info($params) {
	$p1 = $params->getParam(0);
	if ($p1) $user = $p1->scalarval();

	require_once "lib/class.DB.php";
	$DB = DB::Connection(getConnectionString());
	$DB->config['fetch_mode'] = MYSQL_ASSOC;

	$info = $DB->sqlFetch("
		SELECT
			*
		FROM
			simin_user
		WHERE
			simin_user.user = '$user'
	");

	return new XML_RPC_Response(XML_RPC_encode($info));
d202 1
a214 8

//==-- callbacks --==//
function cb_format_news(&$arr) {
	$arr['url'] = 'http://simin.h-9.net/?act=news.read&id='.$arr['idx'];
	$arr['content'] = preg_replace('/\s+/',' ',strip_tags($arr['content']));
//	$arr['content'] = mb_substr($arr['content'],0,10);
	unset($arr['idx']);	// cleanup junk keys..
}
@

