Exemplo n.º 1
0
    def __connecting_httpgetplayerstatusres(self, container):
        self.log.trace()

        self.__save_playerstatus(container.message)
        server_type = ApiInfo.detectServerType(
            self.__live["playerstatus"]["addr"])
        self.__live[server_type] = True

        result = self.send_message(
            UnitId.SOCKETCTRL, EventId.SOCKETCONNECTREQ,
            SocketConnectReq(addr=self.__live["playerstatus"]["addr"],
                             port=self.__live["playerstatus"]["port"]))

        self.__live["block_no"] = ApiInfo.calculateBlockNo(
            no=self.__live["chat"]["no"])
        data = ApiInfo.createGetpostkeyUrl(
            thread=self.__live["playerstatus"]["thread"],
            block_no=self.__live["block_no"])

        result = self.send_message(UnitId.HTTPCTRL, EventId.HTTPGETPOSTKEYREQ,
                                   data)

        self.__send_timerreq_heartbeatreq(live_id=self.__live["liveId"])

        self.state = self.__StateId.CONNECTING
        return True
Exemplo n.º 2
0
    def __chatsending_chatnotify(self, container):
        self.log.trace()

        result = self.send_message(UnitId.UNITCTRL, EventId.DATANOTIFY,
                                   container.message)

        self.__live["chat"]["no"] = container.message.attrs["no"]
        if self.__decide_whether_need_postkey(
                no=container.message.attrs["no"]):
            url = ApiInfo.createGetpostkeyUrl(
                thread=self.__live["playerstatus"]["thread"],
                block_no=self.__live["block_no"])

            result = self.send_message(UnitId.HTTPCTRL,
                                       EventId.HTTPGETPOSTKEYREQ, url)

        return True
Exemplo n.º 3
0
    def __chatsending_httpheartbeatres(self, container):
        self.log.trace()
        heartbeat = ApiInfo.parseHeartbeat(container.message)
        self.log.info("heartbeat: %s", heartbeat)

        self.__live["chat"]["no"] = heartbeat["comment_count"]
        if self.__decide_whether_need_postkey(no=heartbeat["comment_count"]):
            url = ApiInfo.createGetpostkeyUrl(
                thread=self.__live["playerstatus"]["thread"],
                block_no=self.__live["block_no"])

            result = self.send_message(UnitId.HTTPCTRL,
                                       EventId.HTTPGETPOSTKEYREQ, url)

        self.__send_timerreq_heartbeatreq(live_id=self.__live["liveId"],
                                          wait_time=heartbeat["wait_time"])

        self.state = self.__StateId.CHATSENDING
        return True
Exemplo n.º 4
0
    def __chatsending_chatresultnotify(self, container):
        self.log.trace()

        status = int(container.message.attrs["status"])
        if status == 0:
            self.__cleanupSendDataStore()

            result = self.send_message(UnitId.UNITCTRL, EventId.SENDCNF, None)

            data = self.__restoreSendDataStore()
            if data != None:
                chatTag = self.__create_chat_tag(data)

                result = self.send_message(
                    UnitId.SOCKETCTRL, EventId.SOCKETSENDREQ,
                    SocketSendReq(destination=self.__main_socket,
                                  data=chatTag))

                self.state = self.__StateId.CHATSENDING
                return True

            else:
                self.state = self.__StateId.IDLE
                return True

        elif status == 1:
            self.log.warning("chat_result fail[failure] (%s)",
                             container.message)

            self.__cleanupSendDataStore()

            self.state = self.__StateId.IDLE
            return True

        elif status == 2:
            self.log.warning("chat_result fail[thread id error] (%s)",
                             container.message)

            url = ApiInfo.createGetplayerstatusUrl(self.__live["liveId"])
            result = self.send_message(UnitId.HTTPCTRL,
                                       EventId.HTTPGETPLAYERSTATUSREQ, url)

            # TODO 再送処理は未実装
            # 状態をIDLEに戻す
            self.__cleanupSendDataStore()
            self.state = self.__StateId.IDLE
            return True

        elif status == 3:
            self.log.warning("chat_result fail[ticket error] (%s)",
                             container.message)

            threadTag = ApiInfo.createThreadTag(
                self.__live["playerstatus"]["thread"])
            result = self.send_message(
                UnitId.SOCKETCTRL, EventId.SOCKETSENDREQ,
                SocketSendReq(destination=self.__main_socket, data=threadTag))

            # TODO 再送処理は未実装
            # 状態をIDLEに戻す
            self.__cleanupSendDataStore()
            self.state = self.__StateId.IDLE
            return True

        elif status == 4:
            self.log.warning("chat_result fail[postkey error] (%s)",
                             container.message.attrs)

            self.__live["block_no"] = ApiInfo.calculateBlockNo(
                no=container.message.attrs["no"])
            url = ApiInfo.createGetpostkeyUrl(
                thread=self.__live["playerstatus"]["thread"],
                block_no=self.__live["block_no"])
            result = self.send_message(UnitId.HTTPCTRL,
                                       EventId.HTTPGETPOSTKEYREQ, url)

            self.state = self.__StateId.CHATSENDING
            return True

        elif status == 5:
            self.log.warning("chat_result fail[lock comment] (%s)",
                             container.message)

            self.__cleanupSendDataStore()

            self.state = self.__StateId.IDLE
            return True

        elif status == 8:
            self.log.warning("chat_result fail[long comment] (%s)",
                             container.message)

            self.__cleanupSendDataStore()

            self.state = self.__StateId.IDLE
            return True

        else:
            self.log.warning("chat_result fail[unknown error] (%s)",
                             container.message)

            self.__cleanupSendDataStore()

            self.state = self.__StateId.IDLE
            return True