public void onGameDoesNotExistCommand(SCMessageInfo info)
 {
     SCHand.handWithFocus = handHolder;
     gui.client.unInit();
     gui.currentError = new SCErrorInfo("Game no longer exists", 3);
     switchToWindow(SCGUI.WINDOW_ERROR);
 }
 public void onGameStartedCommand(SCMessageInfo info)
 {
     hand.clear(true);
     gui.table.clear(true);
     gui.currentScreen = SCGUI.SCREEN_IN_GAME;
     switchToWindow(SCGUI.WINDOW_NOTHING);
 }
 public void onGameDoesNotExistCommand(SCMessageInfo info)
 {
     gui.client.unInit();
     gui.currentScreen = SCGUI.SCREEN_PLAY_WITH_FRIENDS;
     gui.currentError = new SCErrorInfo("Game no longer exists", 3);
     gui.currentWindow = SCGUI.WINDOW_ERROR;
 }
 public void executeCallback(SCMessageInfo info)
 {
     if(mCallback1 == null){
         mCallback2();
     }else{
         mCallback1(info);
     }
 }
Example #5
0
 public void processMessage(string command, SCMessageInfo info)
 {
     for(int i = 0; i < commandBehaviours.Count; ++i){
         if(commandBehaviours[i].command == command){
             commandBehaviours[i].executeCallback(info);
         }
     }
 }
 public void onAddedPlayerCommand(SCMessageInfo info)
 {
     string name = info.getValue("name");
     if(name == null){
         return;
     }
     for(int i = 0; i < mPlayersInLobby.Count; ++i){
         if(mPlayersInLobby[i] == name){
             //return;
         }
     }
     mPlayersInLobby.Add(name);
 }
 public void onLobbyStatusCommand(SCMessageInfo info)
 {
     playersInLobby.Clear();
     int index = 1;
     while(true){
         string name = info.getValue("name" + index);
         //string status = info.getValue("status" + index);
         if(name == null){
             return;
         }
         playersInLobby.Add(name);
         ++index;
     }
 }
    // only positive ints for now
    public static SCMessageInfo decodeMessage(string message)
    {
        int startIndex = -1;

        for(int i = 0; i < message.Length; ++i){
            if(message[i] == ':'){
                startIndex = i + 1;
                break;
            }
        }

        if(startIndex == -1){
            //Debug.Log("No info after the command");
            return new SCMessageInfo();
        }

        SCMessageInfo messageInfo = new SCMessageInfo();
        int index = startIndex;
        bool readingKey = true;
        bool readingValue = false;
        string key = "";
        string value = "";
        while(index < message.Length){
            if(message[index] == '='){
                readingKey = false;
                readingValue = true;
                value = "";
            }else if(message[index] == ','){
                messageInfo.addPair(key, value);
                readingValue = false;
                readingKey = true;
                key = "";
            }else if(readingKey){
                key += message[index];
            }else if(readingValue){
                value += message[index];
            }
            ++index;
        }
        if(key != ""){
            messageInfo.addPair(key, value);
        }
        return messageInfo;
    }
 private void onReadyCommand(SCMessageInfo info)
 {
     string value = info.getValue("value");
     string reason = info.getValue("reason");
     string extra = info.getValue("extra");
     if(value == "true"){
         localServer.userReady(true, reason, extra, info.fromConnectionId);
     }else{
         localServer.userReady(false, reason, extra, info.fromConnectionId);
     }
 }
 public void onEnteredWrongPasswordCommand(SCMessageInfo info)
 {
     SCHand.handWithFocus = handHolder;
     gui.currentError = new SCErrorInfo("Incorrect password.", 3);
     switchToWindow(SCGUI.WINDOW_ERROR);
 }
