📄 usrsoc.pas
字号:
Msg : TDefaultMessage;
sMsg : string;
HumRecord : THumInfo;
i : Integer;
begin
nCode := -1;
Data := DecodeString(sData);
Data := GetValidStr3(Data, sAccount, ['/']);
Data := GetValidStr3(Data, sChrName, ['/']);
Data := GetValidStr3(Data, sHair, ['/']);
Data := GetValidStr3(Data, sJob, ['/']);
Data := GetValidStr3(Data, sSex, ['/']);
if Trim(Data) <> '' then
nCode := 3;
sChrName := Trim(sChrName);
if Length(sChrName) < 3 then
nCode := 0;
if not CheckDenyChrName(sChrName) then
nCode := 2;
if not CheckChrName(sChrName) then
nCode := 0;
for i := 1 to Length(sChrName) do
begin
if(sChrName[i] = ' ') or
(sChrName[i] = '/') or
(sChrName[i] = '@') or
(sChrName[i] = '?') or
(sChrName[i] = '''') or
(sChrName[i] = '"') or
(sChrName[i] = '\') or
(sChrName[i] = '.') or
(sChrName[i] = ',') or
(sChrName[i] = ':') or
(sChrName[i] = ';') or
(sChrName[i] = '`') or
(sChrName[i] = '~') or
(sChrName[i] = '!') or
(sChrName[i] = '#') or
(sChrName[i] = '$') or
(sChrName[i] = '%') or
(sChrName[i] = '^') or
(sChrName[i] = '&') or
(sChrName[i] = '*') or
(sChrName[i] = '(') or
(sChrName[i] = ')') or
(sChrName[i] = '-') or
(sChrName[i] = '_') or
(sChrName[i] = '+') or
(sChrName[i] = '=') or
(sChrName[i] = '|') or
(sChrName[i] = '[') or
(sChrName[i] = '{') or
(sChrName[i] = ']') or
(sChrName[i] = '}') then
nCode := 0;
end;
// Frmdbsrv.MainOutMessage('创建人物::'+Inttostr(nCode));
if (nCode=-1) then
Begin
ncode:=2; //取消专业版
if (ClientSocket1.Active) then
Begin
nCode:=0;
//` Frmdbsrv.MainOutMessage('创建人物2');
Msg:=MakeDefaultMsg(101,0,0,0,0);
sMsg:=EncodeMessage(Msg)+EncodeString(sChrName);
SendDBSockMsg(sMsg);
if GetDBSockMsg(Msg,2000) then
begin
// Frmdbsrv.MainOutMessage('创建人物3');
if Msg.Ident=1001 then
nCode:=-1
else
nCode:=2;
End
else
ncode:=2;
End;
end;
//Frmdbsrv.MainOutMessage('创建人物4');
if nCode=-1 then
nCode := DataModule_DB.AddChar(sAccount, sChrName, Str_ToInt(sSex, 0), Str_ToInt(sJob, 0), Str_ToInt(sHair, 0) );
if nCode = 0 then
begin
Msg := MakeDefaultMsg(SM_NEWCHR_SUCCESS, 0, 0, 0, 0);
end
else
begin
Msg := MakeDefaultMsg(SM_NEWCHR_FAIL, nCode, 0, 0, 0);
end;
sMsg := EncodeMessage(Msg);
SendUserSocket(UserInfo.Socket, UserInfo.sConnID, sMsg);
end;
//004A440C
function TFrmUserSoc.SelectChr(sData: string;
var UserInfo: TUserInfo): Boolean;
var
sAccount : string;
sChrName : string;
ChrList : TStringList;
HumRecord : THumInfo;
i : Integer;
nIndex : Integer;
nMapIndex : Integer;
QuickID : pTQuickID;
ChrRecord : THumData;
sCurMap : string;
boDataOK : Boolean;
sDefMsg : string;
sRouteMsg : string;
sRouteIP : string;
nRoutePort : Integer;
begin
Result := False;
sChrName := GetValidStr3(DecodeString(sData), sAccount, ['/']);
boDataOK := False;
if UserInfo.sAccount = sAccount then
begin
boDataOK := DataModule_DB.UpdateBy(sChrName,sAccount,1,0);
end;
if boDataOK then
begin
sDefMsg := EncodeMessage(MakeDefaultMsg(SM_STARTPLAY, 0, 0, 0, 0));
sRouteIP := GateRouteIP(Userinfo.sGateIPaddr, nRoutePort);
if g_boDynamicIPMode then
sRouteIP := UserInfo.sGateIPaddr; //使用动态IP
sRouteMsg := EncodeString(sRouteIP + '/' + IntToStr(nRoutePort));
SendUserSocket(UserInfo.Socket,
UserInfo.sConnID,
sDefMsg + sRouteMsg);
FrmIDSoc.SetGlobaSessionPlay(UserInfo.nSessionID);
Result := True;
end
else
begin
SendUserSocket(UserInfo.Socket,
UserInfo.sConnID,
EncodeMessage(MakeDefaultMsg(SM_STARTFAIL, 0, 0, 0, 0)));
end;
end;
function TFrmUserSoc.GateRoutePort(sGateIP: string): Integer; //004A2724
begin
Result := 7200;
end;
function TFrmUserSoc.GateRouteIP(sGateIP: string; var nPort: Integer): string;
//0x004A258C
function GetRoute(RouteInfo: pTRouteInfo; var nGatePort: Integer): string;
var
nGateIndex : Integer;
begin
nGateIndex := Random(RouteInfo.nGateCount);
Result := RouteInfo.sGameGateIP[nGateIndex];
nGatePort := RouteInfo.nGameGatePort[nGateIndex];
end;
var
i : Integer;
RouteInfo : pTRouteInfo;
begin
nPort := 0;
Result := '';
for i := Low(g_RouteInfo) to High(g_RouteInfo) do
begin
RouteInfo := @g_RouteInfo[i];
if RouteInfo.sSelGateIP = sGateIP then
begin
Result := GetRoute(RouteInfo, nPort);
break;
end;
end;
end;
procedure TFrmUserSoc.SendUserSocket(Socket: TCustomWinSocket; sSessionID,
sSendMsg: string);
var
count:Integer;
begin
if (Socket<>nil)and(Socket.Connected) then
count:=Socket.SendText('%' + sSessionID + '/#' + sSendMsg + '!$');
if count=0 then
count:=1;
end;
//0045C2C0
function TFrmUserSoc.CheckDenyChrName(sChrName: string): Boolean;
var
i : Integer;
begin
Result := True;
g_CheckCode.dwThread0 := 1000700;
for i := 0 to DenyChrNameList.Count - 1 do
begin
g_CheckCode.dwThread0 := 1000701;
if AnsiContainsText(sChrName, DenyChrNameList.Strings[i]) then
begin
g_CheckCode.dwThread0 := 1000702;
Result := False;
break;
end;
end;
g_CheckCode.dwThread0 := 1000703;
end;
procedure TFrmUserSoc.ClientSocket1Read(Sender: TObject;
Socket: TCustomWinSocket);
begin
sDBReciveText:=sDBReciveText+Socket.ReceiveText;
// Frmdbsrv.MainOutMessage(sDBReciveText);
end;
function TFrmUserSoc.GetDBSockMsg(var Msg: TDefaultMessage;
TimeOut: LongWord): Boolean;
var
dwTimeOutTick:LongWord;
s24,s28,sDefMsg :string;
begin
Result := False;
dwTimeOutTick := GetTickCount();
s24:='';
while (True) do
begin
if (GetTickCount - dwTimeOutTick) > TimeOut then
begin
break;
end;
if Pos('!', sDBReciveText) > 0 then
begin
s24 := sDBReciveText;
sDBReciveText:= '';
if s24<>'' then
Begin
s28 := '';
s24 := ArrestStringEx(s24, '#', '!', s28);
if s28 <> '' then
begin
sDefMsg :=Copy(s28,1,16);
Msg:=DecodeMessage(sDefMsg);
Result:=True;
ENd;
break;
end;
End
else
begin
Sleep(1);
Application.ProcessMessages;
End;
end;
end;
function TFrmUserSoc.SendDBSockMsg(sMsg: String): Boolean;
begin
Result:=False;
if ClientSocket1.Active then
begin
ClientSocket1.Socket.SendText('#'+smsg+'!');
Result:=True;
end;
end;
function TFrmUserSoc.CheckGuildName(GuildName: String): Boolean;
var
Msg:TDefaultMessage;
sMsg:String;
begin
Result:=False;
if ClientSocket1.Active then
Begin
Msg:=MakeDefaultMsg(109,0,0,0,0);
sMsg:=EncodeMessage(Msg)+EncodeString(GuildName);
SendDBSockMsg(sMsg);
if GetDBSockMsg(Msg,1000) then
begin
if Msg.Ident=1009 then
Result:=True;
End;
End
else
Result:=True;
end;
procedure TFrmUserSoc.ClientSocket1Error(Sender: TObject;
Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
begin
ErrorCode:=0;
Socket.Close;
if not ShowErrorMsg then
Begin
Frmdbsrv.Caption:='游戏数据库服务器(不能建新账号)';
ShowErrorMsg:=True;
End;
end;
procedure TFrmUserSoc.ClientSocket1Connect(Sender: TObject;
Socket: TCustomWinSocket);
begin
Frmdbsrv.Caption:='游戏数据库服务器(企业版)';
ShowErrorMsg:=False;
end;
procedure TFrmUserSoc.ClientSocket1Disconnect(Sender: TObject;
Socket: TCustomWinSocket);
begin
Frmdbsrv.Caption:='游戏数据库服务器(不能建新账号)';
ShowErrorMsg:=False;
end;
procedure TFrmUserSoc.Timer2Timer(Sender: TObject);
var
i : Integer;
sReviceMsg : string;
code : Integer;
begin
try
code:=0;
for i := 0 to 9 do
begin
if not Gatelist[i].IsUsed then Continue;
try
CS_GateSession.Enter;
code:=2;
GateList[i].sText:=GateList[i].sText+GateList[i].sReceiveText;
code:=3;
GateList[i].sReceiveText:='';
finally
CS_GateSession.Leave;
end;
code:=4;
if Length(GateList[i].sText) < 8192 then
begin
code:=5;
if Pos('$', GateList[i].sText) > 1 then
begin
code:=6;
ProcessGateMsg(i);
code:=7;
end;
end
else
begin
GateList[i].sText := '';
end;
end;
except
Frmdbsrv.MainOutMessage('ProcessGateMsg::'+Inttostr(Code));
end;
end;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -