@@ -1423,7 +1423,7 @@ class Game
1423
1423
// If address is "", local server is used and address is updated
1424
1424
std::string *address,
1425
1425
u16 port,
1426
- std::wstring * error_message,
1426
+ std::string & error_message,
1427
1427
ChatBackend *chat_backend,
1428
1428
const SubgameSpec &gamespec, // Used for local game
1429
1429
bool simple_singleplayer_mode);
@@ -1445,9 +1445,8 @@ class Game
1445
1445
1446
1446
// Client creation
1447
1447
bool createClient (const std::string &playername,
1448
- const std::string &password, std::string *address, u16 port,
1449
- std::wstring *error_message);
1450
- bool initGui (std::wstring *error_message);
1448
+ const std::string &password, std::string *address, u16 port);
1449
+ bool initGui ();
1451
1450
1452
1451
// Client connection
1453
1452
bool connectToServer (const std::string &playername,
@@ -1575,7 +1574,7 @@ class Game
1575
1574
video::IVideoDriver *driver;
1576
1575
scene::ISceneManager *smgr;
1577
1576
bool *kill;
1578
- std::wstring *error_message;
1577
+ std::string *error_message;
1579
1578
IGameDef *gamedef; // Convenience (same as *client)
1580
1579
scene::ISceneNode *skybox;
1581
1580
@@ -1692,15 +1691,15 @@ bool Game::startup(bool *kill,
1692
1691
const std::string &password,
1693
1692
std::string *address, // can change if simple_singleplayer_mode
1694
1693
u16 port,
1695
- std::wstring * error_message,
1694
+ std::string & error_message,
1696
1695
ChatBackend *chat_backend,
1697
1696
const SubgameSpec &gamespec,
1698
1697
bool simple_singleplayer_mode)
1699
1698
{
1700
1699
// "cache"
1701
1700
this ->device = device;
1702
1701
this ->kill = kill ;
1703
- this ->error_message = error_message;
1702
+ this ->error_message = & error_message;
1704
1703
this ->random_input = random_input;
1705
1704
this ->input = input;
1706
1705
this ->chat_backend = chat_backend;
@@ -1714,7 +1713,7 @@ bool Game::startup(bool *kill,
1714
1713
if (!init (map_dir, address, port, gamespec))
1715
1714
return false ;
1716
1715
1717
- if (!createClient (playername, password, address, port, error_message ))
1716
+ if (!createClient (playername, password, address, port))
1718
1717
return false ;
1719
1718
1720
1719
return true ;
@@ -1934,10 +1933,10 @@ bool Game::createSingleplayerServer(const std::string map_dir,
1934
1933
}
1935
1934
1936
1935
if (bind_addr.isIPv6 () && !g_settings->getBool (" enable_ipv6" )) {
1937
- *error_message = L " Unable to listen on " +
1938
- narrow_to_wide ( bind_addr.serializeString () ) +
1939
- L " because IPv6 is disabled" ;
1940
- errorstream << wide_to_narrow ( *error_message) << std::endl;
1936
+ *error_message = " Unable to listen on " +
1937
+ bind_addr.serializeString () +
1938
+ " because IPv6 is disabled" ;
1939
+ errorstream << *error_message << std::endl;
1941
1940
return false ;
1942
1941
}
1943
1942
@@ -1950,8 +1949,7 @@ bool Game::createSingleplayerServer(const std::string map_dir,
1950
1949
}
1951
1950
1952
1951
bool Game::createClient (const std::string &playername,
1953
- const std::string &password, std::string *address, u16 port,
1954
- std::wstring *error_message)
1952
+ const std::string &password, std::string *address, u16 port)
1955
1953
{
1956
1954
showOverlayMessage (wgettext (" Creating client..." ), 0 , 10 );
1957
1955
@@ -1966,19 +1964,19 @@ bool Game::createClient(const std::string &playername,
1966
1964
return false ;
1967
1965
1968
1966
if (!could_connect) {
1969
- if (* error_message == L" " && !connect_aborted) {
1967
+ if (error_message-> empty () && !connect_aborted) {
1970
1968
// Should not happen if error messages are set properly
1971
- *error_message = L " Connection failed for unknown reason" ;
1972
- errorstream << wide_to_narrow ( *error_message) << std::endl;
1969
+ *error_message = " Connection failed for unknown reason" ;
1970
+ errorstream << *error_message << std::endl;
1973
1971
}
1974
1972
return false ;
1975
1973
}
1976
1974
1977
1975
if (!getServerContent (&connect_aborted)) {
1978
- if (* error_message == L" " && !connect_aborted) {
1976
+ if (error_message-> empty () && !connect_aborted) {
1979
1977
// Should not happen if error messages are set properly
1980
- *error_message = L " Connection failed for unknown reason" ;
1981
- errorstream << wide_to_narrow ( *error_message) << std::endl;
1978
+ *error_message = " Connection failed for unknown reason" ;
1979
+ errorstream << *error_message << std::endl;
1982
1980
}
1983
1981
return false ;
1984
1982
}
@@ -1997,9 +1995,8 @@ bool Game::createClient(const std::string &playername,
1997
1995
if (m_cache_enable_clouds) {
1998
1996
clouds = new Clouds (smgr->getRootSceneNode (), smgr, -1 , time (0 ));
1999
1997
if (!clouds) {
2000
- *error_message = L" Memory allocation error" ;
2001
- *error_message += narrow_to_wide (" (clouds)" );
2002
- errorstream << wide_to_narrow (*error_message) << std::endl;
1998
+ *error_message = " Memory allocation error (clouds)" ;
1999
+ errorstream << *error_message << std::endl;
2003
2000
return false ;
2004
2001
}
2005
2002
}
@@ -2012,9 +2009,8 @@ bool Game::createClient(const std::string &playername,
2012
2009
local_inventory = new Inventory (itemdef_manager);
2013
2010
2014
2011
if (!(sky && local_inventory)) {
2015
- *error_message = L" Memory allocation error" ;
2016
- *error_message += narrow_to_wide (" (sky or local inventory)" );
2017
- errorstream << wide_to_narrow (*error_message) << std::endl;
2012
+ *error_message = " Memory allocation error (sky or local inventory)" ;
2013
+ errorstream << *error_message << std::endl;
2018
2014
return false ;
2019
2015
}
2020
2016
@@ -2028,7 +2024,7 @@ bool Game::createClient(const std::string &playername,
2028
2024
crack_animation_length = 5 ;
2029
2025
}
2030
2026
2031
- if (!initGui (error_message ))
2027
+ if (!initGui ())
2032
2028
return false ;
2033
2029
2034
2030
/* Set window caption
@@ -2046,15 +2042,15 @@ bool Game::createClient(const std::string &playername,
2046
2042
hud = new Hud (driver, smgr, guienv, gamedef, player, local_inventory);
2047
2043
2048
2044
if (!hud) {
2049
- *error_message = L " Memory error: could not create HUD" ;
2050
- errorstream << wide_to_narrow ( *error_message) << std::endl;
2045
+ *error_message = " Memory error: could not create HUD" ;
2046
+ errorstream << *error_message << std::endl;
2051
2047
return false ;
2052
2048
}
2053
2049
2054
2050
return true ;
2055
2051
}
2056
2052
2057
- bool Game::initGui (std::wstring *error_message )
2053
+ bool Game::initGui ()
2058
2054
{
2059
2055
// First line of debug text
2060
2056
guitext = guienv->addStaticText (
@@ -2095,8 +2091,8 @@ bool Game::initGui(std::wstring *error_message)
2095
2091
gui_chat_console = new GUIChatConsole (guienv, guienv->getRootGUIElement (),
2096
2092
-1 , chat_backend, client);
2097
2093
if (!gui_chat_console) {
2098
- *error_message = L " Could not allocate memory for chat console" ;
2099
- errorstream << wide_to_narrow ( *error_message) << std::endl;
2094
+ *error_message = " Could not allocate memory for chat console" ;
2095
+ errorstream << *error_message << std::endl;
2100
2096
return false ;
2101
2097
}
2102
2098
@@ -2146,16 +2142,16 @@ bool Game::connectToServer(const std::string &playername,
2146
2142
local_server_mode = true ;
2147
2143
}
2148
2144
} catch (ResolveError &e) {
2149
- *error_message = L " Couldn't resolve address: " + narrow_to_wide ( e.what () );
2150
- errorstream << wide_to_narrow ( *error_message) << std::endl;
2145
+ *error_message = std::string ( " Couldn't resolve address: " ) + e.what ();
2146
+ errorstream << *error_message << std::endl;
2151
2147
return false ;
2152
2148
}
2153
2149
2154
2150
if (connect_address.isIPv6 () && !g_settings->getBool (" enable_ipv6" )) {
2155
- *error_message = L " Unable to connect to " +
2156
- narrow_to_wide ( connect_address.serializeString () ) +
2157
- L " because IPv6 is disabled" ;
2158
- errorstream << wide_to_narrow ( *error_message) << std::endl;
2151
+ *error_message = " Unable to connect to " +
2152
+ connect_address.serializeString () +
2153
+ " because IPv6 is disabled" ;
2154
+ errorstream << *error_message << std::endl;
2159
2155
return false ;
2160
2156
}
2161
2157
@@ -2205,9 +2201,9 @@ bool Game::connectToServer(const std::string &playername,
2205
2201
2206
2202
// Break conditions
2207
2203
if (client->accessDenied ()) {
2208
- *error_message = L " Access denied. Reason: "
2204
+ *error_message = " Access denied. Reason: "
2209
2205
+ client->accessDeniedReason ();
2210
- errorstream << wide_to_narrow ( *error_message) << std::endl;
2206
+ errorstream << *error_message << std::endl;
2211
2207
break ;
2212
2208
}
2213
2209
@@ -2253,16 +2249,12 @@ bool Game::getServerContent(bool *aborted)
2253
2249
}
2254
2250
2255
2251
// Error conditions
2256
- if (client->accessDenied ()) {
2257
- *error_message = L" Access denied. Reason: "
2258
- + client->accessDeniedReason ();
2259
- errorstream << wide_to_narrow (*error_message) << std::endl;
2252
+ if (!checkConnection ())
2260
2253
return false ;
2261
- }
2262
2254
2263
2255
if (client->getState () < LC_Init) {
2264
- *error_message = L " Client disconnected" ;
2265
- errorstream << wide_to_narrow ( *error_message) << std::endl;
2256
+ *error_message = " Client disconnected" ;
2257
+ errorstream << *error_message << std::endl;
2266
2258
return false ;
2267
2259
}
2268
2260
@@ -2336,9 +2328,9 @@ inline void Game::updateInteractTimers(GameRunData *runData, f32 dtime)
2336
2328
inline bool Game::checkConnection ()
2337
2329
{
2338
2330
if (client->accessDenied ()) {
2339
- *error_message = L " Access denied. Reason: "
2331
+ *error_message = " Access denied. Reason: "
2340
2332
+ client->accessDeniedReason ();
2341
- errorstream << wide_to_narrow ( *error_message) << std::endl;
2333
+ errorstream << *error_message << std::endl;
2342
2334
return false ;
2343
2335
}
2344
2336
@@ -4219,7 +4211,7 @@ void the_game(bool *kill,
4219
4211
const std::string &address, // If empty local server is created
4220
4212
u16 port,
4221
4213
4222
- std::wstring &error_message,
4214
+ std::string &error_message,
4223
4215
ChatBackend &chat_backend,
4224
4216
const SubgameSpec &gamespec, // Used for local game
4225
4217
bool simple_singleplayer_mode)
@@ -4235,24 +4227,24 @@ void the_game(bool *kill,
4235
4227
try {
4236
4228
4237
4229
if (game.startup (kill , random_input, input, device, map_dir,
4238
- playername, password, &server_address, port,
4239
- &error_message, &chat_backend, gamespec,
4240
- simple_singleplayer_mode)) {
4241
-
4230
+ playername, password, &server_address, port,
4231
+ error_message, &chat_backend, gamespec,
4232
+ simple_singleplayer_mode)) {
4242
4233
game.run ();
4243
4234
game.shutdown ();
4244
4235
}
4245
4236
4246
4237
} catch (SerializationError &e) {
4247
- error_message = L " A serialization error occurred:\n "
4248
- + narrow_to_wide ( e.what ()) + L "\n\n The server is probably "
4249
- L " running a different version of " PROJECT_NAME " ." ;
4250
- errorstream << wide_to_narrow ( error_message) << std::endl;
4238
+ error_message = std::string ( " A serialization error occurred:\n " )
4239
+ + e.what () + " \n\n The server is probably "
4240
+ " running a different version of " PROJECT_NAME " ." ;
4241
+ errorstream << error_message << std::endl;
4251
4242
} catch (ServerError &e) {
4252
- error_message = narrow_to_wide ( e.what () );
4253
- errorstream << " ServerError: " << e. what () << std::endl;
4243
+ error_message = e.what ();
4244
+ errorstream << " ServerError: " << error_message << std::endl;
4254
4245
} catch (ModError &e) {
4255
- errorstream << " ModError: " << e.what () << std::endl ;
4256
- error_message = narrow_to_wide (e. what ()) + wstrgettext ( " \n Check debug.txt for details. " ) ;
4246
+ error_message = e.what () + strgettext ( " \n Check debug.txt for details. " ) ;
4247
+ errorstream << " ModError: " << error_message << std::endl ;
4257
4248
}
4258
4249
}
4250
+
0 commit comments