# Path: cuwo/common.py
# def parse_command(message):
#     try:
#         args = shlex.split(message)
#     except ValueError:
#         # shlex failed. let's just split per space
#         args = message.split(' ')
#     if args:
#         command = args.pop(0)
#     else:
#         command = ''
#     return command, args
# 
# Path: cuwo/script.py
# class ServerScript(BaseScript):
#     connection_class = ConnectionScript
#     commands = None
#     aliases = None
# 
#     def __init__(self, server):
#         self.script_name = self.__module__.split('.')[1]
# 
#         self.server = server
#         self.world = server.world
#         self.loop = server.loop
#         server.scripts.add(self)
#         self.children = []
#         self.on_load()
#         for connection in server.connections:
#             self.call('on_existing_connection', connection=connection)
# 
#     def on_new_connection(self, event):
#         if self.connection_class is None:
#             return
#         script = self.connection_class(self, event.connection)
#         script.call('on_connect')
# 
#     def on_existing_connection(self, event):
#         if self.connection_class is None:
#             return
#         self.connection_class(self, event.connection)
# 
#     def on_command(self, event):
#         return self.call_command(event.user, event.command, event.args)
# 
#     def unload(self):
#         if self.server is None:
#             return
#         self.on_unload()
#         self.server.scripts.remove(self)
#         for script in self.children[:]:
#             script.unload()
#         self.children = None
#         self.server = None
#         self.world = None
# 
#     def call_command(self, user, command, args):
#         if self.commands is None:
#             return
#         command = command.lower()
#         command = self.aliases.get(command, command)
#         command = self.commands.get(command, None)
#         if not command:
#             return
#         user.parent = self  # for ScriptInterface
# 
#         if len(args) < command.min_args:
#             return command.get_syntax()
#         if command.max_args is not None and len(args) > command.max_args:
#             return command.get_syntax()
# 
#         try:
#             ret = command(user, *args) or ''
#         except InvalidPlayer:
#             ret = 'Invalid player specified'
#         except InsufficientRights:
#             ret = 'Insufficient rights'
#         except Exception:
#             import traceback
#             traceback.print_exc()
#             ret = ''
#         return ret
# 
# class ScriptInterface:
#     """
#     Used for external script interfaces to emulate a connection for e.g.
#     console and IRC commands
#     """
# 
#     def __init__(self, name, server, *rights):
#         self.name = name
#         self.rights = AttributeSet(rights)
#         self.server = server
#         self.connection = self
#         self.parent = None  # set by call_command
# 
#     def get_player(self, name):
#         if name is None:
#             raise InvalidPlayer()
#         return get_player(self.server, name)
# 
#     def get_commands(self):
#         return self.server.get_commands()
# 
#     def get_command(self, name):
#         return self.server.get_command(name)


import sys
import asyncio
    import msvcrt
from cuwo.common import parse_command
from cuwo.script import ServerScript, ScriptInterface
                    stdout.flush()
            yield from asyncio.sleep(0.04)
        return current

else:
    reader = None

    @asyncio.coroutine
    def get_stdin():
        loop = asyncio.get_event_loop()
        reader = asyncio.StreamReader()
        reader_protocol = asyncio.StreamReaderProtocol(reader)
        yield from loop.connect_read_pipe(lambda: reader_protocol, sys.stdin)
        return reader

    @asyncio.coroutine
    def async_stdin():
        global reader
        if reader is None:
            reader = yield from get_stdin()
        line = yield from reader.readline()
        return line.decode('utf8')


class ConsoleServer(ServerScript):
    connection_class = None

    def on_load(self):
        if not stdout.isatty():
            return

# Path: cuwo/common.py
# def parse_command(message):
#     try:
#         args = shlex.split(message)
#     except ValueError:
#         # shlex failed. let's just split per space
#         args = message.split(' ')
#     if args:
#         command = args.pop(0)
#     else:
#         command = ''
#     return command, args
# 
# Path: cuwo/script.py
# class ServerScript(BaseScript):
#     connection_class = ConnectionScript
#     commands = None
#     aliases = None
# 
#     def __init__(self, server):
#         self.script_name = self.__module__.split('.')[1]
# 
#         self.server = server
#         self.world = server.world
#         self.loop = server.loop
#         server.scripts.add(self)
#         self.children = []
#         self.on_load()
#         for connection in server.connections:
#             self.call('on_existing_connection', connection=connection)
# 
#     def on_new_connection(self, event):
#         if self.connection_class is None:
#             return
#         script = self.connection_class(self, event.connection)
#         script.call('on_connect')
# 
#     def on_existing_connection(self, event):
#         if self.connection_class is None:
#             return
#         self.connection_class(self, event.connection)
# 
#     def on_command(self, event):
#         return self.call_command(event.user, event.command, event.args)
# 
#     def unload(self):
#         if self.server is None:
#             return
#         self.on_unload()
#         self.server.scripts.remove(self)
#         for script in self.children[:]:
#             script.unload()
#         self.children = None
#         self.server = None
#         self.world = None
# 
#     def call_command(self, user, command, args):
#         if self.commands is None:
#             return
#         command = command.lower()
#         command = self.aliases.get(command, command)
#         command = self.commands.get(command, None)
#         if not command:
#             return
#         user.parent = self  # for ScriptInterface
# 
#         if len(args) < command.min_args:
#             return command.get_syntax()
#         if command.max_args is not None and len(args) > command.max_args:
#             return command.get_syntax()
# 
#         try:
#             ret = command(user, *args) or ''
#         except InvalidPlayer:
#             ret = 'Invalid player specified'
#         except InsufficientRights:
#             ret = 'Insufficient rights'
#         except Exception:
#             import traceback
#             traceback.print_exc()
#             ret = ''
#         return ret
# 
# class ScriptInterface:
#     """
#     Used for external script interfaces to emulate a connection for e.g.
#     console and IRC commands
#     """
# 
#     def __init__(self, name, server, *rights):
#         self.name = name
#         self.rights = AttributeSet(rights)
#         self.server = server
#         self.connection = self
#         self.parent = None  # set by call_command
# 
#     def get_player(self, name):
#         if name is None:
#             raise InvalidPlayer()
#         return get_player(self.server, name)
# 
#     def get_commands(self):
#         return self.server.get_commands()
# 
#     def get_command(self, name):
#         return self.server.get_command(name)


# Path: scripts/console.py
import sys
import asyncio
    import msvcrt
from cuwo.common import parse_command
from cuwo.script import ServerScript, ScriptInterface

                    stdout.flush()
            yield from asyncio.sleep(0.04)
        return current

else:
    reader = None

    @asyncio.coroutine
    def get_stdin():
        loop = asyncio.get_event_loop()
        reader = asyncio.StreamReader()
        reader_protocol = asyncio.StreamReaderProtocol(reader)
        yield from loop.connect_read_pipe(lambda: reader_protocol, sys.stdin)
        return reader

    @asyncio.coroutine
    def async_stdin():
        global reader
        if reader is None:
            reader = yield from get_stdin()
        line = yield from reader.readline()
        return line.decode('utf8')


class ConsoleServer(ServerScript):
    connection_class = None

    def on_load(self):
        if not stdout.isatty():
            return

        self.interface = ScriptInterface('Console', self.server, 'admin',