1 // Ryzom - MMORPG Framework <http://dev.ryzom.com/projects/ryzom/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This source file has been modified by the following contributors:
5 // Copyright (C) 2019 Jan BOON (Kaetemi) <jan.boon@kaetemi.be>
7 // This program is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Affero General Public License as
9 // published by the Free Software Foundation, either version 3 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU Affero General Public License for more details.
17 // You should have received a copy of the GNU Affero General Public License
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "permanent_ban.h"
22 #include "nel/misc/file.h"
23 #include "nel/misc/path.h"
24 #include "nel/misc/big_file.h"
25 #include "nel/misc/random.h"
28 using namespace NLMISC
;
31 #define REGKEY_RYZOM_PATH L"Software\\Nevrax\\ryzom"
32 #define REGKEY_PERMANENT_BAN L"PB"
35 // ************************************************************
36 static void setPermanentBanRegistryKey(bool on
)
39 nlinfo("Not implemented");
42 if (RegCreateKeyW(HKEY_CURRENT_USER
, REGKEY_RYZOM_PATH
, &hKey
)==ERROR_SUCCESS
)
44 DWORD permanentBan
= on
? 1 : 0;
45 LONG result
= RegSetValueExW(hKey
, REGKEY_PERMANENT_BAN
, 0, REG_DWORD
, (LPBYTE
)&permanentBan
, 4);
47 if (result
!= ERROR_SUCCESS
)
49 nlwarning("pb key not created");
54 nlwarning("pb key not created");
59 // ************************************************************
60 static bool getPermanentBanRegistryKey()
63 return false; // not implemented
66 if (RegOpenKeyExW(HKEY_CURRENT_USER
, REGKEY_RYZOM_PATH
, 0, KEY_READ
, &hKey
) == ERROR_SUCCESS
)
70 DWORD dataSize
= sizeof(DWORD
);
72 RegQueryValueExW(hKey
, REGKEY_PERMANENT_BAN
, 0, &type
, (LPBYTE
)&permanentBan
, &dataSize
);
74 if (type
== REG_DWORD
&& dataSize
== sizeof(DWORD
))
76 return permanentBan
!= 0;
84 // ***********************************************************
85 static void setPermanentBanFileMarker(const std::string
&path
, bool on
)
91 // simply touch a file
94 SetFileAttributesW(nlUtf8ToWide(path
), FILE_ATTRIBUTE_HIDDEN
| FILE_ATTRIBUTE_SYSTEM
);
97 catch(const EStream
&e
)
104 CFile::deleteFile(path
);
108 // ***********************************************************
109 static bool getPermanentBanFileMarker(const std::string
&path
)
111 return CFile::isExists(path
);
114 #define PERMANENT_BAN_FILE0 "c:\\3289763c1ecd044e"
115 #define PERMANENT_BAN_FILE1 "78d0732e50bf2bbd"
117 // ************************************************************
118 void setPermanentBanMarkers(bool on
)
120 setPermanentBanRegistryKey(on
);
121 setPermanentBanFileMarker(PERMANENT_BAN_FILE0
, on
);
122 setPermanentBanFileMarker(CPath::getWindowsDirectory() + PERMANENT_BAN_FILE1
, on
);
126 // ************************************************************
127 bool testPermanentBanMarkers()
129 /*#ifndef NL_OS_WINDOWS
130 nlinfo("Not implemented");
133 if (getPermanentBanRegistryKey()) return true;
134 if (getPermanentBanFileMarker(PERMANENT_BAN_FILE0)) return true;
135 if (getPermanentBanFileMarker(CPath::getWindowsDirectory() + PERMANENT_BAN_FILE1)) return true;
143 // mark a bnp file without corrupting its datas (this force the patch to be applied the next time the client is launched, thus delaying the trouble maker)
144 static void markBNPFile(std::string
&path
)
147 rnd
.srand((sint32
) CTime::getLocalTime());
149 uint32 nFileSize
=CFile::getFileSize(path
);
150 if (!nFileSize
) return;
151 FILE *f
= nlfopen(path
, "rb+");
154 if (nlfseek64 (f
, nFileSize
-4, SEEK_SET
) != 0)
160 uint32 nOffsetFromBeginning
;
161 if (fread (&nOffsetFromBeginning
, sizeof(uint32
), 1, f
) != 1)
168 NLMISC_BSWAP32(nOffsetFromBeginning
);
171 if (nlfseek64 (f
, nOffsetFromBeginning
, SEEK_SET
) != 0)
177 // Read the file count
179 if (fread (&nNbFile
, sizeof(uint32
), 1, f
) != 1)
186 NLMISC_BSWAP32(nNbFile
);
189 for (uint32 i
= 0; i
< nNbFile
; ++i
)
191 char FileName
[MAX_PATH
];
193 if (fread (&nStringSize
, 1, 1, f
) != 1)
199 sint64 currPos
= nlftell64(f
);
205 if (fread (FileName
, 1, nStringSize
, f
) != nStringSize
)
211 FileName
[nStringSize
] = 0;
213 for(uint k
= 0; k
< nStringSize
; ++k
)
215 if (rnd
.rand() & 1) FileName
[k
] = toupper(FileName
[k
]);
216 else FileName
[k
] = tolower(FileName
[k
]);
220 if (nlfseek64 (f
, currPos
, SEEK_SET
) != 0)
227 // write shuffled version
228 if (fwrite(FileName
, 1, nStringSize
, f
) != nStringSize
)
236 if (fread (&nFileSize2
, sizeof(uint32
), 1, f
) != 1)
243 NLMISC_BSWAP32(nFileSize2
);
247 if (fread (&nFilePos
, sizeof(uint32
), 1, f
) != 1)
254 NLMISC_BSWAP32(nFilePos
);
261 // ************************************************************
262 void applyPermanentBanPunishment()
264 // go in the data directory & touch all bnp files so that the client should repatch all its datas
265 std::vector
<std::string
> bigFilePaths
;
266 CBigFile::getInstance().getBigFilePaths(bigFilePaths
);
267 for(uint k
= 0; k
< bigFilePaths
.size(); ++k
)
269 markBNPFile(bigFilePaths
[k
]);