void NetMsgReceived(object sender, NetMsgEventArgs e) { var packetMsg = CMClient.GetPacketMsg(e.Data); if (packetMsg == null) { DebugLog.WriteLine(nameof(UFSClient), "Packet message failed to parse, shutting down connection"); Disconnect(userInitiated: false); return; } DebugLog.WriteLine(nameof(UFSClient), "<- Recv'd EMsg: {0} ({1}) {2}", packetMsg.MsgType, ( int )packetMsg.MsgType, packetMsg.IsProto ? "(Proto)" : ""); var msgDispatch = new Dictionary <EMsg, Action <IPacketMsg> > { { EMsg.ClientUFSLoginResponse, HandleLoginResponse }, { EMsg.ClientUFSUploadFileResponse, HandleUploadFileResponse }, { EMsg.ClientUFSUploadFileFinished, HandleUploadFileFinished }, }; if (!msgDispatch.TryGetValue(packetMsg.MsgType, out var handlerFunc)) { return; } handlerFunc(packetMsg); }
public void GetPacketMsgFailsWithTinyArray() { var data = new byte[3]; var packetMsg = CMClient.GetPacketMsg(data); Assert.Null(packetMsg); }
void NetMsgReceived(object sender, NetMsgEventArgs e) { var packetMsg = CMClient.GetPacketMsg(e.Data); DebugLog.WriteLine("UFSClient", "<- Recv'd EMsg: {0} ({1}) {2}", packetMsg.MsgType, ( int )packetMsg.MsgType, packetMsg.IsProto ? "(Proto)" : ""); var msgDispatch = new Dictionary <EMsg, Action <IPacketMsg> > { { EMsg.ChannelEncryptRequest, HandleEncryptRequest }, { EMsg.ChannelEncryptResult, HandleEncryptResult }, { EMsg.ClientUFSLoginResponse, HandleLoginResponse }, { EMsg.ClientUFSUploadFileResponse, HandleUploadFileResponse }, { EMsg.ClientUFSUploadFileFinished, HandleUploadFileFinished }, }; Action <IPacketMsg> handlerFunc; if (!msgDispatch.TryGetValue(packetMsg.MsgType, out handlerFunc)) { return; } handlerFunc(packetMsg); }
public void GetPacketMsgFailsWithTinyArray() { var data = new byte[3]; var packetMsg = CMClient.GetPacketMsg(data, DebugLogContext.Instance); Assert.Null(packetMsg); }
void OnNetMsgReceived(object sender, NetMsgEventArgs e) { if (state == EncryptionState.Encrypted) { var plaintextData = encryption !.ProcessIncoming(e.Data); NetMsgReceived?.Invoke(this, e.WithData(plaintextData)); return; } var packetMsg = CMClient.GetPacketMsg(e.Data, log); if (packetMsg == null) { log.LogDebug(nameof(EnvelopeEncryptedConnection), "Failed to parse message during channel setup, shutting down connection"); Disconnect(userInitiated: false); return; } else if (!IsExpectedEMsg(packetMsg.MsgType)) { log.LogDebug(nameof(EnvelopeEncryptedConnection), "Rejected EMsg: {0} during channel setup", packetMsg.MsgType); return; } switch (packetMsg.MsgType) { case EMsg.ChannelEncryptRequest: HandleEncryptRequest(packetMsg); break; case EMsg.ChannelEncryptResult: HandleEncryptResult(packetMsg); break; } }
void OnNetMsgReceived(object sender, NetMsgEventArgs e) { if (state == EncryptionState.Encrypted) { var plaintextData = encryption.ProcessIncoming(e.Data); NetMsgReceived?.Invoke(this, e.WithData(plaintextData)); return; } var packetMsg = CMClient.GetPacketMsg(e.Data); if (!IsExpectedEMsg(packetMsg.MsgType)) { DebugLog.WriteLine(nameof(EnvelopeEncryptedConnection), "Rejected EMsg: {0} during channel setup", packetMsg.MsgType); return; } switch (packetMsg.MsgType) { case EMsg.ChannelEncryptRequest: HandleEncryptRequest(packetMsg); break; case EMsg.ChannelEncryptResult: HandleEncryptResult(packetMsg); break; } }
public void GetPacketMsgReturnsPacketClientMsgForOtherMessages() { var msg = MsgUtil.MakeMsg(EMsg.ClientLogOnResponse, protobuf: false); var msgHdr = new ExtendedClientMsgHdr { Msg = msg }; var data = Serialize(msgHdr); var packetMsg = CMClient.GetPacketMsg(data); Assert.IsAssignableFrom <PacketClientMsg>(packetMsg); }
public void GetPacketMsgReturnsPacketClientMsgProtobufForMessagesWithProtomask() { var msg = MsgUtil.MakeMsg(EMsg.ClientLogOnResponse, protobuf: true); var msgHdr = new MsgHdrProtoBuf { Msg = msg }; var data = Serialize(msgHdr); var packetMsg = CMClient.GetPacketMsg(data); Assert.IsAssignableFrom <PacketClientMsgProtobuf>(packetMsg); }
public void GetPacketMsgFailsWithNull() { var msg = MsgUtil.MakeMsg(EMsg.ClientLogOnResponse, protobuf: true); var msgHdr = new MsgHdrProtoBuf { Msg = msg }; var data = Serialize(msgHdr); Array.Copy(BitConverter.GetBytes(-1), 0, data, 4, 4); var packetMsg = CMClient.GetPacketMsg(data); Assert.Null(packetMsg); }
public void GetPacketMsgReturnsPacketMsgForCryptoHandshake() { var messages = new[] { EMsg.ChannelEncryptRequest, EMsg.ChannelEncryptResponse, EMsg.ChannelEncryptResult }; foreach (var emsg in messages) { var msgHdr = new MsgHdr { Msg = emsg }; var data = Serialize(msgHdr); var packetMsg = CMClient.GetPacketMsg(data); Assert.IsAssignableFrom <PacketMsg>(packetMsg); } }
static IPacketMsg BuildStructMsg() { return(CMClient.GetPacketMsg(structMsgData)); }
static IPacketMsg BuildStructMsg() { return(CMClient.GetPacketMsg(structMsgData, DebugLogContext.Instance)); }