void CSbmfcsampleDlg::AddServer(SBServer server, BOOL checkForReplace) { // set the progress if(ServerBrowserCount(m_serverBrowser) > 0) m_progress.SetPos((ServerBrowserCount(m_serverBrowser) - ServerBrowserPendingQueryCount(m_serverBrowser)) * 100 / ServerBrowserCount(m_serverBrowser)); // check for the server in the list int index = FindServer(server); bool replace = (index != -1); // if we didn't find a server to replace, append if(!replace) index = m_serverList.GetItemCount(); // set or insert the hostname const char * hostname = SBServerGetStringValue(server, "hostname","(NO NAME)"); if(replace) { m_serverList.SetItem(index, COL_SERVERNAME, LVIF_TEXT, hostname, -1, 0, 0, NULL); } else { m_serverList.InsertItem(index, hostname); m_serverList.SetItem(index, COL_SERVERNAME, LVIF_PARAM, NULL, -1, 0, 0, (LPARAM)server); } // set the rest of the columns int numplayers = SBServerGetIntValue(server, "numplayers", 0); CString ping, players; if (SBServerHasValidPing(server)) ping.Format("%d%s", SBServerGetPing(server), SBServerDirectConnect(server) ? "" : "i"); else ping = "Unknown"; players.Format("%d/%d", numplayers, SBServerGetIntValue(server, "maxplayers", 0)); m_serverList.SetItem(index, COL_PING, LVIF_TEXT, ping, -1, 0, 0, 0); m_serverList.SetItem(index, COL_PLAYERS, LVIF_TEXT, players, -1, 0, 0, 0); m_serverList.SetItem(index, COL_MAPNAME, LVIF_TEXT, SBServerGetStringValue(server, "mapname", "(NO MAP)"), -1, 0, 0, 0); m_serverList.SetItem(index, COL_GAMETYPE, LVIF_TEXT, SBServerGetStringValue(server, "gametype", ""), -1, 0, 0, 0); // update server count if(!replace) { CString str; str.Format("%d", ++m_serverCount); m_servers.SetWindowText(str); } GSI_UNUSED(checkForReplace); }
void CSbmfcsampleDlg::OnColumnclickServerlist(NMHDR* pNMHDR, LRESULT* pResult) { NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR; // track ascending/descending static bool ascending = false; ascending = !ascending; //figure out which column they clicked switch(pNMListView->iSubItem) { case COL_SERVERNAME: ServerBrowserSort(m_serverBrowser, (SBBool)ascending, "hostname", sbcm_stricase); break; case COL_PING: ServerBrowserSort(m_serverBrowser, (SBBool)ascending, "ping", sbcm_int); break; case COL_PLAYERS: ServerBrowserSort(m_serverBrowser, (SBBool)ascending, "numplayers", sbcm_int); break; case COL_MAPNAME: ServerBrowserSort(m_serverBrowser, (SBBool)ascending, "mapname", sbcm_stricase); break; case COL_GAMETYPE: ServerBrowserSort(m_serverBrowser, (SBBool)ascending, "gametype", sbcm_stricase); break; } // we don't want the server list to redraw every time we insert a server! m_serverList.SetRedraw(false); // clear the server list m_serverList.DeleteAllItems(); // clear the server count m_serverCount = 0; m_servers.SetWindowText("0"); // go through the list of servers for(int i = 0; i < ServerBrowserCount(m_serverBrowser) ; i++) { // if we got basic info for it, put it back in the list SBServer server = ServerBrowserGetServer(m_serverBrowser, i); if(SBServerHasBasicKeys(server)) AddServer(server, FALSE); } // let the server list redraw itself now that we're done updating m_serverList.SetRedraw(true); *pResult = 0; }
void CClientDlg::RefillServersList () { OutputDebugString("CClientDlg::RefillServersList \n"); ClearHostList(); // clear the server count // m_serverCount = 0; // m_servers.SetWindowText("0"); // go through the list of servers for(int i = 0; i < ServerBrowserCount(m_serverBrowser) ; i++) { // if we got basic info for it, put it back in the list SBServer server = ServerBrowserGetServer(m_serverBrowser, i); // if(SBServerHasBasicKeys(server)) AddServerToList(server);//, FALSE); } UpdateServersList(); };