mc5-api-client 1.0.15__py3-none-any.whl → 1.0.17__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,198 @@
1
+ #!/usr/bin/env python3
2
+ # ────────────[ CHIZOBA ]────────────────────────────
3
+ # | Email : chizoba2026@hotmail.com
4
+ # | File : federation_quick.py
5
+ # | License | MIT License © 2026 Chizoba
6
+ # | Brief | Quick functions for federation and session management
7
+ # ────────────────★─────────────────────────────────
8
+
9
+ from typing import Optional, Dict, Any, List
10
+ from .simple_client import SimpleMC5Client
11
+ from .telemetry import report_usage
12
+ from .debug import debug_function, debug_print
13
+
14
+ @debug_function
15
+ def quick_get_active_sessions(username: str, password: str, credentials: Optional[List[str]] = None) -> Optional[Dict[str, Any]]:
16
+ """
17
+ Quick function to get active game sessions.
18
+
19
+ Args:
20
+ username: MC5 username
21
+ password: MC5 password
22
+ credentials: Optional list of user credentials to filter by
23
+
24
+ Returns:
25
+ Session information or None if failed
26
+ """
27
+ try:
28
+ with SimpleMC5Client(username, password) as client:
29
+ if client.connect():
30
+ sessions = client.client.get_active_sessions(credentials)
31
+ debug_print(f"✅ Retrieved {sessions.get('total_count', 0)} active sessions", "success")
32
+ return sessions
33
+ return None
34
+ except Exception as e:
35
+ debug_print(f"❌ Failed to get active sessions: {e}", "error")
36
+ return None
37
+
38
+ @debug_function
39
+ def quick_get_my_sessions(username: str, password: str) -> Optional[Dict[str, Any]]:
40
+ """
41
+ Quick function to get current user's sessions.
42
+
43
+ Args:
44
+ username: MC5 username
45
+ password: MC5 password
46
+
47
+ Returns:
48
+ User's sessions or None if failed
49
+ """
50
+ try:
51
+ with SimpleMC5Client(username, password) as client:
52
+ if client.connect():
53
+ sessions = client.client.get_my_sessions()
54
+ debug_print(f"✅ Retrieved {sessions.get('total_count', 0)} user sessions", "success")
55
+ return sessions
56
+ return None
57
+ except Exception as e:
58
+ debug_print(f"❌ Failed to get user sessions: {e}", "error")
59
+ return None
60
+
61
+ @debug_function
62
+ def quick_get_session_statistics(username: str, password: str) -> Optional[Dict[str, Any]]:
63
+ """
64
+ Quick function to get session statistics.
65
+
66
+ Args:
67
+ username: MC5 username
68
+ password: MC5 password
69
+
70
+ Returns:
71
+ Session statistics or None if failed
72
+ """
73
+ try:
74
+ with SimpleMC5Client(username, password) as client:
75
+ if client.connect():
76
+ stats = client.client.get_session_statistics()
77
+ debug_print(f"✅ Session statistics analyzed: {stats.get('total_sessions', 0)} sessions", "success")
78
+ return stats
79
+ return None
80
+ except Exception as e:
81
+ debug_print(f"❌ Failed to get session statistics: {e}", "error")
82
+ return None
83
+
84
+ @debug_function
85
+ def quick_check_session_status(username: str, password: str, fed_id: str) -> Optional[Dict[str, Any]]:
86
+ """
87
+ Quick function to check status of a specific session.
88
+
89
+ Args:
90
+ username: MC5 username
91
+ password: MC5 password
92
+ fed_id: Federation ID to check
93
+
94
+ Returns:
95
+ Session status or None if failed
96
+ """
97
+ try:
98
+ with SimpleMC5Client(username, password) as client:
99
+ if client.connect():
100
+ status = client.client.check_session_status(fed_id)
101
+ if status.get("found"):
102
+ debug_print(f"✅ Session found: {status.get('status')}", "success")
103
+ else:
104
+ debug_print(f"⚠️ Session not found", "warning")
105
+ return status
106
+ return None
107
+ except Exception as e:
108
+ debug_print(f"❌ Failed to check session status: {e}", "error")
109
+ return None
110
+
111
+ @debug_function
112
+ def quick_get_server_type_sessions(username: str, password: str, server_type: str) -> Optional[Dict[str, Any]]:
113
+ """
114
+ Quick function to get sessions by server type.
115
+
116
+ Args:
117
+ username: MC5 username
118
+ password: MC5 password
119
+ server_type: Server type (ts, mp_server, etc.)
120
+
121
+ Returns:
122
+ Filtered sessions or None if failed
123
+ """
124
+ try:
125
+ with SimpleMC5Client(username, password) as client:
126
+ if client.connect():
127
+ sessions = client.client.get_server_type_sessions(server_type)
128
+ debug_print(f"✅ Found {sessions.get('total_count', 0)} {server_type} sessions", "success")
129
+ return sessions
130
+ return None
131
+ except Exception as e:
132
+ debug_print(f"❌ Failed to get {server_type} sessions: {e}", "error")
133
+ return None
134
+
135
+ @debug_function
136
+ def quick_analyze_session_activity(username: str, password: str) -> Optional[Dict[str, Any]]:
137
+ """
138
+ Quick function to analyze overall session activity.
139
+
140
+ Args:
141
+ username: MC5 username
142
+ password: MC5 password
143
+
144
+ Returns:
145
+ Activity analysis or None if failed
146
+ """
147
+ try:
148
+ with SimpleMC5Client(username, password) as client:
149
+ if client.connect():
150
+ # Get all sessions
151
+ all_sessions = client.client.get_active_sessions()
152
+ sessions = all_sessions.get("sessions", [])
153
+
154
+ if not sessions:
155
+ return {"error": "No sessions found"}
156
+
157
+ # Analyze activity patterns
158
+ total_sessions = len(sessions)
159
+
160
+ # Server type analysis
161
+ server_analysis = {}
162
+ country_analysis = {}
163
+
164
+ for session in sessions:
165
+ owner_info = session.get("owner_info", {})
166
+
167
+ # Server types
168
+ server_type = owner_info.get("server_type", "unknown")
169
+ server_analysis[server_type] = server_analysis.get(server_type, 0) + 1
170
+
171
+ # Countries
172
+ country = owner_info.get("country", "unknown")
173
+ country_analysis[country] = country_analysis.get(country, 0) + 1
174
+
175
+ # Find most active server type
176
+ most_active_server = max(server_analysis.items(), key=lambda x: x[1]) if server_analysis else ("unknown", 0)
177
+
178
+ # Find most active country
179
+ most_active_country = max(country_analysis.items(), key=lambda x: x[1]) if country_analysis else ("unknown", 0)
180
+
181
+ analysis = {
182
+ "total_sessions": total_sessions,
183
+ "server_type_distribution": server_analysis,
184
+ "country_distribution": country_analysis,
185
+ "most_active_server_type": most_active_server[0],
186
+ "most_active_server_count": most_active_server[1],
187
+ "most_active_country": most_active_country[0],
188
+ "most_active_country_count": most_active_country[1],
189
+ "analysis_timestamp": __import__('datetime').datetime.now().isoformat()
190
+ }
191
+
192
+ debug_print(f"✅ Activity analysis complete: {total_sessions} sessions", "success")
193
+ return analysis
194
+
195
+ return None
196
+ except Exception as e:
197
+ debug_print(f"❌ Failed to analyze session activity: {e}", "error")
198
+ return None
@@ -0,0 +1,109 @@
1
+ #!/usr/bin/env python3
2
+ # ────────────[ KAKUZU ]────────────────────────────
3
+ # | Discord : kakuzu_f0
4
+ # | Telegram : kakuzu_f0
5
+ # | File : platform.py
6
+ # | License : MIT License © 2026 Kakuzu
7
+ # | Brief : Platform support for MC5 API Client (PC & Android)
8
+ # ────────────────★─────────────────────────────────
9
+
10
+ from enum import Enum
11
+ from typing import Dict, Any, Optional
12
+ import random
13
+ import string
14
+
15
+ class Platform(Enum):
16
+ """Supported platforms for MC5 API."""
17
+ PC = "pc"
18
+ ANDROID = "android"
19
+
20
+ class PlatformConfig:
21
+ """Configuration for different platforms."""
22
+
23
+ def __init__(self, platform: Platform):
24
+ self.platform = platform
25
+ self._config = self._get_platform_config()
26
+
27
+ def _get_platform_config(self) -> Dict[str, Any]:
28
+ """Get platform-specific configuration."""
29
+ configs = {
30
+ Platform.PC: {
31
+ "client_id": "1924:56128:6.0.6a:pc:steam",
32
+ "device_model": "Windows PC",
33
+ "device_resolution": "1920x1080",
34
+ "device_country": "US",
35
+ "device_language": "en",
36
+ "user_agent": "MC5-PC-Client/1.0.16",
37
+ "platform_id": "pc"
38
+ },
39
+ Platform.ANDROID: {
40
+ "client_id": "1924:56128:6.0.6a:android:googleplay",
41
+ "device_model": "SM-S931B", # Samsung Galaxy S23 Ultra
42
+ "device_resolution": "2340x1080",
43
+ "device_country": "FR",
44
+ "device_language": "en",
45
+ "user_agent": "MC5-Android-Client/1.0.16",
46
+ "platform_id": "android"
47
+ }
48
+ }
49
+ return configs.get(self.platform, configs[Platform.PC])
50
+
51
+ def get_client_id(self) -> str:
52
+ """Get platform-specific client ID."""
53
+ return self._config["client_id"]
54
+
55
+ def get_device_info(self) -> Dict[str, str]:
56
+ """Get platform-specific device information."""
57
+ return {
58
+ "device_model": self._config["device_model"],
59
+ "device_resolution": self._config["device_resolution"],
60
+ "device_country": self._config["device_country"],
61
+ "device_language": self._config["device_language"]
62
+ }
63
+
64
+ def get_user_agent(self) -> str:
65
+ """Get platform-specific user agent."""
66
+ return self._config["user_agent"]
67
+
68
+ def get_platform_id(self) -> str:
69
+ """Get platform identifier."""
70
+ return self._config["platform_id"]
71
+
72
+ def generate_device_id(self) -> str:
73
+ """Generate a platform-appropriate device ID."""
74
+ if self.platform == Platform.PC:
75
+ # PC: Generate a 16-digit numeric device ID
76
+ return ''.join(random.choices(string.digits, k=16))
77
+ else:
78
+ # Android: Generate a longer device ID (like Android device IDs)
79
+ return ''.join(random.choices(string.digits, k=19))
80
+
81
+ def generate_android_credential(self) -> str:
82
+ """Generate Android-specific anonymous credential."""
83
+ # Android anonymous credential format: android_v2_ANMP.GloftM5HM_<encoded_data>
84
+ base_data = f"android_v2_ANMP.GloftM5HM_{random.randint(1000000000, 9999999999)}"
85
+ # Simple encoding simulation (in real implementation, this would be proper base64)
86
+ encoded = base_data.replace("ANMP", "QU5NUA==").replace("GloftM5HM", "R2xvZnRNNUhN")
87
+ return encoded
88
+
89
+ def get_platform_config(platform: Platform = Platform.PC) -> PlatformConfig:
90
+ """Get platform configuration."""
91
+ return PlatformConfig(platform)
92
+
93
+ def detect_platform_from_client_id(client_id: str) -> Platform:
94
+ """Detect platform from client ID."""
95
+ if "android" in client_id.lower():
96
+ return Platform.ANDROID
97
+ elif "pc" in client_id.lower() or "steam" in client_id.lower():
98
+ return Platform.PC
99
+ else:
100
+ return Platform.PC # Default to PC
101
+
102
+ def get_android_anonymous_credential() -> str:
103
+ """Generate Android anonymous credential."""
104
+ config = get_platform_config(Platform.ANDROID)
105
+ return config.generate_android_credential()
106
+
107
+ def get_pc_anonymous_credential() -> str:
108
+ """Generate PC anonymous credential."""
109
+ return f"win8_v2_{random.randint(100000000, 999999999)}_{random.choices(string.ascii_letters + string.digits, k=20)}"