Compare commits

..

2 commits

Author SHA1 Message Date
YYHEggEgg
6ac186a1cf command: player kick [uid] [reason] 2024-07-31 00:37:43 +08:00
YYHEggEgg
28a3c8d154 Gacha Model bugfix: post_configure on creating 2024-07-31 00:37:13 +08:00
6 changed files with 96 additions and 36 deletions

View file

@ -87,5 +87,6 @@ impl CommandManager {
player::procedure "[player_uid] [procedure_id]" "changes current beginner procedure id, parameter -1 can be used for skipping it"; player::procedure "[player_uid] [procedure_id]" "changes current beginner procedure id, parameter -1 can be used for skipping it";
avatar::add "[player_uid] [avatar_id]" "gives avatar with specified id to player"; avatar::add "[player_uid] [avatar_id]" "gives avatar with specified id to player";
item::add_weapon "[player_uid] [weapon_id]" "gives weapon with specified id to player"; item::add_weapon "[player_uid] [weapon_id]" "gives weapon with specified id to player";
player::kick "[player_uid] [reason]" "kick the specified player (reason is optional)";
} }
} }

View file

@ -1,5 +1,5 @@
use data::tables::{AvatarBaseID, ProcedureConfigID}; use data::tables::{AvatarBaseID, ProcedureConfigID};
use proto::PlayerSyncScNotify; use proto::{DisconnectReason, DisconnectScNotify, PlayerSyncScNotify};
use crate::ServerState; use crate::ServerState;
@ -126,3 +126,44 @@ pub async fn procedure(
"successfully changed procedure_id to {procedure_id:?}" "successfully changed procedure_id to {procedure_id:?}"
)) ))
} }
pub async fn kick(
args: ArgSlice<'_>,
state: &ServerState,
) -> Result<String, Box<dyn std::error::Error>> {
const USAGE: &str = "Usage: player kick [player_uid]";
if args.len() > 2 {
return Ok(USAGE.to_string());
}
let uid = args[0].parse::<u32>()?;
let reason = match args.get(1) {
Some(arg) => match arg.parse::<i32>() {
Ok(val) => val,
Err(_err) => 1,
},
None => 1,
};
let reason_str = match DisconnectReason::try_from(reason) {
Ok(converted_enum) => converted_enum.as_str_name().to_owned(),
Err(_err) => reason.to_string(),
};
let Some(player_lock) = state.player_mgr.get_player(uid).await else {
return Ok(String::from("player not found"));
};
let session_id = player_lock.lock().await.current_session_id();
if let Some(session) = session_id.map(|id| state.session_mgr.get(id)).flatten() {
session
.notify(DisconnectScNotify { reason: reason })
.await?;
tokio::time::sleep(tokio::time::Duration::from_millis(50)).await;
session.shutdown().await?;
Ok(format!("kicked player, uid: {uid}, reason: {reason_str}"))
} else {
Ok(format!("player uid: {uid} is not online yet."))
}
}

View file

