Example #1
0
    public void StartNewRTSession(string host, int port, string accessToken, Action <bool> onResponse)
    {
        if (_isStartingSession)
        {
            if (onResponse != null)
            {
                onResponse(false);
            }
            return;
        }
        _isStartingSession = true;
        _onResponse        = onResponse;
        GSRequestData mockedResponse = new GSRequestData()
                                       .AddNumber("port", (double)port)
                                       .AddString("host", host)
                                       .AddString("accessToken", accessToken);
        FindMatchResponse response = new FindMatchResponse(mockedResponse);

        _RT.Configure(response,
                      (peerId) => { OnPlayerConnectedToGame(peerId); },
                      (peerId) => { OnPlayerDisconnectedFromGame(peerId); },
                      (ready) => { OnRTReady(ready); },
                      (packet) => { OnPacketReceived(packet); });
        _RT.Connect();
        _sentCommands.Clear();
        _lastReceivedMessageIds.Clear();
    }
        /// <summary>
        /// Initializes and starts a new real time session for users
        /// </summary>
        /// <param name="_info">The session information for this game</param>
        public void StartNewRTSession(RTSessionInfo _info)
        {
            Debug.Log("GSM| Creating new RT Session instance...");
            m_SessionInfo       = _info;
            m_GameSparksRTUnity = this.gameObject.AddComponent <GameSparksRTUnity>(); //Adds the RT script to the game
            //In order to create a new RT game we need a 'FindMatchResponse'
            //This would usually come from the server directly after a successful MatchmakingRequest
            //However, in our case, we want the game to be create only when all the players ready up
            //Therefore, the details from the response is passed in from the gameInfo and a mock-up of a FindMatchReponse is passed in
            GSRequestData mockedReponse = new GSRequestData()
                                          .AddNumber("port", (double)_info.GetPortID())
                                          .AddString("host", _info.GetHostURL())
                                          .AddString("accessToken", _info.GetAccessToken()); //Construct a dataset from the game-details

            FindMatchResponse response = new FindMatchResponse(mockedReponse);               //Create a match-response from that data and pass it into the game-configuration

            //So in the game-configuration method we pass in the response which gives the Instance its connection settings
            //In this example, a lambda expression is used to pass in actions for
            //OnPlayerConnect, OnPlayerDisconnect, OnReady, and OnPacket
            //The methods do exactly what they are named. For example, OnPacket gets called when a packet is received

            m_GameSparksRTUnity.Configure(response,
                                          (peerId) => { OnPlayerConnectedToGame(peerId); },
                                          (peerId) => { OnPlayerDisconnected(peerId); },
                                          (ready) => { OnRTReady(ready); },
                                          (packet) => { OnPacketReceived(packet); });
            m_GameSparksRTUnity.Connect(); //When the configuration is set, connect the game
        }
Example #3
0
        public void StartNewRTSession(RTSessionInfo _info)
        {
            Debug.Log("GSM| Creating New RT Session Instance...");
            sessionInfo       = _info;
            gameSparksRTUnity = this.gameObject.AddComponent <GameSparksRTUnity>(); // Adds the RT script to the game
                                                                                    // In order to create a new RT game we need a 'FindMatchResponse' //
                                                                                    // This would usually come from the server directly after a successful MatchmakingRequest //
                                                                                    // However, in our case, we want the game to be created only when the first player decides using a button //
                                                                                    // therefore, the details from the response is passed in from the gameInfo and a mock-up of a FindMatchResponse //
                                                                                    // is passed in. //
            GSRequestData mockedResponse = new GSRequestData()
                                           .AddNumber("port", (double)_info.GetPortID())
                                           .AddString("host", _info.GetHostURL())
                                           .AddString("accessToken", _info.GetAccessToken()); // construct a dataset from the game-details

            FindMatchResponse response = new FindMatchResponse(mockedResponse);               // create a match-response from that data and pass it into the game-config

            // So in the game-config method we pass in the response which gives the instance its connection settings //
            // In this example, I use a lambda expression to pass in actions for
            // OnPlayerConnect, OnPlayerDisconnect, OnReady and OnPacket actions //
            // These methods are self-explanatory, but the important one is the OnPacket Method //
            // this gets called when a packet is received //

            gameSparksRTUnity.Configure(response,
                                        (peerId) => { OnPlayerConnectedToGame(peerId); },
                                        (peerId) => { OnPlayerDisconnected(peerId); },
                                        (ready) => { OnRTReady(ready); },
                                        (packet) => { OnPacketReceived(packet); });
            gameSparksRTUnity.Connect(); // when the config is set, connect the game
        }
        //Starts the game session
        public void StartNewRTSession(RTSessionInfo _info)
        {
            //if the settings arent null
            if (gameSparksRTUnity == null)
            {
                Debug.Log("GSM| Creating New RT Session Instance...");
                sessionInfo       = _info;                                              //player/session information
                gameSparksRTUnity = this.gameObject.AddComponent <GameSparksRTUnity>(); //add the RT script to the manager
                GSRequestData mockedResponse = new GSRequestData();                     //create a new request
                mockedResponse.AddNumber("port", (double)_info.GetPortID());            //gets the port id
                mockedResponse.AddString("host", _info.GetHostURL());                   //gets host server
                mockedResponse.AddString("accessToken", _info.GetAccessToken());        // construct a dataset from the game-details
                FindMatchResponse response = new FindMatchResponse(mockedResponse);     //create a mock response for match

                //configures the game
                gameSparksRTUnity.Configure(response,
                                            (peerId) => { OnPlayerConnectedToGame(peerId); },
                                            (peerId) => { OnPlayerDisconnected(peerId); },
                                            (ready) => { OnRTReady(ready); },
                                            (packet) => { OnPacketReceived(packet); });
                gameSparksRTUnity.Connect(); // when the config is set, connect the game
            }
            else
            {
                Debug.LogError("Session Already Started");
            }
        }
Example #5
0
    private void StartNewSession(RTSessionInfo sessionInfo, MatchFoundMessage resp)
    {
        Debug.Log("GSM| Creating New RT Session Instance...");

        RtGS = gameObject.AddComponent <GameSparksRTUnity>();

        RtGS.Configure(resp,
                       (peerId) => { OnPlayerConnectedToGame(peerId); },
                       (peerId) => { OnPlayerDisconnected(peerId); },
                       (ready) => { OnRTReady(ready); },
                       (packet) => { OnPacketReceived(packet); }
                       );
        RtGS.Connect();
    }
 public void createSession()
 {
     if (RTClass == null)
     {
         RTClass = gameObject.AddComponent <GameSparksRTUnity>();
     }
     RTClass.Configure(host, port, accessToken, OnPacket: pack => packetReceived(pack),
                       OnPlayerConnect: pack => playerConnected(pack),
                       OnPlayerDisconnect: pack => playerDisconnected(pack),
                       OnReady: pack => playersReady(pack));
     RTClass.Connect();
     connectedToSession = true;
     fighterScript.StartCoroutine(fighterScript.positionSendToPacket());
 }
Example #7
0
    /// <summary>
    /// Starts the match.
    /// </summary>
    /// <param name="message">Message.</param>
    public void StartMatch(MatchFoundMessage message)
    {
        sparkMatch = new SparkMatch(message);

        foreach (MatchFoundMessage._Participant participant in message.Participants)
        {
            SparkPeer peer = new SparkPeer(participant.DisplayName, participant.Id, participant.PeerId.Value);

            sparkMatch.peerList.Add(peer);
        }

        sparkNetwork.Configure(message,
                               OnPlayerConnect,
                               OnPlayerDisconnect,
                               OnReady,
                               OnPacket
                               );

        sparkNetwork.Connect();
    }
Example #8
0
    public void StartNewRTSession(RTSessionInfo _info)
    {
        Debug.Log("GSM| Creating New RT Session Instance...");
        sessionInfo       = _info;
        gameSparksRTUnity = this.gameObject.AddComponent <GameSparksRTUnity>();

        GSRequestData mockedResponse = new GSRequestData()
                                       .AddNumber("port", (double)_info.GetPortID())
                                       .AddString("host", _info.GetHostURL())
                                       .AddString("accessToken", _info.GetAccessToken());

        FindMatchResponse response = new FindMatchResponse(mockedResponse);

        gameSparksRTUnity.Configure(response,
                                    (peerId) => { OnPlayerConnectedToGame(peerId); },
                                    (peerId) => { OnPlayerDisconnected(peerId); },
                                    (ready) => { OnRTReady(ready); },
                                    (packet) => { OnPacketReceived(packet); });
        gameSparksRTUnity.Connect();
    }
Example #9
0
    public void StartNewRealTimeSession(RTSessionInfo sessionInfo)
    {
        m_rtSessionInfo   = sessionInfo;
        gameSparksRTUnity = gameObject.AddComponent <GameSparksRTUnity>();

        GSRequestData mockedResponse = new GSRequestData()
                                       .AddNumber("port", (double)sessionInfo.GetPortId())
                                       .AddString("host", sessionInfo.GetHostUrl())
                                       .AddString("accessToken", sessionInfo.GetAccessToken());

        FindMatchResponse response = new FindMatchResponse(mockedResponse);


        gameSparksRTUnity.Configure(response,
                                    OnPlayerConnect,
                                    OnPlayerDisconnect,
                                    OnReady,
                                    OnPacket);

        gameSparksRTUnity.Connect();
    }
Example #10
0
    private void OnMatchFound(GameSparks.Api.Messages.MatchFoundMessage _message)
    {
        Debug.Log("Match Found!...");

        curr_text.text = "Match Found!...";

        curr_text.alignment = TextAnchor.MiddleCenter;

        searching_ball.gameObject.SetActive(false);

        GameManager       game_manager = GameObject.FindGameObjectWithTag("GameManager").GetComponent <GameManager>();
        GameSparksRTUnity RT_manager   = game_manager.GetGameSparksRTManager();
        NetworkManager    net_manager  = game_manager.GetNetworkManager();

        net_manager.match = new MatchInfo(_message);

        RT_manager.Configure(_message,
                             (peerID) => { net_manager.OnPlayerConnectedToGame(peerID); },
                             (peerID) => { net_manager.OnPlayerDisconnected(peerID); },
                             (ready) => { net_manager.OnRTReady(ready); },
                             (packet) => { net_manager.OnPacketReceived(packet); });
        RT_manager.Connect();



        //Uncoment that to Debug the Match info

        /*Debug.Log("Match Found...");
         * Debug.Log("Host URL:" + _message.Host);
         * Debug.Log("Port:" + _message.Port);
         * Debug.Log("Access Token:" + _message.AccessToken);
         * Debug.Log("MatchId:" + _message.MatchId);
         * Debug.Log("Opponents:" + _message.Participants.Count());
         * Debug.Log("_________________");
         *
         * foreach (GameSparks.Api.Messages.MatchFoundMessage._Participant player in _message.Participants)
         * {
         *  Debug.Log("Player:" + player.PeerId + " User Name:" + player.DisplayName); // add the player number and the display name to the list
         * }*/
    }