Exemplo n.º 1
0
    public override void OnWeaponUpdate(RTPacket packet, int code)
    {
        base.OnWeaponUpdate(packet, code);

        switch ((OpCode)code)
        {
        case OpCode.Fire:
            Fire();
            break;

        case OpCode.Reload:
            StartReload();
            break;

        case OpCode.Ads:
            Ads();
            break;

        case OpCode.StopAds:
            StopAds();
            break;

        default:
            Debug.LogError("Gun::OnWeaponUpdate - Unknown update code " + packet.Data.GetInt(1).Value);
            break;
        }
    }
Exemplo n.º 2
0
 void PacketReceived(RTPacket packet)
 {
     if (packet.OpCode == MultiplayerCodes.START_GAME.Int())
     {
         StartGame();
     }
 }
    private void OnPacketReceived(RTPacket _packet)
    {
        Debug.Log("GSM| Packet received from " + _packet.Sender + " for OpCode " + _packet.OpCode);

        switch (_packet.OpCode)
        {
        // Op-code 1 refers to
        case 1:
            break;

        // Op-code 2 refers to
        case 2:
            GameManager.Instance().UpdateOpponentCameraMovement(_packet);
            break;

        // Op-code 3 refers to
        case 3:
            GameManager.Instance().UpdateOpponentAbility(_packet);
            break;

        case 4:
            GameManager.Instance().UpdateOpponentShield(_packet);
            break;

        case 5:
            GameManager.Instance().UpdateOpponentSpectatorMode(_packet);
            break;

        case 6:
            GameManager.Instance().UpdateOpponentProjectile(_packet);
            break;
        }
    }
Exemplo n.º 4
0
 public void AllClientsFinishedResolvingCloudAnchor(RTPacket _packet)
 {
     if (ASLHelper.m_ASLObjects.TryGetValue(_packet.Data.GetString((int)DataCode.Id) ?? string.Empty, out ASLObject myObject))
     {
         myObject._LocallySetCloudAnchorResolved(true);
     }
 }
Exemplo n.º 5
0
 private void UpdatePlayerHealth(RTPacket packet)
 {
     CheckPeers(packet, (index) =>
     {
         m_playerHealth[index].HP = packet.Data.GetFloat(1).Value;
     });
 }
Exemplo n.º 6
0
    public void SetPlayersInfo(RTPacket _packet)
    {
        Debug.Log(net_manager.match);

        for (int p = 0; p < net_manager.match.GetPlayerList().Count; p++)
        {
            if (net_manager.match.GetPlayerList()[p].id == _packet.Data.GetString(1))
            {
                if (net_manager.match.GetPlayerList()[p].id == game_manager.playerID)
                {
                    player.text = net_manager.match.GetPlayerList()[p].displayName;
                }
                else
                {
                    switch (opponent_count)
                    {
                    case 0:
                        opp1.text = net_manager.match.GetPlayerList()[p].displayName;
                        break;

                    case 1:
                        opp2.text = net_manager.match.GetPlayerList()[p].displayName;
                        break;

                    case 2:
                        opp3.text = net_manager.match.GetPlayerList()[p].displayName;
                        break;
                    }
                    opponent_count++;
                }
                SpawnPlayer(_packet, _packet.Data.GetString(1));
            }
        }
    }
Exemplo n.º 7
0
    public void SyncClock(RTPacket rtPacket)
    {
        long serverUnixTime         = rtPacket.Data.GetLong(1).Value;
        long millisecondsToFixClock = serverUnixTime + timeDelta;

        ServerClock = DateTime.UtcNow.AddMilliseconds(millisecondsToFixClock);
    }
Exemplo n.º 8
0
    public void OnPacketReceived(RTPacket _packet)
    {
        string text = _packet.Data.GetString(5); // get string at key 5

        Debug.Log("\nPackage Received:" + _packet + "\n");
        m_pText.text += "\nPackage Received:" + _packet + "\n";
    }
