But here is one down side of multiplayer I just realized it, in c++ is is much harder than you would think. It is doable but it is also hard for people who haven't done networking before.
I myself have only done getting some text off a webpage and that was getting hard already. And then for multiplayer you have to do that constantly without wasting too much bandwidth, cpu, etc. and it all adds up. In order to do it efficiently you have to be thoughtful about what you transfer and send which is a why we need a static universe for it. But then we also need to do other things with it. Here are the
minimum things we need to transfer.
some of these things can be rpc calls but still it is alot
- time
- player locations
- news
- stocks
- Player's traces
- Player's money
- Player's gateway
- Slow traces for each player
- logs
- companies servers and everything on them (what software, data, etc.)
this is just a small list but
everything transferred costs something in bandwidth and somewhat cpu.
now do this list (transfer every item in the list at once and looping it) and do it in-efficiently and you have a game that uses 2mb of bandwidth per second which is alot (you may not think it is alot but it really is). so you need to think about what is constantly changing and send that to all the players, but then the things that don't change constantly like bank money, firewalls being up or down, etc. make those rpg calls. Now do this all from the main central server to get a anti-cheat proof game. You need to send the players commands (keyboard mouse clicks) to a server and then the server validates them and if they are valid sends the result back to the player and then also to all the to the other players. But now here is another problem there is a thing called connection speed if your connection is slow for every click you might have to wait 5 milliseconds or more to get a result back. So, you need to add one more thing client side prediction, where the player sends the key commands to the server and then the client will also do what it thinks the server will do so that there is no lag, but then if the client is wrong the player has to be moved back to the state the server thinks that player should be in.
Now all of this has to be done and this is why multiplayer is hard in c++ (and programing langs in general) because you have to do all this, be mindful of your bandwidth and cpu usage, make a good client side prediction that is 99.9% of the time never wrong, make a server to receive all the data, and then send it back to the player in a reasonable time (the server must be a good server not a crap one (one with a pentium 3 1.0ghz cpu and 256mb of ram) ).
This is why multiplayer should be something we do but after we implement single player to where everyone likes it. Multiplayer shouldn't be something we add right away.
Edit:
opps, I did it again
I made a 3 post
in a row.
(sing that to the hits song from 2000 (I think) )
Edit: one more thing we need to do encryption
Encrypt all the data the player sends so that it is
- not readable by the player to hack
- not readable by anyone but the server
now you have to do this on the fly but make sure that data is secure.
this is what adds another thing to networking which is hard. You have to choose what to encrypt because encrypt takes up more bandwidth generally, encryption takes more cpu usage, encryption is only necessary for things the player should not be able to change outside of the game (like the money of the player but not the time, etc.). Now you really need client side prediction because the server has to also un-encrypt the data which takes more time and with more players it becomes even harder. Now if you have 5 players on one server it is fine but (here is a scenario for you)
15 players can join a server which doesn't use encryption
how many can join with encryption and keep the same time (amount of lag etc.)
Well lets find out
First we need to decide on an encryption method.
md5? pretty quick but not hard to crack.
md5 with some salt? pretty quick but now the server can't crack it and neither can the player
sh-a2 512? not so quick to encrypt and pretty hard to decrypt
custom method? (the best solution) You need to make a custom method which changes all the character's around etc.
Now with are encryption being a custom method (a random name, cmpt) we can go on to the server side and deal with time,
so how long does it take to encrypt some data in our custom encryption method?
lets say for practical purposes 1 millisecond.
so how long to decrypt? let's take the same amount of time 1 millisecond. (now here is where it gets interesting)
15 players on one server unencrypted
they now all take the same time to connect and receive data 15 milliseconds
now add the encryption and inorder to get the same time to receive data you can only support 13 players (add 2 milliseconds to each player, client side encryption and server side encryption)
now the more players you want you need to do one of 2 things (I think)
A. Get a faster server with a faster connection
Works to a point but then lets say 1500 people that needs to be one powerful server (a super computer most likely). Now that is really expensive
B.have multiple load balancing servers. (one in each continent, North America, Europe, Asia, etc.)
The best solution (I think).
The advantages
- Less time for a person in Asia to connect to the server in North America (because they only connect to the one in asia)
- Can support more people without a really expensive single computer
Those are the main two advantages
Now the disadvantages.
- Expensive (less than the super computer idea but still expensive)
- The servers now have to communicate with each other
- who is the master one which decides who is right? (see Section B)
- You now need a really fast connection for each server to each other
Section B:
Who is right?
now here is one solution to that, the worst solution.
Add all the data of the other servers that this server doesn't have and keep everything else I already have.
Advantages:
None
Disadvantages:
The servers will get out of sync pretty quickly and in the end the servers might be giving the player a negative time value or might just give the player his data he already has back.
now let's find a good solution
How about change all you have to what the other servers have? nope, one server will then become the master server and you lose your data about players in your area.
How about compare the servers and see which one is the best? best solution.
Now how do we go about and do this?
We take all the data from all the other servers and compare them and then on each point take the majority.
Time for example.
server 1 has the time being 10:13pm
server 2, 3, 4, 5, 6, 7 have it being 10:12pm.
Server 1 is wrong and so corrects itself to what the other servers say.
Now you might wonder what happens if the servers all have different things?
this
should never happen if you write the code correctly but then again if you don't you can always have a web interface where a server operator can correct the values on all the servers.
Now don't you think this is kinda slow? well yes it actually is but if you ad one more thing into the game? server-side prediction. The server sends out what it has since it last contacted the other servers and goes with what is says but when it gets the other data from the servers if it finds it isn't in the majority on something it issues a correction to all of it's players.
problem solved.
Now any other problems with this way of networking? none I can think of.
But now you see how complex networking can get. You have a bunch of things to factor in, you have to be wise about what you make synced constantly and what is an rpc call, and you have to worry about hacking. Now to make this all work good you have to be efficient which is hard but doable. Now you guys hopefully know what is involved with networking and now understand why it shouldn't be done right away and made a sure feature.
some of this I bet is wrong in some views but hey it is my opinion and some facts.
correct me on any of this.
Also to the mods and admins you can if you feel it is necessary move this into another topic (but I don't think it is).
Edit:
One more thing which I will not talk about much.
Bandwidth.
Everything costs something to transfer now do this will 1500 people and you have a huge amount of bandwidth, this is where you need to be efficient because bandwidth is really what can kill games, a person with a dsl connection like most have is 768kb which is slow and so the less you transfer the more people will play. This is where you can use compression but then again it takes more strain on the computers un-compressing and compressing files, but if the files are small you can do it quickly enough to make it work.
My lesson for the day.
Multiplayer and Networking.