comparison mcabber/src/commands.c @ 447:03bb57383cea

Initial Multi-User Chat support This patch adds basic MUC support. We now can: - join an existing room; - create and unlock a room using the /rawxml command; - set our nickname; - send/receive chatgroup messages; - see the members of the room; - leave the room. Chatroom logging is currently disabled, as it could do some unexpected things.
author Mikael Berthe <mikael@lilotux.net>
date Sun, 25 Sep 2005 01:01:44 +0200
parents 9f4e9e9aaf08
children 39a28cb59af3
comparison
equal deleted inserted replaced
446:9f4e9e9aaf08 447:03bb57383cea
49 static void do_alias(char *arg); 49 static void do_alias(char *arg);
50 static void do_bind(char *arg); 50 static void do_bind(char *arg);
51 static void do_connect(char *arg); 51 static void do_connect(char *arg);
52 static void do_disconnect(char *arg); 52 static void do_disconnect(char *arg);
53 static void do_rawxml(char *arg); 53 static void do_rawxml(char *arg);
54 static void do_room(char *arg);
54 55
55 // Global variable for the commands list 56 // Global variable for the commands list
56 static GSList *Commands; 57 static GSList *Commands;
57 58
58 59
90 cmd_add("info", "Show basic infos on current buddy", 0, 0, &do_info); 91 cmd_add("info", "Show basic infos on current buddy", 0, 0, &do_info);
91 cmd_add("move", "Move the current buddy to another group", COMPL_GROUPNAME, 92 cmd_add("move", "Move the current buddy to another group", COMPL_GROUPNAME,
92 0, &do_move); 93 0, &do_move);
93 cmd_add("msay", "Send a multi-lines message to the selected buddy", 94 cmd_add("msay", "Send a multi-lines message to the selected buddy",
94 COMPL_MULTILINE, 0, &do_msay); 95 COMPL_MULTILINE, 0, &do_msay);
95 //cmd_add("nick"); 96 cmd_add("room", "MUC actions command", COMPL_ROOM, 0, &do_room);
96 cmd_add("quit", "Exit the software", 0, 0, NULL); 97 cmd_add("quit", "Exit the software", 0, 0, NULL);
97 cmd_add("rawxml", "Send a raw XML string", 0, 0, &do_rawxml); 98 cmd_add("rawxml", "Send a raw XML string", 0, 0, &do_rawxml);
98 cmd_add("rename", "Rename the current buddy", 0, 0, &do_rename); 99 cmd_add("rename", "Rename the current buddy", 0, 0, &do_rename);
99 //cmd_add("request_auth"); 100 //cmd_add("request_auth");
100 cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0, 101 cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0,
144 // Multi-line (msay) category 145 // Multi-line (msay) category
145 compl_add_category_word(COMPL_MULTILINE, "abort"); 146 compl_add_category_word(COMPL_MULTILINE, "abort");
146 compl_add_category_word(COMPL_MULTILINE, "begin"); 147 compl_add_category_word(COMPL_MULTILINE, "begin");
147 compl_add_category_word(COMPL_MULTILINE, "send"); 148 compl_add_category_word(COMPL_MULTILINE, "send");
148 compl_add_category_word(COMPL_MULTILINE, "verbatim"); 149 compl_add_category_word(COMPL_MULTILINE, "verbatim");
150
151 // Room category
152 compl_add_category_word(COMPL_ROOM, "join");
153 compl_add_category_word(COMPL_ROOM, "leave");
154 compl_add_category_word(COMPL_ROOM, "names");
149 } 155 }
150 156
151 // expandalias(line) 157 // expandalias(line)
152 // If there is one, expand the alias in line and returns a new allocated line 158 // If there is one, expand the alias in line and returns a new allocated line
153 // If no alias is found, returns line 159 // If no alias is found, returns line
229 if (!jid) { 235 if (!jid) {
230 scr_LogPrint(LPRINT_NORMAL, "No buddy currently selected."); 236 scr_LogPrint(LPRINT_NORMAL, "No buddy currently selected.");
231 return; 237 return;
232 } 238 }
233 239
234 // local part (UI, logging, etc.) 240 if (buddy_gettype(BUDDATA(current_buddy)) != ROSTER_TYPE_ROOM) {
235 hk_message_out(jid, 0, msg); 241 // local part (UI, logging, etc.)
242 hk_message_out(jid, 0, msg);
243 }
236 244
237 // Network part 245 // Network part
238 jb_send_msg(jid, msg); 246 jb_send_msg(jid, msg, buddy_gettype(BUDDATA(current_buddy)));
239 } 247 }
240 248
241 // process_command(line) 249 // process_command(line)
242 // Process a command line. 250 // Process a command line.
243 // Return 255 if this is the /quit command, and 0 for the other commands. 251 // Return 255 if this is the /quit command, and 0 for the other commands.
545 scr_LogPrint(LPRINT_NORMAL, "Who are you talking to??"); 553 scr_LogPrint(LPRINT_NORMAL, "Who are you talking to??");
546 return; 554 return;
547 } 555 }
548 556
549 bud = BUDDATA(current_buddy); 557 bud = BUDDATA(current_buddy);
550 if (!(buddy_gettype(bud) & ROSTER_TYPE_USER)) { 558 if (!(buddy_gettype(bud) & (ROSTER_TYPE_USER|ROSTER_TYPE_ROOM))) {
551 scr_LogPrint(LPRINT_NORMAL, "This is not a user"); 559 scr_LogPrint(LPRINT_NORMAL, "This is not a user");
552 return; 560 return;
553 } 561 }
554 562
555 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); 563 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE);
601 scr_LogPrint(LPRINT_NORMAL, "Who are you talking to??"); 609 scr_LogPrint(LPRINT_NORMAL, "Who are you talking to??");
602 return; 610 return;
603 } 611 }
604 612
605 bud = BUDDATA(current_buddy); 613 bud = BUDDATA(current_buddy);
606 if (!(buddy_gettype(bud) & ROSTER_TYPE_USER)) { 614 if (!(buddy_gettype(bud) & (ROSTER_TYPE_USER|ROSTER_TYPE_ROOM))) {
607 scr_LogPrint(LPRINT_NORMAL, "This is not a user"); 615 scr_LogPrint(LPRINT_NORMAL, "This is not a user");
608 return; 616 return;
609 } 617 }
610 618
611 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); 619 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE);
681 snprintf(buffer, 127, "Name: %s", name); 689 snprintf(buffer, 127, "Name: %s", name);
682 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); 690 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
683 } 691 }
684 692
685 if (type == ROSTER_TYPE_USER) typestr = "user"; 693 if (type == ROSTER_TYPE_USER) typestr = "user";
694 else if (type == ROSTER_TYPE_ROOM) typestr = "chatroom";
686 else if (type == ROSTER_TYPE_AGENT) typestr = "agent"; 695 else if (type == ROSTER_TYPE_AGENT) typestr = "agent";
687 snprintf(buffer, 127, "Type: %s", typestr); 696 snprintf(buffer, 127, "Type: %s", typestr);
688 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); 697 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
689 698
690 resources = buddy_getresources(bud); 699 resources = buddy_getresources(bud);
890 scr_LogPrint(LPRINT_NORMAL, "Please read the manual page" 899 scr_LogPrint(LPRINT_NORMAL, "Please read the manual page"
891 " before using /rawxml :-)"); 900 " before using /rawxml :-)");
892 } 901 }
893 } 902 }
894 903
904 static void do_room(char *arg)
905 {
906 gpointer bud;
907
908 if (!arg || (!*arg)) {
909 scr_LogPrint(LPRINT_NORMAL, "Missing parameter");
910 return;
911 }
912
913 bud = BUDDATA(current_buddy);
914
915 if (!strncasecmp(arg, "join", 4)) {
916 GSList *roster_usr;
917 char *roomname, *nick, *roomid;
918
919 arg += 4;
920 if (*arg++ != ' ') {
921 scr_LogPrint(LPRINT_NORMAL, "Wrong or missing parameter");
922 return;
923 }
924 for (; *arg && *arg == ' '; arg++)
925 ;
926
927 roomname = g_strdup(arg);
928 nick = strchr(roomname, ' ');
929 if (!nick) {
930 scr_LogPrint(LPRINT_NORMAL, "Missing parameter (nickname)");
931 g_free(roomname);
932 return;
933 }
934
935 *nick++ = 0;
936 while (*nick && *nick == ' ')
937 nick++;
938 if (!*nick) {
939 scr_LogPrint(LPRINT_NORMAL, "Missing parameter (nickname)");
940 g_free(roomname);
941 return;
942 }
943 // room syntax: "room@server/nick"
944 // FIXME: check roomid is a jid
945 roomid = g_strdup_printf("%s/%s", roomname, nick);
946 jb_room_join(roomid);
947 roster_usr = roster_add_user(roomname, NULL, NULL, ROSTER_TYPE_ROOM);
948 if (roster_usr)
949 buddy_setnickname(roster_usr->data, nick);
950 g_free(roomname);
951 g_free(roomid);
952 buddylist_build();
953 update_roster = TRUE;
954 } else if (!strncasecmp(arg, "leave", 5)) {
955 char *roomid;
956 arg += 5;
957 for (; *arg && *arg == ' '; arg++)
958 ;
959 if (!(buddy_gettype(bud) & ROSTER_TYPE_ROOM)) {
960 scr_LogPrint(LPRINT_NORMAL, "This isn't a chatroom");
961 return;
962 }
963 roomid = g_strdup_printf("%s/%s", buddy_getjid(bud),
964 buddy_getnickname(bud));
965 jb_setstatus(offline, roomid, arg);
966 g_free(roomid);
967 buddy_setnickname(bud, NULL);
968 buddy_del_all_resources(bud);
969 scr_LogPrint(LPRINT_NORMAL, "You have left %s", buddy_getjid(bud));
970 } else if (!strcasecmp(arg, "names")) {
971 if (!(buddy_gettype(bud) & ROSTER_TYPE_ROOM)) {
972 scr_LogPrint(LPRINT_NORMAL, "This isn't a chatroom");
973 return;
974 }
975 do_info(NULL);
976 } else {
977 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
978 }
979 }
980
895 static void do_connect(char *arg) 981 static void do_connect(char *arg)
896 { 982 {
897 mcabber_connect(); 983 mcabber_connect();
898 } 984 }
899 985