act_chans.c

act_chans.c · 11.5 KB

From the archive act_chans_1.0.zip

Download the archive   « Back to the archive contents

/*
 * act_chans()
 *
 * This is my channel handler. The orginal code for public_ch
 * Writen by Blade, as is freeware.
 * http://www.algonet.se/~rnen/mud/code.html (only refrence i can find now)
 *
 * This code will dynamicly update a webpage with the list of chat messages
 * in reverse chornilogical order (spelling ;)
 *
 * Uses a linked list to store the chat messages.. since its not saved, every
 * copyover cleans it out.
 *
 * Intregration added with e107 web content magament system, makes it
 * look all nice and pretty ;)
 *
 * Requires the use of htm_colorconvert by Nebiseni of Clandestine mud.
 * In lue of the snippet, just remove the conversion, or filter the
 * strings through strip_color()
 *
 * Licence agreement:
 *
 *  #1: Follow Previous Diku/Merc/Rom Licences, or whatever is applicable
 *      to your codebase.
 *  #2: Email/Contact Myself telling me your using it, and how cool I am
 *  #3: My name and link appearing in your help 'CREDITS' entry
 *  #4: This entire comment must be left in the file, unchanged.
 *
 *  Just remember, what comes around, goes around.
 *
 * -Thri, owner/operator of Vandagard Mud: The Darkness
 * Cyhawk/Thri/Marumine
 *
 * Web addy:    http://vandagard.slayn.net
 * email:       cyhawkx@gmail.com
 * AIM:         CalibanL
 *
 * Special thanks to: Nebseni of Clandestine mud for his contributions
 *      http://cland.dustbite.net/
 * Special thanks to: Drey of Underworld dreams for making a web chatlog for me to copy ;)
 *      http://dreams.daestroke.com
 */

#if defined(macintosh)
#include <types.h>
#else
#include <sys/types.h>
#include <sys/time.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "merc.h"
#include "interp.h"
#include "recycle.h"
#include "tables.h"
#include "act_chans.h"

/* E107 headers, used to fit nicely in with my content management system */
#define E107_HEAD   "<?php require_once(\"class2.php\"); require_once(HEADERF); ?>\n"
#define E107_END    "<?php require_once(FOOTERF); ?>\n"

CHANLOG *chanlog_list;

/*
 * update_chanlist()
 * Updates the channel linked list with the new message
 */
void update_chanlist(char * message, char * time, char * who, char * chan)
{
    CHANLOG * p;
    
    p = malloc(sizeof(CHANLOG));
    p->message      = str_dup(message);
    p->time         = str_dup(time);
    p->name         = str_dup(who);
    p->chan         = str_dup(chan);
    p->next         = chanlog_list;
    chanlog_list    = p;
    
    update_chatlog();
    return;
}

/*
 * update_chatlog()
 *
 * Writes out the chatlog
 */
void update_chatlog(void)
{
    CHANLOG * p;
    FILE * fp;
    char buf[MSL];
    char buf2[MSL];
    
    fclose( fpReserve );
    if ( ( fp = fopen( CHANLOG_FILE, "w" ) ) == NULL )
    {
        log_string("Cannot open channel log file!\n");
        perror( CHANLOG_FILE );
        return;
    }
    /* Print the E107 Header    */
    fprintf(fp, E107_HEAD);
    
    /* Print Information */
    fprintf(fp, "<span style=\"font-size: x-large\">");
    sprintf (buf2, "Recently overheard on {WV{wa{Dn{Rd{ra{Rg{Dr{wa{Wd{D: The {WD{wa{Drkness\n");
    html_colourconv( buf, buf2, NULL );
    fprintf(fp, buf);
    fprintf(fp, "</span><br><br>");
    
    for (p = chanlog_list; p ; p = p->next)
    {
        fprintf(fp, "<span style=\"font-size: medium\">");
        fprintf(fp, "<table width=\"100%%\" cyhawk border=\"0\" align=\"left\" cellpadding=\"1\" cellspacing=\"1\">\n");
        fprintf(fp, "<tr>\n");
        buf[0] = '\0';
        
        /* Time */
        fprintf(fp, "<td width =\"28%%\">");
        sprintf(buf2, "%s", p->time);
        html_colourconv( buf, buf2, NULL );
        fprintf(fp, buf);
        fprintf(fp, "</td>");
        
        /* channel */

        fprintf(fp, "<td>");
        sprintf(buf2, "%s ", p->chan);
        html_colourconv( buf, buf2, NULL );
        fprintf(fp, buf);
        
        /* who */
        sprintf(buf2, "%s says ", p->name);
        html_colourconv( buf, buf2, NULL );
        fprintf(fp, buf);
        
        /* Message */
        sprintf(buf2, "\"%s\"", p->message);
        html_colourconv( buf, buf2, NULL );
        fprintf(fp, buf);
        fprintf(fp, "</td>");
        
    }
    fprintf(fp, E107_END);
    fclose( fp );
    fpReserve = fopen( NULL_FILE, "r" );
    return;
}
    
