nightmare4_fluffos_v1/
nightmare4_fluffos_v1/bin/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/ChangeLog.old/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/Win32/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/compat/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/compat/simuls/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/include/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/clone/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/command/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/data/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/etc/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/include/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/inherit/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/inherit/master/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/log/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/single/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/single/tests/compiler/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/single/tests/efuns/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/single/tests/operators/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/testsuite/u/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/tmp/
nightmare4_fluffos_v1/fluffos-2.9-ds2.14/windows/
nightmare4_fluffos_v1/lib/cfg/
nightmare4_fluffos_v1/lib/cmds/admins/
nightmare4_fluffos_v1/lib/cmds/common/
nightmare4_fluffos_v1/lib/cmds/creators/include/
nightmare4_fluffos_v1/lib/cmds/creators/include/SCCS/
nightmare4_fluffos_v1/lib/cmds/hm/
nightmare4_fluffos_v1/lib/daemon/services/
nightmare4_fluffos_v1/lib/doc/
nightmare4_fluffos_v1/lib/doc/faq/
nightmare4_fluffos_v1/lib/doc/help/classes/
nightmare4_fluffos_v1/lib/doc/help/creators/
nightmare4_fluffos_v1/lib/doc/help/hm/
nightmare4_fluffos_v1/lib/doc/help/players/
nightmare4_fluffos_v1/lib/doc/help/races/
nightmare4_fluffos_v1/lib/doc/help/religion/
nightmare4_fluffos_v1/lib/doc/mudlib/
nightmare4_fluffos_v1/lib/doc/mudlib/cfg/
nightmare4_fluffos_v1/lib/domains/Ylsrim/
nightmare4_fluffos_v1/lib/domains/Ylsrim/adm/
nightmare4_fluffos_v1/lib/domains/Ylsrim/armour/
nightmare4_fluffos_v1/lib/domains/Ylsrim/fish/
nightmare4_fluffos_v1/lib/domains/Ylsrim/meal/
nightmare4_fluffos_v1/lib/domains/Ylsrim/npc/
nightmare4_fluffos_v1/lib/domains/Ylsrim/virtual/
nightmare4_fluffos_v1/lib/domains/Ylsrim/weapon/
nightmare4_fluffos_v1/lib/domains/Ylsrim/xtra/
nightmare4_fluffos_v1/lib/lib/comp/
nightmare4_fluffos_v1/lib/lib/lvs/
nightmare4_fluffos_v1/lib/lib/std/
nightmare4_fluffos_v1/lib/lib/user/
nightmare4_fluffos_v1/lib/news/
nightmare4_fluffos_v1/lib/obj/
nightmare4_fluffos_v1/lib/obj/include/
nightmare4_fluffos_v1/lib/save/
nightmare4_fluffos_v1/lib/save/kills/a/
nightmare4_fluffos_v1/lib/save/kills/b/
nightmare4_fluffos_v1/lib/save/kills/f/
nightmare4_fluffos_v1/lib/save/kills/m/
nightmare4_fluffos_v1/lib/save/kills/q/
nightmare4_fluffos_v1/lib/save/kills/r/
nightmare4_fluffos_v1/lib/secure/cfg/
nightmare4_fluffos_v1/lib/secure/cfg/classes/
nightmare4_fluffos_v1/lib/secure/cfg/races/SCCS/
nightmare4_fluffos_v1/lib/secure/cmds/creators/include/
nightmare4_fluffos_v1/lib/secure/cmds/players/
nightmare4_fluffos_v1/lib/secure/cmds/players/include/
nightmare4_fluffos_v1/lib/secure/daemon/include/
nightmare4_fluffos_v1/lib/secure/lib/
nightmare4_fluffos_v1/lib/secure/lib/include/
nightmare4_fluffos_v1/lib/secure/lib/net/
nightmare4_fluffos_v1/lib/secure/lib/std/
nightmare4_fluffos_v1/lib/secure/obj/
nightmare4_fluffos_v1/lib/secure/obj/include/
nightmare4_fluffos_v1/lib/secure/save/
nightmare4_fluffos_v1/lib/secure/save/boards/
nightmare4_fluffos_v1/lib/secure/save/votes/
nightmare4_fluffos_v1/lib/spells/
nightmare4_fluffos_v1/lib/verbs/admins/include/
nightmare4_fluffos_v1/lib/verbs/common/
nightmare4_fluffos_v1/lib/verbs/common/include/
nightmare4_fluffos_v1/lib/verbs/creators/
nightmare4_fluffos_v1/lib/verbs/creators/include/
nightmare4_fluffos_v1/lib/verbs/players/include/SCCS/
nightmare4_fluffos_v1/lib/verbs/rooms/
nightmare4_fluffos_v1/lib/verbs/rooms/include/
nightmare4_fluffos_v1/lib/www/
nightmare4_fluffos_v1/old/
nightmare4_fluffos_v1/old/tools/
nightmare4_fluffos_v1/win32/
/*    /secure/daemon/bugs.c
 *    from the Nightmare V Object Library
 *    only useable if you can define PACKAGE_DB
 *    manages the bug database
 *    created by Descartes of Borg 960125
 */

