예제 #1
0
        public static void AddOfficer(string handle, string callsign)
        {
            Player p = GetPlayerByHandle(handle);

            // checking if civ exists
            if (GetCivilian(handle) != null)
            {
                SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 },
                            "You cannot be a officer and a civilian at the same time.");
                return;
            }

            // check for officer existing
            if (GetOfficer(handle) == null)
            {
                Officers.Add(new Officer(p.Identifiers["ip"], callsign));                                              // adding new officer
                SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, $"Assigning new officer for callsign {callsign}"); // msg
#if DEBUG
                SendMessage(p, "", new[] { 0, 0, 0 }, "Creating new Officer profile...");
#endif
            }
            else
            {
                int index = Officers.IndexOf(GetOfficer(handle));                                             // finding the index
                Officers[index] = new Officer(p.Identifiers["ip"], callsign);                                 // setting the index to the specified officer
                SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, $"Changing your callsign to {callsign}"); // msg
            }
        }
예제 #2
0
 public void Pack(BinaryWriter writer)
 {
     writer.Write(RecordCount);
     writer.Write((ushort)0x000B); // Unused value
     Officers.Pack(writer);
     OfficerTitles.Pack(writer);
     writer.Write(MonarchBroadcastTime);
     writer.Write(MonarchBroadcastsToday);
     writer.Write(SpokesBroadcastTime);
     writer.Write(SpokesBroadcastsToday);
     writer.WriteString16L(Motd);
     writer.WriteString16L(MotdSetBy);
     writer.Write(ChatRoomID);
     Bindpoint.Pack(writer);
     writer.WriteString16L(AllegianceName);
     writer.Write(NameLastSetTime);
     writer.WriteBool32(IsLocked);
     writer.Write(ApprovedVassal);
     if (RecordCount > 0)
     {
         MonarchData.Pack(writer);
         for (int i = 0; i < RecordCount - 1; i++)
         {
             Records[i].Pack(writer);
         }
     }
 }
예제 #3
0
        public static void DispatchReset(string handle)
        {
            Player p = GetPlayerByHandle(handle);

            if (GetCivilian(p.Handle) != null)
            {
#if DEBUG
                SendMessage(p, "", new [] { 0, 0, 0 }, "Removing Civilian Profile...");
#endif
                Civs.Remove(GetCivilian(p.Handle)); // removing instance of civilian
            }
            if (GetCivilianVeh(p.Handle) != null)
            {
#if DEBUG
                SendMessage(p, "", new[] { 0, 0, 0 }, "Removing Civilian Vehicle Profile...");
#endif
                CivVehs.Remove(GetCivilianVeh(p.Handle)); // removing instance of vehicle
            }
            if (GetOfficer(p.Handle) != null)
            {
#if DEBUG
                SendMessage(p, "", new[] { 0, 0, 0 }, "Removing Officer Profile...");
#endif
                Officers.Remove(GetOfficer(p.Handle)); // removing instance of officer
            }

            SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "All profiles reset"); // displaying the reset message
        }
예제 #4
0
 public static void LoadOfficers()
 {
     Officers.Clear();
     using (var db = new UnitOfWork())
     {
         try
         {
             var officers = db.OfficersRepo.FindAll().ToList();
             if (officers.Count == 0)
             {
                 return;
             }
             foreach (var officer in officers)
             {
                 Officers.Add(officer);
             }
         }
         catch (EntityException ex)
         {
             ExceptionHandler.LogAndNotifyOfException(ex, ex.Message);
         }
         catch (Exception ex)
         {
             ExceptionHandler.LogAndNotifyOfException(ex, ex.Message);
         }
     }
 }
예제 #5
0
 public void UpdateOfficer(Officers officer)
 {
     using (var db = new LiteDatabase(connectionString))
     {
         var col = db.GetCollection <Officers>("Officers");
         col.Update(officer);
     }
 }
예제 #6
0
 public void AddOfficer(Officers officer)
 {
     using (var db = new LiteDatabase(connectionString))
     {
         var col = db.GetCollection <Officers>("Officers");
         officer.Id = Guid.NewGuid();
         col.Insert(officer);
     }
 }
예제 #7
0
        private bool Filter(object item)
        {
            Officers officer = item as Officers;

            if (officer.OfficerGrade.Equals(GradeOfNewOfficer))
            {
                return(true);
            }
            return(false);
        }
예제 #8
0
        /// <summary>
        /// Loads the officers from the backend server.
        /// </summary>
        /// <returns></returns>
        protected override async Task LoadItemsAsync()
        {
            await Task.Delay(2000);

            try
            {
                // Make async request to obtain data
                var client  = new RestClient(GlobalConstants.EndPointURL);
                var request = new RestRequest
                {
                    Timeout = GlobalConstants.RequestTimeout
                };
                request.Resource = String.Format(GlobalConstants.OfficerEndPointRequestURL, Level);
                UserManager.Current.AddAuthorization(request);

                try
                {
                    DataAvailable = false;

                    var response = await client.ExecuteCachedAPITaskAsync(request, GlobalConstants.MaxCacheOfficers, false, true);

                    ErrorMessage = response.ErrorMessage;
                    IsError      = !response.IsSuccessful;

                    if (response.IsSuccessful)
                    {
                        var items = JsonConvert.DeserializeObject <List <Officer> >(response.Content) ?? new List <Officer>();


                        Officers.Clear();

                        foreach (var officer in items)
                        {
                            Officers.Add(officer);
                        }

                        OnPropertyChanged("Officers");

                        DataAvailable = Officers.Count > 0;
                    }
                }
                catch (Exception e)
                {
                    var properties = new Dictionary <string, string> {
                        { "Category", "Officers" }
                    };
                    Crashes.TrackError(e, properties);
                }
            }
            catch (Exception)
            {
                // An exception occurred
                DataAvailable = false;
            }
        }
        public async Task <IHttpActionResult> Register(RegisterBindingModel model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var user = new ApplicationUser()
            {
                UserName = model.UserName, Email = model.Email
            };
            IdentityResult result = await UserManager.CreateAsync(user, model.Password);

            if (!result.Succeeded)
            {
                return(GetErrorResult(result));
            }
            else
            {
                await UserManager.AddToRoleAsync(user.Id, model.UserRoles);

                Officers NewOfficer = new Officers()
                {
                    OfficerId   = user.Id,
                    VnpfNo      = model.VnpfNo,
                    LoanNo      = model.LoanNo,
                    EmpFname    = model.EmpFname,
                    EmpMname    = model.EmpMname,
                    EmpLname    = model.EmpLname,
                    DateCreated = model.DateCreated
                };

                db.Officers.Add(NewOfficer);
                try
                {
                    await db.SaveChangesAsync();
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Error Message: " + ex);
                }
            }

            return(Ok());
        }
예제 #10
0
        public async Task <CompaniesHouseClientResponse <Officers> > GetOfficersAsync(string companyNumber, int startIndex, int pageSize, CancellationToken cancellationToken = default(CancellationToken))
        {
            using (var httpClient = _httpClientFactory.CreateHttpClient())
            {
                var requestUri = _officersUriBuilder.Build(companyNumber, startIndex, pageSize);

                var response = await httpClient.GetAsync(requestUri, cancellationToken).ConfigureAwait(false);

                // Return a null profile on 404s, but raise exception for all other error codes
                if (response.StatusCode != System.Net.HttpStatusCode.NotFound)
                {
                    response.EnsureSuccessStatusCode();
                }

                Officers result = response.IsSuccessStatusCode
                    ? await response.Content.ReadAsAsync <Officers>(cancellationToken).ConfigureAwait(false)
                    : null;

                return(new CompaniesHouseClientResponse <Officers>(result));
            }
        }
예제 #11
0
        public void Unpack(BinaryReader reader)
        {
            RecordCount = reader.ReadUInt16();
            var temp1 = reader.ReadUInt16(); // Unused value

#if NETWORKVALIDATION
            if (temp1 != 0x000B)
            {
                throw new Exception("Recieved value different from static on AllegianceHierarchy, expected: 0x000B, actual " + temp1);
            }
#endif
            Officers.Unpack(reader);
            OfficerTitles.Unpack(reader);
            MonarchBroadcastTime   = reader.ReadInt32();
            MonarchBroadcastsToday = reader.ReadUInt32();
            SpokesBroadcastTime    = reader.ReadInt32();
            SpokesBroadcastsToday  = reader.ReadUInt32();
            Motd       = reader.ReadString16L();
            MotdSetBy  = reader.ReadString16L();
            ChatRoomID = reader.ReadUInt32();
            Bindpoint.Unpack(reader);
            AllegianceName  = reader.ReadString16L();
            NameLastSetTime = reader.ReadInt32();
            IsLocked        = reader.ReadBool32();
            ApprovedVassal  = reader.ReadUInt32();
            if (RecordCount > 0)
            {
                MonarchData.Unpack(reader);
                Records.Clear();
                for (int i = 0; i < RecordCount - 1; i++)
                {
                    AllegianceNode newItem = new AllegianceNode();
                    newItem.Unpack(reader);
                    Records.Add(newItem);
                }
            }
        }
예제 #12
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");
            }
        }
예제 #13
0
 public static Officer GetOfficer(string pHandle)
 {
     return(Officers.FirstOrDefault(item => GetPlayerByIp(item.SourceIP)?.Handle == pHandle)); // Finding the first officer with that handle
 }
예제 #14
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 }));
        }