2020-01-23 23:15:26 +01:00
|
|
|
import os
|
2020-04-22 00:17:28 +02:00
|
|
|
import sys
|
2020-01-23 23:15:26 +01:00
|
|
|
import subprocess
|
|
|
|
import atexit
|
2020-01-26 02:29:34 +01:00
|
|
|
from threading import Timer
|
2020-01-23 23:15:26 +01:00
|
|
|
import string
|
|
|
|
import random
|
2020-02-14 23:27:57 +01:00
|
|
|
import time
|
2020-04-22 00:17:28 +02:00
|
|
|
import mysql.connector
|
2020-05-21 00:19:49 +02:00
|
|
|
from mysql.connector import pooling
|
2020-04-22 00:17:28 +02:00
|
|
|
from mysql.connector import Error
|
|
|
|
from settings import mysql_connection_ip, mysql_connection_user, mysql_connection_pw, mysql_connection_database
|
2020-01-23 23:15:26 +01:00
|
|
|
|
|
|
|
looptestPath = '/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/cfg/looptest.cfg'
|
2020-05-21 00:19:49 +02:00
|
|
|
chatmsg = ""
|
2020-02-14 23:27:57 +01:00
|
|
|
|
2020-05-21 00:19:49 +02:00
|
|
|
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():
|
2020-04-22 00:17:28 +02:00
|
|
|
return mysql.connector.connect(
|
|
|
|
host=mysql_connection_ip,
|
|
|
|
user=mysql_connection_user,
|
|
|
|
passwd=mysql_connection_pw,
|
|
|
|
database=mysql_connection_database)
|
2020-01-23 23:15:26 +01:00
|
|
|
|
|
|
|
def writeCfgInput(Input):
|
|
|
|
with open(looptestPath, 'w') as f:
|
|
|
|
f.write(Input)
|
2020-02-14 23:27:57 +01:00
|
|
|
|
2020-01-23 23:15:26 +01:00
|
|
|
|
|
|
|
def resetCfgInputShortWait():
|
2020-04-22 00:17:28 +02:00
|
|
|
str = "{0}; wait 5;"
|
2020-01-23 23:15:26 +01:00
|
|
|
with open(looptestPath, 'w') as f:
|
|
|
|
f.write(str)
|
2020-04-22 00:17:28 +02:00
|
|
|
time.sleep(0.5)
|
2020-01-23 23:15:26 +01:00
|
|
|
|
|
|
|
def exit_handler():
|
2020-02-09 00:26:05 +01:00
|
|
|
print('reached exithandler')
|
|
|
|
str = "wait 5;"
|
|
|
|
with open(looptestPath, 'w') as f:
|
|
|
|
f.write(str)
|
2020-01-26 02:29:34 +01:00
|
|
|
|
2020-01-23 23:15:26 +01:00
|
|
|
def joinTeam():
|
2020-04-22 00:17:28 +02:00
|
|
|
str = "jointeam 2; wait 2; zspawn; wait 1; {0}; wait 5;"
|
2020-01-23 23:15:26 +01:00
|
|
|
writeCfgInput(str)
|
2020-04-22 00:17:28 +02:00
|
|
|
time.sleep(4.5)
|
|
|
|
print('jointeam func: ')
|
2020-01-23 23:15:26 +01:00
|
|
|
|
|
|
|
def checkbotteam():
|
2020-04-22 00:17:28 +02:00
|
|
|
mysql_check_spectator()
|
2020-02-14 23:27:57 +01:00
|
|
|
resetCfgInputShortWait()
|
|
|
|
connectionTimer = Timer(20.0, checkbotteam)
|
|
|
|
connectionTimer.daemon = True
|
|
|
|
connectionTimer.start()
|
2020-01-23 23:15:26 +01:00
|
|
|
|
2020-04-22 00:17:28 +02:00
|
|
|
def mysql_check_spectator():
|
2020-05-21 00:19:49 +02:00
|
|
|
cnx = mysql_connection_pool.get_connection()
|
2020-04-22 00:17:28 +02:00
|
|
|
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_get_player_info(movement_list):
|
2020-05-21 00:19:49 +02:00
|
|
|
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()
|
2020-05-05 23:52:01 +02:00
|
|
|
|
|
|
|
def mysql_check_messages():
|
2020-05-21 00:19:49 +02:00
|
|
|
cnx = mysql_connection_pool.get_connection()
|
2020-05-05 23:52:01 +02:00
|
|
|
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)
|
2020-05-21 00:19:49 +02:00
|
|
|
global chatmsg
|
|
|
|
chatmsg = str
|
2020-05-05 23:52:01 +02:00
|
|
|
sql_statement = f"""DELETE FROM unloze_css_autism_bot.`chatting` WHERE `responsemessage` = '{result}'"""
|
|
|
|
print('sql_statement: ', sql_statement)
|
2020-04-22 00:17:28 +02:00
|
|
|
cur.execute(sql_statement)
|
|
|
|
cnx.commit()
|
|
|
|
cur.close()
|
|
|
|
cnx.close()
|
2020-05-21 00:19:49 +02:00
|
|
|
connectionTimer = Timer(0.5, mysql_check_messages)
|
2020-02-09 00:26:05 +01:00
|
|
|
connectionTimer.daemon = True
|
|
|
|
connectionTimer.start()
|
|
|
|
|
2020-04-22 00:17:28 +02:00
|
|
|
def mysql_check_if_connected():
|
2020-05-21 00:19:49 +02:00
|
|
|
cnx = mysql_connection_pool.get_connection()
|
2020-04-22 00:17:28 +02:00
|
|
|
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:
|
2020-05-06 01:24:15 +02:00
|
|
|
str1 = "connect 151.80.230.149:27015;"
|
2020-04-22 00:17:28 +02:00
|
|
|
writeCfgInput(str1)
|
2020-05-05 23:52:01 +02:00
|
|
|
time.sleep(0.2)
|
|
|
|
writeCfgInput("wait 5;")
|
2020-04-22 00:17:28 +02:00
|
|
|
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)
|
2020-02-09 00:26:05 +01:00
|
|
|
connectionTimer.daemon = True
|
|
|
|
connectionTimer.start()
|
2020-04-22 00:17:28 +02:00
|
|
|
cur.close()
|
|
|
|
cnx.close()
|
2020-02-28 22:00:22 +01:00
|
|
|
|
2020-05-05 23:52:01 +02:00
|
|
|
def mysql_reset_input():
|
2020-05-21 00:19:49 +02:00
|
|
|
cnx = mysql_connection_pool.get_connection()
|
2020-05-05 23:52:01 +02:00
|
|
|
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()
|
|
|
|
|
2020-02-09 00:26:05 +01:00
|
|
|
def deadlock():
|
|
|
|
try:
|
|
|
|
while True: 42 == 42
|
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
2020-01-23 23:15:26 +01:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
atexit.register(exit_handler)
|
|
|
|
resetCfgInputShortWait()
|
2020-04-22 00:17:28 +02:00
|
|
|
mysql_check_if_connected()
|
2020-02-14 23:27:57 +01:00
|
|
|
checkbotteam()
|
2020-04-22 00:17:28 +02:00
|
|
|
print('reached mysql _get_player_info')
|
2020-05-05 23:52:01 +02:00
|
|
|
mysql_reset_input()
|
|
|
|
mysql_get_player_info([False, True])
|
|
|
|
mysql_check_messages()
|
2020-02-09 00:26:05 +01:00
|
|
|
print('reached deadlock')
|
|
|
|
deadlock()
|
|
|
|
|
2020-04-22 00:17:28 +02:00
|
|
|
#/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/cfg/autoexec.cfg:
|
2020-05-05 23:52:01 +02:00
|
|
|
#alias loop "exec looptest.cfg; wait 5; loop;"; wait 5; loop;
|
2020-04-22 00:17:28 +02:00
|
|
|
|
|
|
|
#-condebug
|
|
|
|
#cd /home/nonroot/.steam/
|
2020-05-21 00:19:49 +02:00
|
|
|
#./steam.sh -applaunch 240 -textmode -textmessagedebug -novid -nosound -noipx -nojoy -noshaderapi +exec looptest.cfg
|