nNetObject Class Reference

#include <nNetObject.h>

Inheritance diagram for nNetObject:

Inheritance graph
[legend]
Collaboration diagram for nNetObject:

Collaboration graph
[legend]

List of all members.

Public Member Functions

virtual void AddRef ()
virtual void Release ()
int GetRefcount () const
virtual void ReleaseOwnership ()
virtual void TakeOwnership ()
bool Owned ()
nObserverGetObserver () const
virtual void Dump (tConsole &con)
unsigned short ID () const
unsigned short Owner () const
nMachineGetMachine () const
 returns the machine this object belongs to
virtual nDescriptorCreatorDescriptor () const =0
 nNetObject (int owner=-1)
 nNetObject (nMessage &m)
virtual void InitAfterCreation ()
void Register (const nNetObjectRegistrar &r)
virtual bool ActionOnQuit ()
virtual void ActionOnDelete ()
virtual bool BroadcastExistence ()
virtual void PrintName (tString &s) const
bool HasBeenTransmitted (int user) const
bool syncRequested (int user) const
virtual bool ClearToTransmit (int user) const
virtual void WriteSync (nMessage &m)
virtual void ReadSync (nMessage &m)
virtual void WriteSync (nMessage &m, int run)
virtual void ReadSync (nMessage &m, int run)
virtual bool SyncIsNew (nMessage &m)
virtual void WriteCreate (nMessage &m)
virtual void WriteCreate (nMessage &m, int run)
virtual void ReadCreate (nMessage &m, int run)
void WriteAll (nMessage &m, bool create)
void ReadAll (nMessage &m, bool create)
virtual void ReceiveControlNet (nMessage &m)
virtual bool AcceptClientSync () const
void GetID ()
void RequestSync (bool ack=true)
void RequestSync (int user, bool ack)

Static Public Member Functions

static bool DoDebugPrint ()
static nNetObjectObjectDangerous (int i)
static void SyncAll ()
static void ClearAll ()
static void ClearAllDeleted ()
static void ClearKnows (int user, bool clear)
static void RelabelOnConnect ()

Protected Member Functions

nNetObjectObject (int i)
void DoBroadcastExistence ()
virtual ~nNetObject ()
virtual nMachineDoGetMachine () const
 returns the machine this object belongs to
nMessageNewControlMessage ()

Static Protected Member Functions

static int SyncedUser ()
 returns the user that the current WriteSync() is intended for

Protected Attributes

nKnowsAboutInfo knowsAbout [MAXCLIENTS+2]

Private Member Functions

 tCONTROLLED_PTR (nObserver) observer_

Private Attributes

bool createdLocally
unsigned long int lastSyncID_
unsigned short id
int refCtr_
unsigned short owner
int syncListID_

Friends

class nWaitForAckSync

Classes

class  nKnowsAboutInfo


Detailed Description

Definition at line 51 of file nNetObject.h.


Constructor & Destructor Documentation

nNetObject::nNetObject ( int  owner = -1  ) 

Definition at line 707 of file nNetObject.cpp.

References createdLocally, owner, sn_myNetID, and syncListID_.

00707                              :lastSyncID_(0),
00708 id(0),refCtr_(0),owner(own){
00709 #ifdef DEBUG
00710     //con << "Netobject " << id  << " created.\n";
00711     //  if (id == 383)
00712     //   st_Breakpoint();
00713 #endif
00714     syncListID_ = -1;
00715 
00716     createdLocally = true;
00717 
00718     if (own<0) owner=::sn_myNetID;
00719 }

nNetObject::nNetObject ( nMessage m  ) 

Definition at line 775 of file nNetObject.cpp.

References createdLocally, nNetObjectRegistrar::id, knowsAbout, nNetObject::nKnowsAboutInfo::knowsAboutExistence, nSERVER, nNetObjectRegistrar::object, owner, nMessage::Read(), nNetObjectRegistrar::sender, nMessage::SenderID(), sn_GetNetState(), syncListID_, and tASSERT.

00775                                  :lastSyncID_(m.MessageIDBig()),refCtr_(0){
00776     // sn_Update(global_lastSync,lastSyncID_);
00777 
00778     id = 0;
00779     owner = 0;
00780 
00781     syncListID_ = -1;
00782 
00783     tASSERT( sn_Registrar );
00784     nNetObjectRegistrar& registrar = *sn_Registrar;
00785 
00786     createdLocally = false;
00787 
00788     m.Read( registrar.id );
00789 #ifdef DEBUG
00790     //con << "Netobject " << id << " created on remote order.\n";
00791     //  if (id == 383)
00792     //  st_Breakpoint();
00793 #endif
00794     m.Read( owner );
00795 
00796     // clients are only allowed to create self-owned objects
00797     if ( sn_GetNetState() == nSERVER )
00798     {
00799         if ( owner != m.SenderID() )
00800         {
00801             throw nKillHim();
00802         }
00803     }
00804 
00805     registrar.object = this;
00806     registrar.sender = m.SenderID();
00807 
00808     knowsAbout[m.SenderID()].knowsAboutExistence=true;
00809 #ifdef DEBUG
00810     // con << "Netobject " << id  << " created (remote order).\n";
00811 #endif
00812 }

Here is the call graph for this function:

nNetObject::~nNetObject (  )  [protected, virtual]

Definition at line 984 of file nNetObject.cpp.

References tRecorderSync< DATA >::Archive(), createdLocally, knowsAbout, MAXCLIENTS, net_destroy, nSERVER, NULL, owner, refCtr_, tList< T, MALLOC, REFERENCE >::Remove(), nDeletedInfo::Set(), sn_GetNetState(), sn_myNetID, sn_netObjects, syncListID_, tCHECK_DEST, tERR_ERROR, and tSysTimeFloat().

00984                        {
00985     // remove from sync list
00986     if ( syncListID_ >= 0 )
00987         sn_SyncRequestedObject.Remove( this, syncListID_ );
00988 
00989     // release observer
00990     if ( this->observer_ )
00991     {
00992         this->observer_->SetObject( NULL );
00993     }
00994 
00995 #ifdef DEBUG
00996     int extra=0;
00997 
00998     // account for the reference held by the creator of the object
00999 
01000     // only if the object is validly entered in our object-array
01001     if (id > 0 && static_cast<nNetObject*>(sn_netObjects[id])==this)
01002     {
01003         if ( createdLocally )
01004             extra = -1;
01005     }
01006 
01007     if (refCtr_ + extra > 0)
01008         tERR_ERROR("Hey! There is stil someone interested in this nNetObject!\n");
01009     //con << "Netobject " << id  << " deleted.\n";
01010 #endif
01011 
01012     // mark id as soon-to-be free
01013     if (id)
01014     {
01015 #ifdef DEBUG
01016         sn_BreakOnObjectID( id );
01017 #endif
01018         if ( sn_GetNetState() == nSERVER )
01019         {
01020             sn_netObjectsOwner[id]=0xFFFF;
01021             sn_freedIDs.push_back( id );
01022         }
01023         else
01024         {
01025             sn_netObjectsOwner[id]=0;
01026         }
01027     }
01028 
01029     // determine whether a destroy message should be sent: the server definitely should...
01030     bool sendDestroyMessage = (sn_GetNetState()==nSERVER);
01031     if (!sendDestroyMessage && id && sn_netObjects_AcceptClientSync[id] && owner==sn_myNetID)
01032     {
01033         // ... but also the client if the object belongs to it.
01034         sendDestroyMessage = true;
01035 
01036         // the server will send a response destroy message later. We need to ignore it.
01037         sn_LocallyDestroyedIDs.insert(id);
01038     }
01039 
01040     // send it
01041     if ( sendDestroyMessage )
01042     {
01043         int idsync=id;
01044         tRecorderSync< int >::Archive( "_NETOBJECT_DESTROYED", 3, idsync );
01045 
01046         // con << "Destroying object " << id << '\n';
01047         for (int user=MAXCLIENTS;user>=0;user--){
01048             if (user!=sn_myNetID && knowsAbout[user].knowsAboutExistence ||
01049                     knowsAbout[user].acksPending){
01050                 if (destroyers[user]==NULL)
01051                 {
01052                     destroyers[user]=new nMessage(net_destroy);
01053                     destroyersTime[user]=tSysTimeFloat();
01054                 }
01055                 destroyers[user]->Write(id);
01056 
01057                 if (destroyers[user]->DataLen()>100){
01058                     destroyers[user]->Send(user);
01059                     destroyers[user]=NULL;
01060                 }
01061 
01062 #ifdef DEBUG
01063                 //con << "remotely destroying object " << id << '\n';
01064 #endif
01065             }
01066         }
01067     }
01068     refCtr_=100;
01069     if (id)
01070     {
01071         if (this == sn_netObjects[id])
01072         {
01073 #ifdef DEBUG
01074             sn_BreakOnObjectID( id );
01075 #endif
01076             sn_netObjects[id] = NULL;
01077         }
01078 
01079         // clear object from info arrays
01080         nDeletedInfos::iterator found = sn_netObjectsDeleted.find( id );
01081         if ( found != sn_netObjectsDeleted.end() )
01082         {
01083             nDeletedInfo  & deleted = (*found).second;
01084             deleted.Set( NULL );
01085             sn_netObjectsDeleted.erase(found);
01086         }
01087     }
01088 
01089     refCtr_=-100;
01090     tCHECK_DEST;
01091 }

Here is the call graph for this function:


Member Function Documentation

nNetObject::tCONTROLLED_PTR ( nObserver   )  [mutable, private]

Referenced by eTeam::RemovePlayer().

Here is the caller graph for this function:

nNetObject * nNetObject::Object ( int  i  )  [protected]

Definition at line 1095 of file nNetObject.cpp.

References Cheater(), con, nReadError(), nSERVER, NULL, ObjectDangerous(), owner, REAL, sn_Connections, sn_GetNetState(), sn_netObjects, sn_Receive(), sn_SendPlanned(), tAdvanceFrame(), tERR_WARN, and tSysTimeFloat().

Referenced by _wrap_GSimpleAI_object(), deptest::deptest(), eNetGameObject::eNetGameObject(), and gNetPlayerWall::gNetPlayerWall().

01095                                    {
01096     if (i==0) // the NULL nNetObject
01097         return NULL;
01098 
01099     // the last deleted object with specified ID
01100     nNetObject* deleted = NULL;
01101     nDeletedInfos::const_iterator found = sn_netObjectsDeleted.find( id );
01102     if ( found != sn_netObjectsDeleted.end() )
01103     {
01104         deleted = (*found).second.object_;
01105     }
01106 
01107     // return immediately if the object is there
01108     nNetObject *ret=ObjectDangerous( i );
01109     if ( ret )
01110     {
01111         return ret;
01112     }
01113 
01114     // set new timeout value
01115     const REAL totalTimeout=10;
01116     const REAL printMessageTimeout=.5;
01117 
01118     double newTimeout=tSysTimeFloat()+totalTimeout;
01119     static double timeout=-1;
01120     if ( tSysTimeFloat() > timeout )
01121         timeout = newTimeout;
01122 
01123     bool printMessage=true;
01124     while (sn_Connections[0].socket &&
01125             NULL==(ret=sn_netObjects[i]) && timeout >tSysTimeFloat()){ // wait until it is spawned
01126         if (tSysTimeFloat()>timeout-(totalTimeout + printMessageTimeout))
01127         {
01128             if (printMessage)
01129             {
01130                 con << "Waiting for NetObject with ID " << i << " to spawn...\n";
01131                 printMessage=false;
01132             }
01133             if (sn_GetNetState()==nSERVER){
01134                 // in server mode, we cannot wait.
01135 
01136                 // the deleted object with the same ID must have been meant
01137                 if ( deleted )
01138                 {
01139                     return deleted;
01140                 }
01141 
01142                 nReadError();
01143 
01144                 con << "Now we need to leave the\n"
01145                 << "system in an undefined state. I hope this works...\n";
01146 
01147                 Cheater(owner); // kill this bastard
01148                 return NULL; // pray that noone references this pointer
01149             }
01150         }
01151         tAdvanceFrame(10000);
01152         sn_Receive();
01153         sn_SendPlanned();
01154     }
01155 
01156     if (!ret)
01157         ret = deleted;
01158 
01159     if (!ret)
01160         tERR_WARN("Netobject " << i << " requested, but was never spawned.");
01161 
01162     return ret;
01163 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nNetObject::DoBroadcastExistence (  )  [protected]

Definition at line 814 of file nNetObject.cpp.

References AcceptClientSync(), BroadcastExistence(), knowsAbout, MAXCLIENTS, nCLIENT, nSERVER, owner, RequestSync(), sn_Connections, sn_GetNetState(), and sn_myNetID.

Referenced by ClearKnows(), InitAfterCreation(), and RelabelOnConnect().

00814                                      {
00815     if (BroadcastExistence() &&
00816             ( sn_GetNetState()!=nCLIENT ||
00817               ( owner == ::sn_myNetID && AcceptClientSync() )
00818             )
00819        )
00820     {
00821         int maxUser = (sn_GetNetState() == nSERVER) ? MAXCLIENTS : 0;
00822         int minUser  = (sn_GetNetState() == nSERVER) ? 1 : 0;
00823         for (int user = maxUser; user >= minUser; --user)
00824         {
00825             // sync the object only to users that don't know about it yet
00826             if ( !knowsAbout[user].knowsAboutExistence && sn_Connections[user].socket ) // && !knowsAbout[user].syncReq )
00827                 RequestSync( user, true );
00828         }
00829     }
00830 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool nNetObject::DoDebugPrint (  )  [static]

Definition at line 1512 of file nNetObject.cpp.

Referenced by _wrap_NNetObject_do_debug_print(), gNetPlayerWall::ClearToTransmit(), eNetGameObject::ClearToTransmit(), and SyncAll().

01513 {
01514     return s_DoPrintDebug;
01515 }

Here is the caller graph for this function:

nNetObject * nNetObject::ObjectDangerous ( int  i  )  [static]

Definition at line 1166 of file nNetObject.cpp.

References NULL, nDeletedInfo::object_, sn_netObjects, nDeletedInfo::time_, and tSysTimeFloat().

Referenced by _wrap_NNetObject_object_dangerous(), eVoteItemHarm::DoFillFromMessage(), handle_chat_client(), net_sync_handler(), new_destination_handler(), Object(), and operator>>().

01166                                              {
01167     if (i==0) // the NULL nNetObject
01168     {
01169         return NULL;
01170     }
01171     else
01172     {
01173         nNetObject* ret = sn_netObjects[i];
01174         if ( ret )
01175         {
01176             return ret;
01177         }
01178         else
01179         {
01180             nDeletedInfos::const_iterator found = sn_netObjectsDeleted.find( i );
01181             if ( found != sn_netObjectsDeleted.end() )
01182             {
01183                 nDeletedInfo const & deleted = (*found).second;
01184                 if ( deleted.time_ > tSysTimeFloat() - nDeletedTimeout )
01185                 {
01186                     return deleted.object_;
01187                 }
01188             }
01189         }
01190     }
01191 
01192     return NULL;
01193 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nNetObject::AddRef ( void   )  [virtual]

Reimplemented in eNetGameObject, SwigDirector_NNetObject, and gCycleMovement.

Definition at line 555 of file nNetObject.cpp.

References refCtr_, and tASSERT.

Referenced by _wrap_NNetObject_add_ref(), and eNetGameObject::AddRef().

00555                        {
00556     tASSERT ( this );
00557 
00558     if ( this )
00559     {
00560         tASSERT( refCtr_ >= 0 );
00561         refCtr_++;
00562         tASSERT( refCtr_ >= 0 );
00563     }
00564 }

Here is the caller graph for this function:

void nNetObject::Release (  )  [virtual]

Reimplemented in eNetGameObject, and SwigDirector_NNetObject.

Definition at line 582 of file nNetObject.cpp.

References createdLocally, refCtr_, sn_netObjects, tASSERT, and tERR_ERROR.

Referenced by _wrap_NNetObject_release(), eNetGameObject::Release(), and ReleaseOwnership().

00582                         {
00583     tASSERT( this );
00584 
00585     if (this){
00586         if (refCtr_>0)
00587             refCtr_--;
00588         else
00589         {
00590 #ifdef DEBUG
00591             tERR_ERROR("Negative recfcount!");
00592 #else
00593             return;
00594 #endif
00595         }
00596         int extra=0;
00597 
00598         // account for the reference held by the creator of the object
00599 
00600         // only if the object is validly entered in our object-array
00601         if (id > 0 && static_cast<nNetObject*>(sn_netObjects[id])==this)
00602         {
00603             if ( createdLocally )
00604                 extra = -1;
00605         }
00606         //    else
00607         //      extra = -1;
00608 
00609         if ( refCtr_ + extra <= 0 )
00610         {
00611             refCtr_ = -100;
00612             delete this;
00613         }
00614     }
00615 }

Here is the caller graph for this function:

int nNetObject::GetRefcount (  )  const

Definition at line 618 of file nNetObject.cpp.

References createdLocally, refCtr_, and sn_netObjects.

Referenced by gCycleMovement::AddRef(), gAITeam::BalanceWithAIs(), GetID(), and gAIPlayer::SetNumberOfAIs().

00619 {
00620     int extra=0;
00621 
00622     // account for the reference held by the creator of the object
00623 
00624     // only if the object is validly entered in our object-array
00625     if (id > 0 && static_cast<nNetObject*>(sn_netObjects[id])==this)
00626     {
00627         if ( createdLocally )
00628             extra = -1;
00629     }
00630     //    else
00631     //      extra = -1;
00632 
00633     return this->refCtr_ + extra;
00634 }

Here is the caller graph for this function:

void nNetObject::ReleaseOwnership (  )  [virtual]

Reimplemented in SwigDirector_NNetObject.

Definition at line 566 of file nNetObject.cpp.

References createdLocally, and Release().

Referenced by _wrap_NNetObject_release_ownership().

00566                                  {
00567     if ( this->createdLocally )
00568     {
00569         this->createdLocally = false;
00570         Release();
00571     }
00572 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nNetObject::TakeOwnership (  )  [virtual]

Reimplemented in SwigDirector_NNetObject.

Definition at line 574 of file nNetObject.cpp.

References createdLocally.

Referenced by _wrap_NNetObject_take_ownership(), gNetPlayerWall::ActionOnQuit(), and gCycle::ActionOnQuit().

00574                               {
00575     if ( !this->createdLocally )
00576     {
00577         this->createdLocally = true;
00578         //              AddRef();
00579     }
00580 }

Here is the caller graph for this function:

bool nNetObject::Owned (  )  [inline]

< returns whether the object is owned by this machine

Definition at line 127 of file nNetObject.h.

References createdLocally.

Referenced by _wrap_NNetObject_owned().

00127                 {
00128         return createdLocally;    
00129     }

Here is the caller graph for this function:

nObserver & nNetObject::GetObserver (  )  const

Definition at line 636 of file nNetObject.cpp.

References tNEW.

Referenced by _wrap_NNetObject_get_observer().

00637 {
00638     if ( !this->observer_ )
00639     {
00640         this->observer_ = tNEW( nObserver );
00641         this->observer_->SetObject( this );
00642     }
00643 
00644     return *this->observer_;
00645 }

Here is the caller graph for this function:

void nNetObject::Dump ( tConsole con  )  [virtual]

Reimplemented in SwigDirector_NNetObject.

Definition at line 649 of file nNetObject.cpp.

References PrintName().

Referenced by _wrap_NNetObject_dump().

00650 {
00651     tString str;
00652     this->PrintName( str );
00653     con << str;
00654 }

Here is the call graph for this function:

Here is the caller graph for this function:

unsigned short nNetObject::ID (  )  const [inline]

Definition at line 135 of file nNetObject.h.

References id.

Referenced by BroadCastNewDestination(), gNetPlayerWall::ClearToTransmit(), eNetGameObject::ClearToTransmit(), zValidator::isOwner(), zValidator::isTeamOwner(), gCycle::OnDropTempWall(), gCycle::PrintName(), se_NewChatMessage(), se_ServerControlledChatMessageConsole(), ePlayerNetID::SetTeamname(), gCycle::Timestep(), and deptest::WriteCreate().

00135                              {
00136         if (this)
00137             return id;
00138         else
00139             return 0;
00140     }

Here is the caller graph for this function:

unsigned short nNetObject::Owner (  )  const [inline]

Definition at line 142 of file nNetObject.h.

References owner, and sn_myNetID.

Referenced by gDestination::CopyFrom(), ePlayerNetID::CreateNewTeam(), ePlayerNetID::CreateVoter(), eVoteItemKick::DoCheckValid(), DoGetMachine(), gCycle::DoTurn(), gCycle::EdgeIsDangerous(), ePlayerNetID::Enemies(), ePlayerNetID::FindPlayerByName(), GameLoop(), eVoter::GetVoter(), eVoter::HandleChat(), IsSilencedWithWarning(), eNetGameObject::LagThreshold(), ePlayerNetID::MyInitAfterCreation(), eVoter::Name(), net_control_handler(), net_sync_handler(), new_destination_handler(), gCycleMovement::OnNotifyNewDestination(), gCycle::OnNotifyNewDestination(), gCycle::ReadSync(), gNetPlayerWall::RealWallReceived(), ePlayerNetID::ReceiveControlNet(), ePlayerNetID::RemoveChatbots(), nAuthentication::RequestLogin(), gCycle::RequestSyncAll(), gCycle::RequestSyncOwner(), gCycle::RightBeforeDeath(), se_ChatMsg(), se_ChatShuffle(), se_ChatState(), se_ChatTeam(), se_ChatTeamLeave(), se_FindPlayerInChatCommand(), se_GetAccessLevel(), se_GetAlivePlayerFromUserID(), se_GetLocalPlayer(), se_GetPing(), se_ListPlayers(), se_ReadUser(), se_RequestLogin(), se_SendPrivateMessage(), se_SendTeamMessage(), se_SendTo(), se_VoteKickPlayer(), eNetGameObject::SendControl(), eNetGameObject::SetPlayer(), ePlayerNetID::SetTeam(), ePlayerNetID::SetTeamWish(), sg_GetSyncIntervalSelf(), sg_UseAntiLagSliding(), sn_DoDestroy(), gCycle::SyncEnemy(), eNetGameObject::SyncIsNew(), ePlayerNetID::TeamChangeAllowed(), gCycleMovement::Timestep(), eNetGameObject::Timestep(), gCycleMovement::TimestepCore(), gCycle::TimestepCore(), ePlayerNetID::Update(), ePlayerNetID::UpdateName(), and ePlayerNetID::UpdateTeam().

00142                                 {
00143         if (this)
00144             return owner;
00145         else
00146             return ::sn_myNetID;
00147     }

nMachine & nNetObject::GetMachine ( void   )  const [inline]

returns the machine this object belongs to

Returns:
the machine this NetObject belongs to

Definition at line 448 of file nNetObject.h.

References DoGetMachine().

Referenced by _wrap_NNetObject_get_machine(), eNetGameObject::DoGetMachine(), ePlayerNetID::Enemies(), and se_ListPlayers().

00449 {
00450     return DoGetMachine();
00451 }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual nDescriptor& nNetObject::CreatorDescriptor (  )  const [pure virtual]

Implemented in ePlayerNetID, eTeam, eTimer, floattest, deptest, floattest, deptest, SwigDirector_NNetObject, gAIPlayer, gAITeam, gCycleExtrapolator, gCycle, gGame, gNetPlayerWall, gZone, zShapeCircle, zShapePolygon, and zZone.

Referenced by nBandwidthTaskCreate::DoExecute(), new_destination_handler(), and SyncAll().

Here is the caller graph for this function:

void nNetObject::InitAfterCreation ( void   )  [virtual]

Reimplemented in eNetGameObject, ePlayerNetID, SwigDirector_NNetObject, gCycle, gCycleMovement, and gNetPlayerWall.

Definition at line 859 of file nNetObject.cpp.

References DoBroadcastExistence(), and sn_WasDeletedLocally().

Referenced by _wrap_NNetObject_init_after_creation(), gNetPlayerWall::InitAfterCreation(), and eNetGameObject::InitAfterCreation().

00859                                   {
00860     DoBroadcastExistence();
00861     // con << "InitAfterCreation\n";
00862 
00863 #ifdef DEBUG
00864     sn_BreakOnObjectID( id );
00865 #endif
00866 
00867     // it just got created, all local deletions must be fakes
00868     sn_WasDeletedLocally( id );
00869 } // after remote creation,

Here is the call graph for this function:

Here is the caller graph for this function:

void nNetObject::Register ( const nNetObjectRegistrar r  ) 

Definition at line 738 of file nNetObject.cpp.

References Cheater(), con, nNetObjectRegistrar::id, nCLIENT, nReadError(), nNetObjectRegistrar::object, owner, nNetObjectRegistrar::sender, sn_GetNetState(), sn_netObjects, and tASSERT.

00739 {
00740     tASSERT( this == registrar.object );
00741     tASSERT( id == 0 || id == registrar.id );
00742 
00743     if ( this->id == registrar.id )
00744     {
00745         return;
00746     }
00747 
00748     id = registrar.id;
00749 
00750     if (sn_netObjectsOwner[id]!= registrar.sender || sn_netObjects[id]){
00751 #ifdef DEBUG
00752         con << "Netobject " << id << " is already reserved!\n";
00753 #endif
00754         if (sn_netObjectsOwner[id]!=registrar.sender){
00755             Cheater( registrar.sender );
00756             nReadError();
00757         }
00758     }
00759     else
00760     {
00761 #ifdef DEBUG
00762         sn_BreakOnObjectID( id );
00763 #endif
00764         sn_netObjects[id]=this;
00765     }
00766 
00767     if (sn_GetNetState()!=nCLIENT)
00768         owner=registrar.sender; // to make sure noone is given a nNetObject from
00769     // someone else.
00770 
00771     sn_netObjectsOwner[id]=owner;
00772     sn_netObjects_AcceptClientSync[id]=false;
00773 }

Here is the call graph for this function:

nMachine & nNetObject::DoGetMachine ( void   )  const [protected, virtual]

returns the machine this object belongs to

Returns:

Reimplemented in eNetGameObject, ePlayerNetID, and SwigDirector_NNetObject.

Definition at line 2082 of file nNetObject.cpp.

References nMachine::GetMachine(), and Owner().

Referenced by ePlayerNetID::DoGetMachine(), eNetGameObject::DoGetMachine(), SwigDirector_NNetObject::DoGetMachineSwigPublic(), GetMachine(), and ePlayerNetID::RegisterWithMachine().

02083 {
02084     return nMachine::GetMachine( Owner() );
02085 }

Here is the call graph for this function:

Here is the caller graph for this function:

virtual bool nNetObject::ActionOnQuit (  )  [inline, virtual]

Reimplemented in eNetGameObject, ePlayerNetID, SwigDirector_NNetObject, gCycle, and gNetPlayerWall.

Definition at line 184 of file nNetObject.h.

Referenced by _wrap_NNetObject_action_on_quit(), and ClearKnows().

00184                                {
00185         return true;
00186     }

Here is the caller graph for this function:

virtual void nNetObject::ActionOnDelete (  )  [inline, virtual]

Reimplemented in eNetGameObject, ePlayerNetID, and SwigDirector_NNetObject.

Definition at line 189 of file nNetObject.h.

Referenced by _wrap_NNetObject_action_on_delete(), and sn_DoDestroy().

00189                                  {
00190     }

Here is the caller graph for this function:

virtual bool nNetObject::BroadcastExistence (  )  [inline, virtual]

Reimplemented in SwigDirector_NNetObject.

Definition at line 194 of file nNetObject.h.

Referenced by _wrap_NNetObject_broadcast_existence(), and DoBroadcastExistence().

00194                                      {
00195         return true;
00196     }

Here is the caller graph for this function:

void nNetObject::PrintName ( tString s  )  const [virtual]

Reimplemented in ePlayerNetID, eTeam, SwigDirector_NNetObject, gCycle, and gNetPlayerWall.

Definition at line 1195 of file nNetObject.cpp.

References id.

Referenced by Dump(), and SyncAll().

01196 {
01197     s << "Nameless NetObject nr. " << id;
01198 }

Here is the caller graph for this function:

bool nNetObject::HasBeenTransmitted ( int  user  )  const

Definition at line 1200 of file nNetObject.cpp.

References knowsAbout.

Referenced by deptest::ClearToTransmit(), and gGame::GridIsReady().

01200                                                  {
01201     return (knowsAbout[user].knowsAboutExistence);
01202 }

Here is the caller graph for this function:

bool nNetObject::syncRequested ( int  user  )  const [inline]

Definition at line 203 of file nNetObject.h.

References knowsAbout, and nNetObject::nKnowsAboutInfo::syncReq.

00203                                       {
00204         return knowsAbout[user].syncReq;
00205     }

bool nNetObject::ClearToTransmit ( int  user  )  const [virtual]

Reimplemented in eNetGameObject, ePlayerNetID, eTeam, deptest, deptest, SwigDirector_NNetObject, and gNetPlayerWall.

Definition at line 1206 of file nNetObject.cpp.

Referenced by _wrap_NNetObject_clear_to_transmit(), gNetPlayerWall::ClearToTransmit(), deptest::ClearToTransmit(), eNetGameObject::ClearToTransmit(), and SyncAll().

01206                                               {
01207     return true;
01208 }

Here is the caller graph for this function:

void nNetObject::WriteSync ( nMessage m  )  [virtual]

Reimplemented in eNetGameObject, ePlayerNetID, eTeam, eTimer, floattest, floattest, SwigDirector_NNetObject, gCycle, gGame, gNetPlayerWall, gZone, zShape, zShapeCircle, and zZone.

Definition at line 1278 of file nNetObject.cpp.

References AcceptClientSync(), nSERVER, sn_GetNetState(), and tERR_ERROR.

Referenced by _wrap_NNetObject_write_sync(), WriteAll(), gNetPlayerWall::WriteSync(), gGame::WriteSync(), WriteSync(), floattest::WriteSync(), eTimer::WriteSync(), and eNetGameObject::WriteSync().

01278                                      {
01279 #ifdef DEBUG
01280     if (sn_GetNetState()!=nSERVER && !AcceptClientSync())
01281         tERR_ERROR("WriteSync should only be called server-side!");
01282 #endif
01283 } // nothing to do yet

Here is the call graph for this function:

Here is the caller graph for this function:

void nNetObject::ReadSync ( nMessage m  )  [virtual]

Reimplemented in eNetGameObject, ePlayerNetID, eTeam, eTimer, floattest, floattest, SwigDirector_NNetObject, gCycle, gGame, gNetPlayerWall, gZone, zShape, zShapeCircle, and zZone.

Definition at line 1287 of file nNetObject.cpp.

References knowsAbout, nSERVER, RequestSync(), nMessage::SenderID(), sn_GetNetState(), and nNetObject::nKnowsAboutInfo::syncReq.

Referenced by _wrap_NNetObject_read_sync(), ReadAll(), gNetPlayerWall::ReadSync(), gGame::ReadSync(), ReadSync(), floattest::ReadSync(), eTimer::ReadSync(), eNetGameObject::ReadSync(), and floattest::ReceiveControl().

01287                                     {
01288     if (sn_GetNetState()==nSERVER){
01289         bool back=knowsAbout[m.SenderID()].syncReq;
01290         RequestSync(); // tell the others about it
01291         knowsAbout[m.SenderID()].syncReq=back;
01292         // but not the sender of the message; he
01293         // knows already.
01294     }
01295 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nNetObject::WriteSync ( nMessage m,
int  run 
) [virtual]

Definition at line 1210 of file nNetObject.cpp.

References WriteSync().

01211 {
01212     if ( run == 0 )
01213     {
01214         WriteSync( m );
01215     }
01216 }

Here is the call graph for this function:

void nNetObject::ReadSync ( nMessage m,
int  run 
) [virtual]

Definition at line 1218 of file nNetObject.cpp.

References ReadSync().

01219 {
01220     if ( run == 0 )
01221     {
01222         ReadSync( m );
01223     }
01224 }

Here is the call graph for this function:

bool nNetObject::SyncIsNew ( nMessage m  )  [virtual]

Reimplemented in eNetGameObject, eTeam, SwigDirector_NNetObject, gCycle, and gNetPlayerWall.

Definition at line 692 of file nNetObject.cpp.

References lastSyncID_, nMessage::MessageIDBig(), and sn_Update().

Referenced by net_sync_handler(), gNetPlayerWall::SyncIsNew(), and eNetGameObject::SyncIsNew().

00692                                      {
00693     unsigned long int bigID =  m.MessageIDBig();
00694     //    sn_Update(global_lastSync,bigID);
00695     return sn_Update(lastSyncID_,bigID);
00696 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nNetObject::WriteCreate ( nMessage m  )  [virtual]

Reimplemented in eNetGameObject, eTeam, floattest, deptest, deptest, SwigDirector_NNetObject, gCycle, gNetPlayerWall, gZone, zShape, zShapeCircle, zShapePolygon, and zZone.

Definition at line 1300 of file nNetObject.cpp.

References AcceptClientSync(), con, id, owner, and nMessage::Write().

Referenced by _wrap_NNetObject_write_create(), WriteAll(), gNetPlayerWall::WriteCreate(), WriteCreate(), deptest::WriteCreate(), floattest::WriteCreate(), eTeam::WriteCreate(), and eNetGameObject::WriteCreate().

01300                                        {
01301     m.Write(id);
01302     m.Write(owner);
01303 
01304     // store the info needed in the destructor
01305     sn_netObjects_AcceptClientSync[id]=this->AcceptClientSync();
01306 
01307     if (deb_net)
01308         con << "Sending creation message for nNetObject " << id << "\n";
01309 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nNetObject::WriteCreate ( nMessage m,
int  run 
) [virtual]

Definition at line 1226 of file nNetObject.cpp.

References WriteCreate().

01227 {
01228     if ( run == 0 )
01229     {
01230         WriteCreate( m );
01231     }
01232 }

Here is the call graph for this function:

void nNetObject::ReadCreate ( nMessage m,
int  run 
) [virtual]

Definition at line 1234 of file nNetObject.cpp.

References tASSERT.

Referenced by ReadAll().

01235 {
01236     // run == 0 would call the constructor, but run == 0 never happens.
01237     tASSERT( run > 0 );
01238 }

Here is the caller graph for this function:

void nNetObject::WriteAll ( nMessage m,
bool  create 
)

Definition at line 1240 of file nNetObject.cpp.

References nMessage::DataLen(), WriteCreate(), and WriteSync().

Referenced by nBandwidthTaskCreate::DoExecute(), nBandwidthTaskSync::DoExecute(), and SyncAll().

01241 {
01242     int lastLen = -1;
01243     int run = 0;
01244 
01245     // write as long as the read functions do something
01246     while ( m.DataLen() > lastLen )
01247     {
01248         lastLen = m.DataLen();
01249         if ( create )
01250         {
01251             WriteCreate(m,run);
01252         }
01253 
01254         WriteSync(m,run);
01255         ++run;
01256     }
01257 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nNetObject::ReadAll ( nMessage m,
bool  create 
)

Definition at line 1259 of file nNetObject.cpp.

References ReadCreate(), nMessage::ReadSoFar(), and ReadSync().

Referenced by nNOInitialisator< T >::Init(), and net_sync_handler().

01260 {
01261     int lastRead = -1;
01262     int run = 0;
01263 
01264     // read as long as the read functions do something
01265     while ( m.ReadSoFar() > lastRead )
01266     {
01267         lastRead = m.ReadSoFar();
01268         if ( create && run > 0 )
01269         {
01270             ReadCreate(m,run);
01271         }
01272 
01273         ReadSync(m,run);
01274         ++run;
01275     }
01276 }

Here is the call graph for this function:

Here is the caller graph for this function:

int nNetObject::SyncedUser (  )  [static, protected]

returns the user that the current WriteSync() is intended for

Definition at line 1520 of file nNetObject.cpp.

Referenced by eTimer::WriteSync().

01521 {
01522     return sn_syncedUser;
01523 }

Here is the caller graph for this function:

nMessage * nNetObject::NewControlMessage (  )  [protected]

Definition at line 1407 of file nNetObject.cpp.

References net_control, and nMessage::Write().

Referenced by ePlayerNetID::CreateNewTeamWish(), floattest::SendControl(), eNetGameObject::SendControl(), and ePlayerNetID::SetTeamWish().

01407                                         {
01408     nMessage *m=new nMessage(net_control);
01409     m->Write(id);
01410     return m;
01411 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nNetObject::ReceiveControlNet ( nMessage m  )  [virtual]

Reimplemented in eNetGameObject, ePlayerNetID, eTeam, and SwigDirector_NNetObject.

Definition at line 1394 of file nNetObject.cpp.

References nCLIENT, RequestSync(), sn_GetNetState(), and tERR_ERROR.

Referenced by _wrap_NNetObject_receive_control_net(), and net_control_handler().

01394                                             {
01395 #ifdef DEBUG
01396     if (sn_GetNetState()==nCLIENT)
01397         tERR_ERROR("rec_cont should not be called client-side!");
01398 #endif
01399 
01400     // after control is received, we better sync this object with
01401     // the clients:
01402 
01403     RequestSync();
01404 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool nNetObject::AcceptClientSync (  )  const [virtual]

Reimplemented in ePlayerNetID, eTeam, floattest, deptest, floattest, deptest, and SwigDirector_NNetObject.

Definition at line 1497 of file nNetObject.cpp.

Referenced by _wrap_NNetObject_accept_client_sync(), ClearKnows(), DoBroadcastExistence(), net_sync_handler(), RequestSync(), SyncAll(), WriteCreate(), and WriteSync().

01497                                        {
01498     return false;
01499 }

Here is the caller graph for this function:

void nNetObject::GetID (  ) 

Definition at line 1311 of file nNetObject.cpp.

References GetRefcount(), nNetObjectRegistrar::id, next_free(), nNetObjectRegistrar::object, owner, sn_netObjects, and tERR_ERROR.

Referenced by RequestSync().

01312 {
01313     if ( !id && GetRefcount() >= 0 )
01314     {
01315         if ( bool( sn_Registrar ) && this == sn_Registrar->object )
01316         {
01317             id = sn_Registrar->id;
01318         }
01319         else
01320         {
01321             id = next_free();
01322         }
01323 
01324         if (sn_netObjects[id])
01325             tERR_ERROR("Dublicate nNetObject id " << id);
01326 
01327         sn_netObjectsOwner[id]=owner;
01328         sn_netObjects_AcceptClientSync[id]=false;
01329 
01330         sn_netObjects[id]=this;
01331     }
01332 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nNetObject::RequestSync ( bool  ack = true  ) 

Reimplemented in gCycleMovement.

Definition at line 1354 of file nNetObject.cpp.

References AcceptClientSync(), tList< T, MALLOC, REFERENCE >::Add(), GetID(), knowsAbout, MAXCLIENTS, nCLIENT, nNetObject::nKnowsAboutInfo::nextSyncAck, owner, sn_GetNetState(), sn_myNetID, syncListID_, nNetObject::nKnowsAboutInfo::syncReq, and tERR_ERROR.

Referenced by eTeam::AddScore(), ePlayerNetID::AddScore(), gNetPlayerWall::BlowHole(), gNetPlayerWall::CopyIntoGrid(), DoBroadcastExistence(), eNetGameObject::eNetGameObject(), eTimer::eTimer(), GameLoop(), gGame::gGame(), gGame::NoLongerGoOn(), ntest(), gWinZoneHack::OnEnter(), gParser::parseZoneArthemis_v1(), eTimer::pause(), ReadSync(), floattest::ReceiveControl(), eNetGameObject::ReceiveControl(), ReceiveControlNet(), gCycleMovement::RequestSync(), eTeam::ResetScore(), ePlayerNetID::SetChatting(), zShape::setColor(), zShape::setRotation2(), eTeam::SetScore(), gGame::SetState(), gGame::StateUpdate(), eTimer::SyncTime(), gBaseZoneHack::Timestep(), ePlayerNetID::Update(), eTeam::UpdateAppearance(), ePlayerNetID::UpdateName(), and eTeam::UpdateProperties().

01354                                     {
01355     this->GetID();
01356 
01357 #ifdef nSIMULATE_PING
01358     ack=true;
01359 #endif
01360 
01361 #ifdef DEBUG
01362     if (sn_GetNetState()==nCLIENT && (!AcceptClientSync() || owner!=::sn_myNetID))
01363         tERR_ERROR("RequestSync should only be called server-side!");
01364 #endif
01365 
01366     for (int i=MAXCLIENTS;i>=0;i--){
01367         knowsAbout[i].syncReq=true;
01368         knowsAbout[i].nextSyncAck |=ack;
01369     }
01370 
01371     if ( syncListID_ < 0 )
01372         sn_SyncRequestedObject.Add( this, syncListID_ );
01373 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nNetObject::RequestSync ( int  user,
bool  ack 
)

Reimplemented in gCycleMovement.

Definition at line 1335 of file nNetObject.cpp.

References AcceptClientSync(), tList< T, MALLOC, REFERENCE >::Add(), GetID(), knowsAbout, nNetObject::nKnowsAboutInfo::nextSyncAck, nSERVER, owner, sn_GetNetState(), sn_myNetID, syncListID_, nNetObject::nKnowsAboutInfo::syncReq, and tERR_ERROR.

01335                                              { // only for a single user
01336 #ifdef nSIMULATE_PING
01337     ack=true;
01338 #endif
01339     this->GetID();
01340 
01341     if (sn_GetNetState()==nSERVER || (AcceptClientSync() && owner==::sn_myNetID)){
01342         knowsAbout[user].syncReq=true;
01343         knowsAbout[user].nextSyncAck |=ack;
01344     }
01345 #ifdef DEBUG
01346     else
01347         tERR_ERROR("RequestSync should only be called server-side!");
01348 #endif
01349 
01350     if ( syncListID_ < 0 )
01351         sn_SyncRequestedObject.Add( this, syncListID_ );
01352 }

Here is the call graph for this function:

void nNetObject::SyncAll (  )  [static]

Definition at line 1525 of file nNetObject.cpp.

References AcceptClientSync(), nConnectionInfo::ackPending, nNetObject::nKnowsAboutInfo::acksPending, nConnectionInfo::bandwidthControl_, ClearToTransmit(), con, nBandwidthControl::Control(), CreatorDescriptor(), DoDebugPrint(), id, knowsAbout, nNetObject::nKnowsAboutInfo::knowsAboutExistence, GrowingArrayBase::Len(), nSendBuffer::Len(), MAXCLIENTS, nCLIENT, net_sync, nNetObject::nKnowsAboutInfo::nextSyncAck, nSERVER, NULL, nWaitForAckSync, PrintName(), tList< T, MALLOC, REFERENCE >::Remove(), nConnectionInfo::sendBuffer_, sn_Connections, sn_GetNetState(), sn_maxNoAck, sn_myNetID, sn_netObjects, sn_SyncRequestedObject, syncListID_, nNetObject::nKnowsAboutInfo::syncReq, tSysTimeFloat(), nBandwidthControl::Usage_Planning, and WriteAll().

Referenced by _wrap_NNetObject_sync_all(), client(), ConnectToServerCore(), gGame::GameLoop(), init_game_objects(), gGame::NetSync(), next_free(), ntest(), server(), and sn_Sync().

01525                         {
01526 #ifdef DEBUG
01527     s_DoPrintDebug = false;
01528 
01529     static nTimeRolling debugtime = 0;
01530     nTimeRolling time = tSysTimeFloat();
01531     if (time > debugtime && sn_GetNetState() == nSERVER)
01532     {
01533         debugtime = time+5;
01534         //      s_DoPrintDebug = true;
01535     }
01536 #endif
01537 
01538     for (int user=MAXCLIENTS;user>=0;user--)
01539         if (is_ready_to_get_objects[user] &&
01540                 sn_Connections[user].socket && sn_netObjects.Len()>0 && user!=sn_myNetID){
01541 
01542             sn_syncedUser = user;
01543 
01544             // send the destroy messages
01545             if (destroyers[user])
01546             {
01547                 // but check whether the opportunity is good (big destroyers message, or a sync packet in the pipe) first
01548                 if ( destroyers[user]->DataLen() > 75 ||
01549                         sn_Connections[user].sendBuffer_.Len() > 0 ||
01550                         destroyersTime[user] < tSysTimeFloat()-.5 )
01551                 {
01552                     destroyers[user]->Send(user);
01553                     destroyers[user]=NULL;
01554                 }
01555             }
01556 
01557             // con << sn_SyncRequestedObject.Len() << "/" << sn_netObjects.Len() << "\n";
01558 
01559             int currentSync = sn_SyncRequestedObject.Len()-1;
01560             while (sn_Connections[user].socket>0 &&
01561                     sn_Connections[user].bandwidthControl_.CanSend() &&
01562                     sn_Connections[user].ackPending<sn_maxNoAck &&
01563                     currentSync >= 0){
01564                 nNetObject *nos = sn_SyncRequestedObject( currentSync );
01565 
01566                 if (nos && nos->ClearToTransmit(user) && ( nos == sn_netObjects( nos->id ) )
01567                         && (sn_GetNetState()!=nCLIENT ||
01568                             nos->AcceptClientSync()))
01569                 {
01570                     short s = nos->id;
01571 
01572                     if (// nos->knowsAbout[user].syncReq &&
01573                         !nos->knowsAbout[user].knowsAboutExistence)
01574                     {
01575                         if (!nos->knowsAbout[user].acksPending){
01576 #ifdef DEBUG
01577                             //con << "remotely creating object " << s << '\n';
01578 #endif
01579                             /*
01580                               con << "creating object " << s << " at user " << user
01581                               << " owned by " << sn_netObjects(s)->owner << '\n';
01582                             */
01583                             // send a creation message
01584 
01585                             tJUST_CONTROLLED_PTR< nMessage > m=new nMessage
01586                                                                (nos->CreatorDescriptor());
01587 
01588 #ifdef DEBUG
01589                             if (s == sn_WatchNetID)
01590                                 sn_WatchMessage = m;
01591 #endif
01592 
01593                             nos->WriteAll(*m,true);
01594                             new nWaitForAckSync(m,user,s);
01595                             unsigned long id = m->MessageIDBig();
01596                             m->SendImmediately(user, false);
01597                             m->messageIDBig_ = id;
01598 
01599                             nos->knowsAbout[user].syncReq = false;
01600                         }
01601 #ifdef DEBUG
01602                         else if (DoDebugPrint())
01603                         {
01604                             tString s;
01605                             s << "Not remotely creating object ";
01606                             nos->PrintName(s);
01607                             s << " on user " << user << " again because there is an Ack pending.\n";
01608                             con << s;
01609                         }
01610 #endif
01611                     }
01612                     else if (nos->knowsAbout[user].syncReq
01613                              && sn_Connections[user].bandwidthControl_.Control( nBandwidthControl::Usage_Planning ) >50
01614                              && nos->knowsAbout[user].acksPending<=1){
01615                         // send a sync
01616                         tJUST_CONTROLLED_PTR< nMessage > m = new nMessage(net_sync);
01617 
01618                         m->Write(s);
01619                         nos->WriteAll(*m,false);
01620                         nos->knowsAbout[user].syncReq=false;
01621 
01622                         if (nos->knowsAbout[user].nextSyncAck){
01623                             new nWaitForAckSync(m,user,s);
01624                             nos->knowsAbout[user].nextSyncAck=false;
01625                         }
01626 #ifndef nSIMULATE_PING
01627                         unsigned long id = m->MessageIDBig();
01628                         //m->Send(user,0,false);
01629                         m->SendImmediately(user,false);
01630                         m->messageIDBig_ = id;
01631 #endif
01632                     }
01633 
01634                 }
01635 
01636                 currentSync--;
01637             }
01638 
01639             sn_syncedUser = -1;
01640 
01641 #ifdef DEBUG
01642             bool inc=false;
01643             static int warn=0;
01644             static int nextWarnOverflow=0;
01645             static int nextWarnAck=0;
01646             if (sn_Connections[user].bandwidthControl_.Control( nBandwidthControl::Usage_Planning )<-100){
01647                 if (warn>=nextWarnOverflow)
01648                 {
01649                     nextWarnOverflow = 2+(warn*17)/16;
01650                     con << "Warning! Network overflow: "
01651                     << -100-sn_Connections[user].bandwidthControl_.Control( nBandwidthControl::Usage_Planning ) << "\n";
01652                 }
01653                 inc=true;
01654             }
01655             if (sn_Connections[user].ackPending>=sn_maxNoAck){
01656                 if (warn>=nextWarnAck)
01657                 {
01658                     nextWarnAck = 2+(warn*17)/16;
01659                     std::cerr << "Warning! Too many acks pending: "
01660                     << sn_Connections[user].ackPending << "\n";
01661                 }
01662                 inc=true;
01663             }
01664             if (inc)
01665                 warn++;
01666 #endif
01667         }
01668 
01669 
01670     // clear out objects that no longer need to be in the list because
01671     // all requested syncs have been sent
01672     {
01673         for ( int currentSync = sn_SyncRequestedObject.Len()-1; currentSync >= 0; --currentSync ){
01674             nNetObject *nos = sn_SyncRequestedObject( currentSync );
01675 
01676             if ( nos )
01677             {
01678                 // check if nos can be removed from sync request list
01679                 bool canRemove = true;
01680 
01681                 // check if there is anything preventing the removal
01682                 if ( nos == sn_netObjects( nos->id ) )
01683                 {
01684                     int start = ( sn_GetNetState() == nSERVER ) ? MAXCLIENTS : 0;
01685                     int stop  = ( sn_GetNetState() == nSERVER ) ? 1 : 0;
01686                     for ( int i = start; i>=stop && canRemove; --i )
01687                     {
01688                         const nKnowsAboutInfo& knows = nos->knowsAbout[i];
01689                         if ( sn_Connections[i].socket && knows.syncReq )
01690                             canRemove = false;
01691                     }
01692                 }
01693                 if ( canRemove )
01694                     sn_SyncRequestedObject.Remove( nos, nos->syncListID_ );
01695             }
01696         }
01697     }
01698 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nNetObject::ClearAll (  )  [static]

Reimplemented in ePlayerNetID, and gAIPlayer.

Definition at line 1741 of file nNetObject.cpp.

References ClearAllDeleted(), GrowingArrayBase::Len(), net_clear, NULL, tList< T, MALLOC, REFERENCE >::Remove(), tArray< T, MALLOC >::SetLen(), sn_netObjects, sn_netObjectsOwner, syncListID_, tASSERT, and tNEW.

Referenced by _wrap_NNetObject_clear_all(), cleanup(), ConnectToServerCore(), main(), and net_clear_handler().

01741                          {
01742     ClearAllDeleted();
01743     sn_freedIDs.clear();
01744 
01745     //con << "WARNING! BAD DESIGN. nNetObject::clear all() called.\n";
01746     int i;
01747     for (i=sn_netObjects.Len()-1;i>=0;i--)
01748         if (tJUST_CONTROLLED_PTR< nNetObject > no=sn_netObjects(i)){
01749             sn_netObjects(i)=NULL;
01750             sn_netObjectsOwner(i)=0;
01751             no->id = 0;
01752         }
01753     sn_netObjects.SetLen(0);
01754     sn_netObjectsOwner.SetLen(0);
01755 
01756     for (i=sn_SyncRequestedObject.Len()-1;i>=0;i--)
01757     {
01758         nNetObject * n = sn_SyncRequestedObject[i];
01759         tASSERT(n);
01760         sn_SyncRequestedObject.Remove( n, n->syncListID_ );
01761     }
01762 
01763     (tNEW(nMessage)(net_clear))->BroadCast(); // just to make sure..
01764 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nNetObject::ClearAllDeleted (  )  [static]

Definition at line 1722 of file nNetObject.cpp.

References MAXCLIENTS, NULL, and sn_Connections.

Referenced by _wrap_NNetObject_clear_all_deleted(), gAITeam::BalanceWithAIs(), ClearAll(), gGame::StateUpdate(), and ePlayerNetID::Update().

01723 {
01724     // forget about objects that were deleted in the past. The swap trick is to
01725     // avoid that the objects try to remove themselves from the list while it is cleared.
01726     nDeletedInfos swap;
01727     swap.swap( sn_netObjectsDeleted );
01728     swap.clear();
01729 
01730     // send out object deletion messages
01731     for ( int i = MAXCLIENTS;i>=0;i--)
01732     {
01733         if ( sn_Connections[i].socket && destroyers[i] )
01734         {
01735             destroyers[i]->Send(i);
01736             destroyers[i] = NULL;
01737         }
01738     }
01739 }

Here is the caller graph for this function:

void nNetObject::ClearKnows ( int  user,
bool  clear 
) [static]

Definition at line 1767 of file nNetObject.cpp.

References AcceptClientSync(), ActionOnQuit(), DoBroadcastExistence(), knowsAbout, MAXCLIENTS, NULL, owner, nNetObject::nKnowsAboutInfo::Reset(), sn_myNetID, sn_netObjects, and sn_netObjectsOwner.

Referenced by _wrap_NNetObject_clear_knows(), ClearKnows(), and login_callback().

01767                                                {
01768     if (0<=user && user <=MAXCLIENTS){
01769         is_ready_to_get_objects[user]=false;
01770         for (int i=sn_netObjects.Len()-1;i>=0;i--){
01771             nNetObject *no=sn_netObjects(i);
01772             if (no){
01773                 no->knowsAbout[user].Reset();
01774 
01775                 no->DoBroadcastExistence();  // immediately transfer the thing
01776 
01777                 if (clear){
01778                     if (no->owner==user && user!=sn_myNetID){
01779                         if (no->ActionOnQuit())
01780                             sn_netObjects(i)=NULL; // destroy it
01781                         else{
01782                             no->owner=::sn_myNetID; // or make it mine.
01783                             sn_netObjectsOwner(i)=::sn_myNetID;
01784                             if (no->AcceptClientSync()){
01785                                 tControlledPTR< nNetObject > bounce( no ); // destroy it, if noone wants it
01786                             }
01787                         }
01788                     }
01789                 }
01790             }
01791         }
01792     }
01793 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nNetObject::RelabelOnConnect (  )  [static]

Definition at line 1811 of file nNetObject.cpp.

References DoBroadcastExistence(), id, knowsAbout, GrowingArrayBase::Len(), MAXCLIENTS, nCLIENT, next_free(), NULL, owner, ready, nNetObject::nKnowsAboutInfo::Reset(), sn_GetNetState(), sn_myNetID, sn_netObjects, and st_Breakpoint().

Referenced by _wrap_NNetObject_relabel_on_connect(), and login_callback().

01811                                  {
01812     if (sn_GetNetState()==nCLIENT){
01813         tArray<tJUST_CONTROLLED_PTR<nNetObject> > sn_netObjects_old;
01814 
01815         // transfer the sn_netObjects to sn_netObjects_old:
01816         int i;
01817         for (i=sn_netObjects.Len()-1;i>=0;i--){
01818             sn_netObjects_old[i]=sn_netObjects(i);
01819             sn_netObjects(i)=NULL;
01820             sn_netObjectsOwner[i]=0;
01821         }
01822 
01823         // assign new id's and transfer them back to sn_netObjects:
01824         for (i=sn_netObjects_old.Len()-1;i>=0;i--){
01825             nNetObject *no = sn_netObjects_old(i);
01826             if (no){
01827                 unsigned short id=next_free();
01828 
01829 #ifdef DEBUG
01830                 sn_BreakOnObjectID( id );
01831 #endif
01832 
01833 #ifdef DEBUG
01834                 //con << "object " <<i << " gets new id " << id << '\n';
01835 #endif
01836                 no->id=id;
01837                 no->owner=::sn_myNetID;
01838                 sn_netObjectsOwner[id]=::sn_myNetID;
01839                 for (int j=MAXCLIENTS;j>=0;j--){
01840                     no->knowsAbout[j].Reset();
01841                     no->DoBroadcastExistence();
01842                 }
01843 
01844                 if (sn_netObjects[id])
01845                     st_Breakpoint();
01846 
01847                 sn_netObjects[id]=no;
01848                 sn_netObjects_old(i)=NULL;
01849             }
01850         }
01851     }
01852     (new nMessage(ready))->Send(0);
01853     is_ready_to_get_objects[0]=true;
01854 }

Here is the call graph for this function:

Here is the caller graph for this function:


Friends And Related Function Documentation

friend class nWaitForAckSync [friend]

Definition at line 52 of file nNetObject.h.

Referenced by SyncAll().


Member Data Documentation

bool nNetObject::createdLocally [private]

Definition at line 54 of file nNetObject.h.

Referenced by GetRefcount(), nNetObject(), Owned(), Release(), ReleaseOwnership(), TakeOwnership(), and ~nNetObject().

unsigned long int nNetObject::lastSyncID_ [private]

Definition at line 55 of file nNetObject.h.

Referenced by SyncIsNew().

unsigned short nNetObject::id [private]

Reimplemented in gNetPlayerWall.

Definition at line 58 of file nNetObject.h.

Referenced by deptest::deptest(), handle_chat_client(), ID(), net_control_handler(), net_destroy_handler(), net_sync_handler(), PrintName(), RelabelOnConnect(), sync_ack_handler(), SyncAll(), and WriteCreate().

int nNetObject::refCtr_ [mutable, private]

Definition at line 61 of file nNetObject.h.

Referenced by AddRef(), GetRefcount(), Release(), and ~nNetObject().

unsigned short nNetObject::owner [private]

Definition at line 64 of file nNetObject.h.

Referenced by ClearKnows(), floattest::debug_out(), deptest::deptest(), DoBroadcastExistence(), floattest::floattest(), GetID(), nNetObject(), Object(), Owner(), floattest::ReadSync(), floattest::ReceiveControl(), Register(), RelabelOnConnect(), RequestSync(), WriteCreate(), deptest::~deptest(), floattest::~floattest(), and ~nNetObject().

int nNetObject::syncListID_ [private]

Definition at line 73 of file nNetObject.h.

Referenced by ClearAll(), nNetObject(), RequestSync(), SyncAll(), and ~nNetObject().

nKnowsAboutInfo nNetObject::knowsAbout[MAXCLIENTS+2] [protected]

Definition at line 103 of file nNetObject.h.

Referenced by nWaitForAckSync::AckExtraAction(), ClearKnows(), DoBroadcastExistence(), HasBeenTransmitted(), nNetObject(), nWaitForAckSync::nWaitForAckSync(), ReadSync(), RelabelOnConnect(), RequestSync(), SyncAll(), syncRequested(), and ~nNetObject().


The documentation for this class was generated from the following files:
Generated on Sat Mar 15 23:49:11 2008 for Armagetron Advanced by  doxygen 1.5.4