-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmemory_alpha.php
More file actions
179 lines (141 loc) · 8.28 KB
/
memory_alpha.php
File metadata and controls
179 lines (141 loc) · 8.28 KB
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
<?php
/*
This file is part of STFC.it
Copyright 2008-2017 by Andrea Carolfi (carolfi@stfc.it) and
Cristiano Delogu (delogu@stfc.it).
STFC.it is based on STFC,
Copyright 2006-2007 by Michael Krauss (info@stfc2.de) and Tobias Gafner
STFC is based on STGC,
Copyright 2003-2007 by Florian Brede (florian_brede@hotmail.com) and Philipp Schmidt
STFC is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
STFC is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//########################################################################################
//########################################################################################
class MemoryAlpha extends NPC {
public function Install($log = INSTALL_LOG_FILE_NPC) {
$this->sdl->start_job('Memory Alpha Archive System', $log);
$this->db->query('INSERT INTO memory_alpha_triggers SET id = 1');
$this->db->query('INSERT INTO memory_alpha_storage SET id = 1, alpha_charted = "", alpha_tform = "", alpha_cships = "", alpha_off = ""');
$this->sdl->finish_job('Memory Alpha Archive System', $log);
}
public function Execute($debug=0) {
$starttime = ( microtime() + time() );
$this->sdl->log('<br><b>-------------------------------------------------------------</b><br>'.
'<b>Starting Memory Alpha Archive Tutor at '.date('d.m.y H:i:s', time()).'</b>', TICK_LOG_FILE_NPC);
if($debug){
$this->sdl->log('Archive opening', TICK_LOG_FILE_NPC);
}
$sql = 'SELECT * FROM memory_alpha_triggers WHERE id = 1';
if(!($triggers = $this->db->queryrow($sql)))
{
$this->sdl->log('<b>Error:</b> Tutor: cannot open main DB', TICK_LOG_FILE_NPC);
}
else {
// Main
if($triggers['trigger_1'] == 1) {
$this->sdl->start_job('Sistemi esplorati', TICK_LOG_FILE_NPC);
if(!$this->f_trigger_1()) {
$this->sdl->log('Tutor: f_trigger_1 fail!!!', TICK_LOG_FILE_NPC);
}
$this->sdl->finish_job('Sistemi esplorati', TICK_LOG_FILE_NPC);
}
if($triggers['trigger_2'] == 1) {
$this->sdl->start_job('Pianeti terraformati', TICK_LOG_FILE_NPC);
if(!$this->f_trigger_2()) {
$this->sdl->log('Tutor: f_trigger_2 fail!!!', TICK_LOG_FILE_NPC);
}
$this->sdl->finish_job('Pianeti terraformati', TICK_LOG_FILE_NPC);
}
if($triggers['trigger_3'] == 1) {
$this->sdl->start_job('Navi Capitali costruite', TICK_LOG_FILE_NPC);
if(!$this->f_trigger_3()) {
$this->sdl->log('Tutor: f_trigger_3 fail!!!', TICK_LOG_FILE_NPC);
}
$this->sdl->finish_job('Navi Capitali costruite', TICK_LOG_FILE_NPC);
}
if($triggers['trigger_4'] == 1) {
$this->sdl->start_job('Ufficiali Comandanti', TICK_LOG_FILE_NPC);
if(!$this->f_trigger_4()) {
$this->sdl->log('Tutor: f_trigger_4 fail!!!', TICK_LOG_FILE_NPC);
}
$this->sdl->finish_job('Ufficiali Comandanti', TICK_LOG_FILE_NPC);
}
// Fine Main
}
$this->sdl->log('<b>Tutor finished in <font color=#009900>'.round((microtime()+time())-$starttime, 4).' secs</font><br>Executed Queries: <font color=#ff0000>'.$this->db->i_query.'</font></b>', TICK_LOG_FILE_NPC);
}
private function f_trigger_1() {
$sql = 'SELECT user_id, user_name, user_charted FROM user WHERE user_active = 1 AND user_auth_level = 1 AND user_charted > 0 ORDER BY user_charted DESC LIMIT 0,10';
$results = $this->db->queryrowset($sql);
foreach ($results AS $key => $res_item) {
$charted_rank[$key] = array('user_id' => $res_item['user_id'],
'user_name' => $res_item['user_name'],
'user_charted' => $res_item['user_charted']
);
}
$sql = 'UPDATE memory_alpha_triggers SET trigger_1 = 0 WHERE id = 1';
$this->db->query($sql);
$sql = 'UPDATE memory_alpha_storage SET alpha_charted = "'.(urlencode(serialize($charted_rank))).'" WHERE id = 1';
if(!$this->db->query($sql)) {return false;}
return true;
}
private function f_trigger_2() {
$sql='SELECT user_id, user_name, user_tform_planets FROM user WHERE user_active = 1 AND user_auth_level = 1 AND user_tform_planets > 0 ORDER BY user_tform_planets DESC LIMIT 0,10';
$results = $this->db->queryrowset($sql);
foreach ($results AS $key => $res_item) {
$tform_rank[$key] = array ('user_id' => $res_item['user_id'],
'user_name' => $res_item['user_name'],
'user_tform_planets' => $res_item['user_tform_planets']
);
}
$sql = 'UPDATE memory_alpha_triggers SET trigger_2 = 0 WHERE id = 1';
$this->db->query($sql);
$sql = 'UPDATE memory_alpha_storage SET alpha_tform = "'.(urlencode(serialize($tform_rank))).'" WHERE id = 1';
if(!$this->db->query($sql)) {return false;}
return true;
}
private function f_trigger_3() {
$sql='SELECT user_id, user_name, user_made_cships FROM user WHERE user_active = 1 AND user_auth_level = 1 AND user_made_cships > 0 ORDER BY user_made_cships DESC LIMIT 0,10';
$results = $this->db->queryrowset($sql);
foreach ($results AS $key => $res_item) {
$cships_rank[$key] = array ('user_id' => $res_item['user_id'],
'user_name' => $res_item['user_name'],
'user_made_cships' => $res_item['user_made_cships']
);
}
$sql = 'UPDATE memory_alpha_triggers SET trigger_3 = 0 WHERE id = 1';
$this->db->query($sql);
$sql = 'UPDATE memory_alpha_storage SET alpha_cships = "'.(urlencode(serialize($cships_rank))).'" WHERE id = 1';
if(!$this->db->query($sql)) {return false;}
return true;
}
private function f_trigger_4() {
$sql='SELECT user_id, user_name, officer_name, officer_rank, officer_level
FROM officers
INNER JOIN user USING(user_id)
WHERE user_active = 1 AND user_auth_level = 1 AND officer_level > 0 ORDER BY officer_xp DESC LIMIT 0,20';
$results = $this->db->queryrowset($sql);
foreach ($results AS $key => $res_item) {
$officers_rank[$key] = array ('user_id' => $res_item['user_id'],
'user_name' => $res_item['user_name'],
'officer_name' => $res_item['officer_name'],
'officer_rank' => $res_item['officer_rank'],
'officer_level' => $res_item['officer_level']
);
}
$sql = 'UPDATE memory_alpha_triggers SET trigger_4 = 0 WHERE id = 1';
$this->db->query($sql);
$sql = 'UPDATE memory_alpha_storage SET alpha_off = "'.(urlencode(serialize($officers_rank))).'" WHERE id = 1';
if(!$this->db->query($sql)) {return false;}
return true;
}
}