You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
match s.write_all(format!("\n{}\n", e).as_bytes()){
107
+
Ok(_) => (),
108
+
Err(e) => println!("Failed to send: {e}"),
109
+
};
108
110
}
109
-
s.shutdown(Shutdown::Both).expect("Failed to shutdown");
111
+
match s.shutdown(Shutdown::Both){
112
+
Ok(_) => (),
113
+
Err(e) => println!("Failed to shutdown: {e}"),
114
+
};
110
115
continue;
111
116
}
112
117
};
113
118
114
119
// Set read timeout
115
-
s.set_read_timeout(Some(Duration::new(0,1)))
116
-
.expect("Unable to set read tiemout");
120
+
match s.set_read_timeout(Some(Duration::new(0,1))){
121
+
Ok(_) => (),
122
+
Err(e) => {
123
+
println!("Unable to set read tiemout: {e}");
124
+
continue;
125
+
}
126
+
};
117
127
118
128
let updates = vec![format!("\nLogged in as: 0x{:016x}\n\nAvailable commands:\n'c'<enter>\tPurchase Cps with idlecoin\n'm'<enter>\tPurchase a new miner license\n\nCommand:\n", miner.wallet_id).to_owned()];
119
129
let conn = Connection{
@@ -164,7 +174,16 @@ fn login(
164
174
165
175
// Read userid
166
176
letmut id_raw:[u8;1024] = [0;1024];
167
-
let _ = stream.read(&mut id_raw[..])?;
177
+
178
+
// Only read 0-1023 to have the end NULL so we can safely do the
179
+
// \r\n => \n\0 conversion
180
+
let len = stream.read(&mut id_raw[..1023])?;
181
+
for i in0..len {
182
+
if id_raw[i] == b'\r' && id_raw[i + 1] == b'\n'{
183
+
id_raw[i] = b'\n';
184
+
id_raw[i + 1] = 0x0;
185
+
}
186
+
}
168
187
169
188
// Calculate the hash of the wallet_id
170
189
letmut hash = xxh3::Xxh3::new();
@@ -266,7 +285,7 @@ fn read_inputs(
266
285
letmut wals = wallets.lock().unwrap();
267
286
for w in wals.iter_mut(){
268
287
if w.id == c.miner.wallet_id{
269
-
if w.idlecoin < 1024{
288
+
if w.idlecoin < 1024&& w.supercoin < 1{
270
289
c.updates.push(
271
290
"You need at least 1024 idlecoin to be able to purchase Cps\n"
272
291
.to_string(),
@@ -286,7 +305,10 @@ fn read_inputs(
286
305
0,
287
306
format!(
288
307
" [{}] Miner 0x{:08x} bought {} Cps with {} idlecoin\n",
289
-
t, c.miner.miner_id, cps, cost
308
+
t.format("%Y-%m-%d %H:%M:%S"),
309
+
c.miner.miner_id,
310
+
cps,
311
+
cost
290
312
),
291
313
);
292
314
sub_idlecoins(w, cost);
@@ -306,9 +328,9 @@ fn read_inputs(
306
328
continue;
307
329
}
308
330
let cost = u64::MAX / (100000 >> (w.max_miners - 5));
309
-
if w.idlecoin > cost {
331
+
if w.idlecoin > cost || w.supercoin > 0{
310
332
let t:DateTime<Local> = Local::now();
311
-
msg.insert(0,format!(" [{}] Wallet 0x{:016x} bought a new miner license with {} idlecoin\n", t, c.miner.wallet_id, cost));
333
+
msg.insert(0,format!(" [{}] Wallet 0x{:016x} bought a new miner license with {} idlecoin\n", t.format("%Y-%m-%d %H:%M:%S"), c.miner.wallet_id, cost));
0 commit comments