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

Method clientButtonPressed

source/modes/MenuModeMultiplayerClient.cpp:88–131  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

86}
87
88bool MenuModeMultiplayerClient::clientButtonPressed(const CEGUI::EventArgs&)
89{
90 CEGUI::Window* mainWin = getModeManager().getGui().getGuiSheet(Gui::guiSheet::multiplayerClientMenu);
91 CEGUI::Editbox* editIp = static_cast<CEGUI::Editbox*>(mainWin->getChild(Gui::MPM_EDIT_IP));
92 const std::string ip = editIp->getText().c_str();
93
94 CEGUI::Window* infoText = mainWin->getChild(Gui::MPM_TEXT_LOADING);
95
96 if (ip.empty())
97 {
98 infoText->setText("Please enter a server IP.");
99 return true;
100 }
101
102 CEGUI::Editbox* editNick = static_cast<CEGUI::Editbox*>(mainWin->getChild(Gui::MPM_EDIT_NICK));
103 std::string nick = editNick->getText().c_str();
104 CEGUI::String nickCeguiStr = reinterpret_cast<const CEGUI::utf8*>(nick.c_str());
105 if (nickCeguiStr.empty())
106 {
107 infoText->setText("Please enter a nickname.");
108 return true;
109 }
110 else if (nickCeguiStr.length() > 20)
111 {
112 infoText->setText("Please enter a shorter nickname. (20 letters max.)");
113 return true;
114 }
115
116 ODFrameListener::getSingleton().getClientGameMap()->setLocalPlayerNick(nick);
117
118 int port = ODServer::getSingleton().getNetworkPort();
119 uint32_t timeout = ConfigManager::getSingleton().getClientConnectionTimeout();
120 std::string replayFilename = ResourceManager::getSingleton().getReplayDataPath()
121 + ResourceManager::getSingleton().buildReplayFilename();
122 if(!ODClient::getSingleton().connect(ip, port, timeout, replayFilename))
123 {
124 // Error while connecting
125 infoText->setText("Could not connect to: " + ip);
126 return true;
127 }
128
129 infoText->setText("Loading...");
130 return true;
131}

Callers

nothing calls this directly

Calls 8

getGuiSheetMethod · 0.80
setTextMethod · 0.80
setLocalPlayerNickMethod · 0.80
getClientGameMapMethod · 0.80
buildReplayFilenameMethod · 0.80
getNetworkPortMethod · 0.45
connectMethod · 0.45

Tested by

no test coverage detected