Esempio n. 1
0
        private async Task RemoveOfcAssignment(ConnectedPeer sender, BareGuid ofcId)
        {
            await Task.FromResult(0);

#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] Remove officer assignment Request Received");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] Remove officer assignment Request Received");
#endif

            // finding the ofc
            Officer ofc = global::DispatchSystem.Server.Main.Core.Officers.FirstOrDefault(x => x.Id == ofcId);
            if (ofc == null)
            {
                return;
            }

            if (!global::DispatchSystem.Server.Main.Core.OfficerAssignments.ContainsKey(ofc))
            {
                return;
            }
            global::DispatchSystem.Server.Main.Core.OfficerAssignments.Remove(ofc); // removing the assignment from the officer

            ofc.Status = OfficerStatus.OnDuty;                                      // set on duty

            global::DispatchSystem.Server.Main.DispatchSystem.Invoke(() =>
            {
                Player p = Common.GetPlayerByLic(ofc.License);
                if (p != null)
                {
                    global::DispatchSystem.Server.Main.Core.RequestHandler.TriggerEvent("leo_assignment_removed", new EventArgument[] { Common.GetPlayerId(p) });
                }
            });
        }
Esempio n. 2
0
        private async Task EndEmergency(ConnectedPeer sender, BareGuid id)
        {
            await Task.FromResult(0);

#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] End emergency Request Received");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] End emergency Request Received");
#endif

            Calls.Remove(id);                                                                                          // removing the id from the calls

            EmergencyCall call = global::DispatchSystem.Server.Main.Core.CurrentCalls.FirstOrDefault(x => x.Id == id); // obtaining the call from the civ

            if (global::DispatchSystem.Server.Main.Core.CurrentCalls.Remove(call))                                     // remove, if successful, then notify
            {
                global::DispatchSystem.Server.Main.DispatchSystem.Invoke(delegate
                {
                    Player p = Common.GetPlayerByIp(call?.License);

                    if (p != null)
                    {
                        global::DispatchSystem.Server.Main.Core.RequestHandler.TriggerEvent("civ_911_ended", new EventArgument[] { Common.GetPlayerId(p) });
                    }
                });
            }
        }
Esempio n. 3
0
        private async Task <object> AcceptEmergency(ConnectedPeer sender, object[] args)
        {
            await Task.FromResult(0);

            if (CheckAndDispose(sender))
            {
                return(null);
            }

#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] Accept emergency Request Received");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] Accept emergency Request Received");
#endif

            Guid          id           = (Guid)args[0];
            EmergencyCall acceptedCall = DispatchSystem.currentCalls.Find(x => x.Id == id);
            if (Calls.ContainsKey(id) || acceptedCall == null)
            {
                return(false);                                               // Checking null and accepted in same expression
            }
            Calls.Add(id, sender.RemoteIP);
            DispatchSystem.Invoke(delegate
            {
                Player p = Common.GetPlayerByIp(acceptedCall.SourceIP);
                if (p != null)
                {
                    Common.SendMessage(p, "Dispatch911", new [] { 255, 0, 0 }, "Your 911 call has been accepted by a Dispatcher");
                }
            });
            return(true);
        }
Esempio n. 4
0
        private bool AcceptEmergency(ConnectedPeer sender, BareGuid id)
        {
#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] Accept emergency Request Received");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] Accept emergency Request Received");
#endif

            // finding the call in the current calls
            EmergencyCall acceptedCall = global::DispatchSystem.Server.Main.Core.CurrentCalls.FirstOrDefault(x => x.Id == id);
            if (Calls.ContainsKey(id) || acceptedCall == null)
            {
                return(false);              // Checking null and accepted in same expression
            }
            Calls.Add(id, sender.RemoteIP); // adding the call and dispatcher to the call list
            // setting a message for invocation on the main thread
            global::DispatchSystem.Server.Main.DispatchSystem.Invoke(delegate
            {
                Player p = Common.GetPlayerByLic(acceptedCall.License);
                if (p != null)
                {
                    global::DispatchSystem.Server.Main.Core.RequestHandler.TriggerEvent("civ_911_accepted", new EventArgument[] { Common.GetPlayerId(p) });
                }
            });
            return(true);
        }
Esempio n. 5
0
        private async Task <object> GetCivilianVeh(ConnectedPeer sender, object[] args)
        {
            await Task.FromResult(0);

            if (CheckAndDispose(sender))
            {
                return(null);
            }
#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] Get civilian veh Request Recieved");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] Get civilian veh Request Recieved");
#endif

            string plate = (string)args[0];

            CivilianVeh civVeh = Common.GetCivilianVehByPlate(plate);
            if (civVeh != null)
            {
#if DEBUG
                Log.WriteLine($"[{sender.RemoteIP}] Sending Civilian Veh information to Client");
#else
                Log.WriteLineSilent($"[{sender.RemoteIP}] Sending Civilian Veh information to Client");
#endif
                return(civVeh);
            }
#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] Civilian Veh not found, sending null");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] Civilian Veh not found, sending null");
#endif
            return(CivilianVeh.Empty);
        }
Esempio n. 6
0
        private async Task MessageEmergency(ConnectedPeer sender, object[] args)
        {
            await Task.FromResult(0);

            if (CheckAndDispose(sender))
            {
                return;
            }

#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] Message emergency Request Received");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] Message emergency Request Received");
#endif

            Guid   id  = (Guid)args[0];
            string msg = args[1] as string;

            EmergencyCall call = DispatchSystem.currentCalls.Find(x => x.Id == id);

            DispatchSystem.Invoke(() =>
            {
                Player p = Common.GetPlayerByIp(call?.SourceIP);

                if (p != null)
                {
                    Common.SendMessage(p, "Dispatcher", new [] { 0x0, 0xff, 0x0 }, msg);
                }
            });
        }
Esempio n. 7
0
        private async Task AddNote(ConnectedPeer sender, BareGuid id, string note)
        {
            await Task.FromResult(0);

#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] Add Civilian note Request Received");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] Add Civilian note Request Received");
#endif

            Civilian civ = DispatchSystem.Civs.FirstOrDefault(x => x.Id == id); // finding the civ from the id

            if (civ != null)
            {
#if DEBUG
                Log.WriteLine($"[{sender.RemoteIP}] Adding the note \"{note}\" to Civilian {civ.First} {civ.Last}");
#else
                Log.WriteLineSilent($"[{sender.RemoteIP}] Adding the note \"{note}\" to Civilian {civ.First} {civ.Last}");
#endif
                civ.Notes.Add(note); // adding the note for the civilian
            }
            else
#if DEBUG
            { Log.WriteLine($"[{sender.RemoteIP}] Civilian not found, not adding note..."); }
#else
            { Log.WriteLineSilent($"[{sender.RemoteIP}] Civilian not found, not adding note..."); }
#endif
        }
Esempio n. 8
0
        public static async void EndEmergency(string handle)
        {
            Player p = GetPlayerByHandle(handle);

            EmergencyCall call = GetEmergencyCall(handle);

            // checking for call null
            if (call == null)
            {
                SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "There is no 911 call to end!");
                return;
            }

#if DEBUG
            SendMessage(p, "", new[] { 0, 0, 0 }, "Ending 911 call...");
#endif

            // finding the dispatcher ip
            string        dispatcherIp = Server.Calls.ContainsKey(call.Id) ? Server.Calls[call.Id] : null;
            ConnectedPeer peer         = Server.ConnectedDispatchers.FirstOrDefault(x => x.RemoteIP == dispatcherIp); // finding the peer from the ip
            var           task         = peer?.RemoteCallbacks.Events?["end" + call.Id].Invoke();                     // creating the task from the events

            // removing the call from the calls list
            CurrentCalls.Remove(call);
            SendMessage(p, "Dispatch911", new[] { 255, 0, 0 }, "Ended the 911 call");

            if (!(task is null))
            {
                await task;                  // await the task
            }
        }
Esempio n. 9
0
        private async Task RemoveOfcAssignment(ConnectedPeer sender, BareGuid ofcId)
        {
            await Task.FromResult(0);

#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] Remove officer assignment Request Received");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] Remove officer assignment Request Received");
#endif

            // finding the ofc
            Officer ofc = DispatchSystem.Officers.FirstOrDefault(x => x.Id == ofcId);
            if (ofc == null)
            {
                return;
            }

            if (!DispatchSystem.OfcAssignments.ContainsKey(ofc))
            {
                return;
            }
            DispatchSystem.OfcAssignments.Remove(ofc); // removing the assignment from the officer

            ofc.Status = OfficerStatus.OnDuty;         // set on duty

            DispatchSystem.Invoke(() =>
            {
                Player p = Common.GetPlayerByIp(ofc.SourceIP);
                if (p != null)
                {
                    Common.SendMessage(p, "^8DispatchCAD", new[] { 0, 0, 0 }, "Your assignment has been removed by a dispatcher");
                }
            });
        }
Esempio n. 10
0
        private async Task RemoveBolo(ConnectedPeer sender, int parse)
        {
            await Task.FromResult(0);

#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] Remove bolo Request Received");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] Remove bolo Request Received");
#endif

            try
            {
                // removing at the specified index
                DispatchSystem.ActiveBolos.RemoveAt(parse);
#if DEBUG
                Log.WriteLine($"[{sender.RemoteIP}] Removed Active BOLO from the List");
#else
                Log.WriteLineSilent($"[{sender.RemoteIP}] Removed Active BOLO from the List");
#endif
            }
            // thrown when argument is out of range
            catch (ArgumentOutOfRangeException)
            {
#if DEBUG
                Log.WriteLine($"[{sender.RemoteIP}] Index for BOLO not found, not removing...");
#else
                Log.WriteLineSilent($"[{sender.RemoteIP}] Index for BOLO not found, not removing...");
#endif
            }
        }
Esempio n. 11
0
        private async Task AddOfcAssignment(ConnectedPeer sender, BareGuid id, BareGuid ofcId)
        {
            await Task.FromResult(0);

#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] Add officer assignment Request Received");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] Add officer assignment Request Received");
#endif

            Assignment assignment = DispatchSystem.Assignments.FirstOrDefault(x => x.Id == id); // finding assignment from the id
            Officer    ofc        = DispatchSystem.Officers.ToList().Find(x => x.Id == ofcId);  // finding the officer from the id
            if (assignment is null || ofc is null)                                              // returning if either is null
            {
                return;
            }
            if (DispatchSystem.OfcAssignments.ContainsKey(ofc)) // returning if the officer already contains the assignment
            {
                return;
            }

            DispatchSystem.OfcAssignments.Add(ofc, assignment); // adding the assignment to the officer

            ofc.Status = OfficerStatus.OffDuty;

            // notify of assignment
            DispatchSystem.Invoke(() =>
            {
                Player p = Common.GetPlayerByIp(ofc.SourceIP);
                if (p != null)
                {
                    Common.SendMessage(p, "^8DispatchCAD", new[] { 0, 0, 0 }, $"New assignment added: \"{assignment.Summary}\"");
                }
            });
        }
Esempio n. 12
0
        private async Task RemoveBolo(ConnectedPeer sender, object[] args)
        {
            await Task.FromResult(0);

            if (CheckAndDispose(sender))
            {
                return;
            }
#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] Remove bolo Request Recieved");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] Remove bolo Request Recieved");
#endif

            int parse = (int)args[0];

            try
            {
                DispatchSystem.ActiveBolos.RemoveAt(parse);
#if DEBUG
                Log.WriteLine($"[{sender.RemoteIP}] Removed Active BOLO from the List");
#else
                Log.WriteLineSilent($"[{sender.RemoteIP}] Removed Active BOLO from the List");
#endif
            }
            catch (ArgumentOutOfRangeException)
            {
#if DEBUG
                Log.WriteLine($"[{sender.RemoteIP}] Index for BOLO not found, not removing...");
#else
                Log.WriteLineSilent($"[{sender.RemoteIP}] Index for BOLO not found, not removing...");
#endif
            }
        }
Esempio n. 13
0
        private async Task EndEmergency(ConnectedPeer sender, BareGuid id)
        {
            await Task.FromResult(0);

#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] End emergency Request Received");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] End emergency Request Received");
#endif

            Calls.Remove(id);                                                                 // removing the id from the calls

            EmergencyCall call = DispatchSystem.CurrentCalls.FirstOrDefault(x => x.Id == id); // obtaining the call from the civ

            if (DispatchSystem.CurrentCalls.Remove(call))                                     // remove, if successful, then notify
            {
                DispatchSystem.Invoke(delegate
                {
                    Player p = Common.GetPlayerByIp(call?.SourceIP);

                    if (p != null)
                    {
                        Common.SendMessage(p, "Dispatch911", new [] { 255, 0, 0 }, "Your 911 call was ended by a Dispatcher");
                    }
                });
            }
        }
Esempio n. 14
0
        private async Task AddNote(ConnectedPeer sender, object[] args)
        {
            await Task.FromResult(0);

            if (CheckAndDispose(sender))
            {
                return;
            }
#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] Add Civilian note Request Recieved");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] Add Civilian note Request Recieved");
#endif

            string[] name = { (string)args[0], (string)args[1] };
            string   note = (string)args[2];

            Civilian civ = Common.GetCivilianByName(name[0], name[1]);

            if (civ != null)
            {
#if DEBUG
                Log.WriteLine($"[{sender.RemoteIP}] Adding the note \"{note}\" to Civilian {civ.First} {civ.Last}");
#else
                Log.WriteLineSilent($"[{sender.RemoteIP}] Adding the note \"{note}\" to Civilian {civ.First} {civ.Last}");
#endif
                civ.Notes.Add(note);
            }
            else
#if DEBUG
            { Log.WriteLine($"[{sender.RemoteIP}] Civilian not found, not adding note..."); }
#else
            { Log.WriteLineSilent($"[{sender.RemoteIP}] Civilian not found, not adding note..."); }
#endif
        }
Esempio n. 15
0
        private bool AcceptEmergency(ConnectedPeer sender, BareGuid id)
        {
#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] Accept emergency Request Received");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] Accept emergency Request Received");
#endif

            // finding the call in the current calls
            EmergencyCall acceptedCall = DispatchSystem.CurrentCalls.FirstOrDefault(x => x.Id == id);
            if (Calls.ContainsKey(id) || acceptedCall == null)
            {
                return(false);              // Checking null and accepted in same expression
            }
            Calls.Add(id, sender.RemoteIP); // adding the call and dispatcher to the call list
            // setting a message for invocation on the main thread
            DispatchSystem.Invoke(delegate
            {
                Player p = Common.GetPlayerByIp(acceptedCall.SourceIP);
                if (p != null)
                {
                    Common.SendMessage(p, "Dispatch911", new [] { 255, 0, 0 }, "Your 911 call has been accepted by a Dispatcher");
                }
            });
            return(true);
        }
Esempio n. 16
0
        private async Task EndEmergency(ConnectedPeer sender, object[] args)
        {
            await Task.FromResult(0);

            if (CheckAndDispose(sender))
            {
                return;
            }

#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] End emergency Request Received");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] End emergency Request Received");
#endif

            Guid id = (Guid)args[0];
            Calls.Remove(id);

            EmergencyCall call = DispatchSystem.currentCalls.Find(x => x.Id == id);

            if (DispatchSystem.currentCalls.Remove(call))
            {
                DispatchSystem.Invoke(delegate
                {
                    Player p = Common.GetPlayerByIp(call?.SourceIP);

                    if (p != null)
                    {
                        Common.SendMessage(p, "Dispatch911", new [] { 255, 0, 0 }, "Your 911 call was ended by a Dispatcher");
                    }
                });
            }
        }
Esempio n. 17
0
        public static void EndEmergency(string handle)
        {
            Player p = GetPlayerByHandle(handle);

            EmergencyCall call = GetEmergencyCall(handle);

            if (call == null)
            {
                SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "There is no 911 call to end!");
                return;
            }

#if DEBUG
            SendMessage(p, "", new[] { 0, 0, 0 }, "Ending 911 call...");
#endif

            string        dispatcherIp = server.Calls[call.Id];
            ConnectedPeer peer         = server.ConnectedDispatchers.First(x => x.RemoteIP == dispatcherIp);
#pragma warning disable 4014
            peer.TryTriggerNetEvent("end" + call.Id);
#pragma warning restore 4014

            currentCalls.Remove(call);
            SendMessage(p, "Dispatch911", new[] { 255, 0, 0 }, "Ended the 911 call");
        }
Esempio n. 18
0
        private static async Task InvalidPerms(ConnectedPeer peer, dynamic i)
        {
            await Task.FromResult(0);

            MessageBox.Show("You seem to have invalid permissions", "DispatchSystem", MessageBoxButtons.OK,
                            MessageBoxIcon.Asterisk);
            Environment.Exit(-13);
        }
Esempio n. 19
0
        private async Task End911(ConnectedPeer peer, object[] data)
        {
            await Task.FromResult(0);

            MessageBox.Show("User has ended 911 call", "DispatchSystem", MessageBoxButtons.OK,
                            MessageBoxIcon.Information);
            Invoke((MethodInvoker)Close);
        }
Esempio n. 20
0
        private static async Task Alert911(ConnectedPeer peer, Civilian civ, EmergencyCall call)
        {
            await Task.FromResult(0);

            mainWindow.Invoke((MethodInvoker) delegate
            {
                new Accept911(civ, call).Show();
            });
        }
