Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Understanding of Client-Server Architecture - MMO example  (Read 7981 times)

0 Members and 1 Guest are viewing this topic.

Alter

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Understanding of Client-Server Architecture - MMO example
« on: February 05, 2017, 05:06:48 pm »
Hello, my name is Artur and I am 3rd year IT student from Poland. For my final task before finishing my university I took something I always dreamed about but never got to work on, MMORPG. The whole journey with programming and IT overall started because of one simple MMORPG Tibia. It might sound ridiculous but I was fascinated and amazed with this game so much that I wanted to learn stuff to be able to change their open source code as I please and create amazing Open Tibia Server which could also become a good income. Well, as time goes on I learned many things and I graduated from being able to edit simple XML script to create new functionalities inside the source code. As now I am, I already wrote some simple games in Javascript, C++ using SFML. In free time I used to solve tasks on SPOJ, I got back to this like 5 days ago as well and am doing pretty well as for beginner.

That's it for story and introduction. I always dreamed of creating great game but never actually had enough of determination to sit down and do it. Now I decided that there is no way back and it's time for something big. To learn good programming habits, to make something what I could show my employer as show for what I am capable of. My last project to graduate from my university with engineer degree is MMORPG written in C++ using SFML library.

I managed to write simple Tic-Tac-Toe multiplayer using Tcp Sockets so I have some experience with networking but it's not client-server architecture. So the whole MMO in MMORPG stands for Massive Multiplayer Online. Massive means that even up to 500-1000 clients might be connected to server at one time. Here goes the question or advice.  How to do it ? I already managed to get hold of basics and read about Quake UDP Client-Server Architecture. Here is my idea of how it works/could work:

Client:

1. We click on Start Game for example.
2. We type our username/password.
3.a) We are biding socket to connect with server.
3.b) We are sending "Handshake" message to server and wait for response.
3.c) We receive response (or we don't, then after X time we get problem with connection message)
4. We send our username/password to server.
5. We receive message (username/password not correct or our character/account data to render).
6. We render what we got (Character select menu for example)
7. We try to login to the game server so we send request to the server and wait for response again.
8. We receive data about our character and map which we need to render our game window.
9. We are sending requests/receiving replies all the time(update on npc movement, update on server time, update on chat, movement etc.)

Server:
1. We are loading everything to game world (map,monsters,database connection, spells, items,scripts)
2. We are binding socket to desired port.
3. We are waiting for connections/data requests(?)
4. We add verificated clients to our vector of clients / prepare replies for data requests.

//Here is something I am not sure about, we are receiving new connections in one thread and send data to those who connected already in other thread ? We use one thread for both like, first we check for other connections, send handshakes, save client to vector of clients and then check data requests ? Or maybe just use switch and depending on request, do something ? But then how to manage it with saving ip and port of clients to vector ?

Should it work like that? :
a) We wait for any packet
b) We make switch for packet byte and depending on what we receive, we do other thing ?
So we know then that if it's handshake then player is sending on other data his ip and port, if it's movement request then he sends only which direction he wants to move, if it's using something then other action etc.

But then it would be like

packet>>id_handshake>>client_ip>>client_port // for Handshake
packet>>id_movement>>enum Direction//for Movement

So should it work like this then?

packet>>id_handshake>>message [client_ip+client_port] // Handshake
packet>>id_movement>>message [enum Direction] // Movement

and using char/string functions should I extract data I need to their respective types ?

How do we send like whole map of objects, layers and stuff then ? It's complicated. It's really interesting but complicated for someone who is throwing himself into deep water as well.

Also why we need Selectors ? We have many clients but one socket which we bind into one port, right ?

sf::UdpSocket socket;
socket.bind(port);
socket.receive(packet,ip,port);
socket.send(packet,ip,port);

It doesn't work for many clients like this?:

for(int i=0;i<client_vector.size();i++)
{
socket.receive(packet,client_vector[i].getIp(),client_vector[i].getPort());
//Prepare packet depending on last request
socket.send(packet,client_vector[i].getIp(),client_vector[i].getPort());
}


I am new at it but I think that I am not too far off and in one year I will be able to complete my task and make my little dream come true. So far, so good. I managed to make simple client-server where server receives every client's IP and Port with information that client wants to connect to the server and sends back confirmation of connection. I have a lot to do but time is on my side. I will appreciate any valuable information, advice and clue. Thanks in advance !
« Last Edit: February 05, 2017, 07:08:40 pm by Alter »

Arcade

  • Full Member
  • ***
  • Posts: 230
    • View Profile
Re: Understanding of Client-Server Architecture - MMO example
« Reply #1 on: February 06, 2017, 05:38:21 pm »
I haven't yet spent the time to read through and try to understand your network architecture, but if you don't mind me offering some general advice:
  • I suspect you may get better help on a different forum. I see you are trying to use SFML to do your networking, but your questions seem to be more about general game design, not on how to use SFML. The topics on this forums are generally about SFML itself
  • You may already be aware of this, but making a full-blown MMORPG is a huge task, even for very experienced programmers. Even RPG games without the multiplayer aspect can be quite an undertaking (character dialog, item inventory, combat, etc). I don't mean to offend, but for what sounds like a single inexperienced programmer,  completing an MMORPG is quite an ambitious project. Perhaps you have something much simpler in mind than a traditional MMORPG, but if you chose this project for yourself and it wasn't assigned to you I just want to make sure you're thinking about realistic goals.
  • Don't be scared to experiment with your code and see what works for you. Some of your questions could maybe be answered by just trying it out and seeing what you do or don't like about it. Then you can come back here or a different forum with more specific questions on how to fix or improve your design.

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Understanding of Client-Server Architecture - MMO example
« Reply #2 on: February 06, 2017, 06:56:11 pm »
Am I understanding you right, thid project is part of your studies at university?
Do you have a professor who supports you? If so, some questions might be better discussed with them and the first thing you should do is set a scope and set a rough plan of the whole project.

Some of your question are quite general, so you need to keep in mind that there isn't just one solution, but pretty much anything can be made to work. It then often comes down to personal preferences. ;)

My advice is to get a very, very, very basic RPG implemented - it's a lot more work than you might think - and then from there on get it working for only a few clients. If there's still enough time you can try c scaling to up to hundred clients.
Thing is, without actually having real 100+ users, you can't easily test your network, server or client code. It might work with 10 clients but when you have 30 clients with different packet loss and RRT things might suddenly break apart or the rendering fails when everyone is in one location, etc.

Maybe you can narrow down your collection of questions to a few important ones. ;)

I wish you all the best and hope you get a large portion of your dream come true.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Alter

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Understanding of Client-Server Architecture - MMO example
« Reply #3 on: February 07, 2017, 04:28:08 am »
I haven't yet spent the time to read through and try to understand your network architecture, but if you don't mind me offering some general advice:
  • I suspect you may get better help on a different forum. I see you are trying to use SFML to do your networking, but your questions seem to be more about general game design, not on how to use SFML. The topics on this forums are generally about SFML itself
  • You may already be aware of this, but making a full-blown MMORPG is a huge task, even for very experienced programmers. Even RPG games without the multiplayer aspect can be quite an undertaking (character dialog, item inventory, combat, etc). I don't mean to offend, but for what sounds like a single inexperienced programmer,  completing an MMORPG is quite an ambitious project. Perhaps you have something much simpler in mind than a traditional MMORPG, but if you chose this project for yourself and it wasn't assigned to you I just want to make sure you're thinking about realistic goals.
  • Don't be scared to experiment with your code and see what works for you. Some of your questions could maybe be answered by just trying it out and seeing what you do or don't like about it. Then you can come back here or a different forum with more specific questions on how to fix or improve your design.
Don't worry, I am thinking about some simple stuff to begin with. No full-blown MMORPG, just simple functionalities like moving around, seeing other characters movement. Nothing big but something to begin work with. I am going to experiment a lot, don't worry about it :P

Am I understanding you right, thid project is part of your studies at university?
Do you have a professor who supports you? If so, some questions might be better discussed with them and the first thing you should do is set a scope and set a rough plan of the whole project.

Some of your question are quite general, so you need to keep in mind that there isn't just one solution, but pretty much anything can be made to work. It then often comes down to personal preferences. ;)

