real gamer hours cat_name_ipc

This commit is contained in:
nullifiedcat 2017-07-30 23:26:40 +03:00
parent 0215156533
commit 4404e8393e
5 changed files with 33 additions and 5 deletions

View File

@ -37,7 +37,7 @@ public:
stream.open("cathook/chat-" + uname + ".log", std::ios::out | std::ios::app); stream.open("cathook/chat-" + uname + ".log", std::ios::out | std::ios::app);
} }
void log(const std::string& msg) { void log(const std::string& msg) {
if (stream.bad()) { if (stream.bad() or not stream.is_open()) {
logging::Info("[ERROR] RAIILog stream is bad!"); logging::Info("[ERROR] RAIILog stream is bad!");
open(); open();
return; return;

View File

@ -939,21 +939,25 @@ void CheckLivingSpace() {
} }
int count = 0; int count = 0;
unsigned highest = 0; unsigned highest = 0;
std::vector<unsigned> botlist {};
for (unsigned i = 1; i < cat_ipc::max_peers; i++) { for (unsigned i = 1; i < cat_ipc::max_peers; i++) {
if (!ipc::peer->memory->peer_data[i].free) { if (!ipc::peer->memory->peer_data[i].free) {
for (auto& k : players) { for (auto& k : players) {
if (ipc::peer->memory->peer_user_data[i].friendid && k == ipc::peer->memory->peer_user_data[i].friendid) { if (ipc::peer->memory->peer_user_data[i].friendid && k == ipc::peer->memory->peer_user_data[i].friendid) {
botlist.push_back(i);
count++; count++;
highest = i; highest = i;
} }
} }
} }
} }
if (ipc::peer->client_id != highest) return; if (ipc::peer->client_id == highest && count > int(wb_abandon_too_many_bots)) {
if (count > int(wb_abandon_too_many_bots)) {
static Timer timer {}; static Timer timer {};
if (timer.test_and_set(1000 * 5)) { if (timer.test_and_set(1000 * 5)) {
logging::Info("Found %d other bots in-game, abandoning.", count); logging::Info("Found %d other bots in-game, abandoning (%u)", count, ipc::peer->client_id);
for (auto i : botlist) {
logging::Info("-> Bot %d with ID %u", i, ipc::peer->memory->peer_user_data[i].friendid);
}
g_TFGCClientSystem->SendExitMatchmaking(true); g_TFGCClientSystem->SendExitMatchmaking(true);
} }
} }

View File

@ -311,9 +311,22 @@ bool StolenName(){
return false; return false;
} }
static CatVar ipc_name(CV_STRING, "name_ipc", "", "IPC Name");
const char* GetFriendPersonaName_hook(ISteamFriends* _this, CSteamID steamID) { const char* GetFriendPersonaName_hook(ISteamFriends* _this, CSteamID steamID) {
static const GetFriendPersonaName_t original = (GetFriendPersonaName_t)hooks::steamfriends.GetMethod(offsets::GetFriendPersonaName()); static const GetFriendPersonaName_t original = (GetFriendPersonaName_t)hooks::steamfriends.GetMethod(offsets::GetFriendPersonaName());
#if IPC_ENABLED
if (ipc::peer) {
static std::string namestr(ipc_name.GetString());
namestr.assign(ipc_name.GetString());
if (namestr.length() > 3) {
ReplaceString(namestr, "%%", std::to_string(ipc::peer->client_id));
return namestr.c_str();
}
}
#endif
// Check User settings if namesteal is allowed // Check User settings if namesteal is allowed
if (namesteal && steamID == g_ISteamUser->GetSteamID()) { if (namesteal && steamID == g_ISteamUser->GetSteamID()) {
@ -390,8 +403,10 @@ void FrameStageNotify_hook(void* _this, int stage) {
#if IPC_ENABLED #if IPC_ENABLED
static Timer ipc_timer {}; static Timer ipc_timer {};
if (ipc_timer.test_and_set(1000)) { if (ipc_timer.test_and_set(1000)) {
if (ipc::peer) if (ipc::peer) {
ipc::Heartbeat();
ipc::UpdateTemporaryData(); ipc::UpdateTemporaryData();
}
} }
#endif #endif
hacks::shared::autojoin::UpdateSearch(); hacks::shared::autojoin::UpdateSearch();

View File

@ -170,6 +170,12 @@ void StoreClientData() {
strncpy(data.name, g_ISteamFriends->GetPersonaName(), sizeof(data.name)); strncpy(data.name, g_ISteamFriends->GetPersonaName(), sizeof(data.name));
} }
void Heartbeat() {
user_data_s& data = peer->memory->peer_user_data[peer->client_id];
data.heartbeat = time(nullptr);
}
static CatVar ipc_update_list(CV_SWITCH, "ipc_update_list", "1", "IPC Auto-Ignore", "Automaticly assign playerstates for bots"); static CatVar ipc_update_list(CV_SWITCH, "ipc_update_list", "1", "IPC Auto-Ignore", "Automaticly assign playerstates for bots");
void UpdatePlayerlist() { void UpdatePlayerlist() {
if (peer && ipc_update_list) { if (peer && ipc_update_list) {

View File

@ -13,6 +13,7 @@
#include "beforecheaders.h" #include "beforecheaders.h"
#include "ipcb.hpp" #include "ipcb.hpp"
#include "pthread.h" #include "pthread.h"
#include <time.h>
#include "aftercheaders.h" #include "aftercheaders.h"
class CatCommand; class CatCommand;
@ -59,12 +60,14 @@ struct user_data_s {
int score; int score;
int last_score; int last_score;
int total_score; int total_score;
time_t heartbeat;
}; };
using peer_t = cat_ipc::Peer<server_data_s, user_data_s>; using peer_t = cat_ipc::Peer<server_data_s, user_data_s>;
extern peer_t* peer; extern peer_t* peer;
void Heartbeat();
void UpdateTemporaryData(); void UpdateTemporaryData();
void UpdateServerAddress(bool shutdown = false); void UpdateServerAddress(bool shutdown = false);
void StoreClientData(); void StoreClientData();