Example #1
0
  // Called when a confirmed death has happened with the corrected Id of the killer, if any. The
  // |event| contains the { playerid, killerid, reason } about the death.
  onPlayerResolvedDeath(event) {
    const player = server.playerManager.getById(event.playerid);
    if (!player)
      return;

    const userId = player.isRegistered() ? player.userId : null;
    const position = player.position;

    const killer = server.playerManager.getById(event.killerid);
    if (!killer)
      this.recorder_.writeDeath(userId, position, event.reason);
    else
      this.recorder_.writeKill(userId, killer.isRegistered() ? killer.userId : null, position, event.reason);
  }
Example #2
0
  // Called when a player has fired from a weapon. Only |event|s that hit a player or a vehicle will
  // be recorded, with all available information and the distance of the shot.
  onPlayerWeaponShot(event) {
    if (event.hittype != 1 /* BULLET_HIT_TYPE_PLAYER */ &&
        event.hittype != 2 /* BULLET_HIT_TYPE_VEHICLE */)
      return;

    const player = server.playerManager.getById(event.playerid);
    if (!player)
      return;

    const userId = player.isRegistered() ? player.userId : null;
    const position = player.position;

    let targetUserId = null;
    if (event.hittype == 1 /* BULLET_HIT_TYPE_PLAYER */) {
      const targetPlayer = server.playerManager.getById(event.hitid);
      if (targetPlayer && targetPlayer.isRegistered())
        targetUserId = targetPlayer.userId;
    }

    // TODO(Russell): It would be great if we could consider the driver of the vehicle that's being
    // hit here as well, but iterating over all players for every shot would be too expensive :/.

    const targetDistance = new Vector(event.fX, event.fY, event.fZ).magnitude;

    this.recorder_.writeHit(userId, targetUserId, targetDistance, event.weaponid, position);
  }
Example #3
0
  // Called when a player somehow leaves the server.
  onPlayerDisconnect(event) {
    if (!this.playerSessionIdMap_.has(event.playerid))
      return;

    const sessionId = this.playerSessionIdMap_.get(event.playerid);
    this.recorder_.writeUpdateSessionAtDisconnect(sessionId, Date.now());

    this.playerSessionIdMap_.delete(event.playerid);
  }
Example #4
0
  // Called when a vehicle has died. The |event| contains the { vehicleid }.
  onVehicleDeath(event) {
    const vehicle = new Vehicle(event.vehicleid);
    if (!vehicle)
      return;

    const modelId = vehicle.modelId;
    const position = vehicle.position;

    this.recorder_.writeVehicleDeath(modelId, position);
  }
Example #5
0
  // Called at the moment a player logged in with a correct password. In this successful case we can
  // update the session with the userid of the player.
  onPlayerLogin(event) {
    const player = server.playerManager.getById(event.playerid);
    if (!player || player.isNpc())
      return;

    if (!this.playerSessionIdMap_.has(player.id))
      return;

    const sessionId = this.playerSessionIdMap_.get(player.id);
    this.recorder_.writeUpdateSessionAtLogin(sessionId, player.userId);
  }
Example #6
0
  // Called at the moment a player with an already used nickname wants to play as guest. In that
  // case his name changes and we should adjust that in the db.
  onPlayerGuestLogin(event) {
    const player = server.playerManager.getById(event.playerId);
    if (!player || player.isNpc())
      return;

    if (!this.playerSessionIdMap_.has(player.id))
      return;

    const sessionId = this.playerSessionIdMap_.get(player.id);
    const guestPlayerName = pawnInvoke('GetPlayerName', 'iS', player.id);

    this.recorder_.writeUpdateSessionAtGuestLogin(sessionId, guestPlayerName);
  }
Example #7
0
  // Called when a player connects. Logs the name, numeric variant of their ip and hashed serial to
  // the database to be able to keep track of them.
  onPlayerConnect(event) {
    const player = server.playerManager.getById(event.playerid);
    if (!player || player.isNpc())
      return;

    const numericIpAddress = this.ip2long(player.ip);
    const hashedGpci = Murmur3Hash.generateHash(player.gpci);

    this.announce_().announceToIRC(JoinIpGpciTag, player.id, player.ip, player.name, hashedGpci);

    this.recorder_.getIdFromWriteInsertSessionAtConnect(player.name, numericIpAddress, hashedGpci).then (result => {
      this.playerSessionIdMap_.set(player.id, result.sessionId);
    });
  }