1. We have added a Gift Upgrades feature that allows you to gift an account upgrade to another member, just in time for the holiday season. You can see the gift option when going to the Account Upgrades screen, or on any user profile screen.
    Dismiss Notice

Network programming

Discussion in 'Civ4Col - Medieval: Conquests' started by Nightinggale, May 1, 2014.

  1. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,986
    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
    Column 1 Column 2 Column 3
    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.
     
  2. Fullerene

    Fullerene Chieftain

    Joined:
    Aug 26, 2009
    Messages:
    228
    Gender:
    Male
    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...)
     
  3. raystuttgart

    raystuttgart Civ4Col Modder

    Joined:
    Jan 24, 2011
    Messages:
    4,446
    Location:
    Stuttgart, Germany
    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. :)
     
  4. Fullerene

    Fullerene Chieftain

    Joined:
    Aug 26, 2009
    Messages:
    228
    Gender:
    Male
    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.
     
  5. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,986
    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 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 :)
     
  6. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    That's awesome Night. I am the one for the most part who messed up network capabilities. I'll be sure to keep this in mind and look for issues myself.
     
  7. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,986
    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.

    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.
     
  8. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,986
    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
     
  9. raystuttgart

    raystuttgart Civ4Col Modder

    Joined:
    Jan 24, 2011
    Messages:
    4,446
    Location:
    Stuttgart, Germany
    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 !
     
  10. Kailric

    Kailric Jack of All Trades

    Joined:
    Mar 25, 2008
    Messages:
    3,094
    Location:
    Marooned, Y'isrumgone
    Yeah, that is sad news. I already had to buy the boxed version because I had issues with my steam version when attempting to debug.
     
  11. Nightinggale

    Nightinggale Chieftain Supporter

    Joined:
    Feb 2, 2009
    Messages:
    3,986
    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.
     

Share This Page