예제 #1
0
    def test_serialization(self):
        """Tests the JSON serialization method."""
        message = 'Hello, world.'
        time = timezone.now()

        info = ServerInfo(timestamp=time, team_msg=message)
        json_data = info.json()

        self.assertTrue('message' in json_data)
        self.assertEqual(json_data['message'], message)
        self.assertTrue('message_timestamp' in json_data)
        self.assertEqual(json_data['message_timestamp'], time.isoformat())
예제 #2
0
    def __init__(self):
        self.server_info = ServerInfo()
        self.demotime = 0.0
        self.frame_count = 0
        self.frame_info = FrameInfo()
        self.last_to = None
        self.last_type = None
        self.match_start_date = None
        self.match_start_demotime = None

        # Rumour has it that a DEM_SET message is supposed to appear
        # in the beginning of each(?) demo that sets these netchan
        # sequence numbers. Clearly this is not the case so to
        # not break things default values of 0 are added here.
        self.outgoing_netchan_sequence_number = 0
        self.incoming_netchan_sequence_number = 0

        self.big_coords_enabled = False
        self.protocol = constants.PROTOCOL_DEFAULT
        self.extension_flags_fte1 = None
        self.extension_flags_fte2 = None
        self.extension_flags_mvd = None
        self.sound_list = []
        self.model_list = []
        self.players = [Player() for i in range(32)]
예제 #3
0
    def getServerInfo(html):
        '''
        根据html获取代理服务器信息
        :param html: 获得的网页html
        :return: 服务器信息
        '''
        #通过正在匹配,定位免费服务器信息块
        patternFree = re.compile(
            r"<!-- Free SS Section -->(.*?)<!-- Provider list Section -->",
            re.S)
        shadowsocksSection = re.findall(patternFree, html)
        #print shadowsocksSection

        #通过正则,更加精确的找到免费服务器对应的div
        patternDiv = re.compile(
            r"<div class=\"col-sm-4 text-center\">(.*?)</div>", re.S)
        serverInfoDivs = re.findall(patternDiv, shadowsocksSection[0])
        #print serverInfoDivs

        itemList = []
        #遍历存在的三个服务器对象
        for serverInfoDiv in serverInfoDivs:
            #通过正则查找匹配的服务器每项信息
            patternServerInfoItems = re.compile(r"<h4>(.*?)</h4>", re.S)
            serverInfoItems = re.findall(patternServerInfoItems, serverInfoDiv)
            #print serverInfoItems

            itemList = []
            for si in serverInfoItems:
                item = si.split(":")
                #print item

                # 过滤没有:的项
                if len(item) < 2:
                    continue

                #获取的内容加入列表
                itemList.append(item[1])

            #如果密码不为空,找到了可用服务器信息
            if len(itemList[2]) != 0:
                break

        #组装代理服务器信息
        server = itemList[0]
        server_port = int(itemList[1])
        local_address = "127.0.0.1"
        local_port = 1080
        password = itemList[2]
        timeout = 300
        method = itemList[3]
        fast_open = True

        #实例化服务器信息类
        serverInfo = ServerInfo(server, server_port, local_address, local_port,
                                password, timeout, method, fast_open)

        return serverInfo
예제 #4
0
def run_server():
    default_ip = get_default_ip()

    parser = argparse.ArgumentParser(
        description='Serve a domsocket application.')
    parser.add_argument(
        '--server_ip',
        '-s',
        dest='server_ip',
        default=default_ip,
        help='the ip address where the zmq domsocket app is listening')
    parser.add_argument(
        '--zmq_bind_ip',
        '-i',
        dest='zmq_bind_ip',
        default='127.0.0.1',
        help='the ip address where the zmq domsocket app is listening')
    parser.add_argument('--server_port',
                        '-p',
                        dest='web_port',
                        default=8443,
                        help='the port for the web server to listen')
    parser.add_argument('--zmq_port',
                        '-z',
                        dest='zmq_port',
                        default=5555,
                        help='the port for the zmq backend to listen')
    parser.add_argument(
        '-v',
        '--verbose',
        dest='verbose',
        action='store_true',
        help=
        'Turn on message debugging (which makes the server seem less responsive'
    )

    args = parser.parse_args()
    app_websocket.parsed_args = args
    config_server_openssl(args.server_ip)

    WebSocketPlugin(cherrypy.engine).subscribe()
    cherrypy.tools.websocket = WebSocketTool()

    cherrypy.engine.subscribe('stop', shutdown)

    server_info = ServerInfo(args)
    backend = init_backend(args)
    backend.start()
    root_factory = RootFactory(server_info)
    root = root_factory.create_root()
    root_conf = root_factory.get_conf()

    try:
        cherrypy.quickstart(root, '/', config=root_conf)
    finally:
        logging.info('finally clause kicked out of cherrypy.quickstart')
예제 #5
0
    def from_configuration(cls, configuration: dict):
        servers = []
        for i, key in enumerate(configuration):
            server_config = configuration[key]
            first_id = i + 1
            second_id = 2 ** 31 + first_id
            description = server_config["description"]
            motd = server_config["motd"]
            try:
                ip = IPv4Address(socket.gethostbyname(server_config["ip"]))
                port = int(server_config["port"])

                server = ServerInfo(first_id, second_id, description, motd, ip, port)
                servers.append(server)
            except socket.gaierror:
                print('ERROR: Failed to get host by name. Check your internet connection')
                pass
        return ServerConfiguration(servers)
예제 #6
0
        message = message + ' '
    return message


def encrypt_message(plain_text, key):
    """
    Takes the plaintext and key and returns the DES encrypted ciphertext.
        -The DES algorithm is the one given by pycryptodome.
        -ECB mode is used.
    """
    cipher = DES.new(key, DES.MODE_ECB)
    cipher_text = cipher.encrypt(plain_text)
    return cipher_text


def decrypt_message(cipher_text, key):
    """
    Takes the ciphertext and key and returns the DES decrypted plaintext.
        -The DES algorithm is the one given by pycryptodome.
        -ECB mode is used.
    """
    cipher = DES.new(key, DES.MODE_ECB)
    plain_text = cipher.decrypt(cipher_text)
    return plain_text


if __name__ == '__main__':
    info = ServerInfo()
    info.read_key()
    connect_to_server(info)
예제 #7
0
    def test_unicode(self):
        """Tests the unicode method executes."""
        info = ServerInfo(timestamp=timezone.now(), team_msg='Test message.')
        info.save()

        info.__unicode__()