예제 #1
0
 public void AuthServer(byte[] re)
 {
     SendControlData(SimplePack.Pack((object)(ushort)1031, (object)this.serverIP, (object)(int)this.serverPort, (object)this.RoleName, (object)false));
 }
예제 #2
0
        public static byte[] Pack(params object[] value)
        {
            if (value == null)
            {
                return((byte[])null);
            }
            byte[] numArray1 = new byte[0];
            foreach (object obj in value)
            {
                byte[] numArray2 = new byte[0];
                Type   type      = obj.GetType();
                switch (Type.GetTypeCode(type))
                {
                case TypeCode.Object:
                    if (type == typeof(byte[]))
                    {
                        numArray2 = (byte[])obj;
                        break;
                    }
                    if (type == typeof(List <uint>))
                    {
                        List <byte> byteList = new List <byte>();
                        byte[]      bytes    = BitConverter.GetBytes((ushort)(((List <uint>)obj).Count * 4));
                        byteList.AddRange((IEnumerable <byte>)numArray2);
                        byteList.AddRange((IEnumerable <byte>)bytes);
                        foreach (uint num in obj as List <uint> )
                        {
                            byteList.AddRange((IEnumerable <byte>)BitConverter.GetBytes(num));
                        }
                        numArray2 = byteList.ToArray();
                        break;
                    }
                    if (type == typeof(List <ulong>))
                    {
                        List <byte> byteList = new List <byte>();
                        byte[]      bytes    = BitConverter.GetBytes((ushort)(((List <ulong>)obj).Count * 8));
                        byteList.AddRange((IEnumerable <byte>)numArray2);
                        byteList.AddRange((IEnumerable <byte>)bytes);
                        foreach (ulong num in obj as List <ulong> )
                        {
                            byteList.AddRange((IEnumerable <byte>)BitConverter.GetBytes(num));
                        }
                        numArray2 = byteList.ToArray();
                        break;
                    }
                    if (type == typeof(GameDescription))
                    {
                        numArray2 = SimplePack.Pack((object)JsonConvert.SerializeObject(obj));
                        break;
                    }
                    break;

                case TypeCode.Boolean:
                    numArray2 = BitConverter.GetBytes((bool)obj);
                    break;

                case TypeCode.Byte:
                    numArray2 = new byte[1] {
                        (byte)obj
                    };
                    break;

                case TypeCode.Int16:
                    numArray2 = BitConverter.GetBytes((short)obj);
                    break;

                case TypeCode.UInt16:
                    numArray2 = BitConverter.GetBytes((ushort)obj);
                    break;

                case TypeCode.Int32:
                    numArray2 = BitConverter.GetBytes((int)obj);
                    break;

                case TypeCode.UInt32:
                    numArray2 = BitConverter.GetBytes((uint)obj);
                    break;

                case TypeCode.Double:
                    numArray2 = BitConverter.GetBytes((double)obj);
                    break;

                case TypeCode.String:
                    byte[] bytes1 = Encoding.UTF8.GetBytes((string)obj);
                    numArray2 = SimplePack.Pack((object)(ushort)bytes1.Length, (object)bytes1);
                    break;

                default:
                    //Logger.Default.Debug("type:" + (object)type, new object[0]);
                    //Logger.Default.Debug("input type error", new object[0]);
                    break;
                }
                numArray1 = ((IEnumerable <byte>)numArray1).Concat <byte>((IEnumerable <byte>)numArray2).ToArray <byte>();
            }
            return(numArray1);
        }