function CheckCommand(Body: String; var Answer: String; Admin: Boolean)
: Integer;
var
X, Xx: Integer;
Argument: String;
WrongNumber: String;
DummyBool: Boolean;
begin
Result := 0; // Wrong command
{ Check for safety prefix }
If (chk_useprefix.Checked) and (length(edt_prefix.Text) > 0) then
If pos(edt_prefix.Text, Body) = 1 then
delete(Body, 1, length(edt_prefix.Text))
else
Body := ''; { Check for safety prefix }
Body := LowerCase(Body);
if WordCount(Body) = 1 then
begin
If Body = 'help' then
begin
Result := 1;
Answer := UpperCase(Body) + ':' + #13;
Answer := Answer +
'Use commands:' + #13 +
'HELP - the help' + #13 +
'DIAL - make a call to GSM' + #13 +
'STATUS - state of the system' + #13 +
'CODES - restrictions for mobile networks' + #13 +
'MIN - minimum length of phone number' + #13 +
'MAX - maximum length of phone number' + #13 +
//'USSD - send USSD command to modem' + #13 +
'SENDTOADMIN - send a message to Administrator' + #13 + #13;
if Admin then
Answer := Answer + '-=# COMMANDS FOR ADMINISTRATORS #=-' + #13 +
'USERS - Users list on the server' + #13 +
'CALLMEBACK - LongBridge will make call to you' + #13 +
'MAKEFREE - cancel all conversations' + #13 +
'GSMINMODE - select mode for incoming GSM' + #13 +
'GSMINTO - forward incoming GSM to Skype account' + #13 +
'SMSINMODE - select mode for incoming GSM' + #13 +
'SMSINTO - forward incoming SMS to Skype account' + #13 +
'ADDADMIN - Add an Administrator' + #13 +
'DELADMIN - Delete an Administrator' + #13 +
'SENDTOALL - Send a message to all users' + #13 +
//'IP - show current IPs' + #13 + 'IPSERVICE - show and set IP service' + #13 +
'PREFIX - show and set safety prefix' + #13 +
'USEPREFIX - enable or disable safety prefix' + #13 +
//'REPEATER - enable or disable repeater mode' + #13 +
//'GSMRT - show GSM Route Table' + #13 +
//'GSMRT+ - Add string to GSM Route Table' + #13 +
//'GSMRT- - Delete string from GSM Route Table' + #13 +
'SAVEALL - save all parameters to ini file';
{ HELP } end;
if Body = 'status' then
begin { ---STATUS--- }
Result := 2;
Answer := UpperCase(Body) + ':' + #13 +
'Version: 4.0' + #13;
if LBDSystem.Busy then
Answer := Answer + 'System is busy by ' + LBDSystem.BusyBy
else
Answer := Answer + 'System is free';
end; { ---STATUS--- }
If Body = 'codes' then
begin { ---CODES--- }
Result := 6;
Answer := UpperCase(Body) + ':' + #13;
If length(edt_Codes.Text) > 0 then
Answer := Answer + 'You may call only to the ' + edt_Codes.Text
else
Answer := Answer + 'You may call to any, there is no restrictions';
end; { ---CODES--- }
If Body = 'min' then
begin { ---MIN--- }
Result := 7;
Answer := UpperCase(Body) + ':' + #13;
Answer := Answer + 'Minimum digits is - ' + edt_Min.Text;
end; { ---MIN--- }
If Body = 'max' then
begin { ---MAX--- }
Result := 7;
Answer := UpperCase(Body) + ':' + #13;
Answer := Answer + 'Maximum digits is - ' + edt_Max.Text;
end; { ---MAX--- }
If Body = 'admins' then
begin { ---ADMINS--- }
Result := 4;
Answer := UpperCase(Body) + ':' + #13;
if lbox_Admins.Items.Count > 0 then
for X := 0 to lbox_Admins.Items.Count - 1 do
Answer := Answer + '[' + IntToStr(X) + '] ' + lbox_Admins.Items.Strings[X] + #13
else
Answer := Answer + 'No admins here';
end; { ---ADMINS--- }
// ################################## ADMINISTRATOR COMMANDS ######################################}
if Admin then
begin { ===IF ADMIN=== }
if Body = 'users' then
begin { ---USERS--- }
Result := 2;
Answer := UpperCase(Body) + ':' + #13;
for X := 0 to lbox_SkypeUsers.Items.Count - 1 do
Answer := Answer + '[' + IntToStr(X) + '] ' + lbox_SkypeUsers.Items[X] + #13;
end; { ---USERS--- }
If Body = 'callmeback' then
begin { ---CALLMEBACK--- }
Result := 3;
if not LBDSystem.Busy then
begin
LBDSystem.Direction := 12; // Callback
Answer := 'Please accept the callback';
LBDSystem.Busy := True;
end
else
Answer := 'System is busy by ' + LBDSystem.BusyBy;;
end; { ---CALLMEBACK--- }
If Body = 'makefree' then
begin { ---MAKEFREE--- }
Result := 3;
Answer := UpperCase(Body) + ': ';
Answer := 'Test again with STATUS command';
LBDSystem.Busy := False;
end; { ---MAKEFREE--- }
If Body = 'prefix' then
begin { ---PREFIX--- }
Result := 5;
Answer := UpperCase(Body) + ':' + #13;
Answer := Answer + edt_prefix.Text;
end; { ---PREFIX--- }
If Body = 'useprefix' then
begin { ---USEPREFIX--- }
Result := 5;
Answer := UpperCase(Body) + ':' + #13;
Answer := Answer + BoolToStr(chk_useprefix.Checked, True) + #13;
Answer := Answer + 'Prefix is : ' + edt_prefix.Text;
end; { ---USEPREFIX--- }
If Body = 'saveall' then
begin { ---SAVEALL--- }
Result := 5;
Answer := UpperCase(Body) + ':' + #13;
SaveRouteTable;
SaveIni;
Answer := Answer + 'Saved' + #13;
end; { ---SAVEALL--- }
If Body = 'gsminmode' then
begin { ---GSMINMODE--- }
Result := 5;
Answer := UpperCase(Body) + ':' + #13;
Answer := Answer + '[' + IntToStr(cbox_IncomingMode.ItemIndex) + '] ' + cbox_IncomingMode.Text + #13#13;
Answer := Answer + 'Available modes:' + #13;
for X := 0 to cbox_IncomingMode.Items.Count-1 do
Answer := Answer + '[' + IntToStr(X) + '] ' + cbox_IncomingMode.Items.Strings[X] + #13;
end; { ---GSMINMODE--- }
If Body = 'smsinmode' then
begin { ---SMSINMODE--- }
Result := 5;
Answer := UpperCase(Body) + ':' + #13;
Answer := Answer + '[' + IntToStr(cbox_IncomingSMSMode.ItemIndex) + '] ' + cbox_IncomingSMSMode.Text + #13#13;
Answer := Answer + 'Available modes:' + #13;
for X := 0 to cbox_IncomingSMSMode.Items.Count-1 do
Answer := Answer + '[' + IntToStr(X) + '] ' + cbox_IncomingSMSMode.Items.Strings[X] + #13;
end; { ---SMSINMODE--- }
If Body = 'gsminto' then
begin { ---GSMINTO--- }
Result := 5;
Answer := UpperCase(Body) + ':' + #13;
Answer := Answer + cbox_IncomingTransferTo.Text + #13;
end; { ---GSMINTO--- }
If Body = 'smsinto' then
begin { ---SMSINTO--- }
Result := 5;
Answer := UpperCase(Body) + ':' + #13;
Answer := Answer + cbox_IncomingSMSTransferTo.Text + #13;
end; { ---SMSINTO--- }
end; { ===IF ADMIN=== }
end; { ===ONE WORD=== }
{ ===TWO WORD=== }
if WordCount(Body) = 2 then
begin
Argument := GetToken(Body, ' ', 2);
Body := GetToken(Body, ' ', 1);
If Body = 'dial' then
begin {---DIAL---}
Result := 3;
if not LBDSystem.Busy then
begin
if PhoneNumberisAllowed(Argument, edt_Codes.Text,
StrToInt(edt_Min.Text), StrToInt(edt_Max.Text),
WrongNumber) then
begin
Answer := 'Please accept the callback';
LBDSystem.Direction := 11;
LBDSystem.BusyBy := LBDSystem.CurrentUser;
LBDSystem.GSMNumber := Argument;
LBDSystem.Busy := True;
end
else
Answer := WrongNumber
end
else
Answer := 'System is busy by ' + LBDSystem.BusyBy;
end; {---DIAL---}
If Body = 'prefix' then
begin
Result := 105;
if Admin then
begin
edt_Prefix.Text := Argument;
Answer := UpperCase(Body) + ':' + #13;
Answer := Answer + edt_Prefix.Text;
end
else
Answer := 'You''re not admin here';
end;
If Body = 'useprefix' then
begin
Result := 105;
if Admin then
begin
if TryStrToBool(Argument, DummyBool) then
chk_UsePrefix.Checked := StrToBool(Argument);
edt_Prefix.Enabled := chk_UsePrefix.Checked;
Answer := UpperCase(Body) + ':' + #13;
Answer := Answer + BoolToStr(chk_UsePrefix.Checked, True) + #13;
Answer := Answer + 'Prefix is : ' + edt_Prefix.Text;
end
else
Answer := 'You''re not admin here';
end;
If Body = 'codes' then
begin
Result := 106;
if Admin then
begin
edt_Codes.Text := Argument;
Answer := UpperCase(Body) + ':' + #13;
Answer := Answer + edt_Codes.Text;
end
else
Answer := 'You''re not admin here';
end;
If Body = 'min' then
begin
Result := 107;
if Admin then
begin
if TryStrToInt(Argument, X) then
edt_Min.Text := Argument;
Answer := UpperCase(Body) + ':' + #13;
Answer := Answer + edt_Min.Text;
end
else
Answer := 'You''re not admin here';
end;
If Body = 'max' then
begin
Result := 107;
if Admin then
begin
if TryStrToInt(Argument, X) then
edt_Max.Text := Argument;
Answer := UpperCase(Body) + ':' + #13;
Answer := Answer + edt_Max.Text;
end
else
Answer := 'You''re not admin here';
end;
If Body = 'gsminmode' then
begin { ---GSMINMODE--- }
Result := 5;
if Admin then
begin
if TryStrToInt(Argument, X) then
if (X >= 0) and (X <= cbox_IncomingMode.Items.Count-1) then cbox_IncomingMode.ItemIndex := X;
Answer := UpperCase(Body) + ':' + #13;
Answer := Answer + '[' + IntToStr(cbox_IncomingMode.ItemIndex) + '] ' + cbox_IncomingMode.Text + #13#13;
Answer := Answer + 'Available modes:' + #13;
for X := 0 to cbox_IncomingMode.Items.Count-1 do
Answer := Answer + '[' + IntToStr(X) + '] ' + cbox_IncomingMode.Items.Strings[X] + #13;
end
else
Answer := 'You''re not admin here';
end; { ---GSMINMODE--- }
If Body = 'smsinmode' then
begin { ---SMSINMODE--- }
Result := 5;
if Admin then
begin
if TryStrToInt(Argument, X) then
if (X >= 0) and (X <= cbox_IncomingSMSMode.Items.Count-1) then cbox_IncomingSMSMode.ItemIndex := X;
Answer := UpperCase(Body) + ':' + #13;
Answer := Answer + '[' + IntToStr(cbox_IncomingSMSMode.ItemIndex) + '] ' + cbox_IncomingSMSMode.Text + #13#13;
Answer := Answer + 'Available modes:' + #13;
for X := 0 to cbox_IncomingSMSMode.Items.Count-1 do
Answer := Answer + '[' + IntToStr(X) + '] ' + cbox_IncomingSMSMode.Items.Strings[X] + #13;
end
else
Answer := 'You''re not admin here';
end; { ---SMSINMODE--- }
If Body = 'gsminto' then
begin { ---GSMINTO--- }
Result := 107;
if Admin then
begin
cbox_IncomingTransferTo.Text := Argument;
Answer := UpperCase(Body) + ':' + #13;
Answer := Answer + cbox_IncomingTransferTo.Text;
end
else
Answer := 'You''re not admin here';
end; { ---GSMINTO--- }
If Body = 'smsinto' then
begin { ---SMSINTO--- }
Result := 107;
if Admin then
begin
cbox_IncomingSMSTransferTo.Text := Argument;
Answer := UpperCase(Body) + ':' + #13;
Answer := Answer + cbox_IncomingSMSTransferTo.Text;
end
else
Answer := 'You''re not admin here';
end; { ---SMSINTO--- }
If Body = 'addadmin' then
begin
Result := 104;
if Admin then
begin
lbox_Admins.Items.Add(Argument);
DeleteDuplicates(lbox_Admins);
Answer := UpperCase(Body) + ':' + #13;
if lbox_Admins.Items.Count > 0 then
for X := 0 to lbox_Admins.Items.Count - 1 do
Answer := Answer + lbox_Admins.Items.Strings[X] + #13
else
Answer := Answer + 'No admins here';
end
else
Answer := 'You''re not admin here';
end;
If Body = 'deladmin' then
begin
Result := 104;
if Admin then
begin
lbox_Admins.Items.Add(Argument);
DeleteDuplicates(lbox_Admins);
Answer := UpperCase(Body) + ':' + #13;
if Argument <> LBDSystem.BusyBy then
begin
lbox_Admins.Selected[lbox_Admins.Items.IndexOf(Argument)] := True;
lbox_Admins.DeleteSelected;
end
else
Answer := Answer + 'You can not delete yourself!' + #13;
if lbox_Admins.Items.Count > 0 then
for X := 0 to lbox_Admins.Items.Count - 1 do
Answer := Answer + lbox_Admins.Items.Strings[X] + #13
else
Answer := Answer + 'No admins here';
end
else
Answer := 'You''re not admin here';
end;
end; { ===TWO WORD=== }
{ ===MANY WORDS=== }
if WordCount(Body) > 2 then
begin
Argument := Body;
Body := GetToken(Body, ' ', 1);
delete(Argument, 1, length(Body) + 1);
If Body = 'codes' then
begin
Result := 106;
if Admin then
begin
edt_Codes.Text := Argument;
Answer := UpperCase(Body) + ':' + #13;
Answer := Answer + edt_Codes.Text;
end
else
Answer := 'You''re not admin here';
end;
if Body = 'sendtoall' then
begin { ===SENDTOALL=== }
Result := 104;
if Admin then
begin
Answer := UpperCase(Body) + ':' + #13;
Xx := 0;
for X := 0 to lbox_SkypeUsers.Items.Count - 1 do
begin
TRY
Skype.CreateChatWith(lbox_SkypeUsers.Items[X]);
Skype.SendMessage(lbox_SkypeUsers.Items[X], Argument);
Sleep(50);
Inc(Xx);
EXCEPT
Answer := Answer + 'Some Error...';
END;
end;
Answer := Answer + 'Your message was sent to ' + IntToStr(Xx) +
' users.';
end
else
Answer := 'You''re not admin here';
end; { ===SENDTOALL=== }
if Body = 'sendtoadmin' then
begin { ===SENDTOADMIN=== }
Result := 104;
Answer := UpperCase(Body) + ':' + #13;
Xx := 0;
if lbox_Admins.Items.Count > 0 then
for X := 0 to lbox_Admins.Items.Count - 1 do
begin
TRY
Skype.CreateChatWith(lbox_Admins.Items[X]);
Skype.SendMessage(lbox_Admins.Items[X], LBDSystem.CurrentUser + ' says: ' + Argument);
Sleep(50);
Inc(Xx);
EXCEPT
Answer := Answer + 'Some Error...';
END;
end;
Answer := Answer + 'Your message was sent to ' + IntToStr(Xx) +
' Admins.';
end; { ===SENDTOADMIN=== }
end; { ===MANY WORDS=== }
end; { ===EOP=== }