Changeset 4284008 in code
- 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)
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
cmd.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 … … 113 113 /* to boot or not to boot, that is the question */ 114 114 ig = is->group; 115 if (!icb_ismod er(ig, is)) {115 if (!icb_ismod(ig, is)) { 116 116 icb_status(is, STATUS_NOTIFY, "Sorry, booting is a privilege " 117 117 "you don't possess"); … … 180 180 if (is->group) { 181 181 changing = 1; 182 if (icb_ismod er(is->group, is))182 if (icb_ismod(is->group, is)) 183 183 (void)icb_pass(is->group, is, NULL); 184 184 LIST_REMOVE(is, entry); … … 196 196 /* acknowledge successful join */ 197 197 icb_status(is, STATUS_STATUS, "You are now in group %s%s", ig->name, 198 icb_ismod er(ig, is) ? " as moderator" : "");198 icb_ismod(ig, is) ? " as moderator" : ""); 199 199 200 200 /* send user a topic name */ … … 285 285 struct icb_session *s; 286 286 287 if (!ig->mod er) /* if there is no mod, let anyone grab it */288 (void)icb_pass(ig, ig->mod er, is);289 else if (icb_ismod er(ig, is)) {287 if (!ig->mod) /* if there is no mod, let anyone grab it */ 288 (void)icb_pass(ig, ig->mod, is); 289 else if (icb_ismod(ig, is)) { 290 290 LIST_FOREACH(s, &ig->sess, entry) { 291 291 if (strcmp(s->nick, arg) == 0) … … 296 296 return; 297 297 } 298 (void)icb_pass(ig, ig->mod er, s);298 (void)icb_pass(ig, ig->mod, s); 299 299 } 300 300 } … … 312 312 icb_status(is, STATUS_TOPIC, "The topic is not set."); 313 313 } else { /* setting the topic */ 314 if (!icb_ismod er(ig, is)) {314 if (!icb_ismod(ig, is)) { 315 315 icb_status(is, STATUS_NOTIFY, "Setting the topic is " 316 316 "only for moderators."); … … 324 324 325 325 void 326 icb_cmd_who(struct icb_session *is, char *arg __attribute__((unused))) 327 { 328 icb_who(is, NULL); 329 } 326 icb_cmd_who(struct icb_session *is, char *arg) 327 { 328 struct icb_group *ig; 329 330 if (strlen(arg) == 0) 331 return icb_who(is, NULL); 332 333 LIST_FOREACH(ig, &groups, entry) { 334 if (strcmp(ig->name, arg) == 0) 335 break; 336 } 337 if (ig == NULL) { 338 icb_error(is, "The group %s doesn't exist.", arg); 339 return; 340 } 341 icb_who(is, ig); 342 } -
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 * -
icb.h
r9195a6a r4284008 50 50 CMDOUT_CO, 51 51 CMDOUT_EC, 52 CMDOUT_WG, 53 CMDOUT_WH, 52 54 CMDOUT_WL, 53 CMDOUT_WG,54 55 }; 55 56 #define ICB_M_PROTO 'j' … … 93 94 LIST_ENTRY(icb_group) entry; 94 95 LIST_HEAD(, icb_session) sess; 95 struct icb_session *mod er;96 struct icb_session *mod; 96 97 }; 97 98 … … 118 119 void icb_init(struct icbd_callbacks *); 119 120 void icb_input(struct icb_session *); 120 int icb_ismod er(struct icb_group *, struct icb_session *);121 int icb_ismod(struct icb_group *, struct icb_session *); 121 122 int icb_pass(struct icb_group *, struct icb_session *, struct icb_session *); 122 123 void icb_privmsg(struct icb_session *, char *, char *);
Note:
See TracChangeset
for help on using the changeset viewer.