MCPcopy Create free account
hub / github.com/GlobedGD/globed2 / handleLinkEvent

Method handleLinkEvent

src/modules/two-player/TwoPlayerModule.cpp:272–323  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

270}
271
272void TwoPlayerModule::handleLinkEvent(const TwoPlayerLinkRequestEvent& event) {
273 // are we already linked? if so, send an unlink if it's a different player (rejecting the link attempt)
274 if (m_linkedPlayer) {
275 if (*m_linkedPlayer != event.playerId) {
276 this->sendUnlinkEventTo(event.playerId);
277 }
278 return;
279 }
280
281 // are we currently trying to link? check if it's the right user
282 if (m_linkAttempt) {
283 if (*m_linkAttempt != event.playerId) {
284 this->sendUnlinkEventTo(event.playerId);
285 return;
286 }
287
288 // successful link!
289 this->linkSuccess(event.playerId, !event.player1);
290 return;
291 }
292
293 // if we are not currently trying to link, show a popup to the user, asking if they agree to link
294 std::string username;
295
296 if (auto pl = GlobedGJBGL::get()) {
297 if (auto player = pl->getPlayer(event.playerId)) {
298 if (player->isDataInitialized()) {
299 username = player->displayData().username;
300 }
301 }
302 }
303
304 if (username.empty()) {
305 username = fmt::format("Unknown ({})", event.playerId);
306 }
307
308 globed::quickPopup(
309 "Note",
310 fmt::format("<cg>{}</c> wants to link with you. You will be playing as the <cy>{} player</c>. Agree to link?", username, event.player1 ? "first" : "second"),
311 "Cancel",
312 "Agree",
313 [this, event](auto, bool agree) {
314 if (!agree) {
315 this->sendUnlinkEventTo(event.playerId);
316 } else {
317 // successful link! make sure to send confirmation event
318 this->sendLinkEventTo(event.playerId, !event.player1);
319 this->linkSuccess(event.playerId, !event.player1);
320 }
321 }
322 );
323}
324
325void TwoPlayerModule::handleUnlinkEvent(const TwoPlayerUnlinkEvent& event) {
326 if (m_linkedPlayer == event.playerId) {

Callers 1

handleEventMethod · 0.95

Calls 8

sendUnlinkEventToMethod · 0.95
linkSuccessMethod · 0.95
sendLinkEventToMethod · 0.95
quickPopupFunction · 0.85
isDataInitializedMethod · 0.80
emptyMethod · 0.80
getFunction · 0.50
getPlayerMethod · 0.45

Tested by

no test coverage detected