├── .gitignore ├── DOCS.md ├── LICENSE ├── README.md ├── examples ├── byLink.js ├── ipv6.js └── sbx.js ├── ext └── ai.js ├── index.js ├── package.json └── src ├── api ├── index.js ├── server.js └── serverlist.js ├── client.js ├── conf.json ├── consts.js ├── game ├── index.js ├── player.js └── world.js ├── net ├── codec │ ├── coder.js │ ├── parser.js │ └── util.js └── index.js └── util.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | package-lock.json 3 | github/ 4 | .DS_Store -------------------------------------------------------------------------------- /DOCS.md: -------------------------------------------------------------------------------- 1 | ## Classes 2 | 3 |
4 |
API
5 |
6 |
Server
7 |
8 |
ServerListArray
9 |
10 |
Game
11 |
12 |
Player
13 |
14 |
World
15 |
16 |
UpdateParser
17 |
18 |
Socket
19 |
20 |
21 | 22 | ## Functions 23 | 24 |
25 |
encode(message)Uint8Array
26 |

Encodes data - fast talk v2

27 |
28 |
decode(packet)Array
29 |

Decodes data - fast talk v2

30 |
31 |
rotator(packet)
32 |

Generates a rotator around a packet

33 |
34 |
35 | 36 | ## Typedefs 37 | 38 |
39 |
GameServerData : Object
40 |

Server as defined by api status / endpoint

