| 1: | <?php |
| 2: | |
| 3: | |
| 4: | |
| 5: | |
| 6: | |
| 7: | |
| 8: | |
| 9: | |
| 10: | |
| 11: | |
| 12: | |
| 13: | |
| 14: | |
| 15: | |
| 16: | |
| 17: | |
| 18: | |
| 19: | namespace GameQ\Protocols; |
| 20: | |
| 21: | use GameQ\Exception\Protocol as Exception; |
| 22: | use GameQ\Protocol; |
| 23: | use GameQ\Result; |
| 24: | |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | class Tibia extends Protocol |
| 36: | { |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | protected $packets = [ |
| 43: | self::PACKET_STATUS => "\x06\x00\xFF\xFF\x69\x6E\x66\x6F", |
| 44: | ]; |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | protected $transport = self::TRANSPORT_TCP; |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | protected $protocol = 'tibia'; |
| 59: | |
| 60: | |
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | protected $name = 'tibia'; |
| 66: | |
| 67: | |
| 68: | |
| 69: | |
| 70: | |
| 71: | |
| 72: | protected $name_long = "Tibia"; |
| 73: | |
| 74: | |
| 75: | |
| 76: | |
| 77: | |
| 78: | |
| 79: | protected $join_link = "otserv://%s/%d/"; |
| 80: | |
| 81: | |
| 82: | |
| 83: | |
| 84: | |
| 85: | |
| 86: | protected $normalize = [ |
| 87: | |
| 88: | 'general' => [ |
| 89: | |
| 90: | 'dedicated' => 'dedicated', |
| 91: | 'gametype' => 'server', |
| 92: | 'hostname' => 'servername', |
| 93: | 'motd' => 'motd', |
| 94: | 'maxplayers' => 'players_max', |
| 95: | 'numplayers' => 'players_online', |
| 96: | 'map' => 'map_name', |
| 97: | ], |
| 98: | ]; |
| 99: | |
| 100: | |
| 101: | |
| 102: | |
| 103: | |
| 104: | |
| 105: | |
| 106: | public function processResponse() |
| 107: | { |
| 108: | |
| 109: | $xmlString = implode('', $this->packets_response); |
| 110: | |
| 111: | |
| 112: | if (($xmlDoc = @simplexml_load_string($xmlString)) === false) { |
| 113: | throw new Exception(__METHOD__ . " Unable to load XML string."); |
| 114: | } |
| 115: | |
| 116: | |
| 117: | $result = new Result(); |
| 118: | |
| 119: | |
| 120: | $result->add('dedicated', 1); |
| 121: | |
| 122: | |
| 123: | foreach (['serverinfo', 'owner', 'map', 'npcs', 'monsters', 'players'] as $property) { |
| 124: | foreach ($xmlDoc->{$property}->attributes() as $key => $value) { |
| 125: | if (!in_array($property, ['serverinfo'])) { |
| 126: | $key = $property . '_' . $key; |
| 127: | } |
| 128: | |
| 129: | |
| 130: | $result->add($key, (string)$value); |
| 131: | } |
| 132: | } |
| 133: | |
| 134: | $result->add("motd", (string)$xmlDoc->motd); |
| 135: | |
| 136: | unset($xmlDoc, $xmlDoc); |
| 137: | |
| 138: | return $result->fetch(); |
| 139: | } |
| 140: | } |
| 141: | |