Android Open Source - it.alcacoop.fourinaline G Service Client






From Project

Back to project page it.alcacoop.fourinaline.

License

The source code is released under:

GNU General Public License

If you think the Android project it.alcacoop.fourinaline 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

/**
 ##################################################################
 #                     FOUR IN A LINE MOBILE                      #
 ##################################################################
 #                                                                #
 #  Authors: Domenico Martella - Francesco Valente                #
 #  E-mail: info@alcacoop.it                                      #
 #  Date:   18/10/2013                                            #
 #                                                                #
 ##################################################################
 #                                                                #
 #  Copyright (C) 2013   Alca Societa' Cooperativa                #
 #                                                                #
 #  This file is part of FOUR IN A LINE MOBILE.                   #
 #  FOUR IN A LINE MOBILE 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 3 of the License, or (at your option)          #
 #  any later version.                                            #
 #                                                                #
 #  FOUR IN A LINE MOBILE 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 v3 along with this program.                    #
 #  If not, see <http://http://www.gnu.org/licenses/>             #
 #                                                                #
 ##################################################################
**///from w  w  w  .j ava 2  s  .com

package it.alcacoop.fourinaline.gservice;


import it.alcacoop.fourinaline.FourInALine;
import it.alcacoop.fourinaline.fsm.FSM.Events;
import it.alcacoop.fourinaline.fsm.FSM.States;

import java.util.concurrent.ArrayBlockingQueue;


public class GServiceClient implements GServiceMessages {

  public static GServiceClient instance;
  public GServiceNetHandler queue;
  public GServiceCookieMonster coockieMonster;
  public ArrayBlockingQueue<String> sendQueue;
  private Thread sendThread;


  private GServiceClient() {
    queue = new GServiceNetHandler();
    coockieMonster = new GServiceCookieMonster();
    sendQueue = new ArrayBlockingQueue<String>(20);

    sendThread = new Thread() {
      @Override
      public void run() {
        while (true) {
          try {
            synchronized (sendThread) {
              wait(230);
            }
            String msg = sendQueue.take();
            FourInALine.Instance.nativeFunctions.gserviceSendReliableRealTimeMessage(msg);
          } catch (InterruptedException e) {
            e.printStackTrace();
          }
        }
      }
    };
    sendThread.start();
  }

  public static GServiceClient getInstance() {
    if (instance == null)
      instance = new GServiceClient();
    return instance;
  }


  public void connect() {
  }


  public void processReceivedMessage(String s) {
    int coockie = coockieMonster.getCookie(s);
    switch (coockie) {
      case GSERVICE_READY:
        queue.post(Events.GSERVICE_READY, null);
        // FourInALine.Instance.fsm.processEvent(Events.GSERVICE_READY, null);
        break;
      case GSERVICE_INIT_RATING:
        String chunks[] = s.split(" ");
        queue.post(Events.GSERVICE_INIT_RATING, Double.parseDouble(chunks[1]));
        break;
      case GSERVICE_HANDSHAKE:
        chunks = s.split(" ");
        queue.post(Events.GSERVICE_HANDSHAKE, Long.parseLong(chunks[1]));
        break;
      case GSERVICE_MOVE:
        chunks = s.split(" ");
        int col = Integer.parseInt(chunks[1]);
        queue.post(Events.GSERVICE_MOVES, col);
        break;
      case GSERVICE_CHATMSG:
        s = s.replace("90 ", "");
        FourInALine.Instance.fsm.processEvent(Events.GSERVICE_CHATMSG, s);
        break;
      case GSERVICE_ABANDON:
        chunks = s.split(" ");
        queue.reset();
        FourInALine.Instance.fsm.state(States.LOCAL_TURN);
        FourInALine.Instance.fsm.processEvent(Events.OPPONENT_LEAVE_OR_RESIGN, Integer.parseInt(chunks[1]));
        break;
      case GSERVICE_PING:
      case GSERVICE_ERROR:
        break;
      case GSERVICE_BYE:
        FourInALine.Instance.fsm.processEvent(Events.GSERVICE_BYE, null);
        break;
    }
  }


  public synchronized void sendMessage(String msg) {
    try {
      sendQueue.put(msg);
    } catch (InterruptedException e) {
      e.printStackTrace();
    }
  }


  public final static int STATUS_OK = 0;
  public final static int STATUS_NETWORK_ERROR_OPERATION_FAILED = 6;
  public final static int STATUS_REAL_TIME_INACTIVE_ROOM = 7005;

  public void leaveRoom(int code) {
    // FourInALine.Instance.nativeFunctions.gserviceResetRoom();
    switch (code) {
      case STATUS_OK:
        // opponent disconnected
        FourInALine.Instance.fsm.processEvent(Events.GSERVICE_ERROR, 0);
        break;
      case STATUS_NETWORK_ERROR_OPERATION_FAILED:
        // you disconnected
        FourInALine.Instance.fsm.processEvent(Events.GSERVICE_ERROR, 1);
        break;
      case STATUS_REAL_TIME_INACTIVE_ROOM:
        // activity stopped
        FourInALine.Instance.fsm.processEvent(Events.GSERVICE_ERROR, 2);
        break;
      default:
        FourInALine.Instance.fsm.processEvent(Events.GSERVICE_BYE, null);
        break;
    }
  }
}




Java Source Code List

android.UnusedStub.java
it.alcacoop.fourinaline.BaseGServiceApplication.java
it.alcacoop.fourinaline.FourInALineDesktop.java
it.alcacoop.fourinaline.FourInALine.java
it.alcacoop.fourinaline.GServiceApplication.java
it.alcacoop.fourinaline.GServiceInterface.java
it.alcacoop.fourinaline.MainActivity.java
it.alcacoop.fourinaline.NativeFunctions.java
it.alcacoop.fourinaline.PrivateDataManager.java
it.alcacoop.fourinaline.PurchaseActivity.java
it.alcacoop.fourinaline.SoundManager.java
it.alcacoop.fourinaline.actors.BoardImage.java
it.alcacoop.fourinaline.actors.Board.java
it.alcacoop.fourinaline.actors.ChatBox.java
it.alcacoop.fourinaline.actors.Checker.java
it.alcacoop.fourinaline.actors.FixedButtonGroup.java
it.alcacoop.fourinaline.actors.IconButton.java
it.alcacoop.fourinaline.actors.ParticleEffectActor.java
it.alcacoop.fourinaline.actors.PlayerBlock.java
it.alcacoop.fourinaline.actors.UIDialog.java
it.alcacoop.fourinaline.billingutils.Base64DecoderException.java
it.alcacoop.fourinaline.billingutils.Base64.java
it.alcacoop.fourinaline.billingutils.IabException.java
it.alcacoop.fourinaline.billingutils.IabHelper.java
it.alcacoop.fourinaline.billingutils.IabResult.java
it.alcacoop.fourinaline.billingutils.Inventory.java
it.alcacoop.fourinaline.billingutils.Purchase.java
it.alcacoop.fourinaline.billingutils.Security.java
it.alcacoop.fourinaline.billingutils.SkuDetails.java
it.alcacoop.fourinaline.client.GwtLauncher.java
it.alcacoop.fourinaline.fsm.FSM.java
it.alcacoop.fourinaline.gservice.GServiceClient.java
it.alcacoop.fourinaline.gservice.GServiceCookieMonster.java
it.alcacoop.fourinaline.gservice.GServiceMessages.java
it.alcacoop.fourinaline.gservice.GServiceNetHandler.java
it.alcacoop.fourinaline.layers.BaseScreen.java
it.alcacoop.fourinaline.layers.GameScreen.java
it.alcacoop.fourinaline.layers.MatchOptionsScreen.java
it.alcacoop.fourinaline.layers.MenuScreen.java
it.alcacoop.fourinaline.layers.OptionsScreen.java
it.alcacoop.fourinaline.layers.SplashScreen.java
it.alcacoop.fourinaline.logic.AIExecutor.java
it.alcacoop.fourinaline.logic.MatchState.java
it.alcacoop.fourinaline.util.Base64DecoderException.java
it.alcacoop.fourinaline.util.Base64.java
it.alcacoop.fourinaline.util.GServiceGameHelper.java
it.alcacoop.fourinaline.util.GameHelperUtils.java
it.alcacoop.fourinaline.utils.AchievementsManager.java
it.alcacoop.fourinaline.utils.AppDataManager.java
it.alcacoop.fourinaline.utils.ELORatingManager.java
org.gojul.fourinaline.model.AlphaBeta.java
org.gojul.fourinaline.model.DefaultEvalScore.java
org.gojul.fourinaline.model.EvalScore.java
org.gojul.fourinaline.model.GameModel.java