networksupervisor.cpp

Go to the documentation of this file.
00001 
00008 /*
00009     This file is part of Advanced Strategic Command; http://www.asc-hq.de
00010     Copyright (C) 1994-2010  Martin Bickel  and  Marc Schellenberger
00011 
00012     This program is free software; you can redistribute it and/or modify
00013     it under the terms of the GNU General Public License as published by
00014     the Free Software Foundation; either version 2 of the License, or
00015     (at your option) any later version.
00016 
00017     This program is distributed in the hope that it will be useful,
00018     but WITHOUT ANY WARRANTY; without even the implied warranty of
00019     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020     GNU General Public License for more details.
00021 
00022     You should have received a copy of the GNU General Public License
00023     along with this program; see the file COPYING. If not, write to the 
00024     Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00025     Boston, MA  02111-1307  USA
00026 */
00027 
00028 #include <stdio.h>                    
00029 #include <stdlib.h>
00030 #include <cstring>
00031 
00032 #include "global.h"
00033 #include "misc.h"
00034 #include "typen.h"
00035 #include "network/simple_file_transfer.h"
00036 #include "dlg_box.h"
00037 #include "dialog.h"
00038 #include "sgstream.h"
00039 #include "loadpcx.h"
00040 #include "dialogs/pwd_dlg.h"
00041 #include "loaders.h"
00042 #include "gamemap.h"
00043 #include "turncontrol.h"
00044 #include "dialogs/fileselector.h"
00045 #include "dialogs/admingame.h"
00046 
00047 
00048 void networksupervisor ()
00049 {
00050    ASCString filename = selectFile( ASCString("*") + tournamentextension + ";*.asc", true );
00051    if ( filename.empty() )
00052       return;
00053 
00054    StatusMessageWindowHolder smw = MessagingHub::Instance().infoMessageWindow( "loading " + filename );
00055    FileTransfer ft;
00056    auto_ptr<GameMap> newMap ( mapLoadingExceptionChecker( filename, MapLoadingFunction( &ft, &FileTransfer::loadPBEMFile )));
00057    if ( !newMap.get() )
00058       return;
00059 
00060    Password pwd;
00061 
00062    for ( int i = 0; i < newMap->getPlayerCount(); ++i )
00063       if ( newMap->getPlayer(i).stat == Player::supervisor ) {
00064          pwd = newMap->getPlayer(i).passwordcrc;
00065          break;
00066       }
00067 
00068    if ( pwd.empty() )
00069       pwd = newMap->supervisorpasswordcrc;
00070 
00071    if ( pwd.empty() ) {
00072       errorMessage ("no supervisor setup in this game!" );
00073       return;
00074    }
00075 
00076    smw.close();
00077   
00078 
00079    try {
00080       bool ok = enterpassword ( pwd );
00081       if ( !ok ) {
00082          errorMessage ("invalid password!" );
00083          return;
00084       }
00085    }
00086    catch ( ... ) {
00087       return;
00088    }
00089 
00090    TurnSkipper ts ( &skipTurn );
00091    
00092    if ( adminGame( newMap.get(), &ts  ) ) {
00093       if ( !newMap->network ) {
00094          errorMessage("no network set up for game");
00095          return;
00096       }
00097       newMap->network->send( newMap.get(), -1, -1 );
00098    }
00099 
00100 }
00101 
00102 

Generated on Mon May 21 01:26:35 2012 for Advanced Strategic Command by  doxygen 1.5.1