mux/src/comsys.cpp File Reference

#include "copyright.h"
#include "autoconf.h"
#include "config.h"
#include "externs.h"
#include <sys/types.h>
#include "ansi.h"
#include "attrs.h"
#include "command.h"
#include "comsys.h"
#include "functions.h"
#include "interface.h"
#include "powers.h"

Include dependency graph for comsys.cpp:

Go to the source code of this file.

Data Structures

struct  chanlist_node

Defines

#define DFLT_MAX_LOG   0
#define MIN_RECALL_REQUEST   1
#define DFLT_RECALL_REQUEST   10
#define MAX_RECALL_REQUEST   200
#define MAX_ALIASES_PER_PLAYER   50
#define MAX_SUPPORTED_NUM_ENTRIES   10000

Functions

static char * RestrictTitleValue (char *pTitleRequest)
static void do_setcomtitlestatus (dbref player, struct channel *ch, bool status)
static void do_setnewtitle (dbref player, struct channel *ch, char *pValidatedTitle)
void load_comsys (char *filename)
void save_comsys (char *filename)
static char * MakeCanonicalComAlias (const char *pAlias, int *nValidAlias, bool *bValidAlias)
static bool ParseChannelLine (char *pBuffer, char *pAlias5, char **ppChannelName)
void load_channels (FILE *fp)
void purge_comsystem (void)
void save_channels (FILE *fp)
comsys_tcreate_new_comsys (void)
static comsys_tget_comsys (dbref which)
void add_comsys (comsys_t *c)
void del_comsys (dbref who)
void destroy_comsys (comsys_t *c)
void sort_com_aliases (comsys_t *c)
static char * get_channel_from_alias (dbref player, char *alias)
void load_comsystem (FILE *fp)
void save_comsystem (FILE *fp)
static void BuildChannelMessage (bool bSpoof, const char *pHeader, struct comuser *user, char *pPose, char **messNormal, char **messNoComtitle)
static void do_processcom (dbref player, char *arg1, char *arg2)
void SendChannelMessage (dbref executor, struct channel *ch, char *msgNormal, char *msgNoComtitle)
void do_joinchannel (dbref player, struct channel *ch)
void do_leavechannel (dbref player, struct channel *ch)
static void do_comwho_line (dbref player, struct channel *ch, struct comuser *user)
void do_comwho (dbref player, struct channel *ch)
void do_comlast (dbref player, struct channel *ch, int arg)
static bool do_chanlog (dbref player, char *channel, char *arg)
channelselect_channel (char *channel)
comuserselect_user (struct channel *ch, dbref player)
void do_addcom (dbref executor, dbref caller, dbref enactor, int key, int nargs, char *arg1, char *arg2)
void do_delcom (dbref executor, dbref caller, dbref enactor, int key, char *arg1)
void do_delcomchannel (dbref player, char *channel, bool bQuiet)
void do_createchannel (dbref executor, dbref caller, dbref enactor, int key, char *channel)
void do_destroychannel (dbref executor, dbref caller, dbref enactor, int key, char *channel)
static void do_listchannels (dbref player)
void do_comtitle (dbref executor, dbref caller, dbref enactor, int key, int nargs, char *arg1, char *arg2)
void do_comlist (dbref executor, dbref caller, dbref enactor, int key, char *pattern)
void do_channelnuke (dbref player)
void do_clearcom (dbref executor, dbref caller, dbref enactor, int unused2)
void do_allcom (dbref executor, dbref caller, dbref enactor, int key, char *arg1)
void sort_users (struct channel *ch)
void do_channelwho (dbref executor, dbref caller, dbref enactor, int key, char *arg1)
static void do_comdisconnectraw_notify (dbref player, char *chan)
static void do_comconnectraw_notify (dbref player, char *chan)
static void do_comconnectchannel (dbref player, char *channel, char *alias, int i)
void do_comdisconnect (dbref player)
void do_comconnect (dbref player)
void do_comdisconnectchannel (dbref player, char *channel)
void do_editchannel (dbref executor, dbref caller, dbref enactor, int flag, int nargs, char *arg1, char *arg2)
bool test_join_access (dbref player, struct channel *chan)
bool test_transmit_access (dbref player, struct channel *chan)
bool test_receive_access (dbref player, struct channel *chan)
bool do_comsystem (dbref who, char *cmd)
void do_cemit (dbref executor, dbref caller, dbref enactor, int key, int nargs, char *chan, char *text)
void do_chopen (dbref executor, dbref caller, dbref enactor, int key, int nargs, char *chan, char *value)
void do_chboot (dbref executor, dbref caller, dbref enactor, int key, int nargs, char *channel, char *victim)
void do_cheader (dbref player, char *channel, char *header)
static int DCL_CDECL chanlist_comp (const void *a, const void *b)
void do_chanlist (dbref executor, dbref caller, dbref enactor, int key, char *pattern)
 FUNCTION (fun_comtitle)
 FUNCTION (fun_comalias)
 FUNCTION (fun_channels)

