Socket Chat Dialog v.5

By Goldy58 on Feb 12, 2008

Well, this little dialog let you host a chat server, just like mIRC, by clicking Connect, then click Join, type in your name, then your server ip (If you're the host, type 127.0.0.1) and give the ip to someone else, if they have this script. The Clients will have to click join, then YOUR IP ADDRESS so they can join. I might have put up sometings that i probably dont need, but it works. Please tell me how it is, and i dont care if its sloppy or not, just showing my scripts. Update will be made, so keep on watch.

on *:start:{
  echo -s - Chat Socket -
  echo -s - Knowing how to use sockets - By Goldy -
  echo -s To use this script, Right-Click on any windows and click Chat Socket Test, or type /chat.socket.
}
alias chat.socket { dialog -dmr chat.socket chat.socket }

alias -l getip sockopen getip checkip.dyndns.org 80

on *:SOCKOPEN:getip:{ sockwrite -n $sockname GET / HTTP/1.1 | sockwrite -n $sockname Host: dyndns.org $+ $crlf $+ $crlf }
on *:SOCKREAD:getip:{
  var %getip, %regex /[^(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})]/g
  sockread %getip
  if (<*> iswm %getip) {
    $null($regsub(%getip,%regex,$null,%retip))
    did -a chat.socket 1 Your IP Address: %retip
    sockclose $sockname
  }
}

menu * {
  Chat Socket Test:/dialog -dmr chat.socket chat.socket
}

dialog chat.socket {
  title "Chat Server Test"
  size -1 -1 695 600
  option pixels notheme
  edit "", 1, 2 7 690 535, read multi vsbar
  edit "", 2, 0 548 625 20, autohs
  button "Send", 3, 630 545 65 25, default
  button "Connect", 4, 0 573 250 25
  button "Disconnect", 5, 445 573 250 25
  button "Join", 6, 315 573 65 25
}

dialog chat.socket.client {
  title "Client Setup"
  size -1 -1 200 70
  option pixels notheme
  text "Enter IP Address:", 1, 3 5 85 17
  edit "", 2, 90 4 110 20, center
  text "Enter Your Name:", 3, 3 25 85 17
  edit "", 4, 90 23 110 20, center
  button "&OK", 5, 10 45 65 20, default
  button "&Cancel", 6, 105 45 65 20, cancel
}

dialog chat.error1 {
  title "ERROR!!!"
  size -1 -1 127 72
  option pixels notheme
  text "IP Address Not Specified", 1, 3 4 120 17, nowrap center
  text "Name Not Specified", 2, 3 23 120 17, center
  button "&OK", 3, 31 44 65 25, ok default
}

dialog chat.error2 {
  title "ERROR!!!"
  size -1 -1 127 72
  option pixels notheme
  text "IP Address Not Specified", 1, 3 10 120 17, nowrap center
  button "&OK", 3, 31 44 65 25, ok default
}

dialog chat.error3 {
  title "ERROR!!!"
  size -1 -1 127 72
  option pixels notheme
  text "Name Not Specified", 1, 3 10 120 17, nowrap center
  button "&OK", 3, 31 44 65 25, ok default
}

