Skip to content

Commit d29fe8d

Browse files
authored
Merge pull request #52 from genonullfree/fix/multiple-issues
Fix/multiple issues
2 parents 8ac82fb + dcefa10 commit d29fe8d

File tree

4 files changed

+74
-36
lines changed

4 files changed

+74
-36
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "idlecoin"
3-
version = "0.3.3"
3+
version = "0.3.4"
44
edition = "2021"
55

66
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ The stats are written out to a file `.idlecoin` in the working directory of the
4040
[+] Miner 0x2c37118e Cps: 546 Level: 3
4141
4242
Events:
43-
[!] Miner 0x91e5e95a gained 50% CPS boost
43+
[!] Miner 0x91e5e95a gained 10% CPS boost
4444
[!] Miner 0x2c37118e leveled up
45-
[!] Miner 0xedadbfe7 gained 50% CPS boost
46-
[!] Miner 0x2c37118e gained 50% CPS boost
47-
[!] Miner 0x2c37118e gained 50% CPS boost
45+
[!] Miner 0xedadbfe7 gained 10% CPS boost
46+
[!] Miner 0x2c37118e gained 10% CPS boost
47+
[!] Miner 0x2c37118e gained 10% CPS boost
4848
4949
Logged in as: 0x7d3ce1ed74b2c05f%
5050
```
@@ -77,20 +77,20 @@ Each wallet supports at least 5 miners.
7777

7878
```
7979
Events:
80-
[!] Miner 0x91e5e95a gained 50% CPS boost
80+
[!] Miner 0x91e5e95a gained 10% CPS boost
8181
[!] Miner 0x2c37118e leveled up
82-
[!] Miner 0xedadbfe7 gained 50% CPS boost
83-
[!] Miner 0x2c37118e gained 50% CPS boost
84-
[!] Miner 0x2c37118e gained 50% CPS boost
82+
[!] Miner 0xedadbfe7 gained 10% CPS boost
83+
[!] Miner 0x2c37118e gained 10% CPS boost
84+
[!] Miner 0x2c37118e gained 10% CPS boost
8585
```
8686

8787
These events are newest on top, and only the most recent 5 are displayed.
8888

8989
These events are special random events that can happen:
9090

91-
1. Gain 10% CPS -- 0.1% chance
92-
1. Gain 1 Level -- 0.5% chance
93-
1. Lose 1 Level -- 0.1% chance
91+
1. Gain 10% CPS -- 0.01% chance
92+
1. Gain 1 Level -- 0.02% chance
93+
1. Lose 1 Level -- 0.01% chance
9494

9595

9696
## Auto-Login
@@ -100,5 +100,7 @@ To setup your terminal to auto-login in case the connection with the server is i
100100
while true; do echo <USER> |nc <SERVER> <PORT>; done
101101
```
102102

103+
*NOTE*: When logging in this way you will be unable to purchase upgrades with this miner. STDIN is not routed through `nc`.
104+
103105
When that happens the miner level and CPS will be reset to 0, just like starting a new connection.
104106

src/main.rs

Lines changed: 59 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,27 @@ fn main() -> Result<(), Error> {
103103
Ok(m) => m,
104104
Err(e) => {
105105
if e.kind() == ErrorKind::ConnectionRefused {
106-
s.write_all(format!("\n{}\n", e).as_bytes())
107-
.expect("Failed to send");
106+
match s.write_all(format!("\n{}\n", e).as_bytes()) {
107+
Ok(_) => (),
108+
Err(e) => println!("Failed to send: {e}"),
109+
};
108110
}
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+
};
110115
continue;
111116
}
112117
};
113118

114119
// 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+
};
117127

118128
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()];
119129
let conn = Connection {
@@ -164,7 +174,16 @@ fn login(
164174

165175
// Read userid
166176
let mut 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 in 0..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+
}
168187

169188
// Calculate the hash of the wallet_id
170189
let mut hash = xxh3::Xxh3::new();
@@ -266,7 +285,7 @@ fn read_inputs(
266285
let mut wals = wallets.lock().unwrap();
267286
for w in wals.iter_mut() {
268287
if w.id == c.miner.wallet_id {
269-
if w.idlecoin < 1024 {
288+
if w.idlecoin < 1024 && w.supercoin < 1 {
270289
c.updates.push(
271290
"You need at least 1024 idlecoin to be able to purchase Cps\n"
272291
.to_string(),
@@ -286,7 +305,10 @@ fn read_inputs(
286305
0,
287306
format!(
288307
" [{}] 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
290312
),
291313
);
292314
sub_idlecoins(w, cost);
@@ -306,9 +328,9 @@ fn read_inputs(
306328
continue;
307329
}
308330
let cost = u64::MAX / (100000 >> (w.max_miners - 5));
309-
if w.idlecoin > cost {
331+
if w.idlecoin > cost || w.supercoin > 0 {
310332
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));
312334
sub_idlecoins(w, cost);
313335
w.max_miners += 1;
314336
} else {
@@ -338,24 +360,28 @@ fn print_wallets(
338360
gens.sort_by(|a, b| a.supercoin.cmp(&b.supercoin));
339361

340362
for (i, g) in gens.iter().enumerate() {
341-
let wal = &format!(
342-
"[{:03}] Wallet 0x{:016x} Coins: {}:{}\n",
343-
gens.len() - i,
344-
g.id,
345-
g.supercoin,
346-
g.idlecoin,
347-
)
348-
.to_owned();
349363
let mut min: String = "".to_string();
364+
let mut total_cps = 0u128;
350365
for c in cons.iter() {
351366
if c.miner.wallet_id == g.id {
352367
min += &format!(
353368
" [+] Miner 0x{:08x} Cps: {} Level: {}\n",
354369
c.miner.miner_id, c.miner.cps, c.miner.level,
355370
)
356371
.to_owned();
372+
total_cps += c.miner.cps as u128;
357373
}
358374
}
375+
let wal = &format!(
376+
"[{:03}] Wallet 0x{:016x} Coins: {}:{} Miner Licenses: {} Total Cps: {}\n",
377+
gens.len() - i,
378+
g.id,
379+
g.supercoin,
380+
g.idlecoin,
381+
g.max_miners,
382+
total_cps,
383+
)
384+
.to_owned();
359385
if !min.is_empty() {
360386
msg += wal;
361387
msg += &min;
@@ -438,7 +464,8 @@ fn action_miners(
438464
0,
439465
format!(
440466
" [{}] Wallet 0x{:016x} was taxed 10% by the IRS!\n",
441-
t, c.miner.miner_id
467+
t.format("%Y-%m-%d %H:%M:%S"),
468+
c.miner.miner_id
442469
),
443470
);
444471
}
@@ -451,7 +478,11 @@ fn action_miners(
451478
if level != c.miner.level {
452479
msg.insert(
453480
0,
454-
format!(" [{}] Miner 0x{:08x} lost a level\n", t, c.miner.miner_id),
481+
format!(
482+
" [{}] Miner 0x{:08x} lost a level\n",
483+
t.format("%Y-%m-%d %H:%M:%S"),
484+
c.miner.miner_id
485+
),
455486
);
456487
}
457488
} else if x % 10000 <= 2 {
@@ -461,7 +492,11 @@ fn action_miners(
461492
if level != c.miner.level {
462493
msg.insert(
463494
0,
464-
format!(" [{}] Miner 0x{:08x} leveled up\n", t, c.miner.miner_id),
495+
format!(
496+
" [{}] Miner 0x{:08x} leveled up\n",
497+
t.format("%Y-%m-%d %H:%M:%S"),
498+
c.miner.miner_id
499+
),
465500
);
466501
};
467502
} else if x % 10000 <= 3 {
@@ -471,7 +506,8 @@ fn action_miners(
471506
0,
472507
format!(
473508
" [{}] Miner 0x{:08x} gained 10% CPS boost\n",
474-
t, c.miner.miner_id
509+
t.format("%Y-%m-%d %H:%M:%S"),
510+
c.miner.miner_id
475511
),
476512
);
477513
}
@@ -535,7 +571,7 @@ fn sub_idlecoins(mut wallet: &mut Wallet, less: u64) {
535571
None => {
536572
if wallet.supercoin > 0 {
537573
wallet.supercoin = wallet.supercoin.saturating_sub(1);
538-
(u128::from(less) - u128::from(wallet.idlecoin) - u128::from(u64::MAX))
574+
(u128::from(u64::MAX) - u128::from(less) + u128::from(wallet.idlecoin))
539575
.try_into()
540576
.unwrap()
541577
} else {

0 commit comments

Comments
 (0)