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

[CS:GO] OnMapStart and SQL problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
blaacky
Senior Member
Join Date: Oct 2012
Old 04-01-2014 , 18:57   [CS:GO] OnMapStart and SQL problem
Reply With Quote #1

When I start my test server, OnMapStart is called, and when I join it, OnMapStart is called again. That doesn't sound right to me. I know the map is literally starting up again to set the "mapgroup". I don't know what that is, but I want to stop it. Also this somewhat ties into my SQL problem where the callback isn't being called, it's just frozen until the next time OnMapStart is called, and then the callback is called twice. Here is an example code.

PHP Code:
#include <sourcemod>

new    String:g_sMapName[64];

new    
Handle:g_DB;

public 
OnPluginStart()
{
    
DB_Connect();
}

public 
OnMapStart()
{
    
GetCurrentMap(g_sMapNamesizeof(g_sMapName));
    
    
CreateCurrentMapID();
}

DB_Connect()
{    
    if(
g_DB != INVALID_HANDLE)
        
CloseHandle(g_DB);
    
    new 
String:error[255];
    
g_DB SQL_Connect("timer"trueerrorsizeof(error));
    
    if(
g_DB == INVALID_HANDLE)
    {
        
LogError(error);
        
CloseHandle(g_DB);
    }
}

CreateCurrentMapID()
{
    
decl String:query[512];
    
FormatEx(querysizeof(query), "INSERT INTO maps (MapName) SELECT * FROM (SELECT '%s') AS tmp WHERE NOT EXISTS (SELECT MapName FROM maps WHERE MapName = '%s') LIMIT 1",
        
g_sMapName,
        
g_sMapName);
    
SQL_TQuery(g_DBDB_CreateCurrentMapID_Callbackquery);
}

public 
DB_CreateCurrentMapID_Callback(Handle:ownerHandle:hndl, const String:error[], any:data)
{
    if(
hndl != INVALID_HANDLE)
    {
        if(
SQL_GetAffectedRows(hndl) > 0)
        {
            
LogMessage("MapID for %s created (%d)"g_sMapNameSQL_GetInsertId(hndl));
        }
    }
    else
    {
        
LogError(error);
    }

Here's what's happening step-by-step:
1. I start the server
2. OnMapStart is called, also calling CreateCurrentMapID
3. The SQL in CreateCurrentMapID isn't calling the SQL callback (frozen)
4. I join the server
5. OnMapStart is called, also calling CreateCurrentMapID
6. The SQL callback from before is now unfrozen and the callback is being called twice

How is this fixed?

Last edited by blaacky; 04-01-2014 at 19:05.
blaacky is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 04-01-2014 , 21:20   Re: [CS:GO] OnMapStart and SQL problem
Reply With Quote #2

CS:GO and L4D(2) servers hibernate when empty and not specified otherwise. During this state everything threaded won't work and the gameserver won't "tick" (so timer callbacks won't fire as well).
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.
Dr. Greg House is offline
blaacky
Senior Member
Join Date: Oct 2012
Old 04-01-2014 , 21:24   Re: [CS:GO] OnMapStart and SQL problem
Reply With Quote #3

That makes sense, but why does the map have to restart?
blaacky is offline
h3bus
AlliedModders Donor
Join Date: Nov 2013
Old 04-03-2014 , 06:00   Re: [CS:GO] OnMapStart and SQL problem
Reply With Quote #4

OnLevelInit would be great to solve that kind of problems but from what I tried it is not called in CSGO
h3bus is offline
tristen620
Junior Member
Join Date: Feb 2012
Old 04-03-2014 , 09:40   Re: [CS:GO] OnMapStart and SQL problem
Reply With Quote #5

A simple bool would help you greatly in this case, and I suggest using them when doing this sort of thing.

Code:
+++bool:g_bMapHasID=false;
public OnMapStart()
{
    GetCurrentMap(g_sMapName, sizeof(g_sMapName));
    
---    CreateCurrentMapID();
+++    if(!g_bMapHasID)
+++      CreateCurrentMapID();
}

public DB_CreateCurrentMapID_Callback(Handle:owner, Handle:hndl, const String:error[], any:data)
{
    if(hndl != INVALID_HANDLE)
    {
        if(SQL_GetAffectedRows(hndl) > 0)
        {
            LogMessage("MapID for %s created (%d)", g_sMapName, SQL_GetInsertId(hndl));
        }
+++        g_bMapHasID=true;
    }
    else
    {
        LogError(error);
+++        g_bMapHasID=false;
    }
}

Last edited by tristen620; 04-03-2014 at 09:41.
tristen620 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 04:21.


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