示例#1
0
        public ClientList(ILogger logger, ICommunicationManager comms)
        {
            this.logger = logger;

            comms.Event(SessionEvents.ClientInitialized).FromServer().On <IClient, Session>(OnInitialized);
            comms.Event(SessionEvents.ClientDisconnected).FromServer().On <IClient, Session>(OnDisconnected);
        }
示例#2
0
        private void MessageEntered(ICommunicationMessage e, string message)
        {
            // Check if message is a command
            if (string.IsNullOrWhiteSpace(this.Configuration.CommandPrefix) || message.Trim().StartsWith(this.Configuration.CommandPrefix))
            {
                // Split message by space, respecting double quotes
                var args = message.Trim().Substring(this.Configuration.CommandPrefix.Length).SplitArguments().ToList();

                // Dispatch command to sender
                _comms.Event(CoreEvents.CommandDispatch).ToClient(e.Client).Emit(args);
            }
            else
            {
                // Un-prefixed message, send to everyone
                _comms.Event(ChatEvents.ChatMessage)
                .ToClients()
                .Emit(new ChatMessage
                {
                    Sender   = e.User,
                    Style    = this.Configuration.DefaultStyle.ToString("G").ToLowerInvariant(),
                    Template = "default",
                    Values   = new[]
                    {
                        e.User.Name,
                        message
                    }
                });
            }
        }
示例#3
0
        public ChatController(ILogger logger, Configuration configuration, ICommunicationManager comms) : base(logger, configuration)
        {
            this._comms = comms;

            // Send configuration when requested
            comms.Event(ChatEvents.Configuration).FromClients().OnRequest(e => e.Reply(this.Configuration));

            // Listen to new client messages
            comms.Event(ChatEvents.MessageEntered).FromClients().On <string>(MessageEntered);
        }
示例#4
0
        public MarkersController(ILogger logger, Configuration configuration, ICommunicationManager comms, MarkersManager markerManager) : base(logger, configuration)
        {
            this.comms         = comms;
            this.markerManager = markerManager;

            // Send configuration when requested
            comms.Event(MarkersEvents.Configuration).FromClients().OnRequest(e => e.Reply(this.Configuration));

            comms.Event(MarkersEvents.GetAllMarkers).FromClients().OnRequest(GetAllMarkersEvent);
            if (this.Configuration.editMode)
            {
                comms.Event(MarkersEvents.AddMarker).FromClients().OnRequest <Marker>(AddMarkerEvent);
                comms.Event(MarkersEvents.RemoveMarker).FromClients().OnRequest <Guid>(RemoveMarkerEvent);
            }
        }
示例#5
0
        public DatabaseController(ILogger logger, DatabaseConfiguration configuration, ICommunicationManager comms) : base(logger, 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);

            comms.Event(BootEvents.GetTime).FromServer().On(e => e.Reply(this.currentBoot.Created));
            comms.Event(BootEvents.GetLastTime).FromServer().On(e => e.Reply(lastBoot.Created));
            comms.Event(BootEvents.GetLastActiveTime).FromServer().On(e => e.Reply(lastBoot.LastActive));
        }
        public NFundamentalsCharactersController(ILogger logger, CharactersConfiguration config, ICommunicationManager comms) : base(logger, config)
        {
            this.comms = comms;
            // Send configuration when requested
            comms.Event(CharacterEvents.Configuration).FromClients().OnRequest(e => e.Reply(this.Configuration));

            // Character events
            comms.Event(CharacterEvents.GetAllForUser).FromClients().OnRequest(GetAllCharactersForUser);
            comms.Event(CharacterEvents.Create).FromClients().OnRequest <Character>(CreateCharacter);
            comms.Event(CharacterEvents.Delete).FromClients().OnRequest <Guid>(DeleteCharacter);
            comms.Event(CharacterEvents.Select).FromClients().OnRequest <Guid>(SelectCharacter);
            comms.Event(CharacterEvents.SaveCharacter).FromClients().On <Character>(SaveCharacter);
            comms.Event(CharacterEvents.SavePosition).FromClients().On <Guid, Position>(SaveCharacterPosition);
            comms.Event(CharacterEvents.GetById).FromClients().OnRequest <Guid>(GetCharacterById);

            // Get all active character sessions
            comms.Event(CharacterEvents.GetActiveSessions).FromServer().OnRequest(e => e.Reply(this.CharacterSessions));

            // SessionManager plugin event when a client disconnects
            comms.Event(SessionEvents.DisconnectPlayer).FromServer().On <IClient, Session>(OnPlayerDisconnected);
        }
示例#7
0
 public DiscordController(ILogger logger, Configuration configuration, ICommunicationManager comms) : base(logger, configuration)
 {
     comms.Event(DiscordEvents.Configuration).FromClients().OnRequest(e => e.Reply(this.Configuration));
 }
示例#8
0
 public IPLLoaderController(ILogger logger, Configuration configuration, ICommunicationManager comms) : base(logger, configuration)
 {
     // Send configuration when requested
     comms.Event(IPLLoaderEvents.Configuration).FromClients().OnRequest(e => e.Reply(this.Configuration));
 }
示例#9
0
 public CommandManager(ICommunicationManager comms)
 {
     comms.Event(CoreEvents.CommandDispatch).FromServer().On <List <string> >(OnCommandDispatch);
 }
 public IdentityManagerController(ILogger logger, ICommunicationManager comms) : base(logger)
 {
     comms.Event(IdentityManagerEvents.Identity).FromClients().OnRequest(e => e.Reply(GetIdentity(e)));
 }
示例#11
0
 public RconManager(ICommunicationManager comms)
 {
     comms.Event(ServerEvents.RconCommand).FromServer().On <string, string[]>(OnCommand);
 }