Explorar o código

cims renames .. namespace fixes, settings saver :)

Paul Klumpp %!s(int64=14) %!d(string=hai) anos
pai
achega
30bba44b1f
Modificáronse 5 ficheiros con 188 adicións e 96 borrados
  1. 81 49
      cims.tcl
  2. 79 23
      cims_admins.tcl
  3. 0 0
      cims_logger.tcl
  4. 0 21
      mnet_conf.tcl
  5. 28 3
      putils.tcl

+ 81 - 49
cims.tcl

@@ -420,7 +420,7 @@ proc ::cims::xmlDefaultCmd {data} {
 
 namespace eval ::cims {
   ## some internal variables for messaging and stuff :) not your business after all.
-  set mnet(version) "mnet 1.013putils"
+  set mnet(version) "cims!1.013putils"
 
   set mnet_max_history 8
 
@@ -539,7 +539,6 @@ proc get_httpfile {host file port} {
 	}
 }
 proc get_localfile {file} {
-	global botnet-nick
 
 	set data ""
 	if {[file isfile "$file"] == 1} {
@@ -556,6 +555,28 @@ proc get_localfile {file} {
 	}
 }
 
+#::cims::write_arraytofile "scripts/cims/$botnick.cims" "mnet_freqs_onoff"
+proc ::cims::write_arraytofile {file arrayname} {
+  variable $arrayname
+
+  set array_string [array get $arrayname]
+  
+  #putlog "array_string: $array_string"
+
+  set fh [open "$file" "w"]
+  puts $fh $array_string
+  close $fh
+}
+#::cims::read_arrayfromfile "scripts/cims/$botnick.cims" "mnet_freqs_onoff" 
+proc ::cims::read_arrayfromfile {file arrayname} {
+  variable $arrayname
+
+  set fh [open "$file" "r"]
+  array set $arrayname [gets $fh]
+  close $fh
+}
+
+
 
 
 proc ::cims::dummy {} {
@@ -1028,37 +1049,36 @@ proc ::cims::enable_frequency {nick mask hand chan text} {
   variable mnet_colors
   variable mnet_freqs 
   variable mnet_freqs_onoff
-  global botnick lastbind
+  global botnick lastbind botnet-nick
 
-	set com $lastbind
-	
-	# validating incoming vars
-	set chan [::cims::proper_channelname $chan]
-	
+  set com $lastbind
 
-	# cutting .prefix_enable down to .prefix
-	set prefix [string range $com 0 [expr [string first _ $com] -1]]
-	#putlog "::cims:: the prefix is $prefix"
+  # validating incoming vars
+  set chan [::cims::proper_channelname $chan]
 
-	set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
-	set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
-	set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
-	set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
 
-	#putlog "network: $network"
-	set allowed [::cims::allowed_channel $network $name $prefix $nick $mask $chan]
-	if {$allowed == 0} {
-		return 0
-	}
-	# now generally allowed.
-	
-	
-	putlog "mnet_freq_status: before $mnet_freqs_onoff($name,$chan)"
-	set mnet_freqs_onoff($name,$chan) 1
-	putlog "mnet_freq_status: now $mnet_freqs_onoff($name,$chan)"
-	
-	::putils::put_local_msg $chan "::cims:: $name _output_ enabled for $chan"
-	
+  # cutting .prefix_enable down to .prefix
+  set prefix [string range $com 0 [expr [string first _ $com] -1]]
+  #putlog "::cims:: the prefix is $prefix"
+
+  set network [join [lindex $mnet_networks_by_prefix($prefix) 0]]
+  set name [join [lindex $mnet_networks_by_prefix($prefix) 1]]
+  set help [join [lindex $mnet_networks_by_prefix($prefix) 2]]
+  set desc [join [lindex $mnet_networks_by_prefix($prefix) 3]]
+
+  #putlog "network: $network"
+  set allowed [::cims::allowed_channel $network $name $prefix $nick $mask $chan]
+  if {$allowed == 0} {
+    return 0
+  }
+  # now generally allowed.
+
+  putlog "mnet_freq_status: before $mnet_freqs_onoff($name,$chan)"
+  set mnet_freqs_onoff($name,$chan) 1
+  putlog "mnet_freq_status: now $mnet_freqs_onoff($name,$chan)"
+
+  ::putils::put_local_msg $chan "::cims:: $name _output_ enabled for $chan"
+
 }
 
 proc ::cims::disable_frequency {nick mask hand chan text} {
@@ -1104,11 +1124,15 @@ proc ::cims::disable_frequency {nick mask hand chan text} {
 
 proc ::cims::toggle_frequency {nick mask hand chan text} {
 # proc triggered by specified $prefix_toggle
-	variable mnet mnet_channels mnet_bots mnet_networks_by_prefix \
-	  mnet_colors \
-	  mnet_freqs mnet_freqs_onoff
-	global botnick lastbind
-	
+  variable mnet 
+  variable mnet_channels 
+  variable mnet_bots 
+  variable mnet_networks_by_prefix 
+  variable mnet_colors
+  variable mnet_freqs 
+  variable mnet_freqs_onoff
+  global botnick lastbind
+
 	set com $lastbind
 
 	# validating incoming vars
@@ -1149,9 +1173,13 @@ proc ::cims::toggle_frequency {nick mask hand chan text} {
 #::cims::enable_color
 proc ::cims::enable_color {nick mask hand chan text} {
 # proc triggered by specified $prefix_enable
-	variable mnet mnet_channels mnet_bots mnet_networks_by_prefix \
-	  mnet_colors_optional mnet_colors_onoff
-	global botnick lastbind
+  variable mnet 
+  variable mnet_channels 
+  variable mnet_bots 
+  variable mnet_networks_by_prefix 
+  variable mnet_colors_optional 
+  variable mnet_colors_onoff
+  global botnick lastbind
 
 	set com $lastbind
 	
@@ -1282,11 +1310,16 @@ proc ::cims::toggle_color {nick mask hand chan text} {
 #::cims::toggle_color
 proc ::cims::status_frequency {nick mask hand chan text} {
 # proc triggered by specified $prefix_toggle
-	variable mnet mnet_channels mnet_bots mnet_networks_by_prefix \
-	  mnet_colors_optional mnet_colors_onoff \
-	  mnet_freqs_onoff \
-	  mnet_reached_users mnet_reached_chans
-	global botnick lastbind
+  variable mnet
+  variable mnet_channels 
+  variable mnet_bots 
+  variable mnet_networks_by_prefix 
+  variable mnet_colors_optional 
+  variable mnet_colors_onoff
+  variable mnet_freqs_onoff
+  variable mnet_reached_users 
+  variable mnet_reached_chans
+  global botnick lastbind
 
 	set com $lastbind
 	
@@ -1313,10 +1346,9 @@ proc ::cims::status_frequency {nick mask hand chan text} {
 	set status_message "$chan $name: "
 	
 	if {$mnet_freqs_onoff($name,$chan) == 1} {
-			append status_message "frequency output is on. "
-		
+		append status_message "frequency output is on. "
 	} else {
-			append status_message "frequency output is off. "
+		append status_message "frequency output is off. "
 	}
 
 	if {$mnet_colors_optional($network) == 1} {
@@ -1610,7 +1642,7 @@ proc ::cims::binds {} {
 }
 bind bot - mnet_receive		::cims::receive_message	
 bind bot - mnet_answer		::cims::receive_answer
-bind dcc m mnet_reload		::cims::dcc_configload
+bind dcc m cims_reload		::cims::dcc_configload
 
 proc ::cims::conf_parsing {} {
   variable mnet_config
@@ -1640,9 +1672,9 @@ proc ::cims::dcc_configload {dummy1 dummy2 dummy3} {
 	::cims::netconfigload
 }
 proc ::cims::netconfigload {} {
-  variable mnet_http_config
-  variable mnet_local_config
-  variable mnet_config
+	variable mnet_http_config
+	variable mnet_local_config
+	variable mnet_config
   variable mnet_num_configs
 
 	putlog "debug:: $mnet_http_config"

+ 79 - 23
mnet_admin.tcl → cims_admins.tcl

@@ -19,7 +19,7 @@
 
 namespace eval ::cims::admin {
   variable admin_channels {"#messagenet" "#quad.dev" "#qwnet"}
-  variable mnet_admin_version "Mnet!1.013namespaced"
+  variable mnet_admin_version "cims!A!1.14namespaced+savesettings"
 
   # include my/our little eggdrop utilities and helper library. ;-) Putils!
   if {[file isfile "scripts/cims/putils.tcl"] == 1} {
@@ -30,6 +30,7 @@ namespace eval ::cims::admin {
 
 
 
+
 # allowcheck for admin commands..
 proc ::cims::admin::allowed_channel {nick mask hand chan admin_channels} {
   global botnick botnet-nick lastbind 
@@ -171,12 +172,15 @@ proc ::cims::admin::has_channelrecord {chan} {
 
 proc ::cims::admin::trylink {nick mask hand chan text} {
   variable admin_channels 
-  variable mnet_admin_version 
-  variable mnet
   global botnet-nick 
 
-	set proper_botnick [::putils::proper_botnick ${botnet-nick}]
-	set botslist [userlist b]
+  set proper_botnick [::putils::proper_botnick ${botnet-nick}]
+  set botslist [userlist b]
+
+  set allowed [::cims::admin::allowed_channel $nick $mask $hand $chan $admin_channels]
+  if {$allowed == 0} {
+    return 0
+  }
 
 	foreach _try_bot $botslist {
 		if {[islinked ${_try_bot}] == 0} {
@@ -195,25 +199,63 @@ proc ::cims::admin::trylink {nick mask hand chan text} {
 
 proc ::cims::admin::trylink_test {_try_bot nick} {
   variable admin_channels 
-  variable mnet_admin_version 
-  variable mnet
   global botnet-nick 
 
-	set proper_botnick [::putils::proper_botnick ${botnet-nick}]
+  set proper_botnick [::putils::proper_botnick ${botnet-nick}]
 
-	if {[islinked ${_try_bot}] == 1} {
-		::putils::put_nick ${nick} "Mnet! \"${proper_botnick}\" \00309succeeded\003 to link to \"${_try_bot}\"! :)"
-	} else {
-		::putils::put_nick ${nick} "Mnet! \"${proper_botnick}\" \00304FAILED\003 to link to \"${_try_bot}\"! :("
-	}
+  if {[islinked ${_try_bot}] == 1} {
+    ::putils::put_nick ${nick} "Mnet! \"${proper_botnick}\" \00309succeeded\003 to link to \"${_try_bot}\"! :)"
+  } else {
+    ::putils::put_nick ${nick} "Mnet! \"${proper_botnick}\" \00304FAILED\003 to link to \"${_try_bot}\"! :("
+  }
+}
+
+
+proc ::cims::admin::savesettings {nick mask hand chan text} {
+  variable admin_channels 
+  global botnet-nick botnick
+  
+  set allowed [::cims::admin::allowed_channel $nick $mask $hand $chan $admin_channels]
+  if {$allowed == 0} {
+    return 0
+  }
+
+  set proper_botnick [::putils::proper_botnick ${botnet-nick}]
+  
+  ::putils::put_nick ${nick} "Mnet! \"${proper_botnick}\" saves settings."
+
+  namespace eval ::cims {
+    set proper_botnick [::putils::proper_botnick ${botnet-nick}]
+    ::putils::write_f_array "scripts/cims/save/${proper_botnick}.cims" [array get mnet_freqs_onoff]
+  }
 }
 
 
+proc ::cims::admin::loadsettings {nick mask hand chan text} {
+  variable admin_channels 
+  global botnet-nick botnick
+  
+  set allowed [::cims::admin::allowed_channel $nick $mask $hand $chan $admin_channels]
+  if {$allowed == 0} {
+    return 0
+  }
+
+  set proper_botnick [::putils::proper_botnick ${botnet-nick}]
+  
+  ::putils::put_nick ${nick} "Mnet! \"${proper_botnick}\" restores settings."
+  
+  namespace eval ::cims {
+    set proper_botnick [::putils::proper_botnick ${botnet-nick}]
+    array set mnet_freqs_onoff [::putils::read_f_array "scripts/cims/save/${proper_botnick}.cims"]
+  }
+}
+
+
+
 proc ::cims::admin::reload {nick mask hand chan text} {
   variable admin_channels 
   global botnet-nick
 
-
     set proper_botnick [::putils::proper_botnick ${botnet-nick}]
 
     set allowed [::cims::admin::allowed_channel $nick $mask $hand $chan $admin_channels]
@@ -224,15 +266,13 @@ proc ::cims::admin::reload {nick mask hand chan text} {
     set cmd "dummy"
     # reload config... be sure this script works or the bot will DIE!
     putlog "mnet! = reloading configs by admin"
-    mnet:dcc_configload ${cmd} ${cmd} ${cmd}
+    ::cims::dcc_configload ${cmd} ${cmd} ${cmd}
     ::putils::put_nick ${nick} "Mnet! \"${proper_botnick}\" Configs reload triggered."
 
 }
 
 proc ::cims::admin::main {nick mask hand chan text} {
   variable admin_channels 
-  variable mnet_admin_version 
-  variable mnet
   global botnet-nick 
 	
 	set proper_botnick [::putils::proper_botnick ${botnet-nick}]
@@ -246,8 +286,8 @@ proc ::cims::admin::main {nick mask hand chan text} {
 	set tmp_value [lindex ${text} 1]
 	
 	
-	set cmd  [string tolower [mnet:kill_spaces ${tmp_cmd}]]
-	set value [string tolower [mnet:kill_spaces ${tmp_value}]]
+	set cmd  [string tolower [::putils::kill_spaces ${tmp_cmd}]]
+	set value [string tolower [::putils::kill_spaces ${tmp_value}]]
 	
 	if {${cmd} == "add"} {
 	
@@ -311,6 +351,19 @@ proc ::cims::admin::main {nick mask hand chan text} {
 		::cims::admin::rehash $nick $mask $hand $chan $text
 		return 0
 	}
+	
+	if {${cmd} == "savesettings"} {
+		# savesettings
+		::cims::admin::savesettings $nick $mask $hand $chan $text
+		return 0
+	}
+
+	if {${cmd} == "loadsettings"} {
+		# loadsettings
+		::cims::admin::loadsettings $nick $mask $hand $chan $text
+		return 0
+	}
+
 
 	if {${cmd} == "version"} {
 		# tells version
@@ -320,7 +373,7 @@ proc ::cims::admin::main {nick mask hand chan text} {
 
 		
 	# none of the above worked .. so we are here:
-	::putils::put_nick ${nick} "mnet! possible commands are: add remove reload channels rehash version"
+	::putils::put_nick ${nick} "mnet! possible commands are: add remove reload channels rehash version savesettings loadsettings"
 	::putils::put_nick ${nick} "mnet! use either \002!mnet_botnetnickname <command>\002 to admin a single bot or just \002!mnet_<command>\002 to admin ALL bots that listen to your words here."
 	::putils::put_nick ${nick} "add #channelname       || bot joins a channel"
 	::putils::put_nick ${nick} "remove #channelname    || bot parts a channel"
@@ -328,9 +381,8 @@ proc ::cims::admin::main {nick mask hand chan text} {
 	::putils::put_nick ${nick} "channels               || tells some channel-infos"
 	::putils::put_nick ${nick} "rehash                 || rehashes the bot, reloads all botscripts"
 	::putils::put_nick ${nick} "version                || tells version"
-	
-
-	
+	::putils::put_nick ${nick} "savesettings           || saves channel output settings to file"
+	::putils::put_nick ${nick} "loadsettings           || restores channel output settings from file"
 }
 
 
@@ -346,6 +398,9 @@ proc ::cims::admin::bindings {} {
   bind pub - !mnet_rehash            ::cims::admin::rehash
   bind pub - !mnet_version           ::cims::admin::version
   bind pub - !mnet_trylink           ::cims::admin::trylink
+  bind pub - !mnet_savesettings      ::cims::admin::savesettings
+  bind pub - !mnet_loadsettings      ::cims::admin::loadsettings
+  
 
   putlog "mnet! = mnet adminscript loaded: $mnet_admin_version"
 }
@@ -358,3 +413,4 @@ namespace eval ::cims::admin {
 
 
 
+

+ 0 - 0
mnet_logger.tcl → cims_logger.tcl


+ 0 - 21
mnet_conf.tcl

@@ -1,21 +0,0 @@
-############# CONFIG SECTION ##############
-### the real config section is here... 
-# for xml parsing you need the tclxml package.. and for the tclxml package you need the tcllib for
-# uri parsing :) 
-
-# BE SURE TO NOT DEFINE TWO NETS OVERLAPPING THEMSELVES (<mnet sig="xxx"> must be unique!)
-# mnet_http_config(x) works like this:
-#			 HOST               DIRECTORY         PORT
-#lappend mnet_http_config "quadaver.mine.nu" "/qw-serveme/qwnet.cfg" "80"
-#lappend mnet_http_config "quad.netdome.biz" "/aq2/aq2net.cfg" "80"
-lappend mnet_http_config "quad.netdome.biz" "/aq2/devnet.cfg" "80"
-#lappend mnet_http_config "quad.netdome.biz" "/aq2/quadnet.cfg" "80"
-
-# mnet_local_config(y) just points to a local file (the basepath is the eggdrop-binary-path)
-#lappend mnet_local_config "./scripts/mnet/anothernet.cfg"
-
-# at which interval should it re-check for a changed config? 300 recommended (5 hours)
-# must be at least 90 or 0 for off.
-set mnet_cfg_reload_interval 300
-########## END OF CONFIG SECTION ##############
-

+ 28 - 3
putils.tcl

@@ -5,13 +5,18 @@
 namespace eval ::putils {
   ## some internal variables for messaging and stuff :) not your business after all.
 
+  set local_ver "0.3"
+
+
   # if putils-variable (thus, putils!) is already loaded, then .. well .. load again, but, this time, quietly. ;-)
   if {![info exists putils]} {
-    putlog "::putils:: paul utils for eggdrop bots in tcl $putils(version) loading..."
+    set putils(version) $local_ver
+    putlog "::putils:: paul's utils for eggdrop bots in tcl - $putils(version) - loading..."
   }
-  
+
   # set again .. perhaps we changed version while in development ;) - even while putils was already loaded.
-  set putils(version) "0.3"
+  set putils(version) $local_ver
+  
 }
 
 
@@ -124,4 +129,24 @@ proc ::putils::botonchannel {chan} {
   }
 }
 
+proc ::putils::write_f_array {file thearraylist} {
+  array set myinternalarray $thearraylist
+  
+  set array_string [array get myinternalarray]
+  
+  set fh [open "$file" "w"]
+  puts $fh $array_string
+  close $fh
+}
+
+proc ::putils::read_f_array {file} {
+  set fh [open "$file" "r"]
+  array set myinternalarray [gets $fh]
+  close $fh
+
+  return [array get myinternalarray]
+}
+
+
+
 return 1