View Full Version : Launch custom front end from Lich UI?
Overlordz
08-05-2015, 01:57 AM
I'm in the early stages of making a WPF/.NET/C# based front end for GS. Basically, in theory, I'd like to make (a subset of) Stormfront without the memory leaks. And in theory a more flexible layout. Right now I'm setting up the UI stuff to make sure WPF can handle it performance wise. I added/removed about a million lines of text (including hyperlinks) in a FlowDocumentScrollViewer and after all that the app was using ~70MB of memory. Seems like it shouldn't need that much, but hey, it hasn't ballooned to 2GB like Stormfront does sometimes.
I would make this in Ruby/GTK because then it would be truly cross platform (WPF is anything but) and it would be the same language/stack as Lich but I don't know anything about GTK, I only know enough Ruby to do simple scripts and I'm just way more fluent in C# (and XAML). Maybe I should just force myself to learn GTK... but... I'm lazy.
Of course my front end would be useless without a connection to Lich so I'm trying to get that wired up right. Right now I'm running Lich in "profanity mode", where I'm giving it the args "--login=Foo --detachable-client=8000 --without-frontend" and then launching my front end. That works but I'd really like it to act more like an "attached" front end and have the game disconnect when I close it. I'd also like to be able to use Lich's GUI login tool. How can I do that?
If I select "custom launch command" and give Lich the path to my .exe (and accept the port/host args), should that work? I tried that but I was getting a shell execute error. I wonder if Lich is trying to launch my exe and failing, or if it's trying to do something like launch the game launcher (which I definitely don't need). Maybe Lich is just ignoring the path I give it since the pre-populated texts (wizard.exe, stormfront.exe) don't include any path.
I can always read the code, just thought I'd ask for some pointers. Thanks for your time in making this thing.
Drunken Durfin
12-11-2016, 11:21 PM
You ever make any progress with this?
I'm about to start down a similar path, looking to build something on the Universal Windows Platform so I can have GS on a RaspberryPi running Windows Core.
Androidpk
12-11-2016, 11:25 PM
You ever make any progress with this?
I'm about to start down a similar path, looking to build something on the Universal Windows Platform so I can have GS on a RaspberryPi running Windows Core.
That sounds like a super cool project. Keep us updated :D
Drunken Durfin
12-12-2016, 07:45 PM
I'm a database / utility coder. I don't know beans about TCP, Sockets and Ports, which is making the initial step into this process very difficult. That and I don't have a lot of free time to research this stuff. So, if someone wants to throw me a bone it will be humbly appreciated.
I'm using the "lich.rbw --login [charactername] --without-frontend --detachable-client=8000" command line option with Lich, and I'm able to see the game feed in a browser pointing to http://127.0.0.1:8000/ so I know that I'm connected.
Unfortunately this is where I currently am with the project:
private void btnSendCommand_Click(object sender, EventArgs e)
{
TcpClient tcpClient = new TcpClient("127.0.0.1", 8000);
using (NetworkStream ns = tcpClient.GetStream())
{
using (BufferedStream bs = new BufferedStream(ns))
{
byte[] messageBytesToSend = Encoding.UTF8.GetBytes("say hello from C#");
bs.Write(messageBytesToSend, 0, messageBytesToSend.Length);
}
}
Console.WriteLine("Operation complete.");
}
This is giving me a wonderful error:
An unhandled exception of type 'System.Net.Sockets.SocketException' occurred in System.dll
Additional information: No connection could be made because the target machine actively refused it
System.Net.Sockets.SocketException was unhandled
ErrorCode=10061
Message=No connection could be made because the target machine actively refused it 127.0.0.1:8000
NativeErrorCode=10061
Source=System
If someone can get me started here it would be greatly appreciated. Once I'm able to receive the game stream, and send commands back up the line, it will progress fairly quickly. The learning curve up to that point is a tad steep right now. Once I have XML stream to work with I'll be able to ramp this up pretty quickly.
I'm coding this in C#, so any assistance will need to be of that flavor to be helpful.
Thanks in advance for any constructive help.
m444w
12-12-2016, 09:03 PM
Lich's TCP server is single threaded, so if you are connected to it in the browser, it won't accept anymore connections.
Also, not that it matters for your current problem, but I am fairly sure you want ASCII encoding (because that's what GS sends), not UTF-8. You might end up with some garbed characters otherwise.
Yeah, ASCII: https://github.com/matt-lowe/Lich/blob/master/lich.rb#L2
Drunken Durfin
12-13-2016, 12:17 AM
Well, that totally worked, thanks!
Dropped the browser connection and I was able to send commands. Granted I could not see anything, had someone else in game watching for my actions.
So, what is the deal if it won't accept more than one connection from the FE? I have to disconnect the incoming game stream, send my command up, then reconnect? That seems kinda error prone.
Jymamon
12-13-2016, 12:36 AM
You use the same TcpClient for read and write. See this StackOverflow question/answer: http://stackoverflow.com/questions/3609280/sending-and-receiving-data-over-a-network-using-tcpclient
Alternately, check out the MinimalisticTelnet at https://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=19071, particularly TelnetInterface.cs (https://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=19071&zep=MinimalisticTelnet%2fMinimalisticTelnet%2fTeln etInterface.cs&rzp=%2fKB%2fIP%2fMinimalisticTelnet%2f%2fminimalis tictelnet.zip)
EDIT: The MSDN async socket example also has some reasonable code: https://msdn.microsoft.com/en-us/library/bew39x2a(v=vs.110).aspx
Drunken Durfin
12-13-2016, 12:57 AM
You use the same TcpClient for read and write. See this StackOverflow question/answer: http://stackoverflow.com/questions/3609280/sending-and-receiving-data-over-a-network-using-tcpclient
Alternately, check out the MinimalisticTelnet at https://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=19071, particularly TelnetInterface.cs (https://www.codeproject.com/script/Articles/ViewDownloads.aspx?aid=19071&zep=MinimalisticTelnet%2fMinimalisticTelnet%2fTeln etInterface.cs&rzp=%2fKB%2fIP%2fMinimalisticTelnet%2f%2fminimalis tictelnet.zip)
EDIT: The MSDN async socket example also has some reasonable code: https://msdn.microsoft.com/en-us/library/bew39x2a(v=vs.110).aspx
Thanks for this. The MSDN stuff looks promising.
Androidpk
12-13-2016, 12:59 AM
Which Pi are you using?
Drunken Durfin
12-13-2016, 08:37 AM
I don't have one for this project yet. Waiting to see if I can actually get the app to work well first.
Donquix
12-13-2016, 12:48 PM
out of curiosity, any reason you aren't just using profanity? something fun to play with or is it missing features you want?
Drunken Durfin
12-13-2016, 01:31 PM
out of curiosity, any reason you aren't just using profanity? something fun to play with or is it missing features you want?
There are a few reasons. The biggest is that I want to make a UWP front end in C# to leverage my knowledge of that language which is far greater than my Ruby. The second is that one of the projects for next year I have at the day job involves writing a couple of apps that will run on Windows Core via the MSFT app store on RaspberryPi. I'm treating my Pi/C# front end project as a study for those coming projects.
Donquix
12-13-2016, 02:30 PM
math checks out, carry on.
Overlordz
12-26-2016, 12:22 AM
Are you planning on hooking your Pi up to a monitor, TV, series of LEDs...? I have a Raspberry Pi B+. The GUI on it runs like dog shit... maybe molasses if you're being forgiving. Raspberry Pi 2/3 are supposed to be faster. I can only imagine what any kind of Windows would run like on a Pi.
Sockets aren't so bad once you get used to them. I learned how to do them in C from Beej's guide eons ago. The basic ideas should transfer to any language. I would hope there's an equivalent guide for doing them in .NET.
I haven't touched WPF in awhile, worked on an Angular based webapp and now a React based webapp at work. I'm still probably most literate in XAML/WPF though. I swear I've half-learned about a dozen different UI toolkits/paradigms now, sometimes I wish the tech world would settle down and stop spastically reinventing the wheel again and again.
HTML3/4, SWING (yuck), CSS (ok I guess), GTK (meh), Win Forms (yuck), WPF (yay), HTML5/CSS (ok), Vaadin (barf), Angular (sure...), React (interesting...). What else am I forgetting...
A few things I'd like in a front end:
- runs in Linux without wine or virtualization (C# ain't gonna work well there... of course there's always mono... I guess...)
- has a tab control for separating out different LNet channels/thought nets/private chats
- no memory leaks a la SF
- drag and drop a la SF
- minimal amounts of wasted screen space
- highlights shared among characters a la Wizard (maybe there's a way to do this in SF already?)
- able to use ctrl + mouse wheel to zoom, like most web browsers do these days, for when my eyes start getting tired (when I started on my WPF front end, this was nicely baked into a FlowDocumentScrollViewer)
- ability to bind regular keys 0-9 and A-Z. When I hunt my wizard I have like a thousand different macros and only so many F-keys, I would like to switch the front end to a "hunting mode" that you'd see in games like TF2 or Dota 2 where pressing a key brings up actually typing to the game, otherwise all your keys could be bound to different commands. Sure you can use modifiers but I would rather not.
Probably other stuff I'm forgetting. All this would take time that I generally don't have.
Jymamon
12-26-2016, 03:53 AM
- runs in Linux without wine or virtualization (C# ain't gonna work well there... of course there's always mono... I guess...)
I haven't tried with anything GUI related, but I was pleseantly surprised how well mono worked on a prior project. It was to be a RPi based in-car entertainment system. All of the RBDS (https://en.wikipedia.org/wiki/Radio_Data_System) work was done in C# along with a SQLite-based media library (who knew that finding a good component re-usable one would be such a pain two decades after MP3 players took off?).
I eventually lost interest in the project when even better head units dropped to being dirt cheap. (Plus I was down to mostly just UI work which is the least fun of any project for me.) I was left with a positive impression of mono, in any case. I think other than a few small tweaks to the msbuild based project files I use, I was able to compile and run both on my PC (Windows) and my RPi (Raspian) without issue. (Never tried pulling binaries from one to the other, though.)
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.