mux/src/comsys.h File Reference

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  chanentry
struct  comuser
struct  channel
struct  tagComsys

Defines

#define NUM_COMSYS   500
#define MAX_CHANNEL_LEN   50
#define MAX_HEADER_LEN   100
#define MAX_TITLE_LEN   200
#define MAX_ALIAS_LEN   5
#define ALIAS_SIZE   (MAX_ALIAS_LEN+1)
#define CHANNEL_PLAYER_JOIN   (0x00000001UL)
#define CHANNEL_PLAYER_TRANSMIT   (0x00000002UL)
#define CHANNEL_PLAYER_RECEIVE   (0x00000004UL)
#define CHANNEL_OBJECT_JOIN   (0x00000010UL)
#define CHANNEL_OBJECT_TRANSMIT   (0x00000020UL)
#define CHANNEL_OBJECT_RECEIVE   (0x00000040UL)
#define CHANNEL_LOUD   (0x00000100UL)
#define CHANNEL_PUBLIC   (0x00000200UL)
#define CHANNEL_SPOOF   (0x00000400UL)
#define UNDEAD(x)   (Good_obj(x) && ((Typeof(x) != TYPE_PLAYER) || Connected(x)))

Typedefs

typedef chanentry CHANENT
typedef tagComsys comsys_t

Functions

void save_comsys (char *filename)
void load_comsys (char *filename)
void del_comsys (dbref who)
void add_comsys (comsys_t *c)
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)
void do_joinchannel (dbref player, struct channel *ch)
void do_comdisconnectchannel (dbref player, char *channel)
void load_channels (FILE *fp)
void purge_comsystem (void)
void save_channels (FILE *fp)
void destroy_comsys (comsys_t *c)
void sort_com_aliases (comsys_t *c)
void load_comsystem (FILE *fp)
void save_comsystem (FILE *fp)
void SendChannelMessage (dbref player, struct channel *ch, char *msgNormal, char *msgNoComtitle)
void do_comwho (dbref player, struct channel *ch)
void do_comlast (dbref player, struct channel *ch, int arg)
void do_leavechannel (dbref player, struct channel *ch)
void do_delcomchannel (dbref player, char *channel, bool bQuiet)
void do_channelnuke (dbref player)
void sort_users (struct channel *ch)
void do_comdisconnect (dbref player)
void do_comconnect (dbref player)
void do_clearcom (dbref executor, dbref caller, dbref enactor, int unused2)
void do_cheader (dbref player, char *channel, char *header)
void do_addcom (dbref executor, dbref caller, dbref enactor, int key, int nargs, char *arg1, char *arg2)
comsys_tcreate_new_comsys ()
channelselect_channel (char *channel)
comuserselect_user (struct channel *ch, dbref player)
char * get_channel_from_alias ()
bool do_comsystem (dbref who, char *cmd)
void do_chanlist (dbref executor, dbref caller, dbref enactor, int key, char *pattern)


Define Documentation

#define ALIAS_SIZE   (MAX_ALIAS_LEN+1)

Definition at line 22 of file comsys.h.

Referenced by do_addcom(), do_clearcom(), do_comconnectchannel(), do_comlist(), do_delcom(), FUNCTION(), get_channel_from_alias(), load_channels(), MakeCanonicalComAlias(), save_channels(), and sort_com_aliases().

#define CHANNEL_LOUD   (0x00000100UL)

Definition at line 126 of file comsys.h.

Referenced by do_chanlist(), do_chopen(), do_comconnectraw_notify(), do_comdisconnectraw_notify(), and do_listchannels().

#define CHANNEL_OBJECT_JOIN   (0x00000010UL)

Definition at line 123 of file comsys.h.

Referenced by do_editchannel(), do_listchannels(), and test_join_access().

#define CHANNEL_OBJECT_RECEIVE   (0x00000040UL)

Definition at line 125 of file comsys.h.

Referenced by do_editchannel(), do_listchannels(), and test_receive_access().

#define CHANNEL_OBJECT_TRANSMIT   (0x00000020UL)

Definition at line 124 of file comsys.h.

Referenced by do_editchannel(), do_listchannels(), and test_transmit_access().

#define CHANNEL_PLAYER_JOIN   (0x00000001UL)

Definition at line 120 of file comsys.h.

Referenced by do_editchannel(), do_listchannels(), and test_join_access().

#define CHANNEL_PLAYER_RECEIVE   (0x00000004UL)

Definition at line 122 of file comsys.h.

Referenced by do_editchannel(), do_listchannels(), and test_receive_access().

#define CHANNEL_PLAYER_TRANSMIT   (0x00000002UL)

Definition at line 121 of file comsys.h.

Referenced by do_editchannel(), do_listchannels(), and test_transmit_access().

#define CHANNEL_PUBLIC   (0x00000200UL)

Definition at line 127 of file comsys.h.

Referenced by do_chanlist(), do_chopen(), do_listchannels(), FUNCTION(), and load_comsystem().

#define CHANNEL_SPOOF   (0x00000400UL)

Definition at line 128 of file comsys.h.

Referenced by do_chanlist(), do_chboot(), do_chopen(), do_comconnectraw_notify(), do_comdisconnectraw_notify(), do_comtitle(), do_comwho_line(), do_delcomchannel(), do_joinchannel(), do_leavechannel(), do_listchannels(), do_processcom(), and SendChannelMessage().

#define MAX_ALIAS_LEN   5

Definition at line 21 of file comsys.h.

Referenced by MakeCanonicalComAlias().

#define MAX_CHANNEL_LEN   50

Definition at line 18 of file comsys.h.

Referenced by do_addcom(), do_channelwho(), do_comtitle(), do_createchannel(), and load_comsystem().

#define MAX_HEADER_LEN   100

Definition at line 19 of file comsys.h.

Referenced by do_cheader(), do_createchannel(), and load_comsystem().

#define MAX_TITLE_LEN   200

Definition at line 20 of file comsys.h.

Referenced by load_comsystem(), and RestrictTitleValue().

#define NUM_COMSYS   500

Definition at line 16 of file comsys.h.

Referenced by add_comsys(), del_comsys(), get_comsys(), load_comsys(), purge_comsystem(), and save_channels().

#define UNDEAD (  )     (Good_obj(x) && ((Typeof(x) != TYPE_PLAYER) || Connected(x)))

Definition at line 132 of file comsys.h.

Referenced by do_channelwho(), and do_joinchannel().


Typedef Documentation

typedef struct chanentry CHANENT

Definition at line 9 of file comsys.h.

typedef struct tagComsys comsys_t


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 }

comsys_t* create_new_comsys (  ) 

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_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, chanlist_node::name, channel::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 }

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 }

void do_cheader ( dbref  player,
char *  channel,
char *  header 
)

Definition at line 2903 of file comsys.cpp.

References ANSI_ENDGOAL_NORMAL, ANSI_TruncateToField(), channel::charge_who, Comm_All, Controls, channel::header, MAX_HEADER_LEN, NOPERM_MESSAGE, raw_notify(), RemoveSetOfCharacters(), and select_channel().

Referenced by do_chopen().

02904 {
02905     struct channel *ch = select_channel(channel);
02906     if (!ch)
02907     {
02908         raw_notify(player, "That channel does not exist.");
02909         return;
02910     }
02911     if (  !Controls(player, ch->charge_who)
02912        && !Comm_All(player))
02913     {
02914         raw_notify(player, NOPERM_MESSAGE);
02915         return;
02916     }
02917     char *p = RemoveSetOfCharacters(header, "\r\n\t");
02918 
02919     // Optimize/terminate any ANSI in the string.
02920     //
02921     char NewHeader_ANSI[MAX_HEADER_LEN+1];
02922     int nVisualWidth;
02923     int nLen = ANSI_TruncateToField(p, sizeof(NewHeader_ANSI),
02924         NewHeader_ANSI, sizeof(NewHeader_ANSI), &nVisualWidth,
02925         ANSI_ENDGOAL_NORMAL);
02926     memcpy(ch->header, NewHeader_ANSI, nLen+1);
02927 }

void do_clearcom ( dbref  executor,
dbref  caller,
dbref  enactor,
int  unused2 
)

Definition at line 2116 of file comsys.cpp.

References tagComsys::alias, ALIAS_SIZE, do_delcom(), get_comsys(), confdata::have_comsys, mudconf, tagComsys::numchannels, raw_notify(), and UNUSED_PARAMETER.

Referenced by ReleaseAllResources().

02117 {
02118     UNUSED_PARAMETER(unused2);
02119 
02120     if (!mudconf.have_comsys)
02121     {
02122         raw_notify(executor, "Comsys disabled.");
02123         return;
02124     }
02125     comsys_t *c = get_comsys(executor);
02126 
02127     int i;
02128     for (i = (c->numchannels) - 1; i > -1; --i)
02129     {
02130         do_delcom(executor, caller, enactor, 0, c->alias + i * ALIAS_SIZE);
02131     }
02132 }

void do_comconnect ( dbref  player  ) 

Definition at line 2349 of file comsys.cpp.

References tagComsys::alias, tagComsys::channels, do_comconnectchannel(), do_comconnectraw_notify(), get_comsys(), and tagComsys::numchannels.

Referenced by announce_connect().

02350 {
02351     comsys_t *c = get_comsys(player);
02352     int i;
02353 
02354     for (i = 0; i < c->numchannels; i++)
02355     {
02356         char *CurrentChannel = c->channels[i];
02357         bool bFound = false;
02358         int j;
02359 
02360         for (j = 0; j < i; j++)
02361         {
02362             if (strcmp(c->channels[j], CurrentChannel) == 0)
02363             {
02364                 bFound = true;
02365                 break;
02366             }
02367         }
02368 
02369         if (!bFound)
02370         {
02371             do_comconnectchannel(player, CurrentChannel, c->alias, i);
02372             do_comconnectraw_notify(player, CurrentChannel);
02373         }
02374     }
02375 }

void do_comdisconnect ( dbref  player  ) 

Definition at line 2321 of file comsys.cpp.

References tagComsys::channels, do_comdisconnectchannel(), do_comdisconnectraw_notify(), get_comsys(), and tagComsys::numchannels.

Referenced by announce_disconnect(), and ReleaseAllResources().

02322 {
02323     comsys_t *c = get_comsys(player);
02324     int i;
02325 
02326     for (i = 0; i < c->numchannels; i++)
02327     {
02328         char *CurrentChannel = c->channels[i];
02329         bool bFound = false;
02330         int j;
02331 
02332         for (j = 0; j < i; j++)
02333         {
02334             if (strcmp(c->channels[j], CurrentChannel) == 0)
02335             {
02336                 bFound = true;
02337                 break;
02338             }
02339         }
02340 
02341         if (!bFound)
02342         {
02343             do_comdisconnectchannel(player, CurrentChannel);
02344             do_comdisconnectraw_notify(player, CurrentChannel);
02345         }
02346     }
02347 }

void do_comdisconnectchannel ( dbref  player,
char *  channel 
)

Definition at line 2378 of file comsys.cpp.

References comuser::on_next, channel::on_users, select_channel(), and comuser::who.

Referenced by do_comdisconnect(), do_comwho(), and do_delcomchannel().

02379 {
02380     struct channel *ch = select_channel(channel);
02381     if (!ch)
02382     {
02383         return;
02384     }
02385 
02386     struct comuser *prevuser = NULL;
02387     struct comuser *user;
02388     for (user = ch->on_users; user;)
02389     {
02390         if (user->who == player)
02391         {
02392             if (prevuser)
02393             {
02394                 prevuser->on_next = user->on_next;
02395             }
02396             else
02397             {
02398                 ch->on_users = user->on_next;
02399             }
02400             return;
02401         }
02402         else
02403         {
02404             prevuser = user;
02405             user = user->on_next;
02406         }
02407     }
02408 }

void do_comlast ( dbref  player,
struct channel ch,
int  arg 
)

Definition at line 1304 of file comsys.cpp.

References atr_get, atr_get_info(), atr_str(), channel::chan_obj, free_lbuf, Good_obj, iMod(), MAX_RECALL_REQUEST, MIN_RECALL_REQUEST, mux_atol(), channel::num_messages, attr::number, raw_notify(), and tprintf().

Referenced by do_processcom().

01305 {
01306     if (!Good_obj(ch->chan_obj))
01307     {
01308         raw_notify(player, "Channel does not have an object.");
01309         return;
01310     }
01311     dbref aowner;
01312     int aflags;
01313     dbref obj = ch->chan_obj;
01314     int logmax = MAX_RECALL_REQUEST;
01315     ATTR *pattr = atr_str("MAX_LOG");
01316     if (  pattr
01317        && (atr_get_info(obj, pattr->number, &aowner, &aflags)))
01318     {
01319         char *maxbuf = atr_get(obj, pattr->number, &aowner, &aflags);
01320         logmax = mux_atol(maxbuf);
01321         free_lbuf(maxbuf);
01322     }
01323     if (logmax < 1)
01324     {
01325         raw_notify(player, "Channel does not log.");
01326         return;
01327     }
01328     if (arg < MIN_RECALL_REQUEST)
01329     {
01330         arg = MIN_RECALL_REQUEST;
01331     }
01332     if (arg > logmax)
01333     {
01334         arg = logmax;
01335     }
01336 
01337     char *message;
01338     int histnum = ch->num_messages - arg;
01339 
01340     raw_notify(player, "-- Begin Comsys Recall --");
01341     for (int count = 0; count < arg; count++)
01342     {
01343         histnum++;
01344         pattr = atr_str(tprintf("HISTORY_%d", iMod(histnum, logmax)));
01345         if (pattr)
01346         {
01347             message = atr_get(obj, pattr->number, &aowner, &aflags);
01348             raw_notify(player, message);
01349             free_lbuf(message);
01350         }
01351     }
01352     raw_notify(player, "-- End Comsys Recall --");
01353 }

bool do_comsystem ( dbref  who,
char *  cmd 
)

Definition at line 2610 of file comsys.cpp.

References alloc_lbuf, do_processcom(), free_lbuf, get_channel_from_alias(), and LBUF_SIZE.

Referenced by process_command().

02611 {
02612     char *t;
02613     char *alias = alloc_lbuf("do_comsystem");
02614     char *s = alias;
02615     for (t = cmd; *t && *t != ' ' && s < alias + LBUF_SIZE; *s++ = *t++)
02616     {
02617         ; // Nothing.
02618     }
02619 
02620     *s = '\0';
02621 
02622     if (*t)
02623     {
02624         t++;
02625     }
02626 
02627     char *ch = get_channel_from_alias(who, alias);
02628     if (  ch[0] != '\0'
02629        && t[0] != '\0')
02630     {
02631         do_processcom(who, ch, t);
02632         free_lbuf(alias);
02633         return false;
02634     }
02635     else
02636     {
02637         free_lbuf(alias);
02638     }
02639     return true;
02640 }

void do_comwho ( dbref  player,
struct channel ch 
)

Definition at line 1260 of file comsys.cpp.

References comuser::bUserIsOn, Connected, do_comdisconnectchannel(), do_comwho_line(), God, Going, Hidden, isPlayer, channel::name, comuser::on_next, channel::on_users, Owner, raw_notify(), See_Hidden, tprintf(), comuser::who, and Wizard_Who.

Referenced by do_processcom().

01261 {
01262     struct comuser *user;
01263 
01264     raw_notify(player, "-- Players --");
01265     for (user = ch->on_users; user; user = user->on_next)
01266     {
01267         if (isPlayer(user->who))
01268         {
01269             if (  Connected(user->who)
01270                && (  !Hidden(user->who)
01271                   || Wizard_Who(player)
01272                   || See_Hidden(player)))
01273             {
01274                 if (user->bUserIsOn)
01275                 {
01276                     do_comwho_line(player, ch, user);
01277                 }
01278             }
01279             else if (!Hidden(user->who))
01280             {
01281                 do_comdisconnectchannel(user->who, ch->name);
01282             }
01283         }
01284     }
01285     raw_notify(player, "-- Objects --");
01286     for (user = ch->on_users; user; user = user->on_next)
01287     {
01288         if (!isPlayer(user->who))
01289         {
01290             if (  Going(user->who)
01291                && God(Owner(user->who)))
01292             {
01293                 do_comdisconnectchannel(user->who, ch->name);
01294             }
01295             else if (user->bUserIsOn)
01296             {
01297                 do_comwho_line(player, ch, user);
01298             }
01299         }
01300     }
01301     raw_notify(player, tprintf("-- %s --", ch->name));
01302 }

void do_delcomchannel ( dbref  player,
char *  channel,
bool  bQuiet 
)

Definition at line 1649 of file comsys.cpp.

References BuildChannelMessage(), comuser::bUserIsOn, CHANNEL_SPOOF, do_comdisconnectchannel(), channel::header, Hidden, MEMFREE, channel::num_users, raw_notify(), select_channel(), SendChannelMessage(), comuser::title, tprintf(), channel::type, channel::users, and comuser::who.

Referenced by do_chboot(), and do_delcom().

01650 {
01651     struct comuser *user;
01652 
01653     struct channel *ch = select_channel(channel);
01654     if (!ch)
01655     {
01656         raw_notify(player, tprintf("Unknown channel %s.", channel));
01657     }
01658     else
01659     {
01660         int i;
01661         int j = 0;
01662         for (i = 0; i < ch->num_users && !j; i++)
01663         {
01664             user = ch->users[i];
01665             if (user->who == player)
01666             {
01667                 do_comdisconnectchannel(player, channel);
01668                 if (!bQuiet)
01669                 {
01670                     if (  user->bUserIsOn
01671                        && !Hidden(player))
01672                     {
01673                         char *messNormal, *messNoComtitle;
01674                         BuildChannelMessage((ch->type & CHANNEL_SPOOF) != 0,
01675                                             ch->header, user, ":has left this channel.",
01676                                             &messNormal, &messNoComtitle);
01677                         SendChannelMessage(player, ch, messNormal, messNoComtitle);
01678                     }
01679                     raw_notify(player, tprintf("You have left channel %s.", channel));
01680                 }
01681 
01682                 if (user->title)
01683                 {
01684                     MEMFREE(user->title);
01685                     user->title = NULL;
01686                 }
01687                 MEMFREE(user);
01688                 user = NULL;
01689                 j = 1;
01690             }
01691         }
01692 
01693         if (j)
01694         {
01695             ch->num_users--;
01696             for (i--; i < ch->num_users; i++)
01697             {
01698                 ch->users[i] = ch->users[i + 1];
01699             }
01700         }
01701     }
01702 }

void do_joinchannel ( dbref  player,
struct channel ch 
)

Definition at line 1129 of file comsys.cpp.

References BuildChannelMessage(), comuser::bUserIsOn, CHANNEL_SPOOF, comuser::ComTitleStatus, channel::header, Hidden, ISOUTOFMEMORY, channel::max_users, MEMALLOC, MEMFREE, channel::name, channel::num_users, comuser::on_next, channel::on_users, raw_notify(), select_user(), SendChannelMessage(), StringClone(), comuser::title, tprintf(), channel::type, UNDEAD, channel::users, and comuser::who.

Referenced by do_processcom(), and load_comsystem().

