Example #1
0
 protected void RpcCommandRun()
 {
     while (true)
     {
         try {
             object[]    data       = (object[])_rpc_command.Dequeue();
             IRpcHandler handler    = (IRpcHandler)data[0];
             ISender     ret_path   = (ISender)data[1];
             string      methname   = (string)data[2];
             IList       param_list = (IList)data[3];
             handler.HandleRpc(ret_path, methname, param_list, ret_path);
         }
         catch (Exception x) {
             Console.Error.WriteLine("Exception in RpcCommandRun: {0}", x);
         }
     }
 }
Example #2
0
        public LoginController(ILogger logger, IEventManager events, IRpcHandler rpc, IRconManager rcon, Configuration configuration) : base(logger, events, rpc, rcon, configuration)
        {
            this.bcrypt = new BCryptHelper(this.Configuration.GlobalSalt, this.Configuration.BcryptCost);

            // Send configuration when requested
            this.Rpc.Event(LoginEvents.Configuration).On(e => e.Reply(new PublicConfiguration(this.Configuration)));

            this.Rpc.Event(LoginEvents.Register).On <Credentials>(OnRegistrationRequested);
            this.Rpc.Event(LoginEvents.Login).On <Credentials>(OnLoginRequested);
            this.Rpc.Event(LoginEvents.AuthenticationStarted).On(OnAuthenticationStarted);

            this.Events.OnRequest(LoginEvents.GetCurrentAccounts, () => this.loggedInAccounts);

            // Listen for NFive session events
            this.sessions = new SessionManager(this.Events, this.Rpc);
            this.sessions.ClientDisconnected += OnClientDisconnected;
        }
Example #3
0
        public SessionController(ILogger logger, IEventManager events, IRpcHandler rpc, IRconManager rcon, SessionConfiguration configuration) : base(logger, events, rpc, rcon, configuration)
        {
            API.EnableEnhancedHostSupport(true);

            this.Events.On(ServerEvents.ServerInitialized, OnSeverInitialized);

            this.Rpc.Event("hostingSession").OnRaw(new Action <Player>(OnHostingSession));
            this.Rpc.Event("HostedSession").OnRaw(new Action <Player>(OnHostedSession));
            this.Rpc.Event("playerConnecting").OnRaw(new Action <Player, string, CallbackDelegate, ExpandoObject>(Connecting));
            this.Rpc.Event("playerDropped").OnRaw(new Action <Player, string, CallbackDelegate>(Dropped));

            this.Rpc.Event(RpcEvents.ClientInitialize).On <string>(Initialize);
            this.Rpc.Event(RpcEvents.ClientInitialized).On(Initialized);
            this.Rpc.Event(SessionEvents.DisconnectPlayer).On <string>(Disconnect);

            this.Events.OnRequest(SessionEvents.GetMaxPlayers, () => this.Configuration.MaxClients);
            this.Events.OnRequest(SessionEvents.GetCurrentSessionsCount, () => this.sessions.Count);
            this.Events.OnRequest(SessionEvents.GetCurrentSessions, () => this.sessions.ToList());
        }
Example #4
0
        public CharactersController(ILogger logger, IEventManager events, IRpcHandler rpc, IRconManager rcon, Configuration configuration) : base(logger, events, rpc, rcon, configuration)
        {
            // Send configuration when requested
            this.Rpc.Event(CharacterEvents.Configuration).On(e => e.Reply(this.Configuration));
            this.Rpc.Event(CharacterEvents.Load).On(Load);
            this.Rpc.Event(CharacterEvents.Create).On <Character>(Create);
            this.Rpc.Event(CharacterEvents.Delete).On <Guid>(Delete);
            this.Rpc.Event(CharacterEvents.Select).On <Guid>(Select);
            this.Rpc.Event(CharacterEvents.SaveCharacter).On <Character>(SaveCharacter);
            this.Rpc.Event(CharacterEvents.SavePosition).On <Guid, Position>(SavePosition);

            this.Events.OnRequest(CharacterEvents.GetActive, () => this.characterSessions);

            // Listen for NFive SessionManager plugin events
            this.sessions = new SessionManager(this.Events, this.Rpc);
            this.sessions.ClientDisconnected += OnClientDisconnected;

            Cleanup();
        }
