diff --git a/src/action_safe.c b/src/action_safe.c index c930fc1..c4d54b1 100644 --- a/src/action_safe.c +++ b/src/action_safe.c @@ -5,6 +5,7 @@ #include #include #include +#include /* include main header file */ #include "mud.h" @@ -31,12 +32,12 @@ void cmd_quit(D_MOBILE *dMob, char *arg) dMob->socket->player = NULL; free_mobile(dMob); - close_socket(dMob->socket, FALSE); + close_socket(dMob->socket, false); } void cmd_shutdown(D_MOBILE *dMob, char *arg) { - shut_down = TRUE; + shut_down = true; } void cmd_commands(D_MOBILE *dMob, char *arg) @@ -128,7 +129,7 @@ void cmd_compress(D_MOBILE *dMob, char *arg) } else /* disable compression */ { - if (!compressEnd(dMob->socket, dMob->socket->compressing, FALSE)) + if (!compressEnd(dMob->socket, dMob->socket->compressing, false)) { text_to_mobile(dMob, "Failed.\n\r"); return; @@ -162,12 +163,12 @@ void cmd_copyover(D_MOBILE *dMob, char *arg) AttachIterator(&Iter, dsock_list); while ((dsock = (D_SOCKET *) NextInList(&Iter)) != NULL) { - compressEnd(dsock, dsock->compressing, FALSE); + compressEnd(dsock, dsock->compressing, false); if (dsock->state != STATE_PLAYING) { text_to_socket(dsock, "\n\rSorry, we are rebooting. Come back in a few minutes.\n\r"); - close_socket(dsock, FALSE); + close_socket(dsock, false); } else { @@ -205,7 +206,7 @@ void cmd_linkdead(D_MOBILE *dMob, char *arg) D_MOBILE *xMob; ITERATOR Iter; char buf[MAX_BUFFER]; - bool found = FALSE; + bool found = false; AttachIterator(&Iter, dmobile_list); while ((xMob = (D_MOBILE *) NextInList(&Iter)) != NULL) @@ -214,7 +215,7 @@ void cmd_linkdead(D_MOBILE *dMob, char *arg) { snprintf(buf, MAX_BUFFER, "%s is linkdead.\n\r", xMob->name); text_to_mobile(dMob, buf); - found = TRUE; + found = true; } } DetachIterator(&Iter); diff --git a/src/db.c b/src/db.c index 1d5109c..1d3ec58 100644 --- a/src/db.c +++ b/src/db.c @@ -2,13 +2,41 @@ #include #include #include +#include /* main header file */ #include "mud.h" +#include "db.h" sqlite3 * db; sqlite3_stmt *db_prepare_internal(const char *sql, va_list vars); +int get_db_schema(); + +/* + * Array of commands to be executed by db_migrate to apply changes to the database. + * + */ + +typedef struct migration_commands { + int schema; + char *action; +} migration_commands; + +migration_commands command[] = { +/* { DB_SCHEMA, Action to upgrade the database to the DB_SCHEMA } */ + { 0, "CREATE TABLE IF NOT EXISTS players (id INTEGER PRIMARY KEY, name TEXT NOT NULL UNIQUE, password TEXT NOT NULL, level INTEGER)" }, + { 1, "CREATE TABLE IF NOT EXISTS NEXT_ID (ID DECIMAL(9,0) NOT NULL)" }, + { 1, "INSERT INTO NEXT_ID (ID) VALUES(1)"}, + {-1, NULL } // Sentinel to identify end of commands. DO NOT REMOVE. +}; + + + +/* + * Open the global database. + * + */ bool db_open() { @@ -18,24 +46,34 @@ bool db_open() db_close(); - return FALSE; + return false; } - return TRUE; + return true; } +/* + * Close the global database. + * + */ + bool db_close() { if (sqlite3_close(db) != SQLITE_OK ) { bug("Unable to close database: %s", sqlite3_errmsg(db)); - return FALSE; + return false; } - return TRUE; + return true; } +/* + * Execute a query to the database expecting no answer. + * Used for things like DROP, INSERT, CREATE TABLE... + */ + bool db_execute(const char *sql, ...) { va_list vars; @@ -48,23 +86,22 @@ bool db_execute(const char *sql, ...) va_end(vars); if ( stmt == NULL ) { - return FALSE; + return false; } - if ( db_step(stmt) != SQLITE_DONE ) { bug("Failed to step through statement: %s", sqlite3_errmsg(db)); - return FALSE; + return false; } if ( db_finalize(stmt) != SQLITE_OK ) { bug("Failed to finalize statement: %s", sqlite3_errmsg(db)); - return FALSE; + return false; } - return TRUE; + return true; } sqlite3_stmt *db_prepare(const char *sql, ...) @@ -173,18 +210,81 @@ sqlite3_stmt *db_prepare_internal(const char *sql, va_list vars) void db_migrate() { + int db_schema = get_db_schema(); + int i = 0; + if ( !db_open() ) { abort(); } - /* players table */ - if ( !db_execute("CREATE TABLE IF NOT EXISTS players (id INTEGER PRIMARY KEY, name TEXT NOT NULL UNIQUE, password TEXT NOT NULL, level INTEGER)") ) + if (-1 == db_schema) { + if( !db_execute("CREATE TABLE IF NOT EXISTS DB_SCHEMA (db_version DECIMAL(6,0) NOT NULL)") + || !db_execute("INSERT INTO DB_SCHEMA (db_version) VALUES(1)")) { + abort(); + } + } + + while(command[i].schema != -1) { + if (command[i].schema > db_schema) { + if ( !db_execute(command[i].action) ) { + abort(); + } + } + if( !db_execute("UPDATE DB_SCHEMA SET db_version = %i", command[i].schema) ) { + abort(); + } + i++; + } + + if(command[i-1].schema > db_schema ) { + log_string("db_schema updated to version %d", command[i-1].schema); + } else { + log_string("Current db_schema: %d", db_schema); + } + + db_close(); + + return; +} + + +/* + * Retrieve the schema version. + * + * SELECT db_version FROM DB_SCHEMA + * + */ + +int get_db_schema() +{ + sqlite3_stmt *stmt; + int db_schema = -1; + + if ( !db_open() ) { abort(); } + stmt = db_prepare("SELECT db_version FROM DB_SCHEMA"); + + if ( stmt == NULL ) + { + db_close(); + return db_schema; + } + + if ( db_step(stmt) == SQLITE_ROW ) { + db_schema = sqlite3_column_int(stmt, 0); + } + + if ( db_finalize(stmt) != SQLITE_OK ) { + bug("Failed to finalize statement: %s", sqlite3_errmsg(db)); + + abort(); + } + db_close(); - return; + return db_schema; } diff --git a/src/db.h b/src/db.h new file mode 100644 index 0000000..89c5ccf --- /dev/null +++ b/src/db.h @@ -0,0 +1,23 @@ +/* file: db.h + * + * Headerfile for sqlite interface + */ + +#ifndef _DB_HEADER +#define _DB_HEADER + +#include +#include + +/* + * db.c + */ +bool db_open ( void ); +bool db_close ( void ); +bool db_execute ( const char *sql, ... ); +sqlite3_stmt *db_prepare (const char *sql, ...); +int db_step (sqlite3_stmt *stmt); +int db_finalize (sqlite3_stmt *stmt); +void db_migrate ( void ); + +#endif diff --git a/src/event-handler.c b/src/event-handler.c index 8b712fd..c48cb5d 100644 --- a/src/event-handler.c +++ b/src/event-handler.c @@ -3,6 +3,8 @@ #include #include #include +#include + /* include main header file */ #include "mud.h" @@ -28,7 +30,7 @@ bool enqueue_event(EVENT_DATA *event, int game_pulses) if (event->ownertype == EVENT_UNOWNED) { bug("enqueue_event: event type %d with no owner.", event->type); - return FALSE; + return false; } /* An event must be enqueued into the future */ @@ -49,7 +51,7 @@ bool enqueue_event(EVENT_DATA *event, int game_pulses) AttachToList(event, eventqueue[bucket]); /* success */ - return TRUE; + return true; } /* function :: dequeue_event() @@ -181,7 +183,7 @@ void heartbeat() * * bool event_function ( EVENT_DATA *event ); * - * Any event returning TRUE is not dequeued, it is assumed + * Any event returning true is not dequeued, it is assumed * that the event has dequeued itself. */ if (!((*event->fun)(event))) @@ -221,7 +223,7 @@ void add_event_mobile(EVENT_DATA *event, D_MOBILE *dMob, int delay) AttachToList(event, dMob->events); /* attempt to enqueue the event */ - if (enqueue_event(event, delay) == FALSE) + if (enqueue_event(event, delay) == false) bug("add_event_mobile: event type %d failed to be enqueued.", event->type); } @@ -256,7 +258,7 @@ void add_event_socket(EVENT_DATA *event, D_SOCKET *dSock, int delay) AttachToList(event, dSock->events); /* attempt to enqueue the event */ - if (enqueue_event(event, delay) == FALSE) + if (enqueue_event(event, delay) == false) bug("add_event_socket: event type %d failed to be enqueued.", event->type); } @@ -290,7 +292,7 @@ void add_event_game(EVENT_DATA *event, int delay) AttachToList(event, global_events); /* attempt to enqueue the event */ - if (enqueue_event(event, delay) == FALSE) + if (enqueue_event(event, delay) == false) bug("add_event_game: event type %d failed to be enqueued.", event->type); } diff --git a/src/event.c b/src/event.c index 356f6c3..509df21 100644 --- a/src/event.c +++ b/src/event.c @@ -2,6 +2,7 @@ #include #include #include +#include /* include main header file */ #include "mud.h" @@ -28,7 +29,7 @@ bool event_game_tick(EVENT_DATA *event) event->type = EVENT_GAME_TICK; add_event_game(event, 10 * 60 * PULSES_PER_SECOND); - return FALSE; + return false; } bool event_mobile_save(EVENT_DATA *event) @@ -36,13 +37,13 @@ bool event_mobile_save(EVENT_DATA *event) D_MOBILE *dMob; /* Check to see if there is an owner of this event. - * If there is no owner, we return TRUE, because + * If there is no owner, we return true, because * it's the safest - and post a bug message. */ if ((dMob = event->owner.dMob) == NULL) { bug("event_mobile_save: no owner."); - return TRUE; + return true; } /* save the actual player file */ @@ -54,7 +55,7 @@ bool event_mobile_save(EVENT_DATA *event) event->type = EVENT_MOBILE_SAVE; add_event_mobile(event, dMob, 2 * 60 * PULSES_PER_SECOND); - return FALSE; + return false; } bool event_socket_idle(EVENT_DATA *event) @@ -62,22 +63,22 @@ bool event_socket_idle(EVENT_DATA *event) D_SOCKET *dSock; /* Check to see if there is an owner of this event. - * If there is no owner, we return TRUE, because + * If there is no owner, we return true, because * it's the safest - and post a bug message. */ if ((dSock = event->owner.dSock) == NULL) { bug("event_socket_idle: no owner."); - return TRUE; + return true; } /* tell the socket that it has idled out, and close it */ text_to_socket(dSock, "You have idled out...\n\n\r"); - close_socket(dSock, FALSE); + close_socket(dSock, false); /* since we closed the socket, all events owned * by that socket has been dequeued, and we need - * to return TRUE, so the caller knows this. + * to return true, so the caller knows this. */ - return TRUE; + return true; } diff --git a/src/gmcp.c b/src/gmcp.c index 9980938..0986355 100644 --- a/src/gmcp.c +++ b/src/gmcp.c @@ -7,6 +7,8 @@ #include #include #include +#include + #include "mud.h" const unsigned char gmcp_head [] = { IAC, SB, TELOPT_GMCP, 0 }; @@ -14,7 +16,7 @@ const unsigned char gmcp_tail [] = { IAC, SE, 0 }; bool gmcpEnable(D_S *dsock) { - dsock->gmcp_enabled = TRUE; + dsock->gmcp_enabled = true; gmcpSend(dsock, "Test data"); return dsock->gmcp_enabled; } @@ -22,12 +24,12 @@ bool gmcpEnable(D_S *dsock) bool gmcpSend(D_S *dsock, const char *data) { if (!dsock->gmcp_enabled) - return FALSE; + return false; text_to_socket(dsock, (char *) gmcp_head); text_to_socket(dsock, (char *) data); text_to_socket(dsock, (char *) gmcp_tail); - return TRUE; + return true; } void gmcpReceived(D_S *dsock) diff --git a/src/help.c b/src/help.c index f903774..be9e537 100644 --- a/src/help.c +++ b/src/help.c @@ -12,6 +12,8 @@ #include #include #include +#include + /* include main header file */ #include "mud.h" @@ -39,7 +41,7 @@ bool check_help(D_MOBILE *dMob, char *helpfile) ITERATOR Iter; char buf[MAX_HELP_ENTRY + 80]; char *entry, *hFile; - bool found = FALSE; + bool found = false; hFile = capitalize(helpfile); @@ -48,7 +50,7 @@ bool check_help(D_MOBILE *dMob, char *helpfile) { if (is_prefix(helpfile, pHelp->keyword)) { - found = TRUE; + found = true; break; } } @@ -67,10 +69,10 @@ bool check_help(D_MOBILE *dMob, char *helpfile) { /* helpfiles do not contain double dots (no moving out of the helpdir) */ if (strstr(hFile, "..") != NULL) - return FALSE; + return false; if ((entry = read_help_entry(hFile)) == NULL) - return FALSE; + return false; else { if ((pHelp = (HELP_DATA *) malloc(sizeof(*pHelp))) == NULL) @@ -88,7 +90,7 @@ bool check_help(D_MOBILE *dMob, char *helpfile) snprintf(buf, MAX_HELP_ENTRY + 80, "=== %s ===\n\r%s", pHelp->keyword, pHelp->text); text_to_mobile(dMob, buf); - return TRUE; + return true; } /* diff --git a/src/interpret.c b/src/interpret.c index 648b6ca..a847925 100644 --- a/src/interpret.c +++ b/src/interpret.c @@ -3,6 +3,7 @@ */ #include #include +#include /* include main header file */ #include "mud.h" @@ -11,7 +12,7 @@ void handle_cmd_input(D_SOCKET *dsock, char *arg) { D_MOBILE *dMob; char command[MAX_BUFFER]; - bool found_cmd = FALSE; + bool found_cmd = false; int i; if ((dMob = dsock->player) == NULL) @@ -25,7 +26,7 @@ void handle_cmd_input(D_SOCKET *dsock, char *arg) if (is_prefix(command, tabCmd[i].cmd_name)) { - found_cmd = TRUE; + found_cmd = true; (*tabCmd[i].cmd_funct)(dMob, arg); } } diff --git a/src/io.c b/src/io.c index 93e5dfd..6ea8df8 100644 --- a/src/io.c +++ b/src/io.c @@ -9,6 +9,7 @@ #include #include #include +#include /* include main header file */ #include "mud.h" @@ -176,7 +177,7 @@ char *fread_line(FILE *fp) int fread_number(FILE *fp) { int c, number = 0; - bool negative = FALSE; + bool negative = false; /* initial read */ c = getc(fp); @@ -192,7 +193,7 @@ int fread_number(FILE *fp) abort(); } else if (c == '-') - negative = TRUE; + negative = true; else if (!isdigit(c)) { bug("Fread_number: Not a number."); diff --git a/src/main.c b/src/main.c index e03bdeb..c4b0ec9 100644 --- a/src/main.c +++ b/src/main.c @@ -15,9 +15,11 @@ #include #include #include +#include /* including main header file */ #include "mud.h" +#include "db.h" /* * This is where it all starts, nothing special. @@ -46,10 +48,10 @@ int main(int argc, char **argv) if (argc > 2 && !strcmp(argv[argc-1], "copyover") && atoi(argv[argc-2]) > 0) { - fCopyOver = TRUE; + fCopyOver = true; control = atoi(argv[argc-2]); } - else fCopyOver = FALSE; + else fCopyOver = false; /* initialize the socket */ if (!fCopyOver) diff --git a/src/mccp.c b/src/mccp.c index 51a26f5..13b1e2a 100644 --- a/src/mccp.c +++ b/src/mccp.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "mud.h" @@ -46,7 +47,7 @@ bool compressStart(D_SOCKET *dsock, unsigned char teleopt) /* already compressing */ if (dsock->out_compress) - return TRUE; + return true; /* allocate and init stream, buffer */ s = (z_stream *) malloc(sizeof(*s)); @@ -64,7 +65,7 @@ bool compressStart(D_SOCKET *dsock, unsigned char teleopt) { free(dsock->out_compress_buf); free(s); - return FALSE; + return false; } /* version 1 or 2 support */ @@ -77,7 +78,7 @@ bool compressStart(D_SOCKET *dsock, unsigned char teleopt) bug("Bad teleoption %d passed", teleopt); free(dsock->out_compress_buf); free(s); - return FALSE; + return false; } /* now we're compressing */ @@ -85,7 +86,7 @@ bool compressStart(D_SOCKET *dsock, unsigned char teleopt) dsock->out_compress = s; /* success */ - return TRUE; + return true; } /* Cleanly shut down compression on `desc' */ @@ -94,10 +95,10 @@ bool compressEnd(D_SOCKET *dsock, unsigned char teleopt, bool forced) unsigned char dummy[1]; if (!dsock->out_compress) - return TRUE; + return true; if (dsock->compressing != teleopt) - return FALSE; + return false; dsock->out_compress->avail_in = 0; dsock->out_compress->next_in = dummy; @@ -105,11 +106,11 @@ bool compressEnd(D_SOCKET *dsock, unsigned char teleopt, bool forced) /* No terminating signature is needed - receiver will get Z_STREAM_END */ if (deflate(dsock->out_compress, Z_FINISH) != Z_STREAM_END && !forced) - return FALSE; + return false; /* try to send any residual data */ if (!processCompressed(dsock) && !forced) - return FALSE; + return false; /* reset compression values */ deflateEnd(dsock->out_compress); @@ -120,7 +121,7 @@ bool compressEnd(D_SOCKET *dsock, unsigned char teleopt, bool forced) dsock->out_compress_buf = NULL; /* success */ - return TRUE; + return true; } /* Try to send any pending compressed-but-not-sent data in `desc' */ @@ -129,7 +130,7 @@ bool processCompressed(D_SOCKET *dsock) int iStart, nBlock, nWrite, len; if (!dsock->out_compress) - return TRUE; + return true; len = dsock->out_compress->next_out - dsock->out_compress_buf; if (len > 0) @@ -143,7 +144,7 @@ bool processCompressed(D_SOCKET *dsock) break; /* write error */ - return FALSE; + return false; } if (nWrite <= 0) break; @@ -159,5 +160,5 @@ bool processCompressed(D_SOCKET *dsock) } /* success */ - return TRUE; + return true; } diff --git a/src/mud.h b/src/mud.h index d3c77a0..4e88c79 100644 --- a/src/mud.h +++ b/src/mud.h @@ -13,19 +13,12 @@ #include "list.h" #include "stack.h" #include "crypt_blowfish-1.3-mini/ow-crypt.h" +#include "mud.h" /************************ * Standard definitions * ************************/ -/* define TRUE and FALSE */ -#ifndef FALSE -#define FALSE 0 -#endif -#ifndef TRUE -#define TRUE 1 -#endif - #define eTHIN 0 #define eBOLD 1 @@ -65,7 +58,6 @@ #define COMM_LOG 10 /* admins only */ /* define simple types */ -typedef unsigned char bool; typedef short int sh_int; @@ -78,14 +70,14 @@ typedef short int sh_int; ***********************/ #define UMIN(a, b) ((a) < (b) ? (a) : (b)) -#define IS_ADMIN(dMob) ((dMob->level) > LEVEL_PLAYER ? TRUE : FALSE) +#define IS_ADMIN(dMob) ((dMob->level) > LEVEL_PLAYER ? true : false) #define IREAD(sKey, sPtr) \ { \ if (!strcasecmp(sKey, word)) \ { \ int sValue = fread_number(fp); \ sPtr = sValue; \ - found = TRUE; \ + found = true; \ break; \ } \ } @@ -94,7 +86,7 @@ typedef short int sh_int; if (!strcasecmp(sKey, word)) \ { \ sPtr = fread_string(fp); \ - found = TRUE; \ + found = true; \ break; \ } \ } @@ -326,16 +318,6 @@ void save_player ( D_M *dMob ); D_M *load_player ( char *player ); D_M *load_profile ( char *player ); -/* - * db.c - */ -bool db_open ( void ); -bool db_close ( void ); -bool db_execute ( const char *sql, ... ); -sqlite3_stmt *db_prepare (const char *sql, ...); -int db_step (sqlite3_stmt *stmt); -int db_finalize (sqlite3_stmt *stmt); -void db_migrate ( void ); /******************************* * End of prototype declartion * diff --git a/src/save.c b/src/save.c index 4648366..b2fbedd 100644 --- a/src/save.c +++ b/src/save.c @@ -3,9 +3,11 @@ #include #include #include +#include /* main header file */ #include "mud.h" +#include "db.h" void save_player(D_MOBILE *dMob) { diff --git a/src/socket.c b/src/socket.c index 02378e7..5e10725 100644 --- a/src/socket.c +++ b/src/socket.c @@ -17,6 +17,7 @@ #include #include #include +#include /* including main header file */ #include "mud.h" @@ -39,7 +40,7 @@ const unsigned char gmcp_will [] = { IAC, WILL, TELOPT_GMCP, '\0' }; void GameLoop ( int control ); /* intialize shutdown state */ -bool shut_down = FALSE; +bool shut_down = false; int control; void GameLoop(int control) @@ -101,7 +102,7 @@ void GameLoop(int control) */ if (FD_ISSET(dsock->control, &rFd) && !read_from_socket(dsock)) { - close_socket(dsock, FALSE); + close_socket(dsock, false); continue; } @@ -136,7 +137,7 @@ void GameLoop(int control) /* Send all new data to the socket and close it if any errors occour */ if (!flush_output(dsock)) - close_socket(dsock, FALSE); + close_socket(dsock, false); } DetachIterator(&Iter); @@ -316,7 +317,7 @@ bool new_socket(int sock) init_events_socket(sock_new); /* everything went as it was supposed to */ - return TRUE; + return true; } /* @@ -377,7 +378,7 @@ bool read_from_socket(D_SOCKET *dsock) if (size >= sizeof(dsock->inbuf) - 2) { text_to_socket(dsock, "\n\r!!!! Input Overflow !!!!\n\r"); - return FALSE; + return false; } /* start reading from the socket */ @@ -398,18 +399,18 @@ bool read_from_socket(D_SOCKET *dsock) else if (sInput == 0) { log_string("Read_from_socket: EOF"); - return FALSE; + return false; } else if (errno == EAGAIN || sInput == wanted) break; else { perror("Read_from_socket"); - return FALSE; + return false; } } dsock->inbuf[size] = '\0'; - return TRUE; + return true; } /* @@ -439,7 +440,7 @@ bool text_to_socket(D_SOCKET *dsock, const char *txt) int status = deflate(dsock->out_compress, Z_SYNC_FLUSH); if (status != Z_OK) - return FALSE; + return false; } length = dsock->out_compress->next_out - dsock->out_compress_buf; @@ -451,7 +452,7 @@ bool text_to_socket(D_SOCKET *dsock, const char *txt) if ((iWrt = write(control, dsock->out_compress_buf + iPtr, iBlck)) < 0) { perror("Text_to_socket (compressed):"); - return FALSE; + return false; } } if (iWrt <= 0) break; @@ -464,7 +465,7 @@ bool text_to_socket(D_SOCKET *dsock, const char *txt) } } } - return TRUE; + return true; } /* write uncompressed */ @@ -474,11 +475,11 @@ bool text_to_socket(D_SOCKET *dsock, const char *txt) if ((iWrt = write(control, txt + iPtr, iBlck)) < 0) { perror("Text_to_socket:"); - return FALSE; + return false; } } - return TRUE; + return true; } /* @@ -492,7 +493,7 @@ bool text_to_socket(D_SOCKET *dsock, const char *txt) void text_to_buffer(D_SOCKET *dsock, const char *txt) { static char output[8 * MAX_BUFFER]; - bool underline = FALSE, bold = FALSE; + bool underline = false, bold = false; int iPtr = 0, last = -1, j, k; int length = strlen(txt); @@ -562,7 +563,7 @@ void text_to_buffer(D_SOCKET *dsock, const char *txt) txt++; if (underline) { - underline = FALSE; + underline = false; output[iPtr++] = 27; output[iPtr++] = '['; output[iPtr++] = '0'; if (bold) { @@ -580,7 +581,7 @@ void text_to_buffer(D_SOCKET *dsock, const char *txt) } else { - underline = TRUE; + underline = true; output[iPtr++] = 27; output[iPtr++] = '['; output[iPtr++] = '4'; output[iPtr++] = 'm'; } @@ -599,8 +600,8 @@ void text_to_buffer(D_SOCKET *dsock, const char *txt) txt++; if (last != -1 || underline || bold) { - underline = FALSE; - bold = FALSE; + underline = false; + bold = false; output[iPtr++] = 27; output[iPtr++] = '['; output[iPtr++] = '0'; output[iPtr++] = 'm'; } @@ -611,31 +612,31 @@ void text_to_buffer(D_SOCKET *dsock, const char *txt) /* check for valid color tag and parse */ else { - bool validTag = FALSE; + bool validTag = false; for (j = 0; ansiTable[j].cString[0] != '\0'; j++) { if (*txt == ansiTable[j].cTag) { - validTag = TRUE; + validTag = true; /* we only add the color sequence if it's needed */ if (last != j) { - bool cSequence = FALSE; + bool cSequence = false; /* escape sequence */ output[iPtr++] = 27; output[iPtr++] = '['; /* remember if a color change is needed */ if (last == -1 || last / 2 != j / 2) - cSequence = TRUE; + cSequence = true; /* handle font boldness */ if (bold && ansiTable[j].aFlag == eTHIN) { output[iPtr++] = '0'; - bold = FALSE; + bold = false; if (underline) { @@ -644,12 +645,12 @@ void text_to_buffer(D_SOCKET *dsock, const char *txt) /* changing to eTHIN wipes the old color */ output[iPtr++] = ';'; - cSequence = TRUE; + cSequence = true; } else if (!bold && ansiTable[j].aFlag == eBOLD) { output[iPtr++] = '1'; - bold = TRUE; + bold = true; if (cSequence) output[iPtr++] = ';'; @@ -713,14 +714,14 @@ void text_to_mobile(D_MOBILE *dMob, const char *txt) if (dMob->socket) { text_to_buffer(dMob->socket, txt); - dMob->socket->bust_prompt = TRUE; + dMob->socket->bust_prompt = true; } } void next_cmd_from_buffer(D_SOCKET *dsock) { int size = 0, i = 0, j = 0, telopt = 0; - bool gmcp = FALSE; + bool gmcp = false; /* if theres already a command ready, we return */ if (dsock->next_command[0] != '\0') @@ -755,7 +756,7 @@ void next_cmd_from_buffer(D_SOCKET *dsock) else if (telopt == 1 && gmcp && dsock->inbuf[i] == (signed char) SE) { telopt = 0; - gmcp = FALSE; + gmcp = false; dsock->next_command[j] = '\0'; gmcpReceived(dsock); dsock->next_command[j = 0] = '\0'; @@ -769,21 +770,21 @@ void next_cmd_from_buffer(D_SOCKET *dsock) if (dsock->inbuf[i-1] == (signed char) DO) /* start compressing */ compressStart(dsock, TELOPT_COMPRESS); else if (dsock->inbuf[i-1] == (signed char) DONT) /* stop compressing */ - compressEnd(dsock, TELOPT_COMPRESS, FALSE); + compressEnd(dsock, TELOPT_COMPRESS, false); } else if (dsock->inbuf[i] == (signed char) TELOPT_COMPRESS2) /* check for version 2 */ { if (dsock->inbuf[i-1] == (signed char) DO) /* start compressing */ compressStart(dsock, TELOPT_COMPRESS2); else if (dsock->inbuf[i-1] == (signed char) DONT) /* stop compressing */ - compressEnd(dsock, TELOPT_COMPRESS2, FALSE); + compressEnd(dsock, TELOPT_COMPRESS2, false); } else if (dsock->inbuf[i] == (signed char) TELOPT_GMCP) /* check for gmcp */ { if (dsock->inbuf[i-1] == (signed char) DO) gmcpEnable(dsock); else if (dsock->inbuf[i-1] == (signed char) SB) { - gmcp = TRUE; + gmcp = true; } } } @@ -797,7 +798,7 @@ void next_cmd_from_buffer(D_SOCKET *dsock) /* skip forward to the next line */ while (dsock->inbuf[size] == '\n' || dsock->inbuf[size] == '\r') { - dsock->bust_prompt = TRUE; /* seems like a good place to check */ + dsock->bust_prompt = true; /* seems like a good place to check */ size++; } @@ -817,27 +818,27 @@ bool flush_output(D_SOCKET *dsock) { /* nothing to send */ if (dsock->top_output <= 0 && !(dsock->bust_prompt && dsock->state == STATE_PLAYING)) - return TRUE; + return true; /* bust a prompt */ if (dsock->state == STATE_PLAYING && dsock->bust_prompt) { text_to_buffer(dsock, "\n\rSocketMud:> "); - dsock->bust_prompt = FALSE; + dsock->bust_prompt = false; } /* reset the top pointer */ dsock->top_output = 0; /* - * Send the buffer, and return FALSE + * Send the buffer, and return false * if the write fails. */ if (!text_to_socket(dsock, dsock->outbuf)) - return FALSE; + return false; /* Success */ - return TRUE; + return true; } void handle_new_connections(D_SOCKET *dsock, char *arg) @@ -975,7 +976,7 @@ void handle_new_connections(D_SOCKET *dsock, char *arg) text_to_socket(dsock, "ERROR: Your pfile is missing!\n\r"); free_mobile(dsock->player); dsock->player = NULL; - close_socket(dsock, FALSE); + close_socket(dsock, false); return; } else @@ -1006,7 +1007,7 @@ void handle_new_connections(D_SOCKET *dsock, char *arg) text_to_socket(dsock, "Bad password!\n\r"); free_mobile(dsock->player); dsock->player = NULL; - close_socket(dsock, FALSE); + close_socket(dsock, false); } break; } @@ -1022,7 +1023,7 @@ void clear_socket(D_SOCKET *sock_new, int sock) sock_new->player = NULL; sock_new->top_output = 0; sock_new->events = AllocList(); - sock_new->gmcp_enabled = FALSE; + sock_new->gmcp_enabled = false; } /* does the lookup, changes the hostname, and dies */ @@ -1076,7 +1077,7 @@ void recycle_sockets() FreeList(dsock->events); /* stop compression */ - compressEnd(dsock, dsock->compressing, TRUE); + compressEnd(dsock, dsock->compressing, true); /* put the socket in the free stack */ PushStack(dsock, dsock_free); diff --git a/src/strings.c b/src/strings.c index 443b2c5..fa86c58 100644 --- a/src/strings.c +++ b/src/strings.c @@ -7,6 +7,7 @@ #include #include #include +#include /* include main header file */ #include "mud.h" @@ -17,20 +18,20 @@ bool is_prefix(const char *aStr, const char *bStr) { /* NULL strings never compares */ - if (aStr == NULL || bStr == NULL) return FALSE; + if (aStr == NULL || bStr == NULL) return false; /* empty strings never compares */ - if (aStr[0] == '\0' || bStr[0] == '\0') return FALSE; + if (aStr[0] == '\0' || bStr[0] == '\0') return false; /* check if aStr is a prefix of bStr */ while (*aStr) { if (tolower(*aStr++) != tolower(*bStr++)) - return FALSE; + return false; } /* success */ - return TRUE; + return true; } char *one_arg(char *fStr, char *bStr) diff --git a/src/utils.c b/src/utils.c index 23626d7..58a39c5 100644 --- a/src/utils.c +++ b/src/utils.c @@ -8,13 +8,15 @@ #include #include #include +#include + /* include main header file */ #include "mud.h" /* * Check to see if a given name is - * legal, returning FALSE if it + * legal, returning false if it * fails our high standards... */ bool check_name(const char *name) @@ -22,12 +24,12 @@ bool check_name(const char *name) int size, i; if ((size = strlen(name)) < 3 || size > 12) - return FALSE; + return false; for (i = 0 ;i < size; i++) - if (!isalpha(name[i])) return FALSE; + if (!isalpha(name[i])) return false; - return TRUE; + return true; } void clear_mobile(D_MOBILE *dMob) @@ -183,19 +185,19 @@ void copyover_recover() } else /* ah bugger */ { - close_socket(dsock, FALSE); + close_socket(dsock, false); continue; } /* Write something, and check if it goes error-free */ if (!text_to_socket(dsock, "\n\r <*> And before you know it, everything has changed <*>\n\r")) { - close_socket(dsock, FALSE); + close_socket(dsock, false); continue; } /* make sure the socket can be used */ - dsock->bust_prompt = TRUE; + dsock->bust_prompt = true; dsock->lookup_status = TSTATE_DONE; dsock->state = STATE_PLAYING; @@ -218,7 +220,7 @@ D_MOBILE *check_reconnect(char *player) { if (dMob->socket) { - close_socket(dMob->socket, TRUE); + close_socket(dMob->socket, true); } break; diff --git a/tests/test_crypt.test b/tests/test_crypt.test index e751ef4..0309750 100644 --- a/tests/test_crypt.test +++ b/tests/test_crypt.test @@ -5,6 +5,7 @@ #include #include #include +#include #include "mud.h" diff --git a/tests/test_list.test b/tests/test_list.test index 8bc59b1..c848e36 100644 --- a/tests/test_list.test +++ b/tests/test_list.test @@ -5,6 +5,7 @@ #include #include #include +#include #include "mud.h" diff --git a/tests/test_stack.test b/tests/test_stack.test index 2266e10..aa29a2f 100644 --- a/tests/test_stack.test +++ b/tests/test_stack.test @@ -5,6 +5,7 @@ #include #include #include +#include #include "mud.h" diff --git a/tests/test_strings.test b/tests/test_strings.test index b961378..872f38f 100644 --- a/tests/test_strings.test +++ b/tests/test_strings.test @@ -5,6 +5,7 @@ #include #include #include +#include #include "mud.h" @@ -12,12 +13,12 @@ #tcase check_is_prefix #test is_prefix_A_A - ck_assert_msg(TRUE == is_prefix("A", "A"), "is_prefix A, A should have returned true"); + ck_assert_msg(true == is_prefix("A", "A"), "is_prefix A, A should have returned true"); #test is_prefix_A_AA - ck_assert_msg(TRUE == is_prefix("A", "AA"), "is_prefix A, AA should have returned true"); + ck_assert_msg(true == is_prefix("A", "AA"), "is_prefix A, AA should have returned true"); #test is_prefix_A_AAA - ck_assert_msg(TRUE == is_prefix("A", "AAA"), "is_prefix A, AAA should have returned true"); + ck_assert_msg(true == is_prefix("A", "AAA"), "is_prefix A, AAA should have returned true"); #test is_prefix_A_AAAZ - ck_assert_msg(TRUE == is_prefix("A", "AAAZ"), "is_prefix A, AAAZ should have returned true"); + ck_assert_msg(true == is_prefix("A", "AAAZ"), "is_prefix A, AAAZ should have returned true"); #test is_prefix_A_B_fail - ck_assert_msg(TRUE != is_prefix("A", "B"), "is_prefix A, B should have returned false"); \ No newline at end of file + ck_assert_msg(true != is_prefix("A", "B"), "is_prefix A, B should have returned false"); \ No newline at end of file diff --git a/tests/test_utils.test b/tests/test_utils.test index da4f04d..89ca588 100644 --- a/tests/test_utils.test +++ b/tests/test_utils.test @@ -5,6 +5,7 @@ #include #include #include +#include #include "mud.h" @@ -12,16 +13,16 @@ #tcase check_name #test check_name_valid - ck_assert_msg(TRUE == check_name("abc"), "check_name abc must not fail is an alpha string >=3 and <=12"); - ck_assert_msg(TRUE == check_name("ALFA"), "check_name ALFA must not fail is an alpha string >=3 and <=12"); - ck_assert_msg(TRUE == check_name("OMEGA"), "check_name OMEGA must not fail is an alpha string >=3 and <=12"); - ck_assert_msg(TRUE == check_name("first"), "check_name first must not fail is an alpha string >=3 and <=12"); - ck_assert_msg(TRUE == check_name("second"), "check_name second must not fail is an alpha string >=3 and <=12"); - ck_assert_msg(TRUE == check_name("abcdefghijkl"), "check_name abcdefghijkl must not fail is an alpha string >=3 and <=12"); + ck_assert_msg(true == check_name("abc"), "check_name abc must not fail is an alpha string >=3 and <=12"); + ck_assert_msg(true == check_name("ALFA"), "check_name ALFA must not fail is an alpha string >=3 and <=12"); + ck_assert_msg(true == check_name("OMEGA"), "check_name OMEGA must not fail is an alpha string >=3 and <=12"); + ck_assert_msg(true == check_name("first"), "check_name first must not fail is an alpha string >=3 and <=12"); + ck_assert_msg(true == check_name("second"), "check_name second must not fail is an alpha string >=3 and <=12"); + ck_assert_msg(true == check_name("abcdefghijkl"), "check_name abcdefghijkl must not fail is an alpha string >=3 and <=12"); #test check_name_fail - ck_assert_msg(FALSE == check_name("guild mud"), "check_name /guild mud/ must fail because has an /space/"); - ck_assert_msg(FALSE == check_name("ab"), "check_name /ab/ must fail because has less < 3 characters"); - ck_assert_msg(FALSE == check_name("abcdefghijklm"), "check_name /abcdefghijklm/ must fail because has > 13 chars"); - ck_assert_msg(FALSE == check_name("guild*mud"), "check_name /guild*mud/ must fail because has an /*/"); - ck_assert_msg(FALSE == check_name("guild1mud"), "check_name /guild1mud/ must fail because has an /1/"); \ No newline at end of file + ck_assert_msg(false == check_name("guild mud"), "check_name /guild mud/ must fail because has an /space/"); + ck_assert_msg(false == check_name("ab"), "check_name /ab/ must fail because has less < 3 characters"); + ck_assert_msg(false == check_name("abcdefghijklm"), "check_name /abcdefghijklm/ must fail because has > 13 chars"); + ck_assert_msg(false == check_name("guild*mud"), "check_name /guild*mud/ must fail because has an /*/"); + ck_assert_msg(false == check_name("guild1mud"), "check_name /guild1mud/ must fail because has an /1/"); \ No newline at end of file