Android Open Source - Freebloks-Android N E T_ S E R V E R_ S T A T U S






From Project

Back to project page Freebloks-Android.

License

The source code is released under:

GNU General Public License

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;
/*w w  w . jav  a 2s  . c om*/
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;

public class NET_SERVER_STATUS extends NET_HEADER implements Serializable {
  private static final long serialVersionUID = 1L;

  public int player, computer, clients; /* int 8 */
  public int width, height; /* int 8 */
  public int stone_numbers_obsolete[] = new int[Stone.STONE_SIZE_MAX]; /* int8[5] */
  public GameMode gamemode; /* int8 */

  /* since 1.5, optional */
  public int spieler[]; /* int8[4] */
  public String client_names[]; /* uint8[8][16] */

  public int version;
  public int version_min;
  
  public int stone_numbers[] = new int[Stone.STONE_COUNT_ALL_SHAPES];
  
  private static final int 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 */
      throw new UnsupportedOperationException("unsupported protocol version: " + version_min);
    }
    
    if (isVersion(2)) {
      /* advanced */
      spieler = new int[4];
      spieler[0] = buffer[11];
      spieler[1] = buffer[12];
      spieler[2] = buffer[13];
      spieler[3] = buffer[14];

      client_names = new String[8];
      char tmp[] = new char[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];
    }
  }
  
  public boolean isVersion(int version) {
    return this.version >= version;
  }

  @Override
  void prepare(ByteArrayOutputStream bos) {
    throw new 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)
      throw new 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]];
  }
}




Java Source Code List

com.google.example.games.basegameutils.BaseGameActivity.java
com.google.example.games.basegameutils.GameHelperUtils.java
com.google.example.games.basegameutils.GameHelper.java
de.saschahlusiak.freebloks.AboutActivity.java
de.saschahlusiak.freebloks.Global.java
de.saschahlusiak.freebloks.backup.FreebloksBackupAgent.java
de.saschahlusiak.freebloks.controller.GameMode.java
de.saschahlusiak.freebloks.controller.JNIServer.java
de.saschahlusiak.freebloks.controller.PlayerData.java
de.saschahlusiak.freebloks.controller.SpielClientInterface.java
de.saschahlusiak.freebloks.controller.SpielClient.java
de.saschahlusiak.freebloks.controller.Spielleiter.java
de.saschahlusiak.freebloks.database.FreebloksDBOpenHandler.java
de.saschahlusiak.freebloks.database.FreebloksDB.java
de.saschahlusiak.freebloks.database.HighscoreDB.java
de.saschahlusiak.freebloks.donate.DonateActivity.java
de.saschahlusiak.freebloks.game.ActivityInterface.java
de.saschahlusiak.freebloks.game.AddScoreTask.java
de.saschahlusiak.freebloks.game.CustomGameDialog.java
de.saschahlusiak.freebloks.game.FreebloksActivity.java
de.saschahlusiak.freebloks.game.GameFinishActivity.java
de.saschahlusiak.freebloks.game.GameMenu.java
de.saschahlusiak.freebloks.game.RateAppDialog.java
de.saschahlusiak.freebloks.game.RetainedConfig.java
de.saschahlusiak.freebloks.game.SpielClientThread.java
de.saschahlusiak.freebloks.lobby.ChatEntry.java
de.saschahlusiak.freebloks.lobby.ChatListAdapter.java
de.saschahlusiak.freebloks.lobby.ColorAdapter.java
de.saschahlusiak.freebloks.lobby.LobbyDialog.java
de.saschahlusiak.freebloks.model.Player.java
de.saschahlusiak.freebloks.model.Spiel.java
de.saschahlusiak.freebloks.model.Stone.java
de.saschahlusiak.freebloks.model.Turn.java
de.saschahlusiak.freebloks.model.Turnpool.java
de.saschahlusiak.freebloks.network.NET_CHAT.java
de.saschahlusiak.freebloks.network.NET_CURRENT_PLAYER.java
de.saschahlusiak.freebloks.network.NET_GAME_FINISH.java
de.saschahlusiak.freebloks.network.NET_GRANT_PLAYER.java
de.saschahlusiak.freebloks.network.NET_HEADER.java
de.saschahlusiak.freebloks.network.NET_REQUEST_GAME_MODE.java
de.saschahlusiak.freebloks.network.NET_REQUEST_HINT.java
de.saschahlusiak.freebloks.network.NET_REQUEST_PLAYER.java
de.saschahlusiak.freebloks.network.NET_REQUEST_UNDO.java
de.saschahlusiak.freebloks.network.NET_REVOKE_PLAYER.java
de.saschahlusiak.freebloks.network.NET_SERVER_STATUS.java
de.saschahlusiak.freebloks.network.NET_SET_STONE.java
de.saschahlusiak.freebloks.network.NET_START_GAME.java
de.saschahlusiak.freebloks.network.NET_UNDO_STONE.java
de.saschahlusiak.freebloks.network.Network.java
de.saschahlusiak.freebloks.preferences.AboutFragment.java
de.saschahlusiak.freebloks.preferences.DisplayFragment.java
de.saschahlusiak.freebloks.preferences.FreebloksPreferences.java
de.saschahlusiak.freebloks.preferences.InterfaceFragment.java
de.saschahlusiak.freebloks.preferences.MiscFragment.java
de.saschahlusiak.freebloks.preferences.StatisticsFragment.java
de.saschahlusiak.freebloks.preferences.ThemePreference.java
de.saschahlusiak.freebloks.stats.StatisticsActivity.java
de.saschahlusiak.freebloks.stats.StatisticsAdapter.java
de.saschahlusiak.freebloks.view.BackgroundRenderer.java
de.saschahlusiak.freebloks.view.BoardRenderer.java
de.saschahlusiak.freebloks.view.Freebloks3DView.java
de.saschahlusiak.freebloks.view.FreebloksRenderer.java
de.saschahlusiak.freebloks.view.SimpleModel.java
de.saschahlusiak.freebloks.view.effects.AbsEffect.java
de.saschahlusiak.freebloks.view.effects.AbsStoneEffect.java
de.saschahlusiak.freebloks.view.effects.BoardStoneGlowEffect.java
de.saschahlusiak.freebloks.view.effects.EffectSet.java
de.saschahlusiak.freebloks.view.effects.Effect.java
de.saschahlusiak.freebloks.view.effects.PhysicalStoneEffect.java
de.saschahlusiak.freebloks.view.effects.StoneFadeEffect.java
de.saschahlusiak.freebloks.view.effects.StoneRollEffect.java
de.saschahlusiak.freebloks.view.effects.StoneUndoEffect.java
de.saschahlusiak.freebloks.view.model.Board.java
de.saschahlusiak.freebloks.view.model.CurrentStone.java
de.saschahlusiak.freebloks.view.model.Intro.java
de.saschahlusiak.freebloks.view.model.Sounds.java
de.saschahlusiak.freebloks.view.model.Theme.java
de.saschahlusiak.freebloks.view.model.ViewElement.java
de.saschahlusiak.freebloks.view.model.ViewModel.java
de.saschahlusiak.freebloks.view.model.Wheel.java