extern int realmlist_reload(char const * filename) { t_elem * new_curr; t_elem * old_curr; t_realm * new_realm; t_realm * old_realm; int match; t_list * newlist = NULL; t_list * oldlist = realmlist_head; realmlist_head = NULL; if (!(newlist = realmlist_load(filename))) return -1; LIST_TRAVERSE(oldlist,old_curr) { if (!(old_realm = elem_get_data(old_curr))) { eventlog(eventlog_level_error,__FUNCTION__,"found NULL elem in list"); continue; } match = 0; LIST_TRAVERSE(newlist,new_curr) { if (!(new_realm = elem_get_data(new_curr))) { eventlog(eventlog_level_error,__FUNCTION__,"found NULL elem in list"); continue; } if (!strcmp(old_realm->name,new_realm->name)) { match = 1; rcm_chref(&old_realm->rcm,new_realm); break; } } if (!match) rcm_chref(&old_realm->rcm,NULL); realm_destroy(old_realm); list_remove_elem(oldlist,&old_curr); } list_destroy(oldlist); realmlist_head = newlist; realm_number = 0; return 0; }
static int _handle_list_command(t_connection * conn, int numparams, char ** params, char * text) { char temp[MAX_IRC_MESSAGE_LEN]; irc_send(conn,RPL_LISTSTART,"Channel :Users Names"); /* backward compatibility */ if (numparams==0) { t_elem const * curr; LIST_TRAVERSE_CONST(channellist(),curr) { t_channel const * channel = (const t_channel*)elem_get_data(curr); char const * tempname; char * topic = channel_get_topic(channel_get_name(channel)); tempname = irc_convert_channel(channel,conn); /* FIXME: AARON: only list channels like in /channels command */ if (topic) { if (std::strlen(tempname)+1+20+1+1+std::strlen(topic)<MAX_IRC_MESSAGE_LEN) snprintf(temp, sizeof(temp), "%s %u :%s",tempname,channel_get_length(channel),topic); else eventlog(eventlog_level_warn,__FUNCTION__,"LISTREPLY length exceeded"); } else { if (std::strlen(tempname)+1+20+1+1<MAX_IRC_MESSAGE_LEN) snprintf(temp, sizeof(temp), "%s %u :",tempname,channel_get_length(channel)); else eventlog(eventlog_level_warn,__FUNCTION__,"LISTREPLY length exceeded"); } irc_send(conn,RPL_LIST,temp); }
extern int tracker_set_servers(char const * servers) { t_addr const * addr; t_elem const * curr; char temp[32]; if (track_servers && addrlist_destroy(track_servers)<0) eventlog(eventlog_level_error,__FUNCTION__,"unable to destroy tracker list"); if (!servers) { track_servers = NULL; return 0; } if (!(track_servers = addrlist_create(servers,INADDR_LOOPBACK,BNETD_TRACK_PORT))) { eventlog(eventlog_level_error,__FUNCTION__,"could not create tracking server list"); return -1; } LIST_TRAVERSE_CONST(track_servers,curr) { addr = elem_get_data(curr); if (!addr_get_addr_str(addr,temp,sizeof(temp))) strcpy(temp,"x.x.x.x:x"); eventlog(eventlog_level_info,__FUNCTION__,"tracking packets will be sent to %s",temp); }
int topiclist_save(char const * topic_file) { t_elem * curr; t_topic * topic; std::FILE * fp; if (topiclist_head) { if ((fp = std::fopen(topic_file, "w")) == NULL) { eventlog(eventlog_level_error, __FUNCTION__, "can't open topic file"); return -1; } LIST_TRAVERSE(topiclist_head, curr) { if (!(topic = (t_topic*)elem_get_data(curr))) { eventlog(eventlog_level_error, __FUNCTION__, "found NULL entry in list"); continue; } if (topic->save == DO_SAVE_TOPIC) std::fprintf(fp, "\"%s\",\"%s\"\n", topic->channel_name, topic->topic); } std::fclose(fp); } return 0; }
/* Get friend list of account */ extern int __account_get_friends(lua_State* L) { const char *username; std::vector<std::map<std::string, std::string> > friends; try { lua::stack st(L); // get args st.at(1, username); if (t_account * account = accountlist_find_account(username)) if (t_list *friendlist = account_get_friends(account)) { t_elem const * curr; t_friend * f; LIST_TRAVERSE_CONST(friendlist, curr) { if (!(f = (t_friend*)elem_get_data(curr))) { eventlog(eventlog_level_error, __FUNCTION__, "found NULL entry in list"); continue; } friends.push_back(get_friend_object(f)); } } st.push(friends); }
int topiclist_unload(void) { t_elem * curr; t_topic * topic; if (topiclist_head) { LIST_TRAVERSE(topiclist_head, curr) { if (!(topic = (t_topic*)elem_get_data(curr))) { eventlog(eventlog_level_error, __FUNCTION__, "found NULL entry in list"); continue; } if (topic->channel_name) xfree((void *)topic->channel_name); if (topic->topic) xfree((void *)topic->topic); xfree((void *)topic); list_remove_elem(topiclist_head, &curr); } if (list_destroy(topiclist_head) < 0) return -1; topiclist_head = NULL; } return 0; }
extern int timerlist_del_all_timers(t_connection * owner) { t_elem * curr; t_timer * timer; if (!owner) { eventlog(eventlog_level_error,"timerlist_del_all_timers","got NULL owner"); return -1; } LIST_TRAVERSE(timerlist_head,curr) { timer = elem_get_data(curr); if (!timer) /* should not happen */ { eventlog(eventlog_level_error,"timerlist_del_all_timers","timerlist contains NULL item"); return -1; } if (timer->owner==owner) { if (timer->cb) timer->cb(timer->owner,(time_t)0,timer->data); timer->cb = NULL; timer->owner = NULL; if (list_remove_elem(timerlist_head,curr)<0) { eventlog(eventlog_level_error,"timerlist_del_all_timers","could not remove timer"); continue; } free(timer); } }
int dbs_server_setup_fdsets(t_psock_fd_set * pReadFDs, t_psock_fd_set * pWriteFDs, t_psock_fd_set * pExceptFDs, int lsocket) { t_elem const * elem; t_d2dbs_connection* it; int highest_fd; PSOCK_FD_ZERO(pReadFDs); PSOCK_FD_ZERO(pWriteFDs); PSOCK_FD_ZERO(pExceptFDs); /* FIXME: don't check these... remove this code */ /* Add the listener socket to the read and except FD sets, if there is one. */ if (lsocket >= 0) { PSOCK_FD_SET(lsocket, pReadFDs); PSOCK_FD_SET(lsocket, pExceptFDs); } highest_fd=lsocket; LIST_TRAVERSE_CONST(dbs_server_connection_list,elem) { if (!(it=elem_get_data(elem))) continue; if (it->nCharsInReadBuffer < (kBufferSize-kMaxPacketLength)) { /* There's space in the read buffer, so pay attention to incoming data. */ PSOCK_FD_SET(it->sd, pReadFDs); } if (it->nCharsInWriteBuffer > 0) { PSOCK_FD_SET(it->sd, pWriteFDs); } PSOCK_FD_SET(it->sd, pExceptFDs); if (highest_fd < it->sd) highest_fd=it->sd; } return highest_fd; }
extern int characterlist_destroy(void) { t_elem * curr; t_character * ch; if (characterlist_head) { LIST_TRAVERSE(characterlist_head,curr) { ch = (t_character*)elem_get_data(curr); if (!ch) /* should not happen */ { eventlog(eventlog_level_error,__FUNCTION__,"characterlist contains NULL item"); continue; } if (list_remove_elem(characterlist_head,&curr)<0) eventlog(eventlog_level_error,__FUNCTION__,"could not remove item from list"); xfree(ch); } if (list_destroy(characterlist_head)<0) return -1; characterlist_head = NULL; }
extern int gametrans_unload(void) { t_elem * curr; t_gametrans * entry; if (gametrans_head) { LIST_TRAVERSE(gametrans_head,curr) { if (!(entry = elem_get_data(curr))) eventlog(eventlog_level_error,"gametrans_unload","found NULL entry in list"); else { netaddr_destroy(entry->exclude); addr_destroy(entry->output); addr_destroy(entry->client); addr_destroy(entry->viewer); free(entry); } list_remove_elem(gametrans_head,curr); } list_destroy(gametrans_head); gametrans_head = NULL; } return 0; }
extern int trans_net(unsigned int clientaddr, unsigned int *addr, unsigned short *port) { t_elem const *curr; t_trans *entry; char temp1[32]; char temp2[32]; char temp3[32]; char temp4[32]; #ifdef DEBUG_TRANS eventlog(eventlog_level_debug, __FUNCTION__, "checking %s for client %s ...", addr_num_to_addr_str(*addr, *port), addr_num_to_ip_str(clientaddr)); #endif if (trans_head) { LIST_TRAVERSE_CONST(trans_head, curr) { if (!(entry = (t_trans*)elem_get_data(curr))) { eventlog(eventlog_level_error, __FUNCTION__, "found NULL entry in list"); continue; } #ifdef DEBUG_TRANS eventlog(eventlog_level_debug, __FUNCTION__, "against entry -> %s output %s network %s", addr_get_addr_str(entry->input, temp1, sizeof(temp1)), addr_get_addr_str(entry->output, temp2, sizeof(temp2)), netaddr_get_addr_str(entry->network, temp3, sizeof(temp3))); #endif if (addr_get_ip(entry->input) != *addr || addr_get_port(entry->input) != *port) { #ifdef DEBUG_TRANS eventlog(eventlog_level_debug, __FUNCTION__, "entry does match input address"); #endif continue; } if (netaddr_contains_addr_num(entry->network, clientaddr) == 0) { #ifdef DEBUG_TRANS eventlog(eventlog_level_debug, __FUNCTION__, "client is not in the correct network"); #endif continue; } #ifdef DEBUG_TRANS eventlog(eventlog_level_debug, __FUNCTION__, "%s translated to %s", addr_num_to_addr_str(*addr, *port), addr_get_addr_str(entry->output, temp4, sizeof(temp4))); #endif *addr = addr_get_ip(entry->output); *port = addr_get_port(entry->output); return 1; /* match found in list */ } } #ifdef DEBUG_TRANS eventlog(eventlog_level_debug, __FUNCTION__, "no match found for %s (not translated)", addr_num_to_addr_str(*addr, *port)); #endif return 0; /* no match found in list */ }
extern t_bits_routing_table_entry * bits_route_find(t_uint16 bits_addr) { t_elem const * curr; LIST_TRAVERSE_CONST(bits_routing_table,curr) { t_bits_routing_table_entry * rte = elem_get_data(curr); if (rte->bits_addr==bits_addr) return rte; }
extern int bits_game_sendlist(t_connection * c) { t_elem const * curr; if (!bits_uplink_connection) { /* bits master server */ t_game * game; LIST_TRAVERSE_CONST(gamelist(),curr) { game = elem_get_data(curr); send_bits_gamelist_add(c,game); }
extern t_connection * bits_va_locklist_is_locked_by(int uid) { t_connection *c; t_elem const * curr; LIST_TRAVERSE_CONST(connlist(),curr) { c = elem_get_data(curr); if (conn_get_class(c) == conn_class_bits) { if (bits_va_locklist_byuid(c,uid)) return c; } }
extern unsigned int command_get_group(char const * command) { t_elem const * curr; t_command_groups * entry; if (command_groups_head) { LIST_TRAVERSE(command_groups_head,curr) { if (!(entry = (t_command_groups*)elem_get_data(curr))) eventlog(eventlog_level_error,__FUNCTION__,"found NULL entry in list"); else if (!(std::strcmp(entry->command,command))) return entry->group; } } return 0; }
int d2ladderlist_destroy(void) { t_d2ladder * d2ladder; t_elem * elem; if (!d2ladder_list) return -1; LIST_TRAVERSE(d2ladder_list,elem) { if (!(d2ladder=(t_d2ladder*)elem_get_data(elem))) continue; xfree(d2ladder); list_remove_elem(d2ladder_list,&elem); } list_destroy(d2ladder_list); return 0; }
extern char * autoupdate_check(t_tag archtag, t_tag clienttag, t_tag gamelang, char const * versiontag) { if (autoupdate_head) { t_elem const * curr; t_autoupdate * entry; char * temp; LIST_TRAVERSE_CONST(autoupdate_head,curr) { if (!(entry = (t_autoupdate*)elem_get_data(curr))) { eventlog(eventlog_level_error,__FUNCTION__,"found NULL entry in list"); continue; } if (entry->archtag != archtag) continue; if (entry->clienttag != clienttag) continue; if (strcmp(entry->versiontag, versiontag) != 0) continue; /* if we have a gamelang then add it to the mpq file name */ if ((gamelang) && // so far only WAR3 uses gamelang specific MPQs! ((clienttag == CLIENTTAG_WARCRAFT3_UINT) || (clienttag == CLIENTTAG_WAR3XP_UINT))){ char gltag[5]; char * tempmpq; char * extention; tag_uint_to_str(gltag,gamelang); tempmpq = xstrdup(entry->mpqfile); temp = (char*)xmalloc(strlen(tempmpq)+6); extention = strrchr(tempmpq,'.'); *extention = '\0'; extention++; sprintf(temp, "%s_%s.%s", tempmpq, gltag, extention); xfree((void *)tempmpq); return temp; } temp = xstrdup(entry->mpqfile); return temp; } } return NULL; }
static t_apiregmember * apireglist_find_apiregmember_by_conn(t_connection * conn) { t_apiregmember * apiregmember; t_elem * curr; if (!conn) { ERROR0("got NULL conn"); return NULL; } LIST_TRAVERSE(apireglist(),curr) { t_apiregmember * apiregmember = (t_apiregmember *)elem_get_data(curr); if (conn == apiregmember_get_conn(apiregmember)) { return apiregmember; } }
static t_anongame_wol_player * anongame_wol_matchlist_find_player_by_conn(t_connection * conn) { t_anongame_wol_player * player; t_elem * curr; if (!conn) { ERROR0("got NULL conn"); return NULL; } LIST_TRAVERSE(anongame_wol_matchlist(),curr) { t_anongame_wol_player * player = (t_anongame_wol_player *)elem_get_data(curr); if (conn == anongame_wol_player_get_conn(player)) { return player; } }
extern int friendlist_unload(t_list * flist) { t_elem * curr; t_friend * fr; if(flist==NULL) return -1; LIST_TRAVERSE(flist,curr) { if (!(fr = elem_get_data(curr))) { eventlog(eventlog_level_error,__FUNCTION__,"found NULL entry in list"); continue; } fr->mutual=-1; } return 0; }
extern t_realm * realmlist_find_realm(char const * realmname) { t_elem const * curr; t_realm * realm; if (!realmname) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL realmname"); return NULL; } LIST_TRAVERSE_CONST(realmlist_head,curr) { realm = elem_get_data(curr); if (strcasecmp(realm->name,realmname)==0) return realm; }
t_d2ladder * d2ladderlist_find_type(unsigned int type) { t_d2ladder * d2ladder; t_elem const * elem; if (!d2ladder_list) { eventlog(eventlog_level_error,__FUNCTION__,"got NULL d2ladder_list"); return NULL; } LIST_TRAVERSE_CONST(d2ladder_list,elem) { if (!(d2ladder=(t_d2ladder*)elem_get_data(elem))) continue; if (d2ladder->type==type) return d2ladder; } eventlog(eventlog_level_error,__FUNCTION__,"could not find type %d in d2ladder_list",type); return NULL; }
extern t_friend * friendlist_find_uid(t_list * flist, int uid) { t_elem * curr; t_friend * fr; if(flist==NULL) return NULL; LIST_TRAVERSE(flist,curr) { if (!(fr = elem_get_data(curr))) { eventlog(eventlog_level_error,__FUNCTION__,"found NULL entry in list"); continue; } if (account_get_uid(fr->friendacc)==uid) return fr; } return NULL; }
extern t_friend * friendlist_find_username(t_list * flist, const char * accname) { t_elem * curr; t_friend * fr; if(flist==NULL) return NULL; LIST_TRAVERSE(flist,curr) { if (!(fr = elem_get_data(curr))) { eventlog(eventlog_level_error,__FUNCTION__,"found NULL entry in list"); continue; } if (strcasecmp(account_get_name(fr->friendacc),accname)==0) return fr; } return NULL; }
extern t_versioncheck * versioncheck_create(t_tag archtag, t_tag clienttag) { t_elem const * curr; t_versioninfo * vi; t_versioncheck * vc; char archtag_str[5]; char clienttag_str[5]; LIST_TRAVERSE_CONST(versioninfo_head,curr) { if (!(vi = (t_versioninfo*)elem_get_data(curr))) /* should not happen */ { eventlog(eventlog_level_error,__FUNCTION__,"version list contains NULL item"); continue; } eventlog(eventlog_level_debug,__FUNCTION__,"version check entry archtag=%s, clienttag=%s", tag_uint_to_str(archtag_str,vi->archtag), tag_uint_to_str(clienttag_str,vi->clienttag)); if (vi->archtag != archtag) continue; if (vi->clienttag != clienttag) continue; /* FIXME: randomize the selection if more than one match */ vc = (t_versioncheck*)xmalloc(sizeof(t_versioncheck)); vc->eqn = xstrdup(vi->eqn); vc->mpqfile = xstrdup(vi->mpqfile); vc->versiontag = xstrdup(tag_uint_to_str(clienttag_str,clienttag)); return vc; } /* * No entries in the file that match, return the dummy because we have to send * some equation and auth mpq to the client. The client is not going to pass the * validation later unless skip_versioncheck or allow_unknown_version is enabled. */ return &dummyvc; }
extern int realmlist_unload(t_list * list_head) { t_elem * curr; t_realm * realm; if (list_head) { LIST_TRAVERSE(list_head,curr) { if (!(realm = elem_get_data(curr))) eventlog(eventlog_level_error,__FUNCTION__,"found NULL realm in list"); else realm_destroy(realm); list_remove_elem(list_head,&curr); } list_destroy(list_head); } return 0; }
extern int apireglist_destroy(void) { t_apiregmember * apiregmember; t_elem * curr; if (apireglist_head) { LIST_TRAVERSE(apireglist_head,curr) { if (!(apiregmember = (t_apiregmember*)elem_get_data(curr))) { ERROR0("channel list contains NULL item"); continue; } apiregmember_destroy(apiregmember,&curr); } if (list_destroy(apireglist_head)<0) return -1; apireglist_head = NULL; } return 0; }
extern int realmlist_destroy(void) { t_elem * curr; t_realm * realm; if (realmlist_head) { LIST_TRAVERSE(realmlist_head,curr) { if (!(realm = elem_get_data(curr))) eventlog(eventlog_level_error,"realmlist_destroy","found NULL realm in list"); else realm_destroy(realm); list_remove_elem(realmlist_head,curr); } list_destroy(realmlist_head); realmlist_head = NULL; } return 0; }
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); }
extern int anongame_wol_matchlist_destroy(void) { t_anongame_wol_player * player; t_elem * curr; if (anongame_wol_matchlist_head) { LIST_TRAVERSE(anongame_wol_matchlist_head,curr) { if (!(player = (t_anongame_wol_player*)elem_get_data(curr))) { /* should not happen */ ERROR0("wol_matchlist contains NULL item"); continue; } anongame_wol_player_destroy(player,&curr); } if (list_destroy(anongame_wol_matchlist_head)<0) return -1; anongame_wol_matchlist_head = NULL; } return 0; }