campaignd: Simplify/move code...
...introduced in 2012-02-01T04:28:19Z!shadowm@wesnoth.org to a server-side-only code unit, making a backport to 1.10 completely safe on the client side Also, removed an accidental extra include.
This commit is contained in:
parent
47aa72ecc0
commit
5ff7d902c9
4 changed files with 17 additions and 31 deletions
|
@ -18,27 +18,11 @@
|
|||
#include "addon/validation.hpp"
|
||||
#include "config.hpp"
|
||||
#include "foreach.hpp"
|
||||
#include "marked-up_text.hpp"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
const unsigned short default_campaignd_port = 15002;
|
||||
|
||||
namespace {
|
||||
// Markup characters recognized by GUI1 code. These must be
|
||||
// the same as the constants defined in marked-up_text.cpp.
|
||||
const std::string illegal_markup_chars = "*`~{^}|@#<&";
|
||||
|
||||
inline bool starts_with_text_markup_char(const std::string& str)
|
||||
{
|
||||
if(str.empty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return illegal_markup_chars.find(str[0]) != std::string::npos;
|
||||
}
|
||||
}
|
||||
|
||||
static bool two_dots(char a, char b)
|
||||
{
|
||||
return a == '.' && b == '.';
|
||||
|
@ -51,20 +35,13 @@ bool addon_name_legal(const std::string& name)
|
|||
std::find(name.begin(),name.end(),'\\') != name.end() ||
|
||||
std::find(name.begin(),name.end(),':') != name.end() ||
|
||||
std::find(name.begin(),name.end(),'~') != name.end() ||
|
||||
std::adjacent_find(name.begin(),name.end(),two_dots) != name.end() ||
|
||||
starts_with_text_markup_char(name)
|
||||
) {
|
||||
std::adjacent_find(name.begin(),name.end(),two_dots) != name.end()) {
|
||||
return false;
|
||||
} else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool addon_title_legal(const std::string& title)
|
||||
{
|
||||
return !starts_with_text_markup_char(title);
|
||||
}
|
||||
|
||||
bool check_names_legal(const config& dir)
|
||||
{
|
||||
foreach (const config &path, dir.child_range("file")) {
|
||||
|
|
|
@ -56,8 +56,6 @@ ADDON_TYPE get_addon_type(const std::string& str);
|
|||
|
||||
/** Checks whether an add-on name is legal or not. */
|
||||
bool addon_name_legal(const std::string& name);
|
||||
/** Checks whether an add-on title is legal or not. */
|
||||
bool addon_title_legal(const std::string& title);
|
||||
/** Probes an add-on archive for illegal names. */
|
||||
bool check_names_legal(const config& dir);
|
||||
|
||||
|
|
|
@ -71,6 +71,14 @@ static void exit_sigterm(int signal) {
|
|||
}
|
||||
|
||||
namespace {
|
||||
// Markup characters recognized by GUI1 code. These must be
|
||||
// the same as the constants defined in marked-up_text.cpp.
|
||||
const std::string illegal_markup_chars = "*`~{^}|@#<&";
|
||||
|
||||
inline bool is_text_markup_char(char c)
|
||||
{
|
||||
return illegal_markup_chars.find(c) != std::string::npos;
|
||||
}
|
||||
|
||||
config construct_message(const std::string& msg)
|
||||
{
|
||||
|
@ -406,12 +414,15 @@ namespace {
|
|||
} else if (!addon_name_legal(upload["name"])) {
|
||||
LOG_CS << "Upload aborted - invalid add-on name.\n";
|
||||
network::send_data(construct_error("Add-on rejected: The name of the add-on is invalid."), sock);
|
||||
} else if (is_text_markup_char(upload["name"].str()[0])) {
|
||||
LOG_CS << "Upload aborted - add-on name starts with an illegal formatting character.\n";
|
||||
network::send_data(construct_error("Add-on rejected: The name of the add-on starts with an illegal formatting character."), sock);
|
||||
} else if (upload["title"].empty()) {
|
||||
LOG_CS << "Upload aborted - no add-on title specified.\n";
|
||||
network::send_data(construct_error("Add-on rejected: You did not specify the title of the add-on in the pbl file!"), sock);
|
||||
} else if (!addon_title_legal(upload["title"])) {
|
||||
LOG_CS << "Upload aborted - invalid add-on name.\n";
|
||||
network::send_data(construct_error("Add-on rejected: The title of the add-on is invalid."), sock);
|
||||
} else if (is_text_markup_char(upload["title"].str()[0])) {
|
||||
LOG_CS << "Upload aborted - add-on title starts with an illegal formatting character.\n";
|
||||
network::send_data(construct_error("Add-on rejected: The title of the add-on starts with an illegal formatting character."), sock);
|
||||
} else if (get_addon_type(upload["type"]) == ADDON_UNKNOWN) {
|
||||
LOG_CS << "Upload aborted - unknown add-on type specified.\n";
|
||||
network::send_data(construct_error("Add-on rejected: You did not specify a known type for the add-on in the pbl file! (See PblWML: wiki.wesnoth.org/PblWML)"), sock);
|
||||
|
|
|
@ -33,8 +33,8 @@
|
|||
namespace font {
|
||||
|
||||
// NOTE: if you add more markup characters below, you'll need to update
|
||||
// the list in addon/validation.cpp to blacklist them for add-on names
|
||||
// and titles.
|
||||
// the list in campaign_server.cpp (illegal_markup_chars) to blacklist
|
||||
// them for add-on names and titles.
|
||||
|
||||
const char LARGE_TEXT='*', SMALL_TEXT='`',
|
||||
BOLD_TEXT='~', NORMAL_TEXT='{',
|
||||
|
|
Loading…
Add table
Reference in a new issue