Variables

static int num_channels
static comsys_tcomsys_table [NUM_COMSYS]


Define Documentation

#define DFLT_MAX_LOG   0

Definition at line 23 of file comsys.cpp.

Referenced by SendChannelMessage().

#define DFLT_RECALL_REQUEST   10

Definition at line 25 of file comsys.cpp.

Referenced by do_processcom().

#define MAX_ALIASES_PER_PLAYER   50

Definition at line 1460 of file comsys.cpp.

Referenced by do_addcom().

#define MAX_RECALL_REQUEST   200

Definition at line 26 of file comsys.cpp.

Referenced by do_chanlog(), do_chopen(), do_comlast(), and SendChannelMessage().

#define MAX_SUPPORTED_NUM_ENTRIES   10000

Referenced by do_chanlist().

#define MIN_RECALL_REQUEST   1

Definition at line 24 of file comsys.cpp.

Referenced by do_comlast().


Function Documentation

void add_comsys ( comsys_t c  ) 

Definition at line 398 of file comsys.cpp.

References comsys_table, statedata::db_top, ENDLINE, Log, mudstate, tagComsys::next, NUM_COMSYS, CLogFile::tinyprintf(), and tagComsys::who.

Referenced by get_comsys(), and load_channels().

00399 {
00400     if (c->who < 0 || c->who >= mudstate.db_top)
00401     {
00402         Log.tinyprintf("add_comsys: dbref %d out of range [0, %d)" ENDLINE, c->who, mudstate.db_top);
00403         return;
00404     }
00405 
00406     c->next = comsys_table[c->who % NUM_COMSYS];
00407     comsys_table[c->who % NUM_COMSYS] = c;
00408 }

static void BuildChannelMessage ( bool  bSpoof,
const char *  pHeader,
struct comuser user,
char *  pPose,
char **  messNormal,
char **  messNoComtitle 
) [static]

Definition at line 807 of file comsys.cpp.

References alloc_lbuf, comuser::ComTitleStatus, EV_EVAL, EV_FCHECK, EV_TOP, confdata::eval_comtitle, free_lbuf, LBUF_SIZE, modSpeech(), Moniker(), mudconf, mux_exec(), safe_chr, safe_str, comuser::title, and comuser::who.

Referenced by do_chboot(), do_comconnectraw_notify(), do_comdisconnectraw_notify(), do_delcomchannel(), do_joinchannel(), do_leavechannel(), and do_processcom().

