Jump to content

TCP Stuff, Where are you smith? xD


AzKay
 Share

Recommended Posts

Okai, Heres my problem, if I use DMZ on my router, The script connects fine, but if I just use portforwarding, it doesnt connect, Though, the port IS open.

#include <GUIConstants.au3>
Opt("GUIOnEventMode", 1)

Global $list, $sock
Global $userlist[16][2]     ; [ username ][ ctrl id ]
Global $USER
Global $IP
Global $PORT

$gui = GUICreate("GaiaGames", 955, 505, 230, 186)
$oGame = ObjCreate("ShockwaveFlash.ShockwaveFlash.9")
$oGame_ctrl = GUICtrlCreateObj($oGame, 0, 0, 552, 504)
$Group1 = GUICtrlCreateGroup("Fishing", 760, 0, 193, 209)
$Bassken = GUICtrlCreateButton("Bassken", 800, 24, 113, 25)
GUICtrlSetOnEvent(-1, "BasskenClick")
$PortOfGambino = GUICtrlCreateButton("Port of Gambino", 800, 56, 113, 25)
GUICtrlSetOnEvent(-1, "PortOfGambinoClick")
$Durem = GUICtrlCreateButton("Durem", 800, 88, 113, 25)
GUICtrlSetOnEvent(-1, "DuremClick")
$MaxCast = GUICtrlCreateButton("Max Cast", 800, 136, 113, 25)
GUICtrlSetOnEvent(-1, "MaxCastClick")
$AutoReel = GUICtrlCreateButton("Auto Reel", 800, 168, 113, 25)
GUICtrlSetOnEvent(-1, "AutoReelClick")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group2 = GUICtrlCreateGroup("Casino", 560, 0, 193, 209)
$Slots = GUICtrlCreateButton("Slots", 600, 24, 113, 25)
GUICtrlSetOnEvent(-1, "SlotsClick")
$Cards = GUICtrlCreateButton("Cards", 600, 56, 113, 25)
GUICtrlSetOnEvent(-1, "CardsClick")
$AutoSlot = GUICtrlCreateButton("Auto Slot", 600, 168, 113, 25)
GUICtrlSetOnEvent(-1, "AutoSlotClick")
$BuyToken = GUICtrlCreateButton("Buy Tokens", 600, 136, 113, 25, 0)
GUICtrlSetOnEvent(-1, "_BuyTokens")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group3 = GUICtrlCreateGroup("Towns", 560, 216, 193, 73)
$Towns = GUICtrlCreateButton("Towns", 600, 240, 113, 25)
GUICtrlSetOnEvent(-1, "TownsClick")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Group4 = GUICtrlCreateGroup("WordBump", 760, 216, 193, 73)
$WordBump = GUICtrlCreateButton("Word Bump", 800, 240, 113, 25)
GUICtrlSetOnEvent(-1, "WordBumpClick")
GUICtrlCreateGroup("", -99, -99, 1, 1)
$Chat = GUICtrlCreateGroup("Chat", 560, 296, 393, 201)
$list = GUICtrlCreateListView("Users", 824, 320, 113, 145)
$list_0 = GUICtrlCreateListViewItem("", $list)
$input = GUICtrlCreateInput("", 568, 320, 249, 21)
$send = GUICtrlCreateButton("Send", 568, 344, 121, 17, 0)
$pm = GUICtrlCreateButton("PM", 696, 344, 121, 17, 0)
$edit = GUICtrlCreateEdit("", 568, 368, 249, 121, BitOR($ES_AUTOVSCROLL,$ES_AUTOHSCROLL,$ES_READONLY,$ES_WANTRETURN,$WS_HSCROLL,$WS_VSCROLL))
$Connect = GUICtrlCreateButton("Connect.", 824, 472, 113, 17, 0)
GUICtrlSetOnEvent(-1, "_Connect")
;GUICtrlSetData(-1, "")
GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)

GUICtrlSetOnEvent($send, "_Send")
GUICtrlSetOnEvent($pm, "_PM")
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

GUICtrlSetState($input, $GUI_FOCUS)
GUISetState()

_ReduceMemory()

While 1
    Sleep(0)
    $recv = TCPRecv($sock, 2048)
    If not $recv Then ContinueLoop
    $recv = StringSplit($recv, Chr(1))
    For $i = 1 to $recv[0]
        $temp = StringSplit($recv[$i], Chr(2))
        Switch $temp[1]
            Case "rejected"
                mError("Too many users in chat room.", 1)
            Case "accepted"
                ; nothing
            Case "adduser"
                _AddUser($temp[2])
            Case "deluser"
                _DelUser($temp[2])
            Case "exit"
                mError("Server has closed.", 1)
            Case Else
                If $recv[$i] Then GUICtrlSetData($edit, $recv[$i] & @CRLF, 1)
        EndSwitch
    Next
    _ReduceMemory()
WEnd


Func _Send()
    TCPSend($sock, StringReplace(StringReplace(GUICtrlRead($input), Chr(1), ""), Chr(2), ""))
    GUICtrlSetData($input, "")
EndFunc

Func _PM()
    Local $user = GUICtrlRead($list), $data = StringReplace(StringReplace(GUICtrlRead($input), Chr(1), ""), Chr(2), "")
    If not $user Then Return 0
    $user = GUICtrlRead($user)
    TCPSend($sock, Chr(1) & "PM" & Chr(2) & $user & Chr(2) & $data)
    GUICtrlSetData($input, "")
    GUICtrlSetData($edit, "<** PM sent to: " & $user & " **>" & @CRLF & "<** " & $data & " **>" & @CRLF, 1)
    Return 1
EndFunc

Func _AddUser( $user )
    For $i = 0 to 15
        If not $userlist[$i][0] Then
            $userlist[$i][0] = $user
            $userlist[$i][1] = GUICtrlCreateListViewItem($user, $list)
            Return 1
        EndIf
    Next
    Return 0
EndFunc

Func _DelUser( $user )
    For $i = 0 to 15
        If $userlist[$i][0] = $user Then
            $userlist[$i][0] = ""
            GUICtrlDelete($userlist[$i][1])
            Return 1
        EndIf
    Next
    Return 0
EndFunc

Func _ReduceMemory()
    DllCall("psapi.dll", "int", "EmptyWorkingSet", "long", -1)
EndFunc

Func mError( $sText, $iFatal = 0, $sTitle = "Error", $iOpt = 0 )
    Local $ret = MsgBox(48 + 4096 + 262144 + $iOpt, $sTitle, $sText)
    If $iFatal Then Exit
    Return $ret
EndFunc

Func _Exit()
    Exit
EndFunc

Func OnAutoItExit()
    TCPSend($sock, Chr(1) & "bye")
    TCPShutdown()
    Exit
EndFunc

Func _Connect()
If GUICtrlRead($Connect) = "Disconnect." Then
    _Disconnect()
ElseIf GUICtrlRead($Connect) = "Connect." Then
$IP = InputBox("Connect To:", "Type in the IP address you wish to connect to.", "")
;If @error or not $IP Then Exit
$USER = InputBox("Enter Username:", "Type in your username below.")
;If @error or not $USER Then Exit
$PORT = 31758

TCPStartUp()

$sock = TCPConnect($IP, $PORT)
If $sock = -1 Then
    MsgBox(0, "Error", "Error: Unable to connect.")
    TCPShutDown()
Else
    GUICtrlSetData($Connect, "Disconnect.")
EndIf
TCPSend($sock, $USER)
EndIf
EndFunc

Func _Disconnect()
    _DelUser($user)
    TCPShutDown()
    GUICtrlSetData($Connect, "Connect.")
EndFunc

