Compare commits

..

No commits in common. "7424dfbd46bdb8f0eca5e4a705668132e1cbad81" and "19d2d6d33424fb7e0a8782d13300cf05ce6e8877" have entirely different histories.

3 changed files with 15 additions and 86 deletions

Binary file not shown.

View file

@ -62,10 +62,6 @@ int pendingAuthTries = 3;
Socket g_socket;
int g_lastPayloadSent;
char gameVersion[32];
int gameAppId;
enum AuthState {
Auth_Fail = -1,
Auth_Inactive,
@ -85,14 +81,13 @@ enum GameState {
State_None,
State_Transitioning = 1,
State_Hibernating = 2,
State_NewGame = 3,
State_EndGame = 4
State_NewGame = 3
}
enum PanelSettings {
Setting_None = 0,
Setting_DisableWithNoViewers = 1
}
GameState g_gameState = State_None;
GameState g_gameState = State_Hibernating;
#define BUFFER_SIZE 2048
Buffer sendBuffer;
Buffer receiveBuffer; // Unfortunately there's no easy way to have this not be the same as BUFFER_SIZE
@ -177,8 +172,6 @@ public void OnPluginStart() {
CommandArgRegex = new Regex("(?:[^\\s\"]+|\"[^\"]*\")+", 0);
CreateTimer(300.0, Timer_FullSync, _, TIMER_REPEAT);
FindGameVersion();
}
bool ConnectDB() {
char error[255];
@ -232,7 +225,6 @@ void SetupUserInDB(int client) {
void DBCT_PanelUser(Database db, DBResultSet results, const char[] error, int userId) {
if(db == null || results == null) {
LogError("DBCT_Insert returned error: %s", error);
return;
}
int client = GetClientOfUserId(userId);
if(client > 0) {
@ -260,7 +252,6 @@ void DBCT_CheckUserName(Database db, DBResultSet results, const char[] error, in
if(results.FetchRow()) {
if(nameCache[client][0] == '\0') {
LogError("DBCT_CheckUserName user %N(#%d) missing namecache", client, userId);
return;
}
char prevName[64];
results.FetchString(0, prevName, sizeof(prevName));
@ -324,11 +315,6 @@ void OnSocketError(Socket socket, int errorType, int errorNumber, int attempt) {
g_socket.SetArg(attempt + 1);
CreateTimer(nextAttempt, Timer_Reconnect);
}
if(authState == Auth_PendingResponse) {
Debug("Got socket error on auth?, retry");
g_socket.SetArg(attempt + 1);
ConnectSocket(false, attempt);
}
}
bool SendFullSync() {
@ -613,7 +599,7 @@ public void L4D_OnServerHibernationUpdate(bool hibernating) {
if(hibernating) {
g_gameState = State_Hibernating;
PrintToServer("[AdminPanel] Server is hibernating, disconnecting from socket");
// hibernateTimer = CreateTimer(30.0, Timer_Wake, 0, TIMER_REPEAT);
hibernateTimer = CreateTimer(30.0, Timer_Wake, 0, TIMER_REPEAT);
} else {
g_gameState = State_None;
PrintToServer("[AdminPanel] Server is not hibernating");
@ -663,26 +649,15 @@ Action Timer_Reconnect(Handle h, int type) {
}
bool ConnectSocket(bool force = false, int authTry = 0) {
if(g_gameState == State_Hibernating) {
Debug("ConnectSocket: Server is hibernating, ignoring");
return false;
} else if(g_socket == null) {
LogError("Socket is invalid");
return false;
} else if(g_socket.Connected) {
Debug("ConnectSocket: Already connected, disconnecting...");
if(g_socket == null) LogError("Socket is invalid");
if(g_socket.Connected) {
Debug("Already connected, disconnecting...");
g_socket.Disconnect();
authState = Auth_Inactive;
}
if(authToken[0] == '\0') {
LogError("ConnectSocket() called with no auth token");
return false;
}
if(authToken[0] == '\0') LogError("ConnectSocket() called with no auth token");
// Do not try to reconnect on auth failure, until token has changed
if(!force && authState == Auth_Fail) {
Debug("ConnectSocket: Ignoring request, auth failed");
return false;
}
if(!force && authState == Auth_Fail) return false;
authState = Auth_Pending;
g_socket.Connect(OnSocketConnect, OnSocketReceive, OnSocketDisconnect, serverIp, serverPort);
CreateTimer(10.0, Timer_ConnectTimeout, authTry);
@ -812,17 +787,7 @@ void Event_GameStart(Event event, const char[] name, bool dontBroadcast) {
}
void Event_GameEnd(Event event, const char[] name, bool dontBroadcast) {
campaignStartTime = 0;
g_gameState = State_EndGame;
if(StartPayload(true)) {
AddGameRecord();
int stage = L4D2_GetCurrentFinaleStage();
if(stage != 0)
AddFinaleRecord(stage);
SendPayload();
// Resend all players
SendPlayers();
}
CreateTimer(10.0, Timer_FullSync);
}
void Event_MapTransition(Event event, const char[] name, bool dontBroadcast) {
@ -1274,7 +1239,6 @@ bool pendingRecord;
void StartPayloadEx() {
if(pendingRecord) {
LogError("StartPayloadEx called before EndRecord()");
return;
}
sendBuffer.Reset();
hasRecord = false;
@ -1288,7 +1252,6 @@ void StartPayloadEx() {
void StartRecord(LiveRecordType type) {
if(pendingRecord) {
LogError("StartRecord called before EndRecord()");
return;
}
if(hasRecord) {
sendBuffer.WriteChar('\x1e');
@ -1366,10 +1329,7 @@ void AddSurvivorRecord(int client) {
if(isL4D1Survivors) {
survivor += 4;
}
if(survivor >= 8) {
LogError("invalid survivor %d", survivor);
return;
}
if(survivor >= 8) LogError("invalid survivor %d", survivor);
StartRecord(Live_Survivor);
sendBuffer.WriteInt(userid);
@ -1427,14 +1387,11 @@ void AddCommandResponseRecord(int id, CommandResultType resultType = Result_None
void AddAuthRecord() {
if(authToken[0] == '\0') {
LogError("AddAuthRecord called with missing auth token");
return;
}
StartRecord(Live_Auth);
sendBuffer.WriteByte(LIVESTATUS_VERSION);
sendBuffer.WriteString(authToken);
sendBuffer.WriteShort(cvar_hostPort.IntValue);
sendBuffer.WriteString(gameVersion);
// gameAppId?
sendBuffer.WriteInt(cvar_hostPort.IntValue);
EndRecord();
}
@ -1581,31 +1538,3 @@ int GetMaxPlayers() {
if(cvar_maxplayers != null) return cvar_maxplayers.IntValue;
return L4D_IsVersusMode() ? 8 : 4;
}
void FindGameVersion() {
char path[PLATFORM_MAX_PATH];
File file = OpenFile("steam.inf", "r");
if (file == null) {
LogError("Could not open steam.inf file to get game version");
return;
}
char line[255];
while (!IsEndOfFile(file) && file.ReadLine(line, sizeof(line))) {
TrimString(line);
if (StrContains(line, "appID=") != -1)
{
ReplaceString(line, sizeof(line), "appID=", "");
ReplaceString(line, sizeof(line), ".", "");
gameAppId = StringToInt(line);
}
else if (StrContains(line, "PatchVersion=") != -1)
{
ReplaceString(line, sizeof(line), "PatchVersion=", "");
ReplaceString(line, sizeof(line), ".", "");
strcopy(gameVersion, sizeof(gameVersion), line);
}
}
delete file;
}