| 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\Buffer; |
| 22: | use GameQ\Exception\Protocol as Exception; |
| 23: | use GameQ\Protocol; |
| 24: | use GameQ\Result; |
| 25: | |
| 26: | |
| 27: | |
| 28: | |
| 29: | |
| 30: | |
| 31: | |
| 32: | |
| 33: | |
| 34: | |
| 35: | class Starmade extends Protocol |
| 36: | { |
| 37: | |
| 38: | |
| 39: | |
| 40: | |
| 41: | |
| 42: | protected $packets = [ |
| 43: | self::PACKET_STATUS => "\x00\x00\x00\x09\x2a\xff\xff\x01\x6f\x00\x00\x00\x00", |
| 44: | ]; |
| 45: | |
| 46: | |
| 47: | |
| 48: | |
| 49: | |
| 50: | |
| 51: | protected $transport = self::TRANSPORT_TCP; |
| 52: | |
| 53: | |
| 54: | |
| 55: | |
| 56: | |
| 57: | |
| 58: | protected $protocol = 'starmade'; |
| 59: | |
| 60: | |
| 61: | |
| 62: | |
| 63: | |
| 64: | |
| 65: | protected $name = 'starmade'; |
| 66: | |
| 67: | |
| 68: | |
| 69: | |
| 70: | |
| 71: | |
| 72: | protected $name_long = "StarMade"; |
| 73: | |
| 74: | |
| 75: | |
| 76: | |
| 77: | |
| 78: | |
| 79: | protected $normalize = [ |
| 80: | |
| 81: | 'general' => [ |
| 82: | |
| 83: | 'dedicated' => 'dedicated', |
| 84: | 'hostname' => 'hostname', |
| 85: | 'maxplayers' => 'max_players', |
| 86: | 'numplayers' => 'num_players', |
| 87: | 'password' => 'password', |
| 88: | ], |
| 89: | ]; |
| 90: | |
| 91: | |
| 92: | |
| 93: | |
| 94: | |
| 95: | |
| 96: | |
| 97: | public function processResponse() |
| 98: | { |
| 99: | |
| 100: | $buffer = new Buffer(implode('', $this->packets_response), Buffer::NUMBER_TYPE_BIGENDIAN); |
| 101: | |
| 102: | |
| 103: | $buffer->readInt32Signed(); |
| 104: | |
| 105: | |
| 106: | $buffer->readInt64(); |
| 107: | |
| 108: | |
| 109: | $buffer->readInt8(); |
| 110: | |
| 111: | |
| 112: | $buffer->readInt16Signed(); |
| 113: | |
| 114: | |
| 115: | $buffer->readInt8Signed(); |
| 116: | |
| 117: | |
| 118: | $buffer->readInt8Signed(); |
| 119: | |
| 120: | $parsed = $this->parseServerParameters($buffer); |
| 121: | |
| 122: | |
| 123: | $result = new Result(); |
| 124: | |
| 125: | |
| 126: | $result->add('info_version', $parsed[0]); |
| 127: | $result->add('version', $parsed[1]); |
| 128: | $result->add('hostname', $parsed[2]); |
| 129: | $result->add('game_descr', $parsed[3]); |
| 130: | $result->add('start_time', $parsed[4]); |
| 131: | $result->add('num_players', $parsed[5]); |
| 132: | $result->add('max_players', $parsed[6]); |
| 133: | $result->add('dedicated', 1); |
| 134: | $result->add('password', 0); |
| 135: | |
| 136: | |
| 137: | unset($parsed); |
| 138: | |
| 139: | return $result->fetch(); |
| 140: | } |
| 141: | |
| 142: | |
| 143: | |
| 144: | |
| 145: | |
| 146: | |
| 147: | |
| 148: | |
| 149: | |
| 150: | |
| 151: | protected function parseServerParameters(Buffer &$buffer) |
| 152: | { |
| 153: | |
| 154: | $parsed = []; |
| 155: | |
| 156: | |
| 157: | $parameterSize = $buffer->readInt32Signed(); |
| 158: | |
| 159: | |
| 160: | for ($i = 0; $i < $parameterSize; $i++) { |
| 161: | |
| 162: | $dataType = $buffer->readInt8Signed(); |
| 163: | |
| 164: | switch ($dataType) { |
| 165: | |
| 166: | case 1: |
| 167: | $parsed[$i] = $buffer->readInt32Signed(); |
| 168: | break; |
| 169: | |
| 170: | |
| 171: | case 2: |
| 172: | $parsed[$i] = $buffer->readInt64(); |
| 173: | break; |
| 174: | |
| 175: | |
| 176: | case 3: |
| 177: | $parsed[$i] = $buffer->readFloat32(); |
| 178: | break; |
| 179: | |
| 180: | |
| 181: | case 4: |
| 182: | |
| 183: | $strLength = $buffer->readInt16Signed(); |
| 184: | |
| 185: | |
| 186: | $parsed[$i] = $buffer->read($strLength); |
| 187: | |
| 188: | unset($strLength); |
| 189: | break; |
| 190: | |
| 191: | |
| 192: | case 5: |
| 193: | $parsed[$i] = (bool)$buffer->readInt8Signed(); |
| 194: | break; |
| 195: | |
| 196: | |
| 197: | case 6: |
| 198: | $parsed[$i] = $buffer->readInt8Signed(); |
| 199: | break; |
| 200: | |
| 201: | |
| 202: | case 7: |
| 203: | $parsed[$i] = $buffer->readInt16Signed(); |
| 204: | break; |
| 205: | |
| 206: | |
| 207: | case 8: |
| 208: | |
| 209: | throw new Exception("StarMade array parsing is not implemented!"); |
| 210: | } |
| 211: | } |
| 212: | |
| 213: | return $parsed; |
| 214: | } |
| 215: | } |
| 216: | |