forked from photogabble/blacknova
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sched_news.php
235 lines (211 loc) · 13.1 KB
/
sched_news.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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
<?php
// Blacknova Traders - A web-based massively multiplayer space combat and trading game
// Copyright (C) 2001-2014 Ron Harwood and the BNT development team
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program 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 Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// File: sched_news.php
// Todo: Recode file so that news are generated in the server default language, and remove hard-coded (language) news text from the database
if (strpos($_SERVER['PHP_SELF'], 'sched_news.php')) // Prevent direct access to this file
{
die('Blacknova Traders error: You cannot access this file directly.');
}
// Database driven language entries
$langvars = Bnt\Translate::load($pdo_db, $lang, array('admin', 'common', 'global_includes', 'global_funcs', 'footer', 'news'));
echo "<strong>Posting News</strong><br>\n";
$sql = $db->Execute("SELECT IF(COUNT(*)>0, SUM(colonists), 0) AS total_colonists, COUNT(owner) AS total_planets, owner, character_name FROM {$db->prefix}planets, {$db->prefix}ships WHERE owner != '0' AND owner=ship_id GROUP BY owner ORDER BY owner ASC;");
Bnt\Db::logDbErrors($db, $sql, __LINE__, __FILE__);
while (!$sql->EOF)
{
$row = $sql->fields;
// Get the owner name.
$name = $row['character_name'];
echo " • Processing Planet(s) owned by {$name}({$row['owner']}) - Planets: ". number_format($row['total_planets']) .", Colonists: ". number_format($row['total_colonists']) ."<br>\n";
// Generation of planet amount
if ($row['total_planets'] >= 1000)
{
$sql2 = $db->Execute("SELECT * FROM {$db->prefix}news WHERE user_id = ? AND news_type = 'planet1000';", array($row['owner']));
Bnt\Db::logDbErrors($db, $sql2, __LINE__, __FILE__);
if ($sql2->EOF)
{
$planetcount = 1000;
$langvars['l_news_p_headline2'] = str_replace("[player]", $name, $langvars['l_news_p_headline']);
$headline = $langvars['l_news_p_headline2'] ." ". $planetcount ." ". $langvars['l_news_planets'];
$langvars['l_news_p_text1002'] = str_replace("[name]", $name, $langvars['l_news_p_text1000']);
$news = $db->Execute("INSERT INTO {$db->prefix}news (headline, newstext, user_id, date, news_type) VALUES (?, ?, ?, NOW(), 'planet1000');", array($headline, $langvars['l_news_p_text1002'], $row['owner']));
Bnt\Db::logDbErrors($db, $news, __LINE__, __FILE__);
}
}
elseif ($row['total_planets'] >= 500)
{
$sql2 = $db->Execute("SELECT * FROM {$db->prefix}news WHERE user_id = ? AND news_type = 'planet500';", array($row['owner']));
Bnt\Db::logDbErrors($db, $sql2, __LINE__, __FILE__);
if ($sql2->EOF)
{
$planetcount = 500;
$langvars['l_news_p_headline2'] = str_replace("[player]", $name, $langvars['l_news_p_headline']);
$headline = $langvars['l_news_p_headline2'] ." ". $planetcount ." ". $langvars['l_news_planets'];
$langvars['l_news_p_text502'] = str_replace("[name]", $name, $langvars['l_news_p_text500']);
$news = $db->Execute("INSERT INTO {$db->prefix}news (headline, newstext, user_id, date, news_type) VALUES (?, ?, ?, NOW(), 'planet500');", array($headline, $langvars['l_news_p_text502'], $row['owner']));
Bnt\Db::logDbErrors($db, $news, __LINE__, __FILE__);
}
}
elseif ($row['total_planets'] >= 250)
{
$sql2 = $db->Execute("SELECT * FROM {$db->prefix}news WHERE user_id = ? AND news_type = 'planet250';", array($row['owner']));
Bnt\Db::logDbErrors($db, $sql2, __LINE__, __FILE__);
if ($sql2->EOF)
{
$planetcount = 250;
$langvars['l_news_p_headline2'] = str_replace("[player]", $name, $langvars['l_news_p_headline']);
$headline = $langvars['l_news_p_headline2'] ." ". $planetcount ." ". $langvars['l_news_planets'];
$langvars['l_news_p_text2502'] = str_replace("[name]", $name, $langvars['l_news_p_text250']);
$news = $db->Execute("INSERT INTO {$db->prefix}news (headline, newstext, user_id, date, news_type) VALUES (?, ?, ?, NOW(), 'planet250');", array($headline, $langvars['l_news_p_text2502'], $row['owner']));
Bnt\Db::logDbErrors($db, $news, __LINE__, __FILE__);
}
}
elseif ($row['total_planets'] >= 100)
{
$sql2 = $db->Execute("SELECT * FROM {$db->prefix}news WHERE user_id = ? AND news_type = 'planet100';", array($row['owner']));
Bnt\Db::logDbErrors($db, $sql2, __LINE__, __FILE__);
if ($sql2->EOF)
{
$planetcount = 100;
$langvars['l_news_p_headline2'] = str_replace("[player]", $name, $langvars['l_news_p_headline']);
$headline = $langvars['l_news_p_headline2'] ." ". $planetcount ." ". $langvars['l_news_planets'];
$langvars['l_news_p_text102'] = str_replace("[name]", $name, $langvars['l_news_p_text100']);
$news = $db->Execute("INSERT INTO {$db->prefix}news (headline, newstext, user_id, date, news_type) VALUES (?, ?, ?, NOW(), 'planet100');", array($headline, $langvars['l_news_p_text102'], $row['owner']));
Bnt\Db::logDbErrors($db, $news, __LINE__, __FILE__);
}
}
elseif ($row['total_planets'] >= 50)
{
$sql2 = $db->Execute("SELECT * FROM {$db->prefix}news WHERE user_id = ? AND news_type = 'planet50';", array($row['owner']));
Bnt\Db::logDbErrors($db, $sql2, __LINE__, __FILE__);
if ($sql2->EOF)
{
$planetcount = 50;
$langvars['l_news_p_headline2'] = str_replace("[player]", $name, $langvars['l_news_p_headline']);
$headline = $langvars['l_news_p_headline2'] ." ". $planetcount ." ". $langvars['l_news_planets'];
$langvars['l_news_p_text502'] = str_replace("[name]", $name, $langvars['l_news_p_text50']);
$news = $db->Execute("INSERT INTO {$db->prefix}news (headline, newstext, user_id, date, news_type) VALUES (?, ?, ?, NOW(), 'planet50');", array($headline, $langvars['l_news_p_text502'], $row['owner']));
Bnt\Db::logDbErrors($db, $news, __LINE__, __FILE__);
}
}
elseif ($row['total_planets'] >= 25)
{
$sql2 = $db->Execute("SELECT * FROM {$db->prefix}news WHERE user_id = ? AND news_type = 'planet25';", array($row['owner']));
Bnt\Db::logDbErrors($db, $sql2, __LINE__, __FILE__);
if ($sql2->EOF)
{
$planetcount = 25;
$langvars['l_news_p_headline2'] = str_replace("[player]", $name, $langvars['l_news_p_headline']);
$headline = $langvars['l_news_p_headline2'] ." ". $planetcount ." ". $langvars['l_news_planets'];
$langvars['l_news_p_text252'] = str_replace("[name]", $name, $langvars['l_news_p_text25']);
$news = $db->Execute("INSERT INTO {$db->prefix}news (headline, newstext, user_id, date, news_type) VALUES (?, ?, ?, NOW(), 'planet25');", array($headline, $langvars['l_news_p_text252'], $row['owner']));
Bnt\Db::logDbErrors($db, $news, __LINE__, __FILE__);
}
}
elseif ($row['total_planets'] >= 10)
{
$sql2 = $db->Execute("SELECT * FROM {$db->prefix}news WHERE user_id = ? AND news_type = 'planet10'", array($row['owner']));
Bnt\Db::logDbErrors($db, $sql2, __LINE__, __FILE__);
if ($sql2->EOF)
{
$planetcount = 10;
$langvars['l_news_p_headline2'] = str_replace("[player]", $name, $langvars['l_news_p_headline']);
$headline = $langvars['l_news_p_headline2'] ." ". $planetcount ." ". $langvars['l_news_planets'];
$langvars['l_news_p_text102'] = str_replace("[name]", $name, $langvars['l_news_p_text10']);
$news = $db->Execute("INSERT INTO {$db->prefix}news (headline, newstext, user_id, date, news_type) VALUES (?, ?, ?, NOW(), 'planet10');", array($headline, $langvars['l_news_p_text102'], $row['owner']));
Bnt\Db::logDbErrors($db, $news, __LINE__, __FILE__);
}
}
elseif ($row['total_planets'] >= 5)
{
$sql2 = $db->Execute("SELECT * FROM {$db->prefix}news WHERE user_id = ? AND news_type = 'planet5';", array($row['owner']));
Bnt\Db::logDbErrors($db, $sql2, __LINE__, __FILE__);
if ($sql2->EOF)
{
$planetcount = 5;
$langvars['l_news_p_headline2'] = str_replace("[player]", $name, $langvars['l_news_p_headline']);
$headline = $langvars['l_news_p_headline2'] ." ". $planetcount ." ". $langvars['l_news_planets'];
$langvars['l_news_p_text52'] = str_replace("[name]", $name, $langvars['l_news_p_text5']);
$news = $db->Execute("INSERT INTO {$db->prefix}news (headline, newstext, user_id, date, news_type) VALUES (?, ?, ?, NOW(), 'planet5');", array($headline, $langvars['l_news_p_text52'], $row['owner']));
Bnt\Db::logDbErrors($db, $news, __LINE__, __FILE__);
}
}
// end generation of planet amount
// generation of colonist amount
if ($row['total_colonists'] >= 1000000000)
{
$sql2 = $db->Execute("SELECT * FROM {$db->prefix}news WHERE user_id = ? AND news_type = 'col1000';", array($row['owner']));
Bnt\Db::logDbErrors($db, $sql2, __LINE__, __FILE__);
if ($sql2->EOF)
{
$colcount = 1000;
$langvars['l_news_p_headline2'] = str_replace("[player]", $name, $langvars['l_news_p_headline']);
$headline = $langvars['l_news_p_headline2'] ." ". $colcount ." ". $langvars['l_news_cols'];
$langvars['l_news_c_text10002'] = str_replace("[name]", $name, $langvars['l_news_c_text1000']);
$news = $db->Execute("INSERT INTO {$db->prefix}news (headline, newstext, user_id, date, news_type) VALUES (?, ?, ?, NOW(), 'col1000');", array($headline, $langvars['l_news_c_text10002'], $row['owner']));
Bnt\Db::logDbErrors($db, $news, __LINE__, __FILE__);
}
}
elseif ($row['total_colonists'] >= 500000000)
{
$sql2 = $db->Execute("SELECT * FROM {$db->prefix}news WHERE user_id = ? AND news_type = 'col500';", array($row['owner']));
Bnt\Db::logDbErrors($db, $sql2, __LINE__, __FILE__);
if ($sql2->EOF)
{
$colcount = 500;
$langvars['l_news_p_headline2'] = str_replace("[player]", $name, $langvars['l_news_p_headline']);
$headline = $langvars['l_news_p_headline2'] ." ". $colcount ." ". $langvars['l_news_cols'];
$langvars['l_news_c_text5002'] = str_replace("[name]", $name, $langvars['l_news_c_text500']);
$news = $db->Execute("INSERT INTO {$db->prefix}news (headline, newstext, user_id, date, news_type) VALUES (?, ?, ?, NOW(), 'col500');", array($headline, $langvars['l_news_c_text5002'], $row['owner']));
Bnt\Db::logDbErrors($db, $news, __LINE__, __FILE__);
}
}
elseif ($row['total_colonists'] >= 100000000)
{
$sql2 = $db->Execute("SELECT * FROM {$db->prefix}news WHERE user_id = ? AND news_type = 'col100';", array($row['owner']));
Bnt\Db::logDbErrors($db, $sql2, __LINE__, __FILE__);
if ($sql2->EOF)
{
$colcount = 100;
$langvars['l_news_p_headline2'] = str_replace("[player]", $name, $langvars['l_news_p_headline']);
$headline = $langvars['l_news_p_headline2'] ." ". $colcount ." ". $langvars['l_news_cols'];
$langvars['l_news_c_text1002'] = str_replace("[name]", $name, $langvars['l_news_c_text100']);
$news = $db->Execute("INSERT INTO {$db->prefix}news (headline, newstext, user_id, date, news_type) VALUES (?, ?, ?, NOW(), 'col100');", array($headline, $langvars['l_news_c_text1002'], $row['owner']));
Bnt\Db::logDbErrors($db, $news, __LINE__, __FILE__);
}
}
elseif ($row['total_colonists'] >= 25000000)
{
$sql2 = $db->Execute("SELECT * FROM {$db->prefix}news WHERE user_id = ? AND news_type = 'col25';", array($row['owner']));
Bnt\Db::logDbErrors($db, $sql2, __LINE__, __FILE__);
if ($sql2->EOF)
{
$colcount = 25;
$langvars['l_news_p_headline2'] = str_replace("[player]", $name, $langvars['l_news_p_headline']);
$headline = $langvars['l_news_p_headline2'] ." ". $colcount ." ". $langvars['l_news_cols'];
$langvars['l_news_c_text252'] = str_replace("[name]", $name, $langvars['l_news_c_text25']);
$news = $db->Execute("INSERT INTO {$db->prefix}news (headline, newstext, user_id, date, news_type) VALUES (?, ?, ?, NOW(), 'col25');", array($headline, $langvars['l_news_c_text252'], $row['owner']));
Bnt\Db::logDbErrors($db, $news, __LINE__, __FILE__);
}
}
// end generation of colonist amount
$sql->MoveNext();
} // while
echo "--- <strong>End of News</strong> ---<br><br>\n";
$multiplier = 0; // No need to run this again
?>