My advice is to get a very, very, very basic RPG implemented - it's a lot more work than you might think - and then from there on get it working for only a few clients. If there's still enough time you can try c scaling to up to hundred clients.
Thing is, without actually having real 100+ users, you can't easily test your network, server or client code. It might work with 10 clients but when you have 30 clients with different packet loss and RRT things might suddenly break apart or the rendering fails when everyone is in one location, etc.

Maybe you can narrow down your collection of questions to a few important ones. ;)

I wish you all the best and hope you get a large portion of your dream come true.

There really isn't way to tell if it will work for more clients or not ? Like writing some tests simulating connection or sending/receiving 100-1000 more packets for one client and checking how it will work out (just thinking).
I am complete newbie when it comes to networking but from what I saw, there isn't really a big magic behind it, just good piece of code to do only what is necessary and wrap it up nicely. Am I wrong ? Or maybe there are some other than bandwidth and RAM requirements to have bigger number of clients connected ? My project is scheduled for next year (basically time when my professor will start helping me and check on my documentation) but I just have to start a lot sooner to be able to make it in time, at least that's what I think. I will do my best to make it true ! I just need one more week to pass semester and then I can go all out on learning things necessary for my project.

My the most important questions would be:

1. Are the sockets in SFML any different than sockets used in global network ?
2. What would be your way of handling packets in UDP socket.
3. Selectors are used to manage mutliple sockets, right ? But when you make server, you create ONE socket and bind it to desired port. Would you use selectors in UDP Socket based connection ? If yes then why ?
What are advantages of selectors and when should I use them ?
4. Should I store IP and port of each client connecting/connected to my server ?
5. There is something like local Ip and global Ip. Why when I set my global Ip as remote IpAddress for server on client, I can't connect to the server ? It works only with local Ip.

I really appreciate any help. Thank you :)
« Last Edit: February 09, 2017, 01:40:02 pm by eXpl0it3r »



eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10815
    • View Profile
    • development blog
    • Email
Re: Understanding of Client-Server Architecture - MMO example
« Reply #6 on: February 09, 2017, 01:40:16 pm »
There really isn't way to tell if it will work for more clients or not ? Like writing some tests simulating connection or sending/receiving 100-1000 more packets for one client and checking how it will work out (just thinking).
You can maybe test most of the software with simulation, but you can't forget that real connections also use hardware and drivers. So for complete tests, you will have to test how it runs with real clients.

1. Are the sockets in SFML any different than sockets used in global network ?
SFML provides a simplified and uniform API over system network sockets.

2. What would be your way of handling packets in UDP socket.
Packets as in sf::Packet or UDP packets? Basically, see the documentation.

3. Selectors are used to manage mutliple sockets, right ? But when you make server, you create ONE socket and bind it to desired port. Would you use selectors in UDP Socket based connection ? If yes then why ? What are advantages of selectors and when should I use them ?
When you have only one UDP socket, i.e. bound to one port, then there's no need for a socket selector. UPD sockets are "simpler" in that regard.
As mentioned in the documentation, you should use a selector when you have multiple sockets to deal with. For TCP which is connection based, you can use a listener that will sever the different connections as dedicated socket, using a selector will make the most sense there.

4. Should I store IP and port of each client connecting/connected to my server ?
You have to, if you don't know your client's IP, you won't be able to respond to them (via UDP).

5. There is something like local Ip and global Ip. Why when I set my global Ip as remote IpAddress for server on client, I can't connect to the server ? It works only with local Ip.
It  sounds like you're unsure about the fact that there are different kinds of IPs, if that's the case, then you should definitely start researching there. Without a proper understanding of networking, it will be near impossible to write any kind of network game. A good starting point would be to understand what NAT is.
Basically if you use your global IP, you'll talk to your router/modem since that device actually has said IP, if you then don't do port forwarding from the router, the router will just block the connection.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Alter

  • Newbie
  • *
  • Posts: 5
    • View Profile
    • Email
Re: Understanding of Client-Server Architecture - MMO example
« Reply #7 on: February 09, 2017, 05:23:00 pm »
Thanks for your answers. I will start researching on proper understanding of networking as soon as I will be able to write a good object oriented structure for game itself. Thank you very much :)

 

anything