void WSClient::OnRead() { for(;;) { if(!_cmd) { if(GetReadBufferSize() < 6) break; Read(2, (uint8*)&_cmd); Read(4, (uint8*)&_remaining); } if(_remaining && GetReadBufferSize() < _remaining) break; if(_cmd == ISMSG_WOW_PACKET) { /* optimized version for packet passing, to reduce latency! ;) */ uint32 sid = *(uint32*)&m_readBuffer[0]; uint16 op = *(uint16*)&m_readBuffer[4]; uint32 sz = *(uint32*)&m_readBuffer[6]; WorldSession * session = sClusterInterface.GetSession(sid); if(session != NULL) { WorldPacket * pck = new WorldPacket(op, sz); pck->resize(sz); memcpy((void*)pck->contents(), &m_readBuffer[10], sz); session->QueuePacket(pck); } RemoveReadBufferBytes(sz + 10/*header*/, false); _cmd = 0; continue; } WorldPacket * pck = new WorldPacket(_cmd, _remaining); _cmd = 0; pck->resize(_remaining); Read(_remaining, (uint8*)pck->contents()); /* we could handle auth here */ switch(_cmd) { case ISMSG_AUTH_REQUEST: sClusterInterface.HandleAuthRequest(*pck); delete pck; break; default: sClusterInterface.QueuePacket(pck); } } }
void WSClient::OnRecvData() { for(;;) { if(!_cmd) { if(GetReadBuffer()->GetSize() < 6) break; Read((uint8*)&_cmd, 2); Read((uint8*)&_remaining, 4); } if(_remaining && GetReadBuffer()->GetSize() < _remaining) return; if(_cmd == SMSGR_WOW_PACKET) { uint32 sid = 0; uint16 op = 0; uint32 sz = 0; Read(&sid, 4); Read(&op, 2); Read(&sz, 4); WorldSession * session = sClusterInterface.GetSession(sid); if(session != NULL) { WorldPacket * pck = new WorldPacket(op, sz); if (sz > 0) { pck->resize(sz); Read((void*)pck->contents(), sz); } if(session) session->QueuePacket(pck); else delete pck; } _cmd = 0; continue; } WorldPacket * pck = new WorldPacket(_cmd, _remaining); _cmd = 0; if(_remaining) { pck->resize(_remaining); Read((uint8*)pck->contents(), _remaining); } /* we could handle auth here */ switch(_cmd) { case SMSGR_AUTH_REQUEST: sClusterInterface.HandleAuthRequest(*pck); delete pck; break; default: sClusterInterface.QueuePacket(pck); } } }