[jetrix-cvs] SF.net SVN: jetrix:[868] jetrix/trunk
Brought to you by:
smanux
|
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.
|