Git Product home page Git Product logo

js-tale's People

Contributors

mdingena avatar narmdo avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

js-tale's Issues

Typo within' js-tale/src/groups/GroupMemberRequest.ts

import GroupMember from './GroupMember';
import Group from "./Group";
import Logger from '../logger';

const logger = new Logger('GroupMemberRequest');

export default class GroupMemberRequest extends GroupMember
{
constructor(group: Group, info: any)
{
super(group, info);
}

accept()
{
    return this.group.manager.api.fetch('POST', `groups/${this.group.info.id}/requests/${this.userId}`)
    .then(logger.thenInfo(`Accepted ${this.username} (${this.userId})'s request to join ${this.group.info.name} (${this.group.info.id})`));

}

reject()
{
    return this.group.manager.api.fetch('DELETE', `groups/${this.group.info.id}/requests/${this.userId}`)
    .then(logger.thenInfo(`Rejected ${this.username} (${this.userId})'s reqyest to join ${this.group.info.name} (${this.group.info.id})`));
}

}

Typo "reqyest"
change to "request".

Bot connects to server with every status change

Observed behaviour

Every time the server status changes, js-tale seems to establish a new connection. I think this is not intentional behaviour, and it might be the root cause of some other issues I've been having.

Here's a dump of my logs. I've filtered it down to one specific server (my bot is connected to many different game servers at the same time).

7/1/2021, 12:34:03 AM - [Server] A Timeship Tale received status. Online: true. Players: 15
7/1/2021, 12:34:03 AM - [ServerConnection] Doing initialize
7/1/2021, 12:34:03 AM - [ServerConnection] Connecting to A Timeship Tale
Connecting to 34.223.108.179:7394
Resolving connection!
Connection Succeeded, Authenticated as: 1529569283 - voodoo mod

7/1/2021, 12:34:28 AM - [Server] A Timeship Tale received status. Online: true. Players: 16
7/1/2021, 12:34:28 AM - [ServerConnection] Doing initialize
7/1/2021, 12:34:28 AM - [ServerConnection] Connecting to A Timeship Tale
Connecting to 34.223.108.179:7394
Resolving connection!
Connection Succeeded, Authenticated as: 1529569283 - voodoo mod

7/1/2021, 12:36:07 AM - [Server] A Timeship Tale received status. Online: true. Players: 17
7/1/2021, 12:36:07 AM - [ServerConnection] Doing initialize
7/1/2021, 12:36:07 AM - [ServerConnection] Connecting to A Timeship Tale
Connecting to 34.223.108.179:7394
Resolving connection!
Connection Succeeded, Authenticated as: 1529569283 - voodoo mod

7/1/2021, 12:37:25 AM - [Server] A Timeship Tale received status. Online: true. Players: 16
7/1/2021, 12:37:25 AM - [ServerConnection] Doing initialize
7/1/2021, 12:37:25 AM - [ServerConnection] Connecting to A Timeship Tale
Connecting to 34.223.108.179:7394
7/1/2021, 12:37:25 AM - [Server] A Timeship Tale received status. Online: true. Players: 15
Resolving connection!
Connection Succeeded, Authenticated as: 1529569283 - voodoo mod

7/1/2021, 12:40:09 AM - [Server] A Timeship Tale received status. Online: true. Players: 16
7/1/2021, 12:40:09 AM - [ServerConnection] Doing initialize
7/1/2021, 12:40:09 AM - [ServerConnection] Connecting to A Timeship Tale
Connecting to 34.223.108.179:7394
Resolving connection!
Connection Succeeded, Authenticated as: 1529569283 - voodoo mod

7/1/2021, 12:42:45 AM - [Server] A Timeship Tale received status. Online: true. Players: 17
7/1/2021, 12:42:45 AM - [ServerConnection] Doing initialize
7/1/2021, 12:42:45 AM - [ServerConnection] Connecting to A Timeship Tale
Connecting to 34.223.108.179:7394
Resolving connection!
Connection Succeeded, Authenticated as: 1529569283 - voodoo mod

⚠️ Important to note is that the connection.server.on('update', ...) event does not seems to fire inside the groupManager.automaticConsole connection handler. Judging by the output above, js-tale is capable of detecting server status updates, but it does not pass these events through to the server connection event handlers.

Expected behaviour

The bot should establish a server connection once and maintain that connection for the duration of the server's uptime. All server status updates should then be handled inside the automatic console connection's event handlers.

[ApiConnection] is logging auth tokens

The Logger for ApiConnection is outputting connection headers in the logs.

I'm running a js-tale bot on Heroku, so these headers end up in my instance logs. The auth tokens are visible here.

2021-05-19T02:47:25.934601+00:00 app[web.1]: 5/19/2021, 2:47:25 AM - [ApiConnection] HEADERS
2021-05-19T02:47:25.935268+00:00 app[web.1]: {
2021-05-19T02:47:25.935269+00:00 app[web.1]:   'Content-Type': 'application/json',
2021-05-19T02:47:25.935270+00:00 app[web.1]:   'x-api-key': '2l6aQGoNes8EHb94qMhqQ5m2iaiOM9666oDTPORf',
2021-05-19T02:47:25.935270+00:00 app[web.1]:   'User-Agent': 'client_1f7c9a3c-89b5-446c-8723-705c67c551cb',
2021-05-19T02:47:25.935303+00:00 app[web.1]:   Authorization: 'Bearer eyJh--REDACTED--_R54',
2021-05-19T02:47:25.935305+00:00 app[web.1]:   logger: '[ApiConnection] ',
2021-05-19T02:47:25.935306+00:00 app[web.1]:   timestamp: 1621392445934
2021-05-19T02:47:25.935306+00:00 app[web.1]: }
  • Is this safe to do?
  • Can this be suppressed? It makes the logs harder to read during normal operation. I understand it's nice to have for debugging purposes.

Bot crashes approximately one hour after coming online

Context

When the bot starts, it will receive an access token with which it can create a websocket connection. It seems that this websocket connecation expires roughly every 10 minutes, and js-tale diligently recreates the connection automatically.

But after 6 to 7 recreations (so after about an hour) the next recreation will fail with a 401 Unauthorized status code. Worse, this exception is unhandled which means the whole bot comes crashing down.

Observation

5/7/2021, 11:57:07 AM - [ApiConnection] Setting up https client
5/7/2021, 11:57:07 AM - [ApiConnection] Deconding token
5/7/2021, 11:57:07 AM - [ApiConnection] User ID: 1529569283
5/7/2021, 11:57:07 AM - [ApiConnection] Username: voodoo mod
5/7/2021, 11:57:08 AM - [LiveList] Subscribed to groups delete
5/7/2021, 11:57:08 AM - [LiveList] Subscribed to groups create
5/7/2021, 11:57:09 AM - [LiveList] Subscribed to invites delete
5/7/2021, 11:57:09 AM - [LiveList] Subscribed to invites create
5/7/2021, 11:57:09 AM - [GroupManager] Accepted all group invites
5/7/2021, 11:57:09 AM - [GroupManager] Enabling automatic console for all groups
5/7/2021, 11:57:09 AM - [Express] API listening on port 3000
5/7/2021, 11:57:32 AM - [Group] Joined 292966562 - Bot Test
5/7/2021, 11:57:32 AM - [Group] Enabling automatic console for Bot Test
5/7/2021, 11:57:33 AM - [GroupInvite] Accepted invite to Bot Test (292966562)
5/7/2021, 11:57:33 AM - [LiveList] Subscribed to Bot Test servers delete
5/7/2021, 11:57:33 AM - [LiveList] Subscribed to Bot Test servers create
5/7/2021, 11:57:33 AM - [Group] Subscribed to Bot Test status
5/7/2021, 12:07:33 PM - [SubscriptionManager] Websocket expired, recreating
5/7/2021, 12:17:49 PM - [SubscriptionManager] Websocket expired, recreating
5/7/2021, 12:28:06 PM - [SubscriptionManager] Websocket expired, recreating
5/7/2021, 12:38:23 PM - [SubscriptionManager] Websocket expired, recreating
5/7/2021, 12:48:40 PM - [SubscriptionManager] Websocket expired, recreating
5/7/2021, 12:58:56 PM - [SubscriptionManager] Websocket expired, recreating
5/7/2021, 1:09:13 PM - [SubscriptionManager] Websocket expired, recreating

C:\Users\Surrogator\code\att-voodoo-server\node_modules\ws\lib\websocket.js:604
      abortHandshake(
      ^
Error: Unexpected server response: 401

Desired outcome

js-tale uses the API's refresh token to request a new access token when the current access token is about to expire. Refreshing the access token will allow the bot to keep recreating websockets, so that it can run indefinitely.

Bot tries to connect to shutdown server, causing unhandled connection errors

Observations

When a server shuts down, js-tale attempts to connect to that server. This issue is similar to #11, which describes js-tale connecting on every server status update.

When the server shuts down, that counts as a status update, and js-tale will connect to the server again. Only this time it will fail because the server is not there anymore.

Here's a dump of my logs.

2021-07-01T01:03:50.803085+00:00 heroku[web.1]: Restarting
2021-07-01T01:03:50.824360+00:00 heroku[web.1]: State changed from up to starting
2021-07-01T01:03:51.979456+00:00 heroku[web.1]: Stopping all processes with SIGTERM

7/1/2021, 1:03:59 AM - [ApiConnection] Setting up https client
7/1/2021, 1:03:59 AM - [ApiConnection] Decoding token
7/1/2021, 1:03:59 AM - [ApiConnection] User ID: 1529569283
7/1/2021, 1:03:59 AM - [ApiConnection] Username: voodoo mod
7/1/2021, 1:04:29 AM - [LiveList] Subscribed to groups delete
7/1/2021, 1:04:31 AM - [LiveList] Subscribed to groups create
7/1/2021, 1:04:32 AM - [Group] Joined (... other servers omitted ...)
7/1/2021, 1:04:32 AM - [Group] Joined 773758417 - pepe
7/1/2021, 1:04:32 AM - [Group] Joined (... other servers omitted ...)
7/1/2021, 1:04:48 AM - [LiveList] Subscribed to (... other servers omitted ...)
7/1/2021, 1:04:49 AM - [LiveList] Subscribed to pepe servers create
7/1/2021, 1:04:49 AM - [LiveList] Subscribed to (... other servers omitted ...)
7/1/2021, 1:04:58 AM - [GroupManager] Accepted all group invites
7/1/2021, 1:04:59 AM - [LiveList] Subscribed to (... other servers omitted ...)
7/1/2021, 1:04:59 AM - [LiveList] Subscribed to pepe servers delete
7/1/2021, 1:04:59 AM - [LiveList] Subscribed to (... other servers omitted ...)
7/1/2021, 1:04:59 AM - [Group] Subscribed to pepe status
7/1/2021, 1:04:59 AM - [LiveList] Subscribed to (... other servers omitted ...)
7/1/2021, 1:04:59 AM - [Server] pepe received status. Online: true. Players: 0
7/1/2021, 1:04:59 AM - [Group] Refreshed server info for pepe (1947466580)
7/1/2021, 1:05:01 AM - [GroupManager] Enabling automatic console for all groups
7/1/2021, 1:05:01 AM - [Group] Enabling (... other servers omitted ...)
7/1/2021, 1:05:01 AM - [Group] Enabling automatic console for pepe
7/1/2021, 1:05:01 AM - [ServerConnection] Creating server connection
7/1/2021, 1:05:01 AM - [ServerConnection] Doing initialize
7/1/2021, 1:05:01 AM - [ServerConnection] Connecting to pepe
7/1/2021, 1:05:01 AM - [Voodoo] Voodoo Server is online
7/1/2021, 1:05:01 AM - [Express] API listening on port 8733
State changed from starting to up
Connecting to 34.212.181.102:7370
Connecting to 34.223.108.179:7394
Connecting to 34.219.192.150:7744
Connecting to 34.223.250.77:7257
Connecting to 44.229.14.94:7671
Resolving connection!
Connection Succeeded, Authenticated as: 1529569283 - voodoo mod
7/1/2021, 1:05:02 AM - [ServerConnection] Subscribing to PlayerJoined
7/1/2021, 1:05:02 AM - [ServerConnection] Subscribing to PlayerLeft
Resolving connection!
Connection Succeeded, Authenticated as: 1529569283 - voodoo mod
7/1/2021, 1:05:02 AM - [ServerConnection] Subscribing to PlayerJoined
7/1/2021, 1:05:02 AM - [ServerConnection] Subscribing to PlayerLeft
Connecting to 52.40.17.250:7161
7/1/2021, 1:05:02 AM - [ServerConnection] Subscribed to PlayerJoined : Success
7/1/2021, 1:05:02 AM - [ServerConnection] Subscribed to PlayerJoined : Success
7/1/2021, 1:05:02 AM - [ServerConnection] Subscribed to PlayerLeft : Success
7/1/2021, 1:05:02 AM - [ServerConnection] Subscribed to PlayerLeft : Success
(... output omitted ...)
7/1/2021, 1:05:02 AM - [Bot] Connected to pepe
(... output omitted ...)
7/1/2021, 1:09:22 AM - [Server] pepe received status. Online: true. Players: 0
7/1/2021, 1:09:22 AM - [ServerConnection] Doing initialize
7/1/2021, 1:09:22 AM - [ServerConnection] Connecting to pepe
Connecting to 52.40.17.250:7161
Resolving connection!
Connection Succeeded, Authenticated as: 1529569283 - voodoo mod
7/1/2021, 1:09:24 AM - [ServerConnection] Connection closed
CloseEvent {
  target: <ref *1> WebSocket {
    _events: [Object: null prototype] {
      open: [Function],
      message: [Function],
      error: [Function],
      close: [Function]
    },
    _eventsCount: 4,
    _maxListeners: undefined,
    _binaryType: 'nodebuffer',
    _closeCode: 1006,
    _closeFrameReceived: false,
    _closeFrameSent: false,
    _closeMessage: '',
    _closeTimer: null,
    _extensions: {},
    _protocol: '',
    _readyState: 3,
    _receiver: Receiver {
      _writableState: [WritableState],
      _events: [Object: null prototype] {},
      _eventsCount: 0,
      _maxListeners: undefined,
      _binaryType: 'nodebuffer',
      _extensions: {},
      _isServer: false,
      _maxPayload: 104857600,
      _bufferedBytes: 0,
      _buffers: [],
      _compressed: false,
      _payloadLength: 161,
      _mask: undefined,
      _fragmented: 0,
      _masked: false,
      _fin: true,
      _opcode: 1,
      _totalPayloadLength: 0,
      _messageLength: 0,
      _fragments: [],
      _state: 0,
      _loop: false,
      [Symbol(kCapture)]: false,
      [Symbol(websocket)]: [Circular *1]
    },
    _sender: Sender {
      _extensions: {},
      _socket: [Socket],
      _firstFragment: true,
      _compress: false,
      _bufferedBytes: 0,
      _deflating: false,
      _queue: []
    },
    _socket: Socket {
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: null,
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: null,
      _server: null,
      parser: null,
      _httpMessage: null,
      timeout: 0,
      write: [Function: writeAfterFIN],
      [Symbol(async_id_symbol)]: 5030,
      [Symbol(kHandle)]: null,
      [Symbol(kSetNoDelay)]: true,
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kBytesRead)]: 294,
      [Symbol(kBytesWritten)]: 434,
      [Symbol(RequestTimeout)]: undefined,
      [Symbol(websocket)]: undefined
    },
    _bufferedAmount: 0,
    _isServer: false,
    _redirects: 0,
    _url: 'ws://52.40.17.250:7161',
    _req: null,
    [Symbol(kCapture)]: false
  },
  type: 'close',
  wasClean: false,
  reason: '',
  code: 1006,
  logger: '[ServerConnection] ',
  timestamp: 1625101764642
}
7/1/2021, 1:09:24 AM - [Server] Console to pepe disconnected.
7/1/2021, 1:09:24 AM - [Voodoo] Removed all players of server 1947466580
7/1/2021, 1:09:24 AM - [Bot] Disconnected from pepe
7/1/2021, 1:09:24 AM - [ServerConnection] Connection closed
CloseEvent {
  target: <ref *1> WebSocket {
    _events: [Object: null prototype] {
      open: [Function],
      message: [Function],
      error: [Function],
      close: [Function]
    },
    _eventsCount: 4,
    _maxListeners: undefined,
    _binaryType: 'nodebuffer',
    _closeCode: 1006,
    _closeFrameReceived: false,
    _closeFrameSent: false,
    _closeMessage: '',
    _closeTimer: null,
    _extensions: {},
    _protocol: '',
    _readyState: 3,
    _receiver: Receiver {
      _writableState: [WritableState],
      _events: [Object: null prototype] {},
      _eventsCount: 0,
      _maxListeners: undefined,
      _binaryType: 'nodebuffer',
      _extensions: {},
      _isServer: false,
      _maxPayload: 104857600,
      _bufferedBytes: 0,
      _buffers: [],
      _compressed: false,
      _payloadLength: 486,
      _mask: undefined,
      _fragmented: 0,
      _masked: false,
      _fin: true,
      _opcode: 1,
      _totalPayloadLength: 0,
      _messageLength: 0,
      _fragments: [],
      _state: 0,
      _loop: false,
      [Symbol(kCapture)]: false,
      [Symbol(websocket)]: [Circular *1]
    },
    _sender: Sender {
      _extensions: {},
      _socket: [Socket],
      _firstFragment: true,
      _compress: false,
      _bufferedBytes: 0,
      _deflating: false,
      _queue: []
    },
    _socket: Socket {
      connecting: false,
      _hadError: false,
      _parent: null,
      _host: null,
      _readableState: [ReadableState],
      _events: [Object: null prototype],
      _eventsCount: 2,
      _maxListeners: undefined,
      _writableState: [WritableState],
      allowHalfOpen: false,
      _sockname: null,
      _pendingData: null,
      _pendingEncoding: '',
      server: null,
      _server: null,
      parser: null,
      _httpMessage: null,
      timeout: 0,
      write: [Function: writeAfterFIN],
      [Symbol(async_id_symbol)]: 2542,
      [Symbol(kHandle)]: null,
      [Symbol(kSetNoDelay)]: true,
      [Symbol(lastWriteQueueSize)]: 0,
      [Symbol(timeout)]: null,
      [Symbol(kBuffer)]: null,
      [Symbol(kBufferCb)]: null,
      [Symbol(kBufferGen)]: null,
      [Symbol(kCapture)]: false,
      [Symbol(kBytesRead)]: 1856,
      [Symbol(kBytesWritten)]: 588,
      [Symbol(RequestTimeout)]: undefined,
      [Symbol(websocket)]: undefined
    },
    _bufferedAmount: 0,
    _isServer: false,
    _redirects: 0,
    _url: 'ws://52.40.17.250:7161',
    _req: null,
    [Symbol(kCapture)]: false
  },
  type: 'close',
  wasClean: false,
  reason: '',
  code: 1006,
  logger: '[ServerConnection] ',
  timestamp: 1625101764655
}
7/1/2021, 1:09:24 AM - [Server] Console to pepe disconnected.
7/1/2021, 1:09:24 AM - [Voodoo] Removed all players of server 1947466580
7/1/2021, 1:09:24 AM - [Bot] Disconnected from pepe

GroupManager does not handle kick events

Context

When you invite a js-tale bot to your server group, it will accept the invitation immediately (or as soon as the bot comes online). But when you kick a bot members from your server group, the js-tale bot does not react accordingly. It still thinks it's part of the server group, with whatever implications this has. That could be problematic as you might try to send commands to a server you longer have access to.

Desired outcome

When bots are kicked (and by extension banned), js-tale needs to react appropriately to prevent operating on outdated assumptions.

Bot does not accept invites from groups it was kicked from during its current lifecycle

Context

When js-tale is running, it seems capable of accepting group invites, and also responds to being kicked by leaving the group. However, being re-invited to a group it was kicked from does not make js-tale accept the invite during the same "session". To accept an invite to a group twice, you have to restart the bot. It will then accept the pending invite upon booting.

Desired outcome

The bot should be able to accept invitations and handle being kicked multiple times for the same server group over the course of its lifecycle. It's likely that bots running js-tale will only realistically reboot when new bot logic is being deployed. This means that a bot might run for days or weeks at a time and it should therefore be able to handle being invited and kicked from a group more than once.

Steps to reproduce:

  • Make sure you kick you bot from the server group before you run the bot.
  • Run the bot.
  • Invite the bot account. The bot accepts the invite.
  • Kick the bot account. The bot leaves the group.
  • Invite the bot account. ⚠️ Nothing happens.
  • Restart the bot. Pending invite is accepted now.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.