Merge branch 'master' of github.com:Jackzmc/sourcemod-plugins

This commit is contained in:
Jackzie 2024-09-22 14:28:30 -05:00
commit 9bfb1e4787

View file

@ -236,7 +236,7 @@ void OnSocketReceive(Socket socket, const char[] receiveData, int dataSize, int
int client = GetClientOfUserId(userid); int client = GetClientOfUserId(userid);
if(client > 0 && StartPayload(true)) { if(client > 0 && StartPayload(true)) {
PrintToServer("[AdminPanel] Sync requested for #%d, performing", userid); PrintToServer("[AdminPanel] Sync requested for #%d, performing", userid);
AddPlayerRecord(client); AddPlayerRecord(client, Client_Normal);
SendPayload(); SendPayload();
} }
} else { } else {
@ -626,8 +626,8 @@ public void Event_BotToPlayer(Handle event, char[] name, bool dontBroadcast) {
int bot = GetClientOfUserId(GetEventInt(event, "bot")); int bot = GetClientOfUserId(GetEventInt(event, "bot"));
if(player > 0 && !IsFakeClient(player) && StartPayload(true)) { if(player > 0 && !IsFakeClient(player) && StartPayload(true)) {
// Bot is going away, remove it: (prob unnecessary OnClientDisconnect happens) // Bot is going away, remove it: (prob unnecessary OnClientDisconnect happens)
AddPlayerRecord(bot, false); AddPlayerRecord(bot, Client_Disconnected);
AddPlayerRecord(player); AddPlayerRecord(player, Client_Normal);
SendPayload(); SendPayload();
} }
} }
@ -657,7 +657,7 @@ void Event_PlayerSpawn(Event event, const char[] name, bool dontBroadcast) {
RecalculatePlayerCount(); RecalculatePlayerCount();
int client = GetClientOfUserId(event.GetInt("userid")); int client = GetClientOfUserId(event.GetInt("userid"));
if(client > 0 && StartPayload()) { if(client > 0 && StartPayload()) {
AddPlayerRecord(client); AddPlayerRecord(client, Client_Normal);
SendPayload(); SendPayload();
} }
} }
@ -676,7 +676,7 @@ void SendPlayers() {
for(int i = 1; i <= MaxClients; i++) { for(int i = 1; i <= MaxClients; i++) {
if(IsClientInGame(i)) { if(IsClientInGame(i)) {
if(StartPayload(true)) { if(StartPayload(true)) {
AddPlayerRecord(i); AddPlayerRecord(i, Client_Normal);
SendPayload(); SendPayload();
} }
} }
@ -805,7 +805,7 @@ void SendNewClient(int client) {
if(!IsClientInGame(client)) return; if(!IsClientInGame(client)) return;
if(StartPayload()) { if(StartPayload()) {
PrintToServer("SendNewClient(%N)", client); PrintToServer("SendNewClient(%N)", client);
AddPlayerRecord(client); AddPlayerRecord(client, Client_Connected);
SendPayload(); SendPayload();
} }
} }
@ -813,7 +813,7 @@ void SendNewClient(int client) {
public void OnClientDisconnect(int client) { public void OnClientDisconnect(int client) {
if(StartPayload()) { if(StartPayload()) {
// hopefully userid is valid here? // hopefully userid is valid here?
AddPlayerRecord(client, false); AddPlayerRecord(client, Client_Disconnected);
SendPayload(); SendPayload();
} }
steamidCache[client][0] = '\0'; steamidCache[client][0] = '\0';
@ -931,27 +931,27 @@ int GetPlayerMovement(int client) {
// TODO: pursued by witch // TODO: pursued by witch
enum { enum {
pState_BlackAndWhite = 1, sState_BlackAndWhite = 1,
pState_InSaferoom = 2, sState_InSaferoom = 2,
pState_IsCalm = 4, sState_IsCalm = 4,
pState_IsBoomed = 8, sState_IsBoomed = 8,
pState_IsPinned = 16, sState_IsPinned = 16,
pState_IsAlive = 32, sState_IsAlive = 32,
} }
stock bool IsPlayerBoomed(int client) { stock bool IsPlayerBoomed(int client) {
return (GetEntPropFloat(client, Prop_Send, "m_vomitStart") + 20.1) > GetGameTime(); return (GetEntPropFloat(client, Prop_Send, "m_vomitStart") + 20.1) > GetGameTime();
} }
int GetPlayerStates(int client) { int GetSurvivorStates(int client) {
int state = 0; int state = 0;
if(L4D_IsInLastCheckpoint(client) || L4D_IsInFirstCheckpoint(client)) if(L4D_IsInLastCheckpoint(client) || L4D_IsInFirstCheckpoint(client))
state |= pState_InSaferoom; state |= sState_InSaferoom;
if(GetEntProp(client, Prop_Send, "m_bIsOnThirdStrike", 1)) state |= pState_BlackAndWhite; if(GetEntProp(client, Prop_Send, "m_bIsOnThirdStrike", 1)) state |= sState_BlackAndWhite;
if(GetEntProp(client, Prop_Send, "m_isCalm")) state |= pState_IsCalm; if(GetEntProp(client, Prop_Send, "m_isCalm")) state |= sState_IsCalm;
if(IsPlayerBoomed(client)) state |= pState_IsBoomed; if(IsPlayerBoomed(client)) state |= sState_IsBoomed;
if(IsPlayerAlive(client)) state |= pState_IsAlive; if(IsPlayerAlive(client)) state |= sState_IsAlive;
if(L4D2_GetInfectedAttacker(client) > 0) state |= pState_IsPinned; if(L4D2_GetInfectedAttacker(client) > 0) state |= sState_IsPinned;
return state; return state;
} }
@ -972,6 +972,13 @@ enum CommandResultType {
Result_Float Result_Float
} }
enum ClientState {
Client_Normal = 0,
Client_Connected = 1,
Client_Disconnected = 2,
Client_Idle = 3
}
enum LiveRecordType { enum LiveRecordType {
Live_Game = 0, Live_Game = 0,
Live_Player = 1, Live_Player = 1,
@ -1088,29 +1095,27 @@ void AddFinaleRecord(int stage) {
EndRecord(); EndRecord();
} }
void AddPlayerRecord(int client, bool connected = true) { void AddPlayerRecord(int client, ClientState state) {
// fake bots are ignored: // fake bots are ignored:
if(steamidCache[client][0] == '\0') return; if(steamidCache[client][0] == '\0') return;
bool isIdle = false;
StartRecord(Live_Player); StartRecord(Live_Player);
sendBuffer.WriteInt(GetClientUserId(client)); sendBuffer.WriteInt(GetClientUserId(client));
sendBuffer.WriteString(steamidCache[client]); sendBuffer.WriteString(steamidCache[client]);
if(connected) { sendBuffer.WriteByte(state);
sendBuffer.WriteByte(isIdle); sendBuffer.WriteInt(state == Client_Disconnected ? GetTime() : playerJoinTime[client]);
sendBuffer.WriteInt(playerJoinTime[client]); sendBuffer.WriteString(nameCache[client]);
sendBuffer.WriteString(nameCache[client]); EndRecord();
EndRecord();
if(state != Client_Disconnected) {
if(GetClientTeam(client) == 2) { if(GetClientTeam(client) == 2) {
AddSurvivorRecord(client); AddSurvivorRecord(client);
AddSurvivorItemsRecord(client); AddSurvivorItemsRecord(client);
} else if(GetClientTeam(client) == 3) { } else if(GetClientTeam(client) == 3) {
AddInfectedRecord(client); AddInfectedRecord(client);
} }
} else {
EndRecord();
} }
} }
void AddSurvivorRecord(int client) { void AddSurvivorRecord(int client) {
@ -1134,7 +1139,7 @@ void AddSurvivorRecord(int client) {
int health = IsPlayerAlive(client) ? GetEntProp(client, Prop_Send, "m_iHealth"): 0; int health = IsPlayerAlive(client) ? GetEntProp(client, Prop_Send, "m_iHealth"): 0;
sendBuffer.WriteByte(health); //perm health sendBuffer.WriteByte(health); //perm health
sendBuffer.WriteByte(L4D2_GetVersusCompletionPlayer(client)); // flow% sendBuffer.WriteByte(L4D2_GetVersusCompletionPlayer(client)); // flow%
sendBuffer.WriteInt(GetPlayerStates(client)); // state (incl. alive) sendBuffer.WriteInt(GetSurvivorStates(client)); // state (incl. alive)
sendBuffer.WriteInt(GetPlayerMovement(client)); // move sendBuffer.WriteInt(GetPlayerMovement(client)); // move
sendBuffer.WriteInt(GetAction(client)); // action sendBuffer.WriteInt(GetAction(client)); // action
EndRecord(); EndRecord();