Ejemplo n.º 1
0
        /// <summary>
        /// Stop the server manager system.
        /// </summary>
        public override void Stop()
        {
            SystemHost.UpdateSystemHost(this, "Stopping server...");
            server.Stop();

            SystemHost.UpdateSystemHost(this, "Stopped");
        }
Ejemplo n.º 2
0
        /// <summary>Starts the manager and loads all help records into memory</summary>
        public override void Start()
        {
            SystemHost.UpdateSystemHost(this, "Starting...");

            string dataRoot = GameConfiguration.DataStoragePath;
            string helpDir  = Path.Combine(dataRoot, "Help");

            if (!Directory.Exists(helpDir))
            {
                Directory.CreateDirectory(helpDir);
            }

            foreach (string file in Directory.GetFiles(helpDir))
            {
                // We need to read in each line of the file and put it back together explicitly with AnsiSequences.NewLines,
                // so that we are prepared to send the contents with the expected NewLine of the Telnet protocal, regardless
                // of what line endings the help file was saved with.
                var    contentLines = File.ReadAllLines(file);
                string contents     = string.Join(AnsiSequences.NewLine, contentLines);

                // The file name depicts the help topic. Something like "foo_bar" would be a single keyword with an underscore
                // as part of the help topic alias, while "foo__bar" depicts two aliases ("foo" and "bar").
                string   nameOnly  = Path.GetFileNameWithoutExtension(file);
                string[] aliases   = nameOnly.Split("__");
                var      helpTopic = new HelpTopic(contents, new List <string>(aliases));
                HelpTopics.Add(helpTopic);
            }

            SystemHost.UpdateSystemHost(this, "Started");
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Start the Session manager system.
        /// </summary>
        public override void Start()
        {
            SystemHost.UpdateSystemHost(this, "Starting...");

            // Do anything extra here.

            SystemHost.UpdateSystemHost(this, "Started");
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Stopo the command system.
        /// </summary>
        public override void Stop()
        {
            SystemHost.UpdateSystemHost(this, "Stopping...");

            Dictionary.Clear();

            SystemHost.UpdateSystemHost(this, "Stopped");
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Start the server manager system.
        /// </summary>
        public override void Start()
        {
            SystemHost.UpdateSystemHost(this, "Starting TCP Server...");
            server.SubscribeToSystem(this);
            server.Start();

            SystemHost.UpdateSystemHost(this, "Server started on port " + server.Port);
            UpTime = DateTime.Now;
        }
Ejemplo n.º 6
0
        /// <summary>Stops this system's individual components.</summary>
        public override void Stop()
        {
            SystemHost.UpdateSystemHost(this, "Stopping...");

            telnetServer.Stop();
            baseServer.Stop();

            SystemHost.UpdateSystemHost(this, "Stopped");
        }
Ejemplo n.º 7
0
 /// <summary>Starts this system's individual components.</summary>
 public override void Start()
 {
     SystemHost.UpdateSystemHost(this, "Starting...");
     baseServer.SubscribeToSystem(this);
     baseServer.Start();
     telnetServer.Start();
     SystemHost.UpdateSystemHost(this, "Started on port " + baseServer.Port);
     StartTime = DateTime.Now;
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Start the Room system.
        /// </summary>
        public override void Start()
        {
            SystemHost.UpdateSystemHost(this, "Starting...");
            RoomList.Add("main", new DefaultRoom());
            var num = LoadUserOwnedRooms();

            SystemHost.UpdateSystemHost(this, $"Loaded {num} user owned rooms");
            SystemHost.UpdateSystemHost(this, "Started");
        }
Ejemplo n.º 9
0
        /// <summary>Stops the time system.</summary>
        public override void Stop()
        {
            SystemHost.UpdateSystemHost(this, "Stopping...");

            timer.Change(Timeout.Infinite, Timeout.Infinite);
            timer.Dispose();

            SystemHost.UpdateSystemHost(this, "Stopped");
        }
Ejemplo n.º 10
0
        /// <summary>Called upon session authentication.</summary>
        /// <param name="session">The authenticated session.</param>
        public void OnSessionAuthenticated(Session session)
        {
            session.ActionReceived += Controller_ActionReceived;

            SystemHost.UpdateSystemHost(this, session.ID + " - Session Authenticated");

            // Tell the player manager about the new authenticated session.
            PlayerManager.Instance.OnSessionAuthenticated(session);
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Start the data manager system. Selects the storage provider to use
        /// </summary>
        public override void Start()
        {
            SystemHost.UpdateSystemHost(this, "Starting...");
            string bootmsg = string.Format("Using  Storage Provider: {0}", configuredStorageProvider.Name);

            SystemHost.UpdateSystemHost(this, bootmsg);
            configuredStorageProvider.Prepare();
            SystemHost.UpdateSystemHost(this, "Started");
        }
Ejemplo n.º 12
0
        /// <summary>Stops this system's individual components.</summary>
        public override void Stop()
        {
            SystemHost.UpdateSystemHost(this, "Stopping...");

            lock (lockObject)
            {
                mobiles.Clear();
            }

            SystemHost.UpdateSystemHost(this, "Stopped");
        }
Ejemplo n.º 13
0
        /// <summary>Start the time system.</summary>
        public override void Start()
        {
            SystemHost.UpdateSystemHost(this, "Starting...");

            if (timer == null)
            {
                timer = new Timer(DoCallbacks, null, interval, interval);
            }

            SystemHost.UpdateSystemHost(this, "Started");
        }
Ejemplo n.º 14
0
        /// <summary>Stops this system's individual components.</summary>
        public override void Stop()
        {
            SystemHost.UpdateSystemHost(this, "Stopping...");

            lock (Sessions)
            {
                Sessions.Clear();
            }

            SystemHost.UpdateSystemHost(this, "Stopped");
        }
Ejemplo n.º 15
0
        /// <summary>Stops this system's individual components.</summary>
        public override void Stop()
        {
            SystemHost.UpdateSystemHost(this, "Stopping...");

            lock (playersList)
            {
                playersList.Clear();
            }

            SystemHost.UpdateSystemHost(this, "Stopped.");
        }
Ejemplo n.º 16
0
        /// <summary>Called upon authentication of a session.</summary>
        /// <param name="session">The authenticated session.</param>
        public void OnSessionAuthenticated(Session session)
        {
            // If there was already a connected player for this new, authentic user session, kick the old
            // one (as it may have been a prior disconnect or whatnot or even a different player character
            // controlled by the same user account).
            // TODO: We can probably handle this more gracefully (without the extra logouts and messaging
            //       the room about it and so on) by having the login process notice the target player is
            //       already in the world sooner, and more directly taking fresh control of THAT Thing.
            PlayerBehavior previousPlayer = FindLoggedInPlayer(session.User.UserName);

            if (previousPlayer != null)
            {
                var msg = $"Duplicate player match, replacing session {previousPlayer.SessionId} with new session {session.ID}";
                SystemHost.UpdateSystemHost(this, msg);

                var previousUser = previousPlayer.Parent.FindBehavior <UserControlledBehavior>();
                Debug.Assert(previousUser != null, "Existing Player found must always also be a UserControlled Thing.");
                previousUser.Disconnect("Another connection has logged in as you; closing this connection.");

                previousUser.Session     = session;
                previousPlayer.SessionId = session.ID;
                session.Thing            = previousPlayer.Parent;
            }
            else
            {
                // Track this new player in the loaded players list.
                AddPlayer(session.Thing);
            }

            // A freshly (re)connected player is assumed not to be AFK anymore.
            PlayerBehavior playerBehavior = session.Thing.FindBehavior <PlayerBehavior>();

            if (playerBehavior != null)
            {
                playerBehavior.IsAFK     = false;
                playerBehavior.AFKReason = null;
            }

            // If this session doesn't have a player thing attached yet, load it up.  Note that
            // for situations like character creation, we might already have our Thing, so we
            // don't want to load a duplicate version of the just-created player Thing.
            if (session.Thing == null)
            {
                var output = new OutputBuilder();
                output.AppendLine("User was authenticated but the player character could not be loaded.");
                output.AppendLine("Please contact an administrator. Disconnecting.");
                session.Write(output);
                session.Connection.Disconnect();
            }

            // TODO: Perhaps reset player command queue to have exactly one "look" command?
        }
Ejemplo n.º 17
0
 /// <summary>
 /// Stop the Room system.
 /// </summary>
 public override void Stop()
 {
     SystemHost.UpdateSystemHost(this, "Stopping...");
     foreach (IRoom r in RoomList.Values)
     {
         if (r.GetType().Equals(typeof(UserOwnedRoom)))
         {
             Room.manager.Save(((UserOwnedRoom)r).Data);
         }
     }
     RoomList.Clear();
     SystemHost.UpdateSystemHost(this, "Stopped");
 }
Ejemplo n.º 18
0
        /// <summary>Stops this system.</summary>
        public override void Stop()
        {
            SystemHost.UpdateSystemHost(this, "Stopping...");

            foreach (var commandProcessor in commandProcessors)
            {
                commandProcessor.Stop();
            }

            commandProcessors.Clear();

            SystemHost.UpdateSystemHost(this, "Stopped");
        }
Ejemplo n.º 19
0
        /// <summary>Starts the manager and loads all help records into memory</summary>
        public override void Start()
        {
            SystemHost.UpdateSystemHost(this, "Starting...");

            string dataRoot = GameConfiguration.DataStoragePath;
            string helpDir  = Path.Combine(dataRoot, "Help");

            if (!Directory.Exists(helpDir))
            {
                Directory.CreateDirectory(helpDir);
            }

            ReloadHelpTopics(helpDir);

            SystemHost.UpdateSystemHost(this, "Started");
        }
Ejemplo n.º 20
0
 /// <summary>
 /// Forward a message from the session to the proper room.
 /// </summary>
 /// <param name="session"></param>
 /// <param name="message"></param>
 public void ProcessMessage(Session session, string message)
 {
     if (SessionLocations.ContainsKey(session.ID))
     {
         if (session.User != null && message.StartsWith(CommandManager.Instance.Trigger))
         {
             CommandManager.Instance.ProcessCommand(session, message.Substring(1));
         }
         else
         {
             var room = GetRoomContainingSession(session);
             var send = $"{session.User.Username}: {message}";
             room.Send(send + Environment.NewLine);
             SystemHost.UpdateSystemHost(this, $"[{room.Name}] {send}");
         }
     }
 }
Ejemplo n.º 21
0
        /// <summary>Starts this system.</summary>
        public override void Start()
        {
            SystemHost.UpdateSystemHost(this, "Starting...");

            ////temp. Add a mobile explicitly here.
            ////TODO: replace with proper persistence mechanism
            ////var basicGuardMobBrain = new BasicGuardMobBrain();
            ////var mobile = new Mobile(basicGuardMobBrain, CoreManager.Instance.PlacesManager.World);
            ////mobile.ActionReceived += mobile_ActionReceived;
            ////basicGuardMobBrain.Entity = mobile;
            ////mobile.Name = "George";
            ////Room room = CoreManager.Instance.PlacesManager.World.FindRoom("1");
            ////mobile.Move(room);
            ////basicGuardMobBrain.Start();
            ////_mobiles.Add(mobile);
            ////mobile.Load();

            SystemHost.UpdateSystemHost(this, "Started");
        }
Ejemplo n.º 22
0
        /// <summary>Called upon authentication of a session.</summary>
        /// <param name="session">The authenticated session.</param>
        public void OnSessionAuthenticated(Session session)
        {
            // If there was already a connected player for this new, authentic user session, kick the old
            // one (as it may have been a prior disconnect or whatnot or even a different player character
            // controlled by the same user account).
            // TODO: We can probably handle this more gracefully (without the extra logouts and messaging
            //       the room about it and so on) by having the login process notice the target player is
            //       already in the world sooner, and more directly taking fresh control of THAT Thing.
            PlayerBehavior previousPlayer = FindLoggedInPlayer(session.User.UserName);

            if (previousPlayer != null)
            {
                var msg = $"Duplicate player match, kicking session id {previousPlayer.SessionId} and keeping {session.ID}";
                SystemHost.UpdateSystemHost(this, msg);

                var existingUserControlledBehavior = previousPlayer.Parent.Behaviors.FindFirst <UserControlledBehavior>();
                if (existingUserControlledBehavior != null)
                {
                    existingUserControlledBehavior.Controller.Write(new OutputBuilder().AppendLine("Another connection has logged in as you; closing this connection."));
                }

                previousPlayer.LogOut();
                RemovePlayer(previousPlayer.Parent);
            }

            // Track this player in the loaded players list.
            AddPlayer(session.Thing);

            // If this session doesn't have a player thing attached yet, load it up.  Note that
            // for situations like character creation, we might already have our Thing, so we
            // don't want to load a duplicate version of the just-created player Thing.
            if (session.Thing == null)
            {
                var output = new OutputBuilder();
                output.AppendLine("User was authenticated but the player character could not be loaded.");
                output.AppendLine("Please contact an administrator. Disconnecting.");
                session.Write(output);
                session.Connection.Disconnect();
            }

            // TODO: Perhaps reset player command queue to have exactly one "look" command?
        }
Ejemplo n.º 23
0
        /// <summary>Starts this system.</summary>
        public override void Start()
        {
            SystemHost.UpdateSystemHost(this, "Starting...");

            // TODO: Test > 1, then allow total command processors to be configurable.
            //  This will take a significant effort to work out any race conditions which may leave
            //  things with multiple parents (essentially duplication bugs), deadlocks should we try
            //  to use multiple locks for transaction-like parenting changes, and so on. (We may need
            //  to end up using a fairly global lock for any Parent changes, etc. Note that the Thing
            //  locks in place now on getters and setters are definitely not effective / sufficient.)
            int totalCommandProcessors = 1;

            for (int i = 0; i < totalCommandProcessors; i++)
            {
                var commandProcessor = new CommandProcessor(this);
                commandProcessor.Start();
                commandProcessors.Add(commandProcessor);
            }

            SystemHost.UpdateSystemHost(this, "Started");
        }
Ejemplo n.º 24
0
        /// <summary>
        /// Start the Command system.
        /// </summary>
        public override void Start()
        {
            SystemHost.UpdateSystemHost(this, "Starting...");

            if (AvailableCommands.Length > 0)
            {
                string[] uniqKeys = (from c in AvailableCommands select c.Metadata.Keyword).Distinct().ToArray();
                foreach (var key in uniqKeys)
                {
                    ICommand command = (from c in AvailableCommands
                                        where c.Metadata.Keyword == key
                                        orderby c.GetType().Assembly.GetName().Version
                                        select c.Value).FirstOrDefault();
                    Dictionary.Add(key, command);
                    command.Register();
                    SystemHost.UpdateSystemHost(this, "Registered command: " + key);
                }
            }

            SystemHost.UpdateSystemHost(this, "Started");
        }
Ejemplo n.º 25
0
        public Server()
        {
            var computer = new Computer
            {
                CPUEnabled = true,
                GPUEnabled = true
            };

            computer.Open();

            //foreach (var hardware in computer.Hardware)
            //{
            //	System.Console.WriteLine(hardware.HardwareType);
            //	System.Console.WriteLine(hardware.Identifier);
            //	System.Console.WriteLine(hardware.Name);

            //	foreach (var sensor in hardware.Sensors)
            //	{
            //		hardware.Update();

            //		System.Console.WriteLine(sensor.SensorType);
            //		System.Console.WriteLine(sensor.Name);
            //		System.Console.WriteLine(sensor.Identifier);
            //		System.Console.WriteLine(sensor.Value);
            //	}

            //	System.Console.WriteLine(hardware.SubHardware);
            //}

            var memoryAccess = new MemoryAccess();
            var cpuAccess    = new CpuAccess(new CpuSensorWrapper(computer.Hardware.First(x => x.HardwareType == HardwareType.CPU)));
            var gpuAccess    = new GpuAccess(new GpuSensorWrapper(computer.Hardware.First(x => x.HardwareType == HardwareType.GpuAti ||
                                                                                          x.HardwareType == HardwareType.GpuNvidia)));

            _systemHost = new SystemHost(new SystemService(cpuAccess, memoryAccess, gpuAccess));

            System.Console.WriteLine("Server Online!");
        }
Ejemplo n.º 26
0
        /// <summary>Starts this system's individual components.</summary>
        public override void Start()
        {
            SystemHost.UpdateSystemHost(this, "Starting...");

            SystemHost.UpdateSystemHost(this, "Started");
        }
Ejemplo n.º 27
0
 /// <summary>Starts this system's individual components.</summary>
 public override void Start()
 {
     SystemHost.UpdateSystemHost(this, "Starting...");
     WorldBehavior.Load();
     SystemHost.UpdateSystemHost(this, "Started");
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Stop the data manager system.
 /// </summary>
 public override void Stop()
 {
     SystemHost.UpdateSystemHost(this, "Stopping...");
     SystemHost.UpdateSystemHost(this, "Stopped.");
 }
Ejemplo n.º 29
0
 /// <summary>Stops this system's individual components.</summary>
 public override void Stop()
 {
     SystemHost.UpdateSystemHost(this, "Stopping...");
     //// TODO: WorldBehavior.Areas.Clear();
     SystemHost.UpdateSystemHost(this, "Stopped");
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Event handler for a successfully authenticated session.
 /// </summary>
 /// <param name="session">Session that was authenticated</param>
 private void OnSessionAuthenticated(Session session)
 {
     SystemHost.UpdateSystemHost(this, session.ID + " - Authenticated");
     SessionAuthenticated?.Invoke(session);
 }