Пример #1
0
        static void HandleStaticRpc(NetIncomingMessage msg)
        {
            var rpcId = msg.ReadByte();

            var player      = GetPlayer(msg.SenderConnection);
            var currentRoom = player.CurrentRoom;

            if (currentRoom != null)
            {
                var info = new NetMessageInfo(RPCMode.None, player);
                currentRoom.CallRPC(rpcId, msg, info);

                if (info.continueForwarding)
                {
                    var newMessage = peer.CreateMessage();
                    msg.Clone(newMessage);
                    if (msg.DeliveryMethod == NetDeliveryMethod.ReliableOrdered)
                    {
                        currentRoom.SendMessage(newMessage, true);
                    }
                    else
                    {
                        currentRoom.SendMessage(newMessage, false);
                    }
                }
            }
            else
            {
                Debug.LogWarning("[PNetS.Consume] Player {0} attempted static rpc {1}, but they are not in a room to do so",
                                 player, rpcId);
                (player).InternalErrorCount++;
            }
        }
Пример #2
0
        internal void CallRPC(byte rpcID, NetIncomingMessage message, NetMessageInfo info)
        {
            RPCProcessor processor;
            if (_rpcProcessors.TryGetValue(rpcID, out processor))
            {
                info.continueForwarding = processor.DefaultContinueForwarding;

                if (processor.Method != null)
                    processor.Method(message, info);
                else
                {
                    Debug.LogWarning("RPC processor for {0} was null. Automatically cleaning up. Please be sure to clean up after yourself in the future.", rpcID);
                    _rpcProcessors.Remove(rpcID);
                }
            }
            else
            {
                Debug.LogWarning("NetworkedSceneView {1} received unhandled RPC {0}", rpcID, NetworkID);
                info.continueForwarding = false;
            }
        }
Пример #3
0
        internal void CallRPC(byte rpcID, NetIncomingMessage message, NetMessageInfo info)
        {
            RPCProcessor processor;

            if (_rpcProcessors.TryGetValue(rpcID, out processor))
            {
                info.continueForwarding = processor.DefaultContinueForwarding;
                if (processor.Method != null)
                {
                    processor.Method(message, info);
                }
                else
                {
                    //Debug.LogWarning("RPC processor for {0} was null. Automatically cleaning up. Please be sure to clean up after yourself in the future.", rpcID);
                    _rpcProcessors.Remove(rpcID);
                }
            }
            else
            {
                Debug.LogWarning("Networkview on {1}: unhandled RPC {0}", rpcID, gameObject.Name);
                info.continueForwarding = false;
            }
        }
