main.c 59 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766
  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. md_printf("`bright yellow`You have %d metal\r\n", my.metal);
  578. ch = md_get_answer("GgAaSsCcRr\r");
  579. switch(tolower(ch)) {
  580. case 'g':
  581. if(my.metal >= (4 * (my.guns + 1))) {
  582. my.metal -= (4 * (my.guns + 1));
  583. my.guns += 1;
  584. my.hitpoints += 1;
  585. md_printf("`bright green`Added a new gun!\r\n`white`");
  586. paws();
  587. } else {
  588. md_printf("`bright red`You don't have the %d metal for this!\r\n`white`", (4 * (my.guns + 1)));
  589. paws();
  590. }
  591. break;
  592. case 'a':
  593. if(my.metal >= (3 * (my.armors + 1))) {
  594. my.metal -= (3 * (my.armors + 1));
  595. my.armors += 1;
  596. my.hitpoints += 1;
  597. my.armorpoints += 8;
  598. md_printf("`bright green`Added a new armor!\r\n`white`");
  599. paws();
  600. } else {
  601. md_printf("`bright red`You don't have the %d metal for this!\r\n`white`", (3 * (my.armors + 1)));
  602. paws();
  603. }
  604. break;
  605. case 's':
  606. if(my.metal >= (6 * (my.shields + 1))) {
  607. my.metal -= (6 * (my.shields + 1));
  608. my.shields += 1;
  609. my.hitpoints += 1;
  610. if(my.shieldsup == 0) {
  611. my.shieldpoints += 3;
  612. } else {
  613. my.shieldpoints += 1;
  614. }
  615. md_printf("`bright green`Added a new shield!\r\n`white`");
  616. paws();
  617. } else {
  618. md_printf("`bright red`You don't have the %d metal for this!\r\n`white`", (6 * (my.shields + 1)));
  619. paws();
  620. }
  621. break;
  622. case '\r':
  623. case 'c':
  624. done = 1;
  625. break;
  626. case 'r':
  627. if(my.experience > 25) {
  628. if(my.metal > 25) {
  629. my.experience -= 25;
  630. my.metal -= 25;
  631. my.fuel += 5;
  632. md_printf("`bright green`Made 5 fuel using 25 experience and 25 metal!\r\n");
  633. paws();
  634. } else {
  635. md_printf("`bright red`You need 25 experience and 25 metal to make fuel!\r\n");
  636. paws();
  637. }
  638. } else {
  639. md_printf("`bright red`You need 25 experience and 25 metal to make fuel!\r\n");
  640. paws();
  641. }
  642. break;
  643. }
  644. }
  645. update_player(my);
  646. return my;
  647. } else {
  648. return my;
  649. }
  650. }
  651. void pvp_menu(user_inf my, user_inf targ) {
  652. int done = 0;
  653. int playerWon = 0;
  654. char ch;
  655. // Extract temp values, assume offline player is at their best
  656. int temp_hp = (targ.shields + targ.armors + targ.guns + 2);
  657. int temp_ap = (targ.armors * 8);
  658. int temp_sp = (targ.shields * 3);
  659. int temp_su = 0;
  660. int temp_dmg = (targ.guns + 1); // Add 1 additional point of damage for offline player
  661. // Prep Combat values
  662. int fire = 0; // Fire Guns
  663. int flee = 0; // Run away
  664. int regen = 0; // Shields
  665. int temp = 0;
  666. int temp1 = 0;
  667. while(!done) {
  668. // Process Shields up
  669. if(temp_su != 0) {
  670. temp_su -= 1;
  671. }
  672. if(my.shieldsup != 0) {
  673. my.shieldsup -= 1;
  674. }
  675. // Process Crew repairing hitpoints
  676. if(temp_hp < (targ.shields + targ.armors + targ.guns + 2)) {
  677. regen = rand() % 100;
  678. if(regen >= 85) { // 15%, offline get a bonus 5% on repairing hull.
  679. temp_hp += 1;
  680. md_printf("`bright green`%s`green`'s crew repaired their hull for 1 point!\r\n", targ.nick);
  681. }
  682. }
  683. if(my.hitpoints < (my.shields + my.armors + my.guns + 2)) {
  684. regen = rand() % 100;
  685. if(regen >= 90) { // 10%
  686. my.hitpoints += 1;
  687. md_printf("`bright green`Your crew repaired your hull for 1 point!\r\n");
  688. }
  689. }
  690. // Process Shields regenerating and display player stats
  691. if(temp_su == 0) {
  692. if(temp_sp < (targ.shields * 3)) {
  693. regen = rand() % 100;
  694. if(regen >= 65) { // 35%, offline bonus
  695. temp_sp += targ.shields;
  696. if(temp_sp > (targ.shields * 3)) {
  697. temp_sp = (targ.shields * 3);
  698. }
  699. md_printf("`bright green`%s`green`'s shields regenerate %d points!\r\n", targ.nick, targ.shields);
  700. }
  701. }
  702. 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);
  703. } else {
  704. if(temp_sp < (targ.shields * 3)) {
  705. regen = rand() % 100;
  706. if(regen >= 65) { // 35%, offline bonus
  707. temp_sp += 1;
  708. if(temp_sp > (targ.shields * 3)) {
  709. temp_sp = (targ.shields * 3);
  710. }
  711. md_printf("`bright green`%s`green`'s shields regenerate 1 points!\r\n", targ.nick);
  712. }
  713. }
  714. 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);
  715. }
  716. // Online Players Shields
  717. if(my.shieldsup == 0) {
  718. if(my.shieldpoints < (my.shields * 3)) {
  719. regen = rand() % 100;
  720. if(regen >= 70) { // 30%
  721. my.shieldpoints += my.shields;
  722. if(my.shieldpoints > (my.shields * 3)) {
  723. my.shieldpoints = (my.shields * 3);
  724. }
  725. md_printf("`bright green`Your shields regenerate %d points!\r\n", my.shields);
  726. }
  727. }
  728. 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);
  729. } else {
  730. if(my.shieldpoints < (my.shields * 3)) {
  731. regen = rand() % 100;
  732. if(regen >= 70) { // 30%
  733. my.shieldpoints += 1;
  734. if(my.shieldpoints > (my.shields * 3)) {
  735. my.shieldpoints = (my.shields * 3);
  736. }
  737. md_printf("`bright green`Your shields regenerate 1 points!\r\n");
  738. }
  739. }
  740. 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);
  741. }
  742. // Form combat menu (Not allowing online to repair since offline can't really repair either)
  743. md_printf("`bright black`(`bright white`A`bright black`)`white`ttack\r\n");
  744. md_printf("`bright black`(`bright white`F`bright black`)`white`lee\r\n");
  745. // Online Players action
  746. ch = md_get_answer("AaFf\r");
  747. switch(tolower(ch)) {
  748. case '\r':
  749. case 'a':
  750. fire = rand() % 100;
  751. temp = my.guns;
  752. if(fire >= 50) {
  753. // Proccess online dealing damage to offline
  754. if(temp_su == 0 && temp_sp != 0) {
  755. if(temp >= temp_sp) {
  756. temp_su = (targ.shields + 2);
  757. temp -= temp_sp;
  758. temp_sp = 0;
  759. md_printf("`bright cyan`%s's shields absorbed %d damage and went offline!\r\n", targ.nick, temp_dmg);
  760. } else {
  761. temp1 = temp;
  762. temp -= temp_sp;
  763. temp_sp -= temp1;
  764. md_printf("`bright cyan`%s's shields absorbed %d damage!\r\n", targ.nick, temp1);
  765. temp1 = 0;
  766. }
  767. } // Armor
  768. if(temp > 0) {
  769. if(temp_ap != 0) {
  770. if(temp >= temp_ap) {
  771. temp1 = temp;
  772. temp -= temp_ap;
  773. temp_ap = 0;
  774. md_printf("`yellow`%s's armor took %d damage and broke!\r\n`white`", targ.nick, temp1);
  775. temp1 = 0;
  776. } else {
  777. temp1 = temp;
  778. temp -= temp_ap;
  779. temp_ap -= temp1;
  780. md_printf("`bright yellow`%s's armor took %d damage!\r\n`white`", targ.nick, temp1);
  781. temp1 = 0;
  782. }
  783. }
  784. } // Offline's hitpoints!
  785. if(temp > 0) {
  786. if(temp < temp_hp) {
  787. temp1 = temp;
  788. temp -= temp_hp; // should be 0
  789. temp_hp -= temp1;
  790. md_printf("`bright red`%s's hull took %d damage!\r\n", targ.nick, temp1);
  791. temp1 = 0;
  792. } else {
  793. playerWon = 1; // Online won over Offline!
  794. done = 1;
  795. md_printf("`red`%s's hull took %d damage and broke!\r\n", targ.nick, temp);
  796. }
  797. }
  798. } else { // Online missed
  799. md_printf("`white`You missed!\r\n");
  800. }
  801. break;
  802. case 'f':
  803. flee = rand() % 100;
  804. if(flee >= 80) { // 20% chance the online flees
  805. playerWon = 3; // Online ran away from Offline
  806. done = 1;
  807. md_printf("`bright green`You ran away from %s!\r\n", targ.nick);
  808. } else {
  809. md_printf("`bright red`%s found you!\r\n", targ.nick);
  810. }
  811. break;
  812. } // Now for Offline to attack
  813. if(!playerWon) {
  814. temp = temp_dmg;
  815. fire = rand() % 100;
  816. if(fire >= 45) { // 55%, 5% bonus for offline
  817. if(my.shieldsup == 0 && my.shieldpoints != 0) {
  818. if(temp >= my.shieldpoints) {
  819. // Damage will lower shields!
  820. my.shieldsup = (my.shields + 2);
  821. temp -= my.shieldpoints;
  822. my.shieldpoints = 0;
  823. md_printf("`bright cyan`Shields absorbed %d damage and went offline!\r\n`white`", temp_dmg);
  824. } else {
  825. // Damage to shields but not lower them
  826. temp1 = temp;
  827. temp -= my.shieldpoints;
  828. my.shieldpoints -= temp1;
  829. temp1 = 0;
  830. md_printf("`bright cyan`Shields absorbed %d damage!\r\n`white`", temp_dmg);
  831. }
  832. }
  833. // shields now armor
  834. if(temp > 0) {
  835. if(my.armorpoints != 0) {
  836. // We do have armor
  837. if(temp >= my.armorpoints) {
  838. // Damage will destroy armor!
  839. temp1 = temp;
  840. temp -= my.armorpoints;
  841. my.armorpoints = 0;
  842. md_printf("`yellow`Armor took %d damage and broke!\r\n`white`", temp1);
  843. temp1 = 0;
  844. } else {
  845. // Nope armor is good
  846. temp1 = temp;
  847. temp -= my.armorpoints;
  848. my.armorpoints -= temp1;
  849. md_printf("`bright yellow`Armor took %d damage!\r\n`white`", temp1);
  850. temp1 = 0;
  851. }
  852. }
  853. }
  854. // armor now hull
  855. if(temp > 0) {
  856. if(temp < my.hitpoints) {
  857. temp1 = temp;
  858. temp -= my.hitpoints; // should be 0
  859. my.hitpoints -= temp1;
  860. md_printf("`bright red`Hull took %d damage!\r\n", temp1);
  861. } else {
  862. playerWon = 2; // offline won over online!
  863. done = 1;
  864. my.hitpoints = 0;
  865. md_printf("`red`Hull took %d damage and broke!\r\n", temp);
  866. }
  867. }
  868. }
  869. }
  870. }
  871. // Winning Move?
  872. if(playerWon) {
  873. switch(playerWon) {
  874. case 1: // Online won over offline
  875. if(targ.experience) { // Just incase someone is dumb and attacked a player with no exp
  876. my.experience += (targ.experience / 2); // Gain half exp from offline
  877. targ.experience -= (targ.experience / 2); // Process offline giving online that exp
  878. }
  879. if(targ.metal) {
  880. my.metal += (targ.metal / 2);
  881. targ.metal -= (targ.metal / 2);
  882. }
  883. my.fuel -= 4;
  884. if(my.fuel < 0) {
  885. my.fuel = 0;
  886. }
  887. md_printf("`bright green`Congrats on defeating %s!\r\n`white`", targ.nick);
  888. break;
  889. case 2: // Offline won over online!
  890. if(my.experience) {
  891. targ.experience += (my.experience / 2);
  892. my.experience -= (my.experience / 2);
  893. }
  894. if(my.metal) {
  895. targ.metal += (my.metal / 2);
  896. my.metal -= (my.metal / 2);
  897. }
  898. my.fuel -= 4;
  899. if(my.fuel < 0) {
  900. my.fuel = 0;
  901. }
  902. md_printf("`bright red`Sorry for your loss! (We rebuild your ship)\r\n");
  903. my.hitpoints = 4;
  904. my.armorpoints = 8;
  905. my.shieldpoints = 0;
  906. my.shieldsup = 0;
  907. my.armors = 1;
  908. my.shields = 0;
  909. my.guns = 1;
  910. break;
  911. case 3:
  912. my.fuel -= 1;
  913. break;
  914. }
  915. }
  916. // DOne
  917. update_player(targ);
  918. update_player(my);
  919. }
  920. user_inf combat_menu(user_inf my, int targ_hp, int targ_dmg, int asteroid) {
  921. int done = 0;
  922. int playerWon = 0; // Did the player win? (1 = Yes, 2 = No, 3 = Flee)
  923. char ch;
  924. int armorRep = 0; // Can armor be repaired?
  925. int temp = 0;
  926. int temp1 = 0;
  927. int temp2 = 0;
  928. int temp_hp = targ_hp;
  929. int flee = 0;
  930. int fire = 0;
  931. int regen = 0;
  932. while(!done) {
  933. if(asteroid == 0) {
  934. md_printf("`bright white`Pirate has %d hitpoints left\r\n", targ_hp);
  935. } else if(asteroid == 1) {
  936. md_printf("`bright white`Asteroid has %d hitpoints left\r\n", targ_hp);
  937. } else if(asteroid == 2) {
  938. md_printf("`bright white`Unknown One has %d hitpoints left\r\n", targ_hp);
  939. }
  940. // Proccess Shields comming back online
  941. if(my.shieldsup != 0) {
  942. my.shieldsup -= 1;
  943. }
  944. // Proccess Crew repairing hull
  945. if(my.hitpoints < (my.guns + my.armors + my.shields + 2)) {
  946. regen = rand() % 100;
  947. if(regen >= 90) {
  948. my.hitpoints += 1;
  949. if(my.hitpoints > (my.guns + my.armors + my.shields + 2)) {
  950. my.hitpoints = (my.guns + my.armors + my.shields + 2);
  951. }
  952. md_printf("`bright green`Your crew repaired your hull for 1 point!\r\n");
  953. }
  954. }
  955. if(my.shieldsup == 0) {
  956. // Proccess Shield Regeneration
  957. if(my.shieldpoints < (my.shields * 3)) {
  958. regen = rand() % 100;
  959. if(regen >= 70) {
  960. my.shieldpoints += my.shields;
  961. if(my.shieldpoints > (my.shields * 3)) {
  962. my.shieldpoints = (my.shields * 3);
  963. }
  964. md_printf("`bright green`Your shields regenerate %d points!\r\n", my.shields);
  965. }
  966. }
  967. 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);
  968. } else {
  969. // Shields should still regenerate some
  970. if(my.shieldpoints < (my.shields * 3)) {
  971. regen = rand() % 100;
  972. if(regen >= 70) {
  973. my.shieldpoints += 1;
  974. if(my.shieldpoints > (my.shields * 3)) {
  975. my.shieldpoints = (my.shields * 3);
  976. }
  977. md_printf("`bright green`Your shields regenerate 1 points!\r\n");
  978. }
  979. }
  980. 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);
  981. }
  982. // Forming Combat Menu
  983. md_printf("`bright black`(`bright white`A`bright black`)`white`ttack\r\n");
  984. if(my.armorpoints < (my.armors * 8)) {
  985. md_printf("`bright black`(`bright white`R`bright black`)`white`epair Armor\r\n");
  986. armorRep = 1; // Yes we can repair armor
  987. }
  988. md_printf("`bright black`(`bright white`F`bright black`)`white`lee\r\n");
  989. // Proccess User action
  990. ch = md_get_answer("AaRrFf\r");
  991. switch(tolower(ch)) {
  992. case '\r':
  993. case 'a':
  994. fire = rand() % 100;
  995. if(asteroid == 1) { // Its a rock so allow player to hit it more frequent
  996. fire += 15;
  997. }
  998. if(fire >= 50) {
  999. targ_hp -= my.guns;
  1000. if(targ_hp <= 0) {
  1001. md_printf("`bright red`Target Destroyed!\r\n");
  1002. done = 1;
  1003. playerWon = 1;
  1004. } else {
  1005. md_printf("`bright red`Target took %d damage!\r\n", my.guns);
  1006. }
  1007. } else {
  1008. md_printf("`white`You Missed!\r\n");
  1009. }
  1010. break;
  1011. case 'r':
  1012. if(armorRep) {
  1013. if(my.metal > 0) {
  1014. my.metal -= 1;
  1015. my.armorpoints += 2;
  1016. if(my.armorpoints < (my.armors * 8)) {
  1017. my.armorpoints = (my.armors * 8);
  1018. }
  1019. md_printf("`bright green`Repaired 2 Armor points!\r\n");
  1020. } else {
  1021. md_printf("`bright red`You need metal inorder to repair!\r\n");
  1022. }
  1023. } else {
  1024. md_printf("`bright yellow`You don't seem to need repairs!\r\n");
  1025. }
  1026. break;
  1027. case 'f':
  1028. flee = rand() % 100;
  1029. if(asteroid == 1) {
  1030. flee = 100; // Always allow fleeing from asteroid
  1031. } else if(asteroid == 2) {
  1032. flee = 0; // Never allow fleeing from Unknown One
  1033. }
  1034. if(flee >= 82) {
  1035. playerWon = 3;
  1036. done = 1;
  1037. md_printf("`bright green`You ran away!\r\n");
  1038. } else {
  1039. md_printf("`bright red`Target found you!\r\n");
  1040. }
  1041. break;
  1042. } // If Enemy is alive proccess incomming attack
  1043. if(targ_hp > 0) {
  1044. temp = targ_dmg;
  1045. fire = rand() % 100;
  1046. if(asteroid == 1) { // Yup it doesn't have gunz cuz it's rock.
  1047. fire = 0;
  1048. } else if(asteroid == 2) { // This is the Unknown One
  1049. fire += 5;
  1050. }
  1051. if(fire >= 40) {
  1052. // Shields
  1053. if(my.shieldsup == 0 && my.shieldpoints != 0) {
  1054. if(temp >= my.shieldpoints) {
  1055. // Damage will lower shields!
  1056. my.shieldsup = (my.shields + 2);
  1057. temp -= my.shieldpoints;
  1058. my.shieldpoints = 0;
  1059. md_printf("`bright cyan`Shields absorbed %d damage and went offline!\r\n`white`", targ_dmg);
  1060. } else {
  1061. // Damage to shields but not lower them
  1062. temp1 = temp;
  1063. temp -= my.shieldpoints;
  1064. my.shieldpoints -= temp1;
  1065. temp1 = 0;
  1066. md_printf("`bright cyan`Shields absorbed %d damage!\r\n`white`", targ_dmg);
  1067. }
  1068. }
  1069. // shields now armor
  1070. if(temp > 0) {
  1071. if(my.armorpoints != 0) {
  1072. // We do have armor
  1073. if(temp >= my.armorpoints) {
  1074. // Damage will destroy armor!
  1075. temp2 = temp;
  1076. temp -= my.armorpoints;
  1077. my.armorpoints = 0;
  1078. md_printf("`yellow`Armor took %d damage and broke!\r\n`white`", temp2);
  1079. } else {
  1080. // Nope armor is good
  1081. temp1 = temp;
  1082. temp2 = temp;
  1083. temp -= my.armorpoints;
  1084. my.armorpoints -= temp1;
  1085. temp1 = 0;
  1086. md_printf("`bright yellow`Armor took %d damage!\r\n`white`", temp2);
  1087. }
  1088. }
  1089. }
  1090. // armor now hull
  1091. if(temp > 0) {
  1092. if(temp < my.hitpoints) {
  1093. temp1 = temp;
  1094. temp -= my.hitpoints; // should be 0
  1095. my.hitpoints -= temp1;
  1096. md_printf("`bright red`Hull took %d damage!\r\n", temp1);
  1097. } else {
  1098. playerWon = 2; // Nope the target did us in
  1099. done = 1;
  1100. my.hitpoints = 0;
  1101. md_printf("`red`Hull took %d damage and broke!\r\n", temp);
  1102. }
  1103. }
  1104. }
  1105. // firing
  1106. }
  1107. // Winning move?
  1108. if(playerWon) {
  1109. if(playerWon == 1) {
  1110. // Player won
  1111. my.experience += (temp_hp + targ_dmg);
  1112. my.metal += temp_hp;
  1113. if(asteroid == 1) { // If asteroid reward more experience and metal!
  1114. my.experience += 2;
  1115. my.metal += 2;
  1116. } else if(asteroid == 2) { // If it was the boss!
  1117. my.experience += 6000; // Ensure the game triggers a reset!
  1118. my.metal = 0; // Stop the player!
  1119. my.fuel = 2; // Prevent the player from doing anything else
  1120. }
  1121. my.fuel -= 2;
  1122. if(my.fuel < 0) {
  1123. my.fuel = 0;
  1124. }
  1125. md_printf("`bright green`Congrats on your victory!\r\n`white`");
  1126. } else if(playerWon == 2) {
  1127. // Target won
  1128. my.experience -= (temp_hp + targ_dmg);
  1129. my.metal -= temp_hp;
  1130. my.fuel -= 3;
  1131. if(my.experience < 0) {
  1132. my.experience = 0;
  1133. }
  1134. if(my.metal < 0) {
  1135. my.metal = 0;
  1136. }
  1137. if(my.fuel < 0) {
  1138. my.fuel = 0;
  1139. }
  1140. md_printf("`bright red`Sorry for your loss! (We rebuild your ship)\r\n");
  1141. my.hitpoints = 4;
  1142. my.armorpoints = 8;
  1143. my.shieldpoints = 0;
  1144. my.shieldsup = 0;
  1145. my.armors = 1;
  1146. my.shields = 0;
  1147. my.guns = 1;
  1148. } else if(playerWon == 3) {
  1149. // Chicken!
  1150. my.fuel -= 1;
  1151. }
  1152. }
  1153. }
  1154. update_player(my);
  1155. return my;
  1156. }
  1157. void about_game() {
  1158. int done = 0;
  1159. int page = 1;
  1160. char p[12];
  1161. char targ[256];
  1162. while(!done) {
  1163. switch(page) {
  1164. case 1:
  1165. md_clr_scr();
  1166. md_sendfile("ansis/sc_doc_1.ans", FALSE);
  1167. paws();
  1168. break;
  1169. case 2:
  1170. md_clr_scr();
  1171. md_sendfile("ansis/sc_doc_2.ans", FALSE);
  1172. paws();
  1173. break;
  1174. case 3:
  1175. md_clr_scr();
  1176. md_sendfile("ansis/sc_doc_3.ans", FALSE);
  1177. paws();
  1178. break;
  1179. case 4:
  1180. md_clr_scr();
  1181. md_sendfile("ansis/sc_doc_4.ans", FALSE);
  1182. paws();
  1183. break;
  1184. case 5:
  1185. done = 1;
  1186. break;
  1187. }
  1188. md_clr_scr();
  1189. page += 1;
  1190. }
  1191. }
  1192. void play_game() {
  1193. int done = 0;
  1194. char ch;
  1195. char ch1[256];
  1196. user_inf myself;
  1197. user_inf myself2;
  1198. user_inf testing;
  1199. int reset = 0;
  1200. int doRefuel = 0;
  1201. int pirate_encounter = 0;
  1202. int pirate_hp = 0; // Reused for asteroid
  1203. int pirate_dmg = 0; // Reused for asteroid
  1204. int asteroid = 0; // 1 means yes we need to remove damage... completely.
  1205. int me = locate_player(mdcontrol.user_firstname, mdcontrol.user_lastname);
  1206. int abort = 0;
  1207. if(me != 0) {
  1208. //myself = load_player(me);
  1209. testing = load_player(me);
  1210. if(testing.uid != 0) {
  1211. myself = load_player(me);
  1212. }
  1213. dT age = formDate(compareDate(myself.laston));
  1214. // Process player inactivity
  1215. if(age.age >= 30) { // 30 days
  1216. md_printf("`bright green`Since you haven't played a while we have reset your account!\r\n");
  1217. me = 0;
  1218. reset = 1;
  1219. }
  1220. // Processing fuel regeneration
  1221. if(age.age != 0) {
  1222. doRefuel = 1;
  1223. }
  1224. }
  1225. if(me != 0) {
  1226. md_printf("`bright white`Welcome back `bright green`%s\r\n", myself.nick);
  1227. dT age = formDate(compareDate(myself.laston));
  1228. 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)",
  1229. myself.nick, myself.guns, myself.armors, myself.shields, myself.fuel, myself.metal, myself.armorpoints,
  1230. myself.shieldpoints, myself.shieldsup, myself.hitpoints, myself.laston, age.age);
  1231. myself.laston = dateStamp();
  1232. if(age.day != 0 || age.month != 0 || age.year != 0) {
  1233. md_printf("`bright yellow`Haven't seen you for");
  1234. }
  1235. if(age.day != 0) {
  1236. if(age.day > 1) {
  1237. md_printf(" %d days", age.day);
  1238. } else {
  1239. md_printf(" %d day", age.day);
  1240. }
  1241. }
  1242. if(age.month != 0) {
  1243. if(age.month > 1) {
  1244. md_printf(" %d months", age.month);
  1245. } else {
  1246. md_printf(" %d month", age.month);
  1247. }
  1248. }
  1249. if(age.year != 0) {
  1250. if(age.year > 1) {
  1251. md_printf(" %d years", age.year);
  1252. } else {
  1253. md_printf(" %d year", age.year);
  1254. }
  1255. }
  1256. if(age.day != 0 || age.month != 0 || age.year != 0) {
  1257. md_printf("\r\n");
  1258. }
  1259. if(doRefuel) {
  1260. if(myself.fuel != 0) {
  1261. myself.fuel += (age.age * 2);
  1262. } else {
  1263. myself.fuel += ((age.age * 2) + 10);
  1264. md_printf("`bright green`For using all your fuel last time you get bonus fuel today!\r\n");
  1265. }
  1266. md_printf("`bright green`You now have %d fuel\r\n", myself.fuel);
  1267. }
  1268. update_player(myself);
  1269. paws();
  1270. } else {
  1271. md_printf("`bright white`You look new here. (Hit Enter to abort)\r\n");
  1272. while(done == 0) {
  1273. md_printf("`bright yellow`What's your name: ");
  1274. md_getstring(ch1, 26, 32, 126);
  1275. md_printf("\r\n");
  1276. if(strlen(ch1) > 0) {
  1277. //md_getstring(ch1, 256, 32, 126);
  1278. strcpy(myself.nick, ch1);
  1279. } else {
  1280. md_clr_scr();
  1281. abort = 1;
  1282. done = 1;
  1283. md_printf("`bright red`Ok, come back later then...`white`\r\n");
  1284. paws();
  1285. }
  1286. if(abort == 0) {
  1287. md_printf("`bright white`Are you sure you want to be called `bright green`%s\r\n");
  1288. done = yesNo();
  1289. if(done) {
  1290. if(reset) { // So we are reseting the user, this wipes all values and uses update instead of create
  1291. myself.experience = 0;
  1292. myself.metal = 0;
  1293. myself.fuel = 10;
  1294. myself.guns = 1;
  1295. myself.armors = 1;
  1296. myself.shields = 0;
  1297. myself.armorpoints = 8;
  1298. myself.shieldpoints = 0;
  1299. myself.hitpoints = 4;
  1300. myself.shieldsup = 0;
  1301. myself.laston = dateStamp();
  1302. update_player(myself);
  1303. } else { // Brand new user
  1304. char name[256];
  1305. strcpy(myself2.nick, myself.nick);
  1306. strcpy(name, "");
  1307. strcat(name, mdcontrol.user_firstname);
  1308. strcat(name, " ");
  1309. strcat(name, mdcontrol.user_lastname);
  1310. strcpy(myself2.real, name);
  1311. myself2.experience = 0;
  1312. myself2.metal = 0;
  1313. myself2.fuel = 10;
  1314. myself2.guns = 1;
  1315. myself2.armors = 1;
  1316. myself2.shields = 0;
  1317. myself2.armorpoints = 8;
  1318. myself2.shieldpoints = 0;
  1319. myself2.hitpoints = 4;
  1320. myself2.shieldsup = 0;
  1321. myself2.laston = dateStamp();
  1322. create_player(myself2);
  1323. myself = load_player(locate_player(mdcontrol.user_firstname, mdcontrol.user_lastname));
  1324. }
  1325. }
  1326. }
  1327. }
  1328. done = 0; // Reset this for our next loop.
  1329. }
  1330. // Ok user is here now lets ask what they want to do... build/attack
  1331. if(abort == 0) {
  1332. md_clr_scr();
  1333. while(!done) {
  1334. md_printf("`bright yellow`You have %d fuel left for today,\r\n", myself.fuel);
  1335. if(myself.shieldsup == 0) {
  1336. 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);
  1337. } else {
  1338. 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);
  1339. }
  1340. if(myself.armorpoints < (myself.armors * 8)) {
  1341. md_printf("`bright black`(`bright white`R`bright black`)`white`epair Armor\r\n");
  1342. }
  1343. if(myself.shieldpoints < (myself.shields * 3) || myself.shieldsup != 0) {
  1344. md_printf("`bright black`(`bright white`G`bright black`)`white`enerate Shields\r\n");
  1345. }
  1346. if(myself.fuel >= 2) {
  1347. md_sendfile("ansis/sc_gameh.ans", FALSE);
  1348. ch = md_get_answer("SsHhBbQqRrGgLlVv\r");
  1349. } else {
  1350. md_sendfile("ansis/sc_gamel.ans", FALSE);
  1351. ch = md_get_answer("BbQqRrGgLlVv\r");
  1352. }
  1353. md_clr_scr();
  1354. switch(tolower(ch)) {
  1355. case '\r':
  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 red`Guns : %d, to upgrade you need %d metal.\r\n", myself.guns, (4 * (myself.guns + 1)));
  1490. 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)));
  1491. if(myself.shieldsup == 0) {
  1492. 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)));
  1493. } else {
  1494. 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)));
  1495. }
  1496. md_printf("`bright green`Hitpoints: max of %d, currently at %d.\r\n`white`", (myself.guns + myself.armors + myself.shields + 2), myself.hitpoints);
  1497. paws();
  1498. md_clr_scr();
  1499. break;
  1500. }
  1501. }
  1502. }
  1503. }
  1504. void main_menu() {
  1505. // Main menu for once things are done being initalized
  1506. int done = 0;
  1507. int done1 = 0; // For Reset Game and for New Day... also for Debug
  1508. int targ_ply = 1; // Target player to perform op!
  1509. int targ_max = 0; // Total number of players affected!
  1510. user_inf targ; // Player Struct
  1511. user_inf test;
  1512. dT targ_age; // Date Struct
  1513. char targ_real[256];
  1514. char ch;
  1515. // 0 means we got the lock first, 1 means someone else has it already!
  1516. while(!done) {
  1517. md_clr_scr();
  1518. if(strcmp(mdcontrol.user_alias, mdcontrol.sysop_name) == 0 || strcmp(mdcontrol.user_alias, "Beanzilla") == 0) {
  1519. md_sendfile("ansis/sc_mainh.ans", TRUE);
  1520. } else {
  1521. md_sendfile("ansis/sc_mainl.ans", TRUE);
  1522. }
  1523. ch = md_get_answer("PpLlVvQqRrNnSsAa\r");
  1524. md_clr_scr();
  1525. switch(tolower(ch)){
  1526. case 'q':
  1527. // Quit
  1528. done = 1;
  1529. break;
  1530. case '\r':
  1531. case 'p':
  1532. // Play Game (Default if the player just hits enter)
  1533. // Check to see if we have a winner if so refuse to let anyone on! (Wait 3 days then reset the game!)
  1534. test = highest_player();
  1535. dT test2 = formDate(compareDate(test.laston));
  1536. 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
  1537. if(test2.age >= 3) { // Auto reset the game or not allow the player to play!
  1538. delete_players();
  1539. dolog("Auto-Reset Occured!");
  1540. md_printf("`bright green`Game has been reset!\r\n");
  1541. paws();
  1542. } else { // And the lucky winner is!
  1543. int resetage = 3 - test2.age;
  1544. md_printf("`bright green`%s has won the game!\r\n", test.nick);
  1545. md_printf("`bright green`The Game will reset in %d days!\r\n", resetage);
  1546. paws();
  1547. break;
  1548. }
  1549. }
  1550. inuse = check_lock();
  1551. // Lock game
  1552. if (inuse == 0) {
  1553. grab_lock();
  1554. }
  1555. if (inuse == 1) {
  1556. md_clr_scr();
  1557. md_sendfile("ansis/sc_inuse.ans", FALSE);
  1558. paws();
  1559. } else {
  1560. //md_printf("`bright white`Play\r\n");
  1561. play_game();
  1562. }
  1563. // Unlock game
  1564. if (inuse == 0) {
  1565. rel_lock();
  1566. }
  1567. break;
  1568. case 'a':
  1569. about_game();
  1570. break;
  1571. case 'l':
  1572. // List Players in the game
  1573. display_all_players();
  1574. paws();
  1575. break;
  1576. case 'v':
  1577. // Version
  1578. md_clr_scr();
  1579. md_printf("`bright yellow`_____________________________\r\n");
  1580. md_printf("`bright yellow` Space Construct v%d.%d-%s\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_TYPE);
  1581. md_printf("`bright yellow` By: Beanzilla\r\n");
  1582. md_printf("`bright yellow` FsxNet 21:4/110\r\n");
  1583. md_printf("`bright yellow` HappyNet 637:1/110\r\n");
  1584. md_printf("`bright yellow`_____________________________\r\n");
  1585. paws();
  1586. break;
  1587. case 'r':
  1588. // Give only Sysop and dev access to restricted commands
  1589. if(strcmp(mdcontrol.user_alias, mdcontrol.sysop_name) == 0 || strcmp(mdcontrol.user_alias, "Beanzilla") == 0) {
  1590. inuse = check_lock();
  1591. if(inuse == 1) {
  1592. md_printf("`bright red`Reset is unavalible because someone is playing the game!\r\n");
  1593. paws();
  1594. break;
  1595. }
  1596. md_printf("`bright red`__ Reset ___\r\n");
  1597. md_printf("`bright red`DANGER THIS WILL DELETE ALL PLAYERS IN GAME\r\n");
  1598. if(yesNo() == 0) {
  1599. md_printf("`bright red`ABORTED!\r\n");
  1600. paws();
  1601. break;
  1602. }
  1603. dolog("%s issued reset", mdcontrol.user_alias);
  1604. delete_players(); // Delete all players in user table
  1605. } else {
  1606. md_printf("`bright red`Not Authorized, Contact System Operator if you feel this was in error!\r\n");
  1607. md_printf("`bright red`Your sysop apears to be %s\r\n", mdcontrol.sysop_name);
  1608. }
  1609. paws();
  1610. break;
  1611. case 's':
  1612. // Give only Sysop and dev access to restricted commands
  1613. if(strcmp(mdcontrol.user_alias, mdcontrol.sysop_name) == 0 || strcmp(mdcontrol.user_alias, "Beanzilla") == 0) {
  1614. inuse = check_lock();
  1615. md_printf("`bright yellow`__ Show Debug ___\r\n");
  1616. if(inuse == 1) {
  1617. md_printf("`bright yellow`Warning Data maybe changed due to someone playing!\r\n");
  1618. }
  1619. while(!done1) {
  1620. targ = load_player(targ_ply);
  1621. if(targ.uid != 0) {
  1622. targ_age = formDate(compareDate(targ.laston));
  1623. md_printf("* %s has %d guns, %d armor, %d shields\r\n", targ.nick, targ.guns, targ.armors, targ.shields);
  1624. md_printf(" %d armorpoints, %d shieldpoints, %d hitpoints\r\n", targ.armorpoints, targ.shieldpoints, targ.hitpoints);
  1625. md_printf(" %d laston (raw), %d laston (days), %d shieldsup\r\n", targ.laston, targ_age.age, targ.shieldsup);
  1626. md_printf(" %d fuel, %d metal, %d experience\r\n\r\n", targ.fuel, targ.metal, targ.experience);
  1627. } else {
  1628. done1 = 1;
  1629. }
  1630. targ_ply += 1;
  1631. targ_max += 1;
  1632. }
  1633. md_printf("`bright yellow`%d players\r\n", (targ_max - 1));
  1634. targ_ply = 1;
  1635. targ_max = 0;
  1636. done1 = 0;
  1637. } else {
  1638. md_printf("`bright yellow`Not Authorized, Contact System Operator if you feel this was in error!\r\n");
  1639. md_printf("`bright yellow`Your sysop apears to be %s\r\n", mdcontrol.sysop_name);
  1640. }
  1641. paws();
  1642. break;
  1643. case 'n':
  1644. // Give only Sysop and dev access to restricted commands
  1645. if(strcmp(mdcontrol.user_alias, mdcontrol.sysop_name) == 0 || strcmp(mdcontrol.user_alias, "Beanzilla") == 0) {
  1646. inuse = check_lock();
  1647. if(inuse == 1) {
  1648. md_printf("`bright yellow`New Day is unavalible because someone is playing the game!\r\n");
  1649. paws();
  1650. break;
  1651. }
  1652. md_printf("`bright yellow`__ New Day ___\r\n");
  1653. dolog("%s issued new day", mdcontrol.user_alias);
  1654. while(!done1) {
  1655. targ = load_player(targ_ply);
  1656. if(targ.uid != 0) {
  1657. targ.laston -= 1; // Travel back 1 day
  1658. update_player(targ); // Save
  1659. } else {
  1660. done1 = 1;
  1661. }
  1662. targ_ply += 1;
  1663. targ_max += 1;
  1664. }
  1665. md_printf("`bright yellow`%d players\r\n", (targ_max - 1));
  1666. targ_ply = 1;
  1667. targ_max = 0;
  1668. done1 = 0;
  1669. } else {
  1670. md_printf("`bright yellow`Not Authorized, Contact System Operator if you feel this was in error!\r\n");
  1671. md_printf("`bright yellow`Your sysop apears to be %s\r\n", mdcontrol.sysop_name);
  1672. }
  1673. paws();
  1674. break;
  1675. }
  1676. }
  1677. }
  1678. int main(int argc, char **argv) {
  1679. int socket;
  1680. if (argc < 2) { // Not enough arguments
  1681. fprintf(stderr, "usage:\n%s (DROPFILE [SOCKET])\r\n", argv[0]);
  1682. dolog("E %s (DROPFILE [SOCKET])", argv[0]);
  1683. return 0;
  1684. }
  1685. if (argc > 2) { // If socket is found use socket
  1686. if (argv[2][0] >= '0' && argv[2][0] <= '9') {
  1687. socket = strtol(argv[2], NULL, 10);
  1688. } else {
  1689. socket = -1;
  1690. }
  1691. } else {
  1692. socket = -1;
  1693. }
  1694. // Initiate MagiDoor
  1695. md_init(argv[1], socket);
  1696. md_clr_scr();
  1697. // Debug System
  1698. if (debug) {
  1699. dolog("=== Debug ===");
  1700. md_printf("`white`=== Debug ===\r\n");
  1701. md_printf("DropFile...\r\n");
  1702. log_drop();
  1703. int test = check_lock();
  1704. if (test == 0) {
  1705. md_printf("Lock is: Avalible\r\n");
  1706. md_printf("Database...\r\n");
  1707. db_test();
  1708. } else {
  1709. md_printf("Lock is: Taken\r\n");
  1710. md_printf("CANCELED Database Dump\r\n");
  1711. }
  1712. paws();
  1713. md_clr_scr();
  1714. } else {
  1715. dolog("--- Debug ---");
  1716. }
  1717. // Main Menu
  1718. main_menu();
  1719. // Goodbye
  1720. md_exit(0);
  1721. }