Exemplo n.º 1
0
        private IMPArray DecodeMPArray(ByteArray buffer)
        {
            IMPArray   array = MPArray.NewInstance();
            MPDataType type  = (MPDataType)Convert.ToInt32(buffer.ReadByte());

            if (type != MPDataType.MP_ARRAY)
            {
                throw new Exception(string.Concat("Invalid MPDataType. Expected: ", MPDataType.MP_ARRAY, ", found: ", type));
            }
            int num = buffer.ReadShort();

            if (num < 0)
            {
                throw new Exception("Can't decode MPArray. Size is negative: " + num);
            }
            for (int i = 0; i < num; i++)
            {
                MPDataWrapper val = DecodeObject(buffer);
                if (val == null)
                {
                    throw new Exception("Could not decode SFSArray item at index: " + i);
                }
                array.Add(val);
            }
            return(array);
        }
Exemplo n.º 2
0
        private MPDataWrapper DecodeObject(ByteArray buffer)
        {
            MPDataType type = (MPDataType)Convert.ToInt32(buffer.ReadByte());

            switch (type)
            {
            case MPDataType.NULL:
                return(BinDecode_NULL(buffer));

            case MPDataType.BOOL:
                return(BinDecode_BOOL(buffer));

            case MPDataType.BYTE:
                return(BinDecode_BYTE(buffer));

            case MPDataType.BYTE_ARRAY:
                return(BinDecode_BYTE_ARRAY(buffer));

            case MPDataType.SHORT:
                return(BinDecode_SHORT(buffer));

            case MPDataType.INT:
                return(BinDecode_INT(buffer));

            case MPDataType.LONG:
                return(BinDecode_LONG(buffer));

            case MPDataType.FLOAT:
                return(BinDecode_FLOAT(buffer));

            case MPDataType.DOUBLE:
                return(BinDecode_DOUBLE(buffer));

            case MPDataType.UTF_STRING:
                return(BinDecode_UTF_STRING(buffer));

            case MPDataType.MP_ARRAY:
                buffer.Position--;
                return(new MPDataWrapper(MPDataType.MP_ARRAY, DecodeMPArray(buffer)));
            }
            if (type != MPDataType.MP_OBJECT)
            {
                throw new Exception("Unknow MPDataType ID: " + type);
            }
            buffer.Position--;
            IMPObject mpObj = DecodeMPObject(buffer);
            byte      num   = Convert.ToByte(MPDataType.MP_OBJECT);
            object    data  = mpObj;

            if (mpObj.ContainsKey(CLASS_MARKER_KEY) && mpObj.ContainsKey(CLASS_FIELDS_KEY))
            {
                num  = Convert.ToByte(MPDataType.CLASS);
                data = Mp2Cs(mpObj);
            }
            return(new MPDataWrapper(num, data));
        }
Exemplo n.º 3
0
        public static void receiveMessage(IncomingMessage inc)
        {
            long       receiver = inc.Reader.ReadInt64();
            int        type     = inc.Reader.ReadInt16();
            string     address  = inc.Reader.ReadString();
            MPDataType dataType = (MPDataType)inc.Reader.ReadInt16();
            object     data     = null;

            switch (dataType)
            {
            case MPDataType.STRING: data = inc.Reader.ReadString(); break;

            case MPDataType.INT: data = inc.Reader.ReadInt32(); break;

            case MPDataType.BOOL: data = inc.Reader.ReadBoolean(); break;

            case MPDataType.DOUBLE: data = inc.Reader.ReadDouble(); break;

            case MPDataType.LONG: data = inc.Reader.ReadInt64(); break;

            default: data = inc.Reader.ReadString(); break;
            }

            MPMessage message = new MPMessage(address, inc.SourceFarmer, data, type, receiver);

            if (Game1.IsServer && receiver != Game1.player.UniqueMultiplayerID)
            {
                sendMessage(message);
            }

            if (receiver == -1 || receiver == Game1.player.UniqueMultiplayerID)
            {
                if (!messages.ContainsKey(address))
                {
                    messages.Add(address, new List <MPMessage>());
                }

                messages[address].Add(message);
            }
        }
Exemplo n.º 4
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="tp"></param>
 /// <param name="data"></param>
 public MPDataWrapper(MPDataType tp, object data)
 {
     type      = (int)tp;
     this.data = data;
 }
Exemplo n.º 5
0
 private void AddObject(object val, MPDataType tp)
 {
     Add(new MPDataWrapper((int)tp, val));
 }
Exemplo n.º 6
0
 public void WriteByte(MPDataType tp)
 {
     WriteByte(Convert.ToByte((int)tp));
 }