socket { readbuffer writequeue } worldsocket { headerbuffer packetbuffer } worldSession contains 2 worldsockets each player has 1 worldSession socket update writes packets to out buffer world->update { update sessions { session->update { per socket recv_queue { process next packet(); } } } update maps } worldsocket::readhandler() { headerbuffer.write(socket::readbuffer, size); if(!header) { return; } packetbuffer.write(socket::readbuffer, size); readdatahandler() { decrypt(packetbuffer) log packet worldsession->queuepacket() } asyncread } 0000 0000 0000 0000 1111 1100 0000 1111 C 00 00 10 m 10 01 10 M 00 11 00 M 00 11 00 000000 00 i=0 0000 0000 i=1 >> 2 00 000000 i=2 >> 4 i=3 000000 00 00112233 33 44556677 6677 88990011 990011 22334455 (i+1)%3 * 2