Thread: [jetrix-cvs] SF.net SVN: jetrix:[851] jetrix/trunk (Page 2)
Brought to you by:
smanux
From: <sm...@us...> - 2010-05-04 12:47:31
|
Revision: 851 http://jetrix.svn.sourceforge.net/jetrix/?rev=851&view=rev Author: smanux Date: 2010-05-04 12:47:25 +0000 (Tue, 04 May 2010) Log Message: ----------- Automatic generation of the commands documentation Modified Paths: -------------- jetrix/trunk/build.xml jetrix/trunk/doc/todo.txt jetrix/trunk/src/site/style.css jetrix/trunk/src/site/user-guide.php Added Paths: ----------- jetrix/trunk/src/java/net/jetrix/tools/DocumentationGenerator.java jetrix/trunk/src/site/commands.html Modified: jetrix/trunk/build.xml =================================================================== --- jetrix/trunk/build.xml 2010-05-04 10:10:28 UTC (rev 850) +++ jetrix/trunk/build.xml 2010-05-04 12:47:25 UTC (rev 851) @@ -337,8 +337,19 @@ <fileset dir="${deploy}/jetrix-${version}"/> </ftp> </target> - - <target name="site" description="Generate and publish the web site to SourceForge"> + + <target name="docgen" depends="compile" description="Generates the documentation of the server commands"> + <java classname="net.jetrix.tools.DocumentationGenerator" fork="true"> + <classpath> + <pathelement path="${build}/classes"/> + <pathelement path="${src}/etc"/> + <pathelement path="${src}/lang"/> + <fileset dir="lib" includes="*.jar"/> + </classpath> + </java> + </target> + + <target name="site" depends="docgen" description="Generate and publish the web site to SourceForge"> <!-- Create the site distribution directory --> <mkdir dir="${dist}/site/docs"/> Modified: jetrix/trunk/doc/todo.txt =================================================================== --- jetrix/trunk/doc/todo.txt 2010-05-04 10:10:28 UTC (rev 850) +++ jetrix/trunk/doc/todo.txt 2010-05-04 12:47:25 UTC (rev 851) @@ -19,6 +19,7 @@ - bonus points when the same player wins several games in a row - immunity mode: a tetris grants a 10 seconds immunity against any special (detrimental and beneficial) - check the end of the game when a player leaves the channel +- handicap filter: increase the difficulty for the winner (increased starting height) Commands - /mute <nick> @@ -41,12 +42,14 @@ - run as a service on Windows (using Java Service Wrapper) - run as a service on Linux (init.d script) - deploy as a web application +- UPnP support (with http://www.cybergarage.org and http://jupnp.dev.java.net, or UPNPLib from http://www.sbbi.net) Website - feature matrix similar to http://damagecontrol.codehaus.org/Continuous+Integration+Server+Feature+Matrix -- automatic generation of the commands documentation - java web start demo - compress the files on the patch server Code - split the code in two parts : the core tetrinet classes and the server specific classes +- reusable project to develop an independent command/filter +- publish Maven artifacts to SonaType (http://nexus.sonatype.org/oss-repository-hosting.html) Added: jetrix/trunk/src/java/net/jetrix/tools/DocumentationGenerator.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/tools/DocumentationGenerator.java (rev 0) +++ jetrix/trunk/src/java/net/jetrix/tools/DocumentationGenerator.java 2010-05-04 12:47:25 UTC (rev 851) @@ -0,0 +1,165 @@ +/** + * Jetrix TetriNET Server + * Copyright (C) 20010 Emmanuel Bourg + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package net.jetrix.tools; + +import java.io.File; +import java.io.FileWriter; +import java.io.PrintWriter; +import java.util.Arrays; +import java.util.Iterator; +import java.util.Locale; +import java.util.TreeMap; + +import net.jetrix.AccessLevel; +import net.jetrix.commands.Command; +import net.jetrix.commands.CommandManager; +import net.jetrix.config.ChannelConfig; +import net.jetrix.config.FilterConfig; +import net.jetrix.config.ServerConfig; + +/** + * Generates the documentation for the server commands. + * + * @author Emmanuel Bourg + * @version $Revision$, $Date$ + */ +public class DocumentationGenerator +{ + public static void main(String[] args) throws Exception + { + File configFile = new File("src/etc/conf/server.xml"); + ServerConfig config = new ServerConfig(); + config.load(configFile); + + File file = new File("src/site/commands.html"); + file.getParentFile().mkdirs(); + + System.out.println("Exporting commands documentation from " + configFile + " to " + file); + System.out.println(""); + + // collect the general commands + TreeMap<String, Command> commands = new TreeMap<String, Command>(); + Iterator<Command> it = CommandManager.getInstance().getCommands(AccessLevel.ADMINISTRATOR); + while (it.hasNext()) + { + Command command = it.next(); + commands.put(command.getAliases()[0], command); + } + + // collect the filter commands + for (ChannelConfig channel : config.getChannels()) + { + Iterator<FilterConfig> filters = channel.getFilters(); + while (filters.hasNext()) + { + FilterConfig filter = filters.next(); + if (!filter.isGlobal() && filter.getName().equals("command")) + { + String cls = filter.getProperties().getProperty("class"); + Command command = (Command) Class.forName(cls).newInstance(); + commands.put(command.getAliases()[0], command); + } + } + } + + PrintWriter out = new PrintWriter(new FileWriter(file)); + + for (Command command : commands.values()) + { + String alias = command.getAliases()[0]; + + out.println("<h2 id=\"command-" + alias + "\">" + alias + "</h2>"); + out.println(); + out.println("<p>" + command.getDescription(Locale.ENGLISH) + "</p>"); + out.println(); + out.println("<div><b>Usage:</b> <tt>" + htmlizeUsage(command.getUsage(Locale.ENGLISH)) + "</tt></div>"); + if (command.getAliases().length > 1) + { + out.println("<div><b>Aliases:</b> <tt>" + Arrays.toString(command.getAliases()) + "</tt></div>"); + } + String role = getRoleName(command.getAccessLevel()); + if (role != null) + { + out.println("<div><b>Access Level:</b> " + role + "</div>"); + } + out.println(); + out.println(); + + System.out.println(command.getUsage(Locale.ENGLISH)); + } + + + out.flush(); + out.close(); + } + + private static String getRoleName(int level) + { + if (level == 0) + { + return "Player"; + } + else if (level == 1) + { + return "Channel Operator"; + } + else if (level == 2) + { + return "Operator"; + } + else if (level == 100) + { + return "Administrator"; + } + else + { + return null; + } + } + + /** + * Return a colorized usage string of the specified command. + */ + private static String htmlizeUsage(String usage) + { + StringBuffer htmlized = new StringBuffer(); + htmlized.append("<span style=\"color: red\">"); + + for (char c : usage.toCharArray()) + { + if (c == '<') + { + htmlized.append("<span style=\"color: blue\"><"); + } + else if (c == '>') + { + htmlized.append("></span>"); + } + else + { + htmlized.append(c); + } + } + + htmlized.append("</span>"); + + return htmlized.toString(); + } +} Property changes on: jetrix/trunk/src/java/net/jetrix/tools/DocumentationGenerator.java ___________________________________________________________________ Added: svn:keywords + Date Author Id Revision HeadURL Added: svn:eol-style + native Added: jetrix/trunk/src/site/commands.html =================================================================== --- jetrix/trunk/src/site/commands.html (rev 0) +++ jetrix/trunk/src/site/commands.html 2010-05-04 12:47:25 UTC (rev 851) @@ -0,0 +1,268 @@ +<h2 id="command-away">away</h2> + +<p>Set your away status.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/afk <span style="color: blue"><message></span></span></tt></div> +<div><b>Aliases:</b> <tt>[away, afk]</tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-broadcast">broadcast</h2> + +<p>Send a message to all clients on the server.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/br <span style="color: blue"><message></span></span></tt></div> +<div><b>Aliases:</b> <tt>[broadcast, br, gmsg, shout]</tt></div> +<div><b>Access Level:</b> Operator</div> + + +<h2 id="command-config">config</h2> + +<p>Display the channel settings.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/config</span></tt></div> +<div><b>Aliases:</b> <tt>[config, conf, settings]</tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-emote">emote</h2> + +<p>Display an emote.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/me</span></tt></div> +<div><b>Aliases:</b> <tt>[emote, me]</tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-goto">goto</h2> + +<p>Go to the channel of the specified player.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/goto <span style="color: blue"><player name></span></span></tt></div> +<div><b>Aliases:</b> <tt>[goto, go]</tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-help">help</h2> + +<p>List all commands available.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/help</span></tt></div> +<div><b>Aliases:</b> <tt>[help, ?, h]</tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-ignore">ignore</h2> + +<p>Add or remove a player from the ignore list.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/ignore <span style="color: blue"><player name|number></span></span></tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-ip">ip</h2> + +<p>Display the IP of a player.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/ip <span style="color: blue"><player name|number></span></span></tt></div> +<div><b>Access Level:</b> Operator</div> + + +<h2 id="command-join">join</h2> + +<p>Join or create a channel.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/join <span style="color: blue"><channel name|number></span> <span style="color: blue"><password></span></span></tt></div> +<div><b>Aliases:</b> <tt>[join, j]</tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-kick">kick</h2> + +<p>Kick a player out of the server.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/kick <span style="color: blue"><player name|number></span></span></tt></div> +<div><b>Aliases:</b> <tt>[kick, disconnect]</tt></div> +<div><b>Access Level:</b> Operator</div> + + +<h2 id="command-language">language</h2> + +<p>Set the language of the user.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/language <span style="color: blue"><language code></span></span></tt></div> +<div><b>Aliases:</b> <tt>[language, lang]</tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-list">list</h2> + +<p>List available channels.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/list</span></tt></div> +<div><b>Aliases:</b> <tt>[list, l]</tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-mode">mode</h2> + +<p>Change the channel's configuration.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/mode <span style="color: blue"><0-9></span></span></tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-motd">motd</h2> + +<p>Display the message of the day.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/motd</span></tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-move">move</h2> + +<p>Move a player to a new slot.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/move <span style="color: blue"><player number></span> <span style="color: blue"><slot number></span></span></tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-operator">operator</h2> + +<p>Gain authenticated operator status.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/op <span style="color: blue"><password></span></span></tt></div> +<div><b>Aliases:</b> <tt>[operator, op]</tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-pause">pause</h2> + +<p>Pause or unpause the game.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/pause</span></tt></div> +<div><b>Access Level:</b> Operator</div> + + +<h2 id="command-petition">petition</h2> + +<p>Send a request for assistance to all operators online.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/petition <span style="color: blue"><message></span></span></tt></div> +<div><b>Aliases:</b> <tt>[petition, omsg]</tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-ping">ping</h2> + +<p>Display the ping to the server.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/ping</span></tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-random">random</h2> + +<p>Display a random number.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/random <span style="color: blue"><min></span> <span style="color: blue"><max></span></span></tt></div> +<div><b>Aliases:</b> <tt>[random, roll]</tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-reply">reply</h2> + +<p>Reply to the previous private message.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/reply <span style="color: blue"><message></span></span></tt></div> +<div><b>Aliases:</b> <tt>[reply, r]</tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-speclist">speclist</h2> + +<p>Show the spectators in the channel</p> + +<div><b>Usage:</b> <tt><span style="color: red">/speclist</span></tt></div> +<div><b>Aliases:</b> <tt>[speclist, slist]</tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-start">start</h2> + +<p>Start the game.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/start <span style="color: blue"><seconds></span></span></tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-stop">stop</h2> + +<p>Stop the game.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/stop</span></tt></div> +<div><b>Access Level:</b> Operator</div> + + +<h2 id="command-summon">summon</h2> + +<p>Summon a player to the current channel.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/summon <span style="color: blue"><player name></span></span></tt></div> +<div><b>Access Level:</b> Operator</div> + + +<h2 id="command-teleport">teleport</h2> + +<p>Teleport a player to another channel.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/teleport <span style="color: blue"><player name|number></span> <span style="color: blue"><channel name|number></span></span></tt></div> +<div><b>Aliases:</b> <tt>[teleport, tp]</tt></div> +<div><b>Access Level:</b> Operator</div> + + +<h2 id="command-tell">tell</h2> + +<p>Send a private message to a player.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/tell <span style="color: blue"><player name|number></span> <span style="color: blue"><message></span></span></tt></div> +<div><b>Aliases:</b> <tt>[tell, msg, cmsg, send]</tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-time">time</h2> + +<p>Display the server's time.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/time</span></tt></div> +<div><b>Aliases:</b> <tt>[time, date]</tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-tmsg">tmsg</h2> + +<p>Send a message to the team.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/tmsg <span style="color: blue"><message></span></span></tt></div> +<div><b>Aliases:</b> <tt>[tmsg, gu]</tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-version">version</h2> + +<p>Display the version of the server.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/version</span></tt></div> +<div><b>Access Level:</b> Player</div> + + +<h2 id="command-who">who</h2> + +<p>List all players connected to the server.</p> + +<div><b>Usage:</b> <tt><span style="color: red">/who</span></tt></div> +<div><b>Aliases:</b> <tt>[who, w, cwho]</tt></div> +<div><b>Access Level:</b> Player</div> + + Property changes on: jetrix/trunk/src/site/commands.html ___________________________________________________________________ Added: svn:keywords + Date Author Id Revision HeadURL Added: svn:eol-style + native Modified: jetrix/trunk/src/site/style.css =================================================================== --- jetrix/trunk/src/site/style.css 2010-05-04 10:10:28 UTC (rev 850) +++ jetrix/trunk/src/site/style.css 2010-05-04 12:47:25 UTC (rev 851) @@ -1,4 +1,4 @@ -body { color: black; background-color: white; margin: 0; font-family: Arial, Helvetica, Sans Serif } +body { color: black; background-color: white; margin: 0 1em; font-family: Arial, Helvetica, Sans Serif; } a { color: #525d76 } a:hover { color: #2B313D } Modified: jetrix/trunk/src/site/user-guide.php =================================================================== --- jetrix/trunk/src/site/user-guide.php 2010-05-04 10:10:28 UTC (rev 850) +++ jetrix/trunk/src/site/user-guide.php 2010-05-04 12:47:25 UTC (rev 851) @@ -17,41 +17,7 @@ </ul> </li> <li><a href="#section3">Web Administration</a></li> - <li><a href="#section4">Command Reference</a> - <ul> - <li><a href="#section4-away">Away</a></li> - <li><a href="#section4-broadcast">Broadcast</a></li> - <li><a href="#section4-config">Config</a></li> - <li><a href="#section4-emote">Emote</a></li> - <li><a href="#section4-goto">Goto</a></li> - <li><a href="#section4-help">Help</a></li> - <li><a href="#section4-ignore">Ignore</a></li> - <li><a href="#section4-ip">Ip</a></li> - <li><a href="#section4-join">Join</a></li> - <li><a href="#section4-kick">Kick</a></li> - <li><a href="#section4-language">Language</a></li> - <li><a href="#section4-list">List</a></li> - <li><a href="#section4-mode">Mode</a></li> - <li><a href="#section4-motd">Motd</a></li> - <li><a href="#section4-move">Move</a></li> - <li><a href="#section4-operator">Operator</a></li> - <li><a href="#section4-pause">Pause</a></li> - <li><a href="#section4-petition">Petition</a></li> - <li><a href="#section4-ping">Ping</a></li> - <li><a href="#section4-random">Random</a></li> - <li><a href="#section4-reply">Reply</a></li> - <li><a href="#section4-speclist">Speclist</a></li> - <li><a href="#section4-start">Start</a></li> - <li><a href="#section4-stop">Stop</a></li> - <li><a href="#section4-summon">Summon</a></li> - <li><a href="#section4-teleport">Teleport</a></li> - <li><a href="#section4-tell">Tell</a></li> - <li><a href="#section4-time">Time</a></li> - <li><a href="#section4-tmsg">Tmsg</a></li> - <li><a href="#section4-version">Version</a></li> - <li><a href="#section4-who">Who</a></li> - </ul> - </li> + <li><a href="#section4">Command Reference</a></li> </ol> <h1><a id="section1"></a>Installation</h1> @@ -60,7 +26,7 @@ <ul> <li>Linux, Windows, Solaris or MacOS X</li> - <li>Java Runtime Environnement 1.5.x or higher</li> + <li>Java 6 or higher</li> <li>32 Mb RAM</li> <li>5 Mb hard drive space</li> <li>If you have a firewall, open the ports 31456, 31457 and 31458</li> @@ -68,10 +34,9 @@ <h3>Running & Upgrading</h3> -<p>You need a JRE 1.5 or higher installed on your server to run Jetrix. You can -download it here :</p> +<p>You need Java 6 or higher installed on your server to run Jetrix. You can +download it on <a href="http://java.com">http://java.com</a></p> -<a href="http://java.sun.com/j2se/1.5.0/download.jsp">http://java.sun.com/j2se/1.5.0/download.jsp</a> <h4>Unix</h4> @@ -79,7 +44,7 @@ environnement variable pointing to your Java directory. For example on Linux you can add this line to your /etc/profile file:</p> -<code>export JAVA_HOME=/usr/java/jre_1.5.0</code> +<code>export JAVA_HOME=/usr/java/jre_1.6.0</code> <p>Then decompress the Jetrix archive to the installation directory:</p> @@ -154,55 +119,6 @@ <h1><a id="section4"></a>Command Reference</h1> -<h2><a id="section4-broadcast"></a>Broadcast</h2> +<? include("commands.html") ?> -<h2><a id="section4-config"></a>Config</h2> - -<h2><a id="section4-emote"></a>Emote</h2> - -<h2><a id="section4-goto"></a>Goto</h2> - -<h2><a id="section4-help"></a>Help</h2> - -<h2><a id="section4-ip"></a>Ip</h2> - -<h2><a id="section4-join"></a>Join</h2> - -<h2><a id="section4-kick"></a>Kick</h2> - -<h2><a id="section4-language"></a>Language</h2> - -<h2><a id="section4-list"></a>List</h2> - -<h2><a id="section4-motd"></a>Motd</h2> - -<h2><a id="section4-move"></a>Move</h2> - -<h2><a id="section4-operator"></a>Operator</h2> - -<h2><a id="section4-pause"></a>Pause</h2> - -<h2><a id="section4-ping"></a>Ping</h2> - -<h2><a id="section4-random"></a>Random</h2> - -<h2><a id="section4-reply"></a>Reply</h2> - -<h2><a id="section4-start"></a>Start</h2> - -<h2><a id="section4-stop"></a>Stop</h2> - -<h2><a id="section4-summon"></a>Summon</h2> - -<h2><a id="section4-teleport"></a>Teleport</h2> - -<h2><a id="section4-tell"></a>Tell</h2> - -<h2><a id="section4-time"></a>Time</h2> - -<h2><a id="section4-version"></a>Version</h2> - -<h2><a id="section4-who"></a>Who</h2> - - <? include("footer.inc.php") ?> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sm...@us...> - 2010-08-20 10:26:31
|
Revision: 863 http://jetrix.svn.sourceforge.net/jetrix/?rev=863&view=rev Author: smanux Date: 2010-08-20 10:26:25 +0000 (Fri, 20 Aug 2010) Log Message: ----------- Fixed the parsing of team messages when the name contains a space character Modified Paths: -------------- jetrix/trunk/doc/changelog.txt jetrix/trunk/src/java/net/jetrix/protocols/TetrinetProtocol.java jetrix/trunk/src/test/net/jetrix/protocols/TetrinetProtocolTest.java Modified: jetrix/trunk/doc/changelog.txt =================================================================== --- jetrix/trunk/doc/changelog.txt 2010-08-20 10:17:33 UTC (rev 862) +++ jetrix/trunk/doc/changelog.txt 2010-08-20 10:26:25 UTC (rev 863) @@ -11,7 +11,8 @@ - Added support for the client identification protocol (i.e lvl 0 0 request, clientinfo response) - The number of players and spectators currently online is now displayed on logging in - The 'TServ' mode of TSpec is now supported -- Channels can be dedicated to TetriFast or non TetriFast clients. +- Channels can be dedicated to TetriFast or non TetriFast clients. A warning is displayed when mixed clients play together. +- Spaces in team names are now properly handled Admin visible changes - Jetrix now requires Java 6 Modified: jetrix/trunk/src/java/net/jetrix/protocols/TetrinetProtocol.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/protocols/TetrinetProtocol.java 2010-08-20 10:17:33 UTC (rev 862) +++ jetrix/trunk/src/java/net/jetrix/protocols/TetrinetProtocol.java 2010-08-20 10:26:25 UTC (rev 863) @@ -152,7 +152,10 @@ { TeamMessage team = new TeamMessage(); team.setSlot(Integer.parseInt(st.nextToken())); - team.setName(st.hasMoreTokens() ? st.nextToken() : null); + if (st.hasMoreTokens()) + { + team.setName(line.substring("team".length() + 3).trim()); + } m = team; m.setRawMessage(this, line); } Modified: jetrix/trunk/src/test/net/jetrix/protocols/TetrinetProtocolTest.java =================================================================== --- jetrix/trunk/src/test/net/jetrix/protocols/TetrinetProtocolTest.java 2010-08-20 10:17:33 UTC (rev 862) +++ jetrix/trunk/src/test/net/jetrix/protocols/TetrinetProtocolTest.java 2010-08-20 10:26:25 UTC (rev 863) @@ -186,6 +186,34 @@ assertEquals("name", null, team.getName()); } + public void testGetMessageTeam3() + { + // check the parsing of a team name containing a space character + String raw = "team 1 L F J R"; + Message message = protocol.getMessage(raw); + + assertNotNull("message not parsed", message); + assertEquals("message class", TeamMessage.class, message.getClass()); + + TeamMessage team = (TeamMessage) message; + assertEquals("slot", 1, team.getSlot()); + assertEquals("name", "L F J R", team.getName()); + } + + public void testGetMessageTeam4() + { + // check the parsing of a team name containing a leading and a trailing space character + String raw = "team 1 LFJR "; + Message message = protocol.getMessage(raw); + + assertNotNull("message not parsed", message); + assertEquals("message class", TeamMessage.class, message.getClass()); + + TeamMessage team = (TeamMessage) message; + assertEquals("slot", 1, team.getSlot()); + assertEquals("name", "LFJR", team.getName()); + } + public void testTranslatePlayerLeave() { LeaveMessage message = new LeaveMessage(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sm...@us...> - 2010-08-23 08:27:34
|
Revision: 864 http://jetrix.svn.sourceforge.net/jetrix/?rev=864&view=rev Author: smanux Date: 2010-08-23 08:27:28 +0000 (Mon, 23 Aug 2010) Log Message: ----------- Fixed the propagation of the playerwon message Modified Paths: -------------- jetrix/trunk/doc/changelog.txt jetrix/trunk/src/java/net/jetrix/Channel.java Modified: jetrix/trunk/doc/changelog.txt =================================================================== --- jetrix/trunk/doc/changelog.txt 2010-08-20 10:26:25 UTC (rev 863) +++ jetrix/trunk/doc/changelog.txt 2010-08-23 08:27:28 UTC (rev 864) @@ -13,6 +13,7 @@ - The 'TServ' mode of TSpec is now supported - Channels can be dedicated to TetriFast or non TetriFast clients. A warning is displayed when mixed clients play together. - Spaces in team names are now properly handled +- The winner can now hear the victory sound at the end of the game Admin visible changes - Jetrix now requires Java 6 Modified: jetrix/trunk/src/java/net/jetrix/Channel.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/Channel.java 2010-08-20 10:26:25 UTC (rev 863) +++ jetrix/trunk/src/java/net/jetrix/Channel.java 2010-08-23 08:27:28 UTC (rev 864) @@ -327,6 +327,14 @@ sendAll(m); } + private void process(PlayerWonMessage m) + { + if (m.getSource() == null) + { + sendAll(m); + } + } + private void process(PlayerLostMessage m) { int slot = m.getSlot(); @@ -803,7 +811,7 @@ { if (log.isLoggable(Level.FINEST)) { - log.finest("[" + channelConfig.getName() + "] Processing " + m); + log.finest("[" + channelConfig.getName() + "] Processing " + m.getClass().getSimpleName() + " from " + m.getSource()); } if (m instanceof CommandMessage) process((CommandMessage) m); @@ -811,6 +819,7 @@ else if (m instanceof SpecialMessage) process((SpecialMessage) m); else if (m instanceof LevelMessage) process((LevelMessage) m); else if (m instanceof PlayerLostMessage) process((PlayerLostMessage) m); + else if (m instanceof PlayerWonMessage) process((PlayerWonMessage) m); else if (m instanceof TeamMessage) process((TeamMessage) m); else if (m instanceof PlineMessage) process((PlineMessage) m); else if (m instanceof GmsgMessage) process((GmsgMessage) m); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sm...@us...> - 2010-08-23 15:02:58
|
Revision: 866 http://jetrix.svn.sourceforge.net/jetrix/?rev=866&view=rev Author: smanux Date: 2010-08-23 15:02:51 +0000 (Mon, 23 Aug 2010) Log Message: ----------- Implemented the speed check Modified Paths: -------------- jetrix/trunk/doc/changelog.txt jetrix/trunk/src/etc/conf/server.xml jetrix/trunk/src/java/net/jetrix/config/ServerConfig.java jetrix/trunk/src/java/net/jetrix/listeners/ClientListener.java jetrix/trunk/src/java/net/jetrix/messages/channel/LevelMessage.java Added Paths: ----------- jetrix/trunk/src/etc/data/speedcheck.field jetrix/trunk/src/java/net/jetrix/listeners/interceptor/InteractiveInterceptor.java jetrix/trunk/src/java/net/jetrix/listeners/interceptor/SpeedCheckInterceptor.java Modified: jetrix/trunk/doc/changelog.txt =================================================================== --- jetrix/trunk/doc/changelog.txt 2010-08-23 14:40:34 UTC (rev 865) +++ jetrix/trunk/doc/changelog.txt 2010-08-23 15:02:51 UTC (rev 866) @@ -22,6 +22,7 @@ - Channels can now be created from the administration console - The IP of the server is no longer submitted to tfast.org since the site is dead - The web administration console has been moved from port 8080 to port 31460 +- The client speed can now be checked by setting the server property 'speedcheck.enabled" to "true" Developer visible changes - added a readLine(Reader) method in the Protocol interface Modified: jetrix/trunk/src/etc/conf/server.xml =================================================================== --- jetrix/trunk/src/etc/conf/server.xml 2010-08-23 14:40:34 UTC (rev 865) +++ jetrix/trunk/src/etc/conf/server.xml 2010-08-23 15:02:51 UTC (rev 866) @@ -129,7 +129,7 @@ <!-- Extended properties --> <properties> - <property name="speedcheck.enable" value="false"/> + <property name="speedcheck.enabled" value="false"/> </properties> </tetrinet-server> Added: jetrix/trunk/src/etc/data/speedcheck.field =================================================================== --- jetrix/trunk/src/etc/data/speedcheck.field (rev 0) +++ jetrix/trunk/src/etc/data/speedcheck.field 2010-08-23 15:02:51 UTC (rev 866) @@ -0,0 +1,22 @@ +000040040000 +000000000000 +000040011011 +011100000100 +100010011111 +111110000000 +000000010001 +100010010001 +101010011111 +111110000000 +000000010001 +100010010101 +101010011111 +111110000000 +000000011111 +111040000100 +101000011111 +111110000000 +000000010001 +101110010001 +101010011111 +111010000000 \ No newline at end of file Modified: jetrix/trunk/src/java/net/jetrix/config/ServerConfig.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/config/ServerConfig.java 2010-08-23 14:40:34 UTC (rev 865) +++ jetrix/trunk/src/java/net/jetrix/config/ServerConfig.java 2010-08-23 15:02:51 UTC (rev 866) @@ -1044,7 +1044,6 @@ */ public void setProperty(String key, String value) { - System.out.println("setting " + key + " to " + value); properties.setProperty(key, value); } } Modified: jetrix/trunk/src/java/net/jetrix/listeners/ClientListener.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/listeners/ClientListener.java 2010-08-23 14:40:34 UTC (rev 865) +++ jetrix/trunk/src/java/net/jetrix/listeners/ClientListener.java 2010-08-23 15:02:51 UTC (rev 866) @@ -205,7 +205,8 @@ Collection<ClientInterceptor> validators = new ArrayList<ClientInterceptor>(); validators.add(new AccessInterceptor()); validators.add(new NameCheckInterceptor()); - + validators.add(new SpeedCheckInterceptor()); + // run the validators for (ClientInterceptor interceptor : validators) { Added: jetrix/trunk/src/java/net/jetrix/listeners/interceptor/InteractiveInterceptor.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/listeners/interceptor/InteractiveInterceptor.java (rev 0) +++ jetrix/trunk/src/java/net/jetrix/listeners/interceptor/InteractiveInterceptor.java 2010-08-23 15:02:51 UTC (rev 866) @@ -0,0 +1,179 @@ +/** + * Jetrix TetriNET Server + * Copyright (C) 2010 Emmanuel Bourg + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package net.jetrix.listeners.interceptor; + +import java.io.IOException; +import java.net.SocketException; +import java.util.concurrent.ArrayBlockingQueue; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.TimeUnit; +import java.util.logging.Level; +import java.util.logging.Logger; + +import net.jetrix.Client; +import net.jetrix.Destination; +import net.jetrix.Message; +import net.jetrix.clients.QueryClient; +import net.jetrix.clients.TetrinetClient; +import net.jetrix.messages.channel.PlayerNumMessage; + +/** + * Interceptor expecting a response from the client (a password, a speed check, etc). + * + * @author Emmanuel Bourg + * @version $Revision$, $Date$ + * @since 0.3 + */ +public abstract class InteractiveInterceptor implements ClientInterceptor, Destination +{ + protected Logger log = Logger.getLogger("net.jetrix"); + + private BlockingQueue<Boolean> queue = new ArrayBlockingQueue<Boolean>(1); + + private boolean running; + + public void process(Client client) throws ClientValidationException + { + if (client instanceof QueryClient) + { + return; + } + + // adjust the read timeout for the client + if (client instanceof TetrinetClient) + { + TetrinetClient c = (TetrinetClient) client; + try + { + c.getSocket().setSoTimeout(2 * getTimeout() * 1000); + } + catch (SocketException e) + { + e.printStackTrace(); + } + } + + // start listening the messages sent by the client + MessageReader messageReader = new MessageReader(client); + messageReader.start(); + + // initiates the dialogue + client.send(new PlayerNumMessage(1)); + prologue(client); + + // wait until the client is processed + try + { + Boolean accepted = queue.poll(getTimeout(), TimeUnit.SECONDS); + if ((accepted == null || accepted == Boolean.FALSE) && isValidating()) + { + log.info("Rejecting " + client); + client.disconnect(); + throw new ClientValidationException(); + } + else + { + log.info("Accepting: " + client); + } + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + } + + /** + * Returns the time to wait for a response from the client. + */ + protected abstract int getTimeout(); + + /** + * Initiates the interaction with the client (i.e. display a message) + */ + protected abstract void prologue(Client client); + + /** + * Process a message received from the client. + * + * @param message + */ + public abstract void send(Message message); + + + protected void accept() + { + try + { + running = false; + queue.put(Boolean.TRUE); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + } + + protected void reject() + { + try + { + running = false; + queue.put(Boolean.FALSE); + } + catch (InterruptedException e) + { + e.printStackTrace(); + } + } + + private class MessageReader extends Thread + { + private Client client; + + private MessageReader(Client client) + { + setDaemon(true); + this.client = client; + } + + public void run() + { + running = true; + + try + { + log.finer("Message reader started (" + this + ")"); + Message message; + while (running && (message = client.receive()) != null) + { + send(message); + } + } + catch (IOException e) + { + log.log(Level.WARNING, "Error reading client message during the interception", e); + } + finally + { + log.finer("Message reader stopped (" + this + ")"); + } + } + } +} Property changes on: jetrix/trunk/src/java/net/jetrix/listeners/interceptor/InteractiveInterceptor.java ___________________________________________________________________ Added: svn:keywords + Date Author Id Revision HeadURL Added: svn:eol-style + native Added: jetrix/trunk/src/java/net/jetrix/listeners/interceptor/SpeedCheckInterceptor.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/listeners/interceptor/SpeedCheckInterceptor.java (rev 0) +++ jetrix/trunk/src/java/net/jetrix/listeners/interceptor/SpeedCheckInterceptor.java 2010-08-23 15:02:51 UTC (rev 866) @@ -0,0 +1,161 @@ +/** + * Jetrix TetriNET Server + * Copyright (C) 2010 Emmanuel Bourg + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package net.jetrix.listeners.interceptor; + +import java.io.IOException; +import java.util.logging.Level; + +import net.jetrix.Client; +import net.jetrix.Field; +import net.jetrix.Message; +import net.jetrix.Server; +import net.jetrix.config.Block; +import net.jetrix.config.ServerConfig; +import net.jetrix.config.Settings; +import net.jetrix.messages.channel.EndGameMessage; +import net.jetrix.messages.channel.FieldMessage; +import net.jetrix.messages.channel.GmsgMessage; +import net.jetrix.messages.channel.NewGameMessage; +import net.jetrix.messages.channel.PlayerLostMessage; + +/** + * Interceptor checking the delay between two successive pieces. + * + * @author Emmanuel Bourg + * @version $Revision$, $Date$ + * @since 0.3 + */ +public class SpeedCheckInterceptor extends InteractiveInterceptor +{ + /** The time the speed check was started */ + private long startTime; + + /** The cumulated delay between the piece drops (~83000 expected for a standard client, 17500 for a tetrifast client) */ + private long sum = -1; + + protected Field getField() + { + Field field = new Field(); + + try + { + field.load("data/speedcheck.field"); + } + catch (IOException e) + { + log.log(Level.WARNING, "Unable to load the speedcheck field", e); + } + + return field; + } + + public void process(Client client) throws ClientValidationException + { + ServerConfig config = Server.getInstance().getConfig(); + boolean enabled = "true".equals(config.getProperty("speedcheck.enabled")); + + // skip the test for tetrifast clients + if (enabled && !"tetrifast".equals(client.getProtocol().getName())) + { + super.process(client); + } + } + + protected void prologue(Client client) + { + // start the game at high speed with squares only + Settings settings = new Settings(); + settings.setOccurancy(Block.SQUARE, 100); + settings.setStartingLevel(99); + settings.setAverageLevels(false); + + client.send(new NewGameMessage(settings)); + + FieldMessage fieldmessage = new FieldMessage(getField().getFieldString()); + fieldmessage.setSlot(1); + client.send(fieldmessage); + + client.send(new GmsgMessage("*** Please wait, the server is checking your client...")); + client.send(new GmsgMessage("*** Do not move, rotate or drop pieces.")); + } + + public void send(Message message) + { + Client client = (Client) message.getSource(); + + if (message instanceof PlayerLostMessage) + { + // stop the game + message.getSource().send(new EndGameMessage()); + + if (isFast()) + { + log.warning("Speed check failed for " + client); + reject(); + } + else + { + accept(); + } + } + else if (message instanceof FieldMessage) + { + FieldMessage msg = (FieldMessage) message; + + long now = System.currentTimeMillis(); + + if (sum == -1 && isFirstPiece(msg)) + { + // start the timer after the first drop + startTime = now; + sum = 0L; + } + + if (sum >= 0) + { + sum += (now - startTime); + } + } + } + + protected boolean isFirstPiece(FieldMessage msg) + { + Field field = new Field(); + field.update(msg); + + return field.getBlock(5, 0) == Field.BLOCK_YELLOW; + } + + protected boolean isFast() + { + // the client must not be more than 10% faster + return sum < 83000 * 0.9; + } + + protected int getTimeout() + { + return 30; + } + + public boolean isValidating() + { + return true; + } +} Property changes on: jetrix/trunk/src/java/net/jetrix/listeners/interceptor/SpeedCheckInterceptor.java ___________________________________________________________________ Added: svn:keywords + Date Author Id Revision HeadURL Added: svn:eol-style + native Modified: jetrix/trunk/src/java/net/jetrix/messages/channel/LevelMessage.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/messages/channel/LevelMessage.java 2010-08-23 14:40:34 UTC (rev 865) +++ jetrix/trunk/src/java/net/jetrix/messages/channel/LevelMessage.java 2010-08-23 15:02:51 UTC (rev 866) @@ -29,6 +29,15 @@ { private int level; + public LevelMessage() + { + } + + public LevelMessage(int level) + { + this.level = level; + } + public int getLevel() { return level; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sm...@us...> - 2010-08-27 11:41:24
|
Revision: 868 http://jetrix.svn.sourceforge.net/jetrix/?rev=868&view=rev Author: smanux Date: 2010-08-27 11:41:18 +0000 (Fri, 27 Aug 2010) Log Message: ----------- Fixed the end logo on non standard clients The semantic of the color code '6' has been changed, it now stands for the previous color instead of a random color. This code is no longer sent to the client, the actual value is computed by the server and then sent to the client. Modified Paths: -------------- jetrix/trunk/doc/changelog.txt jetrix/trunk/src/java/net/jetrix/Channel.java jetrix/trunk/src/java/net/jetrix/Field.java jetrix/trunk/src/java/net/jetrix/messages/channel/FieldMessage.java Modified: jetrix/trunk/doc/changelog.txt =================================================================== --- jetrix/trunk/doc/changelog.txt 2010-08-26 12:32:10 UTC (rev 867) +++ jetrix/trunk/doc/changelog.txt 2010-08-27 11:41:18 UTC (rev 868) @@ -14,6 +14,7 @@ - Channels can be dedicated to TetriFast or non TetriFast clients. A warning is displayed when mixed clients play together. - Spaces in team names are now properly handled - The winner can now hear the victory sound at the end of the game +- The end screen displayed after a player has lost renders properly on alternative clients Admin visible changes - Jetrix now requires Java 6 Modified: jetrix/trunk/src/java/net/jetrix/Channel.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/Channel.java 2010-08-26 12:32:10 UTC (rev 867) +++ jetrix/trunk/src/java/net/jetrix/Channel.java 2010-08-27 11:41:18 UTC (rev 868) @@ -173,7 +173,7 @@ } /** - * Main loop. The channel listens for incomming messages until the server + * Main loop. The channel listens for incoming messages until the server * or the channel closes. Every message is first passed through the * registered filters and then handled by the channel. */ @@ -437,6 +437,11 @@ } else { + if (m.isFullUpdate()) + { + // rewrite the field to handle properly the BLOCK_PREVIOUS type on non standard client + m.setField(fields[slot - 1].getFieldString()); + } sendAll(m); } } @@ -665,7 +670,7 @@ client.send(winlistMessage); } - // send a welcome message to the incomming client + // send a welcome message to the incoming client PlineMessage mwelcome = new PlineMessage(); mwelcome.setKey("channel.welcome", client.getUser().getName(), channelConfig.getName()); client.send(mwelcome); Modified: jetrix/trunk/src/java/net/jetrix/Field.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/Field.java 2010-08-26 12:32:10 UTC (rev 867) +++ jetrix/trunk/src/java/net/jetrix/Field.java 2010-08-27 11:41:18 UTC (rev 868) @@ -1,6 +1,6 @@ /** * Jetrix TetriNET Server - * Copyright (C) 2001-2005 Emmanuel Bourg + * Copyright (C) 2001-2010 Emmanuel Bourg * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -21,9 +21,9 @@ import static net.jetrix.config.Special.*; -import java.util.logging.*; -import java.util.*; import java.io.*; +import java.util.*; +import java.util.logging.*; import net.jetrix.config.*; import net.jetrix.messages.channel.*; @@ -36,34 +36,35 @@ */ public class Field { + private static Logger log = Logger.getLogger("net.jetrix"); + public static final int WIDTH = 12; public static final int HEIGHT = 22; - public static final byte BLOCK_VOID = '0'; - public static final byte BLOCK_BLUE = '1'; - public static final byte BLOCK_YELLOW = '2'; - public static final byte BLOCK_GREEN = '3'; - public static final byte BLOCK_PURPLE = '4'; - public static final byte BLOCK_RED = '5'; - public static final byte BLOCK_RANDOM = '6'; + public static final byte BLOCK_VOID = '0'; + public static final byte BLOCK_BLUE = '1'; + public static final byte BLOCK_YELLOW = '2'; + public static final byte BLOCK_GREEN = '3'; + public static final byte BLOCK_PURPLE = '4'; + public static final byte BLOCK_RED = '5'; + public static final byte BLOCK_PREVIOUS = '6'; - private static final byte blocks[] = - new byte[] { BLOCK_VOID, BLOCK_BLUE, BLOCK_YELLOW, BLOCK_GREEN, BLOCK_PURPLE, BLOCK_RED, - (byte) ADDLINE.getLetter(), - (byte) CLEARLINE.getLetter(), - (byte) NUKEFIELD.getLetter(), - (byte) RANDOMCLEAR.getLetter(), - (byte) SWITCHFIELD.getLetter(), - (byte) CLEARSPECIAL.getLetter(), - (byte) GRAVITY.getLetter(), - (byte) QUAKEFIELD.getLetter(), - (byte) BLOCKBOMB.getLetter() }; + /** The index of blocks used in a partial update. */ + private static final byte[] BLOCKS = { + BLOCK_VOID, BLOCK_BLUE, BLOCK_YELLOW, BLOCK_GREEN, BLOCK_PURPLE, BLOCK_RED, + (byte) ADDLINE.getLetter(), + (byte) CLEARLINE.getLetter(), + (byte) NUKEFIELD.getLetter(), + (byte) RANDOMCLEAR.getLetter(), + (byte) SWITCHFIELD.getLetter(), + (byte) CLEARSPECIAL.getLetter(), + (byte) GRAVITY.getLetter(), + (byte) QUAKEFIELD.getLetter(), + (byte) BLOCKBOMB.getLetter()}; - /** Array of blocks. (0, 0) is the bottom left block, and (12, 22) is the upper right block. */ + /** Array of blocks. (0, 0) is the bottom left block, and (11, 21) is the upper right block. */ private byte[][] field = new byte[WIDTH][HEIGHT]; - private Logger log = Logger.getLogger("net.jetrix"); - public Field() { clear(); @@ -180,51 +181,44 @@ * Update the field with the specified FieldMessage. */ public void update(FieldMessage message) - { - String fieldString = message.getField(); - if (fieldString != null && fieldString.length() > 0) + { + if (message.isPartialUpdate()) { - char first = fieldString.charAt(0); - if (first >= 0x21 && first <= 0x2f) + StringTokenizer tokenizer = new StringTokenizer(message.getField(), "!\"#$%&'()*+,-./", true); + + while (tokenizer.hasMoreTokens()) { - // partial update - StringTokenizer tokenizer = new StringTokenizer(fieldString, "!\"#$%&'()*+,-./", true); - - while (tokenizer.hasMoreTokens()) + // block type + String type = tokenizer.nextToken(); + byte color = BLOCKS[type.charAt(0) - 0x21]; + + // locations + String locations = tokenizer.nextToken(); + for (int i = 0; i < locations.length(); i = i + 2) { - // block type - String type = tokenizer.nextToken(); - byte color = blocks[type.charAt(0) - 0x21]; - - // locations - String locations = tokenizer.nextToken(); - for (int i = 0; i < locations.length(); i = i + 2) - { - int x = locations.charAt(i) - '3'; - int y = HEIGHT - (locations.charAt(i + 1) - '3') - 1; - field[x][y] = color; - } + int x = locations.charAt(i) - '3'; + int y = HEIGHT - (locations.charAt(i + 1) - '3') - 1; + field[x][y] = color; } } - else if (fieldString.length() == WIDTH * HEIGHT) + } + else if (message.isFullUpdate()) + { + String fieldString = message.getField(); + for (int i = 0; i < fieldString.length(); i++) { - // full update - for (int i = 0; i < fieldString.length(); i++) + char c = fieldString.charAt(i); + if (c != BLOCK_PREVIOUS) { - char c = fieldString.charAt(i); - - // replace random colored blocks - c = (c == BLOCK_RANDOM) ? (char) (BLOCK_BLUE + ((int) (Math.random() * 5))) : c; - field[i % WIDTH][HEIGHT - i / WIDTH - 1] = (byte) c; } } - else - { - // malformed message - log.warning("Malformed field update received from " + message.getSource()); - } } + else if (!message.isEmpty()) + { + // malformed message + log.warning("Malformed field update received from " + message.getSource()); + } } /** @@ -248,7 +242,7 @@ /** * Return the block at the specified location. (0, 0) is the bottom left - * block, and (12, 22) is the upper right block. + * block, and (11, 21) is the upper right block. * * @param x * @param y Modified: jetrix/trunk/src/java/net/jetrix/messages/channel/FieldMessage.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/messages/channel/FieldMessage.java 2010-08-26 12:32:10 UTC (rev 867) +++ jetrix/trunk/src/java/net/jetrix/messages/channel/FieldMessage.java 2010-08-27 11:41:18 UTC (rev 868) @@ -19,6 +19,8 @@ package net.jetrix.messages.channel; +import net.jetrix.Field; + /** * A field change message. * @@ -52,4 +54,39 @@ this.field = field; } + /** + * Tells if the field message is a full update. + * + * @since 0.3 + */ + public boolean isFullUpdate() + { + return !isEmpty() && field.length() == Field.WIDTH * Field.HEIGHT; + } + + /** + * Tells if the field message is a partial update. + * + * @since 0.3 + */ + public boolean isPartialUpdate() + { + if (isEmpty()) + { + return false; + } + + char first = field.charAt(0); + return first >= 0x21 && first <= 0x2f; + } + + /** + * Tells if the field message is empty. + * + * @since 0.3 + */ + public boolean isEmpty() + { + return field == null || field.length() == 0; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sm...@us...> - 2011-06-27 21:26:33
|
Revision: 872 http://jetrix.svn.sourceforge.net/jetrix/?rev=872&view=rev Author: smanux Date: 2011-06-27 21:26:26 +0000 (Mon, 27 Jun 2011) Log Message: ----------- Updating blocks and specials occurancies from the admin panel now works properly (issue reported by latcarfe) Refactored the handling of occurancies Modified Paths: -------------- jetrix/trunk/pom.xml jetrix/trunk/src/admin/WEB-INF/classes/net/jetrix/servlets/SettingsAction.java jetrix/trunk/src/admin/settings.jsp jetrix/trunk/src/java/net/jetrix/commands/ModeCommand.java jetrix/trunk/src/java/net/jetrix/config/ChannelsRuleSet.java jetrix/trunk/src/java/net/jetrix/config/Settings.java jetrix/trunk/src/java/net/jetrix/filter/DownstackPuzzleGenerator.java jetrix/trunk/src/java/net/jetrix/filter/RandomFilter.java jetrix/trunk/src/java/net/jetrix/listeners/interceptor/SpeedCheckInterceptor.java jetrix/trunk/src/test/net/jetrix/config/SettingsTest.java Added Paths: ----------- jetrix/trunk/src/java/net/jetrix/config/Occurancy.java jetrix/trunk/src/test/net/jetrix/config/OccurancyTest.java Modified: jetrix/trunk/pom.xml =================================================================== --- jetrix/trunk/pom.xml 2011-04-20 07:46:12 UTC (rev 871) +++ jetrix/trunk/pom.xml 2011-06-27 21:26:26 UTC (rev 872) @@ -154,6 +154,13 @@ <version>3.8.2</version> <scope>test</scope> </dependency> + + <dependency> + <groupId>junit-addons</groupId> + <artifactId>junit-addons</artifactId> + <version>1.4</version> + <scope>test</scope> + </dependency> </dependencies> <build> Modified: jetrix/trunk/src/admin/WEB-INF/classes/net/jetrix/servlets/SettingsAction.java =================================================================== --- jetrix/trunk/src/admin/WEB-INF/classes/net/jetrix/servlets/SettingsAction.java 2011-04-20 07:46:12 UTC (rev 871) +++ jetrix/trunk/src/admin/WEB-INF/classes/net/jetrix/servlets/SettingsAction.java 2011-06-27 21:26:26 UTC (rev 872) @@ -19,15 +19,25 @@ package net.jetrix.servlets; -import net.jetrix.*; -import net.jetrix.config.*; +import java.io.IOException; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Collection; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; -import javax.servlet.*; -import javax.servlet.http.*; -import java.io.*; -import java.lang.reflect.*; -import java.util.*; +import org.apache.commons.lang.StringUtils; +import net.jetrix.Channel; +import net.jetrix.ChannelManager; +import net.jetrix.Server; +import net.jetrix.config.Block; +import net.jetrix.config.Occurancy; +import net.jetrix.config.Settings; +import net.jetrix.config.Special; + /** * Action Servlet handling the server and channels settings changes. * @@ -36,7 +46,6 @@ */ public class SettingsAction extends HttpServlet { - protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { Collection errors = new ArrayList(); @@ -61,41 +70,57 @@ settings = Settings.getDefaultSettings(); } } - + // update the special occurancies boolean resetSpecials = true; + Occurancy<Special> specialOccurancy = settings.getSpecialOccurancy().clone(); for (Special special : Special.values()) { String value = request.getParameter(special.getCode()); - resetSpecials = resetSpecials && (value == null || "".equals(value.trim())); - - if (value != null && !"".equals(value.trim()) && !value.equals(String.valueOf(settings.getOccurancy(special)))) + resetSpecials = resetSpecials && StringUtils.isBlank(value); + + if (StringUtils.isNotBlank(value)) { - settings.setOccurancy(special, Integer.parseInt(value)); + specialOccurancy.setOccurancy(special, Integer.parseInt(value)); } } - - settings.setDefaultSpecialOccurancy(resetSpecials); - + + if (!specialOccurancy.equals(settings.getSpecialOccurancy())) + { + specialOccurancy.normalize(); + settings.setSpecialOccurancy(specialOccurancy); + } + else if (resetSpecials) + { + settings.setDefaultSpecialOccurancy(true); + } + + // update the block occurancies boolean resetBlocks = true; + Occurancy<Block> blockOccurancy = settings.getBlockOccurancy().clone(); for (Block block : Block.values()) { String value = request.getParameter(block.getCode()); - resetBlocks = resetBlocks && (value == null || "".equals(value.trim())); - - if (value != null && !"".equals(value.trim()) && !value.equals(String.valueOf(settings.getOccurancy(block)))) + resetBlocks = resetBlocks && StringUtils.isBlank(value); + + if (StringUtils.isNotBlank(value)) { - settings.setOccurancy(block, Integer.parseInt(request.getParameter(block.getCode()))); + blockOccurancy.setOccurancy(block, Integer.parseInt(value)); } } - - settings.setDefaultSpecialOccurancy(resetSpecials); - - // normalize the occurancies - settings.normalizeBlockOccurancy(); - settings.normalizeSpecialOccurancy(); - + + if (!blockOccurancy.equals(settings.getBlockOccurancy())) + { + blockOccurancy.normalize(); + settings.setBlockOccurancy(blockOccurancy); + } + else if (resetBlocks) + { + settings.setDefaultBlockOccurancy(true); + } + + // update the game settings updateSettingsField(settings, "startingLevel", request); updateSettingsField(settings, "stackHeight", request); Modified: jetrix/trunk/src/admin/settings.jsp =================================================================== --- jetrix/trunk/src/admin/settings.jsp 2011-04-20 07:46:12 UTC (rev 871) +++ jetrix/trunk/src/admin/settings.jsp 2011-06-27 21:26:26 UTC (rev 872) @@ -46,7 +46,7 @@ <table class="thin" style="width: 100%"> <tr> - <th width="70%">Special</th> + <th width="70%">Block</th> <th width="30%">Occurancy</th> </tr> <% for (Block block : Block.values()) { %> Modified: jetrix/trunk/src/java/net/jetrix/commands/ModeCommand.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/commands/ModeCommand.java 2011-04-20 07:46:12 UTC (rev 871) +++ jetrix/trunk/src/java/net/jetrix/commands/ModeCommand.java 2011-06-27 21:26:26 UTC (rev 872) @@ -67,11 +67,13 @@ public void updateSetting(Settings settings, int[] mode) { + Occurancy<Block> occurancy = new Occurancy<Block>(); for (Block block : Block.values()) { - settings.setOccurancy(block, mode[block.ordinal()]); + occurancy.setOccurancy(block, mode[block.ordinal()]); } - + + settings.setBlockOccurancy(occurancy); settings.setLinesPerSpecial(mode[7]); settings.setSpecialAdded(mode[8]); } Modified: jetrix/trunk/src/java/net/jetrix/config/ChannelsRuleSet.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/config/ChannelsRuleSet.java 2011-04-20 07:46:12 UTC (rev 871) +++ jetrix/trunk/src/java/net/jetrix/config/ChannelsRuleSet.java 2011-06-27 21:26:26 UTC (rev 872) @@ -31,7 +31,6 @@ */ class ChannelsRuleSet extends RuleSetBase { - public void addRuleInstances(Digester digester) { digester.addCallMethod("tetrinet-channels/motd", "setMessageOfTheDay", 0); @@ -54,21 +53,25 @@ digester.addCallMethod("*/classic-rules", "setClassicRules", 0, new Class[] {Boolean.TYPE}); digester.addCallMethod("*/average-levels", "setAverageLevels", 0, new Class[] {Boolean.TYPE}); digester.addCallMethod("*/same-blocks", "setSameBlocks", 0, new Class[] {Boolean.TYPE}); - + + // block occurancy + digester.addObjectCreate("*/block-occurancy", Occurancy.class.getName()); + digester.addCallMethod("*/block-occurancy", "normalize", 0, (Class[]) null); + digester.addSetNext("*/block-occurancy", "setBlockOccurancy", Occurancy.class.getName()); for (Block block : Block.values()) { - digester.addRule("*/block-occurancy/" + block.getCode(), new OccurancyRule(digester, block)); + digester.addRule("*/block-occurancy/" + block.getCode(), new OccurancyRule<Block>(digester, block)); } - - digester.addCallMethod("*/block-occurancy", "normalizeBlockOccurancy", 0, (Class[]) null); - + + // special occurancy + digester.addObjectCreate("*/special-occurancy", Occurancy.class.getName()); + digester.addCallMethod("*/special-occurancy", "normalize", 0, (Class[]) null); + digester.addSetNext("*/special-occurancy", "setSpecialOccurancy", Occurancy.class.getName()); for (Special special : Special.values()) { - digester.addRule("*/special-occurancy/" + special.getCode(), new OccurancyRule(digester, special)); + digester.addRule("*/special-occurancy/" + special.getCode(), new OccurancyRule<Special>(digester, special)); } - - digester.addCallMethod("*/special-occurancy", "normalizeSpecialOccurancy", 0, (Class[]) null); - + digester.addCallMethod("*/sudden-death/time", "setSuddenDeathTime", 0, new Class[] { Integer.TYPE }); digester.addCallMethod("*/sudden-death/message", "setSuddenDeathMessage", 0); digester.addCallMethod("*/sudden-death/delay", "setSuddenDeathDelay", 0, new Class[] { Integer.TYPE }); @@ -133,41 +136,26 @@ /** * Custom rule to set the block and special occurancies. */ - private class OccurancyRule extends Rule + private class OccurancyRule<T extends Enum> extends Rule { - private Block block; - private Special special; + private T element; - public OccurancyRule(Digester digester, Block block) + public OccurancyRule(Digester digester, T element) { super(digester); - this.block = block; + this.element = element; } - public OccurancyRule(Digester digester, Special special) - { - super(digester); - this.special = special; - } - public void body(String body) throws Exception { // get the settings on the stack - Settings settings = (Settings) digester.peek(); + Occurancy<T> occurancy = (Occurancy<T>) digester.peek(); // get the value of the occurancy int value = Integer.parseInt(body); // set the value - if (special == null) - { - settings.setOccurancy(block, value); - } - else - { - settings.setOccurancy(special, value); - } + occurancy.setOccurancy(element, value); } } - } Added: jetrix/trunk/src/java/net/jetrix/config/Occurancy.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/config/Occurancy.java (rev 0) +++ jetrix/trunk/src/java/net/jetrix/config/Occurancy.java 2011-06-27 21:26:26 UTC (rev 872) @@ -0,0 +1,155 @@ +/** + * Jetrix TetriNET Server + * Copyright (C) 2011 Emmanuel Bourg + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package net.jetrix.config; + +import java.util.Arrays; + +/** + * The occurancies in percents of a set of elements. + * + * @author Emmanuel Bourg + * @version $Revision$, $Date$ + * @since 0.3 + */ +public class Occurancy<T extends Enum> implements Cloneable +{ + private int[] occurancies; + + /** + * Sets the occurancy of the specified element. + * + * @param element + * @param value + */ + public void setOccurancy(T element, int value) + { + if (occurancies == null) + { + Class enumType = element.getClass(); + occurancies = new int[enumType.getEnumConstants().length]; + } + occurancies[element.ordinal()] = value; + } + + /** + * Returns the occurancy of the specified element. + * + * @param element + */ + public int getOccurancy(T element) + { + return occurancies[element.ordinal()]; + } + + /** + * Normalizes the occurancies such that the sum is equal to 100. + * Negative values are considered null. + */ + public void normalize() + { + normalize(this.occurancies); + } + + void normalize(int[] occurancies) + { + int sum = 0; + + // computing sum + for (int i = 0; i < occurancies.length; i++) + { + if (occurancies[i] < 0) + { + occurancies[i] = 0; + } + sum = sum + occurancies[i]; + } + + if (sum != 100) + { + // equalization + if (sum == 0) + { + int v = 100 / occurancies.length; + for (int i = 0; i < occurancies.length; i++) + { + occurancies[i] = v; + } + } + else + { + float f = 100f / sum; + for (int i = 0; i < occurancies.length; i++) + { + occurancies[i] = (int) (occurancies[i] * f); + } + } + + // distributing points left + sum = 0; + for (int occurancy : occurancies) + { + sum = sum + occurancy; + } + int r = 100 - sum; + int i = 0; + while (i < occurancies.length && r > 0) + { + occurancies[i] = occurancies[i] + 1; + r = r - 1; + i = i + 1; + } + } + } + + public boolean equals(Object o) + { + if (this == o) + { + return true; + } + if (o == null || getClass() != o.getClass()) + { + return false; + } + + Occurancy occurancy = (Occurancy) o; + + return Arrays.equals(occurancies, occurancy.occurancies); + } + + public int hashCode() + { + return Arrays.hashCode(occurancies); + } + + public final Occurancy<T> clone() + { + try + { + Occurancy<T> occurancy = (Occurancy<T>) super.clone(); + occurancy.occurancies = occurancies.clone(); + return occurancy; + } + catch (CloneNotSupportedException e) + { + throw new InternalError(); + } + } +} Property changes on: jetrix/trunk/src/java/net/jetrix/config/Occurancy.java ___________________________________________________________________ Added: svn:keywords + Date Author Id Revision HeadURL Added: svn:eol-style + native Modified: jetrix/trunk/src/java/net/jetrix/config/Settings.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/config/Settings.java 2011-04-20 07:46:12 UTC (rev 871) +++ jetrix/trunk/src/java/net/jetrix/config/Settings.java 2011-06-27 21:26:26 UTC (rev 872) @@ -19,8 +19,6 @@ package net.jetrix.config; -import java.util.*; - /** * Game settings. * @@ -61,8 +59,8 @@ private int levelIncrease; private int specialAdded; private int specialCapacity; - private int blockOccurancy[]; - private int specialOccurancy[]; + private Occurancy<Block> blockOccurancy = new Occurancy<Block>(); + private Occurancy<Special> specialOccurancy = new Occurancy<Special>(); private boolean averageLevels; private boolean classicRules; private boolean sameBlocks; @@ -96,9 +94,6 @@ */ public Settings(boolean useDefaultSettings) { - blockOccurancy = new int[Block.values().length]; - specialOccurancy = new int [Special.values().length]; - if (useDefaultSettings) { defaultBlockOccurancy = true; @@ -211,12 +206,12 @@ public int getOccurancy(Block piece) { - return isDefaultBlockOccurancy() ? defaultSettings.getOccurancy(piece) : blockOccurancy[piece.ordinal()]; + return getBlockOccurancy().getOccurancy(piece); } public int getOccurancy(Special special) { - return isDefaultSpecialOccurancy() ? defaultSettings.getOccurancy(special) : specialOccurancy[special.ordinal()]; + return getSpecialOccurancy().getOccurancy(special); } public void setStartingLevel(int startingLevel) @@ -324,111 +319,28 @@ defaultSuddenDeathDelay = false; } - - /** - * Set the occurancy of a block. - * - * @since 0.2 - * - * @param block - * @param occurancy - */ - public void setOccurancy(Block block, int occurancy) + public Occurancy<Block> getBlockOccurancy() { - if (defaultBlockOccurancy) - { - defaultBlockOccurancy = false; - Arrays.fill(blockOccurancy, 0); - } - - blockOccurancy[block.ordinal()] = occurancy; + return defaultBlockOccurancy ? defaultSettings.blockOccurancy : blockOccurancy; } - /** - * Set the occurancy of a special block - * - * @since 0.2 - * - * @param special - * @param occurancy - */ - public void setOccurancy(Special special, int occurancy) + public void setBlockOccurancy(Occurancy<Block> blockOccurancy) { - if (defaultSpecialOccurancy) - { - defaultSpecialOccurancy = false; - Arrays.fill(specialOccurancy, 0); - } - - specialOccurancy[special.ordinal()] = occurancy; + defaultBlockOccurancy = false; + this.blockOccurancy = blockOccurancy; } - /** - * Normalize array values to get a sum equals to 100. - * Any negative value is nullified. - */ - protected void normalize(int[] tab) + public Occurancy<Special> getSpecialOccurancy() { - int sum = 0; - - // computing sum - for (int i = 0; i < tab.length; i++) - { - if (tab[i] < 0) - { - tab[i] = 0; - } - sum = sum + tab[i]; - } - - if (sum != 100) - { - // equalization - if (sum == 0) - { - int v = 100 / tab.length; - for (int i = 0; i < tab.length; i++) - { - tab[i] = v; - } - } - else - { - float f = 100f / sum; - for (int i = 0; i < tab.length; i++) - { - tab[i] = (int) (tab[i] * f); - } - } - - // distributing points left - sum = 0; - for (int i = 0; i < tab.length; i++) - { - sum = sum + tab[i]; - } - int r = 100 - sum; - int i = 0; - while (i < tab.length && r > 0) - { - tab[i] = tab[i] + 1; - r = r - 1; - i = i + 1; - } - } + return defaultSpecialOccurancy ? defaultSettings.specialOccurancy : specialOccurancy; } - - public void normalizeBlockOccurancy() + public void setSpecialOccurancy(Occurancy<Special> specialOccurancy) { - normalize(blockOccurancy); + defaultSpecialOccurancy = false; + this.specialOccurancy = specialOccurancy; } - public void normalizeSpecialOccurancy() - { - normalize(specialOccurancy); - } - private boolean isDefault() { return defaultSettings == null || this == defaultSettings; Modified: jetrix/trunk/src/java/net/jetrix/filter/DownstackPuzzleGenerator.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/filter/DownstackPuzzleGenerator.java 2011-04-20 07:46:12 UTC (rev 871) +++ jetrix/trunk/src/java/net/jetrix/filter/DownstackPuzzleGenerator.java 2011-06-27 21:26:26 UTC (rev 872) @@ -171,23 +171,27 @@ else if (line.startsWith("SPECIAL")) { // parse the special occurancies - String[] occurancy = StringUtils.split(line.substring(7).trim(), ' '); - + String[] values = StringUtils.split(line.substring(7).trim(), ' '); + + Occurancy<Special> occurancy = new Occurancy<Special>(); for (Special special : Special.values()) { - settings.setOccurancy(special, Integer.parseInt(occurancy[special.ordinal()])); + occurancy.setOccurancy(special, Integer.parseInt(values[special.ordinal()])); } + settings.setSpecialOccurancy(occurancy); } else if (line.startsWith("BLOCK")) { // parse the block occurancies - String[] occurancy = StringUtils.split(line.substring(5).trim(), ' '); - + String[] values = StringUtils.split(line.substring(5).trim(), ' '); + // careful, it doesn't follow the standard order + Occurancy<Block> occurancy = new Occurancy<Block>(); for (int i = 0; i < BLOCKS.length; i++) { - settings.setOccurancy(BLOCKS[i], Integer.parseInt(occurancy[i])); + occurancy.setOccurancy(BLOCKS[i], Integer.parseInt(values[i])); } + settings.setBlockOccurancy(occurancy); } else if (line.startsWith("SUDDENDEATHMSG")) { Modified: jetrix/trunk/src/java/net/jetrix/filter/RandomFilter.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/filter/RandomFilter.java 2011-04-20 07:46:12 UTC (rev 871) +++ jetrix/trunk/src/java/net/jetrix/filter/RandomFilter.java 2011-06-27 21:26:26 UTC (rev 872) @@ -19,11 +19,14 @@ package net.jetrix.filter; -import java.util.*; +import java.util.List; -import net.jetrix.*; -import net.jetrix.config.*; -import net.jetrix.messages.channel.*; +import net.jetrix.Message; +import net.jetrix.config.Block; +import net.jetrix.config.Occurancy; +import net.jetrix.config.Settings; +import net.jetrix.config.Special; +import net.jetrix.messages.channel.NewGameMessage; /** * A filter randomizing the blocks and the specials occurancies when the game starts. @@ -39,24 +42,25 @@ { // get the settings Settings settings = m.getSettings(); + + // randomize the block and special occurancies + settings.setBlockOccurancy(getRandomOccurancy(Block.class)); + settings.setSpecialOccurancy(getRandomOccurancy(Special.class)); + + // forward the new game message + out.add(m); + } - // randomize the block occurancies - for (Block block : Block.values()) + private <T extends Enum> Occurancy<T> getRandomOccurancy(Class<T> enumType) + { + Occurancy<T> occurancy = new Occurancy<T>(); + for (T element : enumType.getEnumConstants()) { - settings.setOccurancy(block, (int) (Math.random() * 100)); + occurancy.setOccurancy(element, (int) (Math.random() * 100)); } - - settings.normalizeBlockOccurancy(); - - for (Special special : Special.values()) - { - settings.setOccurancy(special, (int) (Math.random() * 100)); - } - - settings.normalizeSpecialOccurancy(); - - // forward the new game message - out.add(m); + + occurancy.normalize(); + + return occurancy; } - } Modified: jetrix/trunk/src/java/net/jetrix/listeners/interceptor/SpeedCheckInterceptor.java =================================================================== --- jetrix/trunk/src/java/net/jetrix/listeners/interceptor/SpeedCheckInterceptor.java 2011-04-20 07:46:12 UTC (rev 871) +++ jetrix/trunk/src/java/net/jetrix/listeners/interceptor/SpeedCheckInterceptor.java 2011-06-27 21:26:26 UTC (rev 872) @@ -29,6 +29,7 @@ import net.jetrix.config.Block; import net.jetrix.config.ServerConfig; import net.jetrix.config.Settings; +import net.jetrix.config.Occurancy; import net.jetrix.messages.channel.EndGameMessage; import net.jetrix.messages.channel.FieldMessage; import net.jetrix.messages.channel.GmsgMessage; @@ -81,11 +82,14 @@ protected void prologue(Client client) { // start the game at high speed with squares only - Settings settings = new Settings(); - settings.setOccurancy(Block.SQUARE, 100); + Settings settings = new Settings(false); settings.setStartingLevel(99); settings.setAverageLevels(false); + Occurancy<Block> occurancy = new Occurancy<Block>(); + occurancy.setOccurancy(Block.SQUARE, 100); + settings.setBlockOccurancy(occurancy); + client.send(new NewGameMessage(settings)); FieldMessage fieldmessage = new FieldMessage(getField().getFieldString()); Added: jetrix/trunk/src/test/net/jetrix/config/OccurancyTest.java =================================================================== --- jetrix/trunk/src/test/net/jetrix/config/OccurancyTest.java (rev 0) +++ jetrix/trunk/src/test/net/jetrix/config/OccurancyTest.java 2011-06-27 21:26:26 UTC (rev 872) @@ -0,0 +1,96 @@ +/** + * Jetrix TetriNET Server + * Copyright (C) 2011 Emmanuel Bourg + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +package net.jetrix.config; + +import junit.framework.TestCase; +import junitx.framework.ArrayAssert; + +/** + * @author Emmanuel Bourg + * @version $Revision$, $Date$ + */ +public class OccurancyTest extends TestCase +{ + private long sum(int[] values) + { + long sum = 0; + for (int value : values) + { + sum = sum + value; + } + return sum; + } + + public void testNormalize1() + { + Occurancy s = new Occurancy(); + int[] tab = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; + s.normalize(tab); + assertEquals("Erreur de normalisation", 100, sum(tab)); + } + + public void testNormalize2() + { + Occurancy s = new Occurancy(); + int[] tab = { 0, 0, 0, 0, 0 }; + s.normalize(tab); + assertEquals("Erreur de normalisation", 100, sum(tab)); + assertEquals("tab[0]", 20, tab[0]); + assertEquals("tab[1]", 20, tab[1]); + assertEquals("tab[2]", 20, tab[2]); + assertEquals("tab[3]", 20, tab[3]); + assertEquals("tab[4]", 20, tab[4]); + } + + public void testNormalize3() + { + Occurancy s = new Occurancy(); + int[] tab = { 100, 200, 300, 50, 100, 50, 250, 300 }; + s.normalize(tab); + assertEquals("Erreur de normalisation", 100, sum(tab)); + } + + public void testNormalize4() + { + Occurancy s = new Occurancy(); + int[] tab = { 8, 14, 1, 19, 5, 15, 3, 17, 6, 12 }; + s.normalize(tab); + assertEquals("Erreur de normalisation", 100, sum(tab)); + } + + public void testNormalize5() + { + Occurancy s = new Occurancy(); + int[] tab4 = { 8, 14, 1, 19, 5, 15, 3, 17, 6, 12 }; + int[] tab5 = { 8, 14, 1, 19, 5, 15, 3, 17, 6, 12 }; + s.normalize(tab4); + ArrayAssert.assertEquals("Normalization error", tab4, tab5); + } + + public void testNormalize6() + { + Occurancy s = new Occurancy(); + int[] tab = { 0, -10 }; + s.normalize(tab); + assertEquals("Erreur de normalisation", 100, sum(tab)); + assertEquals("tab[0]", 50, tab[0]); + assertEquals("tab[1]", 50, tab[1]); + } +} Property changes on: jetrix/trunk/src/test/net/jetrix/config/OccurancyTest.java ___________________________________________________________________ Added: svn:keywords + Date Author Id Revision HeadURL Added: svn:eol-style + native Modified: jetrix/trunk/src/test/net/jetrix/config/SettingsTest.java =================================================================== --- jetrix/trunk/src/test/net/jetrix/config/SettingsTest.java 2011-04-20 07:46:12 UTC (rev 871) +++ jetrix/trunk/src/test/net/jetrix/config/SettingsTest.java 2011-06-27 21:26:26 UTC (rev 872) @@ -19,7 +19,7 @@ package net.jetrix.config; -import junit.framework.*; +import junit.framework.TestCase; /** * JUnit TestCase for the class net.jetrix.config.Settings @@ -49,8 +49,8 @@ defaultSettings.setSuddenDeathMessage("Hurry Up!"); defaultSettings.setSuddenDeathTime(20); - defaultSettings.setOccurancy(Block.LINE, 10); - defaultSettings.setOccurancy(Special.GRAVITY, 10); + defaultSettings.getBlockOccurancy().setOccurancy(Block.LINE, 10); + defaultSettings.getSpecialOccurancy().setOccurancy(Special.GRAVITY, 10); Settings.setDefaultSettings(defaultSettings); } @@ -60,93 +60,6 @@ assertEquals(defaultSettings, Settings.getDefaultSettings()); } - public void testNormalize1() - { - Settings s = new Settings(); - int[] tab = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; - s.normalize(tab); - assertEquals("Erreur de normalisation", 100, sum(tab)); - } - - public void testNormalize2() - { - Settings s = new Settings(); - int[] tab = { 0, 0, 0, 0, 0 }; - s.normalize(tab); - assertEquals("Erreur de normalisation", 100, sum(tab)); - assertEquals("tab[0]", 20, tab[0]); - assertEquals("tab[1]", 20, tab[1]); - assertEquals("tab[2]", 20, tab[2]); - assertEquals("tab[3]", 20, tab[3]); - assertEquals("tab[4]", 20, tab[4]); - } - - public void testNormalize3() - { - Settings s = new Settings(); - int[] tab = { 100, 200, 300, 50, 100, 50, 250, 300 }; - s.normalize(tab); - assertEquals("Erreur de normalisation", 100, sum(tab)); - } - - public void testNormalize4() - { - Settings s = new Settings(); - int[] tab = { 8, 14, 1, 19, 5, 15, 3, 17, 6, 12 }; - s.normalize(tab); - assertEquals("Erreur de normalisation", 100, sum(tab)); - } - - public void testNormalize5() - { - Settings s = new Settings(); - int[] tab4 = { 8, 14, 1, 19, 5, 15, 3, 17, 6, 12 }; - int[] tab5 = { 8, 14, 1, 19, 5, 15, 3, 17, 6, 12 }; - s.normalize(tab4); - assertTrue("Erreur de normalisation", equals(tab4, tab5)); - } - - public void testNormalize6() - { - Settings s = new Settings(); - int[] tab = { 0, -10 }; - s.normalize(tab); - assertEquals("Erreur de normalisation", 100, sum(tab)); - assertEquals("tab[0]", 50, tab[0]); - assertEquals("tab[1]", 50, tab[1]); - } - - private long sum(int[] tab) - { - long s = 0; - for(int i=0; i<tab.length; i++) s = s + tab[i]; - return s; - } - - /** - * todo: replace with ArrayAssert from junit-addons - */ - private boolean equals(int[] a, int[] b) - { - boolean equals = true; - - if (a.length == b.length) - { - int i=0; - while(equals && i<a.length) - { - equals = (a[i]==b[i]); - i++; - } - } - else - { - equals = false; - } - - return equals; - } - public void testAverageLevels() { Settings settings = new Settings(); @@ -263,7 +176,7 @@ { Settings settings = new Settings(); assertEquals(defaultSettings.getOccurancy(Block.LINE), settings.getOccurancy(Block.LINE)); - settings.setOccurancy(Block.LINE, 50); + settings.getBlockOccurancy().setOccurancy(Block.LINE, 50); assertEquals(50, settings.getOccurancy(Block.LINE)); } @@ -271,8 +184,7 @@ { Settings settings = new Settings(); assertEquals(defaultSettings.getOccurancy(Special.GRAVITY), settings.getOccurancy(Special.GRAVITY)); - settings.setOccurancy(Special.GRAVITY, 50); + settings.getSpecialOccurancy().setOccurancy(Special.GRAVITY, 50); assertEquals(50, settings.getOccurancy(Special.GRAVITY)); } - } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sm...@us...> - 2012-02-18 15:00:23
|
Revision: 874 http://jetrix.svn.sourceforge.net/jetrix/?rev=874&view=rev Author: smanux Date: 2012-02-18 15:00:17 +0000 (Sat, 18 Feb 2012) Log Message: ----------- Removed the update system Modified Paths: -------------- jetrix/trunk/build.xml Removed Paths: ------------- jetrix/trunk/src/bin/update jetrix/trunk/src/bin/update.bat jetrix/trunk/src/java/net/jetrix/tools/patcher/ Modified: jetrix/trunk/build.xml =================================================================== --- jetrix/trunk/build.xml 2011-08-11 12:03:17 UTC (rev 873) +++ jetrix/trunk/build.xml 2012-02-18 15:00:17 UTC (rev 874) @@ -202,11 +202,9 @@ <zip zipfile="${dist}/bin/jetrix-${version}.zip"> <zipfileset prefix="jetrix-${version}" dir="${build}/dist" filemode="755"> <include name="jetrix"/> - <include name="update"/> </zipfileset> <zipfileset prefix="jetrix-${version}" dir="${build}/dist"> <exclude name="jetrix"/> - <exclude name="update"/> </zipfileset> </zip> @@ -214,11 +212,9 @@ <tar destfile="${dist}/bin/jetrix-${version}.tar.bz2" compression="bzip2"> <tarfileset prefix="jetrix-${version}" dir="${build}/dist" filemode="755"> <include name="jetrix"/> - <include name="update"/> </tarfileset> <tarfileset prefix="jetrix-${version}" dir="${build}/dist"> <exclude name="jetrix"/> - <exclude name="update"/> </tarfileset> </tar> @@ -239,7 +235,6 @@ </tarfileset> <tarfileset prefix="/usr/share/jetrix" dir="${build}/dist" username="root" group="root"> <exclude name="jetrix"/> - <exclude name="update"/> <exclude name="*.bat"/> </tarfileset> </deb> @@ -312,7 +307,6 @@ <mkdir dir="${deploy}"/> <unzip src="${dist}/bin/jetrix-${version}.zip" dest="${deploy}" /> <chmod file="${deploy}/jetrix-${version}/jetrix" perm="+x"/> - <chmod file="${deploy}/jetrix-${version}/update" perm="+x"/> </target> <target name="run" depends="deploy"> @@ -323,21 +317,6 @@ </java> </target> - <target name="update" depends="deploy" description="Uploads Jetrix to the patch server"> - <!-- Installing --> - <delete dir="${deploy}"/> - <mkdir dir="${deploy}"/> - <unzip src="${dist}/bin/jetrix-${version}.zip" dest="${deploy}" /> - - <!-- Checksum computation --> - <java classname="net.jetrix.tools.patcher.UpdateList" dir="${deploy}/jetrix-${version}" classpath="${deploy}/jetrix-${version}/lib/jetrix-${version}.jar" fork="yes" /> - - <!-- Uploading to patch server --> - <ftp server="${ftp.host}" remotedir="/vsite/tetrinet/public_html/jetrix/autoupdate" userid="${ftp.login}" password="${ftp.pass}" depends="yes" verbose="yes" ignoreNoncriticalErrors="yes"> - <fileset dir="${deploy}/jetrix-${version}"/> - </ftp> - </target> - <target name="docgen" depends="compile" description="Generates the documentation of the server commands"> <java classname="net.jetrix.tools.DocumentationGenerator" fork="true"> <classpath> Deleted: jetrix/trunk/src/bin/update =================================================================== --- jetrix/trunk/src/bin/update 2011-08-11 12:03:17 UTC (rev 873) +++ jetrix/trunk/src/bin/update 2012-02-18 15:00:17 UTC (rev 874) @@ -1,10 +0,0 @@ -#!/bin/sh - -if [ -n "$JAVA_HOME" ] -then - JAVA_PATH="$JAVA_HOME/bin/java"; -else - JAVA_PATH="java"; -fi - -$JAVA_PATH -cp lib/jetrix-@version@.jar net.jetrix.patcher.JetrixUpdate Deleted: jetrix/trunk/src/bin/update.bat =================================================================== --- jetrix/trunk/src/bin/update.bat 2011-08-11 12:03:17 UTC (rev 873) +++ jetrix/trunk/src/bin/update.bat 2012-02-18 15:00:17 UTC (rev 874) @@ -1,8 +0,0 @@ -@echo off - -SETLOCAL - -IF NOT JAVA_HOME == "" SET JAVA_EXE="%JAVA_HOME%\bin\java" -IF JAVA_HOME == "" SET JAVA_EXE=java - -%JAVA_EXE% -cp lib/jetrix-@version@.jar net.jetrix.tools.patcher.JetrixUpdate This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <sm...@us...> - 2012-02-20 11:18:22
|
Revision: 875 http://jetrix.svn.sourceforge.net/jetrix/?rev=875&view=rev Author: smanux Date: 2012-02-20 11:18:16 +0000 (Mon, 20 Feb 2012) Log Message: ----------- Updated the pack200 Ant task and simplified the build Modified Paths: -------------- jetrix/trunk/build.xml Added Paths: ----------- jetrix/trunk/lib/build/deployment-ant-pack200-1.0-rc1.jar Removed Paths: ------------- jetrix/trunk/lib/build/Pack200Task.jar Modified: jetrix/trunk/build.xml =================================================================== --- jetrix/trunk/build.xml 2012-02-18 15:00:17 UTC (rev 874) +++ jetrix/trunk/build.xml 2012-02-20 11:18:16 UTC (rev 875) @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="iso-8859-1"?> <project name="Jetrix TetriNET Server" default="dist" basedir="."> - <taskdef name="pack200" classname="com.sun.tools.apache.ant.pack200.Pack200Task" classpath="lib/build/Pack200Task.jar"/> + <taskdef resource="org/jdesktop/deployment/ant/pack200/antlib.xml" classpath="lib/build/deployment-ant-pack200-1.0-rc1.jar"/> <property name="compile.debug" value="true"/> <property name="compile.optimize" value="false"/> @@ -16,10 +16,7 @@ <property file="password.properties" /> <path id="classpath.main"> - <fileset dir="${lib}"> - <include name="**/*.jar"/> - <include name="**/*.zip"/> - </fileset> + <fileset dir="${lib}" includes="**/*.jar"/> </path> <target name="init"> @@ -98,9 +95,7 @@ <attribute name="Implementation-Title" value="Jetrix TetriNET Server"/> <attribute name="Implementation-Version" value="${version}"/> </manifest> - <fileset dir="${build}/classes"> - <exclude name="**/Launcher*.class"/> - </fileset> + <fileset dir="${build}/classes" excludes="**/Launcher*.class"/> <fileset dir="${src}/etc"> <include name="tetrinet-server.dtd"/> <include name="tetrinet-channels.dtd"/> @@ -116,9 +111,7 @@ <attribute name="Implementation-Version" value="${version}"/> <attribute name="Main-Class" value="net.jetrix.Launcher"/> </manifest> - <fileset dir="${build}/classes"> - <include name="**/Launcher*.class"/> - </fileset> + <fileset dir="${build}/classes" includes="**/Launcher*.class"/> </jar> <!-- Create the WAR for the administration console --> @@ -129,9 +122,7 @@ <exclude name="**/*.jsp"/> <exclude name="**/*.java"/> </fileset> - <classes dir="${build}/jsp"> - <include name="**/*.class"/> - </classes> + <classes dir="${build}/jsp" includes="**/*.class"/> </war> </target> @@ -146,23 +137,11 @@ <pack200 src="${dist}/webapp/jetrix-admin-${version}.war" destfile="${dist}/webapp/jetrix-admin-${version}.war.pack" gzipoutput="false" stripdebug="false" keepfileorder="false"/> <!-- Pack the dependencies --> - <antcall target="pack.lib" inheritAll="true"><param name="library" value="commons-digester"/></antcall> - <antcall target="pack.lib" inheritAll="true"><param name="library" value="commons-beanutils"/></antcall> - <antcall target="pack.lib" inheritAll="true"><param name="library" value="commons-lang-2.0-light"/></antcall> - <antcall target="pack.lib" inheritAll="true"><param name="library" value="commons-pool-1.4"/></antcall> - <antcall target="pack.lib" inheritAll="true"><param name="library" value="commons-dbcp-1.2.2"/></antcall> - <antcall target="pack.lib" inheritAll="true"><param name="library" value="winstone-lite-0.9.10"/></antcall> - <antcall target="pack.lib" inheritAll="true"><param name="library" value="jsp-api-light"/></antcall> - <antcall target="pack.lib" inheritAll="true"><param name="library" value="jasper-runtime"/></antcall> - <antcall target="pack.lib" inheritAll="true"><param name="library" value="jcrontab-1.4.1-light"/></antcall> - <antcall target="pack.lib" inheritAll="true"><param name="library" value="mailapi-1.4.1"/></antcall> - <antcall target="pack.lib" inheritAll="true"><param name="library" value="smtp-1.4.1"/></antcall> + <pack200 gzipoutput="false" stripdebug="true" keepfileorder="false" segmentlimit="-1" todir="${build}/lib"> + <fileset dir="${build}/lib" includes="*.jar" excludes="jetrix-${version}.jar"/> + </pack200> </target> - <target name="pack.lib" description="Pack the library specified by the ${library} property"> - <pack200 src="${build}/lib/${library}.jar" destfile="${build}/lib/${library}.jar.pack" gzipoutput="false" stripdebug="true" keepfileorder="false"/> - </target> - <target name="dist" depends="pack"> <mkdir dir="${build}/dist"/> @@ -178,21 +157,15 @@ <include name="data/**" /> <include name="log/**" /> </fileset> - <fileset dir="${build}"> - <include name="lib/*.pack" /> - </fileset> + <fileset dir="${build}" includes="lib/*.pack"/> <fileset dir="${dist}"> <include name="lib/jetrix-${version}.jar.pack" /> <include name="lib/jetrix-launcher-${version}.jar" /> </fileset> - <fileset dir="${src}"> - <include name="lang/**/*.properties" /> - </fileset> + <fileset dir="${src}" includes="lang/**/*.properties"/> </copy> <copy todir="${build}/dist/lib"> - <fileset dir="${dist}/webapp/"> - <include name="*.war.pack" /> - </fileset> + <fileset dir="${dist}/webapp/" includes="*.war.pack"/> </copy> <!-- Create the distribution directory --> @@ -200,27 +173,21 @@ <!-- Create the Windows distribution --> <zip zipfile="${dist}/bin/jetrix-${version}.zip"> - <zipfileset prefix="jetrix-${version}" dir="${build}/dist" filemode="755"> - <include name="jetrix"/> - </zipfileset> - <zipfileset prefix="jetrix-${version}" dir="${build}/dist"> - <exclude name="jetrix"/> - </zipfileset> + <zipfileset prefix="jetrix-${version}" dir="${build}/dist" includes="jetrix" filemode="755"/> + <zipfileset prefix="jetrix-${version}" dir="${build}/dist" excludes="jetrix"/> </zip> <!-- Create the Unix distribution --> <tar destfile="${dist}/bin/jetrix-${version}.tar.bz2" compression="bzip2"> - <tarfileset prefix="jetrix-${version}" dir="${build}/dist" filemode="755"> - <include name="jetrix"/> - </tarfileset> - <tarfileset prefix="jetrix-${version}" dir="${build}/dist"> - <exclude name="jetrix"/> - </tarfileset> + <tarfileset prefix="jetrix-${version}" dir="${build}/dist" includes="jetrix" filemode="755"/> + <tarfileset prefix="jetrix-${version}" dir="${build}/dist" excludes="jetrix"/> </tar> </target> - <target name="dist.linux" depends="dist" description="Build the Linux installer"> + <target name="dist.linux" depends="dist.debian" description="Build the Linux packages"/> + + <target name="dist.debian" depends="dist" description="Build the Debian package"> <mkdir dir="${build}/control"/> <copy todir="${build}/control" filtering="true" > <fileset dir="src/etc/deb/control"/> @@ -277,9 +244,7 @@ <include name="project.xml" /> <include name="project.properties" /> </zipfileset> - <zipfileset prefix="jetrix-${version}-src/src/" dir="${src}"> - <exclude name="site/"/> - </zipfileset> + <zipfileset prefix="jetrix-${version}-src/src/" dir="${src}" excludes="site/"/> <zipfileset prefix="jetrix-${version}-src/lib/" dir="${lib}" /> </zip> @@ -289,9 +254,7 @@ <include name="project.xml" /> <include name="project.properties" /> </tarfileset> - <tarfileset prefix="jetrix-${version}-src/src/" dir="${src}"> - <exclude name="site/"/> - </tarfileset> + <tarfileset prefix="jetrix-${version}-src/src/" dir="${src}" excludes="site/"/> <tarfileset prefix="jetrix-${version}-src/lib/" dir="${lib}" /> </tar> Deleted: jetrix/trunk/lib/build/Pack200Task.jar =================================================================== (Binary files differ) Added: jetrix/trunk/lib/build/deployment-ant-pack200-1.0-rc1.jar =================================================================== (Binary files differ) Property changes on: jetrix/trunk/lib/build/deployment-ant-pack200-1.0-rc1.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |