[Friends] Show playing iw4x state

This commit is contained in:
momo5502 2017-01-29 18:06:48 +01:00
parent 1e72fe51be
commit bb18fcc034
3 changed files with 46 additions and 11 deletions

View File

@ -24,6 +24,7 @@ namespace Components
{ {
std::lock_guard<std::recursive_mutex> _(Friends::Mutex); std::lock_guard<std::recursive_mutex> _(Friends::Mutex);
std::vector<Friends::Friend> connectedList;
std::vector<Friends::Friend> playingList; std::vector<Friends::Friend> playingList;
std::vector<Friends::Friend> onlineList; std::vector<Friends::Friend> onlineList;
std::vector<Friends::Friend> offlineList; std::vector<Friends::Friend> offlineList;
@ -32,14 +33,21 @@ namespace Components
for(auto entry : Friends::FriendsList) for(auto entry : Friends::FriendsList)
{ {
if(entry.online) if(entry.online)
{
if (entry.playing)
{ {
if (entry.server.getType() == Game::NA_BAD) if (entry.server.getType() == Game::NA_BAD)
{ {
onlineList.push_back(entry); playingList.push_back(entry);
} }
else else
{ {
playingList.push_back(entry); connectedList.push_back(entry);
}
}
else
{
onlineList.push_back(entry);
} }
} }
else else
@ -48,12 +56,14 @@ namespace Components
} }
} }
Friends::SortIndividualList(&connectedList);
Friends::SortIndividualList(&playingList); Friends::SortIndividualList(&playingList);
Friends::SortIndividualList(&onlineList); Friends::SortIndividualList(&onlineList);
Friends::SortIndividualList(&offlineList); Friends::SortIndividualList(&offlineList);
Friends::FriendsList.clear(); Friends::FriendsList.clear();
Utils::Merge(&Friends::FriendsList, connectedList);
Utils::Merge(&Friends::FriendsList, playingList); Utils::Merge(&Friends::FriendsList, playingList);
Utils::Merge(&Friends::FriendsList, onlineList); Utils::Merge(&Friends::FriendsList, onlineList);
Utils::Merge(&Friends::FriendsList, offlineList); Utils::Merge(&Friends::FriendsList, offlineList);
@ -72,6 +82,7 @@ namespace Components
*function.add_params() = "iw4x_status"; *function.add_params() = "iw4x_status";
*function.add_params() = "iw4x_rank"; *function.add_params() = "iw4x_rank";
*function.add_params() = "iw4x_server"; *function.add_params() = "iw4x_server";
*function.add_params() = "iw4x_playing";
IPCHandler::SendWorker("friends", function.SerializeAsString()); IPCHandler::SendWorker("friends", function.SerializeAsString());
} }
@ -196,7 +207,11 @@ namespace Components
case 2: case 2:
{ {
if(user.online && user.server.getType() != Game::NA_BAD) if(user.online)
{
if (user.playing)
{
if (user.server.getType() != Game::NA_BAD)
{ {
if (user.serverName.empty()) if (user.serverName.empty())
{ {
@ -207,10 +222,16 @@ namespace Components
return Utils::String::VA("Playing on %s", user.serverName.data()); return Utils::String::VA("Playing on %s", user.serverName.data());
} }
} }
else if(user.online) else
{
return "Playing IW4x";
}
}
else
{ {
return "Online"; return "Online";
} }
}
else else
{ {
return "Offline"; return "Offline";
@ -274,6 +295,10 @@ namespace Components
{ {
entry->playerName = value; entry->playerName = value;
} }
else if (key == "iw4x_playing")
{
entry->playing = atoi(value.data()) == 1;
}
else if (key == "iw4x_server") else if (key == "iw4x_server")
{ {
Network::Address oldAddress = entry->server; Network::Address oldAddress = entry->server;
@ -370,6 +395,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.prestige = 0; entry.prestige = 0;
entry.experience = 0; entry.experience = 0;
entry.server.setType(Game::NA_BAD); entry.server.setType(Game::NA_BAD);
@ -476,6 +502,13 @@ namespace Components
fInterface->map("nameResponse", Friends::NameResponse); fInterface->map("nameResponse", Friends::NameResponse);
fInterface->map("presenceResponse", Friends::PresenceResponse); fInterface->map("presenceResponse", Friends::PresenceResponse);
fInterface->map("infoResponse", Friends::InfoResponse); fInterface->map("infoResponse", Friends::InfoResponse);
Proto::IPC::Function function;
function.set_name("setPresence");
*function.add_params() = "iw4x_playing";
*function.add_params() = "1";
IPCHandler::SendWorker("friends", function.SerializeAsString());
} }
Friends::~Friends() Friends::~Friends()

View File

@ -40,6 +40,7 @@ namespace Components
Network::Address server; Network::Address server;
std::string serverName; std::string serverName;
bool online; bool online;
bool playing;
int experience; int experience;
int prestige; int prestige;
}; };

View File

@ -173,6 +173,7 @@ namespace Handlers
if(Steam::Proxy::SteamFriends) if(Steam::Proxy::SteamFriends)
{ {
Steam::Proxy::SteamFriends->SetRichPresence("iw4x_server", nullptr); Steam::Proxy::SteamFriends->SetRichPresence("iw4x_server", nullptr);
Steam::Proxy::SteamFriends->SetRichPresence("iw4x_playing", nullptr);
} }
if(Steam::Proxy::SteamLegacyFriends) if(Steam::Proxy::SteamLegacyFriends)