initial commit, still not done but getting there next week if time left over

This commit is contained in:
jenzur 2020-04-08 23:15:46 +02:00
parent 124a190ac8
commit 15285e058d

View File

@ -0,0 +1,822 @@
#pragma semicolon 1
#define DEBUG
#define PLUGIN_AUTHOR "jenz"
#define PLUGIN_VERSION "1.00"
#define generic_length 256
#include <sourcemod>
#include <sdktools>
#include <PlayerManager>
int admin_editing[MAXPLAYERS + 1];
int server_port;
char admin_table_edit[generic_length];
char admin_table_coloumn_edit[generic_length];
Database database_connection;
Database database_hlstats_connection;
public Plugin myinfo =
{
name = "Unloze ingame polls",
author = PLUGIN_AUTHOR,
description = "ingame polls",
version = PLUGIN_VERSION,
url = "www.unloze.com"
};
public void OnPluginStart()
{
//reg Cmds
RegConsoleCmd("sm_poll", cmd_polls, "Poll menu for unloze");
RegConsoleCmd("sm_polls", cmd_polls, "Poll menu for unloze");
RegConsoleCmd("say", cmd_say);
//adm cmds
RegAdminCmd("sm_poll_commands", cmd_poll_commands, ADMFLAG_GENERIC);
//mysql con
sql_start_connection();
OnMapStart();
}
public void OnMapStart()
{
server_port = GetConVarInt(FindConVar("hostport"));
mysql_find_poll_commands();
}
public int MenuHandler1(Menu menu, MenuAction action, int client_, int selection)
{
if (IsValidClient(client_))
{
switch(action)
{
case MenuAction_Select:
{
if (!selection)
polladminmenu(client_);
else
{
admin_editing[client_] = 5;
mysql_get_polls("vote", client_);
}
}
case MenuAction_End:
{
PrintToChatAll("menu action end 1");
if (menu != INVALID_HANDLE)
delete menu;
}
}
}
}
public int MenuHandler2(Menu menu, MenuAction action, int iclient2, int selection)
{
if (IsValidClient(iclient2))
{
switch(action)
{
case MenuAction_Select:
{
admin_editing[iclient2] = selection;
//PrintToChat(iclient2, "client: %N \nclient[admin_editing]: %i", iclient2, admin_editing[iclient2]);
if (selection == 1)
{
PrintToChat(iclient2, "Write poll question into the chat, type exit to abort");
}
else
{
char pollchoice[16];
menu.GetItem(selection, pollchoice, sizeof(pollchoice));
mysql_get_polls(pollchoice, iclient2);
}
}
case MenuAction_End:
{
admin_editing[iclient2] = 0;
PrintToChatAll("menu action end 2");
if (menu != INVALID_HANDLE)
delete menu;
}
}
}
}
public void editpoll(int client_edit, char []table_name_info)
{
Menu menu2 = new Menu(editpollmenu);
menu2.SetTitle("Poll editing: %s", table_name_info);
menu2.AddItem(table_name_info, "Add option");
menu2.AddItem(table_name_info, "Rewrite option");
menu2.AddItem(table_name_info, "Remove option");
menu2.AddItem(table_name_info, "Add command to options");
menu2.AddItem(table_name_info, "playtime requirement");
menu2.ExitButton = true;
menu2.Display(client_edit, MENU_TIME_FOREVER);
}
public int menu_vote_poll_options(Menu menu, MenuAction action, int iclient, int selection)
{
if (IsValidClient(iclient))
{
switch(action)
{
case MenuAction_Select:
{
char info[32];
menu.GetItem(selection, info, sizeof(info));
mysql_insert_poll_vote(iclient, info, admin_table_edit[iclient]);
}
case MenuAction_End:
{
admin_editing[iclient] = 0;
if (menu != INVALID_HANDLE)
delete menu;
}
}
}
}
public int MenuHandler3(Menu menu, MenuAction action, int iclient3, int selection)
{
if (IsValidClient(iclient3))
{
switch(action)
{
case MenuAction_Select:
{
char info[32];
menu.GetItem(selection, info, sizeof(info));
PrintToChat(iclient3, "admin_editing[iclient3]: %i \ninfo: %s", admin_editing[iclient3], info);
switch(admin_editing[iclient3])
{
case 2:
{
//edit poll
editpoll(iclient3, info);
}
case 3:
{
//enable or disable poll
mysql_enable_disable_poll(iclient3, info);
}
case 4:
{
//delete poll
mysql_delete_poll(iclient3, info);
}
case 5:
{
//vote poll
mysql_vote_poll(iclient3, info);
}
}
}
case MenuAction_End:
{
admin_editing[iclient3] = 0;
PrintToChatAll("menu action end 3");
if (menu != INVALID_HANDLE)
delete menu;
}
}
}
}
public int menu_edit_poll_options(Menu menu, MenuAction action, int iclient4, int selection)
{
if (IsValidClient(iclient4))
{
switch(action)
{
case MenuAction_Select:
{
char info[32];
menu.GetItem(selection, info, sizeof(info));
if (StrContains(admin_table_coloumn_edit, "rewrite") != -1)
{
PrintToChat(iclient4, "Rewrite the option into chat. Type exit to abort");
Format(admin_table_coloumn_edit, sizeof(admin_table_coloumn_edit), info);
admin_editing[iclient4] = 8;
}
else if (StrContains(admin_table_coloumn_edit, "remove") != -1)
{
mysql_remove_poll_option(iclient4, info, admin_table_edit);
}
else if (StrContains(admin_table_coloumn_edit, "add command option to") != -1)
{
PrintToChat(iclient4, "Write the command related to option %s into the chat. Type exit to abort", info);
Format(admin_table_coloumn_edit, sizeof(admin_table_coloumn_edit), info);
admin_editing[iclient4] = 9;
}
}
case MenuAction_End:
{
PrintToChatAll("menu menu_edit_poll_options");
if (menu != INVALID_HANDLE)
delete menu;
}
}
}
}
public int editpollmenu(Menu menu, MenuAction action, int iclient5, int selection)
{
if (IsValidClient(iclient5))
{
switch(action)
{
case MenuAction_Select:
{
char info[32];
menu.GetItem(selection, info, sizeof(info));
if (admin_editing[iclient5] == 7)
{
admin_editing[iclient5] = 0;
mysql_playtime_update(iclient5, StringToInt(info), admin_table_edit);
}
else if (!selection)
{
Format(admin_table_edit, sizeof(admin_table_edit), info);
admin_editing[iclient5] = 6;
PrintToChat(iclient5, "type vote option into the chat. Type exit to abort");
}
else if (selection == 4)
{
Format(admin_table_edit, sizeof(admin_table_edit), info);
mysql_playtime_requirement(iclient5, info);
}
else
mysql_edit_poll(iclient5, info, selection);
}
case MenuAction_End:
{
admin_editing[iclient5] = 0;
PrintToChatAll("menu editpollmenu");
if (menu != INVALID_HANDLE)
delete menu;
}
}
}
}
public Action cmd_poll_commands(int i_client, int args)
{
mysql_find_poll_commands();
PrintToChat(i_client, "Executed poll commands");
return Plugin_Handled;
}
public Action cmd_polls(int iclient, int args)
{
if (IsValidClient(iclient))
{
if (CheckCommandAccess(iclient, "", ADMFLAG_SLAY))
{
Menu menu = new Menu(MenuHandler1);
menu.SetTitle("Choose if you want to vote or use admin menu", "");
menu.AddItem("", "Admin menu");
menu.AddItem("", "Vote on Polls");
menu.ExitButton = true;
menu.Display(iclient, MENU_TIME_FOREVER);
}
else
{
admin_editing[iclient] = 5;
mysql_get_polls("vote", iclient);
}
}
return Plugin_Handled;
}
public void polladminmenu(int client_admin)
{
Menu menu = new Menu(MenuHandler2);
menu.SetTitle("Poll admin menu", "", client_admin);
menu.AddItem("Disabled", "", ITEMDRAW_DISABLED);
menu.AddItem("", "Create new Poll");
menu.AddItem("Edit", "Edit Poll");
menu.AddItem("Enable/Disable", "Enable/Disable Poll");
menu.AddItem("Delete", "Delete Poll");
menu.ExitButton = true;
menu.Display(client_admin, MENU_TIME_FOREVER);
}
public void OnClientDisconnect (int client_disc)
{
admin_editing[client_disc] = 0;
}
public void OnClientPostAdminCheck(int client_pos)
{
admin_editing[client_pos] = 0;
}
public Action cmd_say(int client_say, int args)
{
if (!!admin_editing[client_say])
{
char info[generic_length];
GetCmdArgString(info, sizeof(info));
StripQuotes(info);
if (StrEqual(info, "exit", false))
{
admin_editing[client_say] = 0;
PrintToChat(client_say, "Aborted chat reading");
return Plugin_Continue;
}
switch(admin_editing[client_say])
{
case 1:
{
sql_create_poll_table(client_say, info);
PrintToChat(client_say, "Saved %s as poll Question", info);
admin_editing[client_say] = 0;
polladminmenu(client_say);
}
case 6:
{
mysql_add_poll_option(client_say, info);
PrintToChat(client_say, "Saved %s as poll option", info);
admin_editing[client_say] = 0;
}
case 8:
{
mysql_rewrite_poll_option(client_say, info);
PrintToChat(client_say, "Rewrote %s into %s", admin_table_coloumn_edit, info);
admin_editing[client_say] = 0;
}
case 9:
{
mysql_add_poll_option_command(client_say, info, admin_table_coloumn_edit);
PrintToChat(client_say, "Added %s as command option", info);
admin_editing[client_say] = 0;
}
}
}
return Plugin_Continue;
}
public void mysql_exec_prepared_statement(char []query_statement)
{
char error[generic_length];
DBStatement create_statement = SQL_PrepareQuery(database_connection, query_statement, error, sizeof(error));
if (create_statement == INVALID_HANDLE)
{
CloseHandle(create_statement);
return;
}
SQL_Execute(create_statement);
CloseHandle(create_statement);
}
public void sql_start_connection()
{
char error_connect[generic_length];
if (SQL_CheckConfig("css_polls"))
database_connection = SQL_Connect("css_polls", true, error_connect, sizeof(error_connect));
if (database_connection == null)
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to maria-DB!");
if (SQL_CheckConfig("hlstatsx"))
database_hlstats_connection = SQL_Connect("hlstatsx", true, error_connect, sizeof(error_connect));
if (database_hlstats_connection == null)
PrintToChatAll("{green}[UNLOZE] {white}Error! Could not connect to maria-DB!");
char query_start[generic_length];
Format(query_start, sizeof(query_start), "CREATE TABLE IF NOT EXISTS unloze_css_polls.`poll_reff` (`polloption` VARCHAR(%i) NOT NULL, `command` text NOT NULL, `server_port` INT NOT NULL, PRIMARY KEY (`polloption`))", generic_length);
mysql_exec_prepared_statement(query_start);
Format(query_start, sizeof(query_start), "CREATE TABLE IF NOT EXISTS unloze_css_polls.`poll_status` (`poll_table` VARCHAR(%i) NOT NULL, PLAYTIME int(10) DEFAULT 0, `enabled` BOOL DEFAULT false, `server_port` INT default 0, PRIMARY KEY (`poll_table`))", generic_length);
mysql_exec_prepared_statement(query_start);
Format(query_start, sizeof(query_start), "CREATE TABLE IF NOT EXISTS unloze_css_polls.`poll_text` (`poll_id` INT NOT NULL AUTO_INCREMENT, `poll_option_text` text NOT NULL, PRIMARY KEY (`poll_id`))");
mysql_exec_prepared_statement(query_start);
}
public void mysql_enable_disable_poll(int iclient6, char []table_name_enable)
{
DBResultSet rs_disable;
char query_enabled[generic_length];
Format(query_enabled, sizeof(query_enabled), "UPDATE unloze_css_polls.poll_status SET enabled = !enabled where poll_table = '%s'", table_name_enable);
mysql_exec_prepared_statement(query_enabled);
Format(query_enabled, sizeof(query_enabled), "SELECT enabled from unloze_css_polls.poll_status WHERE poll_table = '%s'", table_name_enable);
if ((rs_disable = SQL_Query(database_connection, query_enabled)) == null)
{
delete rs_disable;
return;
}
rs_disable.FetchRow();
int status = rs_disable.FetchInt(0);
delete rs_disable;
if (status)
PrintToChat(iclient6, "Enabled poll %s", table_name_enable);
else
PrintToChat(iclient6, "Disabled poll %s", table_name_enable);
editpoll(iclient6, table_name_enable);
}
public void mysql_delete_poll(int iclient7, char []table_name)
{
char query_delete[generic_length];
Format(query_delete, sizeof(query_delete), "DROP TABLE unloze_css_polls.`%s`", table_name);
mysql_exec_prepared_statement(query_delete);
PrintToChat(iclient7, "removed poll %s", table_name);
editpoll(iclient7, table_name);
}
public void mysql_insert_poll_vote(int client, char []coloumn, char table_name)
{
char sSID[24];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
char query_insert[generic_length];
Format(query_insert, sizeof(query_insert), "DELETE FROM unloze_css_polls.%s WHERE steam_auth = '%s'", table_name, sSID);
mysql_exec_prepared_statement(query_insert);
Format(query_insert, sizeof(query_insert), "INSERT INTO unloze_css_polls.%s (%s) VALUES (1) WHERE steam_auth = '%s'", table_name, coloumn, sSID);
mysql_exec_prepared_statement(query_insert);
}
public void mysql_vote_poll(int client, char []table_name)
{
DBResultSet rs_vote;
char query_vote[generic_length];
char sSID[24];
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
Format(query_vote, sizeof(query_vote), "SELECT enabled from unloze_css_polls.poll_status WHERE poll_table = '%s'", table_name);
if ((rs_vote = SQL_Query(database_connection, query_vote)) == null)
{
delete rs_vote;
return;
}
rs_vote.FetchRow();
int status = rs_vote.FetchInt(0);
if (!status)
{
delete rs_vote;
PrintToChat(client, "Poll %s was disabled by an admin to vote on", table_name);
editpoll(client, table_name);
return;
}
Format(query_vote, sizeof(query_vote), "SELECT PLAYTIME FROM unloze_css_polls.poll_status WHERE poll_table = '%s'", table_name);
if ((rs_vote = SQL_Query(database_connection, query_vote)) == null)
{
delete rs_vote;
return;
}
rs_vote.FetchRow();
int playtime = rs_vote.FetchInt(0);
GetClientAuthId(client, AuthId_Steam3, sSID, sizeof(sSID));
if (playtime != 0)
{
char server[8];
switch(server_port)
{
case 27015:
{
Format(server, sizeof(server), "css-ze");
}
case 27016:
{
Format(server, sizeof(server), "css-zr");
}
case 27017:
{
Format(server, sizeof(server), "css-mg");
}
case 27019:
{
Format(server, sizeof(server), "css-ze");
}
case 27035:
{
Format(server, sizeof(server), "css-ze");
}
}
ReplaceString(sSID, sizeof(sSID), "[U:", "");
ReplaceString(sSID, sizeof(sSID), "]", "");
Format(sSID, sizeof(sSID), "0%s", sSID[1]);
Format(query_vote, sizeof(query_vote), "SELECT connection_time from unloze_stats.hlstats_Players hp INNER JOIN unloze_stats.hlstats_PlayerUniqueIds pui on hp.playerId = pui.playerId AND pui.uniqueId = '%s' AND pui.game = '%s'", sSID, server);
if ((rs_vote = SQL_Query(database_hlstats_connection, query_vote)) == null)
{
delete rs_vote;
return;
}
rs_vote.FetchRow();
if (!rs_vote.RowCount)
{
Format(sSID, sizeof(sSID), "1%s", sSID[1]);
Format(query_vote, sizeof(query_vote), "SELECT connection_time from unloze_stats.hlstats_Players hp INNER JOIN unloze_stats.hlstats_PlayerUniqueIds pui on hp.playerId = pui.playerId AND pui.uniqueId = '%s' AND pui.game = '%s'", sSID, server);
if ((rs_vote = SQL_Query(database_hlstats_connection, query_vote)) == null)
{
delete rs_vote;
return;
}
rs_vote.FetchRow();
}
if (!rs_vote.RowCount)
{
GetClientAuthId(client, AuthId_Steam2, sSID, sizeof(sSID));
ReplaceString(sSID, sizeof(sSID), "STEAM_1:", "");
Format(sSID, sizeof(sSID), "0%s", sSID[1]);
Format(query_vote, sizeof(query_vote), "SELECT connection_time from unloze_stats.hlstats_Players hp INNER JOIN unloze_stats.hlstats_PlayerUniqueIds pui on hp.playerId = pui.playerId AND pui.uniqueId = '%s' AND pui.game = '%s'", sSID, server);
if ((rs_vote = SQL_Query(database_hlstats_connection, query_vote)) == null)
{
delete rs_vote;
return;
}
rs_vote.FetchRow();
}
if (!rs_vote.RowCount)
{
Format(sSID, sizeof(sSID), "1%s", sSID[1]);
Format(query_vote, sizeof(query_vote), "SELECT connection_time from unloze_stats.hlstats_Players hp INNER JOIN unloze_stats.hlstats_PlayerUniqueIds pui on hp.playerId = pui.playerId AND pui.uniqueId = '%s' AND pui.game = '%s'", sSID, server);
if ((rs_vote = SQL_Query(database_hlstats_connection, query_vote)) == null)
{
delete rs_vote;
return;
}
rs_vote.FetchRow();
}
//TODO
if (!rs_vote.RowCount)
{
PrintToChat(client, "you do not have enough time on this server to participate in this vote");
delete rs_vote;
return;
}
float connection_time_seconds = rs_vote.FetchFloat(0);
float hours_pre = connection_time_seconds / 60;
int hours = RoundToFloor(hours_pre / 60);
if (hours < playtime)
{
PrintToChat(client, "you have %i hours but require %i to participate in this vote", hours, playtime);
delete rs_vote;
return;
}
}
//check nosteam
if (!PM_IsPlayerSteam(client))
{
PrintToChat(client, "You are not authenticated with steam and can therefore not vote");
delete rs_vote;
return;
}
Format(query_vote, sizeof(query_vote), "SELECT COLUMN_NAME FROM information_schema.columns WHERE TABLE_NAME = '%s'", table_name);
if ((rs_vote = SQL_Query(database_connection, query_vote)) == null)
{
delete rs_vote;
return;
}
char table_names[generic_length];
if (rs_vote.RowCount > 0)
{
int index;
while (rs_vote.FetchRow())
{
rs_vote.FetchString(0, table_names[index], sizeof(table_names));
index++;
}
Format(admin_table_edit[client], sizeof(admin_table_edit), table_name);
Menu menu2 = new Menu(menu_vote_poll_options, MENU_ACTIONS_ALL);
menu2.SetTitle("Select which option to vote on for: %s", table_name);
for (int i = sizeof(table_names); i > 0; i--)
menu2.AddItem(table_names[i], table_names[i]);
menu2.ExitButton = true;
menu2.Display(client, MENU_TIME_FOREVER);
}
delete rs_vote;
}
public void mysql_remove_poll_option(int client, char []coloumn_info, char []target_table)
{
DBResultSet rs_add;
char query_remove[generic_length];
Format(query_remove, sizeof(query_remove), "SELECT poll_id from unloze_css_polls.poll_text WHERE poll_option_text = '%s'", coloumn_info);
if ((rs_add = SQL_Query(database_connection, query_remove)) == null)
{
delete rs_add;
return;
}
int poll_id;
rs_add.FetchRow();
poll_id = rs_add.FetchInt(0);
Format(query_remove, sizeof(query_remove), "ALTER TABLE unloze_css_polls.`%s` DROP `%i`", target_table, poll_id);
mysql_exec_prepared_statement(query_remove);
PrintToChat(client, "removed Option %s from poll %s", coloumn_info, target_table);
delete rs_add;
editpoll(client, target_table);
}
public void mysql_add_poll_option(int client, char []info)
{
DBResultSet rs_add;
char query_add[generic_length];
Format(query_add, sizeof(query_add), "INSERT INTO unloze_css_polls.`poll_text` (poll_option_text) VALUES ('%s')", info);
mysql_exec_prepared_statement(query_add);
Format(query_add, sizeof(query_add), "SELECT LAST_INSERT_ID()");
if ((rs_add = SQL_Query(database_connection, query_add)) == null)
{
delete rs_add;
return;
}
int insert_id;
rs_add.FetchRow();
insert_id = rs_add.FetchInt(0);
Format(query_add, sizeof(query_add), "ALTER TABLE unloze_css_polls.`%s` ADD COLUMN IF NOT EXISTS `%i` INT default 0", admin_table_edit, insert_id);
mysql_exec_prepared_statement(query_add);
delete rs_add;
editpoll(client, admin_table_edit);
}
public void mysql_add_poll_option_command(int client, char []command, char []coloumn)
{
char query_command[generic_length];
Format(query_command, sizeof(query_command), "INSERT INTO unloze_css_polls.`poll_reff` (polloption, command, server_port) VALUES ('%s.%s', '%s', '%i') ON DUPLICATE KEY UPDATE command = '%s'", admin_table_edit, coloumn, command, server_port, command);
mysql_exec_prepared_statement(query_command);
editpoll(client, admin_table_edit);
}
public void mysql_rewrite_poll_option(int client, char []info)
{
char query_rewrite[generic_length];
Format(query_rewrite, sizeof(query_rewrite), "ALTER TABLE unloze_css_polls.`poll_text` SET poll_option_text = '%s' WHERE poll_option_text = '%s'", info, admin_table_coloumn_edit);
mysql_exec_prepared_statement(query_rewrite);
}
public void mysql_playtime_update(int client, int info, char []admin_table_edit_local)
{
char query_playtime[generic_length];
Format(query_playtime, sizeof(query_playtime), "UPDATE unloze_css_polls.`poll_status` SET PLAYTIME = %i WHERE poll_table = '%s'", info, admin_table_edit_local);
mysql_exec_prepared_statement(query_playtime);
PrintToChat(client, "Edited playtime requirement %i to poll: %s", info, admin_table_edit_local);
editpoll(client, admin_table_edit_local);
}
public void mysql_playtime_requirement(int client, char []info)
{
//selection = 4 : playtime requirement for poll
DBResultSet rs;
char query_playtimre_requir[generic_length];
Format(query_playtimre_requir, sizeof(query_playtimre_requir), "SELECT PLAYTIME FROM unloze_css_polls.poll_status WHERE poll_table = '%s'", info);
if ((rs = SQL_Query(database_connection, query_playtimre_requir)) == null)
{
delete rs;
return;
}
int playtime;
rs.FetchRow();
playtime = rs.FetchInt(0);
PrintToChat(client, "playtime: %i", playtime);
admin_editing[client] = 7;
Menu menu = new Menu(editpollmenu, MENU_ACTIONS_ALL);
menu.SetTitle("Poll %s has playtime requirement: %i", "", info, playtime);
menu.AddItem("0", "0 hours playtime requirement");
menu.AddItem("5", "5 hours playtime requirement");
menu.AddItem("10", "10 hours playtime requirement");
menu.AddItem("25", "25 hours playtime requirement");
menu.AddItem("50", "50 hours playtime requirement");
menu.AddItem("250", "250 hours playtime requirement");
menu.AddItem("1000", "1000 hours playtime requirement");
menu.ExitButton = true;
menu.Display(client, MENU_TIME_FOREVER);
delete rs;
}
public void mysql_edit_poll(int client, char []info, int selection)
{
//selection = 1 : rewrite option
//selection = 2 : remove option
//selection = 3 : add command to option
DBResultSet rs;
char query_edit2[generic_length];
Format(query_edit2, sizeof(query_edit2), "SELECT COLUMN_NAME FROM information_schema.columns WHERE TABLE_NAME = '%s'", info);
if ((rs = SQL_Query(database_connection, query_edit2)) == null)
{
delete rs;
return;
}
char table_names[generic_length][64];
int index;
if (rs.RowCount > 0)
{
//skip steam_auth row which is always first
rs.FetchRow();
DBResultSet rs1;
while (rs.FetchRow())
{
int poll_id = rs.FetchInt(0);
Format(query_edit2, sizeof(query_edit2), "SELECT poll_option_text FROM unloze_css_polls.poll_text where poll_id = %i", poll_id);
if ((rs1 = SQL_Query(database_connection, query_edit2)) == null)
continue;
rs1.FetchRow();
rs1.FetchString(0, table_names[index], sizeof(table_names));
index++;
}
delete rs1;
char pollchoice[generic_length];
switch(selection)
{
case 1:
{
Format(pollchoice, sizeof(pollchoice), "rewrite");
}
case 2:
{
Format(pollchoice, sizeof(pollchoice), "remove");
}
case 3:
{
Format(pollchoice, sizeof(pollchoice), "add command option to");
}
}
Format(admin_table_coloumn_edit, sizeof(admin_table_coloumn_edit), pollchoice);
Format(admin_table_edit, sizeof(admin_table_edit), info);
Menu menu_poll_options = new Menu(menu_edit_poll_options, MENU_ACTIONS_ALL);
menu_poll_options.SetTitle("Select which option to %s in poll %s", pollchoice, info);
for (int i = 0; i < index; i++)
menu_poll_options.AddItem(table_names[i], table_names[i]);
menu_poll_options.ExitButton = true;
menu_poll_options.Display(client, MENU_TIME_FOREVER);
}
delete rs;
}
public void mysql_get_polls(char []pollchoice, int client)
{
DBResultSet rs_polls;
char query_get_polls[generic_length];
Format(query_get_polls, sizeof(query_get_polls), "SELECT poll_table from unloze_css_polls.poll_status where server_port = %i", server_port);
if ((rs_polls = SQL_Query(database_connection, query_get_polls)) == null)
{
delete rs_polls;
return;
}
char table_names[generic_length];
int index = 0;
if (rs_polls.RowCount > 0)
{
while (rs_polls.FetchRow())
{
rs_polls.FetchString(0, table_names[index], sizeof(table_names));
index++;
}
}
Menu menu3 = new Menu(MenuHandler3);
menu3.SetTitle("Select which poll to %s", pollchoice);
for (int i = 0; i < index; i++)
menu3.AddItem(table_names[i], table_names[i]);
menu3.ExitButton = true;
menu3.Display(client, MENU_TIME_FOREVER);
delete rs_polls;
}
public void mysql_find_poll_commands()
{
DBResultSet rs;
char query[generic_length];
Format(query, sizeof(query), "SELECT command, polloption FROM unloze_css_polls.poll_reff WHERE server_port = %i", server_port);
//PrintToChatAll("query: %s size: %i", query, sizeof(query));
if ((rs = SQL_Query(database_connection, query)) == null)
{
delete rs;
return;
}
if (rs.RowCount > 0)
{
while (rs.FetchRow())
{
char table_commands[generic_length];
char table_polloptions[generic_length];
char sPart[2][generic_length];
rs.FetchString(0, table_commands, sizeof(table_commands));
rs.FetchString(1, table_polloptions, sizeof(table_polloptions));
ExplodeString(table_polloptions, ".", sPart, sizeof(sPart), sizeof(sPart[]));
Format(query, sizeof(query), "SELECT COUNT(*) FROM unloze_css_polls.%s", sPart[0]);
//TODO
}
}
delete rs;
}
public void sql_create_poll_table(int client, char []info)
{
if (database_connection == null)
sql_start_connection();
if (database_connection == null)
return;
char query[generic_length];
Format(query, sizeof(query), "CREATE TABLE IF NOT EXISTS unloze_css_polls.`%s` (`steam_id` VARCHAR(24) NOT NULL, PRIMARY KEY (`steam_id`))", info);
mysql_exec_prepared_statement(query);
Format(query, sizeof(query), "INSERT IGNORE INTO unloze_css_polls.`poll_status` (PLAYTIME, enabled, poll_table, server_port) VALUES (0, 0, '%s', %i)", info, server_port);
mysql_exec_prepared_statement(query);
}
stock bool IsValidClient(int client)
{
if (client > 0 && client <= MaxClients && IsClientConnected(client) && IsClientInGame(client))
{
return true;
}
return false;
}