[C++ and PHP] How to send data to server via PHP

Results 1 to 1 of 1
  1. #1
    Member vinleprince is offline
    MemberRank
    Feb 2015 Join Date
    77Posts

    [C++ and PHP] How to send data to server via PHP

    Detail : if you want to send some command/action from php to you ace server (Fieldserver)
    like send msg to in-game speaker / send some gm command / discord thing / donation annoucement bla bla.
    but you too noob and no idea what to do. i will be feeder for you, OK?

    Guideline : i will clone some code from webcashshop (S_WEB_CASHSHOP_SERVER_MODULE_HSKIM)
    but this will be easier coding. so it more friendly with newbie.

    this is how it work :
    you gotta make your fieldserver open more unique port like 15099. (dont make this port access by internet. only make it run from localhost or webserver ip)

    now can use PHP send text via TCP socket like "ABCD" to port 15099
    (normally you gotta encode data but we will skip that for easier coding)


    you fieldserver will recived raw text "ABCD" from 15099 port without decode.
    that's all.


    step by step
    1. clone core 4 files to server/fieldserver/main and include to visual studio's fieldserver project
    - FieldPhpWebIOCP.cpp , FieldPhpWebIOCP.h, FieldPhpWebIOCPSocket.cpp, FieldPhpWebIOCPSocket.h
    -> https://pastebin.com/u4AApyNq

    2. open Fieldserver/Main/FieldGlobal.h

    put this under public for create unique open port
    PHP Code:
    CIOCP *                m_pFieldPhpIOCP
    3.open Fieldserver/Main/FieldGlobal.cpp

    put header for link core code (that you do on 1. step)
    PHP Code:
    #include "FieldPhpWebIOCP.h" 
    put in on last line in CFieldGlobal::CFieldGlobal() for init variable
    PHP Code:
    m_pFieldPhpIOCP NULL

    put in on last line in CFieldGlobal::~CFieldGlobal() for clear variable
    PHP Code:
    SAFE_DELETE(m_pFieldPhpIOCP); 

    next put this to BOOL CFieldGlobal::InitServerSocket(void)
    (suggest put this to upper)
    INIT_MSG_WITH_BUFFER(MSG_FP_CONNECT_FIELD_CONNECT, T_FP_CONNECT_FIELD_CONNECT, msgConnect, SendBuf);

    for make port running same IP as main fieldserver
    PHP Code:

    if (FALSE == IsArenaServer() && NULL == m_pFieldPhpIOCP) {

            
    m_pFieldPhpIOCP = new CFieldPHPWebIOCP(15099m_szIPLocal);

            if (
    m_pFieldPhpIOCP->IOCPInit() == FALSE)        { 
     
    MessageBox(NULLszSystemLog"ERROR"MB_OK);
                return 
    FALSE;
            }

            ((
    CFieldPHPWebIOCP*)m_pFieldPhpIOCP)->SetFieldIOCP(((CFieldIOCP*)m_pGIOCP));

        } 
    4. next open Common/IOCPSocket.cpp (server side) goto this function CIOCPSocket::OnReceive

    find this line
    while(this->IsUsing() && m_bFlagDelayClose == FALSE && nBytesRecvd > 0)

    put at first line under {
    for redirect data to core function if connect via 15099 port without decode
    PHP Code:
    if (ST_FIELD_WEB_SERVER == ServerType
    {
    bRet OnRecvdPacketFieldWebServer(pBlocknBytesRecvd0NULL0i_pThreadInfo); 
    return; 

    5. setting up php
    edit you ip/port/data that you want

    https://pastebin.com/4j7G2vTE

    6. done

    now you can send php data when you fieldserver alive. you gotta manage thing after fieldserver got "ABCD" data
    by edit this function

    BOOL CFieldPHPWebIOCPSocket::OnRecvdPacketFieldWebServer (FieldPhpWebIOCPSocket.cpp)

    there are 3 variable that you can use
    - (const char*)pPacket // this is raw text "ABCD". you can use DBGOUT("%s", pPacket ); for output
    - (int) nLength // this is size of raw text "ABCD" = 4
    - m_pFieldIOCP // this is main fieldserver function. you can access anyting base from here

    example you can give warpoint 500 to all player active on map area 3018
    m_pFieldIOCP->GetFieldMapProjectByMapIndex(3018)->GetFirstFieldMapChannel(true)->AddWarPointInMap(500, false, INFLUENCE_TYPE_ALL_MASK);

    add item -> InsertItemInMap
    bla bla

    goodluck
    btw you also can use php socket to attack another server as well by remove waiting time and spam x500 XD
    Last edited by vinleprince; 13-11-21 at 05:17 PM.




Advertisement