# HG changeset patch # User Mikael Berthe # Date 1134236091 -3600 # Node ID 7eff2c1481fa921eca1fd95b9ddbd7e89ceb43ff # Parent 414fbf558f1e54b9465c1342a6ec33a75c1586c0 Add "/room affil" and "/room role" diff -r 414fbf558f1e -r 7eff2c1481fa mcabber/src/commands.c --- a/mcabber/src/commands.c Fri Dec 09 19:49:58 2005 +0100 +++ b/mcabber/src/commands.c Sat Dec 10 18:34:51 2005 +0100 @@ -156,6 +156,7 @@ compl_add_category_word(COMPL_MULTILINE, "verbatim"); // Room category + compl_add_category_word(COMPL_ROOM, "affil"); compl_add_category_word(COMPL_ROOM, "ban"); compl_add_category_word(COMPL_ROOM, "invite"); compl_add_category_word(COMPL_ROOM, "join"); @@ -165,6 +166,7 @@ compl_add_category_word(COMPL_ROOM, "nick"); compl_add_category_word(COMPL_ROOM, "privmsg"); compl_add_category_word(COMPL_ROOM, "remove"); + compl_add_category_word(COMPL_ROOM, "role"); compl_add_category_word(COMPL_ROOM, "topic"); compl_add_category_word(COMPL_ROOM, "unlock"); compl_add_category_word(COMPL_ROOM, "whois"); @@ -1246,6 +1248,71 @@ free_arg_lst(paramlst); } +static void room_affil(gpointer bud, char *arg) +{ + char **paramlst; + gchar *jid, *rolename; + struct role_affil ra; + const char *roomid = buddy_getjid(bud); + + paramlst = split_arg(arg, 3, 1); // jid, new_affil, [reason] + jid = *paramlst; + rolename = *(paramlst+1); + arg = *(paramlst+2); + + if (!jid || !*jid || !rolename || !*rolename) { + scr_LogPrint(LPRINT_NORMAL, "Missing parameter"); + free_arg_lst(paramlst); + return; + } + + ra.type = type_affil; + ra.val.affil = affil_none; + for (; ra.val.affil < imaffiliation_size; ra.val.affil++) + if (!strcasecmp(rolename, straffil[ra.val.affil])) + break; + + if (ra.val.affil < imaffiliation_size) + jb_room_setattrib(roomid, jid, NULL, ra, arg); + else + scr_LogPrint(LPRINT_NORMAL, "Wrong affiliation parameter"); + + free_arg_lst(paramlst); +} + +static void room_role(gpointer bud, char *arg) +{ + char **paramlst; + gchar *jid, *rolename; + struct role_affil ra; + const char *roomid = buddy_getjid(bud); + + paramlst = split_arg(arg, 3, 1); // jid, new_role, [reason] + jid = *paramlst; + rolename = *(paramlst+1); + arg = *(paramlst+2); + + if (!jid || !*jid || !rolename || !*rolename) { + scr_LogPrint(LPRINT_NORMAL, "Missing parameter"); + free_arg_lst(paramlst); + return; + } + + ra.type = type_role; + ra.val.role = role_none; + for (; ra.val.role < imrole_size; ra.val.role++) + if (!strcasecmp(rolename, strrole[ra.val.role])) + break; + + if (ra.val.role < imrole_size) + jb_room_setattrib(roomid, jid, NULL, ra, arg); + else + scr_LogPrint(LPRINT_NORMAL, "Wrong role parameter"); + + free_arg_lst(paramlst); +} + + // The expected argument is a Jabber id static void room_ban(gpointer bud, char *arg) { @@ -1493,6 +1560,12 @@ } else if (!strcasecmp(subcmd, "invite")) { if ((arg = check_room_subcommand(arg, TRUE, bud)) != NULL) room_invite(bud, arg); + } else if (!strcasecmp(subcmd, "affil")) { + if ((arg = check_room_subcommand(arg, TRUE, bud)) != NULL) + room_affil(bud, arg); + } else if (!strcasecmp(subcmd, "role")) { + if ((arg = check_room_subcommand(arg, TRUE, bud)) != NULL) + room_role(bud, arg); } else if (!strcasecmp(subcmd, "ban")) { if ((arg = check_room_subcommand(arg, TRUE, bud)) != NULL) room_ban(bud, arg); diff -r 414fbf558f1e -r 7eff2c1481fa mcabber/src/roster.h --- a/mcabber/src/roster.h Fri Dec 09 19:49:58 2005 +0100 +++ b/mcabber/src/roster.h Sat Dec 10 18:34:51 2005 +0100 @@ -18,7 +18,8 @@ role_none, role_moderator, role_participant, - role_visitor + role_visitor, + imrole_size }; extern char *strrole[]; // Should match enum above @@ -28,7 +29,8 @@ affil_owner, affil_admin, affil_member, - affil_outcast + affil_outcast, + imaffiliation_size }; extern char *straffil[]; // Should match enum above