#include <nServerInfo.h>
Public Types | |
enum | PrimaryKey { KEY_NAME, KEY_PING, KEY_USERS, KEY_SCORE, KEY_MAX } |
enum | QueryType { QUERY_ALL = 0, QUERY_OPTOUT = 1, QUERY_OPTIN = 2, QUERY_NONE = 3 } |
enum | Compat { Compat_Ok, Compat_Downgrade, Compat_Upgrade } |
Public Member Functions | |
nServerInfo () | |
virtual | ~nServerInfo () |
nServerInfo * | Prev () |
virtual void | CalcScore () |
virtual void | Save (std::ostream &s) const |
virtual void | Load (std::istream &s) |
virtual void | Alive () |
void | QueryServer () |
void | SetQueryType (QueryType query) |
void | ClearInfoFlags () |
clears information sent flags | |
void | SetFromMaster () |
indicate that this server was fetched through the master | |
bool | Reachable () const |
bool | Polling () const |
unsigned int | TransactionNr () const |
unsigned int | Method () const |
const tArray< unsigned int > & | Key () const |
REAL | Ping () const |
const nVersion & | Version () const |
int | TimesNotAnswered () const |
int | Users () const |
int | MaxUsers () const |
const tString & | UserNames () const |
const tString & | UserNamesOneLine () const |
const tString & | Options () const |
const tString & | Release () const |
const tString & | Url () const |
REAL | Score () const |
Compat | Compatibility () const |
nServerInfo & | SetScoreBias (int scoreBias) |
Sets score bias for this server. | |
int | GetScoreBias (void) const |
Gets score bias for this server. | |
nServerInfo const & | GetScoreBias (int &scoreBias) const |
Gets score bias for this server. | |
Static Public Member Functions | |
static nServerInfo * | GetFirstServer () |
static void | Sort (PrimaryKey key) |
static void | CalcScoreAll () |
static void | DeleteAll (bool autosave=true) |
static void | GetSmallServerInfo (nMessage &m) |
static void | GiveSmallServerInfo (nMessage &m) |
static void | GetBigServerInfo (nMessage &m) |
static void | GiveBigServerInfo (nMessage &m) |
static void | GetBigServerInfoMaster (nMessage &m) |
static void | GiveBigServerInfoMaster (nMessage &m) |
static sn_ServerInfoCreator * | SetCreator (sn_ServerInfoCreator *creator) |
static void | Save () |
static void | Save (const tPath &path, const char *filename) |
static void | Load (const tPath &path, const char *filename) |
static nServerInfo * | GetMasters () |
get the list of master servers | |
static nServerInfo * | GetRandomMaster () |
gets a random master server | |
static void | GetFromMaster (nServerInfoBase *masterInfo=NULL, char const *fileSuffix=NULL) |
static void | TellMasterAboutMe (nServerInfoBase *masterInfo=NULL) |
static void | GetFromLAN (unsigned int pollBeginPort=4534, unsigned int pollEndPort=4544) |
static void | GetFromLANContinuously (unsigned int pollBeginPort=4534, unsigned int pollEndPort=4544) |
static void | GetFromLANContinuouslyStop () |
static void | DeleteUnreachable () |
Removes unreachable servers from the list. | |
static void | StartQueryAll (QueryType query=QUERY_ALL) |
static bool | DoQueryAll (int simultaneous=10) |
static void | RunMaster () |
static void | GetSenderData (const nMessage &m, tString &name, int &port) |
Protected Member Functions | |
virtual void | DoNetWrite (nMessage &m) const |
writes data to network message | |
virtual void | DoNetRead (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 | |
virtual void | DoGetFrom (nSocket const *socket) |
fills data from this server and the given socket | |
nServerInfo (nServerInfo const &other) | |
nServerInfo & | operator= (nServerInfo const &other) |
virtual const tString & | DoGetName () const |
returns the server's name | |
Static Protected Member Functions | |
static nServerInfo * | GetBigServerInfoCommon (nMessage &m) |
static void | GiveBigServerInfoCommon (nMessage &m, const nServerInfo &info, nDescriptor &descriptor) |
Protected Attributes | |
unsigned int | transactionNr |
int | method |
tArray< unsigned int > | key |
bool | advancedInfoSet |
bool | advancedInfoSetEver |
int | queried |
nTimeRolling | timeQuerySent |
REAL | ping |
nVersion | version_ |
tString | release_ |
bool | login2_ |
int | timesNotAnswered |
bool | stillOnMasterServer |
tString | name |
int | users |
int | maxUsers_ |
tString | userNames_ |
tString | userNamesOneLine_ |
tString | options_ |
tString | url_ |
REAL | score |
int | scoreBias_ |
Private Attributes | |
int | pollID |
QueryType | queryType_ |
the query type to use for this server |
Definition at line 111 of file nServerInfo.h.
QUERY_ALL | query all servers directly |
QUERY_OPTOUT | query all servers with nonnegative score bias |
QUERY_OPTIN | query only servers with positive score bias |
QUERY_NONE | query only manually |
Definition at line 249 of file nServerInfo.h.
00250 { 00251 QUERY_ALL=0, 00252 QUERY_OPTOUT=1, 00253 QUERY_OPTIN=2, 00254 QUERY_NONE=3 00255 };
enum nServerInfo::Compat |
Definition at line 298 of file nServerInfo.h.
00299 { 00300 Compat_Ok, 00301 Compat_Downgrade, 00302 Compat_Upgrade 00303 };
nServerInfo::nServerInfo | ( | nServerInfo const & | other | ) | [protected] |
nServerInfo::nServerInfo | ( | ) |
Definition at line 151 of file nServerInfo.cpp.
References sn_IsMaster, and sn_NextTransactionNr.
00152 :tListItem<nServerInfo>(sn_FirstServer), 00153 pollID(-1), 00154 transactionNr(sn_NextTransactionNr), 00155 method(0), 00156 key(0), 00157 advancedInfoSet(false), 00158 advancedInfoSetEver(false), 00159 queried(0), 00160 timeQuerySent(0), 00161 ping(10), 00162 release_("pre_0.2.5"), 00163 login2_(true), 00164 timesNotAnswered(5), 00165 stillOnMasterServer(false), 00166 name(""), 00167 users(0), 00168 maxUsers_(MAXCLIENTS), 00169 score(-10000), 00170 scoreBias_(0), 00171 queryType_( QUERY_ALL ) 00172 { 00173 if (sn_IsMaster) 00174 { 00175 sn_NextTransactionNr++; 00176 if (0 == sn_NextTransactionNr) 00177 sn_NextTransactionNr++; 00178 } 00179 }
nServerInfo::~nServerInfo | ( | ) | [virtual] |
Definition at line 181 of file nServerInfo.cpp.
References MAXCLIENTS, tListItem< T >::Next(), NULL, pollID, and tList< T, MALLOC, REFERENCE >::Remove().
00182 { 00183 sn_Polling.Remove(this, pollID); 00184 00185 for (int i = MAXCLIENTS+1; i>=0; i--) 00186 if (sn_Transmitting[i] == this) 00187 sn_Transmitting[i] = sn_Transmitting[i]->Next(); 00188 00189 if (sn_Requesting == this) 00190 sn_Requesting = sn_Requesting->Next(); 00191 00192 if (sn_QuerySoon == this) 00193 sn_Requesting = NULL; 00194 }
void nServerInfo::DoNetWrite | ( | nMessage & | m | ) | const [protected, virtual] |
writes data to network message
m | message to write to |
Reimplemented from nServerInfoBase.
Definition at line 2619 of file nServerInfo.cpp.
References nServerInfoBase::DoNetWrite(), and NetWriteThis().
02620 { 02621 nServerInfoBase::DoNetWrite( m ); 02622 NetWriteThis( m ); 02623 }
void nServerInfo::DoNetRead | ( | nMessage & | m | ) | [protected, virtual] |
reads data from network message
null |
Reimplemented from nServerInfoBase.
Definition at line 2635 of file nServerInfo.cpp.
References nServerInfoBase::DoNetRead(), and NetReadThis().
02636 { 02637 nServerInfoBase::DoNetRead( m ); 02638 NetReadThis( m ); 02639 }
void nServerInfo::NetWriteThis | ( | nMessage & | m | ) | const [protected] |
writes data to network message
m | message to write to |
Reimplemented from nServerInfoBase.
Definition at line 2711 of file nServerInfo.cpp.
References maxUsers_, name, options_, release_, url_, userNames_, users, and version_.
Referenced by DoNetWrite().
02712 { 02713 m << name; 02714 m << users; 02715 02716 m << version_; 02717 m << release_; 02718 02719 m << maxUsers_; 02720 02721 m << userNames_; 02722 m << options_; 02723 m << url_; 02724 }
void nServerInfo::NetReadThis | ( | nMessage & | m | ) | [protected] |
reads data from network message
m | message to read from |
Reimplemented from nServerInfoBase.
Definition at line 2736 of file nServerInfo.cpp.
References advancedInfoSet, advancedInfoSetEver, c, CalcScore(), tString::Clear(), con, nMessage::End(), nServerInfoBase::GetAddress(), GetMasters(), tString::Len(), login2_, maxUsers_, name, nServerInfoBase::NetWriteThis(), tListItem< T >::Next(), notrans, options_, ping, pollID, queried, release_, tList< T, MALLOC, REFERENCE >::Remove(), Save(), nMessage::SendCollected(), tString::SetPos(), SmallServerDescriptor, sn_Bend(), sn_IsMaster, sn_ReadFiltered(), timeQuerySent, timesNotAnswered, tNEW, ToString(), tSysTimeFloat(), url_, userNames_, userNamesOneLine_, users, and version_.
Referenced by DoNetRead(), and GetBigServerInfoCommon().
02737 { 02738 tString oldName = name; 02739 02740 sn_ReadFiltered( m, name ); // get the server name 02741 m >> users; // get the playing users 02742 02743 if ( !m.End() ) 02744 { 02745 m >> version_; 02746 sn_ReadFiltered( m, release_ ); 02747 login2_ = true; 02748 } 02749 else 02750 { 02751 login2_ = false; 02752 } 02753 02754 if ( !m.End() ) 02755 { 02756 m >> maxUsers_; 02757 } 02758 02759 if ( !m.End() ) 02760 { 02761 m >> userNames_; 02762 m >> options_; 02763 sn_ReadFiltered( m, url_ ); 02764 02765 if (options_.Len() > 240) 02766 options_.SetPos( 240, true ); 02767 02768 if (url_.Len() > 75) 02769 url_.SetPos( 75, true ); 02770 } 02771 else 02772 { 02773 userNames_ = "No Info\n"; 02774 options_ = "No Info\n"; 02775 url_ = "No Info\n"; 02776 } 02777 02778 userNamesOneLine_.Clear(); 02779 for ( int i = 0; i < userNames_.Len()-2 ; ++i ) 02780 { 02781 char c = userNames_[i]; 02782 if ( c == '\n' ) 02783 userNamesOneLine_ << "0xffffff, "; 02784 else 02785 userNamesOneLine_ << c; 02786 } 02787 02788 timesNotAnswered = 0; 02789 02790 if (!advancedInfoSet) 02791 { 02792 if ( sn_IsMaster ) 02793 { 02794 if ( !advancedInfoSetEver ) 02795 { 02796 con << "Acknowledged server: " << ToString( *this ) << ", name: \"" << tColoredString::RemoveColors(name) << "\"\n"; 02797 con << "\n"; 02798 Save(); 02799 } 02800 else if ( name != oldName ) 02801 { 02802 con << "Name of server " << ToString( *this ) 02803 << " changed from \"" << tColoredString::RemoveColors(oldName) 02804 << "\" to \"" << tColoredString::RemoveColors(name) << "\"\n"; 02805 } 02806 02807 // broadcast the server to the other master servers 02808 nServerInfo * master = GetMasters(); 02809 while( master ) 02810 { 02811 tJUST_CONTROLLED_PTR< nMessage > ret = tNEW(nMessage)(SmallServerDescriptor); 02812 02813 // get small server info 02814 nServerInfoBase::NetWriteThis(*ret); 02815 unsigned int notrans = 0; 02816 *ret << notrans; 02817 ret->ClearMessageID(); 02818 02819 // send message 02820 sn_Bend( master->GetAddress() ); 02821 ret->SendImmediately(0, false); 02822 nMessage::SendCollected(0); 02823 02824 master = master->Next(); 02825 } 02826 } 02827 02828 advancedInfoSet = true; 02829 advancedInfoSetEver = true; 02830 ping = tSysTimeFloat() - timeQuerySent; 02831 02832 CalcScore(); 02833 } 02834 02835 queried = 0; 02836 02837 // queried = true; 02838 sn_Polling.Remove(this, pollID); 02839 }
void nServerInfo::DoGetFrom | ( | nSocket const * | socket | ) | [protected, virtual] |
fills data from this server and the given socket
socket | socket to get bare network information from |
Reimplemented from nServerInfoBase.
Definition at line 2651 of file nServerInfo.cpp.
References nServerInfoBase::DoGetFrom(), nServerInfoAdmin::GetAdmin(), nServerInfoAdmin::GetOptions(), nServerInfoAdmin::GetUrl(), nServerInfoAdmin::GetUsers(), maxUsers_, name, tString::NetFilter(), options_, release_, sn_CurrentVersion(), sn_MaxUsers(), sn_NumRealUsers(), sn_programVersion, sn_serverName, url_, userNames_, users, and version_.
02652 { 02653 // delegate 02654 nServerInfoBase::DoGetFrom( socket ); 02655 02656 // fill 02657 02658 users = sn_NumRealUsers(); 02659 version_ = sn_CurrentVersion(); 02660 release_ = sn_programVersion; 02661 02662 #ifdef WIN32 02663 release_ += " win"; 02664 #else 02665 #ifdef MACOSX 02666 release_ += " mac"; 02667 #else 02668 #endif 02669 release_ += " unix"; 02670 #endif 02671 02672 #ifdef DEDICATED 02673 release_ += " dedicated"; 02674 #else 02675 release_ += " hybrid"; 02676 #endif 02677 02678 maxUsers_ = sn_MaxUsers(); 02679 02680 // filter newlines and stuff from the server name 02681 tColoredString filteredName( sn_serverName ); 02682 filteredName.NetFilter(); 02683 name = filteredName; 02684 02685 if ( nServerInfoAdmin::GetAdmin() ) 02686 { 02687 userNames_ = nServerInfoAdmin::GetAdmin()->GetUsers(); 02688 options_ = nServerInfoAdmin::GetAdmin()->GetOptions(); 02689 url_ = nServerInfoAdmin::GetAdmin()->GetUrl(); 02690 } 02691 else 02692 { 02693 tString str("UNKNOWN"); 02694 02695 userNames_ = str; 02696 options_ = str; 02697 url_ = str; 02698 } 02699 }
nServerInfo * nServerInfo::GetBigServerInfoCommon | ( | nMessage & | m | ) | [static, protected] |
Definition at line 1142 of file nServerInfo.cpp.
References Alive(), CalcScore(), con, nServerInfoBase::CopyFrom(), CreateServerInfo(), nSocket::GetAddress(), GetFirstServer(), nMessage::MessageID(), name, nServerInfoBase::NetRead(), NetReadThis(), tListItem< T >::Next(), QueryServer(), server(), tOutput::SetTemplateParameter(), sn_Connections, sn_IsMaster, nConnectionInfo::socket, nAddress::ToString(), and ToString().
Referenced by GetBigServerInfo(), and GetBigServerInfoMaster().
01143 { 01144 // read server info 01145 nServerInfoBase baseInfo; 01146 baseInfo.NetRead( m ); 01147 01148 // find the server 01149 nServerInfo *server = GetFirstServer(); 01150 while( server && *server != baseInfo ) 01151 server = server->Next(); 01152 01153 if ( server ) 01154 { 01155 server->NetReadThis( m ); 01156 server->Alive(); 01157 server->CalcScore(); 01158 } 01159 else 01160 { 01161 if ( sn_IsMaster ) 01162 { 01163 tOutput message; 01164 message.SetTemplateParameter(1, ToString( baseInfo ) ); 01165 message.SetTemplateParameter(2, sn_Connections[m.MessageID()].socket->GetAddress().ToString() ); 01166 message << "$network_browser_unidentified"; 01167 con << message; 01168 } 01169 else 01170 { 01171 // add the server, but ping it again 01172 nServerInfo * n = CreateServerInfo(); 01173 n->CopyFrom( baseInfo ); 01174 n->name = ToString( baseInfo ); 01175 n->QueryServer(); 01176 #ifdef DEBUG 01177 con << "Recevied unknown server " << n->name << ".\n"; 01178 #endif 01179 } 01180 } 01181 01182 return server; 01183 }
void nServerInfo::GiveBigServerInfoCommon | ( | nMessage & | m, | |
const nServerInfo & | info, | |||
nDescriptor & | descriptor | |||
) | [static, protected] |
Definition at line 1185 of file nServerInfo.cpp.
References nMessage::ClearMessageID(), nServerInfoBase::NetWrite(), nMessage::SendCollected(), nMessage::SenderID(), nMessage::SendImmediately(), and tNEW.
Referenced by GiveBigServerInfo(), and GiveBigServerInfoMaster().
01186 { 01187 // create message 01188 nMessage *ret = tNEW(nMessage)( descriptor ); 01189 01190 // write info 01191 info.NetWrite( *ret ); 01192 01193 // send info 01194 ret->ClearMessageID(); 01195 ret->SendImmediately(m.SenderID(), false); 01196 nMessage::SendCollected(m.SenderID()); 01197 }
nServerInfo& nServerInfo::operator= | ( | nServerInfo const & | other | ) | [protected] |
nServerInfo * nServerInfo::Prev | ( | ) |
Definition at line 367 of file nServerInfo.cpp.
References tListItemBase::anchor, tListItemBase::next, and NULL.
Referenced by Save(), and Sort().
00368 { 00369 if (reinterpret_cast<nServerInfo **>(anchor) == &sn_FirstServer) 00370 return NULL; 00371 00372 static nServerInfo& info = *this; // will not cause recursion since it is called only once. 00373 00374 // uaaa. Pointer magic... 00375 // TODO: perhaps there is a better way using member pointers? 00376 return reinterpret_cast<nServerInfo *> 00377 ( reinterpret_cast<char*> (anchor) + 00378 ( reinterpret_cast<char*>( &info ) - reinterpret_cast<char*> (&info.next) ) 00379 ); 00380 }
void nServerInfo::CalcScore | ( | ) | [virtual] |
Definition at line 198 of file nServerInfo.cpp.
References Compat_Ok, fabsf(), nVersion::Max(), maxUsers_, ping, score, scoreBias_, sn_MyVersion(), and users.
Referenced by CalcScoreAll(), gServerMenuItem::Event(), GetBigServerInfoCommon(), NetReadThis(), and SetFromMaster().
00199 { 00200 static int userScore[8] = { -100, 0, 100, 250, 300, 300, 250, 100 }; 00201 00202 // do nothing if we are requerying 00203 if ( !this->advancedInfoSet && this->advancedInfoSetEver ) 00204 { 00205 // score = scoreBias_; 00206 00207 return; 00208 } 00209 00210 score = 100; 00211 if (ping > .1) 00212 score -= (ping - .1) * 300; 00213 00214 if (users < 8 && users >= 0) 00215 score += userScore[users]; 00216 00217 if (users >= maxUsers_ ) 00218 score -= 200; 00219 00220 if ( Compat_Ok != this->Compatibility() ) 00221 { 00222 score -= 400; 00223 } 00224 00225 score -= fabsf( this->Version().Max() - sn_MyVersion().Max() ) * 10; 00226 00227 score += scoreBias_; 00228 }
void nServerInfo::Save | ( | std::ostream & | s | ) | const [virtual] |
Definition at line 278 of file nServerInfo.cpp.
References CONNECTION, END, nServerInfoBase::GetConnectionName(), nServerInfoBase::GetPort(), key, KEY, GrowingArrayBase::Len(), method, METHOD, name, NAME, PORT, RELEASE, release_, SCOREBIAS, scoreBias_, timesNotAnswered, TNA, TRANSACTION, transactionNr, URL, url_, version_, and VERSION_TAG.
Referenced by operator<<(), and Save().
00279 { 00280 s << CONNECTION << "\t" << GetConnectionName() << "\n"; 00281 s << PORT << "\t" << GetPort() << "\n"; 00282 s << METHOD << "\t" << method << "\n"; 00283 00284 s << KEY << "\t" << key.Len() << " "; 00285 for (int i = key.Len()-1; i>=0; i--) 00286 s << "\t" << key(i); 00287 s << "\n"; 00288 00289 s << TRANSACTION << "\t" << transactionNr << "\n"; 00290 s << VERSION_TAG << "\t" << version_ << "\n"; 00291 s << RELEASE << "\t" << release_ << "\n"; 00292 00293 s << URL << "\t" << url_ << "\n"; 00294 00295 s << SCOREBIAS << "\t" << scoreBias_ << "\n"; 00296 s << NAME << "\t" << name << "\n"; 00297 s << TNA << "\t" << timesNotAnswered << "\n"; 00298 s << END << "\t" << "\n\n"; 00299 }
void nServerInfo::Load | ( | std::istream & | s | ) | [virtual] |
Definition at line 301 of file nServerInfo.cpp.
References advancedInfoSet, advancedInfoSetEver, con, CONNECTION, END, key, KEY, METHOD, name, NAME, PORT, queried, tString::ReadLine(), RELEASE, release_, score, SCOREBIAS, scoreBias_, nServerInfoBase::SetConnectionName(), tArray< T, MALLOC >::SetLen(), nServerInfoBase::SetPort(), START, timesNotAnswered, TNA, TRANSACTION, transactionNr, URL, url_, version_, and VERSION_TAG.
Referenced by gServerFavorites::AlternativesMenu(), GetFromMaster(), GetMasters(), Load(), main(), and operator>>().
00302 { 00303 bool end = false; 00304 while (!end && s.good() && !s.eof()) 00305 { 00306 tString id; 00307 s >> id; 00308 int dummy; 00309 00310 if (id == START) 00311 continue; 00312 else if (id == END) 00313 end = true; 00314 else if (id == METHOD) 00315 s >> dummy; 00316 else if (id == TRANSACTION) 00317 s >> transactionNr; 00318 else if ( id == VERSION_TAG ) 00319 s >> version_; 00320 else if ( id == SCOREBIAS ) 00321 s >> scoreBias_; 00322 else if ( id == RELEASE ) 00323 release_.ReadLine( s ); 00324 else if ( id == URL ) 00325 url_.ReadLine( s ); 00326 else if (id == CONNECTION) 00327 { 00328 tString connectionName; 00329 connectionName.ReadLine( s ); 00330 SetConnectionName( connectionName ); 00331 } 00332 else if (id == PORT) 00333 { 00334 unsigned int port; 00335 s >> port; 00336 SetPort( port ); 00337 } 00338 else if (id == KEY) 00339 { 00340 int len; 00341 s >> len; 00342 key.SetLen(len); 00343 for (int i=len-1; i>=0; i--) 00344 s >> key(i); 00345 } 00346 else if(id == TNA) 00347 s >> timesNotAnswered; 00348 else if (id == NAME) 00349 name.ReadLine(s); 00350 else 00351 con << "Warning: unknown tag " << id << " found in server config file.\n"; 00352 } 00353 00354 queried = 0; 00355 advancedInfoSet = false; 00356 advancedInfoSetEver =false; 00357 00358 score = scoreBias_; 00359 }
nServerInfo * nServerInfo::GetFirstServer | ( | ) | [static] |
Reimplemented in gServerInfo.
Definition at line 361 of file nServerInfo.cpp.
Referenced by gServerFavorites::AlternativesMenu(), CalcScoreAll(), DeleteAll(), DeleteUnreachable(), DoQueryAll(), GetBigServerInfoCommon(), gServerInfo::GetFirstServer(), GetFromMaster(), GetSmallServerInfo(), GiveBigServerInfoMaster(), GiveSmallServerInfo(), gServerMenu::gServerMenu(), Load(), Poll(), QueryServer(), RunMaster(), Save(), Sort(), and StartQueryAll().
00362 { 00363 return sn_FirstServer; 00364 }
void nServerInfo::Sort | ( | PrimaryKey | key | ) | [static] |
Definition at line 383 of file nServerInfo.cpp.
References GetFirstServer(), tListItem< T >::Insert(), KEY_MAX, KEY_NAME, KEY_PING, KEY_SCORE, KEY_USERS, name, tListItemBase::next, tListItem< T >::Next(), ping, Polling(), Prev(), Reachable(), tListItemBase::Remove(), score, and users.
00384 { 00385 // insertion sort 00386 nServerInfo *run = GetFirstServer(); 00387 while (run) 00388 { 00389 nServerInfo* ascend = run; 00390 run = run->Next(); 00391 00392 while (1) 00393 { 00394 if ( ascend == GetFirstServer() ) 00395 break; 00396 00397 nServerInfo *prev = ascend->Prev(); 00398 00399 00400 // check if ascend is well in place 00401 if (!prev) 00402 break; 00403 00404 // if (prev->queried > ascend->queried) 00405 // break; 00406 int compare = 0; 00407 bool previousPolling = prev->Polling(); 00408 bool previousUnreachable = !prev->Reachable() && !previousPolling; 00409 bool ascendPolling = ascend->Polling(); 00410 bool ascendUnreachable = !ascend->Reachable() && !ascendPolling; 00411 00412 switch ( key ) 00413 { 00414 00415 case KEY_NAME: 00416 // Unreachable servers should be displayed at the end of the list 00417 if ( !previousUnreachable && !ascendUnreachable ) { 00418 compare = tColoredString::RemoveColors(prev->name).Compare( tColoredString::RemoveColors(ascend->name), true ); 00419 } 00420 00421 break; 00422 case KEY_PING: 00423 if ( ascend->ping > prev->ping ) 00424 compare = -1; 00425 else if ( ascend->ping < prev->ping ) 00426 compare = 1; 00427 break; 00428 case KEY_USERS: 00429 compare = ascend->users - prev->users; 00430 break; 00431 case KEY_SCORE: 00432 if ( previousUnreachable ) 00433 compare ++; 00434 if ( ascendUnreachable ) 00435 compare --; 00436 if ( ascend->score > prev->score ) 00437 compare = 1; 00438 else if ( ascend->score < prev->score ) 00439 compare = -1; 00440 break; 00441 case KEY_MAX: 00442 break; 00443 } 00444 00445 if (0 == compare) 00446 { 00447 if ( previousPolling ) 00448 compare++; 00449 if ( ascendPolling ) 00450 compare--; 00451 } 00452 00453 if ( compare <= 0 ) 00454 break; 00455 00456 prev->Remove(); 00457 prev->Insert( ascend->next ); 00458 } 00459 } 00460 }
void nServerInfo::CalcScoreAll | ( | ) | [static] |
Definition at line 462 of file nServerInfo.cpp.
References CalcScore(), GetFirstServer(), and tListItem< T >::Next().
Referenced by gServerMenu::Update().
00463 { 00464 nServerInfo *run = GetFirstServer(); 00465 while (run) 00466 { 00467 run->CalcScore(); 00468 run = run->Next(); 00469 } 00470 }
void nServerInfo::DeleteAll | ( | bool | autosave = true |
) | [static] |
Definition at line 472 of file nServerInfo.cpp.
References tString::Clear(), GetFirstServer(), and Save().
Referenced by gServerFavorites::AlternativesMenu(), gServerBrowser::BrowseLAN(), gServerBrowser::BrowseSpecialMaster(), GetFromMaster(), main(), and Poll().
00473 { 00474 if (autosave) 00475 { 00476 Save(); 00477 } 00478 sn_LastLoaded.Clear(); 00479 00480 while (GetFirstServer()) 00481 delete GetFirstServer(); 00482 }
void nServerInfo::Alive | ( | ) | [virtual] |
Definition at line 773 of file nServerInfo.cpp.
References sn_IsMaster, sn_NextTransactionNr, sn_TNALostContact, TimesNotAnswered(), and transactionNr.
Referenced by GetBigServerInfoCommon(), and GetSmallServerInfo().
00774 { 00775 // give it a new transaction number if it was down temporarily 00776 if ( sn_IsMaster && TimesNotAnswered() >= sn_TNALostContact ) 00777 { 00778 transactionNr = sn_NextTransactionNr++; 00779 if (!sn_NextTransactionNr) 00780 sn_NextTransactionNr++; 00781 } 00782 }
void nServerInfo::GetSmallServerInfo | ( | nMessage & | m | ) | [static] |
Definition at line 978 of file nServerInfo.cpp.
References Alive(), con, CreateServerInfo(), nMessage::End(), nServerInfoBase::GetConnectionName(), GetFirstServer(), nServerInfoBase::GetPort(), tString::Len(), name, nServerInfoBase::NetRead(), tListItem< T >::Next(), NULL, queried, QueryServer(), Save(), sn_IsMaster, sn_QueryTimeout, stillOnMasterServer, timesNotAnswered, ToString(), transactionNr, and tSysTimeFloat().
00978 { 00979 nServerInfoBase baseInfo; 00980 baseInfo.NetRead( m ); 00981 00982 // ReadServerInfo(m, port, connectionName, sn_AcceptingFromBroadcast, sn_AcceptingFromMaster); 00983 00984 // master server should not listen to LAN games 00985 //if ( sn_IsMaster && baseInfo.GetConnectionName().Len() >= 3 && 0 == strncmp( baseInfo.GetConnectionName(), "192", 3 ) ) 00986 //{ 00987 // return; 00988 //} 00989 00990 // S_GlobalizeName( connectionName ); 00991 sn_ServerCount++; 00992 00993 nServerInfo *n = NULL; 00994 00995 // check if we already have that server lised 00996 nServerInfo *run = GetFirstServer(); 00997 int countSameAdr = 0; 00998 while(run) 00999 { 01000 if (run->GetConnectionName() == baseInfo.GetConnectionName() ) 01001 { 01002 if (countSameAdr++ > 32) 01003 n = run; 01004 01005 if ( run->GetPort() == baseInfo.GetPort() ) 01006 n = run; 01007 } 01008 run = run->Next(); 01009 } 01010 01011 if (m.End()) 01012 return; 01013 01014 if (!n) 01015 { 01016 // so far no objections have been found; create the new server info. 01017 n = CreateServerInfo(); 01018 n->timesNotAnswered = 0; 01019 if ( sn_IsMaster ) 01020 { 01021 con << "Received new server: " << ToString( baseInfo ) << "\n"; 01022 n->timesNotAnswered = 5; 01023 } 01024 } 01025 else 01026 { 01027 n->Alive(); 01028 01029 if ( sn_IsMaster ) 01030 { 01031 con << "Updated server: " << ToString( baseInfo ) << "\n"; 01032 } 01033 } 01034 01035 n->nServerInfoBase::CopyFrom( baseInfo ); 01036 n->stillOnMasterServer = true; 01037 01038 if (n->name.Len() <= 1) 01039 n->name << ToString( baseInfo ); 01040 01041 // n->advancedInfoSet = false; 01042 n->queried = 0; 01043 01044 if (!sn_IsMaster) 01045 m >> n->transactionNr; 01046 else 01047 { 01048 // n->timesNotAnswered = 5; 01049 01050 if ( n->timesNotAnswered >= 1 ) 01051 { 01052 if (sn_QuerySoon) 01053 sn_QuerySoon->QueryServer(); 01054 01055 sn_QuerySoon = n; 01056 sn_QueryTimeout = tSysTimeFloat() + 5.0f; 01057 } 01058 01059 unsigned int dummy; 01060 m >> dummy; 01061 } 01062 01063 if (sn_IsMaster) 01064 { 01065 Save(); 01066 } 01067 }
void nServerInfo::GiveSmallServerInfo | ( | nMessage & | m | ) | [static] |
Definition at line 1075 of file nServerInfo.cpp.
References con, nMessage::End(), FloodProtection(), GetFirstServer(), nServerInfoBase::GetFrom(), nServerInfoBase::NetWrite(), notrans, nAuthentication::RequestLogin(), nMessage::SendCollected(), nMessage::SenderID(), nAuthentication::SetLoginResultCallback(), SmallServerDescriptor, sn_Connections, sn_GetAdr(), sn_GetPort(), sn_IsMaster, sn_LastKnown, sn_Requested, sn_SendAll, nConnectionInfo::socket, and tNEW.
01076 { 01077 // start transmitting the server list in master server mode 01078 if (sn_IsMaster) 01079 { 01080 con << "Giving server info to user " << m.SenderID() << "\n"; 01081 01082 sn_Requested[m.SenderID()] = true; 01083 #ifdef KRAWALL_SERVER_LEAGUE 01084 // one moment! check if we need authentification 01085 tString adr; 01086 unsigned int port = sn_GetPort(m.SenderID()); 01087 sn_GetAdr(m.SenderID(), adr); 01088 if (nKrawall::RequireMasterLogin(adr, port)) 01089 { 01090 nAuthentication::SetLoginResultCallback(&ResultCallback); 01091 nAuthentication::RequestLogin(tString(""), m.SenderID(), tOutput("$login_request_master")); 01092 } 01093 else 01094 { 01095 sn_Transmitting[m.SenderID()] = GetFirstServer(); 01096 sn_Auth[m.SenderID()] = true; 01097 } 01098 #else 01099 sn_Transmitting[m.SenderID()] = GetFirstServer(); 01100 #endif 01101 01102 if (m.End()) 01103 sn_SendAll[m.SenderID()] = true; 01104 else 01105 { 01106 sn_SendAll[m.SenderID()] = false; 01107 m >> sn_LastKnown[m.SenderID()]; 01108 } 01109 01110 // give out all server info if there is a disagreement 01111 // if ( static_cast< unsigned int > ( sn_NextTransactionNr - sn_lastKnown[m.SenderID] ) < 1000 ) 01112 sn_SendAll[m.SenderID()] = true; 01113 } 01114 01115 else 01116 { 01117 if ( FloodProtection( m ) ) 01118 return; 01119 01120 // immediately respond with a small info 01121 tJUST_CONTROLLED_PTR< nMessage > ret = tNEW(nMessage)(SmallServerDescriptor); 01122 01123 // get small server info 01124 nServerInfoBase info; 01125 info.GetFrom( sn_Connections[m.SenderID()].socket ); 01126 01127 // fill it in 01128 info.NetWrite(*ret); 01129 01130 unsigned int notrans = 0; 01131 *ret << notrans; 01132 01133 ret->ClearMessageID(); 01134 ret->SendImmediately(m.SenderID(), false); 01135 nMessage::SendCollected(m.SenderID()); 01136 } 01137 }
void nServerInfo::GetBigServerInfo | ( | nMessage & | m | ) | [static] |
Definition at line 1199 of file nServerInfo.cpp.
References GetBigServerInfoCommon(), and server().
01200 { 01201 nServerInfo * server = GetBigServerInfoCommon( m ); 01202 01203 if (!server) 01204 return; 01205 }
void nServerInfo::GiveBigServerInfo | ( | nMessage & | m | ) | [static] |
Definition at line 1207 of file nServerInfo.cpp.
References BigServerDescriptor, FloodProtection(), nServerInfoBase::GetFrom(), GiveBigServerInfoCommon(), nMessage::SenderID(), sn_Connections, sn_IsMaster, and nConnectionInfo::socket.
01208 { 01209 if ( FloodProtection( m ) ) 01210 return; 01211 01212 if (sn_IsMaster) 01213 return; 01214 01215 // collect info 01216 nServerInfo me; 01217 me.GetFrom( sn_Connections[m.SenderID()].socket ); 01218 01219 // delegate 01220 GiveBigServerInfoCommon(m, me, BigServerDescriptor ); 01221 }
void nServerInfo::GetBigServerInfoMaster | ( | nMessage & | m | ) | [static] |
Definition at line 1234 of file nServerInfo.cpp.
References FloodProtection(), GetBigServerInfoCommon(), nSERVER, server(), SetFromMaster(), and sn_GetNetState().
01235 { 01236 if ( sn_GetNetState() == nSERVER && FloodProtection( m ) ) 01237 return; 01238 01239 nServerInfo *server = GetBigServerInfoCommon( m ); 01240 01241 if (!server) 01242 return; 01243 01244 server->SetFromMaster(); 01245 }
void nServerInfo::GiveBigServerInfoMaster | ( | nMessage & | m | ) | [static] |
Definition at line 1247 of file nServerInfo.cpp.
References BigServerMasterDescriptor, FloodProtection(), GetFirstServer(), GiveBigServerInfoCommon(), nServerInfoBase::NetRead(), tListItem< T >::Next(), server(), and sn_IsMaster.
01248 { 01249 if ( FloodProtection( m ) ) 01250 return; 01251 01252 if ( !sn_IsMaster ) 01253 return; 01254 01255 // read info of desired server from message 01256 nServerInfoBase baseInfo; 01257 baseInfo.NetRead( m ); 01258 01259 // find the server 01260 nServerInfo *server = GetFirstServer(); 01261 while( server && *server != baseInfo ) 01262 server = server->Next(); 01263 01264 if (!server) 01265 return; 01266 01267 // delegate 01268 GiveBigServerInfoCommon(m, *server, BigServerMasterDescriptor ); 01269 }
sn_ServerInfoCreator * nServerInfo::SetCreator | ( | sn_ServerInfoCreator * | creator | ) | [static] |
Definition at line 487 of file nServerInfo.cpp.
References sn_Creator.
Referenced by gServerBrowser::BrowseLAN(), and gServerBrowser::BrowseSpecialMaster().
00488 { 00489 sn_ServerInfoCreator* ret = sn_Creator; 00490 sn_Creator = creator; 00491 return ret; 00492 }
void nServerInfo::Save | ( | ) | [static] |
Definition at line 495 of file nServerInfo.cpp.
References tString::Len(), and tDirectories::Var().
Referenced by gServerBrowser::BrowseSpecialMaster(), DeleteAll(), DoQueryAll(), GetFromMaster(), GetSmallServerInfo(), main(), and NetReadThis().
00496 { 00497 if ( sn_LastLoaded.Len() <= 1 ) 00498 { 00499 return; 00500 } 00501 00502 Save( tDirectories::Var(), sn_LastLoaded ); 00503 }
void nServerInfo::Save | ( | const tPath & | path, | |
const char * | filename | |||
) | [static] |
Definition at line 505 of file nServerInfo.cpp.
References GetFirstServer(), tRecorderBase::IsPlayingBack(), tListItem< T >::Next(), tPath::Open(), Prev(), Save(), and START.
00506 { 00507 // don't save on playback 00508 if ( tRecorder::IsPlayingBack() ) 00509 return; 00510 00511 std::ofstream s; 00512 if ( path.Open( s, filename ) ) 00513 { 00514 nServerInfo *run = GetFirstServer(); 00515 while (run && run->Next()) 00516 { 00517 run = run->Next(); 00518 } 00519 00520 while (run) 00521 { 00522 s << START << "\n"; 00523 run->Save(s); 00524 run = run->Prev(); 00525 } 00526 } 00527 }
void nServerInfo::Load | ( | const tPath & | path, | |
const char * | filename | |||
) | [static] |
Definition at line 544 of file nServerInfo.cpp.
References CreateServerInfo(), nServerInfoBase::GetAddress(), GetFirstServer(), tRecorderBase::IsPlayingBack(), Load(), tListItem< T >::Next(), tPath::Open(), tRecorder::Playback(), tRecorder::PlaybackStrict(), tRecorder::Record(), section, server(), and START.
00545 { 00546 sn_LastLoaded = filename; 00547 00548 // read server info from archive 00549 static char const * section = "SERVERINFO"; 00550 static char const * sectionEnd = "SERVERINFOEND"; 00551 if ( tRecorder::IsPlayingBack() ) 00552 { 00553 nServerInfo *server = CreateServerInfo(); 00554 while ( tRecorder::Playback( section, *server ) ) 00555 { 00556 // preemptively resolve DNS 00557 server->GetAddress(); 00558 00559 tRecorder::Record( section, *server ); 00560 server = CreateServerInfo(); 00561 } 00562 delete server; 00563 00564 // acknowledge end of playback 00565 tRecorder::PlaybackStrict( sectionEnd ); 00566 tRecorder::Record( sectionEnd ); 00567 return; 00568 } 00569 00570 00571 std::ifstream s; 00572 path.Open( s, filename ); 00573 00574 while (s.good() && !s.eof()) 00575 { 00576 tString id; 00577 s >> id; 00578 if (id == START) 00579 { 00580 nServerInfo *server = CreateServerInfo(); 00581 server->Load(s); 00582 00583 // record server 00584 tRecorder::Record( section, *server ); 00585 00586 // preemptively resolve DNS 00587 server->GetAddress(); 00588 00589 // remove double servers 00590 bool IsDouble = 0; 00591 nServerInfo *run = GetFirstServer(); 00592 while(!IsDouble && run) 00593 { 00594 if (run != server && *run == *server ) 00595 IsDouble = true; 00596 00597 run = run->Next(); 00598 } 00599 00600 if (IsDouble) 00601 delete server; 00602 } 00603 else 00604 break; 00605 } 00606 00607 // mark end of recording 00608 tRecorder::Record( sectionEnd ); 00609 }
nServerInfo * nServerInfo::GetMasters | ( | ) | [static] |
get the list of master servers
Definition at line 2240 of file nServerInfo.cpp.
References tDirectories::Config(), tListItem< T >::Insert(), Load(), NULL, tListItemBase::Remove(), server(), and tSysTimeFloat().
Referenced by GetRandomMaster(), main(), NetReadThis(), QueryServer(), and TellMasterAboutMe().
02241 { 02242 // reload master list at least once per minute 02243 double time = tSysTimeFloat(); 02244 static double deleteTime = time; 02245 if ( time > deleteTime ) 02246 { 02247 deleteTime = time + 60.0; 02248 02249 while (sn_masterList) 02250 delete sn_masterList; 02251 } 02252 02253 if (!sn_masterList) 02254 { 02255 // back up the regular server list 02256 nServerInfo * oldFirstServer = sn_FirstServer; 02257 sn_FirstServer = NULL; 02258 02259 // load the master server list cleanly 02260 Load( tDirectories::Config(), "master.srv" ); 02261 02262 // transfer list 02263 while ( sn_FirstServer ) 02264 { 02265 nServerInfo * server = sn_FirstServer; 02266 server->Remove(); 02267 server->Insert( sn_masterList ); 02268 } 02269 02270 // restore up the regular server list 02271 sn_FirstServer = oldFirstServer; 02272 } 02273 02274 return sn_masterList; 02275 }
nServerInfo * nServerInfo::GetRandomMaster | ( | ) | [static] |
gets a random master server
Definition at line 2289 of file nServerInfo.cpp.
References tRandomizer::Get(), GetMasters(), tListItem< T >::Insert(), tListItem< T >::Next(), REAL, tListItemBase::Remove(), and tASSERT.
Referenced by GetFromMaster().
02290 { 02291 // select a random master server 02292 nServerInfo * masterInfo = GetMasters(); 02293 02294 // count masters 02295 int count = 0; 02296 while( masterInfo ) 02297 { 02298 masterInfo = masterInfo->Next(); 02299 ++count; 02300 } 02301 02302 // select randomly 02303 static tReproducibleRandomizer randomizer; 02304 REAL ran = randomizer.Get(); 02305 // REAL ran = rand()/REAL(RAND_MAX); 02306 int r = 1; 02307 02308 masterInfo = GetMasters(); 02309 while( masterInfo && masterInfo->Next() && r < ran * count ) 02310 { 02311 masterInfo = masterInfo->Next(); 02312 ++r; 02313 } 02314 02315 tASSERT( masterInfo ); 02316 02317 // store and return 02318 masterInfo->Remove(); 02319 masterInfo->Insert( sn_masterList ); 02320 02321 return masterInfo; 02322 }
void nServerInfo::GetFromMaster | ( | nServerInfoBase * | masterInfo = NULL , |
|
char const * | fileSuffix = NULL | |||
) | [static] |
Definition at line 1383 of file nServerInfo.cpp.
References nMessage::BroadCast(), con, nServerInfoBase::Connect(), DeleteAll(), DeleteUnreachable(), GetFirstServer(), nServerInfoBase::GetName(), GetRandomMaster(), Load(), Login_Post0252, MasterFile(), tConsole::Message(), nABORT, nCLIENT, nDENIED, tListItemBase::next, tListItem< T >::Next(), nOK, nSTANDALONE, nTIMEOUT, REAL, RequestSmallServerInfoDescriptor, Save(), scoreBias_, tOutput::SetTemplateParameter(), sn_AcceptingFromMaster, sn_GetNetState(), sn_Receive(), sn_SendPlanned(), sn_SetNetState(), st_DoToDo(), stillOnMasterServer, tAdvanceFrame(), tNEW, TransactionNr(), TransIsNewer(), tSysTimeFloat(), and tDirectories::Var().
Referenced by gServerBrowser::BrowseSpecialMaster(), and main().
01384 { 01385 sn_AcceptingFromMaster = true; 01386 01387 if ( !fileSuffix ) 01388 { 01389 fileSuffix = ""; 01390 } 01391 01392 bool multiMaster = false; 01393 if (!masterInfo) 01394 { 01395 multiMaster = true; 01396 masterInfo = GetRandomMaster(); 01397 } 01398 01399 if (!masterInfo) 01400 return; 01401 01402 DeleteAll(); 01403 01404 // load all the servers we know 01405 Load( tDirectories::Var(), MasterFile( fileSuffix ) ); 01406 01407 // delete unreachable servers 01408 DeleteUnreachable(); 01409 01410 // find the latest server we know about 01411 unsigned int latest=0; 01412 nServerInfo *run = GetFirstServer(); 01413 if (run) 01414 { 01415 latest = run->TransactionNr(); 01416 run = run->Next(); 01417 while (run) 01418 { 01419 if (TransIsNewer(run->TransactionNr(), latest)) 01420 latest = run->TransactionNr(); 01421 run = run->Next(); 01422 } 01423 } 01424 01425 // connect to the master server 01426 con << tOutput("$network_master_connecting", masterInfo->GetName() ); 01427 01428 nConnectError error = nTIMEOUT; 01429 //try 01430 { 01431 error = masterInfo->Connect( Login_Post0252 ); 01432 } 01433 /* 01434 catch( tException const & ) 01435 { 01436 if ( !masterInfo->Next() ) 01437 throw; 01438 } 01439 #ifdef _MSC_VER 01440 #pragma warning ( disable : 4286 ) 01441 // GRR. Visual C++ dones not handle generic exceptions with the above general statement. 01442 // A specialized version is needed. The best part: it warns about the code below being redundant. 01443 catch( tGenericException const & ) 01444 { 01445 if ( !masterInfo->Next() ) 01446 throw; 01447 } 01448 #endif // _MSC_VER 01449 */ 01450 01451 switch( error ) 01452 { 01453 case nOK: 01454 break; 01455 case nABORT: 01456 { 01457 return; 01458 } 01459 case nTIMEOUT: 01460 // delete the master and select a new one 01461 if ( multiMaster ) 01462 { 01463 delete masterInfo; 01464 masterInfo = sn_masterList; 01465 } 01466 else 01467 { 01468 masterInfo = 0; 01469 } 01470 01471 if ( masterInfo ) 01472 { 01473 con << tOutput( "$network_master_timeout_retry" ); 01474 GetFromMaster( masterInfo ); 01475 } 01476 else 01477 { 01478 tConsole::Message("$network_master_timeout_title", "$network_master_timeout_inter", 3600); 01479 } 01480 return; 01481 break; 01482 01483 case nDENIED: 01484 tConsole::Message("$network_master_denied_title", "$network_master_denied_inter", 20); 01485 return; 01486 break; 01487 01488 } 01489 01490 01491 // send the server list request message 01492 con << tOutput("$network_master_reqlist"); 01493 01494 nMessage *m=tNEW(nMessage)(RequestSmallServerInfoDescriptor); 01495 if (GetFirstServer()) 01496 *m << latest; 01497 m->BroadCast(); 01498 01499 sn_ServerCount = 0; 01500 int lastReported = 10; 01501 01502 // just wait for the data to pour in 01503 REAL timeout = tSysTimeFloat() + 60; 01504 while(sn_GetNetState() == nCLIENT && timeout > tSysTimeFloat()) 01505 { 01506 sn_Receive(); 01507 sn_SendPlanned(); 01508 tAdvanceFrame(100000); 01509 st_DoToDo(); 01510 if (sn_ServerCount > lastReported + 9) 01511 { 01512 tOutput o; 01513 o.SetTemplateParameter(1, lastReported); 01514 o << "$network_master_status"; 01515 con << o; 01516 lastReported = (sn_ServerCount/10) * 10; 01517 } 01518 } 01519 01520 tOutput o; 01521 o.SetTemplateParameter(1, sn_ServerCount); 01522 o << "$network_master_finish"; 01523 con << o; 01524 01525 // remove servers that are no longer listed on the master 01526 run = GetFirstServer(); 01527 while (run) 01528 { 01529 nServerInfo * next = run->Next(); 01530 if ( !run->stillOnMasterServer ) 01531 { 01532 // if the server has still positive score bias, just reduce that 01533 if ( run->scoreBias_ > 0 ) 01534 { 01535 run->scoreBias_ -= 10; 01536 } 01537 else 01538 { 01539 // kill it 01540 delete run; 01541 } 01542 } 01543 run = next; 01544 } 01545 01546 Save(tDirectories::Var(), MasterFile( fileSuffix )); 01547 01548 sn_SetNetState(nSTANDALONE); 01549 01550 sn_AcceptingFromMaster = false; 01551 01552 tAdvanceFrame(); 01553 }
void nServerInfo::TellMasterAboutMe | ( | nServerInfoBase * | masterInfo = NULL |
) | [static] |
Definition at line 1635 of file nServerInfo.cpp.
References nSocketListener::begin(), nMessage::BroadCast(), con, nServerInfoBase::Connect(), nSocketListener::end(), nServerInfoBase::GetAddress(), nServerInfoBase::GetFrom(), nBasicNetworkSystem::GetListener(), GetMasters(), nServerInfoBase::GetName(), nAddress::IsSet(), Login_Post0252, nCLIENT, nDENIED, nServerInfoBase::NetWrite(), tListItem< T >::Next(), nOK, nSERVER, nSTANDALONE, NULL, SmallServerDescriptor, sn_BasicNetworkSystem, sn_Connections, sn_GetNetState(), sn_GetServerPort(), sn_Receive(), sn_SendPlanned(), sn_SetNetState(), tAdvanceFrame(), tNEW, and tSysTimeFloat().
Referenced by sg_HostGame().
01636 { 01637 // don't reinitialize the network system 01638 nSocketResetInhibitor inhibitor; 01639 01640 static unsigned int lastPort = 0; 01641 01642 // enter server state so we know our true port number 01643 sn_SetNetState(nSERVER); 01644 unsigned int port = sn_GetServerPort(); 01645 //if (port == lastPort) 01646 // return; // the master already knows about us 01647 01648 lastPort = port; 01649 01650 // sn_SetNetState(nSTANDALONE); 01651 01652 if (!masterInfo) 01653 { 01654 // recurse, logging in to all masters 01655 nServerInfo * run = GetMasters(); 01656 01657 while ( run ) 01658 { 01659 if ( run->GetAddress().IsSet() ) 01660 { 01661 TellMasterAboutMe( run ); 01662 } 01663 run = run->Next(); 01664 } 01665 01666 return; 01667 } 01668 01669 con << tOutput("$network_master_connecting", masterInfo->GetName() ); 01670 01671 // the socket that the master server connection runs on 01672 nSocket const * connection = NULL; 01673 01674 // connect to the master server; try the listening sockets first 01675 { 01676 nConnectError result = nDENIED; 01677 01678 // iterate through listening sockets 01679 const nSocketListener & listener = sn_BasicNetworkSystem.GetListener(); 01680 for ( nSocketListener::iterator i = listener.begin(); i != listener.end(); ++i ) 01681 { 01682 result = masterInfo->Connect( Login_Post0252, &(*i) ); 01683 if ( nOK == result ) 01684 { 01685 connection = &(*i); 01686 break; 01687 } 01688 } 01689 01690 // try a generic socket next ( a shot in the dark, but worth a try ) 01691 if ( result != nOK ) 01692 { 01693 // leave connection at NULL so the server info will be filled with generic info 01694 connection = NULL; 01695 result = masterInfo->Connect( Login_Post0252 ); 01696 } 01697 01698 // give up 01699 if ( result != nOK ) 01700 return; 01701 } 01702 01703 // collect the server information of this system 01704 nServerInfoBase info; 01705 info.GetFrom( connection ); 01706 01707 // write it to a network message message 01708 nMessage *m=tNEW(nMessage)(SmallServerDescriptor); 01709 info.NetWrite(*m); 01710 unsigned int dummy = 0; 01711 *m << dummy; 01712 01713 // send it 01714 con << tOutput("$network_master_send"); 01715 m->BroadCast(); 01716 sn_Receive(); 01717 sn_SendPlanned(); 01718 01719 // wait for the data to be accepted 01720 nTimeRolling timeout = tSysTimeFloat() + 20; 01721 while(sn_GetNetState() == nCLIENT && timeout > tSysTimeFloat() && sn_Connections[0].ackPending > 0) 01722 { 01723 sn_Receive(); 01724 sn_SendPlanned(); 01725 tAdvanceFrame(10000); 01726 } 01727 01728 sn_SetNetState(nSTANDALONE); 01729 }
void nServerInfo::GetFromLAN | ( | unsigned int | pollBeginPort = 4534 , |
|
unsigned int | pollEndPort = 4544 | |||
) | [static] |
Definition at line 1555 of file nServerInfo.cpp.
References nMessage::BroadcastCollected(), tString::Clear(), nMessage::ClearMessageID(), con, nCLIENT, nSTANDALONE, REAL, RequestSmallServerInfoDescriptor, nMessage::SendImmediately(), tOutput::SetTemplateParameter(), sn_AcceptingFromBroadcast, sn_GetNetState(), sn_Receive(), sn_SendPlanned(), sn_SetNetState(), tAdvanceFrame(), tDelay(), tNEW, and tSysTimeFloat().
Referenced by gServerBrowser::BrowseLAN().
01556 { 01557 sn_AcceptingFromBroadcast = true; 01558 01559 sn_LastLoaded.Clear(); 01560 01561 // enter client state 01562 if (sn_GetNetState() != nCLIENT) 01563 sn_SetNetState(nCLIENT); 01564 01565 // prepare the request message and broadcast is 01566 con << tOutput("$network_master_reqlist"); 01567 for (unsigned int port = pollBeginPort; port <= pollEndPort; port++) 01568 { 01569 nMessage *m=tNEW(nMessage)(RequestSmallServerInfoDescriptor); 01570 m->ClearMessageID(); 01571 m->SendImmediately(0, false); 01572 nMessage::BroadcastCollected(0, port); 01573 tDelay(1000); 01574 } 01575 01576 sn_ServerCount = 0; 01577 int lastReported = 10; 01578 01579 // and just wait a bit for the answers to arrive 01580 REAL timeout = tSysTimeFloat() + 1.5f; 01581 while(sn_GetNetState() == nCLIENT && timeout > tSysTimeFloat()) 01582 { 01583 tAdvanceFrame(); 01584 sn_Receive(); 01585 sn_SendPlanned(); 01586 tAdvanceFrame(10000); 01587 if (sn_ServerCount > lastReported) 01588 { 01589 tOutput o; 01590 o.SetTemplateParameter(1, lastReported); 01591 o << "$network_master_status"; 01592 con << 0; 01593 lastReported = (sn_ServerCount/10) * 10; 01594 } 01595 } 01596 01597 tOutput o; 01598 o.SetTemplateParameter(1, sn_ServerCount); 01599 o << "$network_master_finish"; 01600 con << o; 01601 01602 sn_AcceptingFromBroadcast = false; 01603 01604 sn_SetNetState(nSTANDALONE); 01605 }
void nServerInfo::GetFromLANContinuously | ( | unsigned int | pollBeginPort = 4534 , |
|
unsigned int | pollEndPort = 4544 | |||
) | [static] |
Definition at line 1607 of file nServerInfo.cpp.
References nMessage::BroadcastCollected(), tString::Clear(), nMessage::ClearMessageID(), nCLIENT, RequestSmallServerInfoDescriptor, nMessage::SendImmediately(), sn_AcceptingFromBroadcast, sn_GetNetState(), sn_SetNetState(), tDelay(), and tNEW.
Referenced by gServerMenu::Update().
01608 { 01609 sn_AcceptingFromBroadcast = true; 01610 01611 sn_LastLoaded.Clear(); 01612 01613 // enter client state 01614 if (sn_GetNetState() != nCLIENT) 01615 sn_SetNetState(nCLIENT); 01616 01617 // prepare the request message and broadcast it 01618 for (unsigned int port = pollBeginPort; port <= pollEndPort; port++) 01619 { 01620 nMessage *m=tNEW(nMessage)(RequestSmallServerInfoDescriptor); 01621 m->ClearMessageID(); 01622 m->SendImmediately(0, false); 01623 nMessage::BroadcastCollected(0, port); 01624 tDelay(1000); 01625 } 01626 }
void nServerInfo::GetFromLANContinuouslyStop | ( | ) | [static] |
Definition at line 1628 of file nServerInfo.cpp.
References nSTANDALONE, sn_AcceptingFromBroadcast, and sn_SetNetState().
Referenced by gServerBrowser::BrowseServers(), gServerStartMenuItem::Enter(), and gServerMenuItem::Enter().
01629 { 01630 sn_AcceptingFromBroadcast = false; 01631 01632 sn_SetNetState(nSTANDALONE); 01633 }
void nServerInfo::DeleteUnreachable | ( | void | ) | [static] |
Removes unreachable servers from the list.
Definition at line 1903 of file nServerInfo.cpp.
References GetFirstServer(), tListItem< T >::Next(), NULL, sn_MaxTNA(), sn_MaxTNATotal(), sn_MaxUnreachable(), sn_TNALostContact, TimesNotAnswered(), and TNA.
Referenced by GetFromMaster(), and RunMaster().
01904 { 01905 int totalTNAMax = sn_MaxTNATotal(); 01906 int maxUnreachable = sn_MaxUnreachable(); 01907 int totalTNA = totalTNAMax + 1; 01908 int lastTNA = totalTNA + 1; 01909 int unreachableCount = 0; 01910 01911 while ( ( totalTNA > totalTNAMax || unreachableCount > maxUnreachable ) && lastTNA != totalTNA ) 01912 { 01913 lastTNA = totalTNA; 01914 totalTNA = 0; 01915 unreachableCount = 0; 01916 01917 nServerInfo *kickOut = NULL; 01918 int maxTNA = 0; 01919 int minTNA = 100; 01920 01921 nServerInfo * run = GetFirstServer(); 01922 01923 while(run) 01924 { 01925 // run->score = run->scoreBias_; 01926 01927 int TNA = run->TimesNotAnswered(); 01928 // sum up TNAs and determine server with maximum TNA 01929 if ( TNA > 0 && TNA <= sn_MaxTNA() ) 01930 { 01931 unreachableCount++; 01932 totalTNA += TNA; 01933 if ( TNA > maxTNA ) 01934 { 01935 maxTNA = TNA; 01936 kickOut = run; 01937 } 01938 } 01939 01940 if ( TNA < minTNA ) 01941 { 01942 minTNA = TNA; 01943 } 01944 01945 run = run->Next(); 01946 } 01947 01948 if ( minTNA > 0 ) 01949 { 01950 // no server was reachable at all! Ehternet cable is probably pulled. 01951 return; 01952 } 01953 01954 // mark worst server for kickout if total TNA is too high 01955 if ( kickOut && ( ( totalTNA > totalTNAMax && maxTNA >= sn_TNALostContact ) || unreachableCount > maxUnreachable ) ) 01956 { 01957 // just delete the bastard! 01958 delete kickOut; 01959 // kickOut->timesNotAnswered = sn_MaxTNA() + 100; 01960 } 01961 } 01962 }
void nServerInfo::StartQueryAll | ( | QueryType | query = QUERY_ALL |
) | [static] |
Definition at line 1964 of file nServerInfo.cpp.
References advancedInfoSet, advancedInfoSetEver, nServerInfoBase::ClearAddress(), nServerInfoBase::GetAddress(), GetFirstServer(), GrowingArrayBase::Len(), tListItem< T >::Next(), pollID, queried, tList< T, MALLOC, REFERENCE >::Remove(), SetQueryType(), sn_Polling, TimesNotAnswered(), and TNA.
Referenced by gServerBrowser::BrowseServers(), main(), Poll(), Refresh(), and gServerMenu::Update().
01965 { 01966 sn_Requesting = GetFirstServer(); 01967 01968 while (sn_Polling.Len()) 01969 sn_Polling.Remove(sn_Polling(0), sn_Polling(0)->pollID); 01970 01971 nServerInfo *run = GetFirstServer(); 01972 01973 while(run) 01974 { 01975 // set the query type 01976 run->SetQueryType( queryType ); 01977 01978 // do a DNS query of the server 01979 run->ClearAddress(); 01980 run->GetAddress(); 01981 01982 run->queried = 0; 01983 run->advancedInfoSet = 0; 01984 01985 int TNA = run->TimesNotAnswered(); 01986 01987 // remove known status 01988 if ( TNA > 0 ) 01989 { 01990 run->advancedInfoSetEver = false; 01991 } 01992 else 01993 { 01994 // run->advancedInfoSetEver = true; 01995 } 01996 01997 run = run->Next(); 01998 } 01999 }
bool nServerInfo::DoQueryAll | ( | int | simultaneous = 10 |
) | [static] |
Definition at line 2001 of file nServerInfo.cpp.
References advancedInfoSet, GetFirstServer(), GrowingArrayBase::Len(), tListItem< T >::Next(), tListItemBase::next, pollID, queried, QueryServer(), REAL, tList< T, MALLOC, REFERENCE >::Remove(), Save(), sn_numQueries, sn_Polling, sn_queryDelay, sn_queryDelayGlobal, sn_Receive(), sn_SendPlanned(), timeQuerySent, tSysTimeFloat(), and x.
Referenced by main(), Poll(), and gBrowserMenuItem::RenderBackground().
02001 : do we need to go on with this? 02002 { 02003 REAL time = tSysTimeFloat(); 02004 02005 static REAL globalTimeout = time; 02006 if ( time < globalTimeout ) 02007 { 02008 return true; 02009 } 02010 02011 globalTimeout = time + sn_queryDelayGlobal; 02012 02013 for (int i=sn_Polling.Len()-1; i>=0; i--) 02014 { 02015 nServerInfo* poll = sn_Polling(i); 02016 if (poll->timeQuerySent + sn_queryDelay < time) 02017 sn_Polling.Remove(poll, poll->pollID); 02018 } 02019 02020 if (sn_Requesting && sn_Polling.Len() < simultaneous) 02021 { 02022 nServerInfo* next = sn_Requesting->Next(); 02023 02024 if (!sn_Requesting->advancedInfoSet && sn_Requesting->pollID < 0 && sn_Requesting->queried <= sn_numQueries) 02025 { 02026 sn_Requesting->QueryServer(); 02027 } 02028 #ifdef DEBUG 02029 else 02030 { 02031 int x; 02032 x = 1; 02033 } 02034 #endif 02035 02036 sn_Requesting = next; 02037 } 02038 02039 sn_Receive(); 02040 sn_SendPlanned(); 02041 02042 if (sn_Requesting) 02043 return true; 02044 else 02045 { 02046 bool ret = false; 02047 02048 nServerInfo *run = GetFirstServer(); 02049 while(run && !ret) 02050 { 02051 if (!run->advancedInfoSet && (run->queried <= sn_numQueries-1 || run->pollID >= 0)) 02052 ret = true; 02053 02054 run = run->Next(); 02055 } 02056 02057 if (ret) 02058 { 02059 sn_Requesting = GetFirstServer(); 02060 Save(); 02061 } 02062 else 02063 Save(); 02064 02065 return ret; 02066 } 02067 }
void nServerInfo::QueryServer | ( | ) |
Definition at line 1731 of file nServerInfo.cpp.
References tList< T, MALLOC, REFERENCE >::Add(), advancedInfoSetEver, con, tRandomizer::Get(), nServerInfoBase::GetAddress(), GetFirstServer(), GetMasters(), name, nServerInfoBase::NetWriteThis(), tListItem< T >::Next(), NULL, pollID, queried, QUERY_ALL, QUERY_NONE, QUERY_OPTIN, QUERY_OPTOUT, queryType_, RequestBigServerInfoDescriptor, RequestBigServerInfoMasterDescriptor, score, scoreBias_, nMessage::SendCollected(), SetFromMaster(), sn_Bend(), sn_IsMaster, sn_MaxTNA(), sn_TNALostContact, timeQuerySent, timesNotAnswered, tNEW, ToString(), transactionNr, TransactionNr(), TransIsNewer(), and tSysTimeFloat().
Referenced by DoQueryAll(), gServerMenuItem::Event(), GetBigServerInfoCommon(), GetSmallServerInfo(), and RunMaster().
01732 { 01733 // determine whether we should query directly or via the master 01734 bool queryDirectly = false; 01735 switch( queryType_ ) 01736 { 01737 case QUERY_ALL: 01738 queryDirectly = true; 01739 break; 01740 case QUERY_OPTOUT: 01741 queryDirectly = ( scoreBias_ >= 0 ); 01742 break; 01743 case QUERY_OPTIN: 01744 queryDirectly = ( scoreBias_ > 0 ); 01745 break; 01746 case QUERY_NONE: 01747 queryDirectly = false; 01748 break; 01749 } 01750 01751 // early exit if there is nothing to poll 01752 if ( !queryDirectly ) 01753 { 01754 // see if the server name is just IP:port; if no, we already successfully polled it 01755 if ( name != ToString( *this ) ) 01756 { 01757 advancedInfoSetEver = true; 01758 } 01759 01760 if( advancedInfoSetEver ) 01761 { 01762 // but only 90% of the time, we want to know if the server goes down sometime. 01763 static tReproducibleRandomizer randomizer; 01764 if ( randomizer.Get() > .1 && timesNotAnswered == 0 ) 01765 { 01766 SetFromMaster(); 01767 return; 01768 } 01769 } 01770 } 01771 01772 sn_Polling.Add(this, pollID); 01773 01774 #ifdef DEBUG 01775 if ( sn_IsMaster ) 01776 { 01777 con << "Querying server " << ToString( *this ) << "\n"; 01778 } 01779 #endif 01780 01781 if (timesNotAnswered > sn_MaxTNA() ) 01782 { 01783 // server was inactive too long. Delete it if possible. 01784 01785 // check if this server is the one with the highest TAN 01786 unsigned int latest=0; 01787 nServerInfo *run = GetFirstServer(); 01788 nServerInfo *best = NULL; 01789 while (run == this) 01790 run = run->Next(); 01791 01792 if (run) 01793 { 01794 latest = run->TransactionNr(); 01795 best = run; 01796 run = run->Next(); 01797 01798 while (run) 01799 { 01800 if ((run != this) && TransIsNewer(run->TransactionNr(), latest)) 01801 { 01802 latest = run->TransactionNr(); 01803 best = run; 01804 } 01805 run = run->Next(); 01806 } 01807 } 01808 01809 // now, best points to the latest (except this) server and 01810 // latest is its TAN. 01811 01812 // continue if this server is the only one available 01813 if (best) 01814 { 01815 // if THIS server has the latest TAN, simpy transfer it to the second latest. 01816 if (TransIsNewer(TransactionNr(), latest)) 01817 best->transactionNr = TransactionNr(); 01818 01819 timesNotAnswered = 1000; 01820 if ( sn_IsMaster ) 01821 { 01822 con << "Deleted unreachable server: " << ToString( *this ) << "\n"; 01823 01824 delete this; 01825 } 01826 return; 01827 } 01828 } 01829 01830 if ( queryDirectly ) 01831 { 01832 // send information query directly to server 01833 sn_Bend( GetAddress() ); 01834 01835 tJUST_CONTROLLED_PTR< nMessage > req = tNEW(nMessage)(RequestBigServerInfoDescriptor); 01836 req->ClearMessageID(); 01837 req->SendImmediately(0, false); 01838 nMessage::SendCollected(0); 01839 } 01840 else 01841 { 01842 // send information query to master 01843 sn_Bend( GetMasters()->GetAddress() ); 01844 01845 tJUST_CONTROLLED_PTR< nMessage > req = tNEW(nMessage)(RequestBigServerInfoMasterDescriptor); 01846 req->ClearMessageID(); 01847 01848 // write server info into request packet 01849 nServerInfoBase::NetWriteThis( *req ); 01850 01851 req->SendImmediately(0, false); 01852 nMessage::SendCollected(0); 01853 } 01854 01855 timeQuerySent = tSysTimeFloat(); 01856 if ( queried == 0 ) 01857 { 01858 if ( ++timesNotAnswered == sn_TNALostContact && sn_IsMaster ) 01859 { 01860 con << "Lost contact with server: " << ToString( *this ) << "\n"; 01861 } 01862 else if ( sn_IsMaster && timesNotAnswered == 2 ) 01863 { 01864 con << "Starting to lose contact with server: " << ToString( *this ) << ", name \"" << tColoredString::RemoveColors(name) << "\"\n"; 01865 } 01866 } 01867 01868 queried++; 01869 01870 if ( !this->advancedInfoSetEver ) 01871 { 01872 score = -1E+32f; 01873 } 01874 }
void nServerInfo::SetQueryType | ( | QueryType | query | ) |
Definition at line 1876 of file nServerInfo.cpp.
References queryType_.
Referenced by gServerMenuItem::Event(), and StartQueryAll().
01877 { 01878 queryType_ = queryType; 01879 }
void nServerInfo::ClearInfoFlags | ( | ) |
clears information sent flags
Definition at line 1882 of file nServerInfo.cpp.
References advancedInfoSet, advancedInfoSetEver, and ping.
Referenced by gServerMenuItem::Event().
01883 { 01884 advancedInfoSetEver = advancedInfoSet = false; 01885 ping = 10; 01886 }
void nServerInfo::SetFromMaster | ( | ) |
indicate that this server was fetched through the master
Definition at line 1223 of file nServerInfo.cpp.
References advancedInfoSet, CalcScore(), ping, userNames_, userNamesOneLine_, and users.
Referenced by GetBigServerInfoMaster(), and QueryServer().
01224 { 01225 // no information about ping 01226 ping = .999; 01227 users = 0; 01228 userNames_ = userNamesOneLine_ = "Sever polled over master server, no reliable user data available."; 01229 advancedInfoSet = true; 01230 01231 CalcScore(); 01232 }
void nServerInfo::RunMaster | ( | ) | [static] |
Definition at line 2103 of file nServerInfo.cpp.
References DeleteUnreachable(), GetFirstServer(), KRAWALL_SERVER, MAXCLIENTS, tListItem< T >::Next(), NULL, QueryServer(), nMessage::Send(), SmallServerDescriptor, sn_AcceptingFromBroadcast, sn_Connections, sn_DisconnectUser(), sn_IsMaster, sn_LastKnown, sn_MessagesPending(), sn_NextTransactionNr, sn_QueryTimeout, sn_Receive(), sn_Requested, sn_SendAll, sn_SendPlanned(), sn_Timeout, sn_TNALostContact, TimesNotAnswered(), tNEW, TransactionNr(), TransIsNewer(), and tSysTimeFloat().
Referenced by main().
02104 { 02105 sn_IsMaster = true; 02106 sn_AcceptingFromBroadcast = true; 02107 02108 DeleteUnreachable(); 02109 02110 nTimeRolling time = tSysTimeFloat(); 02111 if (time > sn_QueryTimeout && sn_QuerySoon) 02112 { 02113 sn_QuerySoon->QueryServer(); 02114 sn_QuerySoon = NULL; 02115 std::cout.flush(); 02116 std::cerr.flush(); 02117 } 02118 02119 if (sn_NextTransactionNr == 0) 02120 // find the latest server we know about 02121 { 02122 unsigned int latest=0; 02123 nServerInfo *run = GetFirstServer(); 02124 if (run) 02125 { 02126 latest = run->TransactionNr(); 02127 run = run->Next(); 02128 while (run) 02129 { 02130 if (TransIsNewer(run->TransactionNr(), latest)) 02131 latest = run->TransactionNr(); 02132 run = run->Next(); 02133 } 02134 } 02135 02136 latest++; 02137 if (latest == 0) 02138 latest ++; 02139 02140 sn_NextTransactionNr = latest; 02141 } 02142 02143 // start with random transaction number 02144 if (sn_NextTransactionNr == 0) 02145 { 02146 sn_NextTransactionNr = rand(); 02147 } 02148 02149 for (int i=MAXCLIENTS; i>0; i--) 02150 { 02151 if(sn_Connections[i].socket) 02152 { 02153 // kick the user soon when the transfer is completed 02154 if ((sn_Requested[i] && !sn_Transmitting[i] 02155 #ifdef KRAWALL_SERVER 02156 && sn_Auth[i] 02157 #endif 02158 && sn_MessagesPending(i) == 0)) 02159 { 02160 if (sn_Timeout[i] > tSysTimeFloat() + .2f) 02161 sn_Timeout[i] = tSysTimeFloat() + .2f; 02162 } 02163 02164 // defend against DOS attacks: Kill idle clients 02165 if(sn_Timeout[i] < tSysTimeFloat()) 02166 sn_DisconnectUser(i, "$network_kill_timeout"); 02167 02168 if (!sn_Requested[i] && sn_Timeout[i] < tSysTimeFloat() + 60.0f) 02169 sn_DisconnectUser(i, "$network_kill_timeout"); 02170 02171 } 02172 02173 if (sn_Transmitting[i] && sn_MessagesPending(i) < 3) 02174 { 02175 02176 for (int j = 10-sn_MessagesPending(i); j>=0 && sn_Transmitting[i]; j--) 02177 { 02178 // skip known servers 02179 if (!sn_SendAll[i]) 02180 { 02181 while (sn_Transmitting[i] && !TransIsNewer(sn_Transmitting[i]->TransactionNr(), sn_LastKnown[i])) 02182 sn_Transmitting[i] = sn_Transmitting[i]->Next(); 02183 } 02184 02185 if (!sn_Transmitting[i]) 02186 continue; 02187 02188 if (sn_Transmitting[i]->TimesNotAnswered() < sn_TNALostContact ) 02189 { 02190 // tell user i about server sn_Transmitting[i] 02191 nMessage *m = tNEW(nMessage)(SmallServerDescriptor); 02192 sn_Transmitting[i]->nServerInfoBase::NetWriteThis( *m ); 02193 *m << sn_Transmitting[i]->TransactionNr(); 02194 m->Send(i); 02195 } 02196 02197 sn_Transmitting[i] = sn_Transmitting[i]->Next(); 02198 } 02199 } 02200 02201 } 02202 02203 sn_Receive(); 02204 sn_SendPlanned(); 02205 }
bool nServerInfo::Reachable | ( | ) | const |
Definition at line 2207 of file nServerInfo.cpp.
References advancedInfoSetEver, sn_TNALostContact, and TimesNotAnswered().
Referenced by Poll(), gServerMenuItem::Render(), and Sort().
02208 { 02209 return advancedInfoSetEver && TimesNotAnswered() < sn_TNALostContact; 02210 }
bool nServerInfo::Polling | ( | ) | const |
Definition at line 2212 of file nServerInfo.cpp.
References advancedInfoSetEver, queried, sn_TNALostContact, and TimesNotAnswered().
Referenced by gServerMenuItem::Render(), and Sort().
02213 { 02214 return (!advancedInfoSetEver && queried <= 3 && TimesNotAnswered() < sn_TNALostContact );// || ( !advancedInfoSet && queried > 1 && queried <= 3 ); 02215 }
unsigned int nServerInfo::TransactionNr | ( | ) | const [inline] |
Definition at line 279 of file nServerInfo.h.
References transactionNr.
Referenced by GetFromMaster(), QueryServer(), and RunMaster().
00279 {return transactionNr;}
unsigned int nServerInfo::Method | ( | ) | const [inline] |
const tArray<unsigned int>& nServerInfo::Key | ( | ) | const [inline] |
REAL nServerInfo::Ping | ( | ) | const [inline] |
Definition at line 282 of file nServerInfo.h.
References ping.
Referenced by Poll(), and gServerMenuItem::Render().
00282 {return ping;}
const nVersion& nServerInfo::Version | ( | ) | const [inline] |
int nServerInfo::TimesNotAnswered | ( | ) | const [inline] |
Definition at line 285 of file nServerInfo.h.
References timesNotAnswered.
Referenced by Alive(), DeleteUnreachable(), Polling(), Reachable(), RunMaster(), and StartQueryAll().
00285 {return timesNotAnswered;}
int nServerInfo::Users | ( | ) | const [inline] |
Definition at line 287 of file nServerInfo.h.
References users.
Referenced by Poll(), gServerMenuItem::Render(), and gServerMenu::Update().
00287 {return users;}
int nServerInfo::MaxUsers | ( | ) | const [inline] |
Definition at line 288 of file nServerInfo.h.
References maxUsers_.
Referenced by gServerMenuItem::Render().
00288 {return maxUsers_;}
const tString& nServerInfo::UserNames | ( | ) | const [inline] |
Definition at line 290 of file nServerInfo.h.
References userNames_.
Referenced by gServerMenu::Update().
00290 { return userNames_; }
const tString& nServerInfo::UserNamesOneLine | ( | ) | const [inline] |
Definition at line 291 of file nServerInfo.h.
References userNamesOneLine_.
Referenced by gServerMenuItem::RenderBackground().
00291 { return userNamesOneLine_; }
const tString& nServerInfo::Options | ( | ) | const [inline] |
Definition at line 292 of file nServerInfo.h.
References options_.
Referenced by gServerMenuItem::RenderBackground().
00292 { return options_; }
const tString& nServerInfo::Release | ( | ) | const [inline] |
Definition at line 293 of file nServerInfo.h.
References release_.
Referenced by gServerMenuItem::RenderBackground().
00293 { return release_; }
const tString& nServerInfo::Url | ( | ) | const [inline] |
Definition at line 294 of file nServerInfo.h.
References url_.
Referenced by gServerMenuItem::RenderBackground().
00294 { return url_; }
REAL nServerInfo::Score | ( | ) | const [inline] |
Definition at line 296 of file nServerInfo.h.
References score.
Referenced by gServerMenuItem::Render().
00296 {return score;}
nServerInfo::Compat nServerInfo::Compatibility | ( | ) | const |
Definition at line 2324 of file nServerInfo.cpp.
References Compat_Downgrade, Compat_Ok, Compat_Upgrade, nVersion::Max(), nVersion::Min(), sn_MyVersion(), and version_.
Referenced by gServerMenuItem::Render().
02325 { 02326 if ( sn_MyVersion().Min() > version_.Max() ) 02327 { 02328 return Compat_Downgrade; 02329 } 02330 02331 if ( sn_MyVersion().Max() < version_.Min() ) 02332 { 02333 return Compat_Upgrade; 02334 } 02335 02336 return Compat_Ok; 02337 }
nServerInfo & nServerInfo::SetScoreBias | ( | int | scoreBias | ) | [inline] |
Sets score bias for this server.
scoreBias | score bias for this server to set |
Definition at line 394 of file nServerInfo.h.
References scoreBias_.
Referenced by gServerMenuItem::Event().
00395 { 00396 this->scoreBias_ = scoreBias; 00397 return *this; 00398 }
int nServerInfo::GetScoreBias | ( | void | ) | const [inline] |
Gets score bias for this server.
Definition at line 361 of file nServerInfo.h.
References scoreBias_.
Referenced by gServerMenuItem::Event().
00362 { 00363 return this->scoreBias_; 00364 }
nServerInfo const & nServerInfo::GetScoreBias | ( | int & | scoreBias | ) | const [inline] |
Gets score bias for this server.
scoreBias | score bias for this server to fill |
Definition at line 377 of file nServerInfo.h.
References scoreBias_.
00378 { 00379 scoreBias = this->scoreBias_; 00380 return *this; 00381 }
const tString & nServerInfo::DoGetName | ( | void | ) | const [protected, virtual] |
returns the server's name
Reimplemented from nServerInfoBase.
Definition at line 2967 of file nServerInfo.cpp.
References name.
02968 { 02969 return name; 02970 }
int nServerInfo::pollID [private] |
Definition at line 113 of file nServerInfo.h.
Referenced by DoQueryAll(), NetReadThis(), QueryServer(), StartQueryAll(), and ~nServerInfo().
unsigned int nServerInfo::transactionNr [protected] |
Definition at line 116 of file nServerInfo.h.
Referenced by Alive(), GetSmallServerInfo(), Load(), QueryServer(), Save(), and TransactionNr().
int nServerInfo::method [protected] |
tArray<unsigned int> nServerInfo::key [protected] |
bool nServerInfo::advancedInfoSet [protected] |
Definition at line 123 of file nServerInfo.h.
Referenced by ClearInfoFlags(), DoQueryAll(), Load(), NetReadThis(), SetFromMaster(), and StartQueryAll().
bool nServerInfo::advancedInfoSetEver [protected] |
Definition at line 124 of file nServerInfo.h.
Referenced by ClearInfoFlags(), Load(), NetReadThis(), Polling(), QueryServer(), Reachable(), and StartQueryAll().
int nServerInfo::queried [protected] |
Definition at line 125 of file nServerInfo.h.
Referenced by DoQueryAll(), GetSmallServerInfo(), Load(), NetReadThis(), Polling(), QueryServer(), and StartQueryAll().
nTimeRolling nServerInfo::timeQuerySent [protected] |
Definition at line 127 of file nServerInfo.h.
Referenced by DoQueryAll(), NetReadThis(), and QueryServer().
REAL nServerInfo::ping [protected] |
Definition at line 128 of file nServerInfo.h.
Referenced by CalcScore(), ClearInfoFlags(), NetReadThis(), Ping(), SetFromMaster(), and Sort().
nVersion nServerInfo::version_ [protected] |
Definition at line 130 of file nServerInfo.h.
Referenced by Compatibility(), DoGetFrom(), Load(), NetReadThis(), NetWriteThis(), Save(), and Version().
tString nServerInfo::release_ [protected] |
Definition at line 131 of file nServerInfo.h.
Referenced by DoGetFrom(), Load(), NetReadThis(), NetWriteThis(), Release(), and Save().
bool nServerInfo::login2_ [protected] |
int nServerInfo::timesNotAnswered [protected] |
Definition at line 134 of file nServerInfo.h.
Referenced by GetSmallServerInfo(), Load(), NetReadThis(), QueryServer(), Save(), and TimesNotAnswered().
bool nServerInfo::stillOnMasterServer [protected] |
Definition at line 135 of file nServerInfo.h.
Referenced by GetFromMaster(), and GetSmallServerInfo().
tString nServerInfo::name [protected] |
Definition at line 138 of file nServerInfo.h.
Referenced by DoGetFrom(), DoGetName(), GetBigServerInfoCommon(), GetSmallServerInfo(), Load(), NetReadThis(), NetWriteThis(), QueryServer(), Save(), and Sort().
int nServerInfo::users [protected] |
Definition at line 139 of file nServerInfo.h.
Referenced by CalcScore(), DoGetFrom(), NetReadThis(), NetWriteThis(), SetFromMaster(), Sort(), and Users().
int nServerInfo::maxUsers_ [protected] |
Definition at line 140 of file nServerInfo.h.
Referenced by CalcScore(), DoGetFrom(), MaxUsers(), NetReadThis(), and NetWriteThis().
tString nServerInfo::userNames_ [protected] |
Definition at line 142 of file nServerInfo.h.
Referenced by DoGetFrom(), NetReadThis(), NetWriteThis(), SetFromMaster(), and UserNames().
tString nServerInfo::userNamesOneLine_ [protected] |
Definition at line 143 of file nServerInfo.h.
Referenced by NetReadThis(), SetFromMaster(), and UserNamesOneLine().
tString nServerInfo::options_ [protected] |
Definition at line 144 of file nServerInfo.h.
Referenced by DoGetFrom(), NetReadThis(), NetWriteThis(), and Options().
tString nServerInfo::url_ [protected] |
Definition at line 145 of file nServerInfo.h.
Referenced by DoGetFrom(), Load(), NetReadThis(), NetWriteThis(), Save(), and Url().
REAL nServerInfo::score [protected] |
Definition at line 147 of file nServerInfo.h.
Referenced by CalcScore(), Load(), QueryServer(), Score(), and Sort().
int nServerInfo::scoreBias_ [protected] |
Definition at line 148 of file nServerInfo.h.
Referenced by CalcScore(), GetFromMaster(), GetScoreBias(), Load(), QueryServer(), Save(), and SetScoreBias().
QueryType nServerInfo::queryType_ [private] |
the query type to use for this server
Definition at line 314 of file nServerInfo.h.
Referenced by QueryServer(), and SetQueryType().