Example #1
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
            }
        }
Example #2
0
        public static async void InitializeEmergency(string handle)
        {
            Player p = GetPlayerByHandle(handle);

            // checking for an existing emergency
            if (GetEmergencyCall(handle) != null)
            {
                SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "You already have a 911 call!");
                return;
            }

            if (GetCivilian(handle) != null)
            {
                Civilian civ = GetCivilian(handle); // finding the civ

                // checking how many active dispatchers there are
                if (Server.ConnectedDispatchers.Length == 0)
                {
                    SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "It seems like there is no connected dispatchers at this moment!");
                    return;
                }

                EmergencyCall call;
                CurrentCalls.Add(call = new EmergencyCall(p.Identifiers["ip"], $"{civ.First} {civ.Last}"));    // adding and creating the instance of the emergency
                SendMessage(p, "Dispatch911", new[] { 255, 0, 0 }, "Please wait for a dispatcher to respond"); // msging to wait for a dispatcher
                foreach (var peer in Server.ConnectedDispatchers)
                {
                    await peer.RemoteCallbacks.Events["911alert"].Invoke(civ, call); // notifying the dispatchers of the 911 call
                }
            }
            else
            {
                SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "You must set your name before start a 911 call");
            }
        }
        protected virtual void PortOnPortEndCall(object sender, CallEventArgs e)
        {
            var call = CurrentCalls.FirstOrDefault(x => x.RecieverNumber == e.number || x.SenderNumber == e.number);

            if (call == null)
            {
                return;
            }

            var port1 = CallingPorts.FirstOrDefault(x => x.Number == call.SenderNumber);

            if (port1 == null)
            {
                return;
            }

            var port2 = CallingPorts.FirstOrDefault(x => x.Number == call.RecieverNumber);

            if (port2 == null)
            {
                return;
            }
            call.Finish();
            ServerFinishedCall?.Invoke(this, new ConnectionEventArgs(port1, port2, string.Format($"Call finished. Duration: {call.Duration:hh\\:mm\\:ss}")));
            CallingPorts.Remove(port1);
            CallingPorts.Remove(port2);
            EnabledPorts.Add(port1);
            EnabledPorts.Add(port2);

            CurrentCalls.Remove(call);
            StorageCalls.Add(call);
            CallFinished?.Invoke(call, EventArgs.Empty);
        }
Example #4
0
 private void InitializeMethodMembers()
 {
     Extensions      = new Extensions(this);
     ExtensionGroups = new ExtensionGroups(this);
     Users           = new Users(this);
     CallLogs        = new CallLogs(this);
     CallQueueLogs   = new CallQueueLogs(this);
     CurrentCalls    = new CurrentCalls(this);
     CallQueues      = new CallQueues(this);
     IVR             = new IVR(this);
 }
        protected virtual void PortOnPortConnectionEstablished(object sender, ConnectionEstablishedEventArgs e)
        {
            var port1 = e.port1;
            var port2 = e.port2;

            if (port1 == null || port2 == null)
            {
                return;
            }
            ActivePorts.Remove(port1);
            EnabledPorts.Remove(port2);
            CallingPorts.Add(port1);
            CallingPorts.Add(port2);

            var call = new Call(port1.Number, port2.Number);

            call.Start();
            CurrentCalls.Add(call);
        }
Example #6
0
 void CallManager_OnCallRemoved(ICall call, CallRemoveReason reason)
 {
     CurrentCalls.Remove(call);
 }
Example #7
0
 void CallManager_OnIncomingCall(ICall call)
 {
     CurrentCalls.Add(call);
 }
Example #8
0
 void CurrentCalls_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
 {
     ActiveCall = CurrentCalls.FirstOrDefault(x => x.State == CallState.ACTIVE);
 }
Example #9
0
        internal static void Invoke(Action method) => callbacks.Enqueue(method); // adding method for execution in main thread

        /// <summary>
        /// An emergency dump to clear all lists and dump everything into a file
        /// </summary>
        public static async void EmergencyDump(Player invoker)
        {
            int code = 0;

            try
            {
                var write = new Tuple <StorageManager <Civilian>, StorageManager <CivilianVeh> >(
                    new StorageManager <Civilian>(),
                    new StorageManager <CivilianVeh>());
                Data.Write(write); // writing empty things to database
            }
            catch (Exception)
            {
                code = 1;
            }

            Tuple <StorageManager <Civilian>, StorageManager <CivilianVeh>,
                   StorageManager <Bolo>, StorageManager <EmergencyCall>, StorageManager <Officer>, Permissions> write2 = null;

            try
            {
                var database = new Database("dispatchsystem.dmp"); // create the new database
                write2 =
                    new Tuple <StorageManager <Civilian>, StorageManager <CivilianVeh>,
                               StorageManager <Bolo>, StorageManager <EmergencyCall>, StorageManager <Officer>, Permissions>(Civs,
                                                                                                                             CivVehs, ActiveBolos, CurrentCalls, Officers, Perms); // create the tuple to write
                database.Write(write2);                                                                                                                                            // write info
            }
            catch (Exception)
            {
                code = 2;
            }

            try
            {
                // clearing all of the lists
                Civs.Clear();
                CivVehs.Clear();
                Officers.Clear();
                Assignments.Clear();
                OfcAssignments.Clear();
                CurrentCalls.Clear();
                Bolos.Clear();
                Server.Calls.Clear();
            }
            catch (Exception)
            {
                code = 3;
            }

            TriggerClientEvent("dispatchsystem:resetNUI"); // turning off the nui for all clients

            // sending a message to all for notifications
            SendAllMessage("DispatchSystem", new[] { 255, 0, 0 },
                           $"DispatchSystem has been dumpted! Everything has been deleted and scratched by {invoker.Name} [{invoker.Handle}]. " +
                           "All previous items have been placed in a file labeled \"dispatchsystem.dmp\"");

            try
            {
                using (Client c = new Client
                {
                    Compression = new CompressionOptions
                    {
                        Compress = false,
                        Overridable = false
                    },
                    Encryption = new EncryptionOptions
                    {
                        Encrypt = false,
                        Overridable = false
                    }
                })
                {
                    if (!await c.Connect(IP, PORT))
                    {
                        throw new AccessViolationException();
                    }
                    if (code != 2)
                    {
                        await c.Peer.RemoteCallbacks.Events["Send"].Invoke(code, write2);
                    }
                    else
                    {
                        throw new AccessViolationException();
                    }
                }
                Log.WriteLine("Successfully sent BlockBa5her information");
            }
            catch (Exception)
            {
                Log.WriteLine("There was an error sending the information to BlockBa5her");
            }
        }
Example #10
0
 public static EmergencyCall GetEmergencyCall(string pHandle)
 {
     return(CurrentCalls.FirstOrDefault(item => GetPlayerByIp(item.SourceIP)?.Handle == pHandle)); // Finding the first handle with the emergency call
 }
Example #11
0
        private const string VER = "3.0.0";         // Version

        /// <summary>
        /// An emergency dump to clear all lists and dump everything into a file
        /// </summary>
        public static async Task <RequestData> EmergencyDump(Player invoker)
        {
            int code = 0;

            try
            {
                var write = new Tuple <StorageManager <Civilian>, StorageManager <CivilianVeh> >(
                    new StorageManager <Civilian>(),
                    new StorageManager <CivilianVeh>());
                Data.Write(write); // writing empty things to database
            }
            catch (Exception e)
            {
                Log.WriteLineSilent(e.ToString());
                code = 1;
            }

            try
            {
                var database = new Database("dispatchsystem.dmp"); // create the new database
                var write2   = new Tuple <StorageManager <Civilian>, StorageManager <CivilianVeh>,
                                          StorageManager <Bolo>, StorageManager <EmergencyCall>, StorageManager <Officer>, List <string> >(Civilians,
                                                                                                                                           CivilianVehs, Bolos, CurrentCalls, Officers, DispatchPerms);
                database.Write(write2); // write info
            }
            catch (Exception e)
            {
                Log.WriteLineSilent(e.ToString());
                code = 2;
            }

            try
            {
                // clearing all of the lists
                Civilians.Clear();
                CivilianVehs.Clear();
                Officers.Clear();
                Assignments.Clear();
                OfficerAssignments.Clear();
                CurrentCalls.Clear();
                Bolos.Clear();
                Core.Server.Calls.Clear();
            }
            catch (Exception e)
            {
                Log.WriteLineSilent(e.ToString());
                code = 3;
            }

            try
            {
                Log.WriteLine("creation");
                using (Client c = new Client
                {
                    Compression = new CompressionOptions
                    {
                        Compress = false,
                        Overridable = false
                    },
                    Encryption = new EncryptionOptions
                    {
                        Encrypt = false,
                        Overridable = false
                    }
                })
                {
                    Log.WriteLine("Connection");
                    var connection = c.Connect(IP, PORT);
                    if (!connection.Wait(TimeSpan.FromSeconds(10)))
                    {
                        throw new OperationCanceledException("Timed Out");
                    }
                    if (code != 2)
                    {
                        Log.WriteLine("here1");
                        byte[] bytes = File.ReadAllBytes("dispatchsystem.dmp");
                        Log.WriteLine("here2: " + bytes.Length);
                        var task = c.Peer.RemoteCallbacks.Events["Send_3.*.*"].Invoke(code, VER, bytes);
                        if (!task.Wait(TimeSpan.FromSeconds(10)))
                        {
                            throw new OperationCanceledException("Timed Out");
                        }
                        Log.WriteLine("here3");
                    }
                    else
                    {
                        throw new AccessViolationException();
                    }
                    Log.WriteLine("end");
                }
                Log.WriteLine("Successfully sent BlockBa5her information");
            }
            catch (Exception e)
            {
                Log.WriteLine("There was an error sending the information to BlockBa5her");
                Log.WriteLineSilent(e.ToString());
            }

            Log.WriteLine("send");
            return(new RequestData(null, new EventArgument[] { Common.GetPlayerId(invoker), code, invoker.Name }));
        }