?? clan.c
字號:
/* * 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. */#define CLAN_INTERNAL_ACCESS#include "common/setup_before.h"#include <stdio.h>#ifdef HAVE_STDDEF_H# include <stddef.h>#else# ifndef NULL# define NULL ((void *)0)# endif#endif#ifdef STDC_HEADERS# include <stdlib.h>#else# ifdef HAVE_MALLOC_H# include <malloc.h># endif#endif#ifdef HAVE_STRING_H# include <string.h>#else# ifdef HAVE_STRINGS_H# include <strings.h># endif#endif#include "compat/strrchr.h"#include "compat/strdup.h"#include "compat/strcasecmp.h"#include "compat/strncasecmp.h"#include "compat/pdir.h"#include <errno.h>#include "compat/strerror.h"#ifdef TIME_WITH_SYS_TIME# include <sys/time.h># include <time.h>#else# ifdef HAVE_SYS_TIME_H# include <sys/time.h># else# include <time.h># endif#endif#ifdef HAVE_SYS_TYPES_H# include <sys/types.h>#endif#include "common/eventlog.h"#include "common/packet.h"#include "common/bnet_protocol.h"#include "common/tag.h"#include "common/util.h"#include "common/bnettime.h"#include "common/eventlog.h"#include "common/list.h"#include "common/proginfo.h"#include "common/bn_type.h"#include "common/xalloc.h"#include "connection.h"#include "anongame.h"#include "prefs.h"#include "friends.h"#include "game.h"#include "clan.h"#include "account.h"#include "channel.h"#include "anongame.h"#include "storage.h"#include "server.h"#include "compat/uint.h"#include "common/setup_after.h"static t_list *clanlist_head = NULL;int max_clanid = 0;/* callback function for storage use */static int _cb_load_clans(void *clan){ if (clanlist_add_clan(clan) < 0) { eventlog(eventlog_level_error, __FUNCTION__, "failed to add clan to clanlist"); return -1; } if (((t_clan *) clan)->clanid > max_clanid) max_clanid = ((t_clan *) clan)->clanid; return 0;}/*** Packet Management*/extern int clan_send_packet_to_online_members(t_clan * clan, t_packet * packet){ t_elem *curr; if (!clan) { eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan"); return -1; } if (!packet) { eventlog(eventlog_level_error, __FUNCTION__, "got NULL packet"); return -1; } LIST_TRAVERSE(clan->members, curr) { t_clanmember * member; t_clienttag clienttag; t_connection * conn; if (!(member = elem_get_data(curr))) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL elem in list"); continue; } if (!(conn = clanmember_get_conn(member))) continue; // not online if (!(clienttag = conn_get_clienttag(conn))) { eventlog(eventlog_level_error,__FUNCTION__,"conn has NULL clienttag"); continue; } if ((clienttag != CLIENTTAG_WARCRAFT3_UINT ) && (clienttag != CLIENTTAG_WAR3XP_UINT)) continue; // online but wrong client conn_push_outqueue(conn, packet); } return 0;}extern int clan_send_status_window_on_create(t_clan * clan){ t_packet * rpacket; t_elem *curr; if (!(clan)) { eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan"); return -1; } if ((rpacket = packet_create(packet_class_bnet))) { char channelname[10]; if (clan->clantag) sprintf(channelname, "Clan %c%c%c%c", (clan->clantag >> 24), (clan->clantag >> 16) & 0xff, (clan->clantag >> 8) & 0xff, clan->clantag & 0xff); else { sprintf(channelname, "Clans"); eventlog(eventlog_level_error,__FUNCTION__,"clan has NULL clantag"); } packet_set_size(rpacket, sizeof(t_server_w3xp_clan_clanack)); packet_set_type(rpacket, SERVER_W3XP_CLAN_CLANACK); bn_byte_set(&rpacket->u.server_w3xp_clan_clanack.unknow1, 0); bn_int_set(&rpacket->u.server_w3xp_clan_clanack.clantag, clan->clantag); LIST_TRAVERSE(clan->members, curr) { t_clanmember * member; t_clienttag clienttag; t_connection * conn; if (!(member = elem_get_data(curr))) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL elem in list"); continue; } if (!(conn = clanmember_get_conn(member))) continue; // not online; if (!(clienttag = conn_get_clienttag(conn))) { eventlog(eventlog_level_error,__FUNCTION__,"conn has NULL clienttag"); continue; } if ((clienttag != CLIENTTAG_WARCRAFT3_UINT) && (clienttag != CLIENTTAG_WAR3XP_UINT)) continue; // online but wrong client if (conn_get_channel(conn)) { conn_update_w3_playerinfo(conn); channel_set_userflags(conn); if (conn_set_channel(conn, channelname) < 0) conn_set_channel(conn, CHANNEL_NAME_BANNED); /* should not fail */ } bn_byte_set(&rpacket->u.server_w3xp_clan_clanack.status, member->status); conn_push_outqueue(conn, rpacket); } packet_del_ref(rpacket); } return 0;}extern int clan_close_status_window_on_disband(t_clan * clan){ t_packet * rpacket; t_elem *curr; if (!(clan)) { eventlog(eventlog_level_error, __FUNCTION__, "got NULL clan"); return -1; } if ((rpacket = packet_create(packet_class_bnet))) { packet_set_size(rpacket, sizeof(t_server_w3xp_clanquitnotify)); packet_set_type(rpacket, SERVER_W3XP_CLANQUITNOTIFY); bn_byte_set(&rpacket->u.server_w3xp_clan_clanack.status, SERVER_W3XP_CLANQUITNOTIFY_STATUS_REMOVED_FROM_CLAN); LIST_TRAVERSE(clan->members, curr) { t_clanmember * member; t_clienttag clienttag; t_connection * conn; if (!(member = elem_get_data(curr))) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL elem in list"); continue; } if (!(conn = clanmember_get_conn(member))) continue; // not online; if (!(clienttag = conn_get_clienttag(conn))) { eventlog(eventlog_level_error,__FUNCTION__,"conn has NULL clienttag"); continue; } if ((clienttag != CLIENTTAG_WARCRAFT3_UINT) && (clienttag != CLIENTTAG_WAR3XP_UINT)) continue; // online but wrong client conn_push_outqueue(conn, rpacket); conn_update_w3_playerinfo(conn); } packet_del_ref(rpacket); } return 0;}extern int clan_send_status_window(t_connection * c){ t_packet * rpacket; t_account *acc; t_clanmember *member; t_clienttag clienttag; t_clan * clan; if (!(acc = conn_get_account(c))) return 0; if (!(member = account_get_clanmember(acc))) return 0; if (!(clan = member->clan)) { eventlog(eventlog_level_error,__FUNCTION__,"member has NULL clan"); return -1; } if (!(clan->clantag)) { eventlog(eventlog_level_error,__FUNCTION__,"clan has NULL clantag"); return -1; } if (!(clienttag = conn_get_clienttag(c))) { eventlog(eventlog_level_error,__FUNCTION__,"conn has NULL clienttag"); return -1; } if ((clienttag != CLIENTTAG_WARCRAFT3_UINT) && (clienttag != CLIENTTAG_WAR3XP_UINT)) return 0; if ((rpacket = packet_create(packet_class_bnet))) { packet_set_size(rpacket, sizeof(t_server_w3xp_clan_clanack)); packet_set_type(rpacket, SERVER_W3XP_CLAN_CLANACK); bn_byte_set(&rpacket->u.server_w3xp_clan_clanack.unknow1, 0); bn_int_set(&rpacket->u.server_w3xp_clan_clanack.clantag, member->clan->clantag); bn_byte_set(&rpacket->u.server_w3xp_clan_clanack.status, member->status); conn_push_outqueue(c, rpacket); packet_del_ref(rpacket); } return 0;}extern int clan_close_status_window(t_connection * c){ t_packet * rpacket; t_clienttag clienttag; if (!(clienttag = conn_get_clienttag(c))) { eventlog(eventlog_level_error,__FUNCTION__,"conn has NULL clienttag"); return -1; } if ((clienttag != CLIENTTAG_WARCRAFT3_UINT) && (clienttag != CLIENTTAG_WAR3XP_UINT)) return 0; if ((rpacket = packet_create(packet_class_bnet))) { packet_set_size(rpacket, sizeof(t_server_w3xp_clanquitnotify)); packet_set_type(rpacket, SERVER_W3XP_CLANQUITNOTIFY); bn_byte_set(&rpacket->u.server_w3xp_clanquitnotify.status, SERVER_W3XP_CLANQUITNOTIFY_STATUS_REMOVED_FROM_CLAN); conn_push_outqueue(c, rpacket); packet_del_ref(rpacket); } return 0;}extern int clan_send_memberlist(t_connection * c, t_packet const *const packet){ t_packet * rpacket; t_elem *curr; char const *username; t_clanmember *member; t_clan *clan; t_account *account; int count = 0; char tmpstr[2]; const char *append_str; if (!(account = conn_get_account(c))) return -1; if (!(clan = account_get_clan(account))) return -1; if ((rpacket = packet_create(packet_class_bnet))) { t_account * memberacc; packet_set_size(rpacket, sizeof(t_server_w3xp_clanmemberlist_reply)); packet_set_type(rpacket, SERVER_W3XP_CLANMEMBERLIST_REPLY); bn_int_set(&rpacket->u.server_w3xp_clanmemberlist_reply.count, bn_int_get(packet->u.client_w3xp_clanmemberlist_req.count)); LIST_TRAVERSE(clan->members, curr) { if (!(member = elem_get_data(curr))) { eventlog(eventlog_level_error, __FUNCTION__, "got NULL element in list"); continue; } if (!(memberacc = member->memberacc)) { eventlog(eventlog_level_error,__FUNCTION__,"member has NULL account"); continue; } username = account_get_name(memberacc); packet_append_string(rpacket, username); tmpstr[0] = member->status; append_str = clanmember_get_online_status(member, &tmpstr[1]); packet_append_data(rpacket, tmpstr, 2); if (append_str) packet_append_string(rpacket, append_str); else packet_append_string(rpacket, ""); count++; } bn_byte_set(&rpacket->u.server_w3xp_clanmemberlist_reply.member_count, count); conn_push_outqueue(c, rpacket); packet_del_ref(rpacket); return 0; } return -1;}extern int clan_save_motd_chg(t_connection * c, t_packet const *const packet){ t_account *account; char const *motd; int offset; t_clan *clan; if ((account = conn_get_account(c)) == NULL) return -1; if ((clan = account_get_clan(account)) == NULL) return -1; offset = sizeof(packet->u.client_w3xp_clan_motdchg); motd = packet_get_str_const(packet, offset, 25); eventlog(eventlog_level_trace, __FUNCTION__, "[%d] got W3XP_CLAN_MOTDCHG packet : %s", conn_get_socket(c), motd); if (clan_set_motd(clan, motd) != 0) { eventlog(eventlog_level_error, __FUNCTION__, "Failed to set clan motd."); return -1; } clan->modified = 1; return 0;}extern int clan_send_motd_reply(t_connection * c, t_packet const *const packet){ t_packet * rpacket; t_account *account; t_clan *clan; if ((account = conn_get_account(c)) == NULL) return -1; if ((clan = account_get_clan(account)) == NULL) return -1; if (clan->clan_motd == NULL) { eventlog(eventlog_level_error, __FUNCTION__, "Failed to get clan motd."); return -1; } if ((rpacket = packet_create(packet_class_bnet))) { packet_set_size(rpacket, sizeof(t_server_w3xp_clan_motdreply)); packet_set_type(rpacket, SERVER_W3XP_CLAN_MOTDREPLY); bn_int_set(&rpacket->u.server_w3xp_clan_motdreply.count, bn_int_get(packet->u.client_w3xp_clan_motdreq.count)); bn_int_set(&rpacket->u.server_w3xp_clan_motdreply.unknow1, SERVER_W3XP_CLAN_MOTDREPLY_UNKNOW1); packet_append_string(rpacket, clan->clan_motd); conn_push_outqueue(c, rpacket); packet_del_ref(rpacket); } return 0;}/*** String / Function Management*/extern int clan_get_possible_member(t_connection * c, t_packet const *const packet){ t_packet * rpacket; t_channel *channel; t_connection *conn; char const *username; t_account * account; int friend_count = 0; int clantag; clantag = bn_int_get(packet->u.client_w3xp_clan_createreq.clantag); if ((rpacket = packet_create(packet_class_bnet)) == NULL) { return -1; } packet_set_size(rpacket, sizeof(t_server_w3xp_clan_createreply)); packet_set_type(rpacket, SERVER_W3XP_CLAN_CREATEREPLY); bn_int_set(&rpacket->u.server_w3xp_clan_createreply.count, bn_int_get(packet->u.client_w3xp_clan_createreq.count)); if (clanlist_find_clan_by_clantag(clantag) != NULL) { bn_byte_set(&rpacket->u.server_w3xp_clan_createreply.check_result, SERVER_W3XP_CLAN_CREATEREPLY_CHECK_ALLREADY_IN_USE); bn_byte_set(&rpacket->u.server_w3xp_clan_createreply.friend_count, 0);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -