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
ChatSystem.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
6 For more information, see http://www.rigsofrods.org/
7
8 Rigs of Rods is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License version 3, as
10 published by the Free Software Foundation.
11
12 Rigs of Rods is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with Rigs of Rods. If not, see <http://www.gnu.org/licenses/>.
19*/
20
21#include "ChatSystem.h"
22
23#include "Actor.h"
24#include "Console.h"
25#include "GUIManager.h"
26#include "Language.h"
27#include "Utils.h"
28
29namespace RoR {
30namespace ChatSystem {
31
32using namespace RoRnet;
33
34#ifdef USE_SOCKETW
36{
38 memset(&reg, 0, sizeof(RoRnet::StreamRegister));
39 reg.status = 1;
40 strcpy(reg.name, "chat");
41 reg.type = 3;
42
44}
45#endif // USE_SOCKETW
46
47#ifdef USE_SOCKETW
48void ReceiveStreamData(unsigned int type, int source, char* buffer)
49{
50 if (type != MSG2_UTF8_CHAT && type != MSG2_UTF8_PRIVCHAT)
51 return;
52
53 if (source != App::GetNetwork()->GetLocalUserData().uniqueid // Skip mute check for player's own messages (server broadcasts to all by default)
54 && source != -1) // user ID -1 is a server broadcast message, defined as `TO_ALL` in rorserver.
55 {
56 BitMask_t peeropts = BitMask_t(0);
57 if (!App::GetNetwork()->GetUserPeerOpts(source, peeropts) || BITMASK_IS_1(peeropts, RoRnet::PEEROPT_MUTE_CHAT))
58 return;
59 }
60
61 std::string text = SanitizeUtf8CString(buffer);
62 if (type == MSG2_UTF8_PRIVCHAT)
63 {
64 text = _L(" [whispered] ") + text;
65 }
66
68}
69#endif // USE_SOCKETW
70
71#ifdef USE_SOCKETW
72void HandleStreamData(std::vector<RoR::NetRecvPacket> packet_buffer)
73{
74 for (auto packet : packet_buffer)
75 {
76 ReceiveStreamData(packet.header.command, packet.header.source, packet.buffer);
77 }
78}
79#endif // USE_SOCKETW
80
81} // namespace ChatSystem
82} // namespace RoR
#define BITMASK_IS_1(VAR, FLAGS)
Definition BitFlags.h:14
uint32_t BitMask_t
Definition BitFlags.h:7
#define _L
void putNetMessage(int user_id, MessageType type, const char *text)
Definition Console.cpp:108
@ CONSOLE_SYSTEM_NETCHAT
Definition Console.h:55
void AddLocalStream(RoRnet::StreamRegister *reg, int size)
Definition Network.cpp:670
Console * GetConsole()
Network * GetNetwork()
void SendStreamSetup()
void HandleStreamData(std::vector< RoR::NetRecvPacket > packet_buffer)
void ReceiveStreamData(unsigned int type, int source, char *buffer)
std::string SanitizeUtf8CString(const char *start, const char *end=nullptr)
Definition Utils.cpp:128
@ PEEROPT_MUTE_CHAT
CHAT and PRIVCHAT messages will not be allowed through.
Definition RoRnet.h:131
@ MSG2_UTF8_CHAT
broadcast chat line in UTF8 encoding; Payload: const char*(text)
Definition RoRnet.h:59
@ MSG2_UTF8_PRIVCHAT
private chat line in UTF8 encoding; Payload: uint32_t(uniqueid), const char*(text)
Definition RoRnet.h:60
< Sent from the client to server and vice versa, to broadcast a new stream
Definition RoRnet.h:160
int32_t type
0 = Actor, 1 = Character, 3 = ChatSystem
Definition RoRnet.h:161
char name[128]
file name
Definition RoRnet.h:165
int32_t status
initial stream status
Definition RoRnet.h:162