You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
RnQ/RnQ/Protocols_all.pas

332 lines
9.5 KiB
Plaintext

{
This file is part of R&Q.
Under same license
}
unit Protocols_all;
{$I RnQConfig.inc}
{$I NoRTTI.inc}
interface
uses
Vcl.Forms,
Protocol_ICQ, ICQSession, ICQContacts, RnQPics, RDGlobal,
globalLib, outboxLib;
type
TRnQProtoHelper = class helper for TICQSession
public
procedure Event(event: Integer);
procedure UserSetStatus(st: Byte; vi: Byte);
function enterPWD: Boolean;
end;
TRnQContactHelper = class helper for TICQContact
public
function CanMail: Boolean;
function CanBuzz: Boolean;
procedure Auth;
procedure AuthDenied(const msg: string = '');
procedure DelCntFromSrv;
function SendEmailTo: Boolean;
function GetContactIP: Integer;
function GetContactIntIP: Integer;
end;
function GetXSts(cnt: TICQContact; IsSelf: Boolean = False): String;
procedure ProtoEvent(Sender: TICQSession; event: Integer);
function Status2ImgName(s: byte; inv: Boolean = False): TPicName; inline;
function Status2ImgNameExt(s: Byte; inv: Boolean = False; extSts: Byte = 0): TPicName; inline;
function OutboxAdd(kind: Integer; dest: TICQContact; flags: Integer = 0; const info: string = ''): Toevent; overload;
function OutboxAdd(kind: Integer; dest: TICQContact; flags: Integer; cl: TRnQCList): Toevent; overload;
procedure GetTrayIconTip(var vPic: TPicName; var vTip: String);
var
AntiSpamMsgs: array [0 .. 6] of String = (
// (
('Your message has been blocked for antispam reason.'),
('You entered invalid code. Try again.'),
('Confirmation accepted. Your message recieved. Thank you.'),
('You failed antispam verification. You have no attemts. Your UIN (%uin%) is ignored.'),
('Please, type digital CODE which you can see below (3 digits).'),
('You have attempts: %attempt%.'), // %code%
('Please, type answer on question which you can see below.')
{ )
(
('Âàøå ñîîáùåíèå çàáëîêèðîâàíî àíòèñïàì ïëàãèíîì.'),
('Âû ââåëè íå ïðàâèëüíûé êîä. Ïîïðîáóéòå åùå ðàç.'),
('Êîä ïðèíÿò. Âàøå ñîîáùåíèå ïîëó÷åíî. Ñïàñèáî.'),
('Âû íå ïðîøëè àíòèñïàì ïðîâåðêó. Ó âàñ íå îñòàëîñü ïîïûòîê. Âàø UIN (%uin%) èãíîðèðóåòñÿ.'),
('Ïîæàëóéñòà, ââåäèòå öèôðîâîé ÊÎÄ êîòîðûé âû âèäèòå íèæå (3 öèôðû). '),
('Îñòàëîñü ïîïûòîê: %attempt%.'#13#10'%code%')
) }
);
implementation
uses
System.SysUtils,
RnQLangs, RnQStrings, RDUtils, RnQSysUtils, RQThemes, RnQGlobal, ICQCommon, ICQConsts,
SciterLib, pluginLib, history, utilLib, events;
procedure TRnQProtoHelper.Event(event: Integer);
var
ICQSess: TICQSession;
begin
ICQSess := TICQSession(Self);
ProcessICQEvents(ICQSess, TICQEvent(event));
end;
procedure ProtoEvent(Sender: TICQSession; event: Integer);
begin
Sender.Event(event);
end;
function GetXSts(cnt: TICQContact; IsSelf: Boolean = False): String;
begin
Result := '';
if IsSelf then
begin
if Assigned(Account.AccProto) then
begin
if Account.AccProto.CurXStatus > 0 then
Result := XStatusArray[Account.AccProto.CurXStatus].Status;
end;
end else
begin
if Assigned(cnt) then
if cnt is TICQcontact then
Result := XStatusArray[TICQContact(cnt).XStatusIndex].Status
end;
end;
procedure TRnQProtoHelper.UserSetStatus(st: Byte; vi: Byte);
begin
Account.AccProto.SetStatusAndVis(st, vi);
LastStatusUserSet := st;
end; // UserSetStatus
function TRnQProtoHelper.enterPWD: Boolean;
begin
Result := False;
if enteringProtoPWD then
Exit;
enteringProtoPWD := True;
Result := UI.CL.OpenLoginDialog;
enteringProtoPWD := False;
Exit;
// try
// s := Self.pwd;
// sUIN := Self._GetProtoName + '#'+ Self.MyAccNum;
// res := enterPwdDlg(s, getTranslation('Login password') + ' (' + sUIN + ')', Self._MaxPWDLen);
//
// if (Self is TICQSession) and (Length(s) > maxPwdLength)
// or (Length(s) > Self._MaxPWDLen) then
// begin
// msgDlg('Password too long', True, mtError);
// exit;
// end;
// if Self is TICQSession then
// begin
// myInf := Self.getMyInfo;
// if Assigned(myInf) then
// if not tICQcontact(myInf).isAIM then
// if Length(s) > 8 then
// begin
// msgDlg('Please enter only first 8 symbols of your password', True, mtInformation);
// // exit;
// end;
// end;
// finally
// enteringProtoPWD := False;
// end;
//
// if not res or (s='') then exit;
//{ if thisICQ.ProtoElem is TICQSession then
// if LoginMD5 and saveMD5Pwd then
// s := MD5Pass(s);}
// Self.pwd := s;
//// saveCFG;
// if not dontSavePwd then
// saveCfgDelayed := True;
// result := TRUE;
end;
/////////////////////////////////////////////
// TRnQContactHelper
/////////////////////////////////////////////
function TRnQContactHelper.CanMail: Boolean;
begin
Result := Assigned(Self) and ((Self is TICQcontact) and (TICQcontact(Self).Email > ''));
end;
function TRnQContactHelper.CanBuzz: Boolean;
begin
if Assigned(Self) and (Self is TICQContact) then
Result := CAPS_big_Buzz in TICQContact(Self).capabilitiesBig
else
Result := False;
end;
procedure TRnQContactHelper.Auth;
var
ev: THevent;
begin
plugins.castEv(PE_AUTH_SENT, Self.uid);
Account.AccProto.Authorize(TICQContact(Self));
ev := THevent.new(EK_auth, Self, Account.AccProto.GetMyInfo, now, '', [], 0);
ev.outgoing := True;
if logpref.writehistory and (BE_save in behaviour[ev.kind].trig) then
WriteToHistory(ev);
UI.Chat.AddEvent_OpenChat(Self, ev);
end;
procedure TRnQContactHelper.AuthDenied(const msg: string = '');
var
ev: THevent;
begin
plugins.castEv(PE_AUTHDENIED_SENT, Self.uid, msg);
Account.AccProto.Authorize(TICQContact(Self), False);
ev := THevent.new(EK_authDenied, Self, Account.AccProto.GetMyInfo, now, msg, [], 0);
ev.outgoing := True;
if logpref.writehistory and (BE_save in behaviour[ev.kind].trig) then
WriteToHistory(ev);
UI.Chat.AddEvent_OpenChat(Self, ev);
end;
procedure TRnQContactHelper.DelCntFromSrv;
begin
Account.AccProto.RemoveContactFromServer(TICQCOntact(Self));
end;
function TRnQContactHelper.SendEmailTo: Boolean;
var
ml: String;
begin
if Self = nil then
Exit(False)
else if Self is TICQContact then
ml := TICQContact(Self).email
else
ml := '';
Result := not (ml = '');
if Result then
exec('mailto: ' + ml);
end; // SendEmailTo
function TRnQContactHelper.GetContactIP: Integer;
begin
if Self is TICQContact then
Result := 0
else
Result := 0;
end;
function TRnQContactHelper.GetContactIntIP: Integer;
begin
if Self is TICQContact then
Result := 0
else
Result := 0;
end;
function Status2ImgName(s: Byte; inv: Boolean = False): TPicName;
begin
Result := Protocol_ICQ.Status2ImgName(s, inv);
end;
function status2imgNameExt(s: Byte; inv: Boolean = False; extSts: Byte = 0): TPicName;
begin
Result := Protocol_ICQ.Status2ImgNameExt(s, inv, extSts);
end;
function OutboxAdd(kind: Integer; dest: TICQContact; flags: Integer = 0; const info: string = ''): Toevent;
begin
if Assigned(dest) then
begin
Result := Account.outbox.add(kind, dest, flags, info);
UI.UpdateOutbox;
ActionManager.Execute(AK_PROCESSOUTBOX);
end else
Result := nil;
end;
function OutboxAdd(kind: Integer; dest: TICQContact; flags: Integer; cl: TRnQCList): Toevent;
begin
if Assigned(dest) then
begin
Result := Account.outbox.add(kind, dest, flags, cl);
UI.UpdateOutbox;
ActionManager.Execute(AK_PROCESSOUTBOX);
end else
Result := nil;
end;
procedure GetTrayIconTip(var vPic: TPicName; var vTip: String);
var
e: THevent;
MyInf: TICQContact;
begin
vPic := PIC_CLIENT_LOGO;
vTip := Application.Title;
if BossMode.isBossKeyOn then
Exit
else if (eventQ = nil) or eventQ.Empty or (blinkWithStatus and not (Blinking or Account.AccProto.getStatusDisable.blinking)) then
begin
if not Assigned(Account.AccProto) then
vPic := Status2ImgName(byte(SC_UNK), False)
else if Account.AccProto.IsOnline then
begin
vTip := Account.AccProto.GetStatusName;
vPic := Account.AccProto.GetStatusImg;
end else if Account.AccProto.IsConnecting then
begin
vTip := GetTranslation('Connecting');
if Account.AccProto.progLogon > 0 then
begin
vPic := PIC_CONNECTING + IntToStr(Trunc(Account.AccProto.progLogon * 8));
with theme.GetPicSize(RQteTrayNotify, vPic) do
if not ((cx > 0) and (cy > 0)) then
vPic := PIC_CONNECTING;
end else
vPic := PIC_CONNECTING;
if Account.AccProto.IsInvisible then
vPic := INVIS_PREFIX + vPic;
end
else
begin
vTip := GetTranslation(Account.AccProto.Statuses[Byte(SC_OFFLINE)].Cptn);
vPic := Status2imgName(Byte(SC_OFFLINE), Account.AccProto.IsInvisible);
end;
MyInf := Account.AccProto.getMyInfo;
if Assigned(MyInf) then
vTip := GetTranslation('%s [%s]', [vTip, MyInf.Displayed + ' / ' + MyInf.UIN2Show])
else
vTip := 'R&&&Q';
end
else
begin
e := eventQ.Top;
if Assigned(e) then
begin
if Blinking or Account.AccProto.getStatusDisable.blinking then
vPic := e.pic
else
vPic := PIC_EMPTY;
if e.who = nil then
vTip := GetTranslation(Str_Error)
else
vTip := GetTranslation(TrayEvent2Str[e.kind], [e.who.Displayed]);
end;
end;
end;
end.