00815 {
00816     // Allocate necessary buffers.
00817     //
00818     *messNormal = alloc_lbuf("BCM.messNormal");
00819     *messNoComtitle = NULL;
00820     if (!bSpoof)
00821     {
00822         *messNoComtitle = alloc_lbuf("BCM.messNoComtitle");
00823     }
00824 
00825     // Comtitle Check
00826     //
00827     bool hasComTitle = (user->title[0] != '\0');
00828 
00829     char *mnptr  = *messNormal;     // Message without comtitle removal
00830     char *mncptr = *messNoComtitle; // Message with comtitle removal
00831 
00832     safe_str(pHeader, *messNormal, &mnptr);
00833     safe_chr(' ', *messNormal, &mnptr);
00834     if (!bSpoof)
00835     {
00836         safe_str(pHeader, *messNoComtitle, &mncptr);
00837         safe_chr(' ', *messNoComtitle, &mncptr);
00838     }
00839 
00840     // Don't evaluate a title if there isn't one to parse or evaluation of
00841     // comtitles is disabled.
00842     // If they're set spoof, ComTitleStatus doesn't matter.
00843     if (hasComTitle && (user->ComTitleStatus || bSpoof))
00844     {
00845         if (mudconf.eval_comtitle)
00846         {
00847             // Evaluate the comtitle as code.
00848             //
00849             char TempToEval[LBUF_SIZE];
00850             strcpy(TempToEval, user->title);
00851             char *q = TempToEval;
00852             mux_exec(*messNormal, &mnptr, user->who, user->who, user->who,
00853                 EV_FCHECK | EV_EVAL | EV_TOP, &q, (char **)NULL, 0);
00854         }
00855         else
00856         {
00857             safe_str(user->title, *messNormal, &mnptr);
00858         }
00859         if (!bSpoof)
00860         {
00861             safe_chr(' ', *messNormal, &mnptr);
00862             safe_str(Moniker(user->who), *messNormal, &mnptr);
00863             safe_str(Moniker(user->who), *messNoComtitle, &mncptr);
00864         }
00865     }
00866     else
00867     {
00868         safe_str(Moniker(user->who), *messNormal, &mnptr);
00869         if (!bSpoof)
00870         {
00871             safe_str(Moniker(user->who), *messNoComtitle, &mncptr);
00872         }
00873     }
00874 
00875     char *saystring = NULL;
00876     char *newPose = NULL;
00877 
00878     switch(pPose[0])
00879     {
00880     case ':':
00881         pPose++;
00882         newPose = modSpeech(user->who, pPose, true, "channel/pose");
00883         if (newPose)
00884         {
00885             pPose = newPose;
00886         }
00887         safe_chr(' ', *messNormal, &mnptr);
00888         safe_str(pPose, *messNormal, &mnptr);
00889         if (!bSpoof)
00890         {
00891             safe_chr(' ', *messNoComtitle, &mncptr);
00892             safe_str(pPose, *messNoComtitle, &mncptr);
00893         }
00894         break;
00895 
00896     case ';':
00897         pPose++;
00898         newPose = modSpeech(user->who, pPose, true, "channel/pose");
00899         if (newPose)
00900         {
00901             pPose = newPose;
00902         }
00903         safe_str(pPose, *messNormal, &mnptr);
00904         if (!bSpoof)
00905         {
00906             safe_str(pPose, *messNoComtitle, &mncptr);
00907         }
00908         break;
00909 
00910     default:
00911         newPose = modSpeech(user->who, pPose, true, "channel");
00912         if (newPose)
00913         {
00914             pPose = newPose;
00915         }
00916         saystring = modSpeech(user->who, pPose, false, "channel");
00917         if (saystring)
00918         {
00919             safe_chr(' ', *messNormal, &mnptr);
00920             safe_str(saystring, *messNormal, &mnptr);
00921             safe_str(" \"", *messNormal, &mnptr);
00922         }
00923         else
00924         {
00925             safe_str(" says, \"", *messNormal, &mnptr);
00926         }
00927         safe_str(pPose, *messNormal, &mnptr);
00928         safe_chr('"', *messNormal, &mnptr);
00929         if (!bSpoof)
00930         {
00931             if (saystring)
00932             {
00933                 safe_chr(' ', *messNoComtitle, &mncptr);
00934                 safe_str(saystring, *messNoComtitle, &mncptr);
00935                 safe_str(" \"", *messNoComtitle, &mncptr);
00936             }
00937             else
00938             {
00939                 safe_str(" says, \"", *messNoComtitle, &mncptr);
00940             }
00941             safe_str(pPose, *messNoComtitle, &mncptr);
00942             safe_chr('"', *messNoComtitle, &mncptr);
00943         }
00944         break;
00945     }
00946     *mnptr = '\0';
00947     if (!bSpoof)
00948     {
00949         *mncptr = '\0';
00950     }
00951     if (newPose)
00952     {
00953         free_lbuf(newPose);
00954     }
00955     if (saystring)
00956     {
00957         free_lbuf(saystring);
00958     }
00959 }

