This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

regexp help

Help for those learning Tcl or writing their own scripts.
Post Reply
T
TEK7
Voice
Posts: 10
Joined: Sat Apr 10, 2010 10:49 am

regexp help

Post by TEK7 »

hello,
This part of my script doesn't work :/ i need help, i'm not scripter :c

Code: Select all

bind rcon - * rconm

bind pub o|o .m rconm
proc rconm {nickname ident handle channel argument} {
  global rhost rport my-ip
  global matchchan

  getrconlog

if {[regexp {\"(.+)\" committed suicide with \"(.+)\"} nk1 txt]} {  
    putquick "PRIVMSG $channel :$nk1 committed suicide with $txt"
    
  }
}
i want, when i suicide on server de bot sends on irc "committed suicide with" but without bind ".m" i want like a loop.

This is my all script.

Code: Select all

bind msgm -|- ** pvt

proc pvt {mad7684 mad8594 mad873 mad8954} {
     global rhost rport rconpass challenge
     set response [myrcon "say $mad7684: $mad8954"]
}

# Server ip address/hostname
set rhost "82.102.28.104"

# Server port
set rport "27100"

# Rcon password
set rconpass "xxxx"

set matchchan "#sadklaskdl"


set challenge [challengercon $rhost $rport]

bind rcon - * rconm

bind pub o|o .m rconm
proc rconm {nickname ident handle channel argument} {
  global rhost rport my-ip
  global matchchan

  getrconlog

if {[regexp {\"(.+)\" committed suicide with \"(.+)\"} nk1 txt]} {  
    putquick "PRIVMSG $channel :$nk1 $txt"
    
  }
}


bind pub o|o .map rconmap
proc rconmap {nickname ident handle channel argument } {
  global rhost rport rconpass challenge

  if {$argument == ""} {
    putserv "PRIVMSG $channel :Syntax: .map <map>"
  } else {
    set response [myrcon "changelevel $argument"]
    putserv "PRIVMSG $channel :$response"
  }

  return 1
}

bind pub o|o .rr res
proc res {nickname ident handle channel argument } {
  global rhost rport rconpass challenge

if {$argument == ""} {
    set response [myrcon "sv_restart 1"]
    putserv "PRIVMSG $channel :$response"
  }

  return 1
}

bind pub o|o .live live
proc live {nickname ident handle channel argument } {
  global rhost rport rconpass challenge

if {$argument == ""} {
    
    set response [myrcon "sv_restart 1"]
    after 1000 
    set response [myrcon "sv_restart 1"]
    after 1000
    set response [myrcon "sv_restart 3"]
    after 3000 
    set response [myrcon "say LIVE LIVE LIVE - GL & HF"]
    set response [myrcon "say LIVE LIVE LIVE - GL & HF"]
    set response [myrcon "say LIVE LIVE LIVE - GL & HF"]
    putserv "PRIVMSG $channel :$response"
  }

  return 1
}


proc myrcon {mycmd} {
  global rhost rport rconpass challenge

  set response [rcon $rhost $rport $challenge "$rconpass" $mycmd]

  if {[regexp {Bad challenge.} $response all] || [regexp {No challenge for your address.} $response all]} {
      set challenge [challengercon $rhost $rport]
      set response [rcon $rhost $rport $challenge "$rconpass" $mycmd]
  }

  return $response
}

proc getrconlog {} {
    global rhost rport challenge my-ip rcon-listen-port rconpass
    set response [myrcon "logaddress ${my-ip} ${rcon-listen-port}"]
}
sorry my bad english :/
thanks :)
n
nml375
Revered One
Posts: 2860
Joined: Fri Aug 04, 2006 2:09 pm

Post by nml375 »

The syntax for regexp is as follows

Code: Select all

regexp ?switches? exp string ?matchVar? ?subMatchVar subMatchVar ...?
First off, you don't supply any text to be searched to your regexp command. Secondly, the first match-variable (if supplied) contains the whole part of the string that matches the pattern, the second match-variable contains the first sub-expression that matched, third match-variable the second sub-expression, and so on...
Third, since you've already placed your pattern within brackets, there's no need to escape characters from being substituted or such.. don't escape quotes (")

Your regexp should look something along these lines, though you'll have to fill the source-variable with something first (the actual text you're searching).

Code: Select all

...
if {[regexp {"(.+)" committed suicide with "(.+)"} $source match nk1 txt]} {
...
Next, I see you have two different bindings that both call the rconm proc. Unfortunately, these (rcon and pub) do not have matching argument lists, so this will not work.

As for continuous checking, either use the time or cron bindings, or iterative timers (start a new timer for your function at the end of the function).
Obviously, you'll have to adjust the argument list of your procs accordingly to your choice of invocation.
NML_375
T
TEK7
Voice
Posts: 10
Joined: Sat Apr 10, 2010 10:49 am

Post by TEK7 »

I can't do that :/, 'im not scripter, i need that bot reads the console of my hlserver, and compare that string, and if match to say to channel. Can you help me?

Thanks

The original script is this, but that part of script doenst work :/ and i need some help to fix them. I use rcon mod.

Code: Select all

# Server ip address/hostname
set rhost "counterstrike.server.com"

# Server port
set rport "27015"

# Rcon password
set rconpass "blah"


#################################################
## Shouldn't need to change anything down here ##
#################################################

set matchchan ""
set challenge [challengercon $rhost $rport]
set mb_teamsay 1
set mb_say 1
set mb_maxnamelength 15

array set kills {}
array set deaths {}


bind rcon - * rconmsg

proc rconmsg {msg} {
  global rhost rport my-ip
  global mb_teamsay mb_say matchchan

  regexp {log L [^ ]+ - [0-9]{2}:[0-9]{2}:[0-9]{2}: (.+)} $msg orig msg

#  putlog $msg

  if {[regexp {\"(.+)\" attacked \"(.+)\" with \"(.+)\" \(damage \"([0-9]+)\"\) \(damage_armor \"([0-9]+)\"\) \(health \"(.+)\"\) \(armor \"([0-9]+)\"\)} $msg all nk1 nk2 gun damage damage_armor health armor]} {
    # do nothing. ignore.
  } elseif { [regexp {^Rcon: .+$} $msg] } {
      if {[regexp {Rcon: \"rcon .+ logaddress (.+) (.+)\" from \"(.+)\"} $msg all loghost logport address] && $loghost != ${my-ip}} {
          if {$matchchan == ""} {
              putrconchan "Uh oh...logaddress was changed to $loghost $logport by $address..."
          } else {
              putrconchan "Uh oh...logaddress was changed to $loghost $logport by $address...getting it back"
              getrconlog
          }
      } else {
          putlog $msg
      }
  } elseif { [regexp {^Server cvars .+$} $msg] } {
    putlog $msg
  } elseif { [regexp {^Server cvar .+$} $msg] } {
    putlog $msg
  } elseif { [regexp {^Log file .+$} $msg] } {
    putlog $msg
  } elseif { [regexp {^\[ADMIN\] .+$} $msg] } {
    putlog $msg
  } elseif { [regexp {^\[META\] .+$} $msg] } {
    putlog $msg
  } elseif { [regexp {^Server say \"(.+)\"} $msg all s] } {
    putrconchan "\002Server\002: $s"
  } elseif { [regexp {^World triggered \"(.+)\"} $msg all txt] } {
    if {[string compare $txt "Round_End"] == 0} {
    } elseif {[string compare $txt "Round_Start"] == 0} {
      putrconchan "$msg"
    } else {
      putrconchan "$msg"
    }
 } elseif { [regexp {^Team \"(.+)\" scored \"(.+)\" with \"(.+)\" players} $msg all team score players] } {
    putrconchan "\002$team score:\002 $score"
    resetkills
    resetdeaths
 } elseif { [regexp {^Team \"(.+)\" triggered \"(.+)\" \(CT \"([0-9]+)\"\) \(T \"([0-9]+)\"\)} $msg all team txt scorect scoret] } {
    putrconchan "$msg"
  } elseif {[regexp {\"(.+)\" killed \"(.+)\" with \"(.+)\"} $msg all nk1 nk2 gun]} {
   
    set sid1 [serverid $nk1]
    set sid2 [serverid $nk2]
    
    # team kill
    if {[team $nk1] == [team $nk2]} {
      updatekills $sid1  -1
      updatedeaths $sid2 1
    } else { # regular kill
      updatekills $sid1 1
      updatedeaths $sid2 1
    }
    
    putrconchan "[parsename $nk1] killed [parsename $nk2] with \00303$gun\003"
  } elseif {[regexp {\"(.+)\" say \"(.+)\"(.*)} $msg all nk1 txt dead]} {
    if {$mb_say} {
      if {[string compare $dead " (dead)"] == 0} {
        putrconchan "*DEAD*[parsename $nk1]: \00303$txt\003"
      } else {
        putrconchan "[parsename $nk1]: \00303$txt\003"
      }
    }
  } elseif {[regexp {\"(.+)\" say_team \"(.+)\"(.*)} $msg all nk1 txt dead]} {
    if {$mb_teamsay} {
      if {[string compare $dead " (dead)"] == 0} {
        putrconchan "*DEAD*[parsename $nk1] (team): \00303$txt\003"
      } else {
        putrconchan "[parsename $nk1] (team): \00303$txt\003"
      }
    }
  } elseif {[regexp {\"(.+)\" changed name to \"(.+)\"} $msg all nk1 nk2]} {
    putrconchan "[parsename $nk1] changed name to $nk2"
  } elseif {[regexp {\"(.+)\" triggered \"(.+)\"} $msg all nk1 txt]} {
    if {[string compare $txt "Begin_Bomb_Defuse_With_Kit"] == 0} {
      putrconchan "[parsename $nk1] is defusing the bomb with a kit"
    } elseif {[string compare $txt "Begin_Bomb_Defuse_Without_Kit"] == 0} {
      putrconchan "[parsename $nk1] is defusing the bomb without a kit"
    } elseif {[string compare $txt "Planted_The_Bomb"] == 0} {
      putrconchan "[parsename $nk1] planted the bomb"
    } elseif {[string compare $txt "Got_The_Bomb"] == 0} {
      putrconchan "[parsename $nk1] got the bomb"
    } elseif {[string compare $txt "Dropped_The_Bomb"] == 0} {
      putrconchan "[parsename $nk1] dropped the bomb"
    } elseif {[string compare $txt "Spawned_With_The_Bomb"] == 0} {
      putrconchan "[parsename $nk1] has the bomb"
    } elseif {[string compare $txt "Defused_The_Bomb"] == 0} {
      putrconchan "[parsename $nk1] defused the bomb!"
    } else {
      putrconchan "[parsename $nk1] triggered $txt"
    }
  } elseif {[regexp {\"(.+)\" committed suicide with \"(.+)\"} $msg all nk1 txt]} {  
    set sid1 [serverid $nk1]
    
    updatedeaths $sid1 1
    
    putrconchan "[parsename $nk1] committed suicide with $txt"
  } elseif {[regexp {\"(.+)\" joined team \"(.+)\"} $msg all nk1 newteam]} {
    putrconchan "\002[parsename $nk1]\002 joined the $newteam team"
  } elseif {[regexp {\"(.+)\" disconnected} $msg all nk1]} {
    putrconchan "[parsename $nk1] disconnected"
  } elseif {[regexp {\"(.+)\" connected, address \"(.+)\"} $msg all nk1 address]} {
    putrconchan "\002[parsename $nk1]\002 <$address> connected"
  } elseif {[regexp {\"(.+)\" entered the game} $msg all nk1]} {
    updatekills [serverid $nk1] 0
    updatedeaths [serverid $nk1] 0
    putrconchan "\002[parsename $nk1]\002 entered the game"
  } elseif {[regexp {Loading map \"(.+)\"} $msg all map]} {
    putrconchan "Loading map: $map"
  } elseif { [regexp {^Bad Rcon: .+$} $msg] } {
    putlog $msg
  } else {
    putrconchan $msg
    putlog "Unknown: $msg"
  }
}

proc parsename {name} {
  global kills deaths mb_maxnamelength
  
  if {[regexp {(.+)<([0-9]+)><[0-9]+><([A-Z]*)>} $name all nk sid team]} {
    if {[string compare $team "TERRORIST"] == 0} {
      return [format "\00304%-${mb_maxnamelength}.${mb_maxnamelength}s\003 \[%-2d/%2d\]" $nk [getkills $sid] [getdeaths $sid]]
    } elseif {[string compare $team "CT"] == 0} {
      return [format "\00312%-${mb_maxnamelength}.${mb_maxnamelength}s\003 \[%-2d/%2d\]" $nk [getkills $sid] [getdeaths $sid]]
    } else {
      return "$nk"
    }
  } else {
    return $name
  }
}

proc team {name} {
  if {[regexp {.+<[0-9]+><[0-9]+><([A-Z]*)>} $name all team]} {
    return $team
  } else {
    return ""
  }
}


proc serverid {name} {
  if {[regexp {.+<([0-9]+)><[0-9]+><[A-Z]*>} $name all serverid]} {
    return $serverid
  } else {
    return "0"
  }
}

proc getrconlog {} {
    global rhost rport challenge my-ip rcon-listen-port rconpass
    set response [myrcon "logaddress ${my-ip} ${rcon-listen-port}"]
}

proc putrconchan {msg} {
  global matchchan

  dccputchan 1 $msg

  if {$matchchan != ""} {
    putquick "PRIVMSG $matchchan :$msg"
  }
  
}

proc updatekills {sid incr} {
  global kills
  
  if {$incr == 0} {
    set kills($sid) 0
  } elseif {[info exists kills($sid)]} {
    incr kills($sid) $incr
  } else {
    set kills($sid) $incr
  }
}

proc resetkills {} {
  global kills

  array unset kills  
}

proc getkills {sid} {
  global kills

  if {[info exists kills($sid)]} {
    return $kills($sid)
  } else {
    return 0
  }
}

proc updatedeaths {sid incr} {
  global deaths
  
  if {$incr == 0} {
    set deaths($sid) 0
  } elseif {[info exists deaths($sid)]} {
    incr deaths($sid) $incr
  } else {
    set deaths($sid) $incr
  }
}

proc resetdeaths {} {
  global deaths

  array unset deaths
}

proc getdeaths {sid} {
  global deaths

  if {[info exists deaths($sid)]} {
    return $deaths($sid)
  } else {
    return 0
  }
}

proc matchbot {nickname ident handle channel argument } {
  global matchchan rhost rport challenge rconpass rcon-listen-port my-ip
  global mb_say mb_teamsay mb_maxnamelength

  set cmd [lindex $argument 0]
  set args [lrange $argument 1 end]

  resetkills
  resetdeaths

  if {$cmd == "stop"} {
    clearqueue help
    putquick "PRIVMSG $channel :Stopped matchbot"
    set matchchan ""
  } elseif {$cmd == "start"} {
    if {$args != ""} {
        set matchchan $args
    } else {
        set matchchan $channel
    }

    getrconlog
    putquick "PRIVMSG $channel :Starting matchbot in \"$matchchan\""
    putquick "PRIVMSG $channel :Parameters: (say $mb_say) (teamsay $mb_teamsay) (maxnamelength $mb_maxnamelength)"
  } elseif {$cmd == "set"} {
    set var [lindex $args 0]
    set val [lindex $args 1]

    if {$var == "say"} {
      if {$val == ""} {
        putquick "PRIVMSG $channel :mm1 display is set to $mb_say"
      } else {
        if {$val == "1" || $val == "on"} {
          set mb_say 1
        } else {
          set mb_say 0
        }

        putquick "PRIVMSG $channel :mm1 display was changed to $mb_say"
      }

    } elseif {$var == "teamsay"} {
      if {$val == ""} {
        putquick "PRIVMSG $channel :say_team display is set to $mb_teamsay"
      } else {
        if {$val == "1" || $val == "on"} {
          set mb_teamsay 1
        } else {
          set mb_teamsay 0
        }

        putquick "PRIVMSG $channel :say_team display was changed to $mb_teamsay"
      }

    } elseif {$var == "maxnamelength"} {
      if {$val == "" || ![string is integer $val]} {
        putquick "PRIVMSG $channel :Max name length is set to $mb_maxnamelength"
      } else {
        set mb_maxnamelength $val

        putquick "PRIVMSG $channel :Max name length was changed to $mb_maxnamelength"
      }
    } else {
      putserv "NOTICE $nickname :Syntax: @matchbot set <cmd> \[on|off|value\]"
      putserv "NOTICE $nickname :Commands:"
      putserv "NOTICE $nickname :  maxnamelength \[#\]  :: Sets the max name length to \002\#\002, for display purposes"
      putserv "NOTICE $nickname :  say \[on|off\]  :: Sets the display of message mode 1 data \002on\002 or \002off\002"
      putserv "NOTICE $nickname :  teamsay \[on|off\]  :: Sets the display of message mode 2 data (team_say) \002on\002 or \002off\002"
    }

  } else {
    putserv "NOTICE $nickname :ki server matchbot syntax:"
    putserv "NOTICE $nickname :@matchbot start \[target\]  ::  Starts a matchbot in \002target\002, or the current channel if \002target\002 is not specified"
    putserv "NOTICE $nickname :@matchbot stop  ::  Stops matchbot"
    putserv "NOTICE $nickname :@matchbot set <parameter> \[value\]   ::  Sets or displays matchbot parameters :: \002@matchbot set\002 for more info"
  }


  return 1
}

bind pub o|o @matchbot matchbot


proc rconsay {nickname ident handle channel argument } {
  global rhost rport rconpass challenge

  if {$argument == ""} {
    putserv "PRIVMSG $channel :Syntax: @say <text>"
  } else {
    set response [myrcon "say $argument"]
    putserv "PRIVMSG $channel :$response"
  }

  return 1
}

bind pub o|o @say rconsay

proc rconmap {nickname ident handle channel argument } {
  global rhost rport rconpass challenge

  if {$argument == ""} {
    putserv "PRIVMSG $channel :Syntax: @map <map>"
  } else {
    set response [myrcon "changelevel $argument"]
    putserv "PRIVMSG $channel :$response"
  }

  return 1
}

bind pub o|o @map rconmap

proc rconexec {nickname ident handle channel argument } {
  global rhost rport rconpass challenge
  if {$argument == ""} {
    putserv "PRIVMSG $channel :Syntax: @rcon <cmd>"
  } else {
    set response [myrcon $argument]
    putserv "PRIVMSG $channel :$response"
  }

  return 1
}

bind pub o|o @rcon rconexec

bind pub o|o @challenge rconchallenge

proc rconchallenge {nickname ident handle channel argument } {
      global rhost rport challenge
      set challenge [challengercon $rhost $rport]
      putserv "PRIVMSG $channel :Challenge received"
}

proc myrcon {mycmd} {
  global rhost rport rconpass challenge

  set response [rcon $rhost $rport $challenge "$rconpass" $mycmd]

  if {[regexp {Bad challenge.} $response all] || [regexp {No challenge for your address.} $response all]} {
      set challenge [challengercon $rhost $rport]
      set response [rcon $rhost $rport $challenge "$rconpass" $mycmd]
  }

  return $response
}
T
TEK7
Voice
Posts: 10
Joined: Sat Apr 10, 2010 10:49 am

Post by TEK7 »

The rcon dcc connection isn't work. And the bot can't recieve logadress

Code: Select all

SOCK ADDR     PORT  NICK      HOST              TYPE
---- -------- ----- --------- ----------------- ----
3    00000000     0 (dns)                       dns   (ready)
4    00000000     0 (rcon)                      rcon   (ready)
6    C0A80102  2727 (telnet)  *                 lstn  2727
8    55EC6EE2  6667 (server)  uk.quakenet.org   serv  (lag: 0)
9    7F000001 56371 crashers- telnet@localhost  chat  flags: cpTEp/0
Post Reply