/* SQL NON-BLOCKING Sample #1: Logging Chat * **************************************** * This shows you how to edit your /secure/daemon/chat.c * so you can add SQL logging support. */ // Step 1: Add #include "db.h" to the list of includes in chat.c #include "db.h" // Step 2: Replace the current eventAddLast() with this one: varargs int eventAddLast(string feep, string str, string pchan, string pmsg, string pwho) { string plainmsg; string Chan=feep; if(!chanlast) chanlast=([]); if(!sizeof(chanlast[Chan])) chanlast[Chan] = ({}); if(sizeof(chanlast[Chan]) == 50) chanlast[Chan] = chanlast[Chan][1..sizeof(chanlast[Chan])]; chanlast[Chan] += ({ str }); Chan = GetLocalChannel(Chan); //Log in either SQL or file if (SQL && SQL_CHAT_LOGGING) { //If SQL is enabled int handle; string queries; pwho = escape(pwho); pchan = escape(pchan); pmsg = escape(pmsg); if (Chan == "death") return 1; //Don't log death chan if (Chan == "muds") return 1; //Don't log muds chan... Spammy! if (pwho == "" || pwho == 0) pwho = "(emote)"; //Connect to default non-blocking db with default, low-priviledged credentials handle = SQL_D->sql_connect("", "", "", "", 1); //Rack up all our queries into one big long string. //PRO TIP: Insert Ignore tries to insert, but doesn't error if it's already there queries = "INSERT IGNORE INTO LOG_CHAT_CHANNELS (Name) VALUES (\'" + pchan + "\');"; queries += "INSERT IGNORE INTO LOG_CHAT_CHATTERS (Name) VALUES (\'" + pwho + "\');"; queries += "INSERT INTO LOG_CHAT (Channel,Who,What) " "SELECT LOG_CHAT_CHANNELS.ID, " "LOG_CHAT_CHATTERS.ID, " "\'" + pmsg + "\' " "FROM LOG_CHAT_CHANNELS, LOG_CHAT_CHATTERS " "WHERE LOG_CHAT_CHANNELS.Name = \'" + pchan + "\' AND " "LOG_CHAT_CHATTERS.Name = \'" + pwho + "\'"; //Send them off to the non-blocking server SQL_D->sql_query(handle, queries, 1); //Commit and close the non-blocking server. //SQL_D->sql_commit(handle, 1); //Commit not yet implemented SQL_D->sql_close(handle, 1); } else { Chan = GetLocalChannel(Chan); if(!pchan || pchan == "") pchan = "foo"; plainmsg = "bar"; if(pchan) plainmsg = "<" + pchan + "> "; if(pmsg) plainmsg += pmsg; if(pwho && pwho !="") plainmsg = pwho+" "+plainmsg; if(pchan && pchan != "admin"){ LogIt("["+timestamp()+"] "+plainmsg+"\n", "/log/chan/"+Chan, Chan); } else { LogIt("["+timestamp()+"] "+plainmsg+"\n", "/secure/log/"+Chan, Chan); } return 1; } return 1; }