- Timestamp:
- Mar 2, 2014, 1:50:39 AM (11 years ago)
- Branches:
- master
- Children:
- 2e37e9f
- Parents:
- 9195a6a
- git-author:
- Mike Belopuhov <mike@…> (03/02/14 01:45:33)
- git-committer:
- Mike Belopuhov <mike@…> (03/02/14 01:50:39)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
icb.c
r9195a6a r4284008 1 1 /* 2 * Copyright (c) 2009, 2010 Mike Belopuhov2 * Copyright (c) 2009, 2010, 2013 Mike Belopuhov 3 3 * 4 4 * Permission to use, copy, modify, and distribute this software for any … … 34 34 void icb_groupmsg(struct icb_session *, char *); 35 35 void icb_login(struct icb_session *, char *, char *, char *); 36 int icb_dowho(struct icb_session *, struct icb_group *); 36 37 char *icb_nextfield(char **); 37 38 … … 199 200 /* notify user */ 200 201 icb_status(is, STATUS_STATUS, "You are now in group %s%s", ig->name, 201 icb_ismod er(ig, is) ? " as moderator" : "");202 icb_ismod(ig, is) ? " as moderator" : ""); 202 203 203 204 /* send user a topic name */ … … 285 286 otype = "ec"; 286 287 break; 288 case CMDOUT_WG: 289 otype = "wg"; 290 break; 291 case CMDOUT_WH: 292 otype = "wh"; 293 break; 287 294 case CMDOUT_WL: 288 295 otype = "wl"; 289 296 break; 290 case CMDOUT_WG:291 otype = "wg";292 break;293 297 default: 294 298 icb_log(is, LOG_ERR, "unknown cmdout type"); 295 299 return; 296 300 } 297 icb_sendfmt(is, "%c%s%c%s", ICB_M_CMDOUT, otype, ICB_M_SEP, outmsg); 301 if (outmsg) 302 icb_sendfmt(is, "%c%s%c%s", ICB_M_CMDOUT, otype, ICB_M_SEP, 303 outmsg); 304 else 305 icb_sendfmt(is, "%c%s", ICB_M_CMDOUT, otype); 298 306 } 299 307 … … 386 394 { 387 395 if (is->group) { 388 if (icb_ismod er(is->group, is))396 if (icb_ismod(is->group, is)) 389 397 (void)icb_pass(is->group, is, NULL); 390 398 LIST_REMOVE(is, entry); … … 414 422 strlcpy(ig->mpass, mpass, sizeof ig->mpass); 415 423 if (is) 416 ig->mod er= is;424 ig->mod = is; 417 425 LIST_INIT(&ig->sess); 418 426 LIST_INSERT_HEAD(&groups, ig, entry); … … 441 449 442 450 /* 443 * icb_ who: sends a list of users of the specified group (or the current444 * one otherwise)in the "wl" format445 */ 446 void 447 icb_ who(struct icb_session *is, struct icb_group *ig)451 * icb_dowho: a helper function that sends out a group header as a command 452 * output and user information in the "wl" format 453 */ 454 int 455 icb_dowho(struct icb_session *is, struct icb_group *ig) 448 456 { 449 457 char buf[ICB_MSGSIZE]; 450 458 struct icb_session *s; 451 452 if (!ig) 453 ig = is->group; 459 int nusers = 0; 460 461 icb_cmdout(is, CMDOUT_CO, " "); 462 snprintf(buf, sizeof buf, "Group: %-8s (%cvl) Mod: %-13s Topic: %s", 463 ig->name, ig->mod ? 'm' : 'p', ig->mod ? ig->mod->nick : "(None)", 464 strlen(ig->topic) > 0 ? ig->topic : "(None)"); 465 icb_cmdout(is, CMDOUT_CO, buf); 454 466 LIST_FOREACH(s, &ig->sess, entry) { 455 467 (void)snprintf(buf, sizeof buf, 456 468 "%c%c%s%c%lld%c0%c%lld%c%s%c%s%c%s", 457 icb_ismod er(ig, s) ? '*' : ' ', ICB_M_SEP,469 icb_ismod(ig, s) ? 'm' : ' ', ICB_M_SEP, 458 470 s->nick, ICB_M_SEP, getmonotime() - s->last, 459 471 ICB_M_SEP, ICB_M_SEP, s->login, ICB_M_SEP, 460 472 s->client, ICB_M_SEP, s->host, ICB_M_SEP, " "); 461 473 icb_cmdout(is, CMDOUT_WL, buf); 462 } 463 } 464 465 /* 466 * icb_ismoder: checks whether group is moderated by "is" 474 nusers++; 475 } 476 return (nusers); 477 } 478 479 /* 480 * icb_who: sends a list of users of either the specified group or all 481 * groups found on the server 482 */ 483 void 484 icb_who(struct icb_session *is, struct icb_group *ig) 485 { 486 char buf[ICB_MSGSIZE]; 487 struct icb_group *g; 488 489 if (!ig) { 490 int nusers = 0, ngroups = 0; 491 492 LIST_FOREACH(g, &groups, entry) { 493 nusers += icb_dowho(is, g); 494 ngroups++; 495 } 496 if (nusers > 0) { 497 (void)snprintf(buf, sizeof buf, 498 "Total: %d %s in %d %s", 499 nusers, nusers > 1 ? "users" : "user", 500 ngroups, ngroups > 1 ? "groups" : "group"); 501 } else 502 (void)snprintf(buf, sizeof buf, "No users found."); 503 icb_cmdout(is, CMDOUT_CO, buf); 504 } else 505 (void)icb_dowho(is, ig); 506 } 507 508 /* 509 * icb_ismod: checks whether group is moderated by "is" 467 510 */ 468 511 int 469 icb_ismod er(struct icb_group *ig, struct icb_session *is)470 { 471 if (ig->mod er && ig->moder== is)512 icb_ismod(struct icb_group *ig, struct icb_session *is) 513 { 514 if (ig->mod && ig->mod == is) 472 515 return (1); 473 516 return (0); … … 484 527 struct icb_session *to) 485 528 { 486 if (ig->mod er && ig->moder!= from)529 if (ig->mod && ig->mod != from) 487 530 return (-1); 488 531 if (!from && !to) 489 532 return (-1); 490 ig->mod er= to;533 ig->mod = to; 491 534 if (to) 492 535 icb_status(to, STATUS_NOTIFY, "%s just passed you moderation" … … 498 541 499 542 /* 500 * icb_nextfield: advances through a given buffer returning pointer to 501 * thebeginning of the icb field or an empty string otherwise543 * icb_nextfield: advances through a given buffer returning pointer to the 544 * beginning of the icb field or an empty string otherwise 502 545 */ 503 546 char *
Note:
See TracChangeset
for help on using the changeset viewer.