2016-02-13 11:19:37 +00:00
-- WolfAdmin module for Wolfenstein: Enemy Territory servers.
2016-02-16 13:10:00 +00:00
-- Copyright (C) 2015-2016 Timo 'Timothy' Smit
2016-02-13 11:19:37 +00:00
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- at your option any later version.
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
2016-02-22 09:28:43 +00:00
local constants = require " luascripts.wolfadmin.util.constants "
2016-02-13 11:19:37 +00:00
local events = require " luascripts.wolfadmin.util.events "
local settings = require " luascripts.wolfadmin.util.settings "
local files = require " luascripts.wolfadmin.util.files "
2016-09-01 14:13:35 +00:00
local util = require " luascripts.wolfadmin.util.util "
2016-02-13 11:19:37 +00:00
local db = require " luascripts.wolfadmin.db.db "
2016-09-04 08:20:21 +00:00
local players = require " luascripts.wolfadmin.players.players "
2016-02-13 11:19:37 +00:00
local stats = require " luascripts.wolfadmin.players.stats "
local admin = { }
2016-02-22 09:28:43 +00:00
local teamLocks = {
[ constants.TEAM_AXIS ] = false ,
[ constants.TEAM_ALLIES ] = false ,
[ constants.TEAM_SPECTATORS ] = false ,
}
2016-09-01 14:13:35 +00:00
function admin . putPlayer ( clientId , teamId )
et.trap_SendConsoleCommand ( et.EXEC_APPEND , " forceteam " .. clientId .. " " .. util.getTeamCode ( teamId ) .. " ; " )
end
2016-02-22 09:28:43 +00:00
function admin . lockTeam ( teamId )
teamLocks [ teamId ] = false
end
function admin . unlockTeam ( teamId )
teamLocks [ teamId ] = false
end
2016-02-13 11:19:37 +00:00
function admin . setPlayerLevel ( clientId , level , adminId )
2016-09-06 10:41:02 +00:00
local playerid = db.getplayer ( players.getGUID ( clientId ) ) [ " id " ]
local adminid = db.getplayer ( players.getGUID ( clientId ) ) [ " id " ]
2016-09-04 20:28:57 +00:00
db.updateplayerlevel ( playerid , level )
2016-02-13 11:19:37 +00:00
db.addsetlevel ( playerid , level , adminid , os.time ( ) )
end
2016-09-04 08:20:21 +00:00
function admin . onconnectattempt ( clientId , firstTime , isBot )
2016-02-13 11:19:37 +00:00
if firstTime then
2016-09-06 09:17:05 +00:00
local guid = et.Info_ValueForKey ( et.trap_GetUserinfo ( clientId ) , " cl_guid " )
if guid == " NO_GUID " or guid == " unknown " then
2016-08-29 11:27:19 +00:00
return " \n \n It appears you do not have a ^7GUID^9/^7etkey^9. In order to play on this server, enable ^7PunkBuster ^9(use ^7 \\ pb_cl_enable^9) ^9and/or create an ^7etkey^9. \n \n More info: ^7www.etkey.org "
2016-02-13 11:19:37 +00:00
end
end
2016-09-04 08:20:21 +00:00
events.trigger ( " onClientConnect " , clientId , firstTime , isBot )
2016-02-13 11:19:37 +00:00
end
2016-09-04 08:20:21 +00:00
events.handle ( " onClientConnectAttempt " , admin.onconnectattempt )
2016-02-13 11:19:37 +00:00
2016-09-04 08:20:21 +00:00
function admin . onconnect ( clientId , firstTime , isBot )
-- only increase the counter on first connection (fixes counter increase on
-- clientbegin which is also triggered on warmup/maprestart/etc)
stats.set ( clientId , " namechangeStart " , os.time ( ) )
stats.set ( clientId , " namechangePts " , 0 )
2016-02-13 11:19:37 +00:00
end
2016-09-04 08:20:21 +00:00
events.handle ( " onClientConnect " , admin.onconnect )
2016-02-13 11:19:37 +00:00
2016-09-04 16:31:17 +00:00
function players . oninfochange ( clientId )
local clientInfo = et.trap_GetUserinfo ( clientId )
2016-09-06 10:41:02 +00:00
local old = players.getCachedName ( clientId )
2016-09-04 16:31:17 +00:00
local new = et.Info_ValueForKey ( clientInfo , " name " )
2016-09-07 18:19:58 +00:00
-- TODO fix for Legacy
-- prints messages by itself, also when rename is rejected - not desirable
--[[ if new ~= old then
2016-09-07 18:06:07 +00:00
if ( os.time ( ) - stats.get ( clientId , " namechangeStart " ) ) < settings.get ( " g_renameInterval " ) and stats.get ( clientId , " namechangePts " ) >= settings.get ( " g_renameLimit " ) and not players.isNameForced ( clientId ) then
players.setNameForced ( clientId , true )
2016-09-04 16:31:17 +00:00
clientInfo = et.Info_SetValueForKey ( clientInfo , " name " , old )
et.trap_SetUserinfo ( clientId , clientInfo )
et.ClientUserinfoChanged ( clientId )
2016-09-07 18:06:07 +00:00
players.setNameForced ( clientId , false )
2016-09-04 16:31:17 +00:00
et.trap_SendServerCommand ( clientId , " cp \" Too many name changes in 1 minute. \" ; " )
else
if ( os.time ( ) - stats.get ( clientId , " namechangeStart " ) ) > settings.get ( " g_renameInterval " ) then
stats.set ( clientId , " namechangeStart " , os.time ( ) )
stats.get ( clientId , " namechangePts " , 0 )
end
stats.add ( clientId , " namechangePts " , 1 )
events.trigger ( " onClientNameChange " , clientId , old , new )
end
2016-09-07 18:19:58 +00:00
end ] ]
2016-09-04 16:31:17 +00:00
end
events.handle ( " onClientInfoChange " , players.oninfochange )
2016-09-04 08:20:21 +00:00
return admin