static void cmd_join_room(struct xmpp *xmpp, struct contact *u, char *s) { char *p, *part, *res; char to[JID_BUF]; int npart, nres; p = strchr(s + 3, ' '); if (p) *p = 0; part = jid_partial(s + 3, &npart); res = jid_resource(s + 3, &nres); if (!(part && res)) return; u = add_contact(npart, part); u->type = "groupchat"; snprintf(to, sizeof(to), "%.*s/%.*s", npart, part, nres, res); join_room(xmpp, to); }
static void User_command() { char command[130]; char mtext[80]; char mess[MAX_MESSLEN]; char group[80]; char groups[10][MAX_GROUP_NAME]; int num_groups; unsigned int mess_len; int ret; int i; int like; sp_time test_timeout; char server_id[1]; for( i=0; i < sizeof(command); i++ ) command[i] = 0; if( fgets( command, 130, stdin ) == NULL ) Bye(); /* remove newline from string */ command[strlen(command) -1] = 0; switch( command[0] ) { case 'j': ret = sscanf( &command[2], "%s", group ); if (connected > 0) { if( ret < 1 ) { printf(" invalid chatroom \n> "); break; } join_room(group); } else {printf("You must connect to a server first\n>"); } break; case 'c': ret = sscanf( &command[2], "%s", group ); if( ret < 1 ) { printf(" invalid server id \n> "); break; } join_server(group); break; case 'q': Bye(); exit(0); break; case '?': show_menu(); break; case 'u': if (connected > 0 ) { ret = sscanf( &command[2], "%s", username); if( ret < 1 ) { printf(" Invalid Username\n> "); break; } else { printf("Username set to %s\n> ", username); /*If in chatroom, disconnect */ if (strlen(chatroom) > 0) { sprintf(chatroom, "%s%d",chatroom, connected); printf("leaving chatroom, %s due to username change\n", chatroom); SP_leave(Mbox, chatroom); } } } else {printf("You must connect to a server first\n>"); } break; case 'a': if (connected > 0) { strncpy(mtext, &command[2], 130); if( strlen(mtext) < 1) { printf(" invalid message\n> "); break; } send_msg(mtext); } else {printf("You must connect to a server first\n>"); } break; case 'l': if (connected > 0) { ret = sscanf( &command[2], "%d", &like ); if( ret < 1) { printf(" invalid line\n> "); break; } like_msg(like, 1); } else {printf("You must connect to a server first\n>"); } break; case 'r': if (connected > 0) { ret = sscanf( &command[2], "%d", &like); if (ret < 1) { printf(" invalid line\n> "); break; } like_msg(like, 0); } else {printf("You must connect to a server first\n>"); } break; case 'h': if (strlen(chatroom) != 0) { print_history(); printf("> "); } else printf("You are not in a chatroom.\n>"); break; case 'v': if (connected > 0) { show_servers(); } else {printf("You must connect to a server first\n>"); } break; default: printf("> "); break; } fflush(stdout); }