void HandleRemotePacket(NetInboundPacket packet) { // Read the remote header RemoteChannelType type = (RemoteChannelType)packet.ReadByte(); ushort channelId = packet.ReadUInt16(); // Attempt to locate the channel RemoteChannelBase channel = GetRemoteChannelFromPacket(type, channelId); if (channel != null) { inboundRemotes.Enqueue(new InboundRemote(packet, channel)); } }
void HandleRemoteEvent(NetInboundPacket packet, RemoteChannelBase channel) { // Attempt to locate the event string eventName = packet.ReadString(); RemoteEvent evt; if (channel.Events.TryGetValue(eventName, out evt)) { // Call the event ushort numArgs = packet.ReadUInt16(); evt(packet.Sender, packet, numArgs); } else { NetLogger.LogError("Remote Event \"{0}\" was fired on a {1} channel with the id {2}, but it doesn't exist!", eventName, channel.Type, channel.Id); } }
void HandleRemoteFunctionResponse(NetInboundPacket packet, RemoteChannelBase channel) { // Attempt to locate the function callback string funcName = packet.ReadString(); ushort callbackId = packet.ReadUInt16(); RemoteFunctionCallback callback; if (channel.WaitingFunctions.TryGetValue(callbackId, out callback)) { // Call the callback (hehe) callback(packet.Sender, packet); // Remove the callback from the waiting list channel.WaitingFunctions.TryRemove(callbackId, out callback); } else { NetLogger.LogError( "Received a Remote Function Response for function {0} on channel {1}, but we do not have a callback!", funcName, channel.Id); } }
void HandleRemoteFunction(NetInboundPacket packet, RemoteChannelBase channel) { // Attempt to locate the function string funcName = packet.ReadString(); RemoteFunction func; if (channel.Functions.TryGetValue(funcName, out func)) { // Get the callback id ushort callbackId = packet.ReadUInt16(); // Call the event ushort numArgs = packet.ReadUInt16(); NetBuffer returnValue = func(packet.Sender, packet, numArgs); // Send the response NetOutboundPacket funcResponse = new NetOutboundPacket(NetDeliveryMethod.Reliable); funcResponse.Type = NetPacketType.RemoteFunctionResponse; funcResponse.Encrypt = packet.isEncrypted; // Write the normal remote header funcResponse.Write((byte)channel.Type); funcResponse.Write(channel.Id); funcResponse.Write(funcName); funcResponse.Write(callbackId); // Write the return value funcResponse.WriteBytes(returnValue.data, 0, returnValue.Length); // Send the response packet.Sender.SendPacket(funcResponse); } else { NetLogger.LogError("Remote Function \"{0}\" was invoked on a {1} channel with the id {2}, but it doesn't exist!", funcName, channel.Type, channel.Id); } }
public InboundRemote(NetInboundPacket packet, RemoteChannelBase channel) { Packet = packet; Channel = channel; }