コード例 #1
0
ファイル: PNetServer.cs プロジェクト: kangtachan/PNet
        internal static void ProcessUtils(NetIncomingMessage msg)
        {
            //
            var utilId = msg.ReadByte();

            if (utilId == RPCUtils.TimeUpdate)
            {
                //Players shouldn't be doing this either..
                Debug.LogWarning("[PNetS.ProcessUtils] Player {0} attempted to set time", msg.SenderConnection.Tag);
                (msg.SenderConnection.Tag as Player).InternalErrorCount++;
            }
            else if (utilId == RPCUtils.Instantiate)
            {
                //Players shouldn't be instantiating things
                Debug.LogWarning("[PNetS.ProcessUtils] Player {0} attempted to instantiate something", msg.SenderConnection.Tag);
                (msg.SenderConnection.Tag as Player).InternalErrorCount++;
            }
            else if (utilId == RPCUtils.FinishedRoomChange)
            {
                //the player has finished loading into the new room. now actually put their player in the new room.
                var player = msg.SenderConnection.Tag as Player;

                var newRoom = player.GetRoomSwitchingTo();

                if (newRoom != null)
                {
                    newRoom.AddPlayer(player);
                }
                else
                {
                    Debug.LogWarning("[PNetS.ProcessUtils] Player {0} attempted to finish joining a room, but it no longer exists", msg.SenderConnection.Tag);
                    (msg.SenderConnection.Tag as Player).InternalErrorCount++;
                }
            }
            else if (utilId == RPCUtils.Remove)
            {
                //Players shouldn't be removing view ids
                Debug.LogWarning("[PNetS.ProcessUtils] Player {0} attempted to remove a network view", msg.SenderConnection.Tag);
                (msg.SenderConnection.Tag as Player).InternalErrorCount++;
            }
            else if (utilId == RPCUtils.FinishedInstantiate)
            {
                Player player = msg.SenderConnection.Tag as Player;
                ushort viewId = msg.ReadUInt16();

                NetworkView find;
                if (NetworkView.Find(viewId, out find))
                {
                    find.gameObject.OnFinishedInstantiate(player);
                }
                else
                {
                    Debug.LogWarning("[PNetS.ProcessUtils] Player {0} attempted to finish instantiation for {1}, but that view ID doesn't exist", msg.SenderConnection.Tag, viewId);
                    (msg.SenderConnection.Tag as Player).InternalErrorCount++;
                }
            }
        }
コード例 #2
0
ファイル: PNetServer.cs プロジェクト: Antaresgames/PNet
        internal static void ProcessUtils(NetIncomingMessage msg)
        {
            //
            var utilId = msg.ReadByte();

            if (utilId == RPCUtils.TimeUpdate)
            {
                //Players shouldn't be doing this either..
            }
            else if (utilId == RPCUtils.Instantiate)
            {
                //Players shouldn't be instantiating things

                //read the path...

                //var resourcePath = msg.ReadString();
                //var viewId = msg.ReadUInt16();
                //var ownerId = msg.ReadUInt16();

                //var gobj = Resources.Load(resourcePath);
                //var instance = (GameObject)GameObject.Instantiate(gobj);

                //look for a networkview..

                //var view = instance.GetComponent<NetworkView>();

                //if (view)
                //{
                //    NetworkView.RegisterView(view, viewId);
                //    view.viewID = new NetworkViewId() { guid = viewId, IsMine = PlayerId == ownerId };
                //}
            }
            else if (utilId == RPCUtils.FinishedRoomChange)
            {
                //the player has finished loading into the new room. now actually put their player in the new room.



                var player = msg.SenderConnection.Tag as Player;

                var newRoom = player.GetRoomSwitchingTo();

                if (newRoom != null)
                {
                    newRoom.AddPlayer(player);
                }
            }
            else if (utilId == RPCUtils.Remove)
            {
                //Players shouldn't be removing view ids

                //var viewId = msg.ReadUInt16();

                //NetworkView.RemoveView(viewId);
            }
            else if (utilId == RPCUtils.FinishedInstantiate)
            {
                Player player = msg.SenderConnection.Tag as Player;
                ushort viewId = msg.ReadUInt16();

                NetworkView find;
                if (NetworkView.Find(viewId, out find))
                {
                    find.gameObject.OnFinishedInstantiate(player);
                }
            }
        }
コード例 #3
0
ファイル: PNetServer.cs プロジェクト: kangtachan/PNet
        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);
            }
        }
コード例 #4
0
ファイル: PNetServer.cs プロジェクト: Antaresgames/PNet
        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);
            }
        }