От скуки написал простого бота для игры на летней распродажи. Бот запускается с помощью php через консоль.
Код бота:
Так же доступен по ссылке - http://sandbox.onlinephpfunctions.com/code/ef6708c94e207817744a1e54a40482217cdb6548
Токен для бота получаем по ссылке - https://steamcommunity.com/saliengame/gettoken
Код бота:
PHP:
<?php
$access_token = readline('Enter steam access token: ');
$request = json_decode(send('https://community.steam-api.com/ITerritoryControlMinigameService/GetPlayerInfo/v0001/','access_token='.$access_token));
if($request->{response}->{active_zone_position}){
echo 'Game '.$request->{response}->{active_zone_game}.' started.'."\r\n";
sleep(1);
echo 'Exiting...'."\r\n";
send('https://community.steam-api.com/IMiniGameService/LeaveGame/v0001/','access_token='.$access_token.'&gameid='.$request->{response}->{active_zone_game});
sleep(0.5);
echo 'Success!'."\r\n";
sleep(0.3);
}
if($request->{response}->{active_planet}){
echo 'Choosed planet with ID '.$request->{response}->{active_planet}.'.'."\r\n";
sleep(1);
echo 'Exiting...'."\r\n";
send('https://community.steam-api.com/IMiniGameService/LeaveGame/v0001/','access_token='.$access_token.'&gameid='.$request->{response}->{active_planet});
sleep(0.5);
echo 'Success!'."\r\n";
sleep(0.3);
}
$requestJson = json_decode(send('https://community.steam-api.com/ITerritoryControlMinigameService/GetPlanets/v0001/?active_only=1&language=english'));
foreach ($requestJson->response->planets as $planet){
if($planet->state->captured == false){
echo '['.$planet->id.']';
echo ' '.$planet->state->name;
echo ' | Progress:';
echo ' '.round($planet->state->capture_progress, 3)."\r\n";
}
}
$planetId = readline('Choose planet id: ');
send('https://community.steam-api.com/ITerritoryControlMinigameService/JoinPlanet/v0001/','access_token='.$access_token.'&id='.$planetId);
$requestJson = json_decode(send('https://community.steam-api.com/ITerritoryControlMinigameService/GetPlanet/v0001/?id='.$planetId.'&language=english'));
//file_put_contents('test.txt',json_encode($requestJson->response->planets->));
foreach ($requestJson->response->planets[0]->zones as $zone){
if($zone->captured == false){
echo '['.$zone->zone_position.']';
if(strlen($zone->zone_position.'') == 1) echo ' ';
echo ' Game id: '.$zone->gameid;
echo ' | Difficulty:';
switch($zone->difficulty){
case 1:
echo ' Low ';
break;
case 2:
echo ' Medium';
break;
case 3:
echo ' Hard ';
break;
}
echo ' | Progress:';
echo ' '.round($zone->capture_progress, 3)."\r\n";
}
}
$position = readline('Enter game position: ');
$repetitions = readline('Enter number of repetitions: ');
$count = 0;
$errors = 0;
$succeed = 0;
do{
$count++;
$requestJoinJson = json_decode(send('https://community.steam-api.com/ITerritoryControlMinigameService/JoinZone/v0001/','zone_position='.$position.'&access_token='.$access_token));
if($difficulty = $requestJoinJson->response->zone_info->difficulty){
echo 'Game started!'."\r\n";
$startTime = time();
do{
$time = time();
echo 'Waiting for game end...'."\r\n";
if($time < $startTime + 60 * 2) echo 'Remainig '.(($startTime + 60 * 2) - $time).' sec'."\r\n"; else break;
sleep(rand(10,20));
}while($time < $startTime + 60 * 2);
switch($difficulty){
case 1:
$score = rand(500,700);
break;
case 2:
$score = rand(800,1200);
break;
case 3:
$score = rand(1800,2100);
break;
}
}
$requestReportScoreJson = json_decode(send('https://community.steam-api.com/ITerritoryControlMinigameService/ReportScore/v0001/','access_token='.$access_token.'&score='.$score.'&language=english'));
if($new_score = $requestReportScoreJson->response->new_score){
echo 'Game ended.'."\r\n";
echo 'Your new score: '.$new_score."\r\n";
echo 'Progress: '.$count.'/'.$repetitions."\r\n";
echo '------------------------------------'."\r\n";
}else{
$errors++;
echo 'Error.'."\r\n";
echo '------------------------------------'."\r\n";
if($errors >= 3){
echo 'Bot stopped.';
}
}
}while($count <= $repetitions);
echo 'Bot stopped.';
//Functions
function send($url, $post = ''){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
if(!empty($post)) curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
// curl_setopt($ch, CURLOPT_PROXY, '127.0.0.1:8888');
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'accept: */*',
'origin: https://steamcommunity.com',
'user-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.87 Safari/537.36',
'content-type: application/x-www-form-urlencoded; charset=UTF-8',
'referer: https://steamcommunity.com/saliengame/play/',
'accept-language: ru-RU,ru;q=0.9,en-US;q=0.8,en;q=0.7',
));
$output = curl_exec($ch);
curl_close($ch);
return $output;
}
?>
Так же доступен по ссылке - http://sandbox.onlinephpfunctions.com/code/ef6708c94e207817744a1e54a40482217cdb6548
Токен для бота получаем по ссылке - https://steamcommunity.com/saliengame/gettoken
Последнее редактирование: