00001
00002
00003
00004
00005 #include <ctype.h>
00006 #include <sys/types.h>
00007
00008 #include "copyright.h"
00009 #include "config.h"
00010 #include "db.h"
00011 #include "interface.h"
00012 #include "attrs.h"
00013 #include "match.h"
00014 #include "config.h"
00015 #include "externs.h"
00016 #include "flags.h"
00017 #include "powers.h"
00018
00019 #include "comsys.h"
00020 #include "p.comsys.h"
00021 #include "p.functions.h"
00022 #include "create.h"
00023
00024
00025 static void do_save_com(chmsg *);
00026 static void do_show_com(chmsg *);
00027 static void do_comlast(dbref, struct channel *);
00028 static void do_comsend(struct channel *, char *);
00029 static void do_comprintf(struct channel *, char *, ...);
00030 extern void do_joinchannel(dbref, struct channel *);
00031 static void do_leavechannel(dbref, struct channel *);
00032 static void do_comwho(dbref, struct channel *);
00033 static void do_setnewtitle(dbref, struct channel *, char *);
00034 extern void sort_users(struct channel *);
00035 static int do_test_access(dbref, long, struct channel *);
00036
00037
00038
00039
00040
00041 void init_chantab(void)
00042 {
00043 hashinit(&mudstate.channel_htab, 30 * HASH_FACTOR);
00044 }
00045
00046 void send_channel(char *chan, const char *format, ...)
00047 {
00048 struct channel *ch;
00049 char buf[LBUF_SIZE];
00050 char data[LBUF_SIZE];
00051 char *newline;
00052 va_list ap;
00053
00054 if(!(ch = select_channel(chan)))
00055 return;
00056 va_start(ap, format);
00057 vsnprintf(data, LBUF_SIZE, format, ap);
00058 va_end(ap);
00059
00060 snprintf(buf, LBUF_SIZE-1, "[%s] %s", chan, data);
00061 while ((newline = strchr(buf, '\n')))
00062 *newline = ' ';
00063 do_comsend(ch, buf);
00064 }
00065
00066 char *get_channel_from_alias(dbref player, char *alias)
00067 {
00068 struct commac *c;
00069 int first, last, current = 0;
00070 int dir;
00071
00072 c = get_commac(player);
00073
00074 first = 0;
00075 last = c->numchannels - 1;
00076 dir = 1;
00077
00078 while (dir && (first <= last)) {
00079 current = (first + last) / 2;
00080 dir = strcasecmp(alias, c->alias + 6 * current);
00081 if(dir < 0)
00082 last = current - 1;
00083 else
00084 first = current + 1;
00085 }
00086
00087 if(!dir)
00088 return c->channels[current];
00089 else
00090 return "";
00091 }
00092
00093 void load_comsystem(FILE * fp)
00094 {
00095 int i, j, k, dummy;
00096 int nc, new = 0;
00097 struct channel *ch;
00098 struct comuser *user;
00099 char temp[LBUF_SIZE];
00100 char buf[8];
00101
00102 num_channels = 0;
00103
00104 fgets(buf, sizeof(buf), fp);
00105 if(!strncmp(buf, "+V2", 3)) {
00106 new = 2;
00107 fscanf(fp, "%d\n", &nc);
00108 } else if(!strncmp(buf, "+V1", 3)) {
00109 new = 1;
00110 fscanf(fp, "%d\n", &nc);
00111 } else
00112 nc = atoi(buf);
00113
00114 num_channels = nc;
00115
00116 for(i = 0; i < nc; i++) {
00117 ch = (struct channel *) malloc(sizeof(struct channel));
00118
00119 fscanf(fp, "%[^\n]\n", temp);
00120
00121 strncpy(ch->name, temp, CHAN_NAME_LEN);
00122 ch->name[CHAN_NAME_LEN - 1] = '\0';
00123 ch->on_users = NULL;
00124
00125 hashadd(ch->name, (int *) ch, &mudstate.channel_htab);
00126
00127 ch->last_messages = NULL;
00128
00129 if(new) {
00130
00131 if(fscanf(fp,
00132 new ==
00133 1 ? "%d %d %d %d %d %d %d %d\n" :
00134 "%d %d %d %d %d %d %d %d %d\n", &(ch->type),
00135 &(ch->temp1), &(ch->temp2), &(ch->charge),
00136 &(ch->charge_who), &(ch->amount_col),
00137 &(ch->num_messages), &(ch->chan_obj), &dummy) >= 9 &&
00138 new > 1) {
00139
00140 if(dummy > 0) {
00141 for(j = 0; j < dummy; j++) {
00142 chmsg *c;
00143
00144 fscanf(fp, "%d %[^\n]\n", &k, temp);
00145 Create(c, chmsg, 1);
00146 c->msg = strdup(temp);
00147 c->time = k;
00148 myfifo_push(&ch->last_messages, c);
00149 }
00150 }
00151 }
00152 } else {
00153 fscanf(fp, "%d %d %d %d %d %d %d %d %d %d\n", &(ch->type),
00154 &(dummy), &(ch->temp1), &(ch->temp2), &(dummy),
00155 &(ch->charge), &(ch->charge_who), &(ch->amount_col),
00156 &(ch->num_messages), &(ch->chan_obj));
00157 }
00158
00159 fscanf(fp, "%d\n", &(ch->num_users));
00160 ch->max_users = ch->num_users;
00161 if(ch->num_users > 0) {
00162 ch->users = (struct comuser **)
00163 calloc(ch->max_users, sizeof(struct comuser *));
00164
00165 for(j = 0; j < ch->num_users; j++) {
00166 user = (struct comuser *) malloc(sizeof(struct comuser));
00167
00168 ch->users[j] = user;
00169
00170 if(new) {
00171 fscanf(fp, "%d %d\n", &(user->who), &(user->on));
00172 } else {
00173 fscanf(fp, "%d %d %d", &(user->who), &(dummy), &(dummy));
00174 fscanf(fp, "%d\n", &(user->on));
00175 }
00176
00177 fscanf(fp, "%[^\n]\n", temp);
00178
00179 user->title = strdup(temp + 2);
00180
00181 if(!(isPlayer(user->who)) && !(Going(user->who) &&
00182 (God(Owner(user->who))))) {
00183 do_joinchannel(user->who, ch);
00184 user->on_next = ch->on_users;
00185 ch->on_users = user;
00186 } else {
00187 user->on_next = ch->on_users;
00188 ch->on_users = user;
00189 }
00190 }
00191 sort_users(ch);
00192 } else
00193 ch->users = NULL;
00194 }
00195 }
00196
00197 static FILE *temp_file;
00198
00199 static void do_save_com(chmsg * d)
00200 {
00201 fprintf(temp_file, "%d %s\n", (int) d->time, d->msg);
00202 }
00203
00204 void save_comsystem(FILE * fp)
00205 {
00206 struct channel *ch;
00207 struct comuser *user;
00208 int j, k, player_users;
00209
00210 fprintf(fp, "+V2\n");
00211 fprintf(fp, "%d\n", num_channels);
00212 for(ch = (struct channel *) hash_firstentry(&mudstate.channel_htab);
00213 ch; ch = (struct channel *) hash_nextentry(&mudstate.channel_htab)) {
00214 fprintf(fp, "%s\n", ch->name);
00215 k = myfifo_length(&ch->last_messages);
00216
00217 fprintf(fp, "%d %d %d %d %d %d %d %d %d\n", ch->type, ch->temp1,
00218 ch->temp2, ch->charge, ch->charge_who, ch->amount_col,
00219 ch->num_messages, ch->chan_obj, k);
00220
00221 if(k) {
00222 temp_file = fp;
00223 myfifo_trav_r(&ch->last_messages, do_save_com);
00224 }
00225 player_users = 0;
00226 for(j = 0; j < ch->num_users; j++)
00227 if(isPlayer(ch->users[j]->who) || isRobot(ch->users[j]->who))
00228 player_users++;
00229
00230 fprintf(fp, "%d\n", player_users);
00231 for(j = 0; j < ch->num_users; j++) {
00232 user = ch->users[j];
00233 if(!isPlayer(user->who) && !isRobot(user->who))
00234 continue;
00235 fprintf(fp, "%d %d\n", user->who, user->on);
00236 if(strlen(user->title))
00237 fprintf(fp, "t:%s\n", user->title);
00238 else
00239 fprintf(fp, "t:\n");
00240 }
00241 }
00242 }
00243
00244 static dbref cheat_player;
00245
00246 static void do_show_com(chmsg * d)
00247 {
00248 struct tm *t;
00249 int day;
00250 char buf[LBUF_SIZE];
00251
00252 t = localtime(&mudstate.now);
00253 day = t->tm_mday;
00254 t = localtime(&d->time);
00255 if(day == t->tm_mday) {
00256 sprintf(buf, "[%02d:%02d] %s", t->tm_hour, t->tm_min, d->msg);
00257 } else
00258 sprintf(buf, "[%02d.%02d / %02d:%02d] %s", t->tm_mon + 1,
00259 t->tm_mday, t->tm_hour, t->tm_min, d->msg);
00260 notify(cheat_player, buf);
00261 }
00262
00263 static void do_comlast(dbref player, struct channel *ch)
00264 {
00265 if(!myfifo_length(&ch->last_messages)) {
00266 notify_printf(player, "There haven't been any messages on %s.",
00267 ch->name);
00268 return;
00269 }
00270 cheat_player = player;
00271 myfifo_trav_r(&ch->last_messages, do_show_com);
00272 }
00273
00274 void do_processcom(dbref player, char *arg1, char *arg2)
00275 {
00276 struct channel *ch;
00277 struct comuser *user;
00278
00279 if((strlen(arg1) + strlen(arg2)) > LBUF_SIZE / 2) {
00280 arg2[LBUF_SIZE / 2 - strlen(arg1)] = '\0';
00281 }
00282 if(!*arg2) {
00283 raw_notify(player, "No message.");
00284 return;
00285 }
00286
00287 if(!Wizard(player) && In_IC_Loc(player)) {
00288 raw_notify(player, "Permission denied.");
00289 return;
00290 }
00291
00292 if(!(ch = select_channel(arg1))) {
00293 notify_printf(player, "Unknown channel %s.", arg1);
00294 return;
00295 }
00296 if(!(user = select_user(ch, player))) {
00297 raw_notify(player,
00298 "You are not listed as on that channel. Delete this alias and re-add.");
00299 return;
00300 }
00301 if(!strcasecmp(arg2, "on")) {
00302 do_joinchannel(player, ch);
00303 } else if(!strcasecmp(arg2, "off")) {
00304 do_leavechannel(player, ch);
00305 } else if(!user->on && !Wizard(player) && !mudconf.allow_chanlurking) {
00306 notify_printf(player, "You must be on %s to do that.", arg1);
00307 return;
00308 } else if(!strcasecmp(arg2, "who")) {
00309 do_comwho(player, ch);
00310 } else if(!strcasecmp(arg2, "last")) {
00311 do_comlast(player, ch);
00312 } else if(!user->on) {
00313 notify_printf(player, "You must be on %s to do that.", arg1);
00314 return;
00315 } else if(!do_test_access(player, CHANNEL_TRANSMIT, ch)) {
00316 raw_notify(player, "That channel type cannot be transmitted on.");
00317 return;
00318 } else {
00319 if(!payfor(player, Guest(player) ? 0 : ch->charge)) {
00320 notify_printf(player, "You don't have enough %s.",
00321 mudconf.many_coins);
00322 return;
00323 } else {
00324 ch->amount_col += ch->charge;
00325 giveto(ch->charge_who, ch->charge);
00326 }
00327
00328 if((*arg2) == ':')
00329 do_comprintf(ch, "[%s] %s %s", arg1, Name(player), arg2 + 1);
00330 else if((*arg2) == ';')
00331 do_comprintf(ch, "[%s] %s%s", arg1, Name(player), arg2 + 1);
00332 else if(strlen(user->title))
00333 do_comprintf(ch, "[%s] %s: <%s> %s", arg1, Name(player), user->title, arg2);
00334 else
00335 do_comprintf(ch, "[%s] %s: %s", arg1, Name(player), arg2);
00336 }
00337 }
00338
00339 static void do_comsend(struct channel *ch, char *mess)
00340 {
00341 struct comuser *user;
00342 chmsg *c;
00343
00344 ch->num_messages++;
00345 for(user = ch->on_users; user; user = user->on_next) {
00346 if(user->on && do_test_access(user->who, CHANNEL_RECIEVE, ch) &&
00347 (Wizard(user->who) || !In_IC_Loc(user->who))) {
00348 if(Typeof(user->who) == TYPE_PLAYER && Connected(user->who))
00349 raw_notify(user->who, mess);
00350 else
00351 notify(user->who, mess);
00352 }
00353 }
00354
00355 if(myfifo_length(&ch->last_messages) >= CHANNEL_HISTORY_LEN) {
00356 c = myfifo_pop(&ch->last_messages);
00357 free((void *) c->msg);
00358 } else
00359 Create(c, chmsg, 1);
00360 c->msg = strdup(mess);
00361 c->time = mudstate.now;
00362 myfifo_push(&ch->last_messages, c);
00363 }
00364
00365 static void do_comprintf(struct channel *ch, char *messfmt, ...)
00366 {
00367 struct comuser *user;
00368 chmsg *c;
00369 va_list ap;
00370 char buffer[LBUF_SIZE];
00371 memset(buffer, 0, LBUF_SIZE);
00372 va_start(ap, messfmt);
00373 vsnprintf(buffer, LBUF_SIZE-1, messfmt, ap);
00374 va_end(ap);
00375
00376 ch->num_messages++;
00377 for(user = ch->on_users; user; user = user->on_next) {
00378 if(user->on && do_test_access(user->who, CHANNEL_RECIEVE, ch) &&
00379 (Wizard(user->who) || !In_IC_Loc(user->who))) {
00380 if(Typeof(user->who) == TYPE_PLAYER && Connected(user->who))
00381 raw_notify(user->who, buffer);
00382 else
00383 notify(user->who, buffer);
00384 }
00385 }
00386
00387 if(myfifo_length(&ch->last_messages) >= CHANNEL_HISTORY_LEN) {
00388 c = myfifo_pop(&ch->last_messages);
00389 free((void *) c->msg);
00390 } else
00391 Create(c, chmsg, 1);
00392 c->msg = strdup(buffer);
00393 c->time = mudstate.now;
00394 myfifo_push(&ch->last_messages, c);
00395 }
00396
00397 extern void do_joinchannel(dbref player, struct channel *ch)
00398 {
00399 struct comuser *user;
00400 int i;
00401
00402 user = select_user(ch, player);
00403
00404 if(!user) {
00405 ch->num_users++;
00406 if(ch->num_users >= ch->max_users) {
00407 ch->max_users += 10;
00408 ch->users = realloc(ch->users, sizeof(struct comuser *) *
00409 ch->max_users);
00410 memset(ch->users+(ch->num_users-1), 0,
00411 sizeof(struct comuser *)*(ch->max_users-ch->num_users));
00412 }
00413 user = (struct comuser *) malloc(sizeof(struct comuser));
00414
00415 for(i = ch->num_users - 1;
00416 i > 0 && ch->users[i - 1]->who > player; i--)
00417 ch->users[i] = ch->users[i - 1];
00418 ch->users[i] = user;
00419
00420 user->who = player;
00421 user->on = 1;
00422 user->title = strdup("");
00423
00424 if(UNDEAD(player)) {
00425 user->on_next = ch->on_users;
00426 ch->on_users = user;
00427 }
00428 } else if(!user->on) {
00429 user->on = 1;
00430 } else {
00431 notify_printf(player, "You are already on channel %s.", ch->name);
00432 return;
00433 }
00434 #if 0
00435
00436 for(i = ch->num_users - 1; i > 0; i--) {
00437 if(!ch->users[i]) break;
00438 if(Typeof(ch->users[i]->who) == TYPE_THING)
00439 did_it(player, ch->users[i]->who, 0, NULL, 0, NULL, A_AENTER,
00440 (char **) NULL, 0);
00441 }
00442 #endif
00443 notify_printf(player, "You have joined channel %s.", ch->name);
00444
00445 if(!Dark(player)) {
00446 do_comprintf(ch, "[%s] %s has joined this channel.", ch->name, Name(player));
00447 }
00448 }
00449
00450 static void do_leavechannel(dbref player, struct channel *ch)
00451 {
00452 struct comuser *user;
00453 int i;
00454
00455 user = select_user(ch, player);
00456
00457 if(!user)
00458 return;
00459
00460
00461 for(i = ch->num_users - 1; i > 0; i--) {
00462 if(Typeof(ch->users[i]->who) == TYPE_THING)
00463 did_it(player, ch->users[i]->who, 0, NULL, 0, NULL, A_ALEAVE,
00464 (char **) NULL, 0);
00465 }
00466
00467 notify_printf(player, "You have left channel %s.", ch->name);
00468
00469 if((user->on) && (!Dark(player))) {
00470 char *c = Name(player);
00471
00472 if(c && *c) {
00473 do_comprintf(ch,"[%s] %s has left this channel.", ch->name, c);
00474 }
00475 }
00476 user->on = 0;
00477 }
00478
00479 static void do_comwho(dbref player, struct channel *ch)
00480 {
00481 struct comuser *user;
00482 char *buff;
00483
00484 raw_notify(player, "-- Players --");
00485 for(user = ch->on_users; user; user = user->on_next) {
00486 if(Typeof(user->who) == TYPE_PLAYER && user->on &&
00487 Connected(user->who) && (!Hidden(user->who) ||
00488 ((ch->type & CHANNEL_TRANSPARENT)
00489 && !Dark(user->who))
00490 || Wizard_Who(player))
00491 && (!In_IC_Loc(user->who) || Wizard(user->who))) {
00492
00493 int i = fetch_idle(user->who);
00494
00495 buff = unparse_object(player, user->who, 0);
00496 if(i > 30) {
00497 char *c = get_uptime_to_string(i);
00498
00499 notify_printf(player, "%s [idle %s]", buff, c);
00500 free_sbuf(c);
00501 } else
00502 notify_printf(player, "%s", buff);
00503 free_lbuf(buff);
00504 }
00505 }
00506
00507 raw_notify(player, "-- Objects --");
00508 for(user = ch->on_users; user; user = user->on_next) {
00509 if(Typeof(user->who) != TYPE_PLAYER && user->on &&
00510 !(Going(user->who) && God(Owner(user->who)))) {
00511 buff = unparse_object(player, user->who, 0);
00512 notify_printf(player, "%s", buff);
00513 free_lbuf(buff);
00514 }
00515 }
00516 notify_printf(player, "-- %s --", ch->name);
00517 }
00518
00519 struct channel *select_channel(char *channel)
00520 {
00521 return (struct channel *) hashfind(channel, &mudstate.channel_htab);
00522 }
00523
00524 struct comuser *select_user(struct channel *ch, dbref player)
00525 {
00526 int last, current;
00527 int dir = 1, first = 0;
00528
00529 if(!ch)
00530 return NULL;
00531
00532 last = ch->num_users - 1;
00533 current = (first + last) / 2;
00534
00535 while (dir && (first <= last)) {
00536 current = (first + last) / 2;
00537 if(ch->users[current] == NULL) {
00538 last--;
00539 continue;
00540 }
00541 if(ch->users[current]->who == player)
00542 dir = 0;
00543 else if(ch->users[current]->who < player) {
00544 dir = 1;
00545 first = current + 1;
00546 } else {
00547 dir = -1;
00548 last = current - 1;
00549 }
00550 }
00551
00552 if(!dir)
00553 return ch->users[current];
00554 else
00555 return NULL;
00556 }
00557
00558 void do_addcom(dbref player, dbref cause, int key, char *arg1, char *arg2)
00559 {
00560 char channel[200];
00561 char title[100];
00562 struct channel *ch;
00563 char *s;
00564 int where;
00565 struct commac *c;
00566
00567 if(!mudconf.have_comsys) {
00568 raw_notify(player, "Comsys disabled.");
00569 return;
00570 }
00571 if(!*arg1) {
00572 raw_notify(player, "You need to specify an alias.");
00573 return;
00574 }
00575 if(!*arg2) {
00576 raw_notify(player, "You need to specify a channel.");
00577 return;
00578 }
00579
00580 s = strchr(arg2, ',');
00581
00582 if(s) {
00583
00584 if(s >= arg2 + 200) {
00585 raw_notify(player, "Channel name too long.");
00586 return;
00587 }
00588 strncpy(channel, arg2, s - arg2);
00589 channel[s - arg2] = '\0';
00590 strncpy(title, s + 1, 100);
00591 title[99] = '\0';
00592 } else {
00593
00594 if(strlen(arg2) >= 200) {
00595 raw_notify(player, "Channel name too long.");
00596 return;
00597 }
00598 strcpy(channel, arg2);
00599 title[0] = '\0';
00600 }
00601
00602 if(strchr(channel, ' ')) {
00603 raw_notify(player, "Channel name cannot contain spaces.");
00604 return;
00605 }
00606
00607 if(!(ch = select_channel(channel))) {
00608 notify_printf(player, "Channel %s does not exist yet.", channel);
00609 return;
00610 }
00611 if(!do_test_access(player, CHANNEL_JOIN, ch)) {
00612 raw_notify(player,
00613 "Sorry, this channel type does not allow you to join.");
00614 return;
00615 }
00616 if(select_user(ch, player)) {
00617 raw_notify(player,
00618 "Warning: you are already listed on that channel.");
00619 }
00620 c = get_commac(player);
00621 for(where = 0; where < c->numchannels &&
00622 (strcasecmp(arg1, c->alias + where * 6) > 0); where++);
00623 if(where < c->numchannels && !strcasecmp(arg1, c->alias + where * 6)) {
00624 notify_printf(player, "That alias is already in use for channel %s.",
00625 c->channels[where]);
00626 return;
00627 }
00628 if(c->numchannels >= c->maxchannels) {
00629 c->maxchannels += 10;
00630 c->alias = realloc(c->alias, sizeof(char) * 6 * c->maxchannels);
00631 c->channels = realloc(c->channels, sizeof(char *) * c->maxchannels);
00632 }
00633 if(where < c->numchannels) {
00634 memmove(c->alias + 6 * (where + 1), c->alias + 6 * where,
00635 6 * (c->numchannels - where));
00636 memmove(c->channels + where + 1, c->channels + where,
00637 sizeof(c->channels) * (c->numchannels - where));
00638 }
00639
00640 c->numchannels++;
00641
00642 strncpy(c->alias + 6 * where, arg1, 5);
00643 c->alias[where * 6 + 5] = '\0';
00644 c->channels[where] = strdup(ch->name);
00645
00646 do_joinchannel(player, ch);
00647 do_setnewtitle(player, ch, title);
00648
00649 if(title[0])
00650 notify_printf(player, "Channel %s added with alias %s and title %s.",
00651 ch, arg1, title);
00652 else
00653 notify_printf(player, "Channel %s added with alias %s.",
00654 ch, arg1);
00655 }
00656
00657 static void do_setnewtitle(dbref player, struct channel *ch, char *title)
00658 {
00659 struct comuser *user;
00660 char *new;
00661
00662 user = select_user(ch, player);
00663
00664
00665
00666 if(!ch || !user)
00667 return;
00668
00669 new = replace_string("\r\n", "", title);
00670 if(user->title)
00671 free(user->title);
00672 user->title = strdup(new);
00673 free_lbuf(new);
00674 }
00675
00676 void do_delcom(dbref player, dbref cause, int key, char *arg1)
00677 {
00678 int i;
00679 struct commac *c;
00680
00681 if(!mudconf.have_comsys) {
00682 raw_notify(player, "Comsys disabled.");
00683 return;
00684 }
00685 if(!arg1) {
00686 raw_notify(player, "Need an alias to delete.");
00687 return;
00688 }
00689 c = get_commac(player);
00690
00691 for(i = 0; i < c->numchannels; i++) {
00692 if(!strcasecmp(arg1, c->alias + i * 6)) {
00693 do_delcomchannel(player, c->channels[i]);
00694 notify_printf(player, "Channel %s deleted.", c->channels[i]);
00695 free(c->channels[i]);
00696
00697 c->numchannels--;
00698 if(i < c->numchannels) {
00699 memmove(c->alias + 6 * i, c->alias + 6 * (i + 1),
00700 6 * (c->numchannels - i));
00701 memmove(c->channels + i, c->channels + i + 1,
00702 sizeof(c->channels) * (c->numchannels - i));
00703 }
00704 return;
00705 }
00706 }
00707 raw_notify(player, "Unable to find that alias.");
00708 }
00709
00710 void do_delcomchannel(dbref player, char *channel)
00711 {
00712 struct channel *ch;
00713 struct comuser *user;
00714 int i;
00715
00716 if(!(ch = select_channel(channel))) {
00717 notify_printf(player, "Unknown channel %s.", channel);
00718 } else {
00719
00720
00721 for(i = ch->num_users - 1; i > 0; i--) {
00722 if(Typeof(ch->users[i]->who) == TYPE_THING)
00723 did_it(player, ch->users[i]->who, 0, NULL, 0, NULL, A_ALEAVE,
00724 (char **) NULL, 0);
00725 }
00726
00727 for(i = 0; i < ch->num_users; i++) {
00728 user = ch->users[i];
00729 if(user->who == player) {
00730 do_comdisconnectchannel(player, channel);
00731 if(user->on && !Dark(player)) {
00732 char *c = Name(player);
00733
00734 if(c && *c)
00735 do_comprintf(ch, "[%s] %s has left this channel.", channel, c);
00736 }
00737 notify_printf(player, "You have left channel %s.", channel);
00738
00739 if(user->title)
00740 free(user->title);
00741 free(user);
00742 ch->num_users--;
00743 if(i < ch->num_users)
00744 memmove(ch->users + i, ch->users + i + 1,
00745 sizeof(ch->users) * (ch->num_users - i));
00746 }
00747 }
00748 }
00749 }
00750
00751 void do_createchannel(dbref player, dbref cause, int key, char *channel)
00752 {
00753 struct channel *newchannel;
00754
00755 if(!mudconf.have_comsys) {
00756 raw_notify(player, "Comsys disabled.");
00757 return;
00758 }
00759 if(select_channel(channel)) {
00760 notify_printf(player, "Channel %s already exists.", channel);
00761 return;
00762 }
00763 if(!*channel) {
00764 raw_notify(player, "You must specify a channel to create.");
00765 return;
00766 }
00767 if(!(Comm_All(player))) {
00768 raw_notify(player, "You do not have permission to do that.");
00769 return;
00770 }
00771 newchannel = (struct channel *) malloc(sizeof(struct channel));
00772
00773 strncpy(newchannel->name, channel, CHAN_NAME_LEN - 1);
00774 newchannel->name[CHAN_NAME_LEN - 1] = '\0';
00775 newchannel->last_messages = NULL;
00776 newchannel->type = 127;
00777 newchannel->temp1 = 0;
00778 newchannel->temp2 = 0;
00779 newchannel->charge = 0;
00780 newchannel->charge_who = player;
00781 newchannel->amount_col = 0;
00782 newchannel->num_users = 0;
00783 newchannel->max_users = 0;
00784 newchannel->users = NULL;
00785 newchannel->on_users = NULL;
00786 newchannel->chan_obj = NOTHING;
00787 newchannel->num_messages = 0;
00788
00789 num_channels++;
00790
00791 hashadd(newchannel->name, (int *) newchannel, &mudstate.channel_htab);
00792
00793 notify_printf(player, "Channel %s created.", channel);
00794 }
00795
00796 void do_destroychannel(dbref player, dbref cause, int key, char *channel)
00797 {
00798 struct channel *ch;
00799 int j;
00800
00801 if(!mudconf.have_comsys) {
00802 raw_notify(player, "Comsys disabled.");
00803 return;
00804 }
00805 ch = (struct channel *) hashfind(channel, &mudstate.channel_htab);
00806
00807 if(!ch) {
00808 notify_printf(player, "Could not find channel %s.", channel);
00809 return;
00810 } else if(!(Comm_All(player)) && (player != ch->charge_who)) {
00811 raw_notify(player, "You do not have permission to do that. ");
00812 return;
00813 }
00814 num_channels--;
00815 hashdelete(channel, &mudstate.channel_htab);
00816
00817 for(j = 0; j < ch->num_users; j++) {
00818 free(ch->users[j]);
00819 }
00820 free(ch->users);
00821 free(ch);
00822 notify_printf(player, "Channel %s destroyed.", channel);
00823 }
00824
00825 void do_listchannels(dbref player)
00826 {
00827 struct channel *ch;
00828 int perm;
00829
00830 if(!(perm = Comm_All(player))) {
00831 raw_notify(player,
00832 "Warning: Only public channels and your channels will be shown.");
00833 }
00834 raw_notify(player,
00835 "** Channel --Flags-- Obj Own Charge Balance Users Messages");
00836
00837 for(ch = (struct channel *) hash_firstentry(&mudstate.channel_htab);
00838 ch; ch = (struct channel *) hash_nextentry(&mudstate.channel_htab))
00839 if(perm || (ch->type & CHANNEL_PUBLIC)
00840 || ch->charge_who == player) {
00841
00842 notify_printf(player,
00843 "%c%c %-20.20s %c%c%c/%c%c%c %5d %5d %8d %8d %6d %10d",
00844 (ch->type & (CHANNEL_PUBLIC)) ? 'P' : '-',
00845 (ch->type & (CHANNEL_LOUD)) ? 'L' : '-', ch->name,
00846 (ch->type & (CHANNEL_PL_MULT *
00847 CHANNEL_JOIN)) ? 'J' : '-',
00848 (ch->type & (CHANNEL_PL_MULT *
00849 CHANNEL_TRANSMIT)) ? 'X' : '-',
00850 (ch->type & (CHANNEL_PL_MULT *
00851 CHANNEL_RECIEVE)) ? 'R' : '-',
00852 (ch->type & (CHANNEL_OBJ_MULT *
00853 CHANNEL_JOIN)) ? 'j' : '-',
00854 (ch->type & (CHANNEL_OBJ_MULT *
00855 CHANNEL_TRANSMIT)) ? 'x' : '-',
00856 (ch->type & (CHANNEL_OBJ_MULT *
00857 CHANNEL_RECIEVE)) ? 'r' : '-',
00858 (ch->chan_obj != NOTHING) ? ch->chan_obj : -1,
00859 ch->charge_who, ch->charge, ch->amount_col,
00860 ch->num_users, ch->num_messages);
00861 }
00862 raw_notify(player, "-- End of list of Channels --");
00863 }
00864
00865 void do_comtitle(dbref player, dbref cause, int key, char *arg1, char *arg2)
00866 {
00867 struct channel *ch;
00868 char channel[100];
00869
00870 if(!mudconf.have_comsys) {
00871 raw_notify(player, "Comsys disabled.");
00872 return;
00873 }
00874 if(!*arg1) {
00875 raw_notify(player, "Need an alias to do comtitle.");
00876 return;
00877 }
00878 strncpy(channel, get_channel_from_alias(player, arg1), 100);
00879 channel[99] = '\0';
00880
00881 if(!*channel) {
00882 raw_notify(player, "Unknown alias");
00883 return;
00884 }
00885 if((ch = select_channel(channel)) && select_user(ch, player)) {
00886 notify_printf(player, "Title set to '%s' on channel %s.",
00887 arg2, channel);
00888 do_setnewtitle(player, ch, arg2);
00889 }
00890 if(!ch) {
00891 raw_notify(player, "Invalid comsys alias, please delete.");
00892 return;
00893 }
00894 }
00895
00896 void do_comlist(dbref player, dbref cause, int key)
00897 {
00898 struct comuser *user;
00899 struct commac *c;
00900 int i;
00901
00902 if(!mudconf.have_comsys) {
00903 raw_notify(player, "Comsys disabled.");
00904 return;
00905 }
00906 c = get_commac(player);
00907
00908 raw_notify(player,
00909 "Alias Channel Title Status");
00910
00911 for(i = 0; i < c->numchannels; i++) {
00912 if((user = select_user(select_channel(c->channels[i]), player))) {
00913 notify_printf(player, "%-9.9s %-19.19s %-39.39s %s",
00914 c->alias + i * 6, c->channels[i],
00915 user->title, (user->on ? "on" : "off"));
00916 } else {
00917 notify_printf(player, "Bad Comsys Alias: %s for Channel: %s",
00918 c->alias + i * 6, c->channels[i]);
00919 }
00920 }
00921 raw_notify(player, "-- End of comlist --");
00922 }
00923
00924 void do_channelnuke(dbref player)
00925 {
00926 struct channel *ch;
00927 int j;
00928
00929 for(ch = (struct channel *) hash_firstentry(&mudstate.channel_htab);
00930 ch; ch = (struct channel *) hash_nextentry(&mudstate.channel_htab)) {
00931 if(ch->charge_who == player) {
00932 num_channels--;
00933 hashdelete(ch->name, &mudstate.channel_htab);
00934
00935 for(j = 0; j < ch->num_users; j++)
00936 free(ch->users[j]);
00937 free(ch->users);
00938 free(ch);
00939 }
00940 }
00941 }
00942
00943 void do_clearcom(dbref player, dbref cause, int key)
00944 {
00945 int i;
00946 struct commac *c;
00947
00948 if(!mudconf.have_comsys) {
00949 raw_notify(player, "Comsys disabled.");
00950 return;
00951 }
00952 c = get_commac(player);
00953
00954 for(i = (c->numchannels) - 1; i > -1; --i) {
00955 do_delcom(player, player, 0, c->alias + i * 6);
00956 }
00957 }
00958
00959 void do_allcom(dbref player, dbref cause, int key, char *arg1)
00960 {
00961 int i;
00962 struct commac *c;
00963
00964 if(!mudconf.have_comsys) {
00965 raw_notify(player, "Comsys disabled.");
00966 return;
00967 }
00968 c = get_commac(player);
00969
00970 if((strcasecmp(arg1, "who") != 0) && (strcasecmp(arg1, "on") != 0) &&
00971 (strcasecmp(arg1, "off") != 0)) {
00972 raw_notify(player, "Only options available are: on, off and who.");
00973 return;
00974 }
00975 for(i = 0; i < c->numchannels; i++) {
00976 do_processcom(player, c->channels[i], arg1);
00977 if(strcasecmp(arg1, "who") == 0)
00978 raw_notify(player, "");
00979 }
00980
00981 }
00982
00983 extern void sort_users(struct channel *ch)
00984 {
00985 int i;
00986 int nu;
00987 int done;
00988 struct comuser *user;
00989
00990 nu = ch->num_users;
00991 done = 0;
00992 while (!done) {
00993 done = 1;
00994 for(i = 0; i < (nu - 1); i++) {
00995 if(ch->users[i]->who > ch->users[i + 1]->who) {
00996 user = ch->users[i];
00997 ch->users[i] = ch->users[i + 1];
00998 ch->users[i + 1] = user;
00999 done = 0;
01000 }
01001 }
01002 }
01003 }
01004
01005 void do_channelwho(dbref player, dbref cause, int key, char *arg1)
01006 {
01007 struct channel *ch;
01008 struct comuser *user;
01009 char channel[100];
01010 int flag = 0;
01011 char *cp;
01012 int i;
01013 char ansibuffer[LBUF_SIZE];
01014 char outputbuffer[LBUF_SIZE];
01015
01016 if(!mudconf.have_comsys) {
01017 raw_notify(player, "Comsys disabled.");
01018 return;
01019 }
01020 cp = strchr(arg1, '/');
01021 if(!cp) {
01022 strncpy(channel, arg1, 100);
01023 channel[99] = '\0';
01024 } else {
01025
01026 if(cp - arg1 >= 100) {
01027 raw_notify(player, "Channel name too long.");
01028 return;
01029 }
01030 strncpy(channel, arg1, cp - arg1);
01031 channel[cp - arg1] = '\0';
01032 if(*++cp == 'a')
01033 flag = 1;
01034 }
01035
01036 if(!(ch = select_channel(channel))) {
01037 notify_printf(player, "Unknown channel \"%s\".", channel);
01038 return;
01039 }
01040 if(!((Comm_All(player)) || (player == ch->charge_who))) {
01041 raw_notify(player, "You do not have permission to do that.");
01042 return;
01043 }
01044 notify_printf(player, "-- %s --", ch->name);
01045 notify_printf(player, "%-29.29s %-6.6s %-6.6s", "Name", "Status",
01046 "Player");
01047 for(i = 0; i < ch->num_users; i++) {
01048 user = ch->users[i];
01049 if((flag || UNDEAD(user->who)) && (!Hidden(user->who) ||
01050 ((ch->type & CHANNEL_TRANSPARENT)
01051 && !Dark(user->who))
01052 || Wizard_Who(player))) {
01053 cp = unparse_object(player, user->who, 0);
01054 strip_ansi_r(ansibuffer, cp, LBUF_SIZE);
01055 notify_printf(player, "%-29.29s %-6.6s %-6.6s", ansibuffer,
01056 ((user->on) ? "on " : "off"),
01057 (Typeof(user->who) == TYPE_PLAYER) ? "yes" : "no ");
01058 free_lbuf(cp);
01059 }
01060 }
01061 notify_printf(player, "-- %s --", ch->name);
01062 }
01063
01064 void do_comdisconnectraw_notify(dbref player, char *chan)
01065 {
01066 struct channel *ch;
01067 struct comuser *cu;
01068
01069 if(!(ch = select_channel(chan)))
01070 return;
01071 if(!(cu = select_user(ch, player)))
01072 return;
01073
01074 if((ch->type & CHANNEL_LOUD) && (cu->on) && (!Dark(player))) {
01075 do_comprintf(ch, "[%s] %s has disconnected.", ch->name, Name(player));
01076 }
01077 }
01078
01079 void do_comconnectraw_notify(dbref player, char *chan)
01080 {
01081 struct channel *ch;
01082 struct comuser *cu;
01083
01084 if(!(ch = select_channel(chan)))
01085 return;
01086 if(!(cu = select_user(ch, player)))
01087 return;
01088
01089 if((ch->type & CHANNEL_LOUD) && (cu->on) && (!Dark(player))) {
01090 do_comprintf(ch, "[%s] %s has connected.", ch->name, Name(player));
01091 }
01092 }
01093
01094 void do_comconnectchannel(dbref player, char *channel, char *alias, int i)
01095 {
01096 struct channel *ch;
01097 struct comuser *user;
01098
01099 if((ch = select_channel(channel))) {
01100 for(user = ch->on_users; user && user->who != player;
01101 user = user->on_next);
01102
01103 if(!user) {
01104 if((user = select_user(ch, player))) {
01105 user->on_next = ch->on_users;
01106 ch->on_users = user;
01107 } else
01108 notify_printf(player, "Bad Comsys Alias: %s for Channel: %s",
01109 alias + i * 6, channel);
01110 }
01111 } else
01112 notify_printf(player, "Bad Comsys Alias: %s for Channel: %s",
01113 alias + i * 6, channel);
01114 }
01115
01116 void do_comdisconnect(dbref player)
01117 {
01118 int i;
01119 struct commac *c;
01120
01121 c = get_commac(player);
01122
01123 for(i = 0; i < c->numchannels; i++) {
01124 do_comdisconnectchannel(player, c->channels[i]);
01125 do_comdisconnectraw_notify(player, c->channels[i]);
01126 }
01127 send_channel("MUXConnections", "* %s has disconnected *", Name(player));
01128 }
01129
01130 void do_comconnect(dbref player, DESC * d)
01131 {
01132 struct commac *c;
01133 int i;
01134 char *lsite;
01135
01136 c = get_commac(player);
01137
01138 for(i = 0; i < c->numchannels; i++) {
01139 do_comconnectchannel(player, c->channels[i], c->alias, i);
01140 do_comconnectraw_notify(player, c->channels[i]);
01141 }
01142 lsite = d->addr;
01143 if(lsite && *lsite)
01144 send_channel("MUXConnections","* %s has connected from %s *", Name(player), lsite);
01145 else
01146 send_channel("MUXConnections","* %s has connected from somewhere *", Name(player));
01147 }
01148
01149 void do_comdisconnectchannel(dbref player, char *channel)
01150 {
01151 struct comuser *user, *prevuser = NULL;
01152 struct channel *ch;
01153
01154 if(!(ch = select_channel(channel)))
01155 return;
01156 for(user = ch->on_users; user;) {
01157 if(user->who == player) {
01158 if(prevuser)
01159 prevuser->on_next = user->on_next;
01160 else
01161 ch->on_users = user->on_next;
01162 return;
01163 } else {
01164 prevuser = user;
01165 user = user->on_next;
01166 }
01167 }
01168 }
01169
01170 void do_editchannel(dbref player, dbref cause, int flag, char *arg1,
01171 char *arg2)
01172 {
01173 char *s;
01174 struct channel *ch;
01175 int add_remove = 1;
01176
01177 if(!mudconf.have_comsys) {
01178 raw_notify(player, "Comsys disabled.");
01179 return;
01180 }
01181 if(!(ch = select_channel(arg1))) {
01182 notify_printf(player, "Unknown channel %s.", arg1);
01183 return;
01184 }
01185 if(!((Comm_All(player)) || (player == ch->charge_who))) {
01186 raw_notify(player, "Permission denied.");
01187 return;
01188 }
01189 s = arg2;
01190 if(*s == '!') {
01191 add_remove = 0;
01192 s++;
01193 }
01194 switch (flag) {
01195 case 0:
01196 if(lookup_player(player, arg2, 1) != NOTHING) {
01197 ch->charge_who = lookup_player(player, arg2, 1);
01198 raw_notify(player, "Set.");
01199 return;
01200 } else {
01201 raw_notify(player, "Invalid player.");
01202 return;
01203 }
01204 case 1:
01205 ch->charge = atoi(arg2);
01206 raw_notify(player, "Set.");
01207 return;
01208 case 3:
01209 if(strcasecmp(s, "join") == 0) {
01210 add_remove ? (ch->type |=
01211 (CHANNEL_PL_MULT * CHANNEL_JOIN)) : (ch->type &=
01212 ~
01213 (CHANNEL_PL_MULT
01214 *
01215 CHANNEL_JOIN));
01216 raw_notify(player,
01217 (add_remove) ? "@cpflags: Set." :
01218 "@cpflags: Cleared.");
01219 return;
01220 }
01221 if(strcasecmp(s, "receive") == 0) {
01222 add_remove ? (ch->type |=
01223 (CHANNEL_PL_MULT * CHANNEL_RECIEVE)) : (ch->type &=
01224 ~
01225 (CHANNEL_PL_MULT
01226 *
01227 CHANNEL_RECIEVE));
01228 raw_notify(player,
01229 (add_remove) ? "@cpflags: Set." :
01230 "@cpflags: Cleared.");
01231 return;
01232 }
01233 if(strcasecmp(s, "transmit") == 0) {
01234 add_remove ? (ch->type |=
01235 (CHANNEL_PL_MULT * CHANNEL_TRANSMIT)) : (ch->type &=
01236 ~
01237 (CHANNEL_PL_MULT
01238 *
01239 CHANNEL_TRANSMIT));
01240 raw_notify(player,
01241 (add_remove) ? "@cpflags: Set." :
01242 "@cpflags: Cleared.");
01243 return;
01244 }
01245 raw_notify(player, "@cpflags: Unknown Flag.");
01246 break;
01247 case 4:
01248 if(strcasecmp(s, "join") == 0) {
01249 add_remove ? (ch->type |=
01250 (CHANNEL_OBJ_MULT * CHANNEL_JOIN)) : (ch->type &=
01251 ~
01252 (CHANNEL_OBJ_MULT
01253 *
01254 CHANNEL_JOIN));
01255 raw_notify(player,
01256 (add_remove) ? "@coflags: Set." :
01257 "@coflags: Cleared.");
01258 return;
01259 }
01260 if(strcasecmp(s, "receive") == 0) {
01261 add_remove ? (ch->type |=
01262 (CHANNEL_OBJ_MULT * CHANNEL_RECIEVE)) : (ch->type &=
01263 ~
01264 (CHANNEL_OBJ_MULT
01265 *
01266 CHANNEL_RECIEVE));
01267 raw_notify(player,
01268 (add_remove) ? "@coflags: Set." :
01269 "@coflags: Cleared.");
01270 return;
01271 }
01272 if(strcasecmp(s, "transmit") == 0) {
01273 add_remove ? (ch->type |=
01274 (CHANNEL_OBJ_MULT *
01275 CHANNEL_TRANSMIT)) : (ch->type &=
01276 ~(CHANNEL_OBJ_MULT *
01277 CHANNEL_TRANSMIT));
01278 raw_notify(player,
01279 (add_remove) ? "@coflags: Set." :
01280 "@coflags: Cleared.");
01281 return;
01282 }
01283 raw_notify(player, "@coflags: Unknown Flag.");
01284 break;
01285 }
01286 return;
01287 }
01288
01289 static int do_test_access(dbref player, long access, struct channel *chan)
01290 {
01291 long flag_value = access;
01292
01293 if(Comm_All(player))
01294 return (1);
01295
01296
01297
01298
01299
01300
01301
01302
01303
01304
01305
01306
01307 if((flag_value & CHANNEL_JOIN) && !((chan->chan_obj == NOTHING) ||
01308 (chan->chan_obj == 0))) {
01309 if(could_doit(player, chan->chan_obj, A_LOCK))
01310 return (1);
01311 }
01312 if((flag_value & CHANNEL_TRANSMIT) && !((chan->chan_obj == NOTHING) ||
01313 (chan->chan_obj == 0))) {
01314 if(could_doit(player, chan->chan_obj, A_LUSE))
01315 return (1);
01316 }
01317 if((flag_value & CHANNEL_RECIEVE) && !((chan->chan_obj == NOTHING) ||
01318 (chan->chan_obj == 0))) {
01319 if(could_doit(player, chan->chan_obj, A_LENTER))
01320 return (1);
01321 }
01322 if(Typeof(player) == TYPE_PLAYER)
01323 flag_value *= CHANNEL_PL_MULT;
01324 else
01325 flag_value *= CHANNEL_OBJ_MULT;
01326 flag_value &= 0xFF;
01327
01328
01329
01330
01331 return (((long) chan->type & flag_value));
01332 }
01333
01334 int do_comsystem(dbref who, char *cmd)
01335 {
01336 char *t;
01337 char *ch;
01338 char *alias;
01339 char *s;
01340
01341 alias = alloc_lbuf("do_comsystem");
01342 s = alias;
01343 for(t = cmd; *t && *t != ' '; *s++ = *t++)
01344 ;
01345
01346 *s = '\0';
01347
01348 if(*t)
01349 t++;
01350
01351 ch = get_channel_from_alias(who, alias);
01352 if(ch && *ch) {
01353 do_processcom(who, ch, t);
01354 free_lbuf(alias);
01355 return 0;
01356 }
01357 free_lbuf(alias);
01358 return 1;
01359
01360 }
01361
01362 void do_chclose(dbref player, char *chan)
01363 {
01364 struct channel *ch;
01365
01366 if(!(ch = select_channel(chan))) {
01367 notify_printf(player, "@cset: Channel %s does not exist.", chan);
01368 return;
01369 }
01370 if((player != ch->charge_who) && (!Comm_All(player))) {
01371 raw_notify(player, "@cset: Permission denied.");
01372 return;
01373 }
01374 ch->type &= (~(CHANNEL_PUBLIC));
01375 notify_printf(player,
01376 "@cset: Channel %s taken off the public listings.", chan);
01377 return;
01378 }
01379
01380 void do_cemit(dbref player, dbref cause, int key, char *chan, char *text)
01381 {
01382 struct channel *ch;
01383
01384 if(!mudconf.have_comsys) {
01385 raw_notify(player, "Comsys disabled.");
01386 return;
01387 }
01388 if(!(ch = select_channel(chan))) {
01389 notify_printf(player, "Channel %s does not exist.", chan);
01390 return;
01391 }
01392 if((player != ch->charge_who) && (!Comm_All(player))) {
01393 raw_notify(player, "Permission denied.");
01394 return;
01395 }
01396 if(key == CEMIT_NOHEADER)
01397 do_comsend(ch, text);
01398 else
01399 do_comprintf(ch, "[%s] %s", chan, text);
01400 }
01401
01402 void do_chopen(dbref player, dbref cause, int key, char *chan, char *object)
01403 {
01404 struct channel *ch;
01405
01406 if(!mudconf.have_comsys) {
01407 raw_notify(player, "Comsys disabled.");
01408 return;
01409 }
01410 switch (key) {
01411 case CSET_PRIVATE:
01412 do_chclose(player, chan);
01413 return;
01414 case CSET_LOUD:
01415 do_chloud(player, chan);
01416 return;
01417 case CSET_QUIET:
01418 do_chsquelch(player, chan);
01419 return;
01420 case CSET_LIST:
01421 do_chanlist(player, NOTHING, 1);
01422 return;
01423 case CSET_OBJECT:
01424 do_chanobj(player, chan, object);
01425 return;
01426 case CSET_STATUS:
01427 do_chanstatus(player, NOTHING, 1, chan);
01428 return;
01429 case CSET_TRANSPARENT:
01430 do_chtransparent(player, chan);
01431 return;
01432 case CSET_OPAQUE:
01433 do_chopaque(player, chan);
01434 return;
01435 }
01436
01437 if(!(ch = select_channel(chan))) {
01438 notify_printf(player, "@cset: Channel %s does not exist.", chan);
01439 return;
01440 }
01441 if((player != ch->charge_who) && (!Comm_All(player))) {
01442 raw_notify(player, "@cset: Permission denied.");
01443 return;
01444 }
01445 ch->type |= (CHANNEL_PUBLIC);
01446 notify_printf(player, "@cset: Channel %s placed on the public listings.",
01447 chan);
01448 return;
01449 }
01450
01451 void do_chloud(dbref player, char *chan)
01452 {
01453 struct channel *ch;
01454
01455 if(!(ch = select_channel(chan))) {
01456 notify_printf(player, "@cset: Channel %s does not exist.", chan);
01457 return;
01458 }
01459 if((player != ch->charge_who) && (!Comm_All(player))) {
01460 raw_notify(player, "@cset: Permission denied.");
01461 return;
01462 }
01463 ch->type |= (CHANNEL_LOUD);
01464 notify_printf(player,
01465 "@cset: Channel %s now sends connect/disconnect msgs.",
01466 chan);
01467 return;
01468 }
01469
01470 void do_chsquelch(dbref player, char *chan)
01471 {
01472 struct channel *ch;
01473
01474 if(!(ch = select_channel(chan))) {
01475 notify_printf(player, "@cset: Channel %s does not exist.", chan);
01476 return;
01477 }
01478 if((player != ch->charge_who) && (!Comm_All(player))) {
01479 raw_notify(player, "@cset: Permission denied.");
01480 return;
01481 }
01482 ch->type &= ~(CHANNEL_LOUD);
01483 notify_printf(player,
01484 "@cset: Channel %s connect/disconnect msgs muted.", chan);
01485 return;
01486 }
01487
01488 void do_chtransparent(dbref player, char *chan)
01489 {
01490 struct channel *ch;
01491
01492 if(!(ch = select_channel(chan))) {
01493 notify_printf(player, "@cset: Channel %s does not exist.", chan);
01494 return;
01495 }
01496 if((player != ch->charge_who) && (!Comm_All(player))) {
01497 raw_notify(player, "@cset: Permission denied.");
01498 return;
01499 }
01500 ch->type |= CHANNEL_TRANSPARENT;
01501 notify_printf(player,
01502 "@cset: Channel %s now shows all listeners to everyone.",
01503 chan);
01504 return;
01505 }
01506
01507 void do_chopaque(dbref player, char *chan)
01508 {
01509 struct channel *ch;
01510
01511 if(!(ch = select_channel(chan))) {
01512 notify_printf(player, "@cset: Channel %s does not exist.", chan);
01513 return;
01514 }
01515 if((player != ch->charge_who) && (!Comm_All(player))) {
01516 raw_notify(player, "@cset: Permission denied.");
01517 return;
01518 }
01519 ch->type &= ~CHANNEL_TRANSPARENT;
01520 notify_printf(player,
01521 "@cset: Channel %s now does not show all listeners to everyone.",
01522 chan);
01523 return;
01524 }
01525
01526 void do_chboot(dbref player, dbref cause, int key, char *channel,
01527 char *victim)
01528 {
01529 struct comuser *user;
01530 struct channel *ch;
01531 struct comuser *vu;
01532 dbref thing;
01533
01534
01535
01536
01537
01538
01539 if(!mudconf.have_comsys) {
01540 raw_notify(player, "Comsys disabled.");
01541 return;
01542 }
01543 if(!(ch = select_channel(channel))) {
01544 raw_notify(player, "@cboot: Unknown channel.");
01545 return;
01546 }
01547 if(!(user = select_user(ch, player))) {
01548 raw_notify(player, "@cboot: You are not on that channel.");
01549 return;
01550 }
01551 if(!((ch->charge_who == player) || Comm_All(player))) {
01552 raw_notify(player, "Permission denied.");
01553 return;
01554 }
01555 thing = match_thing(player, victim);
01556
01557 if(thing == NOTHING) {
01558 return;
01559 }
01560 if(!(vu = select_user(ch, thing))) {
01561 notify_printf(player, "@cboot: %s in not on the channel.",
01562 Name(thing));
01563 return;
01564 }
01565
01566
01567
01568 do_comprintf(ch, "[%s] %s boots %s off the channel.", ch->name,
01569 unparse_object_numonly(player), unparse_object_numonly(thing));
01570 do_delcomchannel(thing, channel);
01571
01572 }
01573
01574 void do_chanobj(dbref player, char *channel, char *object)
01575 {
01576 struct channel *ch;
01577 dbref thing;
01578 char *buff;
01579
01580 init_match(player, object, NOTYPE);
01581 match_everything(0);
01582 thing = match_result();
01583
01584 if(!(ch = select_channel(channel))) {
01585 raw_notify(player, "That channel does not exist.");
01586 return;
01587 }
01588 if(thing == NOTHING) {
01589 ch->chan_obj = NOTHING;
01590 raw_notify(player, "Set.");
01591 return;
01592 }
01593 if(!(ch->charge_who == player) && !Comm_All(player)) {
01594 raw_notify(player, "Permission denied.");
01595 return;
01596 }
01597 ch->chan_obj = thing;
01598 buff = unparse_object(player, thing, 0);
01599 notify_printf(player,
01600 "Channel %s is now using %s as channel object.", ch->name,
01601 buff);
01602 free_lbuf(buff);
01603 }
01604
01605 void do_chanlist(dbref player, dbref cause, int key)
01606 {
01607 dbref owner;
01608 struct channel *ch;
01609 int flags;
01610 char *temp;
01611 char *buf;
01612 char *atrstr;
01613
01614 if(!mudconf.have_comsys) {
01615 raw_notify(player, "Comsys disabled.");
01616 return;
01617 }
01618 flags = (int) NULL;
01619
01620 if(key & CLIST_FULL) {
01621 do_listchannels(player);
01622 return;
01623 }
01624 temp = alloc_mbuf("do_chanlist_temp");
01625 buf = alloc_mbuf("do_chanlist_buf");
01626
01627 raw_notify(player, "** Channel Owner Description");
01628
01629 for(ch = (struct channel *) hash_firstentry(&mudstate.channel_htab);
01630 ch; ch = (struct channel *) hash_nextentry(&mudstate.channel_htab)) {
01631 if(Comm_All(player) || (ch->type & CHANNEL_PUBLIC) ||
01632 ch->charge_who == player || (do_test_access(player, CHANNEL_JOIN, ch))) {
01633
01634 atrstr = atr_pget(ch->chan_obj, A_DESC, &owner, &flags);
01635 if((ch->chan_obj == NOTHING) || !*atrstr)
01636 sprintf(buf, "%s", "No description.");
01637 else
01638 sprintf(buf, "%-54.54s", atrstr);
01639
01640 free_lbuf(atrstr);
01641 sprintf(temp, "%c%c %-13.13s %-15.15s %-45.45s",
01642 (ch->type & (CHANNEL_PUBLIC)) ? 'P' : '-',
01643 (ch->type & (CHANNEL_LOUD)) ? 'L' : '-', ch->name,
01644 Name(ch->charge_who), buf);
01645
01646 raw_notify(player, temp);
01647 }
01648 }
01649 free_mbuf(temp);
01650 free_mbuf(buf);
01651 raw_notify(player, "-- End of list of Channels --");
01652 }
01653
01654 void do_chanstatus(dbref player, dbref cause, int key, char *chan)
01655 {
01656 dbref owner;
01657 struct channel *ch;
01658 int flags;
01659 char *temp;
01660 char *buf;
01661 char *atrstr;
01662
01663 if(!mudconf.have_comsys) {
01664 raw_notify(player, "Comsys disabled.");
01665 return;
01666 }
01667
01668 if(key & CSTATUS_FULL) {
01669 struct channel *ch;
01670 int perm;
01671
01672 if(!(perm = Comm_All(player))) {
01673 raw_notify(player,
01674 "Warning: Only public channels and your channels will be shown.");
01675 }
01676 raw_notify(player,
01677 "** Channel --Flags-- Obj Own Charge Balance Users Messages");
01678
01679 if(!(ch = select_channel(chan))) {
01680 notify_printf(player,
01681 "@cstatus: Channel %s does not exist.", chan);
01682 return;
01683 }
01684 if(perm || (ch->type & CHANNEL_PUBLIC) || ch->charge_who == player) {
01685
01686 notify_printf(player,
01687 "%c%c %-20.20s %c%c%c/%c%c%c %5d %5d %8d %8d %6d %10d",
01688 (ch->type & (CHANNEL_PUBLIC)) ? 'P' : '-',
01689 (ch->type & (CHANNEL_LOUD)) ? 'L' : '-', ch->name,
01690 (ch->
01691 type & (CHANNEL_PL_MULT *
01692 CHANNEL_JOIN)) ? 'J' : '-',
01693 (ch->
01694 type & (CHANNEL_PL_MULT *
01695 CHANNEL_TRANSMIT)) ? 'X' : '-',
01696 (ch->
01697 type & (CHANNEL_PL_MULT *
01698 CHANNEL_RECIEVE)) ? 'R' : '-',
01699 (ch->
01700 type & (CHANNEL_OBJ_MULT *
01701 CHANNEL_JOIN)) ? 'j' : '-',
01702 (ch->
01703 type & (CHANNEL_OBJ_MULT *
01704 CHANNEL_TRANSMIT)) ? 'x' : '-',
01705 (ch->
01706 type & (CHANNEL_OBJ_MULT *
01707 CHANNEL_RECIEVE)) ? 'r' : '-',
01708 (ch->chan_obj != NOTHING) ? ch->chan_obj : -1,
01709 ch->charge_who, ch->charge, ch->amount_col,
01710 ch->num_users, ch->num_messages);
01711 }
01712 raw_notify(player, "-- End of list of Channels --");
01713 return;
01714 }
01715 temp = alloc_mbuf("do_chanstatus_temp");
01716 buf = alloc_mbuf("do_chanstatus_buf");
01717
01718 raw_notify(player, "** Channel Owner Description");
01719 if(!(ch = select_channel(chan))) {
01720 notify_printf(player, "@cstatus: Channel %s does not exist.", chan);
01721 return;
01722 }
01723 if(Comm_All(player) || (ch->type & CHANNEL_PUBLIC) ||
01724 ch->charge_who == player) {
01725
01726 atrstr = atr_pget(ch->chan_obj, A_DESC, &owner, &flags);
01727 if((ch->chan_obj == NOTHING) || !*atrstr)
01728 sprintf(buf, "%s", "No description.");
01729 else
01730 sprintf(buf, "%-54.54s", atrstr);
01731
01732 free_lbuf(atrstr);
01733 snprintf(temp, MBUF_SIZE, "%c%c %-13.13s %-15.15s %-45.45s",
01734 (ch->type & (CHANNEL_PUBLIC)) ? 'P' : '-',
01735 (ch->type & (CHANNEL_LOUD)) ? 'L' : '-', ch->name,
01736 Name(ch->charge_who), buf);
01737
01738 raw_notify(player, temp);
01739 }
01740 free_mbuf(temp);
01741 free_mbuf(buf);
01742 raw_notify(player, "-- End of list of Channels --");
01743 }
01744
01745 void fun_cemit(char *buff, char **bufc, dbref player, dbref cause,
01746 char *fargs[], char *nfargs[], int cargs, int ncargs)
01747 {
01748 struct channel *ch;
01749 static char smbuf[LBUF_SIZE];
01750
01751 if(!(ch = select_channel(fargs[0]))) {
01752 safe_str("#-1 CHANNEL NOT FOUND", buff, bufc);
01753 return;
01754 }
01755
01756 if(!mudconf.have_comsys
01757 || (!Comm_All(player) && (player != ch->charge_who))) {
01758 safe_str("#-1 NO PERMISSION TO USE", buff, bufc);
01759 return;
01760 }
01761
01762 do_comprintf(ch, "[%s] %s", fargs[0], fargs[1]);
01763 *buff = '\0';
01764 }