| 107 |
#include "clan.h" |
#include "clan.h" |
| 108 |
#include "common/setup_after.h" |
#include "common/setup_after.h" |
| 109 |
|
|
| 110 |
|
#ifndef CHAR_STATUS_DUMP_FILE |
| 111 |
|
# define CHAR_STATUS_DUMP_FILE "/tmp/d2charstatus.dat" |
| 112 |
|
#endif |
| 113 |
|
|
| 114 |
static char const * bnclass_get_str(unsigned int class); |
static char const * bnclass_get_str(unsigned int class); |
| 115 |
static void do_whisper(t_connection * user_c, char const * dest, char const * text); |
static void do_whisper(t_connection * user_c, char const * dest, char const * text); |
| 340 |
static int _handle_lusers_command(t_connection * c, char const * text); |
static int _handle_lusers_command(t_connection * c, char const * text); |
| 341 |
static int _handle_news_command(t_connection * c, char const * text); |
static int _handle_news_command(t_connection * c, char const * text); |
| 342 |
static int _handle_games_command(t_connection * c, char const * text); |
static int _handle_games_command(t_connection * c, char const * text); |
| 343 |
|
static int _handle_games_ext_command(t_connection * c, char const * text); |
| 344 |
static int _handle_channels_command(t_connection * c, char const * text); |
static int _handle_channels_command(t_connection * c, char const * text); |
| 345 |
static int _handle_addacct_command(t_connection * c, char const * text); |
static int _handle_addacct_command(t_connection * c, char const * text); |
| 346 |
static int _handle_chpass_command(t_connection * c, char const * text); |
static int _handle_chpass_command(t_connection * c, char const * text); |
| 373 |
static int _handle_topic_command(t_connection * c, char const * text); |
static int _handle_topic_command(t_connection * c, char const * text); |
| 374 |
static int _handle_moderate_command(t_connection * c, char const * text); |
static int _handle_moderate_command(t_connection * c, char const * text); |
| 375 |
static int _handle_clearstats_command(t_connection * c, char const * text); |
static int _handle_clearstats_command(t_connection * c, char const * text); |
| 376 |
|
static int _handle_char_status_command(t_connection * c, char const *text); |
| 377 |
|
|
| 378 |
static const t_command_table_row standard_command_table[] = |
static const t_command_table_row standard_command_table[] = |
| 379 |
{ |
{ |
| 419 |
{ "/kick" , _handle_kick_command }, |
{ "/kick" , _handle_kick_command }, |
| 420 |
{ "/ban" , _handle_ban_command }, |
{ "/ban" , _handle_ban_command }, |
| 421 |
{ "/unban" , _handle_unban_command }, |
{ "/unban" , _handle_unban_command }, |
| 422 |
|
{ "/charstatus" , _handle_char_status_command }, |
| 423 |
|
|
| 424 |
{ NULL , NULL } |
{ NULL , NULL } |
| 425 |
|
|
| 438 |
{ "/lusers" , _handle_lusers_command }, |
{ "/lusers" , _handle_lusers_command }, |
| 439 |
{ "/news" , _handle_news_command }, |
{ "/news" , _handle_news_command }, |
| 440 |
{ "/games" , _handle_games_command }, |
{ "/games" , _handle_games_command }, |
| 441 |
|
{ "/games_ext" , _handle_games_ext_command }, |
| 442 |
{ "/channels" , _handle_channels_command }, |
{ "/channels" , _handle_channels_command }, |
| 443 |
{ "/chs" , _handle_channels_command }, |
{ "/chs" , _handle_channels_command }, |
| 444 |
{ "/addacct" , _handle_addacct_command }, |
{ "/addacct" , _handle_addacct_command }, |
| 2754 |
{ |
{ |
| 2755 |
struct glist_cb_struct *cbdata = (struct glist_cb_struct*)data; |
struct glist_cb_struct *cbdata = (struct glist_cb_struct*)data; |
| 2756 |
|
|
| 2757 |
|
// Skip void game |
| 2758 |
|
if (game_get_ref(game) == 0) |
| 2759 |
|
return 0; |
| 2760 |
|
|
| 2761 |
if ((!cbdata->tag || !prefs_get_hide_pass_games() || game_get_flag(game) != game_flag_private) && |
if ((!cbdata->tag || !prefs_get_hide_pass_games() || game_get_flag(game) != game_flag_private) && |
| 2762 |
(!cbdata->tag || game_get_clienttag(game)==cbdata->tag) && |
(!cbdata->tag || game_get_clienttag(game)==cbdata->tag) && |
| 2763 |
(cbdata->diff==game_difficulty_none || game_get_difficulty(game)==cbdata->diff)) |
(cbdata->diff==game_difficulty_none || game_get_difficulty(game)==cbdata->diff)) |
| 4650 |
|
|
| 4651 |
return 0; |
return 0; |
| 4652 |
} |
} |
| 4653 |
|
|
| 4654 |
|
static int _glist_cb_ext(t_game *game, void *data) |
| 4655 |
|
{ |
| 4656 |
|
t_connection * owner_conn = NULL; |
| 4657 |
|
t_account * owner_account = NULL; |
| 4658 |
|
const char * owner_email = NULL; |
| 4659 |
|
|
| 4660 |
|
struct glist_cb_struct *cbdata = (struct glist_cb_struct*)data; |
| 4661 |
|
|
| 4662 |
|
// Skip void game |
| 4663 |
|
if (game_get_ref(game) == 0) |
| 4664 |
|
return 0; |
| 4665 |
|
|
| 4666 |
|
if (owner_conn = game_get_owner(game)) { |
| 4667 |
|
if (owner_account = conn_get_account(owner_conn)) { |
| 4668 |
|
owner_email = account_get_email(owner_account); |
| 4669 |
|
} |
| 4670 |
|
} |
| 4671 |
|
|
| 4672 |
|
sprintf(msgtemp," %-16.16s %-16.16s %1.1s %-8.8s %-21.21s %5u %-16.16s %-25.25s", |
| 4673 |
|
game_get_name(game), |
| 4674 |
|
game_get_pass(game), |
| 4675 |
|
game_get_flag(game) != game_flag_private ? "n":"y", |
| 4676 |
|
game_status_get_str(game_get_status(game)), |
| 4677 |
|
game_type_get_str(game_get_type(game)), |
| 4678 |
|
game_get_ref(game), |
| 4679 |
|
account_get_name(owner_account), |
| 4680 |
|
owner_email ? owner_email : "Unknown"); |
| 4681 |
|
|
| 4682 |
|
if (!cbdata->tag) |
| 4683 |
|
{ |
| 4684 |
|
|
| 4685 |
|
strcat(msgtemp,clienttag_uint_to_str(game_get_clienttag(game))); |
| 4686 |
|
strcat(msgtemp," "); |
| 4687 |
|
} |
| 4688 |
|
|
| 4689 |
|
strcat(msgtemp, addr_num_to_addr_str(game_get_addr(game),game_get_port(game))); |
| 4690 |
|
strcat(msgtemp, " "); |
| 4691 |
|
strcat(msgtemp, owner_email ? owner_email : "Unknown"); |
| 4692 |
|
|
| 4693 |
|
message_send_text(cbdata->c,message_type_info,cbdata->c,msgtemp); |
| 4694 |
|
|
| 4695 |
|
return 0; |
| 4696 |
|
} |
| 4697 |
|
|
| 4698 |
|
static int _handle_games_ext_command(t_connection * c, char const *text) |
| 4699 |
|
{ |
| 4700 |
|
unsigned int i; |
| 4701 |
|
unsigned int j; |
| 4702 |
|
char clienttag_str[5]; |
| 4703 |
|
char dest[5]; |
| 4704 |
|
struct glist_cb_struct cbdata; |
| 4705 |
|
|
| 4706 |
|
for (i=0; text[i]!=' ' && text[i]!='\0'; i++); /* skip command */ |
| 4707 |
|
for (; text[i]==' '; i++); |
| 4708 |
|
for (j=0; text[i]!=' ' && text[i]!='\0'; i++) /* get dest */ |
| 4709 |
|
if (j<sizeof(dest)-1) dest[j++] = text[i]; |
| 4710 |
|
dest[j] = '\0'; |
| 4711 |
|
for (; text[i]==' '; i++); |
| 4712 |
|
|
| 4713 |
|
cbdata.c = c; |
| 4714 |
|
|
| 4715 |
|
if(strcmp(&text[i],"norm")==0) |
| 4716 |
|
cbdata.diff = game_difficulty_normal; |
| 4717 |
|
else if(strcmp(&text[i],"night")==0) |
| 4718 |
|
cbdata.diff = game_difficulty_nightmare; |
| 4719 |
|
else if(strcmp(&text[i],"hell")==0) |
| 4720 |
|
cbdata.diff = game_difficulty_hell; |
| 4721 |
|
else |
| 4722 |
|
cbdata.diff = game_difficulty_none; |
| 4723 |
|
|
| 4724 |
|
if (dest[0]=='\0') |
| 4725 |
|
{ |
| 4726 |
|
cbdata.tag = conn_get_clienttag(c); |
| 4727 |
|
message_send_text(c,message_type_info,c,"Currently running games:"); |
| 4728 |
|
} |
| 4729 |
|
else if (strcasecmp(&dest[0],"all")==0) |
| 4730 |
|
{ |
| 4731 |
|
cbdata.tag = 0; |
| 4732 |
|
message_send_text(c,message_type_info,c,"All current games:"); |
| 4733 |
|
} |
| 4734 |
|
else |
| 4735 |
|
{ |
| 4736 |
|
cbdata.tag = tag_case_str_to_uint(&dest[0]); |
| 4737 |
|
|
| 4738 |
|
if (!tag_check_client(cbdata.tag)) |
| 4739 |
|
{ |
| 4740 |
|
message_send_text(c,message_type_error,c,"No valid clienttag specified."); |
| 4741 |
|
return -1; |
| 4742 |
|
} |
| 4743 |
|
|
| 4744 |
|
if(cbdata.diff==game_difficulty_none) |
| 4745 |
|
sprintf(msgtemp,"Current games of type %s",tag_uint_to_str(clienttag_str,cbdata.tag)); |
| 4746 |
|
else |
| 4747 |
|
sprintf(msgtemp,"Current games of type %s %s",tag_uint_to_str(clienttag_str,cbdata.tag),&text[i]); |
| 4748 |
|
message_send_text(c,message_type_info,c,msgtemp); |
| 4749 |
|
} |
| 4750 |
|
|
| 4751 |
|
sprintf(msgtemp," ------name------ ------pass------ p -status- --------type--------- count ---owner name--- --------owner email------- "); |
| 4752 |
|
if (!cbdata.tag) |
| 4753 |
|
strcat(msgtemp,"ctag "); |
| 4754 |
|
strcat(msgtemp,"--------addr--------"); |
| 4755 |
|
message_send_text(c,message_type_info,c,msgtemp); |
| 4756 |
|
gamelist_traverse(_glist_cb_ext,&cbdata); |
| 4757 |
|
|
| 4758 |
|
return 0; |
| 4759 |
|
} |
| 4760 |
|
|
| 4761 |
|
static int _handle_char_status_command(t_connection * c, char const *text) |
| 4762 |
|
{ |
| 4763 |
|
FILE * fp; |
| 4764 |
|
|
| 4765 |
|
if (!(fp = fopen(CHAR_STATUS_DUMP_FILE, "r"))) { |
| 4766 |
|
eventlog(eventlog_level_error, __FUNCTION__, "Can't read char status file %s", CHAR_STATUS_DUMP_FILE); |
| 4767 |
|
sprintf(msgtemp,"Can't read char status file."); |
| 4768 |
|
message_send_text(c,message_type_info,c,msgtemp); |
| 4769 |
|
} else { |
| 4770 |
|
while (fgets(msgtemp, MAX_MESSAGE_LEN, fp)) { |
| 4771 |
|
msgtemp[strlen(msgtemp) - 1] = '\0'; |
| 4772 |
|
message_send_text(c,message_type_info,c,msgtemp); |
| 4773 |
|
} |
| 4774 |
|
fclose(fp); |
| 4775 |
|
} |
| 4776 |
|
|
| 4777 |
|
return 0; |
| 4778 |
|
} |