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

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

Author Topic: Tower Messages to IRC  (Read 3180 times)

0 Members and 1 Guest are viewing this topic.

Offline Dabaron

  • BeBot Apprentice
  • ***
  • Posts: 163
  • Karma: +0/-0
Tower Messages to IRC
« on: December 06, 2007, 05:24:26 am »
With the old TowerAttack module I had messages relaying to IRC (with some color to just catch my attention) but I can't figure out how the heck to do it in the new version.  Its entirely possible I just did it in the wrong place.  Let me know if I did it right (because it's entirely possible I screwed it up, I was half asleep when I added that part in).

Code: [Select]
<?php
/*
* TowerAttack.php - Handle Tower attack events.
*
* BeBot - An Anarchy Online Chat Automaton
* Copyright (C) 2004 Jonas Jax
* Copyright (C) 2005-2007 Thomas Juberg StensÃ¥s, ShadowRealm Creations and the BeBot development team.
*
* Developed by:
* - Alreadythere (RK2)
* - Blondengy (RK1)
* - Blueeagl3 (RK1)
* - Glarawyn (RK1)
* - Khalem (RK1)
* - Naturalistic (RK1)
*
* See Credits file for all aknowledgements.
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; version 2 of the License only.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software
*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
*  USA
*
* File last changed at $LastChangedDate: 2007-10-11 12:00:02 +0200 (Thu, 11 Oct 2007) $
* Revision: $Id: TowerAttack.php 1117 2007-10-11 10:00:02Z alreadythere $
*/

/*
Needed for TowerAttack
*/
$db -> query("CREATE TABLE IF NOT EXISTS " $db -> define_tablename("tower_attack""false") . "
(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
time int,
off_guild VARCHAR(50),
off_side VARCHAR(10),
off_player VARCHAR(20),
off_level int,
off_profession VARCHAR(15),
def_guild VARCHAR(50),
def_side VARCHAR(10),
zone VARCHAR(50),
x_coord INT,
y_coord INT,
UNIQUE (time, off_guild, off_side, off_player, def_guild, def_side, zone, x_coord, y_coord),
INDEX (off_guild),
INDEX (off_side),
INDEX (def_guild),
INDEX (def_side),
INDEX (zone))"
);

$db -> query("CREATE TABLE IF NOT EXISTS " $db -> define_tablename("tower_result""false") . "
(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
time int,
win_guild VARCHAR(50),
win_side VARCHAR(10),
lose_guild VARCHAR(50),
lose_side VARCHAR(10),
zone VARCHAR(50),
UNIQUE (time, win_guild, win_side, lose_guild, lose_side, zone),
INDEX (win_guild),
INDEX (win_side),
INDEX (zone))"
);


$towerAttack = new TowerAttack($bot);


$commands["tell"]["battle"] = &$towerAttack;
$commands["tell"]["victory"] = &$towerAttack;

$commands["pgmsg"]["battle"] = &$towerAttack;
$commands["pgmsg"]["victory"] = &$towerAttack;

$commands["gc"]["battle"] = &$towerAttack;
$commands["gc"]["victory"] = &$towerAttack;

$commands["gmsg"]["All Towers"][] = &$towerAttack;
$commands["gmsg"]["Tower Battle Outcome"][] = &$towerAttack;


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



/*
Constructor:
Hands over a referance to the "Bot" class.
*/
function TowerAttack (&$bot)
{
$this -> bot = &$bot;

$this -> bot -> accesscontrol -> create("all""battle""GUEST");
$this -> bot -> accesscontrol -> create("all""victory""GUEST");

$this -> bot -> settings -> create("TowerAttack""Spam"TRUE"Is spamming of tower attacks into org chat on or off?");
$this -> bot -> settings -> create("TowerAttack""SpamTo""both""Where should any tower spam be displayed to? Just gc, just pgmsg, or both?""gc;pgmsg;both");
$this -> bot -> settings -> create("TowerAttack""ReadOnly"TRUE"Should the bot only read tower attacks without adding them to the tables? Useful if you got several bots sharing tower tables.");
$this -> bot -> settings -> create("TowerAttack""AttackStringOrged""#!off_guild!# attacked #!def_guild!# in##highlight## #!zone!# (#!lca_num!#)##end##! #!blob!#""This string is used as base for all tower attack spam of orged characters. For more information read the comment in TowerAttack.php for the format_attack_string() function""");
$this -> bot -> settings -> create("TowerAttack""AttackStringUnorged""#!off_player!# attacked #!def_guild!# in##highlight## #!zone!# (#!lca_num!#)##end##! #!blob!#""This string is used as base for all tower attack spam of orged characters. For more information read the comment in TowerAttack.php for the format_attack_string() function""");
$this -> bot -> settings -> create("TowerAttack""BlobStringOrged""#!time!# - #!off_guild!# (#!off_player!#, #!off_level!# #!off_profession!#) attacked #!def_guild!# in #!zone!# (#!lca_num!#, L #!lca_minlevel!# - #!lca_maxlevel!#).""This string is used as base for every entry in the history blob for tower attacks. For more information read the comment in TowerAttack.php for the format_attack_string() function""");
$this -> bot -> settings -> create("TowerAttack""BlobStringUnorged""#!time!# - #!off_player!# (#!off_level!# #!off_profession!#) attacked #!def_guild!# in #!zone!# (#!lca_num!#, L #!lca_minlevel!# - #!lca_maxlevel!#).""This string is used as base for every entry in the history blob for tower attacks. For more information read the comment in TowerAttack.php for the format_attack_string() function""");
$this -> bot -> settings -> create("TowerAttack""AttacksPerBlob"20"How many attacks should be shown in the attack history blob?""3;5;8;10;13;;15;18;20");
$this -> bot -> settings -> create("TowerAttack""VictoryBlobSize"20"How many victories from the history should be displayed at once?""5;10;15;20");
$this -> bot -> settings -> create("TowerAttack""VictoryString""#!time!# - #!off_guild!# won vs #!def_guild!# in #!zone!#!""This string is used as base for the victory lines in the victory blob. For more information read the comment in TowerAttack.php for the format_attack_string() function""");
$this -> bot -> settings -> create("TowerAttack""SchemaVersion"1"The version of the table schema."NULLTRUE);
$this -> schemaversion 2;

$this -> update_table();

$this -> help['description'] = 'Handle tower attack events.';
$this -> help['command']['battle']="Shows recent tower attacks.";
$this -> help['command']['victory'] = "Shows recent tower victories.";
$this -> help['notes'] = "The bot MUST be in the top-three rank of the guild for this module to work.";
}



function update_table()
{
switch ($this -> bot -> settings -> get("TowerAttack""SchemaVersion"))
{
case 1:
$this -> bot -> db -> query("ALTER IGNORE TABLE #___tower_result ADD zone VARCHAR(50)");
$this -> bot -> db -> query("ALTER IGNORE TABLE #___tower_result "
"ADD UNIQUE (time, win_guild, win_side, lose_guild, lose_side, zone), "
"ADD INDEX (win_guild), ADD INDEX (win_side), ADD INDEX (zone)");

echo "\nMaking sure that tower_attack table does not contain duplicate entries (same timestamp, org, side and zone.\nThis may take a few seconds on large existing tables!\n";
$tablename "temp_tower_attack_" time() . "_temp";
$this -> bot -> db -> query("CREATE TABLE IF NOT EXISTS " $tablename
"(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, "
"time int, "
"off_guild VARCHAR(50), "
"off_side VARCHAR(10), "
"off_player VARCHAR(20), "
"off_level int, "
"off_profession VARCHAR(15), "
"def_guild VARCHAR(50), "
"def_side VARCHAR(10), "
"zone VARCHAR(50), "
"x_coord INT, "
"y_coord INT, "
"UNIQUE (time, off_guild, off_side, off_player, def_guild, def_side, zone, x_coord, y_coord), "
"INDEX (off_guild), "
"INDEX (off_side), "
"INDEX (def_guild), "
"INDEX (def_side), "
"INDEX (zone))");
$this -> bot -> db -> query("INSERT IGNORE INTO " $tablename
"(time, off_guild, off_side, off_player, off_level, off_profession, def_guild, def_side, zone, "
"x_coord, y_coord) "
"SELECT time, off_guild, off_side, off_player, off_level, off_profession, def_guild, def_side, zone, "
"x_coord, y_coord FROM #___tower_attack");
echo "Done with copying all unique entries!\n";
$this -> bot -> db -> query("DROP TABLE #___tower_attack");
$this -> bot -> db -> query("ALTER TABLE " $tablename " RENAME #___tower_attack");
case 2:
default:
break;
}

$this -> bot -> settings -> save("TowerAttack""SchemaVersion"$this -> schemaversion);
}



/*
This gets called on a tell
*/
function tell($name$msg)
{
$this -> handler($name$msg"tell");
}


function handler($name$msg$channel)
{
if (preg_match("/^" $this -> bot -> commpre "battle$/i"$msg))
$this -> bot -> send_output($name$this -> battle_blob(), $channel);
if (preg_match("/^" $this -> bot -> commpre "victory$/i"$msg))
$this -> bot -> send_output($name$this -> victory_blob(), $channel);
}



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



/*
This gets called on a msg in the guildchat with the command
*/
function gc($name$msg)
{
$this -> handler($name$msg"gc");
}



/*
Makes the victory results
*/
function victory_blob()
{
$battle "##blob_title##:::: Recent Battle Results ::::##end##\n\n";

$result $this -> bot -> db -> select("SELECT time, win_guild as off_guild, win_side as off_side, lose_guild as def_guild,"
" lose_side as def_side, zone FROM #___tower_result ORDER BY time DESC LIMIT 0, "
$this -> bot -> settings -> get("TowerAttack""VictoryBlobSize"), MYSQL_ASSOC);

if (empty($result))
{
return "No tower victories noticed yet!";
}

foreach ($result as $res)
{
$battle .= "##blob_text##" $this -> format_attack_string($res,
$this -> bot -> settings -> get("TowerAttack""VictoryString"), true) . "</font>\n\n";
}
return "Tower Battles Won: " $this -> bot -> make_blob("click to view"$battle);
}



/*
Makes the battle results
*/
function battle_blob()
{
$battle "##blob_title##:::: Recent Tower Battles ::::##end##\n\n";

$result $this -> bot -> db -> select("SELECT time, off_guild, off_side, off_player, off_level, off_profession, "
"def_guild, def_side, zone, x_coord, y_coord FROM #___tower_attack ORDER BY time DESC LIMIT 0, "
$this -> bot -> settings -> get("TowerAttack""AttacksPerBlob"), MYSQL_ASSOC);

if (empty($result))
{
return "No tower attacks noticed yet!";
}

foreach ($result as $res)
{
if ($res["off_guild"] != "")
{
$str $this -> bot -> settings -> get("TowerAttack""BlobStringOrged");
}
else
{
$str $this -> bot -> settings -> get("TowerAttack""BlobStringUnorged");
}
$battle .= "##blob_text##" $this -> format_attack_string($res$str) . "</font>\n\n";
}
return "Tower Battles: " $this -> bot -> make_blob("click to view"$battle);
}



/*
This gets called on a msg in the group
*/
function gmsg($name$group$msg)
{
$attack false;
$victory false;

if (preg_match("/The (clan|neutral|omni) organization (.+) just entered a state of war! (.+) attacked the (clan|neutral|omni) organization (.+)'s tower in (.+) at location \(([0-9]+), ([0-9]+)\)/i"$msg$info))
{
$infos["off_guild"] = $info[2];
$infos["off_side"] = ucfirst(strtolower($info[1]));
$infos["off_player"] = $info[3];
$infos["def_guild"] = $info[5];
$infos["def_side"] = ucfirst(strtolower($info[4]));
$infos["zone"] = $info[6];
$infos["x_coord"] = $info[7];
$infos["y_coord"] = $info[8];
$attack true;
}
else if (preg_match("/(.+) just attacked the (clan|neutral|omni) organization (.+)'s tower in (.+) at location \(([0-9]+), ([0-9]+)\)/i"$msg$info))
{
$infos["off_guild"] = "";
$infos["off_side"] = "";
$infos["off_player"] = $info[1];
$infos["def_guild"] = $info[3];
$infos["def_side"] = ucfirst(strtolower($info[2]));
$infos["zone"] = $info[4];
$infos["x_coord"] = $info[5];
$infos["y_coord"] = $info[6];
$attack true;
}
else if (preg_match("/(.+) (Clan|Omni|Neutral) organization (.+) attacked the (Clan|Omni|Neutral) (.+) at their base in (.+). The attackers won!!/i"$msg$info))
{
if (!$this -> bot -> settings -> get("TowerAttack""ReadOnly"))
{
$this -> bot -> db -> query("INSERT INTO #___tower_result (time, win_guild, win_side, lose_guild, "
"lose_side, zone) VALUES ('" time() . "', '" mysql_escape_string($info[3]) . "', '" $info[2]
"', '" mysql_escape_string($info[5]) . "', '" $info[4] . "', '" $info[6] . "')");
}
}

if ($attack)
{
$infos["time"] = time();
$player $this -> bot -> whois -> lookup($infos["off_player"]);
if (empty($player["level"]))
{
$player["level"] = '0';
}

if (empty($player["profession"]))
{
$player["profession"] = 'Unknown';
}

if (empty($infos["off_side"]))
{
if ($player['error'])
{
$infos["off_side"] = "error";
}
else
{
$infos["off_side"] = $player["faction"];
}
}

$infos["off_level"] = $player["level"];
$infos["off_profession"] = $player["profession"];

if ($this -> bot -> settings -> get("TowerAttack""Spam"))
{
if ($infos["off_guild"] != "")
{
$msg $this -> format_attack_string($infos,
$this -> bot -> settings -> get("TowerAttack""AttackStringOrged"));
}
else
{
$msg $this -> format_attack_string($infos,
$this -> bot -> settings -> get("TowerAttack""AttackStringUnOrged"));
}

$this -> bot -> send_output(""$msg$this -> bot -> settings -> get("TowerAttack""SpamTo"));
$this -> bot -> commands["tell"]["irc"] -> irc_send_local($ircmsg);
}

if (!($this -> bot -> settings -> get("TowerAttack""ReadOnly")))
{
$this -> bot -> db -> query("INSERT INTO #___tower_attack (time, off_guild, off_side, off_player, "
"off_level, off_profession, def_guild, def_side, zone, x_coord, y_coord) VALUES ('" $infos["time"] . "', '"
mysql_escape_string($infos["off_guild"]) . "', '" $infos["off_side"] . "', '" $infos["off_player"]
"', '" $infos["off_level"] . "', '" $infos["off_profession"] . "', '"
mysql_escape_string($infos["def_guild"]) . "', '" $infos["def_side"] . "', '" $infos["zone"] . "', '"
$infos["x_coord"] . "', '" $infos["y_coord"] . "')");
}
}

}

// Gets LCA Area info from LCA Table
function get_lcainfo($zone$x$y)
{
$rad 290//Tower Attack Radius for LCA Table Search
$glca $this -> bot -> db -> select("SELECT * FROM #___land_control_zones WHERE area = '".$zone."'
AND x BETWEEN "
.$x."-".$rad." and ".$x."+".$rad."
AND y BETWEEN "
.$y."-".$rad." and ".$y."+".$rad);
if (!empty($glca))
{
$lca["pid"] = $glca[0][4];
$lca["lrng"] = $glca[0][1];
$lca["hrng"] = $glca[0][2];
$lca["area"] = $glca[0][3];
$lca["x"] = $glca[0][5];
$lca["y"] = $glca[0][6];
$lca["name"] = $glca[0][7];
}
else
{
$lca["pid"] = '??';
$lca["name"] = '??';
$lca["hrng"] = 'Unknown';
}
return $lca;
}

