RunUO Community

This is a sample guest message. Register a free account today to become a member! Once signed in, you'll be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Stop a console ReadLine

Stop a console ReadLine

Hello, i am having a problem with a ReadLine. I have a part of the code doing a ReadLine();, but as it awaits for the user to input something, it pauses all other actions the server wants to do. my question is how can i cancel this ReadLine from another script?

Thx for any help..
 

Phantom

Knight
BeneathTheStars said:
Hello, i am having a problem with a ReadLine. I have a part of the code doing a ReadLine();, but as it awaits for the user to input something, it pauses all other actions the server wants to do. my question is how can i cancel this ReadLine from another script?

Thx for any help..

You could read the buffer I suppose, but you cannot "cancel" a ReadLine, you have to send something. Even if it was possible to "cancel" a ReadLine you shouldn't do it from another script.

If you explain what your trying to do, we can help you do it a better way.
 
I am making a script that will allow you to do certain commands from the console, instead of logging in to do them. I have the script that will send the Readline once the server is done loading..

Code:
using System;
using System.IO;
using Server;

namespace Server.Misc
{
    public class ConsoleShutdown
    {
        public static void Initialize()
        { EventSink.ServerStarted += new ServerStartedEventHandler(EventSink_ServerStarted); }

        public static void EventSink_ServerStarted()
        {
            Console.WriteLine("What?");
            Console.ReadLine();
        }
    }
}

But because of the readLine, it puts a hold on things like saving...
 
Well, if i understand correctly, then they only have a window of time to enter a command( or a number of windows)...

As of now, i have a separate .exe that talks to a script in the Runuo scripts folder. But, i am having a "fun" time trying to get that script to talk to the Server.exe, and not the external .exe i made..if that makes any sense..
 
The external .exe:

Code:
using System;
using System.Collections;
using System.Text;
using Server;
using Server.CHQ;

namespace Server.Misc
{
    class ServerConsole
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Whats do you wish to do?");
            string ans = (Console.ReadLine()).ToLower();

            if (ans == "shutdown")
                ConsoleHQ.ShutDown();
            if (ans == "restart")
                ConsoleHQ.ReStart();
        }
    }
}

The script in the Runuo Script folder:

Code:
using System;
using System.IO;
using Server;
using System.Diagnostics;

namespace Server.CHQ
{
    public class ConsoleHQ
    {
        public static void ShutDown()
        {
            World.Save();
            Core.Process.Kill();
        }
        public static void ReStart()
        {
            AutoRestart.Initialize();
        }
    }
}

The problem is that when for example, i type shutdown, the .exe trys to save, not the Server.exe . Any guidance would be great..
 
Old problem new culprit. The line in red pauses the server.exe until it gets its packet.(Console says Remote Started, but doesnt say "2" untill the socket is sent)
Code:
using System;
using System.Net.Sockets;
using System.IO ;
using Server;
namespace Server.Misc
{
    public class Echoserver
    {
        public static void Initialize()
        { 						
            TcpListener tcpListener = new TcpListener(1234);
            tcpListener.Start();
            Console.WriteLine("Remote Started");
            [COLOR="Red"]Socket socketForClient = tcpListener.AcceptSocket();[/COLOR]
            Console.WriteLine("2");//debuging
            string line = "";
            try
            {...

Is there any way to tell the server to go on while still letting this script accept the socket?
 

Phantom

Knight
BeneathTheStars said:
Old problem new culprit. The line in red pauses the server.exe until it gets its packet.(Console says Remote Started, but doesnt say "2" untill the socket is sent)
Code:
using System;
using System.Net.Sockets;
using System.IO ;
using Server;
namespace Server.Misc
{
    public class Echoserver
    {
        public static void Initialize()
        { 						
            TcpListener tcpListener = new TcpListener(1234);
            tcpListener.Start();
            Console.WriteLine("Remote Started");
            [COLOR="Red"]Socket socketForClient = tcpListener.AcceptSocket();[/COLOR]
            Console.WriteLine("2");//debuging
            string line = "";
            try
            {...

Is there any way to tell the server to go on while still letting this script accept the socket?

The solution is to use a non-console application to connect to RunUO and send the command within a packet.

You have of course send the require bytes that RunUO expects. You can check out the core for what I mean by this.
 

Ravatar

Knight
What noobie means:


Code:
// Along with the other namespace declarations
using System.Threading;

	...

// Somewhere in your calling method
new Thread(new ThreadStart(ConsoleListen)).Start();

	...

// Somewhere else in the class
public static void ConsoleListen()
{
	string input = Console.ReadLine();
	Console.WriteLine("User Input: {0}", input);
}

1337th post btw
 
Hmm, thx newbie,Ravatar, and Phantom. Ill play with that...looks like i diddnt get deep enough into threading.. :)

Going to take this opportunity to learn windows forms, and im going on vacation, so i should have it all done by the end of this month(with lots of features)..
 
Top