Apolyton Archive  |  Preserved copy of the Apolyton Civilization Site and its forums as they stood in September 2005. Read-only; nothing here can be posted to or replied to.  |  Forum index |  About this archive |  The 1998–2001 UBB forums
Today on Apolyton WARDELL INTERVIEW PROMO A.C.S. HISTORY CHAPTER 4 GET CIV4 /w FREE PLUS! A.C.S. PHOTO GALLERY GET A.O.M. V1.1
Apolyton Civilization Forums
main| civ2| civ3| civ4| smac| ctp2| ron| moo3| galciv| galciv2| alt| about|
ApolytonPLUS | register | search | faq | new posts | pm (-/-) | upload | members
hall of fame new! | civgroups | civgroups news | interviews | the column | radio | chat | directory | news | store | PLUS
Apolyton Civilization Forums : Powered by vBulletin version 2.0.3 Apolyton Civilization Forums > Call To Power II > CtP2-Source Code Project > Trying to understand how networking is done
Show a Printable Version | Email This Page to Someone! | Receive updates to this thread | Report this to Apolyton news!
CivGroups
CTP2 Source Code Project (59): Not a Member - Join

bottom of page
  
Author
Thread    < Last Thread     Next Thread > Post New Thread     Post A Reply
kaan is offline kaan
Prince
Aarhus
Mar 2001
time: 05:21
  Old Post 11-10-2004 01:46
Edit/Delete Message Reply w/Quote
#1 Report this post to a moderator
Trying to understand how networking is done Support Apolyton, buy Civilization: The Boardgame

Hi all

Im trying to figure out what goes on with networking and this is what i have come up with so far.

The basic network I/O seems to be in place and working somewhat well so i opted not to investigate that part too much.
in /net/general there is a lot of files named net_something and that something is most of the time a name of a class in /gs/gameobj.
the purpose of those files seems to be to pack and unpack the corresponding gameobject for net transfer.
Also in /net/general is the class Network. Network acts as the main entrypoint to network activities from the rest of the code where it is instantiated as g_network

Then there is the question: what makes it tick?
I havent really been able to understand that part yet but it has to do with events and is tightly integrated into the normal event operations of the game (wich i have a hard time comprehending as well).

Then how do you go about getting information propagated to the rest of the network?
Heres a few examples:

code:
void WonderTracker::AddBuilt(sint32 which) { m_builtWonders |= (uint64)1 << (uint64)which; if(g_network.IsHost()) { g_network.Enqueue(new NetInfo(NET_INFO_CODE_BUILT_WONDERS, (uint32)(m_builtWonders & 0xffffffff), (uint32)(m_builtWonders >> (uint64)32))); } }


This peice of code seems to propagate the fact that a wonder has been build from the host.
Couriusly i havent found any place where the client tells the host that it has completed a wonder.

code:
void BuildQueue::Clear(BOOL fromServer) { if(!fromServer && g_network.IsClient() && g_network.IsLocalPlayer(m_owner)) { g_network.SendAction(new NetAction(NET_ACTION_CLEAR_QUEUE, (uint32)m_city)); } else if(g_network.IsHost()) { g_network.Block(m_owner); g_network.Enqueue(new NetInfo(NET_INFO_CODE_CLEAR_QUEUE, (uint32)m_city)); g_network.Unblock(m_owner); } while (m_list->GetHead()) { if (m_list->GetHead()->m_category == k_GAME_OBJ_TYPE_WONDER) { m_wonderStopped = m_list->GetHead()->m_type; g_theWonderTracker->ClearBuildingWonder(m_wonderStopped, m_owner); } delete m_list->RemoveHead(); } Assert(m_list->GetCount() == 0); }


This peice of code contains handling of both the client action and the host propagating it to the rest of the players. This might be the place to correct bug #26 "* Added check for clear queue actions from clients received after they lost the city to another player".

I suspect that the chat functions might be a good place to look if you want to know more about real time data transfer but i hasnt been in my interest.

I hope you will give me some usefull feedback to this

-klaus

kaan is offline kaan
Prince
Aarhus
Mar 2001
time: 05:21
  Old Post 11-10-2004 03:43
Edit/Delete Message Reply w/Quote
#2 Report this post to a moderator
Got spare money?