static int DCL_CDECL chanlist_comp ( const void *  a,
const void *  b 
) [static]

Definition at line 2935 of file comsys.cpp.

References mux_stricmp(), and chanlist_node::name.

Referenced by do_chanlist().

02936 {
02937     chanlist_node* ca = (chanlist_node*)a;
02938     chanlist_node* cb = (chanlist_node*)b;
02939     return mux_stricmp(ca->name, cb->name);
02940 }

comsys_t* create_new_comsys ( void   ) 

Definition at line 363 of file comsys.cpp.

References tagComsys::alias, tagComsys::channels, ISOUTOFMEMORY, tagComsys::maxchannels, MEMALLOC, tagComsys::next, NOTHING, tagComsys::numchannels, and tagComsys::who.

Referenced by get_comsys(), and load_channels().

00364 {
00365     comsys_t *c = (comsys_t *)MEMALLOC(sizeof(comsys_t));
00366     ISOUTOFMEMORY(c);
00367 
00368     c->who         = NOTHING;
00369     c->numchannels = 0;
00370     c->maxchannels = 0;
00371     c->alias       = NULL;
00372     c->channels    = NULL;
00373     c->next        = NULL;
00374     return c;
00375 }

void del_comsys ( dbref  who  ) 

Definition at line 410 of file comsys.cpp.

References comsys_table, statedata::db_top, destroy_comsys(), ENDLINE, Log, mudstate, tagComsys::next, NUM_COMSYS, CLogFile::tinyprintf(), and tagComsys::who.

Referenced by purge_comsystem(), and ReleaseAllResources().

00411 {
00412     if (who < 0 || who >= mudstate.db_top)
00413     {
00414         Log.tinyprintf("del_comsys: dbref %d out of range [0, %d)" ENDLINE, who, mudstate.db_top);
00415         return;
00416     }
00417 
00418     comsys_t *c = comsys_table[who % NUM_COMSYS];
00419 
00420     if (c == NULL)
00421     {
00422         return;
00423     }
00424 
00425     if (c->who == who)
00426     {
00427         comsys_table[who % NUM_COMSYS] = c->next;
00428         destroy_comsys(c);
00429         return;
00430     }
00431     comsys_t *last = c;
00432     c = c->next;
00433     while (c)
00434     {
00435         if (c->who == who)
00436         {
00437             last->next = c->next;
00438             destroy_comsys(c);
00439             return;
00440         }
00441         last = c;
00442         c = c->next;
00443     }
00444 }

void destroy_comsys ( comsys_t c  ) 

Definition at line 446 of file comsys.cpp.

References tagComsys::alias, tagComsys::channels, MEMFREE, and tagComsys::numchannels.

Referenced by del_comsys().

00447 {
00448     int i;
00449 
00450     if (c->alias)
00451     {
00452         MEMFREE(c->alias);
00453         c->alias = NULL;
00454     }
00455     for (i = 0; i < c->numchannels; i++)
00456     {
00457         MEMFREE(c->channels[i]);
00458         c->channels[i] = NULL;
00459     }
00460     if (c->channels)
00461     {
00462         MEMFREE(c->channels);
00463         c->channels = NULL;
00464     }
00465     MEMFREE(c);
00466     c = NULL;
00467 }

void do_addcom ( dbref  executor,
dbref  caller,
dbref  enactor,
int  key,
int  nargs,
char *  arg1,
char *  arg2 
)

Definition at line 1463 of file comsys.cpp.

References tagComsys::alias, ALIAS_SIZE, ANSI_ENDGOAL_NORMAL, ANSI_TruncateToField(), tagComsys::channels, get_comsys(), confdata::have_comsys, ISOUTOFMEMORY, MakeCanonicalComAlias(), MAX_ALIASES_PER_PLAYER, MAX_CHANNEL_LEN, tagComsys::maxchannels, MEMALLOC, MEMFREE, mudconf, tagComsys::numchannels, raw_notify(), select_channel(), test_join_access(), tprintf(), and UNUSED_PARAMETER.

