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);
 }
예제 #2
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);
     }
 }
예제 #3
0
 private void onUnfreezeClientCommand(SCMessageInfo info)
 {
     SCHand hand = communicator.gameObject.GetComponentInChildren<SCHand>();
     hand.allowInput(info.getValue("reason"));
 }
예제 #4
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));
 }
예제 #5
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();
     }
 }
예제 #6
0
 private void onConnectCommand(SCMessageInfo info)
 {
     string type = info.getValue("type");
     if(type == null){
         return;
     }
     if(type == "successful"){
         SCCommunicator.fireCommand("connected_to_server");
         Debug.Log("SCClient| Successfully connected to server.");
         mFirstTime = false;
     }else if(type == "verify"){
         if(mFirstTime){
             Debug.Log("SCClient| Sending verification to server.");
             communicator.sendMessageToServer("verify:name=" + SCCommunicator.userName);
         }else{
             communicator.sendMessageToServer("reconnecting:unique_id=" + communicator.uniqueId);
         }
     }else if(type == "password"){
         communicator.sendMessageToServer("password:value=" + SCCommunicator.password + ",name=" + SCCommunicator.userName);
     }
 }
예제 #7
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());
    }
예제 #8
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));
 }
예제 #9
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"));
 }
예제 #10
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);
 }
예제 #11
0
 /********************************************************************************************/
 /** Command Fucntions ***********************************************************************/
 /********************************************************************************************/
 private void onLogCommand(SCMessageInfo info)
 {
     Debug.Log("Client: " + info.getValue("message"));
 }
예제 #12
0
 private void onLobbyStatusCommand(SCMessageInfo info)
 {
     string message = "lobby_status:";
     int index = 1;
     while(true){
         string name = info.getValue("name" + index);
         if(name == null){
             SCCommunicator.fireCommand(message);
             return;
         }else{
             message += (index == 1 ? "" : ",") + "name" + index + "=" + name;
         }
         ++index;
     }
 }
예제 #13
0
    private void onErrorCommand(SCMessageInfo info)
    {
        string on = info.getValue("on");
        string extra = info.getValue("extra");
        if(on == null || extra == null){
            return;
        }

        if(on == "reconnecting"){
            if(extra == "game_not_found"){
                SCCommunicator.fireCommand("game_does_not_exist");
                Debug.Log("SCClient| The game I created on master doesn't exist anymore.");
                SCCommunicator.automaticallyReconnect = false;
                communicator.disconnectFrom(info.fromConnectionId);
            }
        }else if(on == "password"){
            if(extra == "wrong"){
                SCCommunicator.fireCommand("entered_wrong_password");
                Debug.Log("SCClient| I entered the wrong password for the server.");
                SCCommunicator.automaticallyReconnect = false;
                communicator.disconnectFrom(info.fromConnectionId);
            }
        }
    }
예제 #14
0
 private void onCurrentTurnCommand(SCMessageInfo info)
 {
     string name = info.getValue("name");
     if(name == null){
         return;
     }
     SCCommunicator.fireCommand("current_turn:name=" + name);
 }
예제 #15
0
    private void onCreateHandCommand(SCMessageInfo info)
    {
        int suffix = 1;
        List<GameObject> cards = new List<GameObject>();
        SCHand hand = communicator.gameObject.GetComponentInChildren<SCHand>();
        SCHand.handWithFocus = hand;
        while(true){
            string suit = info.getValue("suit" + suffix);
            string number = info.getValue("number" + suffix);
            if(suit == null || number == null){
                hand.createHand(cards);
                return;
            }

            GameObject card = hand.createCard(suit, SCNetworkUtil.toInt(number));
            cards.Add(card);

            ++suffix;
        }
    }
예제 #16
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);
     }
 }
 public void onLobbyStatusCommand(SCMessageInfo info)
 {
     mPlayersInLobby.Clear();
     int index = 1;
     while(true){
         string name = info.getValue("name" + index);
         //string status = info.getValue("status" + index);
         if(name == null){
             return;
         }
         mPlayersInLobby.Add(name);
         ++index;
     }
 }
예제 #18
0
 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);
     }
 }
예제 #19
0
 private void onReconnectingCommand(SCMessageInfo info)
 {
     string uniqueId = info.getValue("uniqueId");
     if(uniqueId == null){
         return;
     }
     processReconnection(SCNetworkUtil.toInt(uniqueId), info.fromConnectionId);
 }
예제 #20
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);
    }
예제 #21
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;
        }
    }
예제 #22
0
 private void onAddCardCommand(SCMessageInfo info)
 {
     SCHand hand = communicator.gameObject.GetComponentInChildren<SCHand>();
     hand.addCard(info.getValue("suit"), SCNetworkUtil.toInt(info.getValue("number")));
 }