some updates to focusing on clients and changed connection ot be pooled. Edited /etc/mysql/my.ncnf to manually add version, was neccesary due to bugs
This commit is contained in:
parent
80ec1f3f0d
commit
21b0456f84
@ -7,12 +7,16 @@ import string
|
||||
import random
|
||||
import time
|
||||
import mysql.connector
|
||||
from mysql.connector import pooling
|
||||
from mysql.connector import Error
|
||||
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'
|
||||
chatmsg = ""
|
||||
|
||||
def get_connection():
|
||||
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,
|
||||
@ -50,7 +54,7 @@ def checkbotteam():
|
||||
connectionTimer.start()
|
||||
|
||||
def mysql_check_spectator():
|
||||
cnx = get_connection()
|
||||
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)
|
||||
@ -63,105 +67,103 @@ def mysql_check_spectator():
|
||||
cnx.close()
|
||||
|
||||
def mysql_get_player_info(movement_list):
|
||||
cnx = 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], '#false = forward, true = back')
|
||||
print('movement_list[1]: ', movement_list[1], '#false = left, true = right')
|
||||
print('result_count: ', result_count)
|
||||
axis_distance = 105
|
||||
#print('stuckX: ', stuckX, ' stuckY: ', stuckY)
|
||||
if stuckX and xyz_difference[0] < -axis_distance or xyz_difference[0] > axis_distance:
|
||||
movement_list[0] = not movement_list[0]
|
||||
strInput += " +jump; wait 3; +duck; wait 5;"
|
||||
if stuckY and xyz_difference[1] < -axis_distance or xyz_difference[1] > axis_distance:
|
||||
movement_list[1] = not movement_list[1]
|
||||
strInput += " +jump; wait 3; +duck; wait 5;"
|
||||
if hunt_or_mimic:
|
||||
print('hunt_or_mimic enabled')
|
||||
bool_x_axis_permit = True
|
||||
bool_y_axis_permit = True
|
||||
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]
|
||||
#once hunt_or_mimic is reached it should remain true until round restart or ct death, once close enough distance bot has to copy its input for rest of round
|
||||
if not hunt_or_mimic:
|
||||
if xyz_difference[0] > axis_distance:
|
||||
movement_list[0] = True
|
||||
elif xyz_difference[0] < -axis_distance:
|
||||
movement_list[0] = False
|
||||
else:
|
||||
bool_x_axis_permit = False
|
||||
strInput += " -back; wait 5; -forward; wait 5;"
|
||||
if xyz_difference[1] < -axis_distance:
|
||||
movement_list[1] = True
|
||||
elif xyz_difference[1] > axis_distance:
|
||||
movement_list[1] = False
|
||||
else:
|
||||
bool_y_axis_permit = False
|
||||
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};"""
|
||||
#if xyz_difference[0] > -axis_distance and xyz_difference[0] < axis_distance and xyz_difference[1] > -axis_distance and xyz_difference[1] < axis_distance:
|
||||
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)
|
||||
cnx.commit()
|
||||
if xyz_difference[0] > -25 and xyz_difference[0] < 25:
|
||||
strInput += "-back; wait 5; -forward; wait 5;"
|
||||
if xyz_difference[1] > -25 and xyz_difference[1] < 25:
|
||||
strInput += "-moveright; wait 5; -moveleft; wait 5;"
|
||||
if not hunt_or_mimic:
|
||||
if bool_x_axis_permit:
|
||||
if movement_list[0]:
|
||||
strInput += " -back; wait 5; +forward; wait 5;"
|
||||
else:
|
||||
strInput += " -forward; wait 5; +back; wait 5;"
|
||||
if bool_y_axis_permit:
|
||||
if movement_list[1]:
|
||||
strInput += " -moveleft; wait 5; +moveright; wait 5;"
|
||||
else:
|
||||
strInput += " -moveright; wait 5; +moveleft; wait 5;"
|
||||
|
||||
sql_statement = f"""DELETE FROM unloze_css_autism_bot.`bot movement input` where entry_time <= '{entry_time}'"""
|
||||
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)
|
||||
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()
|
||||
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;"
|
||||
|
||||
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)
|
||||
cnx.commit()
|
||||
|
||||
if not hunt_or_mimic:
|
||||
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;"
|
||||
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}'"""
|
||||
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()
|
||||
|
||||
def mysql_check_messages():
|
||||
cnx = get_connection()
|
||||
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)
|
||||
@ -170,20 +172,20 @@ def mysql_check_messages():
|
||||
result = result[0][0]
|
||||
str = f"""say {result}"""
|
||||
print('str: ', str)
|
||||
writeCfgInput(str)
|
||||
time.sleep(0.9)
|
||||
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(2, mysql_check_messages)
|
||||
connectionTimer = Timer(0.5, mysql_check_messages)
|
||||
connectionTimer.daemon = True
|
||||
connectionTimer.start()
|
||||
|
||||
def mysql_check_if_connected():
|
||||
cnx = get_connection()
|
||||
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)
|
||||
@ -217,7 +219,7 @@ def mysql_check_if_connected():
|
||||
cnx.close()
|
||||
|
||||
def mysql_reset_input():
|
||||
cnx = get_connection()
|
||||
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)
|
||||
@ -248,4 +250,4 @@ if __name__ == '__main__':
|
||||
|
||||
#-condebug
|
||||
#cd /home/nonroot/.steam/
|
||||
#./steam.sh -applaunch 240 -textmode -textmessagedebug -novid -nosound -noipx -nojoy -noshaderapi +exec looptest.cfg
|
||||
#./steam.sh -applaunch 240 -textmode -textmessagedebug -novid -nosound -noipx -nojoy -noshaderapi +exec looptest.cfg
|
||||
|
@ -128,13 +128,28 @@ public Action recursive_pressing(Handle timer, any data)
|
||||
{
|
||||
float present_bot_coords[3];
|
||||
GetClientAbsOrigin(present, present_bot_coords);
|
||||
if (!IsValidClient(targethuman) || GetClientTeam(targethuman) != 3 || !IsPlayerAlive(targethuman))
|
||||
int targeteam = 0;
|
||||
if (GetClientTeam(present) != 3)
|
||||
{
|
||||
//2 = autismo is zm and follows closest zm
|
||||
targeteam = 2;
|
||||
}
|
||||
else
|
||||
{
|
||||
targeteam = 3;
|
||||
}
|
||||
if (!IsValidClient(targethuman) || GetClientTeam(targethuman) != targeteam || !IsPlayerAlive(targethuman))
|
||||
{
|
||||
hunt_or_mimic = false;
|
||||
float lowest_distance = 1000000.0;
|
||||
for (int i = 1; i <= MaxClients; i++)
|
||||
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == 3 && i != present)
|
||||
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == targeteam && i != present)
|
||||
{
|
||||
float flVel[3];
|
||||
float minvelocity = 10.0;
|
||||
GetEntPropVector(i, Prop_Data, "m_vecAbsVelocity", flVel);
|
||||
if (flVel[0] < minvelocity && flVel[1] < minvelocity)
|
||||
continue;
|
||||
float pos[3];
|
||||
GetClientAbsOrigin(i, pos);
|
||||
float dx = present_bot_coords[0] - pos[0];
|
||||
@ -148,6 +163,10 @@ public Action recursive_pressing(Handle timer, any data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
//get bot in distance, mimic all input until CT dead/round over
|
||||
|
||||
|
||||
@ -168,6 +187,8 @@ public Action recursive_pressing(Handle timer, any data)
|
||||
//PrintToChatAll("dist: %f", dist);
|
||||
if (dist < distance_limit)
|
||||
hunt_or_mimic = true;
|
||||
else
|
||||
hunt_or_mimic = false;
|
||||
dx = present_bot_coords[0] - target_human_coords[0];
|
||||
dy = present_bot_coords[1] - target_human_coords[1];
|
||||
dz = FloatAbs(present_bot_coords[2] - target_human_coords[2]);
|
||||
@ -329,7 +350,7 @@ public void mysql_send_input(char []keyinput, float clientangles[3], float xyz[3
|
||||
GetEntPropVector(present, Prop_Data, "m_vecAbsVelocity", flVel);
|
||||
int stuckX = 0;
|
||||
int stuckY = 0;
|
||||
int stuckcap = 6;
|
||||
int stuckcap = 3;
|
||||
float mincapvelocity = 10.0;
|
||||
if (flVel[0] < mincapvelocity)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user