109 $this->needsTranslation =
CommonTypes::getBool($in);
111 $category = Byte::readUnsigned($in);
112 $this->type = Byte::readUnsigned($in);
114 case self::TYPE_CHAT:
115 case self::TYPE_WHISPER:
117 case self::TYPE_ANNOUNCEMENT:
118 if($category !== self::CATEGORY_AUTHORED_MESSAGE){
119 throw new PacketDecodeException(
"Decoded TextPacket has invalid structure: type {$this->type} requires category CATEGORY_AUTHORED_MESSAGE");
121 $this->sourceName = CommonTypes::getString($in);
122 $this->message = CommonTypes::getString($in);
126 case self::TYPE_SYSTEM:
127 case self::TYPE_JSON_WHISPER:
128 case self::TYPE_JSON:
129 case self::TYPE_JSON_ANNOUNCEMENT:
130 if($category !== self::CATEGORY_MESSAGE_ONLY){
131 throw new PacketDecodeException(
"Decoded TextPacket has invalid structure: type {$this->type} requires category CATEGORY_MESSAGE_ONLY");
133 $this->message = CommonTypes::getString($in);
135 case self::TYPE_TRANSLATION:
136 case self::TYPE_POPUP:
137 case self::TYPE_JUKEBOX_POPUP:
138 if($category !== self::CATEGORY_MESSAGE_WITH_PARAMETERS){
139 throw new PacketDecodeException(
"Decoded TextPacket has invalid structure: type {$this->type} requires category CATEGORY_MESSAGE_WITH_PARAMETERS");
141 $this->message = CommonTypes::getString($in);
142 $count = VarInt::readUnsignedInt($in);
143 for($i = 0; $i < $count; ++$i){
144 $this->parameters[] = CommonTypes::getString($in);
149 $this->xboxUserId = CommonTypes::getString($in);
150 $this->platformChatId = CommonTypes::getString($in);
151 $this->filteredMessage = CommonTypes::readOptional($in, CommonTypes::getString(...));
155 CommonTypes::putBool($out, $this->needsTranslation);
157 $category = match ($this->type) {
161 self::TYPE_JSON_WHISPER,
162 self::TYPE_JSON_ANNOUNCEMENT,
163 self::TYPE_JSON => self::CATEGORY_MESSAGE_ONLY,
167 self::TYPE_ANNOUNCEMENT => self::CATEGORY_AUTHORED_MESSAGE,
169 self::TYPE_TRANSLATION,
171 self::TYPE_JUKEBOX_POPUP => self::CATEGORY_MESSAGE_WITH_PARAMETERS,
173 default =>
throw new \LogicException(
"Invalid TextPacket type: $this->type")
176 Byte::writeUnsigned($out, $category);
177 Byte::writeUnsigned($out, $this->type);
179 case self::TYPE_CHAT:
180 case self::TYPE_WHISPER:
182 case self::TYPE_ANNOUNCEMENT:
183 CommonTypes::putString($out, $this->sourceName);
186 case self::TYPE_SYSTEM:
187 case self::TYPE_JSON_WHISPER:
188 case self::TYPE_JSON:
189 case self::TYPE_JSON_ANNOUNCEMENT:
190 CommonTypes::putString($out, $this->message);
193 case self::TYPE_TRANSLATION:
194 case self::TYPE_POPUP:
195 case self::TYPE_JUKEBOX_POPUP:
196 CommonTypes::putString($out, $this->message);
197 VarInt::writeUnsignedInt($out, count($this->parameters));
198 foreach($this->parameters as $p){
199 CommonTypes::putString($out, $p);
204 CommonTypes::putString($out, $this->xboxUserId);
205 CommonTypes::putString($out, $this->platformChatId);
206 CommonTypes::writeOptional($out, $this->filteredMessage, CommonTypes::putString(...));