예제 #1
0
void log_t::damage_event( action_t* a,
                          double    dmg,
                          int       dmg_type )
{
  if ( ! write_timestamp( a -> sim ) ) return;

  if ( is_swing( a ) )
  {
    util_t::fprintf( a -> sim -> log_file, "SWING_DAMAGE,%s,%s", a -> player -> id(), a -> sim -> target -> id() );
  }
  else
  {
    util_t::fprintf( a -> sim -> log_file, "%s,%s,%s,%d,\"%s\",0x%X",
                     ( ( dmg_type == DMG_DIRECT ) ? "SPELL_DAMAGE" : "SPELL_PERIODIC_DAMAGE" ),
                     a -> player -> id(),
                     a -> sim -> target -> id(),
                     ( a -> id ? a -> id : default_id( a -> sim, a -> name() ) ),
                     a -> name(),
                     school_id( a -> school ) );
  }

  util_t::fprintf( a -> sim -> log_file,
                   ",%d,0,%d,%d,0,%d,%s,%s,nil\n",
                   ( int ) dmg,
                   school_id( a -> school ),
                   ( int ) a -> resisted_dmg,
                   ( int ) a -> blocked_dmg,
                   ( ( a -> result == RESULT_CRIT   ) ? "1" : "nil" ),
                   ( ( a -> result == RESULT_GLANCE ) ? "1" : "nil" ) );

}
예제 #2
0
void log_t::start_event( action_t* a )
{
  if ( ! write_timestamp( a -> sim ) ) return;

  util_t::fprintf( a -> sim -> log_file,
                   "SPELL_CAST_START,%s,%s,%d,\"%s\",0x%X\n",
                   a -> player -> id(),
                   nil_target_id(),
                   ( a -> id ? a -> id : default_id( a -> sim, a -> name() ) ),
                   a -> name(),
                   school_id( a -> school ) );
}
예제 #3
0
void log_t::aura_loss_event( player_t*   p,
                             const char* name,
                             int         id )
{
  if ( ! write_timestamp( p -> sim ) ) return;

  util_t::fprintf( p -> sim -> log_file,
                   "SPELL_AURA_REMOVED,%s,%s,%d,\"%s\",0x%X,BUFF\n",
                   p -> id(),
                   p -> id(),
                   ( id ? id : default_id( p -> sim, name ) ),
                   name,
                   school_id( SCHOOL_PHYSICAL ) );
}
예제 #4
0
void log_t::miss_event( action_t* a )
{
  if ( ! write_timestamp( a -> sim ) ) return;

  util_t::fprintf( a -> sim -> log_file,
                   "%s,%s,%s,%d,\"%s\",0x%X,%s\n",
                   ( is_swing( a ) ? "SWING_MISSED" : "SPELL_MISSED" ),
                   a -> player -> id(),
                   a -> player -> id(),
                   ( a -> id ? a -> id : default_id( a -> sim, a -> name() ) ),
                   a -> name(),
                   school_id( a -> school ),
                   result_name( a -> result ) );
}
예제 #5
0
void log_t::resource_gain_event( player_t* p,
                                 int       resource,
                                 double    amount,
                                 double    actual_amount,
                                 gain_t*   source )
{
  if ( ! write_timestamp( p -> sim ) ) return;

  // FIXME! Unable to tell from which player this resource gain occurred, so we assume it is from the player himself.

  if ( resource == RESOURCE_HEALTH )
  {
    util_t::fprintf( p -> sim -> log_file,
                     "SPELL_PERIODIC_HEAL,%s,%s,%d,\"%s\",0x%X,%d,%d,nil\n",
                     p -> id(),
                     p -> id(),
                     ( source -> id ? source -> id : default_id( p -> sim, source -> name() ) ),
                     source -> name(),
                     school_id( SCHOOL_PHYSICAL ),
                     ( int ) actual_amount,
                     ( int ) ( amount - actual_amount ) );
  }
  else
  {
    util_t::fprintf( p -> sim -> log_file,
                     "SPELL_ENERGIZE,%s,%s,%d,\"%s\",0x%X,%d,%d\n",
                     p -> id(),
                     p -> id(),
                     ( source -> id ? source -> id : default_id( p -> sim, source -> name() ) ),
                     source -> name(),
                     school_id( SCHOOL_PHYSICAL ),
                     ( int ) actual_amount,
                     resource_id( resource ) );
  }

}
예제 #6
0
int harmony_join(hdesc_t *hdesc, const char *host, int port, const char *name)
{
    int i, perf_len;
    int apply_argv = (hdesc->state < HARMONY_STATE_CONNECTED);
    char *cfgval;

    /* Verify that we have *at least* one variable bound, and that
     * this descriptor isn't already associated with a tuning
     * session.
     */
    if (hdesc->ptr_len == 0) {
        hdesc->errstr = "No variables bound to Harmony session";
        errno = EINVAL;
        return -1;
    }

    if (hdesc->state >= HARMONY_STATE_READY) {
        hdesc->errstr = "Descriptor already joined with an existing session";
        errno = EINVAL;
        return -1;
    }

    if (hdesc->state == HARMONY_STATE_INIT) {
        hdesc->socket = tcp_connect(host, port);
        if (hdesc->socket < 0) {
            hdesc->errstr = "Error establishing TCP connection with server";
            return -1;
        }

        if (hdesc->id == NULL)
            hdesc->id = default_id(hdesc->socket);
        hdesc->state = HARMONY_STATE_CONNECTED;

        hdesc->sess.sig.name = stralloc(name);
        if (!hdesc->sess.sig.name) {
            hdesc->errstr = "Error allocating memory for signature name";
            return -1;
        }
    }

    /* Prepare a Harmony message. */
    hmesg_scrub(&hdesc->mesg);
    hdesc->mesg.data.join = HSIGNATURE_INITIALIZER;
    if (hsignature_copy(&hdesc->mesg.data.join, &hdesc->sess.sig) < 0) {
        hdesc->errstr = "Internal error copying signature data";
        return -1;
    }

    /* send the client registration message */
    if (send_request(hdesc, HMESG_JOIN) != 0)
        return -1;

    if (hdesc->mesg.status != HMESG_STATUS_OK) {
        hdesc->errstr = "Invalid message received";
        errno = EINVAL;
        return -1;
    }

    hsignature_fini(&hdesc->sess.sig);
    if (hsignature_copy(&hdesc->sess.sig, &hdesc->mesg.data.join) < 0) {
        hdesc->errstr = "Error copying received signature structure";
        return -1;
    }

    /* Apply argv configuration directives now, if necessary. */
    if (apply_argv) {
        for (i = 0; i < hdesc->cmd_len; ++i) {
            char *key, *val, *cpy;
            cpy = stralloc(hdesc->cmd[i]);
            if (hcfg_parse(cpy, &key, &val)) {
                /* This should never fail, but just in case. */
                hdesc->errstr = "Error parsing argv config directive.";
                return -1;
            }
            if (hcfg_set(hdesc->sess.cfg, key, val)) {
                hdesc->errstr = "Error applying argv config directive.";
                return -1;
            }
            free(cpy);
        }
    }

    cfgval = harmony_getcfg(hdesc, CFGKEY_PERF_COUNT);
    if (cfgval) {
        perf_len = atoi(cfgval);
        if (perf_len < 1) {
            hdesc->errstr = "Invalid value for " CFGKEY_PERF_COUNT;
            return -1;
        }
        free(cfgval);
    }
    else {
        perf_len = DEFAULT_PERF_COUNT;
    }

    hdesc->perf = hperf_alloc(perf_len);
    if (!hdesc->perf) {
        hdesc->errstr = "Error allocating performance array.";
        return -1;
    }

    hdesc->state = HARMONY_STATE_READY;
    return 0;
}
예제 #7
0
int harmony_launch(hdesc_t *hdesc, const char *host, int port)
{
    int i;

    /* Sanity check input */
    if (hdesc->sess.sig.range_len < 1) {
        hdesc->errstr = "No tuning variables defined";
        errno = EINVAL;
        return -1;
    }

    if (!host && !getenv("HARMONY_S_HOST")) {
        char *path;
        const char *home;

        /* Provide a default name, if one isn't defined. */
        if (!hdesc->sess.sig.name) {
            if (hsignature_name(&hdesc->sess.sig, "NONAME"))
                return -1;
        }

        /* Find the Active Harmony installation. */
        home = getenv("HARMONY_HOME");
        if (!home) {
            hdesc->errstr = "No host or HARMONY_HOME specified";
            return -1;
        }

        if (hcfg_set(hdesc->sess.cfg, CFGKEY_HARMONY_HOME, home) != 0) {
            hdesc->errstr = "Could not set " CFGKEY_HARMONY_HOME;
            return -1;
        }

        /* Fork a local tuning session. */
        path = sprintf_alloc("%s/libexec/session-core", home);
        hdesc->socket = socket_launch(path, NULL, NULL);
        free(path);
    }
    else {
        hdesc->socket = tcp_connect(host, port);
    }

    if (hdesc->socket < 0) {
        hdesc->errstr = strerror(errno);
        return -1;
    }

    /* Prepare a default client id, if necessary. */
    if (hdesc->id == NULL)
        hdesc->id = default_id(hdesc->socket);
    hdesc->state = HARMONY_STATE_CONNECTED;

    /* Apply argv configuration directives now, if necessary. */
    for (i = 0; i < hdesc->cmd_len; ++i) {
        char *key, *val, *cpy;
        cpy = stralloc(hdesc->cmd[i]);
        if (hcfg_parse(cpy, &key, &val) == NULL) {
            /* This should never fail, but just in case. */
            hdesc->errstr = "Internal error parsing argv config directive.";
            return -1;
        }
        if (hcfg_set(hdesc->sess.cfg, key, val) != 0) {
            hdesc->errstr = "Internal error applying argv config directive.";
            return -1;
        }
        free(cpy);
    }

    /* Prepare a Harmony message. */
    hmesg_scrub(&hdesc->mesg);
    hsession_init(&hdesc->mesg.data.session);
    hsession_copy(&hdesc->mesg.data.session, &hdesc->sess);

    return send_request(hdesc, HMESG_SESSION);
}