extern int handle_irc_welcome(t_connection * conn) { char temp[MAX_IRC_MESSAGE_LEN]; std::time_t temptime; char const * tempname; char const * temptimestr; if (!conn) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return -1; } tempname = conn_get_loggeduser(conn); if ((34+std::strlen(tempname)+1)<=MAX_IRC_MESSAGE_LEN) std::sprintf(temp,":Welcome to the %s IRC Network %s",prefs_get_irc_network_name(), tempname); else std::sprintf(temp,":Maximum length exceeded"); irc_send(conn,RPL_WELCOME,temp); if ((14+std::strlen(server_get_hostname())+10+std::strlen(PVPGN_SOFTWARE" "PVPGN_VERSION)+1)<=MAX_IRC_MESSAGE_LEN) std::sprintf(temp,":Your host is %s, running "PVPGN_SOFTWARE" "PVPGN_VERSION,server_get_hostname()); else std::sprintf(temp,":Maximum length exceeded"); irc_send(conn,RPL_YOURHOST,temp); temptime = server_get_starttime(); /* FIXME: This should be build time */ temptimestr = std::ctime(&temptime); if ((25+std::strlen(temptimestr)+1)<=MAX_IRC_MESSAGE_LEN) std::sprintf(temp,":This server was created %s",temptimestr); /* FIXME: is ctime() portable? */ else std::sprintf(temp,":Maximum length exceeded"); irc_send(conn,RPL_CREATED,temp); /* we don't give mode information on MYINFO we give it on ISUPPORT */ if ((std::strlen(server_get_hostname())+7+std::strlen(PVPGN_SOFTWARE" "PVPGN_VERSION)+9+1)<=MAX_IRC_MESSAGE_LEN) std::sprintf(temp,"%s "PVPGN_SOFTWARE" "PVPGN_VERSION" - -",server_get_hostname()); else std::sprintf(temp,":Maximum length exceeded"); irc_send(conn,RPL_MYINFO,temp); std::sprintf(temp,"NICKLEN=%d TOPICLEN=%d CHANNELLEN=%d PREFIX=%s CHANTYPES="CHANNEL_TYPE" NETWORK=%s IRCD="PVPGN_SOFTWARE, MAX_CHARNAME_LEN, MAX_TOPIC_LEN, MAX_CHANNELNAME_LEN, CHANNEL_PREFIX, prefs_get_irc_network_name()); if((std::strlen(temp))<=MAX_IRC_MESSAGE_LEN) irc_send(conn,RPL_ISUPPORT,temp); else { std::sprintf(temp,":Maximum length exceeded"); irc_send(conn,RPL_ISUPPORT,temp); } irc_send_motd(conn); message_send_text(conn,message_type_notice,NULL,"This is an experimental service"); conn_set_state(conn,conn_state_bot_password); if (conn_get_ircpass(conn)) { message_send_text(conn,message_type_notice,NULL,"Trying to authenticate with PASS ..."); irc_authenticate(conn,conn_get_ircpass(conn)); } else { message_send_text(conn,message_type_notice,NULL,"No PASS command received. Please identify yourself by /msg NICKSERV identify <password>."); } return 0; }
static int _handle_privmsg_command(t_connection * conn, int numparams, char ** params, char * text) { if ((numparams>=1)&&(text)) { int i; char ** e; e = irc_get_listelems(params[0]); /* FIXME: support wildcards! */ /* start amadeo: code was sent by some unkown fellow of pvpgn (maybe u wanna give us your name for any credits), it adds nick-registration, i changed some things here and there... */ for (i=0; ((e)&&(e[i])); i++) { if (strcasecmp(e[i],"NICKSERV")==0) { char * pass; char * p; pass = std::strchr(text,' '); if (pass) *pass++ = '\0'; if (strcasecmp(text,"identify")==0) { switch (conn_get_state(conn)) { case conn_state_bot_password: { if (pass) { t_hash h; for (p = pass; *p; p++) if (std::isupper((int)*p)) *p = std::tolower(*p); bnet_hash(&h,std::strlen(pass),pass); irc_authenticate(conn,hash_get_str(h)); } else { message_send_text(conn,message_type_notice,NULL,"Syntax: IDENTIFY <password> (max 16 characters)"); } break; } case conn_state_loggedin: { message_send_text(conn,message_type_notice,NULL,"You don't need to IDENTIFY"); break; } default: ; eventlog(eventlog_level_trace,__FUNCTION__,"got /msg in unexpected connection state (%s)",conn_state_get_str(conn_get_state(conn))); } } else if (strcasecmp(text,"register")==0) { unsigned int j; t_hash passhash; t_account * temp; char msgtemp[MAX_IRC_MESSAGE_LEN]; char * username=(char *)conn_get_loggeduser(conn); if (account_check_name(username)<0) { message_send_text(conn,message_type_error,conn,"Account name contains invalid symbol!"); break; } if(!prefs_get_allow_new_accounts()) { message_send_text(conn,message_type_error,conn,"Account creation is not allowed"); break; } if (!pass || pass[0]=='\0' || (std::strlen(pass)>16) ) { message_send_text(conn,message_type_error,conn,"Syntax: REGISTER <password> (max 16 characters)"); break; } for (j=0; j<std::strlen(pass); j++) if (std::isupper((int)pass[j])) pass[j] = std::tolower((int)pass[j]); bnet_hash(&passhash,std::strlen(pass),pass); snprintf(msgtemp, sizeof(msgtemp), "Trying to create account \"%s\" with password \"%s\"",username,pass); message_send_text(conn,message_type_info,conn,msgtemp); temp = accountlist_create_account(username,hash_get_str(passhash)); if (!temp) { message_send_text(conn,message_type_error,conn,"Failed to create account!"); eventlog(eventlog_level_debug,__FUNCTION__,"[%d] account \"%s\" not created (failed)",conn_get_socket(conn),username); conn_unget_chatname(conn,username); break; } snprintf(msgtemp, sizeof(msgtemp), "Account "UID_FORMAT" created.",account_get_uid(temp)); message_send_text(conn,message_type_info,conn,msgtemp); eventlog(eventlog_level_debug,__FUNCTION__,"[%d] account \"%s\" created",conn_get_socket(conn),username); conn_unget_chatname(conn,username); } else { char tmp[MAX_IRC_MESSAGE_LEN+1]; message_send_text(conn,message_type_notice,NULL,"Invalid arguments for NICKSERV"); snprintf(tmp, sizeof(tmp), ":Unrecognized command \"%s\"", text); message_send_text(conn,message_type_notice,NULL,tmp); } } else if (conn_get_state(conn)==conn_state_loggedin) { if (e[i][0]=='#') { /* channel message */ t_channel * channel; if ((channel = channellist_find_channel_by_name(irc_convert_ircname(e[i]),NULL,NULL))) { if ((std::strlen(text)>=9)&&(std::strncmp(text,"\001ACTION ",8)==0)&&(text[std::strlen(text)-1]=='\001')) { /* at least "\001ACTION \001" */ /* it's a CTCP ACTION message */ text = text + 8; text[std::strlen(text)-1] = '\0'; channel_message_send(channel,message_type_emote,conn,text); } else { channel_message_log(channel, conn, 1, text); channel_message_send(channel,message_type_talk,conn,text); } } else { irc_send(conn,ERR_NOSUCHCHANNEL,":No such channel"); } } else { /* whisper */ t_connection * user; if ((user = connlist_find_connection_by_accountname(e[i]))) { message_send_text(user,message_type_whisper,conn,text); } else { irc_send(conn,ERR_NOSUCHNICK,":No such user"); } } } } if (e) irc_unget_listelems(e); } else irc_send(conn,ERR_NEEDMOREPARAMS,"PRIVMSG :Not enough parameters"); return 0; }
extern int irc_welcome(t_connection * conn) { char temp[MAX_IRC_MESSAGE_LEN]; time_t temptime; char const * tempname; char const * temptimestr; char const * filename; FILE *fp; char * line, * formatted_line; char send_line[MAX_IRC_MESSAGE_LEN]; char motd_failed = 0; if (!conn) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return -1; } tempname = conn_get_loggeduser(conn); if ((34+strlen(tempname)+1)<=MAX_IRC_MESSAGE_LEN) sprintf(temp,":Welcome to the %s IRC Network %s",prefs_get_irc_network_name(), tempname); else sprintf(temp,":Maximum length exceeded"); irc_send(conn,RPL_WELCOME,temp); if ((14+strlen(server_get_hostname())+10+strlen(PVPGN_SOFTWARE" "PVPGN_VERSION)+1)<=MAX_IRC_MESSAGE_LEN) sprintf(temp,":Your host is %s, running "PVPGN_SOFTWARE" "PVPGN_VERSION,server_get_hostname()); else sprintf(temp,":Maximum length exceeded"); irc_send(conn,RPL_YOURHOST,temp); temptime = server_get_starttime(); /* FIXME: This should be build time */ temptimestr = ctime(&temptime); if ((25+strlen(temptimestr)+1)<=MAX_IRC_MESSAGE_LEN) sprintf(temp,":This server was created %s",temptimestr); /* FIXME: is ctime() portable? */ else sprintf(temp,":Maximum length exceeded"); irc_send(conn,RPL_CREATED,temp); /* we don't give mode information on MYINFO we give it on ISUPPORT */ if ((strlen(server_get_hostname())+7+strlen(PVPGN_SOFTWARE" "PVPGN_VERSION)+9+1)<=MAX_IRC_MESSAGE_LEN) sprintf(temp,"%s "PVPGN_SOFTWARE" "PVPGN_VERSION" - -",server_get_hostname()); else sprintf(temp,":Maximum length exceeded"); irc_send(conn,RPL_MYINFO,temp); if((conn_get_wol(conn) == 1)) sprintf(temp,"NICKLEN=%d TOPICLEN=%d CHANNELLEN=%d PREFIX="CHANNEL_PREFIX" CHANTYPES="CHANNEL_TYPE" NETWORK=%s IRCD="PVPGN_SOFTWARE, WOL_NICKNAME_LEN, MAX_TOPIC_LEN, CHANNEL_NAME_LEN, prefs_get_irc_network_name()); else sprintf(temp,"NICKLEN=%d TOPICLEN=%d CHANNELLEN=%d PREFIX="CHANNEL_PREFIX" CHANTYPES="CHANNEL_TYPE" NETWORK=%s IRCD="PVPGN_SOFTWARE, CHAR_NAME_LEN, MAX_TOPIC_LEN, CHANNEL_NAME_LEN, prefs_get_irc_network_name()); if((strlen(temp))<=MAX_IRC_MESSAGE_LEN) irc_send(conn,RPL_ISUPPORT,temp); else { sprintf(temp,":Maximum length exceeded"); irc_send(conn,RPL_ISUPPORT,temp); } if ((3+strlen(server_get_hostname())+22+1)<=MAX_IRC_MESSAGE_LEN) sprintf(temp,":- %s, "PVPGN_SOFTWARE" "PVPGN_VERSION", built on %s",server_get_hostname(),temptimestr); else sprintf(temp,":Maximum length exceeded"); irc_send(conn,RPL_MOTDSTART,temp); if ((filename = prefs_get_motdfile())) { if ((fp = fopen(filename,"r"))) { while ((line=file_get_line(fp))) { if ((formatted_line = message_format_line(conn,line))) { formatted_line[0]=' '; sprintf(send_line,":-%s",formatted_line); irc_send(conn,RPL_MOTD,send_line); xfree(formatted_line); } } file_get_line(NULL); // clear file_get_line buffer fclose(fp); } else motd_failed = 1; } else motd_failed = 1; if (motd_failed) { irc_send(conn,RPL_MOTD,":- Failed to load motd, sending default motd "); irc_send(conn,RPL_MOTD,":- ====================================================== "); irc_send(conn,RPL_MOTD,":- http://www.pvpgn.org "); irc_send(conn,RPL_MOTD,":- ====================================================== "); } irc_send(conn,RPL_ENDOFMOTD,":End of /MOTD command"); irc_send_cmd(conn,"NOTICE",":This is an experimental service."); conn_set_state(conn,conn_state_bot_password); if (connlist_find_connection_by_accountname(conn_get_loggeduser(conn))) { irc_send_cmd(conn,"NOTICE","This account is already logged in, use another account."); return -1; } if (conn_get_ircpass(conn)) { irc_send_cmd(conn,"NOTICE",":Trying to authenticate with PASS ..."); irc_authenticate(conn,conn_get_ircpass(conn)); } else { irc_send_cmd(conn,"NOTICE",":No PASS command received. Please identify yourself by /msg NICKSERV identify <password>."); } return 0; }