Raised This Month: $14 Target: $400
 3% 

[ANY] Timezone API


Post New Thread Reply   
 
Thread Tools Display Modes
Author
Accelerator
Senior Member
Join Date: Dec 2010
Location: Russia
Plugin ID:
6308
Plugin Version:
1.0
Plugin Category:
Server Management
Plugin Game:
Any
Plugin Dependencies:
    Servers with this Plugin:
     
    Plugin Description:
    Old 10-22-2018 , 01:09   [ANY] Timezone API
    Reply With Quote #1

    TZ API

    This plugin allows you to determine the time, time offset and daylight saving for a specific time zone.

    Installation:
    • Extract files from the downloaded archive
    • Copy plugins tz_api.sp and tz_example.sp in folder scripting
    • If necessary, download the latest time zone database timezonedb.sql.zip from https://timezonedb.com, convert sql dump from archive to sqlite format using site. After that, change the extension of the resulting file to sq3 and the file name to time_zone.sq3 and copy it with the replacement to the data/sqlite folder.
    • 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.
     * @param dst            Daylight Saving 1 or 0.
     * @param offset        Timezone offset.
     * @return                Timezone time as a unix timestamp, or -1 on failure.
     */
    native int TZ_GetTime(const char[] timezoneint &dst, &offset); 
    For example, there is a tz_example.sp plugin in the scripting folder.
    Attached Files
    File Type: zip tz_api.zip (1.35 MB, 65 views)
    __________________

    Last edited by Accelerator; 12-04-2022 at 07:27.
    Accelerator is offline
    Dragokas
    Veteran Member
    Join Date: Nov 2017
    Location: Country of male slavery
    Old 11-26-2019 , 22:54   Re: [ANY] Timezone API
    Reply With Quote #2

    Excellent work!!! Thanks!

    Edits for tz_api.inc if somebody wants to use external MySQL connection:
    PHP Code:
    public void ConnectDB()
    {
        if (
    SQL_CheckConfig("tzdb"))
        {
            
    Database.Connect(SQL_Callback_Connect"tzdb");
        }
        else
            
    LogError("Database.cfg missing 'tzdb' entry!");
    }

    public 
    void SQL_Callback_Connect (Database dbase, const char[] errorany data)
    {
        if (!
    dbase)
        {
            
    LogError("Failed to connect to database: %s"error);
            return;
        }
        
    db dbase;
        
    db.SetCharset("utf8");

    __________________
    Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch)
    [My plugins] [My tools] [GitHub] [Articles] [Donate]

    [ANY] Accepting paid orders on fixing game crashes (expensive). Doesn't accept orders on plugins!

    Last edited by Dragokas; 11-26-2019 at 22:54.
    Dragokas is offline
    LividBunny
    Member
    Join Date: Mar 2021
    Old 11-28-2022 , 00:59   Re: [ANY] Timezone API
    Reply With Quote #3

    Spoiler


    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.

    Last edited by LividBunny; 11-28-2022 at 01:06.
    LividBunny is offline
    Dragokas
    Veteran Member
    Join Date: Nov 2017
    Location: Country of male slavery
    Old 11-29-2022 , 03:15   Re: [ANY] Timezone API
    Reply With Quote #4

    @LividBunny, there are import examples on download page:
    https://timezonedb.com/download

    Or you can just open .sql file in your database manager (personally, I'm using outdated 'MySQL Query Browser). The button is called there as "File" -> "Open script". Script is embedded in .sql file. Then press "Execute".

    databases.cfg is a file in your SourceMod installation - in /addons/sourcemod/configs.
    __________________
    Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch)
    [My plugins] [My tools] [GitHub] [Articles] [Donate]

    [ANY] Accepting paid orders on fixing game crashes (expensive). Doesn't accept orders on plugins!
    Dragokas is offline
    LividBunny
    Member
    Join Date: Mar 2021
    Old 12-02-2022 , 10:31   Re: [ANY] Timezone API
    Reply With Quote #5

    Quote:
    Originally Posted by Dragokas View Post
    @LividBunny, there are import examples on download page:
    https://timezonedb.com/download

    Or you can just open .sql file in your database manager (personally, I'm using outdated 'MySQL Query Browser). The button is called there as "File" -> "Open script". Script is embedded in .sql file. Then press "Execute".

    databases.cfg is a file in your SourceMod installation - in /addons/sourcemod/configs.
    There's lots more steps before I reach "File > Open Script"

    Edit:I guess I'll just give up on it. Thanks anyway.
    Attached Thumbnails
    Click image for larger version

