The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
player_network.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2003 - 2016 by David White <[email protected]>
3  Copyright (C) 2009 - 2016 by Tomasz Sniatowski <[email protected]>
4  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #include "player_network.hpp"
17 #include "log.hpp"
19 
21 #define WRN_CONFIG LOG_STREAM(warn, log_config_pn)
22 
23 namespace wesnothd {
24 
25 namespace chat_message {
26 
27 const size_t max_message_length = 256;
28 
30 {
31  // testing for msg.size() is not sufficient but we're not getting false negatives
32  // and it's cheaper than always converting to ucs4::string.
33  if(str.size() > static_cast<int>(chat_message::max_message_length)) {
34  std::string tmp(str.begin(), str.end());
35  // The string can contain utf-8 characters so truncate as ucs4::string otherwise
36  // a corrupted utf-8 string can be returned.
37  utf8::truncate_as_ucs4(tmp, max_message_length);
38  message.set_attr_dup("message", tmp.c_str());
39  }
40 }
41 
42 } // end chat_message namespace
43 
44 } //end namespace wesnothd
This class represents a single stored chat message.
Definition: data.hpp:27
lg::log_domain log_config_pn("config")
void truncate_as_ucs4(utf8::string &str, const size_t size)
Truncates a UTF-8 string to the specified number of characters.
Definition: unicode.cpp:124
void truncate_message(const simple_wml::string_span &str, simple_wml::node &message)
Function to ensure a text message is within the allowed length.
const char * end() const
Definition: simple_wml.hpp:91
node & set_attr_dup(const char *key, const char *value)
Definition: simple_wml.cpp:427
const char * begin() const
Definition: simple_wml.hpp:90
Definition: ban.cpp:28
Standard logging facilities (interface).
GLsizei GLenum GLuint GLuint GLsizei char * message
Definition: glew.h:2499
GLsizei const GLcharARB ** string
Definition: glew.h:4503
const size_t max_message_length