Advanced Strategic Command
networksupervisor.cpp
Go to the documentation of this file.
1 
8 /*
9  This file is part of Advanced Strategic Command; http://www.asc-hq.de
10  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
11 
12  This program is free software; you can redistribute it and/or modify
13  it under the terms of the GNU General Public License as published by
14  the Free Software Foundation; either version 2 of the License, or
15  (at your option) any later version.
16 
17  This program is distributed in the hope that it will be useful,
18  but WITHOUT ANY WARRANTY; without even the implied warranty of
19  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20  GNU General Public License for more details.
21 
22  You should have received a copy of the GNU General Public License
23  along with this program; see the file COPYING. If not, write to the
24  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
25  Boston, MA 02111-1307 USA
26 */
27 
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <cstring>
31 
32 #include "global.h"
33 #include "misc.h"
34 #include "typen.h"
36 #include "dlg_box.h"
37 #include "dialog.h"
38 #include "sgstream.h"
39 #include "loadpcx.h"
40 #include "dialogs/pwd_dlg.h"
41 #include "loaders.h"
42 #include "gamemap.h"
43 #include "turncontrol.h"
44 #include "dialogs/fileselector.h"
45 #include "dialogs/admingame.h"
46 
47 
49 {
50  ASCString filename = selectFile( ASCString("*") + tournamentextension + ";*.asc", true );
51  if ( filename.empty() )
52  return;
53 
54  StatusMessageWindowHolder smw = MessagingHub::Instance().infoMessageWindow( "loading " + filename );
55  FileTransfer ft;
56  auto_ptr<GameMap> newMap ( mapLoadingExceptionChecker( filename, MapLoadingFunction( &ft, &FileTransfer::loadPBEMFile )));
57  if ( !newMap.get() )
58  return;
59 
60  Password pwd;
61 
62  for ( int i = 0; i < newMap->getPlayerCount(); ++i )
63  if ( newMap->getPlayer(i).stat == Player::supervisor ) {
64  pwd = newMap->getPlayer(i).passwordcrc;
65  break;
66  }
67 
68  if ( pwd.empty() )
69  pwd = newMap->supervisorpasswordcrc;
70 
71  if ( pwd.empty() ) {
72  errorMessage ("no supervisor setup in this game!" );
73  return;
74  }
75 
76  smw.close();
77 
78 
79  try {
80  bool ok = enterpassword ( pwd );
81  if ( !ok ) {
82  errorMessage ("invalid password!" );
83  return;
84  }
85  }
86  catch ( ... ) {
87  return;
88  }
89 
90  TurnSkipper ts ( &skipTurn );
91 
92  if ( adminGame( newMap.get(), &ts ) ) {
93  if ( !newMap->network ) {
94  errorMessage("no network set up for game");
95  return;
96  }
97  newMap->network->send( newMap.get(), -1, -1 );
98  }
99 
100 }
101 
102 
Interface for loading and writing of PCX images.
miscellaneous functions which are used by ASC and all its tools
Loki::Functor< void, LOKI_TYPELIST_1(GameMap *) > TurnSkipper
Definition: admingame.h:27
GameMap * loadPBEMFile(const ASCString &filename)
Loki::Functor< GameMap *, LOKI_TYPELIST_1(const ASCString &) > MapLoadingFunction
Definition: loaders.h:57
Global platform dependant definitions. This file just branches to the platform specific files in thei...
Interface for some basic classes from which all of ASC's dialogs are derived.
bool enterpassword(Password &pwd, bool firstTime, bool cancelAllowed, bool defaultAllowed, const ASCString &username)
Definition: pwd_dlg.cpp:158
if(!yyg->yy_init)
Definition: scanner.cpp:695
A class that hols a MessageWindow. This class ensures that the window is removed if the last copy of ...
Definition: messaginghub.h:34
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
void networksupervisor()
bool empty() const
Definition: password.cpp:89
GameMap * mapLoadingExceptionChecker(const ASCString &filename, MapLoadingFunction loader)
Definition: loaders.cpp:1539
bool adminGame(GameMap *actmap, TurnSkipper *turnSkipper)
Definition: admingame.cpp:387
Definition of THE central asc class: GameMap.
The IO for many basic classes and structurs of ACS.
void errorMessage(const ASCString &string)
ASCString selectFile(const ASCString &ext, bool load, bool overwriteMessage)
void skipTurn(GameMap *gamemap)
skips the next player. This is for administrative use, for example if a player does not react ...
Interface for all the dialog boxes used by the game and the mapeditor.
procedure for loading and writing savegames, maps etc.
const char * tournamentextension
Definition: loaders.cpp:80