Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[Experimental] Server/Client Player Movement Desync Fix


balliztik1
 Share

Recommended Posts

Current Status: Stable (Thanks to Robin's buffer system)

The so-called "map freezing" bug, as Robin pointed out, has to do with the server and client becoming unsynchronized. This is due to the way Eclipse handles movement. The client tells the player that they have moved, then sends that data to the server. The problem with this is if there is a Spork in lag suddenly, the client may register a move or two, but the server won't be able to keep up, making the player's location, to the client, a space or two ahead of where they are really standing. To fix this problem, it's just a matter of sending the player their coordinates.

**Warning: This fix is highly experimental and lacks extensive testing. I suggest you either back up the subs that we'll be replacing, or comment out the old code so you can revert to it later if need be.**

Client first. Go into modGameLogic and find the CanMove function. Find this:

```
    If y < 0 Then
```
Replace that whole If-Elseif block with this:

```
    If X > MAX_MAPX Then
        If Map(GetPlayerMap(MyIndex)).Right > 0 Then
            Exit Function
        Else
            CanMove = False
        End If
    End If

    If X < 0 Then
        If Map(GetPlayerMap(MyIndex)).Left > 0 Then
            Exit Function
        Else
            CanMove = False
        End If
    End If

    If y > MAX_MAPY Then
        If Map(GetPlayerMap(MyIndex)).Down > 0 Then
            Exit Function
        Else
            CanMove = False
        End If
    End If

    If y < 0 Then
        If Map(GetPlayerMap(MyIndex)).Up > 0 Then
            Exit Function
        Else
            CanMove = False
        End If
    End If
```
This will allow the player to trigger a move into spaces outside the map boundaries. Don't worry, the server will catch this. The problem before is that the server wasn't able to catch the difference because the client freezes itself when it hits the map edge. This way, the client sends the movement anyway, even if it's Radicchio. The server knows better.

Next, head to the HandleData sub in modHandleData. Add this packet case:

```
    If (casestring = "playernewxy") Then
        NewPosX = Val(parse(1))
        NewPosY = Val(parse(2))
        IsNewPos = True

        Exit Sub
    End If
```
In modGameLogic, find the GameLoop procedure and look for this:
```
Call CheckMovement
```Paste this under it:
```
            ' Check if X and Y is the same
            If Player(MyIndex).Moving > 0 Then
                If IsNewPos = True Then
                    If Not GetPlayerX(MyIndex) = NewPosX Then SetPlayerX MyIndex, NewPosX
                    If Not GetPlayerY(MyIndex) = NewPosY Then SetPlayerY MyIndex, NewPosY
                    IsNewPos = False
                End If
            End If
```Finally, open up modGlobals and add these variables:
```
' Position buffer
Public NewPosX As Long
Public NewPosY As Long
Public IsNewPos As Boolean
```Now, open the server source. We'll need a sub to send that packet over. Create this in modServerTCP:

```
Sub SendPlayerNewXY(ByVal index As Long)
    Call SendDataTo(index, "PLAYERNEWXY" & SEP_CHAR & GetPlayerX(index) & SEP_CHAR & GetPlayerY(index) & END_CHAR)
End Sub
```
Now, all we do is call it. Simply find this line in the PlayerMove sub in modGameLogic:

```
        packet = "playermove" & SEP_CHAR & index & SEP_CHAR & GetPlayerX(index) & SEP_CHAR & GetPlayerY(index) & SEP_CHAR & GetPlayerDir(index) & SEP_CHAR & Movement & SEP_CHAR & END_CHAR
```
It'll be in there 4 times in the default source. Paste this below that:

```
        Call SendPlayerNewXY(index)
```
That'll make sure to update the player's movements.

And that should do it.
Link to comment
Share on other sites

  • Replies 54
  • Created
  • Last Reply

Top Posters In This Topic

This will create a lot of movement lag for anyone who has over 50 latency.

Keep the CanMove sub, allow the client to handle movement for itself, but when the server sends the movement packet to everyone else on the map, send a small packet to the player who moved telling it what X and Y the player has on the server. If it's not the same as in the client, simply modify the position of the player in their own client.
Link to comment
Share on other sites

Alright, thanks a ton, Robin. This looks a lot cleaner now. It took some modifying of the CanMove function to stop the client from loading the map, and a couple new packets, but it's much more efficient.

I'll be modifying the code momentarily.
Link to comment
Share on other sites

Replace:

```
    If (casestring = "playernewxy") Then
        X = Val(parse(1))
        y = Val(parse(2))

        Call SetPlayerX(MyIndex, X)
        Call SetPlayerY(MyIndex, y)

        Exit Sub
    End If
```
With:

```
    If (casestring = "playernewxy") Then
        X = Val(parse(1))
        Y = Val(parse(2))

        If not GetPlayerX(index) = X then Call SetPlayerX(MyIndex, X)
        If not GetPlayerY(index) = Y then Call SetPlayerY(MyIndex, Y)

        Exit Sub
    End If
```
Re-setting the X and Y is a waste if they're already the same.
Link to comment
Share on other sites

hmm… first it errors on compile, saying that index is not right, so, i dim it, and that solves it.

but then whenever i try to walk, it errors too :/
error code is "subscript out of range" aka rte 9

any idea whats going on?

Damian666

btw, this error is only client sided, server runs as normal.
Link to comment
Share on other sites

Dimming something that doesn't exist is a very stupid thing to do.

The problem was in the code I posted, which is quite funny.

```
        If not GetPlayerX(index) = X then Call SetPlayerX(MyIndex, X)
        If not GetPlayerY(index) = Y then Call SetPlayerY(MyIndex, Y)
```
Index should be MyIndex.
Link to comment
Share on other sites

I just made the same code (well it does the same) some time ago, it works.

The bug it self is irritating, for f.e. NPC talking / PvP.
But trough this fix you get warped all the time with only a server ping of 60! I think this is pretty much more annoying then having to retype /refresh a few times.

We were thinking of coding our server into C++ or Java, simply to build up the speed, as this is the only problem for this issue, any suggestions?
Link to comment
Share on other sites

@Admiral:

> Use Solar Eclipse when it comes out, since it's in Java? XD

You must be kidding Admiral, I'm not waiting for a new engine to come out or whatever Solar Eclipse is.
Aura is already a very developped game with TONS of source edits.

The question was if a Java/c++ server is going to fix this issue
Link to comment
Share on other sites

@Tyr:

> You must be kidding Admiral, I'm not waiting for a new engine to come out or whatever Solar Eclipse is.
> Aura is already a very developped game with TONS of source edits.
>
> The question was if a Java/c++ server is going to fix this issue

No worries mate (though, everything is virtually 100% compatible, from TE to EE2.8)
But how can you turn down 3D?

I think I remember HM saying that the reason the server is so laggy, is because of the datatype (does it use integer or something?) that it uses to send the packets, and he said that if you sent the packets as characters, it would reduce lag.
Link to comment
Share on other sites

@Tyr:

> I just made the same code (well it does the same) some time ago, it works.
>
> The bug it self is irritating, for f.e. NPC talking / PvP.
> But trough this fix you get warped all the time with only a server ping of 60! I think this is pretty much more annoying then having to retype /refresh a few times.
>
> We were thinking of coding our server into C++ or Java, simply to build up the speed, as this is the only problem for this issue, any suggestions?

Have you actually read the fix, or tried this code?

It obviously doesn't warp you at all. It simply checks, after every step, that the client is synced properly. If not, it'll modify the position.

Please read through the thing before making assumptions.
Link to comment
Share on other sites

Of course I did robin and yes i read it trough I know what it does, I even made this sort of fix before.

I'm hopping around the screens like a bunny, let say it that way :)
Server is for me around a 60-65 ping, which is pretty low for MMO's
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share


×
×
  • Create New...