Rigs of Rods 2023.09
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Loading...
Searching...
No Matches
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
29using namespace RoR;
30using namespace Ogre;
31
32void 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
40void Console::forwardLogMessage(MessageArea area, std::string const& message, Ogre::LogMessageLevel lml)
41{
42 switch (lml)
43 {
44 case Ogre::LML_WARNING:
46 break;
47
48 case Ogre::LML_CRITICAL:
50 break;
51
52 default: // LML_NORMAL, LML_TRIVIAL
54 break;
55 }
56}
57
59{
60 std::lock_guard<std::mutex> lock(m_messages_mutex); // Scoped lock
61 m_messages.erase(std::remove_if(m_messages.begin(), m_messages.end(), [user_id](const Console::Message& msg) { return msg.cm_net_userid == user_id; }), m_messages.end());
62}
63
64void Console::handleMessage(MessageArea area, MessageType type, std::string const& msg, int net_userid/* = 0*/, std::string icon)
65{
66 if (net_userid < 0) // 0=server, positive=clients, negative=invalid
67 {
68 net_userid = 0;
69 }
70
71 // Log message to file
72 if (area != MessageArea::CONSOLE_MSGTYPE_LOG && // Don't duplicate echoed log messages
73 type != MessageType::CONSOLE_SYSTEM_NETCHAT) // Privacy
74 {
75 Str<2000> txt;
76 txt << "[RoR|";
77 switch (area)
78 {
79 case MessageArea::CONSOLE_MSGTYPE_INFO: txt << "General"; break;
80 case MessageArea::CONSOLE_MSGTYPE_SCRIPT: txt << "Script"; break;
81 case MessageArea::CONSOLE_MSGTYPE_ACTOR: txt << "Actor"; break;
82 case MessageArea::CONSOLE_MSGTYPE_TERRN: txt << "Terrn"; break;
83 default:;
84 }
85 txt << "|";
86 switch (type)
87 {
88 case MessageType::CONSOLE_SYSTEM_NOTICE: txt << "Notice"; break;
89 case MessageType::CONSOLE_SYSTEM_ERROR: txt << "Error"; break;
90 case MessageType::CONSOLE_SYSTEM_WARNING: txt << "Warning"; break;
91 case MessageType::CONSOLE_SYSTEM_REPLY: txt << "Success"; break;
92 default:;
93 }
94 txt << "] " << msg;
95 Log(txt.ToCStr());
96 }
97
98 // Lock and update message list
99 std::lock_guard<std::mutex> lock(m_messages_mutex); // Scoped lock
100 m_messages.emplace_back(area, type, msg, this->queryMessageTimer(), net_userid, icon);
101}
102
103void Console::putMessage(MessageArea area, MessageType type, std::string const& msg, std::string icon)
104{
105 this->handleMessage(area, type, msg, 0, icon);
106}
107
108void Console::putNetMessage(int user_id, MessageType type, const char* text)
109{
110 this->handleMessage(CONSOLE_MSGTYPE_INFO, type, text, user_id);
111}
quaternion Log() const
Central state/object manager and communications hub.
void putNetMessage(int user_id, MessageType type, const char *text)
Definition Console.cpp:108
virtual void messageLogged(const Ogre::String &message, Ogre::LogMessageLevel lml, bool maskDebug, const Ogre::String &logName, bool &skipThisMessage) override
Definition Console.cpp:32
unsigned long queryMessageTimer()
Definition Console.h:98
std::mutex m_messages_mutex
Definition Console.h:158
std::vector< Message > m_messages
Definition Console.h:157
@ CONSOLE_MSGTYPE_ACTOR
Parsing/spawn/simulation messages for actors.
Definition Console.h:63
@ CONSOLE_MSGTYPE_SCRIPT
Messages sent from scripts.
Definition Console.h:62
@ CONSOLE_MSGTYPE_INFO
Generic message.
Definition Console.h:60
@ CONSOLE_MSGTYPE_TERRN
Parsing/spawn/simulation messages for terrain.
Definition Console.h:64
@ CONSOLE_MSGTYPE_LOG
Logfile echo.
Definition Console.h:61
void purgeNetChatMessagesByUser(int user_id)
Definition Console.cpp:58
void putMessage(MessageArea area, MessageType type, std::string const &msg, std::string icon="")
Definition Console.cpp:103
void handleMessage(MessageArea area, MessageType type, std::string const &msg, int net_id=0, std::string icon="")
Definition Console.cpp:64
@ CONSOLE_SYSTEM_ERROR
Definition Console.h:52
@ CONSOLE_SYSTEM_NOTICE
Definition Console.h:51
@ CONSOLE_SYSTEM_WARNING
Definition Console.h:53
@ CONSOLE_SYSTEM_REPLY
Success.
Definition Console.h:54
@ CONSOLE_SYSTEM_NETCHAT
Definition Console.h:55
void forwardLogMessage(MessageArea area, std::string const &msg, Ogre::LogMessageLevel lml)
Definition Console.cpp:40
Wrapper for classic c-string (local buffer) Refresher: strlen() excludes '\0' terminator; strncat() A...
Definition Str.h:36
const char * ToCStr() const
Definition Str.h:46
CVar * diag_log_console_echo
std::string SanitizeUtf8String(std::string const &str_in)
Definition Utils.cpp:120