접속자수 계산 코드 수정

This commit is contained in:
2020-05-09 23:46:43 +09:00
parent da9d59443b
commit f3ef65ad70
3 changed files with 24 additions and 40 deletions
+19 -36
View File
@@ -868,12 +868,8 @@ function onlinegen(General $general)
$gameStor = KVStorage::getStorage($db, 'game_env');
$nationID = $general->getNationID();
if ($nationID === null || Util::toInt($nationID) === 0) {
$onlinegen = $gameStor->onlinegen;
} else {
$nationStor = KVStorage::getStorage($db, $nationID, 'nation_env');
$onlinegen = $nationStor->onlinegen;
}
$nationStor = KVStorage::getStorage($db, $nationID, 'nation_env');
$onlinegen = $nationStor->online_genenerals;
return $onlinegen;
}
@@ -1193,7 +1189,6 @@ function updateOnline()
{
$db = DB::db();
$gameStor = KVStorage::getStorage($db, 'game_env');
$connect = $db->get();
$nationname = ["재야"];
//국가별 이름 매핑
@@ -1203,40 +1198,28 @@ function updateOnline()
//동접수
$query = "select no,name,nation from general where lastrefresh > DATE_SUB(NOW(), INTERVAL 5 MINUTE)";
$result = MYDB_query($query, $connect) or Error(__LINE__ . MYDB_error($connect), "");
$onlinenum = MYDB_num_rows($result);
$before5Min = TimeUtil::nowAddMinutes(-5);
$onlineUser = $db->query('SELECT no,name,nation FROM general WHERE lastrefresh > %s', $before5Min);
$onlineNum = count($onlineUser);
$onlineNationUsers = Util::arrayGroupBy($onlineUser, 'nation');
uasort($onlineNationUsers, function(array $lhs, array $rhs){
return -(count($lhs)<=>count($rhs));
});
$onnation = array();
$onnationstr = "";
$onlineNation = [];
//국가별 접속중인 장수
for ($i = 0; $i < $onlinenum; $i++) {
$general = MYDB_fetch_array($result);
if (isset($onnation[$general['nation']])) {
$onnation[$general['nation']] .= $general['name'] . ', ';
} else {
$onnation[$general['nation']] = $general['name'] . ', ';
}
}
//$onnation이 empty라면 굳이 foreach를 수행 할 이유가 없음.
if (!empty($onnation)) {
foreach ($onnation as $key => $val) {
$onnationstr .= "【{$nationname[$key]}】, ";
if ($key == 0) {
$gameStor->onlinegen = $onnation[0];
} else {
$nationStor = KVStorage::getStorage($db, $key, 'nation_env');
$nationStor->onlinegen = $onnation[$key];
}
}
foreach($onlineNationUsers as $nationID=>$rawOnlineUser){
$nationName = getNationStaticInfo($nationID)['name'];
$onlineNation[] = "【{$nationName}】";
$userList = join(', ', Util::squeezeFromArray($rawOnlineUser, 'name'));
$nationStor = KVStorage::getStorage($db, $nationID, 'nation_env');
$nationStor->online_genenerals = $userList;
}
//접속중인 국가
$gameStor->online = $onlinenum;
$gameStor->onlinenation = $onnationstr;
$gameStor->online_user_cnt = $onlineNum;
$gameStor->online_nation = join(', ', $onlineNation);
}
function addAge()
+3 -3
View File
@@ -61,7 +61,7 @@ $scenario = $gameStor->scenario_text;
$nationID = $generalObj->getNationID();
if($nationID){
$nationStor = KVStorage::getStorage($db, $nationID, 'nation_env');
$nationStor->cacheValues(['notice', 'onlinegne']);
$nationStor->cacheValues(['notice', 'online_genenerals']);
}
$valid = 0;
@@ -150,7 +150,7 @@ $(function(){
<tr height=30>
<td width=198><?=info(2)?></td>
<td width=198>전체 접속자 수 : <?=$gameStor->online?> 명</td>
<td width=198>전체 접속자 수 : <?=$gameStor->online_user_cnt?> 명</td>
<td width=198>턴당 갱신횟수 : <?=$gameStor->conlimit?>회</td>
<td width=398 colspan=2><?=info(3)?></td>
</tr>
@@ -212,7 +212,7 @@ echo "
</td>
</tr>";
?>
<tr><td colspan=5 style="text-align:left;">접속중인 국가: <?=$gameStor->onlinenation?></td></tr>
<tr><td colspan=5 style="text-align:left;">접속중인 국가: <?=$gameStor->online_nation?></td></tr>
<tr><td colspan=5 style="text-align:left;">운영자 메세지 : <span style='color:yellow;'><?=$gameStor->msg?></span></td></tr>
<tr><td colspan=5 style="text-align:left;"><div>【 국가방침 】</div><div><?=nationMsg($generalObj)?></div></td></tr>
<tr><td colspan=5 style="text-align:left;">【 접속자 】<?=onlinegen($generalObj)?></td></tr>
+2 -1
View File
@@ -88,7 +88,8 @@ CREATE TABLE `general` (
INDEX `troop` (`troop`, `turntime`),
INDEX `officer_level` (`nation`, `officer_level`),
INDEX `officer_city` (`officer_city`, `officer_level`),
INDEX `name` (`name`)
INDEX `name` (`name`),
INDEX `last_refresh` (`lastrefresh`)
)
DEFAULT CHARSET=utf8mb4
ENGINE=Aria;