/*
 * chan_time()
 * A hack to display the time
 */
char * chan_time(void)
{
    time_t rawtime;
    struct tm * timeinfo;
    static char buf[MSL];

    time ( &rawtime );
    timeinfo = localtime ( &rawtime );
    sprintf(buf, "%s", asctime (timeinfo) );
    return buf;
}

void public_ch ( CHAR_DATA *ch, char *argument, char *type, const int bitname)
{
    char buf[MAX_INPUT_LENGTH + 200];
    char command[MAX_INPUT_LENGTH + 100];
    DESCRIPTOR_DATA *d;

    smash_html(argument);
    smash_tilde(argument);
    smash_dollar(argument);
    smash_quote_double(argument);
    smash_quote_single(argument);
    
    if (argument[0] == '\0' )
    {

        if (IS_SET(ch->comm,(bitname)))
        {
            sprintf( buf, "%s channel is now ON.{x\n\r", type);
            send_to_char( buf ,ch);
            REMOVE_BIT(ch->comm,(bitname));
        }
        else
        {
        sprintf( buf, "%s channel is now OFF.{x\n\r", type);
        send_to_char( buf, ch);
        SET_BIT(ch->comm,(bitname));
        }
    }
    else  
    {
        if (IS_SET(ch->comm,COMM_QUIET))
        {
            send_to_char("You must turn off quiet mode first.\n\r",ch);
            return;
        }
        if (IS_SET(ch->comm,COMM_NOCHANNELS))
        {
            send_to_char("The gods have revoked your channel priviliges.\n\r",ch);
            return;
        }
        REMOVE_BIT(ch->comm,(bitname));
        
        update_chanlist(argument, chan_time(), ch->name, type);
        
        argument = one_argument( argument, command );

        if (!str_cmp(command, "wholist"))
        {
            sprintf(command,"{W  Players on %s{x\n\r", type);
            send_to_char(command, ch);
            for ( d = descriptor_list; d != NULL; d = d->next )
            {
                CHAR_DATA *victim;
                victim = d->original ? d->original : d->character;
 
                if ( d->connected == CON_PLAYING &&
                  !IS_SET(victim->comm,(bitname)) &&
                  !IS_SET(victim->comm,COMM_QUIET) )
                {
                    sprintf(buf,"%s\n\r", victim->name);
                    send_to_char(buf, ch);
                }
            }    
            return;
        }
        else if (!str_cmp(argument, ""))
        {
            sprintf( buf, "%s %s '{G%s{x'{x\n\r", type, ch->name, command );
        }
        else
        {
            sprintf( buf, "%s %s: '%s %s'{x\n\r", type, ch->name, command, argument );
        }
        for ( d = descriptor_list; d != NULL; d = d->next )
        {
            CHAR_DATA *victim;
            victim = d->original ? d->original : d->character;
 
            if ( d->connected == CON_PLAYING &&
              !IS_SET(victim->comm,(bitname)) &&
              !IS_SET(victim->comm,COMM_QUIET) )
            {
                send_to_char( buf, d->character);
            }
        }
    }
}

void do_auction( CHAR_DATA *ch, char *argument )
{
        public_ch( ch, argument, "{y[Auction]{x", COMM_NOAUCTION);
}

void do_ooc( CHAR_DATA *ch, char *argument )
{
        public_ch( ch, argument, "{D({wOOC{D){x", COMM_NOGOSSIP);
}

void do_ic( CHAR_DATA *ch, char *argument )
{
        public_ch( ch, argument, "{D[{wIC{D]{x", COMM_NOOOC);
}

void do_grats( CHAR_DATA *ch, char *argument )
{
        public_ch( ch, argument, "{W[{DGrats{W]{D", COMM_NOGRATS);
}

void do_quote( CHAR_DATA *ch, char *argument )
{
        public_ch( ch, argument, "{W[{yQuote{W]{x", COMM_NOQUOTE);
}

void do_question( CHAR_DATA *ch, char *argument )
{
        public_ch( ch, argument, "{b[{B ? {b]{B", COMM_NOQUESTION);
}

