From 4839d55d29f092d74d10597232ec0f3fe08936f2 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Sun, 22 Nov 2020 05:04:51 +0100 Subject: [PATCH 01/16] Fix terminal link coloring. --- rogue_chat_nocanvas_monochrome.html | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/rogue_chat_nocanvas_monochrome.html b/rogue_chat_nocanvas_monochrome.html index c04e362..59d03a9 100644 --- a/rogue_chat_nocanvas_monochrome.html +++ b/rogue_chat_nocanvas_monochrome.html @@ -1,13 +1,19 @@
terminal rows: terminal columns:
-

+

 
 
source code (includes proper terminal / curses client) -- 2.30.2 From 600df1cb4f785eeeb0d604a2d7b6e08d41dd652c Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Sun, 22 Nov 2020 05:09:59 +0100 Subject: [PATCH 02/16] Lessen audio calculation weight. --- plomrogue/commands.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plomrogue/commands.py b/plomrogue/commands.py index 26576d0..41509df 100644 --- a/plomrogue/commands.py +++ b/plomrogue/commands.py @@ -27,7 +27,7 @@ def cmd_ALL(game, msg, connection_id): def lower_msg_by_volume(msg, volume, largest_audible_distance): import random - factor = largest_audible_distance / 8 + factor = largest_audible_distance / 4 lowered_msg = '' for c in msg: c = c @@ -44,7 +44,7 @@ def cmd_ALL(game, msg, connection_id): speaker = game.get_player(connection_id) if not speaker: raise GameError('need to be logged in for this') - largest_audible_distance = 40 + largest_audible_distance = 20 dijkstra_map = DijkstraMap(game.maps, speaker.position, largest_audible_distance, game.get_map) for c_id in game.sessions: -- 2.30.2 From bbf3e311b99cb9f32102c3cb3db4887a6ec91751 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Tue, 24 Nov 2020 23:57:15 +0100 Subject: [PATCH 03/16] Move socket configuration into command line options. --- plomrogue/config.py | 35 +++++++++++++++++++++++++++++++++++ rogue_chat.py | 15 +++++---------- rogue_chat_curses.py | 7 +++++-- rogue_chat_curses.sh | 2 +- 4 files changed, 46 insertions(+), 13 deletions(-) create mode 100644 plomrogue/config.py diff --git a/plomrogue/config.py b/plomrogue/config.py new file mode 100644 index 0000000..fcb74dd --- /dev/null +++ b/plomrogue/config.py @@ -0,0 +1,35 @@ +from plomrogue.io_websocket import PlomWebSocketServer +from plomrogue.io_tcp import PlomTCPServer, PlomTCPServerSSL +from plomrogue.errors import ArgError + +def parse_command_line_arguments(): + import argparse + parser = argparse.ArgumentParser() + parser.add_argument('savefile') + parser.add_argument('--server-type', nargs='+', required=True, + choices=['tcp', 'tcp_ssl', 'ws']) + parser.add_argument('--port', nargs='+', required=True, type=int) + parser.add_argument('--keyfile') + parser.add_argument('--certfile') + opts = parser.parse_args() + if len(opts.server_type) != len(opts.port): + raise ArgError('number of ports unequal to number of server types') + if 'tcp_ssl' in opts.server_type and not (opts.keyfile or opts.certfile): + raise ArgError('need key and cert file for tcp_ssl server') + config = { + 'savefile': opts.savefile, + 'servers': {}, + 'keyfile': opts.keyfile, + 'certfile': opts.certfile, + } + for i in range(len(opts.port)): + server_type = opts.server_type[i] + if server_type == 'ws': + config['servers'][opts.port[i]] = PlomWebSocketServer + elif server_type == 'tcp': + config['servers'][opts.port[i]] = PlomTCPServer + elif server_type == 'tcp_ssl': + config['servers'][opts.port[i]] = PlomTCPServerSSL + return config + +config = parse_command_line_arguments() diff --git a/rogue_chat.py b/rogue_chat.py index 1f40913..407dc29 100755 --- a/rogue_chat.py +++ b/rogue_chat.py @@ -1,7 +1,5 @@ #!/usr/bin/env python3 from plomrogue.game import Game -from plomrogue.io_websocket import PlomWebSocketServer -from plomrogue.io_tcp import PlomTCPServer from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_NICK, cmd_PING, cmd_THING, cmd_MAP, cmd_TURN, cmd_MAP_LINE, cmd_GET_ANNOTATION, cmd_ANNOTATE, cmd_PORTAL, cmd_GET_GAMESTATE, @@ -13,13 +11,9 @@ from plomrogue.commands import (cmd_ALL, cmd_LOGIN, cmd_NICK, cmd_PING, cmd_THIN from plomrogue.tasks import (Task_WAIT, Task_MOVE, Task_WRITE, Task_PICK_UP, Task_DROP, Task_FLATTEN_SURROUNDINGS) from plomrogue.things import Thing_Player, Thing_Item, Thing_Furniture -import sys -if len(sys.argv) != 2: - print('wrong number of arguments, expected one (save file)') - exit(1) -savefile = sys.argv[1] -game = Game(savefile) +from plomrogue.config import config +game = Game(config['savefile']) game.register_command(cmd_PING) game.register_command(cmd_ALL) game.register_command(cmd_LOGIN) @@ -56,5 +50,6 @@ game.register_thing_type(Thing_Item) game.register_thing_type(Thing_Furniture) game.read_savefile() game.io.start_loop() -game.io.start_server(8000, PlomWebSocketServer) -game.io.start_server(5000, PlomTCPServer) +for port in config['servers']: + game.io.start_server(port, config['servers'][port], + config['certfile'], config['keyfile']) diff --git a/rogue_chat_curses.py b/rogue_chat_curses.py index d22539b..2362d99 100755 --- a/rogue_chat_curses.py +++ b/rogue_chat_curses.py @@ -3,6 +3,7 @@ import curses import queue import threading import time +import sys from plomrogue.game import GameBase from plomrogue.parser import Parser from plomrogue.mapping import YX, MapGeometrySquare, MapGeometryHex @@ -900,5 +901,7 @@ class TUI: elif key in self.movement_keys: move_explorer(self.movement_keys[key]) -#TUI('localhost:5000') -TUI('wss://plomlompom.com/rogue_chat/') +if len(sys.argv) != 2: + raise ArgError('wrong number of arguments, need game host') +host = sys.argv[1] +TUI(host) diff --git a/rogue_chat_curses.sh b/rogue_chat_curses.sh index fa78c01..5fd7385 100755 --- a/rogue_chat_curses.sh +++ b/rogue_chat_curses.sh @@ -3,4 +3,4 @@ python3 -m venv .venv . .venv/bin/activate pip install -r requirements_client.txt -./rogue_chat_curses.py +./rogue_chat_curses.py 'wss://plomlompom.com/rogue_chat/' -- 2.30.2 From 2b771f8e84f26be608161b79e19fa255a0832c67 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Wed, 25 Nov 2020 00:07:19 +0100 Subject: [PATCH 04/16] Shorten web client HTML file name. --- rogue_chat_nocanvas_monochrome.html => rogue_chat.html | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename rogue_chat_nocanvas_monochrome.html => rogue_chat.html (100%) diff --git a/rogue_chat_nocanvas_monochrome.html b/rogue_chat.html similarity index 100% rename from rogue_chat_nocanvas_monochrome.html rename to rogue_chat.html -- 2.30.2 From f4e55ffc4ae34874d57f087894b73934eaebd383 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Wed, 25 Nov 2020 00:08:57 +0100 Subject: [PATCH 05/16] Add most basic README. --- README.txt | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 README.txt diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..48b36aa --- /dev/null +++ b/README.txt @@ -0,0 +1,41 @@ +Here you will find the first steps in a re-write of the PlomRogue +engine, plus the RogueChat example application. + +PlomRogue is an attempt at yet another roguelike engine. One of its +core principles is itsserver-client-architecture: the game happens on +a server that speaks the PlomRogue protocol, and can be connected to +with whatever client you come up with. + +RogueChat is an attempt at a multiplayer roguelike environment. Its most +obvious deviations from the roguelike standard are: +- practically non-turn-based (there actually is an internal turn system, + but it should in practice be invisible to players) +- so far a complete lack of combat, survival challenges, or any + pre-defined lore +- far-reaching ability to change the environment + +Python dependencies for the server and client are listed in +./requirements_server.txt and ./requirements_client.txt respectively. + +To run the RogueChat engine as TCP server on port 5000: +$ ./rogue_chat.py SAVEFILE --server-type tcp --port 5000 + +To /additionally/ run at is WebSocket server on port 8000: +$ ./rogue_chat.py SAVEFILE --server-type tcp ws --port 5000 --port 8000 + +SAVEFILE in the command line above will store commands to reconstruct +the game world from its last state after the server process was +killed. You can manipulate these commands to manipulate the game +world. + +To connect the example curses server to the TCP port of the server: +$ ./rogue_chat_curses.py 'localhost:5000' + +To connect the example curses server to the WebSocket port of the server: +$ ./rogue_chat_curses.py 'ws://localhost:8000/' + +The following automatically install the curses client's dependencies in a +Python virtual environment and runs the client against +'wss://plomlompom.com/rogue_chat/', where an example RogueChat server +runs. The same is targeted by ./rogue_chat.html, an example web browser +client that emulates the curses client via HTML and JavaScript. -- 2.30.2 From 1f65215b70d2a8a255aa9327497b88b94c4b1f17 Mon Sep 17 00:00:00 2001 From: Christian Heller Date: Wed, 25 Nov 2020 01:04:18 +0100 Subject: [PATCH 06/16] Put admin stuff into dedicated admin mode. --- plomrogue/commands.py | 1 + rogue_chat.html | 77 ++++++++++++++++++++++++++++++------------- rogue_chat_curses.py | 45 ++++++++++++++++++------- 3 files changed, 90 insertions(+), 33 deletions(-) diff --git a/plomrogue/commands.py b/plomrogue/commands.py index 41509df..c0470ba 100644 --- a/plomrogue/commands.py +++ b/plomrogue/commands.py @@ -98,6 +98,7 @@ def cmd_BECOME_ADMIN(game, password, connection_id): raise GameError('need to be logged in for this') if password in game.admin_passwords: game.sessions[connection_id]['status'] = 'admin' + game.io.send('ADMIN_OK', connection_id) else: raise GameError('wrong password') cmd_BECOME_ADMIN.argtypes = 'string' diff --git a/rogue_chat.html b/rogue_chat.html index 59d03a9..cf82cf9 100644 --- a/rogue_chat.html +++ b/rogue_chat.html @@ -42,33 +42,41 @@ terminal columns:
+ + + - + + - + +
+ + + + + - - - + - - +
+

edit keybindings

(see here for non-obvious available values):
@@ -93,7 +101,7 @@ terminal columns:
  • -
  • +
  • @@ -103,8 +111,8 @@ terminal columns: