BeBot - An Anarchy Online and Age Of Conan chat automaton

Archive => Anarchy Online Archive => 0.2.x Custom/Unofficial Modules => Topic started by: axl on February 02, 2006, 01:00:20 am

Title: Planning DD module
Post by: axl on February 02, 2006, 01:00:20 am
OK, this thread (http://bebot.link/index.php/topic,297.0.html) gave me an idea. it's relatively easy to combine client side/server side for a bot DD report.
The idea behind the project is to have a relatively accurate damage report in bot commands.

How to do it

In client side we create a new damage report window (invisible or not it doesn't matter), which reports:
- damage from me to others (both normal and nano)
- damage from others on me (both normal and nano)
- damage from others on others (both normal and nano).
We enable logging on that window. That takes care of logging of what happens in the game. 2 notes here:
1. Damage is recorded ofc only if players are close to the guy recording the damage.
2. Pets are not taken into consideration unless they have the name of owner. (will explain later why). *

From this point on we must move log from client side to server side where it can be analysed and parsed and where reports can be created. For that task we can simply stream it or better insert it in an sql table for the bot to easier extract it. I prefer the second method, and so I only developed that one. However the other method is doable too. (but I ain't gonna do it). So I made a tiny application which reads the log and inserts the relevant rows in an sql table. I choose php because with all the bots and stuff ppl should have gotten used to php allready, because it's source based and so keylogger drama can be avoided, and because ppl can customise/improove it as they wish too.

Code: [Select]
<?php

$logfile 
"C:\Program Files\Funcom\Anarchy Online\Prefs\{account_name}\Char{char_ID}\Chat\Windows\{window_name}\Log.txt";

$charname "{your_char_name}";

$dbhost "{sql_hostname}";
$dbbase "{sql_database}";
$dbuser "{sql_username}";
$dbpass "{sql_password}";

////////// DO NOT MESS ARROUND BEYOND THIS POINT

$sql mysql_connect($dbhost$dbuser$dbpass);
mysql_select_db($dbbase);

$log fopen($logfile"r");
$fstat fstat($log);
fclose($log);
$cs $fstat['size'];

while(
true)
{
$log fopen($logfile"r");
$fstat fstat($log);
fseek($log$cs);
while (!feof($log))
{
$buffer fgets($log4096);
$buffer str_replace("\"You hit other\"""\"Other hit by other\""$buffer);
$buffer str_replace("You hit other with nano""Other hit by nano"$buffer);
$buffer str_replace("Me hit by monster""Other hit by other"$buffer);
$buffer str_replace("Me hit by player""Other hit by other"$buffer);
$buffer str_replace("Me hit by nano""Other hit by nano"$buffer);
$buffer str_replace("were attacked""was attacked"$buffer);
$buffer str_replace("Your damage shield"$charname "'s damage shield"$buffer);
$buffer str_replace("Your reflect shield"$charname "'s damage shield"$buffer);
$buffer str_replace("You"$charname$buffer);
$buffer str_replace("you"$charname$buffer);
if ((substr_count($buffer'"Other hit by other"') == 1) or
    (substr_count($buffer'"Other hit by nano"') == 1))
{
$parts explode("]"$buffer);
$plen strlen($parts[0]);
$buffer substr($buffer$plen+1);
$insert mysql_query("INSERT INTO damage_dumper (id, time, line) VALUES ('', " date("U") . ", '" $buffer "')");
}
}
fclose($log);
$cs $fstat['size'];
sleep(1);
}

?>


As you can see code is very easy to understand or modify. From this point on, I will start working on the module to parse the table and do the reports.

* Pets have to have the name of owners because I don't want to keep track of who is naming his pet how + we might encounter multiple pets named with the default name. In order to avoid all this problems, only player names (present in raid, taken from raid list) will be taken into consideration. So if a player wants his pet to be taken into consideration he can rename his pet with his name. This way the pet's damage will be treated as the player damage.

This is in a nutshell what I am trying to accomplish. It's not very leet and it will be easy to implement as long as the person holding the log "streamer" is trustworthy to make inserts in sql. In any event if I am not in the mood tomorrow to finish, this might help as a guide line on how to do it :D
Any kind of feedback is welcome.
Title: Re: Planning DD module
Post by: Khalem on February 02, 2006, 01:05:20 am
Interesting concept.

Im sure someone is gonna love this :)
Title: Re: Planning DD module
Post by: axl on February 02, 2006, 01:16:19 am
I wonder we think about the same nazi^D^D^D^D admin ;)
Title: Re: Planning DD module
Post by: axl on February 02, 2006, 02:00:13 pm
It is gimpish, and ugly, but it works. It's not meant to be complete, nice, well sorted, well put, well colored (in other words userfriendly). It is just meant to be sort of a proof of concept, proof that it can be done. From this point on project just needs to be beautified (sort of speak). This is a diff file between original RaidTime.php (current stable branch) and modified RaidTime.php. So here it is.

Code: [Select]
--- RaidTime.php        2005-12-21 20:29:20.000000000 +0200
+++ ../modules/RaidTime.php     2006-02-02 14:43:15.998797250 +0200
@@ -12,7 +12,11 @@
 * Revision: $Id: RaidTime.php 37 2005-12-13 00:34:04Z shadowmaster $
 */
 
-
+/* Also modified by [email protected]:
+*      - raid lock/unlock actually work
+*      - raid pause/unpause implemented (not that is a big thing :P)
+*      - hopefully to finish implementing DD system
+*/
 
 $raid = new Raid($bot);
 
@@ -22,7 +26,6 @@
 $commands["pgleave"][] = &$raid;
 $commands["connect"][] = &$raid;
 
-
 /*
 The Class itself...
 */
@@ -34,7 +37,7 @@
        var $announce;
        var $start;
        var $locked;
-
+       var $paused;
 
 
        /*
@@ -48,6 +51,10 @@
                $this -> user = array();
                $this -> announce = 0;
                $this -> locked = false;
+               $this -> paused = false;
+
+               $this -> last_dd_input = 0;
+               $this -> dd_array = array();
        }
 
 
@@ -69,6 +76,8 @@
                $this -> kick_raid($name, $info[1]);
                else if (preg_match("/^" . $this -> bot -> commpre . "raid (lock|unlock)$/i", $msg, $info))
                $this -> lock_raid($name, $info[1]);
+               else if (preg_match("/^" . $this -> bot -> commpre . "raid (pause|unpause)$/i", $msg, $info))
+               $this -> pause_raid($name, $info[1]);
                else if (preg_match("/^" . $this -> bot -> commpre . "raid check$/i", $msg))
                $this -> check_raid($name);
        }
@@ -94,6 +103,8 @@
                $this -> check_raid($name);
                else if (preg_match("/^" . $this -> bot -> commpre . "raid (lock|unlock)$/i", $msg, $info))
                $this -> lock_raid($name, $info[1]);
+               else if (preg_match("/^" . $this -> bot -> commpre . "raid (pause|unpause)$/i", $msg, $info))
+               $this -> pause_raid($name, $info[1]);
        }
 
 
@@ -128,15 +139,19 @@
        */
        function cron()
        {
-               $this -> bot -> db -> query("Update raid_points SET points = points + 1 WHERE raiding = 1");
-
+               if ($this -> paused == false)
+               {
+                       $this -> bot -> db -> query("Update raid_points SET points = points + 1 WHERE raiding = 1");
+               }
                $this -> announce += 1;
                if ($this -> announce == 10)
                {
                        $this -> bot -> send_pgroup("Raid is running for <font color=#ffff00>" .
                        (((int)((time () - $this -> start) / 60)) + 1) . "</font> minutes now.");
+                       $this ->report_dd();
                        $this -> announce = 0;
                }
+               $this->parse_damage();
        }
 
 
@@ -154,6 +169,8 @@
                                $this -> bot -> cron["1min"]["raid"] = &$this -> bot -> commands["tell"]["raid"];
                                $this -> start = time();
                                $this -> bot -> send_pgroup("<font color=#ffff00>$name</font> has started the raid :: " . $this -> clickjoin());
+                               $this -> pause_raid($name, "pause");
+                               $this -> create_dd_table();
                        }
                        else
                        $this -> bot -> send_tell($name, "Raid already running.");
@@ -199,15 +216,20 @@
                $this -> bot -> send_tell($name, "You are already in the raid", 1);
                else if ($this -> raid)
                {
-                       $id = $this -> bot -> aoc -> get_uid($name);
+                       if ( $this -> locked == false )
+                       {
+                               $id = $this -> bot -> aoc -> get_uid($name);
 
-                       $result = $this -> bot -> db -> select ("SELECT id FROM raid_points WHERE id = " . $this -> points_to($name));
-                       if (empty($result))
-                       $this -> bot -> db -> query("INSERT INTO raid_points (id, points, raiding) VALUES (" . $this -> points_to($name) . ", 0, 0)");
-
-                       $this -> user[$name] = $this -> bot -> aoc -> get_uid($name);
-                       $this -> bot -> send_pgroup("<font color=#ffff00>$name</font> has <font color=#ffff00>joined</font> the raid :: " . $this -> clickjoin());
-                       $this -> bot -> db -> query("UPDATE raid_points SET raiding = 1 WHERE id = " . $this -> points_to($name));
+                               $result = $this -> bot -> db -> select ("SELECT id FROM raid_points WHERE id = " . $this -> points_to($name));
+                               if (empty($result))
+                               $this -> bot -> db -> query("INSERT INTO raid_points (id, points, raiding) VALUES (" . $this -> points_to($name) . ", 0, 0)");
+
+                               $this -> user[$name] = $this -> bot -> aoc -> get_uid($name);
+                               $this -> bot -> send_pgroup("<font color=#ffff00>$name</font> has <font color=#ffff00>joined</font> the raid :: " . $this -> clickjoin());
+                               $this -> bot -> db -> query("UPDATE raid_points SET raiding = 1 WHERE id = " . $this -> points_to($name));
+                       } else {
+                               $this -> bot -> send_tell($name, "Raid is locked!", 1);
+                       }
                }
                else
                $this -> bot -> send_tell($name, "No raid in progress");
