?? handle_anongame.c
字號:
/* * Copyright (C) 2004 CreepLord (creeplord@pvpgn.org) * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */#include "common/setup_before.h"#ifdef HAVE_STRING_H# include <string.h>#else# ifdef HAVE_STRINGS_H# include <strings.h># endif#endif#include <errno.h>#ifdef STDC_HEADERS# include <stdlib.h>#else# ifdef HAVE_MALLOC_H# include <malloc.h># endif#endif#include "common/bn_type.h"#include "common/eventlog.h"#include "common/packet.h"#include "common/queue.h"#include "common/tag.h"#include "common/list.h"#include "common/util.h"#include "common/xalloc.h"#include "common/bnettime.h"#include "connection.h"#include "team.h"#include "account.h"#include "account_wrap.h"#include "channel.h"#include "anongame.h"#include "anongame_infos.h"#include "anongame_maplists.h"#include "handle_anongame.h"#include "tournament.h"#include "server.h"#include "clan.h"#include "common/setup_after.h"/* option - handling function *//* 0x00 */ /* PG style search - handle_anongame_search() in anongame.c */ /* 0x01 */ /* server side packet sent from handle_anongame_search() in anongame.c *//* 0x02 */ static int _client_anongame_infos(t_connection * c, t_packet const * const packet);/* 0x03 */ static int _client_anongame_cancel(t_connection * c);/* 0x04 */ static int _client_anongame_profile(t_connection * c, t_packet const * const packet);/* 0x05 */ /* AT style search - handle_anongame_search() in anongame.c *//* 0x06 */ /* AT style search (Inviter) handle_anongame_search() in anongame.c *//* 0x07 */ static int _client_anongame_tournament(t_connection * c, t_packet const * const packet);/* 0x08 */ static int _client_anongame_profile_clan(t_connection * c, t_packet const * const packet);/* 0x09 */ static int _client_anongame_get_icon(t_connection * c, t_packet const * const packet);/* 0x0A */ static int _client_anongame_set_icon(t_connection * c, t_packet const * const packet);/* misc functions used by _client_anongame_tournament() */static unsigned int _tournament_time_convert(unsigned int time);/* and now the functions */static int _client_anongame_profile_clan(t_connection * c, t_packet const * const packet){ t_packet * rpacket; int clantag; int clienttag; int count; int temp; t_clan * clan; unsigned char rescount; if (packet_get_size(packet)<sizeof(t_client_findanongame_profile_clan)) { eventlog(eventlog_level_error,__FUNCTION__,"[%d] got bad ANONGAME_PROFILE_CLAN packet (expected %u bytes, got %u)",conn_get_socket(c), sizeof(t_client_findanongame_profile_clan), packet_get_size(packet)); return -1; } clantag = bn_int_get(packet->u.client_findanongame_profile_clan.clantag); clienttag = bn_int_get(packet->u.client_findanongame_profile_clan.clienttag); count = bn_int_get(packet->u.server_findanongame_profile_clan.count); clan = clanlist_find_clan_by_clantag(clantag); if ((rpacket = packet_create(packet_class_bnet))) { packet_set_size(rpacket,sizeof(t_server_findanongame_profile_clan)); packet_set_type(rpacket,SERVER_FINDANONGAME_PROFILE_CLAN); bn_byte_set(&rpacket->u.server_findanongame_profile_clan.option,CLIENT_FINDANONGAME_PROFILE_CLAN); bn_int_set(&rpacket->u.server_findanongame_profile_clan.count,count); rescount = 0; if (!(clan)) { temp = 0; packet_append_data(rpacket,&temp,1); } else { temp = 0; packet_append_data(rpacket,&temp,1); /* need to add clan stuff here: format: bn_int ladder_tag (SNLC, 2NLC, 3NLC, 4NLC) bn_int wins bn_int losses bn_byte rank bn_byte progess bar bn_int xp bn_int rank bn_byte 0x06 <-- random + 5 races 6 times: bn_int wins bn_int losses */ } bn_byte_set(&rpacket->u.server_findanongame_profile_clan.rescount,rescount); conn_push_outqueue(c,rpacket); packet_del_ref(rpacket); } return 0;}static int _client_anongame_profile(t_connection * c, t_packet const * const packet){ t_packet * rpacket; char const * username; int Count, i; int temp; t_account * account; t_connection * dest_c; t_clienttag ctag; char clienttag_str[5]; t_list * teamlist; unsigned char teamcount; unsigned char *atcountp; t_elem * curr; t_team * team; t_bnettime bn_time; bn_long ltime; Count = bn_int_get(packet->u.client_findanongame.count); eventlog(eventlog_level_info,__FUNCTION__,"[%d] got a FINDANONGAME PROFILE packet",conn_get_socket(c)); if (!(username = packet_get_str_const(packet,sizeof(t_client_findanongame_profile),USER_NAME_MAX))) { eventlog(eventlog_level_error,__FUNCTION__,"[%d] got bad FINDANONGAME_PROFILE (missing or too long username)",conn_get_socket(c)); return -1; } //If no account is found then break if (!(account = accountlist_find_account(username))) { eventlog(eventlog_level_error, __FUNCTION__, "Could not get account - PROFILE"); return -1; } if (!(dest_c = connlist_find_connection_by_accountname(username))) { eventlog(eventlog_level_debug, __FUNCTION__, "account is offline - try ll_clienttag"); if (!(ctag = account_get_ll_clienttag(account))) return -1; } else ctag = conn_get_clienttag(dest_c); eventlog(eventlog_level_info,__FUNCTION__,"Looking up %s's %s Stats.",username,tag_uint_to_str(clienttag_str,ctag)); if (account_get_ladder_level(account,ctag,ladder_id_solo)<=0 && account_get_ladder_level(account,ctag,ladder_id_team)<=0 && account_get_ladder_level(account,ctag,ladder_id_ffa)<=0 && account_get_teams(account)==NULL) { eventlog(eventlog_level_info,__FUNCTION__,"%s does not have WAR3 Stats.",username); if (!(rpacket = packet_create(packet_class_bnet))) return -1; packet_set_size(rpacket,sizeof(t_server_findanongame_profile2)); packet_set_type(rpacket,SERVER_FINDANONGAME_PROFILE); bn_byte_set(&rpacket->u.server_findanongame_profile2.option,CLIENT_FINDANONGAME_PROFILE); bn_int_set(&rpacket->u.server_findanongame_profile2.count,Count); bn_int_set(&rpacket->u.server_findanongame_profile2.icon,account_icon_to_profile_icon(account_get_user_icon(account,ctag),account,ctag)); bn_byte_set(&rpacket->u.server_findanongame_profile2.rescount,0); temp=0; packet_append_data(rpacket,&temp,2); conn_push_outqueue(c,rpacket); packet_del_ref(rpacket); } else // If they do have a profile then: { int solowins=account_get_ladder_wins(account,ctag,ladder_id_solo); int sololoss=account_get_ladder_losses(account,ctag,ladder_id_solo); int soloxp=account_get_ladder_xp(account,ctag,ladder_id_solo); int sololevel=account_get_ladder_level(account,ctag,ladder_id_solo); int solorank=account_get_ladder_rank(account,ctag,ladder_id_solo); int teamwins=account_get_ladder_wins(account,ctag,ladder_id_team); int teamloss=account_get_ladder_losses(account,ctag,ladder_id_team); int teamxp=account_get_ladder_xp(account,ctag,ladder_id_team); int teamlevel=account_get_ladder_level(account,ctag,ladder_id_team); int teamrank=account_get_ladder_rank(account,ctag,ladder_id_team); int ffawins=account_get_ladder_wins(account,ctag,ladder_id_ffa); int ffaloss=account_get_ladder_losses(account,ctag,ladder_id_ffa); int ffaxp=account_get_ladder_xp(account,ctag,ladder_id_ffa); int ffalevel=account_get_ladder_level(account,ctag,ladder_id_ffa); int ffarank=account_get_ladder_rank(account,ctag,ladder_id_ffa); int humanwins=account_get_racewins(account,1,ctag); int humanlosses=account_get_racelosses(account,1,ctag); int orcwins=account_get_racewins(account,2,ctag); int orclosses=account_get_racelosses(account,2,ctag); int undeadwins=account_get_racewins(account,8,ctag); int undeadlosses=account_get_racelosses(account,8,ctag); int nightelfwins=account_get_racewins(account,4,ctag); int nightelflosses=account_get_racelosses(account,4,ctag); int randomwins=account_get_racewins(account,0,ctag); int randomlosses=account_get_racelosses(account,0,ctag); unsigned char rescount; if (!(rpacket = packet_create(packet_class_bnet))) return -1; packet_set_size(rpacket,sizeof(t_server_findanongame_profile2)); packet_set_type(rpacket,SERVER_FINDANONGAME_PROFILE); bn_byte_set(&rpacket->u.server_findanongame_profile2.option,CLIENT_FINDANONGAME_PROFILE); bn_int_set(&rpacket->u.server_findanongame_profile2.count,Count); //job count bn_int_set(&rpacket->u.server_findanongame_profile2.icon,account_icon_to_profile_icon(account_get_user_icon(account,ctag),account,ctag)); rescount = 0; if (sololevel > 0) { bn_int_set((bn_int*)&temp,0x534F4C4F); // SOLO backwards packet_append_data(rpacket,&temp,4); temp=0; bn_int_set((bn_int*)&temp,solowins); packet_append_data(rpacket,&temp,2); //SOLO WINS bn_int_set((bn_int*)&temp,sololoss); packet_append_data(rpacket,&temp,2); // SOLO LOSSES bn_int_set((bn_int*)&temp,sololevel); packet_append_data(rpacket,&temp,1); // SOLO LEVEL bn_int_set((bn_int*)&temp,account_get_profile_calcs(account,soloxp,sololevel)); packet_append_data(rpacket,&temp,1); // SOLO PROFILE CALC bn_int_set((bn_int *)&temp,soloxp); packet_append_data(rpacket,&temp,2); // SOLO XP bn_int_set((bn_int *)&temp,solorank); packet_append_data(rpacket,&temp,4); // SOLO LADDER RANK rescount++; } if (teamlevel > 0) { //below is for team records. Add this after 2v2,3v3,4v4 are done bn_int_set((bn_int*)&temp,0x5445414D); packet_append_data(rpacket,&temp,4); bn_int_set((bn_int*)&temp,teamwins); packet_append_data(rpacket,&temp,2); bn_int_set((bn_int*)&temp,teamloss); packet_append_data(rpacket,&temp,2); bn_int_set((bn_int*)&temp,teamlevel); packet_append_data(rpacket,&temp,1); bn_int_set((bn_int*)&temp,account_get_profile_calcs(account,teamxp,teamlevel)); packet_append_data(rpacket,&temp,1); bn_int_set((bn_int*)&temp,teamxp); packet_append_data(rpacket,&temp,2); bn_int_set((bn_int*)&temp,teamrank); packet_append_data(rpacket,&temp,4); //done of team game stats rescount++; } if (ffalevel > 0) { bn_int_set((bn_int*)&temp,0x46464120); packet_append_data(rpacket,&temp,4); bn_int_set((bn_int*)&temp,ffawins); packet_append_data(rpacket,&temp,2); bn_int_set((bn_int*)&temp,ffaloss); packet_append_data(rpacket,&temp,2); bn_int_set((bn_int*)&temp,ffalevel); packet_append_data(rpacket,&temp,1); bn_int_set((bn_int*)&temp,account_get_profile_calcs(account,ffaxp,ffalevel)); packet_append_data(rpacket,&temp,1); bn_int_set((bn_int*)&temp,ffaxp); packet_append_data(rpacket,&temp,2); bn_int_set((bn_int*)&temp,ffarank); packet_append_data(rpacket,&temp,4); //End of FFA Stats rescount++; } /* set result count */ bn_byte_set(&rpacket->u.server_findanongame_profile2.rescount,rescount); bn_int_set((bn_int*)&temp,0x06); //start of race stats packet_append_data(rpacket,&temp,1); bn_int_set((bn_int*)&temp,randomwins);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -