Skip to forum content

You are not logged in. Please login or register.


forums.pvpgn.pro → [RU] The Source Code → список игр

Pages 1

You must login or register to post a reply

RSS topic feed

Posts: 10

1 (edited by launcher 20.12.2016 18:02)

Topic: список игр

добрый день форумчане где можно в  исходниках pvpgn найти . а именно найти строки которые показывает созданные игры
http://img.megatorrents.kg/images/644ilS12CdO6d.png

2

Re: список игр

в handle_bnet.cpp связанное с клиентом:

static int _client_gamelistreq(t_connection * c, t_packet const *const packet)
{
    t_packet *rpacket;
    char const *gamename;
    char const *gamepass;
    unsigned short bngtype;
    t_game_type gtype;
    t_clienttag clienttag;
    t_game *game;
    t_server_gamelistreply_game glgame;
    unsigned int addr;
    unsigned short port;
    char clienttag_str[5];

    if (packet_get_size(packet) < sizeof(t_client_gamelistreq)) {
    eventlog(eventlog_level_error, __FUNCTION__, "[%d] got bad GAMELISTREQ packet (expected %lu bytes, got %u)", conn_get_socket(c), sizeof(t_client_gamelistreq), packet_get_size(packet));
    return -1;
    }

    if (!(gamename = packet_get_str_const(packet, sizeof(t_client_gamelistreq), MAX_GAMENAME_LEN))) {
    eventlog(eventlog_level_error, __FUNCTION__, "[%d] got bad GAMELISTREQ (missing or too long gamename)", conn_get_socket(c));
    return -1;
    }

    if (!(gamepass = packet_get_str_const(packet, sizeof(t_client_gamelistreq) + std::strlen(gamename) + 1, MAX_GAMEPASS_LEN))) {
    eventlog(eventlog_level_error, __FUNCTION__, "[%d] got bad GAMELISTREQ (missing or too long password)", conn_get_socket(c));
    return -1;
    }

    bngtype = bn_short_get(packet->u.client_gamelistreq.gametype);
    clienttag = conn_get_clienttag(c);
    gtype = bngreqtype_to_gtype(clienttag, bngtype);
    if (!(rpacket = packet_create(packet_class_bnet)))
    return -1;
    packet_set_size(rpacket, sizeof(t_server_gamelistreply));
    packet_set_type(rpacket, SERVER_GAMELISTREPLY);

    bn_int_set(&rpacket->u.server_gamelistreply.sstatus, 0);

    /* specific game requested? */
    if (gamename[0] != '\0') {
    eventlog(eventlog_level_debug, __FUNCTION__, "[%d] GAMELISTREPLY looking for specific game tag=\"%s\" bngtype=0x%08x gtype=%d name=\"%s\" pass=\"%s\"", conn_get_socket(c), tag_uint_to_str(clienttag_str, clienttag), bngtype, (int) gtype, gamename, gamepass);
    if ((game = gamelist_find_game(gamename, clienttag, gtype))) {
        /* game found but first we need to make sure everything is OK */
        bn_int_set(&rpacket->u.server_gamelistreply.gamecount, 0);
        switch (game_get_status(game)) {
        case game_status_started:
            bn_int_set(&rpacket->u.server_gamelistreply.sstatus, SERVER_GAMELISTREPLY_GAME_SSTATUS_STARTED);
            eventlog(eventlog_level_debug, __FUNCTION__, "[%d] GAMELISTREPLY found but started", conn_get_socket(c));
            break;
        case game_status_full:
            bn_int_set(&rpacket->u.server_gamelistreply.sstatus, SERVER_GAMELISTREPLY_GAME_SSTATUS_FULL);
            eventlog(eventlog_level_debug, __FUNCTION__, "[%d] GAMELISTREPLY found but full", conn_get_socket(c));
            break;
        case game_status_done:
            bn_int_set(&rpacket->u.server_gamelistreply.sstatus, SERVER_GAMELISTREPLY_GAME_SSTATUS_NOTFOUND);
            eventlog(eventlog_level_debug, __FUNCTION__, "[%d] GAMELISTREPLY found but done", conn_get_socket(c));
            break;
        case game_status_open:
        case game_status_loaded:
            if (std::strcmp(gamepass, game_get_pass(game))) {    /* passworded game must match password in request */
            bn_int_set(&rpacket->u.server_gamelistreply.sstatus, SERVER_GAMELISTREPLY_GAME_SSTATUS_PASS);
            eventlog(eventlog_level_debug, __FUNCTION__, "[%d] GAMELISTREPLY found but is password protected and wrong password given", conn_get_socket(c));
            break;
            }

            if (game_get_status(game) == game_status_loaded) {
            bn_int_set(&rpacket->u.server_gamelistreply.sstatus, SERVER_GAMELISTREPLY_GAME_SSTATUS_LOADED);
            eventlog(eventlog_level_debug, __FUNCTION__, "[%d] GAMELISTREPLY found loaded game", conn_get_socket(c));
            }

            /* everything seems fine, lets reply with the found game */
            bn_int_set(&glgame.status, SERVER_GAMELISTREPLY_GAME_STATUS_OPEN);
            bn_short_set(&glgame.gametype, gtype_to_bngtype(game_get_type(game)));
            bn_short_set(&glgame.unknown1, SERVER_GAMELISTREPLY_GAME_UNKNOWN1);
            bn_short_set(&glgame.unknown3, SERVER_GAMELISTREPLY_GAME_UNKNOWN3);
            addr = game_get_addr(game);
            port = game_get_port(game);
            trans_net(conn_get_addr(c), &addr, &port);
            bn_short_nset(&glgame.port, port);
            bn_int_nset(&glgame.game_ip, addr);
            bn_int_set(&glgame.unknown4, SERVER_GAMELISTREPLY_GAME_UNKNOWN4);
            bn_int_set(&glgame.unknown5, SERVER_GAMELISTREPLY_GAME_UNKNOWN5);
            bn_int_set(&glgame.unknown6, SERVER_GAMELISTREPLY_GAME_UNKNOWN6);

            packet_append_data(rpacket, &glgame, sizeof(glgame));
            packet_append_string(rpacket, game_get_name(game));
            packet_append_string(rpacket, game_get_pass(game));
            packet_append_string(rpacket, game_get_info(game));
            bn_int_set(&rpacket->u.server_gamelistreply.gamecount, 1);
            eventlog(eventlog_level_debug, __FUNCTION__, "[%d] GAMELISTREPLY specific game found", conn_get_socket(c));
            break;
        default:
            eventlog(eventlog_level_warn, __FUNCTION__, "[%d] game \"%s\" has bad status %d", conn_get_socket(c), game_get_name(game), game_get_status(game));
        }
    } else {
        bn_int_set(&rpacket->u.server_gamelistreply.gamecount, 0);
        eventlog(eventlog_level_debug, __FUNCTION__, "[%d] GAMELISTREPLY specific game doesn't seem to exist", conn_get_socket(c));
    }
    } else {            /* list all public games of this type */
    struct glist_cbdata cbdata;

    if (gtype == game_type_all)
        eventlog(eventlog_level_debug, __FUNCTION__, "GAMELISTREPLY looking for public games tag=\"%s\" bngtype=0x%08x gtype=all", tag_uint_to_str(clienttag_str, clienttag), bngtype);
    else
        eventlog(eventlog_level_debug, __FUNCTION__, "GAMELISTREPLY looking for public games tag=\"%s\" bngtype=0x%08x gtype=%d", tag_uint_to_str(clienttag_str, clienttag), bngtype, (int) gtype);

    cbdata.counter = 0;
    cbdata.tcount = 0;
    cbdata.c = c;
    cbdata.gtype = gtype;
    cbdata.rpacket = rpacket;
    gamelist_traverse(_glist_cb,&cbdata);

    bn_int_set(&rpacket->u.server_gamelistreply.gamecount, cbdata.counter);
    eventlog(eventlog_level_debug, __FUNCTION__, "[%d] GAMELISTREPLY sent %u of %u games", conn_get_socket(c), cbdata.counter, cbdata.tcount);
    }

    conn_push_outqueue(c, rpacket);
    packet_del_ref(rpacket);

    return 0;
}

