Jump to content

Recommended Posts

Posted (edited)

Ok, so I'm working on a little prog that uses a tcp connection between two pc's, based on the script by AutoIt Smith, that doesnt require a server/client script/prog running. I want to be able to pop open a chat window between me and the person connected to me, or vice versa. How do you accomplish this? Spyrorocks showed me some code to pop open an unclosable window, but how do you open it for both users and allow them to chat?

Also..I pop open a separate window for the chat window, how can I only close the child chat window instead of the entire prog?

Edited by kjmarket
Pink Floyd - The Wall
Posted

OK, thats not the same as what I wanted...but it interests me. With that example, would it be possible to send a tcpsend command to just one person in the chat, rather than to the server?

Pink Floyd - The Wall
Posted (edited)

This is a limited string from the Current server:

Case $String[1] = "~pm"
                    Select
                        Case $String[0] <> 3
                            TCPSend($ConnectedSocket[$SocketNumber], "Invalid Syntax")
                            Return 1
                    EndSelect
                    $Track = 0
                    For $Track = 0 To (UBound($Userlist) - 1) Step 1
                        If $Userlist[$Track] = $String[2] Then $StoredVar = $Track
                    Next
                    TCPSend($ConnectedSocket[$SocketNumber], "Personal Message To " & $Userlist[$StoredVar] & " : " & $String[3])
                    TCPSend($ConnectedSocket[$StoredVar], "Personal Message From " & $Userlist[$SocketNumber] & " : " & $String[3])

You may modify it to work with you server. This works and is tested.

Split the string to allow the message ~pm-username(or socket)-message

$Var = StringSplit($String, "-")
$Var[1] = ~pm
$Var[2] = username/Socket
$Var[3] = Message

This is from 0.8.1 file based.

; Server Stream Functions:
; ~bye
; ~login-USER-PASS-UID
; ~pm-USER-STRING
; ~register-USER-PASS

;.....ex cetera

Case $Text[1] = "~pm"
                SendMessage("Pm From " & GetUser($SocketNumber) & ">" & $Text[3], GetUserCurrentSocket($Text[2]))
                SendMessage("Pm To " & GetUser(GetUserCurrentSocket($Text[2])) & ">" & $Text[3], $SocketNumber)
                FileWriteLine($LogFile, "Pm From " & GetUser($SocketNumber) & " To " & GetUser(GetUserCurrentSocket($Text[2])) & " >" & $Text[3])

Yet another Example, incase you cannot figure it out. ~pm-socketnumber-message

CODE
Global Const $Port = 50911

Global $MaxConc = 100

Global $MainSocket = TCPStartServer($Port, $MaxConc)

If @Error <> 0 Then Exit MsgBox(16, "Error", "Server unable to initialize.")

Global Const $MaxLength = 512

Global $ConnectedSocket[$MaxConc]

Global $CurrentSocket = 0

Local $Track = 0

Global Const $MaxConnection = ($MaxConc - 1)

For $Track = 0 To $MaxConnection Step 1

$ConnectedSocket[$Track] = -1

Next

While 1

$ConnectedSocket[$CurrentSocket] = TCPAccept($MainSocket)

If $ConnectedSocket[$CurrentSocket] <> -1 Then

$CurrentSocket = SocketSearch()

EndIf

$Track = 0

For $Track = 0 To $MaxConnection Step 1

If $ConnectedSocket[$Track] <> - 1 Then

$Data = TCPRecv($ConnectedSocket[$Track], $MaxLength)

$Data2 = StringSplit($Data, "-")

If $Data = "~bye" Then

TCPCloseSocket($ConnectedSocket[$Track])

$ConnectedSocket[$Track] = -1

$CurrentSocket = SocketSearch()

ElseIf $Data2[1] = "~pm" Then

TCPSend($ConnectedSocket[$Data2[2]], "From Socket #" & $Track & " > " & $Data2[3])

TCPSend($ConnectedSocket[$Track], "To Socket #" & $Data2[2] & " > " & $Data2[3])

ElseIf $Data <> "" Then

TCPSendMessageAll($MaxConnection, $Data)

EndIf

EndIf

Next

WEnd

Func TCPSendMessageAll($ConnectionLimit, $Data)

Local $Track = 0

For $Track = 0 To $ConnectionLimit Step 1

If $ConnectedSocket[$Track] <> - 1 Then TCPSend($ConnectedSocket[$Track], $Data)

Next

EndFunc ;==>TCPSendMessageAll

Func TCPStartServer($Port, $MaxConnect = 1)

Local $Socket

$Socket = TCPStartup()

Select

Case $Socket = 0

SetError(@Error)

Return -1

EndSelect

$Socket = TCPListen(@IpAddress1, $Port, $MaxConnect)

Select

Case $Socket = -1

SetError(@Error)

Return 0

EndSelect

SetError(0)

Return $Socket

EndFunc

Func SocketSearch()

Local $Track = 0

For $Track = 0 To $MaxConnection Step 1

If $ConnectedSocket[$Track] = -1 Then

Return $Track

Else

; Socket In Use

EndIf

Next

EndFunc ;==>SocketSearch

Showing This

For $Track = 0 To $MaxConnection Step 1
        If $ConnectedSocket[$Track] <> - 1 Then
            $Data = TCPRecv($ConnectedSocket[$Track], $MaxLength)
            $Data2 = StringSplit($Data, "-")
            If $Data = "~bye" Then
                TCPCloseSocket($ConnectedSocket[$Track])
                $ConnectedSocket[$Track] = -1
                $CurrentSocket = SocketSearch()
            ElseIf $Data2[1] = "~pm" Then
                TCPSend($ConnectedSocket[$Data2[2]], "From Socket #" & $Track & " > " & $Data2[3])
                TCPSend($ConnectedSocket[$Track], "To Socket #" & $Data2[2] & " > " & $Data2[3])
            ElseIf $Data <> "" Then
                TCPSendMessageAll($MaxConnection, $Data)
            EndIf
        EndIf
    Next
Edited by AutoIt Smith
Posted

Incase you doubted the answer was there, there is the answer 3 times over in 2 server versions and another rebuilt generic version.

Posted

I didn't mean to imply anything, so hopeully you didnt take it as me saying it didnt work or what not. It's just my AutoIT ignorance showing. I'm learning as I go, and think I have my answer. I appreciate the help, man. Thanks. :D

Pink Floyd - The Wall

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...