Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Improvement] Player Update
#1
Currently updating vitals and saving players is all done at the same time for all players. Some code to change that.

Private Type TempPlayerRec
Add the following to the UDT
Code:
LastUpdateVitals As Long
LastUpdateSave As Long

modServerLoop
Change your ServerLoop to the following:
Code:
Public Sub ServerLoop()
Dim i As Long
Dim x As Long
Dim y As Long

Dim Tick As Long

Dim tmr500 As Long
Dim tmr1000 As Long

Dim LastUpdateMapSpawnItems As Long

    ServerOnline = True
    
    Do While ServerOnline
        Tick = GetTickCount
        
        If Tick > tmr500 Then
            ' Check for disconnections
            For i = 1 To MAX_PLAYERS
                If frmServer.Socket(i).State > sckConnected Then
                    Call CloseSocket(i)
                End If
                
                ' Update the player
                If IsPlaying(i) Then
                    OnUpdate i
                End If
            Next
            
            ' Process NPC AI
            UpdateNpcAI
          
            tmr500 = GetTickCount + 500
        End If
        
        If Tick > tmr1000 Then
            ' Handle shutting down server
            If isShuttingDown Then
                Call HandleShutdown
            End If
            
            ' Handles closing doors
            For i = 1 To MAX_MAPS
                If Tick > TempTile(i).DoorTimer + 5000 Then
                    For x = 0 To MAX_MAPX
                        For y = 0 To MAX_MAPY
                            If Map(i).Tile(x, y).Type = TILE_TYPE_KEY Then
                                If TempTile(i).DoorOpen(x, y) = YES Then
                                    TempTile(i).DoorOpen(x, y) = NO
                                    Call SendDataToMap(i, SMapKey & SEP_CHAR & x & SEP_CHAR & y & SEP_CHAR & 0 & END_CHAR)
                                End If
                            End If
                        Next
                    Next
                End If
            Next
            
            tmr1000 = GetTickCount + 1000
        End If
        
        ' Checks to spawn map items every 5 minutes - Can be tweaked
        If Tick > LastUpdateMapSpawnItems Then
            UpdateMapSpawnItems
            LastUpdateMapSpawnItems = GetTickCount + 300000
        End If
        
        Sleep 1
        DoEvents
    Loop
End Sub

modPlayer- JoinGame
Add the following before "End Sub"
Code:
TempPlayer(Index).LastUpdateVitals = GetTickCount + 10000
TempPlayer(Index).LastUpdateSave = GetTickCount + 600000

modPlayer
Add the following sub
Code:
''***************************************
' Events for updating
'***************************************
Sub OnUpdate(ByVal Index As Long)
Dim i As Long
    
    '*****************************
    '**  Checks to save player  **
    '*****************************
    If GetTickCount > TempPlayer(Index).LastUpdateSave Then
        SavePlayer Index
        TempPlayer(Index).LastUpdateSave = GetTickCount + 600000    ' 10 minutes
    End If
          
    '**************************************
    '**  Checks to update player vitals  **
    '**************************************
    If GetTickCount > TempPlayer(Index).LastUpdateVitals Then
        For i = 1 To Vitals.Vital_Count - 1
            If GetPlayerVital(Index, i)  GetPlayerMaxVital(Index, i) Then
                Call SetPlayerVital(Index, i, GetPlayerVital(Index, i) + GetPlayerVitalRegen(Index, i))
                Call SendVital(Index, i)
            End If
        Next
        TempPlayer(Index).LastUpdateVitals = GetTickCount + 5000   ' 5 seconds
    End If
End Sub

So when a player logs in they are set to their own timers. This really helps in saving, not all players being saved at once.

This also helps later on for more advanced features. I've added spell buffs and i use the OnUpdate sub to check if the buff duration is over.

Thoughts / Comments ? I think I'll modify this for a future version of MS. (Waiting on something from DFA before I start)
Reply
#2
You should not make this. It's not fair.
The players "backup" should be saved for everybody at the same time.
Reply
#3
If you have proper error handling, saving the players at different times shouldn't matter. By proper error handling, I mean on all code it will catch and error then try to handle it. If it can't be handled it should shut down the server, in the shut down process it should save all players.
Reply
#4
Yeah, shouldn't saving at different times be less stressful for the server?
Reply
#5
Items need to have their own respawn timers, too.
Reply
#6
It would seem better to just save players when they level up. That way you never loose levels due to server crashes (the most complained about part of server crashes)
Reply
#7
Labmonkey Wrote:It would seem better to just save players when they level up. That way you never loose levels due to server crashes (the most complained about part of server crashes)
That's fine until you have higher level players whose levels are few and far between. By doing that, you are forcing one portion of a playerbase to log out and log back in again to force the server to save them.
Reply
#8
ok
Reply
#9
You can't be 100% sure that you can even handle every bug.
Lets just say you don't have a no-break and then light goes out. IMO the server does not need to save game state every x time. I'm backing up the db every 24h, on the server restart.
If a "unhandleble" error occurs just restore the last day. 24 hours is acceptable.
Reply
#10
Saving players based on whether the dice rolls 6 or not? Sounds fucked up. Instead of saving them ALL at once, or or all unique, just process the first 10% of the indexes online every minute.
Reply
#11
Are you thinking when you post? Saving players on a RANDOM CHANCE? Might as well tell them "You only have a chance you will keep your hard-work safe from server crashes, but eventually you will get more luckier."

Please just think and shitty suggestions won't happen anymore hopefully.
Reply
#12
GIAKEN Wrote:Are you thinking when you post? Saving players on a RANDOM CHANCE? Might as well tell them "You only have a chance you will keep your hard-work safe from server crashes, but eventually you will get more luckier."

Please just think and shitty suggestions won't happen anymore hopefully.

If you're going to provide criticism, don't be a dick about it.
Reply
#13
the method up top.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)