Example #5
0
        public DatabaseController(ILogger logger, IEventManager events, IRpcHandler rpc, IRconManager rcon, DatabaseConfiguration configuration) : base(logger, events, rpc, rcon, configuration)
        {
            // Set global database options
            ServerConfiguration.DatabaseConnection  = this.Configuration.Connection.ToString();
            ServerConfiguration.AutomaticMigrations = this.Configuration.Migrations.Automatic;

            // Enable SQL query logging
            MySqlTrace.Switch.Level = SourceLevels.All;
            MySqlTrace.Listeners.Add(new ConsoleTraceListener());

            BootHistory lastBoot;

            using (var context = new StorageContext())
            {
                // Create database if needed
                if (!context.Database.Exists())
                {
                    this.Logger.Info($"No existing database found, creating new database \"{this.Configuration.Connection.Database}\"");
                }

                var migrator = new DbMigrator(new Migrations.Configuration());
                foreach (var migration in migrator.GetPendingMigrations())
                {
                    this.Logger.Debug($"Running migration: {migration}");

                    migrator.Update(migration);
                }

                lastBoot = context.BootHistory.OrderByDescending(b => b.Created).FirstOrDefault() ?? new BootHistory();

                this.currentBoot = new BootHistory();
                context.BootHistory.Add(this.currentBoot);
                context.SaveChanges();
            }

            Task.Factory.StartNew(UpdateBootHistory);

            this.Events.OnRequest(BootEvents.GetTime, () => this.currentBoot.Created);
            this.Events.OnRequest(BootEvents.GetLastTime, () => lastBoot.Created);
            this.Events.OnRequest(BootEvents.GetLastActiveTime, () => lastBoot.LastActive);
        }
Example #6
0
        public LoginController(ILogger logger, IEventManager events, IRpcHandler rpc, IRconManager rcon, Configuration configuration) : base(logger, events, rpc, rcon, configuration)
        {
            this.BCryptHelper = new BCryptHelper(this.Configuration.GlobalSalt, this.Configuration.BCryptCost);

            this.LoginAttempts    = new Dictionary <int, int>();
            this.LoggedInAccounts = new List <Account>();

            // Send configuration when requested
            this.Rpc.Event(LoginEvents.Configuration).On(e => e.Reply(new PublicConfiguration(this.Configuration)));

            this.Rpc.Event(LoginEvents.Register).On <string, string>(OnRegistrationRequested);
            this.Rpc.Event(LoginEvents.Login).On <string, string>(OnLoginRequested);
            this.Rpc.Event(LoginEvents.AuthenticationStarted).On(OnAuthenticationStarted);

            this.Events.OnRequest(LoginEvents.GetCurrentAccountsCount, () => this.LoggedInAccounts.Count);
            this.Events.OnRequest(LoginEvents.GetCurrentAccounts, () => this.LoggedInAccounts);

            // Listen for NFive SessionManager plugin events
            var sessions = new SessionManager.Server.SessionManager(this.Events, this.Rpc);

            sessions.ClientDisconnected += OnClientDisconnected;
        }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="SessionManager"/> class.
        /// </summary>
        /// <param name="events">The controller event manager.</param>
        /// <param name="rpc">The controller RPC handler.</param>
        public SessionManager(IEventManager events, IRpcHandler rpc)
        {
            this.Events = events;
            this.Rpc    = rpc;

            this.Events.On <IClient, Deferrals>(SessionEvents.ClientConnecting, (c, d) => this.ClientConnecting?.Invoke(this, new ClientDeferralsEventArgs(c, d)));
            this.Events.On <IClient>(SessionEvents.UserCreating, c => this.UserCreating?.Invoke(this, new ClientEventArgs(c)));
            this.Events.On <IClient, User>(SessionEvents.UserCreated, (c, u) => this.UserCreated?.Invoke(this, new ClientUserEventArgs(c, u)));
            this.Events.On <IClient>(SessionEvents.SessionCreating, c => this.SessionCreating?.Invoke(this, new ClientEventArgs(c)));
            this.Events.On <IClient, Session, Deferrals>(SessionEvents.SessionCreated, (c, s, d) => this.SessionCreated?.Invoke(this, new ClientSessionDeferralsEventArgs(c, s, d)));
            this.Events.On <IClient, Session>(SessionEvents.ClientConnected, (c, s) => this.ClientConnected?.Invoke(this, new ClientSessionEventArgs(c, s)));

            this.Events.On <IClient, Session, Session>(SessionEvents.ClientReconnecting, (c, o, n) => this.ClientReconnecting?.Invoke(this, new ClientReconnectEventArgs(c, o, n)));
            this.Events.On <IClient, Session, Session>(SessionEvents.ClientReconnected, (c, o, n) => this.ClientReconnected?.Invoke(this, new ClientReconnectEventArgs(c, o, n)));

            this.Events.On <IClient>(SessionEvents.ClientDisconnecting, c => this.ClientDisconnecting?.Invoke(this, new ClientEventArgs(c)));
            this.Events.On <IClient, Session>(SessionEvents.ClientDisconnected, (c, s) => this.ClientDisconnected?.Invoke(this, new ClientSessionEventArgs(c, s)));

            this.Events.On <IClient>(SessionEvents.ClientInitializing, c => this.ClientInitializing?.Invoke(this, new ClientEventArgs(c)));
            this.Events.On <IClient, Session>(SessionEvents.ClientInitialized, (c, s) => this.ClientInitialized?.Invoke(this, new ClientSessionEventArgs(c, s)));

            this.Events.On <IClient, Session>(SessionEvents.SessionTimedOut, (c, s) => this.SessionTimedOut?.Invoke(this, new ClientSessionEventArgs(c, s)));
        }
Example #8
0
        public GateGuardController(ILogger logger, IEventManager events, IRpcHandler rpc, IRconManager rcon, Configuration configuration) : base(logger, events, rpc, rcon, configuration)
        {
            this.Logger.Info($"Running in {this.Configuration.Mode.ToString().ToLower()} mode");
            this.Logger.Info($"Database update interval: Every {this.Configuration.Database.ReloadInterval.ToFriendly()}");

            this.Rpc.Event(GateGuardEvents.RuleCreate).On <Guid, GateGuard.AccessRule, string, DateTime?>(OnRuleCreate);
            this.Rpc.Event(GateGuardEvents.RuleDelete).On <Guid>(OnRuleDelete);

            // Listen for NFive SessionManager plugin events
            var sessions = new SessionManager.Server.SessionManager(this.Events, this.Rpc);

            sessions.SessionCreated += OnSessionCreated;

            // ReSharper disable once FunctionNeverReturns
            Task.Factory.StartNew(async() =>
            {
                while (true)
                {
                    Load();

                    await Task.Delay(this.Configuration.Database.ReloadInterval);
                }
            });
        }
Example #9
0
 public RconManager(IRpcHandler rpc)
 {
     rpc.Event("rconCommand").OnRaw(new Action <string, List <object> >(Handle));
 }
Example #10
0
 public SessionController(ILogger logger, IEventManager events, IRpcHandler rpc, IRconManager rcon, SessionConfiguration configuration) : base(logger, events, rpc, rcon, configuration)
 {
 }
Example #11
0
 /// <inheritdoc />
 public StreetPositionController(ILogger logger, IEventManager events, IRpcHandler rpc, IRconManager rcon, Configuration configuration) : base(logger, events, rpc, rcon, configuration)
 {
     this.Rpc.Event(StreetPositionEvents.GetConfig).On(e => e.Reply(this.Configuration));
 }
Example #12
0
 public PluginAdminService(ILogger logger, ITickManager ticks, IEventManager events, IRpcHandler rpc, ICommandManager commands, OverlayManager overlay, User user) : base(logger, ticks, events, rpc, commands, overlay, user)
 {
     this.Commands.Register("car", new Action <string>(Car));
     this.Commands.Register("dv", new Action(Dv));
     this.Commands.Register("noclip", new Action(ToggleNoclip));
 }
 public InventoryController(ILogger logger, IEventManager events, IRpcHandler rpc, IRconManager rcon, Configuration configuration) : base(logger, events, rpc, rcon, configuration)
 {
     // Send configuration when requested
     this.Rpc.Event(InventoryEvents.Configuration).On(e => e.Reply(this.Configuration));
 }
