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 }
public static void SetName(string handle, string first, string last) { Player p = GetPlayerByHandle(handle); if (GetOfficer(handle) != null) // checking if the civilian has an officer { SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "You cannot be an officer and a civilian at the same time!"); return; // return if they do } if (GetCivilianByName(first, last) != null && GetPlayerByIp(GetCivilianVeh(handle).SourceIP) != p) // checking if the name already exists in the system { SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "That name already exists in the system!"); return; // return if it does } // checking if the civilian already has a civ in the system if (GetCivilian(handle) != null) { int index = Civs.IndexOf(GetCivilian(handle)); // finding the index of the existing civ Civs[index] = new Civilian(p.Identifiers["ip"]) { First = first, Last = last }; // setting the index to an instance of a new civilian SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, $"New name set to: {Civs[index].First} {Civs[index].Last}"); // saying the new name created } else // if the civ doesn't exist { Civs.Add(new Civilian(p.Identifiers["ip"]) { First = first, Last = last }); // add a new civilian to the system int index = Civs.IndexOf(GetCivilian(handle)); // find the index of the civ SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, $"New name set to: {Civs[index].First} {Civs[index].Last}"); // say the new name was created #if DEBUG SendMessage(p, "", new[] { 0, 0, 0 }, "Creating new civilian profile..."); #endif } if (GetCivilianVeh(handle) != null) { // below basically resets the vehicle if it exists int index = CivVehs.IndexOf(GetCivilianVeh(handle)); CivVehs[index] = new CivilianVeh(p.Identifiers["ip"]); } }
public static void SetVehicle(string handle, string plate) { Player p = GetPlayerByHandle(handle); // if no civilian exists if (GetCivilian(handle) == null) { SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "You must set your name before you can set your vehicle"); return; } // checking if the plate already exists in the system if (GetCivilianVehByPlate(plate) != null && GetPlayerByIp(GetCivilianVeh(handle).SourceIP) != p) { SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "That vehicle already exists in the system!"); return; } // checking if player already owns a vehicle if (GetCivilianVeh(handle) != null) { int index = CivVehs.IndexOf(GetCivilianVeh(handle)); // finding the existing index CivVehs[index] = new CivilianVeh(p.Identifiers["ip"]) { Plate = plate, Owner = GetCivilian(handle) }; // setting the index to a new vehicle item SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, $"New vehicle set to {CivVehs[index].Plate}"); // msg of creation } else { CivilianVeh veh = new CivilianVeh(p.Identifiers["ip"]) { Plate = plate, Owner = GetCivilian(handle) }; // creating the new vehicle CivVehs.Add(veh); // adding the new vehicle to the list of vehicles SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, $"New vehicle set to {veh.Plate}"); // msg } }
public static void ToggleVehicleStolen(string handle) { Player p = GetPlayerByHandle(handle); // checking if player has a name if (GetCivilian(handle) == null) { SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "You must set your name before you can set your vehicle stolen"); return; } // checking if vehicle exists if (GetCivilianVeh(handle) != null) { int index = CivVehs.IndexOf(GetCivilianVeh(handle)); // finding index of vehicle CivVehs[index].StolenStatus = !CivVehs[index].StolenStatus; // toggle stolen if (CivVehs[index].StolenStatus) // checking if it is stolen { Civilian civ = Civilian.CreateRandomCivilian(); // creating a new random civ CivVehs[index].Owner = civ; // setting the vehicle owner to the civ Civs.Add(civ); // adding the civ to the database } else { Civilian civ = CivVehs[index].Owner; // finding the existing civ Civs.Remove(civ); // removing the civ from the database CivVehs[index].Owner = GetCivilian(handle); // setting the owner to the person } SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, $"Stolen status set to {CivVehs[index].StolenStatus}"); } else { SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "You must set your vehicle before you can set your vehicle stolen"); } }
public static void ToggleVehicleInsurance(string handle) { Player p = GetPlayerByHandle(handle); // checking for existing civ if (GetCivilian(handle) == null) { SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "You must set your name before you can set your vehicle insurance"); return; } // checking if the vehicle exists if (GetCivilianVeh(handle) != null) { int index = CivVehs.IndexOf(GetCivilianVeh(handle)); // finding the index CivVehs[index].Insured = !CivVehs[index].Insured; // toggle insurance SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, $"Insurance status set to {CivVehs[index].Insured}"); // msg } else { SendMessage(p, "DispatchSystem", new[] { 0, 0, 0 }, "You must set your vehicle before you can set your Insurance"); } }
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"); } }
public static CivilianVeh GetCivilianVehByPlate(string plate) { return(CivVehs.FirstOrDefault(item => string.Equals(item.Plate, plate, StringComparison.CurrentCultureIgnoreCase))); // Finding the first civilian vehicle that has that plate }
public static CivilianVeh GetCivilianVeh(string pHandle) { return(CivVehs.FirstOrDefault(item => GetPlayerByIp(item.SourceIP)?.Handle == pHandle)); // Finding the first Civilian Vehicle that has that handle }