Fix crash regression when chatting in the ncurses console
authorest31 <MTest31@outlook.com>
Thu, 6 Oct 2016 01:32:52 +0000 (03:32 +0200)
committerNer'zhul <nerzhul@users.noreply.github.com>
Thu, 6 Oct 2016 05:45:50 +0000 (07:45 +0200)
Fixes #4579, a regression introduced by commit

d4c76258e37337ea585cf24d8e05b50a30fa307d "Chat: new settings to prevent spam"

src/server.cpp

index 5b67b321aedb82f1803c97896024da13d9fc7cf1..a8494f76e176c1b0b6fb7881efeb851e3d3a3626 100644 (file)
@@ -2751,19 +2751,21 @@ std::wstring Server::handleChat(const std::string &name, const std::wstring &wna
        if (ate)
                return L"";
 
-       switch (player->canSendChatMessage()) {
-               case RPLAYER_CHATRESULT_FLOODING: {
-                       std::wstringstream ws;
-                       ws << L"You cannot send more messages. You are limited to "
-                          << g_settings->getFloat("chat_message_limit_per_10sec")
-                          << " messages per 10 seconds.";
-                       return ws.str();
+       if (player) {
+               switch (player->canSendChatMessage()) {
+                       case RPLAYER_CHATRESULT_FLOODING: {
+                               std::wstringstream ws;
+                               ws << L"You cannot send more messages. You are limited to "
+                               << g_settings->getFloat("chat_message_limit_per_10sec")
+                               << " messages per 10 seconds.";
+                               return ws.str();
+                       }
+                       case RPLAYER_CHATRESULT_KICK:
+                               DenyAccess_Legacy(player->peer_id, L"You have been kicked due to message flooding.");
+                               return L"";
+                       case RPLAYER_CHATRESULT_OK: break;
+                       default: FATAL_ERROR("Unhandled chat filtering result found.");
                }
-               case RPLAYER_CHATRESULT_KICK:
-                       DenyAccess_Legacy(player->peer_id, L"You have been kicked due to message flooding.");
-                       return L"";
-               case RPLAYER_CHATRESULT_OK: break;
-               default: FATAL_ERROR("Unhandled chat filtering result found.");
        }
 
        if (m_max_chatmessage_length > 0 && wmessage.length() > m_max_chatmessage_length) {