#!/usr/bin/env python # coding: utf-8 """ Main module of Chatwisted to start either a client gui or a standalone server """ """ Protocol Specification ========================= Server Commands (what a client can send to the server) -------------------------------------------------------------------- simple text will be broadcasted to all other clients with a "[author] says:" before Commands .......... Commandsyntax: "/[command] [*args] there are some command levels, ie commands of level 2 are subcommands of level 1 say say something (same as sending [*args] direktly without /say) me do something (broadcasts a "[client] [*args]") help sends a pn with a help text nick if not argument is given, the clients nick will be returned. If an argument is given, the nick will be changed to this (if possible) list sends a pn with a list of all clients :todo: improve handling of exceptions and lost connections :todo: cleaner interface ClientFactory->GUI :todo: pygame gui (spg/epg?) """ import sys, os sys.path.insert(0, os.path.abspath("..")) from optparse import OptionParser from chatwisted.plugins import load_plugins, PLUGINS load_plugins() from chatwisted.server import start_standalone_server from chatwisted.client import ChatClientFactory from twisted.internet import reactor import chatwisted def main(): """ main method to run the program subject to given arguments """ about = """ Chatwisted network environment by Julian Habrock more information at juggernaut.bytemuehle.de """ usage = """main.py [options]""" parser = parser = OptionParser(usage) parser.add_option("-s", "--standalone-server", action="store_const", const="server", dest="mode", help="start a standalone server without gui") parser.add_option("-t", "--tkinter", action="store_const", const="tk", dest="mode", help="start a client with a Tkinter gui") parser.add_option("-p", "--pygame", action="store_const", const="pygame", dest="mode", help="start a client with a pygame gui") parser.add_option("-v", action="count", dest="verbosity") parser.set_defaults(mode="tk") parser.set_defaults(verbosity=0) options, args = parser.parse_args() chatwisted.DEBUG = options.verbosity if options.mode: print "got mode", options.mode if options.mode == "server": print "starting standalone server" start_standalone_server() elif options.mode == "pygame": #options.mode = "tk" try: print "pygame gui only for developers and testers" from pygame_gui import PyGameGui PyGameGui(ChatClientFactory()) except ImportError, err: print "Failed to start pygame client:", err print "fallback to tk" options.mode = "tk" elif options.mode == "tk": try: print "starting tk client gui..." from chatwisted.tk_gui import TkGui TkGui(ChatClientFactory()) except ImportError, err: print "Failed to start tk client:", err else: parser.print_help() reactor.run() else: parser.print_help() if __name__ == "__main__": main()