From: <tr...@us...> - 2008-11-22 20:54:52
|
Revision: 18967 http://bzflag.svn.sourceforge.net/bzflag/?rev=18967&view=rev Author: trepan Date: 2008-11-22 20:54:46 +0000 (Sat, 22 Nov 2008) Log Message: ----------- * added timeLimit callouts * added lagWarn callouts * added report callouts * added countdown query callouts * added position and rotation to the PlayerSpawnEvent callin Modified Paths: -------------- trunk/bzflag/plugins/lua/callins.cpp trunk/bzflag/plugins/lua/callouts.cpp trunk/bzflag/plugins/lua/example/bzfs.lua trunk/bzflag/plugins/lua/example/plugins/air_spawn.lua trunk/bzflag/plugins/lua/example/plugins/rogue_genocide.lua trunk/bzflag/plugins/lua/example/plugins.lua trunk/bzflag/plugins/lua/example/utils.lua Modified: trunk/bzflag/plugins/lua/callins.cpp =================================================================== --- trunk/bzflag/plugins/lua/callins.cpp 2008-11-22 19:19:12 UTC (rev 18966) +++ trunk/bzflag/plugins/lua/callins.cpp 2008-11-22 20:54:46 UTC (rev 18967) @@ -1209,9 +1209,15 @@ lua_pushinteger(L, ed->playerID); lua_pushinteger(L, ed->team); + const bz_PlayerUpdateState& state = ed->state; + lua_pushnumber(L, state.pos[0]); + lua_pushnumber(L, state.pos[1]); + lua_pushnumber(L, state.pos[2]); + lua_pushnumber(L, state.rotation); + // bz_PlayerUpdateState state; -- FIXME? - return RunCallIn(2, 0); + return RunCallIn(6, 0); } Modified: trunk/bzflag/plugins/lua/callouts.cpp =================================================================== --- trunk/bzflag/plugins/lua/callouts.cpp 2008-11-22 19:19:12 UTC (rev 18966) +++ trunk/bzflag/plugins/lua/callouts.cpp 2008-11-22 20:54:46 UTC (rev 18967) @@ -20,13 +20,9 @@ // FIXME: TODO // * obstacle queries, tangibility -// - timelimit -// - countdown -// - lagwarn // - plugin management // - connections (new call-in?) // - logging -// - reports // - polls // - help @@ -185,8 +181,10 @@ static int StartRecBuf(lua_State* L); static int StopRecBuf(lua_State* L); +static int GetCountdownActive(lua_State* L); +static int GetCountdownInProgress(lua_State* L); +static int StartCountdown(lua_State* L); static int PauseCountdown(lua_State* L); -static int StartCountdown(lua_State* L); static int ResumeCountdown(lua_State* L); static int ReloadLocalBans(lua_State* L); @@ -200,6 +198,21 @@ static int GetGroupHasPerm(lua_State* L); static int GetStandardPerms(lua_State* L); +static int GetReportCount(lua_State* L); +static int GetReportInfo(lua_State* L); +static int GetReports(lua_State* L); + +static int FileReport(lua_State* L); +static int ClearReport(lua_State* L); +static int ClearReports(lua_State* L); + +static int GetLagWarn(lua_State* L); +static int SetLagWarn(lua_State* L); + +static int ManualTimeLimit(lua_State* L); +static int GetTimeLimit(lua_State* L); +static int SetTimeLimit(lua_State* L); + static int KickPlayer(lua_State* L); static int BanByIP(lua_State* L); static int BanByBZID(lua_State* L); @@ -351,8 +364,10 @@ REGISTER_LUA_CFUNC(StartRecBuf); REGISTER_LUA_CFUNC(StopRecBuf); + REGISTER_LUA_CFUNC(GetCountdownActive); + REGISTER_LUA_CFUNC(GetCountdownInProgress); + REGISTER_LUA_CFUNC(StartCountdown); REGISTER_LUA_CFUNC(PauseCountdown); - REGISTER_LUA_CFUNC(StartCountdown); REGISTER_LUA_CFUNC(ResumeCountdown); REGISTER_LUA_CFUNC(ReloadLocalBans); @@ -369,6 +384,21 @@ REGISTER_LUA_CFUNC(GetGroupHasPerm); REGISTER_LUA_CFUNC(GetStandardPerms); + REGISTER_LUA_CFUNC(GetReportCount); + REGISTER_LUA_CFUNC(GetReportInfo); + REGISTER_LUA_CFUNC(GetReports); + + REGISTER_LUA_CFUNC(FileReport); + REGISTER_LUA_CFUNC(ClearReport); + REGISTER_LUA_CFUNC(ClearReports); + + REGISTER_LUA_CFUNC(GetLagWarn); + REGISTER_LUA_CFUNC(SetLagWarn); + + REGISTER_LUA_CFUNC(ManualTimeLimit); + REGISTER_LUA_CFUNC(GetTimeLimit); + REGISTER_LUA_CFUNC(SetTimeLimit); + REGISTER_LUA_CFUNC(KickPlayer); REGISTER_LUA_CFUNC(BanByIP); REGISTER_LUA_CFUNC(BanByBZID); @@ -1426,14 +1456,20 @@ /******************************************************************************/ /******************************************************************************/ -static int PauseCountdown(lua_State* L) +static int GetCountdownActive(lua_State* L) { - const char* playerName = luaL_checkstring(L, 1); - bz_pauseCountdown(playerName); - return 0; + lua_pushboolean(L, bz_isCountDownActive()); + return 1; } +static int GetCountdownInProgress(lua_State* L) +{ + lua_pushboolean(L, bz_isCountDownInProgress()); + return 1; +} + + static int StartCountdown(lua_State* L) { const char* playerName = luaL_checkstring(L, 1); @@ -1444,6 +1480,14 @@ } +static int PauseCountdown(lua_State* L) +{ + const char* playerName = luaL_checkstring(L, 1); + bz_pauseCountdown(playerName); + return 0; +} + + static int ResumeCountdown(lua_State* L) { const char* playerName = luaL_checkstring(L, 1); @@ -1495,11 +1539,12 @@ static int GetGroups(lua_State* L) { - lua_newtable(L); bz_APIStringList* list = bz_getGroupList(); if (list == NULL) { + lua_createtable(L, 0, 0); return 1; } + lua_createtable(L, list->size(), 0); for (int i = 0; i < list->size(); i++) { lua_pushinteger(L, i + 1); lua_pushstring(L, (*list)[i].c_str()); @@ -1515,9 +1560,10 @@ const char* group = luaL_checkstring(L, 1); bz_APIStringList* list = bz_getGroupPerms(group); if (list == NULL) { - return 0; + lua_createtable(L, 0, 0); + return 1; } - lua_newtable(L); + lua_createtable(L, list->size(), 0); for (int i = 0; i < list->size(); i++) { lua_pushinteger(L, i + 1); lua_pushstring(L, (*list)[i].c_str()); @@ -1539,11 +1585,12 @@ static int GetStandardPerms(lua_State* L) { - lua_newtable(L); bz_APIStringList* list = bz_getStandardPermList(); if (list == NULL) { + lua_createtable(L, 0, 0); return 1; } + lua_createtable(L, list->size(), 0); for (int i = 0; i < list->size(); i++) { lua_pushinteger(L, i + 1); lua_pushstring(L, (*list)[i].c_str()); @@ -1557,6 +1604,111 @@ /******************************************************************************/ /******************************************************************************/ +static int GetReportCount(lua_State* L) +{ + lua_pushinteger(L, bz_getReportCount()); + return 1; +} + + +static int GetReportInfo(lua_State* L) +{ + const unsigned int reportID = (unsigned int)luaL_checkint(L, 1); + lua_pushstring(L, bz_getReportSource(reportID)); + lua_pushstring(L, bz_getReportBody(reportID)); + lua_pushstring(L, bz_getReportTime(reportID)); + return 3; +} + + +static int GetReports(lua_State* L) +{ + bz_APIStringList* list = bz_getReports(); + if (list == NULL) { + lua_createtable(L, 0, 0); + return 1; + } + lua_createtable(L, list->size(), 0); + for (unsigned int i = 0; i < list->size(); i++) { + lua_pushinteger(L, i + 1); + lua_pushstring(L, list->get(i).c_str()); + lua_rawset(L, -3); + } + bz_deleteStringList(list); + return 1; +} + + +static int FileReport(lua_State* L) +{ + const char* msg = luaL_checkstring(L, 1); + const char* from = luaL_checkstring(L, 2); + lua_pushboolean(L, bz_fileReport(msg, from)); + return 1; +} + + +static int ClearReport(lua_State* L) +{ + const unsigned int reportID = luaL_checkint(L, 1); + lua_pushboolean(L, bz_clearReport(reportID)); + return 1; +} + + +static int ClearReports(lua_State* L) +{ + lua_pushboolean(L, bz_clearAllReports()); + return 1; +} + + +/******************************************************************************/ +/******************************************************************************/ + +static int GetLagWarn(lua_State* L) +{ + lua_pushinteger(L, bz_getLagWarn()); + return 1; +} + + +static int SetLagWarn(lua_State* L) +{ + const int lagWarn = luaL_checkint(L, 1); + lua_pushboolean(L, bz_setLagWarn(lagWarn)); + return 1; +} + + +/******************************************************************************/ +/******************************************************************************/ + +static int ManualTimeLimit(lua_State* L) +{ + lua_pushboolean(L, bz_isTimeManualStart()); + return 1; +} + + +static int GetTimeLimit(lua_State* L) +{ + lua_pushnumber(L, bz_getTimeLimit()); + return 1; +} + + +static int SetTimeLimit(lua_State* L) +{ + const float timeLimit = luaL_checkfloat(L, 1); + lua_pushboolean(L, bz_setTimeLimit(timeLimit)); + return 1; +} + + +/******************************************************************************/ +/******************************************************************************/ + static int KickPlayer(lua_State* L) { const int playerID = luaL_checkint(L, 1); Modified: trunk/bzflag/plugins/lua/example/bzfs.lua =================================================================== --- trunk/bzflag/plugins/lua/example/bzfs.lua 2008-11-22 19:19:12 UTC (rev 18966) +++ trunk/bzflag/plugins/lua/example/bzfs.lua 2008-11-22 20:54:46 UTC (rev 18967) @@ -21,6 +21,21 @@ end +do + local sendMsg = BZ.SendMessage + BZ.SendMessage = function(src, dst, msg) + if (#msg < 128) then + sendMsg(src, dst, msg) + else + while (#msg > 0) do + sendMsg(src, dst, msg:sub(1, 128)) + msg = msg:sub(129) + end + end + end +end + + function BZ.Print(...) print(...) local table = {...} Modified: trunk/bzflag/plugins/lua/example/plugins/air_spawn.lua =================================================================== --- trunk/bzflag/plugins/lua/example/plugins/air_spawn.lua 2008-11-22 19:19:12 UTC (rev 18966) +++ trunk/bzflag/plugins/lua/example/plugins/air_spawn.lua 2008-11-22 20:54:46 UTC (rev 18967) @@ -16,12 +16,14 @@ -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- - local height = 10.0 local random = math.random +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- + local function SetHeight() height = BZ.DB.GetFloat('_airSpawnHeight') if (height < 0.001) then Modified: trunk/bzflag/plugins/lua/example/plugins/rogue_genocide.lua =================================================================== --- trunk/bzflag/plugins/lua/example/plugins/rogue_genocide.lua 2008-11-22 19:19:12 UTC (rev 18966) +++ trunk/bzflag/plugins/lua/example/plugins/rogue_genocide.lua 2008-11-22 20:54:46 UTC (rev 18967) @@ -17,7 +17,6 @@ -------------------------------------------------------------------------------- local noSuicide = true -local BZ_SERVER = -2 function CallIn.PlayerDieEvent(victimID, team, killerID, killerTeam, flagType, shotID) @@ -40,9 +39,9 @@ if (team and (team == BZ.TEAM.ROGUE)) then if (BZ.GetPlayerSpawned(pid)) then BZ.KillPlayer(pid, false, killerID, 'G') - BZ.SendMessage(BZ_SERVER, pid, 'You were a victim of Rogue Genocide') + BZ.SendMessage(BZ.PLAYER.SERVER, pid, 'You were a victim of Rogue Genocide') if (pid == killerID) then - BZ.SendMessage(BZ_SERVER, pid, + BZ.SendMessage(BZ.PLAYER.SERVER, pid, 'You should be more careful with Genocide!') end end Modified: trunk/bzflag/plugins/lua/example/plugins.lua =================================================================== --- trunk/bzflag/plugins/lua/example/plugins.lua 2008-11-22 19:19:12 UTC (rev 18966) +++ trunk/bzflag/plugins/lua/example/plugins.lua 2008-11-22 20:54:46 UTC (rev 18967) @@ -22,14 +22,22 @@ -------------------------------------------------------------------------------- -- -- ci: callin --- pi: plugin +-- mo: module -- --- piInfo = { +-- ciInfo = { +-- name = string, +-- func = function, +-- funcs = { func1, func2, ... }, +-- modules = { moInfo1, moInfo2, ... }, +-- } + +-- moInfo = { -- name = string, -- niceness = number, +-- chunk = function, -- fenv = { fenv }, --- funcs = { ciName1 = func1, ciName2 = func2, etc... } +-- funcs = { ciName1 = func1, ciName2 = func2, etc... }, -- unsafe = bool, -- enabled = bool, -- filename = string, @@ -37,32 +45,33 @@ -- author = string, -- date = string, -- license = string, --- } +-- } -local piNames = {} -- < piName = { piInfo } > pairs -local ciFuncs = {} -- < ciName = { ciFunc, ciFunc, ... } > pairs +local modules = {} -- < moName = moInfo > pairs +local callins = {} -- < ciName = ciInfo > pairs + + -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- --- --- Wrap lfs.dir() to capture errors --- -local function safe_dir(dirPath) - local success, func, state, init = pcall(lfs.dir, dirPath) - if (success) then - return func, state, init - else - print('WARNING: ' .. func) - return function() end, nil, nil + +local function FindModules() + local files, dirs = BZ.DirList(PLUGINS_DIR) + local sources = {} + for _, f in ipairs(files) do + if (f:find('^[^.].*%.lua$')) then + sources[#sources + 1] = f + end end + return sources end -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -local function SetupPlugin(fileName) +local function SetupModule(fileName) print('loading plugin: ' .. fileName) local chunk, err = loadfile(fileName) if (not chunk) then @@ -79,9 +88,9 @@ --]] end -for k, v in safe_dir(PLUGINS_DIR) do - if (k:find('%.lua$') and not k:find('^%.')) then - SetupPlugin(PLUGINS_DIR .. k) +do + for _, f in ipairs(FindModules()) do + SetupModule(f) end end @@ -96,23 +105,23 @@ -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -local function CreatePlugin(fileName) - +local function CreateModule(fileName) + end -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- -local function EnablePlugin(pluginName) +local function EnableModule(pluginName) end -local function DisablePlugin(pluginName) +local function DisableModule(pluginName) end -local function TogglePlugin(pluginName) +local function ToggleModule(pluginName) end @@ -259,3 +268,17 @@ -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- + +moduleHandler = { + ListModules = ListModules, + CreateModule = CreateModule, + EnableModule = EnableModule, + DisableModule = DisableModule, + RaiseModule = RaiseModule, + LowerModule = LowerModule, +} + +return moduleHandler + +-------------------------------------------------------------------------------- +-------------------------------------------------------------------------------- Modified: trunk/bzflag/plugins/lua/example/utils.lua =================================================================== --- trunk/bzflag/plugins/lua/example/utils.lua 2008-11-22 19:19:12 UTC (rev 18966) +++ trunk/bzflag/plugins/lua/example/utils.lua 2008-11-22 20:54:46 UTC (rev 18967) @@ -28,6 +28,9 @@ -------------------------------------------------------------------------------- -------------------------------------------------------------------------------- +-- +-- global additions +-- function include(fileName, fenv) local fn = fileName This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |