亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? handshake.java

?? --- --- --- 基于J2ME的游戲程序--------很有技巧性的程序
?? JAVA
字號:
// Copyright (c) 2005 Sony Ericsson Mobile Communications AB
//
// This software is provided "AS IS," without a warranty of any kind. 
// ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, 
// INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A 
// PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. 
//
// THIS SOFTWARE IS COMPLEMENTARY OF JAYWAY AB (www.jayway.se)

package bluegammon.io;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;

import bluegammon.Device;
import bluegammon.Bluegammon;
import bluegammon.RmsFacade;
import bluegammon.logic.Rand;
import bluegammon.logic.GameRecord;
import bluegammon.logic.Rules;

/**
 * <p>
 * A <code>Handshake</code> consists of sending and receiving data as specified
 * below, where one player has server role and the other has client role.
 * </p><p>
 * Stores needed data for further setup, and initializes static aspects
 * of the game (rules and random seed).
 * </p><p>
 * <pre>
 * SERVER                              CLIENT
 *                                     SEND random seed (int)
 *                                     SEND client id (int)
 *                                     SEND client name (UTF)
 * SEND has saved game (boolean)
 * IF saved game: SEND saved data (byte[])
 * SEND server id (int)
 * SEND server name (UTF)
 * SEND client color (boolean)
 * IF no saved game: SEND rules(int)
 *                                     IF no remote saved game: SEND has saved game (boolean)
 *                                     IF no remote saved game AND has saved game: SEND saved data (byte[])
 * </pre>
 * </p>
 * @author Peter Andersson
 */
public class Handshake
{
  /** The id of the remote device being handshaked with*/
  protected int m_remoteId;
  /** The name of the remote device being handshaked with*/
  protected char[] m_remoteName;
  /**
   * The saved game data shared between this device and
   * remote device being handshaked with. The server device
   * has preference.
   */
  protected byte[] m_savedGame;
  /**
   * The color of the this device, as decided between this device
   * and the device being handshaked with.
   */
  protected boolean m_white;
  /**
   * Flag indicating if the saved game data comes from the
   * remote device being handshaked with.
   */
  protected boolean m_remoteResume;
  
  /**
   * Performs a handshake as a server. This will
   * exchange data and any shared game with the other device.
   * 
   * @param dis           The input stream from the other device.
   * @param dos			  The output stream to the other device.
   * @param localName     The name of this device.
   * @throws IOException  if the handshake fails.
   */
  public void serverHandshake(
      DataInputStream dis, DataOutputStream dos, String localName)
      throws IOException
  {
    m_savedGame = null;
    
    // Receive client stats
    long randomSeed = dis.readLong();
    Rand.setRandomSeed(randomSeed);    
    m_remoteId = dis.readInt();
    m_remoteName = dis.readUTF().toCharArray();
    
    // Check for saved game here on server
    m_savedGame = GameRecord.getSavedGame(m_remoteId);
    boolean hasSavedGame = m_savedGame != null;
    dos.writeBoolean(hasSavedGame);
    if (hasSavedGame)
    {
      m_remoteResume = false;
      dos.writeInt(m_savedGame.length);
      for (int i = 0; i < m_savedGame.length; i++)
      {
        dos.writeByte(m_savedGame[i]);
      }
    }
    
    // Send server stats
    dos.writeInt(Device.getDeviceId());
    dos.writeUTF(localName);
    m_white = !RmsFacade.getBoolean(Bluegammon.BLACK_PREFERRED);
    dos.writeBoolean(!m_white);
    if (!hasSavedGame) Rules.saveRules(dos);
    dos.flush();
    
    // Get remote saved game, if no saved game here
    if (!hasSavedGame)
    {
      boolean remoteSavedGame = dis.readBoolean();
      if (remoteSavedGame)
      {
        m_remoteResume = true;
        int len = dis.readInt();
        m_savedGame = new byte[len];
        for (int i = 0; i < len; i++)
        {
          m_savedGame[i] = dis.readByte();
        }
      }
    }
  }
  
  /**
   * Performs a handshake as a client. This will
   * exchange data and any shared game with the other device.
   * 
   * @param dis           The input stream from the other device.
   * @param dos			  The output stream to the other device.
   * @param localName     The name of this device.
   * @throws IOException  if the handshake fails.
   */
  public void clientHandshake(
      DataInputStream dis, DataOutputStream dos, String localName)
	  throws IOException
  {
    m_savedGame = null;
    long randomSeed = System.currentTimeMillis();
    Rand.setRandomSeed(randomSeed);
   
    // Send client stats
    dos.writeLong(randomSeed);
    dos.writeInt(Device.getDeviceId());
    dos.writeUTF(localName);
    dos.flush();
    
    // Check for remote saved game on server
    boolean remoteHasSavedGame = dis.readBoolean();
    if (remoteHasSavedGame)
    {
      m_remoteResume = true;
      int len = dis.readInt();
      m_savedGame = new byte[len];
      for (int i = 0; i < len; i++)
      {
        m_savedGame[i] = dis.readByte();
      }
    }
    
    // Receive server stats
    m_remoteId = dis.readInt();
    m_remoteName = dis.readUTF().toCharArray();
    m_white = dis.readBoolean();
    if (!remoteHasSavedGame) Rules.loadRules(dis);
    
    // Check for saved game here on client if no remote saved game
    if (!remoteHasSavedGame)
    {
      m_savedGame = GameRecord.getSavedGame(m_remoteId);
      boolean hasSavedGame = m_savedGame != null;
      dos.writeBoolean(hasSavedGame);
      if (hasSavedGame)
      {
        m_remoteResume = false;
        dos.writeInt(m_savedGame.length);
        for (int i = 0; i < m_savedGame.length; i++)
        {
          dos.writeByte(m_savedGame[i]);
        }
      }
      dos.flush();
    }
  }
  
  /**
   * Returns the id of the other device after a successful handshake.
   * 
   * @return   The id of the remote device.
   */
  public int getRemoteId()
  {
    return m_remoteId;
  }
  
  /**
   * Returns the name of the other device after a successful handshake.
   * 
   * @return   The name of the remote device.
   */
  public char[] getRemoteName()
  {
    return m_remoteName;
  }
  
  /**
   * Returns the data of a shared saved game. If there was no
   * shared saved game betweed these devices, null is returned.
   * 
   * @return   The shared saved game data or null.
   */
  public byte[] getSavedGame()
  {
    return m_savedGame;
  }
  
  /**
   * Returns the color of this device as decided by the handshake.
   * If a saved game exists, this value is arbitrary.
   * 
   * @return   The local device's color, true for white, false for black.
   */
  public boolean isWhite()
  {
    return m_white;
  }
  
  /**
   * Returns whether the saved game data was collected from the
   * remote device or from this device. If there is no saved game
   * data, this method always returns false.
   * 
   * @return  true if saved game data was collected from remote
   *          device, false if it was collected from local device.
   */
  public boolean isRemoteResume()
  {
    return m_remoteResume;
  }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美一卡二卡在线观看| 91免费观看视频在线| 香蕉影视欧美成人| 亚洲精品中文在线观看| 一区二区三区日韩精品视频| 亚洲精品国产精华液| 亚洲午夜久久久久久久久电影网| 亚洲女同女同女同女同女同69| 亚洲色图欧洲色图婷婷| 亚洲国产综合色| 日韩成人av影视| 国产裸体歌舞团一区二区| 国产精品夜夜嗨| 不卡的av电影在线观看| 欧美在线观看视频一区二区 | 中文在线一区二区| 国产精品剧情在线亚洲| 亚洲午夜在线电影| 另类小说一区二区三区| 丁香亚洲综合激情啪啪综合| 91免费视频大全| 欧美一区二区大片| 久久久久国产精品免费免费搜索| 国产精品久线在线观看| 日韩国产精品久久久| 国内精品伊人久久久久影院对白| 粗大黑人巨茎大战欧美成人| 欧洲视频一区二区| 日韩一级大片在线观看| 国产精品久久久久久久久果冻传媒 | 成人在线一区二区三区| 欧美在线观看视频一区二区三区| 日韩欧美的一区二区| 日韩一区日韩二区| 蜜桃免费网站一区二区三区| 成人黄色一级视频| 777xxx欧美| 亚洲天堂2014| 国产一区二区三区综合| 欧美久久久久久蜜桃| 欧美国产欧美综合| 免费观看在线综合| 一本在线高清不卡dvd| 精品对白一区国产伦| 亚洲精品久久嫩草网站秘色| 国产精品99久久久久久久女警| 欧美影院一区二区三区| 久久毛片高清国产| 五月激情六月综合| bt欧美亚洲午夜电影天堂| 精品国产乱码久久久久久图片| 亚洲制服丝袜av| 成人黄色一级视频| 国产亚洲一区字幕| 免费观看日韩电影| 这里只有精品电影| 亚洲图片欧美综合| av在线播放一区二区三区| 久久久午夜精品| 精品一区免费av| 91麻豆精品国产91久久久久 | 亚洲欧洲性图库| 精品一二三四在线| 日韩一区二区三免费高清| 亚洲综合免费观看高清完整版在线| 国产成人高清视频| 日本一区二区三区视频视频| 九色综合狠狠综合久久| 欧美一区二区视频在线观看2020| 亚洲精品乱码久久久久久黑人| 99国产精品99久久久久久| 国产精品麻豆视频| av在线播放成人| 亚洲男同性恋视频| 在线观看不卡一区| 91精品国产麻豆| 7777精品伊人久久久大香线蕉完整版 | 国产专区欧美精品| 欧美一区二区三区免费在线看| 国产欧美一区二区三区鸳鸯浴| 亚洲一区视频在线| 欧美色精品在线视频| 懂色中文一区二区在线播放| 免费精品视频在线| 一区二区三区不卡视频 | 自拍偷拍国产精品| 欧美xxxxx牲另类人与| 在线观看欧美精品| 99re这里只有精品6| 国产成人自拍在线| 看国产成人h片视频| 亚洲国产精品久久不卡毛片 | 97se亚洲国产综合自在线不卡| 久久国产综合精品| 日韩国产在线观看一区| 亚洲欧洲精品一区二区精品久久久| 337p粉嫩大胆色噜噜噜噜亚洲| 欧美日韩亚洲综合一区| 在线视频欧美精品| 97se亚洲国产综合自在线观| 懂色av一区二区三区蜜臀| 精品一区二区在线视频| 奇米888四色在线精品| 亚洲成人免费影院| 午夜不卡av免费| 亚洲成人精品一区| 亚洲va在线va天堂| 五月天丁香久久| 天天综合色天天综合色h| 亚洲国产综合色| 无吗不卡中文字幕| 免费成人深夜小野草| 蜜臀av一区二区| 久草精品在线观看| 国产精品影视天天线| 国产成人在线视频播放| 岛国精品在线观看| 成人福利视频在线| 色综合久久中文字幕| 欧美亚男人的天堂| 欧美久久久久久久久| 日韩小视频在线观看专区| 日韩欧美一区二区三区在线| 久久综合九色欧美综合狠狠 | 亚洲三级电影全部在线观看高清| 亚洲视频在线一区观看| 一区二区三区四区亚洲| 午夜激情综合网| 蜜臀久久99精品久久久久久9| 韩国v欧美v亚洲v日本v| 成人午夜碰碰视频| 91日韩在线专区| 制服丝袜中文字幕一区| 精品黑人一区二区三区久久| 国产欧美精品一区| 一区二区三区鲁丝不卡| 日本成人在线电影网| 国产福利一区在线| 一本色道久久综合亚洲aⅴ蜜桃| 欧美日韩中文字幕一区| 精品免费日韩av| 亚洲欧美色图小说| 免费亚洲电影在线| 99久久精品情趣| 91精品国产免费久久综合| 久久久亚洲综合| 一区二区三区免费观看| 蜜臀av国产精品久久久久| 成人毛片视频在线观看| 精品视频色一区| 中文字幕av一区 二区| 午夜欧美视频在线观看| 国产福利一区二区| 3atv一区二区三区| 国产精品久久综合| 青娱乐精品在线视频| 97aⅴ精品视频一二三区| 这里只有精品电影| 亚洲蜜桃精久久久久久久| 美女一区二区三区| 91福利小视频| 国产欧美日韩卡一| 免费高清视频精品| 欧日韩精品视频| 国产精品国产自产拍高清av王其| 婷婷久久综合九色综合伊人色| 国产成人99久久亚洲综合精品| 欧美精品在线视频| 中文字幕永久在线不卡| 国产一区二区成人久久免费影院 | 青青草国产成人99久久| 99久久国产综合色|国产精品| 欧美一级一区二区| 一区二区三区中文在线观看| 国产高清久久久| 日韩片之四级片| 午夜精品久久久久久久蜜桃app| 成人aaaa免费全部观看| 2014亚洲片线观看视频免费| 欧美aaaaaa午夜精品| 欧美日韩一级二级| 亚洲影视在线播放| 色狠狠一区二区| 亚洲三级理论片| 99精品桃花视频在线观看| 中文字幕在线免费不卡| 国产成人亚洲精品狼色在线| 精品三级在线看| 美女看a上一区| 欧美电影免费观看高清完整版| 亚洲va欧美va人人爽| 在线观看精品一区| 一区二区三区电影在线播| 99re这里只有精品视频首页| 亚洲欧洲无码一区二区三区| 97se亚洲国产综合自在线不卡| 国产精品白丝在线| av中文字幕不卡| 一区二区三区欧美亚洲| 欧美日韩日本视频|