void engine_gameroom_process_map_changes(engine *p, game_room *p_gr) {
    int i, n = 0;
    warzone *p_wz = &p_gr->zone;
    network_command_prepare(p->p_cmd_out, NCT_MAP_BLOCK_CHANGES);
    network_command_append_byte(p->p_cmd_out, 0);
    for (i = 0; i < p_wz->map_change_count; i++) {
        if (p->p_cmd_out->length + NETWORK_COMMAND_BLOCK_CHANGE_LENGTH >= NETWORK_COMMAND_DATA_LENGTH) {
            write_hex_byte(p->p_cmd_out->data, n);
            engine_bc_command(p, p_gr, p->p_cmd_out);
            network_command_prepare(p->p_cmd_out, NCT_MAP_BLOCK_CHANGES);
            n = 0;
        }
        network_command_append_short(p->p_cmd_out, p_wz->map_change_buffer[i].x);
        network_command_append_short(p->p_cmd_out, p_wz->map_change_buffer[i].y);
        network_command_append_char(p->p_cmd_out, char_from_num(p_wz->map_change_buffer[i].b));
        n++;
    }

    if (n > 0) {
        write_hex_byte(p->p_cmd_out->data, n);
        engine_bc_command(p, p_gr, p->p_cmd_out);
    }

    p_wz->map_change_count = 0;
}
Пример #2
0
void cmd_reply(u08 cmd, u08 num)
{
  write_begin();
  write_cmd(cmd);
  write_hex_byte(num);
  write_end();
}
Пример #3
0
/* send a status reply */
void cmd_status(u08 status)
{
  write_begin();
  write_cmd(':');
  write_hex_byte(status);
  write_end();
}
Пример #4
0
int _engine_authorize_connection(engine *p, network_command cmd) {
    net_client* p_cli;
    network_command cmd_out;
    my_byte reintroduce;
    int socket = cmd.origin_socket;
    
    
    if (cmd.type != NCT_LEAD_INTRODUCE) {
        glog(LOG_FINE, "Authorization of connection %02d failed because command"
                "type was not correct. Expected %d, got %d", socket, NCT_LEAD_INTRODUCE, cmd.type);
        return 1;
    }
    if (cmd.length < 2) {
        glog(LOG_FINE, "Authorization of connection %02d failed because command"
                " was too short", socket);
        return 1;
    }

    reintroduce = read_hex_byte(cmd.data);
    if (reintroduce) {
        p_cli = engine_client_by_secret(p, cmd.data + 2);
        if (p_cli == NULL) {
            reintroduce = 0;
        } else {
            if (p_cli->status != NET_CLIENT_STATUS_DISCONNECTED) {
                glog(LOG_FINE, "Reauthorization of connection %02d failed "
                        "because command client is not disconnected", socket);
                return 1;
            }
        }

    }
    if (!reintroduce) {
        p_cli = engine_first_free_client_offset(p);
    }

    if (p_cli == NULL) {
        glog(LOG_FINE, "Authorization of socket %02d failed because there"
                "was no more room for new client", socket);
        return 1;
    }

    p->resources->con_to_cli[socket] = p_cli - p->resources->clients;
    if (!reintroduce) {
        net_client_init(p_cli, p->resources->connections + socket);
        strrand(p_cli->connection_secret, NET_CLIENT_SECRET_LENGTH);
        p_cli->connection_secret[NET_CLIENT_SECRET_LENGTH] = '\0';
        p_cli->room_id = ITEM_EMPTY;
    } else {
        p_cli->connection = p->resources->connections + socket;
    }
    p_cli->status = NET_CLIENT_STATUS_CONNECTED;

    network_command_prepare(&cmd_out, NCT_LEAD_INTRODUCE);
    write_hex_byte(cmd_out.data, reintroduce);
    memcpy(cmd_out.data + 2, p_cli->connection_secret, NET_CLIENT_SECRET_LENGTH);

    netadapter_send_command(p->p_netadapter, p_cli->connection, &cmd_out);

    if (reintroduce) {
        _engine_authorize_reconnect(p, p_cli);
    } else {
        glog(LOG_INFO, "Connection %02d authorized as client %02d", socket, p->resources->con_to_cli[socket]);
    }


    return 0;
}