Beispiel #1
0
        /// <summary>
        /// Send a message to all players in the room
        /// </summary>
        /// <param name="rpcId">id of the RPC</param>
        /// <param name="mode"></param>
        /// <param name="args"></param>
        public void RPC(byte rpcId, RPCMode mode, params INetSerializable[] args)
        {
            var size = 1;

            RPCUtils.AllocSize(ref size, args);

            var message = PNetServer.peer.CreateMessage(size);

            message.Write(rpcId);
            RPCUtils.WriteParams(ref message, args);

            if (mode == RPCMode.AllBuffered || mode == RPCMode.OthersBuffered)
            {
                Buffer(message, mode);
            }

            if (mode == RPCMode.AllUnordered || mode == RPCMode.OthersUnordered)
            {
                SendMessage(message, false);
            }
            else
            {
                SendMessage(message, true);
            }
        }
Beispiel #2
0
        private const int DEFAULT_RPC_HEADER_SIZE = 3; //guid + rpcid

        #region mode rpcs

        /// <summary>
        /// Send a message to the specified recipients
        /// </summary>
        /// <param name="rpcID"></param>
        /// <param name="mode"></param>
        /// <param name="args"></param>
        public void RPC(byte rpcID, RPCMode mode, params INetSerializable[] args)
        {
            var size = DEFAULT_RPC_HEADER_SIZE;

            RPCUtils.AllocSize(ref size, args);

            var message = CreateMessage(size, rpcID);

            RPCUtils.WriteParams(ref message, args);

            FinishRPCSend(mode, message);
        }
Beispiel #3
0
        /// <summary>
        /// Send a static RPC to the player, in any order
        /// </summary>
        /// <param name="rpcId"></param>
        /// <param name="args"></param>
        public void RPCUnordered(byte rpcId, params INetSerializable[] args)
        {
            var size = 1;

            RPCUtils.AllocSize(ref size, args);

            var message = CreateMessage(rpcId, size);

            RPCUtils.WriteParams(ref message, args);

            SendMessage(message);
        }
Beispiel #4
0
        /// <summary>
        /// Send an rpc to the server
        /// </summary>
        /// <param name="rpcId"></param>
        /// <param name="args"></param>
        public static void RPC(byte rpcId, params INetSerializable[] args)
        {
            var size = 1;

            RPCUtils.AllocSize(ref size, args);

            var message = peer.CreateMessage(size);

            message.Write(rpcId);
            RPCUtils.WriteParams(ref message, args);

            peer.SendMessage(message, NetDeliveryMethod.ReliableOrdered, Channels.STATIC_RPC);
        }
Beispiel #5
0
        /// <summary>
        /// Send an rpc to the owner of this object
        /// </summary>
        /// <param name="rpcID"></param>
        /// <param name="args"></param>
        public void RPCToOwner(byte rpcID, params INetSerializable[] args)
        {
            var size = 3;

            RPCUtils.AllocSize(ref size, args);

            var message = Net.peer.CreateMessage(size);

            message.Write(viewID.guid);
            message.Write(rpcID);
            RPCUtils.WriteParams(ref message, args);

            Net.peer.SendMessage(message, NetDeliveryMethod.ReliableOrdered, Channels.OWNER_RPC);
        }
Beispiel #6
0
        /// <summary>
        /// Send an rpc
        /// </summary>
        /// <param name="rpcID"></param>
        /// <param name="mode"></param>
        /// <param name="args"></param>
        public void RPC(byte rpcID, UnityEngine.RPCMode mode, params INetSerializable[] args)
        {
            var size = 2;

            RPCUtils.AllocSize(ref size, args);

            var message = Net.peer.CreateMessage(size);

            message.Write(viewID.guid);
            message.Write(rpcID);
            RPCUtils.WriteParams(ref message, args);

            Net.peer.SendMessage(message, NetDeliveryMethod.ReliableOrdered, (int)mode + Channels.BEGIN_RPCMODES);
        }
        /// <summary>
        /// Send an rpc to the server
        /// </summary>
        /// <param name="rpcID"></param>
        /// <param name="args"></param>
        public void RPC(byte rpcID, params INetSerializable[] args)
        {
            var size = 3;

            RPCUtils.AllocSize(ref size, args);

            var message = _net.Peer.CreateMessage(size);

            message.Write((ushort)NetworkID);
            message.Write(rpcID);
            RPCUtils.WriteParams(ref message, args);

            _net.Peer.SendMessage(message, NetDeliveryMethod.ReliableOrdered, Channels.OBJECT_RPC);
        }
Beispiel #8
0
        /// <summary>
        /// Create a netbuffer object that can be used to send a message without reserialization
        /// </summary>
        /// <param name="rpcID"></param>
        /// <param name="args"></param>
        /// <returns></returns>
        public NetBuffer CreateBuffer(byte rpcID, params INetSerializable[] args)
        {
            var size = DEFAULT_RPC_HEADER_SIZE;

            RPCUtils.AllocSize(ref size, args);
            var message = CreateMessage(size, rpcID);

            RPCUtils.WriteParams(ref message, args);

            var buff = new NetBuffer();

            message.Clone(buff);
            PNetServer.peer.Recycle(message);
            return(buff);
        }
Beispiel #9
0
        /// <summary>
        /// send a message to the specified player
        /// </summary>
        /// <param name="rpcID"></param>
        /// <param name="player"></param>
        /// <param name="args"></param>
        public void RPC(byte rpcID, Player player, params INetSerializable[] args)
        {
            if (_connections.Count == 0)
            {
                return;
            }

            var size = DEFAULT_RPC_HEADER_SIZE;

            RPCUtils.AllocSize(ref size, args);
            var message = CreateMessage(size, rpcID);

            RPCUtils.WriteParams(ref message, args);

            FinishRPCSend(player, message);
        }
Beispiel #10
0
        /// <summary>
        /// send a message to the specified player
        /// </summary>
        /// <param name="rpcID"></param>
        /// <param name="player"></param>
        /// <param name="args"></param>
        public void RPC(byte rpcID, Player player, params INetSerializable[] args)
        {
            if (_connections.Count == 0)
            {
                return;
            }

            var size = 2;

            RPCUtils.AllocSize(ref size, args);

            var message = PNetServer.peer.CreateMessage(size);

            message.Write(viewID.guid);
            message.Write(rpcID);
            RPCUtils.WriteParams(ref message, args);

            PNetServer.peer.SendMessage(message, player.connection, NetDeliveryMethod.ReliableOrdered, Channels.OWNER_RPC);
        }
Beispiel #11
0
        /// <summary>
        /// Send an rpc to all in the room.
        /// </summary>
        /// <param name="rpcID"></param>
        /// <param name="args"></param>
        public void RPC(byte rpcID, params INetSerializable[] args)
        {
            if (connections.Count == 0)
            {
                return;
            }

            var size = 3;

            RPCUtils.AllocSize(ref size, args);

            var message = PNetServer.peer.CreateMessage(size);

            message.Write((ushort)NetworkID);
            message.Write(rpcID);
            RPCUtils.WriteParams(ref message, args);

            PNetServer.peer.SendMessage(message, connections, NetDeliveryMethod.ReliableOrdered, Channels.OBJECT_RPC);
        }
Beispiel #12
0
        /// <summary>
        /// Send a message to the specified recipients
        /// </summary>
        /// <param name="rpcID"></param>
        /// <param name="mode"></param>
        /// <param name="args"></param>
        public void RPC(byte rpcID, RPCMode mode, params INetSerializable[] args)
        {
            if (_connections.Count == 0)
            {
                return;
            }

            var size = 3;

            RPCUtils.AllocSize(ref size, args);

            var message = PNetServer.peer.CreateMessage(size);

            message.Write(viewID.guid);
            message.Write(rpcID);
            RPCUtils.WriteParams(ref message, args);

            if (mode == RPCMode.AllBuffered || mode == RPCMode.OthersBuffered)
            {
                Buffer(message);
            }

            SendMessage(message, mode);
        }