internal void ConsumeData(NetMessage msg)
        {
            if (!msg.ReadByte(out var header))
            {
                return;
            }
            RpcUtils.ReadHeader(header, out var reliability, out var broadcast, out var msgType, out var sub);

            switch (msgType)
            {
            case MsgType.Internal:
                ProcessInternal(broadcast, reliability, msg);
                break;

            case MsgType.Static:
                ProcessStatic(broadcast, reliability, msg);
                break;

            case MsgType.Netview:
                var info = new NetMessageInfo(broadcast, this)
                {
                    Reliability = reliability
                };
                Room.NetworkManager.CallRpc(msg, info, sub);
                break;

            case MsgType.Stream:
                Room.NetworkManager.Stream(msg, this);
                break;

            default:
                Debug.LogWarning($"Unsupported {msg.LengthBytes - 1} byte message of type {msgType} from {this}");
                break;
            }
        }
        protected override void OnSuccess(NetMessage msg, NetMessageInfo info)
        {
            var val = _deserialize(msg);

            _success?.Invoke(val, info);
            _complete?.Invoke(val, info);
        }
        private void ProcessStatic(BroadcastMode broadcast, ReliabilityMode reliability, NetMessage msg)
        {
            var info = new NetMessageInfo(broadcast, this)
            {
                Reliability = reliability
            };

            //route back to room...
            try
            {
                Room.CallRpc(msg, info);
            }
            catch (Exception e)
            {
                info.ContinueForwarding = false;
                Debug.LogException(e);
            }

            //todo: filter if rpc mode is all/others/owner, and then send to appropriate people.
            if (info.ContinueForwarding)
            {
                if (info.Mode == BroadcastMode.Others)
                {
                    Room.SendExcept(msg, info.Sender, info.Reliability);
                }
                else if (info.Mode == BroadcastMode.All)
                {
                    Room.SendToPlayers(msg, info.Reliability);
                }
            }
        }
 internal void RunSuccess(NetMessage msg, NetMessageInfo info)
 {
     try
     {
         OnSuccess(msg, info);
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
 }
 internal void RunError(NetMessage msg, NetMessageInfo info)
 {
     try
     {
         OnError(msg.ReadString(), info);
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
 }
Example #6
0
        internal void CallRpc(NetMessage msg, NetMessageInfo info)
        {
            if (msg.RemainingBits < 24L)
            {
                Debug.LogError("Malformed networked scene object rpc");
            }
            var id = msg.ReadUInt16();

            if (!_views.TryGetValue(id, out var view))
            {
                Debug.LogWarning($"Could not find networked scene object {id} to call an rpc on");
                return;
            }
            view.CallRpc(msg.ReadByte(), msg, info);
        }
Example #7
0
        internal void CallRpc(NetMessage msg, NetMessageInfo info, SubMsgType sub)
        {
            if (msg.RemainingBits < 32)
            {
                Debug.LogWarning("Attempted to call an rpc on a network view, but there weren't enough bits remaining to do it.");
                return;
            }
            var id   = msg.ReadUInt16();
            var comp = msg.ReadByte();
            var rpc  = msg.ReadByte();

            NetworkView view;
            var         supposedToHave = _networkViews.TryGetValue(id, out view);

            if (supposedToHave && view != null)
            {
                view.IncomingRpc(comp, rpc, msg, info, sub);
            }
            else
            {
                Debug.LogWarning($"Could not find view {id} to call {comp} rpc {rpc}");
            }

            //todo: filter if rpc mode is all/others/owner, and then send to appropriate people.
            if (info.ContinueForwarding && view != null)
            {
                if (info.Mode == BroadcastMode.Others)
                {
                    view.SendExcept(msg, info.Sender, info.Reliability);
                }
                else if (info.Mode == BroadcastMode.All)
                {
                    view.SendMessage(msg, RpcUtils.RpcMode(info.Reliability, info.Mode));
                }
                else if (info.Mode == BroadcastMode.Owner && info.Sender != view.Owner && view.Owner.IsValid)
                {
                    view.Owner.SendMessage(msg, info.Reliability);
                }
            }
        }
Example #8
0
        internal void CallRpc(byte rpcID, NetMessage message, NetMessageInfo info)
        {
            RpcProcessor processor;

            if (_rpcProcessors.TryGetValue(rpcID, out processor))
            {
                info.ContinueForwarding = processor.DefaultContinueForwarding;

                if (processor.Action != null)
                {
                    processor.Action(message, info);
                }
                else
                {
                    Debug.LogWarning($"RPC processor for {rpcID} was null. Automatically cleaning up. Please be sure to clean up after yourself in the future.");
                    _rpcProcessors.Remove(rpcID);
                }
            }
            else
            {
                Debug.LogWarning($"NetworkedSceneView {rpcID} received unhandled RPC {NetworkID}");
                info.ContinueForwarding = false;
            }
        }
 protected abstract void OnSuccess(NetMessage msg, NetMessageInfo info);
 protected abstract void OnError(string msg, NetMessageInfo info);
 protected override void OnError(string msg, NetMessageInfo info)
 {
     _error?.Invoke(msg, info);
     _complete?.Invoke(default(T), info);
 }