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:
jenzur 2020-05-21 00:19:49 +02:00
parent 80ec1f3f0d
commit 21b0456f84
2 changed files with 131 additions and 108 deletions

View File

@ -7,12 +7,16 @@ import string
import random import random
import time import time
import mysql.connector import mysql.connector
from mysql.connector import pooling
from mysql.connector import Error from mysql.connector import Error
from settings import mysql_connection_ip, mysql_connection_user, mysql_connection_pw, mysql_connection_database 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/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( return mysql.connector.connect(
host=mysql_connection_ip, host=mysql_connection_ip,
user=mysql_connection_user, user=mysql_connection_user,
@ -50,7 +54,7 @@ def checkbotteam():
connectionTimer.start() connectionTimer.start()
def mysql_check_spectator(): def mysql_check_spectator():
cnx = get_connection() cnx = mysql_connection_pool.get_connection()
cur = cnx.cursor() cur = cnx.cursor()
sql_statement = f"""SELECT spectate from unloze_css_autism_bot.`bot status`""" sql_statement = f"""SELECT spectate from unloze_css_autism_bot.`bot status`"""
cur.execute(sql_statement) cur.execute(sql_statement)
@ -63,105 +67,103 @@ def mysql_check_spectator():
cnx.close() cnx.close()
def mysql_get_player_info(movement_list): def mysql_get_player_info(movement_list):
cnx = get_connection() cnx = mysql_connection_pool.get_connection()
cur = cnx.cursor() cur = cnx.cursor()
sql_statement = f"""SELECT * from unloze_css_autism_bot.`bot movement input` ORDER BY entry_time LIMIT 1""" 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`" sql_row_count = "SELECT COUNT(*) FROM unloze_css_autism_bot.`bot movement input`"
cur.execute(sql_statement) cur.execute(sql_statement)
result = cur.fetchall() result = cur.fetchall()
cur.execute(sql_row_count) cur.execute(sql_row_count)
result_count = cur.fetchone()[0] result_count = cur.fetchone()[0]
if result: if result:
result = result[0] result = result[0]
movement_input = result[0] movement_input = result[0]
client_angles = [result[1], result[2], result[3]] client_angles = [result[1], result[2], result[3]]
xyz_difference = [result[4], result[5], result[6]] xyz_difference = [result[4], result[5], result[6]]
client_coordinates = result[7], result[8], result[9] client_coordinates = result[7], result[8], result[9]
hunt_or_mimic = result[10] hunt_or_mimic = result[10]
stuckX = result[11] stuckX = result[11]
stuckY = result[12] stuckY = result[12]
strInput = "-attack; wait 5; -jump; wait 5; -duck; wait 5; +attack; wait 5; cl_minmodels 1; " 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[0]: ', movement_list[0], '#0 = forward, 1 = back, 2 = none')
print('movement_list[1]: ', movement_list[1], '#false = left, true = right') print('movement_list[1]: ', movement_list[1], '#0 = left, 1 = right, 2 = none')
print('result_count: ', result_count) print('result_count: ', result_count)
axis_distance = 105 axis_distance = 105
#print('stuckX: ', stuckX, ' stuckY: ', stuckY) print('stuckX: ', stuckX, ' stuckY: ', stuckY)
if stuckX and xyz_difference[0] < -axis_distance or xyz_difference[0] > axis_distance: if stuckX:
movement_list[0] = not movement_list[0] if movement_list[0] == 0:
strInput += " +jump; wait 3; +duck; wait 5;" movement_list[0] = 1
if stuckY and xyz_difference[1] < -axis_distance or xyz_difference[1] > axis_distance: elif movement_list[0] == 1:
movement_list[1] = not movement_list[1] movement_list[0] = 0
strInput += " +jump; wait 3; +duck; wait 5;" strInput += " +jump; wait 3; +duck; wait 5;"
if hunt_or_mimic: if stuckY:
print('hunt_or_mimic enabled') if movement_list[1] == 0:
bool_x_axis_permit = True movement_list[1] = 1
bool_y_axis_permit = True elif movement_list[1] == 1:
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]}' movement_list[1] = 0
and client_coord_2 = '{client_coordinates[2]}' LIMIT 1""" strInput += " +jump; wait 3; +duck; wait 5;"
cur.execute(sql_statement) if hunt_or_mimic:
entry_time = cur.fetchall()[0][0] print('hunt_or_mimic enabled')
#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 sql_statement = f"""SELECT entry_time FROM unloze_css_autism_bot.`bot movement input` where client_coord_0 = '{client_coordinates[0]}' and
if not hunt_or_mimic: client_coord_1 = '{client_coordinates[1]}' and client_coord_2 = '{client_coordinates[2]}' LIMIT 1"""
if xyz_difference[0] > axis_distance: cur.execute(sql_statement)
movement_list[0] = True entry_time = cur.fetchall()[0][0]
elif xyz_difference[0] < -axis_distance: if not hunt_or_mimic:
movement_list[0] = False if xyz_difference[0] > axis_distance:
else: movement_list[0] = 1
bool_x_axis_permit = False elif xyz_difference[0] < -axis_distance:
strInput += " -back; wait 5; -forward; wait 5;" movement_list[0] = 0
if xyz_difference[1] < -axis_distance: else:
movement_list[1] = True movement_list[0] = 2 #strInput += " -back; wait 5; -forward; wait 5;"
elif xyz_difference[1] > axis_distance:
movement_list[1] = False if xyz_difference[1] < -axis_distance:
else: movement_list[1] = 1
bool_y_axis_permit = False elif xyz_difference[1] > axis_distance:
strInput += " -moveright; wait 5; -moveleft; wait 5;" movement_list[1] = 0
print('xyz_difference[0]: ', xyz_difference[0]) else:
print('xyz_difference[1]: ', xyz_difference[1]) movement_list[1] = 2 #strInput += " -moveright; wait 5; -moveleft; wait 5;"
strInput += f""" setang 0 180 0; wait 5; """ print('xyz_difference[0]: ', xyz_difference[0])
else: print('xyz_difference[1]: ', xyz_difference[1])
#print('client_angles: ', client_angles) strInput += f""" setang 0 180 0; wait 5; """
print('movement_input: ', movement_input) else:
strInput += f""" setang {client_angles[0]} {client_angles[1]} {client_angles[2]}; wait 5; {movement_input};""" #print('client_angles: ', client_angles)
#if xyz_difference[0] > -axis_distance and xyz_difference[0] < axis_distance and xyz_difference[1] > -axis_distance and xyz_difference[1] < axis_distance: print('movement_input: ', movement_input)
sql_statement = f"""DELETE FROM unloze_css_autism_bot.`bot movement input` where entry_time <= '{entry_time}'""" strInput += f"""setang {client_angles[0]} {client_angles[1]} {client_angles[2]}; wait 5; {movement_input}; wait 5;"""
cur.execute(sql_statement) sql_statement = f"""DELETE FROM unloze_css_autism_bot.`bot movement input` where entry_time <= '{entry_time}'"""
print('Deleted ', cur.rowcount, ' rows before/during entry_time:', entry_time) cur.execute(sql_statement)
cnx.commit() print('Deleted ', cur.rowcount, ' rows before/during entry_time:', entry_time)
if xyz_difference[0] > -25 and xyz_difference[0] < 25: cnx.commit()
strInput += "-back; wait 5; -forward; wait 5;"
if xyz_difference[1] > -25 and xyz_difference[1] < 25: if not hunt_or_mimic:
strInput += "-moveright; wait 5; -moveleft; wait 5;" if movement_list[0] == 1:
if not hunt_or_mimic: strInput += " -back; wait 5; +forward; wait 5;"
if bool_x_axis_permit: elif movement_list[0] == 0:
if movement_list[0]: strInput += " -forward; wait 5; +back; wait 5;"
strInput += " -back; wait 5; +forward; wait 5;" if movement_list[1] == 1:
else: strInput += " -moveleft; wait 5; +moveright; wait 5;"
strInput += " -forward; wait 5; +back; wait 5;" elif movement_list[1] == 0:
if bool_y_axis_permit: strInput += " -moveright; wait 5; +moveleft; wait 5;"
if movement_list[1]: sql_statement = f"""DELETE FROM unloze_css_autism_bot.`bot movement input` where entry_time <= '{entry_time}'"""
strInput += " -moveleft; wait 5; +moveright; wait 5;" cur.execute(sql_statement)
else: #print('sql_statement: ', sql_statement)
strInput += " -moveright; wait 5; +moveleft; wait 5;" print('Deleted ', cur.rowcount, ' rows before/during entry_time:', entry_time)
cnx.commit()
sql_statement = f"""DELETE FROM unloze_css_autism_bot.`bot movement input` where entry_time <= '{entry_time}'""" #print('strInput final:', strInput)
cur.execute(sql_statement) global chatmsg
#print('sql_statement: ', sql_statement) strInput += f" {chatmsg}"
#print('Deleted ', cur.rowcount, ' rows before/during entry_time:', entry_time) chatmsg = ""
cnx.commit() writeCfgInput(strInput)
#print('strInput final:', strInput) time.sleep(0.10)
writeCfgInput(strInput) writeCfgInput("wait 5;")
time.sleep(0.10) cur.close()
writeCfgInput("wait 5;") cnx.close()
cur.close() run_delay = 0.05 #0.05
cnx.close() connectionTimer = Timer(run_delay, mysql_get_player_info, args=[movement_list])
run_delay = 0.05 #0.05 connectionTimer.daemon = True
connectionTimer = Timer(run_delay, mysql_get_player_info, args=[movement_list]) connectionTimer.start()
connectionTimer.daemon = True
connectionTimer.start()
def mysql_check_messages(): def mysql_check_messages():
cnx = get_connection() cnx = mysql_connection_pool.get_connection()
cur = cnx.cursor() cur = cnx.cursor()
sql_statement = """SELECT responsemessage FROM unloze_css_autism_bot.chatting WHERE responsemessage != '' LIMIT 1""" sql_statement = """SELECT responsemessage FROM unloze_css_autism_bot.chatting WHERE responsemessage != '' LIMIT 1"""
cur.execute(sql_statement) cur.execute(sql_statement)
@ -170,20 +172,20 @@ def mysql_check_messages():
result = result[0][0] result = result[0][0]
str = f"""say {result}""" str = f"""say {result}"""
print('str: ', str) print('str: ', str)
writeCfgInput(str) global chatmsg
time.sleep(0.9) chatmsg = str
sql_statement = f"""DELETE FROM unloze_css_autism_bot.`chatting` WHERE `responsemessage` = '{result}'""" sql_statement = f"""DELETE FROM unloze_css_autism_bot.`chatting` WHERE `responsemessage` = '{result}'"""
print('sql_statement: ', sql_statement) print('sql_statement: ', sql_statement)
cur.execute(sql_statement) cur.execute(sql_statement)
cnx.commit() cnx.commit()
cur.close() cur.close()
cnx.close() cnx.close()
connectionTimer = Timer(2, mysql_check_messages) connectionTimer = Timer(0.5, mysql_check_messages)
connectionTimer.daemon = True connectionTimer.daemon = True
connectionTimer.start() connectionTimer.start()
def mysql_check_if_connected(): def mysql_check_if_connected():
cnx = get_connection() cnx = mysql_connection_pool.get_connection()
cur = cnx.cursor() cur = cnx.cursor()
sql_statement = """SELECT connected, playercount from unloze_css_autism_bot.`bot status`""" sql_statement = """SELECT connected, playercount from unloze_css_autism_bot.`bot status`"""
cur.execute(sql_statement) cur.execute(sql_statement)
@ -217,7 +219,7 @@ def mysql_check_if_connected():
cnx.close() cnx.close()
def mysql_reset_input(): def mysql_reset_input():
cnx = get_connection() cnx = mysql_connection_pool.get_connection()
cur = cnx.cursor() cur = cnx.cursor()
sql_statement = f"""DELETE FROM unloze_css_autism_bot.`bot movement input`""" sql_statement = f"""DELETE FROM unloze_css_autism_bot.`bot movement input`"""
cur.execute(sql_statement) cur.execute(sql_statement)
@ -248,4 +250,4 @@ if __name__ == '__main__':
#-condebug #-condebug
#cd /home/nonroot/.steam/ #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

View File

@ -128,13 +128,28 @@ public Action recursive_pressing(Handle timer, any data)
{ {
float present_bot_coords[3]; float present_bot_coords[3];
GetClientAbsOrigin(present, present_bot_coords); 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; hunt_or_mimic = false;
float lowest_distance = 1000000.0; float lowest_distance = 1000000.0;
for (int i = 1; i <= MaxClients; i++) 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]; float pos[3];
GetClientAbsOrigin(i, pos); GetClientAbsOrigin(i, pos);
float dx = present_bot_coords[0] - pos[0]; 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 //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); //PrintToChatAll("dist: %f", dist);
if (dist < distance_limit) if (dist < distance_limit)
hunt_or_mimic = true; hunt_or_mimic = true;
else
hunt_or_mimic = false;
dx = present_bot_coords[0] - target_human_coords[0]; dx = present_bot_coords[0] - target_human_coords[0];
dy = present_bot_coords[1] - target_human_coords[1]; dy = present_bot_coords[1] - target_human_coords[1];
dz = FloatAbs(present_bot_coords[2] - target_human_coords[2]); 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); GetEntPropVector(present, Prop_Data, "m_vecAbsVelocity", flVel);
int stuckX = 0; int stuckX = 0;
int stuckY = 0; int stuckY = 0;
int stuckcap = 6; int stuckcap = 3;
float mincapvelocity = 10.0; float mincapvelocity = 10.0;
if (flVel[0] < mincapvelocity) if (flVel[0] < mincapvelocity)
{ {