BeBot - An Anarchy Online and Age Of Conan chat automaton

Archive => Anarchy Online Archive => 0.2.x Custom/Unofficial Modules => Topic started by: craized on April 28, 2005, 09:32:04 am

Title: Alien Playfield Module - Keep track of alien PF
Post by: craized on April 28, 2005, 09:32:04 am
ALIEN PLAYFIELD MODULE (http://www.craized.net/junk/bebot/highlight.php?Playfield)

Description:
A module which keeps track of when the gates open for the alien playfield. The module notifies privgroup and org chat at 1 hours, 30 minutes, 15 minutes, 5 minutes, and when the gates open.


WARNING: Timing for the playfield seems to jump when the servers go down, so until I find a better way of calculating the time, all I can do is do my best to keep the downloadable version current.
Title: Alien Playfield Module - Keep track of alien PF
Post by: Lal on April 28, 2005, 10:22:34 am
Last patch FC did something to the gates, the exact time might have changed.
Title: Alien Playfield Module - Keep track of alien PF
Post by: Glarawyn on April 28, 2005, 06:59:12 pm
How is it you're guesstimating the gate opening/closing? Looks like you have to know when one opening happens then the timer?

If you want to go more advanced, you could make use of the server information provided at http://probes.funcom.com/ and guess at the gates based on when the server goes up and down...
Title: Alien Playfield Module - Keep track of alien PF
Post by: craized on April 28, 2005, 09:19:41 pm
Definitely a good idea following server down time, but when the server goes down, the bot char gets kicked from that chat servers making it tricky to track down time. I may use $commands[disconnect] and $commands[connect] to track it through the DB. Hopefully it works, thanks for the suggestion.
Title: Alien Playfield Module - Keep track of alien PF
Post by: Ryvral on May 16, 2005, 07:59:55 pm
I noticed a !setpf in the modules.. Is this used to set the timer? If so can you show an example?
Title: Alien Playfield Module - Keep track of alien PF
Post by: craized on May 16, 2005, 08:55:21 pm
Yes, the !setpf is used to set the timer, but unfortunitely it doesn't work. I was trying to make the module re-write a variable inside iteself when the !setpf was used, so that changes don't get lost every time it restarts.

Recently I've stopped playing AO, so my means of testing/developing these modules has become a problem. I'll still continue hosting them, but I'm not expecting much to happen as far as updates. Everything here is open source, anyone is free to take my code, use it in their own modules etc. I would be very happy to see my work being used to complete existing modules.

If anyone is interested in hosting the files for me send me an e-mail, my server will be going down when I move for college in late August. Until then, all of it should be available.
Title: Alien Playfield Module - Keep track of alien PF
Post by: Ryvral on May 24, 2005, 07:47:08 am
How about using the database for keeping time? Then !setpf could just update the database?
Title: Alien Playfield Module - Keep track of alien PF
Post by: Nesi on May 29, 2005, 02:06:35 pm
The chat servers usually stay up when the game servers go down. So making it reset on a reconnect might not be a good idea. On apfbot the admins set the time until gates open when the servers come back up.
It puts a timestamp in the database and everyone can check the  remaining time using !gates !time or !timer in a tell.

Got no clue how it works these days cause i don't play the game anymore, but im not getting any complaints so i guess it's working alright:)
Title: Alien Playfield Module - Keep track of alien PF
Post by: Derroylo on June 20, 2005, 10:37:12 am
i am using the db to save the pftime cuz this version doesn´t seems to work coreectly. When you are interested i can post it :)
Title: Alien Playfield Module - Keep track of alien PF
Post by: craized on June 20, 2005, 01:21:12 pm
Please post it. I may not be playing, but I'm still interested in how you're planning on getting this to work right.
Title: Alien Playfield Module - Keep track of alien PF
Post by: Glarawyn on June 22, 2005, 12:03:42 am
I have no idea if my server uptime is right anymore, but I put together a web based timer as an expirment before making a bot plugin.

APF Spawn Time guesstimator (http://zibby.isa-geek.net/apf.php)

Currntly it takes the uptime, adds 7 hours. Then that value goes into a loop that adds 7 hours and 20 minutes (or was it 15 or 10? hmmm...). I don't do anything with the times that have already passsed, but I do keep track of how many times the script added 7 hours and 20 minutes so that the webpages displays:

There have been 37 gate openings since the AO servers were last restarted.
(Or however many gate openings there have been.)

Anyway, I added the extra time because the opening and closing of the gates is dependant on the Unicorn Gatekeeper, who runs around to each playfield to open the gate before resetting his timer. So adding somewhere between 10 and 20 extra minutes to account for the putzy Gatekeeper and the 10 minutes of the gates being open seemed to get a fairly accurate guess...as long as you get the uptime right.

For a bot plugin, I'd use similar logic I suppose.

/tell botname !setpf
- Sets timer using now as the opening time of the gates.

/tell botname !setpf 2005-06-10 18:33:18 UTC
- Sets the timer using the given time stamp.


/tell botname !apf

Bot would retrive the last opening time from the database, loop around till it found the first timestamp > than current time, and stop looping when timestamp > timestamp + 7 hours.

/tell username APF gates will open at <timestamp>, X hours and Y minutes from now.

From there just add a cron job that to do the org/channel announcments...

Or something. :)
Title: Alien Playfield Module - Keep track of alien PF
Post by: craized on June 22, 2005, 12:57:28 am
Has it been accurate after a server reset? And if so could you post the PHP, or zip your code/change the extension so people can view/download it please?
Great job getting this together.
Title: Alien Playfield Module - Keep track of alien PF
Post by: Glarawyn on June 23, 2005, 04:59:37 pm
http://zibby.isa-geek.net/apf.phps

There are a few obvious issues, such as the clock on the server hosting the code in it's current state needs to be set to UTC time. :)

Notice that there is no way to set the uptime except by editing the source. I made this to be a test after all... :)
Title: Alien Playfield Module - Keep track of alien PF
Post by: Derroylo on July 04, 2005, 04:51:29 pm
Modified PF Modul (http://nne-clan.clanintern.de/bebot/playfield.phps)

This is the modified Version of the PF Modul from craized. It is using the DB now to save the timer. This is not the version i am using atm cuz i changed some commands. Using SQLite instead of the normal MYSQL Database atm. When there is some interest i will show you how you can switch to SQLite :)

I just got a idea how i could check maybe if the server is up or not. Need to test it when the Server is going down for a patch/maintenance. Hope it works :)
Title: Alien Playfield Module - Keep track of alien PF
Post by: Derroylo on July 05, 2005, 02:56:57 pm
You can get the infos from http://probes.funcom.com/ao.xml if the servers are up or down. Hope i have some time the next days to implement it in the module :)
Title: Alien Playfield Module - Keep track of alien PF
Post by: Xenixa on October 29, 2005, 06:07:56 pm
Updated this module to grab Glarawyn's Timestamp from her website and store in the bots local database.

Also changed it to use the Settings Table rather than a seperate table as originally modified by Derroylo.
ftp://xen.afraid.org/bebot_files/Playfield.php

!apf works in Tells, Guild Chat and Guest channels.
I kept the !setpf command

  EDIT: I fixed my error I was having with the Tell commands. You can redownload from same link above if you had already grabbed it.
Works as advertised. :)
Title: Alien Playfield Module - Keep track of alien PF
Post by: Enian on November 03, 2005, 10:15:13 pm
That script sounds really really interesting but the link seems to be broken  :(
Could you post source ?
Title: Alien Playfield Module - Keep track of alien PF
Post by: Xenixa on November 04, 2005, 11:02:26 am
Hmm odd my FTP server is running and the URL should work.

Never Mind: just saw afraid.org was down for a bit earlier in the day but didn't think it would affect a Dynamic URL that points to my local server here at home.

Anywho give a try again. If no download I'll post the code.
Title: Alien Playfield Module - Keep track of alien PF
Post by: Enian on November 04, 2005, 12:12:55 pm
Ho nice, its up again :D

I will try this script right now, feedback in a bit  8)
Title: Alien Playfield Module - Keep track of alien PF
Post by: Enian on November 04, 2005, 12:17:04 pm
Amazing work ! Gratz :p
Title: Alien Playfield Module - Keep track of alien PF
Post by: Wanuarmi on November 13, 2005, 08:48:53 am
Quote from: "Xenixa"
Updated this module to grab Glarawyn's Timestamp from her website and store in the bots local database.

Also changed it to use the Settings Table rather than a seperate table as originally modified by Derroylo.
ftp://xen.afraid.org/bebot_files/Playfield.php


I had a problem making this work with my server's timezone, after messing around with php's date functions I made a quick and dirty change thats working so far:

Code: [Select]
$this -> timeleft = ($time+$int+$int*$raids)-mktime();

in that line I just added an hour like this:

Code: [Select]
$this -> timeleft = ($time+$int+$int*$raids)-mktime()+60*60;

also added this so you dont have to restart the bot everytime you !setpf

Code: [Select]
$this -> stamp = $settime;

after

Code: [Select]
$this -> bot -> send_tell($name, "Time Stamp is set.");
Title: Alien Playfield Module - Keep track of alien PF
Post by: Xenixa on November 13, 2005, 04:12:39 pm
Actually I already fixed that issue with having to restart. Just hadn't updated the copy on my ftp server yet.
In the copy I have posted, Copy the follow line from the function Playfield (&$bot) to the begining of the function time()
Code: [Select]
$this -> stamp = $this -> get_timer();
That will allow the bot to pull the time from the DB on start-up and the latest time recorded everytime the apf command is used.

