본문 바로가기
프로그래밍/Unity

Steam 웹 api 키로 AuthTicket 인증하기 테스트

by neive 2018. 12. 4.
728x90




백문이 불어일견 -_- 국내에선 검색도 안되냐 이런 중요한게


예제


using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Steamworks;
using System.Text;

public class Main : MonoBehaviour {

    const string MY_WEBAPI = "your web api";
    const int MY_APPID = 0; // your app id

    HAuthTicket m_AuthSessionTicket;
    byte[] m_Ticket = new byte[1024];
    uint m_pcbTicket;
    protected Callback<GetAuthSessionTicketResponse_t> m_GetAuthSessionTicketResponse;

    private void Awake()
    {
        m_GetAuthSessionTicketResponse = Callback<GetAuthSessionTicketResponse_t>.Create(OnGetAuthSessionTicketResponse);
    }

    // Use this for initialization
    void Start () {
		if(SteamManager.Initialized)
            m_AuthSessionTicket = SteamUser.GetAuthSessionTicket(m_Ticket, m_Ticket.Length, out m_pcbTicket);
    }


    void OnGetAuthSessionTicketResponse(GetAuthSessionTicketResponse_t pCallback)
    {
        Debug.Log("[" + GetAuthSessionTicketResponse_t.k_iCallback + " - GetAuthSessionTicketResponse] - " + pCallback.m_hAuthTicket + " -- " + pCallback.m_eResult);

        if (pCallback.m_eResult == EResult.k_EResultOK)
        {
            if (m_AuthSessionTicket != HAuthTicket.Invalid && m_pcbTicket != 0)
            {
                System.Array.Resize(ref m_Ticket, (int)m_pcbTicket);
                StringBuilder sb = new StringBuilder();
                for (int i = 0; i < m_pcbTicket; i++)
                    sb.AppendFormat("{0:x2}", m_Ticket[i]);

                StartCoroutine(TestWebApi(sb.ToString()));
            }
        }
    }

    IEnumerator TestWebApi(string s)
    {
        string url = string.Format("https://api.steampowered.com/ISteamUserAuth/AuthenticateUserTicket/v1/?key={0}&appid={1}&ticket={2}",
                    MY_WEBAPI,
                    MY_APPID,
                    s);

        WWW www = new WWW(url);

        yield return www;

        if (www.error == null)
            Debug.Log("### Success " + www.text);
        else
            Debug.Log("### Failed  " + www.text);
        m_sDebug = www.text;
    }


    string m_sDebug = "";
    private void OnGUI()
    {
        if(m_sDebug != "")
            GUI.Label(new Rect(30, 30, 800, 300), m_sDebug);
    }
}




728x90

댓글