/// <summary> /// Constructor. Common to all inheriting packet types. /// </summary> /// <param name="Creator"></param> /// <param name="DataPacket"></param> public Packet_44_AircraftList(GenericPacket DataPacket) : base() //base == parent. ie: create the parent with this argument. { base.Type = 44; base.Data = DataPacket.Data; if (Data.Length < 4) { throw new PacketCreationException("Data.Length < 4"); } }
/// <summary> /// Constructor. Common to all inheriting packet types. /// </summary> /// <param name="Creator"></param> /// <param name="DataPacket"></param> public Packet_20_OrdinanceLaunch(GenericPacket DataPacket) : base() //base == parent. ie: create the parent with this argument. { base.Type = 20; base.Data = DataPacket.Data; if (Data.Length < 44) { throw new PacketCreationException("Data.Length < 44"); } }
/// <summary> /// Constructor. Common to all inheriting packet types. /// </summary> /// <param name="Creator"></param> /// <param name="DataPacket"></param> public Packet_11_FlightData(GenericPacket DataPacket) : base() //base == parent. ie: create the parent with this argument. { base.Type = 11; base.Data = DataPacket.Data; if (Data.Length < 12) { throw new PacketCreationException("Data Length < 12"); } }
/// <summary> /// Constructor. Common to all inheriting packet types. /// </summary> /// <param name="Creator"></param> /// <param name="DataPacket"></param> public Packet_31_MissilesOption(GenericPacket DataPacket) : base() //base == parent. ie: create the parent with this argument. { base.Type = 31; base.Data = DataPacket.Data; if (Data.Length < 4) { throw new PacketCreationException("Data.Length < 4"); } }
/// <summary> /// Constructor. Common to all inheriting packet types. /// </summary> /// <param name="Creator"></param> /// <param name="DataPacket"></param> public Packet_32_ChatMessage(GenericPacket DataPacket) : base() //base == parent. ie: create the parent with this argument. { base.Type = 32; base.Data = DataPacket.Data; if (Data.Length < 8) { throw new PacketCreationException("Data.Length < 8"); } }
/// <summary> /// Constructor. Common to all inheriting packet types. /// </summary> /// <param name="Creator"></param> /// <param name="DataPacket"></param> public Packet_64_29_OpenYS_Handshake(GenericPacket DataPacket) : base() //base == parent. ie: create the parent with this argument. { base.Type = 29; base.Data = DataPacket.Data; if (Data.Length < 4) { throw new PacketCreationException("Data.Length < 4"); } }
/// <summary> /// Constructor. Common to all inheriting packet types. /// </summary> /// <param name="Creator"></param> /// <param name="DataPacket"></param> public Packet_13_RemoveAirplane(GenericPacket DataPacket) : base() //base == parent. ie: create the parent with this argument. { base.Type = 13; base.Data = DataPacket.Data; if (Data.Length < 4) { throw new PacketCreationException("Data.Length < 4"); } }
/// <summary> /// Constructor. Common to all inheriting packet types. /// </summary> /// <param name="Creator"></param> /// <param name="DataPacket"></param> public Packet_05_EntityJoined(GenericPacket DataPacket) : base() //base == parent. ie: create the parent with this argument. { base.Type = 5; base.Data = DataPacket.Data; if (Data.Length < 60) { throw new PacketCreationException("Packet Length < 60"); } }
/// <summary> /// Enqueues a packet to be sent out the wire /// </summary> /// <param name="packet"></param> internal virtual void SendPacket(GenericPacket packet) { TimestampedPacket tsp = new TimestampedPacket(); tsp.packet = packet; tsp.lastTransmissionTime = Int32.MinValue; tsp.retransmissionCount = 0; tsp.timedOut = false; SendTimestampedPacket(tsp); }
protected override void OnReceivePacket(IPeer peer, object obj, Reliability reliability) { GenericPacket packet = obj as GenericPacket; if (packet != null) { if (groups.TryGetValue(packet.InstCode, out IPeerGroup group)) { group.AddEvent(peer, packet.Data, reliability); } } }
static void Main() { XDef.Test(); PacketExts.Test(); GenericPacket.Test(); Pro.LoadFromDirectory(Application.StartupPath); XRay.BuilderVersion = Assembly.GetEntryAssembly().GetName().Version.ToString(); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new MainForm()); }
/// <summary> /// Ensure that the packet can be handled in order. /// </summary> /// <returns><c>true</c>, if packet was handled, <c>false</c> otherwise.</returns> /// <param name="packet">Packet.</param> internal bool CheckPacket(GenericPacket packet) { if (packet.Ack != 0) { this.Acked(packet.Ack); } if (lastSeqNum + 1 == packet.Seq) { lastSeqNum = packet.Seq; return(true); } return(false); }
public void Send(int operationCode, object data, Reliability reliability) { if (TryGetGroupId(operationCode, out int groupId)) { GenericPacket packet = new GenericPacket(); packet.InstCode = groupId; packet.Data = data; peer.Send(packet, reliability); } else { debugger.LogError("Cannot find group id."); } }
/// <summary> /// Constructor. Common to all inheriting packet types. /// </summary> /// <param name="Creator"></param> /// <param name="DataPacket"></param> public Packet_64_11_FormationData(GenericPacket DataPacket) : base() //base == parent. ie: create the parent with this argument. { base.Type = 11; if (DataPacket.Data.Length == 0) { DataPacket.Data = new byte[52]; } base.Data = DataPacket.Data; if (Data.Length < 16) { throw new PacketCreationException("Data.Length < 16"); } }
/* Deprecated * public static void Analyse(this GenericPacket ThisPacket) * { * Console.Locked = true; * System.Console.SetCursorPosition(0, 0); * System.Console.BackgroundColor = ConsoleColor.Red; * string output = "ANALYSING PACKET OF SIZE: " + ThisPacket.Size.ToString() + " AND TYPE: " + ThisPacket.Type + "."; * System.Console.Write(output + Utilities.StringRepeat(" ", System.Console.WindowWidth - output.Length)); * System.Console.BackgroundColor = ConsoleColor.Black; * Console.ConsoleHandler(ThisPacket.Data.ToColoredDebugHexString()); * int x = System.Console.CursorLeft; * int y = System.Console.CursorTop; * System.Console.WriteLine(Utilities.StringRepeat(" ", 1024)); * System.Console.CursorTop = y; * System.Console.CursorLeft = x; * Console.Locked = false; * } */ public static string Compare(GenericPacket Packet1, GenericPacket Packet2) { List <string> output = new List <string>(); if (Packet1.Type != Packet2.Type) { output.Add("&ePackets are Different Types"); } if (Packet1.Data.Length != Packet2.Data.Length) { output.Add("&ePackets are Different Lengths"); } else { output.Add("&aBegin Comparison"); int matching = 0; int error = 0; for (int i = 0; i < Packet1.Data.Length; i++) { if (Packet1.Data[i] != Packet2.Data[i]) { error++; output.Add("&e-Packets differ at byte[" + i + "]."); output.Add("&b--Packet1: " + Packet1.Data[i].ToString()); output.Add("&d--Packet2: " + Packet2.Data[i].ToString()); } else { matching++; } } output.Add("&c-Total Matches: " + matching); output.Add("&c-Total Errors: " + error); output.Add("&aEnd Comparison"); } string outputfinal = ""; foreach (string ThisString in output) { if (outputfinal.Length > 0) { outputfinal += "\n"; } outputfinal += ThisString; } return(outputfinal); }
internal bool SendPacket(GenericPacket p, TunnelCongestionControllerMock to) { if (random.Next(0, 100) < lossPercentage) { //drop the packet Console.WriteLine("DROPPING packet Seq#" + p.Seq); return(false); } else { //send the packet if (this.delayOn) { Thread.Sleep(delayLength); } to.HandleIncomingPacket(p); return(true); } }
/// <summary> /// Enqueues the send GenericPacket on the send queue. /// </summary> /// <param name="p">P.</param> public virtual void SendPacket(GenericPacket p) { byte[] buffer = p.ToBytes(); this.socket.BeginSendTo(buffer, 0, buffer.Length, SocketFlags.None, p.destination, new AsyncCallback(OnPacketSent), p); /*this.socket.BeginSend (buffer, * 0, * buffer.Length, * SocketFlags.None, * new AsyncCallback (OnPacketSent), * p);*/ }
public void ExpandField(string fieldFilter = null) { if (!XRay.RemoteViewer) { return; } if (XRay.Remote == null || XRay.Remote.ServerConnection == null) { return; } // send request for grid info to remote client var packet = new GenericPacket("RequestField"); packet.Data = new Dictionary <string, string>(); packet.Data["ThreadID"] = Thread.CurrentThread.ManagedThreadId.ToString(); packet.Data["FieldID"] = ID.ToString(); XRay.RunInCoreAsync(() => XRay.Remote.ServerConnection.SendPacket(packet)); }
private void OnClientReceivePacketEvent(object obj, Reliability reliability) { GenericPacket packet = obj as GenericPacket; if (packet != null) { if (receivers.TryGetValue(packet.InstCode, out List <IPacketReceiver> receiverList)) { try { foreach (var receiver in receiverList) { receiver.Receive(packet.Data); } } catch (Exception e) { debugger.LogError(e.Message + e.StackTrace); } } if (actions.TryGetValue(packet.InstCode, out List <Action <object> > actionList)) { foreach (var action in actionList) { try { action.Invoke(packet.Data); } catch (Exception e) { debugger.Log(e.Message + e.StackTrace); } } } } else { debugger.Log("Packet is null."); } }
internal new bool CheckPacket(GenericPacket p) { //no congestion control always returns true for the check packet return(true); }
/// <summary> /// Overriding the base implementation to prevent the queues from growing /// </summary> /// <param name="packet"></param> internal override void SendPacket(GenericPacket packet) { this.packetSender.SendPacket(packet); }
public static byte[] Switcher(Packet p) { PacketType type; Packet packet; switch (p.ID) { case (ushort)PacketType.ClientSendMessage: type = PacketType.ClientSendMessage; packet = AcceptMessage(p); break; case (ushort)PacketType.ClientRequestChannelList: type = PacketType.ServerAcknowledgementRequestChannelList; packet = ClientRequestChannelList(p); break; case (ushort)PacketType.ClientRequestChat: type = PacketType.ServerAcknowledgementRequestChat; packet = CreateChat(p); break; case (ushort)PacketType.ClientAccountLogin: type = PacketType.ServerAcknowledgementLogin; packet = UserAuthentification(p); break; case (ushort)PacketType.ClientAccountRegister: type = PacketType.ServerAcknowledgementRegister; packet = UserRegistration(p); break; case (ushort)PacketType.ClientAccountLogout: type = PacketType.ServerAcknowledgementLogout; packet = UserLogout(p); break; case (ushort)PacketType.ClientConnection: type = PacketType.ServerAcknowledgementConnection; packet = ClientConnection(p); break; case (ushort)PacketType.ClientDisconnection: type = PacketType.ServerAcknowledgementDisconnection; packet = ClientDisconnection(p); break; case (ushort)PacketType.ClientRequestChannelAccess: type = PacketType.ServerAcknowledgementRequestChannelAccess; packet = RequestChannelAccess(p); break; case (ushort)PacketType.ClientRequestCreateChannel: type = PacketType.ServerAcknowledgementCreateChannel; packet = CreateChannel(p); break; case (ushort)PacketType.ClientRequestChannelInfo: type = PacketType.ServerAcknowledgementChannelInfo; packet = RequestChannelInfo(p); break; default: type = (ushort)0; packet = new GenericPacket(); break; } //Format the answer if (packet != null && type != 0) { return(Packet.Encode(type, (ICanSerialize)packet)); } else { return(new byte[0]); } }
/// <summary> /// Constructor. Common to all inheriting packet types. /// </summary> /// <param name="Creator"></param> /// <param name="DataPacket"></param> public Packet_36_WeaponsConfig(GenericPacket DataPacket) : base() //base == parent. ie: create the parent with this argument. { base.Type = 36; base.Data = DataPacket.Data; }
/// <summary> /// Constructor. Common to all inheriting packet types. /// </summary> /// <param name="Creator"></param> /// <param name="DataPacket"></param> public Packet_29_VersionNotify(GenericPacket DataPacket) : base() //base == parent. ie: create the parent with this argument. { base.Type = 29; base.Data = DataPacket.Data; }
/// <summary> /// Constructor. Common to all inheriting packet types. /// </summary> /// <param name="Creator"></param> /// <param name="DataPacket"></param> public Packet_16_PrepareSimulation(GenericPacket DataPacket) : base() //base == parent. ie: create the parent with this argument. { base.Type = 16; base.Data = DataPacket.Data; }
protected virtual void FlushPacket(Packet packet) { if (ConnectionClient == null || !ConnectionClient.Connected) { return; } try { packet.Direction = Direction; EventHandler <PacketEventArgs> packetSending = PacketSending; if (packetSending != null) { packetSending(this, new PacketEventArgs(Proxy, packet)); } if (packet.Ignore) { return; } byte[] buffer; GenericPacket gp = packet as GenericPacket; if (gp != null) { buffer = gp.Data; } else { buffer = PacketSerializer.Serialize(packet); } bool compressed = buffer.Length >= 4096 || packet.AlwaysCompress; if (compressed) { buffer = ZlibStream.CompressBuffer(buffer); } int length = compressed ? -buffer.Length : buffer.Length; byte[] lenBuf = VLQ.CreateSigned(length); byte[] finalBuffer = new byte[1 + lenBuf.Length + buffer.Length]; finalBuffer[0] = packet.PacketId; Buffer.BlockCopy(lenBuf, 0, finalBuffer, 1, lenBuf.Length); Buffer.BlockCopy(buffer, 0, finalBuffer, 1 + lenBuf.Length, buffer.Length); SocketAsyncEventArgs args = new SocketAsyncEventArgs(); args.UserToken = packet; args.Completed += Operation_Completed; args.SetBuffer(finalBuffer, 0, finalBuffer.Length); if (ConnectionClient != null && !ConnectionClient.SendAsync(args)) { Operation_Completed(this, args); } } catch { CloseAsync().Wait(); } }
/// <summary> /// Constructor. Common to all inheriting packet types. /// </summary> /// <param name="Creator"></param> /// <param name="DataPacket"></param> public Packet_06_Acknowledgement(GenericPacket DataPacket) : base() //base == parent. ie: create the parent with this argument. { base.Type = 6; base.Data = DataPacket.Data; }
private void processUnknownPacket(GenericPacket packet) { string debugHeader = " Response header: \t{0}"; string debugData = " Clean data text: \t{0}"; string debugRawData = " Raw unparsed data: \t{0}"; string rawData, responseHeader, responseData; for (int i = 0; i < packet.ResponseData.Count; i++) { rawData = packet.ResponseData[i]; responseHeader = GenericPacket.Response.GetResponseHeader(rawData); responseHeader = (responseHeader == "") ? "<no response type returned>" : responseHeader; responseData = GenericPacket.Response.GetResponseDataString(rawData); WritePacketDbg(String.Format(debugHeader, responseHeader)); WritePacketDbg(String.Format(debugData, responseData)); WritePacketDbg(String.Format(debugRawData, rawData)); } }
/// <summary> /// Constructor. Common to all inheriting packet types. /// </summary> /// <param name="Creator"></param> /// <param name="DataPacket"></param> public Packet_35_ReviveGrounds(GenericPacket DataPacket) : base() //base == parent. ie: create the parent with this argument. { base.Type = 35; base.Data = DataPacket.Data; }
public void BeginUpdateTree(bool refresh) { if (SelectedNode == null) { return; } if (XRay.RemoteViewer) { if (XRay.Remote.ServerConnection == null) { DetailsLabel = "Not connected to server to get instance information"; return; } // send request for initial table data if (!refresh) { var packet = new GenericPacket("RequestInstance"); packet.Data = new Dictionary <string, string> { { "ThreadID", Thread.CurrentThread.ManagedThreadId.ToString() }, { "NodeID", SelectedNode.ID.ToString() } }; if (FieldFilter != null) { packet.Data["Filter"] = FieldFilter; } XRay.RunInCoreAsync(() => XRay.Remote.ServerConnection.SendPacket(packet)); } // else send request to refresh table data else { var packet = new GenericPacket("RequestInstanceRefresh"); packet.Data = new Dictionary <string, string> { { "ThreadID", Thread.CurrentThread.ManagedThreadId.ToString() } }; XRay.RunInCoreAsync(() => XRay.Remote.ServerConnection.SendPacket(packet)); } return; } var nodeTypeName = SelectedNode.UnformattedName; var record = SelectedNode.Record; if (record == null) { if (SelectedNode.External) { DetailsLabel = "Not XRayed"; } else { DetailsLabel = "No record of being created"; } return; } DetailsLabel = String.Format("Active: {0}, Created: {1}, Deleted: {2}", record.Active.Count, record.Created, record.Deleted); // rebuild each list cause instances may be added or removed foreach (var recordList in GenericMap.Values) { recordList.Item2.Clear(); } if (record != null && record.Active.Count > 0) { lock (record.Active) { // traverse up the record's base types until we match the type for the class node selected in the UI // (cant show a debug matrix for types with different properties) // for example we click on the TreeView class, but the record type is of BuddyTreeView for (int i = 0; i < record.Active.Count && i < MaxInstances; i++) { var instance = record.Active[i]; if (!instance.IsStatic && instance.Ref.Target == null) { continue; } Type recordType = instance.InstanceType; string recordTypeName = ""; while (recordType != null) { recordTypeName = recordType.ToString(); if (recordTypeName.Contains(nodeTypeName)) { break; } recordType = recordType.BaseType; } if (recordType == null) { throw new Exception(string.Format("record type not found for node type {0} and instance type {1}", nodeTypeName, recordType.ToString())); } // if we're looking at a template class, then each root node is a diff type of template List<int>, List<string> etc.. recordTypeName = recordType.ToString(); string genericName = SelectedNode.Name; if (recordTypeName.Contains('`')) { genericName = recordTypeName.Substring(recordTypeName.IndexOf('`')); } if (!GenericMap.ContainsKey(genericName)) { GenericMap[genericName] = new Tuple <Type, List <ActiveRecord> >(recordType, new List <ActiveRecord>()); } List <ActiveRecord> recordList = GenericMap[genericName].Item2; if (!recordList.Contains(instance)) { recordList.Add(instance); } } } } // add columns for each intance int instanceCount = 0; if (GenericMap.Count > 0) { instanceCount = GenericMap.Values.Max(v => v.Item2.Count); } ColumnsUpdated = false; var newColumns = new List <string>(); for (int i = 0; i < instanceCount; i++) { if (Columns.Count <= 2 + i) { var col = "Instance " + i.ToString(); newColumns.Add(col); Columns.Add(col); ColumnsUpdated = true; } } while (Columns.Count > 2 + instanceCount) { Columns.RemoveAt(Columns.Count - 1); ColumnsUpdated = true; } UpdatedFields = new HashSet <int>(); foreach (var recordInstance in GenericMap) { var model = RootNodes.Cast <FieldModel>().FirstOrDefault(r => r.GenericName == recordInstance.Key); if (model != null) { model.RefreshField(); continue; } model = new FieldModel(this, null, RowTypes.Root); model.GenericName = recordInstance.Key; model.FieldType = recordInstance.Value.Item1; // instance type that matches selected node model.Instances = recordInstance.Value.Item2; // list of instances if (model.Instances.Count > 0 && model.Instances[0].IsStatic) { Columns[2] = "Static"; } RootNodes.Add(model); model.Init(); model.ExpandField(FieldFilter); } if (UpdatedTree != null) { UpdatedTree(); } }
/// <summary> /// Constructor. Common to all inheriting packet types. /// </summary> /// <param name="Creator"></param> /// <param name="DataPacket"></param> public Packet_10_JoinDenied(GenericPacket DataPacket) : base() //base == parent. ie: create the parent with this argument. { base.Type = 10; base.Data = DataPacket.Data; }