Jump to content

sending packets to game servers


Recommended Posts

hey guys, so far I have a work in progress for finding a game server ip then it sends packets to that server, but number 1 I'm having trouble with the looping, which might not need a switch, so I can probably just take that whole part about the Home key out. Also I don't know how to get the full server ip and port number as a variable that I can just set so that i can TCPSend the packets through the right port. Someone please help me, I will greatly appreciate it.

So here is what I have so far...

#include <guiconstants.au3>
#include <guilistview.au3>
$Main = GUICreate('Get Server Info', 200, 75)
$WinButton = GUICtrlCreateButton('Get Server By Window', 10, 10, 180, 25)
$ProcButton = GUICtrlCreateButton('Get Server By Process', 10, 40, 180, 25)

Global $Paused
HotKeySet("{END}", "Terminate")


GUISetState()
While 1
    Switch GUIGetMsg()
        Case - 3
            Exit
        Case $WinButton
            _CreateWindowGUI($Main)
        Case $ProcButton
            _CreateProcGUI($Main)
    EndSwitch
WEnd
Func _CreateWindowGUI($hMain)
    Local $aWin = WinList(), $sRead
    Local $ChildWin = GUICreate('Visible Windows', 400, 500, Default, Default, Default, Default, HWnd($hMain))
    Local $ChildList = GUICtrlCreateList('', 10, 10, 380, 450)
    For $iCC = 1 To $aWin[0][0]
        If $aWin[$iCC][0] <> '' And BitAND(WinGetState($aWin[$iCC][1]), 2) Then
            GUICtrlSetData($ChildList, $aWin[$iCC][0])
        EndIf
    Next
    Local $ChildSubmit = GUICtrlCreateButton('Make Query', 150, 455, 100, 25)
    GUISetState()
    While 1
        Switch GUIGetMsg()
            Case - 3
                GUIDelete($ChildWin)
                Return 1
            Case $ChildSubmit
                $sRead = GUICtrlRead($ChildList)
                GUIDelete($ChildWin)
                _CreateListView($hMain, _GetServer(WinGetProcess(WinGetHandle($sRead))))
                Return 1
        EndSwitch
    WEnd
EndFunc   ;==>_CreateWindowGUI
Func _CreateProcGUI($hMain)
    Local $aProc = ProcessList(), $sRead
    Local $ChildProc = GUICreate('Running Processes', 400, 500, Default, Default, Default, Default, HWnd($hMain))
    Local $ChildList = GUICtrlCreateList('', 10, 10, 380, 450)
    For $iCC = 1 To $aProc[0][0]
        GUICtrlSetData($ChildList, $aProc[$iCC][0])
    Next
    Local $ChildSubmit = GUICtrlCreateButton('Make Query', 150, 455, 100, 25)
    GUISetState()
    While 1
        Switch GUIGetMsg()
            Case - 3
                GUIDelete($ChildProc)
                Return 1
            Case $ChildSubmit
                $sRead = GUICtrlRead($ChildList)
                GUIDelete($ChildProc)
                _CreateListView($hMain, _GetServer(ProcessExists($sRead)))
                Return 1
        EndSwitch
    WEnd
EndFunc   ;==>_CreateProcGUI
Func _GetServer($iPID)
    Local $iRPID = Run(@ComSpec & " /c netstat -o", @SystemDir, @SW_HIDE, 6), $sOut
    While 1
        $sOut &= StdoutRead($iRPID)
        If @error Then ExitLoop
    WEnd
    Local $aOut = StringSplit(StringStripCR($sOut), @LF, 1), $sServer, $sHold, $sPID
    For $iCC = 1 To $aOut[0]
        $sHold = StringStripWS($aOut[$iCC], 7)
        $sPID = StringMid($sHold, StringInStr($sHold, ' ', 0, -1) + 1)
        If $sPID = $iPID Then $sServer &= $sHold & Chr(1)
    Next
    Return StringTrimRight($sServer, 1)
EndFunc   ;==>_ProcessGetServer
Func _CreateListView($hMain, $sInfo)
    Local $ChildListView = GUICreate('Server Info', 440, 300, Default, Default, Default, Default, HWnd($hMain))
    Local $LVList = GUICtrlCreateListView('Protocol|Local Address|Foreign Address|State|PID', 10, 10, 420, 245, Default, BitOR(0x00000020, 0x00000001))
    Dim $ConnectedSocket = -1
    _GUICtrlListViewSetColumnWidth($LVList, 0, 50)
    _GUICtrlListViewSetColumnWidth($LVList, 1, 80)
    _GUICtrlListViewSetColumnWidth($LVList, 2, 150)
    _GUICtrlListViewSetColumnWidth($LVList, 3, 80)
    _GUICtrlListViewSetColumnWidth($LVList, 4, 55)
    $sInfo = StringReplace($sInfo, ' ', '|')
    Local $aSplit = StringSplit($sInfo, Chr(1)), $aLVI[$aSplit[0] + 1]
    Local $nPORT = 4000

    For $iCC = 1 To $aSplit[0]
        $aLVI[$iCC] = GUICtrlCreateListViewItem($aSplit[$iCC], $LVList)
    Next
    $OkButton = GUICtrlCreateButton('Ok', 170, 265, 100, 25)
    GUISetState()
    While 1
        Switch GUIGetMsg()
            Case - 3, $OkButton
                Local $LVText = StringSplit(GUICtrlRead(GUICtrlRead($LVList), 2), '|')
                If $LVText[0] > 1 Then
                    Local $aSplit = StringSplit($LVText[3], ':')
                    MsgBox(64, 'Info', 'Server IP: ' & $aSplit[1])
                EndIf
                GUIDelete($ChildListView)
                Return 1
        EndSwitch
    WEnd
    
    $Paused = $Paused
    While $Paused
    sleep(300)

    While 1
        $ConnectedSocket = TCPConnect ($aSplit[1], $nPORT)
        Local $szData = "0x15010268616c6c6f6f000000"
        TCPSend ($ConnectedSocket, $szData)
    WEnd

    If "{HOME}" Then
        $Paused = Not $Paused
    EndIf

    WEnd

EndFunc

Func Terminate()
    Exit 0
EndFunc
Link to comment
Share on other sites

Also I don't know how to get the full server ip and port number as a variable that I can just set so that i can TCPSend the packets through the right port.

If I am reading this question correctly, you want to start with some variables?

Imagine that this is the first function called in your code.

Func CheckVars()
;The following check will ensure some variables have been sent with the program request.
;$CmdLine[0] is an integer stating how many vars you have added to your command.
 If $CmdLine[0] < 2 Then 
 MsgBox(0,"","No IP or Port Set",5)
 Return 0
 EndIf

;If function gets to this point, there are variables.
;You should evaluate each $CmdLine[x] to ensure that it is correct format.
;Note $ipaddr and $portaddr should be set as global vars, if using functions.
 $ipaddr=$CmdLine[1]
 $portaddr=$CmdLine[2]
 Return 1
EndFunc

Let's say your compiled program is called test.exe.

If I just called test.exe, $CmdLine[0] = 0, so you get the message.

If you called test.exe 101.45.233.42 80, then $CmdLine[0]=2, $CmdLine[1]=101.45.233.42, $CmdLine[2]=80.

Another way would be to create an INI file, with the settings made there - still changeable from a compiled program.

Does that help? :lmao:

Please correct me if I am wrong in any of my posts. I like learning from my mistakes too.

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...