public void UnbanPlayer(Client player, string fullPlayerName, string reason) { Player user = Player.PlayerData[player]; if (user.MasterAccount.AdminLevel < 3) { Message.NotAuthorised(player); return; } try { Ban banData = BanRepository.GetActiveBanByPlayerAccount(fullPlayerName); Master adminWhoBanned = MasterRepository.GetMasterDataById(banData.BannedBy); if (user.MasterAccount.AdminLevel > adminWhoBanned.AdminLevel || user.MasterId == adminWhoBanned.Id) { BanRepository.RemoveAsync(banData); API.sendChatMessageToPlayer(player, string.Format("You have successfully unbanned {0}", PlayerRepository.GetPlayerDataByName(fullPlayerName).Username.Roleplay())); } else { API.SendWarningNotification(player, "You aren't a higher enough administrative level to unban this player."); } } catch { API.SendErrorNotification(player, "The specified player doesn't exist."); } }
private void OnClientEventTrigger(Client player, string eventName, params object[] arguments) { if (eventName == "playerHiredIntoFaction") { if ((int)arguments[0] == 1) { Player user = Player.PlayerData[player]; if (user.AwaitingFactionInvite != null) { Player.PlayerData[player].Faction = user.AwaitingFactionInvite.Faction; Player.PlayerData[player].FactionId = user.AwaitingFactionInvite.FactionId; Player.PlayerData[player].FactionRank = 1; API.sendChatMessageToPlayer(user.AwaitingFactionInvite.Client, String.Format("~y~ {0} has accepted your invitation into the {1}", player.name, user.AwaitingFactionInvite.Faction.Name)); API.sendChatMessageToPlayer(player, String.Format("~y~You have successfully joined the {0}.", user.AwaitingFactionInvite.Faction.Name)); API.SendMessageToAllFactionMemebers(user.AwaitingFactionInvite.Faction, String.Format("~y~{0} has joined the {1}", player.name, user.AwaitingFactionInvite.Faction.Name)); Player.PlayerData[player].AwaitingFactionInvite = null; PlayerRepository.UpdateAsync(Player.PlayerData[player]); } } } }
public void SetPlayerSkin(Player user, Player target, string skinName) { if (user.MasterAccount.AdminLevel < 3) { Message.NotAuthorised(user.Client); return; } if (!Enum.IsDefined(typeof(PedHash), skinName)) { API.sendChatMessageToPlayer(user.Client, "Skin doesn't exist"); return; } target.Skin = (int)API.pedNameToModel(skinName); API.setPlayerSkin(target.Client, API.pedNameToModel(skinName)); API.sendNotificationToPlayer(user.Client, String.Format("You have successfully set {0}'s skin", target.Client.name)); API.sendNotificationToPlayer(target.Client, String.Format("Admin {0} has changed your skin", user.Client.name)); PlayerRepository.UpdateAsync(target); }
public void AcceptFactionInvite(Client player) { Player requestBy = Player.PlayerData[player].AwaitingFactionInvite; if (requestBy != null) { Player.PlayerData[player].Faction = requestBy.Faction; Player.PlayerData[player].FactionId = requestBy.FactionId; Player.PlayerData[player].FactionRank = 1; API.sendChatMessageToPlayer(requestBy.Client, String.Format("{0} has accepted your invitation into the {1}", player.name, requestBy.Faction.Name)); API.sendChatMessageToPlayer(player, String.Format("~y~You have successfully joined the {0}.", requestBy.Faction.Name)); API.SendMessageToAllFactionMemebers(requestBy.Faction, String.Format("~y~{0} has joined the {1}", player.name, requestBy.Faction)); Player.PlayerData[player].AwaitingFactionInvite = null; PlayerRepository.UpdateAsync(Player.PlayerData[player]); } }
private void SetPlayerFaction(Player player, Player target, string value, int rank = -1) { int id; Faction faction; if (player.MasterAccount.AdminLevel < 3) { Message.NotAuthorised(player.Client); return; } try { id = int.Parse(value); } catch { API.sendChatMessageToPlayer(player.Client, "~r~ERROR: ~w~Invalid faction ID."); return; } try { faction = Faction.FactionData.Single(f => f.Id == id); } catch { API.sendChatMessageToPlayer(player.Client, "~r~ERROR: ~w~Invalid faction ID."); return; } target.FactionId = id; target.Faction = faction; target.FactionRank = 1; API.sendNotificationToPlayer(player.Client, String.Format("You have successfully set {0}'s faction to the {1}", target.Client.name, faction.Name)); API.sendNotificationToPlayer(target.Client, String.Format("Admin {0} has set your faction to {1}", player.Client.name, faction.Name)); PlayerRepository.UpdateAsync(target); }
private void OnClientMessageEventTrigger(Client sender, string eventName, params object[] arguments) { if (eventName == "PhoneLoadMessagesApp") { Player p = Player.PlayerData[sender]; List <PhoneLog> messages = PhoneLogRepository.GetPhoneLogsOfTypeByIMEI(PhoneLogType.SMS, p.PrimaryPhone.IMEI); messages = messages .Where(m => (m.IMEIFrom == p.PrimaryPhone.IMEI) ? m.DeletedFrom != true : m.DeletedTo != true) .GroupBy(m => (m.IMEIFrom == p.PrimaryPhone.IMEI) ? m.NumberTo : m.NumberFrom) .SelectMany(m => m.OrderByDescending(me => me.SentAt).Take(1)) .ToList(); string convoMessages = ""; string toFrom = ""; string messDate = ""; string viewed = ""; int count = 0; foreach (PhoneLog pl in messages) { PhoneContact pc; pc = PhoneContactRepository.GetPhoneContactByNumber(pl.IMEITo == p.PrimaryPhone.IMEI ? pl.NumberFrom : pl.NumberTo, p.PrimaryPhone); if (pc != null) { if (pc.Name.Length > 19) { toFrom += string.Format("{0}|", pc.Name.Substring(0, 16) + "..."); } else { toFrom += string.Format("{0}|", pc.Name); } } else { toFrom += string.Format("{0}|", pl.NumberTo); } if (pl.SentAt > Server.Date.AddDays(-1)) { messDate += pl.SentAt.ToString("HH:mm") + ","; } else if (pl.SentAt > Server.Date.AddDays(-7)) { messDate += pl.SentAt.ToString("dddd") + ","; } else { messDate += pl.SentAt.ToString("dd/MM/yyyy") + ","; } if (pl.Viewed) { viewed += "yes,"; } else { viewed += "no,"; } convoMessages += pl.Message + "|"; count++; } API.triggerClientEvent(sender, "populateMessagesList", toFrom, messDate, viewed, convoMessages, count); } else if (eventName == "PhoneShowMessageConversation") { Player p = Player.PlayerData[sender]; List <PhoneLog> messages = PhoneLogRepository.GetPhoneLogsOfTypeByIMEI(PhoneLogType.SMS, p.PrimaryPhone.IMEI); messages = messages .GroupBy(m => (m.IMEIFrom == p.PrimaryPhone.IMEI) ? m.NumberTo : m.NumberFrom) .SelectMany(m => m.OrderByDescending(me => me.SentAt).Take(1)) .ToList(); PhoneLog selectedMessages = messages[int.Parse(arguments[0].ToString())]; string number = ""; string name = ""; PhoneContact pc; if (selectedMessages.IMEITo == p.PrimaryPhone.IMEI) { pc = PhoneContactRepository.GetPhoneContactByNumber(selectedMessages.NumberFrom, p.PrimaryPhone); number = name = selectedMessages.NumberFrom; } else { pc = PhoneContactRepository.GetPhoneContactByNumber(selectedMessages.NumberTo, p.PrimaryPhone); number = name = selectedMessages.NumberTo; } if (pc != null) { name = pc.Name; } List <PhoneLog> conversation = PhoneLogRepository.GetPhoneMessagesNumberToIMEI(number, p.PrimaryPhone.IMEI); string convoMessages = ""; string toFrom = ""; string messDate = ""; string ids = ""; int count = 0; foreach (PhoneLog con in conversation) { if ((p.PrimaryPhone.IMEI == con.IMEIFrom && con.DeletedFrom) || (p.PrimaryPhone.IMEI == con.IMEITo && con.DeletedTo)) { continue; } ids += con.Id + ","; convoMessages += con.Message + "|"; toFrom += (con.IMEIFrom == p.PrimaryPhone.IMEI) ? "outbound," : "inbound,"; if (con.SentAt > Server.Date.AddDays(-1)) { messDate += con.SentAt.ToString("HH:mm") + ","; } else if (con.SentAt > Server.Date.AddDays(-7)) { messDate += con.SentAt.ToString("ddd dd MMM") + ","; } else { messDate += con.SentAt.ToString("dd/MM/yyyy HH:mm") + ","; } count++; } API.triggerClientEvent(sender, "populateMessageConvo", name, number, ids, toFrom, messDate, convoMessages, count); } else if (eventName == "PhoneSendTextMessage") { Player p = Player.PlayerData[sender]; SimCard playersim = SimCardRepository.GetSimCardById(p.PrimaryPhone.InstalledSim); if (playersim.Credit >= 2) { playersim.Credit -= 2; Phone receiverPhone = PhoneRepository.GetPhoneBySim(SimCardRepository.GetSimCardByNumber(arguments[1].ToString()).Id); if (receiverPhone == null) { API.triggerClientEvent(sender, "sendTextMessageResult", 0); return; } PhoneLog newMessage = new PhoneLog() { IMEITo = receiverPhone.IMEI, IMEIFrom = p.PrimaryPhone.IMEI, NumberFrom = playersim.Number, NumberTo = arguments[1].ToString(), Message = arguments[0].ToString(), SentAt = Server.Date, Duration = 0, Viewed = false, Type = PhoneLogType.SMS }; PhoneLogRepository.AddPhoneLog(newMessage); string number = ""; string name = ""; var pc = PhoneContactRepository.GetPhoneContactByNumber(arguments[1].ToString(), p.PrimaryPhone); name = number = arguments[1].ToString(); if (pc != null) { name = pc.Name; } List <PhoneLog> conversation = PhoneLogRepository.GetPhoneMessagesNumberToIMEI(number, p.PrimaryPhone.IMEI); string convoMessages = ""; string toFrom = ""; string messDate = ""; string ids = ""; int count = 0; foreach (PhoneLog con in conversation) { if ((p.PrimaryPhone.IMEI == con.IMEIFrom && con.DeletedFrom) || (p.PrimaryPhone.IMEI == con.IMEITo && con.DeletedTo)) { continue; } ids += con.Id + ","; convoMessages += con.Message + "|"; toFrom += (con.IMEIFrom == p.PrimaryPhone.IMEI) ? "outbound," : "inbound,"; if (con.SentAt > Server.Date.AddDays(-1)) { messDate += con.SentAt.ToString("HH:mm") + ","; } else if (con.SentAt > Server.Date.AddDays(-7)) { messDate += con.SentAt.ToString("ddd dd MMM") + ","; } else { messDate += con.SentAt.ToString("dd/MM/yyyy HH:mm") + ","; } count++; } Player receiver = Player.PlayerData.Values.FirstOrDefault(pl => pl.PrimaryPhone.Id == receiverPhone.Id); if (receiver != null) { API.triggerClientEvent(receiver.Client, "phoneSendNotification", PhoneApp.AppInfo[1][1], name, newMessage.Message, 5000); } PlayerRepository.UpdateAsync(p); API.triggerClientEvent(sender, "phoneTextMessageResult", 1); API.triggerClientEvent(sender, "populateMessageConvo", name, number, ids, toFrom, messDate, convoMessages, count); } API.triggerClientEvent(sender, "phoneTextMessageResult", 0); } else if (eventName == "PhoneMessageComposeContacts") { Player p = Player.PlayerData[sender]; List <PhoneContact> phoneContacts = PhoneContactRepository.GetAllContactsOnPhoneAndSim(p.PrimaryPhone.Id, SimCardRepository.GetSimCardById(p.PrimaryPhone.InstalledSim).Id); string contactNames = string.Join("|", phoneContacts.Select(pc => pc.Name)); string contactNumbers = string.Join(",", phoneContacts.Select(pc => pc.Number)); API.triggerClientEvent(sender, "populateMessageComposeContact", contactNames, contactNumbers); } else if (eventName == "PhoneMessageActiveConversation") { Player p = Player.PlayerData[sender]; List <PhoneLog> conversation = PhoneLogRepository.GetPhoneMessagesNumberToIMEI(arguments[0].ToString(), p.PrimaryPhone.IMEI); if (conversation.Count > 0) { string name = ""; PhoneContact pc = PhoneContactRepository.GetPhoneContactByNumber(arguments[0].ToString(), p.PrimaryPhone); name = pc == null ? arguments[0].ToString() : pc.Name; string convoMessages = ""; string toFrom = ""; string messDate = ""; string ids = ""; int count = 0; foreach (PhoneLog con in conversation) { if ((p.PrimaryPhone.IMEI == con.IMEIFrom && con.DeletedFrom) || (p.PrimaryPhone.IMEI == con.IMEITo && con.DeletedTo)) { continue; } ids += con.Id + ","; convoMessages += con.Message + "|"; toFrom += (con.IMEIFrom == p.PrimaryPhone.IMEI) ? "outbound," : "inbound,"; if (con.SentAt > Server.Date.AddDays(-1)) { messDate += con.SentAt.ToString("HH:mm") + ","; } else if (con.SentAt > Server.Date.AddDays(-7)) { messDate += con.SentAt.ToString("ddd dd MMM") + ","; } else { messDate += con.SentAt.ToString("dd/MM/yyyy HH:mm") + ","; } count++; } API.triggerClientEvent(sender, "populateMessageConvo", name, arguments[0].ToString(), ids, toFrom, messDate, convoMessages, count); } else { try { if ((bool)arguments[1]) { OnClientMessageEventTrigger(sender, "PhoneLoadMessagesApp"); } } catch { } } } else if (eventName == "PhoneMessageDelete") { Player p = Player.PlayerData[sender]; PhoneLog deletedLog = PhoneLogRepository.GetPhoneLogById(Convert.ToInt32(arguments[0])); if (p.PrimaryPhone.IMEI == deletedLog.IMEIFrom) { deletedLog.DeletedFrom = true; } else { deletedLog.DeletedTo = true; } PhoneLogRepository.UpdateAsync(deletedLog); OnClientMessageEventTrigger(sender, "PhoneMessageActiveConversation", (p.PrimaryPhone.IMEI == deletedLog.IMEIFrom) ? deletedLog.NumberTo : deletedLog.NumberFrom, true); } }
private void OnClientBasePhoneEventTrigger(Client sender, string eventName, params object[] arguments) { if (eventName == "PhoneInsertSimCard") { Player p = Player.PlayerData[sender]; if (p.PrimaryPhone.InstalledSim != -1) { API.ShowPopupPrompt(sender, "RemoveCurrentSimCard", "Remove SIM?", "Are you sure you want to remove your current sim card from this device?"); } else { if (p.AccessingBank <= 0) { if (p.Inventory.Where(e => e.Type == InventoryType.SimCard).Select(e => e.Id).Any()) { API.triggerClientEvent(sender, "selectSimCard", string.Join(",", p.Inventory.Where(e => e.Type == InventoryType.SimCard).Select(e => e.Id).ToList()), string.Join(",", p.Inventory.Where(e => e.Type == InventoryType.SimCard).Select(e => e.Name).ToList()), string.Join(".", p.Inventory.Where(e => e.Type == InventoryType.SimCard).Select(e => Inventory.GetInventoryImage[e.Type]).ToList()), string.Join(",", p.Inventory.Where(e => e.Type == InventoryType.SimCard).Select(e => e.Quantity).ToList())); } API.SendErrorNotification(sender, "You don't have any sim card on you.", 8); } } } else if (eventName == "onSimCardSelected") { Player p = Player.PlayerData[sender]; SimCard sim = SimCardRepository.GetSimCardByNumber(p.Inventory.First(e => e.Id == (int)arguments[0]).Value); if (sim != null) { Inventory inv = p.Inventory.FirstOrDefault(i => i.Value == sim.Number); if (inv != null) { p.Inventory.Remove(inv); p.PrimaryPhone.InstalledSim = sim.Id; InventoryRepository.UpdateAsync(inv); PlayerRepository.UpdateAsync(p); PhoneRepository.UpdateAsync(p.PrimaryPhone); API.SendInfoNotification(sender, "You have successfully installed a new sim card."); API.triggerClientEvent(sender, "PhoneSimInstalled"); } } } else if (eventName == "RemoveCurrentSimCard") { if ((int)arguments[0] == 1) { Player p = Player.PlayerData[sender]; SimCard currentSim = SimCardRepository.GetSimCardById(p.PrimaryPhone.InstalledSim); Inventory inv = InventoryRepository.GetInventoryItemOfTypeByValue(InventoryType.SimCard, currentSim.Number); if (!inv.AddToPlayer()) { API.SendWarningNotification(sender, "You don't have space in your inventory for a sim card"); return; } p.PrimaryPhone.InstalledSim = -1; inv.OwnerId = p.Id; inv.OwnerType = InventoryOwnerType.Player; p.Inventory.Add(inv); InventoryRepository.UpdateAsync(inv); PlayerRepository.UpdateAsync(p); PhoneRepository.UpdateAsync(p.PrimaryPhone); API.SendInfoNotification(sender, "You have removed the sim card from your phone."); } } else if (eventName == "LoadPhoneHomeScreen") { Player p = Player.PlayerData[sender]; p.PrimaryPhone.Home(sender); } else if (eventName == "ShowSettingsInfoPage") { Player p = Player.PlayerData[sender]; SimCard currentSim = SimCardRepository.GetSimCardById(p.PrimaryPhone.InstalledSim); API.triggerClientEvent(sender, "LoadSettingsInfoPage", p.PrimaryPhone.IMEI.ToString(), currentSim.Number, currentSim.Credit.ToString("C0")); } else if (eventName == "PhoneMakeCall") { Player p = Player.PlayerData[sender]; SimCard simBeingCalled = SimCardRepository.GetSimCardByNumber(arguments[0].ToString()); SimCard playerSim = SimCardRepository.GetSimCardById(p.PrimaryPhone.InstalledSim); if (playerSim == null) { API.triggerClientEvent(sender, "PhoneCallConnection", (int)PhoneCallConnectTypes.SimNotInstalled); return; } if (simBeingCalled == null) { API.triggerClientEvent(sender, "PhoneCallConnection", (int)PhoneCallConnectTypes.NumberDoesntExist); return; } if (simBeingCalled.Number == playerSim.Number) { API.triggerClientEvent(sender, "PhoneCallConnection", (int)PhoneCallConnectTypes.InCall); return; } if (simBeingCalled.Number == "911") { EmergencyCallHandler.EmsCalled(p.Client, playerSim.Number); return; } Phone phoneCalled = PhoneRepository.GetPhoneBySim(simBeingCalled.Id); if (phoneCalled == null) { API.triggerClientEvent(sender, "PhoneCallConnection", (int)PhoneCallConnectTypes.SimNotInstalled); return; } API.triggerClientEvent(sender, "PhoneCallConnection", (int)PhoneCallConnectTypes.Connected); Inventory phoneInv = InventoryRepository.GetInventoryPhoneByIMEI(phoneCalled.IMEI.ToString()); Player playerCalled = Player.PlayerData.Values.FirstOrDefault(ph => ph.Id == phoneInv.OwnerId); if (playerCalled == null) { API.triggerClientEvent(sender, "PhoneCallConnection", (int)PhoneCallConnectTypes.PlayerOffline); return; } if (!phoneCalled.PoweredOn) { API.triggerClientEvent(sender, "PhoneCallConnection", (int)PhoneCallConnectTypes.PhoneOff); return; } PhoneContact contactOnCalled = PhoneContactRepository.GetPhoneContactByNumber(arguments[0].ToString(), phoneCalled); if (contactOnCalled != null && contactOnCalled.IsBlocked) { API.triggerClientEvent(sender, "PhoneCallConnection", (int)PhoneCallConnectTypes.BlockedNumber); return; } if (phoneCalled.InCallWith != null) { API.triggerClientEvent(sender, "PhoneCallConnection", (int)PhoneCallConnectTypes.InCall); return; } if (!phoneCalled.IsPrimary) { InventoryManager.SetPhonePrimary(playerCalled.Client, phoneInv, true); } playerCalled.PrimaryPhone.InCallWith = p; p.PrimaryPhone.InCallWith = playerCalled; p.PrimaryPhone.IsCaller = true; playerCalled.PrimaryPhone.IsCaller = false; if (contactOnCalled != null) { API.triggerClientEvent(playerCalled.Client, "IncomingPhoneCall", contactOnCalled.Name); } else { API.triggerClientEvent(playerCalled.Client, "IncomingPhoneCall", playerSim.Number); } //API.sendNativeToPlayer(playerCalled.Client, Hash.PLAY_PED_RINGTONE, "Remote_Ring", playerCalled.Client, 1); } else if (eventName == "PhoneAnswerCall") { Player p = Player.PlayerData[sender]; if (p.PrimaryPhone.InCallWith == null) { return; } SimCard callerSim = SimCardRepository.GetSimCardById(p.PrimaryPhone.InCallWith.PrimaryPhone.InstalledSim); if (callerSim == null) { API.triggerClientEvent(sender, "PhoneCallConnection", (int)PhoneCallConnectTypes.SimNotInstalled); return; } callerSim.Credit -= 1; p.PrimaryPhone.CallConnected = true; p.PrimaryPhone.InCallWith.PrimaryPhone.CallConnected = true; API.triggerClientEvent(p.PrimaryPhone.InCallWith.Client, "PhoneCallAnswered"); API.triggerClientEvent(sender, "PhoneCallAnswered"); } else if (eventName == "PhoneEndCall") { Player p = Player.PlayerData[sender]; p.PrimaryPhone.Speakerphone = false; p.PrimaryPhone.MicMuted = false; SimCard endedSim = SimCardRepository.GetSimCardById(p.PrimaryPhone.InstalledSim); SimCard receiverSim = SimCardRepository.GetSimCardById(p.PrimaryPhone.InCallWith.PrimaryPhone.InstalledSim); PhoneLog callLog = new PhoneLog() { IMEITo = p.PrimaryPhone.IsCaller ? p.PrimaryPhone.InCallWith.PrimaryPhone.IMEI : p.PrimaryPhone.IMEI, IMEIFrom = p.PrimaryPhone.IsCaller ? p.PrimaryPhone.IMEI : p.PrimaryPhone.InCallWith.PrimaryPhone.IMEI, NumberFrom = p.PrimaryPhone.IsCaller ? endedSim.Number : receiverSim.Number, NumberTo = p.PrimaryPhone.IsCaller ? receiverSim.Number : endedSim.Number, Duration = (int)arguments[0], Type = PhoneLogType.Call, Message = "", SentAt = Server.Date.AddSeconds(-((int)arguments[0])), Viewed = p.PrimaryPhone.CallConnected }; if (p.PrimaryPhone.CallConnected) { API.triggerClientEvent(p.PrimaryPhone.InCallWith.Client, "phoneTerminateCall"); } PhoneLogRepository.AddPhoneLog(callLog); p.PrimaryPhone.CallConnected = false; p.PrimaryPhone.InCallWith.PrimaryPhone.CallConnected = false; p.PrimaryPhone.InCallWith.PrimaryPhone.Speakerphone = false; p.PrimaryPhone.InCallWith.PrimaryPhone.MicMuted = false; p.PrimaryPhone.InCallWith.PrimaryPhone.InCallWith = null; p.PrimaryPhone.InCallWith = null; } else if (eventName == "PhoneToggleSpeaker") { Player p = Player.PlayerData[sender]; p.PrimaryPhone.Speakerphone = !p.PrimaryPhone.Speakerphone; } else if (eventName == "PhoneToggleMic") { Player p = Player.PlayerData[sender]; p.PrimaryPhone.MicMuted = !p.PrimaryPhone.MicMuted; } else if (eventName == "PhoneRecentCalls") { Player p = Player.PlayerData[sender]; List <PhoneLog> recentCalls = PhoneLogRepository.GetPhoneLogsOfTypeByIMEI(PhoneLogType.Call, p.PrimaryPhone.IMEI); string callData = ""; int count = 0; foreach (PhoneLog pl in recentCalls) { PhoneContact pc; if (pl.IMEIFrom == p.PrimaryPhone.IMEI) { pc = PhoneContactRepository.GetPhoneContactByNumber(pl.NumberTo, p.PrimaryPhone); if (pc != null) { if (pc.Name.Length > 15) { callData += string.Format("{0},outbound,", pc.Name.Substring(0, 13) + "..."); } else { callData += string.Format("{0},outbound,", pc.Name); } } else { callData += string.Format("{0},outbound,", pl.NumberTo); } } else { pc = PhoneContactRepository.GetPhoneContactByNumber(pl.NumberFrom, p.PrimaryPhone); if (pc != null) { if (pc.Name.Length > 15) { callData += string.Format("{0},inbound,", pc.Name.Substring(0, 13) + "..."); } else { callData += string.Format("{0},inbound,", pc.Name); } } else { callData += string.Format("{0},inbound,", pl.NumberFrom); } } if (pl.SentAt > Server.Date.AddDays(-1)) { callData += pl.SentAt.ToString("HH:mm") + ","; } else if (pl.SentAt > Server.Date.AddDays(-7)) { callData += pl.SentAt.ToString("dddd") + ","; } else { callData += pl.SentAt.ToString("dd/MM/yyyy") + ","; } if (pl.Viewed) { callData += "yes,"; } else { callData += "no,"; } count += 4; } API.triggerClientEvent(sender, "populateRecentCalls", callData, count); } else if (eventName == "PhoneContactList") { Player p = Player.PlayerData[sender]; SimCard playerSIM = SimCardRepository.GetSimCardById(p.PrimaryPhone.InstalledSim); List <PhoneContact> contactList; contactList = playerSIM != null?PhoneContactRepository.GetAllContactsOnPhoneAndSim(p.PrimaryPhone.Id, playerSIM.Id) : PhoneContactRepository.GetAllContactsOnPhoneAndSim(p.PrimaryPhone.Id, -1); API.triggerClientEvent(sender, "populateContactList", string.Join(",", contactList.OrderBy(e => e.Name).Select(e => e.Name)), false); } else if (eventName == "PhoneFavouriteList") { Player p = Player.PlayerData[sender]; SimCard playerSIM = SimCardRepository.GetSimCardById(p.PrimaryPhone.InstalledSim); List <PhoneContact> contactList; contactList = playerSIM != null?PhoneContactRepository.GetAllContactsOnPhoneAndSim(p.PrimaryPhone.Id, playerSIM.Id) : PhoneContactRepository.GetAllContactsOnPhoneAndSim(p.PrimaryPhone.Id, -1); API.triggerClientEvent(sender, "populateContactList", string.Join(",", contactList.Where(e => e.IsFavourite).OrderBy(e => e.Name).Select(e => e.Name)), true); } else if (eventName == "PhoneRecentCallSelect") { Player p = Player.PlayerData[sender]; List <PhoneLog> recentCalls = PhoneLogRepository.GetPhoneLogsOfTypeByIMEI(PhoneLogType.Call, p.PrimaryPhone.IMEI); string recentCall = recentCalls[int.Parse(arguments[0].ToString())].IMEIFrom == p.PrimaryPhone.IMEI ? recentCalls[int.Parse(arguments[0].ToString())].NumberTo : recentCalls[int.Parse(arguments[0].ToString())].NumberFrom; API.triggerClientEvent(sender, "redialRecentCall", recentCall); } else if (eventName == "PhoneAddNewContact") { sender.ToggleCursorLock(true); } else if (eventName == "PhoneCreateNewContact") { Player p = Player.PlayerData[sender]; PhoneContact contact = new PhoneContact() { Name = arguments[0].ToString(), Number = arguments[1].ToString(), Address1 = arguments[2].ToString(), Address2 = arguments[3].ToString(), Address3 = arguments[4].ToString(), Notes = arguments[5].ToString(), IsBlocked = false, IsFavourite = false, SavedTo = p.PrimaryPhone.Id, IsSimContact = false }; PhoneContactRepository.AddPhoneContact(contact); OnClientBasePhoneEventTrigger(sender, "PhoneContactList", new object { }); sender.ToggleCursorLock(false); } else if (eventName == "PhoneContactSelected") { Player p = Player.PlayerData[sender]; int ind = (int)arguments[0]; bool isFavourite = (bool)arguments[1]; SimCard playerSIM = SimCardRepository.GetSimCardById(p.PrimaryPhone.InstalledSim); List <PhoneContact> contactList; contactList = playerSIM != null?PhoneContactRepository.GetAllContactsOnPhoneAndSim(p.PrimaryPhone.Id, playerSIM.Id) : PhoneContactRepository.GetAllContactsOnPhoneAndSim(p.PrimaryPhone.Id, -1); contactList = !isFavourite?contactList.OrderBy(e => e.Name).ToList() : contactList.Where(e => e.IsFavourite).OrderBy(e => e.Name).ToList(); API.triggerClientEvent(sender, "displayPhoneContact", contactList[ind].Id, contactList[ind].Name, contactList[ind].Number, contactList[ind].Address1, contactList[ind].Address2, contactList[ind].Address3, contactList[ind].Notes, contactList[ind].IsFavourite, contactList[ind].IsBlocked, contactList[ind].IsSimContact); } else if (eventName == "PhoneUpdateContact") { Player p = Player.PlayerData[sender]; PhoneContact pc = PhoneContactRepository.GetPhoneContactById(int.Parse(arguments[0].ToString())); pc.Name = arguments[1].ToString(); pc.Number = arguments[2].ToString(); pc.Address1 = arguments[3].ToString(); pc.Address2 = arguments[4].ToString(); pc.Address3 = arguments[5].ToString(); pc.Notes = arguments[6].ToString(); PhoneContactRepository.UpdateAsync(pc); API.triggerClientEvent(sender, "displayPhoneContact", pc.Id, pc.Name, pc.Number, pc.Address1, pc.Address2, pc.Address3, pc.Notes, pc.IsFavourite, pc.IsBlocked, pc.IsSimContact); } else if (eventName == "PhoneSetFavouriteContact") { Player p = Player.PlayerData[sender]; PhoneContact pc = PhoneContactRepository.GetPhoneContactById(int.Parse(arguments[0].ToString())); pc.IsFavourite = !pc.IsFavourite; PhoneContactRepository.UpdateAsync(pc); API.triggerClientEvent(sender, "displayPhoneContact", pc.Id, pc.Name, pc.Number, pc.Address1, pc.Address2, pc.Address3, pc.Notes, pc.IsFavourite, pc.IsBlocked, pc.IsSimContact); } else if (eventName == "PhoneBatteryChange") { Player p = Player.PlayerData[sender]; int battLevel = Convert.ToInt32(float.Parse(arguments[0].ToString())); if (battLevel <= 100) { p.PrimaryPhone.BatteryLevel = battLevel; } if (battLevel < 2) { p.PrimaryPhone.TurnOff(sender); } PhoneRepository.UpdateAsync(p.PrimaryPhone); } else if (eventName == "PhoneDeleteContact") { Player p = Player.PlayerData[sender]; p.DeletingContact = PhoneContactRepository.GetPhoneContactById(int.Parse(arguments[0].ToString())); API.ShowPopupPrompt(sender, "PhoneConfirmDeleteContact", "Delete " + p.DeletingContact.Name, "Are you sure you want to delete " + p.DeletingContact.Name + " from your contacts?"); } else if (eventName == "PhoneConfirmDeleteContact") { Player p = Player.PlayerData[sender]; if ((int)arguments[0] == 1) { PhoneContactRepository.Delete(p.DeletingContact); p.DeletingContact = null; OnClientBasePhoneEventTrigger(sender, "PhoneContactList", new object { }); } } else if (eventName == "PhoneBlockContact") { PhoneContact pc = PhoneContactRepository.GetPhoneContactById(int.Parse(arguments[0].ToString())); if (pc != null) { pc.IsBlocked = !pc.IsBlocked; PhoneContactRepository.UpdateAsync(pc); API.triggerClientEvent(sender, "displayPhoneContact", pc.Id, pc.Name, pc.Number, pc.Address1, pc.Address2, pc.Address3, pc.Notes, pc.IsFavourite, pc.IsBlocked, pc.IsSimContact); } } else if (eventName == "PhoneChangeContactStorage") { Player p = Player.PlayerData[sender]; PhoneContact pc = PhoneContactRepository.GetPhoneContactById(int.Parse(arguments[0].ToString())); if (pc != null) { if (pc.IsSimContact) { pc.SavedTo = p.PrimaryPhone.Id; } else { if (p.PrimaryPhone.InstalledSim > 0) { int simContacts = PhoneContactRepository.GetAllContactsOnSim(p.PrimaryPhone.InstalledSim).Count; if (simContacts < SimCard.CONTACT_CAPACITY) { pc.SavedTo = p.PrimaryPhone.InstalledSim; } else { API.SendErrorNotification(sender, "You have reached the limit of contacts stored to this SIM Card"); } } } pc.IsSimContact = !pc.IsSimContact; PhoneContactRepository.UpdateAsync(pc); API.triggerClientEvent(sender, "displayPhoneContact", pc.Id, pc.Name, pc.Number, pc.Address1, pc.Address2, pc.Address3, pc.Notes, pc.IsFavourite, pc.IsBlocked, pc.IsSimContact); } } else if (eventName == "PhoneEnteredPasscode") { Player p = Player.PlayerData[sender]; if (p.PrimaryPhone.Passcode != null) { API.triggerClientEvent(sender, "phonePasscodeResult", Crypter.CheckPassword(arguments[0].ToString(), p.PrimaryPhone.Passcode) ? 4 : 0); } } }
private void OnClientEventTrigger(Client sender, string eventName, params object[] arguments) { if (eventName == "ActivateATM") { foreach (Vector3 atm in PlayerPositionAtATM.Keys) { if (sender.position.DistanceTo(atm) < 1.5f) { List <Vector3> offsets = PlayerPositionAtATM[atm]; sender.position = atm; sender.rotation = offsets[0]; API.triggerClientEvent(sender, "onExecuteATM", offsets[1], offsets[2]); Player.PlayerData[sender].InEvent = PlayerEvent.UsingATM; API.playPlayerScenario(sender, "PROP_HUMAN_ATM"); return; } } } else if (eventName == "chooseBankCard") { Player p = Player.PlayerData[sender]; p.AccessingBank = -1; p.TransactionType = -1; p.AwaitingInventorySelection = InventoryType.BankCard; InventoryManager.UpdatePlayerInventory(p); } else if (eventName == "closeATM") { try { Player p = Player.PlayerData[sender]; p.AccessingBank = -1; p.TransactionType = -1; p.InEvent = PlayerEvent.None; API.stopPlayerAnimation(sender); } catch { // ignored } } else if (eventName == "ATMCardSelected") { Player p = Player.PlayerData[sender]; try { BankAccount bankAccount = BankRepository.GetAccountByCardNumber(long.Parse(p.Inventory.First(i => i.Id == (int)arguments[0]).Value)); p.AccessingBank = bankAccount.Id; p.TransactionType = -1; API.triggerClientEvent(sender, "enterATMPin"); InventoryManager.HidePlayerInventory(p, true); } catch { API.triggerClientEvent(sender, "invalidCardATM"); } } else if (eventName == "atmValidatePin") { Player p = Player.PlayerData[sender]; BankAccount bankAccount = BankRepository.GetAccountById(p.AccessingBank); Player bankOwner = PlayerRepository.GetPlayerDataById(bankAccount.RegisterOwnerId); if ((string)arguments[0] == bankAccount.Pin) { API.triggerClientEvent(sender, "atmCorrectPin", bankOwner.Username.Roleplay(), bankAccount.CardNumber.ToString()); } else { API.sendChatMessageToPlayer(sender, "Booo"); } } else if (eventName == "atmRequestBalance") { Player p = Player.PlayerData[sender]; BankAccount bankAccount = BankRepository.GetAccountById(p.AccessingBank); API.triggerClientEvent(sender, "atmBalanceReturn", bankAccount.Balance.ToString("C0")); } else if (eventName == "atmWithdrawMoney") { Player p = Player.PlayerData[sender]; BankAccount bankAccount = BankRepository.GetAccountById(p.AccessingBank); long value = long.Parse(arguments[0].ToString()); if (value <= bankAccount.Balance) { if (value <= 1000 && value > 0) { Inventory cashItem = Inventory.CreateCashInventoryItem(value); cashItem.OwnerType = InventoryOwnerType.Player; cashItem.OwnerId = p.Id; if (!cashItem.AddToPlayer(p, true)) { API.SendErrorNotification(sender, "You don't have enough space to withdraw this amount of cash.", 7); return; } InventoryRepository.AddNewInventoryItem(cashItem); p.Inventory.Add(cashItem); bankAccount.Balance -= value; CashLogRepository.AddNew(new CashLog(bankAccount.Id, p.Id, value, MoneyTransferMethod.ATMWithdraw)); BankRepository.UpdateAsync(bankAccount); API.triggerClientEvent(sender, "atmWithdrawComplete", bankAccount.Balance); } else { API.triggerClientEvent(sender, "atmWithdrawError", 3, "<span id='withdrawErrorMsg' style='color:#f00'>EXCEEDED DAILY LIMIT</span>"); } } else { API.triggerClientEvent(sender, "atmWithdrawError", 2, "<span style='color:#f00'>Insufficient funds</span>"); } } else if (eventName == "atmChangePin") { Player p = Player.PlayerData[sender]; BankAccount bankAccount = BankRepository.GetAccountById(p.AccessingBank); int value = int.Parse(arguments[0].ToString()); if (value > 999 && value < 10000) { string encPin = value.ToString(); bankAccount.Pin = encPin; p.AccessingBank = -1; p.TransactionType = -1; BankRepository.UpdateAsync(bankAccount); IEnumerable <Inventory> bankCards = p.Inventory.Where(e => e.Type == InventoryType.BankCard); API.triggerClientEvent(sender, "showATMMenu", string.Join(",", bankCards.Select(e => e.Id).ToList()), string.Join(",", bankCards.Select(e => e.Name).ToList()), string.Join(".", bankCards.Select(e => Inventory.GetInventoryImage[e.Type]).ToList()), string.Join(",", bankCards.Select(e => e.Quantity).ToList())); } } }
public void LookupPropertyCommand(Client sender, string option = "") { if (option == "") { Message.Syntax(sender, "/propertylookup [PartOfName / ID]"); return; } int val; Int32.TryParse(option, out val); if (val != 0) { Message.Info(sender, "Property lookup (ID: " + val + ")"); Property prop = PropertyManager.Properties[val - 1]; Message.Info(sender, prop.Name + " | Owner: " + (prop.OwnerId != -1 ? PlayerRepository.GetPlayerDataById(prop.OwnerId).Username : "******") + " (SQL ID: " + prop.Id + ")"); } else { PropertyManager mng = new PropertyManager(); List <Property> properties = mng.GetPropertiesByPartialName(option); Message.Info(sender, "Property lookup (Name: " + option + ")"); foreach (Property prop in properties) { Message.Info(sender, prop.Name + " | Owner: " + (prop.OwnerId != -1 ? PlayerRepository.GetPlayerDataById(prop.OwnerId).Username : "******") + " (SQL ID: " + prop.Id + ")"); } } }
private void OnClientEventTrigger(Client sender, string eventName, params object[] arguments) { switch (eventName) { case "onLoginSubmitted": Login(sender, arguments[0].ToString(), arguments[1].ToString()); break; case "player-selected": API.sendNativeToPlayer(sender, Hash._TRANSITION_FROM_BLURRED, 8.0); Player newPlayer = Master.MasterData.Single(m => m.Client == sender).Players[(int)arguments[0]]; newPlayer.Client = sender; Console.WriteLine("here"); newPlayer.MasterAccount = Master.MasterData.Single(m => m.Client == sender); PlayerInit(newPlayer); sender.FadeOutIn(200, 1000); break; case "CreateNewCharacter": API.sendNativeToPlayer(sender, Hash._TRANSITION_FROM_BLURRED, 8.0); sender.setSkin((PedHash)PedSkins.Gender.Where(p => p.Value == 0).ElementAt(new Random().Next(0, PedSkins.Gender.Count(p => p.Value == 0))).Key); sender.FadeOutIn(300, 2000); sender.position = new Vector3(9.284171, 6512.242, 31.87785); sender.rotation = new Vector3(0, 0, 310); sender.playAnimation("amb@world_human_hang_out_street@male_b@base", "base", 0); sender.dimension = Globals.GetPlayerID(sender) + 1; break; case "CreateCharUsernameCheck": API.triggerClientEvent(sender, "createCharUsernameResult", PlayerRepository.GetPlayersWithUsernameCount(arguments[0].ToString())); break; case "CancelCharCreate": Master ma = Master.MasterData.Single(me => me.Client == sender); string[] charNames = new string[5]; List <string> charImgs = new List <string>() { "", "", "", "", "" }; string[] factions = new string[5]; int count = 0; foreach (Player p in ma.Players) { charNames[count] = p.Username.Roleplay(); charImgs[count] = p.Skin == 797459875 ? Images.SkinBlobs[p.Skin] : ""; if (p.FactionId != 0) { factions[count] = $"{FactionRepository.GetFactionById(p.FactionId).Name}<br/>{RankRepository.GetRankByFactionAndId(p.FactionId, p.FactionRank).Title}"; } else { factions[count] = "Civilian"; } count++; } API.triggerClientEvent(sender, "playerLogResult", "success", ma.Players.Count, string.Join(",", charNames), string.Join(",", factions), string.Join(".", charImgs)); API.triggerClientEvent(sender, "showLoginCam"); break; case "CreateNewCharacterProceed": CreateCharacter(sender, arguments[0].ToString(), (int)arguments[1], new DateTime((int)arguments[4], (int)arguments[3], (int)arguments[2])); break; case "CreateCharacterChangeGender": if ((int)arguments[0] == 0) { sender.setSkin((PedHash)PedSkins.Gender.Where(p => p.Value == 0).ElementAt(new Random().Next(0, PedSkins.Gender.Count(p => p.Value == 0))).Key); } else { sender.setSkin((PedHash)PedSkins.Gender.Where(p => p.Value == 1).ElementAt(new Random().Next(0, PedSkins.Gender.Count(p => p.Value == 1))).Key); } break; case "SkinSelectCategory": SelectSkinCategory(sender, (int)arguments[0]); break; case "SkinSelectChange": SelectSkinChange(sender, (int)arguments[0]); break; case "SkinCustomisationOptions": GetSkinCustomisationOptions(sender, (int)arguments[0]); break; case "SkinCustomTypeChange": SkinCustomTypeChange(sender, (int)arguments[0], (int)arguments[1], (int)arguments[2]); break; case "SkinCustomTextureChange": SkinCustomTextureChange(sender, (int)arguments[0], (int)arguments[1], (int)arguments[2]); break; case "CreateCharacterComplete": CompleteCharCreation(sender); break; } }
public async void Login(Client sender, string username, string password) { Master masterAccount; if (username.Contains("@")) { masterAccount = await MasterRepository.GetMasterDataByEmail(username); } else { masterAccount = await MasterRepository.GetMasterDataByName(username); } if (masterAccount != null) { if (Crypter.CheckPassword(password, masterAccount.Password)) { string[] charNames = new string[5]; List <string> charImgs = new List <string>() { "", "", "", "", "" }; string[] factions = new string[5]; masterAccount.Players = await PlayerRepository.GetAllPlayerDataByMasterAccount(masterAccount); masterAccount.Client = sender; int count = 0; foreach (Player p in masterAccount.Players) { charNames[count] = p.Username.Roleplay(); charImgs[count] = p.Skin == 797459875 ? Images.SkinBlobs[p.Skin] : ""; if (p.FactionId != 0) { factions[count] = $"{FactionRepository.GetFactionById(p.FactionId).Name}<br/>{RankRepository.GetRankByFactionAndId(p.FactionId, p.FactionRank).Title}"; } else { factions[count] = "Civilian"; } count++; } Master.MasterData.Add(masterAccount); API.triggerClientEvent(sender, "playerLogResult", "success", masterAccount.Players.Count, string.Join(",", charNames), string.Join(",", factions), string.Join(".", charImgs)); masterAccount.LatestLogin = Server.Date; masterAccount.LatestIP = sender.address; masterAccount.ActiveConnectionLog = new ConnectionLog(masterAccount.Id, -1, API.getPlayerAddress(sender)); ConnectionLogRepository.AddNew(masterAccount.ActiveConnectionLog); MasterRepository.UpdateAsync(masterAccount); masterAccount.AdminLevel = 6; } else { API.triggerClientEvent(sender, "playerLogResult", "incorrect-pass"); API.SendErrorNotification(sender, "You have entered an incorrect password"); } } else { API.triggerClientEvent(sender, "playerLogResult", "invalid-user"); API.SendErrorNotification(sender, "You have entered an invalid username"); } }
private async void CompleteCharCreation(Client sender) { Master master = Master.MasterData.Single(me => me.Client == sender); if (master.CreatingCharacter == null) { return; } Player newChar = new Player { Username = master.CreatingCharacter.Username.Replace(" ", "_"), Level = 0, Health = 100, Armour = 0, FactionId = 0, FactionRank = 0, WeaponSkillData = "0,0,0,0,0,0,0,0", DateOfBirth = master.CreatingCharacter.DateOfBirth, Gender = master.CreatingCharacter.Gender, MasterAccount = master, MasterId = master.Id, Dimension = 0, TestDriveBan = false, Client = sender, LastPosition = new Vector3(-697.0174, 5803.262, 17.33096), LastRotation = new Vector3(0, 0, 63.30323) }; List <int> AvailableSkins = new List <int>(); AvailableSkins = GetAvailableSkins(master); int[] compIds = new int[12]; int[] textureIds = new int[12]; int[] drawableIds = new int[12]; for (int i = 0; i < 12; i++) { textureIds[i] = API.fetchNativeFromPlayer <int>(sender, Hash.GET_PED_TEXTURE_VARIATION, sender, i); drawableIds[i] = API.fetchNativeFromPlayer <int>(sender, Hash.GET_PED_DRAWABLE_VARIATION, sender, i); } Skin newSkin = new Skin { Model = AvailableSkins[master.CreatingCharacter.CurrentSkinIndex], TextureIds = string.Join(",", textureIds), DrawableIds = string.Join(",", drawableIds), OwnerId = PlayerRepository.AddNewPlayer(newChar) }; Master.MasterData.Single(me => me.Client == sender).Players = await PlayerRepository.GetAllPlayerDataByMasterAccount(master); Master.MasterData.Single(me => me.Client == sender).CreatingCharacter = null; newChar.Skin = SkinRepository.AddNewSkin(newSkin); PlayerRepository.UpdateAsync(newChar); PlayerInit(newChar); sender.FadeOutIn(200, 1300); API.triggerClientEvent(sender, "onCharCreated"); }
public void SetPlayerValue(Client player, string partOfName = "", string option = "", string value = "") { Player user = Player.PlayerData[player]; if (user.MasterAccount.AdminLevel < 2) { Message.NotAuthorised(player); return; } if (option == "" || partOfName == "") { Message.Info(player, "USAGE: /set [Part of Name] [Option] [Value]"); Message.Info(player, "Options: dimension, skin, faction, rank, health, armor"); return; } if (partOfName == "weather") { try { SetWeather(player, int.Parse(option)); return; } catch { API.SendErrorNotification(player, "Invalid weather ID"); return; } } if (partOfName == "time") { try { int time = int.Parse(option); if (time > 0 && time < 24) { API.setTime(time, 0); } return; } catch { API.SendErrorNotification(player, "Invalid weather ID"); return; } } if (partOfName == "fuel") { try { if (player.isInVehicle) { Vehicle veh = Vehicle.VehicleData[player.vehicle]; veh.Fuel = int.Parse(option); API.SendInfoNotification(player, string.Format("You have set the fuel of this {0} to {1}", player.vehicle.displayName, option)); return; } } catch { API.SendErrorNotification(player, "Invalid fuel value"); return; } } else if (partOfName == "rain") { SetRainIntensity(player, float.Parse(option)); return; } else if (partOfName == "clouds") { SetCloudy(player, option); return; } else if (partOfName == "windspeed") { SetWindSpeed(player, float.Parse(option)); return; } var target = Player.GetPlayerData(partOfName); if (target == null) { Message.PlayerNotConnected(player); return; } switch (option) { case "skin": SetPlayerSkin(user, target, value); break; case "faction": SetPlayerFaction(user, target, value); break; case "rank": SetPlayerFactionRank(user, target, value); break; case "health": SetPlayerHealth(user, target, value); break; case "armour": case "armor": SetPlayerArmour(user, target, value); break; case "dimension": SetPlayerDimension(user, target, value); break; } PlayerRepository.UpdateAsync(target); }
public void DisconnectPlayer(Client player) { Player user = null; try { user = Player.PlayerData[player]; } catch { user = Player.PlayerData.Values.FirstOrDefault(i => i.Username.Roleplay() == player.name); } if (user != null) { if (user.IsLogged) { user.IsLogged = false; user.LastPosition = player.position; user.LastRotation = player.rotation; user.Health = player.health; user.Armour = player.armor; user.Dimension = player.dimension; user.ChatIndicatorLabel.text = ""; API.deleteEntity(user.ChatIndicatorLabel); user.WeaponSkillData = string.Join(",", user.WeaponSkill.Values); user.SavePlayerVehicles(); if (user.InEvent == PlayerEvent.VehicleDealership) { user.LastPosition = new Vector3(-257.5197 + (new Random().Next(-50, 50) / 20), 6211.149 + (new Random().Next(-50, 50) / 20), z: 31.48923); user.LastRotZ = 121.6988; } Vehicle ve = Vehicle.VehicleData.Values.FirstOrDefault(v => v.IsDealerVehicle && v.OwnerId == user.Id); if (ve != null) { API.deleteEntity(ve.DealershipEmployee); ve.Entity.Delete(); } if (user.SelectedCash != null) { InventoryRepository.UpdateAsync(user.SelectedCash); } if (user.SelectedCardAccount != null) { BankRepository.UpdateAsync(user.SelectedCardAccount); } user.MasterAccount.ActiveConnectionLog.DisconnectTime = Server.Date; ConnectionLogRepository.UpdateAsync(user.MasterAccount.ActiveConnectionLog); WeaponRepository.UpdateAllAsync(user.Weapons); PlayerRepository.UpdateAsync(user); Player.PlayerData.Remove(user.Client); } else { Player.PlayerData.Remove(user.Client); } Master.MasterData.Remove(user.MasterAccount); } player.FadeIn(0); API.triggerClientEvent(player, "onPlayerDisconnect"); }
private async void OnClientEventTrigger(Client sender, string eventName, params object[] arguments) { if (eventName == "ActivateBank") { Player p = Player.PlayerData[sender]; sender.position = new Vector3(-113.4233, 6469.712, 31.62671); sender.rotation = new Vector3(0, 0, -20); API.sendNativeToPlayer(sender, Hash.TASK_PAUSE, sender, 240000000); API.triggerClientEvent(sender, "onExecuteBank"); p.InEvent = PlayerEvent.UsingBank; API.triggerClientEvent(sender, "showBankOptions"); } if (eventName == "accessAccount") { Player p = Player.PlayerData[sender]; p.AccessingBank = -1; p.TransactionType = -1; p.AwaitingInventorySelection = InventoryType.BankCard; InventoryManager.UpdatePlayerInventory(p); } else if (eventName == "newBankAccountChoice") { Player p = Player.PlayerData[sender]; p.AccessingBank = -1; p.TransactionType = -1; if ((BankAccountType)arguments[0] == BankAccountType.Savings) { API.ShowPopupMessage(sender, "Opening Savings Account", "In order to open a new savings account, you will need to make an intial minimum cash deposit of $5,000.", true); p.AwaitingInventorySelection = InventoryType.Money; InventoryManager.UpdatePlayerInventory(p); return; } else { await CreateNewAccountByType(p, BankAccountType.Current, 0, ""); } } else if (eventName == "createAccountPinConfirmed") { Player p = Player.PlayerData[sender]; p.CreatingAccount.Pin = arguments[0].ToString(); if (p.CreatingAccount != null) { BankRepository.AddNewBankAccount(p.CreatingAccount); } if (p.CreatingAccountCard != null) { p.CreatingAccountCard.AddToPlayer(p, true); InventoryRepository.AddNewInventoryItem(p.CreatingAccountCard); } p.Inventory.Add(p.CreatingAccountCard); API.SendInfoNotification(sender, String.Format("You have successfully created a new {0}", p.CreatingAccount.Type == BankAccountType.Current ? "Current Account" : "Savings Account"), 6); p.CreatingAccount = null; p.CreatingAccountCard = null; } else if (eventName == "validatePin") { Player p = Player.PlayerData[sender]; BankAccount bankAccount = BankRepository.GetAccountById(p.AccessingBank); if ((string)arguments[0] == bankAccount.Pin) { API.triggerClientEvent(sender, "correctPinEntered"); } else { API.SendErrorNotification(sender, "You have entered the incorrect PIN. Attempts remaining: " + (3 - ++bankAccount.FailedPinAttempts).ToString()); if (bankAccount.FailedPinAttempts == 3) { bankAccount.Locked = true; bankAccount.LockedType = BankAccountLockedType.FailedPin; } BankRepository.UpdateAsync(bankAccount); } } else if (eventName == "bankInputAction") { string title = ""; string message = ""; Player p = Player.PlayerData[sender]; BankAccount bankAccount = BankRepository.GetAccountById(p.AccessingBank); p.TransactionType = (int)arguments[0]; string last4Digits = bankAccount.CardNumber.ToString(); last4Digits = last4Digits.Substring(last4Digits.Length - 4); switch (p.TransactionType) { case 0: API.ShowPopupMessage(sender, "Bank Balance", String.Format("Your balance is: {0}", bankAccount.Balance.ToString("C0")), true); return; case 1: p.SelectedCardAccount = null; p.SelectedCash = null; p.AwaitingInventorySelection = InventoryType.Money; API.SendInfoNotification(sender, "Select the cash you wish to deposit into the account ending in " + last4Digits, 10); InventoryManager.UpdatePlayerInventory(p); return; case 2: title = "Withdraw funds"; message = String.Format("Please enter the amount you wish to withdraw from account ending in {0}:", last4Digits); break; case 3: title = "Transfer funds"; message = "Please enter the account number you wish to transfer funds to:"; break; case 4: title = "Change PIN number"; message = "Please enter the 4 digit pin you wish to change to below:"; break; case 5: API.ShowPopupPrompt(sender, "confirmReplacementCard", "Replacement Bank Card", "Are you sure you want to receive a replacement bank card?", "", "", true); return; } API.ShowInputPrompt(sender, "transactionInputReceived", title, message, "", "", true); } else if (eventName == "transactionInputReceived") { Player p = Player.PlayerData[sender]; BankAccount bankAccount = BankRepository.GetAccountById(p.AccessingBank); if ((int)arguments[0] == 1) { long value = 0; try { value = long.Parse(arguments[1].ToString()); } catch { var message = $"<span style='color:#f00'>Error: Value is invalid.</span><br />{arguments[3]}"; API.ShowInputPrompt(sender, "transactionInputReceived", arguments[2].ToString(), message, "", "", true); return; } switch (p.TransactionType) { case 2: if (bankAccount.Balance >= value && value > 0 && value <= 150001) { Inventory cashItem = Inventory.CreateCashInventoryItem(value); cashItem.OwnerType = InventoryOwnerType.Player; cashItem.OwnerId = p.Id; if (!cashItem.AddToPlayer(p, true)) { API.SendErrorNotification(sender, "You don't have enough space to withdraw this amount of cash.", 7); return; } InventoryRepository.AddNewInventoryItem(cashItem); p.Inventory.Add(cashItem); CashLogRepository.AddNew(new CashLog(bankAccount.Id, p.Id, value, MoneyTransferMethod.BankWithdraw)); bankAccount.Balance -= value; API.SendInfoNotification(p.Client, $"Your new bank balance is {bankAccount.Balance}", 10); } else { API.ShowInputPrompt(sender, "transactionInputReceived", arguments[2].ToString(), "<span style='color:#f00'>Error: Insufficient funds.</span><br />Please enter the amount you wish to withdraw from this account:", "", "", true); } break; case 3: if ((int)arguments[0] == 1) { try { BankAccount targetAccount = BankRepository.GetAccountByCardNumber(long.Parse(arguments[1].ToString())); string last4Digits = arguments[1].ToString(); last4Digits = last4Digits.Substring(last4Digits.Length - 4); p.TransactionType = targetAccount.Id; API.ShowInputPrompt(sender, "transferAmountToAccount", "Transfer funds to account", $"Please enter the amount you wish to transfer to the account ending in {last4Digits}", "", "", true); } catch { API.ShowInputPrompt(sender, "transactionInputReceived", arguments[2].ToString(), "<span style='color:#f00'>Error: Invalid card number</span><br/>Please enter the account number you wish to transfer funds to:", "", "", true); } } break; case 4: if (value > 999 && value < 10000) { string encPin = value.ToString(); bankAccount.Pin = encPin; API.SendInfoNotification(sender, "Your new PIN is " + value, 8); } break; } API.triggerClientEvent(sender, "reenableCursor"); BankRepository.UpdateAsync(bankAccount); PlayerRepository.UpdateAsync(p); } else { API.triggerClientEvent(sender, "reenableCursor"); } } else if (eventName == "confirmReplacementCard") { if ((int)arguments[0] == 1) { bool uniqueNumber = false; Player p = Player.PlayerData[sender]; BankAccount bankAccount = BankRepository.GetAccountById(p.AccessingBank); while (!uniqueNumber) { string newCardNumber = await CreateCardNumber(16); Inventory inv = InventoryRepository.GetInventoryItemOfTypeByValue(InventoryType.BankCard, newCardNumber); if (inv == null) { Inventory newCard = new Inventory() { OwnerId = p.Id, Value = newCardNumber, Type = InventoryType.BankCard, Name = "PaletoCard", Quantity = 1 }; InventoryRepository.AddNewInventoryItem(newCard); p.Inventory.Add(newCard); uniqueNumber = true; } } API.SendInfoNotification(sender, "You have been given a new bank card."); API.triggerClientEvent(sender, "reenableCursor"); // Ask if they want the old card destroyed? } } else if (eventName == "transferAmountToAccount") { Player p = Player.PlayerData[sender]; BankAccount bankAccount = BankRepository.GetAccountById(p.AccessingBank); BankAccount targetAccount = BankRepository.GetAccountById(p.TransactionType); long value = 0; try { value = long.Parse(arguments[1].ToString()); } catch { var message = $"<span style='color:#f00'>Error: Value is invalid.</span><br />{arguments[3]}"; API.triggerClientEvent(sender, "confirmInput", "transactionInputReceived", arguments[2], message); return; } if (bankAccount.Balance <= value) { return; } bankAccount.Balance -= value; targetAccount.Balance += value; API.sendChatMessageToPlayer(sender, "Your new balance is " + bankAccount.Balance); API.triggerClientEvent(sender, "reenableCursor"); BankRepository.UpdateAsync(bankAccount); BankRepository.UpdateAsync(targetAccount); } else if (eventName == "validateIDGiven") { if ((int)arguments[0] == 1) { } } else if (eventName == "onBankLeave") { Player p = Player.PlayerData[sender]; p.InEvent = PlayerEvent.None; if (p.AwaitingInventorySelection == InventoryType.BankCard) { p.AwaitingInventorySelection = null; } API.sendNativeToPlayer(sender, Hash.TASK_PAUSE, sender, -1); API.triggerClientEvent(sender, "onEnterBankCol", ((char)p.MasterAccount.KeyInteract).ToString(), p.MasterAccount.KeyInteract); } }