etlegacy-lua-scripts/ladm/ladm.lua

98 lines
2.9 KiB
Lua
Raw Normal View History

2014-02-11 00:26:34 +00:00
--[[
Author: Jan Šimek [Radegast]
Version 0.1
License: MIT
Released on 09.02.2014
Website: http://www.etlegacy.com
Mod: intended for the Legacy mod
Description: lightweight user administration suite
]]--
2014-02-12 20:22:31 +00:00
package.path = "./" .. et.trap_Cvar_Get("fs_game") .. "/ladm/?.lua;" .. package.path
2014-02-11 00:26:34 +00:00
-- load the config file
dofile ("./" .. et.trap_Cvar_Get("fs_game") .. "/ladm/ladm.cfg")
2014-02-11 00:26:34 +00:00
2014-02-12 20:22:31 +00:00
require "core/db"
require "core/user"
require "core/commands"
2014-02-11 00:26:34 +00:00
function et_InitGame(levelTime, randomSeed, restart)
-- name of this module
et.RegisterModname ( "Lightweight administration suite for the Legacy mod" )
-- init db on game start
2014-02-11 14:09:54 +00:00
db_init()
2014-02-11 00:26:34 +00:00
end -- et_InitGame
function et_ShutdownGame(restart)
local cno = 0
local maxclients = tonumber(et.trap_Cvar_Get("sv_maxclients"))
-- iterate through clients and save their XP
while cno < maxclients do
local cs = et.trap_GetConfigstring(et.CS_PLAYERS + cno)
if not cs or cs == "" then break end
saveXP(cno)
cno = cno + 1
end
-- clean up
cur:close()
con:close()
env:close()
end -- et_ShutdownGame
-- called when a client enters the game world
function et_ClientBegin(cno)
local name = et.Info_ValueForKey( et.trap_GetUserinfo( cno ), "name" )
local guid = et.Info_ValueForKey( et.trap_GetUserinfo( cno ), "cl_guid" )
2014-02-11 14:09:54 +00:00
local player = getPlayerByGUID(guid)
2014-02-11 00:26:34 +00:00
if not player then
-- First time we see this player
et.trap_SendServerCommand (cno, "cpm \"" .. "Welcome, " .. name .. "^7! You are playing on an XP save server.\n\"")
cur = assert (con:execute(string.format([[
INSERT INTO %susers VALUES (
2014-10-31 12:18:27 +00:00
'%s', '%s', '%s', '%s', 0, 0, 0, 0, 0, 0, 0, 0
)]], dbprefix, guid, name, os.date("%Y-%m-%d %H:%M:%S"), os.date("%Y-%m-%d %H:%M:%S"))))
2014-02-11 00:26:34 +00:00
else
et.trap_SendServerCommand (cno, "cpm \"" .. "Welcome back, " .. name .. "^7! Your last connection was on " .. player.last_seen .. "\n\"") -- in db: player.name
et.G_XP_Set (cno, player.xp_battlesense, BATTLESENSE, 0)
et.G_XP_Set (cno, player.xp_engineering, ENGINEERING, 0)
et.G_XP_Set (cno, player.xp_medic, MEDIC, 0)
et.G_XP_Set (cno, player.xp_fieldops, FIELDOPS, 0)
2014-02-11 00:26:34 +00:00
et.G_XP_Set (cno, player.xp_lightweapons, LIGHTWEAPONS, 0)
et.G_XP_Set (cno, player.xp_heavyweapons, HEAVYWEAPONS, 0)
et.G_XP_Set (cno, player.xp_covertops, COVERTOPS, 0)
2014-02-11 00:26:34 +00:00
2014-10-31 12:18:27 +00:00
--et.G_Print (name .. "'s current XP levels:\n")
--for id, skill in pairs(skills) do
-- et.G_Print ("| " .. skill .. ": " .. et.gentity_get (cno, "sess.skillpoints", id) .. " XP |\n")
--end
2014-02-11 00:26:34 +00:00
end
end -- et_ClientBegin
function et_ClientDisconnect(cno)
saveXP(cno)
end -- et_ClientDisconnect
2014-02-11 14:09:54 +00:00
function et_ClientCommand(cno, cmd)
for cmd_name, cmd_function in pairs(Command) do
-- string.lower(et.trap_Argv(0))
if cmd == cmd_name then
cmd_function(cno, cmd)
2014-02-11 14:09:54 +00:00
return 1
end
end
end -- et_ClientCommand
-- testing
function et_ConsoleCommand(cmd)
et_ClientCommand(999, cmd)
2014-02-11 14:09:54 +00:00
end -- et_ConsoleCommand