Exemplo n.º 9
0
    private void PacketReceived(RTPacket packet)
    {
        switch (packet.OpCode)
        {
        case (int)MultiplayerCodes.GAME_POINTS:
            UpdatePoints(packet);
            break;

        case (int)MultiplayerCodes.PLAYER_POSITION:
            UpdatePlayers(packet);
            break;

        case (int)MultiplayerCodes.PLAYER_BULLETS:
            UpdatePlayerBullets(packet);
            break;

        case (int)MultiplayerCodes.PLAYER_HEALTH:
            UpdatePlayerHealth(packet);
            break;

        case (int)MultiplayerCodes.ENEMY_SPAWN:
            UpdateEnemiesSpawn(packet);
            break;
        }
    }
Exemplo n.º 10
0
 private void UpdatePlayerBullets(RTPacket packet)
 {
     CheckPeers(packet, (index) =>
     {
         m_turrets[index].Fire();
     });
 }
Exemplo n.º 11
0
    public void packetReceived(RTPacket pack)
    {
        GameObject enemyToChange;

        players.TryGetValue(pack.Sender, out enemyToChange);

        if (pack.OpCode == 100)
        {
            if (enemyToChange != null)
            {
                //Movement code
                if (!pausePackets[pack.Sender])
                {
                    enemyToChange.transform.DOMove((Vector2)pack.Data.GetVector2(1), Time.deltaTime * 10).SetEase(Ease.Linear);
                }

                //Animation code
                if (!string.Equals(pack.Data.GetString(2), "null"))
                {
                    if (!specialRunning)
                    {
                        enemyToChange.GetComponent <Animator>().Play(pack.Data.GetString(2), 0);
                    }

                    if (pack.Data.GetString(2) == "Enemy_special1")
                    {
                        specialRunning = true;
                    }
                }

                //Sprite flip code
                if (pack.Data.GetInt(3) == 0)
                {
                    if (enemyToChange.GetComponent <SpriteRenderer>().flipX)
                    {
                        enemyToChange.GetComponent <SpriteRenderer>().flipX = false;
                    }
                }
                else if (pack.Data.GetInt(3) == 1)
                {
                    if (!enemyToChange.GetComponent <SpriteRenderer>().flipX)
                    {
                        enemyToChange.GetComponent <SpriteRenderer>().flipX = true;
                    }
                }
            }
            else
            {
                print("Error: No enemy to change");
            }
        }
        else if (pack.OpCode == 110)
        {
            enemyToChange.GetComponent <Enemy>().createHitEffect((Vector2)pack.Data.GetVector2(4));
            var hurtType = pack.Data.GetString(1);
            var dir      = (Vector2)pack.Data.GetVector2(2);
            var damage   = pack.Data.GetFloat(3);
            fighterScript.receiveAttack(Char.Parse(hurtType), dir, (float)damage);
        }
    }
Exemplo n.º 12
0
    private void OnPacketReceived(RTPacket packet)
    {
        if (packet.OpCode == 1)
        {
            SlimeType slime_type;

            int?type = packet.Data.GetInt(3);

            if (type != null)
            {
                slime_type = (SlimeType)type;
            }
            else
            {
                slime_type = SlimeType.NONE;
            }

            int i = (int)packet.Data.GetInt(1);
            int j = (int)packet.Data.GetInt(2);

            Game.Instance.HandleInput(slime_type, i, j);
        }
        else if (packet.OpCode == 2)
        {
            Game.Instance.PassTurn();
        }
    }
