Command Line Interface for C++ Server - c++

I have been working on this C++ chat server for Linux for a while and I have all the basic stuff down. I now need to make a user interface for it. I want to make a command-line interface but I'm having trouble figuring out what I should use to do so. I basically want it so there is a place at the bottom of the terminal for the admin to type and above that I want all messages, information, and etc to be displayed. What happens above the admin's input box should not affect the admin's input box. What would be the best way to accomplish this? I have tried using Ncurses but I am not sure if it is the best option.

Since you have done a chat server anyway why not just have another 'chat' connection on a different port as the admin interface? Then the interface for the admin is whatever you use as the chat client and you can admin it remotely or easily automate tt

You can have a look at this lib too : http://alexis.royer.free.fr/CLI/
(cli = command line interface)

I think that the CLI toolkit (http://alexis.royer.free.fr/CLI/) can help for your bottom terminal, the one managing the admin interface.
You may just have to define your own IODevice so that outputs do not affect the whole screen.
This IODevice may be based on ncurses for instance as you started (get inspiration from ncurses_console.h/.cpp for that).

Related

How do I change the Unreal Engine AppleARKitLiveLink Settings via user input?

After compiling the Unreal Engine FaceARSample project the user can send the iPhone's facial blendshape data via the AppleARKitLiveLink plugin to a computer on their network with an IP address they define. I want to change it so the user can edit other LiveLink settings as well. Most importantly, the Subject Name.
So I found in the FaceARSample where the LiveLink source is created, inside of AppleARKitFaceSupportlmpl.cpp. The console command "LiveLinkFaceAR SendTo= [IP Address] " is used to change where LiveLink is publishing to. Upon pressing a button in the compiled app this console command is triggered which uses the line of code below to send the data over the network:
RemoteLiveLinkPublisher = FAppleARKitLiveLinkSourceFactory::CreateLiveLinkRemotePublisher(RemoteIp);
I've tried to make my own AppleARKitLiveLinkSourceFactory through blueprints but I couldn't figure it out. I found that I could edit the default subject name in the AppleARKit Project Settings. Is it possible to give the user access to these project settings via blueprints?
I'm confused about where to start. I've taken a look at the Maya LiveLink plugin, read the Unreal Engine documentation,and studied C++ for about 4 weeks now but I'm still confused. Do I need to somehow create an Unreal Engine module and #include the AppleARKit plugin then derive my own class from the AppleARKitLiveLinkSourceFactory? Do I need to create my own AppleARKit plugin from scratch?
Here's the documentation I read:
https://docs.unrealengine.com/en-US/Engine/Animation/LiveLinkPlugin/LiveLinkPluginDevelopment/index.html
You need to create your own plugin or game code, there you need to include the AppleARKit module editing your Build.cs then you can use their exported classes.
By instance all settings you can see in the project settings are driven by static UObjects, you can access all them if they are expose using something like this:
class* myclass = GetMutableDefault<>();
In this case you want to look for UAppleARkitSettings, now that been said, looks like that variable is protected, so you will not be able to modify it at all. if you really want to modify it through custom nodes in blueprints, you have 2 options, if you have the source, just change it to public, second option is remove the plugin from your engine, and paste it in your per project plugin folder and edit it there.
that's the closest you can go, nevertheless I suggest you changing that from the settings, looking to the architecture I can't see a valid reason to change that via BP, but it is up to you
Cheers and hope that helps

Qt Console with Bash

I am writing a program using the Qt framework. I would like the user to be able to have access to a console/terminal from within the application itself.
In other words, the user should be greeted with a "BASH" prompt when they start the program.
I have looked into QTermWidget, but there doesn't seem to be too much documentation on it and it doesn't seem to be up to date either.
I've looked at QConsole, but it only seems to be able to run TCL/Python consoles.
How would I be able to embed a terminal into my application?
There is really not much tutorial needed for QTermWidget, although there is one here.
The purpose of the widget is that it does not require any complication. The code would be something like this without the extra settings:
QTermWidget *console = new QTermWidget();
QMainWindow *mainWindow = new QMainWindow();
mainWindow->setCentralWidget(console);
It is also not necessarily true that it is not up-to-date. It was recently updated to build against Qt 5 properly. If you lack anything, please use the issue tracker on github.
It should be more or less in mature and "complete" state, that is why you may not see heavy progress. It is just a widget after all, not a big framework.
You could try QProcess. This is not strictly "embedding" a terminal in your app, but it it really easy to use, you can kick off a terminal that is owned by your app. You can even connect (with signals / slots) to its output and interact with it in a limited fashion... depends on what you need.
Here is the doc with some simple examples: http://qt-project.org/doc/qt-5/QProcess.html
I am not at my Qt-PC today so I don't have an "interacting" example for you, but if you think this is a way for you to go then I can dig that out...

windows api to create shortcut and put application in start menu

I have a client application in C++. For that I want to create a shortcut on the desktop and an entry in the start menu while installing. Is there any C++ windows api for that? I tried searching for it but couldn't find it. Can anyone tell me how it can be done?
You'll have to get your hands a bit dirty, and use COM to access the Shell. You can read here about Shell Links. Also, this project might provide you the code you need.
To get the location of the desktop and the start menu folders, you can use the appropriate System Variables.

Inject C code into *nix application: replacing a function

I have a newbie but really important question for me: I have a Mac Os X application that uses carbon api, but it is still a C++ application. I need to debug which functions are called at execution time and then make a C++ patch to replace one of those functions.
The real goal: I need to log all text printed into a chat window that the application has inside an unnacessible carbon view. I thought at first it was a cocoa application, but it's not, so fscript and imlib are no good to inject code.
Is it possible? Any clues? Thank you very much.
Cheers :)
You could look into using truss to figure out what system calls are being made but I'm not sure for user-calls. The LD_PRELOAD environment variable can allow you to inject methods into other apps, but C++ methods tend to have various dependencies regarding name mangling and calling method so it would probably be tricky to plug in your own.
Can you just have the app maintainer add actual hooks to allow for what you need?

I want to hide system commands issued from system()

Writing a program in c++ and I want to issue a system command from the system() function but I don't want the user to see the command (because the command includes a pwd) in the executable window. I need to copy a file from the user's directory onto the server without allowing user access to the server or displaying the pwd. Figured having a .exe that does this is the easiest way.
Ex:
system("FILETRANSFER_SW.exe -pw helloWORLD11!# C:/temp.txt F:/tempfolder/")
But the executable window is showing this command, hence defeating the purpose of trying to hide the password.
I tried issuing
system("#echo OFF")
at the beginning of the program but that does not suppress the following commands, they still show up in the executable window.
Any suggestions?
Thanks...
The command line of running processes is considered public information in most operating systems.
Therefore it is a very bad idea to pass passwords on the command line.
There are two common workarounds to this problem, both of which require the support of the executable being called:
instead of passing the username/password on the command line, pass the name of a file containing the username/password
re-set the command line of the running process from within the called executable.
The first solution is easy and universally possible, the second one has a race condition and is harder to implement, because there's no cross-platform way to do it (on some OSes, changing argv will help).
I'm assuming from your command line that you're using Windows. If it doesn't need to be portable I would suggest you use the CreateProcess() API instead of calling system().
The CreateProcess() API can take a command-line and you can set up the STARTUP_INFORMATION parameter to hide the new process window (wShowWindow = SW_HIDE).
The command line will be hidden from the casual user, but as others have pointed out, it's not that hard to retrieve. Since you are creating a new process, I would suggest writing the sensitive data to that process' standard input. That way the process can just read it and proceed normally.
Using CreateProcess() API will hide the sensitive data from a user, but a power user can easily get the command line associated with the process using a free utilty, e.g. Process Explorer
Another solution is to send the password between your programs, encrypted with something like 3DES, or AES.
You could use a pipe to comunicate between both programs, and don't use the command line at all.
But any of this schemes is not really secure they can be circumvent rather easily. If you want more security you should use some kind of challenge-response protocol with the server.