Don't send int ParameterCodes

edited August 2011 in Photon Server
Hi all!

ParameterCode declared as:
    public enum ParameterCode: int
    {
        ErrorCode       = 1,          // The error code.
        DebugMessage    = 2,       // The debug message.
        EventCode       = 3,          // The event code.
        OperationCode   = 4,      // The operation code.
        EventData       = 5,          // The event data.

        Login           = 6,
        Password        = 7
    }

AuthorizeOperation on server:
    public class AuthorizeOperation: Operation
    {
        public AuthorizeOperation(OperationRequest request)
            : base(request)
        {
        } 
         
        [RequestParameter(Code = (int)ParameterCode.Login, IsOptional = false)]
        public string Login { get; set; }  
          
        [RequestParameter(Code = (int)ParameterCode.Password, IsOptional = false)]
        public string Password { get; set; }
    }

On client I try send this operation:
        public static void Authorize(Game game, string login, string password)
        {
            Hashtable data = new Hashtable();
            
            data[(int)ParameterCode.Login] = login;
            data[(int)ParameterCode.Password] = password; 

            game.SendOperation(OperationCode.Authorize, data, true, Settings.OperationChannel); 
        }

But on server OnOperationRequest not called - the log not writed:
       public virtual void OnOperationRequest(OperationRequest operationRequest)
        {
            log.Info(string.Format("Operation request {0}", operationRequest.OperationCode));

            operationDispatcher.DispatchOperationRequest(this, operationRequest);
        }

But this work, if do it:
        public static void Authorize(Game game, string login, string password)
        {
            Hashtable data = new Hashtable();
            
            data[(byte)ParameterCode.Login] = login; // changed from data[(int)ParameterCode.Login] = login;
            data[(byte)ParameterCode.Password] = password; // changed from data[(int)ParameterCode.Password] = password; 

            game.SendOperation(OperationCode.Authorize, data, true, Settings.OperationChannel); 
        }


How send operations, where ParameterCode defined as int?

Comments

  • The operation code and parameter codes have to be byte-typed. The definition on the server side is wrong with it's int type but uses the correct numbers per key.

    Sorry for being confusing here. All operation codes and parameter codes are currently byte and must be compared as such.
  • Well... ParameterCodes I can always just define the order:
        public class AuthorizeOperation: Operation
        {
            public AuthorizeOperation(OperationRequest request)
                : base(request)
            {
            } 
             
            [RequestParameter(Code = (byte)1, IsOptional = false)]
            public string Login { get; set; }  
              
            [RequestParameter(Code = (byte)2, IsOptional = false)]
            public string Password { get; set; }
    
            [ResponseParameter(Code = (byte)3, IsOptional = true)]
            public Hashtable ActorList{ get; set; } 
    
    // and so on...
        }
    }
    
        public class AnyOperation: Operation
        {
            public AnyOperation(OperationRequest request)
                : base(request)
            {
            } 
             
            [RequestParameter(Code = (byte)1, IsOptional = false)]
            public string Any_1{ get; set; }  
              
            [RequestParameter(Code = (byte)2, IsOptional = false)]
            public string Any_2 { get; set; }
    
            [ResponseParameter(Code = (byte)3, IsOptional = true)]
            public Hashtable Any_3{ get; set; } 
    
            [ResponseParameter(Code = (byte)4, IsOptional = true)]
            public Hashtable Any_4{ get; set; } 
    
    // and so on...
        }
    }
    

    Of course, it is more convenient to Enum, but the 255 - too few...

    Or to determine the Enum:
    public enum ParameterCode: byte
        {
            Prm_1 = 1,
            Prm_2 = 2,
            Prm_3 = 3,
            Prm_4 = 4,
            Prm_5 = 5,
            Prm_6 = 6,
            Prm_7 = 7,
            Prm_8 = 8
        }
    

    But what to do with OperationCode?
    Maybe define a special operation, which involves a lot of other operations?

    Thanks!
  • So you're out of operation and parameter codes? Never thought that's going to happen.

    Right now, you are out of luck: OperationCodes and Parameter Codes are both fixed byte-length, to save on protocol.

    You should re-use the parameter codes across several operations. We use the "ActorNr" in multiple operations, so it got the same number everywhere. Maybe this doesn't work for you or only limited. Then, probably making them generic is the next best solution (Prm_1, etc).

    Operations most likely can do multiple tasks. Making some special operations that use a parameter to do more than one task is currently the way to go.
  • Go out of 255 separate operations is pretty hard and there may be enough free enum members.
    But 255 parameters limit in pretty hardcore mmo is easy to reach indeed.
    So maybe there is a topic to discuss? :)
    (Today i found this "problem" too trying to send some short-typed parameter codes)
  • Morton wrote:
    Go out of 255 separate operations is pretty hard and there may be enough free enum members.
    But 255 parameters limit in pretty hardcore mmo is easy to reach indeed.
    So maybe there is a topic to discuss? :)
    (Today i found this "problem" too trying to send some short-typed parameter codes)
    Well it is 256 different parametercodes per operation, as you can reuse them, as Tobi mentioned.
    For example the same code could be used as key for a float coordinate in one operation, for a bool in the next one and for an array in another one.
  • Also, the new protocol will allow you to send object-arrays. These are non-strict, so each object has it's own type.
    Think of them as your ticket to optional parameter-arrays. You can nest a lot of parameters into one, if needed.
  • I got the point - use single "Name" paramID for WorldName, ItemName, LocationName and so. But sometimes it's more comfortable to use WorldName param. For example if i receive in single operation response whole gamewold data. :roll:
    But there are ways to solve problem anyway.
    Tobias wrote:
    Also, the new protocol will allow you to send object-arrays.
    Yummeee!!! THAT is really great!!! :D:D:D
    Thank you guys!!
Sign In or Register to comment.