Raised This Month: $12 Target: $400
 3% 

Is OnClientDisconnect called when map ends?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Sammy-ROCK!
Senior Member
Join Date: Jun 2008
Location: Near Mrs.Lag
Old 10-20-2008 , 16:25   Is OnClientDisconnect called when map ends?
Reply With Quote #1

Title says all. Thanks.
Sammy-ROCK! is offline
bl4nk
SourceMod Developer
Join Date: Jul 2007
Old 10-20-2008 , 16:27   Re: Is OnClientDisconnect called when map ends?
Reply With Quote #2

Why not test it out?
bl4nk is offline
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 10-20-2008 , 16:28   Re: Is OnClientDisconnect called when map ends?
Reply With Quote #3

Im pretty sure its called when the map changes and when a player actually disconnects. map changes seem to disconnect then reconnect the players.
__________________
CrimsonGT is offline
Thingie
Junior Member
Join Date: Oct 2008
Old 10-20-2008 , 16:30   Re: Is OnClientDisconnect called when map ends?
Reply With Quote #4

Do timeouts count as disconnects?
Thingie is offline
naris
AlliedModders Donor
Join Date: Dec 2006
Old 10-20-2008 , 16:31   Re: Is OnClientDisconnect called when map ends?
Reply With Quote #5

Yes, I have also seen that all players get disconnected when the map changes and then the connect again for the next map. At least for TF anyways. One of the more recent bug fixes mentions some cases where OnClientDisconnect() doesn't get called for some odd mod, i think it was Synergy. Apparently, you the client doesn';t have all the correct parts installed for a given map, they get tossed out and OnClientDisconnect() doesn't happen.
naris is offline
Sammy-ROCK!
Senior Member
Join Date: Jun 2008
Location: Near Mrs.Lag
Old 10-20-2008 , 16:32   Re: Is OnClientDisconnect called when map ends?
Reply With Quote #6

I'm planning on doing sql queries to save only when player disconnects but it's threaded so I'm not sure if map changing would reset the thread. I gotta try it out.
Sammy-ROCK! is offline
naris
AlliedModders Donor
Join Date: Dec 2006
Old 10-20-2008 , 16:54   Re: Is OnClientDisconnect called when map ends?
Reply With Quote #7

Oh, You probably DON'T want a threaded query going on when the map changes. Bad things happen. I have code that performs threaded saves, but it switches to non-threaded saves when the map is changing.

Here is the code I use. g_MaspChanging is a bool I set when events that indicate the map is being changed h
Code:
public OnPluginStart()
{
    RegConsoleCmd("changelevel",ChangelevelCommand);
}

public Action:ChangelevelCommand(client,args)
{
    g_MapChanging = true;
    return Plugin_Continue;
}

public OnMapStart()
{
    g_MapChanging = false;
}

