(str)
| 155 | } |
| 156 | |
| 157 | #parsePacket(str) { |
| 158 | if (!this.isOpen) return; |
| 159 | |
| 160 | protocol.parseWSPacket(str).forEach((packet) => { |
| 161 | if (global.TW_DEBUG) console.log('§90§30§107 CLIENT §0 PACKET', packet); |
| 162 | if (typeof packet === 'number') { // Ping |
| 163 | this.#ws.send(protocol.formatWSPacket(`~h~${packet}`)); |
| 164 | this.#handleEvent('ping', packet); |
| 165 | return; |
| 166 | } |
| 167 | |
| 168 | if (packet.m === 'protocol_error') { // Error |
| 169 | this.#handleError('Client critical error:', packet.p); |
| 170 | this.#ws.close(); |
| 171 | return; |
| 172 | } |
| 173 | |
| 174 | if (packet.m && packet.p) { // Normal packet |
| 175 | const parsed = { |
| 176 | type: packet.m, |
| 177 | data: packet.p, |
| 178 | }; |
| 179 | |
| 180 | const session = packet.p[0]; |
| 181 | |
| 182 | if (session && this.#sessions[session]) { |
| 183 | this.#sessions[session].onData(parsed); |
| 184 | return; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | if (!this.#logged) { |
| 189 | this.#handleEvent('logged', packet); |
| 190 | return; |
| 191 | } |
| 192 | |
| 193 | this.#handleEvent('data', packet); |
| 194 | }); |
| 195 | } |
| 196 | |
| 197 | #sendQueue = []; |
| 198 |
no test coverage detected