📄 lmain.~pas
字号:
sUserIPaddr :String;
ResourceString
sOpenMsg = 'Open: %s/%s';
begin
sGateIPaddr:=GetValidStr3(sIPaddr,sUserIPaddr,['/']);
try
for I:=0 to GateInfo.UserList.Count -1 do begin
UserInfo:=GateInfo.UserList.Items[I];
if UserInfo.sSockIndex = sSockIndex then begin
UserInfo.sUserIPaddr := sUserIPaddr;
UserInfo.sGateIPaddr := sGateIPaddr;
UserInfo.sAccount := '';
UserInfo.nSessionID := 0;
UserInfo.sReceiveMsg := '';
UserInfo.dwTime5C := GetTickCount();
UserInfo.dwClientTick :=GetTickCount();
exit;
end;
end;
New(UserInfo);
UserInfo.sAccount := '';
UserInfo.sUserIPaddr := sUserIPaddr;
UserInfo.sGateIPaddr := sGateIPaddr;
UserInfo.sSockIndex := sSockIndex;
UserInfo.nVersionDate := 0;
UserInfo.boCertificationOK := False;
UserInfo.nSessionID := 0;
UserInfo.bo51 := False;
UserInfo.Socket := GateInfo.Socket;
UserInfo.sReceiveMsg := '';
UserInfo.dwTime5C := GetTickCount();
UserInfo.dwClientTick := GetTickCount();
UserInfo.bo60 := False;
UserInfo.Gate := GateInfo;
GateInfo.UserList.Add(UserInfo);
if Config.boShowDetailMsg then
MainOutMessage(format(sOpenMsg,[sUserIPaddr,sGateIPaddr]));
except
MainOutMessage('TFrmMain.ReceiveOpenUser');
end;
end;
//0046B1A8
procedure ReceiveSendUser(Config:pTConfig;sSockIndex: String;
GateInfo: pTGateInfo; sData: String);
var
UserInfo :pTUserInfo;
I :integer;
begin
try
for I:=0 to GateInfo.UserList.Count -1 do begin
UserInfo:=GateInfo.UserList.Items[I];
if UserInfo.sSockIndex = sSockIndex then begin
if Length(UserInfo.sReceiveMsg) < 4069 then begin
UserInfo.sReceiveMsg:=UserInfo.sReceiveMsg + sData;
end;
Break;
end;
end;
except
MainOutMessage('TFrmMain.ReceiveSendUser');
end;
end;
//00469D38
procedure SessionClearKick(Config:pTConfig);
var
I :Integer;
ConnInfo :pTConnInfo;
begin
Config.SessionList.Lock;
try
for I := Config.SessionList.Count - 1 downto 0 do begin
ConnInfo:=Config.SessionList.Items[I];
if ConnInfo.boKicked and ((GetTickCount - ConnInfo.dwKickTick) > 5 * 1000) then begin
Dispose(ConnInfo);
Config.SessionList.Delete(I);
end;
end;
finally
Config.SessionList.UnLock;
end;
end;
//0046B284
procedure DecodeUserData(Config:pTConfig;UserInfo: pTUserInfo);
var
sMsg :String;
nCount :Integer;
begin
nCount:=0;
try
//if UserInfo = nil then nErrCode:=1;
while (True) do begin
if TagCount(UserInfo.sReceiveMsg,'!') <= 0 then break;
UserInfo.sReceiveMsg:=ArrestStringEx(UserInfo.sReceiveMsg,'#','!',sMsg);
if sMsg <> '' then begin;
if Length(sMsg) >= DEFBLOCKSIZE + 1 then begin
sMsg:=Copy(sMsg,2,Length(sMsg)-1);
ProcessUserMsg(Config,UserInfo,sMsg);
end;
end else begin
if nCount >= 1 then UserInfo.sReceiveMsg:='';
Inc(nCount);
end;
if UserInfo.sReceiveMsg = '' then break;
end;
except
MainOutMessage('[Exception] TFrmMain.DecodeUserData ');
end;
end;
//0046A088
procedure SessionDel(Config:pTConfig;nSessionID: Integer);
var
ConnInfo:pTConnInfo;
i:Integer;
begin
Config.SessionList.Lock;
try
for i:= 0 to Config.SessionList.Count -1 do begin
ConnInfo:=Config.SessionList.Items[i];
if ConnInfo.nSessionID=nSessionID then begin
Dispose(ConnInfo);
Config.SessionList.Delete(i);
break;
end;
end;
finally
Config.SessionList.UnLock;
end;
end;
//0046CC3C
procedure ProcessUserMsg(Config:pTConfig;UserInfo: pTUserInfo; sMsg: String);
var
sDefMsg :String;
sData :String;
DefMsg :TDefaultMessage;
begin
try
sDefMsg := Copy(sMsg,1,DEFBLOCKSIZE);
sData := Copy(sMsg,DEFBLOCKSIZE+1,Length(sMsg)-DEFBLOCKSIZE);
DefMsg := DecodeMessage(sDefMsg);
case DefMsg.Ident of
CM_SELECTSERVER: begin
if not UserInfo.boSelServer then begin
AccountSelectServer(Config,UserInfo,sData);
end;
end;
CM_PROTOCOL: begin
AccountCheckProtocol(UserInfo,DefMsg.Recog);
end;
CM_IDPASSWORD: begin
if UserInfo.sAccount = '' then begin
AccountLogin(Config,UserInfo,sData);
end else begin
KickUser(Config,UserInfo);
end;
end;
CM_ADDNEWUSER: begin
if Config.boEnableMakingID then begin
if (GetTickCount - UserInfo.dwClientTick) > 5000 then begin
UserInfo.dwClientTick:=GetTickCount();
AccountCreate(Config,UserInfo,sData);
end else begin
MainOutMessage('[Hacker Attack] _ADDNEWUSER ' + '/' + UserInfo.sUserIPaddr);
end;
end;
end;
CM_CHANGEPASSWORD: begin
if UserInfo.sAccount = '' then begin
if (GetTickCount - UserInfo.dwClientTick) > 5000 then begin
UserInfo.dwClientTick:=GetTickCount();
AccountChangePassword(Config,UserInfo,sData);
end else begin
MainOutMessage('[Hacker Attack] _CHANGEPASSWORD ' + '/' + UserInfo.sUserIPaddr);
end;
end else UserInfo.sAccount:='';
end;
CM_UPDATEUSER: begin
if (GetTickCount - UserInfo.dwClientTick) > 5000 then begin
UserInfo.dwClientTick:=GetTickCount();
AccountUpdateUserInfo(Config,UserInfo,sData);
end else begin
MainOutMessage('[Hacker Attack] _UPDATEUSER ' + '/' + UserInfo.sUserIPaddr);
end;
end;
CM_GETBACKPASSWORD: begin
if (GetTickCount - UserInfo.dwClientTick) > 5000 then begin
UserInfo.dwClientTick:=GetTickCount();
AccountGetBackPassword(UserInfo,sData);
end else begin
MainOutMessage('[Hacker Attack] _GETBACKPASSWORD ' + '/' + UserInfo.sUserIPaddr);
end;
end;
end;
except
MainOutMessage('[Exception] TFrmMain.ProcessUserMsg ' + 'wIdent: ' + IntToStr(DefMsg.Ident) + ' sData: ' + sData);
end;
end;
procedure AccountCreate(Config:pTConfig;UserInfo: pTUserInfo; sData: String);//0046C244
var
UserEntry :TUserEntry;
UserAddEntry :TUserEntryAdd;
DBRecord :TAccountDBRecord;
nLen :Integer;
sUserEntryMsg :String;
sUserAddEntryMsg :String;
nErrCode :Integer;
DefMsg :TDefaultMessage;
bo21 :Boolean;
n10 :Integer;
ResourceString
sAddNewuserFail = '[ID Creation Failed] %s/%s';
sLogFlag = 'new';
begin
try
nErrCode:= -1;
FillChar(UserEntry, SizeOf(TUserEntry), #0);
FillChar(UserAddEntry, SizeOf(TUserEntryAdd), #0);
nLen:=GetCodeMsgSize(SizeOf(TUserEntry)* 4/3);
bo21:=False;
sUserEntryMsg:=Copy(sData,1,nLen);
sUserAddEntryMsg:=Copy(sData,nLen+1,Length(sData)-nLen);
if (sUserEntryMsg <> '') and (sUserAddEntryMsg <> '') then begin
DecodeBuffer(sUserEntryMsg,@UserEntry,SizeOf(TUserEntry));
DecodeBuffer(sUserAddEntryMsg,@UserAddEntry,SizeOf(TUserEntryAdd));
if CheckAccountName(UserEntry.sAccount) then bo21:=True;
if bo21 then begin
try
if AccountDB.Open then begin
MainOutMessage('test...');
n10:=AccountDB.Index(UserEntry.sAccount);
if n10 < 0 then begin
FillChar(DBRecord, SizeOf(TAccountDBRecord), #0);
DBRecord.UserEntry:=UserEntry;
DBRecord.UserEntryAdd:=UserAddEntry;
if UserEntry.sAccount <> '' then
if AccountDB.Add(DBRecord) then nErrCode:=1;
end else nErrCode:=0;
end;
finally
AccountDB.Close;
end;
end else begin
MainOutMessage(format(sAddNewuserFail,[UserEntry.sAccount,UserAddEntry.sQuiz2]));
end; //0046C480
end;
if nErrCode = 1 then begin
WriteLogMsg(Config,sLogFlag,UserEntry,UserAddEntry);
DefMsg:=MakeDefaultMsg(SM_NEWID_SUCCESS,0,0,0,0);
end else begin
DefMsg:=MakeDefaultMsg(SM_NEWID_FAIL,nErrCode,0,0,0);
end;
SendGateMsg(UserInfo.Socket,UserInfo.sSockIndex,EncodeMessage(DefMsg));
except
MainOutMessage('TFrmMain.AddNewUser');
end;
end;
//0046C814
procedure AccountChangePassword(Config:pTConfig;UserInfo: pTUserInfo; sData: String);
var
sMsg :String;
sLoginID :String;
sOldPassword :String;
sNewPassword :String;
DefMsg :TDefaultMessage;
nCode :Integer;
n10 :Integer;
DBRecord :TAccountDBRecord;
ResourceString
sChgMsg = 'chg';
begin
try
sMsg:=DecodeString(sData);
sMsg:=GetValidStr3(sMsg,sLoginID,[#9]);
sNewPassword:=GetValidStr3(sMsg,sOldPassword,[#9]);
nCode:=0;
try
if AccountDB.Open and (Length(sNewPassword) >= 3) then begin
n10:=AccountDB.Index(sLoginID);
if (n10 >= 0) and (AccountDB.Get(n10,DBRecord) >= 0) then begin
//if (DBRecord.nErrorCount >= 5) or ((GetTickCount - DBRecord.dwActionTick) > 180000) then begin
if (DBRecord.nErrorCount < 5) or ((GetTickCount - DBRecord.dwActionTick) > 180000) then begin
if DBRecord.UserEntry.sPassword = sOldPassword then begin
DBRecord.nErrorCount:=0;
DBRecord.UserEntry.sPassword:=sNewPassword;
nCode:=1;
end else begin
Inc(DBRecord.nErrorCount);
DBRecord.dwActionTick:=GetTickCount();
nCode:=-1;
end;
AccountDB.Update(n10,DBRecord);
end else begin
nCode:=-2;
if GetTickCount < DBRecord.dwActionTick then begin
DBRecord.dwActionTick:=GetTickCount();
AccountDB.Update(n10,DBRecord);
end;
end;
end;
end;
finally
AccountDB.Close;
end;
if nCode = 1 then begin
DefMsg:=MakeDefaultMsg(SM_CHGPASSWD_SUCCESS,0,0,0,0);
WriteLogMsg(Config,sChgMsg,DBRecord.UserEntry,DBRecord.UserEntryAdd);
end else begin
DefMsg:=MakeDefaultMsg(SM_CHGPASSWD_FAIL,nCode,0,0,0);
end;
SendGateMsg(UserInfo.Socket,UserInfo.sSockIndex,EncodeMessage(DefMsg));
except
MainOutMessage('TFrmMain.ChangePassword');
end;
end;
procedure AccountCheckProtocol(UserInfo: pTUserInfo; nDate: Integer);
var
DefMsg:TDefaultMessage;
begin
if nDate < nVersionDate then begin
DefMsg:=MakeDefaultMsg(SM_CERTIFICATION_FAIL,0,0,0,0);
end else begin
DefMsg:=MakeDefaultMsg(SM_CERTIFICATION_SUCCESS,0,0,0,0);
UserInfo.nVersionDate := nDate;
UserInfo.boCertificationOK := True;
end;
SendGateMsg(UserInfo.Socket,UserInfo.sSockIndex,EncodeMessage(DefMsg));
end;
//0046A368
function KickUser(Config:pTConfig;UserInfo: pTUserInfo):Boolean;
var
I :Integer;
II :Integer;
GateInfo :pTGateInfo;
User :pTUserInfo;
ResourceString
sKickMsg = 'Kick: %s';
begin
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]));
SendGateKickMsg(GateInfo.Socket,UserInfo.sSockIndex);
Dispose(UserInfo);
GateInfo.UserList.Delete(II);
Result:=True;
exit;
end;
end;
end;
finally
LeaveCriticalSection(Config.GateCriticalSection);
end;
end;
//0046B400
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 (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;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -