Mirage Source

Free ORPG making software.
It is currently Sat Apr 20, 2024 5:11 am

All times are UTC




Post new topic Reply to topic  [ 16 posts ] 
Author Message
PostPosted: Fri Apr 10, 2009 1:48 am 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
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)


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 1:54 am 
Offline
Pro
User avatar

Joined: Mon May 29, 2006 3:26 pm
Posts: 493
Location: São Paulo, Brasil
Google Talk: blackagesbr@gmail.com
You should not make this. It's not fair.
The players "backup" should be saved for everybody at the same time.

_________________
http://www.blackages.com.br
Image
Dave wrote:
GameBoy wrote:
www.FreeMoney.com
I admit I clicked. I immediately closed upon realizing there was, in fact, no free money.
Robin wrote:
I love you and your computer.Marry me.


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 2:12 am 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
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.


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 2:19 am 
Offline
Persistant Poster
User avatar

Joined: Wed Nov 29, 2006 11:25 pm
Posts: 860
Location: Ayer
Yeah, shouldn't saving at different times be less stressful for the server?

_________________
Image


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 2:31 am 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
Items need to have their own respawn timers, too.

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 3:06 am 
Offline
Pro
User avatar

Joined: Sun Aug 05, 2007 2:26 pm
Posts: 547
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)

_________________
GIAKEN wrote:
I think what I see is this happening:

Labmonkey gets mod, everybody loves him, people find out his code sucks, he gets demoted, then banned, then he makes an engine called Chaos Engine.


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 3:41 am 
Offline
Knowledgeable
User avatar

Joined: Mon May 29, 2006 6:23 pm
Posts: 128
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.


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 4:06 am 
Offline
Pro
User avatar

Joined: Sun Aug 05, 2007 2:26 pm
Posts: 547
ok

_________________
GIAKEN wrote:
I think what I see is this happening:

Labmonkey gets mod, everybody loves him, people find out his code sucks, he gets demoted, then banned, then he makes an engine called Chaos Engine.


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 4:24 am 
Offline
Pro
User avatar

Joined: Mon May 29, 2006 3:26 pm
Posts: 493
Location: São Paulo, Brasil
Google Talk: blackagesbr@gmail.com
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.

_________________
http://www.blackages.com.br
Image
Dave wrote:
GameBoy wrote:
www.FreeMoney.com
I admit I clicked. I immediately closed upon realizing there was, in fact, no free money.
Robin wrote:
I love you and your computer.Marry me.


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 4:51 am 
Offline
Pro
User avatar

Joined: Wed Jun 07, 2006 8:04 pm
Posts: 464
Location: MI
Google Talk: asrrin29@gmail.com
Make it so that every time a character gains exp, check a random number against a predetermined chance to see if the character gets saved. decrease the predetermined chance every time the check fails (to prevent the server from "never" saving the player) and reset it once the character gets saved. This way, at most the player will lose a few kills, a couple dozen or so, but it also is not saving every character all the time. You can also have it save after every quest, every x trades, whatever. you can also include a mass player save function to run in the dead of night if you want.

_________________
Image
Image


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 1:32 pm 
Offline
Knowledgeable

Joined: Sat Jul 08, 2006 8:24 am
Posts: 339
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.


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 4:08 pm 
Offline
Pro
User avatar

Joined: Wed Jun 07, 2006 8:04 pm
Posts: 464
Location: MI
Google Talk: asrrin29@gmail.com
first check, 1 in 6 chance
next chance 1 in 5
next 1 in 4
next 1 in 3
next 1 in 2
next 1 in 1

Eventually the player will get saved, but not every time they gain experience, and not at the same times as other players.

_________________
Image
Image


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 7:38 pm 
Offline
Persistant Poster
User avatar

Joined: Thu Mar 29, 2007 10:30 pm
Posts: 1510
Location: Virginia, USA
Google Talk: hpmccloud@gmail.com
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.

_________________
Nean wrote:
Yes harold. Give it to me.

Image
Image


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 8:18 pm 
Offline
Pro
User avatar

Joined: Tue Nov 13, 2007 2:42 pm
Posts: 509
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.


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 8:31 pm 
Offline
Pro
User avatar

Joined: Wed Jun 07, 2006 8:04 pm
Posts: 464
Location: MI
Google Talk: asrrin29@gmail.com
you have a chance to lose the last 6 kills you made, or the last one, or any in between. I am not going to cry about not getting my last six kills. The only other way to make sure that no one loses any information is to save after every player change, which would cause alot of disk activity and ultimately bog down the game. Look, I'm just trying to provide a way to find a middle ground between arbitrary updates and continuous updates. if you don't like it, then show me something better.

_________________
Image
Image


Top
 Profile  
 
PostPosted: Fri Apr 10, 2009 8:34 pm 
Offline
Pro
User avatar

Joined: Sun Aug 05, 2007 2:26 pm
Posts: 547
the method up top.

_________________
GIAKEN wrote:
I think what I see is this happening:

Labmonkey gets mod, everybody loves him, people find out his code sucks, he gets demoted, then banned, then he makes an engine called Chaos Engine.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group