public function lookup($name, $rk_num)
    {
        $name = ucfirst(strtolower($name));
        $url = "http://auno.org/ao/char.php?output=xml&dimension={$rk_num}&name={$name}";
        $groupName = "player_history";
        $filename = "{$name}.{$rk_num}.history.xml";
        $maxCacheAge = 86400;
        $cb = create_function('$data', 'if (xml::spliceData($data, "<nick>", "</nick>") != "") {
				return true;
			} else {
				return false;
			}');
        $cacheResult = $this->cacheManager->lookup($url, $groupName, $filename, $cb, $maxCacheAge);
        $obj = new PlayerHistory();
        $obj->name = $name;
        //if there is still no valid data available give an error back
        if ($cacheResult->success !== true) {
            return null;
        } else {
            //parsing of the xml file
            $data = xml::spliceData($cacheResult->data, "<history>", "</history>");
            $data = xml::splicemultidata($data, "<entry", "/>");
            foreach ($data as $hdata) {
                preg_match("/date=\"(.+)\" level=\"(.+)\" ailevel=\"(.*)\" faction=\"(.+)\" guild=\"(.*)\" rank=\"(.*)\"/i", $hdata, $arr);
                $entry = new stdClass();
                $entry->date = $arr[1];
                $entry->level = $arr[2];
                $entry->aiLevel = $arr[3];
                $entry->faction = $arr[4];
                $entry->guild = $arr[5];
                $entry->rank = $arr[6];
                $obj->data[] = $entry;
            }
        }
        return $obj;
    }
Exemplo n.º 2
0
 private function lookup_url($url)
 {
     $playerbio = xml::getUrl($url);
     $xml = new stdClass();
     // parsing of the player data
     $xml->firstname = xml::spliceData($playerbio, '<firstname>', '</firstname>');
     $xml->name = xml::spliceData($playerbio, '<nick>', '</nick>');
     $xml->lastname = xml::spliceData($playerbio, '<lastname>', '</lastname>');
     $xml->level = xml::spliceData($playerbio, '<level>', '</level>');
     $xml->breed = xml::spliceData($playerbio, '<breed>', '</breed>');
     $xml->gender = xml::spliceData($playerbio, '<gender>', '</gender>');
     $xml->faction = xml::spliceData($playerbio, '<faction>', '</faction>');
     $xml->profession = xml::spliceData($playerbio, '<profession>', '</profession>');
     $xml->prof_title = xml::spliceData($playerbio, '<profession_title>', '</profession_title>');
     $xml->ai_rank = xml::spliceData($playerbio, '<defender_rank>', '</defender_rank>');
     $xml->ai_level = xml::spliceData($playerbio, '<defender_rank_id>', '</defender_rank_id>');
     $xml->guild_id = xml::spliceData($playerbio, '<organization_id>', '</organization_id>');
     $xml->guild = xml::spliceData($playerbio, '<organization_name>', '</organization_name>');
     $xml->guild_rank = xml::spliceData($playerbio, '<rank>', '</rank>');
     $xml->guild_rank_id = xml::spliceData($playerbio, '<rank_id>', '</rank_id>');
     return $xml;
 }
 public function lookup($rk_num)
 {
     $serverstat = xml::getUrl("http://probes.funcom.com/ao.xml", 30);
     if ($serverstat == null) {
         return null;
     }
     $data = xml::spliceData($serverstat, "<dimension name=\"d{$rk_num}", "</dimension>");
     if (!$data) {
         return null;
     }
     $obj = new ServerStatus();
     preg_match("/locked=\"(0|1)\"/i", $data, $tmp);
     $obj->locked = $tmp[1];
     preg_match("/<omni percent=\"([0-9.]+)\"\\/>/i", $data, $tmp);
     $obj->omni = $tmp[1];
     preg_match("/<neutral percent=\"([0-9.]+)\"\\/>/i", $data, $tmp);
     $obj->neutral = $tmp[1];
     preg_match("/<clan percent=\"([0-9.]+)\"\\/>/i", $data, $tmp);
     $obj->clan = $tmp[1];
     preg_match("/<servermanager status=\"([0-9]+)\"\\/>/i", $data, $tmp);
     $obj->servermanager = $tmp[1];
     preg_match("/<clientmanager status=\"([0-9]+)\"\\/>/i", $data, $tmp);
     $obj->clientmanager = $tmp[1];
     preg_match("/<chatserver status=\"([0-9]+)\"\\/>/i", $data, $tmp);
     $obj->chatserver = $tmp[1];
     preg_match("/display-name=\"(.+)\" loadmax/i", $data, $tmp);
     $obj->name = $tmp[1];
     $data = xml::spliceMultiData($data, "<playfield", "/>");
     foreach ($data as $hdata) {
         if (preg_match("/id=\"(.+)\" name=\"(.+)\" status=\"(.+)\" load=\"(.+)\" players=\"(.+)%\"/i", $hdata, $arr)) {
             $playfield = new stdClass();
             $playfield->id = $arr[1];
             $playfield->long_name = $arr[2];
             $playfield->status = $arr[3];
             $playfield->load = $arr[4];
             $playfield->percent = $arr[5];
             $obj->data[$arr[1]] = $playfield;
         }
     }
     return $obj;
 }