#include <lib.h>

inherit LIB_DAEMON;

#ifdef __PACKAGE_DB__

private int dbConn = -1;

static void create() {
    daemon::create();
    SetNoClean(1);
    Connect();
}

static int Connect() {
    if( dbConn > 0 ) return;
    dbConn = db_connect("nightmare.imaginary.com", "db_nmlp");
    return (dbConn > 0);
}

static int Destruct() {
    int x;
    
    if( !(x = daemon::Destruct()) ) return x;
    if( dbConn != -1 ) db_close(dbConn);
    return x;
}

int eventAssign(int bug, string who) {
    string sql;

    if( !user_exists(convert_name(who)) ) return 0;
    else who = capitalize(who);
    if( dbConn < 1 && !Connect() ) return 0;
    sql = "UPDATE t_bug SET bug_assigned_to = " + who +
      " WHERE bug_id = " + bug;
    tmp = db_exec(dbConn, sql);
    if( arrayp(tmp) && !sizeof(tmp) ) return 1;
    return 0;
}

int eventComment(int bug, string who, string comment) {
    int id;
    
    if( bug < 1 || !who || !comment ) return 0;
    if( !user_exists(who = convert_name(who)) ) return 0;
    if( dbConn < 1 && !Connect() ) return 0;
    if( strlen(comment) > 254 ) comment = comment[0..253];
    tmp = db_exec(dbConn, ("SELECT table_next_id "
			   "FROM t_gen_id "
			   "WHERE table_name = 't_bug_cmnt'"));
    id = tmp[0][0];
    db_exec(dbConn, ("UPDATE t_gen_id "
		     "SET table_next_id = " +(id+1) + " "
		     "WHERE table_name = 't_bug_cmnt'"));
    db_exec(dbConn, ("INSERT INTO t_bug_cmnt "
		     "(bug_cmnt_id, bug_id, bug_cmnt_by, bug_cmnt_text) "
		     "VALUES(" + id + ", " + bug + ", '" + who + "', '" +
		     comment + "')"));
    return 1;
}

int eventComplete(int bug, string who, string resolution) {
    mixed tmp;
    
    if( !resolution || !bug || !who || !user_exists(who) ) return 0;
    if( dbConn < 1 && !Connect() ) return 0;    
    if( strlen(resolution) > 254 ) reolution = resolution[0..253];
    tmp = db_exec(dbConn, ("UPDATE t_bug "
			   "SET bug_res = " + resolution + ", "
			   "    bug_res_date = " + time() + ", "
			   "    bug_res_by = " + convert_name(who) + " "
			   "WHERE bug_id = " + bug_id));
    if( arrayp(tmp) && !sizeof(tmp) ) return 1;
    return 0;
}

