Script event for MyChat Server: OnUserLogin
The event that occurs at the moment of user authorization on the server.
Event template
function OnUserLogin(iCID, iLoginUIN, iLoginState: integer; sLoginIP, sLoginMAC, sLoginHardwareID, sLoginCompName, sLoginVersion, sLoginDomain, sSessionID, sAuthService, sClientType, sRemoteOS: string): boolean;
begin
// your own code
result := true;
end;
begin
end.
You can use your own code instead of the comment.
Description of parameters
Parameter |
Type |
Value |
iCID |
integer |
Client connection ID, unique session identifier in the online structure of network connections to the server; |
iLoginUIN |
integer |
unique identifier of a user that attempts to register on the server (number >=0); |
iLoginState |
integer |
|
sLoginIP |
string |
IP address of a user; |
sLoginMAC |
string |
MAC address of the user network interface (only for Windows-clients); |
sLoginHardwareID |
string |
unique identifier of the client hardware, text string; |
sLoginCompName |
string |
computer name of the remote client; |
sLoginVersion |
string |
application version of a user; |
sLoginDomain |
string |
user's domain name, if any; |
sSessionID |
string |
unique string that can generate for the current session of login (usually it's relevant for WEB version; SessionID is also called tokens); |
sAuthService |
string |
if the authentication is performed by the third-party service there may be its name; |
sClientType |
string |
|
sRemoteOS |
string |
user's operating system. |
Return value
By default this function must return "true", however, if you return "false" then the client will be disconnected from the server being unauthorized. It can be useful if you need to organize any Access List with complicated rules that can be made with regular filtration of IP addresses, or blocking MAC addresses, bans, and built-in blocking mechanisms in MyChat.
Example
function OnUserLogin(iCID, iLoginUIN, iLoginState: integer; sLoginIP, sLoginMAC, sLoginHardwareID, sLoginCompName, sLoginVersion, sLoginDomain, sSessionID, sAuthService: string): boolean;
var
iHour: integer;
bFlag: boolean;
begin
bFlag := true;
iHour := strtoint(FormatDateTime('hh', Now));
if (iHour > 17) or (iHour < 8 ) then begin
if iLoginUIN <> 3 then bFlag := false;
end;
result := bFlag;
end;
begin
end.
The script checks the time when a user connects to the server. If it happens after working hours (8:00 17:00), then a user is disconnected from the server. However, if administrator with UIN = 3 attempts to login, then the system must let him because the restrictions do not apply to this user.