src/network/master.cpp

Go to the documentation of this file.
00001 /*
00002 
00003 *************************************************************************
00004 
00005 ArmageTron -- Just another Tron Lightcycle Game in 3D.
00006 Copyright (C) 2000  Manuel Moos (manuel@moosnet.de)
00007 
00008 **************************************************************************
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 GNU General Public License for more details.
00019 
00020 You should have received a copy of the GNU General Public License
00021 along with this program; if not, write to the Free Software
00022 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00023   
00024 ***************************************************************************
00025 
00026 */
00027 
00028 #include "tConfiguration.h"
00029 #include "tDirectories.h"
00030 #include "nNetwork.h"
00031 #include "nServerInfo.h"
00032 #include "tSysTime.h"
00033 #include "tLocale.h"
00034 #include "tCommandLine.h"
00035 #include "nSocket.h"
00036 #include  <time.h>
00037 
00038 REAL save_interval = 300.0f;
00039 static tSettingItem< REAL > si( "MASTER_SAVE_INTERVAL", save_interval );
00040 
00041 REAL query_interval = 10.0f;
00042 static tSettingItem< REAL > qi( "MASTER_QUERY_INTERVAL", query_interval );
00043 
00044 int master_port = 4533;
00045 static tSettingItem< int > mp( "MASTER_PORT", master_port );
00046 
00047 REAL master_idle = 2;
00048 static tSettingItem< REAL > mi( "MASTER_IDLE", master_idle );
00049 
00050 // console with filter for better machine readable log format
00051 class nConsoleDateFilter:public tConsoleFilter{
00052 private:
00053     virtual void DoFilterLine( tString &line )
00054     {
00055         char szTemp[128];
00056         time_t     now;
00057         struct tm *pTime;
00058         now = time(NULL);
00059         pTime = localtime(&now);
00060         strftime(szTemp,sizeof(szTemp),"[%Y/%m/%d %H:%M:%S] ",pTime);
00061 
00062         tString orig = line;
00063         line = "";
00064         line << szTemp  << orig;
00065     }
00066 
00067     virtual int DoGetPriority() const{ return 1; }
00068 };
00069 
00070 static nConsoleDateFilter sn_consoleFilter;
00071 
00072 int main(int argc, char** argv)
00073 {
00074     tCommandLineData commandLine;
00075     commandLine.programVersion_ = &sn_programVersion;
00076     commandLine.Analyse(argc, argv);
00077     tLocale::Load("languages.txt");
00078     atexit(tLocale::Clear);
00079 
00080     st_LoadConfig();
00081 
00082     nServerInfo::GetMasters();
00083 
00084 
00085 #ifdef DEBUG
00086     // std::istringstream s("SERVER_IP ANY");
00087     // tConfItemBase::LoadAll( s );
00088 #endif
00089 
00090     nServerInfo::Load( tDirectories::Var(), "master_list.srv" );
00091 
00092     nServerInfo::StartQueryAll();
00093     //  st_LoadConfig();
00094 
00095     sn_serverPort = master_port;
00096     sn_SetNetState(nSERVER);
00097 
00098     nTimeAbsolute savetimeout  = tSysTimeFloat();
00099     nTimeAbsolute querytimeout = tSysTimeFloat();
00100     nTimeAbsolute quitTimeout  = tSysTimeFloat() + master_idle * 3600;
00101 
00102     bool goon = true;
00103     while ( goon )
00104     {
00105         nServerInfo::RunMaster();
00106 
00107         sn_BasicNetworkSystem.Select( .1f );
00108         tAdvanceFrame();
00109         nTimeAbsolute time = tSysTimeFloat();
00110 
00111         sn_Receive();
00112         sn_ReceiveFromControlSocket();
00113         sn_SendPlanned();
00114 
00115         static bool queryGoesOn = true;
00116         if (queryGoesOn && time > querytimeout)
00117         {
00118             queryGoesOn = nServerInfo::DoQueryAll(1);
00119             querytimeout = time + query_interval;
00120         }
00121 
00122         if (time > savetimeout)
00123         {
00124             nServerInfo::Save( tDirectories::Var(), "master_list.srv" );
00125             if (!queryGoesOn)
00126             {
00127                 nServerInfo::StartQueryAll();
00128                 queryGoesOn = true;
00129             }
00130             savetimeout = time + save_interval;
00131 
00132             goon = time < quitTimeout;
00133         }
00134     }
00135 
00136     nServerInfo::DeleteAll();
00137 
00138     return(0);
00139 }
00140 

Generated on Sat Mar 15 22:55:49 2008 for Armagetron Advanced by  doxygen 1.5.4