Commit 08e23eeb authored by Neoony's avatar Neoony
Browse files

v0.1 WIP23 -Fixed cleaning of sockets -Fixed sockets not timing out, timeout...

v0.1 WIP23 -Fixed cleaning of sockets -Fixed sockets not timing out, timeout takes half of the l_refreshservers value
parent 7723cb8c
Pipeline #4733 passed with stages
in 2 minutes and 55 seconds
......@@ -21,7 +21,7 @@
//#include <emputils>
#include <socket>
#define PluginVer "v0.1 WIP22"
#define PluginVer "v0.1 WIP23"
public Plugin myinfo =
{
......@@ -98,11 +98,12 @@ int numPlayersS[10];
int maxPlayersS[10];
//Socket related
Handle socket[10];
Handle socketx[10];
bool socketError[10];
char serverInfo[10][200];
Handle l_serverformat = INVALID_HANDLE;
//char serverName[10][160];
Handle CleanUpTimer[10] = INVALID_HANDLE;
//Preferred Server
bool PreferredServerActive = false;
......@@ -1192,26 +1193,6 @@ public void RSInfoOfServer(Handle RShDriver, Handle RShResult, const char[] sErr
//Vanilla server IP replacement, as it is a local server
//Vanilla IP:
//Vanilla local IP: 192.168.200.81:27016
if (GetConVarInt(l_debug) == 1)
{
if (VanillaLocal == true)
{
PrintToServer("[L]VanillaLocal = true");
}
if (VanillaLocal == false)
{
PrintToServer("[L]VanillaLocal = false");
}
if (EuropiresLocal == true)
{
PrintToServer("[L]EuropiresLocal = true");
}
if (EuropiresLocal == false)
{
PrintToServer("[L]EuropiresLocal = false");
}
}
if (VanillaLocal == true)
{
if (StrEqual(RSaddrx[ServerIndex], "80.112.155.100:27016") == true)
......@@ -1271,36 +1252,53 @@ public Action SCommand_LRSdump(int args)
public Action RefreshServerInfo(int ServerIndex)
{
int ServerIndexx = ServerIndex;
serverInfo[ServerIndexx] = "";
socketError[ServerIndexx] = false;
socket[ServerIndexx] = SocketCreate(SOCKET_UDP, OnSocketError);
SocketSetArg(socket[ServerIndexx], ServerIndexx);
SocketConnect(socket[ServerIndexx], OnSocketConnected, OnSocketReceive, OnSocketDisconnected, RSIPaddr[ServerIndexx], RSPort[ServerIndexx]);
socketx[ServerIndexx] = SocketCreate(SOCKET_UDP, OnSocketError);
SocketSetArg(socketx[ServerIndexx], ServerIndexx);
SocketConnect(socketx[ServerIndexx], OnSocketConnected, OnSocketReceive, OnSocketDisconnected, RSIPaddr[ServerIndexx], RSPort[ServerIndexx]);
if (GetConVarInt(l_debug) == 1)
{
PrintToServer("Connecting to: %s %i", RSIPaddr[ServerIndexx], RSPort[ServerIndexx]);
}
//CreateTimer(10.0, CleanUp, ServerIndexx);
float CleanUpTime = GetConVarFloat(l_refreshservers) / 2;
CleanUpTimer[ServerIndexx] = CreateTimer(CleanUpTime, CleanUpTmr, ServerIndexx);
}
public Action CleanUp(int ServerIndexx)
public Action CleanUpTmr(Handle timer, int ServerIndexx)
{
if (strlen(serverInfo[ServerIndexx]) == 0 && !socketError[ServerIndexx])
{
LogError("Server %s:%s is down: no timely reply received", RSIPaddr[ServerIndexx], RSPort[ServerIndexx]);
LogError("Server %s:%i is down: no timely reply received", RSIPaddr[ServerIndexx], RSPort[ServerIndexx]);
if (GetConVarInt(l_debug) == 1)
{
PrintToServer("Server %s:%s is down: no timely reply received", RSIPaddr[ServerIndexx], RSPort[ServerIndexx]);
PrintToServer("Server %s:%i is down: no timely reply received", RSIPaddr[ServerIndexx], RSPort[ServerIndexx]);
}
if (curPlayersSQL[ServerIndexx] != 0)
{
UpdateSQLServerDown(ServerIndexx);
}
CloseHandle(socketx[ServerIndexx]);
if (GetConVarInt(l_debug) == 1)
{
PrintToServer("[L]CleanUp closed socket for server %i", ServerIndexx);
}
CloseHandle(socket[ServerIndexx]);
}
}
public OnSocketConnected(Handle sock, int ServerIndexx)
public OnSocketConnected(Handle socket, int ServerIndexx)
{
if (GetConVarInt(l_debug) == 1)
{
PrintToServer("[L]Socket connected to server %i", ServerIndexx);
}
char requestStr[25];
Format(requestStr, sizeof(requestStr), "%s", "\xFF\xFF\xFF\xFF\x54Source Engine Query");
SocketSend(sock, requestStr, 25);
SocketSend(socketx[ServerIndexx], requestStr, 25);
}
GetByte( String:receiveData[], offset )
......@@ -1324,7 +1322,7 @@ String:GetString( String:receiveData[], dataSize, offset )
return serverStr;
}
public OnSocketReceive(Handle sock, char[] receiveData, const int dataSize, int ServerIndexx)
public OnSocketReceive(Handle socket, char[] receiveData, const int dataSize, int ServerIndexx)
{
char srvName[160];
char mapName[160];
......@@ -1401,17 +1399,26 @@ public OnSocketReceive(Handle sock, char[] receiveData, const int dataSize, int
#endif
CleanUp(ServerIndexx);
//CleanUp(ServerIndexx);
CloseHandle(sock);
CloseHandle(socketx[ServerIndexx]);
if (GetConVarInt(l_debug) == 1)
{
PrintToServer("[L]Closed socket for server %i", ServerIndexx);
}
}
public OnSocketDisconnected(Handle sock, int ServerIndexx)
public OnSocketDisconnected(Handle socket, int ServerIndexx)
{
CloseHandle(sock);
CloseHandle(socketx[ServerIndexx]);
if (GetConVarInt(l_debug) == 1)
{
PrintToServer("[L]Closed socket for server %i", ServerIndexx);
}
}
public OnSocketError(Handle sock, const errorType, const errorNum, int ServerIndexx)
public OnSocketError(Handle socket, const errorType, const errorNum, int ServerIndexx)
{
LogError("Server %s:%i is down: socket error %d (errno %d)", RSIPaddr[ServerIndexx], RSPort[ServerIndexx], errorType, errorNum);
if (GetConVarInt(l_debug) == 1)
......@@ -1419,8 +1426,16 @@ public OnSocketError(Handle sock, const errorType, const errorNum, int ServerInd
PrintToServer("Server %s:%i is down: socket error %d (errno %d)", RSIPaddr[ServerIndexx], RSPort[ServerIndexx], errorType, errorNum);
}
socketError[ServerIndexx] = true;
UpdateSQLServerDown(ServerIndexx);
CloseHandle(sock);
if (curPlayersSQL[ServerIndexx] != 0)
{
UpdateSQLServerDown(ServerIndexx);
}
CloseHandle(socketx[ServerIndexx]);
if (GetConVarInt(l_debug) == 1)
{
PrintToServer("[L]Closed socket for server %i", ServerIndexx);
}
}
//Update SQL section
......@@ -1474,7 +1489,7 @@ public Action UpdateSQLServerDown(int ServerIndexx)
}
char UpdateServerDown[512];
Format(UpdateServerDown, sizeof(UpdateServerDown), "UPDATE `LobbyDB`.`servers` SET players = '0', maxplayers = '%i' WHERE addr = '%s';", maxPlayersS[ServerIndexx], RSaddrx[ServerIndexx]);
Format(UpdateServerDown, sizeof(UpdateServerDown), "UPDATE `LobbyDB`.`servers` SET players = '0', maxplayers = '0' WHERE addr = '%s';", RSaddrx[ServerIndexx]);
SQL_TQuery(hDatabase, UpdateServer_Handle, UpdateServerDown, ServerIndexx);
}
......
......@@ -4,7 +4,7 @@
{
"Version"
{
"Latest" "v0.1 WIP22"
"Latest" "v0.1 WIP23"
}
"Notes" "First release"
......@@ -39,6 +39,8 @@
"Notes" "WIP20: Revert Europires fast refresh for main lobby back to public IP"
"Notes" "WIP21: Changed Europires fast refresh for main lobby to a different local IP"
"Notes" "WIP22: Added some debug messages related to Fast refresh local ip"
"Notes" "WIP23: Fixed cleaning of sockets"
"Notes" "WIP23: Fixed sockets not timing out, timeout takes half of the l_refreshservers value"
}
"Files"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment