Exemplo n.º 1
0
int parse_server (struct socket_info *sinfo)
{
	struct inputstruct is;
	
	SplitInput(sinfo->buff,&is);
	
	if(isalpha((int)is.command[1])) {
		return(handle_server_command(sinfo,&is));
	}
            
	return(handle_numeric(sinfo,&is));
              
	return(0);
}
Exemplo n.º 2
0
void IRC::handle(const string& oline) {
    string line = trim(oline);
    printf("%s\n", line.c_str());

    //We are pinged, respond!
    if(line.compare(0, 4, "PING") == 0) {
        onServerPing(line.substr(5));
        return;
    }

    char* cstr = new char[line.size() + 1];
    strcpy(cstr, line.c_str());

    string sender, nick, login, host;

    bool nickOnly = false;
    size_t tokn = 0;
    char *tok = strtok(cstr, " ");
    while(tok != NULL) {
        //For each token, check
        string tmp = tok;
        if(tokn == 0) {
            sender = tmp;
            if(sender[0] == ':')
                sender = sender.substr(1);

            size_t exp = sender.find("!");
            size_t at = sender.find("@");

            //TODO: Add checks for 'exp' and 'at' being string::npos
            //  to avoid calling these when there are (no ill effects
            //  have been seen from not doing so yet, however for sanity sake)
            if(exp == string::npos || at == string::npos) {
                nick = trim(sender);
                login = "";
                host = "";
                nickOnly = true;
            } else {
                nick = trim(sender.substr(0, exp));
                login = trim(sender.substr(exp + 1, at));
                host = trim(sender.substr(at + 1));
            }
        }

        if(tokn == 1) {
            tok = strtok(NULL, " ");
            string target(tok); //AKA channel

            uint32_t code = 0;
            if(tmp.length() == 3 && (code = (uint32_t) atoi(tmp.c_str())) != 0 && code < 1000) {
                string response = line.substr(sender.length()+5+target.length()+1);
                handle_numeric(code,target,response);
                onNumeric(sender,code,target,response);
            } else if(tmp.compare("PRIVMSG") == 0) {
                handle_msg(target, nick, login, host, line.substr(line.find(" :") + 2));
            } else if(tmp.compare("NOTICE") == 0) {
                onNotice(target, nick, login, host, line.substr(line.find(" :") + 2));
            } else if(tmp.compare("JOIN") == 0) {
                //TODO: Add this user to the channel.
                onJoin(target, nick, login, host);
            } else if(tmp.compare("PART") == 0) {
                //TODO: Remove this user from the channel.
                onPart(target, nick, login, host);
            } else if(tmp.compare("TOPIC") == 0) {
                onTopic(target, line.substr(line.find(" :") + 2), nick, time(NULL), true);
            } else if(tmp.compare("KICK") == 0) {
                tok = strtok(NULL, " ");
                string recipient(tok);
                onKick(target, nick, login, host, recipient, line.substr(line.find(" :") + 2));
            } else if(tmp.compare("QUIT") == 0) {
                onQuit(nick, login, host, line.substr(line.find(" :") + 2));
            } else if(tmp.compare("MODE") == 0) {
                tok = strtok(NULL, " ");
                string mode = tok;
                if(mode[0] == ':')
                    mode = mode.substr(1);
                handle_mode(nick, login, host, target, mode);
            }
            //TODO: Add mode handler here
            else {
                onUnknown(line);
            }

            break;
        }

        tok = strtok(NULL, " ");
        ++tokn;
    }

    delete[] cstr;
}