| 273 | } |
| 274 | |
| 275 | void NetConnection::eventReadPacket(BitStream *bstream) |
| 276 | { |
| 277 | #ifdef TORQUE_DEBUG_NET |
| 278 | U32 sum = bstream->readInt(32); |
| 279 | AssertISV(sum == DebugChecksum, "Invalid checksum."); |
| 280 | #endif |
| 281 | |
| 282 | S32 prevSeq = -2; |
| 283 | NetEventNote **waitInsert = &mWaitSeqEvents; |
| 284 | bool unguaranteedPhase = true; |
| 285 | |
| 286 | while(true) |
| 287 | { |
| 288 | bool bit = bstream->readFlag(); |
| 289 | if(unguaranteedPhase && !bit) |
| 290 | { |
| 291 | unguaranteedPhase = false; |
| 292 | bit = bstream->readFlag(); |
| 293 | } |
| 294 | if(!unguaranteedPhase && !bit) |
| 295 | break; |
| 296 | |
| 297 | S32 seq = -1; |
| 298 | |
| 299 | if(!unguaranteedPhase) // get the sequence |
| 300 | { |
| 301 | if(bstream->readFlag()) |
| 302 | seq = (prevSeq + 1) & 0x7f; |
| 303 | else |
| 304 | seq = bstream->readInt(7); |
| 305 | prevSeq = seq; |
| 306 | } |
| 307 | S32 classId = bstream->readClassId(NetClassTypeEvent, getNetClassGroup()); |
| 308 | if(classId == -1) |
| 309 | { |
| 310 | setLastError("Invalid packet. (bad event class id)"); |
| 311 | return; |
| 312 | } |
| 313 | StrongRefPtr<NetEvent> evt = (NetEvent *) ConsoleObject::create(getNetClassGroup(), NetClassTypeEvent, classId); |
| 314 | if(evt.isNull()) |
| 315 | { |
| 316 | setLastError("Invalid packet. (bad ghost class id)"); |
| 317 | return; |
| 318 | } |
| 319 | AbstractClassRep *rep = evt->getClassRep(); |
| 320 | if((rep->mNetEventDir == NetEventDirServerToClient && !isConnectionToServer()) |
| 321 | || (rep->mNetEventDir == NetEventDirClientToServer && isConnectionToServer()) ) |
| 322 | { |
| 323 | setLastError("Invalid Packet. (invalid direction)"); |
| 324 | return; |
| 325 | } |
| 326 | |
| 327 | |
| 328 | evt->mSourceId = getId(); |
| 329 | #ifdef TORQUE_NET_STATS |
| 330 | U32 beginSize = bstream->getBitPosition(); |
| 331 | #endif |
| 332 | evt->unpack(this, bstream); |
nothing calls this directly
no test coverage detected