Example #11
0
    private void onRequestGameInfoCommand(SCMessageInfo info)
    {
        communicator.disconnectFromMasterServer();

        string user = info.getValue("user");
        string pass = info.getValue("pass");
        string players = info.getValue("players");
        string ip = info.getValue("ip");
        string port = info.getValue("port");
        string error = info.getValue("error");
        if(user == null || pass == null || players == null || ip == null || port == null){
            SCCommunicator.fireCommand("game_not_found");
            if(error == "game_not_found"){

            }
            return;
        }
        SCCommunicator.fireCommand("game_found:name=" + user + ",pass="******",players=" + players);
        communicator.serverIp = SCNetworkUtil.removeIpPrefix(ip);
        communicator.serverPort = SCNetworkUtil.toInt(port);
    }
Example #12
0
 private void onReconnectingCommand(SCMessageInfo info)
 {
     string uniqueId = info.getValue("uniqueId");
     if(uniqueId == null){
         return;
     }
     processReconnection(SCNetworkUtil.toInt(uniqueId), info.fromConnectionId);
 }
Example #13
0
 private void onUnfreezeClientCommand(SCMessageInfo info)
 {
     SCHand hand = communicator.gameObject.GetComponentInChildren<SCHand>();
     hand.allowInput(info.getValue("reason"));
 }
Example #14
0
    private void onUpdateGameCommand(SCMessageInfo info)
    {
        string players = info.getValue("players");
        if(players == null){
            return;
        }

        SCGameInfo game = SCGameInfo.getGameCreatedByConnectionId(games, info.fromConnectionId);
        int iPlayers = SCNetworkUtil.toInt(players);
        if(iPlayers == game.totalNumberOfPlayers){
            Debug.Log("SCBrain| Game is full created by user: "******"SCBrain| Players updated to " + iPlayers + " for game created by user: " + game.createdByUser);
            game.numberOfConnectedPlayers = iPlayers;
        }
    }
Example #15
0
 /********************************************************************************************/
 /** Command Functions ***********************************************************************/
 /********************************************************************************************/
 private void onFirstTimeCommand(SCMessageInfo info)
 {
     communicator.sendMessageTo(info.fromConnectionId, "connected:uniqueId=" + logic.generateUniqueId());
 }
Example #16
0
 private void onSkipTurnCommand(SCMessageInfo info)
 {
     localServer.userSkippedTurn();
 }
 public void onGameStartedCommand(SCMessageInfo info)
 {
     gui.currentScreen = SCGUI.SCREEN_IN_GAME;
 }
 public void onEnteredWrongPasswordCommand(SCMessageInfo info)
 {
     gui.currentScreen = SCGUI.SCREEN_JOIN_GAME;
     gui.currentError = new SCErrorInfo("Incorrect password.", 3);
     gui.currentWindow = SCGUI.WINDOW_ERROR;
 }
 private void onGameNotFoundCommand(SCMessageInfo info)
 {
     mGameFound = "Game not found";
     mAlreadySearching = false;
 }
Example #20
0
 private void onUpdateTopCardsCommand(SCMessageInfo info)
 {
     SCTable table = communicator.gameObject.GetComponentInChildren<SCTable>();
     SCCardInfo[] cards = new SCCardInfo[4];
     for(int i = 0; i < 4; ++i){
         string suit = info.getValue("suit" + i);
         string number = info.getValue("number" + i);
         if(suit == null || number == null){
             break;
         }
         cards[i] = new SCCardInfo(suit, SCNetworkUtil.toInt(number));
     }
     if(cards[0] == null){
         return;
     }else{
         table.getRules().updateTopCards(cards, false);
     }
 }
Example #21
0
 private void onQuitCommand(SCMessageInfo info)
 {
     string first = info.getValue("first");
     if(first == null){
         return;
     }
     if(first == "true"){
         localServer.userQuit(info.fromConnectionId);
     }else{
         string name = info.getValue("name");
         if(name == null){
             return;
         }
         SCCommunicator.fireCommand("quit:first=false,name=" + name);
     }
 }
