#include "stdafx.h" #include "UI.h" #include "UIScene_JoinMenu.h" #include "../../Minecraft.h" #include "../../TexturePackRepository.h" #include "../../Options.h" #include "../../MinecraftServer.h" #include "../../../Minecraft.World/net.minecraft.world.level.h" #include "../../../Minecraft.World/net.minecraft.world.h" #define UPDATE_PLAYERS_TIMER_ID 0 #define UPDATE_PLAYERS_TIMER_TIME 400.0 // static overlay state for howtoplay static Iggy* s_movieServerDesc = nullptr; static vector s_movieDataServerDesc; static IggyName s_funcLoadPage = 0; static bool s_textInjected = false; static int s_injectionDelay = 0; UIScene_JoinMenu::UIScene_JoinMenu(int iPad, void *_initData, UILayer *parentLayer) : UIScene(iPad, parentLayer) { // Setup all the Iggy references we need for this scene initialiseMovie(); JoinMenuInitData *initData = static_cast(_initData); m_selectedSession = initData->selectedSession; m_friendInfoUpdatedOK = false; m_friendInfoUpdatedERROR = false; m_friendInfoRequestIssued = false; #if defined(_WINDOWS64) || defined(__linux__) m_bViewingPlayerList = false; // reset the howtoplay state s_textInjected = false; s_injectionDelay = 0; #endif } UIScene_JoinMenu::~UIScene_JoinMenu() { // destroy the player when closing the scene to avoid zombie pointers if (s_movieServerDesc) { IggyPlayerDestroy(s_movieServerDesc); s_movieServerDesc = nullptr; } } void UIScene_JoinMenu::updateTooltips() { int iA = -1; int iY = -1; int iX = -1; if (getControlFocus() == eControl_GamePlayers) { #ifdef _DURANGO iY = IDS_TOOLTIPS_VIEW_GAMERCARD; #endif } else { iA = IDS_TOOLTIPS_SELECT; } ui.SetTooltips( DEFAULT_XUI_MENU_USER, iA, IDS_TOOLTIPS_BACK, iX, iY ); } void UIScene_JoinMenu::tick() { if (this == nullptr) return; if (!m_friendInfoRequestIssued) { ui.NavigateToScene(m_iPad, eUIScene_Timer); g_NetworkManager.GetFullFriendSessionInfo(m_selectedSession, &friendSessionUpdated, this); m_friendInfoRequestIssued = true; } if (m_friendInfoUpdatedOK) { m_friendInfoUpdatedOK = false; m_buttonJoinGame.init(app.GetString(IDS_JOIN_GAME), eControl_JoinGame); m_buttonListPlayers.init(eControl_GamePlayers); m_buttonListPlayers.setYPos(m_buttonListPlayers.getYPos() + 320); #if defined(__PS3__) || defined(__ORBIS__) || defined __PSVITA__ for (int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; i++) { if (m_selectedSession->data.players[i] != nullptr) { #ifndef _CONTENT_PACKAGE if (app.DebugSettingsOn() && (app.GetGameSettingsDebugMask() & (1L << eDebugSetting_DebugLeaderboards))) { m_buttonListPlayers.addItem(L"WWWWWWWWWWWWWWWW"); } else #endif { string playerName(m_selectedSession->data.players[i].getOnlineID()); #ifndef __PSVITA__ // Append guest number (any players in an online game not signed into PSN are guests) if (m_selectedSession->data.players[i].isSignedIntoPSN() == false) { char suffix[5]; sprintf(suffix, " (%d)", m_selectedSession->data.players[i].getQuadrant() + 1); playerName.append(suffix); } #endif m_buttonListPlayers.addItem(playerName); } } else { // Leave the loop when we hit the first nullptr player break; } } #elif defined(_DURANGO) for (int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; i++) { if (m_selectedSession->searchResult.m_playerNames[i].size()) { m_buttonListPlayers.addItem(m_selectedSession->searchResult.m_playerNames[i]); } else { // Leave the loop when we hit the first empty player name break; } } #endif m_labelLabels[eLabel_Difficulty].init(app.GetString(IDS_LABEL_DIFFICULTY)); m_labelLabels[eLabel_GameType].init(app.GetString(IDS_LABEL_GAME_TYPE)); m_labelLabels[eLabel_GamertagsOn].init(app.GetString(IDS_LABEL_GAMERTAGS)); m_labelLabels[eLabel_Structures].init(app.GetString(IDS_LABEL_STRUCTURES)); m_labelLabels[eLabel_LevelType].init(app.GetString(IDS_LABEL_LEVEL_TYPE)); m_labelLabels[eLabel_PVP].init(app.GetString(IDS_LABEL_PvP)); m_labelLabels[eLabel_Trust].init(app.GetString(IDS_LABEL_TRUST)); m_labelLabels[eLabel_TNTOn].init(app.GetString(IDS_LABEL_TNT)); m_labelLabels[eLabel_FireOn].init(app.GetString(IDS_LABEL_FIRE_SPREADS)); unsigned int uiGameHostSettings = m_selectedSession->data.m_uiGameHostSettings; switch (app.GetGameHostOption(uiGameHostSettings, eGameHostOption_Difficulty)) { case Difficulty::EASY: m_labelValues[eLabel_Difficulty].init(app.GetString(IDS_DIFFICULTY_TITLE_EASY)); break; case Difficulty::NORMAL: m_labelValues[eLabel_Difficulty].init(app.GetString(IDS_DIFFICULTY_TITLE_NORMAL)); break; case Difficulty::HARD: m_labelValues[eLabel_Difficulty].init(app.GetString(IDS_DIFFICULTY_TITLE_HARD)); break; case Difficulty::PEACEFUL: default: m_labelValues[eLabel_Difficulty].init(app.GetString(IDS_DIFFICULTY_TITLE_PEACEFUL)); break; } int option = app.GetGameHostOption(uiGameHostSettings, eGameHostOption_GameType); if (option == GameType::CREATIVE->getId()) { m_labelValues[eLabel_GameType].init(app.GetString(IDS_CREATIVE)); } else if (option == GameType::ADVENTURE->getId()) { m_labelValues[eLabel_GameType].init(app.GetString(IDS_ADVENTURE)); } else { m_labelValues[eLabel_GameType].init(app.GetString(IDS_SURVIVAL)); } if (app.GetGameHostOption(uiGameHostSettings, eGameHostOption_Gamertags)) m_labelValues[eLabel_GamertagsOn].init(app.GetString(IDS_ON)); else m_labelValues[eLabel_GamertagsOn].init(app.GetString(IDS_OFF)); if (app.GetGameHostOption(uiGameHostSettings, eGameHostOption_Structures)) m_labelValues[eLabel_Structures].init(app.GetString(IDS_ON)); else m_labelValues[eLabel_Structures].init(app.GetString(IDS_OFF)); if (app.GetGameHostOption(uiGameHostSettings, eGameHostOption_LevelType)) m_labelValues[eLabel_LevelType].init(app.GetString(IDS_LEVELTYPE_SUPERFLAT)); else m_labelValues[eLabel_LevelType].init(app.GetString(IDS_LEVELTYPE_NORMAL)); if (app.GetGameHostOption(uiGameHostSettings, eGameHostOption_PvP))m_labelValues[eLabel_PVP].init(app.GetString(IDS_ON)); else m_labelValues[eLabel_PVP].init(app.GetString(IDS_OFF)); if (app.GetGameHostOption(uiGameHostSettings, eGameHostOption_TrustPlayers)) m_labelValues[eLabel_Trust].init(app.GetString(IDS_ON)); else m_labelValues[eLabel_Trust].init(app.GetString(IDS_OFF)); if (app.GetGameHostOption(uiGameHostSettings, eGameHostOption_TNT)) m_labelValues[eLabel_TNTOn].init(app.GetString(IDS_ON)); else m_labelValues[eLabel_TNTOn].init(app.GetString(IDS_OFF)); if (app.GetGameHostOption(uiGameHostSettings, eGameHostOption_FireSpreads)) m_labelValues[eLabel_FireOn].init(app.GetString(IDS_ON)); else m_labelValues[eLabel_FireOn].init(app.GetString(IDS_OFF)); #if defined(_WINDOWS64) || defined(__linux__) if (m_selectedSession->savedServerIndex >= 0 && !m_selectedSession->hasServerInfo) { for (int index = 0; index < eLabel_COUNT; ++index) m_labelValues[index].init(L"-"); } SetPlayerListPage(m_bViewingPlayerList); #endif m_bIgnoreInput = false; // Alert the app the we want to be informed of ethernet connections app.SetLiveLinkRequired(true); TelemetryManager->RecordMenuShown(m_iPad, eUIScene_JoinMenu, 0); addTimer(UPDATE_PLAYERS_TIMER_ID, UPDATE_PLAYERS_TIMER_TIME); } if (m_friendInfoUpdatedERROR) { m_buttonJoinGame.init(app.GetString(IDS_JOIN_GAME), eControl_JoinGame); m_buttonListPlayers.init(eControl_GamePlayers); m_buttonListPlayers.setYPos(m_buttonListPlayers.getYPos() + 320); m_labelLabels[eLabel_Difficulty].init(app.GetString(IDS_LABEL_DIFFICULTY)); m_labelLabels[eLabel_GameType].init(app.GetString(IDS_LABEL_GAME_TYPE)); m_labelLabels[eLabel_GamertagsOn].init(app.GetString(IDS_LABEL_GAMERTAGS)); m_labelLabels[eLabel_Structures].init(app.GetString(IDS_LABEL_STRUCTURES)); m_labelLabels[eLabel_LevelType].init(app.GetString(IDS_LABEL_LEVEL_TYPE)); m_labelLabels[eLabel_PVP].init(app.GetString(IDS_LABEL_PvP)); m_labelLabels[eLabel_Trust].init(app.GetString(IDS_LABEL_TRUST)); m_labelLabels[eLabel_TNTOn].init(app.GetString(IDS_LABEL_TNT)); m_labelLabels[eLabel_FireOn].init(app.GetString(IDS_LABEL_FIRE_SPREADS)); m_labelValues[eLabel_Difficulty].init(app.GetString(IDS_DIFFICULTY_TITLE_PEACEFUL)); m_labelValues[eLabel_GameType].init(app.GetString(IDS_CREATIVE)); m_labelValues[eLabel_GamertagsOn].init(app.GetString(IDS_OFF)); m_labelValues[eLabel_Structures].init(app.GetString(IDS_OFF)); m_labelValues[eLabel_LevelType].init(app.GetString(IDS_LEVELTYPE_NORMAL)); m_labelValues[eLabel_PVP].init(app.GetString(IDS_OFF)); m_labelValues[eLabel_Trust].init(app.GetString(IDS_OFF)); m_labelValues[eLabel_TNTOn].init(app.GetString(IDS_OFF)); m_labelValues[eLabel_FireOn].init(app.GetString(IDS_OFF)); #if defined(_WINDOWS64) || defined(__linux__) SetPlayerListPage(m_bViewingPlayerList); #endif m_friendInfoUpdatedERROR = false; // Show a generic network error message, not always safe to assume the error was host quitting // without bubbling more info up from the network manager so this is the best we can do UINT uiIDA[1]; uiIDA[0] = IDS_CONFIRM_OK; #ifdef _XBOX_ONE ui.RequestErrorMessage(IDS_CONNECTION_FAILED, IDS_DISCONNECTED_SERVER_QUIT, uiIDA, 1, m_iPad, ErrorDialogReturned, this); #else ui.RequestErrorMessage(IDS_ERROR_NETWORK_TITLE, IDS_ERROR_NETWORK, uiIDA, 1, m_iPad, ErrorDialogReturned, this); #endif } #if defined(_WINDOWS64) || defined(__linux__) if (s_movieServerDesc) { if (IggyPlayerReadyToTick(s_movieServerDesc)) { IggyPlayerTickRS(s_movieServerDesc); updateServerDescription(); } } else if (!m_selectedSession->description.empty()) { updateServerDescription(); } #endif UIScene::tick(); } void UIScene_JoinMenu::updateServerDescription() { if (m_selectedSession->description.empty()) return; // load howtoplay it's like the messagebox xd if (!s_movieServerDesc) { wstring moviePath = L"HowToPlay"; if (m_loadedResolution == eSceneResolution_1080) moviePath.append(L"1080.swf"); else if (m_loadedResolution == eSceneResolution_720) moviePath.append(L"720.swf"); else moviePath.append(L"480.swf"); byteArray baFile = ui.getMovieData(moviePath.c_str()); if (baFile.data) { s_movieDataServerDesc.assign((unsigned char*)baFile.data, (unsigned char*)baFile.data + baFile.length); s_movieServerDesc = IggyPlayerCreateFromMemory(s_movieDataServerDesc.data(), (unsigned int)s_movieDataServerDesc.size(), nullptr); if (s_movieServerDesc) { IggyPlayerInitializeAndTickRS(s_movieServerDesc); IggyPlayerSetDisplaySize(s_movieServerDesc, m_movieWidth, m_movieHeight); s_funcLoadPage = IggyPlayerCreateFastName(s_movieServerDesc, (IggyUTF16*)L"LoadHowToPlayPage", -1); // it maintains the resolution at 1080p so that it looks sharp IggyValuePath* root = IggyPlayerRootPath(s_movieServerDesc); if (root) { IggyValueSetF64RS(root, IggyPlayerCreateFastName(s_movieServerDesc, (IggyUTF16*)L"x", -1), nullptr, 0.0); IggyValueSetF64RS(root, IggyPlayerCreateFastName(s_movieServerDesc, (IggyUTF16*)L"y", -1), nullptr, 0.0); IggyValueSetF64RS(root, IggyPlayerCreateFastName(s_movieServerDesc, (IggyUTF16*)L"width", -1), nullptr, (double)m_movieWidth); IggyValueSetF64RS(root, IggyPlayerCreateFastName(s_movieServerDesc, (IggyUTF16*)L"height", -1), nullptr, (double)m_movieHeight); // it hides the logo and other things that the howtoplay has const char* elementsToHide[] = { "__id0_", "__id1_", "__id2_" }; IggyName visibleName = IggyPlayerCreateFastName(s_movieServerDesc, (IggyUTF16*)L"visible", -1); for (int i = 0; i < 3; i++) { IggyValuePath path; if (IggyValuePathMakeNameRef(&path, root, elementsToHide[i])) { IggyValueSetBooleanRS(&path, visibleName, nullptr, false); } } } } } } IggyValuePath* root = IggyPlayerRootPath(s_movieServerDesc); if (root) { // scale the size before Iggy reads it IggyValuePath textPath; if (IggyValuePathMakeNameRef(&textPath, root, "HowToPlayText_0")) { IggyName nameX = IggyPlayerCreateFastName(s_movieServerDesc, (IggyUTF16*)L"x", -1); IggyName nameY = IggyPlayerCreateFastName(s_movieServerDesc, (IggyUTF16*)L"y", -1); IggyName nameW = IggyPlayerCreateFastName(s_movieServerDesc, (IggyUTF16*)L"width", -1); IggyName nameH = IggyPlayerCreateFastName(s_movieServerDesc, (IggyUTF16*)L"height", -1); if (m_loadedResolution == eSceneResolution_1080) { IggyValueSetF64RS(&textPath, nameX, nullptr, 333.0);// horizontal IggyValueSetF64RS(&textPath, nameY, nullptr, 340.0);// vertical IggyValueSetF64RS(&textPath, nameW, nullptr, 575.0); IggyValueSetF64RS(&textPath, nameH, nullptr, 270.0); } else //720 { IggyValueSetF64RS(&textPath, nameX, nullptr, 252.0); IggyValueSetF64RS(&textPath, nameY, nullptr, 285.0); IggyValueSetF64RS(&textPath, nameW, nullptr, 440.0); IggyValueSetF64RS(&textPath, nameH, nullptr, 220.0); } } // harcoded text for test it, later im gonna delete this and // and convert it so that people can add their description when adding the server if (s_funcLoadPage != 0) { IggyDataValue result; IggyDataValue args[2]; args[0].type = IGGY_DATATYPE_number; args[0].number = 0; // 0 is the what's new page on howtoplay don't change it IggyStringUTF16 iggyStr; wstring formattedText = app.EscapeHTMLString(m_selectedSession->description); formattedText = app.FormatColoredString(formattedText); iggyStr.string = (IggyUTF16*)formattedText.c_str(); iggyStr.length = (unsigned int)formattedText.length(); args[1].type = IGGY_DATATYPE_string_UTF16; args[1].string16 = iggyStr; IggyResult res = IggyPlayerCallMethodRS(s_movieServerDesc, &result, root, s_funcLoadPage, 2, args); if (res == IGGY_RESULT_SUCCESS) { s_textInjected = true; } } // keeps the text fixed so it doesn't move from its place IggyValuePath panelPath; if (s_textInjected && IggyValuePathMakeNameRef(&panelPath, root, "DynamicHtmlText")) { IggyName nameX = IggyPlayerCreateFastName(s_movieServerDesc, (IggyUTF16*)L"x", -1); IggyName nameY = IggyPlayerCreateFastName(s_movieServerDesc, (IggyUTF16*)L"y", -1); IggyName nameW = IggyPlayerCreateFastName(s_movieServerDesc, (IggyUTF16*)L"width", -1); IggyName nameH = IggyPlayerCreateFastName(s_movieServerDesc, (IggyUTF16*)L"height", -1); if (m_loadedResolution == eSceneResolution_1080) { IggyValueSetF64RS(&panelPath, nameX, nullptr, 332.0);// horizontal IggyValueSetF64RS(&panelPath, nameY, nullptr, 340.0);// vertical IggyValueSetF64RS(&panelPath, nameW, nullptr, 580.0); IggyValueSetF64RS(&panelPath, nameH, nullptr, 270.0); } else //720p { IggyValueSetF64RS(&panelPath, nameX, nullptr, 250.0); IggyValueSetF64RS(&panelPath, nameY, nullptr, 290.0); IggyValueSetF64RS(&panelPath, nameW, nullptr, 400.0); IggyValueSetF64RS(&panelPath, nameH, nullptr, 230.0); } } } } #if defined(_WINDOWS64) || defined(__linux__) void UIScene_JoinMenu::RebuildServerPlayerList() { m_buttonListPlayers.clearList(); if (m_bViewingPlayerList) { if (m_selectedSession->hasServerInfo) { for (const wstring& playerName : m_selectedSession->serverPlayerNames) { m_buttonListPlayers.addItem(playerName); } } } else { m_buttonListPlayers.addItem(L"Show Player List"); } m_buttonListPlayers.setCurrentSelection(0); m_buttonListPlayers.updateChildFocus(0); } void UIScene_JoinMenu::SetPlayerListPage(bool visible) { if (visible != m_bViewingPlayerList) m_buttonListPlayers.setYPos(m_buttonListPlayers.getYPos() + (visible ? -320 : 320)); m_bViewingPlayerList = visible; m_buttonListPlayers.setVisible(true); // (int index = 0; index < eLabel_COUNT; ++index) { // m_labelLabels[index].setVisible(!visible); // m_labelValues[index].setVisible(!visible); //} RebuildServerPlayerList(); } #endif void UIScene_JoinMenu::friendSessionUpdated(bool success, void *pParam) { UIScene_JoinMenu *scene = static_cast(pParam); ui.NavigateBack(scene->m_iPad); if( success ) { scene->m_friendInfoUpdatedOK = true; } else { scene->m_friendInfoUpdatedERROR = true; } } int UIScene_JoinMenu::ErrorDialogReturned(void *pParam, int iPad, const C4JStorage::EMessageResult) { UIScene_JoinMenu *scene = static_cast(pParam); ui.NavigateBack(scene->m_iPad); return 0; } void UIScene_JoinMenu::updateComponents() { m_parentLayer->showComponent(m_iPad,eUIComponent_Panorama,true); m_parentLayer->showComponent(m_iPad,eUIComponent_Logo,true); } wstring UIScene_JoinMenu::getMoviePath() { return L"JoinMenu"; } void UIScene_JoinMenu::render(S32 width, S32 height, C4JRender::eViewportType viewpBort) { UIScene::render(width, height, viewpBort); #if defined(_WINDOWS64) || defined(__linux__) if (s_movieServerDesc && !m_bViewingPlayerList) { IggyPlayerSetDisplaySize(s_movieServerDesc, width, height); IggyPlayerDraw(s_movieServerDesc); } #endif } void UIScene_JoinMenu::handleInput(int iPad, int key, bool repeat, bool pressed, bool released, bool &handled) { if(m_bIgnoreInput) return; ui.AnimateKeyPress(m_iPad, key, repeat, pressed, released); switch(key) { case ACTION_MENU_CANCEL: if(pressed) { #if defined(_WINDOWS64) || defined(__linux__) if (m_bViewingPlayerList) { SetPlayerListPage(false); handled = true; break; } #endif navigateBack(); handled = true; } break; #ifdef _DURANGO case ACTION_MENU_Y: if(m_selectedSession != nullptr && getControlFocus() == eControl_GamePlayers && m_buttonListPlayers.getItemCount() > 0) { PlayerUID uid = m_selectedSession->searchResult.m_playerXuids[m_buttonListPlayers.getCurrentSelection()]; if( uid != INVALID_XUID ) ProfileManager.ShowProfileCard(ProfileManager.GetLockedProfile(),uid); } break; #endif case ACTION_MENU_OK: if (getControlFocus() != eControl_GamePlayers) { sendInputToMovie(key, repeat, pressed, released); } #if defined(_WINDOWS64) || defined(__linux__) else if (pressed) { int sel = m_buttonListPlayers.getCurrentSelection(); if (!m_bViewingPlayerList && sel == 0) SetPlayerListPage(true); } #endif handled = true; break; #ifdef __ORBIS__ case ACTION_MENU_TOUCHPAD_PRESS: #endif case ACTION_MENU_UP: case ACTION_MENU_DOWN: case ACTION_MENU_PAGEUP: case ACTION_MENU_PAGEDOWN: sendInputToMovie(key, repeat, pressed, released); handled = true; break; #if defined(_WINDOWS64) || defined(__linux__) case ACTION_MENU_OTHER_STICK_UP: case ACTION_MENU_OTHER_STICK_DOWN: if (s_movieServerDesc) { IggyEvent keyEvent; IggyKeycode iggyKeyCode = (key == ACTION_MENU_OTHER_STICK_UP) ? IGGY_KEYCODE_F11 : IGGY_KEYCODE_F12; IggyMakeEventKey(&keyEvent, pressed ? IGGY_KEYEVENT_Down : IGGY_KEYEVENT_Up, iggyKeyCode, IGGY_KEYLOC_Standard); IggyEventResult res; IggyPlayerDispatchEventRS(s_movieServerDesc, &keyEvent, &res); handled = true; } break; #endif } } void UIScene_JoinMenu::handlePress(F64 controlId, F64 childId) { switch(static_cast(controlId)) { case eControl_JoinGame: { m_bIgnoreInput = true; //CD - Added for audio ui.PlayUISFX(eSFX_Press); #ifdef _DURANGO ProfileManager.CheckMultiplayerPrivileges(m_iPad, true, &checkPrivilegeCallback, (LPVOID)GetCallbackUniqueId()); #else StartSharedLaunchFlow(); #endif } break; case eControl_GamePlayers: #if defined(_WINDOWS64) || defined(__linux__) if (!m_bViewingPlayerList && static_cast(childId) == 0) SetPlayerListPage(true); #endif break; }; } void UIScene_JoinMenu::handleFocusChange(F64 controlId, F64 childId) { switch(static_cast(controlId)) { case eControl_GamePlayers: m_buttonListPlayers.updateChildFocus( static_cast(childId) ); }; updateTooltips(); } #ifdef _DURANGO void UIScene_JoinMenu::checkPrivilegeCallback(LPVOID lpParam, bool hasPrivilege, int iPad) { UIScene_JoinMenu* pClass = (UIScene_JoinMenu*)ui.GetSceneFromCallbackId((size_t)lpParam); if(pClass) { if(hasPrivilege) { pClass->StartSharedLaunchFlow(); } else { pClass->m_bIgnoreInput = false; } } } #endif void UIScene_JoinMenu::StartSharedLaunchFlow() { if(!app.IsLocalMultiplayerAvailable()) { JoinGame(this); } else { //ProfileManager.RequestSignInUI(false, false, false, true, false,&UIScene_JoinMenu::StartGame_SignInReturned, this,ProfileManager.GetPrimaryPad()); SignInInfo info; info.Func = &UIScene_JoinMenu::StartGame_SignInReturned; info.lpParam = (LPVOID)GetCallbackUniqueId(); info.requireOnline = true; ui.NavigateToScene(ProfileManager.GetPrimaryPad(),eUIScene_QuadrantSignin,&info); } } int UIScene_JoinMenu::StartGame_SignInReturned(void *pParam,bool bContinue, int iPad) { UIScene_JoinMenu* pClass = static_cast(ui.GetSceneFromCallbackId((size_t)pParam)); if(pClass) { if(bContinue==true) { // It's possible that the player has not signed in - they can back out if(ProfileManager.IsSignedIn(iPad)) { JoinGame(pClass); } else { pClass->m_bIgnoreInput=false; } } else { pClass->m_bIgnoreInput=false; } } return 0; } // Shared function to join the game that is the same whether we used the sign-in UI or not void UIScene_JoinMenu::JoinGame(UIScene_JoinMenu* pClass) { DWORD dwSignedInUsers = 0; bool noPrivileges = false; DWORD dwLocalUsersMask = 0; bool isSignedInLive = true; int iPadNotSignedInLive = -1; ProfileManager.SetLockedProfile(0); // TEMP! // If we're in SD mode, then only the primary player gets to play if (app.IsLocalMultiplayerAvailable()) { for(unsigned int index = 0; index < XUSER_MAX_COUNT; ++index) { if(ProfileManager.IsSignedIn(index)) { if (isSignedInLive && !ProfileManager.IsSignedInLive(index)) { // Record the first non signed in live pad iPadNotSignedInLive = index; } if( !ProfileManager.AllowedToPlayMultiplayer(index) ) noPrivileges = true; dwLocalUsersMask |= CGameNetworkManager::GetLocalPlayerMask(index); isSignedInLive = isSignedInLive && ProfileManager.IsSignedInLive(index); } } } else { if(ProfileManager.IsSignedIn(ProfileManager.GetPrimaryPad())) { if( !ProfileManager.AllowedToPlayMultiplayer(ProfileManager.GetPrimaryPad()) ) noPrivileges = true; dwLocalUsersMask |= CGameNetworkManager::GetLocalPlayerMask(ProfileManager.GetPrimaryPad()); isSignedInLive = ProfileManager.IsSignedInLive(ProfileManager.GetPrimaryPad()); #ifdef __PSVITA__ if(CGameNetworkManager::usingAdhocMode() && SQRNetworkManager_AdHoc_Vita::GetAdhocStatus()) isSignedInLive = true; #endif } } // If this is an online game but not all players are signed in to Live, stop! if (!isSignedInLive) { #ifdef __ORBIS__ // Check if PSN is unavailable because of age restriction int npAvailability = ProfileManager.getNPAvailability(iPadNotSignedInLive); if (npAvailability == SCE_NP_ERROR_AGE_RESTRICTION) { pClass->m_bIgnoreInput = false; // 4J Stu - This is a bit messy and is due to the library incorrectly returning false for IsSignedInLive if the npAvailability isn't SCE_OK UINT uiIDA[1]; uiIDA[0]=IDS_OK; ui.RequestErrorMessage(IDS_ONLINE_SERVICE_TITLE, IDS_CONTENT_RESTRICTION, uiIDA, 1, iPadNotSignedInLive); } else #endif { pClass->m_bIgnoreInput=false; UINT uiIDA[1]; uiIDA[0]=IDS_CONFIRM_OK; ui.RequestErrorMessage( IDS_PRO_NOTONLINE_TITLE, IDS_PRO_NOTONLINE_TEXT, uiIDA,1,ProfileManager.GetPrimaryPad()); } return; } // Check if user-created content is allowed, as we cannot play multiplayer if it's not bool noUGC = false; BOOL pccAllowed = TRUE; BOOL pccFriendsAllowed = TRUE; #if defined(__PS3__) || defined(__PSVITA__) if(isSignedInLive) { ProfileManager.GetChatAndContentRestrictions(ProfileManager.GetPrimaryPad(),false,&noUGC,nullptr,nullptr); } #else ProfileManager.AllowedPlayerCreatedContent(ProfileManager.GetPrimaryPad(),false,&pccAllowed,&pccFriendsAllowed); if(!pccAllowed && !pccFriendsAllowed) noUGC = true; #endif #ifdef __PSVITA__ if( CGameNetworkManager::usingAdhocMode() ) { noPrivileges = false; noUGC = false; } #endif if(noUGC) { pClass->setVisible( true ); pClass->m_bIgnoreInput=false; int messageText = IDS_NO_USER_CREATED_CONTENT_PRIVILEGE_SINGLE_LOCAL; if(dwSignedInUsers > 1) messageText = IDS_NO_USER_CREATED_CONTENT_PRIVILEGE_ALL_LOCAL; ui.RequestUGCMessageBox(IDS_CONNECTION_FAILED, messageText); } else if(noPrivileges) { pClass->setVisible( true ); pClass->m_bIgnoreInput=false; UINT uiIDA[1]; uiIDA[0]=IDS_CONFIRM_OK; ui.RequestErrorMessage( IDS_NO_MULTIPLAYER_PRIVILEGE_TITLE, IDS_NO_MULTIPLAYER_PRIVILEGE_JOIN_TEXT, uiIDA,1,ProfileManager.GetPrimaryPad()); } else { #if defined(__ORBIS__) || defined(__PSVITA__) bool chatRestricted = false; ProfileManager.GetChatAndContentRestrictions(ProfileManager.GetPrimaryPad(),false,&chatRestricted,nullptr,nullptr); if(chatRestricted) { ProfileManager.DisplaySystemMessage( SCE_MSG_DIALOG_SYSMSG_TYPE_TRC_PSN_CHAT_RESTRICTION, ProfileManager.GetPrimaryPad() ); } #endif CGameNetworkManager::eJoinGameResult result = g_NetworkManager.JoinGame( pClass->m_selectedSession, dwLocalUsersMask ); // Alert the app the we no longer want to be informed of ethernet connections app.SetLiveLinkRequired( false ); #if defined(_WINDOWS64) || defined(__linux__) if (result == CGameNetworkManager::JOINGAME_PENDING) { pClass->m_bIgnoreInput = false; ConnectionProgressParams *param = new ConnectionProgressParams(); param->iPad = ProfileManager.GetPrimaryPad(); param->stringId = IDS_PROGRESS_CONNECTING; param->showTooltips = true; param->setFailTimer = false; param->timerTime = 0; param->cancelFunc = nullptr; param->cancelFuncParam = nullptr; ui.NavigateToScene(ProfileManager.GetPrimaryPad(), eUIScene_ConnectingProgress, param); return; } #endif if( result != CGameNetworkManager::JOINGAME_SUCCESS ) { int exitReasonStringId = -1; switch(result) { case CGameNetworkManager::JOINGAME_FAIL_SERVER_FULL: exitReasonStringId = IDS_DISCONNECTED_SERVER_FULL; break; } if( exitReasonStringId == -1 ) { Minecraft* pMinecraft = Minecraft::GetInstance(); int primaryPad = ProfileManager.GetPrimaryPad(); if( pMinecraft->m_connectionFailed[primaryPad] ) { switch( pMinecraft->m_connectionFailedReason[primaryPad] ) { case DisconnectPacket::eDisconnect_LoginTooLong: exitReasonStringId = IDS_DISCONNECTED_LOGIN_TOO_LONG; break; case DisconnectPacket::eDisconnect_ServerFull: exitReasonStringId = IDS_DISCONNECTED_SERVER_FULL; break; case DisconnectPacket::eDisconnect_Kicked: exitReasonStringId = IDS_DISCONNECTED_KICKED; break; case DisconnectPacket::eDisconnect_NoUGC_AllLocal: exitReasonStringId = IDS_NO_USER_CREATED_CONTENT_PRIVILEGE_ALL_LOCAL; break; case DisconnectPacket::eDisconnect_NoUGC_Single_Local: exitReasonStringId = IDS_NO_USER_CREATED_CONTENT_PRIVILEGE_SINGLE_LOCAL; break; case DisconnectPacket::eDisconnect_NoFlying: exitReasonStringId = IDS_DISCONNECTED_FLYING; break; case DisconnectPacket::eDisconnect_Quitting: exitReasonStringId = IDS_DISCONNECTED_SERVER_QUIT; break; case DisconnectPacket::eDisconnect_OutdatedServer: exitReasonStringId = IDS_DISCONNECTED_SERVER_OLD; break; case DisconnectPacket::eDisconnect_OutdatedClient: exitReasonStringId = IDS_DISCONNECTED_CLIENT_OLD; break; default: exitReasonStringId = IDS_CONNECTION_LOST_SERVER; break; } } } if( exitReasonStringId == -1 ) { // No specific disconnect reason was set — the server was likely // unreachable. Show a "Connection Failed" dialog instead of // silently navigating back so the user knows what happened. exitReasonStringId = IDS_CONNECTION_LOST_SERVER; } { UINT uiIDA[1]; uiIDA[0]=IDS_CONFIRM_OK; ui.RequestErrorMessage( IDS_CONNECTION_FAILED, exitReasonStringId, uiIDA,1,ProfileManager.GetPrimaryPad()); pClass->m_bIgnoreInput = false; } } } } void UIScene_JoinMenu::handleTimerComplete(int id) { switch(id) { case UPDATE_PLAYERS_TIMER_ID: { #if TO_BE_IMPLEMENTED PlayerUID selectedPlayerXUID = m_selectedSession->data.players[playersList.GetCurSel()]; bool success = g_NetworkManager.GetGameSessionInfo(m_iPad, m_selectedSession->sessionId,m_selectedSession); if( success ) { playersList.DeleteItems(0, playersList.GetItemCount()); int selectedIndex = 0; for(unsigned int i = 0; i < MINECRAFT_NET_MAX_PLAYERS; ++i) { if( m_selectedSession->data.players[i] != nullptr ) { if(m_selectedSession->data.players[i] == selectedPlayerXUID) selectedIndex = i; playersList.InsertItems(i,1); #ifndef _CONTENT_PACKAGE if(app.DebugSettingsOn() && (app.GetGameSettingsDebugMask()&(1L<data.szPlayers[i] ).c_str() ); } } else { // Leave the loop when we hit the first nullptr player break; } } playersList.SetCurSel(selectedIndex); } #endif } break; }; }