Name:	Untitled.png
Views:	56
Size:	18.0 KB
ID:	198277  

    Last edited by LividBunny; 12-02-2022 at 10:32.
    LividBunny is offline
    Dragokas
    Veteran Member
    Join Date: Nov 2017
    Location: Country of male slavery
    Old 12-03-2022 , 19:39   Re: [ANY] Timezone API
    Reply With Quote #6

    Definitely, you need to connect to your database before doing anything to it.
    host is ip, username, password are self-explained, other fields are optional, default schema is a database name. If you don't have any yet, you need to login as root and create new database using command:
    Code:
    CREATE DATABASE my_db;
    Then select this database in upper right pane, or using command:
    Code:
    USE my_db;
    After that, import .sql as described before, e.g. from File -> Import Script, or through RCON:
    Code:
    mysql -u USERNAME -pPASSWORD timezonedb < time_zone.sql
    That is a very basic knowledge on working with db.
    https://www.mysqltutorial.org/mysql-create-database/

    Also, there are some settings in MySQL preventing from connection to it outside the localhost. You should handle it by applying GRANT ALL PRIVILEGES command (see below).

    If you are hosting from VPS (Linux) and you don't have installed MySQL service at all, here is a short instruction from me about how to install required packages and make a basic setup of your first database to be able connect remotely:

    The following commands executed in RCON:

    MySQL service installation:
    Refer to: https://timeweb.com/ru/community/art...na-debian-10-1

    Code:
    sudo apt install gnupg
    cd /tmp
    wget https://dev.mysql.com/get/mysql-apt-config_0.8.20-1_all.deb
    sudo dpkg -i mysql-apt-config*
    sudo apt update
    sudo apt install mysql-server
    sudo systemctl status mysql
    mysql_secure_installation
    Database creation:
    Code:
    mysql -u root -pPASSWORD
    where:
    * PASSWORD - is a password of your root user set during MySQL service installation stage.

    PHP Code:
    create database my_db;
    use 
    my_db;
    show tables;
    CREATE USER 'my_user'@'%' IDENTIFIED BY 'my_password';
    GRANT ALL PRIVILEGES ON my_db.* TO 'my_user'@'%';
    // it is required to be able connect using the old method of authentification
    ALTER USER 'my_user'@'%' IDENTIFIED BY 'my_password' PASSWORD EXPIRE NEVER;
    ALTER USER 'my_user'@'%' IDENTIFIED WITH mysql_native_password BY 'my_password';
    FLUSH PRIVILEGES;
    quit 
    where:
    * my_db - name of desired database
    * my_user - name of desired user
    * my_password - desired password of that user

    Surely, some steps could be done by simple clicks using GUI tools like phpMyAdmin.

    Also, you'll have to configure firewall to allow MySQL port connections:
    Code:
    apt-get update
    apt-get install iptables-persistent
    iptables -A OUTPUT -p tcp -m tcp --dport 3306 -j ACCEPT
    dpkg-reconfigure iptables-persistent
    __________________
    Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch)
    [My plugins] [My tools] [GitHub] [Articles] [Donate]

    [ANY] Accepting paid orders on fixing game crashes (expensive). Doesn't accept orders on plugins!

    Last edited by Dragokas; 12-03-2022 at 19:57.
    Dragokas is offline
    Accelerator
    Senior Member
    Join Date: Dec 2010
    Location: Russia
    Old 12-04-2022 , 06:29   Re: [ANY] Timezone API
    Reply With Quote #7

    Updated description. Remade the plugin to use the built-in sqlite3 driver in SourceMod. MySQL is no longer required. I also refused to threading queries to the database, so you should not call a large number of functions at the same time in order to avoid lags on the server.
    __________________
    Accelerator is offline
    Dragokas
    Veteran Member
    Join Date: Nov 2017
    Location: Country of male slavery
    Old 12-04-2022 , 06:53   Re: [ANY] Timezone API
    Reply With Quote #8

    Can you please, leave a link to the old version?
    Because if one wants to use external MySQL database, non-threaded query would be not cool at all.
    __________________
    Expert of CMD/VBS/VB6. Malware analyst. L4D fun (Bloody Witch)
    [My plugins] [My tools] [GitHub] [Articles] [Donate]

    [ANY] Accepting paid orders on fixing game crashes (expensive). Doesn't accept orders on plugins!

    Last edited by Dragokas; 12-04-2022 at 06:54.
    Dragokas is offline
    Accelerator
    Senior Member
    Join Date: Dec 2010
    Location: Russia
    Old 12-04-2022 , 07:20   Re: [ANY] Timezone API
    Reply With Quote #9

    I'll probably add threading queries in the future if anyone requested it.
    __________________

    Last edited by Accelerator; 12-04-2022 at 07:21.
    Accelerator is offline
    Reply


    Thread Tools
    Display Modes

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off

    Forum Jump


    All times are GMT -4. The time now is 14:49.


    Powered by vBulletin®
    Copyright ©2000 - 2023, vBulletin Solutions, Inc.
    Theme made by Freecode