Beispiel #1
0
class ClientHandler(rpc.RpcBroker):
    def __init__(self, server, ep, db):
        super().__init__()
        self._server = server
        self._ep = ep
        self._splitter = SplitterBuf()
        self._send_buf = pipe.SimpleBuf()
        self._db = db

        ep.cb = self._ep_cb

        ep.want_pull(True)
        ep.want_push(False)

        auth_client = rpcdef.AuthenticationClient.build_client_proxy()
        notification_client = rpcdef.NotificationListener.build_client_proxy()

        self.add_import(notification_client)

        auth_server = InsecureAuthenticationServer(
            client_handler=self,
            auth_client=self.add_import(auth_client),
            account_manager=AccountManager(self._db)
        )

        self.add_export(ConnectService())
        self.add_export(auth_server)
        self.add_export(FriendsServiceServer())
        self.add_export(ChannelInvitationServiceServer())
        self.add_export(ResourcesServiceServer())
        self.add_export(AccountServiceServer())
        self.add_export(PresenceServiceServer())
        self.add_export(GameUtilitiesServer(self))
        self.add_export(GameMasterServer(notification_client))

        # TODO: only create the services (except AuthenticationService) after login
        # and provide the account object via the service constructor
        self.account = None

    def send_data(self, buf):
        self._send_buf.append(buf)
        self._ep.want_push(True)

    def _ep_cb(self, ep, ev_type, ev_data):
        if ev_type == 'may_pull':
            self._ep.pull(self._splitter)
            while True:
                segment = self._splitter.pull_segment()
                if segment is None:
                    break
                self.handle_packet(segment[0], segment[1])
        elif ev_type == 'may_push':
            if self._send_buf.used > 0:
                self._ep.push(self._send_buf)
            self._ep.want_push(self._send_buf.used)
        elif ev_type == 'closed':
            self.logger.info('Connection closed')
Beispiel #2
0
    def __init__(self, server, ep, db):
        super().__init__()
        self._server = server
        self._ep = ep
        self._splitter = SplitterBuf()
        self._send_buf = pipe.SimpleBuf()
        self._db = db

        ep.cb = self._ep_cb

        ep.want_pull(True)
        ep.want_push(False)

        auth_client = rpcdef.AuthenticationClient.build_client_proxy()
        notification_client = rpcdef.NotificationListener.build_client_proxy()

        self.add_import(notification_client)

        auth_server = InsecureAuthenticationServer(
            client_handler=self,
            auth_client=self.add_import(auth_client),
            account_manager=AccountManager(self._db)
        )

        self.add_export(ConnectService())
        self.add_export(auth_server)
        self.add_export(FriendsServiceServer())
        self.add_export(ChannelInvitationServiceServer())
        self.add_export(ResourcesServiceServer())
        self.add_export(AccountServiceServer())
        self.add_export(PresenceServiceServer())
        self.add_export(GameUtilitiesServer(self))
        self.add_export(GameMasterServer(notification_client))

        # TODO: only create the services (except AuthenticationService) after login
        # and provide the account object via the service constructor
        self.account = None