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

MySQL Polls


Post New Thread Reply   
 
Thread Tools Display Modes
Author
Cep}|{
Member
Join Date: Nov 2009
Plugin ID:
1405
Plugin Version:
1.4
Plugin Category:
General Purpose
Plugin Game:
Any
Plugin Dependencies:
    Servers with this Plugin:
    1 
    Plugin Description:
    In-game polls (on MySQL) - translation your in-game polls to site in realtime.
    Old 01-16-2010 , 01:24   MySQL Polls
    Reply With Quote #1

    Polls mod based on MySQL

    [IMG]http://img341.**************/img341/6471/mysqlpolls.jpg[/IMG]

    Description:

    Mod for in-game voting on MySQL. Easily display the results of voting on your site (in real-time).

    Cvars:

    sm_mysql_polls_version - Plugin version
    sm_mysql_polls_check_client_by "0" - Checking voted client by SteamID or IP. 0 - SteamID, 1 - IP. Default: "0"
    sm_mysql_polls_dbconfig "mysql_polls" - Name of database config in addons/sourcemod/configs/database.cfg. Default: "mysql_polls"
    sm_mysql_polls_enable "1" - Enable\Disable this plugin. Default: "1"
    sm_mysql_polls_prefix "sm_mysql_p" - Table prefix in database. Default: "sm_mysql_p"
    sm_mysql_polls_server_id "1" - Server ID for multiservers polls. Default: "1"


    DB structure description:

    Table prefix_polls:
    `id` - poll ID
    `name` poll name, for your site
    `title` poll title, for in-game poll menu
    `time` time creating a poll, for your site
    `stat` poll status (0 - inactive\1 - active)
    `server_id` server ID for multiservers polls ("1","2","public1" etc.) (see cvars in cfg/sourcemod/mysql_polls.cfg)

    Table prefix_variants:
    `id` - variant ID
    `poll_id` - poll ID
    `name` - variant name, for in-game menu

    Table prefix_votes:
    `id` - vote ID
    `poll_id` - poll ID
    `time` - voted time
    `variant` - variant ID
    `steam` - SteamID player voted
    `ip` - IP player voted
    `name` - nickname player voted

    If there are no tables, they will be created automatically )

    Version history:


    v1.4 (11.19.2010) - Fixed problem with names containing a ' (single quotes)
    and:
    Quote:
    Originally Posted by crazydog
    -It asks the newest questions first
    -Adds an "Ask me Later" option as the first choice in the poll
    -Does not toss up a vote until the player's first death on the server (For our server, I check if mp_friendlyfire is 0 since we use pre round mayhem).
    -Asks 2 questions per client per connection
    Installation:

    1. Edit your addons/sourcemod/configs/databases.cfg file and add a new section (or declare existing in sm_mysql_polls_dbconfig):
    Code:
        "mysql_polls"
        {
            "driver"            "mysql"
            "host"            ""
            "database"      ""
            "user"            ""
            "pass"            ""
            //"timeout"            "0"
            "port"            "3306"
        }
    2. Upload the plugin in the 'addons/sourcemod/plugins/' folder and refrash plugin list or change map or restart server.

    Web-interface - http://forums.alliedmods.net/showpos...7&postcount=13 (Thanks To crazydog)
    Attached Files
    File Type: sp Get Plugin or Get Source (mysql_polls.sp - 1476 views - 8.1 KB)
    __________________

    Last edited by Cep}|{; 11-20-2010 at 01:06. Reason: Update to 1.4
    Cep}|{ is offline
    DarthNinja
    SourceMod Plugin Approver
    Join Date: Mar 2009
    Location: PreThinkHook()
    Old 01-16-2010 , 04:29   Re: MySQL Polls
    Reply With Quote #2

    Will this work in any game or is it specific to CSS for some reason?
    __________________
    DarthNinja is offline
    bobbobagan
    SourceMod Donor
    Join Date: May 2007
    Location: New Zealand
    Old 01-16-2010 , 05:07   Re: MySQL Polls
    Reply With Quote #3

    I quickly looked over the code, and from what I can tell it has nothing specific to CS:S, although the plugin author may only want to support it for CS:S. You could always give it a try on TF2.
    __________________
    bobbobagan is offline
    Send a message via Skype™ to bobbobagan
    Cep}|{
    Member
    Join Date: Nov 2009
    Old 01-16-2010 , 05:20   Re: MySQL Polls
    Reply With Quote #4

    Sorry, i did not test for other. I think it will work on other gameservers. )

    Last edited by Cep}|{; 01-16-2010 at 05:24.
    Cep}|{ is offline
    DarthNinja
    SourceMod Plugin Approver
    Join Date: Mar 2009
    Location: PreThinkHook()
    Old 01-16-2010 , 14:01   Re: MySQL Polls
    Reply With Quote #5

    Quote:
    Originally Posted by Cep}|{ View Post
    Sorry, i did not test for other. I think it will work on other gameservers. )
    I'll drop it on my server tonight, I was thinking about writing this exact plugin a few weeks ago
    __________________
    DarthNinja is offline
    psychonic

    BAFFLED
    Join Date: May 2008
    Old 02-03-2010 , 11:20   Re: MySQL Polls
    Reply With Quote #6

    @Cep}|{
    Please use Sourcemod's MAXPLAYERS define rather than creating your own.
    psychonic is offline
    NovaDenizen
    Junior Member
    Join Date: Jan 2010
    Old 02-03-2010 , 22:23   Re: MySQL Polls
    Reply With Quote #7

    I'm not the most experienced sourcemod programmer, so please take these criticisms with a grain of salt.

    All of the queries are non-threaded. Normally a few SQL queries that take 10ms each to complete are not much of a problem. But when one of those queries winds up taking 500ms, it can result in a poor gaming experience. Whenever possible, you should use SQL_TQuery instead of SQL_Query or SQL_FastQuery, because it keeps the delays from slow queries out of the main server thread.

    The plugin makes many calls to SQL_Query without ever calling CloseHandle on the results. This is a memory leak.

    The plugin makes redundant queries. It would be better if the active polls were queried OnMapStart, then stored in a DataPack. But this isn't such a big deal if the queries are made threaded.

    The tables are not designed well. The 'id' field in the votes table is unnecessary, and poor choices for primary key. were made in all the tables.

    Here's what I recommend for the table structure:
    CREATE TABLE IF NOT EXISTS `%s_polls` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `name` varchar(128 ) NOT NULL,
    `title` varchar(128 ) NOT NULL,
    `time` int(11) NOT NULL,
    `stat` int(1) NOT NULL,
    `server_id` varchar(32) NOT NULL,
    PRIMARY KEY (`id`),
    INDEX (`stat`, `time` DESC)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;", sm_mysql_polls_prefix);

    I added an index on the (`stat`, `time`) tuple to make it faster to find active questions, ordered by time.

    CREATE TABLE IF NOT EXISTS `%s_variants` (
    `id` int(11) NOT NULL AUTO_INCREMENT,
    `poll_id` int(11) NOT NULL,
    `name` varchar(128 ) NOT NULL,
    PRIMARY KEY (`poll_id`, `id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8
    I made the primary key a joint one between poll_id and id. This way queries for variants will be efficient.

    CREATE TABLE IF NOT EXISTS `%s_votes` (
    `poll_id` int(11) NOT NULL,
    `time` int(11) NOT NULL,
    `variant` int(11) NOT NULL,
    `steam` varchar(32) NOT NULL,
    `ip` varchar(15) NOT NULL,
    `name` varchar(128 ) NOT NULL,
    INDEX (`steam`, `poll_id`),
    INDEX (`ip`, `poll_id`),
    INDEX (`poll_id`, `variant`)
    ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
    I removed the id field and the primary key. The (`steam`, `poll_id`) and (`ip`, `poll_id`) indexes will speed the queries that test the existence of votes. The (`poll_id`, `variant`) will make counting votes fast.

    The plugin uses a series of several queries to find the first poll that a user has not answered. This could instead be done with a single query.

    This one assumes you are checking identity by steam id. Checking by ip is very similar. This query returns the id of the first poll that has not been answered by a user, or it returns no rows when a user has answered all the poll questions.
    SELECT %s_polls.id FROM %s_polls LEFT JOIN (SELECT poll_id, variant FROM %s_votes WHERE `steam` = '%s') AS votes ON %s_polls.id = votes.poll_id WHERE stat = 1 AND variant IS NULL ORDER BY %s_polls.time DESC LIMIT 1

    Hope this helps.
    NovaDenizen is offline
    Cep}|{
    Member
    Join Date: Nov 2009
    Old 02-05-2010 , 08:39   Re: MySQL Polls
    Reply With Quote #8

    Quote:
    Originally Posted by psychonic View Post
    @Cep}|{
    Please use Sourcemod's MAXPLAYERS define rather than creating your own.
    Done.
    __________________
    Cep}|{ is offline
    psychonic

    BAFFLED
    Join Date: May 2008
    Old 02-15-2010 , 10:53   Re: MySQL Polls
    Reply With Quote #9

    Quote:
    Originally Posted by Cep}|{ View Post
    Done.
    Did you not upload the edited version?
    psychonic is offline
    Cep}|{
    Member
    Join Date: Nov 2009
    Old 02-15-2010 , 13:24   Re: MySQL Polls
    Reply With Quote #10

    Sorry. I upload a new file on 02.05.2010, but accidentally uploaded the old.
    I am upload new version now.
    __________________
    Cep}|{ 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 21:44.


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