internal void BufferField(NetIncomingMessage msg, byte fieldId) { var toBuffer = new NetBuffer(); msg.Clone(toBuffer); fieldBuffer[fieldId] = toBuffer; }
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); } }
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++; } }