MyChat Scripts: function mGetUINByCID, get a user's UIN by connection number
Get an online user's identifier (UIN) by his connection number (CID).
Syntax
function mGetUINByCID(const iCID: int64): integer;
Parameters and return values
Parameter |
Type |
Value |
iCID |
int64 |
number of the online connection to the server. |
Function result
user's UIN, if CID is correct, -1 if there is no connection with this number.
Example
The script calculates the number of connections of all online users and displays the result in the console.
procedure PrintCount(sUIN: string; iCount: integer);
begin
if iCount > 0 then mLogScript(IntToStr(iCount) + ' connections', 'UIN ' + sUIN);
end;
var
sCIDList, sUIN: string;
i, iCount: integer;
iCID: int64;
SL: TStringList;
begin
SL := TStringList.Create;
SL.Sorted := true;
SL.Duplicates := dupAccept;
sCIDList := mGetCIDSByClientType('any');
while length(sCIDList) > 0 do begin
iCID := StrToInt64(Fetch(sCIDList, ','));
SL.Add(IntToStr(mGetUINByCID(iCID)));
end;
if SL.Count > 0 then begin
sUIN := '';
for i := 0 to SL.Count - 1 do begin
if sUIN <> SL[i] then begin
PrintCount(sUIN, iCount);
sUIN := SL[i];
iCount := 1;
end else inc(iCount);
end;
PrintCount(sUIN, iCount);
end;
SL.Free;
end.
Script work result
[13:25:25] (Log "mGetUINByCID"): [UIN 1] 5 connections
[13:25:25] (Log "mGetUINByCID"): [UIN 6] 1 connections
[13:25:25] (Run "mGetUINByCID"): Script operation time: 5 ms
[13:25:25] (Run "mGetUINByCID"): Script done successfully.