Ejemplo n.º 1
0
void
nick_command_parse (session *sess, char *cmd, char *nick, char *allnick)
{
	char *buf;
	char *host = _("Host unknown");
	struct User *user;
	int len;

/*	if (sess->type == SESS_DIALOG)
	{
		buf = (char *)(GTK_ENTRY (sess->gui->topic_entry)->text);
		buf = strrchr (buf, '@');
		if (buf)
			host = buf + 1;
	} else*/
	{
		user = userlist_find (sess, nick);
		if (user && user->hostname)
			host = strchr (user->hostname, '@') + 1;
	}

	/* this can't overflow, since popup->cmd is only 256 */
	len = strlen (cmd) + strlen (nick) + strlen (allnick) + 512;
	buf = malloc (len);

	auto_insert (buf, len, cmd, 0, 0, allnick, sess->channel, "",
					 server_get_network (sess->server, TRUE), host,
					 sess->server->nick, nick);

	nick_command (sess, buf);

	free (buf);
}
Ejemplo n.º 2
0
void request_check(int index, char* buf){
    char tokens[MAX_MSG_TOKENS][MAX_MSG_LEN+1];
    int arg_num = tokenize(buf,tokens);
    int type,connfd;

    connfd = p.clientfd[index];

    if (!strcmp(tokens[0],"USER"))
        type = USER_CMD;
    else if(!strcmp(tokens[0],"NICK"))
        type = NICK_CMD;
    else if(!strcmp(tokens[0],"JOIN"))
        type = JOIN_CMD;
    else if(!strcmp(tokens[0],"QUIT"))
        type = QUIT_CMD;
    else if(!strcmp(tokens[0],"PART"))
        type = PART_CMD;
    else if(!strcmp(tokens[0],"LIST"))
        type = LIST_CMD;
    else if(!strcmp(tokens[0],"WHO"))
        type = WHO_CMD;
    else if(!strcmp(tokens[0],"PRIVMSG"))
        type = PRIVMSG_CMD;
    else
        type = UNKONWN_CMD;

    //DEBUG
    int i;
    printf(" # CMD:%s\t ARG_NUM:%d\t",tokens[0],arg_num);
    for(i=0;i<4;i++)
        printf(" ARG%d:%s\t",i,tokens[i+1]);
    printf("\n");

    if(type == UNKONWN_CMD)
        unknown_command(connfd,tokens[0]);
    else if(arg_num < ARG_NUM[type]){
        char msg[MAX_MSG_LEN];
        if(type == NICK_CMD)
            /* NICK ERRRO TYPE: ERR_NOERR_NONICKNAMEGIVEN */
            snprintf(msg,MAX_MSG_LEN,":No nickname given\n");
        else if(type == PRIVMSG_CMD){
            /* PRIVMSG ERRRO TYPE: ERR_NORECIPIENT */
            if(!arg_num)
                snprintf(msg,MAX_MSG_LEN,":No recipient given PRIVMSG\n");
            /* PRIVMSG ERRRO TYPE: ERR_NOTEXTTOSEND */
            else
                snprintf(msg,MAX_MSG_LEN,":No text to send\n");
        }else
            snprintf(msg,MAX_MSG_LEN,"%s:Not enough parameters\n", tokens[0]);
        send_msg_back(connfd,msg);
    }
    else
        switch(type){
            case QUIT_CMD:
                quit_command(index);
                break;
            case USER_CMD:
                user_command(connfd,tokens[1],tokens[4]);               
                break;
            case NICK_CMD:
                nick_command(connfd,tokens[1]);
                break;
            default:
                if(check_register(connfd)){
                    switch(type){
                        case JOIN_CMD:
                            join_command(connfd,tokens[1]);
                            break;
                        case PART_CMD:
                            part_command(connfd,tokens[1],1);
                            break;
                        case LIST_CMD:
                            list_command(connfd);
                            break;
                        case WHO_CMD:
                            who_command(connfd,tokens[1]);
                            break;
                        case PRIVMSG_CMD:
                            privmsg_command(connfd,tokens[1],tokens[2]);
                    }
                }else
                    send_msg_back(connfd,":You have not registered\n");
        }
}