m-byte918 / MultiOgarII

A continued version of the original MultiOgar, an open source Ogar server implementation written with Node.js.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Wrong leaderboard packet (protocol 11+ )

Yahnych opened this issue · comments

have strange result when using MultiogarII with 14 protocol. Here is wrong line when item is player .
OgarII example :

function ffaLeaderboard11(writer, data, selfData, protocol) {
    writer.writeUInt8(protocol >= 14 ? 53 : 51);
    for (let i = 0, l = data.length; i < l; i++) {
        const item = data[i];
        if (item === selfData)
            writer.writeUInt8(8);
        else {
            writer.writeUInt8(2);
            writer.writeZTStringUTF8(item.name);
        }
    }
}

MOII code:

buildFfa(protocol) {
        var writer = new BinaryWriter();
        if (protocol < 14)
            writer.writeUInt8(0x33); // 13
        else
            writer.writeUInt8(0x35); // 14
        for (var i = 0; i < this.leaderboardCount; i++) {
            var item = this.leaderboard[i];
            if (item == null)
                return null; // bad leaderboard just don't send it
            if (item === this.player) {
                writer.writeUInt8(0x09);
                writer.writeUInt16(1);//         <--its should not be here
            }
            else {
                var name = item._name;
                writer.writeUInt8(0x02);
                if (name != null && name.length)
                    writer.writeStringZeroUtf8(name);
                else
                    writer.writeUInt8(0);
            }
        }
        var thing = this.leaderboard.indexOf(this.player) + 1;
        var place = (thing <= 10) ? null : thing;
        if (this.player.cells.length && place != null) {
            writer.writeUInt8(0x09);
            writer.writeUInt16(place);
        }
        return writer.toBuffer();
    }