main.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761
  1. /*
  2. Space Construct v0.6-dev
  3. Beanzilla@21:4/110 on FsxNet
  4. Beanzilla@637:1/110 on HappyNet
  5. */
  6. #define VERSION_MAJOR 0
  7. #define VERSION_MINOR 6
  8. #ifndef VERSION_TYPE
  9. #define VERSION_TYPE "dev"
  10. #endif
  11. #define PATH_MAX 256
  12. #define PATH_SEP "/"
  13. #include <MagiDoor.h>
  14. #include <sqlite3.h>
  15. #if defined(_MSC_VER) || defined(WIN32)
  16. #define snprintf _snprintf
  17. #define strcasecmp _stricmp
  18. #include <winsock2.h>
  19. #ifndef _MSC_VER
  20. #define _MSC_VER 1
  21. #endif
  22. #else
  23. #include <arpa/inet.h>
  24. #endif
  25. // Standard C
  26. #include <time.h>
  27. #include <stdio.h>
  28. #include <string.h>
  29. #include <stdlib.h>
  30. #include <stdarg.h>
  31. #include <ctype.h>
  32. #include <sys/types.h>
  33. #include <sys/stat.h>
  34. #include <unistd.h> // stat
  35. char * log_path = "logs";
  36. int inuse = 0; // Are any other copies of us running? (We are a single user door!)
  37. int debug = 0; // Are we in debug mode?
  38. // Please change it for your system!
  39. int allowDev = 1; // Allow "Beanzilla" to not need the password.
  40. char * sysop_pass = "spaceISbig"; // Case sensitive!
  41. // User Structure (This includes guns, fuel, armor, shields, HP)
  42. typedef struct user_info {
  43. int uid; // Primary Key
  44. int experience; // Think about this as score
  45. // Was ship structure, now is part of user
  46. int guns; // Placed Guns, More means more damage (Deals from 1-2 damage per attack)
  47. int fuel; // How many "turns" do we have
  48. int metal; // Used to build more guns/armors/shields possibly fuel too (guns take 5, armor takes 3, shields take 7, maybe fuel takes 12)
  49. int armors; // Placed Armors (Each Armor takes 4 points of damage then breaks off)
  50. int shields; // Placed Shields (Each Shields takes 3 points of damage then is offline, regenerates 1 point per attack/turn must reach 50% of max to being protecting again)
  51. int hitpoints; // Total hitpoints till we die (Rules for taking damage, shields first then armor then hitpoints)
  52. int armorpoints; // Points we get from armors (Repairable but costs 1 metal per point, but can break if taking too much damage)
  53. int shieldpoints; // Points we get from shields (Self-Regenerates, and does not get destroyed)
  54. int shieldsup; // 0 means yes, anything else means shields are offline, deduct if not 0 for each attack.
  55. int laston; // 20200630 is 6-30-2020
  56. int dirty; // Need to save?
  57. char nick[256]; // What they go by on score board, this allows duping since we really go by real
  58. char real[256]; // Their real name to match with drop file info, prevents someone from loging in as another
  59. } user_inf;
  60. // DateStamp Structure to provide date difference
  61. typedef struct dateTamp {
  62. int year; // YYYY, or number of years difference
  63. int month; // MM, or number of months difference
  64. int day; // DD, or number of days difference.
  65. int age; // Taking down to aproximate day count.
  66. } dT; // YYYYMMDD it in int form
  67. void dolog(char *fmt, ...) {
  68. // Low end Logging
  69. char buffer[PATH_MAX];
  70. struct tm *time_now;
  71. time_t timen;
  72. FILE *logfptr;
  73. timen = time(NULL);
  74. time_now = localtime(&timen);
  75. if (log_path != NULL) {
  76. snprintf(buffer, PATH_MAX, "%s%s%04d%02d%02d.log", log_path, PATH_SEP,
  77. time_now->tm_year + 1900, time_now->tm_mon + 1, time_now->tm_mday);
  78. } else {
  79. snprintf(buffer, PATH_MAX, "%04d%02d%02d.log", time_now->tm_year + 1900,
  80. time_now->tm_mon + 1, time_now->tm_mday);
  81. }
  82. logfptr = fopen(buffer, "a");
  83. if (!logfptr) {
  84. return;
  85. }
  86. va_list ap;
  87. va_start(ap, fmt);
  88. vsnprintf(buffer, 512, fmt, ap);
  89. va_end(ap);
  90. fprintf(logfptr, "%02d:%02d:%02d %s\n", time_now->tm_hour, time_now->tm_min,
  91. time_now->tm_sec, buffer);
  92. fclose(logfptr);
  93. }
  94. int dateStamp() {
  95. // YYYYMMDD \o/ In a INT so we can store it and compare against it!
  96. struct tm *time_now;
  97. time_t timen;
  98. int result = 0;
  99. timen = time(NULL);
  100. time_now = localtime(&timen);
  101. result += ((time_now->tm_year + 1900) * 10000);
  102. result += (time_now->tm_mon * 100) + 100;
  103. result += time_now->tm_mday;
  104. return result;
  105. }
  106. int compareDate(int dt) {
  107. // Returns integer of difference, from now.
  108. struct tm *time_now;
  109. time_t timen;
  110. int now = 0;
  111. timen = time(NULL);
  112. time_now = localtime(&timen);
  113. now += ((time_now->tm_year + 1900) * 10000);
  114. now += (time_now->tm_mon * 100) + 100;
  115. now += time_now->tm_mday;
  116. return (now - dt); // 10000 = 1 Year, 100 = 1 Month, 1 = 1 Day
  117. }
  118. dT fromDate(int diff) {
  119. // Reverse process so we can compare exact days or get the structure back out too.
  120. dT result;
  121. result.year = diff / 10000;
  122. result.month = (diff / 100) % 100;
  123. result.day = diff % 100;
  124. result.age = 0;
  125. // Process Aprox day count
  126. result.age += (365 * result.year);
  127. result.age += (30 * result.month);
  128. result.age += result.day;
  129. return result;
  130. }
  131. int db_test() {
  132. // Displays all users in the database
  133. sqlite3 *db;
  134. sqlite3_stmt *stmt;
  135. char sqlbuffer[256];
  136. char strbuffer[256];
  137. int sizeofdb = 0;
  138. int rc = sqlite3_open("spaceconstruct.db3", &db);
  139. if(rc) { // Did we do a successful open?
  140. dolog("E: failed opening database %s", sqlite3_errmsg(db));
  141. sqlite3_close(db);
  142. md_exit(1);
  143. }
  144. sqlite3_busy_timeout(db, 5000);
  145. // DB open
  146. strcpy(sqlbuffer, "SELECT * FROM user;");
  147. sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer), &stmt, NULL);
  148. while(sqlite3_step(stmt) == SQLITE_ROW) {
  149. md_printf("`white`%s=%d %s=%s %s=%s %s=%d %s=%d %s=%d %s=%d %s=%d %s=%d %s=%d %s=%d %s=%d %s=%d %s=%d\r\n",
  150. sqlite3_column_name(stmt, 0), // int, uid
  151. sqlite3_column_int(stmt, 0),
  152. sqlite3_column_name(stmt, 1), // text, nick
  153. sqlite3_column_text(stmt, 1),
  154. sqlite3_column_name(stmt, 2), // text, real
  155. sqlite3_column_text(stmt, 2),
  156. sqlite3_column_name(stmt, 3), // int, experiece
  157. sqlite3_column_int(stmt, 3),
  158. sqlite3_column_name(stmt, 4), // int, metal
  159. sqlite3_column_int(stmt, 4),
  160. sqlite3_column_name(stmt, 5), // int, fuel
  161. sqlite3_column_int(stmt, 5),
  162. sqlite3_column_name(stmt, 6), // int, guns
  163. sqlite3_column_int(stmt, 6),
  164. sqlite3_column_name(stmt, 7), // int, armors
  165. sqlite3_column_int(stmt, 7),
  166. sqlite3_column_name(stmt, 8), // int, shields
  167. sqlite3_column_int(stmt, 8),
  168. sqlite3_column_name(stmt, 9), // int, armorpoints
  169. sqlite3_column_int(stmt, 9),
  170. sqlite3_column_name(stmt, 10), // int, shieldpoints
  171. sqlite3_column_int(stmt, 10),
  172. sqlite3_column_name(stmt, 11), // int, hitpoints
  173. sqlite3_column_int(stmt, 11),
  174. sqlite3_column_name(stmt, 12), // int, shieldsup
  175. sqlite3_column_int(stmt, 12),
  176. sqlite3_column_name(stmt, 13), // int, laston
  177. sqlite3_column_int(stmt, 13)
  178. );
  179. sizeofdb += 1;
  180. } // Clean up database
  181. sqlite3_finalize(stmt);
  182. sqlite3_close(db);
  183. return sizeofdb;
  184. }
  185. int check_lock() {
  186. // Checks stats of lock, (1 = Lock is in effect, 0 = No Lock established)
  187. struct stat s;
  188. if (stat("lock.flg", &s) == 0) {
  189. return 1;
  190. } else {
  191. return 0;
  192. }
  193. }
  194. int grab_lock() {
  195. // Attempt to grab lock, (0 = Already gotten, 1 = Success, -1 = Error)
  196. int valid = check_lock();
  197. FILE *fhandle;
  198. if (valid == 0) {
  199. fhandle = fopen("lock.flg", "w");
  200. if(!fhandle) {
  201. dolog("E: Unable to make lock.flg!");
  202. dolog("E: Something went wrong perhaps we don't have permissions?");
  203. return -1;
  204. }
  205. fprintf(fhandle, "I am in use already!\n");
  206. fclose(fhandle);
  207. return 1;
  208. } else {
  209. dolog("W: Lock already established!");
  210. return 0;
  211. }
  212. }
  213. void rel_lock() {
  214. // Attempt to release lock
  215. int valid = check_lock();
  216. if (valid == 1) {
  217. if (unlink("lock.flg") != 0) {
  218. dolog("C: Unable to release lock.flg!");
  219. dolog("C: Something went wrong! Players might not be able to play now!");
  220. }
  221. } else {
  222. dolog("W: Lock already released!");
  223. }
  224. }
  225. void log_drop() {
  226. // Spits out info from Drop File:
  227. md_printf("`white`First=%s Last=%s Alias=%s TimeLeft=%d SecLevel=%d Location=%s Node=%d Socket=%d Sysop=%s\r\n",
  228. mdcontrol.user_firstname,
  229. mdcontrol.user_lastname,
  230. mdcontrol.user_alias,
  231. mdcontrol.user_timeleft,
  232. mdcontrol.user_seclevel,
  233. mdcontrol.user_location,
  234. mdcontrol.node,
  235. mdcontrol.socket,
  236. mdcontrol.sysop_name
  237. );
  238. }
  239. void paws() {
  240. // Aaah, DRY
  241. md_printf("`white`Press any key to continue...");
  242. md_getc();
  243. md_printf("\r\n");
  244. }
  245. int yesNo() {
  246. char ch;
  247. int done = 0;
  248. md_printf("`bright black`(`bright white`Y`bright black`)`white`es `bright black`(`bright red`N`bright black`)`red`o`white`");
  249. ch = md_get_answer("YyNn\r");
  250. md_printf("\r\n");
  251. switch(tolower(ch)) {
  252. case 'y':
  253. done = 1;
  254. break;
  255. case '\r':
  256. case 'n':
  257. break;
  258. }
  259. return done;
  260. }
  261. int randrange(int min, int max){
  262. return min + rand() / (RAND_MAX / (max - min + 1) + 1);
  263. }
  264. int locate_player(char first[], char last[]) {
  265. // returns user id for given real name and 0 for no record found
  266. sqlite3 *db;
  267. sqlite3_stmt *stmt;
  268. char sqlbuffer[256];
  269. int result = 0;
  270. char name[256];
  271. int rc = sqlite3_open("spaceconstruct.db3", &db);
  272. if(rc) { // Did we do a successful open?
  273. dolog("E: failed opening database %s", sqlite3_errmsg(db));
  274. sqlite3_close(db);
  275. md_exit(-1);
  276. }
  277. sqlite3_busy_timeout(db, 5000);
  278. // Form Real Name
  279. strcpy(name, "");
  280. strcat(name, first);
  281. strcat(name, " ");
  282. strcat(name, last);
  283. //md_printf("realname = '%s'\r\n", name);
  284. // Locating user with given name
  285. strcpy(sqlbuffer, "SELECT * from user where real=? COLLATE NOCASE;");
  286. sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL);
  287. sqlite3_bind_text(stmt, 1, name, strlen(name), SQLITE_STATIC);
  288. rc = sqlite3_step(stmt);
  289. if (rc == SQLITE_ROW) {
  290. //dolog("User=%s uid=%d", name, sqlite3_column_int(stmt, 0));
  291. result = sqlite3_column_int(stmt, 0);
  292. } else {
  293. dolog("W: Unable to locate user=%s", name);
  294. result = 0;
  295. } // Clean Up, return results
  296. sqlite3_finalize(stmt);
  297. sqlite3_close(db);
  298. return result;
  299. }
  300. user_inf load_player(int uuid) {
  301. // Returns a player Structure from database
  302. sqlite3 *db;
  303. sqlite3_stmt *stmt;
  304. char sqlbuffer[256];
  305. user_inf result;
  306. int rc = sqlite3_open("spaceconstruct.db3", &db);
  307. if(rc) { // Did we do a successful open?
  308. dolog("E: failed opening database %s", sqlite3_errmsg(db));
  309. sqlite3_close(db);
  310. md_exit(-1);
  311. }
  312. sqlite3_busy_timeout(db, 5000);
  313. strcpy(sqlbuffer, "SELECT * FROM user WHERE uid=?;");
  314. sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL);
  315. sqlite3_bind_int(stmt, 1, uuid);
  316. rc = sqlite3_step(stmt);
  317. if (rc == SQLITE_ROW) {
  318. result.uid = sqlite3_column_int(stmt, 0);
  319. strcpy(result.nick, sqlite3_column_text(stmt, 1));
  320. strcpy(result.real, sqlite3_column_text(stmt, 2));
  321. result.experience = sqlite3_column_int(stmt, 3);
  322. result.metal = sqlite3_column_int(stmt, 4);
  323. result.fuel = sqlite3_column_int(stmt, 5);
  324. result.guns = sqlite3_column_int(stmt, 6);
  325. result.armors = sqlite3_column_int(stmt, 7);
  326. result.shields = sqlite3_column_int(stmt, 8);
  327. result.armorpoints = sqlite3_column_int(stmt, 9);
  328. result.shieldpoints = sqlite3_column_int(stmt, 10);
  329. result.hitpoints = sqlite3_column_int(stmt, 11);
  330. result.shieldsup = sqlite3_column_int(stmt, 12);
  331. result.laston = sqlite3_column_int(stmt, 13);
  332. } else {
  333. //dolog("E: Unable to locate user with id=%d got %s (%d)", uuid, sqlite3_errmsg(db), rc);
  334. sqlite3_finalize(stmt);
  335. sqlite3_close(db);
  336. result.uid = 0;
  337. return result;
  338. }
  339. sqlite3_finalize(stmt);
  340. sqlite3_close(db);
  341. return result;
  342. }
  343. user_inf highest_player() {
  344. // Used to find if someone may have fought the Unknown One and won the game already!
  345. int done = 0;
  346. user_inf test;
  347. int high = 0;
  348. int high_exp = 0;
  349. int id = 1;
  350. while(!done) {
  351. test = load_player(id);
  352. if(test.uid != 0) {
  353. if(test.experience > high_exp) {
  354. // Update highest player id and experience
  355. high_exp = test.experience;
  356. high = id;
  357. }
  358. } else {
  359. done = 1;
  360. }
  361. id += 1;
  362. } // Ok highest experiencing player found!
  363. test = load_player(high);
  364. return test;
  365. }
  366. void update_player(user_inf data) {
  367. sqlite3 *db;
  368. sqlite3_stmt *stmt;
  369. char sqlbuffer[1024];
  370. int rc = sqlite3_open("spaceconstruct.db3", &db);
  371. if(rc) { // Did we do a successful open?
  372. dolog("E: failed opening database %s", sqlite3_errmsg(db));
  373. sqlite3_close(db);
  374. md_exit(-1);
  375. }
  376. sqlite3_busy_timeout(db, 5000);
  377. // Bad, don't do this... opens to SQL injection!
  378. //snprintf(sqlbuffer, 1024, "UPDATE user SET nick = '%s', experience = %d, metal = %d, fuel = %d, guns = %d, armors = %d, shields = %d, armorpoints = %d, shieldpoints = %d, hitpoints = %d WHERE uid=%d;",
  379. // data.nick, data.experience, data.metal, data.fuel, data.guns, data.armors, data.shields, data.armorpoints, data.shieldpoints, data.hitpoints, data.uid);
  380. strcpy(sqlbuffer, "UPDATE user SET nick=?, experience=?, metal=?, fuel=?, guns=?, armors=?, shields=?, armorpoints=?, shieldpoints=?, hitpoints=?, shieldsup=?, laston=? WHERE uid=?;");
  381. sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL);
  382. // Bind All data values
  383. sqlite3_bind_text(stmt, 1, data.nick, strlen(data.nick), SQLITE_STATIC);
  384. sqlite3_bind_int(stmt, 2, data.experience);
  385. sqlite3_bind_int(stmt, 3, data.metal);
  386. sqlite3_bind_int(stmt, 4, data.fuel);
  387. sqlite3_bind_int(stmt, 5, data.guns);
  388. sqlite3_bind_int(stmt, 6, data.armors);
  389. sqlite3_bind_int(stmt, 7, data.shields);
  390. sqlite3_bind_int(stmt, 8, data.armorpoints);
  391. sqlite3_bind_int(stmt, 9, data.shieldpoints);
  392. sqlite3_bind_int(stmt, 10, data.hitpoints);
  393. sqlite3_bind_int(stmt, 11, data.shieldsup);
  394. sqlite3_bind_int(stmt, 12, data.laston);
  395. sqlite3_bind_int(stmt, 13, data.uid);
  396. // Execute
  397. rc = sqlite3_step(stmt);
  398. if(rc != SQLITE_DONE) {
  399. dolog("E: failed updating player=%d got error %s (%d)", data.uid, sqlite3_errmsg(db), rc);
  400. sqlite3_finalize(stmt);
  401. sqlite3_close(db);
  402. md_exit(-1);
  403. }
  404. sqlite3_finalize(stmt);
  405. sqlite3_close(db);
  406. }
  407. int create_player(user_inf data) {
  408. sqlite3 *db;
  409. sqlite3_stmt *stmt;
  410. char sqlbuffer[1024];
  411. int rc = sqlite3_open("spaceconstruct.db3", &db);
  412. if(rc) { // Did we do a successful open?
  413. dolog("E: failed opening database %s", sqlite3_errmsg(db));
  414. sqlite3_close(db);
  415. md_exit(-1);
  416. }
  417. sqlite3_busy_timeout(db, 5000);
  418. strcpy(sqlbuffer, "INSERT INTO user (nick, real, experience, metal, fuel, guns, armors, shields, armorpoints, shieldpoints, hitpoints, shieldsup, laston) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);");
  419. sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL);
  420. sqlite3_bind_text(stmt, 1, data.nick, strlen(data.nick), SQLITE_STATIC);
  421. sqlite3_bind_text(stmt, 2, data.real, strlen(data.real), SQLITE_STATIC);
  422. sqlite3_bind_int(stmt, 3, data.experience);
  423. sqlite3_bind_int(stmt, 4, data.metal);
  424. sqlite3_bind_int(stmt, 5, data.fuel);
  425. sqlite3_bind_int(stmt, 6, data.guns);
  426. sqlite3_bind_int(stmt, 7, data.armors);
  427. sqlite3_bind_int(stmt, 8, data.shields);
  428. sqlite3_bind_int(stmt, 9, data.armorpoints);
  429. sqlite3_bind_int(stmt, 10, data.shieldpoints);
  430. sqlite3_bind_int(stmt, 11, data.hitpoints);
  431. sqlite3_bind_int(stmt, 12, data.shieldsup);
  432. sqlite3_bind_int(stmt, 13, data.laston);
  433. rc = sqlite3_step(stmt);
  434. if(rc != SQLITE_DONE) {
  435. dolog("E: failed inserting player=%d got error %s (%d)", data.nick, sqlite3_errmsg(db), rc);
  436. sqlite3_finalize(stmt);
  437. sqlite3_close(db);
  438. md_exit(-1);
  439. }
  440. sqlite3_finalize(stmt);
  441. sqlite3_close(db);
  442. return 1; // Good
  443. }
  444. // Removed due to fact it throws off the internal id system
  445. /*void delete_player(int uuid) {
  446. sqlite3 *db;
  447. sqlite3_stmt *stmt;
  448. char sqlbuffer[256];
  449. int rc = sqlite3_open("spaceconstruct.db3", &db);
  450. if(rc) { // Did we do a successful open?
  451. dolog("E: failed opening database %s", sqlite3_errmsg(db));
  452. sqlite3_close(db);
  453. md_exit(-1);
  454. }
  455. sqlite3_busy_timeout(db, 5000);
  456. strcpy(sqlbuffer, "DELETE FROM user WHERE uid=?;");
  457. sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL);
  458. sqlite3_bind_int(stmt, 1, uuid);
  459. rc = sqlite3_step(stmt);
  460. if (rc != SQLITE_DONE){
  461. dolog("E: Unable to locate user with id=%d got %s (%d)", uuid, sqlite3_errmsg(db), rc);
  462. sqlite3_finalize(stmt);
  463. sqlite3_close(db);
  464. md_exit(-1);
  465. }
  466. sqlite3_finalize(stmt);
  467. sqlite3_close(db);
  468. }*/
  469. void delete_players() {
  470. sqlite3 *db;
  471. sqlite3_stmt *stmt;
  472. char sqlbuffer[256];
  473. int rc = sqlite3_open("spaceconstruct.db3", &db);
  474. if(rc) { // Did we do a successful open?
  475. dolog("E: failed opening database %s", sqlite3_errmsg(db));
  476. sqlite3_close(db);
  477. md_exit(-1);
  478. }
  479. sqlite3_busy_timeout(db, 5000);
  480. strcpy(sqlbuffer, "DELETE FROM user;");
  481. sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL);
  482. rc = sqlite3_step(stmt);
  483. if (rc != SQLITE_DONE){
  484. dolog("E: Delete_players 1/2, Unexpected error got %s (%d)", sqlite3_errmsg(db), rc);
  485. sqlite3_finalize(stmt);
  486. sqlite3_close(db);
  487. md_exit(-1);
  488. }
  489. strcpy(sqlbuffer, "UPDATE sqlite_sequence SET seq = 0 WHERE name='user';");
  490. sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL);
  491. rc = sqlite3_step(stmt);
  492. if (rc != SQLITE_DONE){
  493. dolog("E: Delete_players 2/2, Unexpected error got %s (%d)", sqlite3_errmsg(db), rc);
  494. sqlite3_finalize(stmt);
  495. sqlite3_close(db);
  496. md_exit(-1);
  497. }
  498. sqlite3_finalize(stmt);
  499. sqlite3_close(db);
  500. }
  501. int display_all_players() {
  502. sqlite3 *db;
  503. sqlite3_stmt *stmt;
  504. char sqlbuffer[1024];
  505. int rc = sqlite3_open("spaceconstruct.db3", &db);
  506. if(rc) { // Did we do a successful open?
  507. dolog("E: failed opening database %s", sqlite3_errmsg(db));
  508. sqlite3_close(db);
  509. md_exit(1);
  510. }
  511. sqlite3_busy_timeout(db, 5000);
  512. strcpy(sqlbuffer, "SELECT * from user ORDER BY experience DESC, nick DESC;");
  513. sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL);
  514. int total = 0;
  515. md_printf("`bright green`___ The Players ___\r\n");
  516. while(sqlite3_step(stmt) == SQLITE_ROW) {
  517. md_printf("`bright white` %s (%d)\r\n", sqlite3_column_text(stmt, 1), sqlite3_column_int(stmt, 3));
  518. total += 1;
  519. }
  520. if(total > 1) {
  521. md_printf("`green`There are a total of `bright green`%d`green` players\r\n", total);
  522. } else if(total == 0) {
  523. md_printf("`green`There are a total of `bright green`%d`green` players\r\n", total);
  524. } else {
  525. md_printf("`green`There are a total of `bright green`%d`green` player\r\n", total);
  526. }
  527. sqlite3_finalize(stmt);
  528. sqlite3_close(db);
  529. return total;
  530. }
  531. int display_all_opponents(int us) {
  532. sqlite3 *db;
  533. sqlite3_stmt *stmt;
  534. char sqlbuffer[1024];
  535. int rc = sqlite3_open("spaceconstruct.db3", &db);
  536. if(rc) { // Did we do a successful open?
  537. dolog("E: failed opening database %s", sqlite3_errmsg(db));
  538. sqlite3_close(db);
  539. md_exit(1);
  540. }
  541. sqlite3_busy_timeout(db, 5000);
  542. strcpy(sqlbuffer, "SELECT * from user ORDER BY experience DESC, nick DESC;");
  543. sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL);
  544. int total = 1;
  545. md_printf("`bright green`___ Target List ___\r\n");
  546. while(sqlite3_step(stmt) == SQLITE_ROW) {
  547. if(total != us) {
  548. md_printf("`bright black`(`bright white`%d`bright black`) `bright white`%s (%d)\r\n", total, sqlite3_column_text(stmt, 1), sqlite3_column_int(stmt, 3));
  549. }
  550. total += 1;
  551. }
  552. total -= 1;
  553. sqlite3_finalize(stmt);
  554. sqlite3_close(db);
  555. return total;
  556. }
  557. user_inf build_menu(user_inf my) {
  558. int done = 0;
  559. char ch;
  560. if(my.metal != 0) {
  561. while(!done) {
  562. md_clr_scr();
  563. md_sendfile("ansis/sc_build.ans", FALSE);
  564. // Paint over sc_build.ans file
  565. md_set_cursor(3, 15);
  566. md_printf("%5d", (4 * (my.guns + 1)));
  567. md_set_cursor(4, 15);
  568. md_printf("%5d", (3 * (my.armors + 1)));
  569. md_set_cursor(5, 15);
  570. md_printf("%5d", (6 * (my.shields + 1)));
  571. md_set_cursor(9, 0);
  572. // Resuming normal operations
  573. md_printf("`bright yellow`You have %8d metal\r\n", my.metal);
  574. ch = md_get_answer("GgAaSsCcRr\r");
  575. switch(tolower(ch)) {
  576. case 'g':
  577. if(my.metal >= (4 * (my.guns + 1))) {
  578. my.metal -= (4 * (my.guns + 1));
  579. my.guns += 1;
  580. my.hitpoints += 1;
  581. md_printf("`bright green`Added a new gun!\r\n`white`");
  582. paws();
  583. } else {
  584. md_printf("`bright red`You don't have the %d metal for this!\r\n`white`", (4 * (my.guns + 1)));
  585. paws();
  586. }
  587. break;
  588. case 'a':
  589. if(my.metal >= (3 * (my.armors + 1))) {
  590. my.metal -= (3 * (my.armors + 1));
  591. my.armors += 1;
  592. my.hitpoints += 1;
  593. my.armorpoints += 8;
  594. md_printf("`bright green`Added a new armor!\r\n`white`");
  595. paws();
  596. } else {
  597. md_printf("`bright red`You don't have the %d metal for this!\r\n`white`", (3 * (my.armors + 1)));
  598. paws();
  599. }
  600. break;
  601. case 's':
  602. if(my.metal >= (6 * (my.shields + 1))) {
  603. my.metal -= (6 * (my.shields + 1));
  604. my.shields += 1;
  605. my.hitpoints += 1;
  606. if(my.shieldsup == 0) {
  607. my.shieldpoints += 3;
  608. } else {
  609. my.shieldpoints += 1;
  610. }
  611. md_printf("`bright green`Added a new shield!\r\n`white`");
  612. paws();
  613. } else {
  614. md_printf("`bright red`You don't have the %d metal for this!\r\n`white`", (6 * (my.shields + 1)));
  615. paws();
  616. }
  617. break;
  618. case '\r':
  619. case 'c':
  620. done = 1;
  621. break;
  622. case 'r':
  623. if(my.experience > 25) {
  624. if(my.metal > 25) {
  625. my.experience -= 25;
  626. my.metal -= 25;
  627. my.fuel += 5;
  628. md_printf("`bright green`Made 5 fuel using 25 experience and 25 metal!\r\n");
  629. paws();
  630. } else {
  631. md_printf("`bright red`You need 25 experience and 25 metal to make fuel!\r\n");
  632. paws();
  633. }
  634. } else {
  635. md_printf("`bright red`You need 25 experience and 25 metal to make fuel!\r\n");
  636. paws();
  637. }
  638. break;
  639. }
  640. }
  641. update_player(my);
  642. return my;
  643. } else {
  644. return my;
  645. }
  646. }
  647. void pvp_menu(user_inf my, user_inf targ) {
  648. int done = 0;
  649. int playerWon = 0;
  650. char ch;
  651. // Extract temp values, assume offline player is at their best
  652. int temp_hp = (targ.shields + targ.armors + targ.guns + 2);
  653. int temp_ap = (targ.armors * 8);
  654. int temp_sp = (targ.shields * 3);
  655. int temp_su = 0;
  656. int temp_dmg = (targ.guns + 1); // Add 1 additional point of damage for offline player
  657. // Prep Combat values
  658. int fire = 0; // Fire Guns
  659. int flee = 0; // Run away
  660. int regen = 0; // Shields
  661. int temp = 0;
  662. int temp1 = 0;
  663. while(!done) {
  664. // Process Shields up
  665. if(temp_su != 0) {
  666. temp_su -= 1;
  667. }
  668. if(my.shieldsup != 0) {
  669. my.shieldsup -= 1;
  670. }
  671. // Process Crew repairing hitpoints
  672. if(temp_hp < (targ.shields + targ.armors + targ.guns + 2)) {
  673. regen = rand() % 100;
  674. if(regen >= 85) { // 15%, offline get a bonus 5% on repairing hull.
  675. temp_hp += 1;
  676. md_printf("`bright green`%s`green`'s crew repaired their hull for 1 point!\r\n", targ.nick);
  677. }
  678. }
  679. if(my.hitpoints < (my.shields + my.armors + my.guns + 2)) {
  680. regen = rand() % 100;
  681. if(regen >= 90) { // 10%
  682. my.hitpoints += 1;
  683. md_printf("`bright green`Your crew repaired your hull for 1 point!\r\n");
  684. }
  685. }
  686. // Process Shields regenerating and display player stats
  687. if(temp_su == 0) {
  688. if(temp_sp < (targ.shields * 3)) {
  689. regen = rand() % 100;
  690. if(regen >= 65) { // 35%, offline bonus
  691. temp_sp += targ.shields;
  692. if(temp_sp > (targ.shields * 3)) {
  693. temp_sp = (targ.shields * 3);
  694. }
  695. md_printf("`bright green`%s`green`'s shields regenerate %d points!\r\n", targ.nick, targ.shields);
  696. }
  697. }
  698. md_printf("`bright white`%s has `bright cyan`%d`bright white` shields, %d armor and %d hitpoints left\r\n", targ.nick, temp_sp, temp_ap, temp_hp);
  699. } else {
  700. if(temp_sp < (targ.shields * 3)) {
  701. regen = rand() % 100;
  702. if(regen >= 65) { // 35%, offline bonus
  703. temp_sp += 1;
  704. if(temp_sp > (targ.shields * 3)) {
  705. temp_sp = (targ.shields * 3);
  706. }
  707. md_printf("`bright green`%s`green`'s shields regenerate 1 points!\r\n", targ.nick);
  708. }
  709. }
  710. md_printf("`bright white`%s has `bright cyan`%d`bright white` shields, %d armor and %d hitpoints left\r\n", targ.nick, temp_sp, temp_ap, temp_hp);
  711. }
  712. // Online Players Shields
  713. if(my.shieldsup == 0) {
  714. if(my.shieldpoints < (my.shields * 3)) {
  715. regen = rand() % 100;
  716. if(regen >= 70) { // 30%
  717. my.shieldpoints += my.shields;
  718. if(my.shieldpoints > (my.shields * 3)) {
  719. my.shieldpoints = (my.shields * 3);
  720. }
  721. md_printf("`bright green`Your shields regenerate %d points!\r\n", my.shields);
  722. }
  723. }
  724. md_printf("`bright white`Your ship has `bright cyan`%d`bright white` shields, %d armor and %d hitpoints left:\r\n", my.shieldpoints, my.armorpoints, my.hitpoints);
  725. } else {
  726. if(my.shieldpoints < (my.shields * 3)) {
  727. regen = rand() % 100;
  728. if(regen >= 70) { // 30%
  729. my.shieldpoints += 1;
  730. if(my.shieldpoints > (my.shields * 3)) {
  731. my.shieldpoints = (my.shields * 3);
  732. }
  733. md_printf("`bright green`Your shields regenerate 1 points!\r\n");
  734. }
  735. }
  736. md_printf("`bright white`Your ship has `bright cyan`%d`bright white` shields, %d armor and %d hitpoints left:\r\n", my.shieldpoints, my.armorpoints, my.hitpoints);
  737. }
  738. // Form combat menu (Not allowing online to repair since offline can't really repair either)
  739. md_printf("`bright black`(`bright white`A`bright black`)`white`ttack\r\n");
  740. md_printf("`bright black`(`bright white`F`bright black`)`white`lee\r\n");
  741. // Online Players action
  742. ch = md_get_answer("AaFf\r");
  743. switch(tolower(ch)) {
  744. case '\r':
  745. case 'a':
  746. fire = rand() % 100;
  747. temp = my.guns;
  748. if(fire >= 50) {
  749. // Proccess online dealing damage to offline
  750. if(temp_su == 0 && temp_sp != 0) {
  751. if(temp >= temp_sp) {
  752. temp_su = (targ.shields + 2);
  753. temp -= temp_sp;
  754. temp_sp = 0;
  755. md_printf("`bright cyan`%s's shields absorbed %d damage and went offline!\r\n", targ.nick, temp_dmg);
  756. } else {
  757. temp1 = temp;
  758. temp -= temp_sp;
  759. temp_sp -= temp1;
  760. md_printf("`bright cyan`%s's shields absorbed %d damage!\r\n", targ.nick, temp1);
  761. temp1 = 0;
  762. }
  763. } // Armor
  764. if(temp > 0) {
  765. if(temp_ap != 0) {
  766. if(temp >= temp_ap) {
  767. temp1 = temp;
  768. temp -= temp_ap;
  769. temp_ap = 0;
  770. md_printf("`yellow`%s's armor took %d damage and broke!\r\n`white`", targ.nick, temp1);
  771. temp1 = 0;
  772. } else {
  773. temp1 = temp;
  774. temp -= temp_ap;
  775. temp_ap -= temp1;
  776. md_printf("`bright yellow`%s's armor took %d damage!\r\n`white`", targ.nick, temp1);
  777. temp1 = 0;
  778. }
  779. }
  780. } // Offline's hitpoints!
  781. if(temp > 0) {
  782. if(temp < temp_hp) {
  783. temp1 = temp;
  784. temp -= temp_hp; // should be 0
  785. temp_hp -= temp1;
  786. md_printf("`bright red`%s's hull took %d damage!\r\n", targ.nick, temp1);
  787. temp1 = 0;
  788. } else {
  789. playerWon = 1; // Online won over Offline!
  790. done = 1;
  791. md_printf("`red`%s's hull took %d damage and broke!\r\n", targ.nick, temp);
  792. }
  793. }
  794. } else { // Online missed
  795. md_printf("`white`You missed!\r\n");
  796. }
  797. break;
  798. case 'f':
  799. flee = rand() % 100;
  800. if(flee >= 80) { // 20% chance the online flees
  801. playerWon = 3; // Online ran away from Offline
  802. done = 1;
  803. md_printf("`bright green`You ran away from %s!\r\n", targ.nick);
  804. } else {
  805. md_printf("`bright red`%s found you!\r\n", targ.nick);
  806. }
  807. break;
  808. } // Now for Offline to attack
  809. if(!playerWon) {
  810. temp = temp_dmg;
  811. fire = rand() % 100;
  812. if(fire >= 45) { // 55%, 5% bonus for offline
  813. if(my.shieldsup == 0 && my.shieldpoints != 0) {
  814. if(temp >= my.shieldpoints) {
  815. // Damage will lower shields!
  816. my.shieldsup = (my.shields + 2);
  817. temp -= my.shieldpoints;
  818. my.shieldpoints = 0;
  819. md_printf("`bright cyan`Shields absorbed %d damage and went offline!\r\n`white`", temp_dmg);
  820. } else {
  821. // Damage to shields but not lower them
  822. temp1 = temp;
  823. temp -= my.shieldpoints;
  824. my.shieldpoints -= temp1;
  825. temp1 = 0;
  826. md_printf("`bright cyan`Shields absorbed %d damage!\r\n`white`", temp_dmg);
  827. }
  828. }
  829. // shields now armor
  830. if(temp > 0) {
  831. if(my.armorpoints != 0) {
  832. // We do have armor
  833. if(temp >= my.armorpoints) {
  834. // Damage will destroy armor!
  835. temp1 = temp;
  836. temp -= my.armorpoints;
  837. my.armorpoints = 0;
  838. md_printf("`yellow`Armor took %d damage and broke!\r\n`white`", temp1);
  839. temp1 = 0;
  840. } else {
  841. // Nope armor is good
  842. temp1 = temp;
  843. temp -= my.armorpoints;
  844. my.armorpoints -= temp1;
  845. md_printf("`bright yellow`Armor took %d damage!\r\n`white`", temp1);
  846. temp1 = 0;
  847. }
  848. }
  849. }
  850. // armor now hull
  851. if(temp > 0) {
  852. if(temp < my.hitpoints) {
  853. temp1 = temp;
  854. temp -= my.hitpoints; // should be 0
  855. my.hitpoints -= temp1;
  856. md_printf("`bright red`Hull took %d damage!\r\n", temp1);
  857. } else {
  858. playerWon = 2; // offline won over online!
  859. done = 1;
  860. my.hitpoints = 0;
  861. md_printf("`red`Hull took %d damage and broke!\r\n", temp);
  862. }
  863. }
  864. }
  865. }
  866. }
  867. // Winning Move?
  868. if(playerWon) {
  869. switch(playerWon) {
  870. case 1: // Online won over offline
  871. if(targ.experience) { // Just incase someone is dumb and attacked a player with no exp
  872. my.experience += (targ.experience / 2); // Gain half exp from offline
  873. targ.experience -= (targ.experience / 2); // Process offline giving online that exp
  874. }
  875. if(targ.metal) {
  876. my.metal += (targ.metal / 2);
  877. targ.metal -= (targ.metal / 2);
  878. }
  879. my.fuel -= 4;
  880. if(my.fuel < 0) {
  881. my.fuel = 0;
  882. }
  883. md_printf("`bright green`Congrats on defeating %s!\r\n`white`", targ.nick);
  884. break;
  885. case 2: // Offline won over online!
  886. if(my.experience) {
  887. targ.experience += (my.experience / 2);
  888. my.experience -= (my.experience / 2);
  889. }
  890. if(my.metal) {
  891. targ.metal += (my.metal / 2);
  892. my.metal -= (my.metal / 2);
  893. }
  894. my.fuel -= 4;
  895. if(my.fuel < 0) {
  896. my.fuel = 0;
  897. }
  898. md_printf("`bright red`Sorry for your loss! (We rebuild your ship)\r\n");
  899. my.hitpoints = 4;
  900. my.armorpoints = 8;
  901. my.shieldpoints = 0;
  902. my.shieldsup = 0;
  903. my.armors = 1;
  904. my.shields = 0;
  905. my.guns = 1;
  906. break;
  907. case 3:
  908. my.fuel -= 1;
  909. break;
  910. }
  911. }
  912. // DOne
  913. update_player(targ);
  914. update_player(my);
  915. }
  916. user_inf combat_menu(user_inf my, int targ_hp, int targ_dmg, int asteroid) {
  917. int done = 0;
  918. int playerWon = 0; // Did the player win? (1 = Yes, 2 = No, 3 = Flee)
  919. char ch;
  920. int armorRep = 0; // Can armor be repaired?
  921. int temp = 0;
  922. int temp1 = 0;
  923. int temp2 = 0;
  924. int temp_hp = targ_hp;
  925. int flee = 0;
  926. int fire = 0;
  927. int regen = 0;
  928. while(!done) {
  929. if(asteroid == 0) {
  930. md_printf("`bright white`Pirate has %d hitpoints left\r\n", targ_hp);
  931. } else if(asteroid == 1) {
  932. md_printf("`bright white`Asteroid has %d hitpoints left\r\n", targ_hp);
  933. } else if(asteroid == 2) {
  934. md_printf("`bright white`Unknown One has %d hitpoints left\r\n", targ_hp);
  935. }
  936. // Proccess Shields comming back online
  937. if(my.shieldsup != 0) {
  938. my.shieldsup -= 1;
  939. }
  940. // Proccess Crew repairing hull
  941. if(my.hitpoints < (my.guns + my.armors + my.shields + 2)) {
  942. regen = rand() % 100;
  943. if(regen >= 90) {
  944. my.hitpoints += 1;
  945. if(my.hitpoints > (my.guns + my.armors + my.shields + 2)) {
  946. my.hitpoints = (my.guns + my.armors + my.shields + 2);
  947. }
  948. md_printf("`bright green`Your crew repaired your hull for 1 point!\r\n");
  949. }
  950. }
  951. if(my.shieldsup == 0) {
  952. // Proccess Shield Regeneration
  953. if(my.shieldpoints < (my.shields * 3)) {
  954. regen = rand() % 100;
  955. if(regen >= 70) {
  956. my.shieldpoints += my.shields;
  957. if(my.shieldpoints > (my.shields * 3)) {
  958. my.shieldpoints = (my.shields * 3);
  959. }
  960. md_printf("`bright green`Your shields regenerate %d points!\r\n", my.shields);
  961. }
  962. }
  963. md_printf("`bright white`Your ship has `bright cyan`%d`bright white` shields, %d armor and %d hitpoints left:\r\n", my.shieldpoints, my.armorpoints, my.hitpoints);
  964. } else {
  965. // Shields should still regenerate some
  966. if(my.shieldpoints < (my.shields * 3)) {
  967. regen = rand() % 100;
  968. if(regen >= 70) {
  969. my.shieldpoints += 1;
  970. if(my.shieldpoints > (my.shields * 3)) {
  971. my.shieldpoints = (my.shields * 3);
  972. }
  973. md_printf("`bright green`Your shields regenerate 1 points!\r\n");
  974. }
  975. }
  976. md_printf("`bright white`Your ship has `bright cyan`%d`bright white` shields, %d armor and %d hitpoints left:\r\n", my.shieldpoints, my.armorpoints, my.hitpoints);
  977. }
  978. // Forming Combat Menu
  979. md_printf("`bright black`(`bright white`A`bright black`)`white`ttack\r\n");
  980. if(my.armorpoints < (my.armors * 8)) {
  981. md_printf("`bright black`(`bright white`R`bright black`)`white`epair Armor\r\n");
  982. armorRep = 1; // Yes we can repair armor
  983. }
  984. md_printf("`bright black`(`bright white`F`bright black`)`white`lee\r\n");
  985. // Proccess User action
  986. ch = md_get_answer("AaRrFf\r");
  987. switch(tolower(ch)) {
  988. case '\r':
  989. case 'a':
  990. fire = rand() % 100;
  991. if(asteroid == 1) { // Its a rock so allow player to hit it more frequent
  992. fire += 15;
  993. }
  994. if(fire >= 50) {
  995. targ_hp -= my.guns;
  996. if(targ_hp <= 0) {
  997. md_printf("`bright red`Target Destroyed!\r\n");
  998. done = 1;
  999. playerWon = 1;
  1000. } else {
  1001. md_printf("`bright red`Target took %d damage!\r\n", my.guns);
  1002. }
  1003. } else {
  1004. md_printf("`white`You Missed!\r\n");
  1005. }
  1006. break;
  1007. case 'r':
  1008. if(armorRep) {
  1009. if(my.metal > 0) {
  1010. my.metal -= 1;
  1011. my.armorpoints += 2;
  1012. if(my.armorpoints < (my.armors * 8)) {
  1013. my.armorpoints = (my.armors * 8);
  1014. }
  1015. md_printf("`bright green`Repaired 2 Armor points!\r\n");
  1016. } else {
  1017. md_printf("`bright red`You need metal inorder to repair!\r\n");
  1018. }
  1019. } else {
  1020. md_printf("`bright yellow`You don't seem to need repairs!\r\n");
  1021. }
  1022. break;
  1023. case 'f':
  1024. flee = rand() % 100;
  1025. if(asteroid == 1) {
  1026. flee = 100; // Always allow fleeing from asteroid
  1027. } else if(asteroid == 2) {
  1028. flee = 0; // Never allow fleeing from Unknown One
  1029. }
  1030. if(flee >= 82) {
  1031. playerWon = 3;
  1032. done = 1;
  1033. md_printf("`bright green`You ran away!\r\n");
  1034. } else {
  1035. md_printf("`bright red`Target found you!\r\n");
  1036. }
  1037. break;
  1038. } // If Enemy is alive proccess incomming attack
  1039. if(targ_hp > 0) {
  1040. temp = targ_dmg;
  1041. fire = rand() % 100;
  1042. if(asteroid == 1) { // Yup it doesn't have gunz cuz it's rock.
  1043. fire = 0;
  1044. } else if(asteroid == 2) { // This is the Unknown One
  1045. fire += 5;
  1046. }
  1047. if(fire >= 40) {
  1048. // Shields
  1049. if(my.shieldsup == 0 && my.shieldpoints != 0) {
  1050. if(temp >= my.shieldpoints) {
  1051. // Damage will lower shields!
  1052. my.shieldsup = (my.shields + 2);
  1053. temp -= my.shieldpoints;
  1054. my.shieldpoints = 0;
  1055. md_printf("`bright cyan`Shields absorbed %d damage and went offline!\r\n`white`", targ_dmg);
  1056. } else {
  1057. // Damage to shields but not lower them
  1058. temp1 = temp;
  1059. temp -= my.shieldpoints;
  1060. my.shieldpoints -= temp1;
  1061. temp1 = 0;
  1062. md_printf("`bright cyan`Shields absorbed %d damage!\r\n`white`", targ_dmg);
  1063. }
  1064. }
  1065. // shields now armor
  1066. if(temp > 0) {
  1067. if(my.armorpoints != 0) {
  1068. // We do have armor
  1069. if(temp >= my.armorpoints) {
  1070. // Damage will destroy armor!
  1071. temp2 = temp;
  1072. temp -= my.armorpoints;
  1073. my.armorpoints = 0;
  1074. md_printf("`yellow`Armor took %d damage and broke!\r\n`white`", temp2);
  1075. } else {
  1076. // Nope armor is good
  1077. temp1 = temp;
  1078. temp2 = temp;
  1079. temp -= my.armorpoints;
  1080. my.armorpoints -= temp1;
  1081. temp1 = 0;
  1082. md_printf("`bright yellow`Armor took %d damage!\r\n`white`", temp2);
  1083. }
  1084. }
  1085. }
  1086. // armor now hull
  1087. if(temp > 0) {
  1088. if(temp < my.hitpoints) {
  1089. temp1 = temp;
  1090. temp -= my.hitpoints; // should be 0
  1091. my.hitpoints -= temp1;
  1092. md_printf("`bright red`Hull took %d damage!\r\n", temp1);
  1093. } else {
  1094. playerWon = 2; // Nope the target did us in
  1095. done = 1;
  1096. my.hitpoints = 0;
  1097. md_printf("`red`Hull took %d damage and broke!\r\n", temp);
  1098. }
  1099. }
  1100. }
  1101. // firing
  1102. }
  1103. // Winning move?
  1104. if(playerWon) {
  1105. if(playerWon == 1) {
  1106. // Player won
  1107. my.experience += (temp_hp + targ_dmg);
  1108. my.metal += temp_hp;
  1109. if(asteroid == 1) { // If asteroid reward more experience and metal!
  1110. my.experience += 2;
  1111. my.metal += 2;
  1112. } else if(asteroid == 2) { // If it was the boss!
  1113. my.experience += 6000; // Ensure the game triggers a reset!
  1114. my.metal = 0; // Stop the player!
  1115. my.fuel = 2; // Prevent the player from doing anything else
  1116. }
  1117. my.fuel -= 2;
  1118. if(my.fuel < 0) {
  1119. my.fuel = 0;
  1120. }
  1121. md_printf("`bright green`Congrats on your victory!\r\n`white`");
  1122. } else if(playerWon == 2) {
  1123. // Target won
  1124. my.experience -= (temp_hp + targ_dmg);
  1125. my.metal -= temp_hp;
  1126. my.fuel -= 3;
  1127. if(my.experience < 0) {
  1128. my.experience = 0;
  1129. }
  1130. if(my.metal < 0) {
  1131. my.metal = 0;
  1132. }
  1133. if(my.fuel < 0) {
  1134. my.fuel = 0;
  1135. }
  1136. md_printf("`bright red`Sorry for your loss! (We rebuild your ship)\r\n");
  1137. my.hitpoints = 4;
  1138. my.armorpoints = 8;
  1139. my.shieldpoints = 0;
  1140. my.shieldsup = 0;
  1141. my.armors = 1;
  1142. my.shields = 0;
  1143. my.guns = 1;
  1144. } else if(playerWon == 3) {
  1145. // Chicken!
  1146. my.fuel -= 1;
  1147. }
  1148. }
  1149. }
  1150. update_player(my);
  1151. return my;
  1152. }
  1153. void about_game() {
  1154. int done = 0;
  1155. int page = 1;
  1156. char p[12];
  1157. char targ[256];
  1158. while(!done) {
  1159. switch(page) {
  1160. case 1:
  1161. md_clr_scr();
  1162. md_sendfile("ansis/sc_doc_1.ans", FALSE);
  1163. paws();
  1164. break;
  1165. case 2:
  1166. md_clr_scr();
  1167. md_sendfile("ansis/sc_doc_2.ans", FALSE);
  1168. paws();
  1169. break;
  1170. case 3:
  1171. md_clr_scr();
  1172. md_sendfile("ansis/sc_doc_3.ans", FALSE);
  1173. paws();
  1174. break;
  1175. case 4:
  1176. md_clr_scr();
  1177. md_sendfile("ansis/sc_doc_4.ans", FALSE);
  1178. paws();
  1179. break;
  1180. case 5:
  1181. md_clr_scr();
  1182. md_sendfile("ansis/sc_doc_5.ans", FALSE);
  1183. paws();
  1184. break;
  1185. case 6:
  1186. done = 1;
  1187. break;
  1188. }
  1189. md_clr_scr();
  1190. page += 1;
  1191. }
  1192. }
  1193. void play_game() {
  1194. int done = 0;
  1195. char ch;
  1196. char ch1[256];
  1197. user_inf myself;
  1198. user_inf myself2;
  1199. user_inf testing;
  1200. int reset = 0;
  1201. int doRefuel = 0;
  1202. int pirate_encounter = 0;
  1203. int pirate_hp = 0; // Reused for asteroid
  1204. int pirate_dmg = 0; // Reused for asteroid
  1205. int asteroid = 0; // 1 means yes we need to remove damage... completely.
  1206. int me = locate_player(mdcontrol.user_firstname, mdcontrol.user_lastname);
  1207. int abort = 0;
  1208. if(me != 0) {
  1209. //myself = load_player(me);
  1210. testing = load_player(me);
  1211. if(testing.uid != 0) {
  1212. myself = load_player(me);
  1213. }
  1214. dT age = fromDate(compareDate(myself.laston));
  1215. // Process player inactivity
  1216. if(age.age >= 30) { // 30 days
  1217. md_printf("`bright green`Since you haven't played a while we have reset your account!\r\n");
  1218. me = 0;
  1219. reset = 1;
  1220. }
  1221. // Processing fuel regeneration
  1222. if(age.age != 0) {
  1223. doRefuel = 1;
  1224. }
  1225. }
  1226. if(me != 0) {
  1227. md_printf("`bright white`Welcome back `bright green`%s\r\n", myself.nick);
  1228. dT age = fromDate(compareDate(myself.laston));
  1229. dolog("%s is now playing (G=%d A=%d S=%d F=%d M=%d AP=%d SP=%d (%d) HP=%d LO=%d or %d days)",
  1230. myself.nick, myself.guns, myself.armors, myself.shields, myself.fuel, myself.metal, myself.armorpoints,
  1231. myself.shieldpoints, myself.shieldsup, myself.hitpoints, myself.laston, age.age);
  1232. myself.laston = dateStamp();
  1233. if(age.day != 0 || age.month != 0 || age.year != 0) {
  1234. md_printf("`bright yellow`Haven't seen you for");
  1235. }
  1236. if(age.day != 0) {
  1237. if(age.day > 1) {
  1238. md_printf(" %d days", age.day);
  1239. } else {
  1240. md_printf(" %d day", age.day);
  1241. }
  1242. }
  1243. if(age.month != 0) {
  1244. if(age.month > 1) {
  1245. md_printf(" %d months", age.month);
  1246. } else {
  1247. md_printf(" %d month", age.month);
  1248. }
  1249. }
  1250. if(age.year != 0) {
  1251. if(age.year > 1) {
  1252. md_printf(" %d years", age.year);
  1253. } else {
  1254. md_printf(" %d year", age.year);
  1255. }
  1256. }
  1257. if(age.day != 0 || age.month != 0 || age.year != 0) {
  1258. md_printf("\r\n");
  1259. }
  1260. if(doRefuel) {
  1261. if(myself.fuel != 0) {
  1262. myself.fuel += (age.age * 2);
  1263. } else {
  1264. myself.fuel += ((age.age * 2) + 10);
  1265. md_printf("`bright green`For using all your fuel last time you get bonus fuel today!\r\n");
  1266. }
  1267. md_printf("`bright green`You now have %d fuel\r\n", myself.fuel);
  1268. }
  1269. update_player(myself);
  1270. paws();
  1271. } else {
  1272. md_printf("`bright white`You look new here. (Hit Enter to abort)\r\n");
  1273. while(done == 0) {
  1274. md_printf("`bright yellow`What's your name: ");
  1275. md_getstring(ch1, 26, 32, 126);
  1276. md_printf("\r\n");
  1277. if(strlen(ch1) > 0) {
  1278. //md_getstring(ch1, 256, 32, 126);
  1279. strcpy(myself.nick, ch1);
  1280. } else {
  1281. md_clr_scr();
  1282. abort = 1;
  1283. done = 1;
  1284. md_printf("`bright red`Ok, come back later then...`white`\r\n");
  1285. paws();
  1286. }
  1287. if(abort == 0) {
  1288. md_printf("`bright white`Are you sure you want to be called `bright green`%s\r\n");
  1289. done = yesNo();
  1290. if(done) {
  1291. if(reset) { // So we are reseting the user, this wipes all values and uses update instead of create
  1292. myself.experience = 0;
  1293. myself.metal = 0;
  1294. myself.fuel = 10;
  1295. myself.guns = 1;
  1296. myself.armors = 1;
  1297. myself.shields = 0;
  1298. myself.armorpoints = 8;
  1299. myself.shieldpoints = 0;
  1300. myself.hitpoints = 4;
  1301. myself.shieldsup = 0;
  1302. myself.laston = dateStamp();
  1303. update_player(myself);
  1304. } else { // Brand new user
  1305. char name[256];
  1306. strcpy(myself2.nick, myself.nick);
  1307. strcpy(name, "");
  1308. strcat(name, mdcontrol.user_firstname);
  1309. strcat(name, " ");
  1310. strcat(name, mdcontrol.user_lastname);
  1311. strcpy(myself2.real, name);
  1312. myself2.experience = 0;
  1313. myself2.metal = 0;
  1314. myself2.fuel = 10;
  1315. myself2.guns = 1;
  1316. myself2.armors = 1;
  1317. myself2.shields = 0;
  1318. myself2.armorpoints = 8;
  1319. myself2.shieldpoints = 0;
  1320. myself2.hitpoints = 4;
  1321. myself2.shieldsup = 0;
  1322. myself2.laston = dateStamp();
  1323. create_player(myself2);
  1324. myself = load_player(locate_player(mdcontrol.user_firstname, mdcontrol.user_lastname));
  1325. }
  1326. }
  1327. }
  1328. }
  1329. done = 0; // Reset this for our next loop.
  1330. }
  1331. // Ok user is here now lets ask what they want to do... build/attack
  1332. if(abort == 0) {
  1333. md_clr_scr();
  1334. while(!done) {
  1335. md_printf("`bright yellow`You have %d fuel left for today,\r\n", myself.fuel);
  1336. if(myself.shieldsup == 0) {
  1337. md_printf("`bright yellow`Your ship has `bright cyan`%d`bright yellow` shields, %d armor and %d hitpoints left:\r\n", myself.shieldpoints, myself.armorpoints, myself.hitpoints);
  1338. } else {
  1339. md_printf("`bright yellow`Your ship has %d armor, `bright cyan`%d`bright yellow` shields and %d hitpoints left:\r\n", myself.armorpoints, myself.shieldpoints, myself.hitpoints);
  1340. }
  1341. if(myself.armorpoints < (myself.armors * 8)) {
  1342. md_printf("`bright black`(`bright white`R`bright black`)`white`epair Armor\r\n");
  1343. }
  1344. if(myself.shieldpoints < (myself.shields * 3) || myself.shieldsup != 0) {
  1345. md_printf("`bright black`(`bright white`G`bright black`)`white`enerate Shields\r\n");
  1346. }
  1347. if(myself.fuel >= 2) {
  1348. md_sendfile("ansis/sc_gameh.ans", FALSE);
  1349. ch = md_get_answer("SsHhBbQqRrGgLlVv");
  1350. } else {
  1351. md_sendfile("ansis/sc_gamel.ans", FALSE);
  1352. ch = md_get_answer("BbQqRrGgLlVv");
  1353. }
  1354. md_clr_scr();
  1355. switch(tolower(ch)) {
  1356. case 's':
  1357. if(myself.fuel >= 2) {
  1358. pirate_encounter = rand() % 100;
  1359. if(pirate_encounter >= 75) { // 25% chance to encounter a Pirate, or Unknown One
  1360. if(myself.experience > 3000) {
  1361. if(pirate_encounter >= 95) { // 5% chance to encounter unknown one
  1362. md_printf("`bright yellow`You encounter the `bright red`Unknown One\r\n`white`");
  1363. asteroid = 2;
  1364. } else {
  1365. md_printf("`bright yellow`You encounter a `bright red`Pirate\r\n`white`");
  1366. asteroid = 0;
  1367. }
  1368. } else { // The player is not skilled enough to fight the unknown one
  1369. md_printf("`bright yellow`You encounter a `bright red`Pirate\r\n`white`");
  1370. asteroid = 0;
  1371. }
  1372. } else { // 75% chance to encounter a Asteroid
  1373. md_printf("`bright yellow`You encounter a `bright red`Asteroid\r\n`white`");
  1374. asteroid = 1;
  1375. }
  1376. if(asteroid == 0 || asteroid == 2) {
  1377. pirate_hp = ((myself.hitpoints + 1) + (rand() % 4));
  1378. if(asteroid == 2) { // Increase boss hitpoints
  1379. pirate_hp += 10;
  1380. }
  1381. // Increase difficulty based on experience...
  1382. pirate_dmg = (myself.experience / 500);
  1383. if(pirate_dmg == 0) { // Always deal damage
  1384. pirate_dmg = 1;
  1385. }
  1386. if(asteroid == 2) { // Increase boss damage
  1387. pirate_dmg += 2;
  1388. }
  1389. // Send off to combat menu
  1390. myself = combat_menu(myself, pirate_hp, pirate_dmg, asteroid);
  1391. } else {
  1392. pirate_hp = (myself.hitpoints + 1) + (rand() % 10);
  1393. // Send off to combat menu
  1394. myself = combat_menu(myself, pirate_hp, 0, asteroid);
  1395. }
  1396. }
  1397. break;
  1398. case 'h':
  1399. if(myself.fuel >= 4) {
  1400. int targs = display_all_opponents(myself.uid);
  1401. int targg = 1;
  1402. int done2 = 0;
  1403. if(targg == myself.uid) {
  1404. targg += 1;
  1405. }
  1406. while(!done2) {
  1407. md_printf("`bright red`Targetting: %d\r\n", targg);
  1408. if(yesNo()) {
  1409. done2 = 1;
  1410. } else if(targg < targs){
  1411. targg += 1;
  1412. } else {
  1413. done2 = 1;
  1414. md_printf("`bright red`ABORTED!\r\n");
  1415. break;
  1416. }
  1417. }
  1418. user_inf targ = load_player(targg);
  1419. if(targ.uid != 0) {
  1420. // I need to add some limits in here else someone could attack weaker players!
  1421. int proceed = 0;
  1422. int temp = targ.experience + 1000; // Prevent the person from selecting a player that is higher than them
  1423. int temp1 = targ.experience - 500; // Prevent the person from selecting a player that is lower than them
  1424. if(temp1 > 0) {
  1425. temp1 = 0;
  1426. }
  1427. if(temp > myself.experience && temp1 < myself.experience) {
  1428. proceed = 1;
  1429. }
  1430. if(proceed) {
  1431. pvp_menu(myself, targ);
  1432. } else {
  1433. md_printf("`bright white`Please select a opponent within your range of expertise!\r\n");
  1434. break;
  1435. }
  1436. }
  1437. } else {
  1438. md_printf("`bright white`You need 4 fuel to fight another player!\r\n`white`");
  1439. }
  1440. break;
  1441. case 'b':
  1442. if(myself.metal != 0) {
  1443. // Send off to build menu
  1444. md_clr_scr();
  1445. //md_sendfile("ansis/sc_build.ans", FALSE);
  1446. myself = build_menu(myself);
  1447. } else {
  1448. md_printf("`bright white`I am sorry you have no metal go fight.`white`\r\n");
  1449. }
  1450. break;
  1451. case 'q':
  1452. done = 1;
  1453. break;
  1454. case 'r':
  1455. if(myself.armorpoints < (myself.armors * 8)) {
  1456. if(myself.metal > 0) {
  1457. myself.metal -= 1;
  1458. myself.armorpoints += 4;
  1459. if(myself.armorpoints > (myself.armors * 8)) {
  1460. myself.armorpoints = (myself.armors * 8);
  1461. }
  1462. update_player(myself);
  1463. md_printf("`bright green`Repaired 4 Armor Points!\r\n`white`");
  1464. } else {
  1465. md_printf("`bright red`You need metal inorder to repair!\r\n`white`");
  1466. }
  1467. } else {
  1468. md_printf("`bright yellow`You don't seem to need repairs!\r\n`white`");
  1469. }
  1470. break;
  1471. case 'g':
  1472. if(myself.shieldpoints < (myself.shields * 3) || myself.shieldsup != 0) {
  1473. myself.shieldpoints += myself.shields;
  1474. myself.shieldsup -= 1;
  1475. if(myself.shieldsup < 0) {
  1476. myself.shieldsup = 0;
  1477. }
  1478. if(myself.shieldpoints > (myself.shields * 3)) {
  1479. myself.shieldpoints = (myself.shields * 3);
  1480. }
  1481. update_player(myself);
  1482. md_printf("`bright green`Regenerated Shields!\r\n`white`");
  1483. } else {
  1484. md_printf("`bright yellow`You don't seem to need to regenerate shields!\r\n`white`");
  1485. }
  1486. break;
  1487. case 'v':
  1488. md_printf("`bright white` ___ %s's Ship Status ___\r\n", myself.nick);
  1489. md_printf("`bright white`Items: # Installed: Metal to Upgrade:\r\n");
  1490. md_printf("`bright red`Guns: %8d %8d\r\n", myself.guns, (4 * (myself.guns + 1)));
  1491. md_printf("`bright yellow`Armor: %8d %8d\r\n", myself.armors, (3 * (myself.armors + 1)));
  1492. md_printf("`bright cyan`Shields: %8d %8d\r\n", myself.shields, (6 * (myself.shields + 1)));
  1493. md_printf("`bright white`\r\n ___ Situation Report ___\r\n");
  1494. md_printf("`bright white`Items: Maximum: Current:\r\n");
  1495. md_printf("`bright green`Hitpoints: %8d %8d\r\n", (myself.guns + myself.armors + myself.shields + 2), myself.hitpoints);
  1496. md_printf("`bright yellow`Armor: %8d %8d\r\n", (myself.armors * 8), myself.armorpoints);
  1497. md_printf("`bright cyan`Shields: %8d %8d\r\n", (myself.shields * 3), myself.shieldpoints);
  1498. md_printf("`bright magenta`Experience: %8d\r\n", myself.experience);
  1499. md_printf("`bright magenta`Fuel: %8d\r\n", myself.fuel);
  1500. md_printf("`white`Metal: %8d\r\n", myself.metal);
  1501. paws();
  1502. md_clr_scr();
  1503. break;
  1504. }
  1505. }
  1506. }
  1507. }
  1508. void sysop_menu() {
  1509. int done = 0;
  1510. char ch;
  1511. int targ_ply = 1;
  1512. int targ_max = 0;
  1513. int done1 = 0;
  1514. user_inf targ;
  1515. while(!done) {
  1516. md_clr_scr();
  1517. md_sendfile("ansis/sc_sysop.ans", TRUE);
  1518. ch = md_get_answer("RrNnQq");
  1519. //md_printf("\r\n");
  1520. switch(tolower(ch)) {
  1521. case 'q':
  1522. done = 1;
  1523. break;
  1524. case 'r':
  1525. md_printf("`bright red`__ Reset ___\r\n");
  1526. md_printf("`bright red`DANGER THIS WILL DELETE ALL PLAYERS IN GAME\r\n");
  1527. if(yesNo() == 0) {
  1528. md_printf("`bright red`ABORTED!\r\n");
  1529. paws();
  1530. break;
  1531. }
  1532. dolog("%s issued reset", mdcontrol.user_alias);
  1533. delete_players();
  1534. paws();
  1535. break;
  1536. case 'n':
  1537. md_printf("`bright red`__ New Day ___\r\n");
  1538. while(!done1) {
  1539. targ = load_player(targ_ply);
  1540. if(targ.uid != 0) {
  1541. targ.laston -= 1; // Travel back 1 day
  1542. update_player(targ); // Save
  1543. } else {
  1544. done1 = 1;
  1545. }
  1546. targ_ply += 1;
  1547. targ_max += 1;
  1548. }
  1549. md_printf("`bright red`%d players affected\r\n", (targ_max - 1));
  1550. targ_ply = 1;
  1551. targ_max = 0;
  1552. done1 = 0;
  1553. dolog("%s issued new day", mdcontrol.user_alias);
  1554. paws();
  1555. break;
  1556. }
  1557. }
  1558. md_clr_scr();
  1559. }
  1560. void main_menu() {
  1561. // Main menu for once things are done being initalized
  1562. int done = 0;
  1563. int done1 = 0; // For Reset Game and for New Day... also for Debug
  1564. int targ_ply = 1; // Target player to perform op!
  1565. int targ_max = 0; // Total number of players affected!
  1566. user_inf targ; // Player Struct
  1567. user_inf test;
  1568. dT targ_age; // Date Struct
  1569. char targ_real[256];
  1570. char ch;
  1571. int auth; // Security
  1572. char sys[48]; // Security
  1573. // 0 means we got the lock first, 1 means someone else has it already!
  1574. while(!done) {
  1575. md_clr_scr();
  1576. md_sendfile("ansis/sc_main.ans", TRUE);
  1577. ch = md_get_answer("PpLlVvQqSs");
  1578. md_clr_scr();
  1579. switch(tolower(ch)){
  1580. case 'q':
  1581. // Quit
  1582. done = 1;
  1583. break;
  1584. case 'p':
  1585. // Play Game (Default if the player just hits enter)
  1586. // Check to see if we have a winner if so refuse to let anyone on! (Wait 3 days then reset the game!)
  1587. test = highest_player();
  1588. dT test2 = fromDate(compareDate(test.laston));
  1589. if(test.experience >= 8000) { // If the player has the minimum of 3000 exp to fight the Unkown One and wins earning 5000 thats 8000 minimum
  1590. if(test2.age >= 3) { // Auto reset the game or not allow the player to play!
  1591. delete_players();
  1592. dolog("Auto-Reset Occured!");
  1593. md_printf("`bright green`Game has been reset!\r\n");
  1594. paws();
  1595. } else { // And the lucky winner is!
  1596. int resetage = 3 - test2.age;
  1597. md_printf("`bright green`%s has won the game!\r\n", test.nick);
  1598. md_printf("`bright green`The Game will reset in %d days!\r\n", resetage);
  1599. paws();
  1600. break;
  1601. }
  1602. }
  1603. inuse = check_lock();
  1604. if (inuse == 0) {
  1605. //md_printf("`bright white`Play\r\n");
  1606. int lock = grab_lock(); // Grab success and error rc from locking
  1607. if(lock == 1){
  1608. play_game();
  1609. rel_lock();
  1610. } else if(lock == -1) {
  1611. md_clr_scr();
  1612. md_printf("`bright red`Please contact your sysop there seems to be an issue.\r\n");
  1613. paws();
  1614. break;
  1615. }
  1616. } else {
  1617. md_clr_scr();
  1618. md_sendfile("ansis/sc_inuse.ans", FALSE);
  1619. paws();
  1620. }
  1621. break;
  1622. case 'a':
  1623. about_game();
  1624. break;
  1625. case 'l':
  1626. // List Players in the game
  1627. display_all_players();
  1628. paws();
  1629. break;
  1630. case 'v':
  1631. // Version
  1632. md_clr_scr();
  1633. md_printf("`bright yellow`_____________________________\r\n");
  1634. md_printf("`bright yellow` Space Construct v%d.%d-%s\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_TYPE);
  1635. md_printf("`bright yellow` By: Beanzilla\r\n");
  1636. md_printf("`bright yellow` FsxNet 21:4/110\r\n");
  1637. md_printf("`bright yellow` HappyNet 637:1/110\r\n");
  1638. md_printf("`bright yellow`_____________________________\r\n");
  1639. paws();
  1640. break;
  1641. case 's':
  1642. auth = 0;
  1643. if(allowDev && strcmp(mdcontrol.user_alias, "Beanzilla") == 0) {
  1644. md_printf("`bright green`Access Granted\r\n");
  1645. auth = 1;
  1646. } else {
  1647. md_printf("`bright red`Sysop Password: ");
  1648. strcpy(sys, "");
  1649. md_getstring(sys, 32, 32, 126);
  1650. md_clr_scr(); // Add a bit of protecton
  1651. if(strcmp(sys, sysop_pass) == 0) {
  1652. md_printf("`bright green`Access Granted\r\n");
  1653. auth = 1;
  1654. }
  1655. }
  1656. // Give only Sysop and dev access to restricted commands
  1657. if(auth) {
  1658. paws();
  1659. sysop_menu();
  1660. } else {
  1661. md_printf("`bright red`Access Denied\r\n");
  1662. paws();
  1663. }
  1664. break;
  1665. }
  1666. }
  1667. }
  1668. void cleanMe() {
  1669. rel_lock();
  1670. md_exit(0);
  1671. }
  1672. int main(int argc, char **argv) {
  1673. int socket;
  1674. if (argc < 2) { // Not enough arguments
  1675. fprintf(stderr, "usage:\n%s (DROPFILE [SOCKET])\r\n", argv[0]);
  1676. dolog("E %s (DROPFILE [SOCKET])", argv[0]);
  1677. return 0;
  1678. }
  1679. if (argc > 2) { // If socket is found use socket
  1680. if (argv[2][0] >= '0' && argv[2][0] <= '9') {
  1681. socket = strtol(argv[2], NULL, 10);
  1682. } else {
  1683. socket = -1;
  1684. }
  1685. } else {
  1686. socket = -1;
  1687. }
  1688. // Initiate MagiDoor
  1689. md_init(argv[1], socket);
  1690. atexit(cleanMe);
  1691. md_clr_scr();
  1692. // Debug System
  1693. if (debug) {
  1694. dolog("=== Debug ===");
  1695. md_printf("`white`=== Debug ===\r\n");
  1696. md_printf("DropFile...\r\n");
  1697. log_drop();
  1698. int test = check_lock();
  1699. if (test == 0) {
  1700. md_printf("Lock is: Avalible\r\n");
  1701. md_printf("Database...\r\n");
  1702. db_test();
  1703. } else {
  1704. md_printf("Lock is: Taken\r\n");
  1705. md_printf("CANCELED Database Dump\r\n");
  1706. }
  1707. paws();
  1708. md_clr_scr();
  1709. } else {
  1710. dolog("--- Debug ---");
  1711. }
  1712. // Main Menu
  1713. main_menu();
  1714. }