hmm...well you have to know whats going in and out and have a database to store people's data. I think I found the spot where the client receive messages but, I can't confirm it because it will disconnect me if I debug it. This happens because when the server sends me a ping to my client I must pong the server back in a time frame or else i'll be disconnect.
I don't think the packets are crypted with anything. But you do have to decode the packet, like if it has a 32 in the beginning of the packet, that means the user is sending an item request.
I'm am not sure how the chat or login works, but I know it's separate. It's not that easy, but it is possible to emulate a server. Most games that have emulated servers are old games like Ragnarok Online or Linage.
oh, correct me if I'm wrong, I'm still learning.