commit c5ee4e27e6f5732047b4cbcb1a00d2c4fe19a666 Author: Fiereu Date: Sun Aug 3 18:40:38 2025 +0200 init diff --git a/.env b/.env new file mode 100644 index 0000000..e5039ef --- /dev/null +++ b/.env @@ -0,0 +1,8 @@ +LOGIN_DB_PORT=20011 +LOGIN_DB_NAME=openmmo_login_db +LOGIN_DB_USER=openmmo_login_user +LOGIN_DB_PASSWORD=changeMe! +GAME_DB_PORT=20021 +GAME_DB_NAME=openmmo_game_db +GAME_DB_USER=openmmo_game_user +GAME_DB_PASSWORD=changeMe! diff --git a/.forgejo/CODEOWNERS b/.forgejo/CODEOWNERS new file mode 100644 index 0000000..78bdb5f --- /dev/null +++ b/.forgejo/CODEOWNERS @@ -0,0 +1,2 @@ +# Restrict access to priviliged files like actions +.forgejo/** @OpenMMO/Owners \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..108d567 --- /dev/null +++ b/.gitignore @@ -0,0 +1,42 @@ +.gradle +build/ +!gradle/wrapper/gradle-wrapper.jar +!**/src/main/**/build/ +!**/src/test/**/build/ + +### IntelliJ IDEA ### +.idea/ +*.iws +*.iml +*.ipr +out/ +!**/src/main/**/out/ +!**/src/test/**/out/ + +### Kotlin ### +.kotlin + +### Eclipse ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache +bin/ +!**/src/main/**/bin/ +!**/src/test/**/bin/ + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ + +### VS Code ### +.vscode/ + +### Mac OS ### +.DS_Store \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..0ad25db --- /dev/null +++ b/LICENSE @@ -0,0 +1,661 @@ + GNU AFFERO GENERAL PUBLIC LICENSE + Version 3, 19 November 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + Preamble + + The GNU Affero General Public License is a free, copyleft license for +software and other kinds of works, specifically designed to ensure +cooperation with the community in the case of network server software. + + The licenses for most software and other practical works are designed +to take away your freedom to share and change the works. By contrast, +our General Public Licenses are intended to guarantee your freedom to +share and change all versions of a program--to make sure it remains free +software for all its users. + + When we speak of free software, we are referring to freedom, not +price. Our General Public Licenses are designed to make sure that you +have the freedom to distribute copies of free software (and charge for +them if you wish), that you receive source code or can get it if you +want it, that you can change the software or use pieces of it in new +free programs, and that you know you can do these things. + + Developers that use our General Public Licenses protect your rights +with two steps: (1) assert copyright on the software, and (2) offer +you this License which gives you legal permission to copy, distribute +and/or modify the software. + + A secondary benefit of defending all users' freedom is that +improvements made in alternate versions of the program, if they +receive widespread use, become available for other developers to +incorporate. Many developers of free software are heartened and +encouraged by the resulting cooperation. However, in the case of +software used on network servers, this result may fail to come about. +The GNU General Public License permits making a modified version and +letting the public access it on a server without ever releasing its +source code to the public. + + The GNU Affero General Public License is designed specifically to +ensure that, in such cases, the modified source code becomes available +to the community. It requires the operator of a network server to +provide the source code of the modified version running there to the +users of that server. Therefore, public use of a modified version, on +a publicly accessible server, gives the public access to the source +code of the modified version. + + An older license, called the Affero General Public License and +published by Affero, was designed to accomplish similar goals. This is +a different license, not a version of the Affero GPL, but Affero has +released a new version of the Affero GPL which permits relicensing under +this license. + + The precise terms and conditions for copying, distribution and +modification follow. + + TERMS AND CONDITIONS + + 0. Definitions. + + "This License" refers to version 3 of the GNU Affero General Public License. + + "Copyright" also means copyright-like laws that apply to other kinds of +works, such as semiconductor masks. + + "The Program" refers to any copyrightable work licensed under this +License. Each licensee is addressed as "you". "Licensees" and +"recipients" may be individuals or organizations. + + To "modify" a work means to copy from or adapt all or part of the work +in a fashion requiring copyright permission, other than the making of an +exact copy. The resulting work is called a "modified version" of the +earlier work or a work "based on" the earlier work. + + A "covered work" means either the unmodified Program or a work based +on the Program. + + To "propagate" a work means to do anything with it that, without +permission, would make you directly or secondarily liable for +infringement under applicable copyright law, except executing it on a +computer or modifying a private copy. Propagation includes copying, +distribution (with or without modification), making available to the +public, and in some countries other activities as well. + + To "convey" a work means any kind of propagation that enables other +parties to make or receive copies. Mere interaction with a user through +a computer network, with no transfer of a copy, is not conveying. + + An interactive user interface displays "Appropriate Legal Notices" +to the extent that it includes a convenient and prominently visible +feature that (1) displays an appropriate copyright notice, and (2) +tells the user that there is no warranty for the work (except to the +extent that warranties are provided), that licensees may convey the +work under this License, and how to view a copy of this License. If +the interface presents a list of user commands or options, such as a +menu, a prominent item in the list meets this criterion. + + 1. Source Code. + + The "source code" for a work means the preferred form of the work +for making modifications to it. "Object code" means any non-source +form of a work. + + A "Standard Interface" means an interface that either is an official +standard defined by a recognized standards body, or, in the case of +interfaces specified for a particular programming language, one that +is widely used among developers working in that language. + + The "System Libraries" of an executable work include anything, other +than the work as a whole, that (a) is included in the normal form of +packaging a Major Component, but which is not part of that Major +Component, and (b) serves only to enable use of the work with that +Major Component, or to implement a Standard Interface for which an +implementation is available to the public in source code form. A +"Major Component", in this context, means a major essential component +(kernel, window system, and so on) of the specific operating system +(if any) on which the executable work runs, or a compiler used to +produce the work, or an object code interpreter used to run it. + + The "Corresponding Source" for a work in object code form means all +the source code needed to generate, install, and (for an executable +work) run the object code and to modify the work, including scripts to +control those activities. However, it does not include the work's +System Libraries, or general-purpose tools or generally available free +programs which are used unmodified in performing those activities but +which are not part of the work. For example, Corresponding Source +includes interface definition files associated with source files for +the work, and the source code for shared libraries and dynamically +linked subprograms that the work is specifically designed to require, +such as by intimate data communication or control flow between those +subprograms and other parts of the work. + + The Corresponding Source need not include anything that users +can regenerate automatically from other parts of the Corresponding +Source. + + The Corresponding Source for a work in source code form is that +same work. + + 2. Basic Permissions. + + All rights granted under this License are granted for the term of +copyright on the Program, and are irrevocable provided the stated +conditions are met. This License explicitly affirms your unlimited +permission to run the unmodified Program. The output from running a +covered work is covered by this License only if the output, given its +content, constitutes a covered work. This License acknowledges your +rights of fair use or other equivalent, as provided by copyright law. + + You may make, run and propagate covered works that you do not +convey, without conditions so long as your license otherwise remains +in force. You may convey covered works to others for the sole purpose +of having them make modifications exclusively for you, or provide you +with facilities for running those works, provided that you comply with +the terms of this License in conveying all material for which you do +not control copyright. Those thus making or running the covered works +for you must do so exclusively on your behalf, under your direction +and control, on terms that prohibit them from making any copies of +your copyrighted material outside their relationship with you. + + Conveying under any other circumstances is permitted solely under +the conditions stated below. Sublicensing is not allowed; section 10 +makes it unnecessary. + + 3. Protecting Users' Legal Rights From Anti-Circumvention Law. + + No covered work shall be deemed part of an effective technological +measure under any applicable law fulfilling obligations under article +11 of the WIPO copyright treaty adopted on 20 December 1996, or +similar laws prohibiting or restricting circumvention of such +measures. + + When you convey a covered work, you waive any legal power to forbid +circumvention of technological measures to the extent such circumvention +is effected by exercising rights under this License with respect to +the covered work, and you disclaim any intention to limit operation or +modification of the work as a means of enforcing, against the work's +users, your or third parties' legal rights to forbid circumvention of +technological measures. + + 4. Conveying Verbatim Copies. + + You may convey verbatim copies of the Program's source code as you +receive it, in any medium, provided that you conspicuously and +appropriately publish on each copy an appropriate copyright notice; +keep intact all notices stating that this License and any +non-permissive terms added in accord with section 7 apply to the code; +keep intact all notices of the absence of any warranty; and give all +recipients a copy of this License along with the Program. + + You may charge any price or no price for each copy that you convey, +and you may offer support or warranty protection for a fee. + + 5. Conveying Modified Source Versions. + + You may convey a work based on the Program, or the modifications to +produce it from the Program, in the form of source code under the +terms of section 4, provided that you also meet all of these conditions: + + a) The work must carry prominent notices stating that you modified + it, and giving a relevant date. + + b) The work must carry prominent notices stating that it is + released under this License and any conditions added under section + 7. This requirement modifies the requirement in section 4 to + "keep intact all notices". + + c) You must license the entire work, as a whole, under this + License to anyone who comes into possession of a copy. This + License will therefore apply, along with any applicable section 7 + additional terms, to the whole of the work, and all its parts, + regardless of how they are packaged. This License gives no + permission to license the work in any other way, but it does not + invalidate such permission if you have separately received it. + + d) If the work has interactive user interfaces, each must display + Appropriate Legal Notices; however, if the Program has interactive + interfaces that do not display Appropriate Legal Notices, your + work need not make them do so. + + A compilation of a covered work with other separate and independent +works, which are not by their nature extensions of the covered work, +and which are not combined with it such as to form a larger program, +in or on a volume of a storage or distribution medium, is called an +"aggregate" if the compilation and its resulting copyright are not +used to limit the access or legal rights of the compilation's users +beyond what the individual works permit. Inclusion of a covered work +in an aggregate does not cause this License to apply to the other +parts of the aggregate. + + 6. Conveying Non-Source Forms. + + You may convey a covered work in object code form under the terms +of sections 4 and 5, provided that you also convey the +machine-readable Corresponding Source under the terms of this License, +in one of these ways: + + a) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by the + Corresponding Source fixed on a durable physical medium + customarily used for software interchange. + + b) Convey the object code in, or embodied in, a physical product + (including a physical distribution medium), accompanied by a + written offer, valid for at least three years and valid for as + long as you offer spare parts or customer support for that product + model, to give anyone who possesses the object code either (1) a + copy of the Corresponding Source for all the software in the + product that is covered by this License, on a durable physical + medium customarily used for software interchange, for a price no + more than your reasonable cost of physically performing this + conveying of source, or (2) access to copy the + Corresponding Source from a network server at no charge. + + c) Convey individual copies of the object code with a copy of the + written offer to provide the Corresponding Source. This + alternative is allowed only occasionally and noncommercially, and + only if you received the object code with such an offer, in accord + with subsection 6b. + + d) Convey the object code by offering access from a designated + place (gratis or for a charge), and offer equivalent access to the + Corresponding Source in the same way through the same place at no + further charge. You need not require recipients to copy the + Corresponding Source along with the object code. If the place to + copy the object code is a network server, the Corresponding Source + may be on a different server (operated by you or a third party) + that supports equivalent copying facilities, provided you maintain + clear directions next to the object code saying where to find the + Corresponding Source. Regardless of what server hosts the + Corresponding Source, you remain obligated to ensure that it is + available for as long as needed to satisfy these requirements. + + e) Convey the object code using peer-to-peer transmission, provided + you inform other peers where the object code and Corresponding + Source of the work are being offered to the general public at no + charge under subsection 6d. + + A separable portion of the object code, whose source code is excluded +from the Corresponding Source as a System Library, need not be +included in conveying the object code work. + + A "User Product" is either (1) a "consumer product", which means any +tangible personal property which is normally used for personal, family, +or household purposes, or (2) anything designed or sold for incorporation +into a dwelling. In determining whether a product is a consumer product, +doubtful cases shall be resolved in favor of coverage. For a particular +product received by a particular user, "normally used" refers to a +typical or common use of that class of product, regardless of the status +of the particular user or of the way in which the particular user +actually uses, or expects or is expected to use, the product. A product +is a consumer product regardless of whether the product has substantial +commercial, industrial or non-consumer uses, unless such uses represent +the only significant mode of use of the product. + + "Installation Information" for a User Product means any methods, +procedures, authorization keys, or other information required to install +and execute modified versions of a covered work in that User Product from +a modified version of its Corresponding Source. The information must +suffice to ensure that the continued functioning of the modified object +code is in no case prevented or interfered with solely because +modification has been made. + + If you convey an object code work under this section in, or with, or +specifically for use in, a User Product, and the conveying occurs as +part of a transaction in which the right of possession and use of the +User Product is transferred to the recipient in perpetuity or for a +fixed term (regardless of how the transaction is characterized), the +Corresponding Source conveyed under this section must be accompanied +by the Installation Information. But this requirement does not apply +if neither you nor any third party retains the ability to install +modified object code on the User Product (for example, the work has +been installed in ROM). + + The requirement to provide Installation Information does not include a +requirement to continue to provide support service, warranty, or updates +for a work that has been modified or installed by the recipient, or for +the User Product in which it has been modified or installed. Access to a +network may be denied when the modification itself materially and +adversely affects the operation of the network or violates the rules and +protocols for communication across the network. + + Corresponding Source conveyed, and Installation Information provided, +in accord with this section must be in a format that is publicly +documented (and with an implementation available to the public in +source code form), and must require no special password or key for +unpacking, reading or copying. + + 7. Additional Terms. + + "Additional permissions" are terms that supplement the terms of this +License by making exceptions from one or more of its conditions. +Additional permissions that are applicable to the entire Program shall +be treated as though they were included in this License, to the extent +that they are valid under applicable law. If additional permissions +apply only to part of the Program, that part may be used separately +under those permissions, but the entire Program remains governed by +this License without regard to the additional permissions. + + When you convey a copy of a covered work, you may at your option +remove any additional permissions from that copy, or from any part of +it. (Additional permissions may be written to require their own +removal in certain cases when you modify the work.) You may place +additional permissions on material, added by you to a covered work, +for which you have or can give appropriate copyright permission. + + Notwithstanding any other provision of this License, for material you +add to a covered work, you may (if authorized by the copyright holders of +that material) supplement the terms of this License with terms: + + a) Disclaiming warranty or limiting liability differently from the + terms of sections 15 and 16 of this License; or + + b) Requiring preservation of specified reasonable legal notices or + author attributions in that material or in the Appropriate Legal + Notices displayed by works containing it; or + + c) Prohibiting misrepresentation of the origin of that material, or + requiring that modified versions of such material be marked in + reasonable ways as different from the original version; or + + d) Limiting the use for publicity purposes of names of licensors or + authors of the material; or + + e) Declining to grant rights under trademark law for use of some + trade names, trademarks, or service marks; or + + f) Requiring indemnification of licensors and authors of that + material by anyone who conveys the material (or modified versions of + it) with contractual assumptions of liability to the recipient, for + any liability that these contractual assumptions directly impose on + those licensors and authors. + + All other non-permissive additional terms are considered "further +restrictions" within the meaning of section 10. If the Program as you +received it, or any part of it, contains a notice stating that it is +governed by this License along with a term that is a further +restriction, you may remove that term. If a license document contains +a further restriction but permits relicensing or conveying under this +License, you may add to a covered work material governed by the terms +of that license document, provided that the further restriction does +not survive such relicensing or conveying. + + If you add terms to a covered work in accord with this section, you +must place, in the relevant source files, a statement of the +additional terms that apply to those files, or a notice indicating +where to find the applicable terms. + + Additional terms, permissive or non-permissive, may be stated in the +form of a separately written license, or stated as exceptions; +the above requirements apply either way. + + 8. Termination. + + You may not propagate or modify a covered work except as expressly +provided under this License. Any attempt otherwise to propagate or +modify it is void, and will automatically terminate your rights under +this License (including any patent licenses granted under the third +paragraph of section 11). + + However, if you cease all violation of this License, then your +license from a particular copyright holder is reinstated (a) +provisionally, unless and until the copyright holder explicitly and +finally terminates your license, and (b) permanently, if the copyright +holder fails to notify you of the violation by some reasonable means +prior to 60 days after the cessation. + + Moreover, your license from a particular copyright holder is +reinstated permanently if the copyright holder notifies you of the +violation by some reasonable means, this is the first time you have +received notice of violation of this License (for any work) from that +copyright holder, and you cure the violation prior to 30 days after +your receipt of the notice. + + Termination of your rights under this section does not terminate the +licenses of parties who have received copies or rights from you under +this License. If your rights have been terminated and not permanently +reinstated, you do not qualify to receive new licenses for the same +material under section 10. + + 9. Acceptance Not Required for Having Copies. + + You are not required to accept this License in order to receive or +run a copy of the Program. Ancillary propagation of a covered work +occurring solely as a consequence of using peer-to-peer transmission +to receive a copy likewise does not require acceptance. However, +nothing other than this License grants you permission to propagate or +modify any covered work. These actions infringe copyright if you do +not accept this License. Therefore, by modifying or propagating a +covered work, you indicate your acceptance of this License to do so. + + 10. Automatic Licensing of Downstream Recipients. + + Each time you convey a covered work, the recipient automatically +receives a license from the original licensors, to run, modify and +propagate that work, subject to this License. You are not responsible +for enforcing compliance by third parties with this License. + + An "entity transaction" is a transaction transferring control of an +organization, or substantially all assets of one, or subdividing an +organization, or merging organizations. If propagation of a covered +work results from an entity transaction, each party to that +transaction who receives a copy of the work also receives whatever +licenses to the work the party's predecessor in interest had or could +give under the previous paragraph, plus a right to possession of the +Corresponding Source of the work from the predecessor in interest, if +the predecessor has it or can get it with reasonable efforts. + + You may not impose any further restrictions on the exercise of the +rights granted or affirmed under this License. For example, you may +not impose a license fee, royalty, or other charge for exercise of +rights granted under this License, and you may not initiate litigation +(including a cross-claim or counterclaim in a lawsuit) alleging that +any patent claim is infringed by making, using, selling, offering for +sale, or importing the Program or any portion of it. + + 11. Patents. + + A "contributor" is a copyright holder who authorizes use under this +License of the Program or a work on which the Program is based. The +work thus licensed is called the contributor's "contributor version". + + A contributor's "essential patent claims" are all patent claims +owned or controlled by the contributor, whether already acquired or +hereafter acquired, that would be infringed by some manner, permitted +by this License, of making, using, or selling its contributor version, +but do not include claims that would be infringed only as a +consequence of further modification of the contributor version. For +purposes of this definition, "control" includes the right to grant +patent sublicenses in a manner consistent with the requirements of +this License. + + Each contributor grants you a non-exclusive, worldwide, royalty-free +patent license under the contributor's essential patent claims, to +make, use, sell, offer for sale, import and otherwise run, modify and +propagate the contents of its contributor version. + + In the following three paragraphs, a "patent license" is any express +agreement or commitment, however denominated, not to enforce a patent +(such as an express permission to practice a patent or covenant not to +sue for patent infringement). To "grant" such a patent license to a +party means to make such an agreement or commitment not to enforce a +patent against the party. + + If you convey a covered work, knowingly relying on a patent license, +and the Corresponding Source of the work is not available for anyone +to copy, free of charge and under the terms of this License, through a +publicly available network server or other readily accessible means, +then you must either (1) cause the Corresponding Source to be so +available, or (2) arrange to deprive yourself of the benefit of the +patent license for this particular work, or (3) arrange, in a manner +consistent with the requirements of this License, to extend the patent +license to downstream recipients. "Knowingly relying" means you have +actual knowledge that, but for the patent license, your conveying the +covered work in a country, or your recipient's use of the covered work +in a country, would infringe one or more identifiable patents in that +country that you have reason to believe are valid. + + If, pursuant to or in connection with a single transaction or +arrangement, you convey, or propagate by procuring conveyance of, a +covered work, and grant a patent license to some of the parties +receiving the covered work authorizing them to use, propagate, modify +or convey a specific copy of the covered work, then the patent license +you grant is automatically extended to all recipients of the covered +work and works based on it. + + A patent license is "discriminatory" if it does not include within +the scope of its coverage, prohibits the exercise of, or is +conditioned on the non-exercise of one or more of the rights that are +specifically granted under this License. You may not convey a covered +work if you are a party to an arrangement with a third party that is +in the business of distributing software, under which you make payment +to the third party based on the extent of your activity of conveying +the work, and under which the third party grants, to any of the +parties who would receive the covered work from you, a discriminatory +patent license (a) in connection with copies of the covered work +conveyed by you (or copies made from those copies), or (b) primarily +for and in connection with specific products or compilations that +contain the covered work, unless you entered into that arrangement, +or that patent license was granted, prior to 28 March 2007. + + Nothing in this License shall be construed as excluding or limiting +any implied license or other defenses to infringement that may +otherwise be available to you under applicable patent law. + + 12. No Surrender of Others' Freedom. + + If conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot convey a +covered work so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you may +not convey it at all. For example, if you agree to terms that obligate you +to collect a royalty for further conveying from those to whom you convey +the Program, the only way you could satisfy both those terms and this +License would be to refrain entirely from conveying the Program. + + 13. Remote Network Interaction; Use with the GNU General Public License. + + Notwithstanding any other provision of this License, if you modify the +Program, your modified version must prominently offer all users +interacting with it remotely through a computer network (if your version +supports such interaction) an opportunity to receive the Corresponding +Source of your version by providing access to the Corresponding Source +from a network server at no charge, through some standard or customary +means of facilitating copying of software. This Corresponding Source +shall include the Corresponding Source for any work covered by version 3 +of the GNU General Public License that is incorporated pursuant to the +following paragraph. + + Notwithstanding any other provision of this License, you have +permission to link or combine any covered work with a work licensed +under version 3 of the GNU General Public License into a single +combined work, and to convey the resulting work. The terms of this +License will continue to apply to the part which is the covered work, +but the work with which it is combined will remain governed by version +3 of the GNU General Public License. + + 14. Revised Versions of this License. + + The Free Software Foundation may publish revised and/or new versions of +the GNU Affero General Public License from time to time. Such new versions +will be similar in spirit to the present version, but may differ in detail to +address new problems or concerns. + + Each version is given a distinguishing version number. If the +Program specifies that a certain numbered version of the GNU Affero General +Public License "or any later version" applies to it, you have the +option of following the terms and conditions either of that numbered +version or of any later version published by the Free Software +Foundation. If the Program does not specify a version number of the +GNU Affero General Public License, you may choose any version ever published +by the Free Software Foundation. + + If the Program specifies that a proxy can decide which future +versions of the GNU Affero General Public License can be used, that proxy's +public statement of acceptance of a version permanently authorizes you +to choose that version for the Program. + + Later license versions may give you additional or different +permissions. However, no additional obligations are imposed on any +author or copyright holder as a result of your choosing to follow a +later version. + + 15. Disclaimer of Warranty. + + THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY +APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT +HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY +OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, +THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM +IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF +ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. Limitation of Liability. + + IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING +WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS +THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY +GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE +USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF +DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD +PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), +EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF +SUCH DAMAGES. + + 17. Interpretation of Sections 15 and 16. + + If the disclaimer of warranty and limitation of liability provided +above cannot be given local legal effect according to their terms, +reviewing courts shall apply local law that most closely approximates +an absolute waiver of all civil liability in connection with the +Program, unless a warranty or assumption of liability accompanies a +copy of the Program in return for a fee. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program is free software: you can redistribute it and/or modify + it under the terms of the GNU Affero General Public License as published + by the Free Software Foundation, either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU Affero General Public License for more details. + + You should have received a copy of the GNU Affero General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If your software can interact with users remotely through a computer +network, you should also make sure that it provides a way for users to +get its source. For example, if your program is a web application, its +interface could display a "Source" link that leads users to an archive +of the code. There are many ways you could offer source, and different +solutions will be better for different programs; see section 13 for the +specific requirements. + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU AGPL, see +. diff --git a/README.md b/README.md new file mode 100644 index 0000000..d2f411e --- /dev/null +++ b/README.md @@ -0,0 +1,38 @@ +# OpenMMO + +[![](https://dcbadge.limes.pink/api/server/SQwGXyY2gz)](https://discord.gg/SQwGXyY2gz) + +## ToC +- [Description](#description) +- [Modules](#modules) +- [Protocol Documentation](#protocol-documentation) +- [Docker](#docker) +- [License](LICENSE) +- [Disclaimer](#disclaimer) + +## Description + +> OpenMMO is currently in development and not yet ready for any real use. + +OpenMMO is an open-source implementation of the PokeMMO server. +The goal is it to provide a free and open-source alternative to the PokeMMO server. + +## Modules +OpenMMO is split into several modules for better organization and easier documentation. +- [common](common/README.md): Common enums and shared utilities used across most modules. +- [keys](keys/README.md): A module for generating the keys used by the servers for signing packets and by the client for verifying them. +- [patcher](patcher/README.md): A tool for applying patches to the PokeMMO client so that it can connect to OpenMMO. +- [protocol](protocol/README.md): Core packet protocol framework with serialization and deserialization. +- [protocol.tls](protocol.tls/README.md): TLS-like protocol implementation for secure client-server communication. +- [protocol.login](protocol.login/README.md): Login-specific protocol packets and serialization. +- [server](server/README.md): Core server framework using Netty for networking and protocol handling. +- [server.login](server.login/README.md): Login server implementation with authentication and database integration. + +## Protocol Documentation +Detailed specifications and technical documentation for the network protocols used in OpenMMO. + +- [TLS Protocol](docs/protocol/tls/index.md): Custom TLS-like protocol specification with ECDH key exchange, ECDSA authentication, and packet structure diagrams. + +## Disclaimer +[PokeMMO](https://pokemmo.eu/) is not affiliated with this project in any way. +Hosting/Using a private server might be against the [PokeMMO ToS](https://pokemmo.com/tos/). diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..1597158 --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,23 @@ +allprojects { + beforeEvaluate { + loadEnvFile("${rootDir.absolutePath}/.env") + } +} + +fun loadEnvFile(fileName: String) { + val file = rootProject.file(fileName) + if (file.exists()) { + file.forEachLine { line -> + if (line.isNotBlank() && !line.startsWith("#")) { + val parts = line.split("=", limit = 2) + if (parts.size == 2) { + System.setProperty(parts[0].trim(), parts[1].trim()) + } else { + throw IllegalArgumentException("Invalid line in env file: $line") + } + } + } + } else { + throw IllegalArgumentException("Env file '$fileName' does not exist.") + } +} \ No newline at end of file diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..c01927a --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,13 @@ +plugins { + `kotlin-dsl` +} + +kotlin { + jvmToolchain(24) +} + +dependencies { + implementation(libs.kotlinGradlePlugin) + implementation(libs.spotlessGradlePlugin) + implementation(libs.junit5) +} diff --git a/buildSrc/settings.gradle.kts b/buildSrc/settings.gradle.kts new file mode 100644 index 0000000..9b093a5 --- /dev/null +++ b/buildSrc/settings.gradle.kts @@ -0,0 +1,14 @@ +dependencyResolutionManagement { + @Suppress("UnstableApiUsage") + repositories { + mavenCentral() + } + + versionCatalogs { + create("libs") { + from(files("../gradle/libs.versions.toml")) + } + } +} + +rootProject.name = "buildSrc" \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/keys.gradle.kts b/buildSrc/src/main/kotlin/keys.gradle.kts new file mode 100644 index 0000000..92df5cb --- /dev/null +++ b/buildSrc/src/main/kotlin/keys.gradle.kts @@ -0,0 +1,67 @@ +package buildsrc.common + +val KEYS_RESOURCE_LOCATION = "src/main/resources" + +tasks.register("copyPublicKeyChat") { + group = "openmmo" + description = "Copy chat keys from \":keys\" to the current projects resources directory" + from(project(":keys").tasks.getByName("generateChat").outputs.files) { + include("*.public.pem") + } + into(project.layout.projectDirectory.dir(KEYS_RESOURCE_LOCATION)) + tasks.getByName("processResources").let { it.mustRunAfter("copyPublicKeyChat") } +} + +tasks.register("copyPrivateKeyChat") { + group = "openmmo" + description = "Copy chat keys from \":keys\" to the current projects resources directory" + from(project(":keys").tasks.getByName("generateChat").outputs.files) { + include("*.public.pem") + } + into(project.layout.projectDirectory.dir(KEYS_RESOURCE_LOCATION)) + tasks.getByName("processResources").let { it.mustRunAfter("copyPrivateKeyChat") } +} + +tasks.register("copyKeysChat") { + group = "openmmo" + description = "Copies all chat keys from \":keys\" to the current projects resources directory" + dependsOn("copyPublicKeyChat", "copyPrivateKeyChat") +} + +tasks.register("copyPublicKeyGame") { + group = "openmmo" + description = "Copy game keys from \":keys\" to the current projects resources directory" + from(project(":keys").tasks.getByName("generateGame").outputs.files) { + include("*.public.pem") + } + into(project.layout.projectDirectory.dir(KEYS_RESOURCE_LOCATION)) + tasks.getByName("processResources").let { it.mustRunAfter("copyPublicKeyGame") } +} + +tasks.register("copyPrivateKeyGame") { + group = "openmmo" + description = "Copy game keys from \":keys\" to the current projects resources directory" + from(project(":keys").tasks.getByName("generateGame").outputs.files) { + include("*.private.pem") + } + into(project.layout.projectDirectory.dir(KEYS_RESOURCE_LOCATION)) + tasks.getByName("processResources").let { it.mustRunAfter("copyPrivateKeyGame") } +} + +tasks.register("copyKeysGame") { + group = "openmmo" + description = "Copies all game keys from \":keys\" to the current projects resources directory" + dependsOn("copyPublicKeyGame", "copyPrivateKeyGame") +} + +tasks.register("copyPublicKeys") { + group = "openmmo" + description = "Copies all public keys from \":keys\" to the current projects resources directory" + dependsOn("copyPublicKeyChat", "copyPublicKeyGame") +} + +tasks.register("copyKeys") { + group = "openmmo" + description = "Copies all keys from \":keys\" to the current projects resources directory" + dependsOn("copyKeysChat", "copyKeysGame") +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/kotlin-jvm.gradle.kts b/buildSrc/src/main/kotlin/kotlin-jvm.gradle.kts new file mode 100644 index 0000000..5490e5a --- /dev/null +++ b/buildSrc/src/main/kotlin/kotlin-jvm.gradle.kts @@ -0,0 +1,29 @@ +package buildsrc.convention + +import org.gradle.api.tasks.testing.logging.TestLogEvent +import org.gradle.kotlin.dsl.dependencies +import org.gradle.kotlin.dsl.withType + +plugins { + kotlin("jvm") +} + +kotlin { + jvmToolchain(24) +} + +dependencies { + testImplementation(kotlin("test")) +} + +tasks.withType().configureEach { + useJUnitPlatform() + + testLogging { + events( + TestLogEvent.FAILED, + TestLogEvent.PASSED, + TestLogEvent.SKIPPED + ) + } +} diff --git a/buildSrc/src/main/kotlin/spotless.gradle.kts b/buildSrc/src/main/kotlin/spotless.gradle.kts new file mode 100644 index 0000000..ee1d5f7 --- /dev/null +++ b/buildSrc/src/main/kotlin/spotless.gradle.kts @@ -0,0 +1,31 @@ +package buildsrc.convention + +import com.diffplug.spotless.LineEnding + +plugins { + id("com.diffplug.spotless") +} + +spotless { + encoding("UTF-8") + lineEndings = LineEnding.UNIX + kotlinGradle { + target("**/*.gradle.kts") + ktfmt() + trimTrailingWhitespace() + endWithNewline() + } + kotlin { + target("**/src/**/*.kt") + ktfmt() + trimTrailingWhitespace() + endWithNewline() + } + format("misc") { + target("**/*.md", "**/*.yml", "**/*.yaml", "**/*.properties") + trimTrailingWhitespace() + endWithNewline() + } +} + +tasks.withType { dependsOn("spotlessCheck") } \ No newline at end of file diff --git a/common/README.md b/common/README.md new file mode 100644 index 0000000..661cd59 --- /dev/null +++ b/common/README.md @@ -0,0 +1,3 @@ +# Common Module + +The common module contains shared enums and utilities used across most OpenMMO modules. \ No newline at end of file diff --git a/common/build.gradle.kts b/common/build.gradle.kts new file mode 100644 index 0000000..b8ff151 --- /dev/null +++ b/common/build.gradle.kts @@ -0,0 +1,4 @@ +plugins { + id("buildsrc.convention.kotlin-jvm") + id("buildsrc.convention.spotless") +} diff --git a/common/src/main/kotlin/de/fiereu/openmmo/enums/Language.kt b/common/src/main/kotlin/de/fiereu/openmmo/enums/Language.kt new file mode 100644 index 0000000..26725c9 --- /dev/null +++ b/common/src/main/kotlin/de/fiereu/openmmo/enums/Language.kt @@ -0,0 +1,33 @@ +package de.fiereu.openmmo.common.enums + +enum class Language( + val code: String, + private val english: String, + private val display: String +) { + EN("en", "english", "English"), + FR("fr", "french", "Français"), + DE("de", "german", "Deutsch"), + ES("es", "spanish", "Español"), + PT("pt", "portuguese", "Português"), + IT("it", "italian", "Italiano"), + NL("nl", "dutch", "Nederlands"), + PL("pl", "polish", "Polski"), + EL("el", "greek", "Eλληνικá"), + TR("tr", "turkish", "Türkçe"), + FIL("fil", "filipino", "Filipino"), + RU("ru", "russian", "Русский"), + KO("ko", "korean", "한국어"), + JA("ja", "japanese", "日本語"), + CN("cn", "chinese", "简体中文"), + OTHER("other", "other", "Other"), + ; + + companion object { + private val codeMap = entries.associateBy { it.code } + + fun fromCode(code: String): Language { + return codeMap[code] ?: OTHER + } + } +} \ No newline at end of file diff --git a/compose-dev.yaml b/compose-dev.yaml new file mode 100644 index 0000000..81953a4 --- /dev/null +++ b/compose-dev.yaml @@ -0,0 +1,11 @@ +services: + login-db: + image: postgres:latest + container_name: login-db + restart: unless-stopped + environment: + POSTGRES_DB: $LOGIN_DB_NAME + POSTGRES_USER: $LOGIN_DB_USER + POSTGRES_PASSWORD: $LOGIN_DB_PASSWORD + ports: + - $LOGIN_DB_PORT:5432 \ No newline at end of file diff --git a/docs/jdk_version.md b/docs/jdk_version.md new file mode 100644 index 0000000..a9a9a31 --- /dev/null +++ b/docs/jdk_version.md @@ -0,0 +1,4 @@ +# JDK Version + +The goal is to use the most recent JDK version that is compatible with the project. As of now, the project is tested and works with JDK 24. +This may change in the future, so please check `buildSrc/src/main/kotlin/kotlin-jvm.gradle.kts` for the latest version used in the project. \ No newline at end of file diff --git a/docs/protocol/tls/index.md b/docs/protocol/tls/index.md new file mode 100644 index 0000000..98bbafc --- /dev/null +++ b/docs/protocol/tls/index.md @@ -0,0 +1,246 @@ +# OpenMMO TLS Protocol Specification + +The OpenMMO TLS Protocol is a custom TLS-like implementation designed for secure communication between the PokeMMO client and server. This protocol establishes encrypted communication channels using ECDH key exchange. + +## Protocol Flow + +The TLS handshake follows a 3-packet exchange pattern: + +```mermaid +sequenceDiagram + participant Client + participant Server + + Note over Client,Server: TLS Handshake Phase + + Client->>Server: 1. ClientHello (0x00) + Note right of Client: Contains obfuscated timestamp + + Server->>Client: 2. ServerHello (0x01) + Note left of Server: Server public key + signature + checksum size + + Note over Client: Checks signature using known root public key
Derives shared secret via ECDH
Switches to secure mode + + Client->>Server: 3. ClientReady (0x02) + Note right of Client: Client public key + + Note over Server: Derives shared secret via ECDH
Switches to next protocol + + Note over Client,Server: Secure Communication Established
Switch to Application Protocol (e.g., Login) +``` + +## Packet Specifications + +### 1. ClientHello Packet (Opcode: 0x00) + +The ClientHello packet initiates the TLS handshake and contains an obfuscated timestamp for replay attack protection. + +```mermaid +packet + title ClientHello Packet Structure + 0-63: "Obfuscated Random Key (8 bytes)" + 64-127: "Obfuscated Timestamp (8 bytes)" +``` + +#### Field Details +- **Obfuscated Random Key**: Random value XOR'd with predefined key1 constant +- **Obfuscated Timestamp**: Client timestamp XOR'd with key2 and random key + +#### Obfuscation Algorithm +``` +randomKey = Random.nextLong() +xoredRandomKey = randomKey XOR key1 +xoredTimestamp = timestamp XOR key2 XOR randomKey +``` + +### 2. ServerHello Packet (Opcode: 0x01) + +The ServerHello packet contains the server's public key, authentication signature, and the checksum algorithm. + +```mermaid +packet + title ServerHello Packet Structure + 0-15: "Public Key Length (2 bytes, LE)" + 16-543: "Server Public Key (variable length, uncompressed point)" + 544-559: "Signature Length (2 bytes, LE)" + 560-1071: "ECDSA Signature (variable length)" + 1072-1079: "Checksum Size (1 byte)" +``` + +#### Field Details +- **Public Key Length**: Length of the public key data (typically 65 bytes) +- **Server Public Key**: ECDSA public key in uncompressed point format (0x04 + X + Y coordinates) +- **Signature Length**: Length of the ECDSA signature (typically 64 bytes) +- **ECDSA Signature**: Digital signature of the public key using server's root private key +- **Checksum Size**: Size of checksums to be used for subsequent packets (16 for HMAC-SHA256) + +### 3. ClientReady Packet (Opcode: 0x02) + +The ClientReady packet completes the handshake by providing the client's public key. + +```mermaid +packet + title ClientReady Packet Structure + 0-15: "Public Key Length (2 bytes, LE)" + 16-535: "Client Public Key (variable length, uncompressed point)" +``` + +#### Field Details +- **Public Key Length**: Length of the client's public key data (typically 65 bytes) +- **Client Public Key**: Client's ECDSA public key in uncompressed point format + +## Cryptographic Details + +### Elliptic Curve Parameters +- **Curve**: secp256r1 (P-256) +- **Key Size**: 256-bit +- **Public Key Format**: Uncompressed point (65 bytes: 0x04 + 32-byte X + 32-byte Y) +- **Signature Algorithm**: ECDSA with SHA-256 + +### Uncompressed Point De/Encoding + +``` +// Constants +UNCOMPRESSED_POINT_INDICATOR = 0x04 +CURVE = secp256r1 (P-256) +KEY_LENGTH = 32 // bytes for secp256r1 + +function encode_uncompressed_point(ecPublicKey): + point = ecPublicKey.getPoint() + x = point.getX().toByteArray() + y = point.getY().toByteArray() + + // Create output buffer: 1 byte indicator + 32 bytes X + 32 bytes Y + data = new ByteArray(1 + 2 * KEY_LENGTH) + offset = 0 + + // Set indicator + data[offset++] = UNCOMPRESSED_POINT_INDICATOR + + // Handle X coordinate (pad or trim to 32 bytes) + if x.length <= KEY_LENGTH: + // Right-pad with zeros if too short + copyBytes(x, 0, data, offset + KEY_LENGTH - x.length, x.length) + else if x.length == KEY_LENGTH + 1 AND x[0] == 0: + // Remove leading zero byte if present + copyBytes(x, 1, data, offset, KEY_LENGTH) + else: + throw "X coordinate too large" + + offset += KEY_LENGTH + + // Handle Y coordinate (same logic as X) + if y.length <= KEY_LENGTH: + copyBytes(y, 0, data, offset + KEY_LENGTH - y.length, y.length) + else if y.length == KEY_LENGTH + 1 AND y[0] == 0: + copyBytes(y, 1, data, offset, KEY_LENGTH) + else: + throw "Y coordinate too large" + + return data + +function decode_uncompressed_point(byteArray): + // Validate format + if byteArray[0] != UNCOMPRESSED_POINT_INDICATOR: + throw "Invalid uncompressed point indicator" + + if byteArray.length != 1 + 2 * KEY_LENGTH: + throw "Invalid data length" + + offset = 1 + + // Extract X coordinate (32 bytes) + x = bigIntegerFromBytes(byteArray[offset:offset + KEY_LENGTH]) + offset += KEY_LENGTH + + // Extract Y coordinate (32 bytes) + y = bigIntegerFromBytes(byteArray[offset:offset + KEY_LENGTH]) + + // Create EC point and public key + point = ECPoint(x, y) + return createECPublicKey(point, CURVE_SPEC) +``` + +### Key Derivation +After exchanging public keys, both client and server derive a shared secret using ECDH and generate symmetric encryption keys: + +``` +// ECDH Key Agreement +sharedSecret = ECDH(clientPrivateKey, serverPublicKey) // On client side +sharedSecret = ECDH(serverPrivateKey, clientPublicKey) // On server side + +// Key Derivation Constants +CLIENT_KEY_SALT = "KeySalt" + 0x01 +SERVER_KEY_SALT = "KeySalt" + 0x02 +COMMON_IV_SALT = "IVDERIV" + +function tripleHash(data, salt): + hasher = SHA-256() + hasher.update(salt) + hasher.update(data) + hasher.update(salt) + digest = hasher.finalize() + return digest[0:16] // First 16 bytes for 128-bit AES key + +// Derive Symmetric Keys (if shared secret >= 128 bits) +if sharedSecret.length * 8 >= 128: + clientSeed = tripleHash(sharedSecret, CLIENT_KEY_SALT) + serverSeed = tripleHash(sharedSecret, SERVER_KEY_SALT) +else: + // Fallback to default seeds + clientSeed = defaultClientSeed + serverSeed = defaultServerSeed + +// Create AES-CTR Ciphers +clientKey = AES_Key(clientSeed) +serverKey = AES_Key(serverSeed) +clientIV = tripleHash(clientSeed, COMMON_IV_SALT) +serverIV = tripleHash(serverSeed, COMMON_IV_SALT) + +// Initialize Ciphers +encryptionCipher = AES-CTR(serverKey, serverIV) // Server encrypts with server key +decryptionCipher = AES-CTR(clientKey, clientIV) // Server decrypts with client key +``` + +#### Key Usage +- **Client Seed**: Used for client-to-server encryption (server decrypts with this) +- **Server Seed**: Used for server-to-client encryption (server encrypts with this) +- **AES-CTR Mode**: Stream cipher mode enabling encryption/decryption of arbitrary length data +- **IV Derivation**: Initialization vectors derived using the same triple-hash with common salt +## Protocol State Machine + +```mermaid +stateDiagram-v2 + [*] --> Handshake: Connection Established
All packets are framed with length prefix + + state Handshake { + [*] --> WaitingClientHello + WaitingClientHello --> WaitingClientReady: Send ServerHello + WaitingClientReady --> HandshakeComplete: Receive ClientReady + } + + HandshakeComplete --> SecureCommunication: Switch to Application Protocol + + note right of SecureCommunication + All subsequent packets are: + - Framed with length prefix + - Checksummed (CRC16/HMAC-SHA256) + - Optionally encrypted + end note +``` + +## Implementation Notes + +### Packet Framing +- All packets are prefixed with a length field +- No encryption or checksum is applied during the handshake phase + +After the TLS handshake, all subsequent packets use the following format: +- Length prefix (variable encoding) +- Packet payload (encrypted if in secure mode) +- Checksum suffix (size determined by ServerHello) + +### Error Handling +- Invalid signatures result in connection termination +- Malformed packets trigger protocol violations +- Timestamp validation failures indicate potential replay attacks \ No newline at end of file diff --git a/gradle.properties b/gradle.properties new file mode 100644 index 0000000..5787b88 --- /dev/null +++ b/gradle.properties @@ -0,0 +1,19 @@ +org.gradle.caching=true +org.gradle.configuration-cache=true + +# Database settings +openmmo.db.login.port=${LOGIN_DB_PORT} +openmmo.db.login.name=${LOGIN_DB_NAME} +openmmo.db.login.user=${LOGIN_DB_USER} +openmmo.db.login.password=${LOGIN_DB_PASSWORD} +openmmo.db.game.port=${GAME_DB_PORT} +openmmo.db.game.name=${GAME_DB_NAME} +openmmo.db.game.user=${GAME_DB_USER} +openmmo.db.game.password=${GAME_DB_PASSWORD} + +# PokeMMO constants +pokemmo.mainClass=com.pokeemu.client.Client + +# May be overridden by the user +pokemmo.executable=${HOME}/.local/share/pokemmo/PokeMMO.exe +pokemmo.workingDir=${HOME}/.local/share/pokemmo/ \ No newline at end of file diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml new file mode 100644 index 0000000..70c71eb --- /dev/null +++ b/gradle/libs.versions.toml @@ -0,0 +1,64 @@ +[versions] +kotlin = "2.2.10" +kotlinx-serialization = "1.9.0" +kotlinx-coroutines = "1.10.2" +kotlin-logging = "7.0.7" # sl4j wrapper for Kotlin +logback = "1.5.13" +slf4j = "2.0.17" +asm = "9.8" +spotless = "7.2.1" +shadow = "9.0.2" +bouncycastle = "1.81" +junit5 = "6.0.0-M2" +kotest = "6.0.0" +mockk = "1.14.5" +jooq = "3.20.6" +postgresql = "42.7.7" +flyway = "11.10.4" +netty = "4.2.4.Final" +typesafe-config = "1.4.4" +dagger = "2.57" +ksp = "2.2.10-2.0.2" + +[libraries] +kotlinGradlePlugin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "kotlin" } +spotlessGradlePlugin = { module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotless" } +kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" } +kotlinx-serialization-core = { module = "org.jetbrains.kotlinx:kotlinx-serialization-core-jvm", version.ref = "kotlinx-serialization" } +kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json-jvm", version.ref = "kotlinx-serialization" } +kotlinx-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines" } +kotlinx-coroutines-test = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-test", version.ref = "kotlinx-coroutines" } +kotlin-logging = { module = "io.github.oshai:kotlin-logging-jvm", version.ref = "kotlin-logging" } +logback = { module = "ch.qos.logback:logback-classic", version.ref = "logback" } +slf4j = { module = "org.slf4j:slf4j-api", version.ref = "slf4j" } +asm = { module = "org.ow2.asm:asm", version.ref = "asm" } +bouncycastle-pkix = { module = "org.bouncycastle:bcpkix-jdk18on", version.ref = "bouncycastle" } +bouncycastle-provider = { module = "org.bouncycastle:bcprov-jdk18on", version.ref = "bouncycastle" } +junit5 = { module = "org.junit.jupiter:junit-jupiter-api", version.ref = "junit5" } +kotest-core = { module = "io.kotest:kotest-runner-junit5", version.ref = "kotest" } +kotest-assertions = { module = "io.kotest:kotest-assertions-core", version.ref = "kotest" } +kotest-framework = { module = "io.kotest:kotest-framework-engine", version.ref = "kotest" } +jooq = { module = "org.jooq:jooq", version.ref = "jooq" } +jooq-kotlin = { module = "org.jooq:jooq-kotlin", version.ref = "jooq" } +jooq-meta = { module = "org.jooq:jooq-meta", version.ref = "jooq" } +jooq-codegen = { module = "org.jooq:jooq-codegen", version.ref = "jooq" } +postgresql = { module = "org.postgresql:postgresql", version.ref = "postgresql" } +flyway-core = { module = "org.flywaydb:flyway-core", version.ref = "flyway" } +flyway-postgresql = { module = "org.flywaydb:flyway-database-postgresql", version.ref = "flyway" } +netty = { module = "io.netty:netty-all", version.ref = "netty" } +typesafe-config = { module = "com.typesafe:config", version.ref = "typesafe-config" } +dagger = { module = "com.google.dagger:dagger", version.ref = "dagger" } +dagger-compiler = { module = "com.google.dagger:dagger-compiler", version.ref = "dagger" } +mockk = { module = "io.mockk:mockk", version.ref = "mockk" } + +[bundles] +crypto = ["bouncycastle-pkix", "bouncycastle-provider"] +jooq = ["jooq", "jooq-kotlin", "jooq-meta", "jooq-codegen"] +kotest = ["kotest-core", "kotest-assertions", "kotest-framework"] + +[plugins] +kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" } +shadow = { id = "com.gradleup.shadow", version.ref = "shadow" } +jooq = { id = "org.jooq.jooq-codegen-gradle", version.ref = "jooq" } +flyway = { id = "org.flywaydb.flyway", version.ref = "flyway" } +ksp = { id = "com.google.devtools.ksp", version.ref = "ksp" } \ No newline at end of file diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..9bbc975 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..b0da15b --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,8 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-9.0.0-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists + diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..faf9300 --- /dev/null +++ b/gradlew @@ -0,0 +1,251 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# SPDX-License-Identifier: Apache-2.0 +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# within the Gradle project. +# +# You can find Gradle at https://github.com/gradle/gradle/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s\n' "$PWD" ) || exit + +# Use the maximum available, or set MAX_FD != -1 to use that value. +MAX_FD=maximum + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +fi + +# Increase the maximum file descriptors if we can. +if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then + case $MAX_FD in #( + max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + MAX_FD=$( ulimit -H -n ) || + warn "Could not query maximum file descriptor limit" + esac + case $MAX_FD in #( + '' | soft) :;; #( + *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 + ulimit -n "$MAX_FD" || + warn "Could not set maximum file descriptor limit to $MAX_FD" + esac +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. + +set -- \ + "-Dorg.gradle.appname=$APP_BASE_NAME" \ + -classpath "$CLASSPATH" \ + org.gradle.wrapper.GradleWrapperMain \ + "$@" + +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + +# Use "xargs" to parse quoted args. +# +# With -n1 it outputs one arg per line, with the quotes and backslashes removed. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..9b42019 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,94 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem +@rem SPDX-License-Identifier: Apache-2.0 +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +if %ERRORLEVEL% equ 0 goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +set JAVA_EXE=%JAVA_HOME%/bin/java.exe + +if exist "%JAVA_EXE%" goto execute + +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +if %ERRORLEVEL% equ 0 goto mainEnd + +:fail +rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of +rem the _cmd.exe /c_ return code! +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% + +:mainEnd +if "%OS%"=="Windows_NT" endlocal + +:omega diff --git a/keys/.gitignore b/keys/.gitignore new file mode 100644 index 0000000..9648fa6 --- /dev/null +++ b/keys/.gitignore @@ -0,0 +1 @@ +build/*.pem \ No newline at end of file diff --git a/keys/README.md b/keys/README.md new file mode 100644 index 0000000..3904151 --- /dev/null +++ b/keys/README.md @@ -0,0 +1,28 @@ +# Keys (OpenMMO) + +## ToC +- [Description](#description) +- [How to Use](#how-to-use) +- [How It Works](#how-it-works) + +## Description +The keys module is responsible for generating the keys used by the servers for signing packets and by the client for verifying them. +It generates the public keys that are later used by the patcher module to replace the client's public keys. + +> Generated keys are specifically excluded from git commits using `.gitignore` and should not be committed. + +## How to Use +Normally, you don't need to worry about this module, as it is automatically called by all depending modules. +However, if you want to generate the keys manually, you can do so by running the `generateKeys` task in Gradle. +This will generate the keys and place them in the `build/` directory of the module. + +Currently, there are only two key pairs generated: +- `game`: The key pair used for signing game packets by the login and game servers. +- `chat`: The key pair used for signing chat packets by the chat server. + +## How It Works +The build script used [cryptography-kotlin](https://github.com/whyoleg/cryptography-kotlin) to generate the keypairs. +`cryptography-kotlin` is a Kotlin wrapper around libraries like OpenSSL and just provides us a simple API to generate the keys. + +### Key Generation +Keys are generated using the `ECDSA` algorithm with the `secp256r1` curve. Generated keys are saved in PEM format. diff --git a/keys/build.gradle.kts b/keys/build.gradle.kts new file mode 100644 index 0000000..058b6c4 --- /dev/null +++ b/keys/build.gradle.kts @@ -0,0 +1,90 @@ +import org.bouncycastle.util.io.pem.PemObject +import org.bouncycastle.util.io.pem.PemWriter +import java.security.KeyPairGenerator +import java.security.spec.ECGenParameterSpec +import java.io.StringWriter + +buildscript { + repositories { + mavenCentral() + } + + dependencies { + classpath(libs.bundles.crypto) + } +} + +plugins { + id("buildsrc.convention.spotless") +} + +/** + * Abstract task for generating a certificate. + */ +abstract class GenerateCertificateTask : DefaultTask() { + + @get:OutputFile + val privateKeyOutput: RegularFileProperty = project.objects.fileProperty() + + @get:OutputFile + val publicKeyOutput: RegularFileProperty = project.objects.fileProperty() + + @get:Input + val overwriteCertificates: Property = project.objects.property(Boolean::class.java) + .convention(false) + + init { + group = "openmmo" + outputs.upToDateWhen { !overwriteCertificates.get() } + } + + @TaskAction + open fun generate() { + val publicKeyFile = publicKeyOutput.get().asFile + val privateKeyFile = privateKeyOutput.get().asFile + if (!overwriteCertificates.get() && (publicKeyFile.exists() || privateKeyFile.exists())) { + logger.warn("Keys already exist. Use 'overwriteCertificates' to overwrite them.") + return + } + + // Generate ECDSA key pair using secp256r1 curve + val keyPairGenerator = KeyPairGenerator.getInstance("EC") + keyPairGenerator.initialize(ECGenParameterSpec("secp256r1")) + val keyPair = keyPairGenerator.generateKeyPair() + + // Write private key as PEM + val privateKeyPem = StringWriter().use { writer -> + PemWriter(writer).use { pemWriter -> + pemWriter.writeObject(PemObject("EC PRIVATE KEY", keyPair.private.encoded)) + } + writer.toString() + } + privateKeyFile.writeText(privateKeyPem) + + // Write public key as PEM + val publicKeyPem = StringWriter().use { writer -> + PemWriter(writer).use { pemWriter -> + pemWriter.writeObject(PemObject("PUBLIC KEY", keyPair.public.encoded)) + } + writer.toString() + } + publicKeyFile.writeText(publicKeyPem) + } +} + +tasks.register("generateGame") { + description = "Generates a key pair for the login and game servers." + privateKeyOutput.set(layout.buildDirectory.file("game.private.pem")) + publicKeyOutput.set(layout.buildDirectory.file("game.public.pem")) +} + +tasks.register("generateChat") { + description = "Generates a key pair for the chat server." + privateKeyOutput.set(layout.buildDirectory.file("chat.private.pem")) + publicKeyOutput.set(layout.buildDirectory.file("chat.public.pem")) +} + +tasks.register("generate") { + group = "openmmo" + dependsOn("generateGame", "generateChat") +} \ No newline at end of file diff --git a/patcher/README.md b/patcher/README.md new file mode 100644 index 0000000..1bbd9d4 --- /dev/null +++ b/patcher/README.md @@ -0,0 +1,3 @@ +Removed on request of pokemmo.eu. +Date: 2026-08-17 +Nonce: 02298e034dbe43c8806519586565af31 diff --git a/patcher/build.gradle.kts b/patcher/build.gradle.kts new file mode 100644 index 0000000..898b7e2 --- /dev/null +++ b/patcher/build.gradle.kts @@ -0,0 +1,3 @@ +Removed on request of pokemmo.eu. +Date: 2026-08-17 +Nonce: 666b997e54fb4de89c7bf8c413e73791 diff --git a/patcher/src/main/kotlin/de/fiereu/openmmo/patcher/Agent.kt b/patcher/src/main/kotlin/de/fiereu/openmmo/patcher/Agent.kt new file mode 100644 index 0000000..331b8e5 --- /dev/null +++ b/patcher/src/main/kotlin/de/fiereu/openmmo/patcher/Agent.kt @@ -0,0 +1,3 @@ +Removed on request of pokemmo.eu. +Date: 2026-08-17 +Nonce: 0485ce0df8a74237b94853f3ed55fd38 diff --git a/patcher/src/main/kotlin/de/fiereu/openmmo/patcher/PatchingClassFileTransformer.kt b/patcher/src/main/kotlin/de/fiereu/openmmo/patcher/PatchingClassFileTransformer.kt new file mode 100644 index 0000000..bbe727c --- /dev/null +++ b/patcher/src/main/kotlin/de/fiereu/openmmo/patcher/PatchingClassFileTransformer.kt @@ -0,0 +1,3 @@ +Removed on request of pokemmo.eu. +Date: 2026-08-17 +Nonce: 746fedca4ccc49109f8f64ba0b924c6e diff --git a/patcher/src/main/kotlin/de/fiereu/openmmo/patcher/StringPatcher.kt b/patcher/src/main/kotlin/de/fiereu/openmmo/patcher/StringPatcher.kt new file mode 100644 index 0000000..3d588f5 --- /dev/null +++ b/patcher/src/main/kotlin/de/fiereu/openmmo/patcher/StringPatcher.kt @@ -0,0 +1,3 @@ +Removed on request of pokemmo.eu. +Date: 2026-08-17 +Nonce: 60353ee805a94b4190c1042e7f9288fe diff --git a/patcher/src/main/resources/.gitignore b/patcher/src/main/resources/.gitignore new file mode 100644 index 0000000..ba6bec1 --- /dev/null +++ b/patcher/src/main/resources/.gitignore @@ -0,0 +1,3 @@ +Removed on request of pokemmo.eu. +Date: 2026-08-17 +Nonce: 41c150695ef247af96e948424c0c699b diff --git a/protocol.login/README.md b/protocol.login/README.md new file mode 100644 index 0000000..5b54bcd --- /dev/null +++ b/protocol.login/README.md @@ -0,0 +1,3 @@ +# Protocol.Login Module + +The protocol.login module implements login-specific protocol packets and serialization for OpenMMO authentication. \ No newline at end of file diff --git a/protocol.login/build.gradle.kts b/protocol.login/build.gradle.kts new file mode 100644 index 0000000..025b0dd --- /dev/null +++ b/protocol.login/build.gradle.kts @@ -0,0 +1,11 @@ +plugins { + id("buildsrc.convention.kotlin-jvm") + id("buildsrc.convention.spotless") +} + +dependencies { + api(project(":protocol")) + api(project(":common")) + + testImplementation(libs.bundles.kotest) +} diff --git a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/LoginProtocol.kt b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/LoginProtocol.kt new file mode 100644 index 0000000..997d0b9 --- /dev/null +++ b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/LoginProtocol.kt @@ -0,0 +1,30 @@ +package de.fiereu.openmmo.protocols.tls + +import de.fiereu.openmmo.protocols.Protocol +import de.fiereu.openmmo.protocols.incomingPacket +import de.fiereu.openmmo.protocols.outgoingPacket +import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacket +import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacketDeserializer +import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacketSerializer + +/** + * Login Protocol implementation. + * This protocol handles the login process after the TLS handshake is complete. + */ +abstract class LoginProtocol() : Protocol() { + override val async: Boolean + get() = true +} + +class LoginServerProtocol() : LoginProtocol() { + init { + incomingPacket(0x11u, LoginRequestPacketDeserializer()) + } +} + +class LoginClientProtocol() : LoginProtocol() { + init { + outgoingPacket(0x11u, LoginRequestPacket::class, LoginRequestPacketSerializer()) + } +} + diff --git a/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/LoginRequestPacket.kt b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/LoginRequestPacket.kt new file mode 100644 index 0000000..e773446 --- /dev/null +++ b/protocol.login/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/LoginRequestPacket.kt @@ -0,0 +1,105 @@ +package de.fiereu.openmmo.protocols.tls.packets + +import de.fiereu.openmmo.common.enums.Language +import de.fiereu.openmmo.protocols.PacketDeserializer +import de.fiereu.openmmo.protocols.PacketSerializer +import de.fiereu.openmmo.protocols.readUtf16LE +import de.fiereu.openmmo.protocols.writeUtf16LE + +interface LoginMethod + +data class PasswordLogin(val password: String, val stayLoggedIn: Boolean) : LoginMethod +data class TokenLogin(val token: ByteArray) : LoginMethod + +data class LoginRequestPacket( + val username: String, + val manualLogin: Boolean, + val hwid: ByteArray, + val method: LoginMethod, + val language: Language, + val clientRevision: Int, + val installationRevision: Int, + val os: UByte, + val hardwareInfoCache: ByteArray +) + +class LoginRequestPacketSerializer : PacketSerializer { + override fun serialize(packet: LoginRequestPacket, buffer: io.netty.buffer.ByteBuf) { + buffer.writeUtf16LE(packet.username) + buffer.writeBoolean(packet.manualLogin) + buffer.writeByte(packet.hwid.size) + buffer.writeBytes(packet.hwid) + + when (packet.method) { + is PasswordLogin -> { + buffer.writeByte(0) // Method type: Password + buffer.writeUtf16LE(packet.method.password) + buffer.writeBoolean(packet.method.stayLoggedIn) + } + is TokenLogin -> { + buffer.writeByte(1) // Method type: Token + buffer.writeByte(packet.method.token.size) + buffer.writeBytes(packet.method.token) + } + } + + buffer.writeUtf16LE(packet.language.code) + buffer.writeIntLE(packet.clientRevision) + buffer.writeIntLE(packet.installationRevision) + buffer.writeByte(packet.os.toInt()) + buffer.writeByte(packet.hardwareInfoCache.size) + buffer.writeBytes(packet.hardwareInfoCache) + } +} + +class LoginRequestPacketDeserializer : PacketDeserializer { + override fun deserialize(buffer: io.netty.buffer.ByteBuf): LoginRequestPacket { + val username = buffer.readUtf16LE() + val manualLogin = buffer.readBoolean() + + val hwidSize = buffer.readUnsignedByte().toInt() + val hwid = ByteArray(hwidSize) + buffer.readBytes(hwid) + + val methodType = buffer.readByte().toInt() + val method: LoginMethod = when (methodType) { + 0 -> { // Password + val password = buffer.readUtf16LE() + val stayLoggedIn = buffer.readBoolean() + PasswordLogin(password, stayLoggedIn) + } + + 1 -> { // Token + val tokenSize = buffer.readUnsignedByte().toInt() + val token = ByteArray(tokenSize) + buffer.readBytes(token) + TokenLogin(token) + } + + else -> throw IllegalArgumentException("Unknown login method type: $methodType") + } + + val languageCode = buffer.readUtf16LE() + val language = Language.fromCode(languageCode) + + val clientRevision = buffer.readIntLE() + val installationRevision = buffer.readIntLE() + val os = buffer.readUnsignedByte().toUByte() + + val hardwareInfoCacheSize = buffer.readUnsignedByte().toInt() + val hardwareInfoCache = ByteArray(hardwareInfoCacheSize) + buffer.readBytes(hardwareInfoCache) + + return LoginRequestPacket( + username, + manualLogin, + hwid, + method, + language, + clientRevision, + installationRevision, + os, + hardwareInfoCache + ) + } +} \ No newline at end of file diff --git a/protocol.tls/README.md b/protocol.tls/README.md new file mode 100644 index 0000000..8b226c3 --- /dev/null +++ b/protocol.tls/README.md @@ -0,0 +1,35 @@ +# Protocol.TLS Module + +The protocol.tls module implements a custom TLS-like protocol for secure client-server communication in OpenMMO. + +## Contents + +### Core Classes +- **TlsProtocol**: Abstract base protocol for TLS handshake implementation +- **TlsServerProtocol**: Server-side TLS protocol implementation +- **TlsClientProtocol**: Client-side TLS protocol implementation + +### Packet Types +- **ClientHelloPacket**: Initial handshake packet sent by client +- **ServerHelloPacket**: Server response containing server's public key +- **ClientReadyPacket**: Client confirmation with client's public key + +### Cryptographic Features +- **ECKeyExtensions**: Extensions for elliptic curve key operations +- ECDH key exchange for shared secret derivation +- Secure communication setup using ECDSA key pairs + +## Protocol Flow +1. Client sends `ClientHello` to initiate handshake +2. Server responds with `ServerHello` containing its public key +3. Client derives shared secret using ECDH and switches to secure mode +4. Client sends `ClientReady` with its public key +5. Server derives shared secret and switches to next protocol (e.g., LoginProtocol) + +## Dependencies +- Protocol module for base framework +- BouncyCastle crypto libraries for cryptographic operations +- Kotest for testing + +## Security +This module implements a custom TLS-like protocol specifically designed for PokeMMO server compatibility, using ECDSA with secp256r1 curve for key exchange and authentication. \ No newline at end of file diff --git a/protocol.tls/build.gradle.kts b/protocol.tls/build.gradle.kts new file mode 100644 index 0000000..a4e697c --- /dev/null +++ b/protocol.tls/build.gradle.kts @@ -0,0 +1,11 @@ +plugins { + id("buildsrc.convention.kotlin-jvm") + id("buildsrc.convention.spotless") +} + +dependencies { + api(project(":protocol")) + api(libs.bundles.crypto) + + testImplementation(libs.bundles.kotest) +} diff --git a/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/TlsProtocol.kt b/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/TlsProtocol.kt new file mode 100644 index 0000000..776cc54 --- /dev/null +++ b/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/TlsProtocol.kt @@ -0,0 +1,46 @@ +package de.fiereu.openmmo.protocols.tls + +import de.fiereu.openmmo.protocols.Protocol +import de.fiereu.openmmo.protocols.incomingPacket +import de.fiereu.openmmo.protocols.outgoingPacket +import de.fiereu.openmmo.protocols.tls.packets.* +import java.security.interfaces.ECPrivateKey +import java.security.interfaces.ECPublicKey + +/** + * TLS Protocol implementation. + * This protocol handles the initial TLS handshake before any secure communication can take place. + * + * The flow is as follows: + * 1. Client sends a ClientHello packet to initiate the handshake. + * 2. Server responds with a ServerHello packet. + * -> The client knows the servers public key and its own private key. And it can derive a shared secret using ECDH. + * -> Every packet the client now would receive is expected to be secured. + * -> Client switches to next protocol (e.g. LoginProtocol) after the handshake is complete. + * 3. Client sends a ClientReady packet with its public key. + * -> The server can now secure its communication with the client using the shared secret. + * -> Server switches to next protocol (e.g. LoginProtocol) after the handshake is complete. + */ +abstract class TlsProtocol() : Protocol() { + override val async: Boolean + get() = false +} + +class TlsServerProtocol( + serverKeyPair: Pair +) : TlsProtocol() { + init { + incomingPacket(0x00u, ClientHelloPacketDeserializer()) + outgoingPacket(0x01u, ServerHelloPacket::class, ServerHelloPacketSerializer(serverKeyPair.first)) + incomingPacket(0x02u, ClientReadyPacketDeserializer()) + } +} + +class TlsClientProtocol() : TlsProtocol() { + init { + outgoingPacket(0x00u, ClientHelloPacket::class, ClientHelloPacketSerializer()) + incomingPacket(0x01u, ServerHelloPacketDeserializer()) + outgoingPacket(0x02u, ClientReadyPacket::class, ClientReadyPacketSerializer()) + } +} + diff --git a/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ClientHelloPacket.kt b/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ClientHelloPacket.kt new file mode 100644 index 0000000..0bdfc04 --- /dev/null +++ b/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ClientHelloPacket.kt @@ -0,0 +1,37 @@ +package de.fiereu.openmmo.protocols.tls.packets + +import de.fiereu.openmmo.protocols.PacketDeserializer +import de.fiereu.openmmo.protocols.PacketSerializer +import io.netty.buffer.ByteBuf +import kotlin.random.Random + +private const val key1 = 3214621489648854472L +private const val key2 = -4214651440992349575L + +data class ClientHelloPacket(val timestamp: Long) + +class ClientHelloPacketSerializer : PacketSerializer { + + override fun serialize(packet: ClientHelloPacket, buffer: ByteBuf) { + val randomKey = Random.nextLong() + + val xoredRandomKey = randomKey xor key1 + val xoredTimestamp = packet.timestamp xor key2 xor randomKey + + buffer.writeLongLE(xoredRandomKey) + buffer.writeLongLE(xoredTimestamp) + } +} + +class ClientHelloPacketDeserializer : PacketDeserializer { + + override fun deserialize(buffer: ByteBuf): ClientHelloPacket { + val xoredRandomKey = buffer.readLongLE() + val xoredTimestamp = buffer.readLongLE() + + val randomKey = xoredRandomKey xor key1 + val timestamp = xoredTimestamp xor key2 xor randomKey + + return ClientHelloPacket(timestamp) + } +} diff --git a/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ClientReadyPacket.kt b/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ClientReadyPacket.kt new file mode 100644 index 0000000..c504f57 --- /dev/null +++ b/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ClientReadyPacket.kt @@ -0,0 +1,34 @@ +package de.fiereu.openmmo.protocols.tls.packets + +import de.fiereu.openmmo.protocols.PacketDeserializer +import de.fiereu.openmmo.protocols.PacketSerializer +import de.fiereu.openmmo.protocols.tls.util.toECPublicKey +import de.fiereu.openmmo.protocols.tls.util.toUncompressedPoint +import io.netty.buffer.ByteBuf +import java.security.interfaces.ECPublicKey + +data class ClientReadyPacket( + val clientPublicKey: ECPublicKey +) + +class ClientReadyPacketSerializer : PacketSerializer { + + override fun serialize(packet: ClientReadyPacket, buffer: ByteBuf) { + val publicKeyBytes = packet.clientPublicKey.toUncompressedPoint() + + buffer.writeShortLE(publicKeyBytes.size) + buffer.writeBytes(publicKeyBytes) + } +} + +class ClientReadyPacketDeserializer : PacketDeserializer { + + override fun deserialize(buffer: ByteBuf): ClientReadyPacket { + val keyBytes = ByteArray(buffer.readShortLE().toInt()) + buffer.readBytes(keyBytes) + + val publicKey = keyBytes.toECPublicKey() + + return ClientReadyPacket(publicKey) + } +} diff --git a/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ServerHelloPacket.kt b/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ServerHelloPacket.kt new file mode 100644 index 0000000..f1dc8d6 --- /dev/null +++ b/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/packets/ServerHelloPacket.kt @@ -0,0 +1,65 @@ +package de.fiereu.openmmo.protocols.tls.packets + +import de.fiereu.openmmo.protocols.PacketDeserializer +import de.fiereu.openmmo.protocols.PacketSerializer +import de.fiereu.openmmo.protocols.tls.util.sign +import de.fiereu.openmmo.protocols.tls.util.toECPublicKey +import de.fiereu.openmmo.protocols.tls.util.toUncompressedPoint +import io.netty.buffer.ByteBuf +import java.security.PublicKey +import java.security.interfaces.ECPrivateKey +import java.security.interfaces.ECPublicKey + +/** + * Represents a server hello packet in the TLS handshake. + * + * @property publicKey The public key generated for this connection. + * @property checksumSize The size of the checksum used for this connection. + */ +data class ServerHelloPacket( + val publicKey: ECPublicKey, + val checksumSize: Int +) + +class ServerHelloPacketSerializer( + private val serverRootPrivateKey: ECPrivateKey +) : PacketSerializer { + + override fun serialize(packet: ServerHelloPacket, buffer: ByteBuf) { + val publicKeyBytes = packet.publicKey.toUncompressedPoint() + val signature = serverRootPrivateKey.sign(publicKeyBytes) + + buffer.writeShortLE(publicKeyBytes.size) + buffer.writeBytes(publicKeyBytes) + + buffer.writeShortLE(signature.size) + buffer.writeBytes(signature) + + buffer.writeByte(packet.checksumSize) + } +} + +class ServerHelloPacketDeserializer : PacketDeserializer { + + data class ServerHelloPacket( + val clientPublicKey: PublicKey, + val signature: ByteArray, + val checksumSize: Int + ) + + override fun deserialize(buffer: ByteBuf): ServerHelloPacket { + val publicKeySize = buffer.readShortLE().toInt() + val publicKeyBytes = ByteArray(publicKeySize) + buffer.readBytes(publicKeyBytes) + + val clientPublicKey = publicKeyBytes.toECPublicKey() + + val signatureSize = buffer.readShortLE().toInt() + val signature = ByteArray(signatureSize) + buffer.readBytes(signature) + + val checksumSize = buffer.readByte().toInt() + + return ServerHelloPacket(clientPublicKey, signature, checksumSize) + } +} diff --git a/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/util/ECKeyExtensions.kt b/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/util/ECKeyExtensions.kt new file mode 100644 index 0000000..4e045c1 --- /dev/null +++ b/protocol.tls/src/main/kotlin/de/fiereu/openmmo/protocols/tls/util/ECKeyExtensions.kt @@ -0,0 +1,96 @@ +package de.fiereu.openmmo.protocols.tls.util + +import java.math.BigInteger +import java.security.AlgorithmParameters +import java.security.KeyFactory +import java.security.Security +import java.security.interfaces.ECPublicKey +import java.security.spec.ECGenParameterSpec +import java.security.spec.ECParameterSpec +import java.security.spec.ECPoint +import java.security.spec.ECPublicKeySpec +import java.security.Signature +import java.security.interfaces.ECPrivateKey + +private const val uncompressedPointIndicator: Byte = 0x04 + +private val keyFactory: KeyFactory = KeyFactory.getInstance("EC") + +private val ecParameterSpec: ECParameterSpec by lazy { + val algorithmParameters = AlgorithmParameters.getInstance("EC") + algorithmParameters.init(ECGenParameterSpec("secp256r1")) + algorithmParameters.getParameterSpec(ECParameterSpec::class.java) +} + +fun ECPublicKey.toUncompressedPoint(): ByteArray { + val key = this + val point = key.w + val keyLength = (ecParameterSpec.order.bitLength() + Byte.SIZE_BITS - 1) / Byte.SIZE_BITS + + var offset = 0 + val data = ByteArray(1 + 2 * keyLength) + data[offset++] = uncompressedPointIndicator + + val x = point.affineX.toByteArray() + val y = point.affineY.toByteArray() + + when { + x.size <= keyLength -> { + System.arraycopy(x, 0, data, offset + keyLength - x.size, x.size) + } + x.size == keyLength + 1 && x[0] == 0.toByte() -> { + System.arraycopy(x, 1, data, offset, keyLength) + } + else -> { + throw IllegalStateException("x value is too large") + } + } + + offset += keyLength + when { + y.size <= keyLength -> { + System.arraycopy(y, 0, data, offset + keyLength - y.size, y.size) + } + y.size == keyLength + 1 && y[0] == 0.toByte() -> { + System.arraycopy(y, 1, data, offset, keyLength) + } + else -> { + throw IllegalStateException("y value is too large") + } + } + + return data +} + +fun ByteArray.toECPublicKey(): ECPublicKey { + if (this[0] != uncompressedPointIndicator) { + throw IllegalArgumentException("Invalid uncompressed point indicator") + } + + val keyLength = (ecParameterSpec.order.bitLength() + Byte.SIZE_BITS - 1) / Byte.SIZE_BITS + if (this.size != 1 + 2 * keyLength) { + throw IllegalArgumentException("Invalid data length") + } + + var offset = 1 + val x = BigInteger(1, this.copyOfRange(offset, offset + keyLength)) + offset += keyLength + val y = BigInteger(1, this.copyOfRange(offset, offset + keyLength)) + val point = ECPoint(x, y) + + return keyFactory.generatePublic(ECPublicKeySpec(point, ecParameterSpec)) as ECPublicKey +} + +fun ECPrivateKey.sign(data: ByteArray): ByteArray { + val signature = Signature.getInstance("SHA256withECDSA") + signature.initSign(this) + signature.update(data) + return signature.sign() +} + +fun ECPublicKey.verify(data: ByteArray, signatureBytes: ByteArray): Boolean { + val signature = Signature.getInstance("SHA256withECDSA") + signature.initVerify(this) + signature.update(data) + return signature.verify(signatureBytes) +} \ No newline at end of file diff --git a/protocol/README.md b/protocol/README.md new file mode 100644 index 0000000..faf476e --- /dev/null +++ b/protocol/README.md @@ -0,0 +1,3 @@ +# Protocol Module + +The protocol module provides the core packet protocol framework for OpenMMO, including serialization and deserialization capabilities. \ No newline at end of file diff --git a/protocol/build.gradle.kts b/protocol/build.gradle.kts new file mode 100644 index 0000000..dcf1570 --- /dev/null +++ b/protocol/build.gradle.kts @@ -0,0 +1,14 @@ +plugins { + id("buildsrc.convention.kotlin-jvm") + id("buildsrc.convention.spotless") +} + +dependencies { + api(libs.kotlinx.serialization.core) + api(libs.netty) + + implementation(libs.slf4j) + implementation(libs.kotlin.logging) + + testImplementation(libs.bundles.kotest) +} diff --git a/protocol/src/main/kotlin/de/fiereu/openmmo/protocols/ByteBufExtension.kt b/protocol/src/main/kotlin/de/fiereu/openmmo/protocols/ByteBufExtension.kt new file mode 100644 index 0000000..d3acd1a --- /dev/null +++ b/protocol/src/main/kotlin/de/fiereu/openmmo/protocols/ByteBufExtension.kt @@ -0,0 +1,28 @@ +package de.fiereu.openmmo.protocols + +import io.netty.buffer.ByteBuf + +fun ByteBuf.readCharLE(): Char { + return ((readUnsignedByte().toInt() or (readUnsignedByte().toInt() shl 8)) and 0xFFFF).toChar() +} + +fun ByteBuf.writeCharLE(value: Char) { + writeByte(value.code and 0xFF) + writeByte((value.code shr 8) and 0xFF) +} + +fun ByteBuf.readUtf16LE(): String { + val builder = StringBuilder() + var c: Char + while ((readCharLE().also { c = it }).code != 0) { + builder.append(c) + } + return builder.toString() +} + +fun ByteBuf.writeUtf16LE(value: String) { + for (c in value) { + writeCharLE(c) + } + writeCharLE(0.toChar()) // Null-terminator +} \ No newline at end of file diff --git a/protocol/src/main/kotlin/de/fiereu/openmmo/protocols/Protocol.kt b/protocol/src/main/kotlin/de/fiereu/openmmo/protocols/Protocol.kt new file mode 100644 index 0000000..70eb031 --- /dev/null +++ b/protocol/src/main/kotlin/de/fiereu/openmmo/protocols/Protocol.kt @@ -0,0 +1,106 @@ +package de.fiereu.openmmo.protocols + +import io.github.oshai.kotlinlogging.KotlinLogging +import io.netty.buffer.ByteBuf +import kotlin.reflect.KClass + +/** + * Value class wrapping a UByte to represent an opcode. + */ +@JvmInline +value class Opcode(val value: UByte) { + override fun toString(): String = "0x${value.toString(16).padStart(2, '0').uppercase()}" +} + +/** + * Packet direction enum representing the direction of packet flow. + * This is needed because depending on the current side (client or server), + * the same opcode can represent different packets. + * For example, opcode 0x01 might represent a "LoginRequest" packet on the client side, + * but a "LoginResponse" packet on the server side. + */ +enum class PacketDirection { + CLIENT_TO_SERVER, + SERVER_TO_CLIENT +} + +interface PacketSerializer { + fun serializeObject(packet: Any, buffer: ByteBuf) { + @Suppress("UNCHECKED_CAST") + serialize(packet as T, buffer) + } + fun serialize(packet: T, buffer: ByteBuf) +} + +interface PacketDeserializer { + fun deserialize(buffer: ByteBuf): T +} + +/** + * The base class for all protocols. + * A protocol is a collection of packets that can be sent and received. + * + * We cant combine Server and Client protocols because they have different dependencies. + * For example, the server protocol needs to know about the server's root private key, + * while the client protocol should not have any knowledge about the server's private key. + */ +abstract class Protocol { + private val log = KotlinLogging.logger {} + private val incomingPacketRegistry: MutableMap> = mutableMapOf() + private val outgoingPacketRegistry: MutableMap> = mutableMapOf() + private val dataClassToOpcode: MutableMap, Opcode> = mutableMapOf() + + abstract val async: Boolean + + fun getOpcode(dataClass: KClass<*>): Opcode? { + return dataClassToOpcode[dataClass] + } + + fun registerIncoming( + opcode: Opcode, + deserializer: PacketDeserializer + ) { + log.debug { "Registering incoming packet: opcode=$opcode, deserializer=${deserializer::class.simpleName}" } + + incomingPacketRegistry.put(opcode, deserializer) + } + + fun registerOutgoing( + opcode: Opcode, + dataClass: KClass, + serializer: PacketSerializer, + ) { + log.debug { "Registering outgoing packet: opcode=$opcode, serializer=${serializer::class.simpleName}" } + + dataClassToOpcode[dataClass] = opcode + outgoingPacketRegistry.put(opcode, serializer) + } + + fun getSerializer(opcode: Opcode): PacketSerializer<*>? { + return outgoingPacketRegistry[opcode] + } + + fun getDeserializer(opcode: Opcode): PacketDeserializer<*>? { + return incomingPacketRegistry[opcode] + } +} + +fun Protocol.getDeserializer(opcode: UByte): PacketDeserializer<*>? { + return this.getDeserializer(Opcode(opcode)) +} + +fun Protocol.incomingPacket( + opcode: UByte, + deserializer: PacketDeserializer +) { + this.registerIncoming(Opcode(opcode), deserializer) +} + +fun Protocol.outgoingPacket( + opcode: UByte, + dataClass: KClass, + serializer: PacketSerializer +) { + this.registerOutgoing(Opcode(opcode), dataClass, serializer) +} + diff --git a/server.login/.gitignore b/server.login/.gitignore new file mode 100644 index 0000000..31fce6d --- /dev/null +++ b/server.login/.gitignore @@ -0,0 +1 @@ +src/main/resources/game.*.pem \ No newline at end of file diff --git a/server.login/README.md b/server.login/README.md new file mode 100644 index 0000000..72c240c --- /dev/null +++ b/server.login/README.md @@ -0,0 +1,56 @@ +# Server.Login Module + +The server.login module implements the login server for OpenMMO with authentication and database integration. + +## Contents + +### Main Application +- **LoginServer**: Main application entry point that configures and starts the login server on port 2106 +- **LoginProtocolHandler**: Protocol handler for processing login-specific packets + +### Configuration +- Server runs on port 2106 +- Uses ECDSA game keys for packet signing/verification +- Configured with TLS checksum size of 16 bytes (partial HMAC-SHA256) + +### Database Integration +- **PostgreSQL**: Primary database for user authentication +- **Flyway**: Database migration management +- **jOOQ**: Type-safe database queries with code generation + +### Key Features +- User authentication & management +- Integration with protocol.login for packet handling +- TLS-secured communication +- Docker support with dedicated Dockerfile + +### Configuration Files +- **application.conf**: HOCON configuration for server settings +- **logback.xml**: Logging configuration +- **db.migrations**: SQL scripts for schema management + +### Docker Support +The module includes a Dockerfile for containerized deployment: +- Multi-stage build using Zulu OpenJDK 24 +- Exposes port 2106 +- Includes all necessary dependencies and keys + +## Dependencies +- Server module for core framework +- Protocol.login module for authentication packets +- PostgreSQL driver for database connectivity +- jOOQ for database operations +- Flyway for schema management +- Logback for logging +- Kotlinx.coroutines for async processing + +## Environment Variables +The application requires database configuration through environment variables: +- Database connection settings (host, port, name, user, password) +- Configured via gradle.properties or environment + +## Development +- Run with: `./gradlew :server.login:run` +- Database setup: `./gradlew cleanMigrateAndGenerate` +- Code generation: `./gradlew jooqCodegen` +- Docker build: `docker build -t openmmo-login server.login/` \ No newline at end of file diff --git a/server.login/build.gradle.kts b/server.login/build.gradle.kts new file mode 100644 index 0000000..df03726 --- /dev/null +++ b/server.login/build.gradle.kts @@ -0,0 +1,128 @@ +import org.flywaydb.gradle.task.AbstractFlywayTask + +buildscript { + dependencies { + classpath(libs.flyway.postgresql) + } +} + +plugins { + application + distribution + id("buildsrc.convention.kotlin-jvm") + id("buildsrc.convention.spotless") + id("buildsrc.common.keys") + alias(libs.plugins.kotlin.serialization) + alias(libs.plugins.jooq) + alias(libs.plugins.flyway) +} + +group = "de.fiereu.openmmo" +version = "0.1.0" + +dependencies { + implementation(project(":server")) + implementation(project(":protocol.login")) + implementation(libs.logback) + implementation(libs.kotlinx.coroutines) + + runtimeOnly(libs.postgresql) + + implementation(libs.bundles.jooq) + jooqCodegen(libs.postgresql) + + implementation(libs.flyway.core) + implementation(libs.flyway.postgresql) + + testImplementation(libs.bundles.kotest) + testImplementation(libs.kotlinx.coroutines.test) + testImplementation(libs.mockk) +} + +application { + mainClass.set("de.fiereu.openmmo.server.login.LoginServerKt") +} + +tasks.classes.get().apply { + dependsOn("copyKeysGame") + tasks.processResources.get().mustRunAfter("copyKeysGame") +} + +fun env(key: String): Any { + val value = property(key) ?: + System.getenv(key) ?: + throw IllegalArgumentException("Environment variable or system property '$key' is not set.") + fun interpolate(value: String): Any { + val PATTERN_WORD = Regex("\\$([a-zA-Z0-9_]+)") + val PATTERN_MULTI = Regex("\\$\\{([a-zA-Z0-9_]+)\\}") + return (PATTERN_WORD.findAll(value) + PATTERN_MULTI.findAll(value)) + .distinct() + .fold(value) { acc, match -> + val envName = match.groupValues[1] + val envValue = System.getProperty(envName) ?: System.getProperty(envName) + if (envValue == null) { + throw IllegalArgumentException("Environment variable or system property '$envName' is not set.") + } + acc.replace(match.value, envValue) + } + } + return if (value is String && (value.contains('$') || value.contains('{'))) { + interpolate(value) + } else value +} + +val dbPort = env("openmmo.db.login.port") as String +val dbName = env("openmmo.db.login.name") as String +val dbUser = env("openmmo.db.login.user") as String +val dbPassword = env("openmmo.db.login.password") as String + +jooq { + configuration { + jdbc { + driver = "org.postgresql.Driver" + url = "jdbc:postgresql://localhost:$dbPort/$dbName" + user = dbUser + password = dbPassword + } + generator { + database { + name = "org.jooq.meta.postgres.PostgresDatabase" + includes = ".*" + excludes = """ + flyway_schema_history | + pgp_armor_headers + """ + inputSchema = "public" + } + + generate { + name = "org.jooq.codegen.KotlinGenerator" + } + target { + packageName = "de.fiereu.openmmo.server.login.jooq" + directory = "src/main/jooq" + } + } + } +} + +flyway { + driver = "org.postgresql.Driver" + url = "jdbc:postgresql://localhost:$dbPort/$dbName" + user = dbUser + password = dbPassword + schemas = arrayOf("public") + locations = arrayOf("filesystem:src/main/resources/db/migration") + cleanDisabled = false +} + +// Fuck this shit uhh we are not gonna update our gradle plugin bc all our enterprise customers are stuck on Java 1.6 and gradle 5 anyway +tasks.withType().configureEach { + notCompatibleWithConfigurationCache("https://github.com/flyway/flyway/issues/3550") +} + +tasks.register("cleanMigrateAndGenerate") { + group = "openmmo" + description = "Cleans the database, migrates it and generates the jOOQ classes." + dependsOn("flywayClean", "flywayMigrate", "jooqCodegen") +} \ No newline at end of file diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/DefaultCatalog.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/DefaultCatalog.kt new file mode 100644 index 0000000..c278926 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/DefaultCatalog.kt @@ -0,0 +1,43 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq + + +import kotlin.collections.List + +import org.jooq.Constants +import org.jooq.Schema +import org.jooq.impl.CatalogImpl + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class DefaultCatalog : CatalogImpl("") { + companion object { + + /** + * The reference instance of DEFAULT_CATALOG + */ + val DEFAULT_CATALOG: DefaultCatalog = DefaultCatalog() + } + + /** + * standard public schema + */ + val PUBLIC: Public get(): Public = Public.PUBLIC + + override fun getSchemas(): List = listOf( + Public.PUBLIC + ) + + /** + * A reference to the 3.20 minor release of the code generator. If this + * doesn't compile, it's because the runtime library uses an older minor + * release, namely: 3.20. You can turn off the generation of this reference + * by specifying /configuration/generator/generate/jooqVersionReference + */ + private val REQUIRE_RUNTIME_JOOQ_VERSION = Constants.VERSION_3_20 +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/Public.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/Public.kt new file mode 100644 index 0000000..fd1dc83 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/Public.kt @@ -0,0 +1,40 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq + + +import de.fiereu.openmmo.server.login.jooq.tables.User + +import kotlin.collections.List + +import org.jooq.Catalog +import org.jooq.Table +import org.jooq.impl.DSL +import org.jooq.impl.SchemaImpl + + +/** + * standard public schema + */ +@Suppress("warnings") +open class Public : SchemaImpl(DSL.name("public"), DefaultCatalog.DEFAULT_CATALOG, DSL.comment("standard public schema")) { + companion object { + + /** + * The reference instance of public + */ + val PUBLIC: Public = Public() + } + + /** + * The table public.user. + */ + val USER: User get() = User.USER + + override fun getCatalog(): Catalog = DefaultCatalog.DEFAULT_CATALOG + + override fun getTables(): List> = listOf( + User.USER + ) +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/keys/Keys.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/keys/Keys.kt new file mode 100644 index 0000000..525a3c2 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/keys/Keys.kt @@ -0,0 +1,22 @@ +@file:Suppress("warnings") +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.keys + + +import de.fiereu.openmmo.server.login.jooq.tables.User +import de.fiereu.openmmo.server.login.jooq.tables.records.UserRecord + +import org.jooq.UniqueKey +import org.jooq.impl.DSL +import org.jooq.impl.Internal + + + +// ------------------------------------------------------------------------- +// UNIQUE and PRIMARY KEY definitions +// ------------------------------------------------------------------------- + +val USER_PKEY: UniqueKey = Internal.createUniqueKey(User.USER, DSL.name("user_pkey"), arrayOf(User.USER.ID), true) +val USER_USERNAME_KEY: UniqueKey = Internal.createUniqueKey(User.USER, DSL.name("user_username_key"), arrayOf(User.USER.USERNAME), true) diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Armor1.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Armor1.kt new file mode 100644 index 0000000..de877ab --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Armor1.kt @@ -0,0 +1,53 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class Armor1 : AbstractRoutine("armor", Public.PUBLIC, DSL.comment(""), SQLDataType.CLOB) { + companion object { + + /** + * The parameter public.armor.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.CLOB, false, false) + + /** + * The parameter public.armor._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + } + + init { + returnParameter = Armor1.RETURN_VALUE + addInParameter(Armor1._1) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(Armor1._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(Armor1._1, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Armor2.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Armor2.kt new file mode 100644 index 0000000..24ff94b --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Armor2.kt @@ -0,0 +1,91 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class Armor2 : AbstractRoutine("armor", Public.PUBLIC, DSL.comment(""), SQLDataType.CLOB) { + companion object { + + /** + * The parameter public.armor.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.CLOB, false, false) + + /** + * The parameter public.armor._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.armor._2. + */ + val _2: Parameter?> = Internal.createParameter("_2", SQLDataType.CLOB.array(), false, true) + + /** + * The parameter public.armor._3. + */ + val _3: Parameter?> = Internal.createParameter("_3", SQLDataType.CLOB.array(), false, true) + } + + init { + returnParameter = Armor2.RETURN_VALUE + addInParameter(Armor2._1) + addInParameter(Armor2._2) + addInParameter(Armor2._3) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(Armor2._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(Armor2._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: Array?): Unit = setValue(Armor2._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field?>): Unit { + setField(Armor2._2, field) + } + + /** + * Set the _3 parameter IN value to the routine + */ + fun set__3(value: Array?): Unit = setValue(Armor2._3, value) + + /** + * Set the _3 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__3(field: Field?>): Unit { + setField(Armor2._3, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Crypt.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Crypt.kt new file mode 100644 index 0000000..1e91680 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Crypt.kt @@ -0,0 +1,71 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class Crypt : AbstractRoutine("crypt", Public.PUBLIC, DSL.comment(""), SQLDataType.CLOB) { + companion object { + + /** + * The parameter public.crypt.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.CLOB, false, false) + + /** + * The parameter public.crypt._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.CLOB, false, true) + + /** + * The parameter public.crypt._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = Crypt.RETURN_VALUE + addInParameter(Crypt._1) + addInParameter(Crypt._2) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: String?): Unit = setValue(Crypt._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(Crypt._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: String?): Unit = setValue(Crypt._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(Crypt._2, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Dearmor.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Dearmor.kt new file mode 100644 index 0000000..55fd4fc --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Dearmor.kt @@ -0,0 +1,52 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class Dearmor : AbstractRoutine("dearmor", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.dearmor.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.dearmor._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = Dearmor.RETURN_VALUE + addInParameter(Dearmor._1) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: String?): Unit = setValue(Dearmor._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(Dearmor._1, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Decrypt.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Decrypt.kt new file mode 100644 index 0000000..380b51a --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Decrypt.kt @@ -0,0 +1,90 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class Decrypt : AbstractRoutine("decrypt", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.decrypt.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.decrypt._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.decrypt._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.BLOB, false, true) + + /** + * The parameter public.decrypt._3. + */ + val _3: Parameter = Internal.createParameter("_3", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = Decrypt.RETURN_VALUE + addInParameter(Decrypt._1) + addInParameter(Decrypt._2) + addInParameter(Decrypt._3) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(Decrypt._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(Decrypt._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: ByteArray?): Unit = setValue(Decrypt._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(Decrypt._2, field) + } + + /** + * Set the _3 parameter IN value to the routine + */ + fun set__3(value: String?): Unit = setValue(Decrypt._3, value) + + /** + * Set the _3 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__3(field: Field): Unit { + setField(Decrypt._3, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/DecryptIv.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/DecryptIv.kt new file mode 100644 index 0000000..f884146 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/DecryptIv.kt @@ -0,0 +1,109 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class DecryptIv : AbstractRoutine("decrypt_iv", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.decrypt_iv.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.decrypt_iv._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.decrypt_iv._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.BLOB, false, true) + + /** + * The parameter public.decrypt_iv._3. + */ + val _3: Parameter = Internal.createParameter("_3", SQLDataType.BLOB, false, true) + + /** + * The parameter public.decrypt_iv._4. + */ + val _4: Parameter = Internal.createParameter("_4", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = DecryptIv.RETURN_VALUE + addInParameter(DecryptIv._1) + addInParameter(DecryptIv._2) + addInParameter(DecryptIv._3) + addInParameter(DecryptIv._4) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(DecryptIv._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(DecryptIv._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: ByteArray?): Unit = setValue(DecryptIv._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(DecryptIv._2, field) + } + + /** + * Set the _3 parameter IN value to the routine + */ + fun set__3(value: ByteArray?): Unit = setValue(DecryptIv._3, value) + + /** + * Set the _3 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__3(field: Field): Unit { + setField(DecryptIv._3, field) + } + + /** + * Set the _4 parameter IN value to the routine + */ + fun set__4(value: String?): Unit = setValue(DecryptIv._4, value) + + /** + * Set the _4 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__4(field: Field): Unit { + setField(DecryptIv._4, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Digest1.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Digest1.kt new file mode 100644 index 0000000..0230a94 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Digest1.kt @@ -0,0 +1,72 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class Digest1 : AbstractRoutine("digest", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.digest.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.digest._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.CLOB, false, true) + + /** + * The parameter public.digest._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = Digest1.RETURN_VALUE + addInParameter(Digest1._1) + addInParameter(Digest1._2) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: String?): Unit = setValue(Digest1._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(Digest1._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: String?): Unit = setValue(Digest1._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(Digest1._2, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Digest2.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Digest2.kt new file mode 100644 index 0000000..1bb0acd --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Digest2.kt @@ -0,0 +1,72 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class Digest2 : AbstractRoutine("digest", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.digest.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.digest._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.digest._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = Digest2.RETURN_VALUE + addInParameter(Digest2._1) + addInParameter(Digest2._2) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(Digest2._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(Digest2._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: String?): Unit = setValue(Digest2._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(Digest2._2, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Encrypt.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Encrypt.kt new file mode 100644 index 0000000..7e69735 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Encrypt.kt @@ -0,0 +1,90 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class Encrypt : AbstractRoutine("encrypt", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.encrypt.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.encrypt._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.encrypt._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.BLOB, false, true) + + /** + * The parameter public.encrypt._3. + */ + val _3: Parameter = Internal.createParameter("_3", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = Encrypt.RETURN_VALUE + addInParameter(Encrypt._1) + addInParameter(Encrypt._2) + addInParameter(Encrypt._3) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(Encrypt._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(Encrypt._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: ByteArray?): Unit = setValue(Encrypt._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(Encrypt._2, field) + } + + /** + * Set the _3 parameter IN value to the routine + */ + fun set__3(value: String?): Unit = setValue(Encrypt._3, value) + + /** + * Set the _3 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__3(field: Field): Unit { + setField(Encrypt._3, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/EncryptIv.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/EncryptIv.kt new file mode 100644 index 0000000..de16476 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/EncryptIv.kt @@ -0,0 +1,109 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class EncryptIv : AbstractRoutine("encrypt_iv", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.encrypt_iv.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.encrypt_iv._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.encrypt_iv._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.BLOB, false, true) + + /** + * The parameter public.encrypt_iv._3. + */ + val _3: Parameter = Internal.createParameter("_3", SQLDataType.BLOB, false, true) + + /** + * The parameter public.encrypt_iv._4. + */ + val _4: Parameter = Internal.createParameter("_4", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = EncryptIv.RETURN_VALUE + addInParameter(EncryptIv._1) + addInParameter(EncryptIv._2) + addInParameter(EncryptIv._3) + addInParameter(EncryptIv._4) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(EncryptIv._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(EncryptIv._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: ByteArray?): Unit = setValue(EncryptIv._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(EncryptIv._2, field) + } + + /** + * Set the _3 parameter IN value to the routine + */ + fun set__3(value: ByteArray?): Unit = setValue(EncryptIv._3, value) + + /** + * Set the _3 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__3(field: Field): Unit { + setField(EncryptIv._3, field) + } + + /** + * Set the _4 parameter IN value to the routine + */ + fun set__4(value: String?): Unit = setValue(EncryptIv._4, value) + + /** + * Set the _4 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__4(field: Field): Unit { + setField(EncryptIv._4, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/GenRandomBytes.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/GenRandomBytes.kt new file mode 100644 index 0000000..c0292b4 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/GenRandomBytes.kt @@ -0,0 +1,52 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class GenRandomBytes : AbstractRoutine("gen_random_bytes", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.gen_random_bytes.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.gen_random_bytes._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.INTEGER, false, true) + } + + init { + returnParameter = GenRandomBytes.RETURN_VALUE + addInParameter(GenRandomBytes._1) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: Int?): Unit = setValue(GenRandomBytes._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(GenRandomBytes._1, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/GenRandomUuid.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/GenRandomUuid.kt new file mode 100644 index 0000000..93c72bb --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/GenRandomUuid.kt @@ -0,0 +1,34 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import java.util.UUID + +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class GenRandomUuid : AbstractRoutine("gen_random_uuid", Public.PUBLIC, DSL.comment(""), SQLDataType.UUID) { + companion object { + + /** + * The parameter public.gen_random_uuid.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.UUID, false, false) + } + + init { + returnParameter = GenRandomUuid.RETURN_VALUE + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/GenSalt1.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/GenSalt1.kt new file mode 100644 index 0000000..bd52f73 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/GenSalt1.kt @@ -0,0 +1,53 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class GenSalt1 : AbstractRoutine("gen_salt", Public.PUBLIC, DSL.comment(""), SQLDataType.CLOB) { + companion object { + + /** + * The parameter public.gen_salt.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.CLOB, false, false) + + /** + * The parameter public.gen_salt._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = GenSalt1.RETURN_VALUE + addInParameter(GenSalt1._1) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: String?): Unit = setValue(GenSalt1._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(GenSalt1._1, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/GenSalt2.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/GenSalt2.kt new file mode 100644 index 0000000..6215ae5 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/GenSalt2.kt @@ -0,0 +1,72 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class GenSalt2 : AbstractRoutine("gen_salt", Public.PUBLIC, DSL.comment(""), SQLDataType.CLOB) { + companion object { + + /** + * The parameter public.gen_salt.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.CLOB, false, false) + + /** + * The parameter public.gen_salt._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.CLOB, false, true) + + /** + * The parameter public.gen_salt._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.INTEGER, false, true) + } + + init { + returnParameter = GenSalt2.RETURN_VALUE + addInParameter(GenSalt2._1) + addInParameter(GenSalt2._2) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: String?): Unit = setValue(GenSalt2._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(GenSalt2._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: Int?): Unit = setValue(GenSalt2._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(GenSalt2._2, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Hmac1.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Hmac1.kt new file mode 100644 index 0000000..84fbd18 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Hmac1.kt @@ -0,0 +1,91 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class Hmac1 : AbstractRoutine("hmac", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.hmac.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.hmac._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.CLOB, false, true) + + /** + * The parameter public.hmac._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.CLOB, false, true) + + /** + * The parameter public.hmac._3. + */ + val _3: Parameter = Internal.createParameter("_3", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = Hmac1.RETURN_VALUE + addInParameter(Hmac1._1) + addInParameter(Hmac1._2) + addInParameter(Hmac1._3) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: String?): Unit = setValue(Hmac1._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(Hmac1._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: String?): Unit = setValue(Hmac1._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(Hmac1._2, field) + } + + /** + * Set the _3 parameter IN value to the routine + */ + fun set__3(value: String?): Unit = setValue(Hmac1._3, value) + + /** + * Set the _3 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__3(field: Field): Unit { + setField(Hmac1._3, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Hmac2.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Hmac2.kt new file mode 100644 index 0000000..b28272c --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/Hmac2.kt @@ -0,0 +1,91 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class Hmac2 : AbstractRoutine("hmac", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.hmac.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.hmac._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.hmac._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.BLOB, false, true) + + /** + * The parameter public.hmac._3. + */ + val _3: Parameter = Internal.createParameter("_3", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = Hmac2.RETURN_VALUE + addInParameter(Hmac2._1) + addInParameter(Hmac2._2) + addInParameter(Hmac2._3) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(Hmac2._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(Hmac2._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: ByteArray?): Unit = setValue(Hmac2._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(Hmac2._2, field) + } + + /** + * Set the _3 parameter IN value to the routine + */ + fun set__3(value: String?): Unit = setValue(Hmac2._3, value) + + /** + * Set the _3 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__3(field: Field): Unit { + setField(Hmac2._3, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpKeyId.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpKeyId.kt new file mode 100644 index 0000000..9d61e5b --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpKeyId.kt @@ -0,0 +1,52 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class PgpKeyId : AbstractRoutine("pgp_key_id", Public.PUBLIC, DSL.comment(""), SQLDataType.CLOB) { + companion object { + + /** + * The parameter public.pgp_key_id.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.CLOB, false, false) + + /** + * The parameter public.pgp_key_id._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + } + + init { + returnParameter = PgpKeyId.RETURN_VALUE + addInParameter(PgpKeyId._1) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(PgpKeyId._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(PgpKeyId._1, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubDecrypt1.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubDecrypt1.kt new file mode 100644 index 0000000..bbbae0a --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubDecrypt1.kt @@ -0,0 +1,72 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class PgpPubDecrypt1 : AbstractRoutine("pgp_pub_decrypt", Public.PUBLIC, DSL.comment(""), SQLDataType.CLOB) { + companion object { + + /** + * The parameter public.pgp_pub_decrypt.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.CLOB, false, false) + + /** + * The parameter public.pgp_pub_decrypt._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.pgp_pub_decrypt._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.BLOB, false, true) + } + + init { + returnParameter = PgpPubDecrypt1.RETURN_VALUE + addInParameter(PgpPubDecrypt1._1) + addInParameter(PgpPubDecrypt1._2) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(PgpPubDecrypt1._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(PgpPubDecrypt1._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: ByteArray?): Unit = setValue(PgpPubDecrypt1._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(PgpPubDecrypt1._2, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubDecrypt2.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubDecrypt2.kt new file mode 100644 index 0000000..2775cb2 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubDecrypt2.kt @@ -0,0 +1,91 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class PgpPubDecrypt2 : AbstractRoutine("pgp_pub_decrypt", Public.PUBLIC, DSL.comment(""), SQLDataType.CLOB) { + companion object { + + /** + * The parameter public.pgp_pub_decrypt.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.CLOB, false, false) + + /** + * The parameter public.pgp_pub_decrypt._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.pgp_pub_decrypt._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.BLOB, false, true) + + /** + * The parameter public.pgp_pub_decrypt._3. + */ + val _3: Parameter = Internal.createParameter("_3", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = PgpPubDecrypt2.RETURN_VALUE + addInParameter(PgpPubDecrypt2._1) + addInParameter(PgpPubDecrypt2._2) + addInParameter(PgpPubDecrypt2._3) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(PgpPubDecrypt2._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(PgpPubDecrypt2._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: ByteArray?): Unit = setValue(PgpPubDecrypt2._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(PgpPubDecrypt2._2, field) + } + + /** + * Set the _3 parameter IN value to the routine + */ + fun set__3(value: String?): Unit = setValue(PgpPubDecrypt2._3, value) + + /** + * Set the _3 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__3(field: Field): Unit { + setField(PgpPubDecrypt2._3, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubDecrypt3.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubDecrypt3.kt new file mode 100644 index 0000000..3f6ab63 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubDecrypt3.kt @@ -0,0 +1,110 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class PgpPubDecrypt3 : AbstractRoutine("pgp_pub_decrypt", Public.PUBLIC, DSL.comment(""), SQLDataType.CLOB) { + companion object { + + /** + * The parameter public.pgp_pub_decrypt.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.CLOB, false, false) + + /** + * The parameter public.pgp_pub_decrypt._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.pgp_pub_decrypt._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.BLOB, false, true) + + /** + * The parameter public.pgp_pub_decrypt._3. + */ + val _3: Parameter = Internal.createParameter("_3", SQLDataType.CLOB, false, true) + + /** + * The parameter public.pgp_pub_decrypt._4. + */ + val _4: Parameter = Internal.createParameter("_4", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = PgpPubDecrypt3.RETURN_VALUE + addInParameter(PgpPubDecrypt3._1) + addInParameter(PgpPubDecrypt3._2) + addInParameter(PgpPubDecrypt3._3) + addInParameter(PgpPubDecrypt3._4) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(PgpPubDecrypt3._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(PgpPubDecrypt3._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: ByteArray?): Unit = setValue(PgpPubDecrypt3._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(PgpPubDecrypt3._2, field) + } + + /** + * Set the _3 parameter IN value to the routine + */ + fun set__3(value: String?): Unit = setValue(PgpPubDecrypt3._3, value) + + /** + * Set the _3 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__3(field: Field): Unit { + setField(PgpPubDecrypt3._3, field) + } + + /** + * Set the _4 parameter IN value to the routine + */ + fun set__4(value: String?): Unit = setValue(PgpPubDecrypt3._4, value) + + /** + * Set the _4 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__4(field: Field): Unit { + setField(PgpPubDecrypt3._4, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubDecryptBytea1.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubDecryptBytea1.kt new file mode 100644 index 0000000..c0f18a8 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubDecryptBytea1.kt @@ -0,0 +1,72 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class PgpPubDecryptBytea1 : AbstractRoutine("pgp_pub_decrypt_bytea", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.pgp_pub_decrypt_bytea.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.pgp_pub_decrypt_bytea._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.pgp_pub_decrypt_bytea._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.BLOB, false, true) + } + + init { + returnParameter = PgpPubDecryptBytea1.RETURN_VALUE + addInParameter(PgpPubDecryptBytea1._1) + addInParameter(PgpPubDecryptBytea1._2) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(PgpPubDecryptBytea1._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(PgpPubDecryptBytea1._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: ByteArray?): Unit = setValue(PgpPubDecryptBytea1._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(PgpPubDecryptBytea1._2, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubDecryptBytea2.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubDecryptBytea2.kt new file mode 100644 index 0000000..052bb1c --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubDecryptBytea2.kt @@ -0,0 +1,91 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class PgpPubDecryptBytea2 : AbstractRoutine("pgp_pub_decrypt_bytea", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.pgp_pub_decrypt_bytea.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.pgp_pub_decrypt_bytea._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.pgp_pub_decrypt_bytea._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.BLOB, false, true) + + /** + * The parameter public.pgp_pub_decrypt_bytea._3. + */ + val _3: Parameter = Internal.createParameter("_3", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = PgpPubDecryptBytea2.RETURN_VALUE + addInParameter(PgpPubDecryptBytea2._1) + addInParameter(PgpPubDecryptBytea2._2) + addInParameter(PgpPubDecryptBytea2._3) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(PgpPubDecryptBytea2._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(PgpPubDecryptBytea2._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: ByteArray?): Unit = setValue(PgpPubDecryptBytea2._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(PgpPubDecryptBytea2._2, field) + } + + /** + * Set the _3 parameter IN value to the routine + */ + fun set__3(value: String?): Unit = setValue(PgpPubDecryptBytea2._3, value) + + /** + * Set the _3 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__3(field: Field): Unit { + setField(PgpPubDecryptBytea2._3, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubDecryptBytea3.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubDecryptBytea3.kt new file mode 100644 index 0000000..be2f7bd --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubDecryptBytea3.kt @@ -0,0 +1,110 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class PgpPubDecryptBytea3 : AbstractRoutine("pgp_pub_decrypt_bytea", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.pgp_pub_decrypt_bytea.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.pgp_pub_decrypt_bytea._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.pgp_pub_decrypt_bytea._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.BLOB, false, true) + + /** + * The parameter public.pgp_pub_decrypt_bytea._3. + */ + val _3: Parameter = Internal.createParameter("_3", SQLDataType.CLOB, false, true) + + /** + * The parameter public.pgp_pub_decrypt_bytea._4. + */ + val _4: Parameter = Internal.createParameter("_4", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = PgpPubDecryptBytea3.RETURN_VALUE + addInParameter(PgpPubDecryptBytea3._1) + addInParameter(PgpPubDecryptBytea3._2) + addInParameter(PgpPubDecryptBytea3._3) + addInParameter(PgpPubDecryptBytea3._4) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(PgpPubDecryptBytea3._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(PgpPubDecryptBytea3._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: ByteArray?): Unit = setValue(PgpPubDecryptBytea3._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(PgpPubDecryptBytea3._2, field) + } + + /** + * Set the _3 parameter IN value to the routine + */ + fun set__3(value: String?): Unit = setValue(PgpPubDecryptBytea3._3, value) + + /** + * Set the _3 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__3(field: Field): Unit { + setField(PgpPubDecryptBytea3._3, field) + } + + /** + * Set the _4 parameter IN value to the routine + */ + fun set__4(value: String?): Unit = setValue(PgpPubDecryptBytea3._4, value) + + /** + * Set the _4 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__4(field: Field): Unit { + setField(PgpPubDecryptBytea3._4, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubEncrypt1.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubEncrypt1.kt new file mode 100644 index 0000000..54e2519 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubEncrypt1.kt @@ -0,0 +1,72 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class PgpPubEncrypt1 : AbstractRoutine("pgp_pub_encrypt", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.pgp_pub_encrypt.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.pgp_pub_encrypt._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.CLOB, false, true) + + /** + * The parameter public.pgp_pub_encrypt._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.BLOB, false, true) + } + + init { + returnParameter = PgpPubEncrypt1.RETURN_VALUE + addInParameter(PgpPubEncrypt1._1) + addInParameter(PgpPubEncrypt1._2) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: String?): Unit = setValue(PgpPubEncrypt1._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(PgpPubEncrypt1._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: ByteArray?): Unit = setValue(PgpPubEncrypt1._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(PgpPubEncrypt1._2, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubEncrypt2.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubEncrypt2.kt new file mode 100644 index 0000000..891c7b5 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubEncrypt2.kt @@ -0,0 +1,91 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class PgpPubEncrypt2 : AbstractRoutine("pgp_pub_encrypt", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.pgp_pub_encrypt.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.pgp_pub_encrypt._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.CLOB, false, true) + + /** + * The parameter public.pgp_pub_encrypt._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.BLOB, false, true) + + /** + * The parameter public.pgp_pub_encrypt._3. + */ + val _3: Parameter = Internal.createParameter("_3", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = PgpPubEncrypt2.RETURN_VALUE + addInParameter(PgpPubEncrypt2._1) + addInParameter(PgpPubEncrypt2._2) + addInParameter(PgpPubEncrypt2._3) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: String?): Unit = setValue(PgpPubEncrypt2._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(PgpPubEncrypt2._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: ByteArray?): Unit = setValue(PgpPubEncrypt2._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(PgpPubEncrypt2._2, field) + } + + /** + * Set the _3 parameter IN value to the routine + */ + fun set__3(value: String?): Unit = setValue(PgpPubEncrypt2._3, value) + + /** + * Set the _3 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__3(field: Field): Unit { + setField(PgpPubEncrypt2._3, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubEncryptBytea1.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubEncryptBytea1.kt new file mode 100644 index 0000000..eb56f21 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubEncryptBytea1.kt @@ -0,0 +1,72 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class PgpPubEncryptBytea1 : AbstractRoutine("pgp_pub_encrypt_bytea", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.pgp_pub_encrypt_bytea.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.pgp_pub_encrypt_bytea._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.pgp_pub_encrypt_bytea._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.BLOB, false, true) + } + + init { + returnParameter = PgpPubEncryptBytea1.RETURN_VALUE + addInParameter(PgpPubEncryptBytea1._1) + addInParameter(PgpPubEncryptBytea1._2) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(PgpPubEncryptBytea1._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(PgpPubEncryptBytea1._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: ByteArray?): Unit = setValue(PgpPubEncryptBytea1._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(PgpPubEncryptBytea1._2, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubEncryptBytea2.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubEncryptBytea2.kt new file mode 100644 index 0000000..63fc8f7 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpPubEncryptBytea2.kt @@ -0,0 +1,91 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class PgpPubEncryptBytea2 : AbstractRoutine("pgp_pub_encrypt_bytea", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.pgp_pub_encrypt_bytea.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.pgp_pub_encrypt_bytea._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.pgp_pub_encrypt_bytea._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.BLOB, false, true) + + /** + * The parameter public.pgp_pub_encrypt_bytea._3. + */ + val _3: Parameter = Internal.createParameter("_3", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = PgpPubEncryptBytea2.RETURN_VALUE + addInParameter(PgpPubEncryptBytea2._1) + addInParameter(PgpPubEncryptBytea2._2) + addInParameter(PgpPubEncryptBytea2._3) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(PgpPubEncryptBytea2._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(PgpPubEncryptBytea2._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: ByteArray?): Unit = setValue(PgpPubEncryptBytea2._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(PgpPubEncryptBytea2._2, field) + } + + /** + * Set the _3 parameter IN value to the routine + */ + fun set__3(value: String?): Unit = setValue(PgpPubEncryptBytea2._3, value) + + /** + * Set the _3 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__3(field: Field): Unit { + setField(PgpPubEncryptBytea2._3, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymDecrypt1.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymDecrypt1.kt new file mode 100644 index 0000000..7728250 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymDecrypt1.kt @@ -0,0 +1,72 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class PgpSymDecrypt1 : AbstractRoutine("pgp_sym_decrypt", Public.PUBLIC, DSL.comment(""), SQLDataType.CLOB) { + companion object { + + /** + * The parameter public.pgp_sym_decrypt.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.CLOB, false, false) + + /** + * The parameter public.pgp_sym_decrypt._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.pgp_sym_decrypt._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = PgpSymDecrypt1.RETURN_VALUE + addInParameter(PgpSymDecrypt1._1) + addInParameter(PgpSymDecrypt1._2) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(PgpSymDecrypt1._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(PgpSymDecrypt1._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: String?): Unit = setValue(PgpSymDecrypt1._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(PgpSymDecrypt1._2, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymDecrypt2.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymDecrypt2.kt new file mode 100644 index 0000000..8102972 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymDecrypt2.kt @@ -0,0 +1,91 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class PgpSymDecrypt2 : AbstractRoutine("pgp_sym_decrypt", Public.PUBLIC, DSL.comment(""), SQLDataType.CLOB) { + companion object { + + /** + * The parameter public.pgp_sym_decrypt.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.CLOB, false, false) + + /** + * The parameter public.pgp_sym_decrypt._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.pgp_sym_decrypt._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.CLOB, false, true) + + /** + * The parameter public.pgp_sym_decrypt._3. + */ + val _3: Parameter = Internal.createParameter("_3", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = PgpSymDecrypt2.RETURN_VALUE + addInParameter(PgpSymDecrypt2._1) + addInParameter(PgpSymDecrypt2._2) + addInParameter(PgpSymDecrypt2._3) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(PgpSymDecrypt2._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(PgpSymDecrypt2._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: String?): Unit = setValue(PgpSymDecrypt2._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(PgpSymDecrypt2._2, field) + } + + /** + * Set the _3 parameter IN value to the routine + */ + fun set__3(value: String?): Unit = setValue(PgpSymDecrypt2._3, value) + + /** + * Set the _3 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__3(field: Field): Unit { + setField(PgpSymDecrypt2._3, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymDecryptBytea1.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymDecryptBytea1.kt new file mode 100644 index 0000000..72c2329 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymDecryptBytea1.kt @@ -0,0 +1,72 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class PgpSymDecryptBytea1 : AbstractRoutine("pgp_sym_decrypt_bytea", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.pgp_sym_decrypt_bytea.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.pgp_sym_decrypt_bytea._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.pgp_sym_decrypt_bytea._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = PgpSymDecryptBytea1.RETURN_VALUE + addInParameter(PgpSymDecryptBytea1._1) + addInParameter(PgpSymDecryptBytea1._2) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(PgpSymDecryptBytea1._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(PgpSymDecryptBytea1._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: String?): Unit = setValue(PgpSymDecryptBytea1._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(PgpSymDecryptBytea1._2, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymDecryptBytea2.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymDecryptBytea2.kt new file mode 100644 index 0000000..34af81b --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymDecryptBytea2.kt @@ -0,0 +1,91 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class PgpSymDecryptBytea2 : AbstractRoutine("pgp_sym_decrypt_bytea", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.pgp_sym_decrypt_bytea.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.pgp_sym_decrypt_bytea._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.pgp_sym_decrypt_bytea._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.CLOB, false, true) + + /** + * The parameter public.pgp_sym_decrypt_bytea._3. + */ + val _3: Parameter = Internal.createParameter("_3", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = PgpSymDecryptBytea2.RETURN_VALUE + addInParameter(PgpSymDecryptBytea2._1) + addInParameter(PgpSymDecryptBytea2._2) + addInParameter(PgpSymDecryptBytea2._3) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(PgpSymDecryptBytea2._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(PgpSymDecryptBytea2._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: String?): Unit = setValue(PgpSymDecryptBytea2._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(PgpSymDecryptBytea2._2, field) + } + + /** + * Set the _3 parameter IN value to the routine + */ + fun set__3(value: String?): Unit = setValue(PgpSymDecryptBytea2._3, value) + + /** + * Set the _3 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__3(field: Field): Unit { + setField(PgpSymDecryptBytea2._3, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymEncrypt1.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymEncrypt1.kt new file mode 100644 index 0000000..e0bf215 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymEncrypt1.kt @@ -0,0 +1,72 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class PgpSymEncrypt1 : AbstractRoutine("pgp_sym_encrypt", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.pgp_sym_encrypt.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.pgp_sym_encrypt._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.CLOB, false, true) + + /** + * The parameter public.pgp_sym_encrypt._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = PgpSymEncrypt1.RETURN_VALUE + addInParameter(PgpSymEncrypt1._1) + addInParameter(PgpSymEncrypt1._2) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: String?): Unit = setValue(PgpSymEncrypt1._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(PgpSymEncrypt1._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: String?): Unit = setValue(PgpSymEncrypt1._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(PgpSymEncrypt1._2, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymEncrypt2.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymEncrypt2.kt new file mode 100644 index 0000000..b23fc6e --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymEncrypt2.kt @@ -0,0 +1,91 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class PgpSymEncrypt2 : AbstractRoutine("pgp_sym_encrypt", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.pgp_sym_encrypt.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.pgp_sym_encrypt._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.CLOB, false, true) + + /** + * The parameter public.pgp_sym_encrypt._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.CLOB, false, true) + + /** + * The parameter public.pgp_sym_encrypt._3. + */ + val _3: Parameter = Internal.createParameter("_3", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = PgpSymEncrypt2.RETURN_VALUE + addInParameter(PgpSymEncrypt2._1) + addInParameter(PgpSymEncrypt2._2) + addInParameter(PgpSymEncrypt2._3) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: String?): Unit = setValue(PgpSymEncrypt2._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(PgpSymEncrypt2._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: String?): Unit = setValue(PgpSymEncrypt2._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(PgpSymEncrypt2._2, field) + } + + /** + * Set the _3 parameter IN value to the routine + */ + fun set__3(value: String?): Unit = setValue(PgpSymEncrypt2._3, value) + + /** + * Set the _3 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__3(field: Field): Unit { + setField(PgpSymEncrypt2._3, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymEncryptBytea1.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymEncryptBytea1.kt new file mode 100644 index 0000000..b7df61e --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymEncryptBytea1.kt @@ -0,0 +1,72 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class PgpSymEncryptBytea1 : AbstractRoutine("pgp_sym_encrypt_bytea", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.pgp_sym_encrypt_bytea.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.pgp_sym_encrypt_bytea._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.pgp_sym_encrypt_bytea._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = PgpSymEncryptBytea1.RETURN_VALUE + addInParameter(PgpSymEncryptBytea1._1) + addInParameter(PgpSymEncryptBytea1._2) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(PgpSymEncryptBytea1._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(PgpSymEncryptBytea1._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: String?): Unit = setValue(PgpSymEncryptBytea1._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(PgpSymEncryptBytea1._2, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymEncryptBytea2.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymEncryptBytea2.kt new file mode 100644 index 0000000..216b465 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/PgpSymEncryptBytea2.kt @@ -0,0 +1,91 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines + + +import de.fiereu.openmmo.server.login.jooq.Public + +import org.jooq.Field +import org.jooq.Parameter +import org.jooq.impl.AbstractRoutine +import org.jooq.impl.DSL +import org.jooq.impl.Internal +import org.jooq.impl.SQLDataType + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class PgpSymEncryptBytea2 : AbstractRoutine("pgp_sym_encrypt_bytea", Public.PUBLIC, DSL.comment(""), SQLDataType.BLOB) { + companion object { + + /** + * The parameter public.pgp_sym_encrypt_bytea.RETURN_VALUE. + */ + val RETURN_VALUE: Parameter = Internal.createParameter("RETURN_VALUE", SQLDataType.BLOB, false, false) + + /** + * The parameter public.pgp_sym_encrypt_bytea._1. + */ + val _1: Parameter = Internal.createParameter("_1", SQLDataType.BLOB, false, true) + + /** + * The parameter public.pgp_sym_encrypt_bytea._2. + */ + val _2: Parameter = Internal.createParameter("_2", SQLDataType.CLOB, false, true) + + /** + * The parameter public.pgp_sym_encrypt_bytea._3. + */ + val _3: Parameter = Internal.createParameter("_3", SQLDataType.CLOB, false, true) + } + + init { + returnParameter = PgpSymEncryptBytea2.RETURN_VALUE + addInParameter(PgpSymEncryptBytea2._1) + addInParameter(PgpSymEncryptBytea2._2) + addInParameter(PgpSymEncryptBytea2._3) + setOverloaded(true) + } + + /** + * Set the _1 parameter IN value to the routine + */ + fun set__1(value: ByteArray?): Unit = setValue(PgpSymEncryptBytea2._1, value) + + /** + * Set the _1 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__1(field: Field): Unit { + setField(PgpSymEncryptBytea2._1, field) + } + + /** + * Set the _2 parameter IN value to the routine + */ + fun set__2(value: String?): Unit = setValue(PgpSymEncryptBytea2._2, value) + + /** + * Set the _2 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__2(field: Field): Unit { + setField(PgpSymEncryptBytea2._2, field) + } + + /** + * Set the _3 parameter IN value to the routine + */ + fun set__3(value: String?): Unit = setValue(PgpSymEncryptBytea2._3, value) + + /** + * Set the _3 parameter to the function to be used with a + * {@link org.jooq.Select} statement + */ + fun set__3(field: Field): Unit { + setField(PgpSymEncryptBytea2._3, field) + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/references/Routines.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/references/Routines.kt new file mode 100644 index 0000000..87a654d --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/routines/references/Routines.kt @@ -0,0 +1,1662 @@ +@file:Suppress("warnings") +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.routines.references + + +import de.fiereu.openmmo.server.login.jooq.routines.Armor1 +import de.fiereu.openmmo.server.login.jooq.routines.Armor2 +import de.fiereu.openmmo.server.login.jooq.routines.Crypt +import de.fiereu.openmmo.server.login.jooq.routines.Dearmor +import de.fiereu.openmmo.server.login.jooq.routines.Decrypt +import de.fiereu.openmmo.server.login.jooq.routines.DecryptIv +import de.fiereu.openmmo.server.login.jooq.routines.Digest1 +import de.fiereu.openmmo.server.login.jooq.routines.Digest2 +import de.fiereu.openmmo.server.login.jooq.routines.Encrypt +import de.fiereu.openmmo.server.login.jooq.routines.EncryptIv +import de.fiereu.openmmo.server.login.jooq.routines.GenRandomBytes +import de.fiereu.openmmo.server.login.jooq.routines.GenRandomUuid +import de.fiereu.openmmo.server.login.jooq.routines.GenSalt1 +import de.fiereu.openmmo.server.login.jooq.routines.GenSalt2 +import de.fiereu.openmmo.server.login.jooq.routines.Hmac1 +import de.fiereu.openmmo.server.login.jooq.routines.Hmac2 +import de.fiereu.openmmo.server.login.jooq.routines.PgpKeyId +import de.fiereu.openmmo.server.login.jooq.routines.PgpPubDecrypt1 +import de.fiereu.openmmo.server.login.jooq.routines.PgpPubDecrypt2 +import de.fiereu.openmmo.server.login.jooq.routines.PgpPubDecrypt3 +import de.fiereu.openmmo.server.login.jooq.routines.PgpPubDecryptBytea1 +import de.fiereu.openmmo.server.login.jooq.routines.PgpPubDecryptBytea2 +import de.fiereu.openmmo.server.login.jooq.routines.PgpPubDecryptBytea3 +import de.fiereu.openmmo.server.login.jooq.routines.PgpPubEncrypt1 +import de.fiereu.openmmo.server.login.jooq.routines.PgpPubEncrypt2 +import de.fiereu.openmmo.server.login.jooq.routines.PgpPubEncryptBytea1 +import de.fiereu.openmmo.server.login.jooq.routines.PgpPubEncryptBytea2 +import de.fiereu.openmmo.server.login.jooq.routines.PgpSymDecrypt1 +import de.fiereu.openmmo.server.login.jooq.routines.PgpSymDecrypt2 +import de.fiereu.openmmo.server.login.jooq.routines.PgpSymDecryptBytea1 +import de.fiereu.openmmo.server.login.jooq.routines.PgpSymDecryptBytea2 +import de.fiereu.openmmo.server.login.jooq.routines.PgpSymEncrypt1 +import de.fiereu.openmmo.server.login.jooq.routines.PgpSymEncrypt2 +import de.fiereu.openmmo.server.login.jooq.routines.PgpSymEncryptBytea1 +import de.fiereu.openmmo.server.login.jooq.routines.PgpSymEncryptBytea2 + +import java.util.UUID + +import org.jooq.Configuration +import org.jooq.Field + + + +/** + * Call public.armor + */ +fun armor1( + configuration: Configuration + , __1: ByteArray? +): String? { + val f = Armor1() + f.set__1(__1) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.armor as a field. + */ +fun armor1( + __1: ByteArray? +): Field { + val f = Armor1() + f.set__1(__1) + + return f.asField() +} + +/** + * Get public.armor as a field. + */ +fun armor1( + __1: Field +): Field { + val f = Armor1() + f.set__1(__1) + + return f.asField() +} + +/** + * Call public.armor + */ +fun armor2( + configuration: Configuration + , __1: ByteArray? + , __2: Array? + , __3: Array? +): String? { + val f = Armor2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.armor as a field. + */ +fun armor2( + __1: ByteArray? + , __2: Array? + , __3: Array? +): Field { + val f = Armor2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Get public.armor as a field. + */ +fun armor2( + __1: Field + , __2: Field?> + , __3: Field?> +): Field { + val f = Armor2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Call public.crypt + */ +fun crypt( + configuration: Configuration + , __1: String? + , __2: String? +): String? { + val f = Crypt() + f.set__1(__1) + f.set__2(__2) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.crypt as a field. + */ +fun crypt( + __1: String? + , __2: String? +): Field { + val f = Crypt() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Get public.crypt as a field. + */ +fun crypt( + __1: Field + , __2: Field +): Field { + val f = Crypt() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Call public.dearmor + */ +fun dearmor( + configuration: Configuration + , __1: String? +): ByteArray? { + val f = Dearmor() + f.set__1(__1) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.dearmor as a field. + */ +fun dearmor( + __1: String? +): Field { + val f = Dearmor() + f.set__1(__1) + + return f.asField() +} + +/** + * Get public.dearmor as a field. + */ +fun dearmor( + __1: Field +): Field { + val f = Dearmor() + f.set__1(__1) + + return f.asField() +} + +/** + * Call public.decrypt + */ +fun decrypt( + configuration: Configuration + , __1: ByteArray? + , __2: ByteArray? + , __3: String? +): ByteArray? { + val f = Decrypt() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.decrypt as a field. + */ +fun decrypt( + __1: ByteArray? + , __2: ByteArray? + , __3: String? +): Field { + val f = Decrypt() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Get public.decrypt as a field. + */ +fun decrypt( + __1: Field + , __2: Field + , __3: Field +): Field { + val f = Decrypt() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Call public.decrypt_iv + */ +fun decryptIv( + configuration: Configuration + , __1: ByteArray? + , __2: ByteArray? + , __3: ByteArray? + , __4: String? +): ByteArray? { + val f = DecryptIv() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + f.set__4(__4) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.decrypt_iv as a field. + */ +fun decryptIv( + __1: ByteArray? + , __2: ByteArray? + , __3: ByteArray? + , __4: String? +): Field { + val f = DecryptIv() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + f.set__4(__4) + + return f.asField() +} + +/** + * Get public.decrypt_iv as a field. + */ +fun decryptIv( + __1: Field + , __2: Field + , __3: Field + , __4: Field +): Field { + val f = DecryptIv() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + f.set__4(__4) + + return f.asField() +} + +/** + * Call public.digest + */ +fun digest1( + configuration: Configuration + , __1: String? + , __2: String? +): ByteArray? { + val f = Digest1() + f.set__1(__1) + f.set__2(__2) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.digest as a field. + */ +fun digest1( + __1: String? + , __2: String? +): Field { + val f = Digest1() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Get public.digest as a field. + */ +fun digest1( + __1: Field + , __2: Field +): Field { + val f = Digest1() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Call public.digest + */ +fun digest2( + configuration: Configuration + , __1: ByteArray? + , __2: String? +): ByteArray? { + val f = Digest2() + f.set__1(__1) + f.set__2(__2) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.digest as a field. + */ +fun digest2( + __1: ByteArray? + , __2: String? +): Field { + val f = Digest2() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Get public.digest as a field. + */ +fun digest2( + __1: Field + , __2: Field +): Field { + val f = Digest2() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Call public.encrypt + */ +fun encrypt( + configuration: Configuration + , __1: ByteArray? + , __2: ByteArray? + , __3: String? +): ByteArray? { + val f = Encrypt() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.encrypt as a field. + */ +fun encrypt( + __1: ByteArray? + , __2: ByteArray? + , __3: String? +): Field { + val f = Encrypt() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Get public.encrypt as a field. + */ +fun encrypt( + __1: Field + , __2: Field + , __3: Field +): Field { + val f = Encrypt() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Call public.encrypt_iv + */ +fun encryptIv( + configuration: Configuration + , __1: ByteArray? + , __2: ByteArray? + , __3: ByteArray? + , __4: String? +): ByteArray? { + val f = EncryptIv() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + f.set__4(__4) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.encrypt_iv as a field. + */ +fun encryptIv( + __1: ByteArray? + , __2: ByteArray? + , __3: ByteArray? + , __4: String? +): Field { + val f = EncryptIv() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + f.set__4(__4) + + return f.asField() +} + +/** + * Get public.encrypt_iv as a field. + */ +fun encryptIv( + __1: Field + , __2: Field + , __3: Field + , __4: Field +): Field { + val f = EncryptIv() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + f.set__4(__4) + + return f.asField() +} + +/** + * Call public.gen_random_bytes + */ +fun genRandomBytes( + configuration: Configuration + , __1: Int? +): ByteArray? { + val f = GenRandomBytes() + f.set__1(__1) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.gen_random_bytes as a field. + */ +fun genRandomBytes( + __1: Int? +): Field { + val f = GenRandomBytes() + f.set__1(__1) + + return f.asField() +} + +/** + * Get public.gen_random_bytes as a field. + */ +fun genRandomBytes( + __1: Field +): Field { + val f = GenRandomBytes() + f.set__1(__1) + + return f.asField() +} + +/** + * Call public.gen_random_uuid + */ +fun genRandomUuid( + configuration: Configuration +): UUID? { + val f = GenRandomUuid() + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.gen_random_uuid as a field. + */ +fun genRandomUuid(): Field { + val f = GenRandomUuid() + + return f.asField() +} + +/** + * Call public.gen_salt + */ +fun genSalt1( + configuration: Configuration + , __1: String? +): String? { + val f = GenSalt1() + f.set__1(__1) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.gen_salt as a field. + */ +fun genSalt1( + __1: String? +): Field { + val f = GenSalt1() + f.set__1(__1) + + return f.asField() +} + +/** + * Get public.gen_salt as a field. + */ +fun genSalt1( + __1: Field +): Field { + val f = GenSalt1() + f.set__1(__1) + + return f.asField() +} + +/** + * Call public.gen_salt + */ +fun genSalt2( + configuration: Configuration + , __1: String? + , __2: Int? +): String? { + val f = GenSalt2() + f.set__1(__1) + f.set__2(__2) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.gen_salt as a field. + */ +fun genSalt2( + __1: String? + , __2: Int? +): Field { + val f = GenSalt2() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Get public.gen_salt as a field. + */ +fun genSalt2( + __1: Field + , __2: Field +): Field { + val f = GenSalt2() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Call public.hmac + */ +fun hmac1( + configuration: Configuration + , __1: String? + , __2: String? + , __3: String? +): ByteArray? { + val f = Hmac1() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.hmac as a field. + */ +fun hmac1( + __1: String? + , __2: String? + , __3: String? +): Field { + val f = Hmac1() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Get public.hmac as a field. + */ +fun hmac1( + __1: Field + , __2: Field + , __3: Field +): Field { + val f = Hmac1() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Call public.hmac + */ +fun hmac2( + configuration: Configuration + , __1: ByteArray? + , __2: ByteArray? + , __3: String? +): ByteArray? { + val f = Hmac2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.hmac as a field. + */ +fun hmac2( + __1: ByteArray? + , __2: ByteArray? + , __3: String? +): Field { + val f = Hmac2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Get public.hmac as a field. + */ +fun hmac2( + __1: Field + , __2: Field + , __3: Field +): Field { + val f = Hmac2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Call public.pgp_key_id + */ +fun pgpKeyId( + configuration: Configuration + , __1: ByteArray? +): String? { + val f = PgpKeyId() + f.set__1(__1) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.pgp_key_id as a field. + */ +fun pgpKeyId( + __1: ByteArray? +): Field { + val f = PgpKeyId() + f.set__1(__1) + + return f.asField() +} + +/** + * Get public.pgp_key_id as a field. + */ +fun pgpKeyId( + __1: Field +): Field { + val f = PgpKeyId() + f.set__1(__1) + + return f.asField() +} + +/** + * Call public.pgp_pub_decrypt + */ +fun pgpPubDecrypt1( + configuration: Configuration + , __1: ByteArray? + , __2: ByteArray? +): String? { + val f = PgpPubDecrypt1() + f.set__1(__1) + f.set__2(__2) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.pgp_pub_decrypt as a field. + */ +fun pgpPubDecrypt1( + __1: ByteArray? + , __2: ByteArray? +): Field { + val f = PgpPubDecrypt1() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Get public.pgp_pub_decrypt as a field. + */ +fun pgpPubDecrypt1( + __1: Field + , __2: Field +): Field { + val f = PgpPubDecrypt1() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Call public.pgp_pub_decrypt + */ +fun pgpPubDecrypt2( + configuration: Configuration + , __1: ByteArray? + , __2: ByteArray? + , __3: String? +): String? { + val f = PgpPubDecrypt2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.pgp_pub_decrypt as a field. + */ +fun pgpPubDecrypt2( + __1: ByteArray? + , __2: ByteArray? + , __3: String? +): Field { + val f = PgpPubDecrypt2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Get public.pgp_pub_decrypt as a field. + */ +fun pgpPubDecrypt2( + __1: Field + , __2: Field + , __3: Field +): Field { + val f = PgpPubDecrypt2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Call public.pgp_pub_decrypt + */ +fun pgpPubDecrypt3( + configuration: Configuration + , __1: ByteArray? + , __2: ByteArray? + , __3: String? + , __4: String? +): String? { + val f = PgpPubDecrypt3() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + f.set__4(__4) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.pgp_pub_decrypt as a field. + */ +fun pgpPubDecrypt3( + __1: ByteArray? + , __2: ByteArray? + , __3: String? + , __4: String? +): Field { + val f = PgpPubDecrypt3() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + f.set__4(__4) + + return f.asField() +} + +/** + * Get public.pgp_pub_decrypt as a field. + */ +fun pgpPubDecrypt3( + __1: Field + , __2: Field + , __3: Field + , __4: Field +): Field { + val f = PgpPubDecrypt3() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + f.set__4(__4) + + return f.asField() +} + +/** + * Call public.pgp_pub_decrypt_bytea + */ +fun pgpPubDecryptBytea1( + configuration: Configuration + , __1: ByteArray? + , __2: ByteArray? +): ByteArray? { + val f = PgpPubDecryptBytea1() + f.set__1(__1) + f.set__2(__2) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.pgp_pub_decrypt_bytea as a field. + */ +fun pgpPubDecryptBytea1( + __1: ByteArray? + , __2: ByteArray? +): Field { + val f = PgpPubDecryptBytea1() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Get public.pgp_pub_decrypt_bytea as a field. + */ +fun pgpPubDecryptBytea1( + __1: Field + , __2: Field +): Field { + val f = PgpPubDecryptBytea1() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Call public.pgp_pub_decrypt_bytea + */ +fun pgpPubDecryptBytea2( + configuration: Configuration + , __1: ByteArray? + , __2: ByteArray? + , __3: String? +): ByteArray? { + val f = PgpPubDecryptBytea2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.pgp_pub_decrypt_bytea as a field. + */ +fun pgpPubDecryptBytea2( + __1: ByteArray? + , __2: ByteArray? + , __3: String? +): Field { + val f = PgpPubDecryptBytea2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Get public.pgp_pub_decrypt_bytea as a field. + */ +fun pgpPubDecryptBytea2( + __1: Field + , __2: Field + , __3: Field +): Field { + val f = PgpPubDecryptBytea2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Call public.pgp_pub_decrypt_bytea + */ +fun pgpPubDecryptBytea3( + configuration: Configuration + , __1: ByteArray? + , __2: ByteArray? + , __3: String? + , __4: String? +): ByteArray? { + val f = PgpPubDecryptBytea3() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + f.set__4(__4) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.pgp_pub_decrypt_bytea as a field. + */ +fun pgpPubDecryptBytea3( + __1: ByteArray? + , __2: ByteArray? + , __3: String? + , __4: String? +): Field { + val f = PgpPubDecryptBytea3() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + f.set__4(__4) + + return f.asField() +} + +/** + * Get public.pgp_pub_decrypt_bytea as a field. + */ +fun pgpPubDecryptBytea3( + __1: Field + , __2: Field + , __3: Field + , __4: Field +): Field { + val f = PgpPubDecryptBytea3() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + f.set__4(__4) + + return f.asField() +} + +/** + * Call public.pgp_pub_encrypt + */ +fun pgpPubEncrypt1( + configuration: Configuration + , __1: String? + , __2: ByteArray? +): ByteArray? { + val f = PgpPubEncrypt1() + f.set__1(__1) + f.set__2(__2) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.pgp_pub_encrypt as a field. + */ +fun pgpPubEncrypt1( + __1: String? + , __2: ByteArray? +): Field { + val f = PgpPubEncrypt1() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Get public.pgp_pub_encrypt as a field. + */ +fun pgpPubEncrypt1( + __1: Field + , __2: Field +): Field { + val f = PgpPubEncrypt1() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Call public.pgp_pub_encrypt + */ +fun pgpPubEncrypt2( + configuration: Configuration + , __1: String? + , __2: ByteArray? + , __3: String? +): ByteArray? { + val f = PgpPubEncrypt2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.pgp_pub_encrypt as a field. + */ +fun pgpPubEncrypt2( + __1: String? + , __2: ByteArray? + , __3: String? +): Field { + val f = PgpPubEncrypt2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Get public.pgp_pub_encrypt as a field. + */ +fun pgpPubEncrypt2( + __1: Field + , __2: Field + , __3: Field +): Field { + val f = PgpPubEncrypt2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Call public.pgp_pub_encrypt_bytea + */ +fun pgpPubEncryptBytea1( + configuration: Configuration + , __1: ByteArray? + , __2: ByteArray? +): ByteArray? { + val f = PgpPubEncryptBytea1() + f.set__1(__1) + f.set__2(__2) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.pgp_pub_encrypt_bytea as a field. + */ +fun pgpPubEncryptBytea1( + __1: ByteArray? + , __2: ByteArray? +): Field { + val f = PgpPubEncryptBytea1() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Get public.pgp_pub_encrypt_bytea as a field. + */ +fun pgpPubEncryptBytea1( + __1: Field + , __2: Field +): Field { + val f = PgpPubEncryptBytea1() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Call public.pgp_pub_encrypt_bytea + */ +fun pgpPubEncryptBytea2( + configuration: Configuration + , __1: ByteArray? + , __2: ByteArray? + , __3: String? +): ByteArray? { + val f = PgpPubEncryptBytea2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.pgp_pub_encrypt_bytea as a field. + */ +fun pgpPubEncryptBytea2( + __1: ByteArray? + , __2: ByteArray? + , __3: String? +): Field { + val f = PgpPubEncryptBytea2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Get public.pgp_pub_encrypt_bytea as a field. + */ +fun pgpPubEncryptBytea2( + __1: Field + , __2: Field + , __3: Field +): Field { + val f = PgpPubEncryptBytea2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Call public.pgp_sym_decrypt + */ +fun pgpSymDecrypt1( + configuration: Configuration + , __1: ByteArray? + , __2: String? +): String? { + val f = PgpSymDecrypt1() + f.set__1(__1) + f.set__2(__2) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.pgp_sym_decrypt as a field. + */ +fun pgpSymDecrypt1( + __1: ByteArray? + , __2: String? +): Field { + val f = PgpSymDecrypt1() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Get public.pgp_sym_decrypt as a field. + */ +fun pgpSymDecrypt1( + __1: Field + , __2: Field +): Field { + val f = PgpSymDecrypt1() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Call public.pgp_sym_decrypt + */ +fun pgpSymDecrypt2( + configuration: Configuration + , __1: ByteArray? + , __2: String? + , __3: String? +): String? { + val f = PgpSymDecrypt2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.pgp_sym_decrypt as a field. + */ +fun pgpSymDecrypt2( + __1: ByteArray? + , __2: String? + , __3: String? +): Field { + val f = PgpSymDecrypt2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Get public.pgp_sym_decrypt as a field. + */ +fun pgpSymDecrypt2( + __1: Field + , __2: Field + , __3: Field +): Field { + val f = PgpSymDecrypt2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Call public.pgp_sym_decrypt_bytea + */ +fun pgpSymDecryptBytea1( + configuration: Configuration + , __1: ByteArray? + , __2: String? +): ByteArray? { + val f = PgpSymDecryptBytea1() + f.set__1(__1) + f.set__2(__2) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.pgp_sym_decrypt_bytea as a field. + */ +fun pgpSymDecryptBytea1( + __1: ByteArray? + , __2: String? +): Field { + val f = PgpSymDecryptBytea1() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Get public.pgp_sym_decrypt_bytea as a field. + */ +fun pgpSymDecryptBytea1( + __1: Field + , __2: Field +): Field { + val f = PgpSymDecryptBytea1() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Call public.pgp_sym_decrypt_bytea + */ +fun pgpSymDecryptBytea2( + configuration: Configuration + , __1: ByteArray? + , __2: String? + , __3: String? +): ByteArray? { + val f = PgpSymDecryptBytea2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.pgp_sym_decrypt_bytea as a field. + */ +fun pgpSymDecryptBytea2( + __1: ByteArray? + , __2: String? + , __3: String? +): Field { + val f = PgpSymDecryptBytea2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Get public.pgp_sym_decrypt_bytea as a field. + */ +fun pgpSymDecryptBytea2( + __1: Field + , __2: Field + , __3: Field +): Field { + val f = PgpSymDecryptBytea2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Call public.pgp_sym_encrypt + */ +fun pgpSymEncrypt1( + configuration: Configuration + , __1: String? + , __2: String? +): ByteArray? { + val f = PgpSymEncrypt1() + f.set__1(__1) + f.set__2(__2) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.pgp_sym_encrypt as a field. + */ +fun pgpSymEncrypt1( + __1: String? + , __2: String? +): Field { + val f = PgpSymEncrypt1() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Get public.pgp_sym_encrypt as a field. + */ +fun pgpSymEncrypt1( + __1: Field + , __2: Field +): Field { + val f = PgpSymEncrypt1() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Call public.pgp_sym_encrypt + */ +fun pgpSymEncrypt2( + configuration: Configuration + , __1: String? + , __2: String? + , __3: String? +): ByteArray? { + val f = PgpSymEncrypt2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.pgp_sym_encrypt as a field. + */ +fun pgpSymEncrypt2( + __1: String? + , __2: String? + , __3: String? +): Field { + val f = PgpSymEncrypt2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Get public.pgp_sym_encrypt as a field. + */ +fun pgpSymEncrypt2( + __1: Field + , __2: Field + , __3: Field +): Field { + val f = PgpSymEncrypt2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Call public.pgp_sym_encrypt_bytea + */ +fun pgpSymEncryptBytea1( + configuration: Configuration + , __1: ByteArray? + , __2: String? +): ByteArray? { + val f = PgpSymEncryptBytea1() + f.set__1(__1) + f.set__2(__2) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.pgp_sym_encrypt_bytea as a field. + */ +fun pgpSymEncryptBytea1( + __1: ByteArray? + , __2: String? +): Field { + val f = PgpSymEncryptBytea1() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Get public.pgp_sym_encrypt_bytea as a field. + */ +fun pgpSymEncryptBytea1( + __1: Field + , __2: Field +): Field { + val f = PgpSymEncryptBytea1() + f.set__1(__1) + f.set__2(__2) + + return f.asField() +} + +/** + * Call public.pgp_sym_encrypt_bytea + */ +fun pgpSymEncryptBytea2( + configuration: Configuration + , __1: ByteArray? + , __2: String? + , __3: String? +): ByteArray? { + val f = PgpSymEncryptBytea2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + f.execute(configuration) + return f.returnValue +} + +/** + * Get public.pgp_sym_encrypt_bytea as a field. + */ +fun pgpSymEncryptBytea2( + __1: ByteArray? + , __2: String? + , __3: String? +): Field { + val f = PgpSymEncryptBytea2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} + +/** + * Get public.pgp_sym_encrypt_bytea as a field. + */ +fun pgpSymEncryptBytea2( + __1: Field + , __2: Field + , __3: Field +): Field { + val f = PgpSymEncryptBytea2() + f.set__1(__1) + f.set__2(__2) + f.set__3(__3) + + return f.asField() +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/tables/User.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/tables/User.kt new file mode 100644 index 0000000..792a668 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/tables/User.kt @@ -0,0 +1,186 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.tables + + +import de.fiereu.openmmo.server.login.jooq.Public +import de.fiereu.openmmo.server.login.jooq.keys.USER_PKEY +import de.fiereu.openmmo.server.login.jooq.keys.USER_USERNAME_KEY +import de.fiereu.openmmo.server.login.jooq.tables.records.UserRecord + +import java.time.LocalDateTime + +import kotlin.collections.Collection +import kotlin.collections.List + +import org.jooq.Condition +import org.jooq.Field +import org.jooq.ForeignKey +import org.jooq.Identity +import org.jooq.InverseForeignKey +import org.jooq.Name +import org.jooq.PlainSQL +import org.jooq.QueryPart +import org.jooq.Record +import org.jooq.SQL +import org.jooq.Schema +import org.jooq.Select +import org.jooq.Stringly +import org.jooq.Table +import org.jooq.TableField +import org.jooq.TableOptions +import org.jooq.UniqueKey +import org.jooq.impl.DSL +import org.jooq.impl.SQLDataType +import org.jooq.impl.TableImpl + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class User( + alias: Name, + path: Table?, + childPath: ForeignKey?, + parentPath: InverseForeignKey?, + aliased: Table?, + parameters: Array?>?, + where: Condition? +): TableImpl( + alias, + Public.PUBLIC, + path, + childPath, + parentPath, + aliased, + parameters, + DSL.comment(""), + TableOptions.table(), + where, +) { + companion object { + + /** + * The reference instance of public.user + */ + val USER: User = User() + } + + /** + * The class holding records for this type + */ + override fun getRecordType(): Class = UserRecord::class.java + + /** + * The column public.user.id. + */ + val ID: TableField = createField(DSL.name("id"), SQLDataType.INTEGER.nullable(false).identity(true), this, "") + + /** + * The column public.user.created_at. + */ + val CREATED_AT: TableField = createField(DSL.name("created_at"), SQLDataType.LOCALDATETIME(6).nullable(false).defaultValue(DSL.field(DSL.raw("CURRENT_TIMESTAMP"), SQLDataType.LOCALDATETIME)), this, "") + + /** + * The column public.user.username. + */ + val USERNAME: TableField = createField(DSL.name("username"), SQLDataType.VARCHAR(12).nullable(false), this, "") + + /** + * The column public.user.password. + */ + val PASSWORD: TableField = createField(DSL.name("password"), SQLDataType.BLOB.nullable(false), this, "") + + private constructor(alias: Name, aliased: Table?): this(alias, null, null, null, aliased, null, null) + private constructor(alias: Name, aliased: Table?, parameters: Array?>?): this(alias, null, null, null, aliased, parameters, null) + private constructor(alias: Name, aliased: Table?, where: Condition?): this(alias, null, null, null, aliased, null, where) + + /** + * Create an aliased public.user table reference + */ + constructor(alias: String): this(DSL.name(alias)) + + /** + * Create an aliased public.user table reference + */ + constructor(alias: Name): this(alias, null) + + /** + * Create a public.user table reference + */ + constructor(): this(DSL.name("user"), null) + override fun getSchema(): Schema? = if (aliased()) null else Public.PUBLIC + override fun getIdentity(): Identity = super.getIdentity() as Identity + override fun getPrimaryKey(): UniqueKey = USER_PKEY + override fun getUniqueKeys(): List> = listOf(USER_USERNAME_KEY) + override fun `as`(alias: String): User = User(DSL.name(alias), this) + override fun `as`(alias: Name): User = User(alias, this) + override fun `as`(alias: Table<*>): User = User(alias.qualifiedName, this) + + /** + * Rename this table + */ + override fun rename(name: String): User = User(DSL.name(name), null) + + /** + * Rename this table + */ + override fun rename(name: Name): User = User(name, null) + + /** + * Rename this table + */ + override fun rename(name: Table<*>): User = User(name.qualifiedName, null) + + /** + * Create an inline derived table from this table + */ + override fun where(condition: Condition?): User = User(qualifiedName, if (aliased()) this else null, condition) + + /** + * Create an inline derived table from this table + */ + override fun where(conditions: Collection): User = where(DSL.and(conditions)) + + /** + * Create an inline derived table from this table + */ + override fun where(vararg conditions: Condition?): User = where(DSL.and(*conditions)) + + /** + * Create an inline derived table from this table + */ + override fun where(condition: Field?): User = where(DSL.condition(condition)) + + /** + * Create an inline derived table from this table + */ + @PlainSQL override fun where(condition: SQL): User = where(DSL.condition(condition)) + + /** + * Create an inline derived table from this table + */ + @PlainSQL override fun where(@Stringly.SQL condition: String): User = where(DSL.condition(condition)) + + /** + * Create an inline derived table from this table + */ + @PlainSQL override fun where(@Stringly.SQL condition: String, vararg binds: Any?): User = where(DSL.condition(condition, *binds)) + + /** + * Create an inline derived table from this table + */ + @PlainSQL override fun where(@Stringly.SQL condition: String, vararg parts: QueryPart): User = where(DSL.condition(condition, *parts)) + + /** + * Create an inline derived table from this table + */ + override fun whereExists(select: Select<*>): User = where(DSL.exists(select)) + + /** + * Create an inline derived table from this table + */ + override fun whereNotExists(select: Select<*>): User = where(DSL.notExists(select)) +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/tables/records/UserRecord.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/tables/records/UserRecord.kt new file mode 100644 index 0000000..4dd7aa2 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/tables/records/UserRecord.kt @@ -0,0 +1,53 @@ +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.tables.records + + +import de.fiereu.openmmo.server.login.jooq.tables.User + +import java.time.LocalDateTime + +import org.jooq.Record1 +import org.jooq.impl.UpdatableRecordImpl + + +/** + * This class is generated by jOOQ. + */ +@Suppress("warnings") +open class UserRecord() : UpdatableRecordImpl(User.USER) { + + open var id: Int? + set(value): Unit = set(0, value) + get(): Int? = get(0) as Int? + + open var createdAt: LocalDateTime? + set(value): Unit = set(1, value) + get(): LocalDateTime? = get(1) as LocalDateTime? + + open var username: String? + set(value): Unit = set(2, value) + get(): String? = get(2) as String? + + open var password: ByteArray? + set(value): Unit = set(3, value) + get(): ByteArray? = get(3) as ByteArray? + + // ------------------------------------------------------------------------- + // Primary key information + // ------------------------------------------------------------------------- + + override fun key(): Record1 = super.key() as Record1 + + /** + * Create a detached, initialised UserRecord + */ + constructor(id: Int? = null, createdAt: LocalDateTime? = null, username: String? = null, password: ByteArray? = null): this() { + this.id = id + this.createdAt = createdAt + this.username = username + this.password = password + resetTouchedOnNotNull() + } +} diff --git a/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/tables/references/Tables.kt b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/tables/references/Tables.kt new file mode 100644 index 0000000..89472a7 --- /dev/null +++ b/server.login/src/main/jooq/de/fiereu/openmmo/server/login/jooq/tables/references/Tables.kt @@ -0,0 +1,15 @@ +@file:Suppress("warnings") +/* + * This file is generated by jOOQ. + */ +package de.fiereu.openmmo.server.login.jooq.tables.references + + +import de.fiereu.openmmo.server.login.jooq.tables.User + + + +/** + * The table public.user. + */ +val USER: User = User.USER diff --git a/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/LoginServer.kt b/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/LoginServer.kt new file mode 100644 index 0000000..452f805 --- /dev/null +++ b/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/LoginServer.kt @@ -0,0 +1,31 @@ +package de.fiereu.openmmo.server.login + +import de.fiereu.openmmo.protocols.tls.LoginServerProtocol +import de.fiereu.openmmo.server.ServerBuilder +import de.fiereu.openmmo.server.config.ServerConfig +import de.fiereu.openmmo.server.config.TlsConfig +import de.fiereu.openmmo.server.io.resource +import de.fiereu.openmmo.server.keys.KeyLoader +import de.fiereu.openmmo.server.login.protocol.login.LoginProtocolHandler +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.SupervisorJob + +fun main() { + val serverConfig = ServerConfig( + port = 2106 + ) + val tlsConfig = TlsConfig( + checksumSize = 16 + ) + val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Default) + val server = ServerBuilder.create() + .withCoroutineScope(coroutineScope) + .withConfig(serverConfig) + .withTlsConfig(tlsConfig) + .withPublicKey(KeyLoader.loadPemECPublicKey(resource("game.public.pem"))) + .withPrivateKey(KeyLoader.loadPemECPrivateKey(resource("game.private.pem"))) + .withChannelHandlerProvider { LoginProtocolHandler(LoginServerProtocol(), coroutineScope) } + .build() + server.start() +} \ No newline at end of file diff --git a/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/protocol/login/LoginProtocolHandler.kt b/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/protocol/login/LoginProtocolHandler.kt new file mode 100644 index 0000000..d0d094b --- /dev/null +++ b/server.login/src/main/kotlin/de/fiereu/openmmo/server/login/protocol/login/LoginProtocolHandler.kt @@ -0,0 +1,36 @@ +package de.fiereu.openmmo.server.login.protocol.login + +import de.fiereu.openmmo.protocols.Protocol +import de.fiereu.openmmo.protocols.tls.packets.LoginRequestPacket +import de.fiereu.openmmo.server.netty.handlers.ProtocolHandler +import de.fiereu.openmmo.server.protocol.PacketEvent +import io.github.oshai.kotlinlogging.KotlinLogging +import io.netty.channel.ChannelHandlerContext +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.launch + +private val log = KotlinLogging.logger {} + +class LoginProtocolHandler( + protocol: Protocol, + private val coroutineScope: CoroutineScope, +) : ProtocolHandler(protocol) { + + override fun onActive(ctx: ChannelHandlerContext) { + log.info { "Client ${ctx.channel().remoteAddress()} swapped to login protocol." } + } + + @Suppress("unchecked_cast") // Every cast is personally checked and signed off by me AT RUNTIME :P + override fun onPacketReceived(event: PacketEvent<*>) { + coroutineScope.launch { + when (event.packet) { + is LoginRequestPacket -> onLoginRequest(event as PacketEvent) + else -> log.warn { "Unhandled login packet type: ${event.packet::class.simpleName}" } + } + } + } + + fun onLoginRequest(event: PacketEvent) { + log.info { "Received login request for user '${event.packet.username}'" } + } +} \ No newline at end of file diff --git a/server.login/src/main/resources/application.conf b/server.login/src/main/resources/application.conf new file mode 100644 index 0000000..130b091 --- /dev/null +++ b/server.login/src/main/resources/application.conf @@ -0,0 +1 @@ +server.port = 2106 \ No newline at end of file diff --git a/server.login/src/main/resources/db/migration/V1__init.sql b/server.login/src/main/resources/db/migration/V1__init.sql new file mode 100644 index 0000000..24629c2 --- /dev/null +++ b/server.login/src/main/resources/db/migration/V1__init.sql @@ -0,0 +1,17 @@ +create extension if not exists pgcrypto; + +create table + "user" +( + id serial not null, + created_at timestamp not null default current_timestamp, + username varchar(12) not null unique, -- SHA-1 hash of the password + password bytea not null, + primary key (id) +); + +insert into "user"(username, password) +select 'admin', + digest('admin', 'sha1') +where not exists(select 1 + from "user"); \ No newline at end of file diff --git a/server.login/src/main/resources/logback.xml b/server.login/src/main/resources/logback.xml new file mode 100644 index 0000000..bc29b59 --- /dev/null +++ b/server.login/src/main/resources/logback.xml @@ -0,0 +1,11 @@ + + + + %d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n + + + + + + + \ No newline at end of file diff --git a/server/README.md b/server/README.md new file mode 100644 index 0000000..570d042 --- /dev/null +++ b/server/README.md @@ -0,0 +1,63 @@ +# Server Module + +The server module provides the core server framework for OpenMMO using Netty for networking and protocol handling. + +## Contents + +### Core Classes +- **Server**: Main server class with lifecycle management (start/stop) +- **ServerBuilder**: Builder pattern for server configuration and setup +- **NettyServer**: Netty-based server implementation for async I/O + +### Configuration +- **ServerConfig**: Main server configuration settings +- **TlsConfig**: TLS-specific configuration for secure communication +- **ConfigLoader**: Configuration loading utilities + +### Networking Components +- **ChannelHandlerProvider**: Interface for providing Netty channel handlers +- **DefaultChannelHandlerProvider**: Default implementation of channel handler provider + +### Netty Handlers +- **ProtocolHandler**: Main protocol routing and packet handling +- **PacketFrameDecoder/Encoder**: Packet framing with length prefixing +- **ChecksumFrameDecoder/Encoder**: Packet integrity validation (CRC16 and HMAC-SHA256) +- **TlsDecryptionHandler/TlsEncryptionHandler**: TLS-like encryption/decryption + +### Protocol System +- **TlsContext**: TLS session context management +- **TlsProtocolHandler**: TLS protocol implementation +- **PacketEvent**: Event system for packet processing + +### Cryptography +- **KeyLoader**: Utility for loading ECDSA keys from PEM files +- **Checksum**: Abstraction for packet integrity validation + - **Crc16Checksum**: CRC16 implementation + - **HmacSha256Checksum**: HMAC-SHA256 implementation + +### Dependency Injection +- **ServerComponent**: Dagger component for dependency injection +- **ServerModule**: Dagger module providing server dependencies + +## Features +- Asynchronous networking using Netty +- Custom TLS-like protocol for secure communication +- Packet framing and integrity validation +- Protocol switching (TLS handshake → application protocols) +- ECDSA key management for packet signing/verification +- Configurable coroutine scopes for async operations + +## Dependencies +- Netty for networking +- Dagger 2 for dependency injection +- BouncyCastle for cryptography +- Kotlinx.coroutines for async operations +- Kotlinx.serialization for configuration +- TypeSafe Config for configuration management +- Protocol and Protocol.TLS modules + +## Testing +- Comprehensive unit tests using Kotest +- Integration tests for Netty pipeline components +- TLS handler tests with helper utilities +- MockK for mocking dependencies \ No newline at end of file diff --git a/server/build.gradle.kts b/server/build.gradle.kts new file mode 100644 index 0000000..a3a2035 --- /dev/null +++ b/server/build.gradle.kts @@ -0,0 +1,32 @@ +plugins { + `java-library` + id("buildsrc.convention.kotlin-jvm") + alias(libs.plugins.kotlin.serialization) + alias(libs.plugins.ksp) +} + +group = "de.fiereu.openmmo" + +version = "0.1.0" + +dependencies { + api(libs.typesafe.config) + api(libs.slf4j) + api(libs.kotlin.logging) + api(libs.kotlinx.serialization.core) + api(libs.kotlinx.coroutines) + api(libs.dagger) + api(project(":protocol")) + api(project(":protocol.tls")) + + ksp(libs.dagger.compiler) + + implementation(libs.kotlin.reflect) + implementation(libs.netty) + implementation(libs.kotlinx.serialization.json) + implementation(libs.bundles.crypto) + + testImplementation(libs.bundles.kotest) + testImplementation(libs.kotlinx.coroutines.test) + testImplementation(libs.mockk) +} diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/Server.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/Server.kt new file mode 100644 index 0000000..b16547a --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/Server.kt @@ -0,0 +1,54 @@ +package de.fiereu.openmmo.server + +import de.fiereu.openmmo.server.netty.NettyServer +import io.github.oshai.kotlinlogging.KotlinLogging +import javax.inject.Inject +import javax.inject.Singleton + +private val log = KotlinLogging.logger {} + +@Singleton +class Server @Inject constructor( + private val nettyServer: NettyServer +) { + @Volatile + private var isStarted = false + val isRunning: Boolean + get() = isStarted && nettyServer.isRunning + + fun start() { + if (isStarted) { + log.warn { "Server is already started" } + return + } + + log.info { "Starting server..." } + + try { + nettyServer.start() + isStarted = true + log.info { "Server started successfully" } + } catch (e: Exception) { + log.error(e) { "Failed to start server" } + throw e + } + } + + fun stop() { + if (!isStarted) { + log.warn { "Server is not started" } + return + } + + log.info { "Stopping server..." } + + try { + nettyServer.stop() + isStarted = false + log.info { "Server stopped successfully" } + } catch (e: Exception) { + log.error(e) { "Error during server shutdown" } + throw e + } + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/ServerBuilder.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/ServerBuilder.kt new file mode 100644 index 0000000..0beee8e --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/ServerBuilder.kt @@ -0,0 +1,87 @@ +package de.fiereu.openmmo.server + +import de.fiereu.openmmo.server.config.ServerConfig +import de.fiereu.openmmo.server.config.TlsConfig +import de.fiereu.openmmo.server.di.DaggerServerComponent +import de.fiereu.openmmo.server.di.ServerModule +import de.fiereu.openmmo.server.netty.ChannelHandlerProvider +import de.fiereu.openmmo.server.netty.handlers.ProtocolHandler +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.SupervisorJob +import java.security.interfaces.ECPrivateKey +import java.security.interfaces.ECPublicKey + +class ServerBuilder { + private var coroutineScope: CoroutineScope? = null + private var serverConfig: ServerConfig? = null + private var tlsConfig: TlsConfig? = null + private var privateKey: ECPrivateKey? = null + private var publicKey: ECPublicKey? = null + private var protocolProvider: (() -> ProtocolHandler)? = null + + fun withCoroutineScope(scope: CoroutineScope): ServerBuilder = apply { + this.coroutineScope = scope + } + + fun withConfig(config: ServerConfig): ServerBuilder = apply { + this.serverConfig = config + } + + fun withTlsConfig(tlsConfig: TlsConfig): ServerBuilder = apply { + this.tlsConfig = tlsConfig + } + + fun withPrivateKey(privateKey: ECPrivateKey): ServerBuilder = apply { + this.privateKey = privateKey + } + + fun withPublicKey(publicKey: ECPublicKey): ServerBuilder = apply { + this.publicKey = publicKey + } + + fun withChannelHandlerProvider(provider: () -> ProtocolHandler): ServerBuilder = apply { + this.protocolProvider = provider + } + + fun build(): Server { + val coroutineScope = coroutineScope ?: throw IllegalStateException("CoroutineScope must be provided") + val config = serverConfig ?: throw IllegalStateException("ServerConfig must be provided") + val tlsConfig = tlsConfig ?: throw IllegalStateException("TlsConfig must be provided") + val privKey = privateKey ?: throw IllegalStateException("PrivateKey must be provided") + val pubKey = publicKey ?: throw IllegalStateException("PublicKey must be provided") + val protocolProvider = protocolProvider ?: throw IllegalStateException("ChannelHandlerProvider must be provided") + + val component = DaggerServerComponent.builder() + .serverModule(ServerModule( + coroutineScope, + config, + tlsConfig, + Pair(privKey, pubKey), + protocolProvider + )) + .build() + + return component.server() + } + + companion object { + fun create(): ServerBuilder = ServerBuilder() + + fun create( + config: ServerConfig, + tlsConfig: TlsConfig, + privateKey: ECPrivateKey, + publicKey: ECPublicKey, + handlerProvider: () -> ProtocolHandler + ): Server { + return ServerBuilder() + .withConfig(config) + .withTlsConfig(tlsConfig) + .withPrivateKey(privateKey) + .withPublicKey(publicKey) + .withChannelHandlerProvider(handlerProvider) + .build() + } + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/config/ConfigLoader.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/config/ConfigLoader.kt new file mode 100644 index 0000000..41fe86a --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/config/ConfigLoader.kt @@ -0,0 +1,59 @@ +package de.fiereu.openmmo.server.config + +import com.typesafe.config.Config +import com.typesafe.config.ConfigFactory +import kotlinx.serialization.DeserializationStrategy +import kotlinx.serialization.json.Json +import kotlinx.serialization.json.JsonElement +import kotlinx.serialization.json.buildJsonObject +import kotlinx.serialization.serializer +import kotlin.reflect.typeOf + +object ConfigLoader { + private val json = Json { + ignoreUnknownKeys = true + isLenient = true + } + + @Suppress("UNCHECKED_CAST") + inline fun load(path: String): T { + return load(path, serializer(typeOf()) as DeserializationStrategy) + } + + fun load(path: String, deserializer: DeserializationStrategy): T { + val config = ConfigFactory.load(path) + val jsonElement = configToJsonElement(config.root()) + return json.decodeFromJsonElement(deserializer, jsonElement) + } + + inline fun loadWithDefaults(path: String, defaults: T): T { + return try { + load(path) + } catch (e: Exception) { + defaults + } + } + + private fun configToJsonElement(config: Any?): JsonElement { + return when (config) { + is Config -> buildJsonObject { + config.entrySet().forEach { (key, value) -> + put(key, configToJsonElement(value.unwrapped())) + } + } + is Map<*, *> -> buildJsonObject { + config.forEach { (key, value) -> + put(key.toString(), configToJsonElement(value)) + } + } + is List<*> -> kotlinx.serialization.json.buildJsonArray { + config.forEach { add(configToJsonElement(it)) } + } + is String -> kotlinx.serialization.json.JsonPrimitive(config) + is Number -> kotlinx.serialization.json.JsonPrimitive(config) + is Boolean -> kotlinx.serialization.json.JsonPrimitive(config) + null -> kotlinx.serialization.json.JsonNull + else -> kotlinx.serialization.json.JsonPrimitive(config.toString()) + } + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/config/ServerConfig.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/config/ServerConfig.kt new file mode 100644 index 0000000..daf441b --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/config/ServerConfig.kt @@ -0,0 +1,17 @@ +package de.fiereu.openmmo.server.config + +import kotlinx.serialization.Serializable + +@Serializable +data class ServerConfig( + val host: String = "0.0.0.0", + val port: Int, + val workerThreads: Int = Runtime.getRuntime().availableProcessors(), + val bossThreads: Int = 1, + val tcpNoDelay: Boolean = true, + val keepAlive: Boolean = true, + val soBacklog: Int = 128, + val receiveBufferSize: Int = 65536, + val sendBufferSize: Int = 65536, + val writeTimeoutSeconds: Long = 1500L // 25 minutes default +) \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/config/TlsConfig.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/config/TlsConfig.kt new file mode 100644 index 0000000..8a87d20 --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/config/TlsConfig.kt @@ -0,0 +1,5 @@ +package de.fiereu.openmmo.server.config + +data class TlsConfig( + val checksumSize: Int, +) diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/di/ServerComponent.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/di/ServerComponent.kt new file mode 100644 index 0000000..f116d4d --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/di/ServerComponent.kt @@ -0,0 +1,21 @@ +package de.fiereu.openmmo.server.di + +import dagger.Component +import de.fiereu.openmmo.server.Server +import de.fiereu.openmmo.server.config.ServerConfig +import de.fiereu.openmmo.server.netty.NettyServer +import javax.inject.Singleton + +@Singleton +@Component(modules = [ServerModule::class]) +interface ServerComponent { + fun server(): Server + fun nettyServer(): NettyServer + fun serverConfig(): ServerConfig + + @Component.Builder + interface Builder { + fun serverModule(module: ServerModule): Builder + fun build(): ServerComponent + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/di/ServerModule.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/di/ServerModule.kt new file mode 100644 index 0000000..20b3306 --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/di/ServerModule.kt @@ -0,0 +1,64 @@ +package de.fiereu.openmmo.server.di + +import dagger.Module +import dagger.Provides +import de.fiereu.openmmo.protocols.tls.TlsServerProtocol +import de.fiereu.openmmo.server.config.ServerConfig +import de.fiereu.openmmo.server.config.TlsConfig +import de.fiereu.openmmo.server.netty.ChannelHandlerProvider +import de.fiereu.openmmo.server.netty.DefaultChannelHandlerProvider +import de.fiereu.openmmo.server.netty.handlers.ProtocolHandler +import io.netty.channel.EventLoopGroup +import io.netty.channel.MultiThreadIoEventLoopGroup +import io.netty.channel.nio.NioIoHandler +import kotlinx.coroutines.CoroutineScope +import java.security.interfaces.ECPrivateKey +import java.security.interfaces.ECPublicKey +import javax.inject.Named +import javax.inject.Singleton + +@Module +class ServerModule( + private val coroutineScope: CoroutineScope, + private val config: ServerConfig, + private val tlsConfig: TlsConfig, + private val serverKeyPair: Pair, + private val protocolProvider: () -> ProtocolHandler +) { + + @Provides + @Singleton + fun provideServerConfig(): ServerConfig = config + + @Provides + @Singleton + fun provideTlsProtocol(): TlsServerProtocol = TlsServerProtocol( + serverKeyPair + ) + + @Provides + @Singleton + fun provideChannelHandlerProvider( + serverConfig: ServerConfig, + tlsProtocol: TlsServerProtocol + ): ChannelHandlerProvider = DefaultChannelHandlerProvider( + serverConfig, + tlsConfig, + tlsProtocol, + protocolProvider + ) + + @Provides + @Singleton + @Named("boss") + fun provideBossEventLoopGroup(): EventLoopGroup { + return MultiThreadIoEventLoopGroup(config.bossThreads, NioIoHandler.newFactory()) + } + + @Provides + @Singleton + @Named("worker") + fun provideWorkerEventLoopGroup(): EventLoopGroup { + return MultiThreadIoEventLoopGroup(config.workerThreads, NioIoHandler.newFactory()) + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/io/IO.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/io/IO.kt new file mode 100644 index 0000000..1563929 --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/io/IO.kt @@ -0,0 +1,11 @@ +package de.fiereu.openmmo.server.io + +import java.io.FileInputStream +import java.io.InputStream + +fun resource(path: String): InputStream + = Thread.currentThread().contextClassLoader.getResourceAsStream(path) + ?: throw IllegalArgumentException("Resource not found: $path") + +fun file(path: String): InputStream + = FileInputStream(path) \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/keys/KeyLoader.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/keys/KeyLoader.kt new file mode 100644 index 0000000..1da2f44 --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/keys/KeyLoader.kt @@ -0,0 +1,29 @@ +package de.fiereu.openmmo.server.keys + +import io.github.oshai.kotlinlogging.KotlinLogging +import org.bouncycastle.util.io.pem.PemReader +import java.io.InputStream +import java.security.interfaces.ECPublicKey +import java.security.spec.X509EncodedKeySpec + +val log = KotlinLogging.logger {} + +object KeyLoader { + fun loadPemECPublicKey(inputStream: InputStream): ECPublicKey { + PemReader(inputStream.reader()).use { pemReader -> + val pemObject = pemReader.readPemObject() + val keySpec = X509EncodedKeySpec(pemObject.content) + val keyFactory = java.security.KeyFactory.getInstance("EC") + return keyFactory.generatePublic(keySpec) as ECPublicKey + } + } + + fun loadPemECPrivateKey(inputStream: InputStream): java.security.interfaces.ECPrivateKey { + PemReader(inputStream.reader()).use { pemReader -> + val pemObject = pemReader.readPemObject() + val keySpec = java.security.spec.PKCS8EncodedKeySpec(pemObject.content) + val keyFactory = java.security.KeyFactory.getInstance("EC") + return keyFactory.generatePrivate(keySpec) as java.security.interfaces.ECPrivateKey + } + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/netty/ChannelHandlerProvider.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/netty/ChannelHandlerProvider.kt new file mode 100644 index 0000000..0667c94 --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/netty/ChannelHandlerProvider.kt @@ -0,0 +1,17 @@ +package de.fiereu.openmmo.server.netty + +import io.netty.channel.ChannelPipeline + +/** + * Interface for providing channel handlers to be configured in a Netty pipeline. + * Implementations should define how the pipeline is set up with specific handlers. + */ +interface ChannelHandlerProvider { + /** + * Configures the provided [pipeline] with the necessary channel handlers. + * This method should be implemented to add specific handlers to the pipeline. + * + * @param pipeline The [ChannelPipeline] to configure with handlers. + */ + fun configurePipeline(pipeline: ChannelPipeline) +} \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/netty/DefaultChannelHandlerProvider.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/netty/DefaultChannelHandlerProvider.kt new file mode 100644 index 0000000..d8b90f9 --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/netty/DefaultChannelHandlerProvider.kt @@ -0,0 +1,108 @@ +package de.fiereu.openmmo.server.netty + +import de.fiereu.openmmo.protocols.tls.TlsServerProtocol +import de.fiereu.openmmo.server.config.ServerConfig +import de.fiereu.openmmo.server.config.TlsConfig +import de.fiereu.openmmo.server.netty.handlers.ProtocolHandler +import de.fiereu.openmmo.server.netty.handlers.checksum.ChecksumFrameDecoder +import de.fiereu.openmmo.server.netty.handlers.checksum.ChecksumFrameEncoder +import de.fiereu.openmmo.server.netty.handlers.frame.PacketFrameDecoder +import de.fiereu.openmmo.server.netty.handlers.frame.PacketFrameEncoder +import de.fiereu.openmmo.server.netty.handlers.tls.TlsDecryptionHandler +import de.fiereu.openmmo.server.netty.handlers.tls.TlsEncryptionHandler +import de.fiereu.openmmo.server.protocol.tls.NoOpTlsContext +import de.fiereu.openmmo.server.protocol.tls.TlsContext +import de.fiereu.openmmo.server.protocol.tls.TlsProtocolHandler +import de.fiereu.openmmo.server.protocol.tls.checksum.Checksum +import de.fiereu.openmmo.server.protocol.tls.checksum.NoOpChecksum +import io.netty.channel.ChannelHandlerContext +import io.netty.channel.ChannelPipeline +import io.netty.handler.timeout.WriteTimeoutHandler +import java.util.concurrent.TimeUnit + +/** + * Base class for configuring Netty channel handlers in the server. + * Default handlers: + * - Timeout handler (Timeout defined in [ServerConfig]) + * - Packet frame codec + * - Checksum frame codec (initially NoOp, can be switched dynamically) + * - TLS encryption/decryption handlers (initially NoOp, can be switched dynamically) + */ +class DefaultChannelHandlerProvider( + private val serverConfig: ServerConfig, + private val tlsConfig: TlsConfig, + private val tlsProtocol: TlsServerProtocol, + private val protocolProvider: () -> ProtocolHandler, +) : ChannelHandlerProvider { + + override fun configurePipeline(pipeline: ChannelPipeline) { + pipeline.addLast("timeout", WriteTimeoutHandler(serverConfig.writeTimeoutSeconds, TimeUnit.SECONDS)) + + pipeline.addLast("frame-decoder", PacketFrameDecoder()) + pipeline.addLast("frame-encoder", PacketFrameEncoder()) + + pipeline.addLast("checksum-decoder", ChecksumFrameDecoder(NoOpChecksum())) + pipeline.addLast("checksum-encoder", ChecksumFrameEncoder(NoOpChecksum())) + + val tlsContext = NoOpTlsContext() + pipeline.addLast("tls-decryption", TlsDecryptionHandler(tlsContext)) + pipeline.addLast("tls-encryption", TlsEncryptionHandler(tlsContext)) + + + pipeline.addLast("protocol", TlsProtocolHandler(tlsProtocol, tlsConfig, this)) + } + + /** + * Switches the checksum algorithm used in the pipeline. + * + * Will be called from the [TlsProtocolHandler] once the handshake is complete and a checksum algorithm is negotiated. + * + * @param ctx The channel handler context. + * @param newChecksum The new checksum algorithm to use. + */ + fun switchChecksum(ctx: ChannelHandlerContext, newChecksum: Checksum) { + val pipeline = ctx.pipeline() + + if (pipeline.get("checksum-decoder") != null) { + pipeline.replace("checksum-decoder", "checksum-decoder", ChecksumFrameDecoder(newChecksum)) + } + + if (pipeline.get("checksum-encoder") != null) { + pipeline.replace("checksum-encoder", "checksum-encoder", ChecksumFrameEncoder(newChecksum)) + } + } + + /** + * Switches the TLS context used in the pipeline. + * + * Will be called from the [TlsProtocolHandler] once the handshake is complete and a TLS context is established. + * + * @param ctx The channel handler context. + * @param newTlsContext The new TLS context to use. + */ + fun switchTlsContext(ctx: ChannelHandlerContext, newTlsContext: TlsContext) { + val pipeline = ctx.pipeline() + + if (pipeline.get("tls-decryption") != null) { + pipeline.replace("tls-decryption", "tls-decryption", TlsDecryptionHandler(newTlsContext)) + } + + if (pipeline.get("tls-encryption") != null) { + pipeline.replace("tls-encryption", "tls-encryption", TlsEncryptionHandler(newTlsContext)) + } + } + + /** + * Will enable the actual protocol handler after the TLS handshake is complete. + * Initially a [TlsProtocolHandler] is used to handle the handshake. + * Once the handshake is complete, this method replaces it with the actual protocol handler provided by [protocolProvider]. + * + * @param ctx The channel handler context. + */ + fun enableProtocolHandler(ctx: ChannelHandlerContext) { + val pipeline = ctx.pipeline() + if (pipeline.get("protocol") != null) { + pipeline.replace("protocol", "protocol", protocolProvider()) + } + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/netty/NettyServer.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/netty/NettyServer.kt new file mode 100644 index 0000000..325f5a8 --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/netty/NettyServer.kt @@ -0,0 +1,56 @@ +package de.fiereu.openmmo.server.netty + +import de.fiereu.openmmo.server.config.ServerConfig +import io.github.oshai.kotlinlogging.KotlinLogging +import io.netty.bootstrap.ServerBootstrap +import io.netty.channel.ChannelFuture +import io.netty.channel.ChannelInitializer +import io.netty.channel.ChannelOption +import io.netty.channel.EventLoopGroup +import io.netty.channel.socket.SocketChannel +import io.netty.channel.socket.nio.NioServerSocketChannel +import javax.inject.Inject +import javax.inject.Named +import javax.inject.Singleton + +private val log = KotlinLogging.logger {} + +@Singleton +class NettyServer @Inject constructor( + private val config: ServerConfig, + @param:Named("boss") private val bossGroup: EventLoopGroup, + @param:Named("worker") private val workerGroup: EventLoopGroup, + private val channelHandlerProvider: ChannelHandlerProvider +) { + private var channelFuture: ChannelFuture? = null + val isRunning: Boolean + get() = channelFuture?.channel()?.isActive == true + + fun start() { + log.info { "Starting Netty server on ${config.host}:${config.port}" } + val bootstrap = ServerBootstrap() + .group(bossGroup, workerGroup) + .channel(NioServerSocketChannel::class.java) + .childHandler(object : ChannelInitializer() { + override fun initChannel(ch: SocketChannel) { + channelHandlerProvider.configurePipeline(ch.pipeline()) + } + }) + .option(ChannelOption.SO_BACKLOG, config.soBacklog) + .childOption(ChannelOption.SO_KEEPALIVE, config.keepAlive) + .childOption(ChannelOption.TCP_NODELAY, config.tcpNoDelay) + .childOption(ChannelOption.SO_RCVBUF, config.receiveBufferSize) + .childOption(ChannelOption.SO_SNDBUF, config.sendBufferSize) + + channelFuture = bootstrap.bind(config.host, config.port).await() + log.info { "Netty server started and listening on ${config.host}:${config.port}" } + } + + fun stop() { + log.info { "Stopping Netty server" } + channelFuture?.channel()?.close()?.await() + bossGroup.shutdownGracefully().await() + workerGroup.shutdownGracefully().await() + log.info { "Netty server stopped" } + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/ProtocolHandler.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/ProtocolHandler.kt new file mode 100644 index 0000000..ddd2148 --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/ProtocolHandler.kt @@ -0,0 +1,88 @@ +package de.fiereu.openmmo.server.netty.handlers + +import de.fiereu.openmmo.protocols.PacketDirection +import de.fiereu.openmmo.protocols.Protocol +import de.fiereu.openmmo.protocols.getDeserializer +import de.fiereu.openmmo.server.protocol.PacketEvent +import io.github.oshai.kotlinlogging.KotlinLogging +import io.netty.buffer.ByteBuf +import io.netty.channel.ChannelDuplexHandler +import io.netty.channel.ChannelHandlerContext +import io.netty.channel.ChannelPromise + +private val log = KotlinLogging.logger {} + +abstract class ProtocolHandler( + private val protocol: Protocol +) : ChannelDuplexHandler() { + + override fun channelRead(ctx: ChannelHandlerContext, msg: Any) { + if (msg !is ByteBuf) { + log.warn { "Received non-ByteBuf message: ${msg::class.simpleName}" } + return + } + + try { + if (!msg.isReadable) { + log.warn { "Empty packet received" } + return + } + val opcodeValue = msg.readUnsignedByte().toUByte() + + val deserializer = protocol.getDeserializer(opcodeValue) + if (deserializer == null) { + log.warn { "No deserializer found for ${PacketDirection.CLIENT_TO_SERVER} opcode $opcodeValue" } + return + } + + val packetData = deserializer.deserialize(msg) + + /* + We cant call the onPacketReceived function asynchronously directly here, + because the TLS protocol expects a synchronous flow. Meaning that the client already sends the next packet + after the ClientReady packet, so if we would process the ClientReady packet asynchronously, + the next packet would be processed before the ClientReady packet is fully processed. + -> It would be processed by the TLS protocol before and not by the next protocol (e.g. login protocol). + */ + onPacketReceived(PacketEvent(ctx, packetData)) + } catch (e: Exception) { + log.error(e) { "Error processing packet" } + } finally { + msg.release() + } + } + + override fun write( + ctx: ChannelHandlerContext, + msg: Any, + promise: ChannelPromise + ) { + try { + val opcode = protocol.getOpcode(msg::class) + if (opcode == null) { + log.warn { "No opcode found for packet type: ${msg::class.simpleName}" } + return + } + val serializer = protocol.getSerializer(opcode) + if (serializer == null) { + log.warn { "No serializer found for ${PacketDirection.SERVER_TO_CLIENT} opcode $opcode" } + return + } + + val buffer = ctx.alloc().buffer() + buffer.writeByte(opcode.value.toInt()) + serializer.serializeObject(msg, buffer) + + ctx.write(buffer, promise) + } catch (e: Exception) { + log.error(e) { "Error processing packet" } + } + } + + override fun channelActive(ctx: ChannelHandlerContext) { + onActive(ctx) + } + + abstract fun onPacketReceived(event: PacketEvent<*>) + abstract fun onActive(ctx: ChannelHandlerContext) +} \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/checksum/ChecksumFrameDecoder.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/checksum/ChecksumFrameDecoder.kt new file mode 100644 index 0000000..ff4bf04 --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/checksum/ChecksumFrameDecoder.kt @@ -0,0 +1,49 @@ +package de.fiereu.openmmo.server.netty.handlers.checksum + +import de.fiereu.openmmo.server.protocol.tls.checksum.Checksum +import io.github.oshai.kotlinlogging.KotlinLogging +import io.netty.buffer.ByteBuf +import io.netty.channel.ChannelHandlerContext +import io.netty.handler.codec.ByteToMessageDecoder + +private val log = KotlinLogging.logger {} + +class ChecksumFrameDecoder( + private val checksum: Checksum +) : ByteToMessageDecoder() { + + override fun decode(ctx: ChannelHandlerContext, buffer: ByteBuf, out: MutableList) { + // The regular FrameDecoder already handled length field extraction + // We receive the complete packet data here + + if (checksum.size > 0) { + if (buffer.readableBytes() < checksum.size) { + log.warn { "Packet too small for checksum verification" } + return + } + + // Extract checksum from end of packet + val checksumBytes = ByteArray(checksum.size) + buffer.getBytes(buffer.readableBytes() - checksum.size, checksumBytes) + + // Verify checksum (excluding the checksum bytes themselves) + val dataToVerify = buffer.slice(0, buffer.readableBytes() - checksum.size) + if (!checksum.verify(dataToVerify, checksumBytes)) { + log.warn { "Checksum verification failed, dropping packet" } + return + } + + // Remove checksum from packet data and pass it on + // Use slice() instead of readSlice() to avoid modifying the buffer's reader index + val packetWithoutChecksum = buffer.slice(buffer.readerIndex(), buffer.readableBytes() - checksum.size) + out.add(packetWithoutChecksum.retain()) + // Advance the reader index to mark the data as consumed + buffer.readerIndex(buffer.writerIndex()) + } else { // We could use the NoOpChecksum here but this is faster + // No checksum, pass through as-is + out.add(buffer.slice(buffer.readerIndex(), buffer.readableBytes()).retain()) + // Advance the reader index to mark the data as consumed + buffer.readerIndex(buffer.writerIndex()) + } + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/checksum/ChecksumFrameEncoder.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/checksum/ChecksumFrameEncoder.kt new file mode 100644 index 0000000..1602d60 --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/checksum/ChecksumFrameEncoder.kt @@ -0,0 +1,30 @@ +package de.fiereu.openmmo.server.netty.handlers.checksum + +import de.fiereu.openmmo.server.protocol.tls.checksum.Checksum +import io.netty.buffer.ByteBuf +import io.netty.channel.ChannelHandlerContext +import io.netty.handler.codec.MessageToByteEncoder + +class ChecksumFrameEncoder( + private val checksum: Checksum +) : MessageToByteEncoder() { + + override fun encode(ctx: ChannelHandlerContext, msg: ByteBuf, out: ByteBuf) { + val dataLength = msg.readableBytes() + + // Calculate checksum on the original data (before adding length) + val checksumBytes = if (checksum.size > 0) { + checksum.calculate(msg) + } else { + ByteArray(0) + } + + // Write the packet data + out.writeBytes(msg, msg.readerIndex(), dataLength) + + // Append checksum if needed + if (checksumBytes.isNotEmpty()) { + out.writeBytes(checksumBytes) + } + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/frame/PacketFrameDecoder.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/frame/PacketFrameDecoder.kt new file mode 100644 index 0000000..44bf949 --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/frame/PacketFrameDecoder.kt @@ -0,0 +1,14 @@ +package de.fiereu.openmmo.server.netty.handlers.frame + +import io.netty.handler.codec.LengthFieldBasedFrameDecoder +import java.nio.ByteOrder + +class PacketFrameDecoder : LengthFieldBasedFrameDecoder( + ByteOrder.LITTLE_ENDIAN, + UShort.MAX_VALUE.toInt(), + 0, + UShort.SIZE_BYTES, + -UShort.SIZE_BYTES, // Length includes the length field itself, so subtract 2 + UShort.SIZE_BYTES, + false +) \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/frame/PacketFrameEncoder.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/frame/PacketFrameEncoder.kt new file mode 100644 index 0000000..f2eedc5 --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/frame/PacketFrameEncoder.kt @@ -0,0 +1,11 @@ +package de.fiereu.openmmo.server.netty.handlers.frame + +import io.netty.handler.codec.LengthFieldPrepender +import java.nio.ByteOrder + +class PacketFrameEncoder : LengthFieldPrepender( + ByteOrder.LITTLE_ENDIAN, + UShort.SIZE_BYTES, + 0, + true +) \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/tls/TlsDecryptionHandler.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/tls/TlsDecryptionHandler.kt new file mode 100644 index 0000000..04520f3 --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/tls/TlsDecryptionHandler.kt @@ -0,0 +1,25 @@ +package de.fiereu.openmmo.server.netty.handlers.tls + +import de.fiereu.openmmo.server.protocol.tls.TlsContext +import io.netty.buffer.ByteBuf +import io.netty.channel.ChannelHandlerContext +import io.netty.handler.codec.ByteToMessageDecoder + +class TlsDecryptionHandler( + private val tlsContext: TlsContext +) : ByteToMessageDecoder() { + + override fun decode(ctx: ChannelHandlerContext, buffer: ByteBuf, out: MutableList) { + val dataLength = buffer.readableBytes() + if (dataLength == 0) return + + val encryptedBytes = ByteArray(dataLength) + buffer.readBytes(encryptedBytes) + + val decryptedBytes = tlsContext.decrypt(encryptedBytes) + + val decryptedBuffer = ctx.alloc().buffer(decryptedBytes.size) + decryptedBuffer.writeBytes(decryptedBytes) + out.add(decryptedBuffer) + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/tls/TlsEncryptionHandler.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/tls/TlsEncryptionHandler.kt new file mode 100644 index 0000000..2fb2197 --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/netty/handlers/tls/TlsEncryptionHandler.kt @@ -0,0 +1,21 @@ +package de.fiereu.openmmo.server.netty.handlers.tls + +import de.fiereu.openmmo.server.protocol.tls.TlsContext +import io.netty.buffer.ByteBuf +import io.netty.channel.ChannelHandlerContext +import io.netty.handler.codec.MessageToByteEncoder + +class TlsEncryptionHandler( + private val tlsContext: TlsContext +) : MessageToByteEncoder() { + + override fun encode(ctx: ChannelHandlerContext, msg: ByteBuf, out: ByteBuf) { + val dataLength = msg.readableBytes() + val inputBytes = ByteArray(dataLength) + msg.readBytes(inputBytes) + + val encryptedBytes = tlsContext.encrypt(inputBytes) + + out.writeBytes(encryptedBytes) + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/protocol/PacketEvent.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/protocol/PacketEvent.kt new file mode 100644 index 0000000..bb899fc --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/protocol/PacketEvent.kt @@ -0,0 +1,20 @@ +package de.fiereu.openmmo.server.protocol + +import io.github.oshai.kotlinlogging.KotlinLogging +import io.netty.channel.ChannelHandlerContext + +val log = KotlinLogging.logger {} + +data class PacketEvent( + val ctx: ChannelHandlerContext, + val packet: T +) + +fun PacketEvent.disconnect(reason: () -> String = { "No reason provided" }) { + log.info { "Stopping server for client ${ctx.channel().remoteAddress()}: ${reason()}" } + ctx.close() +} + +fun PacketEvent.respond(packet: Any) { + ctx.channel().writeAndFlush(packet) // need to write to channel otherwise the ProtocolHandler will be skipped +} \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/protocol/tls/TlsContext.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/protocol/tls/TlsContext.kt new file mode 100644 index 0000000..b046dc4 --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/protocol/tls/TlsContext.kt @@ -0,0 +1,80 @@ +package de.fiereu.openmmo.server.protocol.tls + +import java.security.MessageDigest +import java.security.PrivateKey +import java.security.PublicKey +import javax.crypto.Cipher +import javax.crypto.KeyAgreement +import javax.crypto.spec.IvParameterSpec +import javax.crypto.spec.SecretKeySpec + +interface TlsContext { + fun encrypt(data: ByteArray): ByteArray + fun decrypt(data: ByteArray): ByteArray +} + +class NoOpTlsContext : TlsContext { + override fun encrypt(data: ByteArray): ByteArray = data + override fun decrypt(data: ByteArray): ByteArray = data +} + +class DefaultTlsContext( + privateKey: PrivateKey, + publicKey: PublicKey +) : TlsContext { + companion object { + private val COMMON_IV = "IVDERIV".toByteArray() + private val CLIENT_KEY_SALT = "KeySalt".toByteArray() + byteArrayOf(1) + private val SERVER_KEY_SALT = "KeySalt".toByteArray() + byteArrayOf(2) + } + + private var clientSeed = byteArrayOf(63, 24, -15, 98, 114, 7, 68, 24, -12, 109, -111, -105, 66, -96, -2, -55) + private var serverSeed = byteArrayOf(31, -102, -128, 60, -103, 38, 10, -117, -105, -50, 2, 116, -83, 57, 39, -76) + + private val encryptionCipher: Cipher // Server to client + private val decryptionCipher: Cipher // Client to server + + fun getClientSeed(): ByteArray = clientSeed.copyOf() + + init { + val sharedSecret = performKeyAgreement(privateKey, publicKey) + + if (sharedSecret.size * 8 >= 128) { + clientSeed = tripleHash(sharedSecret, CLIENT_KEY_SALT) + serverSeed = tripleHash(sharedSecret, SERVER_KEY_SALT) + } + + encryptionCipher = createCipher(Cipher.ENCRYPT_MODE, serverSeed) // Server encrypts outgoing + decryptionCipher = createCipher(Cipher.DECRYPT_MODE, clientSeed) // Server decrypts incoming + } + + private fun performKeyAgreement(privateKey: PrivateKey, publicKey: PublicKey): ByteArray { + val keyAgreement = KeyAgreement.getInstance("ECDH") + keyAgreement.init(privateKey) + keyAgreement.doPhase(publicKey, true) + return keyAgreement.generateSecret() + } + + private fun tripleHash(data1: ByteArray, data2: ByteArray): ByteArray { + val sha256 = MessageDigest.getInstance("SHA-256") + sha256.update(data2) + sha256.update(data1) + sha256.update(data2) + val digest = sha256.digest() + return digest.copyOfRange(0, 16) + } + + private fun createCipher(mode: Int, seed: ByteArray): Cipher { + val cipher = Cipher.getInstance("AES/CTR/NoPadding") + val key = SecretKeySpec(seed, "AES") + val iv = IvParameterSpec(tripleHash(seed, COMMON_IV)) + cipher.init(mode, key, iv) + return cipher + } + + override fun encrypt(data: ByteArray): ByteArray = + encryptionCipher.update(data) + + override fun decrypt(data: ByteArray): ByteArray = + decryptionCipher.update(data) +} \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/protocol/tls/TlsProtocolHandler.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/protocol/tls/TlsProtocolHandler.kt new file mode 100644 index 0000000..6ef725f --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/protocol/tls/TlsProtocolHandler.kt @@ -0,0 +1,75 @@ +package de.fiereu.openmmo.server.protocol.tls + +import de.fiereu.openmmo.protocols.Protocol +import de.fiereu.openmmo.protocols.tls.packets.ClientHelloPacket +import de.fiereu.openmmo.protocols.tls.packets.ClientReadyPacket +import de.fiereu.openmmo.protocols.tls.packets.ServerHelloPacket +import de.fiereu.openmmo.server.config.TlsConfig +import de.fiereu.openmmo.server.netty.DefaultChannelHandlerProvider +import de.fiereu.openmmo.server.netty.handlers.ProtocolHandler +import de.fiereu.openmmo.server.protocol.PacketEvent +import de.fiereu.openmmo.server.protocol.disconnect +import de.fiereu.openmmo.server.protocol.respond +import de.fiereu.openmmo.server.protocol.tls.checksum.ChecksumFactory +import io.github.oshai.kotlinlogging.KotlinLogging +import io.netty.buffer.ByteBuf +import io.netty.channel.ChannelHandlerContext +import java.security.KeyPairGenerator +import java.security.interfaces.ECPrivateKey +import java.security.interfaces.ECPublicKey +import java.security.spec.ECGenParameterSpec + +private val log = KotlinLogging.logger {} + +class TlsProtocolHandler( + protocol: Protocol, + private val tlsConfig: TlsConfig, + private val channelHandlerProvider: DefaultChannelHandlerProvider +) : ProtocolHandler(protocol) { + + private val packetBuffer: MutableList = mutableListOf() + private val connectionKeyPair: Pair + + init { + val keyPairGenerator = KeyPairGenerator.getInstance("EC") + keyPairGenerator.initialize(ECGenParameterSpec("secp256r1")) + keyPairGenerator.generateKeyPair().let { + connectionKeyPair = Pair(it.public as ECPublicKey, it.private as ECPrivateKey) + } + } + + @Suppress("unchecked_cast") // The cast is in fact checked :D + override fun onPacketReceived(event: PacketEvent<*>) { + when (val packet = event.packet) { + is ClientHelloPacket -> onClientHello(event as PacketEvent) + is ClientReadyPacket -> onClientReady(event as PacketEvent) + else -> log.warn { "Unhandled TLS packet type: ${packet::class.simpleName}" } + } + } + + override fun onActive(ctx: ChannelHandlerContext) { + log.info { "New client connected: ${ctx.channel().remoteAddress()}" } + } + + fun onClientHello(event: PacketEvent) { + if (System.currentTimeMillis() - event.packet.timestamp > 10_000) { // 10 seconds is arbitrary + event.disconnect { "Received stale ClientHello packet" } + return + } + + event.respond(ServerHelloPacket(connectionKeyPair.first, tlsConfig.checksumSize)) + } + + fun onClientReady(event: PacketEvent) { + val tlsContext = DefaultTlsContext( + connectionKeyPair.second, + event.packet.clientPublicKey + ) + val checksum = ChecksumFactory.create(tlsConfig.checksumSize, tlsContext.getClientSeed()) + + channelHandlerProvider.switchChecksum(event.ctx, checksum) + channelHandlerProvider.switchTlsContext(event.ctx, tlsContext) + channelHandlerProvider.enableProtocolHandler(event.ctx) + log.info { "Client ${event.ctx.channel().remoteAddress()} completed TLS handshake. Switching to next protocol." } + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/protocol/tls/checksum/Checksum.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/protocol/tls/checksum/Checksum.kt new file mode 100644 index 0000000..f9c3245 --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/protocol/tls/checksum/Checksum.kt @@ -0,0 +1,33 @@ +package de.fiereu.openmmo.server.protocol.tls.checksum + +import io.netty.buffer.ByteBuf + +interface Checksum { + val size: Int + + fun calculate(data: ByteBuf): ByteArray + fun verify(data: ByteBuf, expectedChecksum: ByteArray): Boolean +} + +class NoOpChecksum : Checksum { + override val size: Int = 0 + + override fun calculate(data: ByteBuf): ByteArray = ByteArray(0) + + override fun verify(data: ByteBuf, expectedChecksum: ByteArray): Boolean = true +} + +object ChecksumFactory { + fun create(checksumSize: Int): Checksum { + return create(checksumSize, ByteArray(0)) + } + + fun create(checksumSize: Int, key: ByteArray): Checksum { + return when (checksumSize) { + 0 -> NoOpChecksum() + 2 -> Crc16Checksum() + in 4..32 -> HmacSha256Checksum(checksumSize, key) + else -> throw IllegalArgumentException("Unsupported checksum size: $checksumSize") + } + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/protocol/tls/checksum/Crc16Checksum.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/protocol/tls/checksum/Crc16Checksum.kt new file mode 100644 index 0000000..d424f51 --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/protocol/tls/checksum/Crc16Checksum.kt @@ -0,0 +1,70 @@ +package de.fiereu.openmmo.server.protocol.tls.checksum + +import io.netty.buffer.ByteBuf + +class Crc16Checksum : Checksum { + override val size: Int = 2 + + companion object { + private val table = intArrayOf( + 0x0000, 0xc0c1, 0xc181, 0x0140, 0xc301, 0x03c0, 0x0280, 0xc241, + 0xc601, 0x06c0, 0x0780, 0xc741, 0x0500, 0xc5c1, 0xc481, 0x0440, + 0xcc01, 0x0cc0, 0x0d80, 0xcd41, 0x0f00, 0xcfc1, 0xce81, 0x0e40, + 0x0a00, 0xcac1, 0xcb81, 0x0b40, 0xc901, 0x09c0, 0x0880, 0xc841, + 0xd801, 0x18c0, 0x1980, 0xd941, 0x1b00, 0xdbc1, 0xda81, 0x1a40, + 0x1e00, 0xdec1, 0xdf81, 0x1f40, 0xdd01, 0x1dc0, 0x1c80, 0xdc41, + 0x1400, 0xd4c1, 0xd581, 0x1540, 0xd701, 0x17c0, 0x1680, 0xd641, + 0xd201, 0x12c0, 0x1380, 0xd341, 0x1100, 0xd1c1, 0xd081, 0x1040, + 0xf001, 0x30c0, 0x3180, 0xf141, 0x3300, 0xf3c1, 0xf281, 0x3240, + 0x3600, 0xf6c1, 0xf781, 0x3740, 0xf501, 0x35c0, 0x3480, 0xf441, + 0x3c00, 0xfcc1, 0xfd81, 0x3d40, 0xff01, 0x3fc0, 0x3e80, 0xfe41, + 0xfa01, 0x3ac0, 0x3b80, 0xfb41, 0x3900, 0xf9c1, 0xf881, 0x3840, + 0x2800, 0xe8c1, 0xe981, 0x2940, 0xeb01, 0x2bc0, 0x2a80, 0xea41, + 0xee01, 0x2ec0, 0x2f80, 0xef41, 0x2d00, 0xedc1, 0xec81, 0x2c40, + 0xe401, 0x24c0, 0x2580, 0xe541, 0x2700, 0xe7c1, 0xe681, 0x2640, + 0x2200, 0xe2c1, 0xe381, 0x2340, 0xe101, 0x21c0, 0x2080, 0xe041, + 0xa001, 0x60c0, 0x6180, 0xa141, 0x6300, 0xa3c1, 0xa281, 0x6240, + 0x6600, 0xa6c1, 0xa781, 0x6740, 0xa501, 0x65c0, 0x6480, 0xa441, + 0x6c00, 0xacc1, 0xad81, 0x6d40, 0xaf01, 0x6fc0, 0x6e80, 0xae41, + 0xaa01, 0x6ac0, 0x6b80, 0xab41, 0x6900, 0xa9c1, 0xa881, 0x6840, + 0x7800, 0xb8c1, 0xb981, 0x7940, 0xbb01, 0x7bc0, 0x7a80, 0xba41, + 0xbe01, 0x7ec0, 0x7f80, 0xbf41, 0x7d00, 0xbdc1, 0xbc81, 0x7c40, + 0xb401, 0x74c0, 0x7580, 0xb541, 0x7700, 0xb7c1, 0xb681, 0x7640, + 0x7200, 0xb2c1, 0xb381, 0x7340, 0xb101, 0x71c0, 0x7080, 0xb041, + 0x5000, 0x90c1, 0x9181, 0x5140, 0x9301, 0x53c0, 0x5280, 0x9241, + 0x9601, 0x56c0, 0x5780, 0x9741, 0x5500, 0x95c1, 0x9481, 0x5440, + 0x9c01, 0x5cc0, 0x5d80, 0x9d41, 0x5f00, 0x9fc1, 0x9e81, 0x5e40, + 0x5a00, 0x9ac1, 0x9b81, 0x5b40, 0x9901, 0x59c0, 0x5880, 0x9841, + 0x8801, 0x48c0, 0x4980, 0x8941, 0x4b00, 0x8bc1, 0x8a81, 0x4a40, + 0x4e00, 0x8ec1, 0x8f81, 0x4f40, 0x8d01, 0x4dc0, 0x4c80, 0x8c41, + 0x4400, 0x84c1, 0x8581, 0x4540, 0x8701, 0x47c0, 0x4680, 0x8641, + 0x8201, 0x42c0, 0x4380, 0x8341, 0x4100, 0x81c1, 0x8081, 0x4040 + ) + } + + override fun calculate(data: ByteBuf): ByteArray { + val sum = hash(data) + return byteArrayOf((sum and 0xff).toByte(), ((sum shr 8) and 0xff).toByte()) + } + + override fun verify(data: ByteBuf, expectedChecksum: ByteArray): Boolean { + if (expectedChecksum.size != 2) return false + + val calculatedSum = hash(data) + val expectedSum = ((expectedChecksum[1].toInt() and 0xff) shl 8) or (expectedChecksum[0].toInt() and 0xff) + + return calculatedSum == expectedSum + } + + private fun hash(data: ByteBuf): Int { + var sum = 0 + val readerIndex = data.readerIndex() + + for (i in readerIndex until data.writerIndex()) { + val b = data.getByte(i) + sum = (sum ushr 8) xor table[(sum xor (b.toInt() and 0xff)) and 0xff] + } + + return (sum and 0xffff) + } +} \ No newline at end of file diff --git a/server/src/main/kotlin/de/fiereu/openmmo/server/protocol/tls/checksum/HmacSha256Checksum.kt b/server/src/main/kotlin/de/fiereu/openmmo/server/protocol/tls/checksum/HmacSha256Checksum.kt new file mode 100644 index 0000000..a3eabb2 --- /dev/null +++ b/server/src/main/kotlin/de/fiereu/openmmo/server/protocol/tls/checksum/HmacSha256Checksum.kt @@ -0,0 +1,63 @@ +package de.fiereu.openmmo.server.protocol.tls.checksum + +import io.netty.buffer.ByteBuf +import java.security.MessageDigest +import javax.crypto.Mac +import javax.crypto.spec.SecretKeySpec + +class HmacSha256Checksum( + override val size: Int, + key: ByteArray +) : Checksum { + + private val mac: Mac + private var hashRound = 0 + private var verifyRound = 0 + + init { + require(size in 4..32) { "HMAC-SHA256 size must be between 4 and 32 bytes" } + + mac = Mac.getInstance("HmacSHA256") + mac.init(SecretKeySpec(key, "HmacSHA256")) + } + + override fun calculate(data: ByteBuf): ByteArray { + // Read data without modifying the buffer's reader index + val dataBytes = ByteArray(data.readableBytes()) + data.getBytes(data.readerIndex(), dataBytes) + + mac.update(dataBytes) + mac.update(getBytes(hashRound++)) + val result = mac.doFinal() + return result.copyOfRange(0, size) + } + + override fun verify(data: ByteBuf, expectedChecksum: ByteArray): Boolean { + if (expectedChecksum.size != size) return false + + // Read data without modifying the buffer's reader index + val dataBytes = ByteArray(data.readableBytes()) + data.getBytes(data.readerIndex(), dataBytes) + + mac.update(dataBytes) + mac.update(getBytes(verifyRound++)) + val result = mac.doFinal() + val actualChecksum = result.copyOfRange(0, size) + + return MessageDigest.isEqual(actualChecksum, expectedChecksum) + } + + /** + * Convert an integer to a big endian byte array. + * @param value The integer to convert. + * @return The big endian byte array. + */ + private fun getBytes(value: Int): ByteArray { + return byteArrayOf( + ((value shr 24) and 0xFF).toByte(), + ((value shr 16) and 0xFF).toByte(), + ((value shr 8) and 0xFF).toByte(), + (value and 0xFF).toByte() + ) + } +} \ No newline at end of file diff --git a/server/src/test/kotlin/de/fiereu/openmmo/server/netty/ChannelExt.kt b/server/src/test/kotlin/de/fiereu/openmmo/server/netty/ChannelExt.kt new file mode 100644 index 0000000..a2644a1 --- /dev/null +++ b/server/src/test/kotlin/de/fiereu/openmmo/server/netty/ChannelExt.kt @@ -0,0 +1,29 @@ +package de.fiereu.openmmo.server.netty + +import io.netty.buffer.ByteBuf +import io.netty.buffer.Unpooled +import io.netty.channel.embedded.EmbeddedChannel + +fun EmbeddedChannel.readAllOutbound(): ByteBuf { + val encoded = Unpooled.buffer() + var buf: ByteBuf? + while (true) { + buf = this.readOutbound() + if (buf == null) break + encoded.writeBytes(buf) + buf.release() + } + return encoded +} + +fun EmbeddedChannel.readAllInbound(): ByteBuf { + val encoded = Unpooled.buffer() + var buf: ByteBuf? + while (true) { + buf = this.readInbound() + if (buf == null) break + encoded.writeBytes(buf) + buf.release() + } + return encoded +} \ No newline at end of file diff --git a/server/src/test/kotlin/de/fiereu/openmmo/server/netty/ChecksumFrameCodecTest.kt b/server/src/test/kotlin/de/fiereu/openmmo/server/netty/ChecksumFrameCodecTest.kt new file mode 100644 index 0000000..1d49ad4 --- /dev/null +++ b/server/src/test/kotlin/de/fiereu/openmmo/server/netty/ChecksumFrameCodecTest.kt @@ -0,0 +1,340 @@ +package de.fiereu.openmmo.server.netty + +import de.fiereu.openmmo.server.protocol.tls.checksum.ChecksumFactory +import de.fiereu.openmmo.server.protocol.tls.checksum.Crc16Checksum +import de.fiereu.openmmo.server.protocol.tls.checksum.HmacSha256Checksum +import de.fiereu.openmmo.server.protocol.tls.checksum.NoOpChecksum +import de.fiereu.openmmo.server.netty.handlers.checksum.ChecksumFrameDecoder +import de.fiereu.openmmo.server.netty.handlers.checksum.ChecksumFrameEncoder +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe +import io.netty.buffer.ByteBuf +import io.netty.buffer.Unpooled +import io.netty.channel.embedded.EmbeddedChannel + +class ChecksumFrameCodecTest : FunSpec({ + + test("NoOpChecksum - encoder should not add checksum") { + val checksum = NoOpChecksum() + val encoder = ChecksumFrameEncoder(checksum) + val channel = EmbeddedChannel(encoder) + + val payload = Unpooled.buffer() + .writeByte(0xAB) + .writeByte(0xCD) + + channel.writeOutbound(payload) + + val encoded = channel.readAllOutbound() + encoded.readableBytes() shouldBe 2 // 2 bytes payload (no checksum) + + // Check payload + encoded.readByte() shouldBe 0xAB.toByte() + encoded.readByte() shouldBe 0xCD.toByte() + + encoded.release() + channel.close() + } + + test("NoOpChecksum - decoder should pass through without verification") { + val checksum = NoOpChecksum() + val decoder = ChecksumFrameDecoder(checksum) + val channel = EmbeddedChannel(decoder) + + val input = Unpooled.buffer() + .writeByte(0xAB) + .writeByte(0xCD) + + channel.writeInbound(input) + + val decoded = channel.readAllInbound() + decoded.readableBytes() shouldBe 2 + decoded.readByte() shouldBe 0xAB.toByte() + decoded.readByte() shouldBe 0xCD.toByte() + + decoded.release() + channel.close() + } + + test("CRC16 - encoder should append 2-byte checksum") { + val checksum = Crc16Checksum() + val encoder = ChecksumFrameEncoder(checksum) + val channel = EmbeddedChannel(encoder) + + val payload = Unpooled.buffer() + .writeByte(0xAB) + .writeByte(0xCD) + + channel.writeOutbound(payload) + + val encoded = channel.readAllOutbound() + encoded.readableBytes() shouldBe 4 // 2 bytes payload + 2 bytes CRC16 + + // Check payload + encoded.readByte() shouldBe 0xAB.toByte() + encoded.readByte() shouldBe 0xCD.toByte() + + // Check that checksum bytes are present (we don't verify exact values here) + encoded.readableBytes() shouldBe 2 // Should have 2 checksum bytes left + + encoded.release() + channel.close() + } + + test("CRC16 - decoder should verify and remove checksum") { + val checksum = Crc16Checksum() + val decoder = ChecksumFrameDecoder(checksum) + val channel = EmbeddedChannel(decoder) + + // Create data and calculate its checksum + val originalData = Unpooled.buffer() + .writeByte(0xAB) + .writeByte(0xCD) + + val checksumBytes = checksum.calculate(originalData) + + // Create input with data + checksum + val input = Unpooled.buffer() + .writeByte(0xAB) + .writeByte(0xCD) + .writeBytes(checksumBytes) + + channel.writeInbound(input) + + val decoded = channel.readAllInbound() + decoded.readableBytes() shouldBe 2 // Checksum should be removed + decoded.readByte() shouldBe 0xAB.toByte() + decoded.readByte() shouldBe 0xCD.toByte() + + originalData.release() + decoded.release() + channel.close() + } + + test("CRC16 - decoder should drop packet with invalid checksum") { + val checksum = Crc16Checksum() + val decoder = ChecksumFrameDecoder(checksum) + val channel = EmbeddedChannel(decoder) + + // Create input with data + invalid checksum + val input = Unpooled.buffer() + .writeByte(0xAB) + .writeByte(0xCD) + .writeByte(0xFF) // Invalid checksum + .writeByte(0xFF) + + channel.writeInbound(input) + + // Should not produce any output due to checksum failure + channel.readInbound() shouldBe null + + channel.close() + } + + test("HMAC-SHA256 - encoder should append variable-size checksum") { + val key = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08) + val checksum = HmacSha256Checksum(8, key) // 8-byte HMAC + val encoder = ChecksumFrameEncoder(checksum) + val channel = EmbeddedChannel(encoder) + + val payload = Unpooled.buffer() + .writeByte(0xAB) + .writeByte(0xCD) + + channel.writeOutbound(payload) + + val encoded = channel.readAllOutbound() + encoded.readableBytes() shouldBe 10 // 2 bytes payload + 8 bytes HMAC + + // Check payload + encoded.readByte() shouldBe 0xAB.toByte() + encoded.readByte() shouldBe 0xCD.toByte() + + // Check that HMAC bytes are present + encoded.readableBytes() shouldBe 8 // Should have 8 HMAC bytes left + + encoded.release() + channel.close() + } + + test("HMAC-SHA256 - decoder should verify and remove checksum") { + val key = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08) + val checksum = HmacSha256Checksum(4, key) // 4-byte HMAC + val decoder = ChecksumFrameDecoder(checksum) + val channel = EmbeddedChannel(decoder) + + // Create data and calculate its checksum + val originalData = Unpooled.buffer() + .writeByte(0xAB) + .writeByte(0xCD) + + val checksumBytes = checksum.calculate(originalData) + + // Create input with data + checksum + val input = Unpooled.buffer() + .writeByte(0xAB) + .writeByte(0xCD) + .writeBytes(checksumBytes) + + channel.writeInbound(input) + + val decoded = channel.readAllInbound() + decoded.readableBytes() shouldBe 2 // Checksum should be removed + decoded.readByte() shouldBe 0xAB.toByte() + decoded.readByte() shouldBe 0xCD.toByte() + + originalData.release() + decoded.release() + channel.close() + } + + test("HMAC-SHA256 - decoder should drop packet with invalid checksum") { + val key = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08) + val checksum = HmacSha256Checksum(4, key) + val decoder = ChecksumFrameDecoder(checksum) + val channel = EmbeddedChannel(decoder) + + // Create input with data + invalid checksum + val input = Unpooled.buffer() + .writeByte(0xAB) + .writeByte(0xCD) + .writeByte(0xFF) // Invalid checksum + .writeByte(0xFF) + .writeByte(0xFF) + .writeByte(0xFF) + + channel.writeInbound(input) + + // Should not produce any output due to checksum failure + channel.readInbound() shouldBe null + + channel.close() + } + + test("roundtrip - NoOpChecksum encoding and decoding") { + val checksum = NoOpChecksum() + val encoder = ChecksumFrameEncoder(checksum) + val decoder = ChecksumFrameDecoder(checksum) + val channel = EmbeddedChannel(encoder, decoder) + + val originalPayload = byteArrayOf(0xDE.toByte(), 0xAD.toByte(), 0xBE.toByte(), 0xEF.toByte()) + val input = Unpooled.buffer().writeBytes(originalPayload) + + // Encode then decode + channel.writeOutbound(input) shouldBe true + val encoded = channel.readAllOutbound() + + channel.writeInbound(encoded) shouldBe true + val decoded = channel.readAllInbound() + + decoded.readableBytes() shouldBe originalPayload.size + for (expectedByte in originalPayload) { + decoded.readByte() shouldBe expectedByte + } + + decoded.release() + channel.close() + } + + test("roundtrip - CRC16 encoding and decoding") { + val encoderChecksum = Crc16Checksum() + val decoderChecksum = Crc16Checksum() + val encoder = ChecksumFrameEncoder(encoderChecksum) + val decoder = ChecksumFrameDecoder(decoderChecksum) + + val originalPayload = byteArrayOf(0xDE.toByte(), 0xAD.toByte(), 0xBE.toByte(), 0xEF.toByte()) + val input = Unpooled.buffer().writeBytes(originalPayload) + + // Encode + val encoderChannel = EmbeddedChannel(encoder) + encoderChannel.writeOutbound(input) shouldBe true + val encoded = encoderChannel.readAllOutbound() + + encoded.readableBytes() shouldBe 6 // 4 bytes payload + 2 bytes CRC16 + + // Decode + val decoderChannel = EmbeddedChannel(decoder) + decoderChannel.writeInbound(encoded) shouldBe true + val decoded = decoderChannel.readAllInbound() + + decoded.readableBytes() shouldBe originalPayload.size + for (expectedByte in originalPayload) { + decoded.readByte() shouldBe expectedByte + } + + decoded.release() + encoderChannel.close() + decoderChannel.close() + } + + test("roundtrip - HMAC-SHA256 encoding and decoding") { + val key = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08) + val encoderChecksum = HmacSha256Checksum(16, key) + val decoderChecksum = HmacSha256Checksum(16, key) + val encoder = ChecksumFrameEncoder(encoderChecksum) + val decoder = ChecksumFrameDecoder(decoderChecksum) + + val originalPayload = byteArrayOf(0xDE.toByte(), 0xAD.toByte(), 0xBE.toByte(), 0xEF.toByte()) + val input = Unpooled.buffer().writeBytes(originalPayload) + + // Encode + val encoderChannel = EmbeddedChannel(encoder) + encoderChannel.writeOutbound(input) shouldBe true + val encoded = encoderChannel.readAllOutbound() + + encoded.readableBytes() shouldBe 20 // 4 bytes payload + 16 bytes HMAC + + // Decode + val decoderChannel = EmbeddedChannel(decoder) + decoderChannel.writeInbound(encoded) shouldBe true + val decoded = decoderChannel.readAllInbound() + + decoded.readableBytes() shouldBe originalPayload.size + for (expectedByte in originalPayload) { + decoded.readByte() shouldBe expectedByte + } + + decoded.release() + encoderChannel.close() + decoderChannel.close() + } + + test("decoder should handle packet too small for checksum") { + val checksum = Crc16Checksum() + val decoder = ChecksumFrameDecoder(checksum) + val channel = EmbeddedChannel(decoder) + + // Send packet smaller than checksum size + val input = Unpooled.buffer() + .writeByte(0xAB) // Only 1 byte, but CRC16 needs 2 bytes + + channel.writeInbound(input) + + // Should not produce any output + channel.readInbound() shouldBe null + + channel.close() + } + + test("ChecksumFactory - create with size only") { + val noOpChecksum = ChecksumFactory.create(0) + (noOpChecksum is NoOpChecksum) shouldBe true + + val crc16Checksum = ChecksumFactory.create(2) + (crc16Checksum is Crc16Checksum) shouldBe true + } + + test("ChecksumFactory - create with size and key") { + val key = byteArrayOf(0x01, 0x02, 0x03, 0x04) + + val noOpChecksum = ChecksumFactory.create(0, key) + (noOpChecksum is NoOpChecksum) shouldBe true + + val crc16Checksum = ChecksumFactory.create(2, key) + (crc16Checksum is Crc16Checksum) shouldBe true + + val hmacChecksum = ChecksumFactory.create(8, key) + (hmacChecksum is HmacSha256Checksum) shouldBe true + hmacChecksum.size shouldBe 8 + } +}) \ No newline at end of file diff --git a/server/src/test/kotlin/de/fiereu/openmmo/server/netty/PacketFrameCodecTest.kt b/server/src/test/kotlin/de/fiereu/openmmo/server/netty/PacketFrameCodecTest.kt new file mode 100644 index 0000000..e829ec4 --- /dev/null +++ b/server/src/test/kotlin/de/fiereu/openmmo/server/netty/PacketFrameCodecTest.kt @@ -0,0 +1,179 @@ +package de.fiereu.openmmo.server.netty + +import de.fiereu.openmmo.server.netty.handlers.frame.PacketFrameDecoder +import de.fiereu.openmmo.server.netty.handlers.frame.PacketFrameEncoder +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe +import io.kotest.matchers.nulls.shouldBeNull +import io.netty.buffer.ByteBuf +import io.netty.buffer.Unpooled +import io.netty.channel.embedded.EmbeddedChannel + +class PacketFrameCodecTest : FunSpec({ + + test("decoder should decode frame with correct length prefix") { + val decoder = PacketFrameDecoder() + val channel = EmbeddedChannel(decoder) + + // Create input: length 4 (0x0004) + payload [0xAB, 0xCD] + // Length field includes itself (2 bytes) + payload (2 bytes) = 4 total + val input = Unpooled.buffer() + .writeShortLE(4) // Length field (little endian) + .writeByte(0xAB) + .writeByte(0xCD) + + channel.writeInbound(input) + + val decoded = channel.readAllInbound() + decoded.readableBytes() shouldBe 2 + decoded.readByte() shouldBe 0xAB.toByte() + decoded.readByte() shouldBe 0xCD.toByte() + + decoded.release() + channel.close() + } + + test("decoder should handle empty payload") { + val decoder = PacketFrameDecoder() + val channel = EmbeddedChannel(decoder) + + // Create input: length 2 (only the length field itself) + val input = Unpooled.buffer() + .writeShortLE(2) // Length field (little endian) + + channel.writeInbound(input) + + val decoded = channel.readAllInbound() + decoded.readableBytes() shouldBe 0 + + decoded.release() + channel.close() + } + + test("decoder should handle larger payload") { + val decoder = PacketFrameDecoder() + val channel = EmbeddedChannel(decoder) + + val payload = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05) + val input = Unpooled.buffer() + .writeShortLE(payload.size + 2) // Length includes length field + .writeBytes(payload) + + channel.writeInbound(input) + + val decoded = channel.readAllInbound() + decoded.readableBytes() shouldBe payload.size + for (expectedByte in payload) { + decoded.readByte() shouldBe expectedByte + } + + decoded.release() + channel.close() + } + + test("decoder should not decode incomplete frame") { + val decoder = PacketFrameDecoder() + val channel = EmbeddedChannel(decoder) + + // Send only the length field without payload + val input = Unpooled.buffer() + .writeShortLE(10) // Claims 10 bytes total but we only send 2 + + channel.writeInbound(input) + + val decoded = channel.readInbound() + decoded.shouldBeNull() + + channel.close() + } + + test("encoder should prepend correct length field") { + val encoder = PacketFrameEncoder() + val channel = EmbeddedChannel(encoder) + + val payload = Unpooled.buffer() + .writeByte(0xAB) + .writeByte(0xCD) + + channel.writeOutbound(payload) + + val encoded = channel.readAllOutbound() + encoded.readableBytes() shouldBe 4 + + // Check length field (should be 4: 2 bytes length + 2 bytes payload) + encoded.readUnsignedShortLE() shouldBe 4 + + // Check payload + encoded.readByte() shouldBe 0xAB.toByte() + encoded.readByte() shouldBe 0xCD.toByte() + + encoded.release() + channel.close() + } + + test("encoder should handle empty payload") { + val encoder = PacketFrameEncoder() + val channel = EmbeddedChannel(encoder) + + val payload = Unpooled.buffer() + + channel.writeOutbound(payload) + + val encoded = channel.readAllOutbound() + encoded.readableBytes() shouldBe 2 + + // Check length field (should be 2: only the length field) + encoded.readUnsignedShortLE() shouldBe 2 + + encoded.release() + channel.close() + } + + test("encoder should handle larger payload") { + val encoder = PacketFrameEncoder() + val channel = EmbeddedChannel(encoder) + + val payloadData = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05) + val payload = Unpooled.buffer().writeBytes(payloadData) + + channel.writeOutbound(payload) + + val encoded = channel.readAllOutbound() + encoded.readableBytes() shouldBe (payloadData.size + 2) + + // Check length field + encoded.readUnsignedShortLE() shouldBe (payloadData.size + 2) + + // Check payload + for (expectedByte in payloadData) { + encoded.readByte() shouldBe expectedByte + } + + encoded.release() + channel.close() + } + + test("roundtrip encoding and decoding should work correctly") { + val encoder = PacketFrameEncoder() + val decoder = PacketFrameDecoder() + val channel = EmbeddedChannel(encoder, decoder) + + val originalPayload = byteArrayOf(0xDE.toByte(), 0xAD.toByte(), 0xBE.toByte(), 0xEF.toByte()) + val input = Unpooled.buffer().writeBytes(originalPayload) + + // Encode then decode + channel.writeOutbound(input) shouldBe true + val encoded = channel.readAllOutbound() + + channel.writeInbound(encoded) shouldBe true + val decoded = channel.readAllInbound() + + decoded.readableBytes() shouldBe originalPayload.size + for (expectedByte in originalPayload) { + decoded.readByte() shouldBe expectedByte + } + + decoded.release() + channel.close() + } +}) \ No newline at end of file diff --git a/server/src/test/kotlin/de/fiereu/openmmo/server/netty/PipelineIntegrationTest.kt b/server/src/test/kotlin/de/fiereu/openmmo/server/netty/PipelineIntegrationTest.kt new file mode 100644 index 0000000..89311f7 --- /dev/null +++ b/server/src/test/kotlin/de/fiereu/openmmo/server/netty/PipelineIntegrationTest.kt @@ -0,0 +1,380 @@ +package de.fiereu.openmmo.server.netty + +import de.fiereu.openmmo.server.protocol.tls.checksum.Crc16Checksum +import de.fiereu.openmmo.server.protocol.tls.checksum.HmacSha256Checksum +import de.fiereu.openmmo.server.protocol.tls.checksum.NoOpChecksum +import de.fiereu.openmmo.server.netty.handlers.checksum.ChecksumFrameDecoder +import de.fiereu.openmmo.server.netty.handlers.checksum.ChecksumFrameEncoder +import de.fiereu.openmmo.server.netty.handlers.frame.PacketFrameDecoder +import de.fiereu.openmmo.server.netty.handlers.frame.PacketFrameEncoder +import de.fiereu.openmmo.server.netty.handlers.tls.TlsDecryptionHandler +import de.fiereu.openmmo.server.netty.handlers.tls.TlsEncryptionHandler +import de.fiereu.openmmo.server.protocol.tls.DefaultTlsContext +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe +import io.kotest.matchers.shouldNotBe +import io.netty.buffer.ByteBuf +import io.netty.buffer.Unpooled +import io.netty.channel.embedded.EmbeddedChannel +import io.mockk.every +import io.mockk.mockk +import javax.crypto.Cipher + +class PipelineIntegrationTest : FunSpec({ + + test("complete outbound pipeline - TLS encryption -> checksum -> frame encoding (NoOpChecksum)") { + val tlsContext = createMockTlsContext() + val checksum = NoOpChecksum() + + // Create outbound pipeline: TLS encryption -> checksum -> frame encoding + // Note: In Netty outbound pipeline, handlers are processed in REVERSE order + val tlsEncoder = TlsEncryptionHandler(tlsContext) + val checksumEncoder = ChecksumFrameEncoder(checksum) + val frameEncoder = PacketFrameEncoder() + + val outboundChannel = EmbeddedChannel(frameEncoder, checksumEncoder, tlsEncoder) + + val originalData = byteArrayOf(0xAB.toByte(), 0xCD.toByte(), 0xEF.toByte(), 0x12.toByte()) + val input = Unpooled.buffer().writeBytes(originalData) + + outboundChannel.writeOutbound(input) shouldBe true + val finalOutput = outboundChannel.readAllOutbound() + + // Expected structure: [length (2 bytes)] + [encrypted_data (4 bytes)] + [checksum (0 bytes for NoOp)] + finalOutput.readableBytes() shouldBe 6 // 2 bytes length + 4 bytes encrypted data + 0 bytes checksum + + // Read and verify length field (little endian) + val lengthField = finalOutput.readUnsignedShortLE() + lengthField shouldBe 6 // Length includes itself (2) + encrypted data (4) + checksum (0) + + // Read the encrypted data + val encryptedData = ByteArray(4) + finalOutput.readBytes(encryptedData) + + // Encrypted data should be different from original (XOR with 0x42) + encryptedData shouldNotBe originalData + // Verify it's actually XOR encrypted + val expectedEncrypted = originalData.map { (it.toInt() xor 0x42).toByte() }.toByteArray() + encryptedData shouldBe expectedEncrypted + + finalOutput.release() + outboundChannel.close() + } + + test("complete outbound pipeline - TLS encryption -> checksum -> frame encoding (CRC16)") { + val tlsContext = createMockTlsContext() + val checksum = Crc16Checksum() + + val tlsEncoder = TlsEncryptionHandler(tlsContext) + val checksumEncoder = ChecksumFrameEncoder(checksum) + val frameEncoder = PacketFrameEncoder() + + val outboundChannel = EmbeddedChannel(frameEncoder, checksumEncoder, tlsEncoder) + + val originalData = byteArrayOf(0xAB.toByte(), 0xCD.toByte(), 0xEF.toByte(), 0x12.toByte()) + val input = Unpooled.buffer().writeBytes(originalData) + + outboundChannel.writeOutbound(input) shouldBe true + val finalOutput = outboundChannel.readAllOutbound() + + // Expected structure: [length (2 bytes)] + [encrypted_data (4 bytes)] + [crc16 checksum (2 bytes)] + finalOutput.readableBytes() shouldBe 8 // 2 + 4 + 2 + + val lengthField = finalOutput.readUnsignedShortLE() + lengthField shouldBe 8 + + // Read the encrypted data + val encryptedData = ByteArray(4) + finalOutput.readBytes(encryptedData) + encryptedData shouldNotBe originalData + + // Read the CRC16 checksum + val checksumData = ByteArray(2) + finalOutput.readBytes(checksumData) + // Verify checksum exists (non-zero for this data pattern) + checksumData shouldNotBe byteArrayOf(0, 0) + + finalOutput.release() + outboundChannel.close() + } + + test("complete outbound pipeline - TLS encryption -> checksum -> frame encoding (HMAC-SHA256)") { + val tlsContext = createMockTlsContext() + val key = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08) + val checksum = HmacSha256Checksum(8, key) + + val tlsEncoder = TlsEncryptionHandler(tlsContext) + val checksumEncoder = ChecksumFrameEncoder(checksum) + val frameEncoder = PacketFrameEncoder() + + val outboundChannel = EmbeddedChannel(frameEncoder, checksumEncoder, tlsEncoder) + + val originalData = byteArrayOf(0xAB.toByte(), 0xCD.toByte(), 0xEF.toByte(), 0x12.toByte()) + val input = Unpooled.buffer().writeBytes(originalData) + + outboundChannel.writeOutbound(input) shouldBe true + val finalOutput = outboundChannel.readAllOutbound() + + // Expected structure: [length (2 bytes)] + [encrypted_data (4 bytes)] + [hmac (8 bytes)] + finalOutput.readableBytes() shouldBe 14 // 2 + 4 + 8 + + val lengthField = finalOutput.readUnsignedShortLE() + lengthField shouldBe 14 + + // Read the encrypted data + val encryptedData = ByteArray(4) + finalOutput.readBytes(encryptedData) + encryptedData shouldNotBe originalData + + // Read the HMAC + val hmacData = ByteArray(8) + finalOutput.readBytes(hmacData) + // HMAC should exist and be non-zero + hmacData shouldNotBe ByteArray(8) { 0 } + + finalOutput.release() + outboundChannel.close() + } + + test("complete inbound pipeline - frame decoding -> checksum verification -> TLS decryption (NoOpChecksum)") { + val tlsContext = createMockTlsContext() + val checksum = NoOpChecksum() + + // Create inbound pipeline: frame decoding -> checksum verification -> TLS decryption + val frameDecoder = PacketFrameDecoder() + val checksumDecoder = ChecksumFrameDecoder(checksum) + val tlsDecoder = TlsDecryptionHandler(tlsContext) + + val inboundChannel = EmbeddedChannel(frameDecoder, checksumDecoder, tlsDecoder) + + val originalData = byteArrayOf(0xAB.toByte(), 0xCD.toByte(), 0xEF.toByte(), 0x12.toByte()) + + // First encrypt the data to simulate what would come from the outbound pipeline + val encryptedData = originalData.map { (it.toInt() xor 0x42).toByte() }.toByteArray() + + // Create the complete packet: length + encrypted data (no checksum for NoOp) + val packetLength = 2 + encryptedData.size // length field + data + val completePacket = Unpooled.buffer() + .writeShortLE(packetLength) + .writeBytes(encryptedData) + + inboundChannel.writeInbound(completePacket) shouldBe true + val decryptedOutput = inboundChannel.readAllInbound() + + decryptedOutput.readableBytes() shouldBe originalData.size + val decryptedBytes = ByteArray(decryptedOutput.readableBytes()) + decryptedOutput.readBytes(decryptedBytes) + + // Should get back the original data + decryptedBytes shouldBe originalData + + decryptedOutput.release() + inboundChannel.close() + } + + test("complete inbound pipeline - frame decoding -> checksum verification -> TLS decryption (CRC16)") { + val tlsContext = createMockTlsContext() + val checksum = Crc16Checksum() + + val frameDecoder = PacketFrameDecoder() + val checksumDecoder = ChecksumFrameDecoder(checksum) + val tlsDecoder = TlsDecryptionHandler(tlsContext) + + val inboundChannel = EmbeddedChannel(frameDecoder, checksumDecoder, tlsDecoder) + + val originalData = byteArrayOf(0xAB.toByte(), 0xCD.toByte(), 0xEF.toByte(), 0x12.toByte()) + + // Encrypt the data + val encryptedData = originalData.map { (it.toInt() xor 0x42).toByte() }.toByteArray() + + // Calculate checksum for the encrypted data + val encryptedBuffer = Unpooled.buffer().writeBytes(encryptedData) + val checksumBytes = checksum.calculate(encryptedBuffer) + encryptedBuffer.release() + + // Create the complete packet: length + encrypted data + checksum + val packetLength = 2 + encryptedData.size + checksumBytes.size + val completePacket = Unpooled.buffer() + .writeShortLE(packetLength) + .writeBytes(encryptedData) + .writeBytes(checksumBytes) + + inboundChannel.writeInbound(completePacket) shouldBe true + val decryptedOutput = inboundChannel.readAllInbound() + + decryptedOutput.readableBytes() shouldBe originalData.size + val decryptedBytes = ByteArray(decryptedOutput.readableBytes()) + decryptedOutput.readBytes(decryptedBytes) + + decryptedBytes shouldBe originalData + + decryptedOutput.release() + inboundChannel.close() + } + + test("complete inbound pipeline - frame decoding -> checksum verification -> TLS decryption (HMAC-SHA256)") { + val tlsContext = createMockTlsContext() + val key = byteArrayOf(0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08) + val checksum = HmacSha256Checksum(8, key) + + val frameDecoder = PacketFrameDecoder() + val checksumDecoder = ChecksumFrameDecoder(checksum) + val tlsDecoder = TlsDecryptionHandler(tlsContext) + + val inboundChannel = EmbeddedChannel(frameDecoder, checksumDecoder, tlsDecoder) + + val originalData = byteArrayOf(0xAB.toByte(), 0xCD.toByte(), 0xEF.toByte(), 0x12.toByte()) + + // Encrypt the data + val encryptedData = originalData.map { (it.toInt() xor 0x42).toByte() }.toByteArray() + + // Calculate HMAC for the encrypted data + val encryptedBuffer = Unpooled.buffer().writeBytes(encryptedData) + val hmacBytes = checksum.calculate(encryptedBuffer) + encryptedBuffer.release() + + // Create the complete packet: length + encrypted data + hmac + val packetLength = 2 + encryptedData.size + hmacBytes.size + val completePacket = Unpooled.buffer() + .writeShortLE(packetLength) + .writeBytes(encryptedData) + .writeBytes(hmacBytes) + + inboundChannel.writeInbound(completePacket) shouldBe true + val decryptedOutput = inboundChannel.readAllInbound() + + decryptedOutput.readableBytes() shouldBe originalData.size + val decryptedBytes = ByteArray(decryptedOutput.readableBytes()) + decryptedOutput.readBytes(decryptedBytes) + + decryptedBytes shouldBe originalData + + decryptedOutput.release() + inboundChannel.close() + } + + test("complete roundtrip - outbound then inbound pipeline should preserve original data") { + val tlsContext = createMockTlsContext() + val checksum = Crc16Checksum() + + // Outbound pipeline: TLS encryption -> checksum -> frame encoding + val tlsEncoder = TlsEncryptionHandler(tlsContext) + val checksumEncoder = ChecksumFrameEncoder(checksum) + val frameEncoder = PacketFrameEncoder() + val outboundChannel = EmbeddedChannel(frameEncoder, checksumEncoder, tlsEncoder) + + // Inbound pipeline: frame decoding -> checksum verification -> TLS decryption + val frameDecoder = PacketFrameDecoder() + val checksumDecoder = ChecksumFrameDecoder(checksum) + val tlsDecoder = TlsDecryptionHandler(tlsContext) + val inboundChannel = EmbeddedChannel(frameDecoder, checksumDecoder, tlsDecoder) + + val originalData = byteArrayOf(0xDE.toByte(), 0xAD.toByte(), 0xBE.toByte(), 0xEF.toByte()) + val input = Unpooled.buffer().writeBytes(originalData) + + // Process through outbound pipeline + outboundChannel.writeOutbound(input) shouldBe true + val processedPacket = outboundChannel.readAllOutbound() + + // Process through inbound pipeline + inboundChannel.writeInbound(processedPacket) shouldBe true + val finalOutput = inboundChannel.readAllInbound() + + // Should get back the original data + finalOutput.readableBytes() shouldBe originalData.size + val finalBytes = ByteArray(finalOutput.readableBytes()) + finalOutput.readBytes(finalBytes) + finalBytes shouldBe originalData + + finalOutput.release() + outboundChannel.close() + inboundChannel.close() + } + + test("complete roundtrip with multiple packets should maintain order and content") { + // Create separate TLS contexts for encoder and decoder to avoid stream cipher sync issues + val encoderTlsContext = createMockTlsContext() + val decoderTlsContext = createMockTlsContext() // Same XOR key, but separate cipher state + val key = byteArrayOf(1, 2, 3, 4, 5, 6, 7, 8) + + // Create separate checksum instances for encoder and decoder + // Both start with the same key but maintain separate round counters + val encoderChecksum = HmacSha256Checksum(4, key) + val decoderChecksum = HmacSha256Checksum(4, key) + + // Create pipelines + val tlsEncoder = TlsEncryptionHandler(encoderTlsContext) + val checksumEncoder = ChecksumFrameEncoder(encoderChecksum) + val frameEncoder = PacketFrameEncoder() + val outboundChannel = EmbeddedChannel(frameEncoder, checksumEncoder, tlsEncoder) + + val frameDecoder = PacketFrameDecoder() + val checksumDecoder = ChecksumFrameDecoder(decoderChecksum) + val tlsDecoder = TlsDecryptionHandler(decoderTlsContext) + val inboundChannel = EmbeddedChannel(frameDecoder, checksumDecoder, tlsDecoder) + + val packets = listOf( + byteArrayOf(0x01, 0x02, 0x03), + byteArrayOf(0x04, 0x05, 0x06, 0x07), + byteArrayOf(0x08, 0x09), + byteArrayOf(0x0A, 0x0B, 0x0C, 0x0D, 0x0E) + ) + + val processedPackets = mutableListOf() + + // Process each packet through the complete pipeline + for (originalPacket in packets) { + val input = Unpooled.buffer().writeBytes(originalPacket) + + // Outbound processing + outboundChannel.writeOutbound(input) shouldBe true + val processedPacket = outboundChannel.readAllOutbound() + + // Inbound processing + inboundChannel.writeInbound(processedPacket) shouldBe true + val finalOutput = inboundChannel.readAllInbound() + + val finalBytes = ByteArray(finalOutput.readableBytes()) + finalOutput.readBytes(finalBytes) + processedPackets.add(finalBytes) + + finalOutput.release() + } + + // Verify all packets were processed correctly + packets.forEachIndexed { index, originalPacket -> + processedPackets[index] shouldBe originalPacket + } + + outboundChannel.close() + inboundChannel.close() + } + + test("inbound pipeline should reject packet with invalid checksum") { + val tlsContext = createMockTlsContext() + val checksum = Crc16Checksum() + + val frameDecoder = PacketFrameDecoder() + val checksumDecoder = ChecksumFrameDecoder(checksum) + val tlsDecoder = TlsDecryptionHandler(tlsContext) + val inboundChannel = EmbeddedChannel(frameDecoder, checksumDecoder, tlsDecoder) + + val originalData = byteArrayOf(0xAB.toByte(), 0xCD.toByte(), 0xEF.toByte(), 0x12.toByte()) + val encryptedData = originalData.map { (it.toInt() xor 0x42).toByte() }.toByteArray() + + // Create packet with invalid checksum + val packetLength = 2 + encryptedData.size + 2 // length + data + invalid checksum + val invalidPacket = Unpooled.buffer() + .writeShortLE(packetLength) + .writeBytes(encryptedData) + .writeByte(0xFF) // Invalid checksum + .writeByte(0xFF) + + inboundChannel.writeInbound(invalidPacket) shouldBe false + + // Should not produce any output due to checksum failure + inboundChannel.readInbound() shouldBe null + + inboundChannel.close() + } +}) \ No newline at end of file diff --git a/server/src/test/kotlin/de/fiereu/openmmo/server/netty/TlsHandlerTest.kt b/server/src/test/kotlin/de/fiereu/openmmo/server/netty/TlsHandlerTest.kt new file mode 100644 index 0000000..40f39c7 --- /dev/null +++ b/server/src/test/kotlin/de/fiereu/openmmo/server/netty/TlsHandlerTest.kt @@ -0,0 +1,248 @@ +package de.fiereu.openmmo.server.netty + +import de.fiereu.openmmo.server.netty.handlers.tls.TlsDecryptionHandler +import de.fiereu.openmmo.server.netty.handlers.tls.TlsEncryptionHandler +import de.fiereu.openmmo.server.protocol.tls.DefaultTlsContext +import io.kotest.core.spec.style.FunSpec +import io.kotest.matchers.shouldBe +import io.kotest.matchers.shouldNotBe +import io.netty.buffer.ByteBuf +import io.netty.buffer.Unpooled +import io.netty.channel.embedded.EmbeddedChannel +import io.mockk.every +import io.mockk.mockk +import javax.crypto.Cipher + +class TlsHandlerTest : FunSpec({ + + test("TlsEncryptionHandler should encrypt data") { + val tlsContext = createMockTlsContext() + val encoder = TlsEncryptionHandler(tlsContext) + val channel = EmbeddedChannel(encoder) + + val originalData = byteArrayOf(0xAB.toByte(), 0xCD.toByte(), 0xEF.toByte(), 0x12.toByte()) + val input = Unpooled.buffer().writeBytes(originalData) + + channel.writeOutbound(input) + + val encrypted = channel.readAllOutbound() + encrypted.readableBytes() shouldBe originalData.size + + // The encrypted data should be different from the original + val encryptedBytes = ByteArray(encrypted.readableBytes()) + encrypted.readBytes(encryptedBytes) + encryptedBytes shouldNotBe originalData + + encrypted.release() + channel.close() + } + + test("TlsDecryptionHandler should decrypt data") { + val tlsContext = createMockTlsContext() + val decoder = TlsDecryptionHandler(tlsContext) + val channel = EmbeddedChannel(decoder) + + val originalData = byteArrayOf(0xAB.toByte(), 0xCD.toByte(), 0xEF.toByte(), 0x12.toByte()) + + // First encrypt the data using the TLS context directly + val encryptedBytes = tlsContext.encrypt(originalData) + val input = Unpooled.buffer().writeBytes(encryptedBytes) + + channel.writeInbound(input) + + val decrypted = channel.readAllInbound() + decrypted.readableBytes() shouldBe originalData.size + + val decryptedBytes = ByteArray(decrypted.readableBytes()) + decrypted.readBytes(decryptedBytes) + decryptedBytes shouldBe originalData + + decrypted.release() + channel.close() + } + + test("TlsEncryptionHandler should handle empty data") { + val tlsContext = createMockTlsContext() + val encoder = TlsEncryptionHandler(tlsContext) + val channel = EmbeddedChannel(encoder) + + val input = Unpooled.buffer() // Empty buffer + + channel.writeOutbound(input) + + val encrypted = channel.readAllOutbound() + encrypted.readableBytes() shouldBe 0 + + encrypted.release() + channel.close() + } + + test("TlsDecryptionHandler should handle empty data") { + val tlsContext = createMockTlsContext() + val decoder = TlsDecryptionHandler(tlsContext) + val channel = EmbeddedChannel(decoder) + + val input = Unpooled.buffer() // Empty buffer + + channel.writeInbound(input) + + // Should not produce any output for empty input + channel.readInbound() shouldBe null + + channel.close() + } + + test("TlsEncryptionHandler should handle large data") { + val tlsContext = createMockTlsContext() + val encoder = TlsEncryptionHandler(tlsContext) + val channel = EmbeddedChannel(encoder) + + val largeData = ByteArray(1024) { it.toByte() } + val input = Unpooled.buffer().writeBytes(largeData) + + channel.writeOutbound(input) + + val encrypted = channel.readAllOutbound() + encrypted.readableBytes() shouldBe largeData.size + + // The encrypted data should be different from the original + val encryptedBytes = ByteArray(encrypted.readableBytes()) + encrypted.readBytes(encryptedBytes) + encryptedBytes shouldNotBe largeData + + encrypted.release() + channel.close() + } + + test("TlsDecryptionHandler should handle large data") { + val tlsContext = createMockTlsContext() + val decoder = TlsDecryptionHandler(tlsContext) + val channel = EmbeddedChannel(decoder) + + val largeData = ByteArray(1024) { it.toByte() } + + // First encrypt the data using the TLS context directly + val encryptedBytes = tlsContext.encrypt(largeData) + val input = Unpooled.buffer().writeBytes(encryptedBytes) + + channel.writeInbound(input) + + val decrypted = channel.readAllInbound() + decrypted.readableBytes() shouldBe largeData.size + + val decryptedBytes = ByteArray(decrypted.readableBytes()) + decrypted.readBytes(decryptedBytes) + decryptedBytes shouldBe largeData + + decrypted.release() + channel.close() + } + + test("roundtrip - encryption then decryption should preserve data") { + val tlsContext = createMockTlsContext() + val encoder = TlsEncryptionHandler(tlsContext) + val decoder = TlsDecryptionHandler(tlsContext) + + val originalData = byteArrayOf(0xDE.toByte(), 0xAD.toByte(), 0xBE.toByte(), 0xEF.toByte()) + val input = Unpooled.buffer().writeBytes(originalData) + + // Encrypt + val encryptChannel = EmbeddedChannel(encoder) + encryptChannel.writeOutbound(input) shouldBe true + val encrypted = encryptChannel.readAllOutbound() + + // Decrypt + val decryptChannel = EmbeddedChannel(decoder) + decryptChannel.writeInbound(encrypted) shouldBe true + val decrypted = decryptChannel.readAllInbound() + + decrypted.readableBytes() shouldBe originalData.size + val decryptedBytes = ByteArray(decrypted.readableBytes()) + decrypted.readBytes(decryptedBytes) + decryptedBytes shouldBe originalData + + decrypted.release() + encryptChannel.close() + decryptChannel.close() + } + + test("roundtrip - multiple packets should maintain stream cipher state") { + val tlsContext = createMockTlsContext() + val encoder = TlsEncryptionHandler(tlsContext) + val decoder = TlsDecryptionHandler(tlsContext) + + val encryptChannel = EmbeddedChannel(encoder) + val decryptChannel = EmbeddedChannel(decoder) + + val packets = listOf( + byteArrayOf(0x01, 0x02, 0x03), + byteArrayOf(0x04, 0x05), + byteArrayOf(0x06, 0x07, 0x08, 0x09) + ) + + val decryptedPackets = mutableListOf() + + // Process each packet in order (maintaining stream cipher state) + for (packet in packets) { + val input = Unpooled.buffer().writeBytes(packet) + + // Encrypt + encryptChannel.writeOutbound(input) shouldBe true + val encrypted = encryptChannel.readAllOutbound() + + // Decrypt + decryptChannel.writeInbound(encrypted) shouldBe true + val decrypted = decryptChannel.readAllInbound() + + val decryptedBytes = ByteArray(decrypted.readableBytes()) + decrypted.readBytes(decryptedBytes) + decryptedPackets.add(decryptedBytes) + + decrypted.release() + } + + // Verify all packets were decrypted correctly + packets.forEachIndexed { index, originalPacket -> + decryptedPackets[index] shouldBe originalPacket + } + + encryptChannel.close() + decryptChannel.close() + } + + test("two different TlsContexts should produce different ciphertexts") { + val tlsContext1 = createMockTlsContext() + val tlsContext2 = createMockTlsContext(0x24) + + val encoder1 = TlsEncryptionHandler(tlsContext1) + val encoder2 = TlsEncryptionHandler(tlsContext2) + + val channel1 = EmbeddedChannel(encoder1) + val channel2 = EmbeddedChannel(encoder2) + + val originalData = byteArrayOf(0xAB.toByte(), 0xCD.toByte(), 0xEF.toByte(), 0x12.toByte()) + val input1 = Unpooled.buffer().writeBytes(originalData) + val input2 = Unpooled.buffer().writeBytes(originalData) + + channel1.writeOutbound(input1) + channel2.writeOutbound(input2) + + val encrypted1 = channel1.readAllOutbound() + val encrypted2 = channel2.readAllOutbound() + + encrypted1.readableBytes() shouldBe encrypted2.readableBytes() + + val encrypted1Bytes = ByteArray(encrypted1.readableBytes()) + val encrypted2Bytes = ByteArray(encrypted2.readableBytes()) + encrypted1.readBytes(encrypted1Bytes) + encrypted2.readBytes(encrypted2Bytes) + + // Different contexts should produce different ciphertext + encrypted1Bytes shouldNotBe encrypted2Bytes + + encrypted1.release() + encrypted2.release() + channel1.close() + channel2.close() + } +}) \ No newline at end of file diff --git a/server/src/test/kotlin/de/fiereu/openmmo/server/netty/TlsHelper.kt b/server/src/test/kotlin/de/fiereu/openmmo/server/netty/TlsHelper.kt new file mode 100644 index 0000000..a82c831 --- /dev/null +++ b/server/src/test/kotlin/de/fiereu/openmmo/server/netty/TlsHelper.kt @@ -0,0 +1,21 @@ +package de.fiereu.openmmo.server.netty + +import de.fiereu.openmmo.server.protocol.tls.TlsContext +import io.mockk.every +import io.mockk.mockk + +fun createMockTlsContext(xorKey: Int = 0x42): TlsContext { + val mockTlsContext = mockk(relaxed = true) + + every { mockTlsContext.encrypt(any()) } answers { + val input = firstArg() + input.map { (it.toInt() xor xorKey).toByte() }.toByteArray() + } + + every { mockTlsContext.decrypt(any()) } answers { + val input = firstArg() + input.map { (it.toInt() xor xorKey).toByte() }.toByteArray() + } + + return mockTlsContext +} \ No newline at end of file diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..a622a88 --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1,21 @@ +dependencyResolutionManagement { + @Suppress("UnstableApiUsage") + repositories { + mavenCentral() + } +} + +plugins { + id("org.gradle.toolchains.foojay-resolver-convention") version "0.8.0" +} + +rootProject.name = "openmmo" + +include(":keys") +include(":patcher") +include(":common") +include(":protocol") +include(":protocol.tls") +include(":protocol.login") +include(":server") +include(":server.login") \ No newline at end of file