diff --git a/config.yaml b/config.yaml index f46841921b3..cf319c324ea 100644 --- a/config.yaml +++ b/config.yaml @@ -165,6 +165,14 @@ server: DB_PASS: "" INIT_CONNECTION_POOL_TIMEOUT: 90 # Seconds + PG_DB_URL: "jdbc:postgresql://localhost:5432/cosmic" + PG_DB_SCHEMA: "cosmic" + PG_DB_ADMIN_USERNAME: "cosmic_admin" + PG_DB_ADMIN_PASSWORD: "redsnailshell" + PG_DB_USERNAME: "cosmic_server" + PG_DB_PASSWORD: "bluesnailshell" + PG_DB_CLEAN: false # !!! WARNING !!! Deletes the entire database - starts from scratch. + #Login Configuration WORLDS: 1 #Initial number of worlds on the server. WLDLIST_SIZE: 21 #Max possible worlds on the server. @@ -185,7 +193,6 @@ server: BYPASS_PIN_EXPIRATION: 15 #Enables PIN bypass, which will remain active for that account by that client machine for N minutes. Set 0 to disable. AUTOMATIC_REGISTER: true #Automatically register players when they login with a nonexistent username. - BCRYPT_MIGRATION: true #Performs a migration from old SHA-1 and SHA-512 password to bcrypt. COLLECTIVE_CHARSLOT: false #Available character slots are contabilized globally rather than per world server. DETERRED_MULTICLIENT: false #Enables detection of multi-client and suspicious remote IP on the login system. #Besides blocking logging in with several client sessions on the same machine, this also blocks suspicious login attempts for players that tries to login on an account using several diferent remote addresses. @@ -234,7 +241,6 @@ server: USE_AUTOBAN: false #Commands the server to detect infractors automatically. USE_AUTOBAN_LOG: true #Log autoban related messages. Still logs even with USE_AUTOBAN disabled. USE_EXP_GAIN_LOG: false #Logs characters exp gains; logs world rate & coupon exp, total gained exp, and current exp, level can be calculated from "ExpTable". - USE_AUTOSAVE: true #Enables server autosaving feature (saves characters to DB each 1 hour). USE_SERVER_AUTOASSIGNER: false #HeavenMS-builtin autoassigner, uses algorithm based on distributing AP accordingly with required secondary stat on equipments. USE_REFRESH_RANK_MOVE: true USE_ENFORCE_ADMIN_ACCOUNT: false #Forces accounts having GM characters to be treated as a "GM account" by the client (localhost). Some of the GM account perks is the ability to FLY, but unable to TRADE. @@ -246,7 +252,6 @@ server: USE_ENFORCE_ITEM_SUGGESTION: false #Forces the Owl of Minerva and the Cash Shop to always display the defined item array instead of those featured by the players. USE_ENFORCE_UNMERCHABLE_CASH: true #Forces players to not sell CASH items via merchants, drops of it disappears. USE_ENFORCE_UNMERCHABLE_PET: true #Forces players to not sell pets via merchants, drops of it disappears. (since non-named pets gets dirty name and other possible DB-related issues) - USE_ENFORCE_MERCHANT_SAVE: true #Forces automatic DB save on merchant owners, at every item movement on shop. USE_ENFORCE_MDOOR_POSITION: false #Forces mystic door to be spawned near spawnpoints. USE_SPAWN_CLEAN_MDOOR: false #Makes mystic doors to be spawned without deploy animation. This clears disconnecting issues that may happen when trying to cancel doors a couple seconds after deployment. USE_SPAWN_RELEVANT_LOOT: true #Forces to only spawn loots that are collectable by the player or any of their party members. @@ -355,7 +360,6 @@ server: USE_FULL_HOLY_SYMBOL: false #Holy symbol doesn't require EXP sharers to work in full. #Character Configuration - USE_ADD_SLOTS_BY_LEVEL: false #Slots are added each 20 levels. USE_ADD_RATES_BY_LEVEL: false #Rates are added each 20 levels. USE_STACK_COUPON_RATES: false #Multiple coupons effects builds up together. USE_PERFECT_PITCH: false #For lvl 30 or above, each lvlup grants player 1 perfect pitch. @@ -363,12 +367,6 @@ server: #Quest Configuration USE_QUEST_RATE: false #Exp/Meso gained by quests uses fixed server exp/meso rate times quest rate as multiplier, instead of player rates. - #Quest Points Configuration - QUEST_POINT_REPEATABLE_INTERVAL: 25 #Minimum interval between repeatable quest completions for quest points to be awarded. - QUEST_POINT_REQUIREMENT: 0 #Exchange factor between N quest points to +1 fame, set 0 to disable the entire quest point mechanism. - QUEST_POINT_PER_QUEST_COMPLETE: 0 #Each completed quest awards N quest points, set 0 to disable. - QUEST_POINT_PER_EVENT_CLEAR: 0 #Each completed event instance awards N quest points, set 0 to disable. - #Guild Configuration CREATE_GUILD_MIN_PARTNERS: 6 #Minimum number of members on Guild Headquarters to establish a new guild. CREATE_GUILD_COST: 1500000 diff --git a/database/.gitignore b/database/.gitignore new file mode 100644 index 00000000000..bdf07d7883b --- /dev/null +++ b/database/.gitignore @@ -0,0 +1,2 @@ +docker-db-data/* +docker-pg-db-data/* \ No newline at end of file diff --git a/database/docker-db-data/.gitignore b/database/docker-db-data/.gitignore deleted file mode 100644 index e7a210ec7dc..00000000000 --- a/database/docker-db-data/.gitignore +++ /dev/null @@ -1,3 +0,0 @@ -* -*/ -!.gitignore \ No newline at end of file diff --git a/database/postgres-scripts/create-db-and-admin-user.sql b/database/postgres-scripts/create-db-and-admin-user.sql new file mode 100644 index 00000000000..66ff0c52543 --- /dev/null +++ b/database/postgres-scripts/create-db-and-admin-user.sql @@ -0,0 +1,3 @@ +CREATE DATABASE cosmic; +CREATE USER cosmic_admin WITH CREATEROLE ENCRYPTED PASSWORD 'redsnailshell'; +GRANT ALL PRIVILEGES ON DATABASE cosmic TO cosmic_admin; diff --git a/database/sql/1-db_database.sql b/database/sql/1-db_database.sql new file mode 100644 index 00000000000..5f282702bb0 --- /dev/null +++ b/database/sql/1-db_database.sql @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index a872b6dc839..449fedd2626 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,6 +4,7 @@ services: build: . depends_on: - db + - pg_db ports: # Login server - "8484:8484" @@ -19,7 +20,8 @@ services: - ./wz:/opt/server/wz environment: DB_HOST: "db" ## Remember if this is present it will OVERRIDE the host in the config.yaml, if you put here anything other than db, you'll need to change the config.yaml jdbc string to port 3307, and not port 3306 - + PG_DB_HOST: "pg_db" + db: image: mysql:8.4.0 environment: @@ -30,3 +32,13 @@ services: - "3307:3306" volumes: - ./database/docker-db-data:/var/lib/mysql + + pg_db: + image: postgres:15.0 + ports: + - "5433:5432" + environment: + POSTGRES_PASSWORD: postgres + volumes: + - ./database/docker-pg-db-data:/var/lib/postgresql/data + - ./database/postgres-scripts:/docker-entrypoint-initdb.d diff --git a/pom.xml b/pom.xml index 945a417fd89..7d5f950a035 100644 --- a/pom.xml +++ b/pom.xml @@ -69,6 +69,11 @@ 4.32.0 5.13.1 5.18.0 + 1.20.1 + 42.5.4 + 9.15.1 + 3.1.4 + 1.18.34 @@ -82,6 +87,17 @@ jcip-annotations ${jcip-annotations.version} + + com.github.ben-manes.caffeine + caffeine + ${caffeine.version} + + + org.projectlombok + lombok + ${lombok.version} + provided + @@ -94,11 +110,21 @@ mysql-connector-j ${mysql-connector-j.version} + + org.postgresql + postgresql + ${postgresql.version} + org.jdbi jdbi3-core ${jdbi-version} + + org.flywaydb + flyway-core + ${flyway.version} + org.liquibase liquibase-core @@ -192,6 +218,25 @@ ${mockito.version} test + + org.testcontainers + postgresql + ${testcontainers.version} + test + + + org.testcontainers + mysql + ${testcontainers.version} + test + + + org.testcontainers + junit-jupiter + ${testcontainers.version} + test + + diff --git a/scripts/npc/1022101_old.js b/scripts/npc/1022101_old.js deleted file mode 100644 index 98d0034156b..00000000000 --- a/scripts/npc/1022101_old.js +++ /dev/null @@ -1,222 +0,0 @@ -/* - This file is part of the OdinMS Maple Story Server - Copyright (C) 2008 Patrick Huy - Matthias Butz - Jan Christian Meyer - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ -/* Rooney - Map Name (Map ID) - Used to exchange VP for Maple Leaves, and Maple Leaves for rewards. - */ - -var itemToUse = 4001126; - -var chairs = [3010000, 3010001, 3010002, 3010003, 3010004, 3010005, 3010006, 3010007, 3010008, 3010009, 3010010, 3010011, 3010012, 3010013, 3010015, 3010016, 3010017, 3010018, 3010019, 3010022, 3010023, 3010024, 3010025, 3010026, 3010028, 3010040, 3010041, 3010043, 3010045, 3010046, 3010047, 3010057, 3010058, 3010060, 3010061, 3010062, 3010063, 3010064, 3010065, 3010066, 3010067, 3010069, 3010071, 3010072, 3010073, 3010080, 3010081, 3010082, 3010083, 3010084, 3010085, 3010097, 3010098, 3010099, 3010101, 3010106, 3010116, 3011000, 3012005, 3012010, 3012011]; -var scrolls = [2040603, 2044503, 2041024, 2041025, 2044703, 2044603, 2043303, 2040807, 2040806, 2040006, 2040007, 2043103, 2043203, 2043003, 2040506, 2044403, 2040903, 2040709, 2040710, 2040711, 2044303, 2043803, 2040403, 2044103, 2044203, 2044003, 2043703]; -var weapons = [1302020, 1302030, 1302033, 1302058, 1302064, 1302080, 1312032, 1322054, 1332025, 1332055, 1332056, 1372034, 1382009, 1382012, 1382039, 1402039, 1412011, 1412027, 1422014, 1422029, 1432012, 1432040, 1432046, 1442024, 1442030, 1442051, 1452016, 1452022, 1452045, 1462014, 1462019, 1462040, 1472030, 1472032, 1472055, 1482020, 1482021, 1482022, 1492020, 1492021, 1492022, 1092030, 1092045, 1092046, 1092047]; - -var nxAmount = 3000; -var chairAmount = 2; -var weaponAmount = 2; -var buffAmount = 2; -var hiredMerchantLength = 7; - -var buff1ID = 2022273; -var buff2ID = 2022179; -var status; -var vp; -var choice; - -function start() { - //vp = cm.getClient().getVotePoints(); - //if(vp == null) - vp = 0; - - status = -1; - action(1, 0, 0); -} - -function action(mode, type, selection) { - if (mode < 0) { - cm.dispose(); - } else { - if (mode == 1) { - status++; - } else { - status--; - } - if (status == 0 && mode == 1) { - if (cm.getPlayer().getLevel() < 20) { - cm.sendOk("Hello, I am the Vote Point exchanger for #rMapleSolaxia#k!\r\n\r\nI am sorry, but I can only exchange Vote Points for players #blevel 20 or over#k."); - cm.dispose(); - return; - } - var outStr = "Hello, I am the Vote Point exchanger for #rMapleSolaxia#k!\r\n"; - outStr += "You currently have #r#c" + itemToUse + "##k #t" + itemToUse + "# and #r" + vp + "#k Vote Points.#b\r\n\r\n"; - outStr += "#L0#I would like to exchange my vote points for Maple Leaves#l\r\n"; - outStr += "#L1#I would like to exchange 1 #t" + itemToUse + "# for " + nxAmount + " NX Cash#l\r\n"; - outStr += "#L2#I would like to exchange 1 #t" + itemToUse + "# for " + chairAmount + " Random Chair" + (chairAmount > 1 ? "s" : "") + "#l\r\n"; - outStr += "#L3#I would like to exchange 1 #t" + itemToUse + "# for " + weaponAmount + " Maple Weapons#l\r\n"; - outStr += "#L4#I would like to exchange 1 #t" + itemToUse + "# for " + buffAmount + " #t" + buff1ID + "#s and " + buffAmount + " #t" + buff2ID + "#s#l\r\n"; - outStr += "#L5#I would like to exchange 1 #t" + itemToUse + "# for a " + hiredMerchantLength + " Day Hired Merchant#l\r\n"; - cm.sendSimple(outStr); - } else if (status == 1) { - choice = selection; - - if (selection > 0) { - if (!cm.haveItem(itemToUse) && vp == 0) { - cm.sendOk("I'm sorry, but you don't have any #t" + itemToUse + " or Vote Points."); - cm.dispose(); - return; - } - } - - if (selection == 0) { - // Exchange VP for leaves - if (vp <= 0) { - cm.sendOk("I'm sorry, but you don't have any Vote Points to exchange!"); - cm.dispose(); - return; - } - cm.sendYesNo("Would you like to exchange " + vp + " Vote Point" + (vp > 0 ? "s" : "") + " for " + vp + " #t" + itemToUse + "# " + (vp > 0 ? "s" : "") + "?"); - } else if (selection == 1) { - // Exchange 1 Leaf for Cash - cm.sendYesNo("Would you like to exchange 1 #t" + itemToUse + "# for " + nxAmount + " NX Cash?"); - } else if (selection == 2) { - // Exchange 1 Leaf for Chair - cm.sendYesNo("Would you like to exchange 1 #t" + itemToUse + "# for " + chairAmount + " Random Chair" + (chairAmount > 1 ? "s" : "") + "?"); - } else if (selection == 3) { - // Exchange 1 Leaf for Maple Weapons - cm.sendYesNo("Would you like to exchange 1 #t" + itemToUse + "# for " + weaponAmount + " Random Maple Weapons?"); - } else if (selection == 4) { - // Exchange 1 Leaf for Apples/Cheese - cm.sendYesNo("Would you like to exchange 1 #t" + itemToUse + "# for " + buffAmount + " #t" + buff1ID + "# and #t" + buff2ID + "#?"); - } else if (selection == 5) { - // Echange 1 Leaf for Merchant - cm.sendYesNo("Would you like to exchange 1 #t" + itemToUse + "# for a " + hiredMerchantLength + " Day Hired Merchant?"); - } else { - cm.dispose(); - } - } else if (status == 2) { - var useVP = false; - if (!cm.hasItem(itemToUse) && vp > 0) { - useVP = true; - } - - const InventoryType = Java.type('client.inventory.InventoryType'); - if (choice == 0) { - // VP Exchange - if (!cm.canHold(itemToUse)) { - cm.sendOk("It looks like you don't have enough space in your #rETC#k inventory to hold the #t" + itemToUse + "#" + (vp > 0 ? "s" : "") + "."); - cm.dispose(); - return; - } - - cm.getClient().useVotePoints(vp); - cm.gainItem(itemToUse, vp); - cm.dispose(); - } else if (choice == 1) { - // Leaf for Cash - if (useVP) { - cm.getClient().useVotePoints(1); - } else { - cm.gainItem(itemToUse, -1); - } - - cm.getPlayer().getCashShop().gainCash(1, nxAmount); - const PacketCreator = Java.type('tools.PacketCreator'); - cm.getPlayer().sendPacket(PacketCreator.earnTitleMessage("You have earned " + nxAmount + " NX")); - cm.logLeaf(nxAmount + " NX"); - cm.dispose(); - } else if (choice == 2) { - if (!cm.getPlayer().getInventory(InventoryType.SETUP).isFull(chairAmount)) { - - var chairStr = ""; - for (var i = 0; i < chairAmount; i++) { - var chair = chairs[Math.floor(Math.random() * chairs.length)]; - cm.gainItem(chair, 1, true); - chairStr += chair + " "; - } - - if (useVP) { - cm.getClient().useVotePoints(1); - } else { - cm.gainItem(itemToUse, -1); - } - - cm.logLeaf("Chair ID: " + chairStr); - cm.dispose(); - } else { - cm.sendOk("Please make sure you have enough space to hold the items!"); - } - } else if (choice == 3) { - if (!cm.getPlayer().getInventory(InventoryType.EQUIP).isFull(weaponAmount)) { - - var weaponStr = ""; - for (var i = 0; i < weaponAmount; i++) { - var weapon = weapons[Math.floor(Math.random() * weapons.length)]; - cm.gainItem(weapon, 1, true, true); - weaponStr += weapon + " "; - } - - if (useVP) { - cm.getClient().useVotePoints(1); - } else { - cm.gainItem(itemToUse, -1); - } - - cm.logLeaf("Maple Weapon IDs: " + weaponStr); - cm.dispose(); - } else { - cm.sendOk("Please make sure you have enough space to hold the items!"); - } - } else if (choice == 4) { - if (!cm.getPlayer().getInventory(InventoryType.USE).isFull(2)) { - cm.gainItem(buff1ID, buffAmount, true); - cm.gainItem(buff2ID, buffAmount, true); - cm.gainItem(itemToUse, -1); - cm.logLeaf(buffAmount + " cheeses and apples"); - cm.dispose(); - } else { - cm.sendOk("Please make sure you have enough space to hold the items!"); - } - } else if (choice == 5) { - if (!cm.haveItem(5030000, 1)) { - if (!cm.getPlayer().getInventory(InventoryType.CASH).isFull(1)) { - cm.gainItem(5030000, 1, false, true, 1000 * 60 * 60 * 24 * hiredMerchantLength); - - if (useVP) { - cm.getClient().useVotePoints(1); - } else { - cm.gainItem(itemToUse, -1); - } - - cm.logLeaf(hiredMerchantLength + " day hired merchant"); - cm.dispose(); - } else { - cm.sendOk("Please make sure you have enough space to hold these items!"); - } - } else { - cm.sendOk("I can't give you a merchant if you already have one!"); - } - } - } else { - cm.dispose(); - } - } -} \ No newline at end of file diff --git a/scripts/npc/11000.js b/scripts/npc/11000.js deleted file mode 100644 index 4c2bad1faba..00000000000 --- a/scripts/npc/11000.js +++ /dev/null @@ -1,25 +0,0 @@ -/* - This file is part of the HeavenMS MapleStory Server - Copyleft (L) 2016 - 2019 RonanLana - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -function start() { - const ShopFactory = Java.type('server.ShopFactory'); - ShopFactory.getInstance().getShop(11000).sendShop(cm.getClient()); - cm.dispose(); -} diff --git a/scripts/npc/2100002.js b/scripts/npc/2100002.js deleted file mode 100644 index 2cbe7b96f0d..00000000000 --- a/scripts/npc/2100002.js +++ /dev/null @@ -1,11 +0,0 @@ -var status = 0; - -function start() { - status = -1; - action(1, 0, 0); -} - -function action(mode, type, selection) { - cm.openShopNPC(2100002); - cm.dispose(); -} \ No newline at end of file diff --git a/scripts/npc/2100003.js b/scripts/npc/2100003.js deleted file mode 100644 index 2abc59d8aa1..00000000000 --- a/scripts/npc/2100003.js +++ /dev/null @@ -1,11 +0,0 @@ -var status = 0; - -function start() { - status = -1; - action(1, 0, 0); -} - -function action(mode, type, selection) { - cm.openShopNPC(2100003); - cm.dispose(); -} \ No newline at end of file diff --git a/scripts/npc/9201099.js b/scripts/npc/9201099.js index c22922ed9f0..8973e0b2b8d 100644 --- a/scripts/npc/9201099.js +++ b/scripts/npc/9201099.js @@ -1,14 +1,88 @@ /** - *9201098 - Mo - *@author Ronan + * 9201098 - Mo + * @author Ronan + * @author Ponk */ +let status = 0; +let selectedItem = undefined; + +/* +References: +- https://www.youtube.com/watch?v=g6y2zmCGglI +- https://www.youtube.com/watch?v=CttmlVWLJKM +*/ function start() { - if (cm.getQuestStatus(8224) == 2) { - cm.openShopNPC(9201099); - } else { - cm.sendOk("Hm, at who do you think you are looking at?"); + if (cm.getQuestStatus(8224) !== 2) { + cm.sendDefault(); + cm.dispose(); + return; + } + + cm.sendSimple("Name's Mo. I've got Mo' items for Mo' mesos. What business do you bring me?\r\n#L0##bI'd like to buy some items#k"); +} + +function action(action, type, selection) { + if (!action) { + cm.dispose(); + return; } - cm.dispose(); + if (status === 0) { + let index = 0; + const selections = "#e" + shopItems() + .map(i => { + const mesoText = i.quantity === 1 ? "meso" : `meso per ${i.quantity} arrows`; + return `\r\n#L${index++}##i${i.itemId}# #z${i.itemId}# #b${i.cost} ${mesoText}#k`; + }) + .join(""); + cm.sendSimple("An ally of the Raven Ninja Clan is welcome to buy from me!" + selections); + status++; + } else if (status === 1 && selection !== -1) { + selectedItem = shopItems()[selection]; + cm.sendAcceptDecline("Are you sure you want to buy it?"); + status++; + } else if (status === 2) { + if (!selectedItem) { + cm.dispose(); + return; + } + if (!cm.hasMeso(selectedItem.cost)) { + cm.sendOk("You don't have enough mesos."); + cm.dispose(); + return; + } + if (!cm.canHold(selectedItem.itemId, selectedItem.quantity)) { + cm.sendOk("There's no room in your inventory."); + cm.dispose(); + return; + } + + cm.loseMeso(selectedItem.cost); + cm.gainItem(selectedItem.itemId, selectedItem.quantity); + cm.dispose(); + } +} + +function shopItems() { + return [ + {itemId: 2050004, quantity: 1, cost: 400}, // All-Cure Potion + {itemId: 2050000, quantity: 1, cost: 200}, // Antidote + {itemId: 2020012, quantity: 1, cost: 4500}, // Melting Cheese + {itemId: 2020013, quantity: 1, cost: 5000}, // Reindeer Milk + {itemId: 2020014, quantity: 1, cost: 8100}, // Sunrise Dew + {itemId: 2020015, quantity: 1, cost: 9690}, // Sunset Dew + {itemId: 2050001, quantity: 1, cost: 200}, // Eyedrop + {itemId: 2050002, quantity: 1, cost: 300}, // Tonic + {itemId: 2050003, quantity: 1, cost: 500}, // Holy Water + {itemId: 2022000, quantity: 1, cost: 1650}, // Pure Water + {itemId: 2002017, quantity: 1, cost: 5000}, // Warrior Elixir + {itemId: 2060004, quantity: 2000, cost: 40_000}, // Diamond Arrow for Bow + {itemId: 2061004, quantity: 2000, cost: 40_000}, // Diamond Arrow for Crossbow + {itemId: 2070010, quantity: 1, cost: 2000}, // Icicle + {itemId: 2022003, quantity: 1, cost: 1100}, // Unagi + {itemId: 2000006, quantity: 1, cost: 620}, // Mana Elixir + {itemId: 2022002, quantity: 1, cost: 1000}, // Cider + {itemId: 2030020, quantity: 1, cost: 400}, // Return to New Leaf City Scroll + ] } diff --git a/scripts/npc/commands.js b/scripts/npc/commands.js index 8dfdc7aa302..032217109bb 100644 --- a/scripts/npc/commands.js +++ b/scripts/npc/commands.js @@ -14,9 +14,9 @@ var staff_heading = "!"; var levels = ["Common", "Donator", "JrGM", "GM", "SuperGM", "Developer", "Admin"]; var commands; +// Expectation: "ce" bound to an instance of java.client.command.CommandsExecutor function writeHeavenMSCommands() { - const CommandsExecutor = Java.type('client.command.CommandsExecutor'); - commands = CommandsExecutor.getInstance().getGmCommands(); + commands = ce.getGmCommands(); } function start() { diff --git a/src/main/java/client/AbstractCharacterObject.java b/src/main/java/client/AbstractCharacterObject.java index e178ac1f43a..4703007a72a 100644 --- a/src/main/java/client/AbstractCharacterObject.java +++ b/src/main/java/client/AbstractCharacterObject.java @@ -39,7 +39,7 @@ public abstract class AbstractCharacterObject extends AbstractAnimatedMapObject protected MapleMap map; protected int str, dex, luk, int_, hp, maxhp, mp, maxmp; protected int hpMpApUsed, remainingAp; - protected int[] remainingSp = new int[10]; + protected int[] remainingSp = new int[10]; // TODO: change to a simple int. Evan is not in v83, so why support it? protected transient int clientmaxhp, clientmaxmp, localmaxhp = 50, localmaxmp = 5; protected float transienthp = Float.NEGATIVE_INFINITY, transientmp = Float.NEGATIVE_INFINITY; diff --git a/src/main/java/client/BuddyList.java b/src/main/java/client/BuddyList.java index 6d2bdb974ad..c38ac540bca 100644 --- a/src/main/java/client/BuddyList.java +++ b/src/main/java/client/BuddyList.java @@ -21,6 +21,7 @@ */ package client; +import model.CharacterIdentity; import net.packet.Packet; import net.server.PlayerStorage; import tools.DatabaseConnection; @@ -48,7 +49,7 @@ public enum BuddyAddResult { private final Map buddies = new LinkedHashMap<>(); private int capacity; - private final Deque pendingRequests = new LinkedList<>(); + private final Deque pendingRequests = new LinkedList<>(); public BuddyList(int capacity) { this.capacity = capacity; @@ -150,7 +151,7 @@ public void loadFromDb(int characterId) { try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { if (rs.getInt("pending") == 1) { - pendingRequests.push(new CharacterNameAndId(rs.getInt("buddyid"), rs.getString("buddyname"))); + pendingRequests.push(new CharacterIdentity(rs.getString("buddyname"), rs.getInt("buddyid"))); } else { put(new BuddylistEntry(rs.getString("buddyname"), rs.getString("group"), rs.getInt("buddyid"), (byte) -1, true)); } @@ -167,7 +168,7 @@ public void loadFromDb(int characterId) { } } - public CharacterNameAndId pollPendingRequest() { + public CharacterIdentity pollPendingRequest() { return pendingRequests.pollLast(); } @@ -176,7 +177,7 @@ public void addBuddyRequest(Client c, int cidFrom, String nameFrom, int channelF if (pendingRequests.isEmpty()) { c.sendPacket(PacketCreator.requestBuddylistAdd(cidFrom, c.getPlayer().getId(), nameFrom)); } else { - pendingRequests.push(new CharacterNameAndId(cidFrom, nameFrom)); + pendingRequests.push(new CharacterIdentity(nameFrom, cidFrom)); } } } diff --git a/src/main/java/client/Character.java b/src/main/java/client/Character.java index f4923b01a3f..4107f00fe60 100644 --- a/src/main/java/client/Character.java +++ b/src/main/java/client/Character.java @@ -77,6 +77,8 @@ import constants.skills.Sniper; import constants.skills.ThunderBreaker; import constants.skills.Warrior; +import model.CharacterIdentity; +import net.netty.GameViolationException; import net.packet.Packet; import net.server.PlayerBuffValueHolder; import net.server.PlayerCoolDownValueHolder; @@ -86,8 +88,6 @@ import net.server.guild.Guild; import net.server.guild.GuildCharacter; import net.server.guild.GuildPackets; -import net.server.services.task.world.CharacterSaveService; -import net.server.services.type.WorldServices; import net.server.world.Messenger; import net.server.world.MessengerCharacter; import net.server.world.Party; @@ -105,7 +105,6 @@ import server.ItemInformationProvider; import server.ItemInformationProvider.ScriptedItem; import server.Marriage; -import server.Shop; import server.StatEffect; import server.Storage; import server.ThreadManager; @@ -118,7 +117,6 @@ import server.life.BanishInfo; import server.life.MobSkill; import server.life.MobSkillFactory; -import server.life.MobSkillId; import server.life.MobSkillType; import server.life.Monster; import server.life.PlayerNPC; @@ -148,6 +146,7 @@ import server.partyquest.MonsterCarnivalParty; import server.partyquest.PartyQuest; import server.quest.Quest; +import server.shop.Shop; import tools.DatabaseConnection; import tools.LongTool; import tools.PacketCreator; @@ -166,7 +165,6 @@ import java.time.LocalDateTime; import java.util.ArrayList; import java.util.Arrays; -import java.util.Calendar; import java.util.Collection; import java.util.Collections; import java.util.Comparator; @@ -189,7 +187,6 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; -import static java.util.concurrent.TimeUnit.DAYS; import static java.util.concurrent.TimeUnit.MINUTES; import static java.util.concurrent.TimeUnit.SECONDS; @@ -204,7 +201,7 @@ public class Character extends AbstractCharacterObject { private int accountid, id, level; private int rank, rankMove, jobRank, jobRankMove; private int gender, hair, face; - private int fame, quest_fame; + private int fame; private int initialSpawnPoint; private int mapid; private int currentPage, currentType = 0, currentTab = 1; @@ -236,7 +233,7 @@ public class Character extends AbstractCharacterObject { private int linkedLevel = 0; private String linkedName = null; private boolean finishedDojoTutorial; - private boolean usedStorage = false; + private volatile boolean usedStorage = false; // TODO: fully move this into Storage where usage can be fully controlled. private String name; private String chalktext; private String commandtext; @@ -325,7 +322,7 @@ public class Character extends AbstractCharacterObject { private final List blockedPortals = new ArrayList<>(); private final Map area_info = new LinkedHashMap<>(); private AutobanManager autoban; - private boolean isbanned = false; + private volatile boolean isBanned = false; private boolean blockCashShop = false; private boolean allowExpGain = true; private byte pendantExp = 0, lastmobcount = 0, doorSlot = -1; @@ -582,10 +579,6 @@ public boolean hasDisabledPartySearchInvite(int fromLeaderid) { return disabledPartySearchInvites.contains(fromLeaderid); } - public void setSessionTransitionState() { - client.setCharacterOnSessionTransitionState(this.getId()); - } - public boolean getCS() { return useCS; } @@ -738,57 +731,6 @@ public void addVisibleMapObject(MapObject mo) { visibleMapObjects.add(mo); } - public void ban(String reason) { - this.isbanned = true; - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("UPDATE accounts SET banned = 1, banreason = ? WHERE id = ?")) { - ps.setString(1, reason); - ps.setInt(2, accountid); - ps.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public static boolean ban(String id, String reason, boolean accountId) { - try (Connection con = DatabaseConnection.getConnection()) { - if (id.matches("/[0-9]{1,3}\\..*")) { - try (PreparedStatement ps = con.prepareStatement("INSERT INTO ipbans VALUES (DEFAULT, ?)")) { - ps.setString(1, id); - ps.executeUpdate(); - return true; - } - } - - final String query; - if (accountId) { - query = "SELECT id FROM accounts WHERE name = ?"; - } else { - query = "SELECT accountid FROM characters WHERE name = ?"; - } - - boolean ret = false; - try (PreparedStatement ps = con.prepareStatement(query)) { - ps.setString(1, id); - - try (ResultSet rs = ps.executeQuery()) { - if (rs.next()) { - try (PreparedStatement ps2 = con.prepareStatement("UPDATE accounts SET banned = 1, banreason = ? WHERE id = ?")) { - ps2.setString(1, reason); - ps2.setInt(2, rs.getInt(1)); - ps2.executeUpdate(); - } - ret = true; - } - } - } - return ret; - } catch (SQLException ex) { - ex.printStackTrace(); - } - return false; - } - public int calculateMaxBaseDamage(int watk, WeaponType weapon) { int mainstat, secondarystat; if (getJob().isA(Job.THIEF) && weapon == WeaponType.DAGGER_OTHER) { @@ -1311,6 +1253,10 @@ public void changeQuickslotKeybinding(byte[] aQuickslotKeyMapped) { this.m_pQuickslotKeyMapped = new QuickslotBinding(aQuickslotKeyMapped); } + public QuickslotBinding getQuickslotBinding() { + return this.m_pQuickslotKeyMapped; + } + public void broadcastStance(int newStance) { setStance(newStance); broadcastStance(); @@ -1441,6 +1387,7 @@ public void changeMap(final MapleMap target, Portal pto) { eventAfterChangedMap(this.getMapId()); } + // Only used when entering Magic Door (Priest skill). public void changeMap(final MapleMap target, final Point pos) { canWarpCounter++; @@ -1753,32 +1700,31 @@ private void changeMapInternal(final MapleMap to, final Point pos, Packet warpPa sendPacket(warpPacket); map.removePlayer(this); - if (client.getChannelServer().getPlayerStorage().getCharacterById(getId()) != null) { - map = to; - setPosition(pos); - map.addPlayer(this); - visitMap(map); - - prtLock.lock(); - try { - if (party != null) { - mpc.setMapId(to.getId()); - sendPacket(PacketCreator.updateParty(client.getChannel(), party, PartyOperation.SILENT_UPDATE, null)); - updatePartyMemberHPInternal(); - } - } finally { - prtLock.unlock(); - } - if (Character.this.getParty() != null) { - Character.this.getParty().setEnemy(k); - } - silentPartyUpdateInternal(getParty()); // EIM script calls inside - } else { + if (client.getChannelServer().getPlayerStorage().getCharacterById(id) == null) { log.warn("Chr {} got stuck when moving to map {}", getName(), map.getId()); - client.disconnect(true, false); // thanks BHB for noticing a player storage stuck case here return; } + map = to; + setPosition(pos); + map.addPlayer(this); + visitMap(map); + + prtLock.lock(); + try { + if (party != null) { + mpc.setMapId(to.getId()); + sendPacket(PacketCreator.updateParty(client.getChannel(), party, PartyOperation.SILENT_UPDATE, null)); + updatePartyMemberHPInternal(); + } + } finally { + prtLock.unlock(); + } + if (Character.this.getParty() != null) { + Character.this.getParty().setEnemy(k); + } + silentPartyUpdateInternal(getParty()); // EIM script calls inside + notifyMapTransferToPartner(map.getId()); //alas, new map has been specified when a warping was being processed... @@ -1961,8 +1907,8 @@ public boolean applyConsumeOnPickup(final int itemId) { ii.getItemEffect(itemId).applyTo(this); } - if (itemId / 10000 == 238) { - this.getMonsterBook().addCard(client, itemId); + if (ItemId.isMonsterCard(itemId)) { + monsterbook.addCard(itemId, client); } return true; } @@ -2177,9 +2123,9 @@ public void deleteGuild(int guildId) { } private void nextPendingRequest(Client c) { - CharacterNameAndId pendingBuddyRequest = c.getPlayer().getBuddylist().pollPendingRequest(); + CharacterIdentity pendingBuddyRequest = c.getPlayer().getBuddylist().pollPendingRequest(); if (pendingBuddyRequest != null) { - c.sendPacket(PacketCreator.requestBuddylistAdd(pendingBuddyRequest.getId(), c.getPlayer().getId(), pendingBuddyRequest.getName())); + c.sendPacket(PacketCreator.requestBuddylistAdd(pendingBuddyRequest.id(), c.getPlayer().getId(), pendingBuddyRequest.name())); } } @@ -4686,7 +4632,7 @@ public AbstractPlayerInteraction getAbstractPlayerInteraction() { return client.getAbstractPlayerInteraction(); } - private List getQuests() { + public List getQuests() { synchronized (quests) { return new ArrayList<>(quests.values()); } @@ -5050,6 +4996,14 @@ public void setUsedStorage() { usedStorage = true; } + public void resetUsedStorage() { + usedStorage = false; + } + + public boolean usedStorage() { + return usedStorage; + } + public List getFriendshipRings() { Collections.sort(friendshipRings); return friendshipRings; @@ -5224,7 +5178,7 @@ public int getJobType() { } public Map getKeymap() { - return keymap; + return Collections.unmodifiableMap(keymap); } public long getLastHealed() { @@ -5832,6 +5786,10 @@ public int getRankMove() { return rankMove; } + public SavedLocation[] getSavedLocations() { + return Arrays.copyOf(savedLocations, savedLocations.length); + } + public void clearSavedLocation(SavedLocationType type) { savedLocations[type.ordinal()] = null; } @@ -6438,15 +6396,6 @@ public void run() { } if (level % 20 == 0) { - if (YamlConfig.config.server.USE_ADD_SLOTS_BY_LEVEL == true) { - if (!isGM()) { - for (byte i = 1; i < 5; i++) { - gainSlots(i, 4, true); - } - - this.yellowMessage("You reached level " + level + ". Congratulations! As a token of your success, your inventory has been expanded a little bit."); - } - } if (YamlConfig.config.server.USE_ADD_RATES_BY_LEVEL == true) { //For the rate upgrade revertLastPlayerRates(); setPlayerRates(); @@ -6732,7 +6681,7 @@ public void addPlayerRing(Ring ring) { } } - public static Character loadCharacterEntryFromDB(ResultSet rs, List equipped) { + public static Character loadCharacterViewFromDB(ResultSet rs, List equipped) { Character ret = new Character(); try { @@ -6783,7 +6732,7 @@ public static Character loadCharacterEntryFromDB(ResultSet rs, List equipp return ret; } - public Character generateCharacterEntry() { + public Character createCharacterView() { Character ret = new Character(); ret.accountid = this.getAccountID(); @@ -6843,10 +6792,16 @@ public void updateRemainingSp(int remainingSp) { updateRemainingSp(remainingSp, GameConstants.getSkillBook(job.getId())); } - public static Character loadCharFromDB(final int charid, Client client, boolean channelserver) throws SQLException { + @Deprecated + public static Character loadCharFromDB(int chrId, Client client, boolean channelServer) throws SQLException { + return loadCharFromDB(chrId, client, channelServer, new MonsterBook(Collections.emptyList())); + } + + public static Character loadCharFromDB(final int chrId, Client client, boolean channelServer, + MonsterBook monsterBook) throws SQLException { Character ret = new Character(); ret.client = client; - ret.id = charid; + ret.id = chrId; try (Connection con = DatabaseConnection.getConnection()) { final int mountexp; @@ -6856,7 +6811,7 @@ public static Character loadCharFromDB(final int charid, Client client, boolean // Character info try (PreparedStatement ps = con.prepareStatement("SELECT * FROM characters WHERE id = ?")) { - ps.setInt(1, charid); + ps.setInt(1, chrId); try (ResultSet rs = ps.executeQuery()) { if (!rs.next()) { @@ -6866,7 +6821,6 @@ public static Character loadCharFromDB(final int charid, Client client, boolean ret.name = rs.getString("name"); ret.level = rs.getInt("level"); ret.fame = rs.getInt("fame"); - ret.quest_fame = rs.getInt("fquest"); ret.str = rs.getInt("str"); ret.dex = rs.getInt("dex"); ret.int_ = rs.getInt("int"); @@ -6914,8 +6868,7 @@ public static Character loadCharFromDB(final int charid, Client client, boolean ret.allianceRank = rs.getInt("allianceRank"); ret.familyId = rs.getInt("familyId"); ret.bookCover = rs.getInt("monsterbookcover"); - ret.monsterbook = new MonsterBook(); - ret.monsterbook.loadCards(charid); + ret.monsterbook = monsterBook; ret.vanquisherStage = rs.getInt("vanquisherStage"); ret.ariantPoints = rs.getInt("ariantPoints"); ret.dojoPoints = rs.getInt("dojoPoints"); @@ -6935,7 +6888,7 @@ public static Character loadCharFromDB(final int charid, Client client, boolean ret.getInventory(InventoryType.ETC).setSlotLimit(rs.getByte("etcslots")); short sandboxCheck = 0x0; - for (Pair item : ItemFactory.INVENTORY.loadItems(ret.id, !channelserver)) { + for (Pair item : ItemFactory.INVENTORY.loadItems(ret.id, !channelServer)) { sandboxCheck |= item.getLeft().getFlag(); ret.getInventory(item.getRight()).addItemFromDB(item.getLeft()); @@ -6982,7 +6935,7 @@ public static Character loadCharFromDB(final int charid, Client client, boolean // Items excluded from pet loot try (PreparedStatement psPet = con.prepareStatement("SELECT petid FROM inventoryitems WHERE characterid = ? AND petid > -1")) { - psPet.setInt(1, charid); + psPet.setInt(1, chrId); try (ResultSet rsPet = psPet.executeQuery()) { while (rsPet.next()) { @@ -7005,7 +6958,7 @@ public static Character loadCharFromDB(final int charid, Client client, boolean ret.commitExcludedItems(); - if (channelserver) { + if (channelServer) { MapManager mapManager = client.getChannelServer().getMapFactory(); ret.map = mapManager.getMap(ret.mapid); @@ -7043,7 +6996,7 @@ public static Character loadCharFromDB(final int charid, Client client, boolean // Teleport rocks try (PreparedStatement ps = con.prepareStatement("SELECT mapid,vip FROM trocklocations WHERE characterid = ? LIMIT 15")) { - ps.setInt(1, charid); + ps.setInt(1, chrId); try (ResultSet rs = ps.executeQuery()) { byte vip = 0; @@ -7078,7 +7031,6 @@ public static Character loadCharFromDB(final int charid, Client client, boolean retClient.setAccountName(rs.getString("name")); retClient.setCharacterSlots(rs.getByte("characterslots")); - retClient.setLanguage(rs.getInt("language")); // thanks Zein for noticing user language not overriding default once player is in-game } } } @@ -7114,7 +7066,7 @@ public static Character loadCharFromDB(final int charid, Client client, boolean // Blessing of the Fairy try (PreparedStatement ps = con.prepareStatement("SELECT name, level FROM characters WHERE accountid = ? AND id != ? ORDER BY level DESC limit 1")) { ps.setInt(1, ret.accountid); - ps.setInt(2, charid); + ps.setInt(2, chrId); try (ResultSet rs = ps.executeQuery()) { if (rs.next()) { @@ -7124,12 +7076,12 @@ public static Character loadCharFromDB(final int charid, Client client, boolean } } - if (channelserver) { + if (channelServer) { final Map loadedQuestStatus = new LinkedHashMap<>(); // Quest status try (PreparedStatement ps = con.prepareStatement("SELECT * FROM queststatus WHERE characterid = ?")) { - ps.setInt(1, charid); + ps.setInt(1, chrId); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { @@ -7156,7 +7108,7 @@ public static Character loadCharFromDB(final int charid, Client client, boolean // Quest progress // opportunity for improvement on questprogress/medalmaps calls to DB try (PreparedStatement ps = con.prepareStatement("SELECT * FROM questprogress WHERE characterid = ?")) { - ps.setInt(1, charid); + ps.setInt(1, chrId); try (ResultSet rsProgress = ps.executeQuery()) { while (rsProgress.next()) { QuestStatus status = loadedQuestStatus.get(rsProgress.getInt("queststatusid")); @@ -7169,7 +7121,7 @@ public static Character loadCharFromDB(final int charid, Client client, boolean // Medal map visit progress try (PreparedStatement ps = con.prepareStatement("SELECT * FROM medalmaps WHERE characterid = ?")) { - ps.setInt(1, charid); + ps.setInt(1, chrId); try (ResultSet rsMedalMaps = ps.executeQuery()) { while (rsMedalMaps.next()) { QuestStatus status = loadedQuestStatus.get(rsMedalMaps.getInt("queststatusid")); @@ -7184,7 +7136,7 @@ public static Character loadCharFromDB(final int charid, Client client, boolean // Skills try (PreparedStatement ps = con.prepareStatement("SELECT skillid,skilllevel,masterlevel,expiration FROM skills WHERE characterid = ?")) { - ps.setInt(1, charid); + ps.setInt(1, chrId); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { @@ -7254,7 +7206,7 @@ public static Character loadCharFromDB(final int charid, Client client, boolean // Skill macros try (PreparedStatement ps = con.prepareStatement("SELECT * FROM skillmacros WHERE characterid = ?")) { - ps.setInt(1, charid); + ps.setInt(1, chrId); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { @@ -7267,7 +7219,7 @@ public static Character loadCharFromDB(final int charid, Client client, boolean // Key config try (PreparedStatement ps = con.prepareStatement("SELECT `key`,`type`,`action` FROM keymap WHERE characterid = ?")) { - ps.setInt(1, charid); + ps.setInt(1, chrId); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { @@ -7281,7 +7233,7 @@ public static Character loadCharFromDB(final int charid, Client client, boolean // Saved locations try (PreparedStatement ps = con.prepareStatement("SELECT `locationtype`,`map`,`portal` FROM savedlocations WHERE characterid = ?")) { - ps.setInt(1, charid); + ps.setInt(1, chrId); try (ResultSet rs = ps.executeQuery()) { while (rs.next()) { @@ -7292,7 +7244,7 @@ public static Character loadCharFromDB(final int charid, Client client, boolean // Fame history try (PreparedStatement ps = con.prepareStatement("SELECT `characterid_to`,`when` FROM famelog WHERE characterid = ? AND DATEDIFF(NOW(),`when`) < 30")) { - ps.setInt(1, charid); + ps.setInt(1, chrId); try (ResultSet rs = ps.executeQuery()) { ret.lastfametime = 0; @@ -7304,7 +7256,7 @@ public static Character loadCharFromDB(final int charid, Client client, boolean } } - ret.buddylist.loadFromDb(charid); + ret.buddylist.loadFromDb(chrId); ret.storage = wserv.getAccountStorage(ret.accountid); /* Double-check storage incase player is first time on server @@ -7985,53 +7937,6 @@ public void resetEnteredScript(String script) { } } - public synchronized void saveCooldowns() { - List listcd = getAllCooldowns(); - - if (!listcd.isEmpty()) { - try (Connection con = DatabaseConnection.getConnection()) { - deleteWhereCharacterId(con, "DELETE FROM cooldowns WHERE charid = ?"); - try (PreparedStatement ps = con.prepareStatement("INSERT INTO cooldowns (charid, SkillID, StartTime, length) VALUES (?, ?, ?, ?)")) { - ps.setInt(1, getId()); - for (PlayerCoolDownValueHolder cooling : listcd) { - ps.setInt(2, cooling.skillId); - ps.setLong(3, cooling.startTime); - ps.setLong(4, cooling.length); - ps.addBatch(); - } - ps.executeBatch(); - } - } catch (SQLException se) { - se.printStackTrace(); - } - } - - Map> listds = getAllDiseases(); - if (!listds.isEmpty()) { - try (Connection con = DatabaseConnection.getConnection()) { - deleteWhereCharacterId(con, "DELETE FROM playerdiseases WHERE charid = ?"); - try (PreparedStatement ps = con.prepareStatement("INSERT INTO playerdiseases (charid, disease, mobskillid, mobskilllv, length) VALUES (?, ?, ?, ?, ?)")) { - ps.setInt(1, getId()); - - for (Entry> e : listds.entrySet()) { - ps.setInt(2, e.getKey().ordinal()); - - MobSkill ms = e.getValue().getRight(); - MobSkillId msId = ms.getId(); - ps.setInt(3, msId.type().getId()); - ps.setInt(4, msId.level()); - ps.setInt(5, e.getValue().getLeft().intValue()); - ps.addBatch(); - } - - ps.executeBatch(); - } - } catch (SQLException se) { - se.printStackTrace(); - } - } - } - public void saveGuildStatus() { try (Connection con = DatabaseConnection.getConnection(); PreparedStatement ps = con.prepareStatement("UPDATE characters SET guildid = ?, guildrank = ?, allianceRank = ? WHERE id = ?")) { @@ -8224,471 +8129,135 @@ public final boolean insertNewChar(CharacterFactoryRecipe recipe) { return false; } - public void saveCharToDB() { - if (YamlConfig.config.server.USE_AUTOSAVE) { - Runnable r = new Runnable() { - @Override - public void run() { - saveCharToDB(true); - } - }; - - CharacterSaveService service = (CharacterSaveService) getWorldServer().getServiceAccess(WorldServices.SAVE_CHARACTER); - service.registerSaveCharacter(this.getId(), r); - } else { - saveCharToDB(true); + public CharacterStats getCharacterStats() { + CharacterStats.CharacterStatsBuilder builder = CharacterStats.builder() + .id(id) + .level(level) + .fame(fame) + .gmLevel(gmLevel) + .skin(skinColor.getId()) + .gender(gender) + .job(job.getId()) + .hair(hair) + .face(face) + .meso(meso.get()) + .hpMpApUsed(hpMpApUsed) + .mapId(getSaveMap()) + .spawnPortal(getSaveSpawnPortal()) + .buddyCapacity(buddylist.getCapacity()) + .monsterBookCover(bookCover) + .dojoVanquisherStage(vanquisherStage) + .dojoPoints(dojoPoints) + .dojoStage(dojoStage) + .dojoTutorialComplete(finishedDojoTutorial) + .dojoVanquisherKills(vanquisherKills) + .matchCardWins(matchcardwins) + .matchCardLosses(matchcardlosses) + .matchCardTies(matchcardties) + .omokWins(omokwins) + .omokLosses(omoklosses) + .omokTies(omokties) + .dataString(dataString) + .jailExpiration(jailExpiration) + .lastExpGainTime(lastExpGainTime) + .ariantPoints(ariantPoints) + .canRecvPartySearchInvite(canRecvPartySearchInvite) + .equipSlots(getSlots(InventoryType.EQUIP.getType())) + .useSlots(getSlots(InventoryType.USE.getType())) + .setupSlots(getSlots(InventoryType.SETUP.getType())) + .etcSlots(getSlots(InventoryType.ETC.getType())); + + Party party = getParty(); + if (party != null) { + builder.party(party.getId()); } - } - //ItemFactory saveItems and monsterbook.saveCards are the most time consuming here. - public synchronized void saveCharToDB(boolean notAutosave) { - if (!loggedIn) { - return; + if (partnerId > 0) { + builder.partnerId(partnerId); } - Calendar c = Calendar.getInstance(); - log.debug("Attempting to {} chr {}", notAutosave ? "save" : "autosave", name); - - Server.getInstance().updateCharacterEntry(this); - - try (Connection con = DatabaseConnection.getConnection()) { - con.setAutoCommit(false); - con.setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED); - - try { - try (PreparedStatement ps = con.prepareStatement("UPDATE characters SET level = ?, fame = ?, str = ?, dex = ?, luk = ?, `int` = ?, exp = ?, gachaexp = ?, hp = ?, mp = ?, maxhp = ?, maxmp = ?, sp = ?, ap = ?, gm = ?, skincolor = ?, gender = ?, job = ?, hair = ?, face = ?, map = ?, meso = ?, hpMpUsed = ?, spawnpoint = ?, party = ?, buddyCapacity = ?, messengerid = ?, messengerposition = ?, mountlevel = ?, mountexp = ?, mounttiredness= ?, equipslots = ?, useslots = ?, setupslots = ?, etcslots = ?, monsterbookcover = ?, vanquisherStage = ?, dojoPoints = ?, lastDojoStage = ?, finishedDojoTutorial = ?, vanquisherKills = ?, matchcardwins = ?, matchcardlosses = ?, matchcardties = ?, omokwins = ?, omoklosses = ?, omokties = ?, dataString = ?, fquest = ?, jailexpire = ?, partnerId = ?, marriageItemId = ?, lastExpGainTime = ?, ariantPoints = ?, partySearch = ? WHERE id = ?", Statement.RETURN_GENERATED_KEYS)) { - ps.setInt(1, level); // thanks CanIGetaPR for noticing an unnecessary "level" limitation when persisting DB data - ps.setInt(2, fame); - - effLock.lock(); - statWlock.lock(); - try { - ps.setInt(3, str); - ps.setInt(4, dex); - ps.setInt(5, luk); - ps.setInt(6, int_); - ps.setInt(7, Math.abs(exp.get())); - ps.setInt(8, Math.abs(gachaexp.get())); - ps.setInt(9, hp); - ps.setInt(10, mp); - ps.setInt(11, maxhp); - ps.setInt(12, maxmp); - - StringBuilder sps = new StringBuilder(); - for (int j : remainingSp) { - sps.append(j); - sps.append(","); - } - String sp = sps.toString(); - ps.setString(13, sp.substring(0, sp.length() - 1)); - - ps.setInt(14, remainingAp); - } finally { - statWlock.unlock(); - effLock.unlock(); - } - - ps.setInt(15, gmLevel); - ps.setInt(16, skinColor.getId()); - ps.setInt(17, gender); - ps.setInt(18, job.getId()); - ps.setInt(19, hair); - ps.setInt(20, face); - if (map == null || (cashshop != null && cashshop.isOpened())) { - ps.setInt(21, mapid); - } else { - if (map.getForcedReturnId() != MapId.NONE) { - ps.setInt(21, map.getForcedReturnId()); - } else { - ps.setInt(21, getHp() < 1 ? map.getReturnMapId() : map.getId()); - } - } - ps.setInt(22, meso.get()); - ps.setInt(23, hpMpApUsed); - if (map == null || map.getId() == MapId.CRIMSONWOOD_VALLEY_1 || map.getId() == MapId.CRIMSONWOOD_VALLEY_2) { // reset to first spawnpoint on those maps - ps.setInt(24, 0); - } else { - Portal closest = map.findClosestPlayerSpawnpoint(getPosition()); - if (closest != null) { - ps.setInt(24, closest.getId()); - } else { - ps.setInt(24, 0); - } - } - - prtLock.lock(); - try { - if (party != null) { - ps.setInt(25, party.getId()); - } else { - ps.setInt(25, -1); - } - } finally { - prtLock.unlock(); - } - - ps.setInt(26, buddylist.getCapacity()); - if (messenger != null) { - ps.setInt(27, messenger.getId()); - ps.setInt(28, messengerposition); - } else { - ps.setInt(27, 0); - ps.setInt(28, 4); - } - if (maplemount != null) { - ps.setInt(29, maplemount.getLevel()); - ps.setInt(30, maplemount.getExp()); - ps.setInt(31, maplemount.getTiredness()); - } else { - ps.setInt(29, 1); - ps.setInt(30, 0); - ps.setInt(31, 0); - } - for (int i = 1; i < 5; i++) { - ps.setInt(i + 31, getSlots(i)); - } - - monsterbook.saveCards(con, id); - - ps.setInt(36, bookCover); - ps.setInt(37, vanquisherStage); - ps.setInt(38, dojoPoints); - ps.setInt(39, dojoStage); - ps.setInt(40, finishedDojoTutorial ? 1 : 0); - ps.setInt(41, vanquisherKills); - ps.setInt(42, matchcardwins); - ps.setInt(43, matchcardlosses); - ps.setInt(44, matchcardties); - ps.setInt(45, omokwins); - ps.setInt(46, omoklosses); - ps.setInt(47, omokties); - ps.setString(48, dataString); - ps.setInt(49, quest_fame); - ps.setLong(50, jailExpiration); - ps.setInt(51, partnerId); - ps.setInt(52, marriageItemid); - ps.setTimestamp(53, new Timestamp(lastExpGainTime)); - ps.setInt(54, ariantPoints); - ps.setBoolean(55, canRecvPartySearchInvite); - ps.setInt(56, id); - - int updateRows = ps.executeUpdate(); - if (updateRows < 1) { - throw new RuntimeException("Character not in database (" + id + ")"); - } - } - - List petList = new LinkedList<>(); - petLock.lock(); - try { - for (int i = 0; i < 3; i++) { - if (pets[i] != null) { - petList.add(pets[i]); - } - } - } finally { - petLock.unlock(); - } - - for (Pet pet : petList) { - pet.saveToDb(); - } - - for (Entry> es : getExcluded().entrySet()) { // this set is already protected - try (PreparedStatement psIgnore = con.prepareStatement("DELETE FROM petignores WHERE petid=?")) { - psIgnore.setInt(1, es.getKey()); - psIgnore.executeUpdate(); - } - - try (PreparedStatement psIgnore = con.prepareStatement("INSERT INTO petignores (petid, itemid) VALUES (?, ?)")) { - psIgnore.setInt(1, es.getKey()); - for (Integer x : es.getValue()) { - psIgnore.setInt(2, x); - psIgnore.addBatch(); - } - psIgnore.executeBatch(); - } - } - - // Key config - deleteWhereCharacterId(con, "DELETE FROM keymap WHERE characterid = ?"); - try (PreparedStatement psKey = con.prepareStatement("INSERT INTO keymap (characterid, `key`, `type`, `action`) VALUES (?, ?, ?, ?)")) { - psKey.setInt(1, id); - - Set> keybindingItems = Collections.unmodifiableSet(keymap.entrySet()); - for (Entry keybinding : keybindingItems) { - psKey.setInt(2, keybinding.getKey()); - psKey.setInt(3, keybinding.getValue().getType()); - psKey.setInt(4, keybinding.getValue().getAction()); - psKey.addBatch(); - } - psKey.executeBatch(); - } - - // No quickslots, or no change. - boolean bQuickslotEquals = this.m_pQuickslotKeyMapped == null || (this.m_aQuickslotLoaded != null && Arrays.equals(this.m_pQuickslotKeyMapped.GetKeybindings(), this.m_aQuickslotLoaded)); - if (!bQuickslotEquals) { - long nQuickslotKeymapped = LongTool.BytesToLong(this.m_pQuickslotKeyMapped.GetKeybindings()); - - try (final PreparedStatement psQuick = con.prepareStatement("INSERT INTO quickslotkeymapped (accountid, keymap) VALUES (?, ?) ON DUPLICATE KEY UPDATE keymap = ?;")) { - psQuick.setInt(1, this.getAccountID()); - psQuick.setLong(2, nQuickslotKeymapped); - psQuick.setLong(3, nQuickslotKeymapped); - psQuick.executeUpdate(); - } - } - - // Skill macros - deleteWhereCharacterId(con, "DELETE FROM skillmacros WHERE characterid = ?"); - try (PreparedStatement psMacro = con.prepareStatement("INSERT INTO skillmacros (characterid, skill1, skill2, skill3, name, shout, position) VALUES (?, ?, ?, ?, ?, ?, ?)")) { - psMacro.setInt(1, getId()); - for (int i = 0; i < 5; i++) { - SkillMacro macro = skillMacros[i]; - if (macro != null) { - psMacro.setInt(2, macro.getSkill1()); - psMacro.setInt(3, macro.getSkill2()); - psMacro.setInt(4, macro.getSkill3()); - psMacro.setString(5, macro.getName()); - psMacro.setInt(6, macro.getShout()); - psMacro.setInt(7, i); - psMacro.addBatch(); - } - } - psMacro.executeBatch(); - } - - List> itemsWithType = new ArrayList<>(); - for (Inventory iv : inventory) { - for (Item item : iv.list()) { - itemsWithType.add(new Pair<>(item, iv.getType())); - } - } - - // Items - ItemFactory.INVENTORY.saveItems(itemsWithType, id, con); - - // Skills - try (PreparedStatement psSkill = con.prepareStatement("REPLACE INTO skills (characterid, skillid, skilllevel, masterlevel, expiration) VALUES (?, ?, ?, ?, ?)")) { - psSkill.setInt(1, id); - for (Entry skill : skills.entrySet()) { - psSkill.setInt(2, skill.getKey().getId()); - psSkill.setInt(3, skill.getValue().skillevel); - psSkill.setInt(4, skill.getValue().masterlevel); - psSkill.setLong(5, skill.getValue().expiration); - psSkill.addBatch(); - } - psSkill.executeBatch(); - } - - // Saved locations - deleteWhereCharacterId(con, "DELETE FROM savedlocations WHERE characterid = ?"); - try (PreparedStatement psLoc = con.prepareStatement("INSERT INTO savedlocations (characterid, `locationtype`, `map`, `portal`) VALUES (?, ?, ?, ?)")) { - psLoc.setInt(1, id); - for (SavedLocationType savedLocationType : SavedLocationType.values()) { - if (savedLocations[savedLocationType.ordinal()] != null) { - psLoc.setString(2, savedLocationType.name()); - psLoc.setInt(3, savedLocations[savedLocationType.ordinal()].getMapId()); - psLoc.setInt(4, savedLocations[savedLocationType.ordinal()].getPortal()); - psLoc.addBatch(); - } - } - psLoc.executeBatch(); - } - - deleteWhereCharacterId(con, "DELETE FROM trocklocations WHERE characterid = ?"); - - // Vip teleport rocks - try (PreparedStatement psVip = con.prepareStatement("INSERT INTO trocklocations(characterid, mapid, vip) VALUES (?, ?, 0)")) { - for (int i = 0; i < getTrockSize(); i++) { - if (trockmaps.get(i) != MapId.NONE) { - psVip.setInt(1, getId()); - psVip.setInt(2, trockmaps.get(i)); - psVip.addBatch(); - } - } - psVip.executeBatch(); - } - - // Regular teleport rocks - try (PreparedStatement psReg = con.prepareStatement("INSERT INTO trocklocations(characterid, mapid, vip) VALUES (?, ?, 1)")) { - for (int i = 0; i < getVipTrockSize(); i++) { - if (viptrockmaps.get(i) != MapId.NONE) { - psReg.setInt(1, getId()); - psReg.setInt(2, viptrockmaps.get(i)); - psReg.addBatch(); - } - } - psReg.executeBatch(); - } - - // Buddy - deleteWhereCharacterId(con, "DELETE FROM buddies WHERE characterid = ? AND pending = 0"); - try (PreparedStatement psBuddy = con.prepareStatement("INSERT INTO buddies (characterid, `buddyid`, `pending`, `group`) VALUES (?, ?, 0, ?)")) { - psBuddy.setInt(1, id); - - for (BuddylistEntry entry : buddylist.getBuddies()) { - if (entry.isVisible()) { - psBuddy.setInt(2, entry.getCharacterId()); - psBuddy.setString(3, entry.getGroup()); - psBuddy.addBatch(); - } - } - psBuddy.executeBatch(); - } + if (marriageItemid > 0) { + builder.marriageItemId(marriageItemid); + } - // Area info - deleteWhereCharacterId(con, "DELETE FROM area_info WHERE charid = ?"); - try (PreparedStatement psArea = con.prepareStatement("INSERT INTO area_info (id, charid, area, info) VALUES (DEFAULT, ?, ?, ?)")) { - psArea.setInt(1, id); + effLock.lock(); + statWlock.lock(); + try { + builder.str(str) + .dex(dex) + .int_(int_) + .luk(luk) + .exp(Math.abs(exp.get())) + .gachaExp(Math.abs(gachaexp.get())) + .hp(hp) + .mp(mp) + .maxHp(maxhp) + .maxMp(maxmp) + .ap(remainingAp) + .sp(remainingSp[0]); + } finally { + statWlock.unlock(); + effLock.unlock(); + } - for (Entry area : area_info.entrySet()) { - psArea.setInt(2, area.getKey()); - psArea.setString(3, area.getValue()); - psArea.addBatch(); - } - psArea.executeBatch(); - } - // Event stats - deleteWhereCharacterId(con, "DELETE FROM eventstats WHERE characterid = ?"); - try (PreparedStatement psEvent = con.prepareStatement("INSERT INTO eventstats (characterid, name, info) VALUES (?, ?, ?)")) { - psEvent.setInt(1, id); + if (messenger != null) { + builder.messenger(messenger.getId()) + .messengerPosition(messengerposition); + } - for (Map.Entry entry : events.entrySet()) { - psEvent.setString(2, entry.getKey()); - psEvent.setInt(3, entry.getValue().getInfo()); - psEvent.addBatch(); - } + if (maplemount != null) { + builder.mountLevel(maplemount.getLevel()) + .mountExp(maplemount.getExp()) + .mountTiredness(maplemount.getTiredness()); + } - psEvent.executeBatch(); - } - - deleteQuestProgressWhereCharacterId(con, id); - - // Quests and medals - try (PreparedStatement psStatus = con.prepareStatement("INSERT INTO queststatus (`queststatusid`, `characterid`, `quest`, `status`, `time`, `expires`, `forfeited`, `completed`) VALUES (DEFAULT, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS); - PreparedStatement psProgress = con.prepareStatement("INSERT INTO questprogress VALUES (DEFAULT, ?, ?, ?, ?)"); - PreparedStatement psMedal = con.prepareStatement("INSERT INTO medalmaps VALUES (DEFAULT, ?, ?, ?)")) { - psStatus.setInt(1, id); - - for (QuestStatus qs : getQuests()) { - psStatus.setInt(2, qs.getQuest().getId()); - psStatus.setInt(3, qs.getStatus().getId()); - psStatus.setInt(4, (int) (qs.getCompletionTime() / 1000)); - psStatus.setLong(5, qs.getExpirationTime()); - psStatus.setInt(6, qs.getForfeited()); - psStatus.setInt(7, qs.getCompleted()); - psStatus.executeUpdate(); - - try (ResultSet rs = psStatus.getGeneratedKeys()) { - rs.next(); - for (int mob : qs.getProgress().keySet()) { - psProgress.setInt(1, id); - psProgress.setInt(2, rs.getInt(1)); - psProgress.setInt(3, mob); - psProgress.setString(4, qs.getProgress(mob)); - psProgress.addBatch(); - } - psProgress.executeBatch(); + return builder.build(); + } - for (int i = 0; i < qs.getMedalMaps().size(); i++) { - psMedal.setInt(1, id); - psMedal.setInt(2, rs.getInt(1)); - psMedal.setInt(3, qs.getMedalMaps().get(i)); - psMedal.addBatch(); - } - psMedal.executeBatch(); - } - } - } + private int getSaveMap() { + if (map == null || (cashshop != null && cashshop.isOpened())) { + return mapid; + } - FamilyEntry familyEntry = getFamilyEntry(); //save family rep - if (familyEntry != null) { - if (familyEntry.saveReputation(con)) { - familyEntry.savedSuccessfully(); - } - FamilyEntry senior = familyEntry.getSenior(); - if (senior != null && senior.getChr() == null) { //only save for offline family members - if (senior.saveReputation(con)) { - senior.savedSuccessfully(); - } - senior = senior.getSenior(); //save one level up as well - if (senior != null && senior.getChr() == null) { - if (senior.saveReputation(con)) { - senior.savedSuccessfully(); - } - } - } + if (map.getForcedReturnId() != MapId.NONE) { + return map.getForcedReturnId(); + } - } + if (getHp() < 1) { + return map.getReturnMapId(); + } - if (cashshop != null) { - cashshop.save(con); - } + return map.getId(); + } - if (storage != null && usedStorage) { - storage.saveToDB(con); - usedStorage = false; - } + private int getSaveSpawnPortal() { + if (map == null || map.getId() == MapId.CRIMSONWOOD_VALLEY_1 || map.getId() == MapId.CRIMSONWOOD_VALLEY_2) { // TODO: clean up. Shouldn't hardcode these maps. + return 0; + } - con.commit(); - } catch (Exception e) { - con.rollback(); - throw e; - } finally { - con.setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ); - con.setAutoCommit(true); - } - } catch (Exception e) { - log.error("Error saving chr {}, level: {}, job: {}", name, level, job.getId(), e); + Portal closest = map.findClosestPlayerSpawnpoint(getPosition()); + if (closest == null) { + return 0; } - } - public void sendPolice(int greason, String reason, int duration) { - sendPacket(PacketCreator.sendPolice(String.format("You have been blocked by the#b %s Police for %s.#k", "Cosmic", reason))); - this.isbanned = true; - TimerManager.getInstance().schedule(new Runnable() { - @Override - public void run() { - client.disconnect(false, false); - } - }, duration); + return closest.getId(); } public void sendPolice(String text) { final String message = getName() + " received this - " + text; + log.info(message); if (Server.getInstance().isGmOnline(this.getWorld())) { //Alert and log if a GM is online Server.getInstance().broadcastGMMessage(this.getWorld(), PacketCreator.sendYellowTip(message)); } else { //Auto DC and log if no GM is online - client.disconnect(false, false); + throw new GameViolationException(text); } - log.info(message); - //Server.getInstance().broadcastGMMessage(0, PacketCreator.serverNotice(1, getName() + " received this - " + text)); - //sendPacket(PacketCreator.sendPolice(text)); - //this.isbanned = true; - //TimerManager.getInstance().schedule(new Runnable() { - // @Override - // public void run() { - // client.disconnect(false, false); - // } - //}, 6000); } public void sendKeymap() { sendPacket(PacketCreator.getKeymap(keymap)); } - public void sendQuickmap() { - // send quickslots to user - QuickslotBinding pQuickslotKeyMapped = this.m_pQuickslotKeyMapped; - - if (pQuickslotKeyMapped == null) { - pQuickslotKeyMapped = new QuickslotBinding(QuickslotBinding.DEFAULT_QUICKSLOTS); - } - - this.sendPacket(PacketCreator.QuickslotMappedInit(pQuickslotKeyMapped)); - } - public void sendMacros() { // Always send the macro packet to fix a client side bug when switching characters. sendPacket(PacketCreator.getMacros(skillMacros)); @@ -9159,33 +8728,28 @@ public boolean canGainSlots(int type, int slots) { return slots <= 96; } - public boolean gainSlots(int type, int slots) { - return gainSlots(type, slots, true); - } - public boolean gainSlots(int type, int slots, boolean update) { - int newLimit = gainSlotsInternal(type, slots); - if (newLimit != -1) { - this.saveCharToDB(); - if (update) { - sendPacket(PacketCreator.updateInventorySlotLimit(type, newLimit)); - } - return true; - } else { + Integer updatedLimit = gainSlotsInternal(type, slots); + if (updatedLimit == null) { return false; } + + if (update) { + sendPacket(PacketCreator.updateInventorySlotLimit(type, updatedLimit)); + } + return true; } - private int gainSlotsInternal(int type, int slots) { + private Integer gainSlotsInternal(int type, int slots) { inventory[type].lockInventory(); try { - if (canGainSlots(type, slots)) { - int newLimit = inventory[type].getSlotLimit() + slots; - inventory[type].setSlotLimit(newLimit); - return newLimit; - } else { - return -1; + if (!canGainSlots(type, slots)) { + return null; } + + int newLimit = inventory[type].getSlotLimit() + slots; + inventory[type].setSlotLimit(newLimit); + return newLimit; } finally { inventory[type].unlockInventory(); } @@ -9448,24 +9012,6 @@ public void setQuestProgress(int id, int infoNumber, String progress) { } } - public void awardQuestPoint(int awardedPoints) { - if (YamlConfig.config.server.QUEST_POINT_REQUIREMENT < 1 || awardedPoints < 1) { - return; - } - - int delta; - synchronized (quests) { - quest_fame += awardedPoints; - - delta = quest_fame / YamlConfig.config.server.QUEST_POINT_REQUIREMENT; - quest_fame %= YamlConfig.config.server.QUEST_POINT_REQUIREMENT; - } - - if (delta > 0) { - gainFame(delta); - } - } - public enum DelayedQuestUpdate { // quest updates allow player actions during NPC talk... UPDATE, FORFEIT, COMPLETE, INFO } @@ -9531,9 +9077,6 @@ public void updateQuestStatus(QuestStatus qs) { } else if (qs.getStatus().equals(QuestStatus.Status.COMPLETED)) { Quest mquest = qs.getQuest(); short questid = mquest.getId(); - if (!mquest.isSameDayRepeatable() && !Quest.isExploitableQuest(questid)) { - awardQuestPoint(YamlConfig.config.server.QUEST_POINT_PER_QUEST_COMPLETE); - } qs.setCompleted(qs.getCompleted() + 1); // Jayd's idea - count quest completed announceUpdateQuest(DelayedQuestUpdate.COMPLETE, questid, qs.getCompletionTime()); @@ -9800,42 +9343,12 @@ public Map getAreaInfos() { return area_info; } - public void autoban(String reason) { - if (this.isGM() || this.isBanned()) { // thanks RedHat for noticing GM's being able to get banned - return; - } - - this.ban(reason); - sendPacket(PacketCreator.sendPolice(String.format("You have been blocked by the#b %s Police for HACK reason.#k", "Cosmic"))); - TimerManager.getInstance().schedule(new Runnable() { - @Override - public void run() { - client.disconnect(false, false); - } - }, 5000); - - Server.getInstance().broadcastGMMessage(this.getWorld(), PacketCreator.serverNotice(6, Character.makeMapleReadable(this.name) + " was autobanned for " + reason)); - } - - public void block(int reason, int days, String desc) { - Calendar cal = Calendar.getInstance(); - cal.add(Calendar.DATE, days); - final Timestamp TS = new Timestamp(cal.getTimeInMillis()); - - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("UPDATE accounts SET banreason = ?, tempban = ?, greason = ? WHERE id = ?")) { - ps.setString(1, desc); - ps.setTimestamp(2, TS); - ps.setInt(3, reason); - ps.setInt(4, accountid); - ps.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); - } + public boolean isBanned() { + return isBanned; } - public boolean isBanned() { - return isbanned; + public void setBanned() { + isBanned = true; } public List getTrockMaps() { @@ -10521,7 +10034,7 @@ public static boolean doNameChange(Connection con, int characterId, String oldNa public int checkWorldTransferEligibility() { if (getLevel() < 20) { return 2; - } else if (getClient().getTempBanCalendar() != null && getClient().getTempBanCalendar().getTimeInMillis() + (int) DAYS.toMillis(30) < Calendar.getInstance().getTimeInMillis()) { + } else if (client.wasRecentlyBanned()) { return 3; } else if (isMarried()) { return 4; @@ -10694,33 +10207,6 @@ public void setLastCommandMessage(String text) { this.commandtext = text; } - public int getRewardPoints() { - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("SELECT rewardpoints FROM accounts WHERE id=?;")) { - ps.setInt(1, accountid); - ResultSet resultSet = ps.executeQuery(); - int point = -1; - if (resultSet.next()) { - point = resultSet.getInt(1); - } - return point; - } catch (SQLException e) { - e.printStackTrace(); - } - return -1; - } - - public void setRewardPoints(int value) { - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("UPDATE accounts SET rewardpoints=? WHERE id=?;")) { - ps.setInt(1, value); - ps.setInt(2, accountid); - ps.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - //EVENTS private byte team = 0; private Fitness fitness; @@ -10881,23 +10367,6 @@ public int getAriantPoints() { return this.ariantPoints; } - public void setLanguage(int num) { - getClient().setLanguage(num); - - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("UPDATE accounts SET language = ? WHERE id = ?")) { - ps.setInt(1, num); - ps.setInt(2, getClient().getAccID()); - ps.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public int getLanguage() { - return getClient().getLanguage(); - } - public boolean isChasing() { return chasing; } diff --git a/src/main/java/client/CharacterStats.java b/src/main/java/client/CharacterStats.java new file mode 100644 index 00000000000..515a339f11e --- /dev/null +++ b/src/main/java/client/CharacterStats.java @@ -0,0 +1,66 @@ +package client; + +import lombok.Builder; + +@Builder +public record CharacterStats( + int account, + int world, + String name, + int id, + int level, + int fame, + int str, + int dex, + int luk, + int int_, + int exp, + int gachaExp, + int hp, + int mp, + int maxHp, + int maxMp, + int sp, + int ap, + int gmLevel, + int skin, + int gender, + int job, + int hair, + int face, + int mapId, + int meso, + int hpMpApUsed, + int spawnPortal, + Integer party, + int buddyCapacity, + Integer messenger, + Integer messengerPosition, + Integer mountLevel, + Integer mountExp, + Integer mountTiredness, + int equipSlots, + int useSlots, + int setupSlots, + int etcSlots, + Integer monsterBookCover, + Integer dojoVanquisherStage, + int dojoPoints, + Integer dojoStage, + boolean dojoTutorialComplete, + int dojoVanquisherKills, + int matchCardWins, + int matchCardLosses, + int matchCardTies, + int omokWins, + int omokLosses, + int omokTies, + String dataString, + Long jailExpiration, + Integer partnerId, + Integer marriageItemId, + Long lastExpGainTime, + int ariantPoints, + boolean canRecvPartySearchInvite +) { +} diff --git a/src/main/java/client/Client.java b/src/main/java/client/Client.java index 2e0c2f94fc1..980eeab21d7 100644 --- a/src/main/java/client/Client.java +++ b/src/main/java/client/Client.java @@ -21,15 +21,15 @@ */ package client; -import client.inventory.InventoryType; import config.YamlConfig; -import constants.game.GameConstants; -import constants.id.MapId; +import database.account.Account; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; import io.netty.handler.timeout.IdleStateEvent; import net.PacketHandler; import net.PacketProcessor; +import net.netty.DisconnectException; +import net.netty.GameViolationException; import net.netty.InvalidPacketHeaderException; import net.packet.InPacket; import net.packet.Packet; @@ -40,59 +40,33 @@ import net.server.coordinator.login.LoginBypassCoordinator; import net.server.coordinator.session.Hwid; import net.server.coordinator.session.SessionCoordinator; -import net.server.coordinator.session.SessionCoordinator.AntiMulticlientResult; -import net.server.guild.Guild; -import net.server.guild.GuildCharacter; -import net.server.guild.GuildPackets; -import net.server.world.MessengerCharacter; import net.server.world.Party; -import net.server.world.PartyCharacter; -import net.server.world.PartyOperation; import net.server.world.World; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import scripting.AbstractPlayerInteraction; -import scripting.event.EventInstanceManager; import scripting.event.EventManager; import scripting.npc.NPCConversationManager; import scripting.npc.NPCScriptManager; import scripting.quest.QuestActionManager; import scripting.quest.QuestScriptManager; -import server.MapleLeafLogger; -import server.ThreadManager; import server.TimerManager; import server.life.Monster; -import server.maps.FieldLimit; -import server.maps.MapleMap; -import server.maps.MiniDungeonInfo; -import tools.BCrypt; -import tools.DatabaseConnection; -import tools.HexTool; import tools.PacketCreator; import javax.script.ScriptEngine; -import java.io.IOException; -import java.net.InetAddress; import java.net.InetSocketAddress; -import java.nio.charset.StandardCharsets; -import java.security.MessageDigest; -import java.security.NoSuchAlgorithmException; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; import java.sql.SQLException; -import java.sql.Timestamp; -import java.util.ArrayList; +import java.time.Duration; +import java.time.Instant; +import java.time.LocalDate; import java.util.Arrays; import java.util.Calendar; import java.util.Collections; -import java.util.Date; import java.util.HashMap; import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import java.util.concurrent.Semaphore; import java.util.concurrent.locks.Lock; @@ -102,10 +76,8 @@ public class Client extends ChannelInboundHandlerAdapter { private static final Logger log = LoggerFactory.getLogger(Client.class); - - public static final int LOGIN_NOTLOGGEDIN = 0; - public static final int LOGIN_SERVER_TRANSITION = 1; - public static final int LOGIN_LOGGEDIN = 2; + private static final int MAX_FAILED_LOGIN_ATTEMPTS = 5; + private static final int MAX_CHR_SLOTS = 15; private final Type type; private final long sessionId; @@ -113,23 +85,23 @@ public class Client extends ChannelInboundHandlerAdapter { private Hwid hwid; private String remoteAddress; - private volatile boolean inTransition; private io.netty.channel.Channel ioChannel; + private Account account; private Character player; private int channel = 1; private int accId = -4; private boolean loggedIn = false; - private boolean serverTransition = false; - private Calendar birthday = null; + private boolean inServerTransition = false; + private LocalDate birthday = null; private String accountName = null; private int world; private volatile long lastPong; - private int gmlevel; + private int gmlevel; // TODO: remove? There's a gmlevel in Character too. private Set macs = new HashSet<>(); private Map engines = new HashMap<>(); private byte characterSlots = 3; - private byte loginattempt = 0; + private byte failedLoginAttempts = 0; private String pin = ""; private int pinattempt = 0; private String pic = ""; @@ -139,16 +111,10 @@ public class Client extends ChannelInboundHandlerAdapter { private boolean disconnecting = false; private final Semaphore actionsSemaphore = new Semaphore(7); private final Lock lock = new ReentrantLock(true); - private final Lock encoderLock = new ReentrantLock(true); private final Lock announcerLock = new ReentrantLock(true); // thanks Masterrulax & try2hack for pointing out a bottleneck issue with shared locks, shavit for noticing an opportunity for improvement - private Calendar tempBanCalendar; - private int votePoints; - private int voteTime = -1; - private int visibleWorlds; private long lastNpcClick; private long lastPacket = System.currentTimeMillis(); - private int lang = 0; public enum Type { LOGIN, @@ -219,6 +185,9 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception try { MonitoredChrLogger.logPacketIfMonitored(this, opcode, packet.getBytes()); handler.handlePacket(packet, this); + } catch (GameViolationException gve) { + log.warn("Game violation (disconnecting): {}", gve.getMessage()); + throw new DisconnectException(this, true); } catch (final Throwable t) { final String chrInfo = player != null ? player.getName() + " on map " + player.getMapId() : "?"; log.warn("Error in packet handler {}. Chr {}, account {}. Packet: {}", handler.getClass().getSimpleName(), @@ -238,33 +207,29 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object event) { } @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { if (player != null) { log.warn("Exception caught by {}", player, cause); } if (cause instanceof InvalidPacketHeaderException) { SessionCoordinator.getInstance().closeSession(this, true); - } else if (cause instanceof IOException) { - closeMapleSession(); + } else { + ctx.fireExceptionCaught(cause); } } @Override public void channelInactive(ChannelHandlerContext ctx) { - closeMapleSession(); - } - - private void closeMapleSession() { switch (type) { case LOGIN -> SessionCoordinator.getInstance().closeLoginSession(this); - case CHANNEL -> SessionCoordinator.getInstance().closeSession(this, null); + case CHANNEL -> SessionCoordinator.getInstance().closeSession(this, false); } try { // client freeze issues on session transition states found thanks to yolinlin, Omo Oppa, Nozphex - if (!inTransition) { - disconnect(false, false); + if (!inServerTransition) { + ctx.fireExceptionCaught(new DisconnectException(this, false)); } } catch (Throwable t) { log.warn("Account stuck", t); @@ -297,18 +262,39 @@ public void setHwid(Hwid hwid) { this.hwid = hwid; } - public String getRemoteAddress() { - return remoteAddress; + public void setMacs(String macs) { + if (macs == null || macs.isEmpty()) { + throw new IllegalArgumentException("macs cannot be empty"); + } + this.macs.addAll(Arrays.asList(macs.split(", "))); } - public boolean isInTransition() { - return inTransition; + public String getRemoteAddress() { + return remoteAddress; } public EventManager getEventManager(String event) { return getChannelServer().getEventSM().getEventManager(event); } + public Account getAccount() { + return account; + } + + public void setAccount(Account account) { + Objects.requireNonNull(account); + this.account = account; + this.accId = account.id(); + this.accountName = account.name(); + this.characterSlots = account.chrSlots(); + this.pin = account.pin(); + this.pic = account.pic(); + this.gender = Objects.requireNonNullElse(account.gender(), Gender.NOT_SET); + this.birthday = account.birthdate(); + loggedIn = account.loginState() == LoginState.LOGGED_IN; + inServerTransition = account.loginState() == LoginState.SERVER_TRANSITION; + } + public Character getPlayer() { return player; } @@ -321,267 +307,16 @@ public AbstractPlayerInteraction getAbstractPlayerInteraction() { return new AbstractPlayerInteraction(this); } - public void sendCharList(int server) { - this.sendPacket(PacketCreator.getCharList(this, server, 0)); - } - - public List loadCharacters(int serverId) { - List chars = new ArrayList<>(15); - try { - for (CharNameAndId cni : loadCharactersInternal(serverId)) { - chars.add(Character.loadCharFromDB(cni.id, this, false)); - } - } catch (Exception e) { - e.printStackTrace(); - } - return chars; - } - - public List loadCharacterNames(int worldId) { - List chars = new ArrayList<>(15); - for (CharNameAndId cni : loadCharactersInternal(worldId)) { - chars.add(cni.name); - } - return chars; - } - - private List loadCharactersInternal(int worldId) { - List chars = new ArrayList<>(15); - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("SELECT id, name FROM characters WHERE accountid = ? AND world = ?")) { - ps.setInt(1, this.getAccID()); - ps.setInt(2, worldId); - - try (ResultSet rs = ps.executeQuery()) { - while (rs.next()) { - chars.add(new CharNameAndId(rs.getString("name"), rs.getInt("id"))); - } - } - } catch (SQLException e) { - e.printStackTrace(); - } - return chars; - } - public boolean isLoggedIn() { return loggedIn; } - public boolean hasBannedIP() { - boolean ret = false; - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM ipbans WHERE ? LIKE CONCAT(ip, '%')")) { - ps.setString(1, remoteAddress); - try (ResultSet rs = ps.executeQuery()) { - rs.next(); - if (rs.getInt(1) > 0) { - ret = true; - } - } - } catch (SQLException e) { - e.printStackTrace(); - } - return ret; - } - - public int getVoteTime() { - if (voteTime != -1) { - return voteTime; - } - - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("SELECT date FROM bit_votingrecords WHERE UPPER(account) = UPPER(?)")) { - ps.setString(1, accountName); - try (ResultSet rs = ps.executeQuery()) { - if (!rs.next()) { - return -1; - } - voteTime = rs.getInt("date"); - } - } catch (SQLException e) { - log.error("Error getting voting time"); - return -1; - } - return voteTime; - } - - public void resetVoteTime() { - voteTime = -1; - } - - public boolean hasVotedAlready() { - Date currentDate = new Date(); - int timeNow = (int) (currentDate.getTime() / 1000); - int difference = (timeNow - getVoteTime()); - return difference < 86400 && difference > 0; - } - - public boolean hasBannedHWID() { - if (hwid == null) { - return false; - } - - boolean ret = false; - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM hwidbans WHERE hwid LIKE ?")) { - ps.setString(1, hwid.hwid()); - - try (ResultSet rs = ps.executeQuery()) { - if (rs != null && rs.next()) { - if (rs.getInt(1) > 0) { - ret = true; - } - } - } - } catch (SQLException e) { - e.printStackTrace(); - } - - return ret; - } - - public boolean hasBannedMac() { - if (macs.isEmpty()) { - return false; - } - boolean ret = false; - int i; - StringBuilder sql = new StringBuilder("SELECT COUNT(*) FROM macbans WHERE mac IN ("); - for (i = 0; i < macs.size(); i++) { - sql.append("?"); - if (i != macs.size() - 1) { - sql.append(", "); - } - } - sql.append(")"); - - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement(sql.toString())) { - i = 0; - for (String mac : macs) { - ps.setString(++i, mac); - } - try (ResultSet rs = ps.executeQuery()) { - rs.next(); - if (rs.getInt(1) > 0) { - ret = true; - } - } - } catch (Exception e) { - e.printStackTrace(); - } - - return ret; - } - - private void loadHWIDIfNescessary() throws SQLException { - if (hwid == null) { - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("SELECT hwid FROM accounts WHERE id = ?")) { - ps.setInt(1, accId); - - try (ResultSet rs = ps.executeQuery()) { - if (rs.next()) { - hwid = new Hwid(rs.getString("hwid")); - } - } - } - } - } - - // TODO: Recode to close statements... - private void loadMacsIfNescessary() throws SQLException { - if (macs.isEmpty()) { - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("SELECT macs FROM accounts WHERE id = ?")) { - ps.setInt(1, accId); - try (ResultSet rs = ps.executeQuery()) { - if (rs.next()) { - for (String mac : rs.getString("macs").split(", ")) { - if (!mac.equals("")) { - macs.add(mac); - } - } - } - } - } - } - } - - public void banHWID() { - try { - loadHWIDIfNescessary(); - - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("INSERT INTO hwidbans (hwid) VALUES (?)")) { - ps.setString(1, hwid.hwid()); - ps.executeUpdate(); - } - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public void banMacs() { - try { - loadMacsIfNescessary(); - - List filtered = new LinkedList<>(); - try (Connection con = DatabaseConnection.getConnection()) { - try (PreparedStatement ps = con.prepareStatement("SELECT filter FROM macfilters"); - ResultSet rs = ps.executeQuery()) { - while (rs.next()) { - filtered.add(rs.getString("filter")); - } - } - - try (PreparedStatement ps = con.prepareStatement("INSERT INTO macbans (mac, aid) VALUES (?, ?)")) { - for (String mac : macs) { - boolean matched = false; - for (String filter : filtered) { - if (mac.matches(filter)) { - matched = true; - break; - } - } - if (!matched) { - ps.setString(1, mac); - ps.setString(2, String.valueOf(getAccID())); - ps.executeUpdate(); - } - } - } - } - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public int finishLogin() { - encoderLock.lock(); - try { - if (getLoginState() > LOGIN_NOTLOGGEDIN) { // 0 = LOGIN_NOTLOGGEDIN, 1= LOGIN_SERVER_TRANSITION, 2 = LOGIN_LOGGEDIN - loggedIn = false; - return 7; - } - updateLoginState(Client.LOGIN_LOGGEDIN); - } finally { - encoderLock.unlock(); - } - - return 0; + public boolean isInTransition() { + return inServerTransition; } public void setPin(String pin) { this.pin = pin; - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("UPDATE accounts SET pin = ? WHERE id = ?")) { - ps.setString(1, pin); - ps.setInt(2, accId); - ps.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); - } } public String getPin() { @@ -593,8 +328,7 @@ public boolean checkPin(String other) { return true; } - pinattempt++; - if (pinattempt > 5) { + if (++pinattempt >= MAX_FAILED_LOGIN_ATTEMPTS) { SessionCoordinator.getInstance().closeSession(this, false); } if (pin.equals(other)) { @@ -607,14 +341,6 @@ public boolean checkPin(String other) { public void setPic(String pic) { this.pic = pic; - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("UPDATE accounts SET pic = ? WHERE id = ?")) { - ps.setString(1, pic); - ps.setInt(2, accId); - ps.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); - } } public String getPic() { @@ -626,8 +352,7 @@ public boolean checkPic(String other) { return true; } - picattempt++; - if (picattempt > 5) { + if (++picattempt >= MAX_FAILED_LOGIN_ATTEMPTS) { SessionCoordinator.getInstance().closeSession(this, false); } if (pic.equals(other)) { // thanks ryantpayton (HeavenClient) for noticing null pics being checked here @@ -638,177 +363,13 @@ public boolean checkPic(String other) { return false; } - public int login(String login, String pwd, Hwid hwid) { - int loginok = 5; - - loginattempt++; - if (loginattempt > 4) { - loggedIn = false; - SessionCoordinator.getInstance().closeSession(this, false); - return 6; // thanks Survival_Project for finding out an issue with AUTOMATIC_REGISTER here - } - - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("SELECT id, password, gender, banned, pin, pic, characterslots, tos, language FROM accounts WHERE name = ?")) { - ps.setString(1, login); - - try (ResultSet rs = ps.executeQuery()) { - accId = -2; - if (rs.next()) { - accId = rs.getInt("id"); - if (accId <= 0) { - log.warn("Tried to log in with accId {}", accId); - return 15; - } - - boolean banned = (rs.getByte("banned") == 1); - gmlevel = 0; - pin = rs.getString("pin"); - pic = rs.getString("pic"); - gender = rs.getByte("gender"); - characterSlots = rs.getByte("characterslots"); - lang = rs.getInt("language"); - String passhash = rs.getString("password"); - byte tos = rs.getByte("tos"); - - if (banned) { - return 3; - } - - if (getLoginState() > LOGIN_NOTLOGGEDIN) { // already loggedin - loggedIn = false; - loginok = 7; - } else if (passhash.charAt(0) == '$' && passhash.charAt(1) == '2' && BCrypt.checkpw(pwd, passhash)) { - loginok = (tos == 0) ? 23 : 0; - } else if (pwd.equals(passhash) || checkHash(passhash, "SHA-1", pwd) || checkHash(passhash, "SHA-512", pwd)) { - // thanks GabrielSin for detecting some no-bcrypt inconsistencies here - loginok = (tos == 0) ? (!YamlConfig.config.server.BCRYPT_MIGRATION ? 23 : -23) : (!YamlConfig.config.server.BCRYPT_MIGRATION ? 0 : -10); // migrate to bcrypt - } else { - loggedIn = false; - loginok = 4; - } - } else { - accId = -3; - } - } - } catch (SQLException e) { - e.printStackTrace(); - } - - if (loginok == 0 || loginok == 4) { - AntiMulticlientResult res = SessionCoordinator.getInstance().attemptLoginSession(this, hwid, accId, loginok == 4); - - switch (res) { - case SUCCESS: - if (loginok == 0) { - loginattempt = 0; - } - - return loginok; - - case REMOTE_LOGGEDIN: - return 17; - - case REMOTE_REACHED_LIMIT: - return 13; - - case REMOTE_PROCESSING: - return 10; - - case MANY_ACCOUNT_ATTEMPTS: - return 16; - - default: - return 8; - } - } else { - return loginok; - } + public boolean attemptLogin() { + return ++failedLoginAttempts < MAX_FAILED_LOGIN_ATTEMPTS; } - public Calendar getTempBanCalendarFromDB() { - final Calendar lTempban = Calendar.getInstance(); - - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("SELECT `tempban` FROM accounts WHERE id = ?")) { - ps.setInt(1, getAccID()); - - final Timestamp tempban; - try (ResultSet rs = ps.executeQuery()) { - if (!rs.next()) { - return null; - } - - tempban = rs.getTimestamp("tempban"); - if (tempban.toLocalDateTime().equals(DefaultDates.getTempban())) { - return null; - } - } - - lTempban.setTimeInMillis(tempban.getTime()); - tempBanCalendar = lTempban; - return lTempban; - } catch (SQLException e) { - e.printStackTrace(); - } - - return null;//why oh why!?! - } - - public Calendar getTempBanCalendar() { - return tempBanCalendar; - } - - public boolean hasBeenBanned() { - return tempBanCalendar != null; - } - - public static long dottedQuadToLong(String dottedQuad) throws RuntimeException { - String[] quads = dottedQuad.split("\\."); - if (quads.length != 4) { - throw new RuntimeException("Invalid IP Address format."); - } - long ipAddress = 0; - for (int i = 0; i < 4; i++) { - int quad = Integer.parseInt(quads[i]); - ipAddress += (long) (quad % 256) * (long) Math.pow(256, 4 - i); - } - return ipAddress; - } - - public void updateHwid(Hwid hwid) { - this.hwid = hwid; - - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("UPDATE accounts SET hwid = ? WHERE id = ?")) { - ps.setString(1, hwid.hwid()); - ps.setInt(2, accId); - ps.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - - public void updateMacs(String macData) { - macs.addAll(Arrays.asList(macData.split(", "))); - StringBuilder newMacData = new StringBuilder(); - Iterator iter = macs.iterator(); - while (iter.hasNext()) { - String cur = iter.next(); - newMacData.append(cur); - if (iter.hasNext()) { - newMacData.append(", "); - } - } - - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("UPDATE accounts SET macs = ? WHERE id = ?")) { - ps.setString(1, newMacData.toString()); - ps.setInt(2, accId); - ps.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); - } + public boolean wasRecentlyBanned() { + Instant recentThreshold = Instant.now().minus(Duration.ofDays(30)); + return account != null && account.bannedUntil() != null && account.bannedUntil().isAfter(recentThreshold); } public void setAccID(int id) { @@ -819,164 +380,30 @@ public int getAccID() { return accId; } - public void updateLoginState(int newState) { - // rules out possibility of multiple account entries - if (newState == LOGIN_LOGGEDIN) { - SessionCoordinator.getInstance().updateOnlineClient(this); - } - - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("UPDATE accounts SET loggedin = ?, lastlogin = ? WHERE id = ?")) { - // using sql currenttime here could potentially break the login, thanks Arnah for pointing this out - - ps.setInt(1, newState); - ps.setTimestamp(2, new java.sql.Timestamp(Server.getInstance().getCurrentTime())); - ps.setInt(3, getAccID()); - ps.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); - } - - if (newState == LOGIN_NOTLOGGEDIN) { - loggedIn = false; - serverTransition = false; - setAccID(0); - } else { - serverTransition = (newState == LOGIN_SERVER_TRANSITION); - loggedIn = !serverTransition; - } - } - - public int getLoginState() { // 0 = LOGIN_NOTLOGGEDIN, 1= LOGIN_SERVER_TRANSITION, 2 = LOGIN_LOGGEDIN - try (Connection con = DatabaseConnection.getConnection()) { - int state; - try (PreparedStatement ps = con.prepareStatement("SELECT loggedin, lastlogin, birthday FROM accounts WHERE id = ?")) { - ps.setInt(1, getAccID()); - - try (ResultSet rs = ps.executeQuery()) { - if (!rs.next()) { - throw new RuntimeException("getLoginState - Client AccID: " + getAccID()); - } - - birthday = Calendar.getInstance(); - try { - birthday.setTime(rs.getDate("birthday")); - } catch (SQLException e) { - } - - state = rs.getInt("loggedin"); - if (state == LOGIN_SERVER_TRANSITION) { - if (rs.getTimestamp("lastlogin").getTime() + 30000 < Server.getInstance().getCurrentTime()) { - int accountId = accId; - state = LOGIN_NOTLOGGEDIN; - updateLoginState(Client.LOGIN_NOTLOGGEDIN); // ACCID = 0, issue found thanks to Tochi & K u ssss o & Thora & Omo Oppa - this.setAccID(accountId); - } - } - } - } - if (state == LOGIN_LOGGEDIN) { - loggedIn = true; - } else if (state == LOGIN_SERVER_TRANSITION) { - try (PreparedStatement ps2 = con.prepareStatement("UPDATE accounts SET loggedin = 0 WHERE id = ?")) { - ps2.setInt(1, getAccID()); - ps2.executeUpdate(); - } - } else { + public void onChangedLoginState(LoginState newState) { + switch (newState) { + case LoginState.LOGGED_OUT -> { loggedIn = false; + inServerTransition = false; } - return state; - } catch (SQLException e) { - loggedIn = false; - e.printStackTrace(); - throw new RuntimeException("login state"); - } - } - - public boolean checkBirthDate(Calendar date) { - return date.get(Calendar.YEAR) == birthday.get(Calendar.YEAR) && date.get(Calendar.MONTH) == birthday.get(Calendar.MONTH) && date.get(Calendar.DAY_OF_MONTH) == birthday.get(Calendar.DAY_OF_MONTH); - } - - private void removePartyPlayer(World wserv) { - MapleMap map = player.getMap(); - final Party party = player.getParty(); - final int idz = player.getId(); - - if (party != null) { - final PartyCharacter chrp = new PartyCharacter(player); - chrp.setOnline(false); - wserv.updateParty(party.getId(), PartyOperation.LOG_ONOFF, chrp); - if (party.getLeader().getId() == idz && map != null) { - PartyCharacter lchr = null; - for (PartyCharacter pchr : party.getMembers()) { - if (pchr != null && pchr.getId() != idz && (lchr == null || lchr.getLevel() <= pchr.getLevel()) && map.getCharacterById(pchr.getId()) != null) { - lchr = pchr; - } - } - if (lchr != null) { - wserv.updateParty(party.getId(), PartyOperation.CHANGE_LEADER, lchr); - } - } - } - } - - private void removePlayer(World wserv, boolean serverTransition) { - try { - player.setDisconnectedFromChannelWorld(); - player.notifyMapTransferToPartner(-1); - player.removeIncomingInvites(); - player.cancelAllBuffs(true); - - player.closePlayerInteractions(); - player.closePartySearchInteractions(); - - if (!serverTransition) { // thanks MedicOP for detecting an issue with party leader change on changing channels - removePartyPlayer(wserv); - - EventInstanceManager eim = player.getEventInstance(); - if (eim != null) { - eim.playerDisconnected(player); - } - - if (player.getMonsterCarnival() != null) { - player.getMonsterCarnival().playerDisconnected(getPlayer().getId()); - } - - if (player.getAriantColiseum() != null) { - player.getAriantColiseum().playerDisconnected(getPlayer()); - } + case LoginState.SERVER_TRANSITION -> { + loggedIn = false; + inServerTransition = true; } - - if (player.getMap() != null) { - int mapId = player.getMapId(); - player.getMap().removePlayer(player); - if (MapId.isDojo(mapId)) { - this.getChannelServer().freeDojoSectionIfEmpty(mapId); - } - - if (player.getMap().getHPDec() > 0) { - getWorldServer().removePlayerHpDecrease(player); - } + case LoginState.LOGGED_IN -> { + loggedIn = true; + inServerTransition = false; } - - } catch (final Throwable t) { - log.error("Account stuck", t); } } - public final void disconnect(final boolean shutdown, final boolean cashshop) { - if (canDisconnect()) { - ThreadManager.getInstance().newTask(() -> disconnectInternal(shutdown, cashshop)); - } - } - - public final void forceDisconnect() { - if (canDisconnect()) { - disconnectInternal(true, false); - } + public boolean checkBirthDate(Calendar date) { + LocalDate toCheck = LocalDate.of(date.get(Calendar.YEAR), date.get(Calendar.MONTH), + date.get(Calendar.DAY_OF_MONTH)); + return Objects.equals(birthday, toCheck); } - private synchronized boolean canDisconnect() { + public synchronized boolean tryDisconnect() { if (disconnecting) { return false; } @@ -985,98 +412,7 @@ private synchronized boolean canDisconnect() { return true; } - private void disconnectInternal(boolean shutdown, boolean cashshop) {//once per Client instance - if (player != null && player.isLoggedin() && player.getClient() != null) { - final int messengerid = player.getMessenger() == null ? 0 : player.getMessenger().getId(); - //final int fid = player.getFamilyId(); - final BuddyList bl = player.getBuddylist(); - final MessengerCharacter chrm = new MessengerCharacter(player, 0); - final GuildCharacter chrg = player.getMGC(); - final Guild guild = player.getGuild(); - - player.cancelMagicDoor(); - - final World wserv = getWorldServer(); // obviously wserv is NOT null if this player was online on it - try { - removePlayer(wserv, this.serverTransition); - - if (!(channel == -1 || shutdown)) { - if (!cashshop) { - if (!this.serverTransition) { // meaning not changing channels - if (messengerid > 0) { - wserv.leaveMessenger(messengerid, chrm); - } - /* - if (fid > 0) { - final Family family = worlda.getFamily(fid); - family. - } - */ - - player.forfeitExpirableQuests(); //This is for those quests that you have to stay logged in for a certain amount of time - - if (guild != null) { - final Server server = Server.getInstance(); - server.setGuildMemberOnline(player, false, player.getClient().getChannel()); - player.sendPacket(GuildPackets.showGuildInfo(player)); - } - if (bl != null) { - wserv.loggedOff(player.getName(), player.getId(), channel, player.getBuddylist().getBuddyIds()); - } - } - } else { - if (!this.serverTransition) { // if dc inside of cash shop. - if (bl != null) { - wserv.loggedOff(player.getName(), player.getId(), channel, player.getBuddylist().getBuddyIds()); - } - } - } - } - } catch (final Exception e) { - log.error("Account stuck", e); - } finally { - if (!this.serverTransition) { - if (chrg != null) { - chrg.setCharacter(null); - } - wserv.removePlayer(player); - //getChannelServer().removePlayer(player); already being done - - player.saveCooldowns(); - player.cancelAllDebuffs(); - player.saveCharToDB(true); - - player.logOff(); - if (YamlConfig.config.server.INSTANT_NAME_CHANGE) { - player.doPendingNameChange(); - } - clear(); - } else { - getChannelServer().removePlayer(player); - - player.saveCooldowns(); - player.cancelAllDebuffs(); - player.saveCharToDB(); - } - } - } - - SessionCoordinator.getInstance().closeSession(this, false); - - if (!serverTransition && isLoggedIn()) { - updateLoginState(Client.LOGIN_NOTLOGGEDIN); - - clear(); - } else { - if (!Server.getInstance().hasCharacteridInTransition(this)) { - updateLoginState(Client.LOGIN_NOTLOGGEDIN); - } - - engines = null; // thanks Tochi for pointing out a NPE here - } - } - - private void clear() { + public void clear() { // player hard reference removal thanks to Steve (kaito1410) if (this.player != null) { this.player.empty(true); // clears schedules and stuff @@ -1092,10 +428,10 @@ private void clear() { this.player = null; } - public void setCharacterOnSessionTransitionState(int cid) { - this.updateLoginState(Client.LOGIN_SERVER_TRANSITION); - this.inTransition = true; - Server.getInstance().setCharacteridInTransition(this, cid); + public void clearEngines() { + if (engines != null) { + engines.clear(); + } } public int getChannel() { @@ -1169,7 +505,6 @@ public void checkIfIdle(final IdleStateEvent event) { if (lastPong < pingedAt) { if (ioChannel.isActive()) { log.info("Disconnected {} due to idling. Reason: {}", remoteAddress, event.state()); - updateLoginState(Client.LOGIN_NOTLOGGEDIN); disconnectSession(); } } @@ -1211,95 +546,6 @@ public QuestActionManager getQM() { return QuestScriptManager.getInstance().getQM(this); } - public boolean acceptToS() { - if (accountName == null) { - return true; - } - - boolean disconnect = false; - try (Connection con = DatabaseConnection.getConnection()) { - try (PreparedStatement ps = con.prepareStatement("SELECT `tos` FROM accounts WHERE id = ?")) { - ps.setInt(1, accId); - - try (ResultSet rs = ps.executeQuery()) { - if (rs.next()) { - if (rs.getByte("tos") == 1) { - disconnect = true; - } - } - } - } - - try (PreparedStatement ps = con.prepareStatement("UPDATE accounts SET tos = 1 WHERE id = ?")) { - ps.setInt(1, accId); - ps.executeUpdate(); - } - } catch (SQLException e) { - e.printStackTrace(); - } - return disconnect; - } - - public void checkChar(int accid) { /// issue with multiple chars from same account login found by shavit, resinate - if (!YamlConfig.config.server.USE_CHARACTER_ACCOUNT_CHECK) { - return; - } - - for (World w : Server.getInstance().getWorlds()) { - for (Character chr : w.getPlayerStorage().getAllCharacters()) { - if (accid == chr.getAccountID()) { - log.warn("Chr {} has been removed from world {}. Possible Dupe attempt.", chr.getName(), GameConstants.WORLD_NAMES[w.getId()]); - chr.getClient().forceDisconnect(); - w.getPlayerStorage().removePlayer(chr.getId()); - } - } - } - } - - public int getVotePoints() { - int points = 0; - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("SELECT `votepoints` FROM accounts WHERE id = ?")) { - ps.setInt(1, accId); - - try (ResultSet rs = ps.executeQuery()) { - if (rs.next()) { - points = rs.getInt("votepoints"); - } - } - } catch (SQLException e) { - e.printStackTrace(); - } - votePoints = points; - return votePoints; - } - - public void addVotePoints(int points) { - votePoints += points; - saveVotePoints(); - } - - public void useVotePoints(int points) { - if (points > votePoints) { - //Should not happen, should probably log this - return; - } - votePoints -= points; - saveVotePoints(); - MapleLeafLogger.log(player, false, Integer.toString(points)); - } - - private void saveVotePoints() { - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("UPDATE accounts SET votepoints = ? WHERE id = ?")) { - ps.setInt(1, votePoints); - ps.setInt(2, accId); - ps.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); - } - } - public void lockClient() { lock.lock(); } @@ -1322,42 +568,6 @@ public void releaseClient() { actionsSemaphore.release(); } - public boolean tryacquireEncoder() { - if (actionsSemaphore.tryAcquire()) { - encoderLock.lock(); - return true; - } else { - return false; - } - } - - public void unlockEncoder() { - encoderLock.unlock(); - actionsSemaphore.release(); - } - - private static class CharNameAndId { - - public String name; - public int id; - - public CharNameAndId(String name, int id) { - super(); - this.name = name; - this.id = id; - } - } - - private static boolean checkHash(String hash, String type, String password) { - try { - MessageDigest digester = MessageDigest.getInstance(type); - digester.update(password.getBytes(StandardCharsets.UTF_8), 0, password.length()); - return HexTool.toHexString(digester.digest()).replace(" ", "").toLowerCase().equals(hash); - } catch (NoSuchAlgorithmException e) { - throw new RuntimeException("Encoding the string failed", e); - } - } - public short getAvailableCharacterSlots() { return (short) Math.max(0, characterSlots - Server.getInstance().getAccountCharacterCount(accId)); } @@ -1379,56 +589,26 @@ public void setCharacterSlots(byte slots) { } public boolean canGainCharacterSlot() { - return characterSlots < 15; + return characterSlots < MAX_CHR_SLOTS; } - public synchronized boolean gainCharacterSlot() { + public boolean gainCharacterSlot() { if (canGainCharacterSlot()) { - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("UPDATE accounts SET characterslots = ? WHERE id = ?")) { - ps.setInt(1, this.characterSlots += 1); - ps.setInt(2, accId); - ps.executeUpdate(); - - } catch (SQLException e) { - e.printStackTrace(); - } + characterSlots++; return true; } return false; } - public final byte getGReason() { - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("SELECT `greason` FROM `accounts` WHERE id = ?")) { - ps.setInt(1, accId); - - try (ResultSet rs = ps.executeQuery()) { - if (rs.next()) { - return rs.getByte("greason"); - } - } - } catch (SQLException e) { - e.printStackTrace(); - } - return 0; - } - public byte getGender() { return gender; } - public void setGender(byte m) { - this.gender = m; - - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("UPDATE accounts SET gender = ? WHERE id = ?")) { - ps.setByte(1, gender); - ps.setInt(2, accId); - ps.executeUpdate(); - } catch (SQLException e) { - e.printStackTrace(); + public void setGender(byte gender) { + if (gender != Gender.MALE && gender != Gender.FEMALE) { + throw new IllegalArgumentException("Invalid gender: " + gender); } + this.gender = gender; } private void announceDisableServerMessage() { @@ -1476,68 +656,10 @@ public void announceHint(String msg, int length) { sendPacket(PacketCreator.enableActions()); } - public void changeChannel(int channel) { - Server server = Server.getInstance(); - if (player.isBanned()) { - disconnect(false, false); - return; - } - if (!player.isAlive() || FieldLimit.CANNOTMIGRATE.check(player.getMap().getFieldLimit())) { - sendPacket(PacketCreator.enableActions()); - return; - } else if (MiniDungeonInfo.isDungeonMap(player.getMapId())) { - sendPacket(PacketCreator.serverNotice(5, "Changing channels or entering Cash Shop or MTS are disabled when inside a Mini-Dungeon.")); - sendPacket(PacketCreator.enableActions()); - return; - } - - String[] socket = Server.getInstance().getInetSocket(this, getWorld(), channel); - if (socket == null) { - sendPacket(PacketCreator.serverNotice(1, "Channel " + channel + " is currently disabled. Try another channel.")); - sendPacket(PacketCreator.enableActions()); - return; - } - - player.closePlayerInteractions(); - player.closePartySearchInteractions(); - - player.unregisterChairBuff(); - server.getPlayerBuffStorage().addBuffsToStorage(player.getId(), player.getAllBuffs()); - server.getPlayerBuffStorage().addDiseasesToStorage(player.getId(), player.getAllDiseases()); - player.setDisconnectedFromChannelWorld(); - player.notifyMapTransferToPartner(-1); - player.removeIncomingInvites(); - player.cancelAllBuffs(true); - player.cancelAllDebuffs(); - player.cancelBuffExpireTask(); - player.cancelDiseaseExpireTask(); - player.cancelSkillCooldownTask(); - player.cancelQuestExpirationTask(); - //Cancelling magicdoor? Nope - //Cancelling mounts? Noty - - player.getInventory(InventoryType.EQUIPPED).checked(false); //test - player.getMap().removePlayer(player); - player.getClient().getChannelServer().removePlayer(player); - - player.saveCharToDB(); - - player.setSessionTransitionState(); - try { - sendPacket(PacketCreator.getChannelChange(InetAddress.getByName(socket[0]), Integer.parseInt(socket[1]))); - } catch (IOException e) { - e.printStackTrace(); - } - } - public long getSessionId() { return this.sessionId; } - public boolean canRequestCharlist() { - return lastNpcClick + 877 < Server.getInstance().getCurrentTime(); - } - public boolean canClickNPC() { return lastNpcClick + 500 < Server.getInstance().getCurrentTime(); } @@ -1550,15 +672,6 @@ public void removeClickedNPC() { lastNpcClick = 0; } - public int getVisibleWorlds() { - return visibleWorlds; - } - - public void requestedServerlist(int worlds) { - visibleWorlds = worlds; - setClickedNPC(); - } - public void closePlayerScriptInteractions() { this.removeClickedNPC(); NPCScriptManager.getInstance().dispose(this); @@ -1590,12 +703,4 @@ public boolean canBypassPin() { public boolean canBypassPic() { return LoginBypassCoordinator.getInstance().canLoginBypass(hwid, accId, true); } - - public int getLanguage() { - return lang; - } - - public void setLanguage(int lingua) { - this.lang = lingua; - } } diff --git a/src/main/java/client/Gender.java b/src/main/java/client/Gender.java new file mode 100644 index 00000000000..6f802c4e23c --- /dev/null +++ b/src/main/java/client/Gender.java @@ -0,0 +1,10 @@ +package client; + +/** + * @author Ponk + */ +public class Gender { + public static final byte MALE = 0; + public static final byte FEMALE = 1; + public static final byte NOT_SET = 10; +} diff --git a/src/main/java/client/LoginState.java b/src/main/java/client/LoginState.java new file mode 100644 index 00000000000..4d9e0b8d287 --- /dev/null +++ b/src/main/java/client/LoginState.java @@ -0,0 +1,29 @@ +package client; + +import java.util.Arrays; +import java.util.Optional; + +/** + * @author Ponk + */ +public enum LoginState { + LOGGED_OUT(0), + SERVER_TRANSITION(1), + LOGGED_IN(2); + + private final byte value; + + LoginState(int value) { + this.value = (byte) value; + } + + public byte getValue() { + return value; + } + + public static Optional fromValue(int value) { + return Arrays.stream(values()) + .filter(v -> v.getValue() == value) + .findFirst(); + } +} diff --git a/src/main/java/client/MonsterBook.java b/src/main/java/client/MonsterBook.java index ca75906e82d..bd56f7cc0fb 100644 --- a/src/main/java/client/MonsterBook.java +++ b/src/main/java/client/MonsterBook.java @@ -1,225 +1,110 @@ -/* - This file is part of the OdinMS Maple Story Server - Copyright (C) 2008 Patrick Huy - Matthias Butz - Jan Christian Meyer - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ package client; -import tools.DatabaseConnection; +import database.monsterbook.MonsterCard; +import net.jcip.annotations.ThreadSafe; import tools.PacketCreator; import java.sql.Connection; import java.sql.PreparedStatement; -import java.sql.ResultSet; import java.sql.SQLException; -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedHashMap; import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import java.util.concurrent.locks.Lock; -import java.util.concurrent.locks.ReentrantLock; - -public final class MonsterBook { - private int specialCard = 0; - private int normalCard = 0; - private int bookLevel = 1; - private final Map cards = new LinkedHashMap<>(); - private final Lock lock = new ReentrantLock(); - - public Set> getCardSet() { - lock.lock(); - try { - return new HashSet<>(cards.entrySet()); - } finally { - lock.unlock(); - } +import java.util.ArrayList; +import java.util.List; +import java.util.function.Function; +import java.util.function.Predicate; +import java.util.stream.Collectors; + +// TODO: add tests +@ThreadSafe +public class MonsterBook { + private final Map cards; + private int bookLevel; + + public MonsterBook(List monsterCards) { + this.cards = monsterCards.stream() + .collect(Collectors.toMap(MonsterCard::cardId, Function.identity())); } - public void addCard(final Client c, final int cardid) { - c.getPlayer().getMap().broadcastMessage(c.getPlayer(), PacketCreator.showForeignCardEffect(c.getPlayer().getId()), false); - - Integer qty; - lock.lock(); - try { - qty = cards.get(cardid); - - if (qty != null) { - if (qty < 5) { - cards.put(cardid, qty + 1); - } - } else { - cards.put(cardid, 1); - qty = 0; - - if (cardid / 1000 >= 2388) { - specialCard++; - } else { - normalCard++; - } - } - } finally { - lock.unlock(); - } + public synchronized List getCards() { + return new ArrayList<>(cards.values()); + } - if (qty < 5) { - if (qty == 0) { // leveling system only accounts unique cards - calculateLevel(); - } + public synchronized void addCard(int cardId, Client client) { + var monsterCard = cards.get(cardId); + if (monsterCard != null && monsterCard.isMaxLevel()) { + client.sendPacket(PacketCreator.addMonsterCardAlreadyFull()); + return; + } - c.sendPacket(PacketCreator.addCard(false, cardid, qty + 1)); - c.sendPacket(PacketCreator.showGainCard()); + boolean isNewCard = monsterCard == null; + final MonsterCard card; + if (isNewCard) { + card = new MonsterCard(cardId, (byte) 1); + cards.put(cardId, card); + calculateAndSetLevel(); } else { - c.sendPacket(PacketCreator.addCard(true, cardid, 5)); + card = new MonsterCard(cardId, (byte) (monsterCard.level() + 1)); + cards.put(cardId, card); } - } - private void calculateLevel() { - lock.lock(); - try { - int collectionExp = (normalCard + specialCard); - - int level = 0, expToNextlevel = 1; - do { - level++; - expToNextlevel += level * 10; - } while (collectionExp >= expToNextlevel); - - bookLevel = level; // thanks IxianMace for noticing book level differing between book UI and character info UI - } finally { - lock.unlock(); - } + var chr = client.getPlayer(); + chr.sendPacket(PacketCreator.addMonsterCard(card)); + chr.sendPacket(PacketCreator.showMonsterCardEffect()); + chr.getMap().broadcastMessage(chr, PacketCreator.showForeignMonsterCardEffect(chr.getId()), false); } - public int getBookLevel() { - lock.lock(); - try { - return bookLevel; - } finally { - lock.unlock(); - } - } + private synchronized void calculateAndSetLevel() { + int collectionExp = getTotalCards(); - public Map getCards() { - lock.lock(); - try { - return Collections.unmodifiableMap(cards); - } finally { - lock.unlock(); - } - } + int level = 0; + int expToNextLevel = 1; + do { + level++; + expToNextLevel += level * 10; + } while (collectionExp >= expToNextLevel); - public int getTotalCards() { - lock.lock(); - try { - return specialCard + normalCard; - } finally { - lock.unlock(); - } + this.bookLevel = level; } - public int getNormalCard() { - lock.lock(); - try { - return normalCard; - } finally { - lock.unlock(); - } + public synchronized int getBookLevel() { + return bookLevel; } - public int getSpecialCard() { - lock.lock(); - try { - return specialCard; - } finally { - lock.unlock(); - } + public synchronized int getNormalCards() { + return (int) cards.values().stream() + .filter(Predicate.not(MonsterCard::isSpecial)) + .count(); } - public void loadCards(final int charid) throws SQLException { - lock.lock(); - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("SELECT cardid, level FROM monsterbook WHERE charid = ? ORDER BY cardid ASC")) { - ps.setInt(1, charid); - - try (ResultSet rs = ps.executeQuery()) { - int cardid; - int level; - while (rs.next()) { - cardid = rs.getInt("cardid"); - level = rs.getInt("level"); - if (cardid / 1000 >= 2388) { - specialCard++; - } else { - normalCard++; - } - cards.put(cardid, level); - } - } - } finally { - lock.unlock(); - } + public synchronized int getSpecialCards() { + return (int) cards.values().stream() + .filter(MonsterCard::isSpecial) + .count(); + } - calculateLevel(); + public synchronized int getTotalCards() { + return cards.size(); } - public void saveCards(Connection con, int chrId) throws SQLException { + public synchronized void saveCards(Connection con, int chrId) throws SQLException { final String query = """ INSERT INTO monsterbook (charid, cardid, level) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE level = ?; """; try (final PreparedStatement ps = con.prepareStatement(query)) { - for (Map.Entry cardAndLevel : cards.entrySet()) { - final int card = cardAndLevel.getKey(); - final int level = cardAndLevel.getValue(); + for (MonsterCard card : cards.values()) { // insert ps.setInt(1, chrId); - ps.setInt(2, card); - ps.setInt(3, level); + ps.setInt(2, card.cardId()); + ps.setInt(3, card.level()); // update - ps.setInt(4, level); + ps.setInt(4, card.level()); ps.addBatch(); } ps.executeBatch(); } } - - public static int[] getCardTierSize() { - try (Connection con = DatabaseConnection.getConnection(); - PreparedStatement ps = con.prepareStatement("SELECT COUNT(*) FROM monstercarddata GROUP BY floor(cardid / 1000);", ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY); - ResultSet rs = ps.executeQuery()) { - rs.last(); - int[] tierSizes = new int[rs.getRow()]; - rs.beforeFirst(); - - while (rs.next()) { - tierSizes[rs.getRow() - 1] = rs.getInt(1); - } - - return tierSizes; - } catch (SQLException e) { - e.printStackTrace(); - return new int[0]; - } - } } diff --git a/src/main/java/client/autoban/AutobanFactory.java b/src/main/java/client/autoban/AutobanFactory.java index 811fd7410c8..7cd23af41cd 100644 --- a/src/main/java/client/autoban/AutobanFactory.java +++ b/src/main/java/client/autoban/AutobanFactory.java @@ -88,10 +88,6 @@ public long getExpire() { return expiretime; } - public void addPoint(AutobanManager ban, String reason) { - ban.addPoint(this, reason); - } - public void alert(Character chr, String reason) { if (YamlConfig.config.server.USE_AUTOBAN) { if (chr != null && isIgnored(chr.getId())) { @@ -105,13 +101,6 @@ public void alert(Character chr, String reason) { } } - public void autoban(Character chr, String value) { - if (YamlConfig.config.server.USE_AUTOBAN) { - chr.autoban("Autobanned for (" + this.name() + ": " + value + ")"); - //chr.sendPolice("You will be disconnected for (" + this.name() + ": " + value + ")"); - } - } - /** * Toggle ignored status for a character id. * An ignored character will not trigger GM alerts. diff --git a/src/main/java/client/autoban/AutobanManager.java b/src/main/java/client/autoban/AutobanManager.java index a227ca7e1c3..ca2a4c11057 100644 --- a/src/main/java/client/autoban/AutobanManager.java +++ b/src/main/java/client/autoban/AutobanManager.java @@ -7,6 +7,7 @@ import client.Character; import config.YamlConfig; +import net.netty.GameViolationException; import net.server.Server; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,35 +36,27 @@ public AutobanManager(Character chr) { this.chr = chr; } - public void addPoint(AutobanFactory fac, String reason) { - if (YamlConfig.config.server.USE_AUTOBAN) { - if (chr.isGM() || chr.isBanned()) { - return; - } - - if (lastTime.containsKey(fac)) { - if (lastTime.get(fac) < (Server.getInstance().getCurrentTime() - fac.getExpire())) { - points.put(fac, points.get(fac) / 2); //So the points are not completely gone. - } - } - if (fac.getExpire() != -1) { - lastTime.put(fac, Server.getInstance().getCurrentTime()); - } - - if (points.containsKey(fac)) { - points.put(fac, points.get(fac) + 1); - } else { - points.put(fac, 1); + /** + * @return true if the added point should result in an autoban + */ + public boolean addPoint(AutobanFactory fac) { + if (lastTime.containsKey(fac)) { + if (lastTime.get(fac) < (Server.getInstance().getCurrentTime() - fac.getExpire())) { + points.put(fac, points.get(fac) / 2); //So the points are not completely gone. } + } - if (points.get(fac) >= fac.getMaximum()) { - chr.autoban(reason); - } + if (fac.getExpire() != -1) { + lastTime.put(fac, Server.getInstance().getCurrentTime()); } - if (YamlConfig.config.server.USE_AUTOBAN_LOG) { - // Lets log every single point too. - log.info("Autoban - chr {} caused {} {}", Character.makeMapleReadable(chr.getName()), fac.name(), reason); + + if (points.containsKey(fac)) { + points.put(fac, points.get(fac) + 1); + } else { + points.put(fac, 1); } + + return points.get(fac) >= fac.getMaximum(); } public void addMiss() { @@ -118,11 +111,10 @@ public void setTimestamp(int type, int time, int times) { if (this.timestamp[type] == time) { this.timestampcounter[type]++; if (this.timestampcounter[type] >= times) { + log.info("Autoban - Chr {} was caught spamming TYPE {} and has been disconnected", chr, type); if (YamlConfig.config.server.USE_AUTOBAN) { - chr.getClient().disconnect(false, false); + throw new GameViolationException("Auto ban"); } - - log.info("Autoban - Chr {} was caught spamming TYPE {} and has been disconnected", chr, type); } } else { this.timestamp[type] = time; diff --git a/src/main/java/client/command/Command.java b/src/main/java/client/command/Command.java index 6fd6080be92..5c2ff02533c 100644 --- a/src/main/java/client/command/Command.java +++ b/src/main/java/client/command/Command.java @@ -30,7 +30,7 @@ public abstract class Command { protected int rank; protected String description; - public abstract void execute(Client client, String[] params); + public abstract void execute(Client client, String[] params, CommandContext ctx); public String getDescription() { return description; diff --git a/src/main/java/client/command/CommandContext.java b/src/main/java/client/command/CommandContext.java new file mode 100644 index 00000000000..c643c1f78d4 --- /dev/null +++ b/src/main/java/client/command/CommandContext.java @@ -0,0 +1,19 @@ +package client.command; + +import database.character.CharacterSaver; +import database.drop.DropProvider; +import server.shop.ShopFactory; +import service.BanService; +import service.TransitionService; + +/** + * @author Ponk + */ +public record CommandContext(CommandsExecutor commandsExecutor, DropProvider dropProvider, ShopFactory shopFactory, + CharacterSaver characterSaver, TransitionService transitionService, BanService banService +) { + + public CommandContext with(CommandsExecutor ce) { + return new CommandContext(ce, dropProvider, shopFactory, characterSaver, transitionService, banService); + } +} diff --git a/src/main/java/client/command/CommandsExecutor.java b/src/main/java/client/command/CommandsExecutor.java index 16de5278254..9109c6c4106 100644 --- a/src/main/java/client/command/CommandsExecutor.java +++ b/src/main/java/client/command/CommandsExecutor.java @@ -24,7 +24,6 @@ package client.command; import client.Client; -import client.command.commands.gm0.ChangeLanguageCommand; import client.command.commands.gm0.DisposeCommand; import client.command.commands.gm0.DropLimitCommand; import client.command.commands.gm0.EnableAuthCommand; @@ -38,7 +37,6 @@ import client.command.commands.gm0.OnlineCommand; import client.command.commands.gm0.RanksCommand; import client.command.commands.gm0.RatesCommand; -import client.command.commands.gm0.ReadPointsCommand; import client.command.commands.gm0.ReportBugCommand; import client.command.commands.gm0.ShowRatesCommand; import client.command.commands.gm0.StaffCommand; @@ -106,8 +104,6 @@ import client.command.commands.gm3.FlyCommand; import client.command.commands.gm3.GiveMesosCommand; import client.command.commands.gm3.GiveNxCommand; -import client.command.commands.gm3.GiveRpCommand; -import client.command.commands.gm3.GiveVpCommand; import client.command.commands.gm3.HairCommand; import client.command.commands.gm3.HealMapCommand; import client.command.commands.gm3.HealPersonCommand; @@ -189,15 +185,10 @@ import client.command.commands.gm6.GetAccCommand; import client.command.commands.gm6.MapPlayersCommand; import client.command.commands.gm6.SaveAllCommand; -import client.command.commands.gm6.ServerAddChannelCommand; -import client.command.commands.gm6.ServerAddWorldCommand; -import client.command.commands.gm6.ServerRemoveChannelCommand; -import client.command.commands.gm6.ServerRemoveWorldCommand; import client.command.commands.gm6.SetGmLevelCommand; import client.command.commands.gm6.ShutdownCommand; import client.command.commands.gm6.SpawnAllPNpcsCommand; import client.command.commands.gm6.SupplyRateCouponCommand; -import client.command.commands.gm6.WarpWorldCommand; import constants.id.MapId; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -210,27 +201,20 @@ public class CommandsExecutor { private static final Logger log = LoggerFactory.getLogger(CommandsExecutor.class); - private static final CommandsExecutor instance = new CommandsExecutor(); private static final char USER_HEADING = '@'; private static final char GM_HEADING = '!'; private final HashMap registeredCommands = new HashMap<>(); private final List, List>> commandsNameDesc = new ArrayList<>(); + private final CommandContext commandContext; private Pair, List> levelCommandsCursor; - public static CommandsExecutor getInstance() { - return instance; + public CommandsExecutor(CommandContext commandContext) { + this.commandContext = commandContext.with(this); + registerCommands(); } - public static boolean isCommand(Client client, String content) { - char heading = content.charAt(0); - if (client.getPlayer().isGM()) { - return heading == USER_HEADING || heading == GM_HEADING; - } - return heading == USER_HEADING; - } - - private CommandsExecutor() { + private void registerCommands() { registerLv0Commands(); registerLv1Commands(); registerLv2Commands(); @@ -240,6 +224,14 @@ private CommandsExecutor() { registerLv6Commands(); } + public static boolean isCommand(Client client, String content) { + char heading = content.charAt(0); + if (client.getPlayer().isGM()) { + return heading == USER_HEADING || heading == GM_HEADING; + } + return heading == USER_HEADING; + } + public List, List>> getGmCommands() { return commandsNameDesc; } @@ -287,7 +279,7 @@ private void handleInternal(Client client, String message) { params = new String[]{}; } - command.execute(client, params); + command.execute(client, params, commandContext); log.info("Chr {} used command {}", client.getPlayer().getName(), command.getClass().getSimpleName()); } @@ -347,14 +339,12 @@ private void registerLv0Commands() { addCommand("uptime", UptimeCommand.class); addCommand("gacha", GachaCommand.class); addCommand("dispose", DisposeCommand.class); - addCommand("changel", ChangeLanguageCommand.class); addCommand("equiplv", EquipLvCommand.class); addCommand("showrates", ShowRatesCommand.class); addCommand("rates", RatesCommand.class); addCommand("online", OnlineCommand.class); addCommand("gm", GmCommand.class); addCommand("reportbug", ReportBugCommand.class); - addCommand("points", ReadPointsCommand.class); addCommand("joinevent", JoinEventCommand.class); addCommand("leaveevent", LeaveEventCommand.class); addCommand("ranks", RanksCommand.class); @@ -454,9 +444,7 @@ private void registerLv3Commands() { addCommand("togglewhitechat", 3, ChatCommand.class); addCommand("fame", 3, FameCommand.class); addCommand("givenx", 3, GiveNxCommand.class); - addCommand("givevp", 3, GiveVpCommand.class); addCommand("givems", 3, GiveMesosCommand.class); - addCommand("giverp", 3, GiveRpCommand.class); addCommand("expeds", 3, ExpedsCommand.class); addCommand("kill", 3, KillCommand.class); addCommand("seed", 3, SeedCommand.class); @@ -542,7 +530,6 @@ private void registerLv6Commands() { levelCommandsCursor = new Pair<>(new ArrayList(), new ArrayList()); addCommand("setgmlevel", 6, SetGmLevelCommand.class); - addCommand("warpworld", 6, WarpWorldCommand.class); addCommand("saveall", 6, SaveAllCommand.class); addCommand("dcall", 6, DCAllCommand.class); addCommand("mapplayers", 6, MapPlayersCommand.class); @@ -553,10 +540,6 @@ private void registerLv6Commands() { addCommand("supplyratecoupon", 6, SupplyRateCouponCommand.class); addCommand("spawnallpnpcs", 6, SpawnAllPNpcsCommand.class); addCommand("eraseallpnpcs", 6, EraseAllPNpcsCommand.class); - addCommand("addchannel", 6, ServerAddChannelCommand.class); - addCommand("addworld", 6, ServerAddWorldCommand.class); - addCommand("removechannel", 6, ServerRemoveChannelCommand.class); - addCommand("removeworld", 6, ServerRemoveWorldCommand.class); addCommand("devtest", 6, DevtestCommand.class); commandsNameDesc.add(levelCommandsCursor); diff --git a/src/main/java/client/command/commands/gm0/ChangeLanguageCommand.java b/src/main/java/client/command/commands/gm0/ChangeLanguageCommand.java deleted file mode 100644 index d953d4c11ac..00000000000 --- a/src/main/java/client/command/commands/gm0/ChangeLanguageCommand.java +++ /dev/null @@ -1,42 +0,0 @@ -/* - This file is part of the HeavenMS MapleStory Server, commands OdinMS-based - Copyleft (L) 2016 - 2019 RonanLana - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -/* - @Author: Arthur L - Refactored command content into modules -*/ -package client.command.commands.gm0; - -import client.Client; -import client.command.Command; - -public class ChangeLanguageCommand extends Command { - { - setDescription("Change language settings."); - } - - @Override - public void execute(Client c, String[] params) { - if (params.length < 1) { - c.getPlayer().yellowMessage("Syntax: !changel <0=ptb, 1=esp, 2=eng>"); - return; - } - c.setLanguage(Integer.parseInt(params[0])); - } -} diff --git a/src/main/java/client/command/commands/gm0/DisposeCommand.java b/src/main/java/client/command/commands/gm0/DisposeCommand.java index c5f3543deba..ec5020a08f1 100644 --- a/src/main/java/client/command/commands/gm0/DisposeCommand.java +++ b/src/main/java/client/command/commands/gm0/DisposeCommand.java @@ -25,6 +25,7 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; import scripting.npc.NPCScriptManager; import scripting.quest.QuestScriptManager; import tools.PacketCreator; @@ -35,7 +36,7 @@ public class DisposeCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { NPCScriptManager.getInstance().dispose(c); QuestScriptManager.getInstance().dispose(c); c.sendPacket(PacketCreator.enableActions()); diff --git a/src/main/java/client/command/commands/gm0/DropLimitCommand.java b/src/main/java/client/command/commands/gm0/DropLimitCommand.java index 5792d47bdb1..d4f33ed35a7 100644 --- a/src/main/java/client/command/commands/gm0/DropLimitCommand.java +++ b/src/main/java/client/command/commands/gm0/DropLimitCommand.java @@ -25,6 +25,7 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; import config.YamlConfig; public class DropLimitCommand extends Command { @@ -33,7 +34,7 @@ public class DropLimitCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { int dropCount = c.getPlayer().getMap().getDroppedItemCount(); if (((float) dropCount) / YamlConfig.config.server.ITEM_LIMIT_ON_MAP < 0.75f) { c.getPlayer().showHint("Current drop count: #b" + dropCount + "#k / #e" + YamlConfig.config.server.ITEM_LIMIT_ON_MAP + "#n", 300); diff --git a/src/main/java/client/command/commands/gm0/EnableAuthCommand.java b/src/main/java/client/command/commands/gm0/EnableAuthCommand.java index 5ce7e716928..25bcad49c4d 100644 --- a/src/main/java/client/command/commands/gm0/EnableAuthCommand.java +++ b/src/main/java/client/command/commands/gm0/EnableAuthCommand.java @@ -25,6 +25,7 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.coordinator.login.LoginBypassCoordinator; public class EnableAuthCommand extends Command { @@ -33,7 +34,7 @@ public class EnableAuthCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { if (c.tryacquireClient()) { try { LoginBypassCoordinator.getInstance().unregisterLoginBypassEntry(c.getHwid(), c.getAccID()); diff --git a/src/main/java/client/command/commands/gm0/EquipLvCommand.java b/src/main/java/client/command/commands/gm0/EquipLvCommand.java index beafd307df2..238ac3277f5 100644 --- a/src/main/java/client/command/commands/gm0/EquipLvCommand.java +++ b/src/main/java/client/command/commands/gm0/EquipLvCommand.java @@ -25,6 +25,7 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; public class EquipLvCommand extends Command { { @@ -32,7 +33,7 @@ public class EquipLvCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { c.getPlayer().showAllEquipFeatures(); } } diff --git a/src/main/java/client/command/commands/gm0/GachaCommand.java b/src/main/java/client/command/commands/gm0/GachaCommand.java index 86cf37f552a..d3292ce1b62 100644 --- a/src/main/java/client/command/commands/gm0/GachaCommand.java +++ b/src/main/java/client/command/commands/gm0/GachaCommand.java @@ -25,6 +25,7 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.id.NpcId; import server.ItemInformationProvider; import server.gachapon.Gachapon; @@ -35,7 +36,7 @@ public class GachaCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Gachapon.GachaponType gacha = null; String search = c.getPlayer().getLastCommandMessage(); String gachaName = ""; diff --git a/src/main/java/client/command/commands/gm0/GmCommand.java b/src/main/java/client/command/commands/gm0/GmCommand.java index 5d24133717b..32b881ebbf6 100644 --- a/src/main/java/client/command/commands/gm0/GmCommand.java +++ b/src/main/java/client/command/commands/gm0/GmCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.Server; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -40,7 +41,7 @@ public class GmCommand extends Command { private static final Logger log = LoggerFactory.getLogger(GmCommand.class); @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { String[] tips = { "Please only use @gm in emergencies or to report somebody.", "To report a bug or make a suggestion, use the forum.", diff --git a/src/main/java/client/command/commands/gm0/HelpCommand.java b/src/main/java/client/command/commands/gm0/HelpCommand.java index b8f94e50c80..c24fc8ba620 100644 --- a/src/main/java/client/command/commands/gm0/HelpCommand.java +++ b/src/main/java/client/command/commands/gm0/HelpCommand.java @@ -25,15 +25,19 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.id.NpcId; +import java.util.Map; + public class HelpCommand extends Command { { setDescription("Show available commands."); } @Override - public void execute(Client client, String[] params) { - client.getAbstractPlayerInteraction().openNpc(NpcId.STEWARD, "commands"); + public void execute(Client client, String[] params, CommandContext ctx) { + Map bindings = Map.of("ce", ctx.commandsExecutor()); + client.getAbstractPlayerInteraction().openNpc(NpcId.STEWARD, "commands", bindings); } } diff --git a/src/main/java/client/command/commands/gm0/JoinEventCommand.java b/src/main/java/client/command/commands/gm0/JoinEventCommand.java index 5459d709193..1efcea57da3 100644 --- a/src/main/java/client/command/commands/gm0/JoinEventCommand.java +++ b/src/main/java/client/command/commands/gm0/JoinEventCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.id.MapId; import server.events.gm.Event; import server.maps.FieldLimit; @@ -36,7 +37,7 @@ public class JoinEventCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (!FieldLimit.CANNOTMIGRATE.check(player.getMap().getFieldLimit())) { Event event = c.getChannelServer().getEvent(); diff --git a/src/main/java/client/command/commands/gm0/LeaveEventCommand.java b/src/main/java/client/command/commands/gm0/LeaveEventCommand.java index 496b3917b28..44568bc02c5 100644 --- a/src/main/java/client/command/commands/gm0/LeaveEventCommand.java +++ b/src/main/java/client/command/commands/gm0/LeaveEventCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class LeaveEventCommand extends Command { { @@ -33,7 +34,7 @@ public class LeaveEventCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); int returnMap = player.getSavedLocation("EVENT"); if (returnMap != -1) { diff --git a/src/main/java/client/command/commands/gm0/MapOwnerClaimCommand.java b/src/main/java/client/command/commands/gm0/MapOwnerClaimCommand.java index 8ff939a21a9..cf4fffbc0d3 100644 --- a/src/main/java/client/command/commands/gm0/MapOwnerClaimCommand.java +++ b/src/main/java/client/command/commands/gm0/MapOwnerClaimCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import config.YamlConfig; import server.maps.MapleMap; @@ -35,7 +36,7 @@ public class MapOwnerClaimCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { if (c.tryacquireClient()) { try { Character chr = c.getPlayer(); diff --git a/src/main/java/client/command/commands/gm0/OnlineCommand.java b/src/main/java/client/command/commands/gm0/OnlineCommand.java index 1b9a2f7e104..d89e9093259 100644 --- a/src/main/java/client/command/commands/gm0/OnlineCommand.java +++ b/src/main/java/client/command/commands/gm0/OnlineCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.Server; import net.server.channel.Channel; @@ -35,7 +36,7 @@ public class OnlineCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); for (Channel ch : Server.getInstance().getChannelsFromWorld(player.getWorld())) { player.yellowMessage("Players in Channel " + ch.getId() + ":"); diff --git a/src/main/java/client/command/commands/gm0/RanksCommand.java b/src/main/java/client/command/commands/gm0/RanksCommand.java index 3fc18572051..b4650470f68 100644 --- a/src/main/java/client/command/commands/gm0/RanksCommand.java +++ b/src/main/java/client/command/commands/gm0/RanksCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.id.NpcId; import net.server.Server; import net.server.guild.GuildPackets; @@ -39,7 +40,7 @@ public class RanksCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); List> worldRanking = Server.getInstance().getWorldPlayerRanking(player.getWorld()); diff --git a/src/main/java/client/command/commands/gm0/RatesCommand.java b/src/main/java/client/command/commands/gm0/RatesCommand.java index 95181d6dcf4..5f8c486ebbf 100644 --- a/src/main/java/client/command/commands/gm0/RatesCommand.java +++ b/src/main/java/client/command/commands/gm0/RatesCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import config.YamlConfig; public class RatesCommand extends Command { @@ -34,7 +35,7 @@ public class RatesCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); // travel rates not applicable since it's intrinsically a server/environment rate rather than a character rate diff --git a/src/main/java/client/command/commands/gm0/ReadPointsCommand.java b/src/main/java/client/command/commands/gm0/ReadPointsCommand.java deleted file mode 100644 index e71afb2269b..00000000000 --- a/src/main/java/client/command/commands/gm0/ReadPointsCommand.java +++ /dev/null @@ -1,38 +0,0 @@ -package client.command.commands.gm0; - -import client.Character; -import client.Client; -import client.command.Command; - -public class ReadPointsCommand extends Command { - { - setDescription("Show point total."); - } - - @Override - public void execute(Client client, String[] params) { - - Character player = client.getPlayer(); - if (params.length > 2) { - player.yellowMessage("Syntax: @points (rp|vp|all)"); - return; - } else if (params.length == 0) { - player.yellowMessage("RewardPoints: " + player.getRewardPoints() + " | " - + "VotePoints: " + player.getClient().getVotePoints()); - return; - } - - switch (params[0]) { - case "rp": - player.yellowMessage("RewardPoints: " + player.getRewardPoints()); - break; - case "vp": - player.yellowMessage("VotePoints: " + player.getClient().getVotePoints()); - break; - default: - player.yellowMessage("RewardPoints: " + player.getRewardPoints() + " | " - + "VotePoints: " + player.getClient().getVotePoints()); - break; - } - } -} \ No newline at end of file diff --git a/src/main/java/client/command/commands/gm0/ReportBugCommand.java b/src/main/java/client/command/commands/gm0/ReportBugCommand.java index 53e35013dbe..09147506285 100644 --- a/src/main/java/client/command/commands/gm0/ReportBugCommand.java +++ b/src/main/java/client/command/commands/gm0/ReportBugCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.Server; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -39,7 +40,7 @@ public class ReportBugCommand extends Command { private static final Logger log = LoggerFactory.getLogger(ReportBugCommand.class); @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { diff --git a/src/main/java/client/command/commands/gm0/ShowRatesCommand.java b/src/main/java/client/command/commands/gm0/ShowRatesCommand.java index 3a14f49e0fd..20dd12cc906 100644 --- a/src/main/java/client/command/commands/gm0/ShowRatesCommand.java +++ b/src/main/java/client/command/commands/gm0/ShowRatesCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import config.YamlConfig; public class ShowRatesCommand extends Command { @@ -34,7 +35,7 @@ public class ShowRatesCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); String showMsg = "#eEXP RATE#n" + "\r\n"; showMsg += "World EXP Rate: #k" + c.getWorldServer().getExpRate() + "x#k" + "\r\n"; diff --git a/src/main/java/client/command/commands/gm0/StaffCommand.java b/src/main/java/client/command/commands/gm0/StaffCommand.java index 3209342431c..4fb57c92c46 100644 --- a/src/main/java/client/command/commands/gm0/StaffCommand.java +++ b/src/main/java/client/command/commands/gm0/StaffCommand.java @@ -25,6 +25,7 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.id.NpcId; public class StaffCommand extends Command { @@ -33,7 +34,7 @@ public class StaffCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { c.getAbstractPlayerInteraction().openNpc(NpcId.HERACLE, "credits"); } } diff --git a/src/main/java/client/command/commands/gm0/StatDexCommand.java b/src/main/java/client/command/commands/gm0/StatDexCommand.java index 59660c1a9bb..b2bb97cf308 100644 --- a/src/main/java/client/command/commands/gm0/StatDexCommand.java +++ b/src/main/java/client/command/commands/gm0/StatDexCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import config.YamlConfig; public class StatDexCommand extends Command { @@ -34,7 +35,7 @@ public class StatDexCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); int remainingAp = player.getRemainingAp(); diff --git a/src/main/java/client/command/commands/gm0/StatIntCommand.java b/src/main/java/client/command/commands/gm0/StatIntCommand.java index abfb761e717..42092e605e5 100644 --- a/src/main/java/client/command/commands/gm0/StatIntCommand.java +++ b/src/main/java/client/command/commands/gm0/StatIntCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import config.YamlConfig; public class StatIntCommand extends Command { @@ -34,7 +35,7 @@ public class StatIntCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); int remainingAp = player.getRemainingAp(); diff --git a/src/main/java/client/command/commands/gm0/StatLukCommand.java b/src/main/java/client/command/commands/gm0/StatLukCommand.java index 20cab06e2d0..308d7296e76 100644 --- a/src/main/java/client/command/commands/gm0/StatLukCommand.java +++ b/src/main/java/client/command/commands/gm0/StatLukCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import config.YamlConfig; public class StatLukCommand extends Command { @@ -34,7 +35,7 @@ public class StatLukCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); int remainingAp = player.getRemainingAp(); diff --git a/src/main/java/client/command/commands/gm0/StatStrCommand.java b/src/main/java/client/command/commands/gm0/StatStrCommand.java index 2c8b7eaf840..576a4102f5c 100644 --- a/src/main/java/client/command/commands/gm0/StatStrCommand.java +++ b/src/main/java/client/command/commands/gm0/StatStrCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import config.YamlConfig; public class StatStrCommand extends Command { @@ -34,7 +35,7 @@ public class StatStrCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); int remainingAp = player.getRemainingAp(); int amount; diff --git a/src/main/java/client/command/commands/gm0/TimeCommand.java b/src/main/java/client/command/commands/gm0/TimeCommand.java index 22a3502ee98..e84b3527b81 100644 --- a/src/main/java/client/command/commands/gm0/TimeCommand.java +++ b/src/main/java/client/command/commands/gm0/TimeCommand.java @@ -25,6 +25,7 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; import java.text.DateFormat; import java.text.SimpleDateFormat; @@ -37,7 +38,7 @@ public class TimeCommand extends Command { } @Override - public void execute(Client client, String[] params) { + public void execute(Client client, String[] params, CommandContext ctx) { DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); dateFormat.setTimeZone(TimeZone.getDefault()); client.getPlayer().yellowMessage("Cosmic Server Time: " + dateFormat.format(new Date())); diff --git a/src/main/java/client/command/commands/gm0/ToggleExpCommand.java b/src/main/java/client/command/commands/gm0/ToggleExpCommand.java index 42ff35c9dba..0a48f84f279 100644 --- a/src/main/java/client/command/commands/gm0/ToggleExpCommand.java +++ b/src/main/java/client/command/commands/gm0/ToggleExpCommand.java @@ -25,6 +25,7 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; public class ToggleExpCommand extends Command { { @@ -32,7 +33,7 @@ public class ToggleExpCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { if (c.tryacquireClient()) { try { c.getPlayer().toggleExpGain(); // Vcoc's idea diff --git a/src/main/java/client/command/commands/gm0/UptimeCommand.java b/src/main/java/client/command/commands/gm0/UptimeCommand.java index 8080a4d41bb..fc814bb3f19 100644 --- a/src/main/java/client/command/commands/gm0/UptimeCommand.java +++ b/src/main/java/client/command/commands/gm0/UptimeCommand.java @@ -25,6 +25,7 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.Server; import static java.util.concurrent.TimeUnit.DAYS; @@ -38,7 +39,7 @@ public class UptimeCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { long milliseconds = System.currentTimeMillis() - Server.uptime; int seconds = (int) (milliseconds / SECONDS.toMillis(1)) % 60; int minutes = (int) ((milliseconds / MINUTES.toMillis(1)) % 60); diff --git a/src/main/java/client/command/commands/gm1/BossHpCommand.java b/src/main/java/client/command/commands/gm1/BossHpCommand.java index 4156cfd25c3..779369f4cfd 100644 --- a/src/main/java/client/command/commands/gm1/BossHpCommand.java +++ b/src/main/java/client/command/commands/gm1/BossHpCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.life.Monster; public class BossHpCommand extends Command { @@ -34,7 +35,7 @@ public class BossHpCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); for (Monster monster : player.getMap().getAllMonsters()) { if (monster != null && monster.isBoss() && monster.getHp() > 0) { diff --git a/src/main/java/client/command/commands/gm1/BuffMeCommand.java b/src/main/java/client/command/commands/gm1/BuffMeCommand.java index ce2afba245b..fa69c50314b 100644 --- a/src/main/java/client/command/commands/gm1/BuffMeCommand.java +++ b/src/main/java/client/command/commands/gm1/BuffMeCommand.java @@ -27,6 +27,7 @@ import client.Client; import client.SkillFactory; import client.command.Command; +import client.command.CommandContext; public class BuffMeCommand extends Command { { @@ -34,7 +35,7 @@ public class BuffMeCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); SkillFactory.getSkill(4101004).getEffect(SkillFactory.getSkill(4101004).getMaxLevel()).applyTo(player); SkillFactory.getSkill(2311003).getEffect(SkillFactory.getSkill(2311003).getMaxLevel()).applyTo(player); diff --git a/src/main/java/client/command/commands/gm1/GotoCommand.java b/src/main/java/client/command/commands/gm1/GotoCommand.java index dfbf0c61052..5614f5613fa 100644 --- a/src/main/java/client/command/commands/gm1/GotoCommand.java +++ b/src/main/java/client/command/commands/gm1/GotoCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.game.GameConstants; import constants.id.NpcId; import server.maps.FieldLimit; @@ -77,7 +78,7 @@ private static void sortGotoEntries(List> listEntries) { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { String sendStr = "Syntax: #b@goto #k. Available areas:\r\n\r\n#rTowns:#k\r\n" + GOTO_TOWNS_INFO; diff --git a/src/main/java/client/command/commands/gm1/MobHpCommand.java b/src/main/java/client/command/commands/gm1/MobHpCommand.java index ee9310eadab..8617bf88f25 100644 --- a/src/main/java/client/command/commands/gm1/MobHpCommand.java +++ b/src/main/java/client/command/commands/gm1/MobHpCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.life.Monster; public class MobHpCommand extends Command { @@ -34,7 +35,7 @@ public class MobHpCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); for (Monster monster : player.getMap().getAllMonsters()) { if (monster != null && monster.getHp() > 0) { diff --git a/src/main/java/client/command/commands/gm1/WhatDropsFromCommand.java b/src/main/java/client/command/commands/gm1/WhatDropsFromCommand.java index 111d5ce6eea..7772f17b8e4 100644 --- a/src/main/java/client/command/commands/gm1/WhatDropsFromCommand.java +++ b/src/main/java/client/command/commands/gm1/WhatDropsFromCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.id.NpcId; import server.ItemInformationProvider; import server.life.MonsterDropEntry; @@ -40,7 +41,7 @@ public class WhatDropsFromCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.dropMessage(5, "Please do @whatdropsfrom "); @@ -56,7 +57,7 @@ public void execute(Client c, String[] params) { int mobId = data.getLeft(); String mobName = data.getRight(); output += mobName + " drops the following items:\r\n\r\n"; - for (MonsterDropEntry drop : MonsterInformationProvider.getInstance().retrieveDrop(mobId)) { + for (MonsterDropEntry drop : ctx.dropProvider().getMonsterDropEntries(mobId)) { try { String name = ItemInformationProvider.getInstance().getName(drop.itemId); if (name == null || name.equals("null") || drop.chance == 0) { diff --git a/src/main/java/client/command/commands/gm1/WhoDropsCommand.java b/src/main/java/client/command/commands/gm1/WhoDropsCommand.java index 1c27c8c9b02..6ac3d0bdea7 100644 --- a/src/main/java/client/command/commands/gm1/WhoDropsCommand.java +++ b/src/main/java/client/command/commands/gm1/WhoDropsCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.id.NpcId; import server.ItemInformationProvider; import server.life.MonsterInformationProvider; @@ -43,7 +44,7 @@ public class WhoDropsCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.dropMessage(5, "Please do @whodrops "); diff --git a/src/main/java/client/command/commands/gm2/ApCommand.java b/src/main/java/client/command/commands/gm2/ApCommand.java index 83068f8f01c..a8096490f11 100644 --- a/src/main/java/client/command/commands/gm2/ApCommand.java +++ b/src/main/java/client/command/commands/gm2/ApCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import config.YamlConfig; public class ApCommand extends Command { @@ -34,7 +35,7 @@ public class ApCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !ap [] "); diff --git a/src/main/java/client/command/commands/gm2/BombCommand.java b/src/main/java/client/command/commands/gm2/BombCommand.java index aa609bfefb0..c58dce81983 100644 --- a/src/main/java/client/command/commands/gm2/BombCommand.java +++ b/src/main/java/client/command/commands/gm2/BombCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.id.MobId; import net.server.Server; import server.life.LifeFactory; @@ -37,7 +38,7 @@ public class BombCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length > 0) { Character victim = c.getWorldServer().getPlayerStorage().getCharacterByName(params[0]); diff --git a/src/main/java/client/command/commands/gm2/BuffCommand.java b/src/main/java/client/command/commands/gm2/BuffCommand.java index a6033bb43cc..e5c368e450e 100644 --- a/src/main/java/client/command/commands/gm2/BuffCommand.java +++ b/src/main/java/client/command/commands/gm2/BuffCommand.java @@ -28,6 +28,7 @@ import client.Skill; import client.SkillFactory; import client.command.Command; +import client.command.CommandContext; public class BuffCommand extends Command { { @@ -35,7 +36,7 @@ public class BuffCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !buff "); diff --git a/src/main/java/client/command/commands/gm2/BuffMapCommand.java b/src/main/java/client/command/commands/gm2/BuffMapCommand.java index c1433d30c87..c5dd6cd19d8 100644 --- a/src/main/java/client/command/commands/gm2/BuffMapCommand.java +++ b/src/main/java/client/command/commands/gm2/BuffMapCommand.java @@ -27,6 +27,7 @@ import client.Client; import client.SkillFactory; import client.command.Command; +import client.command.CommandContext; public class BuffMapCommand extends Command { { @@ -34,7 +35,7 @@ public class BuffMapCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); SkillFactory.getSkill(9101001).getEffect(SkillFactory.getSkill(9101001).getMaxLevel()).applyTo(player, true); SkillFactory.getSkill(9101002).getEffect(SkillFactory.getSkill(9101002).getMaxLevel()).applyTo(player, true); diff --git a/src/main/java/client/command/commands/gm2/ClearDropsCommand.java b/src/main/java/client/command/commands/gm2/ClearDropsCommand.java index 05c8e009faa..382c404ce96 100644 --- a/src/main/java/client/command/commands/gm2/ClearDropsCommand.java +++ b/src/main/java/client/command/commands/gm2/ClearDropsCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class ClearDropsCommand extends Command { { @@ -33,7 +34,7 @@ public class ClearDropsCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); player.getMap().clearDrops(player); player.dropMessage(5, "Cleared dropped items"); diff --git a/src/main/java/client/command/commands/gm2/ClearSavedLocationsCommand.java b/src/main/java/client/command/commands/gm2/ClearSavedLocationsCommand.java index 0a5a87bdcc9..8f78e8c6a93 100644 --- a/src/main/java/client/command/commands/gm2/ClearSavedLocationsCommand.java +++ b/src/main/java/client/command/commands/gm2/ClearSavedLocationsCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.maps.SavedLocationType; public class ClearSavedLocationsCommand extends Command { @@ -34,7 +35,7 @@ public class ClearSavedLocationsCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(), victim; if (params.length > 0) { diff --git a/src/main/java/client/command/commands/gm2/ClearSlotCommand.java b/src/main/java/client/command/commands/gm2/ClearSlotCommand.java index 63f31350730..8625fa72006 100644 --- a/src/main/java/client/command/commands/gm2/ClearSlotCommand.java +++ b/src/main/java/client/command/commands/gm2/ClearSlotCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import client.inventory.InventoryType; import client.inventory.Item; import client.inventory.manipulator.InventoryManipulator; @@ -36,7 +37,7 @@ public class ClearSlotCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !clearslot "); diff --git a/src/main/java/client/command/commands/gm2/DcCommand.java b/src/main/java/client/command/commands/gm2/DcCommand.java index 1ae5f093d37..8bf4d276142 100644 --- a/src/main/java/client/command/commands/gm2/DcCommand.java +++ b/src/main/java/client/command/commands/gm2/DcCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class DcCommand extends Command { { @@ -33,21 +34,22 @@ public class DcCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !dc "); return; } - Character victim = c.getWorldServer().getPlayerStorage().getCharacterByName(params[0]); + String chrName = params[0]; + Character victim = c.getWorldServer().getPlayerStorage().getCharacterByName(chrName); if (victim == null) { - victim = c.getChannelServer().getPlayerStorage().getCharacterByName(params[0]); + victim = c.getChannelServer().getPlayerStorage().getCharacterByName(chrName); if (victim == null) { - victim = player.getMap().getCharacterByName(params[0]); + victim = player.getMap().getCharacterByName(chrName); if (victim != null) { try {//sometimes bugged because the map = null - victim.getClient().disconnect(true, false); + ctx.transitionService().disconnect(victim.getClient(), true); player.getMap().removePlayer(victim); } catch (Exception e) { e.printStackTrace(); @@ -60,6 +62,6 @@ public void execute(Client c, String[] params) { if (player.gmLevel() < victim.gmLevel()) { victim = player; } - victim.getClient().disconnect(false, false); + ctx.transitionService().disconnect(victim.getClient(), false); } } diff --git a/src/main/java/client/command/commands/gm2/EmpowerMeCommand.java b/src/main/java/client/command/commands/gm2/EmpowerMeCommand.java index 58c52b9b479..357dbe61bd1 100644 --- a/src/main/java/client/command/commands/gm2/EmpowerMeCommand.java +++ b/src/main/java/client/command/commands/gm2/EmpowerMeCommand.java @@ -27,6 +27,7 @@ import client.Client; import client.SkillFactory; import client.command.Command; +import client.command.CommandContext; public class EmpowerMeCommand extends Command { { @@ -34,7 +35,7 @@ public class EmpowerMeCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); final int[] array = {2311003, 2301004, 1301007, 4101004, 2001002, 1101007, 1005, 2301003, 5121009, 1111002, 4111001, 4111002, 4211003, 4211005, 1321000, 2321004, 3121002}; for (int i : array) { diff --git a/src/main/java/client/command/commands/gm2/GachaListCommand.java b/src/main/java/client/command/commands/gm2/GachaListCommand.java index 805f550e532..54c45d095da 100644 --- a/src/main/java/client/command/commands/gm2/GachaListCommand.java +++ b/src/main/java/client/command/commands/gm2/GachaListCommand.java @@ -21,6 +21,7 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; /** * @author Ronan @@ -31,7 +32,7 @@ public class GachaListCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { c.getAbstractPlayerInteraction().openNpc(10000, "gachaponInfo"); } } diff --git a/src/main/java/client/command/commands/gm2/GmShopCommand.java b/src/main/java/client/command/commands/gm2/GmShopCommand.java index ea286f32618..74504400533 100644 --- a/src/main/java/client/command/commands/gm2/GmShopCommand.java +++ b/src/main/java/client/command/commands/gm2/GmShopCommand.java @@ -25,15 +25,17 @@ import client.Client; import client.command.Command; -import server.ShopFactory; +import client.command.CommandContext; public class GmShopCommand extends Command { { setDescription("Open the GM shop."); } + private static final int GM_SHOP_ID = 1337; + @Override - public void execute(Client c, String[] params) { - ShopFactory.getInstance().getShop(1337).sendShop(c); + public void execute(Client c, String[] params, CommandContext ctx) { + ctx.shopFactory().getShop(GM_SHOP_ID).ifPresent(shop -> shop.sendShop(c)); } } diff --git a/src/main/java/client/command/commands/gm2/HealCommand.java b/src/main/java/client/command/commands/gm2/HealCommand.java index 620c7ddf062..5f09030ec4f 100644 --- a/src/main/java/client/command/commands/gm2/HealCommand.java +++ b/src/main/java/client/command/commands/gm2/HealCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class HealCommand extends Command { { @@ -33,7 +34,7 @@ public class HealCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); player.healHpMp(); } diff --git a/src/main/java/client/command/commands/gm2/HideCommand.java b/src/main/java/client/command/commands/gm2/HideCommand.java index 33a5f9b2c38..9f256f6d9f8 100644 --- a/src/main/java/client/command/commands/gm2/HideCommand.java +++ b/src/main/java/client/command/commands/gm2/HideCommand.java @@ -27,6 +27,7 @@ import client.Client; import client.SkillFactory; import client.command.Command; +import client.command.CommandContext; public class HideCommand extends Command { { @@ -34,7 +35,7 @@ public class HideCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); SkillFactory.getSkill(9101004).getEffect(SkillFactory.getSkill(9101004).getMaxLevel()).applyTo(player); diff --git a/src/main/java/client/command/commands/gm2/IdCommand.java b/src/main/java/client/command/commands/gm2/IdCommand.java index 36d119b8a1e..8c36df41f89 100644 --- a/src/main/java/client/command/commands/gm2/IdCommand.java +++ b/src/main/java/client/command/commands/gm2/IdCommand.java @@ -3,6 +3,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.game.NpcChat; import constants.id.NpcId; import server.ThreadManager; @@ -86,7 +87,7 @@ public boolean matches(String query) { } @Override - public void execute(Client client, final String[] params) { + public void execute(Client client, final String[] params, CommandContext ctx) { final Character chr = client.getPlayer(); if (params.length < 2) { chr.yellowMessage("Syntax: !id "); diff --git a/src/main/java/client/command/commands/gm2/ItemCommand.java b/src/main/java/client/command/commands/gm2/ItemCommand.java index d74f47b1d21..92095ba19de 100644 --- a/src/main/java/client/command/commands/gm2/ItemCommand.java +++ b/src/main/java/client/command/commands/gm2/ItemCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import client.inventory.Pet; import client.inventory.manipulator.InventoryManipulator; import config.YamlConfig; @@ -40,7 +41,7 @@ public class ItemCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { diff --git a/src/main/java/client/command/commands/gm2/ItemDropCommand.java b/src/main/java/client/command/commands/gm2/ItemDropCommand.java index ff065c651fd..5ce00ce4c4d 100644 --- a/src/main/java/client/command/commands/gm2/ItemDropCommand.java +++ b/src/main/java/client/command/commands/gm2/ItemDropCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import client.inventory.InventoryType; import client.inventory.Item; import client.inventory.Pet; @@ -41,7 +42,7 @@ public class ItemDropCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { diff --git a/src/main/java/client/command/commands/gm2/JailCommand.java b/src/main/java/client/command/commands/gm2/JailCommand.java index 671199d1e3d..2a1b98afa89 100644 --- a/src/main/java/client/command/commands/gm2/JailCommand.java +++ b/src/main/java/client/command/commands/gm2/JailCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.id.MapId; import server.maps.MapleMap; import server.maps.Portal; @@ -38,7 +39,7 @@ public class JailCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !jail []"); diff --git a/src/main/java/client/command/commands/gm2/JobCommand.java b/src/main/java/client/command/commands/gm2/JobCommand.java index c233499e404..e3c65ab70b9 100644 --- a/src/main/java/client/command/commands/gm2/JobCommand.java +++ b/src/main/java/client/command/commands/gm2/JobCommand.java @@ -27,6 +27,7 @@ import client.Client; import client.Job; import client.command.Command; +import client.command.CommandContext; public class JobCommand extends Command { { @@ -34,7 +35,7 @@ public class JobCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length == 1) { int jobid = Integer.parseInt(params[0]); diff --git a/src/main/java/client/command/commands/gm2/LevelCommand.java b/src/main/java/client/command/commands/gm2/LevelCommand.java index b0846be4eba..a7812c1a53e 100644 --- a/src/main/java/client/command/commands/gm2/LevelCommand.java +++ b/src/main/java/client/command/commands/gm2/LevelCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import config.YamlConfig; public class LevelCommand extends Command { @@ -34,7 +35,7 @@ public class LevelCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !level "); diff --git a/src/main/java/client/command/commands/gm2/LevelProCommand.java b/src/main/java/client/command/commands/gm2/LevelProCommand.java index 20afd63b502..1f3446c936a 100644 --- a/src/main/java/client/command/commands/gm2/LevelProCommand.java +++ b/src/main/java/client/command/commands/gm2/LevelProCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class LevelProCommand extends Command { { @@ -33,7 +34,7 @@ public class LevelProCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !levelpro "); diff --git a/src/main/java/client/command/commands/gm2/LootCommand.java b/src/main/java/client/command/commands/gm2/LootCommand.java index 6ad115e34de..7cc6cf210a0 100644 --- a/src/main/java/client/command/commands/gm2/LootCommand.java +++ b/src/main/java/client/command/commands/gm2/LootCommand.java @@ -25,6 +25,7 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; import server.maps.MapItem; import server.maps.MapObject; import server.maps.MapObjectType; @@ -39,7 +40,7 @@ public class LootCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { List items = c.getPlayer().getMap().getMapObjectsInRange(c.getPlayer().getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapObjectType.ITEM)); for (MapObject item : items) { MapItem mapItem = (MapItem) item; diff --git a/src/main/java/client/command/commands/gm2/MaxSkillCommand.java b/src/main/java/client/command/commands/gm2/MaxSkillCommand.java index 8f1ffbd9a61..a498fd271ae 100644 --- a/src/main/java/client/command/commands/gm2/MaxSkillCommand.java +++ b/src/main/java/client/command/commands/gm2/MaxSkillCommand.java @@ -29,6 +29,7 @@ import client.Skill; import client.SkillFactory; import client.command.Command; +import client.command.CommandContext; import provider.Data; import provider.DataProviderFactory; import provider.wz.WZFiles; @@ -39,7 +40,7 @@ public class MaxSkillCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); for (Data skill_ : DataProviderFactory.getDataProvider(WZFiles.STRING).getData("Skill.img").getChildren()) { try { diff --git a/src/main/java/client/command/commands/gm2/MaxStatCommand.java b/src/main/java/client/command/commands/gm2/MaxStatCommand.java index f3e7dd1c8bc..464fb79b1cf 100644 --- a/src/main/java/client/command/commands/gm2/MaxStatCommand.java +++ b/src/main/java/client/command/commands/gm2/MaxStatCommand.java @@ -27,6 +27,7 @@ import client.Client; import client.Stat; import client.command.Command; +import client.command.CommandContext; import config.YamlConfig; public class MaxStatCommand extends Command { @@ -35,7 +36,7 @@ public class MaxStatCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); player.loseExp(player.getExp(), false, false); player.setLevel(255); diff --git a/src/main/java/client/command/commands/gm2/MobSkillCommand.java b/src/main/java/client/command/commands/gm2/MobSkillCommand.java index d5adbdf0b35..60ace9f92a0 100644 --- a/src/main/java/client/command/commands/gm2/MobSkillCommand.java +++ b/src/main/java/client/command/commands/gm2/MobSkillCommand.java @@ -3,6 +3,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.life.MobSkill; import server.life.MobSkillFactory; import server.life.MobSkillType; @@ -16,7 +17,7 @@ public class MobSkillCommand extends Command { } @Override - public void execute(Client client, String[] params) { + public void execute(Client client, String[] params, CommandContext ctx) { if (params.length < 2) { throw new IllegalArgumentException("Mob skill command requires two args: mob skill id and level"); } diff --git a/src/main/java/client/command/commands/gm2/ReachCommand.java b/src/main/java/client/command/commands/gm2/ReachCommand.java index 41b3bb3a6b1..113889600d2 100644 --- a/src/main/java/client/command/commands/gm2/ReachCommand.java +++ b/src/main/java/client/command/commands/gm2/ReachCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.maps.MapleMap; public class ReachCommand extends Command { @@ -34,7 +35,7 @@ public class ReachCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !reach "); diff --git a/src/main/java/client/command/commands/gm2/RechargeCommand.java b/src/main/java/client/command/commands/gm2/RechargeCommand.java index 3aaa23bb0e9..c138f3a5c3b 100644 --- a/src/main/java/client/command/commands/gm2/RechargeCommand.java +++ b/src/main/java/client/command/commands/gm2/RechargeCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import client.inventory.InventoryType; import client.inventory.Item; import constants.inventory.ItemConstants; @@ -37,7 +38,7 @@ public class RechargeCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); ItemInformationProvider ii = ItemInformationProvider.getInstance(); for (Item torecharge : c.getPlayer().getInventory(InventoryType.USE).list()) { diff --git a/src/main/java/client/command/commands/gm2/ResetSkillCommand.java b/src/main/java/client/command/commands/gm2/ResetSkillCommand.java index db578291ac1..99dca91af83 100644 --- a/src/main/java/client/command/commands/gm2/ResetSkillCommand.java +++ b/src/main/java/client/command/commands/gm2/ResetSkillCommand.java @@ -29,6 +29,7 @@ import client.Skill; import client.SkillFactory; import client.command.Command; +import client.command.CommandContext; import provider.Data; import provider.DataProviderFactory; import provider.wz.WZFiles; @@ -39,7 +40,7 @@ public class ResetSkillCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); for (Data skill_ : DataProviderFactory.getDataProvider(WZFiles.STRING).getData("Skill.img").getChildren()) { try { diff --git a/src/main/java/client/command/commands/gm2/SearchCommand.java b/src/main/java/client/command/commands/gm2/SearchCommand.java index 3ce506185d7..9766be8924b 100644 --- a/src/main/java/client/command/commands/gm2/SearchCommand.java +++ b/src/main/java/client/command/commands/gm2/SearchCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.id.NpcId; import provider.Data; import provider.DataProvider; @@ -53,7 +54,7 @@ public class SearchCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 2) { player.yellowMessage("Syntax: !search "); diff --git a/src/main/java/client/command/commands/gm2/SetSlotCommand.java b/src/main/java/client/command/commands/gm2/SetSlotCommand.java index fd8124e2de4..dab5b1d8dc2 100644 --- a/src/main/java/client/command/commands/gm2/SetSlotCommand.java +++ b/src/main/java/client/command/commands/gm2/SetSlotCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class SetSlotCommand extends Command { { @@ -33,7 +34,7 @@ public class SetSlotCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !setslot "); diff --git a/src/main/java/client/command/commands/gm2/SetStatCommand.java b/src/main/java/client/command/commands/gm2/SetStatCommand.java index 7eae82c123e..360fe0bd016 100644 --- a/src/main/java/client/command/commands/gm2/SetStatCommand.java +++ b/src/main/java/client/command/commands/gm2/SetStatCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class SetStatCommand extends Command { { @@ -33,7 +34,7 @@ public class SetStatCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !setstat "); diff --git a/src/main/java/client/command/commands/gm2/SpCommand.java b/src/main/java/client/command/commands/gm2/SpCommand.java index f905c21a7a3..c5dc98459ba 100644 --- a/src/main/java/client/command/commands/gm2/SpCommand.java +++ b/src/main/java/client/command/commands/gm2/SpCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import config.YamlConfig; public class SpCommand extends Command { @@ -34,7 +35,7 @@ public class SpCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !sp [] "); diff --git a/src/main/java/client/command/commands/gm2/SummonCommand.java b/src/main/java/client/command/commands/gm2/SummonCommand.java index b159a176e14..39d45979f6d 100644 --- a/src/main/java/client/command/commands/gm2/SummonCommand.java +++ b/src/main/java/client/command/commands/gm2/SummonCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.Server; import net.server.channel.Channel; import server.maps.MapleMap; @@ -36,7 +37,7 @@ public class SummonCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !warphere "); @@ -62,7 +63,7 @@ public void execute(Client c, String[] params) { if (player.getClient().getChannel() != victim.getClient().getChannel()) {//And then change channel if needed. victim.dropMessage("Changing channel, please wait a moment."); - victim.getClient().changeChannel(player.getClient().getChannel()); + ctx.transitionService().changeChannel(victim.getClient(), player.getClient().getChannel()); } try { diff --git a/src/main/java/client/command/commands/gm2/UnBugCommand.java b/src/main/java/client/command/commands/gm2/UnBugCommand.java index fb175c540d2..6863a191bc3 100644 --- a/src/main/java/client/command/commands/gm2/UnBugCommand.java +++ b/src/main/java/client/command/commands/gm2/UnBugCommand.java @@ -25,6 +25,7 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; import tools.PacketCreator; public class UnBugCommand extends Command { @@ -33,7 +34,7 @@ public class UnBugCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { c.getPlayer().getMap().broadcastMessage(PacketCreator.enableActions()); } } diff --git a/src/main/java/client/command/commands/gm2/UnHideCommand.java b/src/main/java/client/command/commands/gm2/UnHideCommand.java index 1e2cd29cef2..e036907226b 100644 --- a/src/main/java/client/command/commands/gm2/UnHideCommand.java +++ b/src/main/java/client/command/commands/gm2/UnHideCommand.java @@ -27,6 +27,7 @@ import client.Client; import client.SkillFactory; import client.command.Command; +import client.command.CommandContext; public class UnHideCommand extends Command { { @@ -34,7 +35,7 @@ public class UnHideCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); SkillFactory.getSkill(9101004).getEffect(SkillFactory.getSkill(9101004).getMaxLevel()).applyTo(player); diff --git a/src/main/java/client/command/commands/gm2/UnJailCommand.java b/src/main/java/client/command/commands/gm2/UnJailCommand.java index 41843f38e19..5e45dc9fef5 100644 --- a/src/main/java/client/command/commands/gm2/UnJailCommand.java +++ b/src/main/java/client/command/commands/gm2/UnJailCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class UnJailCommand extends Command { { @@ -33,7 +34,7 @@ public class UnJailCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !unjail "); diff --git a/src/main/java/client/command/commands/gm2/WarpAreaCommand.java b/src/main/java/client/command/commands/gm2/WarpAreaCommand.java index 8d3d986e5fa..3820b963531 100644 --- a/src/main/java/client/command/commands/gm2/WarpAreaCommand.java +++ b/src/main/java/client/command/commands/gm2/WarpAreaCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.maps.MapleMap; import java.awt.*; @@ -37,7 +38,7 @@ public class WarpAreaCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !warparea "); diff --git a/src/main/java/client/command/commands/gm2/WarpCommand.java b/src/main/java/client/command/commands/gm2/WarpCommand.java index 4f191a51969..4e238b90d75 100644 --- a/src/main/java/client/command/commands/gm2/WarpCommand.java +++ b/src/main/java/client/command/commands/gm2/WarpCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.maps.FieldLimit; import server.maps.MapleMap; import server.maps.MiniDungeonInfo; @@ -36,7 +37,7 @@ public class WarpCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !warp "); diff --git a/src/main/java/client/command/commands/gm2/WarpMapCommand.java b/src/main/java/client/command/commands/gm2/WarpMapCommand.java index 3e7c5ab5e17..d353f2b835e 100644 --- a/src/main/java/client/command/commands/gm2/WarpMapCommand.java +++ b/src/main/java/client/command/commands/gm2/WarpMapCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.maps.MapleMap; import java.util.Collection; @@ -36,7 +37,7 @@ public class WarpMapCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !warpmap "); diff --git a/src/main/java/client/command/commands/gm2/WhereaMiCommand.java b/src/main/java/client/command/commands/gm2/WhereaMiCommand.java index b4ddc29d9fb..7b4b56176e3 100644 --- a/src/main/java/client/command/commands/gm2/WhereaMiCommand.java +++ b/src/main/java/client/command/commands/gm2/WhereaMiCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.life.Monster; import server.life.NPC; import server.life.PlayerNPC; @@ -39,7 +40,7 @@ public class WhereaMiCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); HashSet chars = new HashSet<>(); diff --git a/src/main/java/client/command/commands/gm3/BanCommand.java b/src/main/java/client/command/commands/gm3/BanCommand.java index f24ff3316bb..031656200ed 100644 --- a/src/main/java/client/command/commands/gm3/BanCommand.java +++ b/src/main/java/client/command/commands/gm3/BanCommand.java @@ -26,14 +26,7 @@ import client.Character; import client.Client; import client.command.Command; -import net.server.Server; -import server.TimerManager; -import tools.DatabaseConnection; -import tools.PacketCreator; - -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; +import client.command.CommandContext; public class BanCommand extends Command { { @@ -41,7 +34,7 @@ public class BanCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 2) { player.yellowMessage("Syntax: !ban (Please be descriptive)"); @@ -49,39 +42,6 @@ public void execute(Client c, String[] params) { } String ign = params[0]; String reason = joinStringFrom(params, 1); - Character target = c.getChannelServer().getPlayerStorage().getCharacterByName(ign); - if (target != null) { - String readableTargetName = Character.makeMapleReadable(target.getName()); - String ip = target.getClient().getRemoteAddress(); - //Ban ip - try (Connection con = DatabaseConnection.getConnection()) { - if (ip.matches("/[0-9]{1,3}\\..*")) { - try (PreparedStatement ps = con.prepareStatement("INSERT INTO ipbans VALUES (DEFAULT, ?, ?)")) { - ps.setString(1, ip); - ps.setString(2, String.valueOf(target.getClient().getAccID())); - - ps.executeUpdate(); - } - } - } catch (SQLException ex) { - ex.printStackTrace(); - c.getPlayer().message("Error occured while banning IP address"); - c.getPlayer().message(target.getName() + "'s IP was not banned: " + ip); - } - target.getClient().banMacs(); - reason = c.getPlayer().getName() + " banned " + readableTargetName + " for " + reason + " (IP: " + ip + ") " + "(MAC: " + c.getMacs() + ")"; - target.ban(reason); - target.yellowMessage("You have been banned by #b" + c.getPlayer().getName() + " #k."); - target.yellowMessage("Reason: " + reason); - c.sendPacket(PacketCreator.getGMEffect(4, (byte) 0)); - final Character rip = target; - TimerManager.getInstance().schedule(() -> rip.getClient().disconnect(false, false), 5000); //5 Seconds - Server.getInstance().broadcastMessage(c.getWorld(), PacketCreator.serverNotice(6, "[RIP]: " + ign + " has been banned.")); - } else if (Character.ban(ign, reason, false)) { - c.sendPacket(PacketCreator.getGMEffect(4, (byte) 0)); - Server.getInstance().broadcastMessage(c.getWorld(), PacketCreator.serverNotice(6, "[RIP]: " + ign + " has been banned.")); - } else { - c.sendPacket(PacketCreator.getGMEffect(6, (byte) 1)); - } + ctx.banService().permaBan(c, ign, (byte) 0, reason); } } diff --git a/src/main/java/client/command/commands/gm3/ChatCommand.java b/src/main/java/client/command/commands/gm3/ChatCommand.java index 0ea9c366372..dc6e0041a4c 100644 --- a/src/main/java/client/command/commands/gm3/ChatCommand.java +++ b/src/main/java/client/command/commands/gm3/ChatCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class ChatCommand extends Command { { @@ -33,7 +34,7 @@ public class ChatCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); player.toggleWhiteChat(); player.message("Your chat is now " + (player.getWhiteChat() ? " white" : "normal") + "."); diff --git a/src/main/java/client/command/commands/gm3/CheckDmgCommand.java b/src/main/java/client/command/commands/gm3/CheckDmgCommand.java index 82ffe11cd0d..1aca8ea1589 100644 --- a/src/main/java/client/command/commands/gm3/CheckDmgCommand.java +++ b/src/main/java/client/command/commands/gm3/CheckDmgCommand.java @@ -27,6 +27,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class CheckDmgCommand extends Command { { @@ -34,7 +35,7 @@ public class CheckDmgCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); Character victim = c.getWorldServer().getPlayerStorage().getCharacterByName(params[0]); if (victim != null) { diff --git a/src/main/java/client/command/commands/gm3/ClosePortalCommand.java b/src/main/java/client/command/commands/gm3/ClosePortalCommand.java index 32f55c53c3d..9e4a8889e85 100644 --- a/src/main/java/client/command/commands/gm3/ClosePortalCommand.java +++ b/src/main/java/client/command/commands/gm3/ClosePortalCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class ClosePortalCommand extends Command { { @@ -33,7 +34,7 @@ public class ClosePortalCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !closeportal "); diff --git a/src/main/java/client/command/commands/gm3/DebuffCommand.java b/src/main/java/client/command/commands/gm3/DebuffCommand.java index dedc6d853ce..696618ee300 100644 --- a/src/main/java/client/command/commands/gm3/DebuffCommand.java +++ b/src/main/java/client/command/commands/gm3/DebuffCommand.java @@ -27,6 +27,7 @@ import client.Client; import client.Disease; import client.command.Command; +import client.command.CommandContext; import server.life.MobSkill; import server.life.MobSkillFactory; import server.life.MobSkillType; @@ -42,7 +43,7 @@ public class DebuffCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !debuff SLOW|SEDUCE|ZOMBIFY|CONFUSE|STUN|POISON|SEAL|DARKNESS|WEAKEN|CURSE"); diff --git a/src/main/java/client/command/commands/gm3/EndEventCommand.java b/src/main/java/client/command/commands/gm3/EndEventCommand.java index ceb13efd910..7b3b43cb82d 100644 --- a/src/main/java/client/command/commands/gm3/EndEventCommand.java +++ b/src/main/java/client/command/commands/gm3/EndEventCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class EndEventCommand extends Command { { @@ -33,7 +34,7 @@ public class EndEventCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); c.getChannelServer().setEvent(null); player.dropMessage(5, "You have ended the event. No more players may join."); diff --git a/src/main/java/client/command/commands/gm3/ExpedsCommand.java b/src/main/java/client/command/commands/gm3/ExpedsCommand.java index ed54ea911f7..3ffac4f2b54 100644 --- a/src/main/java/client/command/commands/gm3/ExpedsCommand.java +++ b/src/main/java/client/command/commands/gm3/ExpedsCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.Server; import net.server.channel.Channel; import server.expeditions.Expedition; @@ -39,7 +40,7 @@ public class ExpedsCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); for (Channel ch : Server.getInstance().getChannelsFromWorld(c.getWorld())) { List expeds = ch.getExpeditions(); diff --git a/src/main/java/client/command/commands/gm3/FaceCommand.java b/src/main/java/client/command/commands/gm3/FaceCommand.java index 2ceed1145c0..6893b0a48b2 100644 --- a/src/main/java/client/command/commands/gm3/FaceCommand.java +++ b/src/main/java/client/command/commands/gm3/FaceCommand.java @@ -27,6 +27,7 @@ import client.Client; import client.Stat; import client.command.Command; +import client.command.CommandContext; import constants.inventory.ItemConstants; import server.ItemInformationProvider; @@ -36,7 +37,7 @@ public class FaceCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !face [] "); diff --git a/src/main/java/client/command/commands/gm3/FameCommand.java b/src/main/java/client/command/commands/gm3/FameCommand.java index 3cd2819e0be..517745bf874 100644 --- a/src/main/java/client/command/commands/gm3/FameCommand.java +++ b/src/main/java/client/command/commands/gm3/FameCommand.java @@ -27,6 +27,7 @@ import client.Client; import client.Stat; import client.command.Command; +import client.command.CommandContext; public class FameCommand extends Command { { @@ -34,7 +35,7 @@ public class FameCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 2) { player.yellowMessage("Syntax: !fame "); diff --git a/src/main/java/client/command/commands/gm3/FlyCommand.java b/src/main/java/client/command/commands/gm3/FlyCommand.java index 21d92bc258a..e1e0a73d223 100644 --- a/src/main/java/client/command/commands/gm3/FlyCommand.java +++ b/src/main/java/client/command/commands/gm3/FlyCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.Server; public class FlyCommand extends Command { @@ -34,7 +35,7 @@ public class FlyCommand extends Command { } @Override - public void execute(Client c, String[] params) { // fly option will become available for any character of that account + public void execute(Client c, String[] params, CommandContext ctx) { // fly option will become available for any character of that account Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !fly "); diff --git a/src/main/java/client/command/commands/gm3/GiveMesosCommand.java b/src/main/java/client/command/commands/gm3/GiveMesosCommand.java index f625c0ed789..5710f7149c9 100644 --- a/src/main/java/client/command/commands/gm3/GiveMesosCommand.java +++ b/src/main/java/client/command/commands/gm3/GiveMesosCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class GiveMesosCommand extends Command { { @@ -33,7 +34,7 @@ public class GiveMesosCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !givems [] "); diff --git a/src/main/java/client/command/commands/gm3/GiveNxCommand.java b/src/main/java/client/command/commands/gm3/GiveNxCommand.java index 783d35d699b..868fcba4d31 100644 --- a/src/main/java/client/command/commands/gm3/GiveNxCommand.java +++ b/src/main/java/client/command/commands/gm3/GiveNxCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class GiveNxCommand extends Command { { @@ -33,7 +34,7 @@ public class GiveNxCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !givenx [nx, mp, np] [] "); diff --git a/src/main/java/client/command/commands/gm3/GiveRpCommand.java b/src/main/java/client/command/commands/gm3/GiveRpCommand.java deleted file mode 100644 index 84d8155e67d..00000000000 --- a/src/main/java/client/command/commands/gm3/GiveRpCommand.java +++ /dev/null @@ -1,29 +0,0 @@ -package client.command.commands.gm3; - -import client.Character; -import client.Client; -import client.command.Command; - -public class GiveRpCommand extends Command { - { - setDescription("Give reward points to a player."); - } - - @Override - public void execute(Client client, String[] params) { - Character player = client.getPlayer(); - if (params.length < 2) { - player.yellowMessage("Syntax: !giverp "); - return; - } - - Character victim = client.getWorldServer().getPlayerStorage().getCharacterByName(params[0]); - if (victim != null) { - victim.setRewardPoints(victim.getRewardPoints() + Integer.parseInt(params[1])); - player.message("RP given. Player " + params[0] + " now has " + victim.getRewardPoints() - + " reward points."); - } else { - player.message("Player '" + params[0] + "' could not be found."); - } - } -} diff --git a/src/main/java/client/command/commands/gm3/GiveVpCommand.java b/src/main/java/client/command/commands/gm3/GiveVpCommand.java deleted file mode 100644 index 6bad23706a7..00000000000 --- a/src/main/java/client/command/commands/gm3/GiveVpCommand.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - This file is part of the HeavenMS MapleStory Server, commands OdinMS-based - Copyleft (L) 2016 - 2019 RonanLana - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -/* - @Author: Arthur L - Refactored command content into modules -*/ -package client.command.commands.gm3; - -import client.Character; -import client.Client; -import client.command.Command; - -public class GiveVpCommand extends Command { - { - setDescription("Give vote points to a player."); - } - - @Override - public void execute(Client c, String[] params) { - Character player = c.getPlayer(); - if (params.length < 2) { - player.yellowMessage("Syntax: !givevp "); - return; - } - - Character victim = c.getWorldServer().getPlayerStorage().getCharacterByName(params[0]); - if (victim != null) { - victim.getClient().addVotePoints(Integer.parseInt(params[1])); - player.message("VP given."); - } else { - player.message("Player '" + params[0] + "' could not be found."); - } - } -} diff --git a/src/main/java/client/command/commands/gm3/HairCommand.java b/src/main/java/client/command/commands/gm3/HairCommand.java index eaaebaae651..1cdf108f877 100644 --- a/src/main/java/client/command/commands/gm3/HairCommand.java +++ b/src/main/java/client/command/commands/gm3/HairCommand.java @@ -27,6 +27,7 @@ import client.Client; import client.Stat; import client.command.Command; +import client.command.CommandContext; import constants.inventory.ItemConstants; import server.ItemInformationProvider; @@ -36,7 +37,7 @@ public class HairCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !hair [] "); diff --git a/src/main/java/client/command/commands/gm3/HealMapCommand.java b/src/main/java/client/command/commands/gm3/HealMapCommand.java index 295e46f6337..73bf31e892b 100644 --- a/src/main/java/client/command/commands/gm3/HealMapCommand.java +++ b/src/main/java/client/command/commands/gm3/HealMapCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class HealMapCommand extends Command { { @@ -33,7 +34,7 @@ public class HealMapCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); for (Character mch : player.getMap().getCharacters()) { if (mch != null) { diff --git a/src/main/java/client/command/commands/gm3/HealPersonCommand.java b/src/main/java/client/command/commands/gm3/HealPersonCommand.java index 50dcd176011..c8a141f8422 100644 --- a/src/main/java/client/command/commands/gm3/HealPersonCommand.java +++ b/src/main/java/client/command/commands/gm3/HealPersonCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class HealPersonCommand extends Command { { @@ -33,7 +34,7 @@ public class HealPersonCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); Character victim = c.getWorldServer().getPlayerStorage().getCharacterByName(params[0]); if (victim != null) { diff --git a/src/main/java/client/command/commands/gm3/HpMpCommand.java b/src/main/java/client/command/commands/gm3/HpMpCommand.java index 520886bdb02..9666f2e06fc 100644 --- a/src/main/java/client/command/commands/gm3/HpMpCommand.java +++ b/src/main/java/client/command/commands/gm3/HpMpCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class HpMpCommand extends Command { { @@ -33,7 +34,7 @@ public class HpMpCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); Character victim = player; int statUpdate = 1; diff --git a/src/main/java/client/command/commands/gm3/HurtCommand.java b/src/main/java/client/command/commands/gm3/HurtCommand.java index ee4dc87ce0e..e5418eab336 100644 --- a/src/main/java/client/command/commands/gm3/HurtCommand.java +++ b/src/main/java/client/command/commands/gm3/HurtCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class HurtCommand extends Command { { @@ -33,7 +34,7 @@ public class HurtCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); Character victim = c.getWorldServer().getPlayerStorage().getCharacterByName(params[0]); if (victim != null) { diff --git a/src/main/java/client/command/commands/gm3/IgnoreCommand.java b/src/main/java/client/command/commands/gm3/IgnoreCommand.java index 8428bd22bf7..c6415a074aa 100644 --- a/src/main/java/client/command/commands/gm3/IgnoreCommand.java +++ b/src/main/java/client/command/commands/gm3/IgnoreCommand.java @@ -27,6 +27,7 @@ import client.Client; import client.autoban.AutobanFactory; import client.command.Command; +import client.command.CommandContext; import net.server.Server; import tools.PacketCreator; @@ -36,7 +37,7 @@ public class IgnoreCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !ignore "); diff --git a/src/main/java/client/command/commands/gm3/IgnoredCommand.java b/src/main/java/client/command/commands/gm3/IgnoredCommand.java index f15ccd863a3..33251ac77d4 100644 --- a/src/main/java/client/command/commands/gm3/IgnoredCommand.java +++ b/src/main/java/client/command/commands/gm3/IgnoredCommand.java @@ -27,6 +27,7 @@ import client.Client; import client.autoban.AutobanFactory; import client.command.Command; +import client.command.CommandContext; public class IgnoredCommand extends Command { { @@ -34,7 +35,7 @@ public class IgnoredCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); for (int chrId : AutobanFactory.getIgnoredChrIds()) { player.yellowMessage(Character.getNameById(chrId) + " is being ignored."); diff --git a/src/main/java/client/command/commands/gm3/InMapCommand.java b/src/main/java/client/command/commands/gm3/InMapCommand.java index e7173b755c6..f1db8c369f9 100644 --- a/src/main/java/client/command/commands/gm3/InMapCommand.java +++ b/src/main/java/client/command/commands/gm3/InMapCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class InMapCommand extends Command { { @@ -33,7 +34,7 @@ public class InMapCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); String st = ""; for (Character chr : player.getMap().getCharacters()) { diff --git a/src/main/java/client/command/commands/gm3/KillAllCommand.java b/src/main/java/client/command/commands/gm3/KillAllCommand.java index 787e48343f0..8362f53187f 100644 --- a/src/main/java/client/command/commands/gm3/KillAllCommand.java +++ b/src/main/java/client/command/commands/gm3/KillAllCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.id.MobId; import server.life.Monster; import server.maps.MapObject; @@ -41,7 +42,7 @@ public class KillAllCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); MapleMap map = player.getMap(); List monsters = map.getMapObjectsInRange(player.getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapObjectType.MONSTER)); diff --git a/src/main/java/client/command/commands/gm3/KillCommand.java b/src/main/java/client/command/commands/gm3/KillCommand.java index aefb43e55a0..370993bc488 100644 --- a/src/main/java/client/command/commands/gm3/KillCommand.java +++ b/src/main/java/client/command/commands/gm3/KillCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.Server; import tools.PacketCreator; @@ -35,7 +36,7 @@ public class KillCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !kill "); diff --git a/src/main/java/client/command/commands/gm3/KillMapCommand.java b/src/main/java/client/command/commands/gm3/KillMapCommand.java index babcb59807b..b077832b95c 100644 --- a/src/main/java/client/command/commands/gm3/KillMapCommand.java +++ b/src/main/java/client/command/commands/gm3/KillMapCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class KillMapCommand extends Command { { @@ -33,7 +34,7 @@ public class KillMapCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); for (Character mch : player.getMap().getCharacters()) { mch.updateHp(0); diff --git a/src/main/java/client/command/commands/gm3/MaxEnergyCommand.java b/src/main/java/client/command/commands/gm3/MaxEnergyCommand.java index 977bb5f19f1..05eb351265b 100644 --- a/src/main/java/client/command/commands/gm3/MaxEnergyCommand.java +++ b/src/main/java/client/command/commands/gm3/MaxEnergyCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import tools.PacketCreator; public class MaxEnergyCommand extends Command { @@ -34,7 +35,7 @@ public class MaxEnergyCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); c.getPlayer().setDojoEnergy(10000); c.sendPacket(PacketCreator.getEnergy("energy", 10000)); diff --git a/src/main/java/client/command/commands/gm3/MaxHpMpCommand.java b/src/main/java/client/command/commands/gm3/MaxHpMpCommand.java index ed940562fdb..e53b1d885c8 100644 --- a/src/main/java/client/command/commands/gm3/MaxHpMpCommand.java +++ b/src/main/java/client/command/commands/gm3/MaxHpMpCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class MaxHpMpCommand extends Command { { @@ -33,7 +34,7 @@ public class MaxHpMpCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); Character victim = player; diff --git a/src/main/java/client/command/commands/gm3/MonitorCommand.java b/src/main/java/client/command/commands/gm3/MonitorCommand.java index 7b138192526..4edbf85e459 100644 --- a/src/main/java/client/command/commands/gm3/MonitorCommand.java +++ b/src/main/java/client/command/commands/gm3/MonitorCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.packet.logging.MonitoredChrLogger; import net.server.Server; import tools.PacketCreator; @@ -36,7 +37,7 @@ public class MonitorCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !monitor "); diff --git a/src/main/java/client/command/commands/gm3/MonitorsCommand.java b/src/main/java/client/command/commands/gm3/MonitorsCommand.java index 841433a7c74..761ebae9e30 100644 --- a/src/main/java/client/command/commands/gm3/MonitorsCommand.java +++ b/src/main/java/client/command/commands/gm3/MonitorsCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.packet.logging.MonitoredChrLogger; public class MonitorsCommand extends Command { @@ -34,7 +35,7 @@ public class MonitorsCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); for (int chrId : MonitoredChrLogger.getMonitoredChrIds()) { player.yellowMessage(Character.getNameById(chrId) + " is being monitored."); diff --git a/src/main/java/client/command/commands/gm3/MusicCommand.java b/src/main/java/client/command/commands/gm3/MusicCommand.java index a563c0b7e55..f398253a759 100644 --- a/src/main/java/client/command/commands/gm3/MusicCommand.java +++ b/src/main/java/client/command/commands/gm3/MusicCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.game.GameConstants; import constants.id.NpcId; import tools.PacketCreator; @@ -45,7 +46,7 @@ private static String getSongList() { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { diff --git a/src/main/java/client/command/commands/gm3/MuteMapCommand.java b/src/main/java/client/command/commands/gm3/MuteMapCommand.java index f442723bef9..c871d4f30c8 100644 --- a/src/main/java/client/command/commands/gm3/MuteMapCommand.java +++ b/src/main/java/client/command/commands/gm3/MuteMapCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class MuteMapCommand extends Command { { @@ -33,7 +34,7 @@ public class MuteMapCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (player.getMap().isMuted()) { player.getMap().setMuted(false); diff --git a/src/main/java/client/command/commands/gm3/NightCommand.java b/src/main/java/client/command/commands/gm3/NightCommand.java index 3dfaeb5fe3a..63eb25fc334 100644 --- a/src/main/java/client/command/commands/gm3/NightCommand.java +++ b/src/main/java/client/command/commands/gm3/NightCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class NightCommand extends Command { { @@ -33,7 +34,7 @@ public class NightCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); player.getMap().broadcastNightEffect(); player.yellowMessage("Done."); diff --git a/src/main/java/client/command/commands/gm3/NoticeCommand.java b/src/main/java/client/command/commands/gm3/NoticeCommand.java index 083365c9af9..87d7e85acf1 100644 --- a/src/main/java/client/command/commands/gm3/NoticeCommand.java +++ b/src/main/java/client/command/commands/gm3/NoticeCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.Server; import tools.PacketCreator; @@ -35,7 +36,7 @@ public class NoticeCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); Server.getInstance().broadcastMessage(c.getWorld(), PacketCreator.serverNotice(6, "[Notice] " + player.getLastCommandMessage())); } diff --git a/src/main/java/client/command/commands/gm3/NpcCommand.java b/src/main/java/client/command/commands/gm3/NpcCommand.java index 9fe52f77bf4..3d5edf7c41b 100644 --- a/src/main/java/client/command/commands/gm3/NpcCommand.java +++ b/src/main/java/client/command/commands/gm3/NpcCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.life.LifeFactory; import server.life.NPC; import tools.PacketCreator; @@ -36,7 +37,7 @@ public class NpcCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !npc "); diff --git a/src/main/java/client/command/commands/gm3/OnlineTwoCommand.java b/src/main/java/client/command/commands/gm3/OnlineTwoCommand.java index cdba346eb3b..2627782b10f 100644 --- a/src/main/java/client/command/commands/gm3/OnlineTwoCommand.java +++ b/src/main/java/client/command/commands/gm3/OnlineTwoCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.Server; import net.server.channel.Channel; @@ -35,7 +36,7 @@ public class OnlineTwoCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); int total = 0; for (Channel ch : Server.getInstance().getChannelsFromWorld(player.getWorld())) { diff --git a/src/main/java/client/command/commands/gm3/OpenPortalCommand.java b/src/main/java/client/command/commands/gm3/OpenPortalCommand.java index 41400b51580..d99cfc24971 100644 --- a/src/main/java/client/command/commands/gm3/OpenPortalCommand.java +++ b/src/main/java/client/command/commands/gm3/OpenPortalCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class OpenPortalCommand extends Command { { @@ -33,7 +34,7 @@ public class OpenPortalCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !openportal "); diff --git a/src/main/java/client/command/commands/gm3/PeCommand.java b/src/main/java/client/command/commands/gm3/PeCommand.java index 6ee35f394a2..78e4bc53306 100644 --- a/src/main/java/client/command/commands/gm3/PeCommand.java +++ b/src/main/java/client/command/commands/gm3/PeCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import io.netty.buffer.Unpooled; import net.PacketHandler; import net.PacketProcessor; @@ -49,7 +50,7 @@ public class PeCommand extends Command { private static final Logger log = LoggerFactory.getLogger(PeCommand.class); @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); String packet = ""; try (BufferedReader br = Files.newBufferedReader(Path.of("pe.txt"))) { diff --git a/src/main/java/client/command/commands/gm3/PosCommand.java b/src/main/java/client/command/commands/gm3/PosCommand.java index 5928a351e50..ac538d153ea 100644 --- a/src/main/java/client/command/commands/gm3/PosCommand.java +++ b/src/main/java/client/command/commands/gm3/PosCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class PosCommand extends Command { { @@ -33,7 +34,7 @@ public class PosCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); float xpos = player.getPosition().x; float ypos = player.getPosition().y; diff --git a/src/main/java/client/command/commands/gm3/QuestCompleteCommand.java b/src/main/java/client/command/commands/gm3/QuestCompleteCommand.java index 98bdeb5f7bc..68c5ec1ccda 100644 --- a/src/main/java/client/command/commands/gm3/QuestCompleteCommand.java +++ b/src/main/java/client/command/commands/gm3/QuestCompleteCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.quest.Quest; public class QuestCompleteCommand extends Command { @@ -34,7 +35,7 @@ public class QuestCompleteCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { diff --git a/src/main/java/client/command/commands/gm3/QuestResetCommand.java b/src/main/java/client/command/commands/gm3/QuestResetCommand.java index cfb35da64a2..9316a09d6c7 100644 --- a/src/main/java/client/command/commands/gm3/QuestResetCommand.java +++ b/src/main/java/client/command/commands/gm3/QuestResetCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.quest.Quest; public class QuestResetCommand extends Command { @@ -34,7 +35,7 @@ public class QuestResetCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { diff --git a/src/main/java/client/command/commands/gm3/QuestStartCommand.java b/src/main/java/client/command/commands/gm3/QuestStartCommand.java index 3eeee90331c..7fc8821a18e 100644 --- a/src/main/java/client/command/commands/gm3/QuestStartCommand.java +++ b/src/main/java/client/command/commands/gm3/QuestStartCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.quest.Quest; public class QuestStartCommand extends Command { @@ -34,7 +35,7 @@ public class QuestStartCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { diff --git a/src/main/java/client/command/commands/gm3/ReloadDropsCommand.java b/src/main/java/client/command/commands/gm3/ReloadDropsCommand.java index da88d321b80..ee23bf4fac3 100644 --- a/src/main/java/client/command/commands/gm3/ReloadDropsCommand.java +++ b/src/main/java/client/command/commands/gm3/ReloadDropsCommand.java @@ -26,7 +26,7 @@ import client.Character; import client.Client; import client.command.Command; -import server.life.MonsterInformationProvider; +import client.command.CommandContext; public class ReloadDropsCommand extends Command { { @@ -34,9 +34,9 @@ public class ReloadDropsCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); - MonsterInformationProvider.getInstance().clearDrops(); + ctx.dropProvider().clearCaches(); player.dropMessage(5, "Reloaded Drops"); } } diff --git a/src/main/java/client/command/commands/gm3/ReloadEventsCommand.java b/src/main/java/client/command/commands/gm3/ReloadEventsCommand.java index 4feeeffa1b0..5f8d2cdebb0 100644 --- a/src/main/java/client/command/commands/gm3/ReloadEventsCommand.java +++ b/src/main/java/client/command/commands/gm3/ReloadEventsCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.Server; import net.server.channel.Channel; @@ -35,7 +36,7 @@ public class ReloadEventsCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); for (Channel ch : Server.getInstance().getAllChannels()) { ch.reloadEventScriptManager(); diff --git a/src/main/java/client/command/commands/gm3/ReloadMapCommand.java b/src/main/java/client/command/commands/gm3/ReloadMapCommand.java index 17086974560..d6146cee302 100644 --- a/src/main/java/client/command/commands/gm3/ReloadMapCommand.java +++ b/src/main/java/client/command/commands/gm3/ReloadMapCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.maps.MapleMap; import java.util.Collection; @@ -36,7 +37,7 @@ public class ReloadMapCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); MapleMap newMap = c.getChannelServer().getMapFactory().resetMap(player.getMapId()); int callerid = c.getPlayer().getId(); diff --git a/src/main/java/client/command/commands/gm3/ReloadPortalsCommand.java b/src/main/java/client/command/commands/gm3/ReloadPortalsCommand.java index 44f593c8017..06d3b25cece 100644 --- a/src/main/java/client/command/commands/gm3/ReloadPortalsCommand.java +++ b/src/main/java/client/command/commands/gm3/ReloadPortalsCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import scripting.portal.PortalScriptManager; public class ReloadPortalsCommand extends Command { @@ -34,7 +35,7 @@ public class ReloadPortalsCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); PortalScriptManager.getInstance().reloadPortalScripts(); player.dropMessage(5, "Reloaded Portals"); diff --git a/src/main/java/client/command/commands/gm3/ReloadShopsCommand.java b/src/main/java/client/command/commands/gm3/ReloadShopsCommand.java index f98daf3e20d..5231118fcca 100644 --- a/src/main/java/client/command/commands/gm3/ReloadShopsCommand.java +++ b/src/main/java/client/command/commands/gm3/ReloadShopsCommand.java @@ -25,7 +25,7 @@ import client.Client; import client.command.Command; -import server.ShopFactory; +import client.command.CommandContext; public class ReloadShopsCommand extends Command { @@ -34,7 +34,7 @@ public class ReloadShopsCommand extends Command { } @Override - public void execute(Client c, String[] params) { - ShopFactory.getInstance().reloadShops(); + public void execute(Client c, String[] params, CommandContext ctx) { + ctx.shopFactory().reloadShops(); } } diff --git a/src/main/java/client/command/commands/gm3/RipCommand.java b/src/main/java/client/command/commands/gm3/RipCommand.java index 0d17b6d41f9..29339eeaddf 100644 --- a/src/main/java/client/command/commands/gm3/RipCommand.java +++ b/src/main/java/client/command/commands/gm3/RipCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.Server; import tools.PacketCreator; @@ -35,7 +36,7 @@ public class RipCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); Server.getInstance().broadcastMessage(c.getWorld(), PacketCreator.serverNotice(6, "[RIP]: " + joinStringFrom(params, 1))); } diff --git a/src/main/java/client/command/commands/gm3/SeedCommand.java b/src/main/java/client/command/commands/gm3/SeedCommand.java index 19e3bb8cbd0..a9911e515c1 100644 --- a/src/main/java/client/command/commands/gm3/SeedCommand.java +++ b/src/main/java/client/command/commands/gm3/SeedCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import client.inventory.Item; import constants.id.ItemId; import constants.id.MapId; @@ -38,7 +39,7 @@ public class SeedCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (player.getMapId() != MapId.HENESYS_PQ) { player.yellowMessage("This command can only be used in HPQ."); diff --git a/src/main/java/client/command/commands/gm3/SpawnCommand.java b/src/main/java/client/command/commands/gm3/SpawnCommand.java index cc490d75be1..96466f0af3c 100644 --- a/src/main/java/client/command/commands/gm3/SpawnCommand.java +++ b/src/main/java/client/command/commands/gm3/SpawnCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.life.LifeFactory; import server.life.Monster; @@ -35,7 +36,7 @@ public class SpawnCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !spawn []"); diff --git a/src/main/java/client/command/commands/gm3/StartEventCommand.java b/src/main/java/client/command/commands/gm3/StartEventCommand.java index c5072bdc92d..f480cfe5029 100644 --- a/src/main/java/client/command/commands/gm3/StartEventCommand.java +++ b/src/main/java/client/command/commands/gm3/StartEventCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.Server; import server.events.gm.Event; import tools.PacketCreator; @@ -36,7 +37,7 @@ public class StartEventCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); int players = 50; if (params.length > 1) { diff --git a/src/main/java/client/command/commands/gm3/StartMapEventCommand.java b/src/main/java/client/command/commands/gm3/StartMapEventCommand.java index b269c04be62..325440a5c9a 100644 --- a/src/main/java/client/command/commands/gm3/StartMapEventCommand.java +++ b/src/main/java/client/command/commands/gm3/StartMapEventCommand.java @@ -25,6 +25,7 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; public class StartMapEventCommand extends Command { { @@ -32,7 +33,7 @@ public class StartMapEventCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { c.getPlayer().getMap().startEvent(c.getPlayer()); } } diff --git a/src/main/java/client/command/commands/gm3/StopMapEventCommand.java b/src/main/java/client/command/commands/gm3/StopMapEventCommand.java index 8b541c69968..0f4d7cdc1a0 100644 --- a/src/main/java/client/command/commands/gm3/StopMapEventCommand.java +++ b/src/main/java/client/command/commands/gm3/StopMapEventCommand.java @@ -25,6 +25,7 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; public class StopMapEventCommand extends Command { { @@ -32,7 +33,7 @@ public class StopMapEventCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { c.getPlayer().getMap().setEventStarted(false); } } diff --git a/src/main/java/client/command/commands/gm3/TimerAllCommand.java b/src/main/java/client/command/commands/gm3/TimerAllCommand.java index 18d0d3a9545..3f45f610bc4 100644 --- a/src/main/java/client/command/commands/gm3/TimerAllCommand.java +++ b/src/main/java/client/command/commands/gm3/TimerAllCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import tools.PacketCreator; public class TimerAllCommand extends Command { @@ -34,7 +35,7 @@ public class TimerAllCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !timerall |remove"); diff --git a/src/main/java/client/command/commands/gm3/TimerCommand.java b/src/main/java/client/command/commands/gm3/TimerCommand.java index 9c7a5cfb545..66a1d81454d 100644 --- a/src/main/java/client/command/commands/gm3/TimerCommand.java +++ b/src/main/java/client/command/commands/gm3/TimerCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import tools.PacketCreator; public class TimerCommand extends Command { @@ -34,7 +35,7 @@ public class TimerCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 2) { player.yellowMessage("Syntax: !timer |remove"); diff --git a/src/main/java/client/command/commands/gm3/TimerMapCommand.java b/src/main/java/client/command/commands/gm3/TimerMapCommand.java index 2456dd682b8..13a9e9a7da2 100644 --- a/src/main/java/client/command/commands/gm3/TimerMapCommand.java +++ b/src/main/java/client/command/commands/gm3/TimerMapCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import tools.PacketCreator; public class TimerMapCommand extends Command { @@ -34,7 +35,7 @@ public class TimerMapCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !timermap |remove"); diff --git a/src/main/java/client/command/commands/gm3/ToggleCouponCommand.java b/src/main/java/client/command/commands/gm3/ToggleCouponCommand.java index 03046c04bae..c8672309ac4 100644 --- a/src/main/java/client/command/commands/gm3/ToggleCouponCommand.java +++ b/src/main/java/client/command/commands/gm3/ToggleCouponCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.Server; public class ToggleCouponCommand extends Command { @@ -34,7 +35,7 @@ public class ToggleCouponCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !togglecoupon "); diff --git a/src/main/java/client/command/commands/gm3/UnBanCommand.java b/src/main/java/client/command/commands/gm3/UnBanCommand.java index 7f9cf7fe342..96f00412fbd 100644 --- a/src/main/java/client/command/commands/gm3/UnBanCommand.java +++ b/src/main/java/client/command/commands/gm3/UnBanCommand.java @@ -26,10 +26,7 @@ import client.Character; import client.Client; import client.command.Command; -import tools.DatabaseConnection; - -import java.sql.Connection; -import java.sql.PreparedStatement; +import client.command.CommandContext; public class UnBanCommand extends Command { { @@ -37,32 +34,19 @@ public class UnBanCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !unban "); return; } - try (Connection con = DatabaseConnection.getConnection()) { - int aid = Character.getAccountIdByName(params[0]); - - try (PreparedStatement p = con.prepareStatement("UPDATE accounts SET banned = -1 WHERE id = " + aid)) { - p.executeUpdate(); - } - - try (PreparedStatement p = con.prepareStatement("DELETE FROM ipbans WHERE aid = " + aid)) { - p.executeUpdate(); - } - - try (PreparedStatement p = con.prepareStatement("DELETE FROM macbans WHERE aid = " + aid)) { - p.executeUpdate(); - } - } catch (Exception e) { - e.printStackTrace(); - player.message("Failed to unban " + params[0]); + String chrName = params[0]; + if (!ctx.banService().unban(chrName)) { + player.message("Failed to unban " + chrName); return; } - player.message("Unbanned " + params[0]); + + player.message("Unbanned " + chrName); } } diff --git a/src/main/java/client/command/commands/gm4/BossDropRateCommand.java b/src/main/java/client/command/commands/gm4/BossDropRateCommand.java index 0bf9a549274..7f386d1ac45 100644 --- a/src/main/java/client/command/commands/gm4/BossDropRateCommand.java +++ b/src/main/java/client/command/commands/gm4/BossDropRateCommand.java @@ -22,6 +22,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import tools.PacketCreator; /** @@ -33,7 +34,7 @@ public class BossDropRateCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !bossdroprate "); diff --git a/src/main/java/client/command/commands/gm4/CakeCommand.java b/src/main/java/client/command/commands/gm4/CakeCommand.java index 3b2ba63f1a2..cf13b49ebe9 100644 --- a/src/main/java/client/command/commands/gm4/CakeCommand.java +++ b/src/main/java/client/command/commands/gm4/CakeCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.id.MobId; import server.life.LifeFactory; import server.life.Monster; @@ -36,7 +37,7 @@ public class CakeCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); Monster monster = LifeFactory.getMonster(MobId.GIANT_CAKE); if (params.length == 1) { diff --git a/src/main/java/client/command/commands/gm4/DropRateCommand.java b/src/main/java/client/command/commands/gm4/DropRateCommand.java index 1a94e3d77e8..9d5c472141d 100644 --- a/src/main/java/client/command/commands/gm4/DropRateCommand.java +++ b/src/main/java/client/command/commands/gm4/DropRateCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import tools.PacketCreator; public class DropRateCommand extends Command { @@ -34,7 +35,7 @@ public class DropRateCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !droprate "); diff --git a/src/main/java/client/command/commands/gm4/ExpRateCommand.java b/src/main/java/client/command/commands/gm4/ExpRateCommand.java index 5b363c6927a..6b3a5cb0ce1 100644 --- a/src/main/java/client/command/commands/gm4/ExpRateCommand.java +++ b/src/main/java/client/command/commands/gm4/ExpRateCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import tools.PacketCreator; public class ExpRateCommand extends Command { @@ -34,7 +35,7 @@ public class ExpRateCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !exprate "); diff --git a/src/main/java/client/command/commands/gm4/FishingRateCommand.java b/src/main/java/client/command/commands/gm4/FishingRateCommand.java index 532d94f6495..d848475090f 100644 --- a/src/main/java/client/command/commands/gm4/FishingRateCommand.java +++ b/src/main/java/client/command/commands/gm4/FishingRateCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import tools.PacketCreator; public class FishingRateCommand extends Command { @@ -34,7 +35,7 @@ public class FishingRateCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !fishrate "); diff --git a/src/main/java/client/command/commands/gm4/ForceVacCommand.java b/src/main/java/client/command/commands/gm4/ForceVacCommand.java index 02a3a816a9c..75abd226e0d 100644 --- a/src/main/java/client/command/commands/gm4/ForceVacCommand.java +++ b/src/main/java/client/command/commands/gm4/ForceVacCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import client.inventory.Pet; import client.inventory.manipulator.InventoryManipulator; import constants.id.ItemId; @@ -43,7 +44,7 @@ public class ForceVacCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); List items = player.getMap().getMapObjectsInRange(player.getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapObjectType.ITEM)); for (MapObject item : items) { diff --git a/src/main/java/client/command/commands/gm4/HorntailCommand.java b/src/main/java/client/command/commands/gm4/HorntailCommand.java index dffe66d390f..152e8d2fcab 100644 --- a/src/main/java/client/command/commands/gm4/HorntailCommand.java +++ b/src/main/java/client/command/commands/gm4/HorntailCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.maps.MapleMap; import java.awt.*; @@ -36,7 +37,7 @@ public class HorntailCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); final Point targetPoint = player.getPosition(); final MapleMap targetMap = player.getMap(); diff --git a/src/main/java/client/command/commands/gm4/ItemVacCommand.java b/src/main/java/client/command/commands/gm4/ItemVacCommand.java index a0bf4238bb5..3bd7149aedb 100644 --- a/src/main/java/client/command/commands/gm4/ItemVacCommand.java +++ b/src/main/java/client/command/commands/gm4/ItemVacCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.maps.MapObject; import server.maps.MapObjectType; @@ -38,7 +39,7 @@ public class ItemVacCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); List list = player.getMap().getMapObjectsInRange(player.getPosition(), Double.POSITIVE_INFINITY, Arrays.asList(MapObjectType.ITEM)); for (MapObject item : list) { diff --git a/src/main/java/client/command/commands/gm4/MesoRateCommand.java b/src/main/java/client/command/commands/gm4/MesoRateCommand.java index 4680c0cefc3..79749799107 100644 --- a/src/main/java/client/command/commands/gm4/MesoRateCommand.java +++ b/src/main/java/client/command/commands/gm4/MesoRateCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import tools.PacketCreator; public class MesoRateCommand extends Command { @@ -34,7 +35,7 @@ public class MesoRateCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !mesorate "); diff --git a/src/main/java/client/command/commands/gm4/PapCommand.java b/src/main/java/client/command/commands/gm4/PapCommand.java index f0ddecc7924..895c8e26100 100644 --- a/src/main/java/client/command/commands/gm4/PapCommand.java +++ b/src/main/java/client/command/commands/gm4/PapCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.id.MobId; import server.life.LifeFactory; @@ -35,7 +36,7 @@ public class PapCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); // thanks Conrad for noticing mobid typo here diff --git a/src/main/java/client/command/commands/gm4/PianusCommand.java b/src/main/java/client/command/commands/gm4/PianusCommand.java index 4a5d7fe7393..ceacdf88f5b 100644 --- a/src/main/java/client/command/commands/gm4/PianusCommand.java +++ b/src/main/java/client/command/commands/gm4/PianusCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.id.MobId; import server.life.LifeFactory; @@ -35,7 +36,7 @@ public class PianusCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); player.getMap().spawnMonsterOnGroundBelow(LifeFactory.getMonster(MobId.PIANUS_R), player.getPosition()); } diff --git a/src/main/java/client/command/commands/gm4/PinkbeanCommand.java b/src/main/java/client/command/commands/gm4/PinkbeanCommand.java index 37cee3ae119..4c4cc10f967 100644 --- a/src/main/java/client/command/commands/gm4/PinkbeanCommand.java +++ b/src/main/java/client/command/commands/gm4/PinkbeanCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.id.MobId; import server.life.LifeFactory; @@ -35,7 +36,7 @@ public class PinkbeanCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); player.getMap().spawnMonsterOnGroundBelow(LifeFactory.getMonster(MobId.PINK_BEAN), player.getPosition()); diff --git a/src/main/java/client/command/commands/gm4/PlayerNpcCommand.java b/src/main/java/client/command/commands/gm4/PlayerNpcCommand.java index d4d5ae0316c..e088ebbab42 100644 --- a/src/main/java/client/command/commands/gm4/PlayerNpcCommand.java +++ b/src/main/java/client/command/commands/gm4/PlayerNpcCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.life.PlayerNPC; public class PlayerNpcCommand extends Command { @@ -34,7 +35,7 @@ public class PlayerNpcCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !playernpc "); diff --git a/src/main/java/client/command/commands/gm4/PlayerNpcRemoveCommand.java b/src/main/java/client/command/commands/gm4/PlayerNpcRemoveCommand.java index 68616156ba0..1ef57925ace 100644 --- a/src/main/java/client/command/commands/gm4/PlayerNpcRemoveCommand.java +++ b/src/main/java/client/command/commands/gm4/PlayerNpcRemoveCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.life.PlayerNPC; public class PlayerNpcRemoveCommand extends Command { @@ -34,7 +35,7 @@ public class PlayerNpcRemoveCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !playernpcremove "); diff --git a/src/main/java/client/command/commands/gm4/PmobCommand.java b/src/main/java/client/command/commands/gm4/PmobCommand.java index 7b918a8d940..e61eb201ed1 100644 --- a/src/main/java/client/command/commands/gm4/PmobCommand.java +++ b/src/main/java/client/command/commands/gm4/PmobCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.channel.Channel; import server.life.LifeFactory; import server.life.Monster; @@ -43,7 +44,7 @@ public class PmobCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !pmob []"); @@ -99,4 +100,4 @@ public void execute(Client c, String[] params) { player.dropMessage(5, "You have entered an invalid mob id."); } } -} \ No newline at end of file +} diff --git a/src/main/java/client/command/commands/gm4/PmobRemoveCommand.java b/src/main/java/client/command/commands/gm4/PmobRemoveCommand.java index f2abbea2a0f..4583c99d848 100644 --- a/src/main/java/client/command/commands/gm4/PmobRemoveCommand.java +++ b/src/main/java/client/command/commands/gm4/PmobRemoveCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.channel.Channel; import server.maps.MapleMap; import tools.DatabaseConnection; @@ -45,7 +46,7 @@ public class PmobRemoveCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); int mapId = player.getMapId(); @@ -107,4 +108,4 @@ public void execute(Client c, String[] params) { player.yellowMessage("Cleared " + toRemove.size() + " pmob placements."); } -} \ No newline at end of file +} diff --git a/src/main/java/client/command/commands/gm4/PnpcCommand.java b/src/main/java/client/command/commands/gm4/PnpcCommand.java index e6212b27c49..f8791b912a0 100644 --- a/src/main/java/client/command/commands/gm4/PnpcCommand.java +++ b/src/main/java/client/command/commands/gm4/PnpcCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.channel.Channel; import server.life.LifeFactory; import server.life.NPC; @@ -44,7 +45,7 @@ public class PnpcCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !pnpc "); @@ -106,4 +107,4 @@ public void execute(Client c, String[] params) { player.dropMessage(5, "You have entered an invalid NPC id."); } } -} \ No newline at end of file +} diff --git a/src/main/java/client/command/commands/gm4/PnpcRemoveCommand.java b/src/main/java/client/command/commands/gm4/PnpcRemoveCommand.java index a062496d150..4721ec11feb 100644 --- a/src/main/java/client/command/commands/gm4/PnpcRemoveCommand.java +++ b/src/main/java/client/command/commands/gm4/PnpcRemoveCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.channel.Channel; import server.maps.MapleMap; import tools.DatabaseConnection; @@ -45,7 +46,7 @@ public class PnpcRemoveCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); int mapId = player.getMapId(); @@ -107,4 +108,4 @@ public void execute(Client c, String[] params) { player.yellowMessage("Cleared " + toRemove.size() + " pNPC placements."); } -} \ No newline at end of file +} diff --git a/src/main/java/client/command/commands/gm4/ProItemCommand.java b/src/main/java/client/command/commands/gm4/ProItemCommand.java index 7ecab53fad5..5f35043a2ee 100644 --- a/src/main/java/client/command/commands/gm4/ProItemCommand.java +++ b/src/main/java/client/command/commands/gm4/ProItemCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import client.inventory.Equip; import client.inventory.InventoryType; import client.inventory.Item; @@ -39,7 +40,7 @@ public class ProItemCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 2) { player.yellowMessage("Syntax: !proitem []"); diff --git a/src/main/java/client/command/commands/gm4/QuestRateCommand.java b/src/main/java/client/command/commands/gm4/QuestRateCommand.java index c880d7a166c..3286eaf1c9c 100644 --- a/src/main/java/client/command/commands/gm4/QuestRateCommand.java +++ b/src/main/java/client/command/commands/gm4/QuestRateCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import tools.PacketCreator; public class QuestRateCommand extends Command { @@ -34,7 +35,7 @@ public class QuestRateCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !questrate "); diff --git a/src/main/java/client/command/commands/gm4/ServerMessageCommand.java b/src/main/java/client/command/commands/gm4/ServerMessageCommand.java index 2fd43e483cd..6b423e82625 100644 --- a/src/main/java/client/command/commands/gm4/ServerMessageCommand.java +++ b/src/main/java/client/command/commands/gm4/ServerMessageCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class ServerMessageCommand extends Command { { @@ -33,7 +34,7 @@ public class ServerMessageCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); c.getWorldServer().setServerMessage(player.getLastCommandMessage()); } diff --git a/src/main/java/client/command/commands/gm4/SetEqStatCommand.java b/src/main/java/client/command/commands/gm4/SetEqStatCommand.java index 115654b4b6a..f9d71260ba1 100644 --- a/src/main/java/client/command/commands/gm4/SetEqStatCommand.java +++ b/src/main/java/client/command/commands/gm4/SetEqStatCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import client.inventory.Equip; import client.inventory.Inventory; import client.inventory.InventoryType; @@ -37,7 +38,7 @@ public class SetEqStatCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !seteqstat []"); diff --git a/src/main/java/client/command/commands/gm4/TravelRateCommand.java b/src/main/java/client/command/commands/gm4/TravelRateCommand.java index aabb8605aaa..05c2f2657a5 100644 --- a/src/main/java/client/command/commands/gm4/TravelRateCommand.java +++ b/src/main/java/client/command/commands/gm4/TravelRateCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import tools.PacketCreator; public class TravelRateCommand extends Command { @@ -34,7 +35,7 @@ public class TravelRateCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !travelrate "); diff --git a/src/main/java/client/command/commands/gm4/ZakumCommand.java b/src/main/java/client/command/commands/gm4/ZakumCommand.java index eeea31f45f1..6f69e9ae1c2 100644 --- a/src/main/java/client/command/commands/gm4/ZakumCommand.java +++ b/src/main/java/client/command/commands/gm4/ZakumCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.id.MobId; import server.life.LifeFactory; @@ -35,7 +36,7 @@ public class ZakumCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); player.getMap().spawnFakeMonsterOnGroundBelow(LifeFactory.getMonster(MobId.ZAKUM_1), player.getPosition()); for (int mobId = MobId.ZAKUM_ARM_1; mobId <= MobId.ZAKUM_ARM_8; mobId++) { diff --git a/src/main/java/client/command/commands/gm5/DebugCommand.java b/src/main/java/client/command/commands/gm5/DebugCommand.java index 5800f1ea929..d0a6974defe 100644 --- a/src/main/java/client/command/commands/gm5/DebugCommand.java +++ b/src/main/java/client/command/commands/gm5/DebugCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.id.NpcId; import net.server.Server; import server.TimerManager; @@ -48,7 +49,7 @@ public class DebugCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { diff --git a/src/main/java/client/command/commands/gm5/IpListCommand.java b/src/main/java/client/command/commands/gm5/IpListCommand.java index 3661c8f31b9..5ff9b40fd0f 100644 --- a/src/main/java/client/command/commands/gm5/IpListCommand.java +++ b/src/main/java/client/command/commands/gm5/IpListCommand.java @@ -22,6 +22,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.game.GameConstants; import net.server.Server; import net.server.world.World; @@ -39,7 +40,7 @@ public class IpListCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { String str = "Player-IP relation:"; for (World w : Server.getInstance().getWorlds()) { @@ -57,4 +58,4 @@ public void execute(Client c, String[] params) { c.getAbstractPlayerInteraction().npcTalk(22000, str); } -} \ No newline at end of file +} diff --git a/src/main/java/client/command/commands/gm5/SetCommand.java b/src/main/java/client/command/commands/gm5/SetCommand.java index f42dd1fb1bf..9291a1c8abc 100644 --- a/src/main/java/client/command/commands/gm5/SetCommand.java +++ b/src/main/java/client/command/commands/gm5/SetCommand.java @@ -25,6 +25,7 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; import constants.net.ServerConstants; public class SetCommand extends Command { @@ -33,7 +34,7 @@ public class SetCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { for (int i = 0; i < params.length; i++) { ServerConstants.DEBUG_VALUES[i] = Integer.parseInt(params[i]); } diff --git a/src/main/java/client/command/commands/gm5/ShowMoveLifeCommand.java b/src/main/java/client/command/commands/gm5/ShowMoveLifeCommand.java index d269cc956f1..578f4f6e1a7 100644 --- a/src/main/java/client/command/commands/gm5/ShowMoveLifeCommand.java +++ b/src/main/java/client/command/commands/gm5/ShowMoveLifeCommand.java @@ -25,6 +25,7 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; import config.YamlConfig; public class ShowMoveLifeCommand extends Command { @@ -33,7 +34,7 @@ public class ShowMoveLifeCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { YamlConfig.config.server.USE_DEBUG_SHOW_RCVD_MVLIFE = !YamlConfig.config.server.USE_DEBUG_SHOW_RCVD_MVLIFE; } } diff --git a/src/main/java/client/command/commands/gm5/ShowPacketsCommand.java b/src/main/java/client/command/commands/gm5/ShowPacketsCommand.java index 03bf3bf49ea..5b745b658a2 100644 --- a/src/main/java/client/command/commands/gm5/ShowPacketsCommand.java +++ b/src/main/java/client/command/commands/gm5/ShowPacketsCommand.java @@ -25,6 +25,7 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; import config.YamlConfig; public class ShowPacketsCommand extends Command { @@ -33,7 +34,7 @@ public class ShowPacketsCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { YamlConfig.config.server.USE_DEBUG_SHOW_RCVD_PACKET = !YamlConfig.config.server.USE_DEBUG_SHOW_RCVD_PACKET; } } diff --git a/src/main/java/client/command/commands/gm5/ShowSessionsCommand.java b/src/main/java/client/command/commands/gm5/ShowSessionsCommand.java index acc4d78e51c..01d0ad5da03 100644 --- a/src/main/java/client/command/commands/gm5/ShowSessionsCommand.java +++ b/src/main/java/client/command/commands/gm5/ShowSessionsCommand.java @@ -21,6 +21,7 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.coordinator.session.SessionCoordinator; /** @@ -32,7 +33,7 @@ public class ShowSessionsCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { SessionCoordinator.getInstance().printSessionTrace(c); } } diff --git a/src/main/java/client/command/commands/gm6/ClearQuestCacheCommand.java b/src/main/java/client/command/commands/gm6/ClearQuestCacheCommand.java index 5f094f5600f..8496a61c246 100644 --- a/src/main/java/client/command/commands/gm6/ClearQuestCacheCommand.java +++ b/src/main/java/client/command/commands/gm6/ClearQuestCacheCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.quest.Quest; public class ClearQuestCacheCommand extends Command { @@ -34,7 +35,7 @@ public class ClearQuestCacheCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); Quest.clearCache(); player.dropMessage(5, "Quest Cache Cleared."); diff --git a/src/main/java/client/command/commands/gm6/ClearQuestCommand.java b/src/main/java/client/command/commands/gm6/ClearQuestCommand.java index 79707eff055..77b297d168c 100644 --- a/src/main/java/client/command/commands/gm6/ClearQuestCommand.java +++ b/src/main/java/client/command/commands/gm6/ClearQuestCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import server.quest.Quest; public class ClearQuestCommand extends Command { @@ -34,7 +35,7 @@ public class ClearQuestCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.dropMessage(5, "Please include a quest ID."); diff --git a/src/main/java/client/command/commands/gm6/DCAllCommand.java b/src/main/java/client/command/commands/gm6/DCAllCommand.java index f8298a4534a..28518d05a0e 100644 --- a/src/main/java/client/command/commands/gm6/DCAllCommand.java +++ b/src/main/java/client/command/commands/gm6/DCAllCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.Server; import net.server.world.World; @@ -35,12 +36,12 @@ public class DCAllCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); for (World world : Server.getInstance().getWorlds()) { for (Character chr : world.getPlayerStorage().getAllCharacters()) { if (!chr.isGM()) { - chr.getClient().disconnect(false, false); + ctx.transitionService().disconnect(chr.getClient(), false); } } } diff --git a/src/main/java/client/command/commands/gm6/DevtestCommand.java b/src/main/java/client/command/commands/gm6/DevtestCommand.java index c0fd30dd577..136251a3cf0 100644 --- a/src/main/java/client/command/commands/gm6/DevtestCommand.java +++ b/src/main/java/client/command/commands/gm6/DevtestCommand.java @@ -2,6 +2,7 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import scripting.AbstractScriptManager; @@ -27,7 +28,7 @@ public ScriptEngine getInvocableScriptEngine(String path) { } @Override - public void execute(Client client, String[] params) { + public void execute(Client client, String[] params, CommandContext context) { DevtestScriptManager scriptManager = new DevtestScriptManager(); ScriptEngine scriptEngine = scriptManager.getInvocableScriptEngine("devtest.js"); try { diff --git a/src/main/java/client/command/commands/gm6/EraseAllPNpcsCommand.java b/src/main/java/client/command/commands/gm6/EraseAllPNpcsCommand.java index 6f6394454c8..44dc7ffc593 100644 --- a/src/main/java/client/command/commands/gm6/EraseAllPNpcsCommand.java +++ b/src/main/java/client/command/commands/gm6/EraseAllPNpcsCommand.java @@ -25,6 +25,7 @@ import client.Client; import client.command.Command; +import client.command.CommandContext; import server.life.PlayerNPC; public class EraseAllPNpcsCommand extends Command { @@ -33,7 +34,7 @@ public class EraseAllPNpcsCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { PlayerNPC.removeAllPlayerNPC(); } } diff --git a/src/main/java/client/command/commands/gm6/GetAccCommand.java b/src/main/java/client/command/commands/gm6/GetAccCommand.java index 00b81c69ac5..274e7996077 100644 --- a/src/main/java/client/command/commands/gm6/GetAccCommand.java +++ b/src/main/java/client/command/commands/gm6/GetAccCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class GetAccCommand extends Command { { @@ -33,7 +34,7 @@ public class GetAccCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !getacc "); diff --git a/src/main/java/client/command/commands/gm6/MapPlayersCommand.java b/src/main/java/client/command/commands/gm6/MapPlayersCommand.java index 2404bd9bc06..ff705ac0afc 100644 --- a/src/main/java/client/command/commands/gm6/MapPlayersCommand.java +++ b/src/main/java/client/command/commands/gm6/MapPlayersCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.Server; import net.server.world.World; @@ -35,7 +36,7 @@ public class MapPlayersCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); String names = ""; int map = player.getMapId(); diff --git a/src/main/java/client/command/commands/gm6/SaveAllCommand.java b/src/main/java/client/command/commands/gm6/SaveAllCommand.java index 28df7b456f6..30afb6ed68e 100644 --- a/src/main/java/client/command/commands/gm6/SaveAllCommand.java +++ b/src/main/java/client/command/commands/gm6/SaveAllCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.Server; import net.server.world.World; import tools.PacketCreator; @@ -36,11 +37,11 @@ public class SaveAllCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); for (World world : Server.getInstance().getWorlds()) { for (Character chr : world.getPlayerStorage().getAllCharacters()) { - chr.saveCharToDB(); + ctx.characterSaver().save(chr); } } String message = player.getName() + " used !saveall."; diff --git a/src/main/java/client/command/commands/gm6/ServerAddChannelCommand.java b/src/main/java/client/command/commands/gm6/ServerAddChannelCommand.java deleted file mode 100644 index 4f438c6b538..00000000000 --- a/src/main/java/client/command/commands/gm6/ServerAddChannelCommand.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - This file is part of the HeavenMS MapleStory Server, commands OdinMS-based - Copyleft (L) 2016 - 2019 RonanLana - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -/* - @Author: Arthur L - Refactored command content into modules -*/ -package client.command.commands.gm6; - -import client.Character; -import client.Client; -import client.command.Command; -import net.server.Server; -import server.ThreadManager; - -public class ServerAddChannelCommand extends Command { - { - setDescription("Add a new channel to a world."); - } - - @Override - public void execute(Client c, String[] params) { - final Character player = c.getPlayer(); - - if (params.length < 1) { - player.dropMessage(5, "Syntax: @addchannel "); - return; - } - - final int worldid = Integer.parseInt(params[0]); - - ThreadManager.getInstance().newTask(() -> { - int chid = Server.getInstance().addChannel(worldid); - if (player.isLoggedinWorld()) { - if (chid >= 0) { - player.dropMessage(5, "NEW Channel " + chid + " successfully deployed on world " + worldid + "."); - } else { - if (chid == -3) { - player.dropMessage(5, "Invalid worldid detected. Channel creation aborted."); - } else if (chid == -2) { - player.dropMessage(5, "Reached channel limit on worldid " + worldid + ". Channel creation aborted."); - } else if (chid == -1) { - player.dropMessage(5, "Error detected when loading the 'world.ini' file. Channel creation aborted."); - } else { - player.dropMessage(5, "NEW Channel failed to be deployed. Check if the needed port is already in use or other limitations are taking place."); - } - } - } - }); - } -} diff --git a/src/main/java/client/command/commands/gm6/ServerAddWorldCommand.java b/src/main/java/client/command/commands/gm6/ServerAddWorldCommand.java deleted file mode 100644 index ae611f904d4..00000000000 --- a/src/main/java/client/command/commands/gm6/ServerAddWorldCommand.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - This file is part of the HeavenMS MapleStory Server, commands OdinMS-based - Copyleft (L) 2016 - 2019 RonanLana - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -/* - @Author: Arthur L - Refactored command content into modules -*/ -package client.command.commands.gm6; - -import client.Character; -import client.Client; -import client.command.Command; -import net.server.Server; -import server.ThreadManager; - -public class ServerAddWorldCommand extends Command { - { - setDescription("Add a new world."); - } - - @Override - public void execute(Client c, String[] params) { - final Character player = c.getPlayer(); - - ThreadManager.getInstance().newTask(() -> { - int wid = Server.getInstance().addWorld(); - - if (player.isLoggedinWorld()) { - if (wid >= 0) { - player.dropMessage(5, "NEW World " + wid + " successfully deployed."); - } else { - if (wid == -2) { - player.dropMessage(5, "Error detected when loading the 'world.ini' file. World creation aborted."); - } else { - player.dropMessage(5, "NEW World failed to be deployed. Check if needed ports are already in use or maximum world count has been reached."); - } - } - } - }); - } -} diff --git a/src/main/java/client/command/commands/gm6/ServerRemoveChannelCommand.java b/src/main/java/client/command/commands/gm6/ServerRemoveChannelCommand.java deleted file mode 100644 index e0051403276..00000000000 --- a/src/main/java/client/command/commands/gm6/ServerRemoveChannelCommand.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - This file is part of the HeavenMS MapleStory Server, commands OdinMS-based - Copyleft (L) 2016 - 2019 RonanLana - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -/* - @Author: Arthur L - Refactored command content into modules -*/ -package client.command.commands.gm6; - -import client.Character; -import client.Client; -import client.command.Command; -import net.server.Server; -import server.ThreadManager; - -public class ServerRemoveChannelCommand extends Command { - { - setDescription("Remove channel from a world."); - } - - @Override - public void execute(Client c, String[] params) { - final Character player = c.getPlayer(); - - if (params.length < 1) { - player.dropMessage(5, "Syntax: @removechannel "); - return; - } - - final int worldId = Integer.parseInt(params[0]); - ThreadManager.getInstance().newTask(() -> { - if (Server.getInstance().removeChannel(worldId)) { - if (player.isLoggedinWorld()) { - player.dropMessage(5, "Successfully removed a channel on World " + worldId + ". Current channel count: " + Server.getInstance().getWorld(worldId).getChannelsSize() + "."); - } - } else { - if (player.isLoggedinWorld()) { - player.dropMessage(5, "Failed to remove last Channel on world " + worldId + ". Check if either that world exists or there are people currently playing there."); - } - } - }); - } -} diff --git a/src/main/java/client/command/commands/gm6/ServerRemoveWorldCommand.java b/src/main/java/client/command/commands/gm6/ServerRemoveWorldCommand.java deleted file mode 100644 index 522d891c637..00000000000 --- a/src/main/java/client/command/commands/gm6/ServerRemoveWorldCommand.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - This file is part of the HeavenMS MapleStory Server, commands OdinMS-based - Copyleft (L) 2016 - 2019 RonanLana - - This program is free software: you can redistribute it and/or modify - it under the terms of the GNU Affero General Public License as - published by the Free Software Foundation version 3 as published by - the Free Software Foundation. You may not use, modify or distribute - this program under any other version of the GNU Affero General Public - License. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Affero General Public License for more details. - - You should have received a copy of the GNU Affero General Public License - along with this program. If not, see . -*/ - -/* - @Author: Arthur L - Refactored command content into modules -*/ -package client.command.commands.gm6; - -import client.Character; -import client.Client; -import client.command.Command; -import net.server.Server; -import server.ThreadManager; - -public class ServerRemoveWorldCommand extends Command { - { - setDescription("Remove a world."); - } - - @Override - public void execute(Client c, String[] params) { - final Character player = c.getPlayer(); - - final int rwid = Server.getInstance().getWorldsSize() - 1; - if (rwid <= 0) { - player.dropMessage(5, "Unable to remove world 0."); - return; - } - - ThreadManager.getInstance().newTask(() -> { - if (Server.getInstance().removeWorld()) { - if (player.isLoggedinWorld()) { - player.dropMessage(5, "Successfully removed a world. Current world count: " + Server.getInstance().getWorldsSize() + "."); - } - } else { - if (player.isLoggedinWorld()) { - if (rwid < 0) { - player.dropMessage(5, "No registered worlds to remove."); - } else { - player.dropMessage(5, "Failed to remove world " + rwid + ". Check if there are people currently playing there."); - } - } - } - }); - } -} diff --git a/src/main/java/client/command/commands/gm6/SetGmLevelCommand.java b/src/main/java/client/command/commands/gm6/SetGmLevelCommand.java index 9387ac0cb85..cf06dc93594 100644 --- a/src/main/java/client/command/commands/gm6/SetGmLevelCommand.java +++ b/src/main/java/client/command/commands/gm6/SetGmLevelCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; public class SetGmLevelCommand extends Command { { @@ -33,7 +34,7 @@ public class SetGmLevelCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 2) { player.yellowMessage("Syntax: !setgmlevel "); diff --git a/src/main/java/client/command/commands/gm6/ShutdownCommand.java b/src/main/java/client/command/commands/gm6/ShutdownCommand.java index a083c9b63f3..047a0af0733 100644 --- a/src/main/java/client/command/commands/gm6/ShutdownCommand.java +++ b/src/main/java/client/command/commands/gm6/ShutdownCommand.java @@ -26,6 +26,7 @@ import client.Character; import client.Client; import client.command.Command; +import client.command.CommandContext; import net.server.Server; import net.server.world.World; import server.TimerManager; @@ -41,7 +42,7 @@ public class ShutdownCommand extends Command { } @Override - public void execute(Client c, String[] params) { + public void execute(Client c, String[] params, CommandContext ctx) { Character player = c.getPlayer(); if (params.length < 1) { player.yellowMessage("Syntax: !shutdown [