@ -7,11 +7,19 @@ use rand::{thread_rng, Rng};
use std::collections::{HashMap, HashSet}; use std::collections::{HashMap, HashSet};
use std::hash::{BuildHasher, Hash}; use std::hash::{BuildHasher, Hash};
#[derive(Default)]
pub struct GachaModel { pub struct GachaModel {
pub gacha_bin: GachaModelBin, pub gacha_bin: GachaModelBin,
} }
impl Default for GachaModel {
fn default() -> GachaModel {
let result = GachaModel {
gacha_bin: GachaModelBin::default(),
};
result.post_deserialize()
}
}
impl GachaModel { impl GachaModel {
pub fn from_bin(gacha_bin: GachaModelBin) -> Self { pub fn from_bin(gacha_bin: GachaModelBin) -> Self {
let result = Self { gacha_bin }; let result = Self { gacha_bin };

View file

@ -62,6 +62,12 @@ impl Player {
.add_resource(ItemStatic::FrontendGold as u32, 1_000_000); .add_resource(ItemStatic::FrontendGold as u32, 1_000_000);
self.item_model self.item_model
.add_resource(ItemStatic::GameDiamond as u32, 1_000_000); .add_resource(ItemStatic::GameDiamond as u32, 1_000_000);
self.item_model
.add_resource(ItemStatic::GachaTicketEvent as u32, 30_000);
self.item_model
.add_resource(ItemStatic::GachaTicketStandard as u32, 30_000);
self.item_model
.add_resource(ItemStatic::GachaTicketBangboo as u32, 30_000);
self.item_model.add_resource(ItemStatic::Energy as u32, 240); self.item_model.add_resource(ItemStatic::Energy as u32, 240);
} }

View file

@ -247,4 +247,8 @@ impl NetSession {
pub fn set_state(&self, state: NetSessionState) { pub fn set_state(&self, state: NetSessionState) {
self.state.store(state, std::sync::atomic::Ordering::SeqCst); self.state.store(state, std::sync::atomic::Ordering::SeqCst);
} }
pub async fn shutdown(&self) -> Result<(), std::io::Error> {
self.writer.lock().await.shutdown().await
}
} }

View file

@ -28249,8 +28249,8 @@ pub struct Flpgnabkedc {
#[derive(proto_gen::XorFields)] #[derive(proto_gen::XorFields)]
#[allow(clippy::derive_partial_eq_without_eq)] #[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct Igapopdfcef { pub struct DisconnectScNotify {
#[prost(enumeration = "Obpfhejepck", tag = "15")] #[prost(enumeration = "DisconnectReason", tag = "15")]
pub reason: i32, pub reason: i32,
} }
#[derive(proto_gen::CmdID)] #[derive(proto_gen::CmdID)]
@ -54259,9 +54259,9 @@ pub enum ItemStatic {
FrontendGold = 10, FrontendGold = 10,
GameDiamond = 100, GameDiamond = 100,
RechargeDiamond = 101, RechargeDiamond = 101,
Lcdlfoheaim = 110, GachaTicketStandard = 110,
Mndhfchkhcl = 111, GachaTicketEvent = 111,
Fcffdnjnemf = 112, GachaTicketBangboo = 112,
Exp = 201, Exp = 201,
Energy = 501, Energy = 501,
Gdglcfmgoji = 3000001, Gdglcfmgoji = 3000001,
@ -54280,9 +54280,9 @@ impl ItemStatic {
ItemStatic::FrontendGold => "ITEM_STATIC_FRONTEND_GOLD", ItemStatic::FrontendGold => "ITEM_STATIC_FRONTEND_GOLD",
ItemStatic::GameDiamond => "ITEM_STATIC_GAME_DIAMOND", ItemStatic::GameDiamond => "ITEM_STATIC_GAME_DIAMOND",
ItemStatic::RechargeDiamond => "ITEM_STATIC_RECHARGE_DIAMOND", ItemStatic::RechargeDiamond => "ITEM_STATIC_RECHARGE_DIAMOND",
ItemStatic::Lcdlfoheaim => "ItemStatic_LCDLFOHEAIM", ItemStatic::GachaTicketStandard => "ItemStatic_GACHA_TICKET_STANDARD",
ItemStatic::Mndhfchkhcl => "ItemStatic_MNDHFCHKHCL", ItemStatic::GachaTicketEvent => "ItemStatic_GACHA_TICKET_EVENT",
ItemStatic::Fcffdnjnemf => "ItemStatic_FCFFDNJNEMF", ItemStatic::GachaTicketBangboo => "ItemStatic_GACHA_TICKET_BANGBOO",
ItemStatic::Exp => "ITEM_STATIC_EXP", ItemStatic::Exp => "ITEM_STATIC_EXP",
ItemStatic::Energy => "ITEM_STATIC_ENERGY", ItemStatic::Energy => "ITEM_STATIC_ENERGY",
ItemStatic::Gdglcfmgoji => "ItemStatic_GDGLCFMGOJI", ItemStatic::Gdglcfmgoji => "ItemStatic_GDGLCFMGOJI",
@ -54298,9 +54298,9 @@ impl ItemStatic {
"ITEM_STATIC_FRONTEND_GOLD" => Some(Self::FrontendGold), "ITEM_STATIC_FRONTEND_GOLD" => Some(Self::FrontendGold),
"ITEM_STATIC_GAME_DIAMOND" => Some(Self::GameDiamond), "ITEM_STATIC_GAME_DIAMOND" => Some(Self::GameDiamond),
"ITEM_STATIC_RECHARGE_DIAMOND" => Some(Self::RechargeDiamond), "ITEM_STATIC_RECHARGE_DIAMOND" => Some(Self::RechargeDiamond),
"ItemStatic_LCDLFOHEAIM" => Some(Self::Lcdlfoheaim), "ItemStatic_GACHA_TICKET_STANDARD" => Some(Self::GachaTicketStandard),
"ItemStatic_MNDHFCHKHCL" => Some(Self::Mndhfchkhcl), "ItemStatic_GACHA_TICKET_EVENT" => Some(Self::GachaTicketEvent),
"ItemStatic_FCFFDNJNEMF" => Some(Self::Fcffdnjnemf), "ItemStatic_GACHA_TICKET_BANGBOO" => Some(Self::GachaTicketBangboo),
"ITEM_STATIC_EXP" => Some(Self::Exp), "ITEM_STATIC_EXP" => Some(Self::Exp),
"ITEM_STATIC_ENERGY" => Some(Self::Energy), "ITEM_STATIC_ENERGY" => Some(Self::Energy),
"ItemStatic_GDGLCFMGOJI" => Some(Self::Gdglcfmgoji), "ItemStatic_GDGLCFMGOJI" => Some(Self::Gdglcfmgoji),
@ -55320,9 +55320,9 @@ impl Jiedoddkipa {
#[derive(proto_gen::XorFields)] #[derive(proto_gen::XorFields)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)] #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)] #[repr(i32)]
pub enum Obpfhejepck { pub enum DisconnectReason {
Domjllafeac = 0, Domjllafeac = 0,
Gdbjccehcdb = 1, ServerRelogin = 1,
Clcbejonokn = 2, Clcbejonokn = 2,
Jlimlghggke = 3, Jlimlghggke = 3,
Omjjggajcbh = 4, Omjjggajcbh = 4,
@ -55332,38 +55332,38 @@ pub enum Obpfhejepck {
Lgjemnlahcp = 8, Lgjemnlahcp = 8,
Mfgomdhiejh = 9, Mfgomdhiejh = 9,
} }
impl Obpfhejepck { impl DisconnectReason {
/// String value of the enum field names used in the ProtoBuf definition. /// String value of the enum field names used in the ProtoBuf definition.
/// ///
/// The values are not transformed in any way and thus are considered stable /// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use. /// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str { pub fn as_str_name(&self) -> &'static str {
match self { match self {
Obpfhejepck::Domjllafeac => "OBPFHEJEPCK_DOMJLLAFEAC", DisconnectReason::Domjllafeac => "DISCONNECT_REASON_DOMJLLAFEAC",
Obpfhejepck::Gdbjccehcdb => "OBPFHEJEPCK_GDBJCCEHCDB", DisconnectReason::ServerRelogin => "DISCONNECT_REASON_SERVER_RELOGIN",
Obpfhejepck::Clcbejonokn => "OBPFHEJEPCK_CLCBEJONOKN", DisconnectReason::Clcbejonokn => "DISCONNECT_REASON_CLCBEJONOKN",
Obpfhejepck::Jlimlghggke => "OBPFHEJEPCK_JLIMLGHGGKE", DisconnectReason::Jlimlghggke => "DISCONNECT_REASON_JLIMLGHGGKE",
Obpfhejepck::Omjjggajcbh => "OBPFHEJEPCK_OMJJGGAJCBH", DisconnectReason::Omjjggajcbh => "DISCONNECT_REASON_OMJJGGAJCBH",
Obpfhejepck::Kdpiceebneb => "OBPFHEJEPCK_KDPICEEBNEB", DisconnectReason::Kdpiceebneb => "DISCONNECT_REASON_KDPICEEBNEB",
Obpfhejepck::Nmcpihldicf => "OBPFHEJEPCK_NMCPIHLDICF", DisconnectReason::Nmcpihldicf => "DISCONNECT_REASON_NMCPIHLDICF",
Obpfhejepck::Ihcmpplkgkn => "OBPFHEJEPCK_IHCMPPLKGKN", DisconnectReason::Ihcmpplkgkn => "DISCONNECT_REASON_IHCMPPLKGKN",
Obpfhejepck::Lgjemnlahcp => "OBPFHEJEPCK_LGJEMNLAHCP", DisconnectReason::Lgjemnlahcp => "DISCONNECT_REASON_LGJEMNLAHCP",
Obpfhejepck::Mfgomdhiejh => "OBPFHEJEPCK_MFGOMDHIEJH", DisconnectReason::Mfgomdhiejh => "DISCONNECT_REASON_MFGOMDHIEJH",
} }
} }
/// Creates an enum from field names used in the ProtoBuf definition. /// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> { pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value { match value {
"OBPFHEJEPCK_DOMJLLAFEAC" => Some(Self::Domjllafeac), "DISCONNECT_REASON_DOMJLLAFEAC" => Some(Self::Domjllafeac),
"OBPFHEJEPCK_GDBJCCEHCDB" => Some(Self::Gdbjccehcdb), "DISCONNECT_REASON_SERVER_RELOGIN" => Some(Self::ServerRelogin),
"OBPFHEJEPCK_CLCBEJONOKN" => Some(Self::Clcbejonokn), "DISCONNECT_REASON_CLCBEJONOKN" => Some(Self::Clcbejonokn),
"OBPFHEJEPCK_JLIMLGHGGKE" => Some(Self::Jlimlghggke), "DISCONNECT_REASON_JLIMLGHGGKE" => Some(Self::Jlimlghggke),
"OBPFHEJEPCK_OMJJGGAJCBH" => Some(Self::Omjjggajcbh), "DISCONNECT_REASON_OMJJGGAJCBH" => Some(Self::Omjjggajcbh),
"OBPFHEJEPCK_KDPICEEBNEB" => Some(Self::Kdpiceebneb), "DISCONNECT_REASON_KDPICEEBNEB" => Some(Self::Kdpiceebneb),
"OBPFHEJEPCK_NMCPIHLDICF" => Some(Self::Nmcpihldicf), "DISCONNECT_REASON_NMCPIHLDICF" => Some(Self::Nmcpihldicf),
"OBPFHEJEPCK_IHCMPPLKGKN" => Some(Self::Ihcmpplkgkn), "DISCONNECT_REASON_IHCMPPLKGKN" => Some(Self::Ihcmpplkgkn),
"OBPFHEJEPCK_LGJEMNLAHCP" => Some(Self::Lgjemnlahcp), "DISCONNECT_REASON_LGJEMNLAHCP" => Some(Self::Lgjemnlahcp),
"OBPFHEJEPCK_MFGOMDHIEJH" => Some(Self::Mfgomdhiejh), "DISCONNECT_REASON_MFGOMDHIEJH" => Some(Self::Mfgomdhiejh),
_ => None, _ => None,
} }
} }