QuantiCode games

Zero Ballistics, Full Metal Soccer

Skip to content

Display Ping-time in the server-list [patch included]

Post any game related ideas or features you would like to see in the final version

Moderators: Michael, Bernhard, Christian

Display Ping-time in the server-list [patch included]

Postby b3nn0 on 12 Jan 2011, 20:50

Hey there,
It would be awesome if the Ping-time to each server could be part of the server list (or at least in the details on the right side as soon as you click a server). Just so you don't have to connect to 3+ servers just to find out that they were on the other side of the world and therefore unplayable

Thanks,
b3nn0
Last edited by b3nn0 on 13 Jan 2011, 01:36, edited 1 time in total.
b3nn0
 
Posts: 12
Joined: 12 Jan 2011, 13:18
Location: Germany

Re: Display Ping-time in the server-list

Postby b3nn0 on 13 Jan 2011, 01:35

You know what? Because I like the game that much, and want to support it, I just wrote a patch for this myself. I hope you accept it (feel free to change it. I wrote it in an very intuitive way to break nothing (hopefully) and in a simple way (as I don't know your codebase that good, I just checked it out 2 hours ago).
Oh, and also, this filters out servers that can't be ping'ed. I think that's a good side-effect, since You can't connect to those servers anyway (behind a firewall? I don't know, but there are often servers in the list that can't be connected to).

So here is the patch (created with svn diff):

Code: Select all
Index: libs/master/src/ServerList.cpp
===================================================================
--- libs/master/src/ServerList.cpp   (Revision 4452)
+++ libs/master/src/ServerList.cpp   (Arbeitskopie)
@@ -46,7 +46,8 @@
     interface_(RakNetworkFactory::GetRakPeerInterface()),
     task_ping_lan_(INVALID_TASK_HANDLE),
     lan_scan_port_(0),
-    query_active_(false)
+    query_active_(false),
+    ping_each_(false)
{
     SocketDescriptor desc;
     bool attempt_succeded = interface_->Startup(1, SLEEP_TIMER, &desc, 1);
@@ -70,16 +71,24 @@


//------------------------------------------------------------------------------
-void ServerList::queryMasterServer()
+void ServerList::queryMasterServer(bool ping)
{
     reset();
-   
+   ping_each_ = ping;
     s_log << Log::debug('m')
           << "requesting auth token from master server\n";

     RakNet::BitStream args;
     args.Write((uint8_t)MPI_REQUEST_AUTH_TOKEN);

+    if(ping_each_)
+    {
+        task_ping_lan_ = s_scheduler.addTask(PeriodicTaskCallback(this, &ServerList::handleLanPing),
+                                             SCAN_PING_DT,
+                                             "ServerList::handleLanPing",
+                                             &fp_group_);
+    }
+
     MasterServerRequest * req;
     try
     {
@@ -126,6 +135,7 @@
{
     s_scheduler.removeTask(task_ping_lan_, &fp_group_);
     task_ping_lan_ = INVALID_TASK_HANDLE;
+    ping_each_     = false;
     query_active_  = false;
     lan_scan_port_ = 0;
}
@@ -246,7 +256,6 @@
*/
}

-
//------------------------------------------------------------------------------
/**
  *  Server "pong" packets are handled here.
@@ -259,6 +268,7 @@
     // If we are scanning the LAN, there might be multiple servers
     // on it, so continue scanning and ignore this pong if we
     // already got it.
+
     if (find(server_info_.begin(), server_info_.end(), server_address) != server_info_.end()) return;
     
     
@@ -282,7 +292,6 @@
}


-
//------------------------------------------------------------------------------
void ServerList::sendRequestServerList(uint32_t token)
{
@@ -315,6 +324,13 @@
     ListServerInfo info;
     if (info.readFromBitstream(stream))
     {
+        if(ping_each_)
+        {
+            interface_->Ping(info.address_.ToString(false),
+                                                    info.internal_port_,
+                                                    false);
+            return; // In this case, handleLanServerPong will ad the info.
+        }
         server_info_.push_back(info);
         emit(SLE_FOUND_SERVER);
     } else
Index: libs/master/src/ServerList.h
===================================================================
--- libs/master/src/ServerList.h   (Revision 4452)
+++ libs/master/src/ServerList.h   (Arbeitskopie)
@@ -57,7 +57,7 @@
     ServerList();
     virtual ~ServerList();

-    void queryMasterServer();
+    void queryMasterServer(bool ping = false);
     void queryLan(unsigned port);

     void cancelQueries();
@@ -90,6 +90,8 @@
     unsigned lan_scan_port_;

     bool query_active_;
+
+    bool ping_each_;
};


Index: games/tank/src/GUIServerBrowser.cpp
===================================================================
--- games/tank/src/GUIServerBrowser.cpp   (Revision 4452)
+++ games/tank/src/GUIServerBrowser.cpp   (Arbeitskopie)
@@ -32,16 +32,18 @@
         gui_list_[c]->setWantsMultiClickEvents(true);
         gui_list_[c]->setSortDirection(CEGUI::ListHeaderSegment::None);
         gui_list_[c]->setShowHorzScrollbar(false);
-        gui_list_[c]->addColumn("Name",     0, CEGUI::UDim(0.48f, 0));
+        gui_list_[c]->addColumn("Name",     0, CEGUI::UDim(0.41f, 0));
         gui_list_[c]->addColumn("Map",      1, CEGUI::UDim(0.20f, 0));
         gui_list_[c]->addColumn("Mode",     2, CEGUI::UDim(0.17f, 0));
-        gui_list_[c]->addColumn("Players",  3, CEGUI::UDim(0.14f,0));
+        gui_list_[c]->addColumn("Players",  3, CEGUI::UDim(0.14f, 0));
+        gui_list_[c]->addColumn("Ping",     4, CEGUI::UDim(0.8f, 0));
         
         // customize lists header
         gui_list_[c]->getListHeader()->getSegmentFromColumn(0).setProperty("Font","main_menu_font");
         gui_list_[c]->getListHeader()->getSegmentFromColumn(1).setProperty("Font","main_menu_font");
         gui_list_[c]->getListHeader()->getSegmentFromColumn(2).setProperty("Font","main_menu_font");
-        gui_list_[c]->getListHeader()->getSegmentFromColumn(3).setProperty("Font","main_menu_font");               
+        gui_list_[c]->getListHeader()->getSegmentFromColumn(3).setProperty("Font","main_menu_font");
+        gui_list_[c]->getListHeader()->getSegmentFromColumn(4).setProperty("Font","main_menu_font");       
     }       

     // make first tab visible on default
@@ -311,7 +313,7 @@
     server_list_[INTERNET_LIST]->reset();
     server_count_[INTERNET_LIST]->setText("-");

-    server_list_[INTERNET_LIST]->queryMasterServer();
+    server_list_[INTERNET_LIST]->queryMasterServer(true);
     return true;
}

@@ -624,9 +626,10 @@

     /// XXX testing insertion code
     unsigned row = list->addRow();
-   list->setItem(new ServerListInfoElement(info.name_, info), 0, row);
-   list->setItem(new ServerListTextElement(info.level_name_), 1, row);
-   list->setItem(new ServerListTextElement(info.game_mode_), 2, row);
-   list->setItem(new ServerListPlayerElement(players, info.num_players_, info.max_players_), 3, row);
+    list->setItem(new ServerListInfoElement(info.name_, info), 0, row);
+    list->setItem(new ServerListTextElement(info.level_name_), 1, row);
+    list->setItem(new ServerListTextElement(info.game_mode_), 2, row);
+    list->setItem(new ServerListPlayerElement(players, info.num_players_, info.max_players_), 3, row);
+    list->setItem(new ServerListNumericElement(toString(info.ping_), info.ping_), 4, row);
}



I don't know about your new NAT punchthrough code.. Will this work with it? (diddn't look at the code to find out what it's all about. And couldn't test it because it always crashed the client).

Thanks for the great game,
b3nn0
b3nn0
 
Posts: 12
Joined: 12 Jan 2011, 13:18
Location: Germany

Re: Display Ping-time in the server-list [patch included]

Postby Michael on 17 Jan 2011, 22:14

Hi b3nn0,

thanks for the patch, we'll take a look at it.

kind regards,
Michael
Michael
Developer
 
Posts: 204
Joined: 29 Mar 2008, 17:19


Return to Ideas

Who is online

Users browsing this forum: No registered users and 1 guest


cron