Exemplo n.º 1
0
    public void NotifyPlayer(GameObject recipient, bool noLerp = false)
    {
        serverState.NoLerp = noLerp;
        var msg = PlayerMoveMessage.Send(recipient, gameObject, serverState);

        Logger.LogTraceFormat("Sent {0}", Category.Movement, msg);
    }
Exemplo n.º 2
0
    void PlayerMove(object sender, MessageReceivedEventArgs e)
    {
        using (Message message = e.GetMessage()) {
            using (DarkRiftReader reader = message.GetReader()) {
                PlayerMoveMessage playerMoveMessage = reader.ReadSerializable <PlayerMoveMessage>();

                networkPlayers[playerMoveMessage.ID].transform.position = playerMoveMessage.position;
            }
        }
    }
        internal void MovePlayer(NetIncomingMessage msg)
        {
            int msgLength = msg.ReadInt32();

            byte[]            msgContents = msg.ReadBytes(msgLength);
            PlayerMoveMessage moveMsg     = (PlayerMoveMessage)SerializationHandler.ByteArrayToObject(msgContents);
            PlayerMove        move        = moveMsg.move; // TODO Do something with this

            gameServer.sendMsgToAll(moveMsg);
        }
Exemplo n.º 4
0
    public static PlayerMoveMessage SendToAll(GameObject subjectPlayer, PlayerState state)
    {
        var msg = new PlayerMoveMessage
        {
            SubjectPlayer = subjectPlayer != null?subjectPlayer.GetComponent <NetworkIdentity>().netId : NetworkInstanceId.Invalid,
            State         = state,
        };

        msg.SendToAll();
        return(msg);
    }
Exemplo n.º 5
0
    public static PlayerMoveMessage Send(NetworkConnection recipient, GameObject subjectPlayer, PlayerState state)
    {
        var msg = new PlayerMoveMessage
        {
            SubjectPlayer = subjectPlayer != null?subjectPlayer.GetComponent <NetworkIdentity>().netId : NetId.Invalid,
            State         = state,
        };

        msg.SendTo(recipient);
        return(msg);
    }
Exemplo n.º 6
0
        internal void MovePlayer(NetIncomingMessage msg)
        {
            int msgLength = msg.ReadInt32();

            byte[]            msgContents = msg.ReadBytes(msgLength);
            PlayerMoveMessage moveMsg     = (PlayerMoveMessage)SerializationHandler.ByteArrayToObject(msgContents);
            PlayerMove        move        = moveMsg.move;

            if (game.GameData.clientsPlayerID != moveMsg.playerID)
            {
                game.GameData.getPlayer(moveMsg.playerID).currentMove = move;
            }
        }
    // TODO: performance.
    // TODO: check if in game, etc.
    public void handlePlayerMoveMessage(string msg)
    {
        if (SceneManager.GetActiveScene().name == "MPLevelTest" ||
            SceneManager.GetActiveScene().name == "MPLevel1" ||
            SceneManager.GetActiveScene().name == "MPLevel2" ||
            SceneManager.GetActiveScene().name == "MPLevel3")
        {
            PlayerMoveMessage m = JsonUtility.FromJson <PlayerMoveMessage>(msg);

            DummyController dummy = GameObject.Find("Dummy(Clone)").GetComponent <DummyController> ();

            dummy.ReceivePosition(m.move, m.position, m.time);
        }
    }
Exemplo n.º 8
0
 public void NotifyPlayers(bool noLerp = false)
 {
     //Generally not sending mid-flight updates (unless there's a sudden change of course etc.)
     if (!serverState.ImportantFlightUpdate && consideredFloatingServer)
     {
         return;
     }
     serverState.NoLerp = noLerp;
     PlayerMoveMessage.SendToAll(gameObject, serverState);
     //Clearing state flags
     serverTargetState.ImportantFlightUpdate = false;
     serverTargetState.ResetClientQueue      = false;
     serverState.ImportantFlightUpdate       = false;
     serverState.ImportantFlightUpdate       = false;
 }
Exemplo n.º 9
0
    public void NotifyPlayers(bool noLerp)
    {
        //Generally not sending mid-flight updates (unless there's a sudden change of course etc.)
        if (!serverState.ImportantFlightUpdate && consideredFloatingServer)
        {
            return;
        }
        serverState.NoLerp = noLerp;
        var msg = PlayerMoveMessage.SendToAll(gameObject, serverState);

//		Logger.LogTraceFormat("SentToAll {0}", Category.Movement, msg);
        //Clearing state flags
        serverState.ImportantFlightUpdate = false;
        serverState.ResetClientQueue      = false;
    }
Exemplo n.º 10
0
        private void NotifyPlayers()
        {
            //Do not cache the position if the player is a ghost
            //or else new players will sync the deadbody with the last pos
            //of the ghost:
            if (!playerMove.isGhost)
            {
                serverStateCache = serverState;
            }
            //Generally not sending mid-flight updates (unless there's a sudden change of course etc.)
            if (!serverState.ImportantFlightUpdate && isFloatingServer)
            {
                return;
            }

            PlayerMoveMessage.SendToAll(gameObject, serverState);
            ClearStateFlags();
        }
