Can you give the name of the author of the posted code?
This is my code. I have made a mod to Alliance server. My FLHook AE = FLHook 1.6.0 without plugins + FLShell features + fixed reputation
Can you give the name of the author of the posted code?
This is my code. I have made a mod to Alliance server. My FLHook AE = FLHook 1.6.0 without plugins + FLShell features + fixed reputation
Someone can will make a plugin based on this code. This is flshell-like restarts
void UserCmd_Dots(uint iClientID, wstring wscParam)
{
if(set_bAllowRestarts)
{
WIN32_FIND_DATA FileData;
HANDLE hSearch;
wchar_t oldDir[MAX_PATH];
GetCurrentDirectoryW(MAX_PATH,oldDir);
SetCurrentDirectoryW(set_wscRestartDotsPath.c_str());
BOOL fFinished = FALSE;
// Start searching for .fl files in the current directory.
hSearch = FindFirstFile("*.fl", &FileData);
if (hSearch == INVALID_HANDLE_VALUE)
{
PrintUserCmdText(iClientID, L"Dots not found");
FindClose(hSearch);
SetCurrentDirectoryW(oldDir);
return;
}
wstring wscMsg =L"";
string scFileName="";
//
while (!fFinished)
{
// add filename
scFileName = FileData.cFileName;
size_t len = scFileName.length();
scFileName.erase(len-3,len);
if (scFileName[0]!='_')
wscMsg+=stows(scFileName)+L" ";
if (!FindNextFile(hSearch, &FileData))
{
if (GetLastError() == ERROR_NO_MORE_FILES)
{
PrintUserCmdText(iClientID, L"You can use these restarts:");
PrintUserCmdText(iClientID, wscMsg);
fFinished = TRUE;
}
else
{
PrintUserCmdText(iClientID, L"Internal server error");
FindClose(hSearch);
SetCurrentDirectoryW(oldDir);
return;
}
}
}
// Close the search handle.
FindClose(hSearch);
SetCurrentDirectoryW(oldDir);
}
else
{
PRINT_DISABLED();
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
void UserCmd_Restart(uint iClientID, wstring wscParam)
{
if(ClientInfo[iClientID].bAllowRestart)
{
wstring wscError[] =
{
L"Error: Invalid parameters",
L"Usage: /restart <faction>",
};
wstring wscFraction = GetParam(wscParam, ' ', 0);
if(!wscFraction.length())
PRINT_ERROR();
// get rank for MaxRank limit
int iRank;
pub::Player::GetRank(iClientID, iRank);
// searching restart
string scPathDot=wstos(set_wscRestartDotsPath) + wstos(wscFraction)+".fl";
if(_access( scPathDot.c_str(), 0 ))
{// file not exists
scPathDot=wstos(set_wscRestartDotsPath) + "_" + wstos(wscFraction)+".fl";
if(_access( scPathDot.c_str(), 0 ))
{
PRINT_ERROR();
return;
}
}
if (iRank > set_iMaxRank)
{
PrintUserCmdText(iClientID,L"Error: You must create a new char to restart. Your rank is too high");
return;
}
wstring wscCharname=Players.GetActiveCharacterName(iClientID);
// Kick player
CAccount *acc = Players.FindAccountFromClientID(iClientID);
HkMsgAndKick(iClientID, L" restarting... ",set_iKickMsgPeriod);
acc->ForceLogout();
// get savefile
wstring wscDir;
if(!HKHKSUCCESS(HkGetAccountDirName(acc, wscDir)))
{
string err=wstos(L"Restart failed. " + wscCharname + L" not exists. wscDir = "+wscDir);
AddLog(err.c_str());
return;// HKE_CHAR_DOES_NOT_EXIST;
}
wstring wscFile;
HkGetCharFileName(wscCharname, wscFile);
string scCharFile = scAcctPath + wstos(wscDir) + "\\" + wstos(wscFile) + ".fl";
// delete savefile
if(!(_access( scCharFile.c_str(), 0 )))
{// file exists
DeleteFile(scCharFile.c_str());
}
// rewrite savefile
if(!(CopyFile(scPathDot.c_str(),scCharFile.c_str(),FALSE)))
{
string err=wstos(L"Restart failed. " + wscCharname + L". Files not copied ");
AddLog(err.c_str());
return;// HKE_CHAR_DOES_NOT_EXIST;
}
// restore nickname. Copy&Paste from HkRename
wstring wscNewNameString = L"";
for(uint i = 0; (i < wscCharname.length()); i++)
{
char cHiByte = wscCharname[i] >> 8;
char cLoByte = wscCharname[i] & 0xFF;
wchar_t wszBuf[8];
swprintf(wszBuf, L"%02X%02X", ((uint)cHiByte) & 0xFF, ((uint)cLoByte) & 0xFF);
wscNewNameString += wszBuf;
}
if(HkIsEncoded(scCharFile))
{
string scCharFileNew = scCharFile + ".ini";
if(!flc_decode(scCharFile.c_str(), scCharFileNew.c_str()))
{
string err=wstos(L"Restart failed. Name " + wscCharname + L" not set. File ")+scCharFile;
AddLog(err.c_str());
return;// HKE_COULD_NOT_DECODE_CHARFILE;
}
IniWrite(scCharFileNew, "Player", "name", wstos(wscNewNameString));
if(!flc_encode(scCharFileNew.c_str(), scCharFile.c_str()))
{
string err=wstos(L"Restart failed. Name " + wscCharname + L" not set. File ")+scCharFile;
AddLog(err.c_str());
return;// HKE_COULD_NOT_ENCODE_CHARFILE;
}
DeleteFile(scCharFileNew.c_str());
}
else
{
IniWrite(scCharFile, "Player", "name", wstos(wscNewNameString));
}
}
else
{
PRINT_DISABLED();
}
}
[/i][/i]</faction>