-
Posts
2,140 -
Joined
-
Last visited
-
Days Won
148
Content Type
Profiles
Forums
Events
Everything posted by Magictallguy
-
You're looking for a shim - search GitHub
-
Based on the threads in this topic, not likely at all. If you're feeling adventurous, you could attempt a translation matrix yourself 😄
-
You did read the first post, right? He definitely has thought about it 😄
-
Need to replace my cron_minute with a timestamp
Magictallguy replied to Samurai Legend's topic in Modification Support
One completely untested update to this 🙂 Note: This uses a completely different table to the ones listed above. It stores times as date stamps (i.e., Y-m-d H:i:s). <?php if ('/cronless_crons.php' == $_SERVER['PHP_SELF']) { exit; } define('CHECK_TIMESTAMP_TABLE_EXISTENCE', true); class CronlessCrons { public database $db; private static ?self $inst = null; public array $set = []; private array $timers = []; // cronless_crons.name -> duration in seconds private array $intervals = [ '1m' => 60, '5m' => 300, '1h' => 3600, '1d' => 86400, ]; public function __construct(database $db, array $set = []) { $this->db = $db; $this->setSettings($set); if (CHECK_TIMESTAMP_TABLE_EXISTENCE === true) { $this->checkTable(); } $this->setTimers();; $this->checkTimers(); } public static function getInstance(database $db, array $set): ?self { if (self::$inst === null) { self::$inst = new self($db, $set); } return self::$inst; } private function checkTable() { $getTable = $this->db->query('SELECT 1 FROM cronless_crons'); if (!$this->db->num_rows($getTable)) { $this->db->query(' CREATE TABLE cronless_crons ( id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, name VARCHAR(191) NOT NULL DEFAULT \'\', last_ran TIMESTAMP NOT NULL DEFAULT \'0000-00-00 00:00:00\', INDEX (name) ); '); $values = ''; foreach ($this->intervals as $interval) { $values .= ', (\'' . $interval . '\')'; } $this->db->query('INSERT INTO cronless_crons (name) VALUES ' . substr($values, 2)); } } private function setSettings(array $set = []) { if (empty($set)) { $set = []; $selectSettings = $this->db->query('SELECT conf_name, conf_value FROM settings'); while ($row = $this->db->fetch_row($selectSettings)) { $set[$row['conf_name']] = $row['conf_value']; } } $this->set = $set; } private function setTimers() { $selectTimers = $this->db->query('SELECT name, last_ran FROM cronless_crons'); while ($row = $this->db->fetch_row($selectTimers)) { $this->timers[$row['name']] = $row['last_ran']; } } private function checkTimers() { $currentTime = new DateTime('now'); $currentTimeAsInt = $currentTime->format('U'); foreach ($this->timers as $name => $timer) { $lastRan = strtotime($timer); $interval = $this->intervals[$name]; $deficit = $currentTimeAsInt - $lastRan; if ($deficit > $interval) { $timesToRun = floor($deficit / $interval); $this->runCron($name, $timesToRun); $this->updateLastRan($currentTimeAsInt, $interval); } } } private function updateLastRan(int $currentTimeAsInt, int $interval) { $remaining = $currentTimeAsInt - (floor($currentTimeAsInt / $interval) * $interval); if ($remaining > 0) { $ran = $currentTimeAsInt - $remaining; } else { $ran = $currentTimeAsInt; } $ranAsDate = new DateTime('@' . $ran); $this->db->query('UPDATE cronless_crons SET last_ran = \'' . $ranAsDate . '\' WHERE name = \'' . $name . '\''); } private function runCron(string $name, int $multiplier) { switch ($name) { case '1m': $this->oneMinute($multiplier); break; case '5m': $this->fiveMinutes($multiplier); break; case '1h': $this->oneHour($multiplier); break; case '1d': $this->oneDay($multiplier); break; } } private function oneMinute(int $multiplier) { $this->updateHospJailCounters($multiplier); } private function updateHospJailCounters(int $multiplier) { $this->db->query( 'UPDATE users SET hospital = GREATEST(hospital - ' . $multiplier . ', 0), jail = GREATEST(jail - ' . $multiplier . ', 0) WHERE hospital > 0 OR jail > 0; '); $getCnts = $this->db->query(' SELECT SUM(IF(hospital > 0, 1, 0)) AS hospitalized, SUM(IF(jail > 0, 1, 0)) AS imprisoned FROM users WHERE hospital > 0 OR jail > 0; '); $cnts = $this->db->fetch_row($getCnts); $this->db->query(' UPDATE settings SET conf_value = IF(conf_name = \'hospital_count\', ' . $cnts['hospitalized'] . ', conf_value), conf_value = IF(conf_name = \'jail_count\', ' . $cnts['imprisoned'] . ', conf_value) WHERE conf_name IN(\'hospital_count\', \'jail_count\'); '); } private function fiveMinutes(int $multiplier) { $this->updateUserStatBars(); $this->updatePetStatBars(); } private function updateUserStatBars() { $this->db->query(' UPDATE users SET brave = LEAST(brave + (((maxbrave / 10) + 0.5) * ' . $multiplier . '), maxbrave), hp = LEAST(hp + ((maxhp / 12) * ' . $multiplier . '), maxhp), energy = IF(donatordays > 0, LEAST(energy + ((maxenergy / 5) * ' . $multiplier . '), maxenergy), LEAST(energy + ((maxenergy / 10) * ' . $multiplier . '), maxenergy) ), will = LEAST(maxwill, will + ' . ($multiplier * 100) . '); '); } private function updatePetStatBars() { $this->db->query(' UPDATE pets SET energy = LEAST((energy + ((maxenergy / 30) + 2) * ' . $multiplier . '), maxenergy), hp = LEAST((hp + ((maxhp / 30) + 2) * ' . $multiplier . '), maxhp) WHERE energy < maxenergy OR hp < maxhp; '); } private function oneHour(int $multiplier) { $this->processGangOrganisedCrimes(); if ($this->set['validate_on'] > 0 && $this->set['validate_period'] == 60) { $this->resetValidation(); } } private function processGangOrganisedCrimes() { $this->db->query('UPDATE gangs SET gangCHOURS = GREATEST(gangCHOURS - ' . $multiplier . ', 0) WHERE gangCRIME > 0'); $getOrgCrimes = $this->db->query(' SELECT gangID,ocSTARTTEXT, ocSUCCTEXT, ocFAILTEXT, ocMINMONEY, ocMAXMONEY, ocID, ocNAME FROM gangs AS g LEFT JOIN orgcrimes AS oc ON g.gangCRIME = oc.ocID WHERE g.gangCRIME > 0 AND g.gangCHOURS <= 0 '); if ($this->db->num_rows($getOrgCrimes) > 0) { while ($row = $this->db->fetch_row($getOrgCrimes)) { if (mt_rand(0, 1) === 1) { $money = (int)(mt_rand($row['ocMINMONEY'], $row['ocMAXMONEY'])); $log = str_replace('{muny}', $money, $row['ocSTARTTEXT'] . $row['ocSUCCTEXT']); $outcome = 'success'; } else { $money = 0; $log = $row['ocSTARTTEXT'] . $row['ocFAILTEXT']; $outcome = 'failure'; } $this->db->query('UPDATE gangs SET gangMONEY = gangMONEY + ' . $money . ', gangCRIME = 0 WHERE gangID = ' . $row['gangID']); $this->db->query(' INSERT INTO oclogs (oclOC, oclGANG, oclLOG, oclRESULT, oclMONEY, ocCRIMEN, ocTIME) VALUES (' . $row['ocID'] . ', ' . $row['gangID'] . ', \'' . $this->db->escape($log) . '\', \'' . $outcome . '\', ' . $money . ', \'' . $row['ocNAME'] . '\', ' . time() . ') '); $oclID = $this->db->insert_id(); $selectGangMembers = $this->db->query('SELECT userid FROM users WHERE gang = ' . $row['gangID']); if ($this->db->num_rows($selectGangMembers)) { while ($member = $this->db->fetch_row($selectGangMembers)) { event_add($member['userid'], 'Your Gang\'s Organized Crime ' . ($outcome === 'success' ? 'Succeeded' : 'Failed') . '. Go <a href="oclog.php?ID=' . $oclID . '">here</a> to view the details.'); } } } } } private function resetValidation() { $this->db->query('UPDATE users SET verified = 0 WHERE verified <> 0'); } private function oneDay(int $multiplier) { $this->payJobWages(); $this->updateFedJail(); $this->updateUserDailies(); $this->processUserCourses(); $this->cleanUpVotes(); } private function payJobWages() { $this->db->query(' UPDATE users AS u INNER JOIN userstats AS us ON u.userid = us.userid INNER JOIN jobranks AS jr ON jr.jrID = u.jobrank SET u.money = u.money + jr.jrPAY, u.exp = u.exp + (jr.jrPAY / 20), us.strength = (us.strength + 1) + jr.jrSTRG - 1, us.labour = (us.labour + 1) + jr.jrLABOURG - 1, us.IQ = (us.IQ+1) + jr.jrIQG - 1 WHERE u.job > 0 AND u.jobrank > 0 '); } private function updateFedJail() { $this->db->query('UPDATE fedjail SET fed_days = GREATEST(fed_days - ' . $multiplier . ', 0) WHERE fed_days > 0'); $selectFedded = $this->db->query('SELECT fed_userid FROM fedjail WHERE fed_days <= 0'); $ids = []; if ($this->db->num_rows($selectFedded) > 0) { while ($row = $this->db->fetch_row($selectFedded)) { $ids[] = $row['fed_userid']; } $this->db->query('UPDATE users SET fedjail = 0 WHERE userid IN (' . implode(', ', $ids) . ')'); } $this->db->query('DELETE FROM fedjail WHERE fed_days <= 0'); } private function updateUserDailies() { $this->db->query(' UPDATE users SET daysingang = daysingang + IF(gang > 0, 1, 0), daysold = daysold + 1, boxes_opened = 0, mailban = mailban - IF(mailban > 0, 1, 0), donatordays = donatordays - IF(donatordays > 0, 1, 0), cdays = cdays - IF(course > 0, 1, 0), bankmoney = bankmoney + IF(bankmoney > 0, bankmoney / 50, 0), cybermoney = cybermoney + IF(cybermoney > 0, cybermoney / 100 * 7, 0) '); } private function processUserCourses() { $courses = []; $selectUsersOnCourse = $this->db->query('SELECT userid, course FROM users WHERE cdays <= 0 AND course > 0'); if ($this->db->num_rows($selectUsersOnCourse) > 0) { while ($row = $this->db->fetch_row($selectUsersOnCourse)) { if (!array_key_exists($row['course'], $courses)) { $selectCourse = $this->db->query('SELECT crID, crSTR, crGUARD, crLABOUR, crAGIL, crIQ, crNAME FROM courses WHERE crID = ' . $row['course']); $course = $this->db->fetch_row($selectCourse); $courses[$row['course']] = $course; } else { $course = $courses[$row['course']]; } $this->db->query(' INSERT INTO coursesdone (userid, courseid) VALUES (' . $row['userid'] . ', ' . $row['course'] . ') '); $query = ''; $event = ''; if ($course['crSTR'] > 0) { $query .= ', us.strength = us.strength + ' . $course['crSTR']; $event .= ', ' . number_format($course['crSTR']) . ' strength'; } if ($course['crAGIL'] > 0) { $query .= ', us.agility = us.agility + ' . $course['crAGIL']; $event .= ', ' . number_format($course['crAGIL']) . ' agility'; } if ($course['crLABOUR'] > 0) { $query .= ', us.labour = us.labour + ' . $course['crLABOUR']; $event .= ', ' . number_format($course['crLABOUR']) . ' labour'; } if ($course['crGUARD'] > 0) { $query .= ', us.guard = us.guard + ' . $course['crGUARD']; $event .= ', ' . number_format($course['crGUARD']) . ' guard'; } if ($course['crIQ'] > 0) { $query .= ', us.IQ = us.IQ + ' . $course['crIQ']; $event .= ', ' . number_format($course['crIQ']) . ' IQ'; } if ($query !== '') { $this->db->query(' UPDATE users AS u INNER JOIN userstats AS us ON u.userid = us.userid SET u.course = 0' . $query . ' WHERE u.userid = ' . $row['userid']); event_add($row['userid'], 'Congratulations, you\'ve completed the ' . $course['crNAME'] . ' and gained ' . $event); } } } } private function cleanUpVotes() { $this->db->query('TRUNCATE TABLE votes'); } } /** * UGLY UGLY UGLY! * Set $db and $set properly! Don't be lazy and global scope 'em in */ global $db, $set; CronlessCrons::getInstance($db, $set); -
Split from
-
Note: According to the documentation, only DIRECTORY_SEPARATOR is a valid constant. The others you listed would require defining first. define('DIR_SEPARATOR', DIRECTORY_SEPARATOR); define('DIR_SEP', DIRECTORY_SEPARATOR); Personal opinion: Seems a little lazy to define a constant for an already-existing constant .. should read the documentation 😉
-
You're most welcome 🙂 See the edit for additional information
-
<?php /* * Set to true to enable automatically updating md5-encrypted passwords to the new hashing system. Set to false to disable. * * Note: Ideally, a user should be prompted to update their password themselves, immediately after successful login with an MD5-encrypted password. */ define('UPDATE_OLD_PASSWORDS_TO_NEW_HASH', true); $error = ""; $back = "> <a href = 'login.php'><font color = 'red'>Back</font></a>"; $_POST['pass'] = htmlentities(stripslashes($_POST['pass'])); $_POST['username'] = htmlentities(stripslashes($_POST['username'])); if (!$_POST['username'] || !$_POST['pass']) { $error = "<table width = '390px' align = 'center' class = 'table' style = 'padding:5px; margin-top:87px; border-radius:5px;'> <tr> <td align = 'center'><font color = 'red'><b>Please go back and fill in the form correctly<br>" . $back; } else { $sql = "SELECT `usr_id`,`usr_fed`,`usr_pas` FROM `usr_tbl` WHERE `usr_login` = '" . mysql_real_escape_string($_POST['username']) . "' LIMIT 1"; $sql = mysql_query($sql); if (!mysql_num_rows($sql)) { $error = "<table width = '390px' align = 'center' class = 'table' style = 'padding:5px; margin-top:87px; border-radius:5px;'> <tr> <td align = 'center'><font color = 'red'><b>User not found! Please go back and try again.<br>" . $back; } else { $user = mysql_fetch_array($sql); // Set vars, default to false $passIsMD5 = false; $authed = false; // If their password checks out under the new hashing system if (password_verify($_POST['pass'], $user['usr_pas'])) { // They're authed $authed = true; // If their password checks out under the old md5-encryption } elseif (md5($_POST['pass']) === $user['usr_pas']) { // They're authed .. $authed = true; // .. but we need to update their password* $passIsMD5 = true; } if ($authed !== true) { $error = "<table width = '390px' align = 'center' class = 'table' style = 'padding:5px; margin-top:87px; border-radius:5px;'> <tr> <td align = 'center'><font color = 'red'><b>User not found! Please go back and try again.<br>" . $back; } else { if (UPDATE_OLD_PASSWORDS_TO_NEW_HASH === true && $passIsMD5 === true) { $newPass = password_hash($_POST['pass'], PASSWORD_BCRYPT); mysql_query('UPDATE `usr_tbl` SET `usr_pas` = \''.$newPass.'\' WHERE `usr_id` = '.$user['usr_id']); } unset($_SESSION['feduser']); if ($user['usr_fed'] > time()) { $_SESSION['feduser'] = $user['usr_id']; header('location:fedjail.php'); exit; } else { if ($user['usr_fed']) { $sql = "UPDATE `usr_tbl` SET `usr_fed` = '0' WHERE `usr_id` = '" . mysql_real_escape_string($user['usr_id']) . "'"; mysql_query($sql); } } $_SESSION['myid'] = $user['usr_id']; $_SESSION['verified'] = 0; $sql = "UPDATE `usr_tbl` SET `usr_last_login` = '" . mysql_real_escape_string(time()) . "', `usr_lastact` = '" . mysql_real_escape_string(time()) . "' WHERE `usr_id` = '" . mysql_real_escape_string($_SESSION['myid']) . "'"; mysql_query($sql); } } } Note: Untested! Be sure to update the hashing algorithm used if you set `UPDATE_OLD_PASSWORD_TO_NEW_HASH` to true to whatever you've got in your register Addition: Depending on your DB setup, you may need to increase the storage capacity of the usr_pas column. For example, VARCHAR(255) may not be enough. The query below will modify a column's type to be able to support a longer string of text (i.e., a long password hash). Be sure to backup your database before you make any structural changes! ALTER TABLE `usr_tbl` MODIFY `usr_pas` TEXT NOT NULL;
-
-
Lucky is correct. Your if block logic is a mess. Additionally, according to the CKEditor Documentation, CKEditor replaces the textarea entirely. <div id="editor1"></div>
-
mccode-v2 Honor Awards - Modified by HarryB
Magictallguy replied to HarryB's topic in Free Modifications
MWG was down for over 2 years. The old topics are staying open for now -
mccode-v2 Honor Awards - Modified by HarryB
Magictallguy replied to HarryB's topic in Free Modifications
I've just reviewed the code and don't see the need for one -
The ID attribute needs to remain the same. The duplicate name attribute needs removing.
-
Put the pieces together 🙂
-
`gang` is a valid column name in the `users` table in default MCC v2. Either you're not using v2, or you've renamed the `gang` column
-
Grab the version that @Djkanna has kindly mirror-hosted for us. The module version is 1.1, the codebase it was written for is MCC v2
-
Change $q=$db->query("SELECT * FROM users WHERE cdays=0 AND course > 0"); to $q=$db->query("SELECT * FROM users WHERE cdays <= 0 AND course > 0");
-
@Sim is correct; you need to escape your string variables with mysql_real_escape_string(). $name = mysql_real_escape_string($name); $message = mysql_real_escape_string($message); // escape more strings if needed mysql_query(...);
-
help on inserting something in the header mc codes v2
Magictallguy replied to rednspirited's topic in Modification Support
In the endpage() function, just above the closing </body> tag (recommended), or in the startpage() function somewhere between the <head></head> tags -
Create a directory in `/home/your-username` and name it php-sessions (or something equally obvious) And add session_save_path('/path/to/php-sessions'); above any call to session_start() Also recommend you set the filepath as a variable or constant for ease of future dev (example below) // in a config file define('MY_SESSION_FILEPATH', '/preferrably-absolute/path/to/php-sessions'); // at the session start calls session_save_path(MY_SESSION_FILEPATH); session_start();
-
$itmbuy isn't set because it's part of a braceless if statement, resulting in gap between itmsellvalue and effect1. Simply add a little logic to handle the empty inputs Offending snippet: if (empty($itmname) || empty($itmdesc) || empty($_POST['itmtype']) || empty($_POST['itmbuyprice']) || empty($_POST['itmsellprice'])) $itmbuy = ($_POST['itmbuyable'] == 'on') ? 1 : 0;
-
I'd hazard a guess at a countdown until re-opening
-
Hey I need help.wity my game my Crons doesn't work
Magictallguy replied to athena26's topic in Chit Chat
Underscore != space php http://gangsterparadise.rf.gd/cron_minute.php code=YOUR_CODE_HERE Rinse and repeat (with the schedule) for each cron -
Hey I need help.wity my game my Crons doesn't work
Magictallguy replied to athena26's topic in Chit Chat
You added an underscore between `.php` and `code` Additionally, you may want to change that code and keep your new one private 😉