首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未从Unrealscript传递PHP参数

未从Unrealscript传递PHP参数
EN

Stack Overflow用户
提问于 2013-02-20 03:23:19
回答 1查看 337关注 0票数 1

我写的一个TcpLink类出了点问题。该类连接到数据库,并且可以从echo语句接收简单的消息。但是,由于某些原因,TcpLink类不会发送参数。有人能帮我吗?

通过浏览器运行它会返回正确的结果:"array(1) { "turtles"=> string(3) "yes“}

但是,所有数组返回的都是“UnrealScript (0){ }”

PHP代码:

代码语言:javascript
复制
<?php
$response = "";
$response = var_dump($_GET);
echo $response;
?>

UnrealScript代码:

代码语言:javascript
复制
    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
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-02-20 03:43:35

这是因为您的Opened方法总是在建立连接(即POST请求)之后发送查询字符串。您的GET参数应该在TargetPath中传递,才能正常工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/14965684

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档