Exemple #1
0
        public static void Main(string[] args)
        {
            Console.WriteLine("Starting Vortex MUD Server");

            // Load up game files
            IOManager.InitilizeGameData();

            // Show Commands
            Console.WriteLine("Recognized commands are:");
            foreach (var command in CommandHandler.GetValidCommands ()) {
                Console.WriteLine("\t{0}", command);
            }

            string[] testStrings = {"nothing matches", "shutdown", "q", "qu", "ooc"};
            foreach (var str in testStrings) {
                var result = CommandHandler.GetMatchingCommand(str);
                if (result != null) {
                    Console.WriteLine("[TEST] String \"{0}\" matched command \"{1}\"", str, result.CommandAttributes.Name);
                } else {
                    Console.WriteLine("[TEST] String \"{0}\" failed to match any commands.", str);
                }
            }

            // Start up the connection listener
            ConnectionListener IncomingConnections = new ConnectionListener(MUDServer.Port);
            IncomingConnections.StartListening();

            Console.WriteLine("Vortex MUD ready to rock on port " + MUDServer.Port);

            // enter main loop
            Console.WriteLine("Entering main loop...");
            while (MUDServer.Running) {
                DateTime startTime = DateTime.Now;

                // check for new connections
                CheckForNewConnections(IncomingConnections);

                // get player input
                // run game update tic
                ProcessTick();

                // send output
                SendOutput();

                TimeSpan tickTime = DateTime.Now - startTime;
                if (tickTime.TotalMilliseconds < MillisecondsPerTick) {
                    Thread.Sleep(MillisecondsPerTick - (int)tickTime.TotalMilliseconds);
                } else {
                    Console.WriteLine(String.Format("[ALERT!!!] Tick took {0} ms to run (target is {1} ms)", tickTime.TotalMilliseconds, MillisecondsPerTick));
                }
            }
            Console.WriteLine("Exiting main loop...");

            IncomingConnections.StopListening();

            Console.WriteLine("Vortex MUD server has terminated.  Press any key to continue.");
            Console.ReadKey(true);
        }
Exemple #2
0
        static void CheckForNewConnections(ConnectionListener IncomingConnections)
        {
            List<Socket> newConnections = IncomingConnections.AcceptConnections();
            foreach (Socket sock in newConnections) {
                PlayerCharacter newPlayer = new PlayerCharacter(new PlayerSocket(sock));

                WriteToAllCharacters(String.Format("{0} has connected.\n\r", newPlayer.Name));

                Character.AddCharacterToGame(newPlayer);

                Room.GetRoom (1).AddCharacterToRoom(newPlayer);
                CommandHandler.GetMatchingCommand ("look").Execute(newPlayer, "quiet");
            }
        }