Jump to content
MakeWebGames

Magictallguy

Administrators
  • Posts

    2,026
  • Joined

  • Last visited

  • Days Won

    100

Everything posted by Magictallguy

  1. True! This grants those who prefer an in-site GUI over opening an editor that ability and was originally written with that in mind
  2. And reality - this plane of existence, for example 😉 Better hills to die on, guys!
  3. I believe he's using a PDO wrapper I released a few years ago
  4. Remove the error suppressant from the session_start() call and get the information you need
  5. I quite liked MCC's crime success chance calculation. I feel it was a little lacking on the modifiers side of it as default, but easy enough to extend. I'd suggest doing something similar to it, perhaps incrementally per level range or crime level (don't know what you're intending to do). Alternatively, keep it simple with an "easy", "medium", "hard" at varying integers and use an RNG? <?php // Example // Set array of difficulties with associated percentage of success $difficulties = [ 'easy' => 95, 'medium' => 50, 'hard' => 25, 'extreme' => 10, ]; // Assume $row is an array of crime data, assume "difficulty" is a valid column name with either "easy", "medium", "hard", or "extreme" set if ($difficulties[$row['difficulty']] >= mt_rand(0, 100)) { // success } else { // fail (maybe and/or jail?) } There are many ways to achieve your desired effect; experiment as see what works for you
  6. Provide us with the code. We can't help you if you're only posting your guesses to it
  7. Open a ticket about it. Dave may be able to work with you on this 🙂
  8. If I understand correctly, effectively mirroring MCC v2's forums.php into GL
  9. Mmkay, back on topic, please.
  10. The template, in my opinion isn't great. The colour scheme hurts my eyes and reminds me of baby poop. Sections are spaced out well enough to set some eye-catching stuff. I'd say you've got a few concepts in there I like, but not the best of executions. As for the rest of you; you are welcome to share your opinion about this template on this topic as the OP requested it (a dangerous thing to do on the internet, but ya know..). At no point was slating each other on the table. Rein it in, please.
  11. Community-driven translations from native speakers! Use constants, arrays, a database; whatever gets you valid translations in context.
  12. Somewhat related to the topic; a shim is just a file of functions with the old names doing the new things. To use, you'd simply include it into a core file
  13. You're looking for a shim - search GitHub
  14. Based on the threads in this topic, not likely at all. If you're feeling adventurous, you could attempt a translation matrix yourself 😄
  15. You did read the first post, right? He definitely has thought about it 😄
  16. 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);
  17. 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 😉
  18. You're most welcome 🙂 See the edit for additional information
  19. <?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 = "&gt; <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;
  20. Hey, @athena26! See this icon on the toolbar? Click that before posting code, please!
  21. 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>
  22. MWG was down for over 2 years. The old topics are staying open for now
  23. Code tags! You've got a bunch of none-breaking space entities breaking parsing - the numerous &nbsp;
×
×
  • Create New...