src/network/astat.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 // ASTAT utility: command line interface to server browser
00029 
00030 #include "nServerInfo.h"
00031 #include "nNetwork.h"
00032 #include "tConsole.h"
00033 #include "tDirectories.h"
00034 #include "tLocale.h"
00035 #include "nSocket.h"
00036 #include "tCommandLine.h"
00037 
00038 #include <iostream>
00039 
00040 // hide status messages
00041 class nCon:public tConsole
00042 {
00043 public:
00044     virtual tConsole &Print(const tString &s){return *this;}
00045     nCon(){RegisterBetterConsole(this);}
00046 };
00047 
00048 static nCon ncon;
00049 
00050 
00051 
00052 
00053 void Poll()
00054 {
00055     // poll the servers
00056     nServerInfo::StartQueryAll();
00057     while (nServerInfo::DoQueryAll(10)) usleep(1000);
00058     sn_SetNetState(nSTANDALONE);
00059 
00060     int servers = 0, users = 0;
00061 
00062     // print the list
00063     nServerInfo* run = nServerInfo::GetFirstServer();
00064     while (run)
00065     {
00066 
00067         std::cout << run->GetConnectionName() << "\t" << run->GetPort() << "\t"
00068         << run->Users() << "\t" << run->Ping() << "\n";
00069 
00070         servers += run->Reachable() ? 1 : 0;
00071         users += run->Users();
00072 
00073         run = run->Next();
00074     }
00075 
00076     std::cout << "\nservers: " << servers
00077     << "\nusers  : " << users << "\n";
00078 
00079     nServerInfo::DeleteAll();
00080 
00081 }
00082 
00083 int main(int argc, char **argv)
00084 {
00085     // get the list
00086     //  nServerInfo::GetFromLAN();          // or rather from the local net
00087     //  std::cout << "LAN:\n";
00088     //  Poll();
00089 
00090     tCommandLineData commandLine;
00091     commandLine.programVersion_  = &sn_programVersion;
00092     commandLine.Analyse(argc, argv);
00093     tLocale::Load("languages.txt");
00094 
00095     nServerInfo::GetFromMaster();   // from the master server
00096     //  std::cout << "MASTER:\n";
00097     Poll();
00098 
00099     tLocale::Clear();
00100     sn_BasicNetworkSystem.Shutdown();
00101 }

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