private void Receive_Sync(XConnection connection, G2ReceivedPacket packet) { // received by client from server var sync = SyncPacket.Decode(packet.Root); //Log("Sync packet received"); connection.SyncCount++; connection.LastSyncSize = packet.Root.PacketSize; XRay.RemoteSync(sync); }
internal void IncomingPacket(XConnection connection, G2ReceivedPacket packet) { if (XRay.IsInvokeRequired()) { XRay.RunInCoreAsync(() => IncomingPacket(connection, packet)); return; } switch (packet.Root.Name) { case PacketType.Padding: //Log("Crypt Padding Received"); break; case PacketType.Generic: var generic = GenericPacket.Decode(packet.Root); Log("Generic Packet Received: " + generic.Name); if (RouteGeneric.ContainsKey(generic.Name)) { RouteGeneric[generic.Name](connection, generic); } else { Log("Unknown generic packet: " + generic.Name); } break; case PacketType.Dat: Receive_DatPacket(connection, packet); break; case PacketType.Sync: Receive_Sync(connection, packet); break; case PacketType.Instance: Receive_Instance(connection, packet); break; default: Log("Unknown Packet Type: " + packet.Root.Name.ToString()); break; } }
void Receive_DatPacket(XConnection connection, G2ReceivedPacket packet) { // received by client from server var chunk = DatPacket.Decode(packet.Root); // write to tmp file if (LocalTempFile == null) { LocalTempFile = File.Create(LocalDatTempPath); LocalTempFile.SetLength(0); } Log("Received dat pos: {0}, length: {1}", chunk.Pos, chunk.Data.Length); //todo delete LocalTempFile.Write(chunk.Data); var percentComplete = LocalTempFile.Length * 100 / RemoteDatSize; RemoteStatus = string.Format("Downloading Dat File - {0}% Complete", percentComplete); // hash when complete if (LocalTempFile.Length >= RemoteDatSize) { LocalTempFile.Close(); LocalTempFile = null; var checkHash = Utilities.MD5HashFile(LocalDatTempPath); if (checkHash == RemoteDatHash) { File.Move(LocalDatTempPath, LocalDatPath); Send_StartSync(connection); } else { RemoteStatus = string.Format("Dat integrity check failed - Expecting {0}, got {1}", RemoteDatHash, checkHash); } } }
void ReceivePackets() { int Start = 0; G2ReadResult streamStatus = G2ReadResult.PACKET_GOOD; while (streamStatus == G2ReadResult.PACKET_GOOD) { G2ReceivedPacket packet = new G2ReceivedPacket(); packet.Root = new G2Header(FinalRecvBuffer); streamStatus = G2Protocol.ReadNextPacket(packet.Root, ref Start, ref FinalRecvBuffSize); if (streamStatus != G2ReadResult.PACKET_GOOD) { break; } packet.Tcp = this; // extract data from final recv buffer so it can be referenced without being overwritten by this thread byte[] extracted = Utilities.ExtractBytes(packet.Root.Data, packet.Root.PacketPos, packet.Root.PacketSize); packet.Root = new G2Header(extracted); G2Protocol.ReadPacket(packet.Root); PacketLogEntry logEntry = new PacketLogEntry(DateTime.Now, DirectionType.In, ToString(), packet.Root.Data); LogPacket(logEntry); Remote.IncomingPacket(this, packet); } // re-align buffer if (Start > 0 && FinalRecvBuffSize > 0) { Buffer.BlockCopy(FinalRecvBuffer, Start, FinalRecvBuffer, 0, FinalRecvBuffSize); //Network.UpdateConsole(PacketBytesReady.ToString() + " bytes moved to front of receive buffer"); } }
public static CryptPadding Decode(G2ReceivedPacket packet) { CryptPadding padding = new CryptPadding(); return padding; }
public static CryptPadding Decode(G2ReceivedPacket packet) { CryptPadding padding = new CryptPadding(); return(padding); }
private void Receive_Instance(XConnection connection, G2ReceivedPacket rawPacket) { // received by client from server var packet = InstancePacket.Decode(rawPacket.Root); XUI ui; if (!XRay.UIs.TryGetValue(packet.ThreadID, out ui)) { Log("Receive Instance: UI not found for instance result"); return; } if (ui.CurrentInstance == null) { Log("Receive Instance: Field not set"); return; } bool updateTree = false; bool updateFields = false; IFieldModel expandField = null; var instance = ui.CurrentInstance; if (packet.Details != null) { instance.DetailsLabel = packet.Details; } if (packet.Columns != null) { instance.Columns = packet.Columns; updateTree = true; } if (packet.Type == InstancePacketType.Root) { instance.RootNodes = packet.Fields; updateTree = true; updateFields = true; } else if (packet.Type == InstancePacketType.Field) { IFieldModel field; if (instance.FieldMap.TryGetValue(packet.FieldID, out field)) { field.Nodes = packet.Fields; } updateFields = true; expandField = field; } else if (packet.Type == InstancePacketType.Refresh) { foreach (var field in packet.Fields) { if (instance.FieldMap.ContainsKey(field.ID)) { instance.FieldMap[field.ID].Cells = field.Cells; } } updateTree = true; // cause recursive update of cells // dont update fields because already added, and would orphen fields associated with nodes } if (updateFields) { foreach (var field in packet.Fields) { instance.FieldMap[field.ID] = field; } } // if we're geting fresh info, or refresh info with new columns if (updateTree && instance.UpdatedTree != null) { ui.Window.BeginInvoke(new Action(() => instance.UpdatedTree())); } if (expandField != null && instance.ExpandedField != null) { ui.Window.BeginInvoke(new Action(() => instance.ExpandedField(expandField))); } }
private void Receive_Sync(XConnection connection, G2ReceivedPacket packet) { // received by client from server var sync = SyncPacket.Decode(packet.Root); //Log("Sync packet received"); connection.SyncCount++; connection.LastSyncSize = packet.Root.PacketSize; XRay.RemoteSync(sync); }
private void Receive_Instance(XConnection connection, G2ReceivedPacket rawPacket) { // received by client from server var packet = InstancePacket.Decode(rawPacket.Root); XUI ui; if (!XRay.UIs.TryGetValue(packet.ThreadID, out ui)) { Log("Receive Instance: UI not found for instance result"); return; } if (ui.CurrentInstance == null) { Log("Receive Instance: Field not set"); return; } bool updateTree = false; bool updateFields = false; IFieldModel expandField = null; var instance = ui.CurrentInstance; if (packet.Details != null) instance.DetailsLabel = packet.Details; if (packet.Columns != null) { instance.Columns = packet.Columns; updateTree = true; } if (packet.Type == InstancePacketType.Root) { instance.RootNodes = packet.Fields; updateTree = true; updateFields = true; } else if(packet.Type == InstancePacketType.Field) { IFieldModel field; if (instance.FieldMap.TryGetValue(packet.FieldID, out field)) field.Nodes = packet.Fields; updateFields = true; expandField = field; } else if (packet.Type == InstancePacketType.Refresh) { foreach (var field in packet.Fields) if (instance.FieldMap.ContainsKey(field.ID)) instance.FieldMap[field.ID].Cells = field.Cells; updateTree = true; // cause recursive update of cells // dont update fields because already added, and would orphen fields associated with nodes } if (updateFields) foreach (var field in packet.Fields) instance.FieldMap[field.ID] = field; // if we're geting fresh info, or refresh info with new columns if (updateTree && instance.UpdatedTree != null) ui.Window.BeginInvoke(new Action(() => instance.UpdatedTree())); if (expandField != null && instance.ExpandedField != null) ui.Window.BeginInvoke(new Action(() => instance.ExpandedField(expandField))); }
void Receive_DatPacket(XConnection connection, G2ReceivedPacket packet) { // received by client from server var chunk = DatPacket.Decode(packet.Root); // write to tmp file if (LocalTempFile == null) { LocalTempFile = File.Create(LocalDatTempPath); LocalTempFile.SetLength(0); } Log("Received dat pos: {0}, length: {1}", chunk.Pos, chunk.Data.Length); //todo delete LocalTempFile.Write(chunk.Data); var percentComplete = LocalTempFile.Length * 100 / RemoteDatSize; RemoteStatus = string.Format("Downloading Dat File - {0}% Complete", percentComplete); // hash when complete if (LocalTempFile.Length >= RemoteDatSize) { LocalTempFile.Close(); LocalTempFile = null; var checkHash = Utilities.MD5HashFile(LocalDatTempPath); if (checkHash == RemoteDatHash) { File.Move(LocalDatTempPath, LocalDatPath); Send_StartSync(connection); } else RemoteStatus = string.Format("Dat integrity check failed - Expecting {0}, got {1}", RemoteDatHash, checkHash); } }
internal void IncomingPacket(XConnection connection, G2ReceivedPacket packet) { if (XRay.IsInvokeRequired()) { XRay.RunInCoreAsync(() => IncomingPacket(connection, packet)); return; } switch (packet.Root.Name) { case PacketType.Padding: //Log("Crypt Padding Received"); break; case PacketType.Generic: var generic = GenericPacket.Decode(packet.Root); Log("Generic Packet Received: " + generic.Name); if(RouteGeneric.ContainsKey(generic.Name)) RouteGeneric[generic.Name](connection, generic); else Log("Unknown generic packet: " + generic.Name); break; case PacketType.Dat: Receive_DatPacket(connection, packet); break; case PacketType.Sync: Receive_Sync(connection, packet); break; case PacketType.Instance: Receive_Instance(connection, packet); break; default: Log("Unknown Packet Type: " + packet.Root.Name.ToString()); break; } }
void ReceivePackets() { int Start = 0; G2ReadResult streamStatus = G2ReadResult.PACKET_GOOD; while (streamStatus == G2ReadResult.PACKET_GOOD) { G2ReceivedPacket packet = new G2ReceivedPacket(); packet.Root = new G2Header(FinalRecvBuffer); streamStatus = G2Protocol.ReadNextPacket(packet.Root, ref Start, ref FinalRecvBuffSize); if (streamStatus != G2ReadResult.PACKET_GOOD) break; packet.Tcp = this; // extract data from final recv buffer so it can be referenced without being overwritten by this thread byte[] extracted = Utilities.ExtractBytes(packet.Root.Data, packet.Root.PacketPos, packet.Root.PacketSize); packet.Root = new G2Header(extracted); G2Protocol.ReadPacket(packet.Root); PacketLogEntry logEntry = new PacketLogEntry(DateTime.Now, DirectionType.In, ToString(), packet.Root.Data); LogPacket(logEntry); Remote.IncomingPacket(this, packet); } // re-align buffer if (Start > 0 && FinalRecvBuffSize > 0) { Buffer.BlockCopy(FinalRecvBuffer, Start, FinalRecvBuffer, 0, FinalRecvBuffSize); //Network.UpdateConsole(PacketBytesReady.ToString() + " bytes moved to front of receive buffer"); } }