处理部分关键代码:
中转类网关处理部分:
procedure DiocpExecute(pvCMDObject: TSimpleMsgPack; pvContext:TDiocpStreamClientContext);
var
lvCMDIndex:Integer;
lvSession:TCHATSession;
ToUserID:string;
DataDBID:string;
begin
if pvCMDObject.O['ResultCMD']<> nil then
begin
ToUserID:=pvCMDObject.ForcePathObject('FrmUser').asstring;
pvCMDObject.ForcePathObject('CMD').AsInteger:=pvCMDObject.ForcePathObject('ResultCMD').asinteger;
pvCMDObject.DeleteObject('ResultCMD');
SendCMDObject(pvCMDObject,TCHATSession(ChatSessions.FindSession(ToUserID)).FContext);
pvCMDObject.clear;
exit;
end;
if pvCMDObject.O['cmd']<> nil then
begin
lvCMDIndex := pvCMDObject.ForcePathObject('cmd').AsInteger;
case lvCMDIndex of
0: ExecuteHeart (pvCMDObject, pvContext); // 心跳
1: ExecuteLogin (pvCMDObject, pvContext); // 登陆
10: ExecuteSql (pvCMDObject, pvContext);
else //转发数据给处理端
begin
lvSession := TCHATSession(TDiocpStreamClientContext(pvContext).Data);
if lvSession = nil then
begin
raise exception.CreateFmt(pvContext.RemoteAddr+'['+inttostr(pvcontext.RemotePort) +']非法连接关闭:[%d]', [lvCMDIndex]);
end
else
begin
pvCMDObject.ForcePathObject('FrmUser').asstring:=lvSession.useriD;
if DataDBSrv.count>0 then
begin
Randomize;
DataDBID:=DataDBSrv.strings[Random(DataDBSrv.count)];
// sflogger.logMessage(datadbid);
end
else
begin
sflogger.logMessage('处理端未开启');
end;
SendCMDObject(pvCMDObject,TCHATSession(ChatSessions.FindSession(DataDBID)).FContext);
end;
// sfLogger.logMessage('转发成功');
exception.CreateFmt(pvContext.RemoteAddr+'['+inttostr(pvcontext.RemotePort) +']执行未知命令:[%d]', [lvCMDIndex]);
end;
end;
end;
end;