Skip to content

Commit 7d4193d

Browse files
committed
couple tweaks requested by cg
1 parent 3ba6149 commit 7d4193d

File tree

6 files changed

+93
-76
lines changed

6 files changed

+93
-76
lines changed

src/rs/server/src/handlews.rs

Lines changed: 51 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -2235,6 +2235,57 @@ pub async fn handle_ws(
22352235
}
22362236
}
22372237
}
2238+
AuthMessage::leaderboard { flags, category } => {
2239+
let leagueid = leagueid(&flags);
2240+
let ownscore = logerr(client
2241+
.query(concat!(
2242+
"select val ",
2243+
"from leaderboard l ",
2244+
"join user_data ud on l.data_id = ud.id and ud.user_id = $3 ",
2245+
"where league_id = $1 and category = $2"), &[&leagueid, &category, &userid])
2246+
.await).ok().and_then(|rows| rows.first().map(|row| row.get::<usize, i32>(0))).unwrap_or_default();
2247+
if let Ok(rows) = logerr(client
2248+
.query(concat!(
2249+
"select u.name, ud.name, val ",
2250+
"from leaderboard l ",
2251+
"join user_data ud on l.data_id = ud.id ",
2252+
"join users u on ud.user_id = u.id ",
2253+
"where league_id = $1 and category = $2 ",
2254+
"order by val desc limit 99"), &[&leagueid, &category])
2255+
.await)
2256+
{
2257+
let mut top = Vec::with_capacity(rows.len());
2258+
for row in rows.iter() {
2259+
top.push((row.get::<usize, &str>(0), row.get::<usize, &str>(1), row.get::<usize, i32>(2)));
2260+
}
2261+
sendmsg(&tx, &WsResponse::leaderboard { flags, category, ownscore, top: &top });
2262+
}
2263+
}
2264+
AuthMessage::legacyboard => {
2265+
let ownscore = logerr(client
2266+
.query(concat!(
2267+
"select val ",
2268+
"from leaderboard l ",
2269+
"join user_data ud on l.data_id = ud.id and ud.user_id = $3 ",
2270+
"where league_id = 1 and category = 'Wealth'"), &[&userid])
2271+
.await).ok().and_then(|rows| rows.first().map(|row| row.get::<usize, i32>(0))).unwrap_or_default();
2272+
if let Ok(rows) = logerr(client
2273+
.query(concat!(
2274+
"select u.name, ud.name, val ",
2275+
"from leaderboard l ",
2276+
"join user_data ud on l.data_id = ud.id ",
2277+
"join users u on ud.user_id = u.id ",
2278+
"where league_id = 1 and category = 'Wealth' ",
2279+
"order by val desc limit 99"), &[])
2280+
.await)
2281+
{
2282+
let mut top = Vec::with_capacity(rows.len());
2283+
for row in rows.iter() {
2284+
top.push((row.get::<usize, &str>(0), row.get::<usize, &str>(1), row.get::<usize, i32>(2)));
2285+
}
2286+
sendmsg(&tx, &WsResponse::legacyboard { ownscore, top: &top });
2287+
}
2288+
}
22382289
}
22392290
}
22402291
UserMessage::guestchat { u, msg } => {
@@ -2529,43 +2580,6 @@ pub async fn handle_ws(
25292580
sendmsg(&tx, &WsResponse::arenatop { lv, top: &top });
25302581
}
25312582
}
2532-
UserMessage::leaderboard { flags, category } => {
2533-
let leagueid = leagueid(&flags);
2534-
if let Ok(rows) = client
2535-
.query(concat!(
2536-
"select u.name, ud.name, val ",
2537-
"from leaderboard l ",
2538-
"join user_data ud on l.data_id = ud.id ",
2539-
"join users u on ud.user_id = u.id ",
2540-
"where league_id = $1 and category = $2 ",
2541-
"order by val desc limit 99"), &[&leagueid, &category])
2542-
.await
2543-
{
2544-
let mut top = Vec::with_capacity(rows.len());
2545-
for row in rows.iter() {
2546-
top.push((row.get::<usize, &str>(0), row.get::<usize, &str>(1), row.get::<usize, i32>(2)));
2547-
}
2548-
sendmsg(&tx, &WsResponse::leaderboard { flags, category, top: &top });
2549-
}
2550-
}
2551-
UserMessage::legacyboard => {
2552-
if let Ok(rows) = logerr(client
2553-
.query(concat!(
2554-
"select u.name, ud.name, val ",
2555-
"from leaderboard l ",
2556-
"join user_data ud on l.data_id = ud.id ",
2557-
"join users u on ud.user_id = u.id ",
2558-
"where league_id = 1 and category = 'Wealth' ",
2559-
"order by val desc limit 99"), &[])
2560-
.await)
2561-
{
2562-
let mut top = Vec::with_capacity(rows.len());
2563-
for row in rows.iter() {
2564-
top.push((row.get::<usize, &str>(0), row.get::<usize, &str>(1), row.get::<usize, i32>(2)));
2565-
}
2566-
sendmsg(&tx, &WsResponse::legacyboard { top: &top });
2567-
}
2568-
}
25692583
UserMessage::bzread => {
25702584
let mut bz: FxHashMap<i16, Vec<_>> = Default::default();
25712585
if let Ok(bids) = client.query("select u.name, b.code, b.q, b.p from bazaar b join users u on b.user_id = u.id", &[]).await {

src/rs/server/src/json.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ pub enum AuthMessage {
243243
setquest {
244244
quest: String,
245245
},
246+
leaderboard {
247+
flags: HashSet<String>,
248+
category: Leaderboard,
249+
},
250+
legacyboard,
246251
}
247252

248253
#[derive(Deserialize, Clone)]
@@ -280,11 +285,6 @@ pub enum UserMessage {
280285
arenatop {
281286
lv: u8,
282287
},
283-
leaderboard {
284-
flags: HashSet<String>,
285-
category: Leaderboard,
286-
},
287-
legacyboard,
288288
chatus {
289289
hide: Option<bool>,
290290
afk: Option<bool>,
@@ -466,9 +466,11 @@ pub enum WsResponse<'a> {
466466
flags: HashSet<String>,
467467
category: Leaderboard,
468468
top: &'a [(&'a str, &'a str, i32)],
469+
ownscore: i32,
469470
},
470471
legacyboard {
471472
top: &'a [(&'a str, &'a str, i32)],
473+
ownscore: i32,
472474
},
473475
}
474476

src/rs/src/skill.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4133,21 +4133,13 @@ impl Skill {
41334133
let owner = ctx.get_owner(c);
41344134
let candidates = ctx.count_creatures(owner);
41354135
if candidates > 0 {
4136-
let mut candidate = ctx.upto(candidates as u32);
4137-
for &cr in ctx.get_player(owner).creatures.iter() {
4138-
if cr != 0 {
4139-
if candidate == 0 {
4140-
ctx.buffhp(cr, halfhp);
4141-
ctx.incrAtk(cr, halfatk);
4142-
break;
4143-
} else {
4144-
candidate -= 1;
4145-
}
4146-
}
4136+
let mut nth = ctx.upto(candidates as u32);
4137+
if let Some(&cr) =
4138+
ctx.get_player(owner).creatures.iter().filter(|&&cr| cr != 0).nth(nth as usize)
4139+
{
4140+
ctx.buffhp(cr, halfhp);
4141+
ctx.incrAtk(cr, halfatk);
41474142
}
4148-
} else if owner == ctx.get_owner(t) {
4149-
ctx.buffhp(t, halfhp);
4150-
ctx.incrAtk(t, halfatk);
41514143
}
41524144
}
41534145
Self::precognition => {

src/vanilla/views/Wealth.jsx

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { createSignal, onMount, Index } from 'solid-js';
22

3-
import { emit, setCmds } from '../../sock.jsx';
3+
import { userEmit, setCmds } from '../../sock.jsx';
44
import { doNav } from '../../store.jsx';
55

66
export default function Wealth() {
@@ -12,18 +12,21 @@ export default function Wealth() {
1212
setTop(top);
1313
},
1414
});
15-
emit({ x: 'legacyboard' });
15+
userEmit('legacyboard');
1616
});
1717

1818
return (
1919
<div style="display:flex">
20-
<input
21-
type="button"
22-
value="Exit"
23-
onClick={() => doNav(import('./MainMenu.jsx'))}
24-
/>
20+
<div>
21+
<input
22+
type="button"
23+
value="Exit"
24+
onClick={() => doNav(import('./MainMenu.jsx'))}
25+
/>
26+
<div>{getTop()?.[0]}</div>
27+
</div>
2528
<div style="width:810px;display:grid;grid-template-rows:repeat(33,18px);column-gap:18px;grid-auto-flow:column;grid-auto-columns:257px;white-space:nowrap">
26-
<Index each={getTop()}>
29+
<Index each={getTop()?.[1]}>
2730
{(item, i) => (
2831
<div style="display:flex;justify-content:space-between">
2932
<div style="text-overflow:ellipsis;overflow:hidden">

src/views/DeckEditor.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ export default function DeckEditor() {
312312
style="position:absolute;left:8px;top:162px"
313313
/>
314314
<div style="position:absolute;left:8px;top:8px;width:720px;display:flex;justify-content:space-between">
315-
<div style="overflow:hidden;text-overflow:ellipsis;width:192px">
315+
<div style="overflow:hidden;text-overflow:ellipsis;width:192px;white-space:nowrap">
316316
{rx.user.selectedDeck ?? ''}
317317
</div>
318318
<Qecks onClick={loadDeck} user={rx.user} />

src/views/Leaderboards.jsx

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { createComputed, createSignal, onMount, Index } from 'solid-js';
2-
import { emit, setCmds } from '../sock.jsx';
2+
import { userEmit, setCmds } from '../sock.jsx';
33
import { doNav, state } from '../store.jsx';
44
import { presets } from '../ui.js';
55

@@ -21,11 +21,11 @@ export default function Leaderboards() {
2121

2222
onMount(() => {
2323
setCmds({
24-
leaderboard: ({ flags, category, top }) => {
24+
leaderboard: ({ flags, category, ownscore, top }) => {
2525
const name = category + ':' + flags.sort().join(' ');
2626
setTop(t => ({
2727
...t,
28-
[name]: top,
28+
[name]: [ownscore, top],
2929
}));
3030
},
3131
});
@@ -34,7 +34,7 @@ export default function Leaderboards() {
3434
createComputed(() => {
3535
const top = getTop();
3636
if (!top[getCategory() + ':' + getFlags().join(' ')]) {
37-
emit({ x: 'leaderboard', flags: getFlags(), category: getCategory() });
37+
userEmit('leaderboard', { flags: getFlags(), category: getCategory() });
3838
}
3939
});
4040

@@ -67,16 +67,22 @@ export default function Leaderboards() {
6767
/>
6868
))}
6969
</div>
70-
<input
71-
type="button"
72-
value="Exit"
73-
onClick={() => doNav(import('./MainMenu.jsx'))}
74-
style="margin-top:auto"
75-
/>
70+
<div style="margin-top:auto">
71+
<div>
72+
{getTop()?.[getCategory() + ':' + getFlags().join(' ')]?.[0]}
73+
</div>
74+
<input
75+
type="button"
76+
value="Exit"
77+
onClick={() => doNav(import('./MainMenu.jsx'))}
78+
/>
79+
</div>
7680
</div>
7781
<div style="width:810px;display:grid;grid-template-rows:repeat(33,18px);column-gap:18px;grid-auto-flow:column;grid-auto-columns:257px;white-space:nowrap">
7882
<Index
79-
each={getTop()?.[getCategory() + ':' + getFlags().join(' ')] ?? []}>
83+
each={
84+
getTop()?.[getCategory() + ':' + getFlags().join(' ')]?.[1] ?? []
85+
}>
8086
{(item, i) => (
8187
<div
8288
style="display:flex;justify-content:space-between"

0 commit comments

Comments
 (0)