User must now accept invite
parent
156bee1564
commit
8fe7c2267a
|
@ -1037,7 +1037,7 @@ void Callback(Common_Message *msg)
|
||||||
PRINT_DEBUG("Steam_Friends Got Lobby Invite\n");
|
PRINT_DEBUG("Steam_Friends Got Lobby Invite\n");
|
||||||
//TODO: the user should accept the invite first but we auto accept it because there's no gui yet
|
//TODO: the user should accept the invite first but we auto accept it because there's no gui yet
|
||||||
// Then we will handle it !
|
// Then we will handle it !
|
||||||
overlay->AddLobbyInvite(msg->source_id(), msg->friend_messages().lobby_id());
|
overlay->AddLobbyInvite(*find_friend(msg->source_id()), msg->friend_messages().lobby_id());
|
||||||
|
|
||||||
//GameLobbyJoinRequested_t data;
|
//GameLobbyJoinRequested_t data;
|
||||||
//data.m_steamIDLobby = CSteamID((uint64)msg->friend_messages().lobby_id());
|
//data.m_steamIDLobby = CSteamID((uint64)msg->friend_messages().lobby_id());
|
||||||
|
@ -1049,7 +1049,7 @@ void Callback(Common_Message *msg)
|
||||||
PRINT_DEBUG("Steam_Friends Got Game Invite\n");
|
PRINT_DEBUG("Steam_Friends Got Game Invite\n");
|
||||||
//TODO: I'm pretty sure that the user should accept the invite before this is posted but we do like above
|
//TODO: I'm pretty sure that the user should accept the invite before this is posted but we do like above
|
||||||
// Then we will handle it !
|
// Then we will handle it !
|
||||||
overlay->AddRichInvite(msg->source_id(), msg->friend_messages().connect_str().c_str());
|
overlay->AddRichInvite(*find_friend(msg->source_id()), msg->friend_messages().connect_str().c_str());
|
||||||
|
|
||||||
//std::string const& connect_str = msg->friend_messages().connect_str();
|
//std::string const& connect_str = msg->friend_messages().connect_str();
|
||||||
//GameRichPresenceJoinRequested_t data = {};
|
//GameRichPresenceJoinRequested_t data = {};
|
||||||
|
|
|
@ -95,7 +95,6 @@ Steam_Overlay::Steam_Overlay(Settings* settings, SteamCallResults* callback_resu
|
||||||
notif_position(ENotificationPosition::k_EPositionBottomLeft),
|
notif_position(ENotificationPosition::k_EPositionBottomLeft),
|
||||||
h_inset(0),
|
h_inset(0),
|
||||||
v_inset(0),
|
v_inset(0),
|
||||||
friend_action(friend_action_none),
|
|
||||||
overlay_state_changed(false)
|
overlay_state_changed(false)
|
||||||
{
|
{
|
||||||
run_every_runcb->add(&Steam_Overlay::steam_overlay_run_every_runcb, this);
|
run_every_runcb->add(&Steam_Overlay::steam_overlay_run_every_runcb, this);
|
||||||
|
@ -231,28 +230,34 @@ void Steam_Overlay::ShowOverlay(bool state)
|
||||||
overlay_state_changed = true;
|
overlay_state_changed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Steam_Overlay::AddLobbyInvite(uint64 friendId, uint64 lobbyId)
|
void Steam_Overlay::AddLobbyInvite(Friend friendId, uint64 lobbyId)
|
||||||
{
|
{
|
||||||
invitation invite;
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
||||||
invite.type = invitation_type_lobby;
|
auto i = friends.find(friendId);
|
||||||
invite.friendId = friendId;
|
if (i != friends.end())
|
||||||
invite.lobbyId = lobbyId;
|
{
|
||||||
invitations.push_back(invite);
|
auto& frd = i->second;
|
||||||
|
frd.lobbyId = lobbyId;
|
||||||
|
frd.window_state |= window_state_lobby_invite;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Steam_Overlay::AddRichInvite(uint64 friendId, const char* connect_str)
|
void Steam_Overlay::AddRichInvite(Friend friendId, const char* connect_str)
|
||||||
{
|
{
|
||||||
invitation invite;
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
||||||
invite.type = invitation_type_rich;
|
auto i = friends.find(friendId);
|
||||||
invite.friendId = friendId;
|
if (i != friends.end())
|
||||||
strncpy(invite.connect, connect_str, k_cchMaxRichPresenceValueLength - 1);
|
{
|
||||||
invitations.push_back(invite);
|
auto& frd = i->second;
|
||||||
|
strncpy(frd.connect, connect_str, k_cchMaxRichPresenceValueLength - 1);
|
||||||
|
frd.window_state |= window_state_rich_invite;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Steam_Overlay::FriendConnect(Friend _friend)
|
void Steam_Overlay::FriendConnect(Friend _friend)
|
||||||
{
|
{
|
||||||
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
std::lock_guard<std::recursive_mutex> lock(global_mutex);
|
||||||
friends[_friend] = false;
|
friends[_friend].window_state = window_state_none;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Steam_Overlay::FriendDisconnect(Friend _friend)
|
void Steam_Overlay::FriendDisconnect(Friend _friend)
|
||||||
|
@ -296,29 +301,46 @@ void Steam_Overlay::OverlayProc( int width, int height )
|
||||||
{
|
{
|
||||||
if (ImGui::Button("Invite"))
|
if (ImGui::Button("Invite"))
|
||||||
{
|
{
|
||||||
this->friend_action |= friend_action_invite;
|
i.second.window_state |= window_state_invite;
|
||||||
this->friend_to_action = i.first.id();
|
this->has_friend_action.push(i.first);
|
||||||
}
|
}
|
||||||
if (ImGui::Button("Join"))
|
if (ImGui::Button("Join"))
|
||||||
{
|
{
|
||||||
this->friend_action |= friend_action_join;
|
i.second.window_state |= window_state_join;
|
||||||
this->friend_to_action = i.first.id();
|
this->has_friend_action.push(i.first);
|
||||||
}
|
}
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
//else if (ImGui::IsMouseDoubleClicked(0))
|
|
||||||
else if (ImGui::IsItemClicked() && ImGui::IsMouseDoubleClicked(0))
|
else if (ImGui::IsItemClicked() && ImGui::IsMouseDoubleClicked(0))
|
||||||
{
|
{
|
||||||
i.second = true;
|
i.second.window_state |= window_state_show;
|
||||||
}
|
}
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
|
|
||||||
if (i.second)
|
if (i.second.window_state & window_state_show)
|
||||||
{
|
{
|
||||||
if (ImGui::Begin(i.first.name().c_str(), &i.second))
|
bool show = true;
|
||||||
|
if (ImGui::Begin(i.first.name().c_str(), &show))
|
||||||
{
|
{
|
||||||
// Fill this with the chat box and maybe the invitation
|
// Fill this with the chat box and maybe the invitation
|
||||||
|
if (i.second.window_state & (window_state_lobby_invite | window_state_rich_invite))
|
||||||
|
{
|
||||||
|
ImGui::LabelText("", "%s invited you to join the game.", i.first.name().c_str());
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button("Accept"))
|
||||||
|
{
|
||||||
|
this->has_friend_action.push(i.first);
|
||||||
}
|
}
|
||||||
|
ImGui::SameLine();
|
||||||
|
if (ImGui::Button("Refuse"))
|
||||||
|
{
|
||||||
|
i.second.window_state &= ~(window_state_lobby_invite | window_state_rich_invite);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// User closed the friend window
|
||||||
|
if( !show )
|
||||||
|
i.second.window_state &= ~window_state_show;
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -351,35 +373,65 @@ void Steam_Overlay::RunCallbacks()
|
||||||
Steam_Friends* steamFriends = get_steam_client()->steam_friends;
|
Steam_Friends* steamFriends = get_steam_client()->steam_friends;
|
||||||
Steam_Matchmaking* steamMatchmaking = get_steam_client()->steam_matchmaking;
|
Steam_Matchmaking* steamMatchmaking = get_steam_client()->steam_matchmaking;
|
||||||
|
|
||||||
if (friend_action & friend_action_invite)
|
while (!has_friend_action.empty())
|
||||||
|
{
|
||||||
|
auto friend_info = friends.find(has_friend_action.front());
|
||||||
|
if (friend_info != friends.end())
|
||||||
|
{
|
||||||
|
uint64 friend_id = friend_info->first.id();
|
||||||
|
// The user clicked on "Invite"
|
||||||
|
if (friend_info->second.window_state & window_state_invite)
|
||||||
{
|
{
|
||||||
std::string connect = steamFriends->GetFriendRichPresence(settings->get_local_steam_id(), "connect");
|
std::string connect = steamFriends->GetFriendRichPresence(settings->get_local_steam_id(), "connect");
|
||||||
if (connect.length() > 0)
|
if (connect.length() > 0)
|
||||||
steamFriends->InviteUserToGame(friend_to_action, connect.c_str());
|
steamFriends->InviteUserToGame(friend_id, connect.c_str());
|
||||||
else if(settings->get_lobby().IsValid())
|
else if (settings->get_lobby().IsValid())
|
||||||
steamMatchmaking->InviteUserToLobby(settings->get_lobby(), friend_to_action);
|
steamMatchmaking->InviteUserToLobby(settings->get_lobby(), friend_id);
|
||||||
|
|
||||||
friend_action &= ~friend_action_invite;
|
friend_info->second.window_state &= ~window_state_invite;
|
||||||
}
|
}
|
||||||
|
// The user clicked on "Join"
|
||||||
if (friend_action & friend_action_join)
|
if (friend_info->second.window_state & window_state_join)
|
||||||
{
|
{
|
||||||
std::string connect = steamFriends->GetFriendRichPresence(friend_to_action, "connect");
|
std::string connect = steamFriends->GetFriendRichPresence(friend_id, "connect");
|
||||||
if (connect.length() > 0)
|
if (connect.length() > 0)
|
||||||
{
|
{
|
||||||
GameRichPresenceJoinRequested_t data = {};
|
GameRichPresenceJoinRequested_t data = {};
|
||||||
data.m_steamIDFriend.SetFromUint64(friend_to_action);
|
data.m_steamIDFriend.SetFromUint64(friend_id);
|
||||||
strncpy(data.m_rgchConnect, connect.c_str(), k_cchMaxRichPresenceValueLength - 1);
|
strncpy(data.m_rgchConnect, connect.c_str(), k_cchMaxRichPresenceValueLength - 1);
|
||||||
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
FriendGameInfo_t friend_info = {};
|
FriendGameInfo_t friend_game_info = {};
|
||||||
steamFriends->GetFriendGamePlayed(friend_to_action, &friend_info);
|
steamFriends->GetFriendGamePlayed(friend_id, &friend_game_info);
|
||||||
if(friend_info.m_steamIDLobby.IsValid())
|
if (friend_game_info.m_steamIDLobby.IsValid())
|
||||||
steamMatchmaking->JoinLobby(friend_info.m_steamIDLobby);
|
steamMatchmaking->JoinLobby(friend_game_info.m_steamIDLobby);
|
||||||
}
|
}
|
||||||
|
|
||||||
friend_action &= ~friend_action_join;
|
friend_info->second.window_state &= ~window_state_join;
|
||||||
|
}
|
||||||
|
// The user got a lobby invite and accepeted it
|
||||||
|
if (friend_info->second.window_state & window_state_lobby_invite)
|
||||||
|
{
|
||||||
|
GameLobbyJoinRequested_t data;
|
||||||
|
data.m_steamIDLobby.SetFromUint64(friend_info->second.lobbyId);
|
||||||
|
data.m_steamIDFriend.SetFromUint64(friend_id);
|
||||||
|
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
||||||
|
|
||||||
|
friend_info->second.window_state &= ~window_state_lobby_invite;
|
||||||
|
}
|
||||||
|
// The user got a rich presence invite and accepeted it
|
||||||
|
if (friend_info->second.window_state & window_state_rich_invite)
|
||||||
|
{
|
||||||
|
GameRichPresenceJoinRequested_t data = {};
|
||||||
|
data.m_steamIDFriend.SetFromUint64(friend_id);
|
||||||
|
strncpy(data.m_rgchConnect, friend_info->second.connect, k_cchMaxRichPresenceValueLength - 1);
|
||||||
|
callbacks->addCBResult(data.k_iCallback, &data, sizeof(data));
|
||||||
|
|
||||||
|
friend_info->second.window_state &= ~window_state_rich_invite;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
has_friend_action.pop();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -4,25 +4,21 @@
|
||||||
#include "../dll/base.h"
|
#include "../dll/base.h"
|
||||||
#include "Hook_Manager.h"
|
#include "Hook_Manager.h"
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <queue>
|
||||||
|
|
||||||
enum friend_action
|
enum window_state
|
||||||
{
|
{
|
||||||
friend_action_none = 0,
|
window_state_none = 0,
|
||||||
friend_action_invite = 1<<0,
|
window_state_show = 1<<0,
|
||||||
friend_action_join = 1<<1
|
window_state_invite = 1<<1,
|
||||||
|
window_state_join = 1<<2,
|
||||||
|
window_state_lobby_invite = 1<<3,
|
||||||
|
window_state_rich_invite = 1<<4
|
||||||
};
|
};
|
||||||
|
|
||||||
enum invitation_type
|
struct friend_window_state
|
||||||
{
|
{
|
||||||
invitation_type_lobby,
|
uint8 window_state;
|
||||||
invitation_type_rich
|
|
||||||
};
|
|
||||||
|
|
||||||
struct invitation
|
|
||||||
{
|
|
||||||
uint8 type;
|
|
||||||
uint64 friendId;
|
|
||||||
union
|
union
|
||||||
{
|
{
|
||||||
uint64 lobbyId;
|
uint64 lobbyId;
|
||||||
|
@ -47,7 +43,7 @@ class Steam_Overlay
|
||||||
Networking* network;
|
Networking* network;
|
||||||
|
|
||||||
// friend id, show client window (to chat and accept invite maybe)
|
// friend id, show client window (to chat and accept invite maybe)
|
||||||
std::map<Friend, bool, Friend_Less> friends;
|
std::map<Friend, friend_window_state, Friend_Less> friends;
|
||||||
|
|
||||||
HWND game_hwnd;
|
HWND game_hwnd;
|
||||||
WNDPROC game_hwnd_proc;
|
WNDPROC game_hwnd_proc;
|
||||||
|
@ -57,11 +53,8 @@ class Steam_Overlay
|
||||||
ENotificationPosition notif_position;
|
ENotificationPosition notif_position;
|
||||||
int h_inset, v_inset;
|
int h_inset, v_inset;
|
||||||
|
|
||||||
std::vector<invitation> invitations;
|
|
||||||
|
|
||||||
// Callback infos
|
// Callback infos
|
||||||
uint64 friend_to_action;
|
std::queue<Friend> has_friend_action;
|
||||||
int friend_action;
|
|
||||||
bool overlay_state_changed;
|
bool overlay_state_changed;
|
||||||
|
|
||||||
Steam_Overlay(Steam_Overlay const&) = delete;
|
Steam_Overlay(Steam_Overlay const&) = delete;
|
||||||
|
@ -104,8 +97,8 @@ public:
|
||||||
|
|
||||||
void ShowOverlay(bool state);
|
void ShowOverlay(bool state);
|
||||||
|
|
||||||
void AddLobbyInvite(uint64 friendId, uint64 lobbyId);
|
void AddLobbyInvite(Friend friendId, uint64 lobbyId);
|
||||||
void AddRichInvite(uint64 friendId, const char* connect_str);
|
void AddRichInvite(Friend friendId, const char* connect_str);
|
||||||
|
|
||||||
void FriendConnect(Friend _friend);
|
void FriendConnect(Friend _friend);
|
||||||
void FriendDisconnect(Friend _friend);
|
void FriendDisconnect(Friend _friend);
|
||||||
|
|
Loading…
Reference in New Issue