Skip to content

Commit b03051d

Browse files
author
Dr.Abc
committed
fix a issue when save voice ban data
1 parent 62052aa commit b03051d

File tree

4 files changed

+32
-18
lines changed

4 files changed

+32
-18
lines changed

src/Header/Var/voice_status.h

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class CVoiceStatus{
2828

2929
// Call from HUD_Frame each frame.
3030
void HUD_Frame(double frametime);
31+
// For save data
32+
void HUD_Shutdown();
3133
// Called when a player starts or stops talking.
3234
// entindex is -1 to represent the local client talking (before the data comes back from the server).
3335
// When the server acknowledges that the local client is talking, then entindex will be gEngfuncs.GetLocalPlayer().

src/Source/Var/voice_banmgr.cpp

+24-17
Original file line numberDiff line numberDiff line change
@@ -11,35 +11,42 @@
1111

1212

1313
#define BANMGR_FILEVERSION 1
14-
char const* g_pBanMgrFilename = "abcenchance/voice_ban.dt";
14+
char const g_pBanMgrFilename[] = "abcenchance/";
1515

1616
CVoiceBanMgr::CVoiceBanMgr(){
1717
Clear();
1818
}
1919
bool CVoiceBanMgr::Init(){
2020
char filename[MAX_PATH];
21-
vgui::filesystem()->GetLocalPath(g_pBanMgrFilename, filename, MAX_PATH);
22-
std::ifstream ifs(filename, std::ios::binary);
23-
if (ifs.is_open()) {
24-
while (!ifs.eof()) {
25-
uint64 steamid = 0;
26-
ifs.read(reinterpret_cast<char*>(&steamid), sizeof(uint64));
27-
m_aryBannedPlayer.push_back(steamid);
21+
const char* result = vgui::filesystem()->GetLocalPath(g_pBanMgrFilename, filename, MAX_PATH);
22+
if (result != nullptr) {
23+
Q_snprintf(filename, MAX_PATH, "%s/voice_ban.dt", filename);
24+
std::ifstream ifs(filename, std::ios::binary);
25+
if (ifs.is_open()) {
26+
while (!ifs.eof()) {
27+
uint64 steamid = 0;
28+
ifs.read(reinterpret_cast<char*>(&steamid), sizeof(uint64));
29+
m_aryBannedPlayer.push_back(steamid);
30+
}
31+
ifs.close();
2832
}
29-
ifs.close();
33+
return true;
3034
}
31-
return true;
35+
return false;
3236
}
3337
void CVoiceBanMgr::Save(){
3438
char filename[MAX_PATH];
35-
vgui::filesystem()->GetLocalPath(g_pBanMgrFilename, filename, MAX_PATH);
36-
std::ofstream ofs(filename, std::ios::binary);
37-
if (ofs.is_open()) {
38-
for (auto iter = m_aryBannedPlayer.begin(); iter != m_aryBannedPlayer.end(); iter++) {
39-
uint64 steamid = *iter;
40-
ofs.write(reinterpret_cast<char*>(steamid), sizeof(uint64));
39+
const char* result = vgui::filesystem()->GetLocalPath(g_pBanMgrFilename, filename, MAX_PATH);
40+
if (result != nullptr) {
41+
Q_snprintf(filename, MAX_PATH, "%s/voice_ban.dt", filename);
42+
std::ofstream ofs(filename, std::ios::binary);
43+
if (ofs.is_open()) {
44+
for (auto iter = m_aryBannedPlayer.begin(); iter != m_aryBannedPlayer.end(); iter++) {
45+
uint64 steamid = *iter;
46+
ofs.write(reinterpret_cast<char*>(steamid), sizeof(uint64));
47+
}
48+
ofs.close();
4149
}
42-
ofs.close();
4350
}
4451
}
4552
bool CVoiceBanMgr::GetPlayerBan(uint64 steamid){

src/Source/Var/voice_status.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ CVoiceStatus::CVoiceStatus(){
5454

5555
CVoiceStatus::~CVoiceStatus(){
5656
g_pInternalVoiceStatus = nullptr;
57-
m_BanMgr.Save();
5857
}
5958

6059
void CVoiceStatus::HUD_Init(){
@@ -86,6 +85,10 @@ void CVoiceStatus::HUD_Frame(double frametime){
8685
UpdateServerState(false);
8786
}
8887

88+
void CVoiceStatus::HUD_Shutdown(){
89+
m_BanMgr.Save();
90+
}
91+
8992
void CVoiceStatus::UpdateSpeakerStatus( int entindex, bool bTalking ){
9093
cvar_t *pVoiceLoopback = nullptr;
9194
if ( CVAR_GET_FLOAT( "voice_clientdebug" ) ){

src/Source/exportfuncs.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@ void HUD_Shutdown(void){
409409
FreeParticleMan();
410410
UninstallClientHook();
411411
CHttpClient::ShutDown();
412+
413+
GetClientVoiceMgr()->HUD_Shutdown();
412414
abcconfig::SaveJson();
413415
}
414416

0 commit comments

Comments
 (0)