1
// wizard to start an AssaultCube server and storing the configuration
15
#pragma warning( disable : 4996 )
18
#include "winserviceinstaller.h"
20
#include <sys/types.h>
24
int wizardmain(int argc, char **argv)
28
cout << "invalid arguments specified!" << endl << "usage: ac_server <outfile> <relbinarypath>" << endl;
32
string outfile(argv[1]);
33
string relpath(argv[2]);
35
map<string, string> args;
37
cout << "AssaultCube Server Wizard" << endl << endl;
38
cout << "You can now specify some optional server settings. The default settings will be used if you decide to leave the fields empty. See README.html for a description of the settings." << endl << endl;
40
cout << "server description:\t";
41
getline(cin, args["n"]);
43
cout << "max clients:\t\t";
44
getline(cin, args["c"]);
46
cout << "password:\t\t";
47
getline(cin, args["p"]);
49
cout << "admin password:\t\t";
50
getline(cin, args["x"]);
52
cout << "message of the day:\t";
53
getline(cin, args["o"]);
55
cout << "server port:\t\t";
56
getline(cin, args["f"]);
58
cout << "masterserver:\t\t";
59
getline(cin, args["m"]);
61
cout << "maprotation file:\t";
62
getline(cin, args["r"]);
64
cout << "score threshold:\t";
65
getline(cin, args["k"]);
68
cout << "demorecord buffer size:\t";
69
getline(cin, permdemo);
72
cout << "additional commandline parameters:\t";
77
string wsname, wsdisplayname;
78
cout << "win service name:\t";
83
cout << "win service display:\t";
84
getline(cin, wsdisplayname);
91
for(map<string, string>::iterator i = args.begin(); i != args.end(); i++)
93
if((*i).second.empty()) continue; // arg value not set
96
argstr += " -" + (*i).first;
97
if((*i).second.find(" ") == string::npos) argstr += (*i).second;
98
else argstr += '"' + (*i).second + '"'; // escape spaces
101
if(permdemo.empty() || atoi(permdemo.c_str())) argstr += " -D" + permdemo;
102
if(!cmds.empty()) argstr += " " + cmds;
104
cout << endl << "Writing your configuration to " << outfile << " ... ";
108
fstream startupScript(outfile.c_str(), ios::out);
110
startupScript << relpath << argstr << endl << "pause" << endl;
112
startupScript << "#! /bin/sh" << endl << relpath << argstr << endl;
114
startupScript.close();
118
cout << "Failed!" << endl;
122
cout << "Done" << endl << endl;
123
cout << "Note: You can start " << outfile << " directly the next time you want to use this configuration again." << endl << endl;
129
if(wsdisplayname.empty()) wsdisplayname = wsname;
131
cout << "Installing the AC Server as windows service ... ";
134
_getcwd(path, MAX_PATH);
135
strncat(path, ("\\" + relpath + " -S" + wsname + " " + argstr).c_str(), MAX_PATH);
137
winserviceinstaller installer(wsname.c_str(), wsdisplayname.c_str(), path);
140
if(!installer.OpenManger())
142
cout << "Failed!" << endl;
143
cout << "Could not open the Service Control Manager: " << GetLastError() << endl;
144
installer.CloseManager();
148
if((r = installer.IsInstalled()) != 0)
150
cout << "Failed!" << endl;
151
if(r == -1) cout << "Error accessing the Service Control Manager" << endl;
152
else if(r == 1) cout << "A windows service with this name (" << wsname << ")is already installed: " << GetLastError() << endl;
156
if((r = installer.Install()) != 1)
158
cout << "Failed!" << endl;
159
if(r == -1) cout << "Error accessing the Service Control Manager" << endl;
160
else if(r == 0) cout << "Could not create the new windows service: " << GetLastError() << endl;
164
cout << "Done" << endl << endl;
165
cout << "Note: You can now manage your AC server using services.msc and sc.exe" << endl << endl;
170
cout << "Press Enter to start the server now" << endl;
172
cout << "Starting the AC server ..." << endl;
173
system((relpath + argstr).c_str());