Network programming

Nightinggale

Deity
Joined
Feb 2, 2009
Messages
5,281
I just pushed a change, which is the first step in making CMC network safe.
[party]:dance::dance::dance::band:

Full log entry here: http://sourceforge.net/p/colonizati.../ci/13c8354d2bd434b87814187a3f8d0d3def1acd64/

When the human player clicks on a button, it creates a popup or python event. Those events leads to CvPlayer::setCurrentResearch(). This function then change something inside CvPlayer.

The problem is the trigger. It only happen when the user clicks something. If we have two computers in a network, only one of them have the click event.

The solution is actually pretty simple. Instead of calling CvPlayer::setCurrentResearch(), we should call gDLL->sendPlayerAction(ePlayer, PLAYER_ACTION_CHANGE_CIVIC, eNewResearch, 0, 0);

This will trigger CvPlayer::doAction(), which gains the arguments from sendPlayerAction(). This function then calls CvPlayer::setCurrentResearch().

The reason why this works in network games is that gDLL->sendPlayerAction() is triggered on one computer, then it is transmitted on the network and afterwards all computers execute CvPlayer::doAction() in sync.

The rule for then to use this is simple: if it is a user input, which changes something important (like everything in savegames), then it should be transmitted though the network.

CvDLLUtilityIFaceBase.h is full of network transmitting functions. The most likely to be used by our code will be
class|send|receive
city|sendDoTask()|CvCity::doTask()
player|sendPlayerAction()|CvPlayer::doAction()
unit|sendDoCommand()|CvUnit::doCommand()

I don't think we will gain network support anytime soon, but writing this will hopefully help preventing more code from being written, which will have to be rewritten later.


Maybe it will be easier to understand if the codechange is viewed in smartGIT's log rather than in a browser.

EDIT: reading the post after I posted made me realize it makes it look more complex than it really is :(
Coding network safe code isn't complex if you know how it works. Sadly Firaxis didn't document this feature, which is what I have to make up for.
 
I love multiplaying civ games and would really want to play Medieval MP too. But just wondering if your work is worth the effort? Chances are that I could find few players from this forum and play just few games overall. Same most likely applies to other players too.

Or does someone play for example RaR multiplayer frequently? (I could play some RaR some day, if I just can find someone wanna play with me...)
 
Or does someone play for example RaR multiplayer frequently?

I get reports of people playing RaR multiplayer (Hotseat, LAN, PBEM, ...) quite regularly.
But usually those people play with their (long-known) friends and only seldomly with people they don't know.

I even heard about people playing RaR multiplayer with their own girlfriend or wife ! :eek:

Both, TAC and RaR, have a quite active multiplayer community.
(TAC probably even more than RaR because TAC exists longer.)

So yes, a Civ4Col-Mod should pay at least a bit of attention to MP-capability.

But this is really off-topic. :)
 
Well, I'm surely not complaining if M:C is one day multiplayer compatible :) I was just wondering if it's big effort to fix everything that's needed for MP to work. Compared to using that time for other features. But I won't be complaining, if nightingale gets it through.
 
Or does someone play for example RaR multiplayer frequently? (I could play some RaR some day, if I just can find someone wanna play with me...)
I'm quite sure I played more over the internet this year than I played singleplayer (disregarding testing code changes). I fixed every single network issue I encountered and it would appear to give the same stability in singleplayer as well as network games.

If we look at http://www.gameranger.com/games/pc/ we can see that they support finding players for the following games:
  • Civilization IV
  • Civilization IV: Beyond the Sword
  • Civilization IV: Colonization Commandos
  • Civilization IV: Fall from Heaven II
  • Civilization IV: Warlords
I'm a bit surprised to see FFH there, but it tells me that people seem interested in finding people to play against. Gameranger is great to find random people to play with.

But yeah that is a bit off topic for how to code safe code :)
 
I am the one for the most part who messed up network capabilities.
I blame Firaxis for not telling how the code works. Way too many modders are unaware and write code, which works in singleplayer when they test it and have no idea why multiplayer broke. Odds are that I would have done the same if I didn't have prior network coding experience to rely on. I figured this out because I knew what I had to do and started scanning the code for vanilla function names dealing with this.

Btw I'm not too happy with how Firaxis solved this. The interesting part is in the exe (fair enough), but then they reduced the number and types of arguments to a bare minimum for what vanilla needs. This is modder un-friendly and we can easily run into lack of space. We will deal with that if needed.

I'll be sure to keep this in mind and look for issues myself.
That's the main goal for this thread :)

However I figured out how to look for issues. Smartsynchronize appears to use the same diff code and interface as smartGIT and it can detect changes between directories, which aren't part of git. Using this I compare DLL_sources with vanilla code and can see the new python interface functions. Presumably the new ones are all broken while the vanilla ones work as intended. At least that assumption appears to be a good place to start.

The same goes for popup window clicks. I'm not sure we need to sync anything else over the network. Non-GUI stuff will not need to be synced. If say a city has 200 food, it makes a new unit. All computers have 200 food in the city and will do the same calculation and hence get the same result even without communicating with each other.
 
Due to a bugreport for RaR I have become aware that the steam version butchered networking. It is no longer possible to use Direct IP connection and Internet servers using mods will not show up in the list, hence playing with mods is no longer possible.

There is a thread on the 2k forum where people want direct IP connection back. They only talk about civ4. Perhaps we should sign up and post about colo too. Also can somebody confirm that Direct IP connection is in fact gone from the steam version?

http://forums.2k.com/showthread.php?563191-Steam-multiplayer-update-and-Civilization-IV-Pitboss
 
I still can hardly believe that Steam has done something that stupid. :confused:
(But everything I have heard so far, seems to confirm it.)

If Steam really killed MP games with mods for their version, they most likely have not only butchered networking,
they will have butchered their own sales for Civ4 and Civ4:Col !
 
I have a little update on handling how to make the game stay in sync.

http://forums.civfanatics.com/showpost.php?p=13756026&postcount=66

While it will not fix network sync itself, it will help to figure out what went wrong, which is way better than the vanilla approach, which is "network sync mismatch. The player with the different score should log out and log in again". That doesn't really help identifying the bug causing the desync.

Also about steam, they added the ability to downgrade to the previous version, which brings back direct IP connection and mod support. At least that was the last I read about it. Ideally they should make a new version, in which mods works with the standard install, but I don't know if they have done that.
 
Top Bottom