搜索
查看: 2429|回复: 1

解读Psychostats 3.1 排名系统代码(斑竹++)

[复制链接]
发表于 2008-9-9 09:54:02 | 显示全部楼层 |阅读模式 来自 中国–辽宁–本溪
解读Psychostats 3.1 排名系统代码(adong)
2008年09月09日 星期二 09:03

一,程序初始化
1,\stats\index.asp
1 define("PSYCHOSTATS_PAGE", true);
2 include(dirname(__FILE__) . "/includes/common.php");
3 $cms->init_theme($ps->conf['main']['theme'], $ps->conf['theme']);
4 $ps->theme_setup($cms->theme);
5 $cms->theme->page_title('PsychoStats - Player Stats');
2,\stats\includes\common.php
$ps = PsychoStats::create(array(
'fatal'   => 0,
'dbtype' => $dbtype,
'dbhost' => $dbhost,
'dbport' => $dbport,
'dbname' => $dbname,
'dbuser' => $dbuser,
'dbpass' => $dbpass,
'dbtblprefix' => $dbtblprefix
));
PsychoStats是\stats\includes\class_PS.php
3\stats\includes\class_PS.php
/* 以下代码:通过工厂模式实例化一个数据库类 */
if (isset($dbconf['dbhandle'])) {
   $db =& $dbconf['dbhandle'];
} else {
   require_once(dirname(__FILE__) . "/class_DB.php");
   $db = PsychoDB::create($dbconf);
}
/* 以下代码:通过sql语句从数据库中读取ps_config,获得游戏类型,比如halflife还是cstrike,还是其它,加载对应的类(ps目录下),
如果是cstrike就加载ps\hallife\cstrike.php;如果是dod就加载ps\hallife\dod.php;
...
如果是halflife引擎就加载ps\halflife.php
如果不是halflife引擎就加载ps\PS.php
*/
$cmd = "SELECT value FROM " . $db->dbtblprefix . "config WHERE conftype='main' AND section IS NULL AND ";
if (!$gametype and !$modtype) {
   $cmd .= "var IN ('gametype', 'modtype') ORDER BY var";
   list($gametype,$modtype) = $db->fetch_list($cmd);
} elseif (!$gametype) {
   $cmd .= "var='gametype'";
   list($gametype) = $db->fetch_list($cmd);
} elseif (!$modtype) {
   $cmd .= "var='modtype'";
   list($modtype) = $db->fetch_list($cmd);
}
/*   以下代码: 实例化ps类 */
if (!$class) {
   include_once('PS' . DIRECTORY_SEPARATOR . 'PS.php');
   $class = 'PS';
}
$obj =& new $class($db);
4,\stats\includes\PS\PS.PHP
/*   以下代码: 初始化ps类变量 */
$this->t_weapon    = $this->tblprefix . 'weapon';
$this->t_weapon_data    = $this->tblprefix . 'weapon_data';
/*   以下代码: 从数据库ps_config装载配置 */
// load our main config ...
$this->load_config(array('main','theme','info'));
$this->tblsuffix = '_' . $this->conf['main']['gametype'] . '_' . $this->conf['main']['modtype'];
5,\stats\includes\PS\PS.PHP function load_config($type)
/*    以下代码: 从数据库执行 SELECT conftype,section,var,value FROM ps_config WHERE var IS NOT NULL AND conftype IN ('main', 'theme', 'info'),并将查询结果分配到$ps->conf[]数组中,于是就有了 $ps->conf['main']数组,$ps->conf['theme']数组,$ps->conf['info']数组,3个数组是以查询结果的第2,3列值为键值(key或index),以第4列值(value)为元素值的;
比如:$ps->conf['theme']['images']['cache_timeout']=5*/
/* 下图是查询结果截图(部分) */
http://hiphotos.baidu.com/winterfog/pic/item/4588234eaa8fb810b2de05a9.jpg
function load_config($type) {
$conflist = !is_array($type) ? $conflist = array($type) : $type;
$c = array();
$cmd = "SELECT conftype,section,var,value FROM $this->t_config WHERE var IS NOT NULL AND conftype IN (";
foreach ($conflist as $conftype) {
   $this->conf[$conftype] = array();
   $c[] = $this->db->escape($conftype, true);
}
$cmd .= join(', ', $c) . ")";
$list = $this->db->fetch_rows(1, $cmd);
foreach ($list as $row) {
   if (empty($row['section'])) {
    $this->_assignvar($this->conf[$row['conftype']], $row['var'], $row['value']);
   } else {
    $this->_assignvar($this->conf[$row['conftype']][$row['section']], $row['var'], $row['value']);
   }
}
}


(未完待续,陆续更新中......)


地址:http://hi.baidu.com/winterfog/blog/item/e8134ec7b3a86adad000601c.html
 楼主| 发表于 2008-9-9 09:55:34 | 显示全部楼层 来自 中国–辽宁–本溪

回复: 解读Psychostats 3.1 排名系统代码(斑竹++)

声明一下,我是转贴,wo
回复

使用道具 举报

游客
回复
您需要登录后才可以回帖 登录 | 注个册吧

快速回复 返回顶部 返回列表