├── .gitignore ├── AUTHORS ├── COPYING ├── ChangeLog ├── INSTALL ├── Makefile.am ├── NEWS ├── README ├── autogen.sh ├── config.rpath ├── configure.ac ├── m4 ├── cflags.m4 └── mysql.m4 └── src ├── packets.c ├── packets.h ├── pidfile.c ├── scripts.c ├── scripts.h ├── ship.c ├── ship.h ├── shipgate.c └── shipgate.h /.gitignore: -------------------------------------------------------------------------------- 1 | # Git ignore list... 2 | 3 | # Compiled code. 4 | *.o 5 | *.exe 6 | *.so 7 | *.dylib 8 | *.dSYM 9 | *.a 10 | shipgate 11 | 12 | # Autotools generated stuff and various other build process junk. 13 | Makefile 14 | Makefile.in 15 | aclocal.m4 16 | autom4te.cache 17 | compile 18 | config.guess 19 | config.log 20 | config.status 21 | config.sub 22 | configure 23 | depcomp 24 | install-sh 25 | libtool 26 | ltmain.sh 27 | libtool.m4 28 | ltoptions.m4 29 | ltsugar.m4 30 | ltversion.m4 31 | lt~obsolete.m4 32 | missing 33 | .deps 34 | .dirstamp 35 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sylverant/shipgate/d0f0a3ab3a32aef3a14f79f32a69420442e7d965/AUTHORS -------------------------------------------------------------------------------- /COPYING: -------------------------------------------------------------------------------- 1 | GNU AFFERO GENERAL PUBLIC LICENSE 2 | Version 3, 19 November 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU Affero General Public License is a free, copyleft license for 11 | software and other kinds of works, specifically designed to ensure 12 | cooperation with the community in the case of network server software. 13 | 14 | The licenses for most software and other practical works are designed 15 | to take away your freedom to share and change the works. By contrast, 16 | our General Public Licenses are intended to guarantee your freedom to 17 | share and change all versions of a program--to make sure it remains free 18 | software for all its users. 19 | 20 | When we speak of free software, we are referring to freedom, not 21 | price. Our General Public Licenses are designed to make sure that you 22 | have the freedom to distribute copies of free software (and charge for 23 | them if you wish), that you receive source code or can get it if you 24 | want it, that you can change the software or use pieces of it in new 25 | free programs, and that you know you can do these things. 26 | 27 | Developers that use our General Public Licenses protect your rights 28 | with two steps: (1) assert copyright on the software, and (2) offer 29 | you this License which gives you legal permission to copy, distribute 30 | and/or modify the software. 31 | 32 | A secondary benefit of defending all users' freedom is that 33 | improvements made in alternate versions of the program, if they 34 | receive widespread use, become available for other developers to 35 | incorporate. Many developers of free software are heartened and 36 | encouraged by the resulting cooperation. However, in the case of 37 | software used on network servers, this result may fail to come about. 38 | The GNU General Public License permits making a modified version and 39 | letting the public access it on a server without ever releasing its 40 | source code to the public. 41 | 42 | The GNU Affero General Public License is designed specifically to 43 | ensure that, in such cases, the modified source code becomes available 44 | to the community. It requires the operator of a network server to 45 | provide the source code of the modified version running there to the 46 | users of that server. Therefore, public use of a modified version, on 47 | a publicly accessible server, gives the public access to the source 48 | code of the modified version. 49 | 50 | An older license, called the Affero General Public License and 51 | published by Affero, was designed to accomplish similar goals. This is 52 | a different license, not a version of the Affero GPL, but Affero has 53 | released a new version of the Affero GPL which permits relicensing under 54 | this license. 55 | 56 | The precise terms and conditions for copying, distribution and 57 | modification follow. 58 | 59 | TERMS AND CONDITIONS 60 | 61 | 0. Definitions. 62 | 63 | "This License" refers to version 3 of the GNU Affero General Public License. 64 | 65 | "Copyright" also means copyright-like laws that apply to other kinds of 66 | works, such as semiconductor masks. 67 | 68 | "The Program" refers to any copyrightable work licensed under this 69 | License. Each licensee is addressed as "you". "Licensees" and 70 | "recipients" may be individuals or organizations. 71 | 72 | To "modify" a work means to copy from or adapt all or part of the work 73 | in a fashion requiring copyright permission, other than the making of an 74 | exact copy. The resulting work is called a "modified version" of the 75 | earlier work or a work "based on" the earlier work. 76 | 77 | A "covered work" means either the unmodified Program or a work based 78 | on the Program. 79 | 80 | To "propagate" a work means to do anything with it that, without 81 | permission, would make you directly or secondarily liable for 82 | infringement under applicable copyright law, except executing it on a 83 | computer or modifying a private copy. Propagation includes copying, 84 | distribution (with or without modification), making available to the 85 | public, and in some countries other activities as well. 86 | 87 | To "convey" a work means any kind of propagation that enables other 88 | parties to make or receive copies. Mere interaction with a user through 89 | a computer network, with no transfer of a copy, is not conveying. 90 | 91 | An interactive user interface displays "Appropriate Legal Notices" 92 | to the extent that it includes a convenient and prominently visible 93 | feature that (1) displays an appropriate copyright notice, and (2) 94 | tells the user that there is no warranty for the work (except to the 95 | extent that warranties are provided), that licensees may convey the 96 | work under this License, and how to view a copy of this License. If 97 | the interface presents a list of user commands or options, such as a 98 | menu, a prominent item in the list meets this criterion. 99 | 100 | 1. Source Code. 101 | 102 | The "source code" for a work means the preferred form of the work 103 | for making modifications to it. "Object code" means any non-source 104 | form of a work. 105 | 106 | A "Standard Interface" means an interface that either is an official 107 | standard defined by a recognized standards body, or, in the case of 108 | interfaces specified for a particular programming language, one that 109 | is widely used among developers working in that language. 110 | 111 | The "System Libraries" of an executable work include anything, other 112 | than the work as a whole, that (a) is included in the normal form of 113 | packaging a Major Component, but which is not part of that Major 114 | Component, and (b) serves only to enable use of the work with that 115 | Major Component, or to implement a Standard Interface for which an 116 | implementation is available to the public in source code form. A 117 | "Major Component", in this context, means a major essential component 118 | (kernel, window system, and so on) of the specific operating system 119 | (if any) on which the executable work runs, or a compiler used to 120 | produce the work, or an object code interpreter used to run it. 121 | 122 | The "Corresponding Source" for a work in object code form means all 123 | the source code needed to generate, install, and (for an executable 124 | work) run the object code and to modify the work, including scripts to 125 | control those activities. However, it does not include the work's 126 | System Libraries, or general-purpose tools or generally available free 127 | programs which are used unmodified in performing those activities but 128 | which are not part of the work. For example, Corresponding Source 129 | includes interface definition files associated with source files for 130 | the work, and the source code for shared libraries and dynamically 131 | linked subprograms that the work is specifically designed to require, 132 | such as by intimate data communication or control flow between those 133 | subprograms and other parts of the work. 134 | 135 | The Corresponding Source need not include anything that users 136 | can regenerate automatically from other parts of the Corresponding 137 | Source. 138 | 139 | The Corresponding Source for a work in source code form is that 140 | same work. 141 | 142 | 2. Basic Permissions. 143 | 144 | All rights granted under this License are granted for the term of 145 | copyright on the Program, and are irrevocable provided the stated 146 | conditions are met. This License explicitly affirms your unlimited 147 | permission to run the unmodified Program. The output from running a 148 | covered work is covered by this License only if the output, given its 149 | content, constitutes a covered work. This License acknowledges your 150 | rights of fair use or other equivalent, as provided by copyright law. 151 | 152 | You may make, run and propagate covered works that you do not 153 | convey, without conditions so long as your license otherwise remains 154 | in force. You may convey covered works to others for the sole purpose 155 | of having them make modifications exclusively for you, or provide you 156 | with facilities for running those works, provided that you comply with 157 | the terms of this License in conveying all material for which you do 158 | not control copyright. Those thus making or running the covered works 159 | for you must do so exclusively on your behalf, under your direction 160 | and control, on terms that prohibit them from making any copies of 161 | your copyrighted material outside their relationship with you. 162 | 163 | Conveying under any other circumstances is permitted solely under 164 | the conditions stated below. Sublicensing is not allowed; section 10 165 | makes it unnecessary. 166 | 167 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 168 | 169 | No covered work shall be deemed part of an effective technological 170 | measure under any applicable law fulfilling obligations under article 171 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 172 | similar laws prohibiting or restricting circumvention of such 173 | measures. 174 | 175 | When you convey a covered work, you waive any legal power to forbid 176 | circumvention of technological measures to the extent such circumvention 177 | is effected by exercising rights under this License with respect to 178 | the covered work, and you disclaim any intention to limit operation or 179 | modification of the work as a means of enforcing, against the work's 180 | users, your or third parties' legal rights to forbid circumvention of 181 | technological measures. 182 | 183 | 4. Conveying Verbatim Copies. 184 | 185 | You may convey verbatim copies of the Program's source code as you 186 | receive it, in any medium, provided that you conspicuously and 187 | appropriately publish on each copy an appropriate copyright notice; 188 | keep intact all notices stating that this License and any 189 | non-permissive terms added in accord with section 7 apply to the code; 190 | keep intact all notices of the absence of any warranty; and give all 191 | recipients a copy of this License along with the Program. 192 | 193 | You may charge any price or no price for each copy that you convey, 194 | and you may offer support or warranty protection for a fee. 195 | 196 | 5. Conveying Modified Source Versions. 197 | 198 | You may convey a work based on the Program, or the modifications to 199 | produce it from the Program, in the form of source code under the 200 | terms of section 4, provided that you also meet all of these conditions: 201 | 202 | a) The work must carry prominent notices stating that you modified 203 | it, and giving a relevant date. 204 | 205 | b) The work must carry prominent notices stating that it is 206 | released under this License and any conditions added under section 207 | 7. This requirement modifies the requirement in section 4 to 208 | "keep intact all notices". 209 | 210 | c) You must license the entire work, as a whole, under this 211 | License to anyone who comes into possession of a copy. This 212 | License will therefore apply, along with any applicable section 7 213 | additional terms, to the whole of the work, and all its parts, 214 | regardless of how they are packaged. This License gives no 215 | permission to license the work in any other way, but it does not 216 | invalidate such permission if you have separately received it. 217 | 218 | d) If the work has interactive user interfaces, each must display 219 | Appropriate Legal Notices; however, if the Program has interactive 220 | interfaces that do not display Appropriate Legal Notices, your 221 | work need not make them do so. 222 | 223 | A compilation of a covered work with other separate and independent 224 | works, which are not by their nature extensions of the covered work, 225 | and which are not combined with it such as to form a larger program, 226 | in or on a volume of a storage or distribution medium, is called an 227 | "aggregate" if the compilation and its resulting copyright are not 228 | used to limit the access or legal rights of the compilation's users 229 | beyond what the individual works permit. Inclusion of a covered work 230 | in an aggregate does not cause this License to apply to the other 231 | parts of the aggregate. 232 | 233 | 6. Conveying Non-Source Forms. 234 | 235 | You may convey a covered work in object code form under the terms 236 | of sections 4 and 5, provided that you also convey the 237 | machine-readable Corresponding Source under the terms of this License, 238 | in one of these ways: 239 | 240 | a) Convey the object code in, or embodied in, a physical product 241 | (including a physical distribution medium), accompanied by the 242 | Corresponding Source fixed on a durable physical medium 243 | customarily used for software interchange. 244 | 245 | b) Convey the object code in, or embodied in, a physical product 246 | (including a physical distribution medium), accompanied by a 247 | written offer, valid for at least three years and valid for as 248 | long as you offer spare parts or customer support for that product 249 | model, to give anyone who possesses the object code either (1) a 250 | copy of the Corresponding Source for all the software in the 251 | product that is covered by this License, on a durable physical 252 | medium customarily used for software interchange, for a price no 253 | more than your reasonable cost of physically performing this 254 | conveying of source, or (2) access to copy the 255 | Corresponding Source from a network server at no charge. 256 | 257 | c) Convey individual copies of the object code with a copy of the 258 | written offer to provide the Corresponding Source. This 259 | alternative is allowed only occasionally and noncommercially, and 260 | only if you received the object code with such an offer, in accord 261 | with subsection 6b. 262 | 263 | d) Convey the object code by offering access from a designated 264 | place (gratis or for a charge), and offer equivalent access to the 265 | Corresponding Source in the same way through the same place at no 266 | further charge. You need not require recipients to copy the 267 | Corresponding Source along with the object code. If the place to 268 | copy the object code is a network server, the Corresponding Source 269 | may be on a different server (operated by you or a third party) 270 | that supports equivalent copying facilities, provided you maintain 271 | clear directions next to the object code saying where to find the 272 | Corresponding Source. Regardless of what server hosts the 273 | Corresponding Source, you remain obligated to ensure that it is 274 | available for as long as needed to satisfy these requirements. 275 | 276 | e) Convey the object code using peer-to-peer transmission, provided 277 | you inform other peers where the object code and Corresponding 278 | Source of the work are being offered to the general public at no 279 | charge under subsection 6d. 280 | 281 | A separable portion of the object code, whose source code is excluded 282 | from the Corresponding Source as a System Library, need not be 283 | included in conveying the object code work. 284 | 285 | A "User Product" is either (1) a "consumer product", which means any 286 | tangible personal property which is normally used for personal, family, 287 | or household purposes, or (2) anything designed or sold for incorporation 288 | into a dwelling. In determining whether a product is a consumer product, 289 | doubtful cases shall be resolved in favor of coverage. For a particular 290 | product received by a particular user, "normally used" refers to a 291 | typical or common use of that class of product, regardless of the status 292 | of the particular user or of the way in which the particular user 293 | actually uses, or expects or is expected to use, the product. A product 294 | is a consumer product regardless of whether the product has substantial 295 | commercial, industrial or non-consumer uses, unless such uses represent 296 | the only significant mode of use of the product. 297 | 298 | "Installation Information" for a User Product means any methods, 299 | procedures, authorization keys, or other information required to install 300 | and execute modified versions of a covered work in that User Product from 301 | a modified version of its Corresponding Source. The information must 302 | suffice to ensure that the continued functioning of the modified object 303 | code is in no case prevented or interfered with solely because 304 | modification has been made. 305 | 306 | If you convey an object code work under this section in, or with, or 307 | specifically for use in, a User Product, and the conveying occurs as 308 | part of a transaction in which the right of possession and use of the 309 | User Product is transferred to the recipient in perpetuity or for a 310 | fixed term (regardless of how the transaction is characterized), the 311 | Corresponding Source conveyed under this section must be accompanied 312 | by the Installation Information. But this requirement does not apply 313 | if neither you nor any third party retains the ability to install 314 | modified object code on the User Product (for example, the work has 315 | been installed in ROM). 316 | 317 | The requirement to provide Installation Information does not include a 318 | requirement to continue to provide support service, warranty, or updates 319 | for a work that has been modified or installed by the recipient, or for 320 | the User Product in which it has been modified or installed. Access to a 321 | network may be denied when the modification itself materially and 322 | adversely affects the operation of the network or violates the rules and 323 | protocols for communication across the network. 324 | 325 | Corresponding Source conveyed, and Installation Information provided, 326 | in accord with this section must be in a format that is publicly 327 | documented (and with an implementation available to the public in 328 | source code form), and must require no special password or key for 329 | unpacking, reading or copying. 330 | 331 | 7. Additional Terms. 332 | 333 | "Additional permissions" are terms that supplement the terms of this 334 | License by making exceptions from one or more of its conditions. 335 | Additional permissions that are applicable to the entire Program shall 336 | be treated as though they were included in this License, to the extent 337 | that they are valid under applicable law. If additional permissions 338 | apply only to part of the Program, that part may be used separately 339 | under those permissions, but the entire Program remains governed by 340 | this License without regard to the additional permissions. 341 | 342 | When you convey a copy of a covered work, you may at your option 343 | remove any additional permissions from that copy, or from any part of 344 | it. (Additional permissions may be written to require their own 345 | removal in certain cases when you modify the work.) You may place 346 | additional permissions on material, added by you to a covered work, 347 | for which you have or can give appropriate copyright permission. 348 | 349 | Notwithstanding any other provision of this License, for material you 350 | add to a covered work, you may (if authorized by the copyright holders of 351 | that material) supplement the terms of this License with terms: 352 | 353 | a) Disclaiming warranty or limiting liability differently from the 354 | terms of sections 15 and 16 of this License; or 355 | 356 | b) Requiring preservation of specified reasonable legal notices or 357 | author attributions in that material or in the Appropriate Legal 358 | Notices displayed by works containing it; or 359 | 360 | c) Prohibiting misrepresentation of the origin of that material, or 361 | requiring that modified versions of such material be marked in 362 | reasonable ways as different from the original version; or 363 | 364 | d) Limiting the use for publicity purposes of names of licensors or 365 | authors of the material; or 366 | 367 | e) Declining to grant rights under trademark law for use of some 368 | trade names, trademarks, or service marks; or 369 | 370 | f) Requiring indemnification of licensors and authors of that 371 | material by anyone who conveys the material (or modified versions of 372 | it) with contractual assumptions of liability to the recipient, for 373 | any liability that these contractual assumptions directly impose on 374 | those licensors and authors. 375 | 376 | All other non-permissive additional terms are considered "further 377 | restrictions" within the meaning of section 10. If the Program as you 378 | received it, or any part of it, contains a notice stating that it is 379 | governed by this License along with a term that is a further 380 | restriction, you may remove that term. If a license document contains 381 | a further restriction but permits relicensing or conveying under this 382 | License, you may add to a covered work material governed by the terms 383 | of that license document, provided that the further restriction does 384 | not survive such relicensing or conveying. 385 | 386 | If you add terms to a covered work in accord with this section, you 387 | must place, in the relevant source files, a statement of the 388 | additional terms that apply to those files, or a notice indicating 389 | where to find the applicable terms. 390 | 391 | Additional terms, permissive or non-permissive, may be stated in the 392 | form of a separately written license, or stated as exceptions; 393 | the above requirements apply either way. 394 | 395 | 8. Termination. 396 | 397 | You may not propagate or modify a covered work except as expressly 398 | provided under this License. Any attempt otherwise to propagate or 399 | modify it is void, and will automatically terminate your rights under 400 | this License (including any patent licenses granted under the third 401 | paragraph of section 11). 402 | 403 | However, if you cease all violation of this License, then your 404 | license from a particular copyright holder is reinstated (a) 405 | provisionally, unless and until the copyright holder explicitly and 406 | finally terminates your license, and (b) permanently, if the copyright 407 | holder fails to notify you of the violation by some reasonable means 408 | prior to 60 days after the cessation. 409 | 410 | Moreover, your license from a particular copyright holder is 411 | reinstated permanently if the copyright holder notifies you of the 412 | violation by some reasonable means, this is the first time you have 413 | received notice of violation of this License (for any work) from that 414 | copyright holder, and you cure the violation prior to 30 days after 415 | your receipt of the notice. 416 | 417 | Termination of your rights under this section does not terminate the 418 | licenses of parties who have received copies or rights from you under 419 | this License. If your rights have been terminated and not permanently 420 | reinstated, you do not qualify to receive new licenses for the same 421 | material under section 10. 422 | 423 | 9. Acceptance Not Required for Having Copies. 424 | 425 | You are not required to accept this License in order to receive or 426 | run a copy of the Program. Ancillary propagation of a covered work 427 | occurring solely as a consequence of using peer-to-peer transmission 428 | to receive a copy likewise does not require acceptance. However, 429 | nothing other than this License grants you permission to propagate or 430 | modify any covered work. These actions infringe copyright if you do 431 | not accept this License. Therefore, by modifying or propagating a 432 | covered work, you indicate your acceptance of this License to do so. 433 | 434 | 10. Automatic Licensing of Downstream Recipients. 435 | 436 | Each time you convey a covered work, the recipient automatically 437 | receives a license from the original licensors, to run, modify and 438 | propagate that work, subject to this License. You are not responsible 439 | for enforcing compliance by third parties with this License. 440 | 441 | An "entity transaction" is a transaction transferring control of an 442 | organization, or substantially all assets of one, or subdividing an 443 | organization, or merging organizations. If propagation of a covered 444 | work results from an entity transaction, each party to that 445 | transaction who receives a copy of the work also receives whatever 446 | licenses to the work the party's predecessor in interest had or could 447 | give under the previous paragraph, plus a right to possession of the 448 | Corresponding Source of the work from the predecessor in interest, if 449 | the predecessor has it or can get it with reasonable efforts. 450 | 451 | You may not impose any further restrictions on the exercise of the 452 | rights granted or affirmed under this License. For example, you may 453 | not impose a license fee, royalty, or other charge for exercise of 454 | rights granted under this License, and you may not initiate litigation 455 | (including a cross-claim or counterclaim in a lawsuit) alleging that 456 | any patent claim is infringed by making, using, selling, offering for 457 | sale, or importing the Program or any portion of it. 458 | 459 | 11. Patents. 460 | 461 | A "contributor" is a copyright holder who authorizes use under this 462 | License of the Program or a work on which the Program is based. The 463 | work thus licensed is called the contributor's "contributor version". 464 | 465 | A contributor's "essential patent claims" are all patent claims 466 | owned or controlled by the contributor, whether already acquired or 467 | hereafter acquired, that would be infringed by some manner, permitted 468 | by this License, of making, using, or selling its contributor version, 469 | but do not include claims that would be infringed only as a 470 | consequence of further modification of the contributor version. For 471 | purposes of this definition, "control" includes the right to grant 472 | patent sublicenses in a manner consistent with the requirements of 473 | this License. 474 | 475 | Each contributor grants you a non-exclusive, worldwide, royalty-free 476 | patent license under the contributor's essential patent claims, to 477 | make, use, sell, offer for sale, import and otherwise run, modify and 478 | propagate the contents of its contributor version. 479 | 480 | In the following three paragraphs, a "patent license" is any express 481 | agreement or commitment, however denominated, not to enforce a patent 482 | (such as an express permission to practice a patent or covenant not to 483 | sue for patent infringement). To "grant" such a patent license to a 484 | party means to make such an agreement or commitment not to enforce a 485 | patent against the party. 486 | 487 | If you convey a covered work, knowingly relying on a patent license, 488 | and the Corresponding Source of the work is not available for anyone 489 | to copy, free of charge and under the terms of this License, through a 490 | publicly available network server or other readily accessible means, 491 | then you must either (1) cause the Corresponding Source to be so 492 | available, or (2) arrange to deprive yourself of the benefit of the 493 | patent license for this particular work, or (3) arrange, in a manner 494 | consistent with the requirements of this License, to extend the patent 495 | license to downstream recipients. "Knowingly relying" means you have 496 | actual knowledge that, but for the patent license, your conveying the 497 | covered work in a country, or your recipient's use of the covered work 498 | in a country, would infringe one or more identifiable patents in that 499 | country that you have reason to believe are valid. 500 | 501 | If, pursuant to or in connection with a single transaction or 502 | arrangement, you convey, or propagate by procuring conveyance of, a 503 | covered work, and grant a patent license to some of the parties 504 | receiving the covered work authorizing them to use, propagate, modify 505 | or convey a specific copy of the covered work, then the patent license 506 | you grant is automatically extended to all recipients of the covered 507 | work and works based on it. 508 | 509 | A patent license is "discriminatory" if it does not include within 510 | the scope of its coverage, prohibits the exercise of, or is 511 | conditioned on the non-exercise of one or more of the rights that are 512 | specifically granted under this License. You may not convey a covered 513 | work if you are a party to an arrangement with a third party that is 514 | in the business of distributing software, under which you make payment 515 | to the third party based on the extent of your activity of conveying 516 | the work, and under which the third party grants, to any of the 517 | parties who would receive the covered work from you, a discriminatory 518 | patent license (a) in connection with copies of the covered work 519 | conveyed by you (or copies made from those copies), or (b) primarily 520 | for and in connection with specific products or compilations that 521 | contain the covered work, unless you entered into that arrangement, 522 | or that patent license was granted, prior to 28 March 2007. 523 | 524 | Nothing in this License shall be construed as excluding or limiting 525 | any implied license or other defenses to infringement that may 526 | otherwise be available to you under applicable patent law. 527 | 528 | 12. No Surrender of Others' Freedom. 529 | 530 | If conditions are imposed on you (whether by court order, agreement or 531 | otherwise) that contradict the conditions of this License, they do not 532 | excuse you from the conditions of this License. If you cannot convey a 533 | covered work so as to satisfy simultaneously your obligations under this 534 | License and any other pertinent obligations, then as a consequence you may 535 | not convey it at all. For example, if you agree to terms that obligate you 536 | to collect a royalty for further conveying from those to whom you convey 537 | the Program, the only way you could satisfy both those terms and this 538 | License would be to refrain entirely from conveying the Program. 539 | 540 | 13. Remote Network Interaction; Use with the GNU General Public License. 541 | 542 | Notwithstanding any other provision of this License, if you modify the 543 | Program, your modified version must prominently offer all users 544 | interacting with it remotely through a computer network (if your version 545 | supports such interaction) an opportunity to receive the Corresponding 546 | Source of your version by providing access to the Corresponding Source 547 | from a network server at no charge, through some standard or customary 548 | means of facilitating copying of software. This Corresponding Source 549 | shall include the Corresponding Source for any work covered by version 3 550 | of the GNU General Public License that is incorporated pursuant to the 551 | following paragraph. 552 | 553 | Notwithstanding any other provision of this License, you have 554 | permission to link or combine any covered work with a work licensed 555 | under version 3 of the GNU General Public License into a single 556 | combined work, and to convey the resulting work. The terms of this 557 | License will continue to apply to the part which is the covered work, 558 | but the work with which it is combined will remain governed by version 559 | 3 of the GNU General Public License. 560 | 561 | 14. Revised Versions of this License. 562 | 563 | The Free Software Foundation may publish revised and/or new versions of 564 | the GNU Affero General Public License from time to time. Such new versions 565 | will be similar in spirit to the present version, but may differ in detail to 566 | address new problems or concerns. 567 | 568 | Each version is given a distinguishing version number. If the 569 | Program specifies that a certain numbered version of the GNU Affero General 570 | Public License "or any later version" applies to it, you have the 571 | option of following the terms and conditions either of that numbered 572 | version or of any later version published by the Free Software 573 | Foundation. If the Program does not specify a version number of the 574 | GNU Affero General Public License, you may choose any version ever published 575 | by the Free Software Foundation. 576 | 577 | If the Program specifies that a proxy can decide which future 578 | versions of the GNU Affero General Public License can be used, that proxy's 579 | public statement of acceptance of a version permanently authorizes you 580 | to choose that version for the Program. 581 | 582 | Later license versions may give you additional or different 583 | permissions. However, no additional obligations are imposed on any 584 | author or copyright holder as a result of your choosing to follow a 585 | later version. 586 | 587 | 15. Disclaimer of Warranty. 588 | 589 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 590 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 591 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 592 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 593 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 594 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 595 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 596 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 597 | 598 | 16. Limitation of Liability. 599 | 600 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 601 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 602 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 603 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 604 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 605 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 606 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 607 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 608 | SUCH DAMAGES. 609 | 610 | 17. Interpretation of Sections 15 and 16. 611 | 612 | If the disclaimer of warranty and limitation of liability provided 613 | above cannot be given local legal effect according to their terms, 614 | reviewing courts shall apply local law that most closely approximates 615 | an absolute waiver of all civil liability in connection with the 616 | Program, unless a warranty or assumption of liability accompanies a 617 | copy of the Program in return for a fee. 618 | 619 | END OF TERMS AND CONDITIONS 620 | 621 | How to Apply These Terms to Your New Programs 622 | 623 | If you develop a new program, and you want it to be of the greatest 624 | possible use to the public, the best way to achieve this is to make it 625 | free software which everyone can redistribute and change under these terms. 626 | 627 | To do so, attach the following notices to the program. It is safest 628 | to attach them to the start of each source file to most effectively 629 | state the exclusion of warranty; and each file should have at least 630 | the "copyright" line and a pointer to where the full notice is found. 631 | 632 | 633 | Copyright (C) 634 | 635 | This program is free software: you can redistribute it and/or modify 636 | it under the terms of the GNU Affero General Public License as published by 637 | the Free Software Foundation, either version 3 of the License, or 638 | (at your option) any later version. 639 | 640 | This program is distributed in the hope that it will be useful, 641 | but WITHOUT ANY WARRANTY; without even the implied warranty of 642 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 643 | GNU Affero General Public License for more details. 644 | 645 | You should have received a copy of the GNU Affero General Public License 646 | along with this program. If not, see . 647 | 648 | Also add information on how to contact you by electronic and paper mail. 649 | 650 | If your software can interact with users remotely through a computer 651 | network, you should also make sure that it provides a way for users to 652 | get its source. For example, if your program is a web application, its 653 | interface could display a "Source" link that leads users to an archive 654 | of the code. There are many ways you could offer source, and different 655 | solutions will be better for different programs; see section 13 for the 656 | specific requirements. 657 | 658 | You should also get your employer (if you work as a programmer) or school, 659 | if any, to sign a "copyright disclaimer" for the program, if necessary. 660 | For more information on this, and how to apply and follow the GNU AGPL, see 661 | . 662 | -------------------------------------------------------------------------------- /ChangeLog: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sylverant/shipgate/d0f0a3ab3a32aef3a14f79f32a69420442e7d965/ChangeLog -------------------------------------------------------------------------------- /INSTALL: -------------------------------------------------------------------------------- 1 | Installation Instructions 2 | ************************* 3 | 4 | Copyright (C) 1994, 1995, 1996, 1999, 2000, 2001, 2002, 2004, 2005, 5 | 2006, 2007, 2008 Free Software Foundation, Inc. 6 | 7 | This file is free documentation; the Free Software Foundation gives 8 | unlimited permission to copy, distribute and modify it. 9 | 10 | Basic Installation 11 | ================== 12 | 13 | Briefly, the shell commands `./configure; make; make install' should 14 | configure, build, and install this package. The following 15 | more-detailed instructions are generic; see the `README' file for 16 | instructions specific to this package. 17 | 18 | The `configure' shell script attempts to guess correct values for 19 | various system-dependent variables used during compilation. It uses 20 | those values to create a `Makefile' in each directory of the package. 21 | It may also create one or more `.h' files containing system-dependent 22 | definitions. Finally, it creates a shell script `config.status' that 23 | you can run in the future to recreate the current configuration, and a 24 | file `config.log' containing compiler output (useful mainly for 25 | debugging `configure'). 26 | 27 | It can also use an optional file (typically called `config.cache' 28 | and enabled with `--cache-file=config.cache' or simply `-C') that saves 29 | the results of its tests to speed up reconfiguring. Caching is 30 | disabled by default to prevent problems with accidental use of stale 31 | cache files. 32 | 33 | If you need to do unusual things to compile the package, please try 34 | to figure out how `configure' could check whether to do them, and mail 35 | diffs or instructions to the address given in the `README' so they can 36 | be considered for the next release. If you are using the cache, and at 37 | some point `config.cache' contains results you don't want to keep, you 38 | may remove or edit it. 39 | 40 | The file `configure.ac' (or `configure.in') is used to create 41 | `configure' by a program called `autoconf'. You need `configure.ac' if 42 | you want to change it or regenerate `configure' using a newer version 43 | of `autoconf'. 44 | 45 | The simplest way to compile this package is: 46 | 47 | 1. `cd' to the directory containing the package's source code and type 48 | `./configure' to configure the package for your system. 49 | 50 | Running `configure' might take a while. While running, it prints 51 | some messages telling which features it is checking for. 52 | 53 | 2. Type `make' to compile the package. 54 | 55 | 3. Optionally, type `make check' to run any self-tests that come with 56 | the package. 57 | 58 | 4. Type `make install' to install the programs and any data files and 59 | documentation. 60 | 61 | 5. You can remove the program binaries and object files from the 62 | source code directory by typing `make clean'. To also remove the 63 | files that `configure' created (so you can compile the package for 64 | a different kind of computer), type `make distclean'. There is 65 | also a `make maintainer-clean' target, but that is intended mainly 66 | for the package's developers. If you use it, you may have to get 67 | all sorts of other programs in order to regenerate files that came 68 | with the distribution. 69 | 70 | 6. Often, you can also type `make uninstall' to remove the installed 71 | files again. 72 | 73 | Compilers and Options 74 | ===================== 75 | 76 | Some systems require unusual options for compilation or linking that 77 | the `configure' script does not know about. Run `./configure --help' 78 | for details on some of the pertinent environment variables. 79 | 80 | You can give `configure' initial values for configuration parameters 81 | by setting variables in the command line or in the environment. Here 82 | is an example: 83 | 84 | ./configure CC=c99 CFLAGS=-g LIBS=-lposix 85 | 86 | *Note Defining Variables::, for more details. 87 | 88 | Compiling For Multiple Architectures 89 | ==================================== 90 | 91 | You can compile the package for more than one kind of computer at the 92 | same time, by placing the object files for each architecture in their 93 | own directory. To do this, you can use GNU `make'. `cd' to the 94 | directory where you want the object files and executables to go and run 95 | the `configure' script. `configure' automatically checks for the 96 | source code in the directory that `configure' is in and in `..'. 97 | 98 | With a non-GNU `make', it is safer to compile the package for one 99 | architecture at a time in the source code directory. After you have 100 | installed the package for one architecture, use `make distclean' before 101 | reconfiguring for another architecture. 102 | 103 | On MacOS X 10.5 and later systems, you can create libraries and 104 | executables that work on multiple system types--known as "fat" or 105 | "universal" binaries--by specifying multiple `-arch' options to the 106 | compiler but only a single `-arch' option to the preprocessor. Like 107 | this: 108 | 109 | ./configure CC="gcc -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ 110 | CXX="g++ -arch i386 -arch x86_64 -arch ppc -arch ppc64" \ 111 | CPP="gcc -E" CXXCPP="g++ -E" 112 | 113 | This is not guaranteed to produce working output in all cases, you 114 | may have to build one architecture at a time and combine the results 115 | using the `lipo' tool if you have problems. 116 | 117 | Installation Names 118 | ================== 119 | 120 | By default, `make install' installs the package's commands under 121 | `/usr/local/bin', include files under `/usr/local/include', etc. You 122 | can specify an installation prefix other than `/usr/local' by giving 123 | `configure' the option `--prefix=PREFIX'. 124 | 125 | You can specify separate installation prefixes for 126 | architecture-specific files and architecture-independent files. If you 127 | pass the option `--exec-prefix=PREFIX' to `configure', the package uses 128 | PREFIX as the prefix for installing programs and libraries. 129 | Documentation and other data files still use the regular prefix. 130 | 131 | In addition, if you use an unusual directory layout you can give 132 | options like `--bindir=DIR' to specify different values for particular 133 | kinds of files. Run `configure --help' for a list of the directories 134 | you can set and what kinds of files go in them. 135 | 136 | If the package supports it, you can cause programs to be installed 137 | with an extra prefix or suffix on their names by giving `configure' the 138 | option `--program-prefix=PREFIX' or `--program-suffix=SUFFIX'. 139 | 140 | Optional Features 141 | ================= 142 | 143 | Some packages pay attention to `--enable-FEATURE' options to 144 | `configure', where FEATURE indicates an optional part of the package. 145 | They may also pay attention to `--with-PACKAGE' options, where PACKAGE 146 | is something like `gnu-as' or `x' (for the X Window System). The 147 | `README' should mention any `--enable-' and `--with-' options that the 148 | package recognizes. 149 | 150 | For packages that use the X Window System, `configure' can usually 151 | find the X include and library files automatically, but if it doesn't, 152 | you can use the `configure' options `--x-includes=DIR' and 153 | `--x-libraries=DIR' to specify their locations. 154 | 155 | Particular systems 156 | ================== 157 | 158 | On HP-UX, the default C compiler is not ANSI C compatible. If GNU 159 | CC is not installed, it is recommended to use the following options in 160 | order to use an ANSI C compiler: 161 | 162 | ./configure CC="cc -Ae" 163 | 164 | and if that doesn't work, install pre-built binaries of GCC for HP-UX. 165 | 166 | On OSF/1 a.k.a. Tru64, some versions of the default C compiler cannot 167 | parse its `' header file. The option `-nodtk' can be used as 168 | a workaround. If GNU CC is not installed, it is therefore recommended 169 | to try 170 | 171 | ./configure CC="cc" 172 | 173 | and if that doesn't work, try 174 | 175 | ./configure CC="cc -nodtk" 176 | 177 | Specifying the System Type 178 | ========================== 179 | 180 | There may be some features `configure' cannot figure out 181 | automatically, but needs to determine by the type of machine the package 182 | will run on. Usually, assuming the package is built to be run on the 183 | _same_ architectures, `configure' can figure that out, but if it prints 184 | a message saying it cannot guess the machine type, give it the 185 | `--build=TYPE' option. TYPE can either be a short name for the system 186 | type, such as `sun4', or a canonical name which has the form: 187 | 188 | CPU-COMPANY-SYSTEM 189 | 190 | where SYSTEM can have one of these forms: 191 | 192 | OS KERNEL-OS 193 | 194 | See the file `config.sub' for the possible values of each field. If 195 | `config.sub' isn't included in this package, then this package doesn't 196 | need to know the machine type. 197 | 198 | If you are _building_ compiler tools for cross-compiling, you should 199 | use the option `--target=TYPE' to select the type of system they will 200 | produce code for. 201 | 202 | If you want to _use_ a cross compiler, that generates code for a 203 | platform different from the build platform, you should specify the 204 | "host" platform (i.e., that on which the generated programs will 205 | eventually be run) with `--host=TYPE'. 206 | 207 | Sharing Defaults 208 | ================ 209 | 210 | If you want to set default values for `configure' scripts to share, 211 | you can create a site shell script called `config.site' that gives 212 | default values for variables like `CC', `cache_file', and `prefix'. 213 | `configure' looks for `PREFIX/share/config.site' if it exists, then 214 | `PREFIX/etc/config.site' if it exists. Or, you can set the 215 | `CONFIG_SITE' environment variable to the location of the site script. 216 | A warning: not all `configure' scripts look for a site script. 217 | 218 | Defining Variables 219 | ================== 220 | 221 | Variables not defined in a site shell script can be set in the 222 | environment passed to `configure'. However, some packages may run 223 | configure again during the build, and the customized values of these 224 | variables may be lost. In order to avoid this problem, you should set 225 | them in the `configure' command line, using `VAR=value'. For example: 226 | 227 | ./configure CC=/usr/local2/bin/gcc 228 | 229 | causes the specified `gcc' to be used as the C compiler (unless it is 230 | overridden in the site shell script). 231 | 232 | Unfortunately, this technique does not work for `CONFIG_SHELL' due to 233 | an Autoconf bug. Until the bug is fixed you can use this workaround: 234 | 235 | CONFIG_SHELL=/bin/bash /bin/bash ./configure CONFIG_SHELL=/bin/bash 236 | 237 | `configure' Invocation 238 | ====================== 239 | 240 | `configure' recognizes the following options to control how it 241 | operates. 242 | 243 | `--help' 244 | `-h' 245 | Print a summary of all of the options to `configure', and exit. 246 | 247 | `--help=short' 248 | `--help=recursive' 249 | Print a summary of the options unique to this package's 250 | `configure', and exit. The `short' variant lists options used 251 | only in the top level, while the `recursive' variant lists options 252 | also present in any nested packages. 253 | 254 | `--version' 255 | `-V' 256 | Print the version of Autoconf used to generate the `configure' 257 | script, and exit. 258 | 259 | `--cache-file=FILE' 260 | Enable the cache: use and save the results of the tests in FILE, 261 | traditionally `config.cache'. FILE defaults to `/dev/null' to 262 | disable caching. 263 | 264 | `--config-cache' 265 | `-C' 266 | Alias for `--cache-file=config.cache'. 267 | 268 | `--quiet' 269 | `--silent' 270 | `-q' 271 | Do not print messages saying which checks are being made. To 272 | suppress all normal output, redirect it to `/dev/null' (any error 273 | messages will still be shown). 274 | 275 | `--srcdir=DIR' 276 | Look for the package's source code in directory DIR. Usually 277 | `configure' can determine that directory automatically. 278 | 279 | `--prefix=DIR' 280 | Use DIR as the installation prefix. *Note Installation Names:: 281 | for more details, including other options available for fine-tuning 282 | the installation locations. 283 | 284 | `--no-create' 285 | `-n' 286 | Run the configure checks, but stop before creating any output 287 | files. 288 | 289 | `configure' also accepts some other, not widely useful, options. Run 290 | `configure --help' for more details. 291 | 292 | -------------------------------------------------------------------------------- /Makefile.am: -------------------------------------------------------------------------------- 1 | # 2 | # This file is part of Sylverant PSO Server. 3 | # 4 | # Copyright (C) 2009, 2014, 2018 Lawrence Sebald 5 | # 6 | # This program is free software: you can redistribute it and/or modify 7 | # it under the terms of the GNU Affero General Public License version 3 8 | # as published by the Free Software Foundation. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU Affero General Public License for more details. 14 | # 15 | # You should have received a copy of the GNU Affero General Public License 16 | # along with this program. If not, see . 17 | 18 | ACLOCAL_AMFLAGS = -I m4 19 | 20 | LIBS += $(MYSQL_LIBS) $(LIBICONV) 21 | 22 | bin_PROGRAMS = shipgate 23 | shipgate_SOURCES = src/packets.c src/ship.c src/ship.h src/ship_packets.h \ 24 | src/shipgate.c src/shipgate.h src/scripts.c src/scripts.h 25 | 26 | if NEED_PIDFILE 27 | AM_CFLAGS = -DNEED_PIDFILE=1 28 | shipgate_SOURCES += src/pidfile.c 29 | endif 30 | 31 | datarootdir = @datarootdir@ 32 | -------------------------------------------------------------------------------- /NEWS: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sylverant/shipgate/d0f0a3ab3a32aef3a14f79f32a69420442e7d965/NEWS -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Sylverant/shipgate/d0f0a3ab3a32aef3a14f79f32a69420442e7d965/README -------------------------------------------------------------------------------- /autogen.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | libtoolize --install --copy && aclocal && autoconf && automake --add-missing --copy 3 | 4 | -------------------------------------------------------------------------------- /config.rpath: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | # Output a system dependent set of variables, describing how to set the 3 | # run time search path of shared libraries in an executable. 4 | # 5 | # Copyright 1996-2014 Free Software Foundation, Inc. 6 | # Taken from GNU libtool, 2001 7 | # Originally by Gordon Matzigkeit , 1996 8 | # 9 | # This file is free software; the Free Software Foundation gives 10 | # unlimited permission to copy and/or distribute it, with or without 11 | # modifications, as long as this notice is preserved. 12 | # 13 | # The first argument passed to this file is the canonical host specification, 14 | # CPU_TYPE-MANUFACTURER-OPERATING_SYSTEM 15 | # or 16 | # CPU_TYPE-MANUFACTURER-KERNEL-OPERATING_SYSTEM 17 | # The environment variables CC, GCC, LDFLAGS, LD, with_gnu_ld 18 | # should be set by the caller. 19 | # 20 | # The set of defined variables is at the end of this script. 21 | 22 | # Known limitations: 23 | # - On IRIX 6.5 with CC="cc", the run time search patch must not be longer 24 | # than 256 bytes, otherwise the compiler driver will dump core. The only 25 | # known workaround is to choose shorter directory names for the build 26 | # directory and/or the installation directory. 27 | 28 | # All known linkers require a '.a' archive for static linking (except MSVC, 29 | # which needs '.lib'). 30 | libext=a 31 | shrext=.so 32 | 33 | host="$1" 34 | host_cpu=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\1/'` 35 | host_vendor=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\2/'` 36 | host_os=`echo "$host" | sed 's/^\([^-]*\)-\([^-]*\)-\(.*\)$/\3/'` 37 | 38 | # Code taken from libtool.m4's _LT_CC_BASENAME. 39 | 40 | for cc_temp in $CC""; do 41 | case $cc_temp in 42 | compile | *[\\/]compile | ccache | *[\\/]ccache ) ;; 43 | distcc | *[\\/]distcc | purify | *[\\/]purify ) ;; 44 | \-*) ;; 45 | *) break;; 46 | esac 47 | done 48 | cc_basename=`echo "$cc_temp" | sed -e 's%^.*/%%'` 49 | 50 | # Code taken from libtool.m4's _LT_COMPILER_PIC. 51 | 52 | wl= 53 | if test "$GCC" = yes; then 54 | wl='-Wl,' 55 | else 56 | case "$host_os" in 57 | aix*) 58 | wl='-Wl,' 59 | ;; 60 | mingw* | cygwin* | pw32* | os2* | cegcc*) 61 | ;; 62 | hpux9* | hpux10* | hpux11*) 63 | wl='-Wl,' 64 | ;; 65 | irix5* | irix6* | nonstopux*) 66 | wl='-Wl,' 67 | ;; 68 | linux* | k*bsd*-gnu | kopensolaris*-gnu) 69 | case $cc_basename in 70 | ecc*) 71 | wl='-Wl,' 72 | ;; 73 | icc* | ifort*) 74 | wl='-Wl,' 75 | ;; 76 | lf95*) 77 | wl='-Wl,' 78 | ;; 79 | nagfor*) 80 | wl='-Wl,-Wl,,' 81 | ;; 82 | pgcc* | pgf77* | pgf90* | pgf95* | pgfortran*) 83 | wl='-Wl,' 84 | ;; 85 | ccc*) 86 | wl='-Wl,' 87 | ;; 88 | xl* | bgxl* | bgf* | mpixl*) 89 | wl='-Wl,' 90 | ;; 91 | como) 92 | wl='-lopt=' 93 | ;; 94 | *) 95 | case `$CC -V 2>&1 | sed 5q` in 96 | *Sun\ F* | *Sun*Fortran*) 97 | wl= 98 | ;; 99 | *Sun\ C*) 100 | wl='-Wl,' 101 | ;; 102 | esac 103 | ;; 104 | esac 105 | ;; 106 | newsos6) 107 | ;; 108 | *nto* | *qnx*) 109 | ;; 110 | osf3* | osf4* | osf5*) 111 | wl='-Wl,' 112 | ;; 113 | rdos*) 114 | ;; 115 | solaris*) 116 | case $cc_basename in 117 | f77* | f90* | f95* | sunf77* | sunf90* | sunf95*) 118 | wl='-Qoption ld ' 119 | ;; 120 | *) 121 | wl='-Wl,' 122 | ;; 123 | esac 124 | ;; 125 | sunos4*) 126 | wl='-Qoption ld ' 127 | ;; 128 | sysv4 | sysv4.2uw2* | sysv4.3*) 129 | wl='-Wl,' 130 | ;; 131 | sysv4*MP*) 132 | ;; 133 | sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*) 134 | wl='-Wl,' 135 | ;; 136 | unicos*) 137 | wl='-Wl,' 138 | ;; 139 | uts4*) 140 | ;; 141 | esac 142 | fi 143 | 144 | # Code taken from libtool.m4's _LT_LINKER_SHLIBS. 145 | 146 | hardcode_libdir_flag_spec= 147 | hardcode_libdir_separator= 148 | hardcode_direct=no 149 | hardcode_minus_L=no 150 | 151 | case "$host_os" in 152 | cygwin* | mingw* | pw32* | cegcc*) 153 | # FIXME: the MSVC++ port hasn't been tested in a loooong time 154 | # When not using gcc, we currently assume that we are using 155 | # Microsoft Visual C++. 156 | if test "$GCC" != yes; then 157 | with_gnu_ld=no 158 | fi 159 | ;; 160 | interix*) 161 | # we just hope/assume this is gcc and not c89 (= MSVC++) 162 | with_gnu_ld=yes 163 | ;; 164 | openbsd*) 165 | with_gnu_ld=no 166 | ;; 167 | esac 168 | 169 | ld_shlibs=yes 170 | if test "$with_gnu_ld" = yes; then 171 | # Set some defaults for GNU ld with shared library support. These 172 | # are reset later if shared libraries are not supported. Putting them 173 | # here allows them to be overridden if necessary. 174 | # Unlike libtool, we use -rpath here, not --rpath, since the documented 175 | # option of GNU ld is called -rpath, not --rpath. 176 | hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' 177 | case "$host_os" in 178 | aix[3-9]*) 179 | # On AIX/PPC, the GNU linker is very broken 180 | if test "$host_cpu" != ia64; then 181 | ld_shlibs=no 182 | fi 183 | ;; 184 | amigaos*) 185 | case "$host_cpu" in 186 | powerpc) 187 | ;; 188 | m68k) 189 | hardcode_libdir_flag_spec='-L$libdir' 190 | hardcode_minus_L=yes 191 | ;; 192 | esac 193 | ;; 194 | beos*) 195 | if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then 196 | : 197 | else 198 | ld_shlibs=no 199 | fi 200 | ;; 201 | cygwin* | mingw* | pw32* | cegcc*) 202 | # hardcode_libdir_flag_spec is actually meaningless, as there is 203 | # no search path for DLLs. 204 | hardcode_libdir_flag_spec='-L$libdir' 205 | if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then 206 | : 207 | else 208 | ld_shlibs=no 209 | fi 210 | ;; 211 | haiku*) 212 | ;; 213 | interix[3-9]*) 214 | hardcode_direct=no 215 | hardcode_libdir_flag_spec='${wl}-rpath,$libdir' 216 | ;; 217 | gnu* | linux* | tpf* | k*bsd*-gnu | kopensolaris*-gnu) 218 | if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then 219 | : 220 | else 221 | ld_shlibs=no 222 | fi 223 | ;; 224 | netbsd*) 225 | ;; 226 | solaris*) 227 | if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then 228 | ld_shlibs=no 229 | elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then 230 | : 231 | else 232 | ld_shlibs=no 233 | fi 234 | ;; 235 | sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*) 236 | case `$LD -v 2>&1` in 237 | *\ [01].* | *\ 2.[0-9].* | *\ 2.1[0-5].*) 238 | ld_shlibs=no 239 | ;; 240 | *) 241 | if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then 242 | hardcode_libdir_flag_spec='`test -z "$SCOABSPATH" && echo ${wl}-rpath,$libdir`' 243 | else 244 | ld_shlibs=no 245 | fi 246 | ;; 247 | esac 248 | ;; 249 | sunos4*) 250 | hardcode_direct=yes 251 | ;; 252 | *) 253 | if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then 254 | : 255 | else 256 | ld_shlibs=no 257 | fi 258 | ;; 259 | esac 260 | if test "$ld_shlibs" = no; then 261 | hardcode_libdir_flag_spec= 262 | fi 263 | else 264 | case "$host_os" in 265 | aix3*) 266 | # Note: this linker hardcodes the directories in LIBPATH if there 267 | # are no directories specified by -L. 268 | hardcode_minus_L=yes 269 | if test "$GCC" = yes; then 270 | # Neither direct hardcoding nor static linking is supported with a 271 | # broken collect2. 272 | hardcode_direct=unsupported 273 | fi 274 | ;; 275 | aix[4-9]*) 276 | if test "$host_cpu" = ia64; then 277 | # On IA64, the linker does run time linking by default, so we don't 278 | # have to do anything special. 279 | aix_use_runtimelinking=no 280 | else 281 | aix_use_runtimelinking=no 282 | # Test if we are trying to use run time linking or normal 283 | # AIX style linking. If -brtl is somewhere in LDFLAGS, we 284 | # need to do runtime linking. 285 | case $host_os in aix4.[23]|aix4.[23].*|aix[5-9]*) 286 | for ld_flag in $LDFLAGS; do 287 | if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then 288 | aix_use_runtimelinking=yes 289 | break 290 | fi 291 | done 292 | ;; 293 | esac 294 | fi 295 | hardcode_direct=yes 296 | hardcode_libdir_separator=':' 297 | if test "$GCC" = yes; then 298 | case $host_os in aix4.[012]|aix4.[012].*) 299 | collect2name=`${CC} -print-prog-name=collect2` 300 | if test -f "$collect2name" && \ 301 | strings "$collect2name" | grep resolve_lib_name >/dev/null 302 | then 303 | # We have reworked collect2 304 | : 305 | else 306 | # We have old collect2 307 | hardcode_direct=unsupported 308 | hardcode_minus_L=yes 309 | hardcode_libdir_flag_spec='-L$libdir' 310 | hardcode_libdir_separator= 311 | fi 312 | ;; 313 | esac 314 | fi 315 | # Begin _LT_AC_SYS_LIBPATH_AIX. 316 | echo 'int main () { return 0; }' > conftest.c 317 | ${CC} ${LDFLAGS} conftest.c -o conftest 318 | aix_libpath=`dump -H conftest 2>/dev/null | sed -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } 319 | }'` 320 | if test -z "$aix_libpath"; then 321 | aix_libpath=`dump -HX64 conftest 2>/dev/null | sed -n -e '/Import File Strings/,/^$/ { /^0/ { s/^0 *\(.*\)$/\1/; p; } 322 | }'` 323 | fi 324 | if test -z "$aix_libpath"; then 325 | aix_libpath="/usr/lib:/lib" 326 | fi 327 | rm -f conftest.c conftest 328 | # End _LT_AC_SYS_LIBPATH_AIX. 329 | if test "$aix_use_runtimelinking" = yes; then 330 | hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath" 331 | else 332 | if test "$host_cpu" = ia64; then 333 | hardcode_libdir_flag_spec='${wl}-R $libdir:/usr/lib:/lib' 334 | else 335 | hardcode_libdir_flag_spec='${wl}-blibpath:$libdir:'"$aix_libpath" 336 | fi 337 | fi 338 | ;; 339 | amigaos*) 340 | case "$host_cpu" in 341 | powerpc) 342 | ;; 343 | m68k) 344 | hardcode_libdir_flag_spec='-L$libdir' 345 | hardcode_minus_L=yes 346 | ;; 347 | esac 348 | ;; 349 | bsdi[45]*) 350 | ;; 351 | cygwin* | mingw* | pw32* | cegcc*) 352 | # When not using gcc, we currently assume that we are using 353 | # Microsoft Visual C++. 354 | # hardcode_libdir_flag_spec is actually meaningless, as there is 355 | # no search path for DLLs. 356 | hardcode_libdir_flag_spec=' ' 357 | libext=lib 358 | ;; 359 | darwin* | rhapsody*) 360 | hardcode_direct=no 361 | if { case $cc_basename in ifort*) true;; *) test "$GCC" = yes;; esac; }; then 362 | : 363 | else 364 | ld_shlibs=no 365 | fi 366 | ;; 367 | dgux*) 368 | hardcode_libdir_flag_spec='-L$libdir' 369 | ;; 370 | freebsd2.[01]*) 371 | hardcode_direct=yes 372 | hardcode_minus_L=yes 373 | ;; 374 | freebsd* | dragonfly*) 375 | hardcode_libdir_flag_spec='-R$libdir' 376 | hardcode_direct=yes 377 | ;; 378 | hpux9*) 379 | hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' 380 | hardcode_libdir_separator=: 381 | hardcode_direct=yes 382 | # hardcode_minus_L: Not really in the search PATH, 383 | # but as the default location of the library. 384 | hardcode_minus_L=yes 385 | ;; 386 | hpux10*) 387 | if test "$with_gnu_ld" = no; then 388 | hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' 389 | hardcode_libdir_separator=: 390 | hardcode_direct=yes 391 | # hardcode_minus_L: Not really in the search PATH, 392 | # but as the default location of the library. 393 | hardcode_minus_L=yes 394 | fi 395 | ;; 396 | hpux11*) 397 | if test "$with_gnu_ld" = no; then 398 | hardcode_libdir_flag_spec='${wl}+b ${wl}$libdir' 399 | hardcode_libdir_separator=: 400 | case $host_cpu in 401 | hppa*64*|ia64*) 402 | hardcode_direct=no 403 | ;; 404 | *) 405 | hardcode_direct=yes 406 | # hardcode_minus_L: Not really in the search PATH, 407 | # but as the default location of the library. 408 | hardcode_minus_L=yes 409 | ;; 410 | esac 411 | fi 412 | ;; 413 | irix5* | irix6* | nonstopux*) 414 | hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' 415 | hardcode_libdir_separator=: 416 | ;; 417 | netbsd*) 418 | hardcode_libdir_flag_spec='-R$libdir' 419 | hardcode_direct=yes 420 | ;; 421 | newsos6) 422 | hardcode_direct=yes 423 | hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' 424 | hardcode_libdir_separator=: 425 | ;; 426 | *nto* | *qnx*) 427 | ;; 428 | openbsd*) 429 | if test -f /usr/libexec/ld.so; then 430 | hardcode_direct=yes 431 | if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then 432 | hardcode_libdir_flag_spec='${wl}-rpath,$libdir' 433 | else 434 | case "$host_os" in 435 | openbsd[01].* | openbsd2.[0-7] | openbsd2.[0-7].*) 436 | hardcode_libdir_flag_spec='-R$libdir' 437 | ;; 438 | *) 439 | hardcode_libdir_flag_spec='${wl}-rpath,$libdir' 440 | ;; 441 | esac 442 | fi 443 | else 444 | ld_shlibs=no 445 | fi 446 | ;; 447 | os2*) 448 | hardcode_libdir_flag_spec='-L$libdir' 449 | hardcode_minus_L=yes 450 | ;; 451 | osf3*) 452 | hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' 453 | hardcode_libdir_separator=: 454 | ;; 455 | osf4* | osf5*) 456 | if test "$GCC" = yes; then 457 | hardcode_libdir_flag_spec='${wl}-rpath ${wl}$libdir' 458 | else 459 | # Both cc and cxx compiler support -rpath directly 460 | hardcode_libdir_flag_spec='-rpath $libdir' 461 | fi 462 | hardcode_libdir_separator=: 463 | ;; 464 | solaris*) 465 | hardcode_libdir_flag_spec='-R$libdir' 466 | ;; 467 | sunos4*) 468 | hardcode_libdir_flag_spec='-L$libdir' 469 | hardcode_direct=yes 470 | hardcode_minus_L=yes 471 | ;; 472 | sysv4) 473 | case $host_vendor in 474 | sni) 475 | hardcode_direct=yes # is this really true??? 476 | ;; 477 | siemens) 478 | hardcode_direct=no 479 | ;; 480 | motorola) 481 | hardcode_direct=no #Motorola manual says yes, but my tests say they lie 482 | ;; 483 | esac 484 | ;; 485 | sysv4.3*) 486 | ;; 487 | sysv4*MP*) 488 | if test -d /usr/nec; then 489 | ld_shlibs=yes 490 | fi 491 | ;; 492 | sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[01].[10]* | unixware7* | sco3.2v5.0.[024]*) 493 | ;; 494 | sysv5* | sco3.2v5* | sco5v6*) 495 | hardcode_libdir_flag_spec='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`' 496 | hardcode_libdir_separator=':' 497 | ;; 498 | uts4*) 499 | hardcode_libdir_flag_spec='-L$libdir' 500 | ;; 501 | *) 502 | ld_shlibs=no 503 | ;; 504 | esac 505 | fi 506 | 507 | # Check dynamic linker characteristics 508 | # Code taken from libtool.m4's _LT_SYS_DYNAMIC_LINKER. 509 | # Unlike libtool.m4, here we don't care about _all_ names of the library, but 510 | # only about the one the linker finds when passed -lNAME. This is the last 511 | # element of library_names_spec in libtool.m4, or possibly two of them if the 512 | # linker has special search rules. 513 | library_names_spec= # the last element of library_names_spec in libtool.m4 514 | libname_spec='lib$name' 515 | case "$host_os" in 516 | aix3*) 517 | library_names_spec='$libname.a' 518 | ;; 519 | aix[4-9]*) 520 | library_names_spec='$libname$shrext' 521 | ;; 522 | amigaos*) 523 | case "$host_cpu" in 524 | powerpc*) 525 | library_names_spec='$libname$shrext' ;; 526 | m68k) 527 | library_names_spec='$libname.a' ;; 528 | esac 529 | ;; 530 | beos*) 531 | library_names_spec='$libname$shrext' 532 | ;; 533 | bsdi[45]*) 534 | library_names_spec='$libname$shrext' 535 | ;; 536 | cygwin* | mingw* | pw32* | cegcc*) 537 | shrext=.dll 538 | library_names_spec='$libname.dll.a $libname.lib' 539 | ;; 540 | darwin* | rhapsody*) 541 | shrext=.dylib 542 | library_names_spec='$libname$shrext' 543 | ;; 544 | dgux*) 545 | library_names_spec='$libname$shrext' 546 | ;; 547 | freebsd[23].*) 548 | library_names_spec='$libname$shrext$versuffix' 549 | ;; 550 | freebsd* | dragonfly*) 551 | library_names_spec='$libname$shrext' 552 | ;; 553 | gnu*) 554 | library_names_spec='$libname$shrext' 555 | ;; 556 | haiku*) 557 | library_names_spec='$libname$shrext' 558 | ;; 559 | hpux9* | hpux10* | hpux11*) 560 | case $host_cpu in 561 | ia64*) 562 | shrext=.so 563 | ;; 564 | hppa*64*) 565 | shrext=.sl 566 | ;; 567 | *) 568 | shrext=.sl 569 | ;; 570 | esac 571 | library_names_spec='$libname$shrext' 572 | ;; 573 | interix[3-9]*) 574 | library_names_spec='$libname$shrext' 575 | ;; 576 | irix5* | irix6* | nonstopux*) 577 | library_names_spec='$libname$shrext' 578 | case "$host_os" in 579 | irix5* | nonstopux*) 580 | libsuff= shlibsuff= 581 | ;; 582 | *) 583 | case $LD in 584 | *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ") libsuff= shlibsuff= ;; 585 | *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ") libsuff=32 shlibsuff=N32 ;; 586 | *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ") libsuff=64 shlibsuff=64 ;; 587 | *) libsuff= shlibsuff= ;; 588 | esac 589 | ;; 590 | esac 591 | ;; 592 | linux*oldld* | linux*aout* | linux*coff*) 593 | ;; 594 | linux* | k*bsd*-gnu | kopensolaris*-gnu) 595 | library_names_spec='$libname$shrext' 596 | ;; 597 | knetbsd*-gnu) 598 | library_names_spec='$libname$shrext' 599 | ;; 600 | netbsd*) 601 | library_names_spec='$libname$shrext' 602 | ;; 603 | newsos6) 604 | library_names_spec='$libname$shrext' 605 | ;; 606 | *nto* | *qnx*) 607 | library_names_spec='$libname$shrext' 608 | ;; 609 | openbsd*) 610 | library_names_spec='$libname$shrext$versuffix' 611 | ;; 612 | os2*) 613 | libname_spec='$name' 614 | shrext=.dll 615 | library_names_spec='$libname.a' 616 | ;; 617 | osf3* | osf4* | osf5*) 618 | library_names_spec='$libname$shrext' 619 | ;; 620 | rdos*) 621 | ;; 622 | solaris*) 623 | library_names_spec='$libname$shrext' 624 | ;; 625 | sunos4*) 626 | library_names_spec='$libname$shrext$versuffix' 627 | ;; 628 | sysv4 | sysv4.3*) 629 | library_names_spec='$libname$shrext' 630 | ;; 631 | sysv4*MP*) 632 | library_names_spec='$libname$shrext' 633 | ;; 634 | sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*) 635 | library_names_spec='$libname$shrext' 636 | ;; 637 | tpf*) 638 | library_names_spec='$libname$shrext' 639 | ;; 640 | uts4*) 641 | library_names_spec='$libname$shrext' 642 | ;; 643 | esac 644 | 645 | sed_quote_subst='s/\(["`$\\]\)/\\\1/g' 646 | escaped_wl=`echo "X$wl" | sed -e 's/^X//' -e "$sed_quote_subst"` 647 | shlibext=`echo "$shrext" | sed -e 's,^\.,,'` 648 | escaped_libname_spec=`echo "X$libname_spec" | sed -e 's/^X//' -e "$sed_quote_subst"` 649 | escaped_library_names_spec=`echo "X$library_names_spec" | sed -e 's/^X//' -e "$sed_quote_subst"` 650 | escaped_hardcode_libdir_flag_spec=`echo "X$hardcode_libdir_flag_spec" | sed -e 's/^X//' -e "$sed_quote_subst"` 651 | 652 | LC_ALL=C sed -e 's/^\([a-zA-Z0-9_]*\)=/acl_cv_\1=/' <. 17 | 18 | AC_PREREQ([2.61]) 19 | AC_INIT([shipgate], [0.1.0]) 20 | AC_CONFIG_MACRO_DIR([m4]) 21 | 22 | version_major=0 23 | version_minor=1 24 | version_micro=0 25 | 26 | AC_SUBST([version_major]) 27 | AC_SUBST([version_minor]) 28 | AC_SUBST([version_micro]) 29 | 30 | AC_DEFINE_UNQUOTED([VERSION_MAJOR], [$version_major], [Major Package Version]) 31 | AC_DEFINE_UNQUOTED([VERSION_MINOR], [$version_minor], [Minor Package Version]) 32 | AC_DEFINE_UNQUOTED([VERSION_MICRO], [$version_micro], [Micro Package Version]) 33 | 34 | AC_CANONICAL_HOST 35 | AC_CANONICAL_TARGET 36 | 37 | AM_INIT_AUTOMAKE([subdir-objects]) 38 | AC_PROG_INSTALL 39 | AC_PROG_LIBTOOL 40 | 41 | AC_LANG(C) 42 | 43 | AC_CONFIG_SRCDIR([src/packets.c]) 44 | 45 | # Checks for programs. 46 | AC_PROG_CC 47 | 48 | AM_ICONV 49 | AM_ICONV_LINK 50 | 51 | # Checks for libraries. 52 | PKG_CHECK_MODULES([libxml2], [libxml-2.0 >= 2.7]) 53 | CFLAGS="$CFLAGS $libxml2_CFLAGS" 54 | LIBS="$LIBS $libxml2_LIBS" 55 | 56 | PKG_CHECK_MODULES([gnutls], [gnutls >= 2.0]) 57 | CFLAGS="$CFLAGS $gnutls_CFLAGS" 58 | LIBS="$LIBS $gnutls_LIBS" 59 | 60 | MYSQL_CLIENT() 61 | AC_CHECK_LIB([sylverant], [sylverant_read_config], , AC_MSG_ERROR([libsylverant is required!])) 62 | AC_CHECK_LIB([z], [compress2], , AC_MSG_ERROR([zlib is required!])) 63 | AC_SEARCH_LIBS([pidfile_open], [util bsd], [NEED_PIDFILE=0], [NEED_PIDFILE=1]) 64 | 65 | MYSQL_LIBS="`mysql_config --libs`" 66 | AC_SUBST(MYSQL_LIBS) 67 | AM_CONDITIONAL([NEED_PIDFILE], [test "$NEED_PIDFILE" -eq 1]) 68 | 69 | AC_ARG_ENABLE([scripting], [AS_HELP_STRING([--enable-scripting], 70 | [enable scripting support in the binary (requires Lua 5.3.x)])], 71 | [enable_scripting=$enableval], 72 | [enable_scripting=no]) 73 | 74 | AS_IF([test "x$enable_scripting" != xno], [ 75 | PKG_CHECK_MODULES([lua], [lua-5.3], , [ 76 | PKG_CHECK_MODULES([lua], [lua5.3], , [ 77 | PKG_CHECK_MODULES([lua], [lua >= 5.3], , [ 78 | AC_MSG_ERROR([Scripting support requires Lua 5.3.x!]) 79 | ]) 80 | ]) 81 | ]) 82 | 83 | CFLAGS="$CFLAGS $lua_CFLAGS -DENABLE_LUA" 84 | LIBS="$LIBS $lua_LIBS" 85 | ]) 86 | 87 | # Checks for header files. 88 | AC_CHECK_HEADERS([arpa/inet.h inttypes.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h pwd.h grp.h]) 89 | AC_CHECK_HEADERS([libutil.h bsd/libutil.h]) 90 | 91 | # Checks for typedefs, structures, and compiler characteristics. 92 | AC_TYPE_SSIZE_T 93 | AC_TYPE_UINT16_T 94 | AC_TYPE_UINT32_T 95 | AC_TYPE_UINT8_T 96 | AC_C_BIGENDIAN 97 | AC_CHECK_SIZEOF([int]) 98 | AC_CHECK_SIZEOF([long int]) 99 | AC_CHECK_SIZEOF([void*]) 100 | 101 | # Checks for library functions. 102 | AC_CHECK_FUNCS([malloc realloc inet_ntoa memmove memset select socket getgrouplist]) 103 | 104 | ADD_CFLAGS([-Wall]) 105 | 106 | AC_CONFIG_FILES([Makefile]) 107 | 108 | AC_OUTPUT 109 | -------------------------------------------------------------------------------- /m4/cflags.m4: -------------------------------------------------------------------------------- 1 | AC_DEFUN([ADD_CFLAGS], 2 | [ 3 | AC_MSG_CHECKING([if $CC accepts $1]) 4 | add_cflags_olds="$CFLAGS" 5 | CFLAGS="$CFLAGS $1" 6 | AC_COMPILE_IFELSE([AC_LANG_SOURCE([int main() { return 0; }])], 7 | AC_MSG_RESULT([yes]), 8 | AC_MSG_RESULT([no]) 9 | CFLAGS="$add_cflags_old") 10 | ]) 11 | -------------------------------------------------------------------------------- /m4/mysql.m4: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2007 MySQL AB 2 | # 3 | # This program is free software; you can redistribute it and/or modify it 4 | # under the terms of the GNU General Public License as published by the Free 5 | # Software Foundation; version 2 of the License. 6 | # 7 | # This program is distributed in the hope that it will be useful, but 8 | # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 9 | # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 10 | # for more details. 11 | # 12 | # You should have received a copy of the GNU General Public License along 13 | # with this program; if not, write to the Free Software Foundation, Inc., 59 14 | # Temple Place, Suite 330, Boston, MA 02111-1307 USA 15 | 16 | AC_DEFUN([_MYSQL_CONFIG],[ 17 | AC_ARG_WITH([mysql-config], 18 | AS_HELP_STRING([--with-mysql-config=PATH], [A path to mysql_config script]), 19 | [mysql_config="$withval"], [mysql_config=mysql_config]) 20 | ]) 21 | 22 | dnl 23 | dnl Usage: 24 | dnl 25 | dnl MYSQL_CLIENT([version], [client|thread-safe|embedded]) 26 | dnl 27 | dnl Two optional arguments: 28 | dnl first: The minimal version of the MySQL to use 29 | dnl if not specified, any version will be accepted. 30 | dnl The version should be specified as three numbers, 31 | dnl without suffixes. E.g. 4.10.15 or 5.0.3 32 | dnl second: force the specified library flavor to be selected, 33 | dnl if not specified, a user will be able to choose 34 | dnl between client (non-thread-safe) and embedded 35 | dnl 36 | dnl On successful execution sets MYSQL_CLIENT_CFLAGS and 37 | dnl MYSQL_CLIENT_LIBS shell variables and makes substitutions 38 | dnl out of them (calls AC_SUBST) 39 | dnl 40 | 41 | AC_DEFUN([MYSQL_CLIENT],[ 42 | AC_REQUIRE([_MYSQL_CONFIG]) 43 | AC_MSG_CHECKING([for MySQL]) 44 | ifelse([$2], [client], 45 | [mysql_libs=--libs mysql_cflags=--cflags], 46 | [$2], [thread-safe], 47 | [mysql_libs=--libs_r mysql_cflags=--cflags], 48 | [$2], [embedded], 49 | [mysql_libs=--libmysqld-libs mysql_cflags=--cflags], 50 | [$2], [], [ 51 | AC_ARG_WITH([mysql-library], 52 | AS_HELP_STRING([--with-mysql-library], ['client' or 'embedded']), 53 | [mysql_lib="$withval"], [mysql_lib=client]) 54 | [ 55 | case "$mysql_lib" in 56 | client) mysql_libs=--libs mysql_cflags=--cflags ;; 57 | embedded) mysql_libs=--libmysqld-libs mysql_cflags=--cflags ;; 58 | *) ]AC_MSG_ERROR([Bad value for --with-mysql-library])[ 59 | esac 60 | ] 61 | ], 62 | [AC_FATAL([Bad second (library flavor) argument to MYSQL_CLIENT])]) 63 | [ 64 | mysql_version=`$mysql_config --version` 65 | if test -z "$mysql_version" ; then 66 | ]AC_MSG_ERROR([Cannot execute $mysql_config])[ 67 | fi 68 | ] 69 | ifelse([$1], [], [], [ 70 | ifelse(regexp([$1], [^[0-9][0-9]?\.[0-9][0-9]?\.[0-9][0-9]?$]), -1, 71 | [AC_FATAL([Bad first (version) argument to MYSQL_CLIENT])], [ 72 | dnl 73 | dnl Transformation below works as follows: 74 | dnl assume, we have a number 1.2.3-beta 75 | dnl *a* line removes the suffix and adds first and last dot to the version: 76 | dnl .1.2.3. 77 | dnl *b* line adds a 0 to a "single digit surrounded by dots" 78 | dnl .01.2.03. 79 | dnl note that the pattern that matched .1. has eaten the dot for .2. 80 | dnl and 2 still has no 0 81 | dnl *c* we repeat the same replacement as in *b*, matching .2. this time 82 | dnl .01.02.03. 83 | dnl the last replacement removes all dots 84 | dnl 010203 85 | dnl giving us a number we can compare with 86 | dnl 87 | mysql_ver=`echo ${mysql_version}|dnl 88 | sed 's/[[-a-z]].*//; s/.*/.&./;dnl *a* 89 | s/\.\([[0-9]]\)\./.0\1./g;dnl *b* 90 | s/\.\([[0-9]]\)\./.0\1./g;dnl *c* 91 | s/\.//g'` 92 | if test "$mysql_ver" -lt]dnl 93 | dnl the same as sed transformation above, without suffix-stripping, in m4 94 | patsubst(patsubst(patsubst(.[$1]., [\.\([0-9]\)\.], [.0\1.]), [\.\([0-9]\)\.], [.0\1.]), [\.], [])[ ; then 95 | AC_MSG_ERROR([MySQL version $mysql_version is too low, minimum of $1 is required]) 96 | fi 97 | ])]) 98 | 99 | MYSQL_CLIENT_CFLAGS=`$mysql_config $mysql_cflags` 100 | MYSQL_CLIENT_LIBS=`$mysql_config $mysql_libs` 101 | AC_SUBST(MYSQL_CLIENT_CFLAGS) 102 | AC_SUBST(MYSQL_CLIENT_LIBS) 103 | 104 | # should we try to build a test program ? 105 | 106 | AC_MSG_RESULT([$mysql_version]) 107 | ]) 108 | 109 | -------------------------------------------------------------------------------- /src/packets.c: -------------------------------------------------------------------------------- 1 | /* 2 | Sylverant Shipgate 3 | Copyright (C) 2009, 2010, 2011, 2014, 2016, 2018, 2019, 2021 Lawrence Sebald 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU Affero General Public License version 3 7 | as published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Affero General Public License for more details. 13 | 14 | You should have received a copy of the GNU Affero General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | #include 25 | #include 26 | 27 | #include "shipgate.h" 28 | #include "ship.h" 29 | 30 | static uint8_t sendbuf[65536]; 31 | 32 | static ssize_t ship_send(ship_t *c, const void *buffer, size_t len) { 33 | return gnutls_record_send(c->session, buffer, len); 34 | } 35 | 36 | /* Send a raw packet away. */ 37 | static int send_raw(ship_t *c, int len) { 38 | ssize_t rv, total = 0; 39 | void *tmp; 40 | 41 | /* Keep trying until the whole thing's sent. */ 42 | if(!c->sendbuf_cur) { 43 | while(total < len) { 44 | rv = ship_send(c, sendbuf + total, len - total); 45 | 46 | /* Did the data send? */ 47 | if(rv < 0) { 48 | /* Is it an error code that might be correctable? */ 49 | if(rv == GNUTLS_E_AGAIN || rv == GNUTLS_E_INTERRUPTED) 50 | continue; 51 | else 52 | return -1; 53 | } 54 | 55 | total += rv; 56 | } 57 | } 58 | 59 | rv = len - total; 60 | 61 | if(rv) { 62 | /* Move out any already transferred data. */ 63 | if(c->sendbuf_start) { 64 | memmove(c->sendbuf, c->sendbuf + c->sendbuf_start, 65 | c->sendbuf_cur - c->sendbuf_start); 66 | c->sendbuf_cur -= c->sendbuf_start; 67 | } 68 | 69 | /* See if we need to reallocate the buffer. */ 70 | if(c->sendbuf_cur + rv > c->sendbuf_size) { 71 | tmp = realloc(c->sendbuf, c->sendbuf_cur + rv); 72 | 73 | /* If we can't allocate the space, bail. */ 74 | if(tmp == NULL) 75 | return -1; 76 | 77 | c->sendbuf_size = c->sendbuf_cur + rv; 78 | c->sendbuf = (unsigned char *)tmp; 79 | } 80 | 81 | /* Copy what's left of the packet into the output buffer. */ 82 | memcpy(c->sendbuf + c->sendbuf_cur, sendbuf + total, rv); 83 | c->sendbuf_cur += rv; 84 | } 85 | 86 | return 0; 87 | } 88 | 89 | /* Encrypt a packet, and send it away. */ 90 | static int send_crypt(ship_t *c, int len) { 91 | /* Make sure its at least a header in length. */ 92 | if(len < 8) 93 | return -1; 94 | 95 | return send_raw(c, len); 96 | } 97 | 98 | int forward_dreamcast(ship_t *c, dc_pkt_hdr_t *dc, uint32_t sender, 99 | uint32_t gc, uint32_t block) { 100 | shipgate_fw_9_pkt *pkt = (shipgate_fw_9_pkt *)sendbuf; 101 | int dc_len = LE16(dc->pkt_len); 102 | int full_len = sizeof(shipgate_fw_9_pkt) + dc_len; 103 | 104 | /* Round up the packet size, if needed. */ 105 | if(full_len & 0x07) 106 | full_len = (full_len + 8) & 0xFFF8; 107 | 108 | /* Scrub the buffer */ 109 | memset(pkt, 0, full_len); 110 | 111 | /* Fill in the shipgate header */ 112 | pkt->hdr.pkt_len = htons(full_len); 113 | pkt->hdr.pkt_type = htons(SHDR_TYPE_DC); 114 | pkt->hdr.flags = 0; 115 | pkt->hdr.reserved = 0; 116 | pkt->hdr.version = 0; 117 | 118 | /* Add the metadata */ 119 | pkt->ship_id = htonl(sender); 120 | pkt->guildcard = htonl(gc); 121 | pkt->block = htonl(block); 122 | 123 | /* Copy in the packet, unchanged */ 124 | memcpy(pkt->pkt, dc, dc_len); 125 | 126 | /* Send the packet away */ 127 | return send_crypt(c, full_len); 128 | } 129 | 130 | int forward_pc(ship_t *c, dc_pkt_hdr_t *pc, uint32_t sender, uint32_t gc, 131 | uint32_t block) { 132 | shipgate_fw_9_pkt *pkt = (shipgate_fw_9_pkt *)sendbuf; 133 | int pc_len = LE16(pc->pkt_len); 134 | int full_len = sizeof(shipgate_fw_9_pkt) + pc_len; 135 | 136 | /* Round up the packet size, if needed. */ 137 | if(full_len & 0x07) 138 | full_len = (full_len + 8) & 0xFFF8; 139 | 140 | /* Scrub the buffer */ 141 | memset(pkt, 0, full_len); 142 | 143 | /* Fill in the shipgate header */ 144 | pkt->hdr.pkt_len = htons(full_len); 145 | pkt->hdr.pkt_type = htons(SHDR_TYPE_PC); 146 | pkt->hdr.flags = 0; 147 | pkt->hdr.reserved = 0; 148 | pkt->hdr.version = 0; 149 | 150 | /* Add the metadata */ 151 | pkt->ship_id = htonl(sender); 152 | pkt->guildcard = htonl(gc); 153 | pkt->block = htonl(block); 154 | 155 | /* Copy in the packet, unchanged */ 156 | memcpy(pkt->pkt, pc, pc_len); 157 | 158 | /* Send the packet away */ 159 | return send_crypt(c, full_len); 160 | } 161 | 162 | int forward_bb(ship_t *c, bb_pkt_hdr_t *bb, uint32_t sender, uint32_t gc, 163 | uint32_t block) { 164 | shipgate_fw_9_pkt *pkt = (shipgate_fw_9_pkt *)sendbuf; 165 | int bb_len = LE16(bb->pkt_len); 166 | int full_len = sizeof(shipgate_fw_9_pkt) + bb_len; 167 | 168 | /* Round up the packet size, if needed. */ 169 | if(full_len & 0x07) 170 | full_len = (full_len + 8) & 0xFFF8; 171 | 172 | /* Scrub the buffer */ 173 | memset(pkt, 0, full_len); 174 | 175 | /* Fill in the shipgate header */ 176 | pkt->hdr.pkt_len = htons(full_len); 177 | pkt->hdr.pkt_type = htons(SHDR_TYPE_BB); 178 | pkt->hdr.flags = 0; 179 | pkt->hdr.reserved = 0; 180 | pkt->hdr.version = 0; 181 | 182 | /* Add the metadata */ 183 | pkt->ship_id = htonl(sender); 184 | pkt->guildcard = htonl(gc); 185 | pkt->block = htonl(block); 186 | 187 | /* Copy in the packet, unchanged */ 188 | memcpy(pkt->pkt, bb, bb_len); 189 | 190 | /* Send the packet away */ 191 | return send_crypt(c, full_len); 192 | } 193 | 194 | /* Send a welcome packet to the given ship. */ 195 | int send_welcome(ship_t *c) { 196 | shipgate_login_pkt *pkt = (shipgate_login_pkt *)sendbuf; 197 | 198 | /* Scrub the buffer */ 199 | memset(pkt, 0, sizeof(shipgate_login_pkt)); 200 | 201 | /* Fill in the header */ 202 | pkt->hdr.pkt_len = htons(sizeof(shipgate_login_pkt)); 203 | pkt->hdr.pkt_type = htons(SHDR_TYPE_LOGIN); 204 | pkt->hdr.flags = 0; 205 | pkt->hdr.reserved = 0; 206 | pkt->hdr.version = 0; 207 | 208 | /* Fill in the required message */ 209 | strcpy(pkt->msg, shipgate_login_msg); 210 | 211 | /* Fill in the version information */ 212 | pkt->ver_major = VERSION_MAJOR; 213 | pkt->ver_minor = VERSION_MINOR; 214 | pkt->ver_micro = VERSION_MICRO; 215 | 216 | /* Fill in the nonces */ 217 | memcpy(pkt->ship_nonce, c->ship_nonce, 4); 218 | memcpy(pkt->gate_nonce, c->gate_nonce, 4); 219 | 220 | /* Send the packet away */ 221 | return send_raw(c, sizeof(shipgate_login_pkt)); 222 | } 223 | 224 | int send_ship_status(ship_t *c, ship_t *o, uint16_t status) { 225 | shipgate_ship_status6_pkt *pkt = (shipgate_ship_status6_pkt *)sendbuf; 226 | 227 | /* If the ship hasn't finished logging in yet, don't send this. */ 228 | if(o->name[0] == 0) 229 | return 0; 230 | 231 | /* Scrub the buffer */ 232 | memset(pkt, 0, sizeof(shipgate_ship_status6_pkt)); 233 | 234 | /* Fill in the header */ 235 | pkt->hdr.pkt_len = htons(sizeof(shipgate_ship_status6_pkt)); 236 | pkt->hdr.pkt_type = htons(SHDR_TYPE_SSTATUS); 237 | pkt->hdr.flags = 0; 238 | pkt->hdr.reserved = 0; 239 | pkt->hdr.version = 0; 240 | 241 | /* Fill in the info */ 242 | memcpy(pkt->name, o->name, 12); 243 | pkt->ship_id = htonl(o->key_idx); 244 | pkt->ship_addr4 = o->remote_addr; 245 | memcpy(pkt->ship_addr6, &o->remote_addr6, 16); 246 | pkt->ship_port = htons(o->port); 247 | pkt->status = htons(status); 248 | pkt->flags = htonl(o->flags); 249 | pkt->clients = htons(o->clients); 250 | pkt->games = htons(o->games); 251 | pkt->menu_code = htons(o->menu_code); 252 | pkt->ship_number = (uint8_t)o->ship_number; 253 | pkt->privileges = htonl(o->privileges); 254 | 255 | /* Send the packet away */ 256 | return send_crypt(c, sizeof(shipgate_ship_status6_pkt)); 257 | } 258 | 259 | /* Send a ping packet to a client. */ 260 | int send_ping(ship_t *c, int reply) { 261 | shipgate_hdr_t *pkt = (shipgate_hdr_t *)sendbuf; 262 | 263 | /* Fill in the header. */ 264 | pkt->pkt_len = htons(sizeof(shipgate_hdr_t)); 265 | pkt->pkt_type = htons(SHDR_TYPE_PING); 266 | pkt->reserved = 0; 267 | pkt->version = 0; 268 | 269 | if(reply) 270 | pkt->flags = htons(SHDR_RESPONSE); 271 | else 272 | pkt->flags = 0; 273 | 274 | /* Send it away. */ 275 | return send_crypt(c, sizeof(shipgate_hdr_t)); 276 | } 277 | 278 | /* Send the ship a character data restore. */ 279 | int send_cdata(ship_t *c, uint32_t gc, uint32_t slot, void *cdata, int sz, 280 | uint32_t block) { 281 | shipgate_char_data_pkt *pkt = (shipgate_char_data_pkt *)sendbuf; 282 | 283 | /* Fill in the header. */ 284 | pkt->hdr.pkt_len = htons(sizeof(shipgate_char_data_pkt) + sz); 285 | pkt->hdr.pkt_type = htons(SHDR_TYPE_CREQ); 286 | pkt->hdr.flags = htons(SHDR_RESPONSE); 287 | pkt->hdr.reserved = 0; 288 | pkt->hdr.version = 0; 289 | 290 | /* Fill in the body. */ 291 | pkt->guildcard = htonl(gc); 292 | pkt->slot = htonl(slot); 293 | pkt->block = block; 294 | memcpy(pkt->data, cdata, sz); 295 | 296 | /* Send it away. */ 297 | return send_crypt(c, sizeof(shipgate_char_data_pkt) + sz); 298 | } 299 | 300 | /* Send a reply to a user login request. */ 301 | int send_usrloginreply(ship_t *c, uint32_t gc, uint32_t block, int good, 302 | uint32_t p) { 303 | shipgate_usrlogin_reply_pkt *pkt = (shipgate_usrlogin_reply_pkt *)sendbuf; 304 | uint16_t flags = good ? SHDR_RESPONSE : SHDR_FAILURE; 305 | 306 | /* Clear the packet first */ 307 | memset(pkt, 0, sizeof(shipgate_usrlogin_reply_pkt)); 308 | 309 | /* Fill in the response. */ 310 | pkt->hdr.pkt_len = htons(sizeof(shipgate_usrlogin_reply_pkt)); 311 | pkt->hdr.pkt_type = htons(SHDR_TYPE_USRLOGIN); 312 | pkt->hdr.flags = htons(flags); 313 | pkt->hdr.reserved = 0; 314 | pkt->hdr.version = 0; 315 | 316 | pkt->guildcard = htonl(gc); 317 | pkt->block = htonl(block); 318 | 319 | /* In protocol versions less than 18, priv was an 8 bit field. Since 320 | multibyte stuff is in network byte order, we have to shift to make that 321 | work. */ 322 | if(c->proto_ver < 18) 323 | pkt->priv = htonl(p << 24); 324 | else 325 | pkt->priv = htonl(p); 326 | 327 | return send_crypt(c, sizeof(shipgate_usrlogin_reply_pkt)); 328 | } 329 | 330 | /* Send a client/game update packet. */ 331 | int send_counts(ship_t *c, uint32_t ship_id, uint16_t clients, uint16_t games) { 332 | shipgate_cnt_pkt *pkt = (shipgate_cnt_pkt *)sendbuf; 333 | 334 | /* Clear the packet first */ 335 | memset(pkt, 0, sizeof(shipgate_cnt_pkt)); 336 | 337 | /* Fill in the response. */ 338 | pkt->hdr.pkt_len = htons(sizeof(shipgate_cnt_pkt)); 339 | pkt->hdr.pkt_type = htons(SHDR_TYPE_COUNT); 340 | pkt->hdr.flags = 0; 341 | pkt->hdr.reserved = 0; 342 | pkt->hdr.version = 0; 343 | 344 | pkt->clients = htons(clients); 345 | pkt->games = htons(games); 346 | pkt->ship_id = htonl(ship_id); 347 | 348 | return send_crypt(c, sizeof(shipgate_cnt_pkt)); 349 | } 350 | 351 | /* Send an error packet to a ship */ 352 | int send_error(ship_t *c, uint16_t type, uint16_t flags, uint32_t err, 353 | const uint8_t *data, int data_sz) { 354 | shipgate_error_pkt *pkt = (shipgate_error_pkt *)sendbuf; 355 | uint16_t sz; 356 | 357 | /* Make sure the data size is valid */ 358 | if(data_sz > 65536 - sizeof(shipgate_error_pkt)) 359 | return -1; 360 | 361 | /* Clear the header of the packet */ 362 | memset(pkt, 0, sizeof(shipgate_error_pkt)); 363 | sz = sizeof(shipgate_error_pkt) + data_sz; 364 | 365 | /* Fill it in */ 366 | pkt->hdr.pkt_len = htons(sz); 367 | pkt->hdr.pkt_type = htons(type); 368 | pkt->hdr.flags = htons(flags); 369 | pkt->hdr.reserved = 0; 370 | pkt->hdr.version = 0; 371 | 372 | pkt->error_code = htonl(err); 373 | memcpy(pkt->data, data, data_sz); 374 | 375 | return send_crypt(c, sz); 376 | } 377 | 378 | /* Send a packet to tell a client that a friend has logged on or off */ 379 | int send_friend_message(ship_t *c, int on, uint32_t dest_gc, 380 | uint32_t dest_block, uint32_t friend_gc, 381 | uint32_t friend_block, uint32_t friend_ship, 382 | const char *friend_name, const char *nickname) { 383 | shipgate_friend_login_4_pkt *pkt = (shipgate_friend_login_4_pkt *)sendbuf; 384 | 385 | /* Clear the packet */ 386 | memset(pkt, 0, sizeof(shipgate_friend_login_4_pkt)); 387 | 388 | /* Fill it in */ 389 | pkt->hdr.pkt_len = htons(sizeof(shipgate_friend_login_4_pkt)); 390 | pkt->hdr.pkt_type = htons((on ? SHDR_TYPE_FRLOGIN : SHDR_TYPE_FRLOGOUT)); 391 | pkt->hdr.flags = 0; 392 | pkt->hdr.reserved = 0; 393 | pkt->hdr.version = 0; 394 | pkt->dest_guildcard = htonl(dest_gc); 395 | pkt->dest_block = htonl(dest_block); 396 | pkt->friend_guildcard = htonl(friend_gc); 397 | pkt->friend_ship = htonl(friend_ship); 398 | pkt->friend_block = htonl(friend_block); 399 | strcpy(pkt->friend_name, friend_name); 400 | 401 | if(nickname) { 402 | strncpy(pkt->friend_nick, nickname, 32); 403 | pkt->friend_nick[31] = 0; 404 | } 405 | else { 406 | memset(pkt->friend_nick, 0, 32); 407 | } 408 | 409 | return send_crypt(c, sizeof(shipgate_friend_login_4_pkt)); 410 | } 411 | 412 | /* Send a kick packet */ 413 | int send_kick(ship_t *c, uint32_t requester, uint32_t user, uint32_t block, 414 | const char *reason) { 415 | shipgate_kick_pkt *pkt = (shipgate_kick_pkt *)sendbuf; 416 | 417 | /* Scrub the buffer */ 418 | memset(pkt, 0, sizeof(shipgate_kick_pkt)); 419 | 420 | /* Fill in the packet */ 421 | pkt->hdr.pkt_len = htons(sizeof(shipgate_kick_pkt)); 422 | pkt->hdr.pkt_type = htons(SHDR_TYPE_KICK); 423 | pkt->hdr.flags = 0; 424 | pkt->hdr.reserved = 0; 425 | pkt->hdr.version = 0; 426 | 427 | pkt->requester = htonl(requester); 428 | pkt->guildcard = htonl(user); 429 | pkt->block = htonl(block); 430 | 431 | if(reason) 432 | strncpy(pkt->reason, reason, 64); 433 | 434 | /* Send the packet away */ 435 | return send_crypt(c, sizeof(shipgate_kick_pkt)); 436 | } 437 | 438 | /* Send a portion of a user's friendlist to the user */ 439 | int send_friendlist(ship_t *c, uint32_t requester, uint32_t block, 440 | int count, const friendlist_data_t *entries) { 441 | shipgate_friend_list_pkt *pkt = (shipgate_friend_list_pkt *)sendbuf; 442 | uint16_t len = sizeof(shipgate_friend_list_pkt) + 443 | sizeof(friendlist_data_t) * count; 444 | 445 | /* Fill in the packet */ 446 | pkt->hdr.pkt_len = htons(len); 447 | pkt->hdr.pkt_type = htons(SHDR_TYPE_FRLIST); 448 | pkt->hdr.flags = htons(SHDR_RESPONSE); 449 | pkt->hdr.reserved = 0; 450 | pkt->hdr.version = 0; 451 | 452 | pkt->requester = htonl(requester); 453 | pkt->block = htonl(block); 454 | 455 | /* Copy the friend data */ 456 | memcpy(pkt->entries, entries, sizeof(friendlist_data_t) * count); 457 | 458 | /* Send the packet away */ 459 | return send_crypt(c, len); 460 | } 461 | 462 | /* Send a global message packet to a ship */ 463 | int send_global_msg(ship_t *c, uint32_t requester, const char *text, 464 | uint16_t text_len) { 465 | shipgate_global_msg_pkt *pkt = (shipgate_global_msg_pkt *)sendbuf; 466 | uint16_t len = sizeof(shipgate_global_msg_pkt) + text_len; 467 | 468 | /* Fill in the packet */ 469 | pkt->hdr.pkt_len = htons(len); 470 | pkt->hdr.pkt_type = htons(SHDR_TYPE_GLOBALMSG); 471 | pkt->hdr.flags = 0; 472 | pkt->hdr.reserved = 0; 473 | pkt->hdr.version = 0; 474 | 475 | pkt->requester = htonl(requester); 476 | pkt->reserved = 0; 477 | memcpy(pkt->text, text, len); 478 | 479 | /* Send the packet away */ 480 | return send_crypt(c, len); 481 | } 482 | 483 | /* Begin an options packet */ 484 | void *user_options_begin(uint32_t guildcard, uint32_t block) { 485 | shipgate_user_opt_pkt *pkt = (shipgate_user_opt_pkt *)sendbuf; 486 | 487 | /* Fill in the packet */ 488 | pkt->hdr.pkt_len = sizeof(shipgate_user_opt_pkt); 489 | pkt->hdr.pkt_type = htons(SHDR_TYPE_USEROPT); 490 | pkt->hdr.flags = 0; 491 | pkt->hdr.reserved = 0; 492 | pkt->hdr.version = 0; 493 | 494 | pkt->guildcard = htonl(guildcard); 495 | pkt->block = htonl(block); 496 | pkt->count = 0; 497 | pkt->reserved = 0; 498 | 499 | /* Return the pointer to the end of the buffer */ 500 | return &pkt->options[0]; 501 | } 502 | 503 | /* Append an option value to the options packet */ 504 | void *user_options_append(void *p, uint32_t opt, uint32_t len, 505 | const uint8_t *data) { 506 | shipgate_user_opt_pkt *pkt = (shipgate_user_opt_pkt *)sendbuf; 507 | shipgate_user_opt_t *o = (shipgate_user_opt_t *)p; 508 | int padding = 8 - (len & 7); 509 | 510 | /* Add the new option in */ 511 | o->option = htonl(opt); 512 | memcpy(o->data, data, len); 513 | 514 | /* Options must be a multiple of 8 bytes in length */ 515 | while(padding--) { 516 | o->data[len++] = 0; 517 | } 518 | 519 | o->length = htonl(len + 8); 520 | 521 | /* Adjust the packet's information to account for the new option */ 522 | pkt->hdr.pkt_len += len + 8; 523 | ++pkt->count; 524 | 525 | return (((uint8_t *)p) + len + 8); 526 | } 527 | 528 | /* Finish off a user options packet and send it along */ 529 | int send_user_options(ship_t *c) { 530 | shipgate_user_opt_pkt *pkt = (shipgate_user_opt_pkt *)sendbuf; 531 | uint16_t len = pkt->hdr.pkt_len; 532 | 533 | /* Make sure we have something to send, at least */ 534 | if(!pkt->count) 535 | return 0; 536 | 537 | /* Swap that which we need to do */ 538 | pkt->hdr.pkt_len = htons(len); 539 | pkt->count = htonl(pkt->count); 540 | 541 | /* Send it away */ 542 | return send_crypt(c, len); 543 | } 544 | 545 | /* Send a packet containing a user's Blue Burst options */ 546 | int send_bb_opts(ship_t *c, uint32_t gc, uint32_t block, 547 | sylverant_bb_db_opts_t *opts) { 548 | shipgate_bb_opts_pkt *pkt = (shipgate_bb_opts_pkt *)sendbuf; 549 | 550 | /* Fill in the packet */ 551 | pkt->hdr.pkt_len = htons(sizeof(shipgate_bb_opts_pkt)); 552 | pkt->hdr.pkt_type = htons(SHDR_TYPE_BBOPTS); 553 | pkt->hdr.reserved = 0; 554 | pkt->hdr.version = 0; 555 | pkt->hdr.flags = htons(SHDR_RESPONSE); 556 | 557 | pkt->guildcard = htonl(gc); 558 | pkt->block = htonl(block); 559 | memcpy(&pkt->opts, opts, sizeof(sylverant_bb_db_opts_t)); 560 | 561 | /* Send the packet away */ 562 | return send_crypt(c, sizeof(shipgate_bb_opts_pkt)); 563 | } 564 | 565 | /* Send a system-generated simple mail message. */ 566 | int send_simple_mail(ship_t *c, uint32_t gc, uint32_t block, uint32_t sender, 567 | const char *name, const char *msg) { 568 | dc_simple_mail_pkt pkt; 569 | size_t amt = strlen(name); 570 | 571 | /* Set up the mail. */ 572 | memset(&pkt, 0, sizeof(pkt)); 573 | pkt.hdr.pkt_type = SIMPLE_MAIL_TYPE; 574 | pkt.hdr.pkt_len = LE16(DC_SIMPLE_MAIL_LENGTH); 575 | pkt.tag = LE32(0x00010000); 576 | pkt.gc_sender = LE32(sender); 577 | 578 | /* Thank you GCC for this completely unnecessary warning that means I have 579 | to do this stupid song and dance to get rid of it (or tag the variable 580 | being used with a GCC-specific attribute) Basically, strncpy is totally 581 | useless now when you're dealing with things that need not be 582 | terminated. */ 583 | if(amt > 16) 584 | amt = 16; 585 | 586 | memcpy(pkt.name, name, amt); 587 | 588 | pkt.gc_dest = LE32(gc); 589 | strncpy(pkt.stuff, msg, 0x90); 590 | 591 | return forward_dreamcast(c, (dc_pkt_hdr_t *)&pkt, c->key_idx, gc, block); 592 | } 593 | 594 | /* Send a chunk of scripting code to a ship. */ 595 | int send_script_chunk(ship_t *c, const char *local_fn, const char *remote_fn, 596 | uint8_t type, uint32_t file_len, uint32_t crc) { 597 | shipgate_schunk_pkt *pkt = (shipgate_schunk_pkt *)sendbuf; 598 | FILE *fp; 599 | 600 | /* Don't try to send these to a ship that won't know what to do with them */ 601 | if(c->proto_ver < 16 || !(c->flags & LOGIN_FLAG_LUA)) 602 | return 0; 603 | 604 | /* Make sure it isn't too large... */ 605 | if(file_len > 32768) { 606 | debug(DBG_ERROR, "Attempt to send a script that is too large %s\n", 607 | local_fn); 608 | return -1; 609 | } 610 | 611 | /* Open up the file. */ 612 | if(!(fp = fopen(local_fn, "rb"))) { 613 | debug(DBG_ERROR, "Cannot open script file %s\n", local_fn); 614 | return -1; 615 | } 616 | 617 | /* Fill in the header and such */ 618 | memset(pkt, 0, sizeof(shipgate_schunk_pkt)); 619 | pkt->hdr.pkt_len = htons(file_len + sizeof(shipgate_schunk_pkt)); 620 | pkt->hdr.pkt_type = htons(SHDR_TYPE_SCHUNK); 621 | pkt->chunk_type = type; 622 | pkt->chunk_length = htonl((uint32_t)file_len); 623 | pkt->chunk_crc = htonl(crc); 624 | strncpy(pkt->filename, remote_fn, 32); 625 | 626 | /* Copy in the chunk */ 627 | if(fread(pkt->chunk, 1, file_len, fp) != file_len) { 628 | fclose(fp); 629 | debug(DBG_ERROR, "Error reading from script file %s\n", local_fn); 630 | return -1; 631 | } 632 | 633 | fclose(fp); 634 | 635 | /* Send it away */ 636 | return send_crypt(c, file_len + sizeof(shipgate_schunk_pkt)); 637 | } 638 | 639 | /* Send a packet to check if a particular script is in its current form on a 640 | ship. */ 641 | int send_script_check(ship_t *c, ship_script_t *scr) { 642 | shipgate_schunk_pkt *pkt = (shipgate_schunk_pkt *)sendbuf; 643 | uint8_t type = scr->module ? SCHUNK_TYPE_MODULE : SCHUNK_TYPE_SCRIPT; 644 | 645 | /* Don't try to send these to a ship that won't know what to do with them */ 646 | if(c->proto_ver < 16 || !(c->flags & LOGIN_FLAG_LUA)) 647 | return 0; 648 | 649 | /* Fill in the easy stuff */ 650 | memset(pkt, 0, sizeof(shipgate_schunk_pkt)); 651 | pkt->hdr.pkt_len = htons(sizeof(shipgate_schunk_pkt)); 652 | pkt->hdr.pkt_type = htons(SHDR_TYPE_SCHUNK); 653 | pkt->chunk_type = SCHUNK_CHECK | type; 654 | pkt->chunk_length = htonl(scr->len); 655 | strncpy(pkt->filename, scr->remote_fn, 32); 656 | pkt->chunk_crc = htonl(scr->crc); 657 | 658 | if(scr->event) 659 | pkt->action = htonl(scr->event); 660 | 661 | /* Send it away */ 662 | return send_crypt(c, sizeof(shipgate_schunk_pkt)); 663 | } 664 | 665 | /* Send a packet to send a script to the a ship. */ 666 | int send_script(ship_t *c, ship_script_t *scr) { 667 | shipgate_schunk_pkt *pkt = (shipgate_schunk_pkt *)sendbuf; 668 | FILE *fp; 669 | uint16_t pkt_len; 670 | 671 | /* Don't try to send these to a ship that won't know what to do with them */ 672 | if(c->proto_ver < 16 || !(c->flags & LOGIN_FLAG_LUA)) 673 | return 0; 674 | 675 | debug(DBG_LOG, "Sending ship %s script file '%s' (%s)\n", c->name, 676 | scr->remote_fn, scr->local_fn); 677 | 678 | pkt_len = sizeof(shipgate_schunk_pkt) + scr->len; 679 | if(pkt_len & 0x07) 680 | pkt_len = (pkt_len + 8) & 0xFFF8; 681 | 682 | /* Fill in the easy stuff */ 683 | memset(pkt, 0, pkt_len); 684 | pkt->hdr.pkt_len = htons(pkt_len); 685 | pkt->hdr.pkt_type = htons(SHDR_TYPE_SCHUNK); 686 | pkt->chunk_type = scr->module ? SCHUNK_TYPE_MODULE : SCHUNK_TYPE_SCRIPT; 687 | pkt->chunk_length = htonl(scr->len); 688 | strncpy(pkt->filename, scr->remote_fn, 32); 689 | pkt->chunk_crc = htonl(scr->crc); 690 | 691 | if(scr->event) 692 | pkt->action = htonl(scr->event); 693 | 694 | /* Read the script file in... */ 695 | if(!(fp = fopen(scr->local_fn, "rb"))) { 696 | debug(DBG_ERROR, "Cannot read script file '%s'\n", scr->local_fn); 697 | return 0; 698 | } 699 | 700 | if(fread(pkt->chunk, 1, scr->len, fp) != scr->len) { 701 | debug(DBG_ERROR, "Script file '%s' changed lengths?\n", scr->local_fn); 702 | return 0; 703 | } 704 | 705 | fclose(fp); 706 | 707 | /* Send it away */ 708 | return send_crypt(c, pkt_len); 709 | } 710 | 711 | int send_sset(ship_t *c, uint32_t action, ship_script_t *scr) { 712 | shipgate_sset_pkt *pkt = (shipgate_sset_pkt *)sendbuf; 713 | 714 | /* Don't try to send these to a ship that won't know what to do with them */ 715 | if(c->proto_ver < 16 || !(c->flags & LOGIN_FLAG_LUA)) 716 | return 0; 717 | 718 | /* Make sure the requested operation makes sense... */ 719 | if(scr && scr->module) 720 | return 0; 721 | 722 | /* Fill in the easy stuff */ 723 | memset(pkt, 0, sizeof(shipgate_sset_pkt)); 724 | pkt->hdr.pkt_len = htons(sizeof(shipgate_sset_pkt)); 725 | pkt->hdr.pkt_type = htons(SHDR_TYPE_SSET); 726 | pkt->action = htonl(action); 727 | 728 | if(scr) 729 | strncpy(pkt->filename, scr->remote_fn, 32); 730 | 731 | /* Send it away */ 732 | return send_crypt(c, sizeof(shipgate_sset_pkt)); 733 | } 734 | 735 | /* Send a script data packet */ 736 | int send_sdata(ship_t *c, uint32_t gc, uint32_t block, uint32_t event, 737 | const uint8_t *data, uint32_t len) { 738 | shipgate_sdata_pkt *pkt = (shipgate_sdata_pkt *)sendbuf; 739 | uint16_t pkt_len; 740 | 741 | /* Don't try to send these to a ship that won't know what to do with them */ 742 | if(c->proto_ver < 16 || !(c->flags & LOGIN_FLAG_LUA)) 743 | return 0; 744 | 745 | /* Make sure the length is sane... */ 746 | if(len > 32768) { 747 | debug(DBG_WARN, "Dropping huge sdata packet\n"); 748 | return -1; 749 | } 750 | 751 | pkt_len = sizeof(shipgate_sdata_pkt) + len; 752 | if(pkt_len & 0x07) 753 | pkt_len = (pkt_len + 8) & 0xFFF8; 754 | 755 | /* Fill in the packet... */ 756 | memset(pkt, 0, pkt_len); 757 | pkt->hdr.pkt_len = htons(pkt_len); 758 | pkt->hdr.pkt_type = htons(SHDR_TYPE_SDATA); 759 | pkt->event_id = htonl(event); 760 | pkt->data_len = htonl(len); 761 | pkt->guildcard = htonl(gc); 762 | pkt->block = htonl(block); 763 | memcpy(pkt->data, data, len); 764 | 765 | /* Send it away. */ 766 | return send_crypt(c, pkt_len); 767 | } 768 | 769 | /* Send a quest flag response */ 770 | int send_qflag(ship_t *c, uint16_t type, uint32_t gc, uint32_t block, 771 | uint32_t fid, uint32_t qid, uint32_t value, uint32_t ctl) { 772 | shipgate_qflag_pkt *pkt = (shipgate_qflag_pkt *)sendbuf; 773 | 774 | /* Don't try to send these to a ship that won't know what to do with them */ 775 | if(c->proto_ver < 17) 776 | return 0; 777 | 778 | /* Fill in the packet... */ 779 | memset(pkt, 0, sizeof(shipgate_qflag_pkt)); 780 | pkt->hdr.pkt_len = htons(sizeof(shipgate_qflag_pkt)); 781 | pkt->hdr.pkt_type = htons(type); 782 | pkt->hdr.flags = htons(SHDR_RESPONSE); 783 | pkt->guildcard = htonl(gc); 784 | pkt->block = htonl(block); 785 | pkt->flag_id = htonl((fid & 0xFFFF) | (ctl & 0xFFFF0000)); 786 | pkt->quest_id = htonl(qid); 787 | pkt->flag_id_hi = htons(fid >> 16); 788 | pkt->value = htonl(value); 789 | 790 | /* Send it away. */ 791 | return send_crypt(c, sizeof(shipgate_qflag_pkt)); 792 | } 793 | 794 | /* Send a simple ship control request */ 795 | int send_sctl(ship_t *c, uint32_t ctl, uint32_t acc) { 796 | shipgate_shipctl_pkt *pkt = (shipgate_shipctl_pkt *)sendbuf; 797 | 798 | /* This packet doesn't exist until protocol 19. */ 799 | if(c->proto_ver < 19) 800 | return 0; 801 | 802 | /* Fill in the packet... */ 803 | memset(pkt, 0, sizeof(shipgate_shipctl_pkt)); 804 | pkt->hdr.pkt_len = htons(sizeof(shipgate_shipctl_pkt)); 805 | pkt->hdr.pkt_type = htons(SHDR_TYPE_SHIP_CTL); 806 | 807 | pkt->ctl = htonl(ctl); 808 | pkt->acc = htonl(acc); 809 | 810 | /* Send it away. */ 811 | return send_crypt(c, sizeof(shipgate_shipctl_pkt)); 812 | } 813 | 814 | /* Send a shutdown/restart request */ 815 | int send_shutdown(ship_t *c, int restart, uint32_t acc, uint32_t when) { 816 | shipgate_sctl_shutdown_pkt *pkt = (shipgate_sctl_shutdown_pkt *)sendbuf; 817 | 818 | /* This packet doesn't exist until protocol 19. */ 819 | if(c->proto_ver < 19) 820 | return 0; 821 | 822 | /* Fill in the packet... */ 823 | memset(pkt, 0, sizeof(shipgate_sctl_shutdown_pkt)); 824 | pkt->hdr.pkt_len = htons(sizeof(shipgate_sctl_shutdown_pkt)); 825 | pkt->hdr.pkt_type = htons(SHDR_TYPE_SHIP_CTL); 826 | 827 | if(restart) 828 | pkt->ctl = htonl(SCTL_TYPE_RESTART); 829 | else 830 | pkt->ctl = htonl(SCTL_TYPE_SHUTDOWN); 831 | 832 | pkt->acc = htonl(acc); 833 | pkt->when = htonl(when); 834 | 835 | /* Send it away. */ 836 | return send_crypt(c, sizeof(shipgate_sctl_shutdown_pkt)); 837 | } 838 | 839 | /* Begin an blocklist packet */ 840 | void user_blocklist_begin(uint32_t guildcard, uint32_t block) { 841 | shipgate_user_blocklist_pkt *pkt = (shipgate_user_blocklist_pkt *)sendbuf; 842 | 843 | /* Fill in the packet */ 844 | pkt->hdr.pkt_len = sizeof(shipgate_user_blocklist_pkt); 845 | pkt->hdr.pkt_type = htons(SHDR_TYPE_UBLOCKS); 846 | pkt->hdr.flags = 0; 847 | pkt->hdr.reserved = 0; 848 | pkt->hdr.version = 0; 849 | 850 | pkt->guildcard = htonl(guildcard); 851 | pkt->block = htonl(block); 852 | pkt->count = 0; 853 | pkt->reserved = 0; 854 | } 855 | 856 | /* Append a value to the blocklist packet */ 857 | void user_blocklist_append(uint32_t gc, uint32_t flags) { 858 | shipgate_user_blocklist_pkt *pkt = (shipgate_user_blocklist_pkt *)sendbuf; 859 | uint32_t i = pkt->count; 860 | 861 | /* Add the blocked user */ 862 | pkt->entries[i].gc = htonl(gc); 863 | pkt->entries[i].flags = htonl(flags); 864 | 865 | /* Adjust the packet's information to account for the new option */ 866 | pkt->hdr.pkt_len += 8; 867 | ++pkt->count; 868 | } 869 | 870 | /* Finish off a user blocklist packet and send it along */ 871 | int send_user_blocklist(ship_t *c) { 872 | shipgate_user_blocklist_pkt *pkt = (shipgate_user_blocklist_pkt *)sendbuf; 873 | uint16_t len = pkt->hdr.pkt_len; 874 | 875 | /* Make sure we have something to send, at least */ 876 | if(!pkt->count) 877 | return 0; 878 | 879 | /* Make sure we don't try to send to a ship that won't know what to do with 880 | the packet. */ 881 | if(c->proto_ver < 19) 882 | return 0; 883 | 884 | /* Swap that which we need to do */ 885 | pkt->hdr.pkt_len = htons(len); 886 | pkt->count = htonl(pkt->count); 887 | 888 | /* Send it away */ 889 | return send_crypt(c, len); 890 | } 891 | 892 | int send_user_error(ship_t *c, uint16_t pkt_type, uint32_t err_code, 893 | uint32_t gc, uint32_t block, const char *message) { 894 | shipgate_user_err_pkt *pkt = (shipgate_user_err_pkt *)sendbuf; 895 | uint16_t len = message ? strlen(message) : 0; 896 | uint16_t fl = err_code != ERR_NO_ERROR ? SHDR_FAILURE : 0; 897 | 898 | if(c->proto_ver < 19) 899 | return 0; 900 | 901 | /* Round up the length to the next multiple of 8. */ 902 | len += sizeof(shipgate_user_err_pkt); 903 | if(len & 7) 904 | len = (len + 7) & (~7); 905 | 906 | memset(pkt, 0, len); 907 | pkt->base.hdr.pkt_type = htons(pkt_type); 908 | pkt->base.hdr.pkt_len = htons(len); 909 | pkt->base.hdr.flags = htons(SHDR_RESPONSE | fl); 910 | 911 | pkt->gc = htonl(gc); 912 | pkt->block = htonl(block); 913 | strcpy(pkt->message, message); 914 | 915 | return send_crypt(c, len); 916 | } 917 | -------------------------------------------------------------------------------- /src/pidfile.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2005 Pawel Jakub Dawidek 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | */ 26 | 27 | /* Slightly modified for inclusion in ship_server. Note that this version is 28 | not used if you have BSD's libutil or libbsd installed on Linux (or other 29 | OSes). */ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include 42 | #include 43 | #include 44 | 45 | struct pidfh { 46 | int pf_fd; 47 | char *pf_path; 48 | dev_t pf_dev; 49 | ino_t pf_ino; 50 | }; 51 | 52 | static int _pidfile_remove(struct pidfh *pfh, int freeit); 53 | int flopen(const char *path, int flags, ...); 54 | 55 | static int 56 | pidfile_verify(const struct pidfh *pfh) 57 | { 58 | struct stat sb; 59 | 60 | if (pfh == NULL || pfh->pf_fd == -1) 61 | return (EINVAL); 62 | /* 63 | * Check remembered descriptor. 64 | */ 65 | if (fstat(pfh->pf_fd, &sb) == -1) 66 | return (errno); 67 | if (sb.st_dev != pfh->pf_dev || sb.st_ino != pfh->pf_ino) 68 | return (EINVAL); 69 | return (0); 70 | } 71 | 72 | static int 73 | pidfile_read(const char *path, pid_t *pidptr) 74 | { 75 | char buf[16], *endptr; 76 | int error, fd, i; 77 | 78 | fd = open(path, O_RDONLY); 79 | if (fd == -1) 80 | return (errno); 81 | 82 | i = read(fd, buf, sizeof(buf) - 1); 83 | error = errno; /* Remember errno in case close() wants to change it. */ 84 | close(fd); 85 | if (i == -1) 86 | return (error); 87 | else if (i == 0) 88 | return (EAGAIN); 89 | buf[i] = '\0'; 90 | 91 | *pidptr = strtol(buf, &endptr, 10); 92 | if (endptr != &buf[i]) 93 | return (EINVAL); 94 | 95 | return (0); 96 | } 97 | 98 | struct pidfh * 99 | pidfile_open(const char *path, mode_t mode, pid_t *pidptr) 100 | { 101 | struct pidfh *pfh; 102 | struct stat sb; 103 | int error, fd, /*len,*/ count; 104 | struct timespec rqtp; 105 | 106 | pfh = malloc(sizeof(*pfh)); 107 | if (pfh == NULL) 108 | return (NULL); 109 | 110 | if (path == NULL) { 111 | #if 0 112 | len = asprintf(&pfh->pf_path, "/var/run/%s.pid", getprogname()); 113 | if (len < 0) { 114 | free(pfh); 115 | return (NULL); 116 | } 117 | #else 118 | /* Don't rely on getprogname(), since that's also part of libutil. We 119 | always supply the path, so this is fine for Sylverant. */ 120 | free(pfh); 121 | errno = EINVAL; 122 | return NULL; 123 | #endif 124 | } else 125 | pfh->pf_path = strdup(path); 126 | 127 | /* 128 | * Open the PID file and obtain exclusive lock. 129 | * We truncate PID file here only to remove old PID immediately, 130 | * PID file will be truncated again in pidfile_write(), so 131 | * pidfile_write() can be called multiple times. 132 | */ 133 | fd = flopen(pfh->pf_path, 134 | O_WRONLY | O_CREAT | O_TRUNC | O_NONBLOCK, mode); 135 | if (fd == -1) { 136 | if (errno == EWOULDBLOCK) { 137 | if (pidptr == NULL) { 138 | errno = EEXIST; 139 | } else { 140 | count = 20; 141 | rqtp.tv_sec = 0; 142 | rqtp.tv_nsec = 5000000; 143 | for (;;) { 144 | errno = pidfile_read(pfh->pf_path, 145 | pidptr); 146 | if (errno != EAGAIN || --count == 0) 147 | break; 148 | nanosleep(&rqtp, 0); 149 | } 150 | if (errno == EAGAIN) 151 | *pidptr = -1; 152 | if (errno == 0 || errno == EAGAIN) 153 | errno = EEXIST; 154 | } 155 | } 156 | error = errno; 157 | free(pfh->pf_path); 158 | free(pfh); 159 | errno = error; 160 | return (NULL); 161 | } 162 | 163 | /* 164 | * Remember file information, so in pidfile_write() we are sure we write 165 | * to the proper descriptor. 166 | */ 167 | if (fstat(fd, &sb) == -1) { 168 | error = errno; 169 | unlink(pfh->pf_path); 170 | free(pfh->pf_path); 171 | close(fd); 172 | free(pfh); 173 | errno = error; 174 | return (NULL); 175 | } 176 | 177 | pfh->pf_fd = fd; 178 | pfh->pf_dev = sb.st_dev; 179 | pfh->pf_ino = sb.st_ino; 180 | 181 | return (pfh); 182 | } 183 | 184 | int 185 | pidfile_write(struct pidfh *pfh) 186 | { 187 | char pidstr[16]; 188 | int error, fd; 189 | 190 | /* 191 | * Check remembered descriptor, so we don't overwrite some other 192 | * file if pidfile was closed and descriptor reused. 193 | */ 194 | errno = pidfile_verify(pfh); 195 | if (errno != 0) { 196 | /* 197 | * Don't close descriptor, because we are not sure if it's ours. 198 | */ 199 | return (-1); 200 | } 201 | fd = pfh->pf_fd; 202 | 203 | /* 204 | * Truncate PID file, so multiple calls of pidfile_write() are allowed. 205 | */ 206 | if (ftruncate(fd, 0) == -1) { 207 | error = errno; 208 | _pidfile_remove(pfh, 0); 209 | errno = error; 210 | return (-1); 211 | } 212 | 213 | snprintf(pidstr, sizeof(pidstr), "%u", getpid()); 214 | if (pwrite(fd, pidstr, strlen(pidstr), 0) != (ssize_t)strlen(pidstr)) { 215 | error = errno; 216 | _pidfile_remove(pfh, 0); 217 | errno = error; 218 | return (-1); 219 | } 220 | 221 | return (0); 222 | } 223 | 224 | int 225 | pidfile_close(struct pidfh *pfh) 226 | { 227 | int error; 228 | 229 | error = pidfile_verify(pfh); 230 | if (error != 0) { 231 | errno = error; 232 | return (-1); 233 | } 234 | 235 | if (close(pfh->pf_fd) == -1) 236 | error = errno; 237 | free(pfh->pf_path); 238 | free(pfh); 239 | if (error != 0) { 240 | errno = error; 241 | return (-1); 242 | } 243 | return (0); 244 | } 245 | 246 | static int 247 | _pidfile_remove(struct pidfh *pfh, int freeit) 248 | { 249 | int error; 250 | 251 | error = pidfile_verify(pfh); 252 | if (error != 0) { 253 | errno = error; 254 | return (-1); 255 | } 256 | 257 | if (unlink(pfh->pf_path) == -1) 258 | error = errno; 259 | if (close(pfh->pf_fd) == -1) { 260 | if (error == 0) 261 | error = errno; 262 | } 263 | if (freeit) { 264 | free(pfh->pf_path); 265 | free(pfh); 266 | } else 267 | pfh->pf_fd = -1; 268 | if (error != 0) { 269 | errno = error; 270 | return (-1); 271 | } 272 | return (0); 273 | } 274 | 275 | int 276 | pidfile_remove(struct pidfh *pfh) 277 | { 278 | 279 | return (_pidfile_remove(pfh, 1)); 280 | } 281 | 282 | int 283 | pidfile_fileno(const struct pidfh *pfh) 284 | { 285 | 286 | if (pfh == NULL || pfh->pf_fd == -1) { 287 | errno = EINVAL; 288 | return (-1); 289 | } 290 | return (pfh->pf_fd); 291 | } 292 | -------------------------------------------------------------------------------- /src/scripts.c: -------------------------------------------------------------------------------- 1 | /* 2 | Sylverant Shipgate 3 | Copyright (C) 2011, 2016, 2018, 2019, 2021, 2022 Lawrence Sebald 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU Affero General Public License version 3 7 | as published by the Free Software Foundation. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 | GNU Affero General Public License for more details. 13 | 14 | You should have received a copy of the GNU Affero General Public License 15 | along with this program. If not, see . 16 | */ 17 | 18 | #include 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | #include 25 | #include 26 | 27 | #include 28 | #include 29 | 30 | #include "scripts.h" 31 | 32 | #ifdef ENABLE_LUA 33 | #include 34 | #include 35 | #include 36 | #endif 37 | 38 | #ifndef LIBXML_TREE_ENABLED 39 | #error You must have libxml2 with tree support built-in. 40 | #endif 41 | 42 | #define XC (const xmlChar *) 43 | 44 | #ifdef ENABLE_LUA 45 | 46 | extern sylverant_config_t *cfg; 47 | 48 | static lua_State *lstate; 49 | static int scripts_ref = 0; 50 | static int script_ids[ScriptActionCount] = { 0 }; 51 | 52 | uint32_t script_count; 53 | ship_script_t *scripts; 54 | 55 | /* This should be kept in sync with the same list in ship_server... */ 56 | static const xmlChar *ship_script_action_text[] = { 57 | XC"STARTUP", 58 | XC"SHUTDOWN", 59 | XC"SHIP_LOGIN", 60 | XC"SHIP_LOGOUT", 61 | XC"BLOCK_LOGIN", 62 | XC"BLOCK_LOGOUT", 63 | XC"UNK_SHIP_PKT", 64 | XC"UNK_BLOCK_PKT", 65 | XC"UNK_EP3_PKT", 66 | XC"TEAM_CREATE", 67 | XC"TEAM_DESTROY", 68 | XC"TEAM_JOIN", 69 | XC"TEAM_LEAVE", 70 | XC"ENEMY_KILL", 71 | XC"ENEMY_HIT", 72 | XC"BOX_BREAK", 73 | XC"UNK_COMMAND", 74 | XC"SDATA", 75 | XC"UNK_MENU", 76 | XC"BANK_ACTION", 77 | XC"CHANGE_AREA", 78 | XC"QUEST_SYNCREG", 79 | XC"QUEST_LOAD", 80 | XC"BEFORE_QUEST_LOAD", 81 | NULL 82 | }; 83 | 84 | /* Text versions of the script actions. This must match the list in the 85 | script_action_t enum in scripts.h . */ 86 | static const xmlChar *script_action_text[] = { 87 | XC"STARTUP", 88 | XC"SHUTDOWN", 89 | XC"SDATA", 90 | }; 91 | 92 | /* Figure out what index a given script action sits at */ 93 | static inline int ship_script_action_to_index(xmlChar *str) { 94 | int i; 95 | 96 | for(i = 0; ship_script_action_text[i]; ++i) { 97 | if(!xmlStrcmp(ship_script_action_text[i], str)) { 98 | return i; 99 | } 100 | } 101 | 102 | return -1; 103 | } 104 | 105 | static inline script_action_t script_action_to_index(xmlChar *str) { 106 | int i; 107 | 108 | for(i = 0; i < ScriptActionCount; ++i) { 109 | if(!xmlStrcmp(script_action_text[i], str)) { 110 | return (script_action_t)i; 111 | } 112 | } 113 | 114 | return ScriptActionInvalid; 115 | } 116 | 117 | static int ship_script_add(xmlChar *file, xmlChar *remote, int mod, 118 | int action, uint32_t *alloc, int deleted) { 119 | void *tmp; 120 | FILE *fp; 121 | long len = 0; 122 | uint32_t crc = 0; 123 | 124 | /* Do we have space for this new script? */ 125 | if(!*alloc) { 126 | /* This will probably be enough... At least for now. */ 127 | scripts = (ship_script_t *)malloc(sizeof(ship_script_t) * 10); 128 | if(!scripts) { 129 | debug(DBG_ERROR, "Out of memory allocating scripts array\n"); 130 | return -1; 131 | } 132 | 133 | *alloc = 10; 134 | } 135 | else if(*alloc == script_count) { 136 | tmp = realloc(scripts, sizeof(ship_script_t) * *alloc * 2); 137 | if(!tmp) { 138 | debug(DBG_ERROR, "Out of memory reallocating scripts array\n"); 139 | return -1; 140 | } 141 | 142 | scripts = (ship_script_t *)tmp; 143 | *alloc *= 2; 144 | } 145 | 146 | /* Is the script deleted? */ 147 | if(!deleted) { 148 | if(!(fp = fopen((char *)file, "rb"))) { 149 | debug(DBG_WARN, "Cannot open script file '%s'\n", file); 150 | return -2; 151 | } 152 | 153 | /* Figure out how long it is */ 154 | fseek(fp, 0, SEEK_END); 155 | len = ftell(fp); 156 | fseek(fp, 0, SEEK_SET); 157 | 158 | if(len > 32768) { 159 | debug(DBG_WARN, "Script file '%s' is too long\n", file); 160 | fclose(fp); 161 | return -3; 162 | } 163 | 164 | if(!(tmp = malloc(len))) { 165 | debug(DBG_ERROR, "Out of memory allocating script\n"); 166 | fclose(fp); 167 | return -4; 168 | } 169 | 170 | if(fread(tmp, 1, len, fp) != len) { 171 | debug(DBG_WARN, "Cannot read script '%s'\n", file); 172 | free(tmp); 173 | fclose(fp); 174 | return -4; 175 | } 176 | 177 | fclose(fp); 178 | 179 | crc = sylverant_crc32((const uint8_t *)tmp, len); 180 | free(tmp); 181 | } 182 | 183 | scripts[script_count].local_fn = (char *)file; 184 | scripts[script_count].remote_fn = (char *)remote; 185 | scripts[script_count].module = mod; 186 | scripts[script_count].event = action; 187 | scripts[script_count].len = (uint32_t)len; 188 | scripts[script_count].crc = crc; 189 | scripts[script_count].deleted = deleted; 190 | ++script_count; 191 | 192 | return 0; 193 | } 194 | 195 | /* Parse the XML for the script definitions */ 196 | int script_list_read(const char *fn) { 197 | xmlParserCtxtPtr cxt; 198 | xmlDoc *doc; 199 | xmlNode *n; 200 | xmlChar *file, *event, *remote, *deleted; 201 | int rv = 0; 202 | script_action_t idx; 203 | int sidx; 204 | uint32_t num_alloc = 0; 205 | int is_del = 0; 206 | 207 | /* If we're reloading, kill the old list. */ 208 | if(scripts_ref) { 209 | luaL_unref(lstate, LUA_REGISTRYINDEX, scripts_ref); 210 | } 211 | 212 | /* Create an XML Parsing context */ 213 | cxt = xmlNewParserCtxt(); 214 | if(!cxt) { 215 | debug(DBG_ERROR, "Couldn't create XML parsing context for scripts\n"); 216 | rv = -1; 217 | goto err; 218 | } 219 | 220 | /* Open the script list XML file for reading. */ 221 | doc = xmlReadFile(fn, NULL, 0); 222 | if(!doc) { 223 | xmlParserError(cxt, "Error in parsing script List\n"); 224 | rv = -2; 225 | goto err_cxt; 226 | } 227 | 228 | /* Make sure the document validated properly. */ 229 | if(!cxt->valid) { 230 | xmlParserValidityError(cxt, "Validity Error parsing script List\n"); 231 | rv = -3; 232 | goto err_doc; 233 | } 234 | 235 | /* If we've gotten this far, we have a valid document, now go through and 236 | add in entries for everything... */ 237 | n = xmlDocGetRootElement(doc); 238 | 239 | if(!n) { 240 | debug(DBG_WARN, "Empty script List document\n"); 241 | rv = -4; 242 | goto err_doc; 243 | } 244 | 245 | /* Make sure the list looks sane. */ 246 | if(xmlStrcmp(n->name, XC"scripts")) { 247 | debug(DBG_WARN, "Script list does not appear to be the right type\n"); 248 | rv = -5; 249 | goto err_doc; 250 | } 251 | 252 | /* Create a table for storing our pre-parsed scripts in... */ 253 | lua_newtable(lstate); 254 | 255 | n = n->children; 256 | while(n) { 257 | if(n->type != XML_ELEMENT_NODE) { 258 | /* Ignore non-elements. */ 259 | n = n->next; 260 | continue; 261 | } 262 | if(!xmlStrcmp(n->name, XC"script")) { 263 | /* See if we have all