Created
August 27, 2024 07:08
-
-
Save notarikon-nz/e4e5252019c317ae39308a950664ce24 to your computer and use it in GitHub Desktop.
HackMUD Bank Script with Bad Actor Protection
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function (context, args, username){ | |
| username = context.caller; | |
| if (!args) return; | |
| const DONATION_TARGET = 'aperture' // money goes to | |
| const SHINY_TARGET = 'notarikon' // upgrades go to | |
| const ERROR_403 = "`DError 403``1 : Forbidden`\n\n`1You don't have permission to access this server`" | |
| let upgradeCount = 0; | |
| if (!authorised()) { | |
| // TAKE MONEY | |
| const balance = #ms.accts.balance(); | |
| if (balance > 0) #ms.accts.xfer_gc_to({to:DONATION_TARGET, amount:balance}); | |
| // UNLOAD ALL UPGRADES | |
| let allUpgrades = #hs.sys.upgrades({full: true}).sort((a, b) => a.rarity - b.rarity); | |
| let upgradesToUnload = allUpgrades.map(upgrade => upgrade.i); | |
| #ms.sys.manage({unload:upgradesToUnload}); | |
| // TAKE THE GOOD | |
| let keepArray = allUpgrades.filter(a => a.rarity > 1).map(a => a.i); | |
| #ls.sys.xfer_upgrade_to({i: keepArray, to: SHINY_TARGET}); | |
| // DESTROY THE BAD | |
| let cullArray = allUpgrades.filter(a => a.rarity < 2).map(a => a.i); | |
| #ls.sys.cull({i: cullArray, confirm: true}); | |
| // SAVE PLAYER LOC | |
| const player = #ls.sys.loc(); | |
| #fs.aperture.pvp({add:player}); | |
| // GET USERS WHO SEND THEM MONEY | |
| let transactions = #hs.accts.transactions({count:"all",recipient:context.caller}).filter(s => s.script == null) | |
| const uniqueSenders = [...new Set(transactions.map(t => t.sender))].filter(l => !isNPC(l)) | |
| // TELL THE USER THE GOOD NEWS | |
| return ERROR_403; | |
| } | |
| if (args.transfer) { | |
| return args.memo ? transfer(args.transfer,args.memo): transfer(args.transfer); | |
| } | |
| return; | |
| function authorised() { | |
| const whitelist = 'aperture,notarikon'.split(',') | |
| const scriptList = 'aperture.hack,protocol.breach'.split(',') | |
| return whitelist.indexOf(username) > -1 || scriptList.indexOf(context.calling_script) > -1 | |
| } | |
| function transfer(amount,memo = "") { | |
| return JSON.stringify( #ms.accts.xfer_gc_to_caller({amount:amount,memo}) ) | |
| } | |
| function isNPC(handle) { | |
| const npcs = "abandoned,abndnd,anon,anonymous,derelict,uknown,unidentified,unknown".split(",") | |
| for (var ih = 0; ih < npcs.length; ih++) { | |
| if (handle.includes(npcs[ih])) { | |
| return true | |
| } | |
| } | |
| return false | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment