예제 #1
0
        private ISFSArray DecodeSFSArray(ByteArray buffer)
        {
            //Discarded unreachable code: IL_00c1
            ISFSArray   iSFSArray   = SFSArray.NewInstance();
            SFSDataType sFSDataType = (SFSDataType)Convert.ToInt32(buffer.ReadByte());

            if (sFSDataType != SFSDataType.SFS_ARRAY)
            {
                throw new SFSCodecError(string.Concat("Invalid SFSDataType. Expected: ", SFSDataType.SFS_ARRAY, ", found: ", sFSDataType));
            }
            int num = buffer.ReadShort();

            if (num < 0)
            {
                throw new SFSCodecError("Can't decode SFSArray. Size is negative: " + num);
            }
            try
            {
                for (int i = 0; i < num; i++)
                {
                    SFSDataWrapper sFSDataWrapper = DecodeObject(buffer);
                    if (sFSDataWrapper != null)
                    {
                        iSFSArray.Add(sFSDataWrapper);
                        continue;
                    }
                    throw new SFSCodecError("Could not decode SFSArray item at index: " + i);
                }
                return(iSFSArray);
            }
            catch (SFSCodecError sFSCodecError)
            {
                throw sFSCodecError;
            }
        }
예제 #2
0
        private ISFSArray UnrollArray(ArrayList arr)
        {
            ISFSArray   iSFSArray  = SFSArray.NewInstance();
            IEnumerator enumerator = arr.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    object         current        = enumerator.Current;
                    SFSDataWrapper sFSDataWrapper = WrapField(current);
                    if (sFSDataWrapper == null)
                    {
                        throw new SFSCodecError(string.Concat("Cannot serialize field of array: ", current, " -- unsupported type!"));
                    }
                    iSFSArray.Add(sFSDataWrapper);
                }
                return(iSFSArray);
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = enumerator as IDisposable) != null)
                {
                    disposable.Dispose();
                }
            }
        }
예제 #3
0
        private void ConvertCsObj(object csObj, ISFSObject sfsObj)
        {
            Type   type     = csObj.GetType();
            string fullName = type.FullName;
            SerializableSFSType serializableSFSType = csObj as SerializableSFSType;

            if (serializableSFSType == null)
            {
                throw new SFSCodecError(string.Concat("Cannot serialize object: ", csObj, ", type: ", fullName, " -- It doesn't implement the SerializableSFSType interface"));
            }
            ISFSArray iSFSArray = SFSArray.NewInstance();

            sfsObj.PutUtfString(CLASS_MARKER_KEY, fullName);
            sfsObj.PutSFSArray(CLASS_FIELDS_KEY, iSFSArray);
            FieldInfo[] fields = type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
            FieldInfo[] array  = fields;
            foreach (FieldInfo fieldInfo in array)
            {
                string         name           = fieldInfo.Name;
                object         value          = fieldInfo.GetValue(csObj);
                ISFSObject     iSFSObject     = SFSObject.NewInstance();
                SFSDataWrapper sFSDataWrapper = WrapField(value);
                if (sFSDataWrapper != null)
                {
                    iSFSObject.PutUtfString(FIELD_NAME_KEY, name);
                    iSFSObject.Put(FIELD_VALUE_KEY, sFSDataWrapper);
                    iSFSArray.AddSFSObject(iSFSObject);
                    continue;
                }
                throw new SFSCodecError(string.Concat("Cannot serialize field of object: ", csObj, ", field: ", name, ", type: ", fieldInfo.GetType().Name, " -- unsupported type!"));
            }
        }
예제 #4
0
        private object UnwrapField(SFSDataWrapper wrapper)
        {
            object result = null;
            int    type   = wrapper.Type;

            if (type <= 8)
            {
                result = wrapper.Data;
            }
            else
            {
                switch (type)
                {
                case 17:
                    result = RebuildArray(wrapper.Data as ISFSArray);
                    break;

                case 18:
                {
                    ISFSObject iSFSObject = wrapper.Data as ISFSObject;
                    result = ((!iSFSObject.ContainsKey(CLASS_MARKER_KEY) || !iSFSObject.ContainsKey(CLASS_FIELDS_KEY)) ? RebuildDict(wrapper.Data as ISFSObject) : Sfs2Cs(iSFSObject));
                    break;
                }

                case 19:
                    result = wrapper.Data;
                    break;
                }
            }
            return(result);
        }
