RigsofRods
Soft-body Physics Simulation
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
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 
29 namespace RoR {
30 namespace ChatSystem {
31 
32 using 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
48 void 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 != -1) // user ID -1 is a server broadcast message, defined as `TO_ALL` in rorserver.
54  {
55  BitMask_t peeropts = BitMask_t(0);
56  if (!App::GetNetwork()->GetUserPeerOpts(source, peeropts) || BITMASK_IS_1(peeropts, RoRnet::PEEROPT_MUTE_CHAT))
57  return;
58  }
59 
60  std::string text = SanitizeUtf8CString(buffer);
61  if (type == MSG2_UTF8_PRIVCHAT)
62  {
63  text = _L(" [whispered] ") + text;
64  }
65 
67 }
68 #endif // USE_SOCKETW
69 
70 #ifdef USE_SOCKETW
71 void HandleStreamData(std::vector<RoR::NetRecvPacket> packet_buffer)
72 {
73  for (auto packet : packet_buffer)
74  {
75  ReceiveStreamData(packet.header.command, packet.header.source, packet.buffer);
76  }
77 }
78 #endif // USE_SOCKETW
79 
80 } // namespace ChatSystem
81 } // namespace RoR
RoR::App::GetNetwork
Network * GetNetwork()
Definition: Application.cpp:288
Console.h
RoR::Console::CONSOLE_SYSTEM_NETCHAT
@ CONSOLE_SYSTEM_NETCHAT
Definition: Console.h:55
Utils.h
RoRnet
Definition: ForwardDeclarations.h:266
Language.h
GUIManager.h
Actor.h
RoRnet::MSG2_UTF8_CHAT
@ MSG2_UTF8_CHAT
broadcast chat line in UTF8 encoding; Payload: const char*(text)
Definition: RoRnet.h:59
RoRnet::MSG2_UTF8_PRIVCHAT
@ MSG2_UTF8_PRIVCHAT
private chat line in UTF8 encoding; Payload: uint32_t(uniqueid), const char*(text)
Definition: RoRnet.h:60
BITMASK_IS_1
#define BITMASK_IS_1(VAR, FLAGS)
Definition: BitFlags.h:14
ChatSystem.h
RoR::ChatSystem::SendStreamSetup
void SendStreamSetup()
Definition: ChatSystem.cpp:35
RoR::App::GetConsole
Console * GetConsole()
Definition: Application.cpp:274
RoR::ChatSystem::HandleStreamData
void HandleStreamData(std::vector< RoR::NetRecvPacket > packet_buffer)
Definition: ChatSystem.cpp:71
RoRnet::StreamRegister::status
int32_t status
initial stream status
Definition: RoRnet.h:151
RoR::SanitizeUtf8CString
std::string SanitizeUtf8CString(const char *start, const char *end=nullptr)
Definition: Utils.cpp:128
RoRnet::StreamRegister::type
int32_t type
0 = Actor, 1 = Character, 3 = ChatSystem
Definition: RoRnet.h:150
RoRnet::StreamRegister::name
char name[128]
file name
Definition: RoRnet.h:154
_L
#define _L
Definition: ErrorUtils.cpp:35
RoR::Console::putNetMessage
void putNetMessage(int user_id, MessageType type, const char *text)
Definition: Console.cpp:108
BitMask_t
uint32_t BitMask_t
Definition: BitFlags.h:7
RoRnet::PEEROPT_MUTE_CHAT
@ PEEROPT_MUTE_CHAT
CHAT and PRIVCHAT messages will not be allowed through.
Definition: RoRnet.h:129
RoR::Network::AddLocalStream
void AddLocalStream(RoRnet::StreamRegister *reg, int size)
Definition: Network.cpp:662
RoR
Definition: AppContext.h:36
RoR::ChatSystem::ReceiveStreamData
void ReceiveStreamData(unsigned int type, int source, char *buffer)
Definition: ChatSystem.cpp:48
RoRnet::StreamRegister
< Sent from the client to server and vice versa, to broadcast a new stream
Definition: RoRnet.h:148