No errors. But I'm sure I am doing this wrong.
[lua]
mysql.query(db, "INSERT INTO admines (id, name, nick, time, reason, action, entered_time) VALUES(0, '" .. pl:Nick() .. "', '" .. ply:Nick() .. "', '" .. reason .. "', '" .. "Ban" .. "', NOW())");
[/lua]
[lua]
/*-------------------------------------------------------------------------------------------------------------------------
Ban a player
-- To do: Clean up this piece of shit.
-------------------------------------------------------------------------------------------------------------------------*/
local PLUGIN = {}
PLUGIN.Title = "Ban"
PLUGIN.Description = "Ban a player."
PLUGIN.Author = "Overv"
PLUGIN.ChatCommand = "ban"
PLUGIN.Usage = "<player> [time=5] [reason]"
PLUGIN.Privileges = { "Ban", "Permaban" }
function PLUGIN:Call( ply, args )
local time = math.Clamp( tonumber( args[2] ) or 5, 0, 10080 )
if ( ( time > 0 and ply:EV_HasPrivilege( "Ban" ) ) or ( time == 0 and ply:EV_HasPrivilege( "Permaban" ) ) ) then
/*-------------------------------------------------------------------------------------------------------------------------
-- Check if a player name or SteamID was specified and gather data
-------------------------------------------------------------------------------------------------------------------------*/
local pl
if ( string.match( args[1], "STEAM_[0-5]:[0-9]:[0-9]+" ) ) then
local unid = evolve:UniqueIDByProperty( "SteamID", args[1] )
if ( unid ) then
if ( player.GetByUniqueID( unid ) ) then
pl = { player.GetByUniqueID( unid ) }
else
pl = { unid }
end
else
pl = {}
end
else
pl = evolve:FindPlayer( args[1] )
end
if ( #pl > 1 ) then
evolve:Notify( ply, evolve.colors.white, "Did you mean ", evolve.colors.red, evolve:CreatePlayerList( pl, true ), evolve.colors.white, "?" )
elseif ( #pl == 0 ) then
evolve:Notify( ply, evolve.colors.red, "No matching players found." )
else
/*-------------------------------------------------------------------------------------------------------------------------
Collect data
-------------------------------------------------------------------------------------------------------------------------*/
local uid, nick
if ( type( pl[1] ) == "Player" ) then
pl = pl[1]
uid = pl:UniqueID()
nick = pl:Nick()
else
uid = pl[1]
pl = nil
nick = evolve:GetProperty( uid, "Nick" )
end
local BanInfo = mysql.escape(db, "[BAN] " .. pl:Nick() .. " was banned for " .. reason .. " & " .. time .. " minutes by " .. ply:Nick() )
local time = math.Clamp( tonumber( args[2] ) or 5, 0, 10080 )
local endtime
if ( time > 0 ) then endtime = os.time() + time * 60 else endtime = 0 end
local reason = table.concat( args, " ", 3 )
if ( #reason == 0 ) then reason = "No reason specified" end
/*-------------------------------------------------------------------------------------------------------------------------
Perform banning
-------------------------------------------------------------------------------------------------------------------------*/
if ( pl ) then
for _, v in ipairs( ents.GetAll() ) do
if ( v:EV_GetOwner() == pl:UniqueID() ) then v:Remove() end
end
pl:SetProperty( "BanEnd", endtime )
pl:SetProperty( "BanReason", reason )
pl:SetProperty( "BanAdmin", ply:UniqueID() )
evolve:CommitProperties()
else
evolve:SetProperty( uid, "BanEnd", endtime )
evolve:SetProperty( uid, "BanReason", reason )
evolve:SetProperty( uid, "BanAdmin", ply:UniqueID() )
evolve:CommitProperties()
end
if ( time == 0 ) then
evolve:Notify( evolve.colors.blue, ply:Nick(), evolve.colors.white, " banned ", evolve.colors.red, nick, evolve.colors.white, " permanently (" .. reason .. ")." )
if ( pl ) then
pl:Kick( "Permanently banned (" .. reason .. ")" )
mysql.query(db, "INSERT INTO admines (id, name, nick, time, reason, action, entered_time) VALUES(0, '" .. pl:Nick() .. "', '" .. ply:Nick() .. "', '" .. reason .. "', '" .. "Ban" .. "', NOW())");
end
else
evolve:Notify( evolve.colors.blue, ply:Nick(), evolve.colors.white, " banned ", evolve.colors.red, nick, evolve.colors.white, " for " .. time .. " minutes (" .. reason .. ")." )
if ( pl ) then
pl:Kick( "Banned for " .. time .. " minutes (" .. reason .. ")" )
mysql.query(db, "INSERT INTO admines (id, name, nick, time, reason, action, entered_time) VALUES(0, '" .. pl:Nick() .. "', '" .. ply:Nick() .. "', '" .. reason .. "', '" .. "Ban" .. "', NOW())");
end
end
end
else
evolve:Notify( ply, evolve.colors.red, evolve.constants.notallowed )
end
end
function PLUGIN:PlayerPasswordAuth( user, pass, steamid, ip )
local uid = evolve:UniqueIDByProperty( "SteamID", steamid )
if ( uid ) then
local banend = tonumber( evolve:GetProperty( uid, "BanEnd" ) )
local reason = evolve:GetProperty( uid, "BanReason" )
if ( banend and ( banend > os.time() or banend == 0 ) ) then
if ( banend == 0 ) then
return "You have been permabanned (" .. reason .. ")."
else
return "You have been banned for " .. math.ceil( ( banend - os.time() ) / 60 ) .. " more minutes (" .. reason .. ")."
end
end
end
end
function PLUGIN:PlayerAuthed( ply, steamid, uniqueid )
if ( ply:GetProperty( "BanEnd", false ) ) then
if ( ply:GetProperty( "BanEnd" ) > os.time() or tonumber( ply:GetProperty( "BanEnd" ) ) == 0 ) then
ply:Kick( "Banned." )
else
ply:SetProperty( "BanEnd", nil )
evolve:CommitProperties()
end
end
end
function PLUGIN:Menu( arg, players )
if ( arg ) then
RunConsoleCommand( "ev", "ban", players[1], arg )
else
return "Ban", evolve.category.administration, {
{ "5 minutes", "5" },
{ "10 minutes", "10" },
{ "15 minutes", "15" },
{ "30 minutes", "30" },
{ "1 hour", "60" },
{ "2 hours", "120" },
{ "4 hours", "240" },
{ "12 hours", "720" },
{ "One day", "1440" },
{ "Two days", "2880" },
{ "One week", "10080" },
{ "Two weeks", "20160" },
{ "One month", "43200" },
{ "One year", "525600" },
{ "Permanently", "0" }
}, "Time"
end
end
evolve:RegisterPlugin( PLUGIN )
[/lua]
You sure your tables are named correctly. Unless I'm missing something this looks right.
I'm pretty sure they are.
[php]
-- phpMyAdmin SQL Dump
-- version 3.2.0.1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: May 23, 2010 at 11:57 AM
-- Server version: 5.1.36
-- PHP Version: 5.3.0
SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO";
--
-- Database: `admins`
--
-- --------------------------------------------------------
--
-- Table structure for table `admines`
--
CREATE TABLE IF NOT EXISTS `admines` (
`id` int(11) NOT NULL,
`name` text NOT NULL,
`reason` text NOT NULL,
`nick` text NOT NULL,
`time` text NOT NULL,
`action` text NOT NULL,
`entered_time` datetime NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
--
-- Dumping data for table `admines`
--
INSERT INTO `admines` (`id`, `name`, `reason`, `nick`, `time`, `action`, `entered_time`) VALUES
(0, '«¦HG¦» Clark |Ldr|', 'Mic Spamming', 'JukeBoxDJz023', '0', 'kick', '2010-05-23 06:50:03');
[/php]
Bump.
Try making [code]admines (id, name, nick, time, reason, action, entered_time)[/code]
to
[code]
# CREATE TABLE IF NOT EXISTS `admines` (
# `id` int(11) NOT NULL,
# `name` text NOT NULL,
# `reason` text NOT NULL,
# `nick` text NOT NULL,
# `time` text NOT NULL,
# `action` text NOT NULL,
# `entered_time`tab datetime NOT NULL
admines (id, name, reason, nick, time, action, entered_time)
[/code]
The exact same how your table is.
Same with the other lines.
That's all i can think of for now since im tired.
Big problem: you never escaped any of your strings.
[lua]local crash = [[ "); DROP TABLE admines ]]
-- What if that was my name?[/lua]
Use [b][url=http://wiki.garrysmod.com/?title=Sql.SQLStr]Sql.SQLStr [img]http://wiki.garrysmod.com/favicon.ico[/img][/url][/b] to failsafe any strings you stick in the data.
Sorry, you need to Log In to post a reply to this thread.