示例#1
0
        void Receive_DatFileRequest(XConnection connection, GenericPacket request)
        {
            // received by server from client

            Log("Creating download for connection, size: " + XRay.DatSize.ToString());

            Downloads.Add(new Download()
            {
                Connection = connection,
                Stream     = File.OpenRead(XRay.DatPath),
                FilePos    = 0
            });
        }
示例#2
0
        void Receive_StartSync(XConnection connection, GenericPacket packet)
        {
            // received by server from client

            var client = new SyncClient();

            client.Connection = connection;

            Log("Sync client added");
            SyncClients.Add(client.Connection.GetHashCode(), client);

            // do after state added so new calls get queued to be sent as well
            foreach (var call in XRay.CallMap)
            {
                client.NewCalls.Add(new Tuple <int, int>(call.Source, call.Destination));
            }

            foreach (var init in XRay.InitMap)
            {
                client.Inits.Add(new Tuple <int, int>(init.Source, init.Destination));
            }

            foreach (var flow in XRay.FlowMap)
            {
                client.NewThreads.Add(flow.ThreadID, new Tuple <string, bool>(flow.Name, flow.IsAlive));
            }

            foreach (var node in XRay.Nodes)
            {
                if (node.ThreadIDs != null)
                {
                    foreach (var id in node.ThreadIDs)
                    {
                        client.NodeThreads.Add(new Tuple <int, int>(node.ID, id));
                    }
                }
            }

            foreach (var call in XRay.CallMap)
            {
                if (call.ThreadIDs != null)
                {
                    foreach (var id in call.ThreadIDs)
                    {
                        client.CallThreads.Add(new Tuple <int, int>(call.ID, id));
                    }
                }
            }

            // past threadlines will be added automatically when sync packet is sent
        }
示例#3
0
        void Receive_DatHashRequest(XConnection connection, GenericPacket request)
        {
            var response = new GenericPacket("DatHashResponse");

            response.Data = new Dictionary <string, string>
            {
                { "Hash", XRay.DatHash },
                { "Size", XRay.DatSize.ToString() }
            };

            Log("Sending Dat Hash");

            connection.SendPacket(response);
        }
示例#4
0
        void Receive_RequestField(XConnection connection, GenericPacket request)
        {
            // received by server from client

            // get client
            SyncClient client;

            if (!SyncClients.TryGetValue(connection.GetHashCode(), out client))
            {
                Log("Request field: Instance request received, but sync client not found");
                return;
            }

            // get thread - client can have multiple ui threads viewing instances
            var threadID = int.Parse(request.Data["ThreadID"]);

            InstanceModel instance;

            if (!client.SelectedInstances.TryGetValue(threadID, out instance))
            {
                Log("Request field: instance not found " + threadID.ToString());
                return;
            }

            // get field
            var fieldID = int.Parse(request.Data["FieldID"]);

            IFieldModel field;

            if (!instance.FieldMap.TryGetValue(fieldID, out field))
            {
                Log("Request field: field not found " + fieldID.ToString());
                return;
            }

            field.ExpandField();

            // create packet with expanded results and send
            var response = new InstancePacket()
            {
                Type     = InstancePacketType.Field,
                ThreadID = threadID,
                FieldID  = fieldID,
                Fields   = field.Nodes
            };

            client.Connection.SendPacket(response);
        }
示例#5
0
        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;
            }
        }
示例#6
0
        void Receive_Settings(XConnection connection, GenericPacket request)
        {
            // received by server from client

            SyncClient client;

            if (!SyncClients.TryGetValue(connection.GetHashCode(), out client))
            {
                Log("Request field: Settings received, but sync client not found");
                return;
            }

            if (request.Data.ContainsKey("TargetFps"))
            {
                client.TargetFps = int.Parse(request.Data["TargetFps"]);
            }

            if (request.Data.ContainsKey("TrackFunctionHits"))
            {
                XRay.TrackFunctionHits = bool.Parse(request.Data["TrackFunctionHits"]);
            }

            if (request.Data.ContainsKey("FlowTracking"))
            {
                XRay.FlowTracking = bool.Parse(request.Data["FlowTracking"]);
            }

            if (request.Data.ContainsKey("InstanceTracking"))
            {
                XRay.InstanceTracking = bool.Parse(request.Data["InstanceTracking"]);
            }

            if (request.Data.ContainsKey("TrackRemoteProfiling"))
            {
                client.TrackProfiling = bool.Parse(request.Data["TrackRemoteProfiling"]);
            }

            if (request.Data.ContainsKey("TrackRemoteThreadlines"))
            {
                client.TrackThreadlines = bool.Parse(request.Data["TrackRemoteThreadlines"]);
            }
        }
示例#7
0
        void Receive_RequestInstanceRefresh(XConnection connection, GenericPacket request)
        {
            // received by server from client

            SyncClient client;

            if (!SyncClients.TryGetValue(connection.GetHashCode(), out client))
            {
                Log("Request Instance Refresh: Sync client not found");
                return;
            }

            var threadID = int.Parse(request.Data["ThreadID"]);

            InstanceModel instance;

            if (!client.SelectedInstances.TryGetValue(threadID, out instance))
            {
                Log("Request field: instance not found " + threadID.ToString());
                return;
            }

            instance.BeginUpdateTree(true);

            // send columns if updated
            var response = new InstancePacket();

            response.Type     = InstancePacketType.Refresh;
            response.ThreadID = threadID;
            // flag as a refresh?

            if (instance.ColumnsUpdated)
            {
                response.Columns = instance.Columns;
            }

            // iterate fields, send any marked as changed
            response.Fields = instance.FieldMap.Values.Where(f => instance.UpdatedFields.Contains(f.ID)).ToList();

            client.Connection.SendPacket(response);
        }
示例#8
0
        void Receive_RequestInstance(XConnection connection, GenericPacket request)
        {
            // received by server from client

            SyncClient client;

            if (!SyncClients.TryGetValue(connection.GetHashCode(), out client))
            {
                Log("Request Instance: Sync client not found");
                return;
            }

            var threadID = int.Parse(request.Data["ThreadID"]);

            var node = XRay.Nodes[int.Parse(request.Data["NodeID"])];

            string filter = null;

            request.Data.TryGetValue("Filter", out filter);

            var model = new InstanceModel(node, filter);

            client.SelectedInstances[threadID] = model;
            Log("Request Instance: Model added for thread " + threadID.ToString());

            model.BeginUpdateTree(false);

            // send back details, columns, and nodes
            var response = new InstancePacket()
            {
                Type     = InstancePacketType.Root,
                ThreadID = threadID,
                Details  = model.DetailsLabel,
                Columns  = model.Columns,
                Fields   = model.RootNodes
            };

            client.Connection.SendPacket(response);
        }
示例#9
0
        void Receive_DatHashResponse(XConnection connection, GenericPacket response)
        {
            // only one instance type per builder instance because xray is static
            if (XRay.InitComplete && RemoteDatHash != null && RemoteDatHash != response.Data["Hash"])
            {
                RemoteStatus = "Open a new builder instance to connect to a new server";
                connection.Disconnect();
                return;
            }

            // check if we have this hash.dat file locally, if not then request download
            RemoteDatHash = response.Data["Hash"];
            RemoteDatSize = long.Parse(response.Data["Size"]);

            LocalDatPath     = Path.Combine(RemoteCachePath, RemoteDatHash + ".dat");
            LocalDatTempPath = Path.Combine(RemoteCachePath, RemoteDatHash + ".tmp");

            if (RemoteDatSize == 0)
            {
                RemoteStatus = "Error - Remote Dat Empty";
            }

            else if (File.Exists(LocalDatPath))
            {
                Send_StartSync(connection);
            }

            else
            {
                Log("Requesting Dat File, size: " + RemoteDatSize.ToString());

                RemoteStatus = "Requesting Dat File";

                var request = new GenericPacket("DatFileRequest");

                connection.SendPacket(request);
            }
        }
示例#10
0
        public static GenericPacket Decode(G2Header root)
        {
            var generic = new GenericPacket();

            if (G2Protocol.ReadPayload(root))
            {
                generic.Name = UTF8Encoding.UTF8.GetString(root.Data, root.PayloadPos, root.PayloadSize);
            }

            foreach (var child in G2Protocol.EnumerateChildren(root))
            {
                if (generic.Data == null)
                {
                    generic.Data = new Dictionary <string, string>();
                }

                string key   = null;
                string value = null;

                foreach (var sub in G2Protocol.EnumerateChildren(child))
                {
                    if (sub.Name == Packet_Key)
                    {
                        key = UTF8Encoding.UTF8.GetString(sub.Data, sub.PayloadPos, sub.PayloadSize);
                    }
                    else if (sub.Name == Packet_Value)
                    {
                        value = UTF8Encoding.UTF8.GetString(sub.Data, sub.PayloadPos, sub.PayloadSize);
                    }
                }

                generic.Data[key] = value;
            }

            return(generic);
        }
示例#11
0
        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();
        }
示例#12
0
        void Receive_DatFileRequest(XConnection connection, GenericPacket request)
        {
            // received by server from client

            Log("Creating download for connection, size: " + XRay.DatSize.ToString());

            Downloads.Add(new Download()
            {
                Connection = connection,
                Stream = File.OpenRead(XRay.DatPath),
                FilePos = 0
            });
        }
示例#13
0
 void Receive_Bye(XConnection connection, GenericPacket bye)
 {
     Log("Received bye from {0}: {1}", connection, bye.Data["Reason"]);
     connection.Disconnect();
 }
示例#14
0
        void Receive_DatHashResponse(XConnection connection, GenericPacket response)
        {
            // only one instance type per builder instance because xray is static
            if (XRay.InitComplete && RemoteDatHash != null && RemoteDatHash != response.Data["Hash"])
            {
                RemoteStatus = "Open a new builder instance to connect to a new server";
                connection.Disconnect();
                return;
            }

            // check if we have this hash.dat file locally, if not then request download
            RemoteDatHash = response.Data["Hash"];
            RemoteDatSize = long.Parse(response.Data["Size"]);

            LocalDatPath = Path.Combine(RemoteCachePath, RemoteDatHash + ".dat");
            LocalDatTempPath = Path.Combine(RemoteCachePath, RemoteDatHash + ".tmp");

            if (RemoteDatSize == 0)
                RemoteStatus = "Error - Remote Dat Empty";

            else if (File.Exists(LocalDatPath))
                Send_StartSync(connection);

            else
            {
                Log("Requesting Dat File, size: " + RemoteDatSize.ToString());

                RemoteStatus = "Requesting Dat File";

                var request = new GenericPacket("DatFileRequest");

                connection.SendPacket(request);
            }
        }
示例#15
0
        void Receive_DatHashRequest(XConnection connection, GenericPacket request)
        {
            var response = new GenericPacket("DatHashResponse");

            response.Data = new Dictionary<string, string>
            {
                {"Hash", XRay.DatHash},
                {"Size", XRay.DatSize.ToString()}
            };

            Log("Sending Dat Hash");

            connection.SendPacket(response);
        }
示例#16
0
 void Receive_Pong(XConnection connection, GenericPacket pong)
 {
     // lower level socket on receiving data marks connection as alive
 }
示例#17
0
 void Receive_Ping(XConnection connection, GenericPacket ping)
 {
     Log("Pong Sent");
     connection.SendPacket(new GenericPacket("Pong"));
 }
示例#18
0
        void Receive_RequestInstance(XConnection connection, GenericPacket request)
        {
            // received by server from client

            SyncClient client;
            if (!SyncClients.TryGetValue(connection.GetHashCode(), out client))
            {
                Log("Request Instance: Sync client not found");
                return;
            }

            var threadID = int.Parse(request.Data["ThreadID"]);

            var node = XRay.Nodes[int.Parse(request.Data["NodeID"])];

            string filter = null;
            request.Data.TryGetValue("Filter", out filter);

            var model = new InstanceModel(node, filter);
            client.SelectedInstances[threadID] = model;
            Log("Request Instance: Model added for thread " + threadID.ToString());

            model.BeginUpdateTree(false);

            // send back details, columns, and nodes
            var response = new InstancePacket()
            {
                Type = InstancePacketType.Root,
                ThreadID = threadID,
                Details = model.DetailsLabel,
                Columns = model.Columns,
                Fields = model.RootNodes
            };

            client.Connection.SendPacket(response);
        }
示例#19
0
        void Receive_RequestField(XConnection connection, GenericPacket request)
        {
            // received by server from client

            // get client
            SyncClient client;
            if (!SyncClients.TryGetValue(connection.GetHashCode(), out client))
            {
                Log("Request field: Instance request received, but sync client not found");
                return;
            }

            // get thread - client can have multiple ui threads viewing instances
            var threadID = int.Parse(request.Data["ThreadID"]);

            InstanceModel instance;
            if (!client.SelectedInstances.TryGetValue(threadID, out instance))
            {
                Log("Request field: instance not found " + threadID.ToString());
                return;
            }

            // get field
            var fieldID = int.Parse(request.Data["FieldID"]);

            IFieldModel field;
            if (!instance.FieldMap.TryGetValue(fieldID, out field))
            {
                Log("Request field: field not found " + fieldID.ToString());
                return;
            }

            field.ExpandField();

            // create packet with expanded results and send
            var response = new InstancePacket()
            {
                Type = InstancePacketType.Field,
                ThreadID = threadID,
                FieldID = fieldID,
                Fields = field.Nodes
            };

            client.Connection.SendPacket(response);
        }
示例#20
0
        internal void SendClientSettings()
        {
            if (XRay.IsInvokeRequired())
            {
                XRay.RunInCoreAsync(() => SendClientSettings());
                return;
            }

            if (ServerConnection == null)
                return;

            var packet = new GenericPacket("Settings");

            packet.Data = new Dictionary<string, string>()
            {
                {"TargetFps", XRay.TargetFps.ToString()},
                {"TrackFunctionHits", XRay.TrackFunctionHits.ToString()},
                {"FlowTracking", XRay.FlowTracking.ToString()},
                {"InstanceTracking", XRay.InstanceTracking.ToString()},
                {"TrackRemoteProfiling", XRay.Remote.TrackRemoteProfiling.ToString()},
                {"TrackRemoteThreadlines", XRay.Remote.TrackRemoteThreadlines.ToString()}
            };

            ServerConnection.SendPacket(packet);
        }
示例#21
0
 void Receive_Bye(XConnection connection, GenericPacket bye)
 {
     Log("Received bye from {0}: {1}", connection, bye.Data["Reason"]);
     connection.Disconnect();
 }
示例#22
0
        public static GenericPacket Decode(G2Header root)
        {
            var generic = new GenericPacket();

            if (G2Protocol.ReadPayload(root))
                generic.Name = UTF8Encoding.UTF8.GetString(root.Data, root.PayloadPos, root.PayloadSize);

            foreach(var child in G2Protocol.EnumerateChildren(root))
            {
                if(generic.Data == null)
                    generic.Data = new Dictionary<string, string>();

                string key = null;
                string value = null;

                foreach(var sub in G2Protocol.EnumerateChildren(child))
                    if (sub.Name == Packet_Key)
                        key = UTF8Encoding.UTF8.GetString(sub.Data, sub.PayloadPos, sub.PayloadSize);
                    else if(sub.Name == Packet_Value)
                        value = UTF8Encoding.UTF8.GetString(sub.Data, sub.PayloadPos, sub.PayloadSize);

                generic.Data[key] = value;
            }

            return generic;
        }
示例#23
0
        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));
        }
示例#24
0
        void Receive_StartSync(XConnection connection, GenericPacket packet)
        {
            // received by server from client

            var client = new SyncClient();
            client.Connection = connection;

            Log("Sync client added");
            SyncClients.Add(client.Connection.GetHashCode(), client);

            // do after state added so new calls get queued to be sent as well
            foreach(var call in XRay.CallMap)
                client.NewCalls.Add(new Tuple<int, int>(call.Source, call.Destination));

            foreach (var init in XRay.InitMap)
                client.Inits.Add(new Tuple<int, int>(init.Source, init.Destination));

            foreach (var flow in XRay.FlowMap)
                client.NewThreads.Add(flow.ThreadID, new Tuple<string, bool>(flow.Name, flow.IsAlive));

            foreach (var node in XRay.Nodes)
                if (node.ThreadIDs != null)
                    foreach (var id in node.ThreadIDs)
                        client.NodeThreads.Add(new Tuple<int, int>(node.ID, id));

            foreach (var call in XRay.CallMap)
                if (call.ThreadIDs != null)
                    foreach (var id in call.ThreadIDs)
                        client.CallThreads.Add(new Tuple<int, int>(call.ID, id));

            // past threadlines will be added automatically when sync packet is sent
        }
示例#25
0
        void Receive_Settings(XConnection connection, GenericPacket request)
        {
            // received by server from client

            SyncClient client;
            if (!SyncClients.TryGetValue(connection.GetHashCode(), out client))
            {
                Log("Request field: Settings received, but sync client not found");
                return;
            }

            if (request.Data.ContainsKey("TargetFps"))
                client.TargetFps = int.Parse(request.Data["TargetFps"]);

            if (request.Data.ContainsKey("TrackFunctionHits"))
                XRay.TrackFunctionHits = bool.Parse(request.Data["TrackFunctionHits"]);

            if (request.Data.ContainsKey("FlowTracking"))
                XRay.FlowTracking = bool.Parse(request.Data["FlowTracking"]);

            if (request.Data.ContainsKey("InstanceTracking"))
                XRay.InstanceTracking = bool.Parse(request.Data["InstanceTracking"]);

            if (request.Data.ContainsKey("TrackRemoteProfiling"))
                client.TrackProfiling = bool.Parse(request.Data["TrackRemoteProfiling"]);

            if (request.Data.ContainsKey("TrackRemoteThreadlines"))
                client.TrackThreadlines = bool.Parse(request.Data["TrackRemoteThreadlines"]);
        }
示例#26
0
        void Receive_RequestInstanceRefresh(XConnection connection, GenericPacket request)
        {
            // received by server from client

            SyncClient client;
            if (!SyncClients.TryGetValue(connection.GetHashCode(), out client))
            {
                Log("Request Instance Refresh: Sync client not found");
                return;
            }

            var threadID = int.Parse(request.Data["ThreadID"]);

            InstanceModel instance;
            if (!client.SelectedInstances.TryGetValue(threadID, out instance))
            {
                Log("Request field: instance not found " + threadID.ToString());
                return;
            }

            instance.BeginUpdateTree(true);

            // send columns if updated
            var response = new InstancePacket();
            response.Type = InstancePacketType.Refresh;
            response.ThreadID = threadID;
            // flag as a refresh?

            if (instance.ColumnsUpdated)
                response.Columns = instance.Columns;

            // iterate fields, send any marked as changed
            response.Fields = instance.FieldMap.Values.Where(f => instance.UpdatedFields.Contains(f.ID)).ToList();

            client.Connection.SendPacket(response);
        }
示例#27
0
 void Receive_Ping(XConnection connection, GenericPacket ping)
 {
     Log("Pong Sent");
     connection.SendPacket(new GenericPacket("Pong"));
 }
示例#28
0
 void Receive_Pong(XConnection connection, GenericPacket pong)
 {
     // lower level socket on receiving data marks connection as alive
 }
示例#29
0
        public static void Test()
        {
            // create
            var packet = new GenericPacket("name");
            packet.Data = new Dictionary<string, string>()
            {
                {"test1", "val1"},
                {"test2", "val2"}
            };

            // send
            var protocol = new G2Protocol();
            var encoded = packet.Encode(protocol);

            // recv
            var recvPacket = new G2Header(encoded);
            int start = 0;
            int size = encoded.Length;
            var streamStatus = G2Protocol.ReadNextPacket(recvPacket, ref start, ref size);

            // decode
            var check = GenericPacket.Decode(recvPacket);

            Debug.Assert(check.Data["test1"] == "val1");
            Debug.Assert(check.Data["test2"] == "val2");
        }
示例#30
0
        public void CleanClose(string reason, bool reconnect)
        {
            if (State == TcpState.Connecting)
                ByeMessage = reason;

            if (State == TcpState.Connected)
            {
                ByeMessage = reason;

                var bye = new GenericPacket("Bye");

                bye.Data = new Dictionary<string, string>
                {
                    {"Reason", reason}
                };

                SendPacket(bye);

                Log("CleanClose", "Closing connection: " + reason);

                TcpSocket.Close();
            }

            State = TcpState.Closed;
        }