extern char const * check_mail(t_connection const * c) { t_account * user; t_mailbox * mailbox; static char tmp[64]; int count; if (!(c)) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return ""; } if (!(user=conn_get_account(c))) return ""; mailbox=mailbox_open(user, mbox_mode_read); count = mailbox_count(mailbox); mailbox_close(mailbox); if (count == 0) { return "You have no mail."; } else { sprintf(tmp,"You have %d message(s) in your mailbox.",count); return tmp; } }
static int _client_anongame_set_icon(t_connection * c, t_packet const * const packet) { //BlacKDicK 04/20/2003 unsigned int desired_icon; char user_icon[5]; /*FIXME: In this case we do not get a 'count' but insted of it we get the icon that the client wants to set.'W3H2' for an example. For now it is ok, since they share the same position on the packet*/ desired_icon=bn_int_get(packet->u.client_findanongame.count); user_icon[4]=0; if (desired_icon==0){ std::strcpy(user_icon,"NULL"); eventlog(eventlog_level_info,__FUNCTION__,"[%d] Set icon packet to DEFAULT ICON [%4.4s]",conn_get_socket(c),user_icon); }else{ std::memcpy(user_icon,&desired_icon,4); eventlog(eventlog_level_info,__FUNCTION__,"[%d] Set icon packet to ICON [%s]",conn_get_socket(c),user_icon); } account_set_user_icon(conn_get_account(c),conn_get_clienttag(c),user_icon); //FIXME: Still need a way to 'refresh the user/channel' //_handle_rejoin_command(conn_get_account(c),""); /* ??? channel_update_userflags() */ conn_update_w3_playerinfo(c); channel_rejoin(c); return 0; }
static void mail_func_delete(t_connection * c, std::istream& istr) { if (!c) { ERROR0("got NULL connection"); return; } std::string token; istr >> token; if (token.empty()) { message_send_text(c,message_type_error,c,"Please specify which message to delete. Use the following syntax: /mail delete {<index>|all} ."); return; } t_account * user = conn_get_account(c); Mailbox mbox(account_get_uid(user)); if (token == "all") { mbox.clear(); message_send_text(c, message_type_info, c, "Successfully deleted messages."); } else { if (std::find_if(token.begin(), token.end(), NonNumericChar) != token.end()) { message_send_text(c,message_type_error,c,"Invalid index. Please use /mail delete {<index>|all} where <index> is a number."); return; } mbox.erase(std::atoi(token.c_str())); message_send_text(c,message_type_info,c, "Succesfully deleted message."); } }
/* Choose icon by user from profile > portrait */ static int _client_anongame_set_icon(t_connection * c, t_packet const * const packet) { //BlacKDicK 04/20/2003 // Modified by aancw 16/12/2014 unsigned int desired_icon; char user_icon[5]; t_account * account; // disable with custom icons if (prefs_get_custom_icons() == 1) { return 0; } /*FIXME: In this case we do not get a 'count' but insted of it we get the icon that the client wants to set.'W3H2' for an example. For now it is ok, since they share the same position on the packet*/ desired_icon = bn_int_get(packet->u.client_findanongame.count); //user_icon[4]=0; if (desired_icon == 0){ std::strcpy(user_icon, "1O3W"); // 103W is equal to Default Icon eventlog(eventlog_level_info, __FUNCTION__, "[%d] Set icon packet to DEFAULT ICON [%4.4s]", conn_get_socket(c), user_icon); } else{ std::memcpy(user_icon, &desired_icon, 4); eventlog(eventlog_level_info, __FUNCTION__, "[%d] Set icon packet to ICON [%s]", conn_get_socket(c), user_icon); } account = conn_get_account(c); // ICON SWITCH HACK PROTECTION if (check_user_icon(account, user_icon) == 0) { std::strcpy(user_icon, "1O3W"); // set icon to default eventlog(eventlog_level_info, __FUNCTION__, "[%s] \"%s\" ICON SWITCH hack attempt, icon set to default ", conn_get_username(c), user_icon); //conn_set_state(c,conn_state_destroy); // dont kill user session } account_set_user_icon(conn_get_account(c), conn_get_clienttag(c), user_icon); //FIXME: Still need a way to 'refresh the user/channel' //_handle_rejoin_command(conn_get_account(c),""); /* ??? channel_update_userflags() */ conn_update_w3_playerinfo(c); channel_rejoin(c); return 0; }
extern unsigned check_mail(t_connection const * c) { if (!c) { ERROR0("got NULL connection"); return 0; } return Mailbox(account_get_uid(conn_get_account(c))).size(); }
static int list_commands(t_connection * c) { char * line; int i; message_send_text(c, message_type_info, c, "Chat commands:"); std::rewind(hfd); while ((line = file_get_line(hfd)) != NULL) { for (i = 0; line[i] == ' ' && line[i] != '\0'; i++); /* skip spaces in front of %command */ if (line[i] == '%') /* is this a command ? */ { char *p, *buffer; int al; int skip; unsigned int length, position; /* ok. now we must see if there are any aliases */ length = MAX_COMMAND_LEN + 1; position = 0; buffer = (char*)xmalloc(length + 1); /* initial memory allocation = pretty fair */ p = line + i; do { al = 0; skip = 0; for (i = 1; p[i] != ' ' && p[i] != '\0' && p[i] != '#'; i++); /* skip command */ if (p[i] == ' ') al = 1; /* we have something after the command.. must remember that */ p[i] = '\0'; /* end the string at the end of the command */ p[0] = '/'; /* change the leading character (% or space) read from the help file to / */ if (!(command_get_group(p) & account_get_command_groups(conn_get_account(c)))) skip = 1; if (length < std::strlen(p) + position + 1) /* if we don't have enough space in the buffer then get some */ length = std::strlen(p) + position + 1; /* the new length */ buffer = (char*)xrealloc(buffer, length + 1); buffer[position++] = ' '; /* put a space before each alias */ /* add the alias to the output string */ std::strcpy(buffer + position, p); position += std::strlen(p); if (al) { for (; p[i + 1] == ' ' && p[i + 1] != '\0' && p[i + 1] != '#'; i++); /* skip spaces */ if (p[i + 1] == '\0' || p[i + 1] == '#') { al = 0; continue; } p += i; /* jump to the next command */ } } while (al); if (!skip) message_send_text(c, message_type_info, c, buffer); /* print out the buffer */ xfree(buffer); } } file_get_line(NULL); // clear file_get_line buffer 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 handle_anongame_search(t_connection * c, t_packet const *packet) { if (account_get_auth_ladderban(conn_get_account(c))==1) { message_send_text(c,message_type_error,c,"Sorry, the following option is no longer available for your account."); return _client_anongame_cancel(c); } if (conn_get_latency(c) > 300) //todo: pick not allowed ping { message_send_text(c,message_type_error,c,"Your ping is too high, Please try again later."); return _client_anongame_cancel(c); } return _handle_anongame_search(c, packet); }
extern void guiOnUpdateUserList() { t_connection * c; t_elem const * curr; t_account * acc; char UserCount[80]; SendMessage(gui.hwndUsers, LB_RESETCONTENT, 0, 0); LIST_TRAVERSE_CONST(connlist(), curr) { if (!(c = (t_connection *)elem_get_data(curr))) continue; if (!(acc = conn_get_account(c))) continue; SendMessage(gui.hwndUsers, LB_ADDSTRING, 0, (LPARAM)account_get_name(acc)); } sprintf(UserCount, "%d", connlist_login_get_length()); strcat(UserCount, " user(s) online:"); SendMessage(gui.hwndUserCount, WM_SETTEXT, 0, (LPARAM)UserCount); }
/* tournament notice disabled at this time, but responce is sent to cleint */ static int _client_anongame_tournament(t_connection * c, t_packet const * const packet) { t_packet * rpacket; t_account * account = conn_get_account(c); t_clienttag clienttag = conn_get_clienttag(c); unsigned int start_prelim = tournament_get_start_preliminary(); unsigned int end_signup = tournament_get_end_signup(); unsigned int end_prelim = tournament_get_end_preliminary(); unsigned int start_r1 = tournament_get_start_round_1(); if ((rpacket = packet_create(packet_class_bnet)) == NULL) { eventlog(eventlog_level_error, __FUNCTION__, "could not create new packet"); return -1; } packet_set_size(rpacket, sizeof(t_server_anongame_tournament_reply)); packet_set_type(rpacket, SERVER_FINDANONGAME_TOURNAMENT_REPLY); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.option, 7); bn_int_set(&rpacket->u.server_anongame_tournament_reply.count, bn_int_get(packet->u.client_anongame_tournament_request.count)); if (!start_prelim || (end_signup <= now && tournament_user_signed_up(account) < 0) || tournament_check_client(clienttag) < 0) { /* No Tournament Notice */ bn_byte_set(&rpacket->u.server_anongame_tournament_reply.type, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown, 0); bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown4, 0); bn_int_set(&rpacket->u.server_anongame_tournament_reply.timestamp, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown5, 0); bn_short_set(&rpacket->u.server_anongame_tournament_reply.countdown, 0); bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown2, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.wins, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.losses, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.ties, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown3, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.selection, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.descnum, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.nulltag, 0); } else if (start_prelim >= now) { /* Tournament Notice */ bn_byte_set(&rpacket->u.server_anongame_tournament_reply.type, 1); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown, 0); bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown4, 0x0000); /* random */ bn_int_set(&rpacket->u.server_anongame_tournament_reply.timestamp, _tournament_time_convert(start_prelim)); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown5, 0x01); bn_short_set(&rpacket->u.server_anongame_tournament_reply.countdown, start_prelim - now); bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown2, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.wins, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.losses, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.ties, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown3, 0x00); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.selection, 2); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.descnum, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.nulltag, 0); } else if (end_signup >= now) { /* Tournament Signup Notice - Play Game Active */ bn_byte_set(&rpacket->u.server_anongame_tournament_reply.type, 2); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown, 0); bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown4, 0x0828); /* random */ bn_int_set(&rpacket->u.server_anongame_tournament_reply.timestamp, _tournament_time_convert(end_signup)); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown5, 0x01); bn_short_set(&rpacket->u.server_anongame_tournament_reply.countdown, end_signup - now); bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown2, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.wins, tournament_get_stat(account, 1)); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.losses, tournament_get_stat(account, 2)); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.ties, tournament_get_stat(account, 3)); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown3, 0x08); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.selection, 2); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.descnum, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.nulltag, 0); } else if (end_prelim >= now) { /* Tournament Prelim Period - Play Game Active */ bn_byte_set(&rpacket->u.server_anongame_tournament_reply.type, 3); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown, 0); bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown4, 0x0828); /* random */ bn_int_set(&rpacket->u.server_anongame_tournament_reply.timestamp, _tournament_time_convert(end_prelim)); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown5, 0x01); bn_short_set(&rpacket->u.server_anongame_tournament_reply.countdown, end_prelim - now); bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown2, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.wins, tournament_get_stat(account, 1)); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.losses, tournament_get_stat(account, 2)); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.ties, tournament_get_stat(account, 3)); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown3, 0x08); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.selection, 2); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.descnum, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.nulltag, 0); } else if (start_r1 >= now && (tournament_get_game_in_progress())) { /* Prelim Period Over - Shows user stats (not all prelim games finished) */ bn_byte_set(&rpacket->u.server_anongame_tournament_reply.type, 4); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown, 0); bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown4, 0x0000); /* random */ bn_int_set(&rpacket->u.server_anongame_tournament_reply.timestamp, _tournament_time_convert(start_r1)); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown5, 0x01); bn_short_set(&rpacket->u.server_anongame_tournament_reply.countdown, start_r1 - now); bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown2, 0); /* 00 00 */ bn_byte_set(&rpacket->u.server_anongame_tournament_reply.wins, tournament_get_stat(account, 1)); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.losses, tournament_get_stat(account, 2)); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.ties, tournament_get_stat(account, 3)); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown3, 0x08); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.selection, 2); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.descnum, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.nulltag, 0); } else if (!(tournament_get_in_finals_status(account))) { /* Prelim Period Over - user did not make finals - Shows user stats */ bn_byte_set(&rpacket->u.server_anongame_tournament_reply.type, 5); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown, 0); bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown4, 0); bn_int_set(&rpacket->u.server_anongame_tournament_reply.timestamp, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown5, 0); bn_short_set(&rpacket->u.server_anongame_tournament_reply.countdown, 0); bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown2, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.wins, tournament_get_stat(account, 1)); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.losses, tournament_get_stat(account, 2)); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.ties, tournament_get_stat(account, 3)); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown3, 0x04); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.selection, 2); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.descnum, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.nulltag, 0); } /* cycle through [type-6] & [type-7] packets * * use [type-6] to show client "eliminated" or "continue" * timestamp , countdown & round number (of next round) must be set if clinet continues * * use [type-7] to make cleint wait for 44FF packet option 1 to start game (A guess, not tested) * * not sure if there is overall winner packet sent at end of last final round */ // UNDONE: next two conditions never executed else if ((0)) { /* User in finals - Shows user stats and start of next round*/ bn_byte_set(&rpacket->u.server_anongame_tournament_reply.type, 6); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown, 0); bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown4, 0x0000); bn_int_set(&rpacket->u.server_anongame_tournament_reply.timestamp, _tournament_time_convert(start_r1)); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown5, 0x01); bn_short_set(&rpacket->u.server_anongame_tournament_reply.countdown, start_r1 - now); bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown2, 0x0000); /* 00 00 */ bn_byte_set(&rpacket->u.server_anongame_tournament_reply.wins, 4); /* round number */ bn_byte_set(&rpacket->u.server_anongame_tournament_reply.losses, 0); /* 0 = continue , 1= eliminated */ bn_byte_set(&rpacket->u.server_anongame_tournament_reply.ties, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown3, 0x04); /* number of rounds in finals */ bn_byte_set(&rpacket->u.server_anongame_tournament_reply.selection, 2); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.descnum, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.nulltag, 0); } else if ((0)) { /* user waiting for match to be made */ bn_byte_set(&rpacket->u.server_anongame_tournament_reply.type, 7); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown, 0); bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown4, 0); bn_int_set(&rpacket->u.server_anongame_tournament_reply.timestamp, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown5, 0); bn_short_set(&rpacket->u.server_anongame_tournament_reply.countdown, 0); bn_short_set(&rpacket->u.server_anongame_tournament_reply.unknown2, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.wins, 1); /* round number */ bn_byte_set(&rpacket->u.server_anongame_tournament_reply.losses, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.ties, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.unknown3, 0x04); /* number of finals */ bn_byte_set(&rpacket->u.server_anongame_tournament_reply.selection, 2); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.descnum, 0); bn_byte_set(&rpacket->u.server_anongame_tournament_reply.nulltag, 0); } conn_push_outqueue(c, rpacket); packet_del_ref(rpacket); return 0; }
/* Open portrait in Warcraft 3 user profile */ static int _client_anongame_get_icon(t_connection * c, t_packet const * const packet) { t_packet * rpacket; //BlacKDicK 04/20/2003 Need some huge re-work on this. { struct { char icon_code[4]; unsigned int portrait_code; char race; bn_short required_wins; char client_enabled; } tempicon; //FIXME: Add those to the prefs and also merge them on accoun_wrap; // FIXED BY DJP 07/16/2003 FOR 110 CHANGE ( TOURNEY & RACE WINS ) + Table_witdh short icon_req_race_wins; short icon_req_tourney_wins; int race[] = { W3_RACE_RANDOM, W3_RACE_HUMANS, W3_RACE_ORCS, W3_RACE_UNDEAD, W3_RACE_NIGHTELVES, W3_RACE_DEMONS }; char race_char[6] = { 'R', 'H', 'O', 'U', 'N', 'D' }; char icon_pos[5] = { '2', '3', '4', '5', '6', }; char table_width = 6; char table_height = 5; int i, j; char rico; unsigned int rlvl, rwins; t_clienttag clienttag; t_account * acc; char user_icon[5]; char const * uicon; clienttag = conn_get_clienttag(c); acc = conn_get_account(c); /* WAR3 uses a different table size, might change if blizzard add tournament support to RoC */ if (clienttag == CLIENTTAG_WARCRAFT3_UINT) { table_width = 5; table_height = 4; } eventlog(eventlog_level_info, __FUNCTION__, "[%d] got FINDANONGAME Get Icons packet", conn_get_socket(c)); if ((rpacket = packet_create(packet_class_bnet)) == NULL) { eventlog(eventlog_level_error, __FUNCTION__, "could not create new packet"); return -1; } packet_set_size(rpacket, sizeof(t_server_findanongame_iconreply)); packet_set_type(rpacket, SERVER_FINDANONGAME_ICONREPLY); bn_int_set(&rpacket->u.server_findanongame_iconreply.count, bn_int_get(packet->u.client_findanongame_inforeq.count)); bn_byte_set(&rpacket->u.server_findanongame_iconreply.option, CLIENT_FINDANONGAME_GET_ICON); if (prefs_get_custom_icons() == 1) { // get current custom icon t_icon_info * icon; if (icon = customicons_get_icon_by_account(acc, clienttag)) std::memcpy(&rpacket->u.server_findanongame_iconreply.curricon, icon->icon_code, 4); } else if ((uicon = account_get_user_icon(acc, clienttag))) { std::memcpy(&rpacket->u.server_findanongame_iconreply.curricon, uicon, 4); } else { account_get_raceicon(acc, &rico, &rlvl, &rwins, clienttag); std::sprintf(user_icon, "%1d%c3W", rlvl, rico); std::memcpy(&rpacket->u.server_findanongame_iconreply.curricon, user_icon, 4); } bn_byte_set(&rpacket->u.server_findanongame_iconreply.table_width, table_width); bn_byte_set(&rpacket->u.server_findanongame_iconreply.table_size, table_width*table_height); for (j = 0; j < table_height; j++){ icon_req_race_wins = anongame_infos_get_ICON_REQ(j + 1, clienttag); for (i = 0; i < table_width; i++){ tempicon.race = i; tempicon.icon_code[0] = icon_pos[j]; tempicon.icon_code[1] = race_char[i]; tempicon.icon_code[2] = '3'; tempicon.icon_code[3] = 'W'; tempicon.portrait_code = (account_icon_to_profile_icon(tempicon.icon_code, acc, clienttag)); if (i <= 4){ //Building the icon for the races bn_short_set(&tempicon.required_wins, icon_req_race_wins); if (account_get_racewins(acc, race[i], clienttag) >= icon_req_race_wins) { if (prefs_get_custom_icons() == 1) tempicon.client_enabled = 0; else tempicon.client_enabled = 1; } else{ tempicon.client_enabled = 0; } } else{ //Building the icon for the tourney icon_req_tourney_wins = anongame_infos_get_ICON_REQ_TOURNEY(j + 1); bn_short_set(&tempicon.required_wins, icon_req_tourney_wins); if (account_get_racewins(acc, race[i], clienttag) >= icon_req_tourney_wins) { if (prefs_get_custom_icons() == 1) tempicon.client_enabled = 0; else tempicon.client_enabled = 1; } else{ tempicon.client_enabled = 0; } } packet_append_data(rpacket, &tempicon, sizeof(tempicon)); } } //Go,go,go conn_push_outqueue(c, rpacket); packet_del_ref(rpacket); } return 0; }
int output_standard_writer(std::FILE * fp) { t_elem const *curr; t_connection *conn; t_channel const *channel; t_game *game; char const *channel_name; int number; char clienttag_str[5]; int uptime = server_get_uptime(); if (prefs_get_XML_status_output()) { int seconds; int minutes; int hours; int days; days = (uptime / (60 * 60 * 24)); hours = (uptime / (60 * 60)) % 24; minutes = (uptime / 60) % 60; seconds = uptime % 60; std::fprintf(fp, "<?xml version=\"1.0\"?>\n<status>\n"); std::fprintf(fp, "\t\t<Version>%s</Version>\n", PVPGN_VERSION); std::fprintf(fp, "\t\t<Uptime>\n"); std::fprintf(fp, "\t\t\t<Days>%d</Days>\n", days); std::fprintf(fp, "\t\t\t<Hours>%d</Hours>\n", hours); std::fprintf(fp, "\t\t\t<Minutes>%d</Minutes>\n", minutes); std::fprintf(fp, "\t\t\t<Seconds>%d</Seconds>\n", seconds); std::fprintf(fp, "\t\t</Uptime>\n"); std::fprintf(fp, "\t\t<Users>\n"); std::fprintf(fp, "\t\t<Number>%d</Number>\n", connlist_login_get_length()); LIST_TRAVERSE_CONST(connlist(), curr) { conn = (t_connection*)elem_get_data(curr); if (conn_get_account(conn)) std::fprintf(fp, "\t\t<user><name>%s</name><clienttag>%s</clienttag><version>%s</version>", conn_get_username(conn), tag_uint_to_str(clienttag_str, conn_get_clienttag(conn)), conn_get_clientver(conn)); if ((game = conn_get_game(conn))) std::fprintf(fp, "<gameid>%u</gameid>", game_get_id(game)); std::fprintf(fp, "</user>\n"); } std::fprintf(fp, "\t\t</Users>\n"); std::fprintf(fp, "\t\t<Games>\n"); std::fprintf(fp, "\t\t<Number>%d</Number>\n", gamelist_get_length()); gamelist_traverse(_glist_cb_xml, fp); std::fprintf(fp, "\t\t</Games>\n"); std::fprintf(fp, "\t\t<Channels>\n"); std::fprintf(fp, "\t\t<Number>%d</Number>\n", channellist_get_length()); LIST_TRAVERSE_CONST(channellist(), curr) { channel = (t_channel*)elem_get_data(curr); channel_name = channel_get_name(channel); std::fprintf(fp, "\t\t<channel>%s</channel>\n", channel_name); }
static void mail_func_delete(t_connection * c, const char * str) { t_account * user; t_mailbox * mailbox; const char * p; char tmp[256]; /* that should be enough */ int i; if (c==NULL) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return; } if (str==NULL) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL command string"); return; } for(i=0;str[i]==' ';i++); p=str+i; if (*p=='\0') { message_send_text(c,message_type_error,c,"Please specify which message to delete. Use the following syntax: /mail delete {<index>|all} ."); return; } if ((user=conn_get_account(c))==NULL) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL account"); return; } if ((mailbox=mailbox_open(user, mbox_mode_write))==NULL) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL mailbox"); return; } if (strcmp(p,"all")==0) { int rez; if ((rez=mailbox_delete_all(mailbox))<0) { message_send_text(c,message_type_error,c,"There was an error completing your request."); mailbox_close(mailbox); return; } sprintf(tmp,"Successfuly deleted %d messages.",rez); message_send_text(c,message_type_info,c,tmp); } else { int idx; for(i=0;p[i]>='0' && p[i]<='9' && p[i]!='\0';i++); if (p[i]!='\0' && p[i]!=' ') { message_send_text(c,message_type_error,c,"Invalid index. Please use /mail delete {<index>|all} where <index> is a number."); mailbox_close(mailbox); return; } idx=atoi(p); if (idx<1 || idx>mailbox_count(mailbox)) { message_send_text(c,message_type_error,c,"That index is out of range."); mailbox_close(mailbox); return; } if (mailbox_delete(mailbox,idx)<0) { message_send_text(c,message_type_error,c,"There was an error completing your request."); mailbox_close(mailbox); return; } sprintf(tmp,"Succesfully deleted message #%02d.",idx); message_send_text(c,message_type_info,c,tmp); } mailbox_close(mailbox); }
static void mail_func_read(t_connection * c, const char * str) { t_account * user; t_mailbox * mailbox; const char *p; char tmp[256]; int i; if (c==NULL) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return; } if (str==NULL) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL command string"); return; } for(i=0;str[i]==' ';i++); p=str+i; if ((user=conn_get_account(c))==NULL) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL account"); return; } mailbox=mailbox_open(user, mbox_mode_read); if (*p=='\0') { /* user wants to see the mail summary */ struct maillist_struct *maill, *mp; unsigned int idx; if (!mailbox_count(mailbox)) { message_send_text(c,message_type_info,c,"You have no mail."); mailbox_close(mailbox); return; } if ((maill=mailbox_get_list(mailbox))==NULL) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL maillist"); mailbox_close(mailbox); return; } sprintf(tmp,"You have %d messages. Your mail qouta is set to %d.",mailbox_count(mailbox),get_mail_quota(user)); message_send_text(c,message_type_info,c,tmp); message_send_text(c,message_type_info,c,"ID Sender Date"); message_send_text(c,message_type_info,c,"-------------------------------------"); for(mp=maill,idx=1;mp!=NULL;mp=mp->next,idx++) { sprintf(tmp,"%02u %-14s %s",idx,mp->sender,ctime(&mp->timestamp)); clean_str(tmp); /* ctime() appends an newline that we get cleaned */ message_send_text(c,message_type_info,c,tmp); } message_send_text(c,message_type_info,c,"Use /mail read <ID> to read the content of any message"); mailbox_unget_list(maill); } else { /* user wants to read a message */ int idx; t_mail * mail; for(i=0;p[i]>='0' && p[i]<='9' && p[i]!='\0';i++); if (p[i]!='\0' && p[i]!=' ') { message_send_text(c,message_type_error,c,"Invalid index. Please use /mail read <index> where <index> is a number."); mailbox_close(mailbox); return; } idx=atoi(p); if (idx<1 || idx>mailbox_count(mailbox)) { message_send_text(c,message_type_error,c,"That index is out of range."); mailbox_close(mailbox); return; } if ((mail=mailbox_read(mailbox,idx))==NULL) { message_send_text(c,message_type_error,c,"There was an error completing your request."); mailbox_close(mailbox); return; } sprintf(tmp,"Message #%d from %s on %s:",idx,mail->sender,clean_str(ctime(&mail->timestamp))); message_send_text(c,message_type_info,c,tmp); message_send_text(c,message_type_info,c,mail->message); mailbox_unread(mail); } mailbox_close(mailbox); }
static int on_d2cs_accountloginreq(t_connection * c, t_packet const * packet) { unsigned int sessionkey; unsigned int sessionnum; unsigned int salt; char const * account; char const * tname; t_connection * client; int reply; t_packet * rpacket; struct { bn_int salt; bn_int sessionkey; bn_int sessionnum; bn_int secret; bn_int passhash[5]; } temp; t_hash secret_hash; char const * pass_str; t_hash passhash; t_hash try_hash; if (packet_get_size(packet)<sizeof(t_d2cs_bnetd_accountloginreq)) { eventlog(eventlog_level_error,"on_d2cs_accountloginreq","got bad packet size"); return -1; } if (!(account=packet_get_str_const(packet,sizeof(t_d2cs_bnetd_accountloginreq),USER_NAME_MAX))) { eventlog(eventlog_level_error,"on_d2cs_accountloginreq","got bad account name"); return -1; } sessionkey=bn_int_get(packet->u.d2cs_bnetd_accountloginreq.sessionkey); sessionnum=bn_int_get(packet->u.d2cs_bnetd_accountloginreq.sessionnum); salt=bn_int_get(packet->u.d2cs_bnetd_accountloginreq.seqno); if (!(client=connlist_find_connection_by_sessionnum(sessionnum))) { eventlog(eventlog_level_error,"on_d2cs_accountloginreq","sessionnum %d not found",sessionnum); reply=BNETD_D2CS_ACCOUNTLOGINREPLY_FAILED; } else if (sessionkey!=conn_get_sessionkey(client)) { eventlog(eventlog_level_error,"on_d2cs_accountloginreq","sessionkey %d not match",sessionkey); reply=BNETD_D2CS_ACCOUNTLOGINREPLY_FAILED; } else if (!(tname=conn_get_username(client))) { eventlog(eventlog_level_error,"on_d2cs_accountloginreq","got NULL username"); reply=BNETD_D2CS_ACCOUNTLOGINREPLY_FAILED; } else if (strcasecmp(account,tname)) { eventlog(eventlog_level_error,"on_d2cs_accountloginreq","username %s not match",account); conn_unget_username(client,tname); reply=BNETD_D2CS_ACCOUNTLOGINREPLY_FAILED; } else { conn_unget_username(client,tname); bn_int_set(&temp.salt,salt); bn_int_set(&temp.sessionkey,sessionkey); bn_int_set(&temp.sessionnum,sessionnum); bn_int_set(&temp.secret,conn_get_secret(client)); pass_str=account_get_pass(conn_get_account(client)); if (hash_set_str(&passhash,pass_str)<0) { reply=BNETD_D2CS_ACCOUNTLOGINREPLY_FAILED; } else { hash_to_bnhash((t_hash const *)&passhash,temp.passhash); bnet_hash(&secret_hash,sizeof(temp),&temp); bnhash_to_hash(packet->u.d2cs_bnetd_accountloginreq.secret_hash,&try_hash); if (hash_eq(try_hash,secret_hash)==1) { eventlog(eventlog_level_debug,"on_d2cs_accountloginreq","user %s loggedin on d2cs",\ account); reply=BNETD_D2CS_ACCOUNTLOGINREPLY_SUCCEED; } else { eventlog(eventlog_level_error,"on_d2cs_accountloginreq","user %s hash not match",\ account); reply=BNETD_D2CS_ACCOUNTLOGINREPLY_FAILED; } } account_unget_pass(pass_str); } if ((rpacket=packet_create(packet_class_d2cs_bnetd))) { packet_set_size(rpacket,sizeof(t_bnetd_d2cs_accountloginreply)); packet_set_type(rpacket,BNETD_D2CS_ACCOUNTLOGINREPLY); bn_int_set(&rpacket->u.bnetd_d2cs_accountloginreply.h.seqno,\ bn_int_get(packet->u.d2cs_bnetd_accountloginreq.h.seqno)); bn_int_set(&rpacket->u.bnetd_d2cs_accountloginreply.reply,reply); queue_push_packet(conn_get_out_queue(c),rpacket); packet_del_ref(rpacket); } return 0; }
extern int irc_message_postformat(t_packet * packet, t_connection const * dest) { int len; /* the four elements */ char * e1; char * e1_2; char * e2; char * e3; char * e4; char const * tname = NULL; char const * toname = "AUTH"; /* fallback name */ if (!packet) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL packet"); return -1; } if (!dest) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL dest"); return -1; } e1 = packet_get_raw_data(packet,0); e2 = strchr(e1,'\n'); if (!e2) { eventlog(eventlog_level_warn,__FUNCTION__,"malformed message (e2 missing)"); return -1; } *e2++ = '\0'; e3 = strchr(e2,'\n'); if (!e3) { eventlog(eventlog_level_warn,__FUNCTION__,"malformed message (e3 missing)"); return -1; } *e3++ = '\0'; e4 = strchr(e3,'\n'); if (!e4) { eventlog(eventlog_level_warn,__FUNCTION__,"malformed message (e4 missing)"); return -1; } *e4++ = '\0'; if (prefs_get_hide_addr() && !(account_get_command_groups(conn_get_account(dest)) & command_get_group("/admin-addr"))) { e1_2 = strchr(e1,'@'); if (e1_2) { *e1_2++ = '\0'; } } else 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; } }
static void mail_func_read(t_connection * c, std::istream& istr) { if (!c) { ERROR0("got NULL connection"); return; } std::string token; istr >> token; t_account * user = conn_get_account(c); Mailbox mbox(account_get_uid(user)); if (token.empty()) { /* user wants to see the mail summary */ if (mbox.empty()) { message_send_text(c,message_type_info,c,"You have no mail."); return; } MailList mlist; mbox.readAll(mlist); std::ostringstream ostr; ostr << "You have " << mbox.size() << " messages. Your mail quote is set to " << get_mail_quota(user) << '.'; message_send_text(c, message_type_info, c, ostr.str().c_str()); message_send_text(c, message_type_info, c, "ID Sender Date"); message_send_text(c, message_type_info, c, "-------------------------------------"); for(MailList::const_iterator it(mlist.begin()); it != mlist.end(); ++it) { ostr.str(""); ostr << std::setfill('0') << std::setw(2) << std::right << (it - mlist.begin()) << " " << std::setfill(' ') << std::setw(14) << std::left << it->sender() << ' '; char buff[128]; std::strftime(buff, sizeof(buff), "%a %b %d %H:%M:%S %Y", std::localtime(&it->timestamp())); ostr << buff; message_send_text(c, message_type_info, c, ostr.str().c_str()); } message_send_text(c,message_type_info,c,"Use /mail read <ID> to read the content of any message"); } else { /* user wants to read a message */ if (std::find_if(token.begin(), token.end(), NonNumericChar) != token.end()) { message_send_text(c,message_type_error,c,"Invalid index. Please use /mail read <index> where <index> is a number."); return; } try { unsigned idx = std::atoi(token.c_str()); Mail mail(mbox.read(idx)); std::ostringstream ostr; ostr << "Message #" << idx << " from " << mail.sender() << " on "; char buff[128]; std::strftime(buff, sizeof(buff), "%a %b %d %H:%M:%S %Y", std::localtime(&mail.timestamp())); ostr << buff << ':'; message_send_text(c, message_type_info, c, ostr.str().c_str()); message_send_text(c, message_type_info, c, mail.message().c_str()); } catch (const Mailbox::ReadError&) { message_send_text(c,message_type_error,c,"There was an error completing your request."); } } }