Skip to content

Instantly share code, notes, and snippets.

@ynshung
Created August 4, 2021 09:35
Show Gist options
  • Save ynshung/54b83015b2275b34c4b1d64ea78a6a76 to your computer and use it in GitHub Desktop.
Save ynshung/54b83015b2275b34c4b1d64ea78a6a76 to your computer and use it in GitHub Desktop.
// Version 2.x.x.x
// Written by Ng Young Shung
// Do not copy!
/* Used Audio:
* click.wav
* gotitem.wav
* partyhorn.wav
* drum.wav
* aww.wav
// Total 735 KB
*/
#include <iostream>
#include <sstream>
#include <cmath>
#include <fstream>
#include <windows.h>
#include <conio.h>
#include <stdlib.h> // Returning error()
#include <unistd.h>
#include <irrKlang.h>
#include "version.h"
WORD GetConsoleTextAttribute (HANDLE hCon) {
CONSOLE_SCREEN_BUFFER_INFO con_info;
GetConsoleScreenBufferInfo(hCon, &con_info);
return con_info.wAttributes;
}
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
const int saved_colors = GetConsoleTextAttribute(hConsole);
using namespace std;
irrklang::ISoundEngine* engine = irrklang::createIrrKlangDevice();
void cr(int x) {
if (x == 0) SetConsoleTextAttribute(hConsole, FOREGROUND_GREEN);
else SetConsoleTextAttribute(hConsole, saved_colors);
}
double upSpeed;
double downSpeed;
double RamMB;
bool priv;
int bit;
int plugins;
int pcbit;
// ADV
int spawn;
int diff;
int worldT;
double customMB;
bool hardcore;
bool nether;
double idle;
int lagg;
int viewD;
bool isHDD;
bool ramDisks;
char pcT; int winServer;
void again(); void ask(); void sr(); void process();
bool adv = false; char user; bool pc = true;
string topMessage = "";
string reasonMessage;
string afterMessage = "You're probably better off renting a server instead\nto have a decent experience.";
string maxPR = "";
ofstream stats("CIHAMS.txt");
string tempS = "-1";
double temp1 = -1;
int maxPlayers = 0;
int osAsk() {
user = _getch();
return user;
}
void ask() {
stats << "Your selection: ";
cout << "What is your minecraft version? (PC = 1 PE = 2) ";
cr(0);
do {
user = osAsk();
if (user == '1') pc = true;
else if (user == '2') pc = false;
else continue;
_putch( user );
stats << pc << ".";
engine->play2D("audio/click.wav");
break;
} while (1);
cr(1);
/*
Win NT/2K/XP = 0
Win Vista/7/8 = 1
Win 2003 = 3
Win 2008 = 4
Unix GUI = 5
Unix Console = 6
*/
if (pc) {
cout << "\n\nWhat is your operating system?\n(If there is no similar OS pls select the closest one)\n"
<< "1. Windows older than Vista 2. Windows Vista - W8 3. Windows newer than 8\n4. Windows Server 5. Unix ";
// 1. Older Win 2. Newer Win 3. More new 3. Win Server (leads) 4. Unix
cr(0);
do {
user = _getch();
if (user == '1' || user == '2' || user == '3' || user == '4' || user == '5') {
pcT = user;
_putch( user );
} else continue;
break;
} while (1);
stats << pcT << ".";
cr(1);
engine->play2D("audio/click.wav");
if (pcT == '4') {
cout << "\nChoose one of the server year. 1. 2003 2. 2008 3. 2012 4. 2016: ";
cr(0);
do {
user = _getch();
if (user == '1' || user == '2' || user == '3' || user == '4') {
winServer = user;
_putch( user );
} else continue;
break;
} while (1);
cr(1);
stats << winServer << ".";
engine->play2D("audio/click.wav");
}
}
cout << "\n\nHow fast is your upload speed? (MBits/s) ";
temp1 = -1;
cr(0);
while (temp1 < 0 || temp1 > 2000000000) {
cin >> tempS;
temp1 = atoi(tempS.c_str());
}
upSpeed = temp1;
cr(1);
stats << upSpeed << ".";
engine->play2D("audio/click.wav");
/***/
cout << "How fast is your download speed? (MBits/s) ";
temp1 = -1;
tempS = "-1";
cr(0);
while (temp1 < 0 || temp1 > 2000000000) {
cin >> tempS;
temp1 = atoi(tempS.c_str());
}
downSpeed = temp1;
stats << downSpeed << ".";
cr(1);
engine->play2D("audio/click.wav");
/***/
cout << "How many RAM is allocated for the server? (MB) ";
temp1 = -1;
tempS = "-1";
cr(0);
while (temp1 < 0 || temp1 > 2000000000) {
cin >> tempS;
temp1 = atoi(tempS.c_str());
}
RamMB = temp1;
stats << RamMB << ".";
cr(1);
engine->play2D("audio/click.wav");
/***/
cout << "Is the server running in how many bit?\n(x86/32-bit = 1, x64/64-bit = 2, None = 0) ";
cr(0);
do {
user = _getch();
if (user == '1' || user == '2' || user == '0') {
pcbit = user;
_putch( user );
} else continue;
break;
} while (1);
stats << pcbit << ".";
cr(1);
engine->play2D("audio/click.wav");
/***/
cout << "\nIs it a private (white-listed/etc.) server? (Y/N) ";
cr(0);
do {
user = _getch();
if (user == 'Y' || user == 'y') priv = true;
else if (user == 'N' || user == 'n') priv = false;
else continue;
_putch( user );
break;
} while (1);
stats << priv << ".";
cr(1);
engine->play2D("audio/click.wav");
/***/
cout << "\nHow many plugins/mods does your server contain? (0 if none) ";
cr(0);
temp1 = -1;
tempS = "-1";
while (temp1 < 0 || temp1 > 2000000000) {
cin >> tempS;
temp1 = atoi(tempS.c_str());
}
plugins = temp1;
cr(1);
stats << plugins << ".";
engine->play2D("audio/click.wav");
/***********/
char user;
cout << "\nDo you want to proceed for more advanced search?\n(Note: ` = Default) Press Enter to continue, any key to calculate. ";
user = _getch();
engine->play2D("audio/click.wav");
int z;
for(z = 0;z!=2;z++) {
if (z == 1) user = 'z';
if (user == '\r') {
stats << "adv.";
adv = true;
cout << "\n\nWhat is your world type?\n"
<< "1 = `Normal 2 = Superflat 3 = Amplified 4 = Large Biomes 5 = Custom Map: ";
cr(0);
do {
user = _getch();
if (user == '1' || user == '2' || user == '3' || user == '4' || user == '5') {
worldT = user - '0';
_putch( user );
} else continue;
break;
} while (1);
cr(1);
stats << worldT << ".";
engine->play2D("audio/click.wav");
if (user == '5') {
cout << "\nHow much MB is the custom map? (Whole folder) ";
cr(0);
temp1 = -1;
tempS = "-1";
while (temp1 < 0 || temp1 > 2000000000) {
cin >> tempS;
temp1 = atoi(tempS.c_str());
}
customMB = temp1;
stats << customMB << ".";
cr(1);
engine->play2D("audio/click.wav");
}
/***/
cout << "\nIs nether allowed? (`Y/N) ";
cr(0);
do {
user = _getch();
if (user == 'Y' || user == 'y') nether = true;
else if (user == 'N' || user == 'n') nether = false;
else continue;
_putch( user );
break;
} while (1);
stats << nether << ".";
cr(1);
engine->play2D("audio/click.wav");
/***/
cout << "\nWhat can spawn?\n(1 = Only Animal/NPCs (Peaceful/etc.) 2 = Only Monsters 3 = `Both 4 = No mobs) ";
cr(0);
do {
user = _getch();
if (user == '1' || user == '2' || user == '3' || user == '4' || user == '5') {
spawn = user - '0';
} else continue;
_putch( user );
break;
} while (1);
stats << spawn << ".";
cr(1);
engine->play2D("audio/click.wav");
if (user == '2' || user == '3') {
cout << "\nDifficulty? (1 = `Easy 2 = Normal 3 = Hard) ";
cr(0);
do {
user = _getch();
if (user == '1' || user == '2' || user == '3') {
diff = user - '0';
} else continue;
_putch( user );
break;
} while (1);
stats << diff << ".";
cr(1);
engine->play2D("audio/click.wav");
}
/***/
if (!priv) {
cout << "\nWhat is the idle timeout? (`0 if none) ";
cr(0);
temp1 = -1;
tempS = "-1";
while (temp1 < 0 || temp1 > 2000000000) {
cin >> tempS;
temp1 = atoi(tempS.c_str());
}
idle = temp1;
stats << idle << ".";
cr(1);
engine->play2D("audio/click.wav");
cout << "Is it in hardcore mode? (Y/`N) ";
cr(0);
do {
user = _getch();
if (user == 'Y' || user == 'y') hardcore = true;
else if (user == 'N' || user == 'n') hardcore = false;
else continue;
_putch( user );
break;
} while (1);
stats << hardcore << ".";
cr(1);
engine->play2D("audio/click.wav");
}
/***/
cout << "\nServer view distance? (3-15 `10) ";
cr(0);
temp1 = -1;
tempS = "-1";
while (temp1 < 0 || temp1 > 15) {
cin >> tempS;
temp1 = atoi(tempS.c_str());
}
viewD = temp1;
stats << viewD << ".";
cr(1);
engine->play2D("audio/click.wav");
/***/
cout << "\nFrom the scale of `1 to 10, is your server contains a lot of lag generator?\n(Explosions, Redstone, etc.) ";
temp1 = -1;
tempS = "-1";
cr(0);
while (temp1 < 1 || temp1 > 10) {
cin >> tempS;
temp1 = atoi(tempS.c_str());
}
lagg = temp1;
stats << lagg << ".";
cr(1);
engine->play2D("audio/click.wav");
} else if (user != '\r') {
cout << "\nProcessing...\n";
process();
}
/***/
cout << "\nWhat is your storage type? (`HDD = 1 / SSD = 2) ";
cr(0);
do {
user = _getch();
if (user == '1') isHDD = true;
else if (user == '2') isHDD = false;
else continue;
_putch( user );
break;
} while (1);
stats << isHDD << ".";
cr(1);
engine->play2D("audio/click.wav");
/***/
cout << "\nDo you use RAMDisks? (MB)\n(If yes, type the number you allocated. If not, type '0') ";
temp1 = -1;
tempS = "-1";
cr(0);
while (temp1 < 0 || temp1 > 2000000000) {
cin >> tempS;
temp1 = atoi(tempS.c_str());
}
ramDisks = temp1;
stats << ramDisks << ".";
cr(1);
engine->play2D("audio/click.wav");
/***/
}
}
/*****/
void getFMax(int* a, bool* b) {
double netSpeed = upSpeed < (downSpeed * 2) ? upSpeed : downSpeed;
double netPlayers = netSpeed / 0.33;
double RAMPlayers = (RamMB * 0.75) / 64;
*a = RAMPlayers < netPlayers ? RAMPlayers : netPlayers;
if (netPlayers < RAMPlayers) *b = true;
}
void process() {
stringstream reasonMessageS;
stringstream maxPRS;
/** Start remove/add max players **/
bool req = true;
int add = 0;
int sub = 0;
int maxPtemp;
bool isitTrue;
if (!priv) {RamMB -= 1024; upSpeed -= 2; downSpeed -= 1;}
if (ramDisks > 0) RamMB += (ramDisks * 2);
getFMax(&maxPtemp, &isitTrue);
if (pc) {
if (pcT == '1') {if (RamMB < 1024 || upSpeed < 2 || downSpeed < 2) req = false; else req = true;}
else if (pcT == '2') {if (RamMB < 2048 || upSpeed < 3 || downSpeed < 3) req = false; else req = true;}
else if (pcT == '3') {
if (winServer == 1) {if (RamMB < 512 || upSpeed < 2 || downSpeed < 2) req = false; else req = true;}
else if (winServer == 2) {if (RamMB < 1024 || upSpeed < 2 || downSpeed < 2) req = false; else req = true;}
else if (winServer == 3) {if (RamMB < 1536 || upSpeed < 3 || downSpeed < 2) req = false; else req = true;}
else if (winServer == 4) {if (RamMB < 2048 || upSpeed < 3 || downSpeed < 2) req = false; else req = true;}
}
else if (pcT == '4') {if (RamMB < 512 || upSpeed < 2 || downSpeed < 2) req = false; else req = true;}
} else {
if (RamMB < 512 || upSpeed < 2 || downSpeed < 2) req = false;
else add += 5;
}
if (pcbit == 1) add += (add / 5);
/********** adv ************/
if (adv && req) {
if (worldT == 2) add += 8;
else if (worldT == 3) sub -= 5;
else if (worldT == 4) sub -= 2;
else if (worldT == 5) sub -= (customMB / 8);
if (!nether) add += 4;
if (spawn == 1) add += 5;
if (spawn == 2) {
if (diff == 2) sub -= 2;
else if (diff == 3) sub -= 4;
}
if (spawn == 3) {
if (diff == 2) sub -= 3;
else if (diff == 3) sub -= 6;
}
if (spawn == 4) add += 6;
if (!priv) add += (idle / 5);
if (viewD > 10) sub -= (viewD - 10);
else if (viewD < 10) add += (10 - viewD);
if (lagg > 1) sub -= (lagg - 1);
if (hardcore) add += 5;
}
if (plugins > 0) sub -= (plugins / 3);
if (!isHDD) add += (maxPlayers / 4);
stats << "\nNormal: " << maxPtemp;
maxPtemp += add;
maxPtemp -= sub;
maxPlayers = maxPtemp;
stats << " Added: " << add << " Removed: " << sub << " Count: " << maxPtemp;
stats << "\nNOTE: Not all count was counted in here, there are some exceptions.";
if (upSpeed < 2) maxPlayers /= 2;
if (downSpeed < 2) maxPlayers /= 2;
if (RamMB <= 2048) maxPlayers /= 2;
if (maxPlayers < 0) maxPlayers = 0;
if (!req) maxPlayers = 0;
/***/
if (maxPlayers < 16) {
if (!req) reasonMessageS << "Your computer may not meet one of the the minimum system requirements.";
else if (plugins >= 20 && maxPlayers <= 8) reasonMessageS << "You may need to uninstall some of your plugins.";
else if (adv) reasonMessageS << "You may edit your server.properties or change the map for great performance.";
else if (isitTrue) reasonMessageS << "The problem is that the internet connection speed is too slow to send\nand recieve data the data for more than " << maxPlayers << " people at the same time.";
else reasonMessageS << "You don't have enough RAM in your system to cope with storing data\nfor more than " << maxPlayers << " people at the same time.";
if (maxPlayers > 10) afterMessage = "If you want to have more players, then you should probably consider renting a\n(bigger) server instead.";
} else {
reasonMessageS << "You've got a fast enough internet connection and enough RAM to cope with a\ndecent number of players.";
if (maxPlayers <= 32) afterMessage = "If you want to have more players, then you should probably consider renting a\n(bigger) server instead.";
else afterMessage = "Looks like you're all set up to play. Enjoy!";
}
if (maxPlayers < 2) topMessage = "No, sorry!";
else if (maxPlayers < 6) topMessage = "Not really.";
else if (maxPlayers < 10) topMessage = "Sorta, but you're pushing it!";
else if (maxPlayers < 16) topMessage = "Yes!";
else if (maxPlayers < 20) topMessage = "Nicely so";
else if (maxPlayers < 30) topMessage = "Easily";
else if (maxPlayers < 100) topMessage = "Your server will be smooth!";
else if (maxPlayers < 10000) topMessage = "Yes, a million times!";
else if (maxPlayers < 1000000) topMessage = "Your server will be in great performance!";
else if (maxPlayers < 25000000) topMessage = "Looks fake to me!";
else topMessage = "Congratulations! Looks like you reached the max! xDD";
int temp1 = floor(maxPlayers / 10) * 10;
if (temp1 >= 10) reasonMessageS << "\nWe recommended to host a maximum number of " << temp1 << " players.";
else reasonMessageS << "\nOr just play singleplayer...";
stats << "\n\nMax players = " << maxPlayers << ".";
stats << "\nRecommended players = " << temp1 << ".";
reasonMessage = reasonMessageS.str();
maxPR = maxPRS.str();
sr();
}
void sr() {
engine->play2D("audio/drum.wav"); sleep(5);
cout << "\n" << topMessage;
cout << "\nYou can probably host a maximum number of... ";
cout << maxPlayers << "\nplayers at the same time, plus yourself.\n";
if (maxPlayers > 32) engine->play2D("audio/partyhorn.wav");
else if (maxPlayers > 6) engine->play2D("audio/gotitem.wav");
else if (maxPlayers < 2) engine->play2D("audio/wrong.wav");
else engine->play2D("audio/aww.wav");
sleep(2);
cout << "\n" << reasonMessage;
cout << "\n\n" << afterMessage; sleep(1);
cout << maxPR << "\nLog printed in %TEMP%/nys/CIHAMS.txt\n";
cout << "\nPress Enter to continue and any key to end the program. ";
do {
user = _getch();
if (user == '\r') break;
else exit(0);
} while (1);
cout << string(100, '\n');
stats << "\n\n----------\n";
ask();
}
int main() {
cout << "\nNOTE: Idea and some script from canihostaminecraftserver.com was taken.\n";
cout << "Written by Young Shung!\n";
cout << "Release " << AutoVersion::FULLVERSION_STRING << "\n\n";
sleep(1);
ask();
engine->drop();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment