Skip to content

Commit

Permalink
fix various timer bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
SpikeVN committed Jan 3, 2025
1 parent fdb14b9 commit a571182
Show file tree
Hide file tree
Showing 31 changed files with 253 additions and 59 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -230,3 +230,4 @@ assets/question_official.json
/config.csv
config.json
assets/vcnv/key.png
/game.log
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ See Hacking (above) for requirements. After that, the project may be built. Note
Licensing & Copyright
---------------------
```
Copyright (c) 2023-2024 FalcoLabs.
Copyright (c) 2023-2025 FalcoLabs.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
110 changes: 110 additions & 0 deletions assets/public/bg.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions engine/src/api/packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl Packet {
pub fn into_packet<T: 'static>(name: String, data: T) -> Packet {
// WARNING: HAZMAT SUIT REQUIRED - UNSAFE HELL
unsafe {
return match name.as_str() {
match name.as_str() {
// "Player" if ("Player" == std::any::type_name::<T>()) => Packet::Player(
// (&data as &dyn std::any::Any)
// .downcast_ref::<Player>()
Expand Down Expand Up @@ -89,7 +89,7 @@ impl Packet {
},

_ => panic!("Tried to package unknown resource."),
};
}
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions engine/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* engine, a data serialization and syncronization for owl.
* Copyright (C) 2024 Team Falco
* Copyright (C) 2025 Team Falco
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -15,7 +15,6 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

#[cfg(feature = "api")]
pub mod api;
#[cfg(feature = "logging")]
Expand Down
2 changes: 1 addition & 1 deletion engine/src/universal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ mod logic {
/// as only Rust code handles their matching and serialization.
struct PortableTypeVisitor;

impl<'de> serde::de::Visitor<'de> for PortableTypeVisitor {
impl serde::de::Visitor<'_> for PortableTypeVisitor {
type Value = PortableType;

fn expecting(&self, formatter: &mut std::fmt::Formatter) -> std::fmt::Result {
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
@licstart The following is the entire license notice for the
JavaScript and WebAssembly code in this page.
Copyright (C) 2024 Nguyễn Tri Phương
Copyright (C) 2023-2025 FalcoLabs
The JavaScript and WebAssembly code in this page
is free software: you can redistribute it and/or modify it under
Expand Down
24 changes: 6 additions & 18 deletions frontend/src/components/display/Standby.svelte
Original file line number Diff line number Diff line change
@@ -1,29 +1,17 @@
<script lang="ts">
import { SHOW_NAME, ORG_NAME, SUBTEXT } from "$lib";
</script>

<div class="bg">
<img alt="" src="/bg.jpg" />
<!-- <div></div>
<div class="titlegroup">
<h2 class="caps">{ORG_NAME}</h2>
<h1>
{SHOW_NAME}
</h1>
<h2 class="caps subtext">{SUBTEXT}</h2>
</div>
<p class="cpy">Ⓒ 2024 {ORG_NAME}. Đây là phần mềm nguồn mở, phát hành theo giấy phép GPL3.</p> -->
</div>
<div class="bg"></div>

<style>
img {
width: 100%;
height: 100%;
}
.bg {
background: url("/bg.svg");
background-repeat: no-repeat;
background-attachment: fixed;
background-position: center;
background-size: 100% auto;
width: 100%;
height: 100vh;
background: var(--bg-gradient);
display: flex;
flex-direction: column;
align-items: center;
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/player/AuthPlayer.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
<button class="pill confspot" on:click={click}>Bắt đầu</button>
{/if}
<p class="cpy">
2024 {ORG_NAME}. Đây là phần mềm nguồn mở, phát hành theo giấy phép GPL3.
2025 {ORG_NAME}. Đây là phần mềm nguồn mở, phát hành theo giấy phép GPL3.
</p>
</div>
</form>
Expand Down
10 changes: 10 additions & 0 deletions frontend/src/components/player/TangToc.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@
return;
}
myans = answer;
await conn.log(
gm.username,
`submitted ${$time.toFixed(4)} "${answer}"`
);
await conn.send(
CallProcedure.name("tangtoc::submit_answer")
.string("answer", answer)
Expand All @@ -197,6 +201,12 @@
type="text"
placeholder="Nhập đáp án"
spellcheck="false"
on:input={async () => {
await conn.log(
gm.username,
`${$time.toFixed(4)} "${answer}"`
);
}}
readonly={!$states.allow_input}
bind:value={answer}
bind:this={inputBox}
Expand Down
1 change: 1 addition & 0 deletions frontend/src/components/player/VCNV.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
class:activated={$states.highlighted.includes(gm.username)}
on:click={async () => {
await conn.send(CallProcedure.name("vcnv::bell").string("token", gm.authToken).number("timeMs", Date.now()).build());
await conn.log(gm.username, "gửi chuông trả lời CNV")
}}>Chuông trả lời CNV</button
>
<ScoreBar {states} />
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/components/player/VCNVMain.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
);
states.on("puzzle_data", (_) => {
// @ts-ignore
answer = undefined
myans = ""
})
answer = undefined;
myans = "";
});

states.subscribe((s) => {
if (s.puzzle_data == undefined) return;
Expand Down Expand Up @@ -108,6 +108,7 @@
return;
}
myans = answer;
await conn.log(gm.username, `submitted ${$time.toFixed(4)} "${answer}"`);
await conn.send(
CallProcedure.name("vcnv::submit_answer")
.string("answer", answer)
Expand All @@ -122,6 +123,9 @@
class="inp"
bind:value={answer}
bind:this={inputBox}
on:input={async () => {
await conn.log(gm.username, `${$time.toFixed(4)} "${answer}"`);
}}
readonly={!$states.allow_input}
type="text"
placeholder="Nhập đáp án"
Expand Down Expand Up @@ -155,10 +159,6 @@
font-weight: bold;
}

.code {
font-family: var(--font-monospace);
}

.top {
display: flex;
flex-direction: row;
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/lib/gamemaster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,11 @@ export class GameMaster {
obj.isAuthenticated.set(true);
}
});
obj.connection.on(Peeker.PacketType.Unknown, (packet) => {
if (packet.value == "STATEDUMP") {
obj.connection.log(obj.username, `statedump ${JSON.stringify(obj.states.store)}`)
}
})

await obj.updateAll();
return obj;
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

export const ORG_NAME: string = "Đoàn trường THPT Chuyên Bắc Ninh · THPT Chuyên Bắc Ninh";
export const SHOW_NAME: string = "Đường Đua Xanh";
export const SUBTEXT: string = "Mùa 5, Bán kết 1"
export const ANTICHEAT_ENABLED = false;
export const SUBTEXT: string = "Mùa 5, Chung kết"
export const ANTICHEAT_ENABLED = true;

import { PacketType, type Packet, type _PacketValue, type _PacketVariant } from "client";
type CBHandle<T extends PacketType> = (packet: Packet<T>) => void
Expand Down Expand Up @@ -89,4 +89,8 @@ export class Connection {
async send<T extends PacketType>(packet: Packet<T>) {
this.ws.send(packet.pack());
}

async log(ident: string, message: string) {
this.ws.send(new Peeker.Packet(Peeker.PacketType.Unknown, `LOG ${ident} ${message}`).pack());
}
}
4 changes: 3 additions & 1 deletion frontend/src/routes/display/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
PlayerManager,
StateManager,
ANTICHEAT_ENABLED,

AssetManager

} from "$lib";
Expand Down Expand Up @@ -45,6 +44,9 @@
await gm.updateAll();
}
});
states.onready(async (_) => {
await conn.send(new Peeker.Packet(Peeker.PacketType.Unknown, "IDENT display"))
})
});
</script>

Expand Down
7 changes: 6 additions & 1 deletion frontend/src/routes/game/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
StateManager,
ANTICHEAT_ENABLED,
AssetManager

} from "$lib";
import { writable, type Readable, type Writable } from "svelte/store";
import { onMount } from "svelte";
Expand Down Expand Up @@ -41,6 +40,12 @@
await gm.updateAll();
}
});

states.onready(async (_) => {
await conn.send(
new Peeker.Packet(Peeker.PacketType.Unknown, `IDENT player_${gm.username}`)
);
});
});
</script>

Expand Down
3 changes: 3 additions & 0 deletions frontend/src/routes/judge/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
states = gm.states;
}
});
states.onready(async (_) => {
await conn.send(new Peeker.Packet(Peeker.PacketType.Unknown, "IDENT judge"))
})
});
</script>

Expand Down
9 changes: 5 additions & 4 deletions frontend/src/routes/mc/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@
PlayerManager,
StateManager,
ANTICHEAT_ENABLED,

AssetManager

} from "$lib";
import { onMount } from "svelte";
import Load from "../../components/Load.svelte";
Expand All @@ -31,14 +29,17 @@
conn = await Connection.create();
gm = await GameMaster.create(conn);
states = gm.states;
assets = await AssetManager.create(states)
assets = await AssetManager.create(states);
players = gm.players;
conn.on(Peeker.PacketType.State, async (update) => {
if (update.value.name === "current_part") {
gm.states.flush();
await gm.updateAll();
}
});
states.onready(async (_) => {
await conn.send(new Peeker.Packet(Peeker.PacketType.Unknown, "IDENT mc"));
});
});

const kbehandler = async (kde: KeyboardEvent) => {
Expand All @@ -55,7 +56,7 @@
{:else if $states.available_parts[$states.current_part] == "vcnv"}
<VcnvDisplay {conn} {gm} {states} {players} />
{:else if $states.available_parts[$states.current_part] == "tangtoc"}
<TangTocDisplay {conn} {gm} {states} {players} {assets} />
<TangTocDisplay {gm} {states} {players} {assets} />
{:else if $states.available_parts[$states.current_part] == "vedich"}
<VeDichDisplay {conn} {gm} {states} {players} />
{:else if $states.available_parts[$states.current_part] == "tiebreaker"}
Expand Down
6 changes: 5 additions & 1 deletion frontend/src/routes/panel2/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@
await gm.updateAll();
}
});
states.onready(async (_) => {
await conn.send(new Peeker.Packet(Peeker.PacketType.Unknown, "IDENT panel"));
});
});
</script>

Expand Down Expand Up @@ -61,7 +64,8 @@
{gm}
sounds={[
{ displayName: "Chuyển phần", fileName: "common-startsection" },
{ displayName: "Chỗ trống", fileName: "common-dotdotdot" }
{ displayName: "Chỗ trống", fileName: "common-dotdotdot" },
{ displayName: "Trao giải", fileName: "tongket-award" }
]}
/>
{#if $states.available_parts[$states.current_part] == "khoidong"}
Expand Down
7 changes: 7 additions & 0 deletions frontend/src/routes/panel2/components/PartSwitcher.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
await states.setBoolean("engine_freeze", !$states.engine_freeze);
}}>{$states.engine_freeze ? "Đóng băng" : "Trực tiếp"}</button
>
<button
class="btn smol bfreeze"
class:accent={!$states.engine_freeze}
on:click={async () => {
await conn.send(new Peeker.Packet(Peeker.PacketType.Unknown, "REQUESTSTATEDUMP"))
}}>Dump</button
>
</div>
</Load>
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/panel2/components/TangToc.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
class:accent={$states.reveal_answer}
on:click={async () =>
await states.setBoolean("reveal_answer", !$states.reveal_answer)}
>Hiện đáp án</button
>Hiện KQ chấm</button
>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/panel2/components/TimerControls.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
on:click={async () => {
// @ts-ignore
await gm.timer_operation($states.timer_paused ? "start" : "pause");
$states.timer_paused ? await onstart() : await onpause()
$states.timer_paused ? await onstart() : await onpause();
}}
class="btn"
>
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/routes/panel2/components/VCNV.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
class:accent={$states.reveal_answer}
on:click={async () =>
await states.setBoolean("reveal_answer", !$states.reveal_answer)}
>Hiện đáp án</button
>Hiện KQ chấm</button
>
</div>
</div>
Expand Down
8 changes: 4 additions & 4 deletions server/logic/khoidong.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ def __init__(self) -> None:

self.question_placement = {
STAGE_SEPERATED: {
0: [0, 1, 2, 3, 4, 5],
1: [6, 7, 8, 9, 10, 11],
2: [12, 13, 14, 15, 16, 17],
3: [18, 19, 20, 21, 22, 23],
0: [0, 1, 2],
1: [6, 7, 8],
2: [12, 13, 14],
3: [18, 19, 20],
},
STAGE_JOINT: [24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35],
}
Expand Down
3 changes: 3 additions & 0 deletions server/logic/tangtoc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from config import config
import typing
from penguin import Some, Null
from penguin import gamelog


class PlayerAnswer(typing.TypedDict):
Expand Down Expand Up @@ -114,6 +115,8 @@ def submit_answer(
)
output = sorted(output, key=lambda x: x["time"])
self.answers.set(output)
engine.log_info(f"{name} sent answer '{answer}' at {elapsed}")
gamelog.log("engine", f"{name} sent answer '{answer}' at {elapsed}")
case Null():
engine.log_warning(
f"Unidentified player {token}@{addr} tried to submit answer. Ignored."
Expand Down
Loading

0 comments on commit a571182

Please sign in to comment.