public void HandleCommand(PacketEvent e, string input) { input = input.Substring(1); var arr = input.Split(' '); var name = arr[0]; foreach (var cmd in Commands) { CommandData data = null; foreach (var attr in cmd.GetType().GetCustomAttributes(false)) { if (attr is CommandData) { data = (CommandData)attr; } } if (data?.Name == name) { if (arr.Length == 1) { cmd.Execute(this, e, new string[] { }); } else { var args = new string[arr.Length - 1]; Array.Copy(arr, 1, args, 0, args.Length); cmd.Execute(this, e, args); } } } }
public void ProcessClientPacket(PacketEvent packetEvent) { if (IsEnabled && packetEvent.Id == 0x13) { packetEvent.Cancelled = true; } }
public bool Parse(PacketEvent packet) { DataBuffer rawInput = new DataBuffer(packet.GetData(), packet.GetLength()); DataBufferReader reader = new DataBufferReader(); int firstByte = reader.Read8(rawInput); this.version = firstByte >> 6; this.padding = ((firstByte >> 5 & 1) != 0); this.hasExtension = ((firstByte >> 4 & 1) != 0); this.csrcCount = firstByte & 0xF; int secondByte = reader.Read8(rawInput); this.marker = (secondByte & 0x80) == 0x80; this.payloadType = secondByte & 0x7f; this.SequenceNumber = reader.Read16(rawInput); this.timestamp = reader.ReadInteger(rawInput); this.ssrc = reader.ReadInteger(rawInput); int block3 = reader.Read8(rawInput); bool bflag = (block3 >> 7 & 1) != 0; bool jflag = ((block3 >> 6 & 1) & 0x1) != 0; bool zflag = ((block3 >> 5 & 1) & 0x1) != 0; bool pflag = ((block3 >> 4 & 1) & 0x1) != 0; int command_length = block3 & 0x7; this.payload = rawInput.Slice(rawInput.GetStreamPosition()); this.payload_length = rawInput.GetBytesLength() - rawInput.GetStreamPosition(); return(true); }
public bool Parse(PacketEvent packet) { this.valid = false; DataBuffer rawInput = new DataBuffer(packet.GetData(), packet.GetLength()); DataBufferReader reader = new DataBufferReader(); int protocol = reader.Read16(rawInput); if (protocol == 0xffff) { command = commandMap.GetValueOrDefault <int, AppleMIDICommand>(reader.Read16(rawInput)); switch (command) { case AppleMIDICommand.INVITATION: case AppleMIDICommand.INVITATION_ACCEPTED: case AppleMIDICommand.INVITATION_REJECTED: case AppleMIDICommand.END: this.valid = true; protocol_version = reader.ReadInteger(rawInput); initiator_token = reader.ReadInteger(rawInput); ssrc = reader.ReadInteger(rawInput); name = reader.ReadString(rawInput); // this.version = buffer.readUInt32BE(4); // this.token = buffer.readUInt32BE(8); // this.ssrc = buffer.readUInt32BE(12); // this.name = buffer.toString('utf-8', 16); break; case AppleMIDICommand.SYNCHRONIZATION: this.valid = true; ssrc = reader.ReadInteger(rawInput); count = reader.Read8(rawInput); padding = reader.Read24(rawInput); timestamp1 = reader.ReadUnsignedInteger64(rawInput); timestamp2 = reader.ReadUnsignedInteger64(rawInput); timestamp3 = reader.ReadUnsignedInteger64(rawInput); // this.ssrc = buffer.readUInt32BE(4, 8); // this.count = buffer.readUInt8(8); // this.padding = (buffer.readUInt8(9) << 0xF0) + buffer.readUInt16BE(10); // this.timestamp1 = buffer.slice(12, 20); //[buffer.readUInt32BE(12), buffer.readUInt32BE(16)]; // this.timestamp2 = buffer.slice(20, 28); //[buffer.readUInt32BE(20), buffer.readUInt32BE(24)]; // this.timestamp3 = buffer.slice(28, 36); //[buffer.readUInt32BE(28), buffer.readUInt32BE(32)]; break; case AppleMIDICommand.RECEIVER_FEEDBACK: this.valid = true; ssrc = reader.ReadInteger(rawInput); sequenceNumber = reader.Read16(rawInput); // this.ssrc = buffer.readUInt32BE(4, 8); // this.sequenceNumber = buffer.readUInt16BE(8); break; case AppleMIDICommand.BITRATE_RECEIVE_LIMIT: this.valid = true; break; } } return(valid); }
public PacketSentEvent(PacketEvent packetEvent) { this.PacketID = packetEvent.PacketID; this.Time = packetEvent.Time; this.Source = packetEvent.Source; this.Destination = packetEvent.Destination; this.Type = packetEvent.Type; }
public override void Execute(string[] args, DebugClient client) { if (!client.IsRunning) { client.SendPacket(new PacketRequest(DebugRequest.STEP, 0, 0, 0, 0, new byte[] { })); PacketEvent e = client.WaitForEvent(); Instruction ins = Instruction.Fetch(e.Argument0, e.Data); Console.WriteLine("Step 0x{0:X8}\t{1}", e.Argument0, ins.ToString()); } }
/// <summary> /// Registers a packet handler. This is NOT needed for an EncryptionStatus packet. /// </summary> /// <param name="id">The packet id.</param> /// <param name="handler">The handler for the packet.</param> public void RegisterPacketHandler(PacketId id, PacketEvent handler) { lock (eventLock) { try { EventHandler.Add(id, handler); } catch (Exception e) { throw e; } } }
public void ProcessServerPacket(PacketEvent packetEvent) { // Schritt 2: Wir wissen, dass das Velocity Packet vom Server kommt, also gehen wir in die // Methode "ProcessServerPacket" // Schritt 3: Wir brauchen nun die Id des Velocity Packets. Dazu haben wir die Protocol Spec. // Also, die Id ist 0x12. Dann prüfen wir jetzt nach dem Packet 0x12 if (packetEvent.Id == 0x12) { // Schritt 4: jetzt müssen wir das Packet "schlucken". Dazu müssen wir das PacketEvent abbrechen. packetEvent.Cancelled = true; } }
public override Task PassPacketEventAsync(byte packetId, PacketEvent evt, PacketEventType evtType) { var tasks = new List <Task>(); foreach (CSPlugin plugin in _plugins.Values) { tasks.Add(plugin.PacketEventManager.PassEventAsync(new PacketEventKey { EventType = evtType, PacketId = packetId }, evt)); } return(Task.WhenAll(tasks)); }
public override void Execute(string[] args, DebugClient client) { if (!client.IsRunning) { uint start = uint.Parse(args[1], System.Globalization.NumberStyles.AllowHexSpecifier); uint end = uint.Parse(args[1], System.Globalization.NumberStyles.AllowHexSpecifier); client.SendPacket(new PacketRequest(DebugRequest.READ, start, end, 0, 0, new byte[] { })); PacketEvent e = client.WaitForEvent(); using (BinaryReader br = new BinaryReader(new MemoryStream(e.Data))) { } } }
public void OnServerPacket(int id, PacketBuffer buf) { foreach (var proc in parent.PacketProcessors) { var e = new PacketEvent(this, id, buf); proc.ProcessServerPacket(e); buf = e.Buffer; if (e.Cancelled) { return; } } ProxyConnection.SendPacket(id, buf); }
public override void Execute(string[] args, DebugClient client) { if (!client.IsRunning) { client.SendPacket(new PacketRequest(DebugRequest.REGISTERS, 0, 0, 0, 0, new byte[] { })); PacketEvent e = client.WaitForEvent(); using (BinaryReader br = new BinaryReader(new MemoryStream(e.Data))) { while (br.BaseStream.Position < br.BaseStream.Length) { Console.WriteLine("{0} = 0x{1:X8}", br.ReadString().PadRight(4), br.ReadUInt32()); } } } }
private void Stop(Reason?closeReason) { var wasClosed = Interlocked.Exchange(ref closed, 1); if (wasClosed != 0) { return; } Log.Debug("Stopping PacketHandler {0}", closeReason); lock (sendLoopLock) { resendTimer?.Dispose(); socket?.Dispose(); PacketEvent = null; } StopEvent?.Invoke(closeReason); }
public void OnClientPacket(int id, PacketBuffer buf) { switch (proxyState) { case ProxyState.Handshake: if (id == 0x00) { HandleP00Handshake(buf.AsPacket <C00PacketHandshake>()); } break; case ProxyState.Login: if (id == 0x00) { HandleP00Login(buf.AsPacket <C00PacketLogin>()); } break; case ProxyState.Status: if (id == 0x00) { HandleP00StatusRequest(); } else if (id == 0x01) { HandleP01StatusPing(buf.AsPacket <SC01StatusPing>()); } break; case ProxyState.Established: foreach (var proc in parent.PacketProcessors) { var e = new PacketEvent(this, id, buf); proc.ProcessClientPacket(e); buf = e.Buffer; if (e.Cancelled) { return; } } TargetConnection.SendPacket(id, buf); break; } }
public bool ParseMessage(PacketEvent packet) { this.valid = false; Parse(packet); DataBufferReader reader = new DataBufferReader(); DataBuffer rawPayload = new DataBuffer(payload, payload_length); if (payload_length > 0) { message = rawPayload.GetBytes(); this.valid = true; // Log.Debug("MIDIMessage", "byte array:" + BitConverter.ToString(message).Replace("-", "")); return(true); } else { return(false); } }
public void Execute(CommandManager manager, PacketEvent e, string[] args) { manager.Processor.SendChat(e, "[§9TamperCraft§r] Help", S02ChatMessage.ChatPosition.Chat); foreach (var cmd in manager.Commands) { CommandData data = null; foreach (var attr in cmd.GetType().GetCustomAttributes(false)) { if (attr is CommandData) { data = (CommandData)attr; } } if (data != null) { manager.Processor.SendChat(e, $"[§9TamperCraft§r] {data.Name}: {data.Description}", S02ChatMessage.ChatPosition.Chat); } } }
public void ProcessClientPacket(PacketEvent packetEvent) { if (packetEvent.Id != 0x01) { return; } var str = packetEvent.Buffer.ReadString(); if (str.StartsWith(".")) { commandManager.HandleCommand(packetEvent, str); packetEvent.Cancelled = true; return; } var buf = new PacketBuffer(); buf.WriteString(str); buf.Reset(); packetEvent.Buffer = buf; }
public boolean parseMessage(PacketEvent packet) { this.valid = false; parse(packet); DataBufferReader reader = new DataBufferReader(); DataBuffer rawPayload = new DataBuffer(payload, payload_length); // payload should contain command + journal int block4 = reader.read8(rawPayload); channel_status = block4 >> 4; channel = block4 & 0xf; int block5 = reader.read8(rawPayload); note = block5 & 0x7f; int block6 = reader.read8(rawPayload); velocity = block6 & 0x7f; this.valid = true; Log.d("MIDIMessage", "cs:" + channel_status + " c:" + channel + " n:" + note + " v" + velocity); return(true); }
private void simRandomDeployMethod() { List <int> path; List <MarkingEvent> markingEventList = new List <MarkingEvent>(); //List<PacketEvent> packetEventList = new List<PacketEvent>(); //List<PacketSentEvent> packetSentEventList = new List<PacketSentEvent>(); List <int> firstMeetTracerHopCountList = new List <int>(); List <int> pathCountList = new List <int>(); Random rd = new Random(Guid.NewGuid().GetHashCode()); for (int i = 0; i < c_packetNumber; i++) { bool isMarking = false; NetworkTopology.Node srcNode = m_networkTopology.Nodes[rd.Next(m_networkTopology.Nodes.Count)]; NetworkTopology.Node desNode = null; while (desNode == null || desNode == srcNode) { desNode = m_networkTopology.Nodes[rd.Next(m_networkTopology.Nodes.Count)]; } path = m_networkTopology.GetShortestPath(srcNode.ID, desNode.ID); PacketEvent packetEvent = new PacketEvent() { PacketID = i, Source = srcNode.ID, Destination = desNode.ID, Time = 0, Type = NetworkTopology.NodeType.Attacker }; //packetEventList.Add(packetEvent); for (int j = 0; j < path.Count; j++) { switch (m_networkTopology.Nodes[m_networkTopology.NodeID2Index(path[j])].Tracer) { case NetworkTopology.TracerType.None: break; case NetworkTopology.TracerType.Marking: if (!isMarking) { MarkingEvent markingEvent = new MarkingEvent(packetEvent); markingEvent.MarkingNodeID = path[j]; firstMeetTracerHopCountList.Add(j); isMarking = true; markingEventList.Add(markingEvent); } break; case NetworkTopology.TracerType.Tunneling: break; case NetworkTopology.TracerType.Filtering: break; default: break; } //PacketSentEvent packetSentEvent = new PacketSentEvent(packetEvent); //packetSentEvent.CurrentNodeID = path[j]; //packetSentEvent.NextHopID = j == path.Count - 1 ? -1 : path[j + 1]; //packetSentEvent.Length = j == path.Count - 1 ? 0 : m_networkTopology.AdjacentMatrix[m_networkTopology.NodeID2Index(path[j]), m_networkTopology.NodeID2Index(path[j + 1])].Length; //packetSentEventList.Add(packetSentEvent); } pathCountList.Add(path.Count - 1); if (!isMarking) { firstMeetTracerHopCountList.Add(path.Count - 1); } } // Log into db double undetectedRatio = (double)(c_packetNumber - markingEventList.Count) / (double)c_packetNumber; double firstMeetTracerSearchingCost = (double)firstMeetTracerHopCountList.Sum() / (double)c_packetNumber; double savingCost = 0; double survivalTrafficRatio = (double)firstMeetTracerHopCountList.Sum() / (double)pathCountList.Sum(); for (int i = 0; i < c_packetNumber; i++) { savingCost += pathCountList[i] - firstMeetTracerHopCountList[i]; } savingCost /= c_packetNumber; string cmd; // UndetectedRatio cmd = "INSERT INTO UndetectedRatio(file_name, node_counts, edge_counts, diameter, k, n, metric_name, ratio) VALUES(@file_name, @node_counts, @edge_counts, @diameter, @k, @n, @metric_name, @ratio);"; m_sqlite_utils.RunCommnad(cmd, new List <SQLiteParameter>() { new SQLiteParameter("@file_name", m_networkTopology.FileName), new SQLiteParameter("@node_counts", m_networkTopology.Nodes.Count), new SQLiteParameter("@edge_counts", m_networkTopology.Edges.Count), new SQLiteParameter("@diameter", m_networkTopology.Diameter), new SQLiteParameter("@k", m_deployment.K), new SQLiteParameter("@n", m_deployment.N), new SQLiteParameter("@metric_name", "Random Deployment"), new SQLiteParameter("@ratio", undetectedRatio) }); // Searching Cost cmd = "INSERT INTO SearchingCost(file_name, node_counts, edge_counts, diameter, k, n, metric_name, ratio) VALUES(@file_name, @node_counts, @edge_counts, @diameter, @k, @n, @metric_name, @ratio);"; m_sqlite_utils.RunCommnad(cmd, new List <SQLiteParameter>() { new SQLiteParameter("@file_name", m_networkTopology.FileName), new SQLiteParameter("@node_counts", m_networkTopology.Nodes.Count), new SQLiteParameter("@edge_counts", m_networkTopology.Edges.Count), new SQLiteParameter("@diameter", m_networkTopology.Diameter), new SQLiteParameter("@k", m_deployment.K), new SQLiteParameter("@n", m_deployment.N), new SQLiteParameter("@metric_name", "Random Deployment - First Meet Tracer"), new SQLiteParameter("@ratio", firstMeetTracerSearchingCost) }); // Saving Cost cmd = "INSERT INTO SavingCost(file_name, node_counts, edge_counts, diameter, k, n, metric_name, ratio) VALUES(@file_name, @node_counts, @edge_counts, @diameter, @k, @n, @metric_name, @ratio);"; m_sqlite_utils.RunCommnad(cmd, new List <SQLiteParameter>() { new SQLiteParameter("@file_name", m_networkTopology.FileName), new SQLiteParameter("@node_counts", m_networkTopology.Nodes.Count), new SQLiteParameter("@edge_counts", m_networkTopology.Edges.Count), new SQLiteParameter("@diameter", m_networkTopology.Diameter), new SQLiteParameter("@k", m_deployment.K), new SQLiteParameter("@n", m_deployment.N), new SQLiteParameter("@metric_name", "Random Deployment"), new SQLiteParameter("@ratio", savingCost) }); // Survival Malicious Traffic Ratio cmd = "INSERT INTO SurvivalMaliciousTrafficRatio(file_name, node_counts, edge_counts, diameter, k, n, metric_name, ratio) VALUES(@file_name, @node_counts, @edge_counts, @diameter, @k, @n, @metric_name, @ratio);"; m_sqlite_utils.RunCommnad(cmd, new List <SQLiteParameter>() { new SQLiteParameter("@file_name", m_networkTopology.FileName), new SQLiteParameter("@node_counts", m_networkTopology.Nodes.Count), new SQLiteParameter("@edge_counts", m_networkTopology.Edges.Count), new SQLiteParameter("@diameter", m_networkTopology.Diameter), new SQLiteParameter("@k", m_deployment.K), new SQLiteParameter("@n", m_deployment.N), new SQLiteParameter("@metric_name", "Random Deployment"), new SQLiteParameter("@ratio", survivalTrafficRatio) }); }
public override void PassPacketEvent(byte packetId, PacketEvent evt, PacketEventType evtType) { PassPacketEventAsync(packetId, evt, evtType).Wait(); }
public EventHolder(PacketEvent packetEvent) : this() { EventBuffer[0] = (byte)packetEvent; }
public void ProcessServerPacket(PacketEvent packetEvent) { if (packetEvent.Id == 0x39) { } }
private void ProcessAllocations() { List <HeapEvent> events = null; lock (this) { if (lastFrameEvents == null) { return; } events = lastFrameEvents; lastFrameEvents = null; } int allocCount = 0; int allocSize = 0; int deallocCount = 0; Dictionary <int, int> countForSize = new Dictionary <int, int>(); foreach (HeapEvent ev in events) { // for now if (ev is DeallocateEvent) { deallocCount++; continue; } int size = 0; if (ev is AllocateEvent) { AllocateEvent allocEv = ev as AllocateEvent; size = allocEv.Size; } else if (ev is ReallocateEvent) { ReallocateEvent reallocEv = ev as ReallocateEvent; size = reallocEv.Size; } else { throw new NotImplementedException(); } int oldCount = 0; countForSize.TryGetValue(size, out oldCount); countForSize[size] = oldCount + 1; allocCount++; allocSize += size; } StringBuilder sb = new StringBuilder(); sb.AppendLine(); sb.AppendFormat("{0} allocations ({1} bytes), {2} deallocations\r\n", allocCount, allocSize, deallocCount); sb.AppendLine(); sb.AppendLine(" Size | Count"); sb.AppendLine("------------------"); int[] sizes = countForSize.Keys.ToArray(); Array.Sort(sizes); Array.Reverse(sizes); foreach (int size in sizes) { sb.AppendFormat("{0,7} | {1}\r\n", size, countForSize[size]); } sb.AppendLine(); sb.AppendLine("Events:"); sb.AppendLine("-------"); int count = 0; foreach (HeapEvent ev in events) { sb.AppendLine(ev.ToString()); count++; if (enableEntryLimit && count >= 100) { break; } } if (enableEntryLimit) { int remaining = events.Count - count; if (remaining > 0) { sb.AppendFormat("...and {0} more...\r\n", remaining); } } List <HeapEvent> leakedEvents = new List <HeapEvent>(); foreach (HeapEvent ev in events) { UIntPtr removePtr = UIntPtr.Zero; if (ev is AllocateEvent) { AllocateEvent allocEv = ev as AllocateEvent; if (allocEv.Address != UIntPtr.Zero) { leakedEvents.Add(allocEv); } } else if (ev is ReallocateEvent) { ReallocateEvent reallocEv = ev as ReallocateEvent; if (reallocEv.NewAddress != UIntPtr.Zero) { if (reallocEv.OldAddress != UIntPtr.Zero) { if (reallocEv.NewAddress == reallocEv.OldAddress) { // no change // FIXME: in case we missed the original malloc we could get it here... } else { // relocated leakedEvents.Add(reallocEv); removePtr = reallocEv.OldAddress; } } else { // new event leakedEvents.Add(reallocEv); } } else if (reallocEv.OldAddress != UIntPtr.Zero && reallocEv.Size == 0) { // free removePtr = reallocEv.OldAddress; } } else if (ev is DeallocateEvent) { DeallocateEvent deallocEv = ev as DeallocateEvent; removePtr = deallocEv.Address; } else { throw new NotImplementedException(); } if (removePtr != UIntPtr.Zero) { bool again = false; do { again = false; foreach (HeapEvent leakEv in leakedEvents) { UIntPtr address; if (leakEv is AllocateEvent) { address = (leakEv as AllocateEvent).Address; } else if (leakEv is ReallocateEvent) { address = (leakEv as ReallocateEvent).NewAddress; } else { throw new NotImplementedException("Should not get here"); } if (address == removePtr) { leakedEvents.Remove(leakEv); again = true; break; } } }while (again); } } if (leakedEvents.Count > 0) { sb.AppendLine(); sb.AppendLine("Possible leaks:"); sb.AppendLine("---------------"); foreach (HeapEvent ev in leakedEvents) { sb.AppendLine(ev.ToString()); } } Event.InvocationOrigin origin = new Event.InvocationOrigin("HeapAgent", null, 42); PacketEvent pktEv = new PacketEvent(eventCoordinator, origin); pktEv.Data = Encoding.UTF8.GetBytes(sb.ToString()); manager.Submit(new Event[] { pktEv }); }
public void Execute(CommandManager manager, PacketEvent e, string[] args) { FlightProcessor.IsEnabled = !FlightProcessor.IsEnabled; manager.Processor.SendChat(e, $"Flying {(FlightProcessor.IsEnabled ? "enabled" : "disabled")}", S02ChatMessage.ChatPosition.Chat); //e.Client.ProxyConnection }
public EnOceanFrameLayer() { // Queue.Synchronized() // Queue<PacketEvent> // PacketEventHandler += (EnOceanPacket p) => { Console.WriteLine(" PKT HANDLER"); }; // TESTING PacketEventHandler += (EnOceanPacket p) => { // Console.WriteLine(" PKT HANDLER 2"); foreach (var listener in PacketListeners) { if (listener.handler(p)) { listener.succeeded = true; listener.waitHandle.Set(); } } }; }
public bool LoadReplay(string FileName) { #region Deny if already loading! if (Loading) { Debug.WriteLine("Failure to load YSFlight Replay (Already Loading! Can't Dual Process!)"); return(false); } #endregion #region Deny if already loaded! if (Loaded) { Debug.WriteLine("Failure to load YSFlight Replay (Already Loaded! Can't OverWrite!)"); return(false); } #endregion #region Deny if file not found! if (!Files.FileExists(FileName)) { Debug.WriteLine("Failure to load YSFlight Replay (File Not Found):\n " + FileName); return(false); } #endregion #region load records to buffer string[] Contents = Files.FileReadAllLines(FileName); #endregion #region clear the records, ready to write to. CurrentTime = 0; Records.Clear(); #endregion Console.WriteLine("&eLoading Replay..."); Loading = true; Threads.Add(() => { string Mode = "NONE"; #region Aircraft Data string CurrentAC_Identify = "NULL"; uint CurrentAC_ID = 0; uint CurrentAC_IFF = 0; float CurrentAC_Fuel = 100; string CurrentAC_Tag = "Replay"; #endregion for (int CurrentLineNumber = 0; CurrentLineNumber < Contents.Length; CurrentLineNumber++) { #region prepare variables string ThisLine = Contents[CurrentLineNumber]; string Keyword = ThisLine; string Arguments = ""; if (Keyword.Contains(' ')) { Arguments = Keyword.Split(new char[] { ' ' }, 2)[1]; Keyword = Keyword.Split(' ')[0].ToUpperInvariant(); } #endregion #region No Aircraft at the moment. if (Mode == "NONE") { if (Keyword == "AIRPLANE") { Mode = "AIRPLANE"; CurrentAC_ID = World.Objects.GetNextID() | 256 * 256; AircraftIDs.Add(CurrentAC_ID); if (ThisLine.Contains(' ')) { CurrentAC_Identify = ThisLine.Split(' ')[1]; } continue; } } #endregion #region Working on an aircraft. if (Mode == "AIRPLANE") { #region get IFF if (Keyword == "IDENTIFY") { UInt32.TryParse(Arguments, out CurrentAC_IFF); continue; } #endregion #region get Tag if (Keyword == "IDANDTAG") { if (Arguments.Contains(' ')) { CurrentAC_Tag = Arguments.Split(new char[] { ' ' }, 2)[1]; if (CurrentAC_Tag == "\"\"") { CurrentAC_Tag = "Replay"; } continue; } } #endregion #region get airpcmnd if (Keyword == "AIRPCMND") { if (Arguments.Contains(' ')) { string[] SubArguments = Arguments.Split(' '); #region get fuel if (SubArguments.Length > 1) { try { if (SubArguments[0].ToUpperInvariant() == "INITFUEL") { try { CurrentAC_Fuel = (float)MetaData._Aircraft.FindByName(CurrentAC_Identify).Cache().WEIGFUEL; } catch { Debug.WriteLine("Failed to set default fuel!"); } try { CurrentAC_Fuel = CurrentAC_Fuel / 100 * UInt32.Parse(SubArguments[1].Split('%')[0]); } catch { Debug.WriteLine("Failed to load fuel: " + ThisLine); } } } catch { Debug.WriteLine("Failed to process AIRPCMND: " + ThisLine); } } #endregion continue; } } #endregion #region process flight records. if (Keyword == "NUMRECOR") { int RecordsCount = 0; if (Arguments.Contains(' ')) { Int32.TryParse(Arguments.Split(' ')[0], out RecordsCount); } CurrentLineNumber++; List <Packets.Packet_11_FlightData> ThisAircraftFlightDataRecords = new List <Packets.Packet_11_FlightData>(); for (int i = 0; i < RecordsCount; i++) { string[] RecordContents = new string[4]; try { RecordContents[0] = Contents[CurrentLineNumber]; RecordContents[1] = Contents[CurrentLineNumber + 1]; RecordContents[2] = Contents[CurrentLineNumber + 2]; RecordContents[3] = Contents[CurrentLineNumber + 3]; } catch { Debug.WriteLine("Error reading lines for YSF Record!"); continue; } CurrentLineNumber += 4; PacketEvent ThisPacketEvent = ProcessYSFlightAircraftRecord(RecordContents, CurrentAC_ID); Packets.Packet_11_FlightData FlightData = new Packets.Packet_11_FlightData(ThisPacketEvent.Packet); FlightData.Weight_Fuel = CurrentAC_Fuel; FlightData.Weight_SmokeOil = 100; FlightData.Weight_Payload = 0; #region spawn the aircraft if (i == 0) { //first event, need to add a creation packet! Packets.Packet_05_EntityJoined EntityJoined = new Packets.Packet_05_EntityJoined(); EntityJoined.ID = CurrentAC_ID; EntityJoined.IFF = CurrentAC_IFF; EntityJoined.PosX = FlightData.PosX; EntityJoined.PosY = FlightData.PosY; EntityJoined.PosZ = FlightData.PosZ; EntityJoined.RotX = (float)(FlightData.HdgX / 32767 * Math.PI); EntityJoined.RotY = (float)(FlightData.HdgY / 32767 * Math.PI); EntityJoined.RotZ = (float)(FlightData.HdgZ / 32767 * Math.PI); EntityJoined.Identify = CurrentAC_Identify; EntityJoined.OwnerName = CurrentAC_Tag; EntityJoined.IsOwnedByThisPlayer = false; EntityJoined.IsOwnedByOtherPlayer = true; EntityJoined.IsAircraft = true; Records.Add(new PacketEvent(FlightData.TimeStamp, EntityJoined)); } #endregion if (i > 0) { Packets.Packet_11_FlightData PrevFlightData = ThisAircraftFlightDataRecords.ToArray()[i - 1]; float TimeDifference = FlightData.TimeStamp - PrevFlightData.TimeStamp; float ScalingFactor = 1f / TimeDifference; //short _X_Left = (ushort)FlightData.HdgX - (ushort)ThisAircraftFlightDataRecords.ToArray()[i - 1].HdgX; //350-010 = 340; //010-350 = -340 //short _X_Right = (ushort)ThisAircraftFlightDataRecords.ToArray()[i - 1].HdgX - (ushort)FlightData.HdgX; // float ChangeYDeg = Numbers.AngleAcuteDifference(FlightData.HdgX.ToDegrees(), PrevFlightData.HdgX.ToDegrees()); float ChangeXDeg = Numbers.AngleAcuteDifference(FlightData.HdgY.ToDegrees(), PrevFlightData.HdgY.ToDegrees()); float ChangeZDeg = Numbers.AngleAcuteDifference(FlightData.HdgZ.ToDegrees(), PrevFlightData.HdgZ.ToDegrees()); //FlightData.V_HdgX = (float)(ChangeXDeg * ScalingFactor / 180 * Math.PI); //FlightData.V_HdgY = (float)(ChangeYDeg * ScalingFactor / 180 * Math.PI); //FlightData.V_HdgZ = (float)(ChangeZDeg * ScalingFactor / 180 * Math.PI); //FlightData.V_HdgX = 0; //FlightData.V_HdgY = 2; //FlightData.V_HdgZ = 0; FlightData.V_PosX = (short)((FlightData.PosX - PrevFlightData.PosX) * ScalingFactor * 10); FlightData.V_PosY = (short)((FlightData.PosY - PrevFlightData.PosY) * ScalingFactor * 10); FlightData.V_PosZ = (short)((FlightData.PosZ - PrevFlightData.PosZ) * ScalingFactor * 10); } ThisPacketEvent.Packet = FlightData; Records.Add(ThisPacketEvent); ThisAircraftFlightDataRecords.Add(FlightData); #region despawn the aircraft if (i == RecordsCount - 1) { //Last record, need to destory the aircraft now! Packets.Packet_13_RemoveAirplane RemoveACPacket = new Packets.Packet_13_RemoveAirplane(CurrentAC_ID); Records.Add(new PacketEvent(FlightData.TimeStamp, RemoveACPacket)); } continue; #endregion } Mode = "NONE"; CurrentLineNumber--; } #endregion } #endregion } Loaded = true; Loading = false; Console.WriteLine("&aLoaded Replay."); }, "Replay Loader: " + FileName); return(true); }
public void SendChat(PacketEvent e, string message, ChatPosition pos) { e.Client.ProxyConnection.SendPacket(new S02ChatMessage(Chat.BuildMessage(message), pos)); }
private void simSpecificDeployMethod() { int centerID, minE; List <int> path; List <MarkingEvent> markingEventList = new List <MarkingEvent>(); //List<PacketEvent> packetEventList = new List<PacketEvent>(); //List<PacketSentEvent> packetSentEventList = new List<PacketSentEvent>(); List <int> firstMeetTracerHopCountList = new List <int>(); List <int> srcToScopeCenterHopCountList = new List <int>(); List <int> attackerAreaCounts = new List <int>(); List <int> pathCountList = new List <int>(); Random rd = new Random(Guid.NewGuid().GetHashCode()); for (int i = 0; i < c_packetNumber; i++) { bool isMarking = false; NetworkTopology.Node srcNode = m_networkTopology.Nodes[rd.Next(m_networkTopology.Nodes.Count)]; NetworkTopology.Node desNode = null; while (desNode == null || desNode == srcNode) { desNode = m_networkTopology.Nodes[rd.Next(m_networkTopology.Nodes.Count)]; } NetworkTopology sourceScope = m_deployment.AllRoundScopeList.Find(scope => scope.Nodes.Exists(n => n.ID == srcNode.ID)); if (sourceScope != null) { if (sourceScope.FindCenterNodeID(out centerID, out minE) && srcNode.ID != centerID) { srcToScopeCenterHopCountList.Add(m_networkTopology.GetShortestPathCount(srcNode.ID, centerID) - 1); } else { srcToScopeCenterHopCountList.Add(0); } attackerAreaCounts.Add(sourceScope.Nodes.Count); } else { srcToScopeCenterHopCountList.Add(0); attackerAreaCounts.Add(0); } path = m_networkTopology.GetShortestPath(srcNode.ID, desNode.ID); PacketEvent packetEvent = new PacketEvent() { PacketID = i, Source = srcNode.ID, Destination = desNode.ID, Time = 0, Type = NetworkTopology.NodeType.Attacker }; //packetEventList.Add(packetEvent); for (int j = 0; j < path.Count; j++) { switch (m_networkTopology.Nodes[m_networkTopology.NodeID2Index(path[j])].Tracer) { case NetworkTopology.TracerType.None: break; case NetworkTopology.TracerType.Marking: if (!isMarking) { MarkingEvent markingEvent = new MarkingEvent(packetEvent); markingEvent.MarkingNodeID = path[j]; firstMeetTracerHopCountList.Add(j); isMarking = true; markingEventList.Add(markingEvent); } break; case NetworkTopology.TracerType.Tunneling: break; case NetworkTopology.TracerType.Filtering: break; default: break; } //PacketSentEvent packetSentEvent = new PacketSentEvent(packetEvent); //packetSentEvent.CurrentNodeID = path[j]; //packetSentEvent.NextHopID = j == path.Count - 1 ? -1 : path[j + 1]; //packetSentEvent.Length = j == path.Count - 1 ? 0 : m_networkTopology.AdjacentMatrix[m_networkTopology.NodeID2Index(path[j]), m_networkTopology.NodeID2Index(path[j + 1])].Length; //packetSentEventList.Add(packetSentEvent); } pathCountList.Add(path.Count - 1); if (!isMarking) { firstMeetTracerHopCountList.Add(path.Count - 1); } } m_networkTopology.Reset(); // Log into db double theoreticalUndetectedRatio = (double)m_deployment.AllRoundScopeList.Sum(s => s.Nodes.Count > 1 ? DataUtility.Combination(s.Nodes.Count, 2) : 0) / (double)DataUtility.Combination(m_networkTopology.Nodes.Count, 2); double upperboundUndetectedRatio = m_networkTopology.m_prob_hop.Sum(i => (m_networkTopology.m_prob_hop.ToList().IndexOf(i) >= 1 && m_networkTopology.m_prob_hop.ToList().IndexOf(i) <= m_deployment.K - 1) ? i : 0); double undetectedRatio = (double)(c_packetNumber - markingEventList.Count) / (double)c_packetNumber; double firstMeetTracerSearchingCost = (double)firstMeetTracerHopCountList.Sum() / (double)c_packetNumber; double srcToScopeCenterSearchingCost = (double)srcToScopeCenterHopCountList.Sum() / (double)c_packetNumber; double attackerScopeCountSearchingCost = attackerAreaCounts.Average(); double savingCost = 0; double survivalTrafficRatio = (double)firstMeetTracerHopCountList.Sum() / (double)pathCountList.Sum(); for (int i = 0; i < c_packetNumber; i++) { savingCost += pathCountList[i] - firstMeetTracerHopCountList[i]; } savingCost /= c_packetNumber; string cmd; // UndetectedRatio cmd = "INSERT INTO UndetectedRatio(file_name, node_counts, edge_counts, diameter, k, n, metric_name, ratio) VALUES(@file_name, @node_counts, @edge_counts, @diameter, @k, @n, @metric_name, @ratio);"; m_sqlite_utils.RunCommnad(cmd, new List <SQLiteParameter>() { new SQLiteParameter("@file_name", m_networkTopology.FileName), new SQLiteParameter("@node_counts", m_networkTopology.Nodes.Count), new SQLiteParameter("@edge_counts", m_networkTopology.Edges.Count), new SQLiteParameter("@diameter", m_networkTopology.Diameter), new SQLiteParameter("@k", m_deployment.K), new SQLiteParameter("@n", m_deployment.N), new SQLiteParameter("@metric_name", "K-Cut Deployment"), new SQLiteParameter("@ratio", undetectedRatio) }); cmd = "INSERT INTO UndetectedRatio(file_name, node_counts, edge_counts, diameter, k, n, metric_name, ratio) VALUES(@file_name, @node_counts, @edge_counts, @diameter, @k, @n, @metric_name, @ratio);"; m_sqlite_utils.RunCommnad(cmd, new List <SQLiteParameter>() { new SQLiteParameter("@file_name", m_networkTopology.FileName), new SQLiteParameter("@node_counts", m_networkTopology.Nodes.Count), new SQLiteParameter("@edge_counts", m_networkTopology.Edges.Count), new SQLiteParameter("@diameter", m_networkTopology.Diameter), new SQLiteParameter("@k", m_deployment.K), new SQLiteParameter("@n", m_deployment.N), new SQLiteParameter("@metric_name", "Theoretical Undetected Ratio"), new SQLiteParameter("@ratio", theoreticalUndetectedRatio) }); cmd = "INSERT INTO UndetectedRatio(file_name, node_counts, edge_counts, diameter, k, n, metric_name, ratio) VALUES(@file_name, @node_counts, @edge_counts, @diameter, @k, @n, @metric_name, @ratio);"; m_sqlite_utils.RunCommnad(cmd, new List <SQLiteParameter>() { new SQLiteParameter("@file_name", m_networkTopology.FileName), new SQLiteParameter("@node_counts", m_networkTopology.Nodes.Count), new SQLiteParameter("@edge_counts", m_networkTopology.Edges.Count), new SQLiteParameter("@diameter", m_networkTopology.Diameter), new SQLiteParameter("@k", m_deployment.K), new SQLiteParameter("@n", m_deployment.N), new SQLiteParameter("@metric_name", "Theoretical Undetected Ratio Upper Bound"), new SQLiteParameter("@ratio", upperboundUndetectedRatio) }); // Searching Cost cmd = "INSERT INTO SearchingCost(file_name, node_counts, edge_counts, diameter, k, n, metric_name, ratio) VALUES(@file_name, @node_counts, @edge_counts, @diameter, @k, @n, @metric_name, @ratio);"; m_sqlite_utils.RunCommnad(cmd, new List <SQLiteParameter>() { new SQLiteParameter("@file_name", m_networkTopology.FileName), new SQLiteParameter("@node_counts", m_networkTopology.Nodes.Count), new SQLiteParameter("@edge_counts", m_networkTopology.Edges.Count), new SQLiteParameter("@diameter", m_networkTopology.Diameter), new SQLiteParameter("@k", m_deployment.K), new SQLiteParameter("@n", m_deployment.N), new SQLiteParameter("@metric_name", "K-Cut Deployment - First Meet Tracer"), new SQLiteParameter("@ratio", firstMeetTracerSearchingCost) }); cmd = "INSERT INTO SearchingCost(file_name, node_counts, edge_counts, diameter, k, n, metric_name, ratio) VALUES(@file_name, @node_counts, @edge_counts, @diameter, @k, @n, @metric_name, @ratio);"; m_sqlite_utils.RunCommnad(cmd, new List <SQLiteParameter>() { new SQLiteParameter("@file_name", m_networkTopology.FileName), new SQLiteParameter("@node_counts", m_networkTopology.Nodes.Count), new SQLiteParameter("@edge_counts", m_networkTopology.Edges.Count), new SQLiteParameter("@diameter", m_networkTopology.Diameter), new SQLiteParameter("@k", m_deployment.K), new SQLiteParameter("@n", m_deployment.N), new SQLiteParameter("@metric_name", @"K-Cut Deployment - Attacker to Scope Center"), new SQLiteParameter("@ratio", srcToScopeCenterSearchingCost) }); cmd = "INSERT INTO SearchingCost(file_name, node_counts, edge_counts, diameter, k, n, metric_name, ratio) VALUES(@file_name, @node_counts, @edge_counts, @diameter, @k, @n, @metric_name, @ratio);"; m_sqlite_utils.RunCommnad(cmd, new List <SQLiteParameter>() { new SQLiteParameter("@file_name", m_networkTopology.FileName), new SQLiteParameter("@node_counts", m_networkTopology.Nodes.Count), new SQLiteParameter("@edge_counts", m_networkTopology.Edges.Count), new SQLiteParameter("@diameter", m_networkTopology.Diameter), new SQLiteParameter("@k", m_deployment.K), new SQLiteParameter("@n", m_deployment.N), new SQLiteParameter("@metric_name", @"K-Cut Deployment - The Number of Nodes in Attacker Area"), new SQLiteParameter("@ratio", attackerScopeCountSearchingCost) }); // Saving Cost cmd = "INSERT INTO SavingCost(file_name, node_counts, edge_counts, diameter, k, n, metric_name, ratio) VALUES(@file_name, @node_counts, @edge_counts, @diameter, @k, @n, @metric_name, @ratio);"; m_sqlite_utils.RunCommnad(cmd, new List <SQLiteParameter>() { new SQLiteParameter("@file_name", m_networkTopology.FileName), new SQLiteParameter("@node_counts", m_networkTopology.Nodes.Count), new SQLiteParameter("@edge_counts", m_networkTopology.Edges.Count), new SQLiteParameter("@diameter", m_networkTopology.Diameter), new SQLiteParameter("@k", m_deployment.K), new SQLiteParameter("@n", m_deployment.N), new SQLiteParameter("@metric_name", "K-Cut Deployment"), new SQLiteParameter("@ratio", savingCost) }); // Survival Malicious Traffic Ratio cmd = "INSERT INTO SurvivalMaliciousTrafficRatio(file_name, node_counts, edge_counts, diameter, k, n, metric_name, ratio) VALUES(@file_name, @node_counts, @edge_counts, @diameter, @k, @n, @metric_name, @ratio);"; m_sqlite_utils.RunCommnad(cmd, new List <SQLiteParameter>() { new SQLiteParameter("@file_name", m_networkTopology.FileName), new SQLiteParameter("@node_counts", m_networkTopology.Nodes.Count), new SQLiteParameter("@edge_counts", m_networkTopology.Edges.Count), new SQLiteParameter("@diameter", m_networkTopology.Diameter), new SQLiteParameter("@k", m_deployment.K), new SQLiteParameter("@n", m_deployment.N), new SQLiteParameter("@metric_name", "K-Cut Deployment"), new SQLiteParameter("@ratio", survivalTrafficRatio) }); }
public void ProcessClientPacket(PacketEvent packetEvent) { }
public void ProcessServerPacket(PacketEvent packetEvent) { }
public abstract Task PassPacketEventAsync(byte packetId, PacketEvent evt, PacketEventType evtType);