Skocz do zawartości

Nowy szablon forum

mygo.pl

Stworzyliśmy dla Was nowy wygląd forum. Z pewnością znajdziesz rzeczy, które wg Ciebie mogą zostać zmienione - wspomnij o tym w specjalnym wątku.

Czytaj więcej

Jak założyć własną sieć

serwerów CS

Zastanawiasz się nad prowadzeniem własnej sieci serwerów? Przeczytaj podstawowe informacje, na które należy zwrócić uwagę, przy takim projekcie.

Czytaj więcej

Tworzymy spis sieci

dodaj swoją

Dodaj sieć do której należysz, pozwoli to na promocję i budowę ogólnopolskiej bazy sieci CS.

Czytaj więcej

[ANY] Timezone API


MYGO.pl
 Udostępnij

Rekomendowane odpowiedzi

  • RSSy
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 iQueryNumint 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
File Type: sp Get Plugin or Get Source (tz_api.sp - 3.5 KB)
File Type: inc tz.inc (916 Bytes)

Wyświetl pełny artykuł

Odnośnik do komentarza
Udostępnij na innych stronach

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ę
 Udostępnij

  • Ostatnio przeglądający   0 użytkowników

    • Brak zarejestrowanych użytkowników przeglądających tę stronę.
×
×
  • Dodaj nową pozycję...