public void ReliableRelayHandler(IChannel channel, ProudSession session, ReliableRelay1Message message) { if (session.P2PGroup == null) { return; } foreach (var destination in message.Destination.Where(d => d.HostId != session.HostId)) { if (session.P2PGroup == null) { //Logger<>.Debug($"Client {session.HostId} is not in a P2PGroup"); return; } if (!session.P2PGroup.Members.ContainsKey(destination.HostId)) { //Logger<>.Debug($"Client {session.HostId} trying to relay to non existant {destination.HostId}"); return; } var target = _server.Sessions.GetValueOrDefault(destination.HostId); target?.SendAsync(new ReliableRelay2Message(new RelayDestinationDto(session.HostId, destination.FrameNumber), message.Data)); } }
public Task <bool> OnHandle(MessageContext context, ReliableRelay1Message message) { var session = context.Session; foreach (var destination in message.Destination.Where(x => x.HostId != session.HostId)) { if (destination.HostId == Constants.HostIdServerHack) { var decodedMessage = CoreMessageDecoder.Decode(_serializer, Unpooled.WrappedBuffer(message.Data)); context.ChannelHandlerContext.Handler.ChannelRead(context.ChannelHandlerContext, new MessageContext { ChannelHandlerContext = context.ChannelHandlerContext, Session = context.Session, Message = decodedMessage, UdpEndPoint = context.UdpEndPoint }); continue; } var target = session.P2PGroup?.GetMemberInternal(destination.HostId); target?.Send(new ReliableRelay2Message(new RelayDestinationDto(session.HostId, destination.FrameNumber), message.Data)); } return(Task.FromResult(true)); }
public void ReliableRelayHandler(ProudSession session, ReliableRelay1Message message) { if (session.P2PGroup == null) { return; } foreach (var destination in message.Destination.Where(d => d.HostId != session.HostId)) { if (session.P2PGroup == null) { continue; } if (!session.P2PGroup.Members.ContainsKey(destination.HostId)) { continue; } var target = _server.Sessions.GetValueOrDefault(destination.HostId); target?.SendAsync(new ReliableRelay2Message(new RelayDestinationDto(session.HostId, destination.FrameNumber), message.Data)); } }
public void ReliableRelayHandler(ProudSession session, ReliableRelay1Message message, MessageReceivedEventArgs e) { if (session.P2PGroup == null) { return; } foreach (var destination in message.Destination.Where(d => d.HostId != session.HostId)) { if (session.P2PGroup == null) { Logger.Debug($"Client {session.HostId} is not in a P2PGroup"); return; } if (!session.P2PGroup.Members.ContainsKey(destination.HostId)) { Logger.Debug($"Client {session.HostId} trying to relay to non existant {destination.HostId}"); return; } if (destination.HostId == 2) { #region Hardcoded ServerMember ProudCoreOpCode opCode; byte[] data; using (var r = message.Data.ToBinaryReader()) { opCode = r.ReadEnum <ProudCoreOpCode>(); data = r.ReadToEnd(); } if (opCode == ProudCoreOpCode.Rmi) { var core = new RmiMessage(data) { IsRelayed = true, SenderHostId = session.HostId, TargetHostId = destination.HostId }; e.Message = core; _filter.OnMessageReceived(e); } else if (opCode == ProudCoreOpCode.ReliableUdp_Frame) { ReliableUdp_FrameMessage udpFrameMessage; using (var r = data.ToBinaryReader()) udpFrameMessage = Serializer.Deserialize <ReliableUdp_FrameMessage>(r); using (var r = udpFrameMessage.Data.ToBinaryReader()) { opCode = r.ReadEnum <ProudCoreOpCode>(); data = r.ReadToEnd(); } CoreMessage core; if (opCode == ProudCoreOpCode.Rmi) { core = new RmiMessage(data) { IsRelayed = true, SenderHostId = session.HostId, TargetHostId = destination.HostId }; } else if (opCode == ProudCoreOpCode.EncryptedReliable) { using (var r = data.ToBinaryReader()) core = Serializer.Deserialize <EncryptedReliableMessage>(r); core.IsRelayed = true; core.SenderHostId = session.HostId; core.TargetHostId = destination.HostId; } else { throw new ProudException($"Invalid opCode {opCode}"); } e.Message = core; _filter.OnMessageReceived(e); } else { throw new ProudException($"Invalid opCode {opCode}"); } #endregion } else { var target = _filter.SessionLookupByHostId.GetValueOrDefault(destination.HostId); target?.Send(new ReliableRelay2Message(new RelayDestinationDto(session.HostId, destination.FrameNumber), message.Data)); } } }