#pragma save_binary // /adm/daemons/i3news.c // Tim // Can do things with an I3 news article. // Restore, Save, Write, Query // // Loosely based on the /adm/daemons/mailmesg.c that comes with TMI-2. // Original comments throughout mention Mobydick and Leto. #include #define WHO find_player("tim") #define DEBUG(x) if(WHO) message( "debug", "NEWSLOADER MSG: " + x+ "\n", WHO ); #define NOT_NEWS (member_array(base_name(previous_object()), (({ I3_NEWS, I3_NEWS_OB }))) == -1) // Variables // Just for indexing, no saving... static string dir; static int id; // Part of message data... int posting_time; string thread_id; string subject; string poster; string contents; // Prototypes // Setup a message... void set_posting_time(int i){ if(NOT_NEWS) return; posting_time=i; } void set_thread_id(string str){ if(NOT_NEWS) return; thread_id = str; } void set_subject(string str){ if(NOT_NEWS) return; subject = str; } void set_poster(string str){ if(NOT_NEWS) return; poster = str; } void set_contents(string str){ if(NOT_NEWS) return; contents = str; } // Load/Save a message... void set_dir(string str); void set_id(int i); int save_message(); int load_msg(); void refresh(); // Query info int get_posting_time(){ if(NOT_NEWS) return 0; return posting_time; } string get_thread_id(){ if(NOT_NEWS) return "unauthorized"; return thread_id; } string get_subject(){ if(NOT_NEWS) return "unauthorized"; return subject; } string get_poster(){ if(NOT_NEWS) return "unauthorized"; return poster; } string get_contents(){ if(NOT_NEWS) return "unauthorized"; return contents; } void test(){ DEBUG("PO: "+base_name(previous_object())); if(NOT_NEWS) DEBUG("notnews"); } mixed get_data(){ if(NOT_NEWS) return ({ 0, "unauthorized", "unauthorized", "unauthorized", "unauthorized" }); return ({ posting_time, thread_id, subject, poster, contents }); } void set_dir(string str){ if(NOT_NEWS) DEBUG("setdir PO: "+base_name(previous_object())); // if(NOT_NEWS) return; dir=str; } void set_id(int i){ if(NOT_NEWS) return; id = i; } int save_message(){ int ret=0; string file; // if(NOT_NEWS){ return 0; } if(!id) return 0; if(file = I3_NEWS_DIR+dir+"/"+id){ ret = save_object( file, 1); } return ret; } int load_msg(){ string file; if(NOT_NEWS) return 0; refresh(); file = I3_NEWS_DIR+dir+"/"+id; if(!file_exists(file+__SAVE_EXTENSION__)) return 0; return restore_object(file); } void refresh(){ if(NOT_NEWS) return; posting_time = 0; thread_id = ""; subject = ""; poster = ""; contents = ""; } void create() { seteuid(getuid()); refresh(); }