Review Kademlia assertions
[amule.git] / src / ServerListCtrl.cpp
blob484ce48c600dbd8d8b24f8813f4ae3c3db608170
1 //
2 // This file is part of the aMule Project.
3 //
4 // Copyright (c) 2003-2011 aMule Team ( admin@amule.org / http://www.amule.org )
5 // Copyright (c) 2002-2011 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.
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 "Preferences.h" // Needed for thePrefs
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 = reinterpret_cast<CServer*>(GetItemData(pos));
148 if (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 theApp->serverlist->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() && thePrefs::IsGeoIPEnabled()) {
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 CFormat(wxT("%u")) % server->GetPort());
208 } else {
209 SetItem( itemnr, COLUMN_SERVER_PORT,
210 CFormat(wxT("%u (%s)")) % server->GetPort() % server->GetAuxPortsList());
212 SetItem( itemnr, COLUMN_SERVER_DESC, server->GetDescription() );
214 if ( server->GetPing() ) {
215 SetItem( itemnr, COLUMN_SERVER_PING,
216 CastSecondsToHM(server->GetPing()/1000, server->GetPing() % 1000 ) );
217 } else {
218 SetItem( itemnr, COLUMN_SERVER_PING, wxEmptyString );
221 if ( server->GetUsers() ) {
222 SetItem( itemnr, COLUMN_SERVER_USERS,
223 CFormat(wxT("%u")) % server->GetUsers());
224 } else {
225 SetItem( itemnr, COLUMN_SERVER_USERS, wxEmptyString );
228 if ( server->GetFiles() ) {
229 SetItem( itemnr, COLUMN_SERVER_FILES,
230 CFormat(wxT("%u")) % server->GetFiles());
231 } else {
232 SetItem( itemnr, COLUMN_SERVER_FILES, wxEmptyString );
235 switch ( server->GetPreferences() ) {
236 case SRV_PR_LOW: SetItem(itemnr, COLUMN_SERVER_PRIO, _("Low")); break;
237 case SRV_PR_NORMAL: SetItem(itemnr, COLUMN_SERVER_PRIO, _("Normal")); break;
238 case SRV_PR_HIGH: SetItem(itemnr, COLUMN_SERVER_PRIO, _("High") ); break;
239 default: SetItem(itemnr, COLUMN_SERVER_PRIO, wxT("---")); // this should never happen
242 SetItem( itemnr, COLUMN_SERVER_FAILS, CFormat(wxT("%u")) % server->GetFailedCount());
243 SetItem( itemnr, COLUMN_SERVER_STATIC, ( server->IsStaticMember() ? _("Yes") : _("No") ) );
244 SetItem( itemnr, COLUMN_SERVER_VERSION, server->GetVersion() );
246 #if defined(__DEBUG__) && !defined(CLIENT_GUI)
247 wxString flags;
248 /* TCP */
249 if (server->GetTCPFlags() & SRV_TCPFLG_COMPRESSION) {
250 flags += wxT("c");
252 if (server->GetTCPFlags() & SRV_TCPFLG_NEWTAGS) {
253 flags += wxT("n");
255 if (server->GetTCPFlags() & SRV_TCPFLG_UNICODE) {
256 flags += wxT("u");
258 if (server->GetTCPFlags() & SRV_TCPFLG_RELATEDSEARCH) {
259 flags += wxT("r");
261 if (server->GetTCPFlags() & SRV_TCPFLG_TYPETAGINTEGER) {
262 flags += wxT("t");
264 if (server->GetTCPFlags() & SRV_TCPFLG_LARGEFILES) {
265 flags += wxT("l");
267 if (server->GetTCPFlags() & SRV_TCPFLG_TCPOBFUSCATION) {
268 flags += wxT("o");
271 SetItem( itemnr, COLUMN_SERVER_TCPFLAGS, flags );
273 /* UDP */
274 flags.Clear();
275 if (server->GetUDPFlags() & SRV_UDPFLG_EXT_GETSOURCES) {
276 flags += wxT("g");
278 if (server->GetUDPFlags() & SRV_UDPFLG_EXT_GETFILES) {
279 flags += wxT("f");
281 if (server->GetUDPFlags() & SRV_UDPFLG_NEWTAGS) {
282 flags += wxT("n");
284 if (server->GetUDPFlags() & SRV_UDPFLG_UNICODE) {
285 flags += wxT("u");
287 if (server->GetUDPFlags() & SRV_UDPFLG_EXT_GETSOURCES2) {
288 flags += wxT("G");
290 if (server->GetUDPFlags() & SRV_UDPFLG_LARGEFILES) {
291 flags += wxT("l");
293 if (server->GetUDPFlags() & SRV_UDPFLG_UDPOBFUSCATION) {
294 flags += wxT("o");
296 if (server->GetUDPFlags() & SRV_UDPFLG_TCPOBFUSCATION) {
297 flags += wxT("O");
299 SetItem( itemnr, COLUMN_SERVER_UDPFLAGS, flags );
301 #endif
303 // Deletions of items causes rather large ammount of flicker, so to
304 // avoid this, we resort the list to ensure correct ordering.
305 if (!IsItemSorted(itemnr)) {
306 SortList();
311 void CServerListCtrl::HighlightServer( const CServer* server, bool highlight )
313 // Unset the old highlighted server if we are going to set a new one
314 if ( m_connected && highlight ) {
315 // A recursive call to do the real work.
316 HighlightServer( m_connected, false );
318 m_connected = 0;
321 long itemnr = FindItem( -1, reinterpret_cast<wxUIntPtr>(server) );
322 if ( itemnr > -1 ) {
323 wxListItem item;
324 item.SetId( itemnr );
326 if ( GetItem( item ) ) {
327 wxFont font = GetFont();
329 if ( highlight ) {
330 font.SetWeight( wxBOLD );
332 m_connected = server;
335 item.SetFont( font );
337 SetItem( item );
343 void CServerListCtrl::ShowServerCount()
345 wxStaticText* label = CastByName( wxT("serverListLabel"), GetParent(), wxStaticText );
347 if ( label ) {
348 label->SetLabel(CFormat(_("Servers (%i)")) % GetItemCount());
349 label->GetParent()->Layout();
354 void CServerListCtrl::OnItemActivated( wxListEvent& event )
356 // Unselect all items but the activated one
357 long item = GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
358 while ( item > -1 ) {
359 SetItemState( item, 0, wxLIST_STATE_SELECTED);
361 item = GetNextItem( item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
364 SetItemState( event.GetIndex(), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
366 wxCommandEvent nulEvt;
367 OnConnectToServer( nulEvt );
371 void CServerListCtrl::OnItemRightClicked(wxListEvent& event)
373 // Check if clicked item is selected. If not, unselect all and select it.
374 long index = CheckSelection(event);
376 bool enable_reconnect = false;
377 bool enable_static_on = false;
378 bool enable_static_off = false;
380 // Gather information on the selected items
381 while ( index > -1 ) {
382 CServer* server = reinterpret_cast<CServer*>(GetItemData(index));
384 // The current server is selected, so we might display the reconnect option
385 if (server == m_connected) {
386 enable_reconnect = true;
389 // We want to know which options should be enabled, either one or both
390 enable_static_on |= !server->IsStaticMember();
391 enable_static_off |= server->IsStaticMember();
393 index = GetNextItem( index, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
397 wxMenu* serverMenu = new wxMenu(_("Server"));
398 wxMenu* serverPrioMenu = new wxMenu();
399 serverPrioMenu->Append( MP_PRIOLOW, _("Low") );
400 serverPrioMenu->Append( MP_PRIONORMAL, _("Normal") );
401 serverPrioMenu->Append( MP_PRIOHIGH, _("High") );
402 serverMenu->Append( MP_CONNECTTO, _("Connect to server") );
403 serverMenu->Append( 12345, _("Priority"), serverPrioMenu );
405 serverMenu->AppendSeparator();
407 if (GetSelectedItemCount() == 1) {
408 serverMenu->Append( MP_ADDTOSTATIC, _("Mark server as static") );
409 serverMenu->Append( MP_REMOVEFROMSTATIC, _("Mark server as non-static") );
410 } else {
411 serverMenu->Append( MP_ADDTOSTATIC, _("Mark servers as static") );
412 serverMenu->Append( MP_REMOVEFROMSTATIC, _("Mark servers as non-static") );
415 serverMenu->AppendSeparator();
417 if (GetSelectedItemCount() == 1) {
418 serverMenu->Append( MP_REMOVE, _("Remove server") );
419 } else {
420 serverMenu->Append( MP_REMOVE, _("Remove servers") );
422 serverMenu->Append( MP_REMOVEALL, _("Remove all servers") );
424 serverMenu->AppendSeparator();
426 if (GetSelectedItemCount() == 1) {
427 serverMenu->Append( MP_GETED2KLINK, _("Copy eD2k link to clipboard") );
428 } else {
429 serverMenu->Append( MP_GETED2KLINK, _("Copy eD2k links to clipboard") );
432 serverMenu->Enable( MP_REMOVEFROMSTATIC, enable_static_off );
433 serverMenu->Enable( MP_ADDTOSTATIC, enable_static_on );
435 if ( GetSelectedItemCount() == 1 ) {
436 if ( enable_reconnect )
437 serverMenu->SetLabel( MP_CONNECTTO, _("Reconnect to server") );
438 } else {
439 serverMenu->Enable( MP_CONNECTTO, false );
443 PopupMenu( serverMenu, event.GetPoint() );
444 delete serverMenu;
448 void CServerListCtrl::OnPriorityChange( wxCommandEvent& event )
450 uint32 priority = 0;
452 switch ( event.GetId() ) {
453 case MP_PRIOLOW: priority = SRV_PR_LOW; break;
454 case MP_PRIONORMAL: priority = SRV_PR_NORMAL; break;
455 case MP_PRIOHIGH: priority = SRV_PR_HIGH; break;
457 default:
458 return;
462 ItemDataList items = GetSelectedItems();
464 for ( unsigned int i = 0; i < items.size(); ++i ) {
465 CServer* server = reinterpret_cast<CServer*>(items[i]);
466 theApp->serverlist->SetServerPrio(server, priority);
471 void CServerListCtrl::OnStaticChange( wxCommandEvent& event )
473 bool isStatic = ( event.GetId() == MP_ADDTOSTATIC );
475 ItemDataList items = GetSelectedItems();
477 for ( unsigned int i = 0; i < items.size(); ++i ) {
478 CServer* server = reinterpret_cast<CServer*>(items[i]);
480 // Only update items that have the wrong setting
481 if ( server->IsStaticMember() != isStatic ) {
482 theApp->serverlist->SetStaticServer(server, isStatic);
488 void CServerListCtrl::OnConnectToServer( wxCommandEvent& WXUNUSED(event) )
490 int item = GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
492 if ( item > -1 ) {
493 if ( theApp->IsConnectedED2K() ) {
494 theApp->serverconnect->Disconnect();
497 theApp->serverconnect->ConnectToServer( reinterpret_cast<CServer*>(GetItemData(item)) );
502 void CServerListCtrl::OnGetED2kURL( wxCommandEvent& WXUNUSED(event) )
504 int pos = GetNextItem( -1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
506 wxString URL;
508 while ( pos != -1 ) {
509 CServer* server = reinterpret_cast<CServer*>(GetItemData(pos));
511 URL += CFormat(wxT("ed2k://|server|%s|%d|/\n")) % server->GetFullIP() % server->GetPort();
513 pos = GetNextItem( pos, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED );
516 URL.RemoveLast();
518 theApp->CopyTextToClipboard( URL );
522 void CServerListCtrl::OnRemoveServers( wxCommandEvent& event )
524 if ( event.GetId() == MP_REMOVEALL ) {
525 if ( GetItemCount() ) {
526 wxString question = _("Are you sure that you wish to delete all servers?");
528 if ( wxMessageBox( question, _("Cancel"), wxICON_QUESTION | wxYES_NO, this) == wxYES ) {
529 if ( theApp->serverconnect->IsConnecting() ) {
530 theApp->downloadqueue->StopUDPRequests();
531 theApp->serverconnect->StopConnectionTry();
532 theApp->serverconnect->Disconnect();
535 RemoveAllServers(wxLIST_STATE_DONTCARE);
538 } else if ( event.GetId() == MP_REMOVE ) {
539 if ( GetSelectedItemCount() ) {
540 wxString question;
541 if (GetSelectedItemCount() == 1) {
542 question = _("Are you sure that you wish to delete the selected server?");
543 } else {
544 question = _("Are you sure that you wish to delete the selected servers?");
547 if ( wxMessageBox( question, _("Cancel"), wxICON_QUESTION | wxYES_NO, this) == wxYES ) {
548 RemoveAllServers(wxLIST_STATE_SELECTED);
555 void CServerListCtrl::OnKeyPressed( wxKeyEvent& event )
557 // Check if delete was pressed
558 if ((event.GetKeyCode() == WXK_DELETE) || (event.GetKeyCode() == WXK_NUMPAD_DELETE)) {
559 wxCommandEvent evt;
560 evt.SetId( MP_REMOVE );
561 OnRemoveServers( evt );
562 } else {
563 event.Skip();
568 int CServerListCtrl::SortProc(wxUIntPtr item1, wxUIntPtr item2, long sortData)
570 CServer* server1 = reinterpret_cast<CServer*>(item1);
571 CServer* server2 = reinterpret_cast<CServer*>(item2);
573 int mode = (sortData & CMuleListCtrl::SORT_DES) ? -1 : 1;
575 switch (sortData & CMuleListCtrl::COLUMN_MASK) {
576 // Sort by server-name
577 case COLUMN_SERVER_NAME:
578 return mode * server1->GetListName().CmpNoCase(server2->GetListName());
580 // Sort by address
581 case COLUMN_SERVER_ADDR:
583 if ( server1->HasDynIP() && server2->HasDynIP()) {
584 return mode * server1->GetDynIP().CmpNoCase( server2->GetDynIP() );
585 } else if (server1->HasDynIP()) {
586 return mode * -1;
587 } else if (server2->HasDynIP()) {
588 return mode * 1;
589 } else {
590 uint32 a = wxUINT32_SWAP_ALWAYS(server1->GetIP());
591 uint32 b = wxUINT32_SWAP_ALWAYS(server2->GetIP());
592 return mode * CmpAny(a, b);
595 // Sort by port
596 case COLUMN_SERVER_PORT: return mode * CmpAny( server1->GetPort(), server2->GetPort() );
597 // Sort by description
598 case COLUMN_SERVER_DESC: return mode * server1->GetDescription().CmpNoCase( server2->GetDescription() );
599 // Sort by Ping
600 // The -1 ensures that a value of zero (no ping known) is sorted last.
601 case COLUMN_SERVER_PING: return mode * CmpAny( server1->GetPing() - 1, server2->GetPing() -1 );
602 // Sort by user-count
603 case COLUMN_SERVER_USERS: return mode * CmpAny( server1->GetUsers(), server2->GetUsers() );
604 // Sort by file-count
605 case COLUMN_SERVER_FILES: return mode * CmpAny( server1->GetFiles(), server2->GetFiles() );
606 // Sort by priority
607 case COLUMN_SERVER_PRIO:
609 uint32 srv_pr1 = server1->GetPreferences();
610 uint32 srv_pr2 = server2->GetPreferences();
611 switch ( srv_pr1 ) {
612 case SRV_PR_HIGH: srv_pr1 = SRV_PR_MAX; break;
613 case SRV_PR_NORMAL: srv_pr1 = SRV_PR_MID; break;
614 case SRV_PR_LOW: srv_pr1 = SRV_PR_MIN; break;
615 default: return 0;
617 switch ( srv_pr2 ) {
618 case SRV_PR_HIGH: srv_pr2 = SRV_PR_MAX; break;
619 case SRV_PR_NORMAL: srv_pr2 = SRV_PR_MID; break;
620 case SRV_PR_LOW: srv_pr2 = SRV_PR_MIN; break;
621 default: return 0;
623 return mode * CmpAny( srv_pr1, srv_pr2 );
625 // Sort by failure-count
626 case COLUMN_SERVER_FAILS: return mode * CmpAny( server1->GetFailedCount(), server2->GetFailedCount() );
627 // Sort by static servers
628 case COLUMN_SERVER_STATIC:
630 return mode * CmpAny( server2->IsStaticMember(), server1->IsStaticMember() );
632 // Sort by version
633 case COLUMN_SERVER_VERSION: return mode * FuzzyStrCmp(server1->GetVersion(), server2->GetVersion());
635 default:
636 return 0;
639 // File_checked_for_headers