📄 lmain.pas
字号:
function KickUser(Config: pTConfig; UserInfo: pTUserInfo; nKickType: Integer): Boolean;
var
I: Integer;
II: Integer;
GateInfo: pTGateInfo;
User: pTUserInfo;
resourcestring
sKickMsg = 'Kick: %s';
begin
Result := False;
if Config.boShowDetailMsg then
MainOutMessage(Format(sKickMsg, [UserInfo.sUserIPaddr]));
case nKickType of
0: SendGateKickMsg(UserInfo.Socket, UserInfo.sSockIndex);
1: SendGateAddTempBlockList(UserInfo.Socket, UserInfo.sSockIndex);
2: SendGateAddBlockList(UserInfo.Socket, UserInfo.sSockIndex);
end;
Result := True;
{Result := False;
EnterCriticalSection(Config.GateCriticalSection);
try
for I := 0 to Config.GateList.Count - 1 do begin
GateInfo := Config.GateList.Items[I];
for II := 0 to GateInfo.UserList.Count - 1 do begin
User := GateInfo.UserList.Items[II];
if User = UserInfo then begin
if Config.boShowDetailMsg then
MainOutMessage(format(sKickMsg, [UserInfo.sUserIPaddr]));
case nKickType of
0: SendGateKickMsg(GateInfo.Socket, UserInfo.sSockIndex);
1: SendGateAddTempBlockList(GateInfo.Socket, UserInfo.sSockIndex);
2: SendGateAddBlockList(GateInfo.Socket, UserInfo.sSockIndex);
end;
GateInfo.UserList.Delete(II);
Dispose(UserInfo);
Result := true;
break;
end;
end;
end;
finally
LeaveCriticalSection(Config.GateCriticalSection);
end; }
end;
procedure AccountLogin(Config: pTConfig; UserInfo: pTUserInfo; sData: string);
var
sLoginID: string;
sPassword: string;
nCode: Integer;
boNeedUpdate: Boolean;
DefMsg: TDefaultMessage;
UserEntry: TUserEntry;
nIDCost: Integer;
nIPCost: Integer;
nIDCostIndex: Integer;
nIPCostIndex: Integer;
DBRecord: TAccountDBRecord;
n10: Integer;
boPayCost: Boolean;
sServerName: string;
begin
try
sPassword := GetValidStr3(DecodeString(sData), sLoginID, ['/']);
nCode := 0;
boNeedUpdate := False;
try
if AccountDB.Open then begin
n10 := AccountDB.Index(sLoginID);
if (n10 >= 0) and (AccountDB.Get(n10, DBRecord) >= 0) then begin
{自动解除锁定账号}
if (Config.boUnLockAccount) and (DBRecord.nErrorCount >= 5) and ((GetTickCount - DBRecord.dwActionTick) >= Config.dwUnLockAccountTime * 60 * 1000) then begin
DBRecord.nErrorCount := 0;
DBRecord.dwActionTick := 0;
DBRecord.dwActionTick := GetTickCount - 70000;
end;
if (DBRecord.nErrorCount < 5) or ((GetTickCount - DBRecord.dwActionTick) > 60000) then begin
if DBRecord.UserEntry.sPassword = sPassword then begin
DBRecord.nErrorCount := 0;
if (DBRecord.UserEntry.sUserName = '') or (DBRecord.UserEntryAdd.sQuiz2 = '') then begin
UserEntry := DBRecord.UserEntry;
boNeedUpdate := True;
end;
DBRecord.Header.CreateDate := UserInfo.dtDateTime;
nCode := 1;
end else begin
Inc(DBRecord.nErrorCount);
DBRecord.dwActionTick := GetTickCount();
nCode := -1;
end;
AccountDB.Update(n10, DBRecord);
end else begin
nCode := -2;
DBRecord.dwActionTick := GetTickCount();
AccountDB.Update(n10, DBRecord);
end;
end;
end;
finally
AccountDB.Close;
end;
if (nCode = 1) and IsLogin(Config, sLoginID) then begin
SessionKick(Config, sLoginID);
nCode := -3;
end;
if boNeedUpdate then begin
DefMsg := MakeDefaultMsg(SM_NEEDUPDATE_ACCOUNT, 0, 0, 0, 0);
SendGateMsg(UserInfo.Socket,
UserInfo.sSockIndex,
EncodeMessage(DefMsg) + EncodeBuffer(@UserEntry, SizeOf(TUserEntry)));
end;
if nCode = 1 then begin
UserInfo.sAccount := sLoginID;
UserInfo.nSessionID := GetSessionID();
UserInfo.boSelServer := False;
try
CS_DB.Enter;
nIDCostIndex := Config.AccountCostList.GetIndex(UserInfo.sAccount);
nIPCostIndex := Config.IPaddrCostList.GetIndex(UserInfo.sUserIPaddr);
nIDCost := 0;
nIPCost := 0;
boPayCost := False;
if nIDCostIndex >= 0 then nIDCost := Integer(Config.AccountCostList.Objects[nIDCostIndex]);
if nIPCostIndex >= 0 then begin
nIPCost := Integer(Config.IPaddrCostList.Objects[nIPCostIndex]);
boPayCost := True;
end;
finally
CS_DB.Leave;
end;
if (nIDCost >= 0) or (nIPCost >= 0) then UserInfo.boPayCost := True
else UserInfo.boPayCost := False;
UserInfo.nIDDay := LoWord(nIDCost);
UserInfo.nIDHour := HiWord(nIDCost);
UserInfo.nIPDay := LoWord(nIPCost);
UserInfo.nIPHour := HiWord(nIPCost);
if not UserInfo.boPayCost then begin
DefMsg := MakeDefaultMsg(SM_PASSOK_SELECTSERVER, 0, 0, 0, Config.ServerNameList.Count);
end else begin
DefMsg := MakeDefaultMsg(SM_PASSOK_SELECTSERVER,
nIDCost,
LoWord(nIPCost),
HiWord(nIPCost),
Config.ServerNameList.Count);
end;
sServerName := GetServerListInfo;
SendGateMsg(UserInfo.Socket,
UserInfo.sSockIndex,
EncodeMessage(DefMsg) + EncodeString(sServerName));
SessionAdd(Config,
UserInfo.sAccount,
UserInfo.sUserIPaddr,
UserInfo.nSessionID,
UserInfo.boPayCost,
False);
//CODE:0046B857 call sub_46C150
end else begin
DefMsg := MakeDefaultMsg(SM_PASSWD_FAIL, nCode, 0, 0, 0);
SendGateMsg(UserInfo.Socket, UserInfo.sSockIndex, EncodeMessage(DefMsg));
end;
except
MainOutMessage('TFrmMain.LoginUser');
end;
end;
//0046D890
procedure GetSelGateInfo(Config: pTConfig; sServerName, sIPaddr: string; var sSelGateIP: string; var nSelGatePort: Integer);
var
I: Integer;
nGateIdx: Integer;
nGateCount: Integer;
nSelIdx: Integer;
boSelected: Boolean;
begin
try
sSelGateIP := '';
nSelGatePort := 0;
for I := 0 to Config.nRouteCount - 1 do begin
if Config.boDynamicIPMode or ((Config.GateRoute[I].sServerName = sServerName) and (Config.GateRoute[I].sPublicAddr = sIPaddr)) then begin
nGateCount := 0;
nGateIdx := 0;
while (True) do begin
if (Config.GateRoute[I].Gate[nGateIdx].sIPaddr <> '') and (Config.GateRoute[I].Gate[nGateIdx].boEnable) then
Inc(nGateCount);
Inc(nGateIdx);
if nGateIdx >= 10 then Break;
end; //0046D956
if nGateCount <= 0 then Break; //如果没有相关网关IP设置,则跳出
nSelIdx := Config.GateRoute[I].nSelIdx;
boSelected := False;
for nGateIdx := nSelIdx + 1 to 9 do begin
if (Config.GateRoute[I].Gate[nGateIdx].sIPaddr <> '') and (Config.GateRoute[I].Gate[nGateIdx].boEnable) then begin
Config.GateRoute[I].nSelIdx := nGateIdx;
boSelected := True;
Break;
end;
end;
if not boSelected then begin
for nGateIdx := 0 to nSelIdx - 1 do begin
if (Config.GateRoute[I].Gate[nGateIdx].sIPaddr <> '') and (Config.GateRoute[I].Gate[nGateIdx].boEnable) then begin
Config.GateRoute[I].nSelIdx := nGateIdx;
Break;
end;
end;
end; //0046DA2B
nSelIdx := Config.GateRoute[I].nSelIdx;
sSelGateIP := Config.GateRoute[I].Gate[nSelIdx].sIPaddr;
nSelGatePort := Config.GateRoute[I].Gate[nSelIdx].nPort;
Break;
end; //0046DA72
end; //0046DA7E
except
MainOutMessage('TFrmMain.GetSelGateInfo');
end;
end;
function GetServerListInfo: string;
var
sServerInfo: string;
I: Integer;
sServerName: string;
Config: pTConfig;
begin
Config := @g_Config;
try
for I := 0 to Config.ServerNameList.Count - 1 do begin
sServerName := Config.ServerNameList.Strings[I];
if sServerName <> '' then
sServerInfo := sServerInfo + sServerName + '/' + IntToStr(FrmMasSoc.ServerStatus(sServerName)) + '/';
end;
{
for I := 0 to n473290 - 1 do begin
if (GateRoute[i].sServerName <> '') then begin
sServerInfo:=sServerInfo + GateRoute[i].sServerName + '/' + IntToStr(FrmMasSoc.ServerStatus(GateRoute[i].sServerName)) + '/';
end;
end;
}
Result := sServerInfo;
except
MainOutMessage('TFrmMain.GetServerListInfo');
end;
end;
procedure AccountSelectServer(Config: pTConfig; UserInfo: pTUserInfo; sData: string); //0046B908
var
sServerName: string;
DefMsg: TDefaultMessage;
boPayCost: Boolean;
nPayMode: Integer;
sSelGateIP: string;
nSelGatePort: Integer;
resourcestring
sSelServerMsg = 'Server: %s/%s-%s:%d';
begin
sServerName := DecodeString(sData);
if (UserInfo.sAccount <> '') and (sServerName <> '') and IsLogin(Config, UserInfo.nSessionID) then begin
GetSelGateInfo(Config, sServerName, Config.sGateIPaddr, sSelGateIP, nSelGatePort);
if (sSelGateIP <> '') and (nSelGatePort > 0) then begin
if Config.boDynamicIPMode then sSelGateIP := UserInfo.sGateIPaddr; //增加支动态IP
if Config.boShowDetailMsg then
MainOutMessage(Format(sSelServerMsg, [sServerName, Config.sGateIPaddr, sSelGateIP, nSelGatePort]));
UserInfo.boSelServer := True;
boPayCost := False;
nPayMode := 5;
if UserInfo.nIDHour > 0 then nPayMode := 2;
if UserInfo.nIPHour > 0 then nPayMode := 4;
if UserInfo.nIPDay > 0 then nPayMode := 3;
if UserInfo.nIDDay > 0 then nPayMode := 1;
if FrmMasSoc.IsNotUserFull(sServerName) then begin
SessionUpdate(Config, UserInfo.nSessionID, sServerName, boPayCost);
FrmMasSoc.SendServerMsg(SS_OPENSESSION, sServerName,
UserInfo.sAccount + '/' + IntToStr(UserInfo.nSessionID) + '/' + IntToStr(Integer(UserInfo.boPayCost)) + '/' + IntToStr(nPayMode) + '/' + UserInfo.sUserIPaddr);
DefMsg := MakeDefaultMsg(SM_SELECTSERVER_OK, UserInfo.nSessionID, 0, 0, 0);
SendGateMsg(UserInfo.Socket, UserInfo.sSockIndex, EncodeMessage(DefMsg) + EncodeString(sSelGateIP + '/' + IntToStr(nSelGatePort) + '/' + IntToStr(UserInfo.nSessionID)));
end else begin
UserInfo.boSelServer := False;
SessionDel(Config, UserInfo.nSessionID);
DefMsg := MakeDefaultMsg(SM_STARTFAIL, 0, 0, 0, 0);
SendGateMsg(UserInfo.Socket, UserInfo.sSockIndex, EncodeMessage(DefMsg));
end;
end;
end;
end;
//0046C570
procedure AccountUpdateUserInfo(Config: pTConfig; UserInfo: pTUserInfo; sData: string);
var
UserEntry: TUserEntry;
UserAddEntry: TUserEntryAdd;
DBRecord: TAccountDBRecord;
nLen: Integer;
sUserEntryMsg: string;
sUserAddEntryMsg: string;
nCode: Integer;
DefMsg: TDefaultMessage;
n10: Integer;
begin
try
FillChar(UserEntry, SizeOf(TUserEntry), #0);
FillChar(UserAddEntry, SizeOf(TUserEntryAdd), #0);
nLen := GetCodeMsgSize(SizeOf(TUserEntry) * 4 / 3);
sUserEntryMsg := Copy(sData, 1, nLen);
sUserAddEntryMsg := Copy(sData, nLen + 1, Length(sData) - nLen);
DecodeBuffer(sUserEntryMsg, @UserEntry, SizeOf(TUserEntry));
DecodeBuffer(sUserAddEntryMsg, @UserAddEntry, SizeOf(TUserEntryAdd));
nCode := -1;
if (UserInfo.sAccount = UserEntry.sAccount) and CheckAccountName(UserEntry.sAccount) then begin
try
if AccountDB.Open then begin
n10 := AccountDB.Index(UserEntry.sAccount);
if (n10 >= 0) then begin
if (AccountDB.Get(n10, DBRecord) >= 0) then begin
DBRecord.UserEntry := UserEntry;
DBRecord.UserEntryAdd := UserAddEntry;
AccountDB.Update(n10, DBRecord);
nCode := 1;
end;
end else nCode := 0;
end;
finally
AccountDB.Close;
end;
end; //0046C74B
if nCode = 1 then begin
WriteLogMsg(Config, 'upg', UserEntry, UserAddEntry);
DefMsg := MakeDefaultMsg(SM_UPDATEID_SUCCESS, 0, 0, 0, 0);
end else begin
DefMsg := MakeDefaultMsg(SM_UPDATEID_FAIL, nCode, 0, 0, 0);
end;
SendGateMsg(UserInfo.Socket, UserInfo.sSockIndex, EncodeMessage(DefMsg));
except
MainOutMessage('TFrmMain.UpdateUserInfo');
end;
end;
procedure AccountGetBackPassword(UserInfo: pTUserInfo;
sData: string);
var
sMsg: string;
sAccount: string;
sQuest1: string;
sAnswer1: string;
sQuest2: string;
sAnswer2: string;
sPassword: string;
sBirthDay: string;
nCode: Integer;
nIndex: Integer;
DefMsg: TDefaultMessage;
DBRecord: TAccountDBRecord;
begin
sMsg := DecodeString(sData);
sMsg := GetValidStr3(sMsg, sAccount, [#9]);
sMsg := GetValidStr3(sMsg, sQuest1, [#9]);
sMsg := GetValidStr3(sMsg, sAnswer1, [#9]);
sMsg := GetValidStr3(sMsg, sQuest2, [#9]);
sMsg := GetValidStr3(sMsg, sAnswer2, [#9]);
sMsg := GetValidStr3(sMsg, sBirthDay, [#9]);
nCode := 0;
try
if (sAccount <> '') and AccountDB.Open then begin
nIndex := AccountDB.Index(sAccount);
if (nIndex >= 0) and (AccountDB.Get(nIndex, DBRecord) >= 0) then begin
if (DBRecord.nErrorCount < 5) or ((GetTickCount - DBRecord.dwActionTick) > 180000) then begin
nCode := -1;
if (DBRecord.UserEntry.sQuiz = sQuest1) then begin
nCode := -3;
if DBRecord.UserEntry.sAnswer = sAnswer1 then begin
if DBRecord.UserEntryAdd.sBirthDay = sBirthDay then begin
nCode := 1;
end;
end;
end;
if nCode <> 1 then begin
if (DBRecord.UserEntryAdd.sQuiz2 = sQuest2) then begin
nCode := -3;
if DBRecord.UserEntryAdd.sAnswer2 = sAnswer2 then begin
if DBRecord.UserEntryAdd.sBirthDay = sBirthDay then begin
nCode := 1;
end;
end;
end;
end;
if nCode = 1 then begin
sPassword := DBRecord.UserEntry.sPassword;
end else begin
Inc(DBRecord.nErrorCount);
DBRecord.dwActionTick := GetTickCount();
AccountDB.Update(nIndex, DBRecord);
end;
end else begin
nCode := -2;
if GetTickCount < DBRecord.dwActionTick then begin
DBRecord.dwActionTick := GetTickCount();
AccountDB.Update(nIndex, DBRecord);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -