mIRC Home    About    Download    Register    News    Help

Print Thread
#179497 23/06/07 07:00 PM
Joined: Feb 2007
Posts: 75
T
Babel fish
OP Offline
Babel fish
T
Joined: Feb 2007
Posts: 75
I seem to be stumped on how to create and manange multiple sockets for my MUD client script. I really want to be able to play more than one MUD at a time with it.

Basically what I need is a method to create, read and write for each socket I create and general management like loss of connection on one of them. Any help in this would be apprechiated smile

Anyway here is the link to the script here

Thanks smile


GigIRC Network Admin
irc.gigirc.com
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Use the sockopen command to open a socket using the address variable as the socket name rather than a fixed socket name. This will let you open a socket based on the address chosen from your dialog. You're still limited to one connection to each MUD address, but I think that's what you're wanting. If not, then include in the socket name a number that increments with each new connection to the given MUD.

EDIT: Also, when you create your MUDClient window, name the window based on the address. You can then use the window name to know which socket to access for your sockwrite/sockread commands.

Last edited by Riamus2; 23/06/07 07:14 PM.

Invision Support
#Invision on irc.irchighway.net
Joined: Feb 2007
Posts: 75
T
Babel fish
OP Offline
Babel fish
T
Joined: Feb 2007
Posts: 75
That is exactly what I want, don't want to create something you could use to cheat in MUD'S wink

Could you maybe create a example script demostrating how that can be done? It doesn't have to run or anything, just want to see how it would look in code.

Thanks smile


GigIRC Network Admin
irc.gigirc.com
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
I'm not at home, but here's something quick that may get you started. I'm only showing part of your script to get you started. If you need more after I'm home, I'll do more.

Code:
on *:dialog:MUDclient:sclick:4: {
  %mud.MUDclient.addy = $did(1).text
  %mud.MUDclient.port = $did(3).text
  %mud.MUDclient.info $1-
  sockopen MUDclient- $+ $did(1).text $did(1).text $did(3).text
  window -HexSl12k[9] +bestxn @MUDclient- $+ $did(1).text Fixedsys 9
  var %i = $lines($scriptdir\MUDclienttab.cfg)
  var %b = 1
  while %b < %i {
    %gimme = $read($scriptdir\MUDclienttab.cfg,%b)
    iline -ln @MUDclient- $+ $did(1).text %b %gimme
    inc %b
  }
  echo 7 -m @MUDclient- $+ $did(1).text Connecting to $did(1).text on port $did(3).text
  if ($sock(MUDclient- $+ $did(1).text).status == active) { echo 7 -m @MUDclient- $+ $did(1).text Already Connected }
}


Code:
on *:input:@: {
  if (@MUDclient* iswm $active) {
    var %MUDclient = $remove($active,@)
    if ($left($1-,1) == /) { if $1 == /s { sockwrite -nt %MUDclient /s | halt }
      if $1 == /h { sockwrite -nt %MUDclient /h | halt }
      if $1 == /r { sockwrite -nt %MUDclient $cr | halt }
      if $1 == /lock { if (!%saymode && $2) { echo 7 -m @ $+ %MUDclient CommandLock ON | %saymode = $2 | halt }


Code:
on *:sockread:*: {
  if (MUDclient* !iswm $dname) { return }
  var %MUDclient = $dname
  :nextread
  if ($sockerr > 0) { echo 4 -m @ $+ %MUDclient Connection to $remove(%MUDclient,MUDclient-) Lost | return }


Note in the last line that I changed it so that it isn't using the address variable. That is because your address variable will change if you connect to more MUDs. By setting the variable based on the socket or @window, it will not matter how many MUDs are open.


Invision Support
#Invision on irc.irchighway.net
Joined: Jul 2006
Posts: 3,962
W
Hoopy frood
Offline
Hoopy frood
W
Joined: Jul 2006
Posts: 3,962
Are you sure $dname return dialog name in on sockread event ? $dname only return dialog name in a on dialog event.


#mircscripting @ irc.swiftirc.net == the best mIRC help channel
Joined: Feb 2007
Posts: 75
T
Babel fish
OP Offline
Babel fish
T
Joined: Feb 2007
Posts: 75
Thanks, but I think I can managed, and the current one doesn't seem to give too much trouble.

Only thing I noticed was that you used $dname instead of $sockname in your example, but I worked it out.

Here is the full script if you want to check for errors:
Code:
;=====
;Menus
;=====
menu status,channel {
  MUDclient
  .Connect:dialog -ma MUDclient MUDclient
  .Autologin:dialog -m Autologin Autologin
}

menu @MUDclient* {
  Connect:dialog -m MUDclient MUDclient
  Autologin:dialog -m Autologin Autologin
  Disconnect:closemud
  -
  Clear Buffer:clear @MUDclient
}

;=======
;Dialogs
;=======
dialog MUDclient {
  title "MUDclient"
  size -1 -1 200 135
  edit "mud.wormhole.se", 1, 5 25 190 20, autohs
  text "Port:", 2, 6 47 50 20
  edit "4000", 3, 5 65 190 20, autohs
  button "Connect", 4, 5 95 60 30, ok
  button "Cancel", 5, 135 95 60 30, cancel
  box "Remote Host:", 6, 0 1 200 135
}

dialog Autologin {
  title "Autologin"
  size -1 -1 200 135
  edit %mud.name, 1, 5 25 190 20, autohs
  text "Password:", 2, 6 47 50 20
  edit %mud.password, 3, 5 65 190 20, autohs
  button "OK", 4, 5 95 60 30, ok
  button "Cancel", 5, 135 95 60 30, cancel
  box "Name:", 6, 0 1 200 135
}

on *:dialog:Autologin:sclick:4: {
  %mud.name = $did(1).text
  %mud.password = $did(3).text
}

on *:dialog:MUDclient:sclick:4: {
  %mud.MUDclient.addy = $did(1).text
  %mud.MUDclient.port = $did(3).text
  %mud.MUDclient.info $1-
  sockopen MUDclient- $+ $did(1).text $did(1).text $did(3).text
  window -HexSl12k[9] +bestxn @MUDclient- $+ $did(1).text Fixedsys 9
  var %i = $lines($scriptdir\MUDclienttab.cfg)
  var %b = 1
  while %b < %i {
    %gimme = $read($scriptdir\MUDclienttab.cfg,%b)
    iline -ln @MUDclient- $+ $did(1).text %b %gimme
    inc %b
  }
  echo 7 -m @MUDclient- $+ $did(1).text Connecting to $did(1).text on port $did(3).text
  if ($sock(MUDclient- $+ $did(1).text).status == active) { echo 7 -m @MUDclient- $+ $did(1).text Already Connected }
}

;===============
;Opening Routine
;===============
on *:sockopen:MUDclient*: {
  if ($color(background) == 0 || $color(background) == 15) {
    %colour = 1
    %mud.bn = 99,01
    %mud.bn2 = 01,00
    %mud.br = 99,04
    %mud.br2 = 00,04
    %mud.bg = 99,03
    %mud.bg2 = 00,03
    %mud.by = 99,08
    %mud.by2 = 00,07
    %mud.bb = 99,02
    %mud.bb2 = 00,02
    %mud.bm = 99,13
    %mud.bm2 = 00,06
    %mud.bc = 99,10
    %mud.bc2 = 00,12
    %mud.bw = 99,15
    %mud.bw2 = 00,01
  }
  else {
    %colour = 15
    %mud.bn = 99,01
    %mud.bn2 = 15,01
    %mud.bw = 99,15
    %mud.bw2 = 01,15
  }
  if ($sockerr > 0) { echo 4 -m @MUDclient- $+ %mud.MUDclient.addy Cannot Connect to %mud.MUDclient.addy | return }
  else { echo 7 -m @MUDclient- $+ %mud.MUDclient.addy Connection Opened to %mud.MUDclient.addy
    if ((%mud.name != $null) && (mud.password != $null)) { sockwrite -nt @MUDclient- $+ %mud.MUDclient.addy %mud.name
      sockwrite -nt @MUDclient- $+ %mud.MUDclient.addy %mud.password
    }
  }
}

;================
;Input Processing
;================
on *:input:@: {
  if (@MUDclient* iswm $active) {
    var %MUDclient = $remove($active,@)
    var %MUDclient2 = $active
    if ($left($1-,1) == /) { if $1 == /s { sockwrite -nt %MUDclient /s | halt }
      if $1 == /h { sockwrite -nt %MUDclient /h | halt }
      if $1 == /r { sockwrite -nt %MUDclient $cr | halt }
      if $1 == /lock { if (!%saymode && $2) { echo 7 -m %MUDclient2 CommandLock ON | %saymode = $2 | halt }
        else { echo 7 -m %MUDclient2 CommandLock OFF | unset %saymode | halt }
      }
      if $1 == /fw { var %mud_cnt = 1,%mud_total = $len($1)
        while (%mud_cnt <= %mud_total) {
          if ($mid($1,%mud_cnt,1) isnum) {
            var %mud_number = $iif(%mud_number,%mud_number $+ $mid($1,%mud_cnt,1),$mid($1,%mud_cnt,1))
          }
          else var %mud_direction = $mid($1,%mud_cnt,1)
          inc %mud_cnt
          if (%mud_direction) {
            if (!%mud_number) { var %mud_number = 1 }
            while (%mud_number) {
              sockwrite -nt %MUDclient %mud_direction
              dec %mud_number
            }
            unset %mud_number %mud_direction
          }
        }
        halt
      }
      else { return }
    }
    if ($1 == greet || $1 == tell || $1 == whisper || $1 == follow) { if ($2) { aline -ln $2 } }
    if ($sock(%MUDclient).status == $null) { echo 4 -m %MUDclient2 Not Connected | halt }
    else { if (%saymode) { sockwrite -nt %MUDclient %saymode $1- }
      else { sockwrite -nt %MUDclient $1- }
    }
    if (%mud.name != $null) { echo %colour -mi1 %MUDclient2 4[ $+ %mud.name $+ 4] $1- }
    else { echo %colour -mi1 %MUDclient2 4[ $+ $nick $+ 4] $1- }
    halt
  }
}

;===========================================
;Reading, Processing and Outputting Routines
;===========================================
on *:sockread:*: {
  if (MUDclient* !iswm $sockname) { return }
  var %MUDclient = $sockname
  var %MUDclient2 = @ $+ %MUDclient
  :nextread
  if ($sockerr > 0) { echo 4 -m %MUDclient2 Connection to $remove(%MUDclient,MUDclient-) Lost | return }
  else {
    sockread -nf %mud.info
    if ($sockbr == 0) { return }
    if (!%mud.info) { %mud.info = $chr(160) }
    if ( isin %mud.info) { %mud.info = $remove(%mud.info,) }
    if ( isin %mud.info) { %mud.info = $remove(%mud.info,) }
    if ( isin %mud.info) { %mud.info = $remove(%mud.info,) }
    if ( isin %mud.info) { %mud.info = $remove(%mud.info,) }
    if ( isin %mud.info) { %mud.info = $remove(%mud.info,) }
    if ( isin %mud.info) { %mud.info = $remove(%mud.info,) }
    if ( isin %mud.info) { %mud.info = $remove(%mud.info,) }
    if ( isin %mud.info) { %mud.info = $remove(%mud.info,) }
    if ( isin %mud.info) { %mud.info = $remove(%mud.info,) }
    if ( isin %mud.info) { %mud.info = $remove(%mud.info,) }
    if ( isin %mud.info) { %mud.info = $remove(%mud.info,) }
    if ( isin %mud.info) { %mud.info = $remove(%mud.info,) }
    if ( isin %mud.info) { %mud.info = $remove(%mud.info,) }
    if ( isin %mud.info) { %mud.info = $remove(%mud.info,) }

    %mud.info2 = $ansi2mirc(%mud.info)
    if (%space == $chr(160) && !%mud.info2) { unset %space | goto nextread }
    if (!%mud.info2) { %mud.info2 = $chr(160) }
    if (%colour = 1) { %mud.info2 = $replace(%mud.info2,08,07,13,06,15,14,09,03,11,12,00,01)
      %mud.info2 = $replace(%mud.info2,%mud.bn,%mud.bn2,%mud.br,%mud.br2,%mud.bg,%mud.bg2,%mud.by,%mud.by2,%mud.bb,%mud.bb2,%mud.bm,%mud.bm2,%mud.bc,%mud.bc2,%mud.bw,%mud.bw2)
    }
    if (%colour = 15) { %mud.info2 = $replace(%mud.info2,%mud.bn,%mud.bn2,%mud.bw,%mud.bw2,02,12) }
    %friend = $strip(%mud.info2)
    if (says isincs %friend || states isincs %friend || asks isincs %friend || chats isincs %friend || questions isincs %friend || whispers isincs %friend || tells isincs %friend || grats isincs %friend || walks isincs %friend) {
      %friend = $gettok(%friend,1,32)
      if (%friend != some && %friend isalnum && $len(%friend) > 3) { aline -ln %MUDclient2 %friend }
      unset %friend
    }
    if (%mud.info2 != $chr(160)) { %mud.info2 = $chr(160) $+ %mud.info2 }
    $dll($scriptdirspaces.dll, echo, %colour -mi1 %MUDclient2 %mud.info2)
    %space = %mud.info2
    unset %mud.info %mud.info2
    goto nextread
  }
}

;================
;Closing Routines
;================
on *:sockclose:MUDclient*: {
  if (@MUDclient* iswm $active) {
    var %MUDclient = $active
    echo 4 -m %MUDclient Connection to $remove(%MUDclient,@MUDclient-) Closed.
  }
}

alias closemud {
  if (@MUDclient* iswm $active) {
    var %MUDclient = $remove($active,@)
    var %MUDclient2 = $active
    if ($sock(%MUDclient).status == $null) { halt }
    sockwrite -nt %MUDclient quit
    sockclose %MUDclient | echo 4 -m %MUDclient2 Connection to $remove(%MUDclient,MUDclient-) Closed.
  }
}
on *:CLOSE:@MUDclient*: {
  if (@MUDclient* iswm $active) {
    var %MUDclient = $remove($active,@)
    if ($sock(%MUDclient).status != $null) { sockwrite -nt %MUDclient quit | sockclose %MUDclient }
  }
}


GigIRC Network Admin
irc.gigirc.com
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Sorry about $dname. I was trying to hurry and got mixed up after looking at the dialog section. blush

That looks right from a quick scan of it. If you find something not working, post what it is and I'll look closer.


Invision Support
#Invision on irc.irchighway.net
Joined: Feb 2007
Posts: 75
T
Babel fish
OP Offline
Babel fish
T
Joined: Feb 2007
Posts: 75
Seems to be working fine, haven't found any thing majorly going wrong with it a few error messages and a extra space issue I worked out already. That's about what I can see with a quick test with it on 3 servers. Will let you know if a error pops up a can't handle wink

Thanks for the help, Riamus2


GigIRC Network Admin
irc.gigirc.com
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
No problem. smile


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard