Spoiler
Quote:
Originally Posted by Accelerator
TZ API
This plugin allows you to determine the time, time offset and daylight saving for a specific time zone.
Need MySQL database!
Installation:- Download plugin sourceand inc file.
- Place tz_api.sp to scripting folder, tz.inc to scripting/include folder.
- Compile .smx file and place in plugins folder
- Download last database timezones timezonedb.sql.zip from https://timezonedb.com
- Import MySQL dump timezonedb.sql
- Edit your databases.cfg file and add a section with the following information:
Code:
"tzdb"
{
"driver" "mysql"
"host" "your_host"
"database" "your_db"
"user" "your_user"
"pass" "your_pass"
}
- Now you can use the functions below.
API:
PHP Code:
// tz.inc/** * Gets the timezone time as a unix timestamp. * * @param timezone Timezone to determine the timestamp. * @return Query num, or -1 on failure. */native int TZ_GetTime(const char[] timezone);/** * Gets the timezone Daylight Saving. * * @param timezone Timezone to determine the DST. * @return Query num, or -1 on failure. */native int TZ_GetTimeDST(const char[] timezone);/** * Gets the timezone offset. * * @param timezone Timezone to determine the offset. * @return Query num, or -1 on failure. */native int TZ_GetTimeOffset(const char[] timezone);/** * Callback for receiving asynchronous database query results. * * @param iQueryNum Query num. * @param iRetValue Result answer received from the query. */forward void TZ_OnQueryFinished(int iQueryNum, int iRetValue);
Examples:
Code:
#include <sourcemod>
#include <tz>
int iQuery; // For save query num
public void OnPluginStart()
{
RegConsoleCmd("sm_tztime", cmd_tztime);
}
public Action cmd_tztime(int client, int args)
{
char sTemp[64];
GetCmdArg(1, sTemp, sizeof(sTemp));
iQuery = TZ_GetTime(sTemp);
}
public void TZ_OnQueryFinished(int iQueryNum, int iRetValue)
{
if (iQuery == iQueryNum)
{
char sTemp[128];
FormatTime(sTemp, sizeof(sTemp), "%d/%m/%Y - %H:%M:%S", iRetValue);
PrintToServer(sTemp);
}
}
Output:
Code:
sm_tztime Europe/Moscow
22/10/2018 - 08:03:56
With using GeoIP2 extension:
Code:
#include <sourcemod>
#include <geoip>
#include <tz>
int iQuery; // For save query num
public void OnPluginStart()
{
RegConsoleCmd("sm_tztime", cmd_tztime);
}
public Action cmd_tztime(int client, int args)
{
char sTemp[64];
GetCmdArg(1, sTemp, sizeof(sTemp));
if (GeoipTimezone(sTemp, sTemp, sizeof(sTemp))) // Get timezone and rewrite sTemp variable
iQuery = TZ_GetTime(sTemp);
}
public void TZ_OnQueryFinished(int iQueryNum, int iRetValue)
{
if (iQuery == iQueryNum)
{
char sTemp[128];
FormatTime(sTemp, sizeof(sTemp), "%d/%m/%Y - %H:%M:%S", iRetValue);
PrintToServer(sTemp);
}
}
Output (America/Chicago on the basis IP):
Code:
sm_tztime 66.220.89.1
22/10/2018 - 00:06:51
|
Hey bud, I'd like to setup this API of yours but...
these 2 steps have me stumped due to lack of information.
Code:
Import MySQL dump timezonedb.sql
Edit your databases.cfg file and add a section with the following information:
Could you clarify as to:
Import how what do I do?
Where is this databases.cfg file?
A bit of clarification for others that might want to use it and don't know anything about coding.
cheers.