private OperationResponse ItemOperationSetProperties(Item item, SetProperties operation, SendParameters sendParameters, MmoActor actor)
        {
            MethodReturnValue result = this.CheckAccess(item, actor);

            if (result)
            {
                item.properties.SetProperties(operation.PropertiesSet, operation.PropertiesUnset);
                var eventInstance = new ItemPropertiesSet {
                    ItemId             = item.Id,
                    ItemType           = item.Type,
                    PropertiesRevision = item.properties.propertiesRevision,
                    PropertiesSet      = operation.PropertiesSet,
                    PropertiesUnset    = operation.PropertiesUnset
                };

                var eventData = new EventData((byte)EventCode.ItemPropertiesSet, eventInstance);
                sendParameters.ChannelId = Settings.ItemEventChannel;
                var message = new ItemEventMessage(item, eventData, sendParameters);
                item.EventChannel.Publish(message);

                // no response sent
                operation.OnComplete();
                return(null);
            }

            return(operation.GetOperationResponse(result));
        }
        private OperationResponse ItemOperationDestroy(MmoActor actor, Item item, DestroyItem operation)
        {
            MethodReturnValue result = this.CheckAccess(item, actor);

            if (result)
            {
                item.Destroy();
                item.Dispose();
                actor.RemoveItem(item);

                (item.world as MmoWorld).ItemCache.RemoveItem(item.Type, item.Id);
                var eventInstance = new ItemDestroyed {
                    ItemId = item.Id, ItemType = item.Type
                };
                var eventData = new EventData((byte)EventCode.ItemDestroyed, eventInstance);
                actor.Peer.SendEvent(eventData, new SendParameters {
                    ChannelId = Settings.ItemEventChannel
                });

                // no response, event is sufficient
                operation.OnComplete();
                return(null);
            }

            return(operation.GetOperationResponse(result));
        }
Пример #3
0
        public override void HandleReturnValue(MultiValue returnValue, IOperation operation)
        {
            var associatedMethod = (IMethodSymbol)Context.OwningSymbol;

            if (associatedMethod.ReturnType.IsTypeInterestingForDataflow())
            {
                var returnParameter = new MethodReturnValue(associatedMethod);

                TrimAnalysisPatterns.Add(
                    new TrimAnalysisAssignmentPattern(returnValue, returnParameter, operation),
                    isReturnValue: true
                    );
            }
        }
        protected MethodReturnValue CheckAccess(Item item, MmoActor actor)
        {
            if (item.Disposed)
            {
                return(MethodReturnValue.Fail((int)ReturnCode.ItemNotFound, "ItemNotFound"));
            }

            if (((IMmoItem)item).GrantWriteAccess(actor))
            {
                return(MethodReturnValue.Ok);
            }

            return(MethodReturnValue.Fail((int)ReturnCode.ItemAccessDenied, "ItemAccessDenied"));
        }
Пример #5
0
        private MethodReturnValue CheckAccess(Item item)
        {
            if (item.Disposed)
            {
                return(MethodReturnValue.Fail((int)ReturnCode.ItemNotFound, "ItemNotFound"));
            }

            if (((IMmoItem)item).GrantWriteAccess(this))
            {
                return(MethodReturnValue.Ok);
            }

            return(MethodReturnValue.Fail((int)ReturnCode.ItemAccessDenied, "ItemAccessDenied"));
        }
Пример #6
0
        public OperationResponse OperationCreateWorld(PeerBase peer, OperationRequest request)
        {
            try
            {
                var operation = new CreateWorld(peer.Protocol, request);
                if (!operation.IsValid)
                {
                    return(new OperationResponse(request.OperationCode)
                    {
                        ReturnCode = (int)ReturnCode.InvalidOperationParameter,
                        DebugMessage = operation.GetErrorMessage()
                    });
                }

                MmoWorld          world;
                MethodReturnValue result = MethodReturnValue.Ok;


                if (GameApplication.ResourcePool() == null)
                {
                    log.Info("Resource pool is null");
                }

                log.InfoFormat("find resource for world = {0}", operation.WorldName);

                Res resource = GameApplication.ResourcePool().Resource(operation.WorldName);

                if (MmoWorldCache.Instance(application).TryCreate(operation.WorldName,
                                                                  Settings.CornerMin,
                                                                  Settings.CornerMax,
                                                                  Settings.TileDimensions, out world, resource))
                {
                    result = MethodReturnValue.Ok;
                    world.Initialize();
                }
                else
                {
                    result = MethodReturnValue.Fail((int)ReturnCode.WorldAlreadyExists, "WorldAlreadyExists");
                }

                return(operation.GetOperationResponse(result));
            }
            catch (Exception ex)
            {
                CL.Out(LogFilter.PLAYER, ex.Message);
                CL.Out(LogFilter.PLAYER, ex.StackTrace);
            }
            return(null);
        }
Пример #7
0
        public override MultiValue HandleMethodCall(IMethodSymbol calledMethod, MultiValue instance, ImmutableArray <MultiValue> arguments, IOperation operation)
        {
            // For .ctors:
            // - The instance value is empty (TopValue) and that's a bit wrong.
            //   Technically this is an instance call and the instance is some valid value, we just don't know which
            //   but for example it does have a static type. For now this is OK since we don't need the information
            //   for anything yet.
            // - The return here is also technically problematic, the return value is an instance of a known type,
            //   but currently we return empty (since the .ctor is declared as returning void).
            //   Especially with DAM on type, this can lead to incorrectly analyzed code (as in unknown type which leads
            //   to noise). Linker has the same problem currently: https://github.com/dotnet/linker/issues/1952

            var diagnosticContext = DiagnosticContext.CreateDisabled();
            var handleCallAction  = new HandleCallAction(diagnosticContext, Context.OwningSymbol, operation);

            if (!handleCallAction.Invoke(new MethodProxy(calledMethod), instance, arguments, out MultiValue methodReturnValue))
            {
                if (!calledMethod.ReturnsVoid && calledMethod.ReturnType.IsTypeInterestingForDataflow())
                {
                    methodReturnValue = new MethodReturnValue(calledMethod);
                }
                else
                {
                    methodReturnValue = TopValue;
                }
            }

            TrimAnalysisPatterns.Add(new TrimAnalysisMethodCallPattern(
                                         calledMethod,
                                         instance,
                                         arguments,
                                         operation,
                                         Context.OwningSymbol));

            foreach (var argument in arguments)
            {
                foreach (var argumentValue in argument)
                {
                    if (argumentValue is ArrayValue arrayValue)
                    {
                        arrayValue.IndexValues.Clear();
                    }
                }
            }

            return(methodReturnValue);
        }
Пример #8
0
        private OperationResponse ItemOperationMove(MmoItem item, Move operation, SendParameters sendParameters, MmoActor actor) {
            // should always be OK
            MethodReturnValue result = this.CheckAccess(item, actor);

            if (result) {
                // save previous for event
                float[] oldPosition = item.transform.position.ToArray();
                float[] oldRotation = item.transform.rotation.ToArray();

                // move
                item.transform.SetRotation(operation.Rotation);
                item.Move(operation.Position);

                float speed = 0f;
                var ship = item.GetComponent<PlayerShip>();
                var movalble = item.GetComponent<MovableObject>();
                if(ship) {
                    speed = movalble.speed;
                }

                // send event
                var eventInstance = new ItemMoved {
                    ItemId = item.Id,
                    ItemType = item.Type,
                    OldPosition = oldPosition,
                    Position = operation.Position,
                    Rotation = operation.Rotation,
                    OldRotation = oldRotation,
                    Speed = speed
                };

                var eventData = new EventData((byte)EventCode.ItemMoved, eventInstance);
                sendParameters.ChannelId = Settings.ItemEventChannel;
                var message = new ItemEventMessage(item, eventData, sendParameters);
                item.EventChannel.Publish(message);

                //I ADDED toMOVE AT POSITION
                //item.ReceiveEvent(eventData, sendParameters);

                // no response sent
                operation.OnComplete();
                return null;
            }

            return operation.GetOperationResponse(result);
        }
Пример #9
0
 /// <summary>
 /// Gets the operation response.
 /// </summary>
 /// <param name="returnValue">
 /// The return value.
 /// </param>
 /// <returns>
 /// A new operation response.
 /// </returns>
 public OperationResponse GetOperationResponse(MethodReturnValue returnValue)
 {
     return GetOperationResponse(returnValue.Error, returnValue.Debug);
 }
Пример #10
0
 /// <summary>
 /// Gets the operation response.
 /// </summary>
 /// <param name="returnValue">
 /// The return value.
 /// </param>
 /// <returns>
 /// A new operation response.
 /// </returns>
 public OperationResponse GetOperationResponse(MethodReturnValue returnValue)
 {
     return(this.GetOperationResponse(returnValue.Error, returnValue.Debug));
 }
Пример #11
0
 /// <summary>
 /// Gets the operation response.
 /// </summary>
 /// <param name="returnValue">
 /// The return value.
 /// </param>
 /// <returns>
 /// A new operation response.
 /// </returns>
 public OperationResponse GetOperationResponse(MethodReturnValue returnValue, Hashtable content)
 {
     return(this.GetOperationResponse(returnValue.Error, returnValue.Debug, content));
 }