# 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
# 
# Path: cuwo/exceptions.py
# class InvalidData(Exception):
#     """
#     Raised when invalid data is received
#     """


from cuwo.script import ServerScript
from cuwo.exceptions import InvalidData
import zlib
import json
import asyncio
    def on_packet(self, data, addr):
        pass

    def send_packet(self, value, addr):
        if self.transport is None:
            return
        data = zlib.compress(json.dumps(value).encode('utf-8'))
        self.transport.sendto(data, addr)

    def on_bad_packet(self, addr):
        pass


class ServerData(object):
    location = None
    ip = None

    def __init__(self, data=None):
        if data is None:
            return
        try:
            self.name = data.pop('name')
            self.max = data.pop('max')
            self.players = data.pop('players')
            self.mode = data.pop('mode')
            self.ip = data.pop('ip', None)
        except KeyError:
            raise InvalidData()
        if data:
            # some data was left over

# 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
# 
# Path: cuwo/exceptions.py
# class InvalidData(Exception):
#     """
#     Raised when invalid data is received
#     """


# Path: scripts/master.py
from cuwo.script import ServerScript
from cuwo.exceptions import InvalidData
import zlib
import json
import asyncio

    def on_packet(self, data, addr):
        pass

    def send_packet(self, value, addr):
        if self.transport is None:
            return
        data = zlib.compress(json.dumps(value).encode('utf-8'))
        self.transport.sendto(data, addr)

    def on_bad_packet(self, addr):
        pass


class ServerData(object):
    location = None
    ip = None

    def __init__(self, data=None):
        if data is None:
            return
        try:
            self.name = data.pop('name')
            self.max = data.pop('max')
            self.players = data.pop('players')
            self.mode = data.pop('mode')
            self.ip = data.pop('ip', None)
        except KeyError:
            raise InvalidData()
        if data:
            # some data was left over

            raise InvalidData()