📄 connection.c
字号:
c->protocol.chat.channel=channel; if (channel_add_connection(channel,c)<0) { if (created) channel_destroy(channel,&curr); c->protocol.chat.channel = NULL; return -1; } eventlog(eventlog_level_info,__FUNCTION__,"[%d] joined channel \"%s\"",conn_get_socket(c),channel_get_name(c->protocol.chat.channel)); conn_send_welcome(c); if(c->protocol.chat.channel && (channel_get_flags(c->protocol.chat.channel) & channel_flags_thevoid)) message_send_text(c,message_type_info,c,"This channel does not have chat privileges."); if (clantag && clan && (clan_get_clantag(clan)==clantag)) { char msgtemp[MAX_MESSAGE_LEN]; sprintf(msgtemp,"%s",clan_get_motd(clan)); message_send_text(c,message_type_info,c,msgtemp); } if (channel_get_topic(channel_get_name(c->protocol.chat.channel)) && ((conn_get_class(c)!=conn_class_irc) || (conn_get_class(c)!=conn_class_wol))) { char msgtemp[MAX_MESSAGE_LEN]; sprintf(msgtemp,"%s topic: %s",channel_get_name(c->protocol.chat.channel),channel_get_topic(channel_get_name(c->protocol.chat.channel))); message_send_text(c,message_type_info,c,msgtemp); } if (c->protocol.chat.channel && (channel_get_flags(c->protocol.chat.channel) & channel_flags_moderated)) message_send_text(c,message_type_error,c,"This channel is moderated."); if(c->protocol.chat.channel!=oldchannel) clanmember_on_change_status_by_connection(c); } else { if (c->protocol.chat.channel) { channel_del_connection(c->protocol.chat.channel,c); c->protocol.chat.channel = NULL; } } return 0;}extern t_game * conn_get_game(t_connection const * c){ if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return NULL; } return c->protocol.game;}extern int conn_set_game(t_connection * c, char const * gamename, char const * gamepass, char const * gameinfo, t_game_type type, int version)/* * If game not exists (create) version != 0 (called in handle_bnet.c, function _client_startgameX()) * If game exists (join) version == 0 always (called in handle_bnet.c, function _client_joingame()) * If game exists (join) gameinfo == "" (called in handle_bnet.c, function _client_joingame()) * [KWS] */{ if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return -1; } if (c->protocol.game) { if (gamename) { if (strcasecmp(gamename,game_get_name(c->protocol.game))) eventlog(eventlog_level_error,__FUNCTION__,"[%d] tried to join a new game \"%s\" while already in a game \"%s\"!",conn_get_socket(c),gamename,game_get_name(c->protocol.game)); else return 0; } game_del_player(conn_get_game(c),c); c->protocol.game = NULL; } if (gamename) { if (!(c->protocol.game = gamelist_find_game(gamename,c->protocol.client.clienttag,type)) /* do not allow creation of games with same name of same clienttag (yet) */ && !gamelist_find_game(gamename,c->protocol.client.clienttag,game_type_all)) { c->protocol.game = game_create(gamename,gamepass,gameinfo,type,version,c->protocol.client.clienttag,conn_get_gameversion(c)); if (c->protocol.game && conn_get_realm(c) && conn_get_charname(c)) { game_set_realmname(c->protocol.game,realm_get_name(conn_get_realm(c))); realm_add_game_number(conn_get_realm(c),1); send_d2cs_gameinforeq(c); } } if (c->protocol.game) { if (game_add_player(conn_get_game(c),gamepass,version,c)<0) { c->protocol.game = NULL; // bad password or version # return -1; } if (game_is_ladder(c->protocol.game)) { if (c == game_get_owner(c->protocol.game)) message_send_text(c,message_type_info,c,"Created ladder game"); else message_send_text(c,message_type_info,c,"Joined ladder game"); } } } else c->protocol.game = NULL; return 0;}extern unsigned int conn_get_tcpaddr(t_connection * c){ if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return 0; } return c->socket.tcp_addr;}extern t_packet * conn_get_in_queue(t_connection * c){ assert(c); return c->protocol.queues.inqueue;}extern void conn_put_in_queue(t_connection * c, t_packet * packet){ assert(c); c->protocol.queues.inqueue = packet;}extern unsigned int conn_get_in_size(t_connection const * c){ if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return 0; } return c->protocol.queues.insize;}extern void conn_set_in_size(t_connection * c, unsigned int size){ if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return; } c->protocol.queues.insize = size;}extern unsigned int conn_get_out_size(t_connection const * c){ if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return 0; } return c->protocol.queues.outsize;}extern void conn_set_out_size(t_connection * c, unsigned int size){ if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return; } c->protocol.queues.outsize = size;}extern int conn_push_outqueue(t_connection * c, t_packet * packet){ if (!c) { eventlog(eventlog_level_error, __FUNCTION__, "got NULL connection"); return -1; } if (!packet) { eventlog(eventlog_level_error, __FUNCTION__, "got NULL packet"); return -1; } queue_push_packet((t_queue * *)&c->protocol.queues.outqueue, packet); if (!c->protocol.queues.outsizep++) fdwatch_update_fd(c->socket.fdw_idx, fdwatch_type_read | fdwatch_type_write); return 0;}extern t_packet * conn_peek_outqueue(t_connection * c){ if (!c) { eventlog(eventlog_level_error, __FUNCTION__, "got NULL connection"); return NULL; } return queue_peek_packet((t_queue const * const *)&c->protocol.queues.outqueue);}extern t_packet * conn_pull_outqueue(t_connection * c){ if (!c) { eventlog(eventlog_level_error, __FUNCTION__, "got NULL connection"); return NULL; } if (c->protocol.queues.outsizep) { if (!(--c->protocol.queues.outsizep)) fdwatch_update_fd(c->socket.fdw_idx, fdwatch_type_read); return queue_pull_packet((t_queue * *)&c->protocol.queues.outqueue); } return NULL;}extern char const * conn_get_username_real(t_connection const * c,char const * fn,unsigned int ln){ char const * result; if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection (from %s:%u)",fn,ln); return NULL; } if(!c->protocol.account) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL account (from %s:%u)",fn,ln); return NULL; } result = account_get_name(c->protocol.account); if (result == NULL) eventlog(eventlog_level_error,__FUNCTION__,"returned previous error after being called by %s:%u",fn,ln); return result;}extern char const * conn_get_chatname(t_connection const * c){ if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return NULL; } if ((c->protocol.class==conn_class_bnet) && c->protocol.bound) { if (c->protocol.d2.character) return character_get_name(c->protocol.d2.character); if (c->protocol.bound->protocol.d2.character) return character_get_name(c->protocol.bound->protocol.d2.character); eventlog(eventlog_level_error,__FUNCTION__,"[%d] got connection class %s bound to class %d without a character",conn_get_socket(c),conn_class_get_str(c->protocol.class),c->protocol.bound->protocol.class); } if (!c->protocol.account) return NULL; /* no name yet */ return conn_get_loggeduser(c);}extern int conn_unget_chatname(t_connection const * c, char const * name){ if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return -1; } if ((c->protocol.class==conn_class_bnet) && c->protocol.bound) return 0; return 0;}extern char const * conn_get_chatcharname(t_connection const * c, t_connection const * dst){ char const * accname; char * chatcharname; if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return NULL; } if (!c->protocol.account) return NULL; /* no name yet */ /* for D2 Users */ accname = conn_get_loggeduser(c); if (!accname) return NULL; if (dst && dst->protocol.d2.charname) { const char *mychar; if (c->protocol.d2.charname) mychar = c->protocol.d2.charname; else mychar = ""; chatcharname = xmalloc(strlen(accname) + 2 + strlen(mychar)); sprintf(chatcharname, "%s*%s", mychar, accname); } else chatcharname = xstrdup(accname); return chatcharname;}extern int conn_unget_chatcharname(t_connection const * c, char const * name){ if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return -1; } if (!name) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL name"); return -1; } xfree((void *)name); /* avoid warning */ return 0;}extern t_message_class conn_get_message_class(t_connection const * c, t_connection const * dst){ if (dst && dst->protocol.d2.charname) /* message to D2 user must be char*account */ return message_class_charjoin; return message_class_normal;}extern unsigned int conn_get_userid(t_connection const * c){ if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return 0; } if(!c->protocol.account) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL account"); return 0; } return account_get_uid(c->protocol.account);}extern int conn_get_socket(t_connection const * c){ if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return -1; } return c->socket.tcp_sock;}extern int conn_get_game_socket(t_connection const * c){ if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return -1; } return c->socket.udp_sock;}extern int conn_set_game_socket(t_connection * c, int usock){ if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return -1; } c->socket.udp_sock = usock; return 0;}extern char const * conn_get_playerinfo(t_connection const * c){ t_account * account; static char playerinfo[MAX_PLAYERINFO_STR]; t_clienttag clienttag; char revtag[5]; if (!c) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL connection"); return NULL; } if (!(account = conn_get_account(c))) { eventlog(eventlog_level_error,__FUNCTION__,"connection has no account"); return NULL; } if (!(clienttag = conn_get_fake_clienttag(c))) { eventlog(eventlog_level_error,__FUNCTION__,"connection has NULL fakeclienttag"); return NULL; } tag_uint_to_revstr(revtag,clienttag); if (clienttag==CLIENTTAG_BNCHATBOT_UINT) { strcpy(playerinfo,revtag); /* FIXME: what to return here? */ } else if ((clienttag==CLIENTTAG_STARCRAFT_UINT) || (clienttag==CLIENTTAG_BROODWARS_UINT)) { if (conn_get_versionid(c)<=0x000000c7) { sprintf(playerinfo,"%s %u %u %u %u %u", revtag, account_get_ladder_rating(account,clienttag,ladder_id_normal), account_get_ladder_rank(account,clienttag,ladder_id_normal), account_get_normal_wins(account,clienttag), 0,0); } else { sprintf(playerinfo,"%s %u %u %u %u %u %u %u %u %s", revtag, account_get_ladder_rating(account,clienttag,ladder_id_normal), account_get_ladder_rank(account,clienttag,ladder_id_normal), account_get_normal_wins(account,clienttag), 0,0, account_get_ladder_high_rating(account,clienttag,ladder_id_normal), 0,0, revtag); } } else if (clienttag==CLIENTTAG_SHAREWARE_UINT) { sprintf(playerinfo,"%s %u %u %u %u %u", revtag, account_get_ladder_rating(account,clienttag,ladder_id_normal), account_get_ladder_rank(account,clienttag,ladder_id_normal), account_get_normal_wins(account,clienttag), 0,0); } else if (clienttag==CLIENTTAG_DIABLORTL_UINT) { sprintf(playerinfo,"%s %u %u %u %u %u %u %u %u %u", revtag, account_get_normal_level(account,clienttag), account_get_normal_class(account,clienttag), account_get_normal_diablo_kills(account,clienttag), account_get_normal_strength(account,clienttag), account_get_normal_magic(account,clienttag), account_get_normal_dexterity(account,clienttag), account_get_normal_vitality(account,clienttag), account_get_normal_gold(account,clienttag), 0); } else if (clienttag==CLIENTTAG_DIABLOSHR_UINT) { sprintf(play
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -