-
Notifications
You must be signed in to change notification settings - Fork 2
/
flottes_plugin.php
367 lines (324 loc) · 12.5 KB
/
flottes_plugin.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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
<?php
/***************************************************************************
* filename : flottes_plugin.php
* @package Flottes 1.03
* @author Conrad des Dragons
* created : 19/12/2005
* modified : 30/07/2006 00:00:00
***************************************************************************/
/*
if (!defined('IN_SPYOGAME')) {
die("Hacking attempt");
}
*/
/*
* fonction import par plugin
*/
function mod_flottes_plugin_shipbyid($idplan,$ship) {
global $db, $table_prefix, $user_data;
define("TABLE_MOD_FLOTTES", $table_prefix."mod_flottes");
define("TABLE_MOD_FLOTTES_ADM", $table_prefix."mod_flottes_admin");
if (defined("OGS_PLUGIN_DEBUG")) global $fp;
if (defined("OGS_PLUGIN_DEBUG")) fwrite($fp,"=> entrée fonction mod_flottes_plugin_shipbyid!\n");
if (defined("OGS_PLUGIN_DEBUG")) fwrite($fp,"planetid: ".$idplan." - contenu flotte: ".$ship."!\n");
// $idplan = ID OGSpy de la planète format INT(11) valeurs comprise entre 1 et 18
// $ship = texte brut écran flotte OGame équivalant au copié - collé classique pour ajouter des donnée dans OGSpy avant le plugin
$user_empire = user_get_empire($user_data["user_id"]);
$user_building = $user_empire["building"];
require_once("./mod/flottes/flottes_lang.php");
//// Recherche du jeu
/*
$request= "SELECT GAME, nbpla FROM ".TABLE_MOD_FLOTTES_ADM." WHERE group_name='mod_flottes'";
if($result = $db->sql_query($request)) {
while($ligne = mysql_fetch_row($result)) {
$GA=$ligne[0];
$PLA=$ligne[1];
}
}
else {
$GA='OGAME';
}
if ($GA=='UNIVERS')
{
*/
/// fin de recherche
$lines = array();
$ship = stripcslashes($ship);
$lines = explode(chr(10), $ship);
$datei= mktime(0, 0, 0, date("m") , date("d"), date("Y"));
$OK = false;
$out=0;
$mess="Mise à jour flotte";
$get_ship = array("PT" => 0, "GT" => 0, "CLE" => 0, "CLO" => 0, "CR" => 0, "VB" => 0,
"VC" => 0, "REC" => 0, "SE" => 0, "BMD" => 0, "DST" => 0, "EDLM" => 0, "TRA" =>0, "SAT" =>0);
foreach ($lines as $line) {
$arr = array();
$line = trim($line);
if(strpos($line, "Type de vaisseau") === 0 ) {
$OK = true;
continue;
}
else {
$out=2;
$mess = "Ce n'est pas un écran de flotte";
}
// On enlève le séparateur décimal
$line = str_replace('.', '', $line);
if($OK && preg_match("/^([\D\s]+)\s+(\d+)/", $line, $arr)) {
foreach($mod_flottes_lang as $key => $name) {
if($name==trim($arr[1])) {
$get_ship[$key] = $arr[2];
break;
}
}
continue;
}
}
$sql="SELECT planet_id from ".TABLE_MOD_FLOTTES." WHERE planet_id=".$idplan." AND user_id=".$user_data['user_id'];
if(!($result = $db->sql_query($sql))) {
$out = 1;
$mess=$db->sql_error();
}
else {
$result = $db->sql_query($sql);
$nameid=$db->sql_numrows($result) ;
if (defined("OGS_PLUGIN_DEBUG")) fwrite($fp,"=> nameid :".$nameid."\n");
if ($nameid==1)
{
/// Si la planète existe déjà on met à jour les données
$request = "UPDATE ".TABLE_MOD_FLOTTES." SET";
foreach($get_ship as $key => $value) {
$request .= " `".$key."`=".$value.", ";
}
// $request = substr($request, 0, strlen($request)-2);
if (isset($user_building[$idplan]["planet_name"])& $user_building[$idplan]["planet_name"]!=''){
$nom_planet=$user_building[$idplan]["planet_name"];
$coord_planet=$user_building[$idplan]["coordinates"];
}
else {
$nom_planet=$idplan;
$coord_planet="0";
}
if ($coord_planet=="" or $coord_planet==NULL) $coord_planet="0";
$request .=" `planet_name`='".$nom_planet."', ";
$request .=" `coordinates`='".$coord_planet."', ";
$request .=" `date`=".$datei;
$request .= " WHERE user_id=".$user_data['user_id'];
$request .=" AND planet_id=".$idplan;
$db->sql_query($request);
if (defined("OGS_PLUGIN_DEBUG")) fwrite($fp,"=> requête :".$request."\n");
}
else {
/// Sinon on créé la planète et on met à jour les données
$request = "INSERT INTO ".TABLE_MOD_FLOTTES." (user_id, planet_id) VALUES (".$user_data['user_id'].", ".$idplan." )" ;
if(!($result = $db->sql_query($request))) {
$out = 1;
$mess=$db->sql_error();
}
else {
if (isset($user_building[$idplan]["planet_name"])& $user_building[$idplan]["planet_name"]!=''){
$nom_planet=$user_building[$idplan]["planet_name"];
$coord_planet=$user_building[$idplan]["coordinates"];
}
else {
$nom_planet=$idplan;
$coord_planet="0";
}
if ($coord_planet=="" or $coord_planet==NULL) $coord_planet="0";
$request = "UPDATE ".TABLE_MOD_FLOTTES." SET planet_name ='".$nom_planet."'";
$request .=", coordinates='".$coord_planet."'";
$request .=", date=".$datei;
$request .= " WHERE user_id=".$user_data['user_id'];
$request .=" AND planet_id=".$idplan;
$db->sql_query($request);
if (defined("OGS_PLUGIN_DEBUG")) fwrite($fp,"=> requête :".$request."\n");
$request = "UPDATE ".TABLE_MOD_FLOTTES." SET";
foreach($get_ship as $key => $value) {
$request .= " `".$key."`=".$value.", ";
}
$request = substr($request, 0, strlen($request)-2);
$request .= " WHERE user_id=".$user_data['user_id'];
$request .=" AND planet_id=".$idplan;
$db->sql_query($request);
}
}
$request= "DELETE FROM ".TABLE_MOD_FLOTTES." WHERE planet_id=0";
$db->sql_query($request);
}
if (defined("OGS_PLUGIN_DEBUG")) fwrite($fp,"=> sortie fonction mod_flottes_plugin_shipbyid : ".$out."\n");
/// $out = 0 si import OK
/// $out = 1 si n'a pas trouvé la planète
/// $out = 2 si le texte envoyé ne contient pas 'Type de vaisseau'
/// en cas d'échec, la variable $mess prend la valeur de l'erreur SQL
return $out;
}
function mod_flottes_plugin_shipbyname($nplan,$ship) {
// $nplan = Texte contenant le nom et les coordonnées de la planète ex: TRUlulu [4:245:3]
// $ship = texte brut écran flotte OGame équivalant au copié - collé classique pour ajouter des donnée dans OGSpy avant le plugin
global $db, $table_prefix, $user_data;
define("TABLE_MOD_FLOTTES", $table_prefix."mod_flottes");
define("TABLE_MOD_FLOTTES_ADM", $table_prefix."mod_flottes_admin");
if (defined("OGS_PLUGIN_DEBUG")) global $fp;
if (defined("OGS_PLUGIN_DEBUG")) fwrite($fp,"=> entrée fonction mod_flottes_plugin_ship!\n");
if (defined("OGS_PLUGIN_DEBUG")) fwrite($fp,"planetid: ".$nplan." - contenu flotte: ".$ship."!\n");
$user_empire = user_get_empire($user_data["user_id"]);
$user_building = $user_empire["building"];
require_once("mod/flottes/flottes_lang.php");
//Flotte
/*
$flottes_lang["planet_name"]= "Nom Planet";
$flottes_lang["coordinates"]= "Coordonnées";
$flottes_lang["planet_id"]= "ID Planet";
$flottes_lang["PT"] = "Petit transporteur";
$flottes_lang["GT"] = "Grand transporteur";
$flottes_lang["CLE"] = "Chasseur léger";
$flottes_lang["CLO"] = "Chasseur lourd";
$flottes_lang["CR"] = "Croiseur";
$flottes_lang["VB"] = "Vaisseau de bataille";
$flottes_lang["VC"] = "Vaisseau de colonisation";
$flottes_lang["REC"] = "Recycleur";
$flottes_lang["SE"] = "Sonde espionnage";
$flottes_lang["BMD"] = "Bombardier";
$flottes_lang["DST"] = "Destructeur";
$flottes_lang["EDLM"] = "Étoile de la mort";
$flottes_lang["TRA"] = "Traqueur";
$flottes_lang["SAT"] = "Satellite solaire";
*/
$lines = array();
$ship = stripcslashes($ship);
$lines = explode(chr(10), $ship);
$datei= mktime(0, 0, 0, date("m") , date("d"), date("Y"));
$OK = false;
$out=0;
$idplan=0;
$mess="Mise à jour flotte";
$namplan=array();
$coorplan=array();
$nplan=trim($nplan);
$valid=0;
/// extraction de l'id planète
$patcoor="/[0-9:]{4,8}/";
$patname="#^[^ ]+\s#";
if(preg_match($patname, $nplan, $namplan)) {
if (defined("OGS_PLUGIN_DEBUG")) fwrite($fp,"namplan :".$namplan[0]."-".$valid."-!\n");
if (substr($namplan[0],0,4)=="lune"){
$valid=9;
}
else $valid=0;
}
else {
$out=1;
}
if(preg_match($patcoor, $nplan, $coorplan)) {
if (defined("OGS_PLUGIN_DEBUG")) fwrite($fp,"coorplan :".$coorplan[0]."-".$valid."-!\n");
for ($i=1 ; $i<=18 ; $i++) {
$coord = $user_building[$i]["coordinates"];
if ($coord == $coorplan[0] ) {
$idplan = $i;
if ($idplan<10) $idplan=$idplan+$valid;
break;
}
}
}
if (defined("OGS_PLUGIN_DEBUG")) fwrite($fp,"idplan :".$idplan."!\n");
// echo " : ".$namplan[0]." - ".$idplan." - ".$coorplan[0];
/// extraction de la flotte
$get_ship = array("PT" => 0, "GT" => 0, "CLE" => 0, "CLO" => 0, "CR" => 0, "VB" => 0,
"VC" => 0, "REC" => 0, "SE" => 0, "BMD" => 0, "DST" => 0, "EDLM" => 0, "TRA" =>0, "SAT" =>0);
foreach ($lines as $line) {
$arr = array();
$line = trim($line);
if(strpos($line, "Type de vaisseau") === 0 ) {
$OK = true;
continue;
}
else {
$out=2;
$mess = "Ce n'est pas un écran de flotte";
}
// On enlève le séparateur décimal
$line = str_replace('.', '', $line);
if($OK && preg_match("/^([\D\s]+)\s+(\d+)/", $line, $arr)) {
foreach($mod_flottes_lang as $key => $name) {
if($name==trim($arr[1])) {
$get_ship[$key] = $arr[2];
break;
}
}
continue;
}
}
$sql="SELECT planet_id from ".TABLE_MOD_FLOTTES." WHERE planet_id=".$idplan." AND user_id=".$user_data['user_id'];
if(!($result = $db->sql_query($sql))) {
$out = 1;
$mess=$db->sql_error();
}
else {
$result = $db->sql_query($sql);
$nameid=$db->sql_numrows($result) ;
if ($nameid==1)
{
/// Si la planète existe déjà on met à jour les données
$request = "UPDATE ".TABLE_MOD_FLOTTES." SET";
foreach($get_ship as $key => $value) {
$request .= " `".$key."`=".$value.", ";
}
// $request = substr($request, 0, strlen($request)-2);
if (isset($user_building[$idplan]["planet_name"])& $user_building[$idplan]["planet_name"]!=''){
$nom_planet=$user_building[$idplan]["planet_name"];
$coord_planet=$user_building[$idplan]["coordinates"];
}
else {
$nom_planet=$idplan;
$coord_planet="0";
}
if ($coord_planet=="" or $coord_planet==NULL) $coord_planet="0";
$request .=" `planet_name`='".$nom_planet."', ";
$request .=" `coordinates`='".$coord_planet."', ";
$request .=" `date`=".$datei;
$request .= " WHERE user_id=".$user_data['user_id'];
$request .=" AND planet_id=".$idplan;
$db->sql_query($request);
}
else {
/// Sinon on créé la planète et on met à jour les données
$request = "INSERT INTO ".TABLE_MOD_FLOTTES." (user_id, planet_id) VALUES (".$user_data['user_id'].", ".$idplan." )" ;
if(!($result = $db->sql_query($request))) {
$out = 1;
$mess=$db->sql_error();
}
else {
if (isset($user_building[$idplan]["planet_name"])& $user_building[$idplan]["planet_name"]!=''){
$nom_planet=$user_building[$idplan]["planet_name"];
$coord_planet=$user_building[$idplan]["coordinates"];
}
else {
$nom_planet=$idplan;
$coord_planet="0";
}
if ($coord_planet=="" or $coord_planet==NULL) $coord_planet="0";
$request = "UPDATE ".TABLE_MOD_FLOTTES." SET planet_name ='".$nom_planet."'";
$request .=", coordinates='".$coord_planet."'";
$request .=", date=".$datei;
$request .= " WHERE user_id=".$user_data['user_id'];
$request .=" AND planet_id=".$idplan;
$db->sql_query($request);
$request = "UPDATE ".TABLE_MOD_FLOTTES." SET";
foreach($get_ship as $key => $value) {
$request .= " `".$key."`=".$value.", ";
}
$request = substr($request, 0, strlen($request)-2);
$request .= " WHERE user_id=".$user_data['user_id'];
$request .=" AND planet_id=".$idplan;
$db->sql_query($request);
}
}
$request= "DELETE FROM ".TABLE_MOD_FLOTTES." WHERE planet_id=0";
$db->sql_query($request);
}
/// $out = 0 si import OK
/// $out = 1 si n'a pas trouvé la planète
/// $out = 2 si le texte envoyé ne contient pas 'Type de vaisseau'
/// en cas d'échec, la variable $mess prend la valeur de l'erreur SQL
return $out;
}