Your timezone fix btw would be for those that are +GMT
If you are at GMT or in a timezone that is in a -GMT timezone the orginal should work just fine. Does for me anyway as I'm -7 GMT
Title: Alien Playfield Module - Keep track of alien PF
Post by: Wanuarmi on November 14, 2005, 04:22:20 am
uhm it worked well for a couple of raids and then went on saying there was 8 hrs till apf ><

back to php's date functions...
Title: Alien Playfield Module - Keep track of alien PF
Post by: Wanuarmi on November 15, 2005, 01:49:09 am
fixed it :P I had removed intval() from get_timer() function, cause it was adding five minutes to glarawin's timer.
Title: Alien Playfield Module - Keep track of alien PF
Post by: Xenixa on November 15, 2005, 02:29:50 am
Thats wierd I had to put intval() on $result[1] to get it to work at all. *shrug*

Removing it totaly f***s up my bot.
Title: Alien Playfield Module - Keep track of alien PF
Post by: Wanuarmi on November 15, 2005, 05:36:39 am
removing or not the bug is still there

the script works either way tho, just wrong timer ;/ gonna redownload yours...
Title: Alien Playfield Module - Keep track of alien PF
Post by: Xenixa on November 15, 2005, 05:49:13 am
Just now placed the latest copy that works for me on my ftp server. See post above for link.

Changed the method to ensure its evaluating an Integer in get_timer() to:
Code: [Select]
   function get_timer() {
    $result = $this -> bot -> db -> select("SELECT * FROM settings WHERE setting = 'apf_timer'");
        return (int)$result[1];
    }


Also has the changes to the function time().
i.e. added the line $this -> stamp = $this -> get_timer(); to ensure it has the lastest time stamp from the DB.

Oh and added more feed back on !setpf
Title: Alien Playfield Module - Keep track of alien PF
Post by: Wanuarmi on November 15, 2005, 06:05:18 am
gotta trim the $timestamp

$this -> bot -> send_tell($name, "Time Stamp is set to $TimeStamp.");

theres a new line at the end
Title: Alien Playfield Module - Keep track of alien PF
Post by: Xenixa on November 15, 2005, 06:36:06 am
Just remove the period in here $TimeStamp." No trim necessary.
Title: Alien Playfield Module - Keep track of alien PF
Post by: Solerna on November 21, 2005, 01:56:50 am
ok I've got some issues here and considering the time of the day I'm probably missing something. since I wanted to have the ability to use a timestamp I had set myself I did an alernative to the !setpf command named !altsetpf It's basicly a copy of !setpf with the only change that it takes the time from another site. In this case (http://www.och.nu/serenity/apf.timestamp) since I needed something to test with.

__________________
To [Pfnet]: !apf
[Pfnet]: 00:37:54 remaining until Alien Playfield opens.
To [Pfnet]: !setpf
[Pfnet]: Time Stamp is set to gatetime 2005-11-19 20:45:15 UTC

To [Pfnet]: !apf
[Pfnet]: 00:37:46 remaining until Alien Playfield opens.
To [Pfnet]: !altsetpf
[Pfnet]: Time Stamp is set to gatetime 2005-11-19 20:52:15 UTC
To [Pfnet]: !apf
[Pfnet]: 00:37:38 remaining until Alien Playfield opens.
__________

checking timer. making sure it is set to the first sites timestamp. checking it again.  and the timer seems to be ok.  Now I'm setting it to my alt sites timestamp. As u can se !altsetpf does have another timestamp. so far so good. Now I check the timer using the new timestamp. And the timer hasn't changed? oO

The timer in the script is curently 7 mins of on rk2 and I had some hopes to correct it this way. However it does not seem as if the bot cares about the timestamp. Rebooting the bot gives the exact same time.

Any ideas?
Title: Alien Playfield Module - Keep track of alien PF
Post by: Xenixa on November 21, 2005, 09:20:17 am
My first question would be then is the time in the database actually being changed when you call the TimeStamp from the other site?

Best way to check I guess would be to query the settings table using whatever query tool you use after you set one then the other and compare the value recorded.

Edit: Or on second thought you could test from within the bot itself.
Change"
Code: [Select]
$this -> bot -> send_tell($name, "Time Stamp is set to $TimeStamp");
To:
Code: [Select]
$this -> bot -> send_tell($name, "Time Stamp is set to " . $this -> get_timer());

That will show you the UnixTime ingame from the database as $TimeStamp shows you what the bot got back from the Website(s).
Title: Alien Playfield Module - Keep track of alien PF
Post by: Solerna on November 21, 2005, 03:48:39 pm
Fater changing that I get:

Time Stamp is set to 0

Pussled me so I did some other similar changes.

I added a "   $this -> bot -> send_tell($name, $settime);"
Just before changing the DB result:

1132433115

So it seems he does take the date from the webpage and uses it atleast as far as making the $settime.

____________________________
        $this -> bot -> db -> query("UPDATE settings SET value = '".$settime."' WHERE setting = 'apf_timer'");
____
       $result = $this -> bot -> db -> select("SELECT * FROM settings WHERE setting = 'apf_timer'");

____________________________

First one is the setting of the timestamp in the Db, second one is retreiving it.

But is the second on correct? could check at since bot is curently being used (Kinda shitty setup atm)

$result = $this -> bot -> db -> select("SELECT value FROM settings WHERE setting = 'apf_timer'");

but shouldn't it be like this when retreiving the timestamp?
Title: Alien Playfield Module - Keep track of alien PF
Post by: Xenixa on November 21, 2005, 07:19:38 pm
The select method shouldn't matter really. I'm just so used to pulling an entire row and then looking at the pieces of that row.
But now that you bring it up I guess we really only need to pull the Value.

Just don't forget to remove the array qualifier off of $result. Or for comparision:
Code: [Select]
function get_timer() {
    $result = $this -> bot -> db -> select("SELECT value FROM settings WHERE setting = 'apf_timer'");
        return (int)$result;
    }
Title: Alien Playfield Module - Keep track of alien PF
Post by: Solerna on November 22, 2005, 02:35:02 am
Hmm nope that didn't do the trick. =/

Still get "Time Stamp is set to 0" and the timer doesn't change at all.

Starting to wonder if I'm crazy or something.
What pussles me even more is how this could be possible and yet the timer is running after I reboot the bot >.<
Title: Alien Playfield Module - Keep track of alien PF
Post by: Xenixa on November 22, 2005, 05:58:49 am
hmm, sounds like the field in the Database isn't really being updated. BTW I've since changed my playfield.php but havn't posted the changes.

Basically what I did was in the function time() I removed the $this -> stamp = $this -> get_timer(); and changed $time = $this -> stamp to $time = $this -> get_timer()

Also in the function Playfield (&$bot) I swaped out the $this -> stamp = $this -> get_timer(); with $time = $this -> get_timer()

More to eliminate an un-needed variable.
Title: Alien Playfield Module - Keep track of alien PF
Post by: Solerna on November 22, 2005, 05:02:57 pm
ok Gave up  on my copy of module. downloaded yours.

added

Code: [Select]
$this -> bot -> send_tell($name, "Time Stamp is set to " . $this -> get_timer());


And I still get :  Time Stamp is set to 0

After getting more confused I actually deleted the entire settings table and recreated it incase there had sneaked in some errors there. Still I get the same result.

I'm starting to get curious here, is this actually working for u?
Title: Alien Playfield Module - Keep track of alien PF
Post by: Solerna on November 22, 2005, 05:46:27 pm
Hehe I'm going to fill this thread solo. Ok I found a way to actually get the timestamp not result in showing as 0

Code: [Select]

    function get_timer() {
        $result = $this -> bot -> get_setting("apf_timer");
        return (int)$result;
    }


Resulting in "Time Stamp is set to 1132433115"

Since we are using a setting this function does the trick and I don't have to worry about it.

This seems to fix all the issues I had =)
Or atleast I hope so. Now all I got to do is to fix my alt site and set the timestamp there.
Title: Alien Playfield Module - Keep track of alien PF
Post by: Xenixa on November 23, 2005, 10:08:18 pm
Yes it works for me. I'm curious however, were exactly is this get_setting() function defined? I've never seen it before and I can't find it.
Title: Alien Playfield Module - Keep track of alien PF
Post by: Solerna on November 23, 2005, 11:31:36 pm
Function is defined in bot. php


Code: [Select]

/*
        Returns a selected setting:
        */
        function get_setting($set)
        {
                $res = $this -> db -> select("SELECT * FROM settings"
                        . " WHERE setting = '" . $set . "'");

                if (!empty($res))
                        return $res[0][1];
                else
                        return "";
        }
Title: Alien Playfield Module - Keep track of alien PF
Post by: Xenixa on November 24, 2005, 09:39:47 pm
Hmm, was that a custom Bot.php. The vanilla ones don't have that function. Added it to my copy of bot.php anyway for future use. :)

Updated my copy of Playfield.php (http://ftp://xen.afraid.org/bebot_files/Playfield.php) to use the above function after placing the function in my copy of Bot.php (Placed just above the is_member() function.) Works fine and dandy.
Title: Alien Playfield Module - Keep track of alien PF
Post by: Wanuarmi on November 24, 2005, 11:09:30 pm
xen you should make a new topic and keep the first post updated :p
Title: Alien Playfield Module - Keep track of alien PF
Post by: Solerna on November 25, 2005, 06:57:21 am
hmm no now when u say it I think I added that with some module. Got to check that, aught to have documented it somwere.

Yes, I asked for help with a banfunction and someone posted that. His example used this function

http://bebot.fieses.net/viewtopic.php?t=192
Title: Alien Playfield Module - Keep track of alien PF
Post by: Glarawyn on November 27, 2005, 09:18:36 pm
I used my vacation time wisely, and ported over the module I'd written for VashBotPHP over to BeBot, and started adding functionality.

What I've done:
- Timestamp info is cached to the database, and automatically recached from my website every 4 hours. The apf.timestamp file is the 3rd most popular file on my website thanks to various bots. Thankfully it's not a large file. ;)

- Timestamp can be forced to refresh by an admin using the !setapf command.

To Do:
- Finish automatic hourly/countdown alerts in guild chat and private group.

Future versions:

- Allow disabling of web updates and setting the timestamp information from tells.

- Add a configuration setting for disabing/enabling automatic guild chat and private group alerts.

- Other stuff TBD. ;)


I'm travelling for business for the next two weeks, so I should actually have some free time to work on this as meals and cleaning and stuff are taken care of.
Title: Alien Playfield Module - Keep track of alien PF
Post by: Wanuarmi on December 01, 2005, 10:20:29 pm
on all server resets after getting the new timestamp I need to edit the code and add/subtract hours for it to be right for some reason...
Title: Alien Playfield Module - Keep track of alien PF
Post by: Xenixa on December 02, 2005, 01:26:18 am
What OS you running your Bot on Wanuarmi?

Mine stays pretty much accurate after AO server restarts and a new Timestamp is posted. Usually 3 mins faster than what Glarawyn has posted.
Title: Alien Playfield Module - Keep track of alien PF
Post by: Wanuarmi on December 02, 2005, 01:50:16 am
im using debian linux... not sure about the timezone set in the box, gonna mess with that later. I always try to match the time with campalot, using /campalot !apf, maybe Glara's bot isnt always synchronized with her timestamp.
Title: Alien Playfield Module - Keep track of alien PF
Post by: Wanuarmi on December 07, 2005, 08:40:27 am
Quote from: "Xenixa"
Thats wierd I had to put intval() on $result[1] to get it to work at all. *shrug*

Removing it totaly f*** up my bot.


I think I finally sort this out... shouldnt it be $result[0][1]?
Title: Re: Alien Playfield Module - Keep track of alien PF
Post by: Wanuarmi on December 19, 2005, 10:16:25 pm
updated this a bit, added 2 hours alert, changed alert color to green (looks better on raidbots) and made it automatically update cache on midnight

if you want to change the alert color just change the $this -> alert_color = "#00F700"; variable


modules/Playfield.php
Code: [Select]
<?php
 
/*
  * Playfield Module for BE Bot <http://bebot.fieses.net>
  * Module coded by Craized <http://www.craized.net>
  * Originally modified by Derroylo
  *
  * Modified to use Time Stamp From Glarawyn's site by Xenixa (RK1)
  * Now uses settings table
  */

  /*
  Add a "_" at the beginning of the file (_Playfield.php) if you do not want it to be loaded.
  */

// Commented Line below is intedended to set an initial value and was used for testing.
//$db -> query("REPLACE INTO settings (setting, value) VALUES ('apf_timer', '1130355492')");
               

$playfield = new Playfield($bot);

$commands["tell"]["apf"] = &$playfield;
$commands["tell"]["setpf"] = &$playfield;
$commands["pgmsg"]["apf"] = &$playfield;
$commands["gc"]["apf"] = &$playfield;
$cron["2sec"][] = &$playfield;

/*
The Class itself...
*/
class Playfield {
    var 
$bot;
var $alert_color;

    
/*
    Constructor:
    Hands over a referance to the "Bot" class.
    */
    
function Playfield (&$bot) {
        
$this -> bot = &$bot;
        if(
$this -> bot -> highlight_color) {
            
$this -> highlight "<font color=" $this -> bot -> highlight_color ">";
            } else {
            
$this -> highlight "<font color=#FFFFFF>";
        }
$this -> alert_color "#00F700";
        
$this -> get_timer();
    }

    
/*
    This gets called on a tell with the command
    */
    
function tell($name$msg
    {
        if (
preg_match("/^" $this -> bot -> commpre "apf$/i"$msg))
        { 
            
$this -> time();
            
$this -> bot -> send_tell($name$this -> msg);
        }
        elseif (
preg_match("/^" $this -> bot -> commpre "setpf$/i"$msg))
        { 
            
$this -> set_timer($name$msg);
        }
    }

 
/*
    This gets called on a msg in the privgroup with the command
    */
    
function pgmsg($name$msg) {
        
$this -> time();
        
$this -> bot -> send_pgroup($this -> msg);
    }

    
/*
    This gets called on a msg in the guildchat with the command
    */
    
function gc($name$msg) {
        
$this -> time();
        
$this -> bot -> send_gc($this -> msg);
        
$this -> bot -> log(GROUPSEND$this -> msg);
    }

    
/*
    This gets called on cron
    */
    
function cron() {
        
$highlight $this -> highlight;
$acolor $this -> alert_color;
        
$this -> time();
        if(
floor($this -> timeleft) <= 3600 && floor($this -> timeleft) >= 3599) {
            
$this -> bot -> send_pgroup("<font color=$acolor>Alien playfield gates opening in$highlight 1</font> hour!");
            
$this -> bot -> send_gc("<font color=$acolor>Alien playfield gates opening in$highlight 1</font> hour!");
        }
else if( $secleft <= 7200 && $secleft >= 7199 ) {
            
$this -> bot -> send_pgroup("<font color=$acolor>Alien playfield gates opening in$highlight 2</font> hours!");
            
$this -> bot -> send_gc("<font color=$acolor>Alien playfield gates opening in$highlight 2</font> hours!");
}
        else if(
floor($this -> timeleft) <= 1800 && floor($this -> timeleft) >= 1799) {
            
$this -> bot -> send_pgroup("<font color=$acolor>Alien playfield gates opening in$highlight 30</font> minutes!");
            
$this -> bot -> send_gc("<font color=$acolor>Alien playfield gates opening in$highlight 30</font> minutes!");
        }
        else if(
floor($this -> timeleft) <= 900 && floor($this -> timeleft) >= 899) {
            
$this -> bot -> send_pgroup("<font color=$acolor>Alien playfield gates opening in$highlight 15</font> minutes!");
            
$this -> bot -> send_gc("<font color=$acolor>Alien playfield gates opening in$highlight 15</font> minutes!");
        }
        else if(
floor($this -> timeleft) <= 300 && floor($this -> timeleft) >= 299) {
            
$this -> bot -> send_pgroup("<font color=$acolor>Alien playfield gates opening in$highlight 5</font> minutes!");
            
$this -> bot -> send_gc("<font color=$acolor>Alien playfield gates opening in$highlight 5</font> minutes!");
        }
        else if(
$this -> timeleft <= 1) {
            
$this -> bot -> send_pgroup("<font color=$acolor>Unicorn Gatekeeper is opening Outzone gates$highlight now</font>!");
            
$this -> bot -> send_gc("<font color=$acolor>Unicorn Gatekeeper is opening Outzone gates$highlight now</font>!");
        }

// updates cache at midnight
$time date("G:i:s"gmmktime());
if ($time == "0:00:00" || $time == "0:00:01")
$this -> update_cache();
    }

    
/*
    Record Time Stamp to Settings Table
    */
    
function set_timer($name$msg) {
    
if ($this -> bot -> admin -> in_group($name"admin"))
    
{
        
$TimeStamp $this -> update_cache();
$this -> bot -> send_tell($name"Time Stamp is set to $TimeStamp");
    
}
    
else $this -> bot -> send_tell($name"You must be an admin to do this");
    }
    
    
/*
    Updates database cache
    */
function update_cache()
{
    
$TimeStamp $this -> bot -> get_site("http://zibby.isa-geek.net/apf.timestamp");
    
$TimeStamp trim($TimeStamp);

    
// Parse the APF Time Stamp from the Site above
    
$datetime explode(" "$TimeStamp);
    
$timetype strtoupper($datetime[0]);
    
$date explode("-"$datetime[1]);
    
$time explode(":"$datetime[2]);
    

    
// Uptime is needed to provide a timestamp without the [type] information in the timestamp file.
    
$settime gmmktime $time[0], $time[1], $time[2], $date[1], $date[2], $date[0] );
    
         
        
$this -> bot -> db -> query("UPDATE settings SET value = '".$settime."' WHERE setting = 'apf_timer'");
$this -> get_timer();
return $TimeStamp;
}


    
/*
    Retrieve Time Stamp from Settings Table
    */
    
function get_timer() {
    
$result $this -> bot -> db -> select("SELECT * FROM settings WHERE setting = 'apf_timer'");
        
$this -> stamp $result[0][1];
    }

    function 
time() {
        
$highlight $this -> highlight;
        
$time $this -> stamp;
        
$int 7*60*60+12*60+2.7;
        
$raids floor((mktime()-$time)/$int);
        
$this -> timeleft = ($time+$int+$int*$raids)-mktime();
        if(
$this -> timeleft >= 7*60*60 && $this -> timeleft <= 7*60*60+12*60+2.7) {
            
$timer floor($this -> timeleft -(7*60*60));
            } else {
            
$timer ceil($this -> timeleft);
        }
        
$h 0;
        while(
$timer >= 3600) {
            
$h++;
            
$timer-=3600;
        }
        
$m 0;
        while(
$timer >= 60) {
            
$m++;
            
$timer-=60;
        }
        
$s $timer;
        if(
$h == 0) {
            
$h '00';
        }
        if(
$m 10) {
            
$m '0' $m;
        }
        if(
$s 10) {
            
$s '0' $s;
        }
        if(
$this -> timeleft >= 7*60*60 && $this -> timeleft <= 7*60*60+12*60+2.7) {
            
$this -> msg "Outzone Gates are open, you have$highlight $m:$s </font>until gates close!";
            } else {
            
$this -> msg $highlight "$h:$m:$s </font>remaining until Alien Playfield opens.";
        }
    }
}
?>
Title: Re: Alien Playfield Module - Keep track of alien PF
Post by: Aiiane on December 19, 2005, 11:01:23 pm
hmm... wtb maximum vertical screen size for CODE blocks :) maybe make them scroll or such.
Title: Re: Alien Playfield Module - Keep track of alien PF
Post by: Khalem on December 20, 2005, 09:59:11 am
hmm... wtb maximum vertical screen size for CODE blocks :) maybe make them scroll or such.

