The below marked not clear block, it should for the current login user to get those already login user. Am I correct?
If yes, why the client did not receive this event sink?
but the remain logined client can receive the new login user.
Please advise.
procedure TLoginService.Login(const Nickname: Unicodestring);
var
ev: IChatEvents_Writer;
i: Integer;
s: Unicodestring;
begin
UserClientIDListCs.Acquire;
try
if UserClientIDList.IndexOfName(Nickname) <> -1 then raise Exception.Create('Nickname already in use');
s := VarToWideStr(Session['nick']);
if s <> '' then
UserClientIDList.Delete(UserClientIDList.IndexOfName(s));
CreateSession;
RegisterEventClient((GuidToString(Session.SessionID)), EID_ChatEvents);
<<< Not Clear Start
ev := (EventRepository as IChatEvents_Writer);
ev.ExcludeSender := False;
ev.SessionList.Add(GuidToString(Session.SessionID));
for i := 0 to UserClientIDList.Count - 1 do begin
ev.UserLogin(Session.SessionID, UserClientIDList.Names[i]);
end;
<<< Not Clear End
UserClientIDList.Add(Nickname + '=' + GUIDToString(Session.SessionID));
ev := (EventRepository as IChatEvents_Writer);
ev.ExcludeSender := False;
for i := 0 to UserClientIDList.Count - 1 do
ev.SessionList.Add(Copy(UserClientIDList[i], pos('=', UserClientIDList[i])+1, MaxInt));
ev.UserLogin(Session.SessionID, Nickname);
finally
UserClientIDListCs.Release;
end;
Session['nick'] := Nickname;
end;
ev := (EventRepository as IChatEvents_Writer);
ev.ExcludeSender := False;
ev.SessionList.Add(GuidToString(Session.SessionID));
for i := 0 to UserClientIDList.Count - 1 do begin
ev.UserLogin(Session.SessionID, UserClientIDList.Names[i]);
end;
I mean this part . notifies all other logged users that new user is logged ?
I make my question clear , see if I miss or misunderstanding the case:
ev := (EventRepository as IChatEvents_Writer);
ev.ExcludeSender := False;
for i := 0 to UserClientIDList.Count - 1 do
ev.SessionList.Add(Copy(UserClientIDList[i], pos('=', UserClientIDList[i])+1, MaxInt));
ev.UserLogin(Session.SessionID, Nickname);
This part is what you mean notice all other user , the new user login.
ev := (EventRepository as IChatEvents_Writer);
ev.ExcludeSender := False;
ev.SessionList.Add(GuidToString(Session.SessionID));
for i := 0 to UserClientIDList.Count - 1 do begin
ev.UserLogin(Session.SessionID, UserClientIDList.Names[i]);
end;
This part is to notice current login user the logined user . am i correct?
As Now this part not trigger the client Userlogin code.
TLoginService = class(TRORemoteDataModule, ILoginService)
..
protected
.. procedure DoOnDeactivate(aClientID: TGUID); override;
procedure TLoginService.DoOnDeactivate(aClientID: TGUID);
var
ev: IChatEvents_Writer;
i: Integer;
begin
inherited;
if SessionManager.IsSessionPresent(aClientID) then begin
ev := (EventRepository as IChatEvents_Writer);
ev.ExcludeSender := False;
ev.SessionList.Add(GuidToString(Session.SessionID));
for i := 0 to UserClientIDList.Count - 1 do begin
ev.UserLogin(Session.SessionID, UserClientIDList.Names[i]);
end;
end;
end;
Why it doesn’t work in this sample: we have closed security hole in code and now session is added to session manager after the login call is completed and DestroySession wasn’t called in the Login method.