Permalink
Browse files

Updated cookie module

Removed lua_cookiespew, restricted lua_cookieclear to client realm only.
  • Loading branch information...
1 parent a0fbf8a commit fc95f67486f0e14c6a2999289b04951a3a2c282e @robotboy655 robotboy655 committed Sep 30, 2014
Showing with 19 additions and 39 deletions.
  1. +19 −39 garrysmod/lua/includes/modules/cookie.lua
@@ -2,9 +2,8 @@
if ( !sql.TableExists( "cookies" ) ) then
sql.Query( "CREATE TABLE IF NOT EXISTS cookies ( key TEXT NOT NULL PRIMARY KEY, value TEXT );" )
-
-end
+end
module( "cookie", package.seeall )
@@ -41,19 +40,19 @@ end
local function CommitToSQLite()
sql.Begin()
- for k,v in pairs(BufferedWrites) do
+ for k,v in pairs( BufferedWrites ) do
local name = SQLStr( k )
local value = SQLStr( v )
- sql.Query( "INSERT OR REPLACE INTO cookies ( key, value ) VALUES ( "..name..", "..value.." )" )
+ sql.Query( "INSERT OR REPLACE INTO cookies ( key, value ) VALUES ( " .. name .. ", " .. value .. " )" )
end
BufferedWrites = {}
sql.Commit()
end
-local function ScheduleCommit()
- timer.Create("Cookie_CommitToSQLite", 0.1, 1, CommitToSQLite)
+local function ScheduleCommit()
+ timer.Create( "Cookie_CommitToSQLite", 0.1, 1, CommitToSQLite )
end
local function SetCache( key, value )
@@ -68,32 +67,32 @@ local function SetCache( key, value )
end
--[[---------------------------------------------------------
- Get a String Value
+ Get a String Value
-----------------------------------------------------------]]
function GetString( name, default )
local val = GetCache( name )
- if (!val) then return default end
+ if ( !val ) then return default end
return val
-
+
end
--[[---------------------------------------------------------
- Get a Number Value
+ Get a Number Value
-----------------------------------------------------------]]
function GetNumber( name, default )
local val = GetCache( name )
- if (!val) then return default end
+ if ( !val ) then return default end
return tonumber( val )
-
+
end
--[[---------------------------------------------------------
- Delete a Value
+ Delete a Value
-----------------------------------------------------------]]
function Delete( name )
@@ -105,41 +104,22 @@ function Delete( name )
end
--[[---------------------------------------------------------
- Set a Value
+ Set a Value
-----------------------------------------------------------]]
function Set( name, value )
SetCache( name, value )
end
-
-
+if ( !CLIENT_DLL ) then return end
--[[---------------------------------------------------------
- ClearCookies
+ ClearCookies
-----------------------------------------------------------]]
-local function ClearCookies( ply, command, arguments )
-
+local function ClearCookies( ply, command, arguments )
+
sql.Query( "DELETE FROM cookies" )
FlushCache()
-
-end
-concommand.Add( "lua_cookieclear", ClearCookies )
-
-
---[[---------------------------------------------------------
- ClearCookies
------------------------------------------------------------]]
-local function SpewCookies( ply, command, arguments )
-
- local res = sql.Query( "SELECT key, value FROM cookies LIMIT 200" )
-
- for k, v in ipairs( res ) do
-
- MsgN( v['key'], " = ", v['value'] )
-
- end
-
-end
+end
-concommand.Add( "lua_cookiespew", SpewCookies )
+concommand.Add( "lua_cookieclear", ClearCookies )

0 comments on commit fc95f67

Please sign in to comment.