| 1: | <?php declare(strict_types=1); |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | namespace Clansuite\ServerQuery\ServerProtocols; |
| 14: | |
| 15: | use function preg_match; |
| 16: | use function strlen; |
| 17: | use function substr; |
| 18: | use Override; |
| 19: | |
| 20: | |
| 21: | |
| 22: | |
| 23: | |
| 24: | |
| 25: | |
| 26: | |
| 27: | class Fear extends Quake4 |
| 28: | { |
| 29: | |
| 30: | |
| 31: | |
| 32: | public string $name = 'F.E.A.R.'; |
| 33: | |
| 34: | |
| 35: | |
| 36: | |
| 37: | |
| 38: | |
| 39: | public array $supportedGames = ['F.E.A.R.']; |
| 40: | |
| 41: | |
| 42: | |
| 43: | |
| 44: | public string $protocol = 'fear'; |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | #[Override] |
| 50: | public function getProtocolName(): string |
| 51: | { |
| 52: | return $this->protocol; |
| 53: | } |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | #[Override] |
| 59: | public function query_server(mixed $getPlayers = true, mixed $getRules = true): bool |
| 60: | { |
| 61: | if ($this->online) { |
| 62: | $this->reset(); |
| 63: | } |
| 64: | |
| 65: | |
| 66: | $command = "\xFF\xFFgetInfo\x00\x01\x00\x00\x00"; |
| 67: | |
| 68: | if (($result = $this->sendCommand((string) $this->address, (int) $this->queryport, $command)) === '' || ($result = $this->sendCommand((string) $this->address, (int) $this->queryport, $command)) === '0' || ($result = $this->sendCommand((string) $this->address, (int) $this->queryport, $command)) === false) { |
| 69: | $this->errstr = 'No reply received'; |
| 70: | |
| 71: | return false; |
| 72: | } |
| 73: | |
| 74: | |
| 75: | if (strlen($result) < 16) { |
| 76: | $this->errstr = 'Invalid packet received'; |
| 77: | |
| 78: | return false; |
| 79: | } |
| 80: | |
| 81: | |
| 82: | $data = substr($result, 16); |
| 83: | |
| 84: | |
| 85: | $info = $this->parseDoom3Info($data); |
| 86: | |
| 87: | |
| 88: | $this->gamename = (string) ($info['gamename'] ?? 'FEAR'); |
| 89: | $this->gameversion = $this->translateProtocolVersion((string) ($info['protocol'] ?? $info['si_version'] ?? '')); |
| 90: | $this->servertitle = (string) ($info['si_name'] ?? ''); |
| 91: | $this->mapname = (string) ($info['si_map'] ?? ''); |
| 92: | $this->gametype = (string) ($info['si_rules'] ?? ''); |
| 93: | $this->maxplayers = (int) ($info['si_maxPlayers'] ?? 0); |
| 94: | $this->numplayers = 0; |
| 95: | |
| 96: | |
| 97: | $this->rules = $info; |
| 98: | |
| 99: | |
| 100: | if ($getPlayers && isset($info['si_players'])) { |
| 101: | $this->parsePlayers((string) $info['si_players']); |
| 102: | } |
| 103: | |
| 104: | $this->online = true; |
| 105: | |
| 106: | return true; |
| 107: | } |
| 108: | |
| 109: | |
| 110: | |
| 111: | |
| 112: | #[Override] |
| 113: | protected function translateProtocolVersion(string $protocol): string |
| 114: | { |
| 115: | |
| 116: | if (preg_match('/(\d+\.\d+)/', $protocol, $matches) !== false && isset($matches[1])) { |
| 117: | return 'v' . $matches[1]; |
| 118: | } |
| 119: | |
| 120: | return $protocol; |
| 121: | } |
| 122: | } |
| 123: | |