Ejemplo n.º 1
0
        public async Task UpdateObject(string objectIdentifier, ObjectUpdateRequest query, bool isSuperUser)
        {
            if (!isSuperUser)
            {
                throw new InvalidOperationException("User cannot update object");
            }

            var schema = schemaRegistry.GetSchemaByTypeIdentifier(objectIdentifier);

            if (!schema.Description.AllowEdit)
            {
                throw new InvalidOperationException($"Updating is not allowed for {objectIdentifier}");
            }

            var connector = schemaRegistry.GetConnector(objectIdentifier);
            var oldObject = await connector.Read(query.Conditions).ConfigureAwait(false);

            if (oldObject == null)
            {
                throw new InvalidOperationException("Expected edited object to exist");
            }

            var updatedObject = ObjectPropertyEditor.SetValue(oldObject, query.Path, query.Value, schema.CustomPropertyConfigurationProvider);
            await connector.Write(updatedObject).ConfigureAwait(false);
        }
Ejemplo n.º 2
0
        public async Task Login(Guid sessionId)
        {
            VerifyExists();

            if (sessionId == Guid.Empty)
            {
                throw new ArgumentException($"cannot be an empty {nameof(Guid)}", nameof(sessionId));
            }

            SessionId = sessionId;

            await ActivateWorkingSet();

            // send creation update for self to client
            var objectUpdateRequest = new ObjectUpdateRequest()
            {
                TargetObjectId = State.Id,
            };

            objectUpdateRequest.ObjectUpdates.Add(GetCreationUpdate());

            var mapManager    = GrainFactory.GetGrain <IMapManager>(0);
            var mapInstanceId = await mapManager.GetInstanceIdForCharacter(State);

            var mapInstance = GrainFactory.GetGrain <IMap>(mapInstanceId);
            await mapInstance.AddObject(State);

            await Send(objectUpdateRequest);
        }
Ejemplo n.º 3
0
 public Task UpdateObject(string objectIdentifier, [FromBody] ObjectUpdateRequest query) => impl.UpdateObject(objectIdentifier, query, IsSuperUser());
Ejemplo n.º 4
0
        private async Task <JObject> Write(string objectIdentifier, ObjectUpdateRequest query)
        {
            await client.Write(objectIdentifier, query);

            return((JObject)(await client.Read(objectIdentifier, query.Conditions)).Object);
        }
Ejemplo n.º 5
0
        public override void HandleObjectUpdate(ObjectEntity objectEntity, ObjectUpdate update)
        {
            base.HandleObjectUpdate(objectEntity, update);

            var tasks = new LinkedList <Task>();

            var objectUpdateRequest = new ObjectUpdateRequest()
            {
                TargetObjectId = State.Id,
            };

            objectUpdateRequest.ObjectUpdates.Add(update);
            tasks.AddLast(Send(objectUpdateRequest));

            // for Unit entities, we need to send move start/stop/heartbeat packets as well
            if (objectEntity is UnitEntity unitEntity)
            {
                var opcodes = new LinkedList <ShardServerOpcode>();

                if (unitEntity.Jumped)
                {
                    opcodes.AddLast(ShardServerOpcode.MoveJump);
                }
                if (unitEntity.PreviousMoveFlags.HasFlag(MovementFlags.ModeFalling) && !unitEntity.MoveFlags.HasFlag(MovementFlags.ModeFalling))
                {
                    opcodes.AddLast(ShardServerOpcode.MoveFallLand);
                }

                if ((unitEntity.MoveFlags & MovementFlags.MoveMask) != 0 && unitEntity.PreviousMoveFlags == unitEntity.MoveFlags)
                {
                    // heartbeat
                    opcodes.AddLast(ShardServerOpcode.MoveHeartbeat);
                }
                else
                {
                    // complicated
                    if ((unitEntity.MoveFlags & MovementFlags.MoveLeft) != 0 && (unitEntity.PreviousMoveFlags & MovementFlags.MoveLeft) == 0)
                    {
                        opcodes.AddLast(ShardServerOpcode.MoveStrafeStartLeft);
                    }
                    else if ((unitEntity.MoveFlags & MovementFlags.MoveRight) != 0 && (unitEntity.PreviousMoveFlags & MovementFlags.MoveRight) == 0)
                    {
                        opcodes.AddLast(ShardServerOpcode.MoveStrafeStartRight);
                    }
                    else if ((unitEntity.MoveFlags & (MovementFlags.MoveLeft | MovementFlags.MoveRight)) == 0 && (unitEntity.PreviousMoveFlags & (MovementFlags.MoveLeft | MovementFlags.MoveRight)) != 0)
                    {
                        opcodes.AddLast(ShardServerOpcode.MoveStrafeStop);
                    }

                    if ((unitEntity.MoveFlags & MovementFlags.MoveForward) != 0 && (unitEntity.PreviousMoveFlags & MovementFlags.MoveForward) == 0)
                    {
                        opcodes.AddLast(ShardServerOpcode.MoveStartForward);
                    }
                    else if ((unitEntity.MoveFlags & MovementFlags.MoveBackward) != 0 && (unitEntity.PreviousMoveFlags & MovementFlags.MoveBackward) == 0)
                    {
                        opcodes.AddLast(ShardServerOpcode.MoveStartBackward);
                    }
                    else if ((unitEntity.MoveFlags & (MovementFlags.MoveForward | MovementFlags.MoveBackward)) == 0 && (unitEntity.PreviousMoveFlags & (MovementFlags.MoveForward | MovementFlags.MoveBackward)) != 0)
                    {
                        opcodes.AddLast(ShardServerOpcode.MoveStop);
                    }

                    if ((unitEntity.MoveFlags & MovementFlags.TurnLeft) != 0 && (unitEntity.PreviousMoveFlags & MovementFlags.TurnLeft) == 0)
                    {
                        opcodes.AddLast(ShardServerOpcode.MoveTurnStartLeft);
                    }
                    else if ((unitEntity.MoveFlags & MovementFlags.TurnRight) != 0 && (unitEntity.PreviousMoveFlags & MovementFlags.TurnRight) == 0)
                    {
                        opcodes.AddLast(ShardServerOpcode.MoveTurnStartRight);
                    }
                    else if ((unitEntity.MoveFlags & (MovementFlags.TurnLeft | MovementFlags.TurnRight)) == 0 && (unitEntity.PreviousMoveFlags & (MovementFlags.TurnLeft | MovementFlags.TurnRight)) != 0)
                    {
                        opcodes.AddLast(ShardServerOpcode.MoveTurnStop);
                    }
                }

                if (unitEntity.Orientation != unitEntity.PreviousOrientation && (unitEntity.MoveFlags & (MovementFlags.TurnLeft | MovementFlags.TurnRight)) == 0)
                {
                    opcodes.AddLast(ShardServerOpcode.MoveSetOrientation);
                }

                foreach (var opcode in opcodes)
                {
                    var movePacket = new MovementOutPacket(opcode)
                    {
                        ObjectId = unitEntity.Id,

                        FallTime      = unitEntity.FallTime,
                        MovementFlags = unitEntity.MoveFlags,
                        Orientation   = unitEntity.Orientation,
                        Pitch         = unitEntity.MovePitch,
                        Position      = unitEntity.Position,
                        Time          = unitEntity.MoveTime,

                        Falling = new MovementOutPacket.FallingInfo()
                        {
                            CosAngle = unitEntity.Jump.CosineAngle,
                            SinAngle = unitEntity.Jump.SineAngle,
                            Velocity = unitEntity.Jump.Velocity,
                            XYSpeed  = unitEntity.Jump.XYSpeed,
                        },
                        Transport = null,
                    };

                    tasks.AddLast(Send(movePacket));
                }
            }

            Task.WhenAll(tasks).Wait();
        }
Ejemplo n.º 6
0
 public Task UpdateObject(string objectIdentifier, [FromBody] ObjectUpdateRequest query) => impl.UpdateObject(objectIdentifier, query, true);
Ejemplo n.º 7
0
 public Task <object> Write(string objectIdentifier, ObjectUpdateRequest query)
 {
     return(Request <object>(x => x.PostAsync($"{objectIdentifier}/update", new StringContent(JsonConvert.SerializeObject(query), Encoding.UTF8, "application/json"))));
 }