01130 {
01131     struct comuser **cu;
01132     int i;
01133 
01134     struct comuser *user = select_user(ch, player);
01135 
01136     if (!user)
01137     {
01138         ch->num_users++;
01139         if (ch->num_users >= ch->max_users)
01140         {
01141             ch->max_users += 10;
01142             cu = (struct comuser **)MEMALLOC(sizeof(struct comuser *) * ch->max_users);
01143             ISOUTOFMEMORY(cu);
01144 
01145             for (i = 0; i < (ch->num_users - 1); i++)
01146             {
01147                 cu[i] = ch->users[i];
01148             }
01149             MEMFREE(ch->users);
01150             ch->users = cu;
01151         }
01152         user = (struct comuser *)MEMALLOC(sizeof(struct comuser));
01153         ISOUTOFMEMORY(user);
01154 
01155         for (i = ch->num_users - 1; i > 0 && ch->users[i - 1]->who > player; i--)
01156         {
01157             ch->users[i] = ch->users[i - 1];
01158         }
01159         ch->users[i] = user;
01160 
01161         user->who            = player;
01162         user->bUserIsOn      = true;
01163         user->ComTitleStatus = true;
01164         user->title          = StringClone("");
01165 
01166         // if (Connected(player))&&(isPlayer(player))
01167         //
01168         if (UNDEAD(player))
01169         {
01170             user->on_next = ch->on_users;
01171             ch->on_users  = user;
01172         }
01173     }
01174     else if (!user->bUserIsOn)
01175     {
01176         user->bUserIsOn = true;
01177     }
01178     else
01179     {
01180         raw_notify(player, tprintf("You are already on channel %s.", ch->name));
01181         return;
01182     }
01183 
01184     if (!Hidden(player))
01185     {
01186         char *messNormal, *messNoComtitle;
01187         BuildChannelMessage((ch->type & CHANNEL_SPOOF) != 0, ch->header, user,
01188             ":has joined this channel.", &messNormal, &messNoComtitle);
01189         SendChannelMessage(player, ch, messNormal, messNoComtitle);
01190     }
01191 }

void do_leavechannel ( dbref  player,
struct channel ch 
)

Definition at line 1193 of file comsys.cpp.

References BuildChannelMessage(), comuser::bUserIsOn, CHANNEL_SPOOF, channel::header, Hidden, channel::name, raw_notify(), select_user(), SendChannelMessage(), tprintf(), and channel::type.

Referenced by do_processcom().

01194 {
01195     struct comuser *user = select_user(ch, player);
01196     raw_notify(player, tprintf("You have left channel %s.", ch->name));
01197     if (  user->bUserIsOn
01198        && !Hidden(player))
01199     {
01200         char *messNormal, *messNoComtitle;
01201         BuildChannelMessage((ch->type & CHANNEL_SPOOF) != 0, ch->header, user,
01202             ":has left this channel.", &messNormal, &messNoComtitle);
01203         SendChannelMessage(player, ch, messNormal, messNoComtitle);
01204     }
01205     user->bUserIsOn = false;
01206 }

char* get_channel_from_alias (  ) 

void load_channels ( FILE *  fp  ) 

Definition at line 236 of file comsys.cpp.

References add_comsys(), tagComsys::alias, ALIAS_SIZE, tagComsys::channels, create_new_comsys(), ENDLINE, GetLineTrunc(), Good_obj, ISOUTOFMEMORY, LBUF_SIZE, Log, tagComsys::maxchannels, MEMALLOC, mux_assert, tagComsys::numchannels, ParseChannelLine(), purge_comsystem(), sort_com_aliases(), CLogFile::tinyprintf(), and tagComsys::who.

Referenced by load_comsys().

00237 {
00238     int i, j;
00239     char buffer[LBUF_SIZE];
00240     comsys_t *c;
00241 
00242     int np = 0;
00243     int cc = fscanf(fp, "%d\n", &np);
00244     mux_assert(1 == cc);
00245     for (i = 0; i < np; i++)
00246     {
00247         c = create_new_comsys();
00248         c->who = 0;
00249         c->numchannels = 0;
00250         cc = fscanf(fp, "%d %d\n", &(c->who), &(c->numchannels));
00251         mux_assert(2 == cc);
00252         c->maxchannels = c->numchannels;
00253         if (c->maxchannels > 0)
00254         {
00255             c->alias = (char *)MEMALLOC(c->maxchannels * ALIAS_SIZE);
00256             ISOUTOFMEMORY(c->alias);
00257             c->channels = (char **)MEMALLOC(sizeof(char *) * c->maxchannels);
00258             ISOUTOFMEMORY(c->channels);
00259 
00260             for (j = 0; j < c->numchannels; j++)
00261             {
00262                 int n = GetLineTrunc(buffer, sizeof(buffer), fp);
00263                 if (buffer[n-1] == '\n')
00264                 {
00265                     // Get rid of trailing '\n'.
00266                     //
00267                     n--;
00268                     buffer[n] = '\0';
00269                 }
00270                 if (!ParseChannelLine(buffer, c->alias + j * ALIAS_SIZE, c->channels+j))
00271                 {
00272                     c->numchannels--;
00273                     j--;
00274                 }
00275             }
00276             sort_com_aliases(c);
00277         }
00278         else
00279         {
00280             c->alias = NULL;
00281             c->channels = NULL;
00282         }
00283         if (Good_obj(c->who))
00284         {
00285             add_comsys(c);
00286         }
00287         else
00288         {
00289             Log.tinyprintf("Invalid dbref %d." ENDLINE, c->who);
00290         }
00291         purge_comsystem();
00292     }
00293 }

void load_comsys ( char *  filename  ) 

Definition at line 71 of file comsys.cpp.

References comsys_table, DebugTotalFiles, ENDLINE, load_channels(), load_comsystem(), Log, NUM_COMSYS, and CLogFile::tinyprintf().

Referenced by load_game().