void do_answer( CHAR_DATA *ch, char *argument )
{
        public_ch( ch, argument, "{b[{BAnswer{b]{B", COMM_NOQUESTION);
}

void do_music( CHAR_DATA *ch, char *argument )
{
        public_ch( ch, argument, "{r[{RMusic{r]{R", COMM_NOMUSIC);
}

void do_channels (CHAR_DATA * ch, char *argument)
{
    char buf[MAX_STRING_LENGTH];

    /* lists all channels and their status */
    send_to_char ("   channel     status\n\r", ch);
    send_to_char ("---------------------\n\r", ch);

    send_to_char ("{din character {x        ", ch);
    if (!IS_SET (ch->comm, COMM_NOOOC))
        send_to_char ("ON\n\r", ch);
    else
        send_to_char ("OFF\n\r", ch);

    send_to_char ("{dout of character {x    ", ch);
    if (!IS_SET (ch->comm, COMM_NOGOSSIP))
        send_to_char ("ON\n\r", ch);
    else
        send_to_char ("OFF\n\r", ch);

    send_to_char ("{aauction{x              ", ch);
    if (!IS_SET (ch->comm, COMM_NOAUCTION))
        send_to_char ("ON\n\r", ch);
    else
        send_to_char ("OFF\n\r", ch);

    send_to_char ("{emusic{x                ", ch);
    if (!IS_SET (ch->comm, COMM_NOMUSIC))
        send_to_char ("ON\n\r", ch);
    else
        send_to_char ("OFF\n\r", ch);

    send_to_char ("{qQ{x/{fA{x                  ", ch);
    if (!IS_SET (ch->comm, COMM_NOQUESTION))
        send_to_char ("ON\n\r", ch);
    else
        send_to_char ("OFF\n\r", ch);

    send_to_char ("{hQuote{x                ", ch);
    if (!IS_SET (ch->comm, COMM_NOQUOTE))
        send_to_char ("ON\n\r", ch);
    else
        send_to_char ("OFF\n\r", ch);

    send_to_char ("{yGrats{x                   ", ch);
    if (!IS_SET (ch->comm, COMM_NOGRATS))
        send_to_char ("ON\n\r", ch);
    else
        send_to_char ("OFF\n\r", ch);

    if (IS_IMMORTAL (ch))
    {
        send_to_char ("{cgod channel{x      ", ch);
        if (!IS_SET (ch->comm, COMM_NOWIZ))
            send_to_char ("ON\n\r", ch);
        else
            send_to_char ("OFF\n\r", ch);
    }

    send_to_char ("{tshouts{x               ", ch);
    if (!IS_SET (ch->comm, COMM_SHOUTSOFF))
        send_to_char ("ON\n\r", ch);
    else
        send_to_char ("OFF\n\r", ch);

    send_to_char ("{ktells{x                ", ch);
    if (!IS_SET (ch->comm, COMM_DEAF))
        send_to_char ("ON\n\r", ch);
    else
        send_to_char ("OFF\n\r", ch);

    send_to_char ("{tquiet mode{x           ", ch);
    if (IS_SET (ch->comm, COMM_QUIET))
        send_to_char ("ON\n\r", ch);
    else
        send_to_char ("OFF\n\r", ch);

    if (IS_SET (ch->comm, COMM_AFK))
        send_to_char ("You are AFK.\n\r", ch);

    if (IS_SET (ch->comm, COMM_SNOOP_PROOF))
        send_to_char ("You are immune to snooping.\n\r", ch);

    if (ch->lines != PAGELEN)
    {
        if (ch->lines)
        {
            sprintf (buf, "You display %d lines of scroll.\n\r",
                     ch->lines + 2);
            send_to_char (buf, ch);
        }
        else
            send_to_char ("Scroll buffering is off.\n\r", ch);
    }

    if (ch->prompt != NULL)
    {
        sprintf (buf, "Your current prompt is: %s\n\r", ch->prompt);
        send_to_char (buf, ch);
    }

    if (IS_SET (ch->comm, COMM_NOSHOUT))
        send_to_char ("You cannot shout.\n\r", ch);

    if (IS_SET (ch->comm, COMM_NOTELL))
        send_to_char ("You cannot use tell.\n\r", ch);

    if (IS_SET (ch->comm, COMM_NOCHANNELS))
        send_to_char ("You cannot use channels.\n\r", ch);

    if (IS_SET (ch->comm, COMM_NOEMOTE))
        send_to_char ("You cannot show emotions.\n\r", ch);

}

Site Stats

Snippets: 1791
Codebases: 571