95 lines
2.5 KiB
PHP
95 lines
2.5 KiB
PHP
<?php
|
|
|
|
$g_conf_mysql_cluster = require('../config/game2003api.mysql.cluster.php');
|
|
$g_conf_redis_cluster = require('../config/game2003api.redis.cluster.php');
|
|
|
|
|
|
function checkMysqlConfig()
|
|
{
|
|
$instance_id = 1;
|
|
global $g_conf_mysql_cluster;
|
|
foreach ($g_conf_mysql_cluster as $instance) {
|
|
if ($instance_id != $instance['instance_id']) {
|
|
error_log('game2001api.mysql.cluster.php config error');
|
|
die();
|
|
}
|
|
$instance_id++;
|
|
}
|
|
}
|
|
|
|
|
|
function checkRedisConfig()
|
|
{
|
|
$instance_id = 1;
|
|
global $g_conf_redis_cluster;
|
|
foreach ($g_conf_redis_cluster as $instance) {
|
|
if ($instance_id != $instance['instance_id']) {
|
|
error_log('game2001api.redis.cluster.php config error');
|
|
die();
|
|
}
|
|
$instance_id++;
|
|
}
|
|
}
|
|
|
|
|
|
function getMysqlConfig($hash_value)
|
|
{
|
|
if ($hash_value < 0) {
|
|
error_log('callstack:' . json_encode(debug_backtrace(), JSON_PRETTY_PRINT));
|
|
die('hash_value < 0 ' . $hash_value);
|
|
}
|
|
global $g_conf_mysql_cluster;
|
|
$idx = $hash_value % count($g_conf_mysql_cluster);
|
|
return $g_conf_mysql_cluster[$idx];
|
|
}
|
|
|
|
function getRedisConfig($hash_value)
|
|
{
|
|
if ($hash_value < 0) {
|
|
error_log('callstack:' . json_encode(debug_backtrace(), JSON_PRETTY_PRINT));
|
|
die('hash_value < 0 ' . $hash_value);
|
|
}
|
|
global $g_conf_redis_cluster;
|
|
$idx = $hash_value % count($g_conf_redis_cluster);
|
|
return $g_conf_redis_cluster[$idx];
|
|
}
|
|
|
|
function getTankConfig($tank_table, $tank_id)
|
|
{
|
|
$tank_id = (int)$tank_id;
|
|
return array_key_exists($tank_id, $tank_table) ? $tank_table[$tank_id] : null;
|
|
}
|
|
|
|
function getSignConfig($sign_table, $sign_id)
|
|
{
|
|
$sign_id = (int)$sign_id;
|
|
return array_key_exists($sign_id, $sign_table) ? $sign_table[$sign_id] : null;
|
|
}
|
|
|
|
function getParameterConfig($para_table, $para_id)
|
|
{
|
|
$para_id = (int)$para_id;
|
|
return array_key_exists($para_id, $para_table) ? $para_table[$para_id] : null;
|
|
}
|
|
|
|
function getItemConfig($item_table, $item_id)
|
|
{
|
|
$item_id = (int)$item_id;
|
|
return array_key_exists($item_id, $item_table) ? $item_table[$item_id] : null;
|
|
}
|
|
|
|
function getRobotConfig($robot_table, $robot_id)
|
|
{
|
|
$robot_id = (int)$robot_id;
|
|
return array_key_exists($robot_id, $robot_table) ? $robot_table[$robot_id] : null;
|
|
}
|
|
|
|
function getQuestConfig($task_table, $task_id)
|
|
{
|
|
$task_id = (int)$task_id;
|
|
return array_key_exists($task_id, $task_table) ? $task_table[$task_id] : null;
|
|
}
|
|
|
|
checkMysqlConfig();
|
|
checkRedisConfig();
|