;###################################################################Games###
Func BasskenClick()
        With $oGame
            .bgcolor = "#000000"
            .Movie = 'http://graphics.gaiaonline.com/images/Gaia_Flash/FISHING/bassken4.0.swf'
            .ScaleMode = 2
            .Loop = True
            .wmode = "Opaque"
        EndWith
EndFunc

Func PortOfGambinoClick()
        With $oGame
            .bgcolor = "#000000"
            .Movie = 'http://graphics.gaiaonline.com/images/Gaia_Flash/FISHING/gambino4.0.swf'
            .ScaleMode = 2
            .Loop = True
            .wmode = "Opaque"
        EndWith
EndFunc
  
Func DuremClick()
        With $oGame
            .bgcolor = "#000000"
            .Movie = 'http://graphics.gaiaonline.com/images/Gaia_Flash/FISHING/durem4.0.swf'
            .ScaleMode = 2
            .Loop = True
            .wmode = "Opaque"
        EndWith
EndFunc

  
Func MaxCastClick()

EndFunc

Func AutoReelClick()
    
EndFunc

;################################################################Casino####
  
Func SlotsClick()
        With $oGame
            .bgcolor = "#000000"
            .Movie = 'http://graphics.gaiaonline.com/images/Gaia_Flash/SLOTS/slots4.2.swf'
            .ScaleMode = 2
            .Loop = True
            .wmode = "Opaque"
        EndWith
EndFunc

Func CardsClick()
        With $oGame
            .bgcolor = "#000000"
            .Movie = 'http://graphics.gaiaonline.com/images/Gaia_Flash/BLACKJACK/blackjack2.3.swf'
            .ScaleMode = 2
            .Loop = True
            .wmode = "Opaque"
        EndWith
EndFunc

Func AutoSlotClick()

EndFunc

Func _BuyTokens()
    
EndFunc

;################################################################WordBump####

Func WordBumpClick()
        With $oGame
            .bgcolor = "#000000"
            .Movie = 'http://graphics.gaiaonline.com/images/Gaia_Flash/WORDBUMP/wordbump0.9.8.swf'
            .ScaleMode = 2
            .Loop = True
            .wmode = "Opaque"
        EndWith
EndFunc
    
;################################################################Towns####
    
Func TownsClick()
        With $oGame
            .bgcolor = "#000000"
            .Movie = 'http://graphics.gaiaonline.com/images/towns/015/towns_init.swf'
            .ScaleMode = 2
            .Loop = True
            .wmode = "Opaque"
        EndWith
EndFunc

Its odd. I thought it wouldve worked either way. Apparently not. And, I know the port IS open, because I used: http://www.canyouseeme.org/ To check it. So yeah, I dont know whats up.

# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

And heres the server:

HotKeySet("{ESC}", "OnAutoItExit")

Global Const $IP = @IPADDRESS1
Global Const $PORT = 31758

Global $listen
Global $list[16][2] ; [ socket ][ username ]

TCPStartup()

$listen = TCPListen($IP, $PORT, 100)
If $listen = -1 Then mError("Unable to connect.", 1)

_ReduceMemory()

While 1
    _CheckConn()
    Sleep(0)
    $sock = TCPAccept($listen)
    If $sock = -1 Then ContinueLoop
    If _AddConn($sock) Then
        $recv = _SockRecv($sock)
        If @error Then
            _DelConn($sock)
        Else
            TCPSend($sock, Chr(1) & "accepted")
            _AddUser($sock, $recv)
            _SendUsers($sock)
            _SendAll(Chr(1) & "adduser" & Chr(2) & $recv, "", $sock)
        EndIf
    EndIf
    _ReduceMemory()
WEnd


Func _AddConn( $iSocket )
    Local $added = False
    For $i = 0 to 15
        If not $list[$i][0] Then
            $list[$i][0] = $iSocket
            $added = True
            ExitLoop
        EndIf
    Next
    If $added Then Return True
    TCPSend($iSocket, Chr(1) & "rejected")
    TCPCloseSocket($iSocket)
    Return False
EndFunc

