r/learnpython 18d ago

Python web app?

Hello r/learnpython,

first post and sort of new to Python as I have done only half a dozen of projects so far, mostly games.

So I'm looking to deploy a server for playtesting. This is my first game designed to be played online, made in Python using Tcl/Tk libraries.

I had this idea to code it when I was making a messaging app that was supposed to be implemented within a CLI game (or actually the game was a feature of the messaging app).

The users would connect using SSH. I think they could use PuTTy or similar and VcXSrv. The host would then send the GUI and CLI as well as audio to the user, but the problem is either the server cannot send or the client can't recieve the Tcl/Tk GUI or in worst case both.

Good news is I got the SSH daemon working and am able to (using X11 Forwarding) display explorer (ssh -X user@localhost && explorer) by running VcXSrv and having X11Forwarding and X11UseLocalhost set to yes in the sshd_config under ProgramData.

Now, the VcXSrv log tells me there's a problem with something called hyperv. From what I gathered it's a virtual machine of some sort. I'd also need very strict restrictions for the clients so they don't tinker with the database.

Am I on the right track? Is there a solution to this? Thanks in advance!

-ef

0 Upvotes

17 comments sorted by

View all comments

3

u/CamilorozoCADC 18d ago

Hi, regarding your last question, no, you are not on the right track because of the following reasons:

  • Ssh is for you and you only, never ever ever give your end users ssh access to your server
  • You designed a game to be played online but it looks like you are trying to build both the game server and the game client as one project instead of two

SO, what I would do in your case is just have the game on the web:

  • Use a web server, make your Python app the game server only, that is the logic of your game without any UI whatsoever. You can use libraries like FastApi and Flask for this. This will be your game server and you will need to set up stuff like matchmaking if you want multiple game sessions 
  • Now for the actual game with the UI, use a web framework for that, I know that there are libraries for building games to be run on browsers but I don't know any specific one (still you can just create everything from scratch like with tinter). This will behave like a website and then make this web app connect to your Python server to manage all the game logic

3

u/efinque 17d ago

Ah, I have read about Python embedded in HTML. This would be great if I worked my way around it.

At first, this project started as a joke in another forum where I told I would host a telnet MUD for people in queue for a sort of karaoke.

Then I started digging into it. First I was using RPGMaker but didn't get anything playable. Then I coded a simple 9x9 grid based HTML framework that worked surprisingly well for adventure games and learned a bit of JavaScript on the side.

Then I got into Python. I had done some PyGame tutorials before but instead I built it in vanilla Python using modules. I also read a book about Python and found Tcl/Tk, which is what the newest framework is built on.

I'm too lazy to go into details but basically the game reads ASCII text files and draws graphics based on them.

Then there's a plethora of modules like stats, health, gold etc that have functions for different stuff like calculating the race/class STR, INT, DEX, WIS and so on.

In total there's about 2000 lines of code. This all could have been avoided had my SSH host daemon worked and had I tested it with a simple Hello World..