Esempio n. 21
0
        private async Task ChangeOfficerStatus(ConnectedPeer sender, object[] args)
        {
            await Task.FromResult(0);

            if (CheckAndDispose(sender))
            {
                return;
            }

#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] Change officer status Request Received");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] Change officer status Request Received");
#endif

            Officer       ofc    = (Officer)args[0];
            OfficerStatus status = (OfficerStatus)args[1];

            ofc = DispatchSystem.officers.ToList().Find(x => x.Id == ofc.Id);
            var index = DispatchSystem.officers.IndexOf(ofc);
            if (index == -1)
            {
                return;
            }

            Officer ourOfc = DispatchSystem.officers[index];

            if (ourOfc.Status != status)
            {
                ourOfc.Status = status;
#if DEBUG
                Log.WriteLine($"[{sender.RemoteIP}] Setting officer status to " + status.ToString());
#else
                Log.WriteLineSilent($"[{sender.RemoteIP}] Setting officer status to " + status.ToString());
#endif

                DispatchSystem.Invoke(() =>
                {
                    Player p = Common.GetPlayerByIp(ourOfc.SourceIP);
                    if (p != null)
                    {
                        Common.SendMessage(p, "^8DispatchCAD", new[] { 0, 0, 0 },
                                           $"Dispatcher set status to {(ofc.Status == OfficerStatus.OffDuty ? "Off Duty" : ofc.Status == OfficerStatus.OnDuty ? "On Duty" : "Busy")}");
                    }
                });
            }
            else
            {
#if DEBUG
                Log.WriteLine($"[{sender.RemoteIP}] Officer status already set to the incoming status");
#else
                Log.WriteLineSilent($"[{sender.RemoteIP}] Officer status already set to the incoming status");
#endif
            }
        }
        private void LoadDevicesToDisconected()
        {
            var devices = DeviceManager.LoadDevices();

            foreach (var dev in devices)
            {
                var peer = new ConnectedPeer();
                peer.MacAddress = dev.MacAddress;
                panelConnectionsPreviously.Children.Add(new PeerDeviceView(peer));
            }
        }
Esempio n. 23
0
        private static async Task OnConnect(ConnectedPeer user)
        {
            await Task.Run(delegate
            {
#if DEBUG
                Log.WriteLine($"[{user.RemoteIP}] Connected");
#else
                Log.WriteLineSilent($"[{user.RemoteIP}] Connected");
#endif
            });
        }
Esempio n. 24
0
        public async Task ConnectPeer(PeerConnectInformation connectInfo)
        {
            var remoteEndpoint = connectInfo.CreateConnectEndpoint();
            var connectSocket  = new TcpClient();
            await connectSocket.ConnectAsync(remoteEndpoint.Address, remoteEndpoint.Port);

            // Create new connected client
            var connPeer = new ConnectedPeer(connectSocket, remoteEndpoint);

            PeerConnected?.Invoke(this, new PeerConnectedEventArgs(connPeer));
        }
Esempio n. 25
0
        private async Task <object> GetAssignments(ConnectedPeer sender)
        {
            await Task.FromResult(0);

#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] Get assignments Request Received");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] Get assignments Request Received");
#endif

            return(DispatchSystem.Assignments);
        }
Esempio n. 26
0
        private Officer GetOfficer(ConnectedPeer sender, BareGuid id)
        {
#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] Get officer Request Received");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] Get officer Request Received");
#endif

            // finding the officer from the list
            Officer ofc = DispatchSystem.Officers.ToList().Find(x => x.Id == id);
            return(ofc);
        }
Esempio n. 27
0
        private async Task <object> GetOfficers(ConnectedPeer sender)
        {
            await Task.FromResult(0);

#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] Get officers Request Received");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] Get officers Request Received");
#endif

            return(global::DispatchSystem.Server.Main.Core.Officers);
        }
Esempio n. 28
0
        private static async Task OnDisconnect(ConnectedPeer user, DisconnectionType type)
        {
            await Task.Run(delegate
            {
                // logging the ip disconnected
#if DEBUG
                Log.WriteLine($"[{user.RemoteIP}] Disconnected");
#else
                Log.WriteLineSilent($"[{user.RemoteIP}] Disconnected");
#endif
            });
        }
Esempio n. 29
0
        public PeerDevice(ConnectedPeer peer)
        {
            InitializeComponent();

            this.ContextMenu = new ContextMenu();
            var propertiesMenuItem = new MenuItem();
            propertiesMenuItem.Header = "_Properties...";
            propertiesMenuItem.Click+=new System.Windows.RoutedEventHandler(PropertiesMenuItem_Click);
            this.ContextMenu.Items.Add(propertiesMenuItem);

            this.Peer = peer;
        }
