Exemplo n.º 1
0
 /// <summary>
 /// Enables handling of the callback with the specified <paramref name="name" /> as an event.
 /// </summary>
 /// <typeparam name="T1">The type of parameter 1 of the callback.</typeparam>
 /// <typeparam name="T2">The type of parameter 2 of the callback.</typeparam>
 /// <typeparam name="T3">The type of parameter 3 of the callback.</typeparam>
 /// <typeparam name="T4">The type of parameter 4 of the callback.</typeparam>
 /// <typeparam name="T5">The type of parameter 5 of the callback.</typeparam>
 /// <typeparam name="T6">The type of parameter 6 of the callback.</typeparam>
 /// <typeparam name="T7">The type of parameter 7 of the callback.</typeparam>
 /// <typeparam name="T8">The type of parameter 8 of the callback.</typeparam>
 /// <typeparam name="T9">The type of parameter 9 of the callback.</typeparam>
 /// <typeparam name="T10">The type of parameter 10 of the callback.</typeparam>
 /// <typeparam name="T11">The type of parameter 11 of the callback.</typeparam>
 /// <typeparam name="T12">The type of parameter 12 of the callback.</typeparam>
 /// <typeparam name="T13">The type of parameter 13 of the callback.</typeparam>
 /// <typeparam name="T14">The type of parameter 14 of the callback.</typeparam>
 /// <typeparam name="T15">The type of parameter 15 of the callback.</typeparam>
 /// <typeparam name="T16">The type of parameter 16 of the callback.</typeparam>
 /// <param name="builder">The ECS builder in which to enable the callback.</param>
 /// <param name="name">The name of the callback.</param>
 /// <returns>A reference to this instance after the operation has completed.</returns>
 public static IEcsBuilder EnableEvent <T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16>(
     this IEcsBuilder builder, string name)
 {
     return(builder.EnableEvent(name, typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5), typeof(T6),
                                typeof(T7), typeof(T8), typeof(T9), typeof(T10), typeof(T11), typeof(T12), typeof(T13), typeof(T14),
                                typeof(T15), typeof(T16)));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Enables all RCON related SA:MP events.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <returns>The builder.</returns>
        public static IEcsBuilder EnableRconEvents(this IEcsBuilder builder)
        {
            builder.EnableEvent <string>("OnRconCommand");
            builder.EnableEvent <string, string, bool>("OnRconLoginAttempt");

            return(builder);
        }
