/* Space Construct v0.6-dev Beanzilla@21:4/110 on FsxNet Beanzilla@637:1/110 on HappyNet */ #define VERSION_MAJOR 0 #define VERSION_MINOR 6 #ifndef VERSION_TYPE #define VERSION_TYPE "dev" #endif #define PATH_MAX 256 #define PATH_SEP "/" //#include // Sorry Apam... as much as I would like to keep using your stuff it's just not fully functional #include // Now using odoors for c++ #include #if defined(_MSC_VER) || defined(WIN32) #define snprintf _snprintf #define strcasecmp _stricmp #include #ifndef _MSC_VER #define _MSC_VER 1 #endif #else #include #endif // Standard C #include #include #include #include #include #include #include #include #include // stat #include // sc.log ODoors has logging so why not use it! int inuse = 0; // Are any other copies of us running? (We are a single user door!) int debug = 0; // Are we in debug mode? // Please change it for your system! int allowDev = 1; // Allow "Beanzilla" to not need the password. std::string sysop_pass = "spaceISbig"; // Case sensitive! // LOGGING with file output #include "zf_log.h" FILE *g_log_file; static void file_output_callback(const zf_log_message *msg, void *arg) { (void)arg; *msg->p = '\n'; fwrite(msg->buf, msg->p - msg->buf + 1, 1, g_log_file); fflush(g_log_file); } static void file_output_close(void) { fclose(g_log_file); } static int file_output_open(const char *const log_path) { g_log_file = fopen(log_path, "a"); if (!g_log_file) { ZF_LOGW("Failed to open log file %s", log_path); return 0; } atexit(file_output_close); zf_log_set_output_v(ZF_LOG_PUT_STD, 0, file_output_callback); return 1; } void log_flush(void) { fflush(g_log_file); } // END LOGGING // Randrange int randrange(int min, int max){ return min + rand() / (RAND_MAX / (max - min + 1) + 1); } // Moved to User class #include "user.h" // DateStamp Structure to provide date difference typedef struct dateTamp { int year; // YYYY, or number of years difference int month; // MM, or number of months difference int day; // DD, or number of days difference. int age; // Taking down to aproximate day count. } dT; // YYYYMMDD it in int form int dateStamp() { // YYYYMMDD \o/ In a INT so we can store it and compare against it! struct tm *time_now; time_t timen; int result = 0; timen = time(NULL); time_now = localtime(&timen); result += ((time_now->tm_year + 1900) * 10000); result += (time_now->tm_mon * 100) + 100; result += time_now->tm_mday; return result; } int compareDate(int dt) { // Returns integer of difference, from now. struct tm *time_now; time_t timen; int now = 0; timen = time(NULL); time_now = localtime(&timen); now += ((time_now->tm_year + 1900) * 10000); now += (time_now->tm_mon * 100) + 100; now += time_now->tm_mday; return (now - dt); // 10000 = 1 Year, 100 = 1 Month, 1 = 1 Day } dT fromDate(int diff) { // Reverse process so we can compare exact days or get the structure back out too. dT result; result.year = diff / 10000; result.month = (diff / 100) % 100; result.day = diff % 100; result.age = 0; // Process Aprox day count result.age += (365 * result.year); result.age += (30 * result.month); result.age += result.day; return result; } int db_test() { // Displays all users in the database sqlite3 *db; sqlite3_stmt *stmt; char sqlbuffer[256]; char strbuffer[256]; int sizeofdb = 0; int rc = sqlite3_open("spaceconstruct.db3", &db); if(rc) { // Did we do a successful open? ZF_LOGF("Failed opening database %s (%d)", sqlite3_errmsg(db), rc); sqlite3_close(db); od_exit(-1, FALSE); } sqlite3_busy_timeout(db, 5000); // DB open strcpy(sqlbuffer, "SELECT * FROM user;"); sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer), &stmt, NULL); while(sqlite3_step(stmt) == SQLITE_ROW) { ZF_LOGV("%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", sqlite3_column_name(stmt, 0), // int, uid sqlite3_column_int(stmt, 0), sqlite3_column_name(stmt, 1), // text, nick sqlite3_column_text(stmt, 1), sqlite3_column_name(stmt, 2), // text, real sqlite3_column_text(stmt, 2), sqlite3_column_name(stmt, 3), // int, experiece sqlite3_column_int(stmt, 3), sqlite3_column_name(stmt, 4), // int, metal sqlite3_column_int(stmt, 4), sqlite3_column_name(stmt, 5), // int, fuel sqlite3_column_int(stmt, 5), sqlite3_column_name(stmt, 6), // int, gun sqlite3_column_int(stmt, 6), sqlite3_column_name(stmt, 7), // int, armor sqlite3_column_int(stmt, 7), sqlite3_column_name(stmt, 8), // int, shield sqlite3_column_int(stmt, 8), sqlite3_column_name(stmt, 9), // int, armorpoints sqlite3_column_int(stmt, 9), sqlite3_column_name(stmt, 10), // int, shieldpoints sqlite3_column_int(stmt, 10), sqlite3_column_name(stmt, 11), // int, hitpoints sqlite3_column_int(stmt, 11), sqlite3_column_name(stmt, 12), // int, shieldsup sqlite3_column_int(stmt, 12), sqlite3_column_name(stmt, 13), // int, laston sqlite3_column_int(stmt, 13) ); sizeofdb += 1; } // Clean up database ZF_LOGV("There are %d users", sizeofdb); sqlite3_finalize(stmt); sqlite3_close(db); return sizeofdb; } int check_lock() { // Checks stats of lock, (1 = Lock is in effect, 0 = No Lock established) struct stat s; if (stat("lock.flg", &s) == 0) { return 1; } else { return 0; } } int grab_lock() { // Attempt to grab lock, (0 = Already gotten, 1 = Success, -1 = Error) int valid = check_lock(); FILE *fhandle; if (valid == 0) { fhandle = fopen("lock.flg", "w"); if(!fhandle) { ZF_LOGF("Unable to make lock.flg!"); ZF_LOGF("Something went wrong perhaps we don't have permissions?"); return -1; } fprintf(fhandle, "I am in use already!\n"); fclose(fhandle); ZF_LOGV("Lock Established"); return 1; } else { ZF_LOGW("Lock already established!"); return 0; } } void rel_lock() { // Attempt to release lock int valid = check_lock(); if (valid == 1) { if (unlink("lock.flg") != 0) { ZF_LOGF("Unable to release lock.flg!"); ZF_LOGF("Something went wrong! Players might not be able to play now!"); } } else { ZF_LOGW("Lock already released!"); } } void log_drop() { // Spits out info from Drop File: ZF_LOGV("Name=%s Alias=%s TimeLeft=%d SecLevel=%d Location=%s Node=%d Sysop=%s", od_control.user_name, od_control.user_handle, od_control.user_timelimit, od_control.user_security, od_control.user_location, od_control.od_node, od_control.sysop_name ); } void paws() { // Aaah, DRY od_printf("`white`Press any key to continue..."); od_get_key(true); od_printf("\r\n"); } int yesNo() { char ch; int done = 0; od_printf("`bright black`(`bright white`Y`bright black`)`white`es `bright black`(`bright red`N`bright black`)`red`o`white`"); ch = od_get_answer("YyNn\r"); od_printf("\r\n"); switch(tolower(ch)) { case 'y': done = 1; break; case '\r': case 'n': break; } return done; } int locate_player(char name[]) { // returns user id for given real name and 0 for no record found sqlite3 *db; sqlite3_stmt *stmt; char sqlbuffer[256]; int result = 0; int rc = sqlite3_open("spaceconstruct.db3", &db); if(rc) { // Did we do a successful open? ZF_LOGF("Failed opening database %s (%d)", sqlite3_errmsg(db), rc); sqlite3_close(db); od_exit(-1, FALSE); } sqlite3_busy_timeout(db, 5000); //od_printf("realname = '%s'\r\n", name); // Locating user with given name strcpy(sqlbuffer, "SELECT uid from user where real=? COLLATE NOCASE;"); sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL); sqlite3_bind_text(stmt, 1, name, strlen(name), SQLITE_STATIC); rc = sqlite3_step(stmt); if (rc == SQLITE_ROW) { // Return user id result = sqlite3_column_int(stmt, 0); } else { // User not found ZF_LOGW("Unable to locate user %s", name); result = 0; } // Clean Up, return results sqlite3_finalize(stmt); sqlite3_close(db); return result; } void check_database() { // If the table users does not exist make it. sqlite3 *db; sqlite3_stmt *stmt; char sqlbuffer[256]; int rc = sqlite3_open("spaceconstruct.db3", &db); if(rc) { ZF_LOGF("Failed opening database %s (%d)", sqlite3_errmsg(db), rc); sqlite3_close(db); od_exit(-1, FALSE); } sqlite3_busy_timeout(db, 5000); strcpy(sqlbuffer, "SELECT COUNT(*) FROM user;"); sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL); rc = sqlite3_step(stmt); if(rc == SQLITE_ROW) { // Good } else { // Bad, Create table char *errmsg; 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); ZF_LOGW("Users table did not exist created"); } sqlite3_finalize(stmt); sqlite3_close(db); } User load_player(int uuid) { // Returns a player Structure from database sqlite3 *db; sqlite3_stmt *stmt; char sqlbuffer[256]; //User *result; int rc = sqlite3_open("spaceconstruct.db3", &db); if(rc) { // Did we do a successful open? ZF_LOGF("Failed opening database %s (%d)", sqlite3_errmsg(db), rc); sqlite3_close(db); od_exit(-1, FALSE); } sqlite3_busy_timeout(db, 5000); strcpy(sqlbuffer, "SELECT * FROM user WHERE uid=?;"); sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL); sqlite3_bind_int(stmt, 1, uuid); rc = sqlite3_step(stmt); if (rc == SQLITE_ROW) { std::string val1( (const char *)sqlite3_column_text(stmt, 1) ); std::string val2( (const char *)sqlite3_column_text(stmt, 2) ); User result(sqlite3_column_int(stmt, 0), val1, val2, sqlite3_column_int(stmt, 3), sqlite3_column_int(stmt, 13), sqlite3_column_int(stmt, 7), sqlite3_column_int(stmt, 9), sqlite3_column_int(stmt, 8), sqlite3_column_int(stmt, 10), sqlite3_column_int(stmt, 12), sqlite3_column_int(stmt, 11), sqlite3_column_int(stmt, 6), sqlite3_column_int(stmt, 4), sqlite3_column_int(stmt, 5)); sqlite3_finalize(stmt); sqlite3_close(db); return result; } else { sqlite3_finalize(stmt); sqlite3_close(db); User result; return result; } sqlite3_finalize(stmt); sqlite3_close(db); } User highest_player() { // Used to find if someone may have fought the Unknown One and won the game already! int done = 0; User test; int high = 0; int high_exp = 0; int id = 1; while(!done) { test = load_player(id); if(test.get_uid() != 0) { if(test.get_experience() > high_exp) { // Update highest player id and experience high_exp = test.get_experience(); high = id; } } else { done = 1; } id += 1; } // Ok highest experiencing player found! test = load_player(high); return test; } void update_player(User data) { sqlite3 *db; sqlite3_stmt *stmt; char sqlbuffer[1024]; int rc = sqlite3_open("spaceconstruct.db3", &db); if(rc) { // Did we do a successful open? ZF_LOGF("Failed opening database %s (%d)", sqlite3_errmsg(db), rc); sqlite3_close(db); od_exit(-1, FALSE); } sqlite3_busy_timeout(db, 5000); // Bad, don't do this... opens to SQL injection! //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;", // data.nick, data.experience, data.metal, data.fuel, data.guns, data.armors, data.shields, data.armorpoints, data.shieldpoints, data.hitpoints, data.uid); // strcpy(sqlbuffer, "UPDATE user SET nick=?, experience=?, metal=?, fuel=?, gun=?, armor=?, shield=?, armorpoints=?, shieldpoints=?, hitpoints=?, shieldsup=?, laston=? WHERE uid=?;"); // Are they actually going to be changing their nicks?? strcpy(sqlbuffer, "UPDATE user SET experience=?, metal=?, fuel=?, gun=?, armor=?, shield=?, armorpoints=?, shieldpoints=?, hitpoints=?, shieldsup=?, laston=? WHERE uid=?;"); sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL); // Bind All data values // sqlite3_bind_text(stmt, 1, data.get_nick().c_str(), data.get_nick().length(), SQLITE_STATIC); sqlite3_bind_int(stmt, 1, data.get_experience()); sqlite3_bind_int(stmt, 2, data.get_metal()); sqlite3_bind_int(stmt, 3, data.get_fuel()); sqlite3_bind_int(stmt, 4, data.get_gun()); sqlite3_bind_int(stmt, 5, data.get_armor()); sqlite3_bind_int(stmt, 6, data.get_shield()); sqlite3_bind_int(stmt, 7, data.get_armorpoints()); sqlite3_bind_int(stmt, 8, data.get_shieldpoints()); sqlite3_bind_int(stmt, 9, data.get_hitpoints()); sqlite3_bind_int(stmt, 10, data.get_shieldsup()); sqlite3_bind_int(stmt, 11, data.get_laston()); sqlite3_bind_int(stmt, 12, data.get_uid()); // Execute rc = sqlite3_step(stmt); if(rc != SQLITE_DONE) { ZF_LOGF("Failed updating player %s (%d)", sqlite3_errmsg(db), rc); sqlite3_finalize(stmt); sqlite3_close(db); od_exit(-1, FALSE); } sqlite3_finalize(stmt); sqlite3_close(db); } int create_player(User data) { sqlite3 *db; sqlite3_stmt *stmt; char sqlbuffer[1024]; int rc = sqlite3_open("spaceconstruct.db3", &db); if(rc) { // Did we do a successful open? ZF_LOGF("Failed opening database %s (%d)", sqlite3_errmsg(db), rc); sqlite3_close(db); od_exit(-1, FALSE); } sqlite3_busy_timeout(db, 5000); strcpy(sqlbuffer, "INSERT INTO user (nick, real, experience, metal, fuel, gun, armor, shield, armorpoints, shieldpoints, hitpoints, shieldsup, laston) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"); sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL); std::string temp = data.get_nick(); sqlite3_bind_text(stmt, 1, temp.c_str(), temp.length(), SQLITE_STATIC); std::string temp2 = data.get_real(); sqlite3_bind_text(stmt, 2, temp2.c_str(), temp2.length(), SQLITE_STATIC); //sqlite3_bind_text(stmt, 1, data.get_nick().c_str(), data.get_nick().length(), SQLITE_STATIC); //sqlite3_bind_text(stmt, 2, data.get_real().c_str(), data.get_real().length(), SQLITE_STATIC); sqlite3_bind_int(stmt, 3, data.get_experience()); sqlite3_bind_int(stmt, 4, data.get_metal()); sqlite3_bind_int(stmt, 5, data.get_fuel()); sqlite3_bind_int(stmt, 6, data.get_gun()); sqlite3_bind_int(stmt, 7, data.get_armor()); sqlite3_bind_int(stmt, 8, data.get_shield()); sqlite3_bind_int(stmt, 9, data.get_armorpoints()); sqlite3_bind_int(stmt, 10, data.get_shieldpoints()); sqlite3_bind_int(stmt, 11, data.get_hitpoints()); sqlite3_bind_int(stmt, 12, data.get_shieldsup()); sqlite3_bind_int(stmt, 13, data.get_laston()); rc = sqlite3_step(stmt); if(rc != SQLITE_DONE) { ZF_LOGF("Failed inserting player %s (%d)", sqlite3_errmsg(db), rc); sqlite3_finalize(stmt); sqlite3_close(db); od_exit(-1, FALSE); } sqlite3_finalize(stmt); sqlite3_close(db); return 1; // Good } void delete_player(int uuid) { sqlite3 *db; sqlite3_stmt *stmt; char sqlbuffer[256]; int rc = sqlite3_open("spaceconstruct.db3", &db); if(rc) { // Did we do a successful open? ZF_LOGF("Failed opening database %s (%d)", sqlite3_errmsg(db), rc); sqlite3_close(db); od_exit(-1, FALSE); } sqlite3_busy_timeout(db, 5000); strcpy(sqlbuffer, "DELETE FROM user WHERE uid=?;"); sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL); sqlite3_bind_int(stmt, 1, uuid); rc = sqlite3_step(stmt); if (rc != SQLITE_DONE){ ZF_LOGF("Unable to locate user with id=%d got %s (%d)", uuid, sqlite3_errmsg(db), rc); sqlite3_finalize(stmt); sqlite3_close(db); od_exit(-1, FALSE); } sqlite3_finalize(stmt); sqlite3_close(db); } void delete_players() { sqlite3 *db; sqlite3_stmt *stmt; char sqlbuffer[256]; int rc = sqlite3_open("spaceconstruct.db3", &db); if(rc) { // Did we do a successful open? ZF_LOGF("Failed opening database %s (%d)", sqlite3_errmsg(db), rc); sqlite3_close(db); od_exit(-1, FALSE); } sqlite3_busy_timeout(db, 5000); strcpy(sqlbuffer, "DELETE FROM user;"); sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL); rc = sqlite3_step(stmt); if (rc != SQLITE_DONE){ ZF_LOGF("Delete_players 1/2, Unexpected error %s (%d)", sqlite3_errmsg(db), rc); sqlite3_finalize(stmt); sqlite3_close(db); od_exit(-1, FALSE); } strcpy(sqlbuffer, "UPDATE sqlite_sequence SET seq = 0 WHERE name='user';"); sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL); rc = sqlite3_step(stmt); if (rc != SQLITE_DONE){ ZF_LOGF("Delete_players 2/2, Unexpected error %s (%d)", sqlite3_errmsg(db), rc); sqlite3_finalize(stmt); sqlite3_close(db); od_exit(-1, FALSE); } sqlite3_finalize(stmt); sqlite3_close(db); } int display_all_players() { sqlite3 *db; sqlite3_stmt *stmt; char sqlbuffer[1024]; int rc = sqlite3_open("spaceconstruct.db3", &db); if(rc) { // Did we do a successful open? ZF_LOGF("Failed opening database %s (%d)", sqlite3_errmsg(db), rc); sqlite3_close(db); od_exit(-1, FALSE); } sqlite3_busy_timeout(db, 5000); strcpy(sqlbuffer, "SELECT * from user ORDER BY experience DESC, nick DESC;"); sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL); int total = 0; od_printf("`bright green`___ The Players ___\r\n"); while(sqlite3_step(stmt) == SQLITE_ROW) { od_printf("`bright white` %s (%d)\r\n", sqlite3_column_text(stmt, 1), sqlite3_column_int(stmt, 3)); total += 1; } if(total > 1) { od_printf("`green`There are a total of `bright green`%d`green` players\r\n", total); } else if(total == 0) { od_printf("`green`There are a total of `bright green`%d`green` players\r\n", total); } else { od_printf("`green`There are a total of `bright green`%d`green` player\r\n", total); } sqlite3_finalize(stmt); sqlite3_close(db); return total; } int display_all_opponents(int us) { sqlite3 *db; sqlite3_stmt *stmt; char sqlbuffer[1024]; int rc = sqlite3_open("spaceconstruct.db3", &db); if(rc) { // Did we do a successful open? ZF_LOGF("Failed opening database %s (%d)", sqlite3_errmsg(db), rc); sqlite3_close(db); od_exit(-1, FALSE); } sqlite3_busy_timeout(db, 5000); strcpy(sqlbuffer, "SELECT * from user ORDER BY experience DESC, nick DESC;"); sqlite3_prepare_v2(db, sqlbuffer, strlen(sqlbuffer) + 1, &stmt, NULL); int total = 1; od_printf("`bright green`___ Target List ___\r\n"); while(sqlite3_step(stmt) == SQLITE_ROW) { if(total != us) { 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)); } total += 1; } total -= 1; sqlite3_finalize(stmt); sqlite3_close(db); return total; } User build_menu(User my) { int done = 0; char ch; if(my.get_metal() != 0) { while(!done) { od_clr_scr(); od_send_file("ansis/sc_build.ans"); // Paint over sc_build.ans file od_set_cursor(3, 15); od_printf("%5d", my.calcGun()); od_set_cursor(4, 15); od_printf("%5d", my.calcArmor()); od_set_cursor(5, 15); od_printf("%5d", my.calcShield()); od_set_cursor(9, 1); // Resuming normal operations od_printf("`bright yellow`You have %8d metal\r\n", my.get_metal()); ch = od_get_answer("GgAaSsCcRr\r"); switch(tolower(ch)) { case 'g': if(my.get_metal() >= my.calcGun()) { my.rmMetal(my.calcGun()); my.addGun(1); od_printf("`bright green`Added a new gun!\r\n`white`"); paws(); } else { od_printf("`bright red`You don't have the %d metal for this!\r\n`white`", my.calcGun()); paws(); } break; case 'a': if(my.get_metal() >= my.calcArmor()) { my.rmMetal(my.calcArmor()); my.addArmor(1); od_printf("`bright green`Added a new armor!\r\n`white`"); paws(); } else { od_printf("`bright red`You don't have the %d metal for this!\r\n`white`", my.calcArmor()); paws(); } break; case 's': if(my.get_metal() >= my.calcShield()) { my.rmMetal(my.calcShield()); my.addShield(1); od_printf("`bright green`Added a new shield!\r\n`white`"); paws(); } else { od_printf("`bright red`You don't have the %d metal for this!\r\n`white`", my.calcShield()); paws(); } break; case '\r': case 'c': done = 1; break; case 'r': if(my.get_experience() >= 25) { if(my.get_metal() >= 25) { my.rmEXP(25); my.rmMetal(25); my.addFuel(5); od_printf("`bright green`Made 5 fuel using 25 experience and 25 metal!\r\n"); paws(); } else { od_printf("`bright red`You need 25 experience and 25 metal to make fuel!\r\n"); paws(); } } else { od_printf("`bright red`You need 25 experience and 25 metal to make fuel!\r\n"); paws(); } break; } } update_player(my); return my; } else { return my; } } User pvp_menu(User my, User targ) { int done = 0; int playerWon = 0; char ch; // We need to set the targ's hit points and such to max and enable us to "restore" them int temp_hp = targ.get_hitpoints(); int temp_ap = targ.get_armorpoints(); int temp_sp = targ.get_shieldpoints(); int temp_su = targ.get_shieldsup(); // Set Offline to max values int targ_dmg = (targ.get_gun() + 1); // Add bonus damage for offline targ.set_hitpoints(targ.calcHP()); targ.set_armorpoints(targ.calcAP()); targ.set_shieldpoints(targ.calcSP()); targ.set_shieldsup(0); // Prep Combat values int fire = 0; // Fire Guns int flee = 0; // Run away int regen = 0; // Shields int test = 0; int test2 = 0; while(!done) { // Process Shields up if(temp_su != 0) { temp_su -= 1; } if(my.get_shieldsup() != 0) { my.rmSU(1); } // Process Crew repairing hitpoints if(targ.get_hitpoints() < targ.calcHP()) { regen = randrange(0, 100); if(regen >= 85) { // 15%, offline get a bonus 5% on repairing hull. targ.addHP(1); od_printf("`bright green`%s`green`'s crew repaired their hull for 1 point!\r\n", targ.get_nick().c_str()); } } if(my.get_hitpoints() < my.calcHP()) { regen = randrange(0, 100); if(regen >= 90) { // 10% my.addHP(1); od_printf("`bright green`Your crew repaired your hull for 1 point!\r\n"); } } // Process Shields regenerating and display player stats regen = randrange(0, 100); if(regen >= 75) { // 25% targ.regen(); } od_printf("`bright white`%s has `bright cyan`%d`bright white` shields, %d armor and %d hitpoints left\r\n", targ.get_nick().c_str(), temp_sp, temp_ap, temp_hp); // Online Players Shields regen = randrange(0, 100); if(regen >= 80) { // 20% my.regen(); } od_printf("`bright white`Your ship has `bright cyan`%d`bright white` shields, %d armor and %d hitpoints left\r\n", my.get_shieldpoints(), my.get_armorpoints(), my.get_hitpoints()); // Form combat menu (Not allowing online to repair since offline can't really repair either) od_printf("`bright black`(`bright white`A`bright black`)`white`ttack\r\n"); od_printf("`bright black`(`bright white`F`bright black`)`white`lee\r\n"); // Online Players action ch = od_get_answer("AaFf\r"); switch(tolower(ch)) { case '\r': case 'a': fire = randrange(0, 100); if(fire >= 50) { // Proccess online dealing damage to offline test = targ.takeDamage(my.get_gun()); if(test == 0) { od_printf("`bright red`%s took %d damage!\r\n", targ.get_nick().c_str(), my.get_gun()); } else { od_printf("`bright red`%s took %d damage, and blew up!\r\n", targ.get_nick().c_str(), my.get_gun()); playerWon = 1; // Online beat offline } } else { // Online missed od_printf("`white`You missed!\r\n"); } break; case 'f': flee = randrange(0, 100); if(flee >= 80) { // 20% chance the online flees playerWon = 3; // Online ran away from Offline done = 1; od_printf("`bright green`You ran away from %s!\r\n", targ.get_nick().c_str()); } else { od_printf("`bright red`%s found you!\r\n", targ.get_nick().c_str()); } break; } // Now for Offline to attack if(!playerWon) { fire = randrange(0, 100); if(fire >= 45) { // 55%, 5% bonus for offline test2 = my.takeDamage(targ_dmg); if(test2 == 0) { od_printf("`bright red`You took %d damage!\r\n", targ_dmg); } else { od_printf("`bright red`You took %d damage, and blew up!\r\n", targ_dmg); playerWon = 2; } } } // Winning Move? if(playerWon) { switch(playerWon) { case 1: // Online won over offline ZF_LOGV("%s beat %s in pvp", my.get_nick().c_str(), targ.get_nick().c_str()); if(targ.get_experience()) { my.addEXP((targ.get_experience() / 2)); targ.rmEXP((targ.get_experience() / 2)); } if(targ.get_metal()) { my.addMetal((targ.get_metal() / 2)); targ.rmMetal((targ.get_metal() / 2)); } my.rmFuel(4); if(my.get_fuel() < 0) { my.set_fuel(0); } od_printf("`bright green`Congrats on defeating %s!\r\n`white`", targ.get_nick().c_str()); break; case 2: // Offline won over online! ZF_LOGV("%s beat %s in pvp", targ.get_nick().c_str(), my.get_nick().c_str()); if(my.get_experience()) { targ.addEXP((my.get_experience() / 2)); my.rmEXP((my.get_experience() / 2)); } if(my.get_metal()) { targ.addMetal((my.get_metal() / 2)); my.rmMetal((my.get_metal() / 2)); } my.rmFuel(4); if(my.get_fuel() < 0) { my.set_fuel(0); } od_printf("`bright red`Sorry for your loss! (We rebuild your ship)\r\n"); my.set_hitpoints(4); my.set_armorpoints(8); my.set_shieldpoints(0); my.set_shieldsup(0); my.set_armor(1); my.set_shield(0); my.set_gun(1); break; case 3: ZF_LOGV("%s ran away from %s in pvp", my.get_nick().c_str(), targ.get_nick().c_str()); my.rmFuel(4); if(my.get_fuel() < 0) { my.set_fuel(0); } break; } } } // Restore targ values from temps targ.set_shieldsup(temp_su); targ.set_armorpoints(temp_ap); targ.set_hitpoints(temp_hp); targ.set_shieldpoints(temp_sp); // DOne, save update_player(targ); update_player(my); return my; } User combat_menu(User my, int targ_hp, int targ_dmg, int asteroid) { int done = 0; int playerWon = 0; // Did the player win? (1 = Yes, 2 = No, 3 = Flee) char ch; int armorRep = 0; // Can armor be repaired? int temp = 0; int temp1 = 0; int temp2 = 0; int temp_hp = targ_hp; int flee = 0; int fire = 0; int regen = 0; while(!done) { if(asteroid == 0) { od_printf("`bright white`Pirate has %d hitpoints left\r\n", targ_hp); } else if(asteroid == 1) { od_printf("`bright white`Asteroid has %d hitpoints left\r\n", targ_hp); } else if(asteroid == 2) { od_printf("`bright white`Unknown One has %d hitpoints left\r\n", targ_hp); } // Proccess Shields comming back online if(my.get_shieldsup() != 0) { my.rmSU(1); } // Proccess Crew repairing hull if(my.get_hitpoints() < my.calcHP()) { regen = randrange(0, 100); if(regen >= 90) { my.addHP(1); } } // Proccess Shields Regen regen = randrange(0, 100); if(regen >= 80) { // 20% my.regen(); } od_printf("`bright white`Your ship has `bright cyan`%d`bright white` shields, %d armor and %d hitpoints left:\r\n", my.get_shieldpoints(), my.get_armorpoints(), my.get_hitpoints()); // Forming Combat Menu od_printf("`bright black`(`bright white`A`bright black`)`white`ttack\r\n"); if(my.get_armorpoints() < my.calcAP()) { od_printf("`bright black`(`bright white`R`bright black`)`white`epair Armor\r\n"); armorRep = 1; // Yes we can repair armor } od_printf("`bright black`(`bright white`F`bright black`)`white`lee\r\n"); // Proccess User action ch = od_get_answer("AaRrFf\r"); switch(tolower(ch)) { case '\r': case 'a': fire = rand() % 100; if(asteroid == 1) { // Its a rock so allow player to hit it more frequent fire -= 15; } if(fire >= 50) { targ_hp -= my.get_gun(); if(targ_hp <= 0) { od_printf("`bright red`Target Destroyed!\r\n"); done = 1; playerWon = 1; } else { od_printf("`bright red`Target took %d damage!\r\n", my.get_gun()); } } else { od_printf("`white`You Missed!\r\n"); } break; case 'r': if(armorRep) { my.repair(false); } else { od_printf("`bright yellow`You don't seem to need repairs!\r\n"); } break; case 'f': flee = rand() % 100; if(asteroid == 1) { flee = 100; // Always allow fleeing from asteroid } else if(asteroid == 2) { flee = 0; // Never allow fleeing from Unknown One } if(flee >= 82) { playerWon = 3; done = 1; od_printf("`bright green`You ran away!\r\n"); } else { od_printf("`bright red`Target found you!\r\n"); } break; } // If Enemy is alive proccess incomming attack if(targ_hp > 0) { targ_dmg; fire = rand() % 100; if(asteroid == 1) { // Yup it doesn't have gunz cuz it's rock. fire = 0; } else if(asteroid == 2) { // This is the Unknown One fire += 5; } if(fire >= 40) { temp = my.takeDamage(targ_dmg); if(temp == 0) { od_printf("`bright red`You took %d damage!\r\n", targ_dmg); } else { od_printf("`bright red`You took %d damage, and blew up!\r\n", targ_dmg); playerWon = 2; } } // firing } // Winning move? if(playerWon) { if(playerWon == 1) { std::string who; switch(asteroid) { case 0: //Pirate who = "Pirate"; break; case 1: // Asteroid who = "Asteroid"; break; case 2: // Unknown One who = "Unkown One"; break; } ZF_LOGV("%s beat %s", my.get_nick().c_str(), who.c_str()); // Player won my.addEXP((temp_hp + targ_dmg)); my.addMetal(temp_hp); if(asteroid == 1) { // If asteroid reward more experience and metal! my.addEXP(2); my.addMetal(2); } else if(asteroid == 2) { // If it was the boss! my.addEXP(6000); // Ensure the game triggers a reset! my.set_metal(0); // Stop the player! my.set_fuel(2); // Prevent the player from doing anything else } my.rmFuel(2); if(my.get_fuel() < 0) { my.set_fuel(0); } od_printf("`bright green`Congrats on your victory!\r\n`white`"); } else if(playerWon == 2) { std::string who; switch(asteroid) { case 0: //Pirate who = "Pirate"; break; case 1: // Asteroid who = "Asteroid"; break; case 2: // Unknown One who = "Unkown One"; break; } ZF_LOGV("%s beat %s", who.c_str(), my.get_nick().c_str()); // Target won my.rmEXP((temp_hp + targ_dmg)); my.rmMetal(temp_hp); my.rmFuel(3); if(my.get_experience() < 0) { my.set_experience(0); } if(my.get_metal() < 0) { my.set_metal(0); } if(my.get_fuel() < 0) { my.set_fuel(0); } od_printf("`bright red`Sorry for your loss! (We rebuild your ship)\r\n"); my.set_hitpoints(4); my.set_armorpoints(8); my.set_shieldpoints(0); my.set_shieldsup(0); my.set_armor(1); my.set_shield(0); my.set_gun(1); } else if(playerWon == 3) { std::string who; switch(asteroid) { case 0: //Pirate who = "Pirate"; break; case 1: // Asteroid who = "Asteroid"; break; case 2: // Unknown One who = "Unkown One"; break; } ZF_LOGV("%s ran away from %s", my.get_nick().c_str(), who.c_str()); // Chicken! my.rmFuel(1); } } } update_player(my); return my; } void about_game() { int done = 0; int page = 1; while(!done) { switch(page) { case 1: od_clr_scr(); od_send_file("ansis/sc_doc_1.ans"); paws(); break; case 2: od_clr_scr(); od_send_file("ansis/sc_doc_2.ans"); paws(); break; case 3: od_clr_scr(); od_send_file("ansis/sc_doc_3.ans"); paws(); break; case 4: od_clr_scr(); od_send_file("ansis/sc_doc_4.ans"); paws(); break; case 5: od_clr_scr(); od_send_file("ansis/sc_doc_5.ans"); paws(); break; case 6: done = 1; break; } od_clr_scr(); page += 1; } } void play_game() { int done = 0; char ch; char ch1[256]; User myself; User myself2; User testing; int reset = 0; int doRefuel = 0; int pirate_encounter = 0; int pirate_hp = 0; // Reused for asteroid int pirate_dmg = 0; // Reused for asteroid int asteroid = 0; // 1 means yes we need to remove damage... completely. int me = locate_player(od_control.user_name); int abort = 0; if(me != 0) { //myself = load_player(me); testing = load_player(me); if(testing.get_uid() != 0) { myself = load_player(me); } dT age = fromDate(compareDate(myself.get_laston())); // Process player inactivity if(age.age >= 30) { // 30 days od_printf("`bright green`Since you haven't played a while we have reset your account!\r\n"); ZF_LOGW("%s was reset for expiring", od_control.user_name); me = 0; reset = 1; } // Processing fuel regeneration if(age.age != 0) { doRefuel = 1; } } if(me != 0) { od_printf("`bright white`Welcome back `bright green`%s\r\n", myself.get_nick().c_str()); ZF_LOGV("%s is back again", od_control.user_name); dT age = fromDate(compareDate(myself.get_laston())); myself.set_laston(dateStamp()); if(age.day != 0 || age.month != 0 || age.year != 0) { od_printf("`bright yellow`Haven't seen you for"); } if(age.day != 0) { if(age.day > 1) { od_printf(" %d days", age.day); } else { od_printf(" %d day", age.day); } } if(age.month != 0) { if(age.month > 1) { od_printf(" %d months", age.month); } else { od_printf(" %d month", age.month); } } if(age.year != 0) { if(age.year > 1) { od_printf(" %d years", age.year); } else { od_printf(" %d year", age.year); } } if(age.day != 0 || age.month != 0 || age.year != 0) { od_printf("\r\n"); } if(doRefuel) { if(myself.get_fuel() != 0) { myself.addFuel((age.age * 2)); } else { myself.addFuel(((age.age * 2) + 10)); od_printf("`bright green`For using all your fuel last time you get bonus fuel today!\r\n"); } od_printf("`bright green`You now have %d fuel\r\n", myself.get_fuel()); } update_player(myself); paws(); } else { od_printf("`bright white`You look new here. (Hit Enter to abort)\r\n"); ZF_LOGV("%s is a new player", od_control.user_name); while(done == 0) { od_printf("`bright yellow`What's your name: "); od_input_str(ch1, 26, 32, 126); od_printf("\r\n"); if(strlen(ch1) > 0) { //od_input_str(ch1, 256, 32, 126); myself.set_nick(ch1); } else { od_clr_scr(); abort = 1; done = 1; od_printf("`bright red`Ok, come back later then...`white`\r\n"); paws(); } if(abort == 0) { od_printf("`bright white`Are you sure you want to be called `bright green`%s\r\n", myself.get_nick().c_str()); done = yesNo(); if(done) { if(reset) { // So we are reseting the user, this wipes all values and uses update instead of create User myself(myself.get_uid(), myself.get_nick().c_str(), myself.get_real(), 0, dateStamp(), 1, 8, 0, 0, 0, 4, 1, 0, 10); update_player(myself); } else { // Brand new user ZF_LOGI("Creating user"); User myself2(myself.get_nick().c_str(), od_control.user_name); create_player(myself2); myself = load_player(locate_player(od_control.user_name)); } } } } done = 0; // Reset this for our next loop. } // Ok user is here now lets ask what they want to do... build/attack if(abort == 0) { od_clr_scr(); while(!done) { od_printf("`bright yellow`You have %d fuel left for today,\r\n", myself.get_fuel()); if(myself.get_shieldsup() == 0) { od_printf("`bright yellow`Your ship has `bright cyan`%d`bright yellow` shields, %d armor and %d hitpoints left:\r\n", myself.get_shieldpoints(), myself.get_armorpoints(), myself.get_hitpoints()); } else { od_printf("`bright yellow`Your ship has %d armor, `bright cyan`%d`bright yellow` shields and %d hitpoints left:\r\n", myself.get_shieldpoints(), myself.get_armorpoints(), myself.get_hitpoints()); } if(myself.get_armorpoints() < myself.calcAP()) { od_printf("`bright black`(`bright white`R`bright black`)`white`epair Armor\r\n"); } if(myself.get_shieldpoints() < myself.calcSP() || myself.get_shieldsup() != 0) { od_printf("`bright black`(`bright white`G`bright black`)`white`enerate Shields\r\n"); } if(myself.get_fuel() >= 2) { od_send_file("ansis/sc_gameh.ans"); ch = od_get_answer("SsHhBbQqRrGgLlVv"); } else { od_send_file("ansis/sc_gamel.ans"); ch = od_get_answer("BbQqRrGgLlVv"); } od_clr_scr(); switch(tolower(ch)) { case 's': if(myself.get_fuel() >= 1) { pirate_encounter = rand() % 100; if(pirate_encounter >= 75) { // 25% chance to encounter a Pirate, or Unknown One if(myself.get_experience() > 3000) { if(pirate_encounter >= 95) { // 5% chance to encounter unknown one od_printf("`bright yellow`You encounter the `bright red`Unknown One\r\n`white`"); asteroid = 2; } else { od_printf("`bright yellow`You encounter a `bright red`Pirate\r\n`white`"); asteroid = 0; } } else { // The player is not skilled enough to fight the unknown one od_printf("`bright yellow`You encounter a `bright red`Pirate\r\n`white`"); asteroid = 0; } } else { // 75% chance to encounter a Asteroid od_printf("`bright yellow`You encounter a `bright red`Asteroid\r\n`white`"); asteroid = 1; } if(asteroid == 0 || asteroid == 2) { pirate_hp = ((myself.get_hitpoints() + 1) + (randrange(0, 4))); if(asteroid == 2) { // Increase boss hitpoints pirate_hp += 10; } // Increase difficulty based on experience... pirate_dmg = (myself.get_experience() / 500); if(pirate_dmg == 0) { // Always deal damage pirate_dmg = 1; } if(asteroid == 2) { // Increase boss damage pirate_dmg += 2; } // Send off to combat menu myself = combat_menu(myself, pirate_hp, pirate_dmg, asteroid); } else { pirate_hp = (myself.get_hitpoints() + 1) + (rand() % 10); // Send off to combat menu myself = combat_menu(myself, pirate_hp, 0, asteroid); } } break; case 'h': if(myself.get_fuel() >= 4) { int targs = display_all_opponents(myself.get_uid()); int targg = 1; int done2 = 0; if(targg == myself.get_uid()) { targg += 1; } while(!done2) { od_printf("`bright red`Targetting: %d\r\n", targg); if(yesNo()) { done2 = 1; } else if(targg < targs){ targg += 1; } else { done2 = 1; od_printf("`bright red`ABORTED!\r\n"); break; } } User targ = load_player(targg); if(targ.get_uid() != 0) { // I need to add some limits in here else someone could attack weaker players! int proceed = 0; int temp = targ.get_experience() + 1000; // Prevent the person from selecting a player that is higher than them int temp1 = targ.get_experience() - 500; // Prevent the person from selecting a player that is lower than them if(temp1 > 0) { temp1 = 0; } if(temp > myself.get_experience() && temp1 < myself.get_experience()) { proceed = 1; } if(proceed) { myself = pvp_menu(myself, targ); } else { od_printf("`bright white`Please select a opponent within your range of expertise!\r\n"); break; } } } else { od_printf("`bright white`You need 4 fuel to fight another player!\r\n`white`"); } break; case 'b': if(myself.get_metal() != 0) { // Send off to build menu od_clr_scr(); //od_send_file("ansis/sc_build.ans", FALSE); myself = build_menu(myself); } else { od_printf("`bright white`I am sorry you have no metal go fight.`white`\r\n"); } break; case 'q': done = 1; break; case 'r': if(myself.get_armorpoints() < (myself.get_armor() * 8)) { myself.repair(true); update_player(myself); } else { od_printf("`bright yellow`You don't seem to need repairs!\r\n`white`"); } break; case 'g': if(myself.get_shieldpoints() < myself.calcSP() || myself.get_shieldsup() != 0) { myself.regen(); update_player(myself); } else { od_printf("`bright yellow`You don't seem to need to regenerate shields!\r\n`white`"); } break; case 'v': od_printf("`bright white` ___ %s's Ship Status ___\r\n", myself.get_nick().c_str()); od_printf("`bright white`Items: # Installed: Metal to Upgrade:\r\n"); od_printf("`bright red`Guns: %8d %8d\r\n", myself.get_gun(), myself.calcGun()); od_printf("`bright yellow`Armor: %8d %8d\r\n", myself.get_armor(), myself.calcArmor()); od_printf("`bright cyan`Shields: %8d %8d\r\n", myself.get_shield(), myself.calcShield()); od_printf("`bright white`\r\n ___ Situation Report ___\r\n"); od_printf("`bright white`Items: Maximum: Current:\r\n"); od_printf("`bright green`Hitpoints: %8d %8d\r\n", myself.calcHP(), myself.get_hitpoints()); od_printf("`bright yellow`Armor: %8d %8d\r\n", myself.calcAP(), myself.get_armorpoints()); od_printf("`bright cyan`Shields: %8d %8d\r\n", myself.calcSP(), myself.get_shieldpoints()); od_printf("`bright magenta`Experience: %8d\r\n", myself.get_experience()); od_printf("`bright magenta`Fuel: %8d\r\n", myself.get_fuel()); od_printf("`white`Metal: %8d\r\n", myself.get_metal()); paws(); od_clr_scr(); break; } } } } void sysop_menu() { int done = 0; char ch; int targ_ply = 1; int targ_max = 0; int done1 = 0; User targ; while(!done) { od_clr_scr(); od_send_file("ansis/sc_sysop.ans"); ch = od_get_answer("RrNnQq"); //od_printf("\r\n"); switch(tolower(ch)) { case 'q': done = 1; break; case 'r': od_printf("`bright red`__ Reset ___\r\n"); od_printf("`bright red`DANGER THIS WILL DELETE ALL PLAYERS IN GAME\r\n"); if(yesNo() == 0) { od_printf("`bright red`ABORTED!\r\n"); paws(); break; } ZF_LOGW("%s issued reset", od_control.user_name); delete_players(); paws(); break; case 'n': od_printf("`bright red`__ New Day ___\r\n"); while(!done1) { targ = load_player(targ_ply); if(targ.get_uid() != 0) { targ.rmLaston(1); // Travel back 1 day update_player(targ); // Save } else { done1 = 1; } targ_ply += 1; targ_max += 1; } od_printf("`bright red`%d players affected\r\n", (targ_max - 1)); targ_ply = 1; targ_max = 0; done1 = 0; ZF_LOGW("%s issued new day", od_control.user_name); paws(); break; } } od_clr_scr(); } void cleanMe() { rel_lock(); od_exit(0, FALSE); } void main_menu() { // Main menu for once things are done being initalized int done = 0; int done1 = 0; // For Reset Game and for New Day... also for Debug int targ_ply = 1; // Target player to perform op! int targ_max = 0; // Total number of players affected! User targ; // Player Struct User test; dT targ_age; // Date Struct dT test2; char targ_real[256]; char ch; int auth; // Security char sys[48]; // Security // 0 means we got the lock first, 1 means someone else has it already! while(!done) { od_clr_scr(); od_send_file("ansis/sc_main.ans"); ch = od_get_answer("PpLlVvQqSsAa"); od_clr_scr(); switch(tolower(ch)){ case 'q': // Quit done = 1; break; case 'p': // Play Game (Default if the player just hits enter) // Check to see if we have a winner if so refuse to let anyone on! (Wait 3 days then reset the game!) test = highest_player(); test2 = fromDate(compareDate(test.get_laston())); if(test.get_experience() >= 8000) { // If the player has the minimum of 3000 exp to fight the Unkown One and wins earning 5000 thats 8000 minimum if(test2.age >= 3) { // Auto reset the game or not allow the player to play! delete_players(); ZF_LOGW("Auto-Reset Occured"); od_printf("`bright green`Game has been reset!\r\n"); paws(); } else { // And the lucky winner is! int resetage = 3 - test2.age; od_printf("`bright green`%s has won the game!\r\n", test.get_nick().c_str()); od_printf("`bright green`The Game will reset in %d days!\r\n", resetage); ZF_LOGV("Auto-Reset will occur in %d days", resetage); paws(); break; } } play_game(); break; case 'a': about_game(); break; case 'l': // List Players in the game display_all_players(); paws(); break; case 'v': // Version od_clr_scr(); od_printf("`bright yellow`_____________________________\r\n"); od_printf("`bright yellow` Space Construct v%d.%d-%s\r\n", VERSION_MAJOR, VERSION_MINOR, VERSION_TYPE); od_printf("`bright yellow` By: Beanzilla\r\n"); od_printf("`bright yellow` FsxNet 21:4/110\r\n"); od_printf("`bright yellow` HappyNet 637:1/110\r\n"); od_printf("`bright yellow`_____________________________\r\n"); paws(); break; case 's': auth = 0; if(allowDev && strcmp(od_control.user_handle, "Beanzilla") == 0) { od_printf("`bright green`Access Granted\r\n"); ZF_LOGV("Dev accessed sysop menu"); auth = 1; } else { od_printf("`bright red`Sysop Password: "); strcpy(sys, ""); od_input_str(sys, 32, 32, 126); od_clr_scr(); // Add a bit of protecton if(sys == sysop_pass) { od_printf("`bright green`Access Granted\r\n"); ZF_LOGV("%s accessed sysop menu", od_control.user_name); auth = 1; } } // Give only Sysop and dev access to restricted commands if(auth) { paws(); sysop_menu(); } else { od_printf("`bright red`Access Denied\r\n"); ZF_LOGW("%s tried to access sysop menu", od_control.user_name); paws(); } break; } } } int main(int argc, char *argv[]) { od_parse_cmd_line(argc, argv); // Initiate Door od_init(); od_clr_scr(); // Establish Logging if(file_output_open("logs/sc.log") == 0) { od_printf("`bright red`Error Log file not open!\r\n"); od_exit(-1, false); } // Debug System if (debug) { ZF_LOGV("=== Debug ==="); ZF_LOGV("DropFile..."); log_drop(); int test = check_lock(); if (test == 0) { ZF_LOGV("Lock is: Avalible"); ZF_LOGV("Database..."); db_test(); } else { ZF_LOGV("Lock is: Taken"); ZF_LOGV("CANCELED Database Dump"); } } else { ZF_LOGV("--- Debug ---"); } // Normal Operations inuse = check_lock(); if(!inuse) { int lock = grab_lock(); if(!lock) { od_printf("`white`Something went wrong getting the lock.\r\n"); ZF_LOGF("Lock issue"); paws(); od_exit(0, FALSE); } else { atexit(cleanMe); check_database(); // Ensure the users table exists. main_menu(); } } else { od_send_file("ansis/sc_inuse.ans"); ZF_LOGI("In use"); paws(); od_exit(0, FALSE); } // Odoors testing // Screensaving /*char screen[4096]; // 4MB buffer // Draw box if(od_draw_box(5, 1, 20, 15) == true) { od_set_cursor(3, 7); od_printf("`white`Box is `bright green`GOOD"); } else { od_set_cursor(3, 7); od_printf("`white`Box is `bright red`BAD"); } od_set_cursor(25, 1); paws(); od_save_screen(screen); od_clr_scr(); od_set_cursor(1, 1); // Popup int run = 1; while(run) { switch(od_popup_menu("Main Menu", "^Files|^Electronic Mail|^News|E^xit", 20, 5, 0, MENU_NORMAL | MENU_KEEP)) { case 1: od_set_cursor(25, 1); od_printf("Files"); od_popup_menu("Files Menu", "^Search For Files|^Download|^Upload", 30, 7, 1, MENU_NORMAL | MENU_ALLOW_CANCEL | MENU_KEEP); break; case 2: od_set_cursor(25, 1); od_printf("Email"); od_popup_menu("EMail Menu", "Get ^New Mail|^Send Mail|Send ^Fax", 30, 8, 2, MENU_NORMAL | MENU_ALLOW_CANCEL | MENU_KEEP); break; case 3: od_set_cursor(25, 1); od_printf("News"); od_popup_menu("News Menu", "Choose News^Group|^Read News|^Post News", 30, 9, 3, MENU_NORMAL | MENU_ALLOW_CANCEL | MENU_KEEP); break; case 4: od_set_cursor(25, 1); od_printf("Exit"); od_popup_menu(NULL, NULL, 0, 0, 0, MENU_DESTROY); run = 0; break; case POPUP_ERROR: od_set_cursor(25, 1); od_printf("ERROR"); break; case POPUP_ESCAPE: od_set_cursor(25, 1); od_printf("ESCAPE"); break; case POPUP_LEFT: od_set_cursor(25, 1); od_printf("LEFT"); break; case POPUP_RIGHT: od_set_cursor(25, 1); od_printf("RIGHT"); break; default: od_set_cursor(25, 1); od_printf("DEFAULT"); break; } } paws(); od_restore_screen(screen); */ od_exit(0, false); }