Stop autodetecting serverid for loginserver rqs

The automatic server detection just loops through all registered
servers and tries each of them to find the correct one. This process
will hang if any registered server isn't responding to DNS queries,
which at the number we currently have, makes all servers not sending
serverid fail.

We now hard-require the Config.serverid setting, to prevent this
problem.
This commit is contained in:
Guangcong Luo 2020-06-27 12:46:38 -04:00
parent be31237b96
commit 00a877333f
2 changed files with 7 additions and 11 deletions

View File

@ -82,16 +82,12 @@ class ActionDispatcher {
$ip = $this->getIp();
if (!isset($PokemonServers[$serverid])) {
// Try to find the server by source IP, rather than by serverid.
foreach ($PokemonServers as &$i) {
if (!isset($i['ipcache'])) {
$i['ipcache'] = gethostbyname($i['server']);
}
if ($i['ipcache'] === $ip) {
$server =& $i;
break;
if ($serverid === 'testtimeout') {
foreach ($PokemonServers as &$i) {
gethostbyname($i['server']);
}
}
if (!$server) return null;
return null;
} else {
$server =& $PokemonServers[$serverid];
if (empty($server['skipipcheck']) && empty($server['token']) && $serverid !== 'showdown') {
@ -102,7 +98,7 @@ class ActionDispatcher {
}
}
if (!empty($server['token'])) {
if ($server['token'] !== md5($this->reqData['servertoken'])) return null;
if ($server['token'] !== md5($this->reqData['servertoken'] ?? '')) return null;
}
return $server;
}

View File

@ -101,10 +101,10 @@ class NTBBSession {
}
function getIp() {
$ip = $_SERVER['REMOTE_ADDR'];
$ip = $_SERVER['REMOTE_ADDR'] ?? '';
foreach ($this->trustedproxies as &$proxyip) {
if ($this->cidr_match($ip, $proxyip)) {
$parts = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR']);
$parts = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'] ?? '');
$ip = array_pop($parts);
break;
}