접속자수 계산 코드 수정

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'); $gameStor = KVStorage::getStorage($db, 'game_env');
$nationID = $general->getNationID(); $nationID = $general->getNationID();
if ($nationID === null || Util::toInt($nationID) === 0) { $nationStor = KVStorage::getStorage($db, $nationID, 'nation_env');
$onlinegen = $gameStor->onlinegen; $onlinegen = $nationStor->online_genenerals;
} else {
$nationStor = KVStorage::getStorage($db, $nationID, 'nation_env');
$onlinegen = $nationStor->onlinegen;
}
return $onlinegen; return $onlinegen;
} }
@@ -1193,7 +1189,6 @@ function updateOnline()
{ {
$db = DB::db(); $db = DB::db();
$gameStor = KVStorage::getStorage($db, 'game_env'); $gameStor = KVStorage::getStorage($db, 'game_env');
$connect = $db->get();
$nationname = ["재야"]; $nationname = ["재야"];
//국가별 이름 매핑 //국가별 이름 매핑
@@ -1203,40 +1198,28 @@ function updateOnline()
//동접수 //동접수
$query = "select no,name,nation from general where lastrefresh > DATE_SUB(NOW(), INTERVAL 5 MINUTE)"; $before5Min = TimeUtil::nowAddMinutes(-5);
$result = MYDB_query($query, $connect) or Error(__LINE__ . MYDB_error($connect), ""); $onlineUser = $db->query('SELECT no,name,nation FROM general WHERE lastrefresh > %s', $before5Min);
$onlinenum = MYDB_num_rows($result); $onlineNum = count($onlineUser);
$onlineNationUsers = Util::arrayGroupBy($onlineUser, 'nation');
uasort($onlineNationUsers, function(array $lhs, array $rhs){
return -(count($lhs)<=>count($rhs));
});
$onnation = array(); $onlineNation = [];
$onnationstr = "";
//국가별 접속중인 장수 foreach($onlineNationUsers as $nationID=>$rawOnlineUser){
for ($i = 0; $i < $onlinenum; $i++) { $nationName = getNationStaticInfo($nationID)['name'];
$general = MYDB_fetch_array($result); $onlineNation[] = "【{$nationName}】";
if (isset($onnation[$general['nation']])) { $userList = join(', ', Util::squeezeFromArray($rawOnlineUser, 'name'));
$onnation[$general['nation']] .= $general['name'] . ', '; $nationStor = KVStorage::getStorage($db, $nationID, 'nation_env');
} else { $nationStor->online_genenerals = $userList;
$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];
}
}
} }
//접속중인 국가 //접속중인 국가
$gameStor->online = $onlinenum; $gameStor->online_user_cnt = $onlineNum;
$gameStor->onlinenation = $onnationstr; $gameStor->online_nation = join(', ', $onlineNation);
} }
function addAge() function addAge()
+3 -3
View File
@@ -61,7 +61,7 @@ $scenario = $gameStor->scenario_text;
$nationID = $generalObj->getNationID(); $nationID = $generalObj->getNationID();
if($nationID){ if($nationID){
$nationStor = KVStorage::getStorage($db, $nationID, 'nation_env'); $nationStor = KVStorage::getStorage($db, $nationID, 'nation_env');
$nationStor->cacheValues(['notice', 'onlinegne']); $nationStor->cacheValues(['notice', 'online_genenerals']);
} }
$valid = 0; $valid = 0;
@@ -150,7 +150,7 @@ $(function(){
<tr height=30> <tr height=30>
<td width=198><?=info(2)?></td> <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=198>턴당 갱신횟수 : <?=$gameStor->conlimit?>회</td>
<td width=398 colspan=2><?=info(3)?></td> <td width=398 colspan=2><?=info(3)?></td>
</tr> </tr>
@@ -212,7 +212,7 @@ echo "
</td> </td>
</tr>"; </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;">운영자 메세지 : <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;"><div>【 국가방침 】</div><div><?=nationMsg($generalObj)?></div></td></tr>
<tr><td colspan=5 style="text-align:left;">【 접속자 】<?=onlinegen($generalObj)?></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 `troop` (`troop`, `turntime`),
INDEX `officer_level` (`nation`, `officer_level`), INDEX `officer_level` (`nation`, `officer_level`),
INDEX `officer_city` (`officer_city`, `officer_level`), INDEX `officer_city` (`officer_city`, `officer_level`),
INDEX `name` (`name`) INDEX `name` (`name`),
INDEX `last_refresh` (`lastrefresh`)
) )
DEFAULT CHARSET=utf8mb4 DEFAULT CHARSET=utf8mb4
ENGINE=Aria; ENGINE=Aria;