Exemplo n.º 4
0
    public function get_by_id($guild_id, $rk_num = 0, $force_update = false)
    {
        // if no server number is specified use the one on which the bot is logged in
        if ($rk_num == 0) {
            $rk_num = $this->chatBot->vars["dimension"];
        }
        $name = ucfirst(strtolower($name));
        $url = "http://people.anarchy-online.com/org/stats/d/{$rk_num}/name/{$guild_id}/basicstats.xml";
        $groupName = "guild_roster";
        $filename = "{$guild_id}.{$rk_num}.xml";
        if ($this->chatBot->vars["my_guild_id"] == $guild_id) {
            $maxCacheAge = 21600;
        } else {
            $maxCacheAge = 86400;
        }
        $cb = create_function('$data', 'if (xml::spliceData($data, "<id>", "</id>") != "") {
				return true;
			} else {
				return false;
			}');
        $cacheResult = $this->cacheManager->lookup($url, $groupName, $filename, $cb, $maxCacheAge);
        // if there is still no valid data available give an error back
        if ($cacheResult->success !== true) {
            return null;
        }
        $guild = new stdClass();
        $guild->guild_id = $guild_id;
        // parsing of the memberdata
        $members = xml::splicemultidata($cacheResult->data, "<member>", "</member>");
        $guild->orgname = xml::spliceData($cacheResult->data, "<name>", "</name>");
        $guild->orgside = xml::spliceData($cacheResult->data, "<side>", "</side");
        // pre fetch the charids...this speeds things up immensely
        foreach ($members as $xmlmember) {
            $name = xml::splicedata($xmlmember, "<nickname>", "</nickname>");
            if (!isset($this->chatBot->id[$name])) {
                $this->chatBot->send_packet(new AOChatPacket("out", AOCP_CLIENT_LOOKUP, $name));
            }
        }
        foreach ($members as $member) {
            $name = xml::splicedata($member, "<nickname>", "</nickname>");
            $charid = $this->chatBot->get_uid($name);
            if ($charid == null) {
                $charid = 0;
            }
            $guild->members[$name] = new stdClass();
            $guild->members[$name]->charid = $charid;
            $guild->members[$name]->firstname = xml::spliceData($member, '<firstname>', '</firstname>');
            $guild->members[$name]->name = xml::spliceData($member, '<nickname>', '</nickname>');
            $guild->members[$name]->lastname = xml::spliceData($member, '<lastname>', '</lastname>');
            $guild->members[$name]->level = xml::spliceData($member, '<level>', '</level>');
            $guild->members[$name]->breed = xml::spliceData($member, '<breed>', '</breed>');
            $guild->members[$name]->gender = xml::spliceData($member, '<gender>', '</gender>');
            $guild->members[$name]->faction = $guild->orgside;
            $guild->members[$name]->profession = xml::spliceData($member, '<profession>', '</profession>');
            $guild->members[$name]->prof_title = xml::spliceData($member, '<profession_title>', '</profession_title>');
            $guild->members[$name]->ai_rank = xml::spliceData($member, '<defender_rank>', '</defender_rank>');
            $guild->members[$name]->ai_level = xml::spliceData($member, '<defender_rank_id>', '</defender_rank_id>');
            $guild->members[$name]->guild_id = $guild->guild_id;
            $guild->members[$name]->guild = $guild->orgname;
            $guild->members[$name]->guild_rank = xml::spliceData($member, '<rank_name>', '</rank_name>');
            $guild->members[$name]->guild_rank_id = xml::spliceData($member, '<rank>', '</rank>');
            $guild->members[$name]->dimension = $rk_num;
            $guild->members[$name]->source = 'org_roster';
        }
        // this is done separately from the loop above to prevent nested transaction errors from occuring
        // when looking up charids for characters
        if ($cacheResult->usedCache === false) {
            $this->db->begin_transaction();
            $sql = "UPDATE players SET guild_id = 0, guild = '' WHERE guild_id = ? AND dimension = ?";
            $this->db->exec($sql, $guild->guild_id, $rk_num);
            foreach ($guild->members as $member) {
                $this->playerManager->update($member);
            }
            $this->db->commit();
        }
        return $guild;
    }
