main.c 58 KB

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