Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
fc-minigame
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
陈冲
fc-minigame
Commits
889c6ad0
Commit
889c6ad0
authored
May 26, 2026
by
陈冲
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
rename fc-backend
parent
a336c43f
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
38 additions
and
141 deletions
+38
-141
Cargo.lock
backend/Cargo.lock
+26
-26
Cargo.toml
backend/Cargo.toml
+2
-2
config.rs
backend/src/commons/config.rs
+1
-2
lib.rs
backend/src/lib.rs
+1
-102
router.rs
backend/src/router.rs
+8
-9
No files found.
backend/Cargo.lock
View file @
889c6ad0
...
...
@@ -152,32 +152,6 @@ dependencies = [
]
[[package]]
name = "backend-ds"
version = "0.1.0"
dependencies = [
"aes",
"async-trait",
"base64",
"bytes",
"cbc",
"chrono",
"dashmap",
"lazy_static",
"md-5",
"rand 0.10.0",
"rmp-serde",
"rust-embed",
"salvo",
"serde",
"serde_json",
"socketioxide",
"sqlx",
"tokio",
"tower",
"tower-http",
]
[[package]]
name = "base64"
version = "0.22.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
@@ -783,6 +757,32 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be"
[[package]]
name = "fc-backend"
version = "0.1.0"
dependencies = [
"aes",
"async-trait",
"base64",
"bytes",
"cbc",
"chrono",
"dashmap",
"lazy_static",
"md-5",
"rand 0.10.0",
"rmp-serde",
"rust-embed",
"salvo",
"serde",
"serde_json",
"socketioxide",
"sqlx",
"tokio",
"tower",
"tower-http",
]
[[package]]
name = "find-msvc-tools"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
...
...
backend/Cargo.toml
View file @
889c6ad0
[package]
name
=
"
backend-ds
"
name
=
"
fc-backend
"
version
=
"0.1.0"
edition
=
"2024"
...
...
@@ -27,7 +27,7 @@ cbc = { version = "0.1.2", features = ["alloc"] }
md5
=
{
version
=
"0.10.6"
,
package
=
"md-5"
}
[[bin]]
name
=
"
backend-ds
"
name
=
"
fc-backend
"
# [target.aarch64-unknown-linux-gnu]
# linker = "aarch64-linux-gnu-gcc"
...
...
backend/src/commons/config.rs
View file @
889c6ad0
...
...
@@ -21,9 +21,8 @@ pub struct Config {
#[derive(Clone,
Deserialize,
Serialize,
Debug)]
#[serde(default)]
pub
struct
DbConfig
{
// 数据库类型:
mongodb、postgresql、mysql、sqlite。
// 数据库类型:
postgresql、mysql、sqlite。(暂只处理了postgresql)
pub
kind
:
String
,
// mongodb://admin:123456@127.0.0.1:27017/backend_ds
// postgresql://admin:123456@localhost:5432/backend_ds
pub
uri
:
String
,
}
...
...
backend/src/lib.rs
View file @
889c6ad0
...
...
@@ -3,109 +3,8 @@ mod db;
mod
protocols
;
mod
router
;
use
commons
::
utils
::
CONFIG
as
config
;
use
sqlx
::
PgPool
;
use
sqlx
::
postgres
::
PgPoolOptions
;
pub
async
fn
init_postgresql_schema
()
->
Result
<
(),
String
>
{
let
pool
=
PgPoolOptions
::
new
()
.max_connections
(
4
)
.connect
(
&
config
.db.uri
)
.await
.map_err
(|
err
|
err
.to_string
())
?
;
sqlx
::
raw_sql
(
"create table if not exists player_profiles (
userid text primary key,
nickname text not null,
level bigint not null default 1,
exp bigint not null default 0,
avatar_id bigint not null default 0,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
create table if not exists player_wallets (
userid text primary key references player_profiles(userid) on delete cascade,
gold bigint not null default 0,
diamond bigint not null default 0,
stamina bigint not null default 100,
updated_at timestamptz not null default now()
);
create table if not exists player_items (
id bigserial primary key,
userid text not null references player_profiles(userid) on delete cascade,
item_id text not null,
item_count bigint not null default 0,
updated_at timestamptz not null default now(),
unique(userid, item_id)
);
create table if not exists player_mails (
id bigserial primary key,
userid text not null references player_profiles(userid) on delete cascade,
title text not null,
content text not null default '',
attachments jsonb not null default '[]'::jsonb,
status text not null default 'unread',
created_at timestamptz not null default now()
);
create table if not exists task_idempotency (
task_id text primary key,
task_type text not null,
status text not null default 'running',
attempt bigint not null default 1,
result jsonb,
created_at timestamptz not null default now(),
updated_at timestamptz not null default now()
);
alter table player_profiles alter column level type bigint;
alter table player_profiles alter column avatar_id type bigint;
alter table player_wallets alter column stamina type bigint;"
,
)
.execute
(
&
pool
)
.await
.map_err
(|
err
|
err
.to_string
())
?
;
migrate_legacy_players
(
&
pool
)
.await
}
async
fn
migrate_legacy_players
(
pool
:
&
PgPool
)
->
Result
<
(),
String
>
{
let
row
:
(
bool
,)
=
sqlx
::
query_as
(
"select to_regclass('public.players') is not null"
)
.fetch_one
(
pool
)
.await
.map_err
(|
err
|
err
.to_string
())
?
;
let
has_legacy_table
=
row
.
0
;
if
!
has_legacy_table
{
return
Ok
(());
}
sqlx
::
raw_sql
(
"insert into player_profiles (userid, nickname)
select userid, nickname
from players
on conflict (userid)
do update set nickname = excluded.nickname;
insert into player_wallets (userid)
select userid
from players
on conflict (userid) do nothing;
drop table if exists players;"
,
)
.execute
(
pool
)
.await
.map_err
(|
err
|
err
.to_string
())
?
;
Ok
(())
}
#[cfg(test)]
mod
tests
{
use
serde_json
::
json
;
use
std
::
time
::{
SystemTime
,
UNIX_EPOCH
};
use
crate
::
commons
::
utils
;
...
...
@@ -153,7 +52,7 @@ mod tests {
.unwrap_or
(
0
);
format!
(
"test_userid_{ts}"
)
}
#[tokio
::
test]
async
fn
test_current_timestamp
()
{
let
ts
=
utils
::
get_current_timestamp
();
...
...
backend/src/router.rs
View file @
889c6ad0
...
...
@@ -13,19 +13,18 @@ pub fn config_router() -> Router {
.layer
(
CorsLayer
::
permissive
())
.layer
(
layer
);
let
layer
=
layer
.compat
();
let
mut
r
=
Router
::
new
()
.push
(
Router
::
with_path
(
config
.socket_path
.as_str
())
.hoop
(
layer
)
.goal
(
hello
),
);
io
.ns
(
config
.client_ns
.as_str
(),
crate
::
protocols
::
socket_io
::
on_connect
,
);
r
=
r
.push
(
Router
::
with_path
(
"/manager/login"
)
.post
(
crate
::
protocols
::
socket_io
::
login
));
r
let
layer
=
layer
.compat
();
Router
::
new
()
.push
(
Router
::
with_path
(
config
.socket_path
.as_str
())
.hoop
(
layer
)
.goal
(
hello
),
)
.push
(
Router
::
with_path
(
"/manager/login"
)
.post
(
crate
::
protocols
::
socket_io
::
login
))
}
pub
fn
config_catcher
()
->
Catcher
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment