phpunrealscript

PHP Parameters are not being passed from Unrealscript


I'm having issues with a TcpLink class I wrote. The class connects to the database and can ever receive simple messages from echo statements. However, the TcpLink class won't send parameters for some reason. Can anybody help me out?

Running it through a browser returns a proper result: "array(1) { ["turtles"]=> string(3) "yes" }

However, all the UnrealScript returns is "array(0) { }"

PHP Code:

<?php
$response = "";
$response = var_dump($_GET);
echo $response;
?>

UnrealScript Code:

    class PlayerStatsLinkClient extends TcpLink;

var string TargetHost;
var int TargetPort;
var String TargetPath;
var String RequestText; //Data To Send
var array<String> RequestQueue; //Data Waiting to be sent(used when request is already in progress)
var bool bRequestInProgress; //Currently Sending A Request

var PlayerController PC;

var bool bGetData;

var String RequestType;

//var TestDatabaseServices ServiceProvider; //Owner Service
var int SecurityKey; //Arbitrary number equivalent to what is in .php to check authority(Prevent hacking slightly[Easily hackable])

struct sParam
{
    var String Key;
    var String Value;
};

var array<sParam> ParamList;

delegate OnResponse(String Type, String Data);

function AddParam(string Key, string Value)
{
    local sParam param;

    param.Key = Key;
    param.Value = Value;

    ParamList.AddItem(param);
}

function SetStats(int level, int xp, int xpToNext){
    AddParam("level", string(level));
    AddParam("xp", string(xp));
    AddParam("xpToNext", string(xpToNext));    
}

function GetStatsFromServer(){
    bGetData = true;
    AddParam("COMMAND", "RETRIEVE");
    Execute();
    bRequestInProgress = true;
    `log("========== END GETSTATSFROMSERVER()");
}

function bool Execute()
{
    if(!SetRequest())
    {
        return false;
    }

    Resolve(targethost);

    bRequestInProgress = true;
    return true;
}

function bool SetRequest(optional String Database)
{
    local sParam param;
    local String tmpRequestText;

    tmpRequestText="securitykey="$SecurityKey;

    foreach ParamList(param)
    {
        tmpRequestText $= "&" $ param.Key $ "=" $ param.Value;
    }

    ParamList.Remove(0, ParamList.Length);

    if(!bRequestInProgress)
    {
        RequestText = tmpRequestText;
        return true;
    }
    else
    {
        RequestQueue.AddItem(tmpRequestText);
        return false;
    }
}

event Resolved( IpAddr Addr )
{
    `log("++++++++++++++ RESOLVED!");
    Addr.Port = TargetPort;

    BindPort();
    if (!Open(Addr))
    {
        `Log("[TcpLinkClient] Open failed");
    }
}

event ResolveFailed()
{
    `Log("[TcpLinkClient] Unable to resolve "$TargetHost);
}

function SetRequestText(string text){
    RequestText = text;   
}

function SetbGetData(bool delta){
   bGetData = delta;   
}

event Opened()
{  
    RequestText = "securitykey=REMOVED";
    //let the php file know what's coming
    if(bGetData){
        SendText("GET /"$TargetPath$" HTTP/1.0"$chr(13)$chr(10));
    }else{
        SendText("POST /"$TargetPath$" HTTP/1.0"$chr(13)$chr(10));
    }
    SendText("Host: "$TargetHost$chr(13)$chr(10));
    SendText("User-Agent: HTTPTool/1.0"$Chr(13)$Chr(10));
    SendText("Content-Type: application/x-www-form-urlencoded"$chr(13)$chr(10));
    SendText("Content-Length: "$len(RequestText)$Chr(13)$Chr(10));
    SendText(chr(13)$chr(10));
    //send securitykey, command and params for php to use
    SendText(RequestText);
    SendText(chr(13)$chr(10));
    SendText("Connection: Close");
    SendText(chr(13)$chr(10)$chr(13)$chr(10));
}

event Closed()
{
    if(RequestQueue.Length <= 0)
    {
        bRequestInProgress=false;
    }
    else
    {
        RequestText = RequestQueue[0];
        RequestQueue.Remove(0,1);
        Resolve(targethost);
    }
}

event ReceivedText( string Text )
{  
    Text = Split(Text, chr(13)$chr(10)$chr(13)$chr(10), true);
    WorldInfo.Game.Broadcast(self, "RECEIVED RESPONSE FROM PLAYERSTATS SERVER: " $ Text);
    `log("++++++++++++++++++++");
    `log(Text);
//    if(ServiceProvider != none)
//    {
//        ServiceProvider.RecieveDatabaseText(Text);
//    }
}

defaultproperties
{
    TargetHost="REMOVED.zzl.org"
    TargetPort=80
    TargetPath = "REMOVED.php"

    bGetData=true

    SecurityKey=REMOVED//used in PHP to authenticate
}

Solution

  • This will be because your Opened method always sends the query string after the connection has been established (i.e. a POST request). Your GET parameters should be passed in TargetPath for it to work correctly.