widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #05923
[Merge] lp:~widelands-dev/widelands/dedicated_out_of_main into lp:widelands
SirVer has proposed merging lp:~widelands-dev/widelands/dedicated_out_of_main into lp:widelands.
Commit message:
Remove --dedicated commandline option and associated code.
Rational: --dedicated allowed people who could host a game to keep a server running that people who could not host could control to play games. This is a great feature, but it came at a price: dedicated required a lot of if () else () in many places, i.e. it was very widespread in the code. One of the most pervasive problems was that dedicated could not spin up a Graphic() instance, therfore g_gr == nullptr and a lot of code did not check for that - since g_gr is never null if the game is run normally. Therefore it was easily broken - I am not sure if it worked in b18, but it has not worked for at least a year.
Another problem was that dedicated is essentially a host instance, i.e. it has to run the full game logic for each game that is played. So it is prohibitively expensive to run it (for example) on the server. So we would have needed a donator to even provide another instance that could be used.
We also have a plan of fixing the hosting problem in a principled way: through the proxy server that is spawned by the metaserver that will forward packets between players. Unfortunately, this is not implemented yet and it will not be for b19.
Requested reviews:
Widelands Developers (widelands-dev)
Related bugs:
Bug #1322869 in widelands: "dedicated server broken due to calls to g_gr"
https://bugs.launchpad.net/widelands/+bug/1322869
Bug #1330068 in widelands: "Widelands should never run as a daemon"
https://bugs.launchpad.net/widelands/+bug/1330068
Bug #1355397 in widelands: "Dedication server (cli option) core dumps on non-existing files"
https://bugs.launchpad.net/widelands/+bug/1355397
Bug #1416864 in widelands: "--dedicated issues: needs X, not killable, thrashes X"
https://bugs.launchpad.net/widelands/+bug/1416864
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/dedicated_out_of_main/+merge/285268
Requires https://code.launchpad.net/~widelands-dev/widelands/different_replay_names/+merge/285265 to be merged first.
Spend an hour today trying to fix --dedicated. Then decided it was too difficult after I could not follow the various state machines anymore and after it kept crashing. Now I ripped it out. This closes a few bugs related to --dedicated and simplifies the code, but of course the dedicated feature is gone for good.
--
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/dedicated_out_of_main into lp:widelands.
=== modified file 'src/CMakeLists.txt'
--- src/CMakeLists.txt 2014-12-06 12:22:35 +0000
+++ src/CMakeLists.txt 2016-02-06 16:06:14 +0000
@@ -106,7 +106,6 @@
graphic_text
graphic_text_layout
helper
- io_dedicated_log
io_filesystem
logic
logic_game_controller
@@ -130,8 +129,6 @@
base_exceptions
)
-
-
if (CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
target_link_libraries(widelands_ball_of_mud ${EXECINFO_LIBRARY})
endif (CMAKE_SYSTEM_NAME MATCHES "FreeBSD" OR CMAKE_SYSTEM_NAME MATCHES "OpenBSD")
=== modified file 'src/io/CMakeLists.txt'
--- src/io/CMakeLists.txt 2014-11-28 16:40:55 +0000
+++ src/io/CMakeLists.txt 2016-02-06 16:06:14 +0000
@@ -44,16 +44,3 @@
io_stream
third_party_minizip
)
-
-
-wl_library(io_dedicated_log
- SRCS
- dedicated_log.h
- dedicated_log.cc
- DEPENDS
- base_i18n
- base_log
- chat
- io_fileread
- io_filesystem
-)
=== removed file 'src/io/dedicated_log.cc'
--- src/io/dedicated_log.cc 2014-09-30 05:41:55 +0000
+++ src/io/dedicated_log.cc 1970-01-01 00:00:00 +0000
@@ -1,342 +0,0 @@
-/*
- * Copyright (C) 2012-2013 by the Widelands Development Team
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#include "io/dedicated_log.h"
-
-#include <string>
-
-#include <boost/format.hpp>
-
-#include "base/i18n.h"
-#include "base/log.h"
-#include "io/filesystem/layered_filesystem.h"
-
-/// The dedicated server logger
-static DedicatedLog * logger;
-
-extern std::ostream & wout;
-
-void dedicatedlog(const char * const fmt, ...) {
- char buffer[2048];
- va_list va;
-
- va_start(va, fmt);
- vsnprintf(buffer, sizeof(buffer), fmt, va);
- va_end(va);
-
- // Here comes the difference to widelands standard log() ;)
- DedicatedLog::get()->dlog(buffer);
-
- wout << buffer;
- wout.flush();
-}
-
-/// protected constructor
-DedicatedLog::DedicatedLog()
-:
-m_chat_file_path(""),
-m_info_file_path(""),
-m_log_file_path(""),
-d_name(""),
-d_motd(""),
-d_start(""),
-d_logins(0),
-d_logouts(0),
-d_chatmessages(0),
-root(new RealFSImpl("/"))
-{
- char ts[42];
- time_t currenttime = time(nullptr);
- strftime(ts, sizeof(ts), "%a %Y/%m/%d, %H:%M:%S", localtime(¤ttime));
- d_start = ts;
- d_ip = (boost::format("\\<%s\\>") % _("unknown")).str();
-}
-
-
-/// \returns the dedicated server logger, if it is not yet initialized, this is done before.
-DedicatedLog * DedicatedLog::get() {
- if (logger == nullptr)
- logger = new DedicatedLog();
- return logger;
-}
-
-
-/**
- * chat(ChatMessage & c)
- *
- * Writes the ChatMessage \arg c to the chat log, if initialized.
- */
-void DedicatedLog::chat(ChatMessage & c) {
- if (!m_info_file_path.empty()) {
- ++d_chatmessages;
- info_update();
- }
-
- if (m_chat_file_path.empty())
- return;
-
- std::string temp("<tr>");
- temp += "<td class=\"time\">";
- char ts[32];
- strftime(ts, sizeof(ts), "[%Y-%m-%d, %H:%M]", localtime(&c.time));
- temp += (boost::format("%s</td><td class=\"player%i\">") % ts % c.playern).str();
- temp += c.sender.empty() ? "SYSTEM" : c.sender;
- temp += "</td><td class=\"recipient\"> ->" + c.recipient + "</td><td class=\"message\">";
- temp += c.msg + "</td></tr>\n";
- m_chat.print_f("%s", temp.c_str());
- m_chat.write_append(*root, m_chat_file_path.c_str());
-}
-
-/// Add's a spacer to the chat log
-void DedicatedLog::chat_add_spacer() {
- if (m_chat_file_path.empty())
- return;
-
- m_chat.print_f("<tr><td class=\"space\"></td><td class=\"space\"></td>");
- m_chat.print_f("<td class=\"space\"></td><td class=\"space\"></td></tr>\n");
- m_chat.write_append(*root, m_chat_file_path.c_str());
-}
-
-
-/// Sets the basic server informations
-void DedicatedLog::set_server_data(std::string name, std::string motd) {
- if (!d_name.empty())
- return;
- d_name = name;
- d_motd = motd;
- info_update();
-}
-
-
-/// Sets the servers ip informations
-void DedicatedLog::set_server_ip(std::string ip) {
- if (d_ip != ip) {
- d_ip = ip;
- info_update();
- }
-}
-
-
-/// Saves the data of a newly started game
-void DedicatedLog::game_start(std::vector<std::string> clients, std::string mapname) {
- GameStatistic * new_game = new GameStatistic;
- new_game->mapname = mapname;
- new_game->times.push_back(time(nullptr));
- new_game->clients = clients;
- d_games.push_back(*new_game);
- delete new_game;
- new_game = nullptr;
- info_update();
-}
-
-
-/// Saves the winners of the last started game
-void DedicatedLog::game_end(std::vector<std::string> winners) {
- assert(!d_games.empty());
- d_games.back().winners = winners;
- d_games.back().times.push_back(time(nullptr));
- info_update();
-}
-
-
-/// Updates the server information file with current data
-void DedicatedLog::info_update() {
- if (m_info_file_path.empty())
- return;
-
- std::string temp("<table class=\"infohead\">\n");
- // Basic information
- temp += "<tr><td class=\"infoname\">Servername</td><td class=\"info\">" + d_name + "</td></tr>\n";
- temp += "<tr><td class=\"infoname\">Server IP</td><td class=\"info\">" + d_ip + "</td></tr>\n";
- temp += "<tr><td class=\"infoname\">Server MOTD</td><td class=\"info\">" + d_motd + "</td></tr>\n";
- temp += "<tr><td class=\"infoname\">Started on</td><td class=\"info\">" + d_start + "</td></tr>\n";
- temp += "<tr><td class=\"infoname\">Logins</td><td class=\"info\">";
- temp += std::to_string(d_logins) + "</td></tr>\n";
- temp += "<tr><td class=\"infoname\">Logouts</td><td class=\"info\">";
- temp += std::to_string(d_logouts) + "</td></tr>\n";
- temp += "<tr><td class=\"infoname\">Chat messages</td><td class=\"info\">";
- temp += std::to_string(d_chatmessages) + "</td></tr>\n";
- temp += "<tr><td class=\"infoname\">Games started</td><td class=\"info\">";
- temp += std::to_string(d_games.size()) + "</td></tr>\n";
- if (!d_games.empty()) {
- // Games information
- temp += "</table><br><table class=\"infogames\">\n";
- temp += "<tr><th>start/end of game</th><th>map name</th><th>client(s)</th><th>winner(s)</th></tr>\n";
-
- for (uint16_t i = 0; i < d_games.size(); ++i) {
- assert(!d_games.at(i).clients.empty() && !d_games.at(i).times.empty());
- // Start and (if already ended) end time
- char ts[42];
- strftime(ts, sizeof(ts), "S: %Y/%m/%d, %H:%M:%S", localtime(&d_games.at(i).times.at(0)));
- temp += (boost::format("<tr><td>%s") % ts).str();
- if (d_games.at(i).times.size() > 1) {
- strftime(ts, sizeof(ts), "E: %Y/%m/%d, %H:%M:%S", localtime(&d_games.at(i).times.at(1)));
- temp += (boost::format("<br>%s") % ts).str();
- }
- // Map name
- temp += (boost::format("</td><td>%s</td><td>") % d_games.at(i).mapname).str();
- // Players
- for (uint16_t j = 0; j < d_games.at(i).clients.size(); ++j) {
- if (j > 0)
- temp += ", ";
- temp += d_games.at(i).clients.at(j);
- }
- temp += "</td><td>";
- // Winners
- for (uint16_t j = 0; j < d_games.at(i).winners.size(); ++j) {
- if (j > 0)
- temp += ", ";
- temp += d_games.at(i).winners.at(j);
- }
- temp += "</td></tr>\n";
- }
- }
- temp += "</table>\n";
- m_chat.print_f("%s", temp.c_str());
- m_chat.write(*root, m_info_file_path.c_str());
-}
-
-/// Appends the String \arg msg to the log file
-void DedicatedLog::dlog(std::string msg) {
- if (m_log_file_path.empty())
- return;
-
- std::string temp("<tr><td class=\"time\">");
- char ts[32];
- time_t * t = new time_t(time(nullptr));
- strftime(ts, sizeof(ts), "[%Y-%m-%d, %H:%M]", localtime(t));
- delete t;
- temp += ts;
- temp += "</td><td class=\"log\">";
- temp += msg;
- temp += "</td></tr>\n";
- m_chat.print_f("%s", temp.c_str());
- m_chat.write_append(*root, m_log_file_path.c_str());
-}
-
-
-/**
- * set_chat_file_path(std::string path)
- *
- * Post initialization - this function can be called more than once, but will only handle the input data
- * as long as the chat file path is not yet set up correctly.
- * The function takes care:
- * - Whether the file at \arg path is writeable - \returns false if not.
- * - About file cleanup - all following data will be attached, therefore the original file will be removed
- * - About the initial formating like table headers, etc.
- *
- * \returns false, if path is not writeable, in all other cases true
- */
-bool DedicatedLog::set_chat_file_path(std::string path) {
- if (!m_chat_file_path.empty() || path.empty())
- return true;
-
- if (!check_file_writeable(path))
- return false;
-
- // Everything's fine, set the path
- m_chat_file_path = path;
-
- // Initialize the chat file
- m_chat.print_f("<tr><th>Time</th><th>Sender</th><th>Recipient</th><th>Message</th></tr>");
- m_chat.write(*root, m_chat_file_path.c_str()); // Not write_append, to make sure the file is cleared
- return true;
-}
-
-
-/**
- * set_info_file_path(std::string path)
- *
- * Post initialization - this function can be called more than once, but will only handle the input data
- * as long as the info file path is not yet set up correctly.
- * The function takes care:
- * - Whether the file at \arg path is writeable - \returns false if not.
- * - About file cleanup - all following data will be attached, therefore the original file will be removed
- * - About the initial formating like table headers, etc.
- *
- * \returns false, if path is not writeable, in all other cases true
- */
-bool DedicatedLog::set_info_file_path(std::string path) {
- if (!m_info_file_path.empty() || path.empty())
- return true;
-
- if (!check_file_writeable(path))
- return false;
-
- // Everything's fine, set the path and write info for the first time;
- m_info_file_path = path;
- info_update();
- return true;
-}
-
-
-/**
- * set_log_file_path(std::string path)
- *
- * Post initialization - this function can be called more than once, but will only handle the input data
- * as long as the log file path is not yet set up correctly.
- * The function takes care:
- * - Whether the file at \arg path is writeable - \returns false if not.
- * - About file cleanup - all following data will be attached, therefore the original file will be removed
- * - About the initial formating like table headers, etc.
- *
- * \returns false, if path is not writeable, in all other cases true
- */
-bool DedicatedLog::set_log_file_path (std::string path) {
- if (!m_log_file_path.empty() || path.empty())
- return true;
-
- if (!check_file_writeable(path))
- return false;
-
- // Everything's fine, set the path
- m_log_file_path = path;
-
- // Initialize the log file
- m_chat.print_f("<tr><th></th><th>Widelands dedicated server log:</th></tr>\n");
- m_chat.write(*root, m_log_file_path.c_str()); // Not write_append, to make sure the file is cleared
- return true;
-}
-
-
-/**
- * check_file_writeable(std::string & path)
- *
- * Checks if a file is writeable to \arg path and if yes and a file of that name is already existing
- * moves the original file to path + "~".
- *
- * \returns false, if path is not writeable or if path is a directory or if the directory the file should be
- * written to does not exist, in all other cases true.
- */
-bool DedicatedLog::check_file_writeable(std::string & path) {
- bool existing = root->file_exists(path);
- if (existing && root->is_directory(path))
- return false;
- if (root->file_is_writeable(path)) {
- if (existing) {
- std::string rnpath(path + '~');
- if (root->file_is_writeable(rnpath))
- root->fs_rename(path, rnpath);
- else
- log("Note: original file %s could not be backuped\n", path.c_str());
- }
- return true;
- }
- return false;
-}
=== removed file 'src/io/dedicated_log.h'
--- src/io/dedicated_log.h 2014-09-20 09:37:47 +0000
+++ src/io/dedicated_log.h 1970-01-01 00:00:00 +0000
@@ -1,90 +0,0 @@
-/*
- * Copyright (C) 2012 by the Widelands Development Team
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- */
-
-#ifndef WL_IO_DEDICATED_LOG_H
-#define WL_IO_DEDICATED_LOG_H
-
-#include "base/log.h"
-#include "chat/chat.h"
-#include "io/filesystem/disk_filesystem.h"
-#include "io/filewrite.h"
-
-void dedicatedlog(const char *, ...) PRINTF_FORMAT(1, 2);
-
-/// This struct writes some statistics and chat data to commandline defined files
-struct DedicatedLog {
- // Always call DedicatedLog via get() to have only one instance
- static DedicatedLog * get();
-
- // chat logging functions
- void chat_add_spacer();
- void chat(ChatMessage & c);
-
- // info logging functions
- bool write_info_active() {return !m_info_file_path.empty();}
- void set_server_data(std::string name, std::string motd);
- void set_server_ip (std::string ip);
- void client_login() {++d_logins; info_update();} // simple counter
- void client_logout() {++d_logouts; info_update();} // simple counter
- void game_start(std::vector<std::string> clients, std::string mapname);
- void game_end (std::vector<std::string> winners);
- void info_update(); // updates the info file
-
- // normal log logging function
- void dlog(std::string);
-
- // Post initialization - can be called more than once, but only the first call will be handled
- // The functions do not only set up the output path, but as well take care about file cleanup and
- // generate the initial formating
- bool set_chat_file_path(std::string path);
- bool set_info_file_path(std::string path);
- bool set_log_file_path (std::string path);
-
-protected:
- /// Constructor is protected by purpose - only one instance of DedicatedLog is allowed
- /// call DedicatedLog::get() instead.
- DedicatedLog();
-
-private:
- bool check_file_writeable(std::string & path);
-
- std::string m_chat_file_path;
- std::string m_info_file_path;
- std::string m_log_file_path;
-
- FileWrite m_chat;
- FileWrite m_info;
- FileWrite m_path;
-
- // statics data
- struct GameStatistic {
- std::string mapname;
- std::vector<std::string> clients;
- std::vector<std::string> winners;
- std::vector<time_t> times;
- };
- std::string d_name, d_ip, d_motd, d_start;
- uint32_t d_logins, d_logouts, d_chatmessages;
- std::vector<GameStatistic> d_games;
-
-
- RealFSImpl * root;
-};
-
-#endif // end of include guard: WL_IO_DEDICATED_LOG_H
=== modified file 'src/logic/editor_game_base.cc'
--- src/logic/editor_game_base.cc 2016-01-28 05:24:34 +0000
+++ src/logic/editor_game_base.cc 2016-02-06 16:06:14 +0000
@@ -83,11 +83,7 @@
EditorGameBase::~EditorGameBase() {
delete map_;
delete player_manager_.release();
-
- if (g_gr) { // dedicated does not use the sound_handler
- assert(this == g_sound_handler.egbase_);
- g_sound_handler.egbase_ = nullptr;
- }
+ g_sound_handler.egbase_ = nullptr;
}
void EditorGameBase::think()
=== modified file 'src/logic/game.cc'
--- src/logic/game.cc 2016-01-29 13:43:56 +0000
+++ src/logic/game.cc 2016-02-06 16:06:14 +0000
@@ -24,6 +24,7 @@
#include <memory>
#include <string>
+#include <boost/format.hpp>
#ifndef _WIN32
#include <SDL.h> // for a dirty hack.
#include <unistd.h> // for usleep
@@ -73,10 +74,7 @@
//#define SYNC_DEBUG
Game::SyncWrapper::~SyncWrapper() {
- if (m_dump) {
- delete m_dump;
- m_dump = nullptr;
-
+ if (m_dump != nullptr) {
if (!m_syncstreamsave)
g_fs->fs_unlink(m_dumpfname);
}
@@ -84,7 +82,7 @@
void Game::SyncWrapper::start_dump(const std::string & fname) {
m_dumpfname = fname + ".wss";
- m_dump = g_fs->open_stream_write(m_dumpfname);
+ m_dump.reset(g_fs->open_stream_write(m_dumpfname));
}
static const unsigned long long MINIMUM_DISK_SPACE = 256 * 1024 * 1024;
@@ -98,29 +96,21 @@
log("\n");
#endif
- if
- (m_dump &&
- static_cast<int32_t>(m_counter - m_next_diskspacecheck) >= 0)
- {
+ if (m_dump != nullptr && static_cast<int32_t>(m_counter - m_next_diskspacecheck) >= 0) {
m_next_diskspacecheck = m_counter + 16 * 1024 * 1024;
if (g_fs->disk_space() < MINIMUM_DISK_SPACE) {
log("Stop writing to syncstream file: disk is getting full.\n");
- delete m_dump;
- m_dump = nullptr;
+ m_dump.reset();
}
}
- if (m_dump) {
+ if (m_dump != nullptr) {
try {
m_dump->data(sync_data, size);
} catch (const WException &) {
- log
- ("Writing to syncstream file %s failed. Stop synctream dump.\n",
- m_dumpfname.c_str());
-
- delete m_dump;
- m_dump = nullptr;
+ log("Writing to syncstream file %s failed. Stop synctream dump.\n", m_dumpfname.c_str());
+ m_dump.reset();
}
}
@@ -137,7 +127,6 @@
m_writesyncstream (false),
m_state (gs_notrunning),
m_cmdqueue (*this),
- m_replaywriter (nullptr),
/** TRANSLATORS: Win condition for this game has not been set. */
m_win_condition_displayname(_("Not set"))
{
@@ -145,7 +134,6 @@
Game::~Game()
{
- delete m_replaywriter;
}
@@ -259,7 +247,7 @@
set_game_controller(new SinglePlayerGameController(*this, true, 1));
try {
- bool const result = run(&loaderUI, NewSPScenario, script_to_run, false);
+ bool const result = run(&loaderUI, NewSPScenario, script_to_run, false, "single_player");
delete m_ctrl;
m_ctrl = nullptr;
return result;
@@ -274,39 +262,34 @@
/**
* Initialize the game based on the given settings.
*
- * \note loaderUI can be nullptr, if this is run as dedicated server.
*/
void Game::init_newgame
(UI::ProgressWindow * loaderUI, const GameSettings & settings)
{
- if (loaderUI) {
- loaderUI->step(_("Preloading map"));
- }
+ assert(loaderUI != nullptr);
+
+ loaderUI->step(_("Preloading map"));
assert(!get_map());
set_map(new Map);
std::unique_ptr<MapLoader> maploader
(map().get_correct_loader(settings.mapfilename));
+ assert(maploader != nullptr);
maploader->preload_map(settings.scenario);
- if (loaderUI) {
- loaderUI->step(_("Loading world"));
- }
+ loaderUI->step(_("Loading world"));
world();
- if (loaderUI) {
- loaderUI->step(_("Loading tribes"));
- }
+ loaderUI->step(_("Loading tribes"));
tribes();
std::string const background = map().get_background();
- if (loaderUI) {
- if (!background.empty()) {
- loaderUI->set_background(background);
- }
- loaderUI->step(_("Configuring players"));
+ if (!background.empty()) {
+ loaderUI->set_background(background);
}
+ loaderUI->step(_("Configuring players"));
+
std::vector<PlayerSettings> shared;
std::vector<uint8_t> shared_num;
for (uint32_t i = 0; i < settings.players.size(); ++i) {
@@ -338,8 +321,7 @@
->add_further_starting_position(shared_num.at(n), shared.at(n).initialization_index);
}
- if (loaderUI)
- loaderUI->step(_("Loading map"));
+ loaderUI->step(_("Loading map"));
maploader->load_map_complete(*this,
settings.scenario ?
Widelands::MapLoader::LoadType::kScenario :
@@ -364,15 +346,13 @@
* At return the game is at the same state like a map loaded with Game::init()
* Only difference is, that players are already initialized.
* run<Returncode>() takes care about this difference.
- *
- * \note loaderUI can be nullptr, if this is run as dedicated server.
*/
void Game::init_savegame
(UI::ProgressWindow * loaderUI, const GameSettings & settings)
{
- if (loaderUI) {
- loaderUI->step(_("Preloading map"));
- }
+ assert(loaderUI != nullptr);
+
+ loaderUI->step(_("Preloading map"));
assert(!get_map());
set_map(new Map);
@@ -381,11 +361,9 @@
Widelands::GamePreloadPacket gpdp;
gl.preload_game(gpdp);
m_win_condition_displayname = gpdp.get_win_condition();
- if (loaderUI) {
- std::string background(gpdp.get_background());
- loaderUI->set_background(background);
- loaderUI->step(_("Loading..."));
- }
+ std::string background(gpdp.get_background());
+ loaderUI->set_background(background);
+ loaderUI->step(_("Loading..."));
gl.load_game(settings.multiplayer);
} catch (...) {
throw;
@@ -427,7 +405,7 @@
set_game_controller(new SinglePlayerGameController(*this, true, player_nr));
try {
- bool const result = run(&loaderUI, Loaded, script_to_run, false);
+ bool const result = run(&loaderUI, Loaded, script_to_run, false, "single_player");
delete m_ctrl;
m_ctrl = nullptr;
return result;
@@ -448,12 +426,7 @@
void Game::postload()
{
EditorGameBase::postload();
-
- if (g_gr) {
- assert(get_ibase() != nullptr);
- get_ibase()->postload();
- } else
- log("Note: Widelands runs without graphics, probably in dedicated server mode!\n");
+ get_ibase()->postload();
}
@@ -473,13 +446,13 @@
* 3. After this has happened, the game graphics are loaded.
*
* \return true if a game actually took place, false otherwise
- *
- * \note loader_ui can be nullptr, if this is run as dedicated server.
*/
bool Game::run
(UI::ProgressWindow * loader_ui, StartGameType const start_game_type,
- const std::string& script_to_run, bool replay)
+ const std::string& script_to_run, bool replay, const std::string& prefix_for_replays)
{
+ assert(loader_ui != nullptr);
+
m_replay = replay;
postload();
@@ -488,10 +461,8 @@
if (start_game_type == NewNonScenario) {
std::string step_description = _("Creating player infrastructure");
iterate_players_existing(p, nr_players, *this, plr) {
- if (loader_ui) {
- step_description += ".";
- loader_ui->step(step_description);
- }
+ step_description += ".";
+ loader_ui->step(step_description);
plr->create_default_infrastructure();
}
} else {
@@ -547,16 +518,13 @@
if (m_writereplay || m_writesyncstream) {
// Derive a replay filename from the current time
- std::string fname(REPLAY_DIR);
- fname += '/';
- fname += timestring();
- fname += REPLAY_SUFFIX;
-
+ const std::string fname = (boost::format("%s/%s_%s%s") % REPLAY_DIR % timestring() %
+ prefix_for_replays % REPLAY_SUFFIX).str();
if (m_writereplay) {
log("Starting replay writer\n");
assert(!m_replaywriter);
- m_replaywriter = new ReplayWriter(*this, fname);
+ m_replaywriter.reset(new ReplayWriter(*this, fname));
log("Replay writer has started\n");
}
@@ -567,46 +535,30 @@
sync_reset();
- if (loader_ui) {
- load_graphics(*loader_ui);
+ load_graphics(*loader_ui);
#ifdef _WIN32
- // Clear the event queue before starting game because we don't want
- // to handle events at game start that happened during loading procedure.
- SDL_Event event;
- while (SDL_PollEvent(&event));
-#endif
-
- g_sound_handler.change_music("ingame", 1000, 0);
-
- m_state = gs_running;
-
- get_ibase()->run<UI::Panel::Returncodes>();
-
- m_state = gs_ending;
-
- g_sound_handler.change_music("menu", 1000, 0);
-
- cleanup_objects();
- delete get_ibase();
- set_ibase(nullptr);
-
- m_state = gs_notrunning;
- } else {
- // dedicated server
- m_state = gs_running;
- //handle network
- while (m_state == gs_running) {
- // TODO(unknown): this should be improved.
-#ifndef _WIN32
- if (usleep(100) == -1)
- break;
-#else
- Sleep(1);
-#endif
- think();
- }
- }
+ // Clear the event queue before starting game because we don't want
+ // to handle events at game start that happened during loading procedure.
+ SDL_Event event;
+ while (SDL_PollEvent(&event));
+#endif
+
+ g_sound_handler.change_music("ingame", 1000, 0);
+
+ m_state = gs_running;
+
+ get_ibase()->run<UI::Panel::Returncodes>();
+
+ m_state = gs_ending;
+
+ g_sound_handler.change_music("menu", 1000, 0);
+
+ cleanup_objects();
+ delete get_ibase();
+ set_ibase(nullptr);
+
+ m_state = gs_notrunning;
return true;
}
@@ -636,12 +588,6 @@
}
}
-/// (Only) called by the dedicated server, to end a game once all players left
-void Game::end_dedicated_game() {
- assert(!g_gr);
- m_state = gs_notrunning;
-}
-
/**
* Cleanup for load
* \deprecated
=== modified file 'src/logic/game.h'
--- src/logic/game.h 2015-11-11 09:53:54 +0000
+++ src/logic/game.h 2016-02-06 16:06:14 +0000
@@ -20,6 +20,8 @@
#ifndef WL_LOGIC_GAME_H
#define WL_LOGIC_GAME_H
+#include <memory>
+
#include "base/md5.h"
#include "io/streamwrite.h"
#include "logic/cmd_queue.h"
@@ -108,7 +110,11 @@
void init_newgame (UI::ProgressWindow *, const GameSettings &);
void init_savegame(UI::ProgressWindow *, const GameSettings &);
enum StartGameType {NewSPScenario, NewNonScenario, Loaded, NewMPScenario};
- bool run(UI::ProgressWindow * loader_ui, StartGameType, const std::string& script_to_run, bool replay);
+ bool run(UI::ProgressWindow* loader_ui,
+ StartGameType,
+ const std::string& script_to_run,
+ bool replay,
+ const std::string& prefix_for_replays);
// Returns the upcasted lua interface.
LuaGameInterface& lua() override;
@@ -127,14 +133,15 @@
void think() override;
- ReplayWriter * get_replaywriter() {return m_replaywriter;}
+ ReplayWriter* get_replaywriter() {
+ return m_replaywriter.get();
+ }
/**
* \return \c true if the game is completely loaded and running (or paused)
* or \c false otherwise.
*/
bool is_loaded() {return m_state == gs_running;}
- void end_dedicated_game();
void cleanup_for_load() override;
@@ -217,7 +224,6 @@
m_target (target),
m_counter (0),
m_next_diskspacecheck(0),
- m_dump (nullptr),
m_syncstreamsave(false)
{}
@@ -238,7 +244,7 @@
StreamWrite & m_target;
uint32_t m_counter;
uint32_t m_next_diskspacecheck;
- ::StreamWrite * m_dump;
+ std::unique_ptr<::StreamWrite> m_dump;
std::string m_dumpfname;
bool m_syncstreamsave;
} m_syncwrapper;
@@ -263,8 +269,7 @@
SaveHandler m_savehandler;
- ReplayReader * m_replayreader;
- ReplayWriter * m_replaywriter;
+ std::unique_ptr<ReplayWriter> m_replaywriter;
GeneralStatsVector m_general_stats;
=== modified file 'src/logic/game_settings.h'
--- src/logic/game_settings.h 2016-01-28 05:24:34 +0000
+++ src/logic/game_settings.h 2016-02-06 16:06:14 +0000
@@ -67,12 +67,6 @@
bool ready; // until now only used as a check for whether user is currently receiving a file or not
};
-struct DedicatedMapInfos {
- std::string path;
- uint8_t players;
- bool scenario;
-};
-
/**
* Holds all settings about a game that can be configured before the
* game actually starts.
@@ -130,11 +124,6 @@
/// Users connected to the game (0-based indices) - only used in multiplayer
std::vector<UserSettings> users;
-
- /// Only used for dedicated servers so the clients can look through the maps available on the server
- /// like in their "own" map / saved games selection menu
- std::vector<DedicatedMapInfos> maps;
- std::vector<DedicatedMapInfos> saved_games;
};
=== modified file 'src/main.cc'
--- src/main.cc 2016-01-22 20:02:04 +0000
+++ src/main.cc 2016-02-06 16:06:14 +0000
@@ -22,10 +22,6 @@
#include <typeinfo>
#include <SDL_main.h>
-#ifndef _WIN32
-#include <fcntl.h>
-#include <syslog.h>
-#endif
#include <unistd.h>
#include "base/log.h"
@@ -45,59 +41,6 @@
*/
int main(int argc, char * argv[])
{
-
-#ifndef _WIN32
- // if Widelands is called as dedicated server, Widelands should be forked and started as daemon
- bool dedicated = false;
- bool daemon = false;
-
- for (int i = 1; i < argc && !(daemon && dedicated); ++i) {
- std::string opt = argv[i];
-
- // At least a size of 8 is needed for --daemon, --dedicated is even longer
- if (opt.size() < 8)
- continue;
-
- if (opt == "--version") {
- cout << "Widelands " << build_id() << '(' << build_type() << ')' << "\n";
- return 0;
- }
-
- std::string::size_type const pos = opt.find('=');
- if (pos == std::string::npos) { // if no equals sign found
- if (opt == "--daemon")
- daemon = true;
- } else {
- opt.erase(pos, opt.size() - pos);
- if (opt == "--dedicated")
- dedicated = true;
- }
- }
- if (daemon && dedicated) {
- pid_t pid;
- if ((pid = fork()) < 0) {
- perror("fork() failed");
- exit(2);
- }
- if (pid == 0) {
- setsid();
-
- close(STDIN_FILENO);
- close(STDOUT_FILENO);
- close(STDERR_FILENO);
-
- open("/dev/null", O_RDWR);
- dup(STDIN_FILENO);
- dup(STDIN_FILENO);
- // from now on, it's a daemon
- openlog("FREELINE", LOG_PID, LOG_DAEMON);
- } else {
- log("Child has PID %i.\n", pid);
- return 0;
- }
- }
-#endif
-
WLApplication * g_app = nullptr;
try {
g_app = WLApplication::get(argc, const_cast<char const * *>(argv));
=== modified file 'src/map_io/map_building_packet.cc'
--- src/map_io/map_building_packet.cc 2016-01-29 15:09:06 +0000
+++ src/map_io/map_building_packet.cc 2016-02-06 16:06:14 +0000
@@ -99,8 +99,7 @@
read_priorities (*building, fr);
// Reference the players tribe if in editor.
- if (g_gr) // but not on dedicated servers ;)
- ibase.reference_player_tribe(p, &tribe);
+ ibase.reference_player_tribe(p, &tribe);
} else
throw GameDataError("player %u does not exist", p);
}
=== modified file 'src/network/CMakeLists.txt'
--- src/network/CMakeLists.txt 2015-01-31 16:03:59 +0000
+++ src/network/CMakeLists.txt 2016-02-06 16:06:14 +0000
@@ -32,7 +32,6 @@
chat
game_io
helper
- io_dedicated_log
io_fileread
io_filesystem
io_stream
=== modified file 'src/network/internet_gaming.cc'
--- src/network/internet_gaming.cc 2015-10-25 15:44:36 +0000
+++ src/network/internet_gaming.cc 2016-02-06 16:06:14 +0000
@@ -26,7 +26,6 @@
#include "base/log.h"
#include "base/macros.h"
#include "base/warning.h"
-#include "io/dedicated_log.h"
#include "io/fileread.h"
#include "io/filesystem/layered_filesystem.h"
#include "network/internet_gaming_messages.h"
@@ -103,7 +102,7 @@
void InternetGaming::initialize_connection() {
// First of all try to connect to the metaserver
- dedicatedlog("InternetGaming: Connecting to the metaserver.\n");
+ log("InternetGaming: Connecting to the metaserver.\n");
IPaddress peer;
if (hostent * const he = gethostbyname(m_meta.c_str())) {
peer.host = (reinterpret_cast<in_addr *>(he->h_addr_list[0]))->s_addr;
@@ -147,7 +146,7 @@
initialize_connection();
// If we are here, a connection was established and we can send our login package through the socket.
- dedicatedlog("InternetGaming: Sending login request.\n");
+ log("InternetGaming: Sending login request.\n");
SendPacket s;
s.string(IGPCMD_LOGIN);
s.string(boost::lexical_cast<std::string>(INTERNET_GAMING_PROTOCOL_VERSION));
@@ -174,7 +173,7 @@
return false;
}
}
- dedicatedlog("InternetGaming: No answer from metaserver!\n");
+ log("InternetGaming: No answer from metaserver!\n");
logout("NO_ANSWER");
return false;
}
@@ -191,7 +190,7 @@
initialize_connection();
// If we are here, a connection was established and we can send our login package through the socket.
- dedicatedlog("InternetGaming: Sending relogin request.\n");
+ log("InternetGaming: Sending relogin request.\n");
SendPacket s;
s.string(IGPCMD_RELOGIN);
s.string(boost::lexical_cast<std::string>(INTERNET_GAMING_PROTOCOL_VERSION));
@@ -218,7 +217,7 @@
}
if (INTERNET_GAMING_TIMEOUT <= time(nullptr) - secs) {
- dedicatedlog("InternetGaming: No answer from metaserver!\n");
+ log("InternetGaming: No answer from metaserver!\n");
return false;
}
@@ -249,7 +248,7 @@
s.send(m_sock);
const std::string & msg = InternetGamingMessages::get_message(msgcode);
- dedicatedlog("InternetGaming: logout(%s)\n", msg.c_str());
+ log("InternetGaming: logout(%s)\n", msg.c_str());
format_and_add_chat("", "", true, msg);
reset();
@@ -269,7 +268,7 @@
if (!m_deserializer.read(m_sock)) {
set_error();
const std::string & msg = InternetGamingMessages::get_message("CONNECTION_LOST");
- dedicatedlog("InternetGaming: Error: %s\n", msg.c_str());
+ log("InternetGaming: Error: %s\n", msg.c_str());
format_and_add_chat("", "", true, msg);
// Check how much time passed since the socket broke the last time
@@ -331,7 +330,7 @@
if (now > waittimeout) {
set_error();
waittimeout = std::numeric_limits<int32_t>::max();
- dedicatedlog("InternetGaming: reached a timeout for an awaited answer of the metaserver!\n");
+ log("InternetGaming: reached a timeout for an awaited answer of the metaserver!\n");
if (!relogin()) {
// Do not try to relogin again automatically.
reset();
@@ -383,20 +382,20 @@
m_clientname = packet.string();
m_clientrights = packet.string();
m_state = LOBBY;
- dedicatedlog("InternetGaming: Client %s logged in.\n", m_clientname.c_str());
+ log("InternetGaming: Client %s logged in.\n", m_clientname.c_str());
return;
} else if (cmd == IGPCMD_RELOGIN) {
// Clients request to relogin was granted
m_state = LOBBY;
- dedicatedlog("InternetGaming: Client %s relogged in.\n", m_clientname.c_str());
+ log("InternetGaming: Client %s relogged in.\n", m_clientname.c_str());
format_and_add_chat("", "", true, _("Successfully reconnected to the metaserver!"));
return;
} else if (cmd == IGPCMD_ERROR) {
std::string errortype = packet.string();
if (errortype != "LOGIN" && errortype != "RELOGIN") {
- dedicatedlog("InternetGaming: Strange ERROR in connecting state: %s\n", errortype.c_str());
+ log("InternetGaming: Strange ERROR in connecting state: %s\n", errortype.c_str());
throw WLWarning(_("Mixed up"), _("The metaserver sent a strange ERROR during connection"));
}
// Clients login request got rejected
@@ -419,7 +418,7 @@
try {
if (cmd == IGPCMD_LOGIN || cmd == IGPCMD_RELOGIN) {
// Login specific commands but not in CONNECTING state...
- dedicatedlog
+ log
("InternetGaming: Received %s cmd although client is not in CONNECTING state.\n", cmd.c_str());
std::string temp =
(boost::format
@@ -431,7 +430,7 @@
else if (cmd == IGPCMD_TIME) {
// Client received the server time
time_offset = boost::lexical_cast<int>(packet.string()) - time(nullptr);
- dedicatedlog
+ log
(ngettext
("InternetGaming: Server time offset is %u second.",
"InternetGaming: Server time offset is %u seconds.", time_offset),
@@ -471,7 +470,7 @@
else if (cmd == IGPCMD_GAMES_UPDATE) {
// Client received a note, that the list of games was changed
- dedicatedlog("InternetGaming: Game update on metaserver.\n");
+ log("InternetGaming: Game update on metaserver.\n");
gameupdateonmetaserver = true;
}
@@ -480,7 +479,7 @@
uint8_t number = boost::lexical_cast<int>(packet.string()) & 0xff;
std::vector<InternetGame> old = gamelist;
gamelist.clear();
- dedicatedlog("InternetGaming: Received a game list update with %u items.\n", number);
+ log("InternetGaming: Received a game list update with %u items.\n", number);
for (uint8_t i = 0; i < number; ++i) {
InternetGame * ing = new InternetGame();
ing->name = packet.string();
@@ -513,7 +512,7 @@
else if (cmd == IGPCMD_CLIENTS_UPDATE) {
// Client received a note, that the list of clients was changed
- dedicatedlog("InternetGaming: Client update on metaserver.\n");
+ log("InternetGaming: Client update on metaserver.\n");
clientupdateonmetaserver = true;
}
@@ -522,7 +521,7 @@
uint8_t number = boost::lexical_cast<int>(packet.string()) & 0xff;
std::vector<InternetClient> old = clientlist;
clientlist.clear();
- dedicatedlog("InternetGaming: Received a client list update with %u items.\n", number);
+ log("InternetGaming: Received a client list update with %u items.\n", number);
for (uint8_t i = 0; i < number; ++i) {
InternetClient * inc = new InternetClient();
inc->name = packet.string();
@@ -639,7 +638,7 @@
s.string(gamename);
s.send(m_sock);
m_gamename = gamename;
- dedicatedlog("InternetGaming: Client tries to join a game with the name %s\n", m_gamename.c_str());
+ log("InternetGaming: Client tries to join a game with the name %s\n", m_gamename.c_str());
m_state = IN_GAME;
@@ -660,7 +659,7 @@
s.string(m_gamename);
s.string("1024"); // Used to be maxclients, no longer used.
s.send(m_sock);
- dedicatedlog("InternetGaming: Client opened a game with the name %s.\n", m_gamename.c_str());
+ log("InternetGaming: Client opened a game with the name %s.\n", m_gamename.c_str());
m_state = IN_GAME;
// From now on we wait for a reply from the metaserver
@@ -678,7 +677,7 @@
SendPacket s;
s.string(IGPCMD_GAME_START);
s.send(m_sock);
- dedicatedlog("InternetGaming: Client announced the start of the game %s.\n", m_gamename.c_str());
+ log("InternetGaming: Client announced the start of the game %s.\n", m_gamename.c_str());
// From now on we wait for a reply from the metaserver
waitcmd = IGPCMD_GAME_START;
@@ -700,7 +699,7 @@
m_gameip = "";
m_state = LOBBY;
- dedicatedlog("InternetGaming: Client announced the disconnect from the game %s.\n", m_gamename.c_str());
+ log("InternetGaming: Client announced the disconnect from the game %s.\n", m_gamename.c_str());
}
=== modified file 'src/network/netclient.cc'
--- src/network/netclient.cc 2016-01-28 05:24:34 +0000
+++ src/network/netclient.cc 2016-02-06 16:06:14 +0000
@@ -100,7 +100,7 @@
NetClient::NetClient
(IPaddress * const svaddr, const std::string & playername, bool internet)
-: d(new NetClientImpl), m_internet(internet), m_dedicated_access(false), m_dedicated_temp_scenario(false)
+: d(new NetClientImpl), m_internet(internet)
{
d->sock = SDLNet_TCP_Open(svaddr);
if (d->sock == nullptr)
@@ -157,17 +157,6 @@
d->modal = &lgm;
FullscreenMenuBase::MenuTarget code = lgm.run<FullscreenMenuBase::MenuTarget>();
d->modal = nullptr;
- // Only possible if server is dedicated - client pressed "start game" button
- if (code == FullscreenMenuBase::MenuTarget::kNormalGame) {
- SendPacket subs;
- subs.unsigned_8(NETCMD_LAUNCH);
- subs.send(d->sock);
-
- // Reopen the menu - perhaps the start is denied or other problems occur
- d->modal = &lgm;
- code = lgm.run<FullscreenMenuBase::MenuTarget>();
- d->modal = nullptr;
- }
if (code == FullscreenMenuBase::MenuTarget::kBack) {
// if this is an internet game, tell the metaserver that client is back in the lobby.
if (m_internet)
@@ -184,48 +173,43 @@
#endif
try {
- UI::ProgressWindow * loaderUI = new UI::ProgressWindow("images/loadscreens/progress.png");
+ UI::ProgressWindow* loaderUI = new UI::ProgressWindow("images/loadscreens/progress.png");
std::vector<std::string> tipstext;
tipstext.push_back("general_game");
tipstext.push_back("multiplayer");
try {
tipstext.push_back(get_players_tribe());
- } catch (NoTribe) {}
- GameTips tips (*loaderUI, tipstext);
+ } catch (NoTribe) {
+ }
+ GameTips tips(*loaderUI, tipstext);
loaderUI->step(_("Preparing game"));
d->game = &game;
game.set_game_controller(this);
uint8_t const pn = d->settings.playernum + 1;
- InteractiveGameBase * igb;
+ InteractiveGameBase* igb;
if (pn > 0)
- igb =
- new InteractivePlayer
- (game, g_options.pull_section("global"),
- pn, true);
+ igb = new InteractivePlayer(game, g_options.pull_section("global"), pn, true);
else
- igb =
- new InteractiveSpectator
- (game, g_options.pull_section("global"), true);
+ igb = new InteractiveSpectator(game, g_options.pull_section("global"), true);
game.set_ibase(igb);
igb->set_chat_provider(*this);
- if (!d->settings.savegame) // new map
+ if (!d->settings.savegame) { // new map
game.init_newgame(loaderUI, d->settings);
- else // savegame
+ } else { // savegame
game.init_savegame(loaderUI, d->settings);
+ }
d->time.reset(game.get_gametime());
d->lasttimestamp = game.get_gametime();
d->lasttimestamp_realtime = SDL_GetTicks();
d->modal = game.get_ibase();
- game.run
- (loaderUI,
- d->settings.savegame ?
- Widelands::Game::Loaded
- : d->settings.scenario ?
- Widelands::Game::NewMPScenario : Widelands::Game::NewNonScenario,
- "", false);
+ game.run(loaderUI, d->settings.savegame ? Widelands::Game::Loaded : d->settings.scenario ?
+ Widelands::Game::NewMPScenario :
+ Widelands::Game::NewNonScenario,
+ "", false,
+ (boost::format("netclient_%d") % static_cast<int>(d->settings.usernum)).str());
// if this is an internet game, tell the metaserver that the game is done.
if (m_internet)
@@ -318,38 +302,16 @@
return d->settings;
}
-void NetClient::set_scenario(bool scenario)
-{
- // only accessible, if server is a dedicated server and access is granted
- if (!m_dedicated_access)
- return;
- m_dedicated_temp_scenario = scenario;
-}
-
-bool NetClient::can_change_map()
-{
- // only true, if server is a dedicated server and access is granted
- return m_dedicated_access;
-}
-
-bool NetClient::can_change_player_state(uint8_t const number)
-{
- if (!m_dedicated_access) // normal case
- return false;
-
- // dedicated server, access granted
- if (d->settings.savegame)
- return d->settings.players.at(number).state != PlayerSettings::stateClosed;
- else if (d->settings.scenario)
- return
- ((d->settings.players.at(number).state == PlayerSettings::stateOpen
- ||
- d->settings.players.at(number).state == PlayerSettings::stateHuman)
- &&
- d->settings .players.at(number).closeable)
- ||
- d->settings .players.at(number).state == PlayerSettings::stateClosed;
- return true;
+void NetClient::set_scenario(bool) {
+}
+
+bool NetClient::can_change_map() {
+ return false;
+}
+
+bool NetClient::can_change_player_state(uint8_t const)
+{
+ return false;
}
bool NetClient::can_change_player_tribe(uint8_t number)
@@ -359,75 +321,17 @@
bool NetClient::can_change_player_team(uint8_t number)
{
- if (!m_dedicated_access) // normal case
- return (number == d->settings.playernum) && !d->settings.scenario && !d->settings.savegame;
- else { // dedicated server, access granted
- if (d->settings.scenario || d->settings.savegame)
- return false;
- if (number >= d->settings.players.size())
- return false;
- if (number == d->settings.playernum)
- return true;
- return
- d->settings.players.at(number).state == PlayerSettings::stateComputer;
- }
+ return (number == d->settings.playernum) && !d->settings.scenario && !d->settings.savegame;
}
bool NetClient::can_change_player_init(uint8_t number)
{
- if (!m_dedicated_access) // normal case
- return false;
- else { // dedicated server, access granted
- if (d->settings.scenario || d->settings.savegame)
- return false;
- return number < d->settings.players.size();
- }
+ return false;
}
bool NetClient::can_launch()
{
- // only true, if server is a dedicated server and access is granted
- if (!m_dedicated_access)
- return false;
- if (d->settings.mapname.empty())
- return false;
- if (d->settings.players.size() < 1)
- return false;
- if (d->game)
- return false;
-
- // if there is one client that is currently receiving a file, we can not launch.
- for (uint8_t i = 0; i < d->settings.users.size(); ++i) {
- if (d->settings.users[i].position == d->settings.users[i].not_connected())
- continue;
- if (!d->settings.users[i].ready)
- return false;
- }
-
- // all players must be connected to a controller (human/ai) or be closed.
- for (size_t i = 0; i < d->settings.players.size(); ++i) {
- if (d->settings.players.at(i).state == PlayerSettings::stateOpen)
- return false;
- }
- return true;
-}
-
-void NetClient::set_map
- (const std::string & name,
- const std::string & path,
- uint32_t /* players */,
- bool savegame)
-{
- // only accessible, if server is a dedicated server and access is granted
- if (!m_dedicated_access)
- return;
- SendPacket s;
- s.unsigned_8(NETCMD_SETTING_MAP);
- s.string(name);
- s.string(path);
- s.unsigned_8(savegame ? 1 : 0);
- s.unsigned_8(m_dedicated_temp_scenario ? 1 : 0);
- s.send(d->sock);
+ return false;
}
void NetClient::set_player_state(uint8_t, PlayerSettings::State)
@@ -442,18 +346,16 @@
void NetClient::next_player_state(uint8_t number)
{
- // only accessible, if server is a dedicated server and access is granted
- if (!m_dedicated_access)
- return;
- SendPacket s;
- s.unsigned_8(NETCMD_SETTING_PLAYER);
- s.unsigned_8(number);
- s.send(d->sock);
+ // client is not allowed to do this
+}
+
+void NetClient::set_map(const std::string&, const std::string&, uint32_t, bool) {
+ // client is not allowed to do this
}
void NetClient::set_player_tribe(uint8_t number, const std::string & tribe, bool const random_tribe)
{
- if ((number != d->settings.playernum) && !m_dedicated_access)
+ if ((number != d->settings.playernum))
return;
SendPacket s;
@@ -466,7 +368,7 @@
void NetClient::set_player_team(uint8_t number, Widelands::TeamNumber team)
{
- if ((number != d->settings.playernum) && !m_dedicated_access)
+ if ((number != d->settings.playernum))
return;
SendPacket s;
@@ -483,7 +385,7 @@
void NetClient::set_player_shared(uint8_t number, uint8_t player)
{
- if ((number != d->settings.playernum) && !m_dedicated_access)
+ if ((number != d->settings.playernum))
return;
SendPacket s;
@@ -495,7 +397,7 @@
void NetClient::set_player_init(uint8_t number, uint8_t)
{
- if ((number != d->settings.playernum) && !m_dedicated_access)
+ if ((number != d->settings.playernum))
return;
// Host will decide what to change, therefore the init is not send, just the request to change
@@ -526,12 +428,7 @@
}
void NetClient::next_win_condition() {
- // only accessible, if server is a dedicated server and access is granted
- if (!m_dedicated_access)
- return;
- SendPacket s;
- s.unsigned_8(NETCMD_WIN_CONDITION);
- s.send(d->sock);
+ // Clients are not allowed to change this
}
void NetClient::set_player_number(uint8_t const number)
@@ -687,6 +584,7 @@
return;
}
+
if (d->settings.usernum == -2) {
if (cmd != NETCMD_HELLO)
throw ProtocolException(cmd);
@@ -709,6 +607,7 @@
}
case NETCMD_SETTING_MAP: {
+
d->settings.mapname = packet.string();
d->settings.mapfilename = g_fs->FileSystem::fix_cross_file(packet.string());
d->settings.savegame = packet.unsigned_8() == 1;
@@ -723,23 +622,6 @@
break;
}
- case NETCMD_DEDICATED_MAPS: {
- DedicatedMapInfos info;
- info.path = g_fs->FileSystem::fix_cross_file(packet.string());
- info.players = packet.unsigned_8();
- info.scenario = packet.unsigned_8() == 1;
- d->settings.maps.push_back(info);
- break;
- }
-
- case NETCMD_DEDICATED_SAVED_GAMES: {
- DedicatedMapInfos info;
- info.path = g_fs->FileSystem::fix_cross_file(packet.string());
- info.players = packet.unsigned_8();
- d->settings.saved_games.push_back(info);
- break;
- }
-
case NETCMD_NEW_FILE_AVAILABLE: {
std::string path = g_fs->FileSystem::fix_cross_file(packet.string());
uint32_t bytes = packet.unsigned_32();
@@ -839,7 +721,6 @@
fr.open(*g_fs, file->filename);
std::unique_ptr<char[]> complete(new char[file->bytes]);
- if (!complete) throw wexception("Out of memory");
fr.data_complete(complete.get(), file->bytes);
SimpleMD5Checksum md5sum;
@@ -952,19 +833,23 @@
d->modal->end_modal<FullscreenMenuBase::MenuTarget>(FullscreenMenuBase::MenuTarget::kOk);
break;
}
+
case NETCMD_SETSPEED:
d->realspeed = packet.unsigned_16();
log
("[Client] speed: %u.%03u\n",
d->realspeed / 1000, d->realspeed % 1000);
break;
+
case NETCMD_TIME:
d->time.receive(packet.signed_32());
break;
+
case NETCMD_WAIT:
log("[Client]: server is waiting.\n");
d->server_is_waiting = true;
break;
+
case NETCMD_PLAYERCOMMAND: {
if (!d->game)
throw DisconnectException("PLAYERCMD_WO_GAME");
@@ -977,6 +862,7 @@
d->time.receive(time);
break;
}
+
case NETCMD_SYNCREQUEST: {
if (!d->game)
throw DisconnectException("SYNCREQUEST_WO_GAME");
@@ -985,6 +871,7 @@
d->game->enqueue_command(new CmdNetCheckSync(time, this));
break;
}
+
case NETCMD_CHAT: {
ChatMessage c;
c.time = time(nullptr);
@@ -997,6 +884,7 @@
Notifications::publish(c);
break;
}
+
case NETCMD_SYSTEM_MESSAGE_CODE: {
ChatMessage c;
c.time = time(nullptr);
@@ -1011,10 +899,7 @@
Notifications::publish(c);
break;
}
- case NETCMD_DEDICATED_ACCESS: {
- m_dedicated_access = true;
- break;
- }
+
case NETCMD_INFO_DESYNC:
log
("[Client] received NETCMD_INFO_DESYNC. Trying to salvage some "
@@ -1022,6 +907,7 @@
if (d->game)
d->game->save_syncstream(true);
break;
+
default:
throw ProtocolException(cmd);
}
=== modified file 'src/network/netclient.h'
--- src/network/netclient.h 2014-09-30 06:25:04 +0000
+++ src/network/netclient.h 2016-02-06 16:06:14 +0000
@@ -117,8 +117,6 @@
NetClientImpl * d;
bool m_internet;
- bool m_dedicated_access;
- bool m_dedicated_temp_scenario;
};
#endif // end of include guard: WL_NETWORK_NETCLIENT_H
=== modified file 'src/network/nethost.cc'
--- src/network/nethost.cc 2016-02-01 08:21:18 +0000
+++ src/network/nethost.cc 2016-02-06 16:06:14 +0000
@@ -40,7 +40,6 @@
#include "game_io/game_loader.h"
#include "game_io/game_preload_packet.h"
#include "helper.h"
-#include "io/dedicated_log.h"
#include "io/fileread.h"
#include "io/filesystem/layered_filesystem.h"
#include "logic/game.h"
@@ -310,7 +309,7 @@
struct HostChatProvider : public ChatProvider {
HostChatProvider(NetHost * const _h) : h(_h), kickClient(0) {}
- void send(const std::string & msg) override {
+ void send(const std::string& msg) override {
ChatMessage c;
c.time = time(nullptr);
c.playern = h->get_local_playerposition();
@@ -337,9 +336,9 @@
// Split up in "cmd" "arg1" "arg2"
std::string cmd, arg1, arg2;
- std::string temp = c.msg.substr(1); // cut off '/'
+ std::string temp = c.msg.substr(1); // cut off '/'
h->split_command_array(temp, cmd, arg1, arg2);
- dedicatedlog("%s + \"%s\" + \"%s\"\n", cmd.c_str(), arg1.c_str(), arg2.c_str());
+ log("%s + \"%s\" + \"%s\"\n", cmd.c_str(), arg1.c_str(), arg2.c_str());
// let "/me" pass - handled by chat
if (cmd == "me") {
@@ -354,32 +353,32 @@
// Help
if (cmd == "help") {
- c.msg =
- (boost::format("<br>%s<br>%s<br>%s<br>%s<br>%s<br>%s<br>%s")
- % _("Available host commands are:")
- /** TRANSLATORS: Available host command */
- % _("/help - Shows this help")
- /** TRANSLATORS: Available host command */
- % _("/announce <msg> - Send a chatmessage as announcement (system chat)")
- /** TRANSLATORS: Available host command */
- % _("/warn <name> <reason> - Warn the user <name> because of <reason>")
- /** TRANSLATORS: Available host command */
- % _("/kick <name> <reason> - Kick the user <name> because of <reason>")
- /** TRANSLATORS: Available host command */
- % _("/forcePause - Force the game to pause.")
- /** TRANSLATORS: Available host command */
- % _("/endForcedPause - Return game to normal speed.")
- ).str();
- if (!h->is_dedicated())
- c.recipient = h->get_local_playername();
+ c.msg = (boost::format("<br>%s<br>%s<br>%s<br>%s<br>%s<br>%s<br>%s") %
+ _("Available host commands are:")
+ /** TRANSLATORS: Available host command */
+ %
+ _("/help - Shows this help")
+ /** TRANSLATORS: Available host command */
+ %
+ _("/announce <msg> - Send a chatmessage as announcement (system chat)")
+ /** TRANSLATORS: Available host command */
+ %
+ _("/warn <name> <reason> - Warn the user <name> because of <reason>")
+ /** TRANSLATORS: Available host command */
+ %
+ _("/kick <name> <reason> - Kick the user <name> because of <reason>")
+ /** TRANSLATORS: Available host command */
+ %
+ _("/forcePause - Force the game to pause.")
+ /** TRANSLATORS: Available host command */
+ %
+ _("/endForcedPause - Return game to normal speed.")).str();
}
// Announce
else if (cmd == "announce") {
if (arg1.empty()) {
c.msg = _("Wrong use, should be: /announce <message>");
- if (!h->is_dedicated())
- c.recipient = h->get_local_playername();
} else {
if (arg2.size())
arg1 += " " + arg2;
@@ -391,22 +390,12 @@
else if (cmd == "warn") {
if (arg1.empty() || arg2.empty()) {
c.msg = _("Wrong use, should be: /warn <name> <reason>");
- if (!h->is_dedicated())
- c.recipient = h->get_local_playername();
} else {
int32_t num = h->check_client(arg1);
- if (num == -2) {
- if (!h->is_dedicated()) {
- c.recipient = h->get_local_playername();
- c.msg = _("Why would you warn yourself?");
- } else
- c.msg = _("Why would you want to warn the dedicated server?");
- } else if (num == -1) {
- if (!h->is_dedicated())
- c.recipient = h->get_local_playername();
+ if (num == -1) {
c.msg = (boost::format(_("The client %s could not be found.")) % arg1).str();
} else {
- c.msg = (boost::format("HOST WARNING FOR %s: ") % arg1).str();
+ c.msg = (boost::format("HOST WARNING FOR %s: ") % arg1).str();
c.msg += arg2;
}
}
@@ -424,22 +413,17 @@
kickReason = "No reason given!";
// Check if client exists
int32_t num = h->check_client(kickUser);
- if (num == -2)
- if (!h->is_dedicated()) {
- c.msg = _("You can not kick yourself!");
- } else
- c.msg = _("You can not kick the dedicated server");
- else if (num == -1)
- c.msg = (boost::format(_("The client %s could not be found.")) % arg1).str();
+ if (num == -1) c.msg =
+ (boost::format(_("The client %s could not be found.")) % arg1).str();
else {
kickClient = num;
- c.msg = (boost::format(_("Are you sure you want to kick %s?")) % arg1).str() + "<br>";
- c.msg += (boost::format(_("The stated reason was: %s")) % kickReason).str() + "<br>";
+ c.msg =
+ (boost::format(_("Are you sure you want to kick %s?")) % arg1).str() + "<br>";
+ c.msg +=
+ (boost::format(_("The stated reason was: %s")) % kickReason).str() + "<br>";
c.msg += (boost::format(_("If yes, type: /ack_kick %s")) % arg1).str();
}
}
- if (!h->is_dedicated())
- c.recipient = h->get_local_playername();
}
// Acknowledge kick
@@ -455,18 +439,14 @@
} else
c.msg = _("kick acknowledgement cancelled: Wrong name given!");
}
- kickUser = "";
+ kickUser = "";
kickReason = "";
- if (!h->is_dedicated())
- c.recipient = h->get_local_playername();
}
// Force Pause
else if (cmd == "forcePause") {
if (h->forced_pause()) {
c.msg = _("Pause was already forced - game should be paused.");
- if (!h->is_dedicated())
- c.recipient = h->get_local_playername();
} else {
c.msg = "HOST FORCED THE GAME TO PAUSE!";
h->force_pause();
@@ -477,8 +457,6 @@
else if (cmd == "endForcedPause") {
if (!h->forced_pause()) {
c.msg = _("There is no forced pause - nothing to end.");
- if (!h->is_dedicated())
- c.recipient = h->get_local_playername();
} else {
c.msg = "HOST ENDED THE FORCED GAME PAUSE!";
h->end_forced_pause();
@@ -488,8 +466,6 @@
// Default
else {
c.msg = _("Invalid command! Type /help for a list of commands.");
- if (!h->is_dedicated())
- c.recipient = h->get_local_playername();
}
}
h->send(c);
@@ -522,7 +498,6 @@
bool syncreport_arrived;
int32_t time; // last time report
uint32_t desiredspeed;
- bool dedicated_access;
time_t hung_since;
/// The delta time where the last information about the hung client was sent to the other clients relative
/// to when the last answer of the client was received.
@@ -545,9 +520,6 @@
/// order as players. In fact, a client must not be assigned to a player.
std::vector<Client> clients;
- /// Set to true, once the dedicated server should start
- bool dedicated_start;
-
/// The game itself; only non-null while game is running
Widelands::Game * game;
@@ -603,7 +575,6 @@
syncreport_time(0),
syncreport_arrived(false)
{
- dedicated_start = false;
}
};
@@ -611,12 +582,9 @@
:
d(new NetHostImpl(this)),
m_internet(internet),
- m_is_dedicated(false),
- m_password(""),
- m_dedicated_motd(""),
m_forced_pause(false)
{
- dedicatedlog("[Host]: starting up.\n");
+ log("[Host]: starting up.\n");
if (internet) {
InternetGaming::ref().open_game();
@@ -711,79 +679,18 @@
}
}
-void NetHost::run(bool const autorun)
+void NetHost::run()
{
- m_is_dedicated = autorun;
// Fill the list of possible system messages
NetworkGamingMessages::fill_map();
- if (m_is_dedicated) {
- // Initializing
- d->hp.next_win_condition();
- // May be the server is password protected?
- Section & s = g_options.pull_section("global");
- m_password = s.get_string("dedicated_password", "");
-
- // And we read the message of the day
- const std::string dedicated_motd_key =
- (boost::format
- (_("This is a dedicated server. Send \"@%s help\" to get a full list of available commands."))
- % d->localplayername).str();
- m_dedicated_motd = s.get_string("dedicated_motd", dedicated_motd_key.c_str());
-
- // Maybe this is the first run, so we try to setup the DedicatedLog
- // empty strings are treated as "do not write this type of log"
- DedicatedLog * dl = DedicatedLog::get();
- bool needip = false;
- if (!dl->set_log_file_path (s.get_string("dedicated_log_file_path", "")))
- dedicatedlog("Warning: Could not set dedicated log file path");
- if (!dl->set_chat_file_path(s.get_string("dedicated_chat_file_path", "")))
- dedicatedlog("Warning: Could not set dedicated chat file path");
- if (!dl->write_info_active()) {
- if (!dl->set_info_file_path(s.get_string("dedicated_info_file_path", "")))
- dedicatedlog("Warning: Could not set dedicated info file path");
- else {
- needip = true;
- dl->set_server_data(InternetGaming::ref().get_local_servername(), m_dedicated_motd);
- }
- }
-
- dl->chat_add_spacer();
- // Setup by the users
- log ("[Dedicated] Entering set up mode, waiting for user interaction!\n");
-
- while (!d->dedicated_start) {
- handle_network();
- // TODO(unknown): this should be improved.
-#ifndef _WIN32
- if (d->clients.empty()) {
- if (usleep(100000)) // Sleep for 0.1 seconds - there is not anybody connected anyways.
- return;
- if (needip && (InternetGaming::ref().ip().size() < 1)) {
- dl->set_server_ip(InternetGaming::ref().ip());
- needip = false;
- }
- } else {
- if (usleep(200) == -1)
- return;
- }
-#else
- if (d->clients.empty())
- Sleep(100);
- else
- Sleep(1);
-#endif
- }
- d->dedicated_start = false;
- } else {
- FullscreenMenuLaunchMPG lm(&d->hp, this);
- lm.set_chat_provider(d->chat);
- const FullscreenMenuBase::MenuTarget code = lm.run<FullscreenMenuBase::MenuTarget>();
- if (code == FullscreenMenuBase::MenuTarget::kBack) {
- // if this is an internet game, tell the metaserver that client is back in the lobby.
- if (m_internet)
- InternetGaming::ref().set_game_done();
- return;
- }
+ FullscreenMenuLaunchMPG lm(&d->hp, this);
+ lm.set_chat_provider(d->chat);
+ const FullscreenMenuBase::MenuTarget code = lm.run<FullscreenMenuBase::MenuTarget>();
+ if (code == FullscreenMenuBase::MenuTarget::kBack) {
+ // if this is an internet game, tell the metaserver that client is back in the lobby.
+ if (m_internet)
+ InternetGaming::ref().set_game_done();
+ return;
}
// if this is an internet game, tell the metaserver that the game started
@@ -805,61 +712,40 @@
#endif
try {
- // NOTE loaderUI will stay uninitialized, if this is run as dedicated, so all called functions need
- // NOTE to check whether the pointer is valid.
std::unique_ptr<UI::ProgressWindow> loaderUI;
GameTips * tips = nullptr;
- if (m_is_dedicated) {
- log ("[Dedicated] Starting the game...\n");
- d->game = &game;
- game.set_game_controller(this);
-
- if (d->settings.savegame) {
- // Read and broadcast original win condition
- Widelands::GameLoader gl(d->settings.mapfilename, game);
- Widelands::GamePreloadPacket gpdp;
- gl.preload_game(gpdp);
-
- set_win_condition_script(gpdp.get_win_condition());
- }
- } else {
- loaderUI.reset(new UI::ProgressWindow ("images/loadscreens/progress.png"));
- std::vector<std::string> tipstext;
- tipstext.push_back("general_game");
- tipstext.push_back("multiplayer");
- try {
- tipstext.push_back(d->hp.get_players_tribe());
- } catch (GameSettingsProvider::NoTribe) {}
- tips = new GameTips(*loaderUI, tipstext);
-
- loaderUI->step(_("Preparing game"));
-
- d->game = &game;
- game.set_game_controller(this);
- InteractiveGameBase * igb;
- uint8_t pn = d->settings.playernum + 1;
-
- if (d->settings.savegame) {
- // Read and broadcast original win condition
- Widelands::GameLoader gl(d->settings.mapfilename, game);
- Widelands::GamePreloadPacket gpdp;
- gl.preload_game(gpdp);
-
- set_win_condition_script(gpdp.get_win_condition());
- }
-
- if ((pn > 0) && (pn <= UserSettings::highest_playernum())) {
- igb =
- new InteractivePlayer
- (game, g_options.pull_section("global"),
- pn, true);
- } else
- igb =
- new InteractiveSpectator
- (game, g_options.pull_section("global"), true);
- igb->set_chat_provider(d->chat);
- game.set_ibase(igb);
- }
+ loaderUI.reset(new UI::ProgressWindow("images/loadscreens/progress.png"));
+ std::vector<std::string> tipstext;
+ tipstext.push_back("general_game");
+ tipstext.push_back("multiplayer");
+ try {
+ tipstext.push_back(d->hp.get_players_tribe());
+ } catch (GameSettingsProvider::NoTribe) {
+ }
+ tips = new GameTips(*loaderUI, tipstext);
+
+ loaderUI->step(_("Preparing game"));
+
+ d->game = &game;
+ game.set_game_controller(this);
+ InteractiveGameBase* igb;
+ uint8_t pn = d->settings.playernum + 1;
+
+ if (d->settings.savegame) {
+ // Read and broadcast original win condition
+ Widelands::GameLoader gl(d->settings.mapfilename, game);
+ Widelands::GamePreloadPacket gpdp;
+ gl.preload_game(gpdp);
+
+ set_win_condition_script(gpdp.get_win_condition());
+ }
+
+ if ((pn > 0) && (pn <= UserSettings::highest_playernum())) {
+ igb = new InteractivePlayer(game, g_options.pull_section("global"), pn, true);
+ } else
+ igb = new InteractiveSpectator(game, g_options.pull_section("global"), true);
+ igb->set_chat_provider(d->chat);
+ game.set_ibase(igb);
if (!d->settings.savegame) // new game
game.init_newgame (loaderUI.get(), d->settings);
@@ -879,39 +765,18 @@
// wait mode when there are no clients
check_hung_clients();
init_computer_players();
- if (m_is_dedicated) {
- // Statistics: new game started
- std::vector<std::string> clients;
- for (uint32_t i = 0; i < d->settings.users.size(); ++i)
- if (d->settings.users.at(i).position != UserSettings::not_connected())
- if (d->settings.users.at(i).name != d->localplayername) // all names, but the dedicated server
- clients.push_back(d->settings.users.at(i).name);
- DedicatedLog::get()->game_start(clients, game.map().get_name().c_str());
- }
game.run
(loaderUI.get(),
d->settings.savegame ? Widelands::Game::Loaded : d->settings.scenario ?
Widelands::Game::NewMPScenario : Widelands::Game::NewNonScenario,
"",
- false);
+ false, "nethost");
delete tips;
// if this is an internet game, tell the metaserver that the game is done.
if (m_internet)
InternetGaming::ref().set_game_done();
-
- if (m_is_dedicated) {
- // Statistics: game ended
- std::vector<std::string> winners;
- for (uint32_t i = 0; i < d->settings.users.size(); ++i)
- // We do *not* only check connected users but all, as normally the players are already
- // disconnected once the server reaches this line of code.
- if (d->settings.users.at(i).name != d->localplayername) // all names, but the dedicated server
- if (d->settings.users.at(i).result == Widelands::PlayerEndResult::PLAYER_WON)
- winners.push_back(d->settings.users.at(i).name);
- DedicatedLog::get()->game_end(winners);
- }
clear_computer_players();
} catch (...) {
WLApplication::emergency_save(game);
@@ -963,11 +828,6 @@
for (uint32_t i = 0; i < d->computerplayers.size(); ++i)
d->computerplayers.at(i)->think();
- } else if (m_is_dedicated) {
- // Take care that every player gets updated during set up time
- for (uint8_t i = 0; i < d->settings.players.size(); ++i) {
- d->npsb.refresh(i);
- }
}
}
@@ -997,9 +857,6 @@
if (msg.msg.empty())
return;
- if (is_dedicated())
- DedicatedLog::get()->chat(msg);
-
if (msg.recipient.empty()) {
SendPacket s;
s.unsigned_8(NETCMD_CHAT);
@@ -1016,9 +873,6 @@
// Is this a pm for the host player?
if (d->localplayername == msg.recipient) {
- // If this is a dedicated server, handle commands
- if (m_is_dedicated)
- handle_dserver_command(msg.msg, msg.sender);
d->chat.receive(msg);
// Write the SendPacket - will be used below to show that the message
// was received.
@@ -1036,7 +890,7 @@
s.unsigned_8(1);
s.string(msg.recipient);
s.send(d->clients.at(clientnum).sock);
- dedicatedlog("[Host]: personal chat: from %s to %s\n", msg.sender.c_str(), msg.recipient.c_str());
+ log("[Host]: personal chat: from %s to %s\n", msg.sender.c_str(), msg.recipient.c_str());
} else {
std::string fail = "Failed to send message: Recipient \"";
fail += msg.recipient + "\" could not be found!";
@@ -1068,8 +922,6 @@
else if (d->localplayername == msg.sender)
d->chat.receive(msg);
else { // host is not the sender -> get sender
- if (d->localplayername == msg.recipient && m_is_dedicated)
- return; // There will be an immediate answer from the host
uint16_t i = 0;
for (; i < d->settings.users.size(); ++i) {
const UserSettings & user = d->settings.users.at(i);
@@ -1085,10 +937,10 @@
s.send(d->clients.at(j).sock);
else
// Better no wexception it would break the whole game
- dedicatedlog("WARNING: user was found but no client is connected to it!\n");
+ log("WARNING: user was found but no client is connected to it!\n");
} else
// Better no wexception it would break the whole game
- dedicatedlog("WARNING: sender could not be found!");
+ log("WARNING: sender could not be found!");
}
}
}
@@ -1164,217 +1016,6 @@
arg2 = "";
}
-
-/**
- * This function is used to handle commands for the dedicated server
- */
-void NetHost::handle_dserver_command(std::string cmdarray, std::string sender)
-{
- assert(m_is_dedicated);
-
- ChatMessage c;
- c.time = time(nullptr);
- c.playern = -2;
- c.sender = d->localplayername;
- c.recipient = sender;
-
- // Find the client that send the chat message
- int32_t num = check_client(sender);
- if (num < 0) // host or not found
- return;
- Client & client = d->clients[num];
-
- if (cmdarray.size() < 1) {
- return;
- }
-
- // Split up in "cmd" "arg1" "arg2"
- std::string cmd, arg1, arg2;
- split_command_array(cmdarray, cmd, arg1, arg2);
-
- // help
- if (cmd == "help") {
- if (d->game)
- c.msg =
- (boost::format("<br>%s<br>%s<br>%s<br>%s")
- % _("Available host commands are:")
- /** TRANSLATORS: Available host command */
- % _("/help - Shows this help")
- /** TRANSLATORS: Available host command */
- % _("host $ - Tries to run the host command $")
- /** TRANSLATORS: Available host command */
- % _("save $ - Saves the current game state as $.wgf")
- ).str();
- else
- c.msg =
- (boost::format("<br>%s<br>%s<br>%s")
- % _("Available host commands are:")
- /** TRANSLATORS: Available host command */
- % _("/help - Shows this help")
- /** TRANSLATORS: Available host command */
- % _("host $ - Tries to run the host command $")
- ).str();
- if (m_password.size() > 1) {
- c.msg += "<br>";
- c.msg += _("pwd $ - Sends the password $ to the host");
- }
- send(c);
-
- // host
- } else if (cmd == "host") {
- if (!client.dedicated_access) {
- c.msg = _("Access to host commands denied. To gain access, send the password with pwd command.");
- send(c);
- return;
- }
- std::string temp = arg1 + " " + arg2;
- c.msg = (boost::format(_("%1$s told me to run the command: \"%2$s\"")) % sender % temp).str();
- c.recipient = "";
- send(c);
- d->chat.send(temp);
-
- } else if (cmd == "save") {
- // Check whether saving is allowed at all
- Section & s = g_options.pull_section("global");
- if (!s.get_bool("dedicated_saving", true)) {
- c.msg = _("Sorry! Saving was deactivated on this dedicated server!");
- send(c);
- } else if (!d->game) {
- c.msg = _("Cannot save while there is no game running!");
- send(c);
- } else {
- //try to save the game
- std::string savename = "save/" + arg1;
- if (!arg2.empty()) { // only add space and arg2, if arg2 has anything to print.
- savename += " " + arg2;
- }
- savename += ".wgf";
- std::string * error = new std::string();
- SaveHandler & sh = d->game->save_handler();
- if (sh.save_game(*d->game, savename, error))
- c.msg = _("Game successfully saved!");
- else
- c.msg =
- (boost::format(_("Could not save the game to the file \"%1$s\"! (%2$s)"))
- % savename % error)
- .str();
- send(c);
- delete error;
- }
-
- } else if (cmd == "pwd") {
- if (m_password.empty()) {
- c.msg = _("This server is not password protected!");
- send(c);
- } else if (arg1 != m_password) {
- c.msg = _("The sent password was incorrect!");
- send(c);
- } else {
- // Once the client gained access (s)he might need the knowledge about available maps and saved games
- dserver_send_maps_and_saves(client);
-
- // Send the client the access granted message
- SendPacket s;
- s.reset();
- s.unsigned_8(NETCMD_DEDICATED_ACCESS);
- s.send(client.sock);
- client.dedicated_access = true;
-
- c.msg = _("The password was correct, access was granted!");
- send(c);
- }
-
- // default
- } else {
- c.msg = (boost::format(_("Unknown dedicated server command \"%s\"!")) % cmd).str();
- send(c);
- }
-}
-
-void NetHost::dserver_send_maps_and_saves(Client & client) {
- assert (!d->game);
-
- if (d->settings.maps.empty()) {
- // Read in maps
- std::vector<std::string> directories;
- directories.push_back("maps");
- while (!directories.empty()) {
- FilenameSet files = g_fs->list_directory(directories.at(directories.size() - 1).c_str());
- directories.resize(directories.size() - 1);
- Widelands::Map map;
- for (const std::string& filename : files) {
- std::unique_ptr<Widelands::MapLoader> ml = map.get_correct_loader(filename);
- if (ml) {
- map.set_filename(filename);
- ml->preload_map(true);
- DedicatedMapInfos info;
- info.path = filename;
- info.players = map.get_nrplayers();
- info.scenario = map.scenario_types() & Widelands::Map::MP_SCENARIO;
- d->settings.maps.push_back(info);
- } else {
- if
- (g_fs->is_directory(filename)
- &&
- strcmp(FileSystem::fs_filename(filename.c_str()), ".")
- &&
- strcmp(FileSystem::fs_filename(filename.c_str()), ".."))
- {
- directories.push_back(filename);
- }
- }
- }
- }
- }
-
- if (d->settings.saved_games.empty()) {
- // Read in saved games
- FilenameSet files = g_fs->list_directory("save");
- Widelands::Game game;
- Widelands::GamePreloadPacket gpdp;
- const FilenameSet & gamefiles = files;
- for (const std::string& temp_filenames : gamefiles) {
- char const * const name = temp_filenames.c_str();
- try {
- Widelands::GameLoader gl(name, game);
- gl.preload_game(gpdp);
-
- // If we are here, the saved game is valid
- std::unique_ptr<FileSystem> sg_fs(g_fs->make_sub_file_system(name));
- Profile prof;
- prof.read("map/elemental", nullptr, *sg_fs);
- Section & s = prof.get_safe_section("global");
-
- DedicatedMapInfos info;
- info.path = name;
- info.players = static_cast<uint8_t>(s.get_safe_int("nr_players"));
- d->settings.saved_games.push_back(info);
- } catch (const WException &) {}
- }
- }
-
- SendPacket s;
-
- // Send list of maps
- for (uint8_t i = 0; i < d->settings.maps.size(); ++i) {
- s.reset();
- s.unsigned_8(NETCMD_DEDICATED_MAPS);
- s.string (d->settings.maps[i].path);
- s.unsigned_8(d->settings.maps[i].players);
- s.unsigned_8(d->settings.maps[i].scenario ? 1 : 0);
- s.send(client.sock);
- }
-
- // Send list of saved games
- for (uint8_t i = 0; i < d->settings.saved_games.size(); ++i) {
- s.reset();
- s.unsigned_8(NETCMD_DEDICATED_SAVED_GAMES);
- s.string (d->settings.saved_games[i].path);
- s.unsigned_8(d->settings.saved_games[i].players);
- s.send(client.sock);
- }
-}
-
void NetHost::send_system_message_code
(const std::string & code, const std::string & a, const std::string & b, const std::string & c)
{
@@ -1394,8 +1035,6 @@
msg.playern = UserSettings::none(); // == System message
// c.sender remains empty to indicate a system message
d->chat.receive(msg);
- if (m_is_dedicated)
- DedicatedLog::get()->chat(msg);
}
int32_t NetHost::get_frametime()
@@ -1962,7 +1601,7 @@
bool NetHost::write_map_transfer_info(SendPacket & s, std::string mapfilename) {
// TODO(unknown): not yet able to handle directory type maps / savegames
if (g_fs->is_directory(mapfilename)) {
- dedicatedlog("Map/Save is a directory! No way for making it available a.t.m.!\n");
+ log("Map/Save is a directory! No way for making it available a.t.m.!\n");
return false;
}
@@ -2027,13 +1666,8 @@
assert(client.playernum == UserSettings::not_connected());
assert(client.sock);
- // Just for statistics
- DedicatedLog::get()->client_login();
-
// The client gets its own initial data set.
client.playernum = UserSettings::none();
- // only used at password protected dedicated server, but better initialize always
- client.dedicated_access = m_is_dedicated ? (m_password.empty()) : false;
if (!d->game) // just in case we allow connection of spectators/players after game start
for (uint32_t i = 0; i < d->settings.users.size(); ++i)
@@ -2066,7 +1700,7 @@
d->settings.users.at(client.usernum).name = effective_name;
d->settings.users.at(client.usernum).position = UserSettings::none();
- dedicatedlog("[Host]: Client %u: welcome to usernum %u\n", number, client.usernum);
+ log("[Host]: Client %u: welcome to usernum %u\n", number, client.usernum);
SendPacket s;
s.unsigned_8(NETCMD_HELLO);
@@ -2135,34 +1769,6 @@
}
send_system_message_code("CLIENT_HAS_JOINED_GAME", effective_name);
-
- // If this is a dedicated server, inform the player
- if (m_is_dedicated) {
- ChatMessage c;
- c.time = time(nullptr);
- c.playern = -2;
- c.sender = d->localplayername;
- // Send the message of the day if exists
- c.msg = "<br>" + m_dedicated_motd;
- if (m_password.size() > 1) {
- c.msg += "<br>";
- c.msg +=
- (boost::format
- (_("This server is password protected. You can send the password with: \"@%s pwd PASSWORD\""))
- % d->localplayername)
- .str();
- } else {
- // Once the client gained access it might need the knowledge about available maps and saved games
- dserver_send_maps_and_saves(client);
-
- // If not password protected, give the client access to the settings
- s.reset();
- s.unsigned_8(NETCMD_DEDICATED_ACCESS);
- s.send(client.sock);
- }
- c.recipient = d->settings.users.at(client.usernum).name;
- send(c);
- }
}
void NetHost::committed_network_time(int32_t const time)
@@ -2194,7 +1800,7 @@
}
client.time = time;
- dedicatedlog("[Host]: Client %i: Time %i\n", number, time);
+ log("[Host]: Client %i: Time %i\n", number, time);
if (d->waiting) {
log
@@ -2253,29 +1859,6 @@
d->settings.users.at(d->clients.at(i).usernum).name,
seconds.c_str());
d->clients.at(i).lastdelta = deltanow;
- if (m_is_dedicated) {
- seconds = (boost::format("%li") % (300 - deltanow)).str();
- send_system_message_code
- ("CLIENT_HUNG_AUTOKICK",
- d->settings.users.at(d->clients.at(i).usernum).name,
- seconds.c_str());
- }
- }
-
- // If this is a dedicated server, there is no host that cares about kicking hung players
- // This is especially problematic, if the last or all players hung and the dedicated
- // server does not automatically restart.
- // 5 minutes for all other players to react before the dedicated server takes care
- // about the situation itself
- if ((d->clients.at(i).hung_since < (time(nullptr) - 300)) && m_is_dedicated) {
- disconnect_client(i, "CLIENT_TIMEOUTED");
- // Try to save the game
- std::string savename = (boost::format("save/client_hung_%i.wmf") % time(nullptr)).str();
- std::string * error = new std::string();
- SaveHandler & sh = d->game->save_handler();
- if (sh.save_game(*d->game, savename, error))
- send_system_message_code("GAME_SAVED_AS", savename);
- delete error;
}
}
}
@@ -2284,7 +1867,7 @@
if (!d->waiting) {
if (nrhung) {
- dedicatedlog("[Host]: %i clients hung. Entering wait mode\n", nrhung);
+ log("[Host]: %i clients hung. Entering wait mode\n", nrhung);
// Brake and wait
d->waiting = true;
@@ -2347,14 +1930,12 @@
// No pause was forced - normal speed calculation
std::vector<uint32_t> speeds;
- if (!m_is_dedicated)
- speeds.push_back(d->localdesiredspeed);
+ speeds.push_back(d->localdesiredspeed);
for (uint32_t i = 0; i < d->clients.size(); ++i) {
if (d->clients.at(i).playernum <= UserSettings::highest_playernum())
speeds.push_back(d->clients.at(i).desiredspeed);
}
- if (speeds.empty()) // Possible in dedicated server games with only spectators
- return;
+ assert(!speeds.empty());
std::sort(speeds.begin(), speeds.end());
@@ -2395,7 +1976,7 @@
for (uint32_t i = 0; i < d->clients.size(); ++i)
d->clients.at(i).syncreport_arrived = false;
- dedicatedlog("[Host]: Requesting sync reports for time %i\n", d->syncreport_time);
+ log("[Host]: Requesting sync reports for time %i\n", d->syncreport_time);
SendPacket s;
s.unsigned_8(NETCMD_SYNCREQUEST);
@@ -2425,7 +2006,7 @@
}
d->syncreport_pending = false;
- dedicatedlog("[Host]: comparing syncreports for time %i\n", d->syncreport_time);
+ log("[Host]: comparing syncreports for time %i\n", d->syncreport_time);
for (uint32_t i = 0; i < d->clients.size(); ++i) {
Client & client = d->clients.at(i);
@@ -2474,7 +2055,7 @@
// Check for new connections.
while (d->svsock != nullptr && (sock = SDLNet_TCP_Accept(d->svsock)) != nullptr) {
- dedicatedlog("[Host]: Received a connection request\n");
+ log("[Host]: Received a connection request\n");
SDLNet_TCP_AddSocket (d->sockset, sock);
@@ -2571,7 +2152,7 @@
if (client.playernum == UserSettings::not_connected()) {
if (cmd == NETCMD_METASERVER_PING) {
- dedicatedlog("[Host]: Received ping from metaserver.\n");
+ log("[Host]: Received ping from metaserver.\n");
// Send PING back
SendPacket s;
s.unsigned_8(NETCMD_METASERVER_PING);
@@ -2606,56 +2187,12 @@
switch (cmd) {
case NETCMD_PONG:
- dedicatedlog("[Host]: Client %u: got pong\n", i);
+ log("[Host]: Client %u: got pong\n", i);
break;
case NETCMD_SETTING_MAP:
if (!d->game) {
- // Only valid if the server is dedicated and the client was granted access
- if (!client.dedicated_access)
- throw DisconnectException("NO_ACCESS_TO_SERVER");
-
- // We want to skip past the name, so read that but don't do anything with it
- r.string();
- std::string path = g_fs->FileSystem::fix_cross_file(r.string());
- bool savegame = r.unsigned_8() == 1;
- bool scenario = r.unsigned_8() == 1;
- if (savegame) {
- if (g_fs->file_exists(path)) {
- // Check if file is a saved game and if yes read out the needed data
- try {
- Widelands::Game game;
- Widelands::GamePreloadPacket gpdp;
- Widelands::GameLoader gl(path, game);
- gl.preload_game(gpdp);
-
- // If we are here, it is a saved game file :)
- // Read the needed data from file "elemental" of the used map.
- std::unique_ptr<FileSystem> sg_fs(g_fs->make_sub_file_system(path.c_str()));
- Profile prof;
- prof.read("map/elemental", nullptr, *sg_fs);
- Section & s = prof.get_safe_section("global");
- uint8_t nr_players = s.get_safe_int("nr_players");
-
- d->settings.scenario = false;
- d->hp.set_map(gpdp.get_mapname(), path, nr_players, true);
- } catch (const WException &) {}
- }
- } else {
- if (g_fs->file_exists(path)) {
- // Check if file is a map and if yes read out the needed data
- Widelands::Map map;
- i18n::Textdomain td("maps");
- std::unique_ptr<Widelands::MapLoader> ml = map.get_correct_loader(path);
- if (ml != nullptr) {
- // Yes it is a map file :)
- map.set_filename(path);
- ml->preload_map(true);
- d->settings.scenario = scenario;
- d->hp.set_map(map.get_name(), path, map.get_nrplayers(), false);
- }
- }
- }
+ throw DisconnectException("NO_ACCESS_TO_SERVER");
}
break;
@@ -2665,9 +2202,7 @@
if (!d->game) {
uint8_t num = r.unsigned_8();
if (num != client.playernum)
- // Only valid if the server is dedicated and the client was granted access
- if (!client.dedicated_access)
- throw DisconnectException("NO_ACCESS_TO_PLAYER");
+ throw DisconnectException("NO_ACCESS_TO_PLAYER");
std::string tribe = r.string();
bool random_tribe = r.unsigned_8() == 1;
set_player_tribe(num, tribe, random_tribe);
@@ -2680,9 +2215,7 @@
if (!d->game) {
uint8_t num = r.unsigned_8();
if (num != client.playernum)
- // Only valid if the server is dedicated and the client was granted access
- if (!client.dedicated_access)
- throw DisconnectException("NO_ACCESS_TO_PLAYER");
+ throw DisconnectException("NO_ACCESS_TO_PLAYER");
set_player_shared(num, r.unsigned_8());
}
break;
@@ -2691,9 +2224,7 @@
if (!d->game) {
uint8_t num = r.unsigned_8();
if (num != client.playernum)
- // Only valid if the server is dedicated and the client was granted access
- if (!client.dedicated_access)
- throw DisconnectException("NO_ACCESS_TO_PLAYER");
+ throw DisconnectException("NO_ACCESS_TO_PLAYER");
set_player_team(num, r.unsigned_8());
}
break;
@@ -2702,9 +2233,7 @@
if (!d->game) {
uint8_t num = r.unsigned_8();
if (num != client.playernum)
- // Only valid if the server is dedicated and the client was granted access
- if (!client.dedicated_access)
- throw DisconnectException("NO_ACCESS_TO_PLAYER");
+ throw DisconnectException("NO_ACCESS_TO_PLAYER");
d->npsb.toggle_init(num);
}
break;
@@ -2718,30 +2247,19 @@
case NETCMD_SETTING_PLAYER:
if (!d->game) {
- // Only valid if the server is dedicated and the client was granted access
- if (!client.dedicated_access)
- throw DisconnectException("NO_ACCESS_TO_SERVER");
- d->hp.next_player_state(r.unsigned_8());
+ throw DisconnectException("NO_ACCESS_TO_SERVER");
}
break;
case NETCMD_WIN_CONDITION:
if (!d->game) {
- // Only valid if the server is dedicated and the client was granted access
- if (!client.dedicated_access)
- throw DisconnectException("NO_ACCESS_TO_SERVER");
- d->hp.next_win_condition();
+ throw DisconnectException("NO_ACCESS_TO_SERVER");
}
break;
case NETCMD_LAUNCH:
if (!d->game) {
- // Only valid if the server is dedicated and the client was granted access
- if (!client.dedicated_access)
- throw DisconnectException("NO_ACCESS_TO_SERVER");
- if (!can_launch())
- throw DisconnectException("START_SENT_NOT_READY");
- d->dedicated_start = true;
+ throw DisconnectException("NO_ACCESS_TO_SERVER");
}
break;
@@ -2822,7 +2340,7 @@
uint32_t part = r.unsigned_32();
std::string x = r.string();
if (x != file->md5sum) {
- dedicatedlog("[Host]: File transfer checksum missmatch %s != %s\n", x.c_str(), file->md5sum.c_str());
+ log("[Host]: File transfer checksum missmatch %s != %s\n", x.c_str(), file->md5sum.c_str());
return; // Surely the file was changed, so we cancel here.
}
if (part >= file->parts.size())
@@ -2871,7 +2389,7 @@
void NetHost::disconnect_player_controller(uint8_t const number, const std::string & name)
{
- dedicatedlog("[Host]: disconnect_player_controller(%u, %s)\n", number, name.c_str());
+ log("[Host]: disconnect_player_controller(%u, %s)\n", number, name.c_str());
for (uint32_t i = 0; i < d->settings.users.size(); ++i) {
if (d->settings.users.at(i).position == number) {
@@ -2922,13 +2440,10 @@
s.unsigned_32(client.usernum);
write_setting_user(s, client.usernum);
broadcast(s);
-
- // Just for statistics
- DedicatedLog::get()->client_logout();
} else
send_system_message_code("UNKNOWN_LEFT_GAME", reason, arg);
- dedicatedlog("[Host]: disconnect_client(%u, %s, %s)\n", number, reason.c_str(), arg.c_str());
+ log("[Host]: disconnect_client(%u, %s, %s)\n", number, reason.c_str(), arg.c_str());
if (client.sock) {
if (sendreason) {
@@ -2948,16 +2463,7 @@
if (d->game) {
check_hung_clients();
- if (m_is_dedicated) {
- // Check whether there is at least one client connected. If not, stop the game.
- for (uint32_t i = 0; i < d->clients.size(); ++i)
- if (d->clients.at(i).playernum != UserSettings::not_connected())
- return;
- d->game->end_dedicated_game();
- dedicatedlog("[Dedicated] Stopping the running game...\n");
- }
}
-
}
/**
@@ -3004,7 +2510,7 @@
}
}
- dedicatedlog
+ log
("NetHost::report_result(%d, %u, %s)\n",
player->player_number(), static_cast<uint8_t>(result), info.c_str());
}
=== modified file 'src/network/nethost.h'
--- src/network/nethost.h 2014-09-30 06:25:04 +0000
+++ src/network/nethost.h 2016-02-06 16:06:14 +0000
@@ -40,7 +40,7 @@
NetHost (const std::string & playername, bool internet = false);
virtual ~NetHost ();
- void run(bool autostart = false);
+ void run();
const std::string & get_local_playername() const;
int16_t get_local_playerposition();
@@ -90,8 +90,6 @@
void kick_user(uint32_t, std::string);
void split_command_array
(const std::string & cmdarray, std::string & cmd, std::string & arg1, std::string & arg2);
- void handle_dserver_command(std::string, std::string);
- void dserver_send_maps_and_saves(Client &);
void report_result(uint8_t player, Widelands::PlayerEndResult result, const std::string & info) override;
@@ -107,8 +105,6 @@
bool forced_pause() {return m_forced_pause;}
- bool is_dedicated() {return m_is_dedicated;}
-
private:
NetTransferFile * file;
@@ -159,9 +155,6 @@
NetHostImpl * d;
bool m_internet;
- bool m_is_dedicated;
- std::string m_password;
- std::string m_dedicated_motd;
bool m_forced_pause;
};
=== modified file 'src/network/network_protocol.h'
--- src/network/network_protocol.h 2014-09-20 09:37:47 +0000
+++ src/network/network_protocol.h 2016-02-06 16:06:14 +0000
@@ -153,7 +153,6 @@
/**
* During game setup, this command is sent by the host to advise clients of a map change.
- * Or by a client on a dedicated server to advise a map change.
*
* Payload is:
* \li string: human readable mapname
@@ -183,8 +182,6 @@
* During game setup, this command updates the information associated to
* one player slot.
*
- * The client sends this command to toggle the player type. This is only available if the server is
- * dedicated and the client was granted access.
* Payload in that case is:
* \li unsigned_8: number of the player
*
@@ -216,7 +213,6 @@
/**
* Sent by the host during game setup to indicate that the game starts.
- * Alternatively sent by the client to start a dedicated server.
*
* The client must load the map and setup the game. As soon as the game
* is fully loaded, it must behave as if a \ref NETCMD_WAIT command had
@@ -369,10 +365,9 @@
NETCMD_FILE_PART = 24,
/**
- * Sent by the host (or by the client if access was granted to dedicated server)
- * to change the win condition.
+ * Sent by the host to change the win condition.
*
- * If sent by the host, attached data is:
+ * Attached data is:
* \li string: name of the win condition
*
* If sent by the client, no data is attached, as it is only a request to toggle
@@ -420,34 +415,11 @@
*/
NETCMD_SETTING_CHANGEINIT = 28,
- /**
- * This is sent by the server to grant access to the settings (as well as to acknowledge the correct
- * password if the server is password protected)
- */
- NETCMD_DEDICATED_ACCESS = 29,
-
- /**
- * This is sent by the dedicated server to inform the client about the available maps on the dedicated
- * server. Payload is:
- *
- * \li string: Path to the map file
- * \li unsigned_8: Number of maximum players
- * \li bool: Whether this map can be played as multiplayer scenario
- */
- NETCMD_DEDICATED_MAPS = 30,
-
- /**
- * This is sent by the dedicated server to inform the client about the available saved games on the
- * dedicated server. Payload is:
- *
- * \li string: Path to the map file
- * \li unsigned_8: Number of maximum players
- */
- NETCMD_DEDICATED_SAVED_GAMES = 31,
-
- /**
- * This is sent by the dedicated server to generate a clientsided translated system chat message.
- * Payload is:
+ // 29 - 31 were commands related to dedicated server. Do not use.
+
+ /**
+ * This is sent by the server to generate a clientsided translated system
+ * chat message. Payload is:
*
* \li string: Message code \see NetworkGamingMessages::fill_map()
* \li string: First attached string
=== modified file 'src/sound/sound_handler.h'
--- src/sound/sound_handler.h 2015-10-18 15:41:10 +0000
+++ src/sound/sound_handler.h 2016-02-06 16:06:14 +0000
@@ -229,7 +229,6 @@
Widelands::EditorGameBase * egbase_;
/** Only for buffering the command line option --nosound until real initialization is done.
- * And disabling sound on dedicated servers
* \see SoundHandler::SoundHandler()
* \see SoundHandler::init()
*/
=== modified file 'src/ui_fsmenu/launch_mpg.cc'
--- src/ui_fsmenu/launch_mpg.cc 2016-02-04 09:10:44 +0000
+++ src/ui_fsmenu/launch_mpg.cc 2016-02-06 16:06:14 +0000
@@ -433,16 +433,6 @@
UI::WLMessageBox::MBoxType::kOk);
warning.run<UI::Panel::Returncodes>();
}
- } else {
- if (!settings_ || settings_->settings().saved_games.empty())
- throw wexception("A file was selected, that is not available to the client");
- // this file is obviously a file from the dedicated server's saved games pool not available locally.
- for (uint32_t i = 0; i < settings_->settings().saved_games.size(); ++i)
- if (settings_->settings().saved_games.at(i).path == filename) {
- settings_->set_map(filename, filename, settings_->settings().saved_games.at(i).players, true);
- return;
- }
- throw wexception("The selected file could not be found in the pool of dedicated saved games.");
}
}
=== modified file 'src/ui_fsmenu/loadgame.cc'
--- src/ui_fsmenu/loadgame.cc 2016-02-04 09:10:44 +0000
+++ src/ui_fsmenu/loadgame.cc 2016-02-06 16:06:14 +0000
@@ -435,188 +435,173 @@
games_data_.clear();
table_.clear();
-
- if (settings_ && !settings_->settings().saved_games.empty()) {
+ FilenameSet gamefiles;
+
+ if (is_replay_) {
+ gamefiles = filter(g_fs->list_directory(REPLAY_DIR),
+ [](const std::string& fn) {return boost::ends_with(fn, REPLAY_SUFFIX);});
+ } else {
+ gamefiles = g_fs->list_directory("save");
+ }
+
+ Widelands::GamePreloadPacket gpdp;
+
+ for (const std::string& gamefilename : gamefiles) {
+ if (gamefilename == "save/campvis" || gamefilename == "save\\campvis") {
+ continue;
+ }
+
SavegameData gamedata;
- for (uint32_t i = 0; i < settings_->settings().saved_games.size(); ++i) {
- gamedata.filename = settings_->settings().saved_games.at(i).path;
- games_data_.push_back(gamedata);
-
- UI::Table<uintptr_t const>::EntryRecord & te =
- table_.add(games_data_.size() - 1);
- te.set_string(0, FileSystem::filename_without_ext(gamedata.filename.c_str()).c_str());
- }
- } else { // Normal case
- // Fill it with all files we find.
-
- FilenameSet gamefiles;
-
- if (is_replay_) {
- gamefiles = filter(g_fs->list_directory(REPLAY_DIR),
- [](const std::string& fn) {return boost::ends_with(fn, REPLAY_SUFFIX);});
- } else {
- gamefiles = g_fs->list_directory("save");
- }
-
- Widelands::GamePreloadPacket gpdp;
-
- for (const std::string& gamefilename : gamefiles) {
- if (gamefilename == "save/campvis" || gamefilename == "save\\campvis") {
- continue;
- }
-
- SavegameData gamedata;
-
- std::string savename = gamefilename;
- if (is_replay_) savename += WLGF_SUFFIX;
-
- if (!g_fs->file_exists(savename.c_str())) {
- continue;
- }
-
- gamedata.filename = gamefilename;
-
- try {
- Widelands::GameLoader gl(savename.c_str(), game_);
- gl.preload_game(gpdp);
-
- gamedata.gametype = gpdp.get_gametype();
-
- if (!is_replay_) {
- if (settings_->settings().multiplayer) {
- if (gamedata.gametype == GameController::GameType::SINGLEPLAYER) {
- continue;
- }
- } else if (gamedata.gametype > GameController::GameType::SINGLEPLAYER) {
+
+ std::string savename = gamefilename;
+ if (is_replay_) savename += WLGF_SUFFIX;
+
+ if (!g_fs->file_exists(savename.c_str())) {
+ continue;
+ }
+
+ gamedata.filename = gamefilename;
+
+ try {
+ Widelands::GameLoader gl(savename.c_str(), game_);
+ gl.preload_game(gpdp);
+
+ gamedata.gametype = gpdp.get_gametype();
+
+ if (!is_replay_) {
+ if (settings_->settings().multiplayer) {
+ if (gamedata.gametype == GameController::GameType::SINGLEPLAYER) {
continue;
}
- }
-
- gamedata.mapname = gpdp.get_mapname();
- gamedata.gametime = gpdp.get_gametime();
- gamedata.nrplayers = gpdp.get_number_of_players();
- gamedata.version = gpdp.get_version();
-
- gamedata.savetimestamp = gpdp.get_savetimestamp();
- time_t t;
- time(&t);
- struct tm * currenttime = localtime(&t);
- // We need to put these into variables because of a sideeffect of the localtime function.
- int8_t current_year = currenttime->tm_year;
- int8_t current_month = currenttime->tm_mon;
- int8_t current_day = currenttime->tm_mday;
-
- struct tm * savedate = localtime(&gamedata.savetimestamp);
-
- if (gamedata.savetimestamp > 0) {
- if (savedate->tm_year == current_year &&
- savedate->tm_mon == current_month &&
- savedate->tm_mday == current_day) { // Today
-
- // Adding the 0 padding in a separate statement so translators won't have to deal with it
- const std::string minute = (boost::format("%02u") % savedate->tm_min).str();
-
- /** TRANSLATORS: Display date for choosing a savegame/replay */
- /** TRANSLATORS: hour:minute */
- gamedata.savedatestring = (boost::format(_("Today, %1%:%2%"))
- % savedate->tm_hour % minute).str();
- } else if ((savedate->tm_year == current_year &&
- savedate->tm_mon == current_month &&
- savedate->tm_mday == current_day - 1) ||
- (savedate->tm_year == current_year - 1 &&
- savedate->tm_mon == 11 && current_month == 0 &&
- savedate->tm_mday == 31 && current_day == 1)) { // Yesterday
- // Adding the 0 padding in a separate statement so translators won't have to deal with it
- const std::string minute = (boost::format("%02u") % savedate->tm_min).str();
-
- /** TRANSLATORS: Display date for choosing a savegame/replay */
- /** TRANSLATORS: hour:minute */
- gamedata.savedatestring = (boost::format(_("Yesterday, %1%:%2%"))
- % savedate->tm_hour % minute).str();
- } else { // Older
-
- /** TRANSLATORS: Display date for choosing a savegame/replay */
- /** TRANSLATORS: month day, year */
- gamedata.savedatestring = (boost::format(_("%2% %1%, %3%"))
- % savedate->tm_mday
- % localize_month(savedate->tm_mon)
- % (1900 + savedate->tm_year)).str();
- }
- }
-
- {
- i18n::Textdomain td("win_conditions");
- gamedata.wincondition = _(gpdp.get_win_condition());
- }
- gamedata.minimap_path = gpdp.get_minimap_path();
- games_data_.push_back(gamedata);
-
- UI::Table<uintptr_t const>::EntryRecord & te =
- table_.add(games_data_.size() - 1);
- te.set_string(0, gamedata.savedatestring);
-
- if (is_replay_ || settings_->settings().multiplayer) {
- std::string gametypestring;
- switch (gamedata.gametype) {
- case GameController::GameType::SINGLEPLAYER:
- /** TRANSLATORS: "Single Player" entry in the Game Mode table column. */
- /** TRANSLATORS: "Keep this to 6 letters maximum. */
- /** TRANSLATORS: A tooltip will explain the abbreviation. */
- /** TRANSLATORS: Make sure that this translation is consistent with the tooltip. */
- gametypestring = _("SP");
- break;
- case GameController::GameType::NETHOST:
- /** TRANSLATORS: "Multiplayer Host" entry in the Game Mode table column. */
- /** TRANSLATORS: "Keep this to 2 letters maximum. */
- /** TRANSLATORS: A tooltip will explain the abbreviation. */
- /** TRANSLATORS: Make sure that this translation is consistent with the tooltip. */
- /** TRANSLATORS: %1% is the number of players */
- gametypestring = (boost::format(_("H (%1%)"))
- % static_cast<unsigned int>(gamedata.nrplayers)).str();
- break;
- case GameController::GameType::NETCLIENT:
- /** TRANSLATORS: "Multiplayer" entry in the Game Mode table column. */
- /** TRANSLATORS: "Keep this to 2 letters maximum. */
- /** TRANSLATORS: A tooltip will explain the abbreviation. */
- /** TRANSLATORS: Make sure that this translation is consistent with the tooltip. */
- /** TRANSLATORS: %1% is the number of players */
- gametypestring = (boost::format(_("MP (%1%)"))
- % static_cast<unsigned int>(gamedata.nrplayers)).str();
- break;
- case GameController::GameType::REPLAY:
- gametypestring = "";
- break;
- }
- te.set_string(1, gametypestring);
- te.set_string(2, map_filename(gamedata.filename, gamedata.mapname));
- } else {
- te.set_string(1, map_filename(gamedata.filename, gamedata.mapname));
- }
- } catch (const WException & e) {
- // we simply skip illegal entries
- gamedata.errormessage =
- ((boost::format("%s\n\n%s\n\n%s"))
- /** TRANSLATORS: Error message introduction for when an old savegame can't be loaded */
- % _("This file has the wrong format and can’t be loaded."
- " Maybe it was created with an older version of Widelands.")
- /** TRANSLATORS: This text is on a separate line with an error message below */
- % _("Error message:")
- % e.what()).str();
-
- const std::string fs_filename = FileSystem::filename_without_ext(gamedata.filename.c_str());
- gamedata.mapname = fs_filename;
- games_data_.push_back(gamedata);
-
- UI::Table<uintptr_t const>::EntryRecord & te =
- table_.add(games_data_.size() - 1);
- te.set_string(0, "");
- if (is_replay_ || settings_->settings().multiplayer) {
- te.set_string(1, "");
- /** TRANSLATORS: Prefix for incompatible files in load game screens */
- te.set_string(2, (boost::format(_("Incompatible: %s")) % fs_filename).str());
- } else {
- te.set_string(1, (boost::format(_("Incompatible: %s")) % fs_filename).str());
- }
+ } else if (gamedata.gametype > GameController::GameType::SINGLEPLAYER) {
+ continue;
+ }
+ }
+
+ gamedata.mapname = gpdp.get_mapname();
+ gamedata.gametime = gpdp.get_gametime();
+ gamedata.nrplayers = gpdp.get_number_of_players();
+ gamedata.version = gpdp.get_version();
+
+ gamedata.savetimestamp = gpdp.get_savetimestamp();
+ time_t t;
+ time(&t);
+ struct tm * currenttime = localtime(&t);
+ // We need to put these into variables because of a sideeffect of the localtime function.
+ int8_t current_year = currenttime->tm_year;
+ int8_t current_month = currenttime->tm_mon;
+ int8_t current_day = currenttime->tm_mday;
+
+ struct tm * savedate = localtime(&gamedata.savetimestamp);
+
+ if (gamedata.savetimestamp > 0) {
+ if (savedate->tm_year == current_year &&
+ savedate->tm_mon == current_month &&
+ savedate->tm_mday == current_day) { // Today
+
+ // Adding the 0 padding in a separate statement so translators won't have to deal with it
+ const std::string minute = (boost::format("%02u") % savedate->tm_min).str();
+
+ /** TRANSLATORS: Display date for choosing a savegame/replay */
+ /** TRANSLATORS: hour:minute */
+ gamedata.savedatestring = (boost::format(_("Today, %1%:%2%"))
+ % savedate->tm_hour % minute).str();
+ } else if ((savedate->tm_year == current_year &&
+ savedate->tm_mon == current_month &&
+ savedate->tm_mday == current_day - 1) ||
+ (savedate->tm_year == current_year - 1 &&
+ savedate->tm_mon == 11 && current_month == 0 &&
+ savedate->tm_mday == 31 && current_day == 1)) { // Yesterday
+ // Adding the 0 padding in a separate statement so translators won't have to deal with it
+ const std::string minute = (boost::format("%02u") % savedate->tm_min).str();
+
+ /** TRANSLATORS: Display date for choosing a savegame/replay */
+ /** TRANSLATORS: hour:minute */
+ gamedata.savedatestring = (boost::format(_("Yesterday, %1%:%2%"))
+ % savedate->tm_hour % minute).str();
+ } else { // Older
+
+ /** TRANSLATORS: Display date for choosing a savegame/replay */
+ /** TRANSLATORS: month day, year */
+ gamedata.savedatestring = (boost::format(_("%2% %1%, %3%"))
+ % savedate->tm_mday
+ % localize_month(savedate->tm_mon)
+ % (1900 + savedate->tm_year)).str();
+ }
+ }
+
+ {
+ i18n::Textdomain td("win_conditions");
+ gamedata.wincondition = _(gpdp.get_win_condition());
+ }
+ gamedata.minimap_path = gpdp.get_minimap_path();
+ games_data_.push_back(gamedata);
+
+ UI::Table<uintptr_t const>::EntryRecord & te =
+ table_.add(games_data_.size() - 1);
+ te.set_string(0, gamedata.savedatestring);
+
+ if (is_replay_ || settings_->settings().multiplayer) {
+ std::string gametypestring;
+ switch (gamedata.gametype) {
+ case GameController::GameType::SINGLEPLAYER:
+ /** TRANSLATORS: "Single Player" entry in the Game Mode table column. */
+ /** TRANSLATORS: "Keep this to 6 letters maximum. */
+ /** TRANSLATORS: A tooltip will explain the abbreviation. */
+ /** TRANSLATORS: Make sure that this translation is consistent with the tooltip. */
+ gametypestring = _("SP");
+ break;
+ case GameController::GameType::NETHOST:
+ /** TRANSLATORS: "Multiplayer Host" entry in the Game Mode table column. */
+ /** TRANSLATORS: "Keep this to 2 letters maximum. */
+ /** TRANSLATORS: A tooltip will explain the abbreviation. */
+ /** TRANSLATORS: Make sure that this translation is consistent with the tooltip. */
+ /** TRANSLATORS: %1% is the number of players */
+ gametypestring = (boost::format(_("H (%1%)"))
+ % static_cast<unsigned int>(gamedata.nrplayers)).str();
+ break;
+ case GameController::GameType::NETCLIENT:
+ /** TRANSLATORS: "Multiplayer" entry in the Game Mode table column. */
+ /** TRANSLATORS: "Keep this to 2 letters maximum. */
+ /** TRANSLATORS: A tooltip will explain the abbreviation. */
+ /** TRANSLATORS: Make sure that this translation is consistent with the tooltip. */
+ /** TRANSLATORS: %1% is the number of players */
+ gametypestring = (boost::format(_("MP (%1%)"))
+ % static_cast<unsigned int>(gamedata.nrplayers)).str();
+ break;
+ case GameController::GameType::REPLAY:
+ gametypestring = "";
+ break;
+ }
+ te.set_string(1, gametypestring);
+ te.set_string(2, map_filename(gamedata.filename, gamedata.mapname));
+ } else {
+ te.set_string(1, map_filename(gamedata.filename, gamedata.mapname));
+ }
+ } catch (const WException & e) {
+ // we simply skip illegal entries
+ gamedata.errormessage =
+ ((boost::format("%s\n\n%s\n\n%s"))
+ /** TRANSLATORS: Error message introduction for when an old savegame can't be loaded */
+ % _("This file has the wrong format and can’t be loaded."
+ " Maybe it was created with an older version of Widelands.")
+ /** TRANSLATORS: This text is on a separate line with an error message below */
+ % _("Error message:")
+ % e.what()).str();
+
+ const std::string fs_filename = FileSystem::filename_without_ext(gamedata.filename.c_str());
+ gamedata.mapname = fs_filename;
+ games_data_.push_back(gamedata);
+
+ UI::Table<uintptr_t const>::EntryRecord & te =
+ table_.add(games_data_.size() - 1);
+ te.set_string(0, "");
+ if (is_replay_ || settings_->settings().multiplayer) {
+ te.set_string(1, "");
+ /** TRANSLATORS: Prefix for incompatible files in load game screens */
+ te.set_string(2, (boost::format(_("Incompatible: %s")) % fs_filename).str());
+ } else {
+ te.set_string(1, (boost::format(_("Incompatible: %s")) % fs_filename).str());
}
}
}
=== modified file 'src/ui_fsmenu/mapselect.cc'
--- src/ui_fsmenu/mapselect.cc 2016-01-29 08:37:22 +0000
+++ src/ui_fsmenu/mapselect.cc 2016-02-06 16:06:14 +0000
@@ -214,9 +214,6 @@
* The search starts in \ref curdir_ ("..../maps") and there is no possibility
* to move further up. If the user moves down into subdirectories, we insert an
* entry to move back up.
- *
- * \note special case is, if this is a multiplayer game on a dedicated server and
- * the client wants to change the map - in that case the maps available on the server are shown.
*/
void FullscreenMenuMapSelect::fill_table()
{
@@ -231,137 +228,66 @@
display_type = MapData::DisplayType::kMapnamesLocalized;
}
- if (settings_->settings().maps.empty()) {
- // This is the normal case
-
- // Fill it with all files we find in all directories.
- FilenameSet files = g_fs->list_directory(curdir_);
-
- //If we are not at the top of the map directory hierarchy (we're not talking
- //about the absolute filesystem top!) we manually add ".."
- if (curdir_ != basedir_) {
- maps_data_.push_back(MapData::create_parent_dir(curdir_));
- }
-
- Widelands::Map map; // MapLoader needs a place to put its preload data
-
- for (const std::string& mapfilename : files) {
- // Add map file (compressed) or map directory (uncompressed)
- std::unique_ptr<Widelands::MapLoader> ml = map.get_correct_loader(mapfilename);
- if (ml != nullptr) {
- try {
- map.set_filename(mapfilename);
- ml->preload_map(true);
-
- if (!map.get_width() || !map.get_height()) {
- continue;
- }
-
- MapData::MapType maptype;
- if (map.scenario_types() & scenario_types_) {
- maptype = MapData::MapType::kScenario;
- } else if (dynamic_cast<WidelandsMapLoader*>(ml.get())) {
- maptype = MapData::MapType::kNormal;
- } else {
- maptype = MapData::MapType::kSettlers2;
- }
-
- MapData mapdata(map, mapfilename, maptype, display_type);
-
- has_translated_mapname_ =
- has_translated_mapname_ || (mapdata.name != mapdata.localized_name);
-
- bool has_all_tags = true;
- for (std::set<uint32_t>::const_iterator it = req_tags_.begin(); it != req_tags_.end(); ++it)
- has_all_tags &= mapdata.tags.count(tags_ordered_[*it]);
- if (!has_all_tags) {
- continue;
- }
- maps_data_.push_back(mapdata);
- } catch (const std::exception & e) {
- log("Mapselect: Skip %s due to preload error: %s\n", mapfilename.c_str(), e.what());
- } catch (...) {
- log("Mapselect: Skip %s due to unknown exception\n", mapfilename.c_str());
- }
- } else if (g_fs->is_directory(mapfilename)) {
- // Add subdirectory to the list
- const char* fs_filename = FileSystem::fs_filename(mapfilename.c_str());
- if (!strcmp(fs_filename, ".") || !strcmp(fs_filename, ".."))
- continue;
- maps_data_.push_back(MapData::create_directory(mapfilename));
- }
- }
- } else {
- //client changing maps on dedicated server
- for (uint16_t i = 0; i < settings_->settings().maps.size(); ++i) {
- Widelands::Map map; // MapLoader needs a place to put its preload data
-
- const DedicatedMapInfos & dmap = settings_->settings().maps.at(i);
- const std::string& mapfilename = dmap.path;
- std::unique_ptr<Widelands::MapLoader> ml(map.get_correct_loader(mapfilename));
-
+ // This is the normal case
+
+ // Fill it with all files we find in all directories.
+ FilenameSet files = g_fs->list_directory(curdir_);
+
+ //If we are not at the top of the map directory hierarchy (we're not talking
+ //about the absolute filesystem top!) we manually add ".."
+ if (curdir_ != basedir_) {
+ maps_data_.push_back(MapData::create_parent_dir(curdir_));
+ }
+
+ Widelands::Map map; // MapLoader needs a place to put its preload data
+
+ for (const std::string& mapfilename : files) {
+ // Add map file (compressed) or map directory (uncompressed)
+ std::unique_ptr<Widelands::MapLoader> ml = map.get_correct_loader(mapfilename);
+ if (ml != nullptr) {
try {
- if (!ml) {
- throw wexception("Mapselect: No MapLoader");
- }
-
map.set_filename(mapfilename);
ml->preload_map(true);
if (!map.get_width() || !map.get_height()) {
- throw wexception("Mapselect: Map has no size");
+ continue;
}
MapData::MapType maptype;
-
if (map.scenario_types() & scenario_types_) {
maptype = MapData::MapType::kScenario;
} else if (dynamic_cast<WidelandsMapLoader*>(ml.get())) {
+ maptype = MapData::MapType::kNormal;
+ } else {
maptype = MapData::MapType::kSettlers2;
- } else {
- maptype = MapData::MapType::kNormal;
- }
-
- if (map.get_nrplayers() != dmap.players ||
- (maptype == MapData::MapType::kScenario) != dmap.scenario) {
- throw wexception("Mapselect: Number of players or scenario doesn't match");
}
MapData mapdata(map, mapfilename, maptype, display_type);
- // Finally write the entry to the list
+ has_translated_mapname_ =
+ has_translated_mapname_ || (mapdata.name != mapdata.localized_name);
+
+ bool has_all_tags = true;
+ for (std::set<uint32_t>::const_iterator it = req_tags_.begin(); it != req_tags_.end(); ++it)
+ has_all_tags &= mapdata.tags.count(tags_ordered_[*it]);
+ if (!has_all_tags) {
+ continue;
+ }
maps_data_.push_back(mapdata);
+ } catch (const std::exception & e) {
+ log("Mapselect: Skip %s due to preload error: %s\n", mapfilename.c_str(), e.what());
} catch (...) {
- log("Mapselect: Skipped reading locale data for file %s - not valid.\n", mapfilename.c_str());
-
- MapData mapdata;
-
- // Fill in the data we got from the dedicated server
- mapdata.filename = mapfilename;
- mapdata.name = mapfilename.substr(5, mapfilename.size() - 1);
- mapdata.authors = MapAuthorData(_("Nobody"));
- mapdata.description = _("This map file is not present in your filesystem."
- " The data shown here was sent by the server.");
- mapdata.hint = "";
- mapdata.nrplayers = dmap.players;
- mapdata.width = 1;
- mapdata.height = 0;
- mapdata.displaytype = display_type;
-
- if (dmap.scenario) {
- mapdata.maptype = MapData::MapType::kScenario;
- mapdata.tags.insert("scenario");
- } else if (dynamic_cast<WidelandsMapLoader*>(ml.get())) {
- mapdata.maptype = MapData::MapType::kSettlers2;
- } else {
- mapdata.maptype = MapData::MapType::kNormal;
- }
-
- // Finally write the entry to the list
- maps_data_.push_back(mapdata);
+ log("Mapselect: Skip %s due to unknown exception\n", mapfilename.c_str());
}
+ } else if (g_fs->is_directory(mapfilename)) {
+ // Add subdirectory to the list
+ const char* fs_filename = FileSystem::fs_filename(mapfilename.c_str());
+ if (!strcmp(fs_filename, ".") || !strcmp(fs_filename, ".."))
+ continue;
+ maps_data_.push_back(MapData::create_directory(mapfilename));
}
}
+
table_.fill(maps_data_, display_type);
if (!table_.empty()) {
table_.select(0);
=== modified file 'src/wlapplication.cc'
--- src/wlapplication.cc 2016-02-04 15:37:19 +0000
+++ src/wlapplication.cc 2016-02-06 16:06:14 +0000
@@ -57,7 +57,6 @@
#include "graphic/text/font_set.h"
#include "graphic/text_constants.h"
#include "helper.h"
-#include "io/dedicated_log.h"
#include "io/filesystem/disk_filesystem.h"
#include "io/filesystem/layered_filesystem.h"
#include "logic/game.h"
@@ -391,68 +390,6 @@
emergency_save(game);
throw;
}
- } else if (game_type_ == INTERNET) {
- Widelands::Game game;
- try {
- // disable sound completely
- g_sound_handler.nosound_ = true;
-
- // setup some details of the dedicated server
- Section & s = g_options.pull_section ("global");
- const std::string & meta = s.get_string ("metaserver", INTERNET_GAMING_METASERVER.c_str());
- uint32_t port = s.get_natural("metaserverport", INTERNET_GAMING_PORT);
- const std::string & name = s.get_string ("nickname", "dedicated");
- const std::string & server = s.get_string ("servername", name.c_str());
- const bool registered = s.get_bool ("registered", false);
- const std::string & pwd = s.get_string ("password", "");
- for (;;) { // endless loop
- if (!InternetGaming::ref().login(name, pwd, registered, meta, port)) {
- dedicatedlog("ERROR: Could not connect to metaserver (reason above)!\n");
- return;
- }
- std::string realservername(server);
- bool name_valid = false;
- while (!name_valid) {
- name_valid = true;
- const std::vector<InternetGame> & hosts = InternetGaming::ref().games();
- for (uint32_t i = 0; i < hosts.size(); ++i) {
- if (hosts.at(i).name == realservername)
- name_valid = false;
- }
- if (!name_valid)
- realservername += "*";
- }
-
- InternetGaming::ref().set_local_servername(realservername);
-
- NetHost netgame(name, true);
-
- // Load the requested map
- Widelands::Map map;
- map.set_filename(filename_);
- std::unique_ptr<Widelands::MapLoader> ml = map.get_correct_loader(filename_);
- if (!ml) {
- throw WLWarning
- ("Unsupported format",
- "Widelands could not load the file \"%s\". The file format seems to be incompatible.",
- filename_.c_str());
- }
- ml->preload_map(true);
-
- // set the map
- netgame.set_map(map.get_name(), map.get_filename(), map.get_nrplayers());
-
- // run the network game
- // -> autostarts when a player sends "/start" as pm to the server.
- netgame.run(true);
-
- InternetGaming::ref().logout();
- }
- } catch (const std::exception & e) {
- log("Fatal exception: %s\n", e.what());
- emergency_save(game);
- throw;
- }
} else {
g_sound_handler.start_music("intro");
@@ -749,7 +686,6 @@
s.get_bool("remove_syncstreams");
s.get_bool("sound_at_message");
s.get_bool("transparent_chat");
- s.get_bool("dedicated_saving"); // saving via chatcommand on dedicated servers -> nethost.cc
s.get_string("registered");
s.get_string("nickname");
s.get_string("password");
@@ -958,17 +894,6 @@
game_type_ = SCENARIO;
commandline_.erase("scenario");
}
- if (commandline_.count("dedicated")) {
- if (game_type_ != NONE)
- throw wexception("dedicated can not be combined with other actions");
- filename_ = commandline_["dedicated"];
- if (filename_.empty())
- throw wexception("empty value of commandline parameter --dedicated");
- if (*filename_.rbegin() == '/')
- filename_.erase(filename_.size() - 1);
- game_type_ = INTERNET;
- commandline_.erase("dedicated");
- }
if (commandline_.count("script")) {
script_to_run_ = commandline_["script"];
if (script_to_run_.empty())
@@ -1297,7 +1222,7 @@
game.set_game_controller(ctrl.get());
game.init_newgame(&loaderUI, sp.settings());
- game.run(&loaderUI, Widelands::Game::NewNonScenario, "", false);
+ game.run(&loaderUI, Widelands::Game::NewNonScenario, "", false, "single_player");
} catch (const std::exception & e) {
log("Fatal exception: %s\n", e.what());
emergency_save(game);
@@ -1412,7 +1337,7 @@
game.save_handler().set_allow_saving(false);
- game.run(&loaderUI, Widelands::Game::Loaded, "", true);
+ game.run(&loaderUI, Widelands::Game::Loaded, "", true, "replay");
} catch (const std::exception & e) {
log("Fatal Exception: %s\n", e.what());
emergency_save(game);
=== modified file 'src/wlapplication.h'
--- src/wlapplication.h 2016-01-28 05:24:34 +0000
+++ src/wlapplication.h 2016-02-06 16:06:14 +0000
@@ -135,7 +135,7 @@
static WLApplication * get(int const argc = 0, char const * * argv = nullptr);
~WLApplication();
- enum GameType {NONE, EDITOR, REPLAY, SCENARIO, LOADGAME, NETWORK, INTERNET};
+ enum GameType {NONE, EDITOR, REPLAY, SCENARIO, LOADGAME, NETWORK};
void run();
=== modified file 'src/wlapplication_messages.cc'
--- src/wlapplication_messages.cc 2015-01-12 15:44:52 +0000
+++ src/wlapplication_messages.cc 2016-02-06 16:06:14 +0000
@@ -85,7 +85,6 @@
<< _(" --loadgame=FILENAME Directly loads the savegame FILENAME.") << endl
<< _(" --script=FILENAME Run the given Lua script after initialization.\n"
" Only valid with --scenario, --loadgame, or --editor.") << endl
- << _(" --dedicated=FILENAME Starts a dedicated server with FILENAME as map") << endl
/** TRANSLATORS: You may translate true/false, also as on/off or yes/no, but */
/** TRANSLATORS: it HAS TO BE CONSISTENT with the translation in the widelands textdomain */
<< _(" --auto_roadbuild_mode=[true|false]\n"
=== modified file 'src/wui/chat_msg_layout.cc'
--- src/wui/chat_msg_layout.cc 2015-03-17 21:29:04 +0000
+++ src/wui/chat_msg_layout.cc 2016-02-06 16:06:14 +0000
@@ -58,8 +58,7 @@
//
// Note that we do want host and meta server to send some richtext code,
// as the ability to send formatted commands is nice for the usability
- // of meta server and dedicated servers, so we're treading a bit of a
- // fine line here.
+ // of meta server so we're treading a bit of a fine line here.
std::string sanitized;
for (std::string::size_type pos = 0; pos < chat_message.msg.size(); ++pos) {
if (chat_message.msg[pos] == '<') {
@@ -157,8 +156,7 @@
//
// Note that we do want host and meta server to send some richtext code,
// as the ability to send formatted commands is nice for the usability
- // of meta server and dedicated servers, so we're treading a bit of a
- // fine line here.
+ // of meta server so we're treading a bit of a fine line here.
std::string sanitized;
for (std::string::size_type pos = 0; pos < chat_message.msg.size(); ++pos) {
if (chat_message.msg[pos] == '<') {
Follow ups