Search Unity

Question Unity's UNet Multiplayer MatchMaker API Rest/Ajax from Webserver

Discussion in 'UNet' started by jasonlawless, Jul 7, 2020.

  1. jasonlawless

    jasonlawless

    Joined:
    Sep 21, 2019
    Posts:
    3
    Hi there. I have upgraded my app to communicate with my webserver via Socket instead of traditional REST HttpClient requests. My app is for both PC/Mac Standalone. So far, it's wonderful, and currently each of the clients have to poll the Match Making service on a regular interval to see if any specific matches exist.

    The app will have two builds, a Server build and a Client build. The Server build will have the capability of "Starting" or Hosting a match, to which the Clients would then be alerted that it is online. Instead of the clients polling the mm service, I wanted to have the Webserver do that and then it would broadcast the state to any clients that are online. Basically have that job centralized.

    I dug around in the source code and found out that UnityEngine.Networking.Match.NetworkMatch.ListMatches simply sends a POST request to mm.unet.unity3d.com/json/reply/ListMatchRequest using form data like so:
    Code (CSharp):
    1. object obj = new Uri(this.baseUri, "/json/reply/ListMatchRequest");
    2.         WWWForm wwwform = new WWWForm();
    3.         wwwform.AddField("version", Request.currentVersion);
    4.         wwwform.AddField("projectId", Application.cloudProjectId);
    5.         wwwform.AddField("sourceId", Utility.GetSourceID().ToString());
    6.         wwwform.AddField("accessTokenString", 0);
    7.         wwwform.AddField("domain", req.domain);
    8.         wwwform.AddField("pageSize", req.pageSize);
    9.         wwwform.AddField("pageNum", req.pageNum);
    10.         wwwform.AddField("nameFilter", req.nameFilter);
    11.         wwwform.AddField("filterOutPrivateMatches", req.filterOutPrivateMatches.ToString());
    12.         wwwform.AddField("eloScore", req.eloScore.ToString());
    13.         wwwform.headers["Accept"] = "application/json";
    14.         UnityWebRequest client = UnityWebRequest.Post(obj.ToString(), wwwform);
    15.         result = base.StartCoroutine(this.ProcessMatchResponse<ListMatchResponse, NetworkMatch.DataResponseDelegate<List<MatchInfoSnapshot>>>(client, new NetworkMatch.InternalResponseDelegate<ListMatchResponse, NetworkMatch.DataResponseDelegate<List<MatchInfoSnapshot>>>(this.OnMatchList), callback));
    I tried to replicate that using Postman to see if I can get a proper response from there, but it didn't work. I assume it has to do with authentication or the fact that User-Agent is incorrect? I'm not sure.

    So I am wondering if it is possible to have my webserver send API requests to the mm service, and then receive back proper responses, so that I can parse them and alert my clients on the state?

    As far as the form data, I know how to get all the info like projectId, sourceId, etc. But I do not know how to get "version", I saw somewhere in the code that it was hard coded to 3. So I tried with that.

    Anyways, if this can be done, that would be awesome! Please let me know!

    Thanks!