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);
                }
            });
        }
        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);
        }
        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");
                    }
                });
            }
        }
Beispiel #4
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");
                }
            });
        }
Beispiel #5
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}\"");
                }
            });
        }
Beispiel #6
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");
                    }
                });
            }
        }
Beispiel #7
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);
        }
        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 async Task RemoveOfficer(ConnectedPeer sender, object[] args)
        {
            await Task.FromResult(0);

            if (CheckAndDispose(sender))
            {
                return;
            }

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

            Guid ofcGiven = (Guid)args[0];

            Officer ofc = DispatchSystem.officers.ToList().Find(x => x.Id == ofcGiven);
            if (ofc != null)
            {
                DispatchSystem.Invoke(delegate
                {
                    Player p = Common.GetPlayerByIp(ofc.SourceIP);

                    if (p != null)
                    {
                        Common.SendMessage(p, "^8DispatchCAD", new[] { 0, 0, 0 }, "You have been removed from your officer role by a dispatcher");
                    }
                });

                DispatchSystem.officers.Remove(ofc);

#if DEBUG
                Log.WriteLine($"[{sender.RemoteIP}] Removed the officer from the list of officers");
#else
                Log.WriteLineSilent($"[{sender.RemoteIP}] Removed the officer from the list of officers");
#endif
            }
            else
            {
#if DEBUG
                Log.WriteLine($"[{sender.RemoteIP}] Officer in list not found, not removing");
#else
                Log.WriteLineSilent($"[{sender.RemoteIP}] Officer in list not found, not removing");
#endif
            }
        }
Beispiel #10
0
        private async Task ChangeOfficerStatus(ConnectedPeer sender, BareGuid id, OfficerStatus status)
        {
            await Task.FromResult(0);

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

            // finding the officer
            Officer ofc = DispatchSystem.Officers.FirstOrDefault(x => x.Id == id);

            if (ofc is null)
            {
                return;              // checking for null
            }
            if (ofc.Status != status)
            {
                ofc.Status = status; // changing the status
#if DEBUG
                Log.WriteLine($"[{sender.RemoteIP}] Setting officer status to " + status);
#else
                Log.WriteLineSilent($"[{sender.RemoteIP}] Setting officer status to " + status);
#endif

                DispatchSystem.Invoke(() =>
                {
                    Player p = Common.GetPlayerByIp(ofc.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
            }
        }
Beispiel #11
0
        private async Task RemoveOfficer(ConnectedPeer sender, BareGuid id)
        {
            await Task.FromResult(0);

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

            // getting the officer
            Officer ofc = DispatchSystem.Officers.FirstOrDefault(x => x.Id == id);
            if (ofc != null)
            {
                // notify of removing of role
                DispatchSystem.Invoke(delegate
                {
                    Player p = Common.GetPlayerByIp(ofc.SourceIP);

                    if (p != null)
                    {
                        Common.SendMessage(p, "^8DispatchCAD", new[] { 0, 0, 0 }, "You have been removed from your officer role by a dispatcher");
                    }
                });

                // actually remove the officer from the list
                DispatchSystem.Officers.Remove(ofc);

#if DEBUG
                Log.WriteLine($"[{sender.RemoteIP}] Removed the officer from the list of officers");
#else
                Log.WriteLineSilent($"[{sender.RemoteIP}] Removed the officer from the list of officers");
#endif
            }
            else
            {
#if DEBUG
                Log.WriteLine($"[{sender.RemoteIP}] Officer in list not found, not removing");
#else
                Log.WriteLineSilent($"[{sender.RemoteIP}] Officer in list not found, not removing");
#endif
            }
        }
        private async Task AddOfcAssignment(ConnectedPeer sender, object[] args)
        {
            await Task.FromResult(0);

            if (CheckAndDispose(sender))
            {
                return;
            }

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

            Guid id    = (Guid)args[0];
            Guid ofcId = (Guid)args[1];

            Assignment assignment = DispatchSystem.assignments.Find(x => x.Id == id);
            Officer    ofc        = DispatchSystem.officers.ToList().Find(x => x.Id == ofcId);
            if (assignment is null || ofc is null)
            {
                return;
            }
            if (DispatchSystem.ofcAssignments.ContainsKey(ofc))
            {
                return;
            }

            DispatchSystem.ofcAssignments.Add(ofc, assignment);

            ofc.Status = OfficerStatus.OffDuty;

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

            if (CheckAndDispose(sender))
            {
                return;
            }

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

            Guid    ofcId = (Guid)args[0];
            Officer ofc   = DispatchSystem.officers.ToList().Find(x => x.Id == ofcId);
            if (ofc == null)
            {
                return;
            }

            if (!DispatchSystem.ofcAssignments.ContainsKey(ofc))
            {
                return;
            }
            DispatchSystem.ofcAssignments.Remove(ofc);

            ofc.Status = OfficerStatus.OnDuty;

            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");
                }
            });
        }
Beispiel #14
0
        private async Task MessageEmergency(ConnectedPeer sender, BareGuid id, string msg)
        {
            await Task.FromResult(0);

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

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

            DispatchSystem.Invoke(() =>
            {
                Player p = Common.GetPlayerByIp(call?.SourceIP); // getting the player from the call's ip

                if (p != null)
                {
                    Common.SendMessage(p, "Dispatcher", new [] { 0x0, 0xff, 0x0 }, msg);
                }
            });
        }