Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mysql 8 Fixes #39

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions includes/CallbackHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,29 +39,29 @@ public function apply() {
if (empty($this->calls)) return;
$success = array();
$errors = array();
$query = $db->sql_query('SELECT c.id, c.function, c.type, c.mod_id, m.root, m.title FROM '.TABLE_XTENSE_CALLBACKS.' c LEFT JOIN '.TABLE_MOD.' m ON c.mod_id = m.id WHERE c.active = 1 AND m.active = 1 AND c.type IN ("'.implode('", "', $this->types).'")');

$query = $db->sql_query('SELECT c.`id`, c.`function`, c.`type`, c.`mod_id`, m.`root`, m.`title` FROM '.TABLE_XTENSE_CALLBACKS.' c LEFT JOIN '.TABLE_MOD.' m ON c.`mod_id` = m.`id` WHERE c.`active` = 1 AND m.`active` = 1 AND c.`type` IN ("'.implode('", "', $this->types).'")');
while ($call = $db->sql_fetch_assoc($query)) {
foreach ($this->calls[$call['type']] as $params) {
$this->currentCallback = $call;

try {
$instance = Callback::load($call['root']);

if (!method_exists($instance, $call['function']) || !is_callable(array($instance, $call['function']))) throw new Exception('Invalid method "'.$call['function'].'"');

$execReturn = $instance->{$call['function']}($params);

$io->append_call($call, $execReturn);
} catch (mysqli_sql_exception $e) {
$io->append_call_error($call, 'Erreur MySQL lors de l\'execution'."\n".$e->getFile().' @ '.$e->getLine()."\n".$e->getMessage());
} catch (Exception $e) {
$io->append_call_error($call, $e->getMessage(), $e);
}

$this->currentCallback = false;
} // Foreach
} // while

} // Method "apply"
}
64 changes: 32 additions & 32 deletions includes/check_callbacks.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,39 +11,39 @@

