If you think the Android project Freebloks-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code
package de.saschahlusiak.freebloks.network;
/*www.java2s.com*/import java.io.ByteArrayOutputStream;
import java.io.Serializable;
import java.security.InvalidParameterException;
import android.content.res.Resources;
import de.saschahlusiak.freebloks.R;
import de.saschahlusiak.freebloks.controller.GameMode;
import de.saschahlusiak.freebloks.model.Stone;
publicclass NET_SERVER_STATUS extends NET_HEADER implements Serializable {
privatestaticfinallong serialVersionUID = 1L;
publicint player, computer, clients; /* int 8 */publicint width, height; /* int 8 */publicint stone_numbers_obsolete[] = newint[Stone.STONE_SIZE_MAX]; /* int8[5] */public GameMode gamemode; /* int8 *//* since 1.5, optional */publicint spieler[]; /* int8[4] */public String client_names[]; /* uint8[8][16] */publicint version;
publicint version_min;
publicint stone_numbers[] = newint[Stone.STONE_COUNT_ALL_SHAPES];
privatestaticfinalint VERSION_MAX = 3; // highest version we understand.
public NET_SERVER_STATUS(NET_HEADER from) throws UnsupportedOperationException {
super(from);
player = buffer[0];
computer = buffer[1];
clients = buffer[2];
width = buffer[3];
height = buffer[4];
gamemode = GameMode.from(buffer[10]);
version = 1;
version_min = 1;
if (from.data_length >= 11 + 4 + 16 * 8)
version = 2;
if (from.data_length >= 11 + 4 + 16 * 8 + 2) {
version = buffer[11 + 4 + 16 * 8 + 0];
version_min = buffer[11 + 4 + 16 * 8 + 1];
}
if (version_min > VERSION_MAX) {
/* we don't know how to speak version_min, the minimum required version */thrownew UnsupportedOperationException("unsupported protocol version: " + version_min);
}
if (isVersion(2)) {
/* advanced */
spieler = newint[4];
spieler[0] = buffer[11];
spieler[1] = buffer[12];
spieler[2] = buffer[13];
spieler[3] = buffer[14];
client_names = new String[8];
char tmp[] = newchar[16];
for (int i = 0; i < 8; i++) {
int j;
for (j = 0; j < 16; j++) {
tmp[j] = (char)unsigned(buffer[15 + i * 16 + j]);
if (tmp[j] == 0)
break;
}
if (j > 0)
client_names[i] = new String(tmp, 0, j);
else
client_names[i] = null;
}
}
for (int i = 0; i < Stone.STONE_SIZE_MAX; i++)
stone_numbers_obsolete[i] = buffer[5 + i];
if (isVersion(3)) {
for (int i = 0; i < Stone.STONE_COUNT_ALL_SHAPES; i++)
stone_numbers[i] = buffer[11 + 4 + 16 * 8 + 2 + i];
}
}
publicboolean isVersion(int version) {
return this.version >= version;
}
@Override
void prepare(ByteArrayOutputStream bos) {
thrownew RuntimeException("not implemented");
}
public String getClientName(Resources resources, int client) {
if (client_names == null || client < 0 || client_names[client] == null)
return resources.getString(R.string.client_d, client + 1);
return client_names[client];
}
public String getPlayerName(Resources resources, int player, int color) {
if (player < 0)
thrownew InvalidParameterException();
String color_name = resources.getStringArray(R.array.color_names)[color];
if (spieler == null)
return color_name;
if (client_names == null)
return color_name;
if (spieler[player] < 0)
return color_name;
if (client_names[spieler[player]] == null)
return color_name;
return client_names[spieler[player]];
}
}