예제 #5
0
        private ISFSObject UnrollDictionary(Hashtable dict)
        {
            ISFSObject  iSFSObject = SFSObject.NewInstance();
            IEnumerator enumerator = dict.Keys.GetEnumerator();

            try
            {
                while (enumerator.MoveNext())
                {
                    string         text           = (string)enumerator.Current;
                    SFSDataWrapper sFSDataWrapper = WrapField(dict[text]);
                    if (sFSDataWrapper == null)
                    {
                        throw new SFSCodecError(string.Concat("Cannot serialize field of dictionary with key: ", text, ", ", dict[text], " -- unsupported type!"));
                    }
                    iSFSObject.Put(text, sFSDataWrapper);
                }
                return(iSFSObject);
            }
            finally
            {
                IDisposable disposable;
                if ((disposable = enumerator as IDisposable) != null)
                {
                    disposable.Dispose();
                }
            }
        }
예제 #6
0
 private ByteArray Arr2bin(ISFSArray array, ByteArray buffer)
 {
     for (int i = 0; i < array.Size(); i++)
     {
         SFSDataWrapper wrappedElementAt = array.GetWrappedElementAt(i);
         buffer = EncodeObject(buffer, wrappedElementAt.Type, wrappedElementAt.Data);
     }
     return(buffer);
 }
예제 #7
0
        private SFSDataWrapper WrapField(object val)
        {
            if (val == null)
            {
                return(new SFSDataWrapper(SFSDataType.NULL, null));
            }
            SFSDataWrapper result = null;

            if (val is bool)
            {
                result = new SFSDataWrapper(SFSDataType.BOOL, val);
            }
            else if (val is byte)
            {
                result = new SFSDataWrapper(SFSDataType.BYTE, val);
            }
            else if (val is short)
            {
                result = new SFSDataWrapper(SFSDataType.SHORT, val);
            }
            else if (val is int)
            {
                result = new SFSDataWrapper(SFSDataType.INT, val);
            }
            else if (val is long)
            {
                result = new SFSDataWrapper(SFSDataType.LONG, val);
            }
            else if (val is float)
            {
                result = new SFSDataWrapper(SFSDataType.FLOAT, val);
            }
            else if (val is double)
            {
                result = new SFSDataWrapper(SFSDataType.DOUBLE, val);
            }
            else if (val is string)
            {
                result = new SFSDataWrapper(SFSDataType.UTF_STRING, val);
            }
            else if (val is ArrayList)
            {
                result = new SFSDataWrapper(SFSDataType.SFS_ARRAY, UnrollArray(val as ArrayList));
            }
            else if (val is SerializableSFSType)
            {
                result = new SFSDataWrapper(SFSDataType.SFS_OBJECT, Cs2Sfs(val));
            }
            else if (val is Hashtable)
            {
                result = new SFSDataWrapper(SFSDataType.SFS_OBJECT, UnrollDictionary(val as Hashtable));
            }
            return(result);
        }
