still missing the !autism command to work on discord part

This commit is contained in:
jenzur 2020-06-12 02:01:39 +02:00
parent 4c26d46016
commit 70475bc58f
2 changed files with 288 additions and 286 deletions

View File

@ -7,38 +7,26 @@ import string
import random
import time
import mysql.connector
from mysql.connector import pooling
from mysql.connector import Error
from contextlib import closing
from settings import mysql_connection_ip, mysql_connection_user, mysql_connection_pw, mysql_connection_database
looptestPath = '/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/cfg/looptest.cfg'
looptestPath = '/home/gameservers/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/cfg/looptest.cfg'
chatmsg = ""
mysql_connection_pool = mysql.connector.pooling.MySQLConnectionPool(pool_name="mypool", host=mysql_connection_ip, database=mysql_connection_database, user=mysql_connection_user, passwd=mysql_connection_pw)
def get_connection_obsolete():
return mysql.connector.connect(
host=mysql_connection_ip,
user=mysql_connection_user,
passwd=mysql_connection_pw,
database=mysql_connection_database)
def writeCfgInput(Input):
with open(looptestPath, 'w') as f:
f.write(Input)
def resetCfgInputShortWait():
str = "{0}; wait 5;"
str = "wait 5; "
with open(looptestPath, 'w') as f:
f.write(str)
time.sleep(0.5)
def exit_handler():
print('reached exithandler')
str = "wait 5;"
with open(looptestPath, 'w') as f:
f.write(str)
print('reached exithandler')
resetCfgInputShortWait()
def joinTeam():
str = "jointeam 2; wait 2; zspawn; wait 1; {0}; wait 5;"
@ -47,185 +35,197 @@ def joinTeam():
print('jointeam func: ')
def checkbotteam():
mysql_check_spectator()
resetCfgInputShortWait()
connectionTimer = Timer(20.0, checkbotteam)
connectionTimer.daemon = True
connectionTimer.start()
with closing(mysql.connector.connect(host=mysql_connection_ip, database=mysql_connection_database, user=mysql_connection_user, password=mysql_connection_pw,
auth_plugin='mysql_native_password')) as cnx:
with closing(cnx.cursor()) as cur:
mysql_check_spectator(cur)
resetCfgInputShortWait()
connectionTimer = Timer(20.0, checkbotteam)
connectionTimer.daemon = True
connectionTimer.start()
def mysql_check_spectator():
cnx = mysql_connection_pool.get_connection()
cur = cnx.cursor()
sql_statement = f"""SELECT spectate from unloze_css_autism_bot.`bot status`"""
cur.execute(sql_statement)
result = cur.fetchall()[0]
spectate = result[0]
print('spectate: ', spectate)
if spectate != 0:
joinTeam()
cur.close()
cnx.close()
def mysql_check_spectator(cur):
sql_statement = f"""SELECT spectate from unloze_css_autism_bot.`bot status`"""
cur.execute(sql_statement)
result = cur.fetchall()[0]
spectate = result[0]
print('spectate: ', spectate)
if spectate != 0:
joinTeam()
def mysql_get_player_info(movement_list):
cnx = mysql_connection_pool.get_connection()
cur = cnx.cursor()
sql_statement = f"""SELECT * from unloze_css_autism_bot.`bot movement input` ORDER BY entry_time LIMIT 1"""
sql_row_count = "SELECT COUNT(*) FROM unloze_css_autism_bot.`bot movement input`"
cur.execute(sql_statement)
result = cur.fetchall()
cur.execute(sql_row_count)
result_count = cur.fetchone()[0]
if result:
result = result[0]
movement_input = result[0]
client_angles = [result[1], result[2], result[3]]
xyz_difference = [result[4], result[5], result[6]]
client_coordinates = result[7], result[8], result[9]
hunt_or_mimic = result[10]
stuckX = result[11]
stuckY = result[12]
strInput = "-attack; wait 5; -jump; wait 5; -duck; wait 5; +attack; wait 5; cl_minmodels 1; "
print('movement_list[0]: ', movement_list[0], '#0 = forward, 1 = back, 2 = none')
print('movement_list[1]: ', movement_list[1], '#0 = left, 1 = right, 2 = none')
print('result_count: ', result_count)
axis_distance = 105
print('stuckX: ', stuckX, ' stuckY: ', stuckY)
if stuckX:
if movement_list[0] == 0:
movement_list[0] = 1
elif movement_list[0] == 1:
movement_list[0] = 0
strInput += " +jump; wait 3; +duck; wait 5;"
if stuckY:
if movement_list[1] == 0:
movement_list[1] = 1
elif movement_list[1] == 1:
movement_list[1] = 0
strInput += " +jump; wait 3; +duck; wait 5;"
if hunt_or_mimic:
print('hunt_or_mimic enabled')
sql_statement = f"""SELECT entry_time FROM unloze_css_autism_bot.`bot movement input` where client_coord_0 = '{client_coordinates[0]}' and
client_coord_1 = '{client_coordinates[1]}' and client_coord_2 = '{client_coordinates[2]}' LIMIT 1"""
cur.execute(sql_statement)
entry_time = cur.fetchall()[0][0]
if not hunt_or_mimic:
if xyz_difference[0] > axis_distance:
movement_list[0] = 1
elif xyz_difference[0] < -axis_distance:
movement_list[0] = 0
else:
movement_list[0] = 2 #strInput += " -back; wait 5; -forward; wait 5;"
def organize_player_info(movement_list):
strInput = "-attack; wait 5; -jump; wait 5; -duck; wait 5; +attack; wait 5; cl_minmodels 1; "
writeCfgInput(strInput)
time.sleep(0.2)
writeCfgInput("wait 5;")
mysql_get_player_info(movement_list)
mysql_delete_rows()
post_chatmsg()
if xyz_difference[1] < -axis_distance:
movement_list[1] = 1
elif xyz_difference[1] > axis_distance:
movement_list[1] = 0
else:
movement_list[1] = 2 #strInput += " -moveright; wait 5; -moveleft; wait 5;"
print('xyz_difference[0]: ', xyz_difference[0])
print('xyz_difference[1]: ', xyz_difference[1])
strInput += f""" setang 0 180 0; wait 5; """
else:
#print('client_angles: ', client_angles)
print('movement_input: ', movement_input)
strInput += f"""setang {client_angles[0]} {client_angles[1]} {client_angles[2]}; wait 5; {movement_input}; wait 5;"""
sql_statement = f"""DELETE FROM unloze_css_autism_bot.`bot movement input` where entry_time <= '{entry_time}'"""
cur.execute(sql_statement)
print('Deleted ', cur.rowcount, ' rows before/during entry_time:', entry_time)
run_delay = 0.2 #0.05
connectionTimer = Timer(run_delay, organize_player_info, args=[movement_list])
connectionTimer.daemon = True
connectionTimer.start()
def post_chatmsg():
global chatmsg
strInput = f"""{chatmsg}"""
chatmsg = ""
writeCfgInput(strInput)
time.sleep(0.5)
writeCfgInput("wait 5;")
def mysql_delete_rows():
with closing(mysql.connector.connect(host=mysql_connection_ip, database=mysql_connection_database, user=mysql_connection_user, password=mysql_connection_pw,
auth_plugin='mysql_native_password')) as cnx:
with closing(cnx.cursor()) as cur:
sql_statement = f"""SELECT hunt_or_mimic from unloze_css_autism_bot.`bot movement input` ORDER BY entry_time desc LIMIT 1"""
results = cur.execute(sql_statement, multi=True)
if results:
for result in results:
if result.with_rows:
resultfetch = result.fetchone()
break
if resultfetch:
hunt_or_mimic = resultfetch[0]
print('hunt_or_mimic delete: ', hunt_or_mimic)
if hunt_or_mimic:
sql_statement = f"""DELETE FROM unloze_css_autism_bot.`bot movement input` ORDER BY entry_time asc LIMIT 10"""
cur.execute(sql_statement)
print('Deleted ', cur.rowcount, ' rows')
cnx.commit()
def mysql_get_player_info(movement_list):
with closing(mysql.connector.connect(host=mysql_connection_ip, database=mysql_connection_database, user=mysql_connection_user, password=mysql_connection_pw,
auth_plugin='mysql_native_password')) as cnx:
with closing(cnx.cursor()) as cur:
sql_statement = f"""SELECT StuckX, StuckY, xyz_0, xyz_1, xyz_2, hunt_or_mimic from unloze_css_autism_bot.`bot movement input` bmi ORDER BY entry_time desc LIMIT 1"""
cur.execute(sql_statement)
huntfetch = cur.fetchone()
if huntfetch:
hunt_or_mimic = huntfetch[5]
if not hunt_or_mimic:
stuckX = huntfetch[0]
stuckY = huntfetch[1]
xyz_difference = [huntfetch[2], huntfetch[3], huntfetch[4]]
strInput = ""
axis_distance = 50
if stuckX:
print('stuckX enabled')
if movement_list[0] == 0:
movement_list[0] = 1
elif movement_list[0] == 1:
movement_list[0] = 0
strInput += " +jump; wait 3; +duck; wait 5;"
if stuckY:
print('stuckY enabled')
if movement_list[1] == 0:
movement_list[1] = 1
elif movement_list[1] == 1:
movement_list[1] = 0
strInput += " +jump; wait 3; +duck; wait 5;"
print('hunt mode enabled')
if not stuckX and not stuckY:
if xyz_difference[0] > axis_distance:
movement_list[0] = 1
elif xyz_difference[0] < -axis_distance:
movement_list[0] = 0
if xyz_difference[1] < -axis_distance:
movement_list[1] = 1
elif xyz_difference[1] > axis_distance:
movement_list[1] = 0
if movement_list[0] == 1:
strInput += " -back; wait 5; +forward; wait 5;"
elif movement_list[0] == 0:
strInput += " -forward; wait 5; +back; wait 5;"
if movement_list[1] == 1:
strInput += " -moveleft; wait 5; +moveright; wait 5;"
strInput += " -moveleft; wait 5; +moveright; wait 5;"
elif movement_list[1] == 0:
strInput += " -moveright; wait 5; +moveleft; wait 5;"
sql_statement = f"""DELETE FROM unloze_css_autism_bot.`bot movement input` where entry_time <= '{entry_time}'"""
print('xyz_difference[0]: ', xyz_difference[0])
print('xyz_difference[1]: ', xyz_difference[1])
print('movement_list[0]: ', movement_list[0], '0 = back. 1 = forward.')
print('movement_list[1]: ', movement_list[1], '0 = moveleft. 1 = moveright')
strInput += f""" setang 0 180 0; wait 5; """
writeCfgInput(strInput)
time.sleep(0.4)
writeCfgInput("wait 5;")
else:
sql_statement = f"""SELECT * from unloze_css_autism_bot.`bot movement input` ORDER BY entry_time asc LIMIT 10"""
cur.execute(sql_statement)
#print('sql_statement: ', sql_statement)
print('Deleted ', cur.rowcount, ' rows before/during entry_time:', entry_time)
cnx.commit()
#print('strInput final:', strInput)
global chatmsg
strInput += f" {chatmsg}"
chatmsg = ""
writeCfgInput(strInput)
time.sleep(0.10)
writeCfgInput("wait 5;")
cur.close()
cnx.close()
run_delay = 0.05 #0.05
connectionTimer = Timer(run_delay, mysql_get_player_info, args=[movement_list])
connectionTimer.daemon = True
connectionTimer.start()
resultfetch = cur.fetchall()
#print('resultfetch: ', resultfetch)
for result in resultfetch:
#print('result: ', result)
movement_input = result[0]
client_angles = [result[1], result[2], result[3]]
strInput = ""
#print('client_angles: ', client_angles)
print('movement_input: ', movement_input)
strInput += f"""setang {client_angles[0]} {client_angles[1]} {client_angles[2]}; wait 5; {movement_input}; wait 5; """
#print('strInput final:', strInput)
writeCfgInput(strInput)
time.sleep(0.04)
writeCfgInput("wait 5;")
def mysql_check_messages():
cnx = mysql_connection_pool.get_connection()
cur = cnx.cursor()
sql_statement = """SELECT responsemessage FROM unloze_css_autism_bot.chatting WHERE responsemessage != '' LIMIT 1"""
cur.execute(sql_statement)
result = cur.fetchall()
if result:
result = result[0][0]
str = f"""say {result}"""
print('str: ', str)
global chatmsg
chatmsg = str
sql_statement = f"""DELETE FROM unloze_css_autism_bot.`chatting` WHERE `responsemessage` = '{result}'"""
print('sql_statement: ', sql_statement)
cur.execute(sql_statement)
cnx.commit()
cur.close()
cnx.close()
connectionTimer = Timer(0.5, mysql_check_messages)
connectionTimer.daemon = True
connectionTimer.start()
with closing(mysql.connector.connect(host=mysql_connection_ip, database=mysql_connection_database, user=mysql_connection_user, password=mysql_connection_pw,
auth_plugin='mysql_native_password')) as cnx:
with closing(cnx.cursor()) as cur:
sql_statement = """SELECT responsemessage FROM unloze_css_autism_bot.chatting WHERE responsemessage != '' LIMIT 1"""
cur.execute(sql_statement)
result = cur.fetchall()
if result:
result = result[0][0]
str = f"""say {result}"""
print('str: ', str)
global chatmsg
chatmsg = str
sql_statement = f"""DELETE FROM unloze_css_autism_bot.`chatting` WHERE `responsemessage` = '{result}'"""
#print('sql_statement: ', sql_statement)
cur.execute(sql_statement)
cnx.commit()
connectionTimer = Timer(0.9, mysql_check_messages)
connectionTimer.daemon = True
connectionTimer.start()
def mysql_check_if_connected():
cnx = mysql_connection_pool.get_connection()
cur = cnx.cursor()
sql_statement = """SELECT connected, playercount from unloze_css_autism_bot.`bot status`"""
cur.execute(sql_statement)
result = cur.fetchall()[0]
#print('result: ', result, ' result[0]: ', result[0])
connected = result[0]
playercount = result[1]
#playercount might not be updated ingame and auto leave?
print('connected: ', connected)
if connected == 0:
str1 = "connect 151.80.230.149:27015;"
writeCfgInput(str1)
time.sleep(0.2)
writeCfgInput("wait 5;")
time.sleep(15.50)
print('not yet connected')
mysql_check_if_connected()
obsolete = """
elif playercount > 60:
str1 = "connect 151.80.230.149:27016;"
writeCfgInput(str1)
time.sleep(0.5)
writeCfgInput("wait 500;")
time.sleep(15.50)
print('not yet connected')
mysql_check_if_connected() """
connectionTimer = Timer(60.0 * 2, mysql_check_if_connected)
connectionTimer.daemon = True
connectionTimer.start()
cur.close()
cnx.close()
def mysql_reset_input():
cnx = mysql_connection_pool.get_connection()
cur = cnx.cursor()
sql_statement = f"""DELETE FROM unloze_css_autism_bot.`bot movement input`"""
cur.execute(sql_statement)
cnx.commit()
cur.close()
cnx.close()
with closing(mysql.connector.connect(host=mysql_connection_ip, database=mysql_connection_database, user=mysql_connection_user, password=mysql_connection_pw,
auth_plugin='mysql_native_password')) as cnx:
with closing(cnx.cursor()) as cur:
sql_statement = """SELECT connected, playercount from unloze_css_autism_bot.`bot status`"""
cur.execute(sql_statement)
result = cur.fetchall()[0]
#print('result: ', result, ' result[0]: ', result[0])
connected = result[0]
playercount = result[1]
#playercount might not be updated ingame and auto leave?
print('connected: ', connected)
if connected == 0:
str1 = "connect 151.80.230.149:27015;"
writeCfgInput(str1)
time.sleep(0.2)
writeCfgInput("wait 5;")
time.sleep(15.50)
print('not yet connected')
mysql_check_if_connected()
obsolete = """
elif playercount > 60:
str1 = "connect 151.80.230.149:27016;"
writeCfgInput(str1)
time.sleep(0.5)
writeCfgInput("wait 500;")
time.sleep(15.50)
print('not yet connected')
mysql_check_if_connected() """
connectionTimer = Timer(60.0 * 2, mysql_check_if_connected)
connectionTimer.daemon = True
connectionTimer.start()
def deadlock():
try:
@ -233,21 +233,35 @@ def deadlock():
except KeyboardInterrupt:
pass
if __name__ == '__main__':
atexit.register(exit_handler)
resetCfgInputShortWait()
mysql_check_if_connected()
checkbotteam()
print('reached mysql _get_player_info')
mysql_reset_input()
mysql_get_player_info([False, True])
mysql_check_messages()
print('reached deadlock')
deadlock()
def mysql_reset_input():
with closing(mysql.connector.connect(host=mysql_connection_ip, database=mysql_connection_database, user=mysql_connection_user, password=mysql_connection_pw,
auth_plugin='mysql_native_password')) as cnx:
with closing(cnx.cursor()) as cur:
sql_statement = f"""DELETE FROM unloze_css_autism_bot.`bot movement input`"""
cur.execute(sql_statement)
cnx.commit()
if __name__ == '__main__':
atexit.register(exit_handler)
resetCfgInputShortWait()
mysql_check_if_connected()
checkbotteam()
print('reached mysql _get_player_info')
mysql_reset_input()
organize_player_info([False, True])
mysql_check_messages()
print('reached deadlock')
deadlock()
#/home/gameservers/.steam/debian-installation/steamapps/common/Counter-Strike Source/cstrike/cfg/autoexec.cfg:
#/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/cfg/autoexec.cfg:
#alias loop "exec looptest.cfg; wait 5; loop;"; wait 5; loop;
#-condebug
#cd /home/nonroot/.steam/
#cd /home/gameservers/.steam/debian-installation/
#./steam.sh -applaunch 240 -textmode -textmessagedebug -novid -nosound -noipx -nojoy -noshaderapi +exec looptest.cfg
#cd /home/gameservers/ze_runner_files
#./play.sh
#screen -A -d -m -S ze_runner ./play.sh