// Vidange de la table
$db->sql_query('TRUNCATE TABLE `'.TABLE_XTENSE_CALLBACKS.'`');
$insert = array();
$callInstall = array('errors' => array(), 'success' => array());
$query = $db->sql_query('SELECT action, root, id, title FROM '.TABLE_MOD.' WHERE active = 1');
while ($data = $db->sql_fetch_assoc($query)) {
if (!file_exists('mod/'.$data['root'].'/_xtense.php')) continue;
try {
$call = Callback::load($data['root']);


$insert = array();
$callInstall = array('errors' => array(), 'success' => array());

$query = $db->sql_query('SELECT `action`, `root`, `id`, `title` FROM '.TABLE_MOD.' WHERE `active` = 1');
while ($data = $db->sql_fetch_assoc($query)) {
if (!file_exists('mod/'.$data['root'].'/_xtense.php')) continue;
try {
$call = Callback::load($data['root']);
$error = false;
} catch (Exception $e) {
$callInstall['errors'][] = $data['title'].' (erreur lors du chargement du lien) : '.$e->getMessage();
} catch (Exception $e) {
$callInstall['errors'][] = $data['title'].' (erreur lors du chargement du lien) : '.$e->getMessage();
$error = true;
}
}
if(!$error)
foreach ($call->getCallbacks() as $k => $c) {
try {
if (empty($c)) continue;
if (!isset($c['function'], $c['type'])) throw new Exception('Données sur le lien invalides : '.$k);
if (!in_array($c['type'], $callbackTypesNames)) throw new Exception('Type de lien ('.$c['type'].') invalide');
if (!isset($c['active'])) $c['active'] = 1;
if (!method_exists($call, $c['function'])) throw new Exception('La méthode "'.$c['function'].'" n'existe pas');
$insert[] = '('.$data['id'].', "'.$c['function'].'", "'.$c['type'].'", '.$c['active'].')';
$callInstall['success'][] = $data['title'].' (#'.$k.') : '.$c['type'];
} catch (Exception $e) {
$callInstall['errors'][] = $data['title'].' : '.$e->getMessage();
}
}
}
if (!empty($insert)) {
$db->sql_query('REPLACE INTO '.TABLE_XTENSE_CALLBACKS.' (mod_id, function, type, active) VALUES '.implode(', ', $insert));
}
return $callInstall;
foreach ($call->getCallbacks() as $k => $c) {
try {
if (empty($c)) continue;
if (!isset($c['function'], $c['type'])) throw new Exception('Données sur le lien invalides : '.$k);
if (!in_array($c['type'], $callbackTypesNames)) throw new Exception('Type de lien ('.$c['type'].') invalide');
if (!isset($c['active'])) $c['active'] = 1;
if (!method_exists($call, $c['function'])) throw new Exception('La méthode "'.$c['function'].'" n'existe pas');
$insert[] = '('.$data['id'].', "'.$c['function'].'", "'.$c['type'].'", '.$c['active'].')';
$callInstall['success'][] = $data['title'].' (#'.$k.') : '.$c['type'];
} catch (Exception $e) {
$callInstall['errors'][] = $data['title'].' : '.$e->getMessage();
}
}
}

if (!empty($insert)) {
$db->sql_query('REPLACE INTO '.TABLE_XTENSE_CALLBACKS.' (`mod_id`, `function`, `type`, `active`) VALUES '.implode(', ', $insert));
}
return $callInstall;

102 changes: 51 additions & 51 deletions includes/config.php
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
<?php
/**
* @package Xtense 2
* @author Unibozu
* @licence GNU
*/
if (!defined('IN_SPYOGAME')) die("Hacking Attempt!");
global $table_prefix;
define('TABLE_XTENSE_GROUPS', $table_prefix.'xtense_groups');
define('TABLE_XTENSE_CALLBACKS', $table_prefix.'xtense_callbacks');
define('TABLE_PARSEDREC', $table_prefix.'parsedRec');
define('TABLE_PARSEDSPYEN', $table_prefix.'parsedSpyEn');
define('TYPE_PLANET', 0);
define('TYPE_MOON', 1);
if (file_exists ("../mod/{$root}/version.txt"))
list($mod_name, $mod_version, $mod_install, $ogspy_min_version, $toolbar_min_version) = file("../mod/{$root}/version.txt");
else
list($mod_name, $mod_version, $mod_install, $ogspy_min_version, $toolbar_min_version) = file("mod/{$root}/version.txt");
define('PLUGIN_VERSION', trim($mod_version));
define('TOOLBAR_MIN_VERSION', trim($toolbar_min_version));
$database = array(
'ressources' => array('metal','cristal','deuterium','energie','activite'),
'ressources_p' => array('M_percentage','C_Percentage','D_percentage','CES_percentage','CEF_percentage','SAT_percentage','FOR_percentage'),
'buildings' => array('M', 'C', 'D', 'CES', 'CEF', 'UdR', 'UdN', 'CSp', 'SAT', 'HM', 'HC', 'HD', 'FOR', 'Lab', 'Ter','Dock', 'Silo', 'DdR', 'BaLu', 'Pha', 'PoSa'),
'labo' => array('Esp', 'Ordi', 'Armes', 'Bouclier', 'Protection', 'NRJ', 'Hyp', 'RC', 'RI', 'PH', 'Laser', 'Ions', 'Plasma', 'RRI', 'Graviton', 'Astrophysique'),
'defense' => array('LM', 'LLE', 'LLO', 'CG', 'LP', 'AI', 'PB', 'GB', 'MIC', 'MIP'),
'fleet' => array('PT', 'GT', 'CLE', 'CLO', 'CR', 'VB', 'VC', 'REC', 'SE', 'BMD', 'SAT', 'DST', 'EDLM', 'FOR','TRA','FAU', 'ECL')
);
$databaseSpyId = array(
'ressources' => array( 601 => 'metal',602 => 'cristal',603 => 'deuterium',604 => 'energie'),
//'debris' => array(701 =>'metal',702 =>'cristal',703 =>'deuterium'), Not Supported by OGSpy yet
'buildings' => array( 1 =>'M', 2 =>'C', 3 =>'D', 4 =>'CES', 12 =>'CEF', 14 =>'UdR', 15 =>'UdN', 21 =>'CSp', 22 =>'HM', 23 =>'HC', 24 =>'HD', 31 =>'Lab', 33 =>'Ter',34 =>'DdR', 44 =>'Silo', 36 =>'Dock', 41 =>'BaLu', 42 =>'Pha', 43 =>'PoSa'),
'labo' => array(106 =>'Esp', 108 =>'Ordi', 109 =>'Armes', 110 =>'Bouclier', 111 =>'Protection', 113 =>'NRJ', 114 =>'Hyp', 115 =>'RC', 117 =>'RI', 118 =>'PH', 120 =>'Laser', 121 =>'Ions', 122 =>'Plasma', 123 =>'RRI', 124 =>'Astrophysique', 199 =>'Graviton' ),
'defense' => array(401 =>'LM', 402 =>'LLE', 403 =>'LLO', 404 =>'CG', 405 =>'AI', 406 =>'LP', 407 =>'PB', 408 =>'GB', 502 =>'MIC', 503 =>'MIP'),
'fleet' => array(202 =>'PT', 203 =>'GT', 204 =>'CLE', 205 =>'CLO', 206 =>'CR', 207 =>'VB', 208 =>'VC', 209 =>'REC', 210 =>'SE', 211 => 'BMD', 212 =>'SAT', 213 =>'DST', 214 =>'EDLM', 215 => 'TRA', 217 =>'FOR', 218 => 'FAU', 219 => 'ECL')
);
$callbackTypesNames = array(
'overview','system','ally_list','buildings','research','fleet','fleetSending','defense','spy','ennemy_spy','rc',
'rc_cdr', 'msg', 'ally_msg', 'expedition','ranking'
);
<?php
/**
* @package Xtense 2
* @author Unibozu
* @licence GNU
*/

if (!defined('IN_SPYOGAME')) die("Hacking Attempt!");

global $table_prefix;

define('TABLE_XTENSE_GROUPS', $table_prefix.'xtense_groups');
define('TABLE_XTENSE_CALLBACKS', $table_prefix.'xtense_callbacks');
define('TABLE_PARSEDREC', $table_prefix.'parsedRec');
define('TABLE_PARSEDSPYEN', $table_prefix.'parsedSpyEn');

define('TYPE_PLANET', 0);
define('TYPE_MOON', 1);

if (file_exists ("../mod/{$root}/version.txt"))
list($mod_name, $mod_version, $mod_install, $ogspy_min_version, $toolbar_min_version) = file("../mod/{$root}/version.txt");
else
list($mod_name, $mod_version, $mod_install, $ogspy_min_version, $toolbar_min_version) = file("mod/{$root}/version.txt");

define('PLUGIN_VERSION', trim($mod_version));
define('TOOLBAR_MIN_VERSION', trim($toolbar_min_version));

$database = array(
'ressources' => array('metal','cristal','deuterium','energie','activite'),
'ressources_p' => array('M_percentage','C_Percentage','D_percentage','CES_percentage','CEF_percentage','SAT_percentage','FOR_percentage'),
'buildings' => array('M', 'C', 'D', 'CES', 'CEF', 'UdR', 'UdN', 'CSp', 'SAT', 'HM', 'HC', 'HD', 'FOR', 'Lab', 'Ter','Dock', 'Silo', 'DdR', 'BaLu', 'Pha', 'PoSa'),
'labo' => array('Esp', 'Ordi', 'Armes', 'Bouclier', 'Protection', 'NRJ', 'Hyp', 'RC', 'RI', 'PH', 'Laser', 'Ions', 'Plasma', 'RRI', 'Graviton', 'Astrophysique'),
'defense' => array('LM', 'LLE', 'LLO', 'CG', 'LP', 'AI', 'PB', 'GB', 'MIC', 'MIP'),
'fleet' => array('PT', 'GT', 'CLE', 'CLO', 'CR', 'VB', 'VC', 'REC', 'SE', 'BMD', 'SAT', 'DST', 'EDLM', 'FOR','TRA','FAU', 'ECL')
);

$databaseSpyId = array(
'ressources' => array( 601 => 'metal',602 => 'cristal',603 => 'deuterium',604 => 'energie'),
//'debris' => array(701 =>'metal',702 =>'cristal',703 =>'deuterium'), Not Supported by OGSpy yet
'buildings' => array( 1 =>'M', 2 =>'C', 3 =>'D', 4 =>'CES', 12 =>'CEF', 14 =>'UdR', 15 =>'UdN', 21 =>'CSp', 22 =>'HM', 23 =>'HC', 24 =>'HD', 31 =>'Lab', 33 =>'Ter',34 =>'DdR', 44 =>'Silo', 36 =>'Dock', 41 =>'BaLu', 42 =>'Pha', 43 =>'PoSa'),
'labo' => array(106 =>'Esp', 108 =>'Ordi', 109 =>'Armes', 110 =>'Bouclier', 111 =>'Protection', 113 =>'NRJ', 114 =>'Hyp', 115 =>'RC', 117 =>'RI', 118 =>'PH', 120 =>'Laser', 121 =>'Ions', 122 =>'Plasma', 123 =>'RRI', 124 =>'Astrophysique', 199 =>'Graviton' ),
'defense' => array(401 =>'LM', 402 =>'LLE', 403 =>'LLO', 404 =>'CG', 405 =>'AI', 406 =>'LP', 407 =>'PB', 408 =>'GB', 502 =>'MIC', 503 =>'MIP'),
'fleet' => array(202 =>'PT', 203 =>'GT', 204 =>'CLE', 205 =>'CLO', 206 =>'CR', 207 =>'VB', 208 =>'VC', 209 =>'REC', 210 =>'SE', 211 => 'BMD', 212 =>'SAT', 213 =>'DST', 214 =>'EDLM', 215 => 'TRA', 217 =>'FOR', 218 => 'FAU', 219 => 'ECL')
);

$callbackTypesNames = array(
'overview','system','ally_list','buildings','research','fleet','fleetSending','defense','spy','ennemy_spy','rc',
'rc_cdr', 'msg', 'ally_msg', 'expedition','ranking'
);


50 changes: 25 additions & 25 deletions includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,23 @@
*/
function install_callbacks ($action, $data, $version = null) {
global $db, $table_prefix;

define('XTENSE_LITE_CONFIG', 1);
require_once('mod/xtense/includes/config.php');

if ($version != null && version_compare($version, MOD_VERSION, '<=')) return false;
$query = $db->sql_query('SELECT id FROM '.TABLE_MOD.' WHERE action = "'.$action.'"');

$query = $db->sql_query('SELECT `id` FROM '.TABLE_MOD.' WHERE `action` = "'.$action.'"');
list($mod_id) = $db->sql_fetch_row($query);

$replace = array();
foreach ($data as $k => $call) {
if (!isset($call['function'], $call['type'])) return false;
if (!isset($call['active'])) $call['active'] = 1;
if (!isset($call['active'])) $call['active'] = 1;
$replace[] = '('.$mod_id.', "'.$call['function'].'", "'.$call['type'].'", '.$call['active'].')';
}
$db->sql_query('INSERT IGNORE INTO '.TABLE_XTENSE_CALLBACKS.' (mod_id, function, type, active) VALUES '.implode(',', $replace));

$db->sql_query('INSERT IGNORE INTO '.TABLE_XTENSE_CALLBACKS.' (`mod_id`, `function`, `type`, `active`) VALUES '.implode(',', $replace));
return $db->sql_affectedrows();
}

Expand Down Expand Up @@ -98,13 +98,13 @@ function json_quote($str) {

function home_check($type, $coords) {
global $db, $user_data;

$empty_planets = array(101=>1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);
$empty_moons = array(201=>1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20);
$planets = $moons = array();
$offset = ($type == TYPE_PLANET ? 100 : 200);
$query = $db->sql_query("SELECT `planet_id`, `coordinates` FROM ".TABLE_USER_BUILDING." WHERE `user_id` = ".$user_data['user_id']." ORDER BY planet_id ASC");

$query = $db->sql_query("SELECT `planet_id`, `coordinates` FROM ".TABLE_USER_BUILDING." WHERE `user_id` = ".$user_data['user_id']." ORDER BY `planet_id` ASC");
while ($data = $db->sql_fetch_assoc($query)) {
if ($data['planet_id'] < 200) {
$planets[$data['planet_id']] = $data['coordinates'];
Expand All @@ -122,18 +122,18 @@ function home_check($type, $coords) {
if (isset($moons[$id+100])) return array('update', 'id' => $id+100);
else return array('add', 'id' => $id+100);
}

return array('update', 'id' => $id);
}
}

// Si une lune correspond a la planete, on place la planete sous la lune
foreach ($moons as $id => $m) {
if ($m == $coords) {
return array($type == TYPE_PLANET ? 'add' : 'update', 'id' => $id-200+$offset);
}
}

if ($type == TYPE_PLANET) {
if (count($empty_planets) == 0) return array('full');
foreach ($empty_planets as $p) return array('add', 'id' => $p+$offset);
Expand Down Expand Up @@ -185,38 +185,38 @@ function add_log($type, $data = null) {
if(!isset($data['toolbar'])) {$data['toolbar'] = "";}
if ($type == 'buildings' || $type == 'overview' || $type == 'defense' || $type == 'research' || $type == 'fleet'||$type == 'info') {
if (!$server_config['xtense_log_empire']) return;

if ($type == 'buildings') $message = 'envoie les batiments de sa planète '.$data['planet_name'].' ('.$data['coords'].')';
if ($type == 'overview') $message = 'envoie les informations de sa planète '.$data['planet_name'].' ('.$data['coords'].')';
if ($type == 'defense') $message = 'envoie les defenses de sa planète '.$data['planet_name'].' ('.$data['coords'].')';
if ($type == 'research') $message = 'envoie ses recherches';
if ($type == 'fleet') $message = 'envoie la flotte de sa planète '.$data['planet_name'].' ('.$data['coords'].')';
if ($type == 'info') $message = $data['message'];
}

if ($type == 'system') {
if (!$server_config['xtense_log_system']) return;

$message = 'envoie le système solaire '.$data['coords'];
}

if ($type == 'ranking') {
if (!$server_config['xtense_log_ranking']) return;

$message = 'envoie le classement '.$data['type2'].' des '.$data['type1'].' ('.$data['offset'].'-'.($data['offset']+99).') : '.date('H', $data['time']).'h';
}

if ($type == 'ally_list') {
$message = 'envoie la liste des membres de l\'alliance '.$data['tag'];
}

if ($type == 'rc') {
$message = 'envoie un rapport de combat';
}

if ($type == 'messages') {
$message = 'envoie sa page de messages';

$extra = array();
if (array_key_exists('msg', $data)) $extra[] = 'messages : '.$data['msg'];
if (array_key_exists('ally_msg', $data)) $extra[] = $data['ally_msg'].' messages d\'alliance';
Expand All @@ -225,7 +225,7 @@ function add_log($type, $data = null) {
if (array_key_exists('expedition', $data)) $extra[] = $data['expedition'].' rapports d\'expedition';
if (array_key_exists('added_spy', $data)) $extra[] = ' Rapport d\'espionnage ajouté : '.$data['added_spy_coords'];
if (array_key_exists('ignored_spy', $data)) $extra[] = $data['ignored_spy'].' rapports d\'espionnage ignorés';

if (!empty($extra)) $message .= ' ('.implode(', ', $extra).')';
}
if (!empty($message)) {
Expand Down Expand Up @@ -293,4 +293,4 @@ function update_boosters($boosterdata, $current_time ){
}
}/*$booster_table = array('booster_m_val', 'booster_m_date', 'booster_c_val', 'booster_c_date', 'booster_d_val', 'booster_d_date', 'extention_p', 'extention_m');*/
return $boosters;
}
}
Loading
Loading