예제 #8
0
 private void ConvertSFSObject(ISFSArray fieldList, object csObj, Type objType)
 {
     for (int i = 0; i < fieldList.Size(); i++)
     {
         ISFSObject     sFSObject = fieldList.GetSFSObject(i);
         string         utfString = sFSObject.GetUtfString(FIELD_NAME_KEY);
         SFSDataWrapper data      = sFSObject.GetData(FIELD_VALUE_KEY);
         object         value     = UnwrapField(data);
         objType.GetField(utfString, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.SetValue(csObj, value);
     }
 }
예제 #9
0
 private ByteArray Obj2bin(ISFSObject obj, ByteArray buffer)
 {
     string[] keys  = obj.GetKeys();
     string[] array = keys;
     foreach (string text in array)
     {
         SFSDataWrapper data = obj.GetData(text);
         buffer = EncodeSFSObjectKey(buffer, text);
         buffer = EncodeObject(buffer, data.Type, data.Data);
     }
     return(buffer);
 }
예제 #10
0
        private ISFSArray decodeSFSArray(JsonData jdo)
        {
            ISFSArray iSFSArray = SFSArrayLite.NewInstance();

            for (int i = 0; i < jdo.Count; i++)
            {
                JsonData       jsonData       = jdo[i];
                SFSDataWrapper sFSDataWrapper = decodeJsonObject(jsonData);
                if (sFSDataWrapper != null)
                {
                    iSFSArray.Add(sFSDataWrapper);
                    continue;
                }
                throw new InvalidOperationException("JSON > ISFSArray error: could not decode value for object: " + jsonData);
            }
            return(iSFSArray);
        }
예제 #11
0
        private ISFSObject decodeSFSObject(JsonData jdo)
        {
            ISFSObject iSFSObject = SFSObjectLite.NewInstance();

            foreach (string key in jdo.Keys)
            {
                JsonData       jdo2           = jdo[key];
                SFSDataWrapper sFSDataWrapper = decodeJsonObject(jdo2);
                if (sFSDataWrapper != null)
                {
                    iSFSObject.Put(key, sFSDataWrapper);
                    continue;
                }
                throw new InvalidOperationException("JSON > ISFSObject error: could not decode value for key: " + key);
            }
            return(iSFSObject);
        }
예제 #12
0
        public void EncryptParameter(string parameterKey, Dictionary <string, SFSDataWrapper> parameters)
        {
            if (!parameters.ContainsKey(parameterKey))
            {
                throw new Exception("Failed to encrypt parameter '" + parameterKey + "'. Parameter not found.");
            }
            SFSDataWrapper sFSDataWrapper = parameters[parameterKey];

            if (sFSDataWrapper.Type != 8)
            {
                throw new Exception("Failed to encrypt parameter '" + parameterKey + "'. Parameter is not a UTF string.");
            }
            string s = sFSDataWrapper.Data.ToString();

            byte[] bytes   = Encoding.UTF8.GetBytes(s);
            byte[] inArray = Encrypt(bytes);
            string str     = Convert.ToBase64String(inArray);

            parameters[parameterKey] = SmartFoxGameServerClientShared.serialize(str);
            parameters.Add(ENCRYPTED_PARAMETER, SmartFoxGameServerClientShared.serialize(parameterKey));
        }
예제 #13
0
 public void flattenArray(List <object> list, ISFSArray sfsArray)
 {
     for (int i = 0; i < sfsArray.Size(); i++)
     {
         SFSDataWrapper wrappedElementAt = sfsArray.GetWrappedElementAt(i);
         if (wrappedElementAt.Type == 18)
         {
             Dictionary <string, object> dictionary = new Dictionary <string, object>();
             list.Add(dictionary);
             flattenObject(dictionary, (ISFSObject)wrappedElementAt.Data);
         }
         else if (wrappedElementAt.Type == 17)
         {
             List <object> list2 = new List <object>();
             list.Add(list2);
             flattenArray(list2, (ISFSArray)wrappedElementAt.Data);
         }
         else
         {
             list.Add(wrappedElementAt.Data);
         }
     }
 }
예제 #14
0
 public void flattenObject(Dictionary <string, object> map, ISFSObject sfsObj)
 {
     string[] keys = sfsObj.GetKeys();
     foreach (string key in keys)
     {
         SFSDataWrapper data = sfsObj.GetData(key);
         if (data.Type == 18)
         {
             Dictionary <string, object> dictionary = new Dictionary <string, object>();
             map.Add(key, dictionary);
             flattenObject(dictionary, (ISFSObject)data.Data);
         }
         else if (data.Type == 17)
         {
             List <object> list = new List <object>();
             map.Add(key, list);
             flattenArray(list, (ISFSArray)data.Data);
         }
         else
         {
             map.Add(key, data.Data);
         }
     }
 }
예제 #15
0
        private ISFSObject DecodeSFSObject(ByteArray buffer)
        {
            //Discarded unreachable code: IL_00c7
            SFSObject sFSObject = SFSObject.NewInstance();
            byte      b         = buffer.ReadByte();

            if (b != Convert.ToByte(18))
            {
                throw new SFSCodecError(string.Concat("Invalid SFSDataType. Expected: ", SFSDataType.SFS_OBJECT, ", found: ", b));
            }
            int num = buffer.ReadShort();

            if (num < 0)
            {
                throw new SFSCodecError("Can't decode SFSObject. Size is negative: " + num);
            }
            try
            {
                for (int i = 0; i < num; i++)
                {
                    string         text           = buffer.ReadUTF();
                    SFSDataWrapper sFSDataWrapper = DecodeObject(buffer);
                    if (sFSDataWrapper != null)
                    {
                        sFSObject.Put(text, sFSDataWrapper);
                        continue;
                    }
                    throw new SFSCodecError("Could not decode value for SFSObject with key: " + text);
                }
                return(sFSObject);
            }
            catch (SFSCodecError sFSCodecError)
            {
                throw sFSCodecError;
            }
        }