// Formats the attack spam, using the array $infos to replace tags in $string.
// Each field name in the array can be used as a tag encased in #! !# to be replaced with the info.
// The additional tag #!blob!# can be used to add a blob containing all important information about the attack.
// The tag #!lca_num!# can be used to enter the number on huge map, the tags #!lca_name!#, #!lca_minlevel!#, #!lca_maxlevel!#
// can be used for additional information about the attacked tower site.
// List of the fields in the infos[] array: time, off_guild, off_side, off_player, off_level, off_profession, def_guild,
// def_side, zone, x_coord, y_coord. time is expected as unix timestamp, meaning seconds since unix 0 time. It is gmdate'd.
// off_guild, off_player iand def_guild are colorized using off_side information.
// #!br!# can be used to add linebreaks to the output.
function format_attack_string($infos$string$victory false)
{
if ($victory)
{
$infos["lca_num"] = "";
$infos["lca_name"] = "";
$infos["lca_minlevel"] = "";
$infos["lca_maxlevel"] = "";
$infos["blob"] = "";
}
else
{
$lca $this -> get_lcainfo($infos["zone"], $infos["x_coord"], $infos["y_coord"]);
$infos["lca_num"] = "##red##x".$lca['pid']."</font>";
$infos["lca_name"] = $lca["name"];
$infos["lca_minlevel"] = $lca["lrng"];
$infos["lca_maxlevel"] = $lca["hrng"];
$prtlca "LCA: " $infos["lca_num"] . "##normal## - " $lca['name'] . "##end## ##highlight##(L " $lca['lrng']
" - " $lca['hrng'] . ")##end##\n";

$battle "##blob_title##" $infos["zone"] . " (" $infos["x_coord"] . "x" $infos["y_coord"] . ")##end##\n";
$battle .= $prtlca;
$battle .= "Attacker: ##" $infos["off_side"] . "##" $infos["off_player"] . " ##end##(" $infos["off_level"];
$battle .= " " $infos["off_profession"] . ")\n";
$ircmsg "4[Tower Attack] " $infos["off_player"] . " (" $infos["off_level"] . " " $infos["off_profession"] . ")";
if (!empty($infos["off_guild"]))
{
$battle .= "Attacking Guild: ##" $infos["off_side"] . "##" $infos["off_guild"] . "##end##\n";
$ircmsg .= " of " $infos["off_guild"] . " (" $infos["off_side"] . ")";
}
$battle .= "Defending Guild: ##" $infos["def_side"] . "##" $infos["def_guild"] . "##end##";
$ircmsg .= " has attacked " $infos["def_guild"] . " (" $infos["def_side"] . ") in " $infos["zone"];
$infos["blob"] = $this -> bot -> make_blob("More infos"$battle);
}
$infos["br"] = "\n";
$infos["time"] = gmdate($this -> bot -> settings -> get("Time""FormatString"), $infos["time"]);

if ($infos["off_side"] == "")
{
$who $this -> bot -> whois -> lookup($infos["off_player"]);
if ($who['error'])
{
$infos["off_side"] = "error";
}
else
{
$infos["off_side"] = $who["faction"];
}
}
$infos["off_guild"] = "##" $infos["off_side"] . "##" $infos["off_guild"] . "</font>";
$infos["off_player"] = "##" $infos["off_side"] . "##" $infos["off_player"] . "</font>";
$infos["def_guild"] = "##" $infos["def_side"] . "##" $infos["def_guild"] . "</font>";

foreach ($infos AS $key => $value)
{
$string eregi_replace("#!" $key "!#"$value$string);
}

return $string;
}
}
?>


Offline Temar

  • Contributor
  • *******
  • Posts: 1140
  • Karma: +0/-0
    • AoFiles
Re: Tower Messages to IRC
« Reply #1 on: December 06, 2007, 05:55:17 am »
Code: [Select]
$this -> bot -> send_irc($this -> bot -> settings -> get("Irc", "Ircguildprefix"), "", $ircmsg);

Offline Dabaron

  • BeBot Apprentice
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: Tower Messages to IRC
« Reply #2 on: December 06, 2007, 07:12:05 am »
Same place I have my message at?

Offline Temar

  • Contributor
  • *******
  • Posts: 1140
  • Karma: +0/-0
    • AoFiles
Re: Tower Messages to IRC
« Reply #3 on: December 06, 2007, 07:14:09 am »
same place as $this -> bot -> send_output
then it sends when/if it sends to gc

Offline Dabaron

  • BeBot Apprentice
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: Tower Messages to IRC
« Reply #4 on: December 06, 2007, 07:45:06 am »
Thanks much, you rock

Offline Dabaron

  • BeBot Apprentice
  • ***
  • Posts: 163
  • Karma: +0/-0
Re: Tower Messages to IRC
« Reply #5 on: December 06, 2007, 09:00:05 am »
Well.. that kind of worked.  Its sending a message to IRC but its a blank message on every attack.  Any ideas what I did wrong?