Example #22
0
 private void onPlayCardCommand(SCMessageInfo info)
 {
     SCCardInfo[] playedCards = new SCCardInfo[4];
     for(int i = 0; i < playedCards.Length; ++i){
         string suit = info.getValue("suit" + (i + 1));
         string number = info.getValue("number" + (i + 1));
         if(suit == null || number == null){
             break;
         }
         playedCards[i] = new SCCardInfo(suit, SCNetworkUtil.toInt(number));
     }
     localServer.userPlayed(playedCards, info.getValue("extra"));
 }
Example #23
0
 private void onCreateGameCommand(SCMessageInfo info)
 {
     string user = info.getValue("user");
     string uniqueId = info.getValue("uniqueId");
     string hasPassword = info.getValue("pass");
     string totalPlayers = info.getValue("total");
     if(user == null || uniqueId == null || hasPassword == null || totalPlayers == null){
         return;
     }
     Debug.Log("SCBrain| New game created by user: "******"true" ? true : false),
                              SCNetworkUtil.toInt(totalPlayers),
                              communicator.getConnectionInfo(info.fromConnectionId),
                              forget));
 }
 public void onServerDestroyedCommand(SCMessageInfo info)
 {
     SCHand.handWithFocus = handHolder;
     gui.client.unInit();
     gui.currentError = new SCErrorInfo("Host has quit the game", 3);
     switchToWindow(SCGUI.WINDOW_ERROR);
 }
Example #25
0
 private void onForgetGameCommand(SCMessageInfo info)
 {
     forget(SCGameInfo.getGameCreatedByConnectionId(games, info.fromConnectionId));
 }
Example #26
0
 private void onScrapPileCommand(SCMessageInfo info)
 {
     string safe = info.getValue("safe");
     SCTable table = communicator.gameObject.GetComponentInChildren<SCTable>();
     if(safe == "true"){
         table.safeScrapPile();
     }else{
         table.scrapPile();
     }
 }
Example #27
0
    private void onRequestGameCommand(SCMessageInfo info)
    {
        string user = info.getValue("user");
        if(user == null){
            return;
        }

        SCGameInfo game = SCGameInfo.getGameCreatedByUser(games, user);
        if(game == null){
            communicator.sendMessageTo(info.fromConnectionId, "request_game_info:error=game_not_found");
            return;
        }
        Debug.Log("SCBrain| User requested game created by: " + game.createdByUser);
        communicator.sendMessageTo(info.fromConnectionId, "request_game_info:" +
                                   						  "user="******"," +
                                   						  "pass="******"true" : "false") + "," +
                                   						  "players=" + game.numberOfConnectedPlayers + "," +
                                   						  "ip=" + game.connectionInfo.getIp() + "," +
                                   						  "port=" + game.connectionInfo.getPort());
    }
Example #28
0
 private void onSpawnCardCommand(SCMessageInfo info)
 {
     SCTable table = communicator.gameObject.GetComponentInChildren<SCTable>();
     SCCardInfo[] cardsToSpawn = new SCCardInfo[4];
     for(int i = 1; i <= cardsToSpawn.Length; ++i){
         string suit = info.getValue("suit" + i);
         string number = info.getValue("number" + i);
         if(suit == null || number == null){
             break;
         }
         cardsToSpawn[i - 1] = new SCCardInfo(suit, SCNetworkUtil.toInt(number));
     }
     table.playNewCard(cardsToSpawn, new Vector3(0, 40, 0));
 }
 public void onServerDestroyedCommand(SCMessageInfo info)
 {
     gui.client.unInit();
     gui.currentScreen = SCGUI.SCREEN_PLAY_WITH_FRIENDS;
     gui.currentError = new SCErrorInfo("Host has quit the game", 3);
     gui.currentWindow = SCGUI.WINDOW_ERROR;
 }
Example #30
0
 private void onPasswordCommand(SCMessageInfo info)
 {
     string password = info.getValue("value");
     string name = info.getValue("name");
     if(password == null || name == null){
         return;
     }
     localServer.processPassword(password, name, info.fromConnectionId);
 }