kallefrombosnia / hlds-log

HLDS remote log parser in node.js
MIT License
9 stars 0 forks source link

Error spotted: TypeError: Cannot read property 'event' of null #13

Open Captaindando opened 3 years ago

Captaindando commented 3 years ago

I'm getting an error when attempting to log 'say', 'say_team' and 'kill' signals. am I doing something wrong? I've included my code at the end.

log L 09/01/2021 - 07:55:32: "monkey<1><STEAM_ID_LAN><1>" say "lkjasldjsa"

Error spotted: TypeError: Cannot read property 'event' of null
Error spotted:  TypeError: Cannot read property 'event' of null
    at D:\Google Drive\Half Life Modding\backend app\node_modules\hlds-log\lib\functions.js:58:36
    at Array.forEach (<anonymous>)
    at HLDS_Log.regexSearch (D:\Google Drive\Half Life Modding\backend app\node_modules\hlds-log\lib\functions.js:55:24)
    at Socket.<anonymous> (D:\Google Drive\Half Life Modding\backend app\node_modules\hlds-log\lib\functions.js:44:18)
    at Socket.emit (events.js:321:20)
    at UDP.onMessage [as onmessage] (dgram.js:924:8)
log L 09/01/2021 - 08:14:15: "ryuichi<8>" killed "Billy<10>" with 9mmhandgun

Error spotted: TypeError: Cannot read property 'event' of null
Error spotted:  TypeError: Cannot read property 'event' of null
    at D:\Google Drive\Half Life Modding\backend app\node_modules\hlds-log\lib\functions.js:58:36
    at Array.forEach (<anonymous>)
    at HLDS_Log.regexSearch (D:\Google Drive\Half Life Modding\backend app\node_modules\hlds-log\lib\functions.js:55:24)
    at Socket.<anonymous> (D:\Google Drive\Half Life Modding\backend app\node_modules\hlds-log\lib\functions.js:44:18)
    at Socket.emit (events.js:321:20)
    at UDP.onMessage [as onmessage] (dgram.js:924:8)

/*jshint esversion: 6 */

const {HLDS_Log}= require('hlds-log');
//const {HLDS_Log} = require('../lib/app');

logger = new HLDS_Log(3000, true);

// Start logger
logger.start();

// Increase listeners limit to avoid warning
logger.setMaxListeners(15);

logger.once('hlds_connect', (info) => {
    console.log('Server connected!' + info.address);
});

logger.on('kill', info =>{
    console.log(info);
});

logger.on('raw', raw => {
    console.log(raw);
});

logger.on('say_team', info => {
    console.log(info);
});

logger.on('say', info => {
    console.log(info);
}); 

logger.on('join', info => {
    console.log(info);
});

logger.on('leave', info => {
    console.log(info);
});

logger.on('enter', info => {
    console.log(info);
});

logger.on('end_score', info => {
    console.log(info);
});

logger.on('player_action', info => {
    console.log(info);
});

logger.on('server_action', info => {
    console.log(info);
});

logger.on('round_end', info => {
    console.log(info);
});

logger.on('connect', info => {
    console.log(info);
});

logger.on('map_change', info => {
    console.log(info);
});

logger.on('map_start', info => {
    console.log(info);
});

logger.on('suicide', info => {
    console.log(info);
});

logger.on('shutdown', info => {
    console.log(info);
});

logger.on('log_off', info => {
    console.log(info);
});

logger.on('cvarsDone', info => {
    console.log(info);
});

logger.on('kick', info => {
    console.log(info);
});

logger.on('error', error =>{
    console.log('Error spotted: ', error)
})
kallefrombosnia commented 3 years ago

Hello, which game server version do you use, HLDS or ReHLDS or something else? I will take a look into this later.

Captaindando commented 3 years ago

Hi Kalle, I'm using hlds with these parameters: -game jumbot -console +map crossfire +maxplayers 16 I'm using jumbot to test it out, but I've received the same errors without it. the node app is hosted on the same computer I'm hosting the half life server and I point my log to localhost with a port of 3000 if that helps

just wanted to thank you for developing this, it's a massive help

kallefrombosnia commented 3 years ago

Hello, I debugged this and found out that your arriving string is malformed.

Examples:

⌂⌂⌂⌂log L 09/01/2021 - 19:31:18: "kalle<1><STEAM_ID_LAN><TERRORIST>" killed "VATB | Jackson_<10><BOT><CT>" with "deagle"

log L 09/01/2021 - 08:14:15: "ryuichi<8>" killed "Billy<10>" with 9mmhandgun

⌂⌂⌂⌂log L 09/01/2021 - 19:34:49: "kalle<1><STEAM_ID_LAN><TERRORIST>" say "say"

����log L 09/01/2021 - 07:55:32: "monkey<1><STEAM_ID_LAN><1>" say "lkjasldjsa"

Obviously, there is a difference, so that's why it fails. Try with the cstrike game parameter and give us the results.

Captaindando commented 3 years ago

Hi Kalle, I tested it out with the parameter you asked for and here are the results:

'say' works in this case, along with almost every other log, The only error I found was on 'Dropped_The_Bomb'

log L 09/02/2021 - 07:50:37: "Player<1><STEAM_ID_LAN><TERRORIST>" say "laskjdlkjasl"

{
  event: 'say',
  player: {
    name: 'Player',
    id: '1',
    steamid: 'STEAM_ID_LAN',
    side: 'TERRORIST',
    message: 'laskjdlkjasl'
  },
  time: { ss: '37', mm: '50', hh: '07' },
  date: { dd: '02', mm: '09', yy: '2021' }
}
log L 09/02/2021 - 07:50:52: "Player<-1><><TERRORIST>" triggered "Dropped_The_Bomb"

Error spotted: TypeError: Cannot read property 'event' of undefined
Error spotted:  TypeError: Cannot read property 'event' of undefined
    at D:\Google Drive\Half Life Modding\backend app\node_modules\hlds-log\lib\functions.js:58:36
    at Array.forEach (<anonymous>)
    at HLDS_Log.regexSearch (D:\Google Drive\Half Life Modding\backend app\node_modules\hlds-log\lib\functions.js:55:24)
    at Socket.<anonymous> (D:\Google Drive\Half Life Modding\backend app\node_modules\hlds-log\lib\functions.js:44:18)
    at Socket.emit (events.js:321:20)
    at UDP.onMessage [as onmessage] (dgram.js:924:8)
Captaindando commented 3 years ago

I think I've found what's causing the errors. It's in the name I started a Half-life game and made it a team game and the errors didn't show up

log L 09/02/2021 - 08:08:38: "Player<1><STEAM_ID_LAN><robo>" say_team "dslfkjkl"

{
  event: 'say_team',
  player: {
    name: 'Player',
    id: '1',
    steamid: 'STEAM_ID_LAN',
    side: 'robo',
    message: 'dslfkjkl'
  },

In instances where it's a free for all, or if there is a player-caused log entry that is missing a part, it throws an error, for example, lines like these:

log L 09/02/2021 - 07:59:54: "Player<1><STEAM_ID_LAN><1>" say "lakjslkdja" - Half-life DM with no teams log L 09/02/2021 - 07:50:52: "Player<-1><><TERRORIST>" triggered "Dropped_The_Bomb" - Cstrike, the middle 'STEAM_ID_LAN' is missing

kallefrombosnia commented 3 years ago

Yup, I see where the problem lies. This was tested cstrike only game mode so it fails on other game modes which have their own custom log messages. I will move this from bug to enchantment since I plan on adding a custom class constructor parameter which will be used to determine incoming string type and use the proper parser for it.