Referenced by CGuests::AddToGuestChannel(), and AddToPublicChannel().

01472 {
01473     UNUSED_PARAMETER(caller);
01474     UNUSED_PARAMETER(enactor);
01475     UNUSED_PARAMETER(key);
01476     UNUSED_PARAMETER(nargs);
01477 
01478     if (!mudconf.have_comsys)
01479     {
01480         raw_notify(executor, "Comsys disabled.");
01481         return;
01482     }
01483     bool bValidAlias;
01484     int  nValidAlias;
01485     char *pValidAlias = MakeCanonicalComAlias(arg1, &nValidAlias, &bValidAlias);
01486     if (!bValidAlias)
01487     {
01488         raw_notify(executor, "You need to specify a valid alias.");
01489         return;
01490     }
01491     char *s = arg2;
01492     if (!*s)
01493     {
01494         raw_notify(executor, "You need to specify a channel.");
01495         return;
01496     }
01497     char channel[MAX_CHANNEL_LEN+1];
01498     char *t = channel;
01499     while (*s && ((t - channel) < MAX_CHANNEL_LEN))
01500     {
01501         if (*s != ' ')
01502             *t++ = *s++;
01503         else
01504             s++;
01505     }
01506     *t = '\0';
01507 
01508     int i, j, where;
01509     char *na;
01510     char **nc;
01511     struct channel *ch = select_channel(channel);
01512     char Buffer[MAX_CHANNEL_LEN+1];
01513     if (!ch)
01514     {
01515         int nVisualWidth;
01516         ANSI_TruncateToField(channel, sizeof(Buffer), Buffer, sizeof(Buffer), &nVisualWidth, ANSI_ENDGOAL_NORMAL);
01517         raw_notify(executor, tprintf("Channel %s does not exist yet.", Buffer));
01518         return;
01519     }
01520     if (!test_join_access(executor, ch))
01521     {
01522         raw_notify(executor, "Sorry, this channel type does not allow you to join.");
01523         return;
01524     }
01525     comsys_t *c = get_comsys(executor);
01526     if (c->numchannels >= MAX_ALIASES_PER_PLAYER)
01527     {
01528         raw_notify(executor, tprintf("Sorry, but you have reached the maximum number of aliases allowed."));
01529         return;
01530     }
01531     for (j = 0; j < c->numchannels && (strcmp(pValidAlias, c->alias + j * ALIAS_SIZE) > 0); j++)
01532     {
01533         ; // Nothing.
01534     }
01535     if (j < c->numchannels && !strcmp(pValidAlias, c->alias + j * ALIAS_SIZE))
01536     {
01537         char *p = tprintf("That alias is already in use for channel %s.", c->channels[j]);
01538         raw_notify(executor, p);
01539         return;
01540     }
01541     if (c->numchannels >= c->maxchannels)
01542     {
01543         c->maxchannels += 10;
01544 
01545         na = (char *)MEMALLOC(ALIAS_SIZE * c->maxchannels);
01546         ISOUTOFMEMORY(na);
01547         nc = (char **)MEMALLOC(sizeof(char *) * c->maxchannels);
01548         ISOUTOFMEMORY(nc);
01549 
01550         for (i = 0; i < c->numchannels; i++)
01551         {
01552             strcpy(na + i * ALIAS_SIZE, c->alias + i * ALIAS_SIZE);
01553             nc[i] = c->channels[i];
01554         }
01555         if (c->alias)
01556         {
01557             MEMFREE(c->alias);
01558             c->alias = NULL;
01559         }
01560         if (c->channels)
01561         {
01562             MEMFREE(c->channels);
01563             c->channels = NULL;
01564         }
01565         c->alias = na;
01566         c->channels = nc;
01567     }
01568     where = c->numchannels++;
01569     for (i = where; i > j; i--)
01570     {
01571         strcpy(c->alias + i * ALIAS_SIZE, c->alias + (i - 1) * ALIAS_SIZE);
01572         c->channels[i] = c->channels[i - 1];
01573     }
01574 
01575     where = j;
01576     memcpy(c->alias + where * ALIAS_SIZE, pValidAlias, nValidAlias);
01577     *(c->alias + where * ALIAS_SIZE + nValidAlias) = '\0';
01578     c->channels[where] = StringClone(channel);
01579 
01580     if (!select_user(ch, executor))
01581     {
01582         do_joinchannel(executor, ch);
01583     }
01584 
01585     raw_notify(executor, tprintf("Channel %s added with alias %s.", channel, pValidAlias));
01586 }

void do_allcom ( dbref  executor,
dbref  caller,
dbref  enactor,
int  key,
char *  arg1 
)

Definition at line 2134 of file comsys.cpp.

References tagComsys::channels, do_processcom(), get_comsys(), confdata::have_comsys, mudconf, tagComsys::numchannels, raw_notify(), and UNUSED_PARAMETER.

02135 {
02136     UNUSED_PARAMETER(caller);
02137     UNUSED_PARAMETER(enactor);
02138     UNUSED_PARAMETER(key);
02139 
02140     if (!mudconf.have_comsys)
02141     {
02142         raw_notify(executor, "Comsys disabled.");
02143         return;
02144     }
02145     if (  strcmp(arg1, "who") != 0
02146        && strcmp(arg1, "on")  != 0
02147        && strcmp(arg1, "off") != 0)
02148     {
02149         raw_notify(executor, "Only options available are: on, off and who.");
02150         return;
02151     }
02152 
02153     comsys_t *c = get_comsys(executor);
02154     int i;
02155     for (i = 0; i < c->numchannels; i++)
02156     {
02157         do_processcom(executor, c->channels[i], arg1);
02158         if (strcmp(arg1, "who") == 0)
02159         {
02160             raw_notify(executor, "");
02161         }
02162     }
02163 }

void do_cemit ( dbref  executor,
dbref  caller,
dbref  enactor,
int  key,
int  nargs,
char *  chan,
char *  text 
)

Definition at line 2643 of file comsys.cpp.

References alloc_lbuf, CEMIT_NOHEADER, channel::charge_who, Comm_All, Controls, confdata::have_comsys, channel::header, mudconf, NOPERM_MESSAGE, raw_notify(), select_channel(), SendChannelMessage(), tprintf(), and UNUSED_PARAMETER.

Referenced by FUNCTION().

02652 {
02653     UNUSED_PARAMETER(caller);
02654     UNUSED_PARAMETER(enactor);
02655     UNUSED_PARAMETER(nargs);
02656 
02657     if (!mudconf.have_comsys)
02658     {
02659         raw_notify(executor, "Comsys disabled.");
02660         return;
02661     }
02662     struct channel *ch = select_channel(chan);
02663     if (!ch)
02664     {
02665         raw_notify(executor, tprintf("Channel %s does not exist.", chan));
02666         return;
02667     }
02668     if (  !Controls(executor, ch->charge_who)
02669        && !Comm_All(executor))
02670     {
02671         raw_notify(executor, NOPERM_MESSAGE);
02672         return;
02673     }
02674     char *text2 = alloc_lbuf("do_cemit");
02675     if (key == CEMIT_NOHEADER)
02676     {
02677         strcpy(text2, text);
02678     }
02679     else
02680     {
02681         strcpy(text2, tprintf("%s %s", ch->header, text));
02682     }
02683     SendChannelMessage(executor, ch, text2, text2);
02684 }

void do_chanlist ( dbref  executor,
dbref  caller,
dbref  enactor,
int  key,
char *  pattern 
)

Definition at line 2943 of file comsys.cpp.

References A_DESC, alloc_mbuf, ANSI_TruncateAndPad_sbuf(), atr_pget, channel::chan_obj, chanlist_comp(), statedata::channel_htab, CHANNEL_LOUD, CHANNEL_PUBLIC, CHANNEL_SPOOF, channel::charge_who, CLIST_FULL, CLIST_HEADERS, Comm_All, Controls, do_listchannels(), free_lbuf, free_sbuf, CHashTable::GetEntryCount(), hash_firstentry(), hash_nextentry(), confdata::have_comsys, channel::header, ISOUTOFMEMORY, MAX_SUPPORTED_NUM_ENTRIES, MEMALLOC, Moniker(), mudconf, mudstate, channel::name, chanlist_node::name, NOTHING, chanlist_node::ptr, quick_wild(), raw_notify(), channel::type, and UNUSED_PARAMETER.

Referenced by do_chopen().

02950 {
02951     UNUSED_PARAMETER(caller);
02952     UNUSED_PARAMETER(enactor);
02953 
02954     if (!mudconf.have_comsys)
02955     {
02956         raw_notify(executor, "Comsys disabled.");
02957         return;
02958     }
02959     if (key & CLIST_FULL)
02960     {
02961         do_listchannels(executor);
02962         return;
02963     }
02964 
02965     dbref owner;
02966     struct channel *ch;
02967     int flags = 0;
02968     char *atrstr;
02969     char *temp = alloc_mbuf("do_chanlist_temp");
02970     char *buf = alloc_mbuf("do_chanlist_buf");
02971 
02972     if (key & CLIST_HEADERS)
02973     {
02974         raw_notify(executor, "*** Channel       Owner           Header");
02975     }
02976     else
02977     {
02978         raw_notify(executor, "*** Channel       Owner           Description");
02979     }
02980 
02981     bool bWild;
02982     if (  NULL != pattern
02983        && '\0' != *pattern)
02984     {
02985         bWild = true;
02986     }
02987     else
02988     {
02989         bWild = false;
02990     }
02991 
02992 #define MAX_SUPPORTED_NUM_ENTRIES 10000
02993 
02994     INT64 iEntryCount64 = mudstate.channel_htab.GetEntryCount();
02995     if (MAX_SUPPORTED_NUM_ENTRIES < iEntryCount64)
02996     {
02997         // Nobody should have so many channels.
02998         //
02999         iEntryCount64 = MAX_SUPPORTED_NUM_ENTRIES;
03000     }
03001     size_t entries = (size_t)iEntryCount64;
03002 
03003     struct chanlist_node* charray = (chanlist_node*)MEMALLOC(sizeof(chanlist_node)*entries);
03004     ISOUTOFMEMORY(charray);
03005 
03006     // Arrayify all the channels
03007     //
03008     size_t  actualEntries;
03009     for (  actualEntries = 0, ch = (struct channel *)hash_firstentry(&mudstate.channel_htab);
03010            ch
03011         && actualEntries < entries;
03012            ch = (struct channel *)hash_nextentry(&mudstate.channel_htab))
03013     {
03014             if (  !bWild
03015                || quick_wild(pattern, ch->name))
03016             {
03017                 charray[actualEntries].name = ch->name;
03018                 charray[actualEntries].ptr = ch;
03019                 actualEntries++;
03020             }
03021     }
03022 
03023     qsort(charray, actualEntries, sizeof(struct chanlist_node), chanlist_comp);
03024 
03025     for (size_t i = 0; i < actualEntries; i++)
03026     {
03027         ch = charray[i].ptr;
03028         if (  Comm_All(executor)
03029            || (ch->type & CHANNEL_PUBLIC)
03030            || Controls(executor, ch->charge_who))
03031         {
03032             char *pBuffer;
03033             if (key & CLIST_HEADERS)
03034             {
03035                 pBuffer = ch->header;
03036             }
03037             else
03038             {
03039                 atrstr = atr_pget(ch->chan_obj, A_DESC, &owner, &flags);
03040                 if (  NOTHING == ch->chan_obj
03041                    || !*atrstr)
03042                 {
03043                     strcpy(buf, "No description.");
03044                 }
03045                 else
03046                 {
03047                     sprintf(buf, "%-54.54s", atrstr);
03048                 }
03049                 free_lbuf(atrstr);
03050 
03051                 pBuffer = buf;
03052             }
03053 
03054             char *ownername_ansi = ANSI_TruncateAndPad_sbuf(Moniker(ch->charge_who), 15);
03055             sprintf(temp, "%c%c%c %-13.13s %s %-45.45s",
03056                 (ch->type & (CHANNEL_PUBLIC)) ? 'P' : '-',
03057                 (ch->type & (CHANNEL_LOUD)) ? 'L' : '-',
03058                 (ch->type & (CHANNEL_SPOOF)) ? 'S' : '-',
03059                 ch->name, ownername_ansi, pBuffer);
03060             free_sbuf(ownername_ansi);
03061 
03062             raw_notify(executor, temp);
03063         }
03064     }
03065     MEMFREE(charray);
03066     free_mbuf(temp);
03067     free_mbuf(buf);
03068     raw_notify(executor, "-- End of list of Channels --");
03069 }

static bool do_chanlog ( dbref  player,
char *  channel,
char *  arg 
) [static]

Definition at line 1355 of file comsys.cpp.

References AF_CONST, AF_NOPARSE, AF_NOPROG, atr_add(), atr_clr(), atr_get, atr_str(), channel::chan_obj, free_lbuf, GOD, Good_obj, is_integer(), MAX_RECALL_REQUEST, mkattr(), mux_atol(), mux_ltoa_t(), select_channel(), tprintf(), and UNUSED_PARAMETER.

Referenced by do_chopen().

01356 {
01357     UNUSED_PARAMETER(player);
01358 
01359     int value;
01360     if (  !*arg
01361        || !is_integer(arg, NULL)
01362        || (value = mux_atol(arg)) > MAX_RECALL_REQUEST)
01363     {
01364         return false;
01365     }
01366     if (value < 0)
01367     {
01368         value = 0;
01369     }
01370     struct channel *ch = select_channel(channel);
01371     if (!Good_obj(ch->chan_obj))
01372     {
01373         // No channel object has been set.
01374         //
01375         return false;
01376     }
01377     int atr = mkattr(GOD, "MAX_LOG");
01378     if (atr <= 0)
01379     {
01380         return false;
01381     }
01382     dbref aowner;
01383     int aflags;
01384     char *oldvalue = atr_get(ch->chan_obj, atr, &aowner, &aflags);
01385     if (oldvalue)
01386     {
01387         int oldnum = mux_atol(oldvalue);
01388         if (oldnum > value)
01389         {
01390             ATTR *hist;
01391             for (int count = 0; count <= oldnum; count++)
01392             {
01393                 hist = atr_str(tprintf("HISTORY_%d", count));
01394                 if (hist)
01395                 {
01396                     atr_clr(ch->chan_obj, hist->number);
01397                 }
01398             }
01399         }
01400         free_lbuf(oldvalue);
01401     }
01402     atr_add(ch->chan_obj, atr, mux_ltoa_t(value), GOD,
01403         AF_CONST|AF_NOPROG|AF_NOPARSE);
01404     return true;
01405 }

void do_channelnuke ( dbref  player  ) 

Definition at line 2090 of file comsys.cpp.

References statedata::channel_htab, channel::charge_who, hash_firstentry(), hash_nextentry(), hashdeleteLEN(), MEMFREE, mudstate, channel::name, num_channels, channel::num_users, and channel::users.

Referenced by ReleaseAllResources().

02091 {
02092     struct channel *ch;
02093     int j;
02094 
02095     for (ch = (struct channel *)hash_firstentry(&mudstate.channel_htab);
02096          ch; ch = (struct channel *)hash_nextentry(&mudstate.channel_htab))
02097     {
02098         if (player == ch->charge_who)
02099         {
02100             num_channels--;
02101             hashdeleteLEN(ch->name, strlen(ch->name), &mudstate.channel_htab);
02102 
02103             for (j = 0; j < ch->num_users; j++)
02104             {
02105                 MEMFREE(ch->users[j]);
02106                 ch->users[j] = NULL;
02107             }
02108             MEMFREE(ch->users);
02109             ch->users = NULL;
02110             MEMFREE(ch);
02111             ch = NULL;
02112         }
02113     }
02114 }