41 |
42 |
GameOptions : Object
43 |
44 |
SocketOptions : Object
45 |
46 |
47 | 48 | 49 | 50 | ## API 51 | **Kind**: global class 52 | 53 | * [API](#API) 54 | * [new API([allowCache])](#new_API_new) 55 | * [.fetch(endpoint)](#API+fetch) ⇒ Object 56 | * [.fetchServers()](#API+fetchServers) ⇒ [Promise.<ServerList>](#ServerList) 57 | * [.fetchClientCount()](#API+fetchClientCount) ⇒ Promise.<number> 58 | 59 | 60 | 61 | ### new API([allowCache]) 62 | 63 | | Param | Type | Default | Description | 64 | | --- | --- | --- | --- | 65 | | [allowCache] | boolean | true | Determines whether or not you allow request caching, defaults to `true` | 66 | 67 | 68 | 69 | ### apI.fetch(endpoint) ⇒ Object 70 | Attempts to fetch an endpoint, if the first root server isn't available, it'll attempt the next 71 | 72 | **Kind**: instance method of [API](#API) 73 | 74 | | Param | Type | Description | 75 | | --- | --- | --- | 76 | | endpoint | string | Endpoint it'll be request, part of the path | 77 | 78 | 79 | 80 | ### apI.fetchServers() ⇒ [Promise.<ServerList>](#ServerList) 81 | Fetches all servers and returns a server list object 82 | 83 | **Kind**: instance method of [API](#API) 84 | 85 | 86 | ### apI.fetchClientCount() ⇒ Promise.<number> 87 | Fetches the arras.io global client count 88 | 89 | **Kind**: instance method of [API](#API) 90 | 91 | 92 | ## Server 93 | **Kind**: global class 94 | 95 | * [Server](#Server) 96 | * [new Server(raw)](#new_Server_new) 97 | * _instance_ 98 | * [.clients](#Server+clients) : number 99 | * [.uptime](#Server+uptime) : number 100 | * [.online](#Server+online) : boolean 101 | * [.hash](#Server+hash) : string 102 | * [.mspt](#Server+mspt) : number 103 | * [.tps](#Server+tps) : number 104 | * [.host](#Server+host) : string 105 | * [.code](#Server+code) : string 106 | * [.gamemode](#Server+gamemode) : string 107 | * [.region](#Server+region) : string 108 | * [.provider](#Server+provider) : string 109 | * [.name](#Server+name) : string 110 | * _static_ 111 | * [.parseGamemode(code)](#Server.parseGamemode) ⇒ string 112 | * [.parseRegion(code)](#Server.parseRegion) ⇒ string 113 | * [.parseHost(code)](#Server.parseHost) ⇒ string 114 | * [.parseCode(code)](#Server.parseCode) ⇒ string 115 | 116 | 117 | 118 | ### new Server(raw) 119 | 120 | | Param | Type | Description | 121 | | --- | --- | --- | 122 | | raw | [GameServerData](#GameServerData) | Raw server from response | 123 | 124 | 125 | 126 | ### server.clients : number 127 | Total client count in the server 128 | 129 | **Kind**: instance property of [Server](#Server) 130 | **Read only**: true 131 | 132 | 133 | ### server.uptime : number 134 | Server uptime - in seconds 135 | 136 | **Kind**: instance property of [Server](#Server) 137 | **Read only**: true 138 | 139 | 140 | ### server.online : boolean 141 | Determines if the server is online 142 | 143 | **Kind**: instance property of [Server](#Server) 144 | **Read only**: true 145 | 146 | 147 | ### server.hash : string 148 | Server hash, used to retrieve link 149 | 150 | **Kind**: instance property of [Server](#Server) 151 | **Read only**: true 152 | 153 | 154 | ### server.mspt : number 155 | Milliseconds per tick 156 | 157 | **Kind**: instance property of [Server](#Server) 158 | **Read only**: true 159 | 160 | 161 | ### server.tps : number 162 | Ticks per second 163 | 164 | **Kind**: instance property of [Server](#Server) 165 | **Read only**: true 166 | 167 | 168 | ### server.host : string 169 | Server host / address, used for connection 170 | 171 | **Kind**: instance property of [Server](#Server) 172 | **Read only**: true 173 | 174 | 175 | ### server.code : string 176 | Raw server code 177 | 178 | **Kind**: instance property of [Server](#Server) 179 | **Read only**: true 180 | 181 | 182 | ### server.gamemode : string 183 | Server gamemodes, joined by a space 184 | 185 | **Kind**: instance property of [Server](#Server) 186 | **Read only**: true 187 | 188 | 189 | ### server.region : string 190 | Server region, not precise 191 | 192 | **Kind**: instance property of [Server](#Server) 193 | **Read only**: true 194 | 195 | 196 | ### server.provider : string 197 | Server provider, in short 198 | 199 | **Kind**: instance property of [Server](#Server) 200 | **Read only**: true 201 | 202 | 203 | ### server.name : string 204 | Server name, made of gamemodes, regions and server hosts 205 | 206 | **Kind**: instance property of [Server](#Server) 207 | **Read only**: true 208 | 209 | 210 | ### Server.parseGamemode(code) ⇒ string 211 | Parses a gamemode section code to gamemode names 212 | 213 | **Kind**: static method of [Server](#Server) 214 | 215 | | Param | Type | Description | 216 | | --- | --- | --- | 217 | | code | string | gamemode code, third element in the host-region-gamemode code | 218 | 219 | 220 | 221 | ### Server.parseRegion(code) ⇒ string 222 | Parses a region section code to region names 223 | 224 | **Kind**: static method of [Server](#Server) 225 | 226 | | Param | Type | Description | 227 | | --- | --- | --- | 228 | | code | string | region code, second element in the host-region-gamemode code | 229 | 230 | 231 | 232 | ### Server.parseHost(code) ⇒ string 233 | Parses a server host section code to server host names 234 | 235 | **Kind**: static method of [Server](#Server) 236 | 237 | | Param | Type | Description | 238 | | --- | --- | --- | 239 | | code | string | server host code, first element in the host-region-gamemode code | 240 | 241 | 242 | 243 | ### Server.parseCode(code) ⇒ string 244 | Parses all parts of the host-region-gamemode code 245 | 246 | **Kind**: static method of [Server](#Server) 247 | 248 | | Param | Type | Description | 249 | | --- | --- | --- | 250 | | code | code | host-region-gamemode code | 251 | 252 | 253 | 254 | ## ServerList ⇐ Array 255 | **Kind**: global class 256 | **Extends**: Array 257 | 258 | * [ServerList](#ServerList) ⇐ Array 259 | * [new ServerList(raw)](#new_ServerList_new) 260 | * [.get(hash)](#ServerList+get) ⇒ [Server](#Server) 261 | * [.filterByGamemode(...gamemodes)](#ServerList+filterByGamemode) ⇒ [Array.<Server>](#Server) 262 | * [.filterByRegion(region)](#ServerList+filterByRegion) ⇒ [Array.<Server>](#Server) 263 | * [.byHash(hash)](#ServerList+byHash) ⇒ [Server](#Server) 264 | 265 | 266 | 267 | ### new ServerList(raw) 268 | 269 | | Param | Type | Description | 270 | | --- | --- | --- | 271 | | raw | [Array.<GameServerData>](#GameServerData) | Raw server data - response from status/ | 272 | 273 | 274 | 275 | ### serverList.get(hash) ⇒ [Server](#Server) 276 | Selects server with the same hash 277 | 278 | **Kind**: instance method of [ServerList](#ServerList) 279 | 280 | | Param | Type | Description | 281 | | --- | --- | --- | 282 | | hash | string | Hash of selection | 283 | 284 | 285 | 286 | ### serverList.filterByGamemode(...gamemodes) ⇒ [Array.<Server>](#Server) 287 | Used to retrieve servers by their gamemode 288 | 289 | **Kind**: instance method of [ServerList](#ServerList) 290 | 291 | | Param | Type | Description | 292 | | --- | --- | --- | 293 | | ...gamemodes | string | Gamemode strings, to be looked for in the `name` of the server | 294 | 295 | 296 | 297 | ### serverList.filterByRegion(region) ⇒ [Array.<Server>](#Server) 298 | Retrieves all servers in a specific region 299 | 300 | **Kind**: instance method of [ServerList](#ServerList) 301 | 302 | | Param | Type | Description | 303 | | --- | --- | --- | 304 | | region | string | region of selection | 305 | 306 | 307 | 308 | ### serverList.byHash(hash) ⇒ [Server](#Server) 309 | Selects server with the same hash 310 | 311 | **Kind**: instance method of [ServerList](#ServerList) 312 | 313 | | Param | Type | Description | 314 | | --- | --- | --- | 315 | | hash | string | Hash of selection | 316 | 317 | 318 | 319 | ## Game 320 | **Kind**: global class 321 | 322 | * [Game](#Game) 323 | * [new Game([options])](#new_Game_new) 324 | * [.socket](#Game+socket) : [Socket](#Socket) 325 | * [.world](#Game+world) : [Socket](#Socket) 326 | * [.player](#Game+player) : [Socket](#Socket) 327 | * [.connect(server, [options])](#Game+connect) 328 | 329 | 330 | 331 | ### new Game([options]) 332 | 333 | | Param | Type | Description | 334 | | --- | --- | --- | 335 | | [options] | [GameOptions](#GameOptions) | Game creation options | 336 | 337 | 338 | 339 | ### game.socket : [Socket](#Socket) 340 | Core socket connection manager 341 | 342 | **Kind**: instance property of [Game](#Game) 343 | 344 | 345 | ### game.world : [Socket](#Socket) 346 | Core parser for leaderboards and entities 347 | 348 | **Kind**: instance property of [Game](#Game) 349 | 350 | 351 | ### game.player : [Socket](#Socket) 352 | Core player 353 | 354 | **Kind**: instance property of [Game](#Game) 355 | 356 | 357 | ### game.connect(server, [options]) 358 | **Kind**: instance method of [Game](#Game) 359 | 360 | | Param | Type | Description | 361 | | --- | --- | --- | 362 | | server | [Server](#Server) | Server to connect to | 363 | | [options] | [GameOptions](#GameOptions) | Game creation options | 364 | 365 | 366 | 367 | ## Player 368 | **Kind**: global class 369 | 370 | * [Player](#Player) 371 | * [new Player(world, socket)](#new_Player_new) 372 | * [.isAlive](#Player+isAlive) : boolean 373 | * [.isDead](#Player+isDead) : boolean 374 | * [.toggleShoot([shooting])](#Player+toggleShoot) 375 | * [.toggleRepel([repelling])](#Player+toggleRepel) 376 | * [.levelUp([levels])](#Player+levelUp) 377 | * [.upgradeStats(build)](#Player+upgradeStats) 378 | * [.upgradeTo(...path)](#Player+upgradeTo) 379 | * [.spawn(name, [party], [grecaptcha])](#Player+spawn) 380 | * [.talk(...data)](#Player+talk) 381 | * [.sendInput(x, y, flags)](#Player+sendInput) 382 | * [.moveTo(target, [y])](#Player+moveTo) 383 | 384 | 385 | 386 | ### new Player(world, socket) 387 | 388 | | Param | Type | 389 | | --- | --- | 390 | | world | [World](#World) | 391 | | socket | [Socket](#Socket) | 392 | 393 | 394 | 395 | ### player.isAlive : boolean 396 | **Kind**: instance property of [Player](#Player) 397 | **Read only**: true 398 | 399 | 400 | ### player.isDead : boolean 401 | **Kind**: instance property of [Player](#Player) 402 | **Read only**: true 403 | 404 | 405 | ### player.toggleShoot([shooting]) 406 | Toggles shooting 407 | 408 | **Kind**: instance method of [Player](#Player) 409 | 410 | | Param | Type | Description | 411 | | --- | --- | --- | 412 | | [shooting] | boolean | Set shooting, by default it toggles though | 413 | 414 | 415 | 416 | ### player.toggleRepel([repelling]) 417 | Toggles repelling 418 | 419 | **Kind**: instance method of [Player](#Player) 420 | 421 | | Param | Type | Description | 422 | | --- | --- | --- | 423 | | [repelling] | boolean | Set repelling, by default it toggles though | 424 | 425 | 426 | 427 | ### player.levelUp([levels]) 428 | Levels up the player 429 | 430 | **Kind**: instance method of [Player](#Player) 431 | 432 | | Param | Type | Default | Description | 433 | | --- | --- | --- | --- | 434 | | [levels] | number | 45 | Number of levels to level up | 435 | 436 | 437 | 438 | ### player.upgradeStats(build) 439 | Upgrades stats 440 | 441 | **Kind**: instance method of [Player](#Player) 442 | 443 | | Param | Type | 444 | | --- | --- | 445 | | build | string | 446 | 447 | **Example** 448 | ```js 449 | player.upgradeStats("2/2/2/7/7/7/8/7/0/0"); 450 | ``` 451 | 452 | 453 | ### player.upgradeTo(...path) 454 | Upgrades you to a tank - assumption is you are basic tank 455 | 456 | **Kind**: instance method of [Player](#Player) 457 | 458 | | Param | Type | Description | 459 | | --- | --- | --- | 460 | | ...path | string \| number | Tank path, list of names or numbers | 461 | 462 | 463 | 464 | ### player.spawn(name, [party], [grecaptcha]) 465 | Spawn into the game 466 | 467 | **Kind**: instance method of [Player](#Player) 468 | 469 | | Param | Type | Default | Description | 470 | | --- | --- | --- | --- | 471 | | name | string | | Name for spawn | 472 | | [party] | number | | Party code | 473 | | [grecaptcha] | string \| boolean | false | The grecaptcha token to connect with. Required in player count 30+ servers | 474 | 475 | 476 | 477 | ### player.talk(...data) 478 | Send data to the server - encoder 479 | 480 | **Kind**: instance method of [Player](#Player) 481 | 482 | | Param | Type | 483 | | --- | --- | 484 | | ...data | any | 485 | 486 | 487 | 488 | ### player.sendInput(x, y, flags) 489 | Sends an input / cmd packet 490 | 491 | **Kind**: instance method of [Player](#Player) 492 | 493 | | Param | Type | Description | 494 | | --- | --- | --- | 495 | | x | number | x pos | 496 | | y | number | y pos | 497 | | flags | number | bitwise input flags | 498 | 499 | 500 | 501 | ### player.moveTo(target, [y]) 502 | Sends a move to packet to a specific location 503 | 504 | **Kind**: instance method of [Player](#Player) 505 | 506 | | Param | Type | Description | 507 | | --- | --- | --- | 508 | | target | Object \| number | The target location | 509 | | target.x | number | | 510 | | target.y | number | | 511 | | [y] | number | The y pos, if used this way | 512 | 513 | 514 | 515 | ## World 516 | **Kind**: global class 517 | 518 | * [World](#World) 519 | * [new World(socket)](#new_World_new) 520 | * [.gamemode](#World+gamemode) : string 521 | * [.bases](#World+bases) : string 522 | * [.selfBases](#World+selfBases) : Object \| null 523 | * [.selfEnt](#World+selfEnt) : Object 524 | * [.topChamp](#World+topChamp) : Object 525 | * [.isDead](#World+isDead) : boolean 526 | * [.isAlive](#World+isAlive) : boolean 527 | * [.findById(id)](#World+findById) ⇒ Object \| null 528 | 529 | 530 | 531 | ### new World(socket) 532 | 533 | | Param | Type | 534 | | --- | --- | 535 | | socket | [Socket](#Socket) | 536 | 537 | 538 | 539 | ### world.gamemode : string 540 | Gamemode abbreviation 541 | 542 | **Kind**: instance property of [World](#World) 543 | **Read only**: true 544 | 545 | 546 | ### world.bases : string 547 | All bases on the map (not dom (I think)) 548 | 549 | **Kind**: instance property of [World](#World) 550 | **Read only**: true 551 | 552 | 553 | ### world.selfBases : Object \| null 554 | All bases of the player's team 555 | 556 | **Kind**: instance property of [World](#World) 557 | **Read only**: true 558 | 559 | 560 | ### world.selfEnt : Object 561 | **Kind**: instance property of [World](#World) 562 | **Read only**: true 563 | 564 | 565 | ### world.topChamp : Object 566 | **Kind**: instance property of [World](#World) 567 | **Read only**: true 568 | 569 | 570 | ### world.isDead : boolean 571 | **Kind**: instance property of [World](#World) 572 | **Read only**: true 573 | 574 | 575 | ### world.isAlive : boolean 576 | **Kind**: instance property of [World](#World) 577 | **Read only**: true 578 | 579 | 580 | ### world.findById(id) ⇒ Object \| null 581 | Finds entity in the game by their id 582 | 583 | **Kind**: instance method of [World](#World) 584 | **Returns**: Object \| null - Entity 585 | 586 | | Param | Type | Description | 587 | | --- | --- | --- | 588 | | id | number | id of specific entity | 589 | 590 | 591 | 592 | ## UpdateParser 593 | **Kind**: global class 594 | 595 | * [UpdateParser](#UpdateParser) 596 | * [new UpdateParser([doEntities])](#new_UpdateParser_new) 597 | * [.parse(packet)](#UpdateParser+parse) ⇒ Object 598 | 599 | 600 | 601 | ### new UpdateParser([doEntities]) 602 | 603 | | Param | Type | Default | Description | 604 | | --- | --- | --- | --- | 605 | | [doEntities] | boolean | true | Whether or not to parse entities | 606 | 607 | 608 | 609 | ### updateParser.parse(packet) ⇒ Object 610 | Parsed decoded update packet data 611 | 612 | **Kind**: instance method of [UpdateParser](#UpdateParser) 613 | **Returns**: Object - parsed data 614 | 615 | | Param | Type | Description | 616 | | --- | --- | --- | 617 | | packet | Array | decoded data | 618 | 619 | 620 | 621 | ## Socket 622 | **Kind**: global class 623 | 624 | * [Socket](#Socket) 625 | * [new Socket([options], [wsOptions])](#new_Socket_new) 626 | * [.accepted](#Socket+accepted) : Boolean 627 | * [.options](#Socket+options) : [SocketOptions](#SocketOptions) 628 | * [.server](#Socket+server) 629 | * [.ws](#Socket+ws) : Object 630 | * [.parsers](#Socket+parsers) 631 | * [.open(server)](#Socket+open) 632 | * [.close()](#Socket+close) 633 | * [.talk(...data)](#Socket+talk) 634 | 635 | 636 | 637 | ### new Socket([options], [wsOptions]) 638 | 639 | | Param | Type | Description | 640 | | --- | --- | --- | 641 | | [options] | [SocketOptions](#SocketOptions) | Options for the socket | 642 | | [wsOptions] | Object | Options, passed to the websocket | 643 | 644 | 645 | 646 | ### socket.accepted : Boolean 647 | Determines whether the player can spawn - after 'w' packet 648 | 649 | **Kind**: instance property of [Socket](#Socket) 650 | 651 | 652 | ### socket.options : [SocketOptions](#SocketOptions) 653 | **Kind**: instance property of [Socket](#Socket) 654 | **Read only**: true 655 | 656 | 657 | ### socket.server 658 | **Kind**: instance property of [Socket](#Socket) 659 | **Properties** 660 | 661 | | Name | Type | Description | 662 | | --- | --- | --- | 663 | | server | [Server](#Server) | Server of connection | 664 | 665 | 666 | 667 | ### socket.ws : Object 668 | **Kind**: instance property of [Socket](#Socket) 669 | **Read only**: true 670 | 671 | 672 | ### socket.parsers 673 | **Kind**: instance property of [Socket](#Socket) 674 | **Properties** 675 | 676 | | Name | Type | Description | 677 | | --- | --- | --- | 678 | | parsers | Object | Update and broadcast parsers | 679 | 680 | 681 | 682 | ### socket.open(server) 683 | Opens a socket to a server 684 | 685 | **Kind**: instance method of [Socket](#Socket) 686 | 687 | | Param | Type | 688 | | --- | --- | 689 | | server | [Server](#Server) | 690 | 691 | 692 | 693 | ### socket.close() 694 | Close the connection 695 | 696 | **Kind**: instance method of [Socket](#Socket) 697 | 698 | 699 | ### socket.talk(...data) 700 | Send data to the server - encoder 701 | 702 | **Kind**: instance method of [Socket](#Socket) 703 | 704 | | Param | Type | 705 | | --- | --- | 706 | | ...data | any | 707 | 708 | 709 | 710 | ## encode(message) ⇒ Uint8Array 711 | Encodes data - fast talk v2 712 | 713 | **Kind**: global function 714 | **Returns**: Uint8Array - encoded data 715 | 716 | | Param | Type | Description | 717 | | --- | --- | --- | 718 | | message | Array | Message data | 719 | 720 | 721 | 722 | ## decode(packet) ⇒ Array 723 | Decodes data - fast talk v2 724 | 725 | **Kind**: global function 726 | **Returns**: Array - Parsed data 727 | 728 | | Param | Type | Description | 729 | | --- | --- | --- | 730 | | packet | ArrayBuffer \| Uint8Array | Encoded data | 731 | 732 | 733 | 734 | ## rotator(packet) ⇒ 735 | Generates a rotator around a packet 736 | 737 | **Kind**: global function 738 | **Returns**: rotator 739 | 740 | | Param | Type | Description | 741 | | --- | --- | --- | 742 | | packet | Array | Array of data in any type | 743 | 744 | 745 | 746 | ## GameServerData : Object 747 | Server as defined by api status / endpoint 748 | 749 | **Kind**: global typedef 750 | **Properties** 751 | 752 | | Name | Type | Description | 753 | | --- | --- | --- | 754 | | clients | number | The total client count on the server | 755 | | uptime | number | The server's uptime in seconds | 756 | | online | boolean | Indicates if the server is online or not | 757 | | mspt | number | The milliseconds per tick, server speed check | 758 | | host | string | The host url / address, used for connection | 759 | | code | string | Raw server code, containing server provider-region-gamemode | 760 | | [hash] | string | The server's hash, used for the server link | 761 | 762 | 763 | 764 | ## GameOptions : Object 765 | **Kind**: global typedef 766 | **Properties** 767 | 768 | | Name | Type | Description | 769 | | --- | --- | --- | 770 | | socketOptions | Object | Passed to the socket | 771 | | wsOptions | Object | Passed to the ws | 772 | 773 | 774 | 775 | ## SocketOptions : Object 776 | **Kind**: global typedef 777 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | Interface to interact with arras.io api and game servers 635 | Copyright (C) 2021 ABC 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | arras-client Copyright (C) 2021 ABC 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # arras-client 2 | 3 | Interface to interact with arras.io api and game servers 4 | 5 | 6 | Requirements: 7 | - Node version v14 (may work for v13 but untested) 8 | -------------------------------------------------------------------------------- /examples/byLink.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | console.log('Connecting to server via link'); 4 | (async () => { 5 | const ArrasClient = require('..') 6 | 7 | const arras = new ArrasClient(); 8 | const servers = await arras.api.fetchServers() 9 | const server = servers.get('#oa'); // modifiable 10 | if (!server) { 11 | console.error('Invalid server') 12 | process.exit(0); 13 | } 14 | 15 | console.log('Connecting to https://arras.io/' + server.hash); 16 | 17 | const player = arras.game.connect(server); 18 | 19 | player.once('connected', async () => { 20 | 21 | console.log('Alive, and in game') 22 | 23 | await player.spawn('SBX Works', /* party id, so like 1239 (not link) */); 24 | 25 | player.levelUp(40); 26 | player.moveTo(0, 0); 27 | }); 28 | 29 | player.once('close', () => console.log('Socket closing')); 30 | 31 | player.on('kick', (msg) => { 32 | console.error('Being kicked, msg', msg) 33 | }) 34 | })(); 35 | -------------------------------------------------------------------------------- /examples/ipv6.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | console.log('Connecting to server with ipv6'); 4 | (async () => { 5 | const ArrasClient = require('..') 6 | 7 | const arras = new ArrasClient(); 8 | const servers = await arras.api.fetchServers() 9 | const server = servers.filterByGamemode('Sandbox') 10 | .filterByRegion('USA') 11 | .filter(server => server.clients === 0)[0] // empty sbxs only 12 | 13 | console.log('Connecting to https://arras.io/' + server.hash); 14 | 15 | const player = arras.game.connect(server, { 16 | wsOptions: { 17 | family: 6, 18 | localAddress: 'INSERT_IPV6_ADDRESS' 19 | } 20 | }); 21 | 22 | player.once('connected', async () => { 23 | 24 | console.log('Alive, and in game') 25 | 26 | await player.spawn('IPV6 Works',/* party id, so like 1239 (not link) */); 27 | 28 | player.levelUp(40); 29 | player.moveTo(0, 0); 30 | }); 31 | 32 | player.once('close', () => console.log('Socket closing')); 33 | 34 | player.on('kick', () => { 35 | console.error('Being kicked, msg', msg) 36 | }) 37 | })(); 38 | -------------------------------------------------------------------------------- /examples/sbx.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | console.log('Connecting to a random sbx server'); 4 | (async () => { 5 | const ArrasClient = require('..') 6 | 7 | const arras = new ArrasClient(); 8 | const servers = await arras.api.fetchServers() 9 | const server = servers.filterByGamemode('Sandbox') 10 | .filterByRegion('USA') 11 | .filter(server => server.clients === 0)[0] // empty sbxs only 12 | 13 | console.log('Connecting to https://arras.io/' + server.hash); 14 | 15 | const player = arras.game.connect(server); 16 | 17 | player.once('connected', async () => { 18 | 19 | console.log('Alive, and in game') 20 | 21 | await player.spawn('SBX Works', /* party id, so like 1239 (not link) */); 22 | 23 | player.levelUp(40); 24 | player.moveTo(0, 0); 25 | }); 26 | 27 | player.once('close', () => console.log('Socket closing')); 28 | 29 | player.on('kick', (msg) => { 30 | console.error('Being kicked, msg', msg) 31 | }) 32 | })(); 33 | -------------------------------------------------------------------------------- /ext/ai.js: -------------------------------------------------------------------------------- 1 | // Ponyo's ai 2 | /* 3 | 4 | Auto Aim 5 | 6 | Information required for arguments 7 | player { 8 | x: Number, 9 | y: Number 10 | } 11 | target: { 12 | x: Number, 13 | y: Number, 14 | vx: Number, 15 | vy: Number 16 | } 17 | bulletSpeed: Number 18 | 19 | */ 20 | function autoAim(player, target, bulletSpeed, type = "b") { 21 | 22 | // vector 23 | const direction = { 24 | x: (target.x - player.x), 25 | y: (target.y - player.y) 26 | }; 27 | const distance = Math.sqrt((direction.x ** 2) + (direction.y ** 2)); 28 | const radian = Math.atan2(direction.y, direction.x); 29 | const targetSpeed = Math.sqrt((target.vx ** 2) + (target.vy ** 2)); 30 | 31 | // ranch 32 | let time = 0.0; 33 | switch (type) { 34 | 35 | // type a 36 | case "a": { 37 | 38 | // ax^2 + bx + c = 0 39 | const a = ((target.vx ** 2) + (target.vy ** 2) - (bulletSpeed ** 2)); 40 | const b = (2 * (direction.x * target.vx + direction.y * target.vy)); 41 | const c = ((direction.x ** 2) + (direction.y ** 2)); 42 | 43 | // time for the bullet to reach the target 44 | time = Math.sqrt((b ** 2) - (4 * a * c)); 45 | if (!Number.isNaN(time)) { 46 | const times = new Array(2); 47 | times[0] = ((-b - time) / (2 * a)); 48 | times[1] = ((-b + time) / (2 * a)); 49 | switch (true) { 50 | case ((times[0] < 0) && (times[1] < 0)): { 51 | time = 0.0; 52 | break; 53 | } 54 | case (times[0] < 0): { 55 | time = times[1]; 56 | break; 57 | } 58 | case (times[1] < 0): { 59 | time = times[0]; 60 | break; 61 | } 62 | default: { 63 | time = (times[0] < times[1] ? times[0] : times[1]); 64 | break; 65 | } 66 | } 67 | } else { 68 | console.error("hit impossible (imaginary number)"); 69 | time = 0.0; 70 | } 71 | break; 72 | 73 | } 74 | 75 | // type b 76 | case "b": { 77 | time = (distance / (bulletSpeed * Math.sqrt(1 - ((targetSpeed / bulletSpeed * Math.sin(radian)) ** 2)) - (targetSpeed * Math.cos(radian)))); 78 | if (Number.isNaN(time) || (time < 0)) { 79 | console.error("hit impossible (imaginary number or negative number)"); 80 | time = 0.0; 81 | } 82 | break; 83 | } 84 | 85 | // unknown 86 | default: { 87 | console.error("why lol"); 88 | time = 0.0; 89 | break; 90 | } 91 | 92 | } 93 | 94 | // aim 95 | const input = { 96 | x: (direction.x + target.vx * time), 97 | y: (direction.y + target.vy * time) 98 | }; 99 | return { 100 | x: input.x, 101 | y: input.y 102 | }; 103 | 104 | } 105 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const ArrasClient = require('./src/client'); 2 | 3 | module.exports = ArrasClient -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "arrasclient", 3 | "version": "1.0.0", 4 | "description": "Interface to interact with arras.io api and game servers", 5 | "main": "index.js", 6 | "dependencies": { 7 | "node-fetch": "^2.6.1", 8 | "ws": "^7.4.4" 9 | }, 10 | "devDependencies": { 11 | "jsdoc": "^3.6.6", 12 | "jsdoc-to-markdown": "^7.0.1" 13 | }, 14 | "scripts": { 15 | "doc": "jsdoc2md \"src/**/*.js\" > DOCS.md" 16 | }, 17 | "repository": { 18 | "type": "git", 19 | "url": "github.com/ABCxFF/arras-client" 20 | }, 21 | "keywords": [ 22 | "arras", 23 | "websocket", 24 | "headless", 25 | "api" 26 | ], 27 | "author": "ABC", 28 | "license": "GPL-3.0" 29 | } 30 | -------------------------------------------------------------------------------- /src/api/index.js: -------------------------------------------------------------------------------- 1 | const ServerList = require('./serverlist'); 2 | 3 | const conf = require('../conf.json'); 4 | const fetch = require('node-fetch'); 5 | 6 | /** 7 | * Server as defined by api status/ endpoint 8 | * @typedef {Object} GameServerData 9 | * @property {number} clients The total client count on the server 10 | * @property {number} uptime The server's uptime in seconds 11 | * @property {boolean} online Indicates if the server is online or not 12 | * @property {number} mspt The milliseconds per tick, server speed check 13 | * @property {string} host The host url / address, used for connection 14 | * @property {string} code Raw server code, containing server provider-region-gamemode 15 | * @property {string} [hash] The server's hash, used for the server link 16 | */ 17 | 18 | 19 | class API { 20 | /** 21 | * @param {boolean} [allowCache] Determines whether or not you you allow request caching, defaults to `true` 22 | */ 23 | constructor(allowCache = true) { 24 | this._allowCache = allowCache; 25 | this._cache = {} 26 | } 27 | 28 | /** 29 | * Attempts to fetch an endpoint, if the first root server isn't available, it'll attempt the next 30 | * 31 | * @param {string} endpoint Endpoint it'll be request, part of the path 32 | * @returns {Object} 33 | * 34 | */ 35 | async fetch(endpoint) { 36 | // Retrieve from the cache if its active 37 | if (this._allowCache) { 38 | if (this._cache[endpoint] && this._cache[endpoint]) { 39 | if (Date.now() - this._cache[endpoint]._date < conf.api.cache_timeout) { 40 | const res = JSON.parse(JSON.stringify(this._cache[endpoint])) 41 | 42 | delete res._date; 43 | 44 | return res; 45 | } 46 | } 47 | } 48 | 49 | for (let root of conf.api.roots) { 50 | try { 51 | const res = await fetch(`https://${root}.d.nsrv.cloud:2222/` + endpoint).then(res => res.json()); 52 | 53 | if (this._allowCache) { 54 | this._cache[endpoint] = JSON.parse(JSON.stringify(res)); 55 | this._cache[endpoint]._date = Date.now() 56 | } 57 | 58 | return res; 59 | } catch { 60 | continue 61 | } 62 | } 63 | 64 | throw new Error('Arras api unavailable') 65 | } 66 | /** 67 | * Fetches all servers and returns a server list object 68 | * 69 | * @returns {Promise} 70 | */ 71 | fetchServers() { 72 | return this.fetch('status').then(res => { 73 | if (!res.ok) throw new Error('Arrasio server error - api NOT ok'); 74 | 75 | return new ServerList(Object.entries(res.status).map(([hash, server]) => ({ ...server, hash }))); 76 | }); 77 | } 78 | /** 79 | * Fetches the arrasio global client count 80 | * 81 | * @returns {Promise} 82 | */ 83 | fetchClientCount() { 84 | return this.fetch('clientCount').then(res => { 85 | if (!res.ok) throw new Error('Arrasio server error - api NOT ok'); 86 | 87 | return res.clients; 88 | }); 89 | } 90 | 91 | } 92 | 93 | module.exports = API; -------------------------------------------------------------------------------- /src/api/server.js: -------------------------------------------------------------------------------- 1 | const gamemodeTable = [ 2 | [{ 3 | id: "x", 4 | u: "Private" 5 | }], 6 | [{ 7 | id: "e", 8 | Hb: "word" 9 | }], 10 | [{ 11 | id: "w", 12 | Hb: "words" 13 | }], 14 | [{ 15 | id: "p", 16 | u: "Portal" 17 | }], 18 | [{ 19 | id: "o", 20 | u: "Open" 21 | }], 22 | [{ 23 | id: "m", 24 | u: "Maze", 25 | delay: !0, 26 | remove: "f" 27 | }], 28 | [{ 29 | id: "f", 30 | u: "FFA" 31 | }, 32 | { 33 | id: "d", 34 | u: "Duos" 35 | }, 36 | { 37 | id: "s", 38 | u: "Squads" 39 | }, 40 | { 41 | id: "1", 42 | u: "1 Team", 43 | advance: !0 44 | }, 45 | { 46 | id: "2", 47 | u: "2 Team", 48 | advance: !0, 49 | end: "2TDM" 50 | }, 51 | { 52 | id: "3", 53 | u: "3 Team", 54 | advance: !0, 55 | end: "3TDM" 56 | }, 57 | { 58 | id: "4", 59 | u: "4 Team", 60 | advance: !0, 61 | end: "4TDM" 62 | } 63 | ], 64 | [{ 65 | id: "d", 66 | u: "Domination" 67 | }, 68 | { 69 | id: "m", 70 | u: "Mothership", 71 | remove: "2" 72 | }, 73 | { 74 | id: "a", 75 | u: "Assault", 76 | remove: ["2", "m"] 77 | }, 78 | { 79 | id: "s", 80 | u: "Siege", 81 | remove: "1" 82 | }, 83 | { 84 | id: "t", 85 | u: "Tag", 86 | remove: ["o", "4"] 87 | }, 88 | { 89 | id: "p", 90 | u: "Pandemic", 91 | remove: ["o", "2"] 92 | }, 93 | { 94 | id: "z", 95 | u: "Sandbox" 96 | } 97 | ] 98 | ]; 99 | const regionTable = { 100 | xyz: ["Local", "Localhost", null], 101 | unk: ["Unknown", "Unknown", null], 102 | svx: ["US West", "Silicon Valley, CA, US", -7], 103 | lax: ["US West", "Los Angeles, CA, US", -7], 104 | dal: ["USA", "Dallas, TX, US", -5], 105 | kci: ["USA", 106 | "Kansas City, MO, US", -5 107 | ], 108 | vin: ["US East", "Vint Hill, VA, US", -4], 109 | mtl: ["US East", "Montreal, CA", -4], 110 | lon: ["Europe", "London, UK", 1], 111 | fra: ["Europe", "Frankfurt, DE", 2], 112 | fsn: ["Europe", "Falkenstein, DE", 2], 113 | sgp: ["Asia", "Singapore", 8] 114 | }; 115 | const hostTable = { 116 | z: ["Private", null], 117 | x: ["Local", null], 118 | glitch: ["Glitch", 10], 119 | buyvm: ["BuyVM", 15], 120 | extravm: ["ExtraVM", 40], 121 | hetzner: ["Hetzner", 50], 122 | ovh: ["OVH", 45], 123 | wsi: ["WSI", 50], 124 | vultr: ["Vultr", 30] 125 | } 126 | 127 | class Server { 128 | /** 129 | * @param {GameServerData} raw Raw server from response 130 | */ 131 | constructor(raw) { 132 | this._raw = raw; 133 | 134 | this._resolve(); 135 | } 136 | /** 137 | * Parses the server and stores static stuf 138 | * @private 139 | */ 140 | _resolve() { 141 | /** 142 | * Total client count in the server 143 | * @type {number} 144 | * @readonly 145 | */ 146 | this.clients = this._raw.clients; 147 | /** 148 | * Server uptime - in seconds 149 | * @type {number} 150 | * @readonly 151 | */ 152 | this.uptime = this._raw.uptime; 153 | /** 154 | * Determines if the server is online 155 | * @type {boolean} 156 | * @readonly 157 | */ 158 | this.online = this._raw.online; 159 | /** 160 | * Server Hash, used to retrieve link 161 | * @type {string} 162 | * @readonly 163 | */ 164 | this.hash = this._raw.hash; 165 | /** 166 | * Milliseconds per tick 167 | * @type {number} 168 | * @readonly 169 | */ 170 | this.mspt = this._raw.mspt; 171 | /** 172 | * Ticks per second 173 | * @type {number} 174 | * @readonly 175 | */ 176 | this.tps = 1000 / this._raw.mspt; 177 | /** 178 | * Server host / address, used for connection 179 | * @type {string} 180 | * @readonly 181 | */ 182 | this.host = this._raw.host; 183 | /** 184 | * Raw server code 185 | * @type {string} 186 | * @readonly 187 | */ 188 | this.code = this._raw.code; 189 | 190 | const [provider, region, gamemode] = this.code.split('-'); 191 | 192 | /** 193 | * Server gamemodes, joined by a space 194 | * @type {string} 195 | * @readonly 196 | */ 197 | this.gamemode = Server.parseGamemode(gamemode); 198 | /** 199 | * Server region, not precise 200 | * @type {string} 201 | * @readonly 202 | */ 203 | this.region = Server.parseRegion(region); 204 | /** 205 | * Server provider, in short 206 | * @type {string} 207 | * @readonly 208 | */ 209 | this.provider = Server.parseHost(provider); 210 | /** 211 | * Server name, made of gamemodes, regions and server hosts 212 | * @type {string} 213 | * @readonly 214 | */ 215 | this.name = [this.provider, this.region, this.gamemode].join(' - ') 216 | } 217 | 218 | /** 219 | * Parses a gamemode section code to gamemode names 220 | * 221 | * @param {string} code gamemode code, third element in the host-region-gamemode code 222 | * @returns {string} 223 | */ 224 | static parseGamemode(code) { 225 | if ("%" === code) return "Unknown"; 226 | let tags = []; 227 | let filter = []; 228 | let at = 0; 229 | 230 | for (const games of gamemodeTable) { 231 | for (const game of games) { 232 | if (game.id === code.charAt(at)) { 233 | if (Array.isArray(game.remove)) { 234 | filter.push.apply(filter, game.remove); 235 | } else if (game.remove) { 236 | filter.push(game.remove); 237 | } 238 | tags.push(Object.assign({}, game)); 239 | at++; 240 | break; 241 | } 242 | } 243 | } 244 | if (tags.length == 0) return "Unknown"; 245 | 246 | return tags.map((n, i, l) => l[Math.min(i + Math.pow(-1, i), l.length - 1)]).filter(({ id }) => !filter.includes(id)).map(data => data.u).join(" "); 247 | } 248 | /** 249 | * Parses a region section code to region names 250 | * 251 | * @param {string} code region code, second element in the host-region-gamemode code 252 | * @returns {string} 253 | */ 254 | static parseRegion(code) { 255 | return regionTable[code][0] 256 | } 257 | /** 258 | * Parses a server host section code to server host names 259 | * 260 | * @param {string} code server host code, first element in the host-region-gamemode code 261 | * @returns {string} 262 | */ 263 | static parseHost(code) { 264 | return hostTable[code][0] 265 | } 266 | /** 267 | * Parses all parts of the host-region-gamemode code 268 | * @param {code} code host-region-gamemode code 269 | * @returns {string} 270 | */ 271 | static parseCode(code) { 272 | const [host, region, gamemode] = code.split('-'); 273 | 274 | return [Server.parseHost(host), Server.parseRegion(region), Server.parseGamemode(gamemode)].join(' - ') 275 | } 276 | } 277 | 278 | module.exports = Server; 279 | -------------------------------------------------------------------------------- /src/api/serverlist.js: -------------------------------------------------------------------------------- 1 | const Server = require('./server') 2 | 3 | /** 4 | * @extends Array 5 | */ 6 | class ServerList extends Array { 7 | /** 8 | * @param {GameServerData[]} raw Raw server data - response from status/ 9 | */ 10 | constructor(raw) { 11 | super(...Array.from(raw).map(d => new Server(d))); 12 | this._raw = Array.from(raw); 13 | } 14 | /** 15 | * Selects server with the same hash 16 | * @param {string} hash Hash of selection 17 | * @returns {Server} 18 | */ 19 | get(hash) { 20 | return this.byHash(hash); 21 | } 22 | 23 | /** 24 | * Used to retrieve servers by their gamemode 25 | * @param {...string} gamemodes Gamemode strings, to be looked for in the `name` of the server 26 | * @returns {Server[]} 27 | */ 28 | filterByGamemode(...gamemodes) { 29 | return this.filter(server => { 30 | let gms = server.gamemode.split(" "); 31 | 32 | return gamemodes.every(g => gms.includes(g)); 33 | }); 34 | } 35 | /** 36 | * Retrieves all servers in a specific region 37 | * @param {string} region region of selection 38 | * @returns {Server[]} 39 | */ 40 | filterByRegion(region) { 41 | return this.filter(server => server.region === region) 42 | } 43 | 44 | /** 45 | * Selects server with the same hash 46 | * @param {string} hash Hash of selection 47 | * @returns {Server} 48 | */ 49 | byHash(hash) { 50 | return this.find(server => server.hash.slice(1) === hash.slice(hash.indexOf('#') === -1 ? 0 : 1)) 51 | } 52 | } 53 | 54 | module.exports = ServerList; -------------------------------------------------------------------------------- /src/client.js: -------------------------------------------------------------------------------- 1 | const API = require('./api'); 2 | const Game = require('./game'); 3 | 4 | class Client { 5 | constructor(options = {}) { 6 | /** 7 | * Game interactor 8 | * @type {Game} 9 | */ 10 | this.game = new Game(options.gameOptions || {}); 11 | /** 12 | * API interactor 13 | * @type {API} 14 | */ 15 | this.api = new API(options.apiOptions || {}); 16 | } 17 | } 18 | 19 | Client.Game = Game; 20 | Client.API = API; 21 | Client.Socket = require('./net') 22 | 23 | module.exports = Client; -------------------------------------------------------------------------------- /src/conf.json: -------------------------------------------------------------------------------- 1 | { 2 | "api": { 3 | "roots": [ 4 | "ak7oqfc2u4qqcu6i", "hq3p9viv64d0js08", "n15rqgeh01clbn7n" 5 | ], 6 | "cache_timeout": 1e6 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/consts.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/abcxff/arras-client/b39d772060490c54eaf8b813fac059b7148ca156/src/consts.js -------------------------------------------------------------------------------- /src/game/index.js: -------------------------------------------------------------------------------- 1 | const Player = require("./player"); 2 | const World = require('./world'); 3 | const Server = require('../api/server') 4 | const { configureDefault } = require('../util'); 5 | const EventEmitter = require("events"); 6 | const Socket = require("../net"); 7 | 8 | /** 9 | * @typedef {Object} GameOptions 10 | * @property {Object} socketOptions Passed to the socket 11 | * @property {Object} wsOptions Passed to the ws 12 | */ 13 | 14 | const DEFAULT_OPTIONS = { 15 | socketOptions: {}, 16 | wsOptions: {} 17 | } 18 | 19 | 20 | class Game extends EventEmitter { 21 | /** 22 | * @param {GameOptions} [options] Game creation options 23 | */ 24 | constructor(options = {}) { 25 | super(); 26 | this.options = configureDefault(options, DEFAULT_OPTIONS); 27 | } 28 | /** 29 | * @param {Server} server Server to connect to 30 | * @param {GameOptions} [options] Game creation options 31 | */ 32 | connect(server, options = this.options) { 33 | this.options = configureDefault(options, DEFAULT_OPTIONS); 34 | this.server = server; 35 | /** 36 | * Core socket connection manager 37 | * @type {Socket} 38 | */ 39 | this.socket = new Socket(this.options.socketOptions, this.options.wsOptions); 40 | this.socket.open(server); 41 | 42 | this.socket.on('death', () => this.emit('death')); 43 | this.socket.on('kick', (msg) => { 44 | this.emit('kick', msg) 45 | this.leave(); 46 | }); 47 | 48 | /** 49 | * Core parser for leaderboards and entities 50 | * @type {Socket} 51 | */ 52 | this.world = new World(this.socket); 53 | /** 54 | * Core player 55 | * @type {Socket} 56 | */ 57 | this.player = new Player(this.world, this.socket); 58 | 59 | return this.player 60 | } 61 | 62 | leave() { 63 | this.socket.close(); 64 | this.server = this.socket = this.world = this.player = null; 65 | } 66 | 67 | 68 | } 69 | 70 | module.exports = Game; -------------------------------------------------------------------------------- /src/game/player.js: -------------------------------------------------------------------------------- 1 | const EventEmitter = require("events"); 2 | const Socket = require("../net"); 3 | const World = require("./world"); 4 | 5 | class Player extends EventEmitter { 6 | /** 7 | * @param {World} world 8 | * @param {Socket} socket 9 | */ 10 | constructor(world, socket) { 11 | super(); 12 | 13 | this.world = world; 14 | this.socket = socket; 15 | this.tick = 0; // updated every update - used for internal stuff too 16 | this.input = { 17 | flags: 0, 18 | x: 0, 19 | y: 0 20 | } 21 | this.target = null 22 | 23 | 24 | this._listen(); 25 | } 26 | 27 | /** 28 | * @private 29 | */ 30 | _listen() { 31 | this.socket.on('update', (data) => { 32 | this.emit('update', data) 33 | this.tick++ 34 | if (this.target) this.moveTo(this.target) 35 | }) 36 | this.world.on('spawn', () => this.emit('spawn')) 37 | this.socket.on('accept', (data) => this.emit('connected', data)); 38 | this.socket.on('kick', (data) => this.emit('kick', data)); 39 | this.socket.on('death', (data) => this.emit('death', data)); 40 | this.socket.on('broadcast', (data) => this.emit('broadcast', data)); 41 | 42 | } 43 | /** 44 | * Toggles shooting 45 | * @param {boolean} [shooting] Set shooting, by default it toggles though 46 | */ 47 | toggleShoot(shooting = !(this.input.flags & 16)) { 48 | this.input.flags |= 16 * shooting 49 | } 50 | /** 51 | * Toggles repelling 52 | * @param {boolean} [repelling] Set repelling, by default it toggles though 53 | */ 54 | toggleRepel(shooting = !(this.input.flags & 64)) { 55 | this.input.flags |= 64 * shooting 56 | } 57 | 58 | /** 59 | * Levels up the player 60 | * @param {number} [levels] Amount of levels to level up 61 | */ 62 | levelUp(levels = 45) { 63 | for (let i = 0; i < levels; ++i) this.talk('L') 64 | } 65 | 66 | /** 67 | * Upgrades stats 68 | * @param {string} build 69 | * @example 70 | * player.upgradeStats("2/2/2/7/7/7/8/7/0/0"); 71 | */ 72 | upgradeStats(build) { 73 | build = build.split('/') 74 | for (let stat = 0; stat < build.length; ++stat) { 75 | let amount = build[stat]; 76 | for (let z = 0; z < amount; ++z) { 77 | this.talk("x", stat); 78 | } 79 | } 80 | } 81 | 82 | /** 83 | * Upgrades you to a tank - assumption is you are basic tank 84 | * @param {...string|number} path Tank path, list of names or numbers 85 | */ 86 | upgradeTo(...path) { 87 | if (!this.world.mockups) throw new RangeError('No mockups loaded. Internal error'); 88 | 89 | for (const t of path) { 90 | const id = typeof t === 'number' ? t : this.world.mockups.findIndex(def => def.name === t); 91 | if (id === -1) throw new TypeError('Invalid tank'); 92 | this.talk('U', id) 93 | } 94 | } 95 | 96 | /** 97 | * Spanw into the game 98 | * @param {string} name Name for spawn 99 | * @param {number} [party] Party code 100 | * @param {string|boolean} [grecaptcha] The grecaptcha token to connect with. Required in player count 30+ servers 101 | */ 102 | spawn(name, party = -1, grecaptcha = false) { 103 | if (!this.socket.accepted) { 104 | this.socket.once('accept', () => this.spawn(name, party, grecaptcha)) 105 | } 106 | if (grecaptcha) { 107 | return false 108 | this.talk('s', name, party, grecaptcha); 109 | } else this.talk('s', name, party); 110 | return new Promise(r => this.once('spawn', r)); 111 | } 112 | 113 | /** 114 | * Send data to the server - encoder 115 | * @param {...any} data 116 | */ 117 | talk(...data) { 118 | // replica of Socket.send 119 | this.socket.talk(...data) 120 | } 121 | 122 | /** 123 | * Sends an input / cmd packet 124 | * @param {number} x x pos 125 | * @param {number} y y pos 126 | * @param {number} flags bitwise input flags 127 | */ 128 | sendInput(x, y, flags) { 129 | this.input = { 130 | x, y, flags 131 | } 132 | this.talk('C', x, y, flags) 133 | } 134 | 135 | /** 136 | * @readonly 137 | * @type {boolean} 138 | */ 139 | get isAlive() { 140 | return this.world.isAlive 141 | } 142 | /** 143 | * @readonly 144 | * @type {boolean} 145 | */ 146 | get isDead() { 147 | return this.world.isDead 148 | } 149 | /** 150 | * Looks at a specific location 151 | * @param {Object|number} target The target location 152 | * @param {number} target.x 153 | * @param {number} target.y 154 | * @param {number} [y] The y pos, if used this way 155 | * @return {Player} 156 | */ 157 | lookAt(target, y=false) { 158 | if (!this.world.isAlive) return; 159 | if (y !== false) target = { 160 | x: target, 161 | y: y 162 | } 163 | 164 | this.sendInput((this.input.x = target.x - this.world.selfEnt.x), (this.input.y = target.y - this.world.selfEnt.y), this.input.flags); 165 | } 166 | 167 | /** 168 | * Sends a move to packet to a specific location 169 | * @param {Object|number} target The target location 170 | * @param {number} target.x 171 | * @param {number} target.y 172 | * @param {number} [y] The y pos, if used this way 173 | */ 174 | moveTo(target, y = false) { 175 | if (!this.world.isAlive) return; 176 | if (y !== false) target = { 177 | x: target, 178 | y: y 179 | } 180 | this.target = target; 181 | // Disclaimer, the following code may be ugly 182 | let dir = Math.round(Math.atan2(target.y - this.world.selfEnt.y, target.x - this.world.selfEnt.x) * 180 / Math.PI * (2 / 45)) * (45 / 2); 183 | dir = ((dir % 360) + 360) % 360; // keep positive in range 184 | this.input.flags &= ~15; 185 | return this.sendInput(this.input.x, this.input.y, (this.input.flags = ({ 186 | "0": 0b1000, // 1 = down, 2 = up, 4 = left, 8 = right, 187 | "22.5": 0b1000 ^ ((this.tick & 1) << 1), 188 | "45": 0b1010, 189 | "67.5": 0b0010 ^ ((this.tick & 1) << 3), 190 | "90": 0b0010, 191 | "112.5": 0b0010 ^ ((this.tick & 1) << 2), 192 | "135": 0b0110, 193 | "157.5": 0b0100 ^ ((this.tick & 1) << 1), 194 | "180": 0b0100, 195 | "202.5": 0b0100 ^ ((this.tick & 1) << 0), 196 | "225": 0b0101, 197 | "247.5": 0b0001 ^ ((this.tick & 1) << 2), 198 | "270": 0b0001, 199 | "292.5": 0b0001 ^ ((this.tick & 1) << 3), 200 | "315": 0b1001, 201 | "337.5": 0b1000 ^ ((this.tick & 1) << 0) 202 | })[dir.toString()] | this.input.flags)) 203 | } 204 | 205 | 206 | } 207 | 208 | module.exports = Player; 209 | -------------------------------------------------------------------------------- /src/game/world.js: -------------------------------------------------------------------------------- 1 | const EventEmitter = require("events"); 2 | const fetch = require("node-fetch"); 3 | const Socket = require("../net"); 4 | 5 | class World extends EventEmitter { 6 | /** 7 | * @param {Socket} socket 8 | */ 9 | constructor(socket) { 10 | super(); 11 | this.socket = socket; 12 | this._up = socket.parsers.update; 13 | this._bp = socket.parsers.broadcast; 14 | 15 | this._wasAlive = false; 16 | 17 | this.socket.on('packet', (packet) => this._handle(packet)) 18 | this._retrieveMockups(); 19 | } 20 | /** 21 | * @private 22 | * @async 23 | */ 24 | async _retrieveMockups() { 25 | if (!this.socket.server) return; 26 | 27 | this.mockups = await fetch(`https://${this.socket.server.host}/mockups.json`).then(res => res.json()) 28 | } 29 | 30 | /** 31 | * @type {string} Gamemode abbreviation 32 | * @readonly 33 | */ 34 | get gamemode() { 35 | if (this._gamemode) return this._gamemode; 36 | return this._gamemode = this._bp.globalMinimap.some((wall) => wall.type === 2 && wall.color === 16) ? 'maze' : this.room.zones.every(z => z.type === 'norm' || z.type === 'nest' || z.type === 'roid') ? 'open' : this.room.zones.some(z => z.type.includes('dom')) ? 'dom' : this.room.zones.some(z => z.type.includes('null')) ? 'siege' : this.room.zones.some(z => z.type.includes('port')) ? 'portal' : this.room.zones.some(z => z.type === 'bap4') ? '4tdm' : '2tdm'; 37 | } 38 | /** 39 | * @type {string} All bases on the map (not dom (I think)) 40 | * @readonly 41 | */ 42 | get bases() { 43 | if (this._bases) return this._bases; 44 | return this._bases = this.room.zones.filter(z => z.type.startsWith('bap')); 45 | } 46 | /** 47 | * @type {Object|null} All bases of the player's team 48 | * @readonly 49 | */ 50 | get selfBases() { 51 | if (this._up.player.party < 1) return null 52 | if (this._selfBases) return this._selfBases; 53 | return this._selfBases = this.room.zones.filter(z => z.type === 'bap' + this._up.player.party.toString()[0]); 54 | } 55 | /** 56 | * @type {Object} 57 | * @readonly 58 | */ 59 | get selfEnt() { 60 | return this.findById(this._up.player.body.id); 61 | } 62 | /** 63 | * @type {Object} 64 | * @readonly 65 | */ 66 | get topChamp() { return this._bp.leaderboard[0] } 67 | /** 68 | * @type {boolean} 69 | * @readonly 70 | */ 71 | get isDead() { return !this.selfEnt } 72 | /** 73 | * @type {boolean} 74 | * @readonly 75 | */ 76 | get isAlive() { return !!this.selfEnt } 77 | /** 78 | * Finds entity in the game by their id 79 | * @param {number} id id of specific entity 80 | * @returns {Object|null} Entity 81 | */ 82 | findById(id) { 83 | return this._up.entities.find(ent => ent.id === id) || null; 84 | } 85 | 86 | _handle(packet) { 87 | if (packet[0] === 'F') { 88 | this._wasAlive = false; 89 | } 90 | if (packet[0] === 'u') { 91 | if (!this._wasAlive && this.isAlive) this.emit('spawn') 92 | return this.emit('tick') 93 | } 94 | if (packet[0] !== 'R') return; 95 | const R = packet; 96 | const width = (R[5] - R[3]) / 9; 97 | const height = (R[4] - R[6]) / 9 98 | const zones = JSON.parse(R[7]).map((row, y) => row.map((type, x) => ({ 99 | type, 100 | width, 101 | height, 102 | x: x * width + R[3], 103 | y: y * height + R[4], 104 | mid: { 105 | x: x * width + R[3] + width / 2, 106 | y: y * height + R[4] - height / 2, 107 | } 108 | }))); 109 | 110 | 111 | this.room = { 112 | speed: R[2] 113 | } 114 | this.room.zones = zones.flat(); 115 | } 116 | } 117 | 118 | module.exports = World; -------------------------------------------------------------------------------- /src/net/codec/coder.js: -------------------------------------------------------------------------------- 1 | const u32 = new Uint32Array(1) 2 | const u16 = new Uint16Array(1) 3 | const c16 = new Uint8Array(u16.buffer) 4 | const c32 = new Uint8Array(u32.buffer) 5 | const f32 = new Float32Array(u32.buffer) 6 | /** 7 | * Encodes data - fast talk v2 8 | * @param {Array} message Message data 9 | * @returns {Uint8Array} encoded data 10 | */ 11 | function encode(message) { 12 | let headers = [] 13 | let headerCodes = [] 14 | let contentSize = 0 15 | let lastTypeCode = 0b1111 16 | let repeatTypeCount = 0 17 | for (let block of message) { 18 | let typeCode = 0 19 | if (block === 0 || block === false) { 20 | typeCode = 0b0000 21 | } else if (block === 1 || block === true) { 22 | typeCode = 0b0001 23 | } else if (typeof block === 'number') { 24 | if (!Number.isInteger(block) || block < -0x100000000 || block >= 0x100000000) { 25 | typeCode = 0b1000 26 | contentSize += 4 27 | } else if (block >= 0) { 28 | if (block < 0x100) { 29 | typeCode = 0b0010 30 | contentSize++ 31 | } else if (block < 0x10000) { 32 | typeCode = 0b0100 33 | contentSize += 2 34 | } else if (block < 0x100000000) { 35 | typeCode = 0b0110 36 | contentSize += 4 37 | } 38 | } else { 39 | if (block >= -0x100) { 40 | typeCode = 0b0011 41 | contentSize++ 42 | } else if (block >= -0x10000) { 43 | typeCode = 0b0101 44 | contentSize += 2 45 | } else if (block >= -0x100000000) { 46 | typeCode = 0b0111 47 | contentSize += 4 48 | } 49 | } 50 | } else if (typeof block === 'string') { 51 | let hasUnicode = false 52 | for (let i = 0; i < block.length; i++) { 53 | if (block.charAt(i) > '\xff') { 54 | hasUnicode = true 55 | } else if (block.charAt(i) === '\x00') { 56 | console.error('Null containing string', block) 57 | throw new Error('Null containing string') 58 | } 59 | } 60 | if (!hasUnicode && block.length <= 1) { 61 | typeCode = 0b1001 62 | contentSize++ 63 | } else if (hasUnicode) { 64 | typeCode = 0b1011 65 | contentSize += block.length * 2 + 2 66 | } else { 67 | typeCode = 0b1010 68 | contentSize += block.length + 1 69 | } 70 | } else { 71 | console.error('Unencodable data type', block) 72 | throw new Error('Unencodable data type') 73 | } 74 | headers.push(typeCode) 75 | if (typeCode === lastTypeCode) { 76 | repeatTypeCount++ 77 | } else { 78 | headerCodes.push(lastTypeCode) 79 | if (repeatTypeCount >= 1) { 80 | while (repeatTypeCount > 19) { 81 | headerCodes.push(0b1110) 82 | headerCodes.push(15) 83 | repeatTypeCount -= 19 84 | } 85 | if (repeatTypeCount === 1) 86 | headerCodes.push(lastTypeCode) 87 | else if (repeatTypeCount === 2) 88 | headerCodes.push(0b1100) 89 | else if (repeatTypeCount === 3) 90 | headerCodes.push(0b1101) 91 | else if (repeatTypeCount < 20) { 92 | headerCodes.push(0b1110) 93 | headerCodes.push(repeatTypeCount - 4) 94 | } 95 | } 96 | repeatTypeCount = 0 97 | lastTypeCode = typeCode 98 | } 99 | } 100 | headerCodes.push(lastTypeCode) 101 | if (repeatTypeCount >= 1) { 102 | while (repeatTypeCount > 19) { 103 | headerCodes.push(0b1110) 104 | headerCodes.push(15) 105 | repeatTypeCount -= 19 106 | } 107 | if (repeatTypeCount === 1) 108 | headerCodes.push(lastTypeCode) 109 | else if (repeatTypeCount === 2) 110 | headerCodes.push(0b1100) 111 | else if (repeatTypeCount === 3) 112 | headerCodes.push(0b1101) 113 | else if (repeatTypeCount < 20) { 114 | headerCodes.push(0b1110) 115 | headerCodes.push(repeatTypeCount - 4) 116 | } 117 | } 118 | headerCodes.push(0b1111) 119 | if (headerCodes.length % 2 === 1) 120 | headerCodes.push(0b1111) 121 | 122 | let output = new Uint8Array((headerCodes.length >> 1) + contentSize) 123 | for (let i = 0; i < headerCodes.length; i += 2) { 124 | let upper = headerCodes[i] 125 | let lower = headerCodes[i + 1] 126 | output[i >> 1] = (upper << 4) | lower 127 | } 128 | let index = headerCodes.length >> 1 129 | for (let i = 0; i < headers.length; i++) { 130 | let block = message[i] 131 | switch (headers[i]) { 132 | case 0b0000: 133 | case 0b0001: 134 | break 135 | case 0b0010: 136 | case 0b0011: 137 | output[index++] = block 138 | break 139 | case 0b0100: 140 | case 0b0101: 141 | u16[0] = block 142 | output.set(c16, index) 143 | index += 2 144 | break 145 | case 0b0110: 146 | case 0b0111: 147 | u32[0] = block 148 | output.set(c32, index) 149 | index += 4 150 | break 151 | case 0b1000: 152 | f32[0] = block 153 | output.set(c32, index) 154 | index += 4 155 | break 156 | case 0b1001: 157 | { 158 | let byte = block.length === 0 ? 0 : block.charCodeAt(0) 159 | output[index++] = byte 160 | } 161 | break 162 | case 0b1010: 163 | for (let i = 0; i < block.length; i++) { 164 | output[index++] = block.charCodeAt(i) 165 | } 166 | output[index++] = 0 167 | break 168 | case 0b1011: 169 | for (let i = 0; i < block.length; i++) { 170 | let charCode = block.charCodeAt(i) 171 | output[index++] = charCode & 0xff 172 | output[index++] = charCode >> 8 173 | } 174 | output[index++] = 0 175 | output[index++] = 0 176 | break 177 | } 178 | } 179 | 180 | return output 181 | } 182 | /** 183 | * Decodes data - fast talk v2 184 | * @param {ArrayBuffer|Uint8Array} packet Encoded data 185 | * @returns {Array} Parsed data 186 | */ 187 | function decode(packet) { 188 | let data = new Uint8Array(packet) 189 | if (data[0] >> 4 !== 0b1111) 190 | return null 191 | 192 | let headers = [] 193 | let lastTypeCode = 0b1111 194 | let index = 0 195 | let consumedHalf = true 196 | while (true) { 197 | if (index >= data.length) 198 | return null 199 | let typeCode = data[index] 200 | 201 | if (consumedHalf) { 202 | typeCode &= 0b1111 203 | index++ 204 | } else { 205 | typeCode >>= 4 206 | } 207 | consumedHalf = !consumedHalf 208 | 209 | if ((typeCode & 0b1100) === 0b1100) { 210 | if (typeCode === 0b1111) { 211 | if (consumedHalf) 212 | index++ 213 | break 214 | } 215 | 216 | let repeat = typeCode - 10 // 0b1100 - 2 217 | if (typeCode === 0b1110) { 218 | if (index >= data.length) 219 | return null 220 | let repeatCode = data[index] 221 | 222 | if (consumedHalf) { 223 | repeatCode &= 0b1111 224 | index++ 225 | } else { 226 | repeatCode >>= 4 227 | } 228 | consumedHalf = !consumedHalf 229 | 230 | repeat += repeatCode 231 | } 232 | 233 | for (let i = 0; i < repeat; i++) 234 | headers.push(lastTypeCode) 235 | } else { 236 | headers.push(typeCode) 237 | lastTypeCode = typeCode 238 | } 239 | } 240 | 241 | let output = [] 242 | for (let header of headers) { 243 | switch (header) { 244 | case 0b0000: 245 | output.push(0) 246 | break 247 | case 0b0001: 248 | output.push(1) 249 | break 250 | case 0b0010: 251 | output.push(data[index++]) 252 | break 253 | case 0b0011: 254 | output.push(data[index++] - 0x100) 255 | break 256 | case 0b0100: 257 | c16[0] = data[index++] 258 | c16[1] = data[index++] 259 | output.push(u16[0]) 260 | break 261 | case 0b0101: 262 | c16[0] = data[index++] 263 | c16[1] = data[index++] 264 | output.push(u16[0] - 0x10000) 265 | break 266 | case 0b0110: 267 | c32[0] = data[index++] 268 | c32[1] = data[index++] 269 | c32[2] = data[index++] 270 | c32[3] = data[index++] 271 | output.push(u32[0]) 272 | break 273 | case 0b0111: 274 | c32[0] = data[index++] 275 | c32[1] = data[index++] 276 | c32[2] = data[index++] 277 | c32[3] = data[index++] 278 | output.push(u32[0] - 0x100000000) 279 | break 280 | case 0b1000: 281 | c32[0] = data[index++] 282 | c32[1] = data[index++] 283 | c32[2] = data[index++] 284 | c32[3] = data[index++] 285 | output.push(f32[0]) 286 | break 287 | case 0b1001: 288 | { 289 | let byte = data[index++] 290 | output.push(byte === 0 ? '' : String.fromCharCode(byte)) 291 | } 292 | break 293 | case 0b1010: 294 | { 295 | let string = '' 296 | let byte = 0 297 | while (byte = data[index++]) { 298 | string += String.fromCharCode(byte) 299 | } 300 | output.push(string) 301 | } 302 | break 303 | case 0b1011: 304 | { 305 | let string = '' 306 | let byte = 0 307 | while (byte = data[index++] | (data[index++] << 8)) { 308 | string += String.fromCharCode(byte) 309 | } 310 | output.push(string) 311 | } 312 | break 313 | } 314 | } 315 | 316 | return output 317 | } 318 | module.exports = { encode, decode } -------------------------------------------------------------------------------- /src/net/codec/parser.js: -------------------------------------------------------------------------------- 1 | const rotator = require('./util') 2 | 3 | class BroadcastParser { 4 | constructor() { 5 | this.leaderboard = []; 6 | this.teamMinimap = []; 7 | this.globalMinimap = []; 8 | } 9 | 10 | /** 11 | * Parsed decoded broadcast packet data 12 | * @param {Array} packet decoded data 13 | * @returns {Object} parsed data 14 | */ 15 | parse(packet) { 16 | const rot = rotator(packet); 17 | 18 | if (rot.nex() !== 'b') throw new TypeError('Invalid packet header; expected packet `b`'); 19 | 20 | this._array(rot, () => { 21 | const del = rot.nex(); 22 | 23 | this.globalMinimap.remove(this.globalMinimap.findIndex(({ id }) => id === del)); 24 | }); 25 | 26 | this._array(rot, () => { 27 | const dot = { 28 | id: rot.nex(), 29 | type: rot.nex(), 30 | x: rot.nex(), 31 | y: rot.nex(), 32 | color: rot.nex(), 33 | size: rot.nex() 34 | }; 35 | 36 | let index = this.globalMinimap.findIndex(({ id }) => id === dot.id); 37 | if (index === -1) index = this.globalMinimap.length; 38 | 39 | this.globalMinimap[index] = dot; 40 | }); 41 | 42 | this._array(rot, () => { 43 | const del = rot.nex(); 44 | 45 | this.teamMinimap.remove(this.teamMinimap.findIndex(({ id }) => id === del)); 46 | }); 47 | 48 | this._array(rot, () => { 49 | const dot = { 50 | id: rot.nex(), 51 | x: rot.nex(), 52 | y: rot.nex(), 53 | size: rot.nex() 54 | }; 55 | 56 | let index = this.teamMinimap.findIndex(({ id }) => id === dot.id); 57 | if (index === -1) index = this.teamMinimap.length; 58 | 59 | this.teamMinimap[index] = dot; 60 | }); 61 | 62 | this._array(rot, () => { 63 | const del = rot.nex(); 64 | 65 | this.leaderboard.remove(this.leaderboard.findIndex(({ id }) => id === del)); 66 | }); 67 | 68 | this._array(rot, () => { 69 | const champ = { 70 | id: rot.nex(), 71 | score: rot.nex(), 72 | index: rot.nex(), 73 | name: rot.nex(), 74 | color: rot.nex(), 75 | barColor: rot.nex() 76 | }; 77 | 78 | let index = this.leaderboard.findIndex(({ id }) => id === champ.id); 79 | if (index === -1) index = this.leaderboard.length; 80 | 81 | this.leaderboard[index] = champ; 82 | }); 83 | 84 | this.leaderboard.sort((c1, c2) => c2.score - c1.score); 85 | 86 | return this; 87 | } 88 | 89 | /** 90 | * @private 91 | */ 92 | _array(rot, read, length = rot.nex()) { 93 | const out = Array(Math.max(0, length)); 94 | 95 | for (let i = 0; i < length; ++i) out[i] = read.call(this, i, rot); 96 | 97 | return out; 98 | } 99 | } 100 | 101 | class UpdateParser { 102 | /** 103 | * @param {boolean} [doEntities] Whether or not to parse entities 104 | */ 105 | constructor(doEntities = true) { 106 | this.camera = { x: null, y: null, vx: null, vy: null, fov: null }; 107 | this.now = 0; 108 | this.player = { 109 | fps: 1, 110 | body: { 111 | type: null, 112 | color: null, 113 | id: null, 114 | }, 115 | score: null, 116 | points: null, 117 | upgrades: [], 118 | stats: [], 119 | skills: null, 120 | accel: null, 121 | top: null, 122 | party: null 123 | } 124 | this.entities = doEntities ? [] : false; 125 | } 126 | /** 127 | * Parsed decoded update packet data 128 | * @param {Array} packet decoded data 129 | * @returns {Object} parsed data 130 | */ 131 | parse(packet) { 132 | const rot = rotator(packet); 133 | 134 | if (rot.nex() !== 'u') throw new TypeError('Invalid packet header; expected packet `u`'); 135 | 136 | this.now = rot.nex(); 137 | 138 | const version = this.now === 0 ? 2 : 1; 139 | 140 | this.camera.x = rot.nex(); 141 | this.camera.y = rot.nex(); 142 | this.camera.fov = rot.nex(); 143 | this.camera.vx = rot.nex(); 144 | this.camera.vy = rot.nex(); 145 | 146 | const flags = rot.nex(); 147 | if (flags & 0x0001) this.player.fps = rot.nex(); 148 | if (flags & 0x0002) { 149 | this.player.body.type = rot.nex(); 150 | this.player.body.color = rot.nex(); 151 | this.player.body.id = rot.nex(); 152 | } 153 | if (flags & 0x0004) this.player.score = rot.nex(); 154 | if (flags & 0x0008) this.player.points = rot.nex(); 155 | if (flags & 0x0010) this.player.upgrades = Array(Math.max(0, rot.nex())).fill(-1).map(() => rot.nex()); 156 | if (flags & 0x0020) this.player.stats = Array(30).fill(0).map(() => rot.nex()); 157 | if (flags & 0x0040) { 158 | // Thank you Ponyo 159 | const result = parseInt(rot.nex(), 36); 160 | 161 | this.player.skills = [ 162 | (result / 0x1000000000 & 15), 163 | (result / 0x0100000000 & 15), 164 | (result / 0x0010000000 & 15), 165 | (result / 0x0001000000 & 15), 166 | (result / 0x0000100000 & 15), 167 | (result / 0x0000010000 & 15), 168 | (result / 0x0000001000 & 15), 169 | (result / 0x0000000100 & 15), 170 | (result / 0x0000000010 & 15), 171 | (result / 0x0000000001 & 15) 172 | ] 173 | } 174 | if (flags & 0x0080) this.player.accel = rot.nex(); 175 | if (flags & 0x0100) this.player.top = rot.nex(); 176 | if (flags & 0x0200) this.player.party = rot.nex(); 177 | if (flags & 0x0400) this.player.speed = rot.nex(); 178 | 179 | if (version === 2 && this.entities !== false) { 180 | this._parseEnts(rot) 181 | } else if (version !== 2 && this.entities !== false) { 182 | this.entities = false; 183 | console.error('Invalid version, expected version 2. Disabling entities'); 184 | } 185 | return this; 186 | } 187 | /** 188 | * @private 189 | */ 190 | _table(rot, read) { 191 | const out = []; 192 | for (let id = rot.nex(); id !== -1; id = rot.nex()) { 193 | out[out.length] = read.call(this, id, rot) 194 | } 195 | return out 196 | } 197 | /** 198 | * @private 199 | */ 200 | _parseEnts(rot) { 201 | if (rot.nex() !== -1) return console.warn('uhhhh-cancelling', rot.arr); 202 | 203 | // deletes 204 | this._table(rot, (id) => { 205 | const index = this.entities.findIndex(ent => ent.id === id); 206 | if (index === -1) { 207 | return console.warn('Possible desync, deletion of non existant entity ' + id, this.entities.findIndex(ent => ent.id2 === id), JSON.stringify(this.entities)); 208 | } 209 | this.entities[index] = this.entities[this.entities.length - 1] 210 | --this.entities.length; 211 | }); 212 | // update / creations 213 | this._table(rot, (id) => { 214 | let index = this.entities.findIndex(ent => ent.id === id) 215 | if (index === -1) this.entities[index = this.entities.length] = { id }; 216 | 217 | const ent = this.entities[index]; 218 | this._parseEnt(ent, rot) 219 | }); 220 | } 221 | /** 222 | * @private 223 | */ 224 | _parseEnt(ent, rot) { 225 | // if (ent === undefined) ent = {}; 226 | const flags = rot.nex(); 227 | if (!ent) console.log(this.entities.length, rot.get(rot.i - 1)); 228 | if (flags & 0x0001) { 229 | let { x: lastX, y: lastY } = ent; 230 | ent.x = rot.nex() * 0.0625; 231 | ent.y = rot.nex() * 0.0625; 232 | if (typeof lastX !== 'undefined') { 233 | ent.vx = (ent.x - lastX); 234 | ent.vy = (ent.y - lastY); 235 | } else ent.vx = ent.vy = 0; 236 | } 237 | if (flags & 0x0002) ent.facing = rot.nex() * (360 / 256); // degrees instead of radians 238 | if (flags & 0x0004) ent.flags = rot.nex(); 239 | if (flags & 0x0008) ent.health = rot.nex() / 255; 240 | if (flags & 0x0010) ent.shield = Math.max(0, rot.nex() / 255); 241 | if (flags & 0x0020) ent.alpha = rot.nex() / 255; 242 | if (flags & 0x0040) ent.size = rot.nex() * 0.0625; 243 | if (flags & 0x0080) ent.score = rot.nex(); 244 | if (flags & 0x0100) ent.name = rot.nex(); 245 | if (flags & 0x0200) ent.id2 = rot.nex(); 246 | if (flags & 0x0400) ent.color = rot.nex(); 247 | if (flags & 0x0800) ent.layer = rot.nex(); 248 | if (flags & 0x1000) { 249 | if (!ent.guns) ent.guns = [] 250 | 251 | this._table(rot, (index) => { 252 | const flag = rot.nex(); 253 | if (!ent.guns[index]) ent.guns[index] = {}; 254 | if (flag & 1) ent.guns[index].time = rot.nex(); 255 | if (flag & 2) ent.guns[index].power = Math.sqrt(rot.nex()) / 20; 256 | }); 257 | } 258 | if (flags & 0x2000) { 259 | if (!ent.turrets) ent.turrets = []; 260 | 261 | ent.turrets = this._table(rot, (index) => { 262 | let i = ent.turrets.findIndex(ent => ent.index === index) 263 | if (i === -1) ent.turrets[i = ent.turrets.length] = { index }; 264 | const turret = ent.turrets[i]; 265 | 266 | return this._parseEnt(turret, rot); 267 | }); 268 | } 269 | 270 | return ent; 271 | } 272 | } 273 | 274 | 275 | module.exports = { BroadcastParser, UpdateParser } 276 | -------------------------------------------------------------------------------- /src/net/codec/util.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Generates a rotator around a packet 3 | * @param {Array} packet Array of data in any type 4 | * @returns rotator 5 | */ 6 | function rotator(packet) { 7 | return { 8 | i: 0, 9 | arr: packet, 10 | get(index) { 11 | return packet[index]; 12 | }, 13 | set(index, value) { 14 | return (packet[index] = value); 15 | }, 16 | nex() { 17 | if (this.i === this.arr.length) { 18 | console.error(new Error('End reached'), this.arr) 19 | return -1; 20 | } 21 | return packet[this.i++]; 22 | }, 23 | }; 24 | } 25 | Array.prototype.remove = function (index) { 26 | if (index === this.length - 1) return this.pop(); 27 | this[index] = this.pop(); 28 | } 29 | 30 | module.exports = rotator; -------------------------------------------------------------------------------- /src/net/index.js: -------------------------------------------------------------------------------- 1 | const EventEmitter = require('events') 2 | const WebSocket = require('ws'); 3 | const { configureDefault } = require('../util'); 4 | 5 | const { UpdateParser, BroadcastParser } = require('./codec/parser'); 6 | const coder = require('./codec/coder'); 7 | /** 8 | * @typedef {Object} SocketOptions 9 | */ 10 | 11 | const DEFAULT_OPTIONS = { 12 | 13 | } 14 | 15 | class Socket extends EventEmitter { 16 | /** 17 | * @param {SocketOptions} [options] Options for the socket 18 | * @param {Object} [wsOptions] Options, passed to the websocket 19 | */ 20 | constructor(options = {}, wsOptions = {}) { 21 | super() 22 | this.options = options; 23 | this.wsOptions = wsOptions; 24 | /** 25 | * Determines whether the player can spawn - after 'w' packet 26 | * @type {Boolean} 27 | */ 28 | this.accepted = false; 29 | 30 | this._init(); 31 | } 32 | /** 33 | * @private 34 | */ 35 | _init() { 36 | /** 37 | * @type {SocketOptions} 38 | * @readonly 39 | */ 40 | this.options = configureDefault(this.options, DEFAULT_OPTIONS) 41 | } 42 | /** 43 | * Opens a socket to a server 44 | * @param {Server} server 45 | */ 46 | open(server) { 47 | /** 48 | * @property {Server} server Server of connection 49 | */ 50 | this.server = server; 51 | /** 52 | * @type {Object} 53 | * @readonly 54 | */ 55 | this.ws = new WebSocket(`wss://${server.host}/?a=1`, ["arras.io#v0+ft2", "arras.io#v1+ft2"], { 56 | "rejectUnauthorized": false, 57 | "headers": { 58 | "accept-language": "en-US,en;q=0.9,es;q=0.8", 59 | "cache-control": "no-cache", 60 | "pragma": "no-cache", 61 | "sec-gpc": "1", 62 | }, 63 | ...this.wsOptions 64 | }); 65 | this.ws.binaryType = 'arraybuffer'; 66 | /** 67 | * @property {Object} parsers Update and broadcast parsers 68 | */ 69 | this.parsers = { 70 | update: new UpdateParser(), 71 | broadcast: new BroadcastParser() 72 | } 73 | 74 | this.ws.on('open', () => { 75 | this.emit('open'); 76 | this.talk('p', 1); 77 | this.talk('d', 1); 78 | 79 | this.talk('T', `{"type":"headless"}`); 80 | this.talk('k'); 81 | }); 82 | this.ws.on('error', (err) => this.emit('ws-error', err)); 83 | this.ws.on('close', () => this.emit('close')); 84 | this.ws.on('message', (buf) => { 85 | const data = new Uint8Array(buf); 86 | 87 | const packet = coder.decode(data); 88 | this.emit('packet', packet) 89 | }); 90 | 91 | // Deals with the connection 92 | this.on('packet', (packet) => { 93 | switch (packet[0]) { 94 | case "b": 95 | this.emit('broadcast', this.parsers.broadcast.parse(packet)); 96 | break; 97 | case "K": 98 | this.emit('kick', packet[1]); 99 | break; 100 | case "F": 101 | this.emit('death'); 102 | break 103 | case 'u': 104 | this.emit('update', this.parsers.update.parse(packet)); 105 | this.talk('d', packet[1]); 106 | break; 107 | case 'p': 108 | this.talk('p', packet[1]); 109 | break; 110 | case 'e': 111 | console.error('Fatal Error - unable to respond to the `e`val packet. Terminating process', packet[1]) 112 | process.exit(0); 113 | case 'w': 114 | if (packet[1] === 1) { 115 | // this.talk('s', ) 116 | this.accepted = true; 117 | this.emit('accept'); 118 | } else if (packet[1] === 2) { 119 | console.error('Fatal Error - unable to solve recaptcha v3 (too many players in server). Terminating process', packet[1]) 120 | process.exit(0) 121 | } 122 | 123 | } 124 | }) 125 | } 126 | /** 127 | * Close the connection 128 | */ 129 | close() { 130 | this.ws.terminate(); 131 | } 132 | /** 133 | * Send data to the server - encoder 134 | * @param {...any} data 135 | */ 136 | talk(...data) { 137 | this.ws.send(coder.encode(data)) 138 | } 139 | } 140 | module.exports = Socket -------------------------------------------------------------------------------- /src/util.js: -------------------------------------------------------------------------------- 1 | module.exports.configureDefault = function (options, defaults) { 2 | for (let key in defaults) { 3 | if (typeof defaults[key] === 'object') { 4 | options[key] = module.exports.configureDefault(options[key], defaults[key]) 5 | continue; 6 | } 7 | options[key] = typeof options[key] === 'undefined' ? defaults[key] : options[key]; 8 | } 9 | return options 10 | } 11 | --------------------------------------------------------------------------------