当前位置: 首页>>代码示例>>C#>>正文


C# IRequestCallback.OnRequest方法代码示例

本文整理汇总了C#中IRequestCallback.OnRequest方法的典型用法代码示例。如果您正苦于以下问题:C# IRequestCallback.OnRequest方法的具体用法?C# IRequestCallback.OnRequest怎么用?C# IRequestCallback.OnRequest使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IRequestCallback的用法示例。


在下文中一共展示了IRequestCallback.OnRequest方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: OnServerResponse

    protected void OnServerResponse( string raw, string apicall, IRequestCallback cb )
    {
        var uc = apicall.Split("/"[0]);
        var controller = uc[0];
        var action = uc[1];

        if (Debug.isDebugBuild)
            Debug.Log(raw);

        // Fire call complete event
        RoarManager.OnRoarNetworkEnd("no id");

        // -- Parse the Roar response
        // Unexpected server response
        if ( raw==null || raw.Length==0 || raw[0] != '<')
        {
            // Error: fire the error callback
            System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
            System.Xml.XmlElement error = doc.CreateElement("error");
            doc.AppendChild(error);
            error.AppendChild(doc.CreateTextNode(raw));
            if (cb!=null)
            {
                cb.OnRequest(
                    new Roar.RequestResult(
                        RoarExtensions.CreateXmlElement("error",raw),
                        IWebAPI.FATAL_ERROR,
                        "Invalid server response"
                    ) );
            }
            return;
        }

        System.Xml.XmlElement root = RoarExtensions.CreateXmlElement(raw);

        int callback_code;
        string callback_msg="";

        System.Xml.XmlElement actionElement = root.SelectSingleNode( "/roar/"+controller+"/"+action ) as System.Xml.XmlElement;

        // Pre-process <server> block if any and attach any processed data
        System.Xml.XmlElement serverElement = root.SelectSingleNode( "/roar/server" ) as System.Xml.XmlElement;
        RoarManager.NotifyOfServerChanges( serverElement );

        // Status on Server returned an error. Action did not succeed.
        string status = actionElement.GetAttribute( "status" );
        if (status == "error")
        {
            callback_code = IWebAPI.UNKNOWN_ERR;
            callback_msg = actionElement.SelectSingleNode("error").InnerText;
            string server_error = (actionElement.SelectSingleNode("error") as System.Xml.XmlElement).GetAttribute("type");
            if ( server_error == "0" )
            {
                if (callback_msg=="Must be logged in") { callback_code = IWebAPI.UNAUTHORIZED; }
                if (callback_msg=="Invalid auth_token") { callback_code = IWebAPI.UNAUTHORIZED; }
                if (callback_msg=="Must specify auth_token") { callback_code = IWebAPI.BAD_INPUTS; }
                if (callback_msg=="Must specify name and hash") { callback_code = IWebAPI.BAD_INPUTS; }
                if (callback_msg=="Invalid name or password") { callback_code = IWebAPI.DISALLOWED; }
                if (callback_msg=="Player already exists") { callback_code = IWebAPI.DISALLOWED; }

                logger.DebugLog(string.Format("[roar] -- response error: {0} (api call = {1})", callback_msg, apicall));
            }

            // Error: fire the callback
            // NOTE: The Unity version ASSUMES callback = errorCallback
            if (cb!=null) cb.OnRequest( new Roar.RequestResult(root, callback_code, callback_msg) );
        }

        // No error - pre-process the result
        else
        {
            System.Xml.XmlElement auth_token = actionElement.SelectSingleNode(".//auth_token") as System.Xml.XmlElement;
            if (auth_token!=null && !string.IsNullOrEmpty(auth_token.InnerText)) RoarAuthToken = auth_token.InnerText;

            callback_code = IWebAPI.OK;
            if (cb!=null) cb.OnRequest( new Roar.RequestResult( root, callback_code, callback_msg) );
        }

        RoarManager.OnCallComplete( new RoarManager.CallInfo( root, callback_code, callback_msg, "no id" ) );
    }
开发者ID:QuiVeeGlobal,项目名称:sdk-unity,代码行数:80,代码来源:RequestSender.cs

示例2: OnServerResponse

    protected void OnServerResponse( string raw, string apicall, IRequestCallback<IXMLNode> cb )
    {
        var uc = apicall.Split("/"[0]);
        var controller = uc[0];
        var action = uc[1];

        Debug.Log(raw);
        // TEMP
        /*
        if (apicall == "shop/list")
        {
            raw = "<roar tick=\"135170282509\"><shop><list status=\"ok\"><shopitem ikey=\"rocket_fuel\" label=\"Rocket Fuel\" description=\"\"><costs><stat_cost type=\"currency\" ikey=\"gamecoins\" value=\"10\" ok=\"true\"/></costs><modifiers><grant_stat type=\"currency\" ikey=\"rocket_fuel\" value=\"100\"/></modifiers><tags/></shopitem><shopitem ikey=\"neil_armstrong\" label=\"Neil Armstrong\" description=\"Best copilot in the world\"><costs><stat_cost type=\"currency\" ikey=\"premium_currency\" value=\"15\" ok=\"false\" reason=\"Insufficient Premium Currency\"/></costs><modifiers><grant_item ikey=\"npc_armstrong\"/></modifiers><tags><tag value=\"copilot\"/></tags></shopitem><shopitem ikey=\"starter_space_pack\" label=\"Starter Space Pack\" description=\"Get going!\"><costs><stat_cost type=\"currency\" ikey=\"gamecoins\" value=\"20\" ok=\"true\"/></costs><modifiers><grant_stat type=\"currency\" ikey=\"rocket_fuel\" value=\"30\"/><grant_item ikey=\"regular_space_helmet\"/><grant_item ikey=\"rocket_ship\"/></modifiers><tags><tag value=\"pack\"/></tags></shopitem></list></shop></roar>";
        }
        */

        // Fire call complete event
        RoarManager.OnRoarNetworkEnd("no id");

        // -- Parse the Roar response
        // Unexpected server response
        if (raw[0] != '<')
        {
            // Error: fire the error callback
            IXMLNode errorXml = IXMLNodeFactory.instance.Create("error", raw);
            if (cb!=null) cb.OnRequest( new Roar.CallbackInfo<IXMLNode>(errorXml, IWebAPI.FATAL_ERROR, "Invalid server response" ) );
            return;
        }

        IXMLNode rootNode = IXMLNodeFactory.instance.Create( raw );

        int callback_code;
        string callback_msg="";

        IXMLNode actionNode = rootNode.GetNode( "roar>0>"+controller+">0>"+action+">0" );
        // Hash XML keeping _name and _text values by default

        // Pre-process <server> block if any and attach any processed data
        IXMLNode serverNode = rootNode.GetNode( "roar>0>server>0" );
        RoarManager.NotifyOfServerChanges( serverNode );

        // Status on Server returned an error. Action did not succeed.
        string status = actionNode.GetAttribute( "status" );
        if (status == "error")
        {
            callback_code = IWebAPI.UNKNOWN_ERR;
            callback_msg = actionNode.GetFirstChild("error").Text;
            string server_error = actionNode.GetFirstChild("error").GetAttribute("type");
            if ( server_error == "0" )
            {
                if (callback_msg=="Must be logged in") { callback_code = IWebAPI.UNAUTHORIZED; }
                if (callback_msg=="Invalid auth_token") { callback_code = IWebAPI.UNAUTHORIZED; }
                if (callback_msg=="Must specify auth_token") { callback_code = IWebAPI.BAD_INPUTS; }
                if (callback_msg=="Must specify name and hash") { callback_code = IWebAPI.BAD_INPUTS; }
                if (callback_msg=="Invalid name or password") { callback_code = IWebAPI.DISALLOWED; }
                if (callback_msg=="Player already exists") { callback_code = IWebAPI.DISALLOWED; }

                logger.DebugLog(string.Format("[roar] -- response error: {0} (api call = {1})", callback_msg, apicall));
            }

            // Error: fire the callback
            // NOTE: The Unity version ASSUMES callback = errorCallback
            if (cb!=null) cb.OnRequest( new Roar.CallbackInfo<IXMLNode>(rootNode, callback_code, callback_msg) );
        }

        // No error - pre-process the result
        else
        {
            IXMLNode auth_token = actionNode.GetFirstChild("auth_token");
            if (auth_token!=null) RoarAuthToken = auth_token.Text;

            callback_code = IWebAPI.OK;
            if (cb!=null) cb.OnRequest( new Roar.CallbackInfo<IXMLNode>( rootNode, callback_code, callback_msg) );
        }

        RoarManager.OnCallComplete( new RoarManager.CallInfo( rootNode, callback_code, callback_msg, "no id" ) );
    }
开发者ID:yorrickm,项目名称:sdk-unity,代码行数:76,代码来源:RequestSender.cs


注:本文中的IRequestCallback.OnRequest方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。