main.c 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761
  1. /*
  2. Space Construct v0.6-dev
  3. Beanzilla@21:4/110 on FsxNet
  4. Beanzilla@637:1/110 on HappyNet
  5. */
  6. #define VERSION_MAJOR 0
  7. #define VERSION_MINOR 6
  8. #ifndef VERSION_TYPE
  9. #define VERSION_TYPE "dev"
  10. #endif
  11. #define PATH_MAX 256
  12. #define PATH_SEP "/"
  13. //#include <MagiDoor.h> // 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 guns; // 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 armors; // Placed Armors (Each Armor takes 4 points of damage then breaks off)
  51. 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)
  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, guns
  164. sqlite3_column_int(stmt, 6),
  165. sqlite3_column_name(stmt, 7), // int, armors
  166. sqlite3_column_int(stmt, 7),
  167. sqlite3_column_name(stmt, 8), // int, shields
  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,`guns` INTEGER,`armors` INTEGER,`shields` 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.guns = sqlite3_column_int(stmt, 6);
  345. result.armors = sqlite3_column_int(stmt, 7);
  346. result.shields = 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=?, guns=?, armors=?, shields=?, 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.guns);
  408. sqlite3_bind_int(stmt, 6, data.armors);
  409. sqlite3_bind_int(stmt, 7, data.shields);
  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, guns, armors, shields, 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.guns);
  446. sqlite3_bind_int(stmt, 7, data.armors);
  447. sqlite3_bind_int(stmt, 8, data.shields);
  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
  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.guns + 1)));
  587. od_set_cursor(4, 15);
  588. od_printf("%5d", (3 * (my.armors + 1)));
  589. od_set_cursor(5, 15);
  590. od_printf("%5d", (6 * (my.shields + 1)));
  591. od_set_cursor(9, 0);
  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.guns + 1))) {
  598. my.metal -= (4 * (my.guns + 1));
  599. my.guns += 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.guns + 1)));
  605. paws();
  606. }
  607. break;
  608. case 'a':
  609. if(my.metal >= (3 * (my.armors + 1))) {
  610. my.metal -= (3 * (my.armors + 1));
  611. my.armors += 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.armors + 1)));
  618. paws();
  619. }
  620. break;
  621. case 's':
  622. if(my.metal >= (6 * (my.shields + 1))) {
  623. my.metal -= (6 * (my.shields + 1));
  624. my.shields += 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.shields + 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.shields + targ.armors + targ.guns + 2);
  673. int temp_ap = (targ.armors * 8);
  674. int temp_sp = (targ.shields * 3);
  675. int temp_su = 0;
  676. int temp_dmg = (targ.guns + 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.shields + targ.armors + targ.guns + 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.shields + my.armors + my.guns + 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.shields * 3)) {
  709. regen = rand() % 100;
  710. if(regen >= 65) { // 35%, offline bonus
  711. temp_sp += targ.shields;
  712. if(temp_sp > (targ.shields * 3)) {
  713. temp_sp = (targ.shields * 3);
  714. }
  715. od_printf("`bright green`%s`green`'s shields regenerate %d points!\r\n", targ.nick, targ.shields);
  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.shields * 3)) {
  721. regen = rand() % 100;
  722. if(regen >= 65) { // 35%, offline bonus
  723. temp_sp += 1;
  724. if(temp_sp > (targ.shields * 3)) {
  725. temp_sp = (targ.shields * 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.shields * 3)) {
  735. regen = rand() % 100;
  736. if(regen >= 70) { // 30%
  737. my.shieldpoints += my.shields;
  738. if(my.shieldpoints > (my.shields * 3)) {
  739. my.shieldpoints = (my.shields * 3);
  740. }
  741. od_printf("`bright green`Your shields regenerate %d points!\r\n", my.shields);
  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.shields * 3)) {
  747. regen = rand() % 100;
  748. if(regen >= 70) { // 30%
  749. my.shieldpoints += 1;
  750. if(my.shieldpoints > (my.shields * 3)) {
  751. my.shieldpoints = (my.shields * 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.guns;
  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.shields + 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.shields + 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.armors = 1;
  924. my.shields = 0;
  925. my.guns = 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.guns + my.armors + my.shields + 2)) {
  962. regen = rand() % 100;
  963. if(regen >= 90) {
  964. my.hitpoints += 1;
  965. if(my.hitpoints > (my.guns + my.armors + my.shields + 2)) {
  966. my.hitpoints = (my.guns + my.armors + my.shields + 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.shields * 3)) {
  974. regen = rand() % 100;
  975. if(regen >= 70) {
  976. my.shieldpoints += my.shields;
  977. if(my.shieldpoints > (my.shields * 3)) {
  978. my.shieldpoints = (my.shields * 3);
  979. }
  980. od_printf("`bright green`Your shields regenerate %d points!\r\n", my.shields);
  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.shields * 3)) {
  987. regen = rand() % 100;
  988. if(regen >= 70) {
  989. my.shieldpoints += 1;
  990. if(my.shieldpoints > (my.shields * 3)) {
  991. my.shieldpoints = (my.shields * 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.armors * 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.guns;
  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.guns);
  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.armors * 8)) {
  1033. my.armorpoints = (my.armors * 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.shields + 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.armors = 1;
  1162. my.shields = 0;
  1163. my.guns = 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. char p[12];
  1177. char targ[256];
  1178. while(!done) {
  1179. switch(page) {
  1180. case 1:
  1181. od_clr_scr();
  1182. od_send_file("ansis/sc_doc_1.ans");
  1183. paws();
  1184. break;
  1185. case 2:
  1186. od_clr_scr();
  1187. od_send_file("ansis/sc_doc_2.ans");
  1188. paws();
  1189. break;
  1190. case 3:
  1191. od_clr_scr();
  1192. od_send_file("ansis/sc_doc_3.ans");
  1193. paws();
  1194. break;
  1195. case 4:
  1196. od_clr_scr();
  1197. od_send_file("ansis/sc_doc_4.ans");
  1198. paws();
  1199. break;
  1200. case 5:
  1201. od_clr_scr();
  1202. od_send_file("ansis/sc_doc_5.ans");
  1203. paws();
  1204. break;
  1205. case 6:
  1206. done = 1;
  1207. break;
  1208. }
  1209. od_clr_scr();
  1210. page += 1;
  1211. }
  1212. }
  1213. void play_game() {
  1214. int done = 0;
  1215. char ch;
  1216. char ch1[256];
  1217. user_inf myself;
  1218. user_inf myself2;
  1219. user_inf testing;
  1220. int reset = 0;
  1221. int doRefuel = 0;
  1222. int pirate_encounter = 0;
  1223. int pirate_hp = 0; // Reused for asteroid
  1224. int pirate_dmg = 0; // Reused for asteroid
  1225. int asteroid = 0; // 1 means yes we need to remove damage... completely.
  1226. int me = locate_player(od_control.user_name);
  1227. int abort = 0;
  1228. if(me != 0) {
  1229. //myself = load_player(me);
  1230. testing = load_player(me);
  1231. if(testing.uid != 0) {
  1232. myself = load_player(me);
  1233. }
  1234. dT age = fromDate(compareDate(myself.laston));
  1235. // Process player inactivity
  1236. if(age.age >= 30) { // 30 days
  1237. od_printf("`bright green`Since you haven't played a while we have reset your account!\r\n");
  1238. me = 0;
  1239. reset = 1;
  1240. }
  1241. // Processing fuel regeneration
  1242. if(age.age != 0) {
  1243. doRefuel = 1;
  1244. }
  1245. }
  1246. if(me != 0) {
  1247. od_printf("`bright white`Welcome back `bright green`%s\r\n", myself.nick);
  1248. dT age = fromDate(compareDate(myself.laston));
  1249. 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)",
  1250. myself.nick, myself.guns, myself.armors, myself.shields, myself.fuel, myself.metal, myself.armorpoints,
  1251. myself.shieldpoints, myself.shieldsup, myself.hitpoints, myself.laston, age.age);
  1252. myself.laston = dateStamp();
  1253. if(age.day != 0 || age.month != 0 || age.year != 0) {
  1254. od_printf("`bright yellow`Haven't seen you for");
  1255. }
  1256. if(age.day != 0) {
  1257. if(age.day > 1) {
  1258. od_printf(" %d days", age.day);
  1259. } else {
  1260. od_printf(" %d day", age.day);
  1261. }
  1262. }
  1263. if(age.month != 0) {
  1264. if(age.month > 1) {
  1265. od_printf(" %d months", age.month);
  1266. } else {
  1267. od_printf(" %d month", age.month);
  1268. }
  1269. }
  1270. if(age.year != 0) {
  1271. if(age.year > 1) {
  1272. od_printf(" %d years", age.year);
  1273. } else {
  1274. od_printf(" %d year", age.year);
  1275. }
  1276. }
  1277. if(age.day != 0 || age.month != 0 || age.year != 0) {
  1278. od_printf("\r\n");
  1279. }
  1280. if(doRefuel) {
  1281. if(myself.fuel != 0) {
  1282. myself.fuel += (age.age * 2);
  1283. } else {
  1284. myself.fuel += ((age.age * 2) + 10);
  1285. od_printf("`bright green`For using all your fuel last time you get bonus fuel today!\r\n");
  1286. }
  1287. od_printf("`bright green`You now have %d fuel\r\n", myself.fuel);
  1288. }
  1289. update_player(myself);
  1290. paws();
  1291. } else {
  1292. od_printf("`bright white`You look new here. (Hit Enter to abort)\r\n");
  1293. while(done == 0) {
  1294. od_printf("`bright yellow`What's your name: ");
  1295. od_input_str(ch1, 26, 32, 126);
  1296. od_printf("\r\n");
  1297. if(strlen(ch1) > 0) {
  1298. //od_input_str(ch1, 256, 32, 126);
  1299. strcpy(myself.nick, ch1);
  1300. } else {
  1301. od_clr_scr();
  1302. abort = 1;
  1303. done = 1;
  1304. od_printf("`bright red`Ok, come back later then...`white`\r\n");
  1305. paws();
  1306. }
  1307. if(abort == 0) {
  1308. od_printf("`bright white`Are you sure you want to be called `bright green`%s\r\n");
  1309. done = yesNo();
  1310. if(done) {
  1311. if(reset) { // So we are reseting the user, this wipes all values and uses update instead of create
  1312. myself.experience = 0;
  1313. myself.metal = 0;
  1314. myself.fuel = 10;
  1315. myself.guns = 1;
  1316. myself.armors = 1;
  1317. myself.shields = 0;
  1318. myself.armorpoints = 8;
  1319. myself.shieldpoints = 0;
  1320. myself.hitpoints = 4;
  1321. myself.shieldsup = 0;
  1322. myself.laston = dateStamp();
  1323. update_player(myself);
  1324. } else { // Brand new user
  1325. char name[256];
  1326. strcpy(myself2.nick, myself.nick);
  1327. strcpy(myself2.real, od_control.user_name);
  1328. myself2.experience = 0;
  1329. myself2.metal = 0;
  1330. myself2.fuel = 10;
  1331. myself2.guns = 1;
  1332. myself2.armors = 1;
  1333. myself2.shields = 0;
  1334. myself2.armorpoints = 8;
  1335. myself2.shieldpoints = 0;
  1336. myself2.hitpoints = 4;
  1337. myself2.shieldsup = 0;
  1338. myself2.laston = dateStamp();
  1339. create_player(myself2);
  1340. myself = load_player(locate_player(od_control.user_name));
  1341. }
  1342. }
  1343. }
  1344. }
  1345. done = 0; // Reset this for our next loop.
  1346. }
  1347. // Ok user is here now lets ask what they want to do... build/attack
  1348. if(abort == 0) {
  1349. od_clr_scr();
  1350. while(!done) {
  1351. od_printf("`bright yellow`You have %d fuel left for today,\r\n", myself.fuel);
  1352. if(myself.shieldsup == 0) {
  1353. 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);
  1354. } else {
  1355. 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);
  1356. }
  1357. if(myself.armorpoints < (myself.armors * 8)) {
  1358. od_printf("`bright black`(`bright white`R`bright black`)`white`epair Armor\r\n");
  1359. }
  1360. if(myself.shieldpoints < (myself.shields * 3) || myself.shieldsup != 0) {
  1361. od_printf("`bright black`(`bright white`G`bright black`)`white`enerate Shields\r\n");
  1362. }
  1363. if(myself.fuel >= 2) {
  1364. od_send_file("ansis/sc_gameh.ans");
  1365. ch = od_get_answer("SsHhBbQqRrGgLlVv");
  1366. } else {
  1367. od_send_file("ansis/sc_gamel.ans");
  1368. ch = od_get_answer("BbQqRrGgLlVv");
  1369. }
  1370. od_clr_scr();
  1371. switch(tolower(ch)) {
  1372. case 's':
  1373. if(myself.fuel >= 2) {
  1374. pirate_encounter = rand() % 100;
  1375. if(pirate_encounter >= 75) { // 25% chance to encounter a Pirate, or Unknown One
  1376. if(myself.experience > 3000) {
  1377. if(pirate_encounter >= 95) { // 5% chance to encounter unknown one
  1378. od_printf("`bright yellow`You encounter the `bright red`Unknown One\r\n`white`");
  1379. asteroid = 2;
  1380. } else {
  1381. od_printf("`bright yellow`You encounter a `bright red`Pirate\r\n`white`");
  1382. asteroid = 0;
  1383. }
  1384. } else { // The player is not skilled enough to fight the unknown one
  1385. od_printf("`bright yellow`You encounter a `bright red`Pirate\r\n`white`");
  1386. asteroid = 0;
  1387. }
  1388. } else { // 75% chance to encounter a Asteroid
  1389. od_printf("`bright yellow`You encounter a `bright red`Asteroid\r\n`white`");
  1390. asteroid = 1;
  1391. }
  1392. if(asteroid == 0 || asteroid == 2) {
  1393. pirate_hp = ((myself.hitpoints + 1) + (rand() % 4));
  1394. if(asteroid == 2) { // Increase boss hitpoints
  1395. pirate_hp += 10;
  1396. }
  1397. // Increase difficulty based on experience...
  1398. pirate_dmg = (myself.experience / 500);
  1399. if(pirate_dmg == 0) { // Always deal damage
  1400. pirate_dmg = 1;
  1401. }
  1402. if(asteroid == 2) { // Increase boss damage
  1403. pirate_dmg += 2;
  1404. }
  1405. // Send off to combat menu
  1406. myself = combat_menu(myself, pirate_hp, pirate_dmg, asteroid);
  1407. } else {
  1408. pirate_hp = (myself.hitpoints + 1) + (rand() % 10);
  1409. // Send off to combat menu
  1410. myself = combat_menu(myself, pirate_hp, 0, asteroid);
  1411. }
  1412. }
  1413. break;
  1414. case 'h':
  1415. if(myself.fuel >= 4) {
  1416. int targs = display_all_opponents(myself.uid);
  1417. int targg = 1;
  1418. int done2 = 0;
  1419. if(targg == myself.uid) {
  1420. targg += 1;
  1421. }
  1422. while(!done2) {
  1423. od_printf("`bright red`Targetting: %d\r\n", targg);
  1424. if(yesNo()) {
  1425. done2 = 1;
  1426. } else if(targg < targs){
  1427. targg += 1;
  1428. } else {
  1429. done2 = 1;
  1430. od_printf("`bright red`ABORTED!\r\n");
  1431. break;
  1432. }
  1433. }
  1434. user_inf targ = load_player(targg);
  1435. if(targ.uid != 0) {
  1436. // I need to add some limits in here else someone could attack weaker players!
  1437. int proceed = 0;
  1438. int temp = targ.experience + 1000; // Prevent the person from selecting a player that is higher than them
  1439. int temp1 = targ.experience - 500; // Prevent the person from selecting a player that is lower than them
  1440. if(temp1 > 0) {
  1441. temp1 = 0;
  1442. }
  1443. if(temp > myself.experience && temp1 < myself.experience) {
  1444. proceed = 1;
  1445. }
  1446. if(proceed) {
  1447. pvp_menu(myself, targ);
  1448. } else {
  1449. od_printf("`bright white`Please select a opponent within your range of expertise!\r\n");
  1450. break;
  1451. }
  1452. }
  1453. } else {
  1454. od_printf("`bright white`You need 4 fuel to fight another player!\r\n`white`");
  1455. }
  1456. break;
  1457. case 'b':
  1458. if(myself.metal != 0) {
  1459. // Send off to build menu
  1460. od_clr_scr();
  1461. //od_send_file("ansis/sc_build.ans", FALSE);
  1462. myself = build_menu(myself);
  1463. } else {
  1464. od_printf("`bright white`I am sorry you have no metal go fight.`white`\r\n");
  1465. }
  1466. break;
  1467. case 'q':
  1468. done = 1;
  1469. break;
  1470. case 'r':
  1471. if(myself.armorpoints < (myself.armors * 8)) {
  1472. if(myself.metal > 0) {
  1473. myself.metal -= 1;
  1474. myself.armorpoints += 4;
  1475. if(myself.armorpoints > (myself.armors * 8)) {
  1476. myself.armorpoints = (myself.armors * 8);
  1477. }
  1478. update_player(myself);
  1479. od_printf("`bright green`Repaired 4 Armor Points!\r\n`white`");
  1480. } else {
  1481. od_printf("`bright red`You need metal inorder to repair!\r\n`white`");
  1482. }
  1483. } else {
  1484. od_printf("`bright yellow`You don't seem to need repairs!\r\n`white`");
  1485. }
  1486. break;
  1487. case 'g':
  1488. if(myself.shieldpoints < (myself.shields * 3) || myself.shieldsup != 0) {
  1489. myself.shieldpoints += myself.shields;
  1490. myself.shieldsup -= 1;
  1491. if(myself.shieldsup < 0) {
  1492. myself.shieldsup = 0;
  1493. }
  1494. if(myself.shieldpoints > (myself.shields * 3)) {
  1495. myself.shieldpoints = (myself.shields * 3);
  1496. }
  1497. update_player(myself);
  1498. od_printf("`bright green`Regenerated Shields!\r\n`white`");
  1499. } else {
  1500. od_printf("`bright yellow`You don't seem to need to regenerate shields!\r\n`white`");
  1501. }
  1502. break;
  1503. case 'v':
  1504. od_printf("`bright white` ___ %s's Ship Status ___\r\n", myself.nick);
  1505. od_printf("`bright white`Items: # Installed: Metal to Upgrade:\r\n");
  1506. od_printf("`bright red`Guns: %8d %8d\r\n", myself.guns, (4 * (myself.guns + 1)));
  1507. od_printf("`bright yellow`Armor: %8d %8d\r\n", myself.armors, (3 * (myself.armors + 1)));
  1508. od_printf("`bright cyan`Shields: %8d %8d\r\n", myself.shields, (6 * (myself.shields + 1)));
  1509. od_printf("`bright white`\r\n ___ Situation Report ___\r\n");
  1510. od_printf("`bright white`Items: Maximum: Current:\r\n");
  1511. od_printf("`bright green`Hitpoints: %8d %8d\r\n", (myself.guns + myself.armors + myself.shields + 2), myself.hitpoints);
  1512. od_printf("`bright yellow`Armor: %8d %8d\r\n", (myself.armors * 8), myself.armorpoints);
  1513. od_printf("`bright cyan`Shields: %8d %8d\r\n", (myself.shields * 3), myself.shieldpoints);
  1514. od_printf("`bright magenta`Experience: %8d\r\n", myself.experience);
  1515. od_printf("`bright magenta`Fuel: %8d\r\n", myself.fuel);
  1516. od_printf("`white`Metal: %8d\r\n", myself.metal);
  1517. paws();
  1518. od_clr_scr();
  1519. break;
  1520. }
  1521. }
  1522. }
  1523. }
  1524. void sysop_menu() {
  1525. int done = 0;
  1526. char ch;
  1527. int targ_ply = 1;
  1528. int targ_max = 0;
  1529. int done1 = 0;
  1530. user_inf targ;
  1531. while(!done) {
  1532. od_clr_scr();
  1533. od_send_file("ansis/sc_sysop.ans");
  1534. ch = od_get_answer("RrNnQq");
  1535. //od_printf("\r\n");
  1536. switch(tolower(ch)) {
  1537. case 'q':
  1538. done = 1;
  1539. break;
  1540. case 'r':
  1541. od_printf("`bright red`__ Reset ___\r\n");
  1542. od_printf("`bright red`DANGER THIS WILL DELETE ALL PLAYERS IN GAME\r\n");
  1543. if(yesNo() == 0) {
  1544. od_printf("`bright red`ABORTED!\r\n");
  1545. paws();
  1546. break;
  1547. }
  1548. dolog("%s issued reset", od_control.user_handle);
  1549. delete_players();
  1550. paws();
  1551. break;
  1552. case 'n':
  1553. od_printf("`bright red`__ New Day ___\r\n");
  1554. while(!done1) {
  1555. targ = load_player(targ_ply);
  1556. if(targ.uid != 0) {
  1557. targ.laston -= 1; // Travel back 1 day
  1558. update_player(targ); // Save
  1559. } else {
  1560. done1 = 1;
  1561. }
  1562. targ_ply += 1;
  1563. targ_max += 1;
  1564. }
  1565. od_printf("`bright red`%d players affected\r\n", (targ_max - 1));
  1566. targ_ply = 1;
  1567. targ_max = 0;
  1568. done1 = 0;
  1569. dolog("%s issued new day", od_control.user_handle);
  1570. paws();
  1571. break;
  1572. }
  1573. }
  1574. od_clr_scr();
  1575. }
  1576. void cleanMe() {
  1577. rel_lock();
  1578. od_exit(0, FALSE);
  1579. }
  1580. void main_menu() {
  1581. // Main menu for once things are done being initalized
  1582. int done = 0;
  1583. int done1 = 0; // For Reset Game and for New Day... also for Debug
  1584. int targ_ply = 1; // Target player to perform op!
  1585. int targ_max = 0; // Total number of players affected!
  1586. user_inf targ; // Player Struct
  1587. user_inf test;
  1588. dT targ_age; // Date Struct
  1589. char targ_real[256];
  1590. char ch;
  1591. int auth; // Security
  1592. char sys[48]; // Security
  1593. // 0 means we got the lock first, 1 means someone else has it already!
  1594. while(!done) {
  1595. od_clr_scr();
  1596. od_send_file("ansis/sc_main.ans");
  1597. ch = od_get_answer("PpLlVvQqSsAa");
  1598. od_clr_scr();
  1599. switch(tolower(ch)){
  1600. case 'q':
  1601. // Quit
  1602. done = 1;
  1603. break;
  1604. case 'p':
  1605. // Play Game (Default if the player just hits enter)
  1606. // Check to see if we have a winner if so refuse to let anyone on! (Wait 3 days then reset the game!)
  1607. test = highest_player();
  1608. dT test2 = fromDate(compareDate(test.laston));
  1609. 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
  1610. if(test2.age >= 3) { // Auto reset the game or not allow the player to play!
  1611. delete_players();
  1612. dolog("Auto-Reset Occured!");
  1613. od_printf("`bright green`Game has been reset!\r\n");
  1614. paws();
  1615. } else { // And the lucky winner is!
  1616. int resetage = 3 - test2.age;
  1617. od_printf("`bright green`%s has won the game!\r\n", test.nick);
  1618. od_printf("`bright green`The Game will reset in %d days!\r\n", resetage);
  1619. paws();
  1620. break;
  1621. }
  1622. }
  1623. play_game();
  1624. break;
  1625. case 'a':
  1626. about_game();
  1627. break;
  1628. case 'l':
  1629. // List Players in the game
  1630. display_all_players();
  1631. paws();
  1632. break;
  1633. case 'v':
  1634. // Version
  1635. od_clr_scr();
  1636. od_printf("`bright yellow`_____________________________\r\n");
  1637. od_printf("`bright yellow` Space Construct v%d.%d-%s\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_TYPE);
  1638. od_printf("`bright yellow` By: Beanzilla\r\n");
  1639. od_printf("`bright yellow` FsxNet 21:4/110\r\n");
  1640. od_printf("`bright yellow` HappyNet 637:1/110\r\n");
  1641. od_printf("`bright yellow`_____________________________\r\n");
  1642. paws();
  1643. break;
  1644. case 's':
  1645. auth = 0;
  1646. if(allowDev && strcmp(od_control.user_handle, "Beanzilla") == 0) {
  1647. od_printf("`bright green`Access Granted\r\n");
  1648. auth = 1;
  1649. } else {
  1650. od_printf("`bright red`Sysop Password: ");
  1651. strcpy(sys, "");
  1652. od_input_str(sys, 32, 32, 126);
  1653. od_clr_scr(); // Add a bit of protecton
  1654. if(strcmp(sys, sysop_pass) == 0) {
  1655. od_printf("`bright green`Access Granted\r\n");
  1656. auth = 1;
  1657. }
  1658. }
  1659. // Give only Sysop and dev access to restricted commands
  1660. if(auth) {
  1661. paws();
  1662. sysop_menu();
  1663. } else {
  1664. od_printf("`bright red`Access Denied\r\n");
  1665. paws();
  1666. }
  1667. break;
  1668. }
  1669. }
  1670. }
  1671. int main(int argc, char *argv[]) {
  1672. od_parse_cmd_line(argc, argv);
  1673. // Initiate Door
  1674. od_init();
  1675. od_clr_scr();
  1676. check_database(); // Ensure the users table exists.
  1677. // Debug System
  1678. if (debug) {
  1679. dolog("=== Debug ===");
  1680. od_printf("`white`=== Debug ===\r\n");
  1681. od_printf("DropFile...\r\n");
  1682. log_drop();
  1683. int test = check_lock();
  1684. if (test == 0) {
  1685. od_printf("Lock is: Avalible\r\n");
  1686. od_printf("Database...\r\n");
  1687. db_test();
  1688. } else {
  1689. od_printf("Lock is: Taken\r\n");
  1690. od_printf("CANCELED Database Dump\r\n");
  1691. }
  1692. paws();
  1693. od_clr_scr();
  1694. } else {
  1695. dolog("--- Debug ---");
  1696. }
  1697. inuse = check_lock();
  1698. if(!inuse) {
  1699. int lock = grab_lock();
  1700. if(!lock) {
  1701. od_printf("`white`Something went wrong getting the lock.\r\n");
  1702. paws();
  1703. od_exit(0, FALSE);
  1704. } else {
  1705. atexit(cleanMe);
  1706. main_menu();
  1707. }
  1708. } else {
  1709. od_send_file("ansis/sc_inuse.ans");
  1710. paws();
  1711. od_exit(0, FALSE);
  1712. }
  1713. }