Saving additional data to azure by extending demo (Unity)

Options
Hi (again)

I would like to know if its feasible to modify my version of the demo code to be able to store additional data on my azure storage. For instance I intended to keep the players inventory (sort of) in a database, I'm wondering now whether it would be easiest to just use the same web application that the turnbased demo uses (altered for my own purposes of course). But add some custom calls which send/retrieve data from a different table. This would mean I would only need a single web application, it would also be nice if I could add user authentication to the same server application.

Please let me know your thoughts on this or any alternatives.

Comments

  • failattu
    edited July 2014
    Options
    Hello,

    Yes it's feasible to run custom rpc's to our service. GetGameList is a good example of that and you should take a look how it's done to create webhooks.
    For basic understanding of this let's take a look at the basic idea behind them

    1. You send out webrpc request
    Example of webrpc:
    private void GetRoomsList()
        {
            this.savegameListStartIndex = 0;
            this.GameClientInstance.OpWebRpc("GetGameList", null);
            GetInvitationList();
        }
    
    2. The server calls that webrpc with post function
    You get an error if the webhook is not found.

    Example of the Post style data intake:
    public dynamic Post(GetGameListRequest request, string appId)
            {
    
    3. Your hook is called and your custom parameters are found in the "RPCParams" part of the post call.
    Example what GetGameList sends out:
    {
        "AppId": "<your appid>",
        "AppVersion": "1.0",
        "Region": "EU",
        "UserId": "aaaa",
        "RpcParams": null
    }
    

    4. Do the functional part like database calls and other logic you want to run in the server end
    Read:
    var stateJson = WebApiApplication.DataAccess.StateGet(appId, pair.Key);
    

    5. Return your response remember to add the ResultCode so your requests go through.

    Example:
    error response :
     var errorResponse = new ErrorResponse { Message = message };
    
    Ok response:
    var getGameListResponse = new GetGameListResponse { Data = list };
    return getGameListResponse;
    
  • v1r7u3
    Options
    You are very helpful indeed. Thanks so much. I'll have a look into creating some custom web rpc's then, I'll be back.
  • v1r7u3
    Options
    Hi there, I know its been some time but I finally got round to editing the webhooks and saving additional data to azure (There was lots to do beforehand). I've manage to store and retrieve dictionaries of type <string, string> no problems but now I want to store a more complicated structure that represents a users army which he can edit in the game. This should hopefully give you an idea of what I mean:
    public void StoreArmy()
        {
    
            Army defaultArmy = new Army()
            {
                Name = "Army1",
                PointCost = 1000,
                RaceID = 0,
                SquadList = new Dictionary&lt;string, Squad&gt;()
            };
    
            Squad defaultSquad = new Squad()
            {
                Name = "Squad1",
                PointCost = 100,
                UnitList = new Dictionary&lt;string, Unit&gt;()
            };
    
            Unit defaultUnit = new Unit()
            {
                Name = "Unit1",
                PointCost = 10
            };
    
            defaultSquad.UnitList.Add("unit1", defaultUnit);
            defaultArmy.SquadList.Add("squad1", defaultSquad);
    
            var rpcParams = new Dictionary&lt;string, Army&gt; {{"army1", defaultArmy}};
    
            OpWebRpc("ArmyStore", rpcParams);
        }
    

    How would I go about making it so that these classes can be serialized in this or a similar way?

    Any help/advice would be much appreciated.
  • v1r7u3
    Options
    After some more attempts with simple classes (no nested dictionaries) I seem to get:

    Exception: Unexpected - cannot serialize Dictionary with value type: System.String

    even thought the value type is not String???
  • v1r7u3
    Options
    I notice that if I remove the variables with type string from the class I'm trying to send I get the following:

    Exception: cannot serialize(): Army
  • v1r7u3
    Options
    Haven't tried yet but I'm pretty sure it might be because the variables in my classes didn't have { get; set; }, I'm going to give it a try now
  • v1r7u3
    Options
    No still didn't work. Do I have to extend some class or implement some interface? maybe declare a method for serializing the class? I thought that a class of properties like this:

    public class Army
    {
    public int PointCost { get; set; }

    public byte RaceID { get; set; }

    //public string Name;

    //public Dictionary<string, Squad> SquadList;

    }

    Could be passed as an rpcParameter
  • v1r7u3
    Options
    Ok I've decided to clarify and add more information

    What I want to achieve is something along the lines of this:

    9eb772f0e3.png

    Where my Army data would be something like CreateOptions, in the sense that it has entries of different types and nested dictionaries (CustomProperties)

    I would like to (and assume theres a relatively easy way to) be able to make this rpc call with a single class lets just say Army class.

    c2ee3e5565.png

    Above what I get when I pass a dictionary of type <string, string> with the entry ("test", "hello") which works just fine except the dictionary can only contain value types of type string where as I want instead to call OpWebRPC("ArmyStore", myArmy) and have it determine the names and types of the member variables within the Army class.

    3d85979c3b.png

    One thing I have tried is passing the dictionary of type <string, object> but instead I get strange behaviour where the data is not being passed inside the "RpcParams" entry and is instead merged with the root one making its own name.

    In any case if I try to pass a custom class as the parameter I get either

    Exception: cannot serialize(): Army

    or

    Exception: Unexpected - cannot serialize Dictionary with value type: System.String
  • v1r7u3
    Options
    Not sure if this is how it is intended to be used, but I've realized that if I do use dictionaries of type <string, object> I can nest them. And even though they are no longer within the "RpsParams" I can just change the definition of the request (asin GetGameListRequest) in the webhooks, and its even a little cleaner than having it all in the same place. So I can achieve what I wanted and simply make a method that converts the Army object into Dictionary<string, object> and nest the Squad and Unit stored as the same type within it.

    Please if you could offer advice/clarification that would be great as I'm pretty confused as to how best to go about this (and how the api manages to do it).

    Either way I will make a little post on here to explain how I ended up doing it with relevant output etc.