?? channel.c
字號:
{ channel_destroy(channel,&curr2); } return 0;}extern void channel_update_latency(t_connection * me){ t_channel * channel; t_message * message; t_connection * c; if (!me) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return; } if (!(channel = conn_get_channel(me))) { eventlog(eventlog_level_error,__FUNCTION__,"connection has no channel"); return; } if (!(message = message_create(message_type_userflags,me,NULL,NULL))) /* handles NULL text */ return; for (c=channel_get_first(channel); c; c=channel_get_next()) if (conn_get_class(c)==conn_class_bnet) message_send(message,c); message_destroy(message);}extern void channel_update_userflags(t_connection * me){ t_channel * channel; t_message * message; t_connection * c; if (!me) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return; } if (!(channel = conn_get_channel(me))) { eventlog(eventlog_level_error,__FUNCTION__,"connection has no channel"); return; } if (!(message = message_create(message_type_userflags,me,NULL,NULL))) /* handles NULL text */ return; for (c=channel_get_first(channel); c; c=channel_get_next()) message_send(message,c); message_destroy(message);}extern void channel_message_log(t_channel const * channel, t_connection * me, int fromuser, char const * text){ if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return; } if (!me) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return; } if (channel->log) { time_t now; struct tm * tmnow; char timetemp[CHANLOG_TIME_MAXLEN]; now = time(NULL); if ((!(tmnow = localtime(&now)))) strcpy(timetemp,"?"); else strftime(timetemp,sizeof(timetemp),CHANLOGLINE_TIME_FORMAT,tmnow); if (fromuser) fprintf(channel->log,"%s: \"%s\" \"%s\"\n",timetemp,conn_get_username(me),text); else fprintf(channel->log,"%s: \"%s\" %s\n",timetemp,conn_get_username(me),text); fflush(channel->log); }}extern void channel_message_send(t_channel const * channel, t_message_type type, t_connection * me, char const * text){ t_connection * c; unsigned int heard; t_message * message; char const * tname; if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return; } if (!me) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return; } if(channel_get_flags(channel) & channel_flags_thevoid) // no talking in the void return; if(channel_get_flags(channel) & channel_flags_moderated) // moderated channel - only admins,OPs and voices may talk { if (type==message_type_talk || type==message_type_emote) { if (!((account_is_operator_or_admin(conn_get_account(me),channel_get_name(channel))) || (channel_conn_has_tmpVOICE(channel,me)))) { message_send_text(me,message_type_error,me,"This channel is moderated"); return; } } } if (!(message = message_create(type,me,NULL,text))) { eventlog(eventlog_level_error,__FUNCTION__,"could not create message"); return; } heard = 0; tname = conn_get_chatname(me); for (c=channel_get_first(channel); c; c=channel_get_next()) { if (c==me && (type==message_type_talk || type==message_type_join || type==message_type_part || type==message_wol_gameopt_owner)) continue; /* ignore ourself */ if ((type==message_type_talk || type==message_type_whisper || type==message_type_emote || type==message_type_broadcast) && conn_check_ignoring(c,tname)==1) continue; /* ignore squelched players */ if (message_send(message,c)==0 && c!=me) heard = 1; } conn_unget_chatname(me,tname); message_destroy(message); if ((conn_get_wol(me) == 0)) { if (!heard && (type==message_type_talk || type==message_type_emote)) message_send_text(me,message_type_info,me,"No one hears you.");}}extern int channel_ban_user(t_channel * channel, char const * user){ t_elem const * curr; char * temp; if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return -1; } if (!user) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL user"); return -1; } if (!channel->name) { eventlog(eventlog_level_error,__FUNCTION__,"got channel with NULL name"); return -1; } if (strcasecmp(channel->name,CHANNEL_NAME_BANNED)==0 || strcasecmp(channel->name,CHANNEL_NAME_KICKED)==0) return -1; LIST_TRAVERSE_CONST(channel->banlist,curr) if (strcasecmp(elem_get_data(curr),user)==0) return 0; temp = xstrdup(user); list_append_data(channel->banlist,temp); return 0;}extern int channel_unban_user(t_channel * channel, char const * user){ t_elem * curr; if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return -1; } if (!user) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL user"); return -1; } LIST_TRAVERSE(channel->banlist,curr) { char const * banned; if (!(banned = elem_get_data(curr))) { eventlog(eventlog_level_error,__FUNCTION__,"found NULL name in banlist"); continue; } if (strcasecmp(banned,user)==0) { if (list_remove_elem(channel->banlist,&curr)<0) { eventlog(eventlog_level_error,__FUNCTION__,"unable to remove item from list"); return -1; } xfree((void *)banned); /* avoid warning */ return 0; } } return -1;}extern int channel_check_banning(t_channel const * channel, t_connection const * user){ t_elem const * curr; if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return -1; } if (!user) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL user"); return -1; } if (!(channel->flags & channel_flags_allowbots) && conn_get_class(user)==conn_class_bot) return 1; LIST_TRAVERSE_CONST(channel->banlist,curr) if (conn_match(user,elem_get_data(curr))==1) return 1; return 0;}extern int channel_get_length(t_channel const * channel){ t_channelmember const * curr; int count; for (curr=channel->memberlist,count=0; curr; curr=curr->next,count++); return count;}extern t_connection * channel_get_first(t_channel const * channel){ if (!channel) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL channel"); return NULL; } memberlist_curr = channel->memberlist; return channel_get_next();}extern t_connection * channel_get_next(void){ t_channelmember * member; if (memberlist_curr) { member = memberlist_curr; memberlist_curr = memberlist_curr->next; return member->connection; } return NULL;}extern t_list * channel_get_banlist(t_channel const * channel){ if (!channel) { eventlog(eventlog_level_warn,__FUNCTION__,"got NULL channel"); return NULL; } return channel->banlist;}extern char const * channel_get_shortname(t_channel const * channel){ if (!channel) { eventlog(eventlog_level_warn,__FUNCTION__,"got NULL channel"); return NULL; } return channel->shortname;}static int channellist_load_permanent(char const * filename){ FILE * fp; unsigned int line; unsigned int pos; int botflag; int operflag; int logflag; unsigned int modflag; char * buff; char * name; char * sname; char * tag; char * bot; char * oper; char * log; char * country; char * max; char * moderated; char * newname; char * realmname; if (!filename) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL filename"); return -1; } if (!(fp = fopen(filename,"r"))) { eventlog(eventlog_level_error,__FUNCTION__,"could not open channel file \"%s\" for reading (fopen: %s)",filename,pstrerror(errno)); return -1; } for (line=1; (buff = file_get_line(fp)); line++) { if (buff[0]=='#' || buff[0]=='\0') { continue; } pos = 0; if (!(name = next_token(buff,&pos))) { eventlog(eventlog_level_error,__FUNCTION__,"missing name in line %u in file \"%s\"",line,filename); continue; } if (!(sname = next_token(buff,&pos))) { eventlog(eventlog_level_error,__FUNCTION__,"missing sname in line %u in file \"%s\"",line,filename); continue; } if (!(tag = next_token(buff,&pos))) { eventlog(eventlog_level_error,__FUNCTION__,"missing tag in line %u in file \"%s\"",line,filename); continue; } if (!(bot = next_token(buff,&pos))) { eventlog(eventlog_level_error,__FUNCTION__,"missing bot in line %u in file \"%s\"",line,filename); continue; } if (!(oper = next_token(buff,&pos))) { eventlog(eventlog_level_error,__FUNCTION__,"missing oper in line %u in file \"%s\"",line,filename); continue; } if (!(log = next_token(buff,&pos))) { eventlog(eventlog_level_error,__FUNCTION__,"missing log in line %u in file \"%s\"",line,filename); continue; } if (!(country = next_token(buff,&pos))) { eventlog(eventlog_level_error,__FUNCTION__,"missing country in line %u in file \"%s\"",line,filename); continue; } if (!(realmname = next_token(buff,&pos))) { eventlog(eventlog_level_error,__FUNCTION__,"missing realmname in line %u in file \"%s\"",line,filename); continue; } if (!(max = next_token(buff,&pos))) { eventlog(eventlog_level_error,__FUNCTION__,"missing max in line %u in file \"%s\"",line,filename); continue; } if (!(moderated = next_token(buff,&pos))) { eventlog(eventlog_level_error,__FUNCTION__,"missing mod in line %u in file \"%s\"",line,filename); continue; } switch (str_get_bool(bot)) { case 1: botflag = 1; break; case 0: botflag = 0; break; default: eventlog(eventlog_level_error,__FUNCTION__,"invalid boolean value \"%s\" for field 4 on line %u in file \"%s\"",bot,line,filename); continue; } switch (str_get_bool(oper)) { case 1: operflag = 1; break; case 0: operflag = 0; break; default: eventlog(eventlog_level_error,__FUNCTION__,"invalid boolean value \"%s\" for field 5 on line %u in file \"%s\"",oper,line,filename); continue; } switch (str_get_bool(log)) { case 1: logflag = 1; break; case 0: logflag = 0; break; default: eventlog(eventlog_level_error,__FUNCTION__,"invalid boolean value \"%s\" for field 5 on line %u in file \"%s\"",log,line,filename); continue; } switch (str_get_bool(moderated)) { case 1: modflag = 1; break; case 0: modflag = 0; break; default: eventlog(eventlog_level_error,__FUNCTION__,"invalid boolean value \"%s\" for field 10 on line %u in file \"%s\"",moderated,line,filename); continue; } if (strcmp(sname,"NULL") == 0) sname = NULL; if (strcmp(tag,"NULL") == 0) tag = NULL; if (strcmp(name,"NONE") == 0) name = NULL; if (strcmp(country, "NULL") == 0) country = NULL; if (strcmp(realmname,"NULL") == 0) realmname = NULL; if (name) { channel_create(name,sname,tag,1,botflag,operflag,logflag,country,realmname,atoi(max),modflag,0,0); } else { newname = channel_format_name(sname,country,realmname,1); if (newname) { channel_create(newname,sname,tag,1,botflag,operflag,logflag,country,realmname,atoi(max),modflag,0,1); xfree(newname); } else { eventlog(eventlog_level_error,__FUNCTION__,"cannot format channel name"); } } /* FIXME: call channel_delete() on current perm channels and do a channellist_find_channel() and set the long name, perm flag, etc, otherwise call channel_create(). This will make HUPing the server handle re-reading this file correctly. */ } file_get_line(NULL); // clear file_get_line buffer if (fclose(fp)<0) eventlog(eventlog_level_error,__FUNCTION__,"could not close channel file \"%s\" after reading (fclose: %s)",filename,pstrerror(errno)); return 0;}static char * channel_format_name(char const * sname, char const * country, char const * realmname, unsigned int id){ char * fullname; unsigned int len; if (!sname) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL sname"); return NULL; } len = strlen(sname)+1; /* FIXME: check lengths and format */ if (country) len = len + strlen(country) + 1; if (realmname) len = len + strlen(realmname) + 1; len = len + 32 + 1; fullname=xmalloc(len); sprintf(fullname,"%s%s%s%s%s-%d", realmname?realmname:"", realmname?" ":"", sname, country?" ":"", country?country:"", id); return fullname;}extern int channellist_reload(void){ t_elem * curr; t_channel * channel, * old_channel; t_channelmember * memberlist, * member, * old_member; t_list * channellist_old; if (channellist_head) { channellist_old = list_create(); /* First pass - get members */ LIST_TRAVERSE(channellist_head,curr) { if (!(channel = elem_get_data(curr))) { eventlog(eventlog_level_error,__FUNCTION__,"channel list contains NULL item"); continue; } /* Trick to avoid automatic channel destruction */ channel->flags |= channel_flags_permanent; if (channel->memberlist) { /* we need only channel name and memberlist */ old_channel = (t_channel *) xmalloc(sizeof(t_channel));
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -