Friday, November 30, 2018

c++ - How do I start writing an MMO game server?



I am developing a multi-player on-line game.


I just started coding the server but I have no idea how to do it. Do I have to use threads ?


And if i do, do I need one thread for every client?


Knowing that I am using UDP, can I use multiple sockets in different threads to send packets on the same port?


edit:


server does:


-listen for client connections

-when a client connects:

-update files (send new files to the client)

-retrieve data from database

-loop to retrieve and update live data


-when client disconnects:

-update data in database

Answer



I may be wrong, but your question makes it seem like you are missing a lot of knowledge in order to successfully write an MMO server. I know this message will likely fall on deaf ears because I was in your position when I started programming.


My answer: If I were you I would start smaller. If you want to learn to write an MMO server I would do the following.



  • Write a TCP based p2p chat client.

  • Extend that chat client to work with NAT routers


  • Extend the chat client to have a central server that authenticates and stores message history

  • Extend it to have a secure handshake with the server to verify the client software and server software/location

  • Write a high level architecture of what you would want your MMO server to be

  • Read some articles on MMO server architectures

  • Start expanding your high level architecture into more and more detail

  • Write essential user stories for your architecture

  • start implementing your server


The answer you probably want:




  • Write a thread for the listener to accept incoming connections using TCP

  • Once the player is connected, use TCP for chat messages and sector changes

  • Use UDP for in-sector movement

  • Each connection gets its own thread for the messaging

  • UDP can be implemented with threads (if you really want) but I would probably use some sort of queue on one thread that accepts movement messages. Or spread it out depending on how many connections you get.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...