diff --git a/.gitmodules b/.gitmodules index 21f1589..4652f1b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,3 @@ -[submodule "data"] - path = data - url = https://github.com/mosstest/mosstest-game-default.git +[submodule "data"] + path = data + url = https://github.com/mosstest/mosstest-game-default.git diff --git a/buildcfg/assembly-client.xml b/buildcfg/assembly-client.xml index bd22fb8..a4b922b 100644 --- a/buildcfg/assembly-client.xml +++ b/buildcfg/assembly-client.xml @@ -1,37 +1,37 @@ - - exe - - jar - - false - - - - ${artifactId}-${version}${dashClassifier?}-client.${extension} - - true - runtime - - commons-lang:commons-lang - org.apache.commons:commons-lang3 - commons-collections:commons-collections - org.fusesource.leveldbjni:leveldbjni - org.lwjgl.lwjgl:lwjgl - net.java.jinput:jinput - jme3:jme3-desktop - jme3:jme3-lwjgl - jme3:jme3-lwjgl-natives - jme3:jme3-lwjgl-niftygui - jme3:niftygui - commons-cli:commons-cli - commons-configuration:commons-configuration - - - - - - target/classes/ - - - + + exe + + jar + + false + + + + ${artifactId}-${version}${dashClassifier?}-client.${extension} + + true + runtime + + commons-lang:commons-lang + org.apache.commons:commons-lang3 + commons-collections:commons-collections + org.fusesource.leveldbjni:leveldbjni + org.lwjgl.lwjgl:lwjgl + net.java.jinput:jinput + jme3:jme3-desktop + jme3:jme3-lwjgl + jme3:jme3-lwjgl-natives + jme3:jme3-lwjgl-niftygui + jme3:niftygui + commons-cli:commons-cli + commons-configuration:commons-configuration + + + + + + target/classes/ + + + \ No newline at end of file diff --git a/buildcfg/assembly-server.xml b/buildcfg/assembly-server.xml index 3f09f09..7c077f5 100644 --- a/buildcfg/assembly-server.xml +++ b/buildcfg/assembly-server.xml @@ -1,38 +1,38 @@ - - serverexe - - jar - - false - - - - ${artifactId}-${version}${dashClassifier?}-server.${extension} - - true - runtime - - commons-lang:commons-lang - org.apache.commons:commons-lang3 - commons-collections:commons-collections - org.fusesource.leveldbjni:leveldbjni - commons-cli:commons-cli - commons-configuration:commons-configuration - - - - - - target/classes/net/mosstest/servercore - net/mosstest/servercore - - - target/classes/net/mosstest/scripting - net/mosstest/scripting - - - target/classes/net/mosstest/sandbox - net/mosstest/sandbox - - + + serverexe + + jar + + false + + + + ${artifactId}-${version}${dashClassifier?}-server.${extension} + + true + runtime + + commons-lang:commons-lang + org.apache.commons:commons-lang3 + commons-collections:commons-collections + org.fusesource.leveldbjni:leveldbjni + commons-cli:commons-cli + commons-configuration:commons-configuration + + + + + + target/classes/net/mosstest/servercore + net/mosstest/servercore + + + target/classes/net/mosstest/scripting + net/mosstest/scripting + + + target/classes/net/mosstest/sandbox + net/mosstest/sandbox + + \ No newline at end of file diff --git a/devscripts/javaproperties-to-gettext.sh b/devscripts/javaproperties-to-gettext.sh index 8dc39e6..e4c3388 100644 --- a/devscripts/javaproperties-to-gettext.sh +++ b/devscripts/javaproperties-to-gettext.sh @@ -1,7 +1,7 @@ -cd .. -mkdir -p translate/servercore -mkdir -p translate/scripting -mkdir -p translate/launcher -msgcat -P src/net/mosstest/servercore/messages.properties -o translate/servercore/servercore.pot -msgcat -P src/net/mosstest/scripting/messages.properties -o translate/scripting/scripting.pot -msgcat -P src/net/mosstest/launcher/messages.properties -o translate/launcher/launcher.pot +cd .. +mkdir -p translate/servercore +mkdir -p translate/scripting +mkdir -p translate/launcher +msgcat -P src/net/mosstest/servercore/messages.properties -o translate/servercore/servercore.pot +msgcat -P src/net/mosstest/scripting/messages.properties -o translate/scripting/scripting.pot +msgcat -P src/net/mosstest/launcher/messages.properties -o translate/launcher/launcher.pot diff --git a/notes/performance notes.txt b/notes/performance notes.txt index 8477475..4ab8452 100644 --- a/notes/performance notes.txt +++ b/notes/performance notes.txt @@ -1,2 +1,2 @@ -20:04:00 lag is caused by minetest being very stupid. change 1 node - full 16x16x16 mapblock must be send. and blinky/mesecon/klots of other stuff is actually replacing nodes. also these changes are atacking on server. use drill in 10 places in 1 mapblock - server will send and confirm at least 10 updates to mapblock and inventory - which is idiotic. instead iyt should check that previous update is not sent yet and skip all in middle - sending on -19:59:04 textures on server are small already. and liong time is caused by server sending them one-by-one, each needing confirmation. do smaller texture data will stiull need lots of control traffic. this is minetest fault (unless i am very wrong) +20:04:00 lag is caused by minetest being very stupid. change 1 node - full 16x16x16 mapblock must be send. and blinky/mesecon/klots of other stuff is actually replacing nodes. also these changes are atacking on server. use drill in 10 places in 1 mapblock - server will send and confirm at least 10 updates to mapblock and inventory - which is idiotic. instead iyt should check that previous update is not sent yet and skip all in middle - sending on +19:59:04 textures on server are small already. and liong time is caused by server sending them one-by-one, each needing confirmation. do smaller texture data will stiull need lots of control traffic. this is minetest fault (unless i am very wrong) diff --git a/pom.xml b/pom.xml index 4407482..4c5821a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,336 +1,336 @@ - - 4.0.0 - mosstest - mosstest - 0.1.0-SNAPSHOT - Mosstest - Open-source voxel engine with some extra features - - - - false - - central - Central Repository - http://repo.maven.apache.org/maven2 - - - moss-forums - http://forum-mosstest.rhcloud.com/repository/ - - - - tests - src - - - src - - **/*.java - - - - - - maven-compiler-plugin - 3.1 - - 1.7 - 1.7 - - - - pl.project13.maven - git-commit-id-plugin - 2.1.7 - - - - revision - - - - - - git - yyyy.MM.dd '@' HH:mm:ss z - true - ${project.basedir}/.git - - true - true - src/git.properties - false - - false - false - 7 - -dirty - false - - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 1.4 - - - - - package - - shade - - - - - - bouncycastle:bcprov-jdk15 - - - - - - *:* - - META-INF/*.SF - META-INF/*.DSA - META-INF/*.RSA - - - - - - - - net.mosstest.servercore.MossWorld - - - - properties.properties - - - applicationContext.xml - - - META-INF/cxf/cxf.extension - - - META-INF/cxf/bus-extensions.xml - - - - - - - - - - - https://github.com/mosstest/mosstest - - Launchpad - https://bugs.launchpad.net/mosstest - - - Travis-CI - - - - - - org.apache.commons - commons-math - 2.2 - - - commons-lang - commons-lang - 2.6 - - - org.apache.commons - commons-lang3 - 3.1 - - - commons-collections - commons-collections - 3.2.1 - - - net.java.jinput - jinput - 2.0.5 - - - jme3 - jme3-desktop - 3.1.0 - - - jme3 - jme3-lwjgl - 3.1.0 - - - jme3 - jme3-lwjgl-natives - 3.1.0 - - - jme3 - jme3-lwjgl-niftygui - 3.1.0 - - - jme3 - niftygui - 3.1.0 - - - com.google.guava - guava - 15.0 - - - - commons-cli - commons-cli - 1.2 - - - commons-configuration - commons-configuration - 1.9 - - - rhino - js - 1.7R2 - - - jme3 - jme3-core - 1.3.0 - - - org.fusesource.leveldbjni - leveldbjni-all - 1.7 - - - org.lwjgl.lwjgl - parent - 2.9.0 - pom - - - jme3 - lwjgl-workaround - 9.5.1 - - - junit - junit - 4.8.1 - test - - - log4j - log4j - 1.2.15 - - - javax.mail - mail - - - javax.jms - jms - - - com.sun.jdmk - jmxtools - - - com.sun.jmx - jmxri - - - - - - commons-io - commons-io - 2.4 - - - - + + 4.0.0 + mosstest + mosstest + 0.1.0-SNAPSHOT + Mosstest + Open-source voxel engine with some extra features + + + + false + + central + Central Repository + http://repo.maven.apache.org/maven2 + + + moss-forums + http://forum-mosstest.rhcloud.com/repository/ + + + + tests + src + + + src + + **/*.java + + + + + + maven-compiler-plugin + 3.1 + + 1.7 + 1.7 + + + + pl.project13.maven + git-commit-id-plugin + 2.1.7 + + + + revision + + + + + + git + yyyy.MM.dd '@' HH:mm:ss z + true + ${project.basedir}/.git + + true + true + src/git.properties + false + + false + false + 7 + -dirty + false + + + + + + + + org.apache.maven.plugins + maven-shade-plugin + 1.4 + + + + + package + + shade + + + + + + bouncycastle:bcprov-jdk15 + + + + + + *:* + + META-INF/*.SF + META-INF/*.DSA + META-INF/*.RSA + + + + + + + + net.mosstest.servercore.MossWorld + + + + properties.properties + + + applicationContext.xml + + + META-INF/cxf/cxf.extension + + + META-INF/cxf/bus-extensions.xml + + + + + + + + + + + https://github.com/mosstest/mosstest + + Launchpad + https://bugs.launchpad.net/mosstest + + + Travis-CI + + + + + + org.apache.commons + commons-math + 2.2 + + + commons-lang + commons-lang + 2.6 + + + org.apache.commons + commons-lang3 + 3.1 + + + commons-collections + commons-collections + 3.2.1 + + + net.java.jinput + jinput + 2.0.5 + + + jme3 + jme3-desktop + 3.1.0 + + + jme3 + jme3-lwjgl + 3.1.0 + + + jme3 + jme3-lwjgl-natives + 3.1.0 + + + jme3 + jme3-lwjgl-niftygui + 3.1.0 + + + jme3 + niftygui + 3.1.0 + + + com.google.guava + guava + 15.0 + + + + commons-cli + commons-cli + 1.2 + + + commons-configuration + commons-configuration + 1.9 + + + rhino + js + 1.7R2 + + + jme3 + jme3-core + 1.3.0 + + + org.fusesource.leveldbjni + leveldbjni-all + 1.7 + + + org.lwjgl.lwjgl + parent + 2.9.0 + pom + + + jme3 + lwjgl-workaround + 9.5.1 + + + junit + junit + 4.8.1 + test + + + log4j + log4j + 1.2.15 + + + javax.mail + mail + + + javax.jms + jms + + + com.sun.jdmk + jmxtools + + + com.sun.jmx + jmxri + + + + + + commons-io + commons-io + 2.4 + + + + diff --git a/src/log4j.properties b/src/log4j.properties index 9bf1337..eeed9af 100644 --- a/src/log4j.properties +++ b/src/log4j.properties @@ -1,14 +1,14 @@ -# Root logger option -log4j.rootLogger=DEBUG, file, stdout - -# Direct log messages to a log file -log4j.appender.file=org.apache.log4j.FileAppender -log4j.appender.file.File=mosslog.log -log4j.appender.file.layout=org.apache.log4j.PatternLayout -log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %r %-5p %c{1} - %m%n - -# Direct log messages to stdout -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +# Root logger option +log4j.rootLogger=DEBUG, file, stdout + +# Direct log messages to a log file +log4j.appender.file=org.apache.log4j.FileAppender +log4j.appender.file.File=mosslog.log +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %r %-5p %c{1} - %m%n + +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %r %-5p %c{1} - %m%n \ No newline at end of file diff --git a/src/net/mosstest/launcher/GUIBugReportDialog.java b/src/net/mosstest/launcher/GUIBugReportDialog.java index a9fca9d..fc60557 100644 --- a/src/net/mosstest/launcher/GUIBugReportDialog.java +++ b/src/net/mosstest/launcher/GUIBugReportDialog.java @@ -1,201 +1,201 @@ -package net.mosstest.launcher; - -import javax.swing.*; -import javax.swing.border.EmptyBorder; -import java.awt.*; - -// TODO: Auto-generated Javadoc - -/** - * The Class GUIBugReportDialog. - */ -public class GUIBugReportDialog extends JDialog { - - /** - * The content panel. - */ - private final JPanel contentPanel = new JPanel(); - - /** - * The reporter name. - */ - private JTextField reporterName; - - /** - * The email. - */ - private JTextField email; - - /** - * The problem summary. - */ - private JTextField problemSummary; - - /** - * The chckbx include technical information. - */ - private JCheckBox chckbxIncludeTechnicalInformation; - - /** - * The lbl name. - */ - private JLabel lblName; - - /** - * Launch the application. - * - * @param args the arguments - */ - public static void main(String[] args) { - GUIBugReportDialog dialog = new GUIBugReportDialog("test traceback"); - dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - dialog.setVisible(true); - - } - - /** - * Create the dialog. - * - * @param traceback the traceback - */ - public GUIBugReportDialog(String traceback) { - setModal(true); - setModalityType(ModalityType.APPLICATION_MODAL); - setMinimumSize(new Dimension(640, 480)); - setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - setTitle(Messages.getString("GUIBugReportDialog.DLG_BUG_TITLE")); //$NON-NLS-1$ - setBounds(100, 100, 640, 480); - getContentPane().setLayout(new BorderLayout()); - contentPanel.setAlignmentX(Component.LEFT_ALIGNMENT); - this.contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); - getContentPane().add(this.contentPanel, BorderLayout.CENTER); - contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS)); - { - JPanel namePanel = new JPanel(); - namePanel.setMaximumSize(new Dimension(32767, 20)); - contentPanel.add(namePanel); - namePanel.setLayout(new BorderLayout(0, 0)); - - { - lblName = new JLabel(Messages.getString("GUIBugReportDialog.DLG_BUG_NAME")); //$NON-NLS-1$ - namePanel.add(lblName, BorderLayout.WEST); - lblName.setHorizontalTextPosition(SwingConstants.LEFT); - lblName.setHorizontalAlignment(SwingConstants.LEFT); - lblName.setAlignmentY(Component.TOP_ALIGNMENT); - } - lblName.setLabelFor(reporterName); - { - this.reporterName = new JTextField(); - namePanel.add(reporterName, BorderLayout.CENTER); - reporterName.setMaximumSize(new Dimension(2147483647, 20)); - reporterName.setAlignmentY(Component.TOP_ALIGNMENT); - this.reporterName.setColumns(10); - } - } - { - JPanel emailPanel = new JPanel(); - emailPanel.setMaximumSize(new Dimension(32767, 20)); - contentPanel.add(emailPanel); - emailPanel.setLayout(new BorderLayout(0, 0)); - { - JLabel lblEmailoptional = new JLabel(Messages.getString("GUIBugReportDialog.DLG_BUG_EMAIL")); //$NON-NLS-1$ - emailPanel.add(lblEmailoptional, BorderLayout.WEST); - } - { - this.email = new JTextField(); - emailPanel.add(email, BorderLayout.CENTER); - email.setMaximumSize(new Dimension(2147483647, 20)); - this.email.setColumns(10); - } - } - { - JPanel summaryPnl = new JPanel(); - summaryPnl.setMaximumSize(new Dimension(32767, 20)); - contentPanel.add(summaryPnl); - summaryPnl.setLayout(new BorderLayout(0, 0)); - { - JLabel lblProblemDescription = new JLabel(Messages.getString("GUIBugReportDialog.DLG_BUG_SUMMARY")); //$NON-NLS-1$ - summaryPnl.add(lblProblemDescription, BorderLayout.WEST); - } - { - this.problemSummary = new JTextField(); - summaryPnl.add(problemSummary, BorderLayout.CENTER); - this.problemSummary.setColumns(10); - } - } - { - JPanel descPanel = new JPanel(); - descPanel.setMinimumSize(new Dimension(80, 150)); - contentPanel.add(descPanel); - descPanel.setLayout(new BorderLayout(0, 0)); - { - JLabel lblDetailedProblemDescription = new JLabel( - Messages.getString("GUIBugReportDialog.DLG_BUG_DESC")); //$NON-NLS-1$ - lblDetailedProblemDescription.setVerticalAlignment(SwingConstants.TOP); - descPanel.add(lblDetailedProblemDescription, BorderLayout.WEST); - } - { - JScrollPane scrollPane = new JScrollPane(); - descPanel.add(scrollPane, BorderLayout.CENTER); - { - JTextArea txtLongDesc = new JTextArea(); - scrollPane.setViewportView(txtLongDesc); - txtLongDesc.setWrapStyleWord(true); - txtLongDesc.setLineWrap(true); - txtLongDesc - .setText(Messages.getString("GUIBugReportDialog.DLG_BUG_DESC_DEFAULT")); //$NON-NLS-1$ - } - } - } - { - JPanel techInfoPanel = new JPanel(); - contentPanel.add(techInfoPanel); - techInfoPanel.setLayout(new BorderLayout(0, 0)); - { - chckbxIncludeTechnicalInformation = new JCheckBox( - Messages.getString("GUIBugReportDialog.DLG_CHECKBOX_INCLUDE_TECH_INFO")); //$NON-NLS-1$ - techInfoPanel.add(chckbxIncludeTechnicalInformation, BorderLayout.WEST); - chckbxIncludeTechnicalInformation.setLocation(new Point(2, 0)); - chckbxIncludeTechnicalInformation.setVerticalAlignment(SwingConstants.TOP); - chckbxIncludeTechnicalInformation.setHorizontalTextPosition(SwingConstants.LEFT); - chckbxIncludeTechnicalInformation.setAlignmentX(Component.CENTER_ALIGNMENT); - chckbxIncludeTechnicalInformation.setHorizontalAlignment(SwingConstants.LEFT); - } - { - JScrollPane scrollPane = new JScrollPane(); - techInfoPanel.add(scrollPane, BorderLayout.CENTER); - { - JTextArea textArea = new JTextArea(); - scrollPane.setViewportView(textArea); - textArea.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); - textArea.setBackground(new Color(204, 204, 204)); - textArea.setEditable(false); - textArea.setWrapStyleWord(true); - textArea.setLineWrap(true); - textArea.setText(Messages.getString("GUIBugReportDialog.NOTICE_INFO_INCLUDED") + traceback); //$NON-NLS-1$ - } - } - } - { - JPanel buttonPane = new JPanel(); - getContentPane().add(buttonPane, BorderLayout.SOUTH); - buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS)); - { - JProgressBar progressBar = new JProgressBar(); - buttonPane.add(progressBar); - } - { - JButton okButton = new JButton(Messages.getString("GUIBugReportDialog.DLG_SUBMIT")); //$NON-NLS-1$ - buttonPane.add(okButton); - okButton.setActionCommand(Messages.getString("GUIBugReportDialog.DLG_OK")); //$NON-NLS-1$ - getRootPane().setDefaultButton(okButton); - } - { - JButton cancelButton = new JButton(Messages.getString("GUIBugReportDialog.DLG_CXL")); //$NON-NLS-1$ - buttonPane.add(cancelButton); - cancelButton.setActionCommand(Messages.getString("GUIBugReportDialog.DLG_CXL")); //$NON-NLS-1$ - } - } - } - -} +package net.mosstest.launcher; + +import javax.swing.*; +import javax.swing.border.EmptyBorder; +import java.awt.*; + +// TODO: Auto-generated Javadoc + +/** + * The Class GUIBugReportDialog. + */ +public class GUIBugReportDialog extends JDialog { + + /** + * The content panel. + */ + private final JPanel contentPanel = new JPanel(); + + /** + * The reporter name. + */ + private JTextField reporterName; + + /** + * The email. + */ + private JTextField email; + + /** + * The problem summary. + */ + private JTextField problemSummary; + + /** + * The chckbx include technical information. + */ + private JCheckBox chckbxIncludeTechnicalInformation; + + /** + * The lbl name. + */ + private JLabel lblName; + + /** + * Launch the application. + * + * @param args the arguments + */ + public static void main(String[] args) { + GUIBugReportDialog dialog = new GUIBugReportDialog("test traceback"); + dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + dialog.setVisible(true); + + } + + /** + * Create the dialog. + * + * @param traceback the traceback + */ + public GUIBugReportDialog(String traceback) { + setModal(true); + setModalityType(ModalityType.APPLICATION_MODAL); + setMinimumSize(new Dimension(640, 480)); + setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + setTitle(Messages.getString("GUIBugReportDialog.DLG_BUG_TITLE")); //$NON-NLS-1$ + setBounds(100, 100, 640, 480); + getContentPane().setLayout(new BorderLayout()); + contentPanel.setAlignmentX(Component.LEFT_ALIGNMENT); + this.contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); + getContentPane().add(this.contentPanel, BorderLayout.CENTER); + contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.Y_AXIS)); + { + JPanel namePanel = new JPanel(); + namePanel.setMaximumSize(new Dimension(32767, 20)); + contentPanel.add(namePanel); + namePanel.setLayout(new BorderLayout(0, 0)); + + { + lblName = new JLabel(Messages.getString("GUIBugReportDialog.DLG_BUG_NAME")); //$NON-NLS-1$ + namePanel.add(lblName, BorderLayout.WEST); + lblName.setHorizontalTextPosition(SwingConstants.LEFT); + lblName.setHorizontalAlignment(SwingConstants.LEFT); + lblName.setAlignmentY(Component.TOP_ALIGNMENT); + } + lblName.setLabelFor(reporterName); + { + this.reporterName = new JTextField(); + namePanel.add(reporterName, BorderLayout.CENTER); + reporterName.setMaximumSize(new Dimension(2147483647, 20)); + reporterName.setAlignmentY(Component.TOP_ALIGNMENT); + this.reporterName.setColumns(10); + } + } + { + JPanel emailPanel = new JPanel(); + emailPanel.setMaximumSize(new Dimension(32767, 20)); + contentPanel.add(emailPanel); + emailPanel.setLayout(new BorderLayout(0, 0)); + { + JLabel lblEmailoptional = new JLabel(Messages.getString("GUIBugReportDialog.DLG_BUG_EMAIL")); //$NON-NLS-1$ + emailPanel.add(lblEmailoptional, BorderLayout.WEST); + } + { + this.email = new JTextField(); + emailPanel.add(email, BorderLayout.CENTER); + email.setMaximumSize(new Dimension(2147483647, 20)); + this.email.setColumns(10); + } + } + { + JPanel summaryPnl = new JPanel(); + summaryPnl.setMaximumSize(new Dimension(32767, 20)); + contentPanel.add(summaryPnl); + summaryPnl.setLayout(new BorderLayout(0, 0)); + { + JLabel lblProblemDescription = new JLabel(Messages.getString("GUIBugReportDialog.DLG_BUG_SUMMARY")); //$NON-NLS-1$ + summaryPnl.add(lblProblemDescription, BorderLayout.WEST); + } + { + this.problemSummary = new JTextField(); + summaryPnl.add(problemSummary, BorderLayout.CENTER); + this.problemSummary.setColumns(10); + } + } + { + JPanel descPanel = new JPanel(); + descPanel.setMinimumSize(new Dimension(80, 150)); + contentPanel.add(descPanel); + descPanel.setLayout(new BorderLayout(0, 0)); + { + JLabel lblDetailedProblemDescription = new JLabel( + Messages.getString("GUIBugReportDialog.DLG_BUG_DESC")); //$NON-NLS-1$ + lblDetailedProblemDescription.setVerticalAlignment(SwingConstants.TOP); + descPanel.add(lblDetailedProblemDescription, BorderLayout.WEST); + } + { + JScrollPane scrollPane = new JScrollPane(); + descPanel.add(scrollPane, BorderLayout.CENTER); + { + JTextArea txtLongDesc = new JTextArea(); + scrollPane.setViewportView(txtLongDesc); + txtLongDesc.setWrapStyleWord(true); + txtLongDesc.setLineWrap(true); + txtLongDesc + .setText(Messages.getString("GUIBugReportDialog.DLG_BUG_DESC_DEFAULT")); //$NON-NLS-1$ + } + } + } + { + JPanel techInfoPanel = new JPanel(); + contentPanel.add(techInfoPanel); + techInfoPanel.setLayout(new BorderLayout(0, 0)); + { + chckbxIncludeTechnicalInformation = new JCheckBox( + Messages.getString("GUIBugReportDialog.DLG_CHECKBOX_INCLUDE_TECH_INFO")); //$NON-NLS-1$ + techInfoPanel.add(chckbxIncludeTechnicalInformation, BorderLayout.WEST); + chckbxIncludeTechnicalInformation.setLocation(new Point(2, 0)); + chckbxIncludeTechnicalInformation.setVerticalAlignment(SwingConstants.TOP); + chckbxIncludeTechnicalInformation.setHorizontalTextPosition(SwingConstants.LEFT); + chckbxIncludeTechnicalInformation.setAlignmentX(Component.CENTER_ALIGNMENT); + chckbxIncludeTechnicalInformation.setHorizontalAlignment(SwingConstants.LEFT); + } + { + JScrollPane scrollPane = new JScrollPane(); + techInfoPanel.add(scrollPane, BorderLayout.CENTER); + { + JTextArea textArea = new JTextArea(); + scrollPane.setViewportView(textArea); + textArea.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); + textArea.setBackground(new Color(204, 204, 204)); + textArea.setEditable(false); + textArea.setWrapStyleWord(true); + textArea.setLineWrap(true); + textArea.setText(Messages.getString("GUIBugReportDialog.NOTICE_INFO_INCLUDED") + traceback); //$NON-NLS-1$ + } + } + } + { + JPanel buttonPane = new JPanel(); + getContentPane().add(buttonPane, BorderLayout.SOUTH); + buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.X_AXIS)); + { + JProgressBar progressBar = new JProgressBar(); + buttonPane.add(progressBar); + } + { + JButton okButton = new JButton(Messages.getString("GUIBugReportDialog.DLG_SUBMIT")); //$NON-NLS-1$ + buttonPane.add(okButton); + okButton.setActionCommand(Messages.getString("GUIBugReportDialog.DLG_OK")); //$NON-NLS-1$ + getRootPane().setDefaultButton(okButton); + } + { + JButton cancelButton = new JButton(Messages.getString("GUIBugReportDialog.DLG_CXL")); //$NON-NLS-1$ + buttonPane.add(cancelButton); + cancelButton.setActionCommand(Messages.getString("GUIBugReportDialog.DLG_CXL")); //$NON-NLS-1$ + } + } + } + +} diff --git a/src/net/mosstest/launcher/GUIClientsideLauncher.java b/src/net/mosstest/launcher/GUIClientsideLauncher.java index b05672e..d0abb85 100644 --- a/src/net/mosstest/launcher/GUIClientsideLauncher.java +++ b/src/net/mosstest/launcher/GUIClientsideLauncher.java @@ -1,429 +1,429 @@ -package net.mosstest.launcher; - -import net.mosstest.servercore.*; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.log4j.Logger; - -import javax.swing.*; -import javax.swing.table.AbstractTableModel; -import java.awt.*; -import java.awt.Dialog.ModalityType; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.io.IOException; -import java.lang.reflect.InvocationTargetException; -import java.util.ArrayList; - -// TODO: Auto-generated Javadoc - -/** - * The Class GUIClientsideLauncher. - */ -public class GUIClientsideLauncher { - - /** - * The logger. - */ - static Logger logger = Logger.getLogger(GUIClientsideLauncher.class); - - /** - * The mdl. - */ - private SingleplayerListTableModel mdl; - - static { - System.setSecurityManager(MosstestSecurityManager.instance); - } - - /** - * The Class SingleplayerListEntry. - */ - public static class SingleplayerListEntry { - - /** - * The name. - */ - public String name; - - /** - * The description. - */ - public String description; - - /** - * The game preset. - */ - public String gamePreset; - - /** - * Instantiates a new singleplayer list entry. - * - * @param name the name - * @param description the description - * @param gamePreset the game preset - */ - public SingleplayerListEntry(String name, String description, - String gamePreset) { - this.name = name; - this.description = description; - this.gamePreset = gamePreset; - } - - } - - /** - * The frm mosstest client launcher. - */ - private JDialog frmMosstestClientLauncher; - - /** - * The table. - */ - private JTable table; - - /** - * Launch the application. - * - * @param args the arguments - * @throws InvocationTargetException the invocation target exception - * @throws InterruptedException the interrupted exception - */ - public static void main(String[] args) throws InvocationTargetException, InterruptedException { - logger.info("Mosstest client starting..."); - try { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - } catch (ClassNotFoundException | InstantiationException - | IllegalAccessException | UnsupportedLookAndFeelException e1) { - logger.warn(Messages - .getString("GUIClientsideLauncher.WARN_SET_LAF")); //$NON-NLS-1$ - } - - EventQueue.invokeAndWait(new Runnable() { - public void run() { - ArrayList entries = new ArrayList<>(); - - GUIClientsideLauncher window = new GUIClientsideLauncher( - entries); - window.frmMosstestClientLauncher.setVisible(true); - - } - }); - } - - /** - * Create the application. - * - * @param singleplayerEntries the singleplayer entries - */ - public GUIClientsideLauncher( - ArrayList singleplayerEntries) { - initialize(singleplayerEntries); - } - - /** - * Initialize the contents of the frame. - * - * @param singleplayerEntries the singleplayer entries - */ - private void initialize(ArrayList singleplayerEntries) { - this.frmMosstestClientLauncher = new JDialog(); - this.frmMosstestClientLauncher.setModal(true); - this.frmMosstestClientLauncher.setModalityType(ModalityType.APPLICATION_MODAL); - this.frmMosstestClientLauncher.setTitle(Messages - .getString("GUIClientsideLauncher.DLG_TITLE")); //$NON-NLS-1$ - this.frmMosstestClientLauncher.setBounds(100, 100, 800, 480); - this.frmMosstestClientLauncher - .setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); - - JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); - this.frmMosstestClientLauncher.getContentPane().add(tabbedPane, - BorderLayout.CENTER); - - JPanel singleplayerTab = new JPanel(); - tabbedPane - .addTab(Messages - .getString("GUIClientsideLauncher.DLG_SINGLEPLAYER"), null, singleplayerTab, null); //$NON-NLS-1$ - singleplayerTab.setLayout(new BorderLayout(0, 0)); - this.table = new JTable(); - this.table.setFillsViewportHeight(true); - this.mdl = new SingleplayerListTableModel(singleplayerEntries); - this.table.setModel(this.mdl); - this.table.getColumnModel().getColumn(0).setPreferredWidth(90); - this.table.getColumnModel().getColumn(1).setPreferredWidth(256); - this.table.getColumnModel().getColumn(2).setPreferredWidth(104); - this.table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - JPanel singleplayerControlBtns = new JPanel(); - singleplayerTab.add(singleplayerControlBtns, BorderLayout.SOUTH); - singleplayerControlBtns.setLayout(new GridLayout(0, 4, 0, 0)); - - JButton btnPlaySingleplayer = new JButton( - Messages.getString("GUIClientsideLauncher.DLG_PLAY")); //$NON-NLS-1$ - btnPlaySingleplayer.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - - int row = GUIClientsideLauncher.this.table.getSelectedRow(); - if (row < 0) { - - logger.warn("An attempt was made to start gameplay without selecting a world."); - JOptionPane.showMessageDialog( - null, - Messages.getString("GUIClientsideLauncher.ERR_NO_WORLD_SELECTED"), //$NON-NLS-1$ - Messages.getString("GUIClientsideLauncher.ERR_NO_WORLD_SELECTED_TITLE"), //$NON-NLS-1$ - JOptionPane.WARNING_MESSAGE); - - return; - } - GUIClientsideLauncher.this.frmMosstestClientLauncher - .setVisible(false); - // below is testing code. in reality this would call a method to - // start a world and block. This should be in a try-catch block - // for the bug reporter to snatch up. - try { - - MossWorld w = new MossWorld((String) GUIClientsideLauncher.this.table.getModel().getValueAt(row, 0), -16511); - } catch (MossWorldLoadException | MapDatabaseException | IOException | ConfigurationException e) { - logger.error("Uncaught exception in game code, opening bug reporter."); - - String fname = MossDebugUtils.writeStracktrace(e); - logger.error("Stracktrace has been written to " + fname); - GUIBugReportDialog bg = new GUIBugReportDialog( - MossDebugUtils.getDebugInformation(e)); - bg.setVisible(true); - } - GUIClientsideLauncher.this.frmMosstestClientLauncher - .setVisible(true); - } - }); - singleplayerControlBtns.add(btnPlaySingleplayer); - - JButton btnNewSingleplayer = new JButton( - Messages.getString("GUIClientsideLauncher.DLG_NEW")); //$NON-NLS-1$ - btnNewSingleplayer.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - GUIWorldCreationDialog dlg = new GUIWorldCreationDialog(); - dlg.setVisible(true); - if (dlg.dlgResult) { - logger.debug("Got world: " - + dlg.nameField.getText() - + " with desc: " - + dlg.inputDesc.getText() - + " with game: " - + dlg.comboBox.getItemAt(dlg.comboBox - .getSelectedIndex())); //$NON-NLS-1$ - - } else - logger.info("World creation cancelled"); - } - }); - - singleplayerControlBtns.add(btnNewSingleplayer); - - JButton btnSettingsSingleplayer = new JButton( - Messages.getString("GUIClientsideLauncher.DLG_SETTINGS")); //$NON-NLS-1$ - singleplayerControlBtns.add(btnSettingsSingleplayer); - - JButton btnDelete = new JButton( - Messages.getString("GUIClientsideLauncher.DLG_DELETE")); //$NON-NLS-1$ - btnDelete.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - int row = GUIClientsideLauncher.this.table.getSelectedRow(); - if (row < 0) { - - logger.warn("An attempt was made to delete a world, but none was selected."); - JOptionPane.showMessageDialog( - null, - Messages.getString("GUIClientsideLauncher.DLG_NO_WORLD_TO_DELETE"), //$NON-NLS-1$ - Messages.getString("GUIClientsideLauncher.ERR_NO_WORLD_SELECTED_TITLE"), //$NON-NLS-1$ - JOptionPane.WARNING_MESSAGE); - - } - - } - }); - singleplayerControlBtns.add(btnDelete); - - // singleplayerTab.add(this.table, BorderLayout.CENTER); - - JScrollPane singleplayerScrollPane = new JScrollPane(this.table); - singleplayerScrollPane - .setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); - singleplayerTab.add(singleplayerScrollPane, BorderLayout.CENTER); - JPanel aboutTab = new JPanel(); - tabbedPane - .addTab(Messages.getString("GUIClientsideLauncher.DLG_ABOUT"), null, aboutTab, null); //$NON-NLS-1$ - tabbedPane.setEnabledAt(1, true); - SpringLayout sl_aboutTab = new SpringLayout(); - aboutTab.setLayout(sl_aboutTab); - - JPanel communityToolsButtonPanel = new JPanel(); - sl_aboutTab.putConstraint(SpringLayout.NORTH, - communityToolsButtonPanel, 405, SpringLayout.NORTH, aboutTab); - sl_aboutTab.putConstraint(SpringLayout.WEST, communityToolsButtonPanel, - 0, SpringLayout.WEST, aboutTab); - sl_aboutTab.putConstraint(SpringLayout.EAST, communityToolsButtonPanel, - 787, SpringLayout.WEST, aboutTab); - aboutTab.add(communityToolsButtonPanel); - communityToolsButtonPanel.setLayout(new GridLayout(0, 5, 0, 0)); - - JButton btnReportBug = new JButton( - Messages.getString("GUIClientsideLauncher.23")); //$NON-NLS-1$ - btnReportBug.setEnabled(false); - communityToolsButtonPanel.add(btnReportBug); - - JButton btnRequestNewFeature = new JButton( - Messages.getString("GUIClientsideLauncher.24")); //$NON-NLS-1$ - btnRequestNewFeature.setEnabled(false); - communityToolsButtonPanel.add(btnRequestNewFeature); - - JButton btnVisitWebsite = new JButton( - Messages.getString("GUIClientsideLauncher.25")); //$NON-NLS-1$ - btnVisitWebsite.setEnabled(false); - communityToolsButtonPanel.add(btnVisitWebsite); - - JButton btnGithubProject = new JButton( - Messages.getString("GUIClientsideLauncher.26")); //$NON-NLS-1$ - btnGithubProject.setEnabled(false); - communityToolsButtonPanel.add(btnGithubProject); - - JButton btnVisitForums = new JButton( - Messages.getString("GUIClientsideLauncher.27")); //$NON-NLS-1$ - btnVisitForums.setEnabled(false); - communityToolsButtonPanel.add(btnVisitForums); - - JTextArea textArea = new JTextArea(); - aboutTab.add(textArea); - textArea.setText(" __ __ ____ _____ _____ _______ ______ _____ _______ \r\n" - + " | \\/ |/ __ \\ / ____/ ____|__ __| ____|/ ____|__ __|\r\n" - + " | \\ / | | | | (___| (___ | | | |__ | (___ | | \r\n" - + " | |\\/| | | | |\\___ \\\\___ \\ | | | __| \\___ \\ | | \r\n" - + " | | | | |__| |____) |___) | | | | |____ ____) | | | \r\n" - + " |_| |_|\\____/|_____/_____/ |_| |______|_____/ |_| \r\n" - + " \r\n" - + " 0.0.1-initial \r\n" - + "" - + Messages - .getString("GUIClientsideLauncher.NOTICE_PRIMARY_AUTHORS") //$NON-NLS-1$ - + Messages - .getString("GUIClientsideLauncher.NOTICE_DEFAULT_GAME_CODE") //$NON-NLS-1$ - + Messages.getString("GUIClientsideLauncher.SYS_NEWLINE") //$NON-NLS-1$ - + Messages.getString("GUIClientsideLauncher.USES_LIBS") //$NON-NLS-1$ - + "* Apache Commons Lang\r\n" - + "* Apache Commons Collections\r\n" - + "* JInput\r\n" - + "* jmonkeyengine/jme3\r\n" - + "* niftygui\r\n" - + "* Google Guava Collections\r\n" - + "* Apache Commons CLI\r\n" - + "* Apache Commons Configuration\r\n" - + "* Mozilla Rhino\r\n" - + "* leveldbjni\r\n" - + "* junit4 for testing\r\n" - + Messages.getString("GUIClientsideLauncher.SYS_NEWLINE") //$NON-NLS-1$ - + Messages.getString("GUIClientsideLauncher.NOTICE_TOOLS_USED")); //$NON-NLS-1$ - textArea.setWrapStyleWord(true); - textArea.setBackground(new Color(192, 192, 192)); - textArea.setEditable(false); - JScrollPane scrollPane = new JScrollPane(textArea); - sl_aboutTab.putConstraint(SpringLayout.NORTH, scrollPane, 0, - SpringLayout.NORTH, aboutTab); - sl_aboutTab.putConstraint(SpringLayout.WEST, scrollPane, 0, - SpringLayout.WEST, aboutTab); - sl_aboutTab.putConstraint(SpringLayout.SOUTH, scrollPane, 0, - SpringLayout.NORTH, communityToolsButtonPanel); - sl_aboutTab.putConstraint(SpringLayout.EAST, scrollPane, 787, - SpringLayout.WEST, aboutTab); - scrollPane - .setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); - scrollPane - .setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); - aboutTab.add(scrollPane); - frmMosstestClientLauncher.setVisible(true); - } - - /** - * The Class SingleplayerListTableModel. - */ - class SingleplayerListTableModel extends AbstractTableModel { - - /** - * The column names. - */ - private String[] columnNames = { - Messages.getString("GUIClientsideLauncher.COL_WORLD_NAME"), Messages.getString("GUIClientsideLauncher.COL_WORLD_DESC"), //$NON-NLS-1$ //$NON-NLS-2$ - Messages.getString("GUIClientsideLauncher.COL_GAME_PRESET")}; //$NON-NLS-1$ - - /** - * The entries. - */ - private ArrayList entries = new ArrayList<>(); - - /* (non-Javadoc) - * @see javax.swing.table.TableModel#getColumnCount() - */ - public int getColumnCount() { - return this.columnNames.length; - } - - /* (non-Javadoc) - * @see javax.swing.table.TableModel#getRowCount() - */ - public int getRowCount() { - return this.entries.size(); - } - - /* (non-Javadoc) - * @see javax.swing.table.AbstractTableModel#getColumnName(int) - */ - public String getColumnName(int col) { - return this.columnNames[col]; - } - - /* (non-Javadoc) - * @see javax.swing.table.TableModel#getValueAt(int, int) - */ - public Object getValueAt(int row, int col) { - SingleplayerListEntry entry = this.entries.get(row); - switch (col) { - case 0: - return entry.name; - case 1: - return entry.description; - case 2: - return entry.gamePreset; - default: - return null; - } - } - - /* - * All entries are strings *at the moment*. - */ - /* (non-Javadoc) - * @see javax.swing.table.AbstractTableModel#getColumnClass(int) - */ - public Class getColumnClass(int c) { - return String.class; - } - - /* - * Don't need to implement this method unless your table's editable. - */ - /* (non-Javadoc) - * @see javax.swing.table.AbstractTableModel#isCellEditable(int, int) - */ - public boolean isCellEditable(int row, int col) { - return false; - } - - /** - * Instantiates a new singleplayer list table model. - * - * @param entries the entries - */ - public SingleplayerListTableModel( - ArrayList entries) { - this.entries = entries; - } - - } -} +package net.mosstest.launcher; + +import net.mosstest.servercore.*; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.log4j.Logger; + +import javax.swing.*; +import javax.swing.table.AbstractTableModel; +import java.awt.*; +import java.awt.Dialog.ModalityType; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.IOException; +import java.lang.reflect.InvocationTargetException; +import java.util.ArrayList; + +// TODO: Auto-generated Javadoc + +/** + * The Class GUIClientsideLauncher. + */ +public class GUIClientsideLauncher { + + /** + * The logger. + */ + static Logger logger = Logger.getLogger(GUIClientsideLauncher.class); + + /** + * The mdl. + */ + private SingleplayerListTableModel mdl; + + static { + System.setSecurityManager(MosstestSecurityManager.instance); + } + + /** + * The Class SingleplayerListEntry. + */ + public static class SingleplayerListEntry { + + /** + * The name. + */ + public String name; + + /** + * The description. + */ + public String description; + + /** + * The game preset. + */ + public String gamePreset; + + /** + * Instantiates a new singleplayer list entry. + * + * @param name the name + * @param description the description + * @param gamePreset the game preset + */ + public SingleplayerListEntry(String name, String description, + String gamePreset) { + this.name = name; + this.description = description; + this.gamePreset = gamePreset; + } + + } + + /** + * The frm mosstest client launcher. + */ + private JDialog frmMosstestClientLauncher; + + /** + * The table. + */ + private JTable table; + + /** + * Launch the application. + * + * @param args the arguments + * @throws InvocationTargetException the invocation target exception + * @throws InterruptedException the interrupted exception + */ + public static void main(String[] args) throws InvocationTargetException, InterruptedException { + logger.info("Mosstest client starting..."); + try { + UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); + } catch (ClassNotFoundException | InstantiationException + | IllegalAccessException | UnsupportedLookAndFeelException e1) { + logger.warn(Messages + .getString("GUIClientsideLauncher.WARN_SET_LAF")); //$NON-NLS-1$ + } + + EventQueue.invokeAndWait(new Runnable() { + public void run() { + ArrayList entries = new ArrayList<>(); + + GUIClientsideLauncher window = new GUIClientsideLauncher( + entries); + window.frmMosstestClientLauncher.setVisible(true); + + } + }); + } + + /** + * Create the application. + * + * @param singleplayerEntries the singleplayer entries + */ + public GUIClientsideLauncher( + ArrayList singleplayerEntries) { + initialize(singleplayerEntries); + } + + /** + * Initialize the contents of the frame. + * + * @param singleplayerEntries the singleplayer entries + */ + private void initialize(ArrayList singleplayerEntries) { + this.frmMosstestClientLauncher = new JDialog(); + this.frmMosstestClientLauncher.setModal(true); + this.frmMosstestClientLauncher.setModalityType(ModalityType.APPLICATION_MODAL); + this.frmMosstestClientLauncher.setTitle(Messages + .getString("GUIClientsideLauncher.DLG_TITLE")); //$NON-NLS-1$ + this.frmMosstestClientLauncher.setBounds(100, 100, 800, 480); + this.frmMosstestClientLauncher + .setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); + + JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP); + this.frmMosstestClientLauncher.getContentPane().add(tabbedPane, + BorderLayout.CENTER); + + JPanel singleplayerTab = new JPanel(); + tabbedPane + .addTab(Messages + .getString("GUIClientsideLauncher.DLG_SINGLEPLAYER"), null, singleplayerTab, null); //$NON-NLS-1$ + singleplayerTab.setLayout(new BorderLayout(0, 0)); + this.table = new JTable(); + this.table.setFillsViewportHeight(true); + this.mdl = new SingleplayerListTableModel(singleplayerEntries); + this.table.setModel(this.mdl); + this.table.getColumnModel().getColumn(0).setPreferredWidth(90); + this.table.getColumnModel().getColumn(1).setPreferredWidth(256); + this.table.getColumnModel().getColumn(2).setPreferredWidth(104); + this.table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); + JPanel singleplayerControlBtns = new JPanel(); + singleplayerTab.add(singleplayerControlBtns, BorderLayout.SOUTH); + singleplayerControlBtns.setLayout(new GridLayout(0, 4, 0, 0)); + + JButton btnPlaySingleplayer = new JButton( + Messages.getString("GUIClientsideLauncher.DLG_PLAY")); //$NON-NLS-1$ + btnPlaySingleplayer.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + + int row = GUIClientsideLauncher.this.table.getSelectedRow(); + if (row < 0) { + + logger.warn("An attempt was made to start gameplay without selecting a world."); + JOptionPane.showMessageDialog( + null, + Messages.getString("GUIClientsideLauncher.ERR_NO_WORLD_SELECTED"), //$NON-NLS-1$ + Messages.getString("GUIClientsideLauncher.ERR_NO_WORLD_SELECTED_TITLE"), //$NON-NLS-1$ + JOptionPane.WARNING_MESSAGE); + + return; + } + GUIClientsideLauncher.this.frmMosstestClientLauncher + .setVisible(false); + // below is testing code. in reality this would call a method to + // start a world and block. This should be in a try-catch block + // for the bug reporter to snatch up. + try { + + MossWorld w = new MossWorld((String) GUIClientsideLauncher.this.table.getModel().getValueAt(row, 0), -16511); + } catch (MossWorldLoadException | MapDatabaseException | IOException | ConfigurationException e) { + logger.error("Uncaught exception in game code, opening bug reporter."); + + String fname = MossDebugUtils.writeStracktrace(e); + logger.error("Stracktrace has been written to " + fname); + GUIBugReportDialog bg = new GUIBugReportDialog( + MossDebugUtils.getDebugInformation(e)); + bg.setVisible(true); + } + GUIClientsideLauncher.this.frmMosstestClientLauncher + .setVisible(true); + } + }); + singleplayerControlBtns.add(btnPlaySingleplayer); + + JButton btnNewSingleplayer = new JButton( + Messages.getString("GUIClientsideLauncher.DLG_NEW")); //$NON-NLS-1$ + btnNewSingleplayer.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + GUIWorldCreationDialog dlg = new GUIWorldCreationDialog(); + dlg.setVisible(true); + if (dlg.dlgResult) { + logger.debug("Got world: " + + dlg.nameField.getText() + + " with desc: " + + dlg.inputDesc.getText() + + " with game: " + + dlg.comboBox.getItemAt(dlg.comboBox + .getSelectedIndex())); //$NON-NLS-1$ + + } else + logger.info("World creation cancelled"); + } + }); + + singleplayerControlBtns.add(btnNewSingleplayer); + + JButton btnSettingsSingleplayer = new JButton( + Messages.getString("GUIClientsideLauncher.DLG_SETTINGS")); //$NON-NLS-1$ + singleplayerControlBtns.add(btnSettingsSingleplayer); + + JButton btnDelete = new JButton( + Messages.getString("GUIClientsideLauncher.DLG_DELETE")); //$NON-NLS-1$ + btnDelete.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + int row = GUIClientsideLauncher.this.table.getSelectedRow(); + if (row < 0) { + + logger.warn("An attempt was made to delete a world, but none was selected."); + JOptionPane.showMessageDialog( + null, + Messages.getString("GUIClientsideLauncher.DLG_NO_WORLD_TO_DELETE"), //$NON-NLS-1$ + Messages.getString("GUIClientsideLauncher.ERR_NO_WORLD_SELECTED_TITLE"), //$NON-NLS-1$ + JOptionPane.WARNING_MESSAGE); + + } + + } + }); + singleplayerControlBtns.add(btnDelete); + + // singleplayerTab.add(this.table, BorderLayout.CENTER); + + JScrollPane singleplayerScrollPane = new JScrollPane(this.table); + singleplayerScrollPane + .setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); + singleplayerTab.add(singleplayerScrollPane, BorderLayout.CENTER); + JPanel aboutTab = new JPanel(); + tabbedPane + .addTab(Messages.getString("GUIClientsideLauncher.DLG_ABOUT"), null, aboutTab, null); //$NON-NLS-1$ + tabbedPane.setEnabledAt(1, true); + SpringLayout sl_aboutTab = new SpringLayout(); + aboutTab.setLayout(sl_aboutTab); + + JPanel communityToolsButtonPanel = new JPanel(); + sl_aboutTab.putConstraint(SpringLayout.NORTH, + communityToolsButtonPanel, 405, SpringLayout.NORTH, aboutTab); + sl_aboutTab.putConstraint(SpringLayout.WEST, communityToolsButtonPanel, + 0, SpringLayout.WEST, aboutTab); + sl_aboutTab.putConstraint(SpringLayout.EAST, communityToolsButtonPanel, + 787, SpringLayout.WEST, aboutTab); + aboutTab.add(communityToolsButtonPanel); + communityToolsButtonPanel.setLayout(new GridLayout(0, 5, 0, 0)); + + JButton btnReportBug = new JButton( + Messages.getString("GUIClientsideLauncher.23")); //$NON-NLS-1$ + btnReportBug.setEnabled(false); + communityToolsButtonPanel.add(btnReportBug); + + JButton btnRequestNewFeature = new JButton( + Messages.getString("GUIClientsideLauncher.24")); //$NON-NLS-1$ + btnRequestNewFeature.setEnabled(false); + communityToolsButtonPanel.add(btnRequestNewFeature); + + JButton btnVisitWebsite = new JButton( + Messages.getString("GUIClientsideLauncher.25")); //$NON-NLS-1$ + btnVisitWebsite.setEnabled(false); + communityToolsButtonPanel.add(btnVisitWebsite); + + JButton btnGithubProject = new JButton( + Messages.getString("GUIClientsideLauncher.26")); //$NON-NLS-1$ + btnGithubProject.setEnabled(false); + communityToolsButtonPanel.add(btnGithubProject); + + JButton btnVisitForums = new JButton( + Messages.getString("GUIClientsideLauncher.27")); //$NON-NLS-1$ + btnVisitForums.setEnabled(false); + communityToolsButtonPanel.add(btnVisitForums); + + JTextArea textArea = new JTextArea(); + aboutTab.add(textArea); + textArea.setText(" __ __ ____ _____ _____ _______ ______ _____ _______ \r\n" + + " | \\/ |/ __ \\ / ____/ ____|__ __| ____|/ ____|__ __|\r\n" + + " | \\ / | | | | (___| (___ | | | |__ | (___ | | \r\n" + + " | |\\/| | | | |\\___ \\\\___ \\ | | | __| \\___ \\ | | \r\n" + + " | | | | |__| |____) |___) | | | | |____ ____) | | | \r\n" + + " |_| |_|\\____/|_____/_____/ |_| |______|_____/ |_| \r\n" + + " \r\n" + + " 0.0.1-initial \r\n" + + "" + + Messages + .getString("GUIClientsideLauncher.NOTICE_PRIMARY_AUTHORS") //$NON-NLS-1$ + + Messages + .getString("GUIClientsideLauncher.NOTICE_DEFAULT_GAME_CODE") //$NON-NLS-1$ + + Messages.getString("GUIClientsideLauncher.SYS_NEWLINE") //$NON-NLS-1$ + + Messages.getString("GUIClientsideLauncher.USES_LIBS") //$NON-NLS-1$ + + "* Apache Commons Lang\r\n" + + "* Apache Commons Collections\r\n" + + "* JInput\r\n" + + "* jmonkeyengine/jme3\r\n" + + "* niftygui\r\n" + + "* Google Guava Collections\r\n" + + "* Apache Commons CLI\r\n" + + "* Apache Commons Configuration\r\n" + + "* Mozilla Rhino\r\n" + + "* leveldbjni\r\n" + + "* junit4 for testing\r\n" + + Messages.getString("GUIClientsideLauncher.SYS_NEWLINE") //$NON-NLS-1$ + + Messages.getString("GUIClientsideLauncher.NOTICE_TOOLS_USED")); //$NON-NLS-1$ + textArea.setWrapStyleWord(true); + textArea.setBackground(new Color(192, 192, 192)); + textArea.setEditable(false); + JScrollPane scrollPane = new JScrollPane(textArea); + sl_aboutTab.putConstraint(SpringLayout.NORTH, scrollPane, 0, + SpringLayout.NORTH, aboutTab); + sl_aboutTab.putConstraint(SpringLayout.WEST, scrollPane, 0, + SpringLayout.WEST, aboutTab); + sl_aboutTab.putConstraint(SpringLayout.SOUTH, scrollPane, 0, + SpringLayout.NORTH, communityToolsButtonPanel); + sl_aboutTab.putConstraint(SpringLayout.EAST, scrollPane, 787, + SpringLayout.WEST, aboutTab); + scrollPane + .setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); + scrollPane + .setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); + aboutTab.add(scrollPane); + frmMosstestClientLauncher.setVisible(true); + } + + /** + * The Class SingleplayerListTableModel. + */ + class SingleplayerListTableModel extends AbstractTableModel { + + /** + * The column names. + */ + private String[] columnNames = { + Messages.getString("GUIClientsideLauncher.COL_WORLD_NAME"), Messages.getString("GUIClientsideLauncher.COL_WORLD_DESC"), //$NON-NLS-1$ //$NON-NLS-2$ + Messages.getString("GUIClientsideLauncher.COL_GAME_PRESET")}; //$NON-NLS-1$ + + /** + * The entries. + */ + private ArrayList entries = new ArrayList<>(); + + /* (non-Javadoc) + * @see javax.swing.table.TableModel#getColumnCount() + */ + public int getColumnCount() { + return this.columnNames.length; + } + + /* (non-Javadoc) + * @see javax.swing.table.TableModel#getRowCount() + */ + public int getRowCount() { + return this.entries.size(); + } + + /* (non-Javadoc) + * @see javax.swing.table.AbstractTableModel#getColumnName(int) + */ + public String getColumnName(int col) { + return this.columnNames[col]; + } + + /* (non-Javadoc) + * @see javax.swing.table.TableModel#getValueAt(int, int) + */ + public Object getValueAt(int row, int col) { + SingleplayerListEntry entry = this.entries.get(row); + switch (col) { + case 0: + return entry.name; + case 1: + return entry.description; + case 2: + return entry.gamePreset; + default: + return null; + } + } + + /* + * All entries are strings *at the moment*. + */ + /* (non-Javadoc) + * @see javax.swing.table.AbstractTableModel#getColumnClass(int) + */ + public Class getColumnClass(int c) { + return String.class; + } + + /* + * Don't need to implement this method unless your table's editable. + */ + /* (non-Javadoc) + * @see javax.swing.table.AbstractTableModel#isCellEditable(int, int) + */ + public boolean isCellEditable(int row, int col) { + return false; + } + + /** + * Instantiates a new singleplayer list table model. + * + * @param entries the entries + */ + public SingleplayerListTableModel( + ArrayList entries) { + this.entries = entries; + } + + } +} diff --git a/src/net/mosstest/launcher/GUIWorldCreationDialog.java b/src/net/mosstest/launcher/GUIWorldCreationDialog.java index 81c5c6a..ae1bf72 100644 --- a/src/net/mosstest/launcher/GUIWorldCreationDialog.java +++ b/src/net/mosstest/launcher/GUIWorldCreationDialog.java @@ -1,155 +1,155 @@ -package net.mosstest.launcher; - -import java.awt.BorderLayout; -import java.awt.FlowLayout; - -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.border.EmptyBorder; - -import java.awt.Dialog.ModalityType; - -import javax.swing.DefaultComboBoxModel; - -import com.jme3.material.RenderState.TestFunction; - -import java.awt.event.ActionListener; -import java.awt.event.ActionEvent; -import java.awt.GridLayout; -import java.awt.Dimension; - -// TODO: Auto-generated Javadoc -/** - * The Class GUIWorldCreationDialog. - */ -public class GUIWorldCreationDialog extends JDialog { - - /** The dlg result. */ - boolean dlgResult= false; - - /** The content panel. */ - private final JPanel contentPanel = new JPanel(); - - /** The combo box. */ - JComboBox comboBox; - - /** The input desc. */ - JTextField inputDesc; - - /** The name field. */ - JTextField nameField; - - /** - * Launch the application. - * - * @param args the arguments - */ - public static void main(String[] args) { - try { - GUIWorldCreationDialog dialog = new GUIWorldCreationDialog(); - dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - dialog.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * Create the dialog. - */ - public GUIWorldCreationDialog() { - setTitle(Messages.getString("GUIWorldCreationDialog.DLG_TITLE")); //$NON-NLS-1$ - setModal(true); - setModalityType(ModalityType.APPLICATION_MODAL); - setResizable(false); - setBounds(100, 100, 450, 142); - getContentPane().setLayout(new BorderLayout()); - this.contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); - getContentPane().add(this.contentPanel, BorderLayout.CENTER); - contentPanel.setLayout(new GridLayout(3, 1, 0, 0)); - { - JPanel namePanel = new JPanel(); - namePanel.setMinimumSize(new Dimension(10, 20)); - namePanel.setMaximumSize(new Dimension(32767, 20)); - contentPanel.add(namePanel); - namePanel.setLayout(new BorderLayout(0, 0)); - - { - JLabel lblWorldName = new JLabel(Messages.getString("GUIWorldCreationDialog.WORLD_NAME")); //$NON-NLS-1$ - namePanel.add(lblWorldName, BorderLayout.WEST); - } - { - this.nameField = new JTextField(); - nameField.setMaximumSize(new Dimension(2147483647, 20)); - namePanel.add(nameField, BorderLayout.CENTER); - this.nameField.setColumns(10); - } - } - { - JPanel descPnl = new JPanel(); - descPnl.setMinimumSize(new Dimension(10, 20)); - descPnl.setMaximumSize(new Dimension(32767, 20)); - contentPanel.add(descPnl); - descPnl.setLayout(new BorderLayout(0, 0)); - { - JLabel lblDescription = new JLabel(Messages.getString("GUIWorldCreationDialog.WORLD_DESC")); //$NON-NLS-1$ - descPnl.add(lblDescription, BorderLayout.WEST); - } - { - this.inputDesc = new JTextField(); - descPnl.add(inputDesc, BorderLayout.CENTER); - this.inputDesc.setColumns(10); - } - } - { - JPanel profPnl = new JPanel(); - profPnl.setMinimumSize(new Dimension(10, 20)); - profPnl.setMaximumSize(new Dimension(32767, 20)); - contentPanel.add(profPnl); - profPnl.setLayout(new BorderLayout(0, 0)); - { - JLabel lblGameProfile = new JLabel(Messages.getString("GUIWorldCreationDialog.GAME_PROFILE")); //$NON-NLS-1$ - profPnl.add(lblGameProfile, BorderLayout.WEST); - } - { - this.comboBox = new JComboBox(); - comboBox.setMaximumSize(new Dimension(32767, 23)); - profPnl.add(comboBox, BorderLayout.CENTER); - } - } - { - JPanel buttonPane = new JPanel(); - buttonPane.setMaximumSize(new Dimension(32767, 23)); - buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); - getContentPane().add(buttonPane, BorderLayout.SOUTH); - { - JButton okButton = new JButton(Messages.getString("GUIWorldCreationDialog.OK")); //$NON-NLS-1$ - okButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - GUIWorldCreationDialog.this.dlgResult = true; - GUIWorldCreationDialog.this.dispose(); - } - }); - okButton.setActionCommand(Messages.getString("GUIWorldCreationDialog.OK")); //$NON-NLS-1$ - buttonPane.add(okButton); - getRootPane().setDefaultButton(okButton); - } - { - JButton cancelButton = new JButton(Messages.getString("GUIWorldCreationDialog.CXL")); //$NON-NLS-1$ - cancelButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - GUIWorldCreationDialog.this.dlgResult = false; - GUIWorldCreationDialog.this.dispose(); - } - }); - cancelButton.setActionCommand(Messages.getString("GUIWorldCreationDialog.CXL")); //$NON-NLS-1$ - buttonPane.add(cancelButton); - } - } - } - -} +package net.mosstest.launcher; + +import java.awt.BorderLayout; +import java.awt.FlowLayout; + +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.border.EmptyBorder; + +import java.awt.Dialog.ModalityType; + +import javax.swing.DefaultComboBoxModel; + +import com.jme3.material.RenderState.TestFunction; + +import java.awt.event.ActionListener; +import java.awt.event.ActionEvent; +import java.awt.GridLayout; +import java.awt.Dimension; + +// TODO: Auto-generated Javadoc +/** + * The Class GUIWorldCreationDialog. + */ +public class GUIWorldCreationDialog extends JDialog { + + /** The dlg result. */ + boolean dlgResult= false; + + /** The content panel. */ + private final JPanel contentPanel = new JPanel(); + + /** The combo box. */ + JComboBox comboBox; + + /** The input desc. */ + JTextField inputDesc; + + /** The name field. */ + JTextField nameField; + + /** + * Launch the application. + * + * @param args the arguments + */ + public static void main(String[] args) { + try { + GUIWorldCreationDialog dialog = new GUIWorldCreationDialog(); + dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + dialog.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Create the dialog. + */ + public GUIWorldCreationDialog() { + setTitle(Messages.getString("GUIWorldCreationDialog.DLG_TITLE")); //$NON-NLS-1$ + setModal(true); + setModalityType(ModalityType.APPLICATION_MODAL); + setResizable(false); + setBounds(100, 100, 450, 142); + getContentPane().setLayout(new BorderLayout()); + this.contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); + getContentPane().add(this.contentPanel, BorderLayout.CENTER); + contentPanel.setLayout(new GridLayout(3, 1, 0, 0)); + { + JPanel namePanel = new JPanel(); + namePanel.setMinimumSize(new Dimension(10, 20)); + namePanel.setMaximumSize(new Dimension(32767, 20)); + contentPanel.add(namePanel); + namePanel.setLayout(new BorderLayout(0, 0)); + + { + JLabel lblWorldName = new JLabel(Messages.getString("GUIWorldCreationDialog.WORLD_NAME")); //$NON-NLS-1$ + namePanel.add(lblWorldName, BorderLayout.WEST); + } + { + this.nameField = new JTextField(); + nameField.setMaximumSize(new Dimension(2147483647, 20)); + namePanel.add(nameField, BorderLayout.CENTER); + this.nameField.setColumns(10); + } + } + { + JPanel descPnl = new JPanel(); + descPnl.setMinimumSize(new Dimension(10, 20)); + descPnl.setMaximumSize(new Dimension(32767, 20)); + contentPanel.add(descPnl); + descPnl.setLayout(new BorderLayout(0, 0)); + { + JLabel lblDescription = new JLabel(Messages.getString("GUIWorldCreationDialog.WORLD_DESC")); //$NON-NLS-1$ + descPnl.add(lblDescription, BorderLayout.WEST); + } + { + this.inputDesc = new JTextField(); + descPnl.add(inputDesc, BorderLayout.CENTER); + this.inputDesc.setColumns(10); + } + } + { + JPanel profPnl = new JPanel(); + profPnl.setMinimumSize(new Dimension(10, 20)); + profPnl.setMaximumSize(new Dimension(32767, 20)); + contentPanel.add(profPnl); + profPnl.setLayout(new BorderLayout(0, 0)); + { + JLabel lblGameProfile = new JLabel(Messages.getString("GUIWorldCreationDialog.GAME_PROFILE")); //$NON-NLS-1$ + profPnl.add(lblGameProfile, BorderLayout.WEST); + } + { + this.comboBox = new JComboBox(); + comboBox.setMaximumSize(new Dimension(32767, 23)); + profPnl.add(comboBox, BorderLayout.CENTER); + } + } + { + JPanel buttonPane = new JPanel(); + buttonPane.setMaximumSize(new Dimension(32767, 23)); + buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); + getContentPane().add(buttonPane, BorderLayout.SOUTH); + { + JButton okButton = new JButton(Messages.getString("GUIWorldCreationDialog.OK")); //$NON-NLS-1$ + okButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + GUIWorldCreationDialog.this.dlgResult = true; + GUIWorldCreationDialog.this.dispose(); + } + }); + okButton.setActionCommand(Messages.getString("GUIWorldCreationDialog.OK")); //$NON-NLS-1$ + buttonPane.add(okButton); + getRootPane().setDefaultButton(okButton); + } + { + JButton cancelButton = new JButton(Messages.getString("GUIWorldCreationDialog.CXL")); //$NON-NLS-1$ + cancelButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + GUIWorldCreationDialog.this.dlgResult = false; + GUIWorldCreationDialog.this.dispose(); + } + }); + cancelButton.setActionCommand(Messages.getString("GUIWorldCreationDialog.CXL")); //$NON-NLS-1$ + buttonPane.add(cancelButton); + } + } + } + +} diff --git a/src/net/mosstest/launcher/GUIWorldDeletionDialog.java b/src/net/mosstest/launcher/GUIWorldDeletionDialog.java index 2591bd9..2c06241 100644 --- a/src/net/mosstest/launcher/GUIWorldDeletionDialog.java +++ b/src/net/mosstest/launcher/GUIWorldDeletionDialog.java @@ -1,99 +1,99 @@ -package net.mosstest.launcher; - -import java.awt.BorderLayout; -import java.awt.FlowLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; - -import javax.swing.BoxLayout; -import javax.swing.JButton; -import javax.swing.JDialog; -import javax.swing.JLabel; -import javax.swing.JPanel; -import javax.swing.SwingConstants; -import javax.swing.border.EmptyBorder; - -// TODO: Auto-generated Javadoc -/** - * The Class GUIWorldDeletionDialog. - */ -public class GUIWorldDeletionDialog extends JDialog { - - /** The dlg result. */ - boolean dlgResult=false; - - /** The content panel. */ - private final JPanel contentPanel = new JPanel(); - - /** - * Launch the application. - * - * @param args the arguments - */ - public static void main(String[] args) { - try { - GUIWorldDeletionDialog dialog = new GUIWorldDeletionDialog("test from main"); //$NON-NLS-1$ - dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); - dialog.setVisible(true); - } catch (Exception e) { - e.printStackTrace(); - } - } - - /** - * Create the dialog. - * - * @param worldName the world name - */ - public GUIWorldDeletionDialog(String worldName) { - setTitle(Messages.getString("GUIWorldDeletionDialog.DLG_TITLE")); //$NON-NLS-1$ - setModal(true); - setModalityType(ModalityType.APPLICATION_MODAL); - setResizable(false); - setBounds(100, 100, 600, 105); - getContentPane().setLayout(new BorderLayout()); - this.contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); - getContentPane().add(this.contentPanel, BorderLayout.CENTER); - contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.X_AXIS)); - { - JPanel panel = new JPanel(); - contentPanel.add(panel); - panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); - - { - JLabel lblAreYouSure = new JLabel(Messages.getString("GUIWorldDeletionDialog.AREYOUSURE_TEXT")+worldName+Messages.getString("GUIWorldDeletionDialog.QUESTIONMARK_CANNOT_UNDO")); //$NON-NLS-1$ //$NON-NLS-2$ - panel.add(lblAreYouSure); - lblAreYouSure.setHorizontalTextPosition(SwingConstants.LEFT); - lblAreYouSure.setHorizontalAlignment(SwingConstants.LEFT); - } - } - { - JPanel buttonPane = new JPanel(); - buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); - getContentPane().add(buttonPane, BorderLayout.SOUTH); - { - JButton btnYes = new JButton(Messages.getString("GUIWorldDeletionDialog.YES")); //$NON-NLS-1$ - btnYes.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - GUIWorldDeletionDialog.this.dlgResult = true; - GUIWorldDeletionDialog.this.dispose(); - } - }); - btnYes.setActionCommand(Messages.getString("GUIWorldDeletionDialog.YES")); //$NON-NLS-1$ - buttonPane.add(btnYes); - getRootPane().setDefaultButton(btnYes); - } - { - JButton cancelButton = new JButton(Messages.getString("GUIWorldDeletionDialog.NO")); //$NON-NLS-1$ - cancelButton.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - GUIWorldDeletionDialog.this.dlgResult = false; - GUIWorldDeletionDialog.this.dispose(); - } - }); - buttonPane.add(cancelButton); - } - } - } - -} +package net.mosstest.launcher; + +import java.awt.BorderLayout; +import java.awt.FlowLayout; +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; + +import javax.swing.BoxLayout; +import javax.swing.JButton; +import javax.swing.JDialog; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.SwingConstants; +import javax.swing.border.EmptyBorder; + +// TODO: Auto-generated Javadoc +/** + * The Class GUIWorldDeletionDialog. + */ +public class GUIWorldDeletionDialog extends JDialog { + + /** The dlg result. */ + boolean dlgResult=false; + + /** The content panel. */ + private final JPanel contentPanel = new JPanel(); + + /** + * Launch the application. + * + * @param args the arguments + */ + public static void main(String[] args) { + try { + GUIWorldDeletionDialog dialog = new GUIWorldDeletionDialog("test from main"); //$NON-NLS-1$ + dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); + dialog.setVisible(true); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** + * Create the dialog. + * + * @param worldName the world name + */ + public GUIWorldDeletionDialog(String worldName) { + setTitle(Messages.getString("GUIWorldDeletionDialog.DLG_TITLE")); //$NON-NLS-1$ + setModal(true); + setModalityType(ModalityType.APPLICATION_MODAL); + setResizable(false); + setBounds(100, 100, 600, 105); + getContentPane().setLayout(new BorderLayout()); + this.contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); + getContentPane().add(this.contentPanel, BorderLayout.CENTER); + contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.X_AXIS)); + { + JPanel panel = new JPanel(); + contentPanel.add(panel); + panel.setLayout(new BoxLayout(panel, BoxLayout.X_AXIS)); + + { + JLabel lblAreYouSure = new JLabel(Messages.getString("GUIWorldDeletionDialog.AREYOUSURE_TEXT")+worldName+Messages.getString("GUIWorldDeletionDialog.QUESTIONMARK_CANNOT_UNDO")); //$NON-NLS-1$ //$NON-NLS-2$ + panel.add(lblAreYouSure); + lblAreYouSure.setHorizontalTextPosition(SwingConstants.LEFT); + lblAreYouSure.setHorizontalAlignment(SwingConstants.LEFT); + } + } + { + JPanel buttonPane = new JPanel(); + buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); + getContentPane().add(buttonPane, BorderLayout.SOUTH); + { + JButton btnYes = new JButton(Messages.getString("GUIWorldDeletionDialog.YES")); //$NON-NLS-1$ + btnYes.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + GUIWorldDeletionDialog.this.dlgResult = true; + GUIWorldDeletionDialog.this.dispose(); + } + }); + btnYes.setActionCommand(Messages.getString("GUIWorldDeletionDialog.YES")); //$NON-NLS-1$ + buttonPane.add(btnYes); + getRootPane().setDefaultButton(btnYes); + } + { + JButton cancelButton = new JButton(Messages.getString("GUIWorldDeletionDialog.NO")); //$NON-NLS-1$ + cancelButton.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + GUIWorldDeletionDialog.this.dlgResult = false; + GUIWorldDeletionDialog.this.dispose(); + } + }); + buttonPane.add(cancelButton); + } + } + } + +} diff --git a/src/net/mosstest/launcher/Messages.java b/src/net/mosstest/launcher/Messages.java index 122301e..18189ae 100644 --- a/src/net/mosstest/launcher/Messages.java +++ b/src/net/mosstest/launcher/Messages.java @@ -1,48 +1,48 @@ -package net.mosstest.launcher; - - -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -// TODO: Auto-generated Javadoc -/** - * The Class Messages. - */ -public class Messages { - - /** The Constant BUNDLE_NAME. */ - private static final String BUNDLE_NAME = "net.mosstest.launcher.messages"; //$NON-NLS-1$ - - /** The res bundle. */ - private static ResourceBundle resBundle = ResourceBundle - .getBundle(BUNDLE_NAME); - - /** - * Change language. - * - * @param identifier the identifier - */ - public static void changeLanguage(String identifier) { - resBundle = ResourceBundle.getBundle(BUNDLE_NAME + "." + identifier); - } - - /** - * Instantiates a new messages. - */ - private Messages() { - } - - /** - * Gets the string. - * - * @param key the key - * @return the string - */ - public static String getString(String key) { - try { - return resBundle.getString(key); - } catch (MissingResourceException e) { - return '!' + key + '!'; - } - } -} +package net.mosstest.launcher; + + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +// TODO: Auto-generated Javadoc +/** + * The Class Messages. + */ +public class Messages { + + /** The Constant BUNDLE_NAME. */ + private static final String BUNDLE_NAME = "net.mosstest.launcher.messages"; //$NON-NLS-1$ + + /** The res bundle. */ + private static ResourceBundle resBundle = ResourceBundle + .getBundle(BUNDLE_NAME); + + /** + * Change language. + * + * @param identifier the identifier + */ + public static void changeLanguage(String identifier) { + resBundle = ResourceBundle.getBundle(BUNDLE_NAME + "." + identifier); + } + + /** + * Instantiates a new messages. + */ + private Messages() { + } + + /** + * Gets the string. + * + * @param key the key + * @return the string + */ + public static String getString(String key) { + try { + return resBundle.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } +} diff --git a/src/net/mosstest/launcher/log4j.properties b/src/net/mosstest/launcher/log4j.properties index 598b5bf..b429636 100644 --- a/src/net/mosstest/launcher/log4j.properties +++ b/src/net/mosstest/launcher/log4j.properties @@ -1,14 +1,14 @@ -# Root logger option -log4j.rootLogger=DEBUG, file, stdout - -# Direct log messages to a log file -log4j.appender.file=org.apache.log4j.FileAppender -log4j.appender.file.File=mosslog.log -log4j.appender.file.layout=org.apache.log4j.PatternLayout -log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n - -# Direct log messages to stdout -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +# Root logger option +log4j.rootLogger=DEBUG, file, stdout + +# Direct log messages to a log file +log4j.appender.file=org.apache.log4j.FileAppender +log4j.appender.file.File=mosslog.log +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n + +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file diff --git a/src/net/mosstest/launcher/messages.properties b/src/net/mosstest/launcher/messages.properties index 1a4a932..aee2a76 100644 --- a/src/net/mosstest/launcher/messages.properties +++ b/src/net/mosstest/launcher/messages.properties @@ -1,46 +1,46 @@ -GUIBugReportDialog.DLG_BUG_DESC=Detailed problem description: -GUIBugReportDialog.DLG_BUG_DESC_DEFAULT=Please describe your problem here, preferably including what you had done, what you expected to happen, what happened, and any other details about the world or game.\n\nPlease note that we cannot help with third-party games or mods. -GUIBugReportDialog.DLG_BUG_EMAIL=e-mail (optional): -GUIBugReportDialog.DLG_BUG_NAME=Name: -GUIBugReportDialog.DLG_BUG_SUMMARY=Problem summary: -GUIBugReportDialog.DLG_BUG_TITLE=Report a bug -GUIBugReportDialog.DLG_CHECKBOX_INCLUDE_TECH_INFO=Include technical information -GUIBugReportDialog.DLG_CXL=Cancel -GUIBugReportDialog.DLG_OK=OK -GUIBugReportDialog.DLG_SUBMIT=Submit -GUIBugReportDialog.NOTICE_INFO_INCLUDED=The following information will be included in the bug report if this box is checked: \n\n -GUIClientsideLauncher.23=Report a bug... -GUIClientsideLauncher.24=Request new feature... -GUIClientsideLauncher.25=Visit website -GUIClientsideLauncher.26=GitHub project -GUIClientsideLauncher.27=Visit forums -GUIClientsideLauncher.COL_GAME_PRESET=Game preset -GUIClientsideLauncher.COL_WORLD_DESC=Description -GUIClientsideLauncher.COL_WORLD_NAME=World name -GUIClientsideLauncher.DLG_ABOUT=About -GUIClientsideLauncher.DLG_DELETE=Delete... -GUIClientsideLauncher.DLG_NEW=New... -GUIClientsideLauncher.DLG_NO_WORLD_TO_DELETE=No world was selected to be deleted. Please select an existing world in the table. -GUIClientsideLauncher.DLG_PLAY=Play -GUIClientsideLauncher.DLG_SETTINGS=Settings... -GUIClientsideLauncher.DLG_SINGLEPLAYER=Singleplayer -GUIClientsideLauncher.DLG_TITLE=Mosstest Client launcher <0.0.1-initial> -GUIClientsideLauncher.ERR_NO_WORLD_SELECTED=No world was selected to be started. Please select an existing world in the table, or create a new world. -GUIClientsideLauncher.ERR_NO_WORLD_SELECTED_TITLE=No world selected -GUIClientsideLauncher.NOTICE_DEFAULT_GAME_CODE=Default game code and textures created by dolinksy296, hexafraction, et. al.\n -GUIClientsideLauncher.NOTICE_PRIMARY_AUTHORS=Made by hexafraction, thatnerd2, et al.\n -GUIClientsideLauncher.NOTICE_TOOLS_USED=Made with the help of Eclipse, Git, Maven, and countless services such as TravisCI and GitHub.\n -GUIClientsideLauncher.SYS_NEWLINE=\n -GUIClientsideLauncher.USES_LIBS=Uses the following libraries:\n -GUIClientsideLauncher.WARN_SET_LAF=Warning: The look-and-feel cannot be set to system. Using default look-and-feel. -GUIWorldCreationDialog.CXL=Cancel -GUIWorldCreationDialog.DLG_TITLE=Create new singleplayer world... -GUIWorldCreationDialog.GAME_PROFILE=Game profile: -GUIWorldCreationDialog.OK=OK -GUIWorldCreationDialog.WORLD_DESC=Description: -GUIWorldCreationDialog.WORLD_NAME=World name: -GUIWorldDeletionDialog.AREYOUSURE_TEXT=Are you sure you wish to delete the world called -GUIWorldDeletionDialog.DLG_TITLE=Delete singleplayer world... -GUIWorldDeletionDialog.NO=No -GUIWorldDeletionDialog.QUESTIONMARK_CANNOT_UNDO=? This operation cannot be undone. -GUIWorldDeletionDialog.YES=Yes +GUIBugReportDialog.DLG_BUG_DESC=Detailed problem description: +GUIBugReportDialog.DLG_BUG_DESC_DEFAULT=Please describe your problem here, preferably including what you had done, what you expected to happen, what happened, and any other details about the world or game.\n\nPlease note that we cannot help with third-party games or mods. +GUIBugReportDialog.DLG_BUG_EMAIL=e-mail (optional): +GUIBugReportDialog.DLG_BUG_NAME=Name: +GUIBugReportDialog.DLG_BUG_SUMMARY=Problem summary: +GUIBugReportDialog.DLG_BUG_TITLE=Report a bug +GUIBugReportDialog.DLG_CHECKBOX_INCLUDE_TECH_INFO=Include technical information +GUIBugReportDialog.DLG_CXL=Cancel +GUIBugReportDialog.DLG_OK=OK +GUIBugReportDialog.DLG_SUBMIT=Submit +GUIBugReportDialog.NOTICE_INFO_INCLUDED=The following information will be included in the bug report if this box is checked: \n\n +GUIClientsideLauncher.23=Report a bug... +GUIClientsideLauncher.24=Request new feature... +GUIClientsideLauncher.25=Visit website +GUIClientsideLauncher.26=GitHub project +GUIClientsideLauncher.27=Visit forums +GUIClientsideLauncher.COL_GAME_PRESET=Game preset +GUIClientsideLauncher.COL_WORLD_DESC=Description +GUIClientsideLauncher.COL_WORLD_NAME=World name +GUIClientsideLauncher.DLG_ABOUT=About +GUIClientsideLauncher.DLG_DELETE=Delete... +GUIClientsideLauncher.DLG_NEW=New... +GUIClientsideLauncher.DLG_NO_WORLD_TO_DELETE=No world was selected to be deleted. Please select an existing world in the table. +GUIClientsideLauncher.DLG_PLAY=Play +GUIClientsideLauncher.DLG_SETTINGS=Settings... +GUIClientsideLauncher.DLG_SINGLEPLAYER=Singleplayer +GUIClientsideLauncher.DLG_TITLE=Mosstest Client launcher <0.0.1-initial> +GUIClientsideLauncher.ERR_NO_WORLD_SELECTED=No world was selected to be started. Please select an existing world in the table, or create a new world. +GUIClientsideLauncher.ERR_NO_WORLD_SELECTED_TITLE=No world selected +GUIClientsideLauncher.NOTICE_DEFAULT_GAME_CODE=Default game code and textures created by dolinksy296, hexafraction, et. al.\n +GUIClientsideLauncher.NOTICE_PRIMARY_AUTHORS=Made by hexafraction, thatnerd2, et al.\n +GUIClientsideLauncher.NOTICE_TOOLS_USED=Made with the help of Eclipse, Git, Maven, and countless services such as TravisCI and GitHub.\n +GUIClientsideLauncher.SYS_NEWLINE=\n +GUIClientsideLauncher.USES_LIBS=Uses the following libraries:\n +GUIClientsideLauncher.WARN_SET_LAF=Warning: The look-and-feel cannot be set to system. Using default look-and-feel. +GUIWorldCreationDialog.CXL=Cancel +GUIWorldCreationDialog.DLG_TITLE=Create new singleplayer world... +GUIWorldCreationDialog.GAME_PROFILE=Game profile: +GUIWorldCreationDialog.OK=OK +GUIWorldCreationDialog.WORLD_DESC=Description: +GUIWorldCreationDialog.WORLD_NAME=World name: +GUIWorldDeletionDialog.AREYOUSURE_TEXT=Are you sure you wish to delete the world called +GUIWorldDeletionDialog.DLG_TITLE=Delete singleplayer world... +GUIWorldDeletionDialog.NO=No +GUIWorldDeletionDialog.QUESTIONMARK_CANNOT_UNDO=? This operation cannot be undone. +GUIWorldDeletionDialog.YES=Yes diff --git a/src/net/mosstest/log4j.properties b/src/net/mosstest/log4j.properties index 598b5bf..b429636 100644 --- a/src/net/mosstest/log4j.properties +++ b/src/net/mosstest/log4j.properties @@ -1,14 +1,14 @@ -# Root logger option -log4j.rootLogger=DEBUG, file, stdout - -# Direct log messages to a log file -log4j.appender.file=org.apache.log4j.FileAppender -log4j.appender.file.File=mosslog.log -log4j.appender.file.layout=org.apache.log4j.PatternLayout -log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n - -# Direct log messages to stdout -log4j.appender.stdout=org.apache.log4j.ConsoleAppender -log4j.appender.stdout.Target=System.out -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout +# Root logger option +log4j.rootLogger=DEBUG, file, stdout + +# Direct log messages to a log file +log4j.appender.file=org.apache.log4j.FileAppender +log4j.appender.file.File=mosslog.log +log4j.appender.file.layout=org.apache.log4j.PatternLayout +log4j.appender.file.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n + +# Direct log messages to stdout +log4j.appender.stdout=org.apache.log4j.ConsoleAppender +log4j.appender.stdout.Target=System.out +log4j.appender.stdout.layout=org.apache.log4j.PatternLayout log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n \ No newline at end of file diff --git a/src/net/mosstest/scripting/FlatMapGenerator.java b/src/net/mosstest/scripting/FlatMapGenerator.java index 0c44def..ae826ff 100644 --- a/src/net/mosstest/scripting/FlatMapGenerator.java +++ b/src/net/mosstest/scripting/FlatMapGenerator.java @@ -1,94 +1,94 @@ -package net.mosstest.scripting; - -import net.mosstest.servercore.INodeManager; -import net.mosstest.servercore.MapGeneratorException; - -// TODO: Auto-generated Javadoc - -/** - * The Class FlatMapGenerator. - */ -public class FlatMapGenerator implements IMapGenerator { - - public static final int CHUNK_DIMENSION = 16; - /** - * The seed. - */ - long seed; - - /** - * The nm. - */ - INodeManager nm; - - /* (non-Javadoc) - * @see net.mosstest.scripting.IMapGenerator#init(long, net.mosstest.servercore.INodeManager, java.lang.Object[]) - */ - @Override - public void init(long seed, INodeManager nm, Object... params) - throws MapGeneratorException { - this.seed = seed; - this.nm = nm; - } - - /* (non-Javadoc) - * @see net.mosstest.scripting.IMapGenerator#generateChunk(net.mosstest.scripting.Position) - */ - @Override - public MapChunk generateChunk(Position pos) - throws MapGeneratorException { - int[][][] nodes = new int[CHUNK_DIMENSION][CHUNK_DIMENSION][CHUNK_DIMENSION]; - - int fillNode = (pos.getZ() >= 0) ? this.nm.getNode( - "mg:air", false).getNodeId() : this.nm.getNode( //$NON-NLS-1$ - "mg:ground", false).getNodeId(); //$NON-NLS-1$ - - for (int x = 0; x < CHUNK_DIMENSION; x++) { - for (int y = 0; y < CHUNK_DIMENSION; y++) { - for (int z = 0; z < CHUNK_DIMENSION; z++) { - nodes[x][y][z] = fillNode; - } - } - - } - return new MapChunk(pos, nodes); - - } - - - /* (non-Javadoc) - * @see net.mosstest.scripting.IMapGenerator#fillInChunk(int[][][], net.mosstest.scripting.Position) - */ - @Override - public void fillInChunk(int[][][] lightNodes, Position pos) - throws MapGeneratorException { - int fillNode = (pos.getZ() >= 0) ? this.nm.getNode("mg:air", //$NON-NLS-1$ - false).getNodeId() : this.nm - .getNode("mg:ground", false).getNodeId(); //$NON-NLS-1$ - - for (int x = 0; x < CHUNK_DIMENSION; x++) { - for (int y = 0; y < CHUNK_DIMENSION; y++) { - for (int z = 0; z < CHUNK_DIMENSION; z++) { - if (lightNodes[x][y][z] == 0) { - // operation in place on passed in array as per - // contract - lightNodes[x][y][z] = fillNode; - } - } - } - - } - - } - - /* (non-Javadoc) - * @see net.mosstest.scripting.IMapGenerator#registerOre(net.mosstest.scripting.MapNode, double, double, double, int, java.lang.Object[]) - */ - @Override - public void registerOre(MapNode oreNode, double minDepth, - double rarity, double clumping, int seed, Object... params) { - // TODO Auto-generated method stub - - } - +package net.mosstest.scripting; + +import net.mosstest.servercore.INodeManager; +import net.mosstest.servercore.MapGeneratorException; + +// TODO: Auto-generated Javadoc + +/** + * The Class FlatMapGenerator. + */ +public class FlatMapGenerator implements IMapGenerator { + + public static final int CHUNK_DIMENSION = 16; + /** + * The seed. + */ + long seed; + + /** + * The nm. + */ + INodeManager nm; + + /* (non-Javadoc) + * @see net.mosstest.scripting.IMapGenerator#init(long, net.mosstest.servercore.INodeManager, java.lang.Object[]) + */ + @Override + public void init(long seed, INodeManager nm, Object... params) + throws MapGeneratorException { + this.seed = seed; + this.nm = nm; + } + + /* (non-Javadoc) + * @see net.mosstest.scripting.IMapGenerator#generateChunk(net.mosstest.scripting.Position) + */ + @Override + public MapChunk generateChunk(Position pos) + throws MapGeneratorException { + int[][][] nodes = new int[CHUNK_DIMENSION][CHUNK_DIMENSION][CHUNK_DIMENSION]; + + int fillNode = (pos.getZ() >= 0) ? this.nm.getNode( + "mg:air", false).getNodeId() : this.nm.getNode( //$NON-NLS-1$ + "mg:ground", false).getNodeId(); //$NON-NLS-1$ + + for (int x = 0; x < CHUNK_DIMENSION; x++) { + for (int y = 0; y < CHUNK_DIMENSION; y++) { + for (int z = 0; z < CHUNK_DIMENSION; z++) { + nodes[x][y][z] = fillNode; + } + } + + } + return new MapChunk(pos, nodes); + + } + + + /* (non-Javadoc) + * @see net.mosstest.scripting.IMapGenerator#fillInChunk(int[][][], net.mosstest.scripting.Position) + */ + @Override + public void fillInChunk(int[][][] lightNodes, Position pos) + throws MapGeneratorException { + int fillNode = (pos.getZ() >= 0) ? this.nm.getNode("mg:air", //$NON-NLS-1$ + false).getNodeId() : this.nm + .getNode("mg:ground", false).getNodeId(); //$NON-NLS-1$ + + for (int x = 0; x < CHUNK_DIMENSION; x++) { + for (int y = 0; y < CHUNK_DIMENSION; y++) { + for (int z = 0; z < CHUNK_DIMENSION; z++) { + if (lightNodes[x][y][z] == 0) { + // operation in place on passed in array as per + // contract + lightNodes[x][y][z] = fillNode; + } + } + } + + } + + } + + /* (non-Javadoc) + * @see net.mosstest.scripting.IMapGenerator#registerOre(net.mosstest.scripting.MapNode, double, double, double, int, java.lang.Object[]) + */ + @Override + public void registerOre(MapNode oreNode, double minDepth, + double rarity, double clumping, int seed, Object... params) { + // TODO Auto-generated method stub + + } + } \ No newline at end of file diff --git a/src/net/mosstest/scripting/IMapGenerator.java b/src/net/mosstest/scripting/IMapGenerator.java index 175bc8f..613ee32 100644 --- a/src/net/mosstest/scripting/IMapGenerator.java +++ b/src/net/mosstest/scripting/IMapGenerator.java @@ -1,66 +1,66 @@ -package net.mosstest.scripting; - -import net.mosstest.servercore.INodeManager; -import net.mosstest.servercore.MapGeneratorException; - -// TODO: Auto-generated Javadoc -/** - * The Interface IMapGenerator. - */ -public interface IMapGenerator { - - /** - * Inits the. - * - * @param seed the seed - * @param nm the nm - * @param params the params - * @throws MapGeneratorException the map generator exception - */ - void init(long seed, INodeManager nm, Object... params) throws MapGeneratorException; - - /** - * Generate chunk. - * - * @param pos the pos - * @return the map chunk - * @throws MapGeneratorException the map generator exception - */ - public MapChunk generateChunk(Position pos) throws MapGeneratorException; - - /** - * Fills in a chunk as an array of light nodes, where 0 values require - * filling. - * - * @param lightNodes - * A reference to the array that must be updated. - * @param pos - * The position corresponding to the chunk to be filled in. - * @throws MapGeneratorException - * Thrown in case the map generator encounters an inconsistency - * it cannot recover from. - */ - public void fillInChunk(int[][][] lightNodes, Position pos) - throws MapGeneratorException; - - /** - * Register an ore for future generation of chunks. The values given here - * are hints to the map generator and need not be exact. - * - * @param oreNode The ore to generate. - * @param minDepth The minimum depth(as a positive integer number of nodes below - * sea level. - * @param rarity How rare the ore should be. Rarity 1 corresponds to virtually - * every ore-containing node, and rarity 100 would correspond to - * approximately one out of 100 nodes being this ore. - * @param clumping Defines how clumped the ore should be. Generally corresponds - * to 0=uniform and 1=most strongly clumped(solid spheres of ore - * clumps to meet rarity goal) - * @param seed the seed - * @param params Miscellaneous params for the map generator. - */ - public void registerOre(MapNode oreNode, double minDepth, double rarity, - double clumping, int seed, Object... params); - - -} +package net.mosstest.scripting; + +import net.mosstest.servercore.INodeManager; +import net.mosstest.servercore.MapGeneratorException; + +// TODO: Auto-generated Javadoc +/** + * The Interface IMapGenerator. + */ +public interface IMapGenerator { + + /** + * Inits the. + * + * @param seed the seed + * @param nm the nm + * @param params the params + * @throws MapGeneratorException the map generator exception + */ + void init(long seed, INodeManager nm, Object... params) throws MapGeneratorException; + + /** + * Generate chunk. + * + * @param pos the pos + * @return the map chunk + * @throws MapGeneratorException the map generator exception + */ + public MapChunk generateChunk(Position pos) throws MapGeneratorException; + + /** + * Fills in a chunk as an array of light nodes, where 0 values require + * filling. + * + * @param lightNodes + * A reference to the array that must be updated. + * @param pos + * The position corresponding to the chunk to be filled in. + * @throws MapGeneratorException + * Thrown in case the map generator encounters an inconsistency + * it cannot recover from. + */ + public void fillInChunk(int[][][] lightNodes, Position pos) + throws MapGeneratorException; + + /** + * Register an ore for future generation of chunks. The values given here + * are hints to the map generator and need not be exact. + * + * @param oreNode The ore to generate. + * @param minDepth The minimum depth(as a positive integer number of nodes below + * sea level. + * @param rarity How rare the ore should be. Rarity 1 corresponds to virtually + * every ore-containing node, and rarity 100 would correspond to + * approximately one out of 100 nodes being this ore. + * @param clumping Defines how clumped the ore should be. Generally corresponds + * to 0=uniform and 1=most strongly clumped(solid spheres of ore + * clumps to meet rarity goal) + * @param seed the seed + * @param params Miscellaneous params for the map generator. + */ + public void registerOre(MapNode oreNode, double minDepth, double rarity, + double clumping, int seed, Object... params); + + +} diff --git a/src/net/mosstest/scripting/MapChunk.java b/src/net/mosstest/scripting/MapChunk.java index 6d9a5fc..a208d0d 100644 --- a/src/net/mosstest/scripting/MapChunk.java +++ b/src/net/mosstest/scripting/MapChunk.java @@ -1,224 +1,224 @@ -package net.mosstest.scripting; - -import net.mosstest.servercore.*; -import net.mosstest.servercore.Messages; -import org.apache.log4j.Logger; - -import java.io.*; -import java.util.Arrays; - -// TODO: Auto-generated Javadoc - -/** - * The Class MapChunk. - */ -public class MapChunk extends AbstractMapChunk { - public static final Logger logger = Logger.getLogger(MapChunk.class); - public static final int IS_CHANGED_MASK = 16384; - public static final int UNSIGNED_IDENTITY_MASK = 0b0011111111111111; - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - MapChunk mapChunk = (MapChunk) o; - - if (!pos.equals(mapChunk.pos)) return false; - - return true; - } - - @Override - public int hashCode() { - return pos.hashCode(); - } - - /** - * The pos. - */ - public Position pos; - - /** - * The light nodes. - */ - int[][][] lightNodes = new int[CHUNK_DIMENSION][CHUNK_DIMENSION][CHUNK_DIMENSION]; - - - boolean compressed; - - - static final int MAPCHUNK_SERIALIZATION_VERSION = 2; - - - /** - * Instantiates a new map chunk. - * - * - * - * @param light the primary data storage - * @throws IOException Signals that an I/O exception has occurred. - */ - public MapChunk(byte[] light) - throws IOException { - loadBytes_(light); - - } - - @Override - protected void setManager(Void manager) { - // This is a void here, ergo we can just return - return; - } - - public void loadBytes_(byte[] light) throws IOException { - //Arrays.copyOf(light, light.length); - try (DataInputStream lightStreamIn = new DataInputStream( - new ByteArrayInputStream(light))) { - int flags = lightStreamIn.readUnsignedShort(); - int version = lightStreamIn.readUnsignedShort(); - - if (version > MAPCHUNK_SERIALIZATION_VERSION) - ExceptionHandler.registerException(new MossWorldLoadException( - Messages.getString("MapChunk.BAD_SER_VER"))); //$NON-NLS-1$ - byte[] posBuf = new byte[Position.SERIALIZED_LENGTH]; - // side effect of reading into buffer - lightStreamIn.read(posBuf); - - this.pos = new Position(posBuf); - /* - * flags short: 1=TODO - * 2=none yet 4=run-length diff compression - * (not implemented yet) 8...=reserved - */ - - this.compressed = (((flags & 0x04)) != 0); - if (this.compressed) { - int cursor = 0; - // Below comment for IntelliJ Idea. This is the primary side effect of this method - //noinspection MismatchedReadAndWriteOfArray - int[] lightTmp = new int[CHUNK_DIMENSION * CHUNK_DIMENSION * CHUNK_DIMENSION]; - while (lightStreamIn.available() > 0) { - int curShort = lightStreamIn.readUnsignedShort(); - if ((curShort & IS_CHANGED_MASK) != 0) { - lightTmp[cursor] = curShort; - cursor++; - } else { - if ((curShort & IS_CHANGED_MASK) != 0) { - for (int i = 0; i < (curShort & UNSIGNED_IDENTITY_MASK); i++) { - lightTmp[cursor] = 0; - cursor++; - } - } - } - } - try { - MapGenerators.getDefaultMapgen().fillInChunk(this.lightNodes, - pos); - } catch (MapGeneratorException e) { - // pass, we'll deal with a bad chunk later in the pipeline - } - // throw new NotImplementedException(); - } else { - for (int x = 0; x < CHUNK_DIMENSION; x++) { - for (int y = 0; y < CHUNK_DIMENSION; y++) { - for (int z = 0; z < CHUNK_DIMENSION; z++) { - this.lightNodes[x][y][z] = lightStreamIn.readShort(); - } - } - } - } - } - } - - private void loadHeavy(byte[] heavy) { - - } - - - /** - * Instantiates a new map chunk. - * - * @param pos2 the pos2 - * @param nodes the nodes - */ - public MapChunk(Position pos2, int[][][] nodes) { - this.pos = pos2; - this.lightNodes = Arrays.copyOf(nodes, nodes.length); - - } - - /** - * Gets the node id. - * - * @param x the x - * @param y the y - * @param z the z - * @return the node id - */ - @Override - public int getNodeId(byte x, byte y, byte z) { - return this.lightNodes[x][y][z]; - } - - /** - * Updates the chunk to set a node. The chunk is not written to the database - * or committed across the network. - * - * @param x the x - * @param y the y - * @param z the z - * @param node the node - */ - @Override - public void setNode(byte x, byte y, byte z, short node) { - this.lightNodes[x][y][z] = node; - } - - @Override - public int[][][] getNodes() { - return this.lightNodes; - } - - @Override - public byte[] writeLight(boolean compressed) { - - ByteArrayOutputStream bos = new ByteArrayOutputStream(); - - try (DataOutputStream dos = new DataOutputStream(bos)) { - dos.writeShort(0); - dos.writeShort(MAPCHUNK_SERIALIZATION_VERSION); - dos.write(this.pos.toBytes()); - for (int[][] nodelvl : this.lightNodes) { - for (int[] nodelvl2 : nodelvl) { - for (int node : nodelvl2) { - dos.writeShort(node); - } - } - } - dos.flush(); - bos.flush(); - } catch (IOException e) { - // should never happen - logger.warn("IOException writing light chunk data"); - } - - return bos.toByteArray(); - } - - @Override - public void compact() { - // noop in this version. Later versions may compact. - } - - @Override - public byte[] toBytes() { - return this.writeLight(true); - } - - @Override - public void loadBytes(byte[] buf) throws IOException{ - // delegate to internal implementation - this.loadBytes_(buf); - } -} +package net.mosstest.scripting; + +import net.mosstest.servercore.*; +import net.mosstest.servercore.Messages; +import org.apache.log4j.Logger; + +import java.io.*; +import java.util.Arrays; + +// TODO: Auto-generated Javadoc + +/** + * The Class MapChunk. + */ +public class MapChunk extends AbstractMapChunk { + public static final Logger logger = Logger.getLogger(MapChunk.class); + public static final int IS_CHANGED_MASK = 16384; + public static final int UNSIGNED_IDENTITY_MASK = 0b0011111111111111; + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + MapChunk mapChunk = (MapChunk) o; + + if (!pos.equals(mapChunk.pos)) return false; + + return true; + } + + @Override + public int hashCode() { + return pos.hashCode(); + } + + /** + * The pos. + */ + public Position pos; + + /** + * The light nodes. + */ + int[][][] lightNodes = new int[CHUNK_DIMENSION][CHUNK_DIMENSION][CHUNK_DIMENSION]; + + + boolean compressed; + + + static final int MAPCHUNK_SERIALIZATION_VERSION = 2; + + + /** + * Instantiates a new map chunk. + * + * + * + * @param light the primary data storage + * @throws IOException Signals that an I/O exception has occurred. + */ + public MapChunk(byte[] light) + throws IOException { + loadBytes_(light); + + } + + @Override + protected void setManager(Void manager) { + // This is a void here, ergo we can just return + return; + } + + public void loadBytes_(byte[] light) throws IOException { + //Arrays.copyOf(light, light.length); + try (DataInputStream lightStreamIn = new DataInputStream( + new ByteArrayInputStream(light))) { + int flags = lightStreamIn.readUnsignedShort(); + int version = lightStreamIn.readUnsignedShort(); + + if (version > MAPCHUNK_SERIALIZATION_VERSION) + ExceptionHandler.registerException(new MossWorldLoadException( + Messages.getString("MapChunk.BAD_SER_VER"))); //$NON-NLS-1$ + byte[] posBuf = new byte[Position.SERIALIZED_LENGTH]; + // side effect of reading into buffer + lightStreamIn.read(posBuf); + + this.pos = new Position(posBuf); + /* + * flags short: 1=TODO + * 2=none yet 4=run-length diff compression + * (not implemented yet) 8...=reserved + */ + + this.compressed = (((flags & 0x04)) != 0); + if (this.compressed) { + int cursor = 0; + // Below comment for IntelliJ Idea. This is the primary side effect of this method + //noinspection MismatchedReadAndWriteOfArray + int[] lightTmp = new int[CHUNK_DIMENSION * CHUNK_DIMENSION * CHUNK_DIMENSION]; + while (lightStreamIn.available() > 0) { + int curShort = lightStreamIn.readUnsignedShort(); + if ((curShort & IS_CHANGED_MASK) != 0) { + lightTmp[cursor] = curShort; + cursor++; + } else { + if ((curShort & IS_CHANGED_MASK) != 0) { + for (int i = 0; i < (curShort & UNSIGNED_IDENTITY_MASK); i++) { + lightTmp[cursor] = 0; + cursor++; + } + } + } + } + try { + MapGenerators.getDefaultMapgen().fillInChunk(this.lightNodes, + pos); + } catch (MapGeneratorException e) { + // pass, we'll deal with a bad chunk later in the pipeline + } + // throw new NotImplementedException(); + } else { + for (int x = 0; x < CHUNK_DIMENSION; x++) { + for (int y = 0; y < CHUNK_DIMENSION; y++) { + for (int z = 0; z < CHUNK_DIMENSION; z++) { + this.lightNodes[x][y][z] = lightStreamIn.readShort(); + } + } + } + } + } + } + + private void loadHeavy(byte[] heavy) { + + } + + + /** + * Instantiates a new map chunk. + * + * @param pos2 the pos2 + * @param nodes the nodes + */ + public MapChunk(Position pos2, int[][][] nodes) { + this.pos = pos2; + this.lightNodes = Arrays.copyOf(nodes, nodes.length); + + } + + /** + * Gets the node id. + * + * @param x the x + * @param y the y + * @param z the z + * @return the node id + */ + @Override + public int getNodeId(byte x, byte y, byte z) { + return this.lightNodes[x][y][z]; + } + + /** + * Updates the chunk to set a node. The chunk is not written to the database + * or committed across the network. + * + * @param x the x + * @param y the y + * @param z the z + * @param node the node + */ + @Override + public void setNode(byte x, byte y, byte z, short node) { + this.lightNodes[x][y][z] = node; + } + + @Override + public int[][][] getNodes() { + return this.lightNodes; + } + + @Override + public byte[] writeLight(boolean compressed) { + + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + + try (DataOutputStream dos = new DataOutputStream(bos)) { + dos.writeShort(0); + dos.writeShort(MAPCHUNK_SERIALIZATION_VERSION); + dos.write(this.pos.toBytes()); + for (int[][] nodelvl : this.lightNodes) { + for (int[] nodelvl2 : nodelvl) { + for (int node : nodelvl2) { + dos.writeShort(node); + } + } + } + dos.flush(); + bos.flush(); + } catch (IOException e) { + // should never happen + logger.warn("IOException writing light chunk data"); + } + + return bos.toByteArray(); + } + + @Override + public void compact() { + // noop in this version. Later versions may compact. + } + + @Override + public byte[] toBytes() { + return this.writeLight(true); + } + + @Override + public void loadBytes(byte[] buf) throws IOException{ + // delegate to internal implementation + this.loadBytes_(buf); + } +} diff --git a/src/net/mosstest/scripting/MapGenerators.java b/src/net/mosstest/scripting/MapGenerators.java index 8efaf0c..1496b1a 100644 --- a/src/net/mosstest/scripting/MapGenerators.java +++ b/src/net/mosstest/scripting/MapGenerators.java @@ -1,46 +1,46 @@ -package net.mosstest.scripting; - -import net.mosstest.servercore.INodeManager; -import net.mosstest.servercore.MapGeneratorException; - -// TODO: Auto-generated Javadoc - -/** - * The Class MapGenerators. - */ -public class MapGenerators { - - public static final int CHUNK_DIMENSION = 16; - /** - * The mg. - */ - private static volatile IMapGenerator mg; - - /** - * Sets the default map generator. - * - * @param g the g - * @param nm the nm - * @param seed the seed - * @param params the params - * @throws MapGeneratorException the map generator exception - */ - public static void setDefaultMapGenerator(IMapGenerator g, INodeManager nm, long seed, - Object... params) throws MapGeneratorException { - synchronized (MapGenerators.class) { - mg = g; - mg.init(seed, nm, params); - } - } - - /** - * Gets the default mapgen. - * - * @return the default mapgen - */ - public static IMapGenerator getDefaultMapgen() { - return mg; - } - - -} +package net.mosstest.scripting; + +import net.mosstest.servercore.INodeManager; +import net.mosstest.servercore.MapGeneratorException; + +// TODO: Auto-generated Javadoc + +/** + * The Class MapGenerators. + */ +public class MapGenerators { + + public static final int CHUNK_DIMENSION = 16; + /** + * The mg. + */ + private static volatile IMapGenerator mg; + + /** + * Sets the default map generator. + * + * @param g the g + * @param nm the nm + * @param seed the seed + * @param params the params + * @throws MapGeneratorException the map generator exception + */ + public static void setDefaultMapGenerator(IMapGenerator g, INodeManager nm, long seed, + Object... params) throws MapGeneratorException { + synchronized (MapGenerators.class) { + mg = g; + mg.init(seed, nm, params); + } + } + + /** + * Gets the default mapgen. + * + * @return the default mapgen + */ + public static IMapGenerator getDefaultMapgen() { + return mg; + } + + +} diff --git a/src/net/mosstest/scripting/MapNodeBuilder.java b/src/net/mosstest/scripting/MapNodeBuilder.java index 13dcde7..203364c 100644 --- a/src/net/mosstest/scripting/MapNodeBuilder.java +++ b/src/net/mosstest/scripting/MapNodeBuilder.java @@ -1,60 +1,60 @@ -package net.mosstest.scripting; - -import net.mosstest.scripting.MapNode.DrawType; - -// TODO: Auto-generated Javadoc -/** - * The Class MapNodeBuilder. - */ -public class MapNodeBuilder { - - /** The name. */ - private String name; - - /** The ui name. */ - private String uiName; - - /** The params. */ - private INodeParams params; - - /** The light emission. */ - private int lightEmission = 0; - - /** The drop item. */ - private MossItem dropItem; - - /** The is buildable to. */ - private boolean isBuildableTo = true; - - /** The draw type. */ - private DrawType drawType = DrawType.DRAW_BLOCK; - - /** The box origin z. */ - private float boxOriginX = 0, boxOriginY = 0, boxOriginZ = 0; - - /** The length z. */ - private float lengthX = 0.5f, lengthY = 0.5f, lengthZ = 0.5f; - - /** - * Instantiates a new map node builder. - * - * @param name the name - * @param uiName the ui name - */ - public MapNodeBuilder(String name, String uiName) { - this.name = name; - this.uiName = uiName; - } - - /** - * Params. - * - * @param params the params - * @return the map node builder - */ - public MapNodeBuilder params(INodeParams params) { - this.params = params; - return this; - } - -} +package net.mosstest.scripting; + +import net.mosstest.scripting.MapNode.DrawType; + +// TODO: Auto-generated Javadoc +/** + * The Class MapNodeBuilder. + */ +public class MapNodeBuilder { + + /** The name. */ + private String name; + + /** The ui name. */ + private String uiName; + + /** The params. */ + private INodeParams params; + + /** The light emission. */ + private int lightEmission = 0; + + /** The drop item. */ + private MossItem dropItem; + + /** The is buildable to. */ + private boolean isBuildableTo = true; + + /** The draw type. */ + private DrawType drawType = DrawType.DRAW_BLOCK; + + /** The box origin z. */ + private float boxOriginX = 0, boxOriginY = 0, boxOriginZ = 0; + + /** The length z. */ + private float lengthX = 0.5f, lengthY = 0.5f, lengthZ = 0.5f; + + /** + * Instantiates a new map node builder. + * + * @param name the name + * @param uiName the ui name + */ + public MapNodeBuilder(String name, String uiName) { + this.name = name; + this.uiName = uiName; + } + + /** + * Params. + * + * @param params the params + * @return the map node builder + */ + public MapNodeBuilder params(INodeParams params) { + this.params = params; + return this; + } + +} diff --git a/src/net/mosstest/scripting/Messages.java b/src/net/mosstest/scripting/Messages.java index 4b6dfdd..635ecf9 100644 --- a/src/net/mosstest/scripting/Messages.java +++ b/src/net/mosstest/scripting/Messages.java @@ -1,47 +1,47 @@ -package net.mosstest.scripting; - -import java.util.MissingResourceException; -import java.util.ResourceBundle; - -// TODO: Auto-generated Javadoc -/** - * The Class Messages. - */ -public class Messages { - - /** The Constant BUNDLE_NAME. */ - private static final String BUNDLE_NAME = "net.mosstest.scripting.messages"; //$NON-NLS-1$ - - /** The res bundle. */ - private static ResourceBundle resBundle = ResourceBundle - .getBundle(BUNDLE_NAME); - - /** - * Change language. - * - * @param identifier the identifier - */ - public static void changeLanguage(String identifier) { - resBundle = ResourceBundle.getBundle(BUNDLE_NAME + "." + identifier); - } - - /** - * Instantiates a new messages. - */ - private Messages() { - } - - /** - * Gets the string. - * - * @param key the key - * @return the string - */ - public static String getString(String key) { - try { - return resBundle.getString(key); - } catch (MissingResourceException e) { - return '!' + key + '!'; - } - } +package net.mosstest.scripting; + +import java.util.MissingResourceException; +import java.util.ResourceBundle; + +// TODO: Auto-generated Javadoc +/** + * The Class Messages. + */ +public class Messages { + + /** The Constant BUNDLE_NAME. */ + private static final String BUNDLE_NAME = "net.mosstest.scripting.messages"; //$NON-NLS-1$ + + /** The res bundle. */ + private static ResourceBundle resBundle = ResourceBundle + .getBundle(BUNDLE_NAME); + + /** + * Change language. + * + * @param identifier the identifier + */ + public static void changeLanguage(String identifier) { + resBundle = ResourceBundle.getBundle(BUNDLE_NAME + "." + identifier); + } + + /** + * Instantiates a new messages. + */ + private Messages() { + } + + /** + * Gets the string. + * + * @param key the key + * @return the string + */ + public static String getString(String key) { + try { + return resBundle.getString(key); + } catch (MissingResourceException e) { + return '!' + key + '!'; + } + } } \ No newline at end of file diff --git a/src/net/mosstest/scripting/MossItemBuilder.java b/src/net/mosstest/scripting/MossItemBuilder.java index 9810ae1..081b14e 100644 --- a/src/net/mosstest/scripting/MossItemBuilder.java +++ b/src/net/mosstest/scripting/MossItemBuilder.java @@ -1,68 +1,68 @@ -package net.mosstest.scripting; - -public class MossItemBuilder { - private String invTex; - private String wieldTex; - private double invWeight; - private MossItem.StackMode mayStack = MossItem.StackMode.STACK_UNIT; - private String displayName; - private String internalName; - - public MossItemBuilder setInvTex(String invTex) { - this.invTex = invTex; - return this; - } - - public MossItemBuilder setWieldTex(String wieldTex) { - this.wieldTex = wieldTex; - return this; - } - - public MossItemBuilder setInvWeight(double invWeight) { - this.invWeight = invWeight; - return this; - } - - public String getInvTex() { - return invTex; - } - - public String getWieldTex() { - return wieldTex; - } - - public double getInvWeight() { - return invWeight; - } - - public MossItem.StackMode getStackMode() { - return mayStack; - } - - public MossItemBuilder setStackMode(MossItem.StackMode mayStack) { - this.mayStack = mayStack; - return this; - } - - public String getDisplayName() { - return displayName; - } - - public String getInternalName() { - return internalName; - } - - public MossItemBuilder setDisplayName(String displayName) { - this.displayName = displayName; - return this; - } - - public MossItemBuilder setInternalName(String internalName) { - this.internalName = internalName; - return this; - } - - public MossItem createMossItem() { - return new MossItem(invTex, wieldTex, invWeight, mayStack, displayName, internalName); - } +package net.mosstest.scripting; + +public class MossItemBuilder { + private String invTex; + private String wieldTex; + private double invWeight; + private MossItem.StackMode mayStack = MossItem.StackMode.STACK_UNIT; + private String displayName; + private String internalName; + + public MossItemBuilder setInvTex(String invTex) { + this.invTex = invTex; + return this; + } + + public MossItemBuilder setWieldTex(String wieldTex) { + this.wieldTex = wieldTex; + return this; + } + + public MossItemBuilder setInvWeight(double invWeight) { + this.invWeight = invWeight; + return this; + } + + public String getInvTex() { + return invTex; + } + + public String getWieldTex() { + return wieldTex; + } + + public double getInvWeight() { + return invWeight; + } + + public MossItem.StackMode getStackMode() { + return mayStack; + } + + public MossItemBuilder setStackMode(MossItem.StackMode mayStack) { + this.mayStack = mayStack; + return this; + } + + public String getDisplayName() { + return displayName; + } + + public String getInternalName() { + return internalName; + } + + public MossItemBuilder setDisplayName(String displayName) { + this.displayName = displayName; + return this; + } + + public MossItemBuilder setInternalName(String internalName) { + this.internalName = internalName; + return this; + } + + public MossItem createMossItem() { + return new MossItem(invTex, wieldTex, invWeight, mayStack, displayName, internalName); + } } \ No newline at end of file diff --git a/src/net/mosstest/scripting/MossScriptEnv.java b/src/net/mosstest/scripting/MossScriptEnv.java index e8335bb..cfb19ee 100644 --- a/src/net/mosstest/scripting/MossScriptEnv.java +++ b/src/net/mosstest/scripting/MossScriptEnv.java @@ -1,320 +1,321 @@ -package net.mosstest.scripting; - -import net.mosstest.scripting.events.IMossEvent; -import net.mosstest.scripting.handlers.MossEventHandler; -import net.mosstest.scripting.handlers.MossNodeChangeHandler; -import net.mosstest.servercore.*; - -import java.util.ArrayList; -import java.util.HashMap; - -/** - * This class is used by scripts and script-facing portions of Mosstest. Methods - * restricted to be called from trusted Java-side shall pass a - * {@link ScriptSandboxBorderToken}. Each event fired will run in the thread - * pool. All requests via this API need not concern themselves with threading as - * everything is handled by Mosstest itself. - *

- * The event handlers called are the ones defined via this class's registerOnFoo - * methods, followed by any handlers defined in an instance of NodeParams via an - * anonymous inner class, and finally with the default handler. - *

- * The order in which handlers registered here are called is undefined due to - * the undefined order of scripts being loaded. Generally, this is planned to - * occur in an order based on the SHA512 hash of the script. Comments with dummy - * information may be used by the script author to attempt to set the position - * of a script in the execution order via manipulating the hash. Handlers of the - * same types within the same script are guaranteed to be called in order. - *

- * An event handler may interrupt handling of the event so that no further event - * handlers nor the default are ever called, by returning the proper boolean value - * - * @author rarkenin - * @version 0.0 - * @since 0.0 - */ -public class MossScriptEnv { - - public void registerNodeChangeHandler(MossNodeChangeHandler h) { - - } - - - private HashMap, ArrayList> eventHandlers; - - private ScriptableDatabase db; - - private MapCache nc; - - private FuturesProcessor fp; - - private INodeManager nm; - - - /** - * Sends a chat message to a player. - * - * @param recipient A {@link Player} object representing the recipient. A Player - * object may be constructed with - * {@link MossScriptEnv#getPlayerByName(String)}. - * @param from A player object representing the sender. A Player object may - * be constructed with - * {@link MossScriptEnv#getPlayerByName(String)}. If null a - * message is sent showing to users as having been sent by the - * server with the prefix [*] Server: - * @param message A string representing the message that shall be sent to the - * specified recipient. - */ - public void sendChatMessage(Player recipient, Player from, String message) { - // TODO - } - - /** - * Sends a chat message to all players. - * - * @param from A player object representing the sender. A Player object may - * be constructed with - * {@link MossScriptEnv#getPlayerByName(String)}. If null a - * message is sent showing to users as having been sent by the - * server with the prefix [*] Server: - * @param message A string representing the message that shall be sent to the - * specified recipient. - */ - public void sendChatAll(Player from, String message) { - // TODO - } - - /** - * Sets the health on an entity or player. - * - * @param p The player to set health on. - * @param health A positive integer representing the amount of health to set. - */ - public void setHp(Player p, int health) { - // TODO Once we have players doing stuff - } - - /** - * Damages the tool of a player corresponding to a dig. The player's - * currently selected tool is damaged. - * - * @param actor The player that is digging a node. - * @param nd The node dug. - * @throws MossScriptException Thrown if the current tool cannot be used to dig the node. - */ - public void damageTool(Player actor, MapNode nd) throws MossScriptException { - // TODO Auto-generated method stub - - } - - /** - * Gives a player an item. The item stack will be added to the player's - * default inventory, adding to the first available partial stack. If no - * partial stacks are available the item is added to the first open slot in - * the inventory. - * - * @param player the player - * @param item the item - * @return True if the item could be added, false if the item could not be - * added due to insufficient space. - */ - public boolean givePlayer(Player player, MossItem.Stack item) { - MossInventory mi = player.getInventory("default", 4, 8, 128); - - // use side effect - return (mi.addItem(item) == item.amount); - - } - - /** - * Sets a node of the world to a given type. This cannot be called on a - * NodePosition with an existing solid node; use - * {@link #removeNode(NodePosition)} first. - * - * @param pos The position at which to set a node. - * @param node The node to place at that position. - */ - public void setNode(NodePosition pos, MapNode node) throws MapGeneratorException { - MapChunk chk = this.nc.getChunkNoGenerate(pos.chunk); - if (chk == null) - return; - if (!(this.nm.containsNode(node) || node instanceof IDynamicNode)) - throw new IllegalArgumentException("The mapnode passed is not contained in the world node manager"); - - chk.setNode(pos.xl, pos.yl, pos.zl, node.getNodeId()); - } - - /** - * Removes a node, setting it to air. This may be called on a NodePosition - * with an existing solid node. - * - * @param pos The NodePosition at which to remove the node. - */ - public void removeNode(NodePosition pos) throws MapGeneratorException { - MapChunk chk = this.nc.getChunkNoGenerate(pos.chunk); - if (chk == null) - return; - chk.setNode(pos.xl, pos.yl, pos.zl, this.nm.getNode("mg:air") //$NON-NLS-1$ - .getNodeId()); - this.nc.setChunk(pos.chunk, chk); - } - - /** - * Get the MapNode at a certain location. - * - * @param pos The location at which to get the node - * @return A MapNode object representing the node at that location. - * @throws MapGeneratorException the map generator exception - */ - public MapNode getNode(NodePosition pos) throws MapGeneratorException { - return this.nm.getNode((short) this.nc.getChunk(pos.chunk).getNodeId( - pos.xl, pos.yl, pos.zl)); - - } - - /** - * Registers a mapnode in the world, allowing it to be placed. - * @param nd - * @throws MossWorldLoadException - */ - public void registerNode(MapNode nd) throws MossWorldLoadException { - this.nm.putNode(nd); - } - - /** - * Register a new liquid in the node manager, generating intermediates as needed. - * - * @param sysname The name such as default:lava to set. The prefix mg: is used - * for mapgen-specific nodes, and should be done by creating a - * node with a different prefix and aliasing mg:foo to it. - * @param userFacingName The name to display in the UI, such as Lava or Iron Ore - * @param params An implementation of the {@link LiquidNodeParams} interface - * detailing the action of the node. {@link LiquidSourceNodeParams} and - * {@link LiquidFlowingNodeParams} are valid for liquid sources and flowing liquid nodes, - * respectively. - * @param flowParams the source params - * @param textures A string stating the filename of the textures image. - * @param light The amount of light from 0 to 255 to be emitted. - * @return The MapNode object that has been created and added to the - * manager. - * @throws MossWorldLoadException If an exception occurs during the execution of the - * registering. - */ - public LiquidNode registerLiquid(String sysname, String userFacingName, - LiquidNodeParams params, LiquidNodeParams flowParams, - String textures, int light) throws MossWorldLoadException { - LiquidNode nd = new LiquidNode(params, textures, sysname, - userFacingName, light); - this.nm.putNode(nd); - nd.level = 0; - for (int i = 1; i < 8; i++) { - LiquidNode innerNd = new LiquidNode(flowParams, textures, sysname - + "$LEVEL$" + i, userFacingName, light); //$NON-NLS-1$ - innerNd.setByBounds(-.5f, .5f, -.5f, .5f, -.5f, (i / 8f) - 0.5f); - nd.liquidLevels[i] = innerNd; - innerNd.liquidLevels = nd.liquidLevels; - innerNd.level = i; - this.nm.putNode(innerNd); - } - nd.liquidLevels[0] = nd; - return nd; - } - - /** - * Registers a node alias. Since the map generator and scripts work via - * string names, registering an alias of mg:dirt to myscript:specialdirt - * will cause a mapgen that recognizes mg:dirt as a generated element to use - * specialdirt for that. - * - * @param alias The alias to create, i.e. mg:dirt - * @param dst The existing node to set as the alias target, i.e - * myscript:specialdirt. This element must already exist. - */ - public void registerNodeAlias(String alias, String dst) { - this.nm.putNodeAlias(alias, dst); - } - - - /** - * Gets the inv by name. - * - * @param player the player - * @param name the name - * @return the inv by name - */ - public MossInventory getInvByName(Player player, String name) { - return null; - } - - /** - * Creates the inv by name. - * - * @param p the p - * @param name the name - * @return the moss inventory - */ - public MossInventory createInvByName(Player p, String name) { - return null; - } - - /** - * Gets the player by name. - * - * @param name the name - * @return the player by name - */ - public Player getPlayerByName(String name) { - return null; - } - - /** - * Gets the node by name. - * - * @param name the name - * @return the node by name - */ - public MapNode getNodeByName(String name) { - return null; - } - - /** - * Gets the db. - * - * @return the db - */ - public ScriptableDatabase getDb() { - return this.db; - } - - /** - * Instantiates a new moss script env. - * - * @param db the db - * @param nc the nc - * @param fp the fp - * @param nm the nm - */ - public MossScriptEnv(ScriptableDatabase db, MapCache nc, - FuturesProcessor fp, INodeManager nm) { - this.db = db; - this.nc = nc; - this.fp = fp; - this.nm = nm; - } - - /** - * Gets the futures processor. - * - * @return the futures processor - */ - public FuturesProcessor getFuturesProcessor() { - return this.fp; - } - - public ArrayList getEventHandlers( - Class class1) { - // TODO Auto-generated method stub - return null; - } - -} +package net.mosstest.scripting; + +import net.mosstest.scripting.events.IMossEvent; +import net.mosstest.scripting.handlers.MossEventHandler; +import net.mosstest.scripting.handlers.MossNodeChangeHandler; +import net.mosstest.servercore.*; +import org.mozilla.javascript.NativeJavaPackage; + +import java.util.ArrayList; +import java.util.HashMap; + +/** + * This class is used by scripts and script-facing portions of Mosstest. Methods + * restricted to be called from trusted Java-side shall pass a + * {@link ScriptSandboxBorderToken}. Each event fired will run in the thread + * pool. All requests via this API need not concern themselves with threading as + * everything is handled by Mosstest itself. + *

+ * The event handlers called are the ones defined via this class's registerOnFoo + * methods, followed by any handlers defined in an instance of NodeParams via an + * anonymous inner class, and finally with the default handler. + *

+ * The order in which handlers registered here are called is undefined due to + * the undefined order of scripts being loaded. Generally, this is planned to + * occur in an order based on the SHA512 hash of the script. Comments with dummy + * information may be used by the script author to attempt to set the position + * of a script in the execution order via manipulating the hash. Handlers of the + * same types within the same script are guaranteed to be called in order. + *

+ * An event handler may interrupt handling of the event so that no further event + * handlers nor the default are ever called, by returning the proper boolean value + * + * @author rarkenin + * @version 0.0 + * @since 0.0 + */ +public class MossScriptEnv { + + public void registerNodeChangeHandler(MossNodeChangeHandler h) { + + } + + + private HashMap, ArrayList> eventHandlers; + + private ScriptableDatabase db; + + private MapCache nc; + + private FuturesProcessor fp; + + private INodeManager nm; + + + /** + * Sends a chat message to a player. + * + * @param recipient A {@link Player} object representing the recipient. A Player + * object may be constructed with + * {@link MossScriptEnv#getPlayerByName(String)}. + * @param from A player object representing the sender. A Player object may + * be constructed with + * {@link MossScriptEnv#getPlayerByName(String)}. If null a + * message is sent showing to users as having been sent by the + * server with the prefix [*] Server: + * @param message A string representing the message that shall be sent to the + * specified recipient. + */ + public void sendChatMessage(Player recipient, Player from, String message) { + // TODO + } + + /** + * Sends a chat message to all players. + * + * @param from A player object representing the sender. A Player object may + * be constructed with + * {@link MossScriptEnv#getPlayerByName(String)}. If null a + * message is sent showing to users as having been sent by the + * server with the prefix [*] Server: + * @param message A string representing the message that shall be sent to the + * specified recipient. + */ + public void sendChatAll(Player from, String message) { + // TODO + } + + /** + * Sets the health on an entity or player. + * + * @param p The player to set health on. + * @param health A positive integer representing the amount of health to set. + */ + public void setHp(Player p, int health) { + // TODO Once we have players doing stuff + } + + /** + * Damages the tool of a player corresponding to a dig. The player's + * currently selected tool is damaged. + * + * @param actor The player that is digging a node. + * @param nd The node dug. + * @throws MossScriptException Thrown if the current tool cannot be used to dig the node. + */ + public void damageTool(Player actor, MapNode nd) throws MossScriptException { + // TODO Auto-generated method stub + + } + + /** + * Gives a player an item. The item stack will be added to the player's + * default inventory, adding to the first available partial stack. If no + * partial stacks are available the item is added to the first open slot in + * the inventory. + * + * @param player the player + * @param item the item + * @return True if the item could be added, false if the item could not be + * added due to insufficient space. + */ + public boolean givePlayer(Player player, MossItem.Stack item) { + MossInventory mi = player.getInventory("default", 4, 8, 128); + + // use side effect + return (mi.addItem(item) == item.amount); + + } + + /** + * Sets a node of the world to a given type. This cannot be called on a + * NodePosition with an existing solid node; use + * {@link #removeNode(NodePosition)} first. + * + * @param pos The position at which to set a node. + * @param node The node to place at that position. + */ + public void setNode(NodePosition pos, MapNode node) throws MapGeneratorException { + MapChunk chk = this.nc.getChunkNoGenerate(pos.chunk); + if (chk == null) + return; + if (!(this.nm.containsNode(node) || node instanceof IDynamicNode)) + throw new IllegalArgumentException("The mapnode passed is not contained in the world node manager"); + + chk.setNode(pos.xl, pos.yl, pos.zl, node.getNodeId()); + } + + /** + * Removes a node, setting it to air. This may be called on a NodePosition + * with an existing solid node. + * + * @param pos The NodePosition at which to remove the node. + */ + public void removeNode(NodePosition pos) throws MapGeneratorException { + MapChunk chk = this.nc.getChunkNoGenerate(pos.chunk); + if (chk == null) + return; + chk.setNode(pos.xl, pos.yl, pos.zl, this.nm.getNode("mg:air") //$NON-NLS-1$ + .getNodeId()); + this.nc.setChunk(pos.chunk, chk); + } + + /** + * Get the MapNode at a certain location. + * + * @param pos The location at which to get the node + * @return A MapNode object representing the node at that location. + * @throws MapGeneratorException the map generator exception + */ + public MapNode getNode(NodePosition pos) throws MapGeneratorException { + return this.nm.getNode((short) this.nc.getChunk(pos.chunk).getNodeId( + pos.xl, pos.yl, pos.zl)); + + } + + /** + * Registers a mapnode in the world, allowing it to be placed. + * @param nd + * @throws MossWorldLoadException + */ + public void registerNode(MapNode nd) throws MossWorldLoadException { + this.nm.putNode(nd); + } + + /** + * Register a new liquid in the node manager, generating intermediates as needed. + * + * @param sysname The name such as default:lava to set. The prefix mg: is used + * for mapgen-specific nodes, and should be done by creating a + * node with a different prefix and aliasing mg:foo to it. + * @param userFacingName The name to display in the UI, such as Lava or Iron Ore + * @param params An implementation of the {@link LiquidNodeParams} interface + * detailing the action of the node. {@link LiquidSourceNodeParams} and + * {@link LiquidFlowingNodeParams} are valid for liquid sources and flowing liquid nodes, + * respectively. + * @param flowParams the source params + * @param textures A string stating the filename of the textures image. + * @param light The amount of light from 0 to 255 to be emitted. + * @return The MapNode object that has been created and added to the + * manager. + * @throws MossWorldLoadException If an exception occurs during the execution of the + * registering. + */ + public LiquidNode registerLiquid(String sysname, String userFacingName, + LiquidNodeParams params, LiquidNodeParams flowParams, + String textures, int light) throws MossWorldLoadException { + LiquidNode nd = new LiquidNode(params, textures, sysname, + userFacingName, light); + this.nm.putNode(nd); + nd.level = 0; + for (int i = 1; i < 8; i++) { + LiquidNode innerNd = new LiquidNode(flowParams, textures, sysname + + "$LEVEL$" + i, userFacingName, light); //$NON-NLS-1$ + innerNd.setByBounds(-.5f, .5f, -.5f, .5f, -.5f, (i / 8f) - 0.5f); + nd.liquidLevels[i] = innerNd; + innerNd.liquidLevels = nd.liquidLevels; + innerNd.level = i; + this.nm.putNode(innerNd); + } + nd.liquidLevels[0] = nd; + return nd; + } + + /** + * Registers a node alias. Since the map generator and scripts work via + * string names, registering an alias of mg:dirt to myscript:specialdirt + * will cause a mapgen that recognizes mg:dirt as a generated element to use + * specialdirt for that. + * + * @param alias The alias to create, i.e. mg:dirt + * @param dst The existing node to set as the alias target, i.e + * myscript:specialdirt. This element must already exist. + */ + public void registerNodeAlias(String alias, String dst) { + this.nm.putNodeAlias(alias, dst); + } + + + /** + * Gets the inv by name. + * + * @param player the player + * @param name the name + * @return the inv by name + */ + public MossInventory getInvByName(Player player, String name) { + return null; + } + + /** + * Creates the inv by name. + * + * @param p the p + * @param name the name + * @return the moss inventory + */ + public MossInventory createInvByName(Player p, String name) { + return null; + } + + /** + * Gets the player by name. + * + * @param name the name + * @return the player by name + */ + public Player getPlayerByName(String name) { + return null; + } + + /** + * Gets the node by name. + * + * @param name the name + * @return the node by name + */ + public MapNode getNodeByName(String name) { + return null; + } + + /** + * Gets the db. + * + * @return the db + */ + public ScriptableDatabase getDb() { + return this.db; + } + + /** + * Instantiates a new moss script env. + * + * @param db the db + * @param nc the nc + * @param fp the fp + * @param nm the nm + */ + public MossScriptEnv(ScriptableDatabase db, MapCache nc, + FuturesProcessor fp, INodeManager nm) { + this.db = db; + this.nc = nc; + this.fp = fp; + this.nm = nm; + } + + /** + * Gets the futures processor. + * + * @return the futures processor + */ + public FuturesProcessor getFuturesProcessor() { + return this.fp; + } + + public ArrayList getEventHandlers( + Class class1) { + // TODO Auto-generated method stub + return null; + } + +} diff --git a/src/net/mosstest/scripting/events/IMossEvent.java b/src/net/mosstest/scripting/events/IMossEvent.java index a52dcbe..05fee7f 100644 --- a/src/net/mosstest/scripting/events/IMossEvent.java +++ b/src/net/mosstest/scripting/events/IMossEvent.java @@ -1,8 +1,8 @@ -package net.mosstest.scripting.events; - -/** - * Marker interface for all events. - */ -public interface IMossEvent { - -} +package net.mosstest.scripting.events; + +/** + * Marker interface for all events. + */ +public interface IMossEvent { + +} diff --git a/src/net/mosstest/scripting/events/MossNodeChangeEvent.java b/src/net/mosstest/scripting/events/MossNodeChangeEvent.java index 8014f75..0e043b9 100644 --- a/src/net/mosstest/scripting/events/MossNodeChangeEvent.java +++ b/src/net/mosstest/scripting/events/MossNodeChangeEvent.java @@ -1,91 +1,91 @@ -package net.mosstest.scripting.events; - -import net.mosstest.scripting.MapNode; -import net.mosstest.scripting.MossItem; -import net.mosstest.scripting.NodePosition; -import net.mosstest.scripting.Player; - -// TODO: Auto-generated Javadoc -/** - * The Class MossNodeChangeEvent. - */ -public class MossNodeChangeEvent implements IMossEvent{ - - /** - * The Enum NodeActionType. - */ - public enum NodeActionType { - /** - * Fired when the user fully digs a node. - */ - NODE_ACTION_DIG, - - /** Fired when the user punches (left-clicks) a node. */ - NODE_ACTION_PUNCH, - /** - * Fired when the user punches a node with a right-click. The default - * action is to place a node; onDig should return false to avoid this. - */ - NODE_ACTION_RIGHTPUNCH, - /** - * Fired when the user punches a node with a middle-click. - */ - NODE_ACTION_MIDDLE_MOUSE_PUNCH, - /** - * Fired when the user right-clicks the node while pressing shift. This - * is generally a sign of attempting to place a node as opposed to - * right-punching it. - */ - NODE_ACTION_PLACE, - /** - * Currently unused. - */ - NODE_ACTION_REPLACE - } - - /** - * The player performing the action, or null for none (e.g. a plugin raising - * a dig event, for example via a node that is designed to dig another node - * with a ceratin tool and is raising the event to be evaluated as if it - * occurs with that tool. - */ - public final Player pl; - /** - * The NodePosition of the node in question. - */ - public final NodePosition pos; - /** - * A sequence number for this event. Refer to {@link net.mosstest.scripting.events}. - */ - public final long seqnum; - - /** The type. */ - public final NodeActionType type; - - /** The node before. */ - public final MapNode nodeBefore; - - /** The wield item. */ - public final MossItem wieldItem; - - /** - * Instantiates a new moss node change event. - * - * @param pl the pl - * @param pos the pos - * @param seqnum the seqnum - * @param type the type - * @param nodeBefore the node before - * @param wieldItem the wield item - */ - public MossNodeChangeEvent(Player pl, NodePosition pos, long seqnum, - NodeActionType type, MapNode nodeBefore, MossItem wieldItem) { - this.pl = pl; - this.pos = pos; - this.seqnum = seqnum; - this.type = type; - this.nodeBefore = nodeBefore; - this.wieldItem = wieldItem; - } - -} +package net.mosstest.scripting.events; + +import net.mosstest.scripting.MapNode; +import net.mosstest.scripting.MossItem; +import net.mosstest.scripting.NodePosition; +import net.mosstest.scripting.Player; + +// TODO: Auto-generated Javadoc +/** + * The Class MossNodeChangeEvent. + */ +public class MossNodeChangeEvent implements IMossEvent{ + + /** + * The Enum NodeActionType. + */ + public enum NodeActionType { + /** + * Fired when the user fully digs a node. + */ + NODE_ACTION_DIG, + + /** Fired when the user punches (left-clicks) a node. */ + NODE_ACTION_PUNCH, + /** + * Fired when the user punches a node with a right-click. The default + * action is to place a node; onDig should return false to avoid this. + */ + NODE_ACTION_RIGHTPUNCH, + /** + * Fired when the user punches a node with a middle-click. + */ + NODE_ACTION_MIDDLE_MOUSE_PUNCH, + /** + * Fired when the user right-clicks the node while pressing shift. This + * is generally a sign of attempting to place a node as opposed to + * right-punching it. + */ + NODE_ACTION_PLACE, + /** + * Currently unused. + */ + NODE_ACTION_REPLACE + } + + /** + * The player performing the action, or null for none (e.g. a plugin raising + * a dig event, for example via a node that is designed to dig another node + * with a ceratin tool and is raising the event to be evaluated as if it + * occurs with that tool. + */ + public final Player pl; + /** + * The NodePosition of the node in question. + */ + public final NodePosition pos; + /** + * A sequence number for this event. Refer to {@link net.mosstest.scripting.events}. + */ + public final long seqnum; + + /** The type. */ + public final NodeActionType type; + + /** The node before. */ + public final MapNode nodeBefore; + + /** The wield item. */ + public final MossItem wieldItem; + + /** + * Instantiates a new moss node change event. + * + * @param pl the pl + * @param pos the pos + * @param seqnum the seqnum + * @param type the type + * @param nodeBefore the node before + * @param wieldItem the wield item + */ + public MossNodeChangeEvent(Player pl, NodePosition pos, long seqnum, + NodeActionType type, MapNode nodeBefore, MossItem wieldItem) { + this.pl = pl; + this.pos = pos; + this.seqnum = seqnum; + this.type = type; + this.nodeBefore = nodeBefore; + this.wieldItem = wieldItem; + } + +} diff --git a/src/net/mosstest/scripting/events/ThreadStopEvent.java b/src/net/mosstest/scripting/events/ThreadStopEvent.java index cd36eff..12794d6 100644 --- a/src/net/mosstest/scripting/events/ThreadStopEvent.java +++ b/src/net/mosstest/scripting/events/ThreadStopEvent.java @@ -1,20 +1,20 @@ -package net.mosstest.scripting.events; - -import net.mosstest.servercore.MosstestSecurityManager; - - -/** - * Empty class, but has a security-oriented constructor. - * - */ -public class ThreadStopEvent implements IMossEvent { - - /** - * Instantiates a new thread stop event. - * - * @throws SecurityException the security exception - */ - public ThreadStopEvent() throws SecurityException { - MosstestSecurityManager.instance.checkMosstestControl(); - } -} +package net.mosstest.scripting.events; + +import net.mosstest.servercore.MosstestSecurityManager; + + +/** + * Empty class, but has a security-oriented constructor. + * + */ +public class ThreadStopEvent implements IMossEvent { + + /** + * Instantiates a new thread stop event. + * + * @throws SecurityException the security exception + */ + public ThreadStopEvent() throws SecurityException { + MosstestSecurityManager.instance.checkMosstestControl(); + } +} diff --git a/src/net/mosstest/scripting/events/package-info.java b/src/net/mosstest/scripting/events/package-info.java index 1acaaa5..255d123 100644 --- a/src/net/mosstest/scripting/events/package-info.java +++ b/src/net/mosstest/scripting/events/package-info.java @@ -1,14 +1,14 @@ -/** - * @author rarkenin - * - * This package contains various immutable Java objects to contain the parameters of events which scripts shall handle. - *

- * Sequence numbers, aka seqnums are serial IDs given to events with certain ordering guarantees, which include guarantees that: - *

    - *
  • Seqnums are unique until wraparound occurs at 18446744073709551616.
  • - *
  • A seqnum with a higher value was received at the server after one with a lower value, even if the seqnums differ between sessions.
  • - *
  • Within a given session between the server and a compliant client, a lower-value seqnum is assigned to an event arising from an earlier client action than a higher-value seqnum. - * - *
- */ +/** + * @author rarkenin + * + * This package contains various immutable Java objects to contain the parameters of events which scripts shall handle. + *

+ * Sequence numbers, aka seqnums are serial IDs given to events with certain ordering guarantees, which include guarantees that: + *

    + *
  • Seqnums are unique until wraparound occurs at 18446744073709551616.
  • + *
  • A seqnum with a higher value was received at the server after one with a lower value, even if the seqnums differ between sessions.
  • + *
  • Within a given session between the server and a compliant client, a lower-value seqnum is assigned to an event arising from an earlier client action than a higher-value seqnum. + * + *
+ */ package net.mosstest.scripting.events; \ No newline at end of file diff --git a/src/net/mosstest/scripting/handlers/MossEventHandler.java b/src/net/mosstest/scripting/handlers/MossEventHandler.java index 2b9d560..92a0d01 100644 --- a/src/net/mosstest/scripting/handlers/MossEventHandler.java +++ b/src/net/mosstest/scripting/handlers/MossEventHandler.java @@ -1,10 +1,10 @@ -package net.mosstest.scripting.handlers; - - -/** - * Marker interface for event handlers - * - */ -public interface MossEventHandler { - -} +package net.mosstest.scripting.handlers; + + +/** + * Marker interface for event handlers + * + */ +public interface MossEventHandler { + +} diff --git a/src/net/mosstest/scripting/handlers/MossNodeChangeHandler.java b/src/net/mosstest/scripting/handlers/MossNodeChangeHandler.java index e75104b..2078f0e 100644 --- a/src/net/mosstest/scripting/handlers/MossNodeChangeHandler.java +++ b/src/net/mosstest/scripting/handlers/MossNodeChangeHandler.java @@ -1,25 +1,25 @@ -package net.mosstest.scripting.handlers; - -import net.mosstest.scripting.MapNode; -import net.mosstest.scripting.MossItem; -import net.mosstest.scripting.NodePosition; -import net.mosstest.scripting.Player; -import net.mosstest.scripting.events.MossNodeChangeEvent; - -// TODO: Auto-generated Javadoc -/** - * The Interface MossNodeChangeHandler. - */ -public interface MossNodeChangeHandler extends MossEventHandler { - - - /** - * Called when a node is acted upon. - * - * @param evt A NodeChangeEvent object describing the event. - * @return True if this event should be processed by other subscribed and - * registered handlers, false otherwise. - */ - public abstract boolean onAction(MossNodeChangeEvent evt); - -} +package net.mosstest.scripting.handlers; + +import net.mosstest.scripting.MapNode; +import net.mosstest.scripting.MossItem; +import net.mosstest.scripting.NodePosition; +import net.mosstest.scripting.Player; +import net.mosstest.scripting.events.MossNodeChangeEvent; + +// TODO: Auto-generated Javadoc +/** + * The Interface MossNodeChangeHandler. + */ +public interface MossNodeChangeHandler extends MossEventHandler { + + + /** + * Called when a node is acted upon. + * + * @param evt A NodeChangeEvent object describing the event. + * @return True if this event should be processed by other subscribed and + * registered handlers, false otherwise. + */ + public abstract boolean onAction(MossNodeChangeEvent evt); + +} diff --git a/src/net/mosstest/scripting/messages.properties b/src/net/mosstest/scripting/messages.properties index 17aa218..57c9357 100644 --- a/src/net/mosstest/scripting/messages.properties +++ b/src/net/mosstest/scripting/messages.properties @@ -1,3 +1,3 @@ -AntiCheatController.THREAD_NAME=anticheat -MossEvent.MSG_CROSS_DMZ_SECURITY_WARNING=Attempt to access controlled resources in the script DMZ. -ScriptableDatabase.DB_NAME_INVALID=Invalid database name. +AntiCheatController.THREAD_NAME=anticheat +MossEvent.MSG_CROSS_DMZ_SECURITY_WARNING=Attempt to access controlled resources in the script DMZ. +ScriptableDatabase.DB_NAME_INVALID=Invalid database name. diff --git a/src/net/mosstest/servercore/AbstractNodeManager.java b/src/net/mosstest/servercore/AbstractNodeManager.java index e2125d1..80b6a91 100644 --- a/src/net/mosstest/servercore/AbstractNodeManager.java +++ b/src/net/mosstest/servercore/AbstractNodeManager.java @@ -1,87 +1,87 @@ -package net.mosstest.servercore; - -import com.google.common.collect.HashBiMap; -import net.mosstest.scripting.MapNode; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.Set; -import java.util.concurrent.ConcurrentHashMap; - -// TODO: Auto-generated Javadoc - -/** - * The Class AbstractNodeManager. - */ -public abstract class AbstractNodeManager implements INodeManager { - - /** - * The defined nodes. - */ - protected ArrayList definedNodes = new ArrayList<>(); - - /** - * The def node by name. - */ - protected HashMap defNodeByName = new HashMap<>(); - - /** - * The pending. - */ - protected HashBiMap pending = HashBiMap.create(); - - protected Set containedNodes = Collections.newSetFromMap(new ConcurrentHashMap()); - - /** - * The Constant MAPNODE_UNKNOWN. - */ - public static final MapNode MAPNODE_UNKNOWN; - - static { - MAPNODE_UNKNOWN = new MapNode("sys:unknown", Messages.getString("AbstractNodeManager.DESC_UNKNOWN_NODE"), "builtin/unknown.png", - 1); //$NON-NLS-1$ //$NON-NLS-2$ - MAPNODE_UNKNOWN.setNodeId((short) -1); - } - - { - this.definedNodes.add(this.MAPNODE_UNKNOWN); - } - - /* (non-Javadoc) - * @see net.mosstest.servercore.INodeManager#getNode(short) - */ - @Override - public abstract MapNode getNode(short nodeId); - - /* (non-Javadoc) - * @see net.mosstest.servercore.INodeManager#putNode(net.mosstest.scripting.MapNode) - */ - @Override - public abstract short putNode(MapNode node) throws MossWorldLoadException; - - /* (non-Javadoc) - * @see net.mosstest.servercore.INodeManager#putNodeAlias(java.lang.String, java.lang.String) - */ - @Override - public abstract void putNodeAlias(String alias, String dst); - - /* (non-Javadoc) - * @see net.mosstest.servercore.INodeManager#getNode(java.lang.String, boolean) - */ - @Override - public abstract MapNode getNode(String string, boolean isModified); - - /* (non-Javadoc) - * @see net.mosstest.servercore.INodeManager#getNode(java.lang.String) - */ - @Override - public abstract MapNode getNode(String string); - - /* (non-Javadoc) - * @see net.mosstest.servercore.INodeManager#init() - */ - @Override - public abstract void init(); - -} +package net.mosstest.servercore; + +import com.google.common.collect.HashBiMap; +import net.mosstest.scripting.MapNode; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.HashMap; +import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; + +// TODO: Auto-generated Javadoc + +/** + * The Class AbstractNodeManager. + */ +public abstract class AbstractNodeManager implements INodeManager { + + /** + * The defined nodes. + */ + protected ArrayList definedNodes = new ArrayList<>(); + + /** + * The def node by name. + */ + protected HashMap defNodeByName = new HashMap<>(); + + /** + * The pending. + */ + protected HashBiMap pending = HashBiMap.create(); + + protected Set containedNodes = Collections.newSetFromMap(new ConcurrentHashMap()); + + /** + * The Constant MAPNODE_UNKNOWN. + */ + public static final MapNode MAPNODE_UNKNOWN; + + static { + MAPNODE_UNKNOWN = new MapNode("sys:unknown", Messages.getString("AbstractNodeManager.DESC_UNKNOWN_NODE"), "builtin/unknown.png", + 1); //$NON-NLS-1$ //$NON-NLS-2$ + MAPNODE_UNKNOWN.setNodeId((short) -1); + } + + { + this.definedNodes.add(this.MAPNODE_UNKNOWN); + } + + /* (non-Javadoc) + * @see net.mosstest.servercore.INodeManager#getNode(short) + */ + @Override + public abstract MapNode getNode(short nodeId); + + /* (non-Javadoc) + * @see net.mosstest.servercore.INodeManager#putNode(net.mosstest.scripting.MapNode) + */ + @Override + public abstract short putNode(MapNode node) throws MossWorldLoadException; + + /* (non-Javadoc) + * @see net.mosstest.servercore.INodeManager#putNodeAlias(java.lang.String, java.lang.String) + */ + @Override + public abstract void putNodeAlias(String alias, String dst); + + /* (non-Javadoc) + * @see net.mosstest.servercore.INodeManager#getNode(java.lang.String, boolean) + */ + @Override + public abstract MapNode getNode(String string, boolean isModified); + + /* (non-Javadoc) + * @see net.mosstest.servercore.INodeManager#getNode(java.lang.String) + */ + @Override + public abstract MapNode getNode(String string); + + /* (non-Javadoc) + * @see net.mosstest.servercore.INodeManager#init() + */ + @Override + public abstract void init(); + +} diff --git a/src/net/mosstest/servercore/IFileManager.java b/src/net/mosstest/servercore/IFileManager.java index 7f8cf4b..e76d2db 100644 --- a/src/net/mosstest/servercore/IFileManager.java +++ b/src/net/mosstest/servercore/IFileManager.java @@ -1,19 +1,19 @@ -package net.mosstest.servercore; - -import com.jme3.asset.AssetLocator; - -import java.io.IOException; -import java.nio.ByteBuffer; -import java.util.List; - -public interface IFileManager { - public IMossFile getFile(String name) throws IOException; - - public void registerFile(String name, String sha256, long size); - - public void receiveFileChunk(String sha512, int chunkId, ByteBuffer buf) throws IOException; - - public Class getAssetLocatorClass(); - - public List getFiles(); -} +package net.mosstest.servercore; + +import com.jme3.asset.AssetLocator; + +import java.io.IOException; +import java.nio.ByteBuffer; +import java.util.List; + +public interface IFileManager { + public IMossFile getFile(String name) throws IOException; + + public void registerFile(String name, String sha256, long size); + + public void receiveFileChunk(String sha512, int chunkId, ByteBuffer buf) throws IOException; + + public Class getAssetLocatorClass(); + + public List getFiles(); +} diff --git a/src/net/mosstest/servercore/IMossFile.java b/src/net/mosstest/servercore/IMossFile.java index 464d567..268b3ad 100644 --- a/src/net/mosstest/servercore/IMossFile.java +++ b/src/net/mosstest/servercore/IMossFile.java @@ -1,22 +1,22 @@ -package net.mosstest.servercore; - -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; - -public interface IMossFile { - long CHUNK_SIZE = 65536; - - public Reader getReader() throws FileNotFoundException; - - public InputStream getInputStream() throws FileNotFoundException; - - public byte[] readChunk(int chunkId) throws IOException; - - public void writeChunk(int chunkId, byte[] buf) throws IOException; - - public String getSha256(); - - public String getName(); +package net.mosstest.servercore; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; + +public interface IMossFile { + long CHUNK_SIZE = 65536; + + public Reader getReader() throws FileNotFoundException; + + public InputStream getInputStream() throws FileNotFoundException; + + public byte[] readChunk(int chunkId) throws IOException; + + public void writeChunk(int chunkId, byte[] buf) throws IOException; + + public String getSha256(); + + public String getName(); } \ No newline at end of file diff --git a/src/net/mosstest/servercore/IPlayerManager.java b/src/net/mosstest/servercore/IPlayerManager.java index 7657c61..62d9cd6 100644 --- a/src/net/mosstest/servercore/IPlayerManager.java +++ b/src/net/mosstest/servercore/IPlayerManager.java @@ -1,19 +1,19 @@ -package net.mosstest.servercore; - -import net.mosstest.scripting.Player; - -// TODO: Auto-generated Javadoc -/** - * The Interface IPlayerManager. - */ -public interface IPlayerManager extends PlayerCommunicator { - - /** - * Gets the or create. - * - * @param name the name - * @return the or create - */ - public abstract Player getOrCreate(String name); - -} +package net.mosstest.servercore; + +import net.mosstest.scripting.Player; + +// TODO: Auto-generated Javadoc +/** + * The Interface IPlayerManager. + */ +public interface IPlayerManager extends PlayerCommunicator { + + /** + * Gets the or create. + * + * @param name the name + * @return the or create + */ + public abstract Player getOrCreate(String name); + +} diff --git a/src/net/mosstest/servercore/LocalAssetLocator.java b/src/net/mosstest/servercore/LocalAssetLocator.java index b554d98..e0ec4ba 100644 --- a/src/net/mosstest/servercore/LocalAssetLocator.java +++ b/src/net/mosstest/servercore/LocalAssetLocator.java @@ -1,56 +1,56 @@ -package net.mosstest.servercore; - -import java.io.IOException; -import java.io.InputStream; - -import com.jme3.asset.AssetInfo; -import com.jme3.asset.AssetKey; -import com.jme3.asset.AssetLoadException; -import com.jme3.asset.AssetLocator; -import com.jme3.asset.AssetManager; - -public class LocalAssetLocator implements AssetLocator { - private LocalFileManager lfm; - - @Override - public AssetInfo locate(AssetManager manager, AssetKey key) { - if (this.lfm == null) - this.lfm = LocalFileManager.getFileManager("scripts"); - if (this.lfm == null) - this.lfm = LocalFileManager.scriptsInstance; - try { - return new LocalAssetInfo(manager, key, - this.lfm.getFile(key.getName())); - } catch (IOException ex) { - throw new AssetLoadException("Failed to open file: " - + key.getName(), ex); - } - - - } - - @Override - public void setRootPath(String arg0) { - this.lfm = LocalFileManager.getFileManager(arg0); - } - - private static class LocalAssetInfo extends AssetInfo { - - private LocalFile file; - - public LocalAssetInfo(AssetManager manager, AssetKey key, LocalFile file) { - super(manager, key); - this.file = file; - } - - @Override - public InputStream openStream() { - try { - return this.file.getInputStream(); - } catch (IOException ex) { - throw new AssetLoadException("Failed to open file: " - + this.file.getFilename(), ex); - } - } - } -} +package net.mosstest.servercore; + +import java.io.IOException; +import java.io.InputStream; + +import com.jme3.asset.AssetInfo; +import com.jme3.asset.AssetKey; +import com.jme3.asset.AssetLoadException; +import com.jme3.asset.AssetLocator; +import com.jme3.asset.AssetManager; + +public class LocalAssetLocator implements AssetLocator { + private LocalFileManager lfm; + + @Override + public AssetInfo locate(AssetManager manager, AssetKey key) { + if (this.lfm == null) + this.lfm = LocalFileManager.getFileManager("scripts"); + if (this.lfm == null) + this.lfm = LocalFileManager.scriptsInstance; + try { + return new LocalAssetInfo(manager, key, + this.lfm.getFile(key.getName())); + } catch (IOException ex) { + throw new AssetLoadException("Failed to open file: " + + key.getName(), ex); + } + + + } + + @Override + public void setRootPath(String arg0) { + this.lfm = LocalFileManager.getFileManager(arg0); + } + + private static class LocalAssetInfo extends AssetInfo { + + private LocalFile file; + + public LocalAssetInfo(AssetManager manager, AssetKey key, LocalFile file) { + super(manager, key); + this.file = file; + } + + @Override + public InputStream openStream() { + try { + return this.file.getInputStream(); + } catch (IOException ex) { + throw new AssetLoadException("Failed to open file: " + + this.file.getFilename(), ex); + } + } + } +} diff --git a/src/net/mosstest/servercore/LocalFile.java b/src/net/mosstest/servercore/LocalFile.java index 4457916..67920df 100644 --- a/src/net/mosstest/servercore/LocalFile.java +++ b/src/net/mosstest/servercore/LocalFile.java @@ -1,87 +1,87 @@ -package net.mosstest.servercore; - -import org.apache.log4j.Logger; - -import java.io.*; -import java.security.NoSuchAlgorithmException; - -public class LocalFile implements IMossFile { - - public String getFilename() { - return f.getAbsolutePath(); - } - - static Logger logger = Logger.getLogger(LocalFile.class); - private final File f; - private final RandomAccessFile rFile; - - public LocalFile(File f, int numChunks, long length, String name, String sha256) throws FileNotFoundException { - this.f = f; - this.rFile = new RandomAccessFile(f, "r"); - this.numChunks = numChunks; - this.length = length; - this.name = name; - this.sha256 = sha256; - } - - private final int numChunks; - private final long length; - private final String name; - - @Override - public String getName() { - return name; - } - - private final String sha256; - - public LocalFile(String name, File f) throws IOException, FileNotFoundException { - this.name = name; - if (!f.canRead()) - throw new FileNotFoundException( - "File not existent or cannot be read"); - this.f = f; - this.rFile = new RandomAccessFile(f, "r"); - this.length = this.rFile.length(); - this.numChunks = (int) Math.ceil(this.length - / ((double) IMossFile.CHUNK_SIZE)); - try { - this.sha256 = LocalFileManager.getHash(f); - logger.info("Hashed " + f.getAbsolutePath() + " as " + this.sha256); - } catch (NoSuchAlgorithmException e) { - logger.error("Could not find algorithm SHA-256 while hashing " + f.getAbsolutePath()); - throw new IOException("Hashing failed while preparing file", e); - } - } - - @Override - public Reader getReader() throws FileNotFoundException { - return new FileReader(this.f); - } - - @Override - public InputStream getInputStream() throws FileNotFoundException { - return new FileInputStream(this.f); - } - - @Override - public byte[] readChunk(int chunkId) throws IOException { - this.rFile.seek(chunkId * IMossFile.CHUNK_SIZE); - byte[] buf = new byte[(int) (chunkId == (this.numChunks - 1) ? (this.length % IMossFile.CHUNK_SIZE) - : IMossFile.CHUNK_SIZE)]; - this.rFile.readFully(buf); - return buf; - } - - @Override - public void writeChunk(int chunkId, byte[] buf) throws IOException { - throw new IOException( - "An attempt was made to write to a read-only local file"); - } - - @Override - public String getSha256() { - return this.sha256; - } - -} +package net.mosstest.servercore; + +import org.apache.log4j.Logger; + +import java.io.*; +import java.security.NoSuchAlgorithmException; + +public class LocalFile implements IMossFile { + + public String getFilename() { + return f.getAbsolutePath(); + } + + static Logger logger = Logger.getLogger(LocalFile.class); + private final File f; + private final RandomAccessFile rFile; + + public LocalFile(File f, int numChunks, long length, String name, String sha256) throws FileNotFoundException { + this.f = f; + this.rFile = new RandomAccessFile(f, "r"); + this.numChunks = numChunks; + this.length = length; + this.name = name; + this.sha256 = sha256; + } + + private final int numChunks; + private final long length; + private final String name; + + @Override + public String getName() { + return name; + } + + private final String sha256; + + public LocalFile(String name, File f) throws IOException, FileNotFoundException { + this.name = name; + if (!f.canRead()) + throw new FileNotFoundException( + "File not existent or cannot be read"); + this.f = f; + this.rFile = new RandomAccessFile(f, "r"); + this.length = this.rFile.length(); + this.numChunks = (int) Math.ceil(this.length + / ((double) IMossFile.CHUNK_SIZE)); + try { + this.sha256 = LocalFileManager.getHash(f); + logger.info("Hashed " + f.getAbsolutePath() + " as " + this.sha256); + } catch (NoSuchAlgorithmException e) { + logger.error("Could not find algorithm SHA-256 while hashing " + f.getAbsolutePath()); + throw new IOException("Hashing failed while preparing file", e); + } + } + + @Override + public Reader getReader() throws FileNotFoundException { + return new FileReader(this.f); + } + + @Override + public InputStream getInputStream() throws FileNotFoundException { + return new FileInputStream(this.f); + } + + @Override + public byte[] readChunk(int chunkId) throws IOException { + this.rFile.seek(chunkId * IMossFile.CHUNK_SIZE); + byte[] buf = new byte[(int) (chunkId == (this.numChunks - 1) ? (this.length % IMossFile.CHUNK_SIZE) + : IMossFile.CHUNK_SIZE)]; + this.rFile.readFully(buf); + return buf; + } + + @Override + public void writeChunk(int chunkId, byte[] buf) throws IOException { + throw new IOException( + "An attempt was made to write to a read-only local file"); + } + + @Override + public String getSha256() { + return this.sha256; + } + +} diff --git a/src/net/mosstest/servercore/LocalFileManager.java b/src/net/mosstest/servercore/LocalFileManager.java index b7f5e74..f869c21 100644 --- a/src/net/mosstest/servercore/LocalFileManager.java +++ b/src/net/mosstest/servercore/LocalFileManager.java @@ -1,191 +1,190 @@ -package net.mosstest.servercore; - -import com.google.common.collect.ImmutableList; -import com.jme3.asset.AssetLocator; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.io.filefilter.FileFilterUtils; -import org.apache.commons.io.filefilter.IOFileFilter; -import org.apache.log4j.Logger; - -import java.io.*; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.util.HashMap; -import java.util.List; - -public class LocalFileManager implements IFileManager { - - public static final LocalFileManager scriptsInstance; - public static final int HASHING_BUFFER_SIZE = 8192; - public static final int BYTE_CAST_MASK = 0xFF; - @SuppressWarnings("StaticCollection") - private static HashMap managers = new HashMap<>(); - - static { - scriptsInstance = new LocalFileManager(new File("data/scripts")); - managers.put("scripts", scriptsInstance); - } - - private HashMap files = new HashMap<>(); - public static final IOFileFilter CVS_FILTER = FileFilterUtils.makeCVSAware(null); - - public static LocalFileManager getFileManager(String key) { - return managers.get(key); - } - - private final File basedir; - - static Logger logger = Logger.getLogger(LocalFileManager.class); - - @Override - public LocalFile getFile(String name) throws IOException, FileNotFoundException { - String normalized = FilenameUtils.normalize(name); - if (normalized == null) { - logger.warn("Failed to normalize game resource filename: " + name); - - throw new FileNotFoundException("The filename " + name - + " could not be normalized."); - } - File f = new File(this.basedir, normalized); - logger.info("Got local file " + name + " as " + f.getAbsolutePath()); - - return new LocalFile(name, f); - } - - @Override - public void registerFile(String name, String sha256, long size) { - try { - this.files.put(name, new LocalFile(new File(basedir, name), (int) Math.ceil(size / (double) LocalFile.CHUNK_SIZE), size, name, sha256)); - } catch (IOException ignored) { - } - - - } - - public void registerFile(String name, LocalFile lf) { - this.files.put(name, lf); - - } - - @Override - public void receiveFileChunk(String sha512, int chunkId, ByteBuffer buf) throws IOException { - throw new IOException("This file is read-only due to its being in a non-cache directory."); - } - - @Override - public Class getAssetLocatorClass() { - return LocalAssetLocator.class; - } - - public LocalFileManager(File basedir) { - this.basedir = basedir; - - } - - public static String getHash(File f) throws IOException, - NoSuchAlgorithmException, FileNotFoundException { - - - MessageDigest md = MessageDigest.getInstance("SHA-256"); - - try (FileInputStream fis = new FileInputStream(f)) { - try (FileChannel fc = fis.getChannel()) { - ByteBuffer bbf = ByteBuffer.allocateDirect(HASHING_BUFFER_SIZE); - - int bytesRead; - - bytesRead = fc.read(bbf); - - while ((bytesRead != -1) && (bytesRead != 0)) { - bbf.flip(); - - byte[] bytes = new byte[bytesRead]; - bbf.get(bytes); - - md.update(bbf); - - bbf.clear(); - bytesRead = fc.read(bbf); - } - - fis.close(); - - byte[] mdBytes = md.digest(); - - StringBuilder hexString = new StringBuilder(); - - for (byte b : mdBytes) { - hexString.append(Integer.toHexString((BYTE_CAST_MASK & b))); - } - - return hexString.toString(); - } - } - } - - @Override - public List getFiles() { - return ImmutableList.copyOf(files.values()); - } - - public IMossFile getScriptInitFile(String scName) throws IOException, FileNotFoundException { - String normalized = FilenameUtils.normalize(scName); - if (normalized == null) { - logger.warn("Failed to normalize game resource filename: " + scName); - - throw new FileNotFoundException("The filename " + scName - + " could not be normalized."); - } - final String scriptName = normalized + "/init.js"; - LocalFile scriptFile = getFile(scriptName); - registerFile(scriptName, scriptFile); - try { - final String indexName = normalized + "/index"; - LocalFile fileIndex = getFile(indexName); - registerFile(indexName, scriptFile); - BufferedReader idxR = new BufferedReader(fileIndex.getReader()); - String line; - while ((line = idxR.readLine()) != null) { - String normalizedLine = FilenameUtils.normalize(line.trim()); - if (normalizedLine == null) { - logger.warn("Failed to normalize game resource filename from file index: " - + line); - - continue; - } - try { - - final String filename = normalized + normalizedLine; - final LocalFile file = getFile(filename); - this.registerFile(filename, file); - } catch (FileNotFoundException e) { - logger.warn("File was in index but not on disk: " - + line); - - } - } - } catch (FileNotFoundException e) { - logger.warn("No index file found; no files will be served to the client."); - File base = new File(basedir, normalized); - Path basePath = Paths.get(basedir.getAbsolutePath()); - for (File f : FileUtils.listFiles(base, CVS_FILTER, CVS_FILTER)) { - try { - Path path = Paths.get(f.getAbsolutePath()); - final String resolvedName = basePath.relativize(path).toFile().getPath(); - LocalFile file = this.getFile(resolvedName); - logger.debug("Got file via recursive directory listing: " + resolvedName); - this.registerFile(resolvedName, file); - } catch (FileNotFoundException fnfe2) { - // should not happen - logger.warn("Could not find file from recursive directory listing. This should never happen."); - } - } - } - return scriptFile; - } -} +package net.mosstest.servercore; + +import com.google.common.collect.ImmutableList; +import com.jme3.asset.AssetLocator; +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.FilenameUtils; +import org.apache.commons.io.filefilter.FileFilterUtils; +import org.apache.commons.io.filefilter.IOFileFilter; +import org.apache.log4j.Logger; + +import java.io.*; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.security.MessageDigest; +import java.security.NoSuchAlgorithmException; +import java.util.HashMap; +import java.util.List; + +public class LocalFileManager implements IFileManager { + + public static final LocalFileManager scriptsInstance; + public static final int HASHING_BUFFER_SIZE = 8192; + public static final int BYTE_CAST_MASK = 0xFF; + @SuppressWarnings("StaticCollection") + private static HashMap managers = new HashMap<>(); + + static { + scriptsInstance = new LocalFileManager(new File("data/scripts")); + managers.put("scripts", scriptsInstance); + } + + private HashMap files = new HashMap<>(); + public static final IOFileFilter CVS_FILTER = FileFilterUtils.makeCVSAware(null); + + public static LocalFileManager getFileManager(String key) { + return managers.get(key); + } + + private final File basedir; + + static Logger logger = Logger.getLogger(LocalFileManager.class); + + @Override + public LocalFile getFile(String name) throws IOException, FileNotFoundException { + String normalized = FilenameUtils.normalize(name); + if (normalized == null) { + logger.warn("Failed to normalize game resource filename: " + name); + + throw new FileNotFoundException("The filename " + name + + " could not be normalized."); + } + File f = new File(this.basedir, normalized); + logger.info("Got local file " + name + " as " + f.getAbsolutePath()); + + return new LocalFile(name, f); + } + + @Override + public void registerFile(String name, String sha256, long size) { + try { + this.files.put(name, new LocalFile(new File(basedir, name), (int) Math.ceil(size / (double) LocalFile.CHUNK_SIZE), size, name, sha256)); + } catch (IOException ignored) { + } + + + } + + public void registerFile(String name, LocalFile lf) { + this.files.put(name, lf); + + } + + @Override + public void receiveFileChunk(String sha512, int chunkId, ByteBuffer buf) throws IOException { + throw new IOException("This file is read-only due to its being in a non-cache directory."); + } + + @Override + public Class getAssetLocatorClass() { + return LocalAssetLocator.class; + } + + public LocalFileManager(File basedir) { + this.basedir = basedir; + + } + + public static String getHash(File f) throws IOException, + NoSuchAlgorithmException, FileNotFoundException { + + + MessageDigest md = MessageDigest.getInstance("SHA-256"); + + try (FileInputStream fis = new FileInputStream(f)) { + try (FileChannel fc = fis.getChannel()) { + ByteBuffer bbf = ByteBuffer.allocateDirect(HASHING_BUFFER_SIZE); + + int bytesRead; + + bytesRead = fc.read(bbf); + + while ((bytesRead != -1) && (bytesRead != 0)) { + bbf.flip(); + + + + md.update(bbf); + + bbf.clear(); + bytesRead = fc.read(bbf); + } + + fis.close(); + + byte[] mdBytes = md.digest(); + + StringBuilder hexString = new StringBuilder(); + + for (byte b : mdBytes) { + hexString.append(Integer.toHexString((BYTE_CAST_MASK & b))); + } + + return hexString.toString(); + } + } + } + + @Override + public List getFiles() { + return ImmutableList.copyOf(files.values()); + } + + public IMossFile getScriptInitFile(String scName) throws IOException, FileNotFoundException { + String normalized = FilenameUtils.normalize(scName); + if (normalized == null) { + logger.warn("Failed to normalize game resource filename: " + scName); + + throw new FileNotFoundException("The filename " + scName + + " could not be normalized."); + } + final String scriptName = normalized + "/init.js"; + LocalFile scriptFile = getFile(scriptName); + registerFile(scriptName, scriptFile); + try { + final String indexName = normalized + "/index"; + LocalFile fileIndex = getFile(indexName); + registerFile(indexName, scriptFile); + BufferedReader idxR = new BufferedReader(fileIndex.getReader()); + String line; + while ((line = idxR.readLine()) != null) { + String normalizedLine = FilenameUtils.normalize(line.trim()); + if (normalizedLine == null) { + logger.warn("Failed to normalize game resource filename from file index: " + + line); + + continue; + } + try { + + final String filename = normalized + normalizedLine; + final LocalFile file = getFile(filename); + this.registerFile(filename, file); + } catch (FileNotFoundException e) { + logger.warn("File was in index but not on disk: " + + line); + + } + } + } catch (FileNotFoundException e) { + logger.warn("No index file found; no files will be served to the client."); + File base = new File(basedir, normalized); + Path basePath = Paths.get(basedir.getAbsolutePath()); + for (File f : FileUtils.listFiles(base, CVS_FILTER, CVS_FILTER)) { + try { + Path path = Paths.get(f.getAbsolutePath()); + final String resolvedName = basePath.relativize(path).toFile().getPath(); + LocalFile file = this.getFile(resolvedName); + logger.debug("Got file via recursive directory listing: " + resolvedName); + this.registerFile(resolvedName, file); + } catch (FileNotFoundException fnfe2) { + // should not happen + logger.warn("Could not find file from recursive directory listing. This should never happen."); + } + } + } + return scriptFile; + } +} diff --git a/src/net/mosstest/servercore/MapCache.java b/src/net/mosstest/servercore/MapCache.java index 0a37685..5d5e395 100644 --- a/src/net/mosstest/servercore/MapCache.java +++ b/src/net/mosstest/servercore/MapCache.java @@ -1,151 +1,151 @@ -package net.mosstest.servercore; - -import com.google.common.cache.*; -import net.mosstest.scripting.MapChunk; -import net.mosstest.scripting.MapGenerators; -import net.mosstest.scripting.Position; -import org.apache.log4j.Logger; - - -import java.util.Map; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.TimeUnit; - - -// TODO: Auto-generated Javadoc -/** - * The Class MapCache. - */ -public class MapCache { - private static final Logger logger = Logger.getLogger(MapCache.class); - private final LoadingCache chunkCache; - private final Map chunkCacheAsMap; - { - chunkCache = CacheBuilder.newBuilder() - .concurrencyLevel(4) - .softValues() - .expireAfterAccess(EngineSettings.getInt("chunkCacheTTL", 240), TimeUnit.SECONDS) - .removalListener(new RemovalListener()) - .build(new PositionMapChunkCacheLoader()); - chunkCacheAsMap = chunkCache.asMap(); - } - - - /** - * The db. - */ - private MapDatabase db ; - - /** - * Gets the chunk. - * - * @param pos the pos - * @return the chunk - * @throws MapGeneratorException the map generator exception - */ - public MapChunk getChunk(Position pos) throws MapGeneratorException { - // we want loading implicitly (which will generate it) - MapChunk chk = null; - try { - chk = chunkCache.get(pos); - } catch (ExecutionException e) { - logger.error("ExecutionException getting a chunk: "+e.getCause() + "/" + e.getMessage()); - } - if(chk == null){ - // loading from DB is still done if no chunk exists after an async load - chk = db.getChunk(pos); - // fill in, in case it was stored as compressed - MapGenerators.getDefaultMapgen().fillInChunk(chk.getNodes(), pos); - if(chk == null){ - // if still not loaded, generate - chk = MapGenerators.getDefaultMapgen().generateChunk(pos); - } - } - return chk; - - } - - - /** - * Gets the chunk fail fast. - * - * @param pos the pos - * @return the chunk fail fast - */ - public MapChunk getChunkFailFast(Position pos) { - // we don't want loading from DB or generating - return chunkCacheAsMap.get(pos); - } - - - /** - * Sets the chunk, updating cache and database. - * - * @param pos The position in question - * @param chunk the chunk to be stored - */ - public void setChunk(Position pos, MapChunk chunk) { - // plain and simple, we just store it - chunk.compact(); - db.addMapChunk(pos, chunk); - chunkCache.put(pos, chunk); - } - - /** - * Instantiates a new node cache. - * - * @param db the db - */ - public MapCache(MapDatabase db) { - this.db = db; - } - - /** - * Gets the chunk, or null if it is not generated. - * - * @param pos The position in question - * @return the chunk, or null if it does not exist on disk. - */ - public MapChunk getChunkNoGenerate(Position pos) throws MapGeneratorException{ - // we don't want loading implicitly (which will generate it) - MapChunk chk = chunkCacheAsMap.get(pos); - if(chk == null){ - // loading from DB is still done - chk = db.getChunk(pos); - if(chk == null) return null; // not found in DB - // fill in, in case it was stored as compressed. This still requires mapgen use as chunks are not guaranteed to be stored fully. - MapGenerators.getDefaultMapgen().fillInChunk(chk.getNodes(), pos); - } - return chk; - } - - private class RemovalListener implements com.google.common.cache.RemovalListener { - - @Override - public void onRemoval(RemovalNotification notification) { - switch(notification.getCause()){ - case COLLECTED: - logger.warn("Un-cacahing " + notification.getKey().toString() + " due to GC. Memory may be low."); - break; - case EXPIRED: - logger.info("Un-cacahing " + notification.getKey().toString() + " as it expired"); - case SIZE: - logger.warn("Un-cacahing " + notification.getKey().toString() + " due to a size constraint"); - } - - } - } - - private class PositionMapChunkCacheLoader extends CacheLoader { - @Override - public MapChunk load(Position position) throws Exception { - logger.info("Re-loading " + position.toString() + " into cache."); - MapChunk chk = MapCache.this.db.getChunk(position); - if(chk == null) { - chk = MapGenerators.getDefaultMapgen().generateChunk(position); - MapCache.this.db.addMapChunk(position, chk); - } - return chk; - } - } -} +package net.mosstest.servercore; + +import com.google.common.cache.*; +import net.mosstest.scripting.MapChunk; +import net.mosstest.scripting.MapGenerators; +import net.mosstest.scripting.Position; +import org.apache.log4j.Logger; + + +import java.util.Map; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + + +// TODO: Auto-generated Javadoc +/** + * The Class MapCache. + */ +public class MapCache { + private static final Logger logger = Logger.getLogger(MapCache.class); + private final LoadingCache chunkCache; + private final Map chunkCacheAsMap; + { + chunkCache = CacheBuilder.newBuilder() + .concurrencyLevel(4) + .softValues() + .expireAfterAccess(EngineSettings.getInt("chunkCacheTTL", 240), TimeUnit.SECONDS) + .removalListener(new RemovalListener()) + .build(new PositionMapChunkCacheLoader()); + chunkCacheAsMap = chunkCache.asMap(); + } + + + /** + * The db. + */ + private MapDatabase db ; + + /** + * Gets the chunk. + * + * @param pos the pos + * @return the chunk + * @throws MapGeneratorException the map generator exception + */ + public MapChunk getChunk(Position pos) throws MapGeneratorException { + // we want loading implicitly (which will generate it) + MapChunk chk = null; + try { + chk = chunkCache.get(pos); + } catch (ExecutionException e) { + logger.error("ExecutionException getting a chunk: "+e.getCause() + "/" + e.getMessage()); + } + if(chk == null){ + // loading from DB is still done if no chunk exists after an async load + chk = db.getChunk(pos); + // fill in, in case it was stored as compressed + MapGenerators.getDefaultMapgen().fillInChunk(chk.getNodes(), pos); + if(chk == null){ + // if still not loaded, generate + chk = MapGenerators.getDefaultMapgen().generateChunk(pos); + } + } + return chk; + + } + + + /** + * Gets the chunk fail fast. + * + * @param pos the pos + * @return the chunk fail fast + */ + public MapChunk getChunkFailFast(Position pos) { + // we don't want loading from DB or generating + return chunkCacheAsMap.get(pos); + } + + + /** + * Sets the chunk, updating cache and database. + * + * @param pos The position in question + * @param chunk the chunk to be stored + */ + public void setChunk(Position pos, MapChunk chunk) { + // plain and simple, we just store it + chunk.compact(); + db.addMapChunk(pos, chunk); + chunkCache.put(pos, chunk); + } + + /** + * Instantiates a new node cache. + * + * @param db the db + */ + public MapCache(MapDatabase db) { + this.db = db; + } + + /** + * Gets the chunk, or null if it is not generated. + * + * @param pos The position in question + * @return the chunk, or null if it does not exist on disk. + */ + public MapChunk getChunkNoGenerate(Position pos) throws MapGeneratorException{ + // we don't want loading implicitly (which will generate it) + MapChunk chk = chunkCacheAsMap.get(pos); + if(chk == null){ + // loading from DB is still done + chk = db.getChunk(pos); + if(chk == null) return null; // not found in DB + // fill in, in case it was stored as compressed. This still requires mapgen use as chunks are not guaranteed to be stored fully. + MapGenerators.getDefaultMapgen().fillInChunk(chk.getNodes(), pos); + } + return chk; + } + + private class RemovalListener implements com.google.common.cache.RemovalListener { + + @Override + public void onRemoval(RemovalNotification notification) { + switch(notification.getCause()){ + case COLLECTED: + logger.warn("Un-cacahing " + notification.getKey().toString() + " due to GC. Memory may be low."); + break; + case EXPIRED: + logger.info("Un-cacahing " + notification.getKey().toString() + " as it expired"); + case SIZE: + logger.warn("Un-cacahing " + notification.getKey().toString() + " due to a size constraint"); + } + + } + } + + private class PositionMapChunkCacheLoader extends CacheLoader { + @Override + public MapChunk load(Position position) throws Exception { + logger.info("Re-loading " + position.toString() + " into cache."); + MapChunk chk = MapCache.this.db.getChunk(position); + if(chk == null) { + chk = MapGenerators.getDefaultMapgen().generateChunk(position); + MapCache.this.db.addMapChunk(position, chk); + } + return chk; + } + } +} diff --git a/src/net/mosstest/servercore/MapDatabase.java b/src/net/mosstest/servercore/MapDatabase.java index fcbc18e..9c50311 100644 --- a/src/net/mosstest/servercore/MapDatabase.java +++ b/src/net/mosstest/servercore/MapDatabase.java @@ -1,141 +1,141 @@ -package net.mosstest.servercore; - -import net.mosstest.scripting.MapChunk; -import net.mosstest.scripting.Position; -import org.apache.log4j.Logger; -import org.iq80.leveldb.DB; -import org.iq80.leveldb.Options; - -import java.io.File; -import java.io.IOException; - -import static org.fusesource.leveldbjni.JniDBFactory.factory; - -//import static org.iq80.leveldb.impl.Iq80DBFactory.factory; - -// TODO: Auto-generated Javadoc -/** - * The Class MapDatabase. - */ -public class MapDatabase { - private static final Logger logger = Logger.getLogger(MapDatabase.class); - /** - * The map. - */ - DB map; - - /** The entities. */ - DB entities; - - /** The metadata. */ - DB metadata; - - /** The map heavies. */ - DB mapHeavies; - - /** The landclaims. */ - DB landclaims; - - /** The players. */ - DB players; - - /** The nodes. */ - public DB nodes; - - /** - * Instantiates a new map database. - * - * @param basedir the basedir - * @throws MapDatabaseException the map database exception - * @throws MossWorldLoadException the moss world load exception - */ - @SuppressWarnings("nls") - public MapDatabase(File basedir) throws MapDatabaseException, - MossWorldLoadException { - File dbDir = new File(basedir, "db"); //$NON-NLS-1$ - dbDir.mkdirs(); - try { - - Options options = new Options(); - options.comparator(null); - this.map = factory.open(new File(dbDir, "map"), options); //$NON-NLS-1$ - this.mapHeavies = factory.open(new File(dbDir, "mapHeavies"), //$NON-NLS-1$ - options); - this.entities = factory.open(new File(dbDir, "entities"), options); //$NON-NLS-1$ - this.metadata = factory.open(new File(dbDir, "metadata"), options); //$NON-NLS-1$ - this.players = factory.open(new File(dbDir, "players"), options); //$NON-NLS-1$ - this.nodes = factory.open(new File(dbDir, "nodes"), options); //$NON-NLS-1$ - } catch (IOException e) { - logger.error("IOException in database loading: " + e.toString()); - throw new MossWorldLoadException(Messages.getString("MapDatabase.ERR_DB_FAIL"), e); //$NON-NLS-1$ - } - - logger.info("Database loaded normally."); - - } - - /** - * Close. - * - * @throws MapDatabaseException the map database exception - */ - public void close() throws MapDatabaseException { - - logger.info("Database shutting down (normally)"); - try { - this.map.close(); - this.entities.close(); - this.metadata.close(); - } catch (IOException e) { - throw new MapDatabaseException("Database shutdown failed!", e, - MapDatabaseException.SEVERITY_UNKNOWN - | MapDatabaseException.SEVERITY_FATAL_TRANSIENT); //$NON-NLS-1$ - } - } - - - /** - * Gets the chunk, but does not generate it if it does not exist. - * - * @param pos the position - * @return the chunk - */ - public MapChunk getChunk(final Position pos) throws MapGeneratorException { - - byte[] chunk = this.map.get(pos.toBytes()); - if(chunk == null){ - return null; - } - try { - return new MapChunk(chunk); - } catch (IOException e) { - logger.error("IOException loading a chunk from byte[]"); - ExceptionHandler.registerException(e); - return null; - } - - } - - /** - * Adds the map chunk. - * - * @param pos the pos - * @param mapChunk the map chunk - */ - - void addMapChunk(Position pos, MapChunk mapChunk) { - this.map.put(pos.toBytes(), mapChunk.writeLight(true)); - - } - - /** - * Gets the heavy. - * - * @param pos the pos - * @return the heavy - */ - public byte[] getHeavy(Position pos) { - return this.mapHeavies.get(pos.toBytes()); - } - -} +package net.mosstest.servercore; + +import net.mosstest.scripting.MapChunk; +import net.mosstest.scripting.Position; +import org.apache.log4j.Logger; +import org.iq80.leveldb.DB; +import org.iq80.leveldb.Options; + +import java.io.File; +import java.io.IOException; + +import static org.fusesource.leveldbjni.JniDBFactory.factory; + +//import static org.iq80.leveldb.impl.Iq80DBFactory.factory; + +// TODO: Auto-generated Javadoc +/** + * The Class MapDatabase. + */ +public class MapDatabase { + private static final Logger logger = Logger.getLogger(MapDatabase.class); + /** + * The map. + */ + DB map; + + /** The entities. */ + DB entities; + + /** The metadata. */ + DB metadata; + + /** The map heavies. */ + DB mapHeavies; + + /** The landclaims. */ + DB landclaims; + + /** The players. */ + DB players; + + /** The nodes. */ + public DB nodes; + + /** + * Instantiates a new map database. + * + * @param basedir the basedir + * @throws MapDatabaseException the map database exception + * @throws MossWorldLoadException the moss world load exception + */ + @SuppressWarnings("nls") + public MapDatabase(File basedir) throws MapDatabaseException, + MossWorldLoadException { + File dbDir = new File(basedir, "db"); //$NON-NLS-1$ + dbDir.mkdirs(); + try { + + Options options = new Options(); + options.comparator(null); + this.map = factory.open(new File(dbDir, "map"), options); //$NON-NLS-1$ + this.mapHeavies = factory.open(new File(dbDir, "mapHeavies"), //$NON-NLS-1$ + options); + this.entities = factory.open(new File(dbDir, "entities"), options); //$NON-NLS-1$ + this.metadata = factory.open(new File(dbDir, "metadata"), options); //$NON-NLS-1$ + this.players = factory.open(new File(dbDir, "players"), options); //$NON-NLS-1$ + this.nodes = factory.open(new File(dbDir, "nodes"), options); //$NON-NLS-1$ + } catch (IOException e) { + logger.error("IOException in database loading: " + e.toString()); + throw new MossWorldLoadException(Messages.getString("MapDatabase.ERR_DB_FAIL"), e); //$NON-NLS-1$ + } + + logger.info("Database loaded normally."); + + } + + /** + * Close. + * + * @throws MapDatabaseException the map database exception + */ + public void close() throws MapDatabaseException { + + logger.info("Database shutting down (normally)"); + try { + this.map.close(); + this.entities.close(); + this.metadata.close(); + } catch (IOException e) { + throw new MapDatabaseException("Database shutdown failed!", e, + MapDatabaseException.SEVERITY_UNKNOWN + | MapDatabaseException.SEVERITY_FATAL_TRANSIENT); //$NON-NLS-1$ + } + } + + + /** + * Gets the chunk, but does not generate it if it does not exist. + * + * @param pos the position + * @return the chunk + */ + public MapChunk getChunk(final Position pos) throws MapGeneratorException { + + byte[] chunk = this.map.get(pos.toBytes()); + if(chunk == null){ + return null; + } + try { + return new MapChunk(chunk); + } catch (IOException e) { + logger.error("IOException loading a chunk from byte[]"); + ExceptionHandler.registerException(e); + return null; + } + + } + + /** + * Adds the map chunk. + * + * @param pos the pos + * @param mapChunk the map chunk + */ + + void addMapChunk(Position pos, MapChunk mapChunk) { + this.map.put(pos.toBytes(), mapChunk.writeLight(true)); + + } + + /** + * Gets the heavy. + * + * @param pos the pos + * @return the heavy + */ + public byte[] getHeavy(Position pos) { + return this.mapHeavies.get(pos.toBytes()); + } + +} diff --git a/src/net/mosstest/servercore/MossDebugUtils.java b/src/net/mosstest/servercore/MossDebugUtils.java index cd551ad..a0b1238 100644 --- a/src/net/mosstest/servercore/MossDebugUtils.java +++ b/src/net/mosstest/servercore/MossDebugUtils.java @@ -1,130 +1,130 @@ -package net.mosstest.servercore; - -import org.apache.log4j.Logger; - -import java.io.File; -import java.io.FileWriter; -import java.io.IOException; -import java.util.Properties; - -// TODO: Auto-generated Javadoc - -/** - * The Class MossDebugUtils. - */ -public class MossDebugUtils { - - /** - * The logger. - */ - static Logger logger = Logger.getLogger(MossDebugUtils.class); - - /** - * The Constant propertiesToGet. - */ - private static final String[] propertiesToGet = {"awt.toolkit", //$NON-NLS-1$ - "file.encoding", "file.separator", "java.class.version", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - "java.home", "java.runtime.name", "java.runtime.version", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - "java.specification.name", "java.specification.vendor", //$NON-NLS-1$ //$NON-NLS-2$ - "java.specification.version", "java.vendor", "java.vm.info", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - "java.vm.name", "java.vm.specification.name", "java.vm.version", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - "os.arch", "os.name", "path.separator", "sun.arch.data.model", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - "sun.cpu.endian", "sun.desktop", "user.language" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - - }; - - /** - * Write stracktrace. - * - * @param e the e - * @return the string - */ - public static String writeStracktrace(Exception e) { - String fName = Integer.toString(System.identityHashCode(e), 16) + "@" - + System.currentTimeMillis(); - File write = new File("stacktraces/" + fName + ".txt"); - try { - new File("stacktraces").mkdirs(); - write.createNewFile(); - try (FileWriter writer = new FileWriter(write)) { - writer.write(getDebugInformation(e)); - writer.close(); - } - } catch (IOException e1) { - logger.fatal(e1.getClass().getName() + " caught trying to write stacktrace of an existing exception. Message: " + e1.getMessage()); - } - return write.getAbsolutePath(); - } - - /** - * Gets the debug information. - * - * @param e the e - * @return the debug information - */ - public static String getDebugInformation(Exception e) { - StringBuilder s = new StringBuilder( - MossDebugUtils.getGitConfig("git.commit.id") + " on " + MossDebugUtils.getGitConfig("git.branch") + "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ - s.append(Messages.getString("MossDebugUtils.MSG_BUILT_ON")).append(MossDebugUtils.getGitConfig(Messages.getString("MossDebugUtils.27"))).append("\r\n\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - s.append(Messages.getString("MossDebugUtils.MSG_EXCEPTION_CAUGHT")); //$NON-NLS-1$ - for (StackTraceElement ste : e.getStackTrace()) { - s.append(ste.toString()).append("\r\n"); //$NON-NLS-1$ - } - s.append("\r\n"); //$NON-NLS-1$ - s.append(getOsDetails()); - return s.toString(); - } - - /** - * Gets the os details. - * - * @return the os details - */ - public static String getOsDetails() { - StringBuilder s = new StringBuilder(); - - s.append(Messages.getString("MossDebugUtils.MSG_SYS_PROPS")); //$NON-NLS-1$ - s.append(Messages.getString("MossDebugUtils.MSG_CORES")).append(Runtime.getRuntime().availableProcessors()).append("\r\n"); //$NON-NLS-1$ - s.append(Messages.getString("MossDebugUtils.MSG_FREEMEM")).append(Runtime.getRuntime().freeMemory()).append("\r\n"); //$NON-NLS-1$ - long maxMemory = Runtime.getRuntime().maxMemory(); - s.append(Messages.getString("MossDebugUtils.MSG_MAXMEM")).append(maxMemory == Long.MAX_VALUE ? Messages - .getString("MossDebugUtils.MSG_MEM_NO_LIMIT") : maxMemory).append("\r\n"); //$NON-NLS-1$ - s.append(Messages.getString("MossDebugUtils.MSG_TOTAL_MEM")).append(Runtime.getRuntime().totalMemory()).append("\r\n"); //$NON-NLS-1$ - File[] roots = File.listRoots(); - - for (File root : roots) { - s.append(Messages.getString("MossDebugUtils.MSG_FS_ROOT")).append(root.getAbsolutePath()).append("\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ - s.append(Messages.getString("MossDebugUtils.MSG_TOTAL_SPACE")).append(root.getTotalSpace()).append("\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ - - s.append(Messages.getString("MossDebugUtils.MSG_FREE_SPACE")).append(root.getFreeSpace()).append("\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ - s.append(Messages.getString("MossDebugUtils.MSG_USABLE_SPACE")).append(root.getUsableSpace()).append("\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ - } - s.append("\r\n"); //$NON-NLS-1$ - s.append(Messages.getString("MossDebugUtils.MSG_JAVA_PROPS")); //$NON-NLS-1$ - for (String key : propertiesToGet) { - s.append(key).append(":").append(System.getProperty(key, "")).append("\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ - } - return s.toString(); - } - - /** - * Gets the git config. - * - * @param cfgKey the cfg key - * @return the git config - */ - private static String getGitConfig(String cfgKey) { - - Properties properties = new Properties(); - try { - properties.load(MossDebugUtils.class.getClassLoader() - .getResourceAsStream("git.properties")); //$NON-NLS-1$ - } catch (IOException e) { - return Messages.getString("MossDebugUtils.MSG_IO_EXCEPTION"); //$NON-NLS-1$ - } - return properties.getProperty(cfgKey); - - } - - -} +package net.mosstest.servercore; + +import org.apache.log4j.Logger; + +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.util.Properties; + +// TODO: Auto-generated Javadoc + +/** + * The Class MossDebugUtils. + */ +public class MossDebugUtils { + + /** + * The logger. + */ + static Logger logger = Logger.getLogger(MossDebugUtils.class); + + /** + * The Constant propertiesToGet. + */ + private static final String[] propertiesToGet = {"awt.toolkit", //$NON-NLS-1$ + "file.encoding", "file.separator", "java.class.version", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + "java.home", "java.runtime.name", "java.runtime.version", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + "java.specification.name", "java.specification.vendor", //$NON-NLS-1$ //$NON-NLS-2$ + "java.specification.version", "java.vendor", "java.vm.info", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + "java.vm.name", "java.vm.specification.name", "java.vm.version", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + "os.arch", "os.name", "path.separator", "sun.arch.data.model", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + "sun.cpu.endian", "sun.desktop", "user.language" //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + + }; + + /** + * Write stracktrace. + * + * @param e the e + * @return the string + */ + public static String writeStracktrace(Exception e) { + String fName = Integer.toString(System.identityHashCode(e), 16) + "@" + + System.currentTimeMillis(); + File write = new File("stacktraces/" + fName + ".txt"); + try { + new File("stacktraces").mkdirs(); + write.createNewFile(); + try (FileWriter writer = new FileWriter(write)) { + writer.write(getDebugInformation(e)); + writer.close(); + } + } catch (IOException e1) { + logger.fatal(e1.getClass().getName() + " caught trying to write stacktrace of an existing exception. Message: " + e1.getMessage()); + } + return write.getAbsolutePath(); + } + + /** + * Gets the debug information. + * + * @param e the e + * @return the debug information + */ + public static String getDebugInformation(Exception e) { + StringBuilder s = new StringBuilder( + MossDebugUtils.getGitConfig("git.commit.id") + " on " + MossDebugUtils.getGitConfig("git.branch") + "\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ + s.append(Messages.getString("MossDebugUtils.MSG_BUILT_ON")).append(MossDebugUtils.getGitConfig(Messages.getString("MossDebugUtils.27"))).append("\r\n\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + s.append(Messages.getString("MossDebugUtils.MSG_EXCEPTION_CAUGHT")); //$NON-NLS-1$ + for (StackTraceElement ste : e.getStackTrace()) { + s.append(ste.toString()).append("\r\n"); //$NON-NLS-1$ + } + s.append("\r\n"); //$NON-NLS-1$ + s.append(getOsDetails()); + return s.toString(); + } + + /** + * Gets the os details. + * + * @return the os details + */ + public static String getOsDetails() { + StringBuilder s = new StringBuilder(); + + s.append(Messages.getString("MossDebugUtils.MSG_SYS_PROPS")); //$NON-NLS-1$ + s.append(Messages.getString("MossDebugUtils.MSG_CORES")).append(Runtime.getRuntime().availableProcessors()).append("\r\n"); //$NON-NLS-1$ + s.append(Messages.getString("MossDebugUtils.MSG_FREEMEM")).append(Runtime.getRuntime().freeMemory()).append("\r\n"); //$NON-NLS-1$ + long maxMemory = Runtime.getRuntime().maxMemory(); + s.append(Messages.getString("MossDebugUtils.MSG_MAXMEM")).append(maxMemory == Long.MAX_VALUE ? Messages + .getString("MossDebugUtils.MSG_MEM_NO_LIMIT") : maxMemory).append("\r\n"); //$NON-NLS-1$ + s.append(Messages.getString("MossDebugUtils.MSG_TOTAL_MEM")).append(Runtime.getRuntime().totalMemory()).append("\r\n"); //$NON-NLS-1$ + File[] roots = File.listRoots(); + + for (File root : roots) { + s.append(Messages.getString("MossDebugUtils.MSG_FS_ROOT")).append(root.getAbsolutePath()).append("\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ + s.append(Messages.getString("MossDebugUtils.MSG_TOTAL_SPACE")).append(root.getTotalSpace()).append("\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ + + s.append(Messages.getString("MossDebugUtils.MSG_FREE_SPACE")).append(root.getFreeSpace()).append("\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ + s.append(Messages.getString("MossDebugUtils.MSG_USABLE_SPACE")).append(root.getUsableSpace()).append("\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ + } + s.append("\r\n"); //$NON-NLS-1$ + s.append(Messages.getString("MossDebugUtils.MSG_JAVA_PROPS")); //$NON-NLS-1$ + for (String key : propertiesToGet) { + s.append(key).append(":").append(System.getProperty(key, "")).append("\r\n"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ + } + return s.toString(); + } + + /** + * Gets the git config. + * + * @param cfgKey the cfg key + * @return the git config + */ + private static String getGitConfig(String cfgKey) { + + Properties properties = new Properties(); + try { + properties.load(MossDebugUtils.class.getClassLoader() + .getResourceAsStream("git.properties")); //$NON-NLS-1$ + } catch (IOException e) { + return Messages.getString("MossDebugUtils.MSG_IO_EXCEPTION"); //$NON-NLS-1$ + } + return properties.getProperty(cfgKey); + + } + + +} diff --git a/src/net/mosstest/servercore/MossRenderSetPositionEvent.java b/src/net/mosstest/servercore/MossRenderSetPositionEvent.java index b69669e..7d49b62 100644 --- a/src/net/mosstest/servercore/MossRenderSetPositionEvent.java +++ b/src/net/mosstest/servercore/MossRenderSetPositionEvent.java @@ -1,88 +1,88 @@ -package net.mosstest.servercore; - -// TODO: Auto-generated Javadoc -/** - * The Class MossRenderSetPositionEvent. - */ -public class MossRenderSetPositionEvent extends MossRenderEvent { - - /** The offset z. */ - private final double offsetX, offsetY, offsetZ; - - /** The chk z. */ - private final int chkX, chkY, chkZ; - - /** - * Instantiates a new moss render set position event. - * - * @param offsetX the offset x - * @param offsetY the offset y - * @param offsetZ the offset z - * @param chkX the chk x - * @param chkY the chk y - * @param chkZ the chk z - */ - public MossRenderSetPositionEvent(double offsetX, double offsetY, - double offsetZ, int chkX, int chkY, int chkZ) { - this.offsetX = offsetX; - this.offsetY = offsetY; - this.offsetZ = offsetZ; - this.chkX = chkX; - this.chkY = chkY; - this.chkZ = chkZ; - } - - /** - * Gets the offset x. - * - * @return the offset x - */ - public double getOffsetX() { - return this.offsetX; - } - - /** - * Gets the offset y. - * - * @return the offset y - */ - public double getOffsetY() { - return this.offsetY; - } - - /** - * Gets the offset z. - * - * @return the offset z - */ - public double getOffsetZ() { - return this.offsetZ; - } - - /** - * Gets the chk x. - * - * @return the chk x - */ - public int getChkX() { - return this.chkX; - } - - /** - * Gets the chk y. - * - * @return the chk y - */ - public int getChkY() { - return this.chkY; - } - - /** - * Gets the chk z. - * - * @return the chk z - */ - public int getChkZ() { - return this.chkZ; - } -} +package net.mosstest.servercore; + +// TODO: Auto-generated Javadoc +/** + * The Class MossRenderSetPositionEvent. + */ +public class MossRenderSetPositionEvent extends MossRenderEvent { + + /** The offset z. */ + private final double offsetX, offsetY, offsetZ; + + /** The chk z. */ + private final int chkX, chkY, chkZ; + + /** + * Instantiates a new moss render set position event. + * + * @param offsetX the offset x + * @param offsetY the offset y + * @param offsetZ the offset z + * @param chkX the chk x + * @param chkY the chk y + * @param chkZ the chk z + */ + public MossRenderSetPositionEvent(double offsetX, double offsetY, + double offsetZ, int chkX, int chkY, int chkZ) { + this.offsetX = offsetX; + this.offsetY = offsetY; + this.offsetZ = offsetZ; + this.chkX = chkX; + this.chkY = chkY; + this.chkZ = chkZ; + } + + /** + * Gets the offset x. + * + * @return the offset x + */ + public double getOffsetX() { + return this.offsetX; + } + + /** + * Gets the offset y. + * + * @return the offset y + */ + public double getOffsetY() { + return this.offsetY; + } + + /** + * Gets the offset z. + * + * @return the offset z + */ + public double getOffsetZ() { + return this.offsetZ; + } + + /** + * Gets the chk x. + * + * @return the chk x + */ + public int getChkX() { + return this.chkX; + } + + /** + * Gets the chk y. + * + * @return the chk y + */ + public int getChkY() { + return this.chkY; + } + + /** + * Gets the chk z. + * + * @return the chk z + */ + public int getChkZ() { + return this.chkZ; + } +} diff --git a/src/net/mosstest/servercore/MosstestSecurityManager.java b/src/net/mosstest/servercore/MosstestSecurityManager.java index ab31ec2..be909b8 100644 --- a/src/net/mosstest/servercore/MosstestSecurityManager.java +++ b/src/net/mosstest/servercore/MosstestSecurityManager.java @@ -1,744 +1,744 @@ -package net.mosstest.servercore; - -import net.mosstest.scripting.MossScriptEnv; -import org.apache.log4j.Logger; - -import java.io.File; -import java.io.FileDescriptor; -import java.io.IOException; -import java.net.InetAddress; -import java.security.Permission; - -// TODO: Auto-generated Javadoc - -/** - * The Class MosstestSecurityManager. - */ -public class MosstestSecurityManager extends SecurityManager { - - - public static final int PORT_HTTP = 80; - public static final int PORT_HTTPS = 443; - public static final int MIN_SCRIPT_PORT = 16600; - public static final int MAX_SCRIPT_PORT = 16512; - /** - * The logger. - */ - static Logger logger = Logger.getLogger(MosstestSecurityManager.class); - - - @Override - public void checkPermission(Permission perm) { - - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - logger.fatal("Requested permssion " + perm); - logger.warn("MosstestSecurityManager prevented the use of arbitrary permissions outside engine contexts."); - throw new SecurityException( - "MosstestSecurityManager prevented the use of arbitrary permissions outside engine contexts."); - - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkPermission(java.security.Permission, - * java.lang.Object) - */ - @Override - public void checkPermission(Permission perm, Object context) { - System.err.println(perm.toString() + ":" + context.toString()); - checkPermission(perm); - } - - /** - * The Constant instance. - */ - public static final MosstestSecurityManager instance = new MosstestSecurityManager(); - - /** - * Gets the connected peer. - * - * @return the connected peer - */ - public String getConnectedPeer() { - return this.connectedPeer; - } - - /** - * The lock. - */ - private InheritableThreadLocal lock = new InheritableThreadLocal<>(); - private File basedir; - // Class dir corresponding to "net.mosstest" - private final File classDir; - - public void setTrustedBasedir(File basedir) throws SecurityException, - IOException { - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - logger.error("The security manager prevented an attempt to set the trusted basedir."); - throw new SecurityException("Cannot set basedir."); - } - this.basedir = basedir.getCanonicalFile(); - } - - /** - * Lock. - * - * @param key the key - * @param tc the tc - */ - public void lock(Object key, ThreadContext tc) { - if ((this.lock.get() != null) - || this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - logger.error("The security manager prevented an attempt to lock it on an already-locked thread."); - throw new SecurityException( - "The security manager is already locked for this thread."); - } - this.lock.set(key); - this.threadContext.set(tc); - - } - - private Object forceUnlock() { - Object key = this.lock.get(); - this.threadContext.set(ThreadContext.CONTEXT_ENGINE); - return key; - } - - /** - * Unlock. - * - * @param key the key - */ - public void unlock(Object key) { - if (this.lock.get() != key) { - logger.error("The security manager prevented an attempt to unlock it using a mismatched key."); - throw new SecurityException( - "A mismatched key has been used to unlock this thread."); - } - this.threadContext.set(ThreadContext.CONTEXT_ENGINE); - } - - /** - * Sets the connected peer. - * - * @param connectedPeer the new connected peer - */ - public void setConnectedPeer(String connectedPeer) { - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - logger.warn("MosstestSecurityManager prevented a non-engine-context thread from changing the connected peer."); - throw new SecurityException( - "Attempted to set the connected peer from outside engine code"); - } - - this.connectedPeer = connectedPeer; - } - - /** - * Gets the thread context. - * - * @return the thread context - */ - public ThreadContext getThreadContext() { - return this.threadContext.get(); - } - - /** - * Sets the thread context. - * - * @param tc the new thread context - */ - public void setThreadContext(ThreadContext tc) { - if (this.threadContext.get() == null) { - logger.warn("A thread has started without inheriting a thread context and has been elevated"); - this.threadContext.set(tc); - - return; - } - ThreadContext old = this.threadContext.get(); - if (tc == ThreadContext.CONTEXT_LOCKDOWN) { - this.threadContext.set(tc); - } - if (old != ThreadContext.CONTEXT_ENGINE) { - logger.warn("Attempted to set the thread context type from non-engine code"); - throw new SecurityException( - "Attempted to set the thread context type from non-engine code"); - } - } - - /** - * The Enum ThreadContext. - */ - public enum ThreadContext { - - /** - * The context engine. - */ - CONTEXT_ENGINE, - /** - * The context script. - */ - CONTEXT_SCRIPT, - /** - * The context client. - */ - CONTEXT_CLIENT, - /** - * The context lockdown. - */ - CONTEXT_LOCKDOWN - } - - /** - * The connected peer. - */ - private String connectedPeer = null; - - /** - * The thread context. - */ - private InheritableThreadLocal threadContext = new InheritableThreadLocal() { - @Override - protected ThreadContext initialValue() { - logger.warn("A thread has started without inheriting a thread context and has been elevated"); - return ThreadContext.CONTEXT_ENGINE; - } - }; - - { - this.threadContext.set(ThreadContext.CONTEXT_ENGINE); - - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkCreateClassLoader() - */ - @Override - public void checkCreateClassLoader() { - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - - logger.warn("MosstestSecurityManager stopped an attempt to create a classloader"); - throw new SecurityException( - "MosstestSecurityManager stopped an attempt to create a classloader"); - - } else { - super.checkCreateClassLoader(); - } - - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkAccess(java.lang.Thread) - */ - @Override - public void checkAccess(Thread t) { - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - - logger.warn("MosstestSecurityManager stopped an attempt to stop or modify a thread"); - throw new SecurityException( - "MosstestSecurityManager stopped an attempt to stop or modify a thread"); - - } else { - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkAccess(java.lang.ThreadGroup) - */ - @Override - public void checkAccess(ThreadGroup g) { - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - - logger.warn("MosstestSecurityManager stopped an attempt to modify a ThreadGroup"); - throw new SecurityException( - "MosstestSecurityManager stopped an attempt to modify a ThreadGroup"); - - } else { - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkExit(int) - */ - @Override - public void checkExit(int status) { - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - - logger.warn("MosstestSecurityManager stopped an attempt to exit Mosstest improperly from a script"); - throw new SecurityException( - "MosstestSecurityManager stopped an attempt to exit Mosstest improperly from a script"); - - } - super.checkExit(status); - - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkExec(java.lang.String) - */ - @Override - public void checkExec(String cmd) { - - logger.warn("MosstestSecurityManager does not allow any script or portion of the engine to start a new process"); - throw new SecurityException( - "MosstestSecurityManager does not allow any script or portion of the engine to start a new process"); - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkLink(java.lang.String) - */ - @Override - public void checkLink(String lib) { - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - - logger.warn("MosstestSecurityManager stopped an attempt to link to a JN library from insecure code"); - throw new SecurityException( - "MosstestSecurityManager stopped an attempt to link to a JN library from insecure code"); - - } - - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkRead(java.io.FileDescriptor) - */ - @Override - public void checkRead(FileDescriptor fd) { - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - - logger.warn("1MosstestSecurityManager stopped an attempt to read a file from non-core code " - + fd.toString()); - throw new SecurityException( - "MosstestSecurityManager stopped an attempt to read a file from non-core code"); - - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkRead(java.lang.String) - */ - @Override - public void checkRead(String file) { - - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - File tested; - try { - ThreadContext oldTc = MosstestSecurityManager.this - .getThreadContext(); - Object oldLock = MosstestSecurityManager.this.forceUnlock(); - - tested = new File(file).getCanonicalFile(); - MosstestSecurityManager.this.lock(oldLock, oldTc); - } catch (IOException e1) { - throw new SecurityException( - "The basedir resolution failed to resolve!"); - } - - File parentFile = tested; - while (parentFile != null) { - if (basedir.equals(parentFile) || classDir.equals(parentFile)) { - return; - } - parentFile = parentFile.getParentFile(); - } - logger.warn("MosstestSecurityManager stopped an attempt to read a file from non-core code" - + file); - - throw new SecurityException( - "MosstestSecurityManager stopped an attempt to read a file from non-core code"); - - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkRead(java.lang.String, - * java.lang.Object) - */ - @Override - public void checkRead(String file, Object context) { - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - - logger.warn("3MosstestSecurityManager stopped an attempt to read a file from non-core code: " - + file); - throw new SecurityException( - "MosstestSecurityManager stopped an attempt to read a file from non-core code"); - - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkWrite(java.io.FileDescriptor) - */ - @Override - public void checkWrite(FileDescriptor fd) { - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - - logger.warn("MosstestSecurityManager stopped an attempt to write to a file from non-core code"); - throw new SecurityException( - "MosstestSecurityManager stopped an attempt to write to a file from non-core code"); - - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkWrite(java.lang.String) - */ - @Override - public void checkWrite(String file) { - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - - logger.warn("MosstestSecurityManager stopped an attempt to write to a file from non-core code"); - throw new SecurityException( - "MosstestSecurityManager stopped an attempt to write to a file from non-core code"); - - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkDelete(java.lang.String) - */ - @Override - public void checkDelete(String file) { - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - - logger.warn("MosstestSecurityManager stopped an attempt to delete a file from non-core code"); - throw new SecurityException( - "MosstestSecurityManager stopped an attempt to delete a file from non-core code"); - - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkConnect(java.lang.String, int) - */ - @Override - public void checkConnect(String host, int port) { - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - if ((port != PORT_HTTP && port != PORT_HTTPS) && (port > MIN_SCRIPT_PORT || port < MAX_SCRIPT_PORT)) - - logger.warn("MosstestSecurityManager stopped an attempt to connect to a network port other than 80, 443, or any port in the range 16512-16600"); - throw new SecurityException( - "MosstestSecurityManager stopped an attempt to connect to a network port other than 80, 443, or any port in the range 16512-16600"); - - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkConnect(java.lang.String, int, - * java.lang.Object) - */ - @Override - public void checkConnect(String host, int port, Object context) { - if (this.threadContext.get() == ThreadContext.CONTEXT_CLIENT) { - if ((port != PORT_HTTP && port != PORT_HTTPS) && (port > MIN_SCRIPT_PORT || port < MAX_SCRIPT_PORT)) { - - logger.warn("MosstestSecurityManager stopped an attempt to connect to a network port other than 80, 443, or any port in the range 16512-16600"); - throw new SecurityException( - "MosstestSecurityManager stopped an attempt to connect to a network port other than 80, 443, or any port in the range 16512-16600"); - } - if (!host.equals(this.connectedPeer)) { - - throw new SecurityException( - "MosstestSecurityManager stopped an attempt for the client to connect to a peer other than the server currently played"); - } - } else if (this.threadContext.get() == ThreadContext.CONTEXT_LOCKDOWN) { - - logger.warn("MosstestSecurityManager has denied a thread in lockdown to open a network connection"); - throw new SecurityException( - "MosstestSecurityManager has denied a thread in lockdown to open a network connection"); - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkListen(int) - */ - @Override - public void checkListen(int port) { - if (this.threadContext.get() == ThreadContext.CONTEXT_SCRIPT) { - if ((port > MIN_SCRIPT_PORT || port < MAX_SCRIPT_PORT)) - - logger.warn("MosstestSecurityManager stopped an attempt to listen on a port not in the range 16512-16600"); - throw new SecurityException( - "MosstestSecurityManager stopped an attempt to listen on a port not in the range 16512-16600"); - - } else if (this.threadContext.get() == ThreadContext.CONTEXT_LOCKDOWN - || this.threadContext.get() == ThreadContext.CONTEXT_CLIENT) { - - logger.warn("MosstestSecurityManager has denied a thread in lockdown or running a client script to listen on a port"); - throw new SecurityException( - "MosstestSecurityManager has denied a thread in lockdown or running a client script to listen on a port"); - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkAccept(java.lang.String, int) - */ - @Override - public void checkAccept(String host, int port) { - if (this.threadContext.get() == ThreadContext.CONTEXT_SCRIPT) { - if ((port > MIN_SCRIPT_PORT || port < MAX_SCRIPT_PORT)) - - logger.warn("MosstestSecurityManager stopped an attempt to listen on a port not in the range 16512-16600"); - throw new SecurityException( - "MosstestSecurityManager stopped an attempt to listen on a port not in the range 16512-16600"); - - } else if (this.threadContext.get() == ThreadContext.CONTEXT_LOCKDOWN - || this.threadContext.get() == ThreadContext.CONTEXT_CLIENT) { - - logger.warn("MosstestSecurityManager has denied a thread in lockdown or running a client script to listen on a port"); - throw new SecurityException( - "MosstestSecurityManager has denied a thread in lockdown or running a client script to listen on a port"); - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkMulticast(java.net.InetAddress) - */ - @Override - public void checkMulticast(InetAddress maddr) { - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - - logger.warn("MosstestSecurityManager has denied a script use of multicast directly without use of loadbalancing facilities"); - throw new SecurityException( - "Scripts may not use mutlicast under any circumstances, except through the engine loadbalancing facilities"); - - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkMulticast(java.net.InetAddress, byte) - */ - @Override - public void checkMulticast(InetAddress maddr, byte ttl) { - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - - logger.warn("MosstestSecurityManager has denied a script use of multicast directly without use of loadbalancing facilities"); - throw new SecurityException( - "Scripts may not use mutlicast under any circumstances, except through the engine loadbalancing facilities"); - - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkPropertiesAccess() - */ - @Override - public void checkPropertiesAccess() { - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - - logger.warn("MosstestSecurityManager has denied a thread running outside the engine context the right to access system properties."); - throw new SecurityException( - "Scripts may not access system properties"); - - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String) - */ - @Override - public void checkPropertyAccess(String key) { - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - - logger.warn("MosstestSecurityManager has denied a thread running outside the engine context the right to access system properties."); - throw new SecurityException( - "Scripts may not access system properties"); - - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkTopLevelWindow(java.lang.Object) - */ - @Override - public boolean checkTopLevelWindow(Object window) { - if (this.threadContext.get() == ThreadContext.CONTEXT_LOCKDOWN) { - - logger.warn("MosstestSecurityManager has blocked a thread running outside the engine context frop opening a top-level window."); - throw new SecurityException( - "Threads in lockdown may not create top-level windows"); - } - return true; - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkPrintJobAccess() - */ - @Override - public void checkPrintJobAccess() { - - logger.warn("MosstestSecurityManager has denied a thread running outside the engine context the right to access system print jobs."); - throw new SecurityException( - "Print job access is not allowed for the engine or scripts"); - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkSystemClipboardAccess() - */ - @Override - public void checkSystemClipboardAccess() { - if (this.threadContext.get() == ThreadContext.CONTEXT_LOCKDOWN) { - - logger.warn("MosstestSecurityManager has prevented a thread in lockdown from accessing the system clipboard."); - throw new SecurityException( - "Threads in lockdown may not access the system clipboard"); - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkAwtEventQueueAccess() - */ - @Override - public void checkAwtEventQueueAccess() { - if (this.threadContext.get() == ThreadContext.CONTEXT_LOCKDOWN) { - - logger.warn("MosstestSecurityManager has prevented a thread in lockdown from accessing the AWT queue."); - throw new SecurityException( - "Threads in lockdown may not access the AWT queue"); - } - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkPackageAccess(java.lang.String) - */ - @Override - public void checkPackageAccess(String pkg) { - super.checkPackageAccess(pkg); - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkPackageDefinition(java.lang.String) - */ - @Override - public void checkPackageDefinition(String pkg) { - super.checkPackageDefinition(pkg); - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkSetFactory() - */ - @Override - public void checkSetFactory() { - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - - logger.warn("MosstestSecurityManager has prevented a thread in lockdown from setting a Java system factory."); - throw new SecurityException( - "Non-engine threads may not set java system factories"); - } - super.checkSetFactory(); - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkMemberAccess(java.lang.Class, int) - */ - @Override - public void checkMemberAccess(Class clazz, int which) { - super.checkMemberAccess(clazz, which); - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#checkSecurityAccess(java.lang.String) - */ - @Override - public void checkSecurityAccess(String target) { - super.checkSecurityAccess(target); - } - - /* - * (non-Javadoc) - * - * @see java.lang.SecurityManager#getThreadGroup() - */ - @Override - public ThreadGroup getThreadGroup() { - return super.getThreadGroup(); - } - - /** - * Check mosstest control. - */ - public void checkMosstestControl() { - if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { - - logger.warn("MosstestSecurityManager has prevented a plugin from controlling certain portions of the Mosstest engine."); - throw new SecurityException( - "Non-engine threads may not set java system factories"); - } - super.checkSetFactory(); - } - - public MosstestSecurityManager() { - File classDir = null; - try { - classDir = new File(MossScriptEnv.class.getProtectionDomain() - .getCodeSource().getLocation().getPath()) // net.mosstest.scripting.MossScriptEnv - .getParentFile() // net.mosstest.scripting - .getParentFile() // net.mosstest - .getCanonicalFile(); - } catch (IOException e) { - logger.warn("Failed to obtain a class directory for the security manager, surious classloading failures may result."); - } finally { - this.classDir = classDir; - } - } - -} +package net.mosstest.servercore; + +import net.mosstest.scripting.MossScriptEnv; +import org.apache.log4j.Logger; + +import java.io.File; +import java.io.FileDescriptor; +import java.io.IOException; +import java.net.InetAddress; +import java.security.Permission; + +// TODO: Auto-generated Javadoc + +/** + * The Class MosstestSecurityManager. + */ +public class MosstestSecurityManager extends SecurityManager { + + + public static final int PORT_HTTP = 80; + public static final int PORT_HTTPS = 443; + public static final int MIN_SCRIPT_PORT = 16600; + public static final int MAX_SCRIPT_PORT = 16512; + /** + * The logger. + */ + static Logger logger = Logger.getLogger(MosstestSecurityManager.class); + + + @Override + public void checkPermission(Permission perm) { + + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + logger.fatal("Requested permssion " + perm); + logger.warn("MosstestSecurityManager prevented the use of arbitrary permissions outside engine contexts."); + throw new SecurityException( + "MosstestSecurityManager prevented the use of arbitrary permissions outside engine contexts."); + + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkPermission(java.security.Permission, + * java.lang.Object) + */ + @Override + public void checkPermission(Permission perm, Object context) { + System.err.println(perm.toString() + ":" + context.toString()); + checkPermission(perm); + } + + /** + * The Constant instance. + */ + public static final MosstestSecurityManager instance = new MosstestSecurityManager(); + + /** + * Gets the connected peer. + * + * @return the connected peer + */ + public String getConnectedPeer() { + return this.connectedPeer; + } + + /** + * The lock. + */ + private InheritableThreadLocal lock = new InheritableThreadLocal<>(); + private File basedir; + // Class dir corresponding to "net.mosstest" + private final File classDir; + + public void setTrustedBasedir(File basedir) throws SecurityException, + IOException { + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + logger.error("The security manager prevented an attempt to set the trusted basedir."); + throw new SecurityException("Cannot set basedir."); + } + this.basedir = basedir.getCanonicalFile(); + } + + /** + * Lock. + * + * @param key the key + * @param tc the tc + */ + public void lock(Object key, ThreadContext tc) { + if ((this.lock.get() != null) + || this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + logger.error("The security manager prevented an attempt to lock it on an already-locked thread."); + throw new SecurityException( + "The security manager is already locked for this thread."); + } + this.lock.set(key); + this.threadContext.set(tc); + + } + + private Object forceUnlock() { + Object key = this.lock.get(); + this.threadContext.set(ThreadContext.CONTEXT_ENGINE); + return key; + } + + /** + * Unlock. + * + * @param key the key + */ + public void unlock(Object key) { + if (this.lock.get() != key) { + logger.error("The security manager prevented an attempt to unlock it using a mismatched key."); + throw new SecurityException( + "A mismatched key has been used to unlock this thread."); + } + this.threadContext.set(ThreadContext.CONTEXT_ENGINE); + } + + /** + * Sets the connected peer. + * + * @param connectedPeer the new connected peer + */ + public void setConnectedPeer(String connectedPeer) { + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + logger.warn("MosstestSecurityManager prevented a non-engine-context thread from changing the connected peer."); + throw new SecurityException( + "Attempted to set the connected peer from outside engine code"); + } + + this.connectedPeer = connectedPeer; + } + + /** + * Gets the thread context. + * + * @return the thread context + */ + public ThreadContext getThreadContext() { + return this.threadContext.get(); + } + + /** + * Sets the thread context. + * + * @param tc the new thread context + */ + public void setThreadContext(ThreadContext tc) { + if (this.threadContext.get() == null) { + logger.warn("A thread has started without inheriting a thread context and has been elevated"); + this.threadContext.set(tc); + + return; + } + ThreadContext old = this.threadContext.get(); + if (tc == ThreadContext.CONTEXT_LOCKDOWN) { + this.threadContext.set(tc); + } + if (old != ThreadContext.CONTEXT_ENGINE) { + logger.warn("Attempted to set the thread context type from non-engine code"); + throw new SecurityException( + "Attempted to set the thread context type from non-engine code"); + } + } + + /** + * The Enum ThreadContext. + */ + public enum ThreadContext { + + /** + * The context engine. + */ + CONTEXT_ENGINE, + /** + * The context script. + */ + CONTEXT_SCRIPT, + /** + * The context client. + */ + CONTEXT_CLIENT, + /** + * The context lockdown. + */ + CONTEXT_LOCKDOWN + } + + /** + * The connected peer. + */ + private String connectedPeer = null; + + /** + * The thread context. + */ + private InheritableThreadLocal threadContext = new InheritableThreadLocal() { + @Override + protected ThreadContext initialValue() { + logger.warn("A thread has started without inheriting a thread context and has been elevated"); + return ThreadContext.CONTEXT_ENGINE; + } + }; + + { + this.threadContext.set(ThreadContext.CONTEXT_ENGINE); + + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkCreateClassLoader() + */ + @Override + public void checkCreateClassLoader() { + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + + logger.warn("MosstestSecurityManager stopped an attempt to create a classloader"); + throw new SecurityException( + "MosstestSecurityManager stopped an attempt to create a classloader"); + + } else { + super.checkCreateClassLoader(); + } + + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkAccess(java.lang.Thread) + */ + @Override + public void checkAccess(Thread t) { + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + + logger.warn("MosstestSecurityManager stopped an attempt to stop or modify a thread"); + throw new SecurityException( + "MosstestSecurityManager stopped an attempt to stop or modify a thread"); + + } else { + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkAccess(java.lang.ThreadGroup) + */ + @Override + public void checkAccess(ThreadGroup g) { + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + + logger.warn("MosstestSecurityManager stopped an attempt to modify a ThreadGroup"); + throw new SecurityException( + "MosstestSecurityManager stopped an attempt to modify a ThreadGroup"); + + } else { + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkExit(int) + */ + @Override + public void checkExit(int status) { + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + + logger.warn("MosstestSecurityManager stopped an attempt to exit Mosstest improperly from a script"); + throw new SecurityException( + "MosstestSecurityManager stopped an attempt to exit Mosstest improperly from a script"); + + } + super.checkExit(status); + + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkExec(java.lang.String) + */ + @Override + public void checkExec(String cmd) { + + logger.warn("MosstestSecurityManager does not allow any script or portion of the engine to start a new process"); + throw new SecurityException( + "MosstestSecurityManager does not allow any script or portion of the engine to start a new process"); + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkLink(java.lang.String) + */ + @Override + public void checkLink(String lib) { + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + + logger.warn("MosstestSecurityManager stopped an attempt to link to a JN library from insecure code"); + throw new SecurityException( + "MosstestSecurityManager stopped an attempt to link to a JN library from insecure code"); + + } + + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkRead(java.io.FileDescriptor) + */ + @Override + public void checkRead(FileDescriptor fd) { + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + + logger.warn("1MosstestSecurityManager stopped an attempt to read a file from non-core code " + + fd.toString()); + throw new SecurityException( + "MosstestSecurityManager stopped an attempt to read a file from non-core code"); + + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkRead(java.lang.String) + */ + @Override + public void checkRead(String file) { + + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + File tested; + try { + ThreadContext oldTc = MosstestSecurityManager.this + .getThreadContext(); + Object oldLock = MosstestSecurityManager.this.forceUnlock(); + + tested = new File(file).getCanonicalFile(); + MosstestSecurityManager.this.lock(oldLock, oldTc); + } catch (IOException e1) { + throw new SecurityException( + "The basedir resolution failed to resolve!"); + } + + File parentFile = tested; + while (parentFile != null) { + if (basedir.equals(parentFile) || classDir.equals(parentFile)) { + return; + } + parentFile = parentFile.getParentFile(); + } + logger.warn("MosstestSecurityManager stopped an attempt to read a file from non-core code" + + file); + + throw new SecurityException( + "MosstestSecurityManager stopped an attempt to read a file from non-core code"); + + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkRead(java.lang.String, + * java.lang.Object) + */ + @Override + public void checkRead(String file, Object context) { + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + + logger.warn("3MosstestSecurityManager stopped an attempt to read a file from non-core code: " + + file); + throw new SecurityException( + "MosstestSecurityManager stopped an attempt to read a file from non-core code"); + + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkWrite(java.io.FileDescriptor) + */ + @Override + public void checkWrite(FileDescriptor fd) { + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + + logger.warn("MosstestSecurityManager stopped an attempt to write to a file from non-core code"); + throw new SecurityException( + "MosstestSecurityManager stopped an attempt to write to a file from non-core code"); + + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkWrite(java.lang.String) + */ + @Override + public void checkWrite(String file) { + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + + logger.warn("MosstestSecurityManager stopped an attempt to write to a file from non-core code"); + throw new SecurityException( + "MosstestSecurityManager stopped an attempt to write to a file from non-core code"); + + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkDelete(java.lang.String) + */ + @Override + public void checkDelete(String file) { + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + + logger.warn("MosstestSecurityManager stopped an attempt to delete a file from non-core code"); + throw new SecurityException( + "MosstestSecurityManager stopped an attempt to delete a file from non-core code"); + + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkConnect(java.lang.String, int) + */ + @Override + public void checkConnect(String host, int port) { + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + if ((port != PORT_HTTP && port != PORT_HTTPS) && (port > MIN_SCRIPT_PORT || port < MAX_SCRIPT_PORT)) + + logger.warn("MosstestSecurityManager stopped an attempt to connect to a network port other than 80, 443, or any port in the range 16512-16600"); + throw new SecurityException( + "MosstestSecurityManager stopped an attempt to connect to a network port other than 80, 443, or any port in the range 16512-16600"); + + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkConnect(java.lang.String, int, + * java.lang.Object) + */ + @Override + public void checkConnect(String host, int port, Object context) { + if (this.threadContext.get() == ThreadContext.CONTEXT_CLIENT) { + if ((port != PORT_HTTP && port != PORT_HTTPS) && (port > MIN_SCRIPT_PORT || port < MAX_SCRIPT_PORT)) { + + logger.warn("MosstestSecurityManager stopped an attempt to connect to a network port other than 80, 443, or any port in the range 16512-16600"); + throw new SecurityException( + "MosstestSecurityManager stopped an attempt to connect to a network port other than 80, 443, or any port in the range 16512-16600"); + } + if (!host.equals(this.connectedPeer)) { + + throw new SecurityException( + "MosstestSecurityManager stopped an attempt for the client to connect to a peer other than the server currently played"); + } + } else if (this.threadContext.get() == ThreadContext.CONTEXT_LOCKDOWN) { + + logger.warn("MosstestSecurityManager has denied a thread in lockdown to open a network connection"); + throw new SecurityException( + "MosstestSecurityManager has denied a thread in lockdown to open a network connection"); + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkListen(int) + */ + @Override + public void checkListen(int port) { + if (this.threadContext.get() == ThreadContext.CONTEXT_SCRIPT) { + if ((port > MIN_SCRIPT_PORT || port < MAX_SCRIPT_PORT)) + + logger.warn("MosstestSecurityManager stopped an attempt to listen on a port not in the range 16512-16600"); + throw new SecurityException( + "MosstestSecurityManager stopped an attempt to listen on a port not in the range 16512-16600"); + + } else if (this.threadContext.get() == ThreadContext.CONTEXT_LOCKDOWN + || this.threadContext.get() == ThreadContext.CONTEXT_CLIENT) { + + logger.warn("MosstestSecurityManager has denied a thread in lockdown or running a client script to listen on a port"); + throw new SecurityException( + "MosstestSecurityManager has denied a thread in lockdown or running a client script to listen on a port"); + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkAccept(java.lang.String, int) + */ + @Override + public void checkAccept(String host, int port) { + if (this.threadContext.get() == ThreadContext.CONTEXT_SCRIPT) { + if ((port > MIN_SCRIPT_PORT || port < MAX_SCRIPT_PORT)) + + logger.warn("MosstestSecurityManager stopped an attempt to listen on a port not in the range 16512-16600"); + throw new SecurityException( + "MosstestSecurityManager stopped an attempt to listen on a port not in the range 16512-16600"); + + } else if (this.threadContext.get() == ThreadContext.CONTEXT_LOCKDOWN + || this.threadContext.get() == ThreadContext.CONTEXT_CLIENT) { + + logger.warn("MosstestSecurityManager has denied a thread in lockdown or running a client script to listen on a port"); + throw new SecurityException( + "MosstestSecurityManager has denied a thread in lockdown or running a client script to listen on a port"); + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkMulticast(java.net.InetAddress) + */ + @Override + public void checkMulticast(InetAddress maddr) { + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + + logger.warn("MosstestSecurityManager has denied a script use of multicast directly without use of loadbalancing facilities"); + throw new SecurityException( + "Scripts may not use mutlicast under any circumstances, except through the engine loadbalancing facilities"); + + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkMulticast(java.net.InetAddress, byte) + */ + @Override + public void checkMulticast(InetAddress maddr, byte ttl) { + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + + logger.warn("MosstestSecurityManager has denied a script use of multicast directly without use of loadbalancing facilities"); + throw new SecurityException( + "Scripts may not use mutlicast under any circumstances, except through the engine loadbalancing facilities"); + + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkPropertiesAccess() + */ + @Override + public void checkPropertiesAccess() { + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + + logger.warn("MosstestSecurityManager has denied a thread running outside the engine context the right to access system properties."); + throw new SecurityException( + "Scripts may not access system properties"); + + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkPropertyAccess(java.lang.String) + */ + @Override + public void checkPropertyAccess(String key) { + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + + logger.warn("MosstestSecurityManager has denied a thread running outside the engine context the right to access system properties."); + throw new SecurityException( + "Scripts may not access system properties"); + + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkTopLevelWindow(java.lang.Object) + */ + @Override + public boolean checkTopLevelWindow(Object window) { + if (this.threadContext.get() == ThreadContext.CONTEXT_LOCKDOWN) { + + logger.warn("MosstestSecurityManager has blocked a thread running outside the engine context frop opening a top-level window."); + throw new SecurityException( + "Threads in lockdown may not create top-level windows"); + } + return true; + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkPrintJobAccess() + */ + @Override + public void checkPrintJobAccess() { + + logger.warn("MosstestSecurityManager has denied a thread running outside the engine context the right to access system print jobs."); + throw new SecurityException( + "Print job access is not allowed for the engine or scripts"); + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkSystemClipboardAccess() + */ + @Override + public void checkSystemClipboardAccess() { + if (this.threadContext.get() == ThreadContext.CONTEXT_LOCKDOWN) { + + logger.warn("MosstestSecurityManager has prevented a thread in lockdown from accessing the system clipboard."); + throw new SecurityException( + "Threads in lockdown may not access the system clipboard"); + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkAwtEventQueueAccess() + */ + @Override + public void checkAwtEventQueueAccess() { + if (this.threadContext.get() == ThreadContext.CONTEXT_LOCKDOWN) { + + logger.warn("MosstestSecurityManager has prevented a thread in lockdown from accessing the AWT queue."); + throw new SecurityException( + "Threads in lockdown may not access the AWT queue"); + } + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkPackageAccess(java.lang.String) + */ + @Override + public void checkPackageAccess(String pkg) { + super.checkPackageAccess(pkg); + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkPackageDefinition(java.lang.String) + */ + @Override + public void checkPackageDefinition(String pkg) { + super.checkPackageDefinition(pkg); + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkSetFactory() + */ + @Override + public void checkSetFactory() { + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + + logger.warn("MosstestSecurityManager has prevented a thread in lockdown from setting a Java system factory."); + throw new SecurityException( + "Non-engine threads may not set java system factories"); + } + super.checkSetFactory(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkMemberAccess(java.lang.Class, int) + */ + @Override + public void checkMemberAccess(Class clazz, int which) { + super.checkMemberAccess(clazz, which); + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#checkSecurityAccess(java.lang.String) + */ + @Override + public void checkSecurityAccess(String target) { + super.checkSecurityAccess(target); + } + + /* + * (non-Javadoc) + * + * @see java.lang.SecurityManager#getThreadGroup() + */ + @Override + public ThreadGroup getThreadGroup() { + return super.getThreadGroup(); + } + + /** + * Check mosstest control. + */ + public void checkMosstestControl() { + if (this.threadContext.get() != ThreadContext.CONTEXT_ENGINE) { + + logger.warn("MosstestSecurityManager has prevented a plugin from controlling certain portions of the Mosstest engine."); + throw new SecurityException( + "Non-engine threads may not set java system factories"); + } + super.checkSetFactory(); + } + + public MosstestSecurityManager() { + File classDir = null; + try { + classDir = new File(MossScriptEnv.class.getProtectionDomain() + .getCodeSource().getLocation().getPath()) // net.mosstest.scripting.MossScriptEnv + .getParentFile() // net.mosstest.scripting + .getParentFile() // net.mosstest + .getCanonicalFile(); + } catch (IOException e) { + logger.warn("Failed to obtain a class directory for the security manager, surious classloading failures may result."); + } finally { + this.classDir = classDir; + } + } + +} diff --git a/src/net/mosstest/servercore/PlayerCommunicator.java b/src/net/mosstest/servercore/PlayerCommunicator.java index e31bbde..fe874ba 100644 --- a/src/net/mosstest/servercore/PlayerCommunicator.java +++ b/src/net/mosstest/servercore/PlayerCommunicator.java @@ -1,25 +1,25 @@ -package net.mosstest.servercore; - -import net.mosstest.scripting.Player; - -// TODO: Auto-generated Javadoc -/** - * The Interface PlayerCommunicator. - */ -public interface PlayerCommunicator { - - /** - * Force set position. - * - * @param pl the pl - * @param cx the cx - * @param cy the cy - * @param cz the cz - * @param offsetx the offsetx - * @param offsety the offsety - * @param offsetz the offsetz - * @throws InterruptedException the interrupted exception - */ - void forceSetPosition(Player pl, int cx, int cy, int cz, double offsetx, - double offsety, double offsetz) throws InterruptedException; -} +package net.mosstest.servercore; + +import net.mosstest.scripting.Player; + +// TODO: Auto-generated Javadoc +/** + * The Interface PlayerCommunicator. + */ +public interface PlayerCommunicator { + + /** + * Force set position. + * + * @param pl the pl + * @param cx the cx + * @param cy the cy + * @param cz the cz + * @param offsetx the offsetx + * @param offsety the offsety + * @param offsetz the offsetz + * @throws InterruptedException the interrupted exception + */ + void forceSetPosition(Player pl, int cx, int cy, int cz, double offsetx, + double offsety, double offsetz) throws InterruptedException; +} diff --git a/src/net/mosstest/servercore/ScriptEnv.java b/src/net/mosstest/servercore/ScriptEnv.java index 2ef377a..0c76922 100644 --- a/src/net/mosstest/servercore/ScriptEnv.java +++ b/src/net/mosstest/servercore/ScriptEnv.java @@ -10,7 +10,7 @@ import java.io.IOException; // TODO: Auto-generated Javadoc /** - * Static environment for executing scripts. Call {@link ScriptEnv.runScript()} + * Static environment for executing scripts. Call {@link ScriptEnv#runScript()} * to call a script. * * @author rarkenin @@ -19,7 +19,7 @@ public class ScriptEnv { static Logger logger = Logger.getLogger(MossDebugUtils.class); - ScriptableObject globalScope; + ImporterTopLevel globalScope; /** @@ -52,14 +52,9 @@ public class ScriptEnv { /** * Executes a script with default permissions. This will allow sandboxed * access to the database, and gameplay data, without access to - * authentication data. These scripts have access to - * Hashmap<String, Object>-style maps used for extended - * custom attributes, and may access various API classes via - * {@link net.mosstest.scripting.JavaApi JavaApi}(which internally uses - * reflection to obtain classes). Via an ACL, certain classes may be blocked + * authentication data. Via an ACL, certain classes may be blocked * or replaced with limited versions thereof. At the time of writing, this - * feature is incomplete and will not allow any access to the Java(tm) SE - * API. + * feature uses a security manager to disallow anything that tries to access risky data or sockets. * * @param script A string representing the script to run * @return A {@link ScriptEnv.ScriptResult} constant representing the @@ -101,9 +96,9 @@ public class ScriptEnv { * @param ev the ev */ public ScriptEnv(MossScriptEnv ev) { - this.cx = ContextFactory.getGlobal().enterContext(); - this.globalScope = this.cx.initStandardObjects(); + this.globalScope = new ImporterTopLevel(); + this.globalScope.initStandardObjects(cx, false); cx.setOptimizationLevel(9); this.globalScope.put("moss", this.globalScope, ev); //$NON-NLS-1$ diff --git a/src/net/mosstest/swingui/DnDListener.java b/src/net/mosstest/swingui/DnDListener.java index 8512a66..edcb4c1 100644 --- a/src/net/mosstest/swingui/DnDListener.java +++ b/src/net/mosstest/swingui/DnDListener.java @@ -1,110 +1,110 @@ -package net.mosstest.swingui; - -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; - - - -import java.awt.MouseInfo; -import java.awt.Point; -import java.awt.PointerInfo; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; - -import javax.swing.JLabel; - -// TODO: Auto-generated Javadoc -/** - * The listener interface for receiving dnD events. - * The class that is interested in processing a dnD - * event implements this interface, and the object created - * with that class is registered with a component using the - * component's addDnDListener method. When - * the dnD event occurs, that object's appropriate - * method is invoked. - * - * @see DnDEvent - */ -public class DnDListener implements MouseListener { - - /** The start y. */ - private double startX, startY; - - /** The end y. */ - private double endX, endY; - - /** The holder. */ - private JLabel holder; - - /** - * Instantiates a new dn d listener. - * - * @param parent the parent - */ - public DnDListener (JLabel parent) { - startX = 0; - startY = 0; - endX = 0; - endY = 0; - holder = parent; - } - - /** - * Prints the diagnostics. - */ - public void printDiagnostics () { - System.out.println("START X: "+startX+" START Y: "+startY); - System.out.println("END X: "+endX+" END Y: "+endY); - } - - /* (non-Javadoc) - * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) - */ - @Override - public void mousePressed(MouseEvent arg0) { - PointerInfo info = MouseInfo.getPointerInfo(); - Point location = info.getLocation(); - startX = location.getX(); - startY = location.getY(); - } - - /* (non-Javadoc) - * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent) - */ - @Override - public void mouseReleased(MouseEvent arg0) { - PointerInfo info = MouseInfo.getPointerInfo(); - Point location = info.getLocation(); - endX = location.getX() - 35; //35, 60: modifiers that need to be present or there - endY = location.getY() - 60; //is a significant offset when placement occurs. - holder.setLocation((int)endX, (int)endY); - printDiagnostics(); - } - - - /* (non-Javadoc) - * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) - */ - @Override - public void mouseClicked(MouseEvent arg0) { - } - - /* (non-Javadoc) - * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent) - */ - @Override - public void mouseEntered(MouseEvent arg0) { - // TODO Auto-generated method stub - - } - - /* (non-Javadoc) - * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent) - */ - @Override - public void mouseExited(MouseEvent arg0) { - // TODO Auto-generated method stub - - } - -} +package net.mosstest.swingui; + +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; + + + +import java.awt.MouseInfo; +import java.awt.Point; +import java.awt.PointerInfo; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; + +import javax.swing.JLabel; + +// TODO: Auto-generated Javadoc +/** + * The listener interface for receiving dnD events. + * The class that is interested in processing a dnD + * event implements this interface, and the object created + * with that class is registered with a component using the + * component's addDnDListener method. When + * the dnD event occurs, that object's appropriate + * method is invoked. + * + * @see DnDEvent + */ +public class DnDListener implements MouseListener { + + /** The start y. */ + private double startX, startY; + + /** The end y. */ + private double endX, endY; + + /** The holder. */ + private JLabel holder; + + /** + * Instantiates a new dn d listener. + * + * @param parent the parent + */ + public DnDListener (JLabel parent) { + startX = 0; + startY = 0; + endX = 0; + endY = 0; + holder = parent; + } + + /** + * Prints the diagnostics. + */ + public void printDiagnostics () { + System.out.println("START X: "+startX+" START Y: "+startY); + System.out.println("END X: "+endX+" END Y: "+endY); + } + + /* (non-Javadoc) + * @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent) + */ + @Override + public void mousePressed(MouseEvent arg0) { + PointerInfo info = MouseInfo.getPointerInfo(); + Point location = info.getLocation(); + startX = location.getX(); + startY = location.getY(); + } + + /* (non-Javadoc) + * @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent) + */ + @Override + public void mouseReleased(MouseEvent arg0) { + PointerInfo info = MouseInfo.getPointerInfo(); + Point location = info.getLocation(); + endX = location.getX() - 35; //35, 60: modifiers that need to be present or there + endY = location.getY() - 60; //is a significant offset when placement occurs. + holder.setLocation((int)endX, (int)endY); + printDiagnostics(); + } + + + /* (non-Javadoc) + * @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent) + */ + @Override + public void mouseClicked(MouseEvent arg0) { + } + + /* (non-Javadoc) + * @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent) + */ + @Override + public void mouseEntered(MouseEvent arg0) { + // TODO Auto-generated method stub + + } + + /* (non-Javadoc) + * @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent) + */ + @Override + public void mouseExited(MouseEvent arg0) { + // TODO Auto-generated method stub + + } + +} diff --git a/src/net/mosstest/swingui/ItemSlot.java b/src/net/mosstest/swingui/ItemSlot.java index ebcfa10..d95ba24 100644 --- a/src/net/mosstest/swingui/ItemSlot.java +++ b/src/net/mosstest/swingui/ItemSlot.java @@ -1,10 +1,10 @@ -package net.mosstest.swingui; - -import javax.swing.JLabel; - -/** - * The Class ItemSlot. - */ -public class ItemSlot extends JLabel { - -} +package net.mosstest.swingui; + +import javax.swing.JLabel; + +/** + * The Class ItemSlot. + */ +public class ItemSlot extends JLabel { + +} diff --git a/src/net/mosstest/swingui/SwingDragDrop.java b/src/net/mosstest/swingui/SwingDragDrop.java index cbf386e..64d8043 100644 --- a/src/net/mosstest/swingui/SwingDragDrop.java +++ b/src/net/mosstest/swingui/SwingDragDrop.java @@ -1,62 +1,62 @@ -package net.mosstest.swingui; - -import java.awt.Image; -import java.io.File; -import java.io.IOException; - -import javax.imageio.ImageIO; -import javax.swing.ImageIcon; -import javax.swing.JFrame; -import javax.swing.JLabel; - - -// TODO: Auto-generated Javadoc -/** - * The Class SwingDragDrop. - */ -public class SwingDragDrop { - - /** The frame. */ - static JFrame frame; - - /** The picture. */ - static JLabel picture; - - /** - * The main method. - * - * @param args the arguments - * @throws IOException Signals that an I/O exception has occurred. - */ - public static void main(String[] args) throws IOException { - setupFrame(); - setupLabels(); - frame.repaint(); - } - - /** - * Setup frame. - */ - public static void setupFrame() { - frame = new JFrame("Drag and Drop Test"); - frame.setSize(800, 600); - frame.setVisible(true); - frame.setLayout(null); - } - - /** - * Setup labels. - * - * @throws IOException Signals that an I/O exception has occurred. - */ - public static void setupLabels() throws IOException { - ImageIcon icon = new ImageIcon(ImageIO - .read(new File("item_switch.png")).getScaledInstance(64, 64, - Image.SCALE_REPLICATE)); - picture = new JLabel(icon); - picture.setSize(64, 64); - picture.setLocation(200, 200); - picture.addMouseListener(new DnDListener(picture)); - frame.add(picture); - } -} +package net.mosstest.swingui; + +import java.awt.Image; +import java.io.File; +import java.io.IOException; + +import javax.imageio.ImageIO; +import javax.swing.ImageIcon; +import javax.swing.JFrame; +import javax.swing.JLabel; + + +// TODO: Auto-generated Javadoc +/** + * The Class SwingDragDrop. + */ +public class SwingDragDrop { + + /** The frame. */ + static JFrame frame; + + /** The picture. */ + static JLabel picture; + + /** + * The main method. + * + * @param args the arguments + * @throws IOException Signals that an I/O exception has occurred. + */ + public static void main(String[] args) throws IOException { + setupFrame(); + setupLabels(); + frame.repaint(); + } + + /** + * Setup frame. + */ + public static void setupFrame() { + frame = new JFrame("Drag and Drop Test"); + frame.setSize(800, 600); + frame.setVisible(true); + frame.setLayout(null); + } + + /** + * Setup labels. + * + * @throws IOException Signals that an I/O exception has occurred. + */ + public static void setupLabels() throws IOException { + ImageIcon icon = new ImageIcon(ImageIO + .read(new File("item_switch.png")).getScaledInstance(64, 64, + Image.SCALE_REPLICATE)); + picture = new JLabel(icon); + picture.setSize(64, 64); + picture.setLocation(200, 200); + picture.addMouseListener(new DnDListener(picture)); + frame.add(picture); + } +} diff --git a/src/urls.properties b/src/urls.properties index 89b8e75..db9dd85 100644 --- a/src/urls.properties +++ b/src/urls.properties @@ -1,8 +1,8 @@ -#Stores URLs for this deployment -tracker.list=http://moss-servers.appspot.com/list -#Params should be ?skey=key&port=port&maxusers=max&curusers=current -tracker.serverheartbeat=http://moss-servers.appspot.com/serveralive - -updater.updateurl=http://moss-servers.appspot.com/updater -updater.version=0.1.0-SNAPSHOT +#Stores URLs for this deployment +tracker.list=http://moss-servers.appspot.com/list +#Params should be ?skey=key&port=port&maxusers=max&curusers=current +tracker.serverheartbeat=http://moss-servers.appspot.com/serveralive + +updater.updateurl=http://moss-servers.appspot.com/updater +updater.version=0.1.0-SNAPSHOT updater.strategy=informational \ No newline at end of file diff --git a/tests/net/mosstest/tests/MainServerTest.java b/tests/net/mosstest/tests/MainServerTest.java index 7f423bd..c2c8a28 100644 --- a/tests/net/mosstest/tests/MainServerTest.java +++ b/tests/net/mosstest/tests/MainServerTest.java @@ -1,8 +1,8 @@ -package net.mosstest.tests; - -/** - * The Class MainServerTest. - */ -public class MainServerTest { -//empty class -} +package net.mosstest.tests; + +/** + * The Class MainServerTest. + */ +public class MainServerTest { +//empty class +} diff --git a/tests/net/mosstest/tests/MapChunkTest.java b/tests/net/mosstest/tests/MapChunkTest.java index 4de9141..a958ea8 100644 --- a/tests/net/mosstest/tests/MapChunkTest.java +++ b/tests/net/mosstest/tests/MapChunkTest.java @@ -1,36 +1,36 @@ -package net.mosstest.tests; - -import static org.junit.Assert.assertTrue; - -import java.io.IOException; - -import net.mosstest.scripting.MapChunk; -import net.mosstest.scripting.MapGenerators; -import net.mosstest.scripting.Position; -import net.mosstest.scripting.SimplexMapGenerator; -import net.mosstest.servercore.MapGeneratorException; - -import org.junit.Before; -import org.junit.Test; - -public class MapChunkTest { - public static final Position[] positions = { - new Position(1,1,1,0), new Position(2,4,6,0), new Position(-24,14,62,0), new Position(2,3,5,0), new Position(7,11,-13,0), - }; - - @Before - public void setUp() throws MapGeneratorException { - MapGenerators.setDefaultMapGenerator(new SimplexMapGenerator(), new MockNodeManager(), 1123581321, null); - } - - @Test - public void testByteArraySerialization() throws MapGeneratorException, IOException { - for(Position p : positions) { - MapChunk mc1 = MapGenerators.getDefaultMapgen().generateChunk(p); - byte[] bytes = mc1.writeLight(false); - MapChunk mc2 = new MapChunk(bytes); - assertTrue(mc1.equals(mc2)); - } - } - -} +package net.mosstest.tests; + +import static org.junit.Assert.assertTrue; + +import java.io.IOException; + +import net.mosstest.scripting.MapChunk; +import net.mosstest.scripting.MapGenerators; +import net.mosstest.scripting.Position; +import net.mosstest.scripting.SimplexMapGenerator; +import net.mosstest.servercore.MapGeneratorException; + +import org.junit.Before; +import org.junit.Test; + +public class MapChunkTest { + public static final Position[] positions = { + new Position(1,1,1,0), new Position(2,4,6,0), new Position(-24,14,62,0), new Position(2,3,5,0), new Position(7,11,-13,0), + }; + + @Before + public void setUp() throws MapGeneratorException { + MapGenerators.setDefaultMapGenerator(new SimplexMapGenerator(), new MockNodeManager(), 1123581321, null); + } + + @Test + public void testByteArraySerialization() throws MapGeneratorException, IOException { + for(Position p : positions) { + MapChunk mc1 = MapGenerators.getDefaultMapgen().generateChunk(p); + byte[] bytes = mc1.writeLight(false); + MapChunk mc2 = new MapChunk(bytes); + assertTrue(mc1.equals(mc2)); + } + } + +} diff --git a/tests/net/mosstest/tests/MapGenProfilerEntryPoint.java b/tests/net/mosstest/tests/MapGenProfilerEntryPoint.java index c5ebda6..c1fc37a 100644 --- a/tests/net/mosstest/tests/MapGenProfilerEntryPoint.java +++ b/tests/net/mosstest/tests/MapGenProfilerEntryPoint.java @@ -1,54 +1,54 @@ -package net.mosstest.tests; - -import java.util.HashMap; -import java.util.Random; - -import net.mosstest.scripting.MapChunk; -import net.mosstest.scripting.MapGenerators; -import net.mosstest.scripting.Position; -import net.mosstest.scripting.SimplexMapGenerator; -import net.mosstest.servercore.MapGeneratorException; - -// TODO: Auto-generated Javadoc -/** - * The Class MapGenProfilerEntryPoint. - */ -public class MapGenProfilerEntryPoint { - - /** - * The main method. - * - * @param args the arguments - * @throws MapGeneratorException the map generator exception - * @throws InterruptedException the interrupted exception - */ - public static void main(String[] args) throws MapGeneratorException, InterruptedException { - int chks = 0; - Thread.sleep(10000); // sleep to allow profiler launch - MapGenerators.setDefaultMapGenerator(new SimplexMapGenerator(), - new MockNodeManager(), 1011, null); - HashMap chunks = new HashMap<>(); - Random rand = new Random(); - whileLoop: while (true) { - long sTime = System.currentTimeMillis(); - for (int i = 0; i < 100; i++) { - Position pos = new Position(rand.nextInt(), rand.nextInt(), - rand.nextInt(), 0); - - MapChunk chk = MapGenerators.getDefaultMapgen().generateChunk( - pos); - - chunks.put(pos, chk); - chks++; - if(chks > 10000) { - break whileLoop; - } - } - System.err.println(System.currentTimeMillis() - sTime + ", " + chks); - } - while(true) { - Thread.sleep(1000); - } - } - -} +package net.mosstest.tests; + +import java.util.HashMap; +import java.util.Random; + +import net.mosstest.scripting.MapChunk; +import net.mosstest.scripting.MapGenerators; +import net.mosstest.scripting.Position; +import net.mosstest.scripting.SimplexMapGenerator; +import net.mosstest.servercore.MapGeneratorException; + +// TODO: Auto-generated Javadoc +/** + * The Class MapGenProfilerEntryPoint. + */ +public class MapGenProfilerEntryPoint { + + /** + * The main method. + * + * @param args the arguments + * @throws MapGeneratorException the map generator exception + * @throws InterruptedException the interrupted exception + */ + public static void main(String[] args) throws MapGeneratorException, InterruptedException { + int chks = 0; + Thread.sleep(10000); // sleep to allow profiler launch + MapGenerators.setDefaultMapGenerator(new SimplexMapGenerator(), + new MockNodeManager(), 1011, null); + HashMap chunks = new HashMap<>(); + Random rand = new Random(); + whileLoop: while (true) { + long sTime = System.currentTimeMillis(); + for (int i = 0; i < 100; i++) { + Position pos = new Position(rand.nextInt(), rand.nextInt(), + rand.nextInt(), 0); + + MapChunk chk = MapGenerators.getDefaultMapgen().generateChunk( + pos); + + chunks.put(pos, chk); + chks++; + if(chks > 10000) { + break whileLoop; + } + } + System.err.println(System.currentTimeMillis() - sTime + ", " + chks); + } + while(true) { + Thread.sleep(1000); + } + } + +} diff --git a/translate/launcher/launcher.pot b/translate/launcher/launcher.pot index b228751..7c895f9 100644 --- a/translate/launcher/launcher.pot +++ b/translate/launcher/launcher.pot @@ -1,153 +1,153 @@ -msgid "GUIBugReportDialog.DLG_BUG_DESC" -msgstr "Detailed problem description:" - -msgid "GUIBugReportDialog.DLG_BUG_DESC_DEFAULT" -msgstr "" -"Please describe your problem here, preferably including what you had done, " -"what you expected to happen, what happened, and any other details about the " -"world or game.\n" -"\n" -"Please note that we cannot help with third-party games or mods." - -msgid "GUIBugReportDialog.DLG_BUG_EMAIL" -msgstr "e-mail (optional):" - -msgid "GUIBugReportDialog.DLG_BUG_NAME" -msgstr "Name:" - -msgid "GUIBugReportDialog.DLG_BUG_SUMMARY" -msgstr "Problem summary:" - -msgid "GUIBugReportDialog.DLG_BUG_TITLE" -msgstr "Report a bug" - -msgid "GUIBugReportDialog.DLG_CHECKBOX_INCLUDE_TECH_INFO" -msgstr "Include technical information" - -msgid "GUIBugReportDialog.DLG_CXL" -msgstr "Cancel" - -msgid "GUIBugReportDialog.DLG_OK" -msgstr "OK" - -msgid "GUIBugReportDialog.DLG_SUBMIT" -msgstr "Submit" - -msgid "GUIBugReportDialog.NOTICE_INFO_INCLUDED" -msgstr "" -"The following information will be included in the bug report if this box is " -"checked: \n" -"\n" - -msgid "GUIClientsideLauncher.23" -msgstr "Report a bug..." - -msgid "GUIClientsideLauncher.24" -msgstr "Request new feature..." - -msgid "GUIClientsideLauncher.25" -msgstr "Visit website" - -msgid "GUIClientsideLauncher.26" -msgstr "GitHub project" - -msgid "GUIClientsideLauncher.27" -msgstr "Visit forums" - -msgid "GUIClientsideLauncher.COL_GAME_PRESET" -msgstr "Game preset" - -msgid "GUIClientsideLauncher.COL_WORLD_DESC" -msgstr "Description" - -msgid "GUIClientsideLauncher.COL_WORLD_NAME" -msgstr "World name" - -msgid "GUIClientsideLauncher.DLG_ABOUT" -msgstr "About" - -msgid "GUIClientsideLauncher.DLG_DELETE" -msgstr "Delete..." - -msgid "GUIClientsideLauncher.DLG_NEW" -msgstr "New..." - -msgid "GUIClientsideLauncher.DLG_NO_WORLD_TO_DELETE" -msgstr "" -"No world was selected to be deleted. Please select an existing world in the " -"table." - -msgid "GUIClientsideLauncher.DLG_PLAY" -msgstr "Play" - -msgid "GUIClientsideLauncher.DLG_SETTINGS" -msgstr "Settings..." - -msgid "GUIClientsideLauncher.DLG_SINGLEPLAYER" -msgstr "Singleplayer" - -msgid "GUIClientsideLauncher.DLG_TITLE" -msgstr "Mosstest Client launcher <0.0.1-initial>" - -msgid "GUIClientsideLauncher.ERR_NO_WORLD_SELECTED" -msgstr "" -"No world was selected to be started. Please select an existing world in the " -"table, or create a new world." - -msgid "GUIClientsideLauncher.ERR_NO_WORLD_SELECTED_TITLE" -msgstr "No world selected" - -msgid "GUIClientsideLauncher.NOTICE_DEFAULT_GAME_CODE" -msgstr "" -"Default game code and textures created by dolinksy296, hexafraction, et. " -"al.\n" - -msgid "GUIClientsideLauncher.NOTICE_PRIMARY_AUTHORS" -msgstr "Made by hexafraction, thatnerd2, et al.\n" - -msgid "GUIClientsideLauncher.NOTICE_TOOLS_USED" -msgstr "" -"Made with the help of Eclipse, Git, Maven, and countless services such as " -"TravisCI and GitHub.\n" - -msgid "GUIClientsideLauncher.SYS_NEWLINE" -msgstr "\n" - -msgid "GUIClientsideLauncher.USES_LIBS" -msgstr "Uses the following libraries:\n" - -msgid "GUIClientsideLauncher.WARN_SET_LAF" -msgstr "Warning: The system look-and-feel cannot be set" - -msgid "GUIWorldCreationDialog.CXL" -msgstr "Cancel" - -msgid "GUIWorldCreationDialog.DLG_TITLE" -msgstr "Create new singleplayer world..." - -msgid "GUIWorldCreationDialog.GAME_PROFILE" -msgstr "Game profile:" - -msgid "GUIWorldCreationDialog.OK" -msgstr "OK" - -msgid "GUIWorldCreationDialog.WORLD_DESC" -msgstr "Description:" - -msgid "GUIWorldCreationDialog.WORLD_NAME" -msgstr "World name:" - -msgid "GUIWorldDeletionDialog.AREYOUSURE_TEXT" -msgstr "Are you sure you wish to delete the world called " - -msgid "GUIWorldDeletionDialog.DLG_TITLE" -msgstr "Delete singleplayer world..." - -msgid "GUIWorldDeletionDialog.NO" -msgstr "No" - -msgid "GUIWorldDeletionDialog.QUESTIONMARK_CANNOT_UNDO" -msgstr "? This operation cannot be undone." - -msgid "GUIWorldDeletionDialog.YES" -msgstr "Yes" +msgid "GUIBugReportDialog.DLG_BUG_DESC" +msgstr "Detailed problem description:" + +msgid "GUIBugReportDialog.DLG_BUG_DESC_DEFAULT" +msgstr "" +"Please describe your problem here, preferably including what you had done, " +"what you expected to happen, what happened, and any other details about the " +"world or game.\n" +"\n" +"Please note that we cannot help with third-party games or mods." + +msgid "GUIBugReportDialog.DLG_BUG_EMAIL" +msgstr "e-mail (optional):" + +msgid "GUIBugReportDialog.DLG_BUG_NAME" +msgstr "Name:" + +msgid "GUIBugReportDialog.DLG_BUG_SUMMARY" +msgstr "Problem summary:" + +msgid "GUIBugReportDialog.DLG_BUG_TITLE" +msgstr "Report a bug" + +msgid "GUIBugReportDialog.DLG_CHECKBOX_INCLUDE_TECH_INFO" +msgstr "Include technical information" + +msgid "GUIBugReportDialog.DLG_CXL" +msgstr "Cancel" + +msgid "GUIBugReportDialog.DLG_OK" +msgstr "OK" + +msgid "GUIBugReportDialog.DLG_SUBMIT" +msgstr "Submit" + +msgid "GUIBugReportDialog.NOTICE_INFO_INCLUDED" +msgstr "" +"The following information will be included in the bug report if this box is " +"checked: \n" +"\n" + +msgid "GUIClientsideLauncher.23" +msgstr "Report a bug..." + +msgid "GUIClientsideLauncher.24" +msgstr "Request new feature..." + +msgid "GUIClientsideLauncher.25" +msgstr "Visit website" + +msgid "GUIClientsideLauncher.26" +msgstr "GitHub project" + +msgid "GUIClientsideLauncher.27" +msgstr "Visit forums" + +msgid "GUIClientsideLauncher.COL_GAME_PRESET" +msgstr "Game preset" + +msgid "GUIClientsideLauncher.COL_WORLD_DESC" +msgstr "Description" + +msgid "GUIClientsideLauncher.COL_WORLD_NAME" +msgstr "World name" + +msgid "GUIClientsideLauncher.DLG_ABOUT" +msgstr "About" + +msgid "GUIClientsideLauncher.DLG_DELETE" +msgstr "Delete..." + +msgid "GUIClientsideLauncher.DLG_NEW" +msgstr "New..." + +msgid "GUIClientsideLauncher.DLG_NO_WORLD_TO_DELETE" +msgstr "" +"No world was selected to be deleted. Please select an existing world in the " +"table." + +msgid "GUIClientsideLauncher.DLG_PLAY" +msgstr "Play" + +msgid "GUIClientsideLauncher.DLG_SETTINGS" +msgstr "Settings..." + +msgid "GUIClientsideLauncher.DLG_SINGLEPLAYER" +msgstr "Singleplayer" + +msgid "GUIClientsideLauncher.DLG_TITLE" +msgstr "Mosstest Client launcher <0.0.1-initial>" + +msgid "GUIClientsideLauncher.ERR_NO_WORLD_SELECTED" +msgstr "" +"No world was selected to be started. Please select an existing world in the " +"table, or create a new world." + +msgid "GUIClientsideLauncher.ERR_NO_WORLD_SELECTED_TITLE" +msgstr "No world selected" + +msgid "GUIClientsideLauncher.NOTICE_DEFAULT_GAME_CODE" +msgstr "" +"Default game code and textures created by dolinksy296, hexafraction, et. " +"al.\n" + +msgid "GUIClientsideLauncher.NOTICE_PRIMARY_AUTHORS" +msgstr "Made by hexafraction, thatnerd2, et al.\n" + +msgid "GUIClientsideLauncher.NOTICE_TOOLS_USED" +msgstr "" +"Made with the help of Eclipse, Git, Maven, and countless services such as " +"TravisCI and GitHub.\n" + +msgid "GUIClientsideLauncher.SYS_NEWLINE" +msgstr "\n" + +msgid "GUIClientsideLauncher.USES_LIBS" +msgstr "Uses the following libraries:\n" + +msgid "GUIClientsideLauncher.WARN_SET_LAF" +msgstr "Warning: The system look-and-feel cannot be set" + +msgid "GUIWorldCreationDialog.CXL" +msgstr "Cancel" + +msgid "GUIWorldCreationDialog.DLG_TITLE" +msgstr "Create new singleplayer world..." + +msgid "GUIWorldCreationDialog.GAME_PROFILE" +msgstr "Game profile:" + +msgid "GUIWorldCreationDialog.OK" +msgstr "OK" + +msgid "GUIWorldCreationDialog.WORLD_DESC" +msgstr "Description:" + +msgid "GUIWorldCreationDialog.WORLD_NAME" +msgstr "World name:" + +msgid "GUIWorldDeletionDialog.AREYOUSURE_TEXT" +msgstr "Are you sure you wish to delete the world called " + +msgid "GUIWorldDeletionDialog.DLG_TITLE" +msgstr "Delete singleplayer world..." + +msgid "GUIWorldDeletionDialog.NO" +msgstr "No" + +msgid "GUIWorldDeletionDialog.QUESTIONMARK_CANNOT_UNDO" +msgstr "? This operation cannot be undone." + +msgid "GUIWorldDeletionDialog.YES" +msgstr "Yes" diff --git a/translate/scripting/scripting.pot b/translate/scripting/scripting.pot index f1a12d2..054012d 100644 --- a/translate/scripting/scripting.pot +++ b/translate/scripting/scripting.pot @@ -1,8 +1,8 @@ -msgid "AntiCheatController.THREAD_NAME" -msgstr "anticheat" - -msgid "MossEvent.MSG_CROSS_DMZ_SECURITY_WARNING" -msgstr "Attempt to access controlled resources in the script DMZ." - -msgid "ScriptableDatabase.DB_NAME_INVALID" -msgstr "Invalid database name." +msgid "AntiCheatController.THREAD_NAME" +msgstr "anticheat" + +msgid "MossEvent.MSG_CROSS_DMZ_SECURITY_WARNING" +msgstr "Attempt to access controlled resources in the script DMZ." + +msgid "ScriptableDatabase.DB_NAME_INVALID" +msgstr "Invalid database name." diff --git a/translate/servercore/servercore.pot b/translate/servercore/servercore.pot index f2d53ae..12276fa 100644 --- a/translate/servercore/servercore.pot +++ b/translate/servercore/servercore.pot @@ -1,157 +1,157 @@ -msgid "AbstractNodeManager.DESC_UNKNOWN_NODE" -msgstr "An unknown piece of the world" - -msgid "ClientNetworkingManager.DESC_NETWORK_TIMEOUT" -msgstr "" -"The connection to the server has been lost or has become too slow to " -"continue. \n" -"This is likely caused by an unstable connection, poor WiFi, loose cables, or " -"a firewall issue." - -msgid "ClientNetworkingManager.ERR_NETWORK_TIMEOUT" -msgstr "Network Timeout" - -msgid "ClientNetworkingManager.THREAD_NET_TIMEOUT" -msgstr "netTimeout" - -msgid "ClientNetworkingManager.THREAD_QUEUEING" -msgstr "netClientSendQueue" - -msgid "DefaultEventHandlers.NO_SUCH_CMD" -msgstr "No such chat command." - -msgid "EventProcessor.MSG_ADD_DYNAMIC" -msgstr "Dynamically added thread" - -msgid "EventProcessor.MSG_STOP_ONE_THREAD" -msgstr "Stopping one thread" - -msgid "EventProcessor.MSG_THREAD_START" -msgstr "Worker thread started" - -msgid "EventProcessor.THREAD_NAME_MGR" -msgstr "EventProcessorManager" - -msgid "EventProcessor.THREADGROUP" -msgstr "EventProcessor" - -msgid "FuturesProcessor.FUTURES_THREAD" -msgstr "futures" - -msgid "LocalRenderPreparator.MG_EXCEPT" -msgstr "The map generator has thrown an exception." - -msgid "LocalRenderPreparator.MSG_REQUESTED" -msgstr "REQUESTED " - -msgid "LocalRenderPreparator.START_MSG" -msgstr "<<< START LOCAL RENDER PREPARATOR >>>" - -msgid "MapChunk.BAD_SER_VER" -msgstr "Incorrect serialization version" - -msgid "MapDatabase.ERR_DB_FAIL" -msgstr "Database loading failed." - -msgid "MossDebugUtils.27" -msgstr "git.build.time" - -msgid "MossDebugUtils.MSG_BUILT_ON" -msgstr "Built on: " - -msgid "MossDebugUtils.MSG_CORES" -msgstr "Available cores: " - -msgid "MossDebugUtils.MSG_EXCEPTION_CAUGHT" -msgstr "<<>> \n" - -msgid "MossDebugUtils.MSG_FREE_SPACE" -msgstr "Free space (bytes): " - -msgid "MossDebugUtils.MSG_FREEMEM" -msgstr "Free memory (bytes): " - -msgid "MossDebugUtils.MSG_FS_ROOT" -msgstr "File system root: " - -msgid "MossDebugUtils.MSG_IO_EXCEPTION" -msgstr "IOException loading, perhaps non-existent?" - -msgid "MossDebugUtils.MSG_JAVA_PROPS" -msgstr "<<>>\n" - -msgid "MossDebugUtils.MSG_MAXMEM" -msgstr "Maximum memory (bytes): " - -msgid "MossDebugUtils.MSG_MEM_NO_LIMIT" -msgstr "no limit" - -msgid "MossDebugUtils.MSG_SYS_PROPS" -msgstr "<<>>\n" - -msgid "MossDebugUtils.MSG_TOTAL_MEM" -msgstr "Total memory (bytes): " - -msgid "MossDebugUtils.MSG_TOTAL_SPACE" -msgstr "Total space (bytes): " - -msgid "MossDebugUtils.MSG_USABLE_SPACE" -msgstr "Usable space (bytes): " - -msgid "MossGame.CFG_LOAD_ERR" -msgstr "Error in loading the configuration file." - -msgid "MossGame.DIR_OR_CFG_NOT_FOUND" -msgstr "Game directory or configuration file not found." - -msgid "MossGame.FILE_NOT_FOUND" -msgstr "file not found: " - -msgid "MossScript.[NAME]_NOT_FOUND" -msgstr " not found!" - -msgid "MossScript.MSG_IO_EXCEPTION" -msgstr "IOException with script named " - -msgid "MossScript.MSG_OOPS" -msgstr "Extremely unexpected situation on our hands" - -msgid "MossScript.MSG_SCRIPT_NAMED_[NAME]" -msgstr "Script named " - -msgid "MossTest.PORT_DESC" -msgstr "Port number to use" - -msgid "MossTest.RUN_STANDALONE" -msgstr "Run as standalone server" - -msgid "MossWorld.ERR_DB" -msgstr "" -"An error has occured when opening the database. It is likely inaccessible, " -"on a full disk, or corrupt." - -msgid "MossWorld.MG_SELECT_FAILURE" -msgstr "The map generator could not be seeded." - -msgid "MossWorld.NO_GAME_ID" -msgstr "" -"The game ID is not specified. The game ID must be specified in game.xml as " -"foo where data/games/foo is a directory with a valid game." - -msgid "MossWorld.NO_NETWORKING_NOW" -msgstr "Networking cannot occur at this time" - -msgid "NodeManager.DESC_UNKNWN_NODE" -msgstr "An unknown piece of the world" - -msgid "ScriptEnv.ERR_SCRIPT_ERR" -msgstr "Script error has occured. Wrapped exception: \n" - -msgid "ServerNetworkingManager.ACCEPT_THREAD" -msgstr "svrNetAccept" - -msgid "ServerNetworkingManager.CONN_THREAD_NAME" -msgstr "connection thread" - -msgid "ServerNetworkingManager.THREADGROUP" -msgstr "SvrNetGroup" +msgid "AbstractNodeManager.DESC_UNKNOWN_NODE" +msgstr "An unknown piece of the world" + +msgid "ClientNetworkingManager.DESC_NETWORK_TIMEOUT" +msgstr "" +"The connection to the server has been lost or has become too slow to " +"continue. \n" +"This is likely caused by an unstable connection, poor WiFi, loose cables, or " +"a firewall issue." + +msgid "ClientNetworkingManager.ERR_NETWORK_TIMEOUT" +msgstr "Network Timeout" + +msgid "ClientNetworkingManager.THREAD_NET_TIMEOUT" +msgstr "netTimeout" + +msgid "ClientNetworkingManager.THREAD_QUEUEING" +msgstr "netClientSendQueue" + +msgid "DefaultEventHandlers.NO_SUCH_CMD" +msgstr "No such chat command." + +msgid "EventProcessor.MSG_ADD_DYNAMIC" +msgstr "Dynamically added thread" + +msgid "EventProcessor.MSG_STOP_ONE_THREAD" +msgstr "Stopping one thread" + +msgid "EventProcessor.MSG_THREAD_START" +msgstr "Worker thread started" + +msgid "EventProcessor.THREAD_NAME_MGR" +msgstr "EventProcessorManager" + +msgid "EventProcessor.THREADGROUP" +msgstr "EventProcessor" + +msgid "FuturesProcessor.FUTURES_THREAD" +msgstr "futures" + +msgid "LocalRenderPreparator.MG_EXCEPT" +msgstr "The map generator has thrown an exception." + +msgid "LocalRenderPreparator.MSG_REQUESTED" +msgstr "REQUESTED " + +msgid "LocalRenderPreparator.START_MSG" +msgstr "<<< START LOCAL RENDER PREPARATOR >>>" + +msgid "MapChunk.BAD_SER_VER" +msgstr "Incorrect serialization version" + +msgid "MapDatabase.ERR_DB_FAIL" +msgstr "Database loading failed." + +msgid "MossDebugUtils.27" +msgstr "git.build.time" + +msgid "MossDebugUtils.MSG_BUILT_ON" +msgstr "Built on: " + +msgid "MossDebugUtils.MSG_CORES" +msgstr "Available cores: " + +msgid "MossDebugUtils.MSG_EXCEPTION_CAUGHT" +msgstr "<<>> \n" + +msgid "MossDebugUtils.MSG_FREE_SPACE" +msgstr "Free space (bytes): " + +msgid "MossDebugUtils.MSG_FREEMEM" +msgstr "Free memory (bytes): " + +msgid "MossDebugUtils.MSG_FS_ROOT" +msgstr "File system root: " + +msgid "MossDebugUtils.MSG_IO_EXCEPTION" +msgstr "IOException loading, perhaps non-existent?" + +msgid "MossDebugUtils.MSG_JAVA_PROPS" +msgstr "<<>>\n" + +msgid "MossDebugUtils.MSG_MAXMEM" +msgstr "Maximum memory (bytes): " + +msgid "MossDebugUtils.MSG_MEM_NO_LIMIT" +msgstr "no limit" + +msgid "MossDebugUtils.MSG_SYS_PROPS" +msgstr "<<>>\n" + +msgid "MossDebugUtils.MSG_TOTAL_MEM" +msgstr "Total memory (bytes): " + +msgid "MossDebugUtils.MSG_TOTAL_SPACE" +msgstr "Total space (bytes): " + +msgid "MossDebugUtils.MSG_USABLE_SPACE" +msgstr "Usable space (bytes): " + +msgid "MossGame.CFG_LOAD_ERR" +msgstr "Error in loading the configuration file." + +msgid "MossGame.DIR_OR_CFG_NOT_FOUND" +msgstr "Game directory or configuration file not found." + +msgid "MossGame.FILE_NOT_FOUND" +msgstr "file not found: " + +msgid "MossScript.[NAME]_NOT_FOUND" +msgstr " not found!" + +msgid "MossScript.MSG_IO_EXCEPTION" +msgstr "IOException with script named " + +msgid "MossScript.MSG_OOPS" +msgstr "Extremely unexpected situation on our hands" + +msgid "MossScript.MSG_SCRIPT_NAMED_[NAME]" +msgstr "Script named " + +msgid "MossTest.PORT_DESC" +msgstr "Port number to use" + +msgid "MossTest.RUN_STANDALONE" +msgstr "Run as standalone server" + +msgid "MossWorld.ERR_DB" +msgstr "" +"An error has occured when opening the database. It is likely inaccessible, " +"on a full disk, or corrupt." + +msgid "MossWorld.MG_SELECT_FAILURE" +msgstr "The map generator could not be seeded." + +msgid "MossWorld.NO_GAME_ID" +msgstr "" +"The game ID is not specified. The game ID must be specified in game.xml as " +"foo where data/games/foo is a directory with a valid game." + +msgid "MossWorld.NO_NETWORKING_NOW" +msgstr "Networking cannot occur at this time" + +msgid "NodeManager.DESC_UNKNWN_NODE" +msgstr "An unknown piece of the world" + +msgid "ScriptEnv.ERR_SCRIPT_ERR" +msgstr "Script error has occured. Wrapped exception: \n" + +msgid "ServerNetworkingManager.ACCEPT_THREAD" +msgstr "svrNetAccept" + +msgid "ServerNetworkingManager.CONN_THREAD_NAME" +msgstr "connection thread" + +msgid "ServerNetworkingManager.THREADGROUP" +msgstr "SvrNetGroup" diff --git a/wbp-meta/org.eclipse.wb.swing.wbp-palette.xml b/wbp-meta/org.eclipse.wb.swing.wbp-palette.xml index 1ee32d4..b775f56 100644 --- a/wbp-meta/org.eclipse.wb.swing.wbp-palette.xml +++ b/wbp-meta/org.eclipse.wb.swing.wbp-palette.xml @@ -1,7 +1,7 @@ - - - - - - + + + + + + \ No newline at end of file