Offline Alreadythere

  • BeBot Maintainer
  • BeBot Hero
  • ******
  • Posts: 1288
  • Karma: +0/-0
Re: Tower Messages to IRC
« Reply #6 on: December 06, 2007, 11:34:16 am »
I'd guess you are trying to output a  blob to IRC. Not sure though.

Offline Temar

  • Contributor
  • *******
  • Posts: 1140
  • Karma: +0/-0
    • AoFiles
Re: Tower Messages to IRC
« Reply #7 on: December 06, 2007, 06:31:11 pm »
have u set $ircmsg to whateva u want output?

Offline Temar

  • Contributor
  • *******
  • Posts: 1140
  • Karma: +0/-0
    • AoFiles
Re: Tower Messages to IRC
« Reply #8 on: December 06, 2007, 06:37:27 pm »
i see where u set $ircmsg
it wont be set in another function
u need to return it

Offline Temar

  • Contributor
  • *******
  • Posts: 1140
  • Karma: +0/-0
    • AoFiles
Re: Tower Messages to IRC
« Reply #9 on: December 06, 2007, 06:47:19 pm »
try this

Code: [Select]
<?php
/*
* TowerAttack.php - Handle Tower attack events.
*
* BeBot - An Anarchy Online Chat Automaton
* Copyright (C) 2004 Jonas Jax
* Copyright (C) 2005-2007 Thomas Juberg StensÃ¥s, ShadowRealm Creations and the BeBot development team.
*
* Developed by:
* - Alreadythere (RK2)
* - Blondengy (RK1)
* - Blueeagl3 (RK1)
* - Glarawyn (RK1)
* - Khalem (RK1)
* - Naturalistic (RK1)
*
* See Credits file for all aknowledgements.
*
*  This program is free software; you can redistribute it and/or modify
*  it under the terms of the GNU General Public License as published by
*  the Free Software Foundation; version 2 of the License only.
*
*  This program is distributed in the hope that it will be useful,
*  but WITHOUT ANY WARRANTY; without even the implied warranty of
*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*  GNU General Public License for more details.
*
*  You should have received a copy of the GNU General Public License
*  along with this program; if not, write to the Free Software
*  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
*  USA
*
* File last changed at $LastChangedDate: 2007-10-11 12:00:02 +0200 (Thu, 11 Oct 2007) $
* Revision: $Id: TowerAttack.php 1117 2007-10-11 10:00:02Z alreadythere $
*/

/*
Needed for TowerAttack
*/
$db -> query("CREATE TABLE IF NOT EXISTS " $db -> define_tablename("tower_attack""false") . "
(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
time int,
off_guild VARCHAR(50),
off_side VARCHAR(10),
off_player VARCHAR(20),
off_level int,
off_profession VARCHAR(15),
def_guild VARCHAR(50),
def_side VARCHAR(10),
zone VARCHAR(50),
x_coord INT,
y_coord INT,
UNIQUE (time, off_guild, off_side, off_player, def_guild, def_side, zone, x_coord, y_coord),
INDEX (off_guild),
INDEX (off_side),
INDEX (def_guild),
INDEX (def_side),
INDEX (zone))"
);

$db -> query("CREATE TABLE IF NOT EXISTS " $db -> define_tablename("tower_result""false") . "
(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
time int,
win_guild VARCHAR(50),
win_side VARCHAR(10),
lose_guild VARCHAR(50),
lose_side VARCHAR(10),
zone VARCHAR(50),
UNIQUE (time, win_guild, win_side, lose_guild, lose_side, zone),
INDEX (win_guild),
INDEX (win_side),
INDEX (zone))"
);


$towerAttack = new TowerAttack($bot);


$commands["tell"]["battle"] = &$towerAttack;
$commands["tell"]["victory"] = &$towerAttack;

$commands["pgmsg"]["battle"] = &$towerAttack;
$commands["pgmsg"]["victory"] = &$towerAttack;

$commands["gc"]["battle"] = &$towerAttack;
$commands["gc"]["victory"] = &$towerAttack;

$commands["gmsg"]["All Towers"][] = &$towerAttack;
$commands["gmsg"]["Tower Battle Outcome"][] = &$towerAttack;


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



/*
Constructor:
Hands over a referance to the "Bot" class.
*/
function TowerAttack (&$bot)
{
$this -> bot = &$bot;

$this -> bot -> accesscontrol -> create("all""battle""GUEST");
$this -> bot -> accesscontrol -> create("all""victory""GUEST");

$this -> bot -> settings -> create("TowerAttack""Spam"TRUE"Is spamming of tower attacks into org chat on or off?");
$this -> bot -> settings -> create("TowerAttack""SpamTo""both""Where should any tower spam be displayed to? Just gc, just pgmsg, or both?""gc;pgmsg;both");
$this -> bot -> settings -> create("TowerAttack""ReadOnly"TRUE"Should the bot only read tower attacks without adding them to the tables? Useful if you got several bots sharing tower tables.");
$this -> bot -> settings -> create("TowerAttack""AttackStringOrged""#!off_guild!# attacked #!def_guild!# in##highlight## #!zone!# (#!lca_num!#)##end##! #!blob!#""This string is used as base for all tower attack spam of orged characters. For more information read the comment in TowerAttack.php for the format_attack_string() function""");
$this -> bot -> settings -> create("TowerAttack""AttackStringUnorged""#!off_player!# attacked #!def_guild!# in##highlight## #!zone!# (#!lca_num!#)##end##! #!blob!#""This string is used as base for all tower attack spam of orged characters. For more information read the comment in TowerAttack.php for the format_attack_string() function""");
$this -> bot -> settings -> create("TowerAttack""BlobStringOrged""#!time!# - #!off_guild!# (#!off_player!#, #!off_level!# #!off_profession!#) attacked #!def_guild!# in #!zone!# (#!lca_num!#, L #!lca_minlevel!# - #!lca_maxlevel!#).""This string is used as base for every entry in the history blob for tower attacks. For more information read the comment in TowerAttack.php for the format_attack_string() function""");
$this -> bot -> settings -> create("TowerAttack""BlobStringUnorged""#!time!# - #!off_player!# (#!off_level!# #!off_profession!#) attacked #!def_guild!# in #!zone!# (#!lca_num!#, L #!lca_minlevel!# - #!lca_maxlevel!#).""This string is used as base for every entry in the history blob for tower attacks. For more information read the comment in TowerAttack.php for the format_attack_string() function""");
$this -> bot -> settings -> create("TowerAttack""AttacksPerBlob"20"How many attacks should be shown in the attack history blob?""3;5;8;10;13;;15;18;20");
$this -> bot -> settings -> create("TowerAttack""VictoryBlobSize"20"How many victories from the history should be displayed at once?""5;10;15;20");
$this -> bot -> settings -> create("TowerAttack""VictoryString""#!time!# - #!off_guild!# won vs #!def_guild!# in #!zone!#!""This string is used as base for the victory lines in the victory blob. For more information read the comment in TowerAttack.php for the format_attack_string() function""");
$this -> bot -> settings -> create("TowerAttack""SchemaVersion"1"The version of the table schema."NULLTRUE);
$this -> schemaversion 2;

$this -> update_table();

$this -> help['description'] = 'Handle tower attack events.';
$this -> help['command']['battle']="Shows recent tower attacks.";
$this -> help['command']['victory'] = "Shows recent tower victories.";
$this -> help['notes'] = "The bot MUST be in the top-three rank of the guild for this module to work.";
}



function update_table()
{
switch ($this -> bot -> settings -> get("TowerAttack""SchemaVersion"))
{
case 1:
$this -> bot -> db -> query("ALTER IGNORE TABLE #___tower_result ADD zone VARCHAR(50)");
$this -> bot -> db -> query("ALTER IGNORE TABLE #___tower_result "
"ADD UNIQUE (time, win_guild, win_side, lose_guild, lose_side, zone), "
"ADD INDEX (win_guild), ADD INDEX (win_side), ADD INDEX (zone)");

echo "\nMaking sure that tower_attack table does not contain duplicate entries (same timestamp, org, side and zone.\nThis may take a few seconds on large existing tables!\n";
$tablename "temp_tower_attack_" time() . "_temp";
$this -> bot -> db -> query("CREATE TABLE IF NOT EXISTS " $tablename
"(id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, "
"time int, "
"off_guild VARCHAR(50), "
"off_side VARCHAR(10), "
"off_player VARCHAR(20), "
"off_level int, "
"off_profession VARCHAR(15), "
"def_guild VARCHAR(50), "
"def_side VARCHAR(10), "
"zone VARCHAR(50), "
"x_coord INT, "
"y_coord INT, "
"UNIQUE (time, off_guild, off_side, off_player, def_guild, def_side, zone, x_coord, y_coord), "
"INDEX (off_guild), "
"INDEX (off_side), "
"INDEX (def_guild), "
"INDEX (def_side), "
"INDEX (zone))");
$this -> bot -> db -> query("INSERT IGNORE INTO " $tablename
"(time, off_guild, off_side, off_player, off_level, off_profession, def_guild, def_side, zone, "
"x_coord, y_coord) "
"SELECT time, off_guild, off_side, off_player, off_level, off_profession, def_guild, def_side, zone, "
"x_coord, y_coord FROM #___tower_attack");
echo "Done with copying all unique entries!\n";
$this -> bot -> db -> query("DROP TABLE #___tower_attack");
$this -> bot -> db -> query("ALTER TABLE " $tablename " RENAME #___tower_attack");
case 2:
default:
break;
}

$this -> bot -> settings -> save("TowerAttack""SchemaVersion"$this -> schemaversion);
}



/*
This gets called on a tell
*/
function tell($name$msg)
{
$this -> handler($name$msg"tell");
}


function handler($name$msg$channel)
{
if (preg_match("/^" $this -> bot -> commpre "battle$/i"$msg))
$this -> bot -> send_output($name$this -> battle_blob(), $channel);
if (preg_match("/^" $this -> bot -> commpre "victory$/i"$msg))
$this -> bot -> send_output($name$this -> victory_blob(), $channel);
}



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



/*
This gets called on a msg in the guildchat with the command
*/
function gc($name$msg)
{
$this -> handler($name$msg"gc");
}



/*
Makes the victory results
*/
function victory_blob()
{
$battle "##blob_title##:::: Recent Battle Results ::::##end##\n\n";

$result $this -> bot -> db -> select("SELECT time, win_guild as off_guild, win_side as off_side, lose_guild as def_guild,"
" lose_side as def_side, zone FROM #___tower_result ORDER BY time DESC LIMIT 0, "
$this -> bot -> settings -> get("TowerAttack""VictoryBlobSize"), MYSQL_ASSOC);

if (empty($result))
{
return "No tower victories noticed yet!";
}

foreach ($result as $res)
{
$battle .= "##blob_text##" $this -> format_attack_string($res,
$this -> bot -> settings -> get("TowerAttack""VictoryString"), true) . "</font>\n\n";
}
return "Tower Battles Won: " $this -> bot -> make_blob("click to view"$battle);
}



/*
Makes the battle results
*/
function battle_blob()
{
$battle "##blob_title##:::: Recent Tower Battles ::::##end##\n\n";

$result $this -> bot -> db -> select("SELECT time, off_guild, off_side, off_player, off_level, off_profession, "
"def_guild, def_side, zone, x_coord, y_coord FROM #___tower_attack ORDER BY time DESC LIMIT 0, "
$this -> bot -> settings -> get("TowerAttack""AttacksPerBlob"), MYSQL_ASSOC);

if (empty($result))
{
return "No tower attacks noticed yet!";
}

foreach ($result as $res)
{
if ($res["off_guild"] != "")
{
$str $this -> bot -> settings -> get("TowerAttack""BlobStringOrged");
}
else
{
$str $this -> bot -> settings -> get("TowerAttack""BlobStringUnorged");
}
$battle .= "##blob_text##" $this -> format_attack_string($res$str) . "</font>\n\n";
}
return "Tower Battles: " $this -> bot -> make_blob("click to view"$battle);
}



/*
This gets called on a msg in the group
*/
function gmsg($name$group$msg)
{
$attack false;
$victory false;

if (preg_match("/The (clan|neutral|omni) organization (.+) just entered a state of war! (.+) attacked the (clan|neutral|omni) organization (.+)'s tower in (.+) at location \(([0-9]+), ([0-9]+)\)/i"$msg$info))
{
$infos["off_guild"] = $info[2];
$infos["off_side"] = ucfirst(strtolower($info[1]));
$infos["off_player"] = $info[3];
$infos["def_guild"] = $info[5];
$infos["def_side"] = ucfirst(strtolower($info[4]));
$infos["zone"] = $info[6];
$infos["x_coord"] = $info[7];
$infos["y_coord"] = $info[8];
$attack true;
}
else if (preg_match("/(.+) just attacked the (clan|neutral|omni) organization (.+)'s tower in (.+) at location \(([0-9]+), ([0-9]+)\)/i"$msg$info))
{
$infos["off_guild"] = "";
$infos["off_side"] = "";
$infos["off_player"] = $info[1];
$infos["def_guild"] = $info[3];
$infos["def_side"] = ucfirst(strtolower($info[2]));
$infos["zone"] = $info[4];
$infos["x_coord"] = $info[5];
$infos["y_coord"] = $info[6];
$attack true;
}
else if (preg_match("/(.+) (Clan|Omni|Neutral) organization (.+) attacked the (Clan|Omni|Neutral) (.+) at their base in (.+). The attackers won!!/i"$msg$info))
{
if (!$this -> bot -> settings -> get("TowerAttack""ReadOnly"))
{
$this -> bot -> db -> query("INSERT INTO #___tower_result (time, win_guild, win_side, lose_guild, "
"lose_side, zone) VALUES ('" time() . "', '" mysql_escape_string($info[3]) . "', '" $info[2]
"', '" mysql_escape_string($info[5]) . "', '" $info[4] . "', '" $info[6] . "')");
}
}

if ($attack)
{
$infos["time"] = time();
$player $this -> bot -> whois -> lookup($infos["off_player"]);
if (empty($player["level"]))
{
$player["level"] = '0';
}

if (empty($player["profession"]))
{
$player["profession"] = 'Unknown';
}

if (empty($infos["off_side"]))
{
if ($player['error'])
{
$infos["off_side"] = "error";
}
else
{
$infos["off_side"] = $player["faction"];
}
}

$infos["off_level"] = $player["level"];
$infos["off_profession"] = $player["profession"];

if ($this -> bot -> settings -> get("TowerAttack""Spam"))
{
if ($infos["off_guild"] != "")
{
$msg $this -> format_attack_string($infos,
$this -> bot -> settings -> get("TowerAttack""AttackStringOrged"));
}
else
{
$msg $this -> format_attack_string($infos,
$this -> bot -> settings -> get("TowerAttack""AttackStringUnOrged"));
}

$this -> bot -> send_output(""$msg$this -> bot -> settings -> get("TowerAttack""SpamTo"));
$ircmsg $this -> format_irc_string($infos)
$this -> bot -> send_irc($this -> bot -> settings -> get("Irc""Ircguildprefix"), ""$ircmsg);
}

if (!($this -> bot -> settings -> get("TowerAttack""ReadOnly")))
{
$this -> bot -> db -> query("INSERT INTO #___tower_attack (time, off_guild, off_side, off_player, "
"off_level, off_profession, def_guild, def_side, zone, x_coord, y_coord) VALUES ('" $infos["time"] . "', '"
mysql_escape_string($infos["off_guild"]) . "', '" $infos["off_side"] . "', '" $infos["off_player"]
"', '" $infos["off_level"] . "', '" $infos["off_profession"] . "', '"
mysql_escape_string($infos["def_guild"]) . "', '" $infos["def_side"] . "', '" $infos["zone"] . "', '"
$infos["x_coord"] . "', '" $infos["y_coord"] . "')");
}
}

}

// Gets LCA Area info from LCA Table
function get_lcainfo($zone$x$y)
{
$rad 290//Tower Attack Radius for LCA Table Search
$glca $this -> bot -> db -> select("SELECT * FROM #___land_control_zones WHERE area = '".$zone."'
AND x BETWEEN "
.$x."-".$rad." and ".$x."+".$rad."
AND y BETWEEN "
.$y."-".$rad." and ".$y."+".$rad);
if (!empty($glca))
{
$lca["pid"] = $glca[0][4];
$lca["lrng"] = $glca[0][1];
$lca["hrng"] = $glca[0][2];
$lca["area"] = $glca[0][3];
$lca["x"] = $glca[0][5];
$lca["y"] = $glca[0][6];
$lca["name"] = $glca[0][7];
}
else
{
$lca["pid"] = '??';
$lca["name"] = '??';
$lca["hrng"] = 'Unknown';
}
return $lca;
}

// Formats the attack spam, using the array $infos to replace tags in $string.
// Each field name in the array can be used as a tag encased in #! !# to be replaced with the info.
// The additional tag #!blob!# can be used to add a blob containing all important information about the attack.
// The tag #!lca_num!# can be used to enter the number on huge map, the tags #!lca_name!#, #!lca_minlevel!#, #!lca_maxlevel!#
// can be used for additional information about the attacked tower site.
// List of the fields in the infos[] array: time, off_guild, off_side, off_player, off_level, off_profession, def_guild,
// def_side, zone, x_coord, y_coord. time is expected as unix timestamp, meaning seconds since unix 0 time. It is gmdate'd.
// off_guild, off_player iand def_guild are colorized using off_side information.
// #!br!# can be used to add linebreaks to the output.
function format_attack_string($infos$string$victory false)
{
if ($victory)
{
$infos["lca_num"] = "";
$infos["lca_name"] = "";
$infos["lca_minlevel"] = "";
$infos["lca_maxlevel"] = "";
$infos["blob"] = "";
}
else
{
$lca $this -> get_lcainfo($infos["zone"], $infos["x_coord"], $infos["y_coord"]);
$infos["lca_num"] = "##red##x".$lca['pid']."</font>";
$infos["lca_name"] = $lca["name"];
$infos["lca_minlevel"] = $lca["lrng"];
$infos["lca_maxlevel"] = $lca["hrng"];
$prtlca "LCA: " $infos["lca_num"] . "##normal## - " $lca['name'] . "##end## ##highlight##(L " $lca['lrng']
" - " $lca['hrng'] . ")##end##\n";

$battle "##blob_title##" $infos["zone"] . " (" $infos["x_coord"] . "x" $infos["y_coord"] . ")##end##\n";
$battle .= $prtlca;
$battle .= "Attacker: ##" $infos["off_side"] . "##" $infos["off_player"] . " ##end##(" $infos["off_level"];
$battle .= " " $infos["off_profession"] . ")\n";
if (!empty($infos["off_guild"]))
{
$battle .= "Attacking Guild: ##" $infos["off_side"] . "##" $infos["off_guild"] . "##end##\n";
$ircmsg .= " of " $infos["off_guild"] . " (" $infos["off_side"] . ")";
}
$battle .= "Defending Guild: ##" $infos["def_side"] . "##" $infos["def_guild"] . "##end##";
$ircmsg .= " has attacked " $infos["def_guild"] . " (" $infos["def_side"] . ") in " $infos["zone"];
$infos["blob"] = $this -> bot -> make_blob("More infos"$battle);
}
$infos["br"] = "\n";
$infos["time"] = gmdate($this -> bot -> settings -> get("Time""FormatString"), $infos["time"]);

if ($infos["off_side"] == "")
{
$who $this -> bot -> whois -> lookup($infos["off_player"]);
if ($who['error'])
{
$infos["off_side"] = "error";
}
else
{
$infos["off_side"] = $who["faction"];
}
}
$infos["off_guild"] = "##" $infos["off_side"] . "##" $infos["off_guild"] . "</font>";
$infos["off_player"] = "##" $infos["off_side"] . "##" $infos["off_player"] . "</font>";
$infos["def_guild"] = "##" $infos["def_side"] . "##" $infos["def_guild"] . "</font>";

foreach ($infos AS $key => $value)
{
$string eregi_replace("#!" $key "!#"$value$string);
}

return $string;
}

function format_irc_string($infos)
{
$ircmsg "4[Tower Attack] " $infos["off_player"] . " (" $infos["off_level"] . " " $infos["off_profession"] . ")";
}
}
?>

 

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


0.8.x updates for AoC by bitnykk
[January 30, 2024, 11:16:08 pm]


0.8.x updates for AO by bitnykk
[January 30, 2024, 11:15:37 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: 501
  • 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