Results 1 to 10 of 10

Thread: Programming MMO(Server Issues)

  1. #1

    Thread Starter
    New Member dreiecon's Avatar
    Join Date
    Aug 2006
    Location
    Australia
    Posts
    8

    Programming MMO(Server Issues)

    Hello guys, I'm new here so I don't know where I should post this (in networks or games)

    Basically when the client connects to the server to send the chat message the server stops with the error type mismatch. I have tried everything I could think of to fix this and it didn't work.

    I'm not sure if I should post the code of not but here goes.

    Server Code
    VB Code:
    1. Private blnarray() As Boolean
    2.  
    3. Private Sub Command1_Click()
    4.  
    5. If Socket.Count <> 1 Then
    6.     For i = i To Socket.Count - 1
    7. Socket(i).Close
    8.     Next i
    9. Else
    10. status = "Server Stopped!"
    11. End If
    12.  
    13. End Sub
    14.  
    15. Private Sub Command2_Click()
    16. If Socket.Count <> 1 Then
    17.         For i = 1 To Socket.Count - 1
    18.             If blnarray(i) = False Then 'Checks if the socket at index "i" is available
    19.                 Socket(i).Close
    20.                 Exit Sub
    21.             End If
    22.         Next i
    23. End If
    24. Unload All
    25. End Sub
    26.  
    27. Private Sub Form_Load()
    28. ReDim blnarray(0)
    29. Socket(0).LocalPort = "22101"
    30. Socket(0).Listen
    31. blnarray(0) = True
    32. End Sub
    33.  
    34. Private Sub Form_Terminate()
    35. Close
    36. End Sub
    37.  
    38. Private Sub Form_Unload(Cancel As Integer)
    39. Close
    40. End Sub
    41.  
    42. Private Sub Socket_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    43.     'Check if any free sockets
    44.     If Socket.Count <> 1 Then
    45.         For i = 1 To Socket.Count - 1
    46.             If blnarray(i) = False Then 'Checks if the socket at index "i" is available
    47.                 Socket(i).Accept requestID 'Accepted connection to old but available socket
    48.                 Exit Sub
    49.             End If
    50.         Next i
    51.     End If
    52.  
    53.     'Only runs if no open sockets
    54.     'Increase size of blnArray
    55.     ReDim Preserve blnarray(Socket.UBound + 1)
    56.     'Load new Winsock1
    57.  
    58.     Load Socket(Socket.UBound + 1)
    59.     'Accept Connection to newly created socket
    60.     Socket(Socket.UBound).Accept requestID
    61.     'Updates the Array at requested position to true stating socket is in use at theis index
    62.     blnarray(Socket.UBound) = True
    63.     'Do not worry your new Winsock1 control automatically is given an open port by the Windows OS
    64. End Sub
    65.  
    66. Private Sub Socket_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    67. status = "Receiving Data!"
    68. ReDim dat(5)
    69. Dim dat_a As String
    70. Call Socket(Index).GetData(dat_a, vbString)
    71. dat = Split(dat_a, ",")
    72. status = "Data Received!"
    73.  
    74. If inarray("chat", dat) = True Then
    75. Dim dat1 As String
    76. dat1 = "chat," + dat(3) + "," + dat(2) + "," + dat(4)
    77. If Socket.Count <> 1 Then
    78.     For i = 1 To Socket.Count - 1
    79.         If blnarray(i) = False Then
    80.             Socket(i).SendData (dat1)
    81.             Exit Sub
    82.         End If
    83.     Next i
    84. End If
    85. Else
    86. Socket(Index).SendData "Error! You are not using the game client to access this server and port. Your IP has been logged and sent to our anti hacking group!"
    87. 'Dim dat1 As String
    88. 'dat1 = "chat," + dat(3) + "," + dat(2) + "," + dat(4)
    89. 'Socket(Index).SendData dat1
    90. End If
    91. End Sub
    92.  
    93. Private Sub Socket_SendComplete(Index As Integer)
    94. status = "Pending New Connection. . ."
    95. Socket(Index).Close
    96. End Sub
    97.  
    98. Private Sub Socket_SendProgress(Index As Integer, ByVal bytesSent As Long, ByVal bytesRemaining As Long)
    99. status = "Sending Data!"
    100. End Sub
    101.  
    102. Public Function inarray(expression As String, a As Variant) As Boolean
    103. Dim fval As Boolean
    104. x = 4
    105. If x <> 1 Then
    106. For i = 1 To x = -1
    107. If a(i) = expression Then
    108. inarray = True
    109. End If
    110. Next i
    111. End If
    112. End Function

    And heres the client code

    VB Code:
    1. 'Private dat1_a() As String
    2. Private connected As Boolean
    3. Private Sub chatsubmit_Click()
    4. 'dat = "chat," + chattype.Text + "," + to_c.Text + "," + chattxt.Text
    5. dat = Array("chat", chattype.Text, to_c.Text, chattxt.Text)
    6. Dim dat_a As String
    7. dat_a = Join(dat, ",")
    8. If connected = True Then
    9. sock.SendData (dat_a)
    10. ElseIf connected = False Then
    11. If sock.State = 8 Then
    12. sock.Close
    13. While sock.State <> sckClosed
    14. Wend
    15. sock.Connect
    16.  
    17. Else
    18. 'sock.Connect
    19.  
    20. End If
    21. End If
    22. End Sub
    23.  
    24. Private Sub conn_Timer()
    25. If connected = False Then
    26. sock.Close
    27. While sock.State <> sckClosed
    28. Wend
    29. sock.Connect
    30. Else
    31. Exit Sub
    32. End If
    33. End Sub
    34.  
    35. Private Sub Form_Load()
    36. 'text As String
    37. text_v = "[System] Welcome to the example of the chat system."
    38. chatview = chatview + vbCrLf + text_v
    39. sock.RemoteHost = "localhost"
    40. sock.RemotePort = "22101"
    41. sock.Connect
    42. End Sub
    43.  
    44. Private Sub sock_Close()
    45. connected = False
    46. End Sub
    47.  
    48. Private Sub sock_Connect()
    49. connected = True
    50. End Sub
    51.  
    52. Private Sub sock_DataArrival(ByVal bytesTotal As Long)
    53. Dim dat_a1() As String
    54. Dim dat1 As String
    55. Call sock.GetData(dat1)
    56. dat_a1 = Split(dat1, ",")
    57. Dim dat1_a(0 To 4) As String
    58. count1 = 4
    59. 'If count1 <> 1 Then
    60. '   For i = 1 To count1 - 1
    61.   '  dat1_a(i) = dat_a1(i)
    62.    ' Next i
    63. 'End If
    64. MsgBox (dat1)
    65. If dat1_a(0) = "GM" Then
    66. gmview = "[GM] " + dat1_a(3)
    67. ElseIf dat1_a(0) = "System" Then
    68. chatview = "[System] " + dat1_a(3)
    69. Else
    70. chatview.Caption = dat1
    71. End If
    72. End Sub
    73.  
    74. Private Sub sock_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
    75. m = MsgBox("Error. Disconnected from the server and cannot reconnect.", vbOKOnly, "Error with connection!")
    76. Unload Form1
    77. Unload Form2
    78. Close
    79. End Sub
    80.  
    81. Private Sub Timer1_Timer()
    82. gmview = ""
    83. Timer1.Enabled = False
    84. End Sub

    I'm only trying to get the chat to work so I can test and make sure that my Winsock multi connection works then I will begin developing movements of such.

    I know the code is very ugly but I'm not a VB6 Programmer lol, I program in PHP.

    All help greatly appreciated.

    Thanks guys.
    Last edited by dreiecon; Aug 13th, 2006 at 05:54 PM.
    [VBCODE]
    Private Sub form1_load()
    If programming = fun then
    MsgBox ("Programming is so much fun!")
    Else
    MsgBox ("Learn to program n00b")
    End If
    End Sub[/VBCODE]

  2. #2

    Thread Starter
    New Member dreiecon's Avatar
    Join Date
    Aug 2006
    Location
    Australia
    Posts
    8

    Re: Programming MMO(Server Issues)

    Bump.

    Can anyone help?
    [VBCODE]
    Private Sub form1_load()
    If programming = fun then
    MsgBox ("Programming is so much fun!")
    Else
    MsgBox ("Learn to program n00b")
    End If
    End Sub[/VBCODE]

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Programming MMO(Server Issues)

    "Type Mismatch" means that you are not using data types properly - for example, you may be trying to put a string value into an Integer variable/property.

    Which line is the error occuring on?

  4. #4

    Thread Starter
    New Member dreiecon's Avatar
    Join Date
    Aug 2006
    Location
    Australia
    Posts
    8

    Re: Programming MMO(Server Issues)

    This entire area is not working correctly.

    VB Code:
    1. Private Sub Socket_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    2. status = "Receiving Data!"
    3. ReDim dat(5)
    4. Dim dat_a As String
    5. Call Socket(Index).GetData(dat_a, vbString)
    6. dat = Split(dat_a, ",")
    7. status = "Data Received!"
    8.  
    9. If inarray("chat", dat) = True Then
    10. Dim dat1 As String
    11. dat1 = "chat," + dat(3) + "," + dat(2) + "," + dat(4)
    12. If Socket.Count <> 1 Then
    13.     For i = 1 To Socket.Count - 1
    14.         If blnarray(i) = False Then
    15.             Socket(i).SendData (dat1)
    16.             Exit Sub
    17.         End If
    18.     Next i
    19. End If
    20. Else
    21. Socket(Index).SendData "Error! You are not using the game client to access this server and port. Your IP has been logged and sent to our anti hacking group!"
    22. 'Dim dat1 As String
    23. 'dat1 = "chat," + dat(3) + "," + dat(2) + "," + dat(4)
    24. 'Socket(Index).SendData dat1
    25. End If
    26. End Sub
    [VBCODE]
    Private Sub form1_load()
    If programming = fun then
    MsgBox ("Programming is so much fun!")
    Else
    MsgBox ("Learn to program n00b")
    End If
    End Sub[/VBCODE]

  5. #5
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Programming MMO(Server Issues)

    There's nothing obvious, but we can probably work it out if you tell us which line the error is occuring on.

  6. #6

    Thread Starter
    New Member dreiecon's Avatar
    Join Date
    Aug 2006
    Location
    Australia
    Posts
    8

    Re: Programming MMO(Server Issues)

    Ok. I've fixed it as much as I can.

    I now use;
    VB Code:
    1. Dim dat() as String
    2. dat = Split(dat_a)
    I try to call the array value "dat(0)" and I get;
    "Run-time error '9':
    Subscript out of range"

    It then highlights the line that uses the array value "dat(0)".
    [VBCODE]
    Private Sub form1_load()
    If programming = fun then
    MsgBox ("Programming is so much fun!")
    Else
    MsgBox ("Learn to program n00b")
    End If
    End Sub[/VBCODE]

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Programming MMO(Server Issues)

    That would be beacuse dat_a is empty (so Split doesnt have anything to return).

    You need to check that dat_a contains something before you Split it.

  8. #8

    Thread Starter
    New Member dreiecon's Avatar
    Join Date
    Aug 2006
    Location
    Australia
    Posts
    8

    Re: Programming MMO(Server Issues)

    dat_a is set by;
    "Call Socket(Index).GetData(dat_a)"
    [VBCODE]
    Private Sub form1_load()
    If programming = fun then
    MsgBox ("Programming is so much fun!")
    Else
    MsgBox ("Learn to program n00b")
    End If
    End Sub[/VBCODE]

  9. #9
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Programming MMO(Server Issues)

    That's what I assumed, but it doesnt change the fact that dat_a is empty when the error occurs.

    If you provide any text to Split, it will return an array with at least one value - so dat(0) will be valid if text has been provided.

  10. #10

    Thread Starter
    New Member dreiecon's Avatar
    Join Date
    Aug 2006
    Location
    Australia
    Posts
    8

    Re: Programming MMO(Server Issues)

    Thanks for your help.

    I've managed to fix this =D

    What the problem was is, I received the data sent by the client as "??????????" so I added "Dim dat_a as String" and it worked with a bit of tweaking.


    Thanks so much for your help.
    [VBCODE]
    Private Sub form1_load()
    If programming = fun then
    MsgBox ("Programming is so much fun!")
    Else
    MsgBox ("Learn to program n00b")
    End If
    End Sub[/VBCODE]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width