private void packetProcessingSequence(NetPacket packet) { DaedalusGlobal.ReturnCodes rc; int packetStart, packetLength; // We already did this in the comms stream parser, but what the hey if (EncryptedDaedalusPacket.IsValidPacket(packet.payload, out rc, out packetStart, out packetLength)) { // Build the encrypted packet EncryptedDaedalusPacket encPacket = new EncryptedDaedalusPacket(packet.payload, packetStart, packetLength, out rc, AESKey); // If the decrypted payload is a valid packet... if (DecryptedDaedalusPacket.IsValidPacket(encPacket.decryptedPayload, out rc, out packetStart, out packetLength)) { // Build the decrypted packet DecryptedDaedalusPacket decPacket = new DecryptedDaedalusPacket(encPacket.decryptedPayload, packetStart, packetLength, out rc); // Resolve the command type of this packet IDaedalusCommandType commandType = decPacket.commandType; //IDaedalusCommandType commandType = DecryptedDaedalusPacket.commandTypes.Where(p => p.getCommandType() == decPacket.command).First(); // I don't really like passing the whole form as a parameter, but it was either that, a huge list of parameters, or a big switch statement here commandType.processAction(decPacket, this, packet.source); } } }
//#region AsyncComm delegates //public AsyncComm.ValidatePacketResponse ValidateOmegaPacketDelegate(byte[] packetData, uint packetLength, AsyncComm comm, IPEndPoint remoteEndPoint) //{ // bool isValid; // DaedalusProtocolPacket.ReturnCodes returnCode; // uint outPacketStart; // ushort outPacketLength; // Attempt to validate the incoming packet as an Omega protocol packet // isValid = DaedalusProtocolPacket.IsValidPacket(packetData, out returnCode, out outPacketStart, out outPacketLength); // return new AsyncComm.ValidatePacketResponse(isValid, outPacketStart, outPacketLength); //} //public void ReceivedOmegaPacketDelegate(byte[] packetData, AsyncComm comm, IPEndPoint remoteEndPoint) //{ // BeginInvoke(delAddToListBox, lstTraffic, "From: " + remoteEndPoint + ", server received packet: " + // Post this transaction to the UI // packetData.ToHexString("-")); //} //public void SocketCloseDelegate(SocketError socketEvent, AsyncComm comm, IPEndPoint remoteEndPoint) //{ // switch (socketEvent) // { // case SocketError.NotConnected: // BeginInvoke(delAddToListBox, lstTraffic, "From: " + remoteEndPoint + ", remote end closed socket."); // break; // case SocketError.ConnectionRefused: // BeginInvoke(delAddToListBox, lstTraffic, "From: " + remoteEndPoint + ", remote end refused connection."); // break; // case SocketError.ConnectionReset: // BeginInvoke(delAddToListBox, lstTraffic, "From: " + remoteEndPoint + ", remote end reset connection."); // break; // default: // BeginInvoke(delAddToListBox, lstTraffic, "From: " + remoteEndPoint + ", unknown socket event."); // comm.Dispose(); // break; // } //} //public void CommExceptionDelegate(Exception e, AsyncComm comm) //{ // BeginInvoke((Action)delegate() { lstTraffic.Items.Add(comm.ToString() + ": " + e.Message); }); //} //#endregion private void cmdDefinePacketPayload_Click(object sender, EventArgs e) { IDaedalusCommandType commandInterface = getDaedalusCommandTypeFromComboBox(cboProtocolCommand); byte[] payload; // If we were able to successfully get a payload value... if (commandInterface.showPayloadDefinitionForm(this, out payload)) { // Stick our payload into the UI Invoke((Action)(() => txtPacketPayload.Text = GlobalHelpers.GlobalMethods.BufferToHexString(payload, 0, payload.Length, " "))); } else { // Blank out the payload Invoke((Action)(() => txtPacketPayload.Text = "")); } }