This commit is contained in:
BetaSteward 2010-03-20 03:44:53 +00:00
parent b4164b4d10
commit 5eee0c6de7
44 changed files with 4226 additions and 0 deletions

117
Mage.Server/build.xml Normal file
View file

@ -0,0 +1,117 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="Mage.Server" default="default" basedir=".">
<description>Builds, tests, and runs the project Mage.Server.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar-with-manifest: JAR building (if you are using a manifest)
-do-jar-without-manifest: JAR building (if you are not using a manifest)
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="Mage.Server-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
<target name="package-for-release" depends="jar">
<property name="release.jar.name" value="${application.title}"/>
<property name="release.dir" value="release-${app.version}"/>
<property name="release.jar" value="${release.dir}/${release.jar.name}.jar"/>
<echo message="Packaging ${application.title} into a single JAR at ${release.jar}"/>
<delete dir="${release.dir}"/>
<mkdir dir="${release.dir}"/>
<mkdir dir="${release.dir}/plugins"/>
<jar destfile="${release.dir}/temp_final.jar" filesetmanifest="skip">
<zipgroupfileset dir="dist" includes="*.jar"/>
<zipgroupfileset dir="dist/lib" includes="*.jar"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
<attribute name="Implementation-Version" value="${app.version}"/>
</manifest>
</jar>
<zip destfile="${release.jar}">
<zipfileset src="${release.dir}/temp_final.jar" excludes="META-INF/*.SF, META-INF/*.DSA, META-INF/*.RSA"/>
</zip>
<delete file="${release.dir}/temp_final.jar"/>
<copy todir="${release.dir}/config">
<fileset dir="./config"/>
</copy>
<copy todir="${release.dir}">
<fileset dir="./release"/>
</copy>
<copy todir="${release.dir}/plugins">
<fileset dir="./plugins"/>
</copy>
</target>
</project>

14
Mage.Server/catalog.xml Normal file
View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog" prefer="system">
<system systemId="file:/C:/Projects/Mage/Mage.Server/src/mage/server/util/config.xml" uri="xml-resources/jaxb/ServerConfig/config.xml"/>
<system systemId="file:/C:/Projects/Mage/Mage.Server/src/mage/server/util/ConfigSettings.xsd" uri="xml-resources/jaxb/Config/ConfigSettings.xsd"/>
<system systemId="file:/C:/Projects/Mage/Mage.Server/src/mage/server/util/Config.xsd" uri="xml-resources/jaxb/Config/Config.xsd"/>
</catalog>

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Config.xsd">
<server serverName="mage-server" port="17171" maxGameThreads="10" maxSecondsIdle="600"/>
<playerTypes>
<plugin name="Human" jar="Mage.HumanPlayer.jar" className="mage.human.HumanPlayer"/>
<plugin name="Computer - default" jar="Mage.AI.jar" className="mage.ai.ComputerPlayer"/>
</playerTypes>
<gameTypes>
<plugin name="Two Player Duel" jar="Mage.Game.TwoPlayerDuel.jar" className="mage.game.TwoPlayerGame"/>
</gameTypes>
</config>

3
Mage.Server/manifest.mf Normal file
View file

@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

View file

