Upstream tarball 10153
[amule.git] / src / ServerListCtrl.cpp
blobe177a65b8838fa8f9fcb75c36fa16382780de794
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2008 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2008 Merkur ( devs@emule-project.net / http://www.emule-project.net )
6 //
7 // Any parts of this program derived from the xMule, lMule or eMule project,
8 // or contributed by third-party developers are copyrighted by their
9 // respective authors.
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 of the License, or
14 // (at your option) any later version.
16 // This program is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU General Public License for more details.
20 //
21 // You should have received a copy of the GNU General Public License
22 // along with this program; if not, write to the Free Software
23 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
26 #include "ServerListCtrl.h" // Interface declarations
28 #include <common/MenuIDs.h>
30 #include <wx/menu.h>
31 #include <wx/stattext.h>
32 #include <wx/msgdlg.h>
33 #include <wx/settings.h>
35 #include "amule.h" // Needed for theApp
36 #include "DownloadQueue.h" // Needed for CDownloadQueue
37 #ifdef ENABLE_IP2COUNTRY
38 #include "IP2Country.h" // Needed for IP2Country
39 #include "amuleDlg.h" // Needed for IP2Country
40 #endif
41 #include "ServerList.h" // Needed for CServerList
42 #include "ServerConnect.h" // Needed for CServerConnect
43 #include "Server.h" // Needed for CServer and SRV_PR_*
44 #include "Logger.h"
45 #include <common/Format.h> // Needed for CFormat
46 #include <common/TextFile.h> // Needed for CTextFile
49 #define CMuleColour(x) (wxSystemSettings::GetColour(x))
52 BEGIN_EVENT_TABLE(CServerListCtrl,CMuleListCtrl)
53 EVT_LIST_ITEM_RIGHT_CLICK( -1, CServerListCtrl::OnItemRightClicked)
54 EVT_LIST_ITEM_ACTIVATED( -1, CServerListCtrl::OnItemActivated )
56 EVT_MENU( MP_PRIOLOW, CServerListCtrl::OnPriorityChange )
57 EVT_MENU( MP_PRIONORMAL, CServerListCtrl::OnPriorityChange )
58 EVT_MENU( MP_PRIOHIGH, CServerListCtrl::OnPriorityChange )
60 EVT_MENU( MP_ADDTOSTATIC, CServerListCtrl::OnStaticChange )
61 EVT_MENU( MP_REMOVEFROMSTATIC, CServerListCtrl::OnStaticChange )
63 EVT_MENU( MP_CONNECTTO, CServerListCtrl::OnConnectToServer )
65 EVT_MENU( MP_REMOVE, CServerListCtrl::OnRemoveServers )
66 EVT_MENU( MP_REMOVEALL, CServerListCtrl::OnRemoveServers )
68 EVT_MENU( MP_GETED2KLINK, CServerListCtrl::OnGetED2kURL )
70 EVT_CHAR( CServerListCtrl::OnKeyPressed )
71 END_EVENT_TABLE()
75 CServerListCtrl::CServerListCtrl( wxWindow *parent, wxWindowID winid, const wxPoint& pos, const wxSize& size,
76 long style, const wxValidator& validator, const wxString& name )
77 : CMuleListCtrl( parent, winid, pos, size, style, validator, name )
79 // Setting the sorter function.
80 SetSortFunc( SortProc );
82 // Set the table-name (for loading and saving preferences).
83 SetTableName( wxT("Server") );
85 m_connected = 0;
87 InsertColumn( COLUMN_SERVER_NAME, _("Server Name"), wxLIST_FORMAT_LEFT, 150, wxT("N") );
88 InsertColumn( COLUMN_SERVER_ADDR, _("Address"), wxLIST_FORMAT_LEFT, 140, wxT("A") );
89 InsertColumn( COLUMN_SERVER_PORT, _("Port"), wxLIST_FORMAT_LEFT, 25, wxT("P") );
90 InsertColumn( COLUMN_SERVER_DESC, _("Description"), wxLIST_FORMAT_LEFT, 150, wxT("D") );
91 InsertColumn( COLUMN_SERVER_PING, _("Ping"), wxLIST_FORMAT_LEFT, 25, wxT("p") );
92 InsertColumn( COLUMN_SERVER_USERS, _("Users"), wxLIST_FORMAT_LEFT, 40, wxT("U") );
93 InsertColumn( COLUMN_SERVER_FILES, _("Files"), wxLIST_FORMAT_LEFT, 45, wxT("F") );
94 InsertColumn( COLUMN_SERVER_PRIO, _("Priority"), wxLIST_FORMAT_LEFT, 60, wxT("r") );
95 InsertColumn( COLUMN_SERVER_FAILS, _("Failed"), wxLIST_FORMAT_LEFT, 40, wxT("f") );
96 InsertColumn( COLUMN_SERVER_STATIC, _("Static"), wxLIST_FORMAT_LEFT, 40, wxT("S") );
97 InsertColumn( COLUMN_SERVER_VERSION, _("Version"), wxLIST_FORMAT_LEFT, 80, wxT("V") );
98 #ifdef __DEBUG__
99 InsertColumn( COLUMN_SERVER_TCPFLAGS, wxT("TCP Flags"), wxLIST_FORMAT_LEFT, 80, wxT("t") );
100 InsertColumn( COLUMN_SERVER_UDPFLAGS, wxT("UDP Flags"), wxLIST_FORMAT_LEFT, 80, wxT("u") );
101 #endif
104 LoadSettings();
108 wxString CServerListCtrl::GetOldColumnOrder() const
110 return wxT("N,A,P,D,p,U,F,r,f,S,V,t,u");
114 CServerListCtrl::~CServerListCtrl()
119 void CServerListCtrl::AddServer( CServer* toadd )
121 // RefreshServer will add the server.
122 // This also means that we have simple duplicity checking. ;)
123 RefreshServer( toadd );
125 ShowServerCount();
129 void CServerListCtrl::RemoveServer(CServer* server)
131 long result = FindItem(-1, reinterpret_cast<wxUIntPtr>(server));
132 if ( result != -1 ) {
133 DeleteItem(result);
134 ShowServerCount();
139 void CServerListCtrl::RemoveAllServers(int state)
141 int pos = GetNextItem( -1, wxLIST_NEXT_ALL, state);
142 bool connected = theApp->IsConnectedED2K() ||
143 theApp->serverconnect->IsConnecting();
145 while ( pos != -1 ) {
146 CServer* server = (CServer*)GetItemData(pos);
148 if (reinterpret_cast<wxUIntPtr>(server) == m_connected && connected) {
149 wxMessageBox(_("You are connected to a server you are trying to delete. Please disconnect first. The server was NOT deleted."), _("Info"), wxOK, this);
150 ++pos;
151 } else if (server->IsStaticMember()) {
152 const wxString name = (!server->GetListName() ? wxString(_("(Unknown name)")) : server->GetListName());
154 if (wxMessageBox(CFormat(_("Are you sure you want to delete the static server %s")) % name, _("Cancel"), wxICON_QUESTION | wxYES_NO, this) == wxYES) {
155 SetStaticServer(server, false);
156 DeleteItem( pos );
157 theApp->serverlist->RemoveServer( server );
158 } else {
159 ++pos;
161 } else {
162 DeleteItem( pos );
163 theApp->serverlist->RemoveServer( server );
166 pos = GetNextItem(pos - 1, wxLIST_NEXT_ALL, state);
169 ShowServerCount();
173 void CServerListCtrl::RefreshServer( CServer* server )
175 // Cant really refresh a NULL server
176 if (!server) {
177 return;
180 wxUIntPtr ptr = reinterpret_cast<wxUIntPtr>(server);
181 long itemnr = FindItem( -1, ptr );
182 if ( itemnr == -1 ) {
183 // We are not at the sure that the server isn't in the list, so we can re-add
184 itemnr = InsertItem( GetInsertPos( ptr ), server->GetListName() );
185 SetItemPtrData( itemnr, ptr );
187 wxListItem item;
188 item.SetId( itemnr );
189 item.SetBackgroundColour(CMuleColour(wxSYS_COLOUR_LISTBOX));
190 SetItem( item );
193 wxString serverName;
194 #ifdef ENABLE_IP2COUNTRY
195 // Get the country name
196 if (theApp->amuledlg->m_IP2Country->IsEnabled()) {
197 const CountryData& countrydata = theApp->amuledlg->m_IP2Country->GetCountryData(server->GetFullIP());
198 serverName << countrydata.Name;
199 serverName << wxT(" - ");
201 #endif // ENABLE_IP2COUNTRY
202 serverName << server->GetListName();
203 SetItem(itemnr, COLUMN_SERVER_NAME, serverName);
204 SetItem(itemnr, COLUMN_SERVER_ADDR, server->GetAddress());
205 if (server->GetAuxPortsList().IsEmpty()) {
206 SetItem( itemnr, COLUMN_SERVER_PORT,
207 wxString::Format(wxT("%u"), server->GetPort()));
208 } else {
209 SetItem( itemnr, COLUMN_SERVER_PORT,
210 wxString::Format(wxT("%u ("),
211 server->GetPort()) + server->GetAuxPortsList() + wxT(")") );
213 SetItem( itemnr, COLUMN_SERVER_DESC, server->GetDescription() );
215 if ( server->GetPing() ) {
216 SetItem( itemnr, COLUMN_SERVER_PING,
217 CastSecondsToHM(server->GetPing()/1000, server->GetPing() % 1000 ) );
218 } else {
219 SetItem( itemnr, COLUMN_SERVER_PING, wxEmptyString );
222 if ( server->GetUsers() ) {
223 SetItem( itemnr, COLUMN_SERVER_USERS,
224 wxString::Format( wxT("%u"), server->GetUsers() ) );
225 } else {
226 SetItem( itemnr, COLUMN_SERVER_USERS, wxEmptyString );
229 if ( server->GetFiles() ) {
230 SetItem( itemnr, COLUMN_SERVER_FILES,
231 wxString::Format( wxT("%u"), server->GetFiles() ) );
232 } else {
233 SetItem( itemnr, COLUMN_SERVER_FILES, wxEmptyString );
236 switch ( server->GetPreferences() ) {
237 case SRV_PR_LOW: SetItem(itemnr, COLUMN_SERVER_PRIO, _("Low")); break;
238 case SRV_PR_NORMAL: SetItem(itemnr, COLUMN_SERVER_PRIO, _("Normal")); break;
239 case SRV_PR_HIGH: SetItem(itemnr, COLUMN_SERVER_PRIO, _("High") ); break;
240 default: SetItem(itemnr, COLUMN_SERVER_PRIO, wxT("---")); // this should never happen
243 SetItem( itemnr, COLUMN_SERVER_FAILS, wxString::Format( wxT("%u"),server->GetFailedCount() ) );
244 SetItem( itemnr, COLUMN_SERVER_STATIC, ( server->IsStaticMember() ? _("Yes") : _("No") ) );
245 SetItem( itemnr, COLUMN_SERVER_VERSION, server->GetVersion() );
247 #ifdef __DEBUG__
248 wxString flags;
249 /* TCP */
250 if (server->GetTCPFlags() & SRV_TCPFLG_COMPRESSION) {
251 flags += wxT("c");
253 if (server->GetTCPFlags() & SRV_TCPFLG_NEWTAGS) {
254 flags += wxT("n");
256 if (server->GetTCPFlags() & SRV_TCPFLG_UNICODE) {
257 flags += wxT("u");
259 if (server->GetTCPFlags() & SRV_TCPFLG_RELATEDSEARCH) {
260 flags += wxT("r");
262 if (server->GetTCPFlags() & SRV_TCPFLG_TYPETAGINTEGER) {
263 flags += wxT("t");
265 if (server->GetTCPFlags() & SRV_TCPFLG_LARGEFILES) {
266 flags += wxT("l");
268 if (server->GetTCPFlags() & SRV_TCPFLG_TCPOBFUSCATION) {
269 flags += wxT("o");
272 SetItem( itemnr, COLUMN_SERVER_TCPFLAGS, flags );
274 /* UDP */
275 flags = wxEmptyString;
276 if (server->GetUDPFlags() & SRV_UDPFLG_EXT_GETSOURCES) {
277 flags += wxT("g");
279 if (server->GetUDPFlags() & SRV_UDPFLG_EXT_GETFILES) {
280 flags += wxT("f");
282 if (server->GetUDPFlags() & SRV_UDPFLG_NEWTAGS) {
283 flags += wxT("n");
285 if (server->GetUDPFlags() & SRV_UDPFLG_UNICODE) {
286 flags += wxT("u");
288 if (server->GetUDPFlags() & SRV_UDPFLG_EXT_GETSOURCES2) {
289 flags += wxT("G");
291 if (server->GetUDPFlags() & SRV_UDPFLG_LARGEFILES) {
292 flags += wxT("l");
294 if (server->GetUDPFlags() & SRV_UDPFLG_UDPOBFUSCATION) {
295 flags += wxT("o");
297 if (server->GetUDPFlags() & SRV_UDPFLG_TCPOBFUSCATION) {
298 flags += wxT("O");
300 SetItem( itemnr, COLUMN_SERVER_UDPFLAGS, flags );
302 #endif
304 // Deletions of items causes rather large ammount of flicker, so to
305 // avoid this, we resort the list to ensure correct ordering.
306 if (!IsItemSorted(itemnr)) {
307 SortList();
312 void CServerListCtrl::HighlightServer( const CServer* server, bool highlight )
314 // Unset the old highlighted server if we are going to set a new one
315 if ( m_connected && highlight ) {
316 // A recursive call to do the real work.
317 HighlightServer( (CServer*)m_connected, false );
319 m_connected = 0;
322 long itemnr = FindItem( -1, reinterpret_cast<wxUIntPtr>(server) );
323 if ( itemnr > -1 ) {
324 wxListItem item;
325 item.SetId( itemnr );
327 if ( GetItem( item ) ) {
328 wxFont font = GetFont();
330 if ( highlight ) {
331 font.SetWeight( wxBOLD );
333 m_connected = reinterpret_cast<wxUIntPtr>(server);
336 item.SetFont( font );
338 SetItem( item );
343 //#warning Kry TODO: Dude, this gotta be moved to core
344 bool CServerListCtrl::SetStaticServer( CServer* server, bool isStatic )
346 server->SetIsStaticMember( isStatic );
347 RefreshServer( server );
349 wxString filename = theApp->ConfigDir + wxT("staticservers.dat");
351 CTextFile file;
352 if (!file.Open(filename, CTextFile::write)) {
353 AddLogLineM( false, CFormat( _("Failed to open '%s'") ) % filename );
354 return false;
357 for (int i = 0; i < GetItemCount(); ++i) {
358 server = reinterpret_cast<CServer*>(GetItemData(i));
360 if (server->IsStaticMember()) {
361 file.WriteLine(CFormat(wxT("%s:%u,%u,%s"))
362 % server->GetAddress() % server->GetPort()
363 % server->GetPreferences() % server->GetListName());
367 return true;
371 void CServerListCtrl::ShowServerCount()
373 wxStaticText* label = CastByName( wxT("serverListLabel"), GetParent(), wxStaticText );
375 if ( label ) {
376 label->SetLabel( wxString::Format( _("Servers (%i)"), GetItemCount() ) );
377 label->GetParent()->Layout();
382 void CServerListCtrl::OnItemActivated( wxListEvent& event )
384 // Unselect all items but the activated one
385 long item = GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
386 while ( item > -1 ) {
387 SetItemState( item, 0, wxLIST_STATE_SELECTED);
389 item = GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
392 SetItemState( event.GetIndex(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
394 wxCommandEvent nulEvt;
395 OnConnectToServer( nulEvt );
399 void CServerListCtrl::OnItemRightClicked(wxListEvent& event)
401 // Check if clicked item is selected. If not, unselect all and select it.
402 long index = CheckSelection(event);
404 bool enable_reconnect = false;
405 bool enable_static_on = false;
406 bool enable_static_off = false;
408 // Gather information on the selected items
409 while ( index > -1 ) {
410 CServer* server = (CServer*)GetItemData( index );
412 // The current server is selected, so we might display the reconnect option
413 if ( reinterpret_cast<wxUIntPtr>(server) == m_connected )
414 enable_reconnect = true;
416 // We want to know which options should be enabled, either one or both
417 enable_static_on |= !server->IsStaticMember();
418 enable_static_off |= server->IsStaticMember();
420 index = GetNextItem( index, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
424 wxMenu* serverMenu = new wxMenu(_("Server"));
425 wxMenu* serverPrioMenu = new wxMenu();
426 serverPrioMenu->Append( MP_PRIOLOW, _("Low") );
427 serverPrioMenu->Append( MP_PRIONORMAL, _("Normal") );
428 serverPrioMenu->Append( MP_PRIOHIGH, _("High") );
429 serverMenu->Append( MP_CONNECTTO, _("Connect to server") );
430 serverMenu->Append( 12345, _("Priority"), serverPrioMenu );
432 serverMenu->AppendSeparator();
434 if (GetSelectedItemCount() == 1) {
435 serverMenu->Append( MP_ADDTOSTATIC, _("Mark server as static") );
436 serverMenu->Append( MP_REMOVEFROMSTATIC, _("Mark server as non-static") );
437 } else {
438 serverMenu->Append( MP_ADDTOSTATIC, _("Mark servers as static") );
439 serverMenu->Append( MP_REMOVEFROMSTATIC, _("Mark servers as non-static") );
442 serverMenu->AppendSeparator();
444 if (GetSelectedItemCount() == 1) {
445 serverMenu->Append( MP_REMOVE, _("Remove server") );
446 } else {
447 serverMenu->Append( MP_REMOVE, _("Remove servers") );
449 serverMenu->Append( MP_REMOVEALL, _("Remove all servers") );
451 serverMenu->AppendSeparator();
453 if (GetSelectedItemCount() == 1) {
454 serverMenu->Append( MP_GETED2KLINK, _("Copy eD2k link to clipboard") );
455 } else {
456 serverMenu->Append( MP_GETED2KLINK, _("Copy eD2k links to clipboard") );
459 serverMenu->Enable( MP_REMOVEFROMSTATIC, enable_static_off );
460 serverMenu->Enable( MP_ADDTOSTATIC, enable_static_on );
462 if ( GetSelectedItemCount() == 1 ) {
463 if ( enable_reconnect )
464 serverMenu->SetLabel( MP_CONNECTTO, _("Reconnect to server") );
465 } else {
466 serverMenu->Enable( MP_CONNECTTO, false );
470 PopupMenu( serverMenu, event.GetPoint() );
471 delete serverMenu;
475 void CServerListCtrl::OnPriorityChange( wxCommandEvent& event )
477 int priority = 0;
479 switch ( event.GetId() ) {
480 case MP_PRIOLOW: priority = SRV_PR_LOW; break;
481 case MP_PRIONORMAL: priority = SRV_PR_NORMAL; break;
482 case MP_PRIOHIGH: priority = SRV_PR_HIGH; break;
484 default:
485 return;
489 ItemDataList items = GetSelectedItems();
491 for ( unsigned int i = 0; i < items.size(); ++i ) {
492 CServer* server = (CServer*)items[ i ];
494 server->SetPreference( priority );
495 RefreshServer( server );
500 void CServerListCtrl::OnStaticChange( wxCommandEvent& event )
502 bool isStatic = ( event.GetId() == MP_ADDTOSTATIC );
504 ItemDataList items = GetSelectedItems();
506 for ( unsigned int i = 0; i < items.size(); ++i ) {
507 CServer* server = (CServer*)items[ i ];
509 // Only update items that have the wrong setting
510 if ( server->IsStaticMember() != isStatic ) {
511 if ( !SetStaticServer( server, isStatic ) ) {
512 wxFAIL;
514 return;
517 server->SetIsStaticMember( isStatic );
518 RefreshServer( server );
524 void CServerListCtrl::OnConnectToServer( wxCommandEvent& WXUNUSED(event) )
526 int item = GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
528 if ( item > -1 ) {
529 if ( theApp->IsConnectedED2K() ) {
530 theApp->serverconnect->Disconnect();
533 theApp->serverconnect->ConnectToServer( (CServer*)GetItemData( item ) );
538 void CServerListCtrl::OnGetED2kURL( wxCommandEvent& WXUNUSED(event) )
540 int pos = GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
542 wxString URL;
544 while ( pos != -1 ) {
545 CServer* server = (CServer*)GetItemData(pos);
547 URL += wxT("ed2k://|server|") + server->GetFullIP() + wxString::Format(wxT("|%d|"), server->GetPort()) + wxT("/\n");
549 pos = GetNextItem( pos, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
552 URL.RemoveLast();
554 theApp->CopyTextToClipboard( URL );
558 void CServerListCtrl::OnRemoveServers( wxCommandEvent& event )
560 if ( event.GetId() == MP_REMOVEALL ) {
561 if ( GetItemCount() ) {
562 wxString question = _("Are you sure that you wish to delete all servers?");
564 if ( wxMessageBox( question, _("Cancel"), wxICON_QUESTION | wxYES_NO, this) == wxYES ) {
565 if ( theApp->serverconnect->IsConnecting() ) {
566 theApp->downloadqueue->StopUDPRequests();
567 theApp->serverconnect->StopConnectionTry();
568 theApp->serverconnect->Disconnect();
571 RemoveAllServers(wxLIST_STATE_DONTCARE);
574 } else if ( event.GetId() == MP_REMOVE ) {
575 if ( GetSelectedItemCount() ) {
576 wxString question;
577 if (GetSelectedItemCount() == 1) {
578 question = _("Are you sure that you wish to delete the selected server?");
579 } else {
580 question = _("Are you sure that you wish to delete the selected servers?");
583 if ( wxMessageBox( question, _("Cancel"), wxICON_QUESTION | wxYES_NO, this) == wxYES ) {
584 RemoveAllServers(wxLIST_STATE_SELECTED);
591 void CServerListCtrl::OnKeyPressed( wxKeyEvent& event )
593 // Check if delete was pressed
594 if ((event.GetKeyCode() == WXK_DELETE) || (event.GetKeyCode() == WXK_NUMPAD_DELETE)) {
595 wxCommandEvent evt;
596 evt.SetId( MP_REMOVE );
597 OnRemoveServers( evt );
598 } else {
599 event.Skip();
604 int CServerListCtrl::SortProc(wxUIntPtr item1, wxUIntPtr item2, long sortData)
606 CServer* server1 = (CServer*)item1;
607 CServer* server2 = (CServer*)item2;
609 int mode = (sortData & CMuleListCtrl::SORT_DES) ? -1 : 1;
611 switch (sortData & CMuleListCtrl::COLUMN_MASK) {
612 // Sort by server-name
613 case COLUMN_SERVER_NAME:
614 return mode * server1->GetListName().CmpNoCase(server2->GetListName());
616 // Sort by address
617 case COLUMN_SERVER_ADDR:
619 if ( server1->HasDynIP() && server2->HasDynIP()) {
620 return mode * server1->GetDynIP().CmpNoCase( server2->GetDynIP() );
621 } else if (server1->HasDynIP()) {
622 return mode * -1;
623 } else if (server2->HasDynIP()) {
624 return mode * 1;
625 } else {
626 uint32 a = wxUINT32_SWAP_ALWAYS(server1->GetIP());
627 uint32 b = wxUINT32_SWAP_ALWAYS(server2->GetIP());
628 return mode * CmpAny(a, b);
631 // Sort by port
632 case COLUMN_SERVER_PORT: return mode * CmpAny( server1->GetPort(), server2->GetPort() );
633 // Sort by description
634 case COLUMN_SERVER_DESC: return mode * server1->GetDescription().CmpNoCase( server2->GetDescription() );
635 // Sort by Ping
636 // The -1 ensures that a value of zero (no ping known) is sorted last.
637 case COLUMN_SERVER_PING: return mode * CmpAny( server1->GetPing() - 1, server2->GetPing() -1 );
638 // Sort by user-count
639 case COLUMN_SERVER_USERS: return mode * CmpAny( server1->GetUsers(), server2->GetUsers() );
640 // Sort by file-count
641 case COLUMN_SERVER_FILES: return mode * CmpAny( server1->GetFiles(), server2->GetFiles() );
642 // Sort by priority
643 case COLUMN_SERVER_PRIO:
645 uint32 srv_pr1 = server1->GetPreferences();
646 uint32 srv_pr2 = server2->GetPreferences();
647 switch ( srv_pr1 ) {
648 case SRV_PR_HIGH: srv_pr1 = SRV_PR_MAX; break;
649 case SRV_PR_NORMAL: srv_pr1 = SRV_PR_MID; break;
650 case SRV_PR_LOW: srv_pr1 = SRV_PR_MIN; break;
651 default: return 0;
653 switch ( srv_pr2 ) {
654 case SRV_PR_HIGH: srv_pr2 = SRV_PR_MAX; break;
655 case SRV_PR_NORMAL: srv_pr2 = SRV_PR_MID; break;
656 case SRV_PR_LOW: srv_pr2 = SRV_PR_MIN; break;
657 default: return 0;
659 return mode * CmpAny( srv_pr1, srv_pr2 );
661 // Sort by failure-count
662 case COLUMN_SERVER_FAILS: return mode * CmpAny( server1->GetFailedCount(), server2->GetFailedCount() );
663 // Sort by static servers
664 case COLUMN_SERVER_STATIC:
666 return mode * CmpAny( server2->IsStaticMember(), server1->IsStaticMember() );
668 // Sort by version
669 case COLUMN_SERVER_VERSION: return mode * FuzzyStrCmp(server1->GetVersion(), server2->GetVersion());
671 default:
672 return 0;
675 // File_checked_for_headers