@@ -221,7 +243,7 @@
        function leave_raid($name)
        {
                if (!isset($this -> user[$name]))
-               $this -> bot -> send_tell($name, "You are not in the raid.", 1);
+                       $this -> bot -> send_tell($name, "You are not in the raid.", 1);
                else
                {
                        unset($this -> user[$name]);
@@ -306,6 +328,30 @@
        }
 
 
+       /*
+       Pauses/unPauses a Raid
+       */
+       function pause_raid($name, $lock)
+       {
+               
+               if ($this -> bot -> admin -> in_group($name, "raidleader"))
+               {
+                       if (strtolower($lock) == "pause")
+                       {
+                               $this -> paused = true;
+                               $this -> bot -> send_pgroup("<font color=#ffff00>$name</font> has <font color=#ffff00>paused</font> the raid.");
+                       }
+                       else
+                       {
+                               $this -> paused = false;
+                               $this -> bot -> send_pgroup("<font color=#ffff00>$name</font> has <font color=#ffff00>unpaused</font> the raid.");
+                       }
+               }
+               else
+               $this -> bot -> send_tell($name, "You must be a raidleader to do this");
+       }
+
+
 
        /*
        Make click to join blob
@@ -328,5 +374,66 @@
        {
                return $this -> bot -> commands["tell"]["points"] -> points_to($name);
        }
+
+       function create_dd_table()
+       {
+               $querystr = "DROP TABLE IF EXISTS damage_dumper; " .
+                        "CREATE TABLE IF NOT EXISTS damage_dumper (" .
+                        "id int(24) NOT NULL auto_increment," .
+                        "`time` int(11) NOT NULL," .
+                        "line varchar(255) NOT NULL," .
+                        "PRIMARY KEY  (id))";
+               $query = $this -> bot -> db -> query("DROP TABLE IF EXISTS damage_dumper;");
+               $query = $this -> bot -> db -> query("CREATE TABLE IF NOT EXISTS damage_dumper (id int(24) NOT NULL auto_increment,`time` int(11) NOT NULL,line varchar(255) NOT NULL,PRIMARY KEY  (id))");
+       }
+
+       function report_dd()
+       {
+               $window = "<font color=CCInfoHeadline>:::: Join/Leave Raid ::::</font>\n\n";
+               $participants = explode(",", $this -> dd_array['participants']);
+               foreach($participants as $member)
+               {
+                       if(isset($this-> user[$member]))
+                               $window .= $member . " - " . $this -> dd_array[$member] . " points of damage\n";
+               }
+               $this -> bot -> send_pgroup($this -> bot -> make_blob("Click here", $window) . " to see DD report");
+       }
+       
+       function parse_damage()
+       {
+               $query = "SELECT id, time, line FROM damage_dumper WHERE id > " . $this->last_dd_input . " ORDER by id";
+               $result = $this -> bot -> db -> select($query);
+               foreach ($result as $row)
+               {
+                       $this -> last_dd_input = $row[0];
+                       $need_update=0;
+                       if ((substr_count($row[2], " hit ") == 1) and (substr_count($row[2], " with nanobots ") == 1))
+                       {
+                               list($damager, $damaged, $nr, $type) = sscanf($row[2], "%s hit %s with nanobots for %d points of %s damage.");
+                               $need_update=1;
+                       }
+                       elseif (substr_count($row[2], " hit ") == 1)
+                       {
+                               list($damager, $damaged, $nr, $type, $crit) = sscanf($row[2], "%s hit %s for %d points of %s damage.%s");
+                               $need_update=1;
+                       }
+                       elseif (substr_count($row[2], " was attacked ") ==1)
+                       {
+                               list($damager, $damaged, $nr, $type) = sscanf($row[2], "%s was attacked with nanobots from %s for %d points of %s damage.");
+                               $need_update=1;
+                       }
+                       if($need_update=1)
+                       {
+                               if(isset($this -> user[$damager]))
+                               {
+                                       $this -> dd_array[$damager] = $this -> dd_array[$damager] + $nr;
+                                       if(substr_count($this -> dd_array['participants'], "," . $damager) == 0)
+                                       {
+                                               $this -> dd_array['participants'] = $this -> dd_array['participants'] . "," . $damager;
+                                       }
+                               }
+                       }
+               }
+       }
 }
 ?>

For now it only takes into consideration damage made by me vs others (nano and normal), other on other (nano and normal). It doesn't take into consideration Damage Shields, Reflect Shields. It's doesn't do anything else but adding of damage as long as dealer is a raider. Once every 10 minutes when the tiny note "raid has been going for x minutes", prints out a blob with damage/participant in order of who did the first damage.

Again it's not a big deal to improove from this point on. However I think from this point forward everyone should create their own varioations of the project. I will post mine if I do any more improovments.

Again all types of feedback are welcomed.
Title: Re: Planning DD module
Post by: Glarawyn on February 03, 2006, 01:26:37 am
Glad my "I'm freaking bored I need a project for the night" code inspired someone.  ;D
Title: Re: Planning DD module
Post by: axl on February 03, 2006, 01:31:42 am
Yeah well, I was bored too :D
Besides I didn't had enough time to do a good enough job.
Title: Re: Planning DD module
Post by: axl on February 10, 2006, 05:26:30 pm
any success stories?
Title: Re: Planning DD module
Post by: captainwinky on May 13, 2006, 12:10:15 pm
WTB some form of DD that works in Linux.  if this does work in BeBot independently of OS, i'd love to know how :)
i'd write something myself if i could program my way out of a "hello world"... hehe
Title: Re: Planning DD module
Post by: Xenixa on May 13, 2006, 01:58:58 pm
This would work independent of OS with Bebot.
Since you define which DB to send it to, you direct your local chat log to dump into the remote mysql server's DD log table. More than likely the same database that the bot uses. :)
Title: Re: Planning DD module
Post by: axl on May 13, 2006, 02:59:19 pm
lol forgot about this post. didn't think anyway was interested. :)
anyway meanwhile i adapted the code and turned it into a stand alone bot. but that's far from bebot, because it's written from scratch. can be adapted for bebot thou. those who are clan on rk1 and do pande often know the project as "natzibot".
if more proved interested i will put things together and turn it into smth useful :)
Title: Re: Planning DD module
Post by: captainwinky on May 13, 2006, 03:18:19 pm
well, i'm very interested.  i don't know if one person counts for much coding time though :)
i tried to run it in BeBot and got errors.  however, my MySql knowledge extends about as far as setting BeBot up initially, hehe.
i'm not opposed to receiving any kind of instruction ;). 
running stable 0.2.2 atm.  but open to suggestions.
Title: Re: Planning DD module
Post by: captainwinky on May 14, 2006, 09:17:14 am
all i did was replace the path-to-logfile with the appropriate path for my linux setup.

apon attempting to run BeBot with the Damage.php module in place i got these errors:

PHP Warning:  PHP Startup: Unable to load dynamic library './php_bz2.so' - ./php_bz2.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library './mysql.so' - ./mysql.so: cannot open shared object file: No such file or directory in Unknown on line 0
PHP Warning:  PHP Startup: Unable to load dynamic library './php_sockets.so' - ./php_sockets.so: cannot open shared object file: No such file or directory in Unknown on line 0

i have no idea how to diagnose this myself :)
-cw

(well not technically errors, but warnings which i assume would render the module inoperable)
Title: Re: Planning DD module
Post by: axl on May 15, 2006, 12:14:59 pm
well, you dont run bebot with damage.php. damage.php is a script which takes your logs and puts them into your mysql server, provided ofc 3 things are ok:

- logs are appending (there are logs to insert)
- php works
- mysql works

that seems to be a php related issue, to which i can only tell you to download a php distribution from www.php.net for your system.
Title: Re: Planning DD module
Post by: captainwinky on May 15, 2006, 02:51:22 pm
well, no denying i'm a real php noob :) but i did try to run it by itself at one point.  it just seemed to print the file to screen.

i have logs enabled, and php and mysql are working - currently running 4x BeBot :)

will try again soon and see if i can get more information on what problems i'm encountering.

edit:
yeah, upon trying to run it i get:
$ php Damage.php
?php

$logfile = "/home/*cough*/Anarchy/Prefs/*cough*/*cough*/Chat/Windows/Window1/Log.txt";

$charname = "*cough*";

$dbhost = "127.0.0.1";
$dbbase = "damage";
$dbuser = "*cough*";
$dbpass = "*cough*";

////////// DO NOT MESS ARROUND BEYOND THIS POINT

$sql = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbbase);
etc...
does seem to just print out text of file to screen. 
not sure what i'm doing wrong here :)
Title: Re: Planning DD module
Post by: axl on May 15, 2006, 03:37:01 pm
well, that is the point. to run it by itself and to show "the log" on the screen.
again. contains 2 parts. 1 which will enable transfer of logs from client to a mysql server, and second, raid plugin which will read those logs and interpret them.
your part 1 here stands alone. has nothing to do with bebot whatsoever. only reads logs, prints then in console, and inserts them in sql. 1 file. 1 job. period.
your part 2 consists in the modified raid_time.php which will read those logs and try to interpret them.
Title: Re: Planning DD module
Post by: captainwinky on May 18, 2006, 04:39:17 pm
i had a little look at the mysql database that i have assigned to this.  there were no changes made to the DB by the script.
is there perhaps something i need to do in the mysql manually in order to make the script able to work?
(from what i can see, the raid_time.php module would have nothing to read with my current setup).
thanks for your answers so far :)
Title: Re: Planning DD module
Post by: axl on May 18, 2006, 05:17:12 pm
well, creating the table where data should be entered would be a good start :)
and your raid_time.php doesn't have anything changed to it because it hasn't been patched with the patch attached by me here in my 3rd(?) post.
Title: Re: Planning DD module
Post by: captainwinky on May 20, 2006, 03:40:59 pm
taking a close look at your first post, i get the impression that i would call the table within the database "damage_dumper".
would that be correct? :)
SimplePortal 2.3.7 © 2008-2024, SimplePortal