@ -0,0 +1,713 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
*** GENERATED FROM project.xml - DO NOT EDIT ***
*** EDIT ../build.xml INSTEAD ***
For the purpose of easier reading the script
is divided into following sections:
- initialization
- compilation
- jar
- execution
- debugging
- javadoc
- junit compilation
- junit execution
- junit debugging
- applet
- cleanup
-->
<project xmlns:j2seproject1="http://www.netbeans.org/ns/j2se-project/1" xmlns:j2seproject3="http://www.netbeans.org/ns/j2se-project/3" xmlns:jaxrpc="http://www.netbeans.org/ns/j2se-project/jax-rpc" basedir=".." default="default" name="Mage.Server-impl">
<import file="xml_binding_build.xml"/>
<fail message="Please build using Ant 1.7.1 or higher.">
<condition>
<not>
<antversion atleast="1.7.1"/>
</not>
</condition>
</fail>
<target depends="test,jar,javadoc" description="Build and test whole project." name="default"/>
<!--
======================
INITIALIZATION SECTION
======================
-->
<target name="-pre-init">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target depends="-pre-init" name="-init-private">
<property file="nbproject/private/config.properties"/>
<property file="nbproject/private/configs/${config}.properties"/>
<property file="nbproject/private/private.properties"/>
</target>
<target depends="-pre-init,-init-private" name="-init-user">
<property file="${user.properties.file}"/>
<!-- The two properties below are usually overridden -->
<!-- by the active platform. Just a fallback. -->
<property name="default.javac.source" value="1.4"/>
<property name="default.javac.target" value="1.4"/>
</target>
<target depends="-pre-init,-init-private,-init-user" name="-init-project">
<property file="nbproject/configs/${config}.properties"/>
<property file="nbproject/project.properties"/>
</target>
<target depends="-pre-init,-init-private,-init-user,-init-project,-init-macrodef-property" name="-do-init">
<available file="${manifest.file}" property="manifest.available"/>
<condition property="manifest.available+main.class">
<and>
<isset property="manifest.available"/>
<isset property="main.class"/>
<not>
<equals arg1="${main.class}" arg2="" trim="true"/>
</not>
</and>
</condition>
<condition property="manifest.available+main.class+mkdist.available">
<and>
<istrue value="${manifest.available+main.class}"/>
<isset property="libs.CopyLibs.classpath"/>
</and>
</condition>
<condition property="have.tests">
<or>
<available file="${test.src.dir}"/>
</or>
</condition>
<condition property="have.sources">
<or>
<available file="${src.dir}"/>
</or>
</condition>
<condition property="netbeans.home+have.tests">
<and>
<isset property="netbeans.home"/>
<isset property="have.tests"/>
</and>
</condition>
<condition property="no.javadoc.preview">
<and>
<isset property="javadoc.preview"/>
<isfalse value="${javadoc.preview}"/>
</and>
</condition>
<property name="run.jvmargs" value=""/>
<property name="javac.compilerargs" value=""/>
<property name="work.dir" value="${basedir}"/>
<condition property="no.deps">
<and>
<istrue value="${no.dependencies}"/>
</and>
</condition>
<property name="javac.debug" value="true"/>
<property name="javadoc.preview" value="true"/>
<property name="application.args" value=""/>
<property name="source.encoding" value="${file.encoding}"/>
<condition property="javadoc.encoding.used" value="${javadoc.encoding}">
<and>
<isset property="javadoc.encoding"/>
<not>
<equals arg1="${javadoc.encoding}" arg2=""/>
</not>
</and>
</condition>
<property name="javadoc.encoding.used" value="${source.encoding}"/>
<property name="includes" value="**"/>
<property name="excludes" value=""/>
<property name="do.depend" value="false"/>
<condition property="do.depend.true">
<istrue value="${do.depend}"/>
</condition>
<condition else="" property="javac.compilerargs.jaxws" value="-Djava.endorsed.dirs='${jaxws.endorsed.dir}'">
<and>
<isset property="jaxws.endorsed.dir"/>
<available file="nbproject/jaxws-build.xml"/>
</and>
</condition>
</target>
<target name="-post-init">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target depends="-pre-init,-init-private,-init-user,-init-project,-do-init" name="-init-check">
<fail unless="src.dir">Must set src.dir</fail>
<fail unless="test.src.dir">Must set test.src.dir</fail>
<fail unless="build.dir">Must set build.dir</fail>
<fail unless="dist.dir">Must set dist.dir</fail>
<fail unless="build.classes.dir">Must set build.classes.dir</fail>
<fail unless="dist.javadoc.dir">Must set dist.javadoc.dir</fail>
<fail unless="build.test.classes.dir">Must set build.test.classes.dir</fail>
<fail unless="build.test.results.dir">Must set build.test.results.dir</fail>
<fail unless="build.classes.excludes">Must set build.classes.excludes</fail>
<fail unless="dist.jar">Must set dist.jar</fail>
</target>
<target name="-init-macrodef-property">
<macrodef name="property" uri="http://www.netbeans.org/ns/j2se-project/1">
<attribute name="name"/>
<attribute name="value"/>
<sequential>
<property name="@{name}" value="${@{value}}"/>
</sequential>
</macrodef>
</target>
<target name="-init-macrodef-javac">
<macrodef name="javac" uri="http://www.netbeans.org/ns/j2se-project/3">
<attribute default="${src.dir}" name="srcdir"/>
<attribute default="${build.classes.dir}" name="destdir"/>
<attribute default="${javac.classpath}" name="classpath"/>
<attribute default="${includes}" name="includes"/>
<attribute default="${excludes}" name="excludes"/>
<attribute default="${javac.debug}" name="debug"/>
<attribute default="${empty.dir}" name="sourcepath"/>
<attribute default="${empty.dir}" name="gensrcdir"/>
<element name="customize" optional="true"/>
<sequential>
<property location="${build.dir}/empty" name="empty.dir"/>
<mkdir dir="${empty.dir}"/>
<javac debug="@{debug}" deprecation="${javac.deprecation}" destdir="@{destdir}" encoding="${source.encoding}" excludes="@{excludes}" includeantruntime="false" includes="@{includes}" source="${javac.source}" sourcepath="@{sourcepath}" srcdir="@{srcdir}" target="${javac.target}">
<src>
<dirset dir="@{gensrcdir}" erroronmissingdir="false">
<include name="*"/>
</dirset>
</src>
<classpath>
<path path="@{classpath}"/>
</classpath>
<compilerarg line="${javac.compilerargs} ${javac.compilerargs.jaxws}"/>
<customize/>
</javac>
</sequential>
</macrodef>
<macrodef name="depend" uri="http://www.netbeans.org/ns/j2se-project/3">
<attribute default="${src.dir}" name="srcdir"/>
<attribute default="${build.classes.dir}" name="destdir"/>
<attribute default="${javac.classpath}" name="classpath"/>
<sequential>
<depend cache="${build.dir}/depcache" destdir="@{destdir}" excludes="${excludes}" includes="${includes}" srcdir="@{srcdir}">
<classpath>
<path path="@{classpath}"/>
</classpath>
</depend>
</sequential>
</macrodef>
<macrodef name="force-recompile" uri="http://www.netbeans.org/ns/j2se-project/3">
<attribute default="${build.classes.dir}" name="destdir"/>
<sequential>
<fail unless="javac.includes">Must set javac.includes</fail>
<pathconvert pathsep="," property="javac.includes.binary">
<path>
<filelist dir="@{destdir}" files="${javac.includes}"/>
</path>
<globmapper from="*.java" to="*.class"/>
</pathconvert>
<delete>
<files includes="${javac.includes.binary}"/>
</delete>
</sequential>
</macrodef>
</target>
<target name="-init-macrodef-junit">
<macrodef name="junit" uri="http://www.netbeans.org/ns/j2se-project/3">
<attribute default="${includes}" name="includes"/>
<attribute default="${excludes}" name="excludes"/>
<attribute default="**" name="testincludes"/>
<sequential>
<junit dir="${work.dir}" errorproperty="tests.failed" failureproperty="tests.failed" fork="true" showoutput="true">
<batchtest todir="${build.test.results.dir}">
<fileset dir="${test.src.dir}" excludes="@{excludes},${excludes}" includes="@{includes}">
<filename name="@{testincludes}"/>
</fileset>
</batchtest>
<classpath>
<path path="${run.test.classpath}"/>
</classpath>
<syspropertyset>
<propertyref prefix="test-sys-prop."/>
<mapper from="test-sys-prop.*" to="*" type="glob"/>
</syspropertyset>
<formatter type="brief" usefile="false"/>
<formatter type="xml"/>
<jvmarg line="${run.jvmargs}"/>
</junit>
</sequential>
</macrodef>
</target>
<target depends="-init-debug-args" name="-init-macrodef-nbjpda">
<macrodef name="nbjpdastart" uri="http://www.netbeans.org/ns/j2se-project/1">
<attribute default="${main.class}" name="name"/>
<attribute default="${debug.classpath}" name="classpath"/>
<attribute default="" name="stopclassname"/>
<sequential>
<nbjpdastart addressproperty="jpda.address" name="@{name}" stopclassname="@{stopclassname}" transport="${debug-transport}">
<classpath>
<path path="@{classpath}"/>
</classpath>
</nbjpdastart>
</sequential>
</macrodef>
<macrodef name="nbjpdareload" uri="http://www.netbeans.org/ns/j2se-project/1">
<attribute default="${build.classes.dir}" name="dir"/>
<sequential>
<nbjpdareload>
<fileset dir="@{dir}" includes="${fix.classes}">
<include name="${fix.includes}*.class"/>
</fileset>
</nbjpdareload>
</sequential>
</macrodef>
</target>
<target name="-init-debug-args">
<property name="version-output" value="java version &quot;${ant.java.version}"/>
<condition property="have-jdk-older-than-1.4">
<or>
<contains string="${version-output}" substring="java version &quot;1.0"/>
<contains string="${version-output}" substring="java version &quot;1.1"/>
<contains string="${version-output}" substring="java version &quot;1.2"/>
<contains string="${version-output}" substring="java version &quot;1.3"/>
</or>
</condition>
<condition else="-Xdebug" property="debug-args-line" value="-Xdebug -Xnoagent -Djava.compiler=none">
<istrue value="${have-jdk-older-than-1.4}"/>
</condition>
<condition else="dt_socket" property="debug-transport-by-os" value="dt_shmem">
<os family="windows"/>
</condition>
<condition else="${debug-transport-by-os}" property="debug-transport" value="${debug.transport}">
<isset property="debug.transport"/>
</condition>
</target>
<target depends="-init-debug-args" name="-init-macrodef-debug">
<macrodef name="debug" uri="http://www.netbeans.org/ns/j2se-project/3">
<attribute default="${main.class}" name="classname"/>
<attribute default="${debug.classpath}" name="classpath"/>
<element name="customize" optional="true"/>
<sequential>
<java classname="@{classname}" dir="${work.dir}" fork="true">
<jvmarg line="${debug-args-line}"/>
<jvmarg value="-Xrunjdwp:transport=${debug-transport},address=${jpda.address}"/>
<jvmarg value="-Dfile.encoding=${source.encoding}"/>
<redirector errorencoding="${source.encoding}" inputencoding="${source.encoding}" outputencoding="${source.encoding}"/>
<jvmarg line="${run.jvmargs}"/>
<classpath>
<path path="@{classpath}"/>
</classpath>
<syspropertyset>
<propertyref prefix="run-sys-prop."/>
<mapper from="run-sys-prop.*" to="*" type="glob"/>
</syspropertyset>
<customize/>
</java>
</sequential>
</macrodef>
</target>
<target name="-init-macrodef-java">
<macrodef name="java" uri="http://www.netbeans.org/ns/j2se-project/1">
<attribute default="${main.class}" name="classname"/>
<attribute default="${run.classpath}" name="classpath"/>
<element name="customize" optional="true"/>
<sequential>
<java classname="@{classname}" dir="${work.dir}" fork="true">
<jvmarg value="-Dfile.encoding=${source.encoding}"/>
<redirector errorencoding="${source.encoding}" inputencoding="${source.encoding}" outputencoding="${source.encoding}"/>
<jvmarg line="${run.jvmargs}"/>
<classpath>
<path path="@{classpath}"/>
</classpath>
<syspropertyset>
<propertyref prefix="run-sys-prop."/>
<mapper from="run-sys-prop.*" to="*" type="glob"/>
</syspropertyset>
<customize/>
</java>
</sequential>
</macrodef>
</target>
<target name="-init-presetdef-jar">
<presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-project/1">
<jar compress="${jar.compress}" jarfile="${dist.jar}">
<j2seproject1:fileset dir="${build.classes.dir}"/>
</jar>
</presetdef>
</target>
<target depends="-pre-init,-init-private,-init-user,-init-project,-do-init,-post-init,-init-check,-init-macrodef-property,-init-macrodef-javac,-init-macrodef-junit,-init-macrodef-nbjpda,-init-macrodef-debug,-init-macrodef-java,-init-presetdef-jar" name="init"/>
<!--
===================
COMPILATION SECTION
===================
-->
<target depends="init" name="deps-jar" unless="no.deps">
<ant antfile="${project.Mage}/build.xml" inheritall="false" target="jar"/>
<ant antfile="${project.Mage_AI}/build.xml" inheritall="false" target="jar"/>
<ant antfile="${project.Mage_Common}/build.xml" inheritall="false" target="jar"/>
<ant antfile="${project.Mage_HumanPlayer}/build.xml" inheritall="false" target="jar"/>
<ant antfile="${project.Mage_Sets}/build.xml" inheritall="false" target="jar"/>
</target>
<target depends="init,-check-automatic-build,-clean-after-automatic-build" name="-verify-automatic-build"/>
<target depends="init" name="-check-automatic-build">
<available file="${build.classes.dir}/.netbeans_automatic_build" property="netbeans.automatic.build"/>
</target>
<target depends="init" if="netbeans.automatic.build" name="-clean-after-automatic-build">
<antcall target="clean"/>
</target>
<target depends="init,deps-jar,jaxb-code-generation" name="-pre-pre-compile">
<mkdir dir="${build.classes.dir}"/>
</target>
<target name="-pre-compile">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target if="do.depend.true" name="-compile-depend">
<pathconvert property="build.generated.subdirs">
<dirset dir="${build.generated.sources.dir}" erroronmissingdir="false">
<include name="*"/>
</dirset>
</pathconvert>
<j2seproject3:depend srcdir="${src.dir}:${build.generated.subdirs}"/>
</target>
<target depends="init,deps-jar,-pre-pre-compile,-pre-compile,-compile-depend" if="have.sources" name="-do-compile">
<j2seproject3:javac gensrcdir="${build.generated.sources.dir}"/>
<copy todir="${build.classes.dir}">
<fileset dir="${src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
</copy>
</target>
<target name="-post-compile">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile,-do-compile,-post-compile" description="Compile project." name="compile"/>
<target name="-pre-compile-single">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target depends="init,deps-jar,-pre-pre-compile" name="-do-compile-single">
<fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
<j2seproject3:force-recompile/>
<j2seproject3:javac excludes="" gensrcdir="${build.generated.sources.dir}" includes="${javac.includes}" sourcepath="${src.dir}"/>
</target>
<target name="-post-compile-single">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target depends="init,deps-jar,-verify-automatic-build,-pre-pre-compile,-pre-compile-single,-do-compile-single,-post-compile-single" name="compile-single"/>
<!--
====================
JAR BUILDING SECTION
====================
-->
<target depends="init" name="-pre-pre-jar">
<dirname file="${dist.jar}" property="dist.jar.dir"/>
<mkdir dir="${dist.jar.dir}"/>
</target>
<target name="-pre-jar">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target depends="init,compile,-pre-pre-jar,-pre-jar" name="-do-jar-without-manifest" unless="manifest.available">
<j2seproject1:jar/>
</target>
<target depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available" name="-do-jar-with-manifest" unless="manifest.available+main.class">
<j2seproject1:jar manifest="${manifest.file}"/>
</target>
<target depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class" name="-do-jar-with-mainclass" unless="manifest.available+main.class+mkdist.available">
<j2seproject1:jar manifest="${manifest.file}">
<j2seproject1:manifest>
<j2seproject1:attribute name="Main-Class" value="${main.class}"/>
</j2seproject1:manifest>
</j2seproject1:jar>
<echo>To run this application from the command line without Ant, try:</echo>
<property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
<property location="${dist.jar}" name="dist.jar.resolved"/>
<pathconvert property="run.classpath.with.dist.jar">
<path path="${run.classpath}"/>
<map from="${build.classes.dir.resolved}" to="${dist.jar.resolved}"/>
</pathconvert>
<echo>java -cp "${run.classpath.with.dist.jar}" ${main.class}</echo>
</target>
<target depends="init,compile,-pre-pre-jar,-pre-jar" if="manifest.available+main.class+mkdist.available" name="-do-jar-with-libraries">
<property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
<pathconvert property="run.classpath.without.build.classes.dir">
<path path="${run.classpath}"/>
<map from="${build.classes.dir.resolved}" to=""/>
</pathconvert>
<pathconvert pathsep=" " property="jar.classpath">
<path path="${run.classpath.without.build.classes.dir}"/>
<chainedmapper>
<flattenmapper/>
<globmapper from="*" to="lib/*"/>
</chainedmapper>
</pathconvert>
<taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/>
<copylibs compress="${jar.compress}" jarfile="${dist.jar}" manifest="${manifest.file}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
<fileset dir="${build.classes.dir}"/>
<manifest>
<attribute name="Main-Class" value="${main.class}"/>
<attribute name="Class-Path" value="${jar.classpath}"/>
</manifest>
</copylibs>
<echo>To run this application from the command line without Ant, try:</echo>
<property location="${dist.jar}" name="dist.jar.resolved"/>
<echo>java -jar "${dist.jar.resolved}"</echo>
</target>
<target depends="init,compile,-pre-pre-jar,-pre-jar" if="libs.CopyLibs.classpath" name="-do-jar-with-libraries-without-manifest" unless="manifest.available+main.class">
<property location="${build.classes.dir}" name="build.classes.dir.resolved"/>
<pathconvert property="run.classpath.without.build.classes.dir">
<path path="${run.classpath}"/>
<map from="${build.classes.dir.resolved}" to=""/>
</pathconvert>
<pathconvert pathsep=" " property="jar.classpath">
<path path="${run.classpath.without.build.classes.dir}"/>
<chainedmapper>
<flattenmapper/>
<globmapper from="*" to="lib/*"/>
</chainedmapper>
</pathconvert>
<taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/>
<copylibs compress="${jar.compress}" jarfile="${dist.jar}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
<fileset dir="${build.classes.dir}"/>
</copylibs>
</target>
<target name="-post-jar">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target depends="init,compile,-pre-jar,-do-jar-with-manifest,-do-jar-without-manifest,-do-jar-with-mainclass,-do-jar-with-libraries,-do-jar-with-libraries-without-manifest,-post-jar" description="Build JAR." name="jar"/>
<!--
=================
EXECUTION SECTION
=================
-->
<target depends="init,compile" description="Run a main class." name="run">
<j2seproject1:java>
<customize>
<arg line="${application.args}"/>
</customize>
</j2seproject1:java>
</target>
<target name="-do-not-recompile">
<property name="javac.includes.binary" value=""/>
</target>
<target depends="init,-do-not-recompile,compile-single" name="run-single">
<fail unless="run.class">Must select one file in the IDE or set run.class</fail>
<j2seproject1:java classname="${run.class}"/>
</target>
<target depends="init,-do-not-recompile,compile-test-single" name="run-test-with-main">
<fail unless="run.class">Must select one file in the IDE or set run.class</fail>
<j2seproject1:java classname="${run.class}" classpath="${run.test.classpath}"/>
</target>
<!--
=================
DEBUGGING SECTION
=================
-->
<target depends="init" if="netbeans.home" name="-debug-start-debugger">
<j2seproject1:nbjpdastart name="${debug.class}"/>
</target>
<target depends="init" if="netbeans.home" name="-debug-start-debugger-main-test">
<j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${debug.class}"/>
</target>
<target depends="init,compile" name="-debug-start-debuggee">
<j2seproject3:debug>
<customize>
<arg line="${application.args}"/>
</customize>
</j2seproject3:debug>
</target>
<target depends="init,compile,-debug-start-debugger,-debug-start-debuggee" description="Debug project in IDE." if="netbeans.home" name="debug"/>
<target depends="init" if="netbeans.home" name="-debug-start-debugger-stepinto">
<j2seproject1:nbjpdastart stopclassname="${main.class}"/>
</target>
<target depends="init,compile,-debug-start-debugger-stepinto,-debug-start-debuggee" if="netbeans.home" name="debug-stepinto"/>
<target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-single">
<fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
<j2seproject3:debug classname="${debug.class}"/>
</target>
<target depends="init,-do-not-recompile,compile-single,-debug-start-debugger,-debug-start-debuggee-single" if="netbeans.home" name="debug-single"/>
<target depends="init,compile-test-single" if="netbeans.home" name="-debug-start-debuggee-main-test">
<fail unless="debug.class">Must select one file in the IDE or set debug.class</fail>
<j2seproject3:debug classname="${debug.class}" classpath="${debug.test.classpath}"/>
</target>
<target depends="init,-do-not-recompile,compile-test-single,-debug-start-debugger-main-test,-debug-start-debuggee-main-test" if="netbeans.home" name="debug-test-with-main"/>
<target depends="init" name="-pre-debug-fix">
<fail unless="fix.includes">Must set fix.includes</fail>
<property name="javac.includes" value="${fix.includes}.java"/>
</target>
<target depends="init,-pre-debug-fix,compile-single" if="netbeans.home" name="-do-debug-fix">
<j2seproject1:nbjpdareload/>
</target>
<target depends="init,-pre-debug-fix,-do-debug-fix" if="netbeans.home" name="debug-fix"/>
<!--
===============
JAVADOC SECTION
===============
-->
<target depends="init" name="-javadoc-build">
<mkdir dir="${dist.javadoc.dir}"/>
<javadoc additionalparam="${javadoc.additionalparam}" author="${javadoc.author}" charset="UTF-8" destdir="${dist.javadoc.dir}" docencoding="UTF-8" encoding="${javadoc.encoding.used}" failonerror="true" noindex="${javadoc.noindex}" nonavbar="${javadoc.nonavbar}" notree="${javadoc.notree}" private="${javadoc.private}" source="${javac.source}" splitindex="${javadoc.splitindex}" use="${javadoc.use}" useexternalfile="true" version="${javadoc.version}" windowtitle="${javadoc.windowtitle}">
<classpath>
<path path="${javac.classpath}"/>
</classpath>
<fileset dir="${src.dir}" excludes="${excludes}" includes="${includes}">
<filename name="**/*.java"/>
</fileset>
<fileset dir="${build.generated.sources.dir}" erroronmissingdir="false">
<include name="**/*.java"/>
</fileset>
</javadoc>
</target>
<target depends="init,-javadoc-build" if="netbeans.home" name="-javadoc-browse" unless="no.javadoc.preview">
<nbbrowse file="${dist.javadoc.dir}/index.html"/>
</target>
<target depends="init,-javadoc-build,-javadoc-browse" description="Build Javadoc." name="javadoc"/>
<!--
=========================
JUNIT COMPILATION SECTION
=========================
-->
<target depends="init,compile" if="have.tests" name="-pre-pre-compile-test">
<mkdir dir="${build.test.classes.dir}"/>
</target>
<target name="-pre-compile-test">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target if="do.depend.true" name="-compile-test-depend">
<j2seproject3:depend classpath="${javac.test.classpath}" destdir="${build.test.classes.dir}" srcdir="${test.src.dir}"/>
</target>
<target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-compile-test-depend" if="have.tests" name="-do-compile-test">
<j2seproject3:javac classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" srcdir="${test.src.dir}"/>
<copy todir="${build.test.classes.dir}">
<fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
</copy>
</target>
<target name="-post-compile-test">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target depends="init,compile,-pre-pre-compile-test,-pre-compile-test,-do-compile-test,-post-compile-test" name="compile-test"/>
<target name="-pre-compile-test-single">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single" if="have.tests" name="-do-compile-test-single">
<fail unless="javac.includes">Must select some files in the IDE or set javac.includes</fail>
<j2seproject3:force-recompile destdir="${build.test.classes.dir}"/>
<j2seproject3:javac classpath="${javac.test.classpath}" debug="true" destdir="${build.test.classes.dir}" excludes="" includes="${javac.includes}" sourcepath="${test.src.dir}" srcdir="${test.src.dir}"/>
<copy todir="${build.test.classes.dir}">
<fileset dir="${test.src.dir}" excludes="${build.classes.excludes},${excludes}" includes="${includes}"/>
</copy>
</target>
<target name="-post-compile-test-single">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target depends="init,compile,-pre-pre-compile-test,-pre-compile-test-single,-do-compile-test-single,-post-compile-test-single" name="compile-test-single"/>
<!--
=======================
JUNIT EXECUTION SECTION
=======================
-->
<target depends="init" if="have.tests" name="-pre-test-run">
<mkdir dir="${build.test.results.dir}"/>
</target>
<target depends="init,compile-test,-pre-test-run" if="have.tests" name="-do-test-run">
<j2seproject3:junit testincludes="**/*Test.java"/>
</target>
<target depends="init,compile-test,-pre-test-run,-do-test-run" if="have.tests" name="-post-test-run">
<fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
</target>
<target depends="init" if="have.tests" name="test-report"/>
<target depends="init" if="netbeans.home+have.tests" name="-test-browse"/>
<target depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" description="Run unit tests." name="test"/>
<target depends="init" if="have.tests" name="-pre-test-run-single">
<mkdir dir="${build.test.results.dir}"/>
</target>
<target depends="init,compile-test-single,-pre-test-run-single" if="have.tests" name="-do-test-run-single">
<fail unless="test.includes">Must select some files in the IDE or set test.includes</fail>
<j2seproject3:junit excludes="" includes="${test.includes}"/>
</target>
<target depends="init,compile-test-single,-pre-test-run-single,-do-test-run-single" if="have.tests" name="-post-test-run-single">
<fail if="tests.failed" unless="ignore.failing.tests">Some tests failed; see details above.</fail>
</target>
<target depends="init,-do-not-recompile,compile-test-single,-pre-test-run-single,-do-test-run-single,-post-test-run-single" description="Run single unit test." name="test-single"/>
<!--
=======================
JUNIT DEBUGGING SECTION
=======================
-->
<target depends="init,compile-test" if="have.tests" name="-debug-start-debuggee-test">
<fail unless="test.class">Must select one file in the IDE or set test.class</fail>
<property location="${build.test.results.dir}/TEST-${test.class}.xml" name="test.report.file"/>
<delete file="${test.report.file}"/>
<mkdir dir="${build.test.results.dir}"/>
<j2seproject3:debug classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTestRunner" classpath="${ant.home}/lib/ant.jar:${ant.home}/lib/ant-junit.jar:${debug.test.classpath}">
<customize>
<syspropertyset>
<propertyref prefix="test-sys-prop."/>
<mapper from="test-sys-prop.*" to="*" type="glob"/>
</syspropertyset>
<arg value="${test.class}"/>
<arg value="showoutput=true"/>
<arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.BriefJUnitResultFormatter"/>
<arg value="formatter=org.apache.tools.ant.taskdefs.optional.junit.XMLJUnitResultFormatter,${test.report.file}"/>
</customize>
</j2seproject3:debug>
</target>
<target depends="init,compile-test" if="netbeans.home+have.tests" name="-debug-start-debugger-test">
<j2seproject1:nbjpdastart classpath="${debug.test.classpath}" name="${test.class}"/>
</target>
<target depends="init,-do-not-recompile,compile-test-single,-debug-start-debugger-test,-debug-start-debuggee-test" name="debug-test"/>
<target depends="init,-pre-debug-fix,compile-test-single" if="netbeans.home" name="-do-debug-fix-test">
<j2seproject1:nbjpdareload dir="${build.test.classes.dir}"/>
</target>
<target depends="init,-pre-debug-fix,-do-debug-fix-test" if="netbeans.home" name="debug-fix-test"/>
<!--
=========================
APPLET EXECUTION SECTION
=========================
-->
<target depends="init,compile-single" name="run-applet">
<fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
<j2seproject1:java classname="sun.applet.AppletViewer">
<customize>
<arg value="${applet.url}"/>
</customize>
</j2seproject1:java>
</target>
<!--
=========================
APPLET DEBUGGING SECTION
=========================
-->
<target depends="init,compile-single" if="netbeans.home" name="-debug-start-debuggee-applet">
<fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>
<j2seproject3:debug classname="sun.applet.AppletViewer">
<customize>
<arg value="${applet.url}"/>
</customize>
</j2seproject3:debug>
</target>
<target depends="init,compile-single,-debug-start-debugger,-debug-start-debuggee-applet" if="netbeans.home" name="debug-applet"/>
<!--
===============
CLEANUP SECTION
===============
-->
<target depends="init" name="deps-clean" unless="no.deps">
<ant antfile="${project.Mage}/build.xml" inheritall="false" target="clean"/>
<ant antfile="${project.Mage_AI}/build.xml" inheritall="false" target="clean"/>
<ant antfile="${project.Mage_Common}/build.xml" inheritall="false" target="clean"/>
<ant antfile="${project.Mage_HumanPlayer}/build.xml" inheritall="false" target="clean"/>
<ant antfile="${project.Mage_Sets}/build.xml" inheritall="false" target="clean"/>
</target>
<target depends="init" name="-do-clean">
<delete dir="${build.dir}"/>
<delete dir="${dist.dir}"/>
</target>
<target name="-post-clean">
<!-- Empty placeholder for easier customization. -->
<!-- You can override this target in the ../build.xml file. -->
</target>
<target depends="init,deps-clean,-do-clean,-post-clean" description="Clean build products." name="clean"/>
</project>

View file

@ -0,0 +1,8 @@
build.xml.data.CRC32=0771c912
build.xml.script.CRC32=7fe29de1
build.xml.stylesheet.CRC32=958a1d3e@1.26.2.45
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=c70740ce
nbproject/build-impl.xml.script.CRC32=5b9b3297
nbproject/build-impl.xml.stylesheet.CRC32=5c621a33@1.26.2.45

View file

@ -0,0 +1,83 @@
application.title=MageServer
application.vendor=BetaSteward_at_googlemail.com
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.test.classpath=\
${run.test.classpath}
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/Mage.Server.jar
dist.javadoc.dir=${dist.dir}/javadoc
excludes=
includes=**
jar.compress=false
javac.classpath=\
${reference.Mage.jar}:\
${reference.Mage_Common.jar}:\
${reference.Mage_Sets.jar}:\
${reference.Mage_HumanPlayer.jar}:\
${reference.Mage_AI.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.source=1.6
javac.target=1.6
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}:\
${libs.junit.classpath}:\
${libs.junit_4.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
jaxbwiz.endorsed.dirs="${netbeans.home}/../ide9/modules/ext/jaxb/api"
jaxbwiz.gensrc.classpath=${libs.jaxb.classpath}
jaxbwiz.xjcdef.classpath=${libs.jaxb.classpath}
jaxbwiz.xjcrun.classpath=${libs.jaxb.classpath}
main.class=mage.server.Main
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
platform.active=default_platform
project.license=bsd
project.Mage=../Mage
project.Mage_AI=../Mage.AI
project.Mage_Common=../Mage.Common
project.Mage_HumanPlayer=../Mage.HumanPlayer
project.Mage_Sets=../Mage.Sets
reference.Mage.jar=${project.Mage}/dist/Mage.jar
reference.Mage_AI.jar=${project.Mage_AI}/dist/Mage.AI.jar
reference.Mage_Common.jar=${project.Mage_Common}/dist/Mage.Common.jar
reference.Mage_HumanPlayer.jar=${project.Mage_HumanPlayer}/dist/Mage.HumanPlayer.jar
reference.Mage_Sets.jar=${project.Mage_Sets}/dist/Mage.Sets.jar
run-sys-prop.java.endorsed.dirs=${jaxbwiz.endorsed.dirs}
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
run.jvmargs=-server -Djava.security.policy=src/security.policy
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test
app.version=0.1

View file

@ -0,0 +1,62 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<buildExtensions xmlns="http://www.netbeans.org/ns/ant-build-extender/1">
<extension file="xml_binding_build.xml" id="jaxb">
<dependency dependsOn="jaxb-code-generation" target="-pre-pre-compile"/>
</extension>
</buildExtensions>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>Mage.Server</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
<references xmlns="http://www.netbeans.org/ns/ant-project-references/1">
<reference>
<foreign-project>Mage</foreign-project>
<artifact-type>jar</artifact-type>
<script>build.xml</script>
<target>jar</target>
<clean-target>clean</clean-target>
<id>jar</id>
</reference>
<reference>
<foreign-project>Mage_AI</foreign-project>
<artifact-type>jar</artifact-type>
<script>build.xml</script>
<target>jar</target>
<clean-target>clean</clean-target>
<id>jar</id>
</reference>
<reference>
<foreign-project>Mage_Common</foreign-project>
<artifact-type>jar</artifact-type>
<script>build.xml</script>
<target>jar</target>
<clean-target>clean</clean-target>
<id>jar</id>
</reference>
<reference>
<foreign-project>Mage_HumanPlayer</foreign-project>
<artifact-type>jar</artifact-type>
<script>build.xml</script>
<target>jar</target>
<clean-target>clean</clean-target>
<id>jar</id>
</reference>
<reference>
<foreign-project>Mage_Sets</foreign-project>
<artifact-type>jar</artifact-type>
<script>build.xml</script>
<target>jar</target>
<clean-target>clean</clean-target>
<id>jar</id>
</reference>
</references>
</configuration>
</project>

View file

@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
*** GENERATED FROM xml_binding_cfg.xml - DO NOT EDIT ***
*** Configure thru JAXB Wizard. ***
-->
<project name="Mage.Server_jaxb" default="default" basedir=".">
<target name="xjc-typedef-target" depends="-init-project">
<typedef classname="com.sun.tools.xjc.XJCTask" name="xjc" xmlns:s="http://xml.netbeans.org/schema/JAXBWizConfig">
<classpath path="${jaxbwiz.xjcdef.classpath}"/>
</typedef>
</target>
<target name="jaxb-clean-code-generation" depends="clean,jaxb-code-generation"/>
<target name="jaxb-code-generation" depends="xjc-typedef-target,-do-init,-init-macrodef-javac">
<mkdir dir="${build.generated.sources.dir}/jaxb" xmlns:s="http://xml.netbeans.org/schema/JAXBWizConfig"/>
<mkdir dir="build/generated/jaxbCache" xmlns:s="http://xml.netbeans.org/schema/JAXBWizConfig"/>
<mkdir dir="build/generated/jaxbCache/Config"/>
<xjc package="mage.server.util.config" destdir="build/generated/jaxbCache/Config" catalog="catalog.xml">
<classpath>
<pathelement location="${src.dir}"/>
<pathelement path="${jaxbwiz.xjcrun.classpath}"/>
</classpath>
<arg value="-xmlschema"/>
<schema file="xml-resources/jaxb/Config/Config.xsd"/>
<depends file="xml-resources/jaxb/Config/Config.xsd"/>
<produces dir="build/generated/jaxbCache/Config"/>
</xjc>
<copy todir="${build.generated.sources.dir}/jaxb">
<fileset dir="build/generated/jaxbCache/Config"/>
</copy>
</target>
</project>

View file

@ -0,0 +1,13 @@
<?xml version='1.0' encoding='UTF-8' ?>
<schemas xmlns='http://xml.netbeans.org/schema/JAXBWizConfig' destdir='build/generated-sources/jaxb' projectName='Mage.Server' version='1.0'>
<schema type='-xmlschema' package='mage.server.util.config' name='Config'>
<xjc-options>
</xjc-options>
<schema-sources>
<schema-source location='xml-resources/jaxb/Config/Config.xsd' origLocation='src/mage/server/util/Config.xsd'/>
</schema-sources>
<bindings>
</bindings>
<catalog/>
</schema>
</schemas>

Binary file not shown.

Binary file not shown.

Binary file not shown.

View file

@ -0,0 +1 @@
start java -jar .\MageServer.jar

View file

@ -0,0 +1,72 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import mage.interfaces.ChatClient;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class ChatManager {
private final static ChatManager INSTANCE = new ChatManager();
public static ChatManager getInstance() {
return INSTANCE;
}
private ChatManager() {}
private ConcurrentHashMap<UUID, ChatSession> chatSessions = new ConcurrentHashMap<UUID, ChatSession>();
public UUID createChatSession() {
ChatSession chatSession = new ChatSession();
chatSessions.put(chatSession.getChatId(), chatSession);
return chatSession.getChatId();
}
public void joinChat(UUID chatId, ChatClient client) {
chatSessions.get(chatId).join(client);
}
public void leaveChat(UUID chatId, UUID clientId) {
chatSessions.get(chatId).leave(clientId);
}
public void destroyChatSession(UUID chatId) {
chatSessions.remove(chatId);
}
public void broadcast(UUID chatId, String userName, String message) {
chatSessions.get(chatId).broadcast(userName, message);
}
}

View file

@ -0,0 +1,119 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server;
import mage.server.util.ThreadExecutor;
import java.rmi.RemoteException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.interfaces.ChatClient;
import mage.util.Logging;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class ChatSession {
private static ExecutorService executor = ThreadExecutor.getInstance().getRMIExecutor();
private final static Logger logger = Logging.getLogger(ChatSession.class.getName());
private ConcurrentHashMap<UUID, ChatClient> clients = new ConcurrentHashMap<UUID, ChatClient>();
private UUID chatId;
private DateFormat timeFormatter = SimpleDateFormat.getTimeInstance(SimpleDateFormat.SHORT);
//TODO: use sessionId for chatting - prevents sending without being part of the chat
public ChatSession() {
chatId = UUID.randomUUID();
}
public void join(ChatClient client) {
try {
logger.log(Level.INFO, "joining chat " + chatId);
clients.put(client.getId(), client);
broadcast(client.getName(), " has joined");
} catch (RemoteException ex) {
logger.log(Level.SEVERE, null, ex);
}
}
public void leave(UUID clientId) {
if (clients.contains(clientId)) {
String clientName = "";
try {
clientName = clients.get(clientId).getName();
} catch (RemoteException ex) {
logger.log(Level.SEVERE, null, ex);
}
kill(clientId);
broadcast(clientName, " has left");
}
}
public void kill(UUID clientId) {
if (clients.contains(clientId))
clients.remove(clientId);
}
public void broadcast(final String userName, final String message) {
Calendar cal = new GregorianCalendar();
final String msg = timeFormatter.format(cal.getTime()) + " " + userName + ":" + message;
for (final Entry<UUID, ChatClient> entry: clients.entrySet()) {
executor.submit(
new Runnable() {
public void run() {
try {
entry.getValue().receiveMessage(msg);
}
catch (RemoteException ex) {
logger.log(Level.WARNING, ex.getMessage());
kill(entry.getKey());
}
}
}
);
}
}
/**
* @return the chatId
*/
public UUID getChatId() {
return chatId;
}
}

View file

@ -0,0 +1,80 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server;
import java.io.File;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.interfaces.Server;
import mage.server.game.GameFactory;
import mage.server.game.PlayerFactory;
import mage.server.util.ConfigSettings;
import mage.server.util.config.Plugin;
import mage.util.Logging;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class Main {
private static Logger logger = Logging.getLogger(Main.class.getName());
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
logger.info("Starting MAGE server version " + Main.class.getPackage().getImplementationVersion());
ConfigSettings config = ConfigSettings.getInstance();
for (Plugin plugin: config.getGameTypes()) {
GameFactory.getInstance().addGameType(plugin.getName(), loadPlugin(plugin));
}
for (Plugin plugin: config.getPlayerTypes()) {
PlayerFactory.getInstance().addPlayerType(plugin.getName(), loadPlugin(plugin));
}
Server server = new ServerImpl(config.getPort(), config.getServerName());
}
private static Class<?> loadPlugin(Plugin plugin) {
try {
File jarFile = new File("plugins/" + plugin.getJar());
URLClassLoader urlClassLoader = URLClassLoader.newInstance(new URL[] { jarFile.toURI().toURL() }, Main.class.getClassLoader());
logger.info("Loaded plugin: " + plugin.getClassName());
return Class.forName(plugin.getClassName(), true, urlClassLoader);
} catch (Exception ex) {
logger.log(Level.SEVERE, "Error loading plugin " + plugin.getJar(), ex);
}
return null;
}
}

View file

@ -0,0 +1,440 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.rmi.server.UnicastRemoteObject;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.Constants.DeckType;
import mage.interfaces.ChatClient;
import mage.interfaces.Client;
import mage.cards.decks.DeckCardLists;
import mage.interfaces.GameClient;
import mage.interfaces.GameReplayClient;
import mage.interfaces.MageException;
import mage.interfaces.Server;
import mage.server.game.GameFactory;
import mage.server.game.GameManager;
import mage.server.game.GamesRoomManager;
import mage.server.game.PlayerFactory;
import mage.server.game.ReplayManager;
import mage.server.game.TableManager;
import mage.util.Logging;
import mage.view.TableView;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class ServerImpl implements Server {
private final static Logger logger = Logging.getLogger("Mage Server");
public ServerImpl(int port, String name) {
try {
System.setSecurityManager(null);
Registry reg = LocateRegistry.createRegistry(port);
Server server = (Server) UnicastRemoteObject.exportObject(this, 0);
reg.rebind(name, server);
logger.info("Started MAGE server - listening on port " + port);
} catch (RemoteException ex) {
logger.log(Level.SEVERE, "Failed to start RMI server at port " + port, ex);
}
}
@Override
public UUID registerClient(Client c) throws RemoteException {
UUID sessionId = SessionManager.getInstance().createSession(c);
logger.info("Session " + sessionId + " created for client " + c.getId());
return sessionId;
}
@Override
public TableView createTable(UUID sessionId, UUID roomId, String gameType, DeckType deckType, List<String> playerTypes) throws MageException {
try {
TableView table = GamesRoomManager.getInstance().getRoom(roomId).createTable(sessionId, gameType, deckType, playerTypes);
logger.info("Table " + table.getTableId() + " created");
return table;
}
catch (Exception ex) {
handleException(ex);
}
return null;
}
@Override
public void removeTable(UUID sessionId, UUID roomId, UUID tableId) throws MageException {
try {
GamesRoomManager.getInstance().getRoom(roomId).removeTable(sessionId, tableId);
}
catch (Exception ex) {
handleException(ex);
}
}
@Override
public boolean joinTable(UUID sessionId, UUID roomId, UUID tableId, int seatNum, String name, DeckCardLists deckList) throws MageException {
try {
boolean ret = GamesRoomManager.getInstance().getRoom(roomId).joinTable(sessionId, tableId, seatNum, name, deckList);
logger.info("Session " + sessionId + " joined table " + tableId);
return ret;
}
catch (Exception ex) {
handleException(ex);
}
return false;
}
@Override
public Collection<TableView> getTables(UUID roomId) throws MageException {
try {
return GamesRoomManager.getInstance().getRoom(roomId).getTables();
}
catch (Exception ex) {
handleException(ex);
}
return null;
}
@Override
public TableView getTable(UUID roomId, UUID tableId) throws MageException {
try {
return GamesRoomManager.getInstance().getRoom(roomId).getTable(tableId);
}
catch (Exception ex) {
handleException(ex);
}
return null;
}
@Override
public void deregisterClient(UUID sessionId) throws MageException {
try {
SessionManager.getInstance().getSession(sessionId).kill();
logger.info("Client deregistered ...");
}
catch (Exception ex) {
handleException(ex);
}
}
@Override
public void startGame(UUID sessionId, UUID roomId, UUID tableId) throws MageException {
try {
TableManager.getInstance().startGame(sessionId, roomId, tableId);
}
catch (Exception ex) {
handleException(ex);
}
}
@Override
public void sendChatMessage(UUID chatId, String userName, String message) throws MageException {
try {
ChatManager.getInstance().broadcast(chatId, userName, message);
}
catch (Exception ex) {
handleException(ex);
}
}
@Override
public void joinChat(UUID chatId, ChatClient chatClient) throws MageException {
try {
ChatManager.getInstance().joinChat(chatId, chatClient);
}
catch (Exception ex) {
handleException(ex);
}
}
@Override
public void leaveChat(UUID chatId, UUID clientId) throws MageException {
try {
ChatManager.getInstance().leaveChat(chatId, clientId);
}
catch (Exception ex) {
handleException(ex);
}
}
@Override
public UUID getMainRoomId() throws MageException {
try {
return GamesRoomManager.getInstance().getMainRoomId();
}
catch (Exception ex) {
handleException(ex);
}
return null;
}
@Override
public UUID getRoomChatId(UUID roomId) throws MageException {
try {
return GamesRoomManager.getInstance().getRoom(roomId).getChatId();
}
catch (Exception ex) {
handleException(ex);
}
return null;
}
@Override
public boolean isTableOwner(UUID sessionId, UUID roomId, UUID tableId) throws MageException {
try {
return TableManager.getInstance().isTableOwner(tableId, sessionId);
}
catch (Exception ex) {
handleException(ex);
}
return false;
}
@Override
public void leaveTable(UUID sessionId, UUID roomId, UUID tableId) throws MageException {
try {
GamesRoomManager.getInstance().getRoom(roomId).leaveTable(sessionId, tableId);
}
catch (Exception ex) {
handleException(ex);
}
}
@Override
public UUID getTableChatId(UUID tableId) throws MageException {
try {
return TableManager.getInstance().getChatId(tableId);
}
catch (Exception ex) {
handleException(ex);
}
return null;
}
@Override
public void joinGame(UUID gameId, UUID sessionId, GameClient gameClient) throws MageException {
try {
GameManager.getInstance().joinGame(gameId, sessionId, gameClient);
}
catch (Exception ex) {
handleException(ex);
}
}
@Override
public UUID getGameChatId(UUID gameId) throws MageException {
try {
return GameManager.getInstance().getChatId(gameId);
}
catch (Exception ex) {
handleException(ex);
}
return null;
}
@Override
public void sendPlayerUUID(UUID gameId, UUID sessionId, UUID data) throws MageException {
try {
GameManager.getInstance().sendPlayerUUID(gameId, sessionId, data);
}
catch (Exception ex) {
handleException(ex);
}
}
@Override
public void sendPlayerString(UUID gameId, UUID sessionId, String data) throws MageException {
try {
GameManager.getInstance().sendPlayerString(gameId, sessionId, data);
}
catch (Exception ex) {
handleException(ex);
}
}
@Override
public void sendPlayerBoolean(UUID gameId, UUID sessionId, Boolean data) throws MageException {
try {
GameManager.getInstance().sendPlayerBoolean(gameId, sessionId, data);
}
catch (Exception ex) {
handleException(ex);
}
}
@Override
public void sendPlayerInteger(UUID gameId, UUID sessionId, Integer data) throws RemoteException, MageException {
try {
GameManager.getInstance().sendPlayerInteger(gameId, sessionId, data);
}
catch (Exception ex) {
handleException(ex);
}
}
@Override
public void concedeGame(UUID gameId, UUID sessionId) throws MageException {
try {
GameManager.getInstance().concedeGame(gameId, sessionId);
}
catch (Exception ex) {
handleException(ex);
}
}
@Override
public boolean watchTable(UUID sessionId, UUID roomId, UUID tableId) throws MageException {
try {
return GamesRoomManager.getInstance().getRoom(roomId).watchTable(sessionId, tableId);
}
catch (Exception ex) {
handleException(ex);
}
return false;
}
@Override
public void watchGame(UUID gameId, UUID sessionId, GameClient gameClient) throws MageException {
try {
GameManager.getInstance().watchGame(gameId, sessionId, gameClient);
}
catch (Exception ex) {
handleException(ex);
}
}
@Override
public void stopWatching(UUID gameId, UUID clientId) throws MageException {
try {
GameManager.getInstance().stopWatching(gameId, clientId);
}
catch (Exception ex) {
handleException(ex);
}
}
@Override
public void replayGame(UUID gameId, UUID sessionId, GameReplayClient replayClient) throws MageException {
try {
ReplayManager.getInstance().startReplay(sessionId, replayClient);
}
catch (Exception ex) {
handleException(ex);
}
}
@Override
public void stopReplay(UUID sessionId) throws MageException {
try {
ReplayManager.getInstance().stopReplay(sessionId);
}
catch (Exception ex) {
handleException(ex);
}
}
@Override
public void nextPlay(UUID sessionId) throws MageException {
try {
ReplayManager.getInstance().nextPlay(sessionId);
}
catch (Exception ex) {
handleException(ex);
}
}
@Override
public void previousPlay(UUID sessionId) throws MageException {
try {
ReplayManager.getInstance().previousPlay(sessionId);
}
catch (Exception ex) {
handleException(ex);
}
}
@Override
public boolean replayTable(UUID sessionId, UUID roomId, UUID tableId) throws MageException {
try {
return TableManager.getInstance().replayTable(sessionId, tableId);
}
catch (Exception ex) {
handleException(ex);
}
return false;
}
@Override
public String[] getGameTypes() throws MageException {
try {
return GameFactory.getInstance().getGameTypes().toArray(new String[0]);
}
catch (Exception ex) {
handleException(ex);
}
return null;
}
@Override
public String[] getPlayerTypes() throws MageException {
try {
return PlayerFactory.getInstance().getPlayerTypes().toArray(new String[0]);
}
catch (Exception ex) {
handleException(ex);
}
return null;
}
@Override
public void cheat(UUID gameId, UUID sessionId, DeckCardLists deckList) throws MageException {
try {
// GameManager.getInstance().cheat(gameId, sessionId, deckList);
}
catch (Exception ex) {
handleException(ex);
}
}
public void handleException(Exception ex) throws MageException {
logger.log(Level.SEVERE, "", ex);
throw new MageException("Server error");
}
}

View file

@ -0,0 +1,132 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server;
import mage.server.util.ThreadExecutor;
import java.rmi.RemoteException;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.interfaces.Client;
import mage.server.game.GameManager;
import mage.server.game.TableManager;
import mage.util.Logging;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class Session {
private static ExecutorService executor = ThreadExecutor.getInstance().getRMIExecutor();
private final static Logger logger = Logging.getLogger(Session.class.getName());
private UUID sessionId;
private String username;
private Client client;
public Session(Client client) {
sessionId = UUID.randomUUID();
try {
username = client.getUserName();
} catch (RemoteException ex) {
logger.log(Level.SEVERE, null, ex);
}
this.client = client;
}
public UUID getId() {
return sessionId;
}
public void kill() {
SessionManager.getInstance().removeSession(sessionId);
TableManager.getInstance().removeSession(sessionId);
GameManager.getInstance().removeSession(sessionId);
}
public void gameStarted(final UUID gameId, final UUID playerId) {
executor.submit(
new Runnable() {
@Override
public void run() {
try {
client.gameStarted(gameId, playerId);
logger.info("game started for player " + playerId);
}
catch (RemoteException ex) {
logger.log(Level.WARNING, ex.getMessage());
kill();
}
}
}
);
}
public void watchGame(final UUID gameId) {
executor.submit(
new Runnable() {
@Override
public void run() {
try {
client.watchGame(gameId);
}
catch (RemoteException ex) {
logger.log(Level.WARNING, ex.getMessage());
kill();
}
}
}
);
}
public void replayGame(final UUID gameId) {
executor.submit(
new Runnable() {
@Override
public void run() {
try {
client.replayGame(gameId);
}
catch (RemoteException ex) {
logger.log(Level.WARNING, ex.getMessage());
kill();
}
}
}
);
}
public String getUsername() {
return username;
}
}

View file

@ -0,0 +1,64 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import mage.interfaces.Client;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class SessionManager {
private final static SessionManager INSTANCE = new SessionManager();
public static SessionManager getInstance() {
return INSTANCE;
}
private ConcurrentHashMap<UUID, Session> sessions = new ConcurrentHashMap<UUID, Session>();
public Session getSession(UUID sessionId) {
return sessions.get(sessionId);
}
public UUID createSession(Client c) {
Session session = new Session(c);
sessions.put(session.getId(), session);
return session.getId();
}
public void removeSession(UUID sessionId) {
sessions.remove(sessionId);
}
}

View file

@ -0,0 +1,39 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.game;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public interface GameCallback {
public void gameResult(String result);
}

View file

@ -0,0 +1,354 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.game;
import java.util.Collection;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.abilities.ActivatedAbility;
import mage.cards.Card;
import mage.cards.Cards;
import mage.cards.decks.Deck;
import mage.cards.decks.DeckCardLists;
import mage.game.Game;
import mage.game.GameReplay;
import mage.game.events.TableEvent;
import mage.interfaces.GameClient;
import mage.server.ChatManager;
import mage.server.util.ThreadExecutor;
import mage.game.events.Listener;
import mage.game.events.PlayerQueryEvent;
import mage.human.HumanPlayer;
import mage.players.Player;
import mage.util.Logging;
import mage.view.AbilityPickerView;
import mage.view.CardsView;
import mage.view.GameView;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class GameController implements GameCallback {
private static ExecutorService gameExecutor = ThreadExecutor.getInstance().getGameExecutor();
private final static Logger logger = Logging.getLogger(GameController.class.getName());
private ConcurrentHashMap<UUID, GameSession> gameSessions = new ConcurrentHashMap<UUID, GameSession>();
private ConcurrentHashMap<UUID, GameWatcher> watchers = new ConcurrentHashMap<UUID, GameWatcher>();
private ConcurrentHashMap<UUID, UUID> sessionPlayerMap;
private UUID gameSessionId;
private Game game;
private UUID chatId;
private UUID tableId;
private Future<?> gameFuture;
public GameController(Game game, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId) {
gameSessionId = UUID.randomUUID();
this.sessionPlayerMap = sessionPlayerMap;
chatId = ChatManager.getInstance().createChatSession();
this.game = game;
this.tableId = tableId;
init();
}
private void init() {
game.addTableEventListener(
new Listener<TableEvent> () {
@Override
public void event(TableEvent event) {
switch (event.getEventType()) {
case UPDATE:
updateGame();
break;
case INFO:
ChatManager.getInstance().broadcast(chatId, "", event.getMessage());
logger.info(game.getId() + " " + event.getMessage());
break;
}
}
}
);
game.addPlayerQueryEventListener(
new Listener<PlayerQueryEvent> () {
@Override
public void event(PlayerQueryEvent event) {
switch (event.getQueryType()) {
case ASK:
ask(event.getPlayerId(), event.getMessage());
break;
case PICK_TARGET:
target(event.getPlayerId(), event.getMessage(), event.getCards(), event.isRequired());
break;
case SELECT:
select(event.getPlayerId(), event.getMessage());
break;
case PLAY_MANA:
playMana(event.getPlayerId(), event.getMessage());
break;
case PLAY_X_MANA:
playXMana(event.getPlayerId(), event.getMessage());
break;
case CHOOSE_ABILITY:
chooseAbility(event.getPlayerId(), event.getAbilities());
break;
case CHOOSE:
choose(event.getPlayerId(), event.getMessage(), event.getChoices());
break;
case AMOUNT:
amount(event.getPlayerId(), event.getMessage(), event.getMin(), event.getMax());
break;
}
}
}
);
}
private UUID getPlayerId(UUID sessionId) {
return sessionPlayerMap.get(sessionId);
}
public void join(UUID sessionId, GameClient client) {
UUID playerId = sessionPlayerMap.get(sessionId);
GameSession gameSession = new GameSession(client, game, sessionId, playerId);
gameSessions.put(playerId, gameSession);
logger.log(Level.INFO, "player " + playerId + " has joined game " + game.getId());
gameSession.init(getGameView(playerId));
ChatManager.getInstance().broadcast(chatId, "", game.getPlayer(playerId).getName() + " has joined the game");
if (allJoined()) {
startGame();
}
}
private synchronized void startGame() {
if (gameFuture == null) {
GameWorker worker = new GameWorker(game, this);
gameFuture = gameExecutor.submit(worker);
}
}
private boolean allJoined() {
for (Player player: game.getPlayers().values()) {
if (player instanceof HumanPlayer && gameSessions.get(player.getId()) == null) {
return false;
}
}
return true;
}
public void watch(UUID sessionId, GameClient client) {
GameWatcher gameWatcher = new GameWatcher(client, sessionId, game.getId());
watchers.put(sessionId, gameWatcher);
gameWatcher.init(getGameView());
ChatManager.getInstance().broadcast(chatId, "", " has started watching");
}
public GameReplay createReplay() {
if (game.isGameOver()) {
return new GameReplay(game.getGameStates());
}
return null;
}
public void stopWatching(UUID sessionId) {
watchers.remove(sessionId);
ChatManager.getInstance().broadcast(chatId, "", " has stopped watching");
}
public void concede(UUID sessionId) {
game.concede(getPlayerId(sessionId));
}
private void leave(UUID sessionId) {
game.quit(getPlayerId(sessionId));
}
public void cheat(UUID sessionId, DeckCardLists deckList) {
Player player = game.getPlayer(getPlayerId(sessionId));
Deck deck = Deck.load(deckList);
deck.setOwnerId(player.getId());
for (Card card: deck.getCards().values()) {
player.putOntoBattlefield(card, game);
}
updateGame();
}
// public void timeout(UUID sessionId) {
// kill(sessionId);
// }
public void kill(UUID sessionId) {
if (sessionPlayerMap.containsKey(sessionId)) {
gameSessions.get(sessionPlayerMap.get(sessionId)).setKilled();
gameSessions.remove(sessionPlayerMap.get(sessionId));
leave(sessionId);
sessionPlayerMap.remove(sessionId);
}
if (watchers.containsKey(sessionId)) {
watchers.get(sessionId).setKilled();
watchers.remove(sessionId);
}
}
public void timeout(UUID sessionId) {
if (sessionPlayerMap.containsKey(sessionId)) {
ChatManager.getInstance().broadcast(chatId, "", game.getPlayer(sessionPlayerMap.get(sessionId)).getName() + " has timed out. Auto concede.");
concede(sessionId);
}
}
public void endGame(final String message) {
for (final GameSession gameSession: gameSessions.values()) {
gameSession.gameOver(message);
}
for (final GameWatcher gameWatcher: watchers.values()) {
gameWatcher.gameOver(message);
}
TableManager.getInstance().endGame(tableId);
}
public UUID getSessionId() {
return this.gameSessionId;
}
public UUID getChatId() {
return chatId;
}
public void sendPlayerUUID(UUID sessionId, UUID data) {
gameSessions.get(sessionPlayerMap.get(sessionId)).sendPlayerUUID(data);
}
public void sendPlayerString(UUID sessionId, String data) {
gameSessions.get(sessionPlayerMap.get(sessionId)).sendPlayerString(data);
}
public void sendPlayerBoolean(UUID sessionId, Boolean data) {
gameSessions.get(sessionPlayerMap.get(sessionId)).sendPlayerBoolean(data);
}
public void sendPlayerInteger(UUID sessionId, Integer data) {
gameSessions.get(sessionPlayerMap.get(sessionId)).sendPlayerInteger(data);
}
private void updateGame() {
for (final Entry<UUID, GameSession> entry: gameSessions.entrySet()) {
entry.getValue().update(getGameView(entry.getKey()));
}
for (final GameWatcher gameWatcher: watchers.values()) {
gameWatcher.update(getGameView());
}
}
private void ask(UUID playerId, String question) {
informOthers(playerId);
gameSessions.get(playerId).ask(question, getGameView(playerId));
}
private void chooseAbility(UUID playerId, Collection<? extends ActivatedAbility> choices) {
informOthers(playerId);
gameSessions.get(playerId).chooseAbility(new AbilityPickerView(choices));
}
private void choose(UUID playerId, String message, String[] choices) {
informOthers(playerId);
gameSessions.get(playerId).choose(message, choices);
}
private void target(UUID playerId, String question, Cards cards, boolean required) {
informOthers(playerId);
gameSessions.get(playerId).target(question, getCardView(cards), required, getGameView(playerId));
}
private void select(UUID playerId, String message) {
informOthers(playerId);
gameSessions.get(playerId).select(message, getGameView(playerId));
}
private void playMana(UUID playerId, String message) {
informOthers(playerId);
gameSessions.get(playerId).playMana(message, getGameView(playerId));
}
private void playXMana(UUID playerId, String message) {
informOthers(playerId);
gameSessions.get(playerId).playXMana(message, getGameView(playerId));
}
private void amount(UUID playerId, String message, int min, int max) {
informOthers(playerId);
gameSessions.get(playerId).getAmount(message, min, max);
}
private void revealCards(String name, Cards cards) {
for (GameSession session: gameSessions.values()) {
session.revealCards(name, getCardView(cards));
}
}
private void informOthers(UUID playerId) {
final String message = "Waiting for " + game.getPlayer(playerId).getName();
for (final Entry<UUID, GameSession> entry: gameSessions.entrySet()) {
if (!entry.getKey().equals(playerId)) {
entry.getValue().inform(message, getGameView(entry.getKey()));
}
}
for (final GameWatcher watcher: watchers.values()) {
watcher.inform(message, getGameView());
}
}
private GameView getGameView() {
return new GameView(game.getState());
}
private GameView getGameView(UUID playerId) {
GameView gameView = new GameView(game.getState());
gameView.setHand(getCardView(game.getPlayer(playerId).getHand()));
return gameView;
}
private CardsView getCardView(Cards cards) {
if (cards == null)
return null;
return new CardsView(cards.values());
}
public void gameResult(String result) {
endGame(result);
}
}

View file

@ -0,0 +1,82 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.game;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.game.Game;
import mage.util.Logging;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class GameFactory {
private final static GameFactory INSTANCE = new GameFactory();
private final static Logger logger = Logging.getLogger(GameFactory.class.getName());
private Map<String, Class> gameTypes = new HashMap<String, Class>();
public static GameFactory getInstance() {
return INSTANCE;
}
private GameFactory() {}
public Game createGame(String gameType) {
Game game;
Constructor<?> con;
try {
con = gameTypes.get(gameType).getConstructor(new Class[]{});
game = (Game)con.newInstance(new Object[] {});
} catch (Exception ex) {
logger.log(Level.SEVERE, null, ex);
return null;
}
logger.info("Game created: " + game.getId().toString());
return game;
}
public Set<String> getGameTypes() {
return gameTypes.keySet();
}
public void addGameType(String name, Class gameType) {
this.gameTypes.put(name, gameType);
}
}

View file

@ -0,0 +1,125 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.game;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import mage.cards.decks.DeckCardLists;
import mage.game.Game;
import mage.game.GameReplay;
import mage.interfaces.GameClient;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class GameManager {
private final static GameManager INSTANCE = new GameManager();
public static GameManager getInstance() {
return INSTANCE;
}
private GameManager() {}
private ConcurrentHashMap<UUID, GameController> gameControllers = new ConcurrentHashMap<UUID, GameController>();
public UUID createGameSession(Game game, ConcurrentHashMap<UUID, UUID> sessionPlayerMap, UUID tableId) {
GameController gameController = new GameController(game, sessionPlayerMap, tableId);
gameControllers.put(game.getId(), gameController);
return gameController.getSessionId();
}
public void joinGame(UUID gameId, UUID sessionId, GameClient client) {
gameControllers.get(gameId).join(sessionId, client);
}
// public void leaveGame(UUID gameId, UUID clientId) {
// gameControllers.get(gameId).leave(clientId);
// }
public void destroyChatSession(UUID gameId) {
gameControllers.remove(gameId);
}
public UUID getChatId(UUID gameId) {
return gameControllers.get(gameId).getChatId();
}
public void sendPlayerUUID(UUID gameId, UUID sessionId, UUID data) {
gameControllers.get(gameId).sendPlayerUUID(sessionId, data);
}
public void sendPlayerString(UUID gameId, UUID sessionId, String data) {
gameControllers.get(gameId).sendPlayerString(sessionId, data);
}
public void sendPlayerBoolean(UUID gameId, UUID sessionId, Boolean data) {
gameControllers.get(gameId).sendPlayerBoolean(sessionId, data);
}
public void sendPlayerInteger(UUID gameId, UUID sessionId, Integer data) {
gameControllers.get(gameId).sendPlayerInteger(sessionId, data);
}
public void concedeGame(UUID gameId, UUID sessionId) {
gameControllers.get(gameId).concede(sessionId);
}
public void watchGame(UUID gameId, UUID sessionId, GameClient client) {
gameControllers.get(gameId).watch(sessionId, client);
}
public void stopWatching(UUID gameId, UUID clientId) {
gameControllers.get(gameId).stopWatching(clientId);
}
public void removeSession(UUID sessionId) {
for (GameController controller: gameControllers.values()) {
controller.kill(sessionId);
}
}
public void kill(UUID gameId, UUID sessionId) {
gameControllers.get(gameId).kill(sessionId);
}
public GameReplay createReplay(UUID gameId) {
return gameControllers.get(gameId).createReplay();
}
public void cheat(UUID gameId, UUID sessionId, DeckCardLists deckList) {
gameControllers.get(gameId).cheat(sessionId, deckList);
}
void timeout(UUID gameId, UUID sessionId) {
gameControllers.get(gameId).timeout(sessionId);
}
}

View file

@ -0,0 +1,262 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.game;
import java.rmi.RemoteException;
import java.util.UUID;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;
import mage.game.Game;
import mage.interfaces.GameClient;
import mage.server.util.ConfigSettings;
import mage.server.util.ThreadExecutor;
import mage.view.AbilityPickerView;
import mage.view.CardsView;
import mage.view.GameView;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class GameSession extends GameWatcher {
private Game game;
private UUID playerId;
private ScheduledFuture<?> futureTimeout;
protected static ScheduledExecutorService timeoutExecutor = ThreadExecutor.getInstance().getTimeoutExecutor();
public GameSession(GameClient client, Game game, UUID sessionId, UUID playerId) {
super(client, sessionId, game.getId());
this.game = game;
this.playerId = playerId;
}
public void ask(final String question, final GameView gameView) {
if (!killed) {
setupTimeout();
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.ask(question, gameView);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
}
}
public void target(final String question, final CardsView cardView, final boolean required, final GameView gameView) {
if (!killed) {
setupTimeout();
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.target(question, cardView, required, gameView);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
}
}
public void select(final String message, final GameView gameView) {
if (!killed) {
setupTimeout();
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.select(message, gameView);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
}
}
public void chooseAbility(final AbilityPickerView abilities) {
if (!killed) {
setupTimeout();
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.chooseAbility(abilities);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
}
}
public void choose(final String message, final String[] choices) {
if (!killed) {
setupTimeout();
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.choose(message, choices);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
}
}
public void playMana(final String message, final GameView gameView) {
if (!killed) {
setupTimeout();
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.playMana(message, gameView);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
}
}
public void playXMana(final String message, final GameView gameView) {
if (!killed) {
setupTimeout();
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.playXMana(message, gameView);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
}
}
public void getAmount(final String message, final int min, final int max) {
if (!killed) {
setupTimeout();
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.getAmount(min, max);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
}
}
public void revealCards(final String name, final CardsView cardView) {
if (!killed) {
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.revealCards(name, cardView);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
}
}
private synchronized void setupTimeout() {
cancelTimeout();
futureTimeout = timeoutExecutor.schedule(
new Runnable() {
@Override
public void run() {
GameManager.getInstance().timeout(gameId, sessionId);
}
},
ConfigSettings.getInstance().getMaxSecondsIdle(), TimeUnit.SECONDS
);
}
private synchronized void cancelTimeout() {
if (futureTimeout != null) {
futureTimeout.cancel(false);
}
}
public void sendPlayerUUID(UUID data) {
cancelTimeout();
game.getPlayer(playerId).setResponseUUID(data);
}
public void sendPlayerString(String data) {
cancelTimeout();
game.getPlayer(playerId).setResponseString(data);
}
public void sendPlayerBoolean(Boolean data) {
cancelTimeout();
game.getPlayer(playerId).setResponseBoolean(data);
}
public void sendPlayerInteger(Integer data) {
cancelTimeout();
game.getPlayer(playerId).setResponseInteger(data);
}
}

View file

@ -0,0 +1,135 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.game;
import java.rmi.RemoteException;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.interfaces.GameClient;
import mage.server.util.ThreadExecutor;
import mage.util.Logging;
import mage.view.GameView;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class GameWatcher {
protected static ExecutorService rmiExecutor = ThreadExecutor.getInstance().getRMIExecutor();
protected final static Logger logger = Logging.getLogger(GameWatcher.class.getName());
protected GameClient client;
protected UUID sessionId;
protected UUID gameId;
protected boolean killed = false;
public GameWatcher(GameClient client, UUID sessionId, UUID gameId) {
this.client = client;
this.sessionId = sessionId;
this.gameId = gameId;
}
public void init(final GameView gameView) {
if (!killed)
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.init(gameView);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
}
public void update(final GameView gameView) {
if (!killed)
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.update(gameView);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
}
public void inform(final String message, final GameView gameView) {
if (!killed)
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.inform(message, gameView);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
}
public void gameOver(final String message) {
if (!killed)
rmiExecutor.submit(
new Runnable() {
@Override
public void run() {
try {
client.gameOver(message);
} catch (RemoteException ex) {
handleRemoteException(ex);
}
}
}
);
}
protected void handleRemoteException(RemoteException ex) {
logger.log(Level.SEVERE, null, ex);
GameManager.getInstance().kill(gameId, sessionId);
}
public void setKilled() {
killed = true;
}
}

View file

@ -0,0 +1,64 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.game;
import java.util.concurrent.Callable;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.game.Game;
import mage.util.Logging;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class GameWorker implements Callable {
private final static Logger logger = Logging.getLogger(GameWorker.class.getName());
private GameCallback result;
private Game game;
public GameWorker(Game game, GameCallback result) {
this.game = game;
this.result = result;
}
@Override
public Object call() {
try {
game.start();
result.gameResult(game.getWinner());
} catch (Exception ex) {
logger.log(Level.SEVERE, null, ex);
}
return null;
}
}

View file

@ -0,0 +1,53 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.game;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import mage.Constants.DeckType;
import mage.cards.decks.DeckCardLists;
import mage.view.TableView;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public interface GamesRoom extends Room {
public Collection<TableView> getTables();
public boolean joinTable(UUID sessionId, UUID tableId, int seatNum, String name, DeckCardLists deckList);
public TableView createTable(UUID sessionId, String gameType, DeckType deckType, List<String> playerTypes);
public void removeTable(UUID sessionId, UUID tableId);
public TableView getTable(UUID tableId);
public void leaveTable(UUID sessionId, UUID tableId);
public boolean watchTable(UUID sessionId, UUID tableId);
}

View file

@ -0,0 +1,101 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.game;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import mage.Constants.DeckType;
import mage.cards.decks.DeckCardLists;
import mage.game.Table;
import mage.util.Logging;
import mage.view.TableView;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class GamesRoomImpl extends RoomImpl implements GamesRoom, Serializable {
private final static Logger logger = Logging.getLogger(GamesRoomImpl.class.getName());
private ConcurrentHashMap<UUID, Table> tables = new ConcurrentHashMap<UUID, Table>();
@Override
public Collection<TableView> getTables() {
ArrayList<TableView> tableList = new ArrayList<TableView>();
for (Table table: tables.values()) {
tableList.add(new TableView(table));
}
return tableList;
}
@Override
public boolean joinTable(UUID sessionId, UUID tableId, int seatNum, String name, DeckCardLists deckList) {
if (tables.containsKey(tableId)) {
return TableManager.getInstance().joinTable(sessionId, tableId, seatNum, name, deckList);
} else {
return false;
}
}
@Override
public TableView createTable(UUID sessionId, String gameType, DeckType deckType, List<String> playerTypes) {
Table table = TableManager.getInstance().createTable(sessionId, gameType, deckType, playerTypes);
tables.put(table.getId(), table);
return new TableView(table);
}
@Override
public TableView getTable(UUID tableId) {
return new TableView(tables.get(tableId));
}
@Override
public void removeTable(UUID sessionId, UUID tableId) {
if (TableManager.getInstance().removeTable(sessionId, tableId)) {
tables.remove(tableId);
}
}
@Override
public void leaveTable(UUID sessionId, UUID tableId) {
TableManager.getInstance().leaveTable(sessionId, tableId);
}
@Override
public boolean watchTable(UUID sessionId, UUID tableId) {
return TableManager.getInstance().watchTable(sessionId, tableId);
}
}

View file

@ -0,0 +1,72 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.game;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import mage.util.Logging;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class GamesRoomManager {
private final static GamesRoomManager INSTANCE = new GamesRoomManager();
private final static Logger logger = Logging.getLogger(GamesRoomManager.class.getName());
private ConcurrentHashMap<UUID, GamesRoom> rooms = new ConcurrentHashMap<UUID, GamesRoom>();
private UUID mainRoomId;
public static GamesRoomManager getInstance() {
return INSTANCE;
}
private GamesRoomManager() {
GamesRoom mainRoom = new GamesRoomImpl();
mainRoomId = mainRoom.getRoomId();
rooms.put(mainRoomId, mainRoom);
}
public UUID createRoom() {
GamesRoom room = new GamesRoomImpl();
rooms.put(room.getRoomId(), room);
return room.getRoomId();
}
public UUID getMainRoomId() {
return mainRoomId;
}
public GamesRoom getRoom(UUID roomId) {
return rooms.get(roomId);
}
}

View file

@ -0,0 +1,79 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.game;
import java.lang.reflect.Constructor;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.players.Player;
import mage.util.Logging;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class PlayerFactory {
private final static PlayerFactory INSTANCE = new PlayerFactory();
private final static Logger logger = Logging.getLogger(PlayerFactory.class.getName());
private Map<String, Class> playerTypes = new HashMap<String, Class>();
public static PlayerFactory getInstance() {
return INSTANCE;
}
private PlayerFactory() {}
public Player createPlayer(String playerType, String name) {
Player player;
Constructor<?> con;
try {
con = playerTypes.get(playerType).getConstructor(new Class[]{String.class});
player = (Player)con.newInstance(new Object[] {name});
} catch (Exception ex) {
logger.log(Level.SEVERE, null, ex);
return null;
}
logger.info("Player created: " + player.getId().toString());
return player;
}
public Set<String> getPlayerTypes() {
return playerTypes.keySet();
}
public void addPlayerType(String name, Class gameType) {
this.playerTypes.put(name, gameType);
}
}

View file

@ -0,0 +1,73 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.game;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import mage.interfaces.GameReplayClient;
import mage.server.SessionManager;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class ReplayManager {
private final static ReplayManager INSTANCE = new ReplayManager();
public static ReplayManager getInstance() {
return INSTANCE;
}
private ReplayManager() {}
private ConcurrentHashMap<UUID, ReplaySession> replaySessions = new ConcurrentHashMap<UUID, ReplaySession>();
public void replayGame(UUID sessionId, UUID gameId) {
ReplaySession replaySession = new ReplaySession(gameId);
replaySessions.put(sessionId, replaySession);
SessionManager.getInstance().getSession(sessionId).replayGame(gameId);
}
public void startReplay(UUID sessionId, GameReplayClient replayClient) {
replaySessions.get(sessionId).replay(replayClient);
}
public void stopReplay(UUID sessionId) {
replaySessions.get(sessionId).stop();
}
public void nextPlay(UUID sessionId) {
replaySessions.get(sessionId).next();
}
public void previousPlay(UUID sessionId) {
replaySessions.get(sessionId).previous();
}
}

View file

@ -0,0 +1,115 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.game;
import java.rmi.RemoteException;
import java.util.UUID;
import java.util.concurrent.ExecutorService;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.game.GameReplay;
import mage.game.GameState;
import mage.interfaces.GameReplayClient;
import mage.server.util.ThreadExecutor;
import mage.util.Logging;
import mage.view.GameView;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class ReplaySession implements GameCallback {
protected static ExecutorService rmiExecutor = ThreadExecutor.getInstance().getRMIExecutor();
private final static Logger logger = Logging.getLogger(ReplaySession.class.getName());
private GameReplay game;
private GameReplayClient client;
ReplaySession(UUID gameId) {
this.game = GameManager.getInstance().createReplay(gameId);
}
public void replay(GameReplayClient replayClient) {
this.client = replayClient;
game.start();
rmiExecutor.submit(
new Runnable() {
public void run() {
try {
client.init(new GameView(game.next()));
} catch (RemoteException ex) {
logger.log(Level.SEVERE, null, ex);
}
}
}
);
}
public void stop() {
gameResult("stopped replay");
}
public synchronized void next() {
updateGame(game.next());
}
public synchronized void previous() {
updateGame(game.previous());
}
public void gameResult(final String result) {
rmiExecutor.submit(
new Runnable() {
public void run() {
try {
client.gameOver(result);
} catch (RemoteException ex) {
logger.log(Level.SEVERE, null, ex);
}
}
}
);
}
private void updateGame(final GameState state) {
rmiExecutor.submit(
new Runnable() {
public void run() {
try {
client.update(new GameView(state));
} catch (RemoteException ex) {
logger.log(Level.SEVERE, null, ex);
}
}
}
);
}
}

View file

@ -0,0 +1,41 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.game;
import java.rmi.Remote;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public interface Room extends Remote {
public UUID getChatId();
public UUID getRoomId();
}

View file

