Initial commit, includes Lua with broken Luabind as a backup for branching purposes
[terrastrategy.git] / src / server / main.cpp
blob38cc9c5696a78981432ea1cff7b769d1de553dec
1 //
2 // Copyright (C) 2007 by Martin Moracek
3 //
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 /**
20 * @file server/main.cpp
22 * This file contains the main() function for the terra client.
24 * main() simply initializes few core subsystems, parses command line and
25 * executes the application instance.
28 #include "../core/platform.h"
29 #include "../core/exception.h"
31 #include "../support/vfs.h"
33 #include "../framework/application.h"
35 void ParseArguments(int argc, char * argv[])
37 for(int i = 1; i < argc; ++i) {
38 if(argv[i][0] == '-') {
39 switch(argv[i][1]) {
40 case 'm': // mount directory
41 if(i >= argc - 2) {
42 vfs::vLog << "Error: Too few parameters for mounting.\n";
43 exit(EXIT_FAILURE);
45 if(!vfs::sInterface().HasRoot() && strcmp(argv[i + 2], "/") != 0) {
46 vfs::vLog << "Error: First mounted directory "
47 "must be root.\n";
48 exit(EXIT_FAILURE);
50 if(!vfs::sInterface().MountPath(argv[i + 1], argv[i + 2])) {
51 vfs::vLog << "Error: Unable to mount directory ";
52 // "'%s' as '%s',\n", argv[i + 1], argv[i + 2]);
53 exit(EXIT_FAILURE);
55 i += 2;
56 break;
57 default:
58 vfs::vLog << "Warning: Unknown command line ";
59 // "argument '%s'.\n", argv[i];
60 return;
66 int main(int argc, char * argv[])
68 try {
69 // turn off exhaustive logging
70 SET_LOG_ALWAYS(false);
72 // check program arguments
73 ParseArguments(argc,argv);
75 // mount default root if needed
76 if(!vfs::sInterface().HasRoot())
77 throw(Exception("Unable to initialize vfs"));
79 // create and run the game instance
80 framework::Application server;
82 server.Run();
84 } catch(std::exception & exc) {
85 vfs::vLog << "Error: Caught fatal exception: %s!\n";
86 // "Error: Program termination imminent!\n",exc.what());
87 return 1;
88 } catch(...) {
89 vfs::vLog << "Error: Caught unhandled exception!\n";
90 // "Error: Program termination imminent!\n");
91 return 1;
94 return 0;