RigsofRods
Soft-body Physics Simulation
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  std::string text = SanitizeUtf8CString(buffer);
54  if (type == MSG2_UTF8_PRIVCHAT)
55  {
56  text = _L(" [whispered] ") + text;
57  }
58 
60 }
61 #endif // USE_SOCKETW
62 
63 #ifdef USE_SOCKETW
64 void HandleStreamData(std::vector<RoR::NetRecvPacket> packet_buffer)
65 {
66  for (auto packet : packet_buffer)
67  {
68  ReceiveStreamData(packet.header.command, packet.header.source, packet.buffer);
69  }
70 }
71 #endif // USE_SOCKETW
72 
73 } // namespace ChatSystem
74 } // namespace RoR
RoR::App::GetNetwork
Network * GetNetwork()
Definition: Application.cpp:284
Console.h
RoR::Console::CONSOLE_SYSTEM_NETCHAT
@ CONSOLE_SYSTEM_NETCHAT
Definition: Console.h:55
Utils.h
RoRnet
Definition: ForwardDeclarations.h:232
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
ChatSystem.h
RoR::ChatSystem::SendStreamSetup
void SendStreamSetup()
Definition: ChatSystem.cpp:35
RoR::App::GetConsole
Console * GetConsole()
Definition: Application.cpp:270
RoR::ChatSystem::HandleStreamData
void HandleStreamData(std::vector< RoR::NetRecvPacket > packet_buffer)
Definition: ChatSystem.cpp:64
RoRnet::StreamRegister::status
int32_t status
initial stream status
Definition: RoRnet.h:143
RoR::SanitizeUtf8CString
std::string SanitizeUtf8CString(const char *start, const char *end=nullptr)
Definition: Utils.cpp:125
RoRnet::StreamRegister::type
int32_t type
0 = Actor, 1 = Character, 3 = ChatSystem
Definition: RoRnet.h:142
RoRnet::StreamRegister::name
char name[128]
file name
Definition: RoRnet.h:146
_L
#define _L
Definition: ErrorUtils.cpp:34
RoR::Console::putNetMessage
void putNetMessage(int user_id, MessageType type, const char *text)
Definition: Console.cpp:102
RoR::Network::AddLocalStream
void AddLocalStream(RoRnet::StreamRegister *reg, int size)
Definition: Network.cpp:660
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:140