noq: adjustments for legacy mod, sql tool script and missing files. noq

starts with legacy mod now - still a lot TODO
This commit is contained in:
IR4T4 2014-01-29 16:20:45 +01:00
parent e5af32ff32
commit 8fd6681973
8 changed files with 295 additions and 45 deletions

View file

@ -1,4 +1,4 @@
-- put this file into your noquarter path (fs_homepath)
-- put this file into your legacy path (fs_homepath)
-- never change values here unless you exactly know what you are doing
return {
-- Table: {1}

View file

@ -1,4 +1,4 @@
-- put this file into your noquarter path (fs_homepath)
-- put this file into your legacy path (fs_homepath)
-- never change values here unless you exactly know what you are doing
return {
-- Table: {1}

View file

@ -1,4 +1,4 @@
-- put this file into your noquarter path (fs_homepath)
-- put this file into your legacy path (fs_homepath)
-- never change values here unless you exactly know what you are doing
-- TODO: We can use better names here

View file

@ -0,0 +1,63 @@
-- put this file into your legacy path (fs_homepath)
-- never change values here unless you exactly know what you are doing
return {
-- Table: {1}
{
WP_NONE=0,
WP_KNIFE=1,
WP_LUGER=2,
WP_MP40=3,
WP_GRENADE_LAUNCHER=4,
WP_PANZERFAUST=5,
WP_FLAMETHROWER=6,
WP_COLT=7,
WP_THOMPSON=8,
WP_GRENADE_PINEAPPLE=9,
WP_STEN=10,
WP_MEDIC_SYRINGE=11,
WP_AMMO=12,
WP_ARTY=13,
WP_SILENCER=14,
WP_DYNAMITE=15,
WP_SMOKETRAIL=16,
WP_MAPMORTAR=17,
VERYBIGEXPLOSION=18,
WP_MEDKIT=19,
WP_BINOCULARS=20,
WP_PLIERS=21,
WP_SMOKE_MARKER=22,
WP_KAR98=23,
WP_CARBINE=24,
WP_GARAND=25,
WP_LANDMINE=26,
WP_SATCHEL=27,
WP_SATCHEL_DET=28,
WP_SMOKE_BOMB=29,
WP_MOBILE_MG42=30,
WP_K43=31,
WP_FG42=32,
WP_DUMMY_MG42=33,
WP_MORTAR=34,
WP_AKIMBO_COLT=35,
WP_AKIMBO_LUGER=36,
WP_GPG40=37,
WP_M7=38,
WP_SILENCED_COLT=39,
WP_GARAND_SCOPE=40,
WP_K43_SCOPE=41,
WP_FG42SCOPE=42,
WP_MORTAR_SET=43,
WP_MEDIC_ADRENALINE=44,
WP_AKIMBO_SILENCEDCOLT=45,
WP_AKIMBO_SILENCEDLUGER=46,
WP_MOBILE_MG42_SET=47,
WP_KNIFE_KABAR=48,
WP_MOBILE_BROWNING=49,
WP_MOBILE_BROWNING_SET=50,
WP_MORTAR2=51,
WP_MORTAR2_SET=52,
WP_BAZOOKA=53,
WP_NUM_WEAPONS=54,
},
}

View file

@ -33,19 +33,19 @@
-- - Restart the server and check if all lua_modules noq_i.lua, noq_c.lua (optional) and noq.lua are registered.
-- - Call /rcon !sqlcreate - Done. Your system is set up - you should remove noq_i.lua from lua_modules now.
--
-- Files:
-- NOQ basic files:
-- noq_i.lua - Install script remove after install
-- noq_c.lua - Additional tool to enter sql cmds on the ET console
-- noq_config.cfg - Stores all data to run & control the NOQ. Make this file your own!
-- noq_commands.cfg - Commands definition file - Make this file your own!
--
-- noq_mods_names_<NQ_VERSION>.cfg - Methods of death enum file - never touch!
-- noq_mods_<NQ_VERSION>.cfg - Methods of death enum file - never touch!
-- noq_weapons_<NQ_VERSION>.cfg - Weapon enum config file - never touch!
-- noq_weapons_names_<NQ_VERSION>.cfg - Weapon enum config file - never touch!
-- Note: Delete files not matching your version. Example: If you run NQ 1.2.9 delete the files with suffix 130
-- legacy_mods_names_<NQ_VERSION>.cfg - Methods of death enum file - never touch!
-- legacy_mods_<NQ_VERSION>.cfg - Methods of death enum file - never touch!
-- legacy_weapons_<NQ_VERSION>.cfg - Weapon enum config file - never touch!
-- legacy_weapons_names_<NQ_VERSION>.cfg - Weapon enum config file - never touch!
--
-- nqconst.lua - No Quarter constants
-- legacyconst.lua - legacy constants
-- noq_db.lua - No Quarter DB functions
--
@ -53,6 +53,9 @@
-- Again - you don't have to modyfiy any code in this script. If you disagree contact the dev team.
-- FIXME legacy mod
-- et.G_shrubbot_level(_clientNum) (keep for NQ)
-------------------------------------------------------------------------------
-------------------------------------------------------------------------------
@ -160,24 +163,21 @@ if modname == "nq" then
-- TODO: check for version incompatibilities...
--version = et.trap_Cvar_Get( cvarname )
modprefix = "noq"
elseif modname == "etpro" then
--TODO:
-- only commands may work - no loadlib:/
elseif modname == "legacy" then
modprefix = "legacy"
end
et.G_LogPrint("Loading NOQ config from ".. scriptpath.."\n")
noqvartable = assert(table.load( scriptpath .. "noq_config.cfg"))
-- TODO: check if we can do this in 2 tables
et.G_LogPrint("Loading NOQ config files from ".. scriptpath.."\n")
noqvartable = assert(table.load( scriptpath .. "noq_config.cfg"))
-- TODO: check if we can do this in total 2 tables
meansofdeath = assert(table.load( scriptpath .. modprefix .. "_mods.cfg")) -- all MODS
weapons = assert(table.load( scriptpath .. modprefix .. "_weapons.cfg")) -- all weapons
mod = assert(table.load( scriptpath .. modprefix .. "_mods_names.cfg")) -- mods by name
w = assert(table.load( scriptpath .. modprefix .. "_weapons_names.cfg")) -- weapons by name
weapons = assert(table.load( scriptpath .. modprefix .. "_weapons.cfg")) -- all weapons
mod = assert(table.load( scriptpath .. modprefix .. "_mods_names.cfg")) -- mods by name
w = assert(table.load( scriptpath .. modprefix .. "_weapons_names.cfg")) -- weapons by name
-- end TODO
greetings = assert(table.load( scriptpath .. "noq_greetings.cfg")) -- all greetings, customize as wished
tkweight = {} -- TODO: external table
greetings = assert(table.load( scriptpath .. "noq_greetings.cfg")) -- all greetings, customize as wished
et.G_LogPrint("NOQ config files loaded.\n")
tkweight = {} -- TODO: external table
-- Gets varvalue else null
function getConfig ( varname )
@ -191,7 +191,6 @@ function getConfig ( varname )
end
end
-- don't get often used vars from noqvartable ...
databasecheck = tonumber((getConfig("useDB"))) -- Is DB on?
@ -236,7 +235,7 @@ debug_getInfoFromTable(noqvartable)
-- ["pkey"] = 0
-- ["conname"] = row.conname
-- ["regname"] = row.regname
-- ["netname"] = row.netname
-- ["netname"] = row.netnameet.G_Print("warning, invalid config value for " .. varname .. "\n")
-- ["isBot"] = 0
-- ["clan"] = 0
-- ["level"] = 0
@ -518,7 +517,7 @@ function et_ClientCommand( _clientNum, _command )
local arg0 = string.lower(et.trap_Argv(0))
local arg1 = string.lower(et.trap_Argv(1))
local arg2 = string.lower(et.trap_Argv(2))
callershrublvl = et.G_shrubbot_level(_clientNum)
callershrublvl = 1 -- FIXME !!! et.G_shrubbot_level(_clientNum)
debugPrint("print","Got a Clientcommand: ".. arg0)
@ -746,6 +745,7 @@ function et_ClientCommand( _clientNum, _command )
end
-- FIXME: this crashes in legacy mod
function et_ShutdownGame( _restart )
if databasecheck == 1 then
-- We write only the informations from a session that gone till intermission end
@ -765,7 +765,7 @@ function et_ShutdownGame( _restart )
for i=0, maxclients, 1 do
-- TODO: check slot[] if its existingreco
if et.gentity_get(i,"classname") == "player" then
-- TODO : check if this works. Is the output from 'D' option in the needed format for the database?
-- TODO : check if this works. Is the output from 'D' option in the required format for the database?
local timediff = timehandle('D',endgametime,slot[i]["start"])
et.G_LogPrint( "Noq: saved player "..i.." to Database\n" )
WriteClientDisconnect( i , endgametime, timediff )
@ -774,7 +774,7 @@ function et_ShutdownGame( _restart )
end
end
DBCon:DoDisconnect()
--DBCon:DoDisconnect()
end
-- delete old sessions if set in config
@ -984,7 +984,7 @@ function initClient ( _clientNum, _FirstTime, _isBot)
a, b, slot[_clientNum]["ip"]= string.find(slot[_clientNum]["ip"],"(%d+%.%d+%.%d+%.%d+)")
slot[_clientNum]["isBot"] = _isBot
slot[_clientNum]["conname"] = et.Info_ValueForKey( et.trap_GetUserinfo( _clientNum ), "name" )
slot[_clientNum]["level"] = et.G_shrubbot_level(_clientNum)
slot[_clientNum]["level"] = 1 -- FIXME !!! et.G_shrubbot_level(_clientNum)
slot[_clientNum]["flags"] = "" -- TODO
slot[_clientNum]["start"] = timehandle('N') -- Get the start connection time

177
noq/noq_c.lua Normal file
View file

@ -0,0 +1,177 @@
--
-- ET Lua SQL console - console.lua (p) 2010 IRATA [*]
--
--
-- Execute SQL via the ET server console like
-- [commandprefix]sql "select * from players"
--
-- Enables faster debugging for SQL based Lua scripts, adds some new options and is nice to have ...
--
-- Notes:
-- There are limits by the buffer of ET. Avoid very long statements and don't expect you always get the full result printed.
-- Keep resultsets short
--
-- TODO
-- get configurations from noq_config
-- test all
--------------------------------------------------------------------------------
color = "^5"
version = 1
commandprefix = "!"
debug = 0 -- debug 0/1
tablespacer = " " -- use something like " " or "|"
--------------------------------------------------------------------------------
-- db connection data
dbms = "SQLite" -- possible values "mySQL", "postgreSQL" and "SQLite"
dbname = "noquarter.sqlite" -- also filename for SQLite file
dbuser = "myuser"
dbpassword = "mypassword"
--------------------------------------------------------------------------------
env = nil
con = nil
-- Connect & handle different dbms
if dbms == "mySQL" then
require "luasql.mysql"
env = assert (luasql.mysql())
con = assert (env:connect( dbname, dbuser, dbpassword, dbhostname, dbport ))
elseif dbms == "SQLite" then
require "luasql.sqlite3"
env = assert (luasql.sqlite3())
con = assert (env:connect( dbname )) -- this opens OR creates a sqlite db - if this Lua is loaded db is created -fix this?
else
-- stop script
error("DBMS not supported.")
end
cur = {}
res = {}
row = {}
--------------------------------------------------------------------------------
function et_InitGame( levelTime, randomSeed, restart )
et.RegisterModname( "ET SQL console " .. version .. " " .. et.FindSelf() )
if debug == 1 then
et.trap_SendServerCommand( -1 ,"chat \"" .. color .. "ET Lua SQL console " .. version )
end
end
function et_ConsoleCommand( command )
if debug == 1 then
et.trap_SendServerCommand( -1 ,"chat \"" .. color .. "ConsoleCommand - command: " .. command )
end
-- TODO should be used by admins only
if string.lower(et.trap_Argv(0)) == commandprefix.."sql" then
-- TODO sanity checks - help output
-- 2 ?
if (et.trap_Argc() < 1) then
et.G_Print(color..commandprefix.."sql is used to access the db with common sql commands.\n" .. "usage: ...\n")
return 1
end
-- we have some cases now - get the sql command ... insert, update
local cmd = string.lower( string.sub(et.trap_Argv(1), 0 , 6) )
if debug == 1 then
et.G_Print(color .. commandprefix.."sql: " .. et.trap_Argv(1) .. "\n")
end
-- ok, does work
if cmd == "select" then
cur = assert (con:execute(et.trap_Argv(1)))
row = cur:fetch ({}, "a") -- the rows will be indexed by field names
local collect = ""
for i,v in pairs(cur:getcolnames()) do collect = collect .. v .. tablespacer end
et.G_Print(collect .. "\n") -- fix this order is not in sync with following output
-- add a limit to 20 rows ?
while row do
collect = ""
for i,v in pairs(row) do collect = collect .. v .. tablespacer end
-- send more rows each print ? (depends on table size)
et.G_Print(collect .. "\n")
row = cur:fetch (row, "a") -- reusing the table of results
end
cur:close()
elseif cmd == "insert" or "create" or "delete" then
-- exec cmd
res = assert (con:execute(et.trap_Argv(1)))
et.G_Print(res .. "\n")
elseif cmd == "vacuum" then
-- only sqlite defrag the database
if dbms == "SQLite" then
res = assert (con:execute(et.trap_Argv(1)))
et.G_Print(res .. "\n")
else
et.G_Print(color..commandprefix.."sql: Command unknown for this dbms\n")
end
else
-- cmd is 5 char based ?
cmd = string.lower( string.sub(et.trap_Argv(1), 0 , 5) )
-- alter
if cmd == "alter" then
res = assert (con:execute(et.trap_Argv(1)))
et.G_Print(res .. "\n")
else
-- cmd is 4 char based
cmd = string.lower( string.sub(et.trap_Argv(1), 0 , 4) )
-- drop
if cmd == "drop" then
-- create a row of data
res = assert (con:execute(et.trap_Argv(1)))
cur:close()
-- untested (only mysql atm)
elseif cmd == "show" then
cur = assert (con:execute(et.trap_Argv(1)))
row = cur:fetch ({}, "a") -- the rows will be indexed by field names
local collect = ""
for i,v in pairs(cur:getcolnames()) do collect = collect .. v .. tablespacer end
et.G_Print(collect .. "\n")
-- add a limit to 20 rows ?
while row do
collect = ""
for i,v in pairs(row) do collect = collect .. v .. tablespacer end
-- send more rows each print ? (depends on table size
et.G_Print(collect .. "\n")
row = cur:fetch (row, "a") -- reusing the table of results
end
cur:close()
else
et.G_Print(color..commandprefix.."sql: Command unknown\n")
end
end
end
end
-- add more cmds here ...
end
function shuttdownDBMS()
if dbms == "mySQL" or dbms == "SQLite" then
con:close()
env:close()
else
-- should never happen ;)
error("DBMS not supported.")
end
end
function et_ShutdownGame( restart )
shuttdownDBMS()
end

10
noq/noq_greetings.cfg Normal file
View file

@ -0,0 +1,10 @@
return {
-- Table: {1}
{
[0]=nil, -- this means no greeting for that level
"^1Welcome Level 1 player <COLOR_PLAYER>", -- this is level 1 greeting
"^1Welcome Level 2 player <COLOR_PLAYER>", -- this is level 2 greeting
"^1Welcome Level .. argh, you get it....",
[4]= nil, -- no greeting for level 4
},
}

View file

@ -195,7 +195,7 @@ function createTablesDBMS()
regdate DATE DEFAULT NULL, \
updatedate DATE DEFAULT CURRENT_DATE, \
createdate DATE DEFAULT CURRENT_DATE)" )
et.G_Print(res .. "\n")
et.G_Print("CREATE TABLE IF NOT EXISTS player res: " .. res .. "\n")
res = assert(con:execute"CREATE TABLE IF NOT EXISTS log ( \
id INTEGER PRIMARY KEY, \
@ -204,7 +204,7 @@ function createTablesDBMS()
type INTEGER DEFAULT NULL, \
textxml TEXT DEFAULT NULL, \
createdate DATE DEFAULT CURRENT_DATE)")
et.G_Print(res .. "\n")
et.G_Print("CREATE TABLE IF NOT EXISTS log res: " .. res .. "\n")
res = assert(con:execute"CREATE TABLE IF NOT EXISTS session ( \
id INTEGER PRIMARY KEY, \
@ -236,7 +236,7 @@ function createTablesDBMS()
death INTEGER DEFAULT 0, \
revives INTEGER DEFAULT 0, \
uci INTEGER DEFAULT 0)" )
et.G_Print(res .. "\n")
et.G_Print("CREATE TABLE IF NOT EXISTS session res: " .. res .. "\n")
res = assert(con:execute"CREATE TABLE IF NOT EXISTS level ( \
id INTEGER PRIMARY KEY, \
@ -244,33 +244,33 @@ function createTablesDBMS()
name TEXT NOT NULL, \
greetings TEXT DEFAULT '', \
flags TEXT NOT NULL)" )
et.G_Print(res .. "\n")
et.G_Print("CREATE TABLE IF NOT EXISTS level res: " .. res .. "\n")
res = assert(con:execute"CREATE TABLE IF NOT EXISTS version ( \
id INTEGER PRIMARY KEY, \
version INTEGER NOT NULL UNIQUE )" )
et.G_Print(res .. "\n")
et.G_Print("CREATE TABLE IF NOT EXISTS version res: " .. res .. "\n")
-- SQLite needs exra cmds for setting up an index (anybody knows syntax for create table stmd?)
-- player
res = assert(con:execute"CREATE INDEX p_regname ON player( regname )" )
et.G_Print(res .. "\n")
res = assert(con:execute"CREATE INDEX p_netname ON player( netname )" )
et.G_Print(res .. "\n")
res = assert(con:execute"CREATE INDEX p_regname ON player(regname)" )
et.G_Print("CREATE INDEX p_regname ON player(regname) res: " .. res .. "\n")
res = assert(con:execute"CREATE INDEX p_netname ON player(netname)" )
et.G_Print("CREATE INDEX p_netname ON player(netname) res: " .. res .. "\n")
--log
res = assert(con:execute"CREATE INDEX l_guid ON log (guid1, guid2)" )
et.G_Print(res .. "\n")
res = assert(con:execute"CREATE INDEX l_guid ON log(guid1, guid2)" )
et.G_Print("CREATE INDEX l_guid ON log(guid1, guid2) res: " .. res .. "\n")
-- session
res = assert(con:execute"CREATE INDEX s_pkey ON session ( pkey )" )
et.G_Print(res .. "\n")
res = assert(con:execute"CREATE INDEX s_ip ON session ( ip )" )
et.G_Print(res .. "\n")
res = assert(con:execute"CREATE INDEX s_end ON session ( end )" )
et.G_Print(res .. "\n")
res = assert(con:execute"CREATE INDEX s_pkey ON session(pkey)" )
et.G_Print("CREATE INDEX s_pkey ON session(pkey) res: " .. res .. "\n")
res = assert(con:execute"CREATE INDEX s_ip ON session(ip)" )
et.G_Print("CREATE INDEX s_ip ON session(ip) res: " .. res .. "\n")
res = assert(con:execute"CREATE INDEX s_end ON session(end)" )
et.G_Print("CREATE INDEX s_end ON session(end) res: " .. res .. "\n")
-- insert data
res = assert(con:execute("INSERT INTO version VALUES ( '1', '" .. version .. "' )"))
et.G_Print(res .. "\n")
et.G_Print("Version res: " .. res .. " - Database version is " .. version .. "\n")
-- TODO: create level entries