Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[C++] Game server design for MMORPG Emulator

Newbie Spellweaver
Joined
Aug 14, 2015
Messages
79
Reaction score
18
I'm working on an emulator for an old mmorpg.Currently done with login server and login part of relay server where I do database related stuff. For login server I'm using simple tcp listener/stream classes and a big switch loop to respond incoming client packets. It's working pretty well for login server since it's dealing with one client in their own thread but I don't think it'll be nearly enough for game server. Are there any experienced emulator programmers who could give me some tips ?
 
[emoji848]
Legend
Joined
Dec 3, 2011
Messages
2,232
Reaction score
1,518
This is a very theoretical question....
Might want to show us some code you use as well? With just the bare explanation of what your IOCP classes seem to do you wont get much but some theoretical hints from this question.

Generally switch statements on integral datatypes can be handled by the processor extremely fast. It's faster than any if / else if or map construct. However it can become very unreadable with a high amount of OP-Codes to switch on. Specially if you deal with 1 big method, that kinda does everything (I've seen some dumb poop already)
However things like packet-type switching are less a performance issue. What the handlers do or if you use an asynchronous approach or not, is the more critical stuff. So don't worry about a switch loop :)
 
Newbie Spellweaver
Joined
Aug 14, 2015
Messages
79
Reaction score
18
Thanks for the answer. I was using a blocking socket model but apparently that's the worst model to choose. I've been reading about completion port model for the last couple of days and it looks much better already. I think what I'm trying to ask is how would one go about managing client connections. I'm still learning IOCP but with blocking sockets in case someone would say something in chat I would have to get a list of currently connected clients and wait for each send function to return. That sounds extremely bad. But as far as I understood with IOCP you queue up messages with WSASend then the completion port will signal one of the worker threads. I created the topic before I knew about IOCP and currently I do not know enough to tell but this may be what I was looking for.
 
Joined
Sep 27, 2006
Messages
557
Reaction score
88
1.)server main
2.) server-> start
3.) server-> create SOCK_STREAM
4.) server-> Create a socket for the server
5.) server-> Bind the socket to a specific port
6.) server-> Start listening for connections
7.) server-> Thread the client connection (pthread or whatever thread lib)
8.) server -> StartLoop listening for connections

Recv side
1.) recv packet do what you need with the header and info (decrypt etc..)
2.) what to do after you recv it @Future wrote about the switch cases.

example: after you recv the packet and decrypted it and sent the data into the ReceivedPacket function

Code:
void CLoginServer::ReceivedPacket( ClientBased* thisclientdata, ClientPacket* packet )
{
        switch( packet->Command ) // returns the opcode header
    {
    case 0x00: // ping opcode
        break;
    case 0x65: // Greeting Packet opcode
        {
             //greeting packet handler (function)
        }
        break;
    
    default:
      // log your stuff here
    }
}

If you need more stuff on game sever and how to set that up its a lot more information.
 
Newbie Spellweaver
Joined
Aug 14, 2015
Messages
79
Reaction score
18
Thanks for the code. That's how I've been handling connections so far. But as far as I know blocking socket is the worst model in terms if performance and scalibility.
 
Joined
Sep 27, 2006
Messages
557
Reaction score
88
Ive written a blocking socket server and it was able to hold 1,000+ users. With also 50,000+ spawn monsters on the map before it started to lag like no other. So its just how you handle the code and what not.

There are some 3rd party socket librarys that you can use or you can go boost or winsock2.

Some reading material

 
Newbie Spellweaver
Joined
Aug 14, 2015
Messages
79
Reaction score
18
Thanks for the answer. I should've been more informative about game and it's requirements. It' s an mmorpg which lets you have 100% cast and cooldown with more than 30 usable skills for each class. There're also weekly events such as castle siegeing and race vs race which hundreds of players gather at single maps. My concern is if I use blocking sockets with one or two threads for each client it'd consume a lot of cpu and possibly crash. It may seem that I am not qualified for a project on such scale but I'm willing to learn a lot of things. I just need a point in the right direction.
 
Joined
Sep 27, 2006
Messages
557
Reaction score
88
Look at some of the C++ source code that exist here on ragezone it will give you a good start as to how to build a server. With the correct hardware any crap server can handle crappy code.
 
Divine Celestial
Joined
Feb 25, 2013
Messages
808
Reaction score
343
Just follow this and don't forget to use Lua for your world-server scripts

AcarX - [C++] Game server design for MMORPG Emulator - RaGEZONE Forums
 
[emoji848]
Legend
Joined
Dec 3, 2011
Messages
2,232
Reaction score
1,518
I have to agree that a web development language has not much to do with highly efficient game engines... :v
 
Divine Celestial
Joined
Feb 25, 2013
Messages
808
Reaction score
343
I have to agree that a web development language has not much to do with highly efficient game engines... :v
Lua beats JS hands down. Especially in performance :8:
 
Moderator
Staff member
Moderator
Joined
Feb 22, 2008
Messages
2,404
Reaction score
723
Take a look at this.


So, you are basically saying javascript should be used instead of lua, because it does != instead of ~= ? Really? Visual Basic arrays also start at position 1 if Im not mistaken. To say about syntax, you can't really rely in javascript. java syntax is just ugly too ^^. (personal opinion)
 
Newbie Spellweaver
Joined
Aug 14, 2015
Messages
79
Reaction score
18
I'll opt for lua since I need speed and performance. I don't mind learning a new syntax at all. Thanks for the suggestion though.
 
Divine Celestial
Joined
Feb 25, 2013
Messages
808
Reaction score
343
I'll opt for lua since I need speed and performance. I don't mind learning a new syntax at all. Thanks for the suggestion though.
It's not about learning Lua, it's about scripting in lua.
You can use some bindings or a wrapper for Lua in C++.
Just do your core in C++ and bind Lua for scripts
 
Elite Diviner
Joined
Mar 24, 2015
Messages
426
Reaction score
416
Kinda late on this, but instead of using a switch for handling by opcode, you can also use an array of handler objects. That makes it alot more organized in my opinion.
 
Back
Top