~ubuntu-branches/debian/stretch/assaultcube-data/stretch

« back to all changes in this revision

Viewing changes to source/src/wizard.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Gonéri Le Bouder, Ansgar Burchardt, Gonéri Le Bouder
  • Date: 2010-04-02 23:37:55 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20100402233755-kf74fxwlu634o6vg
Tags: 1.0.4+repack1-1
[ Ansgar Burchardt ]
* debian/control: fix typo in short description

[ Gonéri Le Bouder ]
* Upgrade to 1.0.4
* bump standards-version to 3.8.4
* Add Depends: ${misc:Depends} just to avoid a lintian warning
* Add a debian/source/format file for the same reason

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// wizard to start an AssaultCube server and storing the configuration
 
2
 
 
3
 
 
4
#include "pch.h"
 
5
 
 
6
#include <map>
 
7
#include <string>
 
8
#include <iostream>
 
9
#include <fstream>
 
10
 
 
11
using namespace std;
 
12
 
 
13
#ifdef WIN32
 
14
    #ifndef __GNUC__
 
15
        #pragma warning( disable : 4996 )
 
16
    #endif
 
17
    #include <direct.h>
 
18
    #include "winserviceinstaller.h"
 
19
#elif __GNUC__
 
20
    #include <sys/types.h>
 
21
    #include <sys/stat.h>
 
22
#endif
 
23
 
 
24
int wizardmain(int argc, char **argv)
 
25
{
 
26
    if(argc < 3)
 
27
    {
 
28
        cout << "invalid arguments specified!" << endl << "usage: ac_server <outfile> <relbinarypath>" << endl;
 
29
        return EXIT_FAILURE;
 
30
    }
 
31
 
 
32
    string outfile(argv[1]);
 
33
    string relpath(argv[2]);
 
34
 
 
35
        map<string, string> args;
 
36
 
 
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;
 
39
 
 
40
        cout << "server description:\t";
 
41
        getline(cin, args["n"]);
 
42
 
 
43
        cout << "max clients:\t\t";
 
44
        getline(cin, args["c"]);
 
45
 
 
46
        cout << "password:\t\t";
 
47
        getline(cin, args["p"]);
 
48
 
 
49
        cout << "admin password:\t\t";
 
50
        getline(cin, args["x"]);
 
51
 
 
52
        cout << "message of the day:\t";
 
53
        getline(cin, args["o"]);
 
54
 
 
55
        cout << "server port:\t\t";
 
56
        getline(cin, args["f"]);
 
57
 
 
58
        cout << "masterserver:\t\t";
 
59
        getline(cin, args["m"]);
 
60
 
 
61
        cout << "maprotation file:\t";
 
62
        getline(cin, args["r"]);
 
63
 
 
64
        cout << "score threshold:\t";
 
65
        getline(cin, args["k"]);
 
66
 
 
67
    string permdemo;
 
68
        cout << "demorecord buffer size:\t";
 
69
        getline(cin, permdemo);
 
70
 
 
71
    string cmds;
 
72
        cout << "additional commandline parameters:\t";
 
73
        getline(cin, cmds);
 
74
 
 
75
#ifdef WIN32
 
76
 
 
77
    string wsname, wsdisplayname;
 
78
        cout << "win service name:\t";
 
79
        getline(cin, wsname);
 
80
 
 
81
    if(!wsname.empty())
 
82
    {
 
83
        cout << "win service display:\t";
 
84
        getline(cin, wsdisplayname);
 
85
    }
 
86
 
 
87
#endif
 
88
 
 
89
    string argstr;
 
90
 
 
91
        for(map<string, string>::iterator i = args.begin(); i != args.end(); i++)
 
92
        {
 
93
                if((*i).second.empty()) continue; // arg value not set
 
94
                else
 
95
                {
 
96
                        argstr += " -" + (*i).first;
 
97
                        if((*i).second.find(" ") == string::npos) argstr += (*i).second;
 
98
                        else argstr += '"' + (*i).second + '"'; // escape spaces
 
99
                }
 
100
        }
 
101
    if(permdemo.empty() || atoi(permdemo.c_str())) argstr += " -D" + permdemo;
 
102
    if(!cmds.empty()) argstr += " " + cmds;
 
103
 
 
104
        cout << endl << "Writing your configuration to " << outfile << " ... ";
 
105
 
 
106
        try
 
107
        {
 
108
        fstream startupScript(outfile.c_str(), ios::out);
 
109
#ifdef WIN32
 
110
        startupScript << relpath << argstr << endl << "pause" << endl;
 
111
#elif __GNUC__
 
112
            startupScript << "#! /bin/sh" << endl << relpath << argstr << endl;
 
113
#endif
 
114
                startupScript.close();
 
115
        }
 
116
        catch(...)
 
117
        {
 
118
                cout << "Failed!" << endl;
 
119
                return EXIT_FAILURE;
 
120
        }
 
121
 
 
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;
 
124
 
 
125
#ifdef WIN32
 
126
 
 
127
    if(!wsname.empty())
 
128
    {
 
129
        if(wsdisplayname.empty()) wsdisplayname = wsname;
 
130
 
 
131
        cout << "Installing the AC Server as windows service ... ";
 
132
 
 
133
        char path[MAX_PATH];
 
134
            _getcwd(path, MAX_PATH);
 
135
        strncat(path, ("\\" + relpath + " -S" + wsname + " " + argstr).c_str(), MAX_PATH);
 
136
 
 
137
        winserviceinstaller installer(wsname.c_str(), wsdisplayname.c_str(), path);
 
138
 
 
139
        int r;
 
140
        if(!installer.OpenManger())
 
141
        {
 
142
            cout << "Failed!" << endl;
 
143
            cout << "Could not open the Service Control Manager: " << GetLastError() << endl;
 
144
            installer.CloseManager();
 
145
            return EXIT_FAILURE;
 
146
        }
 
147
 
 
148
        if((r = installer.IsInstalled()) != 0)
 
149
        {
 
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;
 
153
            return EXIT_FAILURE;
 
154
        }
 
155
 
 
156
        if((r = installer.Install()) != 1)
 
157
        {
 
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;
 
161
            return EXIT_FAILURE;
 
162
        }
 
163
 
 
164
        cout << "Done" << endl << endl;
 
165
        cout << "Note: You can now manage your AC server using services.msc and sc.exe" << endl << endl;
 
166
    }
 
167
 
 
168
#endif
 
169
 
 
170
        cout << "Press Enter to start the server now" << endl;
 
171
        cin.get();
 
172
        cout << "Starting the AC server ..." << endl;
 
173
        system((relpath + argstr).c_str());
 
174
 
 
175
        return EXIT_SUCCESS;
 
176
}