1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#[macro_use] extern crate lazy_static;
mod models;
use std::collections::HashMap;
use models::*;
use serde_json::Value;
use regex::Regex;
pub struct RoCheck {
cookie: String,
client: reqwest::Client
}
impl RoCheck {
pub fn new(cookie: &str) -> RoCheck {
let client = reqwest::Client::builder()
.build().expect("HttpClient failed to initialize");
RoCheck {
cookie: String::from(cookie),
client: client
}
}
pub async fn get_data(&self, place_id: i64, job_id: &str) -> Error<HashMap<String, serde_json::Value>> {
lazy_static! {
static ref SIG_REMOVAL: Regex = Regex::new("--.*\r\n").expect("Regex is invalid");
}
let init_data: HashMap<String, Value> = self.send_http(&format!("https://assetgame.roblox.com/Game/PlaceLauncher.ashx?request=RequestGameJob&placeId={}&gameId={}", place_id, job_id), Some(place_id)).await?.json().await?;
let join_url = init_data.get("joinScriptUrl").expect("joinScriptUrl does not exist");
if let Value::String(join_url) = join_url {
let game_resp = self.send_http(&join_url, None).await?.text().await?;
let game_data: HashMap<String, Value> = serde_json::from_str( SIG_REMOVAL.replace(&game_resp, "").as_ref() )?;
Ok(game_data)
} else {
Err(Box::new(RoError::Failure("Join URL is not there")))
}
}
pub async fn get_ip(&self, place_id: i64, job_id: &str) -> Error<String> {
let game_data = self.get_data(place_id, job_id).await?;
let machine_addr = game_data.get("MachineAddress").expect("MachineAddress does not exist");
Ok(machine_addr.as_str().unwrap().to_string())
}
pub async fn verify_ip(&self, place_id: i64, job_id: &str, ip: &str) -> Error<bool> {
let mach_ip = self.get_ip(place_id, job_id).await?;
Ok(mach_ip == ip)
}
pub async fn validate_ip(&self, place_id: i64, job_id: &str, ip: &str) -> bool {
let verified = self.verify_ip(place_id, job_id, ip).await;
if let Ok(verified) = verified {
verified
} else {
false
}
}
async fn send_http(&self, url: &str, place_info: Option<i64>) -> Error<reqwest::Response> {
let mut req = self.client.request(reqwest::Method::GET, url)
.header("Cookie", format!(".ROBLOSECURITY={}", self.cookie));
if let Some(placeid) = place_info {
req = req.header("Referer", format!("https://www.roblox.com/games/{}", placeid));
req = req.header("Origin", "https://www.roblox.com");
req = req.header("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36")
}
let req = req.build()?;
Ok(self.client.execute(req).await?)
}
}