function module_validity_check($file) { $log = ''; if (!file_exists($file)) { $log .= "<span><font color=\"red\">模块列表文件不存在。</font></span><br>"; return $log; } $content = openfile($file); $in = sizeof($content); $n = 0; $m = 0; for ($i = 0; $i < $in; $i++) { list($modname, $modpath, $inuse) = explode(',', $content[$i]); if ($inuse == 1) { if (isset($modnamelist[$modname])) { $log .= "<span><font color=\"red\">模块{$modname}被多次加载,路径分别为{$modpath}和{$modnamelist[$modname]}。</font></span><br>"; return $log; } $modnamelist[$modname] = $modpath; $n++; $modn[$n] = $modname; $modp[$n] = $modpath; } else { $m++; $bmodn[$m] = $modname; $bmodp[$m] = $modpath; } } global $___TEMP_DRY_RUN, $___TEMP_DRY_RUN_COUNTER; $___TEMP_DRY_RUN = 1; $mod_exist['root'] = 1; $dependency = array(); $dependency_optional = array(); $sup_func_list = array(); for ($i = 1; $i <= $n; $i++) { $dependency[$i] = array(); } for ($i = 1; $i <= $n; $i++) { $dependency_optional[$i] = array(); } for ($i = 1; $i <= $n; $i++) { $sup_func_list[$i] = array(); } for ($i = 1; $i <= $n; $i++) { $modname = $modn[$i]; $modpath = $modp[$i]; if (!file_exists(GAME_ROOT . './include/modules/' . $modpath . 'module.inc.php')) { $log .= "<span><font color=\"red\">模块{$modname}没有提供module.inc.php。</font></span><br>"; return $log; } global $faillog; $faillog = "<span><font color=\"red\">遇到了一个未知错误。这可能是由于模块{$modname}包含语法错误造成的。</font></span><br>"; require GAME_ROOT . './include/modules/' . $modpath . 'module.inc.php'; $faillog = ''; $mod_exist[$modname] = $modpath; if (isset($conflict_list[$modname])) { $log .= "<span><font color=\"red\">模块{$modname}与模块{$conflict_list[$modname]}冲突。</font></span><br>"; return $log; } foreach (explode(' ', $___MODULE_conflict) as $key) { if ($key != '') { if (isset($mod_exist[$key])) { $log .= "<span><font color=\"red\">模块{$modname}与模块{$key}冲突。</font></span><br>"; return $log; } $conflict_list[$key] = $modname; } } foreach (explode(' ', $___MODULE_dependency) as $key) { if ($key != '') { array_push($dependency[$i], $key); } } foreach (explode(' ', $___MODULE_dependency_optional) as $key) { if ($key != '') { array_push($dependency_optional[$i], $key); } } foreach (explode(' ', $___MODULE_codelist) as $key) { if ($key != '') { if (!file_exists(GAME_ROOT . './include/modules/' . $modpath . $key)) { $log .= "<span><font color=\"red\">模块{$modname}声明包含代码文件{$key},但这个文件并不存在。</font></span><br>"; return $log; } } } foreach (explode(' ', $___MODULE_templatelist) as $key) { if ($key != '') { if (!file_exists(GAME_ROOT . './include/modules/' . $modpath . $key . '.htm')) { $log .= "<span><font color=\"red\">模块{$modname}声明包含模板文件{$key}.htm,但这个文件并不存在。</font></span><br>"; return $log; } } } $a = get_defined_functions()['user']; $b = array(); foreach ($a as $key) { if ($key != '') { if (strtoupper(substr($key, 0, strlen($modname) + 1)) == strtoupper($modname . '\\')) { array_push($b, substr($key, strlen($modname) + 1)); } } } $init_exist = 0; foreach ($b as $key) { if ($key != '') { if ($key != 'init') { array_push($sup_func_list[$i], $key); } else { $init_exist = 1; } } } if (!$init_exist) { $log .= "<span><font color=\"red\">模块{$modname}没有包含init()函数。</font></span><br>"; return $log; } foreach ($b as $key) { if ($key != '') { if ($key != 'init') { global $faillog; $faillog = "<span><font color=\"red\">模块{$modname}的函数{$key}的开头没有写上" . '<pre>if (eval(__MAGIC__)) return $___RET_VALUE;</pre>这句话。</font></span><br>'; $expect = $___TEMP_DRY_RUN_COUNTER + 1; global $___TEMP_FUNCNAME_EXPECT; $___TEMP_FUNCNAME_EXPECT = $modname . '\\' . $key; $__RET = ''; eval('$__RET=' . $modname . '\\' . $key . '();'); $faillog = ''; if ($__RET != '23333333' || $___TEMP_DRY_RUN_COUNTER != $expect) { $log .= "<span><font color=\"red\">模块{$modname}的函数{$key}的开头没有写上" . '<pre>if (eval(__MAGIC__)) return $___RET_VALUE;</pre>这句话。</font></span><br>'; return $log; } } } } } $g = array(); for ($i = 1; $i <= $n; $i++) { $g[$i] = array(); } for ($i = 1; $i <= $n; $i++) { foreach ($dependency[$i] as $key) { $flag = 0; for ($j = 1; $j <= $n; $j++) { if ($modn[$j] == $key) { $flag = 1; array_push($g[$j], $i); $rd[$i]++; break; } } if (!$flag) { $log .= "<span><font color=\"red\">模块{$modn[$i]}的依赖{$key}没有满足。</font></span><br>"; return $log; } } foreach ($dependency_optional[$i] as $key) { $flag = 0; for ($j = 1; $j <= $n; $j++) { if ($modn[$j] == $key) { $flag = 1; array_push($g[$j], $i); $rd[$i]++; break; } } } } $head = 1; $tail = 1; for ($i = 1; $i <= $n; $i++) { if ($rd[$i] == 0) { $q[$tail] = $i; $tail++; } } while ($head < $tail) { $x = $q[$head]; $head++; foreach ($g[$x] as $y) { $rd[$y]--; if ($rd[$y] == 0) { $q[$tail] = $y; $tail++; } } } if ($tail != $n + 1) { $log .= "<span><font color=\"red\">模块出现了循环依赖,请检查。</font></span><br>"; return $log; } for ($z = 1; $z <= $n; $z++) { $i = $q[$z]; $modname = $modn[$i]; foreach ($sup_func_list[$i] as $key) { if ($key != '') { $flag = 0; foreach ($dependency[$i] as $r) { if ($r != '') { if (isset($func[$r]) && isset($func[$r][strtoupper($key)])) { $flag = 1; } } } foreach ($dependency_optional[$i] as $r) { if ($r != '') { if (isset($func[$r]) && isset($func[$r][strtoupper($key)])) { $flag = 1; } } } if (!$flag) { if (isset($funclist[strtoupper($key)])) { $x = $funclist[strtoupper($key)]; $log .= "<span><font color=\"red\">模块{$modname}提供了函数{$key},\n\t\t\t\t\t这个函数没有重载任何其依赖的模块中的同名函数,\n\t\t\t\t\t却重载了模块{$x}中的同名函数。这可能是函数名冲突造成的。</font></span><br>"; return $log; } } $funclist[strtoupper($key)] = $modname; $func[$modname][strtoupper($key)] = 1; } } } $content = array(); for ($i = 1; $i <= $n; $i++) { array_push($content, $modn[$q[$i]] . ',' . $modp[$q[$i]] . ',' . '1'); } for ($i = 1; $i <= $m; $i++) { array_push($content, $bmodn[$i] . ',' . $bmodp[$i] . ',' . '0'); } writeover_array(GAME_ROOT . './gamedata/modules.list.pass.php', $content); return 1; }
copy(GAME_ROOT . './gamedata/modules.list.php', GAME_ROOT . './gamedata/modules.list.temp.php'); } } header('Location: modulemng.php'); die; } else { if ($_POST['action'] == 'add') { $file = GAME_ROOT . './gamedata/modules.list.php'; $content = openfile($file); if ($_POST['modpath'][strlen($_POST['modpath']) - 1] != '/') { $_POST['modpath'] .= '/'; } $s = $_POST['modname'] . ',' . $_POST['modpath'] . ',0'; $in = sizeof($content); $content[$in] = $s; writeover_array($file, $content); copy(GAME_ROOT . './gamedata/modules.list.php', GAME_ROOT . './gamedata/modules.list.temp.php'); header('Location: modulemng.php'); } else { echo '<br><span><font size=5>模块管理系统</font></span><br><br>'; echo '<a href="modulemng.php?mode=edit" style="text-decoration: none"><span><font color="red">[进入编辑模式]</font></span></a><br><br>'; printmodtable(GAME_ROOT . './gamedata/modules.list.php', 1); echo '<br><br><font color="green">添加模块:</font><br> <form method="post" name="addmodule" action="modulemng.php"> <input name="action" value="add" type="hidden"> 模块名<input name="modname" size="20" maxlength="100" value="" type="text"> 路径<input name="modpath" size="20" maxlength="100" value="" type="text"> <input name="enter" value="添加" type="submit"> </form>模块名务必不要打错,这个系统是不检查的。<br>路径基准位置是./include/modules<br> 例: 添加位于./include/modules/core/sys的sys模块,应填写路径“core/sys”和模块名“sys”<br>'; die;