This repository has been archived by the owner on Nov 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathunlink_scan.php
139 lines (97 loc) · 3.46 KB
/
unlink_scan.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<?php
require_once('inc/user.inc.php');
//Check Unlinked v1 by TheMadWeaz & KC
set_time_limit(10);
if($user[login_id] != 1) {
print_page("Admin","Admin access only.");
exit();
}
$map_array = array();
map_systems($map_array,1); //Crawl through systems from sol and record all systems found.
$number_of_islands = 0;
//Find what stars aren't connected to sol that can be linked
$sql_blank_link = "( (link_1 = 0) OR (link_2 = 0) OR (link_3 = 0) OR (link_4 = 0) OR (link_5 = 0) OR (link_6 = 0) )";
db("select * from ${db_name}_stars where $sql_blank_link");
while($star = dbr()) {
if(in_array($star['star_id'],$map_array)) { //Skip it if it was found in the crawl
continue;
}
$island_systems = array();
map_systems($island_systems,$star['star_id']); //Crawl through the island
$number_of_islands++;
//Go through each star of the island
foreach ($island_systems as $island_star) {
$star = dbo("select * from ${db_name}_stars where star_id = $island_star");
//Find the nearest system that has been mapped to sol and link the two
$sql_star_distance = "SQRT( POWER( (x_loc - $star[x_loc]) ,2) + POWER( ( (y_loc - $star[y_loc]) ) ,2) )";
db2("select *,$sql_star_distance AS distance from ${db_name}_stars where $sql_blank_link order by distance");
while($nearby_star = dbr2()) {
if(!in_array($nearby_star['star_id'],$map_array)) { //Skip it if it isn't connected to Sol
continue;
}
$star1 = $star;
$star2 = $nearby_star;
//Find the closest star in the island to this star
$sql_star_distance = "SQRT( POWER( (x_loc - $star2[x_loc]) ,2) + POWER( ( (y_loc - $star2[y_loc]) ) ,2) )";
db3("select * from ${db_name}_stars where ($sql_star_distance < $star2[distance]) AND $sql_blank_link order by $sql_star_distance");
while($closer_star = dbr3()) {
if(!in_array($closer_star['star_id'],$island_systems)) { //Skip it if it isn't in the island
continue;
}
$star1 = $closer_star;
break;
}
add_link($star1,$star2['star_id']);
add_link($star2,$star1['star_id']);
break;
}
}
$map_array = array_merge($map_array,$island_systems); //Add the island systems into the list
}
print_page("Unlinked Scan","$number_of_islands islands found and linked to sol");
function map_systems(&$map_array,$current_system) {
global $db_name;
array_push($map_array,$current_system);
db2("select * from ${db_name}_stars where star_id = $current_system"); //Get the star info
$star = dbr2();
$linknum = 1;
while($linknum <= 6) { //Loop through each linked system
if($star["link_$linknum"] && !in_array($star["link_$linknum"],$map_array)) {
map_systems($map_array,$star["link_$linknum"]);
}
$linknum++;
}
}
function add_link($star,$link_to) {
global $db_name;
$linknum = 1;
while($linknum <= 6) { //Look for an empty link slot
if($star["link_$linknum"] == $link_to) {
return false;
}
if(empty($star["link_$linknum"])) {
break;
}
$linknum++;
}
if($linknum > 6) { //No available links
return false;
} else {
$star["link_$linknum"] = $link_to;
dbn("update ${db_name}_stars set link_$linknum = $link_to where star_id = $star[star_id]");
}
}
$query3 = "";
function db3($string) {
global $query3;
$query3 = mysql_db_query(DATABASE,$string) or die("Failure in db3 function: ".mysql_error());
}
function dbr3() {
global $query3;
return mysql_fetch_array($query3);
}
function dbo($string) {
$temp = mysql_db_query(DATABASE,$string) or die("Failure in dbo function: ".mysql_error());
return mysql_fetch_array($temp);
}
?>