on *:dialog:*:*:*:{
  if ($dname == chat.socket) {
    if ($devent == sclick) {
      if ($did == 3) {
        if ($did(2) == $null) { halt }
        else {
          if ($sock(chat.socket.client)) {
            if ($gettok($did(2),1,32) == /ckick && $gettok($did(2),2,32)) {
              sockwrite -n chat.socket.client C.KICK $gettok($did(2),2-,32)
            }

            elseif (!$istok(/ckick /cnick,$gettok($did(2),1,32),32)) { sockwrite -n chat.socket.client C.MSG $did(2) }
          }
          else { did -a $dname 1 ***NOT CONNECTED TO SERVER*** $crlf }
        }
        did -r $dname 2
      }
      elseif ($did == 4) {
        if (!$sock(chat.socket.host)) {
          socklisten chat.socket.host 6667
          did -a $dname 1 ***HOSTING SERVER STARTED. LISTENING ON PORT 6667*** $crlf $crlf
          getip
          hmake -s chat 1000 | hmake -s names 1000
          hadd -ms chat users 0
          hadd -ms chat socket 0
        }
        else { did -a $dname 1 ***SERVER ALREADY STARTED*** $crlf }
      }
      elseif ($did == 5) {
        if ($sock(chat.socket.client)) {
          sockwrite -n chat.socket.client C.QUIT
          sockclose chat.socket.client
          did -a $dname 1 ***DISCONNECTED FROM SERVER*** $crlf $crlf
        }
        if ($sock(chat.socket.host)) {
          sockclose chat.socket.host
          did -a $dname 1 ***CONNECTION TERMINATED*** $crlf $crlf
          var %i 1
          while ($+(chat.socket.client.,%i) <= $hget(chat,users)) {
            hfree -s $+(chat.socket.client.,%i)
            inc %i
          }
          unset %retip
          hfree -s chat
          hfree -s names
        }
      }
      elseif ($did == 6) {
        if ($sock(chat.socket.client)) { did -a $dname 1 ***CONNECTION ALREADY ESTABLISH*** $crlf }
        else { dialog -dmr chat.socket.client chat.socket.client }
      }
    }
    if ($devent == close) {
      if ($sock(chat.socket.client)) {
        unset %tictactoe.nick
        sockclose chat.socket.client
      }
      if ($sock(chat.socket.host)) { sockclose chat.socket.host }
    }
  }
  elseif ($dname == chat.socket.client) {
    if ($devent == sclick) {
      if ($did == 5) {
        if ($did(2) == $null && $did(4) == $null) { dialog -dmr chat.error1 chat.error1 }
        elseif ($did(2) == $null && $did(4) != $null) { dialog -dmr chat.error2 chat.error2 }
        elseif ($did(2) != $null && $did(4) == $null) { dialog -dmr chat.error3 chat.error3 }
        elseif ($did(2) != $null && $did(4) != $null) {
          set %chat.nick $did(4)
          sockopen chat.socket.client $did(2) 6667
          dialog -x $dname
        }
      }
    }
  }
}
on *:socklisten:chat.socket.host:{
  did -a chat.socket 1 User connecting... $crlf
  hinc -s chat users 1
  hinc -s chat socket 1
  sockaccept $+(chat.socket.client.,$hget(chat,socket))
}

on *:sockopen:chat.socket.client:{
  if ($sockerr) { did -a chat.socket 1 ***CONNECTION UNAVAILABLE*** $crlf $crlf }
  else {
    sockwrite -n $sockname C.NICK %chat.nick
    sockwrite -n $sockname C.JOIN %chat.nick
  }
}

on *:sockread:chat.socket.client:{
  var %chat
  sockread %chat
  tokenize 32 %chat

;RECIEVING DATA----------------------------------------------

  did -a chat.socket 1 $+([,$asctime(hh:nn:ss tt),]) %chat $crlf
}