code:
void BuildQueue::Clear(BOOL fromServer) { #if !defined(ACTIVISION_ORIGINAL) // possible bug 26 solution if (m_owner == m_city->GetOwner()) { #endif if(!fromServer && g_network.IsClient() && g_network.IsLocalPlayer(m_owner)) { g_network.SendAction(new NetAction(NET_ACTION_CLEAR_QUEUE, (uint32)m_city)); } else if(g_network.IsHost()) { g_network.Block(m_owner); g_network.Enqueue(new NetInfo(NET_INFO_CODE_CLEAR_QUEUE, (uint32)m_city)); g_network.Unblock(m_owner); } while (m_list->GetHead()) { if (m_list->GetHead()->m_category == k_GAME_OBJ_TYPE_WONDER) { m_wonderStopped = m_list->GetHead()->m_type; g_theWonderTracker->ClearBuildingWonder(m_wonderStopped, m_owner); } delete m_list->RemoveHead(); } Assert(m_list->GetCount() == 0); #if !defined(ACTIVISION_ORIGINAL) // possible bug 26 solution } #endif }


this might do the trick

can someone compile this with the latest source and post it here so that it might be playtested?

Attachment: bldque.zip
This has been downloaded 0 time(s).

EPW is offline EPW
King
California, USA
Jan 2004
time: 21:21
  Old Post 11-10-2004 03:51 Visit EPW's homepage!
Edit/Delete Message Reply w/Quote
#3 Report this post to a moderator
Browse Apolyton AD-FREE

Could you make a check to make sure non-host players get their pw every turn? I have know idea how these things work so feel free to ignore me

kaan is offline kaan
Prince
Aarhus
Mar 2001
time: 05:21
  Old Post 11-10-2004 04:20
Edit/Delete Message Reply w/Quote
#4 Report this post to a moderator
Suffering from ads?

quote:
Originally posted by EPW
Could you make a check to make sure non-host players get their pw every turn? I have know idea how these things work so feel free to ignore me


Well the reason i wrote this is that i have almost no idea myself

Writing it and reading it again made me think though.
There is a class called net_action and in it is a very long switch that contains this bit of code:

code:
case NET_ACTION_CLEAR_QUEUE: { DPRINTF(k_DBG_NET, ("Client %d clearing queue for city %lx\n", index, m_data[0])); Unit city(m_data[0]); #if !defined(ACTIVISION_ORIGINAL) // possible bug 26 solution if(g_theUnitPool->IsValid(city) && city->GetOwner() == index) { city.GetData()->GetCityData()->GetBuildQueue()->Clear(); } #else if(g_theUnitPool->IsValid(city)) { city.GetData()->GetCityData()->GetBuildQueue()->Clear(); } #endif break;


The trained eye will spot the changes i made, this might also be a place to solve the #26 bug.

Attachment: net_action.zip
This has been downloaded 0 time(s).

kaan is offline kaan
Prince
Aarhus
Mar 2001
time: 05:21
  Old Post 11-10-2004 17:11
Edit/Delete Message Reply w/Quote
#5 Report this post to a moderator
Support Apolyton, buy Galactic Civilizations: Deluxe Edition

This might be the solution for bug #30

"* Network object bookkeeping gets cleared when exiting a game (exiting and rejoining occasionally left something lying around, resulting in a resync not long after joining)"

code:
void Network::RemovePlayer(uint16 id) { DPRINTF(k_DBG_NET, ("Removing player %d\n", id)); if(id == m_pid) { SessionLost(); #if !defined(ACTIVISION_ORIGINAL) // possible bug 30 solution // removing object bookkeeping if (m_gameObjects) delete m_gameObjects; #endif } ...


-klaus

Attachment: network.zip
This has been downloaded 0 time(s).

child of Thor is offline child of Thor
Emperor
UK
Jan 2002
time: 05:21
  Old Post 11-10-2004 17:47
Edit/Delete Message Reply w/Quote
#6 Report this post to a moderator
Support Apolyton, buy Call to Power 2

well good luck kaan! i think if MP can be sorted a bit, then many people will be super happy

Locutus is offline Locutus
ACS CTP1/2 Manager & Civ4 Co-Manager
Hengelo, The Netherlands
Nov 1999
time: 06:21
  Old Post 11-10-2004 17:59 Visit Locutus<br><img src=/forums/images/staff-icon.gif>'s homepage!
Edit/Delete Message Reply w/Quote
#7 Report this post to a moderator
Increase Your PM Length

Fantastic to see someone's finally tackling MP

I can't offer it myelf, but hopefully you'll get the support needed to bring it at least on par with 1.11...

J Bytheway is offline J Bytheway
Emperor
England
Jul 2001
time: 05:21
  Old Post 11-10-2004 19:34 Visit J Bytheway's homepage!
Edit/Delete Message Reply w/Quote
#8 Report this post to a moderator
Re: Trying to understand how networking is done Support Apolyton, buy Alpha Centauri

quote:
Originally posted by kaan
code:
void WonderTracker::AddBuilt(sint32 which) { m_builtWonders |= (uint64)1 << (uint64)which; if(g_network.IsHost()) { g_network.Enqueue(new NetInfo(NET_INFO_CODE_BUILT_WONDERS, (uint32)(m_builtWonders & 0xffffffff), (uint32)(m_builtWonders >> (uint64)32))); } }


This peice of code seems to propagate the fact that a wonder has been build from the host.
Couriusly i havent found any place where the client tells the host that it has completed a wonder.


That's not so curious. The host doesn't need to be told that the client completed a wonder, because it will determine this fact for itself when it processes the turn of the player in question. What is strange is that the client needs to be told. I'm not sure whether clients do any kind of processing at all, or whether the host works everything out and then just tells the client what has happened...

quote:
code:
void BuildQueue::Clear(BOOL fromServer) { if(!fromServer && g_network.IsClient() && g_network.IsLocalPlayer(m_owner)) { g_network.SendAction(new NetAction(NET_ACTION_CLEAR_QUEUE, (uint32)m_city)); } else if(g_network.IsHost()) { g_network.Block(m_owner); g_network.Enqueue(new NetInfo(NET_INFO_CODE_CLEAR_QUEUE, (uint32)m_city)); g_network.Unblock(m_owner); } while (m_list->GetHead()) { if (m_list->GetHead()->m_category == k_GAME_OBJ_TYPE_WONDER) { m_wonderStopped = m_list->GetHead()->m_type; g_theWonderTracker->ClearBuildingWonder(m_wonderStopped, m_owner); } delete m_list->RemoveHead(); } Assert(m_list->GetCount() == 0); }


This peice of code contains handling of both the client action and the host propagating it to the rest of the players.


In this case, it makes sense that the client must tell the host, because this is a user-triggered event and so there is no way the host would be able to work out for itself that it occured.

kaan is offline kaan
Prince
Aarhus
Mar 2001
time: 05:21
  Old Post 11-10-2004 23:57
Edit/Delete Message Reply w/Quote
#9 Report this post to a moderator
Re: Re: Trying to understand how networking is done Increase Your PM Length

quote:
Originally posted by J Bytheway


That's not so curious. The host doesn't need to be told that the client completed a wonder, because it will determine this fact for itself when it processes the turn of the player in question. What is strange is that the client needs to be told. I'm not sure whether clients do any kind of processing at all, or whether the host works everything out and then just tells the client what has happened...

quote:
code:
void BuildQueue::Clear(BOOL fromServer) { if(!fromServer && g_network.IsClient() && g_network.IsLocalPlayer(m_owner)) { g_network.SendAction(new NetAction(NET_ACTION_CLEAR_QUEUE, (uint32)m_city)); } else if(g_network.IsHost()) { g_network.Block(m_owner); g_network.Enqueue(new NetInfo(NET_INFO_CODE_CLEAR_QUEUE, (uint32)m_city)); g_network.Unblock(m_owner); } while (m_list->GetHead()) { if (m_list->GetHead()->m_category == k_GAME_OBJ_TYPE_WONDER) { m_wonderStopped = m_list->GetHead()->m_type; g_theWonderTracker->ClearBuildingWonder(m_wonderStopped, m_owner); } delete m_list->RemoveHead(); } Assert(m_list->GetCount() == 0); }


This peice of code contains handling of both the client action and the host propagating it to the rest of the players.


In this case, it makes sense that the client must tell the host, because this is a user-triggered event and so there is no way the host would be able to work out for itself that it occured.


Well i hadnt thought about it that way but it would be logical that the host is responsible for the gamelogic and that the client need only to be concerned about userinteractions.

and to the fans: thanks for the support

kaan is offline kaan
Prince
Aarhus
Mar 2001
time: 05:21
  Old Post 12-10-2004 15:59
Edit/Delete Message Reply w/Quote
#10 Report this post to a moderator
Enter the AD-FREE zone

possible bug 21 solution "* Added extra checks to disable science victory in network games"

code:
#if defined(ACTIVISION_ORIGINAL) if (GetGaiaController()->TurnsToComplete() == 0) { GameOver(GAME_OVER_WON_SCIENCE, -1); } } #else // possible bug 21 solution if (!g_network.IsActive() && GetGaiaController()->TurnsToComplete() == 0) { GameOver(GAME_OVER_WON_SCIENCE, -1); } #endif


code:
case GAME_OVER_WON_SCIENCE: #if defined(ACTIVISION_ORIGINAL) GenerateDescriptionString(TRUE); m_hasWonTheGame = TRUE; for(i = 1; i < k_MAX_PLAYERS; i++) { if(g_player[i] && !g_player[i]->m_isDead && i != m_owner) { if(!g_network.IsClient()) { g_player[i]->GameOver(GAME_OVER_LOST_SCIENCE, -1); } } } #else // possible bug 21 solution if (!g_network.IsActive()) { GenerateDescriptionString(TRUE); m_hasWonTheGame = TRUE; for(i = 1; i < k_MAX_PLAYERS; i++) { if(g_player[i] && !g_player[i]->m_isDead && i != m_owner) { if(!g_network.IsClient()) { g_player[i]->GameOver(GAME_OVER_LOST_SCIENCE, -1); } } } } #endif


Both codesnippets are from the Player class.

Attachment: player.zip
This has been downloaded 0 time(s).

kaan is offline kaan
Prince
Aarhus
Mar 2001
time: 05:21
  Old Post 20-10-2004 23:40
Edit/Delete Message Reply w/Quote
#11 Report this post to a moderator
Full PM-box? Change here!

OK heres an update


Client/Host Communication
I have found that most communication between client and host is done through 2 classes:
net_action and net_info

net_action is used to transport requests/trigger events from the clients to the host.
net_info is used to propagate information from the host to the clients and/or to execute events on the clients.

To complicate things a bit it seems that it isnt all traffic that follows this routine.


Code Structure
Much of the networking code is tangled into the "normal" code and the structure suggest that most of the code is run simultaneusly on both the host and client.
To keep that environment sane the host will often check the clients data and if nessesary request a resync.
This structure facilitates that any client can become host if the host suddently drops out of the game.

kaan is offline kaan
Prince
Aarhus
Mar 2001
time: 05:21
  Old Post 24-10-2004 16:34
Edit/Delete Message Reply w/Quote
#12 Report this post to a moderator
Lose 30 kilos (of popups)

I have been looking at the code for where battle takes place and I found it, but what I havent found is even the slightest bit of networking code relating to battle. Did any of you stumple upon anything that might be usefull?

  < Last Thread     Next Thread > Post New Thread     Post A Reply
All times are GMT. The time now is 05:21.
Apolyton Time is 00:21.
    top of page
Rate This Thread:
Forum Jump:
Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is ON
vB code is ON
Smilies are ON
[IMG] code is ON
 




Contact Us - Apolyton Civilization Site - Support Us!

Building a better Apolyton through better information. Click here and take our poll!
Non-US visitors, click here!

Powered by: vBulletin Version 2.0.3
Copyright ©2000, 2001, Jelsoft Enterprises Limited.

Page generated in 0.0390 seconds (89.20% PHP - 10.80% MySQL) with 36 queries
Page Loading Time:

Support Apolyton: Amazon USA | Amazon UK | Amazon DE | Amazon FR |
Support Apolyton and get FREE PLUS, Buy from Chips&Bits: Galactic Civilizations | Galactic Civilizations: Deluxe Edition | Call to Power 2 | Civilization: The Boardgame | GURPS/ Alpha Centauri | Alpha Centauri | Civilization IV | Civilization III: Complete |


Front Page | Civilization IV | Civilization III | Civilization II | Call to Power II | Alpha Centauri | Master of Orion III
Rise of Nations | Galactic Civilizations | Galactic Civilizations II | Misc
Alt.Civs | Civ I | C:CtP I | About | News | Directory | Apolyton Store | Forums | Chat | Columns | Interviews | Newsletter
Scenario League | CSC | Clash of Civs | Spanish Site | CtP Maps | Cradle of Civ | WesW's Ctp1/2 Site | Civ3 Haven

apolyton.net | apolyton.com | civilization2.net | civilization3.net | civilization4.net | civilizationiv.info | calltopower.net | galciv.net | galciv2.net | moo3.net