some updates regarding communication between serveur and da bot
This commit is contained in:
parent
b9eba36882
commit
a2c8a96d1a
@ -5,19 +5,30 @@ import re
|
||||
from threading import Timer
|
||||
import string
|
||||
import random
|
||||
import time
|
||||
|
||||
|
||||
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'
|
||||
clearbool = True
|
||||
|
||||
def id_generator(size=6, chars=string.ascii_uppercase + string.digits):
|
||||
return ''.join(random.choice(chars) for _ in range(size))
|
||||
|
||||
def switchbool():
|
||||
global clearbool
|
||||
clearbool = True
|
||||
|
||||
def clearconsolelog():
|
||||
open(consolelogPath, 'w').close()
|
||||
connectionTimer = Timer(20.0, clearconsolelog)
|
||||
#daemon true kills thread instead of deadlock waiting in case program exits
|
||||
connectionTimer.daemon = True
|
||||
connectionTimer.start()
|
||||
global clearbool
|
||||
if clearbool:
|
||||
clearbool = False
|
||||
open(consolelogPath, 'w').close()
|
||||
print('cleaned console')
|
||||
connectionTimer = Timer(3.0, switchbool)
|
||||
#daemon true kills thread instead of deadlock waiting in case program exits
|
||||
connectionTimer.daemon = True
|
||||
connectionTimer.start()
|
||||
|
||||
def writeCfgInput(Input):
|
||||
with open(looptestPath, 'w') as f:
|
||||
@ -26,7 +37,6 @@ def writeCfgInput(Input):
|
||||
def getconsoleOutputForStatus():
|
||||
randomlygeneratedString = id_generator(11)
|
||||
str = "status; wait 5; {0}; wait 5;".format(randomlygeneratedString)
|
||||
print('writeCfgInput')
|
||||
writeCfgInput(str)
|
||||
checkConsoleOutput(randomlygeneratedString)
|
||||
server_str = ""
|
||||
@ -35,6 +45,7 @@ def getconsoleOutputForStatus():
|
||||
for line in f:
|
||||
if "udp/ip :" in line: server_str = line[9:].strip()
|
||||
if "players :" in line: player_count = int(line[9:].split()[0].strip())
|
||||
print('server_str: ', server_str, '\nplayer_count: ', player_count)
|
||||
return (server_str, player_count)
|
||||
|
||||
def get_output_if_spec():
|
||||
@ -44,29 +55,31 @@ def get_output_if_spec():
|
||||
#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
|
||||
targetstr = "This feature requires that you are on a team."
|
||||
failurestr = "Unknown command \"zspawn\""
|
||||
checkConsoleOutput(randomlygeneratedString)
|
||||
with open(consolelogPath, 'r') as f:
|
||||
for line in f:
|
||||
if targetstr in line: return True
|
||||
return False
|
||||
|
||||
|
||||
if targetstr in line: return 1
|
||||
if failurestr in line: return 2
|
||||
return 0
|
||||
|
||||
def checkConsoleOutput(input):
|
||||
bool = False
|
||||
iterations_count = 0
|
||||
#print('entered checkconsole output')
|
||||
while not bool:
|
||||
while iterations_count < 6:
|
||||
time.sleep(0.5)
|
||||
with open(consolelogPath, 'r') as f:
|
||||
for line in f:
|
||||
if input in line:
|
||||
#print('line: ', line, ' \ninput: ', input)
|
||||
bool = True
|
||||
iterations_count += 6
|
||||
break
|
||||
iterations_count += 1
|
||||
|
||||
|
||||
def resetCfgInputShortWait():
|
||||
#getpos
|
||||
randomlygeneratedString = id_generator(11)
|
||||
print('randomlygeneratedString: ', randomlygeneratedString)
|
||||
#print('randomlygeneratedString: ', randomlygeneratedString)
|
||||
str = "{0}; wait 5;".format(randomlygeneratedString)
|
||||
with open(looptestPath, 'w') as f:
|
||||
f.write(str)
|
||||
@ -87,23 +100,35 @@ def joinTeam():
|
||||
checkConsoleOutput(randomlygeneratedString)
|
||||
|
||||
def checkbotteam():
|
||||
team = get_output_if_spec()
|
||||
if team: joinTeam()
|
||||
while True:
|
||||
clearconsolelog()
|
||||
state = get_output_if_spec()
|
||||
if state == 1:
|
||||
joinTeam()
|
||||
break
|
||||
if state == 0:
|
||||
break
|
||||
resetCfgInputShortWait()
|
||||
connectionTimer = Timer(20.0, checkbotteam)
|
||||
connectionTimer.daemon = True
|
||||
connectionTimer.start()
|
||||
|
||||
def checkIfConnected():
|
||||
randomlygeneratedString = id_generator(11)
|
||||
str1 = "connect 151.80.230.149:27015; wait 5; {0}; wait 50; ".format(randomlygeneratedString)
|
||||
server_str, player_count = getconsoleOutputForStatus()
|
||||
if "Zombie Escape" not in server_str:
|
||||
connectionTimer = None
|
||||
if "27015" not in server_str:
|
||||
str1 = "connect 151.80.230.149:27015; wait 5; {0}; wait 1500; ".format(randomlygeneratedString)
|
||||
writeCfgInput(str1)
|
||||
checkConsoleOutput(randomlygeneratedString)
|
||||
elif player_count > 58:
|
||||
writeCfgInput("connect 151.80.230.149:27016; wait 5; {0}; wait 50;").format(randomlygeneratedString)
|
||||
checkConsoleOutput(randomlygeneratedString)
|
||||
#TODO check team differently because zspawn unknown command on zr server
|
||||
writeCfgInput("connect 151.80.230.149:27016; wait 5; {0}; wait 1500;".format(randomlygeneratedString))
|
||||
checkConsoleOutput(randomlygeneratedString)
|
||||
connectionTimer = Timer(60.0 * 15, checkIfConnected)
|
||||
resetCfgInputShortWait()
|
||||
print('reached checkbotteam:')
|
||||
checkbotteam()
|
||||
resetCfgInputShortWait()
|
||||
connectionTimer = Timer(60.0 * 5, checkIfConnected)
|
||||
if not connectionTimer:
|
||||
connectionTimer = Timer(60.0 * 2, checkIfConnected)
|
||||
#daemon true kills thread instead of deadlock waiting in case program exits
|
||||
connectionTimer.daemon = True
|
||||
connectionTimer.start()
|
||||
@ -129,13 +154,22 @@ def getBotOrigin():
|
||||
def get_player_info():
|
||||
movement_input = []
|
||||
ct_angles = []
|
||||
while not movement_input or not ct_angles:
|
||||
while not movement_input and not ct_angles:
|
||||
with open(consolelogPath, 'r') as f:
|
||||
for line in f:
|
||||
if "movement_input_:" in line:
|
||||
movement_input.append(line[16:].strip())
|
||||
if "movement_input_specific:" in line:
|
||||
try:
|
||||
movement = line.split("movement_input_specific:", 1)[1]
|
||||
movement = movement.replace("\n", "")
|
||||
#print('movement: ', movement)
|
||||
movement_input.append(movement)
|
||||
except IndexError:
|
||||
pass
|
||||
if "ct_eye_angles_:" in line:
|
||||
ct_angles = line[15:].split()
|
||||
try:
|
||||
ct_angles = line.split("ct_eye_angles_:", 1)[1].split("+")
|
||||
except IndexError:
|
||||
pass
|
||||
ct_angles = [element.strip() for element in ct_angles]
|
||||
return (movement_input, ct_angles)
|
||||
|
||||
@ -155,15 +189,18 @@ def followPlayer():
|
||||
#writeCfgInput(default_input)
|
||||
#botOrigin = getBotOrigin()
|
||||
movement_input, ct_angles = get_player_info()
|
||||
print('movement_input: ', movement_input, '\nct_angles: ', ct_angles)
|
||||
randomlygeneratedString = id_generator(11)
|
||||
|
||||
strInput = "+attack; wait 5; cl_minmodels 1; wait 5; {0}; wait 5; setang {1} {2} {3}; wait 5;".format(randomlygeneratedString, ct_angles[0], ct_angles[1], ct_angles[2])
|
||||
strInput = "-forward; wait 5; -back; wait 5; -moveleft; wait 5; -moveright; wait 5; -jump; wait 5; +attack; wait 5; cl_minmodels 1; wait 5; {0}; wait 5; setang {1} {2} {3}; wait 5;".format(randomlygeneratedString, ct_angles[0], ct_angles[1], ct_angles[2])
|
||||
for movement in movement_input:
|
||||
strInput += movement + "; wait 5;"
|
||||
print('strInput: ', strInput)
|
||||
strInput += movement
|
||||
strInput += "; wait 5;"
|
||||
#print('strInput: ', strInput)
|
||||
writeCfgInput(strInput)
|
||||
checkConsoleOutput(randomlygeneratedString)
|
||||
connectionTimer = Timer(2.5, followPlayer)
|
||||
clearconsolelog()
|
||||
connectionTimer = Timer(1.0, followPlayer)
|
||||
connectionTimer.daemon = True
|
||||
connectionTimer.start()
|
||||
|
||||
@ -178,6 +215,8 @@ if __name__ == '__main__':
|
||||
clearconsolelog()
|
||||
resetCfgInputShortWait()
|
||||
checkIfConnected()
|
||||
checkbotteam()
|
||||
print('reached followPlayer')
|
||||
followPlayer()
|
||||
print('reached deadlock')
|
||||
deadlock()
|
||||
|
@ -11,7 +11,7 @@
|
||||
#pragma newdecls required
|
||||
|
||||
bool outputspam[MAXPLAYERS + 1];
|
||||
int ticksCooldown = 66; // 66 tick per second
|
||||
int ticksCooldown = 48; // 66 tick per second
|
||||
int botTicker;
|
||||
int targethuman = 0;
|
||||
|
||||
@ -71,6 +71,65 @@ public bool TraceEntityFilterPlayer( int entity, int contentsMask )
|
||||
return ( entity > GetMaxClients() || !entity );
|
||||
}
|
||||
|
||||
//TODO FINISH MOVING OVER, RECURSIVE OR 1 SEC TIMER JUST instead of using OnPlayerRunCmdPost
|
||||
|
||||
public void recursivePressing()
|
||||
{
|
||||
if (targethuman && (GetClientTeam(targethuman) != 3 || !IsPlayerAlive(targethuman)))
|
||||
{
|
||||
targethuman = 0;
|
||||
}
|
||||
if (!targethuman)
|
||||
{
|
||||
float pos_client[3];
|
||||
TraceEye(client, pos_client);
|
||||
float lowest_distance = 1000000.0;
|
||||
for (int i = 1; i <= MaxClients; i++)
|
||||
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == 3 && i != client)
|
||||
{
|
||||
float pos_i[3];
|
||||
TraceEye(client, pos_i);
|
||||
float dx = pos_client[0] - pos_i[0];
|
||||
float dy = pos_client[1] - pos_i[1];
|
||||
float dz = FloatAbs(pos_client[2] - pos_i[2]);
|
||||
float dist = SquareRoot(dx*dx + dy*dy + dz*dz);
|
||||
if (dist < lowest_distance)
|
||||
{
|
||||
lowest_distance = dist;
|
||||
targethuman = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
//maybe this holds some order?
|
||||
float clientorigin[3];
|
||||
float clientangles[3];
|
||||
GetClientAbsOrigin(targethuman, clientorigin);
|
||||
GetClientAbsAngles(targethuman, clientangles);
|
||||
//PrintToChat(client, "player_start_origin: %f %f %f", clientorigin[0], clientorigin[1], clientorigin[2]);
|
||||
int keys = GetClientButtons(targethuman);
|
||||
if (keys & IN_FORWARD)
|
||||
{
|
||||
ServerCommand("sm_psay #[U:1:120378081] movement_input_specific:+forward");
|
||||
}
|
||||
if (keys & IN_BACK)
|
||||
{
|
||||
ServerCommand("sm_psay #[U:1:120378081] movement_input_specific:+back");
|
||||
}
|
||||
if (keys & IN_LEFT)
|
||||
{
|
||||
ServerCommand("sm_psay #[U:1:120378081] movement_input_specific:+moveleft");
|
||||
}
|
||||
if (keys & IN_RIGHT)
|
||||
{
|
||||
ServerCommand("sm_psay #[U:1:120378081] movement_input_specific:+moveright");
|
||||
}
|
||||
if (keys & IN_JUMP)
|
||||
{
|
||||
ServerCommand("sm_psay #[U:1:120378081] movement_input_specific:+jump");
|
||||
}
|
||||
ServerCommand("sm_psay #[U:1:120378081] ct_eye_angles_:%f+%f+%f", clientangles[0], clientangles[1], clientangles[2]);
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
// Purpose:
|
||||
//----------------------------------------------------------------------------------------------------
|
||||
@ -82,58 +141,7 @@ public void OnPlayerRunCmdPost(int client, int buttons, int impulse, const float
|
||||
if (botTicker > ticksCooldown)
|
||||
{
|
||||
botTicker = 0;
|
||||
if (targethuman && (GetClientTeam(targethuman) != 3 || !IsPlayerAlive(targethuman)))
|
||||
{
|
||||
targethuman = 0;
|
||||
}
|
||||
if (!targethuman)
|
||||
{
|
||||
float pos_client[3];
|
||||
TraceEye(client, pos_client);
|
||||
float lowest_distance = 1000000.0;
|
||||
for (int i = 1; i <= MaxClients; i++)
|
||||
if (IsValidClient(i) && IsPlayerAlive(i) && GetClientTeam(i) == 3 && i != client)
|
||||
{
|
||||
float pos_i[3];
|
||||
TraceEye(client, pos_i);
|
||||
float dx = pos_client[0] - pos_i[0];
|
||||
float dy = pos_client[1] - pos_i[1];
|
||||
float dz = FloatAbs(pos_client[2] - pos_i[2]);
|
||||
float dist = SquareRoot(dx*dx + dy*dy + dz*dz);
|
||||
if (dist < lowest_distance)
|
||||
{
|
||||
lowest_distance = dist;
|
||||
targethuman = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
//maybe this holds some order?
|
||||
float clientorigin[3];
|
||||
float clientangles[3];
|
||||
GetClientAbsOrigin(targethuman, clientorigin);
|
||||
GetClientAbsAngles(targethuman, clientangles);
|
||||
//PrintToChat(client, "player_start_origin: %f %f %f", clientorigin[0], clientorigin[1], clientorigin[2]);
|
||||
if (GetEntProp(targethuman, Prop_Data, "m_afButtonPressed") & IN_FORWARD)
|
||||
{
|
||||
PrintToChat(client, "movement_input_: +forward");
|
||||
}
|
||||
if (GetEntProp(targethuman, Prop_Data, "m_afButtonPressed") & IN_BACK)
|
||||
{
|
||||
PrintToChat(client, "movement_input_: +back");
|
||||
}
|
||||
if (GetEntProp(targethuman, Prop_Data, "m_afButtonPressed") & IN_LEFT)
|
||||
{
|
||||
PrintToChat(client, "movement_input_: +moveleft");
|
||||
}
|
||||
if (GetEntProp(targethuman, Prop_Data, "m_afButtonPressed") & IN_RIGHT)
|
||||
{
|
||||
PrintToChat(client, "movement_input_: +moveright");
|
||||
}
|
||||
if (GetEntProp(targethuman, Prop_Data, "m_afButtonPressed" ) & IN_JUMP)
|
||||
{
|
||||
PrintToChat(client, "movement_input_: +jump");
|
||||
}
|
||||
PrintToChat(client, "ct_eye_angles_: %f %f %f", clientangles[0], clientangles[1], clientangles[2]);
|
||||
|
||||
}
|
||||
botTicker++;
|
||||
}
|
||||
@ -153,6 +161,7 @@ public void OnClientPostAdminCheck(int client)
|
||||
//STEAM_0:1:34783317
|
||||
//STEAM_0:1:60189040
|
||||
//[U:1:120378081]
|
||||
//[U:1:69566635]
|
||||
char auth[50];
|
||||
GetClientAuthId(client, AuthId_Engine, auth, sizeof(auth));
|
||||
//PrintToChatAll("client: %N \nAuth: %s", client, auth);
|
||||
|
Loading…
Reference in New Issue
Block a user