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
|
|
|
|
]]--
|
|
|
|
|
|
|
|
-- load the config file
|
|
|
|
dofile "ladm.cfg"
|
|
|
|
|
2014-02-11 14:09:54 +00:00
|
|
|
require "ladm/core/db"
|
|
|
|
require "ladm/core/user"
|
|
|
|
require "ladm/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\"")
|
2014-02-11 14:09:54 +00:00
|
|
|
cur = assert (con:execute(string.format("INSERT INTO %susers VALUES ('%s', '%s', '%s', 0, 0, 0, 0, 0, 0, 0)", dbprefix, guid, 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)
|
|
|
|
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)
|
|
|
|
|
|
|
|
et.G_Print (name .. "'s current XP levels:\n")
|
|
|
|
for id, skill in pairs(skills) do
|
2014-02-11 14:09:54 +00:00
|
|
|
et.G_Print ("| " .. skill .. ": " .. et.gentity_get (cno, "sess.skillpoints", id) .. " XP ")
|
|
|
|
et.G_Print ("|\n")
|
2014-02-11 00:26:34 +00:00
|
|
|
end
|
|
|
|
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()
|
|
|
|
return 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end -- et_ClientCommand
|
|
|
|
|
|
|
|
-- testing
|
|
|
|
function et_ConsoleCommand(cmd)
|
|
|
|
et_ClientCommand(nil, cmd)
|
|
|
|
end -- et_ConsoleCommand
|