[Cherbot-commit] SF.net SVN: cherbot: [46] trunk
Status: Alpha
Brought to you by:
christianhujer
|
From: <chr...@us...> - 2007-06-09 14:02:52
|
Revision: 46
http://svn.sourceforge.net/cherbot/?rev=46&view=rev
Author: christianhujer
Date: 2007-06-09 07:02:47 -0700 (Sat, 09 Jun 2007)
Log Message:
-----------
Removed old code, updated requirements.
Modified Paths:
--------------
trunk/cherbot.iml
trunk/cherbot.ipr
trunk/src/doc/requirements2.0.xhtml
Removed Paths:
-------------
trunk/src/net/sf/cherbot/BlackListManager.java
trunk/src/net/sf/cherbot/CherBot.java
trunk/src/net/sf/cherbot/CherBotException.java
trunk/src/net/sf/cherbot/CherBotLogger.java
trunk/src/net/sf/cherbot/CherBotPermission.java
trunk/src/net/sf/cherbot/CherBotSecurityManager.java
trunk/src/net/sf/cherbot/CollectionsManager.java
trunk/src/net/sf/cherbot/CommType.java
trunk/src/net/sf/cherbot/Crime.java
trunk/src/net/sf/cherbot/CrimeManager.java
trunk/src/net/sf/cherbot/CronManager.java
trunk/src/net/sf/cherbot/DeathsManager.java
trunk/src/net/sf/cherbot/DummyManagerProxy.java
trunk/src/net/sf/cherbot/EmotesManager.java
trunk/src/net/sf/cherbot/ExampleTestCase.java
trunk/src/net/sf/cherbot/ExampleTester.java
trunk/src/net/sf/cherbot/GreetingsManager.java
trunk/src/net/sf/cherbot/GroupManager.java
trunk/src/net/sf/cherbot/LamentsManager.java
trunk/src/net/sf/cherbot/MailManager.java
trunk/src/net/sf/cherbot/Manager.java
trunk/src/net/sf/cherbot/ManagerDocumenter.java
trunk/src/net/sf/cherbot/NoSuchPlayerException.java
trunk/src/net/sf/cherbot/NoobManager.java
trunk/src/net/sf/cherbot/PlayerManager.java
trunk/src/net/sf/cherbot/PollManager.java
trunk/src/net/sf/cherbot/RodBabyManager.java
trunk/src/net/sf/cherbot/RodBabyWannabeManager.java
trunk/src/net/sf/cherbot/SalesManager.java
trunk/src/net/sf/cherbot/SmutException.java
trunk/src/net/sf/cherbot/SmutManager.java
trunk/src/net/sf/cherbot/TestManager.java
trunk/src/net/sf/cherbot/TimeManager.java
Modified: trunk/cherbot.iml
===================================================================
--- trunk/cherbot.iml 2007-06-08 19:41:29 UTC (rev 45)
+++ trunk/cherbot.iml 2007-06-09 14:02:47 UTC (rev 46)
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
-<module version="4" relativePaths="true" type="JAVA_MODULE">
+<module relativePaths="true" type="JAVA_MODULE" version="4">
<component name="DependecySynchronizer" />
<component name="ModuleRootManager" />
<component name="NewModuleRootManager" inherit-compiler-output="true">
Modified: trunk/cherbot.ipr
===================================================================
--- trunk/cherbot.ipr 2007-06-08 19:41:29 UTC (rev 45)
+++ trunk/cherbot.ipr 2007-06-09 14:02:47 UTC (rev 46)
@@ -1,11 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
-<project version="4" relativePaths="true">
+<project relativePaths="true" version="4">
<component name="AntConfiguration">
<defaultAnt bundledAnt="true" />
</component>
<component name="BuildJarProjectSettings">
<option name="BUILD_JARS_ON_MAKE" value="false" />
</component>
+ <component name="ClearCase" />
<component name="CodeStyleProjectProfileManger">
<option name="PROJECT_PROFILE" />
<option name="USE_PROJECT_LEVEL_SETTINGS" value="false" />
@@ -42,6 +43,15 @@
<option name="METHOD_ANNOTATION_WRAP" value="1" />
<option name="CLASS_ANNOTATION_WRAP" value="1" />
<option name="FIELD_ANNOTATION_WRAP" value="1" />
+ <ADDITIONAL_INDENT_OPTIONS fileType="js">
+ <option name="INDENT_SIZE" value="4" />
+ <option name="CONTINUATION_INDENT_SIZE" value="8" />
+ <option name="TAB_SIZE" value="4" />
+ <option name="USE_TAB_CHARACTER" value="false" />
+ <option name="SMART_TABS" value="false" />
+ <option name="LABEL_INDENT_SIZE" value="0" />
+ <option name="LABEL_INDENT_ABSOLUTE" value="false" />
+ </ADDITIONAL_INDENT_OPTIONS>
</value>
</option>
<option name="USE_PER_PROJECT_SETTINGS" value="true" />
@@ -94,7 +104,7 @@
<option name="MAXIMUM_HEAP_SIZE" value="128" />
</component>
<component name="EntryPointsManager">
- <entry_points />
+ <entry_points version="2.0" />
</component>
<component name="ExportToHTMLSettings">
<option name="PRINT_LINE_NUMBERS" value="false" />
@@ -135,7 +145,9 @@
<option name="ignoreLocalVariables" value="false" />
<option name="ignorePrivateMethodsAndFields" value="false" />
</inspection_tool>
- <inspection_tool class="FeatureEnvy" level="WARNING" enabled="true" />
+ <inspection_tool class="FeatureEnvy" level="WARNING" enabled="true">
+ <option name="ignoreTestCases" value="false" />
+ </inspection_tool>
<inspection_tool class="InstanceofThis" level="WARNING" enabled="true" />
<inspection_tool class="MagicNumber" level="WARNING" enabled="true">
<option name="m_ignoreInHashCode" value="true" />
@@ -191,7 +203,9 @@
</inspection_tool>
<inspection_tool class="ThrowablePrintStackTrace" level="WARNING" enabled="true" />
<inspection_tool class="ThreadDumpStack" level="WARNING" enabled="true" />
- <inspection_tool class="ObsoleteCollection" level="WARNING" enabled="true" />
+ <inspection_tool class="ObsoleteCollection" level="WARNING" enabled="true">
+ <option name="ignoreLibraryArguments" value="false" />
+ </inspection_tool>
<inspection_tool class="SystemOutErr" level="WARNING" enabled="true" />
<inspection_tool class="UseOfAnotherObjectsPrivateField" level="WARNING" enabled="true" />
<inspection_tool class="AssignmentToCollectionFieldFromParameter" level="WARNING" enabled="true">
@@ -204,8 +218,12 @@
<inspection_tool class="PackageVisibleInnerClass" level="WARNING" enabled="true" />
<inspection_tool class="ProtectedField" level="WARNING" enabled="true" />
<inspection_tool class="ProtectedInnerClass" level="WARNING" enabled="true" />
- <inspection_tool class="PublicField" level="WARNING" enabled="true" />
- <inspection_tool class="PublicInnerClass" level="WARNING" enabled="true" />
+ <inspection_tool class="PublicField" level="WARNING" enabled="true">
+ <option name="ignoreEnums" value="false" />
+ </inspection_tool>
+ <inspection_tool class="PublicInnerClass" level="WARNING" enabled="true">
+ <option name="ignoreEnums" value="false" />
+ </inspection_tool>
<inspection_tool class="ReturnOfCollectionField" level="WARNING" enabled="true">
<option name="ignorePrivateMethods" value="true" />
</inspection_tool>
@@ -305,7 +323,7 @@
<option name="m_maxLength" value="64" />
</inspection_tool>
<inspection_tool class="BooleanMethodNameMustStartWithQuestion" level="WARNING" enabled="true">
- <option name="nameCheckString" value="is,can,has,should,could,will,shall,check,contains,equals,add,put,remove,startsWith,endsWith" />
+ <option name="questionString" value="is,can,has,should,could,will,shall,check,contains,equals,add,put,remove,startsWith,endsWith" />
</inspection_tool>
<inspection_tool class="ClassNameSameAsAncestorName" level="WARNING" enabled="true" />
<inspection_tool class="ClassNamingConvention" level="WARNING" enabled="true">
@@ -361,7 +379,7 @@
<option name="m_maxLength" value="20" />
</inspection_tool>
<inspection_tool class="NonBooleanMethodNameMayNotStartWithQuestion" level="WARNING" enabled="true">
- <option name="nameCheckString" value="is,can,has,should,could,will,shall,check,contains,equals,startsWith,endsWith" />
+ <option name="questionString" value="is,can,has,should,could,will,shall,check,contains,equals,startsWith,endsWith" />
</inspection_tool>
<inspection_tool class="UpperCaseFieldNameNotConstant" level="WARNING" enabled="true" />
<inspection_tool class="NonExceptionNameEndsWithException" level="WARNING" enabled="true" />
@@ -508,7 +526,9 @@
<inspection_tool class="EmptyClass" level="WARNING" enabled="true" />
<inspection_tool class="FinalMethodInFinalClass" level="WARNING" enabled="true" />
<inspection_tool class="MissingDeprecatedAnnotation" level="WARNING" enabled="true" />
- <inspection_tool class="MissingOverrideAnnotation" level="WARNING" enabled="true" />
+ <inspection_tool class="MissingOverrideAnnotation" level="WARNING" enabled="true">
+ <option name="useJdk6Rules" value="false" />
+ </inspection_tool>
<inspection_tool class="MultipleTopLevelClassesInFile" level="WARNING" enabled="true" />
<inspection_tool class="NoopMethodInAbstractClass" level="WARNING" enabled="true" />
<inspection_tool class="ProtectedMemberInFinalClass" level="WARNING" enabled="true" />
@@ -849,6 +869,13 @@
<output url="file://$PROJECT_DIR$/ideaclasses" />
</component>
<component name="ProjectRunConfigurationManager" />
+ <component name="ResourceManagerContainer">
+ <option name="myResourceBundles">
+ <value>
+ <list size="0" />
+ </value>
+ </option>
+ </component>
<component name="RmicSettings">
<option name="IS_EANABLED" value="false" />
<option name="DEBUGGING_INFO" value="true" />
@@ -857,6 +884,10 @@
<option name="ADDITIONAL_OPTIONS_STRING" value="" />
</component>
<component name="StarteamVcsAdapter" />
+ <component name="SvnBranchConfigurationManager" />
+ <component name="VcsDirectoryMappings">
+ <mapping directory="" vcs="svn" />
+ </component>
<component name="VssVcs" />
<component name="com.intellij.jsf.UserDefinedFacesConfigs">
<option name="USER_DEFINED_CONFIGS">
@@ -1085,6 +1116,5 @@
<option name="COPY_FORMS_RUNTIME_TO_OUTPUT" value="true" />
<option name="DEFAULT_LAYOUT_MANAGER" value="GridLayoutManager" />
</component>
- <UsedPathMacros />
</project>
Modified: trunk/src/doc/requirements2.0.xhtml
===================================================================
--- trunk/src/doc/requirements2.0.xhtml 2007-06-08 19:41:29 UTC (rev 45)
+++ trunk/src/doc/requirements2.0.xhtml 2007-06-09 14:02:47 UTC (rev 46)
@@ -26,5 +26,14 @@
<li>Web interface.</li>
<li>Graphical user interface.</li>
</ul>
+ <h2>Detailed requirements</h2>
+ <ul>
+ <li>CherBot must work for Daimonin.</li>
+ <li>CherBot must work for Crossfire.</li>
+ <li>CherBot must work for IRC.</li>
+ <li>CherBot must be able to connect to more than one server.</li>
+ <li>CherBot must maintain groups called clans.</li>
+ <li>CherBot must be able to act as a communication proxy / multiplexer for members of a clan.</li>
+ </ul>
</body>
</html>
Deleted: trunk/src/net/sf/cherbot/BlackListManager.java
===================================================================
--- trunk/src/net/sf/cherbot/BlackListManager.java 2007-06-08 19:41:29 UTC (rev 45)
+++ trunk/src/net/sf/cherbot/BlackListManager.java 2007-06-09 14:02:47 UTC (rev 46)
@@ -1,134 +0,0 @@
-/*
- * Copyright © 2006, Christian Hujer and the CherBot developers. All Rights Reserved.
- * License: GNU General Public License v2.0 or newer.
- * See file COPYING in the root directory of this project.
- */
-
-package net.sf.cherbot;
-
-import java.util.SortedSet;
-import java.util.TreeSet;
-import org.jetbrains.annotations.NotNull;
-
-/**
- * Manages a black list of users that may not use Cherbot.
- * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
- */
-@Manager.Description("Blacklist of players that are denied to use Cherbot.")
-@Manager.Features({ "Blacklist players that are denied to use Cherbot." })
-public class BlackListManager extends Manager {
-
- /**
- * Permission to modify blacklist.
- */
- private static final String PERM_BLACKLIST = "Blacklist";
-
- /**
- * The black list.
- */
- private SortedSet<String> blacklist = new TreeSet<String>();
-
- { // Commands
- new Command("(?:$LIST ?(?:the )?blacklist(?:ed players)?|wh(?:o|ich players?) (?:is|are|r) (?:blacklisted|on (?:the )?blacklist))[.!?]?") {
- @Description("Lists the blacklisted players.")
- @Examples({ "List blacklist", "Tell me the blacklisted players.", "Who is blacklisted?", "Which players are on the blacklist?" })
- @Override public void performImpl() {
- listBlacklist();
- }
- };
- new Command("(?:put|add) $PLAYER (?:to|on) blacklist[.!]?") {
- @Description("Puts a player on the blacklist.")
- @Examples({ "Put Lead on blacklist.", "Add Lead to blacklist." })
- @Override public void performImpl() {
- addBlacklist(player(1));
- }
- };
- new Command("(?:remove) $PLAYER from blacklist[.!]?") {
- @Description("Removes a player from the blacklist.")
- @Examples({ "Remove Lead from blacklist." })
- @Override public void performImpl() {
- removeBlacklist(player(1));
- }
- };
- } // Commands
-
- /**
- * Create the BlackListManager.
- * @param cherbot CherBot
- */
- public BlackListManager(@NotNull final CherBot cherbot) {
- super(cherbot, "blacklist");
- }
-
- /**
- * List the blacklist.
- */
- private void listBlacklist() {
- if (blacklist.size() == 0) {
- answer("Noone's on the blacklist yet.");
- } else {
- final StringBuilder sb = new StringBuilder();
- sb.append("The following players are blacklisted: ");
- concat(sb, blacklist);
- sb.append('.');
- answer(sb.toString());
- }
- }
-
- /**
- * Puts a player to the blacklist.
- * @param player Player to blacklist
- */
- private void addBlacklist(@NotNull final String player) {
- checkPermission(PERM_BLACKLIST);
- if (blacklist.add(player)) {
- answer("Added " + player + " to the blacklist.");
- tell(player, getActor() + " has put you on the blacklist. You cannot use Cherbot anymore.");
- } else {
- answer(player + " already was on the blacklist.");
- }
- }
-
- /**
- * Removes a player from the blacklist.
- * @param player Player to remove
- */
- private void removeBlacklist(@NotNull final String player) {
- checkPermission(PERM_BLACKLIST);
- if (blacklist.remove(player)) {
- answer("Removed " + player + " from the blacklist.");
- tell(player, getActor() + " has removed you from the blacklist. You can use Cherbot again.");
- } else {
- answer(player + " wasn't blacklisted anyway.");
- }
- }
-
- /**
- * Checks wether a player is blacklisted.
- * @param player Player to check
- * @return <code>true</code> if <var>player</var> is blacklisted, otherwise <code>false</code>.
- */
- public boolean isBlacklisted(@NotNull final String player) {
- return blacklist.contains(player);
- }
-
- /**
- * Checks wether the actor is blacklisted.
- * @return <code>true</code> if the actor is blacklisted, otherwise <code>false</code>.
- */
- public boolean isBlacklisted() {
- return blacklist.contains(getActor());
- }
-
- /**
- * {@inheritDoc}
- */
- @Override public void help() {
- answer("I have a blacklist. Players on the blacklist cannot use Cherbot.");
- }
-
- { // IO Modules
- new CollectionIOModule("blacklist.txt", blacklist, false);
- } // IO Modules
-
-} // class BlackListManager
Deleted: trunk/src/net/sf/cherbot/CherBot.java
===================================================================
--- trunk/src/net/sf/cherbot/CherBot.java 2007-06-08 19:41:29 UTC (rev 45)
+++ trunk/src/net/sf/cherbot/CherBot.java 2007-06-09 14:02:47 UTC (rev 46)
@@ -1,809 +0,0 @@
-/*
- * Copyright © 2006, Christian Hujer and the CherBot developers. All Rights Reserved.
- * License: GNU General Public License v2.0 or newer.
- * See file COPYING in the root directory of this project.
- */
-
-package net.sf.cherbot;
-
-
-import java.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.text.BreakIterator;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import net.sf.cherbot.Manager.Command;
-
-/**
- * A Daimonin bot.
- * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
- * @todo split this class into four: A generic base class for robots, a class handling Daimonin-specific stuff, an interface for network
- * implementations implemted by the latter, and this specific CherBot subclass.
- * @todo perhaps add a graphical interface.
- */
-public class CherBot {
-
- /**
- * Lihes of code.
- */
- private static final int LINES_OF_CODE = 11137;
-
- /**
- * Wether to stop.
- * This variable initially is false.
- * Telling the Bot to stop sets this variable to true, terminating the two thread loops for receiving packets and the console.
- */
- private boolean stop;
-
- /**
- * The user name this bot should use for connecting with the server.
- */
- private String username;
-
- /**
- * The password this bot sohuld use for connecting with the server.
- */
- private String password;
-
- /**
- * The SecurityManager.
- * Provides access to security handling possibly used by every other manager.
- * Thus needs to be available to all managers.
- */
- private CherBotSecurityManager securityManager;
-
- /**
- * The internal manager.
- */
- private InternalManager internalManager;
-
- /**
- * The Blacklist manager.
- */
- private BlackListManager blacklistManager;
-
- /**
- * The Player manager.
- */
- private PlayerManager playerManager;
-
- /**
- * The Managers as a list for looping or similar.
- * It's a List because the order in which the managers are added really matters.
- * Managers might have regular expression overlapping, an input string could match the commands of more than just one manager.
- * The managers are searched in their creation order.
- * The basic association relation between the bot (1) and the managers (n) is a bidirectional composition.
- */
- private List<Manager> managers = new ArrayList<Manager>();
-
- /**
- * The Managers as map, for getting the Manager on a specific topic.
- * Key: topic of Manager ({@link Manager#getTopic()}).
- * Value: Manager
- */
- private Map<String, Manager> managerMap = new HashMap<String, Manager>();
-
- /**
- * The Managers with timers.
- */
- private List<Manager> timers = new ArrayList<Manager>();
-
- /**
- * The Commands.
- * The order is important, this must be a List.
- */
- private List<Command> commands = new ArrayList<Command>();
-
- /**
- * Main program.
- * @param args command line arguments
- * @throws IOException in case of I/O problems
- */
- public static void main(final String... args) throws IOException {
- final CherBot bot = new CherBot();
- bot.connect(args[0], args[1], args[2]);
- bot.run();
- }
-
- /**
- * Create the CherBot.
- * This creates the managers.
- * @todo put the list of managers that should be created in a file, read the file and use reflection to create the managers.
- * This would allow users to configure what modules the bot should load without recompiling the bot.
- */
- public CherBot() {
- // Add Managers
- // The order is important, since commands (regexes) are searched in the order the managers are constructed.
- // Also some managers require other managers to already exist
- new SmutManager(this);
- securityManager = new CherBotSecurityManager(this);
- internalManager = new InternalManager(this);
- blacklistManager = new BlackListManager(this);
- playerManager = new PlayerManager(this);
- new TimeManager(this);
- new TestManager(this);
- new GreetingsManager(this);
- new LamentsManager(this);
- new CollectionsManager(this);
- //new CrimeManager(this);
- new RodBabyManager(this);
- new RodBabyWannabeManager(this);
- new DeathsManager(this);
- new PollManager(this);
- new SalesManager(this);
- new MailManager(this);
- new EmotesManager(this);
- new GroupManager(this);
- new NoobManager(this);
- }
-
- /**
- * Quit Cherbot.
- */
- public void quit() {
- System.exit(0);
- }
-
- /**
- * Add a Manager.
- * The constructor of Manager invokes this method.
- * So do not call this method or a Manager would be added twice.
- * @param manager Manager to add
- */
- public void addManager(final Manager manager) {
- managers.add(manager);
- if (manager.getTicksDelay() != 0) {
- timers.add(manager);
- }
- managerMap.put(manager.getTopic(), manager);
- }
-
- /**
- * Get a Manager for a certain topic.
- * @param topic Topic to get Manager for
- * @return Manager for <var>topic</var> or <code>null</code> if no manager for the specified topic is known
- */
- public Manager getManager(final String topic) {
- return managerMap.get(topic);
- }
-
- /**
- * Get all managers.
- * The returned collection is immutable.
- * @return all managers
- */
- public Collection<Manager> managers() {
- return Collections.unmodifiableList(managers);
- }
-
- /**
- * Get the SecurityManager.
- * Don't rely on the SecurityManager instance being the same all the time for an instance of CherBot.
- * The SecurityManager might change over the time.
- * @return SecurityManager
- */
- public CherBotSecurityManager getSecurityManager() {
- return securityManager;
- }
-
- /**
- * Add a Command.
- * The constructor of Manager.Command indirectly invokes this method by invoking Manager.addCommand.
- * So do not call this method or a Command would be added twice.
- * @param command Command to add
- */
- public void addCommand(final Command command) {
- commands.add(command);
- }
-
- /**
- * Get username used by the bot.
- * @return username
- */
- public String getUsername() {
- return username;
- }
-
- /**
- * Connect to a server.
- * @param username username
- * @param password password
- * @param server Server to connect to
- * @throws IOException if the socket cannot be opened.
- */
- @SuppressWarnings({ "SocketOpenedButNotSafelyClosed" })
- public void connect(final String username, final String password, final String server) throws IOException {
- this.username = username;
- this.password = password;
- try {
- internalManager.load();
- } catch (final Exception e) {
- System.err.println(e);
- }
- //say("food");
- }
-
- /**
- * Keep the bot running.
- * @throws IOException in case of I/O problems
- */
- public void run() throws IOException {
- try {
- while (!stop) {
- }
- } finally {
- try {
- internalManager.save();
- } catch (final Exception e) {
- System.err.println(e);
- }
- }
- }
-
- /**
- * Answer.
- * @param cs String to answer
- */
- public void answer(final CharSequence cs) {
- tell(actor, cs.toString()); // TODO: Improve CharSequence handling
- }
-
- /**
- * Shout.
- * @param s String to shout
- */
- public void shout(final String s) {
- final StringBuilder sb = new StringBuilder();
- for (final String line : lineSplit(s)) {
- sb.setLength(0);
- sb.append("/shout ");
- sb.append(line);
- }
- }
-
- /**
- * Tell.
- * @param p Player name
- * @param s String to tell
- */
- public void tell(final String p, final String s) {
- if (s.length() == 0) {
- return; // nothing to tell.
- }
- if (p == null) {
- println(s);
- } else {
- // either lineSplit or ncom has a bug. Probably lineSplit.
- final StringBuilder sb = new StringBuilder();
- for (final String line : lineSplit(s)) {
- sb.setLength(0);
- }
- }
- }
-
- /**
- * Reply.
- * @param s String to tell
- * @throws IOException in case of I/O problems.
- */
- public void reply(final String s) throws IOException {
- final StringBuilder sb = new StringBuilder();
- for (final String line : lineSplit(s)) {
- sb.setLength(0);
- }
- }
-
- /**
- * Say.
- * @param s String to say
- */
- public void say(final String s) {
- final StringBuilder sb = new StringBuilder();
- for (final String line : lineSplit(s)) {
- sb.setLength(0);
- }
- }
-
- /**
- * Split a String into substrings.
- * @param s String to split
- * @return substrings
- */
- @SuppressWarnings({ "AssignmentToForLoopParameter" })
- private static Iterable<String> lineSplit(final String s) {
- final BreakIterator it = BreakIterator.getLineInstance();
- it.setText(s);
- final List<String> ret = new ArrayList<String>();
- final int width = 230;
- for (int end = it.last(), split = it.first(), current = 0; current <= end;) {
- current = it.next();
- if (current - split > width) {
- current = it.previous();
- if (current == split) {
- current = it.next();
- }
- ret.add(s.substring(split, current));
- split = current;
- } else if (current == end) {
- ret.add(s.substring(split, current));
- current++;
- }
- }
- return ret;
- }
-
- /**
- * Pattern for game entering.
- */
- private static final Pattern enter = Pattern.compile("(\\S+) has entered the game.");
-
- /**
- * Pattern for game kill.
- */
- private static final Pattern kill = Pattern.compile("(.+) killed (\\S+)( with (.*))?.");
-
- /**
- * Dispatch a packet of data.
- * @param data packet to dispatch
- * @throws IOException in case of I/O problems
- */
- private void dispatch(final byte[] data) throws IOException {
- } // dispatch
-
- private static final String[] colors = {
- "\000\033[0m\001", // default / white
- "\000\033[33m\001", // orange
- "\000\033[96m\001", // light blue / navy
- "\000\033[91m\001", // red
- "\000\033[92m\001", // green
- "\000\033[94m\001", // blue
- "\000\033[37m\001", // grey
- "\000\033[93m\001", // yellow
- "\000\033[36m\001", // dark navy
- "\000\033[0m\001", // don't know
- "\000\033[93m\001", // yellow again
- };
-
- /**
- * Switch output to a certain color.
- * @param n color to switch to
- */
- private static void switchColor(final int n) {
- try {
- System.out.print(colors[n]);
- } catch (final ArrayIndexOutOfBoundsException e) {
- System.err.println("Unknown color number: " + n);
- }
- }
-
- /**
- * Handle communication.
- * @param ct Communication Type
- * @param who speaker
- * @param msg message
- * @throws IOException in case of I/O problems
- * @todo this needs to be improved so /shout can also be used to communicate with Cherbot and Cherbot could respond on shout
- */
- private void communicate(final CommType ct, final String who, final String msg) throws IOException {
- playerManager.see(who);
- if (username.equals(who)) {
- return;
- } // avoid loop dispatch!
- if (ct == CommType.SHOUT) {
- final Pattern p = Pattern.compile(username + "(?:(?:,|:)? *)(.*)");
- final Matcher matcher = p.matcher(msg);
- if (matcher.matches()) {
- final String cmd = matcher.group(1);
- dispatch(who, cmd);
- }
- } else {
- dispatch(who, msg);
- }
- }
-
- /**
- * Who executes the current / executed the last command.
- */
- private String actor;
-
- /**
- * Get the actor (player that executes current / executed the last command).
- * @return actor
- */
- public String getActor() {
- return actor;
- }
-
- /**
- * Dispatch a message, try to execute it's command.
- * @param who speaker
- * @param rawCmd Command to perform
- * @todo this needs to be improved so /shout can also be used to communicate with Cherbot and Cherbot could respond on shout
- */
- private synchronized void dispatch(final String who, final String rawCmd) {
- final String cookedCmd = rawCmd.replaceAll("\\s+", " ").trim();
- actor = who;
- if (actor != null && blacklistManager.isBlacklisted()) {
- answer("You are denied.");
- return;
- }
- try {
- for (final Command command : commands) {
- if (command.perform(cookedCmd)) {
- break;
- }
- }
- } catch (final CherBotException e) {
- answer("I can't: " + e.getMessage());
- } catch (final SecurityException e) {
- answer("I don't want to: " + e.getMessage());
- }
- }
-
- /**
- * Handle enter.
- * @param who person that entered.
- */
- private void enter(final String who) {
- for (final Manager manager : managers) {
- manager.entered(who);
- }
- }
-
- /**
- * Handle kill.
- * @param killer Killer
- * @param who person that was killed
- * @param with with what
- * @throws IOException in case of I/O problems
- */
- private void kill(final String killer, final String who, final String with) throws IOException {
- if (username.equals(who)) {
- return;
- } // avoid lamenting myself
- for (final Manager manager : managers) {
- manager.died(who, killer, with);
- }
- }
-
- /**
- * Write a line to stdout.
- * @param s line to write
- */
- private static void println(final String s) {
- System.out.println(s);
- }
-
- /**
- * The internal manager.
- * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
- */
- @Manager.Description("Manages the other modules and gives some general information about the bot.")
- @Manager.Features({
- "Load and save persistent data.",
- "List commands.",
- "Tell what's new."
- })
- private class InternalManager extends Manager {
-
- private static final String PERM_SAVE = "Internal.Save";
-
- private static final String PERM_LOAD = "Internal.Load";
-
- private static final String PERM_QUIT = "Internal.Quit";
-
- /* Commands. */ {
- new Command("(?:in )?wh(?:ich|at) (?:programming[- ])?language (?:(?:were|are) $YOU|have you been) (?:written|programmed|coded)(?: in)?[?]?") {
- @Description("You can ask in which language cherbot is written in.")
- @Examples({ "What language are you coded in?", "In which programming language have you been written?" })
- @Override public void performImpl() {
- answer("I'm written in " + LINES_OF_CODE + " of Java code.");
- }
- };
- new Command("save[.!]?") {
- @Description("Saves all module data to persistent storage.")
- @Examples({ "Save!" })
- @Override public void performImpl() {
- checkPermission(new CherBotPermission(PERM_SAVE));
- try {
- save();
- answer("Saved all modules.");
- } catch (final Exception e) {
- answer("Save failed: " + e);
- }
- }
- };
- new Command("save (\\w+)[.!]") {
- @Description("Saves a specific module's data to persistent storage.")
- @Examples({ "Save collections!", "Save sales!" })
- @Override public void performImpl() {
- final String module = matcher.group(1);
- checkPermission(new CherBotPermission(PERM_SAVE + '.' + module));
- try {
- managerMap.get(module).save();
- answer("Saved module " + module + '.');
- } catch (final NullPointerException e) {
- answer("No such module.");
- } catch (final Exception e) {
- answer("Error while saving module " + module + ": " + e);
- }
- }
- };
- new Command("load[.!]?") {
- @Description("Load all module data from persistent storage.")
- @Examples({ "Load!" })
- @Override public void performImpl() {
- checkPermission(new CherBotPermission(PERM_LOAD));
- try {
- load();
- answer("Loaded.");
- } catch (final Exception e) {
- answer("Save failed: " + e);
- }
- }
- };
- new Command("load (\\w+)[.!]?") {
- @Description("Load a specific module's data from persistent storage.")
- @Examples({ "Load collections!", "Load sales!" })
- @Override public void performImpl() {
- final String module = matcher.group(1);
- checkPermission(new CherBotPermission(PERM_LOAD + '.' + module));
- try {
- managerMap.get(module).load();
- answer("Loaded module " + module + '.');
- } catch (final NullPointerException e) {
- answer("No such module.");
- } catch (final Exception e) {
- answer("Error while loading module " + module + ": " + e);
- }
- }
- };
- new Command("help[.!]?") {
- @Description("Displays some general help.")
- @Examples({ "Help!" })
- @Override public void performImpl() {
- answer("More info: about, info, help commands, help topics, help usage, help testing");
- }
- };
- new Command("(about|tell me about $YOU)[.!]?") {
- @Description("Displays some information about Cherbot.")
- @Examples({ "About!", "Tell me about you!" })
- @Override public void performImpl() {
- answer("Hello. I am Cherbot, Cheristheus' stupid bot, written in 12 hours, approx. " + LINES_OF_CODE + " lines of code.\nI understand several commands, but most of them are privileged. If you talk to me, use short yet complete correct English sentences. I usually won't respond to single words thrown at me. If I say something like \"I don't want to.\", that means you used the correct command but you don't have enough permissions.\nAsk me about 'help topics' to find out what I can.");
- }
- };
- new Command("(list|show|help) modules[.!]?") {
- @Description("Lists which modules Cherbot has loaded.")
- @Examples({ "List modules!", "Show modules!" })
- @Override public void performImpl() {
- final StringBuilder mods = new StringBuilder();
- for (final Manager manager : managers) {
- if (mods.length() > 0) {
- mods.append(", ");
- } else {
- mods.append("Loaded modules: ");
- }
- mods.append(manager.getTopic());
- }
- mods
- .append(". ")
- .append(Integer.toString(managers.size()))
- .append(" modules total. Use 'help <modulename>' to get information on a specific module.");
- answer(mods.toString());
- }
- };
- new Command("(list|show|help) commands[.!]?") {
- @Description("Lists the commands. Won't really list the commands but show the modules, since the commands are quite a lot now.")
- @Examples({ "List commands!", "Show commands!" })
- @Override public void performImpl() {
- final StringBuilder sb = new StringBuilder();
- for (final Manager manager : managers) {
- if (sb.length() == 0) {
- sb.append("Loaded modules: ");
- } else {
- sb.append(", ");
- }
- sb.append(manager.getTopic());
- }
- sb.append(". To know the commands for a specific module, use 'help commands <modulename>', like 'help commands topics'.");
- answer(sb.toString());
- }
- };
- new Command("(list|show|help) commands? (of |from )?(the |module )?(\\w+)([- ](module|commands))?[.!]?") {
- @Description("Lists all commands from the specified module.")
- @Examples({ "Show commands from module sales", "Show commands from the sales-module!" })
- @Override public void performImpl() {
- final String topic = matcher.group(4);
- final StringBuilder sb = new StringBuilder();
- for (final Manager manager : managers) {
- if (topic.equals(manager.getTopic())) {
- sb.append("Commands for module ").append(topic).append('\n');
- for (final Command command : manager.commands()) {
- sb.append(command.getPattern()).append('\n');
- }
- answer(sb.toString());
- return;
- }
- }
- answer("No such module: " + topic);
- }
- };
- new Command("(list||show|help) (me )?all commands[.!]?") {
- @Description("Lists all commands. Please don't use it.")
- @Examples({ "List all commands!", "Show me all commands!" })
- @Override public void performImpl() {
- answer("The commands might be quite a lot. If you really want me to do that, tell me 'Really list all commands.'.");
- }
- };
- new Command("really (list|show|help) (me )?all commands[.!]?") {
- @Description("Lists all commands. Please don't use it.")
- @Examples({ "Really list all commands!", "Really show me all commands!" })
- @Override public void performImpl() {
- final StringBuilder sb = new StringBuilder();
- for (final Manager manager : managers) {
- sb.append(manager.getTopic()).append('\n').append(manager.getTopic().replaceAll(".", "-")).append('\n');
- for (final Command command : manager.commands()) {
- sb.append(command.getPattern()).append('\n');
- }
- }
- }
- };
- new Command("help (.*?)[.!]?") {
- @Description("List the help on a specific module.")
- @Examples({ "Help collections!", "Help sales!" })
- @Override public void performImpl() {
- final String topic = matcher.group(1);
- if (topic.equals("usage")) {
- answer("Usage: tell me a command. You may also use shout or say but I will nearly always respond in tell. I don't want to bother other players. Use good, clear, correct, complete English sentences, that will work best. Tell me 'help commands' to find out what I understand.");
- } else {
- for (final Manager manager : managers) {
- if (topic.equalsIgnoreCase(manager.getTopic())) {
- manager.help();
- }
- }
- }
- }
- };
- new Command("info[.!]?") {
- @Description("Gives some general info about Cherbot.")
- @Examples({ "Info" })
- @Override public void performImpl() {
- final StringBuilder info = new StringBuilder();
- info
- .append("Version: some alpha.\n")
- .append("Lines of code: approx. ")
- .append(LINES_OF_CODE)
- .append(".\n")
- .append("Loaded modules: ")
- .append(managers.size())
- .append(".\n")
- .append("Known commands: ")
- .append(commands.size())
- .append('.');
- answer(info.toString());
- }
- };
- new Command("how many commands do $YOU know[?]?") {
- @Description("Asks Cherbot how many commands it knows.")
- @Examples({ "How many commands do you know?" })
- @Override public void performImpl() {
- answer("I know " + commands.size() + " commands.");
- }
- };
- new Command("what('?s| is) new[?]?") {
- @Description("Reports what's new since the last versions.")
- @Examples({ "What's new?" })
- @Override public void performImpl() {
- whatsNew();
- }
- };
- new Command("ping") {
- @Description("Command to test wether Cherbot is still active. If Cherbot works, it will respond \"pong\".")
- @Examples({ "ping" })
- public void performImpl() {
- answer("pong");
- }
- };
- new Command("quit[.!]?") {
- @Description("Quit Cherbot.")
- @Examples({ "Quit!" })
- @Override public void performImpl() {
- checkPermission(new CherBotPermission(PERM_QUIT));
- answer("Quitting.");
- quit();
- }
- };
- } // Commands
-
- // private final String[] permissions = { PERM_SAVE, PERM_LOAD };
-
- /**
- * Create an internal manager.
- * @param cherBot Cher Bot
- */
- InternalManager(final CherBot cherBot) {
- super(cherBot, "topics");
- }
-
- /**
- * {@inheritDoc}
- */
- @Override public void help() {
- final StringBuilder topics = new StringBuilder();
- for (final Manager manager : managers) {
- if (topics.length() > 0) {
- topics.append(", ");
- }
- topics.append(manager.getTopic());
- }
- topics.insert(0, "I have help on the following topics: \n");
- topics.append(".\n");
- topics.append("Use help <topic> (without <>) to learn more on a specific topic.");
- answer(topics.toString());
- }
-
- ///** {@inheritDoc} */
- //public String[] getPermissions() {
- // return permissions;
- //}
-
- /**
- * What's new.
- */
- private void whatsNew() {
- try {
- final BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream("news.txt")));
- try {
- final StringBuilder sb = new StringBuilder();
- for (String line; (line = in.readLine()) != null; sb.append(line).append('\n')) {
- ;
- }
- answer(sb.toString());
- } finally {
- in.close();
- }
- } catch (final IOException e) {
- answer("No news available.");
- }
- }
-
- { // IO Modules
- new IOModule() {
- @Override public void save() {
- for (final Manager manager : managers) {
- if (manager != InternalManager.this) {
- try {
- manager.save();
- } catch (final Exception e) {
- System.err.println("Error while saving data from module " + manager.getTopic() + ": " + e);
- e.printStackTrace();
- }
- }
- }
- }
-
- @Override public void load() {
- for (final Manager manager : managers) {
- if (manager != InternalManager.this) {
- try {
- manager.load();
- } catch (final Exception e) {
- System.err.println("Error while loading data for module " + manager.getTopic() + ": " + e);
- e.printStackTrace();
- }
- }
- }
- }
- };
- }
- } // class InternalManager
-
-} // class CherBot
Deleted: trunk/src/net/sf/cherbot/CherBotException.java
===================================================================
--- trunk/src/net/sf/cherbot/CherBotException.java 2007-06-08 19:41:29 UTC (rev 45)
+++ trunk/src/net/sf/cherbot/CherBotException.java 2007-06-09 14:02:47 UTC (rev 46)
@@ -1,25 +0,0 @@
-/*
- * Copyright © 2006, Christian Hujer and the CherBot developers. All Rights Reserved.
- * License: GNU General Public License v2.0 or newer.
- * See file COPYING in the root directory of this project.
- */
-
-package net.sf.cherbot;
-
-/**
- * Base Exception for exteptions that could occur when using players.
- * These exceptions are runtime exceptions thrown if actors use illegal arguments or commands in a wrong state.
- * The message of such an exception must be a message meaningful to the end user (bot user).
- * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
- */
-public class CherBotException extends RuntimeException {
-
- /**
- * Create a CherBotException.
- * @param msg Message (displayed to end user)
- */
- public CherBotException(final String msg) {
- super(msg);
- }
-
-} // class CherBotException
Deleted: trunk/src/net/sf/cherbot/CherBotLogger.java
===================================================================
--- trunk/src/net/sf/cherbot/CherBotLogger.java 2007-06-08 19:41:29 UTC (rev 45)
+++ trunk/src/net/sf/cherbot/CherBotLogger.java 2007-06-09 14:02:47 UTC (rev 46)
@@ -1,90 +0,0 @@
-/*
- * Copyright © 2006, Christian Hujer and the CherBot developers. All Rights Reserved.
- * License: GNU General Public License v2.0 or newer.
- * See file COPYING in the root directory of this project.
- */
-
-package net.sf.cherbot;
-
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.PrintWriter;
-
-/**
- * This class is used for logging within Cherbot.
- * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
- */
-public class CherBotLogger {
-
- /**
- * The logger.
- */
- private PrintWriter log;
-
- /**
- * Create a logger.
- * @throws IOException in case of I/O problems during logger creation.
- */
- @SuppressWarnings({ "IOResourceOpenedButNotSafelyClosed" })
- public CherBotLogger() throws IOException {
- log = new PrintWriter(new FileWriter("log.txt", true));
- }
-
- /**
- * Log something said.
- * @param who Who said it
- * @param msg What he said
- */
- public void say(final String who, final String msg) {
- log.append("[say] ").append(who).append(": ").append(msg).println();
- }
-
- /**
- * Log something told.
- * @param who Who told it
- * @param msg What he told
- */
- public void tell(final String who, final String msg) {
- log.append("[tell] ").append(who).append(": ").append(msg).println();
- }
-
- /**
- * Log something shouted.
- * @param who Who shouted it
- * @param msg What he shouted
- */
- public void shout(final String who, final String msg) {
- log.append("[shout] ").append(who).append(": ").append(msg).println();
- }
-
- /**
- * Log a successful command.
- * @param who Who invoked it
- * @param msg Message that triggered command
- * @param cmd Command
- */
- public void command(final String who, final String msg, final Manager.Command cmd) {
- log.append("[cmd] ").append("[").append(cmd.getManager().getTopic()).append("]").append(who).append(": ").append(msg).println();
- }
-
- /**
- * Log an unsuccessful command.
- * @param who Who invoked it
- * @param msg Message that triggered command
- * @param cmd Command
- * @param ex Exception that made the command fail
- */
- public void fail(final String who, final String msg, final Manager.Command cmd, final Exception ex) {
- log.append("[fail] ").append("[").append(cmd.getManager().getTopic()).append("]").append(who).append(": ").append(msg).append("!").append(ex.toString()).println();
- }
-
- /**
- * Log that a command wasn't found.
- * @param who Who tried to command
- * @param msg Message that didn't trigger a command
- */
- public void noCommand(final String who, final String msg) {
- log.append("[nocmd] ").append(who).append(": ").append(msg).println();
- }
-
-} // class CherBotLogger
Deleted: trunk/src/net/sf/cherbot/CherBotPermission.java
===================================================================
--- trunk/src/net/sf/cherbot/CherBotPermission.java 2007-06-08 19:41:29 UTC (rev 45)
+++ trunk/src/net/sf/cherbot/CherBotPermission.java 2007-06-09 14:02:47 UTC (rev 46)
@@ -1,30 +0,0 @@
-/*
- * Copyright © 2006, Christian Hujer and the CherBot developers. All Rights Reserved.
- * License: GNU General Public License v2.0 or newer.
- * See file COPYING in the root directory of this project.
- */
-
-package net.sf.cherbot;
-
-import java.security.BasicPermission;
-
-/**
- * Permissions to access the CherBot.
- * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
- */
-public class CherBotPermission extends BasicPermission {
-
- /**
- * Serial Version.
- */
- private static final long serialVersionUID = 1L;
-
- /**
- * Create a CherBotPermission.
- * @param name name
- */
- public CherBotPermission(final String name) {
- super(name);
- }
-
-} // class CherBotPermission
Deleted: trunk/src/net/sf/cherbot/CherBotSecurityManager.java
===================================================================
--- trunk/src/net/sf/cherbot/CherBotSecurityManager.java 2007-06-08 19:41:29 UTC (rev 45)
+++ trunk/src/net/sf/cherbot/CherBotSecurityManager.java 2007-06-09 14:02:47 UTC (rev 46)
@@ -1,310 +0,0 @@
-/*
- * Copyright © 2006, Christian Hujer and the CherBot developers. All Rights Reserved.
- * License: GNU General Public License v2.0 or newer.
- * See file COPYING in the root directory of this project.
- */
-
-package net.sf.cherbot;
-
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.security.AllPermission;
-import java.security.Permission;
-import java.security.Permissions;
-import java.util.Comparator;
-import java.util.Enumeration;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.SortedSet;
-import java.util.TreeSet;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-
-/**
- * SecurityManager for CherBot.
- * The CherBotSecurityManager manages the permissions granted for the individual modules and actions.
- * @author <a href="mailto:ch...@ri...">Christian Hujer</a>
- */
-@Manager.Description("Cherbot has a sophisticated security system, derived from Java. It is comparable with JAAS, the security concept used in Java application servers. This module controls security.")
-@Manager.Features({ "Grant permissions", "Revoke permissions", "List permissions" })
-public class CherBotSecurityManager extends Manager {
-
- /**
- * Permission to grant permissions.
- */
- private static final String PERM_GRANT = "Security.Grant";
-
- /**
- * Permission to revoke permissions.
- */
- private static final String PERM_REVOKE = "Security.Revoke";
-
- /**
- * Permission to list own permissions.
- */
- private static final String PERM_LIST_OWN = "Security.List.Own";
-
- /**
- * Permission to list other player's permissions.
- */
- private static final String PERM_LIST_OTHER = "Security.List";
-
- /**
- * The Permissions.
- * Key: player name.
- * Value: Set with permission names.
- */
- private Map<String, Permissions> permissions = new HashMap<String, Permissions>();
-
- /**
- * NullStringComparator.
- */
- private Comparator<String> nullStringComparator = new Comparator<String>() {
- public int compare(final String o1, final String o2) {
- if (o1 == null && o2 == null) {
- return 0;
- } else if (o1 == null) {
- return -1;
- } else if (o2 == null) {
- return 1;
- } else {
- return o1.compareTo(o2);
- }
- }
- };
-
- { // Commands
- /* Grant command. */
- new Command("(?:grant|allow) $PLAYER(?: access| permission)?(?: to| on)? (.*?)[.!]?") {
- @Description("Grants someone the permission to do something.")
- @Examples({ "Grant Michtoen permission on *.", "Allow Michtoen access to *.", "Allow Tehrtapimp to Greetings.Set.Own." })
- @Override public void performImpl() {
- grant(player(1), gr(2));
- }
- };
-
- /* Revoke command. */
- new Command("(?:deny|revoke) $PLAYER(?:'s?)?(?: access| permission)?(?: to| on)? (.*?)[.!]?") {
- @Description("Revokes someone's permission to do something.")
- @Examples({ "Deny Tehrtapimp to Greetings.Set.Own." })
- @Override public void performImpl() {
- revoke(player(1), gr(2));
- }
- };
-
- /* List command. */
- new Command("(?:$LIST|what (?:are|r)) my permissions[.!?]?") {
- @Description("Shows what permissions you have.")
- @Examples({ "What are my permissions?", "Show me my permissions." })
- @Override public void performImpl() {
- list(getCherBot().getActor());
- }
- };
-
- /* List command. */
- new Command("(?:$LIST|what (?:are|r)) $PLAYER(?:'s?)? permissions[.!?]?") {
- @Description("Lists somebody else's permissions.")
- @Examples({ "List Michtoen's permissions." })
- @Override public void performImpl() {
- list(player(1));
- }
- };
-
- /* List command. */
- new Command("$LIST permissions[.!]?") {
- @Description("Lists all permissoins.")
- @Examples({ "List permissions." })
- @Override public void performImpl() {
- final SortedSet<String> players = new TreeSet<String>(nullStringComparator);
- players.addAll(permissions.keySet());
- for (final String player : players) {
- list(player);
- }
- }
- };
- } // Commands
-
- /**
- * Create the SecurityManager.
- * @param cherBot reference to CherBot instance.
- */
- public CherBotSecurityManager(final CherBot cherBot) {
- super(cherBot, "security");
- final Permissions pm = new Permissions();
- pm.add(new AllPermission());
- }
-
- /**
- * Get the String to add to a grant / revoke permission for checking.
- * @param permission permission to get String from
- * @return part
- */
- private static String getPart(final String permission) {
- final Pattern p = Pattern.compile("(\\.+)\\."); // intentionally greedy
- final Matcher m = p.matcher(permission);
- return m.matches() ? '.' + m.group(1) : "";
- }
-
- /**
- * Grant permission to someone on something.
- * @param player to whome are permissions granted
- * @param permission Permission to grant
- */
- private void grant(final String player, final String permission) {
- checkPermission(PERM_GRANT + getPart(permission));
- Permissions perms = permissions.get(player);
- if (perms == null) {
- perms = new Permissions();
- permissions.put(player, perms);
- }
- perms.add(new CherBotPermission(permission));
- answer("Granted " + permission + "-permission to " + player);
- tell(player, getActor() + " granted you " + permission + "-permission.");
- }
-
- /**
- * Revoke permission to someoneon something.
- * @param player whose permissions are to be revoked
- * @param permission Permissions to revoke
- */
- private void revoke(final String player, final String permission) {
- checkPermission(PERM_REVOKE + getPart(permission));
- answer("Revoked " + permission + "-permission for " + player);
- tell(player, getActor() + " revoked your " + permission + "-permission.");
- }
-
- /**
- * List permissons.
- * @param player whose permissions to list
- */
- private void list(final String player) {
- final boolean own = player != null && player.equals(getActor());
- checkPermission(own ? PERM_LIST_OWN : PERM_LIST_OTHER);
- final Permissions perms = permissions.get(player);
- if (perms == null) {
- answer((own ? "You do" : player + " does") + " not have any permissions.");
- } else {
- final StringBuilder sb = new StringBuilder();
- for (Enumeration<Permission> enu = perms.elements(); enu.hasMoreElements();) {
- sb.append(sb.length() > 0 ? ", " : (own ? "Your" : player + "'s") + " permissions: ");
- sb.append(enu.nextElement().getName());
- }
- sb.append('.');
- answer(sb.toString());
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override public void help() {
- answer("The Security engine controls access on the different bot functions that I have. If you're unsure about wether to first write the permissions or first write the player in a command, first write the player, th...
[truncated message content] |