Skip to content

Commit

Permalink
Added a chat module which can be used to communicate with all other p…
Browse files Browse the repository at this point in the history
…layers in the game, or with an individual player privately.
  • Loading branch information
ecdavis committed Aug 20, 2016
1 parent 7f2a523 commit 97a2ca4
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions spacegame/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import spacegame.core
import spacegame.modules

def init():
spacegame.core.init()
spacegame.modules.init()
5 changes: 5 additions & 0 deletions spacegame/modules/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from spacegame.modules import chat


def init():
chat.init()
33 changes: 33 additions & 0 deletions spacegame/modules/chat.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from pantsmud.driver import parser

from spacegame.core import command_manager


def chat_global_command(mobile, _, args):
params = parser.parse([("message", parser.STRING)], args)
universe = mobile.universe
for m in (universe.mobiles[u] for u in universe.mobiles):
m.message("chat.global", {"mobile_from": mobile.name, "message": params["message"]})


def chat_private_command(mobile, _, args):
params = parser.parse([("mobile_name", parser.WORD), ("message", parser.STRING)], args)
target = mobile.universe.get_mobile(params["mobile_name"])
if not target:
mobile.message("chat.private.fail") # TODO Add error message.
return
if target is mobile:
mobile.message("chat.private.fail") # TODO Add error message.
return
data = {
"mobile_from": mobile.name,
"mobile_to": target.name,
"message": params["message"]
}
target.message("chat.private", data)
mobile.message("chat.private", data)


def init():
command_manager.add_command("chat.global", chat_global_command)
command_manager.add_command("chat.private", chat_private_command)

0 comments on commit 97a2ca4

Please sign in to comment.