main.c 60 KB

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