bool:SavePlayerData(client, Handle:playerHandle, bool:disconnected)
{
    if (DatabaseAvailable())
    {
        decl String:steamid[64];
        if (GetClientAuthString(client,steamid,sizeof(steamid)))
        {
            // Don't use threaded saves when the map is changing!
            // or the map is about to end
            new timeleft = 0;
            new bool:threaded;
            if (g_MapChanging)
                threaded = false;
            else if (GetMapTimeLeft(timeleft))
                threaded = (timeleft > 60);
            else
                threaded = true;
            new player_ident = GetDatabaseIdent(playerHandle);
            if (player_ident > 0)
            {
                new Handle:raceHandle = GetRaceHandle(GetRace(playerHandle));
                new race_ident        = GetRaceIdent(raceHandle);
                new Settings:bits     = GetClientSettingsBits(client);
                new overall_level     = GetOverallLevel(playerHandle);
                new crystals          = GetCrystals(playerHandle);
                new vespene           = GetVespene(playerHandle);

                if (threaded)
                {
                    // When threading, copy the data first so it can't
                    // get freed while we are using it!
                    new Handle:playerData;
                    if (disconnected)
                        playerData = playerHandle;
                    else
                        playerData = ClonePlayer(playerHandle);

                    new Handle:dataPack = CreateDataPack();
                    WritePackCell(dataPack, client);
                    WritePackCell(dataPack, _:playerData);
                    WritePackCell(dataPack, player_ident);
                    ResetPack(dataPack);

                    decl String:SQLString[512];
                    Format(SQLString,sizeof(SQLString),
                           "UPDATE sc_players SET race_ident=%d, crystals=%d, vespene=%d, overall_level=%d, settings=%d, last_update=current_timestamp WHERE player_ident = %d",
                           race_ident, crystals, vespene, overall_level, bits, player_ident);

                    SQL_TQuery(g_DbHandle, SQL_UpdatePlayer, SQLString, dataPack);

                    if (playerData != playerHandle)
                    {
                        // Assume save will work and mark playerHandle data saved.
                        new raceId = GetRace(playerHandle);
                        new upgradeCount = GetUpgradeCount(raceHandle);
                        for(new upgrade=0;upgrade<upgradeCount;upgrade++)
                        {
                            new upgradeLevel = GetUpgradeLevel(playerHandle,raceId,upgrade);
                            SetSavedUpgradeLevel(playerHandle,raceId,upgrade,upgradeLevel);
                        }
                        SetDatabaseSaved(playerHandle,1);
                    }
                    return false;
                }
                else
                {
                    decl String:error[256];
                    error[0] = '\0';

                    // Process this query in the main thread
                    SQL_LockDatabase(g_DbHandle);

                    new Handle:dbUpdatePlayerStmtHandle = SQL_PrepareQuery(g_DbHandle, "UPDATE sc_players SET race_ident=?, crystals=?, vespene=?, overall_level=?, settings=?, last_update=current_timestamp WHERE player_ident = ?", error, sizeof(error));
                    if (dbUpdatePlayerStmtHandle == INVALID_HANDLE)
                    {
                        LogError("Unable to prepare Player Update: %s", error);
                        SQL_UnlockDatabase(g_DbHandle);
                        CloseDatabase();
                        return true;
                    }

                    SQL_BindParamInt(dbUpdatePlayerStmtHandle, 0, race_ident);
                    SQL_BindParamInt(dbUpdatePlayerStmtHandle, 1, crystals);
                    SQL_BindParamInt(dbUpdatePlayerStmtHandle, 2, vespene);
                    SQL_BindParamInt(dbUpdatePlayerStmtHandle, 3, overall_level);
                    SQL_BindParamInt(dbUpdatePlayerStmtHandle, 4, _:bits);
                    SQL_BindParamInt(dbUpdatePlayerStmtHandle, 5, player_ident);
                    if (SQL_Execute(dbUpdatePlayerStmtHandle))
                    {
                        CloseHandle(dbUpdatePlayerStmtHandle);
                        if (SavePlayerRaceData(client, playerHandle, player_ident))
                            SetDatabaseSaved(playerHandle,1);
                    }
                    else
                    {
                        SetDatabaseIdent(playerHandle,-1);
                        SQL_GetError(dbUpdatePlayerStmtHandle, error, sizeof(error));
                        CloseHandle(dbUpdatePlayerStmtHandle);

                        LogError("Unable to update %N's player record, client=%d, handle=%x, ident=%d: %s",
                                 client, client, playerHandle, player_ident, error);

                    }

                    SQL_UnlockDatabase(g_DbHandle);
                }
            }
            else
                return InsertPlayerData(client, playerHandle, disconnected, steamid, threaded);
        }
        else
            LogError("Unable to obtain steamid when saving %N", client);
    }
    return true;
}
naris is offline
CrimsonGT
Veteran Member
Join Date: Oct 2007
Location: Gainesville, FL
Old 10-20-2008 , 17:08   Re: Is OnClientDisconnect called when map ends?
Reply With Quote #8

Players get disconnected SOMETIMES in CSS on map changes too. I was hired to write a pretty involved mod for someone, and I found out the hard way that connections weren't always persistent through a map change.
__________________
CrimsonGT is offline
BAILOPAN
Join Date: Jan 2004
Old 10-20-2008 , 23:59   Re: Is OnClientDisconnect called when map ends?
Reply With Quote #9

OnClientDisconnect is always called for players that are successfully connected. It is always called on mapchange for all successfully connected players.
__________________
egg
BAILOPAN is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 00:21.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode