projects-jenz/AutismBotIngame/python/ingamefollowct.py

122 lines
3.9 KiB
Python
Raw Normal View History

2020-01-23 23:15:26 +01:00
import os
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
looptestPath = '/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/cfg/looptest.cfg'
consolelogPath = '/home/nonroot/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/console.log'
iterationCap = 150
def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
return ''.join(random.choice(chars) for _ in range(size))
def clearconsolelog():
open(consolelogPath, 'w').close()
def writeCfgInput(Input):
with open(looptestPath, 'w') as f:
f.write(Input)
def getconsoleOutputForStatus(input):
randomlygeneratedString = id_generator(11)
2020-01-26 02:29:34 +01:00
str = "status; wait 5; {0}; wait 5; exec looptest.cfg;".format(randomlygeneratedString)
2020-01-23 23:15:26 +01:00
print('writeCfgInput')
writeCfgInput(str)
checkConsoleOutput(randomlygeneratedString)
incrementer = 0
with open(consolelogPath, 'r') as f:
for line in f:
incrementer += 1
if incrementer > iterationCap: return True #cap before leaving the file again
if input in line: return False #found hostname which means connected
return True
def getConsoleOutputForTeams():
teamvalues = ['Spectactor', 'Terrorist', 'Counter-Terrorist']
randomlygeneratedString = id_generator(11)
2020-01-26 02:29:34 +01:00
str = "sm_teaminfo; wait 50; {0}; wait 5; exec looptest.cfg;".format(randomlygeneratedString)
2020-01-23 23:15:26 +01:00
while True:
writeCfgInput(str)
#is sm_team a command to show team?
#maybe instead say !teaminfo, add sourcemod command to autism_bot_info.sp to print team to chat instead
previousStr = ""
checkConsoleOutput(randomlygeneratedString)
with open(consolelogPath, 'r') as f:
for line in f:
print('getConsoleOutputForTeams line: ', line)
if randomlygeneratedString in line:
if teamvalues[2] in previousStr: return teamvalues[2]
elif teamvalues[1] in previousStr: return teamvalues[1]
return teamvalues[0]
previousStr = line
def checkConsoleOutput(input):
bool = False
#print('entered checkconsole output')
while not bool:
with open(consolelogPath, 'r') as f:
for line in f:
if input in line:
#print('line: ', line, ' \ninput: ', input)
bool = True
break
def resetCfgInputShortWait():
#getpos
randomlygeneratedString = id_generator(11)
print('randomlygeneratedString: ', randomlygeneratedString)
2020-01-26 02:29:34 +01:00
str = "wait 50; {0}; wait 50; exec looptest.cfg;".format(randomlygeneratedString)
2020-01-23 23:15:26 +01:00
with open(looptestPath, 'w') as f:
f.write(str)
checkConsoleOutput(randomlygeneratedString)
def exit_handler():
2020-01-26 02:29:34 +01:00
print('exithandler')
#resetCfgInputShortWait()
2020-01-23 23:15:26 +01:00
def joinTeam():
clearconsolelog()
randomlygeneratedString = id_generator(11)
2020-01-26 02:29:34 +01:00
str = "jointeam 2; wait 2; zspawn; wait 1; {0}; wait 5; exec looptest.cfg;".format(randomlygeneratedString)
2020-01-23 23:15:26 +01:00
writeCfgInput(str)
checkConsoleOutput(randomlygeneratedString)
def checkbotteam():
print('reached checkbotteam')
clearconsolelog()
team = getConsoleOutputForTeams()
print('team value: ', team)
if "Spectactor" in team:
joinTeam()
def checkIfConnected():
clearconsolelog()
2020-01-26 02:29:34 +01:00
randomlygeneratedString = id_generator(11)
str1 = "connect 151.80.230.149:27015; wait 5; {0}; wait 500; exec looptest.cfg;".format(randomlygeneratedString)
2020-01-23 23:15:26 +01:00
if (getconsoleOutputForStatus("hostname:")):
writeCfgInput(str1)
2020-01-26 02:29:34 +01:00
checkConsoleOutput(randomlygeneratedString)
2020-01-23 23:15:26 +01:00
resetCfgInputShortWait()
checkbotteam()
resetCfgInputShortWait()
followPlayer()
def followPlayer():
2020-01-26 02:29:34 +01:00
randomlygeneratedString = id_generator(11)
#setang 0 180 0;
default_input = "+attack; wait 50; cl_minmodels; wait 50; +right; wait 50; +jump; wait 50; -jump; wait 50; +forward; wait 50; {0}; wait 5; exec looptest.cfg;".format(randomlygeneratedString)
2020-01-23 23:15:26 +01:00
writeCfgInput(default_input)
2020-01-26 02:29:34 +01:00
checkConsoleOutput(randomlygeneratedString)
2020-01-23 23:15:26 +01:00
#print('start of method \n')
if __name__ == '__main__':
atexit.register(exit_handler)
clearconsolelog()
resetCfgInputShortWait()
checkIfConnected()