See http://bebot.link/index.php/topic,276.0.html and vote :)
Title: Re: Alien Playfield Module - Keep track of alien PF
Post by: Glarawyn on December 20, 2005, 04:36:11 pm
im using debian linux... not sure about the timezone set in the box, gonna mess with that later. I always try to match the time with campalot, using /campalot !apf, maybe Glara's bot isnt always synchronized with her timestamp.

Campalot should be in sync with my site most of the time. Campalot used to be running my VashBotPHP module, which grabbed the apf.timestamp file from my website every time someone did !apf. Currenty Campalot runs the current development version of my BeBot module. (Not the 0.9.5 module that I've released.) When I do make code updates I make sure it's in sync with my control bots (2 guildbots) and website. Campalot does cache the info for 4 hours before automatically updating from the site, but when I change the site I force the bot to recache the info.

I'm usually at work when FunCom resets the servers, so it usually takes awhile before my timer is in sync with the servers again. :)
Title: Re: Alien Playfield Module - Keep track of alien PF
Post by: craized on December 26, 2005, 04:20:20 am
I didn't have much to do, and I deleted the bots I've been working on on accident and I'm not quite ready to go back and try to redo all my work, so I thought I would optimize this a little. The source I modified is from Wanuarmi's most recent post. I haven't gotten to test this either, so no gaurantees... So basically didn't do anything necessary.


<?php
/*
* Playfield Module for BE Bot <http://bebot.fieses.net>
* Module coded by Craized <http://www.craized.net>
* Originally modified by Derroylo
*
* Modified to use Time Stamp From Glarawyn's site by Xenixa (RK1)
* Now uses settings table
*/

/*
Add a '_' at the beginning of the file (_Playfield.php) if you do not want it to be loaded.
*/

// Commented Line below is intedended to set an initial value and was used for testing.
//$db -> query('REPLACE INTO settings (setting, value) VALUES ('apf_timer', '1130355492')');


$playfield = new Playfield($bot);

$commands['tell']['apf'] = &$playfield;
$commands['tell']['setpf'] = &$playfield;
$commands['pgmsg']['apf'] = &$playfield;
$commands['gc']['apf'] = &$playfield;
$cron['2sec'][] = &$playfield;

/*
The Class itself...
*/
class Playfield {
var $bot;
var $alert_color;

/*
Constructor:
Hands over a referance to the 'Bot' class.
*/
function Playfield (&$bot) {
$this -> bot = &$bot;
$this -> highlight = isset($this -> bot -> highlight_color) ? '<font color='.$this -> bot -> highlight_color.'>' : '<font color=#FFFFFF>';
$this -> alert_color = '#00F700';
$this -> get_timer();
}

/*
This gets called on a tell with the command
*/
function tell($name, $msg) {
if (preg_match('/^'.$this -> bot -> commpre.'apf$/i', $msg)) $c = $this -> time();
elseif (preg_match('/^'.$this -> bot -> commpre.'setpf$/i', $msg)) $c = $this -> set_timer($name, $msg);
$this -> bot -> send_tell($name, $c);
}

/*
This gets called on a msg in the privgroup with the command
*/
function pgmsg($name, $msg) {
if (preg_match('/^'.$this -> bot -> commpre.'apf$/i', $msg)) $c = $this -> time();
$this -> bot -> send_pgroup($c);
}

/*
This gets called on a msg in the guildchat with the command
*/
function gc($name, $msg) {
if (preg_match('/^'.$this -> bot -> commpre.'apf$/i', $msg)) $c = $this -> time();
$this -> bot -> send_gc($c);
$this -> bot -> log('GROUP', 'SEND', $c);
}

/*
This gets called on cron
*/
function cron() {
$this -> time();
if(floor($this -> timeleft) <= 3600 && floor($this -> timeleft) >= 3599) {
$this -> bot -> send_pgroup('<font color='.$this -> acolor.'>Alien playfield gates opening in '.$this -> highlight.'1</font> hour!');
$this -> bot -> send_gc('<font color='.$this -> acolor.'>Alien playfield gates opening in '.$this -> highlight.'1</font> hour!');
}
else if( $secleft <= 7200 && $secleft >= 7199 ) {
$this -> bot -> send_pgroup('<font color='.$this -> acolor.'>Alien playfield gates opening in '.$this -> highlight.'2</font> hours!');
$this -> bot -> send_gc('<font color='.$this -> acolor.'>Alien playfield gates opening in '.$this -> highlight.'2</font> hours!');
}
else if(floor($this -> timeleft) <= 1800 && floor($this -> timeleft) >= 1799) {
$this -> bot -> send_pgroup('<font color='.$this -> acolor.'>Alien playfield gates opening in '.$this -> highlight.'30</font> minutes!');
$this -> bot -> send_gc('<font color='.$this -> acolor.'>Alien playfield gates opening in '.$this -> highlight.'30</font> minutes!');
}
else if(floor($this -> timeleft) <= 900 && floor($this -> timeleft) >= 899) {
$this -> bot -> send_pgroup('<font color='.$this -> acolor.'>Alien playfield gates opening in '.$this -> highlight.'15</font> minutes!');
$this -> bot -> send_gc('<font color='.$this -> acolor.'>Alien playfield gates opening in '.$this -> highlight.'15</font> minutes!');
}
else if(floor($this -> timeleft) <= 300 && floor($this -> timeleft) >= 299) {
$this -> bot -> send_pgroup('<font color='.$this -> acolor.'>Alien playfield gates opening in '.$this -> highlight.'5</font> minutes!');
$this -> bot -> send_gc('<font color='.$this -> acolor.'>Alien playfield gates opening in '.$this -> highlight.'5</font> minutes!');
}
else if($this -> timeleft <= 1) {
$this -> bot -> send_pgroup('<font color='.$this -> acolor.'>Unicorn Gatekeeper is opening Outzone gates '.$this -> highlight.'now</font>!');
$this -> bot -> send_gc('<font color='.$this -> acolor.'>Unicorn Gatekeeper is opening Outzone gates '.$this -> highlight.'now</font>!');
}

// updates cache at midnight
$time = date('G:i:s', gmmktime());
if ($time == '0:00:00' || $time == '0:00:01')
$this -> update_cache();
}

/*
Record Time Stamp to Settings Table
*/
function set_timer($name, $msg) {
if ($this -> bot -> admin -> in_group($name, 'admin')) {
$TimeStamp = $this -> update_cache();
$c = 'Time Stamp is set to '.$TimeStamp;
}
else $c = 'You must be an admin to do this';
return $c;
}

/*
Updates database cache
*/
function update_cache()
{
$TimeStamp = $this -> bot -> get_site('http://zibby.isa-geek.net/apf.timestamp');
$TimeStamp = trim($TimeStamp);

// Parse the APF Time Stamp from the Site above
$datetime = explode(' ', $TimeStamp);
$timetype = strtoupper($datetime['0']);
$date = explode('-', $datetime['1']);
$time = explode(':', $datetime['2']);

// Uptime is needed to provide a timestamp without the [type] information in the timestamp file.
$settime = gmmktime ( $time['0'], $time['1'], $time['2'], $date['1'], $date['2'], $date['0'] );

$this -> bot -> db -> query('UPDATE settings SET value = "'.$settime.'" WHERE setting = "apf_timer"');
$this -> get_timer();
return $TimeStamp;
}


/*
Retrieve Time Stamp from Settings Table
*/
function get_timer() {
$result = $this -> bot -> db -> select('SELECT * FROM settings WHERE setting = "apf_timer"');
$this -> stamp = $result['0']['1'];
}

function time() {
$time = $this -> stamp;
$int = 7*60*60+12*60+2.7;
$raids = floor((mktime()-$time)/$int);
$this -> timeleft = ($time+$int+$int*$raids)-mktime();
if($this -> timeleft >= 7*60*60 && $this -> timeleft <= 7*60*60+12*60+2.7) $timer = floor($this -> timeleft -(7*60*60));
else $timer = ceil($this -> timeleft);
$h = 0;
while($timer >= 3600) {
$h++;
$timer-=3600;
}
$m = 0;
while($timer >= 60) {
$m++;
$timer-=60;
}
$s = $timer;
if($h == 0) $h = '00';
if($m < 10) $m = '0' . $m;
if($s < 10) $s = '0' . $s;
if($this -> timeleft >= 7*60*60 && $this -> timeleft <= 7*60*60+12*60+2.7) {
$c = 'Outzone Gates are open, you have '.$this -> highlight.$m.':'.$s.' </font>until gates close!';
} else $c = $this -> highlight.$h.':'.$m.':'.$s.'</font> remaining until Alien Playfield opens.';
return $c;
}
}
?>
Title: Re: Alien Playfield Module - Keep track of alien PF
Post by: Khalem on December 26, 2005, 03:04:38 pm
Recommend adding a random delay on the midnight updating just so that one doesn't end up with multiple bots hammering the server at the exact same time.
Title: Re: Alien Playfield Module - Keep track of alien PF
Post by: craized on December 26, 2005, 09:52:25 pm
I can add that in, but the way I'm thinking of seems kind of sloppy. If anyone else wants to do this, please do. If no one decides to, I'll get to it.
SimplePortal 2.3.7 © 2008-2024, SimplePortal