Results 1 to 10 of 13
Thread: patch: refactor classes in commands.py to extensions & fix ls_list_admin
-
03-15-09, 09:14 PM #1
patch: refactor classes in commands.py to extensions & fix ls_list_admin
patch: refactor classes in commands.py to individual module extensions & fix ls_list_admin console command.
Notes:
- The commands.py should be deleted if this patch is applied.
- The ls_list_admins console command has been fixed to minic the code of the menu based list admins command. These commands are in seperate files. I think we might want to move the admins.py in extensions a directory up and pull the listing admins menu function down into the list_admin.py holding the console command.
- I have the whole diff if you would prefer it since this type of patch setup is going to be a pain in your neck for larger changes.
D lib\lonestar\commands.py
Code:Index: lib/lonestar/commands.py =================================================================== --- lib/lonestar/commands.py (revision 580) +++ lib/lonestar/commands.py (working copy) @@ -1,326 +0,0 @@ -# $Id$ -# Copyright 2008 Tim Thelin -# -# This file is part of LoneStar. -# -# LoneStar 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. -# -# LoneStar 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 LoneStar. If not, see <http://www.gnu.org/licenses/>. - -import hl2sdk as sdk -from logging import logger -import modinfo -from modinfo import teamManager -import cvars -import hud -from maps import mapManager -import client -from client import playerManager -import ui -from ui import consoleUserInterface, chatUserInterface, ConsoleCommand, ChatCommand, ParsedChatCommand, SingleWordChatCommand -import actions -from voting import voteManager -import configs - -class DebugTargetConsoleCommand(ConsoleCommand): - def __init__(self): - ConsoleCommand.__init__(self, "ls_debug_target", "<target>", "Sets who gets the debug messages", client.PERM_CONFIG) - - def doCommand(self, invoker, args): - if len(args) != 2: - self.printUsage(invoker) - return - - if args[ 1 ] == "none": - logger.logTarget = None - actions.logAction(invoker, "set debug target to nobody") - else: - target = self.findTarget(invoker, args[ 1 ]) - if not target: - return - logger.logTarget = target - hud.consolePrint(target, "You have now been set as the debug target") - actions.logActionAgainstPlayer(invoker, target, "set debug target to") - -class ReloadConfigsConsoleCommand(ConsoleCommand): - def __init__(self): - ConsoleCommand.__init__(self, "ls_reload_configs", "", "Reload all configuration information", client.PERM_CONFIG) - - def doCommand(self, invoker, args): - if len(args) != 1: - self.printUsage(invoker) - return - configs.reloadConfigs() - actions.logAction(invoker, "reloaded configs") - hud.consolePrint(invoker, "Configs reloaded") - -class BanConsoleCommand(ConsoleCommand): - def __init__(self): - ConsoleCommand.__init__(self, "ls_ban", "<target> <minutes> [<reason>]", "Bans a player. Use 0 minutes for a permanent ban", client.PERM_BAN) - - def doCommand(self, invoker, args): - if len(args) < 3: - self.printUsage(invoker) - return - - target = self.findTarget(invoker, args[ 1 ]) - if not target: - return - minutes = self.parseFloatAsIntParameter(invoker, "minutes", args[ 2 ]) - if minutes is None: - return - if minutes < 0: - hud.consolePrint(invoker, "Minutes cannot be negative: %d" % minutes) - return - - actions.banId(invoker, target, minutes, " ".join(args[3:])) - -class TempBanConsoleCommand(ConsoleCommand): - def __init__(self): - ConsoleCommand.__init__(self, "ls_tempban", "<target> <minutes> [<reason>]", "Bans a player. Minutes must be bewteen 1 and 120 (2 hours)", (client.PERM_TEMP_BAN, client.PERM_BAN)) - - def doCommand(self, invoker, args): - if len(args) < 3: - self.printUsage(invoker) - return - - target = self.findTarget(invoker, args[ 1 ]) - if not target: - return - minutes = self.parseFloatAsIntParameter(invoker, "minutes", args[ 2 ]) - if minutes is None: - return - if minutes < 1 or minutes > 120: - hud.consolePrint(invoker, "Minutes must be bewteen 1 and 120: %d" % minutes) - return - - actions.banId(invoker, target, minutes, " ".join(args[3:])) - -class KickConsoleCommand(ConsoleCommand): - def __init__(self): - ConsoleCommand.__init__(self, "ls_kick", "<target> [<reason>]", "Kicks a player", client.PERM_KICK) - - def doCommand(self, invoker, args): - if len(args) < 2: - self.printUsage(invoker) - return - target = self.findTarget(invoker, args[ 1 ]) - if not target: - return - actions.kick(invoker, target, " ".join(args[3:])) - -class SlayConsoleCommand(ConsoleCommand): - def __init__(self): - ConsoleCommand.__init__(self, "ls_slay", "<target>", "Slays a player", client.PERM_SLAY) - - def doCommand(self, invoker, args): - if len(args) < 2: - self.printUsage(invoker) - return - target = self.findTarget(invoker, args[ 1 ]) - if not target: - return - actions.slay(invoker, target) - -class ListAdminsConsoleCommand(ConsoleCommand): - def __init__(self): - ConsoleCommand.__init__(self, "ls_list_admins", "", "Lists all admins currently connected", client.PERM_ADMIN) - - def doCommand(self, invoker, args): - if len(args) != 1: - self.printUsage(invoker) - return - admins = playerManager.filterPlayers(client.adminFilter) - hud.consolePrint(invoker, "Admins currently connected:") - for i, a in enumerate(admins): - g = a.data[client.PDATA_ADMIN_GROUP] - if g: - line = "%d) %s (%s)" % (i, a.name, g.name) - else: - line = "%d) %s" % (i, a.name) - hud.consolePrint(invoker, line) - -class MenuSelectConsoleCommand(ConsoleCommand): - def __init__(self): - ConsoleCommand.__init__(self, "menuselect", "<menu-item-index>", "Select a menu item") - - def doCommand(self, invoker, args): - if len(args) != 2: - self.printUsage(invoker) - return - if not invoker: - hud.consolePrint(client.formatIdentity(invoker) + " doesn't have menus") - return - selection = self.parseIntParameter(invoker, "menu-item", args[ 1 ]) - if selection is None: - return - ui.getDialogManager(invoker).selectionOccured(selection) - -class AdminChatCommand(ChatCommand): - def __init__(self): - ChatCommand.__init__(self, "@", "message", "Allows admins to talk to admins, admins to talk to players, and players to talk to admins") - - def doCommand(self, invoker, team, message, cmd, rest): - if not rest: - self.printUsage(invoker) - return False - - if invoker and not invoker.hasPermission(client.PERM_ADMIN): # Normal user wanting to talk to an admin - admins = playerManager.filterPlayers(client.inGameAdminFilter) - adminMessage = "(To Admins) %s: %s" % (invoker.name, rest) - hud.chatPrint(invoker, "(Sent to Admins) %s: %s" % (invoker.name, rest)) - logger.chat(adminMessage) - hud.chatBroadcast(admins, adminMessage) - hud.centerBroadcast(admins, adminMessage, 0xFFFF) #cyan - - else: #must be server or admin - adminName = client.getName(invoker) - - if team: #admins talking to themselves - admins = playerManager.filterPlayers(client.inGameAdminFilter) - adminMessage = "(Admin Chat) %s: %s" % (adminName, rest) - logger.chat(adminMessage) - hud.chatBroadcast(admins, adminMessage) - hud.centerBroadcast(admins, adminMessage, 0xFF00) #green - - else: #admin talking to everyone - nonAdmins = playerManager.filterPlayers(client.inGameNonAdminFilter) - hud.chatBroadcast(nonAdmins, "(Admin): %s" % rest) - - admins = playerManager.filterPlayers(client.inGameAdminFilter) - adminMessage = "(Admin) %s: %s" % (adminName, rest) - hud.chatBroadcast(admins, adminMessage) - logger.chat(adminMessage) - - everyone = playerManager.filterPlayers(client.inGamePersonFilter) - hud.centerBroadcast(everyone, rest, 0xFF0000) #red - return False - -class TimeLeftChatCommand(SingleWordChatCommand): - def __init__(self): - SingleWordChatCommand.__init__(self, "timeleft", "Displays how much time is left on this map") - - def doSingleWordCommand(self, invoker, team, cmd): - players = playerManager.filterPlayers(client.inGamePersonFilter) - hud.chatBroadcast(players, "Map time left: %d minutes, %d seconds" % mapManager.timeleft); - return True - -class NextMapChatCommand(SingleWordChatCommand): - def __init__(self): - SingleWordChatCommand.__init__(self, "nextmap", "Displays the next map that will be played on the server") - - def doSingleWordCommand(self, invoker, team, cmd): - players = playerManager.filterPlayers(client.inGamePersonFilter) - name = mapManager.nextMap - if not name: - name = "unknown" - hud.chatBroadcast(players, "Next map: %s" % name); - return True - -class StopMusicChatCommand(SingleWordChatCommand): - def __init__(self): - SingleWordChatCommand.__init__(self, "stopmusic", "Stops the the intro music if it is currently playing") - - def doSingleWordCommand(self, invoker, team, cmd): - if invoker: - hud.showUrl(invoker, "about:blank") - return True - -class FriendlyFireChatCommand(SingleWordChatCommand): - def __init__(self): - SingleWordChatCommand.__init__(self, "ff", "Prints back whether friendly fire is on or off") - - def doSingleWordCommand(self, invoker, team, cmd): - players = playerManager.filterPlayers(client.inGamePersonFilter) - if cvars.findCvar("mp_friendlyfire").boolValue: - hud.chatBroadcast(players, "Friendly fire is ON") - else: - hud.chatBroadcast(players, "Friendly fire is OFF") - return True - -class SlayChatCommand(ParsedChatCommand): - def __init__(self): - ParsedChatCommand.__init__(self, "@slay", "<target>", "Slays the targeted player", client.PERM_SLAY) - - def doParsedCommand(self, invoker, team, args): - if len(args) != 2: - self.printUsage(invoker) - return False - target = self.findTarget(invoker, args[1]) - if not target: - return False - actions.slay(invoker, target) - return False - -class ChangeTeamChatCommand(ParsedChatCommand): - def __init__(self): - ParsedChatCommand.__init__(self, "@changeteam", "<target> <team>", "Changes the team of the targeted player", client.PERM_ADMIN) - - def doParsedCommand(self, invoker, team, args): - if len(args) != 3: - self.printUsage(invoker) - return False - target = self.findTarget(invoker, args[1]) - if not target: - return False - team = teamManager.findTeam(args[2]) - if not team: - hud.chatPrint(invoker, "Cannot change team: unable to find team \"%s\"" % args[2]) - return False - if target.getTeamId() == team.teamId: - hud.chatPrint(invoker, "Cannot change team: player is already on that team") - return False - actions.changeClientTeam(invoker, target, team.teamId) - return False - -class SwapTeamChatCommand(ParsedChatCommand): - def __init__(self): - ParsedChatCommand.__init__(self, "@swapteam", "<target 1> <target 2>", "Swaps the teams of the two targeted players", client.PERM_ADMIN) - - def doParsedCommand(self, invoker, team, args): - if len(args) != 3: - self.printUsage(invoker) - return False - target1 = self.findTarget(invoker, args[1]) - if not target1: - return False - target2 = self.findTarget(invoker, args[2]) - if not target2: - return False - if target1 == target2: - hud.chatPrint(invoker, "Cannot swap teams: both players specified are the same person") - return False - if target1.getTeamId() == target2.getTeamId(): - hud.chatPrint(invoker, "Cannot swap teams: both players are on the same team") - return False - actions.swapClientTeams(invoker, target1, target2) - return False - -consoleUserInterface.registerCommand(DebugTargetConsoleCommand()) -consoleUserInterface.registerCommand(ReloadConfigsConsoleCommand()) -consoleUserInterface.registerCommand(BanConsoleCommand()) -consoleUserInterface.registerCommand(TempBanConsoleCommand()) -consoleUserInterface.registerCommand(KickConsoleCommand()) -consoleUserInterface.registerCommand(ListAdminsConsoleCommand()) -consoleUserInterface.registerCommand(MenuSelectConsoleCommand()) -if modinfo.modName != "left4dead": - consoleUserInterface.registerCommand(SlayConsoleCommand()) - -chatUserInterface.registerCommand(AdminChatCommand()) -chatUserInterface.registerCommand(StopMusicChatCommand()) -if modinfo.modName != "left4dead": - chatUserInterface.registerCommand(TimeLeftChatCommand()) - chatUserInterface.registerCommand(NextMapChatCommand()) - chatUserInterface.registerCommand(FriendlyFireChatCommand()) - chatUserInterface.registerCommand(SlayChatCommand()) - chatUserInterface.registerCommand(ChangeTeamChatCommand()) - chatUserInterface.registerCommand(SwapTeamChatCommand())
M lib\lonestar\__init__.py
Code:Index: lib/lonestar/__init__.py =================================================================== --- lib/lonestar/__init__.py (revision 580) +++ lib/lonestar/__init__.py (working copy) @@ -25,7 +25,6 @@ from client import playerManager from ui import _consoleCommandManager, _chatManager import cvars -import commands import menus import extensions
M lib\lonestar\ui.py
Code:Index: lib/lonestar/ui.py =================================================================== --- lib/lonestar/ui.py (revision 580) +++ lib/lonestar/ui.py (working copy) @@ -876,3 +876,21 @@ def doAction(self, menuItem = None): viewer = ViewerDialog(self.parentDialog.user, self.title, self.getItems()) getDialogManager(self.parentDialog.user).showDialog(viewer) + +class MenuSelectConsoleCommand(ConsoleCommand): + def __init__(self): + ConsoleCommand.__init__(self, "menuselect", "<menu-item-index>", "Select a menu item") + + def doCommand(self, invoker, args): + if len(args) != 2: + self.printUsage(invoker) + return + if not invoker: + hud.consolePrint(client.formatIdentity(invoker) + " doesn't have menus") + return + selection = self.parseIntParameter(invoker, "menu-item", args[ 1 ]) + if selection is None: + return + getDialogManager(invoker).selectionOccured(selection) + +consoleUserInterface.registerCommand(MenuSelectConsoleCommand()) \ No newline at end of file
A lib\lonestar\extensions\punishment.py
Code:Index: lib/lonestar/extensions/punishment.py =================================================================== --- lib/lonestar/extensions/punishment.py (revision 0) +++ lib/lonestar/extensions/punishment.py (revision 0) @@ -0,0 +1,114 @@ +# $Id: punishment.py 569 2009-02-11 08:21:47Z Ewok $ +# Copyright 2008 Tim Thelin +# +# This file is part of LoneStar. +# +# LoneStar 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. +# +# LoneStar 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 LoneStar. If not, see <http://www.gnu.org/licenses/>. + +from lonestar import hud, actions, modinfo +from lonestar.client import PERM_BAN, PERM_TEMP_BAN, PERM_KICK, PERM_SLAY +from lonestar.ui import consoleUserInterface, ConsoleCommand, chatUserInterface, ParsedChatCommand + +class BanConsoleCommand(ConsoleCommand): + def __init__(self): + ConsoleCommand.__init__(self, "ls_ban", "<target> <minutes> [<reason>]", "Bans a player. Use 0 minutes for a permanent ban", PERM_BAN) + + def doCommand(self, invoker, args): + if len(args) < 3: + self.printUsage(invoker) + return + + target = self.findTarget(invoker, args[ 1 ]) + if not target: + return + minutes = self.parseFloatAsIntParameter(invoker, "minutes", args[ 2 ]) + if minutes is None: + return + if minutes < 0: + hud.consolePrint(invoker, "Minutes cannot be negative: %d" % minutes) + return + + actions.banId(invoker, target, minutes, " ".join(args[3:])) + +class TempBanConsoleCommand(ConsoleCommand): + def __init__(self): + ConsoleCommand.__init__(self, "ls_tempban", "<target> <minutes> [<reason>]", "Bans a player. Minutes must be bewteen 1 and 120 (2 hours)", (PERM_TEMP_BAN, PERM_BAN)) + + def doCommand(self, invoker, args): + if len(args) < 3: + self.printUsage(invoker) + return + + target = self.findTarget(invoker, args[ 1 ]) + if not target: + return + minutes = self.parseFloatAsIntParameter(invoker, "minutes", args[ 2 ]) + if minutes is None: + return + if minutes < 1 or minutes > 120: + hud.consolePrint(invoker, "Minutes must be bewteen 1 and 120: %d" % minutes) + return + + actions.banId(invoker, target, minutes, " ".join(args[3:])) + +class KickConsoleCommand(ConsoleCommand): + def __init__(self): + ConsoleCommand.__init__(self, "ls_kick", "<target> [<reason>]", "Kicks a player", PERM_KICK) + + def doCommand(self, invoker, args): + if len(args) < 2: + self.printUsage(invoker) + return + target = self.findTarget(invoker, args[ 1 ]) + if not target: + return + actions.kick(invoker, target, " ".join(args[3:])) + +class SlayConsoleCommand(ConsoleCommand): + def __init__(self): + ConsoleCommand.__init__(self, "ls_slay", "<target>", "Slays a player", PERM_SLAY) + + def doCommand(self, invoker, args): + if len(args) < 2: + self.printUsage(invoker) + return + target = self.findTarget(invoker, args[ 1 ]) + if not target: + return + actions.slay(invoker, target) + +class SlayChatCommand(ParsedChatCommand): + def __init__(self): + ParsedChatCommand.__init__(self, "@slay", "<target>", "Slays the targeted player", PERM_SLAY) + + def doParsedCommand(self, invoker, team, args): + if len(args) != 2: + self.printUsage(invoker) + return False + target = self.findTarget(invoker, args[1]) + if not target: + return False + actions.slay(invoker, target) + return False + +consoleUserInterface.registerCommand(BanConsoleCommand()) +consoleUserInterface.registerCommand(TempBanConsoleCommand()) +consoleUserInterface.registerCommand(KickConsoleCommand()) + +if modinfo.modName != "left4dead": + consoleUserInterface.registerCommand(SlayConsoleCommand()) + +if modinfo.modName != "left4dead": + chatUserInterface.registerCommand(SlayChatCommand()) + \ No newline at end of file
A lib\lonestar\extensions\player_commands.py
Code:Index: lib/lonestar/extensions/player_commands.py =================================================================== --- lib/lonestar/extensions/player_commands.py (revision 0) +++ lib/lonestar/extensions/player_commands.py (revision 0) @@ -0,0 +1,71 @@ +# $Id: punishment.py 569 2009-02-11 08:21:47Z Ewok $ +# Copyright 2008 Tim Thelin +# +# This file is part of LoneStar. +# +# LoneStar 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. +# +# LoneStar 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 LoneStar. If not, see <http://www.gnu.org/licenses/>. + +from lonestar import hud, modinfo, client, cvars +from lonestar.client import playerManager +from lonestar.maps import mapManager +from lonestar.ui import chatUserInterface, SingleWordChatCommand + +class TimeLeftChatCommand(SingleWordChatCommand): + def __init__(self): + SingleWordChatCommand.__init__(self, "timeleft", "Displays how much time is left on this map") + + def doSingleWordCommand(self, invoker, team, cmd): + players = playerManager.filterPlayers(client.inGamePersonFilter) + hud.chatBroadcast(players, "Map time left: %d minutes, %d seconds" % mapManager.timeleft); + return True + +class NextMapChatCommand(SingleWordChatCommand): + def __init__(self): + SingleWordChatCommand.__init__(self, "nextmap", "Displays the next map that will be played on the server") + + def doSingleWordCommand(self, invoker, team, cmd): + players = playerManager.filterPlayers(client.inGamePersonFilter) + name = mapManager.nextMap + if not name: + name = "unknown" + hud.chatBroadcast(players, "Next map: %s" % name); + return True + +class StopMusicChatCommand(SingleWordChatCommand): + def __init__(self): + SingleWordChatCommand.__init__(self, "stopmusic", "Stops the the intro music if it is currently playing") + + def doSingleWordCommand(self, invoker, team, cmd): + if invoker: + hud.showUrl(invoker, "about:blank") + return True + +class FriendlyFireChatCommand(SingleWordChatCommand): + def __init__(self): + SingleWordChatCommand.__init__(self, "ff", "Prints back whether friendly fire is on or off") + + def doSingleWordCommand(self, invoker, team, cmd): + players = playerManager.filterPlayers(client.inGamePersonFilter) + if cvars.findCvar("mp_friendlyfire").boolValue: + hud.chatBroadcast(players, "Friendly fire is ON") + else: + hud.chatBroadcast(players, "Friendly fire is OFF") + return True + +chatUserInterface.registerCommand(StopMusicChatCommand()) + +if modinfo.modName != "left4dead": + chatUserInterface.registerCommand(TimeLeftChatCommand()) + chatUserInterface.registerCommand(NextMapChatCommand()) + chatUserInterface.registerCommand(FriendlyFireChatCommand()) \ No newline at end of file
A lib\lonestar\extensions\team_management.py
Code:Index: lib/lonestar/extensions/team_management.py =================================================================== --- lib/lonestar/extensions/team_management.py (revision 0) +++ lib/lonestar/extensions/team_management.py (revision 0) @@ -0,0 +1,70 @@ +# $Id: punishment.py 569 2009-02-11 08:21:47Z Ewok $ +# Copyright 2008 Tim Thelin +# +# This file is part of LoneStar. +# +# LoneStar 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. +# +# LoneStar 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 LoneStar. If not, see <http://www.gnu.org/licenses/>. + +from lonestar import hud, actions, modinfo +from lonestar.modinfo import teamManager +from lonestar.client import PERM_ADMIN +from lonestar.ui import chatUserInterface, ParsedChatCommand + +class ChangeTeamChatCommand(ParsedChatCommand): + def __init__(self): + ParsedChatCommand.__init__(self, "@changeteam", "<target> <team>", "Changes the team of the targeted player", PERM_ADMIN) + + def doParsedCommand(self, invoker, team, args): + if len(args) != 3: + self.printUsage(invoker) + return False + target = self.findTarget(invoker, args[1]) + if not target: + return False + team = teamManager.findTeam(args[2]) + if not team: + hud.chatPrint(invoker, "Cannot change team: unable to find team \"%s\"" % args[2]) + return False + if target.getTeamId() == team.teamId: + hud.chatPrint(invoker, "Cannot change team: player is already on that team") + return False + actions.changeClientTeam(invoker, target, team.teamId) + return False + +class SwapTeamChatCommand(ParsedChatCommand): + def __init__(self): + ParsedChatCommand.__init__(self, "@swapteam", "<target 1> <target 2>", "Swaps the teams of the two targeted players", PERM_ADMIN) + + def doParsedCommand(self, invoker, team, args): + if len(args) != 3: + self.printUsage(invoker) + return False + target1 = self.findTarget(invoker, args[1]) + if not target1: + return False + target2 = self.findTarget(invoker, args[2]) + if not target2: + return False + if target1 == target2: + hud.chatPrint(invoker, "Cannot swap teams: both players specified are the same person") + return False + if target1.getTeamId() == target2.getTeamId(): + hud.chatPrint(invoker, "Cannot swap teams: both players are on the same team") + return False + actions.swapClientTeams(invoker, target1, target2) + return False + +if modinfo.modName != "left4dead": + chatUserInterface.registerCommand(ChangeTeamChatCommand()) + chatUserInterface.registerCommand(SwapTeamChatCommand()) \ No newline at end of file
A lib\lonestar\extensions\system_utils.py
Code:Index: lib/lonestar/extensions/system_utils.py =================================================================== --- lib/lonestar/extensions/system_utils.py (revision 0) +++ lib/lonestar/extensions/system_utils.py (revision 0) @@ -0,0 +1,35 @@ +# $Id: punishment.py 569 2009-02-11 08:21:47Z Ewok $ +# Copyright 2008 Tim Thelin +# +# This file is part of LoneStar. +# +# LoneStar 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. +# +# LoneStar 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 LoneStar. If not, see <http://www.gnu.org/licenses/>. + +from lonestar import hud, actions, configs +from lonestar.client import PERM_CONFIG +from lonestar.ui import consoleUserInterface, ConsoleCommand + +class ReloadConfigsConsoleCommand(ConsoleCommand): + def __init__(self): + ConsoleCommand.__init__(self, "ls_reload_configs", "", "Reload all configuration information", PERM_CONFIG) + + def doCommand(self, invoker, args): + if len(args) != 1: + self.printUsage(invoker) + return + configs.reloadConfigs() + actions.logAction(invoker, "reloaded configs") + hud.consolePrint(invoker, "Configs reloaded") + +consoleUserInterface.registerCommand(ReloadConfigsConsoleCommand()) \ No newline at end of file
A lib\lonestar\extensions\list_admins.py
Code:Index: lib/lonestar/extensions/list_admins.py =================================================================== --- lib/lonestar/extensions/list_admins.py (revision 0) +++ lib/lonestar/extensions/list_admins.py (revision 0) @@ -0,0 +1,44 @@ +# $Id: punishment.py 569 2009-02-11 08:21:47Z Ewok $ +# Copyright 2008 Tim Thelin +# +# This file is part of LoneStar. +# +# LoneStar 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. +# +# LoneStar 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 LoneStar. If not, see <http://www.gnu.org/licenses/>. + +from lonestar import hud, client +from lonestar.client import playerManager, PERM_ADMIN, adminFilter +from lonestar.ui import consoleUserInterface, ConsoleCommand +from admins import adminManager + +class ListAdminsConsoleCommand(ConsoleCommand): + def __init__(self): + ConsoleCommand.__init__(self, "ls_list_admins", "", "Lists all admins currently connected", PERM_ADMIN) + + def doCommand(self, invoker, args): + if len(args) != 1: + self.printUsage(invoker) + return + admins = playerManager.filterPlayers(adminFilter) + hud.consolePrint(invoker, "Admins currently connected:") + if len(admins) != 0: + for i, a in enumerate(admins): + g = adminManager.accounts[a.steamId].group + if g: + line = "%d) %s (%s)" % (i, a.name, g.name) + else: + line = "%d) %s" % (i, a.name) + hud.consolePrint(invoker, line) + else: + hud.consolePrint(invoker, "None") +consoleUserInterface.registerCommand(ListAdminsConsoleCommand()) \ No newline at end of file
A lib\lonestar\extensions\admin_chat.py
Code:Index: lib/lonestar/extensions/admin_chat.py =================================================================== --- lib/lonestar/extensions/admin_chat.py (revision 0) +++ lib/lonestar/extensions/admin_chat.py (revision 0) @@ -0,0 +1,64 @@ +# $Id: punishment.py 569 2009-02-11 08:21:47Z Ewok $ +# Copyright 2008 Tim Thelin +# +# This file is part of LoneStar. +# +# LoneStar 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. +# +# LoneStar 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 LoneStar. If not, see <http://www.gnu.org/licenses/>. + +from lonestar import hud, client +from lonestar.client import playerManager, PERM_ADMIN +from lonestar.ui import chatUserInterface, ChatCommand +from lonestar.logging import logger + +class AdminChatCommand(ChatCommand): + def __init__(self): + ChatCommand.__init__(self, "@", "message", "Allows admins to talk to admins, admins to talk to players, and players to talk to admins") + + def doCommand(self, invoker, team, message, cmd, rest): + if not rest: + self.printUsage(invoker) + return False + + if invoker and not invoker.hasPermission(client.PERM_ADMIN): # Normal user wanting to talk to an admin + admins = playerManager.filterPlayers(client.inGameAdminFilter) + adminMessage = "(To Admins) %s: %s" % (invoker.name, rest) + hud.chatPrint(invoker, "(Sent to Admins) %s: %s" % (invoker.name, rest)) + logger.chat(adminMessage) + hud.chatBroadcast(admins, adminMessage) + hud.centerBroadcast(admins, adminMessage, 0xFFFF) #cyan + + else: #must be server or admin + adminName = client.getName(invoker) + + if team: #admins talking to themselves + admins = playerManager.filterPlayers(client.inGameAdminFilter) + adminMessage = "(Admin Chat) %s: %s" % (adminName, rest) + logger.chat(adminMessage) + hud.chatBroadcast(admins, adminMessage) + hud.centerBroadcast(admins, adminMessage, 0xFF00) #green + + else: #admin talking to everyone + nonAdmins = playerManager.filterPlayers(client.inGameNonAdminFilter) + hud.chatBroadcast(nonAdmins, "(Admin): %s" % rest) + + admins = playerManager.filterPlayers(client.inGameAdminFilter) + adminMessage = "(Admin) %s: %s" % (adminName, rest) + hud.chatBroadcast(admins, adminMessage) + logger.chat(adminMessage) + + everyone = playerManager.filterPlayers(client.inGamePersonFilter) + hud.centerBroadcast(everyone, rest, 0xFF0000) #red + return False + +chatUserInterface.registerCommand(AdminChatCommand()) \ No newline at end of file
M lib\lonestar\extensions\debug.py
Code:Index: lib/lonestar/extensions/debug.py =================================================================== --- lib/lonestar/extensions/debug.py (revision 580) +++ lib/lonestar/extensions/debug.py (working copy) @@ -17,9 +17,10 @@ # along with LoneStar. If not, see <http://www.gnu.org/licenses/>. import gc -from lonestar import hud +from lonestar import hud, actions from lonestar.client import PERM_CONFIG from lonestar.ui import consoleUserInterface, ConsoleCommand +from lonestar.logging import logger class GcDebugConsoleCommand(ConsoleCommand): def __init__(self): @@ -48,5 +49,25 @@ gc.collect() hud.consolePrint(invoker, "Python GC run complete.") +class DebugTargetConsoleCommand(ConsoleCommand): + def __init__(self): + ConsoleCommand.__init__(self, "ls_debug_target", "<target>", "Sets who gets the debug messages", PERM_CONFIG) + + def doCommand(self, invoker, args): + if len(args) != 2: + self.printUsage(invoker) + return + if args[ 1 ] == "none": + logger.logTarget = None + actions.logAction(invoker, "set debug target to nobody") + else: + target = self.findTarget(invoker, args[ 1 ]) + if not target: + return + logger.logTarget = target + hud.consolePrint(target, "You have now been set as the debug target") + actions.logActionAgainstPlayer(invoker, target, "set debug target to") + consoleUserInterface.registerCommand(GcDebugConsoleCommand()) consoleUserInterface.registerCommand(ForceGcCollectionConsoleCommand()) +consoleUserInterface.registerCommand(DebugTargetConsoleCommand())
-
03-15-09, 09:23 PM #2
Re: patch: refactor classes in commands.py to extensions & fix ls_list_admin
delicious, nice work :9
-
03-15-09, 10:53 PM #3
Re: patch: refactor classes in commands.py to extensions & fix ls_list_admin
https://ttp.devguard.com/trac/lonestar/ticket/3
It has the complete diff in there as well.
-
03-15-09, 11:12 PM #4
Re: patch: refactor classes in commands.py to extensions & fix ls_list_admin
Thanks for doing this.
Regarding list_admins.py, now that you mention it about admins.py, I think the list admins command should be folded into admins.py. The purpose behind admins.py is to define admins, and it makes sense that the extension that manages them is also the one that lets you see them in-game.
Regarding you're fix to list_admins.py, was there an actual bug or was the issue simply that it wasn't printing anything out in the case of no admins being found?
Regarding your patch question, I think what you did with using trac should be the way its handled going forward. We didn't have an issue tracker at the time the patch policy was made, but now that we have one I think it would be best to attach the complete diff on the issue report.
-
03-16-09, 07:42 AM #5
Re: patch: refactor classes in commands.py to extensions & fix ls_list_admin
the ls_list_admins was not print anything at all, other than the label "current admins". It will throw an exception cause it refers to client.PDATA_ADMIN_GROUP, which doesn't exist anywhere. I assume it was deprecated at some point.
-
03-16-09, 12:01 PM #6
Re: patch: refactor classes in commands.py to extensions & fix ls_list_admin
Yeah I redid how permissions and groups were done and that private data (PDATA) was purged out. I must have missed that command when doing the refactoring.
-
03-16-09, 12:04 PM #7
Re: patch: refactor classes in commands.py to extensions & fix ls_list_admin
Shouldn't the definition of an admin be outside of extensions?
Do you want me to make the admin list changes as a part of this patch or a new one? I would prefer a new one.
-
03-16-09, 01:11 PM #8
Re: patch: refactor classes in commands.py to extensions & fix ls_list_admin
The permission and group framework is in the core of LoneStar, and being an "admin" is layered on top of that (basically being an admin is essentially just having some specific permissions and/or being a part of a special "admin group").
This way the way admins are handled is now a component that can be switched out with a new implementation. Other extensions that care don't need to now how admins are implemented, all they need to do is make sure that a player has the right permissions.
The state you're looking at lonestar is in the middle of a larger refactor that's trying to reduce the lonestar core to just a core.
The list admins change is easy enough that I'll just do it myself once I apply your patch.
-
03-16-09, 01:39 PM #9
Re: patch: refactor classes in commands.py to extensions & fix ls_list_admin
Smooth, I am going to make an attempt at making the team management (swap teams) have menu items.
-
03-16-09, 02:46 PM #10
Re: patch: refactor classes in commands.py to extensions & fix ls_list_admin
Originally Posted by noexitpath
Thread Information
Users Browsing this Thread
There are currently 2 users browsing this thread. (0 members and 2 guests)
Bookmarks