Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

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

Newbie Spellweaver
Joined
Feb 2, 2015
Messages
77
Reaction score
53
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
->

2. open Fieldserver/Main/FieldGlobal.h

put this under public for create unique open port
PHP:
CIOCP *                m_pFieldPhpIOCP;

3.open Fieldserver/Main/FieldGlobal.cpp

put header for link core code (that you do on 1. step)
PHP:
#include "FieldPhpWebIOCP.h"

put in on last line in CFieldGlobal::CFieldGlobal() for init variable
PHP:
m_pFieldPhpIOCP = NULL;


put in on last line in CFieldGlobal::~CFieldGlobal() for clear variable
PHP:
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:
if (FALSE == IsArenaServer() && NULL == m_pFieldPhpIOCP) {

        m_pFieldPhpIOCP = new CFieldPHPWebIOCP(15099, m_szIPLocal);

        if (m_pFieldPhpIOCP->IOCPInit() == FALSE)        { 
 MessageBox(NULL, szSystemLog, "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:
if (ST_FIELD_WEB_SERVER == ServerType) 
{
bRet = OnRecvdPacketFieldWebServer(pBlock, nBytesRecvd, 0, NULL, 0, i_pThreadInfo); 
return; 
}

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



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:
Back
Top