RSSy MYGO.pl Opublikowano Październik 22, 2018 o 05:09 RSSy Udostępnij Opublikowano Październik 22, 2018 o 05:09 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 Attached Files Get Plugin or Get Source (tz_api.sp - 3.5 KB) tz.inc (916 Bytes) Wyświetl pełny artykuł Odnośnik do komentarza Udostępnij na innych stronach Więcej opcji udostępniania...
Rekomendowane odpowiedzi
Jeśli chcesz dodać odpowiedź, zaloguj się lub zarejestruj nowe konto
Jedynie zarejestrowani użytkownicy mogą komentować zawartość tej strony.
Zarejestruj nowe konto
Załóż nowe konto. To bardzo proste!
Zarejestruj sięZaloguj się
Posiadasz już konto? Zaloguj się poniżej.
Zaloguj się