Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
CRAP
100.00% covered (success)
100.00%
1 / 1
LoginCommand
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
2 / 2
2
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 pack
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3declare(strict_types=1);
4
5namespace AqwSocketClient\Commands;
6
7use AqwSocketClient\Interfaces\CommandInterface;
8use AqwSocketClient\Objects\Names\PlayerName;
9use AqwSocketClient\Packet;
10use Override;
11use SensitiveParameter;
12
13/**
14 * Represents a command to log in a player to the AQW server.
15 *
16 * This is the first command sent to authenticate a player using their username
17 * and authentication token. It constructs an XML-based packet required by the server.
18 */
19final class LoginCommand implements CommandInterface
20{
21    public function __construct(
22        public readonly PlayerName $playerName,
23        #[SensitiveParameter]
24        public readonly string $token,
25    ) {}
26
27    #[Override]
28    public function pack(): Packet
29    {
30        return Packet::packetify(
31            "<msg t='sys'>"
32            . "<body action='login' r='0'>"
33            . "<login z='zone_master'>"
34            . "<nick><![CDATA[SPIDER#0001~{$this->playerName}~3.01]]></nick>"
35            . "<pword><![CDATA[{$this->token}]]></pword>"
36            . '</login></body></msg>',
37        );
38    }
39}