on *:sockread:chat.socket.client.*:{
  var %chat
  sockread %chat
  tokenize 32 %chat

;NICK--------------------------------------------------------

  if ($1 == C.NICK) {
    var %i 1
    while (%i <= $hget(chat,users)) {
      if ($hget($+(chat.socket.client.,%i),nick) == $2) {
        sockwrite -n $sockname $+(.:,$2,:.) Nickname already in use.
        hadd -ms $sockname nick $+(XXX-,$rand(0,9),$rand(a,z),$rand(0,9),$rand(A,Z),$rand(0,9),-XXX)
        sockwrite -n $sockname Your Name is now $hget($sockname,nick)
        set -u2 %nick failed
      }
      inc %i
    }
    unset %i
    if (%nick != failed) {
      hadd -ms $sockname nick $2
      sockwrite -n $sockname -- Welcone to the chatroom, $hget($sockname,nick) -- $crlf
    }
  }

;JOIN--------------------------------------------------------

  elseif ($1 == C.JOIN) {
    var %i 1
    while (%i <= $hget(chat,users)) {
      if ($hget($+(chat.socket.client.,%i))) {
        sockwrite -n $+(chat.socket.client.,%i) -- $hget($sockname,nick) has joined the Chat -- $crlf
      }
      inc %i
    }
    unset %i
  }

;MESSAGE-----------------------------------------------------

  elseif ($1 == C.MSG) {
    var %i 1
    while (%i <= $hget(chat,users)) {
      if ($hget($+(chat.socket.client.,%i))) {
        sockwrite -n $+(chat.socket.client.,%i) $+(<,$hget($sockname,nick),>) $remove(%chat,C.MSG)
      }
      inc %i
    }
    unset %i
  }

;KICK--------------------------------------------------------

  elseif ($1 == C.KICK) { sockwrite -n $sockname %chat }

;QUIT--------------------------------------------------------

  elseif ($1 == C.QUIT) {
    var %i 1
    while (%i <= $hget(chat,users)) {
      if ($hget($+(chat.socket.client.,%i))) {
        sockwrite -n $+(chat.socket.client.,%i) -- User has quit --
      }
      inc %i
    }
  }
;did -a chat.socket 1 %chat $crlf

}

Comments

Sign in to comment.
Goldy58   -  Apr 13, 2010

I havent been updatin this in a while, cause was too busy gettin the understanding of Visual Basic (VB). I havent lost my knowledge in sockets for mIRC either. I am goin to get back at it, but will be a lil slow process to it, since i am workin on somethin good with VB.

 Respond  
Goldy58   -  Feb 16, 2009

Im glad you like it :). Sorry i didn't come back to this, but i'm getting ready to actually make my first game with it. Check back soon.

 Respond  
Jonesy44   -  Apr 18, 2008

Goldy58, Neptune and I just tried this properly over my IP. This is very impressive. I\'m looking to expand on this sometime soon, a game of some sort hehe

 Respond  
Goldy58   -  Feb 16, 2008

mountaindew - Oh and make sure the ip is 127.0.0.1 (or just copy your ip the socket gave you), cause both Chat Dialogs is running on the same computer.

 Respond  
Goldy58   -  Feb 16, 2008

napa182 - hehe, sorry about the size. I only made it big just for the heck of it, should\'ve cut down the size. But thats how i test things out :P

Gemster jonesy44 - but then you might want to make some kind of games, like a Multiplayer Tic-Tac-Toe Script, or a tank game, or whatever. Maybe even customize your own Chat scripts, just like this one, but it a beta (ANYWAYS).

Gemster - yes your right, about the port, i should\'ve thought about that.

mountaindew - If you have another IRC, place this code on that one too, and load it up, run it the same way with another name by clicking Join, but make sure your irc is the host. Click join on Both the host and the other one with different names, and chat.

 Respond  
Jonesy44   -  Feb 13, 2008

It\'s a great idea, port forwarding isn\'t too hard if your know what you\'re doing.

However, i think it would be a hell of a lot easier, if ya just made a channel xD

 Respond  
Gemster   -  Feb 12, 2008

hmm i cant say i know much about connecting to ur local host but if i did and sum1 else connected the local host wouldnt they conect to there local host not mine.
also 1 important fact is for sum1 to connect to ur ip as host then u need ur port forwarding set on ur router/modem to allow ports 6667-6697.

although this is a realy good idea but wouldent making a channel be much easyer ?

 Respond  
guest598594   -  Feb 12, 2008

i chatted with myself

 Respond  
napa182   -  Feb 12, 2008

wow the dialog is huge and cuts off on my screen =/

 Respond  
Are you sure you want to unfollow this person?
Are you sure you want to delete this?
Click "Unsubscribe" to stop receiving notices pertaining to this post.
Click "Subscribe" to resume notices pertaining to this post.