-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjkplus_launcher.cpp
More file actions
318 lines (292 loc) · 10.2 KB
/
jkplus_launcher.cpp
File metadata and controls
318 lines (292 loc) · 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*
===================== Jedi Knight Plus Launcher =====================
By Tr!Force. Work copyrighted (C) with holder attribution 2005 - 2019
=====================================================================
[Description]: Main application functionality to launch the server
=====================================================================
*/
// System headers
#include <windows.h>
#include <direct.h>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
// Main header
#include "jkplus_launcher.h"
// Welcome message
#define MOD_WELCOME R"!(
__________________________________________________________________________
| _______________________________________________________________________ |
|| [Jedi Knight Plus Launcher] ||
|| _ _ __ _ _ ||
|| | || |/ / _ | | | | ||
|| | || ' /_| |_ | | __ _ _ _ _ __ ___| |__ ___ _ __ ||
|| _ | || <|_ _| | | / _` | | | | '_ \ / __| '_ \ / _ \| '__| ||
|| | |__| || . \ |_| | |____| (_| | |_| | | | | (__| | | | __/| | ||
|| \____/ |_|\_\ |______|\__,_|\__,_|_| |_|\___|_| |_|\___||_| ||
|| ||
|| - Simple tool to launch Jedi Knight Plus Mod dedicated server ||
|| - Developed by Tr!Force ||
|| - https://github.com/TriForceX/JediKnightPlus ||
||_______________________________________________________________________||
|_________________________________________________________________________|
)!"
// Default settings
#define MOD_DEFAULT R"!(
// Server Binary
jk2mvded.exe
// Server Port
set net_port 28070
// Server Dedicated
set dedicated 2
// Server Version
set mv_serverversion 1.04
// Server Mod
set fs_game JediKnightPlus
// Server Config
exec jkplus_server.cfg
)!"
// Using declarations
using namespace std;
// Check file existence
inline bool fileExist(const std::string& name){
ifstream infile(name);
return infile.good();
}
// Check file empty
inline bool fileEmpty(const std::string& name){
ifstream infile(name);
return infile.peek() == std::ifstream::traits_type::eof();
}
// Get working directory
string getCurrentPath(void){
char buff[FILENAME_MAX];
_getcwd(buff, FILENAME_MAX);
std::string current_working_dir(buff);
return current_working_dir;
}
// Create default file
void generateDefault(void){
ofstream defaultFile;
string defaultText = 1 + MOD_DEFAULT;
defaultFile.open("jkplus_launcher.cfg");
defaultFile << defaultText.substr(0, defaultText.size() - 1);
defaultFile.close();
return;
}
// Main function
int main(){
while (true){
// Set console title
SetConsoleTitle(TEXT(VER_PRODUCTNAME_STR));
// Set console size
const int consoleWidth = 645;
const int consoleHeight = 570;
SetWindowPos(GetConsoleWindow(), NULL, GetSystemMetrics(SM_CXSCREEN) / 2 - consoleWidth / 2, GetSystemMetrics(SM_CYSCREEN) / 2 - consoleHeight / 2, consoleWidth, consoleHeight, SWP_SHOWWINDOW);
// Set mod path
string modPath = getCurrentPath();
// Delete auto generated config
if (fileExist("jk2mpserver.cfg")){
system("del jk2mpserver.cfg");
continue;
}
if (fileExist("jk2mvserver.cfg")){
system("del jk2mvserver.cfg");
continue;
}
// Check settings file
if (!fileExist("jkplus_launcher.cfg")){
system("cls");
printf("\n-------------------------------- [ Error ] --------------------------------\n\n");
printf("Can't find 'jkplus_launcher.cfg'. Starting to create a new one...\n");
printf("\n---------------------------------------------------------------------------\n\n");
system("pause");
generateDefault();
//Restart
system("cls");
continue;
}
// Check empty file
if (fileEmpty("jkplus_launcher.cfg")){
system("cls");
printf("\n-------------------------------- [ Error ] --------------------------------\n\n");
printf("File 'jkplus_launcher.cfg' is empty. Giving default values...\n");
printf("\n---------------------------------------------------------------------------\n\n");
system("pause");
generateDefault();
//Restart
system("cls");
continue;
}
// Show welcome message
printf("%s", 1 + MOD_WELCOME);
printf("\n-------------------------- [ Current Settings ] ---------------------------\n\n");
// Get and parse settings
ifstream getSettingFile("jkplus_launcher.cfg");
string getSettingLine;
string getSettingTitle;
string launchBin;
string launchCvars;
string launchServerCFG;
while (getline(getSettingFile, getSettingLine))
{
char *getFirst;
char *getLast = strtok_s(_strdup(getSettingLine.c_str()), " ", &getFirst);
vector<string> getCvars;
// Parse
while (getLast)
{
getCvars.push_back(getLast);
getLast = strtok_s(NULL, " ", &getFirst);
}
if (strstr(getSettingLine.c_str(), "//")){
// Set Title
getSettingTitle = getSettingLine.c_str();
}
else{
// Check title
if (getSettingTitle == ""){
getSettingTitle = "// " + getCvars[1];
}
// Set Cvars
if (strstr(getSettingLine.c_str(), ".exe")){
launchBin = getCvars[0].c_str();
printf("%-35s: %s\n", getSettingTitle.c_str(), getCvars[0].c_str());
}
else if (strstr(getSettingLine.c_str(), ".cfg")){
launchServerCFG = getCvars[1].c_str();
launchCvars = launchCvars + "+" + getCvars[0].c_str() + " " + getCvars[1].c_str() + " ";
printf("%-35s: %s\n", getSettingTitle.c_str(), getCvars[1].c_str());
}
else{
launchCvars = launchCvars + "+" + getCvars[0].c_str() + " " + getCvars[1].c_str() + " " + getCvars[2].c_str() + " ";
if (getCvars[1] == "dedicated"){
string type = getCvars[2] == "2" ? "(Internet)" : "(LAN)";
printf("%-35s: %s\n", getSettingTitle.c_str(), (getCvars[2] + " " + type).c_str());
}
else{
printf("%-35s: %s\n", getSettingTitle.c_str(), getCvars[2].c_str());
}
}
getSettingTitle = "";
}
}
// User input
string userOption;
string userOptionText[][2] = {
{ "[1] Start the server", "[4] Open mod folder" },
{ "[2] Modify launch settings", "[5] Open config generator" },
{ "[3] Open server config file", "[6] Visit JKPlus Website" },
};
int userOptionRows = (sizeof(userOptionText) / sizeof(*userOptionText));
int userOptionCols = (sizeof(userOptionText) / sizeof(userOptionText[0][0]));
printf("\n-------------------------- [ Choose an option ] ---------------------------\n\n");
for (int i = 0; i < userOptionRows; i++){
printf("%-34s %s\n", userOptionText[i][0].c_str(), userOptionText[i][1].c_str());
}
printf("\nType the number of your option: ");
getline(cin, userOption);
int userOptionNum = userOption.empty() ? 0 : stoi(userOption);
// User options
switch (userOptionNum){
case 1:
// Go to parent folder
SetCurrentDirectory(TEXT(".."));
// Check server binary
if (!fileExist(launchBin)){
system("cls");
printf("\n-------------------------------- [ Error ] --------------------------------\n\n");
printf("Can't find '%s'. Place it in 'GameData' folder and try again.\n", launchBin.c_str());
printf("\n---------------------------------------------------------------------------\n\n");
// Back to mod path
TCHAR *modPathBack = new TCHAR[modPath.size() + 1];
modPathBack[modPath.size()] = 0;
copy(modPath.begin(), modPath.end(), modPathBack);
SetCurrentDirectory(modPathBack);
system("pause");
// Restart
system("cls");
continue;
}
else{
// Launch server binary
system(("start " + launchBin + " " + launchCvars).c_str());
return EXIT_SUCCESS;
}
break;
case 2:
system("cls");
printf("\n--------------------------- [ Modify Settings ] ---------------------------\n\n");
printf("Opening settings file... Edit it and launch the server again.\n");
printf("\n---------------------------------------------------------------------------\n\n");
system("jkplus_launcher.cfg");
system("pause");
//Restart
system("cls");
continue;
break;
case 3:
system("cls");
printf("\n----------------------- [ Open Server Config File ] -----------------------\n\n");
printf("Opening server configuration file.. Now you can back to main menu.\n");
printf("\n---------------------------------------------------------------------------\n\n");
// Open mod directory
system((launchServerCFG).c_str());
system("pause");
// Restart
system("cls");
continue;
break;
case 4:
system("cls");
printf("\n--------------------------- [ Open Mod Folder ] ---------------------------\n\n");
printf("Opening mod folder... Now you can back to main menu.\n");
printf("\n---------------------------------------------------------------------------\n\n");
// Open mod directory
system(("explorer " + modPath).c_str());
system("pause");
// Restart
system("cls");
continue;
break;
case 5:
// Open mod directory
SetCurrentDirectory(TEXT("tools"));
system("jkplus_server.html");
if (!fileExist(launchBin)){
system("cls");
printf("\n------------------------ [ Open Server Generator ] ------------------------\n\n");
printf("Opening server generator... Now you can back to main menu.\n");
printf("\n---------------------------------------------------------------------------\n\n");
// Back to mod path
TCHAR *modPathBack = new TCHAR[modPath.size() + 1];
modPathBack[modPath.size()] = 0;
copy(modPath.begin(), modPath.end(), modPathBack);
SetCurrentDirectory(modPathBack);
system("pause");
// Restart
system("cls");
continue;
}
break;
case 6:
system("cls");
printf("\n------------------------- [ Open JKPlus Website ] -------------------------\n\n");
printf("Opening JKPlus website... Now you can back to main menu.\n");
printf("\n---------------------------------------------------------------------------\n\n");
// Open mod directory
system("start https://jkplus.github.io");
system("pause");
// Restart
system("cls");
continue;
break;
default:
// Restart
system("cls");
continue;
break;
}
}
}