25.02.2013, 13:53
pawn Код:
stock NS-><EndSession(pid)> {
new tmp[64];
mysql_format(dbhandle, tmp, "UPDATE `%s` SET session_end = NOW() WHERE id = %d", dbtables[TB_SESSIONS], GetPVarInt(pid, "session_id"));
mysql_function_query(dbhandle, tmp, false, "", "");
//Kill session
SetPVarInt(pid, "session_end", 0);
SetPVarInt(pid, "session_start", 0);
return 1;
}
pawn Код:
stock NS-><EndAllSessions()> {
//No players connected
if(!Iter_Count(Player)) return 1;
#define QLEN (511)
new tmp[QLEN];
format(tmp, sizeof tmp, "UPDATE `%s` SET session_end = NOW() WHERE id IN (", dbtables[TB_SESSIONS]);
new j = strlen(tmp), last = Iter_Last(Player), len;
foreach(new pid : Player) {
if(GetPVarInt(pid, "session_start")) {
//Id is bigint(20)
new uid[21];
//User id as a string
valstr(uid, GetPVarInt(pid, "uid"));
len = strlen(uid);
new bool:isLast = pid == last;
//Current index + id length + comma separator >= string length - ')'
if(j + len + (isLast ? 0 : 1) >= QLEN - 1) return NS-><EndAllSessions()>;
j += len;
strcat(tmp, uid);
if(!isLast) {
tmp[++j] = ',';
}
//Kill session
SetPVarInt(pid, "session_start", 0);
SetPVarInt(pid, "session_end", 0);
}
}
#undef QLEN
tmp[j] = ')';
mysql_function_query(dbhandle, tmp, false, "", "");
return 1;
}