geph5_misc_rpc/
client_control.rs1use std::time::SystemTime;
2
3use async_trait::async_trait;
4use geph5_broker_protocol::{AccountLevel, ExitDescriptor, NetStatus, VoucherInfo};
5use nanorpc::nanorpc_derive;
6use serde::{Deserialize, Serialize};
7
8#[derive(Serialize, Deserialize, Clone, Debug)]
9#[serde(tag = "state")]
10pub enum ConnInfo {
11 Disconnected,
12 Connecting,
13 Connected(ConnectedInfo),
14}
15
16#[derive(Serialize, Deserialize, Clone, Debug)]
17pub struct ConnectedInfo {
18 pub protocol: String,
19 pub bridge: String,
20
21 pub exit: ExitDescriptor,
22}
23
24#[derive(Serialize, Deserialize, Clone, Debug)]
25pub struct ControlUserInfo {
26 pub user_id: u64,
27 pub level: AccountLevel,
28
29 pub recurring: bool,
30 pub expiry: Option<u64>,
31}
32
33#[nanorpc_derive]
34#[async_trait]
35pub trait ControlProtocol {
36 async fn conn_info(&self) -> ConnInfo;
37 async fn stat_num(&self, stat: String) -> f64;
38 async fn start_time(&self) -> SystemTime;
39 async fn stop(&self);
40
41 async fn recent_logs(&self) -> Vec<String>;
42
43 async fn check_secret(&self, secret: String) -> Result<bool, String>;
46 async fn user_info(&self, secret: String) -> Result<ControlUserInfo, String>;
47 async fn start_registration(&self) -> Result<usize, String>;
48 async fn delete_account(&self, secret: String) -> Result<(), String>;
49 async fn poll_registration(&self, idx: usize) -> Result<RegistrationProgress, String>;
50 async fn convert_legacy_account(
51 &self,
52 username: String,
53 password: String,
54 ) -> Result<String, String>;
55 async fn stat_history(&self, stat: String) -> Result<Vec<f64>, String>;
56
57 async fn net_status(&self) -> Result<NetStatus, String>;
58 async fn latest_news(&self, lang: String) -> Result<Vec<NewsItem>, String>;
59 async fn price_points(&self) -> Result<Vec<(u32, f64)>, String>;
60 async fn basic_price_points(&self) -> Result<Vec<(u32, f64)>, String>;
61 async fn payment_methods(&self) -> Result<Vec<String>, String>;
62 async fn create_payment(
63 &self,
64 secret: String,
65 days: u32,
66 method: String,
67 ) -> Result<String, String>;
68 async fn create_basic_payment(
69 &self,
70 secret: String,
71 days: u32,
72 method: String,
73 ) -> Result<String, String>;
74 async fn get_free_voucher(&self, secret: String) -> Result<Option<VoucherInfo>, String>;
75 async fn redeem_voucher(&self, secret: String, code: String) -> Result<i32, String>;
76 async fn export_debug_pack(
77 &self,
78 email: Option<String>,
79 contents: String,
80 ) -> Result<(), String>;
81
82 async fn get_update_manifest(&self) -> Result<(serde_json::Value, String), String>;
83}
84
85#[derive(Serialize, Deserialize, Clone)]
86pub struct RegistrationProgress {
87 pub progress: f64,
88 pub secret: Option<String>,
89}
90
91#[derive(Serialize, Deserialize, Clone, Debug)]
92pub struct NewsItem {
93 pub title: String,
94 pub date_unix: u64,
95 pub contents: String,
96 pub important: bool,
97}