View File

@ -14,14 +14,11 @@
int present = 0;
int targethuman = 0;
int stuckcounterX = 0;
int stuckcounterY = 0;
Database database_connection_input;
int stuckcounterx = 0;
int stuckcountery = 0;
//bot input
int row_counter = 0;
int stuckX = 0;
int stuckY = 0;
char keyinput[rows_entry_cap][generic_length];
float clientangles[rows_entry_cap][3];
float xyz[rows_entry_cap][3];
@ -55,12 +52,6 @@ public void OnPluginStart()
HookEvent("round_start", Event_RoundStart, EventHookMode_PostNoCopy);
HookEvent("player_team", event_playerteam, EventHookMode_PostNoCopy);
//global DB
char error_connect[generic_length];
if (SQL_CheckConfig("css_autism_bot_info"))
database_connection_input = SQL_Connect("css_autism_bot_info", true, error_connect, sizeof(error_connect));
if (database_connection_input == null)
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to maria-DB! %s", error_connect);
//mysql
sql_create_table();
}
@ -79,20 +70,18 @@ public Action cmd_talk(int client, int args)
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)
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to maria-DB!");
return Plugin_Handled;
char query_start[generic_length * 2];
Format(query_start, sizeof(query_start), "INSERT INTO unloze_css_autism_bot.`chatting` (`chatmessage`, `responsemessage`) VALUES ('%s', '')", info);
//PrintToChatAll("query_start: %s", query_start);
mysql_exec_prepared_statement(database_connection, query_start);
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;
return Plugin_Handled;
}
public void OnPluginEnd()
{
delete database_connection_input;
}
public Action event_playerteam(Event event, const char[] name, bool dontBroadcast)
{
int client = GetClientOfUserId(event.GetInt("userid"));
@ -196,43 +185,21 @@ public Action recursive_pressing(Handle timer, any data)
xyz[row_counter][0] = dx;
xyz[row_counter][1] = dy;
xyz[row_counter][2] = dz;
float flVel[3];
GetEntPropVector(present, Prop_Data, "m_vecAbsVelocity", flVel);
int stuckcap = 3;
float mincapvelocity = 10.0;
if (flVel[0] < mincapvelocity)
{
stuckcounterX++;
if (stuckcounterX > stuckcap)
{
stuckcounterX = 0;
stuckX = 1;
}
}
if (flVel[1] < mincapvelocity)
{
stuckcounterY++;
if (stuckcounterY > stuckcap)
{
stuckcounterY = 0;
stuckY = 1;
}
}
}
int keys = GetClientButtons(targethuman);
if (keys & IN_FORWARD)
StrCat(keyinput[row_counter], sizeof(keyinput[]), "-back; wait 5; +forward; wait 5; ");
Format(keyinput[row_counter], sizeof(keyinput[]), "-back; wait 5; +forward; wait 5; ");
else if (keys & IN_BACK)
StrCat(keyinput[row_counter], sizeof(keyinput[]), "-forward; wait 5; +back; wait 5; ");
if (keys & IN_MOVELEFT)
StrCat(keyinput[row_counter], sizeof(keyinput[]), "-moveright; wait 5; +moveleft; wait 5; ");
else if (keys & IN_MOVERIGHT)
StrCat(keyinput[row_counter], sizeof(keyinput[]), "-moveleft; wait 5; +moveright; wait 5; ");
if (keys & IN_JUMP)
StrCat(keyinput[row_counter], sizeof(keyinput[]), "+jump; wait 5; ");
if (keys & IN_DUCK)
StrCat(keyinput[row_counter], sizeof(keyinput[]), "+duck; wait 5; ");
Format(keyinput[row_counter], sizeof(keyinput[]), "-forward; wait 5; +back; wait 5; ");
if (keys & IN_MOVELEFT && StrContains(keyinput[row_counter], "moveleft", false) == -1)
Format(keyinput[row_counter], sizeof(keyinput[]), "%s -moveright; wait 5; +moveleft; wait 5; ", keyinput[row_counter]);
else if (keys & IN_MOVERIGHT && StrContains(keyinput[row_counter], "moveright", false) == -1)
Format(keyinput[row_counter], sizeof(keyinput[]), "%s -moveleft; wait 5; +moveright; wait 5; ", keyinput[row_counter]);
if (keys & IN_JUMP && StrContains(keyinput[row_counter], "jump", false) == -1)
Format(keyinput[row_counter], sizeof(keyinput[]), "%s +jump; wait 5; ", keyinput[row_counter]);
if (keys & IN_DUCK && StrContains(keyinput[row_counter], "duck", false) == -1)
Format(keyinput[row_counter], sizeof(keyinput[]), "%s +duck; wait 5; ", keyinput[row_counter]);
GetClientAbsAngles(targethuman, clientangles[row_counter]);
//PrintToChatAll("targethuman: %N", targethuman);
}
@ -278,17 +245,17 @@ public void sql_create_table()
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)
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to maria-DB!");
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`))");
mysql_exec_prepared_statement(database_connection, query_start);
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)");
mysql_exec_prepared_statement(database_connection, query_start);
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)");
mysql_exec_prepared_statement(database_connection, query_start);
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)");
mysql_exec_prepared_statement(database_connection, query_start);
SQL_TQuery(database_connection, DummyCallbackSimple, query_start);
delete database_connection;
}
@ -299,10 +266,11 @@ public void mysql_clean_movement_input()
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)
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to maria-DB!");
return;
char query_start[generic_length];
Format(query_start, sizeof(query_start), "delete from unloze_css_autism_bot.`bot movement input`");
mysql_exec_prepared_statement(database_connection, query_start);
SQL_TQuery(database_connection, DummyCallbackSimple, query_start);
delete database_connection;
}
public void mysql_update_playercount()
@ -312,10 +280,10 @@ public void mysql_update_playercount()
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)
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to maria-DB!");
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);
mysql_exec_prepared_statement(database_connection, query_start);
SQL_TQuery(database_connection, DummyCallbackSimple, query_start);
delete database_connection;
}
@ -326,10 +294,11 @@ public void mysql_bot_not_spec()
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)
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to maria-DB!");
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)");
mysql_exec_prepared_statement(database_connection, query_start);
SQL_TQuery(database_connection, DummyCallbackSimple, query_start);
delete database_connection;
}
public void mysql_enable_disable_connected(int state)
@ -339,72 +308,91 @@ public void mysql_enable_disable_connected(int state)
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)
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to maria-DB!");
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);
mysql_exec_prepared_statement(database_connection, 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)
{
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to maria-DB!");
return;
}
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];
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), " ");
for (int i = 0; i < 3; i++)
if (xyz[iterator][0] != 0 || xyz[iterator][1] != 0 || xyz[iterator][2] != 0)
{
clientangles[iterator][i] = 0.0;
xyz[iterator][i] = 0.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;
if (stuckX)
stuckX = !stuckX;
if (stuckY)
stuckY = !stuckY;
int querylen = strlen(query_start);
query_start[querylen - 1] = '\0';
//debugging
//PrintToChatAll("query_start final length: %i", querylen);
/*
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, "w");
inputfile = OpenFile(g_sConfigzones, "a+");
if (inputfile != INVALID_HANDLE)
{
WriteFileLine(inputfile, "%s", query_start);
}
delete inputfile;
*/
//mysql_exec_prepared_statement(database_connection_input, query_start);
SQL_TQuery(database_connection_input, DummyCallbackSimple, query_start);
}
public void mysql_exec_prepared_statement(Database database_connection, char []query_statement)
{
char error[generic_length];
DBStatement create_statement = SQL_PrepareQuery(database_connection, query_statement, error, sizeof(error));
if (create_statement == INVALID_HANDLE)
{
CloseHandle(create_statement);
return;
}
SQL_Execute(create_statement);
CloseHandle(create_statement);
if (testdebug)
SQL_TQuery(database_connection, DummyCallbackSimple, query_start);
delete database_connection;
}
public void DummyCallbackSimple(Handle hOwner, Handle hChild, const char[] err, DataPack pack1)