00072 {
00073     int i;
00074     char buffer[200];
00075 
00076     for (i = 0; i < NUM_COMSYS; i++)
00077     {
00078         comsys_table[i] = NULL;
00079     }
00080 
00081     FILE *fp = fopen(filename, "rb");
00082     if (!fp)
00083     {
00084         Log.tinyprintf("Error: Couldn't find %s." ENDLINE, filename);
00085     }
00086     else
00087     {
00088         DebugTotalFiles++;
00089         Log.tinyprintf("LOADING: %s" ENDLINE, filename);
00090         if (fscanf(fp, "*** Begin %s ***\n", buffer) == 1 && !strcmp(buffer, "CHANNELS"))
00091         {
00092             load_channels(fp);
00093         }
00094         else
00095         {
00096             Log.tinyprintf("Error: Couldn't find Begin CHANNELS in %s.", filename);
00097             if (fclose(fp) == 0)
00098             {
00099                 DebugTotalFiles--;
00100             }
00101             return;
00102         }
00103 
00104         if (fscanf(fp, "*** Begin %s ***\n", buffer) == 1 && !strcmp(buffer, "COMSYS"))
00105         {
00106             load_comsystem(fp);
00107         }
00108         else
00109         {
00110             Log.tinyprintf("Error: Couldn't find Begin COMSYS in %s.", filename);
00111             if (fclose(fp) == 0)
00112             {
00113                 DebugTotalFiles--;
00114             }
00115             return;
00116         }
00117 
00118         if (fclose(fp) == 0)
00119         {
00120             DebugTotalFiles--;
00121         }
00122         Log.tinyprintf("LOADING: %s (done)" ENDLINE, filename);
00123     }
00124 }

void load_comsystem ( FILE *  fp  ) 

Definition at line 525 of file comsys.cpp.

References ANSI_BLUE, ANSI_CYAN, ANSI_ENDGOAL_NORMAL, ANSI_HILITE, ANSI_MAGENTA, ANSI_NORMAL, ANSI_RED, ANSI_TruncateToField(), statedata::channel_htab, CHANNEL_PUBLIC, statedata::db_top, do_joinchannel(), ENDLINE, GetLineTrunc(), God, Going, Good_dbref, hashaddLEN(), isGarbage, ISOUTOFMEMORY, isPlayer, LBUF_SIZE, Log, MAX_CHANNEL_LEN, MAX_HEADER_LEN, MAX_TITLE_LEN, MEMALLOC, mudstate, mux_assert, mux_atol(), NOTHING, num_channels, comuser::on_next, Owner, sort_users(), StringCloneLen(), CLogFile::tinyprintf(), comuser::title, and comuser::who.

Referenced by load_comsys().

00526 {
00527     int i, j, dummy;
00528     int ver = 0;
00529     struct channel *ch;
00530     char temp[LBUF_SIZE];
00531 
00532     num_channels = 0;
00533 
00534     int nc = 0;
00535     fgets(temp, sizeof(temp), fp);
00536     if (!strncmp(temp, "+V", 2))
00537     {
00538         // +V2 has colored headers
00539         //
00540         ver = mux_atol(temp + 2);
00541         if (ver < 1 || 3 < ver)
00542         {
00543             return;
00544         }
00545         int cc;
00546         cc = fscanf(fp, "%d\n", &nc);
00547         mux_assert(1 == cc);
00548     }
00549     else
00550     {
00551         nc = mux_atol(temp);
00552     }
00553 
00554     num_channels = nc;
00555 
00556     for (i = 0; i < nc; i++)
00557     {
00558         ch = (struct channel *)MEMALLOC(sizeof(struct channel));
00559         ISOUTOFMEMORY(ch);
00560 
00561         int nChannel = GetLineTrunc(temp, sizeof(temp), fp);
00562         if (nChannel > MAX_CHANNEL_LEN)
00563         {
00564             nChannel = MAX_CHANNEL_LEN;
00565         }
00566         if (temp[nChannel-1] == '\n')
00567         {
00568             // Get rid of trailing '\n'.
00569             //
00570             nChannel--;
00571         }
00572         memcpy(ch->name, temp, nChannel);
00573         ch->name[nChannel] = '\0';
00574 
00575         if (ver >= 2)
00576         {
00577             int nHeader = GetLineTrunc(temp, sizeof(temp), fp);
00578             if (nHeader > MAX_HEADER_LEN)
00579             {
00580                 nHeader = MAX_HEADER_LEN;
00581             }
00582             if (temp[nHeader-1] == '\n')
00583             {
00584                 nHeader--;
00585             }
00586             memcpy(ch->header, temp, nHeader);
00587             ch->header[nHeader] = '\0';
00588         }
00589 
00590         ch->on_users = NULL;
00591 
00592         hashaddLEN(ch->name, nChannel, ch, &mudstate.channel_htab);
00593 
00594         ch->type         = 127;
00595         ch->temp1        = 0;
00596         ch->temp2        = 0;
00597         ch->charge       = 0;
00598         ch->charge_who   = NOTHING;
00599         ch->amount_col   = 0;
00600         ch->num_messages = 0;
00601         ch->chan_obj     = NOTHING;
00602 
00603         int cc;
00604         if (ver >= 1)
00605         {
00606             cc = fscanf(fp, "%d %d %d %d %d %d %d %d\n",
00607                 &(ch->type), &(ch->temp1), &(ch->temp2),
00608                 &(ch->charge), &(ch->charge_who),
00609                 &(ch->amount_col), &(ch->num_messages), &(ch->chan_obj));
00610             mux_assert(8 == cc);
00611         }
00612         else
00613         {
00614             cc = fscanf(fp, "%d %d %d %d %d %d %d %d %d %d\n",
00615                 &(ch->type), &(dummy), &(ch->temp1), &(ch->temp2),
00616                 &(dummy), &(ch->charge), &(ch->charge_who),
00617                 &(ch->amount_col), &(ch->num_messages), &(ch->chan_obj));
00618             mux_assert(10 == cc);
00619         }
00620 
00621         if (ver <= 1)
00622         {
00623             // Build colored header if not +V2 or later db.
00624             //
00625             if (ch->type & CHANNEL_PUBLIC)
00626             {
00627                 sprintf(temp, "%s[%s%s%s%s%s]%s", ANSI_CYAN, ANSI_HILITE,
00628                     ANSI_BLUE, ch->name, ANSI_NORMAL, ANSI_CYAN, ANSI_NORMAL);
00629             }
00630             else
00631             {
00632                 sprintf(temp, "%s[%s%s%s%s%s]%s", ANSI_MAGENTA, ANSI_HILITE,
00633                     ANSI_RED, ch->name, ANSI_NORMAL, ANSI_MAGENTA,
00634                     ANSI_NORMAL);
00635             }
00636             int vwVisual;
00637             ANSI_TruncateToField(temp, MAX_HEADER_LEN+1, ch->header,
00638                 MAX_HEADER_LEN+1, &vwVisual, ANSI_ENDGOAL_NORMAL);
00639         }
00640 
00641         ch->num_users = 0;
00642         cc =fscanf(fp, "%d\n", &(ch->num_users));
00643         mux_assert(1 == cc);
00644         ch->max_users = ch->num_users;
00645         if (ch->num_users > 0)
00646         {
00647             ch->users = (struct comuser **)calloc(ch->max_users, sizeof(struct comuser *));
00648             ISOUTOFMEMORY(ch->users);
00649 
00650             int jAdded = 0;
00651             for (j = 0; j < ch->num_users; j++)
00652             {
00653                 struct comuser t_user;
00654                 memset(&t_user, 0, sizeof(t_user));
00655 
00656                 t_user.who = NOTHING;
00657                 t_user.bUserIsOn = false;
00658                 t_user.ComTitleStatus = false;
00659 
00660                 int iUserIsOn;
00661                 if (ver == 3)
00662                 {
00663                     int iComTitleStatus;
00664                     cc = fscanf(fp, "%d %d %d\n", &(t_user.who), &iUserIsOn,
00665                         &iComTitleStatus);
00666                     mux_assert(3 == cc);
00667                     t_user.bUserIsOn = (iUserIsOn ? true : false);
00668                     t_user.ComTitleStatus = (iComTitleStatus ? true : false);
00669                 }
00670                 else
00671                 {
00672                     t_user.ComTitleStatus = true;
00673                     if (ver)
00674                     {
00675                         cc = fscanf(fp, "%d %d\n", &(t_user.who), &iUserIsOn);
00676                         mux_assert(2 == cc);
00677                         t_user.bUserIsOn = (iUserIsOn ? true : false);
00678                     }
00679                     else
00680                     {
00681                         cc = fscanf(fp, "%d %d %d", &(t_user.who), &(dummy), &(dummy));
00682                         mux_assert(3 == cc);
00683                         cc = fscanf(fp, "%d\n", &iUserIsOn);
00684                         mux_assert(1 == cc);
00685                         t_user.bUserIsOn = (iUserIsOn ? true : false);
00686                     }
00687                 }
00688 
00689                 // Read Comtitle.
00690                 //
00691                 int nTitle = GetLineTrunc(temp, sizeof(temp), fp);
00692                 char *pTitle = temp;
00693 
00694                 if (!Good_dbref(t_user.who))
00695                 {
00696                     Log.tinyprintf("load_comsystem: dbref %d out of range [0, %d)." ENDLINE, t_user.who, mudstate.db_top);
00697                 }
00698                 else if (isGarbage(t_user.who))
00699                 {
00700                     Log.tinyprintf("load_comsystem: dbref is GARBAGE." ENDLINE, t_user.who);
00701                 }
00702                 else
00703                 {
00704                     // Validate comtitle
00705                     //
00706                     if (3 < nTitle && temp[0] == 't' && temp[1] == ':')
00707                     {
00708                         pTitle = temp+2;
00709                         nTitle -= 2;
00710                         if (pTitle[nTitle-1] == '\n')
00711                         {
00712                             // Get rid of trailing '\n'.
00713                             //
00714                             nTitle--;
00715                         }
00716                         if (nTitle <= 0 || MAX_TITLE_LEN < nTitle)
00717                         {
00718                             nTitle = 0;
00719                             pTitle = temp;
00720                         }
00721                     }
00722                     else
00723                     {
00724                         nTitle = 0;
00725                     }
00726 
00727                     struct comuser *user = (struct comuser *)MEMALLOC(sizeof(struct comuser));
00728                     ISOUTOFMEMORY(user);
00729                     memcpy(user, &t_user, sizeof(struct comuser));
00730 
00731                     user->title = StringCloneLen(pTitle, nTitle);
00732                     ch->users[jAdded++] = user;
00733 
00734                     if (  !(isPlayer(user->who))
00735                        && !(Going(user->who)
00736                        && (God(Owner(user->who)))))
00737                     {
00738                         do_joinchannel(user->who, ch);
00739                     }
00740                     user->on_next = ch->on_users;
00741                     ch->on_users = user;
00742                 }
00743             }
00744             ch->num_users = jAdded;
00745             sort_users(ch);
00746         }
00747         else
00748         {
00749             ch->users = NULL;
00750         }
00751     }
00752 }

void purge_comsystem ( void   ) 

Definition at line 295 of file comsys.cpp.

References comsys_table, del_comsys(), God, Going, isPlayer, tagComsys::next, NUM_COMSYS, tagComsys::numchannels, Owner, and tagComsys::who.

Referenced by load_channels(), and save_channels().

00296 {
00297 #ifdef ABORT_PURGE_COMSYS
00298     return;
00299 #endif // ABORT_PURGE_COMSYS
00300 
00301     comsys_t *c;
00302     comsys_t *d;
00303     int i;
00304     for (i = 0; i < NUM_COMSYS; i++)
00305     {
00306         c = comsys_table[i];
00307         while (c)
00308         {
00309             d = c;
00310             c = c->next;
00311             if (d->numchannels == 0)
00312             {
00313                 del_comsys(d->who);
00314                 continue;
00315             }
00316             if (isPlayer(d->who))
00317             {
00318                 continue;
00319             }
00320             if (  God(Owner(d->who))
00321                && Going(d->who))
00322             {
00323                 del_comsys(d->who);
00324                 continue;
00325             }
00326         }
00327     }
00328 }

void save_channels ( FILE *  fp  ) 

Definition at line 330 of file comsys.cpp.

References ALIAS_SIZE, comsys_table, tagComsys::next, NUM_COMSYS, and purge_comsystem().

Referenced by save_comsys().

00331 {
00332     purge_comsystem();
00333 
00334     comsys_t *c;
00335     int i, j;
00336     int np = 0;
00337     for (i = 0; i < NUM_COMSYS; i++)
00338     {
00339         c = comsys_table[i];
00340         while (c)
00341         {
00342             np++;
00343             c = c->next;
00344         }
00345     }
00346 
00347     fprintf(fp, "%d\n", np);
00348     for (i = 0; i < NUM_COMSYS; i++)
00349     {
00350         c = comsys_table[i];
00351         while (c)
00352         {
00353             fprintf(fp, "%d %d\n", c->who, c->numchannels);
00354             for (j = 0; j < c->numchannels; j++)
00355             {
00356                 fprintf(fp, "%s %s\n", c->alias + j * ALIAS_SIZE, c->channels[j]);
00357             }
00358             c = c->next;
00359         }
00360     }
00361 }

void save_comsys ( char *  filename  ) 

Definition at line 126 of file comsys.cpp.

References DebugTotalFiles, ENDLINE, Log, ReplaceFile(), save_channels(), save_comsystem(), and CLogFile::tinyprintf().

Referenced by dump_database_internal().

00127 {
00128     char buffer[500];
00129 
00130     sprintf(buffer, "%s.#", filename);
00131     FILE *fp = fopen(buffer, "wb");
00132     if (!fp)
00133     {
00134         Log.tinyprintf("Unable to open %s for writing." ENDLINE, buffer);
00135         return;
00136     }
00137     DebugTotalFiles++;
00138     fprintf(fp, "*** Begin CHANNELS ***\n");
00139     save_channels(fp);
00140 
00141     fprintf(fp, "*** Begin COMSYS ***\n");
00142     save_comsystem(fp);
00143 
00144     if (fclose(fp) == 0)
00145     {
00146         DebugTotalFiles--;
00147     }
00148     ReplaceFile(buffer, filename);
00149 }

void save_comsystem ( FILE *  fp  ) 

Definition at line 754 of file comsys.cpp.

References channel::amount_col, comuser::bUserIsOn, channel::chan_obj, statedata::channel_htab, channel::charge, channel::charge_who, comuser::ComTitleStatus, statedata::db_top, hash_firstentry(), hash_nextentry(), channel::header, mudstate, channel::name, num_channels, channel::num_messages, channel::num_users, channel::temp1, channel::temp2, comuser::title, channel::type, channel::users, and comuser::who.

Referenced by save_comsys().

00755 {
00756     struct channel *ch;
00757     struct comuser *user;
00758     int j;
00759 
00760     fprintf(fp, "+V3\n");
00761     fprintf(fp, "%d\n", num_channels);
00762     for (ch = (struct channel *)hash_firstentry(&mudstate.channel_htab);
00763          ch;
00764          ch = (struct channel *)hash_nextentry(&mudstate.channel_htab))
00765     {
00766         fprintf(fp, "%s\n", ch->name);
00767         fprintf(fp, "%s\n", ch->header);
00768 
00769         fprintf(fp, "%d %d %d %d %d %d %d %d\n", ch->type, ch->temp1,
00770             ch->temp2, ch->charge, ch->charge_who, ch->amount_col,
00771             ch->num_messages, ch->chan_obj);
00772 
00773         // Count the number of 'valid' users to dump.
00774         //
00775         int nUsers = 0;
00776         for (j = 0; j < ch->num_users; j++)
00777         {
00778             user = ch->users[j];
00779             if (user->who >= 0 && user->who < mudstate.db_top)
00780             {
00781                 nUsers++;
00782             }
00783         }
00784 
00785         fprintf(fp, "%d\n", nUsers);
00786         for (j = 0; j < ch->num_users; j++)
00787         {
00788             user = ch->users[j];
00789             if (user->who >= 0 && user->who < mudstate.db_top)
00790             {
00791                 user = ch->users[j];
00792                 fprintf(fp, "%d %d %d\n", user->who, user->bUserIsOn, user->ComTitleStatus);
00793                 if (user->title[0] != '\0')
00794                 {
00795                     fprintf(fp, "t:%s\n", user->title);
00796                 }
00797                 else
00798                 {
00799                     fprintf(fp, "t:\n");
00800                 }
00801             }
00802         }
00803     }
00804 }

struct channel* select_channel ( char *  channel  ) 

Definition at line 1407 of file comsys.cpp.

References statedata::channel_htab, hashfindLEN(), and mudstate.

Referenced by do_addcom(), do_cemit(), do_chanlog(), do_channelwho(), do_chboot(), do_cheader(), do_chopen(), do_comconnectchannel(), do_comconnectraw_notify(), do_comdisconnectchannel(), do_comdisconnectraw_notify(), do_comlist(), do_comtitle(), do_createchannel(), do_delcomchannel(), do_editchannel(), do_processcom(), and FUNCTION().

01408 {
01409     struct channel *cp = (struct channel *)hashfindLEN(channel,
01410         strlen(channel), &mudstate.channel_htab);
01411     return cp;
01412 }

struct comuser* select_user ( struct channel ch,
dbref  player 
)

Definition at line 1414 of file comsys.cpp.

References channel::num_users, channel::users, and comuser::who.

Referenced by do_chboot(), do_comconnectchannel(), do_comconnectraw_notify(), do_comdisconnectraw_notify(), do_comlist(), do_comtitle(), do_joinchannel(), do_leavechannel(), do_processcom(), do_setcomtitlestatus(), do_setnewtitle(), and FUNCTION().

01415 {
01416     if (!ch)
01417     {
01418         return NULL;
01419     }
01420 
01421     int first = 0;
01422     int last = ch->num_users - 1;
01423     int dir = 1;
01424     int current = 0;
01425 
01426     while (dir && (first <= last))
01427     {
01428         current = (first + last) / 2;
01429         if (ch->users[current] == NULL)
01430         {
01431             last--;
01432             continue;
01433         }
01434         if (ch->users[current]->who == player)
01435         {
01436             dir = 0;
01437         }
01438         else if (ch->users[current]->who < player)
01439         {
01440             dir = 1;
01441             first = current + 1;
01442         }
01443         else
01444         {
01445             dir = -1;
01446             last = current - 1;
01447         }
01448     }
01449 
01450     if (!dir)
01451     {
01452         return ch->users[current];
01453     }
01454     else
01455     {
01456         return NULL;
01457     }
01458 }

void SendChannelMessage ( dbref  player,
struct channel ch,
char *  msgNormal,
char *  msgNoComtitle 
)

Definition at line 1051 of file comsys.cpp.

References AF_CONST, AF_NOPARSE, AF_NOPROG, atr_add(), atr_get, atr_str(), comuser::bUserIsOn, channel::chan_obj, CHANNEL_SPOOF, comuser::ComTitleStatus, DFLT_MAX_LOG, free_lbuf, GOD, Good_obj, iMod(), MAX_RECALL_REQUEST, mkattr(), mux_atol(), mux_ltoa_t(), NOTHING, notify_with_cause_ooc, channel::num_messages, attr::number, comuser::on_next, channel::on_users, test_receive_access(), tprintf(), channel::type, and comuser::who.

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

