#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <direct.h>
#include <windows.h>
#include <string>
//Default values if user does not specify the variable
#define G_UNLAGGED 1
#define G_GRAVITY 800
#define TIMELIMIT 60
#define G_KNOCKBACK 1000
#define G_HUMANBUILDPOINTS 200
#define G_ALIENBUILDPOINTS 200
#define G_FRIENDLYFIRE 1
#define SV_MAXPING 500
#define SV_MINPING 0
#define G_MOTD "Welcome to the server...Have fun!"
#define SV_HOSTNAME "My Server"
#define G_FRIENDLYBUILDABLEFIRE 1
#define G_ALIENMAXSTAGE 2
#define G_HUMANMAXSTAGE 2
#define RCONPASSWORD "password"
#define SV_PURE 1
#define G_ALLOWVOTE 1
#define G_INITIALMAPROTATION "rotation1"
#define G_ADMINNAMEPROTECT 1
#define G_PRIVATEMESSAGES 1
#define FIRSTMAP "atcs"
//End of default values
using namespace std;
int main()
{
verystart:
//Making the file properties
ofstream cfg;
//end of making the file properties
//Define our variables
int g_unlagged = G_UNLAGGED;
int g_gravity = G_GRAVITY;
int timelimit = TIMELIMIT;
int g_knockback = G_KNOCKBACK;
int g_humanbuildpoints = G_HUMANBUILDPOINTS;
int g_alienbuildpoints = G_ALIENBUILDPOINTS;
int g_friendlyfire = G_FRIENDLYFIRE;
int sv_maxping = SV_MAXPING;
int sv_minping = SV_MINPING;
string g_motd = G_MOTD;
string sv_hostname = SV_HOSTNAME;
int g_friendlybuildablefire = G_FRIENDLYBUILDABLEFIRE;
int g_alienmaxstage = G_ALIENMAXSTAGE;
int g_humanmaxstage = G_HUMANMAXSTAGE;
string rconpassword = RCONPASSWORD;
int sv_pure = SV_PURE;
int g_allowvote = G_ALLOWVOTE;
string g_initialmaprotation = G_INITIALMAPROTATION;
int g_adminnameprotect = G_ADMINNAMEPROTECT;
int g_privatemessages = G_PRIVATEMESSAGES;
string firstmap = FIRSTMAP;
//End of our variables
//Additional in-program variables
int selection;
int intselect;
string stringselect;
//end of additional in-program variables
system("color fc");
//start
start:
//start
cout <<"Server Config generator 1.0. Copyright The {NaNo} Development Team\n";
cout <<"Press enter to continue...\n";
cin.get();
menu:
system("cls");
//menu
//menu
//This is the main menu
cout <<"ServerCFG->Menu\n\n";
cout <<"1: Create server.cfg\n";
cout <<"2: Edit Cvar's\n";
cout <<"3: Remove server.cfg\n";
cout <<"4: Reset all cvar's to default\n";
cout <<"5: Exit\n";
cin >> selection;
//start of the 'big' loop
if (selection == 1) {
cout <<"Creating server.cfg in current directory... Please wait\n";
cfg.open("server.cfg", ios::trunc);
cfg << "//Generated server.cfg. Copyright The {NaNo}Development Team\n";
cfg << "set g_gravity " << g_gravity << "\n";
cfg << "set g_knockback " << g_knockback << "\n";
cfg << "set timelimit " << timelimit << "\n";
cfg << "set g_unlagged " << g_unlagged << "\n";
cfg << "set g_humanbuildpoints " << g_humanbuildpoints << "\n";
cfg << "set g_alienbuildpoints " << g_alienbuildpoints << "\n";
cfg << "set g_friendlyfire " << g_friendlyfire << "\n";
cfg << "set sv_maxping " << sv_maxping << "\n";
cfg << "set sv_minping " << sv_minping << "\n";
cfg << "set g_motd '" << g_motd <<"'\n";
cfg << "set sv_hostname '" << sv_hostname <<"'\n";
cfg << "set g_friendlybuildablefire " << g_friendlybuildablefire <<"\n";
cfg << "set g_alienmaxstage " << g_alienmaxstage << "\n";
cfg << "set g_humanmaxstage " << g_humanmaxstage << "\n";
cfg << "set rconpassword '" << rconpassword << "'\n";
cfg << "set sv_pure " << sv_pure << "'\n";
cfg << "set g_allowvote " << g_allowvote << "\n";
cfg << "set g_initialmaprotation '" << g_initialmaprotation <<"'\n";
cfg << "set g_adminnameprotect " << g_adminnameprotect <<"\n";
cfg << "set g_privatemessages " << g_privatemessages << "\n";
cfg << "map " << firstmap <<"\n";
cfg.close();
MessageBox(NULL,"Added server.cfg to the current directory","ServerCFG",MB_OK | MB_ICONINFORMATION);
cout <<"\nComplete\n";
cin.get();
goto menu;
}
//End of writing file
//start of a lot of rotations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (selection == 2) {
editmenu:
system("cls");
cout << "ServerCFG->Menu->Edit\n";
cout << "WARNING: ONLY EDIT THE VALUES THAT YOU WANT TO CHANGE. UNCHANGED VALUES WILL BE SET TO DEFAULT\n";
cout << " 1: Change Server name\n";
cout << " 2: Change wether or not there should be a 'lag' filter\n";
cout << " 3: Change the gravity level\n";
cout << " 4: Change timelimit\n";
cout << " 5: Change knockback\n";
cout << " 6: Change How many build points humans have\n";
cout << " 7: Change how many build points aliens have\n";
cout << " 8: Change wether or not team-mates are effected by them attacking each-other\n";
cout << " 9: Change the maximum latency (ping) between the client and the server\n";
cout << "10: Change the minimum latency (ping) between the client and the server\n";
cout << "11: Change the screen with text when a client is entering the server\n";
cout << "12: Change wether or not building are effected by the same team when shot\n";
cout << "13: Change The maximum stage that Aliens can achieve\n";
cout << "14: Change the maximum stage that Huamns can achieve\n";
cout << "15: Change the remote control (rcon) password\n";
cout << "16: Change wether or not client's can connect with a modified executable\n";
cout << "17: Change wether or not connected clients can call votes\n";
cout << "18: Change the name of the map rotation\n";
cout << "19: Change wether or not Administrator's names are protected\n";
cout << "20: Change wether or not connected client's can send private messages\n";
cout << "21: Change the first map when the server start's\n";
cout << "22: Exit to Main menu\n";
cin >> selection;
//inner selection
if (selection == 1) {
cout <<"Please enter the new server name (without quotations): ";
cin.get();
getline(cin,stringselect);
sv_hostname = stringselect;
goto editmenu;
}
if (selection == 2) {
cout << "Should we apply a 'lag' filter? (1 = Yes, 0 = No): ";
cin >> intselect;
g_unlagged = intselect;
goto editmenu;
}
if (selection == 3) {
cout << "What should be the gravity number?: ";
cin >> intselect;
g_gravity = intselect;
goto editmenu;
}
if (selection == 4) {
cout << "What should be the timelimit?: ";
cin >> intselect;
timelimit = intselect;
goto editmenu;
}
if (selection == 5) {
cout << "What should be the knockback?: ";
cin >> intselect;
g_knockback = intselect;
goto editmenu;
}
if (selection == 6) {
cout << "How many build points should Humans have?: ";
cin >> intselect;
g_humanbuildpoints = intselect;
goto editmenu;
}
if (selection == 7) {
cout << "How many build points should Aliens have?: ";
cin >> intselect;
g_alienbuildpoints = intselect;
goto editmenu;
}
if (selection == 8) {
cout << "Should friendly fire be on or of? (1 = On, 0 = Off): ";
cin >> intselect;
g_friendlyfire = intselect;
goto editmenu;
}
if (selection == 9) {
cout << "What should be the maximum ping from the client?: ";
cin >> intselect;
sv_maxping = intselect;
goto editmenu;
}
if (selection == 10) {
cout << "What should be the minimum ping from the client?: ";
cin >> intselect;
sv_minping = intselect;
}
//FIXED
if (selection == 11) {
cout << "What should be the text when a client enter's a server?: ";
cin.get();
std::getline (std::cin,stringselect);
g_motd = stringselect;
goto editmenu;
}
//End of 'To fix'
if (selection == 12) {
cout << "Will whooting at your own building effect them? (1 = Yes, 0 = No): ";
cin >> intselect;
g_friendlybuildablefire = intselect;
goto editmenu;
}
if (selection == 13) {
cout << "What should be the Human's maximum stage?: ";
cin >> intselect;
g_humanmaxstage = intselect;
goto editmenu;
}
if (selection == 14) {
cout << "What should be the Alien's maximum stage?: ";
cin >> intselect;
g_alienmaxstage = intselect;
goto editmenu;
}
if (selection == 15) {
cout << "What should be the new remote control (rcon) password?: ";
cin.get();
getline(cin,stringselect);
rconpassword = stringselect;
goto editmenu;
}
if (selection == 16) {
cout << "Should clients be able to connect with a modified executable? (1 = Yes, 0 = No): ";
cin >> intselect;
sv_pure = intselect;
goto editmenu;
}
if (selection == 17) {
cout << "Should connected client's be able to call a vote? (1 = Yes, 0 = No): ";
cin >> intselect;
g_allowvote = intselect;
goto editmenu;
}
if (selection == 18) {
cout << "What should be the new name of the map rotation?: ";
cin.get();
getline (cin,stringselect);
g_initialmaprotation = stringselect;
goto editmenu;
}
if (selection == 19) {
cout << "Should administrator's names be protected from other's using them? (1 = Yes, 0 = No): ";
cin >> intselect;
g_adminnameprotect = intselect;
goto editmenu;
}
if (selection == 20) {
cout << "Should connected client's send private messages? (1 = Yes, 0 = No): ";
cin >> intselect;
g_privatemessages = intselect;
goto editmenu;
}
if (selection == 21) {
cout << "What should be the first map when the server starts?: ";
cin.get();
getline (cin,stringselect);
firstmap = stringselect;
}
if (selection == 22) {
goto menu;
}
//if they dont enter anything....
else {
goto editmenu;
}
}
//Done of a lot of rotation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if (selection == 3) {
int result = (MessageBox(NULL,"Are you sure?","ServerCFG",MB_YESNO | MB_ICONWARNING));
if (result == IDYES) {
remove("server.cfg");
MessageBox(NULL,"Removed server.cfg","ServerCFG",MB_OK | MB_ICONINFORMATION);
goto menu;
}
if (result == IDNO) {
MessageBox(NULL,"Aborted","ServerCFG", MB_ICONSTOP | MB_OK);
goto menu;
}
}
//End of selection2 and editing cvar's
//the else statment
if (selection == 4) {
int answer = MessageBox(NULL,"Are you sure?","ServerCFG",MB_YESNO | MB_ICONWARNING);
if (answer == IDYES) {
goto verystart;
}
else {
goto start;
}
}
if (selection == 5) {
goto end;
}
else {
cout <<"Invalid selection\n";
cin.get();
goto menu;
}
//end of the 'big' loop
end:;
MessageBox(NULL,"Thanks for using ServerCFG\n Visit us at:\n xnano.freeforums.org","ServerCFG",MB_OK | MB_ICONINFORMATION);
}
There is the source if anyone needs it. However i am working on a linux version at the moment.