Closed st-way closed 7 years ago
Thanks for sharing the error and the code! We will look right into the issue as to why what you changed isn't working! 😄
Sorry, I didnt thought you have time to loose checking my code.. Here I tried to clone the W key to E key just to test if it worked, but it does not Error dissapear if you remove PacketHandler.prototype.message_onKeyE block in PacketHandler, but WHY, that is the question
PlayerTracker:
var Packet = require('./packet');
var GameServer = require('./GameServer');
var BinaryWriter = require("./packet/BinaryWriter");
var UserRoleEnum = require("./enum/UserRoleEnum");
function PlayerTracker(gameServer, socket) {
this.gameServer = gameServer;
this.socket = socket;
this.pID = -1;
this.userRole = UserRoleEnum.GUEST;
this.userAuth = null;
this.isRemoved = false;
this.isCloseRequested = false;
this._name = "";
this._skin = "";
this._nameUtf8 = null;
this._nameUnicode = null;
this._skinUtf8 = null;
this.color = { r: 0, g: 0, b: 0 };
this.viewNodes = [];
this.clientNodes = [];
this.cells = [];
this.mergeOverride = false; // Triggered by console command
this._score = 0; // Needed for leaderboard
this._scale = 1;
this._scaleF = 1;
this.isMassChanged = true;
this.borderCounter = 0;
this.mouse = {
x: 0,
y: 0
};
this.tickLeaderboard = 0;
this.team = 0;
this.spectate = false;
this.freeRoam = false; // Free-roam mode enables player to move in spectate mode
this.spectateTarget = null; // Spectate target, null for largest player
this.lastSpectateSwitchTick = 0;
this.centerPos = {
x: 0,
y: 0
};
this.viewBox = {
minx: 0,
miny: 0,
maxx: 0,
maxy: 0,
width: 0,
height: 0,
halfWidth: 0,
halfHeight: 0
};
// Scramble the coordinate system for anti-raga
this.scrambleX = 0;
this.scrambleY = 0;
this.scrambleId = 0;
this.connectedTime = 0;
this.isMinion = false;
this.spawnCounter = 0;
this.isMuted = false;
// Gamemode function
if (gameServer) {
this.connectedTime = gameServer.stepDateTime;
this.centerPos.x = gameServer.border.centerx;
this.centerPos.y = gameServer.border.centery;
// Player id
this.pID = gameServer.getNewPlayerID();
// Gamemode function
gameServer.gameMode.onPlayerInit(this);
// Only scramble if enabled in config
this.scramble();
}
}
module.exports = PlayerTracker;
// Setters/Getters
PlayerTracker.prototype.scramble = function () {
if (!this.gameServer.config.serverScrambleLevel) {
this.scrambleId = 0;
this.scrambleX = 0;
this.scrambleY = 0;
} else {
this.scrambleId = (Math.random() * 0xFFFFFFFF) >>> 0;
// avoid mouse packet limitations
var maxx = Math.max(0, 32767 - 1000 - this.gameServer.border.width);
var maxy = Math.max(0, 32767 - 1000 - this.gameServer.border.height);
var x = maxx * Math.random();
var y = maxy * Math.random();
if (Math.random() >= 0.5) x = -x;
if (Math.random() >= 0.5) y = -y;
this.scrambleX = x;
this.scrambleY = y;
}
this.borderCounter = 0;
};
PlayerTracker.prototype.getFriendlyName = function () {
var name = this.getName();
if (!name) name = "";
name = name.trim();
if (name.length == 0)
name = "An unnamed cell";
return name;
};
PlayerTracker.prototype.setName = function (name) {
this._name = name;
if (!name || name.length < 1) {
this._nameUnicode = null;
this._nameUtf8 = null;
return;
}
var writer = new BinaryWriter()
writer.writeStringZeroUnicode(name);
this._nameUnicode = writer.toBuffer();
writer = new BinaryWriter()
writer.writeStringZeroUtf8(name);
this._nameUtf8 = writer.toBuffer();
};
PlayerTracker.prototype.getName = function () {
return this._name;
};
PlayerTracker.prototype.setSkin = function (skin) {
this._skin = skin;
if (!skin || skin.length < 1) {
this._skinUtf8 = null;
return;
}
var writer = new BinaryWriter()
writer.writeStringZeroUtf8(skin);
this._skinUtf8 = writer.toBuffer();
};
PlayerTracker.prototype.getSkin = function () {
if (this.gameServer.gameMode.haveTeams) {
return "";
}
return this._skin;
};
PlayerTracker.prototype.getNameUtf8 = function () {
return this._nameUtf8;
}
PlayerTracker.prototype.getNameUnicode = function () {
return this._nameUnicode;
}
PlayerTracker.prototype.getSkinUtf8 = function () {
return this._skinUtf8;
}
PlayerTracker.prototype.getColor = function (color) {
return this.color;
};
PlayerTracker.prototype.setColor = function (color) {
this.color.r = color.r;
this.color.g = color.g;
this.color.b = color.b;
};
PlayerTracker.prototype.getTeam = function () {
return this.team;
};
PlayerTracker.prototype.getScore = function () {
if (this.isMassChanged)
this.updateMass();
return this._score;
};
PlayerTracker.prototype.getScale = function () {
if (this.isMassChanged)
this.updateMass();
return this._scale;
};
PlayerTracker.prototype.updateMass = function () {
var totalSize = 0;
var totalScore = 0;
for (var i = 0; i < this.cells.length; i++) {
var node = this.cells[i];
totalSize += node.getSize();
totalScore += node.getSizeSquared();
}
if (totalSize == 0) {
//do not change scale for spectators or not in game players
this._score = 0;
} else {
this._score = totalScore;
this._scale = Math.pow(Math.min(64 / totalSize, 1), 0.4);
}
this.isMassChanged = false;
};
PlayerTracker.prototype.massChanged = function () {
this.isMassChanged = true;
};
// Functions
PlayerTracker.prototype.joinGame = function (name, skin) {
if (this.cells.length > 0) return;
if (name == null) name = "";
this.setName(name);
if (skin != null)
this.setSkin(skin);
this.spectate = false;
this.freeRoam = false;
this.spectateTarget = null;
// some old clients don't understand ClearAll message
// so we will send update for them
if (this.socket.packetHandler.protocol < 6) {
this.socket.sendPacket(new Packet.UpdateNodes(this, [], [], [], this.clientNodes));
}
this.socket.sendPacket(new Packet.ClearAll());
this.clientNodes = [];
this.scramble();
if (this.gameServer.config.serverScrambleLevel < 2) {
// no scramble / lightweight scramble
this.socket.sendPacket(new Packet.SetBorder(this, this.gameServer.border));
}
else if (this.gameServer.config.serverScrambleLevel == 3) {
// Scramble level 3 (no border)
// Ruins most known minimaps
var border = {
minx: this.gameServer.border.minx - (0x10000 + 10000000 * Math.random()),
miny: this.gameServer.border.miny - (0x10000 + 10000000 * Math.random()),
maxx: this.gameServer.border.maxx + (0x10000 + 10000000 * Math.random()),
maxy: this.gameServer.border.maxy + (0x10000 + 10000000 * Math.random())
};
this.socket.sendPacket(new Packet.SetBorder(this, border));
}
this.spawnCounter++;
this.gameServer.gameMode.onPlayerSpawn(this.gameServer, this);
};
PlayerTracker.prototype.checkConnection = function () {
// Handle disconnection
if (!this.socket.isConnected) {
// wait for playerDisconnectTime
var dt = (this.gameServer.stepDateTime - this.socket.closeTime) / 1000;
if (this.cells.length == 0 || dt >= this.gameServer.config.playerDisconnectTime) {
// Remove all client cells
var cells = this.cells;
this.cells = [];
for (var i = 0; i < cells.length; i++) {
this.gameServer.removeNode(cells[i]);
}
// Mark to remove
this.isRemoved = true;
return;
}
this.mouse.x = this.centerPos.x;
this.mouse.y = this.centerPos.y;
this.socket.packetHandler.pressSpace = false;
this.socket.packetHandler.pressW = false; this.socket.packetHandler.pressE = false;
this.socket.packetHandler.pressQ = false;
return;
}
// Check timeout
if (!this.isCloseRequested && this.gameServer.config.serverTimeout) {
var dt = (this.gameServer.stepDateTime - this.socket.lastAliveTime) / 1000;
if (dt >= this.gameServer.config.serverTimeout) {
this.socket.close(1000, "Connection timeout");
this.isCloseRequested = true;
}
}
};
PlayerTracker.prototype.updateTick = function () {
this.socket.packetHandler.process();
if (this.spectate) {
if (this.freeRoam || this.getSpectateTarget() == null) {
// free roam
this.updateCenterFreeRoam();
this._scale = this.gameServer.config.serverSpectatorScale;//0.25;
} else {
// spectate target
return;
}
} else {
// in game
this.updateCenterInGame();
}
this.updateViewBox();
this.updateVisibleNodes();
};
PlayerTracker.prototype.sendUpdate = function () {
if (this.isRemoved||
!this.socket.packetHandler.protocol ||
!this.socket.isConnected ||
(this.socket._socket.writable != null && !this.socket._socket.writable) ||
this.socket.readyState != this.socket.OPEN) {
// do not send update for disconnected clients
// also do not send if initialization is not complete yet
return;
}
if (this.spectate) {
if (!this.freeRoam) {
// spectate target
var player = this.getSpectateTarget();
if (player != null) {
this.setCenterPos(player.centerPos.x, player.centerPos.y);
this._scale = player.getScale();
this.viewBox = player.viewBox;
this.viewNodes = player.viewNodes;
}
}
this.sendCameraPacket();
}
if (this.gameServer.config.serverScrambleLevel == 2) {
// scramble (moving border)
if (this.borderCounter == 0) {
var bound = {
minx: Math.max(this.gameServer.border.minx, this.viewBox.minx - this.viewBox.halfWidth),
miny: Math.max(this.gameServer.border.miny, this.viewBox.miny - this.viewBox.halfHeight),
maxx: Math.min(this.gameServer.border.maxx, this.viewBox.maxx + this.viewBox.halfWidth),
maxy: Math.min(this.gameServer.border.maxy, this.viewBox.maxy + this.viewBox.halfHeight)
};
this.socket.sendPacket(new Packet.SetBorder(this, bound));
}
this.borderCounter++;
if (this.borderCounter >= 20)
this.borderCounter = 0;
}
var delNodes = [];
var eatNodes = [];
var addNodes = [];
var updNodes = [];
var oldIndex = 0;
var newIndex = 0;
for (; newIndex < this.viewNodes.length && oldIndex < this.clientNodes.length;) {
if (this.viewNodes[newIndex].nodeId < this.clientNodes[oldIndex].nodeId) {
addNodes.push(this.viewNodes[newIndex]);
newIndex++;
continue;
}
if (this.viewNodes[newIndex].nodeId > this.clientNodes[oldIndex].nodeId) {
var node = this.clientNodes[oldIndex];
if (node.isRemoved && node.getKiller() != null && node.owner != node.getKiller().owner)
eatNodes.push(node);
else
delNodes.push(node);
oldIndex++;
continue;
}
var node = this.viewNodes[newIndex];
// skip food & eject if no moving
if (node.isMoving || (node.cellType != 1 && node.cellType != 3))
updNodes.push(node);
newIndex++;
oldIndex++;
}
for (; newIndex < this.viewNodes.length; ) {
addNodes.push(this.viewNodes[newIndex]);
newIndex++;
}
for (; oldIndex < this.clientNodes.length; ) {
var node = this.clientNodes[oldIndex];
if (node.isRemoved && node.getKiller() != null && node.owner != node.getKiller().owner)
eatNodes.push(node);
else
delNodes.push(node);
oldIndex++;
}
this.clientNodes = this.viewNodes;
// Send packet
this.socket.sendPacket(new Packet.UpdateNodes(
this,
addNodes,
updNodes,
eatNodes,
delNodes));
// Update leaderboard
if (++this.tickLeaderboard > 25) {
// 1 / 0.040 = 25 (once per second)
this.tickLeaderboard = 0;
if (this.gameServer.leaderboardType >= 0) {
var packet = new Packet.UpdateLeaderboard(this, this.gameServer.leaderboard, this.gameServer.leaderboardType);
this.socket.sendPacket(packet);
}
}
};
// Viewing box
PlayerTracker.prototype.updateCenterInGame = function () { // Get center of cells
var len = this.cells.length;
if (len <= 0) return;
var cx = 0;
var cy = 0;
var count = 0;
for (var i = 0; i < len; i++) {
var node = this.cells[i];
cx += node.position.x;
cy += node.position.y;
count++;
}
if (count == 0) return;
cx /= count;
cy /= count;
cx = (this.centerPos.x + cx) / 2;
cy = (this.centerPos.y + cy) / 2;
this.setCenterPos(cx, cy);
};
PlayerTracker.prototype.updateCenterFreeRoam = function () {
var dx = this.mouse.x - this.centerPos.x;
var dy = this.mouse.y - this.centerPos.y;
var squared = dx * dx + dy * dy;
if (squared < 1) return; // stop threshold
// distance
var d = Math.sqrt(squared);
var invd = 1 / d;
var nx = dx * invd;
var ny = dy * invd;
var speed = Math.min(d, 32);
if (speed <= 0) return;
var x = this.centerPos.x + nx * speed;
var y = this.centerPos.y + ny * speed;
this.setCenterPos(x, y);
};
PlayerTracker.prototype.updateViewBox = function () {
var scale = this.getScale();
scale = Math.max(scale, this.gameServer.config.serverMinScale);
this._scaleF += 0.1 * (scale - this._scaleF);
if (isNaN(this._scaleF))
this._scaleF = 1;
var width = (this.gameServer.config.serverViewBaseX + 100) / this._scaleF;
var height = (this.gameServer.config.serverViewBaseY + 100) / this._scaleF;
var halfWidth = width / 2;
var halfHeight = height / 2;
this.viewBox = {
minx: this.centerPos.x - halfWidth,
miny: this.centerPos.y - halfHeight,
maxx: this.centerPos.x + halfWidth,
maxy: this.centerPos.y + halfHeight,
width: width,
height: height,
halfWidth: halfWidth,
halfHeight: halfHeight
};
};
PlayerTracker.prototype.pressQ = function () {
if (this.spectate) {
// Check for spam first (to prevent too many add/del updates)
var tick = this.gameServer.getTick();
if (tick - this.lastSpectateSwitchTick < 40)
return;
this.lastSpectateSwitchTick = tick;
if (this.spectateTarget == null) {
this.freeRoam = !this.freeRoam;
}
this.spectateTarget = null;
}
};
PlayerTracker.prototype.pressW = function () {
if (this.spectate) {
return;
}
else if (this.gameServer.run) {
this.gameServer.ejectMass(this);
}
};PlayerTracker.prototype.pressE = function () { if (this.spectate) { return; } else if (this.gameServer.run) { this.gameServer.ejectMass(this); }};
PlayerTracker.prototype.pressSpace = function () {
if (this.spectate) {
// Check for spam first (to prevent too many add/del updates)
var tick = this.gameServer.getTick();
if (tick - this.lastSpectateSwitchTick < 40)
return;
this.lastSpectateSwitchTick = tick;
// Space doesn't work for freeRoam mode
if (this.freeRoam || this.gameServer.largestClient == null)
return;
this.nextSpectateTarget();
} else if (this.gameServer.run) {
if (this.mergeOverride)
return;
this.gameServer.splitCells(this);
}
};
PlayerTracker.prototype.nextSpectateTarget = function () {
if (this.spectateTarget == null) {
this.spectateTarget = this.gameServer.largestClient;
return;
}
// lookup for next spectate target
var index = this.gameServer.clients.indexOf(this.spectateTarget.socket);
if (index < 0) {
this.spectateTarget = this.gameServer.largestClient;
return;
}
// find next
for (var i = index + 1; i < this.gameServer.clients.length; i++) {
var player = this.gameServer.clients[i].playerTracker;
if (player.cells.length > 0) {
this.spectateTarget = player;
return;
}
}
for (var i = 0; i <= index; i++) {
var player = this.gameServer.clients[i].playerTracker;
if (player.cells.length > 0) {
this.spectateTarget = player;
return;
}
}
// no alive players
this.spectateTarget = null;
};
PlayerTracker.prototype.getSpectateTarget = function () {
if (this.spectateTarget == null || this.spectateTarget.isRemoved || this.spectateTarget.cells.length < 1) {
this.spectateTarget = null;
return this.gameServer.largestClient;
}
return this.spectateTarget;
};
PlayerTracker.prototype.updateVisibleNodes = function () {
this.viewNodes = [];
if (!this.isMinion) {
var self = this;
this.gameServer.quadTree.find(this.viewBox, function (quadItem) {
if (quadItem.cell.owner != self)
self.viewNodes.push(quadItem.cell);
});
}
this.viewNodes = this.viewNodes.concat(this.cells);
this.viewNodes.sort(function (a, b) { return a.nodeId - b.nodeId; });
};
PlayerTracker.prototype.setCenterPos = function (x, y) {
if (isNaN(x) || isNaN(y)) {
throw new TypeError("PlayerTracker.setCenterPos: NaN");
}
x = Math.max(x, this.gameServer.border.minx);
y = Math.max(y, this.gameServer.border.miny);
x = Math.min(x, this.gameServer.border.maxx);
y = Math.min(y, this.gameServer.border.maxy);
this.centerPos.x = x;
this.centerPos.y = y;
};
PlayerTracker.prototype.sendCameraPacket = function () {
this.socket.sendPacket(new Packet.UpdatePosition(
this,
this.centerPos.x,
this.centerPos.y,
this.getScale()
));
};
PacketHandler:
var pjson = require('../package.json');
var Packet = require('./packet');
var BinaryReader = require('./packet/BinaryReader');
function PacketHandler(gameServer, socket) {
this.gameServer = gameServer;
this.socket = socket;
this.protocol = 0;
this.handshakeProtocol = null;
this.handshakeKey = null;
this.lastJoinTick = 0;
this.lastChatTick = 0;
this.lastStatTick = 0;
this.lastWTick = 0; this.lastETick = 0;
this.lastQTick = 0;
this.lastSpaceTick = 0;
this.pressQ = false;
this.pressW = false; this.pressE = false;
this.pressSpace = false;
this.mouseData = null;
this.handler = {
254: this.handshake_onProtocol.bind(this),
};
}
module.exports = PacketHandler;
PacketHandler.prototype.handleMessage = function (message) {
if (!this.handler.hasOwnProperty(message[0])) {
return;
}
this.handler[message[0]](message);
this.socket.lastAliveTime = this.gameServer.stepDateTime;
};
PacketHandler.prototype.handshake_onProtocol = function (message) {
if (message.length !== 5) return;
this.handshakeProtocol = message[1] | (message[2] << 8) | (message[3] << 16) | (message[4] << 24);
if (this.handshakeProtocol < 1 || this.handshakeProtocol > 9) {
this.socket.close(1002, "Not supported protocol");
return;
}
this.handler = {
255: this.handshake_onKey.bind(this),
};
};
PacketHandler.prototype.handshake_onKey = function (message) {
if (message.length !== 5) return;
this.handshakeKey = message[1] | (message[2] << 8) | (message[3] << 16) | (message[4] << 24);
if (this.handshakeProtocol > 6 && this.handshakeKey !== 0) {
this.socket.close(1002, "Not supported protocol");
return;
}
this.handshake_onCompleted(this.handshakeProtocol, this.handshakeKey);
};
PacketHandler.prototype.handshake_onCompleted = function (protocol, key) {
this.handler = {
0: this.message_onJoin.bind(this),
1: this.message_onSpectate.bind(this),
16: this.message_onMouse.bind(this),
17: this.message_onKeySpace.bind(this),
18: this.message_onKeyQ.bind(this),
//19: AFK
21: this.message_onKeyW.bind(this), //69: this.message_onKeyE.bind(this),
99: this.message_onChat.bind(this),
254: this.message_onStat.bind(this),
};
this.protocol = protocol;
// Send handshake response
this.socket.sendPacket(new Packet.ClearAll());
this.socket.sendPacket(new Packet.SetBorder(this.socket.playerTracker, this.gameServer.border, this.gameServer.config.serverGamemode, "MultiOgar " + pjson.version));
// Send welcome message
this.gameServer.sendChatMessage(null, this.socket.playerTracker, "MultiOgar " + pjson.version);
if (this.gameServer.config.serverWelcome1)
this.gameServer.sendChatMessage(null, this.socket.playerTracker, this.gameServer.config.serverWelcome1);
if (this.gameServer.config.serverWelcome2)
this.gameServer.sendChatMessage(null, this.socket.playerTracker, this.gameServer.config.serverWelcome2);
if (this.gameServer.config.serverChat == 0)
this.gameServer.sendChatMessage(null, this.socket.playerTracker, "This server's chat is disabled.");
if (this.protocol < 4)
this.gameServer.sendChatMessage(null, this.socket.playerTracker, "WARNING: Protocol " + this.protocol + " assumed as 4!");
};
PacketHandler.prototype.message_onJoin = function (message) {
var tick = this.gameServer.getTick();
var dt = tick - this.lastJoinTick;
this.lastJoinTick = tick;
if (dt < 25 || this.socket.playerTracker.cells.length !== 0) {
return;
}
var reader = new BinaryReader(message);
reader.skipBytes(1);
var text = null;
if (this.protocol < 6)
text = reader.readStringZeroUnicode();
else
text = reader.readStringZeroUtf8();
this.setNickname(text);
};
PacketHandler.prototype.message_onSpectate = function (message) {
if (message.length !== 1 || this.socket.playerTracker.cells.length !== 0) {
return;
}
this.socket.playerTracker.spectate = true;
};
PacketHandler.prototype.message_onMouse = function (message) {
if (message.length !== 13 && message.length !== 9 && message.length !== 21) {
return;
}
this.mouseData = Buffer.concat([message]);
};
PacketHandler.prototype.message_onKeySpace = function (message) {
if (message.length !== 1) return;
var tick = this.gameServer.getTick();
var dt = tick - this.lastSpaceTick;
if (dt < this.gameServer.config.ejectCooldown) {
return;
}
this.lastSpaceTick = tick;
this.pressSpace = true;
};
PacketHandler.prototype.message_onKeyQ = function (message) {
if (message.length !== 1) return;
var tick = this.gameServer.getTick();
var dt = tick - this.lastQTick;
if (dt < this.gameServer.config.ejectCooldown) {
return;
}
this.lastQTick = tick;
this.pressQ = true;
};
PacketHandler.prototype.message_onKeyW = function (message) {
if (message.length !== 1) return;
var tick = this.gameServer.getTick();
var dt = tick - this.lastWTick;
if (dt < this.gameServer.config.ejectCooldown) {
return;
}
this.lastWTick = tick;
this.pressW = true;
};PacketHandler.prototype.message_onKeyE = function (message) { if (message.length !== 1) return; var tick = this.gameServer.getTick(); var dt = tick - this.lastETick; if (dt < this.gameServer.config.ejectCooldown) { return; } this.lastETick = tick; this.pressE = true;};
PacketHandler.prototype.message_onChat = function (message) {
if (message.length < 3) return;
var tick = this.gameServer.getTick();
var dt = tick - this.lastChatTick;
this.lastChatTick = tick;
if (dt < 25 * 2) {
return;
}
var flags = message[1]; // flags
var rvLength = (flags & 2 ? 4:0) + (flags & 4 ? 8:0) + (flags & 8 ? 16:0);
if (message.length < 3 + rvLength) // second validation
return;
var reader = new BinaryReader(message);
reader.skipBytes(2 + rvLength); // reserved
var text = null;
if (this.protocol < 6)
text = reader.readStringZeroUnicode();
else
text = reader.readStringZeroUtf8();
this.gameServer.onChatMessage(this.socket.playerTracker, null, text);
};
PacketHandler.prototype.message_onStat = function (message) {
if (message.length !== 1) return;
var tick = this.gameServer.getTick();
var dt = tick - this.lastStatTick;
this.lastStatTick = tick;
if (dt < 25) {
return;
}
this.socket.sendPacket(new Packet.ServerStat(this.socket.playerTracker));
};
PacketHandler.prototype.processMouse = function () {
if (this.mouseData == null) return;
var client = this.socket.playerTracker;
var reader = new BinaryReader(this.mouseData);
reader.skipBytes(1);
if (this.mouseData.length === 13) {
// protocol late 5, 6, 7
client.mouse.x = reader.readInt32() - client.scrambleX;
client.mouse.y = reader.readInt32() - client.scrambleY;
} else if (this.mouseData.length === 9) {
// early protocol 5
client.mouse.x = reader.readInt16() - client.scrambleX;
client.mouse.y = reader.readInt16() - client.scrambleY;
} else if (this.mouseData.length === 21) {
// protocol 4
var x = reader.readDouble() - client.scrambleX;
var y = reader.readDouble() - client.scrambleY;
if (!isNaN(x) && !isNaN(y)) {
client.mouse.x = x;
client.mouse.y = y;
}
}
this.mouseData = null;
};
PacketHandler.prototype.process = function () {
if (this.pressSpace) { // Split cell
this.socket.playerTracker.pressSpace();
this.pressSpace = false;
}
if (this.pressW) { // Eject mass
this.socket.playerTracker.pressW();
this.pressW = false;
} if (this.pressE) { // Eject mass this.socket.playerTracker.pressE(); this.pressE = false; }
if (this.pressQ) { // Q Press
this.socket.playerTracker.pressQ();
this.pressQ = false;
}
this.processMouse();
};
PacketHandler.prototype.setNickname = function (text) {
var name = "";
var skin = null;
if (text != null && text.length > 0) {
var skinName = null;
var userName = text;
var n = -1;
if (text[0] == '<' && (n = text.indexOf('>', 1)) >= 1) {
if (n > 1)
skinName = "%" + text.slice(1, n);
else
skinName = "";
userName = text.slice(n + 1);
}
//else if (text[0] == "|" && (n = text.indexOf('|', 1)) >= 0) {
// skinName = ":http://i.imgur.com/" + text.slice(1, n) + ".png";
// userName = text.slice(n + 1);
//}
if (skinName && !this.gameServer.checkSkinName(skinName)) {
skinName = null;
userName = text;
}
skin = skinName;
name = userName;
}
if (name.length > this.gameServer.config.playerMaxNickLength) {
name = name.substring(0, this.gameServer.config.playerMaxNickLength);
}
if (this.gameServer.checkBadWord(name)) {
skin = null;
name = "Hi there!";
}
this.socket.playerTracker.joinGame(name, skin);
};
Error in console:
/var/www/html/agario/MultiOgar-masterrr/src/PacketHandler.js:264
});
^
SyntaxError: Unexpected token )
at Module._compile (module.js:439:25)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Module.require (module.js:364:17)
at require (module.js:380:17)
at Object.<anonymous> (/var/www/html/agario/MultiOgar-masterrr/src/GameServer.js:15:21)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
I don't think any code is needed; it's not possible to add any extra keys using vanilla client. The only keys you can bind to using the vanilla client is q, w, and the space key.
That aside, based on the error stack trace, you should check line 264 on your PacketHandler.js
file for an error related to a parenthesis. You might have used it when not necessary (no leading opening parenthesis or double-closed parenthesis), or it just doesn't belong there.
I didnt know it was not possible, thanks.. I was thinking it's strange java key codes does not correspond for W and space keys ^^'
Hi, Is it possible to add some shortcuts like E for full split ? I tried to add E key in PlayerTracker and Packethandler but it give me error when launching Start-linux.sh