📄 command.c
字号:
else if (channel_conn_is_tmpOP(conn_get_channel(c),account_get_conn(acc))) OP_lvl = 2; if (OP_lvl==0) { message_send_text(c,message_type_error,c,"You must be at least a Channel Operator or tempOP to use this command."); return -1; } text = skip_command(text); if (!(username = &text[0])) { message_send_text(c, message_type_info, c, "You need to supply a username."); return -1; } if(!(acc = accountlist_find_account(username))) { sprintf(msgtemp, "There's no account with username %.64s.", username); message_send_text(c, message_type_info, c, msgtemp); return -1; } dst_c = account_get_conn(acc); if (OP_lvl==1) // user is real OP and allowed to deOP { if (account_get_auth_admin(acc,channel) == 1 || account_get_auth_operator(acc,channel) == 1) { if (account_get_auth_admin(acc,channel) == 1) { if (account_get_auth_admin(conn_get_account(c),channel)!=1 && account_get_auth_admin(conn_get_account(c),NULL)!=1) message_send_text(c,message_type_info,c,"You must be at least a Channel Admin to demote another Channel Admin"); else { account_set_auth_admin(acc,channel,0); sprintf(msgtemp, "%s has been demoted from a Channel Admin.", username); message_send_text(c, message_type_info, c, msgtemp); if (dst_c) { sprintf(msgtemp2,"%s has demoted you from a Channel Admin of channel \"%s\"",conn_get_loggeduser(c),channel); message_send_text(dst_c, message_type_info, c, msgtemp2); } } } if (account_get_auth_operator(acc,channel) == 1) { account_set_auth_operator(acc,channel,0); sprintf(msgtemp,"%s has been demoted from a Channel Operator",username); message_send_text(c, message_type_info, c, msgtemp); if (dst_c) { sprintf(msgtemp2,"%s has demoted you from a Channel Operator of channel \"%s\"",conn_get_loggeduser(c),channel); message_send_text(dst_c, message_type_info, c, msgtemp2); } } done = 1; } if ((dst_c) && channel_conn_is_tmpOP(conn_get_channel(c),dst_c)) { conn_set_tmpOP_channel(dst_c,NULL); sprintf(msgtemp,"%s has been demoted from a tempOP of this channel",username); message_send_text(c, message_type_info, c, msgtemp); if (dst_c) { sprintf(msgtemp2,"%s has demoted you from a tmpOP of channel \"%s\"",conn_get_loggeduser(c),channel); message_send_text(dst_c, message_type_info, c, msgtemp2); } done = 1; } if (!done) { sprintf(msgtemp,"%s is no Channel Admin or Channel Operator or tempOP, so you can't demote him.",username); message_send_text(c, message_type_info, c, msgtemp); } } else //user is just a tempOP and may only deOP other tempOPs { if (dst_c && channel_conn_is_tmpOP(conn_get_channel(c),dst_c)) { conn_set_tmpOP_channel(account_get_conn(acc),NULL); sprintf(msgtemp,"%s has been demoted from a tempOP of this channel",username); message_send_text(c, message_type_info, c, msgtemp); sprintf(msgtemp2,"%s has demoted you from a tempOP of channel \"%s\"",conn_get_loggeduser(c),channel); if (dst_c) message_send_text(dst_c, message_type_info, c, msgtemp2); } else { sprintf(msgtemp,"%s is no tempOP in this channel, so you can't demote him",username); message_send_text(c, message_type_info, c, msgtemp); } } command_set_flags(connlist_find_connection_by_accountname(username)); return 0;}static int _handle_friends_command(t_connection * c, char const * text){ int i; t_account *my_acc = conn_get_account(c); text = skip_command(text);; if(text[0]=='\0' || strstart(text,"help")==0 || strstart(text, "h")==0) { message_send_text(c,message_type_info,c,"Friends List (Used in Arranged Teams and finding online friends.)"); message_send_text(c,message_type_info,c,"Type: /f add <username> (adds a friend to your list)"); message_send_text(c,message_type_info,c,"Type: /f del <username> (removes a friend from your list)"); message_send_text(c,message_type_info,c,"Type: /f promote <username> (promote a friend in your list)"); message_send_text(c,message_type_info,c,"Type: /f demote <username> (demote a friend in your list)"); message_send_text(c,message_type_info,c,"Type: /f list (shows your full friends list)"); message_send_text(c,message_type_info,c,"Type: /f msg (whispers a message to all your friends at once)"); return 0; } if (strstart(text,"add")==0 || strstart(text,"a")==0) { char msgtemp[MAX_MESSAGE_LEN]; t_packet * rpacket; t_connection * dest_c; t_account * friend_acc; t_server_friendslistreply_status status; t_game * game; t_channel * channel; char stat; t_list * flist; t_friend * fr; text = skip_command(text); if (text[0] == '\0') { message_send_text(c,message_type_info,c,"usage: /f add <username>"); return 0; } if (!(friend_acc = accountlist_find_account(text))) { message_send_text(c,message_type_info,c,"That user does not exist."); return 0; } switch(account_add_friend(my_acc, friend_acc)) { case -1: message_send_text(c,message_type_error,c,"Server error."); return 0; case -2: message_send_text(c,message_type_info,c,"You can't add yourself to your friends list."); return 0; case -3: sprintf(msgtemp, "You can only have a maximum of %d friends.", prefs_get_max_friends()); message_send_text(c,message_type_info,c,msgtemp); return 0; case -4: sprintf(msgtemp, "%s is already on your friends list!", text); message_send_text(c,message_type_info,c,msgtemp); return 0; } sprintf( msgtemp, "Added %s to your friends list.", text); message_send_text(c,message_type_info,c,msgtemp); dest_c = connlist_find_connection_by_account(friend_acc); if(dest_c!=NULL) { sprintf(msgtemp,"%s added you to his/her friends list.",conn_get_username(c)); message_send_text(dest_c,message_type_info,dest_c,msgtemp); } if ((conn_get_class(c)!=conn_class_bnet) || (!(rpacket = packet_create(packet_class_bnet)))) return 0; packet_set_size(rpacket,sizeof(t_server_friendadd_ack)); packet_set_type(rpacket,SERVER_FRIENDADD_ACK); packet_append_string(rpacket, account_get_name(friend_acc)); game = NULL; channel = NULL; if(!(dest_c)) { bn_byte_set(&status.location,FRIENDSTATUS_OFFLINE); bn_byte_set(&status.status,0); bn_int_set(&status.clienttag,0); } else { bn_int_set(&status.clienttag, conn_get_clienttag(dest_c)); stat = 0; flist = account_get_friends(my_acc); fr = friendlist_find_account(flist,friend_acc); if ((friend_get_mutual(fr))) stat |= FRIEND_TYPE_MUTUAL; if ((conn_get_dndstr(dest_c))) stat |= FRIEND_TYPE_DND; if ((conn_get_awaystr(dest_c))) stat |= FRIEND_TYPE_AWAY; bn_byte_set(&status.status,stat); if((game = conn_get_game(dest_c))) { if (game_get_flag(game) != game_flag_private) bn_byte_set(&status.location,FRIENDSTATUS_PUBLIC_GAME); else bn_byte_set(&status.location,FRIENDSTATUS_PRIVATE_GAME); } else if((channel = conn_get_channel(dest_c))) { bn_byte_set(&status.location,FRIENDSTATUS_CHAT); } else { bn_byte_set(&status.location,FRIENDSTATUS_ONLINE); } } packet_append_data(rpacket, &status, sizeof(status)); if (game) packet_append_string(rpacket,game_get_name(game)); else if (channel) packet_append_string(rpacket,channel_get_name(channel)); else packet_append_string(rpacket,""); conn_push_outqueue(c,rpacket); packet_del_ref(rpacket); return 0; } if (strstart(text,"msg")==0 || strstart(text,"w")==0 || strstart(text,"whisper")==0 || strstart(text,"m")==0) { char const *msg; int cnt = 0; t_connection * dest_c; t_elem * curr; t_friend * fr; t_list * flist; msg = skip_command(text); /* if the message test is empty then ignore command */ if (msg[0]=='\0') { message_send_text(c,message_type_info,c,"Did not message any friends. Type some text next time."); return 0; } flist=account_get_friends(my_acc); if(flist==NULL) return -1; LIST_TRAVERSE(flist,curr) { if (!(fr = elem_get_data(curr))) { eventlog(eventlog_level_error,__FUNCTION__,"found NULL entry in list"); continue; } if(friend_get_mutual(fr)) { dest_c = connlist_find_connection_by_account(friend_get_account(fr)); if (!dest_c) continue; message_send_text(dest_c,message_type_whisper,c,msg); cnt++; } } if(cnt) message_send_text(c,message_type_friendwhisperack,c,msg); else message_send_text(c,message_type_info,c,"All your friends are offline."); return 0; } if (strstart(text,"r")==0 || strstart(text,"remove")==0 || strstart(text,"del")==0 || strstart(text,"delete")==0) { int num; char msgtemp[MAX_MESSAGE_LEN]; t_packet * rpacket; text = skip_command(text); if (text[0]=='\0') { message_send_text(c,message_type_info,c,"usage: /f remove <username>"); return 0; } switch((num = account_remove_friend2(my_acc, text))) { case -1: return -1; case -2: sprintf(msgtemp, "%s was not found on your friends list.", text); message_send_text(c,message_type_info,c,msgtemp); return 0; default: sprintf(msgtemp, "Removed %s from your friends list.", text); message_send_text(c,message_type_info,c,msgtemp); if ((conn_get_class(c)!=conn_class_bnet) || (!(rpacket = packet_create(packet_class_bnet)))) return 0; packet_set_size(rpacket,sizeof(t_server_frienddel_ack)); packet_set_type(rpacket,SERVER_FRIENDDEL_ACK); bn_byte_set(&rpacket->u.server_frienddel_ack.friendnum, num); conn_push_outqueue(c,rpacket); packet_del_ref(rpacket); return 0; } } if (strstart(text,"p")==0 || strstart(text,"promote")==0) { int num; int n; char msgtemp[MAX_MESSAGE_LEN]; char const * dest_name; t_packet * rpacket; t_list * flist; t_friend * fr; t_account * dest_acc; unsigned int dest_uid; text = skip_command(text); if (text[0]=='\0') { message_send_text(c,message_type_info,c,"usage: /f promote <username>"); return 0; } num = account_get_friendcount(my_acc); flist = account_get_friends(my_acc); for(n = 1; n<num; n++) if( (dest_uid = account_get_friend(my_acc, n)) && (fr = friendlist_find_uid(flist, dest_uid)) && (dest_acc = friend_get_account(fr)) && (dest_name = account_get_name(dest_acc)) && (strcasecmp(dest_name, text) == 0) ) { account_set_friend(my_acc, n, account_get_friend(my_acc, n-1)); account_set_friend(my_acc, n-1, dest_uid); sprintf(msgtemp, "Premoted %s in your friends list.", dest_name); message_send_text(c,message_type_info,c,msgtemp); if ((conn_get_class(c)!=conn_class_bnet) || (!(rpacket = packet_create(packet_class_bnet)))) return 0; packet_set_size(rpacket,sizeof(t_server_friendmove_ack)); packet_set_type(rpacket,SERVER_FRIENDMOVE_ACK); bn_byte_set(&rpacket->u.server_friendmove_ack.pos1, n-1); bn_byte_set(&rpacket->u.server_friendmove_ack.pos2, n); conn_push_outqueue(c,rpacket); packet_del_ref(rpacket); return 0; } return 0; } if (strstart(text,"d")==0 || strstart(text,"demote")==0) { int num; int n; char msgtemp[MAX_MESSAGE_LEN]; char const * dest_name; t_packet * rpacket; t_list * flist; t_friend * fr; t_account * dest_acc; unsigned int dest_uid; text = skip_command(text); if (text[0]=='\0') { message_send_text(c,message_type_info,c,"usage: /f demote <username>"); return 0; } num = account_get_friendcount(my_acc); flist = account_get_friends(my_acc); for(n = 0; n<num-1; n++) if( (dest_uid = account_get_friend(my_acc, n)) && (fr = friendlist_find_uid(flist, dest_uid)) && (dest_acc = friend_get_account(fr)) && (dest_name = account_get_name(dest_acc)) && (strcasecmp(dest_name, text) == 0) ) { account_set_friend(my_acc, n, account_get_friend(my_acc, n+1)); account_set_friend(my_acc, n+1, dest_uid); sprintf(msgtemp, "Premoted %s in your friends list.", dest_name); message_send_text(c,message_type_info,c,msgtemp); if ((conn_get_class(c)!=conn_class_bnet) || (!(rpacket = packet_create(packet_class_bnet)))) return 0; packet_set_size(rpacket,sizeof(t_server_friendmove_ack)); packet_set_type(rpacket,SERVER_FRIENDMOVE_ACK); bn_byte_set(&rpacket->u.server_friendmove_ack.pos1, n);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -