Code
#####################################################################################
#
# wow_mangos.tcl 0.1.4
#
# Описание:
# Выдаёт статистику по игракам и серверу MaNGOS на канал.
#
# Установка:
# 1) Скопируйте wow.tcl в директорию 'scripts; и добавьте строку
# 'source scripts/wow.tcl' в eggdrop.conf файл;
# 2) Настройте скрипт;
# 3) Измените информацию о версиях.
#
# Автор: GriffonHeart <GriffonHeart@sosnovoborsk.ru>
# Обновление: Skel
# Скрипты взяты с Mangos.ru
#
# Поддержка: irc.sosnovoborsk.ru @ #wow-s
#
######################################################################################
#
# Исрия версий:
#
#-------------------------------------------------------------------------------------
#
# v0.1.1 Переписан скрипт из wow.tcl v0.6.2 от faerion <faerion@eggdrop.org.ru>.
# v0.1.2 Исправлены мелкие ошибки.
# v0.1.3 Добавлен анонс о статусе сервера.
# v0.1.4 Добавлена поддержка 3 баз
# Исправлены некоторые функции
# Добавлена функция выборки игроков, провевших больше всех времени на сервере
# Добавлена выборка максимального аптайма
######################################################################################
### Настройки скрипта ################################################################
# Set your MySQL-host
set mysql(host) "Cдесь вписываем ваш хост"
# Set your MySQL-user
set mysql(user) "имя юзера для mysql"
# Set your MySQL-password
set mysql(password) "пароль"
# Set your MySQL-mangos-database
set mysql(dbm) "mangos"
# Set your MySQL-realmd-database
set mysql(dbr) "realmd"
# Set your MySQL-realmd-database
set mysql(dbc) "characters"
# Set interval between script announcements (minutes)
set wow(announcetime) 30
# Set your server realmid
set wow(realm_id) 1;
setudef flag nopubwow
### НЕ ИЗМЕНЯТЬ! Сединение с MySQL сервером ##########################################
### Скопированно из My Quest Engine System для WoWEmu от faerion #####################
foreach dir [glob -type d lib/*] {
source $dir/pkgIndex.tcl
}
set pl [package names]
if { [lsearch $pl "mysqltcl"]==-1 } {
puts "MyQE: mysqltcl extension not found. Exiting..."
return
}
unset pl
puts "MyQE: Opening MySQL connection..."
package require mysqltcl
foreach link [info vars "mysql*"] {
catch { ::mysql::close $link }
}
if { [catch { set myqe_dbr [::mysql::connect -host $mysql(host) -user $mysql(user) -password $mysql(password) -db $mysql(dbr)] }] } {
puts "MyQE: MySQL connection error. (Realmd) Exiting..."
return
}
if { [catch { set myqe_dbm [::mysql::connect -host $mysql(host) -user $mysql(user) -password $mysql(password) -db $mysql(dbm)] }] } {
puts "MyQE: MySQL connection error. (Mangos) Exiting..."
return
}
if { [catch { set myqe_dbc [::mysql::connect -host $mysql(host) -user $mysql(user) -password $mysql(password) -db $mysql(dbc)] }] } {
puts "MyQE: MySQL connection error. (Mangos) Exiting..."
return
}
puts "MyQE: Done"
######################################################################################
namespace eval wow {}
bind pub - "!wow" wow::wow
bind pub - "!djd" wow::wow
bind pub - "!вов" wow::wow
bind pub - "!цщц" wow::wow
bind pub - "!players" wow::players
bind pub - "!здфнукы" wow::players
bind pub - "!игроки" wow::players
bind pub - "!buhjrb" wow::players
bind pub - "!zombs" wow::topz
bind pub - "!зомби" wow::topz
bind pub - "!pjv,b" wow::topz
bind pub - "!ящьиы" wow::topz
proc wow::players {n uh h c t} {
if { [channel get $c nopubwow] } return
global myqe_dbr;
global myqe_dbc;
global myqe_dbm;
global wow;
set al_string "";
set ho_string "";
set read [::mysql::sel $myqe_dbc "select `name`, `race`, `class`, `data` FROM `characters` WHERE `online` = 1" -flatlist];
set al 0;
set ho 0;
for {set i 0} {$i<[llength $read]} { incr i } {
set name [lindex $read $i];
incr i
set race [lindex $read $i];
incr i
set class [lindex $read $i];
incr i
set level [lindex $read $i];
set level [lindex $level 34];
set flag 0;
if { $race==1 } {incr al;set flag 1;set race "Человек";}
if { $race==2 } {incr ho;set flag 2;set race "Орк";}
if { $race==3 } {incr al;set flag 1;set race "Карлик";}
if { $race==4 } {incr al;set flag 1;set race "Ночной эльф";}
if { $race==5 } {incr ho;set flag 2;set race "Нежить";}
if { $race==6 } {incr ho;set flag 2;set race "Таурен";}
if { $race==7 } {incr al;set flag 1;set race "Гном";}
if { $race==8 } {incr ho;set flag 2;set race "Тролль";}
if { $race==10 } {incr ho;set flag 2;set race "Кровавый эльф";}
if { $race==11 } {incr al;set flag 2;set race "Дрэней";}
if { $class==1 } {set class "Воин";}
if { $class==2 } {set class "Паладин";}
if { $class==3 } {set class "Охотник";}
if { $class==4 } {set class "Разбойник";}
if { $class==5 } {set class "Священник";}
if { $class==7 } {set class "Шаман";}
if { $class==8 } {set class "Маг";}
if { $class==9 } {set class "Колдун";}
if { $class==11 } {set class "Друид";}
if {$flag==1} {set al_string "$al_string\002$name\002 ($level; $race; $class), ";}
if {$flag==2} {set ho_string "$ho_string\002$name\002 ($level; $race; $class), ";}
}
set online [expr {$al+$ho}];
set proc_a [expr {round($al*100.00/$online*1.0)}];
set proc_h [expr {round($ho*100.00/$online*1.0)}];
set read [::mysql::sel $myqe_dbr "select `name` FROM `realmlist` WHERE `id` = $wow(realm_id)" -flatlist];
set server_name [lindex $read 0];
foreach chan [channels] {
if { [channel get $c nopubwow] } return
putserv "PRIVMSG $chan :\0033В королевстве \002$server_name\002 сейчас \002$online\002 персонажей\003";
if {$al>0} {
putserv "PRIVMSG $chan :\0032За Альянс \002$al\002 ($proc_a%)\003:";
putserv "PRIVMSG $chan :$al_string";
}
if {$ho>0} {
putserv "PRIVMSG $chan :\0035За Орду \002$ho\002 ($proc_h%)\003:";
putserv "PRIVMSG $chan :$ho_string";
}
}
}
proc wow::wow {n uh h c t} {
if { [channel get $c nopubwow] } return
global myqe_dbr;
global myqe_dbm;
global myqe_dbc;
global wow;
set time_cur [clock second];
set al 0;
set ho 0;
set proc_a 0;
set proc_h 0;
set read [::mysql::sel $myqe_dbc "select `race` FROM `characters` WHERE `online` = 1" -flatlist];
for {set i 0} {$i<[llength $read]} { incr i } {
if { [lindex $read $i]==1 } {incr al;}
if { [lindex $read $i]==2 } {incr ho;}
if { [lindex $read $i]==3 } {incr al;}
if { [lindex $read $i]==4 } {incr al;}
if { [lindex $read $i]==5 } {incr ho;}
if { [lindex $read $i]==6 } {incr ho;}
if { [lindex $read $i]==7 } {incr al;}
if { [lindex $read $i]==8 } {incr ho;}
if { [lindex $read $i]==10 } {incr ho;}
if { [lindex $read $i]==11 } {incr al;}
}
set online [llength $read];
if {$online!=0} {
set proc_a [expr {round($al*100.00/$online*1.0)}];
set proc_h [expr {round($ho*100.00/$online*1.0)}];
set len_a [expr {round($al*30/$online*1.0)}];
set len_h [expr {round($ho*30/$online*1.0)}];
if { $proc_a != 0 } {
set procs_a "$proc_a%";
set tlen_a [expr {[llength $procs_a]+2}];
if { $tlen_a>$len_a } {
set len_a $tlen_a;
set len_h [expr {30-$tlen_a}];
}
}
if { $proc_h != 0 } {
set procs_h "$proc_h%"
set tlen_h [expr {[llength $procs_h]+2}];
if { $tlen_h>$len_h } {
set len_h $tlen_h;
set len_a [expr {30-$tlen_h}];
}
}
if { $proc_a != 0 } {
set fp_a [string repeat "\ " [expr {$len_a-$tlen_a}]]
set pb_a "\0030,2 $procs_a $fp_a\003"
} else { set pb_a "" }
if { $proc_h != 0 } {
set fp_h [string repeat "\ " [expr {$len_h-$tlen_h}]]
set pb_h "\0030,5$fp_h $procs_h \003"
} else { set pb_h "" }
}
set read [::mysql::sel $myqe_dbr "select `name` FROM `realmlist` WHERE `id` = $wow(realm_id)" -flatlist];
set server_name [lindex $read 0];
set read [::mysql::sel $myqe_dbm "select `starttime` FROM `uptime` ORDER BY `starttime` DESC LIMIT 1" -flatlist]; set time_start [lindex $read 0];
set up_time [expr {$time_cur-$time_start}];
set read [::mysql::sel $myqe_dbm "SELECT MAX(`uptime`) FROM uptime;" -flatlist];
set mup_time [lindex $read 0];
set year [expr {round($up_time/60/60/24/30/12*1.0)}];
set month [expr {round(($up_time-$year*60*60*24*30*12)/60/60/24/30*1.0)}];
set day [expr {round(($up_time-$year*60*60*24*30*12-$month*60*60*24*30)/60/60/24*1.0)}];
set hour [expr {round(($up_time-$year*60*60*24*30*12-$month*60*60*24*30-$day*60*60*24)/60/60*1.0)}];
set min [expr {round(($up_time-$year*60*60*24*30*12-$month*60*60*24*30-$day*24*60*60-$hour*60*60)/60*1.0)}];
set sec [expr {round($up_time-$year*60*60*24*30*12-$month*60*60*24*30-$day*24*60*60-$hour*60*60-$min*60*1.0)}];
if {!$year==0} {
set up_time "$year\002г.\002 $month\002мес.\002 $day\002д.\002 $hour\002ч.\002 $min\002м.\002 $sec\002с.\002";
} elseif {!$month==0} {
set up_time "$month\002мес.\002 $day\002д.\002 $hour\002ч.\002 $min\002м.\002 $sec\002с.\002";
} elseif {!$day==0} {
set up_time "$day\002д.\002 $hour\002ч.\002 $min\002м.\002 $sec\002с.\002";
} elseif {!$hour==0} {
set up_time "$hour\002ч.\002 $min\002м.\002 $sec\002с.\002";
} elseif {!$min==0} {
set up_time "$min\002м.\002 $sec\002с.\002";
} elseif {!$sec==0} {
$up_time="$sec\002сек.\002";
} else {
set up_time "Неизвестная ошибка";
}
set year_m [expr {round($mup_time/60/60/24/30/12*1.0)}];
set month_m [expr {round(($mup_time-$year_m*60*60*24*30*12)/60/60/24/30*1.0)}];
set day_m [expr {round(($mup_time-$year_m*60*60*24*30*12-$month_m*60*60*24*30)/60/60/24*1.0)}];
set hour_m [expr {round(($mup_time-$year_m*60*60*24*30*12-$month_m*60*60*24*30-$day_m*60*60*24)/60/60*1.0)}];
set min_m [expr {round(($mup_time-$year_m*60*60*24*30*12-$month_m*60*60*24*30-$day_m*24*60*60-$hour_m*60*60)/60*1.0)}];
set sec_m [expr {round($mup_time-$year_m*60*60*24*30*12-$month_m*60*60*24*30-$day_m*24*60*60-$hour_m*60*60-$min_m*60*1.0)}];
if {!$year_m==0} {
set up_time "$year_m\002г.\002 $month_m\002мес.\002 $day_m\002д.\002 $hour_m\002ч.\002 $min_m\002м.\002 $sec_m\002с.\002";
} elseif {!$month_m==0} {
set up_time "$month_m\002мес.\002 $day_m\002д.\002 $hour_m\002ч.\002 $min_m\002м.\002 $sec_m\002с.\002";
} elseif {!$day_m==0} {
set mup_time "$day_m\002д.\002 $hour_m\002ч.\002 $min_m\002м.\002 $sec_m\002с.\002";
} elseif {!$hour==0} {
set mup_time "$hour_m\002ч.\002 $min_m\002м.\002 $sec_m\002с.\002";
} elseif {!$min_m==0} {
set mup_time "$min_m\002м.\002 $sec_m\002с.\002";
} elseif {!$sec_m==0} {
$mup_time="$sec_m\002сек.\002";
} else {
set mup_time "Неизвестная ошибка";
}
foreach chan [channels] {
if { [channel get $c nopubwow] } return
putserv "PRIVMSG $chan :Королевство: \0033\002$server_name\002\003";
putserv "PRIVMSG $chan :Работает: \0033\002$up_time\002\003";
putserv "PRIVMSG $chan :Максимальное время работы: \0033\002$mup_time\002\003";
putserv "PRIVMSG $chan :Персонажей: \0033\002$online\002\003";
if {$online!=0} {
putserv "PRIVMSG $chan :\0032Альянс\003/\0035Орда\003: \0032\002$al\002\003 $pb_a$pb_h \0035\002$ho\002\003";
}
}
}
proc ::wow::init {} {
global wow;
global announcetime;
foreach tmr [timers] {if {[lindex $tmr 1] == "::wow::announce"} {killtimer [lindex $tmr 2]}}
timer $wow(announcetime) ::wow::announce
}
proc ::wow::announce {} {
global wow;
global myqe_dbr;
global myqe_dbm;
global myqe_dbc;
set read [::mysql::sel $myqe_dbc "select `race` FROM `characters` WHERE `online` = 1" -flatlist];
set online [llength $read];
set read [::mysql::sel $myqe_dbr "select `name` FROM `realmlist` WHERE `id` = $wow(realm_id)" -flatlist];
set server_name [lindex $read 0];
foreach chan [channels] {
putserv "PRIVMSG $chan :\0033В королевстве \002$server_name\002 сейчас \002$online\002 персонажей\003"
}
timer $wow(announcetime) ::wow::announce
}
proc wow::topz {n uh h c t} {
if { [channel get $c nopubwow] } return
global myqe_dbr;
global myqe_dbm;
global myqe_dbc;
global wow;
set top_string "";
set read [::mysql::sel $myqe_dbc "select `name` FROM `characters` ORDER BY `totaltime` DESC LIMIT 11" -flatlist];
for {set i 1} {$i<[llength $read]} { incr i } {
set name [lindex $read $i];
set top_string "$top_string\002$i) $name \002";
}
set read [::mysql::sel $myqe_dbr "select `name` FROM `realmlist` WHERE `id` = $wow(realm_id)" -flatlist];
set server_name [lindex $read 0];
foreach chan [channels] {
if { [channel get $c nopubwow] } return
putserv "PRIVMSG $chan :TOP 10 Зомберов реалма: \0033\002$server_name\002\003";
putserv "PRIVMSG $chan :<->: \0033\002$top_string\002\003";
}
}
::wow::init
putlog "wow.tcl loaded"