Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
codels committed Jun 19, 2015
1 parent 3a26bb0 commit d173e15
Show file tree
Hide file tree
Showing 12 changed files with 139 additions and 149 deletions.
54 changes: 0 additions & 54 deletions account_in_room.php

This file was deleted.

36 changes: 21 additions & 15 deletions controller_v_first.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ applicationKPP.controller('controllerVFirst', function ($http, $timeout, $interv
return;
}

$http.post('./room_status.php', {room_id: vm.roomLastId, timeout: 1000}).then(function (response) {
$http.post('./room_info_json.php', {room_id: vm.roomLastId}).then(function (response) {
var timeoutTime = 0;
if (_.has(response.data, 'room_id') && _.has(response.data, 'status')) {
if (response.data.status == -1) {
Expand All @@ -45,7 +45,8 @@ applicationKPP.controller('controllerVFirst', function ($http, $timeout, $interv
id: response.data.room_id,
players: response.data.players,
founded: false,
disabled: false
disabled: false,
accounts_found: []
};
vm.roomsScanning.push(room);
vm.scanRoom(room);
Expand All @@ -60,25 +61,30 @@ applicationKPP.controller('controllerVFirst', function ($http, $timeout, $interv
if (!vm.is_start) {
return;
}
$http.post('./account_in_room.php', {
$http.post('./search_accounts_in_room.php', {
room_id: room.id,
account_id: vm.accountsSearch,
timeout: 1000
account_id: vm.accountsSearch
}).then(function (response) {
room.founded = response.data.exists || false;
room.players = response.data.players || -1;
if (room.players <= vm.ignoreCountPlayers) {
vm.scanRoom(room);
if (_.has(response, 'data') && _.has(response.data, 'room_id')) {
if (_.has(response.data, 'exists')) {
room.founded = response.data.exists;
}

if (_.has(response.data, 'players')) {
room.players = response.data.players;
}

if (room.players <= vm.ignoreCountPlayers || room.founded) {
$timeout(function() { vm.scanRoom(room); }, 1000);
} else {
room.disabled = true;
}
} else {
room.disabled = true;
// retry instant scan
vm.scanRoom(room);
}
})
};

vm.startSearch = function () {
vm.is_start = true;
vm.currentRoomId = vm.minRoomId;
vm.searchNewRoom();
};
}
);
12 changes: 3 additions & 9 deletions controller_v_second.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,6 @@ applicationKPP.controller('controllerVSecond', function ($http, $timeout, $inter
vm.foundedRooms = [];
vm.stalkRoom = 0;

vm.start = function () {
vm.is_start = true;
vm.currentRoomId = vm.minRoomId;
vm.scanRoomsStatus();
};

vm.startSearch = function () {
vm.newRooms = [];
vm.is_start = true;
Expand All @@ -32,7 +26,7 @@ applicationKPP.controller('controllerVSecond', function ($http, $timeout, $inter
};

vm.stalk = function () {
$http.post('./account_in_room.php', {
$http.post('./search_accounts_in_room.php', {
room_id: vm.stalkRoom,
account_id: 133090071
}).then(function (response) {
Expand All @@ -50,7 +44,7 @@ applicationKPP.controller('controllerVSecond', function ($http, $timeout, $inter
if (!vm.is_start) {
return;
}
$http.post('./room_status.php', {room_id: vm.currentRoomId}).then(function (response) {
$http.post('./room_info_json.php', {room_id: vm.currentRoomId}).then(function (response) {
if (!response || response.data.status == -1) {
$timeout(function () {
vm.searchNewRoom();
Expand All @@ -77,7 +71,7 @@ applicationKPP.controller('controllerVSecond', function ($http, $timeout, $inter

vm.startRefreshing = function (roomId) {
console.log('refreshing' + roomId);
$http.post('./account_in_room.php', {
$http.post('./search_accounts_in_room.php', {
room_id: roomId,
account_id: vm.accountsSearch
}).then(function (response) {
Expand Down
10 changes: 0 additions & 10 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,7 @@
}
}
}
/*
$objectRoom->me = false;

foreach ($roomsMe as $room) {
if ($room->id == $objectRoom->id) {
$objectRoom->me = true;
break;
}
}
*/
// format
$objectRoom->possible_max_level_format = number_format($objectRoom->possible_max_level, 0, '.', ' ');
$objectRoom->clicks_format = number_format($objectRoom->clicks, 0, '.', ' ');
Expand Down Expand Up @@ -164,7 +155,6 @@
return (sort_value != undefined) ? sort_value : cell_value;
}
});
//$("#options").tablesorter({sortList: [[0,0]], headers: { 3:{sorter: false}, 4:{sorter: false}}});
});

function updateRooms() {
Expand Down
4 changes: 0 additions & 4 deletions me_rooms.json

This file was deleted.

1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Search rooms in steam mini game tower (summer 2015) filter by steam accounts id
60 changes: 35 additions & 25 deletions room_status.php → room_info_json.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,47 +24,57 @@
$statementSearch = $db->prepare('SELECT `status`, `level` FROM `rooms` WHERE `id` = ?');
$statementSearch->execute(array($roomId));
$info = $statementSearch->fetch(PDO::FETCH_ASSOC);
$players = -1;
$level = -1;
$status = -1;

if (!empty($info['status']) && $info['status'] == 3) {
$level = $info['level'];
$status = $info['status'];
$players = -1;
$activePlayers = -1;
} else {
$statementUpdate = $db->prepare('REPLACE INTO `rooms` (`id`, `level`, `status`, `players`) VALUES (?, ?, ?, ?)');
$context = stream_context_create(array('http' =>
array(
'timeout' => 5,
)
));

$response = @file_get_contents('http://steamapi-a.akamaihd.net/ITowerAttackMiniGameService/GetGameData/v0001/?gameid='.$roomId.'&include_stats=1', null, $context);

$level = -1;
$status = -1;
$players = -1;
$activePlayers = -1;
if ($response === false) {
return;
}

$gameInfo = json_decode($response);

$gameInfo = json_decode(file_get_contents('http://steamapi-a.akamaihd.net/ITowerAttackMiniGameService/GetGameData/v0001/?gameid='.$roomId.'&include_stats=1'));
if ($gameInfo === false) {
return;
}

if (property_exists($gameInfo, 'response')) {
if (property_exists($gameInfo->response, 'game_data')) {
if (property_exists($gameInfo->response->game_data, 'level')) {
$level = $gameInfo->response->game_data->level;
}
if (property_exists($gameInfo->response->game_data, 'status')) {
$status = $gameInfo->response->game_data->status;
}
if (!property_exists($gameInfo, 'response')) {
return;
}

if (property_exists($gameInfo->response, 'game_data')) {
if (property_exists($gameInfo->response->game_data, 'level')) {
$level = $gameInfo->response->game_data->level;
}
if (property_exists($gameInfo->response, 'stats')) {
if (property_exists($gameInfo->response->stats, 'num_players')) {
$players = $gameInfo->response->stats->num_players;
}
if (property_exists($gameInfo->response->stats, 'num_active_players')) {
$activePlayers = $gameInfo->response->stats->num_active_players;
}
if (property_exists($gameInfo->response->game_data, 'status')) {
$status = $gameInfo->response->game_data->status;
}
}
if (property_exists($gameInfo->response, 'stats')) {
if (property_exists($gameInfo->response->stats, 'num_players')) {
$players = $gameInfo->response->stats->num_players;
}
}

$statementUpdate = $db->prepare('REPLACE INTO `rooms` (`id`, `level`, `status`, `players`) VALUES (?, ?, ?, ?)');
$statementUpdate->execute(array($roomId, $level, $status, $players));
}

echo json_encode(array(
'room_id' => $roomId,
'level' => $level,
'status' => $status,
'players' => $players,
'activePlayers' => $activePlayers
'players' => $players
), JSON_FORCE_OBJECT);
2 changes: 1 addition & 1 deletion rooms.sql
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@

DROP TABLE IF EXISTS `rooms`;
CREATE TABLE `rooms` (
`id` int(10) unsigned NOT NULL,
`level` bigint(20) NOT NULL,
`status` tinyint(3) NOT NULL,
`players` int(11) NOT NULL DEFAULT '-1',
`update_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
File renamed without changes.
78 changes: 78 additions & 0 deletions search_accounts_in_room_json.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
date_default_timezone_set('Europe/Moscow');
mb_internal_encoding('UTF-8');

$data = file_get_contents('php://input');
if (!empty($data)) {
if (!empty($_SERVER['HTTP_ACCEPT']) && strpos($_SERVER['HTTP_ACCEPT'], 'application/json') !== false) {
$parse = json_decode($data, true);
$_REQUEST = array_merge($_REQUEST, $parse);
}
}

if (empty($_REQUEST['room_id']) || empty($_REQUEST['account_id'])) {
return;
}

$roomId = intval($_REQUEST['room_id']);
$accountId = $_REQUEST['account_id'];

$context = stream_context_create(array('http' =>
array(
'timeout' => 5,
)
));

$response = @file_get_contents('http://steamapi-a.akamaihd.net/ITowerAttackMiniGameService/GetPlayerNames/v0001/?input_json=%7B%22gameid%22%3A%22' . $roomId . '%22%2C%22accountids%22%3A%5B%5D%7D', null, $context);

if ($response === false) {
return;
}

$gameInfo = json_decode($response);

if ($gameInfo === false) {
return;
}

if (!property_exists($gameInfo, 'response')) {
return;
}

if (!property_exists($gameInfo->response, 'names')) {
return;
}

$players = count($gameInfo->response->names);

require_once 'config.php';

$db = new PDO('mysql:host=' . $dbHost . ';dbname=' . $dbName, $dbUser, $dbPass);
$db->query('SET NAMES utf8');

$statementUp = $db->prepare('UPDATE `rooms` SET `players` = ? WHERE `id` = ?');
$statementUp->execute(array($players, $roomId));

$exists = false;
$accountsFound = array();

foreach ($gameInfo->response->names as $player) {
if (is_array($accountId)) {
if (in_array($player->accountid, $accountId)) {
$exists = true;
$accountsFound[] = $player->accountid;
}
} else {
if ($player->accountid == $accountId) {
$exists = true;
$accountsFound[] = $player->accountid;
}
}
}

echo json_encode(array(
'room_id' => $roomId,
'players' => $players,
'exists' => $exists,
'accounts_found' => $accountsFound
), JSON_FORCE_OBJECT);
20 changes: 0 additions & 20 deletions stats.php

This file was deleted.

Loading

0 comments on commit d173e15

Please sign in to comment.