Setting char_var in SQL on disconnect

Post Reply
bluesolarflare
Posts: 129
Joined: Wed May 27, 2015 4:23 pm

Setting char_var in SQL on disconnect

Post by bluesolarflare » Wed Dec 21, 2016 4:07 pm

Hello,

I am looking to have the core set a value in the char_var SQL table on disconnects. What I am trying to do is that when a user disconnects, it sets the epoch current time when the disconnect happens into the character variable table for tracking purposes. Currently to ensure that the time is being counted properly, I have setup a variable called dotime and when I print that variable with show warning, it shows the correct epoch time (example: 1482353944) . However, in the SQL table, it shows a completely different number (1001279688). I figure I am using the wrong integer type or something else is going wrong. Below is the code that I am using in map.cpp two lines under where the Pchar status is STATUS_SHUTDOWN

Code: Select all

    uint32 dotime = (uint32)time(nullptr);
    ShowWarning(CL_RED"Epoch Time Received %u.\n" CL_RESET, dotime); 
    std::string varname;
    const int8* fmtQuery = "INSERT INTO char_vars SET charid = %u, varname = 'disconnect', value = %u ON DUPLICATE KEY UPDATE value = %u;";
    Sql_Query(SqlHandle, fmtQuery, PChar->id, varname, dotime, dotime);

Thanks.

bluesolarflare
Posts: 129
Joined: Wed May 27, 2015 4:23 pm

Re: Setting char_var in SQL on disconnect

Post by bluesolarflare » Tue Jan 10, 2017 11:11 am

Nvm got this to work by using the sql operation "unix_timestamp()" as the value instead of a variable which was the issue.

Post Reply