Page 1 of 1

Fix to the extra comma on /status

PostPosted: Tue Mar 27, 2012 23:03
by lkjoel
As many of you may know, when you type /status in a server, it gives this message (along other things, of course):
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
clients={player1,player2,player3,}

You see the comma after player3? It's very minor, but it's enough to annoy me :P. I decided to make a very simple patch for it (it also adds a space after the comma):
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
4298,4299c4298,4313
<               // Add name to information string
<               os<<name<<L",";
---
>               // Temporarily increase i to check if it's the last entry
>               i++;
>               if (i.atEnd() == false)
>               {
>                       // This is not the last entry
>                       // Add name to information string
>                       os<<name<<L", ";
>               }
>               else
>               {
>                       // This is the last entry
>                       // Add name to information string
>                       os<<name;
>               }
>               // Decrease temporarily increased i
>               i--;

This is the new output:
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
clients={player1, player2, player3}

Better, don't you think?

PostPosted: Tue Mar 27, 2012 23:14
by Death Dealer
it what it should be, its grammatically correct:D

PostPosted: Tue Mar 27, 2012 23:19
by lkjoel
lol

PostPosted: Tue Mar 27, 2012 23:28
by sdzen
very nice just remember its serverside ikjoel XP

PostPosted: Tue Mar 27, 2012 23:49
by lkjoel
lol yeah I had that problem on C55's server lol

PostPosted: Wed Mar 28, 2012 12:53
by jordan4ibanez
this is a VERY SMALL fix, but being grammatically correct is awesome..i love it!

PostPosted: Wed Mar 28, 2012 15:04
by lkjoel
I hope that c55 includes this fix lol

PostPosted: Wed Mar 28, 2012 16:40
by sfan5
+1 for this Fix! :D

PostPosted: Wed Mar 28, 2012 17:15
by jn
A bit bloated, I got a smaller one: (EDIT: ok, this is not necessarily shorter)
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
diff --git a/src/server.cpp b/src/server.cpp
index 02734bb..e2aafd8 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -4273,6 +4273,7 @@ RemoteClient* Server::getClient(u16 peer_id)
 std::wstring Server::getStatusString()
 {
     std::wostringstream os(std::ios_base::binary);
+    bool not_first = false;
     os<<L"# Server: ";
     // Version
     os<<L"version="<<narrow_to_wide(VERSION_STRING);
@@ -4284,6 +4285,11 @@ RemoteClient* Server::getClient(u16 peer_id)
         i = m_clients.getIterator();
         i.atEnd() == false; i++)
     {
+        // add a comma
+        if(not_first)
+            os<<L",";
+        else
+            not_first = true;
         // Get client and check that it is valid
         RemoteClient *client = i.getNode()->getValue();
         assert(client->peer_id == i.getNode()->getKey());
@@ -4296,7 +4302,7 @@ RemoteClient* Server::getClient(u16 peer_id)
         if(player != NULL)
             name = narrow_to_wide(player->getName());
         // Add name to information string
-        os<<name<<L",";
+        os<<name;
     }
     os<<L"}";
     if(((ServerMap*)(&m_env->getMap()))->isSavingEnabled() == false)

PostPosted: Wed Feb 27, 2013 18:04
by lkjoel
jn wrote:A bit bloated, I got a smaller one: (EDIT: ok, this is not necessarily shorter)
Your phone or window isn't wide enough to display the code box. If it's a phone, try rotating it to landscape mode.
Code: Select all
diff --git a/src/server.cpp b/src/server.cpp
index 02734bb..e2aafd8 100644
--- a/src/server.cpp
+++ b/src/server.cpp
@@ -4273,6 +4273,7 @@ RemoteClient* Server::getClient(u16 peer_id)
 std::wstring Server::getStatusString()
 {
     std::wostringstream os(std::ios_base::binary);
+    bool not_first = false;
     os<<L"# Server: ";
     // Version
     os<<L"version="<<narrow_to_wide(VERSION_STRING);
@@ -4284,6 +4285,11 @@ RemoteClient* Server::getClient(u16 peer_id)
         i = m_clients.getIterator();
         i.atEnd() == false; i++)
     {
+        // add a comma
+        if(not_first)
+            os<<L",";
+        else
+            not_first = true;
         // Get client and check that it is valid
         RemoteClient *client = i.getNode()->getValue();
         assert(client->peer_id == i.getNode()->getKey());
@@ -4296,7 +4302,7 @@ RemoteClient* Server::getClient(u16 peer_id)
         if(player != NULL)
             name = narrow_to_wide(player->getName());
         // Add name to information string
-        os<<name<<L",";
+        os<<name;
     }
     os<<L"}";
     if(((ServerMap*)(&m_env->getMap()))->isSavingEnabled() == false)

Nice! :D