⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ttg_proto.cpp

📁 This programm is proxy server for ragnarok online game. Also it s can be use as bot. It control all
💻 CPP
字号:
#include "ttg_proto.h"
#include "../win_and_sock.h"
#include "../data.h"

#include <stdio.h>

#include "../buffers.h"
#include "../packet_db.h"

#include "../bots/bot.h"

#define PC_TTG_TOUT 1 // send tout;
#define PC_TTG_DUMP 2 // send dump;
#define PC_TTG_TEST 3 // test
/******* Thread side *******/

/**** Send ****/

int send_tout(ParsePoint * pp, char * text)
{
    stackbuf * buf = pp->tg;
    char * s; 
    int textlen_sz = strlen(text)+1; // line + termZero
    s = (char *)malloc(textlen_sz);
    if(s == NULL)
        return 0;
    strcpy(s, text);

    WORD packetlen = 4 + 4; // 4 header + 4(pointer)
    int res = 0;

    if(packetlen>space_sb(buf))
    {
        // todo: buf space not enough
        return 0;
    }

    sb_W_AT(buf, 0) = PC_TTG_TOUT; // packet id
    sb_W_AT(buf, 2) = packetlen; // packet length
    sb_I_AT(buf, 4) = (int)s;
    commit_sb(buf, packetlen);
    return 1;
}

int send_dump(ParsePoint * pp, BYTE direction, BYTE * src, WORD len)
{
    if(direction == DIR_TTS) // filter
        return 1;
    if(direction == DIR_TTC) // filter
        return 1;
    
    stackbuf * buf = pp->tg;   
    BYTE * p;
    p = (BYTE *)malloc(len);
    if(p == NULL)
        return 0;
    memcpy(p,src, len);

    WORD packetlen = 4+ 1+2 + 4; // 4 header + 1(dir) + 2(len) + 4(pointer)
    int res = 0;

    if(packetlen>space_sb(buf))
    {
        // todo: ttg buf full
        return 0;
    }

    sb_W_AT(buf, 0) = PC_TTG_DUMP; // packet id
    sb_W_AT(buf, 2) = packetlen; // packet len
    sb_B_AT(buf, 4) = direction; 
    sb_W_AT(buf, 5) = len; // data length
    sb_I_AT(buf, 7) = (int)p;
    commit_sb(buf, packetlen); // commit
    return 1;
}


/******* GUI *******/

/**** recv ****/
void tout(char * text, bool refresh);
void tout_dump(BYTE * data, int len, int direction);

// forward declarations
void On_TTG_Test();

// for roxy.cpp *** GUI ***
int ttg_parse()
{
    int cnt = count_rb(&ttg);
    if(cnt < 4) // 4=minimal size of a packet
        return 0;

    WORD pc_id = read_rb_W(&ttg); // packet id
    WORD pc_len = read_rb_W(&ttg); // packet length
    if(count_rb(&ttg)<pc_len)
    {
        rd_undo_rb(&ttg);
        return 0;
    }
    rdcom_rb(&ttg); // read commit;
    
    switch(pc_id)
    {
    case PC_TTG_TOUT:
        char * text;
        text = (char*)read_rb_I(&ttg);
        rdcom_rb(&ttg); // read commit;

        tout(text,false);
        free(text);
        break;

    case PC_TTG_DUMP:
        WORD len;
        BYTE direction;
        BYTE * data;
        direction = read_rb_B(&ttg);
        len= read_rb_W(&ttg);
        data = (BYTE*)read_rb_I(&ttg);
        rdcom_rb(&ttg); // read commit;
 
        tout_dump(data,len, direction);
        free(data);
        break;
    case PC_TTG_TEST:
        On_TTG_Test();
        break;

    default:
        // todo
        ; 
    }

    return 1;
}

// 桉镱朦珞弪

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -