mirror of
https://github.com/Jackzmc/sourcemod-plugins.git
synced 2025-05-06 03:03:21 +00:00
Update adminpanel, socket inc
This commit is contained in:
parent
19d2d6d334
commit
7e6eb4ed4b
3 changed files with 73 additions and 11 deletions
Binary file not shown.
|
@ -62,6 +62,10 @@ int pendingAuthTries = 3;
|
||||||
|
|
||||||
Socket g_socket;
|
Socket g_socket;
|
||||||
int g_lastPayloadSent;
|
int g_lastPayloadSent;
|
||||||
|
|
||||||
|
char gameVersion[32];
|
||||||
|
int gameAppId;
|
||||||
|
|
||||||
enum AuthState {
|
enum AuthState {
|
||||||
Auth_Fail = -1,
|
Auth_Fail = -1,
|
||||||
Auth_Inactive,
|
Auth_Inactive,
|
||||||
|
@ -81,7 +85,8 @@ enum GameState {
|
||||||
State_None,
|
State_None,
|
||||||
State_Transitioning = 1,
|
State_Transitioning = 1,
|
||||||
State_Hibernating = 2,
|
State_Hibernating = 2,
|
||||||
State_NewGame = 3
|
State_NewGame = 3,
|
||||||
|
State_EndGame = 4
|
||||||
}
|
}
|
||||||
enum PanelSettings {
|
enum PanelSettings {
|
||||||
Setting_None = 0,
|
Setting_None = 0,
|
||||||
|
@ -172,6 +177,8 @@ public void OnPluginStart() {
|
||||||
CommandArgRegex = new Regex("(?:[^\\s\"]+|\"[^\"]*\")+", 0);
|
CommandArgRegex = new Regex("(?:[^\\s\"]+|\"[^\"]*\")+", 0);
|
||||||
|
|
||||||
CreateTimer(300.0, Timer_FullSync, _, TIMER_REPEAT);
|
CreateTimer(300.0, Timer_FullSync, _, TIMER_REPEAT);
|
||||||
|
|
||||||
|
FindGameVersion();
|
||||||
}
|
}
|
||||||
bool ConnectDB() {
|
bool ConnectDB() {
|
||||||
char error[255];
|
char error[255];
|
||||||
|
@ -225,6 +232,7 @@ void SetupUserInDB(int client) {
|
||||||
void DBCT_PanelUser(Database db, DBResultSet results, const char[] error, int userId) {
|
void DBCT_PanelUser(Database db, DBResultSet results, const char[] error, int userId) {
|
||||||
if(db == null || results == null) {
|
if(db == null || results == null) {
|
||||||
LogError("DBCT_Insert returned error: %s", error);
|
LogError("DBCT_Insert returned error: %s", error);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
int client = GetClientOfUserId(userId);
|
int client = GetClientOfUserId(userId);
|
||||||
if(client > 0) {
|
if(client > 0) {
|
||||||
|
@ -252,6 +260,7 @@ void DBCT_CheckUserName(Database db, DBResultSet results, const char[] error, in
|
||||||
if(results.FetchRow()) {
|
if(results.FetchRow()) {
|
||||||
if(nameCache[client][0] == '\0') {
|
if(nameCache[client][0] == '\0') {
|
||||||
LogError("DBCT_CheckUserName user %N(#%d) missing namecache", client, userId);
|
LogError("DBCT_CheckUserName user %N(#%d) missing namecache", client, userId);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
char prevName[64];
|
char prevName[64];
|
||||||
results.FetchString(0, prevName, sizeof(prevName));
|
results.FetchString(0, prevName, sizeof(prevName));
|
||||||
|
@ -599,7 +608,7 @@ public void L4D_OnServerHibernationUpdate(bool hibernating) {
|
||||||
if(hibernating) {
|
if(hibernating) {
|
||||||
g_gameState = State_Hibernating;
|
g_gameState = State_Hibernating;
|
||||||
PrintToServer("[AdminPanel] Server is hibernating, disconnecting from socket");
|
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 {
|
} else {
|
||||||
g_gameState = State_None;
|
g_gameState = State_None;
|
||||||
PrintToServer("[AdminPanel] Server is not hibernating");
|
PrintToServer("[AdminPanel] Server is not hibernating");
|
||||||
|
@ -649,13 +658,20 @@ Action Timer_Reconnect(Handle h, int type) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ConnectSocket(bool force = false, int authTry = 0) {
|
bool ConnectSocket(bool force = false, int authTry = 0) {
|
||||||
if(g_socket == null) LogError("Socket is invalid");
|
if(g_gameState == State_Hibernating) return false; // ignore when hibernating
|
||||||
|
if(g_socket == null) {
|
||||||
|
LogError("Socket is invalid");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
if(g_socket.Connected) {
|
if(g_socket.Connected) {
|
||||||
Debug("Already connected, disconnecting...");
|
Debug("Already connected, disconnecting...");
|
||||||
g_socket.Disconnect();
|
g_socket.Disconnect();
|
||||||
authState = Auth_Inactive;
|
authState = Auth_Inactive;
|
||||||
}
|
}
|
||||||
if(authToken[0] == '\0') LogError("ConnectSocket() called with no auth token");
|
if(authToken[0] == '\0') {
|
||||||
|
LogError("ConnectSocket() called with no auth token");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// Do not try to reconnect on auth failure, until token has changed
|
// Do not try to reconnect on auth failure, until token has changed
|
||||||
if(!force && authState == Auth_Fail) return false;
|
if(!force && authState == Auth_Fail) return false;
|
||||||
authState = Auth_Pending;
|
authState = Auth_Pending;
|
||||||
|
@ -787,7 +803,17 @@ void Event_GameStart(Event event, const char[] name, bool dontBroadcast) {
|
||||||
}
|
}
|
||||||
void Event_GameEnd(Event event, const char[] name, bool dontBroadcast) {
|
void Event_GameEnd(Event event, const char[] name, bool dontBroadcast) {
|
||||||
campaignStartTime = 0;
|
campaignStartTime = 0;
|
||||||
CreateTimer(10.0, Timer_FullSync);
|
g_gameState = State_EndGame;
|
||||||
|
if(StartPayload(true)) {
|
||||||
|
AddGameRecord();
|
||||||
|
int stage = L4D2_GetCurrentFinaleStage();
|
||||||
|
if(stage != 0)
|
||||||
|
AddFinaleRecord(stage);
|
||||||
|
SendPayload();
|
||||||
|
|
||||||
|
// Resend all players
|
||||||
|
SendPlayers();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Event_MapTransition(Event event, const char[] name, bool dontBroadcast) {
|
void Event_MapTransition(Event event, const char[] name, bool dontBroadcast) {
|
||||||
|
@ -1239,6 +1265,7 @@ bool pendingRecord;
|
||||||
void StartPayloadEx() {
|
void StartPayloadEx() {
|
||||||
if(pendingRecord) {
|
if(pendingRecord) {
|
||||||
LogError("StartPayloadEx called before EndRecord()");
|
LogError("StartPayloadEx called before EndRecord()");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
sendBuffer.Reset();
|
sendBuffer.Reset();
|
||||||
hasRecord = false;
|
hasRecord = false;
|
||||||
|
@ -1252,6 +1279,7 @@ void StartPayloadEx() {
|
||||||
void StartRecord(LiveRecordType type) {
|
void StartRecord(LiveRecordType type) {
|
||||||
if(pendingRecord) {
|
if(pendingRecord) {
|
||||||
LogError("StartRecord called before EndRecord()");
|
LogError("StartRecord called before EndRecord()");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
if(hasRecord) {
|
if(hasRecord) {
|
||||||
sendBuffer.WriteChar('\x1e');
|
sendBuffer.WriteChar('\x1e');
|
||||||
|
@ -1329,7 +1357,10 @@ void AddSurvivorRecord(int client) {
|
||||||
if(isL4D1Survivors) {
|
if(isL4D1Survivors) {
|
||||||
survivor += 4;
|
survivor += 4;
|
||||||
}
|
}
|
||||||
if(survivor >= 8) LogError("invalid survivor %d", survivor);
|
if(survivor >= 8) {
|
||||||
|
LogError("invalid survivor %d", survivor);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
StartRecord(Live_Survivor);
|
StartRecord(Live_Survivor);
|
||||||
sendBuffer.WriteInt(userid);
|
sendBuffer.WriteInt(userid);
|
||||||
|
@ -1387,11 +1418,14 @@ void AddCommandResponseRecord(int id, CommandResultType resultType = Result_None
|
||||||
void AddAuthRecord() {
|
void AddAuthRecord() {
|
||||||
if(authToken[0] == '\0') {
|
if(authToken[0] == '\0') {
|
||||||
LogError("AddAuthRecord called with missing auth token");
|
LogError("AddAuthRecord called with missing auth token");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
StartRecord(Live_Auth);
|
StartRecord(Live_Auth);
|
||||||
sendBuffer.WriteByte(LIVESTATUS_VERSION);
|
sendBuffer.WriteByte(LIVESTATUS_VERSION);
|
||||||
sendBuffer.WriteString(authToken);
|
sendBuffer.WriteString(authToken);
|
||||||
sendBuffer.WriteInt(cvar_hostPort.IntValue);
|
sendBuffer.WriteShort(cvar_hostPort.IntValue);
|
||||||
|
sendBuffer.WriteString(gameVersion);
|
||||||
|
// gameAppId?
|
||||||
EndRecord();
|
EndRecord();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1452,7 +1486,7 @@ enum struct Buffer {
|
||||||
|
|
||||||
void WriteByteAt(int value, int offset) {
|
void WriteByteAt(int value, int offset) {
|
||||||
this.buffer[offset] = value & 0xFF;
|
this.buffer[offset] = value & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteShort(int value) {
|
void WriteShort(int value) {
|
||||||
this.buffer[this.offset++] = value & 0xFF;
|
this.buffer[this.offset++] = value & 0xFF;
|
||||||
|
@ -1462,7 +1496,7 @@ enum struct Buffer {
|
||||||
void WriteShortAt(int value, int offset) {
|
void WriteShortAt(int value, int offset) {
|
||||||
this.buffer[offset] = value & 0xFF;
|
this.buffer[offset] = value & 0xFF;
|
||||||
this.buffer[offset+1] = (value >> 8) & 0xFF;
|
this.buffer[offset+1] = (value >> 8) & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteInt(int value) {
|
void WriteInt(int value) {
|
||||||
this.WriteIntAt(value, this.offset);
|
this.WriteIntAt(value, this.offset);
|
||||||
|
@ -1474,7 +1508,7 @@ enum struct Buffer {
|
||||||
this.buffer[offset+1] = (value >> 8) & 0xFF;
|
this.buffer[offset+1] = (value >> 8) & 0xFF;
|
||||||
this.buffer[offset+2] = (value >> 16) & 0xFF;
|
this.buffer[offset+2] = (value >> 16) & 0xFF;
|
||||||
this.buffer[offset+3] = (value >> 24) & 0xFF;
|
this.buffer[offset+3] = (value >> 24) & 0xFF;
|
||||||
}
|
}
|
||||||
|
|
||||||
void WriteFloat(float value) {
|
void WriteFloat(float value) {
|
||||||
this.WriteInt(view_as<int>(value));
|
this.WriteInt(view_as<int>(value));
|
||||||
|
@ -1537,4 +1571,32 @@ int GetMaxPlayers() {
|
||||||
if(cvar_visibleMaxPlayers != null && cvar_visibleMaxPlayers.IntValue > 0) return cvar_visibleMaxPlayers.IntValue;
|
if(cvar_visibleMaxPlayers != null && cvar_visibleMaxPlayers.IntValue > 0) return cvar_visibleMaxPlayers.IntValue;
|
||||||
if(cvar_maxplayers != null) return cvar_maxplayers.IntValue;
|
if(cvar_maxplayers != null) return cvar_maxplayers.IntValue;
|
||||||
return L4D_IsVersusMode() ? 8 : 4;
|
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;
|
||||||
}
|
}
|
|
@ -665,4 +665,4 @@ public void __ext_socket_SetNTVOptional()
|
||||||
MarkNativeAsOptional("SocketSetArg");
|
MarkNativeAsOptional("SocketSetArg");
|
||||||
MarkNativeAsOptional("SocketGetHostName");
|
MarkNativeAsOptional("SocketGetHostName");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
Loading…
Add table
Add a link
Reference in a new issue