@ -0,0 +1,66 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.game;
import java.util.UUID;
import mage.server.ChatManager;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public abstract class RoomImpl implements Room {
private UUID chatId;
private UUID roomId;
public RoomImpl() {
roomId = UUID.randomUUID();
chatId = ChatManager.getInstance().createChatSession();
}
/**
* @return the chatId
*/
@Override
public UUID getChatId() {
return chatId;
}
/**
* @return the roomId
*/
@Override
public UUID getRoomId() {
return roomId;
}
}

View file

@ -0,0 +1,156 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.game;
import java.util.List;
import java.util.Map.Entry;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.Constants.DeckType;
import mage.Constants.TableState;
import mage.cards.decks.Deck;
import mage.cards.decks.DeckCardLists;
import mage.game.Game;
import mage.game.GameException;
import mage.game.Seat;
import mage.game.Table;
import mage.players.Player;
import mage.server.ChatManager;
import mage.server.SessionManager;
import mage.util.Logging;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TableController {
private final static Logger logger = Logging.getLogger(TableController.class.getName());
private UUID sessionId;
private UUID chatId;
private Table table;
private Game game;
private ConcurrentHashMap<UUID, UUID> sessionPlayerMap = new ConcurrentHashMap<UUID, UUID>();
public TableController(UUID sessionId, String gameType, DeckType deckType, List<String> playerTypes) {
this.sessionId = sessionId;
chatId = ChatManager.getInstance().createChatSession();
game = GameFactory.getInstance().createGame(gameType);
table = new Table(game, deckType, playerTypes);
}
public synchronized boolean joinTable(UUID sessionId, int seatNum, String name, DeckCardLists deckList) {
if (table.getState() != TableState.WAITING) {
return false;
}
try {
Seat seat = table.getSeats()[seatNum];
Deck deck = Deck.load(deckList);
if (validDeck(deck)) {
Player player = createPlayer(name, deck, seat.getPlayerType());
table.joinTable(player, seatNum);
logger.info("player joined " + player.getId());
//only add human players to sessionPlayerMap
if (table.getSeats()[seatNum].getPlayerType().equals("Human")) {
//TODO: add isHuman property to Player and check that instead
sessionPlayerMap.put(sessionId, player.getId());
}
}
else {
throw new GameException("Invalid deck type");
}
} catch (GameException ex) {
logger.log(Level.WARNING, ex.getMessage());
return false;
}
return true;
}
public boolean watchTable(UUID sessionId) {
SessionManager.getInstance().getSession(sessionId).watchGame(game.getId());
return true;
}
public boolean replayTable(UUID sessionId) {
ReplayManager.getInstance().replayGame(sessionId, game.getId());
return true;
}
private boolean validDeck(Deck deck) {
return table.getValidator().validate(deck);
}
private Player createPlayer(String name, Deck deck, String playerType) {
Player player = PlayerFactory.getInstance().createPlayer(playerType, name);
logger.info("Player created " + player.getId());
player.setDeck(deck);
return player;
}
public synchronized void leaveTable(UUID sessionId) {
if (table.getState() == TableState.WAITING)
table.leaveTable(sessionPlayerMap.get(sessionId));
}
public synchronized void startGame(UUID sessionId) {
if (sessionId.equals(this.sessionId) && table.getState() == TableState.STARTING) {
try {
table.initGame();
} catch (GameException ex) {
logger.log(Level.SEVERE, null, ex);
}
GameManager.getInstance().createGameSession(game, sessionPlayerMap, table.getId());
SessionManager sessionManager = SessionManager.getInstance();
for (Entry<UUID, UUID> entry: sessionPlayerMap.entrySet()) {
sessionManager.getSession(entry.getKey()).gameStarted(game.getId(), entry.getValue());
}
}
}
public void endGame() {
table.endGame();
}
public boolean isOwner(UUID sessionId) {
return sessionId.equals(this.sessionId);
}
public Table getTable() {
return table;
}
public UUID getChatId() {
return chatId;
}
}

View file

@ -0,0 +1,116 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.game;
import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.logging.Logger;
import mage.Constants.DeckType;
import mage.cards.decks.DeckCardLists;
import mage.game.Table;
import mage.util.Logging;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class TableManager {
private final static TableManager INSTANCE = new TableManager();
private final static Logger logger = Logging.getLogger(TableManager.class.getName());
private ConcurrentHashMap<UUID, TableController> controllers = new ConcurrentHashMap<UUID, TableController>();
private ConcurrentHashMap<UUID, Table> tables = new ConcurrentHashMap<UUID, Table>();
public static TableManager getInstance() {
return INSTANCE;
}
public Table createTable(UUID sessionId, String gameType, DeckType deckType, List<String> playerTypes) {
TableController tableController = new TableController(sessionId, gameType, deckType, playerTypes);
controllers.put(tableController.getTable().getId(), tableController);
tables.put(tableController.getTable().getId(), tableController.getTable());
return tableController.getTable();
}
public Table getTable(UUID tableId) {
return tables.get(tableId);
}
public Collection<Table> getTables() {
return tables.values();
}
public boolean joinTable(UUID sessionId, UUID tableId, int seatNum, String name, DeckCardLists deckList) {
return controllers.get(tableId).joinTable(sessionId, seatNum, name, deckList);
}
public void removeSession(UUID sessionId) {
// TODO: search through tables and remove session
}
public boolean isTableOwner(UUID tableId, UUID sessionId) {
return controllers.get(tableId).isOwner(sessionId);
}
public boolean removeTable(UUID sessionId, UUID tableId) {
if (isTableOwner(tableId, sessionId)) {
controllers.remove(tableId);
tables.remove(tableId);
return true;
}
return false;
}
public void leaveTable(UUID sessionId, UUID tableId) {
controllers.get(tableId).leaveTable(sessionId);
}
public UUID getChatId(UUID tableId) {
return controllers.get(tableId).getChatId();
}
public void startGame(UUID sessionId, UUID roomId, UUID tableId) {
controllers.get(tableId).startGame(sessionId);
}
public boolean watchTable(UUID sessionId, UUID tableId) {
return controllers.get(tableId).watchTable(sessionId);
}
public boolean replayTable(UUID sessionId, UUID tableId) {
return controllers.get(tableId).replayTable(sessionId);
}
public void endGame(UUID tableId) {
controllers.get(tableId).endGame();
}
}

View file

@ -0,0 +1,63 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.util;
import java.io.IOException;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
import mage.util.Logging;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class Config {
private final static Logger logger = Logging.getLogger(Config.class.getName());
static {
Properties p = new Properties();
try {
p.load(Config.class.getResourceAsStream("resources/config.properties"));
} catch (IOException ex) {
logger.log(Level.SEVERE, null, ex);
}
port = Integer.parseInt(p.getProperty("port"));
remoteServer = p.getProperty("remote-server");
maxGameThreads = Integer.parseInt(p.getProperty("max-game-threads"));
maxSecondsIdle = Integer.parseInt(p.getProperty("max-seconds-idle"));
}
public static final String remoteServer;
public static final int port;
public static final int maxGameThreads;
public static final int maxSecondsIdle;
}

View file

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="config">
<xs:complexType>
<xs:sequence>
<xs:element ref="server"/>
<xs:element ref="playerTypes"/>
<xs:element ref="gameTypes"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="server">
<xs:complexType>
<xs:attribute name="serverName" type="xs:string" use="required"/>
<xs:attribute name="port" type="xs:positiveInteger" use="required"/>
<xs:attribute name="maxGameThreads" type="xs:positiveInteger" use="required"/>
<xs:attribute name="maxSecondsIdle" type="xs:positiveInteger" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="plugin">
<xs:complexType>
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="jar" type="xs:string"/>
<xs:attribute name="className" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="playerTypes">
<xs:complexType>
<xs:sequence>
<xs:element ref="plugin" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="gameTypes">
<xs:complexType>
<xs:sequence>
<xs:element ref="plugin" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

View file

@ -0,0 +1,90 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.util;
import java.io.File;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;
import mage.server.util.config.Config;
import mage.server.util.config.Plugin;
import mage.util.Logging;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class ConfigSettings {
private final static Logger logger = Logging.getLogger(ConfigSettings.class.getName());
private final static ConfigSettings INSTANCE = new ConfigSettings();
private Config config;
public static ConfigSettings getInstance() {
return INSTANCE;
}
private ConfigSettings() {
try {
JAXBContext jaxbContext = JAXBContext.newInstance("mage.server.util.config");
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
config = (Config) unmarshaller.unmarshal(new File("config/config.xml"));
} catch (JAXBException ex) {
logger.log(Level.SEVERE, null, ex);
}
}
public String getServerName() {
return config.getServer().getServerName();
}
public int getPort() {
return config.getServer().getPort().intValue();
}
public int getMaxGameThreads() {
return config.getServer().getMaxGameThreads().intValue();
}
public int getMaxSecondsIdle() {
return config.getServer().getMaxSecondsIdle().intValue();
}
public List<Plugin> getPlayerTypes() {
return config.getPlayerTypes().getPlugin();
}
public List<Plugin> getGameTypes() {
return config.getGameTypes().getPlugin();
}
}

View file

@ -0,0 +1,65 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.server.util;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
/**
*
* @author BetaSteward_at_googlemail.com
*/
public class ThreadExecutor {
private static ExecutorService rmiExecutor = Executors.newCachedThreadPool();
private static ExecutorService gameExecutor = Executors.newFixedThreadPool(ConfigSettings.getInstance().getMaxGameThreads());
private static ScheduledExecutorService timeoutExecutor = Executors.newScheduledThreadPool(5);
private final static ThreadExecutor INSTANCE = new ThreadExecutor();
public static ThreadExecutor getInstance() {
return INSTANCE;
}
private ThreadExecutor() {}
public ExecutorService getRMIExecutor() {
return rmiExecutor;
}
public ExecutorService getGameExecutor() {
return gameExecutor;
}
public ScheduledExecutorService getTimeoutExecutor() {
return timeoutExecutor;
}
}

View file

@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="../Config.xsd">
<server serverName="mage-server" port="17171" maxGameThreads="10" maxSecondsIdle="600"/>
<playerTypes>
<plugin name="Human" jar="Mage.HumanPlayer.jar" className="mage.human.HumanPlayer"/>
<plugin name="Computer - default" jar="Mage.AI.jar" className="mage.ai.ComputerPlayer"/>
</playerTypes>
<gameTypes>
<plugin name="Two Player Duel" jar="Mage.Game.TwoPlayerDuel.jar" className="mage.game.TwoPlayerGame"/>
</gameTypes>
</config>

View file

@ -0,0 +1,3 @@
grant {
permission java.security.AllPermission;
};

View file

@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="config">
<xs:complexType>
<xs:sequence>
<xs:element ref="server"/>
<xs:element ref="playerTypes"/>
<xs:element ref="gameTypes"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="server">
<xs:complexType>
<xs:attribute name="serverName" type="xs:string" use="required"/>
<xs:attribute name="port" type="xs:positiveInteger" use="required"/>
<xs:attribute name="maxGameThreads" type="xs:positiveInteger" use="required"/>
<xs:attribute name="maxSecondsIdle" type="xs:positiveInteger" use="required"/>
</xs:complexType>
</xs:element>
<xs:element name="plugin">
<xs:complexType>
<xs:attribute name="name" type="xs:string"/>
<xs:attribute name="jar" type="xs:string"/>
<xs:attribute name="className" type="xs:string"/>
</xs:complexType>
</xs:element>
<xs:element name="playerTypes">
<xs:complexType>
<xs:sequence>
<xs:element ref="plugin" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="gameTypes">
<xs:complexType>
<xs:sequence>
<xs:element ref="plugin" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>