[EO 2.0] Disconnect Inactive Users

This is a pretty easy edit, and it’s all server-sided.

First, go to modConstants and chuck this anywhere.

Public Const TIMEOUT_DURATION As Long = 5000 ' 5 seconds

Now, go to modTypes and look for TempPlayerRec. Add this at the bottom.

    LastActive As Long

Look for the sub “HandleData(ByVal index As Long, ByRef Data() As Byte)”

Right before

CallWindowProc HandleDataSub(MsgType), index, Buffer.ReadBytes(Buffer.Length), 0, 0

put there

TempPlayer(index).LastActive = GetTickCount

Finally, go to your gameloop and look for the lines

        ' Check for disconnections every half second
        If Tick > tmr500 Then
            For i = 1 To MAX_PLAYERS

Put this right after it.

                If IsPlaying(i) Then
                    ' Check to see if they've been inactive for too long.
                    If Tick - TempPlayer(i).LastActive > TIMEOUT_DURATION And TempPlayer(i).LastActive <> 0 Then Call CloseSocket(i)
                End If

Save, and compile; you’re done!

Will this work for EO 3 also?



Great 😄

Why check it every 25ms? Why not every second?

It’s just a simple check inside a pre-existing for statement, so it won’t really make a visible difference on performance. But, I suppose it would be proper to make it every second. I’ll update the tutorial.

EDIT: Actually, every half a second should be better. I updated the tutorial.

Log in to reply