Hello ive got a client/server 2d mmorgp game plaing by us frinds and due to to many copies of the client i
ve tried to reduce the client to be opened to 2 clients per device but is not per device its on the network 2 clients . maybe i do somewhere mistake.
Sub ConnectionRequestCon(ByVal requestID As Long)
On Error Resume Next
Dim check As Integer
Dim LoggedOn As Integer
Dim NewIndex As Integer
Dim RandomCheck As Integer
NewIndex = GetFreeIndex
LogOutProcedure NewIndex
RandomizeConLandLaunch NewIndex
Load Main.Server(NewIndex)
Load Main.EngageTimer(NewIndex)
Main.Server(NewIndex).Accept requestID
AddServerLogText NewIndex & ": Connected [" & Main.Server(NewIndex).RemoteHostIP & "]"
RandomCheck = RandomNumber(1000, 30000)
SetConAuthNumber NewIndex, RandomCheck
Main.Server(NewIndex).SendData "1,Welcome To Xiaspora - " & TotalLogedInUsers & " Users Online" & Chr(13) & "34," & RandomCheck & Chr(13)
DoEvents
Do
check = check + 1
If Main.Server(check).State = 7 And Main.Server(check).RemoteHostIP = Main.Server(NewIndex).RemoteHostIP Then LoggedOn = LoggedOn + 1
Loop Until check = Main.Server.Count
If LoggedOn >= 4 Then CloseCon NewIndex 'with the number 4 reduce the clients per device . when is 7 is unlimited
End Sub
You are looping check
from 1 to Main.Server.Count
and check each Main.Server(check).State
but you probably have unloaded socket controls already.
You have On Error Resume Next
at the top of the code but consider that similar code like this
Dim lCount As Long
On Error Resume Next
If 1 / 0 > 0 Then lCount = lCount + 1
Debug.Print lCount
. . . prints 1
i.e. from If expression OERN gets "next" statement inside the If, no matter that it's on the same line as the If expression.
Now consider what happens when Main.Server(check).State
is checked on an unloaded control. Because of the OERN this one will be counted towards LoggedOn
which is clearly not what you want to do.
With OERN in this case you might want to reverse the If expression like this
If Main.Server(check).State <> 7 Then
'--- do nothing
ElseIf Main.Server(check).RemoteHostIP = Main.Server(NewIndex).RemoteHostIP Then
LoggedOn = LoggedOn + 1
End If
. . . so that when accessing Main.Server(check).State
bombs out it "enters" the If block and there is nothing to do there.