Expand|Select|Wrap|Line Numbers
- 'Enable listening on port 25001
- Private Sub Form_Load()
- Dim i As Integer
- packetDelimiter = Chr$(0)
- Set dbdata = OpenDatabase(App.Path & "/data/data.mdb") ' opens database file
- RoomLimitNumber = 0
- ItemLimitNumber = 0
- Call LoadRooms
- 'Pause
- For i = 1 To 50
- DoEvents
- Next i
- Call LoadItems
- 'Load all the sockets and timers
- WStcpServer(0).LocalPort = 25001
- WStcpServer(0).Listen
- num = 0 'User count
- End Sub
- 'When a connection is recieved, goto verifying stages
- Private Sub WStcpServer_ConnectionRequest(Index As Integer, ByVal requestID As Long)
- num = num + 1
- Load WStcpServer(num)
- Load Timer3(num)
- Load tmrrefresh(num)
- WStcpServer(num).Accept requestID
- 'Add a user to the arrays. Prevents making a 'limit' to the amount of users you can have.
- MsgSend = "¿caut¶" & "Verify" 'Ask for verification
- blnRetVal = WinsockSend(WStcpServer(num), MsgSend)
- End Sub
- 'Preform this when a client closes or disconnects
- Private Sub WStcpServer_Close(Index As Integer)
- Dim i As Integer
- If Not users(Index) = "" Then 'If there was no connection or bad login, then don't do this, otherwise continue
- txtMain.Text = txtMain.Text & "Disconnected: " & WStcpServer(Index).RemoteHostIP & ": " & users(Index) & vbCrLf
- For i = WStcpServer.LBound + 1 To WStcpServer.UBound
- If userroom(i) = userroom(Index) Then
- If users(i) = users(Index) Then
- Else
- 'Leave the game message
- MsgSend = "~g" & users(Index) & " has just left the game!"
- blnRetVal = WinsockSend(WStcpServer(i), MsgSend)
- End If
- End If
- Next
- users(Index) = "" 'Clear the username from the users. Frees up a socket.
- End If
- WStcpServer(Index).Close
- Unload WStcpServer(Index)
- Unload Timer3(Index)
- Unload tmrrefresh(Index)
- num = num - 1
- End Sub
and basicly something id use would be..
Expand|Select|Wrap|Line Numbers
- 'Chat Sub
- Private Sub PublicChat(ByVal Index As Integer, Comarray() As String, ComI As Integer)
- Dim i As Integer
- 'Send to all users in room
- For i = WStcpServer.LBound + 1 To WStcpServer.UBound
- If userroom(i) = userroom(Index) Then 'In the room?
- MsgSend = "~yFrom " & "~w" & users(Index) & "~y: " & Comarray(ComI)
- blnRetVal = WinsockSend(WStcpServer(i), MsgSend)
- Else
- End If
- Next
- End Sub
Personally the getdata is fine, but its the sockets. I do not know how to move or skip sockets that aren't in use. Another example would be 2 people on, one disconnects, the first person disconnects.. so person on socket 2 other person cannot talk because its trying to send the data to a invalid socket (thinking its socket 1 I believe) Something like that.. Any help? Need more info?