Skip to content

Commit edd8906

Browse files
tslashd1zc
andauthored
Sync Dev with Main (#18)
* [DB] Add Transactions (#12) * cs# version bump * add transaction method * save cps with transaction;dot for millis co-pilot = op * small patch * Change hook methods for OnTriggerStart/EndTouch * don't start timer after `!s <X>` * reset `IsStageMode` * Latest "update" and reworks (#17) * hi Summary of completed items: - Resolved hibernation issues with timers. - Implemented async queries and methods with multiple database connections. - Moved PlayerProfile and Map queries to respective classes. - Added ReplayFrame Situations for situation-specific replay handling. - Corrected Map Replays reload and ReplayFrameSituations usage. - Updated Checkpoints comparison messages for correct display. - Adjusted Stage Replays tracking, saving, and reloading during map runs. - Fixed checkpoint saving on first map run. - Refer to TODO for more information * bonus replays * readme + todo * Update README.md * Update README.md * Update README.md Fix `TODO` link --------- Co-authored-by: 1zc <liamzcharles@gmail.com>
1 parent 87f4670 commit edd8906

35 files changed

+3970
-1125
lines changed

.github/workflows/dotnet.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
- name: Setup .NET
2020
uses: actions/setup-dotnet@v3
2121
with:
22-
dotnet-version: 7.0.x
22+
dotnet-version: 8.0.x
2323
- name: Restore dependencies
2424
run: dotnet restore
2525
- name: Build

README.md

Lines changed: 177 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,175 @@
1-
# PLEASE DO NOT USE THIS, IT IS NOT COMPLETE AND IS AN ACTIVE WORK-IN-PROGRESS. ISSUES HAVE BEEN DISABLED FOR THIS REASON.
1+
# EVERYONE IS WELCOME TO BUILD UP ON THIS PROJECT AND CONTRIBUTE. ISSUES ARE DISABLED FOR THE TIME BEING
22
## Please join the Discord: https://discord.cs.surf
33

44
# Timer
55
Core plugin for CS2 Surf Servers. This project is aimed to be fully open-source with the goal of uniting all of CS2 surf towards building the game mode.
6+
<br>
7+
<details>
8+
<summary>Center HUD Speedometer</summary>
9+
<p>Different time formatting is available in the code base but not implemented for players to change it themselves. Refer to <strong>PlayerTimer.TimeFormatStyle</strong> in codebase</p>
10+
<ul>
11+
<li><strong>Map</strong>
12+
<p><em>Shown while player starts their Map Run from the map start zone (!r)</em></p>
13+
<details>
14+
<summary>Zone name + Start speed</summary>
15+
<p>Map Run mode:</p>
16+
<img src="https://i.imgur.com/IqUL067.png" alt="Map Start Zone">
17+
<img src="https://i.imgur.com/ITooApq.png" alt="Map Start Zone exit">
18+
</details>
19+
</li>
20+
<li><strong>Checkpoints</strong>
21+
<p><em>Only shown during Map Run after exiting a Checkpoint/Stage zone</em></p>
22+
<details>
23+
<summary>Zone name + Start speed</summary>
24+
<p>Checkpoint comparison:</p>
25+
<img src="https://i.imgur.com/recf26f.png" alt="Checkpoint Start Zone exit">
26+
</details>
27+
</li>
28+
<li><strong>Stages</strong>
29+
<p><em>Only shown while in Stage Mode, accessed through !s X or !stage X commands</em></p>
30+
<details>
31+
<summary>Zone name + Start speed</summary>
32+
<p>Stage Run mode:</p>
33+
<img src="https://i.imgur.com/Zi3HN2b.png" alt="Stages Start Zone">
34+
<img src="https://i.imgur.com/uYyumVJ.png" alt="Stages Start Zone exit">
35+
</details>
36+
</li>
37+
<li><strong>Bonuses</strong>
38+
<p><em>Only shown while in Bonus Mode, accessed through !b X or !bonus X commands</em></p>
39+
<details>
40+
<summary>Zone name + Start speed</summary>
41+
<p>Bonus Run mode:</p>
42+
<img src="https://i.imgur.com/Tlmdq9r.png" alt="Bonuses Start Zone">
43+
<img src="https://i.imgur.com/Rfm9qG4.png" alt="Bonuses Start Zone exit">
44+
</details>
45+
</li>
46+
</ul>
47+
</details>
648

7-
# Goals
49+
<details>
50+
<summary>Replays</summary>
51+
<p>Currently only accessible through the <strong>!spec</strong> command and cycling the players. Different time formatting is available in the code base but not implemented for players to change it themselves. Refer to <strong>PlayerTimer.TimeFormatStyle</strong> in codebase</p>
52+
<p>Replays are saved for all types of runs Map/Stage/Bonus (and future Styles) regardless if they are a World Record or just a Personal Best. No functionality is implemented for replaying PB replays yet, feel free to add and Pull Request it</p>
53+
<ul>
54+
<li><strong>Map</strong>
55+
<details>
56+
<summary>Spectating Map Replay</summary>
57+
<p>Map Run:</p>
58+
<img src="https://i.imgur.com/gZutBkS.png" alt="Map Run Replay">
59+
</details>
60+
</li>
61+
<li><strong>Stages</strong>
62+
<details>
63+
<summary>Spectating Stage Replay</summary>
64+
<p>Stage Run:</p>
65+
<img src="https://i.imgur.com/tL7kM1l.png" alt="Stages Run Replay">
66+
</details>
67+
</li>
68+
<li><strong>Bonuses</strong>
69+
<p>Bonus Replays are also available but no screenshots at the time of writing.</p>
70+
</li>
71+
<li><strong>Scoreboard</strong>
72+
<details>
73+
<summary>Currently available replays for the map</summary>
74+
<p>Scoreboard:</p>
75+
<img src="https://i.imgur.com/RNTTFgi.png" alt="Scoreboard showing all available Replays">
76+
</details>
77+
</li>
78+
</ul>
79+
</details>
80+
81+
82+
<details>
83+
<summary>Chat Messages</summary>
84+
<ul>
85+
<li><strong>Map Run</strong>
86+
<details>
87+
<summary>Improving a Record</summary>
88+
<p>Timer sends a chat message to all players upon a player beating the Map Record. Missing it sends a message only to the player:</p>
89+
<img src="https://i.imgur.com/ggCNjZ8.png" alt="Beating a Map record">
90+
</details>
91+
<details>
92+
<summary>Checkpoint Comparison</summary>
93+
<p>Timer sends a chat message the player comparing their PB checkpoint times with the current run (value in brackets after the time indicate the Speed):</p>
94+
<img src="https://i.imgur.com/ts4FfhY.png" alt="Checkpoints Comparison">
95+
</details>
96+
</li>
97+
<li><strong>Stage Records</strong>
98+
<details>
99+
<summary>New Stage record and improving Stage record</summary>
100+
<p>Timer sends a chat message to all players upon a player beating a Stage/Bonus/Map record. Different scenarios for missed/comparing times are also available and shown in chat but only to the player who is doing the run:</p>
101+
<img src="https://i.imgur.com/MNehNmv.png" alt="Stage Records and comparisons">
102+
</details>
103+
</li>
104+
<li><strong>QOL</strong>
105+
<details>
106+
<summary>Player Connected + Map Info (!mi / !tier)</summary>
107+
<p>LL is used for Local development and testing:</p>
108+
<img src="https://i.imgur.com/JtHwYnx.png" alt="Player Connected + Map Info">
109+
</details>
110+
<details>
111+
<summary>Player Rank</summary>
112+
<p>Displays the rank of the player on the current map:</p>
113+
<img src="https://i.imgur.com/4BXJjMv.png" alt="Player Rank">
114+
</details>
115+
</li>
116+
</ul>
117+
</details>
118+
119+
<details>
120+
<summary>Player Commands</summary>
121+
<p>We recommend making binds using the <strong>Console</strong> commands, chat commands may flood the server and not always work.</p>
122+
<ul>
123+
<li><strong>Saveloc (Practice Mode)</strong>
124+
<details>
125+
<summary>Save the current location</summary>
126+
<p>Chat: !saveloc</p>
127+
<p>Console: css_saveloc</p>
128+
</details>
129+
<details>
130+
<summary>Teleport to the last saved location</summary>
131+
<p>Chat: !tele</p>
132+
<p>Console: css_tele</p>
133+
</details>
134+
<details>
135+
<summary>Teleport to the previous saved location</summary>
136+
<p>Chat: !teleprev</p>
137+
<p>Console: css_teleprev</p>
138+
</details>
139+
<details>
140+
<summary>Teleport to the next saved location</summary>
141+
<p>Chat: !telenext</p>
142+
<p>Console: css_telenext</p>
143+
</details>
144+
</li>
145+
</ul>
146+
<ul>
147+
<li><strong>Spectate</strong>
148+
<details>
149+
<summary>Enter Spectator Mode</summary>
150+
<p>Chat: !spec</p>
151+
<p>Console: css_spec</p>
152+
</details>
153+
<details>
154+
<summary>Exiting Spectator Mode</summary>
155+
<p>No command currently available to go back to Play Mode (time may NOT be reset and you will loose your progress post entering Spectator Mode)</p>
156+
<p>Open team choosing menu <strong>M</strong> and select CT</p>
157+
</details>
158+
</li>
159+
</ul>
160+
</details>
161+
</br>
162+
163+
# Main list with tasks (more details can be found [here](https://github.com/CS2Surf/Timer/blob/dev/TODO)):
8164
*Note: This is not definitive/complete and simply serves as a reference for what we should try to achieve. Subject to change.*
9165
Bold & Italics = being worked on.
10-
11166
- [ ] Database
12-
- [ ] MySQL database schema ([W.I.P Design Diagram](https://dbdiagram.io/d/CS2Surf-Timer-DB-Schema-6560b76b3be1495787ace4d2))
167+
- [X] MySQL database schema ([Design Diagram](https://dbdiagram.io/d/CS2Surf-Timer-DB-Schema-6560b76b3be1495787ace4d2))
13168
- [ ] Plugin auto-create tables for easier setup?
14169
- [X] Base database class implementation
15-
- [ ] Maps
170+
- [X] Maps
16171
- [X] Implement map info object (DB)
17-
- [ ] Zoning
172+
- [X] Zoning
18173
- [X] Hook zones from map triggers
19174
- [X] Map start/end zones
20175
- [X] Stage zones
@@ -23,45 +178,46 @@ Bold & Italics = being worked on.
23178
- [X] Support for stages/checkpoints
24179
- [X] Hook to their start/end zones
25180
- [X] Save/Compare checkpoint times
26-
- [ ] Save Stage times
181+
- [X] Save Stage times
27182
- [X] Support for bonuses
28183
- [X] Hook to their start/end zones
29-
- [ ] Save Bonus times
184+
- [X] Save Bonus times
30185
- [X] Start/End trigger touch hooks
31186
- [X] Load zone information automatically from standardised triggers: https://github.com/CS2Surf/Timer/wiki/CS2-Surf-Mapping
32-
- [X] _**Support for stages (`/rs`, teleporting with `/s`)**_
33-
- [ ] _**Support for bonuses (`/rs`, teleporting with `/b #`)**_
34-
- [ ] _**Start/End touch hooks implemented for all zones**_
187+
- [X] Support for stages (`/rs`, teleporting with `/s`)
188+
- [X] Support for bonuses (`/rs`, teleporting with `/b #`)
189+
- [X] Start/End touch hooks implemented for all zones
35190
- [ ] Surf configs
36191
- [X] Server settings configuration
37192
- [ ] Plugin configuration
38193
- [X] Database configuration
39-
- [ ] Timing
194+
- [X] Timing
40195
- [X] Base timer class implementation
41196
- [X] Base timer HUD implementation
42197
- [X] Prespeed measurement and display
43-
- [ ] Save/load times
198+
- [X] Save/load times
44199
- [x] Map times
45200
- [x] Checkpoint times
46-
- [ ] Stage times
47-
- [ ] Bonus times
201+
- [X] Stage times
202+
- [X] Bonus times
48203
- [X] Practice Mode implementation
49204
- [ ] Announce records to Discord
50205
- [ ] Stretch goal: sub-tick timing
51206
- [ ] Player Data
52207
- [X] Base player class
53-
- [ ] **_Player stat classes_**
208+
- [ ] Player stat classes
54209
- [ ] Profile implementation (DB)
55210
- [ ] Points/Skill Groups (DB)
56211
- [ ] Player settings (DB)
57-
- [x] Replays - Not tracking Stage/Bonus times but Replay functionality for them is there
212+
- [x] Replays
58213
- [x] Personal Best
59214
- [x] Map Record
60-
- [ ] Stage Record
61-
- [ ] Bonus Record
215+
- [X] Stage Record
216+
- [X] Bonus Record
62217
- [x] World Record
63218
- [X] Map Record
64-
- [ ] Stage Record
65-
- [ ] Bonus Record
219+
- [X] Stage Record
220+
- [X] Bonus Record
66221
- [ ] Style implementation (SW, HSW, BW)
67222
- [ ] Paint (?)
223+
- [ ] API Integration (Repo can be found [here](https://github.com/CS2Surf/CS2-Surf-API))

TODO

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
- Re-add the MySQL queries in code and make it switch between API and DB functions
2+
- Map Time is NOT being saved with API
3+
- Make configs generate themselves inside the `./configs/plugins/...` folder
4+
- Fix loading MapTimes for each type (stage, bonus, maps)
5+
- API
6+
- DB
7+
- Change `DB_QUERY_MAP_GET_RUNS` query with `DB_QUERY_MAP_GET_RECORD_RUNS_AND_COUNT` in API and edit code in plugin
8+
- Change `DB_QUERY_PB_GET_RUNTIME` query in API
9+
10+
- Double check the Start/End velocities for End Zone,Checkpoints, Stages, Bonuses
11+
+ Maps
12+
+ Checkpoints
13+
- Stages
14+
- Try and get the Start/End velocity values from the Checkpoint object in Map Run
15+
+ Bonuses
16+
17+
- Using `!spec` from any start zone and going back to CT starts your timer
18+
19+
- Try and determine Left/Right side for Bonuses (surf_ace)
20+
- Try and determine Left/Right side for Maps
21+
- Try and determine Left/Right side for Stages
22+
# Done
23+
+ Hibernation fucks up the creation of `CurrentMap`, if nobody has joined the first map it was on and you change to another map, server segfaults. I guess a query is being held?? :think:
24+
+ Solution is to use `Server.NextWorldUpdate` as hibernation stops all `Timer`s :peepoHappy:
25+
+ Introduce `async` for queries and some methods
26+
+ Make Database spawn a new connection for each query to avoid `Connection in use` error
27+
+ Add notes to apply `using` blocks for certain methods for proper operation
28+
+ Move **PlayerProfile** queries to the respective class
29+
+ Move **Map** queries to the respective class
30+
+ Total Completions for a map are wrong in HUD
31+
+ Add `Situation` to each `ReplayFrame` and load it properly
32+
+ Fix `STAGE_EXIT_ZONE` situations - not triggered (logic in `TriggerEndTouch` is most likely bad)
33+
+ Fix Map Replays
34+
+ Reload after setting a new WR
35+
+ Load if no replay existed before a new run
36+
+ Use the `ReplayFrameSituation` for determining where to cut replays
37+
+ Do not cut replay as soon as we enter end zone (determined by the AddTimer amount for `SaveMapTime`)
38+
+ Double check the Checkpoints comparison messages
39+
+ 1st run: [CS2 Surf] CP [1]: 02.468 (1083) [PB: N/A (N/A) | WR: N/A (N/A)]
40+
+ 2nd run: [CS2 Surf] CP [1]: 02.421 (1128) [PB: +02.390 (+46) | WR: +02.390 (+46)]
41+
+ Fix Stage replays
42+
+ Track the times even during Map Run on staged maps
43+
+ Include the pre-strafe
44+
+ Load all of them instead of overwriting and cycle (maybe make StageWR a Dictionary)
45+
+ Reload them after setting a new Stage WR
46+
+ Load if no replay existed before
47+
+ Use the `ReplayFrameSituation` for determining where to cut replays
48+
+ Save stage replays when `IsStageMode` is enabled
49+
+ Use seperate method
50+
+ Save the correct amount of `Ticks` for stage runs during map run
51+
+ Use seperate method
52+
+ Save the last stage time - triggered in `END_ZONE_ENTER`
53+
+ `IsStageMode`
54+
+ Use seperate method
55+
+ Map run
56+
+ Use seperate method
57+
+ When loading new stage replays the cycling of them does not work
58+
+ First ever map run does not save Checkpoints, check if we wait to retrieve the MapTime_ID before trying to insert Checkpoints
59+
+ Trim different type of replays based on situations
60+
+ Map Replays
61+
+ Stage Replays during Map runs
62+
+ Stage Replays in `IsStageMode`
63+
+ Bonus Replays
64+
+ Replay bots are not being spawned on `Linear` maps
65+
+ Needs the CS2Fixes NAV mesh patch to work with our implementation

src/ST-API/Api.cs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
using System.Net.Http.Json;
2+
3+
namespace SurfTimer;
4+
5+
internal class ApiCall
6+
{
7+
public static async Task Api_Save_Stage_MapTime(Player player)
8+
{
9+
// This is a trick to record the time before the player exits the start zone
10+
int last_exit_tick = player.ReplayRecorder.LastExitTick();
11+
int last_enter_tick = player.ReplayRecorder.LastEnterTick();
12+
13+
// player.Controller.PrintToChat($"CS2 Surf DEBUG >> OnTriggerStartTouch -> Last Exit Tick: {last_exit_tick} | Current Frame: {player.ReplayRecorder.Frames.Count}");
14+
15+
int stage_run_time = player.ReplayRecorder.Frames.Count - 1 - last_exit_tick; // Would like some check on this
16+
int time_since_last_enter = player.ReplayRecorder.Frames.Count - 1 - last_enter_tick;
17+
18+
int tt = -1;
19+
if (last_exit_tick - last_enter_tick > 2 * 64)
20+
tt = last_exit_tick - 2 * 64;
21+
else
22+
tt = last_enter_tick;
23+
24+
API_CurrentRun stage_time = new()
25+
{
26+
player_id = player.Profile.ID,
27+
map_id = player.CurrMap.ID,
28+
style = player.Timer.Style,
29+
type = 2,
30+
stage = player.Timer.Stage - 1,
31+
run_time = stage_run_time,
32+
run_date = (int)DateTimeOffset.UtcNow.ToUnixTimeSeconds(),
33+
replay_frames = player.ReplayRecorder.SerializeReplayPortion(tt, time_since_last_enter)
34+
35+
};
36+
37+
await ApiMethod.POST(Config.API.Endpoints.ENDPOINT_CR_SAVE_STAGE_TIME, stage_time);
38+
// player.Stats.LoadStageTime(player);
39+
// await CurrentMap.ApiGetMapRecordAndTotals(); // Reload the Map record and totals for the HUD
40+
}
41+
}

0 commit comments

Comments
 (0)