Exemplo n.º 3
0
        public void Configure(IEcsBuilder builder)
        {
            builder.EnableSampEvents()
            .EnablePlayerCommands()
            .EnableRconCommands()
            .EnableEventScope("OnPlayerConnect")
            .EnableEventScope("OnPlayerText");

            builder.EnableEvent <int, int>("TestCallback");

            // Load middleware:
            // Can also be loaded by systems which are IConfiguringSystem
            builder.UseMiddleware("OnGameModeInit", (ctx, next) =>
            {
                Console.WriteLine("I am middleware for OnGameModeInit!");
                return(next());
            });

            builder.UseMiddleware("OnPlayerText", (ctx, next) =>
            {
                if (ctx.Arguments[1] is string txt && txt.Contains("I dislike SampSharp"))
                {
                    return(null);
                }
                return(next());
            });
        public void Configure(IEcsBuilder builder)
        {
            // TODO: Enable desired ECS system features

            builder.EnableSampEvents()
            .EnablePlayerCommands()
            .EnableRconCommands();
        }
Exemplo n.º 5
0
        /// <summary>
        /// Enables all object related SA:MP events.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <returns>The builder.</returns>
        public static IEcsBuilder EnableObjectEvents(this IEcsBuilder builder)
        {
            builder.EnableEvent <int>("OnObjectMoved");
            builder.EnableEvent <int, int>("OnPlayerObjectMoved");

            builder.UseMiddleware <EntityMiddleware>("OnObjectMoved", 0, SampEntities.ObjectType, false);
            builder.UseMiddleware <PlayerObjectMiddleware>("OnPlayerObjectMoved");
            return(builder);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Enables all actor, player related SA:MP events.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>The builder.</returns>
 public static IEcsBuilder EnableSampEvents(this IEcsBuilder builder)
 {
     return(builder
            .EnableActorEvents()
            .EnablePlayerEvents()
            .EnableObjectEvents()
            .EnableRconEvents()
            .EnableVehicleEvents());
 }
Exemplo n.º 7
0
        /// <summary>
        /// Enables all actor related SA:MP events.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <returns>The builder.</returns>
        public static IEcsBuilder EnableActorEvents(this IEcsBuilder builder)
        {
            builder.EnableEvent <int, int>("OnActorStreamIn");
            builder.EnableEvent <int, int>("OnActorStreamOut");

            builder.UseMiddleware <EntityMiddleware>("OnActorStreamIn", 0, ActorType, true);
            builder.UseMiddleware <EntityMiddleware>("OnActorStreamIn", 1, PlayerType, true);
            builder.UseMiddleware <EntityMiddleware>("OnActorStreamOut", 0, ActorType, true);
            builder.UseMiddleware <EntityMiddleware>("OnActorStreamOut", 1, PlayerType, true);

            return(builder);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Adds a middleware of the specified type <paramref name="middleware" /> to the handler of the event with the specified
        /// <paramref name="name" />.
        /// </summary>
        /// <param name="builder">The ECS builder to add the middleware to.</param>
        /// <param name="name">The name of the event.</param>
        /// <param name="middleware">The type of the middleware.</param>
        /// <param name="args">The arguments for the constructor of the event.</param>
        /// <returns>A reference to this instance after the operation has completed.</returns>
        public static IEcsBuilder UseMiddleware(this IEcsBuilder builder, string name, Type middleware,
                                                params object[] args)
        {
            var applicationServices = builder.Services;

            return(builder.UseMiddleware(name, next =>
            {
                var methods = middleware.GetMethods(BindingFlags.Instance | BindingFlags.Public);
                var invokeMethods = methods.Where(m =>
                                                  string.Equals(m.Name, "Invoke", StringComparison.Ordinal)
                                                  ).ToArray();

                if (invokeMethods.Length != 1)
                {
                    throw new InvalidOperationException();
                }

                var methodInfo = invokeMethods[0];

                var parameters = methodInfo.GetParameters();
                if (parameters.Length < 1 || parameters[0].ParameterType != typeof(EventContext))
                {
                    throw new InvalidOperationException();
                }

                var ctorArgs = new object[args.Length + 1];
                ctorArgs[0] = next;
                Array.Copy(args, 0, ctorArgs, 1, args.Length);
                var instance = ActivatorUtilities.CreateInstance(applicationServices, middleware, ctorArgs);
                if (parameters.Length == 1)
                {
                    return (EventDelegate)methodInfo.CreateDelegate(typeof(EventDelegate), instance);
                }

                var factory = Compile <object>(methodInfo, parameters);

                return context =>
                {
                    var serviceProvider = context.EventServices ?? applicationServices;
                    if (serviceProvider == null)
                    {
                        throw new InvalidOperationException();
                    }

                    return factory(instance, context, serviceProvider);
                };
            }));
        }
Exemplo n.º 9
0
        /// <summary>
        /// Adds a middleware to the handler of the event with the specified <paramref name="name" />.
        /// </summary>
        /// <param name="builder">The ECS builder to add the middleware to.</param>
        /// <param name="name">The name of the event.</param>
        /// <param name="middleware">The middleware to add to the event.</param>
        /// <returns>A reference to this instance after the operation has completed.</returns>
        public static IEcsBuilder UseMiddleware(this IEcsBuilder builder, string name,
                                                Func <EventContext, Func <object>, object> middleware)
        {
            return(builder.UseMiddleware(name, next =>
            {
                return context =>
                {
                    object SimpleNext()
                    {
                        return next(context);
                    }

                    return middleware(context, SimpleNext);
                };
            }));
        }
Exemplo n.º 10
0
        /// <summary>
        /// Enables all vehicle related SA:MP events.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <returns>The builder.</returns>
        public static IEcsBuilder EnableVehicleEvents(this IEcsBuilder builder)
        {
            builder.EnableEvent <int>("OnVehicleSpawn");
            builder.EnableEvent <int, int>("OnVehicleDeath");
            builder.EnableEvent <int, int, int>("OnVehicleMod");
            builder.EnableEvent <int, int, int>("OnVehiclePaintjob");
            builder.EnableEvent <int, int, int, int>("OnVehicleRespray");
            builder.EnableEvent <int, int>("OnVehicleDamageStatusUpdate");
            builder.EnableEvent <int, int>("OnVehicleStreamIn");
            builder.EnableEvent <int, int>("OnVehicleStreamOut");
            builder.EnableEvent <int, int, int>("OnVehicleSirenStateChange");
            builder.EnableEvent <int, int>("OnTrailerUpdate");
            builder.EnableEvent <int, int, int, float, float, float, float, float, float>("OnUnoccupiedVehicleUpdate");

            builder.UseMiddleware <EntityMiddleware>("OnVehicleSpawn", 0, VehicleType, true);
            builder.UseMiddleware <EntityMiddleware>("OnVehicleDeath", 0, VehicleType, true);
            builder.UseMiddleware <EntityMiddleware>("OnVehicleDeath", 1, PlayerType, false);
            builder.UseMiddleware <EntityMiddleware>("OnVehicleMod", 0, PlayerType, true);
            builder.UseMiddleware <EntityMiddleware>("OnVehicleMod", 1, VehicleType, true);
            builder.UseMiddleware <EntityMiddleware>("OnVehiclePaintjob", 0, PlayerType, true);
            builder.UseMiddleware <EntityMiddleware>("OnVehiclePaintjob", 1, VehicleType, true);
            builder.UseMiddleware <EntityMiddleware>("OnVehicleRespray", 0, PlayerType, true);
            builder.UseMiddleware <EntityMiddleware>("OnVehicleRespray", 1, VehicleType, true);
            builder.UseMiddleware <EntityMiddleware>("OnVehicleDamageStatusUpdate", 0, VehicleType, true);
            builder.UseMiddleware <EntityMiddleware>("OnVehicleDamageStatusUpdate", 1, PlayerType, true);
            builder.UseMiddleware <EntityMiddleware>("OnVehicleStreamIn", 0, VehicleType, true);
            builder.UseMiddleware <EntityMiddleware>("OnVehicleStreamIn", 1, PlayerType, true);
            builder.UseMiddleware <EntityMiddleware>("OnVehicleStreamOut", 0, VehicleType, true);
            builder.UseMiddleware <EntityMiddleware>("OnVehicleStreamOut", 1, PlayerType, true);
            builder.UseMiddleware <EntityMiddleware>("OnVehicleSirenStateChange", 0, PlayerType, true);
            builder.UseMiddleware <EntityMiddleware>("OnVehicleSirenStateChange", 1, VehicleType, true);
            builder.UseMiddleware <EntityMiddleware>("OnTrailerUpdate", 0, PlayerType, true);
            builder.UseMiddleware <EntityMiddleware>("OnTrailerUpdate", 1, VehicleType, true);
            builder.UseMiddleware <UnoccupiedVehicleUpdateMiddleware>("OnUnoccupiedVehicleUpdate");

            return(builder);
        }
Exemplo n.º 11
0
 /// <summary>
 /// Enabled a Dependency Injection scope for the event with the specified <paramref name="name"/>.
 /// </summary>
 /// <param name="builder">The ECS builder in which to enable the scope.</param>
 /// <param name="name">The name of the event to add the scope to.</param>
 /// <returns>A reference to this instance after the operation has completed.</returns>
 public static IEcsBuilder EnableEventScope(this IEcsBuilder builder, string name)
 {
     return(builder.UseMiddleware <EventScopeMiddleware>(name));
 }
Exemplo n.º 12
0
 /// <summary>
 /// Enables handling of the callback with the specified <paramref name="name" /> as an event.
 /// </summary>
 /// <typeparam name="T1">The type of parameter 1 of the callback.</typeparam>
 /// <typeparam name="T2">The type of parameter 2 of the callback.</typeparam>
 /// <typeparam name="T3">The type of parameter 3 of the callback.</typeparam>
 /// <typeparam name="T4">The type of parameter 4 of the callback.</typeparam>
 /// <typeparam name="T5">The type of parameter 5 of the callback.</typeparam>
 /// <param name="builder">The ECS builder in which to enable the callback.</param>
 /// <param name="name">The name of the callback.</param>
 /// <returns>A reference to this instance after the operation has completed.</returns>
 public static IEcsBuilder EnableEvent <T1, T2, T3, T4, T5>(this IEcsBuilder builder, string name)
 {
     return(builder.EnableEvent(name, typeof(T1), typeof(T2), typeof(T3), typeof(T4), typeof(T5)));
 }
Exemplo n.º 13
0
 /// <summary>
 /// Enables handling of the callback with the specified <paramref name="name" /> as an event.
 /// </summary>
 /// <typeparam name="T1">The type of parameter 1 of the callback.</typeparam>
 /// <typeparam name="T2">The type of parameter 2 of the callback.</typeparam>
 /// <param name="builder">The ECS builder in which to enable the callback.</param>
 /// <param name="name">The name of the callback.</param>
 /// <returns>A reference to this instance after the operation has completed.</returns>
 public static IEcsBuilder EnableEvent <T1, T2>(this IEcsBuilder builder, string name)
 {
     return(builder.EnableEvent(name, typeof(T1), typeof(T2)));
 }
Exemplo n.º 14
0
 /// <summary>
 /// Enables handling of the callback with the specified <paramref name="name" /> as an event.
 /// </summary>
 /// <param name="builder">The ECS builder in which to enable the callback.</param>
 /// <param name="name">The name of the callback.</param>
 /// <returns>A reference to this instance after the operation has completed.</returns>
 public static IEcsBuilder EnableEvent(this IEcsBuilder builder, string name)
 {
     return(builder.EnableEvent(name));
 }
Exemplo n.º 15
0
 public void Configure(IEcsBuilder builder)
 {
     builder.EnableSampEvents()
     .EnablePlayerCommands();
 }
Exemplo n.º 16
0
        /// <summary>
        /// Enables all player related SA:MP events.
        /// </summary>
        /// <param name="builder">The builder.</param>
        /// <returns>The builder.</returns>
        public static IEcsBuilder EnablePlayerEvents(this IEcsBuilder builder)
        {
            builder.EnableEvent <int>("OnPlayerConnect");
            builder.EnableEvent <int, int>("OnPlayerDisconnect");
            builder.EnableEvent <int>("OnPlayerSpawn");
            builder.EnableEvent <int, int, int>("OnPlayerDeath");
            builder.EnableEvent <int, string>("OnPlayerText");
            builder.EnableEvent <int, string>("OnPlayerCommandText");
            builder.EnableEvent <int, int>("OnPlayerRequestClass");
            builder.EnableEvent <int, int, bool>("OnPlayerEnterVehicle");
            builder.EnableEvent <int, int>("OnPlayerExitVehicle");
            builder.EnableEvent <int, int, int>("OnPlayerStateChange");
            builder.EnableEvent <int>("OnPlayerEnterCheckpoint");
            builder.EnableEvent <int>("OnPlayerLeaveCheckpoint");
            builder.EnableEvent <int>("OnPlayerEnterRaceCheckpoint");
            builder.EnableEvent <int>("OnPlayerLeaveRaceCheckpoint");
            builder.EnableEvent <int>("OnPlayerRequestSpawn");
            builder.EnableEvent <int, int>("OnPlayerPickUpPickup");
            builder.EnableEvent <int, int>("OnPlayerSelectedMenuRow");
            builder.EnableEvent <int>("OnPlayerExitedMenu");
            builder.EnableEvent <int, int, int>("OnPlayerInteriorChange");
            builder.EnableEvent <int, int, int>("OnPlayerKeyStateChange");
            builder.EnableEvent <int>("OnPlayerUpdate");
            builder.EnableEvent <int, int>("OnPlayerStreamIn");
            builder.EnableEvent <int, int>("OnPlayerStreamOut");
            builder.EnableEvent <int, int, float, int, int>("OnPlayerTakeDamage");
            builder.EnableEvent <int, int, float, int, int>("OnPlayerGiveDamage");
            builder.EnableEvent <int, int, float, int, int>("OnPlayerGiveDamageActor");
            builder.EnableEvent <int, float, float, float>("OnPlayerClickMap");
            builder.EnableEvent <int, int>("OnPlayerClickTextDraw");
            builder.EnableEvent <int, int>("OnPlayerClickPlayerTextDraw");
            builder.EnableEvent <int, int, int>("OnPlayerClickPlayer");
            builder.EnableEvent <int, bool, int, int, float, float, float, float, float, float>("OnPlayerEditObject");
            builder.EnableEvent <int, int, int, int, int, float, float, float, float, float, float, float, float, float>(
                "OnPlayerEditAttachedObject");
            builder.EnableEvent <int, int, int, int, float, float, float>("OnPlayerSelectObject");
            builder.EnableEvent <int, int, int, int, float, float, float>("OnPlayerWeaponShot");
            builder.EnableEvent <int, bool, int>("OnEnterExitModShop");
            builder.EnableEvent <int, int, int, int, string>("OnDialogResponse");
            builder.EnableEvent <int, string, int>("OnIncomingConnection"); // Don't swap out player id

            void AddPlayerTarget(string callback)
            {
                builder.UseMiddleware <EntityMiddleware>(callback, 0, PlayerType, true);
            }

            builder.UseMiddleware <PlayerConnectMiddleware>("OnPlayerConnect");
            builder.UseMiddleware <PlayerDisconnectMiddleware>("OnPlayerDisconnect");
            AddPlayerTarget("OnPlayerSpawn");
            AddPlayerTarget("OnPlayerDeath");
            builder.UseMiddleware <EntityMiddleware>("OnPlayerDeath", 1, PlayerType, false);
            AddPlayerTarget("OnPlayerText");
            AddPlayerTarget("OnPlayerCommandText");
            AddPlayerTarget("OnPlayerRequestClass");
            AddPlayerTarget("OnPlayerEnterVehicle");
            builder.UseMiddleware <EntityMiddleware>("OnPlayerEnterVehicle", 1, VehicleType, true);
            AddPlayerTarget("OnPlayerExitVehicle");
            builder.UseMiddleware <EntityMiddleware>("OnPlayerExitVehicle", 1, VehicleType, true);
            AddPlayerTarget("OnPlayerStateChange");
            AddPlayerTarget("OnPlayerEnterCheckpoint");
            AddPlayerTarget("OnPlayerLeaveCheckpoint");
            AddPlayerTarget("OnPlayerEnterRaceCheckpoint");
            AddPlayerTarget("OnPlayerLeaveRaceCheckpoint");
            AddPlayerTarget("OnPlayerRequestSpawn");
            AddPlayerTarget("OnPlayerPickUpPickup");
            builder.UseMiddleware <EntityMiddleware>("OnPlayerPickUpPickup", 1, SampEntities.PickupType, true);
            AddPlayerTarget("OnPlayerSelectedMenuRow");
            AddPlayerTarget("OnPlayerExitedMenu");
            AddPlayerTarget("OnPlayerInteriorChange");
            AddPlayerTarget("OnPlayerKeyStateChange");
            AddPlayerTarget("OnPlayerUpdate");
            AddPlayerTarget("OnPlayerStreamIn");
            builder.UseMiddleware <EntityMiddleware>("OnPlayerStreamIn", 1, PlayerType, true);
            AddPlayerTarget("OnPlayerStreamOut");
            builder.UseMiddleware <EntityMiddleware>("OnPlayerStreamOut", 1, PlayerType, true);
            AddPlayerTarget("OnPlayerTakeDamage");
            builder.UseMiddleware <EntityMiddleware>("OnPlayerTakeDamage", 1, PlayerType, false);
            AddPlayerTarget("OnPlayerGiveDamage");
            builder.UseMiddleware <EntityMiddleware>("OnPlayerGiveDamage", 1, PlayerType, true);
            AddPlayerTarget("OnPlayerGiveDamageActor");
            builder.UseMiddleware <EntityMiddleware>("OnPlayerGiveDamageActor", 1, ActorType, true);
            builder.UseMiddleware <PlayerClickMapMiddleware>("OnPlayerClickMap");
            builder.UseMiddleware <TextDrawClickMiddleware>("OnPlayerClickTextDraw");
            builder.UseMiddleware <PlayerTextDrawMiddleware>("OnPlayerClickPlayerTextDraw");
            AddPlayerTarget("OnPlayerClickPlayer");
            builder.UseMiddleware <EntityMiddleware>("OnPlayerClickPlayer", 1, PlayerType, true);
            builder.UseMiddleware <PlayerEditObjectMiddleware>("OnPlayerEditObject");
            builder.UseMiddleware <PlayerEditAttachedObjectMiddleware>("OnPlayerEditAttachedObject");
            builder.UseMiddleware <PlayerSelectObjectMiddleware>("OnPlayerSelectObject");
            builder.UseMiddleware <PlayerWeaponShotMiddleware>("OnPlayerWeaponShot");
            AddPlayerTarget("OnEnterExitModShop");
            AddPlayerTarget("OnDialogResponse");

            return(builder);
        }
Exemplo n.º 17
0
 /// <summary>
 /// Adds a middleware of the specified type <typeparamref name="TMiddleware" /> to the handler of the event with the
 /// specified <paramref name="name" />.
 /// </summary>
 /// <typeparam name="TMiddleware">The type of the middleware.</typeparam>
 /// <param name="builder">The ECS builder to add the middleware to.</param>
 /// <param name="name">The name of the event.</param>
 /// <param name="args">The arguments for the constructor of the event.</param>
 /// <returns>A reference to this instance after the operation has completed.</returns>
 public static IEcsBuilder UseMiddleware <TMiddleware>(this IEcsBuilder builder, string name,
                                                       params object[] args)
 {
     return(builder.UseMiddleware(name, typeof(TMiddleware), args));
 }
Exemplo n.º 18
0
 /// <summary>
 /// Enables player commands.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>The builder.</returns>
 public static IEcsBuilder EnablePlayerCommands(this IEcsBuilder builder)
 {
     return(builder.UseMiddleware <PlayerCommandProcessingMiddleware>("OnPlayerCommandText"));
 }
Exemplo n.º 19
0
 /// <summary>
 /// Enables RCON commands.
 /// </summary>
 /// <param name="builder">The builder.</param>
 /// <returns>The builder.</returns>
 public static IEcsBuilder EnableRconCommands(this IEcsBuilder builder)
 {
     return(builder.UseMiddleware <RconCommandProcessingMiddleware>("OnRconCommand"));
 }