Example #1
0
    public void SetCmdType(NetCmdType nct)
    {
        int cmd = (int)nct;

        CmdType    = (byte)(cmd >> 8);
        SubCmdType = (byte)cmd;
    }
Example #2
0
        public PackageIn msg;      // 数据buff

        public NetCommand()
        {
            this.dwType = NetCmdType.NetCmd_Null;
            this.dwLen  = 0;
            this.error  = NetWorkError.NetWorkError_null;
            msg         = null;
        }
Example #3
0
 public NetCommand(NetCommand cmd)
 {
     this.dwType = cmd.dwType;
     this.dwLen  = cmd.dwLen;
     if (this.dwLen > 0)
     {
         this.msg = cmd.msg;
     }
 }
Example #4
0
 public static bool CheckCmdType(NetCmdType cmdType)
 {
     if (NetCmdMapping.IsRegisterCmd(cmdType))
     {
         return(true);
     }
     else
     {
         return(false);
     }
 }
Example #5
0
    public static NetTypeInfo GetTypeInfo(NetCmdType type)
    {
        ushort      size = (ushort)TypeSize <T> .SIZE;
        NetTypeInfo nti  = new NetTypeInfo();

        nti.CmdType      = type;
        nti.StructType   = TypeSize <T> .RUN_TYPE;
        nti.StructSize   = size;
        nti.TypeHashCode = TypeSize <T> .HASH;
        return(nti);
    }
Example #6
0
    public static NetCmdBase ByteToCmd(byte[] byteData, int offset, int length)
    {
        if (length < 4)
        {
            return(null);
        }
        int t1 = (int)byteData[offset + 3];
        int t2 = (int)byteData[offset + 2];

        t1 = t1 << 8 | t2;

        NetCmdType cmdType = (NetCmdType)(t1);

        if (cmdType >= NetCmdType.CMD_MAX)
        {
            return(null);
        }
        NetTypeInfo typeInfo = NetCmdMapping.GetTypeInfo(cmdType);

        if (typeInfo == null)
        {
            LogMgr.Log("未注册的命令:" + cmdType.ToString());
            return(null);
        }
        if (length < typeInfo.StructSize)
        {
            LogMgr.Log("命令大小与结构体大小不匹配:" + length.ToString() + " : " + typeInfo.StructSize.ToString() + " :" + cmdType.ToString());
            return(null);
        }
        NetCmdBase cmd = (NetCmdBase)TypeReflector.BytesToObj(
            typeInfo.TypeHashCode,
            byteData,
            offset,
            length
            );

        return(cmd);
    }
Example #7
0
 protected virtual void _RegisterEvent(NetCmdType aEventName_cmd, EventDelegate aEventDelegate)
 {
     msgList[aEventName_cmd + ""] = aEventDelegate;
     NetManager.Instance.AddNetEventListener(aEventName_cmd, aEventDelegate);
 }
Example #8
0
 public NetCmd(NetCmdType t)
 {
     SetCmdType(t);
 }
Example #9
0
 public bool AddNetEventListener(NetCmdType aEventName_cmd, EventDelegate aEventDelegate)
 {
     return(AddEventListener(aEventName_cmd + "", aEventDelegate));
 }