├── .gitignore ├── GameServer.properties ├── LICENSE ├── pom.xml ├── readme.md └── src └── main └── java └── org └── openpanfu └── gameserver ├── GameServer.java ├── GameServerFrameDecoder.java ├── GameServerHandler.java ├── GameServerInitializer.java ├── PanfuPacket.java ├── User.java ├── commands ├── Commands.java ├── Help.java └── ICommand.java ├── constants ├── HomeCommands.java ├── Packets.java ├── PlayerToPlayerCommands.java └── RoomCommands.java ├── database ├── Database.java ├── GameServerData.java ├── UserData.java └── dao │ ├── GameServerDAO.java │ └── UserDAO.java ├── games └── multiplayer │ ├── FourBoom.java │ ├── GameQueue.java │ └── RockPaperScissors.java ├── handler ├── CMD_ACTION.java ├── CMD_ADDBUDDY.java ├── CMD_CHANGE_ROOM.java ├── CMD_CHAT.java ├── CMD_EMOTE.java ├── CMD_ENTER_MULTIGAME.java ├── CMD_GET_ALL_HOUSES.java ├── CMD_GET_PLAYER_IDS_BY_CLOTHES.java ├── CMD_GET_ROOM_ATTENDEES.java ├── CMD_GET_SALT.java ├── CMD_JOIN_GAME.java ├── CMD_JOIN_HOME.java ├── CMD_JOIN_ROOM.java ├── CMD_LOGIN.java ├── CMD_MOVE.java ├── CMD_PLAYER_TO_PLAYER.java ├── CMD_QUERY_SHARED_ITEMS.java ├── CMD_QUIT_GAME.java ├── CMD_SAFE_CHAT.java ├── CMD_UPDATE_ROOM.java ├── CMD_UPDATE_SOUND.java ├── Handler.java ├── IHandler.java ├── p2p │ ├── CMD_CREATE_AVATAR.java │ ├── CMD_HIDE_STATUS.java │ ├── CMD_SHOW_STATUS.java │ ├── CMD_UPDATE_AVATAR.java │ ├── CMD_USE_SHARED_ITEM.java │ ├── IP2PHandler.java │ └── P2PHandler.java └── special │ └── CMD_INFOMESSAGE.java ├── plugin ├── IPlugin.java ├── Plugin.java ├── PluginInstance.java ├── PluginLoader.java └── PluginManager.java ├── sessions └── SessionManager.java └── util ├── Key.java └── Logger.java /.gitignore: -------------------------------------------------------------------------------- 1 | # IDE 2 | .idea 3 | *.iml 4 | 5 | # Eclipse 6 | .classpath 7 | .project 8 | .settings 9 | 10 | # Maven 11 | dependency-reduced-pom.xml 12 | target 13 | 14 | # Plugins 15 | plugins/ -------------------------------------------------------------------------------- /GameServer.properties: -------------------------------------------------------------------------------- 1 | # This file is part of openPanfu, a project that imitates the Flex remoting 2 | # and gameservers of Panfu. 3 | # @author Altro50 4 | 5 | # Database settings 6 | 7 | database.host = 127.0.0.1 8 | database.port = 3306 9 | database.database = openpanfu 10 | database.user = openPanfu 11 | database.pass = password 12 | 13 | # Gameserver environment variables 14 | 15 | gameserver.ansilogging = 1 16 | 17 | # Treehouses 18 | 19 | treehouses.showSheriffAsGold = 0 20 | 21 | # Chat settings 22 | 23 | chat.commands.prefix = ! 24 | chat.sheriff.prefix = FF0000 25 | chat.forcesafechat = 0 26 | 27 | # Chat anti-spam 28 | # When enabled, the secondsbetweenmessages variable is used. If disabled, there will still be an anti-spam, 29 | # but it'll only go off if you send a message within 0.1 seconds. 30 | chat.antispam.enabled = 1 31 | chat.antispam.secondsbetweenmessages = 1 32 | chat.antispam.warnings = 3 33 | chat.antispam.message = You're sending too many messages! Warning &&warns&&/&&maxwarns&& 34 | 35 | # Actions (transformations etc) anti-spam 36 | actions.antispam.enabled = 1 37 | actions.antispam.secondsbetweenactions = 1 38 | actions.antispam.message = You're performing too many actions! Warning &&warns&&/&&maxwarns&& 39 | 40 | # Room-specific 41 | rooms.pool.jumpintotheshowers = 0 -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 4.0.0 8 | org.openpanfu 9 | gameserver 10 | 1.0-SNAPSHOT 11 | 12 | 13 | 14 | org.apache.maven.plugins 15 | maven-compiler-plugin 16 | 17 | 8 18 | 8 19 | 20 | 21 | 22 | maven-assembly-plugin 23 | 24 | 25 | 26 | org.openpanfu.gameserver.GameServer 27 | 28 | 29 | 30 | jar-with-dependencies 31 | 32 | false 33 | 34 | 35 | 36 | make-assembly 37 | package 38 | 39 | single 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | io.netty 49 | netty-all 50 | 4.1.26.Final 51 | 52 | 53 | com.zaxxer 54 | HikariCP 55 | 3.2.0 56 | 57 | 58 | 59 | org.javassist 60 | javassist 61 | 3.23.1-GA 62 | 63 | 64 | mysql 65 | mysql-connector-java 66 | 6.0.6 67 | 68 | 69 | org.slf4j 70 | slf4j-simple 71 | 1.6.1 72 | 73 | 74 | commons-lang 75 | commons-lang 76 | 2.6 77 | 78 | 79 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # OpenPanfu GameServer 2 | 3 | ### About 4 | Panfu is made out of two components: an InformationServer (emulated with [InformationServer](https://github.com/openPanfu/InformationServer)) and a GameServer. 5 | 6 | The InformationServer is more for Database tasks and tasks that the other users don't have to know about (Login, Register, inventory), while the GameServer is for multiplayer interactions in the game (moving, actions and multiplayer games like 4boom and hotboom). 7 | 8 | ### Installation 9 | You need to have the [InformationServer](https://github.com/openPanfu/InformationServer) up and running with the database configured and all. Then, change the details in GameServer.properties to match the database settings that the InformationServer is running on. 10 | 11 | #### Running the GameServer 12 | If you've got a [release](https://github.com/openPanfu/GameServer/releases), you can simply extract it and run with the following command: `java -jar (jar name)`. 13 | 14 | #### Compiling the GameServer 15 | To compile the jar, you need [Maven](https://maven.apache.org/). 16 | After you've installed it and confirmed you can run `mvn -v`, run `mvn clean compile package` 17 | 18 | A jar file will appear in the target directory, now copy it and GameServer.properties to a directory and run `java -jar (jar name)`. 19 | 20 | #### Adding a new GS to the InformationServer 21 | 22 | In your database, there's a table called gameservers. Add new entries for the gameservers you want to host. 23 | 24 | All entries in that table will be hosted from this server. 25 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/GameServer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @category GameServer 6 | * @package org.openpanfu.gameserver 7 | * @author Altro50 8 | */ 9 | 10 | package org.openpanfu.gameserver; 11 | 12 | import java.io.FileInputStream; 13 | import java.sql.SQLException; 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | import java.util.Properties; 17 | 18 | import org.openpanfu.gameserver.commands.Commands; 19 | import org.openpanfu.gameserver.commands.Help; 20 | import org.openpanfu.gameserver.database.Database; 21 | import org.openpanfu.gameserver.database.GameServerData; 22 | import org.openpanfu.gameserver.database.dao.GameServerDAO; 23 | import org.openpanfu.gameserver.games.multiplayer.FourBoom; 24 | import org.openpanfu.gameserver.games.multiplayer.RockPaperScissors; 25 | import org.openpanfu.gameserver.handler.Handler; 26 | import org.openpanfu.gameserver.plugin.PluginManager; 27 | import org.openpanfu.gameserver.sessions.SessionManager; 28 | import org.openpanfu.gameserver.util.Logger; 29 | 30 | import io.netty.bootstrap.ServerBootstrap; 31 | import io.netty.channel.Channel; 32 | import io.netty.channel.EventLoopGroup; 33 | import io.netty.channel.nio.NioEventLoopGroup; 34 | import io.netty.channel.socket.nio.NioServerSocketChannel; 35 | 36 | public class GameServer { 37 | private static List gameServers = new ArrayList(); 38 | private static Properties properties = new Properties(); 39 | 40 | private int id; 41 | private String name; 42 | private int port; 43 | private boolean chatEnabled = false; 44 | private SessionManager sessionManager; 45 | private String secretKey = ""; 46 | private Channel channel; 47 | 48 | // Multiplayer games 49 | 50 | private FourBoom fourBoom; 51 | private RockPaperScissors rockPaperScissors; 52 | 53 | public GameServer(int id, String name, int port) { 54 | this.id = id; 55 | this.name = name; 56 | this.port = port; 57 | this.sessionManager = new SessionManager(); 58 | this.chatEnabled = (Integer.valueOf(GameServer.getProperties().getProperty("chat.forcesafechat")) == 0); 59 | this.fourBoom = new FourBoom(); 60 | this.rockPaperScissors = new RockPaperScissors(); 61 | Logger.info("[" + this.id + "] Starting gameserver on port: " + port); 62 | 63 | EventLoopGroup bossGroup = new NioEventLoopGroup(1); 64 | EventLoopGroup workerGroup = new NioEventLoopGroup(); 65 | try { 66 | ServerBootstrap b = new ServerBootstrap(); 67 | b.group(bossGroup, workerGroup).channel(NioServerSocketChannel.class); 68 | b.childHandler(new GameServerInitializer(this)); 69 | this.channel = b.bind(this.port).sync().channel(); 70 | } catch (Exception e) { 71 | Logger.error("Failed to create channel! (Make sure the port isn't already in use!)"); 72 | e.printStackTrace(); 73 | } 74 | } 75 | 76 | public int getId() { 77 | return this.id; 78 | } 79 | 80 | public int getPort() { 81 | return this.port; 82 | } 83 | 84 | public String getName() { 85 | return this.name; 86 | } 87 | 88 | public static void main(String[] arguments) throws SQLException, InterruptedException { 89 | try { 90 | properties.load(new FileInputStream("GameServer.properties")); 91 | } catch (Exception e) { 92 | Logger.error("There was an issue loading the properties file."); 93 | e.printStackTrace(); 94 | return; 95 | } 96 | Handler.initialize(); 97 | if (Database.connect()) { 98 | for (GameServerData data : GameServerDAO.getGameServers()) { 99 | GameServer gameserver = new GameServer(data.id, data.name, data.port); 100 | gameServers.add(gameserver); 101 | gameserver.updateUserCount(); 102 | GameServerDAO.setupKeys(gameserver); 103 | Logger.info("Gameserver " + gameserver.name + " is ready for connections."); 104 | } 105 | } else { 106 | Logger.error("HALT! The database connection could not be initialized!"); 107 | } 108 | Commands.registerCommand("help", new Help()); 109 | PluginManager.loadPlugins("plugins"); 110 | } 111 | 112 | public static Properties getProperties() { 113 | return properties; 114 | } 115 | 116 | public SessionManager getSessionManager() { 117 | return sessionManager; 118 | } 119 | 120 | public void updateUserCount() { 121 | GameServerDAO.updateUserCount(this.id, this.sessionManager.getUserCount()); 122 | } 123 | 124 | public static User getUserById(int userId) { 125 | for (GameServer gs : gameServers) { 126 | User u = gs.getSessionManager().getUserById(userId); 127 | if (u != null) { 128 | return u; 129 | } 130 | } 131 | return null; 132 | } 133 | 134 | public boolean isChatEnabled() { 135 | return chatEnabled; 136 | } 137 | 138 | public FourBoom getFourBoom() { 139 | return fourBoom; 140 | } 141 | 142 | public RockPaperScissors getRockPaperScissors() { 143 | return rockPaperScissors; 144 | } 145 | 146 | public String getKey() { 147 | return secretKey; 148 | } 149 | 150 | public void setKey(String secretKey) { 151 | this.secretKey = secretKey; 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/GameServerFrameDecoder.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver; 2 | 3 | import io.netty.buffer.Unpooled; 4 | import io.netty.handler.codec.DelimiterBasedFrameDecoder; 5 | 6 | public class GameServerFrameDecoder extends DelimiterBasedFrameDecoder { 7 | public GameServerFrameDecoder(int maxFrameLength) { 8 | super(maxFrameLength, false, Unpooled.wrappedBuffer(new byte[] { '|' }), 9 | Unpooled.wrappedBuffer(new byte[] { '>' })); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/GameServerHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver; 9 | 10 | import java.util.Arrays; 11 | 12 | import org.openpanfu.gameserver.util.Logger; 13 | 14 | import io.netty.channel.ChannelHandlerContext; 15 | import io.netty.channel.SimpleChannelInboundHandler; 16 | import io.netty.util.AttributeKey; 17 | 18 | public class GameServerHandler extends SimpleChannelInboundHandler { 19 | private GameServer gameServer; 20 | 21 | public GameServerHandler(GameServer gameServer) { 22 | this.gameServer = gameServer; 23 | } 24 | 25 | @Override 26 | public void channelActive(final ChannelHandlerContext ctx) { 27 | Logger.info("Connection from: " + ctx.channel().remoteAddress()); 28 | ctx.channel().attr(AttributeKey.valueOf("user")).set(new User(ctx.channel(), this.gameServer)); 29 | } 30 | 31 | @Override 32 | public void channelInactive(final ChannelHandlerContext ctx) { 33 | User user = (User) ctx.channel().attr(AttributeKey.valueOf("user")).get(); 34 | user.onDisconnect(); 35 | } 36 | 37 | @Override 38 | public void channelRead0(ChannelHandlerContext channelHandlerContext, String message) { 39 | // Useless characters, they only make interpretation harder. 40 | // You can't use them in things like chat anyway, so it's safe to ignore them. 41 | message = message.replace("\r", ""); 42 | message = message.replace("\n", ""); 43 | Logger.debug("} " + message); 44 | User user = (User) channelHandlerContext.channel().attr(AttributeKey.valueOf("user")).get(); 45 | if (message.startsWith("<")) { 46 | String policy = "\r\n\r\n\r\n \r\n\0"; 47 | user.getChannel().writeAndFlush(policy); 48 | user.getChannel().close(); 49 | return; 50 | } 51 | if (message.contains(String.valueOf('|'))) { 52 | String[] packets = message.split("\\|"); 53 | for (String packet : packets) { 54 | try { 55 | String[] split = packet.split(";"); 56 | String[] arguments = Arrays.copyOfRange(split, 1, split.length); 57 | PanfuPacket panfuPacket = new PanfuPacket(Integer.valueOf(split[0])); 58 | panfuPacket.passParameters(arguments); 59 | user.handlePacket(panfuPacket); 60 | } catch (Exception e) { 61 | e.printStackTrace(); 62 | user.getChannel().close(); 63 | } 64 | } 65 | } 66 | } 67 | 68 | @Override 69 | public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { 70 | cause.printStackTrace(); 71 | ctx.close(); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/GameServerInitializer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver; 9 | 10 | import io.netty.channel.Channel; 11 | import io.netty.channel.ChannelInitializer; 12 | import io.netty.channel.ChannelPipeline; 13 | import io.netty.handler.codec.string.StringDecoder; 14 | import io.netty.handler.codec.string.StringEncoder; 15 | 16 | public class GameServerInitializer extends ChannelInitializer { 17 | private GameServer gameServer; 18 | 19 | public GameServerInitializer(GameServer gameServer) { 20 | this.gameServer = gameServer; 21 | } 22 | 23 | @Override 24 | public void initChannel(Channel channel) { 25 | ChannelPipeline pipeline = channel.pipeline(); 26 | pipeline.addLast("framer", new GameServerFrameDecoder(1000)); 27 | pipeline.addLast(new StringDecoder()); 28 | pipeline.addLast(new StringEncoder()); 29 | pipeline.addLast(new GameServerHandler(this.gameServer)); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/PanfuPacket.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver; 9 | 10 | import java.util.ArrayList; 11 | import java.util.Arrays; 12 | import java.util.List; 13 | 14 | public class PanfuPacket { 15 | private int header; 16 | private List parameters = new ArrayList(); 17 | private int pos = 0; 18 | private User sender; 19 | private static String PAR_DELIMETER = ";"; 20 | private static String SRV_CMD_DELIMETER = "|"; 21 | 22 | public PanfuPacket(int Header) { 23 | this.header = Header; 24 | } 25 | 26 | public void passParameters(String[] parameters) { 27 | this.parameters.addAll(Arrays.asList(parameters)); 28 | } 29 | 30 | public int getHeader() { 31 | return header; 32 | } 33 | 34 | public int getPos() { 35 | return pos; 36 | } 37 | 38 | public void setPos(int pos) { 39 | this.pos = pos; 40 | } 41 | 42 | public User getSender() { 43 | return sender; 44 | } 45 | 46 | public void setSender(User sender) { 47 | sender = sender; 48 | } 49 | 50 | public int readInt() { 51 | try { 52 | if (parameters.get(pos).contains(".")) { 53 | return Integer.valueOf(parameters.get(pos).split("\\.")[0]); 54 | } 55 | return Integer.valueOf(parameters.get(pos)); 56 | } catch (Exception e) { 57 | return -1; 58 | } finally { 59 | pos++; 60 | } 61 | } 62 | 63 | public String readString() { 64 | try { 65 | return String.valueOf(parameters.get(pos)); 66 | } catch (Exception e) { 67 | return ""; 68 | } finally { 69 | pos++; 70 | } 71 | } 72 | 73 | public void writeInt(int Value) { 74 | parameters.add(String.valueOf(Value)); 75 | } 76 | 77 | public void writeString(String Value) { 78 | parameters.add(Value); 79 | } 80 | 81 | public String toString() { 82 | String Packet = ""; 83 | Packet += header; 84 | for (String part : parameters) { 85 | Packet += PAR_DELIMETER + part; 86 | } 87 | Packet += SRV_CMD_DELIMETER; 88 | return Packet; 89 | } 90 | } 91 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/User.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver; 9 | 10 | import java.util.List; 11 | 12 | import org.openpanfu.gameserver.constants.Packets; 13 | import org.openpanfu.gameserver.constants.PlayerToPlayerCommands; 14 | import org.openpanfu.gameserver.database.dao.UserDAO; 15 | import org.openpanfu.gameserver.handler.Handler; 16 | import org.openpanfu.gameserver.handler.IHandler; 17 | import org.openpanfu.gameserver.plugin.PluginManager; 18 | import org.openpanfu.gameserver.util.Logger; 19 | 20 | import io.netty.channel.Channel; 21 | 22 | public class User { 23 | private int userId = -1; 24 | private String username; 25 | private boolean isLoggedIn = false; 26 | private int sheriff = 0; 27 | private int goldpanda = 0; 28 | private Channel channel; 29 | private GameServer gameServer; 30 | private boolean inHome = false; 31 | private int gameId = -1; 32 | private User multiGamePartner = null; 33 | private int roomId = -1; 34 | private int subRoom = 0; 35 | private int x; 36 | private int y; 37 | private int status = 0; 38 | private int rot = 0; 39 | private int interactingWith = -1; 40 | private long timeUntilWalkComplete; 41 | private String lastChatMessage = ""; 42 | private long lastChatMessageTime = System.currentTimeMillis(); 43 | private String lastActionPerformed = ""; 44 | private long lastActionPerformedTime = System.currentTimeMillis(); 45 | private int spamWarning = 0; 46 | 47 | public User(Channel channel, GameServer gameServer) { 48 | this.timeUntilWalkComplete = System.currentTimeMillis(); 49 | this.channel = channel; 50 | this.gameServer = gameServer; 51 | } 52 | 53 | public void handlePacket(PanfuPacket panfuPacket) { 54 | IHandler packetHandler = Handler.getHandlerForHeader(panfuPacket.getHeader()); 55 | if (!this.isLoggedIn) { 56 | if (panfuPacket.getHeader() != Packets.CMD_LOGIN && panfuPacket.getHeader() != Packets.CMD_GET_SALT 57 | && panfuPacket.getHeader() != Packets.CMD_INFOMESSAGE) { 58 | Logger.warning( 59 | "User tried inputting a forbidden packet for the state he is in! (Not logged in) Attempted packet: " 60 | + panfuPacket.getHeader()); 61 | return; 62 | } 63 | } 64 | 65 | if (panfuPacket.getHeader() == Packets.CMD_MULTIGAME) { 66 | if (getMultiGamePartner() != null) { 67 | if (gameId == 25) { 68 | gameServer.getFourBoom().onMessage(this, panfuPacket); 69 | } 70 | if (gameId == 41) { 71 | gameServer.getRockPaperScissors().onMessage(this, panfuPacket); 72 | } 73 | } 74 | return; 75 | } 76 | 77 | if (packetHandler == null) { 78 | Logger.warning("Unhandled packet: " + Packets.headerToName(panfuPacket.getHeader()) + " (" 79 | + panfuPacket.getHeader() + ")"); 80 | } else { 81 | Handler.getHandlerForHeader(panfuPacket.getHeader()).handlePacket(panfuPacket, this); 82 | } 83 | } 84 | 85 | public void disconnect() { 86 | this.onDisconnect(); 87 | this.channel.disconnect(); 88 | } 89 | 90 | public void disconnect(String message) { 91 | this.sendString("2;" + message + "|"); 92 | this.disconnect(); 93 | } 94 | 95 | public void setChatEnabled(boolean enabled) { 96 | PanfuPacket packetToInform = new PanfuPacket(Packets.RES_TOGGLE_SAFE_CHAT); 97 | packetToInform.writeInt(enabled ? 0 : 1); 98 | this.sendPacket(packetToInform); 99 | } 100 | 101 | public void sendAlert(String message) { 102 | PanfuPacket gameServerAlert = new PanfuPacket(Packets.RES_ON_SHOW_GS_MSG); 103 | gameServerAlert.writeString(message + "\r\n"); 104 | this.sendPacket(gameServerAlert); 105 | } 106 | 107 | public void setCurrentGameServer(int gameServerId) { 108 | UserDAO.setCurrentGameServer(userId, gameServerId); 109 | } 110 | 111 | public void nullTicketId() { 112 | UserDAO.nullTicket(userId); 113 | } 114 | 115 | public void sendPacket(PanfuPacket packet) { 116 | this.sendString(packet.toString()); 117 | } 118 | 119 | public void sendString(String data) { 120 | Logger.debug("{ " + data); 121 | this.channel.writeAndFlush(data); 122 | } 123 | 124 | public int getUserId() { 125 | return userId; 126 | } 127 | 128 | public void setUserId(int userId) { 129 | this.userId = userId; 130 | } 131 | 132 | public String getUsername() { 133 | return username; 134 | } 135 | 136 | public void setUsername(String username) { 137 | this.username = username; 138 | } 139 | 140 | public int getSheriff() { 141 | return sheriff; 142 | } 143 | 144 | public void setSheriff(int sheriff) { 145 | this.sheriff = sheriff; 146 | } 147 | 148 | public int getGoldpanda() { 149 | return goldpanda; 150 | } 151 | 152 | public void setGoldpanda(int goldpanda) { 153 | this.goldpanda = goldpanda; 154 | } 155 | 156 | public boolean isInHome() { 157 | return inHome; 158 | } 159 | 160 | public void setInHome(boolean inHome) { 161 | this.inHome = inHome; 162 | } 163 | 164 | public Channel getChannel() { 165 | return this.channel; 166 | } 167 | 168 | public GameServer getGameServer() { 169 | return gameServer; 170 | } 171 | 172 | public boolean isLoggedIn() { 173 | return isLoggedIn; 174 | } 175 | 176 | public void setLoggedIn(boolean loggedIn) { 177 | isLoggedIn = loggedIn; 178 | } 179 | 180 | public void onDisconnect() { 181 | Logger.debug("User disconnected"); 182 | if (this.roomId > -1) { 183 | PanfuPacket statusBroadcast = new PanfuPacket(Packets.RES_PLAYER_TO_PLAYER); 184 | statusBroadcast.writeInt(userId); 185 | statusBroadcast.writeInt(PlayerToPlayerCommands.ON_SHOW_STATUS); 186 | statusBroadcast.writeString("Offline"); 187 | statusBroadcast.writeString("I gotta go now. Bye!"); 188 | this.sendRoomExcludingMe(statusBroadcast); 189 | PanfuPacket unset = new PanfuPacket(Packets.RES_UNSET_AVATAR); 190 | unset.writeInt(this.userId); 191 | this.sendRoomExcludingMe(unset); 192 | } 193 | 194 | if (this.isLoggedIn) { 195 | if (this.gameId == 25) { 196 | gameServer.getFourBoom().onExit(this); 197 | } 198 | if (this.gameId == 41) { 199 | gameServer.getRockPaperScissors().onExit(this); 200 | } 201 | gameServer.getSessionManager().removeUserById(this.userId); 202 | gameServer.updateUserCount(); 203 | UserDAO.clearCurrentGameServer(this.userId); 204 | } 205 | } 206 | 207 | public void move(int toX, int toY, int walkms, int type) { 208 | this.x = toX; 209 | this.y = toY; 210 | PanfuPacket movePacket = new PanfuPacket(Packets.RES_MOVE_AVATAR); 211 | movePacket.writeInt(this.getUserId()); 212 | movePacket.writeInt(walkms); 213 | movePacket.writeInt(toX); 214 | movePacket.writeInt(toY); 215 | movePacket.writeInt(type); 216 | this.sendRoom(movePacket); 217 | } 218 | 219 | public void joinRoom(int roomId) { 220 | if (this.roomId > -1) { 221 | PanfuPacket unset = new PanfuPacket(Packets.RES_UNSET_AVATAR); 222 | unset.writeInt(this.userId); 223 | this.sendRoomExcludingMe(unset); 224 | } 225 | this.roomId = roomId; 226 | this.inHome = false; 227 | this.subRoom = 0; 228 | PanfuPacket joinRoom = new PanfuPacket(Packets.RES_ON_ROOM_JOINED); 229 | joinRoom.writeInt(this.roomId); 230 | this.sendPacket(joinRoom); 231 | PluginManager.onUserJoinRoom(this, roomId, this.inHome); 232 | } 233 | 234 | public void joinHome(int playerId) { 235 | if (this.roomId > -1) { 236 | PanfuPacket unset = new PanfuPacket(Packets.RES_UNSET_AVATAR); 237 | unset.writeInt(this.userId); 238 | this.sendRoomExcludingMe(unset); 239 | } 240 | this.roomId = playerId; 241 | this.inHome = true; 242 | this.subRoom = 0; 243 | PanfuPacket joinHome = new PanfuPacket(Packets.RES_ON_HOME_JOINED); 244 | joinHome.writeInt(this.roomId); 245 | this.sendPacket(joinHome); 246 | PluginManager.onUserJoinRoom(this, this.roomId, this.inHome); 247 | } 248 | 249 | public String getPlayerString() { 250 | return String.format("%d:%d:%d:0:%d:%d:0", userId, x, y, status, rot); 251 | } 252 | 253 | public void sendRoomExcludingMe(PanfuPacket PP) { 254 | List users = gameServer.getSessionManager().getUsersInRoom(this.roomId, this.inHome, this.subRoom); 255 | for (User u : users) { 256 | if (u.isInHome() == inHome && u.userId != userId) { 257 | u.sendPacket(PP); 258 | } 259 | } 260 | } 261 | 262 | public void sendRoom(PanfuPacket PP) { 263 | List users = gameServer.getSessionManager().getUsersInRoom(this.roomId, this.inHome, this.subRoom); 264 | for (User u : users) { 265 | u.sendPacket(PP); 266 | } 267 | } 268 | 269 | public void sendForReceiver(PanfuPacket PP, String receiver) { 270 | if (receiver.contains(",")) { 271 | String[] split = receiver.split(","); 272 | if (split[0].equals(String.valueOf(PlayerToPlayerCommands.P2P_RECEIVER_ALL))) { 273 | List users = getGameServer().getSessionManager().getUsers(); 274 | for (User user : users) { 275 | if (user.getUserId() == this.getUserId() && user.getUserId() != Integer.valueOf(split[1])) 276 | continue; 277 | user.sendPacket(PP); 278 | } 279 | return; 280 | } 281 | if (split[0].equals(String.valueOf(PlayerToPlayerCommands.P2P_RECEIVER_ROOM))) { 282 | List users = getGameServer().getSessionManager().getUsersInRoom(this.getRoomId(), this.inHome, 283 | this.subRoom); 284 | for (User user : users) { 285 | if (user.getUserId() == this.getUserId() && user.getUserId() != Integer.valueOf(split[1])) 286 | continue; 287 | user.sendPacket(PP); 288 | } 289 | return; 290 | } 291 | return; 292 | } 293 | 294 | if (receiver.equals(String.valueOf(PlayerToPlayerCommands.P2P_RECEIVER_ALL))) { 295 | List users = getGameServer().getSessionManager().getUsers(); 296 | for (User user : users) { 297 | if (user.getUserId() == this.getUserId()) 298 | continue; 299 | user.sendPacket(PP); 300 | } 301 | return; 302 | } 303 | 304 | if (receiver.equals(String.valueOf(PlayerToPlayerCommands.P2P_RECEIVER_ROOM))) { 305 | List users = getGameServer().getSessionManager().getUsersInRoom(this.getRoomId(), this.inHome, 306 | this.subRoom); 307 | for (User user : users) { 308 | if (user.getUserId() == this.getUserId()) 309 | continue; 310 | user.sendPacket(PP); 311 | } 312 | return; 313 | } 314 | 315 | int receiverAsInt = Integer.valueOf(receiver); 316 | // User 317 | if (receiverAsInt > 0) { 318 | User user = getGameServer().getSessionManager().getUserById(receiverAsInt); 319 | if (user != null) { 320 | user.sendPacket(PP); 321 | } 322 | } 323 | } 324 | 325 | public int getInteractingWith() { 326 | return interactingWith; 327 | } 328 | 329 | public void nullInteractions() { 330 | this.interactingWith = -1; 331 | } 332 | 333 | public void setInteractingWith(int interactingWith) { 334 | this.interactingWith = interactingWith; 335 | } 336 | 337 | public int getRoomId() { 338 | return this.roomId; 339 | } 340 | 341 | public void setRoomId(int roomId) { 342 | this.roomId = roomId; 343 | } 344 | 345 | public int getCurrentGame() { 346 | return this.gameId; 347 | } 348 | 349 | public void joinGame(int gameId) { 350 | this.gameId = gameId; 351 | } 352 | 353 | public void quitGame() { 354 | if (this.gameId == 25) { 355 | gameServer.getFourBoom().onExit(this); 356 | } 357 | if (this.gameId == 41) { 358 | gameServer.getRockPaperScissors().onExit(this); 359 | } 360 | this.gameId = -1; 361 | } 362 | 363 | public int getX() { 364 | return this.x; 365 | } 366 | 367 | public void setX(int x) { 368 | this.x = x; 369 | } 370 | 371 | public int getY() { 372 | return this.y; 373 | } 374 | 375 | public void setY(int y) { 376 | this.y = y; 377 | } 378 | 379 | public int getStatus() { 380 | return this.status; 381 | } 382 | 383 | public void setStatus(int status) { 384 | this.status = status; 385 | } 386 | 387 | public int getRot() { 388 | return this.rot; 389 | } 390 | 391 | public void setRot(int rot) { 392 | this.rot = rot; 393 | } 394 | 395 | public long getTimeUntilWalkComplete() { 396 | return this.timeUntilWalkComplete; 397 | } 398 | 399 | public void setTimeUntilWalkComplete(long timeUntilWalkComplete) { 400 | this.timeUntilWalkComplete = timeUntilWalkComplete; 401 | } 402 | 403 | public String getLastChatMessage() { 404 | return lastChatMessage; 405 | } 406 | 407 | public void setLastChatMessage(String lastChatMessage) { 408 | this.lastChatMessage = lastChatMessage; 409 | } 410 | 411 | public String getLastActionPerformed() { 412 | return lastActionPerformed; 413 | } 414 | 415 | public void setLastActionPerformed(String lastActionPerformed) { 416 | this.lastActionPerformed = lastActionPerformed; 417 | } 418 | 419 | public long getLastChatMessageTime() { 420 | return lastChatMessageTime; 421 | } 422 | 423 | public void setLastChatMessageTime(long lastChatMessageTime) { 424 | this.lastChatMessageTime = lastChatMessageTime; 425 | } 426 | 427 | public long getLastActionPerformedTime() { 428 | return lastActionPerformedTime; 429 | } 430 | 431 | public void setLastActionPerformedTime(long lastActionPerformedTime) { 432 | this.lastActionPerformedTime = lastActionPerformedTime; 433 | } 434 | 435 | public int getSpamWarningsGiven() { 436 | return spamWarning; 437 | } 438 | 439 | public void giveActionSpamWarning() { 440 | if (this.spamWarning == Integer.valueOf(GameServer.getProperties().getProperty("chat.antispam.warnings"))) { 441 | this.disconnect("KICKED: Anti-Spam"); 442 | return; 443 | } 444 | this.spamWarning++; 445 | String alert = GameServer.getProperties().getProperty("actions.antispam.message"); 446 | alert = alert.replaceAll("&&warns&&", String.valueOf(this.spamWarning)); 447 | alert = alert.replaceAll("&&maxwarns&&", GameServer.getProperties().getProperty("chat.antispam.warnings")); 448 | this.sendAlert(alert); 449 | } 450 | 451 | public void giveChatSpamWarning() { 452 | if (this.spamWarning == Integer.valueOf(GameServer.getProperties().getProperty("chat.antispam.warnings"))) { 453 | this.disconnect("KICKED: Anti-Spam"); 454 | return; 455 | } 456 | this.spamWarning++; 457 | String alert = GameServer.getProperties().getProperty("chat.antispam.message"); 458 | alert = alert.replaceAll("&&warns&&", String.valueOf(this.spamWarning)); 459 | alert = alert.replaceAll("&&maxwarns&&", GameServer.getProperties().getProperty("chat.antispam.warnings")); 460 | this.sendAlert(alert); 461 | } 462 | 463 | public User getMultiGamePartner() { 464 | return multiGamePartner; 465 | } 466 | 467 | public void setMultiGamePartner(User multiGamePartner) { 468 | this.multiGamePartner = multiGamePartner; 469 | } 470 | 471 | public int getSubRoom() { 472 | return subRoom; 473 | } 474 | 475 | public void setSubRoom(int subRoom) { 476 | this.subRoom = subRoom; 477 | } 478 | } 479 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/commands/Commands.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.commands; 2 | 3 | import java.util.Collection; 4 | import java.util.HashMap; 5 | 6 | import org.openpanfu.gameserver.User; 7 | import org.openpanfu.gameserver.util.Logger; 8 | 9 | public class Commands { 10 | private static HashMap handlers = new HashMap(); 11 | 12 | /** 13 | * 14 | * @param handle The handle the command should go by 15 | * @param commandExecutor the ICommand instance that will be called when the 16 | * command is invoked by a user 17 | * @return 18 | */ 19 | public static boolean registerCommand(String handle, ICommand commandExecutor) { 20 | handle = handle.toLowerCase(); 21 | if (!handlers.containsKey(handle)) { 22 | if (handle.chars().allMatch(Character::isLetter)) { 23 | handlers.put(handle, commandExecutor); 24 | return true; 25 | } else { 26 | Logger.error(String.format( 27 | "Attempted to register command %s, this was denied because the handle contains invalid characters. (Only letters are allowed!)", 28 | handle)); 29 | } 30 | } else { 31 | Logger.error(String.format( 32 | "Attempted to register command %s, this was denied because a command has already been registered with that handle.", 33 | handle)); 34 | } 35 | return false; 36 | } 37 | 38 | public static String[] listCommands() { 39 | String[] commandsAndDescriptions = new String[handlers.size()]; 40 | Collection commandHandlers = handlers.values(); 41 | int i = 0; 42 | for (ICommand command : commandHandlers) { 43 | commandsAndDescriptions[i] = command.getDescription(); 44 | i++; 45 | } 46 | return commandsAndDescriptions; 47 | } 48 | 49 | public static void executeCommand(User sender, String handle, String[] arguments) { 50 | if (handle.chars().allMatch(Character::isLetter) && handlers.containsKey(handle)) { 51 | handlers.get(handle).onExecution(sender, arguments); 52 | return; 53 | } 54 | sender.sendAlert(String.format("Unknown command: %s..", handle)); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/commands/Help.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.commands; 2 | 3 | import org.openpanfu.gameserver.User; 4 | 5 | public class Help implements ICommand { 6 | @Override 7 | public void onExecution(User invoker, String[] parameters) { 8 | String alert = "GameServer commands:" + "\r\n"; 9 | String[] commandsAndDescriptions = Commands.listCommands(); 10 | for (String description : commandsAndDescriptions) { 11 | alert += " " + description + "\r\n"; 12 | } 13 | invoker.sendAlert(alert); 14 | } 15 | 16 | @Override 17 | public String getDescription() { 18 | return "!help - Lists all the available commands."; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/commands/ICommand.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.commands; 2 | 3 | import org.openpanfu.gameserver.User; 4 | 5 | public interface ICommand { 6 | /** 7 | * 8 | * @param invoker The user that invoked the command 9 | * @param parameters the parameters that the user provided 10 | */ 11 | public void onExecution(User invoker, String[] parameters); 12 | 13 | public String getDescription(); 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/constants/HomeCommands.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.constants; 2 | 3 | public class HomeCommands { 4 | // C -> S 5 | public static final int CMD_UPDATE_ROOM = 33; 6 | public static final int CMD_UPDATE_SOUND = 34; 7 | public static final int CMD_UPDATE_LOCK = 38; 8 | public static final int CMD_CHANGE_ROOM = 28; 9 | 10 | // S -> C 11 | public static final int ON_UPDATE_ROOM = 33; 12 | public static final int ON_UPDATE_SOUND = 34; 13 | public static final int ON_UPDATE_LOCK = 38; 14 | public static final int ON_CHANGE_ROOM = 28; 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/constants/Packets.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver.constants; 9 | 10 | public class Packets { 11 | // C->S 12 | public static final int CMD_LOGIN = 0; 13 | public static final int CMD_LOGOUT = 2; 14 | public static final int CMD_JOIN_GAME = 11; 15 | public static final int CMD_LEAVE_ROOM = 13; 16 | public static final int CMD_ENTER_MULTIGAME = 14; 17 | public static final int CMD_MULTIGAME = 15; 18 | public static final int CMD_QUIT_GAME = 16; 19 | public static final int CMD_ROTATE = 19; 20 | public static final int CMD_MOVE = 20; 21 | public static final int CMD_FORCE_COORD = 21; 22 | public static final int CMD_GOTO_PLAYER = 23; 23 | public static final int CMD_JOIN_ROOM = 25; 24 | public static final int CMD_JOIN_HOME = 26; 25 | public static final int CMD_GET_OPEN_HOUSES = 27; 26 | public static final int CMD_GET_ALL_HOUSES = 29; 27 | public static final int CMD_UPDATE_PLAYERS = 35; 28 | public static final int CMD_UPDATE_PLAYER = 37; 29 | public static final int CMD_CHAT = 40; 30 | public static final int CMD_EMOTE = 41; 31 | public static final int CMD_SEND_ECARD = 42; 32 | public static final int CMD_SAFE_CHAT = 43; 33 | public static final int CMD_PROFILE_TEXT = 44; 34 | public static final int CMD_ACTION = 50; 35 | public static final int CMD_ADDBUDDY = 60; 36 | public static final int CMD_GET_ROOM_ATTENDEES = 70; 37 | public static final int CMD_PLAYER_TO_PLAYER = 113; 38 | public static final int CMD_REPORT_PLAYER = 114; 39 | public static final int CMD_LOCK_PLAYER = 115; 40 | public static final int CMD_SMS_ABO_RECIVE = 120; 41 | public static final int CMD_INITIATE_RACE = 200; 42 | public static final int CMD_RESPONSE_RACE_REQUEST = 201; 43 | public static final int CMD_POKOPET_PRIVATEINVITE_CANCELLED = 202; 44 | public static final int CMD_SET_PLAYER_STATUS = 210; 45 | public static final int CMD_GET_PLAYER_LOCATION = 211; 46 | public static final int CMD_GET_PLAYER_IDS_BY_CLOTHES = 212; 47 | public static final int CMD_RESPONSE_PUBLIC_RACE_MATCHFOUND = 250; 48 | public static final int CMD_SET_SINGLE_PLAYER_MODE = 300; 49 | public static final int CMD_PING = 1050; 50 | public static final int CMD_SHOW_GS_MSG = 260; 51 | public static final int CMD_RECIEVE_NEW_MSGBOARD_MSG = 270; 52 | public static final int CMD_GET_SALT = 301; 53 | 54 | // Special 55 | 56 | public static final int CMD_INFOMESSAGE = 900; 57 | 58 | // S->C 59 | public static final int RES_ON_LOGIN = 0; 60 | public static final int RES_DISCONNECT = 2; 61 | public static final int RES_LOGOUT_SUCCESS = 3; 62 | public static final int RES_ON_ROOM_JOINED = 10; 63 | public static final int RES_ON_SINGLEGAME_JOINED = 11; 64 | public static final int RES_ON_SUBROOM_ENTER = 12; 65 | public static final int RES_ON_MULTIGAME_MESSAGE = 15; 66 | public static final int RES_MOVE_AVATAR = 20; 67 | public static final int RES_GOTO_PLAYER = 23; 68 | public static final int RES_ON_HOME_JOINED = 26; 69 | public static final int RES_RECEIVE_OPENHOUSES = 27; 70 | public static final int RES_RECEIVE_ALLHOUSES = 29; 71 | public static final int RES_SET_AVATAR = 30; 72 | public static final int RES_UNSET_AVATAR = 31; 73 | public static final int RES_USER_DISCONNECTED = 32; 74 | public static final int RES_UPDATE_PLAYERINFO = 35; 75 | public static final int RES_UPDATE_USERINFO = 37; 76 | public static final int RES_CHAT_MSG = 40; 77 | public static final int RES_EMOTE_MSG = 41; 78 | public static final int RES_RECEIVE_ECARD = 42; 79 | public static final int RES_TOGGLE_SAFE_CHAT = 45; 80 | public static final int RES_ON_HOME_LOCKED = 46; 81 | public static final int RES_DO_ACTION = 50; 82 | public static final int RES_ADD_BUDDY = 60; 83 | public static final int RES_UPDATE_BUDDY_STATUS = 61; 84 | public static final int RES_GET_ROOM_ATTENDEES = 70; 85 | public static final int RES_RECEIVE_ALERT = 80; 86 | public static final int RES_RECEIVE_MODERATORMSG = 81; 87 | public static final int RES_RECEIVE_PROFILE_BADWORD = 92; 88 | public static final int RES_RECEIVE_PROFILE_FIELD_OK = 93; 89 | public static final int RES_MICROPAY_SUCCES = 110; 90 | public static final int RES_MICROPAY_FAILED = 111; 91 | public static final int RES_MICROPAY_ROLLBACK = 112; 92 | public static final int RES_PLAYER_TO_PLAYER = 113; 93 | public static final int RES_ON_SMS_ABO_RECIEVED = 120; 94 | public static final int RES_HOTBOMB_OWNER_CHANGED = 122; 95 | public static final int RES_HOTBOMB_EXPLODE = 123; 96 | public static final int RES_HOTBOMB_STATUS_RECEIVED = 124; 97 | public static final int RES_HOTBOMB_START_GAME = 125; 98 | public static final int RES_SOCCERGAME_STATUS_RECEIVED = 130; 99 | public static final int RES_SOCCERGAME_START_GAME = 131; 100 | public static final int RES_SOCCERGAME_BALL_SHOOT = 132; 101 | public static final int RES_SOCCERGAME_GOAL = 133; 102 | public static final int RES_SOCCERGAME_OVER = 134; 103 | public static final int RES_SOCCERGAME_TEAM_INFO = 135; 104 | public static final int RES_SOCCERGAME_JOIN_TEAM = 136; 105 | public static final int RES_PETRACE_PRIVATE_REQUEST = 200; 106 | public static final int RES_PETRACE_PRIVATE_RESPONSE = 201; 107 | public static final int RES_PETRACE_PRIVATE_CANCELLED = 202; 108 | public static final int RES_PLAYER_STATUS_REQUEST = 210; 109 | public static final int RES_PLAYER_LOCATION_REQUEST = 211; 110 | public static final int RES_PLAYER_IDS_BY_CLOTHES_REQUEST = 212; 111 | public static final int RES_PETRACE_PUBLIC_MATCHFOUND = 250; 112 | public static final int RES_RECEIVE_SHARED_ITEMS = 140; 113 | public static final int RES_ON_SHOW_GS_MSG = 260; 114 | public static final int RES_ON_MSGBOARD_NEW_MSG_RECIEVED = 270; 115 | public static final int RES_ON_CONTAINER_UPDATE = 280; 116 | public static final int RES_ON_GET_SALT = 301; 117 | public static final int RES_ON_GET_ROBOT_ATTACK = 302; 118 | public static final int RES_ON_GET_SP_GP = 310; 119 | 120 | // Special 121 | 122 | public static final int RES_ON_INFO_ACKNOWLEDGEMENT = 901; 123 | 124 | public static String headerToName(int header) { 125 | if (header == 0) { 126 | return "CMD_LOGIN"; 127 | } 128 | if (header == 2) { 129 | return "CMD_LOGOUT"; 130 | } 131 | if (header == 11) { 132 | return "CMD_JOIN_GAME"; 133 | } 134 | if (header == 13) { 135 | return "CMD_LEAVE_ROOM"; 136 | } 137 | if (header == 14) { 138 | return "CMD_ENTER_MULTIGAME"; 139 | } 140 | if (header == 15) { 141 | return "CMD_MULTIGAME"; 142 | } 143 | if (header == 16) { 144 | return "CMD_QUIT_GAME"; 145 | } 146 | if (header == 19) { 147 | return "CMD_ROTATE"; 148 | } 149 | if (header == 20) { 150 | return "CMD_MOVE"; 151 | } 152 | if (header == 21) { 153 | return "CMD_FORCE_COORD"; 154 | } 155 | if (header == 23) { 156 | return "CMD_GOTO_PLAYER"; 157 | } 158 | if (header == 25) { 159 | return "CMD_JOIN_ROOM"; 160 | } 161 | if (header == 26) { 162 | return "CMD_JOIN_HOME"; 163 | } 164 | if (header == 27) { 165 | return "CMD_GET_OPEN_HOUSES"; 166 | } 167 | if (header == 29) { 168 | return "CMD_GET_ALL_HOUSES"; 169 | } 170 | if (header == 35) { 171 | return "CMD_UPDATE_PLAYERS"; 172 | } 173 | if (header == 37) { 174 | return "CMD_UPDATE_PLAYER"; 175 | } 176 | if (header == 40) { 177 | return "CMD_CHAT"; 178 | } 179 | if (header == 41) { 180 | return "CMD_EMOTE"; 181 | } 182 | if (header == 42) { 183 | return "CMD_SEND_ECARD"; 184 | } 185 | if (header == 43) { 186 | return "CMD_SAFE_CHAT"; 187 | } 188 | if (header == 44) { 189 | return "CMD_PROFILE_TEXT"; 190 | } 191 | if (header == 50) { 192 | return "CMD_ACTION"; 193 | } 194 | if (header == 60) { 195 | return "CMD_ADDBUDDY"; 196 | } 197 | if (header == 70) { 198 | return "CMD_GET_ROOM_ATTENDEES"; 199 | } 200 | if (header == 113) { 201 | return "CMD_PLAYER_TO_PLAYER"; 202 | } 203 | if (header == 114) { 204 | return "CMD_REPORT_PLAYER"; 205 | } 206 | if (header == 115) { 207 | return "CMD_LOCK_PLAYER"; 208 | } 209 | if (header == 120) { 210 | return "CMD_SMS_ABO_RECIVE"; 211 | } 212 | if (header == 200) { 213 | return "CMD_INITIATE_RACE"; 214 | } 215 | if (header == 201) { 216 | return "CMD_RESPONSE_RACE_REQUEST"; 217 | } 218 | if (header == 202) { 219 | return "CMD_POKOPET_PRIVATEINVITE_CANCELLED"; 220 | } 221 | if (header == 210) { 222 | return "CMD_SET_PLAYER_STATUS"; 223 | } 224 | if (header == 211) { 225 | return "CMD_GET_PLAYER_LOCATION"; 226 | } 227 | if (header == 212) { 228 | return "CMD_GET_PLAYER_IDS_BY_CLOTHES"; 229 | } 230 | if (header == 250) { 231 | return "CMD_RESPONSE_PUBLIC_RACE_MATCHFOUND"; 232 | } 233 | if (header == 300) { 234 | return "CMD_SET_SINGLE_PLAYER_MODE"; 235 | } 236 | if (header == 1050) { 237 | return "CMD_PING"; 238 | } 239 | if (header == 260) { 240 | return "CMD_SHOW_GS_MSG"; 241 | } 242 | if (header == 270) { 243 | return "CMD_RECIEVE_NEW_MSGBOARD_MSG"; 244 | } 245 | if (header == 301) { 246 | return "CMD_GET_SALT"; 247 | } 248 | return "(Unknown)"; 249 | } 250 | } 251 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/constants/PlayerToPlayerCommands.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver.constants; 9 | 10 | public class PlayerToPlayerCommands { 11 | public static final int P2P_RECEIVER_ALL = -1; 12 | public static final int P2P_RECEIVER_ROOM = -2; 13 | public static final int CMD_CREATE_AVATAR = 10; 14 | public static final int CMD_UPDATE_AVATAR = 11; 15 | public static final int CMD_USE_SHARED_ITEM = 12; 16 | public static final int CMD_SET_TRANSFORMATION = 13; 17 | public static final int CMD_SHOW_STATUS = 14; 18 | public static final int CMD_HIDE_STATUS = 15; 19 | public static final int CMD_ELEMENT_CLICKED = 16; 20 | public static final int CMD_REMOVE_AVATAR = 17; 21 | public static final int CMD_KICK_AVATAR = 18; 22 | public static final int CMD_SEND_SOUND = 19; 23 | public static final int CMD_SEND_REPORT_FEEDBACK = 20; 24 | public static final int CMD_SEND_POPUP = 21; 25 | public static final int CMD_GREYOUT_MC = 22; 26 | public static final int CMD_SPAWN_SLIME = 23; 27 | public static final int CMD_SEND_EVIL_CHAT = 24; 28 | public static final int CMD_SEND_NO_EVIL = 25; 29 | public static final int CMD_SEND_TT = 26; 30 | public static final int CMD_SEND_UNTT = 27; 31 | public static final int ON_CREATE_AVATAR = CMD_CREATE_AVATAR; 32 | public static final int ON_UPDATE_AVATAR = CMD_UPDATE_AVATAR; 33 | public static final int ON_REMOVE_AVATAR = CMD_REMOVE_AVATAR; 34 | public static final int ON_USE_SHARED_ITEM = CMD_USE_SHARED_ITEM; 35 | public static final int ON_SET_TRANSFORMATION = CMD_SET_TRANSFORMATION; 36 | public static final int ON_SHOW_STATUS = CMD_SHOW_STATUS; 37 | public static final int ON_HIDE_STATUS = CMD_HIDE_STATUS; 38 | public static final int ON_ELEMENT_CLICKED = CMD_ELEMENT_CLICKED; 39 | public static final int ON_KICK_AVATAR = CMD_KICK_AVATAR; 40 | public static final int ON_SEND_SOUND = CMD_SEND_SOUND; 41 | public static final int ON_SEND_REPORT_FEEDBACK = CMD_SEND_REPORT_FEEDBACK; 42 | public static final int ON_SEND_POPUP_FEEDBACK = CMD_SEND_POPUP; 43 | public static final int ON_GREYOUT_FEEDBACK = CMD_GREYOUT_MC; 44 | public static final int ON_SPAWN_SLIME = CMD_SPAWN_SLIME; 45 | public static final int ON_SEND_EVIL_CHAT = CMD_SEND_EVIL_CHAT; 46 | public static final int ON_SEND_NO_EVIL = CMD_SEND_NO_EVIL; 47 | public static final int ON_SEND_TT = CMD_SEND_TT; 48 | public static final int ON_SEND_UNTT = CMD_SEND_UNTT; 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/constants/RoomCommands.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver.constants; 9 | 10 | public class RoomCommands { 11 | public static final int GET_ROOM_INFO = 70; 12 | 13 | public static final int QUERY_SHARED_ITEMS = 140; 14 | 15 | public static final int TYPE_GETITEMSTATE = 0; 16 | 17 | public static final int TYPE_GETITEMSSTATE = 1; 18 | 19 | public static final int TYPE_UPDATEITEMSTATE = 2; 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/database/Database.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver.database; 9 | 10 | import java.sql.Connection; 11 | import java.sql.SQLException; 12 | import java.util.Properties; 13 | 14 | import org.openpanfu.gameserver.GameServer; 15 | import org.openpanfu.gameserver.util.Logger; 16 | 17 | import com.zaxxer.hikari.HikariConfig; 18 | import com.zaxxer.hikari.HikariDataSource; 19 | 20 | public class Database { 21 | private static HikariDataSource dataSource; 22 | 23 | public static boolean connect() { 24 | HikariConfig config = new HikariConfig(); 25 | try { 26 | Properties properties = GameServer.getProperties(); 27 | config.setJdbcUrl(String.format( 28 | "jdbc:mysql://%s:%s/%s?useJDBCCompliantTimezoneShift=true&useLegacyDatetimeCode=false&serverTimezone=UTC", 29 | properties.getProperty("database.host"), properties.getProperty("database.port"), 30 | properties.getProperty("database.database"))); 31 | config.setUsername(properties.getProperty("database.user")); 32 | config.setPassword(properties.getProperty("database.pass")); 33 | config.setDriverClassName("com.mysql.cj.jdbc.Driver"); 34 | config.addDataSourceProperty("cachePrepStmts", "true"); 35 | config.addDataSourceProperty("prepStmtCacheSize", "250"); 36 | config.addDataSourceProperty("prepStmtCacheSqlLimit", "2048"); 37 | config.addDataSourceProperty("tcpKeepAlive", true); 38 | config.addDataSourceProperty("maxReconnects", 6); 39 | config.addDataSourceProperty("useSSL", "false"); 40 | } catch (Exception e) { 41 | Logger.error("There was an error initializing the database connection."); 42 | e.printStackTrace(); 43 | return false; 44 | } 45 | dataSource = new HikariDataSource(config); 46 | return true; 47 | } 48 | 49 | public static Connection getConnection() throws SQLException { 50 | return dataSource.getConnection(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/database/GameServerData.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver.database; 9 | 10 | public class GameServerData { 11 | public int id; 12 | public String name; 13 | public int playerCount; 14 | public String url; 15 | public int port; 16 | public boolean goldpanda; 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/database/UserData.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver.database; 9 | 10 | public class UserData { 11 | public int id; 12 | public String name; 13 | public String email; 14 | public int sex; 15 | public String ticket_id; 16 | public int goldpanda; 17 | public int sheriff; 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/database/dao/GameServerDAO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver.database.dao; 9 | 10 | import java.sql.Connection; 11 | import java.sql.PreparedStatement; 12 | import java.sql.ResultSet; 13 | import java.sql.SQLException; 14 | import java.sql.Statement; 15 | import java.util.ArrayList; 16 | import java.util.List; 17 | import java.util.concurrent.ThreadLocalRandom; 18 | 19 | import org.openpanfu.gameserver.GameServer; 20 | import org.openpanfu.gameserver.database.Database; 21 | import org.openpanfu.gameserver.database.GameServerData; 22 | import org.openpanfu.gameserver.util.Key; 23 | 24 | public class GameServerDAO { 25 | 26 | /** 27 | * Returns a list of all the GameServers present in the database. 28 | * 29 | * @author Altro50 30 | * @return List 31 | */ 32 | public static List getGameServers() { 33 | List gameservers = new ArrayList(); 34 | Connection database = null; 35 | try { 36 | 37 | database = Database.getConnection(); 38 | Statement st = database.createStatement(); 39 | String query = ("SELECT * FROM gameservers ORDER BY id;"); 40 | ResultSet resultSet = st.executeQuery(query); 41 | 42 | while (resultSet.next()) { 43 | GameServerData data = new GameServerData(); 44 | data.id = resultSet.getInt("id"); 45 | data.playerCount = resultSet.getInt("player_count"); 46 | data.name = resultSet.getString("name"); 47 | data.url = resultSet.getString("url"); 48 | data.port = resultSet.getInt("port"); 49 | data.goldpanda = resultSet.getBoolean("goldpanda"); 50 | gameservers.add(data); 51 | } 52 | 53 | return gameservers; 54 | 55 | } catch (SQLException e) { 56 | e.printStackTrace(); 57 | } finally { 58 | try { 59 | database.close(); 60 | } catch (SQLException e) { 61 | e.printStackTrace(); 62 | } 63 | } 64 | return null; 65 | } 66 | 67 | /** 68 | * Sets up the keys for the GameServer, allowing the Information Server to 69 | * communicate with the GameServer securely. 70 | * 71 | * @param gameserver GameServer object 72 | */ 73 | public static void setupKeys(GameServer gameserver) { 74 | Connection database = null; 75 | try { 76 | database = Database.getConnection(); 77 | Key keygen = new Key(64, ThreadLocalRandom.current()); 78 | gameserver.setKey(keygen.nextString()); 79 | PreparedStatement preparedStatement = database 80 | .prepareStatement("UPDATE gameservers SET secret_key = ? where id = ?"); 81 | preparedStatement.setString(1, gameserver.getKey()); 82 | preparedStatement.setInt(2, gameserver.getId()); 83 | preparedStatement.executeUpdate(); 84 | } catch (SQLException e) { 85 | e.printStackTrace(); 86 | } finally { 87 | try { 88 | database.close(); 89 | } catch (SQLException e) { 90 | e.printStackTrace(); 91 | } 92 | } 93 | } 94 | 95 | /** 96 | * Updates the player count 97 | * 98 | * @param serverId Server id 99 | * @param playerCount The user count 100 | */ 101 | public static void updateUserCount(int serverId, int playerCount) { 102 | Connection database = null; 103 | try { 104 | database = Database.getConnection(); 105 | PreparedStatement preparedStatement = database 106 | .prepareStatement("UPDATE gameservers SET player_count = ? where id = ?"); 107 | preparedStatement.setInt(1, playerCount); 108 | preparedStatement.setInt(2, serverId); 109 | preparedStatement.executeUpdate(); 110 | } catch (SQLException e) { 111 | e.printStackTrace(); 112 | } finally { 113 | try { 114 | database.close(); 115 | } catch (SQLException e) { 116 | e.printStackTrace(); 117 | } 118 | } 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/database/dao/UserDAO.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver.database.dao; 9 | 10 | import java.sql.Connection; 11 | import java.sql.PreparedStatement; 12 | import java.sql.ResultSet; 13 | import java.sql.SQLException; 14 | 15 | import org.openpanfu.gameserver.database.Database; 16 | import org.openpanfu.gameserver.database.UserData; 17 | 18 | public class UserDAO { 19 | 20 | /** 21 | * Returns the user with the specified id, returns null if not found. 22 | * 23 | * @author Altro50 24 | * @param int id The user's id. 25 | * @return UserData | Null 26 | */ 27 | public static UserData getById(int id) { 28 | Connection database = null; 29 | try { 30 | database = Database.getConnection(); 31 | PreparedStatement preparedStatement = database.prepareStatement("SELECT * FROM users WHERE id = ? LIMIT 1"); 32 | preparedStatement.setInt(1, id); 33 | ResultSet resultSet = preparedStatement.executeQuery(); 34 | if (resultSet.next()) { 35 | UserData data = new UserData(); 36 | data.id = resultSet.getInt("id"); 37 | data.name = resultSet.getString("name"); 38 | data.email = resultSet.getString("email"); 39 | data.sex = resultSet.getInt("sex"); 40 | data.ticket_id = resultSet.getString("ticket_id"); 41 | data.goldpanda = resultSet.getInt("goldpanda"); 42 | data.sheriff = resultSet.getInt("sheriff"); 43 | return data; 44 | } 45 | } catch (SQLException e) { 46 | System.err.println("[UserDAO] -- Error getting user by id!"); 47 | e.printStackTrace(); 48 | } finally { 49 | try { 50 | database.close(); 51 | } catch (SQLException e) { 52 | e.printStackTrace(); 53 | } 54 | } 55 | return null; 56 | } 57 | 58 | /** 59 | * Returns the user with the specified id AND ticket, returns null if not found. 60 | * 61 | * @author Altro50 62 | * @param int id The user's id 63 | * @param int ticket the user's ticket, they will give this ticket in CMD_LOGIN. 64 | * @return Void 65 | */ 66 | public static UserData getByIdAndTicket(int id, int ticket) { 67 | Connection database = null; 68 | try { 69 | database = Database.getConnection(); 70 | PreparedStatement preparedStatement = database 71 | .prepareStatement("SELECT * FROM users WHERE id = ? AND ticket_id = ? LIMIT 1"); 72 | preparedStatement.setInt(1, id); 73 | preparedStatement.setInt(2, ticket); 74 | ResultSet resultSet = preparedStatement.executeQuery(); 75 | if (resultSet.next()) { 76 | UserData data = new UserData(); 77 | data.id = resultSet.getInt("id"); 78 | data.name = resultSet.getString("name"); 79 | data.email = resultSet.getString("email"); 80 | data.sex = resultSet.getInt("sex"); 81 | data.ticket_id = resultSet.getString("ticket_id"); 82 | data.goldpanda = resultSet.getInt("goldpanda"); 83 | data.sheriff = resultSet.getInt("sheriff"); 84 | return data; 85 | } 86 | } catch (SQLException e) { 87 | System.err.println("[UserDAO] -- Error getting user by id and ticket!"); 88 | e.printStackTrace(); 89 | } finally { 90 | try { 91 | database.close(); 92 | } catch (SQLException e) { 93 | e.printStackTrace(); 94 | } 95 | } 96 | return null; 97 | } 98 | 99 | /** 100 | * Sets the user specified by id's session ticket to null, so they cannot reuse 101 | * their ticket. 102 | * 103 | * @author Altro50 104 | * @param int id User Id. 105 | * @return UserData | Null 106 | */ 107 | public static void nullTicket(int id) { 108 | Connection database = null; 109 | try { 110 | database = Database.getConnection(); 111 | PreparedStatement preparedStatement = database 112 | .prepareStatement("UPDATE users SET ticket_id = NULL where id = ?"); 113 | preparedStatement.setInt(1, id); 114 | preparedStatement.executeUpdate(); 115 | database.close(); 116 | } catch (SQLException e) { 117 | e.printStackTrace(); 118 | } finally { 119 | try { 120 | database.close(); 121 | } catch (SQLException e) { 122 | e.printStackTrace(); 123 | } 124 | } 125 | } 126 | 127 | /** 128 | * Sets the user specified by id's current gameserver, so their friends will 129 | * know which server the user is on. 130 | * 131 | * @author Altro50 132 | * @param int id User Id. 133 | * @return Void 134 | */ 135 | public static void setCurrentGameServer(int id, int currentGameServer) { 136 | Connection database = null; 137 | try { 138 | database = Database.getConnection(); 139 | PreparedStatement preparedStatement = database 140 | .prepareStatement("UPDATE users SET current_gameserver = ? where id = ?"); 141 | preparedStatement.setInt(1, currentGameServer); 142 | preparedStatement.setInt(2, id); 143 | preparedStatement.executeUpdate(); 144 | database.close(); 145 | } catch (SQLException e) { 146 | e.printStackTrace(); 147 | } finally { 148 | try { 149 | database.close(); 150 | } catch (SQLException e) { 151 | e.printStackTrace(); 152 | } 153 | } 154 | } 155 | 156 | /** 157 | * Sets the user specified by id's current gameserver to NULL, so their friends 158 | * will know the user isn't online. 159 | * 160 | * @author Altro50 161 | * @param int id User Id. 162 | * @return Void 163 | */ 164 | public static void clearCurrentGameServer(int id) { 165 | Connection database = null; 166 | try { 167 | database = Database.getConnection(); 168 | PreparedStatement preparedStatement = database 169 | .prepareStatement("UPDATE users SET current_gameserver = NULL where id = ?"); 170 | preparedStatement.setInt(1, id); 171 | preparedStatement.executeUpdate(); 172 | database.close(); 173 | } catch (SQLException e) { 174 | e.printStackTrace(); 175 | } finally { 176 | try { 177 | database.close(); 178 | } catch (SQLException e) { 179 | e.printStackTrace(); 180 | } 181 | } 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/games/multiplayer/FourBoom.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.games.multiplayer; 2 | 3 | import org.openpanfu.gameserver.PanfuPacket; 4 | import org.openpanfu.gameserver.User; 5 | import org.openpanfu.gameserver.constants.Packets; 6 | import org.openpanfu.gameserver.util.Logger; 7 | 8 | public class FourBoom { 9 | private GameQueue queue = new GameQueue(); 10 | 11 | // Called on CMD_ENTER_MULTIGAME 12 | public void onEnter(User user) { 13 | // First we check if someone else is already in the queue. 14 | if (queue.hasUserWaiting()) { 15 | // We join this user's session. 16 | User victim = queue.get(); 17 | victim.setMultiGamePartner(user); 18 | user.setMultiGamePartner(victim); 19 | Logger.info(String.format("[4boom] Player %s was matched with %s from the 4boom queue!", user.getUsername(), 20 | victim.getUsername())); 21 | // Packets to start the game 22 | PanfuPacket player1StartPacket = new PanfuPacket(Packets.RES_ON_MULTIGAME_MESSAGE); 23 | player1StartPacket.writeInt(25); // Game id 24 | player1StartPacket.writeInt(0); // Sender (0 = server, I guess) 25 | player1StartPacket.writeString("setPlayer"); 26 | player1StartPacket.writeInt(1); 27 | PanfuPacket player2StartPacket = new PanfuPacket(Packets.RES_ON_MULTIGAME_MESSAGE); 28 | player2StartPacket.writeInt(25); // Game id 29 | player2StartPacket.writeInt(0); // Sender (0 = server, I guess) 30 | player2StartPacket.writeString("setPlayer"); 31 | player2StartPacket.writeInt(2); 32 | user.sendPacket(player1StartPacket); 33 | victim.sendPacket(player2StartPacket); 34 | } else { 35 | Logger.info(String.format("[4boom] Player %s joined the 4boom queue!", user.getUsername())); 36 | queue.put(user); 37 | } 38 | } 39 | 40 | // If the user leaves or disconnects 41 | public void onExit(User user) { 42 | Logger.info(String.format("[4boom] Player %s left the 4boom queue!", user.getUsername())); 43 | queue.removeUserIfIn(user); 44 | if (user.getMultiGamePartner() != null) { 45 | // We need to inform the partner that the user has left. 46 | PanfuPacket quitPacket = new PanfuPacket(Packets.RES_ON_MULTIGAME_MESSAGE); 47 | quitPacket.writeInt(25); // Game id 48 | quitPacket.writeInt(user.getUserId()); // Sender (0 = server, I guess) 49 | quitPacket.writeString("unsetPlayer"); 50 | quitPacket.writeInt(user.getUserId()); // user id 51 | user.getMultiGamePartner().sendPacket(quitPacket); 52 | user.getMultiGamePartner().setMultiGamePartner(null); 53 | user.setMultiGamePartner(null); 54 | } 55 | } 56 | 57 | // Called on CMD_MULTIGAME, used to inform the other user of a multiplayer 58 | // interaction 59 | public void onMessage(User user, PanfuPacket panfuPacket) { 60 | int gameId = panfuPacket.readInt(); 61 | int senderId = panfuPacket.readInt(); 62 | String action = panfuPacket.readString(); 63 | String parameter = panfuPacket.readString(); 64 | User partner = user.getMultiGamePartner(); 65 | if (partner != null) { 66 | PanfuPacket information = new PanfuPacket(Packets.RES_ON_MULTIGAME_MESSAGE); 67 | information.writeInt(25); // Game id 68 | information.writeInt(user.getUserId()); // Sender (0 = server, I guess) 69 | information.writeInt(senderId); 70 | information.writeString(action); 71 | information.writeString(parameter); 72 | partner.sendPacket(information); 73 | } 74 | } 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/games/multiplayer/GameQueue.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.games.multiplayer; 2 | 3 | import java.util.LinkedList; 4 | 5 | import org.openpanfu.gameserver.User; 6 | 7 | public class GameQueue { 8 | private LinkedList list = new LinkedList<>(); 9 | 10 | public void put(User user) { 11 | list.addLast(user); 12 | } 13 | 14 | // Allows us to check whether there's still someone in the queue 15 | public User peek() { 16 | return list.getFirst(); 17 | } 18 | 19 | public boolean hasUserWaiting() { 20 | try { 21 | return (list.getFirst() != null); 22 | } catch (Exception e) { 23 | return false; 24 | } 25 | } 26 | 27 | // Removes and returns the user 28 | public User get() { 29 | // Could happen, who knows. 30 | if (list.isEmpty()) { 31 | return null; 32 | } 33 | return list.removeFirst(); 34 | } 35 | 36 | public void removeUserIfIn(User user) { 37 | if (list.contains(user)) 38 | list.remove(user); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/games/multiplayer/RockPaperScissors.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.games.multiplayer; 2 | 3 | import org.openpanfu.gameserver.PanfuPacket; 4 | import org.openpanfu.gameserver.User; 5 | import org.openpanfu.gameserver.constants.Packets; 6 | import org.openpanfu.gameserver.util.Logger; 7 | 8 | public class RockPaperScissors { 9 | 10 | public void onEnter(User sender) { 11 | // Other player is ready, we can start. 12 | if (sender.getMultiGamePartner().getCurrentGame() == 41) { 13 | User victim = sender.getMultiGamePartner(); 14 | Logger.info(String.format("[RPS] Player %s started a RPS match with %s!", sender.getUsername(), 15 | victim.getUsername())); 16 | // Packets to start the game 17 | PanfuPacket player1StartPacket = new PanfuPacket(Packets.RES_ON_MULTIGAME_MESSAGE); 18 | player1StartPacket.writeInt(41); // Game id 19 | player1StartPacket.writeInt(0); // Sender (0 = server, I guess) 20 | player1StartPacket.writeString("setPlayer"); 21 | player1StartPacket.writeInt(1); 22 | PanfuPacket player2StartPacket = new PanfuPacket(Packets.RES_ON_MULTIGAME_MESSAGE); 23 | player2StartPacket.writeInt(41); // Game id 24 | player2StartPacket.writeInt(0); // Sender (0 = server, I guess) 25 | player2StartPacket.writeString("setPlayer"); 26 | player2StartPacket.writeInt(2); 27 | sender.sendPacket(player1StartPacket); 28 | victim.sendPacket(player2StartPacket); 29 | } 30 | } 31 | 32 | // If the user leaves or disconnects 33 | public void onExit(User user) { 34 | Logger.info(String.format("[RPS] Player %s left RPS!", user.getUsername())); 35 | if (user.getMultiGamePartner() != null) { 36 | // We need to inform the partner that the user has left. 37 | PanfuPacket quitPacket = new PanfuPacket(Packets.RES_ON_MULTIGAME_MESSAGE); 38 | quitPacket.writeInt(41); // Game id 39 | quitPacket.writeInt(user.getUserId()); // Sender (0 = server, I guess) 40 | quitPacket.writeString("unsetPlayer"); 41 | quitPacket.writeInt(user.getUserId()); // user id 42 | user.getMultiGamePartner().sendPacket(quitPacket); 43 | user.getMultiGamePartner().setMultiGamePartner(null); 44 | user.setMultiGamePartner(null); 45 | } 46 | } 47 | 48 | // Called on CMD_MULTIGAME, used to inform the other user of a multiplayer 49 | // interaction 50 | public void onMessage(User user, PanfuPacket panfuPacket) { 51 | int gameId = panfuPacket.readInt(); 52 | int senderId = panfuPacket.readInt(); 53 | String action = panfuPacket.readString(); 54 | String parameter = panfuPacket.readString(); 55 | User partner = user.getMultiGamePartner(); 56 | if (partner != null) { 57 | PanfuPacket information = new PanfuPacket(Packets.RES_ON_MULTIGAME_MESSAGE); 58 | information.writeInt(41); // Game id 59 | information.writeInt(user.getUserId()); // Sender (0 = server, I guess) 60 | information.writeInt(senderId); 61 | information.writeString(action); 62 | information.writeString(parameter); 63 | partner.sendPacket(information); 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_ACTION.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | import java.util.concurrent.ThreadLocalRandom; 7 | 8 | import org.openpanfu.gameserver.GameServer; 9 | import org.openpanfu.gameserver.PanfuPacket; 10 | import org.openpanfu.gameserver.User; 11 | import org.openpanfu.gameserver.constants.Packets; 12 | import org.openpanfu.gameserver.util.Logger; 13 | 14 | public class CMD_ACTION implements IHandler { 15 | final List throwables = Collections.unmodifiableList(new ArrayList() { 16 | { 17 | add("waterbomb"); 18 | add("slimebomb"); 19 | add("slimebombSprite"); 20 | add("sendFlyingCup"); 21 | add("flyingCup"); 22 | add("sendFlyingBottle"); 23 | add("flyingBottle"); 24 | add("sendPancake"); 25 | add("pancake"); 26 | add("flyingPillow"); 27 | add("sendFlyingBottle2"); 28 | add("flyingBottle2"); 29 | add("sendCake"); 30 | add("cake"); 31 | add("blueSlimebombSprite"); 32 | add("pinkSlimebombSprite"); 33 | add("icecubeSpell"); 34 | add("masterOfIce"); 35 | add("hole"); 36 | add("teleportation"); 37 | add("gameInvite"); 38 | add("gameInvite_41_"); 39 | } 40 | }); 41 | 42 | @Override 43 | public void handlePacket(PanfuPacket packet, User sender) { 44 | if (Integer.valueOf(GameServer.getProperties().getProperty("actions.antispam.enabled")) != 0) { 45 | int seconds = Integer 46 | .parseInt(GameServer.getProperties().getProperty("actions.antispam.secondsbetweenactions")); 47 | if ((System.currentTimeMillis() - sender.getLastActionPerformedTime()) < (seconds * 1000)) { 48 | sender.giveActionSpamWarning(); 49 | return; 50 | } 51 | } 52 | String action = packet.readString(); 53 | if (!action.equals("")) { 54 | PanfuPacket actionBroadcast = new PanfuPacket(Packets.RES_DO_ACTION); 55 | actionBroadcast.writeInt(sender.getUserId()); 56 | 57 | // Is throwable 58 | if (action.equals("throw")) { 59 | if (throwables.contains(sender.getLastActionPerformed())) { 60 | int throwX = packet.readInt(); 61 | int throwY = packet.readInt(); 62 | String toThrow = packet.readString(); 63 | int victim = packet.readInt(); 64 | if (throwables.contains(toThrow)) { 65 | actionBroadcast.writeString("throw"); 66 | actionBroadcast.writeInt(throwX); 67 | actionBroadcast.writeInt(throwY); 68 | actionBroadcast.writeString(toThrow); 69 | if (victim == -1) { 70 | actionBroadcast.writeString("false"); 71 | } else { 72 | actionBroadcast.writeInt(victim); 73 | actionBroadcast.writeString("false"); 74 | } 75 | sender.setLastActionPerformed(action); 76 | sender.setLastActionPerformedTime(System.currentTimeMillis()); 77 | sender.sendRoom(actionBroadcast); 78 | } else { 79 | sender.sendAlert(String.format("CMD_ACTION: Unknown throwable: %s", toThrow)); 80 | } 81 | } else { 82 | Logger.warning(String.format( 83 | "Prevented user %s (%d) from throwing an item because his last action wasn't a throw action.", 84 | sender.getUsername(), sender.getUserId())); 85 | } 86 | return; 87 | } 88 | 89 | // RPS - GameId 41 90 | if (action.equals("gameInvite")) { 91 | packet.readInt(); // X - Unused in invites, always 0. 92 | packet.readInt(); // Y - Unused in invites, always 0. 93 | int gameId = packet.readInt(); 94 | int userToInvite = packet.readInt(); 95 | actionBroadcast.writeString("gameInvite"); 96 | actionBroadcast.writeInt(0); 97 | actionBroadcast.writeInt(0); 98 | actionBroadcast.writeInt(gameId); 99 | actionBroadcast.writeInt(userToInvite); 100 | actionBroadcast.writeString("false"); 101 | sender.sendRoom(actionBroadcast); 102 | return; 103 | } 104 | 105 | if (action.equals("gameInviteAccepted")) { 106 | packet.readInt(); // X - Unused when accepting, always 0. 107 | int myId = packet.readInt(); 108 | int gameId = packet.readInt(); 109 | int victimId = packet.readInt(); 110 | actionBroadcast.writeString("gameInviteAccepted"); 111 | actionBroadcast.writeInt(0); 112 | actionBroadcast.writeInt(myId); 113 | actionBroadcast.writeInt(gameId); 114 | actionBroadcast.writeInt(victimId); 115 | actionBroadcast.writeString("false"); 116 | sender.sendRoom(actionBroadcast); 117 | return; 118 | } 119 | 120 | if (action.equals("invitedPlayerLoadGame")) { 121 | packet.readInt(); // X - Unused when accepting, always 0. 122 | int myId = packet.readInt(); 123 | int gameId = packet.readInt(); 124 | int victimId = packet.readInt(); 125 | actionBroadcast.writeString("invitedPlayerLoadGame"); 126 | actionBroadcast.writeInt(0); 127 | actionBroadcast.writeInt(myId); 128 | actionBroadcast.writeInt(gameId); 129 | actionBroadcast.writeInt(victimId); 130 | actionBroadcast.writeString("false"); 131 | sender.sendRoom(actionBroadcast); 132 | return; 133 | } 134 | 135 | if (action.equals("gameInviteDenied")) { 136 | packet.readInt(); // X - Unused when accepting, always 0. 137 | int myId = packet.readInt(); 138 | int gameId = packet.readInt(); 139 | int victimId = packet.readInt(); 140 | actionBroadcast.writeString("gameInviteDenied"); 141 | actionBroadcast.writeInt(0); 142 | actionBroadcast.writeInt(myId); 143 | actionBroadcast.writeInt(gameId); 144 | actionBroadcast.writeInt(victimId); 145 | actionBroadcast.writeString("false"); 146 | sender.sendRoom(actionBroadcast); 147 | return; 148 | } 149 | 150 | // Slide 151 | if (action.equals("doSlideAnimation") && sender.getRoomId() == 3) { 152 | final int poolX = 134; 153 | final int poolX2 = 524; 154 | final int poolY = 206; 155 | final int poolY2 = 295; 156 | 157 | int endPosX = packet.readInt(); 158 | int endPosY = packet.readInt(); 159 | packet.readString(); // Not filled by the client 160 | int unknown = packet.readInt(); 161 | actionBroadcast.writeString("doSlideAnimation"); 162 | if (Integer.valueOf(GameServer.getProperties().getProperty("rooms.pool.jumpintotheshowers")) != 0) { 163 | actionBroadcast.writeInt(540); 164 | actionBroadcast.writeInt(390); 165 | } else { 166 | actionBroadcast.writeInt(ThreadLocalRandom.current().nextInt(poolX, poolX2 + 1)); 167 | actionBroadcast.writeInt(ThreadLocalRandom.current().nextInt(poolY, poolY2 + 1)); 168 | } 169 | actionBroadcast.writeString(""); 170 | actionBroadcast.writeInt(unknown); 171 | actionBroadcast.writeString("false"); 172 | sender.setLastActionPerformedTime(System.currentTimeMillis()); 173 | sender.sendRoom(actionBroadcast); 174 | return; 175 | } 176 | if (action.equals("doDivingAnimation") && sender.getRoomId() == 3) { 177 | int endPosX = packet.readInt(); 178 | int endPosY = packet.readInt(); 179 | int plankId = packet.readInt(); 180 | actionBroadcast.writeString("doDivingAnimation"); 181 | if (Integer.valueOf(GameServer.getProperties().getProperty("rooms.pool.jumpintotheshowers")) != 0) { 182 | actionBroadcast.writeInt(540); 183 | actionBroadcast.writeInt(390); 184 | } else { 185 | actionBroadcast.writeInt(endPosX); 186 | actionBroadcast.writeInt(endPosY); 187 | } 188 | actionBroadcast.writeInt(plankId); 189 | actionBroadcast.writeString("false"); 190 | sender.setLastActionPerformedTime(System.currentTimeMillis()); 191 | sender.sendRoom(actionBroadcast); 192 | return; 193 | } 194 | 195 | // Lake slide 196 | if (action.equals("doSlideLakeAnimation") && sender.getRoomId() == 39) { 197 | int endPosX = packet.readInt(); 198 | int endPosY = packet.readInt(); 199 | int height = packet.readInt(); 200 | String hoop = packet.readString(); 201 | actionBroadcast.writeString("doSlideLakeAnimation"); 202 | actionBroadcast.writeInt(endPosX); 203 | actionBroadcast.writeInt(endPosY); 204 | actionBroadcast.writeInt(height); 205 | actionBroadcast.writeString(hoop); 206 | sender.sendRoom(actionBroadcast); 207 | return; 208 | } 209 | actionBroadcast.writeString(action); 210 | sender.setLastActionPerformed(action); 211 | 212 | // Optimization, we don't have to send throwables to everyone. 213 | // This prevents other people from knowing that the player is about to throw 214 | // something. 215 | if (throwables.contains(action)) { 216 | sender.sendPacket(actionBroadcast); 217 | return; 218 | } 219 | sender.setLastActionPerformedTime(System.currentTimeMillis()); 220 | sender.sendRoom(actionBroadcast); 221 | } 222 | } 223 | } 224 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_ADDBUDDY.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler; 2 | 3 | import org.openpanfu.gameserver.PanfuPacket; 4 | import org.openpanfu.gameserver.User; 5 | import org.openpanfu.gameserver.constants.Packets; 6 | 7 | public class CMD_ADDBUDDY implements IHandler { 8 | @Override 9 | public void handlePacket(PanfuPacket packet, User sender) { 10 | int buddyId = packet.readInt(); 11 | String yourUsername = packet.readString(); 12 | User buddy = sender.getGameServer().getSessionManager().getUserById(buddyId); 13 | if (buddy != null) { 14 | PanfuPacket inviteMessage = new PanfuPacket(Packets.RES_ADD_BUDDY); 15 | inviteMessage.writeInt(sender.getUserId()); 16 | inviteMessage.writeString(sender.getUsername()); 17 | buddy.sendPacket(inviteMessage); 18 | } 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_CHANGE_ROOM.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler; 2 | 3 | import org.openpanfu.gameserver.PanfuPacket; 4 | import org.openpanfu.gameserver.User; 5 | 6 | public class CMD_CHANGE_ROOM implements IHandler { 7 | @Override 8 | public void handlePacket(PanfuPacket packet, User sender) { 9 | // STUB 10 | // Not sure why they send this, seeing as I can just read the room the user is 11 | // in... 12 | int roomOwner = packet.readInt(); 13 | // The subroom to enter 14 | int subRoom = packet.readInt(); 15 | // Start x and y 16 | int x = packet.readInt(); 17 | int y = packet.readInt(); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_CHAT.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Arrays; 5 | import java.util.List; 6 | 7 | import org.openpanfu.gameserver.GameServer; 8 | import org.openpanfu.gameserver.PanfuPacket; 9 | import org.openpanfu.gameserver.User; 10 | import org.openpanfu.gameserver.commands.Commands; 11 | import org.openpanfu.gameserver.constants.Packets; 12 | import org.openpanfu.gameserver.plugin.PluginManager; 13 | 14 | public class CMD_CHAT implements IHandler { 15 | @Override 16 | public void handlePacket(PanfuPacket packet, User sender) { 17 | if ((System.currentTimeMillis() - sender.getLastChatMessageTime()) < 100) { 18 | sender.disconnect("CMD_CHAT > You are chatting too fast!"); 19 | return; 20 | } 21 | if (Integer.valueOf(GameServer.getProperties().getProperty("chat.antispam.enabled")) != 0) { 22 | int seconds = Integer 23 | .parseInt(GameServer.getProperties().getProperty("chat.antispam.secondsbetweenmessages")); 24 | if ((System.currentTimeMillis() - sender.getLastChatMessageTime()) < (seconds * 1000)) { 25 | sender.giveChatSpamWarning(); 26 | return; 27 | } 28 | } 29 | if (sender.getGameServer().isChatEnabled()) { 30 | String text = packet.readString(); 31 | if (text.length() > 120) { 32 | sender.disconnect("KICK_SHUTDOWN_MSG"); 33 | } 34 | List textParts = new ArrayList(Arrays.asList(text.split(" "))); 35 | if (textParts.get(0).startsWith("#")) { 36 | textParts.remove(0); 37 | } 38 | 39 | if (textParts.get(0).startsWith(GameServer.getProperties().getProperty("chat.commands.prefix"))) { 40 | String handle = textParts.remove(0).substring(1).toLowerCase(); 41 | String[] commandParameters = textParts.toArray(new String[0]); 42 | Commands.executeCommand(sender, handle, commandParameters); 43 | return; 44 | } 45 | 46 | text = String.join(" ", textParts).replaceAll("\\<[^>]*>", ""); 47 | if (PluginManager.handleUserChat(sender, text)) { 48 | sender.setLastChatMessage(text); 49 | sender.setLastChatMessageTime(System.currentTimeMillis()); 50 | if (sender.getSheriff() > 0) { 51 | text = "#" + GameServer.getProperties().getProperty("chat.sheriff.prefix") + " " + text; 52 | } 53 | 54 | PanfuPacket chatPacket = new PanfuPacket(Packets.RES_CHAT_MSG); 55 | chatPacket.writeInt(sender.getUserId()); 56 | chatPacket.writeString(text); 57 | sender.sendRoom(chatPacket); 58 | PluginManager.onUserChat(sender, text); 59 | } 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_EMOTE.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler; 2 | 3 | import org.openpanfu.gameserver.PanfuPacket; 4 | import org.openpanfu.gameserver.User; 5 | import org.openpanfu.gameserver.constants.Packets; 6 | 7 | public class CMD_EMOTE implements IHandler { 8 | @Override 9 | public void handlePacket(PanfuPacket packet, User sender) { 10 | if ((System.currentTimeMillis() - sender.getLastChatMessageTime()) < 500) { 11 | sender.disconnect("CMD_EMOTE > You are sending emotes too fast!"); 12 | return; 13 | } 14 | int emoteId = packet.readInt(); 15 | PanfuPacket emotePacket = new PanfuPacket(Packets.RES_EMOTE_MSG); 16 | emotePacket.writeInt(sender.getUserId()); 17 | emotePacket.writeInt(emoteId); 18 | sender.setLastChatMessageTime(System.currentTimeMillis()); 19 | sender.sendRoom(emotePacket); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_ENTER_MULTIGAME.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler; 2 | 3 | import org.openpanfu.gameserver.PanfuPacket; 4 | import org.openpanfu.gameserver.User; 5 | 6 | public class CMD_ENTER_MULTIGAME implements IHandler { 7 | @Override 8 | public void handlePacket(PanfuPacket packet, User sender) { 9 | int gameId = packet.readInt(); 10 | int partnerId = packet.readInt(); 11 | if (gameId == 25) { // 4boom 12 | sender.joinGame(25); 13 | sender.getGameServer().getFourBoom().onEnter(sender); 14 | } 15 | if (gameId == 41) { // RPS 16 | User partner = sender.getGameServer().getSessionManager().getUserById(partnerId); 17 | if (partner != null) { 18 | sender.joinGame(41); 19 | sender.setMultiGamePartner(partner); 20 | sender.getGameServer().getRockPaperScissors().onEnter(sender); 21 | } 22 | } 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_GET_ALL_HOUSES.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler; 2 | 3 | import java.util.List; 4 | 5 | import org.openpanfu.gameserver.GameServer; 6 | import org.openpanfu.gameserver.PanfuPacket; 7 | import org.openpanfu.gameserver.User; 8 | import org.openpanfu.gameserver.constants.Packets; 9 | 10 | public class CMD_GET_ALL_HOUSES implements IHandler { 11 | 12 | @Override 13 | public void handlePacket(PanfuPacket packet, User sender) { 14 | PanfuPacket response = new PanfuPacket(Packets.RES_RECEIVE_ALLHOUSES); 15 | GameServer gameserver = sender.getGameServer(); 16 | List users = gameserver.getSessionManager().getUsers(); 17 | for (User user : users) { 18 | if (Integer.valueOf(GameServer.getProperties().getProperty("treehouses.showSheriffAsGold")) != 0) 19 | response.writeString( 20 | String.format("%d:%s:%d", user.getUserId(), user.getUsername(), user.getGoldpanda())); 21 | else 22 | response.writeString(String.format("%d:%s:%d", user.getUserId(), user.getUsername(), 23 | (user.getSheriff() > 1) ? 1 : 0)); 24 | } 25 | sender.sendPacket(response); 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_GET_PLAYER_IDS_BY_CLOTHES.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver.handler; 9 | 10 | import org.openpanfu.gameserver.PanfuPacket; 11 | import org.openpanfu.gameserver.User; 12 | import org.openpanfu.gameserver.constants.Packets; 13 | 14 | public class CMD_GET_PLAYER_IDS_BY_CLOTHES implements IHandler { 15 | /* Now, this is an interesting story. */ 16 | /* 17 | * The only time this is used is for time travel, we don't need to handle it.. 18 | * yet. 19 | */ 20 | @Override 21 | public void handlePacket(PanfuPacket packet, User sender) { 22 | PanfuPacket response = new PanfuPacket(Packets.RES_PLAYER_IDS_BY_CLOTHES_REQUEST); 23 | sender.sendPacket(response); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_GET_ROOM_ATTENDEES.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver.handler; 9 | 10 | import java.util.List; 11 | 12 | import org.openpanfu.gameserver.GameServer; 13 | import org.openpanfu.gameserver.PanfuPacket; 14 | import org.openpanfu.gameserver.User; 15 | import org.openpanfu.gameserver.constants.Packets; 16 | 17 | public class CMD_GET_ROOM_ATTENDEES implements IHandler { 18 | @Override 19 | public void handlePacket(PanfuPacket packet, User sender) { 20 | PanfuPacket roomAttendees = new PanfuPacket(Packets.RES_GET_ROOM_ATTENDEES); 21 | roomAttendees.writeString( 22 | getRoomString(sender.getRoomId(), sender.isInHome(), sender.getSubRoom(), sender.getGameServer())); 23 | sender.sendPacket(roomAttendees); 24 | 25 | PanfuPacket setAvatar = new PanfuPacket(Packets.RES_SET_AVATAR); 26 | setAvatar.writeInt(sender.getUserId()); 27 | setAvatar.writeInt(sender.getRoomId()); 28 | setAvatar.writeInt(sender.getX()); 29 | setAvatar.writeInt(sender.getY()); 30 | setAvatar.writeString(sender.getUsername()); 31 | sender.sendRoomExcludingMe(setAvatar); 32 | sender.setChatEnabled(sender.getGameServer().isChatEnabled()); 33 | } 34 | 35 | private String getRoomString(int roomId, boolean inHome, int subroom, GameServer gameServer) { 36 | String roomString = String.valueOf(roomId); 37 | List users = gameServer.getSessionManager().getUsersInRoom(roomId, inHome, subroom); 38 | for (User user : users) { 39 | if (user.isInHome() == inHome) { 40 | roomString += ";" + user.getPlayerString(); 41 | } 42 | } 43 | return roomString; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_GET_SALT.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver.handler; 9 | 10 | import org.openpanfu.gameserver.PanfuPacket; 11 | import org.openpanfu.gameserver.User; 12 | import org.openpanfu.gameserver.constants.Packets; 13 | 14 | public class CMD_GET_SALT implements IHandler { 15 | @Override 16 | public void handlePacket(PanfuPacket packet, User sender) { 17 | PanfuPacket salt = new PanfuPacket(Packets.RES_ON_GET_SALT); 18 | salt.writeString("P4nfu8Ri5$3*m/#4nt1Ch34t2gHTu.%ru1{<0?K_&45fS4lt6,]-lO5=+354y"); 19 | sender.sendPacket(salt); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_JOIN_GAME.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler; 2 | 3 | import org.openpanfu.gameserver.PanfuPacket; 4 | import org.openpanfu.gameserver.User; 5 | 6 | public class CMD_JOIN_GAME implements IHandler { 7 | @Override 8 | public void handlePacket(PanfuPacket packet, User sender) { 9 | int gameId = packet.readInt(); 10 | sender.joinGame(gameId); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_JOIN_HOME.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler; 2 | 3 | import org.openpanfu.gameserver.PanfuPacket; 4 | import org.openpanfu.gameserver.User; 5 | 6 | public class CMD_JOIN_HOME implements IHandler { 7 | @Override 8 | public void handlePacket(PanfuPacket packet, User sender) { 9 | // The user who's treehouse you'd like to enter 10 | int userId = packet.readInt(); 11 | 12 | // Start X and Y 13 | int x = packet.readInt(); 14 | int y = packet.readInt(); 15 | 16 | sender.setX(x); 17 | sender.setY(y); 18 | 19 | sender.joinHome(userId); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_JOIN_ROOM.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver.handler; 9 | 10 | import org.openpanfu.gameserver.PanfuPacket; 11 | import org.openpanfu.gameserver.User; 12 | 13 | public class CMD_JOIN_ROOM implements IHandler { 14 | 15 | @Override 16 | public void handlePacket(PanfuPacket packet, User sender) { 17 | int roomId = packet.readInt(); 18 | int x = packet.readInt(); 19 | int y = packet.readInt(); 20 | sender.setX(x); 21 | sender.setY(y); 22 | sender.joinRoom(roomId); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_LOGIN.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver.handler; 9 | 10 | import java.util.Random; 11 | 12 | import org.openpanfu.gameserver.PanfuPacket; 13 | import org.openpanfu.gameserver.User; 14 | import org.openpanfu.gameserver.constants.Packets; 15 | import org.openpanfu.gameserver.database.UserData; 16 | import org.openpanfu.gameserver.database.dao.UserDAO; 17 | import org.openpanfu.gameserver.plugin.PluginManager; 18 | import org.openpanfu.gameserver.util.Logger; 19 | 20 | public class CMD_LOGIN implements IHandler { 21 | @Override 22 | public void handlePacket(PanfuPacket packet, User sender) { 23 | int userId = packet.readInt(); 24 | int sessionTicket = packet.readInt(); 25 | int startRoom = packet.readInt(); 26 | UserData data = UserDAO.getByIdAndTicket(userId, sessionTicket); 27 | if (data != null) { 28 | sender.setUserId(data.id); 29 | sender.setGoldpanda(data.goldpanda); 30 | sender.setUsername(data.name); 31 | sender.setSheriff(data.sheriff); 32 | sender.setCurrentGameServer(sender.getGameServer().getId()); 33 | Logger.info("User " + sender.getUsername() + " logged in!"); 34 | sender.getGameServer().getSessionManager().addUser(sender); 35 | sender.setLoggedIn(true); 36 | sender.nullTicketId(); 37 | 38 | // Plugins can deny a user's login by either returning false or setting their 39 | // loggedIn to false. 40 | if (PluginManager.handleUserConnect(sender) && sender.isLoggedIn()) { 41 | PanfuPacket onLoginPacket = new PanfuPacket(Packets.RES_ON_LOGIN); 42 | onLoginPacket.writeString("OK"); 43 | sender.sendPacket(onLoginPacket); 44 | sender.setX(450); 45 | sender.setY(450); 46 | int[] randomRooms = { 1, 2, 3, 4 }; 47 | if (startRoom > 0) 48 | sender.joinRoom(startRoom); 49 | else 50 | sender.joinRoom(getRandom(randomRooms)); 51 | sender.getGameServer().updateUserCount(); 52 | PluginManager.onUserConnect(sender); 53 | } else { 54 | sender.disconnect(); 55 | } 56 | } else { 57 | sender.sendString("0;FAILED|10;0|"); 58 | sender.disconnect("KICK_LOGIN_FAILED_MSG"); 59 | } 60 | } 61 | 62 | public static int getRandom(int[] array) { 63 | int rnd = new Random().nextInt(array.length); 64 | return array[rnd]; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_MOVE.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver.handler; 9 | 10 | import org.openpanfu.gameserver.PanfuPacket; 11 | import org.openpanfu.gameserver.User; 12 | 13 | public class CMD_MOVE implements IHandler { 14 | public static final int MOVEMENT_TYPE_WALK = 0; 15 | public static final int MOVEMENT_TYPE_SLIDE = 1; 16 | public static final int MOVEMENT_TYPE_SWEEP = 2; 17 | public static final int MOVEMENT_TYPE_JUMP = 3; 18 | public static final int MOVEMENT_TYPE_TELEPORT = 4; 19 | public static final int MOVEMENT_TYPE_RUNNING = 5; 20 | public static final int MOVEMENT_TYPE_ROLLERBLADES = 6; 21 | public static final int MOVEMENT_TYPE_SLOW = 7; 22 | public static final int MOVEMENT_TYPE_SNOWBOARD = 8; 23 | 24 | private static int calcuTime(int x1, int y1, int x2, int y2) { 25 | double distance = Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)); 26 | if (distance <= 1) { 27 | return (1); 28 | } 29 | return (int) (distance / 0.1); 30 | } 31 | 32 | @Override 33 | public void handlePacket(PanfuPacket packet, User sender) { 34 | int toX = packet.readInt(); 35 | int toY = packet.readInt(); 36 | int type = packet.readInt(); 37 | if (type > 8) { 38 | sender.disconnect("Error: CMD_MOVE, unknown movement type."); 39 | } 40 | 41 | sender.nullInteractions(); 42 | 43 | switch (type) { 44 | case MOVEMENT_TYPE_WALK: 45 | int msLeft = 0; 46 | if (sender.getTimeUntilWalkComplete() - System.currentTimeMillis() > 0) { 47 | msLeft = Math.toIntExact((sender.getTimeUntilWalkComplete() - System.currentTimeMillis()) / 2); 48 | } else { 49 | sender.setTimeUntilWalkComplete( 50 | System.currentTimeMillis() + calcuTime(sender.getX(), sender.getY(), toX, toY) + msLeft); 51 | } 52 | sender.move(toX, toY, calcuTime(sender.getX(), sender.getY(), toX, toY) + msLeft, type); 53 | break; 54 | default: 55 | sender.move(toX, toY, 1000, type); 56 | break; 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_PLAYER_TO_PLAYER.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver.handler; 9 | 10 | import org.openpanfu.gameserver.PanfuPacket; 11 | import org.openpanfu.gameserver.User; 12 | import org.openpanfu.gameserver.handler.p2p.IP2PHandler; 13 | import org.openpanfu.gameserver.handler.p2p.P2PHandler; 14 | import org.openpanfu.gameserver.util.Logger; 15 | 16 | public class CMD_PLAYER_TO_PLAYER implements IHandler { 17 | @Override 18 | public void handlePacket(PanfuPacket packet, User sender) { 19 | String reciever = packet.readString(); 20 | int command = packet.readInt(); 21 | 22 | IP2PHandler packetHandler = P2PHandler.getHandlerForHeader(command); 23 | if (packetHandler == null) { 24 | Logger.warning("Unhandled P2P packet: " + command); 25 | } else { 26 | packetHandler.handlePacket(packet, reciever, sender); 27 | } 28 | 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_QUERY_SHARED_ITEMS.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver.handler; 9 | 10 | import java.util.List; 11 | 12 | import org.openpanfu.gameserver.PanfuPacket; 13 | import org.openpanfu.gameserver.User; 14 | import org.openpanfu.gameserver.constants.Packets; 15 | import org.openpanfu.gameserver.constants.RoomCommands; 16 | 17 | public class CMD_QUERY_SHARED_ITEMS implements IHandler { 18 | @Override 19 | public void handlePacket(PanfuPacket packet, User sender) { 20 | int type = packet.readInt(); 21 | int roomToQuery = packet.readInt(); 22 | final int interactableItems = 255; 23 | int[] interactables = new int[interactableItems]; 24 | for (int temp = 0; temp < interactableItems; temp++) { 25 | interactables[temp] = -1; 26 | } 27 | 28 | PanfuPacket result = new PanfuPacket(Packets.RES_RECEIVE_SHARED_ITEMS); 29 | result.writeInt(type); 30 | result.writeInt(roomToQuery); 31 | switch (type) { 32 | case RoomCommands.TYPE_GETITEMSSTATE: 33 | List users = sender.getGameServer().getSessionManager().getUsersInRoom(roomToQuery, sender.isInHome(), 34 | sender.getSubRoom()); 35 | for (User u : users) { 36 | if (u.getInteractingWith() != -1) { 37 | interactables[u.getInteractingWith()] = u.getUserId(); 38 | } 39 | } 40 | for (int userInteracting : interactables) { 41 | result.writeInt(userInteracting); 42 | } 43 | break; 44 | case RoomCommands.TYPE_UPDATEITEMSTATE: 45 | int itemId = packet.readInt(); 46 | int userId = packet.readInt(); 47 | result.writeInt(itemId); 48 | if (userId == -1) { 49 | result.writeInt(-1); 50 | } else { 51 | result.writeInt(sender.getUserId()); 52 | } 53 | sender.setInteractingWith(itemId); 54 | sender.sendRoom(result); 55 | return; 56 | } 57 | sender.sendPacket(result); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_QUIT_GAME.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler; 2 | 3 | import org.openpanfu.gameserver.PanfuPacket; 4 | import org.openpanfu.gameserver.User; 5 | import org.openpanfu.gameserver.constants.Packets; 6 | 7 | public class CMD_QUIT_GAME implements IHandler { 8 | @Override 9 | public void handlePacket(PanfuPacket packet, User sender) { 10 | int gameId = packet.readInt(); 11 | sender.quitGame(); 12 | // Makes the user rejoin the room they initially joined the game in. 13 | // We don't use sender.joinRoom() because then they'll be unset. 14 | PanfuPacket joinRoom = new PanfuPacket(Packets.RES_ON_ROOM_JOINED); 15 | joinRoom.writeInt(sender.getRoomId()); 16 | sender.sendPacket(joinRoom); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_SAFE_CHAT.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler; 2 | 3 | import org.openpanfu.gameserver.GameServer; 4 | import org.openpanfu.gameserver.PanfuPacket; 5 | import org.openpanfu.gameserver.User; 6 | import org.openpanfu.gameserver.constants.Packets; 7 | 8 | public class CMD_SAFE_CHAT implements IHandler { 9 | @Override 10 | public void handlePacket(PanfuPacket packet, User sender) { 11 | if ((System.currentTimeMillis() - sender.getLastChatMessageTime()) < 100) { 12 | sender.disconnect("CMD_CHAT > You are chatting too fast!"); 13 | return; 14 | } 15 | if (Integer.valueOf(GameServer.getProperties().getProperty("chat.antispam.enabled")) != 0) { 16 | int seconds = Integer 17 | .parseInt(GameServer.getProperties().getProperty("chat.antispam.secondsbetweenmessages")); 18 | if ((System.currentTimeMillis() - sender.getLastChatMessageTime()) < (seconds * 1000)) { 19 | sender.giveChatSpamWarning(); 20 | return; 21 | } 22 | } 23 | String text = packet.readString().replaceAll("\\<[^>]*>", ""); 24 | ; 25 | if (text.length() > 120) { 26 | sender.disconnect("KICK_SHUTDOWN_MSG"); 27 | } 28 | sender.setLastChatMessage(text); 29 | sender.setLastChatMessageTime(System.currentTimeMillis()); 30 | if (sender.getSheriff() > 0) { 31 | text = "#" + GameServer.getProperties().getProperty("chat.sheriff.prefix") + " " + text; 32 | } 33 | 34 | PanfuPacket chatPacket = new PanfuPacket(Packets.RES_CHAT_MSG); 35 | chatPacket.writeInt(sender.getUserId()); 36 | chatPacket.writeString(text); 37 | sender.sendRoom(chatPacket); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_UPDATE_ROOM.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler; 2 | 3 | import org.openpanfu.gameserver.PanfuPacket; 4 | import org.openpanfu.gameserver.User; 5 | import org.openpanfu.gameserver.constants.HomeCommands; 6 | 7 | public class CMD_UPDATE_ROOM implements IHandler { 8 | @Override 9 | public void handlePacket(PanfuPacket packet, User sender) { 10 | PanfuPacket updateRoom = new PanfuPacket(HomeCommands.ON_UPDATE_ROOM); 11 | sender.sendRoom(updateRoom); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/CMD_UPDATE_SOUND.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler; 2 | 3 | import org.openpanfu.gameserver.PanfuPacket; 4 | import org.openpanfu.gameserver.User; 5 | import org.openpanfu.gameserver.constants.HomeCommands; 6 | 7 | public class CMD_UPDATE_SOUND implements IHandler { 8 | @Override 9 | public void handlePacket(PanfuPacket packet, User sender) { 10 | // Updates the current song being played by the jukebox in someone's home. 11 | 12 | // Song name as in /features/jukebox/conf/jukebox.xml 13 | // For example, song_b4_nl would be No Limit. 14 | String songName = packet.readString(); 15 | 16 | // Is the sender in their own room? 17 | if (sender.getRoomId() == sender.getUserId() && sender.isInHome()) { 18 | PanfuPacket updateSong = new PanfuPacket(HomeCommands.ON_UPDATE_SOUND); 19 | updateSong.writeString(songName); 20 | sender.sendRoom(updateSong); 21 | } 22 | } 23 | } -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/Handler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver.handler; 9 | 10 | import java.util.HashMap; 11 | 12 | import org.openpanfu.gameserver.constants.HomeCommands; 13 | import org.openpanfu.gameserver.constants.Packets; 14 | import org.openpanfu.gameserver.constants.RoomCommands; 15 | import org.openpanfu.gameserver.handler.p2p.P2PHandler; 16 | import org.openpanfu.gameserver.handler.special.CMD_INFOMESSAGE; 17 | import org.openpanfu.gameserver.util.Logger; 18 | 19 | public class Handler { 20 | private static HashMap handlers = new HashMap(); 21 | 22 | public static void initialize() { 23 | Logger.info("Initializing Handlers..."); 24 | addPacketHandler(Packets.CMD_LOGIN, new CMD_LOGIN()); 25 | addPacketHandler(Packets.CMD_GET_SALT, new CMD_GET_SALT()); 26 | addPacketHandler(Packets.CMD_GET_ROOM_ATTENDEES, new CMD_GET_ROOM_ATTENDEES()); 27 | addPacketHandler(Packets.CMD_GET_PLAYER_IDS_BY_CLOTHES, new CMD_GET_PLAYER_IDS_BY_CLOTHES()); 28 | addPacketHandler(Packets.CMD_PLAYER_TO_PLAYER, new CMD_PLAYER_TO_PLAYER()); 29 | addPacketHandler(Packets.CMD_MOVE, new CMD_MOVE()); 30 | addPacketHandler(Packets.CMD_CHAT, new CMD_CHAT()); 31 | addPacketHandler(Packets.CMD_SAFE_CHAT, new CMD_SAFE_CHAT()); 32 | addPacketHandler(Packets.CMD_EMOTE, new CMD_EMOTE()); 33 | addPacketHandler(Packets.CMD_ACTION, new CMD_ACTION()); 34 | addPacketHandler(Packets.CMD_ADDBUDDY, new CMD_ADDBUDDY()); 35 | addPacketHandler(Packets.CMD_GET_ALL_HOUSES, new CMD_GET_ALL_HOUSES()); 36 | addPacketHandler(Packets.CMD_JOIN_ROOM, new CMD_JOIN_ROOM()); 37 | addPacketHandler(Packets.CMD_JOIN_HOME, new CMD_JOIN_HOME()); 38 | addPacketHandler(Packets.CMD_JOIN_GAME, new CMD_JOIN_GAME()); 39 | addPacketHandler(Packets.CMD_ENTER_MULTIGAME, new CMD_ENTER_MULTIGAME()); 40 | addPacketHandler(Packets.CMD_QUIT_GAME, new CMD_QUIT_GAME()); 41 | addPacketHandler(RoomCommands.QUERY_SHARED_ITEMS, new CMD_QUERY_SHARED_ITEMS()); 42 | 43 | // Home commands 44 | addPacketHandler(HomeCommands.CMD_UPDATE_SOUND, new CMD_UPDATE_SOUND()); 45 | addPacketHandler(HomeCommands.CMD_UPDATE_ROOM, new CMD_UPDATE_ROOM()); 46 | addPacketHandler(HomeCommands.CMD_CHANGE_ROOM, new CMD_CHANGE_ROOM()); 47 | 48 | // Special 49 | 50 | addPacketHandler(Packets.CMD_INFOMESSAGE, new CMD_INFOMESSAGE()); 51 | 52 | Logger.info("Registered " + handlers.size() + " Packet handlers."); 53 | P2PHandler.initialize(); 54 | } 55 | 56 | public static IHandler getHandlerForHeader(int header) { 57 | return handlers.get(header); 58 | } 59 | 60 | public static void addPacketHandler(int header, IHandler handler) { 61 | if (!handlers.containsKey(header)) { 62 | handlers.put(header, handler); 63 | } else { 64 | Logger.error(String.format( 65 | "Attempted to register packet header %d, this was denied because a packet handler has already been registered with that header.", 66 | header)); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/IHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver.handler; 9 | 10 | import org.openpanfu.gameserver.PanfuPacket; 11 | import org.openpanfu.gameserver.User; 12 | 13 | public interface IHandler { 14 | void handlePacket(PanfuPacket packet, User sender); 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/p2p/CMD_CREATE_AVATAR.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler.p2p; 2 | 3 | import org.openpanfu.gameserver.PanfuPacket; 4 | import org.openpanfu.gameserver.User; 5 | import org.openpanfu.gameserver.constants.Packets; 6 | import org.openpanfu.gameserver.constants.PlayerToPlayerCommands; 7 | 8 | public class CMD_CREATE_AVATAR implements IP2PHandler { 9 | @Override 10 | public void handlePacket(PanfuPacket packet, String receiver, User sender) { 11 | PanfuPacket response = new PanfuPacket(Packets.RES_PLAYER_TO_PLAYER); 12 | int x = packet.readInt(); 13 | int y = packet.readInt(); 14 | String action = packet.readString(); 15 | int rotation = packet.readInt(); 16 | String timeTravel = packet.readString(); 17 | String pokopetType = packet.readString(); 18 | int sheriff = packet.readInt(); 19 | String clothes = packet.readString(); 20 | response.writeInt(sender.getUserId()); 21 | response.writeInt(PlayerToPlayerCommands.ON_CREATE_AVATAR); 22 | response.writeInt(x); 23 | response.writeInt(y); 24 | response.writeString(action); 25 | response.writeInt(rotation); 26 | response.writeString(timeTravel); 27 | response.writeString(pokopetType); 28 | response.writeInt(sender.getSheriff()); 29 | response.writeString(clothes); 30 | sender.sendForReceiver(response, receiver); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/p2p/CMD_HIDE_STATUS.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler.p2p; 2 | 3 | import org.openpanfu.gameserver.PanfuPacket; 4 | import org.openpanfu.gameserver.User; 5 | import org.openpanfu.gameserver.constants.Packets; 6 | import org.openpanfu.gameserver.constants.PlayerToPlayerCommands; 7 | 8 | public class CMD_HIDE_STATUS implements IP2PHandler { 9 | @Override 10 | public void handlePacket(PanfuPacket packet, String receiver, User sender) { 11 | PanfuPacket HideStatusBroadcast = new PanfuPacket(Packets.RES_PLAYER_TO_PLAYER); 12 | HideStatusBroadcast.writeInt(sender.getUserId()); 13 | HideStatusBroadcast.writeInt(PlayerToPlayerCommands.ON_HIDE_STATUS); 14 | HideStatusBroadcast.writeString(packet.readString()); 15 | sender.sendForReceiver(HideStatusBroadcast, receiver); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/p2p/CMD_SHOW_STATUS.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler.p2p; 2 | 3 | import org.openpanfu.gameserver.PanfuPacket; 4 | import org.openpanfu.gameserver.User; 5 | import org.openpanfu.gameserver.constants.Packets; 6 | import org.openpanfu.gameserver.constants.PlayerToPlayerCommands; 7 | 8 | public class CMD_SHOW_STATUS implements IP2PHandler { 9 | @Override 10 | public void handlePacket(PanfuPacket packet, String receiver, User sender) { 11 | PanfuPacket StatusBroadcast = new PanfuPacket(Packets.RES_PLAYER_TO_PLAYER); 12 | StatusBroadcast.writeInt(sender.getUserId()); 13 | StatusBroadcast.writeInt(PlayerToPlayerCommands.ON_SHOW_STATUS); 14 | StatusBroadcast.writeString(packet.readString()); 15 | StatusBroadcast.writeString(packet.readString()); 16 | sender.sendForReceiver(StatusBroadcast, receiver); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/p2p/CMD_UPDATE_AVATAR.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler.p2p; 2 | 3 | import org.openpanfu.gameserver.PanfuPacket; 4 | import org.openpanfu.gameserver.User; 5 | import org.openpanfu.gameserver.constants.Packets; 6 | import org.openpanfu.gameserver.constants.PlayerToPlayerCommands; 7 | 8 | public class CMD_UPDATE_AVATAR implements IP2PHandler { 9 | @Override 10 | public void handlePacket(PanfuPacket packet, String receiver, User sender) { 11 | PanfuPacket response = new PanfuPacket(Packets.RES_PLAYER_TO_PLAYER); 12 | String pokopet = packet.readString(); 13 | int unknown = packet.readInt(); 14 | String playerString = packet.readString(); 15 | response.writeInt(sender.getUserId()); 16 | response.writeInt(PlayerToPlayerCommands.ON_UPDATE_AVATAR); 17 | response.writeString(pokopet); 18 | response.writeInt(sender.getSheriff()); 19 | response.writeString(playerString); 20 | sender.sendForReceiver(response, receiver); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/p2p/CMD_USE_SHARED_ITEM.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler.p2p; 2 | 3 | import org.openpanfu.gameserver.PanfuPacket; 4 | import org.openpanfu.gameserver.User; 5 | import org.openpanfu.gameserver.constants.Packets; 6 | import org.openpanfu.gameserver.constants.PlayerToPlayerCommands; 7 | 8 | public class CMD_USE_SHARED_ITEM implements IP2PHandler { 9 | @Override 10 | public void handlePacket(PanfuPacket packet, String receiver, User sender) { 11 | int posX = packet.readInt(); 12 | int posY = packet.readInt(); 13 | String actionToPerform = packet.readString(); 14 | String actionFrameName = packet.readString(); 15 | int sort = packet.readInt(); 16 | 17 | PanfuPacket response = new PanfuPacket(Packets.RES_PLAYER_TO_PLAYER); 18 | response.writeInt(sender.getUserId()); 19 | response.writeInt(PlayerToPlayerCommands.ON_USE_SHARED_ITEM); 20 | response.writeInt(posX); 21 | response.writeInt(posY); 22 | response.writeString(actionToPerform); 23 | response.writeString(actionFrameName); 24 | response.writeInt(sort); 25 | sender.sendForReceiver(response, receiver); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/p2p/IP2PHandler.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler.p2p; 2 | 3 | import org.openpanfu.gameserver.PanfuPacket; 4 | import org.openpanfu.gameserver.User; 5 | 6 | public interface IP2PHandler { 7 | void handlePacket(PanfuPacket packet, String receiver, User sender); 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/p2p/P2PHandler.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler.p2p; 2 | 3 | import java.util.HashMap; 4 | 5 | import org.openpanfu.gameserver.constants.PlayerToPlayerCommands; 6 | import org.openpanfu.gameserver.util.Logger; 7 | 8 | public class P2PHandler { 9 | private static HashMap handlers = new HashMap(); 10 | 11 | public static void initialize() { 12 | Logger.info("Initializing P2P Handlers..."); 13 | handlers.put(PlayerToPlayerCommands.CMD_CREATE_AVATAR, new CMD_CREATE_AVATAR()); 14 | handlers.put(PlayerToPlayerCommands.CMD_UPDATE_AVATAR, new CMD_UPDATE_AVATAR()); 15 | handlers.put(PlayerToPlayerCommands.CMD_SHOW_STATUS, new CMD_SHOW_STATUS()); 16 | handlers.put(PlayerToPlayerCommands.CMD_HIDE_STATUS, new CMD_HIDE_STATUS()); 17 | handlers.put(PlayerToPlayerCommands.CMD_USE_SHARED_ITEM, new CMD_USE_SHARED_ITEM()); 18 | Logger.info("Registered " + handlers.size() + " P2P Packet handlers."); 19 | } 20 | 21 | public static IP2PHandler getHandlerForHeader(int header) { 22 | return handlers.get(header); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/handler/special/CMD_INFOMESSAGE.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.handler.special; 2 | 3 | import java.net.InetSocketAddress; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | 7 | import org.openpanfu.gameserver.GameServer; 8 | import org.openpanfu.gameserver.PanfuPacket; 9 | import org.openpanfu.gameserver.User; 10 | import org.openpanfu.gameserver.constants.Packets; 11 | import org.openpanfu.gameserver.handler.IHandler; 12 | import org.openpanfu.gameserver.util.Logger; 13 | 14 | public class CMD_INFOMESSAGE implements IHandler { 15 | private List blockList = new ArrayList(); 16 | 17 | @Override 18 | public void handlePacket(PanfuPacket packet, User sender) { 19 | String externalIp = ((InetSocketAddress) sender.getChannel().remoteAddress()).getAddress().getHostAddress(); 20 | 21 | if (blockList.contains(externalIp)) { 22 | Logger.error(String.format("Denied request of %s, ip has been blocked.", externalIp)); 23 | sender.disconnect(); 24 | return; 25 | } 26 | 27 | String key = packet.readString(); 28 | String command = packet.readString(); 29 | int userId; 30 | if (sender.getGameServer().getKey().equals(key)) { 31 | switch (command) { 32 | case "testConnection": 33 | Logger.info(String.format("Connection test from %s success.", externalIp)); 34 | break; 35 | case "kickUser": 36 | userId = packet.readInt(); 37 | User toKick = GameServer.getUserById(userId); 38 | if (toKick != null) 39 | toKick.disconnect(); 40 | break; 41 | case "updateBuddyStatus": 42 | userId = packet.readInt(); 43 | int buddyId = packet.readInt(); 44 | int status = packet.readInt(); 45 | User toInformOfNewStatus = GameServer.getUserById(userId); 46 | PanfuPacket updateBuddyStatus = new PanfuPacket(Packets.RES_UPDATE_BUDDY_STATUS); 47 | updateBuddyStatus.writeInt(buddyId); 48 | updateBuddyStatus.writeInt(status); 49 | if (toInformOfNewStatus != null) { 50 | toInformOfNewStatus.sendPacket(updateBuddyStatus); 51 | } 52 | break; 53 | } 54 | } else { 55 | blockList.add(externalIp); 56 | Logger.error(String.format("Invalid key from %s, ip has been blocked.", externalIp)); 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/plugin/IPlugin.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.plugin; 2 | 3 | import org.openpanfu.gameserver.User; 4 | 5 | public interface IPlugin { 6 | 7 | /** 8 | * This method will be ran when the server starts. 9 | * 10 | * @return Boolean Returning true will allow the plugin to use the other 11 | * methods. 12 | */ 13 | boolean onStartup(); 14 | 15 | /** 16 | * This method will be called after a user joins a room. 17 | * 18 | * @param user The user that just joined the room. 19 | * @param roomId The roomId of the room they just joined. If the user just 20 | * entered a home, this will be the user id of the person who's 21 | * home they just joined. 22 | * @param isHome Whether that room is a user home. 23 | */ 24 | void onUserJoinRoom(User user, int roomId, boolean isHome); 25 | 26 | /** 27 | * Called when a user *tries* to enter a room, this allows you to override 28 | * normal room joining behavior. 29 | * 30 | * @param user The user that just joined the room. 31 | * @param roomId The roomId of the room they just joined. If the user just 32 | * entered a home, this will be the user id of the person who's 33 | * home they just joined. 34 | * @param isHome Whether that room is a user home. 35 | * @return boolean If true, the normal handler will be ran afterwards. 36 | */ 37 | boolean handleUserJoinRoom(User user, int roomId, boolean isHome); 38 | 39 | /** 40 | * Called when a user just logged in from CMD_LOGIN. 41 | * 42 | * @param user The user that just connected. 43 | */ 44 | void onUserConnect(User user); 45 | 46 | /** 47 | * Called when a user is trying to login. 48 | * 49 | * @param user The user that just connected. 50 | * @return boolean If false, the user's session will be denied and they will be 51 | * disconnected. 52 | */ 53 | boolean handleUserConnect(User user); 54 | 55 | /** 56 | * 57 | * @param user 58 | * @param message 59 | */ 60 | void onUserChat(User user, String message); 61 | 62 | boolean handleUserChat(User user, String message); 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/plugin/Plugin.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.plugin; 2 | 3 | import org.openpanfu.gameserver.User; 4 | 5 | public class Plugin implements IPlugin { 6 | public boolean onStartup() { 7 | return false; 8 | } 9 | 10 | public void onUserJoinRoom(User user, int roomId, boolean isHome) { 11 | 12 | } 13 | 14 | public boolean handleUserJoinRoom(User user, int roomId, boolean isHome) { 15 | return true; 16 | } 17 | 18 | public void onUserConnect(User user) { 19 | 20 | } 21 | 22 | public boolean handleUserConnect(User user) { 23 | return true; 24 | } 25 | 26 | public void onUserChat(User user, String message) { 27 | 28 | } 29 | 30 | public boolean handleUserChat(User user, String message) { 31 | return true; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/plugin/PluginInstance.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.plugin; 2 | 3 | import java.io.File; 4 | import java.net.MalformedURLException; 5 | import java.net.URL; 6 | import java.net.URLClassLoader; 7 | import java.util.Properties; 8 | import java.util.jar.JarFile; 9 | 10 | import org.openpanfu.gameserver.util.Logger; 11 | 12 | public class PluginInstance { 13 | private String name; 14 | private String description; 15 | private Properties pluginProperties; 16 | private IPlugin mainClass; 17 | private String mainClassName; 18 | private JarFile jarFile; 19 | public Boolean listening = false; 20 | 21 | public PluginInstance(File file, JarFile jarFile, Properties pluginProperties) { 22 | this.jarFile = jarFile; 23 | this.pluginProperties = pluginProperties; 24 | 25 | String name = this.pluginProperties.getProperty("name"); 26 | if (name != null && !name.equals("")) { 27 | this.name = name; 28 | } 29 | 30 | String mainClassName = this.pluginProperties.getProperty("mainclass"); 31 | if (mainClassName != null && !mainClassName.equals("")) { 32 | this.mainClassName = mainClassName; 33 | } else { 34 | Logger.error(String.format( 35 | "[PluginInstance] Failed to load plugin: %s. (plugin.properties->mainclass is missing)", 36 | file.getName())); 37 | return; 38 | } 39 | 40 | String description = this.pluginProperties.getProperty("description"); 41 | if (description != null && !description.equals("")) { 42 | this.description = description; 43 | } 44 | URL url = null; 45 | try { 46 | url = file.toURI().toURL(); 47 | } catch (MalformedURLException e) { 48 | e.printStackTrace(); 49 | } 50 | URLClassLoader cl = new URLClassLoader(new java.net.URL[] { url }); 51 | try { 52 | Class mainClass = cl.loadClass(this.mainClassName); 53 | this.mainClass = (IPlugin) mainClass.newInstance(); 54 | } catch (ClassNotFoundException e) { 55 | Logger.error(String.format( 56 | "[PluginInstance] Failed to load plugin: %s. (The class specified in plugin.properties->mainclass is missing)", 57 | file.getName())); 58 | return; 59 | } catch (IllegalAccessException e) { 60 | e.printStackTrace(); 61 | Logger.error( 62 | String.format("[PluginInstance] Failed to load plugin: %s. (Check trace error)", file.getName())); 63 | return; 64 | } catch (InstantiationException e) { 65 | e.printStackTrace(); 66 | Logger.error( 67 | String.format("[PluginInstance] Failed to load plugin: %s. (Check trace error)", file.getName())); 68 | return; 69 | } 70 | this.listening = this.mainClass.onStartup(); 71 | } 72 | 73 | public String getName() { 74 | return this.name; 75 | } 76 | 77 | public IPlugin getPlugin() { 78 | return this.mainClass; 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/plugin/PluginLoader.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.plugin; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | import java.util.Properties; 6 | import java.util.jar.JarFile; 7 | import java.util.regex.Matcher; 8 | import java.util.regex.Pattern; 9 | 10 | import org.openpanfu.gameserver.util.Logger; 11 | 12 | public class PluginLoader { 13 | private static final Pattern fileFilter = Pattern.compile("\\.jar$"); 14 | 15 | public static void loadPluginsInDirectory(String directoryToSearch) { 16 | Logger.info(String.format("[PluginLoader] Loading plugins from ./%s..", directoryToSearch)); 17 | final File directory = new File(directoryToSearch); 18 | if (directory.isDirectory()) { 19 | for (File file : directory.listFiles()) { 20 | Matcher match = fileFilter.matcher(file.getName()); 21 | if (match.find()) { 22 | // This is a proper jar file, time to load. 23 | try { 24 | JarFile jarFile = loadJar(file); 25 | if (jarFile.getEntry("plugin.properties") != null) { 26 | Properties pluginProperties = new Properties(); 27 | pluginProperties.load(jarFile.getInputStream(jarFile.getEntry("plugin.properties"))); 28 | PluginManager.loadPlugin(file, jarFile, pluginProperties); 29 | } else { 30 | Logger.error(String.format( 31 | "[PluginLoader] Failed to load plugin: %s. (plugin.properties is missing from the jar file)", 32 | file.getName())); 33 | } 34 | } catch (IOException e) { 35 | e.printStackTrace(); 36 | Logger.error(String.format("[PluginLoader] Failed to load plugin: %s. (Check trace)", 37 | file.getName())); 38 | } 39 | } 40 | } 41 | } else { 42 | Logger.error("[PluginLoader] Failed to load plugins. (Plugin is not a directory)"); 43 | } 44 | } 45 | 46 | public static JarFile loadJar(String jarFile) { 47 | try { 48 | return loadJar(new File(jarFile)); 49 | } catch (IOException e) { 50 | e.printStackTrace(); 51 | } 52 | Logger.error(String.format("[PluginLoader] Failed to load plugin %s..", jarFile)); 53 | return null; 54 | } 55 | 56 | public static JarFile loadJar(File jarFile) throws IOException { 57 | return new JarFile(jarFile); 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/plugin/PluginManager.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.plugin; 2 | 3 | import java.io.File; 4 | import java.util.ArrayList; 5 | import java.util.List; 6 | import java.util.Properties; 7 | import java.util.jar.JarFile; 8 | 9 | import org.openpanfu.gameserver.User; 10 | import org.openpanfu.gameserver.util.Logger; 11 | 12 | public class PluginManager { 13 | private static List plugins = new ArrayList(); 14 | 15 | public static void loadPlugins(String directory) { 16 | PluginLoader.loadPluginsInDirectory(directory); 17 | } 18 | 19 | public static void loadPlugin(File file, JarFile jarFile, Properties pluginProps) { 20 | PluginInstance pi = new PluginInstance(file, jarFile, pluginProps); 21 | plugins.add(pi); 22 | } 23 | 24 | // Functions to run on plugins 25 | 26 | // On functions (Run after doing something) 27 | 28 | public static void onUserJoinRoom(User user, int roomId, boolean isHome) { 29 | for (PluginInstance plugin : plugins) { 30 | if (plugin.listening) 31 | plugin.getPlugin().onUserJoinRoom(user, roomId, isHome); 32 | } 33 | } 34 | 35 | public static void onUserConnect(User user) { 36 | for (PluginInstance plugin : plugins) { 37 | if (plugin.listening) 38 | plugin.getPlugin().onUserConnect(user); 39 | } 40 | } 41 | 42 | public static void onUserChat(User user, String message) { 43 | for (PluginInstance plugin : plugins) { 44 | if (plugin.listening) 45 | plugin.getPlugin().onUserChat(user, message); 46 | } 47 | } 48 | 49 | // Handle functions (Run before doing something and can stop normal behaviour) 50 | public static boolean handleUserJoinRoom(User user, int roomId, boolean isHome) { 51 | for (PluginInstance plugin : plugins) { 52 | if (plugin.listening && !plugin.getPlugin().handleUserJoinRoom(user, roomId, isHome)) { 53 | Logger.debug("Exiting in handleUserJoinRoom due to " + plugin.getName()); 54 | return false; 55 | } 56 | } 57 | return true; 58 | } 59 | 60 | public static boolean handleUserConnect(User user) { 61 | for (PluginInstance plugin : plugins) { 62 | if (plugin.listening && !plugin.getPlugin().handleUserConnect(user)) { 63 | return false; 64 | } 65 | } 66 | return true; 67 | } 68 | 69 | public static boolean handleUserChat(User user, String message) { 70 | for (PluginInstance plugin : plugins) { 71 | if (plugin.listening && !plugin.getPlugin().handleUserChat(user, message)) { 72 | Logger.debug("Exiting in handleUserChat due to " + plugin.getName()); 73 | return false; 74 | } 75 | } 76 | return true; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/sessions/SessionManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver.sessions; 9 | 10 | import java.util.List; 11 | import java.util.concurrent.ConcurrentHashMap; 12 | import java.util.concurrent.ConcurrentMap; 13 | import java.util.stream.Collectors; 14 | 15 | import org.openpanfu.gameserver.User; 16 | 17 | public class SessionManager { 18 | private ConcurrentMap sessions; 19 | 20 | public SessionManager() { 21 | this.sessions = new ConcurrentHashMap(); 22 | } 23 | 24 | public void addUser(User user) { 25 | if (sessions.get(user.getUserId()) != null) { 26 | user.disconnect("KICK_NEW_LOGIN"); 27 | } 28 | 29 | sessions.putIfAbsent(user.getUserId(), user); 30 | } 31 | 32 | public User getUserById(int id) { 33 | return this.sessions.values().stream().filter(s -> s.getUserId() == id).findFirst().get(); 34 | } 35 | 36 | public User getUserByUsername(String username) { 37 | return this.sessions.values().stream().filter(s -> s.getUsername().equals(username)).findFirst().get(); 38 | } 39 | 40 | public void removeUserById(int id) { 41 | sessions.remove(id); 42 | } 43 | 44 | public int getUserCount() { 45 | return sessions.size(); 46 | } 47 | 48 | public List getUsers() { 49 | return this.sessions.values().stream().collect(Collectors.toList()); 50 | } 51 | 52 | public List getUsersInRoom(int roomid, boolean inHome, int subroom) { 53 | return this.sessions.values().stream() 54 | .filter(s -> s.getRoomId() == roomid && s.isInHome() == inHome && s.getSubRoom() == subroom) 55 | .collect(Collectors.toList()); 56 | } 57 | 58 | public ConcurrentMap getSessions() { 59 | return sessions; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/util/Key.java: -------------------------------------------------------------------------------- 1 | package org.openpanfu.gameserver.util; 2 | 3 | import java.security.SecureRandom; 4 | import java.util.Locale; 5 | import java.util.Objects; 6 | import java.util.Random; 7 | 8 | // With help of https://stackoverflow.com/a/41156 9 | public class Key { 10 | public String nextString() { 11 | for (int idx = 0; idx < buf.length; ++idx) 12 | buf[idx] = symbols[random.nextInt(symbols.length)]; 13 | return new String(buf); 14 | } 15 | 16 | public static final String upper = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; 17 | 18 | public static final String lower = upper.toLowerCase(Locale.ROOT); 19 | 20 | public static final String digits = "0123456789"; 21 | 22 | public static final String alphanum = upper + lower + digits; 23 | 24 | private final Random random; 25 | 26 | private final char[] symbols; 27 | 28 | private final char[] buf; 29 | 30 | public Key(int length, Random random, String symbols) { 31 | if (length < 1) 32 | throw new IllegalArgumentException(); 33 | if (symbols.length() < 2) 34 | throw new IllegalArgumentException(); 35 | this.random = Objects.requireNonNull(random); 36 | this.symbols = symbols.toCharArray(); 37 | this.buf = new char[length]; 38 | } 39 | 40 | public Key(int length, Random random) { 41 | this(length, random, alphanum); 42 | } 43 | 44 | public Key(int length) { 45 | this(length, new SecureRandom()); 46 | } 47 | 48 | public Key() { 49 | this(21); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/openpanfu/gameserver/util/Logger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * This file is part of openPanfu, a project that imitates the Flex remoting 3 | * and gameservers of Panfu. 4 | * 5 | * @author Altro50 6 | */ 7 | 8 | package org.openpanfu.gameserver.util; 9 | 10 | import java.text.SimpleDateFormat; 11 | import java.util.Calendar; 12 | 13 | import org.openpanfu.gameserver.GameServer; 14 | 15 | public class Logger { 16 | public static final String ANSI_RESET = "\u001B[0m"; 17 | public static final String ANSI_BLACK = "\u001B[30m"; 18 | public static final String ANSI_RED = "\u001B[31m"; 19 | public static final String ANSI_GREEN = "\u001B[32m"; 20 | public static final String ANSI_YELLOW = "\u001B[33m"; 21 | public static final String ANSI_BLUE = "\u001B[34m"; 22 | public static final String ANSI_PURPLE = "\u001B[35m"; 23 | public static final String ANSI_CYAN = "\u001B[36m"; 24 | public static final String ANSI_WHITE = "\u001B[37m"; 25 | 26 | public static void log(String Level, String Message, String colorCode) { 27 | Calendar cal = Calendar.getInstance(); 28 | SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss"); 29 | if (Integer.valueOf(GameServer.getProperties().getProperty("gameserver.ansilogging")) != 0) 30 | System.out.println(String.format("%s[%s] %s > %s%s", colorCode, sdf.format(cal.getTime()), Level, Message, 31 | ANSI_RESET)); 32 | else 33 | System.out.println(String.format("[%s] %s > %s", sdf.format(cal.getTime()), Level, Message)); 34 | } 35 | 36 | public static void info(String Message) { 37 | log("INFO", Message, ANSI_CYAN); 38 | } 39 | 40 | public static void debug(String Message) { 41 | log("DEBUG", Message, ANSI_PURPLE); 42 | } 43 | 44 | public static void warning(String Message) { 45 | log("WARN", Message, ANSI_YELLOW); 46 | } 47 | 48 | public static void error(String Message) { 49 | log("ERROR", Message, ANSI_RED); 50 | } 51 | } 52 | --------------------------------------------------------------------------------