Exemplo n.º 13
0
        /// <summary>
        /// Releases an object so another user can claim it. This function will also call this object's release function if it exists.
        /// This function is triggered by a packet received from the relay server.
        /// </summary>
        /// <param name="_packet">The packet containing the id of the object that another player wants to claim</param>
        public void ReleaseClaimedObject(RTPacket _packet)
        {
            if (ASLHelper.m_ASLObjects.TryGetValue(_packet.Data.GetString((int)DataCode.Id) ?? string.Empty, out ASLObject myObject))
            {
                if (GameSparksManager.m_PlayerIds.TryGetValue(_packet.Data.GetString((int)DataCode.OldPlayer), out bool currentOwner))
                {
                    if (currentOwner) //If this client is the current owner
                    {
                        //Send a packet to new owner informing them that the previous owner (this client) no longer owns the object
                        //So they can do whatever they want with it now.
                        using (RTData data = RTData.Get())
                        {
                            data.SetString((int)DataCode.Id, myObject.m_Id);
                            data.SetString((int)DataCode.Player, _packet.Data.GetString((int)DataCode.Player));
                            GameSparksManager.Instance().GetRTSession().SendData((int)GameSparksManager.OpCode.ClaimFromPlayer,
                                                                                 GameSparksRT.DeliveryIntent.RELIABLE, data, (int)_packet.Data.GetInt((int)DataCode.PlayerPeerId));
                        }
                        myObject.m_ReleaseFunction?.Invoke(myObject.gameObject); //If user wants to do something before object is released - let them do so
                        myObject._LocallyRemoveReleaseCallback();

                        myObject._LocallySetClaim(false);
                        myObject._LocallyRemoveClaimCallbacks();
                    }
                }
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Loads a new scene for all players. This function is triggered by a packet received from the relay server.
        /// </summary>
        /// <param name="_packet">The packet containing the name of the new scene to be loaded</param>
        public void LoadScene(RTPacket _packet)
        {
            if (_packet.OpCode == (int)GameSparksManager.OpCode.LoadStartScene) //If loading starting scene
            {
                //Pick the next scene to load depending on how this game was launched
                if (QuickConnect.m_StaticStartingScene != string.Empty)
                {
                    ASLSceneLoader.m_SceneToLoad = QuickConnect.m_StaticStartingScene;
                }
                else
                {
                    ASLSceneLoader.m_SceneToLoad = LobbyManager.m_StaticStartingScene;
                }

                Debug.Log("Scene: " + ASLSceneLoader.m_SceneToLoad);

                SceneManager.LoadScene("ASL_SceneLoader");
                LobbyManager.m_GameStarted = true;
            }
            else if (_packet.OpCode == (int)GameSparksManager.OpCode.LoadScene) //If loading any scene after starting scene
            {
                ASLSceneLoader.m_SceneToLoad = _packet.Data.GetString((int)DataCode.SceneName);
                SceneManager.LoadScene("ASL_SceneLoader");
            }
            else //Scene is ready to launch - inform user they can now activate the scene
            {
                ASLSceneLoader.m_AllPlayersLoaded = true;
            }
        }
Exemplo n.º 15
0
 /// <summary>
 /// Updates the local scale of an ASL Object based upon its ID. This function is triggered by a packet received from the relay server.
 /// </summary>
 /// <param name="_packet">The packet from the relay server containing the ID of what ASL Object to modified
 /// and the Vector3 of the object's new scale</param>
 public void SetLocalScale(RTPacket _packet)
 {
     if (ASLHelper.m_ASLObjects.TryGetValue(_packet.Data.GetString((int)DataCode.Id) ?? string.Empty, out ASLObject myObject))
     {
         myObject.transform.localScale = ((Vector3)_packet.Data.GetVector3((int)DataCode.Scale));
     }
 }
Exemplo n.º 16
0
 /// <summary>
 /// Updates the Anchor Point of an ASL Object based upon its ID. The anchor point is used for AR applications.
 /// This function is triggered by a packet received from the relay server.
 /// </summary>
 /// <param name="_packet">The packet from the relay server containing the ID of what ASL Object to modified
 /// and the object's new Anchor Point information</param>
 public void SetAnchorID(RTPacket _packet)
 {
     if (ASLHelper.m_ASLObjects.TryGetValue(_packet.Data.GetString((int)DataCode.Id) ?? string.Empty, out ASLObject myObject))
     {
         myObject._LocallySetAnchorID(_packet.Data.GetString((int)DataCode.AnchorID));
     }
 }
Exemplo n.º 17
0
    private void OnPacketReceived(RTPacket _packet)
    {
        //Debug.Log("Received RT packet, opCode = " + _packet.OpCode);

        /*int messageId = _packet.OpCode / MaxCommandId;
         * int command = messageId % MaxCommandId;
         * //		Debug.LogFormat ("received command {0} with messageid {1}", commandId, messageId);
         *
         * if (command != 0) {
         *      //			Debug.Log ("sending command confirmer with messageid " + messageId.ToString());
         *      SendDataUnreliableTry(new SentCommand(0, new RTData(), messageId)); // Send command confirmer.
         * }
         *
         * if (_lastReceivedMessageIds.Contains (messageId)) {
         *      //			Debug.Log ("ignored as duplicate");
         *      return; // Ignore duplicate.
         * }
         * //if (commandId == (int)MultiplayerCommand.StartLightAttack)
         * //	Debug.Log("hi2");
         * _lastReceivedMessageIds.Add(messageId);
         * if (_lastReceivedMessageIds.Count > MaxLastMessageIds)
         *      _lastReceivedMessageIds.RemoveAt (0);
         * if (command == 0) {
         *      //			Debug.Log ("stopped sending command with messageid " + messageId.ToString());
         *      _sentCommands.Remove (messageId); // Command receiving confirmed. Dont resent this command.
         *      return; // Ignore command confirmer.
         * }*/

        OnReliableDataReceived(_packet.OpCode, _packet.Data);
    }
Exemplo n.º 18
0
        public static void OnNetworkInstantiate(RTPacket packet)
        {
            int     prefabIndex = packet.Data.GetInt(1).Value;
            int     owner       = packet.Data.GetInt(2).Value;
            string  objectId    = packet.Data.GetString(3);
            Vector3 position    = packet.Data.GetVector3(4).Value;
            Vector3 rotation    = packet.Data.GetVector3(5).Value;

            // Get the prefab
            GameObject prefab = NetworkPrefabs.instance.prefabs[prefabIndex];

            if (prefab != null)
            {
                // Copy
                Transform copy = UnityEngine.Object.Instantiate(prefab).transform;

                copy.name += " (" + objectId + ")";

                copy.position = position;
                copy.rotation = Quaternion.Euler(rotation);

                // Get all the NetworkObjects and set the ids
                NetworkObject[] nos = copy.GetComponentsInChildren <NetworkObject>();
                for (uint i = 0; i < nos.Length; i++)
                {
                    nos[i].SetOwner(owner);
                    nos[i].SetId(objectId + "-" + i);
                }
            }
        }
Exemplo n.º 19
0
        private void OnPacketReceived(RTPacket packet)
        {
            switch (packet.OpCode)
            {
            case STARTING_NUMBERS_CODE:
                Debug.Log($"Got starting numbers: {packet.Data.GetString(1)}");
                Enumerable.Range(0, 3).ToList()
                .ForEach(i => StateManager.Dispatch(new CardStartAction {
                    CardIndex = i, StartingNumbers = packet.Data.GetString((uint)i + 1).Split(',').Select(int.Parse).ToList()
                }));
                break;

            case NUMBER_CALLED_CODE:
                Debug.Log($"Got numbers: {packet.Data.GetString(1)}");
                List <int> numbersCalled = packet.Data.GetString(1).Split(',').Select(int.Parse).ToList();
                StartCoroutine(PlayPopAsync(numbersCalled[numbersCalled.Count - 1]));
                StateManager.Dispatch(new CalledNumbersUpdateAction {
                    CalledNumbers = numbersCalled
                });
                break;

            case PLAYER_ID_CODE:
                Debug.Log($"I am player: {packet.Data.GetString(1)}");
                break;

            case END_GAME_CODE:
                ExitBingoGame(3f);
                break;
            }
            //Debug.Log(packet.OpCode + "-" + packet.Data.ToString());
        }
Exemplo n.º 20
0
    public void CardUseRecieved(RTPacket _packet)
    {
        Debug.Log("recivi el packete wey");

        string card_name = _packet.Data.GetString(1);
        int    pos_x     = (int)_packet.Data.GetInt(2);
        int    pos_y     = (int)_packet.Data.GetInt(3);
        string id        = _packet.Data.GetString(4);
        string target_id = _packet.Data.GetString(5);

        GameObject player        = null;
        Player     player_script = null;

        GameObject target = null;
        Player     target_player_script = null;

        player = GetPlayerById(id);
        target = GetPlayerById(target_id);

        if (player != null)
        {
            player_script = player.GetComponent <Player>();
        }

        if (target != null)
        {
            target_player_script = target.GetComponent <Player>();
        }

        Player.Card card = new Player.Card(card_name, player_script);
        card.SetTarget(target_player_script);

        cards_to_attack.Add(card);
    }
Exemplo n.º 21
0
 /// <summary>
 /// Destroys the pending match this player is in so that more players cannot join this match. This prevents late comers or reconnectors from joining this match
 /// </summary>
 /// <param name="_packet">Empty packet from the relay server indicating that it is safe to destroy the pending match this player is a part of.</param>
 public void DestroyPendingMatch(RTPacket _packet)
 {
     new LogEventRequest().SetEventKey("Disconnect").
     SetEventAttribute("MatchShortCode", GameSparksManager.Instance().GetMatchShortCode()).
     SetEventAttribute("MatchGroup", GameSparksManager.Instance().GetMyMatchGroup())
     .Send((_disconnectResponse) => {});
 }
Exemplo n.º 22
0
 private void OnRTPacket(RTPacket packet)
 {
     if (packet.OpCode == 1)
     {
         chatManager.OnMessageReceived(packet);
     }
 }
Exemplo n.º 23
0
 private void OnPacketReceive(RTPacket packet)
 {
     if (OnPacketReceived != null)
     {
         OnPacketReceived(packet);
     }
 }
Exemplo n.º 24
0
        private void OnPacketReceived(RTPacket rtPacket)
        {
            if (GameController.Instance() != null)
            {
                GameController.Instance().PacketReceived(rtPacket.PacketSize);
                GameController.Instance().Match = SupportClasses.MatchType.MultiPlayer;
                Debug.Log("GameController Match ---- " + GameController.Instance().Match);
            }
            else
            {
                Debug.Log("GameController is Null");
                return;
            }

            switch (rtPacket.OpCode)
            {
            case 1:
                GameController.Instance().UpdateOpponentUnit(rtPacket);
                Debug.Log("UpdateOpponentUnit");
                break;

            case 2:
                GameController.Instance().SetMap(rtPacket);
                //Debug.Log("UpdateOpponentUnit");
                break;

            case 100:
                //SceneManager.LoadScene("GamePlay");
                break;
            }
        }
Exemplo n.º 25
0
 /// <summary>
 /// Updates the local transform of an ASL Object based upon its ID by taking the value passed and adding it to the current localPosition value.
 /// This function is triggered by a packet received from the relay server.
 /// </summary>
 /// <param name="_packet">The packet from the relay server containing the ID of what ASL Object to modified
 /// and the Vector3 of the object's new position</param>
 public void IncrementLocalPosition(RTPacket _packet)
 {
     if (ASLHelper.m_ASLObjects.TryGetValue(_packet.Data.GetString((int)DataCode.Id) ?? string.Empty, out ASLObject myObject))
     {
         myObject.transform.localPosition += (Vector3)_packet.Data.GetVector3((int)DataCode.Position);
     }
 }
Exemplo n.º 26
0
        protected override void RetrieveDataAsync()
        {
            RTPacket packet = connection.Protocol.GetRTPacket();

            cameras = packet.Get2DMarkerData();

            if (cameras != null)
            {
                for (int i = 0; i < cameras.Count; i++)
                {
                    int id = i + 1;
                    if (CameraManager.Cameras.ContainsKey(id))
                    {
                        Camera       camera       = cameras[i];
                        CameraScreen cameraScreen = CameraManager.Cameras[id]?.Screen;

                        // NOTE: There is a chance that the packet does not contain data for the currently selected
                        // camera if that is the case simply catch the exception and log it then keep streaming as usual.
                        try
                        {
                            if (cameraScreen != null)
                            {
                                Urho.Application.InvokeOnMain(() => cameraScreen.MarkerData = camera);
                            }
                        }
                        catch (Exception e)
                        {
                            Debug.WriteLine("MarkerStream:" + e.Message);
                            Debugger.Break();
                        }
                    }
                }
            }
        }
Exemplo n.º 27
0
    public void OnPacket(string packet)
    {
        if (!ignoreEvent && m_OnPacket != null)
        {
            packet = DecodeFromUtf8(packet);

            JsonObject            o             = (JsonObject)SimpleJson2.SimpleJson2.DeserializeObject(packet);
            int                   opCode        = Convert.ToInt32(o ["opCode"]);
            int                   sender        = Convert.ToInt32(o ["sender"]);
            int                   limit         = Convert.ToInt32(o ["streamLength"]);
            int                   packetSize    = Convert.ToInt32(o ["packetSize"]);
            JsonObject            data          = (JsonObject)o ["data"];
            RTData                data2         = DeserializeData(data);
            JsonObject            stream        = (JsonObject)o ["stream"];
            LimitedPositionStream limitedStream = null;

            if (stream != null)
            {
                limitedStream = new LimitedPositionStream(Encoding.UTF8.GetBytes((string)((JsonObject)stream ["stream"]) ["buffer"]),
                                                          Convert.ToInt32(stream ["limit"]));
            }

            RTPacket packet2 = new RTPacket(opCode, sender, limitedStream, limit, data2, packetSize);

            m_OnPacket(packet2);
        }
    }
Exemplo n.º 28
0
    private void UpdatePlayers(RTPacket packet)
    {
        CheckPeers(packet, (index) =>
        {
            Transform playerTransform   = m_players[index].transform;
            Rigidbody2D playerRigidBody = m_players[index].GetComponent <Rigidbody2D>();
            Quaternion playerRot        = playerTransform.rotation;
            Vector3 playerAngles        = playerRot.eulerAngles;

            // Referenced from PlayerController.SendTransformUpdates()
            Vector3 newPos = packet.Data.GetVector3(1).Value;
            Signs sign     = (Signs)packet.Data.GetInt(2);
            newPos         = SignsExt.Vector3Sign(newPos, sign);

            float newRot   = packet.Data.GetFloat(3).Value;
            Vector2 newVel = packet.Data.GetVector2(4).Value;
            newVel         = SignsExt.Vector2Sign(newVel, (Signs)packet.Data.GetInt(5));

            playerTransform.position = newPos;
            playerRigidBody.velocity = newVel;
            playerAngles.z           = newRot;
            playerRot.eulerAngles    = playerAngles;

            playerTransform.rotation = playerRot;
        });
    }
Exemplo n.º 29
0
 public void OnPacket(RTPacket packet)
 {
     if (m_OnPacket != null)
     {
         m_OnPacket(packet);
     }
 }
Exemplo n.º 30
0
 public void OnWeaponUpdate(RTPacket packet, int code)
 {
     if (weapon != null)
     {
         weapon.OnWeaponUpdate(packet, code);
     }
 }
Exemplo n.º 31
0
 public void OnPacket(RTPacket packet)
 {
     if(m_OnPacket != null) {
         m_OnPacket(packet);
     }
 }