Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
addMessage(time, username, message)
{
Assert.instanceOf(time, Date);
Assert.string(username);
Assert.string(message);
let msgElement = this._doc.createElement('div');
msgElement.classList.add('message');
msgElement.innerHTML = MESSAGE_TEMPLATE
.replace(
'__TIME__',
this._format(time.getHours(), 2) + ':' + this._format(time.getMinutes(), 2) + ':' + this._format(time.getSeconds(), 2)
).replace('__USERNAME__', username)
.replace('__MESSAGE__', message);
this._packet.appendChild(msgElement);
this._chatContainer.scrollTop = this._chatContainer.scrollHeight;
}
getConnection(playerId)
{
Assert.string(playerId);
for (let connection of this._connections.values()) {
if (connection.hasPlayerId && connection.playerId === playerId) {
return connection;
}
}
throw `Can't find connection for player with id ${playerId}`;
}
getPlayer(playerId)
{
Assert.string(playerId);
if (!this._characters.has(playerId)) {
throw new Error(`Player with id ${playerId} does not exists.`);
}
return this._characters.get(playerId);
}
removeConnection(id)
{
Assert.string(id);
this._connections.delete(id);
}
attack(characterId)
{
Assert.string(characterId);
this._targetId = characterId;
}
addMessage(time, username, message)
{
Assert.instanceOf(time, Date);
Assert.string(username);
Assert.string(message);
let msgElement = this._doc.createElement('div');
msgElement.classList.add('message');
msgElement.innerHTML = MESSAGE_TEMPLATE
.replace(
'__TIME__',
this._format(time.getHours(), 2) + ':' + this._format(time.getMinutes(), 2) + ':' + this._format(time.getSeconds(), 2)
).replace('__USERNAME__', username)
.replace('__MESSAGE__', message);
this._packet.appendChild(msgElement);
this._chatContainer.scrollTop = this._chatContainer.scrollHeight;
}
constructor(name, logLevel)
{
super();
Assert.string(name);
Assert.string(logLevel);
this._logger = bunyan.createLogger({
name: name,
level: logLevel
});
}
constructor(text)
{
Assert.string(text);
this._text = text;
this._endTime = new Date().getTime() + 5000;
}
constructor(characterId, message)
{
super();
Assert.string(characterId);
Assert.string(message);
this._name = ServerMessages.CHARACTER_SAY;
this._data = {
id: characterId,
message: message
};
}
}
constructor(message)
{
super();
Assert.string(message);
this._name = ClientMessages.MESSAGE;
this._data = {message: message};
}
}