Func _DelConn( $iSocket )
    For $i = 0 to 15
        If $list[$i][0] = $iSocket Then
            TCPCloseSocket($iSocket)
            $list[$i][0] = 0
            $list[$i][1] = ""
            Return
        EndIf
    Next
EndFunc

Func _CheckConn()
    Local $recv = ""
    For $i = 0 to 15
        If $list[$i][0] Then
            $recv = TCPRecv($list[$i][0], 2048)
            If @error Then
                TCPCloseSocket($list[$i][0])
                _SendAll(Chr(1) & "deluser" & Chr(2) & $list[$i][1])
                $list[$i][0] = 0
                $list[$i][1] = ""
            Else
                If $recv Then
                    $recv = StringSplit($recv, Chr(1))
                    For $j = 1 to $recv[0]
                        $temp = StringSplit($recv[$j], Chr(2))
                        Switch $temp[1]
                            Case "bye"
                                TCPCloseSocket($list[$i][0])
                                _SendAll(Chr(1) & "deluser" & Chr(2) & $list[$i][1])
                                $list[$i][0] = 0
                                $list[$i][1] = ""
                            Case "PM"
                                _PM($temp[2], $temp[3], $list[$i][1])
                            Case Else
                                If $recv[$j] Then _SendAll($recv[$j], $list[$i][1])
                        EndSwitch
                    Next
                EndIf
            EndIf
        EndIf
    Next
EndFunc

Func _AddUser( $iSocket, $sUser )
    For $i = 0 to 15
        If $list[$i][0] = $iSocket Then $list[$i][1] = $sUser
    Next
EndFunc

Func _SendAll( $str, $from = "", $except = 0 )
    For $i = 0 to 15
        If $list[$i][0] and $list[$i][0] <> $except Then
            If $from and StringLeft($str, 1) <> Chr(1) Then
                TCPSend($list[$i][0], $from & " > " & $str)
            Else
                TCPSend($list[$i][0], $str)
            EndIf
        EndIf
    Next
EndFunc

Func _PM( $user, $str, $from )
    For $i = 0 to 15
        If $list[$i][1] = $user Then
            TCPSend($list[$i][0], "~ " & $from & " > " & $str)
            Return
        EndIf
    Next
EndFunc

Func _SendUsers( $iSocket )
    For $i = 0 to 15
        If $list[$i][0] Then TCPSend($iSocket, Chr(1) & "adduser" & Chr(2) & $list[$i][1])
    Next
EndFunc

Func _SockRecv( $iSocket, $iBytes = 2048 )
    Local $sData = ""
    While $sData = ""
        $sData = TCPRecv($iSocket, $iBytes)
        If @error Then
            SetError(1)
            Return ""
        EndIf
    Wend
    Return $sData
EndFunc

Func _ReduceMemory()
    DllCall("psapi.dll", "int", "EmptyWorkingSet", "long", -1)
EndFunc

Func mError( $sText, $iFatal = 0, $sTitle = "Error", $iOpt = 0 )
    Local $ret = MsgBox(48 + 4096 + 262144 + $iOpt, $sTitle, $sText)
    If $iFatal Then Exit
    Return $ret
EndFunc

Func OnAutoItExit()
    _SendAll(Chr(1) & "exit")
    TCPShutdown()
    Exit
EndFunc

And Yes, Im well aware I didnt make this server/client. I got it from scripts and scraps. Credits to the creator. I decided to put the chat in there, so, me and my friends can talk if were not in the same fishing rooms, or slots/card games :)

Edited by AzKay
# MY LOVE FOR YOU... IS LIKE A TRUCK- #
Link to comment
Share on other sites

Just remember servers are tempermental you probably need to use @IpAddress1 for it to host on the internet. Also remember YOU CAN'T connect to your self on the public IP. You need to get your Network IP.

I made a utility called IPScout that will tell you both.

Checkit out at the AutoIt-ITS Download page.

AutoIt Smith

Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

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