RigsofRods
Soft-body Physics Simulation
Console.cpp
Go to the documentation of this file.
1 /*
2  This source file is part of Rigs of Rods
3  Copyright 2005-2012 Pierre-Michel Ricordel
4  Copyright 2007-2012 Thomas Fischer
5  Copyright 2013-2019 Petr Ohlidal
6 
7  For more information, see http://www.rigsofrods.org/
8 
9  Rigs of Rods is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License version 3, as
11  published by the Free Software Foundation.
12 
13  Rigs of Rods is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #include "Console.h"
23 
24 #include "Application.h"
25 #include "Utils.h"
26 
27 #include <Ogre.h>
28 
29 using namespace RoR;
30 using namespace Ogre;
31 
32 void Console::messageLogged(const Ogre::String& message, Ogre::LogMessageLevel lml, bool maskDebug, const Ogre::String& logName, bool& skipThisMessage)
33 {
34  if (App::diag_log_console_echo->getBool())
35  {
36  this->forwardLogMessage(CONSOLE_MSGTYPE_LOG, message, lml);
37  }
38 }
39 
40 void Console::forwardLogMessage(MessageArea area, std::string const& message, Ogre::LogMessageLevel lml)
41 {
42  switch (lml)
43  {
44  case Ogre::LML_WARNING:
45  this->putMessage(area, CONSOLE_SYSTEM_WARNING, SanitizeUtf8String(message));
46  break;
47 
48  case Ogre::LML_CRITICAL:
49  this->putMessage(area, CONSOLE_SYSTEM_ERROR, SanitizeUtf8String(message));
50  break;
51 
52  default: // LML_NORMAL, LML_TRIVIAL
53  this->putMessage(area, CONSOLE_SYSTEM_NOTICE, SanitizeUtf8String(message));
54  break;
55  }
56 }
57 
58 void Console::handleMessage(MessageArea area, MessageType type, std::string const& msg, int net_userid/* = 0*/, std::string icon)
59 {
60  if (net_userid < 0) // 0=server, positive=clients, negative=invalid
61  {
62  net_userid = 0;
63  }
64 
65  // Log message to file
66  if (area != MessageArea::CONSOLE_MSGTYPE_LOG && // Don't duplicate echoed log messages
67  type != MessageType::CONSOLE_SYSTEM_NETCHAT) // Privacy
68  {
69  Str<2000> txt;
70  txt << "[RoR|";
71  switch (area)
72  {
73  case MessageArea::CONSOLE_MSGTYPE_INFO: txt << "General"; break;
74  case MessageArea::CONSOLE_MSGTYPE_SCRIPT: txt << "Script"; break;
75  case MessageArea::CONSOLE_MSGTYPE_ACTOR: txt << "Actor"; break;
76  case MessageArea::CONSOLE_MSGTYPE_TERRN: txt << "Terrn"; break;
77  default:;
78  }
79  txt << "|";
80  switch (type)
81  {
82  case MessageType::CONSOLE_SYSTEM_NOTICE: txt << "Notice"; break;
83  case MessageType::CONSOLE_SYSTEM_ERROR: txt << "Error"; break;
84  case MessageType::CONSOLE_SYSTEM_WARNING: txt << "Warning"; break;
85  case MessageType::CONSOLE_SYSTEM_REPLY: txt << "Success"; break;
86  default:;
87  }
88  txt << "] " << msg;
89  Log(txt.ToCStr());
90  }
91 
92  // Lock and update message list
93  std::lock_guard<std::mutex> lock(m_messages_mutex); // Scoped lock
94  m_messages.emplace_back(area, type, msg, this->queryMessageTimer(), net_userid, icon);
95 }
96 
97 void Console::putMessage(MessageArea area, MessageType type, std::string const& msg, std::string icon)
98 {
99  this->handleMessage(area, type, msg, 0, icon);
100 }
101 
102 void Console::putNetMessage(int user_id, MessageType type, const char* text)
103 {
104  this->handleMessage(CONSOLE_MSGTYPE_INFO, type, text, user_id);
105 }
RoR::SanitizeUtf8String
std::string SanitizeUtf8String(std::string const &str_in)
Definition: Utils.cpp:117
Console.h
RoR::Console::putMessage
void putMessage(MessageArea area, MessageType type, std::string const &msg, std::string icon="")
Definition: Console.cpp:97
Utils.h
RoR::Str
Wrapper for classic c-string (local buffer) Refresher: strlen() excludes '\0' terminator; strncat() A...
Definition: Str.h:35
RoR::Console::forwardLogMessage
void forwardLogMessage(MessageArea area, std::string const &msg, Ogre::LogMessageLevel lml)
Definition: Console.cpp:40
RoR::Str::ToCStr
const char * ToCStr() const
Definition: Str.h:46
RoR::Console::MessageType
MessageType
Definition: Console.h:46
Application.h
Central state/object manager and communications hub.
RoR::Console::handleMessage
void handleMessage(MessageArea area, MessageType type, std::string const &msg, int net_id=0, std::string icon="")
Definition: Console.cpp:58
RoR::App::diag_log_console_echo
CVar * diag_log_console_echo
Definition: Application.cpp:146
RoR::Console::messageLogged
virtual void messageLogged(const Ogre::String &message, Ogre::LogMessageLevel lml, bool maskDebug, const Ogre::String &logName, bool &skipThisMessage) override
Definition: Console.cpp:32
RoR::Console::putNetMessage
void putNetMessage(int user_id, MessageType type, const char *text)
Definition: Console.cpp:102
Ogre
Definition: ExtinguishableFireAffector.cpp:35
RoR
Definition: AppContext.h:36
RoR::Log
void Log(const char *msg)
The ultimate, application-wide logging function. Adds a line (any length) in 'RoR....
Definition: Application.cpp:419
RoR::Console::MessageArea
MessageArea
Definition: Console.h:58