Code Duplication    Length = 47-90 lines in 2 locations

src/DP/GameServer/MinecraftServerBundle/MinecraftQuery/MinecraftRcon.php 1 location

@@ 31-77 (lines=47) @@
28
    protected $authenticated = null;
29
    protected $fullyConstructed = false;
30
    
31
    public function __construct($container, $host, $port, $rconPassword)
32
    {
33
        $callbacks = array();
34
        // Permet de déterminé s'il s'agit d'une réponse multi-paquet
35
        $callbacks[Socket::MULTI_DETECTOR] = function(Packet $packet) {
36
            if (is_null($packet) || $packet->isEmpty()) return false;
37
            
38
            // Récupération de la longueur de la réponse
39
            $len = $packet->getLong(false);
40
            // Il faut rajouter 4 puisque la taille récupéré correspondant 
41
            // A la taille du paquet sans l'entier contenant la taille
42
            $remaining = $len - $packet->getLength() + 4;
43
            
44
            if ($remaining > 0) {                
45
                return true;
46
            }
47
            else {
48
                return false;
49
            }
50
        };
51
        // Permet de récupérer les différents paquets qui composent une réponse
52
        $callbacks[Socket::MULTI_RECEIVER] = function(Packet $packet, Socket $socket) {
53
            if (is_null($packet) || $packet->isEmpty()) return false;
54
            
55
            // Récupération de la longueur de la réponse
56
            $len = $packet->getLong(false);
57
            // Il faut rajouter 4 puisque la taille récupéré correspondant 
58
            // A la taille du paquet sans l'entier contenant la taille
59
            $remaining = $len - $packet->getLength() + 4;
60
            
61
            while ($remaining > 0) {
62
                // Récupération du prochain paquet et calcul de la taille restante à récupérer
63
                $newPacket = $socket->recv(false, $remaining);
64
                $remaining = $remaining - $newPacket->getLength();
65
66
                // Ajout du paquet au paquet originel
67
                $packet->setPos($packet->getLength() - 2);
68
                $packet->addContent($newPacket->getContent());
69
            }
70
            
71
            return $packet;
72
        };
73
        
74
        $this->rconPassword = $rconPassword;
75
        $this->socket = $container->get('socket')->getTCPSocket($host, $port, $callbacks);
76
        $this->packetFactory = $container->get('packet.factory.rcon.source');
77
    }
78
79
    /**
80
     * Permet de ne finaliser la création du rcon qu'en cas d'utilisation de celui-ci

src/DP/GameServer/SteamServerBundle/SteamQuery/SourceRcon.php 1 location

@@ 31-120 (lines=90) @@
28
    protected $authenticated = null;
29
    protected $fullyConstructed = false;
30
    
31
    public function __construct($container, $host, $port, $rconPassword)
32
    {
33
        /*$callback = function(Packet $packet, Socket $socket) {
34
            if (is_null($packet) || $packet->isEmpty()) return false;
35
            
36
            $remaining = $packet->getLong(false);
37
            $packet->setPos(4);
38
            $id = $packet->getLong(false);
39
            
40
            if ($remaining > 0) {
41
                $splittedPackets = new PacketCollection();
42
                $respId = null;
43
                
44
                do {
45
                    if (!$respId) {
46
                        $respId = $id;
47
                    }
48
                    elseif ($respId != $id) {
49
                        $packet = $socket->recv(false);
50
                        continue;
51
                    }
52
                    
53
                    $splittedPackets->add($packet->rewind());
54
                    $packet = $socket->recv(false, $remaining);
55
                    $remaining -= $packet->getLength();
56
                } while ($remaining > 0);
57
                
58
                return $splittedPackets->reassemble(
59
                    function(Packet $bigPacket, Packet $packet) {
60
                        if ($bigPacket->isEmpty()) {
61
                            $bigPacket->addContent($packet->getContent());
62
                            $bigPacket->setPos($packet->getLength()-2);
63
                        }
64
                        else {
65
                            $bigPacket->addContent($packet);
66
                        }
67
                        
68
                        return $bigPacket;
69
                    }
70
                )->rewind();
71
            }
72
            else {
73
                return $packet;
74
            }
75
        };*/
76
        $callbacks = array();
77
        // Permet de déterminé s'il s'agit d'une réponse multi-paquet
78
        $callbacks[Socket::MULTI_DETECTOR] = function(Packet $packet) {
79
            if (is_null($packet) || $packet->isEmpty()) return false;
80
            
81
            // Récupération de la longueur de la réponse
82
            $len = $packet->getLong(false);
83
            // Il faut rajouter 4 puisque la taille récupéré correspondant 
84
            // A la taille du paquet sans l'entier contenant la taille
85
            $remaining = $len - $packet->getLength() + 4;
86
            
87
            if ($remaining > 0) {                
88
                return true;
89
            }
90
            else {
91
                return false;
92
            }
93
        };
94
        // Permet de récupérer les différents paquets qui composent une réponse
95
        $callbacks[Socket::MULTI_RECEIVER] = function(Packet $packet, Socket $socket) {
96
            if (is_null($packet) || $packet->isEmpty()) return false;
97
            
98
            // Récupération de la longueur de la réponse
99
            $len = $packet->getLong(false);
100
            // Il faut rajouter 4 puisque la taille récupéré correspondant 
101
            // A la taille du paquet sans l'entier contenant la taille
102
            $remaining = $len - $packet->getLength() + 4;
103
            
104
            while ($remaining > 0) {
105
                // Récupération du prochain paquet et calcul de la taille restante à récupérer
106
                $newPacket = $socket->recv(false, $remaining);
107
                $remaining = $remaining - $newPacket->getLength();
108
109
                // Ajout du paquet au paquet originel
110
                $packet->setPos($packet->getLength() - 2);
111
                $packet->addContent($newPacket->getContent());
112
            }
113
            
114
            return $packet;
115
        };
116
        
117
        $this->rconPassword = $rconPassword;
118
        $this->socket = $container->get('socket')->getTCPSocket($host, $port, $callbacks);
119
        $this->packetFactory = $container->get('packet.factory.rcon.source');
120
    }
121
122
    /**
123
     * Permet de ne finaliser la création du rcon qu'en cas d'utilisation de celui-ci