Go Back   RunUO - Ultima Online Emulation > Developer's Corner > Programming > C#

C# C# Discussion

Reply
 
Thread Tools Display Modes
Old 05-29-2006, 02:18 PM   #1 (permalink)
Forum Expert
 
BeneathTheStars's Avatar
 
Join Date: Jul 2005
Location: (South)Tip o' Texas
Posts: 1,294
Send a message via AIM to BeneathTheStars Send a message via MSN to BeneathTheStars
Default 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..
BeneathTheStars is offline   Reply With Quote
Old 05-30-2006, 08:27 AM   #2 (permalink)
Account Terminated
 
Join Date: Sep 2002
Age: 26
Posts: 3,846
Send a message via ICQ to Phantom Send a message via AIM to Phantom Send a message via MSN to Phantom
Default

Quote:
Originally Posted by BeneathTheStars
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.
Phantom is offline   Reply With Quote
Old 05-30-2006, 12:11 PM   #3 (permalink)
Forum Expert
 
BeneathTheStars's Avatar
 
Join Date: Jul 2005
Location: (South)Tip o' Texas
Posts: 1,294
Send a message via AIM to BeneathTheStars Send a message via MSN to BeneathTheStars
Default

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...

Last edited by BeneathTheStars; 05-30-2006 at 12:13 PM.
BeneathTheStars is offline   Reply With Quote
Old 05-30-2006, 04:18 PM   #4 (permalink)
Forum Expert
 
Join Date: Jul 2005
Location: Istanbul/Turkey
Age: 27
Posts: 425
Default

use threading..
noobie is offline   Reply With Quote
Old 05-30-2006, 05:17 PM   #5 (permalink)
Forum Expert
 
BeneathTheStars's Avatar
 
Join Date: Jul 2005
Location: (South)Tip o' Texas
Posts: 1,294
Send a message via AIM to BeneathTheStars Send a message via MSN to BeneathTheStars
Default

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..
BeneathTheStars is offline   Reply With Quote
Old 05-30-2006, 05:25 PM   #6 (permalink)
Forum Expert
 
BeneathTheStars's Avatar
 
Join Date: Jul 2005
Location: (South)Tip o' Texas
Posts: 1,294
Send a message via AIM to BeneathTheStars Send a message via MSN to BeneathTheStars
Default

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..
BeneathTheStars is offline   Reply With Quote
Old 05-30-2006, 07:08 PM   #7 (permalink)
Account Terminated
 
Join Date: Sep 2002
Age: 26
Posts: 3,846
Send a message via ICQ to Phantom Send a message via AIM to Phantom Send a message via MSN to Phantom
Default

Have it connect to runuo via sockets.

Using a ReadLine is just a poor way to do it.
Phantom is offline   Reply With Quote
Old 05-30-2006, 07:18 PM   #8 (permalink)
Forum Expert
 
BeneathTheStars's Avatar
 
Join Date: Jul 2005
Location: (South)Tip o' Texas
Posts: 1,294
Send a message via AIM to BeneathTheStars Send a message via MSN to BeneathTheStars
Default

Quote:
Originally Posted by Phantom
Have it connect to runuo via sockets.

Using a ReadLine is just a poor way to do it.
Ill look into that tonight, thx!
BeneathTheStars is offline   Reply With Quote
Old 05-31-2006, 12:51 AM   #9 (permalink)
Forum Expert
 
BeneathTheStars's Avatar
 
Join Date: Jul 2005
Location: (South)Tip o' Texas
Posts: 1,294
Send a message via AIM to BeneathTheStars Send a message via MSN to BeneathTheStars
Default

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");
            Socket socketForClient = tcpListener.AcceptSocket();
            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?
BeneathTheStars is offline   Reply With Quote
Old 05-31-2006, 01:22 AM   #10 (permalink)
Account Terminated
 
Join Date: Sep 2002
Age: 26
Posts: 3,846
Send a message via ICQ to Phantom Send a message via AIM to Phantom Send a message via MSN to Phantom
Default

Quote:
Originally Posted by BeneathTheStars
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");
            Socket socketForClient = tcpListener.AcceptSocket();
            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.
Phantom is offline   Reply With Quote
Old 05-31-2006, 04:30 AM   #11 (permalink)
Forum Expert
 
Join Date: Jul 2005
Location: Istanbul/Turkey
Age: 27
Posts: 425
Default

use your first script with threading..
noobie is offline   Reply With Quote
Old 06-01-2006, 04:23 AM   #12 (permalink)
Forum Expert
 
Join Date: Sep 2002
Age: 23
Posts: 1,472
Default

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
Ravatar is offline   Reply With Quote
Old 06-01-2006, 11:56 AM   #13 (permalink)
Forum Expert
 
BeneathTheStars's Avatar
 
Join Date: Jul 2005
Location: (South)Tip o' Texas
Posts: 1,294
Send a message via AIM to BeneathTheStars Send a message via MSN to BeneathTheStars
Default

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)..

Last edited by BeneathTheStars; 06-01-2006 at 12:01 PM.
BeneathTheStars is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off



Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5