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-08-19 00:12:39 +02:00
|
|
|
import signal
|
2020-02-14 23:27:57 +01:00
|
|
|
import time
|
2020-07-03 22:50:21 +02:00
|
|
|
import socket
|
|
|
|
import codecs
|
2020-08-30 20:00:02 +02:00
|
|
|
import datetime
|
2020-01-23 23:15:26 +01:00
|
|
|
|
2020-06-12 02:01:39 +02:00
|
|
|
looptestPath = '/home/gameservers/.steam/steam/steamapps/common/Counter-Strike Source/cstrike/cfg/looptest.cfg'
|
2020-05-21 00:19:49 +02:00
|
|
|
chatmsg = ""
|
2020-07-24 00:25:03 +02:00
|
|
|
ladder_counter = 0
|
2020-02-14 23:27:57 +01:00
|
|
|
|
2020-01-23 23:15:26 +01:00
|
|
|
def writeCfgInput(Input):
|
|
|
|
with open(looptestPath, 'w') as f:
|
|
|
|
f.write(Input)
|
2020-06-12 02:01:39 +02:00
|
|
|
|
2020-01-23 23:15:26 +01:00
|
|
|
def resetCfgInputShortWait():
|
2020-06-12 02:01:39 +02:00
|
|
|
str = "wait 5; "
|
2020-01-23 23:15:26 +01:00
|
|
|
with open(looptestPath, 'w') as f:
|
|
|
|
f.write(str)
|
2020-08-19 00:12:39 +02:00
|
|
|
time.sleep(0.2)
|
2020-01-23 23:15:26 +01:00
|
|
|
|
|
|
|
def exit_handler():
|
2020-06-12 02:01:39 +02:00
|
|
|
print('reached exithandler')
|
|
|
|
resetCfgInputShortWait()
|
2020-01-26 02:29:34 +01:00
|
|
|
|
2020-01-23 23:15:26 +01:00
|
|
|
def joinTeam():
|
2020-08-30 20:00:02 +02:00
|
|
|
str = "jointeam 2; joinclass 3; zspawn;"
|
|
|
|
writeCfgInput(str)
|
|
|
|
time.sleep(4.5)
|
|
|
|
print('jointeam func: ')
|
2020-07-21 01:03:06 +02:00
|
|
|
|
2020-08-01 01:15:39 +02:00
|
|
|
def bot_process_surf(input_line):
|
|
|
|
bot_surf_plane = input_line[input_line.index("surfing:") + len("surfing:"):]
|
|
|
|
bot_surf_plane = bot_surf_plane.strip()
|
|
|
|
bot_surf_plane = [float(i.replace('\U00002013', '-')) for i in bot_surf_plane.split(' ')]
|
|
|
|
#X axis positive = hold A
|
|
|
|
#X axis negative = hold D
|
|
|
|
#if Y axis = 0.0 use X instead
|
|
|
|
#Y axis negative = hold A
|
|
|
|
#Y axis positive = hold D
|
|
|
|
strInput = "-forward; wait 3; "
|
|
|
|
if bot_surf_plane[1] < 0.0:
|
|
|
|
strInput += "+moveleft; wait 3; "
|
|
|
|
elif bot_surf_plane[1] > 0.0:
|
|
|
|
strInput += "+moveright; wait 3;"
|
|
|
|
elif bot_surf_plane[0] < 0.0:
|
|
|
|
strInput += "+moveleft; wait 3; "
|
|
|
|
elif bot_surf_plane[0] > 0.0:
|
|
|
|
strInput += "+moveright; wait 3; "
|
|
|
|
print('bot surfing bot_surf_plane: ', bot_surf_plane)
|
|
|
|
writeCfgInput(strInput)
|
|
|
|
time.sleep(0.3)
|
|
|
|
writeCfgInput("wait 5;")
|
|
|
|
|
2020-07-21 01:03:06 +02:00
|
|
|
def bot_process_keyinput(input_line):
|
|
|
|
movement_input = input_line[input_line.index("keyinput:") + len("keyinput:"):input_line.index("dist_target:")]
|
|
|
|
dist_target = input_line[input_line.index("dist_target:") + len("dist_target:"):]
|
|
|
|
dist_target = float(dist_target)
|
2020-08-01 01:15:39 +02:00
|
|
|
strInput = f"""{movement_input}; wait 5; -jump; wait 5; -duck; wait 5; """
|
2020-07-21 01:03:06 +02:00
|
|
|
writeCfgInput(strInput)
|
2020-08-30 20:00:02 +02:00
|
|
|
print('MIMIC datetime: ', datetime.datetime.now().time(), ' dist_target: ', dist_target, ' movement strinput: ', strInput)
|
2020-08-01 01:15:39 +02:00
|
|
|
time.sleep(0.3)
|
2020-07-21 01:03:06 +02:00
|
|
|
writeCfgInput("wait 5;")
|
|
|
|
|
2020-07-15 02:14:00 +02:00
|
|
|
def bot_process_movement(input_line):
|
|
|
|
dist_target = input_line[input_line.index("dist_target:") + len("dist_target:"):input_line.index("targethuman:")]
|
|
|
|
targethuman = input_line[input_line.index("targethuman:") + len("targethuman:"):input_line.index("bot_on_type:")]
|
2020-07-21 01:03:06 +02:00
|
|
|
bot_on_type = input_line[input_line.index("bot_on_type:") + len("bot_on_type:"):input_line.index("enemy_distance:")]
|
2020-08-30 20:00:02 +02:00
|
|
|
enemy_distance = input_line[input_line.index("enemy_distance:") + len("enemy_distance:"):input_line.index("dot_product:")]
|
|
|
|
dot_product = input_line[input_line.index("dot_product:") + len("dot_product:"):input_line.index("targeteam:")]
|
|
|
|
targeteam = input_line[input_line.index("targeteam:") + len("targeteam:"):input_line.index("target_enemy:")]
|
|
|
|
target_enemy = input_line[input_line.index("target_enemy:") + len("target_enemy:"):input_line.index("z_axis:")]
|
|
|
|
z_axis = input_line[input_line.index("z_axis:") + len("z_axis:"):]
|
2020-07-15 02:14:00 +02:00
|
|
|
dist_target = float(dist_target)
|
2020-08-30 20:00:02 +02:00
|
|
|
z_axis = float(z_axis)
|
2020-07-21 01:03:06 +02:00
|
|
|
enemy_distance = float(enemy_distance)
|
2020-07-15 02:14:00 +02:00
|
|
|
bot_on_type = int(bot_on_type)
|
2020-08-30 20:00:02 +02:00
|
|
|
dot_product = float(dot_product)
|
2020-07-24 00:25:03 +02:00
|
|
|
targeteam = int(targeteam)
|
2020-08-30 20:00:02 +02:00
|
|
|
min_distance_target_human = 800.0
|
2020-08-19 00:12:39 +02:00
|
|
|
strInput = "-attack; wait 2; -use; wait 5; -jump; wait 5; -duck; wait 5; +attack; wait 5; cl_minmodels 1; wait 2; +use; +forward; wait 2; "
|
2020-08-30 20:00:02 +02:00
|
|
|
if dot_product > 0.0:
|
|
|
|
print('dot_product: ', dot_product)
|
|
|
|
if z_axis > 0.0:
|
|
|
|
print('z_axis: ', z_axis)
|
|
|
|
crouch_cap = 5000.0
|
|
|
|
jump_cap = 100000.0
|
|
|
|
if 0.0 < dot_product <= crouch_cap:
|
|
|
|
print('crouching', datetime.datetime.now().time())
|
|
|
|
strInput += "+duck; wait 1500; +jump; -duck; wait 250; -jump; wait 50;"
|
|
|
|
elif 0.0 < dot_product <= jump_cap:
|
|
|
|
print('jumping', datetime.datetime.now().time())
|
|
|
|
strInput += "+jump; wait 350; +duck; wait 250; -jump; -duck; wait 50;"
|
2020-07-30 18:01:57 +02:00
|
|
|
if dist_target > min_distance_target_human:
|
2020-07-24 00:25:03 +02:00
|
|
|
strInput += "use weapon_elite; wait 3; "
|
|
|
|
elif targeteam == 3:
|
|
|
|
strInput += "use weapon_p90; wait 3; "
|
|
|
|
elif targeteam == 2:
|
|
|
|
strInput += "use weapon_knife; wait 5; "
|
|
|
|
global ladder_counter
|
2020-07-27 00:34:15 +02:00
|
|
|
if bot_on_type == 0 and ladder_counter < 100:
|
2020-07-24 00:25:03 +02:00
|
|
|
print('bot_on_type ladder, ladder_counter: ', ladder_counter)
|
2020-08-19 00:12:39 +02:00
|
|
|
strInput += "setang -90 0 0; wait 5; -back; wait 3; -moveleft; wait 3; -moveright; wait 5; -jump; wait 3; -duck; wait 3; "
|
2020-07-24 00:25:03 +02:00
|
|
|
ladder_counter += 1
|
2020-07-15 02:14:00 +02:00
|
|
|
else:
|
2020-07-24 00:25:03 +02:00
|
|
|
ladder_counter = 0
|
2020-07-30 18:01:57 +02:00
|
|
|
min_enemy_distance = 100.0
|
2020-08-30 20:00:02 +02:00
|
|
|
if bot_on_type == 3:
|
|
|
|
print('3 = downhill: ', bot_on_type)
|
2020-08-01 01:15:39 +02:00
|
|
|
for _ in range(5):
|
2020-07-27 00:34:15 +02:00
|
|
|
strInput += "+jump; wait 5;"
|
2020-08-30 20:00:02 +02:00
|
|
|
if enemy_distance > 0:
|
|
|
|
print('date: ', datetime.datetime.now().time(), ' target_enemy: ', target_enemy, ' enemy distance: ', enemy_distance)
|
|
|
|
else:
|
|
|
|
print('date: ', datetime.datetime.now().time(), ' target human: ', targethuman, ' dist_target: ', dist_target,)
|
2020-08-19 00:12:39 +02:00
|
|
|
strInput = strinput_append(strInput, 2)
|
2020-07-17 01:44:18 +02:00
|
|
|
#print('strInput final:', strInput)
|
2020-07-03 22:50:21 +02:00
|
|
|
writeCfgInput(strInput)
|
2020-08-19 00:12:39 +02:00
|
|
|
time.sleep(0.4)
|
2020-07-03 22:50:21 +02:00
|
|
|
writeCfgInput("wait 5;")
|
2020-01-23 23:15:26 +01:00
|
|
|
|
2020-07-27 00:34:15 +02:00
|
|
|
def strinput_append(strInput, nth):
|
|
|
|
for _ in range(10 * nth):
|
|
|
|
boolean_val = random.choice([True, False])
|
|
|
|
if boolean_val:
|
|
|
|
strInput += "+moveleft; wait 15; -moveleft; "
|
|
|
|
else:
|
|
|
|
strInput += "+moveright; wait 15; -moveright; "
|
|
|
|
return strInput
|
|
|
|
|
2020-08-19 00:12:39 +02:00
|
|
|
def kill_css_process():
|
|
|
|
css_pid = subprocess.getoutput(["pidof hl2_linux"])
|
|
|
|
if css_pid:
|
|
|
|
print('css_pid: ', css_pid, 'shutting the bots game down....')
|
|
|
|
css_pid = int(css_pid.strip())
|
|
|
|
os.kill(css_pid, signal.SIGTERM)
|
|
|
|
time.sleep(15)
|
|
|
|
print('preparing to launch game....')
|
|
|
|
os.chdir('/home/gameservers/.steam/debian-installation/')
|
2020-08-30 20:00:02 +02:00
|
|
|
subprocess.check_call("./steam.sh %s" % ("-applaunch 240 -textmode -textmessagedebug -novid -nosound -noipx -nojoy -noshaderapi"), shell=True)
|
2020-08-19 00:12:39 +02:00
|
|
|
print('finished starting game')
|
|
|
|
|
2020-07-03 22:50:21 +02:00
|
|
|
def bot_connect_ze():
|
|
|
|
#use whatever ip you want here to connect with
|
|
|
|
strdev = "connect 151.80.230.149:27019/test132;"
|
|
|
|
str1 = "connect 151.80.230.149:27015;"
|
2020-07-15 02:14:00 +02:00
|
|
|
writeCfgInput(str1)
|
2020-07-03 22:50:21 +02:00
|
|
|
time.sleep(0.2)
|
|
|
|
writeCfgInput("wait 5;")
|
|
|
|
print('not yet connected')
|
2020-06-12 02:01:39 +02:00
|
|
|
|
2020-01-23 23:15:26 +01:00
|
|
|
if __name__ == '__main__':
|
2020-06-12 02:01:39 +02:00
|
|
|
atexit.register(exit_handler)
|
|
|
|
resetCfgInputShortWait()
|
2020-07-03 22:50:21 +02:00
|
|
|
local_ip = "127.0.0.1"
|
|
|
|
local_port = 48477
|
|
|
|
udp_external_ip = "62.210.110.245"
|
|
|
|
buffer_size = 4096 #potentially not large enough?
|
2020-08-19 00:12:39 +02:00
|
|
|
connection_issue_counter = 0;
|
2020-07-03 22:50:21 +02:00
|
|
|
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock:
|
|
|
|
with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as sock_external:
|
|
|
|
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
|
|
|
sock.bind(("", local_port))
|
|
|
|
print('reached deadlock')
|
|
|
|
try:
|
|
|
|
while True:
|
|
|
|
data, addr = sock.recvfrom(buffer_size)
|
|
|
|
databyte = data
|
|
|
|
data = codecs.decode(data, "utf-8", "ignore")
|
|
|
|
ip = addr[0]
|
|
|
|
port = addr[1]
|
2020-07-15 02:14:00 +02:00
|
|
|
#print('port: ', port, " ip: ", ip)
|
2020-07-03 22:50:21 +02:00
|
|
|
if not data:
|
|
|
|
continue
|
|
|
|
if ip not in [local_ip, udp_external_ip]:
|
|
|
|
continue
|
|
|
|
if ip == udp_external_ip:
|
|
|
|
print("enabled remote UDP packet")
|
|
|
|
response_msg = f"""say {data}"""
|
|
|
|
writeCfgInput(response_msg)
|
|
|
|
time.sleep(0.5)
|
|
|
|
resetCfgInputShortWait()
|
2020-07-15 02:14:00 +02:00
|
|
|
#print('data: ', data)
|
2020-07-03 22:50:21 +02:00
|
|
|
if data == "autismo connected":
|
|
|
|
print('Bot connected!')
|
2020-08-19 00:12:39 +02:00
|
|
|
connection_issue_counter = 0
|
2020-07-03 22:50:21 +02:00
|
|
|
time.sleep(2)
|
|
|
|
joinTeam()
|
2020-08-30 20:00:02 +02:00
|
|
|
elif data == "bot kicked server full":
|
|
|
|
print('bot kicked server full: ', datetime.datetime.now().time())
|
2020-07-03 22:50:21 +02:00
|
|
|
elif data == "connect to ze":
|
2020-08-19 00:12:39 +02:00
|
|
|
if connection_issue_counter == 5:
|
|
|
|
kill_css_process()
|
|
|
|
connection_issue_counter += 1
|
|
|
|
print('connection_issue_counter: ', connection_issue_counter)
|
2020-07-03 22:50:21 +02:00
|
|
|
bot_connect_ze()
|
|
|
|
elif "clientmessage:" in data:
|
|
|
|
sock_external.sendto(databyte, (udp_external_ip, local_port))
|
|
|
|
print('sent databyte: ', databyte)
|
2020-07-21 01:03:06 +02:00
|
|
|
elif data.startswith("dist_target:"):
|
|
|
|
bot_process_movement(data)
|
2020-08-01 01:15:39 +02:00
|
|
|
elif data.startswith("surfing:"):
|
|
|
|
bot_process_surf(data)
|
2020-07-03 22:50:21 +02:00
|
|
|
elif data.startswith("keyinput:"):
|
2020-07-21 01:03:06 +02:00
|
|
|
bot_process_keyinput(data)
|
2020-07-03 22:50:21 +02:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
pass
|
2020-02-09 00:26:05 +01:00
|
|
|
|
2020-06-12 02:01:39 +02:00
|
|
|
#/home/gameservers/.steam/debian-installation/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
|
2020-06-12 02:01:39 +02:00
|
|
|
#cd /home/gameservers/.steam/debian-installation/
|
2020-08-30 20:00:02 +02:00
|
|
|
#./steam.sh -applaunch 240 -textmode -textmessagedebug -novid -nosound -noipx -nojoy -noshaderapi
|
2020-06-12 02:01:39 +02:00
|
|
|
|
|
|
|
#cd /home/gameservers/ze_runner_files
|
|
|
|
#./play.sh
|
|
|
|
#screen -A -d -m -S ze_runner ./play.sh
|
2020-08-21 02:30:29 +02:00
|
|
|
|
|
|
|
#before steam login: export SDL_VIDEO_X11_VISUALID=0x074
|
|
|
|
#to find correct SDL_VIDEO_X11_VISUALID use glxinfo in X2GO
|