public override void ReceiveUpdate(BSONObject bsonObj)
    {
        bool changed = false;

        if (!bsonObj.ContainsKey("trunks"))
        {
            return;
        }
        BSONArray trunks = bsonObj["trunks"].ArrayValue;

        foreach (BSONObject obj in trunks)
        {
            Guid       id    = obj["id"];
            TrunkPiece piece = this.trunkPieces.FirstOrDefault(p => p.ID == id);

            if (piece != null && (piece.Position != obj["pos"] || piece.Rotation != obj["rot"]))
            {
                piece.Position       = obj["pos"];
                piece.Rotation       = obj["rot"];
                piece.Velocity       = obj["v"];
                piece.LastUpdateTime = TimeUtil.Seconds;
                changed = true;
            }
        }

        if (changed)
        {
            if (this.UpRooted)
            {
                this.Position = this.trunkPieces.First().Position;
            }
            this.lastKeyframeTime = bsonObj["time"];
            this.LastUpdateTime   = TimeUtil.Seconds;
        }
    }
Ejemplo n.º 2
0
        public override void ReceiveUpdate(BSONObject bsonObj)
        {
            base.ReceiveUpdate(bsonObj);
            if (bsonObj.ContainsKey("cage"))
            {
                var cagebson = bsonObj["cage"].ObjectValue;
                this.cagePos      = cagebson["pos"].Vector3Value.y;
                this.cageVelocity = cagebson["v"].Vector3Value.y;
            }

            if (bsonObj.ContainsKey("stop"))
            {
                this.cageVelocity = 0f;
                this.SetAnimatedState("dir", 0f);
            }
        }
Ejemplo n.º 3
0
        private byte[] OnPacket(byte[] revBuffer, String from)
        {
            // Remove padding and load the bson.
            byte[] data = new byte[revBuffer.Length - 4];
            Buffer.BlockCopy(revBuffer, 4, data, 0, data.Length);

            BSONObject packets = null;

            try
            {
                packets = SimpleBSON.Load(data);
            }catch { }

            if (packets == null || !packets.ContainsKey("mc"))
            {
                return(revBuffer);
            }

            // Modify the packet?
            Console.WriteLine(from + " ========================================================================================");
            for (int i = 0; i < packets["mc"]; i++)
            {
                BSONObject packet = packets["m" + i] as BSONObject;
                ReadBSON(packet);

                if (packet["ID"].stringValue == "OoIP")
                {
                    PIXEL_IP     = (packet["IP"].stringValue == "prod.gamev70.portalworldsgame.com" ? "3.220.252.91" : packet["IP"].stringValue);
                    packet["IP"] = "prod.gamev70.portalworldsgame.com";
                }
            }

            // Dump the BSON and add padding.
            MemoryStream memoryStream = new MemoryStream();

            using (BinaryWriter binaryWriter = new BinaryWriter(memoryStream))
            {
                byte[] bsonDump = SimpleBSON.Dump(packets);

                binaryWriter.Write(bsonDump.Length + 4);
                binaryWriter.Write(bsonDump);
            }
            return(memoryStream.ToArray());
        }
Ejemplo n.º 4
0
 public IClientCmd decodeBSON(BSONObject obj)
 {
     //Debug.Log("Try to decode !");
     if (obj.ContainsKey("meta"))
     {
         string meta = obj ["meta"];
         //Debug.Log ("Meta:" + meta);
         Type t = Type.GetType("UnityBSONClient." + meta);
         if (t == null)
         {
             //Debug.Log ("Meta:" + meta + " not found");
             return(null);
         }
         IClientCmd cmd = (IClientCmd)Activator.CreateInstance(t);
         cmd.decode(obj);
         return(cmd);
     }
     return(null);
 }
        public override void ReceiveUpdate(BSONObject bsonObj)
        {
            BSONValue cageUpdate;

            if (bsonObj.TryGetValue("cage", out cageUpdate))
            {
                this.cagePos    = cageUpdate.ObjectValue["pos"].Vector3Value.y;
                bsonObj["time"] = cageUpdate.ObjectValue["time"].FloatValue;
                if (cageUpdate.ObjectValue.ContainsKey("v"))
                {
                    this.v = cageUpdate.ObjectValue["v"].Vector3Value.y;
                }
            }
            base.ReceiveUpdate(bsonObj);

            if (bsonObj.ContainsKey("stop"))
            {
                this.v = 0f;
                this.AnimatedStates["dir"] = 0f;
            }
            this.SetDirty();
        }