Exemplo n.º 5
0
 /**
  * @HandlesCommand("weather")
  * @Matches("/^weather (.+)$/i")
  */
 public function weatherCommand($message, $channel, $sender, $sendto, $args)
 {
     $location = $args[1];
     $blob = '';
     $host = "api.wunderground.com";
     $geolookup = "/auto/wui/geo/GeoLookupXML/index.xml?query=" . urlencode($location);
     $current = "/auto/wui/geo/WXCurrentObXML/index.xml?query=" . urlencode($location);
     $forecast = "/auto/wui/geo/ForecastXML/index.xml?query=" . urlencode($location);
     $alerts = "/auto/wui/geo/AlertsXML/index.xml?query=" . urlencode($location);
     $geolookup = $this->getweatherdata("api.wunderground.com", 80, $geolookup);
     // Geolookup
     if (xml::spliceData($geolookup, "<wui_error>", "</wui_error>") != "") {
         $sendto->reply("No information is available for <highlight>" . $location . "<end>.");
         return;
     }
     $locations = xml::spliceMultiData($geolookup, "<name>", "</name>");
     if (count($locations) > 1) {
         $blob .= "Multiple hits for {$location}.\n\n";
         foreach ($locations as $spot) {
             $blob .= $this->text->make_chatcmd($spot, "/tell <myname> weather {$spot}") . "\n";
         }
         $msg = $this->text->make_blob('Weather Locations', $blob);
         $sendto->reply($msg);
         return;
     }
     $sendto->reply("Collecting data for <highlight>" . $location . "<end>.");
     $current = $this->getweatherdata("api.wunderground.com", 80, $current);
     $forecast = $this->getweatherdata("api.wunderground.com", 80, $forecast);
     $alerts = $this->getweatherdata("api.wunderground.com", 80, $alerts);
     // CURRENT
     $updated = xml::spliceData($current, "<observation_time_rfc822>", "</observation_time_rfc822>");
     if ($updated == ", :: GMT") {
         $sendto->reply("No information is available for <highlight>" . $location . "<end>.");
         return;
     }
     $credit = xml::spliceData($current, "<credit>", "</credit>");
     $crediturl = xml::spliceData($current, "<credit_URL>", "</credit_URL>");
     $observeLoc = xml::spliceData($current, "<observation_location>", "</observation_location>");
     $fullLoc = xml::spliceData($observeLoc, "<full>", "</full>");
     $country = xml::spliceData($observeLoc, "<country>", "</country>");
     $lat = xml::spliceData($observeLoc, "<latitude>", "</latitude>");
     $lon = xml::spliceData($observeLoc, "<longitude>", "</longitude>");
     $elevation = xml::spliceData($observeLoc, "<elevation>", "</elevation>");
     $weather = xml::spliceData($current, "<weather>", "</weather>");
     $tempstr = xml::spliceData($current, "<temperature_string>", "</temperature_string>");
     $humidity = xml::spliceData($current, "<relative_humidity>", "</relative_humidity>");
     $windstr = xml::spliceData($current, "<wind_string>", "</wind_string>");
     $windgust = xml::spliceData($current, "<wind_gust_mph>", "</wind_gust_mph>");
     $pressurestr = xml::spliceData($current, "<pressure_string>", "</pressure_string>");
     $dewstr = xml::spliceData($current, "<dewpoint_string>", "</dewpoint_string>");
     $heatstr = xml::spliceData($current, "<heat_index_string>", "</heat_index_string>");
     $windchillstr = xml::spliceData($current, "<windchill_string>", "</windchill_string>");
     $visibilitymi = xml::spliceData($current, "<visibility_mi>", "</visibility_mi>");
     $visibilitykm = xml::spliceData($current, "<visibility_km>", "</visibility_km>");
     $latlonstr = number_format(abs($lat), 1);
     if (abs($lat) == $lat) {
         $latlonstr .= "N ";
     } else {
         $latlonstr .= "S ";
     }
     $latlonstr .= number_format(abs($lon), 1);
     if (abs($lon) == $lon) {
         $latlonstr .= "E ";
     } else {
         $latlonstr .= "W ";
     }
     $latlonstr .= $this->text->make_chatcmd("Google Map", "/start http://maps.google.com/maps?q={$lat},{$lon}") . " ";
     $latlonstr .= $this->text->make_chatcmd("Wunder Map", "/start http://www.wunderground.com/wundermap/?lat={$lat}&lon={$lon}&zoom=10") . "\n\n";
     $blob .= "Credit: <highlight>" . $this->text->make_chatcmd($credit, "/start {$crediturl}") . "<end>\n";
     $blob .= "Last Updated: <highlight>{$updated}<end>\n\n";
     $blob .= "Location: <highlight>{$fullLoc}, {$country}<end>\n";
     $blob .= "Lat/Lon: <highlight>{$latlonstr}<end>";
     $blob .= "Currently: <highlight>{$tempstr}, {$weather}<end>\n";
     $blob .= "Humidity: <highlight>{$humidity}<end>\n";
     $blob .= "Dew Point: <highlight>{$dewstr}<end>\n";
     $blob .= "Wind: <highlight>{$windstr}<end>";
     if ($windgust) {
         $blob .= " (Gust:{$windgust} mph)\n";
     } else {
         $blob .= "\n";
     }
     if ($heatstr != "NA") {
         $blob .= "Heat Index: <highlight>{$heatstr}<end>\n";
     }
     if ($windchillstr != "NA") {
         $blob .= "Windchill: <highlight>{$windchillstr}<end>\n";
     }
     $blob .= "Pressure: <highlight>{$pressurestr}<end>\n";
     $blob .= "Visibility: <highlight>{$visibilitymi} miles, {$visibilitykm} km<end>\n";
     $blob .= "Elevation: <highlight>{$elevation}<end>\n";
     // ALERTS
     $alertitems = xml::spliceMultiData($alerts, "<AlertItem>", "</AlertItem>");
     if (count($alertitems) == 0) {
         $blob .= "\n<header2>Alerts:<end> None reported.\n\n";
     } else {
         foreach ($alertitems as $thisalert) {
             $blob .= "\n<header2>Alert: " . xml::spliceData($thisalert, "<description>", "</description>") . "<end>\n\n";
             // gotta find date/expire manually.
             $start = strpos($thisalert, ">", strpos($thisalert, "<date epoch=")) + 1;
             $end = strpos($thisalert, "<", $start);
             $blob .= "Issued:<highlight>" . substr($thisalert, $start, $end - $start) . "<end>\n";
             $start = strpos($thisalert, ">", strpos($thisalert, "<expires epoch=")) + 1;
             $end = strpos($thisalert, "<", $start);
             $blob .= "Expires:<highlight>" . substr($thisalert, $start, $end - $start) . "<end>\n";
             $blob .= xml::spliceData($thisalert, "<message>", "</message>") . "";
         }
     }
     // FORECAST
     $simpleforecast = xml::spliceData($forecast, "<simpleforecast>", "</simpleforecast>");
     $forecastday = xml::spliceMultiData($simpleforecast, "<forecastday>", "</forecastday>");
     if (count($forecastday) > 0) {
         foreach ($forecastday as $day) {
             if (!($condition = xml::spliceData($day, "<conditions>", "</conditions>"))) {
                 break;
             }
             $low[0] = xml::spliceData($day, "<low>", "</low>");
             $low[1] = xml::spliceData($low[0], "<fahrenheit>", "</fahrenheit");
             $low[2] = xml::spliceData($low[0], "<celsius>", "</celsius");
             $high[0] = xml::spliceData($day, "<high>", "</high>");
             $high[1] = xml::spliceData($high[0], "<fahrenheit>", "</fahrenheit");
             $high[2] = xml::spliceData($high[0], "<celsius>", "</celsius");
             $pop = xml::spliceData($day, "<pop>", "</pop>");
             $blob .= xml::spliceData($day, "<weekday>", "</weekday>") . ": <highlight>{$condition}<end>";
             if (0 == $pop) {
                 $blob .= "\n";
             } else {
                 $blob .= " ({$pop}% Precip)\n";
             }
             $blob .= "High: <highlight>";
             $blob .= $this->fix_num_space($high[1], 3) . "F";
             $blob .= $this->fix_num_space($high[2], 3) . "C<end>    ";
             $blob .= "Low: <highlight>" . $this->fix_num_space($low[1], 3) . "F";
             $blob .= $this->fix_num_space($low[2], 3) . "C<end>\n\n";
         }
     }
     $msg = $this->text->make_blob('Weather: ' . $location, $blob);
     $sendto->reply($msg);
 }