Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Chat Messages to DBLog Plugin #272

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions squad-server/plugins/db-log.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,34 @@ export default class DBLog extends BasePlugin {
}
);

this.createModel(
'ChatMessage',
{
id: {
type: DataTypes.INTEGER,
primaryKey: true,
autoIncrement: true
},
time: {
type: DataTypes.DATE,
notNull: true
},
chat: {
type: DataTypes.STRING
},
message: {
type: DataTypes.TEXT
},
steamid: {
type: DataTypes.STRING
}
},
{
charset: 'utf8mb4',
collate: 'utf8mb4_unicode_ci'
}
);

this.createModel(
'Wound',
{
Expand Down Expand Up @@ -329,6 +357,11 @@ export default class DBLog extends BasePlugin {
onDelete: 'CASCADE'
});

this.models.Server.hasMany(this.models.ChatMessage, {
foreignKey: { name: 'server', allowNull: false },
onDelete: 'CASCADE'
});

this.models.SteamUser.hasMany(this.models.Wound, {
foreignKey: { name: 'attacker' },
onDelete: 'CASCADE'
Expand Down Expand Up @@ -389,12 +422,18 @@ export default class DBLog extends BasePlugin {
onDelete: 'CASCADE'
});

this.models.Match.hasMany(this.models.ChatMessage, {
foreignKey: { name: 'match' },
onDelete: 'CASCADE'
});

this.onTickRate = this.onTickRate.bind(this);
this.onUpdatedA2SInformation = this.onUpdatedA2SInformation.bind(this);
this.onNewGame = this.onNewGame.bind(this);
this.onPlayerWounded = this.onPlayerWounded.bind(this);
this.onPlayerDied = this.onPlayerDied.bind(this);
this.onPlayerRevived = this.onPlayerRevived.bind(this);
this.onChatMessage = this.onChatMessage.bind(this);
}

createModel(name, schema) {
Expand All @@ -412,6 +451,7 @@ export default class DBLog extends BasePlugin {
await this.models.Wound.sync();
await this.models.Death.sync();
await this.models.Revive.sync();
await this.models.ChatMessage.sync();
}

async mount() {
Expand All @@ -430,6 +470,7 @@ export default class DBLog extends BasePlugin {
this.server.on('PLAYER_WOUNDED', this.onPlayerWounded);
this.server.on('PLAYER_DIED', this.onPlayerDied);
this.server.on('PLAYER_REVIVED', this.onPlayerRevived);
this.server.on('CHAT_MESSAGE', this.onChatMessage);
}

async unmount() {
Expand All @@ -439,6 +480,18 @@ export default class DBLog extends BasePlugin {
this.server.removeEventListener('PLAYER_WOUNDED', this.onPlayerWounded);
this.server.removeEventListener('PLAYER_DIED', this.onPlayerDied);
this.server.removeEventListener('PLAYER_REVIVED', this.onPlayerRevived);
this.server.removeEventListener('CHAT_MESSAGE', this.onChatMessage);
}

async onChatMessage(info) {
await this.models.ChatMessage.create({
server: this.options.overrideServerID || this.server.id,
match: this.match ? this.match.id : null,
time: info.time,
steamid: info.player.steamID,
chat: info.chat,
message: info.message
});
}

async onTickRate(info) {
Expand Down