Simple Question

kidovate
edited February 2012 in Photon Server
Hi guys,

Quick question, I haven't seen any docs on this, although they might be somewhere I havent dug around yet.

What data is supported in params for photon operations? I understand everything is stored in hashtables, but say I wanted to send a custom class called LoginInfo as a paramater.

Could you do this:
    public class LoginInfo
    {
        /// <summary>
        /// The username.
        /// </summary>
        public string Username { get; set; }

        /// <summary>
        /// The password. Using MD5 hash for security.
        /// </summary>
        public string PasswordMd5 { get; set; }
    }

...
//Photon paramaters for sending
var loginInfo = new LoginInfo();
var paramater = new Hashtable { { (byte)100, loginInfo } };


Or would you have to convert LoginInfo into a hashtable and then shoot that into the paramater?

Thanks,
Christian

Comments

  • The hashtables are used as collection of operation parameters.
    All parameters of operations in Photon must have byte codes assigned. These byte-keys make up the hashtable for operations. Server-side, they are assigned by attributes, client side "by convention" and using constants for those. Compare (e.g.) JoinRequest.cs in socketserver sdk\src-server\Lite\Lite\Operations.

    The values for these parameters can be one of the supported types. They are described here:
    http://doc.exitgames.com/v3/photonclient/binaryprotocol
  • Thanks for your response.

    I've developed an interface called ISyncedObject which is used to create objects that can be easily syncronized along Photon (such as the login object). This makes two functions on the object that is inheriting from it:

    ToHashtable
    FromHashtable

    Code to use for example login object:
    #region Photon Hashtable
            /// <summary>
            /// Takes data from photon hashtable and loads into LoginInfo.
            /// </summary>
            /// <param name="data"></param>
            public void FromHashtable(Hashtable data)
            {
                Username = (string)data[1];
                PasswordMd5 = (string) data[2];
            }
            /// <summary>
            /// Converts this LoginInfo into a photon compatable hashtable.
            /// </summary>
            /// <returns></returns>
            public Hashtable ToHashtable()
            {
                return new Hashtable {{1, Username}, {2, PasswordMd5}};
            }
            #endregion
    

    This has been working beautifully for me and makes it easy to make syncable types. I'll post a tutorial if it seems valuable enough to you.

    ~Christian
  • You can also use custom type serialization as described here:

    http://forum.exitgames.com/viewtopic.php?f=5&t=1398