collapse collapse
* User Info
 
 
Welcome, Guest. Please login or register.
* Search

* Board Stats
  • stats Total Members: 989
  • stats Total Posts: 18365
  • stats Total Topics: 2500
  • stats Total Categories: 7
  • stats Total Boards: 35
  • stats Most Online: 1144

Author Topic: Planning DD module  (Read 9049 times)

0 Members and 1 Guest are viewing this topic.

Offline axl

  • BeBot Rookie
  • *
  • Posts: 11
  • Karma: +0/-0
Planning DD module
« 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.
« Last Edit: February 10, 2006, 05:29:24 pm by axl »

Offline Khalem

  • BeBot Founder
  • Administrator
  • ********
  • Posts: 1169
  • Karma: +0/-0
    • http://www.ancarim.com
Re: Planning DD module
« Reply #1 on: February 02, 2006, 01:05:20 am »
Interesting concept.

Im sure someone is gonna love this :)
BeBot Founder and Fixer Kingpin

Offline axl

  • BeBot Rookie
  • *
  • Posts: 11
  • Karma: +0/-0
Re: Planning DD module
« Reply #2 on: February 02, 2006, 01:16:19 am »
I wonder we think about the same nazi^D^D^D^D admin ;)
« Last Edit: February 02, 2006, 01:20:20 am by axl »

Offline axl

  • BeBot Rookie
  • *
  • Posts: 11
  • Karma: +0/-0
Re: Planning DD module
« Reply #3 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.

Offline Glarawyn

  • BeBot Hero
  • ******
  • Posts: 521
  • Karma: +0/-0
Re: Planning DD module
« Reply #4 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

Offline axl

  • BeBot Rookie
  • *
  • Posts: 11
  • Karma: +0/-0
Re: Planning DD module
« Reply #5 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.

Offline axl

  • BeBot Rookie
  • *
  • Posts: 11
  • Karma: +0/-0
Re: Planning DD module
« Reply #6 on: February 10, 2006, 05:26:30 pm »
any success stories?

Offline captainwinky

  • BeBot User
  • **
  • Posts: 32
  • Karma: +0/-0
Re: Planning DD module
« Reply #7 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

Offline Xenixa

  • Contributor
  • *******
  • Posts: 307
  • Karma: +0/-0
Re: Planning DD module
« Reply #8 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. :)
<<< Hack's in Zend Studio

All my Custom Bebot files may be Found Here <-clicky

Offline axl

  • BeBot Rookie
  • *
  • Posts: 11
  • Karma: +0/-0
Re: Planning DD module
« Reply #9 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 :)

Offline captainwinky

  • BeBot User
  • **
  • Posts: 32
  • Karma: +0/-0
Re: Planning DD module
« Reply #10 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.

Offline captainwinky

  • BeBot User
  • **
  • Posts: 32
  • Karma: +0/-0
Re: Planning DD module
« Reply #11 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)
« Last Edit: May 14, 2006, 09:18:49 am by captainwinky »

Offline axl

  • BeBot Rookie
  • *
  • Posts: 11
  • Karma: +0/-0
Re: Planning DD module
« Reply #12 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.

Offline captainwinky

  • BeBot User
  • **
  • Posts: 32
  • Karma: +0/-0
Re: Planning DD module
« Reply #13 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 :)
« Last Edit: May 15, 2006, 03:21:15 pm by captainwinky »

Offline axl

  • BeBot Rookie
  • *
  • Posts: 11
  • Karma: +0/-0
Re: Planning DD module
« Reply #14 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.

 

* Recent Posts
0.8.x updates for AO by bitnykk
[June 23, 2024, 03:19:47 pm ]


0.8.x updates for AoC by bitnykk
[June 23, 2024, 03:19:44 pm ]


[AoC] special char for items module by bitnykk
[February 09, 2024, 09:41:18 pm ]


BeBot still alive & kicking ! by bitnykk
[December 17, 2023, 12:58:44 am ]


Bebot and Rasberry by bitnykk
[November 29, 2023, 11:04:14 pm ]

* Who's Online
  • Dot Guests: 160
  • Dot Hidden: 0
  • Dot Users: 0

There aren't any users online.
* Forum Staff
bitnykk admin bitnykk
Administrator
Khalem admin Khalem
Administrator
WeZoN gmod WeZoN
Global Moderator
SimplePortal 2.3.7 © 2008-2024, SimplePortal