std::wstring &error_message,
std::string configpath,
ChatBackend &chat_backend,
- const SubgameSpec &gamespec // Used for local game
+ const SubgameSpec &gamespec, // Used for local game,
+ bool simple_singleplayer_mode
)
{
video::IVideoDriver* driver = device->getVideoDriver();
if(address == ""){
draw_load_screen(L"Creating server...", driver, font);
infostream<<"Creating server"<<std::endl;
- server = new Server(map_dir, configpath, gamespec);
+ server = new Server(map_dir, configpath, gamespec,
+ simple_singleplayer_mode);
server->start(port);
}
<<"Launching pause menu"<<std::endl;
// It will delete itself by itself
(new GUIPauseMenu(guienv, guiroot, -1, g_gamecallback,
- &g_menumgr))->drop();
+ &g_menumgr, simple_singleplayer_mode))->drop();
// Move mouse cursor on top of the disconnect button
input->setMousePos(displaycenter.X, displaycenter.Y+25);
std::wstring &error_message,
std::string configpath,
ChatBackend &chat_backend,
- const SubgameSpec &gamespec // Used for local game
+ const SubgameSpec &gamespec, // Used for local game
+ bool simple_singleplayer_mode
);
#endif
if(e != NULL && e->getType() == gui::EGUIET_TAB_CONTROL)
dst->selected_tab = ((gui::IGUITabControl*)e)->getActiveTab();
}
- if(getTab() == TAB_SINGLEPLAYER)
+ if(dst->selected_tab == TAB_SINGLEPLAYER)
{
- dst->name = L"singleplayer";
- dst->password = L"";
- dst->address = L"";
- dst->port = 30000;
+ dst->simple_singleplayer_mode = true;
}
else
{
+ dst->simple_singleplayer_mode = false;
{
gui::IGUIElement *e = getElementFromId(GUI_ID_NAME_INPUT);
if(e != NULL)
bool creative_mode;
bool enable_damage;
int selected_world;
+ bool simple_singleplayer_mode;
// Actions
WorldSpec delete_world_spec;
std::wstring create_world_name;
// Server opts
creative_mode(false),
enable_damage(false),
- selected_world(0)
+ selected_world(0),
+ simple_singleplayer_mode(false)
{}
};
GUIPauseMenu::GUIPauseMenu(gui::IGUIEnvironment* env,\r
gui::IGUIElement* parent, s32 id,\r
IGameCallback *gamecallback,\r
- IMenuManager *menumgr):\r
- GUIModalMenu(env, parent, id, menumgr)\r
+ IMenuManager *menumgr,\r
+ bool simple_singleplayer_mode):\r
+ GUIModalMenu(env, parent, id, menumgr),\r
+ m_gamecallback(gamecallback),\r
+ m_simple_singleplayer_mode(simple_singleplayer_mode)\r
{\r
- m_gamecallback = gamecallback;\r
}\r
\r
GUIPauseMenu::~GUIPauseMenu()\r
*/\r
const s32 btn_height = 30;\r
const s32 btn_gap = 20;\r
- const s32 btn_num = 4;\r
+ const s32 btn_num = m_simple_singleplayer_mode ? 3 : 4;\r
s32 btn_y = size.Y/2-((btn_num*btn_height+(btn_num-1)*btn_gap))/2;\r
changeCtype("");\r
{\r
wgettext("Continue"));\r
}\r
btn_y += btn_height + btn_gap;\r
+ if(!m_simple_singleplayer_mode)\r
{\r
- core::rect<s32> rect(0, 0, 140, btn_height);\r
- rect = rect + v2s32(size.X/2-140/2, btn_y);\r
- Environment->addButton(rect, this, 261,\r
- wgettext("Change Password"));\r
+ {\r
+ core::rect<s32> rect(0, 0, 140, btn_height);\r
+ rect = rect + v2s32(size.X/2-140/2, btn_y);\r
+ Environment->addButton(rect, this, 261,\r
+ wgettext("Change Password"));\r
+ }\r
+ btn_y += btn_height + btn_gap;\r
}\r
- btn_y += btn_height + btn_gap;\r
{\r
core::rect<s32> rect(0, 0, 140, btn_height);\r
rect = rect + v2s32(size.X/2-140/2, btn_y);\r
Environment->addButton(rect, this, 260,\r
- wgettext("Disconnect"));\r
+ wgettext("Exit to Menu"));\r
}\r
btn_y += btn_height + btn_gap;\r
{\r
GUIPauseMenu(gui::IGUIEnvironment* env,\r
gui::IGUIElement* parent, s32 id,\r
IGameCallback *gamecallback,\r
- IMenuManager *menumgr);\r
+ IMenuManager *menumgr,\r
+ bool simple_singleplayer_mode);\r
~GUIPauseMenu();\r
\r
void removeChildren();\r
\r
private:\r
IGameCallback *m_gamecallback;\r
+ bool m_simple_singleplayer_mode;\r
};\r
\r
#endif\r
infostream<<"Using gamespec \""<<gamespec.id<<"\""<<std::endl;
// Create server
- Server server(world_path, configpath, gamespec);
+ Server server(world_path, configpath, gamespec, false);
server.start(port);
// Run server
SubgameSpec gamespec;
WorldSpec worldspec;
+ bool simple_singleplayer_mode = false;
+
+ // These are set up based on the menu and other things
+ std::string current_playername = "invĀ£lid";
+ std::string current_password = "";
+ std::string current_address = "does-not-exist";
+ int current_port = 0;
/*
Out-of-game menu loop.
int newport = stoi(wide_to_narrow(menudata.port));
if(newport != 0)
port = newport;
+ simple_singleplayer_mode = menudata.simple_singleplayer_mode;
// Save settings
g_settings->setS32("selected_mainmenu_tab", menudata.selected_tab);
g_settings->set("new_style_leaves", itos(menudata.fancy_trees));
if(menudata.selected_world != -1)
g_settings->set("selected_world_path",
worldspecs[menudata.selected_world].path);
- /*// Update configuration file
- if(configpath != "")
- g_settings->updateConfigFile(configpath.c_str());*/
// Break out of menu-game loop to shut down cleanly
if(device->run() == false || kill == true)
break;
+ current_playername = playername;
+ current_password = password;
+ current_address = address;
+ current_port = port;
+
+ // If using simple singleplayer mode, override
+ if(simple_singleplayer_mode){
+ current_playername = "singleplayer";
+ current_password = "";
+ current_address = "";
+ current_port = 30011;
+ }
+
// Set world path to selected one
if(menudata.selected_world != -1){
worldspec = worldspecs[menudata.selected_world];
}
// If local game
- if(address == "")
+ if(current_address == "")
{
if(menudata.selected_world == -1){
error_message = L"No world selected and no address "
// Break out of menu-game loop to shut down cleanly
if(device->run() == false || kill == true)
break;
-
+
/*
Run game
*/
device,
font,
worldspec.path,
- playername,
- password,
- address,
- port,
+ current_playername,
+ current_password,
+ current_address,
+ current_port,
error_message,
configpath,
chat_backend,
- gamespec
+ gamespec,
+ simple_singleplayer_mode
);
} //try
Server::Server(
const std::string &path_world,
const std::string &path_config,
- const SubgameSpec &gamespec
+ const SubgameSpec &gamespec,
+ bool simple_singleplayer_mode
):
m_path_world(path_world),
m_path_config(path_config),
m_gamespec(gamespec),
+ m_simple_singleplayer_mode(simple_singleplayer_mode),
m_async_fatal_error(""),
m_env(NULL),
m_con(PROTOCOL_ID, 512, CONNECTION_TIMEOUT, this),
// share/server
m_path_share = porting::path_share + DIR_DELIM + "server";
- infostream<<"Server created for gameid \""<<m_gamespec.id<<"\""<<std::endl;
+ infostream<<"Server created for gameid \""<<m_gamespec.id<<"\"";
+ if(m_simple_singleplayer_mode)
+ infostream<<" in simple singleplayer mode"<<std::endl;
+ else
+ infostream<<std::endl;
infostream<<"- world: "<<m_path_world<<std::endl;
infostream<<"- config: "<<m_path_config<<std::endl;
infostream<<"- game: "<<m_gamespec.path<<std::endl;
SendAccessDenied(m_con, peer_id, L"Invalid password");
return;
}
+
+ // Do not allow multiple players in simple singleplayer mode.
+ // This isn't a perfect way to do it, but will suffice for now.
+ if(m_simple_singleplayer_mode && m_clients.size() > 1){
+ infostream<<"Server: Not allowing another client to connect in"
+ <<" simple singleplayer mode"<<std::endl;
+ SendAccessDenied(m_con, peer_id,
+ L"Running in simple singleplayer mode.");
+ return;
+ }
// Enforce user limit.
// Don't enforce for users that have some admin right
m_con.Send(peer_id, 0, data, true);
}
- // Send information about server to player in chat
- SendChatMessage(peer_id, getStatusString());
-
- // Send information about joining in chat
+ // Note things in chat if not in simple singleplayer mode
+ if(!m_simple_singleplayer_mode)
{
- std::wstring name = L"unknown";
- Player *player = m_env->getPlayer(peer_id);
- if(player != NULL)
- name = narrow_to_wide(player->getName());
+ // Send information about server to player in chat
+ SendChatMessage(peer_id, getStatusString());
- std::wstring message;
- message += L"*** ";
- message += name;
- message += L" joined game";
- BroadcastChatMessage(message);
+ // Send information about joining in chat
+ {
+ std::wstring name = L"unknown";
+ Player *player = m_env->getPlayer(peer_id);
+ if(player != NULL)
+ name = narrow_to_wide(player->getName());
+
+ std::wstring message;
+ message += L"*** ";
+ message += name;
+ message += L" joined game";
+ BroadcastChatMessage(message);
+ }
}
// Warnings about protocol version can be issued here
Server(
const std::string &path_world,
const std::string &path_config,
- const SubgameSpec &gamespec
+ const SubgameSpec &gamespec,
+ bool simple_singleplayer_mode
);
~Server();
void start(unsigned short port);
std::string m_path_config;
// Subgame specification
SubgameSpec m_gamespec;
+ // If true, do not allow multiple players and hide some multiplayer
+ // functionality
+ bool m_simple_singleplayer_mode;
// Equivalent of /usr/share/minetest/server
std::string m_path_share;