[Friends] Determine online status using a timestamp
This commit is contained in:
parent
358822d560
commit
b85dd9e3a1
@ -34,7 +34,7 @@ namespace Components
|
|||||||
for(auto entry : Friends::FriendsList)
|
for(auto entry : Friends::FriendsList)
|
||||||
{
|
{
|
||||||
if(!entry.online) offlineList.push_back(entry);
|
if(!entry.online) offlineList.push_back(entry);
|
||||||
else if(!entry.playing) onlineList.push_back(entry);
|
else if(!Friends::IsOnline(entry.lastTime)) onlineList.push_back(entry);
|
||||||
else if (entry.server.getType() == Game::NA_BAD) playingList.push_back(entry);
|
else if (entry.server.getType() == Game::NA_BAD) playingList.push_back(entry);
|
||||||
else connectedList.push_back(entry);
|
else connectedList.push_back(entry);
|
||||||
}
|
}
|
||||||
@ -66,7 +66,6 @@ namespace Components
|
|||||||
entry->name = Steam::Proxy::SteamFriends->GetFriendPersonaName(user);
|
entry->name = Steam::Proxy::SteamFriends->GetFriendPersonaName(user);
|
||||||
entry->playerName = Steam::Proxy::SteamFriends->GetFriendRichPresence(user, "iw4x_name");
|
entry->playerName = Steam::Proxy::SteamFriends->GetFriendRichPresence(user, "iw4x_name");
|
||||||
entry->online = Steam::Proxy::SteamFriends->GetFriendPersonaState(user) != 0;
|
entry->online = Steam::Proxy::SteamFriends->GetFriendPersonaState(user) != 0;
|
||||||
entry->playing = atoi(Steam::Proxy::SteamFriends->GetFriendRichPresence(user, "iw4x_playing")) == 1;
|
|
||||||
entry->guid.Bits = strtoull(Steam::Proxy::SteamFriends->GetFriendRichPresence(user, "iw4x_guid"), nullptr, 16);
|
entry->guid.Bits = strtoull(Steam::Proxy::SteamFriends->GetFriendRichPresence(user, "iw4x_guid"), nullptr, 16);
|
||||||
entry->experience = atoi(Steam::Proxy::SteamFriends->GetFriendRichPresence(user, "iw4x_experience"));
|
entry->experience = atoi(Steam::Proxy::SteamFriends->GetFriendRichPresence(user, "iw4x_experience"));
|
||||||
entry->prestige = atoi(Steam::Proxy::SteamFriends->GetFriendRichPresence(user, "iw4x_prestige"));
|
entry->prestige = atoi(Steam::Proxy::SteamFriends->GetFriendRichPresence(user, "iw4x_prestige"));
|
||||||
@ -74,6 +73,8 @@ namespace Components
|
|||||||
std::string server = Steam::Proxy::SteamFriends->GetFriendRichPresence(user, "iw4x_server");
|
std::string server = Steam::Proxy::SteamFriends->GetFriendRichPresence(user, "iw4x_server");
|
||||||
Network::Address oldAddress = entry->server;
|
Network::Address oldAddress = entry->server;
|
||||||
|
|
||||||
|
entry->lastTime = static_cast<unsigned int>(atoi(Steam::Proxy::SteamFriends->GetFriendRichPresence(user, "iw4x_playing")));
|
||||||
|
|
||||||
if (server.empty())
|
if (server.empty())
|
||||||
{
|
{
|
||||||
entry->server.setType(Game::NA_BAD);
|
entry->server.setType(Game::NA_BAD);
|
||||||
@ -155,7 +156,7 @@ namespace Components
|
|||||||
|
|
||||||
for (auto entry : Friends::FriendsList)
|
for (auto entry : Friends::FriendsList)
|
||||||
{
|
{
|
||||||
if (entry.guid.Bits == guid.Bits && entry.playing && entry.online)
|
if (entry.guid.Bits == guid.Bits && Friends::IsOnline(entry.lastTime) && entry.online)
|
||||||
{
|
{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -199,7 +200,7 @@ namespace Components
|
|||||||
Friends::Friend entry;
|
Friends::Friend entry;
|
||||||
entry.userId = id;
|
entry.userId = id;
|
||||||
entry.online = false;
|
entry.online = false;
|
||||||
entry.playing = false;
|
entry.lastTime = 0;
|
||||||
entry.prestige = 0;
|
entry.prestige = 0;
|
||||||
entry.experience = 0;
|
entry.experience = 0;
|
||||||
entry.server.setType(Game::NA_BAD);
|
entry.server.setType(Game::NA_BAD);
|
||||||
@ -265,7 +266,7 @@ namespace Components
|
|||||||
case 2:
|
case 2:
|
||||||
{
|
{
|
||||||
if (!user.online) return "Offline";
|
if (!user.online) return "Offline";
|
||||||
if (!user.playing) return "Online";
|
if (!Friends::IsOnline(user.lastTime)) return "Online";
|
||||||
if (user.server.getType() == Game::NA_BAD) return "Playing IW4x";
|
if (user.server.getType() == Game::NA_BAD) return "Playing IW4x";
|
||||||
if (user.serverName.empty()) return Utils::String::VA("Playing on %s", user.server.getCString());
|
if (user.serverName.empty()) return Utils::String::VA("Playing on %s", user.server.getCString());
|
||||||
return Utils::String::VA("Playing on %s", user.serverName.data());
|
return Utils::String::VA("Playing on %s", user.serverName.data());
|
||||||
@ -299,6 +300,16 @@ namespace Components
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Friends::UpdateTimeStamp()
|
||||||
|
{
|
||||||
|
Friends::SetPresence("iw4x_playing", Utils::String::VA("%d", Steam::Proxy::SteamUtils->GetServerRealTime()));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Friends::IsOnline(unsigned int ts)
|
||||||
|
{
|
||||||
|
return (Steam::Proxy::SteamUtils && ((Steam::Proxy::SteamUtils->GetServerRealTime() - ts) <= 5 * 60)); // % minutes
|
||||||
|
}
|
||||||
|
|
||||||
Friends::Friends()
|
Friends::Friends()
|
||||||
{
|
{
|
||||||
// Callback to update user information
|
// Callback to update user information
|
||||||
@ -374,12 +385,23 @@ namespace Components
|
|||||||
Friends::InitialState = Steam::Proxy::SteamLegacyFriends->GetPersonaState();
|
Friends::InitialState = Steam::Proxy::SteamLegacyFriends->GetPersonaState();
|
||||||
}
|
}
|
||||||
|
|
||||||
Friends::SetPresence("iw4x_playing", "1");
|
|
||||||
Friends::SetPresence("iw4x_guid", Utils::String::VA("%llX", Steam::SteamUser()->GetSteamID().Bits));
|
Friends::SetPresence("iw4x_guid", Utils::String::VA("%llX", Steam::SteamUser()->GetSteamID().Bits));
|
||||||
//Friends::UpdateState(); // Don't update state yet, stats will do that
|
//Friends::UpdateState(); // Don't update state yet, stats will do that
|
||||||
|
Friends::UpdateTimeStamp();
|
||||||
Friends::UpdateFriends();
|
Friends::UpdateFriends();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QuickPatch::OnFrame([]()
|
||||||
|
{
|
||||||
|
static Utils::Time::Interval interval;
|
||||||
|
|
||||||
|
if(interval.elapsed(2min))
|
||||||
|
{
|
||||||
|
interval.update();
|
||||||
|
Friends::UpdateTimeStamp();
|
||||||
|
Friends::UpdateState();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Friends::~Friends()
|
Friends::~Friends()
|
||||||
|
@ -44,7 +44,7 @@ namespace Components
|
|||||||
Network::Address server;
|
Network::Address server;
|
||||||
std::string serverName;
|
std::string serverName;
|
||||||
bool online;
|
bool online;
|
||||||
bool playing;
|
unsigned int lastTime;
|
||||||
int experience;
|
int experience;
|
||||||
int prestige;
|
int prestige;
|
||||||
};
|
};
|
||||||
@ -69,5 +69,9 @@ namespace Components
|
|||||||
static unsigned int GetFriendCount();
|
static unsigned int GetFriendCount();
|
||||||
static const char* GetFriendText(unsigned int index, int column);
|
static const char* GetFriendText(unsigned int index, int column);
|
||||||
static void SelectFriend(unsigned int index);
|
static void SelectFriend(unsigned int index);
|
||||||
|
|
||||||
|
static void UpdateTimeStamp();
|
||||||
|
|
||||||
|
static bool IsOnline(unsigned int ts);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user