Exemplo n.º 1
0
static void
connection_free(struct connection *c)
{
    struct linked_server *ls, *n;

    connection_check(c);

    list_for_each_entry_safe(ls, n, &c->servers, siblings)
        connection_server_dispose(c, ls);

    connection_disconnect(c);

    if (c->client.reconnecting)
        event_del(&c->client.reconnect_event);

    client_version_free(&c->client_version);

    poison(c, sizeof(*c));
    free(c);
}
Exemplo n.º 2
0
int connection_new(struct instance *instance,
                   int server_socket,
                   struct connection **connectionp) {
    struct connection *c;
    struct linked_server *ls;
    int ret;

    c = calloc(1, sizeof(*c));
    if (c == NULL)
        return ENOMEM;

    c->instance = instance;
    c->background = instance->config->background;
    c->autoreconnect = instance->config->autoreconnect;

    INIT_LIST_HEAD(&c->client.world.items);
    INIT_LIST_HEAD(&c->client.world.mobiles);
    INIT_LIST_HEAD(&c->servers);

    if (instance->config->client_version != NULL) {
        ret = client_version_set(&c->client_version,
                                 instance->config->client_version);
        if (ret > 0)
            log(2, "configured client version '%s', protocol '%s'\n",
                c->client_version.packet->version,
                protocol_name(c->client_version.protocol));
    }

    ls = connection_server_new(c, server_socket);
    if (ls == NULL) {
        ret = errno;
        connection_free(c);
        return ret;
    }

    connection_check(c);

    *connectionp = c;

    return 0;
}
Exemplo n.º 3
0
bool script_program_execute(struct program_config *c)
{
//rom image load
	struct romimage rom;
	if(nesfile_load(&c->log, c->target, &rom) == false){
		c->log.append(c->log.object, wgT("ROM image open error"));
		return false;
	}
//variable init
	c->mappernum = rom.mappernum;
	c->vram_mirroring = rom.mirror;
	c->cpu.memory.name = wgT("Program Flash");
	if(memory_image_init(&rom.cpu_rom, &c->cpu, &c->log) == false){
		nesbuffer_free(&rom, 0);
		return false;
	}
	c->ppu.memory.name = wgT("Charcter Flash");
	if(memory_image_init(&rom.ppu_rom, &c->ppu, &c->log) == false){
		nesbuffer_free(&rom, 0);
		return false;
	}
//reader initalize
	c->handle = c->control->open(c->except, &c->log);
	if(c->handle == NULL){
		c->log.append(c->log.object, wgT("reader open error\n"));
		nesbuffer_free(&rom, 0);
		return false;
	}
//program start, reader finalize
	if(connection_check(c->handle, &c->log, c->cpu.access, c->ppu.access) == false){
		nesbuffer_free(&rom, 0);
		c->control->close(c->handle);
		return false;
	}
	bool ret = zendan(c);
	c->control->close(c->handle);
	c->handle = NULL;
	nesbuffer_free(&rom, 0);
	return ret;
}