Interactive server terminal

My game’s server program is windowless but I still want the end user to be able to enter commands (similar to minecraft’s server and others). Is such a thing possible with panda’s run() function or writing my own main loop?

The way i see things, you will need a panda3D window if you want to capture the keyboard events from any kind of DirectObject.

If you really want to avoid a panda3D window, you can use another lib that also opens a window and handles keyboard input (pygame, any GUI lib…).

If you really want to avoid opening any window, and want to send the commands from the console, raw_input alone won’t do. Assuming you’re on linux, you will have to use the select, tty, and termios modules, as is explained on this Stack Overflow page.

You could use threading. Have the main process on one thread and another thread for a GUI to enter commands.

I’ve done something like this before using the ‘exec’ keyword to handle the commands I entered to simulate a python injector, but I think what you’d want to do is have a list of predefined keywords to submit and a checker to see if the input is actual commands. If you were interested in having it offscreen, hide the window and use your own form of input via command-line.

Here’s some sample code:

import threading
from myMainFile import myMainFile # This file imports and starts ShowBase
from myGUIFile import myGUIFile # This file creates my command box on ShowBase window

main = myMainFile()
mainThread = threading.Thread(target=main.startFunction, name="main", args=(main,))
mainThread.daemon = True
mainThread.start()

gui = myGUIFile()
guiThread = threading.Thread(target=gui.start, name="GUI", args=(gui,))
guiThread.daemon = True
guiThread.start()

base.run()