Example #14
0
        /**
         * When requests come in this handles it
         */
        public void HandleData(MemBlock payload, ISender ret_path, object state)
        {
            Exception exception = null;

#if RPC_DEBUG
            Console.Error.WriteLine("[RpcServer: {0}] Getting method invocation request at: {1}.",
                                    _rrman.Info, DateTime.Now);
#endif
            try {
                object data = AdrConverter.Deserialize(payload);
                IList  l    = data as IList;

                if (l == null)
                {
                    //We could not cast the request into a list... so sad:
                    throw new AdrException(-32600, "method call not a list");
                }

                string methname = (string)l[0];
#if RPC_DEBUG
                Console.Error.WriteLine("[RpcServer: {0}] Getting invocation request,  method: {1}",
                                        _rrman.Info, methname);
#endif

                /*
                 * Lookup this method name in our table.
                 * This uses a cache, so it should be fast
                 * after the first time
                 */
                IRpcHandler handler = null;
                string      mname   = null;
                lock ( _sync ) {
                    object[] info = (object[])_method_cache[methname];
                    if (info == null)
                    {
                        int dot_idx = methname.IndexOf('.');
                        if (dot_idx == -1)
                        {
                            throw new AdrException(-32601, "No Handler for method: " + methname);
                        }
                        string hname = methname.Substring(0, dot_idx);
                        //Skip the '.':
                        mname = methname.Substring(dot_idx + 1);

                        handler = (IRpcHandler)_method_handlers[hname];
                        if (handler == null)
                        {
                            //No handler for this.
                            throw new AdrException(-32601, "No Handler for method: " + methname);
                        }
                        info    = new object[2];
                        info[0] = handler;
                        info[1] = mname;
                        _method_cache[methname] = info;
                    }
                    else
                    {
                        handler = (IRpcHandler)info[0];
                        mname   = (string)info[1];
                    }
                }

                ArrayList pa = (ArrayList)l[1];
#if DAVID_ASYNC_INVOKE
                object[] odata = new object[4];
                odata[0] = handler;
                odata[1] = ret_path;
                odata[2] = mname;
                odata[3] = pa;
                _rpc_command.Enqueue(odata);
#else
                handler.HandleRpc(ret_path, mname, pa, ret_path);
#endif
            }
            catch (ArgumentException argx) {
                exception = new AdrException(-32602, argx);
            }
            catch (TargetParameterCountException argx) {
                exception = new AdrException(-32602, argx);
            }
            catch (Exception x) {
                exception = x;
            }
            if (exception != null)
            {
                //something failed even before invocation began
#if RPC_DEBUG
                Console.Error.WriteLine("[RpcServer: {0}] Something failed even before invocation began: {1}",
                                        _rrman.Info, exception);
#endif
                using (MemoryStream ms = new MemoryStream()) {
                    AdrConverter.Serialize(exception, ms);
                    ret_path.Send(new CopyList(PType.Protocol.Rpc, MemBlock.Reference(ms.ToArray())));
                }
            }
        }
Example #15
0
 public CommandManager(IRpcHandler rpc)
 {
     rpc.Event(RpcEvents.ChatSendMessage).On <ChatMessage>(Handle);
 }
 public MetricsService(ILogger logger, ITickManager ticks, IEventManager events, IRpcHandler rpc, ICommandManager commands, OverlayManager overlay, User user) : base(logger, ticks, events, rpc, commands, overlay, user)
 {
     this.Rpc.Event("metric").On(new Action <IRpcEvent, object>((e, data) => this.Rpc.Event("metric").Trigger(data)));
 }
Example #17
0
 public VehiclesService(ILogger logger, ITickManager ticks, IEventManager events, IRpcHandler rpc,
                        ICommandManager commands, OverlayManager overlay, User user) : base(logger, ticks, events, rpc, commands,
                                                                                            overlay, user)
 {
 }
 /// <inheritdoc />
 /// <summary>
 /// Initializes a new instance of the <see cref="ConfigurableController{T}"/> class.
 /// </summary>
 /// <param name="logger">The message logger.</param>
 /// <param name="events">The server event manager.</param>
 /// <param name="rpc">The RPC handler.</param>
 /// <param name="rcon">The RCON handler.</param>
 /// <param name="configuration">The configuration loaded from file.</param>
 protected ConfigurableController(ILogger logger, IEventManager events, IRpcHandler rpc, IRconManager rcon, T configuration) : base(logger, events, rpc, rcon)
 {
     this.Configuration = configuration;
 }
Example #19
0
 public QueueController(ILogger logger, IEventManager events, IRpcHandler rpc, IRconManager rcon, Configuration configuration) : base(logger, events, rpc, rcon, configuration) => Startup();
Example #20
0
 public RpcRequest(string @event, IRpcHandler handler, IRpcTrigger trigger, IRpcSerializer serializer) : base(@event, handler, trigger, serializer)
 {
 }
Example #21
0
 public DebugController(ILogger logger, IEventManager events, IRpcHandler rpc, IRconManager rcon, Configuration configuration) : base(logger, events, rpc, rcon, configuration)
 {
     this.Rpc.Event(DebugEvents.Configuration).On(e => e.Reply(this.Configuration));
 }
Example #22
0
 public GameController(ILogger logger, IEventManager events, IRpcHandler rpc) : base(logger, events, rpc)
 {
 }
 public static IDisposable ReceiveRpcRequest <T>(this IBusConnection connection, IRpcHandler <T> handler)
 {
     return(connection.ReceiveRpcRequest <T>(handler.HandleAsync));
 }