int eventDelete(int bug) {
    mixed tmp;
    
    if( !((int)master()->valid_access(({}))) ) return 0;
    if( bug < 1 || dbConn < 1 && !Connect() ) return 0;
    tmp = db_exec(dbConn, ("DELETE from t_bug "
			   "WHERE bug_id = " + bug));
    if( arrayp(tmp) && !sizeof(tmp) ) return 1;
    return 0;
}

int eventReport(mapping data) {
    mixed tmp;
    int id;
    
    if( dbConn < 1 && !Connect() ) return 0;
    tmp = db_exec(dbConn, ("SELECT table_next_id "
			   "FROM t_gen_id "
			   "WHERE table_name = 't_bug'"));
    if( !arrayp(tmp) || sizeof(tmp) != 1 ) return 0;
    id = tmp[0][0];
    tmp = db_exec(dbConn, ("UPDATE t_gen_id "
			   "SET table_next_id = " + (id+1) + " "
			   "WHERE table_name = 't_bug'"));
    if( !arrayp(tmp) || sizeof(tmp) != 0 ) return 0;
    tmp = db_exec(dbConn, ("INSERT INTO t_bug "
			   "(bug_id, bug_type, bug_status, bug_rpt_date, "
			   "bug_rpt_by, bug_rpt_room, bug_room_cre, bug_desc) "
			   "VALUES(" + id + ", 'new report', " + time() + ", "
			   "'" + convert_name(data["bug_rpt_by"]) + "', '" +
			   data["bug_rpt_room"] + "', '" +
			   convert_name(data["bug_room_cre"]) + "', '" +
			   data["bug_desc"] + "')"));
    if( !arrayp(tmp) || sizeof(tmp) ) return 0; /* rollback is no big deal */
    foreach(string *obdata in data["inventory"]) {
	/* Need to make sure the object is in t_inventory
	 * The object *probably* already exists, so catch the error and ignore
	 */
	catch(db_exec(dbConn, ("INSERT INTO t_inventory "
			       "(inventory_id, inventory_cre) "
			       "VALUES('" + obdata[0] + "', '" +
			       obdata[1] + "')")));
	db_exec(dbConn, ("INSERT INTO t_bug_inv "
			 "(bug_id, inventory_id) "
			 "VALUES(" + id + ", '" + obdata[1] + "')"));
    }
    return 1;
}

int GetAssignedBugs(string who) {
    mixed tmp;
    
    if( !who || !user_exists(who = convert_name(who)) ) return -1;
    if( dbConn < 1 && !Connect() ) return -1;
    tmp = db_exec(dbConn, ("SELECT bug_id "
			   "FROM t_bug "
			   "WHERE bug_assigned_to = '" + who + "'"));
    return sizeof(tmp);
}

mapping GetBugs(mapping where_clause) {
    mixed tmp;
    string where = "WHERE ";

    if( sizeof(where_clause) ) {
	foreach(string key, mixed val in where_clause) {
	    where += key + " = ";
	    if( stringp(val) ) where += "'" + val + "' AND ";
	    else where += val + " AND ";
	}
    }
    tmp = db_exec(dbConn, ("SELECT t_bug.bug_id, "
			   "       t_bug.bug_type, "
			   "       t_bug.bug_status, "
			   "       t_bug.bug_rpt_date, "
			   "       t_player.player_cap_name "
			   "       t_bug.bug_rpt_room, "
			   "       t_bug.bug_room_cre, "
			   "       t_bug.bug_desc, "
			   "       t_bug.bug_res, "
			   "       t_bug.bug_res_date, "
			   "       t_bug.bug_res_by, "
			   "       t_bug.bug_assigned_to "
			   "FROM   t_bug, t_player "
			   where +
			   "       t_bug.bug_rpt_by = t_player.player_name "));
    foreach(mixed *row in tmp) {
	ret[row[0]] = ([ "bug_type" : row[1],
			"bug_status" : row[2],
			"bug_rpt_date" : row[3],
			
       
			   
}
#endif