Пример #4
0
        private static void Consume(NetIncomingMessage msg)
        {
            try
            {
                //faster than switch, as this is in most to least common order
                if (msg.SequenceChannel == Channels.UNRELIABLE_STREAM)
                {
                    var actorId = msg.ReadUInt16();
                    NetworkView find;
                    if (NetworkView.Find(actorId, out find))
                    {
                        Player player = GetPlayer(msg.SenderConnection);
                        find.OnDeserializeStream(msg, player);
                    }
                }
                else if (msg.SequenceChannel == Channels.RELIABLE_STREAM)
                {
                    var actorId = msg.ReadUInt16();
                    NetworkView find;
                    if (NetworkView.Find(actorId, out find))
                    {
                        Player player = GetPlayer(msg.SenderConnection);
                        find.OnDeserializeStream(msg, player);
                    }
                }
                else if (msg.SequenceChannel >= Channels.BEGIN_RPCMODES && msg.SequenceChannel <= Channels.OWNER_RPC)
                {
                    //rpc...
                    var viewID = msg.ReadUInt16();
                    var rpcId = msg.ReadByte();
                    Player player = GetPlayer(msg.SenderConnection);
                    NetworkView find;
                    var info = new NetMessageInfo((RPCMode)(msg.SequenceChannel - Channels.BEGIN_RPCMODES), player);
                    if (NetworkView.Find(viewID, out find))
                    {
                        find.CallRPC(rpcId, msg, info);

                        //Do we need to forward this still?
                        if (info.mode != RPCMode.Server && info.continueForwarding)
                        {
                            //need to forward...
                            if (info.mode == RPCMode.Others || info.mode == RPCMode.All) { }
                            else
                            {
                                find.Buffer(msg);
                            }
                            find.Send(msg, info.mode, msg.SenderConnection);
                        }
                    }

                }
                else if (msg.SequenceChannel == Channels.SYNCHED_FIELD)
                {
                    var viewId = msg.ReadUInt16();
                    var fieldId = msg.ReadByte();
                    NetworkView find;
                    if (NetworkView.Find(viewId, out find))
                    {
                        find.BufferField(msg, fieldId);
                        find.SendField(msg, msg.SenderConnection);
                    }
                }
                else if (msg.SequenceChannel == Channels.OBJECT_RPC)
                {
                    Player player = GetPlayer(msg.SenderConnection);
                    if (player.CurrentRoom != null)
                        player.CurrentRoom.IncomingObjectRPC(msg);
                }
                else if (msg.SequenceChannel == Channels.STATIC_RPC)
                {
                    var rpcId = msg.ReadByte();

                    var player = GetPlayer(msg.SenderConnection);
                    var currentRoom = player.CurrentRoom;
                    if (currentRoom != null)
                    {
                        NetMessageInfo info = new NetMessageInfo(RPCMode.None, player);
                        currentRoom.CallRPC(rpcId, msg, info);

                        if (info.continueForwarding)
                        {
                            var newMessage = peer.CreateMessage();
                            msg.Clone(newMessage);
                            currentRoom.SendMessage(newMessage);
                        }
                    }

                }
                else if (msg.SequenceChannel == Channels.STATIC_UTILS)
                {
                    ProcessUtils(msg);
                }
                else
                {
                    Debug.LogWarning("data received over unhandled channel " + msg.SequenceChannel);
                }
            }
            catch (Exception ex)
            {
                Debug.Log("[Consumption] {0} : {1}", ex.Message, ex.StackTrace);
            }
        }
Пример #5
0
        void ReceiveMessage(NetIncomingMessage msg, NetMessageInfo info)
        {
            //if you want to prevent the message from the player from continuing to other players (if it was sent with rpcmode.all or others or owner,
            //then you set info.continueForwarding to false
            //alternatively, the second parameter of the rpc attribute can set what the default value of info.continueForwarding is (in this case, false),
            //and then change it to true if you figure out you do need to let the message continue on.

            Debug.Log("Player {0} sent a message on this component: {1}", info.player, msg.ReadString());
        }
Пример #6
0
        static void HandleStaticRpc(NetIncomingMessage msg)
        {
            var rpcId = msg.ReadByte();

            var player = GetPlayer(msg.SenderConnection);
            var currentRoom = player.CurrentRoom;
            if (currentRoom != null)
            {
                var info = new NetMessageInfo(RPCMode.None, player);
                currentRoom.CallRPC(rpcId, msg, info);

                if (info.continueForwarding)
                {
                    var newMessage = peer.CreateMessage();
                    msg.Clone(newMessage);
                    if (msg.DeliveryMethod == NetDeliveryMethod.ReliableOrdered)
                        currentRoom.SendMessage(newMessage, true);
                    else
                        currentRoom.SendMessage(newMessage, false);
                }
            }
            else
            {
                Debug.LogWarning("[PNetS.Consume] Player {0} attempted static rpc {1}, but they are not in a room to do so",
                    player, rpcId);
                (player).InternalErrorCount++;
            }
        }
Пример #7
0
        private static void Consume(NetIncomingMessage msg)
        {
            try
            {
                //faster than switch, as this is in most to least common order
                if (msg.SequenceChannel == Channels.UNRELIABLE_STREAM)
                {
                    if (msg.DeliveryMethod == NetDeliveryMethod.ReliableUnordered)
                    {
                        HandleStaticRpc(msg);
                    }
                    else
                    {
                        var actorId = msg.ReadUInt16();
                        NetworkView find;
                        if (NetworkView.Find(actorId, out find))
                        {
                            Player player = GetPlayer(msg.SenderConnection);
                            find.OnDeserializeStream(msg, player);
                        }
                        else
                        {
                            if (GetPlayer(msg.SenderConnection).CurrentRoom != null)
                            {
                                Debug.LogWarning(
                                    "[PNetS.Consume] Player {0} attempted to send unreliable stream data for view {1}, but it does not exist",
                                    msg.SenderConnection.Tag, actorId);
                                (msg.SenderConnection.Tag as Player).InternalErrorCount++;
                            }
                        }
                    }
                }
                else if (msg.SequenceChannel == Channels.RELIABLE_STREAM)
                {
                    var actorId = msg.ReadUInt16();
                    NetworkView find;
                    if (NetworkView.Find(actorId, out find))
                    {
                        Player player = GetPlayer(msg.SenderConnection);
                        find.OnDeserializeStream(msg, player);
                    }
                    else
                    {
                        if (GetPlayer(msg.SenderConnection).CurrentRoom != null)
                        {
                            Debug.LogWarning(
                                "[PNetS.Consume] Player {0} attempted to send reliable stream data for view {1}, but it does not exist",
                                msg.SenderConnection.Tag, actorId);
                            (msg.SenderConnection.Tag as Player).InternalErrorCount++;
                        }
                    }
                }
                else if (msg.SequenceChannel >= Channels.BEGIN_RPCMODES && msg.SequenceChannel <= Channels.OWNER_RPC)
                {
                    //rpc...
                    var viewId = msg.ReadUInt16();
                    var rpcId = msg.ReadByte();
                    Player player = GetPlayer(msg.SenderConnection);
                    NetworkView find;
                    var info = new NetMessageInfo((RPCMode)(msg.SequenceChannel - Channels.BEGIN_RPCMODES), player);
                    if (NetworkView.Find(viewId, out find))
                    {
                        find.CallRPC(rpcId, msg, info);


                        //Do we need to forward this still?
                        if (info.mode != RPCMode.Server && info.continueForwarding)
                        {
                            //need to forward...
                            if (info.mode == RPCMode.Others || info.mode == RPCMode.All) { }
                            else
                            {
                                find.Buffer(msg);
                            }
                            find.Send(msg, info.mode, msg.SenderConnection);
                        }
                    }
                    else
                    {
                        if (player.CurrentRoom != null)
                        {
                            Debug.LogWarning(
                                "[PNetS.Consume] Player {0} attempted RPC {1} on view {2}, but the view does not exist",
                                player, rpcId, viewId);
                            player.InternalErrorCount++;
                        }
                    }
                }
                else if (msg.SequenceChannel == Channels.SYNCHED_FIELD)
                {
                    var viewId = msg.ReadUInt16();
                    var fieldId = msg.ReadByte();
                    NetworkView find;
                    if (NetworkView.Find(viewId, out find))
                    {
                        find.BufferField(msg, fieldId);
                        find.SendField(msg, msg.SenderConnection);
                    }
                }
                else if (msg.SequenceChannel == Channels.OBJECT_RPC)
                {
                    Player player = GetPlayer(msg.SenderConnection);
                    if (player.CurrentRoom != null)
                        player.CurrentRoom.IncomingObjectRPC(msg);
                }
                else if (msg.SequenceChannel == Channels.STATIC_RPC)
                {
                    HandleStaticRpc(msg);
                }
                else if (msg.SequenceChannel == Channels.STATIC_UTILS)
                {
                    ProcessUtils(msg);
                }
                else
                {
                    Debug.LogWarning("{2} bytes received over unhandled channel {0}, delivery {1}", msg.SequenceChannel, msg.DeliveryMethod, msg.LengthBytes);
                    (msg.SenderConnection.Tag as Player).InternalErrorCount++;
                }
            }
            catch (Exception ex)
            {
                Debug.Log("[Consumption] {0} : {1}", ex.Message, ex.StackTrace);
            }
        }
Пример #8
0
 internal void CallRPC(byte rpcID, NetIncomingMessage message, NetMessageInfo info)
 {
     Action<NetIncomingMessage, NetMessageInfo> processor;
     if (RPCProcessors.TryGetValue(rpcID, out processor))
     {
         if (processor != null)
             processor(message, info);
         else
         {
             //Debug.LogWarning("RPC processor for {0} was null. Automatically cleaning up. Please be sure to clean up after yourself in the future.", rpcID);
             RPCProcessors.Remove(rpcID);
         }
     }
     else
     {
         Debug.LogWarning("Networkview on {1}: unhandled RPC {0}", rpcID, gameObject.Name);
         info.continueForwarding = false;
     }
 }
Пример #9
0
 void PlayerStaticMessage3(NetIncomingMessage msg, NetMessageInfo info)
 {
     Debug.Log("Got a room-wide/static message {0} from player {1}", msg.ReadString(), info.player);
 }
Пример #10
0
        private static void Consume(NetIncomingMessage msg)
        {
            try
            {
                //faster than switch, as this is in most to least common order
                if (msg.SequenceChannel == Channels.UNRELIABLE_STREAM)
                {
                    if (msg.DeliveryMethod == NetDeliveryMethod.ReliableUnordered)
                    {
                        HandleStaticRpc(msg);
                    }
                    else
                    {
                        var         actorId = msg.ReadUInt16();
                        NetworkView find;
                        if (NetworkView.Find(actorId, out find))
                        {
                            Player player = GetPlayer(msg.SenderConnection);
                            find.OnDeserializeStream(msg, player);
                        }
                        else
                        {
                            if (GetPlayer(msg.SenderConnection).CurrentRoom != null)
                            {
                                Debug.LogWarning(
                                    "[PNetS.Consume] Player {0} attempted to send unreliable stream data for view {1}, but it does not exist",
                                    msg.SenderConnection.Tag, actorId);
                                (msg.SenderConnection.Tag as Player).InternalErrorCount++;
                            }
                        }
                    }
                }
                else if (msg.SequenceChannel == Channels.RELIABLE_STREAM)
                {
                    var         actorId = msg.ReadUInt16();
                    NetworkView find;
                    if (NetworkView.Find(actorId, out find))
                    {
                        Player player = GetPlayer(msg.SenderConnection);
                        find.OnDeserializeStream(msg, player);
                    }
                    else
                    {
                        if (GetPlayer(msg.SenderConnection).CurrentRoom != null)
                        {
                            Debug.LogWarning(
                                "[PNetS.Consume] Player {0} attempted to send reliable stream data for view {1}, but it does not exist",
                                msg.SenderConnection.Tag, actorId);
                            (msg.SenderConnection.Tag as Player).InternalErrorCount++;
                        }
                    }
                }
                else if (msg.SequenceChannel >= Channels.BEGIN_RPCMODES && msg.SequenceChannel <= Channels.OWNER_RPC)
                {
                    //rpc...
                    var         viewId = msg.ReadUInt16();
                    var         rpcId  = msg.ReadByte();
                    Player      player = GetPlayer(msg.SenderConnection);
                    NetworkView find;
                    var         info = new NetMessageInfo((RPCMode)(msg.SequenceChannel - Channels.BEGIN_RPCMODES), player);
                    if (NetworkView.Find(viewId, out find))
                    {
                        find.CallRPC(rpcId, msg, info);


                        //Do we need to forward this still?
                        if (info.mode != RPCMode.Server && info.continueForwarding)
                        {
                            //need to forward...
                            if (info.mode == RPCMode.Others || info.mode == RPCMode.All)
                            {
                            }
                            else
                            {
                                find.Buffer(msg);
                            }
                            find.Send(msg, info.mode, msg.SenderConnection);
                        }
                    }
                    else
                    {
                        if (player.CurrentRoom != null)
                        {
                            Debug.LogWarning(
                                "[PNetS.Consume] Player {0} attempted RPC {1} on view {2}, but the view does not exist",
                                player, rpcId, viewId);
                            player.InternalErrorCount++;
                        }
                    }
                }
                else if (msg.SequenceChannel == Channels.SYNCHED_FIELD)
                {
                    var         viewId  = msg.ReadUInt16();
                    var         fieldId = msg.ReadByte();
                    NetworkView find;
                    if (NetworkView.Find(viewId, out find))
                    {
                        find.BufferField(msg, fieldId);
                        find.SendField(msg, msg.SenderConnection);
                    }
                }
                else if (msg.SequenceChannel == Channels.OBJECT_RPC)
                {
                    Player player = GetPlayer(msg.SenderConnection);
                    if (player.CurrentRoom != null)
                    {
                        player.CurrentRoom.IncomingObjectRPC(msg);
                    }
                }
                else if (msg.SequenceChannel == Channels.STATIC_RPC)
                {
                    HandleStaticRpc(msg);
                }
                else if (msg.SequenceChannel == Channels.STATIC_UTILS)
                {
                    ProcessUtils(msg);
                }
                else
                {
                    Debug.LogWarning("{2} bytes received over unhandled channel {0}, delivery {1}", msg.SequenceChannel, msg.DeliveryMethod, msg.LengthBytes);
                    (msg.SenderConnection.Tag as Player).InternalErrorCount++;
                }
            }
            catch (Exception ex)
            {
                Debug.Log("[Consumption] {0} : {1}", ex.Message, ex.StackTrace);
            }
        }
Пример #11
0
        private static void Consume(NetIncomingMessage msg)
        {
            try
            {
                //faster than switch, as this is in most to least common order
                if (msg.SequenceChannel == Channels.UNRELIABLE_STREAM)
                {
                    var         actorId = msg.ReadUInt16();
                    NetworkView find;
                    if (NetworkView.Find(actorId, out find))
                    {
                        Player player = GetPlayer(msg.SenderConnection);
                        find.OnDeserializeStream(msg, player);
                    }
                }
                else if (msg.SequenceChannel == Channels.RELIABLE_STREAM)
                {
                    var         actorId = msg.ReadUInt16();
                    NetworkView find;
                    if (NetworkView.Find(actorId, out find))
                    {
                        Player player = GetPlayer(msg.SenderConnection);
                        find.OnDeserializeStream(msg, player);
                    }
                }
                else if (msg.SequenceChannel >= Channels.BEGIN_RPCMODES && msg.SequenceChannel <= Channels.OWNER_RPC)
                {
                    //rpc...
                    var         viewID = msg.ReadUInt16();
                    var         rpcId  = msg.ReadByte();
                    Player      player = GetPlayer(msg.SenderConnection);
                    NetworkView find;
                    var         info = new NetMessageInfo((RPCMode)(msg.SequenceChannel - Channels.BEGIN_RPCMODES), player);
                    if (NetworkView.Find(viewID, out find))
                    {
                        find.CallRPC(rpcId, msg, info);


                        //Do we need to forward this still?
                        if (info.mode != RPCMode.Server && info.continueForwarding)
                        {
                            //need to forward...
                            if (info.mode == RPCMode.Others || info.mode == RPCMode.All)
                            {
                            }
                            else
                            {
                                find.Buffer(msg);
                            }
                            find.Send(msg, info.mode, msg.SenderConnection);
                        }
                    }
                }
                else if (msg.SequenceChannel == Channels.SYNCHED_FIELD)
                {
                    var         viewId  = msg.ReadUInt16();
                    var         fieldId = msg.ReadByte();
                    NetworkView find;
                    if (NetworkView.Find(viewId, out find))
                    {
                        find.BufferField(msg, fieldId);
                        find.SendField(msg, msg.SenderConnection);
                    }
                }
                else if (msg.SequenceChannel == Channels.OBJECT_RPC)
                {
                    Player player = GetPlayer(msg.SenderConnection);
                    if (player.CurrentRoom != null)
                    {
                        player.CurrentRoom.IncomingObjectRPC(msg);
                    }
                }
                else if (msg.SequenceChannel == Channels.STATIC_RPC)
                {
                    var rpcId = msg.ReadByte();

                    var player      = GetPlayer(msg.SenderConnection);
                    var currentRoom = player.CurrentRoom;
                    if (currentRoom != null)
                    {
                        NetMessageInfo info = new NetMessageInfo(RPCMode.None, player);
                        currentRoom.CallRPC(rpcId, msg, info);

                        if (info.continueForwarding)
                        {
                            var newMessage = peer.CreateMessage();
                            msg.Clone(newMessage);
                            currentRoom.SendMessage(newMessage);
                        }
                    }
                }
                else if (msg.SequenceChannel == Channels.STATIC_UTILS)
                {
                    ProcessUtils(msg);
                }
                else
                {
                    Debug.LogWarning("data received over unhandled channel " + msg.SequenceChannel);
                }
            }
            catch (Exception ex)
            {
                Debug.Log("[Consumption] {0} : {1}", ex.Message, ex.StackTrace);
            }
        }