а имена игр game.cpp :

extern char const * game_get_name(t_game const * game)
{
    char msgtemp222[32];
    if (!game)
    {
    eventlog(eventlog_level_error,__FUNCTION__,"got NULL game");
        return NULL;
    }
    snprintf(msgtemp222, sizeof(msgtemp222), "%.24s",game->name);
    
    return game->name ? xstrdup(msgtemp222) : "Bnet";
}

3

Re: список игр

extern char const * game_get_name(t_game const * game)
{
    char msgtemp222[32];
    if (!game)
    {
    eventlog(eventlog_level_error,__FUNCTION__,"got NULL game");
        return NULL;
    }
    snprintf(msgtemp222, sizeof(msgtemp222), "%.24s",game->name);
    
    return game->name ? xstrdup(msgtemp222) : "Bnet";
}

тут можно вывести какой нибудь текст ???

Добавлено: 20.12.2016 21:44

я просто хотел вывести проверку у версии лаунчера  через БД.
чтобы если вдруг не обновив игрок зашел на сервер то вместо игр было написано ОБНОВИ ЛАУНЧЕР.

4

Re: список игр

возможно туда добавить условия
t_account и тд
if (версия ...)
{
snprintf(msgtemp222, sizeof(msgtemp222), "%.24s",game->name);
}
else
{
обнови лаунчер
}

5

Re: список игр

как можно добавить

 snprintf(msgtemp, sizeof(msgtemp), "обнови лаунчер",text);
        message_send_text(c,message_type_error,c,msgtemp);

snprintf ошибку выдает

6

Re: список игр

launcher wrote:

как можно добавить

 snprintf(msgtemp, sizeof(msgtemp), "обнови лаунчер",text);
        message_send_text(c,message_type_error,c,msgtemp);

snprintf ошибку выдает

char msgtemp[32];
neutral

7

Re: список игр

заменял c, neutral

8

Re: список игр

как получилось в итоге?
лаунчер будет связан с бд? ) интересная связка )

9

Re: список игр

а где находиться код который можно написать текст при завершении игры?
или есть такой код ?)))

10

Re: список игр

launcher wrote:

а где находиться код который можно написать текст при завершении игры?
или есть такой код ?)))

Вариант 1: этот файл находится в боте - он определяет конец игры и удаляет из неё всех игроков, а затем и себя.
Вариант 2: сервер может определить окончание игры при парсере начатых игр - транслировать сообщение в законченую игру сервер не сможет.

Posts: 10

Pages 1

You must login or register to post a reply

Who now at forum

Currently view post: 0 guests, 0 registered users

forums.pvpgn.pro → [RU] The Source Code → список игр