Join lobby on startup

This commit is contained in:
Atlante45 2016-07-29 13:34:10 -07:00
parent 6b861e680f
commit 7ec2f98cf2
3 changed files with 42 additions and 21 deletions

View file

@ -3224,6 +3224,14 @@ void Application::init() {
addressLookupString = arguments().value(urlIndex + 1);
}
// when +connect_lobby in command line, join steam lobby
const QString STEAM_LOBBY_COMMAND_LINE_KEY = "+connect_lobby";
int lobbyIndex = arguments().indexOf(STEAM_LOBBY_COMMAND_LINE_KEY);
if (lobbyIndex != -1) {
QString lobbyId = arguments().value(lobbyIndex + 1);
SteamClient::joinLobby(lobbyId);
}
Setting::Handle<bool> firstRun { Settings::firstRun, true };
if (addressLookupString.isEmpty() && firstRun.get()) {
qDebug() << "First run and no URL passed... attempting to go to Home or Entry...";

View file

@ -165,9 +165,7 @@ SteamCallbackManager::SteamCallbackManager() :
{
}
void SteamCallbackManager::onGameRichPresenceJoinRequested(GameRichPresenceJoinRequested_t* pCallback) {
auto url = QString::fromLocal8Bit(pCallback->m_rgchConnect);
void parseUrlAndGo(QString url) {
if (url.startsWith(CONNECT_PREFIX) && url.endsWith(CONNECT_SUFFIX)) {
url.remove(0, CONNECT_PREFIX.size());
url.remove(-CONNECT_SUFFIX.size(), CONNECT_SUFFIX.size());
@ -176,40 +174,50 @@ void SteamCallbackManager::onGameRichPresenceJoinRequested(GameRichPresenceJoinR
qDebug() << "Joining Steam Friend at:" << url;
auto mimeData = new QMimeData();
mimeData->setUrls(QList<QUrl>() << QUrl(url));
auto event = new QDropEvent(QPointF(0,0), Qt::MoveAction, mimeData, Qt::LeftButton, Qt::NoModifier);
auto event = new QDropEvent(QPointF(0, 0), Qt::MoveAction, mimeData, Qt::LeftButton, Qt::NoModifier);
QCoreApplication::postEvent(qApp, event);
}
void SteamCallbackManager::onGameRichPresenceJoinRequested(GameRichPresenceJoinRequested_t* pCallback) {
auto url = QString::fromLocal8Bit(pCallback->m_rgchConnect);
parseUrlAndGo(url);
}
void SteamCallbackManager::onLobbyCreated(LobbyCreated_t* pCallback) {
qDebug() << pCallback->m_eResult << pCallback->m_ulSteamIDLobby;
if (pCallback->m_eResult == k_EResultOK) {
qDebug() << "Inviting steam friends";
SteamMatchmaking()->SetLobbyData(pCallback->m_ulSteamIDLobby, "connect",
SteamFriends()->GetFriendRichPresence(SteamUser()->GetSteamID(), "connect"));
SteamMatchmaking()->SetLobbyMemberData(pCallback->m_ulSteamIDLobby,
"Creator", "true");
auto url = SteamFriends()->GetFriendRichPresence(SteamUser()->GetSteamID(), "connect");
SteamMatchmaking()->SetLobbyData(pCallback->m_ulSteamIDLobby, "connect", url);
SteamMatchmaking()->SetLobbyMemberData(pCallback->m_ulSteamIDLobby, "creator", "true");
SteamFriends()->ActivateGameOverlayInviteDialog(pCallback->m_ulSteamIDLobby);
}
}
void SteamCallbackManager::onGameLobbyJoinRequested(GameLobbyJoinRequested_t* pCallback) {
qDebug() << "onGameLobbyJoinRequested";
qDebug() << "Joining Steam lobby";
SteamMatchmaking()->JoinLobby(pCallback->m_steamIDLobby);
}
void SteamCallbackManager::onLobbyEnter(LobbyEnter_t* pCallback) {
qDebug() << "onLobbyEnter";
auto creator = SteamMatchmaking()->GetLobbyMemberData(pCallback->m_ulSteamIDLobby, SteamUser()->GetSteamID(), "creator");
if (strcmp(creator, "true") == 0) {
qDebug() << "Created lobby";
SteamMatchmaking()->LeaveLobby(pCallback->m_ulSteamIDLobby);
} else if (pCallback->m_EChatRoomEnterResponse == k_EChatRoomEnterResponseSuccess) {
qDebug() << "Success";
auto connectValue = SteamMatchmaking()->GetLobbyData(pCallback->m_ulSteamIDLobby, "connect");
qDebug() << connectValue;
if (pCallback->m_EChatRoomEnterResponse != k_EChatRoomEnterResponseSuccess) {
qWarning() << "An error occured while joing the Steam lobby:" << pCallback->m_EChatRoomEnterResponse;
return;
}
auto creator = SteamMatchmaking()->GetLobbyMemberData(pCallback->m_ulSteamIDLobby,
SteamUser()->GetSteamID(), "creator");
if (strcmp(creator, "true") != 0) {
auto url = SteamMatchmaking()->GetLobbyData(pCallback->m_ulSteamIDLobby, "connect");
parseUrlAndGo(url);
}
SteamMatchmaking()->LeaveLobby(pCallback->m_ulSteamIDLobby);
}
@ -218,9 +226,6 @@ static SteamCallbackManager steamCallbackManager;
bool SteamClient::isRunning() {
if (!initialized) {
init();
}
return initialized;
}
@ -292,3 +297,10 @@ void SteamClient::openInviteOverlay() {
static const int MAX_LOBBY_SIZE = 20;
SteamMatchmaking()->CreateLobby(k_ELobbyTypePrivate, MAX_LOBBY_SIZE);
}
void SteamClient::joinLobby(QString lobbyIdStr) {
qDebug() << "Trying to join Steam lobby:" << lobbyIdStr;
CSteamID lobbyId(lobbyIdStr.toULongLong());
SteamMatchmaking()->JoinLobby(lobbyId);
}

View file

@ -35,6 +35,7 @@ public:
static void requestTicket(TicketRequestCallback callback);
static void updateLocation(QString status, QUrl locationUrl);
static void openInviteOverlay();
static void joinLobby(QString lobbyId);
};