fixing ingame udp packets
This commit is contained in:
parent
70475bc58f
commit
e5865ff676
@ -3,20 +3,24 @@
|
||||
#define DEBUG
|
||||
|
||||
#define PLUGIN_AUTHOR "jenz"
|
||||
#define PLUGIN_VERSION "1.2"
|
||||
#define PLUGIN_VERSION "1.3"
|
||||
#define generic_length 256
|
||||
#define rows_entry_cap 10
|
||||
#define rows_entry_cap 6
|
||||
|
||||
#include <sourcemod>
|
||||
#include <sdktools>
|
||||
#include <socket>
|
||||
|
||||
#pragma newdecls required
|
||||
//#pragma newdecls required
|
||||
|
||||
int present = 0;
|
||||
int targethuman = 0;
|
||||
int stuckcounterx = 0;
|
||||
int stuckcountery = 0;
|
||||
|
||||
//socket for bot input
|
||||
Handle global_socket;
|
||||
|
||||
//bot input
|
||||
int row_counter = 0;
|
||||
char keyinput[rows_entry_cap][generic_length];
|
||||
@ -34,15 +38,6 @@ public Plugin myinfo =
|
||||
url = ""
|
||||
};
|
||||
|
||||
public void OnClientDisconnect(int client)
|
||||
{
|
||||
if (present == client)
|
||||
{
|
||||
present = 0;
|
||||
mysql_enable_disable_connected(0);
|
||||
}
|
||||
}
|
||||
|
||||
public void OnPluginStart()
|
||||
{
|
||||
//talking
|
||||
@ -50,14 +45,18 @@ public void OnPluginStart()
|
||||
|
||||
//hooks
|
||||
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
|
||||
HookEvent("player_team", event_playerteam, EventHookMode_PostNoCopy);
|
||||
|
||||
//mysql
|
||||
sql_create_table();
|
||||
//socket otherwise declare in public OnConfigsExecuted(){}
|
||||
Handle socket = SocketCreate(SOCKET_UDP, OnSocketError);
|
||||
SocketSetOption(socket, SocketReuseAddr, 1);
|
||||
SocketBind(socket, "127.0.0.1", 48476);
|
||||
connect(socket);
|
||||
global_socket = socket;
|
||||
}
|
||||
|
||||
public Action cmd_talk(int client, int args)
|
||||
{
|
||||
char msg[generic_length];
|
||||
char info[generic_length];
|
||||
GetCmdArgString(info, sizeof(info));
|
||||
if (strlen(info) == 0)
|
||||
@ -65,54 +64,21 @@ public Action cmd_talk(int client, int args)
|
||||
PrintToChat(client, "Add a message to the command if autism bot is ingame and running on discord");
|
||||
return Plugin_Handled;
|
||||
}
|
||||
char error_connect[generic_length];
|
||||
Database database_connection;
|
||||
if (SQL_CheckConfig("css_autism_bot_info"))
|
||||
database_connection = SQL_Connect("css_autism_bot_info", true, error_connect, sizeof(error_connect));
|
||||
if (database_connection == null)
|
||||
return Plugin_Handled;
|
||||
char query_start[generic_length * 2];
|
||||
int size2 = 2 * strlen(info) + 1;
|
||||
char[] sEscapedName = new char[size2 + 1];
|
||||
SQL_EscapeString(database_connection, info, sEscapedName, size2 + 1);
|
||||
Format(query_start, sizeof(query_start), "INSERT INTO unloze_css_autism_bot.`chatting` (`chatmessage`, `responsemessage`) VALUES ('%s', '')", sEscapedName);
|
||||
//PrintToChat(client, "sEscapedName: %s", query_start);
|
||||
SQL_TQuery(database_connection, DummyCallbackSimple, query_start);
|
||||
delete database_connection;
|
||||
Format(msg, sizeof(msg), "clientmessage: %s", info);
|
||||
send_socket_msg(msg, strlen(msg));
|
||||
return Plugin_Handled;
|
||||
}
|
||||
|
||||
public Action event_playerteam(Event event, const char[] name, bool dontBroadcast)
|
||||
{
|
||||
int client = GetClientOfUserId(event.GetInt("userid"));
|
||||
if (client == present)
|
||||
{
|
||||
//PrintToChatAll("called event_playerteam");
|
||||
int team = event.GetInt("team");
|
||||
//PrintToChatAll("team: %i", team);
|
||||
if (team == 2 || team == 3)
|
||||
mysql_bot_not_spec();
|
||||
}
|
||||
}
|
||||
|
||||
public void Event_RoundStart(Handle event, const char[] name, bool dontBroadcast)
|
||||
{
|
||||
targethuman = 0;
|
||||
int server_port = GetConVarInt(FindConVar("hostport"));
|
||||
if (server_port == 27015)
|
||||
{
|
||||
mysql_update_playercount();
|
||||
}
|
||||
hunt_or_mimic = false;
|
||||
if (present)
|
||||
mysql_clean_movement_input();
|
||||
}
|
||||
|
||||
public void OnMapStart()
|
||||
{
|
||||
sql_create_table();
|
||||
CreateTimer(0.2, recursive_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||
CreateTimer(2.0, mysql_send_pressing, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||
CreateTimer(0.5, socket_send_msg, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||
CreateTimer(10.0, bot_check_connect, INVALID_HANDLE, TIMER_REPEAT|TIMER_FLAG_NO_MAPCHANGE);
|
||||
}
|
||||
|
||||
public bool TraceEntityFilterPlayer(int entity, int contentsMask)
|
||||
@ -120,10 +86,74 @@ public bool TraceEntityFilterPlayer(int entity, int contentsMask)
|
||||
return (entity > GetMaxClients() || !entity);
|
||||
}
|
||||
|
||||
public Action mysql_send_pressing(Handle timer, any data)
|
||||
public void send_socket_msg(char[] query_msg, int len)
|
||||
{
|
||||
if (present && IsPlayerAlive(present))
|
||||
mysql_send_input();
|
||||
if (global_socket != INVALID_HANDLE && SocketIsConnected(global_socket))
|
||||
SocketSendTo(global_socket, query_msg, len, "127.0.0.1", 48477); //udp
|
||||
}
|
||||
|
||||
public Action bot_check_connect(Handle timer, any data)
|
||||
{
|
||||
if (!IsValidClient(present) && GetClientCount(false) < 63)
|
||||
{
|
||||
char msg[generic_length];
|
||||
//PrintToChatAll("sending UDP message...");
|
||||
Format(msg, sizeof(msg), "connect to ze");
|
||||
send_socket_msg(msg, strlen(msg));
|
||||
}
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
public Action socket_send_msg(Handle timer, any data)
|
||||
{
|
||||
if (IsValidClient(present) && IsPlayerAlive(present))
|
||||
{
|
||||
char message[generic_length * 7];
|
||||
int iterator = 0;
|
||||
int stuckcap = 12;
|
||||
float flVel[3];
|
||||
int stuckX = 0;
|
||||
int stuckY = 0;
|
||||
GetEntPropVector(present, Prop_Data, "m_vecAbsVelocity", flVel);
|
||||
float mincapvelocity = 40.0;
|
||||
if (flVel[0] < mincapvelocity)
|
||||
{
|
||||
if (stuckcounterx >= stuckcap)
|
||||
{
|
||||
stuckX = 1;
|
||||
stuckcounterx = 0;
|
||||
}
|
||||
stuckcounterx++;
|
||||
}
|
||||
if (flVel[1] < mincapvelocity)
|
||||
{
|
||||
if (stuckcountery >= stuckcap)
|
||||
{
|
||||
stuckY = 1;
|
||||
stuckcountery = 0;
|
||||
}
|
||||
stuckcountery++;
|
||||
}
|
||||
while (iterator < row_counter)
|
||||
{
|
||||
char row[generic_length];
|
||||
if (xyz[iterator][0] != 0 || xyz[iterator][1] != 0 || xyz[iterator][2] != 0)
|
||||
{
|
||||
Format(row, sizeof(row), "keyinput: %s clientangles: %f %f %f xyz: %f %f %f hunt_or_mimic: %i stuckX: %i stuckY: %i \n", keyinput[iterator], clientangles[iterator][0], clientangles[iterator][1], clientangles[iterator][2], xyz[iterator][0], xyz[iterator][1], xyz[iterator][2], hunt_or_mimic, stuckX, stuckY);
|
||||
StrCat(message, sizeof(message), row);
|
||||
Format(keyinput[iterator], sizeof(keyinput), "");
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
clientangles[iterator][i] = 0.0;
|
||||
xyz[iterator][i] = 0.0;
|
||||
}
|
||||
}
|
||||
iterator++;
|
||||
}
|
||||
row_counter = 0;
|
||||
send_socket_msg(message, strlen(message));
|
||||
}
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
public Action recursive_pressing(Handle timer, any data)
|
||||
@ -206,15 +236,13 @@ public Action recursive_pressing(Handle timer, any data)
|
||||
}
|
||||
if (row_counter < rows_entry_cap - 1)
|
||||
row_counter++;
|
||||
return Plugin_Handled;
|
||||
return Plugin_Continue;
|
||||
}
|
||||
|
||||
stock bool IsValidClient(int client)
|
||||
{
|
||||
if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -228,175 +256,62 @@ public void OnClientPostAdminCheck(int client)
|
||||
GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth));
|
||||
if (StrEqual("[U:1:120378081]", auth, false))
|
||||
{
|
||||
mysql_enable_disable_connected(1);
|
||||
present = client;
|
||||
bot_send_connected_msg();
|
||||
}
|
||||
else if (StrEqual("STEAM_0:1:60189040", auth, false))
|
||||
{
|
||||
mysql_enable_disable_connected(1);
|
||||
present = client;
|
||||
bot_send_connected_msg();
|
||||
}
|
||||
}
|
||||
|
||||
public void sql_create_table()
|
||||
public OnSocketError(Handle socket, const int errorType, const int errorNum, any args)
|
||||
{
|
||||
char error_connect[generic_length];
|
||||
Database database_connection;
|
||||
if (SQL_CheckConfig("css_autism_bot_info"))
|
||||
database_connection = SQL_Connect("css_autism_bot_info", true, error_connect, sizeof(error_connect));
|
||||
if (database_connection == null)
|
||||
return;
|
||||
//256 not enough
|
||||
char query_start[generic_length * 3];
|
||||
Format(query_start, sizeof(query_start), "CREATE TABLE IF NOT EXISTS unloze_css_autism_bot.`bot status` (`connected` BOOL DEFAULT false, `spectate` BOOL DEFAULT true, `ID` INT NOT NULL DEFAULT 1, `playercount` INT DEFAULT 0, PRIMARY KEY (`ID`))");
|
||||
SQL_TQuery(database_connection, DummyCallbackSimple, query_start);
|
||||
Format(query_start, sizeof(query_start), "CREATE TABLE IF NOT EXISTS unloze_css_autism_bot.`bot movement input` (`keyinput` text NOT NULL, `clientangles_0` DECIMAL(13, 8) DEFAULT 0.000, `clientangles_1` DECIMAL(13, 8) DEFAULT 0.000, `clientangles_2` DECIMAL(13, 8) DEFAULT 0.000, `xyz_0` DECIMAL(13, 8) DEFAULT 0.000, `xyz_1` DECIMAL(13, 8) DEFAULT 0.000, `xyz_2` DECIMAL(13, 8) DEFAULT 0.000, `hunt_or_mimic` BOOLEAN DEFAULT false, `stuckX` BOOLEAN DEFAULT false, `stuckY` BOOLEAN DEFAULT false, `entry_time` DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP)");
|
||||
SQL_TQuery(database_connection, DummyCallbackSimple, query_start);
|
||||
Format(query_start, sizeof(query_start), "INSERT INTO unloze_css_autism_bot.`bot status` (connected, spectate, ID) VALUES (0, 1, 1) ON DUPLICATE KEY UPDATE connected = VALUES(connected), spectate = VALUES(spectate)");
|
||||
SQL_TQuery(database_connection, DummyCallbackSimple, query_start);
|
||||
Format(query_start, sizeof(query_start), "CREATE TABLE IF NOT EXISTS unloze_css_autism_bot.`chatting` (`chatmessage` text NOT NULL, `responsemessage` text NOT NULL)");
|
||||
SQL_TQuery(database_connection, DummyCallbackSimple, query_start);
|
||||
delete database_connection;
|
||||
LogError("[MR] Socket error: %d (errno %d)", errorType, errorNum);
|
||||
CreateTimer(120.0, TimerConnect, socket, TIMER_HNDL_CLOSE);
|
||||
}
|
||||
|
||||
public void mysql_clean_movement_input()
|
||||
stock void connect(Handle socket)
|
||||
{
|
||||
char error_connect[generic_length];
|
||||
Database database_connection;
|
||||
if (SQL_CheckConfig("css_autism_bot_info"))
|
||||
database_connection = SQL_Connect("css_autism_bot_info", true, error_connect, sizeof(error_connect));
|
||||
if (database_connection == null)
|
||||
return;
|
||||
char query_start[generic_length];
|
||||
Format(query_start, sizeof(query_start), "delete from unloze_css_autism_bot.`bot movement input`");
|
||||
SQL_TQuery(database_connection, DummyCallbackSimple, query_start);
|
||||
delete database_connection;
|
||||
if (!SocketIsConnected(socket))
|
||||
SocketConnect(socket, OnSocketConnected, OnSocketReceive, OnSocketDisconnected, "127.0.0.1", 48476);
|
||||
}
|
||||
|
||||
public void mysql_update_playercount()
|
||||
public void OnClientDisconnect(int client)
|
||||
{
|
||||
char error_connect[generic_length];
|
||||
Database database_connection;
|
||||
if (SQL_CheckConfig("css_autism_bot_info"))
|
||||
database_connection = SQL_Connect("css_autism_bot_info", true, error_connect, sizeof(error_connect));
|
||||
if (database_connection == null)
|
||||
return;
|
||||
char query_start[generic_length];
|
||||
Format(query_start, sizeof(query_start), "INSERT INTO unloze_css_autism_bot.`bot status` (playercount, ID) VALUES (%i, 1) ON DUPLICATE KEY UPDATE playercount = %i", MaxClients, MaxClients);
|
||||
SQL_TQuery(database_connection, DummyCallbackSimple, query_start);
|
||||
delete database_connection;
|
||||
}
|
||||
|
||||
public void mysql_bot_not_spec()
|
||||
{
|
||||
char error_connect[generic_length];
|
||||
Database database_connection;
|
||||
if (SQL_CheckConfig("css_autism_bot_info"))
|
||||
database_connection = SQL_Connect("css_autism_bot_info", true, error_connect, sizeof(error_connect));
|
||||
if (database_connection == null)
|
||||
return;
|
||||
char query_start[generic_length];
|
||||
Format(query_start, sizeof(query_start), "INSERT INTO unloze_css_autism_bot.`bot status` (connected, spectate, ID) VALUES (1, 0, 1) ON DUPLICATE KEY UPDATE connected = VALUES(connected), spectate = VALUES(spectate)");
|
||||
SQL_TQuery(database_connection, DummyCallbackSimple, query_start);
|
||||
delete database_connection;
|
||||
}
|
||||
|
||||
public void mysql_enable_disable_connected(int state)
|
||||
{
|
||||
char error_connect[generic_length];
|
||||
Database database_connection;
|
||||
if (SQL_CheckConfig("css_autism_bot_info"))
|
||||
database_connection = SQL_Connect("css_autism_bot_info", true, error_connect, sizeof(error_connect));
|
||||
if (database_connection == null)
|
||||
return;
|
||||
char query_start[generic_length];
|
||||
if (!state)
|
||||
Format(query_start, sizeof(query_start), "INSERT INTO unloze_css_autism_bot.`bot status` (connected, spectate, ID) VALUES (0, 1, 1) ON DUPLICATE KEY UPDATE connected = VALUES(connected), spectate = VALUES(spectate)");
|
||||
else
|
||||
Format(query_start, sizeof(query_start), "INSERT INTO unloze_css_autism_bot.`bot status` (connected, spectate, ID) VALUES (1, 1, 1) ON DUPLICATE KEY UPDATE connected = VALUES(connected), spectate = VALUES(spectate)");
|
||||
//PrintToChatAll("query_start: %s", query_start);
|
||||
SQL_TQuery(database_connection, DummyCallbackSimple, query_start);
|
||||
delete database_connection;
|
||||
}
|
||||
|
||||
public void mysql_send_input()
|
||||
{
|
||||
char error_connect[generic_length];
|
||||
Database database_connection;
|
||||
if (SQL_CheckConfig("css_autism_bot_info"))
|
||||
database_connection = SQL_Connect("css_autism_bot_info", true, error_connect, sizeof(error_connect));
|
||||
if (database_connection == null)
|
||||
if (present == client)
|
||||
{
|
||||
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to maria-DB!");
|
||||
return;
|
||||
present = 0;
|
||||
}
|
||||
char query_start[generic_length * 7];
|
||||
int iterator = 0;
|
||||
float flVel[3];
|
||||
int stuckX = 0;
|
||||
int stuckY = 0;
|
||||
GetEntPropVector(present, Prop_Data, "m_vecAbsVelocity", flVel);
|
||||
float mincapvelocity = 10.0;
|
||||
if (flVel[0] < mincapvelocity)
|
||||
{
|
||||
if (stuckcounterx > 5)
|
||||
{
|
||||
stuckX = 1;
|
||||
stuckcounterx = -1;
|
||||
}
|
||||
stuckcounterx++;
|
||||
}
|
||||
if (flVel[1] < mincapvelocity)
|
||||
{
|
||||
if (stuckcountery > 5)
|
||||
{
|
||||
stuckY = 1;
|
||||
stuckcountery = -1;
|
||||
}
|
||||
stuckcountery++;
|
||||
}
|
||||
bool testdebug = false;
|
||||
Format(query_start, sizeof(query_start), "INSERT INTO unloze_css_autism_bot.`bot movement input` VALUES ");
|
||||
while (iterator < row_counter)
|
||||
{
|
||||
char row[generic_length];
|
||||
if (xyz[iterator][0] != 0 || xyz[iterator][1] != 0 || xyz[iterator][2] != 0)
|
||||
{
|
||||
Format(row, sizeof(row), " ('%s', %f, %f, %f, %f, %f, %f, %i, %i, %i, NOW()),", keyinput[iterator], clientangles[iterator][0], clientangles[iterator][1], clientangles[iterator][2], xyz[iterator][0], xyz[iterator][1], xyz[iterator][2], hunt_or_mimic, stuckX, stuckY);
|
||||
StrCat(query_start, sizeof(query_start), row);
|
||||
Format(keyinput[iterator], sizeof(keyinput), "");
|
||||
testdebug = true;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
clientangles[iterator][i] = 0.0;
|
||||
xyz[iterator][i] = 0.0;
|
||||
}
|
||||
}
|
||||
iterator++;
|
||||
}
|
||||
row_counter = 0;
|
||||
int querylen = strlen(query_start);
|
||||
query_start[querylen - 1] = '\0';
|
||||
//debugging
|
||||
//PrintToChatAll("query_start final length: %i", querylen);
|
||||
/*
|
||||
char g_sConfigzones[PLATFORM_MAX_PATH];
|
||||
Handle inputfile = INVALID_HANDLE;
|
||||
BuildPath(Path_SM, g_sConfigzones, sizeof(g_sConfigzones), "configs/autism_insert_debug.txt");
|
||||
inputfile = OpenFile(g_sConfigzones, "a+");
|
||||
if (inputfile != INVALID_HANDLE)
|
||||
{
|
||||
WriteFileLine(inputfile, "%s", query_start);
|
||||
}
|
||||
delete inputfile;
|
||||
*/
|
||||
if (testdebug)
|
||||
SQL_TQuery(database_connection, DummyCallbackSimple, query_start);
|
||||
delete database_connection;
|
||||
}
|
||||
|
||||
public void DummyCallbackSimple(Handle hOwner, Handle hChild, const char[] err, DataPack pack1)
|
||||
public void bot_send_connected_msg()
|
||||
{
|
||||
if (hOwner == null || hChild == null)
|
||||
LogError("Query error. (%s)", err);
|
||||
char msg[generic_length];
|
||||
Format(msg, sizeof(msg), "autismo connected");
|
||||
send_socket_msg(msg, strlen(msg));
|
||||
}
|
||||
|
||||
//Socket callback
|
||||
public OnSocketConnected(Handle socket, any arg)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//manage message
|
||||
public OnSocketReceive(Handle socket, char[] receiveData, const dataSize, any hFile)
|
||||
{
|
||||
//PrintToChatAll("receiveData: %s", receiveData);
|
||||
}
|
||||
|
||||
public OnSocketDisconnected(Handle socket, any arg)
|
||||
{
|
||||
CreateTimer(120.0, TimerConnect, socket, TIMER_HNDL_CLOSE);
|
||||
}
|
||||
|
||||
public Action TimerConnect(Handle timer, any arg)
|
||||
{
|
||||
connect(arg);
|
||||
return Plugin_Handled;
|
||||
}
|
Loading…
Reference in New Issue
Block a user