Esempio n. 30
0
        public readonly string[] ExtensionIds; // nullable  // not null only for requests

        /// <summary>
        /// creates packet for transmission to peer
        /// </summary>
        /// <param name="connectedPeer">destination</param>
        /// <param name="stream">destination</param>
        public PeerHelloPacket(LocalPeer localPeer, ConnectedPeer connectedPeer, ConnectedPeerStream stream, PeerHelloRequestStatus status)
        {
            LibraryVersion  = CompilationInfo.CompilationDateTimeUtc_uint32;
            ProtocolVersion = P2ptpCommon.ProtocolVersion;
            FromPeerId      = localPeer.LocalPeerId;
            ExtensionIds    = localPeer.Configuration.Extensions?.Select(x => x.ExtensionId).ToArray();
            StreamId        = stream.StreamId;
            ToPeerId        = connectedPeer.RemotePeerId;
            Status          = status;
            RequestTime32   = localPeer.Time32;
            RoleFlags       = localPeer.Configuration.RoleAsUser ? (byte)0x01 : (byte)0x00;
        }
Esempio n. 31
0
        private async Task RemoveAssignment(ConnectedPeer sender, BareGuid id)
        {
            await Task.FromResult(0);

#if DEBUG
            Log.WriteLine($"[{sender.RemoteIP}] Remove assignment Request Received");
#else
            Log.WriteLineSilent($"[{sender.RemoteIP}] Remove assignment Request Received");
#endif

            Assignment item2 = DispatchSystem.Assignments.FirstOrDefault(x => x.Id == id); // finding the assignment from the id
            Common.RemoveAllInstancesOfAssignment(item2);                                  // removing using common
        }
        private void removeDisconnectedPeers(ConnectedPeer[] peers)
        {
            List<PeerDevice> peersToRemove = new List<PeerDevice>();

            foreach (var element in panelConnections.Children)
            {
                var elem = element as PeerDevice;
                if (elem != null)
                {
                    var exists = false;
                    foreach (var p in peers)
                    {
                        if (p.MacAddress.ToLowerInvariant() == elem.Peer.MacAddress.ToLowerInvariant())
                        {
                            exists = true;
                            break;
                        }
                    }
                    if (!exists)
                    {
                        peersToRemove.Add(elem);
                    }
                }
            }
            foreach (var elem in peersToRemove)
            {
                panelConnections.Children.Remove(elem);
            }
        }
 private bool isPeerAlreadyConnected(ConnectedPeer peer)
 {
     foreach (var element in panelConnections.Children)
     {
         var elem = element as PeerDevice;
         if (elem != null)
         {
             if (elem.Peer.MacAddress.ToLowerInvariant() == peer.MacAddress.ToLowerInvariant())
             {
                 return true;
             }
         }
     }
     return false;
 }
Esempio n. 34
0
        // Start the send receive operations
        void PeerFinder_StartSendReceive(StreamSocket socket, PeerInformation peerInformation)
        {
            ConnectedPeer connectedPeer = new ConnectedPeer(socket, false, new Windows.Storage.Streams.DataWriter(socket.OutputStream));
            _socketHelper.Add(connectedPeer);

            if (!_peerFinderStarted)
            {
                _socketHelper.CloseSocket();
                return;
            }

            PeerFinder_ConnectionGrid.Visibility = Visibility.Visible;
            PeerFinder_SendButton.Visibility = Visibility.Visible;
            PeerFinder_MessageBox.Visibility = Visibility.Visible;
            PeerFinder_SendToPeerList.Visibility = Visibility.Visible;

            if (peerInformation != null)
            {
                // Add a new peer to the list of peers.
                ComboBoxItem item = new ComboBoxItem();
                item.Content = peerInformation.DisplayName;
                PeerFinder_SendToPeerList.Items.Add(item);
                PeerFinder_SendToPeerList.SelectedIndex = 0;
            }

            // Hide the controls related to setting up a connection
            PeerFinder_AcceptButton.Visibility = Visibility.Collapsed;
            PeerFinder_BrowseGrid.Visibility = Visibility.Collapsed;
            PeerFinder_AdvertiseGrid.Visibility = Visibility.Collapsed;

            _socketHelper.StartReader(connectedPeer);
        }