Exemplo n.º 11
0
    public void SendPosition(Vector3 move, Vector3 position)
    {
        Vector3 noMovement = new Vector3(0, 0, 0);

        frames++;
        if (frames % 1 == 0 && position != noMovement && move != noMovement)
        {
            ConnectionManager gameConnection = GameObject.Find("Game Connection").GetComponent <ConnectionManager> ();
            if (gameConnection.isConnected())
            {
                PlayerMoveMessage msg = new PlayerMoveMessage();
                msg.move     = move;
                msg.position = position;
                msg.time     = Time.time;

                gameConnection.sendJSON(msg);
            }
        }
    }
Exemplo n.º 12
0
 public static void SendToAll(GameObject subjectPlayer, PlayerState state)
 {
     if (PlayerUtils.IsGhost(subjectPlayer))
     {
         //Send ghost positions only to ghosts
         foreach (var connectedPlayer in PlayerList.Instance.InGamePlayers)
         {
             if (PlayerUtils.IsGhost(connectedPlayer.GameObject))
             {
                 Send(connectedPlayer.GameObject, subjectPlayer, state);
             }
         }
     }
     else
     {
         var msg = new PlayerMoveMessage
         {
             SubjectPlayer = subjectPlayer != null?subjectPlayer.GetComponent <NetworkIdentity>().netId : NetworkInstanceId.Invalid,
             State         = state,
         };
         msg.SendToAll();
     }
 }
Exemplo n.º 13
0
    public void NotifyPlayers(bool noLerp)
    {
        //Generally not sending mid-flight updates (unless there's a sudden change of course etc.)
        if (!serverState.ImportantFlightUpdate && consideredFloatingServer)
        {
            return;
        }

        //hack to make clients accept non-pull-breaking external pushes for stuff they're pulling
        //because they ignore updates for stuff they pull w/prediction
        bool isPullNudge = pushPull &&
                           pushPull.IsBeingPulled &&
                           !serverState.IsFollowUpdate &&
                           serverState.Impulse != Vector2.zero;

        if (isPullNudge)
        {
            //temporarily "break" pull so that puller would get the update
            InformPullMessage.Send(pushPull.PulledBy, this.pushPull, null);
        }

        serverState.NoLerp = noLerp;
        var msg = PlayerMoveMessage.SendToAll(gameObject, serverState);

//		Logger.LogTraceFormat("SentToAll {0}", Category.Movement, msg);
        //Clearing state flags
        serverState.ImportantFlightUpdate = false;
        serverState.ResetClientQueue      = false;

        if (isPullNudge)
        {
            //restore pull for client.
            //previous fake break erases all pull train info from train head, so we make head aware again
            pushPull.InformHead(pushPull.PulledBy);
//			InformPullMessage.Send( pushPull.PulledBy, this.pushPull, pushPull.PulledBy );
        }
    }
Exemplo n.º 14
0
 public void NotifyPlayer(GameObject recipient, bool noLerp = false)
 {
     serverState.NoLerp = noLerp;
     PlayerMoveMessage.Send(recipient, gameObject, serverState);
 }
Exemplo n.º 15
0
 public void NotifyPlayer(GameObject recipient)
 {
     PlayerMoveMessage.Send(recipient, gameObject, serverState);
 }
Exemplo n.º 16
0
    void RecieveMessage(Message msg)
    {
        print("MESSAGE RECIEVED " + msg);
        switch (msg.type)
        {
        case MessageTypes.PlayerJoined:

            print("A NEW CHALLENGER APPROACHES");
            PlayerJoinedMessage pjm = (PlayerJoinedMessage)msg;
            m_playerController.AddPlayer(new PlayerData {
                index = pjm.id, color = pjm.color, icon = (PhoneUserIcon)pjm.icon, name = pjm.name
            });

            if (onPlayerCountChange != null)
            {
                onPlayerCountChange.Invoke(m_playerController.PlayerCount);
            }


            break;

        case MessageTypes.PlayerLeft:

            PlayerLeftMessage plm = (PlayerLeftMessage)msg;
            m_playerController.RemovePlayer(plm.id);

            if (onPlayerCountChange != null)
            {
                onPlayerCountChange.Invoke(m_playerController.PlayerCount);
            }
            SceneManager.LoadScene(0);
            break;

        case MessageTypes.PlayerMove:
            PlayerMoveMessage      pmm    = (PlayerMoveMessage)msg;
            ThirdPersonUserControl player = ThirdPersonUserControl.players[pmm.pid - 1];
            //if(pmm.x != null && pmm.y != null)
            player.setAxis(pmm.x, pmm.y);
            if (pmm.jmp)
            {
                player.jump = pmm.jmp;
            }
            if (pmm.drp)
            {
                player.drop = pmm.drp;
            }
            break;

        case MessageTypes.PlayerAction:
            PlayerActionMessage pam = (PlayerActionMessage)msg;
            print(pam + " sad");
            if (pam.jump)
            {
                ThirdPersonUserControl.players[pam.pid - 1].jump = true;
            }
            else
            {
                ThirdPersonUserControl.players[pam.pid - 1].drop = true;
            }
            break;
        }
    }