command.c
上传用户:tany51
上传日期:2013-06-12
资源大小:1397k
文件大小:142k
- {
- char const * tname;
-
- sprintf(msgtemp,"%-.20s has been squelched.",(tname = account_get_name(account)));
- account_unget_name(tname);
- message_send_text(c,message_type_info,c,msgtemp);
- }
-
- return 0;
- }
- static int _handle_unsquelch_command(t_connection * c, char const *text)
- {
- t_account const * account;
- text = skip_command(text);
-
- /* D2 puts * before username - FIXME: the client don't see it until
- the player rejoins the channel */
- if (text[0]=='*')
- text++;
-
- if (text[0]==' ')
- {
- message_send_text(c,message_type_info,c,"usage: /unsquelch <username>");
- return 0;
- }
-
- if (!(account = accountlist_find_account(text)))
- {
- message_send_text(c,message_type_info,c,"No such user.");
- return 0;
- }
-
- if (conn_del_ignore(c,account)<0)
- message_send_text(c,message_type_info,c,"User was not being ignored.");
- else
- message_send_text(c,message_type_info,c,"No longer ignoring.");
-
- return 0;
- }
- static int _handle_kick_command(t_connection * c, char const *text)
- {
- char dest[USER_NAME_MAX];
- unsigned int i,j;
- t_channel const * channel;
- t_connection * kuc;
- t_account * acc;
-
- for (i=0; text[i]!=' ' && text[i]!=' '; i++); /* skip command */
- for (; text[i]==' '; i++);
- for (j=0; text[i]!=' ' && text[i]!=' '; i++) /* get dest */
- if (j<sizeof(dest)-1) dest[j++] = text[i];
- dest[j] = ' ';
- for (; text[i]==' '; i++);
-
- if (dest[0]==' ')
- {
- message_send_text(c,message_type_info,c,"usage: /kick <username>");
- return 0;
- }
-
- if (!(channel = conn_get_channel(c)))
- {
- message_send_text(c,message_type_error,c,"This command can only be used inside a channel.");
- return 0;
- }
- acc = conn_get_account(c);
- if (account_get_auth_admin(acc,NULL)!=1 && /* default to false */
- account_get_auth_admin(acc,channel_get_name(channel))!=1 && /* default to false */
- account_get_auth_operator(acc,NULL)!=1 && /* default to false */
- account_get_auth_operator(acc,channel_get_name(channel))!=1 && /* default to false */
- !channel_account_is_tmpOP(channel,acc))
- {
- message_send_text(c,message_type_error,c,"You have to be at least a Channel Operator or tempOP to use this command.");
- return 0;
- }
- if (!(kuc = connlist_find_connection_by_accountname(dest)))
- {
- message_send_text(c,message_type_error,c,"That user is not logged in.");
- return 0;
- }
- if (conn_get_channel(kuc)!=channel)
- {
- message_send_text(c,message_type_error,c,"That user is not in this channel.");
- return 0;
- }
- if (account_get_auth_admin(conn_get_account(kuc),NULL)==1 ||
- account_get_auth_admin(conn_get_account(kuc),channel_get_name(channel))==1)
- {
- message_send_text(c,message_type_error,c,"You cannot kick administrators.");
- return 0;
- }
- else if (account_get_auth_operator(conn_get_account(kuc),NULL)==1 ||
- account_get_auth_operator(conn_get_account(kuc),channel_get_name(channel))==1)
- {
- message_send_text(c,message_type_error,c,"You cannot kick operators.");
- return 0;
- }
-
- {
- char const * tname1;
- char const * tname2;
-
- tname1 = account_get_name(conn_get_account(kuc));
- tname2 = account_get_name(conn_get_account(c));
- if (text[i]!=' ')
- sprintf(msgtemp,"%-.20s has been kicked by %-.20s (%s).",tname1,tname2?tname2:"unknown",&text[i]);
- else
- sprintf(msgtemp,"%-.20s has been kicked by %-.20s.",tname1,tname2?tname2:"unknown");
- if (tname2)
- account_unget_name(tname2);
- if (tname1)
- account_unget_name(tname1);
- channel_message_send(channel,message_type_info,c,msgtemp);
- }
- conn_set_channel(kuc,CHANNEL_NAME_KICKED); /* should not fail */
-
- return 0;
- }
- static int _handle_ban_command(t_connection * c, char const *text)
- {
- char dest[USER_NAME_MAX];
- unsigned int i,j;
- t_channel * channel;
- t_connection * buc;
-
- for (i=0; text[i]!=' ' && text[i]!=' '; i++); /* skip command */
- for (; text[i]==' '; i++);
- for (j=0; text[i]!=' ' && text[i]!=' '; i++) /* get dest */
- if (j<sizeof(dest)-1) dest[j++] = text[i];
- dest[j] = ' ';
- for (; text[i]==' '; i++);
-
- if (dest[0]==' ')
- {
- message_send_text(c,message_type_info,c,"usage. /ban <username>");
- return 0;
- }
-
- if (!(channel = conn_get_channel(c)))
- {
- message_send_text(c,message_type_error,c,"This command can only be used inside a channel.");
- return 0;
- }
- if (account_get_auth_admin(conn_get_account(c),NULL)!=1 && /* default to false */
- account_get_auth_admin(conn_get_account(c),channel_get_name(channel))!=1 && /* default to false */
- account_get_auth_operator(conn_get_account(c),NULL)!=1 && /* default to false */
- account_get_auth_operator(conn_get_account(c),channel_get_name(channel))!=1) /* default to false */
- {
- message_send_text(c,message_type_error,c,"You have to be at least a Channel Operator to use this command.");
- return 0;
- }
- {
- t_account * account;
-
- if (!(account = accountlist_find_account(dest)))
- message_send_text(c,message_type_info,c,"That account doesn't currently exist, banning anyway.");
- else if (account_get_auth_admin(account,NULL)==1 || account_get_auth_admin(account,channel_get_name(channel))==1)
- {
- message_send_text(c,message_type_error,c,"You cannot ban administrators.");
- return 0;
- }
- else if (account_get_auth_operator(account,NULL)==1 ||
- account_get_auth_operator(account,channel_get_name(channel))==1)
- {
- message_send_text(c,message_type_error,c,"You cannot ban operators.");
- return 0;
- }
- }
-
- if (channel_ban_user(channel,dest)<0)
- {
- sprintf(msgtemp,"Unable to ban %-.20s.",dest);
- message_send_text(c,message_type_error,c,msgtemp);
- }
- else
- {
- char const * tname;
-
- tname = account_get_name(conn_get_account(c));
- if (text[i]!=' ')
- sprintf(msgtemp,"%-.20s has been banned by %-.20s (%s).",dest,tname?tname:"unknown",&text[i]);
- else
- sprintf(msgtemp,"%-.20s has been banned by %-.20s.",dest,tname?tname:"unknown");
- if (tname)
- account_unget_name(tname);
- channel_message_send(channel,message_type_info,c,msgtemp);
- }
- if ((buc = connlist_find_connection_by_accountname(dest)) &&
- conn_get_channel(buc)==channel)
- conn_set_channel(buc,CHANNEL_NAME_BANNED);
-
- return 0;
- }
- static int _handle_unban_command(t_connection * c, char const *text)
- {
- t_channel * channel;
- unsigned int i;
-
- for (i=0; text[i]!=' ' && text[i]!=' '; i++); /* skip command */
- for (; text[i]==' '; i++);
-
- if (text[i]==' ')
- {
- message_send_text(c,message_type_info,c,"usage: /unban <username>");
- return 0;
- }
-
- if (!(channel = conn_get_channel(c)))
- {
- message_send_text(c,message_type_error,c,"This command can only be used inside a channel.");
- return 0;
- }
- if (account_get_auth_admin(conn_get_account(c),NULL)!=1 && /* default to false */
- account_get_auth_admin(conn_get_account(c),channel_get_name(channel))!=1 && /* default to false */
- account_get_auth_operator(conn_get_account(c),NULL)!=1 && /* default to false */
- account_get_auth_operator(conn_get_account(c),channel_get_name(channel))!=1) /* default to false */
- {
- message_send_text(c,message_type_error,c,"You are not a channel operator.");
- return 0;
- }
-
- if (channel_unban_user(channel,&text[i])<0)
- message_send_text(c,message_type_error,c,"That user is not banned.");
- else
- {
- sprintf(msgtemp,"%s is no longer banned from this channel.",&text[i]);
- message_send_text(c,message_type_info,c,msgtemp);
- }
-
- return 0;
- }
- static int _handle_reply_command(t_connection * c, char const *text)
- {
- unsigned int i;
- char const * dest;
-
- if (!(dest = conn_get_lastsender(c)))
- {
- message_send_text(c,message_type_error,c,"No one messaged you, use /m instead");
- return 0;
- }
-
- for (i=0; text[i]!=' ' && text[i]!=' '; i++); /* skip command */
- for (; text[i]==' '; i++);
-
- if (text[i]==' ')
- {
- message_send_text(c,message_type_info,c,"usage: /reply <replytext>");
- return 0;
- }
- do_whisper(c,dest,&text[i]);
- return 0;
- }
- static int _handle_realmann_command(t_connection * c, char const *text)
- {
- unsigned int i;
- char const * realmname;
- char const * tname;
- t_connection * tc;
- t_elem const * curr;
- t_message * message;
-
- for (i=0; text[i]!=' ' && text[i]!=' '; i++); /* skip command */
- for (; text[i]==' '; i++);
-
- if (!(realmname=conn_get_realmname(c))) {
- message_send_text(c,message_type_info,c,"You must join a realm first");
- return 0;
- }
- if (text[i]==' ')
- {
- message_send_text(c,message_type_info,c,"usage: /realmann <announcement text>");
- return 0;
- }
-
- sprintf(msgtemp,"Announcement from %.32s@%.32s: %.128s",(tname = conn_get_username(c)),realmname,&text[i]);
- conn_unget_username(c,tname);
- if (!(message = message_create(message_type_broadcast,c,NULL,msgtemp)))
- {
- message_send_text(c,message_type_info,c,"Could not broadcast message.");
- }
- else
- {
- LIST_TRAVERSE_CONST(connlist(),curr)
- {
- tc = elem_get_data(curr);
- if (!tc)
- continue;
- if ((conn_get_realmname(tc))&&(strcasecmp(conn_get_realmname(tc),realmname)==0))
- {
- message_send(message,tc);
- }
- }
- }
- return 0;
- }
- static int _handle_watch_command(t_connection * c, char const *text)
- {
- unsigned int i;
- t_account * account;
-
- for (i=0; text[i]!=' ' && text[i]!=' '; i++); /* skip command */
- for (; text[i]==' '; i++);
-
- if (text[i]==' ')
- {
- message_send_text(c,message_type_info,c,"usage: /watch <username>");
- return 0;
- }
- if (!(account = accountlist_find_account(&text[i])))
- {
- message_send_text(c,message_type_info,c,"That user does not exist.");
- return 0;
- }
-
- if (conn_add_watch(c,account,NULL)<0) /* FIXME: adds all events for now */
- message_send_text(c,message_type_error,c,"Add to watch list failed.");
- else
- {
- sprintf(msgtemp,"User %.64s added to your watch list.",&text[i]);
- message_send_text(c,message_type_info,c,msgtemp);
- }
-
- return 0;
- }
- static int _handle_unwatch_command(t_connection * c, char const *text)
- {
- unsigned int i;
- t_account * account;
-
- for (i=0; text[i]!=' ' && text[i]!=' '; i++); /* skip command */
- for (; text[i]==' '; i++);
-
- if (text[i]==' ')
- {
- message_send_text(c,message_type_info,c,"usage: /unwatch <username>");
- return 0;
- }
- if (!(account = accountlist_find_account(&text[i])))
- {
- message_send_text(c,message_type_info,c,"That user does not exist.");
- return 0;
- }
-
- if (conn_del_watch(c,account,NULL)<0) /* FIXME: deletes all events for now */
- message_send_text(c,message_type_error,c,"Removal from watch list failed.");
- else
- {
- sprintf(msgtemp,"User %.64s removed from your watch list.",&text[i]);
- message_send_text(c,message_type_info,c,msgtemp);
- }
-
- return 0;
- }
- static int _handle_watchall_command(t_connection * c, char const *text)
- {
- char const * clienttag = NULL;
- text = skip_command(text);
- if(text[0] != ' ')
- clienttag = text;
- if (conn_add_watch(c,NULL,clienttag)<0) /* FIXME: adds all events for now */
- message_send_text(c,message_type_error,c,"Add to watch list failed.");
- else
- if(clienttag)
- {
- char msgtemp[MAX_MESSAGE_LEN];
- sprintf(msgtemp, "All %s users added to your watch list.", clienttag);
- message_send_text(c,message_type_info,c,msgtemp);
- }
- else
- message_send_text(c,message_type_info,c,"All users added to your watch list.");
- return 0;
- }
- static int _handle_unwatchall_command(t_connection * c, char const *text)
- {
- char const * clienttag = NULL;
- text = skip_command(text);
- if(text[0] != ' ')
- clienttag = text;
- if (conn_del_watch(c,NULL,clienttag)<0) /* FIXME: deletes all events for now */
- message_send_text(c,message_type_error,c,"Removal from watch list failed.");
- else
- if(clienttag)
- {
- char msgtemp[MAX_MESSAGE_LEN];
- sprintf(msgtemp, "All %s users removed from your watch list.", clienttag);
- message_send_text(c,message_type_info,c,msgtemp);
- }
- else
- message_send_text(c,message_type_info,c,"All users removed from your watch list.");
- return 0;
- }
- static int _handle_lusers_command(t_connection * c, char const *text)
- {
- t_channel * channel;
- t_elem const * curr;
- char const * banned;
- unsigned int i;
-
- if (!(channel = conn_get_channel(c)))
- {
- message_send_text(c,message_type_error,c,"This command can only be used inside a channel.");
- return 0;
- }
-
- strcpy(msgtemp,"Banned users:");
- i = strlen(msgtemp);
- LIST_TRAVERSE_CONST(channel_get_banlist(channel),curr)
- {
- banned = elem_get_data(curr);
- if (i+strlen(banned)+2>sizeof(msgtemp)) /* " ", name, ' ' */
- {
- message_send_text(c,message_type_info,c,msgtemp);
- i = 0;
- }
- sprintf(&msgtemp[i]," %s",banned);
- i += strlen(&msgtemp[i]);
- }
- if (i>0)
- message_send_text(c,message_type_info,c,msgtemp);
-
- return 0;
- }
- static int _handle_news_command(t_connection * c, char const *text)
- {
- if (newslist()) {
- t_news_index const *newsindex;
- t_elem const *curr;
- char date[64];
- char *body;
- struct tm *temp;
- time_t temp1;
- char *temp2;
- int i,j;
-
- LIST_TRAVERSE_CONST(newslist(),curr)
- {
- newsindex = elem_get_data(curr);
- temp1 = news_get_date(newsindex);
- temp = localtime(&temp1);
- strftime(date, 64,"%B %d, %Y", temp);
- message_send_text(c,message_type_info,c,date);
- if ((body = news_get_body(newsindex)))
- {
- for (i=0; body[i] != ' '; i++) {
- temp2 = strdup(&body[i]);
- for (j=0; (temp2[j] != 'n')&&(temp2[j] != ' '); j++);
- temp2[j] = ' ';
- message_send_text(c,message_type_info,c,temp2);
- free((void *)temp2);
- i = i+j;
- }
- }
- }
- } else
- message_send_text(c,message_type_info,c,"No news today.");
- return 0;
- }
- static int _handle_games_command(t_connection * c, char const *text)
- {
- unsigned int i;
- t_elem const * curr;
- t_game const * game;
- char const * tag;
-
- for (i=0; text[i]!=' ' && text[i]!=' '; i++); /* skip command */
- for (; text[i]==' '; i++);
-
- if (text[i]==' ')
- {
- tag = conn_get_clienttag(c);
- message_send_text(c,message_type_info,c,"Currently accessable games:");
- }
- else if (strcmp(&text[i],"all")==0)
- {
- tag = NULL;
- message_send_text(c,message_type_info,c,"All current games:");
- }
- else
- {
- tag = &text[i];
- sprintf(msgtemp,"Current games of type %s",tag);
- message_send_text(c,message_type_info,c,msgtemp);
- }
-
- if (prefs_get_hide_addr() && !(account_get_command_groups(conn_get_account(c)) & command_get_group("/admin-addr"))) /* default to false */
- sprintf(msgtemp," ------name------ p -status- --------type--------- count");
- else
- sprintf(msgtemp," ------name------ p -status- --------type--------- count --------addr--------");
- message_send_text(c,message_type_info,c,msgtemp);
- LIST_TRAVERSE_CONST(gamelist(),curr)
- {
- game = elem_get_data(curr);
- if ((!tag || !prefs_get_hide_pass_games() || game_get_flag(game) != game_flag_private) &&
- (!tag || strcasecmp(game_get_clienttag(game),tag)==0))
- {
- if (prefs_get_hide_addr() && !(account_get_command_groups(conn_get_account(c)) & command_get_group("/admin-addr"))) /* default to false */
- sprintf(msgtemp," %-16.16s %1.1s %-8.8s %-21.21s %5u",
- game_get_name(game),
- game_get_flag(game) != game_flag_private ? "n":"y",
- game_status_get_str(game_get_status(game)),
- game_type_get_str(game_get_type(game)),
- game_get_ref(game));
- else
- sprintf(msgtemp," %-16.16s %1.1s %-8.8s %-21.21s %5u %s",
- game_get_name(game),
- game_get_flag(game) != game_flag_private ? "n":"y",
- game_status_get_str(game_get_status(game)),
- game_type_get_str(game_get_type(game)),
- game_get_ref(game),
- addr_num_to_addr_str(game_get_addr(game),game_get_port(game)));
- message_send_text(c,message_type_info,c,msgtemp);
- }
- }
-
- return 0;
- }
- static int _handle_channels_command(t_connection * c, char const *text)
- {
- unsigned int i;
- t_elem const * curr;
- t_channel const * channel;
- char const * tag;
- t_connection const * conn;
- t_account * acc;
- char const * name;
- int first;
-
- for (i=0; text[i]!=' ' && text[i]!=' '; i++); /* skip command */
- for (; text[i]==' '; i++);
-
- if (text[i]==' ')
- {
- tag = conn_get_clienttag(c);
- message_send_text(c,message_type_info,c,"Currently accessable channels:");
- }
- else if (strcmp(&text[i],"all")==0)
- {
- tag = NULL;
- message_send_text(c,message_type_info,c,"All current channels:");
- }
- else
- {
- tag = &text[i];
- sprintf(msgtemp,"Current channels of type %s",tag);
- message_send_text(c,message_type_info,c,msgtemp);
- }
-
- sprintf(msgtemp," -----------name----------- users ----admin/operator----");
- message_send_text(c,message_type_info,c,msgtemp);
- LIST_TRAVERSE_CONST(channellist(),curr)
- {
- channel = elem_get_data(curr);
- if ((!(channel_get_flags(channel) & channel_flags_clan)) && (!tag || !prefs_get_hide_temp_channels() || channel_get_permanent(channel)) &&
- (!tag || !channel_get_clienttag(channel) ||
- strcasecmp(channel_get_clienttag(channel),tag)==0) &&
- ((channel_get_max(channel)!=0) || //only show restricted channels to OPs and Admins
- ((channel_get_max(channel)==0 && account_is_operator_or_admin(conn_get_account(c),NULL)))) &&
- (!(channel_get_flags(channel) & channel_flags_thevoid)) // don't list TheVoid
- )
- {
- sprintf(msgtemp," %-26.26s %5u - ",
- channel_get_name(channel),
- channel_get_length(channel));
- first = 1;
- for (conn = channel_get_first(channel);conn;conn=channel_get_next())
- {
- acc = conn_get_account(conn);
- if (account_is_operator_or_admin(acc,channel_get_name(channel)) ||
- channel_account_is_tmpOP(channel,acc))
- {
- name = account_get_name(acc);
- if (strlen(msgtemp) + strlen(name) +6 >= MAX_MESSAGE_LEN) break;
- if (!first) strcat(msgtemp," ,");
- strcat(msgtemp,name);
- account_unget_name(name);
- if (account_get_auth_admin(acc,NULL)==1) strcat(msgtemp,"(A)");
- else if (account_get_auth_operator(acc,NULL)==1) strcat(msgtemp,"(O)");
- else if (account_get_auth_admin(acc,channel_get_name(channel))==1) strcat(msgtemp,"(a)");
- else if (account_get_auth_operator(acc,channel_get_name(channel))==1) strcat(msgtemp,"(o)");
- first = 0;
- }
- }
- message_send_text(c,message_type_info,c,msgtemp);
- }
- }
-
- return 0;
- }
- static int _handle_addacct_command(t_connection * c, char const *text)
- {
- unsigned int i,j;
- t_account * temp;
- t_hash passhash;
- char username[USER_NAME_MAX];
- char pass[256];
-
- for (i=0; text[i]!=' ' && text[i]!=' '; i++);
- for (; text[i]==' '; i++);
-
- for (j=0; text[i]!=' ' && text[i]!=' '; i++) /* get username */
- if (j<sizeof(username)-1) username[j++] = text[i];
- username[j] = ' ';
-
- for (; text[i]==' '; i++); /* skip spaces */
- for (j=0; text[i]!=' '; i++) /* get pass (spaces are allowed) */
- if (j<sizeof(pass)-1) pass[j++] = text[i];
- pass[j] = ' ';
-
- if (username[0]==' ' || pass[0]==' ')
- {
- message_send_text(c,message_type_info,c,"usage: /addacct <username> <password>");
- return 0;
- }
-
- if (account_check_name(username)<0)
- {
- message_send_text(c,message_type_error,c,"Account name contains some invalid symbol!");
- return 0;
- }
- /* FIXME: truncate or err on too long password */
- for (i=0; i<strlen(pass); i++)
- if (isupper((int)pass[i])) pass[i] = tolower((int)pass[i]);
-
- bnet_hash(&passhash,strlen(pass),pass);
-
- sprintf(msgtemp,"Trying to add account "%s" with password "%s"",username,pass);
- message_send_text(c,message_type_info,c,msgtemp);
-
- sprintf(msgtemp,"Hash is: %s",hash_get_str(passhash));
- message_send_text(c,message_type_info,c,msgtemp);
-
- if (!(temp = account_create(username,hash_get_str(passhash))))
- {
- message_send_text(c,message_type_error,c,"Failed to create account!");
- eventlog(eventlog_level_info,"handle_command","[%d] account "%s" not created by admin (failed)",conn_get_socket(c),username);
- return 0;
- }
- if (!accountlist_add_account(temp))
- {
- account_destroy(temp);
- message_send_text(c,message_type_error,c,"Failed to insert account (already exists?)!");
- eventlog(eventlog_level_info,"handle_command","[%d] account "%s" could not be created by admin (insert failed)",conn_get_socket(c),username);
- }
- else
- {
- sprintf(msgtemp,"Account "UID_FORMAT" created.",account_get_uid(temp));
- message_send_text(c,message_type_info,c,msgtemp);
- eventlog(eventlog_level_info,"handle_command","[%d] account "%s" created by admin",conn_get_socket(c),username);
- }
- return 0;
- }
- static int _handle_chpass_command(t_connection * c, char const *text)
- {
- unsigned int i,j;
- t_account * account;
- t_account * temp;
- t_hash passhash;
- char arg1[256];
- char arg2[256];
- char const * username;
- char * pass;
- char const * channel;
-
- for (i=0; text[i]!=' ' && text[i]!=' '; i++);
- for (; text[i]==' '; i++);
-
- for (j=0; text[i]!=' ' && text[i]!=' '; i++) /* get username/pass */
- if (j<sizeof(arg1)-1) arg1[j++] = text[i];
- arg1[j] = ' ';
-
- for (; text[i]==' '; i++); /* skip spaces */
- for (j=0; text[i]!=' '; i++) /* get pass (spaces are allowed) */
- if (j<sizeof(arg2)-1) arg2[j++] = text[i];
- arg2[j] = ' ';
-
- if (arg2[0]==' ')
- {
- username = conn_get_username(c);
- pass = arg1;
- }
- else
- {
- username = arg1;
- pass = arg2;
- }
-
- if (pass[0]==' ')
- {
- message_send_text(c,message_type_info,c,"usage: /chpass [username] <password>");
- return 0;
- }
- temp = accountlist_find_account(username);
- account = conn_get_account(c);
-
- if ((temp==account && account_get_auth_changepass(account)==0) || /* default to true */
- (temp!=account && !(account_get_command_groups(conn_get_account(c)) & command_get_group("/admin-chpass")))) /* default to false */
- {
- eventlog(eventlog_level_info,"handle_command","[%d] password change for "%s" refused (no change access)",conn_get_socket(c),username);
- if (username!=arg1)
- conn_unget_username(c,username);
- message_send_text(c,message_type_error,c,"Only admins may change passwords for other accounts.");
- return 0;
- }
- if (!temp)
- {
- message_send_text(c,message_type_error,c,"Account does not exist.");
- if (username!=arg1)
- conn_unget_username(c,username);
- return 0;
- }
-
- /* FIXME: truncate or err on too long password */
- for (i=0; i<strlen(pass); i++)
- if (isupper((int)pass[i])) pass[i] = tolower((int)pass[i]);
-
- bnet_hash(&passhash,strlen(pass),pass);
-
- sprintf(msgtemp,"Trying to change password for account "%s" to "%s"",username,pass);
- message_send_text(c,message_type_info,c,msgtemp);
-
- if (username!=arg1)
- conn_unget_username(c,username);
-
- if (account_set_pass(temp,hash_get_str(passhash))<0)
- {
- message_send_text(c,message_type_error,c,"Unable to set password.");
- return 0;
- }
-
- channel = channel_get_name(conn_get_channel(c));
- if (account_get_auth_admin(account,channel) == 1 ||
- account_get_auth_admin(account,NULL) == 1 ||
- account_get_auth_operator(account,channel) == 1 ||
- account_get_auth_operator(account,NULL) == 1) {
- sprintf(msgtemp,
- "Password for account "UID_FORMAT" updated.",account_get_uid(temp));
- message_send_text(c,message_type_info,c,msgtemp);
- sprintf(msgtemp,"Hash is: %s",hash_get_str(passhash));
- message_send_text(c,message_type_info,c,msgtemp);
- } else {
- sprintf(msgtemp,
- "Password for account %s updated.",username);
- message_send_text(c,message_type_info,c,msgtemp);
- }
-
- return 0;
- }
- static int _handle_connections_command(t_connection *c, char const *text)
- {
- t_elem const * curr;
- t_connection * conn;
- char name[19];
- unsigned int i; /* for loop */
- char const * channel_name;
- char const * game_name;
-
- if (!prefs_get_enable_conn_all() && !(account_get_command_groups(conn_get_account(c)) & command_get_group("/admin-con"))) /* default to false */
- {
- message_send_text(c,message_type_error,c,"This command is only enabled for admins.");
- return 0;
- }
-
- message_send_text(c,message_type_info,c,"Current connections:");
- /* addon */
- for (i=0; text[i]!=' ' && text[i]!=' '; i++); /* skip command */
- for (; text[i]==' '; i++);
-
- if (text[i]==' ')
- {
- sprintf(msgtemp," -class -tag -----name------ -lat(ms)- ----channel---- --game--");
- message_send_text(c,message_type_info,c,msgtemp);
- }
- else
- if (strcmp(&text[i],"all")==0) /* print extended info */
- {
- if (prefs_get_hide_addr() && !(account_get_command_groups(conn_get_account(c)) & command_get_group("/admin-addr")))
- sprintf(msgtemp," -#- -class ----state--- -tag -----name------ -session-- -flag- -lat(ms)- ----channel---- --game--");
- else
- sprintf(msgtemp," -#- -class ----state--- -tag -----name------ -session-- -flag- -lat(ms)- ----channel---- --game-- ---------addr--------");
- message_send_text(c,message_type_info,c,msgtemp);
- }
- else
- {
- message_send_text(c,message_type_error,c,"Unknown option.");
- return 0;
- }
-
- LIST_TRAVERSE_CONST(connlist(),curr)
- {
- conn = elem_get_data(curr);
- if (conn_get_account(conn))
- {
- char const * tname;
-
- sprintf(name,""%.16s"",(tname = conn_get_username(conn)));
- conn_unget_username(conn,tname);
- }
- else
- strcpy(name,"(none)");
-
- if (conn_get_channel(conn)!=NULL)
- channel_name = channel_get_name(conn_get_channel(conn));
- else channel_name = "none";
- if (conn_get_game(conn)!=NULL)
- game_name = game_get_name(conn_get_game(conn));
- else game_name = "none";
-
- if (text[i]==' ')
- sprintf(msgtemp," %-6.6s %4.4s %-15.15s %9u %-16.16s %-8.8s",
- conn_class_get_str(conn_get_class(conn)),
- conn_get_fake_clienttag(conn),
- name,
- conn_get_latency(conn),
- channel_name,
- game_name);
- else
- if (prefs_get_hide_addr() && !(account_get_command_groups(conn_get_account(c)) & command_get_group("/admin-addr"))) /* default to false */
- sprintf(msgtemp," %3d %-6.6s %-12.12s %4.4s %-15.15s 0x%08x 0x%04x %9u %-16.16s %-8.8s",
- conn_get_socket(conn),
- conn_class_get_str(conn_get_class(conn)),
- conn_state_get_str(conn_get_state(conn)),
- conn_get_fake_clienttag(conn),
- name,
- conn_get_sessionkey(conn),
- conn_get_flags(conn),
- conn_get_latency(conn),
- channel_name,
- game_name);
- else
- sprintf(msgtemp," %3u %-6.6s %-12.12s %4.4s %-15.15s 0x%08x 0x%04x %9u %-16.16s %-8.8s %s",
- conn_get_socket(conn),
- conn_class_get_str(conn_get_class(conn)),
- conn_state_get_str(conn_get_state(conn)),
- conn_get_fake_clienttag(conn),
- name,
- conn_get_sessionkey(conn),
- conn_get_flags(conn),
- conn_get_latency(conn),
- channel_name,
- game_name,
- addr_num_to_addr_str(conn_get_addr(conn),conn_get_port(conn)));
-
- message_send_text(c,message_type_info,c,msgtemp);
- }
-
- return 0;
- }
- static int _handle_finger_command(t_connection * c, char const *text)
- {
- char dest[USER_NAME_MAX];
- unsigned int i,j;
- t_account * account;
- t_connection * conn;
- char const * ip;
- char * tok;
- char const * tname;
- char const * tsex;
- char const * tloc;
- char const * tage;
- char const * tip;
- char const * tdesc;
-
- for (i=0; text[i]!=' ' && text[i]!=' '; i++); /* skip command */
- for (; text[i]==' '; i++);
- for (j=0; text[i]!=' ' && text[i]!=' '; i++) /* get dest */
- if (j<sizeof(dest)-1) dest[j++] = text[i];
- dest[j] = ' ';
- for (; text[i]==' '; i++);
- if (dest[0]==' ')
- {
- message_send_text(c,message_type_info,c,"usage: /finger <account>");
- return 0;
- }
-
- if (!(account = accountlist_find_account(dest)))
- {
- message_send_text(c,message_type_error,c,"Invalid user.");
- return 0;
- }
- sprintf(msgtemp,"Login: %-16.16s "UID_FORMAT" Sex: %.14s",
- (tname = account_get_name(account)),
- account_get_uid(account),
- (tsex = account_get_sex(account)));
- account_unget_name(tname);
- account_unget_sex(tsex);
- message_send_text(c,message_type_info,c,msgtemp);
-
- sprintf(msgtemp,"Location: %-23.23s Age: %.14s",
- (tloc = account_get_loc(account)),
- (tage = account_get_age(account)));
- account_unget_loc(tloc);
- account_unget_age(tage);
- message_send_text(c,message_type_info,c,msgtemp);
-
- if (!(ip=tip = account_get_ll_ip(account)) ||
- !(account_get_command_groups(conn_get_account(c)) & command_get_group("/admin-addr"))) /* default to false */
- ip = "unknown";
-
- {
- time_t then;
- struct tm * tmthen;
-
- then = account_get_ll_time(account);
- tmthen = localtime(&then); /* FIXME: determine user's timezone */
- if (!(conn = connlist_find_connection_by_accountname(dest)))
- if (tmthen)
- strftime(msgtemp,sizeof(msgtemp),"Last login %a %b %d %H:%M %Y from ",tmthen);
- else
- strcpy(msgtemp,"Last login ? from ");
- else
- if (tmthen)
- strftime(msgtemp,sizeof(msgtemp),"On since %a %b %d %H:%M %Y from ",tmthen);
- else
- strcpy(msgtemp,"On since ? from ");
- }
- strncat(msgtemp,ip,32);
- if (tip)
- account_unget_ll_ip(tip);
-
- message_send_text(c,message_type_info,c,msgtemp);
-
- if (conn)
- {
- sprintf(msgtemp,"Idle %s",seconds_to_timestr(conn_get_idletime(conn)));
- message_send_text(c,message_type_info,c,msgtemp);
- }
-
- strncpy(msgtemp,(tdesc = account_get_desc(account)),sizeof(msgtemp));
- msgtemp[sizeof(msgtemp)-1] = ' ';
- account_unget_desc(tdesc);
- for (tok=strtok(msgtemp,"rn"); tok; tok=strtok(NULL,"rn"))
- message_send_text(c,message_type_info,c,tok);
- message_send_text(c,message_type_info,c,"");
-
- return 0;
- }
- /*
- * rewrote command /operator to add and remove operator status [Omega]
- *
- * Fixme: rewrite /operators to show Currently logged on Server and/or Channel operators ...??
- */
- /*
- static int _handle_operator_command(t_connection * c, char const *text)
- {
- t_connection const * opr;
- t_channel const * channel;
-
- if (!(channel = conn_get_channel(c)))
- {
- message_send_text(c,message_type_error,c,"This command can only be used inside a channel.");
- return 0;
- }
-
- if (!(opr = channel_get_operator(channel)))
- strcpy(msgtemp,"There is no operator.");
- else
- {
- char const * tname;
-
- sprintf(msgtemp,"%.64s is the operator.",(tname = conn_get_username(opr)));
- conn_unget_username(opr,tname);
- }
- message_send_text(c,message_type_info,c,msgtemp);
- return 0;
- }
- */
- /* FIXME: do we want to show just Server Admin or Channel Admin Also? [Omega] */
- static int _handle_admins_command(t_connection * c, char const *text)
- {
- unsigned int i;
- t_elem const * curr;
- t_connection * tc;
- char const * nick;
-
- strcpy(msgtemp,"Currently logged on Administrators:");
- i = strlen(msgtemp);
- LIST_TRAVERSE_CONST(connlist(),curr)
- {
- tc = elem_get_data(curr);
- if (!tc)
- continue;
- if (account_get_auth_admin(conn_get_account(tc),NULL)==1)
- {
- if ((nick = conn_get_username(tc)))
- {
- if (i+strlen(nick)+2>sizeof(msgtemp)) /* " ", name, ' ' */
- {
- message_send_text(c,message_type_info,c,msgtemp);
- i = 0;
- }
- sprintf(&msgtemp[i]," %s", nick);
- i += strlen(&msgtemp[i]);
- conn_unget_username(tc,nick);
- }
- }
- }
- if (i>0)
- message_send_text(c,message_type_info,c,msgtemp);
-
- return 0;
- }
- static int _handle_quit_command(t_connection * c, char const *text)
- {
- message_send_text(c,message_type_info,c,"Connection closed.");
- conn_set_state(c,conn_state_destroy);
- return 0;
- }
- static int _handle_kill_command(t_connection * c, char const *text)
- {
- unsigned int i,j;
- t_connection * user;
- char usrnick[USER_NAME_MAX]; /* max length of nick +