nServerInfoBase Class Reference

Basic server information: everything you need to connect. More...

#include <nServerInfo.h>

Inheritance diagram for nServerInfoBase:

Inheritance graph
[legend]
Collaboration diagram for nServerInfoBase:

Collaboration graph
[legend]

List of all members.

Public Member Functions

 nServerInfoBase ()
virtual ~nServerInfoBase ()
bool operator== (const nServerInfoBase &other) const
bool operator!= (const nServerInfoBase &other) const
void NetWrite (nMessage &m) const
 writes data to network message
void NetRead (nMessage &m)
 reads data from network message
void NetWriteThis (nMessage &m) const
 writes data to network message
void NetReadThis (nMessage &m)
 reads data from network message
void GetFrom (nSocket const *socket)
 fills data from this server and the given socket
nConnectError Connect (nLoginType loginType=Login_All, const nSocket *socket=NULL)
 connect to this server ( using the specified socket )
void CopyFrom (const nServerInfoBase &other)
 copies server info
nServerInfoBaseoperator= (const nServerInfoBase &other)
const tStringGetName () const
 returns the server's name
tString const & GetConnectionName (void) const
 Gets the internet name of the server ("192.168.10.10", "atron.dyndns.org").
nServerInfoBase const & GetConnectionName (tString &connectionName) const
 Gets the internet name of the server ("192.168.10.10", "atron.dyndns.org").
unsigned int GetPort (void) const
 Gets the network port the server listens on.
nServerInfoBase const & GetPort (unsigned int &port) const
 Gets the network port the server listens on.
nAddress const & GetAddress (void) const
 Gets the network address of the server.
nServerInfoBase const & GetAddress (nAddress &address) const
 Gets the network address of the server.
nServerInfoBase const & ClearAddress () const
 Clears the network address of the server ( so it gets requeried ).

Protected Member Functions

virtual void DoNetWrite (nMessage &m) const
 writes data to network message
virtual void DoNetRead (nMessage &m)
 reads data from network message
virtual void DoGetFrom (nSocket const *socket)
 fills data from this server and the given socket
virtual const tStringDoGetName () const
 returns the server's name
nServerInfoBaseSetConnectionName (tString const &connectionName)
 Sets the internet name of the server ("192.168.10.10", "atron.dyndns.org").
nServerInfoBaseSetPort (unsigned int port)
 Sets the network port the server listens on.

Private Member Functions

nAddressAccessAddress (void) const
 Accesses the network address of the server.
nServerInfoBaseSetAddress (nAddress const &address)
 Sets the network address of the server.

Private Attributes

tString connectionName_
 the internet name of the server ("192.168.10.10", "atron.dyndns.org")
unsigned int port_
 the network port the server listens on
std::auto_ptr< nAddressaddress_
 the network address of the server


Detailed Description

Basic server information: everything you need to connect.

Definition at line 47 of file nServerInfo.h.


Constructor & Destructor Documentation

nServerInfoBase::nServerInfoBase (  ) 

Definition at line 2367 of file nServerInfo.cpp.

02368         : connectionName_(""),
02369           port_(0)
02370 {
02371 }

nServerInfoBase::~nServerInfoBase (  )  [virtual]

Definition at line 2382 of file nServerInfo.cpp.

02383 {
02384 }


Member Function Documentation

bool nServerInfoBase::operator== ( const nServerInfoBase other  )  const

Definition at line 2395 of file nServerInfo.cpp.

References GetAddress(), and port_.

Referenced by operator!=().

02396 {
02397     return GetAddress() == other.GetAddress() && port_ == other.port_;
02398 }

Here is the call graph for this function:

Here is the caller graph for this function:

bool nServerInfoBase::operator!= ( const nServerInfoBase other  )  const

Definition at line 2409 of file nServerInfo.cpp.

References operator==().

02410 {
02411     return ! operator == ( other );
02412 }

Here is the call graph for this function:

void nServerInfoBase::NetWrite ( nMessage message  )  const [inline]

writes data to network message

Parameters:
message message to write info to

Definition at line 410 of file nServerInfo.h.

References DoNetWrite().

Referenced by nServerInfo::GiveBigServerInfoCommon(), nServerInfo::GiveSmallServerInfo(), and nServerInfo::TellMasterAboutMe().

00411 {
00412     DoNetWrite( message );
00413 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nServerInfoBase::NetRead ( nMessage message  )  [inline]

reads data from network message

Parameters:
mesage message to read from

Definition at line 425 of file nServerInfo.h.

References DoNetRead().

Referenced by nServerInfo::GetBigServerInfoCommon(), nServerInfo::GetSmallServerInfo(), and nServerInfo::GiveBigServerInfoMaster().

00426 {
00427     DoNetRead( message );
00428 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nServerInfoBase::NetWriteThis ( nMessage m  )  const

writes data to network message

Parameters:
m message to write to

Reimplemented in nServerInfo.

Definition at line 2519 of file nServerInfo.cpp.

References connectionName_, and port_.

Referenced by DoNetWrite(), nServerInfo::NetReadThis(), and nServerInfo::QueryServer().

02520 {
02521     m << port_;            // write the port
02522     m << connectionName_;  // and the name
02523 }

Here is the caller graph for this function:

void nServerInfoBase::NetReadThis ( nMessage m  ) 

reads data from network message

Parameters:
m message to read from

Reimplemented in nServerInfo.

Definition at line 2544 of file nServerInfo.cpp.

References connectionName_, tString::Len(), port_, S_GlobalizeName(), S_LocalizeName(), nMessage::SenderID(), tString::Size(), sn_AcceptingFromBroadcast, sn_AcceptingFromMaster, sn_GetAdr(), sn_IsMaster, sn_ReadFiltered(), and tString::SubStr().

Referenced by DoNetRead().

02545 {
02546     m >> port_;                            // get the port
02547     sn_ReadFiltered( m, connectionName_ ); // get the connection name
02548 
02549     if ( ( sn_IsMaster || sn_AcceptingFromBroadcast || sn_AcceptingFromMaster ) && connectionName_.Len()>1 ) // no valid name (must come directly from the server who does not know his own address)
02550     {
02551         // resolve DNS
02552         connectionName_ = S_LocalizeName( connectionName_ );
02553     }
02554     else
02555     {
02556 #ifdef DEBUG_X
02557         if ( connectionName_.Len() > 1 )
02558         {
02559             std::cout << "Overwriting source from " << connectionName_ << ".\n";
02560         }
02561 #endif
02562 
02563         sn_GetAdr( m.SenderID(), connectionName_ );
02564 
02565         // remove the port
02566         for (int i=connectionName_.Size()-1; i>=0; i--)
02567             if (':' == connectionName_[i])
02568             {
02569                 connectionName_ = connectionName_.SubStr( 0, i );
02570             }
02571 
02572         S_GlobalizeName( connectionName_ );
02573     }
02574 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nServerInfoBase::GetFrom ( nSocket const *  socket  )  [inline]

fills data from this server and the given socket

Parameters:
socket socket to get bare network information from

Definition at line 440 of file nServerInfo.h.

References DoGetFrom().

Referenced by nServerInfo::GiveBigServerInfo(), nServerInfo::GiveSmallServerInfo(), and nServerInfo::TellMasterAboutMe().

00441 {
00442     DoGetFrom( socket );
00443 }

Here is the call graph for this function:

Here is the caller graph for this function:

nConnectError nServerInfoBase::Connect ( nLoginType  loginType = Login_All,
const nSocket socket = NULL 
)

connect to this server ( using the specified socket )

Returns:
error code

Definition at line 2424 of file nServerInfo.cpp.

References GetAddress(), nTIMEOUT, sn_Connect(), and ToString().

Referenced by ConnectToServerCore(), nServerInfo::GetFromMaster(), and nServerInfo::TellMasterAboutMe().

02425 {
02426     // refuse to connect without address
02427     if ( !GetAddress().IsSet() )
02428     {
02429         // well, not really a timeout. But we would timeout if we tried to connect.
02430         return nTIMEOUT;
02431     }
02432 
02433     //unsigned int portBack = sn_clientPort;
02434     //sn_clientPort = port_;
02435     if ( GetAddress().ToString().StartsWith( "*.*.*.*" ) )
02436     {
02437         throw tGenericException( tOutput("$network_message_dns_error_inter"),tOutput("$network_message_dns_error_title"));
02438     }
02439 
02440     nConnectError error = sn_Connect( GetAddress(), loginType, socket );
02441     //sn_clientPort = portBack;
02442 
02443     return error;
02444 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nServerInfoBase::CopyFrom ( const nServerInfoBase other  ) 

copies server info

Parameters:
other 

Definition at line 2456 of file nServerInfo.cpp.

References connectionName_, and port_.

Referenced by nServerInfo::GetBigServerInfoCommon(), and operator=().

02457 {
02458     port_               = other.port_;
02459     connectionName_     = other.connectionName_;
02460 }

Here is the caller graph for this function:

nServerInfoBase & nServerInfoBase::operator= ( const nServerInfoBase other  ) 

Parameters:
other 
Returns:

Definition at line 2473 of file nServerInfo.cpp.

References CopyFrom().

02474 {
02475     CopyFrom( other );
02476     return *this;
02477 }

Here is the call graph for this function:

const tString & nServerInfoBase::GetName ( void   )  const [inline]

returns the server's name

Returns:
this server's name

Definition at line 346 of file nServerInfo.h.

References DoGetName().

Referenced by gServerFavoritesHolder::AddFavorite(), ConnectToServerCore(), nServerInfo::GetFromMaster(), gServerMenuItem::Render(), and nServerInfo::TellMasterAboutMe().

00347 {
00348     return DoGetName();
00349 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nServerInfoBase::DoNetWrite ( nMessage m  )  const [protected, virtual]

writes data to network message

Parameters:
m message to write to

Reimplemented in nServerInfo.

Definition at line 2489 of file nServerInfo.cpp.

References NetWriteThis().

Referenced by nServerInfo::DoNetWrite(), and NetWrite().

02490 {
02491     NetWriteThis( m );
02492 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nServerInfoBase::DoNetRead ( nMessage m  )  [protected, virtual]

reads data from network message

Parameters:
m message to read from

Reimplemented in nServerInfo.

Definition at line 2504 of file nServerInfo.cpp.

References NetReadThis().

Referenced by nServerInfo::DoNetRead(), and NetRead().

02505 {
02506     NetReadThis( m );
02507 }

Here is the call graph for this function:

Here is the caller graph for this function:

void nServerInfoBase::DoGetFrom ( nSocket const *  socket  )  [protected, virtual]

fills data from this server and the given socket

Parameters:
socket socket to get bare network information from

Reimplemented in nServerInfo.

Definition at line 2592 of file nServerInfo.cpp.

References connectionName_, nSocket::GetAddress(), nAddress::GetPort(), net_dns, port_, and sn_GetServerPort().

Referenced by nServerInfo::DoGetFrom(), and GetFrom().

02593 {
02594     // better not set connection name, the message recipient can figure it out more reliably
02595     connectionName_ = net_dns;
02596 
02597     if ( ! socket )
02598     {
02599         port_ = sn_GetServerPort();
02600     }
02601     else
02602     {
02603         // fill port information from socket
02604         nAddress const & address = socket->GetAddress();
02605         port_ = address.GetPort();
02606     }
02607 }

Here is the call graph for this function:

Here is the caller graph for this function:

const tString & nServerInfoBase::DoGetName ( void   )  const [protected, virtual]

returns the server's name

Returns:
this server's name

Reimplemented in nServerInfo.

Definition at line 2952 of file nServerInfo.cpp.

References connectionName_.

Referenced by GetName().

02953 {
02954     return connectionName_;
02955 }

Here is the caller graph for this function:

tString const & nServerInfoBase::GetConnectionName ( void   )  const [inline]

Gets the internet name of the server ("192.168.10.10", "atron.dyndns.org").

Returns:
the internet name of the server ("192.168.10.10", "atron.dyndns.org")

Definition at line 455 of file nServerInfo.h.

References connectionName_.

Referenced by gServerFavoritesHolder::AddFavorite(), nServerInfo::GetSmallServerInfo(), gServerFavoritesHolder::IsFavorite(), Poll(), nServerInfo::Save(), sg_NetworkError(), and ToString().

00456 {
00457     return this->connectionName_;
00458 }

Here is the caller graph for this function:

nServerInfoBase const & nServerInfoBase::GetConnectionName ( tString connectionName  )  const [inline]

Gets the internet name of the server ("192.168.10.10", "atron.dyndns.org").

Parameters:
connectionName the internet name of the server ("192.168.10.10", "atron.dyndns.org") to fill
Returns:
A reference to this to allow chaining

Definition at line 471 of file nServerInfo.h.

References connectionName_.

00472 {
00473     connectionName = this->connectionName_;
00474     return *this;
00475 }

unsigned nServerInfoBase::GetPort ( void   )  const [inline]

Gets the network port the server listens on.

Returns:
the network port the server listens on

Definition at line 504 of file nServerInfo.h.

References port_.

Referenced by gServerFavoritesHolder::AddFavorite(), nServerInfo::GetSmallServerInfo(), gServerFavoritesHolder::IsFavorite(), Poll(), nServerInfo::Save(), sg_NetworkError(), and ToString().

00505 {
00506     return this->port_;
00507 }

Here is the caller graph for this function:

nServerInfoBase const& nServerInfoBase::GetPort ( unsigned int &  port  )  const [inline]

Gets the network port the server listens on.

nAddress const & nServerInfoBase::GetAddress ( void   )  const

Gets the network address of the server.

Returns:
the network address of the server

Definition at line 2851 of file nServerInfo.cpp.

References AccessAddress().

Referenced by Connect(), nServerInfo::Load(), nServerInfo::NetReadThis(), operator==(), nServerInfo::QueryServer(), nServerInfo::StartQueryAll(), and nServerInfo::TellMasterAboutMe().

02852 {
02853     return this->AccessAddress();
02854 }

Here is the call graph for this function:

Here is the caller graph for this function:

nServerInfoBase const & nServerInfoBase::GetAddress ( nAddress address  )  const

Gets the network address of the server.

Parameters:
address the network address of the server to fill
Returns:
A reference to this to allow chaining

Definition at line 2867 of file nServerInfo.cpp.

References AccessAddress().

02868 {
02869     address = this->AccessAddress();
02870     return *this;
02871 }

Here is the call graph for this function:

nServerInfoBase const & nServerInfoBase::ClearAddress (  )  const

Clears the network address of the server ( so it gets requeried ).

Returns:
A reference to this to allow chaining

Definition at line 2883 of file nServerInfo.cpp.

References address_.

Referenced by nServerInfo::StartQueryAll().

02884 {
02885     std::auto_ptr< nAddress > clearedAddress;
02886     address_ = clearedAddress;
02887     return *this;
02888 }

Here is the caller graph for this function:

nAddress & nServerInfoBase::AccessAddress ( void   )  const [private]

Accesses the network address of the server.

Returns:
the network address of the server as a modifiable reference

Definition at line 2918 of file nServerInfo.cpp.

References address_, con, tNEW, and ToString().

Referenced by GetAddress(), and SetAddress().

02919 {
02920     // create address if it is not already there
02921     if ( !this->address_.get() )
02922     {
02923         std::auto_ptr< nAddress > address( tNEW( nAddress ) );
02924 
02925         // fill it with hostname and port
02926         address->SetHostname( this->GetConnectionName() );
02927         address->SetPort( this->GetPort() );
02928 
02929         this->address_ = address;
02930 
02931 #ifdef DEBUG
02932         tString unresolved = ToString( *this );
02933         tString resolved = this->address_->ToString();
02934         if ( unresolved != resolved )
02935             con << "Address of server " << unresolved << " determined to be " << resolved << "\n";
02936 #endif
02937     }
02938 
02939     return *this->address_;
02940 }

Here is the call graph for this function:

Here is the caller graph for this function:

nServerInfoBase & nServerInfoBase::SetAddress ( nAddress const &  address  )  [private]

Sets the network address of the server.

Parameters:
address the network address of the server to set
Returns:
A reference to this to allow chaining

Definition at line 2901 of file nServerInfo.cpp.

References AccessAddress().

02902 {
02903     AccessAddress() = address;
02904     return *this;
02905 }

Here is the call graph for this function:

nServerInfoBase & nServerInfoBase::SetConnectionName ( tString const &  connectionName  )  [inline, protected]

Sets the internet name of the server ("192.168.10.10", "atron.dyndns.org").

Parameters:
connectionName the internet name of the server ("192.168.10.10", "atron.dyndns.org") to set
Returns:
A reference to this to allow chaining

Definition at line 488 of file nServerInfo.h.

References connectionName_.

Referenced by nServerInfo::Load(), and nServerInfoRedirect::nServerInfoRedirect().

00489 {
00490     this->connectionName_ = connectionName;
00491     return *this;
00492 }

Here is the caller graph for this function:

nServerInfoBase& nServerInfoBase::SetPort ( unsigned int  port  )  [inline, protected]

Sets the network port the server listens on.

Referenced by nServerInfo::Load(), and nServerInfoRedirect::nServerInfoRedirect().

Here is the caller graph for this function:


Member Data Documentation

tString nServerInfoBase::connectionName_ [private]

the internet name of the server ("192.168.10.10", "atron.dyndns.org")

Definition at line 79 of file nServerInfo.h.

Referenced by CopyFrom(), DoGetFrom(), DoGetName(), GetConnectionName(), NetReadThis(), NetWriteThis(), and SetConnectionName().

unsigned int nServerInfoBase::port_ [private]

the network port the server listens on

Definition at line 80 of file nServerInfo.h.

Referenced by CopyFrom(), DoGetFrom(), GetPort(), NetReadThis(), NetWriteThis(), and operator==().

std::auto_ptr< nAddress > nServerInfoBase::address_ [mutable, private]

the network address of the server

Definition at line 81 of file nServerInfo.h.

Referenced by AccessAddress(), and ClearAddress().


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