📄 irc.c
字号:
e1_2 = NULL; if (e3[0]=='\0') { /* fill in recipient */ if ((tname = conn_get_chatname(dest))) toname = tname; } else toname = e3; if (strcmp(toname,"\r")==0) { toname = ""; /* HACK: the target field is really empty */ } len = (strlen(e1)+1+strlen(e2)+1+strlen(toname)+1+strlen(e4)+2+1); if (len<=MAX_IRC_MESSAGE_LEN) { char msg[MAX_IRC_MESSAGE_LEN+1]; if (e1_2) sprintf(msg,"%s@hidden %s %s %s\r\n",e1,e2,toname,e4); else sprintf(msg,"%s %s %s %s\r\n",e1,e2,toname,e4); eventlog(eventlog_level_debug,__FUNCTION__,"sent \"%s\"",msg); packet_set_size(packet,0); packet_append_data(packet,msg,strlen(msg)); if (tname) conn_unget_chatname(dest,tname); return 0; } else { /* FIXME: split up message? */ eventlog(eventlog_level_warn,__FUNCTION__,"maximum IRC message length exceeded"); if (tname) conn_unget_chatname(dest,tname); return -1; }}extern int irc_message_format(t_packet * packet, t_message_type type, t_connection * me, t_connection * dst, char const * text, unsigned int dstflags){ char * msg; char const * ctag; t_irc_message_from from; if (!packet) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL packet"); return -1; } msg = NULL; if (me) ctag = clienttag_uint_to_str(conn_get_clienttag(me)); else ctag = clienttag_uint_to_str(CLIENTTAG_IIRC_UINT); switch (type) { /* case message_type_adduser: this is sent manually in handle_irc */ case message_type_adduser: /* when we do it somewhere else, then we can also make sure to not get our logs spammed */ break; case message_type_join: from.nick = conn_get_chatname(me); from.user = ctag; from.host = addr_num_to_ip_str(conn_get_addr(me)); if((conn_get_wol(me) == 1)) { char temp[MAX_IRC_MESSAGE_LEN]; memset(temp,0,sizeof(temp)); /** * For WOL the channel JOIN output must be like the following: * user!WWOL@hostname JOIN :clanID,longIP channelName */ sprintf(temp,":0,%u",conn_get_addr(me)); msg = irc_message_preformat(&from,"JOIN",temp,irc_convert_channel(conn_get_channel(me))); } else msg = irc_message_preformat(&from,"JOIN","\r",irc_convert_channel(conn_get_channel(me))); conn_unget_chatname(me,from.nick); break; case message_type_part: from.nick = conn_get_chatname(me); from.user = ctag; from.host = addr_num_to_ip_str(conn_get_addr(me)); msg = irc_message_preformat(&from,"PART","\r",irc_convert_channel(conn_get_channel(me))); conn_unget_chatname(me,from.nick); break; case message_type_talk: case message_type_whisper: { char const * dest; char temp[MAX_IRC_MESSAGE_LEN]; if (me) { from.nick = conn_get_chatname(me); from.host = addr_num_to_ip_str(conn_get_addr(me)); } else { from.nick = server_get_hostname(); from.host = server_get_hostname(); } from.user = ctag; if (type==message_type_talk) dest = irc_convert_channel(conn_get_channel(me)); /* FIXME: support more channels and choose right one! */ else dest = ""; /* will be replaced with username in postformat */ sprintf(temp,":%s",text); msg = irc_message_preformat(&from,"PRIVMSG",dest,temp); if (me) conn_unget_chatname(me,from.nick); } break; case message_type_emote: { char const * dest; char temp[MAX_IRC_MESSAGE_LEN]; /* "\001ACTION " + text + "\001" + \0 */ if ((8+strlen(text)+1+1)<=MAX_IRC_MESSAGE_LEN) { sprintf(temp,":\001ACTION %s\001",text); } else { sprintf(temp,":\001ACTION (maximum message length exceeded)\001"); } from.nick = conn_get_chatname(me); from.user = ctag; from.host = addr_num_to_ip_str(conn_get_addr(me)); /* FIXME: also supports whisper emotes? */ dest = irc_convert_channel(conn_get_channel(me)); /* FIXME: support more channels and choose right one! */ msg = irc_message_preformat(&from,"PRIVMSG",dest,temp); conn_unget_chatname(me,from.nick); } break; case message_type_broadcast: case message_type_info: case message_type_error: { char temp[MAX_IRC_MESSAGE_LEN]; sprintf(temp,":%s",text); msg = irc_message_preformat(NULL,"NOTICE",NULL,temp); } break; case message_type_channel: /* ignore it */ break; case message_type_mode: from.nick = conn_get_chatname(me); from.user = ctag; from.host = addr_num_to_ip_str(conn_get_addr(me)); msg = irc_message_preformat(&from,"MODE","\r",text); conn_unget_chatname(me,from.nick); break; /** * Westwood Online Extensions */ case message_wol_joingame: from.nick = conn_get_chatname(me); from.user = ctag; from.host = addr_num_to_ip_str(conn_get_addr(me)); msg = irc_message_preformat(&from,"JOINGAME",text,"\r"); conn_unget_chatname(me,from.nick); break; case message_wol_gameopt_owner: from.nick = conn_get_chatname(me); from.user = ctag; from.host = addr_num_to_ip_str(conn_get_addr(me)); msg = irc_message_preformat(&from,"GAMEOPT",irc_convert_channel(conn_get_channel(me)),text); conn_unget_chatname(me,from.nick); break; case message_wol_gameopt_join: from.nick = conn_get_chatname(me); from.user = ctag; from.host = addr_num_to_ip_str(conn_get_addr(me)); msg = irc_message_preformat(&from,"GAMEOPT",channel_wol_get_game_owner(conn_get_channel(me)),text); conn_unget_chatname(me,from.nick); break; case message_wol_start_game: from.nick = conn_get_chatname(me); from.user = ctag; from.host = addr_num_to_ip_str(conn_get_addr(me)); msg = irc_message_preformat(&from,"STARTG","u",text); conn_unget_chatname(me,from.nick); break; case message_wol_page: from.nick = conn_get_chatname(me); from.user = ctag; from.host = addr_num_to_ip_str(conn_get_addr(me)); msg = irc_message_preformat(&from,"PAGE","u",text); conn_unget_chatname(me,from.nick); break; default: eventlog(eventlog_level_warn,__FUNCTION__,"%d not yet implemented",type); return -1; } if (msg) { packet_append_string(packet,msg); xfree(msg); return 0; } return -1;}extern int irc_send_rpl_namreply(t_connection * c, t_channel const * channel){ char temp[MAX_IRC_MESSAGE_LEN]; char const * ircname; int first = 1; t_connection * m; if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return -1; } if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return -1; } memset(temp,0,sizeof(temp)); ircname = irc_convert_channel(channel); if (!ircname) { eventlog(eventlog_level_error,__FUNCTION__,"channel has NULL ircname"); return -1; } /* '@' = secret; '*' = private; '=' = public */ if ((1+1+strlen(ircname)+2+1)<=MAX_IRC_MESSAGE_LEN) { sprintf(temp,"%c %s :",((channel_get_permanent(channel))?('='):('*')),ircname); } else { eventlog(eventlog_level_warn,__FUNCTION__,"maximum message length exceeded"); return -1; } /* FIXME: Add per user flags (@(op) and +(voice))*/ for (m = channel_get_first(channel);m;m = channel_get_next()) { char const * name = conn_get_chatname(m); char flg[5] = ""; unsigned int flags; if (!name) continue; flags = conn_get_flags(m); if (flags & MF_BLIZZARD) strcat(flg,"@"); else if ((flags & MF_BNET) || (flags & MF_GAVEL)) strcat(flg,"%"); else if (flags & MF_VOICE) strcat(flg,"+"); if ((strlen(temp)+((!first)?(1):(0))+strlen(flg)+strlen(name)+1)<=sizeof(temp)) { if (!first) strcat(temp," "); if((conn_get_wol(c) == 1)) { if((conn_wol_get_ingame(c) == 0)) { if ((flags & MF_BLIZZARD)) strcat(temp,"@"); if ((flags & MF_BNET) || (flags & MF_GAVEL)) strcat(temp,"@"); } sprintf(temp,"%s%s,0,%u",temp,name,conn_get_addr(m)); } else { strcat(temp,flg); strcat(temp,name); } first = 0; } conn_unget_chatname(m,name); } irc_send(c,RPL_NAMREPLY,temp); return 0;}static int irc_who_connection(t_connection * dest, t_connection * c){ t_account * a; char const * tempuser; char const * tempowner; char const * tempname; char const * tempip; char const * tempflags = "@"; /* FIXME: that's dumb */ char temp[MAX_IRC_MESSAGE_LEN]; char const * tempchannel; if (!dest) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL destination"); return -1; } if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return -1; } a = conn_get_account(c); if (!(tempuser = clienttag_uint_to_str(conn_get_clienttag(c)))) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL clienttag (tempuser)"); return -1; } if (!(tempowner = account_get_ll_owner(a))) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL ll_owner (tempowner)"); return -1; } if (!(tempname = conn_get_username(c))) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL username (tempname)"); return -1; } if (!(tempip = addr_num_to_ip_str(conn_get_addr(c)))) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL addr (tempip)"); return -1; } if (!(tempchannel = irc_convert_channel(conn_get_channel(c)))) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel (tempchannel)"); return -1; } if ((strlen(tempchannel)+1+strlen(tempuser)+1+strlen(tempip)+1+strlen(server_get_hostname())+1+strlen(tempname)+1+1+strlen(tempflags)+4+strlen(tempowner)+1)>MAX_IRC_MESSAGE_LEN) { eventlog(eventlog_level_info,__FUNCTION__,"WHO reply too long - skip"); return -1; } else sprintf(temp,"%s %s %s %s %s %c%s :0 %s",tempchannel,tempuser,tempip,server_get_hostname(),tempname,'H',tempflags,tempowner); irc_send(dest,RPL_WHOREPLY,temp); return 0;}extern int irc_who(t_connection * c, char const * name){ /* FIXME: support wildcards! */ if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return -1; } if (!name) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL name"); return -1; } if ((name[0]=='#')||(name[0]=='&')||(name[0]=='!')) { /* it's a channel */ t_connection * info; t_channel * channel; char const * ircname; ircname = irc_convert_ircname(name); channel = channellist_find_channel_by_name(ircname,NULL,NULL); if (!channel) { char temp[MAX_IRC_MESSAGE_LEN]; if ((strlen(":No such channel")+1+strlen(name)+1)<=MAX_IRC_MESSAGE_LEN) { sprintf(temp,":No such channel %s",name); irc_send(c,ERR_NOSUCHCHANNEL,temp); } else { irc_send(c,ERR_NOSUCHCHANNEL,":No such channel"); } return 0; } for (info = channel_get_first(channel);info;info = channel_get_next()) { irc_who_connection(c,info); } } else { /* it's just one user */ t_connection * info; if ((info = connlist_find_connection_by_accountname(name))) return irc_who_connection(c,info); } return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -