View Single Post
  #1  
Old 07-09-2008, 08:49 AM
nosfentora
Discordant
 
Join Date: Oct 2004
Location: In a house
Posts: 377
Default Telnet and broadcasting

I'm writing some code to broadcast to the server through a tool i'm working on.

Using the following code it works
Code:
   Dim lReturn As Object
   lReturn = IIf(My.Settings.ShowTelnet, Shell("Telnet " & My.Settings.BroadcastServerIP & " " & My.Settings.BroadcastServerPort, AppWinStyle.NormalFocus, False), Shell("Telnet " & My.Settings.BroadcastServerIP & " " & My.Settings.BroadcastServerPort, AppWinStyle.Hide, False))
   Sleep(5)
   AppActivate(lReturn)
   Sleep(2)
   ''login
   System.Windows.Forms.SendKeys.SendWait(My.Settings.BroadcastUsername & "{ENTER}")
   Sleep(2)
   '' pass
   System.Windows.Forms.SendKeys.SendWait(My.Settings.BroadcastPassword & "{ENTER}")
   Sleep(2)
   ''broadcast message
   System.Windows.Forms.SendKeys.SendWait("broadcast " & msg & "{ENTER}")
   Sleep(1)
   ''LOGOFF
   System.Windows.Forms.SendKeys.SendWait("exit{ENTER}")
   Sleep(2)
   ''CLOSE TELNET
   System.Windows.Forms.SendKeys.SendWait("{ENTER}")
   System.Windows.Forms.SendKeys.SendWait("%{F4}")
*BUT* it does not work if the computer is locked (the telnet window stays open and times out - preventing any future broadcasts)

So I tried this:

Code:
            Dim sock As System.Net.Sockets.Socket
            sock = New System.Net.Sockets.Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
            sock.Connect(My.Settings.BroadcastServerIP, Val(My.Settings.BroadcastServerPort))
            If sock.Connected Then
                sock.Send(System.Text.Encoding.ASCII.GetBytes(My.Settings.BroadcastUsername & vbCrLf))
                sock.Send(System.Text.Encoding.ASCII.GetBytes(My.Settings.BroadcastPassword & vbCrLf))
                sock.Send(System.Text.Encoding.ASCII.GetBytes("broadcast " & msg & vbCrLf))
                sock.Send(System.Text.Encoding.ASCII.GetBytes("exit" & vbCrLf & vbCrLf))
                sock.Shutdown(SocketShutdown.Both)
                sock.Disconnect(False)
                sock.Close()
                Log.WriteLine("Message Broadcasted!")
            Else
                Log.WriteLine("Failed to connect!")
            End If
            sock = Nothing
This worked once, and then continues to output the following in the World.exe window:
[DEBUG] [WORLD__ZONE] New TCP Connection from 0.0.0.0:0
[DEBUG] [WORLD__CONSOLE] removing concole (!tcp -> connected) from 0.0.0.0:

I then tried this:
Code:
            Dim ip As New System.Net.IPEndPoint(System.Net.Dns.GetHostAddresses(My.Settings.BroadcastServerIP)(0), My.Settings.BroadcastServerPort)
            Dim client As New System.Net.Sockets.TcpClient()
            client.Connect(ip)
            If client.Connected Then
                Dim myWrite As System.IO.StreamWriter = New System.IO.StreamWriter(client.GetStream())
                myWrite.WriteLine(My.Settings.BroadcastUsername)
                myWrite.WriteLine(My.Settings.BroadcastPassword)
                myWrite.WriteLine("broadcast " & msg)
                myWrite.WriteLine("exit")
                myWrite.Close()
                client.Close()
            End If
which never worked and constantly output
[DEBUG] [WORLD__ZONE] New TCP Connection from 0.0.0.0:0
[DEBUG] [WORLD__CONSOLE} removing concole (!tcp -> connected) from 0.0.0.0:

in the World.exe window

Any thoughts from the developers on a possible solution? The easiest would be to turn off the auto-lock on the computer, but I'd prefer not to.

(if this is the wrong area to post - please feel free to move it)
Reply With Quote