Commit ac4af865 authored by 陈冲's avatar 陈冲

fix: 修复部分功能

parent 1a7d7b79
......@@ -6,22 +6,21 @@ mod router;
use commons::utils::CONFIG as config;
use db::init_db;
// 后台测试页,正式线上时不要代理该路径
#[derive(rust_embed::RustEmbed)]
#[folder = "src/web"]
struct AssetsWeb;
#[tokio::main]
async fn main() {
if let Err(err) = init_db().await {
panic!("init db failed: {err}");
}
let router = Router::new().push(router::config_router())
.push(
Router::with_path("/web/{**path}")
.get(salvo::serve_static::static_embed::<AssetsWeb>().fallback("index.html")),
)
;
let mut router = Router::new().push(router::config_router());
if cfg!(debug_assertions) {
#[derive(rust_embed::RustEmbed)]
#[folder = "src/web"]
struct AssetsWeb;
router = router.push(
Router::with_path("/web/{**path}")
.get(salvo::serve_static::static_embed::<AssetsWeb>().fallback("index.html")),
);
}
let host = config.host.clone();
dbg!(&config);
println!("http://{}", host);
......
......@@ -319,7 +319,7 @@ fn emit_msgpack(socket: &SocketRef, event: &str, payload: &Value) {
}
}
/// 发送给所有玩家,不包含管理员。
/// 发送给所有在房间里游玩的玩家
fn broadcast_msgpack_all_player(event: &str, payload: &Value) {
if let Some(payload) = encode_msgpack(payload) {
for socket in CLIENT_PLAYER_MAP.iter() {
......@@ -330,6 +330,16 @@ fn broadcast_msgpack_all_player(event: &str, payload: &Value) {
}
}
}
/// 发送给所有玩家(不管是否在房间里)
fn broadcast_msgpack_all_player_2(event: &str, payload: &Value) {
if let Some(payload) = encode_msgpack(payload) {
for socket in CLIENT_PLAYER_MAP.iter() {
let (state, socks) = socket.value();
_ = socks.emit(event, &payload);
}
}
}
/// 发送给所有管理员
fn broadcast_msgpack_all_admin(event: &str, payload: &Value) {
let Some(payload) = encode_msgpack(payload) else {
......@@ -600,9 +610,9 @@ async fn handle_room_command(
state.status = RoomStatus::Loading;
// let snapshot = state.snapshot();
drop(state);
// dbg!(&CLIENT_PLAYER_MAP.len());
emit_msgpack(&socket, evt, &ok_resp(Some(json!(index))));
broadcast_msgpack_all_player(evt, &ok_resp(Some(json!(index))));
broadcast_msgpack_all_player_2(evt, &ok_resp(Some(json!(index))));
}
}
}
......
......@@ -159,7 +159,7 @@ export function useGameSocket(options: GameSocketOptions) {
break;
}
case 'room_close_result': {
$toast('管理员关闭了房间')
$toast('管理员关闭了游戏房间')
break;
}
default: {
......
<script setup lang="ts">
import { cssAssetUrl } from '@/commons/assets'
import { $getWechat } from '@/commons/utils';
import { useGameSocket } from '@/composables/useGameSocket';
import { onBeforeUnmount, onMounted, ref, watch } from 'vue'
const imageUrls = {
......@@ -22,12 +24,24 @@ const imageUrls = {
// rule: cssAssetUrl('game1/rule.png')
}
const _offSocketMessage = ref<(() => void) | undefined>()
const wechat = $getWechat()
if (wechat) {
const gameId = '';
const { offSocketMessage } = useGameSocket({
gameId,
auth: {
userid: wechat.token,
},
})
_offSocketMessage.value = offSocketMessage
}
onMounted(() => {
document.title = '游戏'
document.title = '互动游戏'
})
onBeforeUnmount(() => {
_offSocketMessage.value?.()
})
</script>
......
......@@ -212,8 +212,8 @@ if (wechat) {
stopGameCountdown()
currentView.value = 'loading'
setDivDescVisible(false)
// alert('管理员关闭了房间')
$toast('管理员关闭了房间')
// alert('管理员关闭了游戏房间')
$toast('管理员关闭了游戏房间')
},
onRoomBack: () => {
resetToLoadingView()
......@@ -226,7 +226,7 @@ if (wechat) {
}
onMounted(() => {
document.title = '游戏 - 击鼓齐福'
document.title = '互动游戏 - 击鼓齐福'
if (token.value) {
window.addEventListener('beforeunload', confirmRefresh)
}
......@@ -309,8 +309,8 @@ const showGameRuleHandler = () => {
background: v-bind('imageUrls.close') center / cover no-repeat;
transform: translateX(-50%) scale(1.4);
position: absolute;
bottom: -75px;
left: 50%;
top: 0;
left: 100%;
}
}
</style>
......@@ -123,8 +123,8 @@ function showLoadingView() {
stopGameCountdown()
currentView.value = 'loading'
setDivDescVisible(false)
// alert('管理员关闭了房间')
$toast('管理员关闭了房间')
// alert('管理员关闭了游戏房间')
$toast('管理员关闭了游戏房间')
}
function resetToLoadingView() {
......@@ -214,7 +214,7 @@ if (wechat) {
}
onMounted(() => {
document.title = '游戏 - 策马迎福'
document.title = '互动游戏 - 策马迎福'
if (token.value) {
window.addEventListener('beforeunload', confirmRefresh)
}
......@@ -293,8 +293,8 @@ onBeforeUnmount(() => {
background: v-bind('imageUrls.close') center / cover no-repeat;
transform: translateX(-50%) scale(1.4);
position: absolute;
bottom: -75px;
left: 50%;
top: 0;
left: 100%;
}
}
</style>
......@@ -150,8 +150,8 @@ function showLoadingView() {
stopGameCountdown()
currentView.value = 'loading'
setDivDescVisible(false)
// alert('管理员关闭了房间')
$toast('管理员关闭了房间')
// alert('管理员关闭了游戏房间')
$toast('管理员关闭了游戏房间')
}
function resetToLoadingView() {
......@@ -253,7 +253,7 @@ if (wechat) {
}
onMounted(() => {
document.title = '游戏 - 圈彩纳福'
document.title = '互动游戏 - 圈彩纳福'
if (token.value) {
window.addEventListener('beforeunload', confirmRefresh)
}
......@@ -376,8 +376,8 @@ const rankCloseHandler = () => {
background: v-bind('imageUrls.close') center / cover no-repeat;
transform: translateX(-50%) scale(1.4);
position: absolute;
bottom: -75px;
left: 50%;
top: 0;
left: 100%;
}
}
......
......@@ -126,6 +126,20 @@ onMounted(() => {
transform: translateX(-50%);
}
@keyframes loading-text-scale {
0%,
100% {
transform: translateX(-50%) scale(1);
}
50% {
transform: translateX(-50%) scale(1.08);
}
}
.txt-loading {
position: absolute;
bottom: 4.74%;
......@@ -140,6 +154,7 @@ onMounted(() => {
font-size: 36px;
color: #FFFFFF;
line-height: 50px;
animation: loading-text-scale 1.2s ease-in-out infinite;
}
.txt-loading2 {
......
......@@ -244,7 +244,7 @@ if (wechat) {
stopGameCountdown()
currentView.value = 'loading'
setDivDescVisible(false)
$toast('管理员关闭了房间')
$toast('管理员关闭了游戏房间')
},
onRoomBack: () => {
resetToLoadingView()
......@@ -257,7 +257,7 @@ if (wechat) {
}
onMounted(() => {
document.title = '游戏 - 福运当头'
document.title = '互动游戏 - 福运当头'
if (token.value) {
window.addEventListener('beforeunload', confirmRefresh)
}
......@@ -384,8 +384,8 @@ const rankCloseHandler = () => {
background: v-bind('imageUrls.close') center / cover no-repeat;
transform: translateX(-50%) scale(1.4);
position: absolute;
bottom: -75px;
left: 50%;
top: 0;
left: 100%;
}
}
......
......@@ -254,6 +254,7 @@ function ensureConfirmElement() {
'background: #fff',
'color: #666',
'font-size: 24px',
'cursor: pointer',
].join(';');
confirmCancelElement.onclick = () => closeConfirm(false);
......@@ -267,6 +268,7 @@ function ensureConfirmElement() {
'background: #AA0000',
'color: #fff',
'font-size: 24px',
'cursor: pointer',
].join(';');
confirmOkElement.onclick = () => closeConfirm(true);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment