I've been messing around with programming with the miniboa module recently, and I'm confused as to how to wait for one particular user's input. I'm trying to create a MUD-like telnet server that pits a board game engine that I wrote against a client. The problem is most likely coming from a lack of understanding of how asynchronous networking works, but here are my goals with the program.
1) Allow clients to connect to my computer.
2) Allow clients to chat in the lobby
3) Once a client enters a command, the server will play a game with the client.
The way that my board game engine works offline is relatively simple;
1) Prints the board to the user.
2) Waits on user input.
3) If the move is legal, it prints a new board with the user's move.
4) Prints a new board with the computer's move.
5) Repeat steps 2-5.
My confusion comes from a conflict between the way I want the engine to work online, and if it can be applied to an asynchronous server. Is this even reasonable? I tried to make a loop that waits until a valid move has been made by the client, but it just sticks the client and server in an infinite loop.
def interface(client): print("Game interface started for %s\n" % (client.addrport())) if client.active and client.cmd_ready: client.send("Hello, and welcome to my first ever igo engine!\n") client.send("I hope to make it around 20k one day, but right now\n") client.send("it plays on a 50k level. It's good for a time-killer,\n") client.send("and even better to take out your frustrations! Now\n") client.send("that the introductions are out of the way, let's\n") client.send("play!\n\n") client.send("What sized board do you want to play on?\n") valid_size = False while valid_size == False: try: size = int(client.get_command()) if size <= 19 and size >= 2: valid_size = True else: client.send("Oh no! That's not a valid board size!") except ValueError: client.send("Oh no! That's not a valid board size!") self.single_player_match(client, size)
I've also tried to just explicitly call the client.get_command(), but it just returns the None type.
def test(client): client.send("This is some test text. Thanks!\n") cmd = client.get_command() print("You entered: %s\n" % cmd)
I probably have the completely wrong idea about my entire approach, so a push in the right direction would be appreciated.