/********************************************************************* v.1 dsc.c Dynamic Saved Channels ... Allows for multiple user-defined channels, with easy communications to them Requirments: ewtoo derivitive talker Notes: This alters your pfiles... if you are squimish at the sight of blood, or have a weak stomach, don't bother trying to install. Installation instructions are for SensiSummink 1.3, if you dont have get_string_safe, youll have to change the call (along with updating your pfiles). Once you install and set MAX_CHANNELS, that is Set In Stone... as in, dont change it, unless you run a pfile update to do so, else youll bugger your files. Youll find any staff related commands missing from this release, mainly cause the staff have no buisness mucking about with any of it. Its all private stuff, even using the tell and remote commands to a specfic consentual group. basically... I dont think staff have any reason to police or even have knowledge of channels... so i dint code any way for them to. Take it how you will. Usage: Once installed, to communicate with a channel, simply do tells or remotes to it as if it were a player. list_chans [channel] Used alone, it will list all the channels that you are on, if a [channel] argument is given, it will list everyone on [channel] (assuming that you are actually on that channel) join_chan Join/Create . The word used is simply a matter of semantics. leave_chan Remove yoursele from chan_hi Recieve channels in hilight. block_all_chans Toggle block recieving of all channels. This is so you can remove yourself without doing it one at a time, or having to rejoin the channels. Installing: Place this file in your src dir, have it linked into your talker as an object as the other files are done. Decide the maximum possible channels your ressies may be on at once. Change the follownig define to reflect that, and place it in player.h #define MAX_CHANNELS 10 Add the following to player.h, where ever you wish ... (note with these, they are at these offsets so that a future release may use lower and upper offsets for other things... something to consider if you think about changing them) #define BLOCK_ALL_CHANS (1<<21) #define HI_CHANS (1<<22) In either proto.h or player.h (to the bottom), add the following ... extern void connect_channels (player *); extern void disconnect_channels (player *); extern int tell_command_channel (player *, char *, char *); extern int remote_command_channel (player *, char *, char *); To your player struct (in player.h) add the following members ... char channels[MAX_CHANNELS][MAX_NAME]; int dsc_flags; To your tell() function add the following, after check for FROGGED, and (if you have it) after repeat bit. if (tell_command_channel (p, str, msg)) return; To your remote() function add the following, after check for FROGGED, and (if you have it) after repeat bit. if (remote_command_channel (p, str, msg)) return; To plists.c, link_to_program(), at the endish of the function... (note, possibly youll not be able to successfully put it there, just so long as it gets put after the person is going to login, your ok) connect_channels (p); To commands.c, quit(), at the endish of the function... disconnect_channels (p); And the part that mucks with your playerfiles, so be berybery carepul plists.c, construct_save_data() ... declare (if you dont have it declared already) int i; At the end of all the store_*'ing calls that are there, add: for (i = 0; i < MAX_CHANNELS; i++) stack = store_string (stack, p->channels[i]); stack = store_int (stack, p->dsc_flags); plists.c, load_player() (or load_player_common()) declare (if you dont have it declared already) int i; At the end of all the get_*_safe calls that are there, add: for (i = 0; i < MAX_CHANNELS; i++) r = get_string_safe (p->channels[i], r, sp->data); r = get_int_safe (&p->dsc_flags, r, sp->data); Finally add some commands to clist.h, these commands are safe enough to give to newbies if you wish... (you dont have to use these its just how the code currently Format : 's the stuff) command function list_chans list_channels join_chan join_channel leave_chan leave_channel chan_hi hichan block_all_chans block_all_channels Bug Reports: send to phypor@benland.muc.edu Licences: freely distributable and modifiable, as long as credit given in appropritate places for any distrubitions (be it this alone or within another package) "DSC channel code by phypor" in help credits or equavelant is sufficent. Warranty: non, the author is in no way responsible for use, misuse, abuse, or any other actions misactions, reactions of this code, its provided as is. Author: phypor "if it breaks you get to keep both pieces" ~old linux proverb *********************************************************************/ /* * dsc.c Dynamic Saved Channels by phypor */ #include #include #include /* alter these as needed, possibly youll need to change proto.h to player.h */ #include "config.h" #include "proto.h" /* ok, heres the deal...if you dont have ez_*, thats fine, you probably have the equvelant already... for instance, if you use sensisummink3+ then uncomment the stuff for it, if you use pg, then uncomment the stuff for that...if you have your own version then you prolly dont need any help figuring out whut to do... and finally, if you have no printf format functions ...you should get ez.c from http://benland.muc.edu/~clouds/code/ cause its highly useful... (altho there is only one call here to it, its still useful to have for other things) */ /* sensisummink 3+ #define ez_tell_player vtell_player */ /* pg #define ez_tell_player TELLPLAYER */ /* if you want to have a diffrent char appear in front of channel stufs, change it here....(note, keep it a single char with '' around it ...) */ #define DSC_TAG ')' void tell_channels (char * channel, char * msg) { player *scan; int i, oct = command_type; command_type = 0; for (scan = flatlist_start; scan; scan = scan->flat_next) for (i = 0; i < MAX_CHANNELS; i++) if (!strcasecmp (scan->channels[i], channel) && !(scan->dsc_flags & BLOCK_ALL_CHANS)) { if (scan->dsc_flags & HI_CHANS) command_type |= HIGHLIGHT; ez_tell_player (scan, "%c %s", DSC_TAG, msg); if (scan->dsc_flags & HI_CHANS) command_type &= ~HIGHLIGHT; break; } command_type = oct; } void connect_channels (player * p) { char *oldstack = stack; int i; if (p->dsc_flags & BLOCK_ALL_CHANS) return; for (i = 0; i < MAX_CHANNELS; i++) if (*(p->channels[i])) { sprintf (stack, "[%s] LOGIN: %s\n", p->channels[i], p->name); stack = end_string (stack); tell_channels (p->channels[i], oldstack); stack = oldstack; } } void disconnect_channels (player * p) { char *oldstack = stack; int i; if (p->dsc_flags & BLOCK_ALL_CHANS || !p->location || !p->name[0]) return; for (i = 0; i < MAX_CHANNELS; i++) if (*(p->channels[i])) { sprintf (stack, "[%s] LOGOUT: %s\n", p->channels[i], p->name); stack = end_string (stack); tell_channels (p->channels[i], oldstack); stack = oldstack; } } char *says_asks_exclaims ( player * p, char * str ) { if (*str) switch (str[strlen (str) - 1]) { case '!': if (p->gender == PLURAL) return "exclaim"; else return "exclaims"; case '?': if (p->gender == PLURAL) return "ask"; else return "asks"; } if (p->gender == PLURAL) return "say"; else return "says"; } int tell_command_channel (player * p, char * chan, char * msg) { int i; char *oldstack = stack; if (p->dsc_flags & BLOCK_ALL_CHANS) return 0; for (i = 0; i < MAX_CHANNELS; i++) { if (!strncasecmp (p->channels[i], chan, strlen (chan))) { sprintf (stack, "[%s] %s %s '%s'\n", p->channels[i], p->name, says_asks_exclaims (p, msg), msg); stack = end_string (stack); tell_channels (p->channels[i], oldstack); stack = oldstack; return 1; } } return 0; } int remote_command_channel (player * p, char * chan, char * msg) { int i; char *oldstack = stack; if (p->dsc_flags & BLOCK_ALL_CHANS) return 0; for (i = 0; i < MAX_CHANNELS; i++) { if (!strncasecmp (p->channels[i], chan, strlen (chan))) { if ((*msg == '\'') || (*msg == ',')) sprintf (stack,"[%s] %s%s\n", p->channels[i], p->name, msg); else sprintf (stack,"[%s] %s %s\n", p->channels[i], p->name, msg); stack = end_string (stack); tell_channels (p->channels[i], oldstack); stack = oldstack; return 1; } } return 0; } void list_whos_on_channel (player * p, char * channel) { player *scan; int counted = 0, i; char *oldstack = stack; for (scan = flatlist_start; scan; scan = scan->flat_next) for (i = 0; i < MAX_CHANNELS; i++) if (!strcasecmp (scan->channels[i], channel)) { counted++; if (scan->dsc_flags & BLOCK_ALL_CHANS) stack += sprintf (stack, "(%s), ", scan->name); else stack += sprintf (stack, "%s, ", scan->name); } if (counted) { stack = end_string (stack); oldstack[strlen (oldstack) - 2] = '.'; oldstack[strlen (oldstack) - 1] = '\n'; tell_player (p, oldstack); } else tell_player (p, " Noone on the channel ?!? *le boggle*\n"); stack = oldstack; } void list_channels (player * p, char * str) { int i, hit = 0; char *oldsac = stack; for (i = 0; i < MAX_CHANNELS; i++) if (*(p->channels[i])) break; if (i == MAX_CHANNELS) { tell_player (p, " You aren't on any channels atm.\n"); return; } if (*str) { for (i = 0; i < MAX_CHANNELS; i++) if (!strncasecmp (p->channels[i], str, strlen (str))) { list_whos_on_channel (p, p->channels[i]); return; } ez_tell_player (p, " But you aren't on the '%s' channel?\n", str); return; } sprintf (stack, " You are on the following channels ...\n"); for (i = 0; i < MAX_CHANNELS; i++) if (*(p->channels[i])) { stack += sprintf (stack, " %s\n", p->channels[i]); hit++; } if (hit) { stack += sprintf (stack, " (On %d of a maximum %d channels)\n", hit, MAX_CHANNELS); stack = end_string (stack); tell_player (p, oldsac); } else tell_player (p, " You are on no channels at all.\n"); stack = oldsac; if (p->dsc_flags & BLOCK_ALL_CHANS) tell_player (p, " Btw, you are blocking all channels.\n"); } void join_channel (player * p, char * str) { char *oldstack = stack, *ptr = str; player *p2, dummy; int i; if (!*str) { tell_player(p, " Format : join_chan \n"); return; } if (p->dsc_flags & BLOCK_ALL_CHANS) { tell_player (p, " You should unblock channels before doing that.\n"); return; } while (*ptr++) if (*ptr == ' ') { *ptr = '\0'; break; } if (strlen (str) > MAX_NAME - 2) { tell_player (p, " That is just too long to have as a channel name.\n"); return; } p2 = find_player_absolute_quiet (str); if (p2) { tell_player (p, " You dont really want to name your channel " "after a person... do you?\n"); return; } strncpy (dummy.lower_name, str, MAX_NAME - 1); lower_case (dummy.lower_name); dummy.fd = p->fd; if (load_player (&dummy)) { tell_player (p, " You dont really want to name your channel " "after a person... do you?.\n"); return; } for (i = 0; i < MAX_CHANNELS; i++) if (!strcasecmp (p->channels[i], str)) { tell_player (p, " You are already on that channel.\n"); return; } for (i = 0; i < MAX_CHANNELS; i++) if (!*(p->channels[i])) break; if (*(p->channels[i])) { tell_player (p, " You are on the most channels that you may join.\n"); return; } strncpy (p->channels[i], str, MAX_NAME - 1); sprintf (stack, "[%s] JOINING: %s\n", str, p->name); stack = end_string(stack); tell_channels(str, oldstack); stack = oldstack; } void leave_channel (player * p, char * str) { char *oldstack = stack; int i; if (!*str) { tell_player (p, " Format : leave_chan \n"); return; } for (i = 0; i < MAX_CHANNELS; i++) if (!strcasecmp (p->channels[i], str)) { sprintf (stack, "[%s] DEPARTING: %s\n", str, p->name); stack = end_string (stack); tell_channels (str, oldstack); stack = oldstack; memset (p->channels[i], 0, MAX_NAME); if (p->dsc_flags & BLOCK_ALL_CHANS) tell_player (p, " You leave the channel.\n"); return; } tell_player(p, " You don't seem to be on that channel.\n"); } void hichan (player * p, char * str) { if (!*str) p->dsc_flags ^= HI_CHANS; else if (!strcasecmp (str, "on")) p->dsc_flags |= HI_CHANS; else if (!strcasecmp (str, "off")) p->dsc_flags &= ~HI_CHANS; else tell_player (p, " Format : chan_hi [on/off]\n"); if (p->dsc_flags & HI_CHANS) tell_player (p, " You will get channels hilighted.\n"); else tell_player (p, " You will not get channels hilighted.\n"); } void block_all_channels (player * p, char * str) { if (!*str) p->dsc_flags ^= BLOCK_ALL_CHANS; else if (!strcasecmp (str, "on")) p->dsc_flags |= BLOCK_ALL_CHANS; else if (!strcasecmp (str, "off")) p->dsc_flags &= ~BLOCK_ALL_CHANS; else tell_player (p, " Format : block_all_chans [on/off]\n"); if (p->dsc_flags & BLOCK_ALL_CHANS) tell_player (p, " You are blocking off all channels.\n"); else tell_player (p, " You are not blocking channels.\n"); }