MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / serverButtonPressed

Method serverButtonPressed

source/modes/MenuModeMultiplayerServer.cpp:191–254  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

189}
190
191bool MenuModeMultiplayerServer::serverButtonPressed(const CEGUI::EventArgs&)
192{
193 CEGUI::Window* mainWin = getModeManager().getGui().getGuiSheet(Gui::guiSheet::multiplayerServerMenu);
194 CEGUI::Listbox* levelSelectList = static_cast<CEGUI::Listbox*>(mainWin->getChild(Gui::MPM_LIST_LEVELS));
195
196 if(levelSelectList->getSelectedCount() == 0)
197 {
198 mainWin->getChild(Gui::MPM_TEXT_LOADING)->setText("Please select a level first.");
199 return true;
200 }
201
202 CEGUI::Editbox* editNick = static_cast<CEGUI::Editbox*>(mainWin->getChild(Gui::MPM_EDIT_NICK));
203 std::string nick = editNick->getText().c_str();
204 CEGUI::String nickCeguiStr = reinterpret_cast<const CEGUI::utf8*>(nick.c_str());
205 if (nickCeguiStr.empty())
206 {
207 mainWin->getChild(Gui::MPM_TEXT_LOADING)->setText("Please enter a nickname.");
208 return true;
209 }
210 else if (nickCeguiStr.length() > 20)
211 {
212 mainWin->getChild(Gui::MPM_TEXT_LOADING)->setText("Please enter a shorter nickname. (20 letters max.)");
213 return true;
214 }
215
216 ODFrameListener::getSingleton().getClientGameMap()->setLocalPlayerNick(nick);
217
218 mainWin->getChild(Gui::MPM_TEXT_LOADING)->setText("Loading...");
219
220 CEGUI::ListboxItem* selItem = levelSelectList->getFirstSelectedItem();
221 uint32_t id = selItem->getID();
222
223 if(id >= mFilesList.size())
224 {
225 OD_LOG_ERR("index too high=" + Helper::toString(id) + ", size=" + Helper::toString(mFilesList.size()));
226 return true;
227 }
228 const std::string& level = mFilesList[id];
229
230 bool useMasterServer = (getModeType() == ModeManager::MENU_MASTERSERVER_HOST);
231
232 // We are a server
233 if(!ODServer::getSingleton().startServer(nick, level, ServerMode::ModeGameMultiPlayer, useMasterServer))
234 {
235 OD_LOG_ERR("Could not start server for multi player game !!!");
236 mainWin->getChild(Gui::MPM_TEXT_LOADING)->setText("ERROR: Could not start server for multi player game !!!");
237 return true;
238 }
239
240 // Connexion parameters
241 int port = ODServer::getSingleton().getNetworkPort();
242 uint32_t timeout = ConfigManager::getSingleton().getClientConnectionTimeout();
243 std::string replayFilename = ResourceManager::getSingleton().getReplayDataPath()
244 + ResourceManager::getSingleton().buildReplayFilename();
245
246 // We connect ourself
247 if(!ODClient::getSingleton().connect("localhost", port, timeout, replayFilename))
248 {

Callers

nothing calls this directly

Calls 10

getGuiSheetMethod · 0.80
setTextMethod · 0.80
setLocalPlayerNickMethod · 0.80
getClientGameMapMethod · 0.80
buildReplayFilenameMethod · 0.80
toStringFunction · 0.50
startServerMethod · 0.45
getNetworkPortMethod · 0.45
connectMethod · 0.45

Tested by

no test coverage detected