| 42 | |
| 43 | |
| 44 | class RoverRequest: |
| 45 | ssl_verify = True |
| 46 | |
| 47 | def is_net(self, roleId): |
| 48 | _temp = int(roleId) |
| 49 | return _temp >= 200000000 |
| 50 | |
| 51 | def get_server_id( |
| 52 | self, |
| 53 | roleId: str, |
| 54 | serverId: Optional[str] = None, |
| 55 | game_id: int = WAVES_GAME_ID, |
| 56 | ) -> str: |
| 57 | if serverId: |
| 58 | return serverId |
| 59 | if game_id == WAVES_GAME_ID: |
| 60 | if self.is_net(roleId): |
| 61 | return SERVER_ID_NET |
| 62 | return SERVER_ID |
| 63 | return "" |
| 64 | |
| 65 | async def refresh_bat_token(self, waves_user: WavesUser): |
| 66 | success, access_token = await self.get_request_token( |
| 67 | waves_user.uid, |
| 68 | waves_user.cookie, |
| 69 | waves_user.did, |
| 70 | game_id=waves_user.game_id, |
| 71 | ) |
| 72 | if not success: |
| 73 | return waves_user |
| 74 | |
| 75 | waves_user.bat = access_token |
| 76 | await WavesUser.update_data_by_data( |
| 77 | select_data={ |
| 78 | "uid": waves_user.uid, |
| 79 | "game_id": waves_user.game_id, |
| 80 | }, |
| 81 | update_data={"bat": access_token}, |
| 82 | ) |
| 83 | return waves_user |
| 84 | |
| 85 | async def get_used_headers( |
| 86 | self, |
| 87 | cookie: str, |
| 88 | uid: str, |
| 89 | needToken: bool = False, |
| 90 | game_id: Optional[int] = WAVES_GAME_ID, |
| 91 | ) -> Dict[str, Any]: |
| 92 | headers = { |
| 93 | "did": "", |
| 94 | "b-at": "", |
| 95 | } |
| 96 | if needToken: |
| 97 | headers["token"] = cookie |
| 98 | waves_user: Optional[WavesUser] = await WavesUser.select_data_by_cookie_and_uid( |
| 99 | cookie=cookie, |
| 100 | uid=uid, |
| 101 | game_id=game_id, |