01057 {
01058     bool bSpoof = ((ch->type & CHANNEL_SPOOF) != 0);
01059     ch->num_messages++;
01060 
01061     struct comuser *user;
01062     for (user = ch->on_users; user; user = user->on_next)
01063     {
01064         if (  user->bUserIsOn
01065            && test_receive_access(user->who, ch))
01066         {
01067             if (  user->ComTitleStatus
01068                || bSpoof
01069                || msgNoComtitle == NULL)
01070             {
01071                 notify_with_cause_ooc(user->who, executor, msgNormal);
01072             }
01073             else
01074             {
01075                 notify_with_cause_ooc(user->who, executor, msgNoComtitle);
01076             }
01077         }
01078     }
01079 
01080     dbref obj = ch->chan_obj;
01081     if (Good_obj(obj))
01082     {
01083         dbref aowner;
01084         int aflags;
01085         int logmax = DFLT_MAX_LOG;
01086         char *maxbuf;
01087         ATTR *pattr = atr_str("MAX_LOG");
01088         if (  pattr
01089            && pattr->number)
01090         {
01091             maxbuf = atr_get(obj, pattr->number, &aowner, &aflags);
01092             logmax = mux_atol(maxbuf);
01093             free_lbuf(maxbuf);
01094         }
01095         if (logmax > 0)
01096         {
01097             if (logmax > MAX_RECALL_REQUEST)
01098             {
01099                 logmax = MAX_RECALL_REQUEST;
01100                 atr_add(ch->chan_obj, pattr->number, mux_ltoa_t(logmax), GOD,
01101                     AF_CONST|AF_NOPROG|AF_NOPARSE);
01102             }
01103             char *p = tprintf("HISTORY_%d", iMod(ch->num_messages, logmax));
01104             int atr = mkattr(GOD, p);
01105             if (0 < atr)
01106             {
01107                 atr_add(ch->chan_obj, atr, msgNormal, GOD, AF_CONST|AF_NOPROG|AF_NOPARSE);
01108             }
01109         }
01110     }
01111     else if (ch->chan_obj != NOTHING)
01112     {
01113         ch->chan_obj = NOTHING;
01114     }
01115 
01116     // Since msgNormal and msgNoComTitle are no longer needed, free them here.
01117     //
01118     if (msgNormal)
01119     {
01120         free_lbuf(msgNormal);
01121     }
01122     if (  msgNoComtitle
01123        && msgNoComtitle != msgNormal)
01124     {
01125         free_lbuf(msgNoComtitle);
01126     }
01127 }

void sort_com_aliases ( comsys_t c  ) 

Definition at line 469 of file comsys.cpp.

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

Referenced by load_channels().

00470 {
00471     int i;
00472     char buffer[10];
00473     char *s;
00474     bool cont = true;
00475 
00476     while (cont)
00477     {
00478         cont = false;
00479         for (i = 0; i < c->numchannels - 1; i++)
00480         {
00481             if (strcmp(c->alias + i * ALIAS_SIZE, c->alias + (i + 1) * ALIAS_SIZE) > 0)
00482             {
00483                 strcpy(buffer, c->alias + i * ALIAS_SIZE);
00484                 strcpy(c->alias + i * ALIAS_SIZE, c->alias + (i + 1) * ALIAS_SIZE);
00485                 strcpy(c->alias + (i + 1) * ALIAS_SIZE, buffer);
00486                 s = c->channels[i];
00487                 c->channels[i] = c->channels[i + 1];
00488                 c->channels[i + 1] = s;
00489                 cont = true;
00490             }
00491         }
00492     }
00493 }

void sort_users ( struct channel ch  ) 

Definition at line 2165 of file comsys.cpp.

References channel::num_users, channel::users, and comuser::who.

Referenced by load_comsystem().

02166 {
02167     int i;
02168     bool done = false;
02169     struct comuser *user;
02170     int nu = ch->num_users;
02171 
02172     while (!done)
02173     {
02174         done = true;
02175         for (i = 0; i < (nu - 1); i++)
02176         {
02177             if (ch->users[i]->who > ch->users[i + 1]->who)
02178             {
02179                 user = ch->users[i];
02180                 ch->users[i] = ch->users[i + 1];
02181                 ch->users[i + 1] = user;
02182                 done = false;
02183             }
02184         }
02185     }
02186 }

bool test_join_access ( dbref  player,
struct channel chan 
)

Definition at line 2546 of file comsys.cpp.

References A_LOCK, channel::chan_obj, CHANNEL_OBJECT_JOIN, CHANNEL_PLAYER_JOIN, Comm_All, could_doit(), isPlayer, and channel::type.

Referenced by do_addcom().

02547 {
02548     if (Comm_All(player))
02549     {
02550         return true;
02551     }
02552 
02553     int access;
02554     if (isPlayer(player))
02555     {
02556         access = CHANNEL_PLAYER_JOIN;
02557     }
02558     else
02559     {
02560         access = CHANNEL_OBJECT_JOIN;
02561     }
02562     return (  (chan->type & access) != 0
02563            || could_doit(player, chan->chan_obj, A_LOCK));
02564 }

bool test_receive_access ( dbref  player,
struct channel chan 
)

Definition at line 2587 of file comsys.cpp.

References A_LENTER, channel::chan_obj, CHANNEL_OBJECT_RECEIVE, CHANNEL_PLAYER_RECEIVE, Comm_All, could_doit(), isPlayer, and channel::type.

Referenced by SendChannelMessage().

02588 {
02589     if (Comm_All(player))
02590     {
02591         return true;
02592     }
02593 
02594     int access;
02595     if (isPlayer(player))
02596     {
02597         access = CHANNEL_PLAYER_RECEIVE;
02598     }
02599     else
02600     {
02601         access = CHANNEL_OBJECT_RECEIVE;
02602     }
02603     return (  (chan->type & access) != 0
02604            || could_doit(player, chan->chan_obj, A_LENTER));
02605 
02606 }

bool test_transmit_access ( dbref  player,
struct channel chan 
)

Definition at line 2566 of file comsys.cpp.

References A_LUSE, channel::chan_obj, CHANNEL_OBJECT_TRANSMIT, CHANNEL_PLAYER_TRANSMIT, Comm_All, could_doit(), isPlayer, and channel::type.

Referenced by do_processcom().

02567 {
02568     if (Comm_All(player))
02569     {
02570         return true;
02571     }
02572 
02573     int access;
02574     if (isPlayer(player))
02575     {
02576         access = CHANNEL_PLAYER_TRANSMIT;
02577     }
02578     else
02579     {
02580         access = CHANNEL_OBJECT_TRANSMIT;
02581     }
02582     return (  (chan->type & access) != 0
02583            || could_doit(player, chan->chan_obj, A_LUSE));
02584 
02585 }


Generated on Mon May 28 04:40:14 2007 for MUX by  doxygen 1.4.7