├── .github └── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md ├── LICENSE ├── README.md ├── addon.json ├── database.sql ├── fake_data.sql └── lua ├── autorun └── msync_autorun.lua └── msync ├── client_gui ├── cl_admin_gui.lua ├── cl_init.lua ├── cl_modules.lua ├── cl_net.lua └── modules │ ├── cl_mbsync.lua │ ├── cl_mrsync.lua │ └── cl_samplemodule.lua ├── server ├── modules │ ├── sv_mbsync.lua │ ├── sv_mrsync.lua │ └── sv_samplemodule.lua ├── sv_hooks.lua ├── sv_init.lua ├── sv_modules.lua ├── sv_mysql.lua ├── sv_net.lua └── sv_ulx.lua └── sh_init.lua /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Open a bug report when something doesnt work as it should 4 | title: Bugreport 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | **__Description__** 11 | [Describe the bug as good as possible] 12 | 13 | **__Reproduction__** 14 | [How can we re-produce the bug, what did you do to cause it?] 15 | 16 | **__Error Messages__** 17 | ``` 18 | [Add error messages here if you recieved any, if not leave this part out] 19 | ``` 20 | 21 | **__Optional: Screenshots__** 22 | [Attach screenshots of the bug here if possible] 23 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: How can we make MSync even better? 4 | title: Feature Request 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | **__Description:__** 11 | [Describe your feature idea as much as possible] 12 | 13 | **__Usage Cases:__** 14 | [In what cases would your feature be usefull] 15 | 16 | **__Optional: Alternatives__** 17 | [Alternative ideas for your feature you have considered. Explain what you came up with and why you think it's your feature is better] 18 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ### GNU GENERAL PUBLIC LICENSE 2 | 3 | Version 3, 29 June 2007 4 | 5 | Copyright (C) 2007 Free Software Foundation, Inc. 6 | 7 | 8 | Everyone is permitted to copy and distribute verbatim copies of this 9 | license document, but changing it is not allowed. 10 | 11 | ### Preamble 12 | 13 | The GNU General Public License is a free, copyleft license for 14 | software and other kinds of works. 15 | 16 | The licenses for most software and other practical works are designed 17 | to take away your freedom to share and change the works. By contrast, 18 | the GNU General Public License is intended to guarantee your freedom 19 | to share and change all versions of a program--to make sure it remains 20 | free software for all its users. We, the Free Software Foundation, use 21 | the GNU General Public License for most of our software; it applies 22 | also to any other work released this way by its authors. You can apply 23 | it to your programs, too. 24 | 25 | When we speak of free software, we are referring to freedom, not 26 | price. Our General Public Licenses are designed to make sure that you 27 | have the freedom to distribute copies of free software (and charge for 28 | them if you wish), that you receive source code or can get it if you 29 | want it, that you can change the software or use pieces of it in new 30 | free programs, and that you know you can do these things. 31 | 32 | To protect your rights, we need to prevent others from denying you 33 | these rights or asking you to surrender the rights. Therefore, you 34 | have certain responsibilities if you distribute copies of the 35 | software, or if you modify it: responsibilities to respect the freedom 36 | of others. 37 | 38 | For example, if you distribute copies of such a program, whether 39 | gratis or for a fee, you must pass on to the recipients the same 40 | freedoms that you received. You must make sure that they, too, receive 41 | or can get the source code. And you must show them these terms so they 42 | know their rights. 43 | 44 | Developers that use the GNU GPL protect your rights with two steps: 45 | (1) assert copyright on the software, and (2) offer you this License 46 | giving you legal permission to copy, distribute and/or modify it. 47 | 48 | For the developers' and authors' protection, the GPL clearly explains 49 | that there is no warranty for this free software. For both users' and 50 | authors' sake, the GPL requires that modified versions be marked as 51 | changed, so that their problems will not be attributed erroneously to 52 | authors of previous versions. 53 | 54 | Some devices are designed to deny users access to install or run 55 | modified versions of the software inside them, although the 56 | manufacturer can do so. This is fundamentally incompatible with the 57 | aim of protecting users' freedom to change the software. The 58 | systematic pattern of such abuse occurs in the area of products for 59 | individuals to use, which is precisely where it is most unacceptable. 60 | Therefore, we have designed this version of the GPL to prohibit the 61 | practice for those products. If such problems arise substantially in 62 | other domains, we stand ready to extend this provision to those 63 | domains in future versions of the GPL, as needed to protect the 64 | freedom of users. 65 | 66 | Finally, every program is threatened constantly by software patents. 67 | States should not allow patents to restrict development and use of 68 | software on general-purpose computers, but in those that do, we wish 69 | to avoid the special danger that patents applied to a free program 70 | could make it effectively proprietary. To prevent this, the GPL 71 | assures that patents cannot be used to render the program non-free. 72 | 73 | The precise terms and conditions for copying, distribution and 74 | modification follow. 75 | 76 | ### TERMS AND CONDITIONS 77 | 78 | #### 0. Definitions. 79 | 80 | "This License" refers to version 3 of the GNU General Public License. 81 | 82 | "Copyright" also means copyright-like laws that apply to other kinds 83 | of works, such as semiconductor masks. 84 | 85 | "The Program" refers to any copyrightable work licensed under this 86 | License. Each licensee is addressed as "you". "Licensees" and 87 | "recipients" may be individuals or organizations. 88 | 89 | To "modify" a work means to copy from or adapt all or part of the work 90 | in a fashion requiring copyright permission, other than the making of 91 | an exact copy. The resulting work is called a "modified version" of 92 | the earlier work or a work "based on" the earlier work. 93 | 94 | A "covered work" means either the unmodified Program or a work based 95 | on the Program. 96 | 97 | To "propagate" a work means to do anything with it that, without 98 | permission, would make you directly or secondarily liable for 99 | infringement under applicable copyright law, except executing it on a 100 | computer or modifying a private copy. Propagation includes copying, 101 | distribution (with or without modification), making available to the 102 | public, and in some countries other activities as well. 103 | 104 | To "convey" a work means any kind of propagation that enables other 105 | parties to make or receive copies. Mere interaction with a user 106 | through a computer network, with no transfer of a copy, is not 107 | conveying. 108 | 109 | An interactive user interface displays "Appropriate Legal Notices" to 110 | the extent that it includes a convenient and prominently visible 111 | feature that (1) displays an appropriate copyright notice, and (2) 112 | tells the user that there is no warranty for the work (except to the 113 | extent that warranties are provided), that licensees may convey the 114 | work under this License, and how to view a copy of this License. If 115 | the interface presents a list of user commands or options, such as a 116 | menu, a prominent item in the list meets this criterion. 117 | 118 | #### 1. Source Code. 119 | 120 | The "source code" for a work means the preferred form of the work for 121 | making modifications to it. "Object code" means any non-source form of 122 | a work. 123 | 124 | A "Standard Interface" means an interface that either is an official 125 | standard defined by a recognized standards body, or, in the case of 126 | interfaces specified for a particular programming language, one that 127 | is widely used among developers working in that language. 128 | 129 | The "System Libraries" of an executable work include anything, other 130 | than the work as a whole, that (a) is included in the normal form of 131 | packaging a Major Component, but which is not part of that Major 132 | Component, and (b) serves only to enable use of the work with that 133 | Major Component, or to implement a Standard Interface for which an 134 | implementation is available to the public in source code form. A 135 | "Major Component", in this context, means a major essential component 136 | (kernel, window system, and so on) of the specific operating system 137 | (if any) on which the executable work runs, or a compiler used to 138 | produce the work, or an object code interpreter used to run it. 139 | 140 | The "Corresponding Source" for a work in object code form means all 141 | the source code needed to generate, install, and (for an executable 142 | work) run the object code and to modify the work, including scripts to 143 | control those activities. However, it does not include the work's 144 | System Libraries, or general-purpose tools or generally available free 145 | programs which are used unmodified in performing those activities but 146 | which are not part of the work. For example, Corresponding Source 147 | includes interface definition files associated with source files for 148 | the work, and the source code for shared libraries and dynamically 149 | linked subprograms that the work is specifically designed to require, 150 | such as by intimate data communication or control flow between those 151 | subprograms and other parts of the work. 152 | 153 | The Corresponding Source need not include anything that users can 154 | regenerate automatically from other parts of the Corresponding Source. 155 | 156 | The Corresponding Source for a work in source code form is that same 157 | work. 158 | 159 | #### 2. Basic Permissions. 160 | 161 | All rights granted under this License are granted for the term of 162 | copyright on the Program, and are irrevocable provided the stated 163 | conditions are met. This License explicitly affirms your unlimited 164 | permission to run the unmodified Program. The output from running a 165 | covered work is covered by this License only if the output, given its 166 | content, constitutes a covered work. This License acknowledges your 167 | rights of fair use or other equivalent, as provided by copyright law. 168 | 169 | You may make, run and propagate covered works that you do not convey, 170 | without conditions so long as your license otherwise remains in force. 171 | You may convey covered works to others for the sole purpose of having 172 | them make modifications exclusively for you, or provide you with 173 | facilities for running those works, provided that you comply with the 174 | terms of this License in conveying all material for which you do not 175 | control copyright. Those thus making or running the covered works for 176 | you must do so exclusively on your behalf, under your direction and 177 | control, on terms that prohibit them from making any copies of your 178 | copyrighted material outside their relationship with you. 179 | 180 | Conveying under any other circumstances is permitted solely under the 181 | conditions stated below. Sublicensing is not allowed; section 10 makes 182 | it unnecessary. 183 | 184 | #### 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 185 | 186 | No covered work shall be deemed part of an effective technological 187 | measure under any applicable law fulfilling obligations under article 188 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 189 | similar laws prohibiting or restricting circumvention of such 190 | measures. 191 | 192 | When you convey a covered work, you waive any legal power to forbid 193 | circumvention of technological measures to the extent such 194 | circumvention is effected by exercising rights under this License with 195 | respect to the covered work, and you disclaim any intention to limit 196 | operation or modification of the work as a means of enforcing, against 197 | the work's users, your or third parties' legal rights to forbid 198 | circumvention of technological measures. 199 | 200 | #### 4. Conveying Verbatim Copies. 201 | 202 | You may convey verbatim copies of the Program's source code as you 203 | receive it, in any medium, provided that you conspicuously and 204 | appropriately publish on each copy an appropriate copyright notice; 205 | keep intact all notices stating that this License and any 206 | non-permissive terms added in accord with section 7 apply to the code; 207 | keep intact all notices of the absence of any warranty; and give all 208 | recipients a copy of this License along with the Program. 209 | 210 | You may charge any price or no price for each copy that you convey, 211 | and you may offer support or warranty protection for a fee. 212 | 213 | #### 5. Conveying Modified Source Versions. 214 | 215 | You may convey a work based on the Program, or the modifications to 216 | produce it from the Program, in the form of source code under the 217 | terms of section 4, provided that you also meet all of these 218 | conditions: 219 | 220 | - a) The work must carry prominent notices stating that you modified 221 | it, and giving a relevant date. 222 | - b) The work must carry prominent notices stating that it is 223 | released under this License and any conditions added under 224 | section 7. This requirement modifies the requirement in section 4 225 | to "keep intact all notices". 226 | - c) You must license the entire work, as a whole, under this 227 | License to anyone who comes into possession of a copy. This 228 | License will therefore apply, along with any applicable section 7 229 | additional terms, to the whole of the work, and all its parts, 230 | regardless of how they are packaged. This License gives no 231 | permission to license the work in any other way, but it does not 232 | invalidate such permission if you have separately received it. 233 | - d) If the work has interactive user interfaces, each must display 234 | Appropriate Legal Notices; however, if the Program has interactive 235 | interfaces that do not display Appropriate Legal Notices, your 236 | work need not make them do so. 237 | 238 | A compilation of a covered work with other separate and independent 239 | works, which are not by their nature extensions of the covered work, 240 | and which are not combined with it such as to form a larger program, 241 | in or on a volume of a storage or distribution medium, is called an 242 | "aggregate" if the compilation and its resulting copyright are not 243 | used to limit the access or legal rights of the compilation's users 244 | beyond what the individual works permit. Inclusion of a covered work 245 | in an aggregate does not cause this License to apply to the other 246 | parts of the aggregate. 247 | 248 | #### 6. Conveying Non-Source Forms. 249 | 250 | You may convey a covered work in object code form under the terms of 251 | sections 4 and 5, provided that you also convey the machine-readable 252 | Corresponding Source under the terms of this License, in one of these 253 | ways: 254 | 255 | - a) Convey the object code in, or embodied in, a physical product 256 | (including a physical distribution medium), accompanied by the 257 | Corresponding Source fixed on a durable physical medium 258 | customarily used for software interchange. 259 | - b) Convey the object code in, or embodied in, a physical product 260 | (including a physical distribution medium), accompanied by a 261 | written offer, valid for at least three years and valid for as 262 | long as you offer spare parts or customer support for that product 263 | model, to give anyone who possesses the object code either (1) a 264 | copy of the Corresponding Source for all the software in the 265 | product that is covered by this License, on a durable physical 266 | medium customarily used for software interchange, for a price no 267 | more than your reasonable cost of physically performing this 268 | conveying of source, or (2) access to copy the Corresponding 269 | Source from a network server at no charge. 270 | - c) Convey individual copies of the object code with a copy of the 271 | written offer to provide the Corresponding Source. This 272 | alternative is allowed only occasionally and noncommercially, and 273 | only if you received the object code with such an offer, in accord 274 | with subsection 6b. 275 | - d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | - e) Convey the object code using peer-to-peer transmission, 288 | provided you inform other peers where the object code and 289 | Corresponding Source of the work are being offered to the general 290 | public at no charge under subsection 6d. 291 | 292 | A separable portion of the object code, whose source code is excluded 293 | from the Corresponding Source as a System Library, need not be 294 | included in conveying the object code work. 295 | 296 | A "User Product" is either (1) a "consumer product", which means any 297 | tangible personal property which is normally used for personal, 298 | family, or household purposes, or (2) anything designed or sold for 299 | incorporation into a dwelling. In determining whether a product is a 300 | consumer product, doubtful cases shall be resolved in favor of 301 | coverage. For a particular product received by a particular user, 302 | "normally used" refers to a typical or common use of that class of 303 | product, regardless of the status of the particular user or of the way 304 | in which the particular user actually uses, or expects or is expected 305 | to use, the product. A product is a consumer product regardless of 306 | whether the product has substantial commercial, industrial or 307 | non-consumer uses, unless such uses represent the only significant 308 | mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to 312 | install and execute modified versions of a covered work in that User 313 | Product from a modified version of its Corresponding Source. The 314 | information must suffice to ensure that the continued functioning of 315 | the modified object code is in no case prevented or interfered with 316 | solely because modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or 331 | updates for a work that has been modified or installed by the 332 | recipient, or for the User Product in which it has been modified or 333 | installed. Access to a network may be denied when the modification 334 | itself materially and adversely affects the operation of the network 335 | or violates the rules and protocols for communication across the 336 | network. 337 | 338 | Corresponding Source conveyed, and Installation Information provided, 339 | in accord with this section must be in a format that is publicly 340 | documented (and with an implementation available to the public in 341 | source code form), and must require no special password or key for 342 | unpacking, reading or copying. 343 | 344 | #### 7. Additional Terms. 345 | 346 | "Additional permissions" are terms that supplement the terms of this 347 | License by making exceptions from one or more of its conditions. 348 | Additional permissions that are applicable to the entire Program shall 349 | be treated as though they were included in this License, to the extent 350 | that they are valid under applicable law. If additional permissions 351 | apply only to part of the Program, that part may be used separately 352 | under those permissions, but the entire Program remains governed by 353 | this License without regard to the additional permissions. 354 | 355 | When you convey a copy of a covered work, you may at your option 356 | remove any additional permissions from that copy, or from any part of 357 | it. (Additional permissions may be written to require their own 358 | removal in certain cases when you modify the work.) You may place 359 | additional permissions on material, added by you to a covered work, 360 | for which you have or can give appropriate copyright permission. 361 | 362 | Notwithstanding any other provision of this License, for material you 363 | add to a covered work, you may (if authorized by the copyright holders 364 | of that material) supplement the terms of this License with terms: 365 | 366 | - a) Disclaiming warranty or limiting liability differently from the 367 | terms of sections 15 and 16 of this License; or 368 | - b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | - c) Prohibiting misrepresentation of the origin of that material, 372 | or requiring that modified versions of such material be marked in 373 | reasonable ways as different from the original version; or 374 | - d) Limiting the use for publicity purposes of names of licensors 375 | or authors of the material; or 376 | - e) Declining to grant rights under trademark law for use of some 377 | trade names, trademarks, or service marks; or 378 | - f) Requiring indemnification of licensors and authors of that 379 | material by anyone who conveys the material (or modified versions 380 | of it) with contractual assumptions of liability to the recipient, 381 | for any liability that these contractual assumptions directly 382 | impose on those licensors and authors. 383 | 384 | All other non-permissive additional terms are considered "further 385 | restrictions" within the meaning of section 10. If the Program as you 386 | received it, or any part of it, contains a notice stating that it is 387 | governed by this License along with a term that is a further 388 | restriction, you may remove that term. If a license document contains 389 | a further restriction but permits relicensing or conveying under this 390 | License, you may add to a covered work material governed by the terms 391 | of that license document, provided that the further restriction does 392 | not survive such relicensing or conveying. 393 | 394 | If you add terms to a covered work in accord with this section, you 395 | must place, in the relevant source files, a statement of the 396 | additional terms that apply to those files, or a notice indicating 397 | where to find the applicable terms. 398 | 399 | Additional terms, permissive or non-permissive, may be stated in the 400 | form of a separately written license, or stated as exceptions; the 401 | above requirements apply either way. 402 | 403 | #### 8. Termination. 404 | 405 | You may not propagate or modify a covered work except as expressly 406 | provided under this License. Any attempt otherwise to propagate or 407 | modify it is void, and will automatically terminate your rights under 408 | this License (including any patent licenses granted under the third 409 | paragraph of section 11). 410 | 411 | However, if you cease all violation of this License, then your license 412 | from a particular copyright holder is reinstated (a) provisionally, 413 | unless and until the copyright holder explicitly and finally 414 | terminates your license, and (b) permanently, if the copyright holder 415 | fails to notify you of the violation by some reasonable means prior to 416 | 60 days after the cessation. 417 | 418 | Moreover, your license from a particular copyright holder is 419 | reinstated permanently if the copyright holder notifies you of the 420 | violation by some reasonable means, this is the first time you have 421 | received notice of violation of this License (for any work) from that 422 | copyright holder, and you cure the violation prior to 30 days after 423 | your receipt of the notice. 424 | 425 | Termination of your rights under this section does not terminate the 426 | licenses of parties who have received copies or rights from you under 427 | this License. If your rights have been terminated and not permanently 428 | reinstated, you do not qualify to receive new licenses for the same 429 | material under section 10. 430 | 431 | #### 9. Acceptance Not Required for Having Copies. 432 | 433 | You are not required to accept this License in order to receive or run 434 | a copy of the Program. Ancillary propagation of a covered work 435 | occurring solely as a consequence of using peer-to-peer transmission 436 | to receive a copy likewise does not require acceptance. However, 437 | nothing other than this License grants you permission to propagate or 438 | modify any covered work. These actions infringe copyright if you do 439 | not accept this License. Therefore, by modifying or propagating a 440 | covered work, you indicate your acceptance of this License to do so. 441 | 442 | #### 10. Automatic Licensing of Downstream Recipients. 443 | 444 | Each time you convey a covered work, the recipient automatically 445 | receives a license from the original licensors, to run, modify and 446 | propagate that work, subject to this License. You are not responsible 447 | for enforcing compliance by third parties with this License. 448 | 449 | An "entity transaction" is a transaction transferring control of an 450 | organization, or substantially all assets of one, or subdividing an 451 | organization, or merging organizations. If propagation of a covered 452 | work results from an entity transaction, each party to that 453 | transaction who receives a copy of the work also receives whatever 454 | licenses to the work the party's predecessor in interest had or could 455 | give under the previous paragraph, plus a right to possession of the 456 | Corresponding Source of the work from the predecessor in interest, if 457 | the predecessor has it or can get it with reasonable efforts. 458 | 459 | You may not impose any further restrictions on the exercise of the 460 | rights granted or affirmed under this License. For example, you may 461 | not impose a license fee, royalty, or other charge for exercise of 462 | rights granted under this License, and you may not initiate litigation 463 | (including a cross-claim or counterclaim in a lawsuit) alleging that 464 | any patent claim is infringed by making, using, selling, offering for 465 | sale, or importing the Program or any portion of it. 466 | 467 | #### 11. Patents. 468 | 469 | A "contributor" is a copyright holder who authorizes use under this 470 | License of the Program or a work on which the Program is based. The 471 | work thus licensed is called the contributor's "contributor version". 472 | 473 | A contributor's "essential patent claims" are all patent claims owned 474 | or controlled by the contributor, whether already acquired or 475 | hereafter acquired, that would be infringed by some manner, permitted 476 | by this License, of making, using, or selling its contributor version, 477 | but do not include claims that would be infringed only as a 478 | consequence of further modification of the contributor version. For 479 | purposes of this definition, "control" includes the right to grant 480 | patent sublicenses in a manner consistent with the requirements of 481 | this License. 482 | 483 | Each contributor grants you a non-exclusive, worldwide, royalty-free 484 | patent license under the contributor's essential patent claims, to 485 | make, use, sell, offer for sale, import and otherwise run, modify and 486 | propagate the contents of its contributor version. 487 | 488 | In the following three paragraphs, a "patent license" is any express 489 | agreement or commitment, however denominated, not to enforce a patent 490 | (such as an express permission to practice a patent or covenant not to 491 | sue for patent infringement). To "grant" such a patent license to a 492 | party means to make such an agreement or commitment not to enforce a 493 | patent against the party. 494 | 495 | If you convey a covered work, knowingly relying on a patent license, 496 | and the Corresponding Source of the work is not available for anyone 497 | to copy, free of charge and under the terms of this License, through a 498 | publicly available network server or other readily accessible means, 499 | then you must either (1) cause the Corresponding Source to be so 500 | available, or (2) arrange to deprive yourself of the benefit of the 501 | patent license for this particular work, or (3) arrange, in a manner 502 | consistent with the requirements of this License, to extend the patent 503 | license to downstream recipients. "Knowingly relying" means you have 504 | actual knowledge that, but for the patent license, your conveying the 505 | covered work in a country, or your recipient's use of the covered work 506 | in a country, would infringe one or more identifiable patents in that 507 | country that you have reason to believe are valid. 508 | 509 | If, pursuant to or in connection with a single transaction or 510 | arrangement, you convey, or propagate by procuring conveyance of, a 511 | covered work, and grant a patent license to some of the parties 512 | receiving the covered work authorizing them to use, propagate, modify 513 | or convey a specific copy of the covered work, then the patent license 514 | you grant is automatically extended to all recipients of the covered 515 | work and works based on it. 516 | 517 | A patent license is "discriminatory" if it does not include within the 518 | scope of its coverage, prohibits the exercise of, or is conditioned on 519 | the non-exercise of one or more of the rights that are specifically 520 | granted under this License. You may not convey a covered work if you 521 | are a party to an arrangement with a third party that is in the 522 | business of distributing software, under which you make payment to the 523 | third party based on the extent of your activity of conveying the 524 | work, and under which the third party grants, to any of the parties 525 | who would receive the covered work from you, a discriminatory patent 526 | license (a) in connection with copies of the covered work conveyed by 527 | you (or copies made from those copies), or (b) primarily for and in 528 | connection with specific products or compilations that contain the 529 | covered work, unless you entered into that arrangement, or that patent 530 | license was granted, prior to 28 March 2007. 531 | 532 | Nothing in this License shall be construed as excluding or limiting 533 | any implied license or other defenses to infringement that may 534 | otherwise be available to you under applicable patent law. 535 | 536 | #### 12. No Surrender of Others' Freedom. 537 | 538 | If conditions are imposed on you (whether by court order, agreement or 539 | otherwise) that contradict the conditions of this License, they do not 540 | excuse you from the conditions of this License. If you cannot convey a 541 | covered work so as to satisfy simultaneously your obligations under 542 | this License and any other pertinent obligations, then as a 543 | consequence you may not convey it at all. For example, if you agree to 544 | terms that obligate you to collect a royalty for further conveying 545 | from those to whom you convey the Program, the only way you could 546 | satisfy both those terms and this License would be to refrain entirely 547 | from conveying the Program. 548 | 549 | #### 13. Use with the GNU Affero General Public License. 550 | 551 | Notwithstanding any other provision of this License, you have 552 | permission to link or combine any covered work with a work licensed 553 | under version 3 of the GNU Affero General Public License into a single 554 | combined work, and to convey the resulting work. The terms of this 555 | License will continue to apply to the part which is the covered work, 556 | but the special requirements of the GNU Affero General Public License, 557 | section 13, concerning interaction through a network will apply to the 558 | combination as such. 559 | 560 | #### 14. Revised Versions of this License. 561 | 562 | The Free Software Foundation may publish revised and/or new versions 563 | of the GNU General Public License from time to time. Such new versions 564 | will be similar in spirit to the present version, but may differ in 565 | detail to address new problems or concerns. 566 | 567 | Each version is given a distinguishing version number. If the Program 568 | specifies that a certain numbered version of the GNU General Public 569 | License "or any later version" applies to it, you have the option of 570 | following the terms and conditions either of that numbered version or 571 | of any later version published by the Free Software Foundation. If the 572 | Program does not specify a version number of the GNU General Public 573 | License, you may choose any version ever published by the Free 574 | Software Foundation. 575 | 576 | If the Program specifies that a proxy can decide which future versions 577 | of the GNU General Public License can be used, that proxy's public 578 | statement of acceptance of a version permanently authorizes you to 579 | choose that version for the Program. 580 | 581 | Later license versions may give you additional or different 582 | permissions. However, no additional obligations are imposed on any 583 | author or copyright holder as a result of your choosing to follow a 584 | later version. 585 | 586 | #### 15. Disclaimer of Warranty. 587 | 588 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 589 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 590 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT 591 | WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT 592 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 593 | A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND 594 | PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE 595 | DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR 596 | 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 602 | CONVEYS THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, 603 | INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES 604 | ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT 605 | NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR 606 | LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM 607 | TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER 608 | PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 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 626 | terms. 627 | 628 | To do so, attach the following notices to the program. It is safest to 629 | attach them to the start of each source file to most effectively state 630 | the exclusion of warranty; and each file should have at least the 631 | "copyright" line and a pointer to where the full notice is found. 632 | 633 | 634 | Copyright (C) 635 | 636 | This program is free software: you can redistribute it and/or modify 637 | it under the terms of the GNU General Public License as published by 638 | the Free Software Foundation, either version 3 of the License, or 639 | (at your option) any later version. 640 | 641 | This program is distributed in the hope that it will be useful, 642 | but WITHOUT ANY WARRANTY; without even the implied warranty of 643 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 644 | GNU General Public License for more details. 645 | 646 | You should have received a copy of the GNU General Public License 647 | along with this program. If not, see . 648 | 649 | Also add information on how to contact you by electronic and paper 650 | mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands \`show w' and \`show c' should show the 661 | appropriate parts of the General Public License. Of course, your 662 | program's commands might be different; for a GUI interface, you would 663 | use an "about box". 664 | 665 | You should also get your employer (if you work as a programmer) or 666 | school, if any, to sign a "copyright disclaimer" for the program, if 667 | necessary. For more information on this, and how to apply and follow 668 | the GNU GPL, see . 669 | 670 | The GNU General Public License does not permit incorporating your 671 | program into proprietary programs. If your program is a subroutine 672 | library, you may consider it more useful to permit linking proprietary 673 | applications with the library. If this is what you want to do, use the 674 | GNU Lesser General Public License instead of this License. But first, 675 | please read . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MSync-2 2 | 3 | ![BuildStatus](https://tcci.aperture-development.de/app/rest/builds/buildType:(id:MSync2_BuildTestPublish)/statusIcon.svg) 4 | [![Issues](https://img.shields.io/github/issues-raw/Aperture-Development/MSync-2.svg)](https://github.com/Aperture-Development/MSync-2/issues) 5 | [![Chat](https://img.shields.io/discord/272563407209889792.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://discord.gg/JpDPa6w) 6 | ![Size](https://img.shields.io/github/repo-size/Aperture-Development/MSync-2.svg) 7 | [![Licence](https://img.shields.io/github/license/Aperture-Development/MSync-2)](https://github.com/Aperture-Development/MSync-2/blob/master/LICENSE) 8 | [![Release](https://img.shields.io/github/release/Aperture-Development/MSync-2.svg)](https://github.com/Aperture-Development/MSync-2/releases) 9 | 10 | What is MSync-2 ? 11 | 12 | MSync is a all around GMod server synchronisation addon. The addon is and will always be free to use. 13 | 14 | MSync 2 is a new version of https://github.com/Aperture-Development/MSync 15 | 16 | It requires [MySQLoo](https://github.com/FredyH/MySQLOO) to work. 17 | 18 | **Why version 2?** 19 | 20 | Let's be honest here, version one is a broken piece of shit. It errors out everywhere, the GUI does not work and when you remove it, all bans and stuff are lost, because we overwrite the origiinal commands. 21 | 22 | It was my first addon I ever made, and now looking back with my new knowledge, I feel ashamed for the code. 23 | 24 | Version 2 will include a lot of changes, like: 25 | - New Database Structure 26 | - Completly own GUI System (Means we use GMod ressources and not XGUI anymore, because XGUI is shit) 27 | - Module system, to easily extend features 28 | - STEAK 29 | 30 | 31 | # A Note to the different versions 32 | 33 | MSync 2 is Split up in 3 versions: 34 | - EGG 35 | - CHEESE 36 | - STEAK 37 | 38 | **EGG** is the WIP addon which does not work yet at all. DO NOT USE ANYTHING OF THIS! The file structure will change propably. If you have problems with a EGG version, we do not Provide support. Use the STEAK version or at least CHEESE. 39 | 40 | **CHEESE** is the beta phase of the addon. The addon works, but has propably bugs everywhere that needs to be found yet. If you have errors whith this version, please inform us with a GitHub issue or over our ticketsystem: [https://www.Aperture-Development.de/ticketsystem](https://www.Aperture-Development.de/ticketsystem) 41 | 42 | **STEAK** is the stable version of MSync 2. This version is safe to be used on your server. 43 | 44 | **Why do all versions are named after food?** 45 | 46 | Because it's a joke, as you maybe know, Debian distributions are named after the characters of Toy Story, and I thought its funny to have something like that for our Addons. 47 | 48 | # A note to modules 49 | 50 | If you plan on extending the features of MSync 2, please copy and use the samplemodule files. You can distribute the Module under every licence you like. We always use the root_dir/LICENCE which is basicly the Licence you get the addon with. MSync 2 is licensed under GPL 3.0, please read the LICENSE file for more informations. 51 | 52 | # Installation 53 | 54 | You need to install some things manually on the Server in order for MSync to work. 55 | 56 | First you need libmysql on windows or libmysqlclient on linux. You can find them here: 57 | Windows: https://github.com/FredyH/MySQLOO/raw/master/MySQL/lib/windows/libmysql.dll 58 | Linux: https://github.com/FredyH/MySQLOO/raw/master/MySQL/lib/linux/libmysqlclient.so.18 59 | Put the file in the same folder where your scrds.exe or your scrds_linux file is. 60 | 61 | Then you need MySQLoo 9 or higher. You can download MySQLoo from here: 62 | https://github.com/FredyH/MySQLOO/releases 63 | Select win32 if your server runs on windows, otherwise use the linux dll. 64 | Put the dll file in your lua/bin folder. If you don't have one, create it. 65 | it should look like this: 66 | 67 | ``` 68 | bin 69 | garrysmod 70 | ->lua 71 | -->bin 72 | --->gmsv_mysql_.dll 73 | ``` 74 | 75 | After that just install the addon by putting it in your servers workshop collection or download the zip file from github and put the folder in your servers addon folder: 76 | https://github.com/Aperture-Development/MSync-2/archive/master.zip 77 | 78 | When the server is started, everything should be ready for MSync 2. You can access the admin gui using "!msync" 79 | 80 | # Features 81 | 82 | **Server Groups:** 83 | 84 | >Server groups allow you to group your servers in sub teams. Modules will just sync things that are explicity told to sync it across all servers, otherwise it will just sync it with servers that have the same server group. 85 | 86 | 87 | **MRSync:** 88 | 89 | >**M**ySQL **R**ank **Sync**hronisation 90 | > 91 | >MRSync allows you to synchronise your staff team across your servers without the need to add/remove a staff member on every server. Just add a user to a rank and he will also have the rank on all other servers. For now it is important that the ranks you synchronise also exist on all servers. 92 | > 93 | >You want some ranks to not be synced? 94 | There is a rank blacklist for ranks that dont get saved to the database. Just add the rank and you are good to go. 95 | > 96 | >You want some ranks to be synced across all servers and some just for ( as example ) your DarkRP servers? 97 | The server_group option allows you to do just that. Just sub-categorise your servers and your ranks now just get synced within this group. You can exclude ranks from that rule and force them to synchronise across all servers using the allserver table, all ranks in that table get saved as ranks for the whole network. 98 | 99 | 100 | **MBSync:** 101 | 102 | >**M**ySQL **B**an **Sync**hronisation 103 | > 104 | >MBSync allos you to synchronise your bans across all servers ( network bans ). This Module is also server_group bound, means when you ban a user on a server in the group darkrp they dont get banned on servers with a different group. 105 | > 106 | >**Commands:** 107 | > 108 | >!mban - Opens ban GUI 109 | > 110 | >!mban [Name] [Length] [global] [Reason] - bans a player 111 | > 112 | >!mbanid [SteamID/SteamID64] [Length] [global] [Reason] - bans a players steamid 113 | > 114 | >!munban [SteamID/SteamID64] - unbans a player 115 | > 116 | >!mbsync - Opens Ban list 117 | > 118 | >!mcheck [SteamID/SteamID64] - Checks if the given steamid if it is banned 119 | > 120 | >!medit [BanID] [Length] [Global] [Reason] - Edits a ban 121 | > 122 | > 123 | >**Console Commands:** 124 | > 125 | >msync.mbsync.banPlayer [Name] [Length] [global] [Reason] - bans a player 126 | > 127 | >msync.mbsync.bansteamid [SteamID/SteamID64] [Length] [global] [Reason] - bans a players steamid 128 | > 129 | >msync.mbsync.unbanid [SteamID/SteamID64] - unbans a player 130 | > 131 | >msync.mbsync.checkBan [SteamID/SteamID64] - Checks if the given steamid if it is banned 132 | > 133 | >msync.mbsync.editBan [BanID] [Length] [Global] [Reason] - Edits a ban 134 | 135 | 136 | **Planned Features** 137 | 138 | >- UTime synchronisation - Codename: MUSync 139 | >- MySQL Warning system - Codename: MWS 140 | >- Permission synchronisation - Codename: MPSync 141 | >- MSync synchronisation - Codename: MSSync 142 | 143 | 144 | 145 | # Other info 146 | 147 | MSync 2 is distributed under the GNU General Public Licence 3.0 licence. Please read the LICENCE file in the root directory of MSync 2 to find out more. 148 | 149 | ![GPL 3.0](https://www.gnu.org/graphics/gplv3-127x51.png) -------------------------------------------------------------------------------- /addon.json: -------------------------------------------------------------------------------- 1 | { 2 | "title" : "MSync 2 - Now with steak", 3 | "type" : "ServerContent", 4 | "tags" : [ "roleplay", "realism" ], 5 | "ignore" : 6 | [ 7 | "*.psd", 8 | "*.vcproj", 9 | "*.svn*", 10 | "*samplemodule.lua", 11 | "LICENSE", 12 | "README.md", 13 | "*.sql", 14 | ".git/*", 15 | ".git*", 16 | ".vscode*" 17 | ] 18 | } -------------------------------------------------------------------------------- /database.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Manual Database Setup File 3 | */ 4 | CREATE DATABASE IF NOT EXISTS `msync`; 5 | 6 | USE `msync`; 7 | 8 | CREATE TABLE IF NOT EXISTS `tbl_msyncdb_version` ( `version` float NOT NULL ); 9 | 10 | CREATE TABLE IF NOT EXISTS `tbl_msync_servers` ( 11 | `p_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 12 | `server_name` VARCHAR(55) NOT NULL, 13 | `options` VARCHAR(100) NOT NULL DEFAULT '[]', 14 | `ip` INT NOT NULL, 15 | `port` VARCHAR(5) NOT NULL, 16 | `server_group` INT NOT NULL, 17 | UNIQUE INDEX `server_UNIQUE` (`ip`, `port`) 18 | ); 19 | 20 | CREATE TABLE IF NOT EXISTS `tbl_server_grp` ( 21 | `p_group_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 22 | `group_name` VARCHAR(15) NOT NULL, 23 | UNIQUE INDEX `group_UNIQUE` (`group_name`) 24 | ); 25 | 26 | CREATE TABLE IF NOT EXISTS `tbl_users` ( 27 | `p_user_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 28 | `steamid` VARCHAR(20) NOT NULL, 29 | `steamid64` VARCHAR(17) NOT NULL, 30 | `nickname` VARCHAR(30) NOT NULL, 31 | `joined` DATETIME NOT NULL, 32 | UNIQUE INDEX `steamid_UNIQUE` (`steamid`), 33 | UNIQUE INDEX `steamid64_UNIQUE` (`steamid64`) 34 | ); 35 | 36 | CREATE TABLE IF NOT EXISTS `tbl_mbsync` ( 37 | `p_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 38 | `userid` INT UNSIGNED NOT NULL, 39 | `adminid` INT UNSIGNED NOT NULL, 40 | `reason` VARCHAR(45) NOT NULL, 41 | `date_unix` float NOT NULL, 42 | `length_unix` float NOT NULL, 43 | `server_group` INT UNSIGNED NOT NULL, 44 | `ban_lifted` INT UNSIGNED, 45 | FOREIGN KEY (server_group) REFERENCES tbl_server_grp(p_group_id), 46 | FOREIGN KEY (userid) REFERENCES tbl_users(p_user_id), 47 | FOREIGN KEY (adminid) REFERENCES tbl_users(p_user_id) 48 | ); 49 | 50 | CREATE TABLE IF NOT EXISTS `tbl_mrsync` ( 51 | `p_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 52 | `user_id` INT UNSIGNED NOT NULL, 53 | `rank` VARCHAR(15) NOT NULL, 54 | `server_group` INT UNSIGNED NOT NULL, 55 | FOREIGN KEY (server_group) REFERENCES tbl_server_grp(p_group_id), 56 | FOREIGN KEY (user_id) REFERENCES tbl_users(p_user_id), 57 | UNIQUE INDEX `user_UNIQUE` (`user_id`, `server_group`) 58 | ); 59 | 60 | CREATE TABLE IF NOT EXISTS `tbl_mws` ( 61 | `p_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 62 | `userid` INT UNSIGNED NOT NULL, 63 | `adminid` INT UNSIGNED NOT NULL, 64 | `reason` VARCHAR(45) NOT NULL, 65 | `date_unix` float NOT NULL, 66 | `expire` float NOT NULL, 67 | `server_group` INT UNSIGNED NOT NULL, 68 | FOREIGN KEY (server_group) REFERENCES tbl_server_grp(p_group_id), 69 | FOREIGN KEY (userid) REFERENCES tbl_users(p_user_id), 70 | FOREIGN KEY (adminid) REFERENCES tbl_users(p_user_id) 71 | ); 72 | 73 | CREATE TABLE IF NOT EXISTS `tbl_mrs` ( 74 | `p_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 75 | `userid` INT UNSIGNED NOT NULL, 76 | `adminid` INT UNSIGNED NOT NULL, 77 | `resolved` BOOLEAN DEFAULT FALSE, 78 | `message` VARCHAR(100) NOT NULL, 79 | `server_group` INT UNSIGNED NOT NULL, 80 | FOREIGN KEY (server_group) REFERENCES tbl_server_grp(p_group_id), 81 | FOREIGN KEY (userid) REFERENCES tbl_users(p_user_id), 82 | FOREIGN KEY (adminid) REFERENCES tbl_users(p_user_id) 83 | ); 84 | 85 | CREATE TABLE IF NOT EXISTS `tbl_musync` ( 86 | `p_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 87 | `userid` INT UNSIGNED NOT NULL, 88 | `time` INT UNSIGNED NOT NULL, 89 | `server_group` INT UNSIGNED NOT NULL, 90 | FOREIGN KEY (server_group) REFERENCES tbl_server_grp(p_group_id), 91 | FOREIGN KEY (userid) REFERENCES tbl_users(p_user_id) 92 | ); -------------------------------------------------------------------------------- /fake_data.sql: -------------------------------------------------------------------------------- 1 | /*INSERT INTO tbl_users (steamid, steamid64, nickname, joined) VALUES ('STEAM_0:0:1', '760000001', 'User 1', '2020-04-09 17:00'); 2 | INSERT INTO tbl_users (steamid, steamid64, nickname, joined) VALUES ('STEAM_0:0:2', '760000002', 'User 2', '2020-04-09 17:00'); 3 | INSERT INTO tbl_users (steamid, steamid64, nickname, joined) VALUES ('STEAM_0:0:3', '760000003', 'User 3', '2020-04-09 17:00'); 4 | INSERT INTO tbl_users (steamid, steamid64, nickname, joined) VALUES ('STEAM_0:0:4', '760000004', 'User 4', '2020-04-09 17:00'); 5 | INSERT INTO tbl_users (steamid, steamid64, nickname, joined) VALUES ('STEAM_0:0:5', '760000005', 'User 5', '2020-04-09 17:00'); 6 | INSERT INTO tbl_users (steamid, steamid64, nickname, joined) VALUES ('STEAM_0:0:6', '760000006', 'User 6', '2020-04-09 17:00'); 7 | INSERT INTO tbl_users (steamid, steamid64, nickname, joined) VALUES ('STEAM_0:0:7', '760000007', 'User 7', '2020-04-09 17:00');*/ 8 | 9 | INSERT INTO tbl_mbsync (user_id, admin_id, reason, date_unix, length_unix, server_group) VALUES (7, 2, 'Test 1', 1586445390, 99999999, 1); 10 | INSERT INTO tbl_mbsync (user_id, admin_id, reason, date_unix, length_unix, server_group) VALUES (2, 3, 'Test 2', 1586445390, 99999999, 1); 11 | INSERT INTO tbl_mbsync (user_id, admin_id, reason, date_unix, length_unix, server_group) VALUES (3, 4, 'Test 3', 1586445390, 99999999, 1); 12 | INSERT INTO tbl_mbsync (user_id, admin_id, reason, date_unix, length_unix, server_group) VALUES (4, 5, 'Test 4', 1586445390, 99999999, 1); 13 | INSERT INTO tbl_mbsync (user_id, admin_id, reason, date_unix, length_unix, server_group) VALUES (5, 6, 'Test 5', 1586445390, 99999999, 1); 14 | INSERT INTO tbl_mbsync (user_id, admin_id, reason, date_unix, length_unix, server_group) VALUES (6, 7, 'Test 6', 1586445390, 99999999, 1); -------------------------------------------------------------------------------- /lua/autorun/msync_autorun.lua: -------------------------------------------------------------------------------- 1 | if SERVER then 2 | include("msync/sh_init.lua") 3 | AddCSLuaFile("msync/sh_init.lua") 4 | 5 | include("msync/server/sv_init.lua") 6 | 7 | MSync.func.loadServer() 8 | elseif CLIENT then 9 | include("msync/sh_init.lua") 10 | 11 | include("msync/client_gui/cl_admin_gui.lua") 12 | include("msync/client_gui/cl_init.lua") 13 | include("msync/client_gui/cl_net.lua") 14 | include("msync/client_gui/cl_modules.lua") 15 | 16 | end -------------------------------------------------------------------------------- /lua/msync/client_gui/cl_admin_gui.lua: -------------------------------------------------------------------------------- 1 | MSync = MSync or {} 2 | MSync.AdminPanel = MSync.AdminPanel or {} 3 | 4 | --[[ 5 | Description: MySQL settings panel 6 | Arguments: parent sheet 7 | Returns: panel 8 | ]] 9 | function MSync.AdminPanel.InitMySQL( sheet ) 10 | 11 | MSync.log(MSYNC_DBG_DEBUG, "Initializing MySQL settings panel") 12 | 13 | local pnl = vgui.Create( "DPanel", sheet ) 14 | 15 | local mysqlip_text = vgui.Create( "DLabel", pnl ) 16 | mysqlip_text:SetPos( 25, 10 ) 17 | mysqlip_text:SetColor( Color( 0, 0, 0 ) ) 18 | mysqlip_text:SetText( "Host IP" ) 19 | 20 | local mysqlip = vgui.Create( "DTextEntry", pnl ) 21 | mysqlip:SetPos( 25, 30 ) 22 | mysqlip:SetSize( 150, 20 ) 23 | mysqlip:SetText( "127.0.0.1" ) 24 | 25 | local mysqlport_text = vgui.Create( "DLabel", pnl ) 26 | mysqlport_text:SetPos( 25, 55 ) 27 | mysqlport_text:SetColor( Color( 0, 0, 0 ) ) 28 | mysqlport_text:SetText( "Host Port" ) 29 | 30 | local mysqlport = vgui.Create( "DTextEntry", pnl ) 31 | mysqlport:SetPos( 25, 75 ) 32 | mysqlport:SetSize( 150, 20 ) 33 | mysqlport:SetText( "3306" ) 34 | 35 | local mysqldb_text = vgui.Create( "DLabel", pnl ) 36 | mysqldb_text:SetPos( 25, 100 ) 37 | mysqldb_text:SetColor( Color( 0, 0, 0 ) ) 38 | mysqldb_text:SetText( "Database" ) 39 | 40 | local mysqldb = vgui.Create( "DTextEntry", pnl ) 41 | mysqldb:SetPos( 25, 120 ) 42 | mysqldb:SetSize( 150, 20 ) 43 | mysqldb:SetText( "MSync" ) 44 | 45 | local mysqluser_text = vgui.Create( "DLabel", pnl ) 46 | mysqluser_text:SetPos( 25, 145 ) 47 | mysqluser_text:SetColor( Color( 0, 0, 0 ) ) 48 | mysqluser_text:SetText( "Username" ) 49 | 50 | local mysqluser = vgui.Create( "DTextEntry", pnl ) 51 | mysqluser:SetPos( 25, 165 ) 52 | mysqluser:SetSize( 150, 20 ) 53 | mysqluser:SetText( "root" ) 54 | 55 | local mysqlpassword_text = vgui.Create( "DLabel", pnl ) 56 | mysqlpassword_text:SetPos( 25, 190 ) 57 | mysqlpassword_text:SetColor( Color( 0, 0, 0 ) ) 58 | mysqlpassword_text:SetText( "Password" ) 59 | 60 | local mysqlpassword = vgui.Create( "DTextEntry", pnl ) 61 | mysqlpassword:SetPos( 25, 210 ) 62 | mysqlpassword:SetSize( 150, 20 ) 63 | mysqlpassword:SetText( "*****" ) 64 | 65 | local servergroup_text = vgui.Create( "DLabel", pnl ) 66 | servergroup_text:SetPos( 25, 235 ) 67 | servergroup_text:SetColor( Color( 0, 0, 0 ) ) 68 | servergroup_text:SetText( "Server Group" ) 69 | 70 | local servergroup = vgui.Create( "DTextEntry", pnl ) 71 | servergroup:SetPos( 25, 255 ) 72 | servergroup:SetSize( 150, 20 ) 73 | servergroup:SetText( "allserver" ) 74 | 75 | local title_info = vgui.Create( "DLabel", pnl ) 76 | title_info:SetPos( 200, 25 ) 77 | title_info:SetColor( Color( 0, 0, 0 ) ) 78 | title_info:SetSize(400, 15) 79 | title_info:SetText( "--Information--" ) 80 | 81 | local info = vgui.Create( "RichText", pnl ) 82 | info:SetPos( 200, 45 ) 83 | info:SetSize(350, 150) 84 | info:InsertColorChange(10, 10, 10, 255) 85 | info:AppendText("MSync2 - Now with Steak\n\nSupport: ") 86 | info:InsertColorChange(72, 72, 155, 255) 87 | info:InsertClickableTextStart("OpenWebsite") 88 | info:AppendText("https://www.Aperture-Development.de") 89 | info:InsertClickableTextEnd() 90 | info:InsertColorChange(10, 10, 10, 255) 91 | info:AppendText("\nGitHub: ") 92 | info:InsertColorChange(72, 72, 155, 255) 93 | info:InsertClickableTextStart("OpenGitHub") 94 | info:AppendText("https://github.com/Aperture-Development/MSync-2") 95 | info:InsertClickableTextEnd() 96 | info:InsertColorChange(10, 10, 10, 255) 97 | info:AppendText("\nLicence:\n") 98 | info:InsertColorChange(80, 80, 80, 255) 99 | info:AppendText("To know what you are allowed to do and what not, read the LICENCE file in the root directory of the addon. If there is no file, the licence GPL 3.0 applies.\n\n") 100 | info:InsertColorChange(10, 10, 10, 255) 101 | info:AppendText("This addon was created by Aperture Development\n") 102 | info:InsertColorChange(10, 10, 10, 255) 103 | info:AppendText("Copyright 2018 - Aperture Development") 104 | 105 | info.Paint = function( parentPanel, w, h ) 106 | draw.RoundedBox( 5, 0, 0, w, h, Color(215, 215, 215) ) 107 | end 108 | 109 | info.ActionSignal = function( parentPanel, signalName, signalValue ) 110 | if signalName == "TextClicked" then 111 | if signalValue == "OpenWebsite" then 112 | gui.OpenURL( "https://www.Aperture-Development.de" ) 113 | elseif signalValue == "OpenGitHub" then 114 | gui.OpenURL( "https://github.com/Aperture-Development/MSync-2" ) 115 | end 116 | end 117 | end 118 | 119 | local dbstatus = vgui.Create( "DLabel", pnl ) 120 | dbstatus:SetPos( 200, 210 ) 121 | dbstatus:SetColor( Color( 0, 0, 0 ) ) 122 | dbstatus:SetSize(400, 15) 123 | dbstatus:SetText( "Database Status: " ) 124 | 125 | local dbstatus_info = vgui.Create( "DLabel", pnl ) 126 | dbstatus_info:SetPos( 300, 210 ) 127 | dbstatus_info:SetColor( Color( 80, 80, 80 ) ) 128 | dbstatus_info:SetSize(400, 15) 129 | dbstatus_info:SetText( "Please wait..." ) 130 | 131 | local function getConnectionStatus() 132 | dbstatus_info:SetColor( Color( 80, 80, 80 ) ) 133 | dbstatus_info:SetText( "Please wait..." ) 134 | timer.Simple(3, function() 135 | MSync.net.getDBStatus() 136 | timer.Create("msync.dbConnectionStatus", 3, 10, function() 137 | if MSync.DBStatus == nil then return end 138 | 139 | if MSync.DBStatus then 140 | dbstatus_info:SetColor( Color( 80, 255, 80 ) ) 141 | dbstatus_info:SetText( "Connected" ) 142 | else 143 | dbstatus_info:SetColor( Color( 255, 80, 80 ) ) 144 | dbstatus_info:SetText( "Not Connected" ) 145 | end 146 | timer.Remove("msync.dbConnectionStatus") 147 | end) 148 | end) 149 | end 150 | 151 | local save_button = vgui.Create( "DButton", pnl ) 152 | save_button:SetText( "Save Settings" ) 153 | save_button:SetPos( 25, 290 ) 154 | save_button:SetSize( 130, 30 ) 155 | save_button.DoClick = function() 156 | MSync.log(MSYNC_DBG_DEBUG, "Saving settings") 157 | MSync.settings.mysql.host = mysqlip:GetValue() 158 | MSync.settings.mysql.port = mysqlport:GetValue() 159 | MSync.settings.mysql.database = mysqldb:GetValue() 160 | MSync.settings.mysql.username = mysqluser:GetValue() 161 | MSync.settings.mysql.password = mysqlpassword:GetValue() 162 | MSync.settings.serverGroup = servergroup:GetValue() 163 | MSync.net.sendSettings(MSync.settings) 164 | end 165 | 166 | local saveconnect_button = vgui.Create( "DButton", pnl ) 167 | saveconnect_button:SetText( "Save and Connect" ) 168 | saveconnect_button:SetPos( 155, 290 ) 169 | saveconnect_button:SetSize( 130, 30 ) 170 | saveconnect_button.DoClick = function() 171 | MSync.log(MSYNC_DBG_DEBUG, "Saving settings and connecting to the database") 172 | MSync.settings.mysql.host = mysqlip:GetValue() 173 | MSync.settings.mysql.port = mysqlport:GetValue() 174 | MSync.settings.mysql.database = mysqldb:GetValue() 175 | MSync.settings.mysql.username = mysqluser:GetValue() 176 | MSync.settings.mysql.password = mysqlpassword:GetValue() 177 | MSync.settings.serverGroup = servergroup:GetValue() 178 | MSync.net.sendSettings(MSync.settings) 179 | MSync.net.connectDB() 180 | getConnectionStatus() 181 | end 182 | 183 | local connect_button = vgui.Create( "DButton", pnl ) 184 | connect_button:SetText( "Connect" ) 185 | connect_button:SetPos( 285, 290 ) 186 | connect_button:SetSize( 130, 30 ) 187 | connect_button.DoClick = function() 188 | MSync.log(MSYNC_DBG_DEBUG, "Connecting to the database") 189 | MSync.net.connectDB() 190 | getConnectionStatus() 191 | end 192 | 193 | local reset_button = vgui.Create( "DButton", pnl ) 194 | reset_button:SetText( "Reset Settings" ) 195 | reset_button:SetPos( 415, 290 ) 196 | reset_button:SetSize( 130, 30 ) 197 | reset_button.DoClick = function() 198 | MSync.log(MSYNC_DBG_DEBUG, "Reset confirm request"); 199 | 200 | local resetConfirm_panel = vgui.Create( "DFrame" ) 201 | resetConfirm_panel:SetSize( 350, 100 ) 202 | resetConfirm_panel:SetTitle( "MSync Reset - Confirm" ) 203 | resetConfirm_panel:Center() 204 | resetConfirm_panel:MakePopup() 205 | 206 | local save_text = vgui.Create( "DLabel", resetConfirm_panel ) 207 | save_text:SetPos( 15, 20 ) 208 | save_text:SetColor( Color( 255, 255, 255 ) ) 209 | save_text:SetText( "This action will reset all MySQL settings back to default, causing MSync to be unable to connect to the database when restarting the server. Are you sure you want to do that?" ) 210 | save_text:SetSize(320, 50) 211 | save_text:SetWrap( true ) 212 | 213 | local accept_button = vgui.Create( "DButton", resetConfirm_panel ) 214 | accept_button:SetText( "Yes" ) 215 | accept_button:SetPos( 15, 70 ) 216 | accept_button:SetSize( 160, 20 ) 217 | accept_button.DoClick = function() 218 | MSync.log(MSYNC_DBG_DEBUG, "Reset of MySQL configuration confirmed") 219 | mysqlip:SetText("127.0.0.1") 220 | mysqlport:SetText("3306") 221 | mysqldb:SetText("msync") 222 | mysqluser:SetText("root") 223 | mysqlpassword:SetText("****") 224 | servergroup:SetText("allserver") 225 | MSync.settings.mysql.host = mysqlip:GetValue() 226 | MSync.settings.mysql.port = mysqlport:GetValue() 227 | MSync.settings.mysql.database = mysqldb:GetValue() 228 | MSync.settings.mysql.username = mysqluser:GetValue() 229 | MSync.settings.mysql.password = "" 230 | MSync.settings.serverGroup = servergroup:GetValue() 231 | MSync.net.sendSettings(MSync.settings) 232 | 233 | resetConfirm_panel:Close() 234 | end 235 | 236 | local deny_button = vgui.Create( "DButton", resetConfirm_panel ) 237 | deny_button:SetText( "No" ) 238 | deny_button:SetPos( 175, 70 ) 239 | deny_button:SetSize( 160, 20 ) 240 | deny_button.DoClick = function() 241 | MSync.log(MSYNC_DBG_INFO, "Reset of MySQL configuration cancelled"); 242 | resetConfirm_panel:Close() 243 | end 244 | end 245 | 246 | if MSync.settings and MSync.settings.mysql then 247 | mysqlip:SetText(MSync.settings.mysql.host) 248 | mysqlport:SetText(MSync.settings.mysql.port) 249 | mysqldb:SetText(MSync.settings.mysql.database) 250 | mysqluser:SetText(MSync.settings.mysql.username) 251 | servergroup:SetText(MSync.settings.serverGroup) 252 | else 253 | timer.Create("msync.t.checkForSettings", 0.5, 0, function() 254 | if not MSync.settings or not MSync.settings.mysql then return end; 255 | 256 | MSync.log(MSYNC_DBG_DEBUG, "Got server settings, updating MySQL settings panel") 257 | 258 | mysqlip:SetText(MSync.settings.mysql.host) 259 | mysqlport:SetText(MSync.settings.mysql.port) 260 | mysqldb:SetText(MSync.settings.mysql.database) 261 | mysqluser:SetText(MSync.settings.mysql.username) 262 | servergroup:SetText(MSync.settings.serverGroup) 263 | timer.Remove("msync.t.checkForSettings") 264 | end) 265 | end 266 | 267 | getConnectionStatus() 268 | 269 | return pnl 270 | end 271 | 272 | --[[ 273 | Description: Module list panel 274 | Arguments: parent sheet 275 | Returns: panel 276 | ]] 277 | function MSync.AdminPanel.InitModules( sheet ) 278 | 279 | MSync.log(MSYNC_DBG_DEBUG, "Initializing modulestate panel") 280 | 281 | local pnl = vgui.Create( "DPanel", sheet ) 282 | 283 | local ModuleList = vgui.Create( "DListView", pnl ) 284 | ModuleList:Dock( FILL ) 285 | ModuleList:SetMultiSelect( false ) 286 | ModuleList:AddColumn( "Name" ) 287 | ModuleList:AddColumn( "Identifier" ) 288 | ModuleList:AddColumn( "Enabled" ) 289 | 290 | timer.Create("msync.t.checkForServerModules", 1, 0, function() 291 | if not MSync.serverModules then return end; 292 | 293 | for k,v in pairs(MSync.serverModules) do 294 | ModuleList:AddLine(v["Name"], v["ModuleIdentifier"], v["state"]) 295 | end 296 | timer.Remove("msync.t.checkForServerModules") 297 | end) 298 | ModuleList.OnRowRightClick = function(panel, lineID, line) 299 | local ident = line:GetValue(2) 300 | local cursor_x, cursor_y = ModuleList:CursorPos() 301 | local DMenu = vgui.Create("DMenu", ModuleList) 302 | DMenu:SetPos(cursor_x, cursor_y) 303 | DMenu:AddOption(MSync.serverModules[ident].Description):SetDisabled(true) 304 | DMenu:AddSpacer() 305 | DMenu:AddOption("Enable") 306 | DMenu:AddOption("Disable") 307 | DMenu.OptionSelected = function(menu,optPnl,optStr) 308 | MSync.net.toggleModule(ident, optStr) 309 | if optStr == "Enable" then 310 | line:SetColumnText( 3, "true" ) 311 | elseif optStr == "Disable" then 312 | line:SetColumnText( 3, "false" ) 313 | end 314 | end 315 | end 316 | return pnl 317 | end 318 | 319 | --[[ 320 | Description: Module settings panel 321 | Arguments: parent sheet 322 | Returns: panel 323 | ]] 324 | function MSync.AdminPanel.InitModuleSettings( sheet ) 325 | 326 | MSync.log(MSYNC_DBG_DEBUG, "Initializing module settings panel") 327 | 328 | local pnl = vgui.Create( "DColumnSheet", sheet ) 329 | 330 | local files, _ = file.Find("msync/client_gui/modules/*.lua", "LUA") 331 | 332 | for k, v in pairs(files) do 333 | local info = include("msync/client_gui/modules/" .. v) 334 | 335 | if MSync.moduleState[info["ModuleIdentifier"]] then 336 | MSync.modules[info.ModuleIdentifier]["init"]() 337 | MSync.modules[info.ModuleIdentifier]["net"]() 338 | pnl:AddSheet( info.Name, MSync.modules[info.ModuleIdentifier].adminPanel(pnl)) 339 | MSync.log(MSYNC_DBG_DEBUG, "Added settings tab for module: ") 340 | end 341 | end 342 | 343 | return pnl 344 | end 345 | 346 | --[[ 347 | Description: MSync 2 panel 348 | Returns: nothing 349 | ]] 350 | function MSync.AdminPanel.InitPanel() 351 | 352 | MSync.log(MSYNC_DBG_DEBUG, "Opening Admin GUI") 353 | 354 | --if not LocalPlayer():query("msync.admingui") then return false end; 355 | 356 | MSync.net.getSettings() 357 | MSync.net.getModules() 358 | 359 | local panel = vgui.Create( "DFrame" ) 360 | panel:SetSize( 600, 400 ) 361 | panel:SetTitle( "MSync Admin Menu" ) 362 | panel:Center() 363 | panel:MakePopup() 364 | 365 | local sheet = vgui.Create( "DPropertySheet", panel ) 366 | sheet:Dock( FILL ) 367 | 368 | sheet:AddSheet( "MySQL", MSync.AdminPanel.InitMySQL( sheet ), "icon16/database.png" ) 369 | sheet:AddSheet( "Modules", MSync.AdminPanel.InitModules( sheet ), "icon16/application.png" ) 370 | sheet:AddSheet( "Module Settings", MSync.AdminPanel.InitModuleSettings( sheet ), "icon16/folder.png" ) 371 | 372 | end -------------------------------------------------------------------------------- /lua/msync/client_gui/cl_init.lua: -------------------------------------------------------------------------------- 1 | MSync = MSync or {} 2 | MSync.net = MSync.net or {} -------------------------------------------------------------------------------- /lua/msync/client_gui/cl_modules.lua: -------------------------------------------------------------------------------- 1 | MSync = MSync or {} 2 | MSync.mysql = MSync.mysql or {} 3 | MSync.settings = MSync.settings or {} 4 | MSync.modules = MSync.modules or {} 5 | 6 | --[[ 7 | Description: loads the client side modules 8 | Returns: nothing 9 | ]] 10 | function MSync.loadModules() 11 | local files, _ = file.Find("msync/client_gui/modules/*.lua", "LUA") 12 | for k, v in pairs(files) do 13 | include("msync/client_gui/modules/" .. v) 14 | end 15 | MSync.initModules() 16 | end 17 | 18 | --[[ 19 | Description: initializes the client modules 20 | Returns: nothing 21 | ]] 22 | function MSync.initModules() 23 | 24 | for k,v in pairs(MSync.modules) do 25 | if MSync.moduleState[v["info"]["ModuleIdentifier"]] then 26 | v["init"]() 27 | v["net"]() 28 | v["ulx"]() 29 | v["hooks"]() 30 | MSync.log(MSYNC_DBG_INFO, "[" .. v["info"]["Name"] .. "] Module loaded") 31 | end 32 | end 33 | 34 | end 35 | 36 | --[[ 37 | Description: loads a single client side module 38 | Arguments: Module path 39 | Returns: nothing 40 | ]] 41 | function MSync.loadModule(path) 42 | local info = include(path) 43 | 44 | MSync.modules[info.ModuleIdentifier].init() 45 | MSync.modules[info.ModuleIdentifier].net() 46 | MSync.modules[info.ModuleIdentifier].ulx() 47 | MSync.modules[info.ModuleIdentifier].hooks() 48 | 49 | MSync.log(MSYNC_DBG_INFO, "[" .. MSync.modules[info.ModuleIdentifier]["info"]["Name"] .. "] Module loaded") 50 | 51 | end 52 | 53 | --[[ 54 | Description: Enables a single already loaded clientside module 55 | Arguments: Module path 56 | Returns: nothing 57 | ]] 58 | function MSync.enableModule( module ) 59 | if MSync.modules[module] then 60 | MSync.modules[module].init() 61 | MSync.modules[module].net() 62 | MSync.modules[module].ulx() 63 | MSync.modules[module].hooks() 64 | MSync.log(MSYNC_DBG_INFO, "[" .. MSync.modules[module]["info"]["Name"] .. "] Module loaded") 65 | else 66 | MSync.log(MSYNC_DBG_WARNING, "Cannot enable non-existant module \"" .. module .. "\"") 67 | end 68 | end 69 | 70 | --[[ 71 | Description: Disabled a single already loaded clientside module 72 | Arguments: Module path 73 | Returns: nothing 74 | ]] 75 | function MSync.disableModule( module ) 76 | if MSync.modules[module] then 77 | if MSync.modules[module].disable then 78 | MSync.modules[module].disable() 79 | MSync.log(MSYNC_DBG_INFO, "[" .. MSync.modules[module]["info"]["Name"] .. "] Module disabled") 80 | else 81 | MSync.log(MSYNC_DBG_WARNING, "Cannot disable outdated module \"" .. module .. "\"") 82 | end 83 | else 84 | MSync.log(MSYNC_DBG_WARNING, "Cannot disable non-existant module \"" .. module .. "\"") 85 | end 86 | end 87 | -------------------------------------------------------------------------------- /lua/msync/client_gui/cl_net.lua: -------------------------------------------------------------------------------- 1 | MSync = MSync or {} 2 | MSync.net = MSync.net or {} 3 | 4 | --[[ 5 | Description: Function to get the server settings 6 | Returns: nothing 7 | ]] 8 | function MSync.net.getSettings() 9 | MSync.log(MSYNC_DBG_DEBUG, "Exec: net.getSettings") 10 | net.Start("msync.getSettings") 11 | net.SendToServer() 12 | end 13 | 14 | --[[ 15 | Description: function to get the modules 16 | Returns: nothing 17 | ]] 18 | function MSync.net.getModules() 19 | MSync.log(MSYNC_DBG_DEBUG, "Exec: net.getModules") 20 | net.Start("msync.getModules") 21 | net.SendToServer() 22 | end 23 | 24 | --[[ 25 | Description: function to toggle a module 26 | Returns: nothing 27 | ]] 28 | function MSync.net.toggleModule(ident, state) 29 | MSync.log(MSYNC_DBG_DEBUG, "Exec: net.toggleModule Param.: " .. ident .. " " .. state) 30 | net.Start("msync.toggleModule") 31 | net.WriteString(ident) 32 | net.WriteString(state) 33 | net.SendToServer() 34 | end 35 | 36 | --[[ 37 | Description: function to send settngs to the server 38 | Returns: nothing 39 | ]] 40 | function MSync.net.sendSettings(table) 41 | MSync.log(MSYNC_DBG_DEBUG, "Exec: net.sendSettings Param.: " .. tostring(table)) 42 | net.Start("msync.sendSettings") 43 | net.WriteTable(table) 44 | net.SendToServer() 45 | end 46 | 47 | --[[ 48 | Description: function to connect to the database server 49 | Returns: nothing 50 | ]] 51 | function MSync.net.connectDB() 52 | MSync.log(MSYNC_DBG_DEBUG, "Exec: net.connectDB") 53 | net.Start("msync.connectDB") 54 | net.SendToServer() 55 | end 56 | 57 | --[[ 58 | Description: function to ask for database connection 59 | Returns: nothing 60 | ]] 61 | function MSync.net.getDBStatus() 62 | MSync.log(MSYNC_DBG_DEBUG, "Exec: net.connectionStatus") 63 | net.Start("msync.connectionStatus") 64 | net.SendToServer() 65 | end 66 | 67 | --[[ 68 | Description: Net Receiver - Gets called when the server sends a table to the client 69 | Returns: nothing 70 | ]] 71 | net.Receive( "msync.sendTable", function( len, pl ) 72 | MSync.log(MSYNC_DBG_DEBUG, "Net: msync.sendTable") 73 | local type = net.ReadString() 74 | local table = net.ReadTable() 75 | 76 | if type == "settings" then MSync.settings = table; MSync.log(MSYNC_DBG_INFO, "Got settings from server") 77 | elseif type == "modules" then MSync.serverModules = table; MSync.log(MSYNC_DBG_INFO, "Got modules from server") 78 | elseif type == "modulestate" then 79 | MSync.moduleState = table 80 | MSync.loadModules() 81 | MSync.log(MSYNC_DBG_INFO, "Got module states from server") 82 | end 83 | end ) 84 | 85 | --[[ 86 | Description: Net Receiver - Gets called when the server sends a message to the client 87 | Returns: nothing 88 | ]] 89 | net.Receive( "msync.sendMessage", function( len, pl ) 90 | MSync.log(MSYNC_DBG_DEBUG, "Net: msync.sendMessage") 91 | local state = net.ReadString() 92 | 93 | if state == "error" then 94 | chat.AddText(Color(255,0,0),"[MSync_ERROR] " .. net.ReadString()) 95 | elseif state == "advert" then 96 | chat.AddText(Color(255,255,255), "[MSync] ", Color(0,0,255), net.ReadString()) 97 | else 98 | chat.AddText(Color(255,255,255), "[MSync] " .. net.ReadString()) 99 | end 100 | end ) 101 | 102 | --[[ 103 | Description: Net Receiver - Gets called when the client requested to open the admin GUI 104 | Returns: nothing 105 | ]] 106 | net.Receive( "msync.openAdminGUI", function( len, pl ) 107 | MSync.log(MSYNC_DBG_DEBUG, "Net: msync.openAdminGUI") 108 | MSync.AdminPanel.InitPanel() 109 | end ) 110 | 111 | --[[ 112 | Description: Net Receiver - Gets called when server sent the db status 113 | Returns: nothing 114 | ]] 115 | net.Receive( "msync.dbStatus", function( len, pl ) 116 | MSync.DBStatus = net.ReadBool() 117 | MSync.log(MSYNC_DBG_DEBUG, "Net: msync.dbStatus Return: " .. tostring(MSync.DBStatus)) 118 | end ) 119 | 120 | --[[ 121 | Description: Net Receiver - Gets called when a module has been enabled 122 | Returns: nothing 123 | ]] 124 | net.Receive( "msync.enableModule", function( len, pl ) 125 | local module = net.ReadString() 126 | MSync.log(MSYNC_DBG_DEBUG, "Net: msync.enableModule Return: " .. module) 127 | MSync.enableModule( module ) 128 | MSync.moduleState[module] = true 129 | end ) 130 | 131 | --[[ 132 | Description: Net Receiver - Gets called when a module has been disabled 133 | Returns: nothing 134 | ]] 135 | net.Receive( "msync.disableModule", function( len, pl ) 136 | local module = net.ReadString() 137 | MSync.log(MSYNC_DBG_DEBUG, "Net: msync.disableModule Return: " .. module) 138 | MSync.disableModule( module ) 139 | MSync.moduleState[module] = nil 140 | end ) -------------------------------------------------------------------------------- /lua/msync/client_gui/modules/cl_mbsync.lua: -------------------------------------------------------------------------------- 1 | MSync = MSync or {} 2 | MSync.modules = MSync.modules or {} 3 | --[[ 4 | * @file cl_mbsync.lua 5 | * @package MySQL Ban Sync 6 | * @author Aperture Development 7 | * @license root_dir/LICENCE 8 | * @version 1.4.0 9 | ]] 10 | 11 | --[[ 12 | Define name, description and module identifier 13 | ]] 14 | local info = { 15 | Name = "MySQL Ban Sync", 16 | ModuleIdentifier = "MBSync", 17 | Description = "Synchronise bans across your servers", 18 | Version = "1.4.0" 19 | } 20 | 21 | --[[ 22 | Prepare Module 23 | ]] 24 | 25 | MSync.modules[info.ModuleIdentifier] = MSync.modules[info.ModuleIdentifier] or {} 26 | MSync.modules[info.ModuleIdentifier].info = info 27 | 28 | --[[ 29 | Define additional functions that are later used 30 | ]] 31 | MSync.modules[info.ModuleIdentifier].init = function() 32 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Initializing"); 33 | 34 | MSync.modules[info.ModuleIdentifier].banTable = {} 35 | 36 | MSync.modules[info.ModuleIdentifier].getTablePage = function(tbl, maxResults, page) 37 | MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.getTablePage Param.: $tbl $maxResults $page",{["tbl"] = tbl,["maxResults"] = maxResults,["page"] = page})); 38 | local tempTbl = {} 39 | local i = 0 40 | local startPos = 0 + (maxResults * page) 41 | local endPos = 19 + (maxResults * page) 42 | 43 | for k,v in pairs(tbl) do 44 | if i >= startPos and i <= endPos then 45 | tempTbl[k] = v 46 | end 47 | i = i + 1 48 | end 49 | 50 | return tempTbl 51 | end 52 | 53 | MSync.modules[info.ModuleIdentifier].displayTable = function(panel, tbl, maxResults, page) 54 | MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.displayTable Param.: $panel $tbl $maxResults $page",{["panel"] = panel,["tbl"] = tbl,["maxResults"] = maxResults,["page"] = page})); 55 | panel:Clear() 56 | local table = MSync.modules[info.ModuleIdentifier].getTablePage(tbl, maxResults, page) 57 | local length = 0 58 | for k,v in pairs(table) do 59 | if v["length"] == 0 then 60 | length = "Permanent" 61 | else 62 | length = ULib.secondsToStringTime(v["length"]) 63 | end 64 | panel:AddLine( v["banId"], v["nickname"], v["adminNickname"], os.date( "%H:%M:%S - %d/%m/%Y" , v["timestamp"]), length, v["reason"] ) 65 | end 66 | end 67 | 68 | MSync.modules[info.ModuleIdentifier].getTablePages = function(tbl, resultsPerPage) 69 | MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.getTablePages Param.: $tbl $resultsPerPage",{["tbl"] = tbl, ["resultsPerPage"] = resultsPerPage})); 70 | return math.Round(#tbl / resultsPerPage) 71 | end 72 | 73 | MSync.modules[info.ModuleIdentifier].explodeTable = function(tbl, part) 74 | MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.explodeTable Param.: $tbl $part",{["tbl"] = tbl, ["part"] = part})); 75 | for k,v in pairs(part) do 76 | tbl[k] = v 77 | end 78 | end 79 | 80 | MSync.modules[info.ModuleIdentifier].sortTable = function(tbl, key, asc) 81 | MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.sortTable Param.: $tbl $key $asc",{["tbl"] = tbl, ["key"] = key, ["asc"] = asc})); 82 | local sorting = true 83 | local tempTable = table.DeSanitise( tbl ) 84 | local keys = table.GetKeys( tempTable ) 85 | 86 | while sorting do 87 | sorting = false 88 | for k,v in pairs(keys) do 89 | local a, b 90 | if not keys[k + 1] then break end 91 | 92 | if type( tempTable[v][key] ) == "string" then 93 | a = tempTable[v][key]:lower() 94 | b = tempTable[keys[k + 1]][key]:lower() 95 | else 96 | a = tempTable[v][key] 97 | b = tempTable[keys[k + 1]][key] 98 | end 99 | 100 | if asc then 101 | if a > b then 102 | sorting = true 103 | local temp = tempTable[v] 104 | tempTable[v] = tempTable[keys[k + 1]] 105 | tempTable[keys[k + 1]] = temp 106 | break 107 | end 108 | else 109 | if a < b then 110 | sorting = true 111 | local temp = tempTable[keys[k + 1]] 112 | tempTable[keys[k + 1]] = tempTable[v] 113 | tempTable[v] = temp 114 | break 115 | end 116 | end 117 | end 118 | end 119 | return tempTable 120 | end 121 | 122 | MSync.modules[info.ModuleIdentifier].searchTable = function(tbl, term) 123 | MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.searchTable Param.: $tbl $term", {["tbl"] = tbl,["term"] = term})); 124 | local searchTerm = "" 125 | 126 | if type(term) == "string" then 127 | searchTerm = term:lower() 128 | else 129 | searchTerm = tostring(term):lower() 130 | end 131 | 132 | local tempTbl = {} 133 | local matches = false 134 | 135 | for k, v in pairs(tbl) do 136 | matches = false 137 | for k2, v2 in pairs(v) do 138 | if type(v2) == "string" then 139 | if string.match(v2:lower(), ".*" .. searchTerm .. ".*") then 140 | matches = true 141 | end 142 | else 143 | if string.match(tostring( v2 ):lower(), ".*" .. searchTerm .. ".*") then 144 | matches = true 145 | end 146 | end 147 | end 148 | 149 | if matches then 150 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Search: Found match " .. k); 151 | tempTbl[k] = v 152 | end 153 | end 154 | 155 | return tempTbl 156 | end 157 | 158 | MSync.modules[info.ModuleIdentifier].banPanel = function( tbl ) 159 | MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.banPanel Param.: $tbl",{["tbl"] = tbl})); 160 | 161 | local panel = vgui.Create( "DFrame" ) 162 | panel:SetSize( 350, 500 ) 163 | panel:SetTitle( "MBSync - Ban User " ) 164 | panel:Center() 165 | panel:MakePopup() 166 | 167 | local steamid_text = vgui.Create( "DLabel", panel ) 168 | steamid_text:SetPos( 15, 35 ) 169 | steamid_text:SetColor( Color( 255, 255, 255 ) ) 170 | steamid_text:SetText( "SteamID/SteamID64:" ) 171 | steamid_text:SetSize(380, 15) 172 | 173 | local steamid_textentry = vgui.Create( "DTextEntry", panel ) 174 | steamid_textentry:SetPos( 125, 35 ) 175 | steamid_textentry:SetSize( 210, 20 ) 176 | steamid_textentry:SetPlaceholderText( "SteamID/SteamID64" ) 177 | 178 | local length_text = vgui.Create( "DLabel", panel ) 179 | length_text:SetPos( 15, 60 ) 180 | length_text:SetColor( Color( 255, 255, 255 ) ) 181 | length_text:SetText( "Length" ) 182 | length_text:SetSize(380, 15) 183 | 184 | local length_textentry = vgui.Create( "DTextEntry", panel ) 185 | length_textentry:SetPos( 125, 60 ) 186 | length_textentry:SetSize( 210, 20 ) 187 | length_textentry:SetPlaceholderText( "Ban Length in Minutes, 0 = Permanent" ) 188 | 189 | local allservers_text = vgui.Create( "DLabel", panel ) 190 | allservers_text:SetPos( 15, 85 ) 191 | allservers_text:SetColor( Color( 255, 255, 255 ) ) 192 | allservers_text:SetText( "Banned everywhere:" ) 193 | allservers_text:SetSize(380, 15) 194 | 195 | local allservers_dropdown = vgui.Create( "DComboBox", panel ) 196 | allservers_dropdown:SetPos( 125, 85 ) 197 | allservers_dropdown:SetSize( 210, 20 ) 198 | allservers_dropdown:SetValue( "True" ) 199 | allservers_dropdown:AddChoice( "True" ) 200 | allservers_dropdown:AddChoice( "False" ) 201 | allservers_dropdown:SetSortItems( false ) 202 | 203 | local reason_text = vgui.Create( "DLabel", panel ) 204 | reason_text:SetPos( 15, 110 ) 205 | reason_text:SetColor( Color( 255, 255, 255 ) ) 206 | reason_text:SetText( "Reason" ) 207 | reason_text:SetSize(380, 15) 208 | 209 | local reasonMaxLen_text = vgui.Create( "DLabel", panel ) 210 | reasonMaxLen_text:SetPos( 280, 185 ) 211 | reasonMaxLen_text:SetColor( Color( 255, 255, 255 ) ) 212 | reasonMaxLen_text:SetText( "0/100" ) 213 | reasonMaxLen_text:SetSize(50, 15) 214 | reasonMaxLen_text:SetContentAlignment( 9 ) 215 | 216 | local reason_textentry = vgui.Create( "DTextEntry", panel ) 217 | reason_textentry:SetPos( 15, 125 ) 218 | reason_textentry:SetSize( 320, 60 ) 219 | reason_textentry:SetPlaceholderText( "Leave empty for 'No Reason given'" ) 220 | reason_textentry:SetMultiline(true) 221 | reason_textentry:SetUpdateOnType(true) 222 | reason_textentry.OnValueChange = function( pnl, value ) 223 | reasonMaxLen_text:SetText(string.len( value ) .. "/100") 224 | 225 | if string.len( value ) > 100 then 226 | reasonMaxLen_text:SetColor( Color( 255, 120, 120 ) ) 227 | else 228 | reasonMaxLen_text:SetColor( Color( 255, 255, 255 ) ) 229 | end 230 | end 231 | 232 | local disconnectedPly_text = vgui.Create( "DLabel", panel ) 233 | disconnectedPly_text:SetPos( 15, 205 ) 234 | disconnectedPly_text:SetColor( Color( 255, 255, 255 ) ) 235 | disconnectedPly_text:SetText( "Recently Disconnected Players" ) 236 | disconnectedPly_text:SetSize(380, 15) 237 | 238 | local ban_table = vgui.Create( "DListView", panel ) 239 | ban_table:SetPos( 15, 220 ) 240 | ban_table:SetSize( 320, 200 ) 241 | ban_table:SetMultiSelect( false ) 242 | ban_table:AddColumn( "Nickname" ) 243 | ban_table:AddColumn( "SteamID" ) 244 | ban_table:AddColumn( "SteamID64" ) 245 | ban_table.OnRowSelected = function( lst, index, pnl ) 246 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Ban Panel: Selected row " .. index); 247 | 248 | steamid_textentry:SetText(pnl:GetColumnText( 2 )) 249 | end 250 | 251 | if tbl then 252 | for k,v in pairs(tbl) do 253 | ban_table:AddLine( v.name, v.steamid, v.steamid64 ) 254 | end 255 | end 256 | 257 | local ban_button = vgui.Create( "DButton", panel ) 258 | ban_button:SetText( "Ban User" ) 259 | ban_button:SetPos( 15, 425 ) 260 | ban_button:SetSize( 320, 30 ) 261 | ban_button.DoClick = function() 262 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Ban confirm request"); 263 | 264 | local banConfirm_panel = vgui.Create( "DFrame" ) 265 | banConfirm_panel:SetSize( 350, 100 ) 266 | banConfirm_panel:SetTitle( "MBSync Ban - Confirm" ) 267 | banConfirm_panel:Center() 268 | banConfirm_panel:MakePopup() 269 | 270 | local save_text = vgui.Create( "DLabel", banConfirm_panel ) 271 | save_text:SetPos( 15, 20 ) 272 | save_text:SetColor( Color( 255, 255, 255 ) ) 273 | save_text:SetText( "This action will ban the user with the given data, are you sure you want to do that?" ) 274 | save_text:SetSize(320, 50) 275 | save_text:SetWrap( true ) 276 | 277 | local accept_button = vgui.Create( "DButton", banConfirm_panel ) 278 | accept_button:SetText( "Accept" ) 279 | accept_button:SetPos( 15, 70 ) 280 | accept_button:SetSize( 160, 20 ) 281 | accept_button.DoClick = function() 282 | MSync.log(MSYNC_DBG_INFO, "[MBSync] Ban confirmed, banning player and closing panel"); 283 | 284 | RunConsoleCommand("msync.MBSync.banSteamID", steamid_textentry:GetValue(), length_textentry:GetValue(), allservers_dropdown:GetValue(), reason_textentry:GetValue()) 285 | panel:Close() 286 | banConfirm_panel:Close() 287 | end 288 | 289 | local deny_button = vgui.Create( "DButton", banConfirm_panel ) 290 | deny_button:SetText( "Deny" ) 291 | deny_button:SetPos( 175, 70 ) 292 | deny_button:SetSize( 160, 20 ) 293 | deny_button.DoClick = function() 294 | MSync.log(MSYNC_DBG_INFO, "[MBSync] Ban denied, closing confirmation panel"); 295 | 296 | banConfirm_panel:Close() 297 | end 298 | end 299 | 300 | local cancel_button = vgui.Create( "DButton", panel ) 301 | cancel_button:SetText( "Cancel" ) 302 | cancel_button:SetPos( 15, 460 ) 303 | cancel_button:SetSize( 320, 30 ) 304 | cancel_button.DoClick = function() 305 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Ban cancellation request"); 306 | local cancel_panel = vgui.Create( "DFrame" ) 307 | cancel_panel:SetSize( 350, 100 ) 308 | cancel_panel:SetTitle( "MBSync Ban - Confirm" ) 309 | cancel_panel:Center() 310 | cancel_panel:MakePopup() 311 | 312 | local save_text = vgui.Create( "DLabel", cancel_panel ) 313 | save_text:SetPos( 15, 20 ) 314 | save_text:SetColor( Color( 255, 255, 255 ) ) 315 | save_text:SetText( "This action will cancel the ban, are you sure you want to do that?" ) 316 | save_text:SetSize(320, 50) 317 | save_text:SetWrap( true ) 318 | 319 | local accept_button = vgui.Create( "DButton", cancel_panel ) 320 | accept_button:SetText( "Accept" ) 321 | accept_button:SetPos( 15, 70 ) 322 | accept_button:SetSize( 160, 20 ) 323 | accept_button.DoClick = function() 324 | MSync.log(MSYNC_DBG_INFO, "[MBSync] Ban canceled, closing panels"); 325 | -- do nothing and close panel 326 | panel:Close() 327 | cancel_panel:Close() 328 | end 329 | 330 | local deny_button = vgui.Create( "DButton", cancel_panel ) 331 | deny_button:SetText( "Deny" ) 332 | deny_button:SetPos( 175, 70 ) 333 | deny_button:SetSize( 160, 20 ) 334 | deny_button.DoClick = function() 335 | MSync.log(MSYNC_DBG_INFO, "[MBSync] Ban cancel aborted, returning to ban panel"); 336 | cancel_panel:Close() 337 | end 338 | end 339 | 340 | end 341 | 342 | MSync.modules[info.ModuleIdentifier].advancedInfoPanel = function(tbl) 343 | MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.advancedInfoPanel Param.: $tbl",{["tbl"] = tbl})); 344 | 345 | local panel = vgui.Create( "DFrame" ) 346 | panel:SetSize( 350, 455 ) 347 | panel:SetTitle( "MBSync Advanced Ban Info" ) 348 | panel:Center() 349 | panel:MakePopup() 350 | 351 | --[[ 352 | { 353 | banNick = "Nickname", 354 | banSteamID = "SteamID" 355 | banSTeamID64 = "SteamID64" 356 | adminNick = "Nickname" 357 | adminSteamID = "SteamID" 358 | adminSteamID64 = "SteamID64" 359 | banDate = "Date" 360 | banLength = "length" 361 | unbanDate = "Date" 362 | banRemaining = "Time" 363 | banServerGroup = "Servergroup" 364 | banReason = "Reason" 365 | } 366 | ]] 367 | 368 | --[[ 369 | Info about the banned user 370 | ]] 371 | 372 | local nickname_text = vgui.Create( "DLabel", panel ) 373 | nickname_text:SetPos( 15, 35 ) 374 | nickname_text:SetColor( Color( 255, 255, 255 ) ) 375 | nickname_text:SetText( "Nickname:" ) 376 | nickname_text:SetSize(380, 15) 377 | 378 | local nickname_textentry = vgui.Create( "DTextEntry", panel ) 379 | nickname_textentry:SetPos( 125, 35 ) 380 | nickname_textentry:SetSize( 210, 20 ) 381 | nickname_textentry:SetDisabled(true) 382 | 383 | local steamid_text = vgui.Create( "DLabel", panel ) 384 | steamid_text:SetPos( 15, 60 ) 385 | steamid_text:SetColor( Color( 255, 255, 255 ) ) 386 | steamid_text:SetText( "SteamID:" ) 387 | steamid_text:SetSize(380, 15) 388 | 389 | local steamid_textentry = vgui.Create( "DTextEntry", panel ) 390 | steamid_textentry:SetPos( 125, 60 ) 391 | steamid_textentry:SetSize( 210, 20 ) 392 | steamid_textentry:SetDisabled(true) 393 | 394 | local steamid64_text = vgui.Create( "DLabel", panel ) 395 | steamid64_text:SetPos( 15, 85 ) 396 | steamid64_text:SetColor( Color( 255, 255, 255 ) ) 397 | steamid64_text:SetText( "SteamID64:" ) 398 | steamid64_text:SetSize(380, 15) 399 | 400 | local steamid64_textentry = vgui.Create( "DTextEntry", panel ) 401 | steamid64_textentry:SetPos( 125, 85 ) 402 | steamid64_textentry:SetSize( 210, 20 ) 403 | steamid64_textentry:SetDisabled(true) 404 | 405 | --[[ 406 | Info about the banning Admin 407 | ]] 408 | 409 | local adminnickname_text = vgui.Create( "DLabel", panel ) 410 | adminnickname_text:SetPos( 15, 120 ) 411 | adminnickname_text:SetColor( Color( 255, 255, 255 ) ) 412 | adminnickname_text:SetText( "Admin Nickname:" ) 413 | adminnickname_text:SetSize(380, 15) 414 | 415 | local adminnickname_textentry = vgui.Create( "DTextEntry", panel ) 416 | adminnickname_textentry:SetPos( 125, 120 ) 417 | adminnickname_textentry:SetSize( 210, 20 ) 418 | --adminnickname_textentry:SetText( "[ApDev] Rainbow Dash" ) 419 | adminnickname_textentry:SetDisabled(true) 420 | 421 | --[[ 422 | Info about the ban 423 | ]] 424 | 425 | local bandate_text = vgui.Create( "DLabel", panel ) 426 | bandate_text:SetPos( 15, 155 ) 427 | bandate_text:SetColor( Color( 255, 255, 255 ) ) 428 | bandate_text:SetText( "Ban Date:" ) 429 | bandate_text:SetSize(380, 15) 430 | 431 | local bandate_textentry = vgui.Create( "DTextEntry", panel ) 432 | bandate_textentry:SetPos( 125, 155 ) 433 | bandate_textentry:SetSize( 210, 20 ) 434 | --bandate_textentry:SetText( "24.09.2019 23:11" ) 435 | bandate_textentry:SetDisabled(true) 436 | 437 | local banlength_text = vgui.Create( "DLabel", panel ) 438 | banlength_text:SetPos( 15, 180 ) 439 | banlength_text:SetColor( Color( 255, 255, 255 ) ) 440 | banlength_text:SetText( "Ban Length:" ) 441 | banlength_text:SetSize(380, 15) 442 | 443 | local banlength_textentry = vgui.Create( "DTextEntry", panel ) 444 | banlength_textentry:SetPos( 125, 180 ) 445 | banlength_textentry:SetSize( 210, 20 ) 446 | --banlength_textentry:SetText( "Permanent" ) 447 | banlength_textentry:SetDisabled(true) 448 | 449 | local unbandate_text = vgui.Create( "DLabel", panel ) 450 | unbandate_text:SetPos( 15, 205 ) 451 | unbandate_text:SetColor( Color( 255, 255, 255 ) ) 452 | unbandate_text:SetText( "Unban Date:" ) 453 | unbandate_text:SetSize(380, 15) 454 | 455 | local unbandate_textentry = vgui.Create( "DTextEntry", panel ) 456 | unbandate_textentry:SetPos( 125, 205 ) 457 | unbandate_textentry:SetSize( 210, 20 ) 458 | --unbandate_textentry:SetText( "24.09.2019 23:11" ) 459 | unbandate_textentry:SetDisabled(true) 460 | 461 | local remainingtime_text = vgui.Create( "DLabel", panel ) 462 | remainingtime_text:SetPos( 15, 230 ) 463 | remainingtime_text:SetColor( Color( 255, 255, 255 ) ) 464 | remainingtime_text:SetText( "Time Remaining:" ) 465 | remainingtime_text:SetSize(380, 15) 466 | 467 | local remainingtime_textentry = vgui.Create( "DTextEntry", panel ) 468 | remainingtime_textentry:SetPos( 125, 230 ) 469 | remainingtime_textentry:SetSize( 210, 20 ) 470 | --remainingtime_textentry:SetText( "1d,13h" ) 471 | remainingtime_textentry:SetDisabled(true) 472 | 473 | local bangroup_text = vgui.Create( "DLabel", panel ) 474 | bangroup_text:SetPos( 15, 255 ) 475 | bangroup_text:SetColor( Color( 255, 255, 255 ) ) 476 | bangroup_text:SetText( "Ban Server Group:" ) 477 | bangroup_text:SetSize(380, 15) 478 | 479 | local bangroup_textentry = vgui.Create( "DTextEntry", panel ) 480 | bangroup_textentry:SetPos( 125, 255 ) 481 | bangroup_textentry:SetSize( 210, 20 ) 482 | --bangroup_textentry:SetText( "allservers" ) 483 | bangroup_textentry:SetDisabled(true) 484 | 485 | local banreason_text = vgui.Create( "DLabel", panel ) 486 | banreason_text:SetPos( 15, 300 ) 487 | banreason_text:SetColor( Color( 255, 255, 255 ) ) 488 | banreason_text:SetText( "Ban Reason:" ) 489 | banreason_text:SetSize(380, 15) 490 | banreason_text:SetDark(1) 491 | 492 | local banreason_panel = vgui.Create( "DPanel", panel ) 493 | banreason_panel:SetPos( 15, 320 ) 494 | banreason_panel:SetSize( 320, 80 ) 495 | 496 | local banreasonreason_text = vgui.Create( "DLabel", banreason_panel ) 497 | banreasonreason_text:SetPos( 5, 5 ) 498 | banreasonreason_text:SetColor( Color( 0, 0, 0 ) ) 499 | banreasonreason_text:SetText( "" ) 500 | banreasonreason_text:SetSize(310, 100) 501 | banreasonreason_text:SetWrap( true ) 502 | banreasonreason_text:SetContentAlignment( 7 ) 503 | 504 | local close_button = vgui.Create( "DButton", panel ) 505 | close_button:SetText( "Close" ) 506 | close_button:SetPos( 15, 410 ) 507 | close_button:SetSize( 320, 30 ) 508 | close_button.DoClick = function() 509 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Close info panel"); 510 | panel:Close() 511 | end 512 | 513 | --[[ 514 | ############ 515 | FILL DATA 516 | ############ 517 | ]] 518 | 519 | if (tbl ~= nil) then 520 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Filling in ban data"); 521 | 522 | nickname_textentry:SetText( tbl["nickname"] ) 523 | steamid_textentry:SetText( tbl["steamid"] ) 524 | steamid64_textentry:SetText( tbl["steamid64"] ) 525 | adminnickname_textentry:SetText( tbl["adminNickname"] ) 526 | bandate_textentry:SetText( os.date( "%H:%M:%S - %d/%m/%Y" ,tbl["timestamp"]) ) 527 | if (tbl["length"] ~= 0) then 528 | banlength_textentry:SetText( ULib.secondsToStringTime(tbl["length"]) ) 529 | unbandate_textentry:SetText( os.date( "%H:%M:%S - %d/%m/%Y" ,tbl["timestamp"] + tbl["length"]) ) 530 | remainingtime_textentry:SetText( ULib.secondsToStringTime((tbl["timestamp"] + tbl["length"]) - os.time()) ) 531 | else 532 | banlength_textentry:SetText( "Permanent" ) 533 | unbandate_textentry:SetText( "Never" ) 534 | remainingtime_textentry:SetText( "Forever" ) 535 | end 536 | bangroup_textentry:SetText( tbl["servergroup"] ) 537 | banreasonreason_text:SetText( tbl["reason"] ) 538 | end 539 | 540 | end 541 | 542 | MSync.modules[info.ModuleIdentifier].editBanPanel = function(tbl) 543 | MSync.log(MSYNC_DBG_DEBUG, MSync.formatString("[MBSync] Exec: MBSync.editBanPanel Param.: $tbl",{["tbl"] = tbl})); 544 | 545 | local panel = vgui.Create( "DFrame" ) 546 | panel:SetSize( 350, 280 ) 547 | panel:SetTitle( "MBSync Edit Ban" ) 548 | panel:Center() 549 | panel:MakePopup() 550 | 551 | --[[ 552 | Info about the banned user 553 | ]] 554 | 555 | local nickname_text = vgui.Create( "DLabel", panel ) 556 | nickname_text:SetPos( 15, 35 ) 557 | nickname_text:SetColor( Color( 255, 255, 255 ) ) 558 | nickname_text:SetText( "Nickname:" ) 559 | nickname_text:SetSize(380, 15) 560 | 561 | local nickname_textentry = vgui.Create( "DTextEntry", panel ) 562 | nickname_textentry:SetPos( 125, 35 ) 563 | nickname_textentry:SetSize( 210, 20 ) 564 | --nickname_textentry:SetText( "[ApDev] Rainbow Dash" ) 565 | nickname_textentry:SetDisabled(true) 566 | 567 | local steamid_text = vgui.Create( "DLabel", panel ) 568 | steamid_text:SetPos( 15, 60 ) 569 | steamid_text:SetColor( Color( 255, 255, 255 ) ) 570 | steamid_text:SetText( "SteamID:" ) 571 | steamid_text:SetSize(380, 15) 572 | 573 | local steamid_textentry = vgui.Create( "DTextEntry", panel ) 574 | steamid_textentry:SetPos( 125, 60 ) 575 | steamid_textentry:SetSize( 210, 20 ) 576 | --steamid_textentry:SetText( "STEAM_0:0:0" ) 577 | steamid_textentry:SetDisabled(true) 578 | 579 | local steamid64_text = vgui.Create( "DLabel", panel ) 580 | steamid64_text:SetPos( 15, 85 ) 581 | steamid64_text:SetColor( Color( 255, 255, 255 ) ) 582 | steamid64_text:SetText( "SteamID64:" ) 583 | steamid64_text:SetSize(380, 15) 584 | 585 | local steamid64_textentry = vgui.Create( "DTextEntry", panel ) 586 | steamid64_textentry:SetPos( 125, 85 ) 587 | steamid64_textentry:SetSize( 210, 20 ) 588 | --steamid64_textentry:SetText( "7600000000" ) 589 | steamid64_textentry:SetDisabled(true) 590 | 591 | --[[ 592 | Editable Data 593 | ]] 594 | 595 | local banlength_text = vgui.Create( "DLabel", panel ) 596 | banlength_text:SetPos( 15, 120 ) 597 | banlength_text:SetColor( Color( 255, 255, 255 ) ) 598 | banlength_text:SetText( "Ban Length:" ) 599 | banlength_text:SetSize(380, 15) 600 | 601 | local banlength_textentry = vgui.Create( "DTextEntry", panel ) 602 | banlength_textentry:SetPos( 125, 120 ) 603 | banlength_textentry:SetSize( 210, 20 ) 604 | --banlength_textentry:SetText( "Permanent" ) 605 | banlength_textentry:SetDisabled(false) 606 | 607 | local banallservers_text = vgui.Create( "DLabel", panel ) 608 | banallservers_text:SetPos( 15, 145 ) 609 | banallservers_text:SetColor( Color( 255, 255, 255 ) ) 610 | banallservers_text:SetText( "Banned everywhere:" ) 611 | banallservers_text:SetSize(380, 15) 612 | 613 | local banallservers_textentry = vgui.Create( "DComboBox", panel ) 614 | banallservers_textentry:SetPos( 125, 145 ) 615 | banallservers_textentry:SetSize( 210, 20 ) 616 | --banallservers_textentry:SetValue( "true" ) 617 | banallservers_textentry:AddChoice( "true" ) 618 | banallservers_textentry:AddChoice( "false" ) 619 | banallservers_textentry:SetSortItems( false ) 620 | banallservers_textentry.OnSelect = function( self, index, value ) 621 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Ban on all servers: " .. value); 622 | end 623 | 624 | local banlreason_text = vgui.Create( "DLabel", panel ) 625 | banlreason_text:SetPos( 15, 170 ) 626 | banlreason_text:SetColor( Color( 255, 255, 255 ) ) 627 | banlreason_text:SetText( "Ban Reason:" ) 628 | banlreason_text:SetSize(380, 15) 629 | 630 | local banreason_textentry = vgui.Create( "DTextEntry", panel ) 631 | banreason_textentry:SetPos( 125, 170 ) 632 | banreason_textentry:SetSize( 210, 20 ) 633 | --banreason_textentry:SetText( "Permanent" ) 634 | banreason_textentry:SetDisabled(false) 635 | 636 | --[[ 637 | Save and Cancel button 638 | ]] 639 | 640 | local save_button = vgui.Create( "DButton", panel ) 641 | save_button:SetText( "Save" ) 642 | save_button:SetPos( 15, 200 ) 643 | save_button:SetSize( 320, 30 ) 644 | save_button.DoClick = function() 645 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Ban edit confirmation request"); 646 | local save_panel = vgui.Create( "DFrame" ) 647 | save_panel:SetSize( 350, 100 ) 648 | save_panel:SetTitle( "MBSync Edit Ban - Edit" ) 649 | save_panel:Center() 650 | save_panel:MakePopup() 651 | 652 | local save_text = vgui.Create( "DLabel", save_panel ) 653 | save_text:SetPos( 15, 20 ) 654 | save_text:SetColor( Color( 255, 255, 255 ) ) 655 | save_text:SetText( "This action will overwrite the ban with your edited data, are you sure you want to do that?" ) 656 | save_text:SetSize(320, 50) 657 | save_text:SetWrap( true ) 658 | 659 | local accept_button = vgui.Create( "DButton", save_panel ) 660 | accept_button:SetText( "Accept" ) 661 | accept_button:SetPos( 15, 70 ) 662 | accept_button:SetSize( 160, 20 ) 663 | accept_button.DoClick = function() 664 | MSync.log(MSYNC_DBG_INFO, "[MBSync] Edited data accepted, editing ban and closing panel"); 665 | RunConsoleCommand( "msync.MBSync.editBan", tbl["banId"], banlength_textentry:GetValue(), banallservers_textentry:GetValue(), banreason_textentry:GetValue()) 666 | panel:Close() 667 | save_panel:Close() 668 | end 669 | 670 | local deny_button = vgui.Create( "DButton", save_panel ) 671 | deny_button:SetText( "Deny" ) 672 | deny_button:SetPos( 175, 70 ) 673 | deny_button:SetSize( 160, 20 ) 674 | deny_button.DoClick = function() 675 | MSync.log(MSYNC_DBG_INFO, "[MBSync] Edited data denied, closing panel"); 676 | -- CLOSE ACCEPT PANEL 677 | save_panel:Close() 678 | end 679 | end 680 | 681 | local cancel_button = vgui.Create( "DButton", panel ) 682 | cancel_button:SetText( "Cancel" ) 683 | cancel_button:SetPos( 15, 235 ) 684 | cancel_button:SetSize( 320, 30 ) 685 | cancel_button.DoClick = function() 686 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Ban edit cancellation request"); 687 | local cancel_panel = vgui.Create( "DFrame" ) 688 | cancel_panel:SetSize( 350, 100 ) 689 | cancel_panel:SetTitle( "MBSync Edit Ban - Cancel" ) 690 | cancel_panel:Center() 691 | cancel_panel:MakePopup() 692 | 693 | local cancel_text = vgui.Create( "DLabel", cancel_panel ) 694 | cancel_text:SetPos( 15, 20 ) 695 | cancel_text:SetColor( Color( 255, 255, 255 ) ) 696 | cancel_text:SetText( "When you cancel the edit, your progress will be lost. Are you sure you want to do that?" ) 697 | cancel_text:SetSize(320, 50) 698 | cancel_text:SetWrap( true ) 699 | 700 | local accept_button = vgui.Create( "DButton", cancel_panel ) 701 | accept_button:SetText( "Accept" ) 702 | accept_button:SetPos( 15, 70 ) 703 | accept_button:SetSize( 160, 20 ) 704 | accept_button.DoClick = function() 705 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Ban edit cancelled"); 706 | panel:Close() 707 | cancel_panel:Close() 708 | end 709 | 710 | local deny_button = vgui.Create( "DButton", cancel_panel ) 711 | deny_button:SetText( "Deny" ) 712 | deny_button:SetPos( 175, 70 ) 713 | deny_button:SetSize( 160, 20 ) 714 | deny_button.DoClick = function() 715 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Ban edit cancellation request denied"); 716 | cancel_panel:Close() 717 | end 718 | end 719 | 720 | --[[ 721 | ########### 722 | FILL DATA 723 | ########### 724 | ]] 725 | 726 | if (tbl ~= nil) then 727 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Filling in ban data"); 728 | nickname_textentry:SetText( tbl["nickname"] ) 729 | steamid_textentry:SetText( tbl["steamid"] ) 730 | steamid64_textentry:SetText( tbl["steamid64"] ) 731 | banlength_textentry:SetText( tbl["length"] ) 732 | if tbl["servergroup"] == "allservers" then 733 | banallservers_textentry:SetValue( "true" ) 734 | else 735 | banallservers_textentry:SetValue( "false" ) 736 | end 737 | banreason_textentry:SetText( tbl["reason"] ) 738 | end 739 | end 740 | 741 | end 742 | 743 | --[[ 744 | Define the admin panel for the settings 745 | ]] 746 | MSync.modules[info.ModuleIdentifier].adminPanel = function(sheet) 747 | local pnl = vgui.Create( "DPanel", sheet ) 748 | local tempTable = {}; 749 | pnl:Dock(FILL) 750 | 751 | MSync.modules[info.ModuleIdentifier].getSettings() 752 | 753 | local delay_text = vgui.Create( "DLabel", pnl ) 754 | delay_text:SetPos( 10, 5 ) 755 | delay_text:SetColor( Color( 0, 0, 0 ) ) 756 | delay_text:SetText( "Set the delay when MBSync should re-synchronize the bans." ) 757 | delay_text:SetSize(380, 15) 758 | 759 | local delay_textentry = vgui.Create( "DTextEntry", pnl ) 760 | delay_textentry:SetPos( 10, 20 ) 761 | delay_textentry:SetSize( 220, 20 ) 762 | delay_textentry:SetPlaceholderText( "Timer Delay in seconds ( example: 300 )" ) 763 | 764 | local save_button = vgui.Create( "DButton", pnl ) 765 | save_button:SetText( "Save" ) 766 | save_button:SetPos( 230, 20 ) 767 | save_button:SetSize( 100, 20 ) 768 | 769 | local bantable_text = vgui.Create( "DLabel", pnl ) 770 | bantable_text:SetPos( 10, 50 ) 771 | bantable_text:SetColor( Color( 0, 0, 0 ) ) 772 | bantable_text:SetText( "Ban table with ALL bans" ) 773 | bantable_text:SetSize(380, 15) 774 | 775 | local search_textentry = vgui.Create( "DTextEntry", pnl ) 776 | search_textentry:SetPos( 10, 65 ) 777 | search_textentry:SetSize( 170, 20 ) 778 | search_textentry:SetPlaceholderText( "Nickname/SteamID/SID64/Admin" ) 779 | 780 | local search_button = vgui.Create( "DButton", pnl ) 781 | search_button:SetText( "Search" ) 782 | search_button:SetPos( 180, 65 ) 783 | search_button:SetSize( 60, 20 ) 784 | 785 | local reload_button = vgui.Create( "DButton", pnl ) 786 | reload_button:SetText( "Load Data" ) 787 | reload_button:SetPos( 380, 65 ) 788 | reload_button:SetSize( 65, 20 ) 789 | 790 | local ban_table = vgui.Create( "DListView", pnl ) 791 | ban_table:SetPos( 10, 85 ) 792 | ban_table:SetSize( 435, 240 ) 793 | ban_table:SetMultiSelect( false ) 794 | ban_table:AddColumn( "Ban ID" ):SetFixedWidth( 40 ) 795 | ban_table:AddColumn( "SteamID" ) 796 | ban_table:AddColumn( "Admin" ) 797 | ban_table:AddColumn( "Ban Length" ) 798 | ban_table:AddColumn( "Ban Reason" ) 799 | ban_table:AddColumn( "Unbanned" ) 800 | --local test = allserver_table:AddColumn( "Test" ) 801 | 802 | local sortby_dropdown = vgui.Create( "DComboBox", pnl ) 803 | sortby_dropdown:SetPos( 240, 65 ) 804 | sortby_dropdown:SetSize( 140, 20 ) 805 | sortby_dropdown:SetValue( "Sort by: Ban ID/Desc" ) 806 | sortby_dropdown:AddChoice( "Ban ID" ) 807 | sortby_dropdown:AddChoice( "SteamID" ) 808 | sortby_dropdown:AddChoice( "Admin" ) 809 | sortby_dropdown:AddChoice( "Ban Length" ) 810 | sortby_dropdown:AddChoice( "Ban Reason" ) 811 | sortby_dropdown:AddChoice( "Unbanned" ) 812 | sortby_dropdown:SetSortItems( false ) 813 | 814 | --[[ 815 | ############################ 816 | FUNCTIONALITY PART 817 | ############################ 818 | ]] 819 | 820 | local sortby = { 821 | Column = 1, 822 | Descending = true 823 | } 824 | ban_table:SortByColumn( sortby.Column, sortby.Descending ) 825 | 826 | function displayTable(tbl) 827 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Displaying data to table"); 828 | ban_table:Clear() 829 | for k,v in pairs(tbl) do 830 | local length = "" 831 | local unbanned = "false" 832 | 833 | if v["unBanningAdmin"] then 834 | unbanned = "true" 835 | end 836 | 837 | if v["length"] == 0 then 838 | length = "Permanent" 839 | else 840 | length = ULib.secondsToStringTime(v["length"]) 841 | end 842 | 843 | ban_table:AddLine( v["banId"], v["steamid"], v["adminNickname"], length, v["reason"], unbanned) 844 | end 845 | end 846 | 847 | save_button.DoClick = function() 848 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Save settings requested"); 849 | local num = tonumber(delay_textentry:GetValue()) 850 | if num then 851 | if num < 30 then 852 | MSync.log(MSYNC_DBG_ERROR, "[MBSync] You should not select a value below \"30\" seconds. We recommend to have it at \"300\" seconds"); 853 | chat.AddText(Color(255, 60, 60),"[MBSync_ERROR] ",Color(255,170,0),"You should not select a value below ",Color(60, 255, 60),"30",Color(255,170,0)," seconds. We recommend to have it at ",Color(60, 255, 60),"300",Color(255,170,0)," seconds") 854 | else 855 | MSync.modules[info.ModuleIdentifier].settings["syncDelay"] = num 856 | MSync.modules[info.ModuleIdentifier].sendSettings() 857 | end 858 | else 859 | MSync.log(MSYNC_DBG_ERROR, "[MBSync] The value you entered is invalid"); 860 | chat.AddText(Color(255, 60, 60),"[MBSync_ERROR] ",Color(255,170,0),"That is not a valid value!") 861 | end 862 | end 863 | 864 | search_button.DoClick = function() 865 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Searching table"); 866 | if search_textentry:GetValue() then 867 | tempTable = {} 868 | tempTable = MSync.modules[info.ModuleIdentifier].searchTable(MSync.modules[info.ModuleIdentifier].banTable, search_textentry:GetValue()) 869 | displayTable(tempTable) 870 | ban_table:SortByColumn( sortby.Column, sortby.Descending ) 871 | else 872 | tempTable = MSync.modules[info.ModuleIdentifier].banTable 873 | displayTable(tempTable) 874 | ban_table:SortByColumn( sortby.Column, sortby.Descending ) 875 | end 876 | end 877 | 878 | reload_button.DoClick = function() 879 | MSync.log(MSYNC_DBG_INFO, "[MBSync] Reloading data"); 880 | MSync.modules[info.ModuleIdentifier].getBanTable(true) 881 | ban_table:Clear() 882 | 883 | timer.Create("msync.mbsync.waitForBanTable", 1, 0, function() 884 | if MSync.modules[info.ModuleIdentifier].temporary["unfinished"] then return end 885 | 886 | tempTable = MSync.modules[info.ModuleIdentifier].banTable 887 | for k,v in pairs(tempTable) do 888 | local length = "" 889 | local unbanned = "false" 890 | 891 | if v["unBanningAdmin"] then 892 | unbanned = "true" 893 | end 894 | 895 | if v["length"] == 0 then 896 | length = "Permanent" 897 | else 898 | length = ULib.secondsToStringTime(v["length"]) 899 | end 900 | 901 | ban_table:AddLine( v["banId"], v["steamid"], v["adminNickname"], length, v["reason"], unbanned) 902 | end 903 | timer.Remove("msync.mbsync.waitForBanTable") 904 | end) 905 | reload_button:SetText("Reload") 906 | end 907 | 908 | ban_table.OnRowRightClick = function(panel, lineID, line) 909 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Row " .. lineID .. " right clicked"); 910 | 911 | --local ident = line:GetValue(1) 912 | local cursor_x, cursor_y = panel:CursorPos() 913 | local DMenu = vgui.Create("DMenu", panel) 914 | 915 | if cursor_y > 170 then 916 | cursor_y = 170 917 | end 918 | 919 | if cursor_x > 290 then 920 | cursor_x = 290 921 | end 922 | 923 | DMenu:SetPos(cursor_x, cursor_y) 924 | DMenu:AddOption("Unban") 925 | DMenu:AddOption("Edit") 926 | DMenu:AddOption("Advanced Info") 927 | DMenu.OptionSelected = function(menu,optPnl,optStr) 928 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Option \"" .. optStr .. "\" selected"); 929 | if optStr == "Unban" then 930 | MSync.modules[info.ModuleIdentifier].unban(line:GetColumnText( 1 )) 931 | elseif optStr == "Edit" then 932 | MSync.modules[info.ModuleIdentifier].editBanPanel(MSync.modules[info.ModuleIdentifier].banTable[line:GetColumnText( 1 )]) 933 | elseif optStr == "Advanced Info" then 934 | MSync.modules[info.ModuleIdentifier].advancedInfoPanel(MSync.modules[info.ModuleIdentifier].banTable[line:GetColumnText( 1 )]) 935 | end 936 | end 937 | end 938 | 939 | sortby_dropdown.OnSelect = function( self, index, value ) 940 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Sortby dropdown selected"); 941 | if value == "Ban ID" then 942 | sortby.Column = 1 943 | if sortby.Descending then 944 | sortby.Descending = false 945 | sortby_dropdown:SetValue( "Sort by: Ban ID/Asc" ) 946 | else 947 | sortby.Descending = true 948 | sortby_dropdown:SetValue( "Sort by: Ban ID/Desc" ) 949 | end 950 | elseif value == "SteamID" then 951 | sortby.Column = 2 952 | if sortby.Descending then 953 | sortby.Descending = false 954 | sortby_dropdown:SetValue( "Sort by: SID/ASC" ) 955 | else 956 | sortby.Descending = true 957 | sortby_dropdown:SetValue( "Sort by: SID/Desc" ) 958 | end 959 | elseif value == "Admin" then 960 | sortby.Column = 3 961 | if sortby.Descending then 962 | sortby.Descending = false 963 | sortby_dropdown:SetValue( "Sort by: Admin/Asc" ) 964 | else 965 | sortby.Descending = true 966 | sortby_dropdown:SetValue( "Sort by: Admin/Desc" ) 967 | end 968 | elseif value == "Ban Length" then 969 | sortby.Column = 4 970 | if sortby.Descending then 971 | sortby.Descending = false 972 | sortby_dropdown:SetValue( "Sort by: Length/Asc" ) 973 | else 974 | sortby.Descending = true 975 | sortby_dropdown:SetValue( "Sort by: Length/Desc" ) 976 | end 977 | elseif value == "Ban Reason" then 978 | sortby.Column = 5 979 | if sortby.Descending then 980 | sortby.Descending = false 981 | sortby_dropdown:SetValue( "Sort by: Reason/Asc" ) 982 | else 983 | sortby.Descending = true 984 | sortby_dropdown:SetValue( "Sort by: Reason/Desc" ) 985 | end 986 | elseif value == "Unbanned" then 987 | sortby.Column = 6 988 | if sortby.Descending then 989 | sortby.Descending = false 990 | sortby_dropdown:SetValue( "Sort by: Unbanned/Asc" ) 991 | else 992 | sortby.Descending = true 993 | sortby_dropdown:SetValue( "Sort by: Unbanned/Desc" ) 994 | end 995 | end 996 | 997 | if value then 998 | ban_table:SortByColumn( sortby.Column, sortby.Descending ) 999 | end 1000 | end 1001 | 1002 | timer.Create("msync.mbsync.waitForSettings", 1, 0, function() 1003 | if not MSync.modules[info.ModuleIdentifier].settings then return end 1004 | 1005 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Got settings from server, filling in data"); 1006 | 1007 | delay_textentry:SetText(MSync.modules[info.ModuleIdentifier].settings["syncDelay"]) 1008 | 1009 | timer.Remove("msync.mbsync.waitForSettings") 1010 | end) 1011 | 1012 | return pnl 1013 | end 1014 | 1015 | --[[ 1016 | Define the client panel for client usage ( or as example: use it as additional admin gui which does not need msync.admingui permission) 1017 | ]] 1018 | MSync.modules[info.ModuleIdentifier].clientPanel = function() 1019 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.clientPanel"); 1020 | 1021 | --[[ 1022 | Get Ban table and then wait for the reply before showing it 1023 | ]] 1024 | 1025 | MSync.modules[info.ModuleIdentifier].getBanTable() 1026 | 1027 | local tempTable = {} 1028 | local pages = 0 1029 | local tablePage = 0 1030 | 1031 | local panel = vgui.Create( "DFrame" ) 1032 | panel:SetSize( 800, 450 ) 1033 | panel:SetTitle( "MSync Admin Menu" ) 1034 | panel:Center() 1035 | panel:MakePopup() 1036 | panel:SetBackgroundBlur( true ) 1037 | 1038 | local search_textentry = vgui.Create( "DTextEntry", panel ) 1039 | search_textentry:SetPos( 15, 35 ) 1040 | search_textentry:SetSize( 250, 20 ) 1041 | search_textentry:SetPlaceholderText( "Nickname/SteamID/SID64/Admin" ) 1042 | 1043 | local ban_table = vgui.Create( "DListView", panel ) 1044 | ban_table:SetPos( 15, 60 ) 1045 | ban_table:SetSize( 770, 360 ) 1046 | ban_table:SetMultiSelect( false ) 1047 | ban_table:AddColumn( "Ban ID" ):SetFixedWidth( 50 ) 1048 | ban_table:AddColumn( "Nickname" ):SetFixedWidth( 120 ) 1049 | ban_table:AddColumn( "Admin" ):SetFixedWidth( 120 ) 1050 | ban_table:AddColumn( "Ban Date" ):SetFixedWidth( 120 ) 1051 | ban_table:AddColumn( "Ban Length" ):SetFixedWidth( 120 ) 1052 | ban_table:AddColumn( "Ban Reason" ) 1053 | 1054 | local search_button = vgui.Create( "DButton", panel ) 1055 | search_button:SetText( "Search" ) 1056 | search_button:SetPos( 270, 35 ) 1057 | search_button:SetSize( 130, 20 ) 1058 | 1059 | local sortby_dropdown = vgui.Create( "DComboBox", panel ) 1060 | sortby_dropdown:SetPos( 405, 35 ) 1061 | sortby_dropdown:SetSize( 130, 20 ) 1062 | sortby_dropdown:SetValue( "Sort by: Ban ID" ) 1063 | sortby_dropdown:AddChoice( "Ban ID" ) 1064 | sortby_dropdown:AddChoice( "Nickname" ) 1065 | sortby_dropdown:AddChoice( "Admin" ) 1066 | sortby_dropdown:AddChoice( "Ban Length" ) 1067 | sortby_dropdown:AddChoice( "Ban Reason" ) 1068 | sortby_dropdown:SetSortItems( false ) 1069 | 1070 | local listascdesc_button = vgui.Create( "DButton", panel ) 1071 | listascdesc_button:SetText( "List: Desc" ) 1072 | listascdesc_button:SetPos( 540, 35 ) 1073 | listascdesc_button:SetSize( 110, 20 ) 1074 | 1075 | local sync_button = vgui.Create( "DButton", panel ) 1076 | sync_button:SetText( "Reload Bans" ) 1077 | sync_button:SetPos( 655, 35 ) 1078 | sync_button:SetSize( 130, 20 ) 1079 | 1080 | local firstpage_button = vgui.Create( "DButton", panel ) 1081 | firstpage_button:SetText( "<< First" ) 1082 | firstpage_button:SetPos( 15, 421 ) 1083 | firstpage_button:SetSize( 185, 20 ) 1084 | firstpage_button:SetDisabled(true) 1085 | 1086 | local previouspage_button = vgui.Create( "DButton", panel ) 1087 | previouspage_button:SetText( "< Previous" ) 1088 | previouspage_button:SetPos( 200, 421 ) 1089 | previouspage_button:SetSize( 185, 20 ) 1090 | previouspage_button:SetDisabled(true) 1091 | 1092 | local pageof_text = vgui.Create( "DLabel", panel ) 1093 | pageof_text:SetPos( 385, 421 ) 1094 | pageof_text:SetColor( Color( 255, 255, 255 ) ) 1095 | pageof_text:SetText( "1/" .. pages ) 1096 | pageof_text:SetSize(30, 20) 1097 | pageof_text:SetContentAlignment( 5 ) 1098 | 1099 | local nextpage_button = vgui.Create( "DButton", panel ) 1100 | nextpage_button:SetText( "Next >" ) 1101 | nextpage_button:SetPos( 415, 421 ) 1102 | nextpage_button:SetSize( 185, 20 ) 1103 | nextpage_button:SetDisabled(true) 1104 | 1105 | local lastpage_button = vgui.Create( "DButton", panel ) 1106 | lastpage_button:SetText( "Last >>" ) 1107 | lastpage_button:SetPos( 600, 421 ) 1108 | lastpage_button:SetSize( 185, 20 ) 1109 | lastpage_button:SetDisabled(true) 1110 | 1111 | --[[ 1112 | ############# 1113 | FUNCTION PART 1114 | ############# 1115 | ]] 1116 | --[[ 1117 | Define sortby variable for sorting the ban table 1118 | ]] 1119 | local sortby = { 1120 | Column = "banId", 1121 | Descending = false 1122 | } 1123 | 1124 | local function checkPage() 1125 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: checkPage"); 1126 | if ( (tablePage + 1) >= pages ) then 1127 | lastpage_button:SetDisabled(true) 1128 | nextpage_button:SetDisabled(true) 1129 | else 1130 | lastpage_button:SetDisabled(false) 1131 | nextpage_button:SetDisabled(false) 1132 | end 1133 | 1134 | if (tablePage >= 1) then 1135 | firstpage_button:SetDisabled(false) 1136 | previouspage_button:SetDisabled(false) 1137 | else 1138 | firstpage_button:SetDisabled(true) 1139 | previouspage_button:SetDisabled(true) 1140 | end 1141 | end 1142 | 1143 | ban_table.OnRowRightClick = function(parentPanel, lineID, line) 1144 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Row \"" .. lineID .. "\" right clicked"); 1145 | --local ident = line:GetValue(1) 1146 | local cursor_x, cursor_y = panel:CursorPos() 1147 | local DMenu = vgui.Create("DMenu", panel) 1148 | DMenu:SetPos(cursor_x, cursor_y) 1149 | DMenu:AddOption("Unban") 1150 | DMenu:AddOption("Edit") 1151 | DMenu:AddOption("Advanced Info") 1152 | DMenu.OptionSelected = function(menu,optPnl,optStr) 1153 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Option \"" .. optStr .. "\" selected"); 1154 | if optStr == "Unban" then 1155 | MSync.modules[info.ModuleIdentifier].unban(line:GetColumnText( 1 )) 1156 | elseif optStr == "Edit" then 1157 | MSync.modules[info.ModuleIdentifier].editBanPanel(MSync.modules[info.ModuleIdentifier].banTable[line:GetColumnText( 1 )]) 1158 | elseif optStr == "Advanced Info" then 1159 | MSync.modules[info.ModuleIdentifier].advancedInfoPanel(MSync.modules[info.ModuleIdentifier].banTable[line:GetColumnText( 1 )]) 1160 | end 1161 | end 1162 | end 1163 | 1164 | sortby_dropdown.OnSelect = function( self, index, value ) 1165 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Sortby: Selected \"" .. value .. "\""); 1166 | --ban_table 1167 | if value == "Ban ID" then 1168 | sortby.Column = "banId" 1169 | sortby_dropdown:SetValue( "Sort by: Ban ID" ) 1170 | elseif value == "Nickname" then 1171 | sortby.Column = "nickname" 1172 | sortby_dropdown:SetValue( "Sort by: Nickname" ) 1173 | elseif value == "Admin" then 1174 | sortby.Column = "adminNickname" 1175 | sortby_dropdown:SetValue( "Sort by: Admin" ) 1176 | elseif value == "Ban Date" then 1177 | sortby.Column = "timestamp" 1178 | sortby_dropdown:SetValue( "Sort by: Ban Length" ) 1179 | elseif value == "Ban Length" then 1180 | sortby.Column = "length" 1181 | sortby_dropdown:SetValue( "Sort by: Ban Length" ) 1182 | elseif value == "Ban Reason" then 1183 | sortby.Column = "reason" 1184 | sortby_dropdown:SetValue( "Sort by: Ban Reason" ) 1185 | end 1186 | 1187 | if value then 1188 | tempTable = MSync.modules[info.ModuleIdentifier].sortTable(tempTable, sortby.Column, sortby.Descending) 1189 | MSync.modules[info.ModuleIdentifier].displayTable(ban_table, tempTable, 20, 0) 1190 | checkPage() 1191 | end 1192 | end 1193 | 1194 | listascdesc_button.DoClick = function() 1195 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Changing if list should be ascending or descending"); 1196 | if sortby.Descending then 1197 | sortby.Descending = false 1198 | listascdesc_button:SetText( "List: Desc" ) 1199 | else 1200 | sortby.Descending = true 1201 | listascdesc_button:SetText( "List: Asc" ) 1202 | end 1203 | tempTable = MSync.modules[info.ModuleIdentifier].sortTable(tempTable, sortby.Column, sortby.Descending) 1204 | MSync.modules[info.ModuleIdentifier].displayTable(ban_table, tempTable, 20, 0) 1205 | checkPage() 1206 | end 1207 | 1208 | search_button.DoClick = function() 1209 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Searching table"); 1210 | if search_textentry:GetValue() then 1211 | tempTable = {} 1212 | tempTable = MSync.modules[info.ModuleIdentifier].searchTable(MSync.modules[info.ModuleIdentifier].banTable, search_textentry:GetValue()) 1213 | tempTable = MSync.modules[info.ModuleIdentifier].sortTable(tempTable, sortby.Column, sortby.Descending) 1214 | MSync.modules[info.ModuleIdentifier].displayTable(ban_table, tempTable, 20, 0) 1215 | checkPage() 1216 | else 1217 | tempTable = MSync.modules[info.ModuleIdentifier].sortTable(MSync.modules[info.ModuleIdentifier].banTable, sortby.Column, sortby.Descending) 1218 | MSync.modules[info.ModuleIdentifier].displayTable(ban_table, tempTable, 20, 0) 1219 | checkPage() 1220 | end 1221 | end 1222 | 1223 | sync_button.DoClick = function() 1224 | MSync.log(MSYNC_DBG_INFO, "[MBSync] Reloading ban table"); 1225 | MSync.modules[info.ModuleIdentifier].getBanTable() 1226 | timer.Create("msync.mbsync.waitForBanTable", 3, 0, function() 1227 | if MSync.modules[info.ModuleIdentifier].temporary["unfinished"] then MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Still waiting for some data from server"); return end 1228 | 1229 | MSync.log(MSYNC_DBG_INFO, "[MBSync] Got all ban data from server! Reloading table now"); 1230 | tempTable = MSync.modules[info.ModuleIdentifier].sortTable(MSync.modules[info.ModuleIdentifier].banTable, sortby.Column, sortby.Descending) 1231 | pages = MSync.modules[info.ModuleIdentifier].getTablePages(tempTable, 20) 1232 | tablePage = 0 1233 | 1234 | pageof_text:SetText( (tablePage + 1) .. "/" .. pages ) 1235 | 1236 | if pages > 1 then 1237 | nextpage_button:SetDisabled(false) 1238 | lastpage_button:SetDisabled(false) 1239 | end 1240 | 1241 | MSync.modules[info.ModuleIdentifier].displayTable(ban_table, tempTable, 20, tablePage) 1242 | timer.Remove("msync.mbsync.waitForBanTable") 1243 | end) 1244 | end 1245 | 1246 | firstpage_button.DoClick = function() 1247 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Go to first page"); 1248 | 1249 | tablePage = 0 1250 | pageof_text:SetText( (tablePage + 1) .. "/" .. pages ) 1251 | MSync.modules[info.ModuleIdentifier].displayTable(ban_table, tempTable, 20, tablePage) 1252 | checkPage() 1253 | end 1254 | 1255 | previouspage_button.DoClick = function() 1256 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Go to previous page"); 1257 | 1258 | tablePage = tablePage - 1 1259 | pageof_text:SetText( (tablePage + 1) .. "/" .. pages ) 1260 | MSync.modules[info.ModuleIdentifier].displayTable(ban_table, tempTable, 20, tablePage) 1261 | checkPage() 1262 | end 1263 | 1264 | nextpage_button.DoClick = function() 1265 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Go to next page"); 1266 | 1267 | tablePage = tablePage + 1 1268 | pageof_text:SetText( (tablePage + 1) .. "/" .. pages ) 1269 | MSync.modules[info.ModuleIdentifier].displayTable(ban_table, tempTable, 20, tablePage) 1270 | checkPage() 1271 | end 1272 | 1273 | lastpage_button.DoClick = function() 1274 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Go to last page"); 1275 | 1276 | tablePage = pages-1 1277 | pageof_text:SetText( (tablePage + 1) .. "/" .. pages ) 1278 | MSync.modules[info.ModuleIdentifier].displayTable(ban_table, tempTable, 20, tablePage) 1279 | checkPage() 1280 | end 1281 | 1282 | if pages > 1 then 1283 | nextpage_button:SetDisabled(false) 1284 | lastpage_button:SetDisabled(false) 1285 | end 1286 | 1287 | timer.Create("msync.mbsync.waitForBanTable", 1, 0, function() 1288 | if MSync.modules[info.ModuleIdentifier].temporary["unfinished"] then MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Still waiting for some data from server");return end 1289 | 1290 | MSync.log(MSYNC_DBG_INFO, "[MBSync] Got all ban data from server! Reloading table now"); 1291 | 1292 | tempTable = MSync.modules[info.ModuleIdentifier].sortTable(MSync.modules[info.ModuleIdentifier].banTable, sortby.Column, sortby.Descending) 1293 | pages = MSync.modules[info.ModuleIdentifier].getTablePages(tempTable, 20) 1294 | tablePage = 0 1295 | 1296 | pageof_text:SetText( (tablePage + 1) .. "/" .. pages ) 1297 | 1298 | if pages > 1 then 1299 | nextpage_button:SetDisabled(false) 1300 | lastpage_button:SetDisabled(false) 1301 | end 1302 | 1303 | MSync.modules[info.ModuleIdentifier].displayTable(ban_table, tempTable, 20, tablePage) 1304 | timer.Remove("msync.mbsync.waitForBanTable") 1305 | end) 1306 | 1307 | 1308 | return panel 1309 | end 1310 | 1311 | --[[ 1312 | Define net receivers and util.AddNetworkString 1313 | ]] 1314 | MSync.modules[info.ModuleIdentifier].net = function() 1315 | --[[ 1316 | So basically we run into a problem as data packages have a size limit of 64KB, so if the ban table is big enough we cant send it over net.WriteTable. 1317 | The solution? We send it in single chunks. 1318 | We first need to request the table, that should return how much entries we have and then send us each data and at the end a "finished" 1319 | So first we need a net sender to request the data, then we need a reciever to recieve the package count, then one to recieve the actuall packages and last but not least one to finish the process. 1320 | Should not be that hard, eh? 1321 | 1322 | Notice: 1323 | For future usage we may should make that a MSync function and not a MBSync function 1324 | ]] 1325 | 1326 | --[[ 1327 | Description: Function to unban a user using the banid 1328 | Arguments: 1329 | userid [number] - the ban id of the to be lifted ban 1330 | Returns: nothing 1331 | ]] 1332 | MSync.modules[info.ModuleIdentifier].unban = function(userid) 1333 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.unban Param.:" .. userid); 1334 | 1335 | if type(userid) ~= "number" then 1336 | userid = tonumber(userid) 1337 | end 1338 | 1339 | net.Start("msync." .. info.ModuleIdentifier .. ".unban") 1340 | net.WriteFloat(userid) 1341 | net.SendToServer() 1342 | end 1343 | --[[ 1344 | Description: Net Receiver - Gets called when the server wants to print something to the user chat 1345 | Returns: nothing 1346 | ]] 1347 | net.Receive( "msync." .. info.ModuleIdentifier .. ".sendMessage", function( len, ply ) 1348 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Net: msync.MBSync.sendMessage"); 1349 | 1350 | local msgType = net.ReadFloat() 1351 | if msgType == 0 then 1352 | chat.AddText( Color( 237, 135, 26 ), "[MBSync] ", Color( 255, 255, 255), net.ReadString()) 1353 | end 1354 | end ) 1355 | 1356 | --[[ 1357 | Description: Net Receiver - Gets called when the client entered '!mban' 1358 | Returns: nothing 1359 | ]] 1360 | net.Receive( "msync." .. info.ModuleIdentifier .. ".openBanGUI", function( len, ply ) 1361 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Net: msync.MBSync.openBanGUI"); 1362 | 1363 | MSync.modules[info.ModuleIdentifier].banPanel(net.ReadTable()) 1364 | end ) 1365 | 1366 | --[[ 1367 | Description: Net Receiver - Gets called when the client entered '!mbsync' 1368 | Returns: nothing 1369 | ]] 1370 | net.Receive( "msync." .. info.ModuleIdentifier .. ".openBanTable", function( len, ply ) 1371 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Net: msync.MBSync.openBanTable"); 1372 | 1373 | MSync.modules[info.ModuleIdentifier].clientPanel() 1374 | end ) 1375 | 1376 | --[[ 1377 | Description: Function to unban a user using the banid 1378 | Arguments: 1379 | userid [number] - the ban id of the to be lifted ban 1380 | Returns: nothing 1381 | ]] 1382 | MSync.modules[info.ModuleIdentifier].getBanTable = function(fulltable) 1383 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.getBanTable Param.: " .. tostring(fulltable)); 1384 | 1385 | MSync.modules[info.ModuleIdentifier].temporary = {} 1386 | MSync.modules[info.ModuleIdentifier].banTable = {} 1387 | 1388 | net.Start("msync." .. info.ModuleIdentifier .. ".getBanTable") 1389 | net.WriteBool(fulltable) 1390 | net.SendToServer() 1391 | end 1392 | 1393 | --[[ 1394 | Description: Net Receiver - Gets called when the client entered '!mban' 1395 | Returns: nothing 1396 | ]] 1397 | net.Receive( "msync." .. info.ModuleIdentifier .. ".recieveDataCount", function( len, ply ) 1398 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Net: msync.MBSync.recieveDataCount"); 1399 | 1400 | local num = net.ReadFloat() 1401 | if num > 0 and not MSync.modules[info.ModuleIdentifier].temporary["unfinished"] then 1402 | MSync.modules[info.ModuleIdentifier].temporary["count"] = num 1403 | MSync.modules[info.ModuleIdentifier].temporary["recieved"] = 0 1404 | MSync.modules[info.ModuleIdentifier].temporary["unfinished"] = true 1405 | MSync.modules[info.ModuleIdentifier].banTable = {} 1406 | end 1407 | end ) 1408 | 1409 | --[[ 1410 | Description: Net Receiver - Gets called when the client entered '!mban' 1411 | Returns: nothing 1412 | ]] 1413 | net.Receive( "msync." .. info.ModuleIdentifier .. ".recieveData", function( len, ply ) 1414 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] msync.MBSync.recieveData"); 1415 | 1416 | MSync.modules[info.ModuleIdentifier].explodeTable(MSync.modules[info.ModuleIdentifier].banTable, net.ReadTable()) 1417 | 1418 | MSync.modules[info.ModuleIdentifier].temporary["recieved"] = MSync.modules[info.ModuleIdentifier].temporary["recieved"] + 1 1419 | 1420 | if MSync.modules[info.ModuleIdentifier].temporary["recieved"] == MSync.modules[info.ModuleIdentifier].temporary["count"] then 1421 | MSync.modules[info.ModuleIdentifier].temporary = {} 1422 | local tempTable = {} 1423 | for k,v in pairs(MSync.modules[info.ModuleIdentifier].banTable) do 1424 | tempTable[v["banId"]] = {} 1425 | tempTable[v["banId"]]["banId"] = v["banId"] 1426 | tempTable[v["banId"]]["adminNickname"] = v["adminNickname"] 1427 | tempTable[v["banId"]]["nickname"] = v["banned"]["nickname"] 1428 | tempTable[v["banId"]]["steamid"] = v["banned"]["steamid"] 1429 | tempTable[v["banId"]]["steamid64"] = k 1430 | tempTable[v["banId"]]["length"] = v["length"] 1431 | tempTable[v["banId"]]["reason"] = v["reason"] 1432 | tempTable[v["banId"]]["timestamp"] = v["timestamp"] 1433 | tempTable[v["banId"]]["servergroup"] = v["servergroup"] 1434 | if v["banningAdmin"] then 1435 | tempTable[v["banId"]]["adminNickname"] = v["banningAdmin"]["nickname"] 1436 | end 1437 | if v["unBanningAdmin"] then 1438 | tempTable[v["banId"]]["unBanningAdmin"] = v["unBanningAdmin"]["nickname"] 1439 | end 1440 | end 1441 | MSync.modules[info.ModuleIdentifier].banTable = tempTable 1442 | end 1443 | end ) 1444 | 1445 | --[[ 1446 | Description: Net Receiver - Gets called when the server sent settings 1447 | Returns: nothing 1448 | ]] 1449 | net.Receive( "msync." .. info.ModuleIdentifier .. ".sendSettingsPly", function( len, ply ) 1450 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Net: msync.MBSync.sendSettingsPly"); 1451 | 1452 | MSync.modules[info.ModuleIdentifier].settings = net.ReadTable() 1453 | end ) 1454 | 1455 | --[[ 1456 | Description: Function to request the settings from the server 1457 | Returns: nothing 1458 | ]] 1459 | MSync.modules[info.ModuleIdentifier].getSettings = function() 1460 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.getSettings"); 1461 | 1462 | net.Start("msync." .. info.ModuleIdentifier .. ".getSettings") 1463 | net.SendToServer() 1464 | end 1465 | 1466 | --[[ 1467 | Description: Function to request the settings from the server 1468 | Returns: nothing 1469 | ]] 1470 | MSync.modules[info.ModuleIdentifier].sendSettings = function() 1471 | MSync.log(MSYNC_DBG_DEBUG, "[MBSync] Exec: MBSync.sendSettings"); 1472 | 1473 | net.Start("msync." .. info.ModuleIdentifier .. ".sendSettings") 1474 | net.WriteTable(MSync.modules[info.ModuleIdentifier].settings) 1475 | net.SendToServer() 1476 | end 1477 | end 1478 | 1479 | --[[ 1480 | Define ulx Commands and overwrite common ulx functions (module does not get loaded until ulx has fully been loaded) 1481 | ]] 1482 | MSync.modules[info.ModuleIdentifier].ulx = function() 1483 | -- 1484 | end 1485 | 1486 | --[[ 1487 | Define hooks your module is listening on e.g. PlayerDisconnect 1488 | ]] 1489 | MSync.modules[info.ModuleIdentifier].hooks = function() 1490 | -- 1491 | end 1492 | 1493 | --[[ 1494 | Define a function to run on the clients when the module gets disabled 1495 | ]] 1496 | MSync.modules[info.ModuleIdentifier].disable = function() 1497 | 1498 | end 1499 | 1500 | --[[ 1501 | Return info ( Just for single module loading ) 1502 | ]] 1503 | return MSync.modules[info.ModuleIdentifier].info -------------------------------------------------------------------------------- /lua/msync/client_gui/modules/cl_mrsync.lua: -------------------------------------------------------------------------------- 1 | MSync = MSync or {} 2 | MSync.modules = MSync.modules or {} 3 | MSync.modules.MRSync = MSync.modules.MRSync or {} 4 | --[[ 5 | * @file cl_mrsync.lua 6 | * @package MySQL Rank Sync 7 | * @author Aperture Development 8 | * @license root_dir/LICENCE 9 | * @version 2.3.0 10 | ]] 11 | 12 | --[[ 13 | Define name, description and module identifier 14 | ]] 15 | MSync.modules.MRSync.info = { 16 | Name = "MySQL Rank Sync", 17 | ModuleIdentifier = "MRSync", 18 | Description = "Synchronise your ranks across your servers", 19 | Version = "2.3.0" 20 | } 21 | 22 | --[[ 23 | Define additional functions that are later used 24 | ]] 25 | function MSync.modules.MRSync.init() 26 | 27 | end 28 | 29 | --[[ 30 | Define the admin panel for the settings 31 | ]] 32 | function MSync.modules.MRSync.adminPanel(sheet) 33 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Initializing AdminGUI panel"); 34 | local pnl = vgui.Create( "DPanel", sheet ) 35 | pnl:Dock(FILL) 36 | 37 | local allserver_text = vgui.Create( "DLabel", pnl ) 38 | allserver_text:SetPos( 25, 0 ) 39 | allserver_text:SetColor( Color( 0, 0, 0 ) ) 40 | allserver_text:SetText( "Add Allserver ranks. Those ranks get Synced across all servers." ) 41 | allserver_text:SetSize(380, 15) 42 | 43 | local allserver_textentry = vgui.Create( "DTextEntry", pnl ) 44 | allserver_textentry:SetPos( 25, 15 ) 45 | allserver_textentry:SetSize( 250, 20 ) 46 | allserver_textentry:SetPlaceholderText( "Rank name as string. Example: superadmin" ) 47 | 48 | local allserver_table = vgui.Create( "DListView", pnl ) 49 | allserver_table:SetPos( 25, 35 ) 50 | allserver_table:SetSize( 380, 100 ) 51 | allserver_table:SetMultiSelect( false ) 52 | allserver_table:AddColumn( "Allserver Ranks" ) 53 | allserver_table.OnRowRightClick = function(panel, lineID, line) 54 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Right clicked " .. line:GetValue(1)); 55 | --local ident = line:GetValue(1) 56 | local cursor_x, cursor_y = panel:CursorPos() 57 | local DMenu = vgui.Create("DMenu", panel) 58 | DMenu:SetPos(cursor_x, cursor_y) 59 | DMenu:AddOption("Remove") 60 | DMenu.OptionSelected = function(menu,optPnl,optStr) 61 | if MSync.modules.MRSync.settings.syncall[line:GetValue(1)] then 62 | 63 | MSync.log(MSYNC_DBG_INFO, "[MRSync] Removing \"" .. line:GetValue(1) .. "\" from allservers ranks"); 64 | allserver_table:RemoveLine(lineID) 65 | MSync.modules.MRSync.settings.syncall[line:GetValue(1)] = nil 66 | MSync.modules.MRSync.sendSettings() 67 | 68 | end 69 | end 70 | end 71 | 72 | local allserver_button = vgui.Create( "DButton", pnl ) 73 | allserver_button:SetText( "Add" ) 74 | allserver_button:SetPos( 275, 15 ) 75 | allserver_button:SetSize( 130, 20 ) 76 | allserver_button.DoClick = function() 77 | if string.len(allserver_textentry:GetValue()) > 0 and not MSync.modules.MRSync.settings.nosync[allserver_textentry:GetValue()] and not MSync.modules.MRSync.settings.syncall[allserver_textentry:GetValue()] then 78 | if string.match(allserver_textentry:GetValue(), "^%s*$") or string.match(allserver_textentry:GetValue(), "^%s") or string.match(allserver_textentry:GetValue(), "%s$") then MSync.log(MSYNC_DBG_WARNING, "[MRSync] String contains one or more whitespaces at the end or the beginning, not adding to list"); return end 79 | 80 | MSync.log(MSYNC_DBG_INFO, "[MRSync] Adding \"" .. allserver_textentry:GetValue() .. "\" to allservers rank list"); 81 | allserver_table:AddLine(allserver_textentry:GetValue()) 82 | MSync.modules.MRSync.settings.syncall[allserver_textentry:GetValue()] = true 83 | allserver_textentry:SetText("") 84 | MSync.modules.MRSync.sendSettings() 85 | end 86 | end 87 | 88 | local nosync_text = vgui.Create( "DLabel", pnl ) 89 | nosync_text:SetPos( 25, 140 ) 90 | nosync_text:SetColor( Color( 0, 0, 0 ) ) 91 | nosync_text:SetText( "Add Nosync ranks. Those ranks do not get Synced at all." ) 92 | nosync_text:SetSize(380, 15) 93 | 94 | local nosync_textentry = vgui.Create( "DTextEntry", pnl ) 95 | nosync_textentry:SetPos( 25, 155 ) 96 | nosync_textentry:SetSize( 250, 20 ) 97 | nosync_textentry:SetPlaceholderText( "Rank name as string. Example: superadmin" ) 98 | 99 | local nosync_table = vgui.Create( "DListView", pnl ) 100 | nosync_table:SetPos( 25, 175 ) 101 | nosync_table:SetSize( 380, 100 ) 102 | nosync_table:SetMultiSelect( false ) 103 | nosync_table:AddColumn( "Nosync Ranks" ) 104 | nosync_table.OnRowRightClick = function(panel, lineID, line) 105 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Right clicked " .. line:GetValue(1)); 106 | --local ident = line:GetValue(1) 107 | local cursor_x, cursor_y = panel:CursorPos() 108 | local DMenu = vgui.Create("DMenu", panel) 109 | DMenu:SetPos(cursor_x, cursor_y) 110 | DMenu:AddOption("Remove") 111 | DMenu.OptionSelected = function(menu,optPnl,optStr) 112 | if MSync.modules.MRSync.settings.nosync[line:GetValue(1)] then 113 | 114 | MSync.log(MSYNC_DBG_INFO, "[MRSync] Removing \"" .. line:GetValue(1) .. "\" from nosync ranks"); 115 | nosync_table:RemoveLine(lineID) 116 | MSync.modules.MRSync.settings.nosync[line:GetValue(1)] = nil 117 | MSync.modules.MRSync.sendSettings() 118 | 119 | end 120 | end 121 | end 122 | 123 | local nosync_button = vgui.Create( "DButton", pnl ) 124 | nosync_button:SetText( "Add" ) 125 | nosync_button:SetPos( 275, 155 ) 126 | nosync_button:SetSize( 130, 20 ) 127 | nosync_button.DoClick = function() 128 | if string.len(nosync_textentry:GetValue()) > 0 and not MSync.modules.MRSync.settings.nosync[nosync_textentry:GetValue()] and not MSync.modules.MRSync.settings.syncall[nosync_textentry:GetValue()] then 129 | if string.match(nosync_textentry:GetValue(), "^%s*$") or string.match(nosync_textentry:GetValue(), "^%s") or string.match(nosync_textentry:GetValue(), "%s$") then MSync.log(MSYNC_DBG_WARNING, "[MRSync] String contains one or more whitespaces at the end or the beginning, not adding to list"); return end 130 | 131 | MSync.log(MSYNC_DBG_INFO, "[MRSync] Adding \"" .. allserver_textentry:GetValue() .. "\" to nosync rank list"); 132 | nosync_table:AddLine(nosync_textentry:GetValue()) 133 | MSync.modules.MRSync.settings.nosync[nosync_textentry:GetValue()] = true 134 | nosync_textentry:SetText("") 135 | MSync.modules.MRSync.sendSettings() 136 | end 137 | end 138 | 139 | -- Load settings from the server 140 | MSync.modules.MRSync.getSettings() 141 | 142 | -- Wait for settings from the server 143 | if not MSync.modules.MRSync.settings then 144 | timer.Create("mrsync.t.checkSettings", 1, 0, function() 145 | if not MSync.modules.MRSync.settings then return end 146 | 147 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Got settings from server, adding to panel"); 148 | for k,_ in pairs(MSync.modules.MRSync.settings.syncall) do 149 | allserver_table:AddLine(k) 150 | end 151 | 152 | for k,_ in pairs(MSync.modules.MRSync.settings.nosync) do 153 | nosync_table:AddLine(k) 154 | end 155 | 156 | timer.Remove("mrsync.t.checkSettings") 157 | end) 158 | else 159 | 160 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Settings found, adding to panel"); 161 | for k,_ in pairs(MSync.modules.MRSync.settings.syncall) do 162 | allserver_table:AddLine(k) 163 | end 164 | 165 | for k,_ in pairs(MSync.modules.MRSync.settings.nosync) do 166 | nosync_table:AddLine(k) 167 | end 168 | end 169 | 170 | return pnl 171 | end 172 | 173 | --[[ 174 | Define the client panel for client usage ( or as example: use it as additional admin gui which does not need msync.admingui permission) 175 | ]] 176 | function MSync.modules.MRSync.clientPanel() 177 | local pnl = vgui.Create( "DPanel" ) 178 | 179 | return pnl 180 | end 181 | 182 | --[[ 183 | Define net receivers and util.AddNetworkString 184 | ]] 185 | function MSync.modules.MRSync.net() 186 | 187 | --[[ 188 | Description: Function to send the mrsync settings to the client 189 | Arguments: 190 | player [player] - the player that wants to open the admin GUI 191 | Returns: nothing 192 | ]] 193 | function MSync.modules.MRSync.sendSettings() 194 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Exec: MRSync.sendSettings"); 195 | net.Start("msync.mrsync.sendSettings") 196 | net.WriteTable(MSync.modules.MRSync.settings) 197 | net.SendToServer() 198 | end 199 | 200 | --[[ 201 | Description: Function to send the mrsync settings to the client 202 | Arguments: 203 | player [player] - the player that wants to open the admin GUI 204 | Returns: nothing 205 | ]] 206 | function MSync.modules.MRSync.getSettings() 207 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Exec: MRSync.getSettings"); 208 | net.Start("msync.mrsync.getSettings") 209 | net.SendToServer() 210 | end 211 | 212 | --[[ 213 | Description: Net Receiver - Gets called when the client requests the settings table 214 | Returns: nothing 215 | ]] 216 | net.Receive("msync.mrsync.sendSettingsPly", function(len, ply) 217 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Net: msync.mrsync.sendSettingsPly"); 218 | MSync.modules.MRSync.settings = net.ReadTable() 219 | end ) 220 | end 221 | 222 | --[[ 223 | Define ulx Commands and overwrite common ulx functions (module does not get loaded until ulx has fully been loaded) 224 | ]] 225 | function MSync.modules.MRSync.ulx() 226 | 227 | end 228 | 229 | --[[ 230 | Define hooks your module is listening on e.g. PlayerDisconnect 231 | ]] 232 | function MSync.modules.MRSync.hooks() 233 | 234 | end 235 | 236 | --[[ 237 | Define a function to run on the clients when the module gets disabled 238 | ]] 239 | MSync.modules.MRSync.disable = function() 240 | 241 | end 242 | 243 | --[[ 244 | Return info ( Just for single module loading ) 245 | ]] 246 | return MSync.modules.MRSync.info -------------------------------------------------------------------------------- /lua/msync/client_gui/modules/cl_samplemodule.lua: -------------------------------------------------------------------------------- 1 | MSync = MSync or {} 2 | MSync.modules = MSync.modules or {} 3 | MSync.modules.SampleModule = MSync.modules.SampleModule or {} 4 | --[[ 5 | * @file cl_samplemodule.lua 6 | * @package Sample Module 7 | * @author Aperture Development 8 | * @license root_dir/LICENCE 9 | * @version 1.0.1 10 | ]] 11 | 12 | --[[ 13 | Define name, description and module identifier 14 | ]] 15 | local info = { 16 | Name = "Sample Module", 17 | ModuleIdentifier = "SampleModule", 18 | Description = "A basic example module on how to create modules", 19 | Version = "1.0.1" 20 | } 21 | 22 | --[[ 23 | Prepare Module 24 | ]] 25 | MSync.modules[info.ModuleIdentifier] = MSync.modules[info.ModuleIdentifier] or {} 26 | MSync.modules[info.ModuleIdentifier].info = info 27 | 28 | --[[ 29 | Define additional functions that are later used 30 | ]] 31 | MSync.modules[info.ModuleIdentifier].init = function() 32 | 33 | function MSync.modules.SampleModule.SampleFunction() 34 | return true 35 | end 36 | 37 | end 38 | 39 | --[[ 40 | Define the admin panel for the settings 41 | ]] 42 | MSync.modules[info.ModuleIdentifier].adminPanel = function(sheet) 43 | local pnl = vgui.Create( "DPanel", sheet ) 44 | pnl:Dock(FILL) 45 | return pnl 46 | end 47 | 48 | --[[ 49 | Define the client panel for client usage ( or as example: use it as additional admin gui which does not need msync.admingui permission) 50 | ]] 51 | MSync.modules[info.ModuleIdentifier].clientPanel = function() 52 | local pnl = vgui.Create( "DPanel" ) 53 | 54 | return pnl 55 | end 56 | 57 | --[[ 58 | Define net receivers and util.AddNetworkString 59 | ]] 60 | MSync.modules[info.ModuleIdentifier].net = function() 61 | net.Receive( "my_message", function( len, pl ) 62 | if ( IsValid( pl ) and pl:IsPlayer() ) then 63 | print( "Message from " .. pl:Nick() .. " received. Its length is " .. len .. "." ) 64 | else 65 | print( "Message from server received. Its length is " .. len .. "." ) 66 | end 67 | end ) 68 | end 69 | 70 | --[[ 71 | Define ulx Commands and overwrite common ulx functions (module does not get loaded until ulx has fully been loaded) 72 | ]] 73 | MSync.modules[info.ModuleIdentifier].ulx = function() 74 | 75 | end 76 | 77 | --[[ 78 | Define hooks your module is listening on e.g. PlayerDisconnect 79 | ]] 80 | MSync.modules[info.ModuleIdentifier].hooks = function() 81 | hook.Add("initialize", "msync_sampleModule_init", function() 82 | 83 | end) 84 | end 85 | 86 | --[[ 87 | Define a function to run on the clients when the module gets disabled 88 | ]] 89 | MSync.modules[info.ModuleIdentifier].disable = function() 90 | 91 | end 92 | 93 | --[[ 94 | Return info ( Just for single module loading ) 95 | ]] 96 | return MSync.modules[info.ModuleIdentifier].info -------------------------------------------------------------------------------- /lua/msync/server/modules/sv_mrsync.lua: -------------------------------------------------------------------------------- 1 | MSync = MSync or {} 2 | MSync.modules = MSync.modules or {} 3 | MSync.modules.MRSync = MSync.modules.MRSync or {} 4 | local userTransaction = userTransaction or {} 5 | --[[ 6 | * @file sv_mrsync.lua 7 | * @package MySQL Rank Sync 8 | * @author Aperture Development 9 | * @license root_dir/LICENCE 10 | * @version 2.3.0 11 | ]] 12 | 13 | --[[ 14 | Define name, description and module identifier 15 | ]] 16 | MSync.modules.MRSync.info = { 17 | Name = "MySQL Rank Sync", 18 | ModuleIdentifier = "MRSync", 19 | Description = "Synchronise your ranks across your servers", 20 | Version = "2.3.0" 21 | } 22 | 23 | --[[ 24 | Define mysql table and additional functions that are later used 25 | ]] 26 | function MSync.modules.MRSync.init( transaction ) 27 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Exec: MRSync.init") 28 | transaction:addQuery( MSync.DBServer:query([[ 29 | CREATE TABLE IF NOT EXISTS `tbl_mrsync` ( 30 | `p_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 31 | `user_id` INT UNSIGNED NOT NULL, 32 | `rank` VARCHAR(15) NOT NULL, 33 | `server_group` INT UNSIGNED NOT NULL, 34 | FOREIGN KEY (server_group) REFERENCES tbl_server_grp(p_group_id), 35 | FOREIGN KEY (user_id) REFERENCES tbl_users(p_user_id), 36 | UNIQUE INDEX `user_UNIQUE` (`user_id`, `server_group`) 37 | ); 38 | ]] )) 39 | 40 | --[[ 41 | Description: Function to save a players rank using steamid and group name 42 | Arguments: 43 | - steamid [string] : The steamid of the user to be saved 44 | - group [string] : the group to be saved in combination with the steamid 45 | Returns: nothing 46 | ]] 47 | function MSync.modules.MRSync.saveRankByID(steamid, group) 48 | 49 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Exec: MRSync.saveRankByID Params: " .. steamid .. " " .. group) 50 | 51 | if MSync.modules.MRSync.settings.nosync[group] then MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Group \"" .. group .. "\" is set to No-Sync. Not sending data to the database"); return end; 52 | 53 | if string.len(group) > 15 then MSync.log(MSYNC_DBG_ERROR, "[MRSync] Groupname \"" .. group .. "\" is too long for MRSync! Please use rank names with max. 15 characters instead."); return end; 54 | 55 | local addUserRankQ = MSync.DBServer:prepare( [[ 56 | INSERT INTO `tbl_mrsync` (user_id, `rank`, server_group) 57 | SELECT * FROM ( 58 | SELECT tbl_users.p_user_id, ? AS newRank, tbl_server_grp.p_group_id 59 | FROM tbl_users, tbl_server_grp 60 | WHERE 61 | ( 62 | tbl_users.steamid=? AND tbl_users.steamid64=? 63 | ) 64 | AND 65 | tbl_server_grp.group_name=? 66 | ) AS dataQuery 67 | ON DUPLICATE KEY UPDATE `rank`=newRank; 68 | ]] ) 69 | addUserRankQ:setString(1, group) 70 | addUserRankQ:setString(2, steamid) 71 | addUserRankQ:setString(3, util.SteamIDTo64( steamid )) 72 | if not MSync.modules.MRSync.settings.syncall[group] then 73 | addUserRankQ:setString(4, MSync.settings.data.serverGroup) 74 | else 75 | addUserRankQ:setString(4, "allservers") 76 | end 77 | 78 | addUserRankQ.onError = function( q, err, sql ) 79 | if string.match( err, "^Column 'user_id' cannot be null$" ) then 80 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] User does not exist, creating user \"" .. steamid .. "\" and repeating"); 81 | MSync.mysql.addUserID(steamid) 82 | MSync.modules.MRSync.saveRankByID(steamid, group) 83 | else 84 | MSync.log(MSYNC_DBG_ERROR, MSync.formatString("\n------------------------------------\n[MRSync] SQL Error!\n------------------------------------\nPlease include this in a Bug report:\n\n$err\n\n------------------------------------\nDo not include this, this is for debugging only:\n\n$sql\n\n------------------------------------", {["err"] = err, ["sql"] = sql})) 85 | end 86 | end 87 | 88 | addUserRankQ:start() 89 | end 90 | 91 | --[[ 92 | Description: Function to validate user rank in DB is correct 93 | Arguments: 94 | - steamid [STRING] - the steamid of the user to validate 95 | - group [STRING] - the group of the user to validate 96 | ]] 97 | function MSync.modules.MRSync.validateData( steamid, group ) 98 | 99 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Exec: MRSync.validateData Param.: " .. steamid .. " " .. group); 100 | 101 | if MSync.modules.MRSync.settings.nosync[group] then MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Group \"" .. group .. "\" is set to No-Sync. Not sending data to the database"); return end; 102 | 103 | local removeOldRanksQ 104 | 105 | if not MSync.modules.MRSync.settings.syncall[group] then 106 | 107 | MSync.log(MSYNC_DBG_INFO, "[MRSync] Non-Syncall group, removing all \"allservers\" ranks from user"); 108 | 109 | removeOldRanksQ = MSync.DBServer:prepare( [[ 110 | DELETE FROM `tbl_mrsync` WHERE user_id=(SELECT p_user_id FROM tbl_users WHERE steamid=? AND steamid64=?) AND server_group=(SELECT p_group_id FROM tbl_server_grp WHERE group_name='allservers'); 111 | ]] ) 112 | removeOldRanksQ:setString(1, steamid) 113 | removeOldRanksQ:setString(2, util.SteamIDTo64(steamid)) 114 | 115 | removeOldRanksQ.onSuccess = function( q, data ) 116 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Data validation completed successfully, saving user"); 117 | MSync.modules.MRSync.saveRankByID(steamid, group) 118 | end 119 | else 120 | 121 | MSync.log(MSYNC_DBG_INFO, "[MRSync] Syncall group, removing all groups from user \"" .. steamid .. "\" that are not \"allservers\""); 122 | 123 | removeOldRanksQ = MSync.DBServer:prepare( [[ 124 | DELETE FROM `tbl_mrsync` WHERE user_id=(SELECT p_user_id FROM tbl_users WHERE steamid=? AND steamid64=?) AND server_group<>(SELECT p_group_id FROM tbl_server_grp WHERE group_name='allservers'); 125 | ]] ) 126 | removeOldRanksQ:setString(1, steamid) 127 | removeOldRanksQ:setString(2, util.SteamIDTo64(steamid)) 128 | 129 | removeOldRanksQ.onSuccess = function( q, data ) 130 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Data validation completed successfully, saving user"); 131 | MSync.modules.MRSync.saveRankByID(steamid, group) 132 | end 133 | end 134 | 135 | removeOldRanksQ.onError = function( q, err, sql ) 136 | if string.match( err, "^Column 'user_id' cannot be null$" ) then 137 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] User not found, creating user before trying again"); 138 | MSync.mysql.addUserID(steamid) 139 | MSync.modules.MRSync.saveRankByID(steamid, group) 140 | else 141 | MSync.log(MSYNC_DBG_ERROR, MSync.formatString("\n------------------------------------\n[MRSync] SQL Error!\n------------------------------------\nPlease include this in a Bug report:\n\n$err\n\n------------------------------------\nDo not include this, this is for debugging only:\n\n$sql\n\n------------------------------------", {["err"] = err, ["sql"] = sql})) 142 | end 143 | end 144 | 145 | removeOldRanksQ:start() 146 | end 147 | 148 | --[[ 149 | Description: Function to load a players rank 150 | Arguments: 151 | - ply [playerEntity] : The player to be loaded 152 | Returns: nothing 153 | ]] 154 | function MSync.modules.MRSync.loadRank(ply) 155 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Exec: MRSync.loadRank Param.:" .. ply:Nick()); 156 | local loadUserQ = MSync.DBServer:prepare( [[ 157 | SELECT `rank` FROM `tbl_mrsync` 158 | WHERE user_id=( 159 | SELECT p_user_id FROM tbl_users WHERE steamid=? AND steamid64=? 160 | ) AND (server_group=( 161 | SELECT p_group_id FROM tbl_server_grp WHERE group_name=? 162 | ) OR server_group=( 163 | SELECT p_group_id FROM tbl_server_grp WHERE group_name='allservers' 164 | )) 165 | LIMIT 1; 166 | ]] ) 167 | loadUserQ:setString(1, ply:SteamID()) 168 | loadUserQ:setString(2, ply:SteamID64()) 169 | loadUserQ:setString(3, MSync.settings.data.serverGroup) 170 | 171 | function loadUserQ.onData( q, data ) 172 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Got data for user \"" .. ply:Nick() .. "\". Rank: " .. data.rank); 173 | if not ULib.ucl.groups[data.rank] then 174 | MSync.log(MSYNC_DBG_ERROR, "[MRSync] Could not load rank " .. data.rank .. " for " .. ply:Nick() .. ". Rank does not exist on this server") 175 | return 176 | end 177 | 178 | if data.rank == ply:GetUserGroup() then return end; 179 | 180 | MSync.log(MSYNC_DBG_INFO, "[MRSync] Data for user \"" .. ply:Nick() .. "\" valid and user does not have the right group, changing to " .. data.rank); 181 | ply:SetUserGroup(data.rank) 182 | end 183 | 184 | function loadUserQ.onSuccess( q, data ) 185 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] loadUser query executed successfully"); 186 | if not data[1] then 187 | if ply:GetUserGroup() == "user" or MSync.modules.MRSync.settings.nosync[ply:GetUserGroup()] then return end 188 | 189 | MSync.log(MSYNC_DBG_INFO, "[MRSync] Assuming user \"" .. ply:Nick() .. "\" has been removed from rank, setting them to default") 190 | 191 | userTransaction[ply:SteamID64()] = true 192 | ULib.ucl.removeUser(ply:SteamID()) 193 | end 194 | end 195 | 196 | loadUserQ:start() 197 | end 198 | 199 | --[[ 200 | Description: Function to remove a user entirely from MRSync 201 | Arguments: 202 | - steamid [string] : The steamid of the user to be removed 203 | Returns: nothing 204 | ]] 205 | function MSync.modules.MRSync.removeRank(steamid) 206 | 207 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Exec: MRSync.removeRank Param.: " .. steamid); 208 | 209 | local removeUserRankQ = MSync.DBServer:prepare( [[ 210 | DELETE FROM `tbl_mrsync` WHERE 211 | user_id=(SELECT p_user_id FROM tbl_users WHERE steamid=? AND steamid64=?) AND 212 | ( 213 | server_group=(SELECT p_group_id FROM tbl_server_grp WHERE group_name='allservers') OR 214 | server_group=(SELECT p_group_id FROM tbl_server_grp WHERE group_name=?) 215 | ); 216 | ]] ) 217 | removeUserRankQ:setString(1, steamid) 218 | removeUserRankQ:setString(2, util.SteamIDTo64( steamid )) 219 | removeUserRankQ:setString(3, MSync.settings.data.serverGroup) 220 | 221 | removeUserRankQ:start() 222 | end 223 | 224 | --[[ 225 | Description: Function to load the MSync settings file 226 | Returns: true 227 | ]] 228 | function MSync.modules.MRSync.loadSettings() 229 | 230 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Exec: MRSync.loadSettings"); 231 | 232 | if not file.Exists("msync/mrsync.txt", "DATA") then 233 | MSync.modules.MRSync.settings = { 234 | nosync = { 235 | ["member"] = true 236 | }, 237 | syncall = { 238 | ["superadmin"] = true 239 | } 240 | } 241 | file.Write("msync/mrsync.txt", util.TableToJSON(MSync.modules.MRSync.settings, true)) 242 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] No config file, creating one now"); 243 | else 244 | MSync.modules.MRSync.settings = util.JSONToTable(file.Read("msync/mrsync.txt", "DATA")) 245 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Found config file, loading it now"); 246 | end 247 | 248 | return true 249 | end 250 | 251 | --[[ 252 | Description: Function to save the MSync settings to the settings file 253 | Returns: true if the settings file exists 254 | ]] 255 | function MSync.modules.MRSync.saveSettings() 256 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Exec: MRSync.saveSettings"); 257 | file.Write("msync/mrsync.txt", util.TableToJSON(MSync.modules.MRSync.settings, true)) 258 | return file.Exists("msync/mrsync.txt", "DATA") 259 | end 260 | 261 | --[[ 262 | Load settings when module finished loading 263 | ]] 264 | MSync.modules.MRSync.loadSettings() 265 | end 266 | 267 | --[[ 268 | Define net receivers and util.AddNetworkString 269 | ]] 270 | function MSync.modules.MRSync.net() 271 | 272 | --[[ 273 | Description: Function to send the mrsync settings to the client 274 | Arguments: 275 | player [player] - the player that wants to open the admin GUI 276 | Returns: nothing 277 | ]] 278 | util.AddNetworkString("msync.mrsync.sendSettingsPly") 279 | function MSync.modules.MRSync.sendSettings(ply) 280 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Exec: MRSync.sendSettings Param.: " .. ply:Nick()); 281 | net.Start("msync.mrsync.sendSettingsPly") 282 | net.WriteTable(MSync.modules.MRSync.settings) 283 | net.Send(ply) 284 | end 285 | 286 | --[[ 287 | Description: Net Receiver - Gets called when the client requests the settings table 288 | Returns: nothing 289 | ]] 290 | util.AddNetworkString("msync.mrsync.getSettings") 291 | net.Receive("msync.mrsync.getSettings", function(len, ply) 292 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Net: msync.mrsync.getSettings Ply.: " .. ply:Nick()); 293 | if not ply:query("msync.getSettings") then return end 294 | 295 | MSync.modules.MRSync.sendSettings(ply) 296 | end ) 297 | 298 | --[[ 299 | Description: Net Receiver - Gets called when the client requests the settings table 300 | Returns: nothing 301 | ]] 302 | util.AddNetworkString("msync.mrsync.sendSettings") 303 | net.Receive("msync.mrsync.sendSettings", function(len, ply) 304 | MSync.log(MSYNC_DBG_DEBUG, "[MRSync] Net: msync.mrsync.sendSettings Ply.: " .. ply:Nick()); 305 | if not ply:query("msync.sendSettings") then return end 306 | 307 | MSync.modules.MRSync.settings = net.ReadTable() 308 | MSync.modules.MRSync.saveSettings() 309 | end ) 310 | 311 | 312 | end 313 | 314 | --[[ 315 | Define ulx Commands and overwrite common ulx functions (module does not get loaded until ulx has fully been loaded) 316 | ]] 317 | function MSync.modules.MRSync.ulx() 318 | 319 | end 320 | 321 | --[[ 322 | Define hooks your module is listening on e.g. PlayerDisconnect 323 | ]] 324 | function MSync.modules.MRSync.hooks() 325 | 326 | -- Load rank on spawn 327 | hook.Add("PlayerInitialSpawn", "mrsync.H.loadRank", function(ply) 328 | MSync.log(MSYNC_DBG_INFO, "[MRSync] Loading user rank for \"" .. ply:Nick() .. "\""); 329 | MSync.modules.MRSync.loadRank(ply) 330 | end) 331 | 332 | -- Save rank on disconnect 333 | hook.Add("PlayerDisconnected", "mrsync.H.saveRank", function(ply) 334 | MSync.log(MSYNC_DBG_INFO, "[MRSync] Saving user rank for \"" .. ply:Nick() .. "\""); 335 | --MSync.modules.MRSync.saveRank(ply) 336 | MSync.modules.MRSync.validateData(ply:SteamID(), ply:GetUserGroup()) 337 | end) 338 | 339 | -- Save rank on GroupChange 340 | hook.Add("ULibUserGroupChange", "mrsync.H.saveRankOnUpdate", function(sid, _, _, new_group, _) 341 | MSync.log(MSYNC_DBG_INFO, "[MRSync] Rank changed for user \"" .. sid .. "\" updating it now"); 342 | --MSync.modules.MRSync.saveRankByID(sid, new_group) 343 | MSync.modules.MRSync.validateData(sid, new_group) 344 | end) 345 | 346 | -- Remove Rank on ULX Remove 347 | hook.Add("ULibUserRemoved", "mrsync.H.saveRankOnUpdate", function(sid) 348 | MSync.log(MSYNC_DBG_INFO, "[MRSync] User deletion detected for \"" .. sid .. "\""); 349 | if userTransaction[util.SteamIDTo64(sid)] then 350 | userTransaction[util.SteamIDTo64(sid)] = nil 351 | MSync.log(MSYNC_DBG_INFO, "[MRSync] User has already been removed from MRSync, aborting removal"); 352 | return 353 | end 354 | 355 | MSync.log(MSYNC_DBG_INFO, "[MRSync] User with ID \"" .. sid .. "\" was removed from ULX, removing from MRSync"); 356 | MSync.modules.MRSync.removeRank(sid) 357 | end) 358 | end 359 | 360 | --[[ 361 | Define a function to run on the server when the module gets disabled 362 | ]] 363 | MSync.modules.MRSync.disable = function() 364 | hook.Remove("PlayerInitialSpawn", "mrsync.H.loadRank") 365 | hook.Remove("PlayerDisconnected", "mrsync.H.saveRank") 366 | hook.Remove("ULibUserGroupChange", "mrsync.H.saveRankOnUpdate") 367 | hook.Remove("ULibUserRemoved", "mrsync.H.saveRankOnUpdate") 368 | end 369 | 370 | --[[ 371 | Return info ( Just for single module loading ) 372 | ]] 373 | return MSync.modules.MRSync.info -------------------------------------------------------------------------------- /lua/msync/server/modules/sv_samplemodule.lua: -------------------------------------------------------------------------------- 1 | MSync = MSync or {} 2 | MSync.modules = MSync.modules or {} 3 | --[[ 4 | * @file sv_samplemodule.lua 5 | * @package Sample Module 6 | * @author Aperture Development 7 | * @license root_dir/LICENCE 8 | * @version 1.0.1 9 | ]] 10 | 11 | --[[ 12 | Define name, description and module identifier 13 | ]] 14 | local info = { 15 | Name = "Sample Module", 16 | ModuleIdentifier = "SampleModule", 17 | Description = "A basic example module on how to create modules", 18 | Version = "1.0.1" 19 | } 20 | 21 | --[[ 22 | Prepare Module 23 | ]] 24 | MSync.modules[info.ModuleIdentifier] = MSync.modules[info.ModuleIdentifier] or {} 25 | MSync.modules[info.ModuleIdentifier].info = info 26 | 27 | --[[ 28 | Define mysql table and additional functions that are later used 29 | ]] 30 | MSync.modules[info.ModuleIdentifier].init = function( transaction ) 31 | transaction:addQuery( MSync.DBServer:query([[ 32 | CREATE TABLE IF NOT EXISTS `tbl_SampleModule` ( 33 | SampleData INT 34 | ); 35 | ]] )) 36 | 37 | MSync.modules[info.ModuleIdentifier].SampleFunction = function() 38 | return true 39 | end 40 | 41 | end 42 | 43 | --[[ 44 | Define net receivers and util.AddNetworkString 45 | ]] 46 | MSync.modules[info.ModuleIdentifier].net = function() 47 | net.Receive( "my_message", function( len, pl ) 48 | if ( IsValid( pl ) and pl:IsPlayer() ) then 49 | print( "Message from " .. pl:Nick() .. " received. Its length is " .. len .. "." ) 50 | else 51 | print( "Message from server received. Its length is " .. len .. "." ) 52 | end 53 | end ) 54 | end 55 | 56 | --[[ 57 | Define ulx Commands and overwrite common ulx functions (module does not get loaded until ulx has fully been loaded) 58 | ]] 59 | MSync.modules[info.ModuleIdentifier].ulx = function() 60 | 61 | end 62 | 63 | --[[ 64 | Define hooks your module is listening on e.g. PlayerDisconnect 65 | ]] 66 | MSync.modules[info.ModuleIdentifier].hooks = function() 67 | hook.Add("initialize", "msync_sampleModule_init", function() 68 | 69 | end) 70 | end 71 | 72 | --[[ 73 | Define a function to run on the server when the module gets disabled 74 | ]] 75 | MSync.modules[info.ModuleIdentifier].disable = function() 76 | 77 | end 78 | 79 | --[[ 80 | Return info ( Just for single module loading ) 81 | ]] 82 | return MSync.modules[info.ModuleIdentifier].info -------------------------------------------------------------------------------- /lua/msync/server/sv_hooks.lua: -------------------------------------------------------------------------------- 1 | MSync = MSync or {} 2 | MSync.mysql = MSync.mysql or {} 3 | MSync.net = MSync.net or {} 4 | MSync.loadedModules = MSync.loadedModules or {} 5 | --[[ 6 | Description: hook to initialize MSync 2 7 | Returns: nothing 8 | 9 | Somehow the hook never gets called and I can't fix that. 10 | ] 11 | hook.Add( "Initialize", "msync.initScript", function() 12 | MSync.func.loadSettings() 13 | 14 | --[[ 15 | Description: timer to prevent loading before ULX 16 | Returns: nothing 17 | ] 18 | timer.Create("msync.t.checkForULXandULib", 5, 0, function() 19 | if not ULX or not ULib then return end; 20 | 21 | timer.Remove("msync.t.checkForULXandULib") 22 | MSync.ulx.createPermissions() 23 | MSync.ulx.createCommands() 24 | MSync.mysql.initialize() 25 | end) 26 | end) 27 | ]] 28 | --[[ 29 | Description: Creates a entry to the database for every player that joins. 30 | Returns: nothing 31 | ]] 32 | hook.Add("PlayerInitialSpawn", "msync.createUser", function( ply ) 33 | MSync.mysql.addUser(ply) 34 | MSync.net.sendTable(ply, "modulestate", MSync.loadedModules) 35 | 36 | if ply:query("msync.openAdminGUI") then 37 | MSync.net.dbStatus(ply) 38 | end 39 | end) -------------------------------------------------------------------------------- /lua/msync/server/sv_init.lua: -------------------------------------------------------------------------------- 1 | MSync = MSync or {} 2 | MSync.net = MSync.net or {} 3 | MSync.mysql = MSync.mysql or {} 4 | MSync.modules = MSync.modules or {} 5 | MSync.settings = MSync.settings or {} 6 | MSync.func = MSync.func or {} 7 | MSync.ulx = MSync.ulx or {} 8 | MSync.loadedModules = MSync.loadedModules or {} 9 | 10 | --[[ 11 | Description: Function to load the server side files 12 | Returns: nothing 13 | ]] 14 | function MSync.func.loadServer() 15 | 16 | MSync.log(MSYNC_DBG_DEBUG, "Loading Server") 17 | 18 | include("msync/server/sv_net.lua") 19 | include("msync/server/sv_mysql.lua") 20 | include("msync/server/sv_modules.lua") 21 | include("msync/server/sv_hooks.lua") 22 | include("msync/server/sv_ulx.lua") 23 | 24 | MSync.func.loadSettings() 25 | 26 | timer.Create("msync.t.checkForULXandULib", 5, 0, function() 27 | if not ulx or not ULib then return end; 28 | 29 | MSync.log(MSYNC_DBG_DEBUG, "ULX Loaded, continuing startup") 30 | 31 | timer.Remove("msync.t.checkForULXandULib") 32 | MSync.ulx.createPermissions() 33 | MSync.ulx.createCommands() 34 | MSync.mysql.initialize() 35 | end) 36 | 37 | MSync.loadModules() 38 | 39 | local clientfiles, _ = file.Find("msync/client_gui/*.lua", "LUA") 40 | for k, v in pairs(clientfiles) do 41 | AddCSLuaFile("msync/client_gui/" .. v) 42 | MSync.log(MSYNC_DBG_DEBUG, "Added client Lua file: " .. v) 43 | end 44 | 45 | local clientmodules, _ = file.Find("msync/client_gui/modules/*.lua", "LUA") 46 | for k, v in pairs(clientmodules) do 47 | AddCSLuaFile("msync/client_gui/modules/" .. v) 48 | MSync.log(MSYNC_DBG_DEBUG, "Added client module file: " .. v) 49 | end 50 | end 51 | 52 | --[[ 53 | Description: Function to load the MSync settings file 54 | Returns: true 55 | ]] 56 | function MSync.func.loadSettings() 57 | MSync.log(MSYNC_DBG_INFO, "Loading Settings") 58 | if not file.Exists("msync/settings.txt", "DATA") then 59 | MSync.settings.data = { 60 | mysql = { 61 | host = "127.0.0.1", 62 | port = 3306, 63 | username = "root", 64 | password = "", 65 | database = "msync" 66 | }, 67 | enabledModules = { 68 | ["MRSync"] = true 69 | }, 70 | serverGroup = "allservers" 71 | } 72 | file.CreateDir("msync") 73 | file.Write("msync/settings.txt", util.TableToJSON(MSync.settings.data, true)) 74 | MSync.log(MSYNC_DBG_DEBUG, "Created new configuration") 75 | else 76 | MSync.settings.data = util.JSONToTable(file.Read("msync/settings.txt", "DATA")) 77 | 78 | if MSync.settings.data.EnabledModules and MSync.settings.data.DisabledModules then 79 | MSync.log(MSYNC_DBG_WARNING, "Old settings file found! Updating to new format") 80 | file.Delete( "msync/settings.txt" ) 81 | 82 | local oldSettings = table.Copy(MSync.settings.data) 83 | MSync.settings.data = { 84 | mysql = { 85 | host = oldSettings.mysql.Host, 86 | port = oldSettings.mysql.Port, 87 | username = oldSettings.mysql.Username, 88 | password = oldSettings.mysql.Password, 89 | database = oldSettings.mysql.Database 90 | }, 91 | enabledModules = { 92 | ["MRSync"] = true 93 | }, 94 | serverGroup = "allservers" 95 | } 96 | 97 | file.Write("msync/settings.txt", util.TableToJSON(MSync.settings.data, true)) 98 | MSync.log(MSYNC_DBG_WARNING, "Settings imported! Module settings cannot be ported and need to be re-done") 99 | end 100 | MSync.log(MSYNC_DBG_DEBUG, "Loaded found configuration") 101 | end 102 | 103 | return true 104 | end 105 | 106 | --[[ 107 | Description: Function to save the MSync settings to the settings file 108 | Returns: true if the settings file exists 109 | ]] 110 | function MSync.func.saveSettings() 111 | file.Write("msync/settings.txt", util.TableToJSON(MSync.settings.data, true)) 112 | 113 | MSync.log(MSYNC_DBG_INFO, "Saved configuration") 114 | 115 | return file.Exists("msync/settings.txt", "DATA") 116 | end 117 | 118 | --[[ 119 | Description: Function to get a table of the module informations 120 | Returns: table with Module informations 121 | ]] 122 | function MSync.func.getModuleInfos() 123 | local infoTable = {} 124 | 125 | MSync.log(MSYNC_DBG_DEBUG, "Getting module informations...") 126 | 127 | for k,v in pairs(MSync.modules) do 128 | infoTable[k] = v.info 129 | infoTable[k].state = MSync.settings.data.enabledModules[v.info.ModuleIdentifier] or false 130 | MSync.log(MSYNC_DBG_DEBUG, "[getModuleInfos] Got info for " .. k) 131 | end 132 | 133 | return infoTable 134 | end 135 | 136 | --[[ 137 | Description: Function to return settings without the MySQL password 138 | We have decided that its better to Re-Enter the password always, and not be able to see the MySQL password client side 139 | Returns: safe settings table 140 | ]] 141 | function MSync.func.getSafeSettings() 142 | local settings = table.Copy(MSync.settings.data) 143 | 144 | MSync.log(MSYNC_DBG_DEBUG, "Generating safe settings to be sent to the player") 145 | 146 | settings.mysql.password = nil 147 | 148 | return settings 149 | end -------------------------------------------------------------------------------- /lua/msync/server/sv_modules.lua: -------------------------------------------------------------------------------- 1 | MSync = MSync or {} 2 | MSync.mysql = MSync.mysql or {} 3 | MSync.settings = MSync.settings or {} 4 | MSync.modules = MSync.modules or {} 5 | MSync.loadedModules = MSync.loadedModules or {} 6 | 7 | --[[ 8 | Description: Loads all server side modules 9 | Returns: nothing 10 | ]] 11 | function MSync.loadModules() 12 | 13 | MSync.log(MSYNC_DBG_DEBUG, "Loading modules") 14 | 15 | local files, _ = file.Find("msync/server/modules/*.lua", "LUA") 16 | for k, v in pairs(files) do 17 | include("msync/server/modules/" .. v) 18 | MSync.log(MSYNC_DBG_DEBUG, "Found module: " .. v) 19 | end 20 | end 21 | 22 | --[[ 23 | Description: initializes all modules 24 | Returns: nothing 25 | ]] 26 | function MSync.initModules() 27 | 28 | MSync.log(MSYNC_DBG_DEBUG, "Initializing modules") 29 | 30 | MSync.mysql.dbstatus = false 31 | if MSync.DBServer then 32 | local initTransaction = MSync.DBServer:createTransaction() 33 | 34 | for k,v in pairs(MSync.modules) do 35 | if MSync.settings.data.enabledModules[v["info"].ModuleIdentifier] then 36 | v["init"](initTransaction) 37 | v["net"]() 38 | v["ulx"]() 39 | v["hooks"]() 40 | MSync.loadedModules[v["info"].ModuleIdentifier] = true 41 | MSync.net.sendModuleEnable( v["info"].ModuleIdentifier ) 42 | MSync.log(MSYNC_DBG_INFO, "[" .. v["info"]["Name"] .. "] Module loaded") 43 | end 44 | end 45 | 46 | function initTransaction.onSuccess() 47 | MSync.log(MSYNC_DBG_INFO, "Module querys have been completed successfully") 48 | hook.Call("MSyncModuleLoaded", nil, nil) 49 | MSync.mysql.dbstatus = true 50 | end 51 | 52 | function initTransaction.onError(tr, err) 53 | MSync.log(MSYNC_DBG_ERROR, "There has been a error while loading the module querys.\nPlease inform the Developer and send him this:\n" .. err) 54 | MSync.mysql.dbstatus = false 55 | end 56 | 57 | initTransaction:start() 58 | else 59 | MSync.log(MSYNC_DBG_ERROR, "No MySQL server connected, aborting module loading.") 60 | end 61 | end 62 | 63 | --[[ 64 | Description: Loads single modules 65 | Arguments: path to module 66 | Returns: nothing 67 | ]] 68 | function MSync.loadModule(path) 69 | local initTransaction = MSync.DBServer:createTransaction() 70 | local info = include(path) 71 | 72 | MSync.modules[info.ModuleIdentifier].init(initTransaction) 73 | MSync.modules[info.ModuleIdentifier].net() 74 | MSync.modules[info.ModuleIdentifier].ulx() 75 | MSync.modules[info.ModuleIdentifier].hooks() 76 | 77 | MSync.log(MSYNC_DBG_INFO, "[" .. MSync.modules[info.Name] .. "] Module loaded") 78 | 79 | function initTransaction.onSuccess() 80 | MSync.log(MSYNC_DBG_INFO, "Module query has been completed successfully") 81 | hook.Call("MSyncModuleLoaded", nil, info.ModuleIdentifier) 82 | --MSync.mysql[info.ModuleIdentifier].dbstatus = true 83 | end 84 | 85 | function initTransaction.onError(tr, err) 86 | MSync.log(MSYNC_DBG_ERROR, "There has been a error while loading the module querys.\nPlease inform the Developer and send him this:\n" .. err) 87 | --MSync.mysql[info.ModuleIdentifier].dbstatus = false 88 | end 89 | 90 | initTransaction:start() 91 | end 92 | 93 | --[[ 94 | Description: Enables a single already loaded clientside module 95 | Arguments: 96 | - module [string] - the module to be enabled 97 | Returns: nothing 98 | ]] 99 | function MSync.enableModule( module ) 100 | if MSync.modules[module] then 101 | MSync.log(MSYNC_DBG_DEBUG, "Module \"" .. module .. "\" enabled?: " .. tostring(MSync.settings.data.enabledModules[module])) 102 | if not MSync.settings.data.enabledModules[module] then 103 | if MSync.DBServer:status() == mysqloo.DATABASE_CONNECTED then 104 | local initTransaction = MSync.DBServer:createTransaction() 105 | 106 | MSync.modules[module].init(initTransaction) 107 | MSync.modules[module].net() 108 | MSync.modules[module].ulx() 109 | MSync.modules[module].hooks() 110 | 111 | function initTransaction.onSuccess() 112 | MSync.log(MSYNC_DBG_INFO, "[" .. MSync.modules[module]["info"]["Name"] .. "] Module loaded") 113 | MSync.net.sendModuleEnable( module ) 114 | hook.Call("MSyncModuleLoaded", nil, module) 115 | --MSync.mysql[module].dbstatus = true 116 | end 117 | 118 | function initTransaction.onError(tr, err) 119 | MSync.log(MSYNC_DBG_ERROR, "There has been a error while loading the module querys.\nPlease inform the Developer and send him this:\n" .. err) 120 | --MSync.mysql[module].dbstatus = false 121 | end 122 | 123 | initTransaction:start() 124 | else 125 | MSync.log(MSYNC_DBG_WARNING, "Cannot enable \"" .. module .. "\". Database isn't connected") 126 | end 127 | else 128 | MSync.log(MSYNC_DBG_WARNING, "Module \"" .. module .. "\" is already enabled") 129 | end 130 | else 131 | MSync.log(MSYNC_DBG_WARNING, "Cannot enable non-existant module \"" .. module .. "\"") 132 | end 133 | end 134 | 135 | --[[ 136 | Description: Disabled a single already loaded clientside module 137 | Arguments: 138 | - module [string] - the module to be disabled 139 | Returns: nothing 140 | ]] 141 | function MSync.disableModule( module ) 142 | if MSync.modules[module] then 143 | if MSync.settings.data.enabledModules[module] then 144 | if MSync.modules[module].disable then 145 | MSync.modules[module].disable() 146 | MSync.log(MSYNC_DBG_INFO, "[" .. MSync.modules[module]["info"]["Name"] .. "] Module disabled") 147 | MSync.net.sendModuleDisable( module ) 148 | else 149 | MSync.log(MSYNC_DBG_WARNING, "Cannot disable outdated module \"" .. module .. "\"") 150 | end 151 | else 152 | MSync.log(MSYNC_DBG_WARNING, "Module \"" .. module .. "\" is already disabled") 153 | end 154 | else 155 | MSync.log(MSYNC_DBG_WARNING, "Cannot disable non-existant module \"" .. module .. "\"") 156 | end 157 | end -------------------------------------------------------------------------------- /lua/msync/server/sv_mysql.lua: -------------------------------------------------------------------------------- 1 | MSync = MSync or {} 2 | MSync.net = MSync.net or {} 3 | MSync.mysql = MSync.mysql or {} 4 | MSync.settings = MSync.settings or {} 5 | MSync.func = MSync.func or {} 6 | 7 | --[[ 8 | Description: initializes the MySQL part 9 | Returns: nothing 10 | ]] 11 | function MSync.mysql.initialize() 12 | if (file.Exists( "bin/gmsv_mysqloo_linux.dll", "LUA" ) or file.Exists( "bin/gmsv_mysqloo_win32.dll", "LUA" ) or file.Exists( "bin/gmsv_mysqloo_linux64.dll", "LUA" ) or file.Exists( "bin/gmsv_mysqloo_win64.dll", "LUA" )) and MSync.settings.data.mysql then 13 | require("mysqloo") 14 | 15 | MSync.log(MSYNC_DBG_INFO, "Initializing database") 16 | 17 | MSync.DBServer = mysqloo.connect( 18 | MSync.settings.data.mysql.host, 19 | MSync.settings.data.mysql.username, 20 | MSync.settings.data.mysql.password, 21 | MSync.settings.data.mysql.database, 22 | tonumber(MSync.settings.data.mysql.port) -- Just to be sure it deffinetly is a number 23 | ) 24 | 25 | function MSync.DBServer.onConnected( db ) 26 | local initDatabase = MSync.DBServer:createTransaction() 27 | 28 | MSync.log(MSYNC_DBG_INFO, "Connected to database, running database preparation ( this is done at each startup )") 29 | 30 | initDatabase:addQuery(MSync.DBServer:query([[ 31 | CREATE TABLE IF NOT EXISTS `tbl_msyncdb_version` ( 32 | `version` INT UNSIGNED NOT NULL, 33 | `module_id` VARCHAR(25) NOT NULL, 34 | UNIQUE INDEX `module_UNIQUE` (`module_id`) 35 | ); 36 | ]] )) 37 | 38 | initDatabase:addQuery(MSync.DBServer:query( [[ 39 | CREATE TABLE IF NOT EXISTS `tbl_server_grp` ( 40 | `p_group_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 41 | `group_name` VARCHAR(15) NOT NULL, 42 | UNIQUE INDEX `group_UNIQUE` (`group_name`) 43 | ); 44 | ]] )) 45 | 46 | initDatabase:addQuery(MSync.DBServer:query( [[ 47 | INSERT INTO `tbl_server_grp` (group_name) 48 | SELECT * FROM (SELECT 'allservers' AS newGroup) AS dataQuery 49 | ON DUPLICATE KEY UPDATE group_name=newGroup; 50 | ]] )) 51 | 52 | initDatabase:addQuery(MSync.DBServer:query( [[ 53 | CREATE TABLE IF NOT EXISTS `tbl_msync_servers` ( 54 | `p_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 55 | `server_name` VARCHAR(75) NOT NULL, 56 | `options` VARCHAR(100) NOT NULL DEFAULT '[]', 57 | `ip` VARCHAR(15) NOT NULL, 58 | `port` VARCHAR(5) NOT NULL, 59 | `server_group` INT UNSIGNED NOT NULL, 60 | FOREIGN KEY (server_group) REFERENCES tbl_server_grp(p_group_id), 61 | UNIQUE INDEX `server_UNIQUE` (`ip`, `port`) 62 | ); 63 | ]] )) 64 | 65 | initDatabase:addQuery(MSync.DBServer:query( [[ 66 | CREATE TABLE IF NOT EXISTS `tbl_users` ( 67 | `p_user_id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 68 | `steamid` VARCHAR(20) NOT NULL, 69 | `steamid64` VARCHAR(17) NOT NULL, 70 | `nickname` VARCHAR(30) NOT NULL, 71 | `joined` DATETIME NOT NULL, 72 | UNIQUE INDEX `steamid_UNIQUE` (`steamid`), 73 | UNIQUE INDEX `steamid64_UNIQUE` (`steamid64`) 74 | ); 75 | ]] )) 76 | 77 | initDatabase:addQuery(MSync.DBServer:query( [[ 78 | INSERT INTO `tbl_users` (steamid, steamid64, nickname, joined) 79 | SELECT * FROM (SELECT 'STEAM_0:0:0', '76561197960265728', '(CONSOLE)' AS newUser, '2004-12-24 12:00:00') AS dataQuery 80 | ON DUPLICATE KEY UPDATE nickname=newUser; 81 | ]] )) 82 | 83 | function initDatabase.onSuccess() 84 | MSync.mysql.saveServer() 85 | MSync.initModules() 86 | MSync.log(MSYNC_DBG_INFO, "Database prepared") 87 | end 88 | 89 | function initDatabase.onError(tr, err) 90 | MSync.log(MSYNC_DBG_ERROR, "There has been a error while initializing the database.\nPlease inform the Developer and send him this:\n" .. err) 91 | end 92 | 93 | initDatabase:start() 94 | 95 | end 96 | 97 | function MSync.DBServer.onConnectionFailed( db, err ) 98 | MSync.log(MSYNC_DBG_ERROR, "There has been a error while loading the module querys.\nPlease inform the Developer and send him this:\n" .. err) 99 | end 100 | 101 | MSync.DBServer:connect() 102 | elseif not MSync.settings then 103 | MSync.log(MSYNC_DBG_ERROR, "Settings not found") 104 | else 105 | MSync.log(MSYNC_DBG_ERROR, "Could not locate MySQLoo") 106 | end 107 | end 108 | 109 | --[[ 110 | Description: Adds a user to the users table 111 | Arguments: player 112 | Returns: nothing 113 | ]] 114 | function MSync.mysql.addUser(ply) 115 | MSync.log(MSYNC_DBG_DEBUG, "Exec: addUser. Param.: " .. tostring(ply)) 116 | if not MSync.DBServer then MSync.log(MSYNC_DBG_DEBUG, "No Database connected yet. Please connect to a Database to be able to create users."); return end; 117 | 118 | local addUserQ = MSync.DBServer:prepare( [[ 119 | INSERT INTO `tbl_users` (steamid, steamid64, nickname, joined) 120 | SELECT * FROM (SELECT ? AS steamid, ? AS steamid64, ? AS newNick, ? AS joined) AS dataQuery 121 | ON DUPLICATE KEY UPDATE nickname=newNick; 122 | ]] ) 123 | 124 | local nickname = ply:Nick() 125 | if string.len(nickname) > 30 then 126 | nickname = string.sub( nickname, 1, 30 ) 127 | end 128 | 129 | addUserQ:setString(1, ply:SteamID()) 130 | addUserQ:setString(2, ply:SteamID64()) 131 | addUserQ:setString(3, nickname) 132 | addUserQ:setString(4, os.date("%Y-%m-%d %H:%M:%S", os.time())) 133 | 134 | function addUserQ.onSuccess() 135 | MSync.log(MSYNC_DBG_INFO, "User " .. ply:Nick() .. " successfully created") 136 | end 137 | 138 | function addUserQ.onError(q, err, sql) 139 | MSync.log(MSYNC_DBG_ERROR, "Failed to create user " .. ply:Nick() .. " !\nPlease report this to the developer: " .. err) 140 | end 141 | 142 | addUserQ:start() 143 | end 144 | 145 | --[[ 146 | Description: Adds a userid to the users table 147 | Arguments: 148 | - steamid [string] - the steamid of the player to be added 149 | - nickname [string] - OPTIONAL: the nickname of the user to be created 150 | Returns: nothing 151 | ]] 152 | function MSync.mysql.addUserID(steamid, nickname) 153 | MSync.log(MSYNC_DBG_DEBUG, "Exec: addUserID. Param.: " .. steamid .. " " .. (nickname or "")) 154 | if not MSync.DBServer then MSync.log(MSYNC_DBG_DEBUG, "No Database connected yet. Please connect to a Database to be able to create users."); return end; 155 | if not string.match( steamid, "^STEAM_[0-1]:[0-1]:[0-9]+$" ) then return end; 156 | 157 | nickname = nickname or "None Given" 158 | 159 | local addUserQ = MSync.DBServer:prepare( [[ 160 | INSERT INTO `tbl_users` (steamid, steamid64, nickname, joined) 161 | SELECT * FROM (SELECT ? AS steamid, ? AS steamid64, ? AS newNick, ? AS joined) AS dataQuery 162 | ON DUPLICATE KEY UPDATE nickname=newNick; 163 | ]] ) 164 | 165 | if string.len(nickname) > 30 then 166 | nickname = string.sub( nickname, 1, 30 ) 167 | end 168 | 169 | addUserQ:setString(1, steamid) 170 | addUserQ:setString(2, util.SteamIDTo64(steamid)) 171 | addUserQ:setString(3, nickname) 172 | addUserQ:setString(4, os.date("%Y-%m-%d %H:%M:%S", os.time())) 173 | 174 | function addUserQ.onSuccess() 175 | MSync.log(MSYNC_DBG_INFO, "User " .. steamid .. " successfully created") 176 | end 177 | 178 | function addUserQ.onError(q, err, sql) 179 | MSync.log(MSYNC_DBG_ERROR, "Failed to create user " .. steamid .. " !\nPlease report this to the developer: " .. err) 180 | end 181 | 182 | addUserQ:start() 183 | end 184 | 185 | --[[ 186 | Description: Function to print the MySQL informations to the console 187 | Returns: nothing 188 | ]] 189 | function MSync.mysql.getInfo() 190 | print("--Database Server Information--") 191 | print("Version: " .. MSync.DBServer:serverVersion()) 192 | print("Fancy Version: " .. MSync.DBServer:serverInfo()) 193 | print("Host Info: " .. MSync.DBServer:hostInfo()) 194 | end 195 | 196 | --[[ 197 | Description: Function to save the server date to the database 198 | Returns: nothing 199 | ]] 200 | function MSync.mysql.saveServer() 201 | 202 | local addServerGroup = MSync.DBServer:prepare( [[ 203 | INSERT INTO `tbl_server_grp` (group_name) 204 | SELECT * FROM (SELECT ? AS newGroup) AS dataQuery 205 | ON DUPLICATE KEY UPDATE group_name=newGroup; 206 | ]] ) 207 | addServerGroup:setString(1, MSync.settings.data.serverGroup) 208 | 209 | function addServerGroup.onSuccess() 210 | local addServer = MSync.DBServer:prepare( [[ 211 | INSERT INTO `tbl_msync_servers` (server_name, ip, `port`, server_group) 212 | SELECT * FROM ( 213 | SELECT ? AS newServerName, ? AS ip, ? AS `port`, tbl_server_grp.p_group_id AS newGroup 214 | FROM tbl_server_grp 215 | WHERE 216 | tbl_server_grp.group_name=? 217 | ) AS dataQuery 218 | ON DUPLICATE KEY UPDATE server_name=newServerName, server_group=newGroup; 219 | ]] ) 220 | 221 | local hostname = GetHostName() 222 | local gameAddress = string.Split(game.GetIPAddress(), ":") 223 | 224 | if string.len(hostname) > 75 then 225 | hostname = string.sub( hostname, 1, 75 ) 226 | MSync.log(MSYNC_DBG_WARNING, "Hostname too long, shorting it down to a max of 75 letters") 227 | end 228 | addServer:setString(1, hostname) 229 | addServer:setString(2, gameAddress[1]) 230 | addServer:setString(3, gameAddress[2]) 231 | addServer:setString(4, MSync.settings.data.serverGroup) 232 | 233 | function addServer.onSuccess() 234 | MSync.log(MSYNC_DBG_INFO, "Server saved to database") 235 | end 236 | 237 | function addServer.onError(q, err, sql) 238 | MSync.log(MSYNC_DBG_ERROR, "Failed to create server !\nPlease report this to the developer: " .. err) 239 | end 240 | 241 | addServer:start() 242 | end 243 | 244 | function addServerGroup.onError(q, err, sql) 245 | MSync.log(MSYNC_DBG_ERROR, "Failed to create server !\nPlease report this to the developer: " .. err) 246 | end 247 | 248 | addServerGroup:start() 249 | end 250 | -------------------------------------------------------------------------------- /lua/msync/server/sv_net.lua: -------------------------------------------------------------------------------- 1 | MSync = MSync or {} 2 | MSync.net = MSync.net or {} 3 | 4 | --[[ 5 | Description: Function to send a table to the client 6 | Arguments: 7 | player [player] - the player to send the table to 8 | identifier [string] - what kind of table you are sending to the client 9 | table [table] - the table you send 10 | Returns: nothing 11 | ]] 12 | function MSync.net.sendTable(ply, identifier, table) 13 | MSync.log(MSYNC_DBG_DEBUG, "Exec: net.sendTable. Param.: " .. tostring(ply) .. " " .. identifier .. " " .. tostring(table)) 14 | identifier = identifier or "settings" 15 | 16 | net.Start("msync.sendTable") 17 | net.WriteString(identifier) 18 | net.WriteTable(table) 19 | net.Send(ply) 20 | end 21 | util.AddNetworkString("msync.sendTable") 22 | 23 | --[[ 24 | Description: Function to send a text message to the client 25 | Arguments: 26 | player [player] - the player you want to send the message to 27 | state [string] - the state of the message, can be "info", "error", "advert" 28 | message [string] - the message you want to send to the client 29 | Returns: nothing 30 | ]] 31 | function MSync.net.sendMessage(ply, state, string) 32 | MSync.log(MSYNC_DBG_DEBUG, "Exec: net.sendMessage. Param.: " .. tostring(ply) .. " " .. state .. " " .. tostring(string)) 33 | state = state or "info" 34 | 35 | net.Start("msync.sendMessage") 36 | net.WriteString(state) 37 | net.WriteString(string) 38 | net.Send(ply) 39 | end 40 | util.AddNetworkString("msync.sendMessage") 41 | 42 | --[[ 43 | Description: Function to open the admin GUI on the client 44 | Arguments: 45 | player [player] - the player that wants to open the admin GUI 46 | Returns: nothing 47 | ]] 48 | function MSync.net.openAdminGUI(ply) 49 | MSync.log(MSYNC_DBG_DEBUG, "Exec: net.openAdminGUI. Param.: " .. tostring(ply)) 50 | net.Start("msync.openAdminGUI") 51 | net.Send(ply) 52 | end 53 | util.AddNetworkString("msync.openAdminGUI") 54 | 55 | --[[ 56 | Description: Function to send the database status to the client 57 | Arguments: 58 | player [player] - the player that wants to know the db status 59 | Returns: nothing 60 | ]] 61 | function MSync.net.dbStatus(ply) 62 | MSync.log(MSYNC_DBG_DEBUG, "Exec: net.dbStatus. Param.: " .. tostring(ply)) 63 | net.Start("msync.dbStatus") 64 | if MSync.DBServer then 65 | net.WriteBool(MSync.DBServer:status() == mysqloo.DATABASE_CONNECTED and true or false) 66 | else 67 | net.WriteBool(false) 68 | end 69 | net.Send(ply) 70 | end 71 | util.AddNetworkString("msync.dbStatus") 72 | 73 | --[[ 74 | Description: Function to enable a module on all clients 75 | Arguments: 76 | module [string] - the module to be enabled 77 | Returns: nothing 78 | ]] 79 | function MSync.net.sendModuleEnable( module ) 80 | MSync.log(MSYNC_DBG_DEBUG, "Exec: net.enableModule. Param.: " .. module) 81 | net.Start("msync.enableModule") 82 | net.WriteString(module) 83 | net.Broadcast() 84 | end 85 | util.AddNetworkString("msync.enableModule") 86 | 87 | --[[ 88 | Description: Function to disable a module on all clients 89 | Arguments: 90 | module [string] - the module to be disabled 91 | Returns: nothing 92 | ]] 93 | function MSync.net.sendModuleDisable( module ) 94 | MSync.log(MSYNC_DBG_DEBUG, "Exec: net.disableModule. Param.: " .. module) 95 | net.Start("msync.disableModule") 96 | net.WriteString(module) 97 | net.Broadcast() 98 | end 99 | util.AddNetworkString("msync.disableModule") 100 | 101 | --[[ 102 | Description: Net Receiver - Gets called when the client requests a table 103 | Returns: nothing 104 | ]] 105 | util.AddNetworkString("msync.getTable") 106 | net.Receive("msync.getTable", function(len, ply) 107 | MSync.log(MSYNC_DBG_DEBUG, "Net: msync.getTable. Ply.: " .. ply:Nick()) 108 | if not ply:query("msync.getTable") then return end 109 | 110 | local identifier = net.ReadString() 111 | MSync.net.sendTable(ply, identifier, MSync[identifier]) 112 | end ) 113 | 114 | --[[ 115 | Description: Net Receiver - Gets called when the client sends the settings table to the server 116 | Returns: nothing 117 | ]] 118 | util.AddNetworkString("msync.sendSettings") 119 | net.Receive("msync.sendSettings", function(len, ply) 120 | MSync.log(MSYNC_DBG_DEBUG, "Net: msync.sendSettings. Ply.: " .. ply:Nick()) 121 | if not ply:query("msync.sendSettings") then return end 122 | 123 | local password = MSync.settings.data.mysql.password 124 | MSync.settings.data = net.ReadTable() 125 | 126 | if not MSync.settings.data.mysql.password then 127 | MSync.settings.data.mysql.password = password 128 | end 129 | 130 | if type(MSync.settings.data.mysql.port) ~= number then 131 | MSync.settings.data.mysql.port = tonumber(MSync.settings.data.mysql.port) 132 | end 133 | 134 | MSync.func.saveSettings() 135 | end ) 136 | 137 | --[[ 138 | Description: Net Receiver - Gets called when the client requests the settings table 139 | Returns: nothing 140 | ]] 141 | util.AddNetworkString("msync.getSettings") 142 | net.Receive("msync.getSettings", function(len, ply) 143 | MSync.log(MSYNC_DBG_DEBUG, "Net: msync.getSettings. Ply.: " .. ply:Nick()) 144 | if not ply:query("msync.getSettings") then return end 145 | MSync.net.sendTable(ply, "settings", MSync.func.getSafeSettings()) 146 | end ) 147 | 148 | --[[ 149 | Description: Net Receiver - Gets called when the client requests the module table 150 | Returns: nothing 151 | ]] 152 | util.AddNetworkString("msync.getModules") 153 | net.Receive("msync.getModules", function(len, ply) 154 | MSync.log(MSYNC_DBG_DEBUG, "Net: msync.getModules. Ply.: " .. ply:Nick()) 155 | if not ply:query("msync.getModules") then return end 156 | 157 | MSync.net.sendTable(ply, "modules", MSync.func.getModuleInfos()) 158 | end ) 159 | 160 | --[[ 161 | Description: Net Receiver - Gets called when the client requests a module toggle 162 | Returns: nothing 163 | ]] 164 | util.AddNetworkString("msync.toggleModule") 165 | net.Receive("msync.toggleModule", function(len, ply) 166 | MSync.log(MSYNC_DBG_DEBUG, "Net: msync.toggleModule. Ply.: " .. ply:Nick()) 167 | if not ply:query("msync.toggleModule") then return end 168 | 169 | 170 | local ident = net.ReadString() 171 | local state = net.ReadString() 172 | if state == "Enable" then 173 | MSync.enableModule( ident ) 174 | MSync.settings.data.enabledModules[ident] = true 175 | elseif state == "Disable" then 176 | MSync.disableModule( ident ) 177 | MSync.settings.data.enabledModules[ident] = nil 178 | end 179 | MSync.func.saveSettings() 180 | MSync.net.sendMessage(ply, "info", state .. "d module " .. ident) 181 | end ) 182 | 183 | --[[ 184 | Description: Net Receiver - Gets called when the client requests db connection 185 | Returns: nothing 186 | ]] 187 | util.AddNetworkString("msync.connectDB") 188 | net.Receive("msync.connectDB", function(len, ply) 189 | MSync.log(MSYNC_DBG_DEBUG, "Net: msync.connectDB. Ply.: " .. ply:Nick()) 190 | if not ply:query("msync.connectDB") then return end 191 | 192 | if MSync.DBServer then 193 | if (MSync.DBServer:status() ~= mysqloo.DATABASE_CONNECTED) then 194 | MSync.mysql.initialize() 195 | else 196 | MSync.net.sendMessage(ply, "error", "The database is already connected!") 197 | MSync.log(MSYNC_DBG_DEBUG, "Aborted database connect because connection is already established") 198 | end 199 | else 200 | MSync.mysql.initialize() 201 | end 202 | end ) 203 | 204 | --[[ 205 | Description: Net Receiver - Gets called when the client requests the database status 206 | Returns: nothing 207 | ]] 208 | util.AddNetworkString("msync.connectionStatus") 209 | net.Receive("msync.connectionStatus", function(len, ply) 210 | MSync.log(MSYNC_DBG_DEBUG, "Net: msync.connectionStatus. Ply.: " .. ply:Nick()) 211 | if not ply:query("msync.getSettings") then return end 212 | MSync.net.dbStatus(ply) 213 | end ) 214 | -------------------------------------------------------------------------------- /lua/msync/server/sv_ulx.lua: -------------------------------------------------------------------------------- 1 | MSync = MSync or {} 2 | MSync.ulx = MSync.ulx or {} 3 | 4 | --[[ 5 | Description: Function to create the ULX permissions 6 | Returns: nothing 7 | ]] 8 | function MSync.ulx.createPermissions() 9 | MSync.log(MSYNC_DBG_DEBUG, "Creating ULX permissions") 10 | ULib.ucl.registerAccess("msync.getTable", "superadmin", "Allows player to get MSync tables", "MSync") 11 | ULib.ucl.registerAccess("msync.sendSettings", "superadmin", "Allows player to send settings to server", "MSync") 12 | ULib.ucl.registerAccess("msync.connectDB", "superadmin", "Allows player to connect the server to the database server", "MSync") 13 | ULib.ucl.registerAccess("msync.resetSettings", "superadmin", "Allows the player to reset the settings", "MSync") 14 | ULib.ucl.registerAccess("msync.loadModule", "superadmin", "Allows the player to load a module", "MSync") 15 | ULib.ucl.registerAccess("msync.reloadModules", "superadmin", "Allows the player to reload all modules", "MSync") 16 | ULib.ucl.registerAccess("msync.toggleModule", "superadmin", "Allows the player to enable/disable modules", "MSync" ) 17 | ULib.ucl.registerAccess("msync.getSettings", "superadmin", "Allows the player to get the server settings", "MSync" ) 18 | ULib.ucl.registerAccess("msync.getModules", "superadmin", "Allows the player to get the server settings", "MSync" ) 19 | end 20 | 21 | --[[ 22 | Description: Function to create the ULX commands 23 | Returns: nothing 24 | ]] 25 | function MSync.ulx.createCommands() 26 | MSync.log(MSYNC_DBG_DEBUG, "Creating ULX commands") 27 | function MSync.func.openAdminGUI(calling_ply) 28 | if not calling_ply:query("msync.openAdminGUI") then return end; 29 | if not IsValid(calling_ply) then return end; 30 | 31 | MSync.net.openAdminGUI(calling_ply) 32 | end 33 | local OpenAdminGUI = ulx.command( "MSync", "msync.openAdminGUI", MSync.func.openAdminGUI, "!msync" ) 34 | OpenAdminGUI:defaultAccess( ULib.ACCESS_SUPERADMIN ) 35 | OpenAdminGUI:help( "Opens MSync Settings." ) 36 | end 37 | --ucl.registerAccess("msync.", "superadmin", "", "MSync" ) 38 | -------------------------------------------------------------------------------- /lua/msync/sh_init.lua: -------------------------------------------------------------------------------- 1 | MSync = MSync or {} 2 | MSync.net = MSync.net or {} 3 | 4 | MSYNC_DBG_ERROR = 0 5 | MSYNC_DBG_WARNING = 1 6 | MSYNC_DBG_INFO = 2 7 | MSYNC_DBG_DEBUG = 3 8 | 9 | local debugLevels = { 10 | [MSYNC_DBG_ERROR] = { 11 | color = Color(255, 44, 44), 12 | prefix = "[MSync_ERROR]" 13 | }, 14 | [MSYNC_DBG_WARNING] = { 15 | color = Color(255, 160, 17), 16 | prefix = "[MSync_WARN]" 17 | }, 18 | [MSYNC_DBG_INFO] = { 19 | color = Color(255, 255, 255), 20 | prefix = "[MSync_INFO]" 21 | }, 22 | [MSYNC_DBG_DEBUG] = { 23 | color = Color(180, 180, 180), 24 | prefix = "[MSync_DEGUB]" 25 | } 26 | } 27 | 28 | --[[ 29 | MSync debug level convar 30 | ]] 31 | MSync.DebugCVar = CreateConVar( "msync_debug", 0, FCVAR_REPLICATED + FCVAR_ARCHIVE, "Set the MSync debug level. 0 = Error, 1 = Warning, 2 = Info, 3 = Debug", 0, 3 ) 32 | 33 | --[[ 34 | Description: MSync logging function, allowing log levels and formated console logs 35 | Arguments: 36 | - logLevel [number] - The log level this message requires to be sent. Valid Globals are: MSYNC_DBG_ERROR, MSYNC_DBG_WARNING, MSYNC_DBG_INFO and MSYNC_DBG_DEBUG 37 | - logMessage [string] - The log message to be sent into the console ( should Prefix the module like "[MBSync]...") 38 | Returns: 39 | - Nothing 40 | ]] 41 | MSync.log = function(logLevel, logMessage) 42 | if type(logLevel) ~= "number" then return end 43 | 44 | local DebugCvarValue = MSync.DebugCVar:GetInt() 45 | 46 | if DebugCvarValue >= logLevel then 47 | if type(logMessage) == "function" then 48 | logMessage = logMessage() 49 | end 50 | if debugLevels[logLevel] then 51 | MsgC(debugLevels[logLevel].color, debugLevels[logLevel].prefix .. " " .. logMessage .. "\n") 52 | else 53 | MsgC(Color(255, 255, 255), "[MSync_LOG] " .. logMessage .. "\n") 54 | end 55 | -- Feature(?): Log files? Client GUI log viewer? 56 | --file.Append( "msync/logs/msync_"..os.date("[]")..".log", os.date("[]") ) 57 | end 58 | end 59 | 60 | --[[ 61 | Description: MSync string format function, allows easy and fast formating of long strings 62 | Arguments: 63 | - str [string] - The string containing the variables formated like $ 64 | - tbl [table] - The table containing the variable name as key and the value as key value ( e.g. {["variable"] = "My first variable"}) 65 | Returns: 66 | - formatedString [string] - the string with all variables replaced 67 | ]] 68 | MSync.formatString = function(str, tbl) 69 | return function() 70 | for k,v in pairs(tbl) do 71 | str = string.Replace(str, "$" .. k, tostring(v)) 72 | end 73 | return str 74 | end 75 | end --------------------------------------------------------------------------------