public static function apply_modifiers($kinskode, $modifiers = array()) { self::$x_last_mods = array(); if (!is_array($modifiers)) { $modifiers = str_split($modifiers); } if (empty($modifiers)) { return $kinskode; } foreach ($modifiers as $mod => $func) { if (isset(self::$deer_modifiers[$func])) { $tfunc = 'modify_' . self::$deer_modifiers[$func]; if (method_exists(__CLASS__, $tfunc)) { $kinskode = self::$tfunc($kinskode); } } } return $kinskode; }
<?php include 'deer.class.php'; $deer = new Deer(); $return = array(); if (@(!empty($_GET['deer']))) { $return = $deer->get_deer($_GET['deer']); } elseif (@(!empty($_GET['q']))) { echo $deer->search_deer($_GET['q']); } else { $stop = 10; $extended = false; if (isset($_GET['extended'])) { $stop = 1; $extended = true; } $return = $deer->paged_deer($_GET['start'], $stop, $extended); } if (!empty($return)) { if (isset($_GET['callback'])) { echo $deer->sanitize_deer($_GET['callback']) . '(' . json_encode($return) . ')'; } else { echo json_encode($return); } }
function deer($processed_data) { if (($type = $this->is_banned($processed_data)) !== false) { $this->log(Bashful::c('bold', 'red') . 'Banned' . Bashful::reset() . ': ' . Bashful::bold() . $processed_data['nick'] . Bashful::unbold() . '@' . $processed_data['host'] . ' on ' . $processed_data['replyto'] . ' (' . $type . ': ' . $processed_data[$type] . ')'); return; } $replyto = $processed_data['recepient']; $privileged = $this->is_privileged($processed_data); if (strpos($replyto, '#') !== 0 && $privileged == false) { $this->log('Ignoring deerme in priv'); return; } $timer_to = 'cake'; //$timer_to = $replyto; // TODO: make this channel specific! if (!isset($this->deer_used[$timer_to])) { $this->deer_used[$timer_to] = false; } $requested_deer = $this->strip_command($processed_data['message']); if ($requested_deer == '') { $requested_deer = 'deer'; } $mods_deer = $this->get_mods($requested_deer); $mods_deer == !empty($mods_deer) ? $mods_deer : array(); $requested_deer = $this->strip_mods($requested_deer); $timeout = $this->deer_timeout; // check for samedeer or samenick. Add timeout as punishment. if ($replyto == $this->last['channel'] && $processed_data['nick'] == $this->last['nick'] || $requested_deer != 'random' && $replyto == $this->last['channel'] && $requested_deer == $this->last['deer'] && array_diff($mods_deer, $this->last['modifiers']) == array()) { $timeout = $timeout * $this->timeout_punish; } // if person is in NICELIST, completely ignore the punishment! :D:D:D $timeout = $privileged != false && is_numeric($privileged['timeout']) ? $privileged['timeout'] : $timeout; // if privileged, undo punish! if ($requested_deer == 'help') { $deertime = !isset($this->deer_used[$timer_to]) || $this->deer_used[$timer_to] + $timeout < microtime(true) ? 'Ready to deer!' : floor($this->deer_used[$timer_to] - microtime(true) + $timeout) . ' seconds until deer.'; $this->notice($processed_data['nick'], chr(02) . 'How to deer:' . chr(02) . ' Type deerme <mods>|<deer> to deer or deerme help modifiers for available mods. (' . Deer::count_deer() . ' deer total) ' . chr(02) . 'Status: ' . chr(02) . $deertime . ' ' . chr(02) . 'Create your own: ' . chr(02) . $this->deeritor, IRCINE_PRIO_MEDIUM); return; } if ($requested_deer == 'help modifiers') { $modifiers = Deer::$deer_modifiers; $mods = array(); foreach ($modifiers as $mod => $name) { $mods[] = $mod . '(=' . $name . ')'; } $mods = implode(', ', $mods); $this->notice($processed_data['nick'], chr(02) . 'Available modifiers: ' . chr(02) . $mods . '.', IRCINE_PRIO_MEDIUM); return; } if ($this->deer_used[$timer_to] + $timeout > microtime(true)) { $this->log('Deer called, but deer not so fast :('); if ($timeout < $this->deer_timeout) { $this->notice($processed_data['nick'], 'You are privileged! You have LOWER timeout than others (-' . ($this->deer_timeout - $timeout) . ' seconds), which is like ' . floor($this->deer_used[$timer_to] - microtime(true) + $timeout) . ' seconds from now, bro.', IRCINE_PRIO_MEDIUM); } elseif ($timeout > $this->deer_timeout) { $this->notice($processed_data['nick'], 'You have somehow been punished! You have HIGHER timeout than others (+' . ($timeout - $this->deer_timeout) . ' seconds), which is like <CENSORED> seconds from now, bro.', IRCINE_PRIO_MEDIUM); } elseif ($timeout == $this->deer_timeout) { $this->notice($processed_data['nick'], 'Deer called, but deer not so fast :( It only walks the earth every ' . $timeout . ' seconds, which is like ' . floor($this->deer_used[$timer_to] - microtime(true) + $timeout) . ' seconds from now, bro.', IRCINE_PRIO_MEDIUM); } return; } // fetch deer from db $deer = Deer::get_deer($requested_deer); if (empty($deer)) { $this->log('No such deer.'); $this->say($replyto, '404: Deer Not Found. Go to ' . $this->deeritor . ' and create it.', IRCINE_PRIO_MEDIUM); return; } // apply modifier, turn into IRC $data = explode(PHP_EOL, Deer::parse_deer(Deer::apply_modifiers($deer['kinskode'], $mods_deer))); foreach ($data as $line) { $this->say($replyto, $line, IRCINE_PRIO_MEDIUM); // TODO: THROTTLE THIS BITCH? } $used_mods = in_array('x', $mods_deer) ? Deer::$x_last_mods : $mods_deer; $used_mods_friendly = empty($used_mods) ? '' : ' (' . implode(', ', $used_mods) . ')'; if (strtolower($requested_deer) == 'random') { $this->say($replyto, $deer['deer'] . ' by ' . $deer['creator'] . $used_mods_friendly, IRCINE_PRIO_MEDIUM); } $this->log('Deer "' . $deer['deer'] . '" is walking in ' . $replyto . '!'); $this->deer_used[$timer_to] = microtime(true); $this->last = array('deer' => $deer['deer'], 'nick' => $processed_data['nick'], 'channel' => $replyto, 'creator' => $deer['creator'], 'modifiers' => $used_mods); }
<?php include 'deer.class.php'; $deer = new Deer(); if (isset($_POST['name'])) { $max_rows = 15; $max_cols = 26; $kins_deer = $deer->fix_deer($max_rows); $irc_deer = $deer->parse_deer($kins_deer); $deername = $deer->write_deer(strtolower($deer->sanitize_deer($_POST['name'])), $deer->sanitize_deer($_POST['creator']), $kins_deer, $irc_deer); $output = array('name' => $deername, 'raw' => $kins_deer, 'ircraw' => $irc_deer); echo json_encode($output); }
} else { return false; } $r = hexdec($r); $g = hexdec($g); $b = hexdec($b); return array($r, $g, $b); } function cache_write($contents, $file) { $fp = fopen($file, 'w'); fwrite($fp, $contents); fclose($fp); } $output = $_GET['output']; $deer = new Deer(); $deer_info = $deer->get_deer($deer->sanitize_deer(isset($_GET['deer']) ? $_GET['deer'] : 'deer')); $kins = $deer_info['kinskode']; if ($deer_info['status'] != 'found') { header('HTTP/1.1 404 Deer Not Found'); die('Deer not found!'); } $modifiers = isset($_GET['modifiers']) && $_GET['modifiers'] != '' ? str_split(preg_replace("/[^a-z]/i", '', $_GET['modifiers'])) : array(); sort($modifiers); $modifiers = implode(array_unique($modifiers)); $sizemultiplier = strpos($modifiers, 'h') !== false ? 3 : 1; $cellspacing = strpos($modifiers, 'c') !== false ? 2 : 0; $lonely_secluded = strpos($modifiers, 'a') !== false ? 10 : 1; if (strlen($modifiers) > 0) { $kins = $deer->apply_modifiers($kins, $modifiers); }