All pastes #837752 Raw Edit

Anonymous

public text v1 · immutable
#837752 ·published 2007-12-29 22:01 UTC
rendered paste body
unit YchatU1;

interface

uses
  Windows,  SysUtils,   Graphics, Controls, Forms,
  Dialogs, ExtCtrls, StdCtrls, Buttons, Menus,
  Registry,  ComCtrls,YchatU4,  ActiveX, OleStd,JpgImg,
   ImgList, calculator,  MmSystem, jpeg, GifImage,HashTrie,  OleCtrls, YACSCOMLib_TLB, Winsock,
  SkinCtrls, ad3SpellBase, ad3Spell, ad3LiveBase, ad3LiveAutospell,
  spSkinShellCtrls, SkinData, SkinMenus,  ScktComp,
  SkinBoxCtrls, MyRicheditEx,  Classes, Richedit,
  DBSock, filedownloader,ImageHlp,OleConsts,Comobj,CjDateUtils,Math,
  Names,ShellAPI, FileCtrl, YmsgAuth, SpartaServices, MImage, MemoryMan, FastIniFile, CjEncrypt,
  Mask,  GetIp2,  spTrayIcon,  Messages, DynamicSkinForm,
  RicheditFuncs, ad3RichEdit,spColorCtrls, MediaPlayer_TLB,
  SkinHint, DYmsg;

 Const
  FontInf: String ='p𣢍T}‚zT}xn¡€¨™TuŠun';

// IP address as an array of 4 bytes
{type
  PIpBytes       =  ^TIpBytes;
  TIpBytes       =  Array [0..3] of Byte;

// Enumerations
type
  TIpInOut       =  (ioIn, ioOut);
  TIpProtocol    =  (protoTcp, protoUdp, protoAny);

// Globals
var
  hIF:           INTERFACE_HANDLE;
  ipLocal:       TIpBytes;}


type
  TDllRegisterServer = function: HResult; stdcall;

Type
{overrides wrong TTextRange definition in RichEdit.pas}
 TTextRange = record
   chrg: TCharRange;
   lpstrText: PAnsiChar;
end;


type
 TMyProxySettings = record
   Server: string[255];
   Port: integer;
   Enabled: boolean;
 end;


 Type
  TRichEditObject = packed record
    cbStruct: Longword;     // Size of structure C++: DWord
    cp: Longword;           // Character position of object c++:Long
    clsid: TClsID;				// Class ID of object
    oleobj: IOleObject;			// OLE object interface
    stg: IStorage;				// Associated storage interface
    olesite: IOLEClientSite;			// Associated client site interface
    sizel: TSize;				// Size of object (may be 0,0)
    dvaspect: Longword;			// Display aspect to use
    dwFlags: Longword;			// Object status flags
    dwUser: Longword;				// Dword for user's use
  end;

  type
     TEditStreamCallBack = function (dwCookie: Longint; pbBuff: PByte;cb:
     Longint; var pcb: Longint): DWORD; stdcall;

      TEditStream = record
       dwCookie: Longint;
       dwError: Longint;
       pfnCallback: TEditStreamCallBack;
     end;


Type
  PUserData2 = ^TuserData2;
  TUserData2 = Packed Record
    RoomName,ExtendedInfo,Ident,UserName: String[255];
    Age: String[3];
    ColIDStr: String[255];
    UCaseV: DWord;
    Iggies: Integer;
    LastBlock,LastUrl: String[255];
    Proto,CheckSum,Version,Extra,Mf: String[10];
    BotPCount,BlockCount,TotalBlock: Integer;
    AssignedCustomName,CustomName,AltTag,FadeTag,ChatClient,Location,Nick: String[255];
    LastThingsSaid: Array [1..5] of String;
    Station,CustomData: String;
    DebugStr: String;
    PostNum: Word;
    SourceID: Integer;
    UcaseUsed,SaidYourName: Boolean;
    NumLinesPosted: Integer;
    LocalTime,Joined,LastPost: TdateTime;
    YLinePost: Integer;
  End;

Type TPornBots = Class(TObject)
 Private
   BotList,BotStrings: TStringHashTrie;
    Obj: Tobject;
    procedure Clear;
 Public
   procedure SaveStringsList; 
   Function CheckBot(UserName: String): Boolean;
   Function CheckString(Username,Str: String): Boolean;
   Function TrackBot(UserName: String): Integer;
   function DeleteBot(UserName: String): Integer;   
   Procedure AddBotString(Str: String);
   Function  DealWithBot(Username,Str: String): Boolean;
   Function ChatP(UserName,Str: String): Boolean;
   Constructor Create;
   Destructor Destroy; override;
End;


type
//   TREOleCallBack = class (TInterfacedObject, IRichEditOleCallback)
    TREOleCallBack = class (TInterfacedObject, IRichEditOleCallback)
    Function _Release : Longint;Stdcall;
    Function GetNewStorage(Out stg : IStorage) : HResult;Stdcall;
    function GetInPlaceContext (out Frame: IOleInPlaceFrame; out Doc: IOleInPlaceUIWindow; var FrameInfo: TOleInPlaceFrameInfo): HRESULT; overload; stdcall;
    function ShowContainerUI (fShow: BOOL): HRESULT; overload; stdcall;
    function QueryInsertObject (const clsid: TCLSID; stg: IStorage; cp: longint): HRESULT; overload; stdcall;
    function DeleteObject (oleobj: IOLEObject): HRESULT; overload; stdcall;
    function QueryAcceptData (dataobj: IDataObject; var cfFormat: TClipFormat; reco: DWORD; fReally: BOOL; hMetaPict: HGLOBAL): HRESULT; overload; stdcall;
    function ContextSensitiveHelp (fEnterMode: BOOL): HRESULT; overload; stdcall;
    function GetClipboardData (const chrg: _CharRange; reco: DWORD; out dataobj: IDataObject): HRESULT; overload; stdcall;
    function GetDragDropEffect (fDrag: BOOL; grfKeyState: DWORD; var dwEffect: DWORD): HRESULT; overload; stdcall;
    function GetContextMenu (seltype: Word; oleobj: IOleObject; const chrg: _CharRange; var menu: HMENU): HRESULT; overload; stdcall;
  private
    FItemCount : integer;
    FStorage : IStorage;
    procedure DeleteObject (OleObject: IOLEObject; var Result : integer); overload; virtual; abstract;
  public
    constructor Create;
  end;

 Type TCords = Record
   X: Integer;
   Y: Integer;
 End;


Type TCloneDetails = Record
       Percent: Integer;
       ID1: String[50];
       ID2: String[50];
   End;


Type TDebugDisplay = Class(TThread)
 S: String;
 Code: Integer;
 Constructor Create(S2: String; Code2: Integer);
 Procedure Execute; Override;
End;


Type TwhatIsMyIP = Class (TThread)
  Port,Server: String;
  HttpStr: String;
  Data: String;
  Count: Integer;
  Socket: TDCBSock;
  Procedure Execute; Override;
  Procedure OnDisconnect;
  Constructor Create(SSearchStr,SUser: String; SCount: Integer);
End;


Type TGetAlphaCode = Class (TThread)
  Port,Server: String;
  HttpStr: String;
  Data: String;
  FSend: Boolean;
  FKeyStr: String;
  Count: Integer;
  Socket: TDCBSock;
  Procedure Execute; Override;
  Constructor Create(Url: String; Send: Boolean; KeyStr: String);
  private
    procedure GetCode;
    procedure SendCode;
End;


Type TYahooNews = Class (TThread)
  Port,Server: String;
  HttpStr: String;
  Data: String;
  Count: Integer;
  Socket: TDCBSock;
  Procedure Execute; Override;
  Constructor Create;
End;

Type TGetRoomList = Class(TThread)
  Socket: TDCBSock;
  LB: TListBox;
  S,CCookie,RmCat,Serv,GetType: String;
  Procedure OnError(Sender: Tobject; ErrorCode: Integer);
  Constructor Create(SServ,SGetType,Scookie,SRmCat: String; SLB: TListBox);
  Procedure Execute; OverRide;
  Procedure OnDisconnect(Data: String);
End;

Type TGetRoomList2 = Class(TThread)
  Socket: TDCBSock;
  S,CCookie,RmCat,Serv,GetType: String;
  Procedure OnError(Sender: Tobject; ErrorCode: Integer);
  Constructor Create(SServ,SGetType,Scookie,SRmCat: String);
  Procedure Execute; OverRide;
  Procedure OnDisconnect(Data: String);
End;


Type TIdentitarDownload = Class (TThread)
  Br: Integer;
  Image: TImage;
  HttpStr,HttpGrabData,Port,Server: String;
  S,ExtendedInfo,Fn1,Fn2,Data: String;
  Socket: TDCBSock;
  Buf: Array[0..8024] of Char;
  Procedure Execute; Override;
  Procedure OnDisconnect;
  Constructor Create(Sfn1: String; ImageObj: Timage);
End;


Type
   TUserFields = Class(Tobject)
    Private
     Fields: TStringList;
    Public
     FieldCount: Integer;
     Constructor Create;
     Destructor Destroy; Override;
     Procedure SplitFields(S: String);
     Function GetField(S: String): String;
 End;


 Type
   TUserFields2 = Class(Tobject)
    Private
     Fields: TStringList;
    Public
     FieldCount: Integer;
     Constructor Create;
     Destructor Destroy; Override;
     Procedure SplitFields(S: String);
     Function GetField(S: String): String;
 End;

Type
  TGetIdentList = Class(TThread)
   Private
    Sock: TDCBSock;
    Sender: Tobject;
    AvaList: TStringList;
    function ExtractIdent(S: String): String;
   Public
    Constructor Create(Limit: Integer; SSender: Tobject);
    Destructor Destroy; Override;
    Procedure Execute; Override;
End;

Type TCheetaDownload = Class (TThread)
  Br: Integer;
  S,Port,Server: String;
  HttpStr,HttpGrabData,ExtendedInfo,Fn1,Fn2,Data: String;
  Socket: TDCBSock;
  Buf: Array[0..2024] of Char;
  Procedure Execute; Override;
  Procedure OnDisconnect;
  Constructor Create(Sfn1: String);
End;


Type TGetNewsHeadlines = Class (TThread)
  Code,Br: Integer;
  GetImage: Boolean;
  SearchStr,Port,Server: String;
  HttpStr,ExtendedInfo,User,Fn2,Data: String;
  Socket: TDCBSock;
  Procedure Execute; Override;
  Procedure OnDisconnect;
  Constructor Create(SSearchStr: String);
End;


Type TFadeWindow = Class(TThread)
   Obj: TPanel;
   StartC,FinishC: Tcolor;
   Delay,Steps: Integer;
   Constructor Create(SObj: TPanel; SStartC,SFinishC: Tcolor; SSteps,SDelay: Integer);
   Procedure Execute; override;
 End;


Type TFileDownload = Class(TThread)
 Private
  Sock: TDCBsock;
  Offset: Longint;
  OnNotification,FPause: Boolean;
  Url,Server: String;
  ExeOnFinish,YmUpdate: Boolean;
  LocalF: String;
  Port: String;
  Obj: Tform39;
  Public
   Constructor Create(SUrl,SlocalF: String; SPort: String; SOffset: Longint; SObj: TForm39; YmLiteUpdate: Boolean; ExecuteOnFinish,FonNotification,Resumable: Boolean);
   Procedure Execute; Override;
   Procedure Pause;
   Procedure Go;
End;




Type TConvertURLsToIps = Class(TThread)
  Private
   Str: String;
    function GetHostFromStr(S: String): String;
  Public
  Constructor Create(FStr: String);
  function HostToIP(Host: String): String;
  Procedure Execute; Override;
 End;

Type TGetIPAdd = Class (TThread)
  Code,Br: Integer;
  CreateAccount,GetImage: Boolean;
  Port,Server: String;
  HttpStr,ExtendedInfo,User,Fn2,Data: String;
  Socket: TDCBSock;
  Procedure Execute; Override;
  Procedure OnDisconnect;
  Constructor Create(SSearchStr: String);
End;


Type TWeather = Class (TThread)
  Code,Br: Integer;
  GetImage: Boolean;
  UserName,SearchStr,Port,Server: String;
  HttpStr,ExtendedInfo,User,Fn2,Data: String;
  Socket: TDCBSock;
  Procedure Execute; Override;
  Procedure OnDisconnect;
  Constructor Create(Suser,SSearchStr: String);
End;




Type TCreateAccount = Class (TThread)
  Br: Integer;
  Cp,AddUser: Boolean;
  S,Port,Server: String;
  HttpStr,ExtendedInfo,User,Fn2,Data: String;
  Socket: TDCBSock;
  NewPassword,OldPassword: String;
  Age,Password,Gender,location,HomePage,EmailAdd: String;
  Procedure Execute; Override;
  Procedure OnDisconnect;
  Constructor Create(SUser,Spassword,SGender,SLocation,ShomePage,SEmailAdd, SAge: String; SCP: Boolean);
End;


Type TincCounterStats = Class (TThread)
  Port,Server: String;
  Data: String;
  Socket: TDCBSock;
  Procedure Execute; Override;
  Procedure OnDisconnect;
  Constructor Create;
End;

Type TStartSound = Class(TThread)
  AFileName: String;
  AlertSound,FExt: Boolean;
  Procedure execute; Override;
  Constructor Create(FileName: String; EXt,FAlertSound: Boolean);
 End;


Type TStruct = Record
  Min: Longint;
  Max: Longint;
  TheWord: String;
End;


Type TRemoveBuddyFromOthers = Class (TThread)
  Br: Integer;
  S,Port,Server: String;
  HttpStr,ExtendedInfo,User,Fn2,Data: String;
  Socket: TDCBSock;
  Procedure Execute; Override;
  Procedure OnDisconnect;
  Constructor Create(SUser: String);
End;

Type  TWorkingDetails = Record
    Port: Integer;
    Server: String;
 End;

Type
   Tmp3Library = Class(TObject)
    Public
     WinampHandle: Hwnd;
     MatchList: TStringList;
     mp3ListLoaded: Boolean;
     PlayListTracks: Integer;
     FromMemory: Boolean;
     Mp3List: TStringList;
     Constructor Create;
     Destructor Destroy; override;
     Procedure BuildMp3FileDb;
     Procedure PlayRandomMp3;
     Procedure PlayPartialMatch(Str: String);
     function MediaPlayerString: String;
     function UltraMP3PlayerString: String;
     function winamp: string;
    Private
     T: TextFile;
    Procedure FindFiles(Dir: String);
    procedure LoadMp3List;
    function SMP3PlayerString: String;
   End;

TYPE
 TRGBTripleArray = ARRAY[WORD] OF TRGBTriple;
 pRGBTripleArray = ^TRGBTripleArray;

Type
   PPersonality = ^Tpersonality;
   TPersonality = Record
    OldWord: String;
    NewWord: String;
   End;

Type
  TObjPersonality = Class(Tobject)
  private
   Personalitys: Array of TPersonality;
   PersonalityLoaded: Boolean;
   PersonalitySearch: TStringList;
  Public
    Constructor Create;
    Destructor Destroy; override;
    Procedure Clear;
    function TextToPersonality(S: String): String;
    function GetPersonalityWord(S: String): String;
    function LoadPersonality(Fn: String): Boolean;
    procedure TestLoad;
 End;



Type
 TBadEnglish = Class(Tobject)
  private
    function JumbleChars(S: String): String;
    function TextToBadEnglish(S: String): String;
 End;


Type
  TKnock = Class(Tobject)
   Public
     FKnockRoom: String;
     FInterVal,FTimeOut: Longint;
     Procedure StartKnocking;
     Procedure StopKnock;
     constructor Create(Room: String; Timeout,Interval: Integer);
     Destructor Destroy; Override;
   Private
     Timer: TTimer;
     KnockAttempt,Counter: Longint;
     Procedure OnTimer(Sender: Tobject);
End;




type
  TForm1 = class(TForm)
    Timer1: TTimer;
    ColorDialog1: TColorDialog;
    SaveDialog1: TSaveDialog;
    PopupMenu2: TPopupMenu;
    RemoveBuddy1: TMenuItem;
    InstantMessage2: TMenuItem;
    PopupMenu3: TPopupMenu;
    Logout1: TMenuItem;
    Exist1: TMenuItem;
    Timer2: TTimer;
    Timer3: TTimer;
    FindDialog1: TFindDialog;
    ImageList3: TImageList;
    PopupMenu5: TPopupMenu;
    RemoveBuddy2: TMenuItem;
    IMPMUser1: TMenuItem;
    IMPMallusersonlist1: TMenuItem;
    AddBuddy3: TMenuItem;
    GroupIM1: TMenuItem;
    DumpFriendsList1: TMenuItem;
    Timer4: TTimer;
    MainPanel: TPanel;
    SPRT: TClientSocket;
    OpenDialog1: TOpenDialog;
    Ymsg: TClientSocket;
    spDynamicSkinForm1: TspDynamicSkinForm;
    spSkinData1: TspSkinData;
    Popupmenu1: TspSkinPopupMenu;
    ActionFor1: TMenuItem;
    RoomFunctions1: TMenuItem;
    IgnoreUsershighlighted1: TMenuItem;
    IMBroadcasttoroom1: TMenuItem;
    Friends2: TMenuItem;
    AssignCustomName1: TMenuItem;
    InviteToViewWebCam1: TMenuItem;
    ViewWebCam1: TMenuItem;
    RemoveBuddy3: TMenuItem;
    AddtoNeverIgnore1: TMenuItem;
    AddAsBuddy2: TMenuItem;
    Profiles1: TMenuItem;
    PutNameInTextArea1: TMenuItem;
    InstantMessage1: TMenuItem;
    VoiceIgnore1: TMenuItem;
    IgnoreUser1: TMenuItem;
    LogUser1: TMenuItem;
    PopupMenu4: TspSkinPopupMenu;
    N1: TMenuItem;
    IgnoreUser2: TMenuItem;
    ViewProfile2: TMenuItem;
    Friends3: TMenuItem;
    AssignCustomName2: TMenuItem;
    ViewWebCam2: TMenuItem;
    Invitetoviewwebcam2: TMenuItem;
    AddToNeverIgnore2: TMenuItem;
    RemoveBuddy4: TMenuItem;
    Addasbuddy1: TMenuItem;
    IMPMuser2: TMenuItem;
    LogUser2: TMenuItem;
    PopupMenu7: TspSkinPopupMenu;
    Copy2: TMenuItem;
    oops1: TMenuItem;
    OpenPictureDialog1: TspSkinOpenPictureDialog;
    spOpenSkinDialog1: TspOpenSkinDialog;
    spSkinPopupMenu1: TspSkinPopupMenu;
    Copy4: TMenuItem;
    Paste2: TMenuItem;
    DropMailMessage1: TMenuItem;
    ViewLastPacket1: TMenuItem;
    ViewLastPacket2: TMenuItem;
    Panel5: TPanel;
    Panel6: TPanel;
    Button1: TspSkinButton;
    spSkinControlBar1: TspSkinControlBar;
    spSkinToolBar5: TspSkinToolBar;
    Label3: TLabel;
    spSkinSpeedButton2: TspSkinSpeedButton;
    spSkinTrackBar1: TspSkinTrackBar;
    spSkinGauge1: TspSkinGauge;
    spSkinGauge2: TspSkinGauge;
    Button8: TspSkinButton;
    Button9: TspSkinButton;
    spSkinButton5: TspSkinButton;
    spSkinToolBar8: TspSkinToolBar;
    spSkinControlBar2: TspSkinControlBar;
    spSkinToolBar1: TspSkinToolBar;
    spSkinStdLabel1: TspSkinStdLabel;
    spSkinStdLabel2: TspSkinStdLabel;
    spSkinStdLabel3: TspSkinStdLabel;
    BoldP: TspSkinCheckRadioBox;
    ItalicP: TspSkinCheckRadioBox;
    UnderlineP: TspSkinCheckRadioBox;
    spSkinCheckRadioBox1: TspSkinCheckRadioBox;
    spSkinToolBar2: TspSkinToolBar;
    spSkinFontComboBox1: TspSkinFontComboBox;
    spSkinComboBox2: TspSkinComboBox;
    RicheditReplacement: TPanel;
    RichEdit1: TMyRichEdit;
    Button3: TButton;
    Panel3: TPanel;
    spSkinToolBar6: TspSkinToolBar;
    spSkinButton2: TspSkinButton;
    spSkinButton3: TspSkinButton;
    spSkinSplitter2: TspSkinSplitter;
    spSkinSplitter3: TspSkinSplitter;
    MainMenu1: TMainMenu;
    Yahoo1: TMenuItem;
    Login1: TMenuItem;
    CreateSparterAccount1: TMenuItem;
    ChangeSparterPassword1: TMenuItem;
    Disconnect1: TMenuItem;
    ClearChatText1: TMenuItem;
    YOptions1: TMenuItem;
    Lockout1: TMenuItem;
    SaveChatText1: TMenuItem;
    MailLogin1: TMenuItem;
    EditNick1: TMenuItem;
    ExpDetails1: TMenuItem;
    Exit1: TMenuItem;
    Edit1: TMenuItem;
    Copy1: TMenuItem;
    SelectAll1: TMenuItem;
    Find1: TMenuItem;
    Format1: TMenuItem;
    HotKeysEnabled1: TMenuItem;
    DingOnID1: TMenuItem;
    FlashWindowOnID1: TMenuItem;
    AIOptions1: TMenuItem;
    EnableAi1: TMenuItem;
    OtronTechnology1: TMenuItem;
    AutoReplytowb1: TMenuItem;
    Replytothanks1: TMenuItem;
    Greetbuddywhentheyenter1: TMenuItem;
    CustomMessagesSetup1: TMenuItem;
    Identitar1: TMenuItem;
    On1: TMenuItem;
    ViewIdentitars1: TMenuItem;
    UploadIdentitar1: TMenuItem;
    MessengerStyleEmotes1: TMenuItem;
    Filters1: TMenuItem;
    GirlyFilter1: TMenuItem;
    EnableSwearWordFilter1: TMenuItem;
    AutoRejectAddBuddy1: TMenuItem;
    ProcessGamesMessages1: TMenuItem;
    Style1: TMenuItem;
    Forcetexttolowercase1: TMenuItem;
    Brightcolorfiltr1: TMenuItem;
    AlphaSpellChecker1: TMenuItem;
    HTTPFileDownloader1: TMenuItem;
    View1: TMenuItem;
    ViewURLS1: TMenuItem;
    QuickRoomHotkeys1: TMenuItem;
    Friends1: TMenuItem;
    AllOnlineFriends1: TMenuItem;
    ViewOnlineFriends1: TMenuItem;
    NeverIgnoreList1: TMenuItem;
    ViewUsersIgnored1: TMenuItem;
    Emotes1: TMenuItem;
    Scroll1: TMenuItem;
    RoomEnterLeaveMessages1: TMenuItem;
    UerswhosaidyourID1: TMenuItem;
    StayOnTop1: TMenuItem;
    MenuBar1: TMenuItem;
    Messenger1: TMenuItem;
    AddBuddy1: TMenuItem;
    DeleteBuddy1: TMenuItem;
    AwayIMPMSettings1: TMenuItem;
    YaheliteIgnoreImport1: TMenuItem;
    YaheliteButtonImport1: TMenuItem;
    CheetaChat657IgnoreImport1: TMenuItem;
    Removeyourselffromothersfriendslist1: TMenuItem;
    LaunchVoice1: TMenuItem;
    StartMyWebCam1: TMenuItem;
    EnableAntiBootMode1: TMenuItem;
    Updates1: TMenuItem;
    ColorSchemes1: TMenuItem;
    SelectWallpaperBMP1: TMenuItem;
    SelectSkin1: TMenuItem;
    oys1: TMenuItem;
    PostHomePage1: TMenuItem;
    YmLiteAdPerkTheirInterest1: TMenuItem;
    Funstuff1: TMenuItem;
    HackersCode1: TMenuItem;
    Mirroryourtext1: TMenuItem;
    IggyRoulette1: TMenuItem;
    AddNewSmileyFace1: TMenuItem;
    SmileyEditor1: TMenuItem;
    CoolJansText1: TMenuItem;
    YMSGPingTime1: TMenuItem;
    YmLiteScreenShot1: TMenuItem;
    UserIDCheck1: TMenuItem;
    DebugOptions1: TMenuItem;
    ViewYPackets1: TMenuItem;
    PacketConstructor1: TMenuItem;
    Releaseanyfreememory1: TMenuItem;
    RequestEchoChat1: TMenuItem;
    GetCPUSpeed1: TMenuItem;
    EnableBossKeyF101: TMenuItem;
    ViewButtons1: TMenuItem;
    UserReport1: TMenuItem;
    ViewDownloadsDirectory1: TMenuItem;
    Help1: TMenuItem;
    About2: TMenuItem;
    Credits1: TMenuItem;
    DonateToHelpKeepYmLiteGoing1: TMenuItem;
    BadEnglishGenerator1: TMenuItem;
    ConvertIt1: TMenuItem;
    TheYmLiteFourm1: TMenuItem;
    spSkinPopupMenu4: TspSkinPopupMenu;
    Move1: TMenuItem;
    ViewGSCams1: TMenuItem;
    InviteBuddy1: TMenuItem;
    PostLinkToFourms1: TMenuItem;
    YTunnelIgnoreListImport1: TMenuItem;
    SpellChecker1: TMenuItem;
    spSkinScrollPanel1: TspSkinGroupBox;
    spSkinExPanel2: TspSkinExPanel;
    spSkinPanel1: TspSkinPanel;
    ListBox2: TspSkinListBox;
    spSkinExPanel3: TspSkinExPanel;
    Panel16: TspSkinMenuButton;
    spSkinExPanel1: TspSkinExPanel;
    spSkinExPanel4: TspSkinExPanel;
    ListBox3: TListBox;
    MemoryStats1: TMenuItem;
    spSkinOpenDialog1: TspSkinOpenDialog;
    ListenToTheirStation1: TMenuItem;
    ListenToThierStation1: TMenuItem;
    spSkinPopupMenu2: TspSkinPopupMenu;
    Flanger1: TMenuItem;
    Flanger2: TMenuItem;
    Echo1: TMenuItem;
    Reverb1: TMenuItem;
    Off1: TMenuItem;
    DigitallyImported1: TMenuItem;
    DigitallyImported56K1: TMenuItem;
    spSkinMainMenuBar1: TspSkinMainMenuBar;
    Timer5: TTimer;
    SelectJpgIdent1: TMenuItem;
    TimeSpentTyping1: TMenuItem;
    Panel10: TspSkinXFormButton;
    YmLiteVoiceShield2KXPOnly1: TMenuItem;
    ServerSocket1: TServerSocket;
    FlagAsBotLearn1: TMenuItem;
    AutoRejectViewCamMessages1: TMenuItem;
    InterfaceOptions1: TMenuItem;
    FancyMenuInterface1: TMenuItem;
    ChangeRooms1: TMenuItem;
    spTrayIcon1: TspTrayIcon;
    SendCheetaSound1: TMenuItem;
    Image1: TMImage;
    Richedit2: TAddictRichEdit;
    NeedaDrinksTrayHolder1: TMenuItem;
    AllowVoice1: TMenuItem;
    VoiceProblemFixClick1: TMenuItem;
    Label2: TspSkinShadowLabel;
    ListBox1: TListBox;
    spSkinImagesMenu1: TspSkinImagesMenu;
    ImageList1: TImageList;
    spSkinComboBox1: TspSkinComboBox;
    spSkinMenuButton2: TspSkinMenuButton;
    CompressedStoredSkin1: TspCompressedStoredSkin;
    spSkinPanel2: TspSkinPanel;
    spSkinSpinEdit1: TspSkinSpinEdit;
    ColorBox1: TspSkinColorButton;
    Panel1: TspSkinPanel;
    spSkinSplitter1: TspSkinSplitter;
    spSkinComboBox5: TspSkinComboBox;
    spSkinButton13: TspSkinButton;
    spSkinHint1: TspSkinHint;
    RejectMailInvites1: TMenuItem;
    ResetFlagAsBotFilter1: TMenuItem;
    YmLiteGeneralSounds1: TMenuItem;
    YmLiteAlertSoundsBootersetc1: TMenuItem;
    spSkinButton1: TspSkinButton;
    Eye: TYMSG;
    Timer7: TTimer;
    GotoUser2: TMenuItem;
    procedure Exit1Click(Sender: TObject);
    procedure Login1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure ViewYPackets1Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Disconnect1Click(Sender: TObject);
    procedure RichEdit1Change(Sender: TObject);
    procedure ClearChatText1Click(Sender: TObject);
    procedure InstantMessage1Click(Sender: TObject);
    procedure IgnoreUser1Click(Sender: TObject);
    procedure ViewURLS1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure Credits1Click(Sender: TObject);
    procedure PutNameInTextArea1Click(Sender: TObject);
    procedure ListBox1DblClick(Sender: TObject);
    procedure SelectAll1Click(Sender: TObject);
    procedure Copy1Click(Sender: TObject);
    procedure YOptions1Click(Sender: TObject);
    procedure ViewUsersIgnored1Click(Sender: TObject);
    procedure ViewOnlineFriends1Click(Sender: TObject);
    procedure Scroll1Click(Sender: TObject);
    procedure Form12GotoUser1Click(Sender: TObject);
    procedure InstantMessage2Click(Sender: TObject);
    procedure About2Click(Sender: TObject);
    procedure EnableSwearWordFilter1Click(Sender: TObject);
    procedure Updates1Click(Sender: TObject);
    procedure Richedit1MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure RoomEnterLeaveMessages1Click(Sender: TObject);
    procedure PostHomePage1Click(Sender: TObject);
    procedure RxTrayIcon1Click(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Exist1Click(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure AddBuddy1Click(Sender: TObject);
    procedure DeleteBuddy1Click(Sender: TObject);
    procedure Panel16eMouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure RichEdit1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Timer3Timer(Sender: TObject);
    procedure GetCPUSpeed1Click(Sender: TObject);
    procedure Emotes1Click(Sender: TObject);
    procedure MailLogin1Click(Sender: TObject);
    procedure QuickRoomHotkeys1Click(Sender: TObject);
    procedure Richedit1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure IMuser1Click(Sender: TObject);
    procedure IgnoreUser2Click(Sender: TObject);
    procedure ViewProfile2Click(Sender: TObject);
    procedure UserIdClick(Sender: TObject);
    procedure ExpDetails1Click(Sender: TObject);
    procedure AssignCustomName1Click(Sender: TObject);
    procedure AssignCustomName2Click(Sender: TObject);
    procedure EnableAi1Click(Sender: TObject);
    procedure HackersCode1Click(Sender: TObject);
    procedure HotKeysEnabled1Click(Sender: TObject);
    procedure LogUser1Click(Sender: TObject);
    procedure LogUser2Click(Sender: TObject);
    procedure UerswhosaidyourID1Click(Sender: TObject);
    procedure AllOnlineFriends1Click(Sender: TObject);
    procedure FindDialog1Find(Sender: TObject);
    procedure Find1Click(Sender: TObject);
    procedure FindDialog1Close(Sender: TObject);
    procedure ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    procedure AwayIMPMSettings1Click(Sender: TObject);
    procedure RemoveBuddy1Click(Sender: TObject);
    procedure EditNick1Click(Sender: TObject);
    procedure YMSGPingTime1Click(Sender: TObject);
    procedure UserIDCheck1Click(Sender: TObject);
    procedure AddAsFriend1Click(Sender: TObject);
    procedure On1Click(Sender: TObject);
    procedure DingOnID1Click(Sender: TObject);
    procedure IMPMallusersonlist1Click(Sender: TObject);
    procedure RemoveBuddy2Click(Sender: TObject);
    procedure GroupIM1Click(Sender: TObject);
    procedure AutoReplytowb1Click(Sender: TObject);
    procedure Replytothanks1Click(Sender: TObject);
    procedure MessengerStyleEmotes1Click(Sender: TObject);
    procedure IggyRoulette1Click(Sender: TObject);
    procedure AvatarConnect(Sender: TObject; Socket: TCustomWinSocket);
    procedure Event1Click(Sender: TObject);
    procedure Forcetexttolowercase1Click(Sender: TObject);
    procedure Brightcolorfiltr1Click(Sender: TObject);
    procedure EnableBossKeyF101Click(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure Releaseanyfreememory1Click(Sender: TObject);
    procedure Splitter3Moved(Sender: TObject);
    procedure OnEnterGreetFriends1Click(Sender: TObject);
    procedure Greetbuddywhentheyenter1Click(Sender: TObject);
    procedure CustomMessagesSetup1Click(Sender: TObject);
    procedure Lockout1Click(Sender: TObject);
    procedure PopupMenu1Popup(Sender: TObject);
    procedure AddNewSmileyFace1Click(Sender: TObject);
    procedure Mirroryourtext1Click(Sender: TObject);
    procedure UserReport1Click(Sender: TObject);
    procedure PacketConstructor1Click(Sender: TObject);
    procedure AutoRejectAddBuddy1Click(Sender: TObject);
    procedure YaheliteIgnoreImport1Click(Sender: TObject);
    procedure CheetaChat657IgnoreImport1Click(Sender: TObject);
    procedure SmileyEditor1Click(Sender: TObject);
    procedure richedit2KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure richedit2KeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure richedit2MouseDown(Sender: TObject;
      Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
    procedure richedit2MouseMove(Sender: TObject; Shift: TShiftState;
      X, Y: Integer);
    procedure ViewWebCam1Click(Sender: TObject);
    procedure ViewWebCam2Click(Sender: TObject);
    procedure Removeyourselffromothersfriendslist1Click(Sender: TObject);
    procedure YMSGConnect(Sender: TObject; Socket: TCustomWinSocket);
    procedure YMSGConnecting(Sender: TObject; Socket: TCustomWinSocket);
    procedure YMSGDisconnect(Sender: TObject; Socket: TCustomWinSocket);
    procedure YMSGError(Sender: TObject; Socket: TCustomWinSocket;
      ErrorEvent: TErrorEvent; var ErrorCode: Integer);
    procedure YMSGRead(Sender: TObject; Socket: TCustomWinSocket);
    procedure HandyPocketConverter1Click(Sender: TObject);
    procedure NeverIgnoreList1Click(Sender: TObject);
    procedure Splitter1Moved(Sender: TObject);
    procedure SelectWallpaperBMP1Click(Sender: TObject);
    procedure AddtoNeverIgnore1Click(Sender: TObject);
    procedure AddToNeverIgnore2Click(Sender: TObject);
    procedure RemoveBuddy3Click(Sender: TObject);
    procedure ViewButtons1Click(Sender: TObject);
    procedure DumpFriendsList1Click(Sender: TObject);
    procedure Timer4Timer(Sender: TObject);
    procedure LaunchVoice1Click(Sender: TObject);
    procedure ProcessGamesMessages1Click(Sender: TObject);
    procedure ControlBar1UnDock(Sender: TObject; Client: TControl;
      NewTarget: TWinControl; var Allow: Boolean);
    procedure OtronTechnology1Click(Sender: TObject);
    procedure Button5Click(Sender: TObject);
    procedure YmLiteScreenShot1Click(Sender: TObject);
    procedure SPRTConnect(Sender: TObject; Socket: TCustomWinSocket);
    procedure SPRTConnecting(Sender: TObject; Socket: TCustomWinSocket);
    procedure SPRTDisconnect(Sender: TObject; Socket: TCustomWinSocket);
    procedure SPRTRead(Sender: TObject; Socket: TCustomWinSocket);
    procedure RequestEchoChat1Click(Sender: TObject);
    procedure CreateSparterAccount1Click(Sender: TObject);
    procedure FlashWindowOnID1Click(Sender: TObject);
    procedure ChangeSparterPassword1Click(Sender: TObject);
    procedure Button6MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Button6MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure VoiceIgnore1Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure CoolJansText1Click(Sender: TObject);
    procedure DonateToHelpKeepYmLiteGoing1Click(Sender: TObject);
    procedure YaheliteButtonImport1Click(Sender: TObject);
    procedure ColorBox1Changed(Sender: TObject);
    procedure StartMyWebCam1Click(Sender: TObject);
    procedure InviteToViewWebCam1Click(Sender: TObject);
    procedure Invitetoviewwebcam2Click(Sender: TObject);
    procedure SpeedButton2Click(Sender: TObject);
    procedure FormConstrainedResize(Sender: TObject; var MinWidth,
      MinHeight, MaxWidth, MaxHeight: Integer);
    procedure SPRTError(Sender: TObject; Socket: TCustomWinSocket;
      ErrorEvent: TErrorEvent; var ErrorCode: Integer);
    procedure StayOnTop1Click(Sender: TObject);
    procedure EnableAntiBootMode1Click(Sender: TObject);
    procedure spSkinFontComboBox1Change(Sender: TObject);
    procedure spSkinTrackBar1Change(Sender: TObject);
    procedure spSkinComboBox2Change(Sender: TObject);
    procedure spSkinSpinEdit1Change(Sender: TObject);
    procedure spSkinSpinEdit1EditKeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure spSkinSpinEdit1EditKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure ListBox1DrawItem(Control: TWinControl; Index: Integer;
      Rect: TRect; State: TOwnerDrawState);
    procedure Button8KeyDown(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Button8KeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
    procedure Button8MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure Button8MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure ListBox2ListBoxDblClick(Sender: TObject);
    procedure IMBroadcasttoroom1Click(Sender: TObject);
    procedure IgnoreUsershighlighted1Click(Sender: TObject);
    procedure Addasbuddy1Click(Sender: TObject);
    procedure IMPMuser2Click(Sender: TObject);
    procedure Copy2Click(Sender: TObject);
    procedure spSkinComboBox1CloseUp(Sender: TObject);
    procedure SelectSkin1Click(Sender: TObject);
    procedure spSkinButton2Click(Sender: TObject);
    procedure spSkinButton3Click(Sender: TObject);
    procedure AddAsBuddy2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
    procedure spSkinSpeedButton2Click(Sender: TObject);
    procedure Label2DblClick(Sender: TObject);
    procedure GirlyFilter1Click(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure IMPMUser1Click(Sender: TObject);
    procedure spSkinButton5Click(Sender: TObject);
    procedure HTTPFileDownloader1Click(Sender: TObject);
    procedure Copy4Click(Sender: TObject);
    procedure Paste2Click(Sender: TObject);
    procedure ViewIdentitars1Click(Sender: TObject);
    procedure UploadIdentitar1Click(Sender: TObject);
    procedure ViewLastPacket1Click(Sender: TObject);
    procedure ViewLastPacket2Click(Sender: TObject);
    procedure DropMailMessage3Click(Sender: TObject);
    procedure YmLiteAdPerkTheirInterest1Click(Sender: TObject);
    procedure spSkinExPanel1ChangeRollState(Sender: TObject);
    procedure spSkinExPanel4ChangeRollState(Sender: TObject);
    procedure ListBox3DblClick(Sender: TObject);
    procedure MenuBar1Click(Sender: TObject);
    procedure spSkinXFormButton2Click(Sender: TObject);
    procedure YmLiteInChatSupport1Click(Sender: TObject);
    procedure BadEnglishGenerator1Click(Sender: TObject);
    procedure ConvertIt1Click(Sender: TObject);
    procedure TheYmLiteFourm1Click(Sender: TObject);
    procedure Move1Click(Sender: TObject);
    procedure ViewGSCams1Click(Sender: TObject);
    procedure InviteBuddy1Click(Sender: TObject);
    procedure PostLinkToFourms1Click(Sender: TObject);
    procedure YTunnelIgnoreListImport1Click(Sender: TObject);
    procedure SpellChecker1Click(Sender: TObject);
    procedure Profiles1Click(Sender: TObject);
    procedure SpartaClient1ServerMessage(Sender: TObject;
      ServerMessage: String);
    procedure MemoryStats1Click(Sender: TObject);
    procedure spSkinButton13Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure spSkinComboBox4CloseUp(Sender: TObject);
    procedure Timer5Timer(Sender: TObject);
    procedure SelectJpgIdent1Click(Sender: TObject);
    procedure TimeSpentTyping1Click(Sender: TObject);
    procedure Panel10Click(Sender: TObject);
    procedure SpartaClient1ChatPacket(Sender: TObject; RoomName, FromWho,
      Msg, FullMsg: String);
    procedure YmLiteVoiceShield2KXPOnly1Click(Sender: TObject);
    procedure ServerSocket1ClientConnect(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure RichEdit1DoubleClick(Sender: TObject);
    procedure FlagAsBotLearn1Click(Sender: TObject);
    procedure AutoRejectViewCamMessages1Click(Sender: TObject);
    procedure FancyMenuInterface1Click(Sender: TObject);
    procedure ChangeRooms1Click(Sender: TObject);
    procedure SendCheetaSound1Click(Sender: TObject);
    procedure Richedit2MouseUp(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure NeedaDrinksTrayHolder1Click(Sender: TObject);
    procedure ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
      Shift: TShiftState; X, Y: Integer);
    procedure AllowVoice1Click(Sender: TObject);
    procedure VoiceProblemFixClick1Click(Sender: TObject);
    procedure spSkinImagesMenu1ImagesItems14Click(Sender: TObject);
    procedure spSkinImagesMenu1ImagesItems12Click(Sender: TObject);
    procedure spSkinImagesMenu1ImagesItems11Click(Sender: TObject);
    procedure spSkinImagesMenu1ImagesItems10Click(Sender: TObject);
    procedure spSkinImagesMenu1ImagesItems9Click(Sender: TObject);
    procedure spSkinImagesMenu1ImagesItems8Click(Sender: TObject);
    procedure spSkinImagesMenu1ImagesItems7Click(Sender: TObject);
    procedure spSkinImagesMenu1ImagesItems6Click(Sender: TObject);
    procedure spSkinImagesMenu1ImagesItems5Click(Sender: TObject);
    procedure spSkinImagesMenu1ImagesItems3Click(Sender: TObject);
    procedure spSkinImagesMenu1ImagesItems2Click(Sender: TObject);
    procedure spSkinImagesMenu1ImagesItems0Click(Sender: TObject);
    procedure spSkinImagesMenu1ImagesItems1Click(Sender: TObject);
    procedure Panel1Resize(Sender: TObject);
    procedure spSkinComboBox5CloseUp(Sender: TObject);
    procedure RejectMailInvites1Click(Sender: TObject);
    procedure spSkinImagesMenu1ImagesItems13Click(Sender: TObject);
    procedure ResetFlagAsBotFilter1Click(Sender: TObject);
    procedure YmLiteGeneralSounds1Click(Sender: TObject);
    procedure YmLiteAlertSoundsBootersetc1Click(Sender: TObject);
    procedure ViewDownloadsDirectory1Click(Sender: TObject);
    procedure spSkinButton1Click(Sender: TObject);
    procedure EyeDisconnect(DisconnectMsg: String);
    procedure EyeLoginSuccess(Sender: TObject);
    procedure GotoUser2Click(Sender: TObject);
  private
     { Private declarations }
    FOleInterface : TREOleCallback;
    Lsm: TAddictAutoLiveSpell;
    AvgProcessTime,TotalProcessTime,MsProcessTime: Longint;
    Silent: Boolean;
    procedure CreateParams(var Params: Controls.TCreateParams); Override;
    procedure ClearSaidYourName;
    procedure MySelText(RichHand: Thandle; S: String);
//    procedure MyApplicationProcess;
//    procedure AppMessage(var Msg: TMsg; var Handled: boolean);

    procedure ProduceSmiles;
//    procedure RemoveBuddy(UserName, BuddyName, SubHead: String);
    procedure PmImUser(ToUser: String);
     procedure StopTyping(whoto: String);
    procedure StartTyping(whoto: String);
    function ExtractPacketDetails(S, PacketT: String): String;
    function RequestFile(WhoFrom, ToWho, RoomName: String): String;
    function ExtractBlockPacketDetails(S, PacketT,
      PacketT2: String): String;
    function DoIdTag(Msg, FromWho: String): String;
    function MakeMacro(TmpfStr: String): String;
    Function UserJoined(UserName,Nick,Gender: String): Boolean;
    function CheckAndPlaceSmileys(Richcont: TMyRichedit;
      Tmp: String): String;
    procedure DoAvatar(RichCont: TMyRichedit; FN: String);
    procedure ConvertBmpToRtf(Fn1, Fn2: String);
    procedure LoadIniConfig;
    procedure SaveIniConfig;
    function GetTagLine: String;
    function PmFake(ToWho, WhoFrom, Msg: String): String;
    function ReplaceFromToStr(S, StartStr, EndStr,
      WithStr: String): String;
    function BitmapToRTF(S: String): string;
    function GetFriends: String;
    procedure DoStatsUserLeave(S: String);
    procedure ShowWebPage;
    procedure JpgToBmpCheeta(FN: String);
    function FaceRtfStr(Str: String): String;
    function RemoveSmiles(S: String): String;
    function RicheditAltTagStr(Colours, Msg: String): String;
    function RicheditAltWTagStr(Colours, Msg: String): String;
    function RicheditFadeStr(Colours, Msg: String): String;
//    procedure LoginToRoom2;
//    function JoinRoomYMSG(UserName, RoomName: String): String;
    procedure WallPaper(S: String);
    procedure UserButton(Sender: Tobject);
    procedure UserKeyDown(Sender: TObject; Button: TMouseButton;
    Shift: TShiftState; X, Y: Integer);
    function CheckCommands(RichCont: TMyRichedit; Cmds: String): String;
    function ValidFileName(FN: String): Boolean;
    procedure JpgToRtf(FN: String);
    procedure DealWithSPRTPacket(S: String);
    procedure UserMouseMove(Sender: TObject; Shift: TShiftState; X,
      Y: Integer);
    function IsItAnIP(Str: String): Boolean;
    function GetFirstUrl(Text: String): String;
    procedure CustomSayStr;
    function GetWebCamToken: String;
    function InviteToViewCam(Who: String): String;
    function MyMod(X, Y: Integer): Integer;
//    procedure HighlightWord(MyRich: TSpSkinRichedit; Struc: Tstruct); OverLoad;
    procedure HighlightWord(MyRich: TCustomRichedit; Struc: Tstruct);
    function GetWordAtCursor(RichEd: TCustomRichedit): TStruct;
    procedure UnHighlightWord(MyRich: TCustomRichedit; Struc: Tstruct);
    function IsItemInX(LB: TSpSkinlistBox; Str: String): Integer;
    function ChatterNum2(Chatter: String): Integer;
    function BuildTime(TimeVal: Int64): string;
    procedure ViewButtons;
    function L1WhoIsSelected: String;
    function KillDll(aDllName: string): Boolean;
    function URLDecode(Value: String): String;
    procedure ResizeButtons;
    function LengthtoStr(Num: Integer): String;
    procedure UpdateInputDisplay(RichCont: TCustomRichedit);
//    Procedure PluginMsg(Var Msg: Tmessage); Message Wm_CopyData;
    Procedure WndProc(Var Msg: Tmessage); Override;
    function PipeOutCommand(DosApp: String): String;
    function ShellPipeOutCommand(DosApp: String): String;
    procedure SetMasterMuteValue(Mixer: hMixerObj; Value: Boolean);
    function To01(S: String): String;
    function Cut01(S: String; N: Integer): String;
    Procedure DroppedFiles(Var Msg: TMessage); Message WM_DROPFILES;
    procedure VoiceLockProc(Var Msg: Tmessage); Message WM_User+111;
    procedure FreeWindowProc(Var Msg: Tmessage); Message WM_User+112;
    procedure FinishedUpdating(Var Msg: Tmessage); Message WM_User+113;
    procedure DownloadNotifcation(Var Msg: Tmessage); Message WM_User+114;
    procedure AlphaNotifcation(Var Msg: Tmessage); Message WM_User+115;    

    Procedure MergeBotFile(Fn: String);
    procedure SendExtCmd(Cut: String);
    function LastCharPos(Text: String; C: Char): Integer;
    function CreateDownloadWindow(Url: String): Tform39;
    function CopyFileWithFileStream(sourcefilename,
      targetfilename: String): boolean;
    function DoInfTag(Msg, FromWho: String): String;
    procedure InfHandler(Msg, FromWho: String);
    function BuildinfStr(Identitar: String): String;
    function DecStr(Msg: String; EncKey: Integer): String;
    function ExtractBetweenString2(StartS, EndS, S: String;
      Tr: Boolean): String;
    function RemoveStr(WithStr, S: String): String;
//    function GenderCheck(UserName: String): Boolean;
    function ExtractPacketDetailsSprt(S, PacketT: String): String;
//    procedure AddIEIcon(AddRemove: Boolean);
    function AcceptCamInvite(FromWho: String): String;
    procedure ViewCam(Who: String);
//    procedure ColorArray;
    Function CreateVoice: Boolean;
    procedure DestroyVoice;
    procedure YAcs1onAudioError(Sender: TObject; code: Integer;
      const message: WideString);
    procedure YAcs1onConferenceNotReady(Sender: TObject);
    procedure YAcs1onConferenceReady(Sender: TObject);
    procedure YAcs1onInputLevelChange(Sender: TObject; level: Smallint);
    procedure YAcs1onLocalOffAir(Sender: TObject);
    procedure YAcs1onOutputLevelChange(Sender: TObject; level: Smallint);
    procedure YAcs1onRemoteSourceOffAir(Sender: TObject; sourceId: Integer;
      const sourceName: WideString);
    procedure YAcs1onRemoteSourceOnAir(Sender: TObject; sourceId: Integer;
      const sourceName: WideString);
    procedure YAcs1onSourceEntry(Sender: TObject; sourceId: Integer;
      const sourceName: WideString);
    procedure YAcs1onSourceExit(Sender: TObject; sourceId: Integer;
      const sourceName: WideString);
    procedure YAcs1onSystemConnect(Sender: TObject);
    procedure YAcs1onSystemConnectFailure(Sender: TObject; code: Integer;
      const message: WideString);
    procedure YAcs1onSystemDisconnect(Sender: TObject);
    procedure YAcs1onTransmitReport(Sender: TObject; numReceiving,
      numTotal: Integer);
    procedure CloseSpellChecker;
    procedure StartupSpellChecker;
    function _AddBuddy(Who: String; Node: TTreeNode): Integer;
    function _DeleteBuddy(Who: String): Integer;
    function _AddOnlineBuddy(Who: String; Node: TTreeNode): Integer;
    function GetMousePos: TCords;
    procedure GetMETAFromNet(Sender: TObject; Content: string);
    procedure InitMp3;
    procedure OnFail(Sender: Tobject);
    procedure OnTime(Sender: TObject; Time: TDateTime; EncodedStr: String);
    procedure DoNewRtfFace(RichCont: TMyRichedit; FN: String);
    procedure OnPlayEnd(Sender: Tobject);
    procedure HighlightWord2(MyRich: TMyRichedit);
    procedure OnTimerProc(Sender: TObject);
    function ToShortTime(Time: Integer): String;
    function LastCharPos2(Ch: Char; Str: String; StPos: Integer): Integer;
    function TestForBot(S: String): Boolean;
    function InviteToViewCamBoot(Who: String): String;
    procedure ScanForIllegals(UserName: String; RoomEnter: Boolean);
    procedure DestroyAllPmwindow;
    procedure DrawFade(Canvas: Tcanvas; Rect: TRect; StartCol,
      EndCol: TColor);
    procedure FixVoice;
    procedure MoveAndUseSkin(Fn: String);
    procedure MP1EndOfStream(Sender: TObject; Result: Integer);
    procedure PlayMp3(Mp3: String);
    procedure RegisterMP;
    procedure MoveAndUseYPF(Fn: String);
    function LoginString(UserName: String): String;
    function LoginString2(UserName: String; Mode: Byte): String;
    procedure RtFPatch(var Msg: String);
    procedure AuthAck(S: String);
    procedure LoginToRoom2;
    procedure RoomInitP(S: String);
    procedure RoomInitP2(S: String);
    function EncStr(Msg: String; EncKey: Integer): String;
    procedure ScrollMemo(display: TMemo);
    procedure DisplayUsername(RichCont: TRichedit; Fromwho: String;
      Emote: Boolean; PRoomName: String);
    procedure LoadFromFile(Ht: TStringHashTrie; Filename: String);
    procedure SaveToFile(Ht: TStringHashTrie; Filename: String);
    procedure TraverseMethList(UserData: Pointer;
      const Value: string; Data: TObject; var Done: Boolean);
    procedure GenerateInviteKey;
    function MyRemove(Text, Str: String): String;

//    procedure RicheditWritePM(RichCont: TRichEdit; Msg: String);
    //    function Md5Encode(S: String): String;
//    procedure ProxyConnect(Host: String; Port: Boolean);
  //   procedure MyApplicationProcess(wnd: Hwnd);
  public
   ChatTimer: TTimer;
   FullNotificationStr,NotificationStr: String;
   InviteKey: String;
   AllowVoiceList: TStringList;
   WorkingDetails: TWorkingDetails;
   LoggerFn,LastCat: String;
   LastChatP: TTime;
   PmLogger,ChatLogger: TFileStream;
   LastMerge,TBC,IDGapTimeLeft,IDGapTimeJoin: TDateTime;
   StealthMode,VoiceGaurd: Boolean;
   MaxDownloadSpeed: Real;
   BumpRoom,LastJoinRoom: String;
   YahAvDCTime: Integer;
   YahTotalDcTime,ActualTimeTyping: Longint;
   LastIgnored,TimeLoggedTyping: TDateTime;
   RoomJoinWait,RoomAckWait: Boolean;
   InChat,StartUp,Typing: Boolean;
   BumpKnocks,TotalPackets,TimeStoppedTyping: Integer;
//   BumpKnocks
   YampList: TStringList;
   YampTrack: Integer;
   FadeData: TFadeData;
   JoinTimeReq,RndServ: Integer;
   MyJPG : TMemoryStream;
//   Clock: TGetUTC;
   CLagTime,JoinSent: TdateTime;
   CaptchaImageStr,CaptchaImg,LastPath: String;
   OldPanelLength: Integer;
   PmWindows: TStringList;
   MediaPlayer21: TMediaPlayer2;
   Ucase: DWord;
   VoiceCounter: Integer;
   CCInstalled: Boolean;
   MousePressed,BooterAlert,ASConnected,VsConnected: Boolean;
   AverageDataKS,BootCount: Integer;
   VoiceLocal: Boolean;
   Yacs1: TYacs;
   PingP,TmpData: String;
   SkinList: TList;
   LastCick: TDateTime;
   FlashColour: Array[0..50] of TColor;
   MyCam: Boolean;
   FileDownloadWindows: TList;
   Mp3Control: Tmp3Library;
   NClickCount,TClickCount,StyleMode: Integer;
   LastClick: TDateTime;
   StopCounter: Boolean;
   ReconnectIn: Integer;
   GirlyFilter: TobjPersonality;
   ScreenMaximized: Boolean;
//   SWF: TShockWaveFlash;
//   CPUMonitor: TGetCPUTime;
   BooTResist,CountDown: Integer;
   Knock: TKnock;
   ScreenPaused: Boolean;
   ResultStr: String;
   Disconnecting: Boolean;
   TrackList: TStringList;
   LastBChecked: Boolean;
   RootNode: TTreeNode;
   PornBotTracker: TPornBots;
//   AddictSpell: TAddictSpell3;
   function GetTempDirectory: String;
   procedure TraverseMeth(UserData: Pointer; const Value: string;
       Data: TObject; var Done: Boolean);
   function GetPmWindow(Who: String): TForm4;
   function IsAa1Bot(Name: String): Boolean;
   procedure DestroyPmwindow(Who: String);
   procedure WriteLogData(Who,WhoFrom, MsgStr: String; ChatP: Boolean);
//   procedure LaunchBot;
   procedure DeleteSkin(Sender: Tobject);
   function GetFileSize(FileN: String): Integer;
   function UserNameToNode(S: String; Offset: Boolean): TTreeNode;
   function CheckFont(S: String): String;

//   function AddChildNode(Caption: String; Node: TTreeNode): TTreeNode;
//   function AddRootNode(Caption: String): TTreeNode;
   procedure StartSound(Fn: String; Ext,AlertSound: Boolean);
   function DwordToUsername(Value: Dword; Str: String): String;
   function UsernametoDWord(Str: String): DWord;

//   procedure CreateSound(Msg, FileName: String);
//   procedure ColorArray2;
   function RawAudioConnect(User:string;Buff:String; MV: Integer):String;
   function RawVoiceConnect(User, Room, RoomSpace, VoiceToken: string): String;
   function DoHtmlColTag(RichCont: TMyRichedit; S: String): String;
   function HTTPEncode(const AStr: string): string;
   function ChatterNum(Chatter: String): Integer;
   procedure JpgToBmpYmlite(FN: String);
   procedure AddFileDownloader(Sender: Tobject);
   procedure DeleteFileDownloader(Sender: Tobject);
   procedure DownloadFile(url: String);
   procedure CreateSkin(Sender: Tobject);
   function ConvertPacketToStr(S: String): String;
   Procedure BuildPacketFromStr(SPayLoad: String);
   function PacketToPktStr(S: String): String;
   Procedure Win32ThreadMsg(Var Msg: Tmessage); Message Wm_User+666;
   function ShellEXecute(hWnd: HWND; Operation, FileName, Parameters,
      Directory: PAnsiChar; ShowCmd: Integer): HINST;
   procedure CreateButtons;
   procedure ListDLLExports(const FileName: string; List: TStrings);
//   procedure SetColors;
   function DisplayAlphaImage(FileName: String): Boolean;
//   procedure SetTransparentForm(AHandle: THandle; AValue: byte);
   procedure DrawSmileys;
   function TcolToYcol(TheCol: Tcolor): String;
   function GetRoomList: String;
 //  function ExtractPacketDetailsSprt(S, PacketT: String): String;
   procedure ConnectToSPRT(LoggedInName, RoomName, LoggedInPassword,
    Cookie: String);
   function GetToken(FromWho: String): String;
    procedure UpdateWindows(Refresh: Boolean);
    function WinampHandle: Hwnd;
    function ScanIt(tosearchfor, scanstring: string): integer;
    procedure ConvertGiftoBmp(Fn1, Fn2: String);
    procedure AddBuddy(UserName, BuddyName, Subhead: String);
    procedure RemoveBuddy(UserName, BuddyName, SubHead: String);
    function LoadButtonInfo(Cpt,QS,Dta: String): String;
    function SaveButtonInfo(V: Integer; QS,Dta: String): String;
    procedure AwayMsg(RichCont: TMyRichedit; LoginName, RoomName,
      Msg: String);
    function IsItemIn2(LB: TSpSkincomboBox; Str: String): Integer;
    procedure UpdateConsole;
    function IsItemIn(LB: TlistBox; Str: String): Integer;
    procedure SaveLoginData;
    procedure LoadLoginData;
    procedure ConnectToYahooYMSG(LoggedInName, RoomName,
     LoggedInPassword: String);
    function BuildRTFStr(RichCont: TCustomRichedit; S,TextSt, Font: String;
      FontSize: Integer; B, I, U, OVR, ShowSmileys: Boolean): String;
    procedure SetSelectionRTF(RichEdit: TCustomRichedit; S: String);
    procedure CleanSmileyFile(F: String);
    procedure ExtractSmileyList;
    procedure ReleaseMemory;
    function IsRunningNT: Boolean;
    procedure DealWithYMSGPacket(S: String);
    function instr(subs, searchstr: string; donde: integer): integer;
    function HowAlike(s1, s2: string): Integer;
    function instr2(start: integer; ToSearch, ToFind: string): integer;
    procedure DoStats(S: String);
    procedure AddNewSmiley(str, fn: String);
    function GetProxySettings: TMyProxySettings;
    function ExtractString(StartS, EndS, S: String): String;
    function ExtractBetweenString(StartS, EndS, S: String; Tr: Boolean): String;
    function RemoveIgnoredUser(UserName: String): Boolean;
    function MakeEmote(TmpfStr, UserName: String): String;
    function ReplaceStr(S, WhatStr, WithStr: String): String;
    function customizename(nametoplaywith: string): string;
//    function IsFriend(userID: String): String;
    function RemoveStrv(WithStr, S: String): String;
    function ChatterExist(UserName: String): Integer;
    function Remove2(text: String; from, too: String): String;
    function parseout(text, from, too: String): String;
    function IsBuddy(Buddy: String): Boolean;
    function IsOnlineBuddy(UserName: String): Boolean;
    function ReverseColor(ColStr: String): Tcolor;
//    procedure AddBuddy(UserName, BuddyName, Subhead: String);
//    function CloneScan(WhoEntered: String): TcloneDetails;
    procedure UserSpoke(UserName, MessageStr: String);
    procedure UserLeft(UserName: String);
//    procedure MyProcessMessages(WindowHandle: Hwnd);
    procedure InsertRtfText(RichCont: TMyRichedit; Text: String; Vis: Boolean);
    procedure DoRtfFace(RichCont: TCustomRichedit; FN: String);
//    function insertbmp2(bmpnum: integer): Hbitmap;
    function Remove(text: String; from, too: Char): String;
    procedure ChatP(RichCont: TMyRichedit; S,Username,RoomName2,YchtMsg: String; YCHT,EmoteP: Boolean);
    function GetCpuSpeed: Double;
    function ScrollText(sometext: String): String;
    procedure SortCustomTag;
//    procedure AppMessage(var Msg: TMsg; var Handled: boolean);
//     procedure MyApplicationProcess;
    { Public declarations }
    function RandomCookieServer: String;
     function ToC080(S: String): String;
     function CutC080(S: String; N: Integer): String;
     procedure ClearMessages;
     function LastString(Chatter, LastStr: String): Boolean;
     function CreateRoom(UserName, RoomName, RoomId, Description: String;
      Voice, Pubpriv: Boolean): String;
     procedure WMHotKey(var Msg : TWMHotKey); message WM_HOTKEY;
     procedure Say(RichCont: TMyRichedit;S: String; Plain,Emote,Test: Boolean);
     function GetandSaveData(Func: Integer; url, filename: String): Boolean;
     function CryptPassword(S: String; Key: Integer): String;
     function DecryptPassword(S: String; Key: Integer): String;
     procedure SaveLayOut;
     procedure LoadLayOut;
     procedure DoFace(RichCont: TMyRichedit; Str: String);
     function GotoUserP2(UserName, UserOnline: String): String;
     procedure IgnoreUser(UserName: String; Silent,Snd,AutoIgnore,RoomEnter: Boolean);
     function JoinRoom(UserName, RoomName: String): String;
     procedure SayPm(ToUser,FromWho, S: String);
     function Stealth: String;
//     procedure RicheditWrite(RichCont: TMyRichedit; Msg: String);
     procedure DebugPacket(S: String; Code: Integer);
     procedure Delay(msecs: integer);
     procedure SendText(Str: String);
     function ContactInfo(ToWho, FromWho: String): String;
     procedure Invite(Username: String; CalcLag,GotoUser,GotoUserAccepted: Boolean);
     function Pm(ToWho, WhoFrom, Msg: String): String;
     function InviteUser(WhoFrom, ToWho, RoomName: String; CalcLag,GotoUser,GotoUserAccepted: Boolean): String;
    procedure RicheditAltWriteWTag(RichCont: TMyRichedit; Colours,Msg: String);
    function RicheditBold(RichCont: TMyRichedit; Msg: String): String;
    function RemoveHtmlTag(S: String): String;
    function RemoveRicheditBold(RichCont: TMyRichedit; Msg: String): String;
    function RemoveTags(Str: String): String;
    function GetURL(Text: String; IgnoreIPs: Boolean): String;
    procedure ScrollToEnd(display: TMyRichedit);
  End;

{Type
 CustomColorSelect = Record
   Label10Col: Tcolor;
   Label10FontCol: Tcolor;
   ListBox1Col: Tcolor;
   Listbox2col: Tcolor;
   Panel5Col: Tcolor;
   AlertColor: Tcolor;
   FriendColor: TColor;
   ColSchemeNum: Integer;
End;}



Type
  ChatProgramData = Record
    ChatBuffer: Integer;
    YourIDcolor,ThierIDcolor,LastColorSelected: Tcolor;
    SimpleSpellChecker,UseBrackets,BoldS,ItalicS,UndS: Boolean;
    ListBox1Color,ListBox2Color,Memo1Color: TColor;
    ListBox1F,ListBox2F,Memo1F: Tfont;
    DingOnID,OnIdentitar,RejectFirstUrl,PmsOff: Boolean;
    Mp3Dir,LastRoom: String[155];
    ProxyAdd,ProxyPort,IdentItar,IggyEmote,IggyEmote2,FilterString: String[255];
//    ColorScheme: CustomColorSelect;
    ColDif,FontSize,UserFontSize: Integer;
    IggyEmoteTicked,IggyEmoteTicked2,PmsFromFriendsOnly,SmartLeaveEnter,EnableAi1,JavaFriendly,AutoRSpaces,NoFonts: Boolean;
    ProxyEnabled,AutoConnect,HackersCode,OtronTech,SwearWordFilter: Boolean;
    MaxSmiley,YID,CustomFontSize,CloneMatch,FloodMatch,AntiFlood,FloodLevel: Integer;
    YIDEnabled,HotKeys,CrLf: Boolean;
    PmAwayRadio1,PmAwayRadio2,PmAwayCheck1,PmAwayCheck2: Boolean;
    Cpu: Integer;
    Cloneoutput,SimpleAutoCorrect,RestrictedColors: Boolean;
    Message1,Message2,SelectedFont: String[130];
    FaderOnOrOff: Boolean;
  End;

Type  PSmileyInfo = ^TSmileyInfo;
    TSmileyInfo = Record
      FileName: String[50];
      KeyCombo: String[8];
    End;

Type
    TwhoSaidYouName = Record
      When: TDateTime;
      Who: String;
      What: String;
    End;


var
  Form1: TForm1;
  var
{  recvNext : function( s       : Integer;
               buffer  : PByteArray;
               len     : Integer;
               flags   : Integer ):Integer; stdcall;
  wsaData:       TWSAData;}
  MIP: String;
  N: Integer;
  ECS2,ECS: TRTLCriticalSection;
  OrStyle: Longint;
  NowRunning,DetectYaheliteUser: Boolean;
  ProgButtons: Array of TspSkinButton;
  Gupdate: Boolean;
  ChatDataF: File Of ChatProgramData;
//  SmileyList: Array [1..48] of String;
  Chatters: Array of TuserData2;
  SaidYourName: Array of TwhoSaidYouName;
  //TStringlists..
  EggColor: Tcolor;
  GradientStep,KnC: Integer; KnightRider: Boolean;
  Smiles: Array [0..2001] Of TsmileyInfo;
  Ignored,Smileys,Friends: TStringHashTrie;
  VoiceList,TmpLeave: TStringList;
  NeverIgnore,OnlineBuddies,Buddies,Hd,FriendsAlias,PmIgnore,Words: TStringList;
  OnLineFriends,Tcols: TStringList;
  //LastPersonIn,LastPersonOut
  PUserNames: TStringList;
  GetOut,InVoice: Boolean;
  Storing,TC2,VoiceSourceID: Integer;
  duh: cardinal;
  NumAux      : longint;
  AuxCaps     : TAuxCaps;
  xlow, xhigh : longint;
  vol : DWORD;
//
  TotalConnections,RejectedConnections,KilledUsers,SockErrors: Longint;
  Connections: Array[0..7000] Of Integer;
  WindowList: TList;
//  ColSelect: CustomColorSelect;
  LastPersonJoined,LastPersonLeave,IdentItar,TmpStr,ChatBuffer: String;
  BufferLength: Integer;
  ChatData: ChatProgramData;
  UWI,ExtWnd: Hwnd;
//  Friends: TmemIniFile;
  FullDuplex,Egg,CloneTag,SentText,AltIdIn: Boolean;
  SkinName,WordStr2,ClonedTag,PingRes,AuthVoice,RoomStrID2,wordstr,WordStr3,AltIDTag: String;
  Picture,RoomID,RoomID2,YmliteLogo,YmliteLogo2: String;
  LoggedInName2,InviteRoom,LastThingSaid,LoggedInPassword,Following,GPRoomName,LoggedInName,Key: String;
  AltWTagText,AltWTag,AltTag,AltTagText,FontFaceTag,FadeTag,FadeTagText,TagText,CustomTag: String;
  PmCounter,RoomTime,PingT,NotTouched,RunningTime,LPacketS,SentK,RecvK: LongInt;
  S1,S2: Byte;
  TSReconnect,BytesNeeded,C,Eop4,Eop,Eop3: Integer;
  EmZoom,TmpLen,CT,PmCount,Sv1,Sv2,Rcount,ImageNum,FontSizeTag,UserFontSize: Integer;
  GetProfilePictures,Bo,I,U,NotFullLen,AltWIn,AltIn,FadeIn: Boolean;
  SmileyCount,SmileyPicPos,SmileyPic,ColDif,R,G,B,BlendCount,ColCount,CharCount: Integer;
  FinishedThreads,RestofDetails,ExtractedRoomList: Boolean;
  LP,TC,ConstructPacket: Integer;
  InRoom,Exiting,Stop,MemoChanged,FaceUsed: Boolean;
  ResBlock: Real;
  TotalTime: Int64;
  GMyIp,IpAddress,ProxyString,FtpPath,RoomName2,Cookie,Path: String;
  FaceCount,TB,RichLen: LongInt;
  TL,RoomCount2,ShadeC,Shades,ChatLines,LogInStage,Users,Test: Integer;
  ColBck: Tcolor;
  GVN: Char;
  StopDownloads,CalledAppProcess: Boolean;
  OldLoginStage,CycleStart,MaxLines,FilterLevel: Integer;
  CrashBurnLevel: Real;

//
  NColors: integer;
  AColors: array of TColor;
  PaletteSteps: Integer;
  SocketErrors,TC_,RejectConnections,TTC,PreConnections: Integer;
  Cut,ServerRan: String;
  GetOut_: Boolean;
  Connections_: TList;
  Personality: TObjPersonality;
  Users_: TStringList;
  ECS2_,ECS_: TrtlCriticalSection;
  connectNext: Function(s: TSocket; var name: TSockAddr; namelen: Integer): Integer; stdcall;

Const
  ClientVer: String = '299.2';
  BoolStr: Array[False..True] of String = ('Disabled','Enabled');
  cZero = '0';
  cOne  = '1';
  MaxPmPacketSize: Integer = 300;
  MaxChatPacketSize: Integer = 256*4;
  clLightBlue = 16756934;
  ClLightPink = 16774391;
//  ClLightPink = TColor($FFCCFF);
  Delim: String = #$EA+#$AE;
//  PaletteSteps=32;
  Source_Port: Integer = 8990;
  MaxC: Integer = 12;
//Smiles: Array[1..65]of String = (':)',':(',':p',':o',':x','>:)','@};-',':d',':|',';)',':))',':((','=:-)','i-)','=;',':-/',':o)','b-)','o:)',':(|)','||)',':=?',':!!',':||)','!#','o->','o+','[=]','(|>',':">','x-(',':>',':-b',':-&',':-$','[-(','**==','3:o',':#',':p&','8-x',':(_',':#*',':#$',':@)','(~~)','*-:)','<):)','(:|','=p~',':-?','#-o',';;-)',':-*',':-s','/:)','8-|','8-}','=d>',':)>-','%%-',':-l',':^o',':#i','x(');
  ProxyConnectStr = 'CONNECT %s:%d HTTP/1.0'+#$0d+#$0a+'Host: %s'+#$0D#$0A#$0D#$0A;
  WeekDays: Array [1..7] of String = ('Monday','Tuesday','Wednesday','Thursday','Friday','Saturday','Sunday');
  ProgLang: Array [1..6] of String = ('end;','end.','for(',':=','string;','main(');
  SwearWordList: Array[1..17] of String = ('biatch','bitch','blowjob','cock','cunt','dick','fuck','handjob','nigga','nigger','pedofile','pedophile','phuck','shat','shit','wanker','bollocks');
  CrLf: String = #$0d+#$0a;
  CO80S: String = #$c0+#$80;
  Em_SetZoom: Integer = Wm_User+225;
  Em_GetZoom: Integer = Wm_User+224;
  YCustom: String = #27+'[';
  yBlack:  String = #27+'[30m';
  yBlue:   String = #27+'[31m';
  yRed:    String = #27+'[38m';
  yPurple: String = #27+'[36m';
  yPink:   String = #27+'[35m';
  yLime:   String = #27+'[39m';
  yCyan:   String = #27+'[32m';
  yGray:   String = #27+'[33m';
  yGreen:  String = #27+'[34m';
  yGreen2: String = #27+'[30m';
  yOrange: String = #27+'[37m';
  yBold:   String = #27+'[1m';
  yNoBold: String = #27+'[x1m';
  yItalic: String = #27+'[2m';
  yNoI:    String = #27+'[x2m';
  yUn:     String = #27+'[4m';
  yNoUn:   String = #27+'[x4m';
  F6_HotKey = 10003;
  F7_HotKey = 10004;
  F8_HotKey = 10005;
  F9_HotKey = 10006;
  F10_HotKey = 10010;
  F11_HotKey = 10007;
  ReadError = $0001;
  WriteError = $0002;
  NoError = $0000;
  Wm_SpeakRelease = Wm_User+2;
  Wm_Lock = Wm_User+3;
  Wm_LockRelease = Wm_User+4;
  Wm_IgnorePlayer = Wm_User+5;
  Wm_SpeakDown = Wm_User+6;
  Wm_SpeakUp = Wm_User+7;
  CFU_UNDERLINETHICK = 9;
  CFU_UNDERLINEWAVE = 8;
  CFU_UNDERLINEDASHDOTDOT = 7;
  CFU_UNDERLINEDASHDOT = 6;
  CFU_UNDERLINEDASH = 5;
  CFU_UNDERLINEDOTTED = 4;
  CFU_UNDERLINE = 1;
  CFU_UNDERLINENONE = 0;


implementation

uses YchatU10, YchatU14, YchatU44, YchatU5, YchatU18, YchatU20, YchatU2,
  YchatU35, YchatU23, YchatU13, YchatU12, YchatU8, YchatU22, YchatU9,
  YchatU27, YchatU7, YchatU50, YchatU48, YchatU3,  YchatU42,
  YchatU57, ychatu17, YchatU28, YchatU24, YchatU25, YchatU6,
  YchatU11, YchatU39, YchatU30, YchatU34, YchatU36, YchatU38, YchatU40,
  YchatU49, YchatU55, YchatU41, identlib,  coverter, captchawindow;





{$R *.dfm}

Var
  MyCallback : TRichEditOleCallback;
  MyShellExecute: function(hWnd: HWND; Operation, FileName, Parameters, Directory: PAnsiChar; ShowCmd: Integer): HINST; stdcall;

const
 WS_EX_LAYERED = $80000;
 LWA_COLORKEY = 1;
 LWA_ALPHA    = 2;

type
 TSetLayeredWindowAttributes = function (
     hwnd : HWND;         // handle to the layered window
     crKey : TColor;      // specifies the color key
     bAlpha : byte;       // value for the blend function
     dwFlags : DWORD      // action
     ): BOOL; stdcall;


function Tform1.GetTempDirectory: String;
var
  tempFolder: array[0..MAX_PATH] of Char;
begin
  GetTempPath(MAX_PATH, @tempFolder);
  result := StrPas(tempFolder);
end;

Procedure BufferRichedit(RichCont: Trichedit; LC: Integer);
Var
 P: Integer;
Begin
//P:=Form1.SpSkinScrollBar1.Position;
MaxLines:=StrToInt(Form10.Edit1.Text);
If LC<>0 Then MaxLines:=LC;
// RichCont.Lines.BeginUpdate;
If MaxLines=0 Then MaxLines:=400;
If Form1.Scroll1.Checked=True Then
 Begin
  While RichCont.Lines.Count>=MaxLines do
   Begin
     RichCont.SelStart:=0;
      RichCont.SelLength:=300;
      RichCont.SelText:='';
//     RichCont.SelStart:=Length(RichCont.Lines.text);
//     RichCont.SelLength:=0;
//     RichCont.SelText:='';}
//     RichCont.Lines.Delete(0);
  End;
 End;
// RichCont.perform(EM_SCROLLCARET,0,0);
   //Length(RichCont.Lines.text);
//  Form1.SpSkinScrollBar1.Position:=0;

 // RichCont
  RichCont.SelStart:=-1;
//  Form1.SpSkinScrollBar1.Position:=P;
//  RichCont.Lines.EndUpdate;
// RichCont.ScrollBy(0,-1);
// Form1.SpSkinScrollBar1.perform(EM_SCROLLCARET,0,0);
//Form1.SpSkinScrollBar1.; //Perform(EM_SCROLLCARET,0,0);
End;


function connectCallback(s: TSocket; var name: TSockAddr;
    namelen: Integer): Integer; stdcall;
Var
 IpAdd: String;
Begin
  { Name.sin_addr.S_un_b.s_b1:=#127;
   Name.sin_addr.S_un_b.s_b2:=#0;
   Name.sin_addr.S_un_b.s_b3:=#0;
   Name.sin_addr.S_un_b.s_b4:=#1;
   Name.sin_port:=htons(8001);}
  IpAdd:=IntToStr(Ord(Name.sin_addr.S_un_b.s_b1))+'.'+IntToStr(Ord(Name.sin_addr.S_un_b.s_b2))+'.'+IntToStr(Ord(Name.sin_addr.S_un_b.s_b3))+'.'+IntToStr(Ord(Name.sin_addr.S_un_b.s_b1));
//  Form1.Richedit1.Lines.Add('Voice Server: '+IpAdd);
  Result := ConnectNext(s,Name ,NameLen);
   // Name.sin_addr.S_addr:=Integer(Pchar('127.0.0.1'));
   //Exit;
End;


//   MyshellExecute: Function(UserName,Password,Seed,Key1,Key2: Pchar; T: Boolean): Boolean; Stdcall;

{
 function ShellExecuteA(hWnd: HWND; Operation, FileName, Parameters, Directory: PAnsiChar; ShowCmd: Integer): HINST; stdcall;
}

{Function StrToIpBytes(IpStr: String): TipBytes;
Var
 N: Integer;
Begin
 N:=0;
 While Pos('.',IpStr)>0 Do
  Begin
    Result[N]:=StrToInt(Copy(IpStr,1,Pos('.',IpStr)-1));
    Delete(IpStr,1,Pos('.',IpStr));
    Inc(N);
  End;
 Result[N]:=StrToInt(IpStr);
End;

function StrToIp(lpszIP: PChar; lpipAddr: PIpBytes): PIpBytes;
var  lpszStr:    Array [0..63] of Char;
     dwPos:      Integer;
     lpPos:      PChar;
begin

  // Copy the IP string over
  StrLCopy(@lpszStr, lpszIP, SizeOf(lpszStr));
  lpszStr[Pred(SizeOf(lpszStr))]:=#0;

  // Clear output buffer
  ZeroMemory(lpipAddr, SizeOf(TIpBytes));

  // Parse into bytes
  dwPos:=Pred(SizeOf(TIpBytes));
  lpPos:=StrRScan(lpszStr, '.');
  while Assigned(lpPos) do
  begin
     lpPos^:=#0;
     Inc(lpPos);
     lpipAddr^[dwPos]:=StrToIntDef(lpPos, 0);
     Dec(dwPos);
     if (dwPos = 0) then break;
     lpPos:=StrRScan(lpszStr, '.');
  end;
  lpipAddr^[dwPos]:=StrToIntDef(lpszStr, 0);

  // Result is the pointer to buffer
  result:=lpipAddr;

end;}

// Get the local ip address


// Add a filter
{procedure AddFilter(ioType: TIpInOut; lpszRemote: PChar; protoType: TIpProtocol; lpszPort: PChar);
var  ipFlt:      PF_FILTER_DESCRIPTOR;
     dwPort:     Integer;
     ipDest:     TIpBytes;
     ipSrcMask:  TIpBytes;
     ipDstMask:  TIpBytes;
     dwRet:      DWORD;
begin

  // Clear the filter description buffer
  ZeroMemory(@ipFlt, SizeOf(ipFlt));

  // Set the static filtering flags
  ipFlt.dwFilterFlags:=FD_FLAGS_NOSYN;
  ipFlt.dwRule:=0;
  ipFlt.pfatType:=PF_IPV4;
  ipFlt.fLateBound:=0;

  // Set protocol filtering
  case protoType of
     protoTcp :  ipFlt.dwProtocol:=FILTER_PROTO_TCP;
     protoUdp :  ipFlt.dwProtocol:=FILTER_PROTO_UDP;
  else
     ipFlt.dwProtocol:=FILTER_PROTO_ANY;
  end;

  // If nil is passed for the port, set port type to any
  if Assigned(lpszPort) then
     dwPort:=StrToIntDef(lpszPort, FILTER_TCPUDP_PORT_ANY)
  else
     dwPort:=FILTER_TCPUDP_PORT_ANY;

  // Set port ranges
  case ioType of
     // Filter all inbound connections to specified port
     ioIn  :
     begin
        ipFlt.wDstPort:=FILTER_TCPUDP_PORT_ANY;
        ipFlt.wDstPortHighRange:=FILTER_TCPUDP_PORT_ANY;
        ipFlt.wSrcPort:=dwPort;
        ipFlt.wSrcPortHighRange:=dwPort;
     end;
     // Filter all outbound connections to specific port
     ioOut :
     begin
        ipFlt.wDstPort:=dwPort;
        ipFlt.wDstPortHighRange:=dwPort;
        ipFlt.wSrcPort:=FILTER_TCPUDP_PORT_ANY;
        ipFlt.wSrcPortHighRange:=FILTER_TCPUDP_PORT_ANY;
     end;
  end;

  // Create default subnet masks
  StrToIP('255.255.255.255', @ipSrcMask);
  StrToIP('255.255.255.255', @ipDstMask);

  // Check for input or output filter
  if (ioType = ioIn) then
  begin
     // Input filter
     if Assigned(lpszRemote) then
     begin
        ipFlt.SrcAddr:=PByteArray(StrToIp(lpszRemote, @ipDest));
        ipFlt.SrcMask:=@ipSrcMask;
     end
     else
     begin
        ipFlt.SrcAddr:=PByteArray(StrToIp('0.0.0.0', @ipDest));
        StrToIP('0.0.0.0', @ipSrcMask);
        ipFlt.SrcMask:=@ipSrcMask;
     end;
     ipFlt.DstAddr:=@ipLocal;
     ipFlt.DstMask:=@ipDstMask;
     PfAddFiltersToInterface(hIF, 1, @ipFlt, 0, nil, nil);
  end
  else
  begin
     // Output filter
     ipFlt.SrcAddr:=@ipLocal;
     ipFlt.SrcMask:=@ipSrcMask;
     if Assigned(lpszRemote) then
     begin
        ipFlt.DstAddr:=PByteArray(StrToIp(lpszRemote, @ipDest));
        ipFlt.DstMask:=@ipDstMask;
     end
     else
     begin
        ipFlt.DstAddr:=PByteArray(StrToIp('0.0.0.0', @ipDest));
        StrToIP('0.0.0.0', @ipDstMask);
        ipFlt.DstMask:=@ipDstMask;
     end;
     PfAddFiltersToInterface(hIF, 0, nil, 1, @ipFlt, nil);
  end;
end;}

{Procedure BlockUDPPorts;
begin

  // Initialize winsock so we can get the local ip address
  if (WSAStartup(MakeWord(1, 1), wsaData) = 0) then
  begin

     // Get the local IP address (Network or Assigned ISP IP should it get? as it gets network)
     //192.168.0.1
     MIP:=GetIP2.GetIPAddress2;
     FillChar(IpLocal,4,#0);
     IpLocal:=StrToIpBytes(MIP);
     If MIP<>'' Then
     begin
       // Create the interface
         PfCreateInterface(0, PF_ACTION_FORWARD, PF_ACTION_FORWARD, False, True, hIF);
       For N:=5000 to 5010 do
        Begin
          AddFilter(ioIN,  Nil, protoUDP, Pchar(IntToStr(N)));
          AddFilter(ioOut,  Nil, protoUDP, Pchar(IntTOStr(N)));
     //     Sleep(10);
         End;
        PfBindInterfaceToIPAddress(hIF, PF_IPV4, @ipLocal);
     end;
  end;
end;}

Function TForm1.RandomCookieServer: String;
Begin
 Case Random(3)+1 of
   1: Result:='edit.yahoo.com';
   2: Result:='edit.my.yahoo.com';
   3: Result:='edit.europe.yahoo.com';
  End;
 Form1.Richedit1.Lines.Add('Trying to Authenticate on '+Result+' Port 80');
 Form1.ScrollToEnd(FOrm1.Richedit1);
End;



procedure RE_SetSelBgColor(RichEdit: TRichEdit; AColor: TColor);
var
  Format: CHARFORMAT2;
begin
  FillChar(Format, SizeOf(Format), #0);
  with Format do
  begin
    cbSize := SizeOf(Format);
    dwMask := CFM_BACKCOLOR;
    crBackColor := AColor;
    Richedit.Perform(EM_SETCHARFORMAT, SCF_SELECTION, Longint(@Format));
  end;
end;


procedure RE_SetCharFormat(ARichEdit: TCustomRichedit; AUnderlineType: Byte);
var
  // The CHARFORMAT2 structure contains information about
  // character formatting in a rich edit control.
  Format: CHARFORMAT2;
begin
  FillChar(Format, SizeOf(Format), #0);
  with Format do
  begin
    cbSize := SizeOf(Format);
    dwMask := CFM_UNDERLINETYPE;
    bUnderlineType := AUnderlineType or ClSilver;
    ARichEdit.Perform(EM_SETCHARFORMAT, SCF_SELECTION, Longint(@Format));
  end;
end;


function RegisterOCX(FileName: string): Boolean;
var
  OCXHand: THandle;
  RegFunc: TDllRegisterServer;
begin
  OCXHand := LoadLibrary(PChar(FileName));
  RegFunc := GetProcAddress(OCXHand, 'DllRegisterServer');
  if @RegFunc <> nil then
    Result := RegFunc = S_OK
  else
    Result := False;
  FreeLibrary(OCXHand);
end;

function UnRegisterOCX(FileName: string): Boolean;
var
  OCXHand: THandle;
  RegFunc: TDllRegisterServer;
begin
  OCXHand := LoadLibrary(PChar(FileName));
  RegFunc := GetProcAddress(OCXHand, 'DllUnregisterServer');
  if @RegFunc <> nil then
    Result := RegFunc = S_OK
  else
    Result := False;
  FreeLibrary(OCXHand);
end;


function LowerCaseRep(const s: string): string;
asm
       push  ebx
       push  esi
       push  edi
       mov   esi, eax          // s
       mov   eax, edx
       test  esi, esi
       jz    @nil
       mov   edx, [esi-4]      // Length(s)
       mov   edi, eax          // @Result
       test  edx, edx
       jle   @nil
       mov   ebx, edx
       test  edx, 3
       jz    @LengthOk         // Jump if Length mod 4 = 0
       or    edx, 3            // Else requre Length mod 4 = 3
@LengthOk:
       call  System.@LStrSetLength
       mov   edi, [edi]        // Result
       mov   [edi-4], ebx      // Correct Result length
       add   ebx, -1
       and   ebx, -4
       mov   eax, [ebx+esi]

@Loop: mov   ecx, eax
       or    eax, $80808080    // $C1..$DA
       mov   edx, eax
       sub   eax, $5B5B5B5B    // $66..$7F
       xor   edx, ecx          // $80
       or    eax, $80808080    // $E6..$FF
       sub   eax, $66666666    // $80..$99
       and   eax, edx          // $80
       shr   eax, 2            // $20
       xor   eax, ecx          // Lower
       mov   [ebx+edi], eax
       mov   eax, [ebx+esi-4]
       sub   ebx, 4
       jge   @Loop

       pop   edi
       pop   esi
       pop   ebx
       ret

@Nil:  pop   edi
       pop   esi
       pop   ebx
       jmp   System.@LStrClr   // Result:=''
end;

function PosRep(const SubStr: AnsiString; const Str: AnsiString): Integer;
asm
       push  ebx
       push  esi
       add   esp, -16
       test  edx, edx
       jz    @NotFound
       test  eax, eax
       jz    @NotFound
       mov   esi, [edx-4] //Length(Str)
       mov   ebx, [eax-4] //Length(Substr)
       cmp   esi, ebx
       jl    @NotFound
       test  ebx, ebx
       jle   @NotFound
       dec   ebx
       add   esi, edx
       add   edx, ebx
       mov   [esp+8], esi
       add   eax, ebx
       mov   [esp+4], edx
       neg   ebx
       movzx ecx, byte ptr [eax]
       mov   [esp], ebx
       jnz   @FindString

       sub   esi, 2
       mov   [esp+12], esi

@FindChar2:
       cmp   cl, [edx]
       jz    @Matched0ch
       cmp   cl, [edx+1]
       jz    @Matched1ch
       add   edx, 2
       cmp   edx, [esp+12]
       jb    @FindChar4
       cmp   edx, [esp+8]
       jb    @FindChar2
@NotFound:
       xor   eax, eax
       jmp   @Exit0ch

@FindChar4:
       cmp   cl, [edx]
       jz    @Matched0ch
       cmp   cl, [edx+1]
       jz    @Matched1ch
       cmp   cl, [edx+2]
       jz    @Matched2ch
       cmp   cl, [edx+3]
       jz    @Matched3ch
       add   edx, 4
       cmp   edx, [esp+12]
       jb    @FindChar4
       cmp   edx, [esp+8]
       jb    @FindChar2
       xor   eax, eax
       jmp   @Exit0ch

@Matched2ch:
       add   edx, 2
@Matched0ch:
       inc   edx
       mov   eax, edx
       sub   eax, [esp+4]
@Exit0ch:
       add   esp, 16
       pop   esi
       pop   ebx
       ret

@Matched3ch:
       add   edx, 2
@Matched1ch:
       add   edx, 2
       xor   eax, eax
       cmp   edx, [esp+8]
       ja    @Exit1ch
       mov   eax, edx
       sub   eax, [esp+4]
@Exit1ch:
       add   esp, 16
       pop   esi
       pop   ebx
       ret

@FindString4:
       cmp   cl, [edx]
       jz    @Test0
       cmp   cl, [edx+1]
       jz    @Test1
       cmp   cl, [edx+2]
       jz    @Test2
       cmp   cl, [edx+3]
       jz    @Test3
       add   edx, 4
       cmp   edx, [esp+12]
       jb    @FindString4
       cmp   edx, [esp+8]
       jb    @FindString2
       xor   eax, eax
       jmp   @Exit1

@FindString:
       sub   esi, 2
       mov   [esp+12], esi
@FindString2:
       cmp   cl, [edx]
       jz    @Test0
@AfterTest0:
       cmp   cl, [edx+1]
       jz    @Test1
@AfterTest1:
       add   edx, 2
       cmp   edx, [esp+12]
       jb    @FindString4
       cmp   edx, [esp+8]
       jb    @FindString2
       xor   eax, eax
       jmp   @Exit1

@Test3:
       add   edx, 2
@Test1:
       mov   esi, [esp]
@Loop1:
       movzx ebx, word ptr [esi+eax]
       cmp   bx, word ptr [esi+edx+1]
       jnz   @AfterTest1
       add   esi, 2
       jl    @Loop1
       add   edx, 2
       xor   eax, eax
       cmp   edx, [esp+8]
       ja    @Exit1
@RetCode1:
       mov   eax, edx
       sub   eax, [esp+4]
@Exit1:
       add   esp, 16
       pop   esi
       pop   ebx
       ret

@Test2:
       add   edx,2
@Test0:
       mov   esi, [esp]
@Loop0:
       movzx ebx, word ptr [esi+eax]
       cmp   bx, word ptr [esi+edx]
       jnz   @AfterTest0
       add   esi, 2
       jl    @Loop0
       inc   edx
@RetCode0:
       mov   eax, edx
       sub   eax, [esp+4]
       add   esp, 16
       pop   esi
       pop   ebx
end;

Procedure TForm1.LoadFromFile(Ht: TStringHashTrie; Filename: String);
var f: TextFile;
    S: string;
    j,ipos: integer;
    TimeMs,start, stop : Int64;
begin
 If FileExists(FileName)=False Then
   Exit;
 AssignFile(f,Filename);
  try
   Reset(f);
   ipos:=0;
   while not Eof(f) do begin
     readln(f,S);
     ht.Add(S,Tobject(Ipos));
     Inc(ipos);
   end;
  finally
   CloseFile(f);
  end;
End;

Procedure Tform1.SaveToFile(Ht: TStringHashTrie; Filename: String);
var f: TextFile;
    S: string;
    TimeMs,start, stop : Int64;
begin
  AssignFile(f,FileName);
  try
   Rewrite(f);
   //ht.Traverse(@f,TraverseProc); //???
   ht.Traverse(@f,TraverseMeth);
  finally
   CloseFile(f);
  end;
End;

Function ShortFileName(Const FileName: String): String;
Var
  aTmp: Array[0..255] Of Char;
Begin
 If GetShortPathName(PChar (FileName), aTmp, Sizeof (aTmp) - 1) = 0 Then
    Begin
      Result:= FileName;
    End
    Else
    Begin
      Result:= StrPas (aTmp);
    End;
End;


Function Tform1.ShellEXecute(hWnd: HWND; Operation, FileName, Parameters, Directory: PAnsiChar; ShowCmd: Integer): HINST;
Var
 Lib: Thandle;
Begin
 Lib:=LoadLibrary(Pchar('shell32.dll'));
 MyShellExecute:=GetProcAddress(Lib,Pchar('ShellExecuteA'));
 MyShellExecute(Hwnd,Operation,FileName,Parameters,Directory,ShowCmd);
 FreeLibrary(Lib);
End;

procedure Tform1.ListDLLExports(const FileName: string; List: TStrings);
type
  TDWordArray = array [0..$FFFFF] of DWORD;
var
  imageinfo: LoadedImage;
  pExportDirectory: PImageExportDirectory; 
  dirsize: Cardinal;
  pDummy: PImageSectionHeader; 
  i: Cardinal; 
  pNameRVAs: ^TDWordArray;
  Name: string; 
begin 
  List.Clear; 
  if MapAndLoad(PChar(FileName), nil, @imageinfo, True, True) then
  begin
    try 
      pExportDirectory := ImageDirectoryEntryToData(imageinfo.MappedAddress, 
        False, IMAGE_DIRECTORY_ENTRY_EXPORT, dirsize); 
      if (pExportDirectory <> nil) then
      begin 
        pNameRVAs := ImageRvaToVa(imageinfo.FileHeader, imageinfo.MappedAddress, 
          DWORD(pExportDirectory^.AddressOfNames), pDummy); 
        for i := 0 to pExportDirectory^.NumberOfNames - 1 do 
        begin 
          Name := PChar(ImageRvaToVa(imageinfo.FileHeader, imageinfo.MappedAddress, 
            pNameRVAs^[i], pDummy)); 
          List.Add(Name);
        end; 
      end; 
    finally 
      UnMapAndLoad(@imageinfo); 
    end; 
  end; 
end;


{procedure Tform1.SetTransparentForm(AHandle:THandle; AValue:byte);
var
 Info: TOSVersionInfo;
 SetLayeredWindowAttributes: TSetLayeredWindowAttributes;
begin
 //Check Windows version
 Info.dwOSVersionInfoSize := SizeOf(Info);
 GetVersionEx(Info);
 if (Info.dwPlatformId = VER_PLATFORM_WIN32_NT) and
 (Info.dwMajorVersion >= 5) then
   begin
     SetLayeredWindowAttributes := GetProcAddress(GetModulehandle(user32), 'SetLayeredWindowAttributes');
      if Assigned(SetLayeredWindowAttributes) then
       begin
        IF Avalue<255 Then
         Begin
          SetWindowLong(AHandle, GWL_EXSTYLE, GetWindowLong(AHandle, GWL_EXSTYLE) or WS_EX_LAYERED);
        //Make form transparent
          SetLayeredWindowAttributes(AHandle, 0, AValue, LWA_ALPHA);
         End
          else
         SetWindowLong(AHandle, GWL_EXSTYLE, OrStyle);
      end;
   end;
end;}


procedure TForm1.CreateParams(var Params: TCreateParams);
begin
  inherited CreateParams(Params);
//   Params.ExStyle := Params.ExStyle and not WS_EX_TOOLWINDOW or WS_EX_APPWINDOW;
   Params.WinClassName := 'Y!mLite';
end;

const
  SubStorageMode = fmOpenReadWrite or fmShareExclusive or fmTransacted;
  StorageMode = SubStorageMode or fmDeleteOnRelease;
  CLSID_NULL : TCLSID = '{00000000-0000-0000-0000-000000000000}';

constructor TREOleCallBack.Create;
begin
  inherited Create;
  FStorage := OleStdCreateTempRootStorage (StorageMode);
end;

Procedure CreateIStorage(Out Fstorage : Istorage);
// Crée un IStorage
Var
  FlockBytes : IlockBytes;
Begin
  OleCheck(CreateILockBytesOnHGlobal(0, True, FLockBytes));
  OleCheck(StgCreateDocfileOnILockBytes(FLockBytes, STGM_SHARE_EXCLUSIVE Or STGM_CREATE Or STGM_READWRITE, 0, FStorage))
End;



function TREOleCallBack.GetNewStorage (out Stg: IStorage): HRESULT;
begin
  Result:= ddOk;
  Try
    CreateIStorage(stg);
    Result := S_OK;
  Except
    Result := E_OUTOFMEMORY;
  End;
 { inc (FItemCount);
  Stg := OleStdCreateChildStorage (FStorage, Format ('REOBJ%d', [FItemCount]), SubStorageMode)}
end;

function TREOleCallBack.GetInPlaceContext (out Frame: IOleInPlaceFrame; out Doc: IOleInPlaceUIWindow; var FrameInfo: TOleInPlaceFrameInfo): HRESULT;
begin
  Result:=  ddNotImplemented
end;

Function TREOleCallBack._Release : LongInt;
Begin
  Dec(FRefCount);
  Result := FRefCount;
End;


function TREOleCallBack.ShowContainerUI (fShow: BOOL): HRESULT;
begin
  Result:=  ddNotImplemented
end;

function TREOleCallBack.QueryInsertObject (const clsid: TCLSID; stg: IStorage; cp: longint): HRESULT;
begin
  Result :=  ddOk
end;

function TREOleCallBack.DeleteObject (oleobj: IOLEObject): HRESULT;
begin
   If Assigned(oleobj) Then
      oleobj.Close(OLECLOSE_NOSAVE);
  Result := NOERROR;
end;

function TREOleCallBack.QueryAcceptData (dataobj: IDataObject; var cfFormat: TClipFormat; reco: DWORD; fReally: BOOL; hMetaPict: HGLOBAL): HRESULT;
begin
  Result := ddOk
end;

function TREOleCallBack.ContextSensitiveHelp (fEnterMode: BOOL): HRESULT;
begin
  Result :=  ddNotImplemented
end;

function TREOleCallBack.GetClipboardData (const chrg: TCharRange; reco: DWORD; out dataobj: IDataObject): HRESULT;
begin
  Result := ddNotImplemented
end;

function TREOleCallBack.GetDragDropEffect (fDrag: BOOL; grfKeyState: DWORD; var dwEffect: DWORD): HRESULT;
begin
  Result := ddNotImplemented
end;

function TREOleCallBack.GetContextMenu (seltype: Word; oleobj: IOleObject; const chrg: TCharRange; var menu: HMENU): HRESULT;
begin
  Result := ddNotImplemented
end;

Function OleMalloc(Size : Longword;Malloc : IMalloc = Nil) : pointer;
// Alloue et retourne un pointeur d'un block mémoire
Begin
  If Not Assigned(Malloc) Then
    Result := CoTaskMemAlloc(Size)
  Else
    Result := Malloc.Alloc(Size)
End;

procedure REOleSetCallback (RichEdit : TMyRichedit; OleInterface: IRichEditOleCallback);
begin
  if (not Assigned (RichEdit)) or (SendMessage (RichEdit.Handle, EM_SETOLECALLBACK, 0, integer (OleInterface)) = 0) then
    raise Exception.Create('Unable to set RichEditOleCallback')
end;

{Procedure TForm1.CreateSound(Msg,FileName: String);
Begin
 If Form1.YmLiteMessageSounds1.Checked=True Then
  TTTSDownload.Create(Msg,''+FileName,True,'Female','British');
End;}

function ColorGradient(StartColor, EndColor: TColor; Steps,WichStep: integer): Tcolor;
var
Deltas: array [0..2] of Real; //R,G,B
begin
    Deltas[0] := (GetRValue(EndColor) - GetRValue(StartColor)) / Steps;
    Deltas[1] := (GetGValue(EndColor) - GetGValue(StartColor)) / Steps;
    Deltas[2] := (GetBValue(EndColor) - GetBValue(StartColor)) / Steps;
    result := RGB(Round(GetRValue(StartColor) + WichStep * Deltas[0]),
                  Round(GetGValue(StartColor) + WichStep * Deltas[1]),
                  Round(GetBValue(StartColor) + WichStep * Deltas[2]));
end;


procedure StopSound;
begin
SndPlaySound(nil,SND_ASYNC or SND_PURGE);
end;


{Procedure SortSmilesArray;
Var
 Tmp: String;
 N1,N2: Integer;
Begin
 For N1:=0 to High(Smiles)-1 Do
  For N2:=0 to High(Smiles)-1 DO
     If Length(Smiles[N2+1])<Length(Smiles[N2]) Then
      Begin
        Tmp:=Smiles[N2+1];
        Smiles[N2+1]:=Smiles[N2];
        Smiles[N2]:=Tmp;
      End;
End;}



Function Tform1.PipeOutCommand(DosApp:String): String;
const
   ReadBuffer = 2400;
 var
   BufferStr: String;
   Security : TSecurityAttributes;
   ReadPipe,WritePipe : THandle;
   start : TStartUpInfo;
   ProcessInfo : TProcessInformation;
   Buffer : Pchar;
   BytesRead : DWord;
   Apprunning : DWord;
  begin
   BufferStr:='';
   With Security do begin
    nlength := SizeOf(TSecurityAttributes) ;
    binherithandle := true;
    lpsecuritydescriptor := nil;
   end;
   if Createpipe (ReadPipe, WritePipe,
                  @Security, 0) then begin
    Buffer := AllocMem(ReadBuffer + 1) ;
    FillChar(Start,Sizeof(Start),#0) ;
    start.cb := SizeOf(start) ;
    start.hStdOutput := WritePipe;
    start.hStdInput := ReadPipe;
    start.dwFlags := STARTF_USESTDHANDLES +
                         STARTF_USESHOWWINDOW;
    start.wShowWindow := SW_Hide;

    if CreateProcess(nil,
           PChar(DosApp),
           @Security,
           @Security,
           true,
           NORMAL_PRIORITY_CLASS,
           nil,
           nil,
           start,
           ProcessInfo)
    then
    begin
     repeat
      Apprunning := WaitForSingleObject
                   (ProcessInfo.hProcess,100) ;
      Application.ProcessMessages;
     until (Apprunning <> WAIT_TIMEOUT) ;
      Repeat
        BytesRead := 0;
        ReadFile(ReadPipe,Buffer[0],
ReadBuffer,BytesRead,nil) ;
        Buffer[BytesRead]:= #0;
        OemToAnsi(Buffer,Buffer) ;
        BufferStr:=BufferStr+String(Buffer) ;
      until (BytesRead < ReadBuffer) ;
   end;
   FreeMem(Buffer) ;
   CloseHandle(ProcessInfo.hProcess) ;
   CloseHandle(ProcessInfo.hThread) ;
   CloseHandle(ReadPipe) ;
   CloseHandle(WritePipe) ;
   end;
 Result:=BufferStr;
end;

Function TForm1.GetFileSize(FileN: String): Integer;
Var
 F: File;
 S: TFileStream;
Begin
If FileExists(FileN) Then
Begin
   S := TFileStream.Create(FileN, fmOpenRead or fmShareDenyNone);
   Result:=S.Size;
   S.Free;
 End
  else
 Result:=0;
End;


Function Tform1.ShellPipeOutCommand(DosApp:String): String;
const
   ReadBuffer = 8000;
 var
   BufferStr: String;
   Security : TSecurityAttributes;
   ReadPipe,WritePipe : THandle;
   start : TStartUpInfo;
   ProcessInfo : TProcessInformation;
   Buffer : Pchar;
   BytesRead : DWord;
   Apprunning : DWord;
  begin
   DosApp:='cmd command.com /c '+DosApp;
   BufferStr:='';
   With Security do begin
    nlength := SizeOf(TSecurityAttributes) ;
    binherithandle := true;
    lpsecuritydescriptor := nil;
   end;
   if Createpipe (ReadPipe, WritePipe,
                  @Security, 0) then begin
    Buffer := AllocMem(ReadBuffer + 1) ;
    FillChar(Start,Sizeof(Start),#0) ;
    start.cb := SizeOf(start) ;
    start.hStdOutput := WritePipe;
    start.hStdInput := ReadPipe;
    start.dwFlags := STARTF_USESTDHANDLES +
                         STARTF_USESHOWWINDOW;
    start.wShowWindow := SW_hide;

    if CreateProcess(nil,
           PChar(DosApp),
           @Security,
           @Security,
           true,
           NORMAL_PRIORITY_CLASS,
           nil,
           nil,
           start,
           ProcessInfo)
    then
    begin
     repeat
      Apprunning := WaitForSingleObject
                   (ProcessInfo.hProcess,100) ;
      Application.ProcessMessages;
     until (Apprunning <> WAIT_TIMEOUT) ;
      Repeat
        BytesRead := 0;
        ReadFile(ReadPipe,Buffer[0],
ReadBuffer,BytesRead,nil) ;
        Buffer[BytesRead]:= #0;
        OemToAnsi(Buffer,Buffer) ;
        BufferStr:=BufferStr+String(Buffer) ;
      until (BytesRead < ReadBuffer) ;
   end;
   FreeMem(Buffer) ;
   CloseHandle(ProcessInfo.hProcess) ;
   CloseHandle(ProcessInfo.hThread) ;
   CloseHandle(ReadPipe) ;
   CloseHandle(WritePipe) ;
   end;
 Result:=BufferStr;
end;

Procedure TForm1.DrawSmileys;
Var
 N: Integer;
 TmpSmileyList: TStringList;
Begin
 Form14.Obj:=Form14.RichEdit1;
 Form14.Richedit1.Clear;
 TmpSmileyList:=TstringList.Create;
 TmpSmileyList.Sort;
//  For N:=1 to High(Smiles) Do
 N:=0;
  While N<High(Smiles) Do
   Begin
    IF Smiles[N].FileName<>'' Then
     Begin
      If TmpSmileyList.IndexOf(Smiles[N].FileName)=-1 Then
       Begin
        Form1.DoRtfFace(Form14.Richedit1,Smiles[N].FileName);
        Form14.Richedit1.SelText:=Smiles[N].KeyCombo+'     ';
        TmpSmileyList.Add(Smiles[N].FileName);
        Application.ProcessMessages;
       End;
      Inc(N); 
     End
      else
     Break;
   End;
  TmpSmileyList.Free;  
End;

Procedure Tform1.ExtractSmileyList;
Var
 T: System.Text;
 Tmp2,tmp: String;
 N: Integer;
 SmInfo: PSmileyInfo;
 SmileyTmpList: TStringList;
Begin
{ If FileExists(Path+'rtfimages\smileyref.txt') Then
  Begin
   SortList:=TStringList.Create;
   SortList.LoadFromFile(Path+'rtfimages\smileyref.txt');
   SortList.SaveToFile(Path+'rtfimages\smileyref.txt');
   SortList.Free;
  End;}
 SmileyTmpList:=TStringList.Create;
 N:=0;
 //Smileys.Clear;
 If FileExists(Path+'rtfimages\smileyref.txt') Then
 Begin
  SmileyTmpList.LoadFromFile(Path+'rtfimages\smileyref.txt');
  For N:=0 To SmileyTmpList.Count-1 do
   Begin
    Tmp:=SmileyTmpList.Strings[N];
    If Trim(Tmp)<>'' Then
     Begin
 //     SetLength(Smiles,N+1);
      Tmp2:=Copy(Tmp,1,PosRep(' ',tmp));
      Smiles[N].KeyCombo:=LowerCaseRep(Trim(Tmp2));
      Delete(Tmp,1,PosRep(' ',Tmp));
      Tmp2:=Tmp;
      Smiles[N].FileName:=Tmp2;
      Smileys.Add(Smiles[N].KeyCombo,Tobject(@smiles[N]));
//  Smileys.AddObject(Smiles[N].KeyCombo,Tobject(@smiles[N]));
      //  If FileExists(Path+'\rtfimages\Tmp);
     End;
   End;
  End;
 SmileyTmpList.Free;
{ If Assigned(Form14) Then
   DrawSmileys;}
//  SortSmilesArray;
End;

Procedure AddBlockMessage(Msg: String);
Begin
  Form40.ListBox1.Items.Insert(0,Msg);
  If Form40.ListBox1.Items.Count>40 Then
    Form40.ListBox1.Items.Delete(Form40.ListBox1.Items.Count-1);
End;

function GetWindowA (Handle: HWND; LParam: longint): bool; stdcall;
begin
  Result := true;
  WindowList.Add (Pointer(Handle));
end;


function Tform1.GetProxySettings: TMyProxySettings;
const
 IE_REG_KEY = 'Software\Microsoft\Windows\CurrentVersion\Internet Settings';
 DEFAULT_PORT: integer = 80;
var
 reg: TRegistry;
 cp: integer;
 s: string;
begin
 reg := TRegistry.Create;
 try
   with reg do
   begin
     RootKey := HKEY_CURRENT_USER;
     if OpenKey(IE_REG_KEY,false) then
     begin
       //get server name & port (usually combined)
       s := ReadString('ProxyServer');
       cp := PosRep(':',s);
       if cp > 0 then
       begin
         result.Server := Copy(s,1,cp-1);
         result.Port := StrToIntDef(Copy(s,cp+1,length(s)-cp),DEFAULT_PORT);
       end
       else
       begin
         result.Server := s;
         result.Port := DEFAULT_PORT;
       end;
       //get proxy enabled state
       cp := ReadInteger('ProxyEnable');
       result.Enabled := cp > 0;
       //all done
       CloseKey;
     end
     else
     begin
       result.Server := '';
       result.Port := DEFAULT_PORT;
     end;
   end;
 finally
   reg.free;
 end;
end;

{Function Strip(Const S : String) : String;
Begin
  Result := S;
  Delete(Result,1,2);
End;

Function MD5ToString(Const S : String) : String;
Var I : Integer;
Begin
   Result := '';
  For I := 1 to Length(S) do Begin
    Result := Result+IntToHex(Ord(S[I]),2);
  End;
End;

Function Tform1.Md5Encode(S: String): String;
Begin
 Form1.IdCoderMD51.Reset;
 Form1.IdCoderMD51.AutoCompleteInput := True;
 Form1.IdCoderMD51.Key:='_2S43d5f';
 Result := Strip(Form1.IdCoderMD51.CodeString(S));
 //MD5 of "test" is $1$_2S43d5f$aICQZCAFvFAWof1vtGFLe1
End;}

Function GetHandle(PClass,ClassName: String): Hwnd;
var i: integer;
    wnd,Hnd: HWND;
    Buffer: array [0..255] of char;
begin
  ClassName:=LowerCaseRep(ClassName);
  PClass:=LowerCaseRep(Pclass);
  WindowList := TList.Create;
  Wnd:=Findwindow(Pchar(PClass),nil);
  EnumChildWindows (wnd,@GetWindowA, 0);
    for i := 0 to WindowList.Count - 1 do
     begin
      Hnd := HWND (WindowList [i]);
      GetWindowText (Hnd, Buffer, SizeOf (Buffer) - 1);
      getclassname(hnd,buffer,sizeof(buffer));
      If ClassName=LowerCaseRep(String(Buffer)) Then
           GetHandle:=Hnd;
     end;
 WindowList.Free;
End;

//Wnd:=GetHandle('shell_traywnd','TrayClockWClass');


Procedure SetRichedit2;
Var
 TmpStr: String;
Begin
// TmpStr:=Form1.RichEdit2.Text;
// Form1.Richedit2.Clear;
 Form1.Richedit2.SelAttributes.Color:=Form1.ColorBox1.ColorValue;
 Form1.Richedit2.SelAttributes.Size:=StrToInt(Form1.SpSkinComboBox2.Text);
 Form1.Richedit2.SelAttributes.Name:=Form1.spSkinFontComboBox1.FontName;
 Form1.Richedit2.SelAttributes.Style:=[];
  If Form1.BoldP.checked=true Then
    Form1.Richedit2.SelAttributes.Style:=Form1.Richedit2.SelAttributes.Style+[FsBold];
  IF Form1.ItalicP.checked=true Then
    Form1.Richedit2.SelAttributes.Style:=Form1.Richedit2.SelAttributes.Style+[FsItalic];
  If Form1.UnderLineP.checked=true Then
    Form1.Richedit2.SelAttributes.Style:=Form1.Richedit2.SelAttributes.Style+[FsUnderline];
// Form1.RichEdit2.SelText:=TmpStr;
End;

Procedure SaveUserData;
Var
 Tmp: TstringList;
Begin
 NeverIgnore.SaveToFile(Path+'NeverIgnore.txt');
// Ignored.SaveToFile(Path+'Ignored.txt');
 Form1.SaveToFile(Ignored,Path+'Ignored.txt');
 Form5.ListBox1.Items.SaveToFile(Path+'Urls.txt');
 Form18.ListBox1.Items.SaveToFile(Path+'emotes.txt');
 FriendsAlias.SaveToFile(Path+'friendsalias.txt');
 Tcols.SaveToFile(Path+'Fade.Txt');
 Tmp:=TStringList.Create;
 Tmp.Clear;
 Tmp.Add(Form20.Edit1.Text);
 Tmp.Add(Form20.Edit2.Text);
 Tmp.Add(Form20.Edit3.Text);
 Tmp.Add(Form20.Edit4.Text);
 Tmp.SaveToFile(Path+'hotkeys.txt');
 Tmp.Free;
End;

Function UserGender(code: String): String;
Begin
 Try
  If Code<>'' Then
    Case StrToInt(Trim(Code)) Of
         66560: Result:='Female';
         66624: Result:='Female';
         83008: Result:='Female';
         66640: Result:='Female'; //cam on?
         66576: Result:='CamF';
         50240: Result:='Male';
         33856: Result:='Male';   //cam off
         33792: Result:='Male';
         33808: Result:='CamM';
         34112: Result:='Male';
         33872: Result:='Male';   //cam on?
         1088:  Result:='Unknown';
         1024:  Result:='Unknown';
         1104:  Result:='Female';
         1040:  Result:='CamU';
       Else
         Result:='Unknown '+Code+'?';
      End;
    Except
  End;    
End;

{Procedure SetupData;
Begin
    ChatData.ChatBuffer:=0;
    ChatData.LastColorSelected:=clblack;
    ChatData.BoldS:=False;
    ChatData.ItalicS:=False;
    ChatData.UndS:=False;
    ChatData.ListBox1Color:=ClWhite;
    ChatData.ListBox2Color:=ClWhite;
    ChatData.Memo1Color:=ClWhite;
//    ChatData.Debug:=False;
    ChatData.PmsOff:=False;
    ChatData.LastRoom:='';
    ChatData.UserFontSize:=10;
    ChatData.EnableAi1:=True;
    ChatData.JavaFriendly:=False;
    ChatData.AutoRSpaces:=True;
    ChatData.NoFonts:=False;
    ChatData.HackersCode:=False;
    ChatData.OtronTech:=False;
    ChatData.SwearWordFilter:=True;
    ChatData.AntiFlood:=3;
    ChatData.FloodMatch:=90;
    ChatData.FloodLevel:=2;
    ChatData.HotKeys:=False;
    ChatData.CrLf:=True;
    ChatData.Cpu:=201;
    ChatData.RestrictedColors:=False;
    ChatData.SelectedFont:='Arial';
    ChatData.FaderOnOrOff:=False;
    ChatData.FontSize:=11;
    ShowMessage('For Richedit Optimizations, a CPU check is needed (You will not be asked again to do this)');
    ShowMessage('Your estimated CPU speed is: '+FloatToStr(Form1.GetCpuSpeed)+'Mhz');
End;}


function StreamSave(dwCookie: Longint; pbBuff: PByte;
  cb: Longint; var pcb: Longint): Longint; stdcall;
var
  StreamInfo: PRichEditStreamInfo;
begin
  Result := NoError;
  StreamInfo := PRichEditStreamInfo(Pointer(dwCookie));
  try
    pcb := 0;
    if StreamInfo^.Converter <> nil then
      pcb := StreamInfo^.Converter.ConvertWriteStream(StreamInfo^.Stream, PChar(pbBuff), cb);
  except
    Result := WriteError;
  end;
end;


Function ExtraInfo(JoinRoom: String): String;
Begin
 Result:='';
 If Chatters[Form1.ChatterNum(JoinRoom)].Nick<>'' Then
     Result:=Result+'Nick Name: '+Chatters[Form1.ChatterNum(JoinRoom)].Nick;
 If Chatters[Form1.ChatterNum(JoinRoom)].Location<>'' Then
     Result:=Result+' Location: '+Chatters[Form1.ChatterNum(JoinRoom)].Location;
 If Chatters[Form1.ChatterNum(JoinRoom)].Age<>'' Then
     Result:=Result+' Age: '+Chatters[Form1.ChatterNum(JoinRoom)].Age;
 If Chatters[Form1.ChatterNum(JoinRoom)].Extra<>'' Then
     Result:=Result+' Gender: '+UserGender(Chatters[Form1.ChatterNum(JoinRoom)].Extra);
 If Trim(Chatters[Form1.ChatterNum(JoinRoom)].ChatClient)<>'' Then
     Result:=Result+' Chat Client Detected: '+Chatters[Form1.ChatterNum(JoinRoom)].Chatclient+', ';
 If Trim(Chatters[Form1.ChatterNum(JoinRoom)].Version)<>'' Then
     Result:=Result+' Ver: '+Chatters[Form1.ChatterNum(JoinRoom)].Version;
 If Trim(Chatters[Form1.ChatterNum(JoinRoom)].ExtendedInfo)<>'' Then
     Result:=Result+' Detected Info: '+Chatters[Form1.ChatterNum(JoinRoom)].ExtendedInfo;
 If Trim(Chatters[Form1.ChatterNum(JoinRoom)].Proto)<>'' Then
     Result:=Result+' Proto: '+Chatters[Form1.ChatterNum(JoinRoom)].Proto;
   Try
 If Chatters[Form1.ChatterNum(JoinRoom)].YLinePost<>0 Then
     Result:=Result+' ALP: '+IntTOStr(Chatters[Form1.ChatterNum(JoinRoom)].YLinePost);
   Except
  End;
End;

function GetSelectionRTF(RichEdit: TMyRichedit): String;
var
  EditStream: TEditStream;
  TextType: Longint;
  StreamInfo: TRichEditStreamInfo;
  Converter: TConversion;
  Stream: TMemoryStream;
begin
  Stream := TMemoryStream.Create;
  Converter := RichEdit.DefaultConverter.Create;
  StreamInfo.Stream := Stream;
  StreamInfo.Converter := Converter;
  try
    with EditStream do
    begin
      dwCookie := LongInt(Pointer(@StreamInfo));
      pfnCallBack := @StreamSave;
      dwError := 0;
    end;
    TextType := SF_RTF  or SFF_SELECTION;
    SendMessage(RichEdit.Handle, EM_STREAMOUT, TextType, Longint(@EditStream));
  finally
    Converter.Free;
    Stream.Position := 0;
    SetLength(Result, Stream.Size);
    Result:=PChar(Stream.Memory);
    Stream.Free;
  end;
end;

function AdjustLineBreaks(Dest, Source: PChar): Integer; assembler;
asm
        PUSH    ESI
        PUSH    EDI
        MOV     EDI,EAX
        MOV     ESI,EDX
        MOV     EDX,EAX
        CLD
@@1:    LODSB
@@2:    OR      AL,AL
        JE      @@4
        CMP     AL,0AH
        JE      @@3
        STOSB
        CMP     AL,0DH
        JNE     @@1
        MOV     AL,0AH
        STOSB
        LODSB
        CMP     AL,0AH
        JE      @@1
        JMP     @@2
@@3:    MOV     EAX,0A0DH
        STOSW
        JMP     @@1
@@4:    STOSB
        LEA     EAX,[EDI-1]
        SUB     EAX,EDX
        POP     EDI
        POP     ESI
end;

function StreamLoad(dwCookie: Longint; pbBuff: PByte;
  cb: Longint; var pcb: Longint): Longint; stdcall;
var
  Buffer, pBuff: PChar;
  StreamInfo: PRichEditStreamInfo;
begin
  Result := NoError;
  StreamInfo := PRichEditStreamInfo(Pointer(dwCookie));
  Buffer := StrAlloc(cb + 1);
  try
    cb := cb div 2;
    pcb := 0;
    pBuff := Buffer + cb;
    try
      if StreamInfo^.Converter <> nil then
        pcb := StreamInfo^.Converter.ConvertReadStream(StreamInfo^.Stream, pBuff, cb);
      if pcb > 0 then
      begin
        pBuff[pcb] := #0;
        if pBuff[pcb - 1] = #13 then pBuff[pcb - 1] := #0;
        pcb := AdjustLineBreaks(Buffer, pBuff);
        Move(Buffer^, pbBuff^, pcb);
      end;
    except
      Result := ReadError;
    end;
  finally
    StrDispose(Buffer);
  end;
end;

Function Tform1.GetTagLine: String;
Var
  TagLines: TstringList;
Begin
If FileExists(Path+'Tags.Txt') Then
 Begin
  TagLines:=TStringList.Create;
  TagLines.LoadFromFile(Path+'tags.txt');
  Result:=TagLines.Strings[Random(TagLines.Count)];
  TagLines.Free;
 End
  else
 Form1.Richedit1.Lines.Add('Tags.Txt does not exist..');
 Form1.ScrollToEnd(FOrm1.Richedit1);
End;

procedure Tform1.SetSelectionRTF(RichEdit: TCustomRichedit; S: String);
var
  EditStream: TEditStream;
  Position: Longint;
  TextType: Longint;
  StreamInfo: TRichEditStreamInfo;
  Converter: TConversion;
  Stream: TMemoryStream;
begin
  If Length(S)<1 Then Exit;
  Stream := TMemoryStream.Create;
  Stream.Write(S[1], Length(S)+1);
  Stream.Position:=0;
  StreamInfo.Stream := Stream;
  Converter := RichEdit.DefaultConverter.Create;
  StreamInfo.Converter := Converter;
  try
    with EditStream do
    begin
      dwCookie := LongInt(Pointer(@StreamInfo));
      pfnCallBack := @StreamLoad;
      dwError := 0;
    end;
    Position := Stream.Position;
    TextType := SF_RTF or SFF_SELECTION;
    SendMessage(RichEdit.Handle, EM_STREAMIN, TextType, Longint(@EditStream));
    if (TextType = SF_RTF) and (EditStream.dwError <> 0) then
    begin
      Stream.Position := Position;
      TextType := SF_RTF or SFF_SELECTION;
      SendMessage(RichEdit.Handle, EM_STREAMIN, TextType, Longint(@EditStream));
    end;
  finally
    Converter.Free;
    Stream.Free;
  end;
end;


function PrintToCanvas(ACanvas : TCanvas; FromChar, ToChar : integer;
                      ARichEdit : TMyRichedit; AWidth, AHeight : integer) : Longint;
var
 Range    : TFormatRange;
begin
 FillChar(Range, SizeOf(TFormatRange), #0);
 Range.hdc        := ACanvas.handle;
 Range.hdcTarget  := ACanvas.Handle;
 Range.rc.left    := 0;
 Range.rc.top     := 0;
 Range.rc.right   := AWidth * 1440 div Screen.PixelsPerInch;
 Range.rc.Bottom  := AHeight * 1440 div Screen.PixelsPerInch;
 Range.chrg.cpMax := ToChar;
 Range.chrg.cpMin := FromChar;
 Result := SendMessage(ARichedit.Handle, EM_FORMATRANGE, 1, Longint(@Range));
 SendMessage(ARichEdit.handle, EM_FORMATRANGE, 0,0);
end;



Procedure tform1.ConnectToSPRT(LoggedInName,RoomName,LoggedInPassword,Cookie: String);
var
  RndServ: Integer;
Begin
 Form1.SPRT.Active:=False;
 RndServ:=Random(1)+1;
  Case RndServ Of
   1: Form1.SPRT.Port:=8866;
//   2: Form1.YCHT.Port:=8002;
  End;

  RndServ:=Random(1)+1;
  Case RndServ Of
   1: Form1.SPRT.Host:='spartahost.ath.cx'; //Form2.Edit2.Text; //replace for getip
//   2: Form1.YCHT.Host:='cs8.chat.yahoo.com';
//   3: Form1.dhtml.Host:='cs66.msg.sc5.yahoo.com';
//   2: Form1.Ymsg.Host:='cs44.msg.sc5.yahoo.com';  //logs in that's it!
//   3: Form1.Ymsg.Host:='';
//   4: Form1.Ymsg.Host:='';
  End;

//Form1.SPRT.Host:='127.0.0.1';

Form1.Richedit1.SelStart:=-1;
 If Form10.CheckBox3.Checked=True Then
  Begin
   Form1.Richedit1.SelText:='Attempting Proxy Connection: '+Form10.Edit3.Text+':'+Form10.Edit4.Text+' For connection with: '+Form1.SPRT.Host+' On Port: ';
   Form1.Richedit1.SelText:=IntToStr(Form1.SPRT.port);
   Form1.Richedit1.Lines.Add('');
   Form1.ScrollToEnd(FOrm1.Richedit1);   
   Form2.ProxySPRTConnect;
  End
    else
  Begin
   Form1.Richedit1.Lines.Add('Attempting Connection With: '+Form1.SPRT.Host+' On Port: '+IntToStr(Form1.SPRT.port));
   Form1.ScrollToEnd(FOrm1.Richedit1);
   Form1.SPRT.Active:=True;
  End;
 Form1.Richedit1.SelStart:=-1;
 If Form1.Scroll1.Checked=True Then Form1.ScrollToEnd(Form1.Richedit1);
End;




Function Soundex(OriginalWord: string): string;
var
  Tempstring1, Tempstring2: string;
  Count: integer;
begin
  Tempstring1 := '';
  Tempstring2 := '';
  OriginalWord := Uppercase(OriginalWord); {Make original word uppercase}
  Tempstring1:=tempString1+OriginalWord[1]; {Use the first letter of the word}
  for Count := 2 to length(OriginalWord) do
    {Assign a numeric value to each letter, except the first}
    case OriginalWord[Count] of
      'B','F','P','V': Tempstring1:=Tempstring1+'1';
      'C','G','J','K','Q','S','X','Z': Tempstring1:=Tempstring1+'2';
      'D','T': Tempstring1:=Tempstring1+'3';
      'L': Tempstring1:=Tempstring1+'4';
      'M','N': Tempstring1:=Tempstring1+'5';
      'R': Tempstring1:=Tempstring1+'6';
      {All other letters, punctuation and numbers are ignored}
    end;
   Tempstring2:=TempString2+OriginalWord[1];
  {Go through the result removing any consecutive duplicate numeric values.}

  for Count:=2 to length(Tempstring1) do
    if Tempstring1[Count-1]<>Tempstring1[Count] then
        Tempstring2:=TempString2+Tempstring1[Count];
  Soundex:=Tempstring2; {This is the soundex value}
end;


Function SoundAlike(Word1, Word2: string): boolean;
begin
  if (Word1 = '') and (Word2 = '') then result := True
  else
  if (Word1 = '') or (Word2 = '') then result := False
  else
  if (Soundex(Word1) = Soundex(Word2)) then result := True
  else result := False;
end;


//Add ons for user leave/enter


Function DeleteBadIdentitars: Boolean;
var
 F: TSearchRec;
begin
if FindFirst(Path+'identitar\*.$$$',faAnyFile, F) = 0 then
  repeat
   DeleteFile(Path+'identitar\'+F.Name);
  until FindNext(F) <> 0;

  if FindFirst(Path+'RtfImages\*.$$$',faAnyFile, F) = 0 then
  repeat
   DeleteFile(Path+'RtfImages\'+F.Name);
  until FindNext(F) <> 0;

 if FindFirst(Path+'cheeta_avs\*.$$$',faAnyFile, F) = 0 then
  repeat
   DeleteFile(Path+'cheeta_avs\'+F.Name);
  until FindNext(F) <> 0;
End;


Procedure TForm1.ScanForIllegals(UserName: String; RoomEnter: Boolean);
Var
 Tmp,S: String;
Begin
 S:=Form10.Edit6.Text;
 For N:=1 to Form1.Scanit(',',S)+1 Do
  Begin
   If PosRep(',',S)>0 Then
     Tmp:=Trim(Copy(S,1,PosRep(',',S)-1))
      else
     Tmp:=S;
    If PosRep(',',S)>0 Then
      Delete(S,1,Length(Tmp)+1);
    If Trim(Tmp)<>'' Then
    If PosRep(LowerCaseRep(Tmp),LowerCaseRep(UserName))>0 Then
      Begin
       If RoomEnter=False Then
        Begin
           If Form18.CheckBox1.Checked=True Then
              Form1.IgnoreUser(UserName,False,True,True,RoomEnter)
            else
              Form1.IgnoreUser(UserName,True,True,True,RoomEnter);
         End
          else
            Form1.IgnoreUser(UserName,False,False,False,RoomEnter)
       End;
    End;
End;

Function TForm1.IsAa1Bot(Name: String): Boolean;
Var
 N,C: Integer;
 Tmp: String;
 Len: Integer;
Begin
 Result:=False;
 Len:=Length(Name);
 If Len<6 Then Exit;
 C:=0;
// If Name[Len-5]='_' Then Exit;
 Tmp:=Copy(Name,Len-4,5);
 If Tmp[3]<>'_' Then Exit;
 For N:=1 to Length(Tmp) do
  If Tmp[N] in ['0'..'9','a'..'f','A'..'F'] Then
    Inc(C);
 If C=4 Then
   Result:=True;
End;



Function Tform1.UserJoined(UserName,Nick,Gender: String): Boolean;
Var
  SDetails: TCloneDetails;
  Tmp: String;
  HLike: Integer;
  S: String;
  N: Integer;
  Obj: TObject;
Begin

Result:=False;

 If Ignored.Find(UserName,Obj)=True Then
  Exit;

 IF Form10.AA1BotFilter.Checked=True Then
    Begin
      If IsAa1Bot(UserName)=True Then
       Begin
         Form1.Panel10.Caption:=Username+': Ignored for being aa1 family bot (Y!options > Flood Filters > AA1 Bot family (RED) Setting ';
         AddBlockMessage(Form1.Panel10.Caption);
         Form1.IgnoreUser(Username,false,true,True,False);
         Result:=True;
         Exit;
       End;
    End;

// UserName:=LowerCaseRep(UserName);
// TfadeWindow2.Create(Form1.Panel10,Form1.Panel10.Color,ColSelect.AlertColor,30);

 If Form10.CheckBox12.Checked=True Then
  If (LowerCaseRep(LoggedInName)<>LowerCaseRep(UserName)) Then
   Begin
      For N:=1 to High(Chatters) Do
//        If Friends.IndexOf(Chatters[N].Username)<>-1 Then
         If Friends.Find(Chatters[N].Username,Obj)=True Then
           Begin
            Hlike:=HowAlike(Chatters[N].Username,Username);
            If HLike>Form10.SpinEdit14.Value Then
             Begin
              Form1.Panel10.Caption:='Possible Clone: '+Chatters[N].Username+' has an '+IntToStr(HLike)+'% match against '+Username;
              AddBlockMessage(Form1.Panel10.Caption);
              If Form10.CheckBox5.Checked=True Then
                   Say(Form1.Richedit1,'Clone Warning: '+Chatters[N].Username+' has an '+IntToStr(HLike)+'% match against '+Username,False,False,False);
              Result:=True;
              If Form10.CheckBox13.Checked=True Then
                 Form1.IgnoreUser(UserName,false,True,True,False);
          End;
       End;
    End;



  If Form10.CheckBox15.Checked=True Then
       Form1.ScanForIllegals(Username,False);


End;

Procedure Tform1.UserLeft(UserName: String);
Begin
End;

Procedure Tform1.UserSpoke(UserName,MessageStr: String);
Var
 N: Integer;
 Friend: Boolean;
 BuildStr: String;
 obj: Tobject;
Begin
Friend:=False;
BuildStr:='';
If Form1.AutoReplytowb1.Checked=True Then
 Begin
  BuildStr:=LowerCaseRep('wb '+customizeName(LoggedInName));
//  If Friends.IndexOf(UserName)<>-1 Then
   If Friends.Find(Username,Obj)=True Then
   If PosRep(BuildStr,LowerCaseRep(MessageStr))>0 Then
      Form1.Say(Richedit1,'thanks '+CustomizeName(UserName),False,False,False)
End;

If Form1.Replytothanks1.Checked=True Then
 Begin
   If Friends.Find(Username,Obj)=True Then
   Begin
     BuildStr:=LowerCaseRep(customizeName(LoggedInName));
   If PosRep('hi '+BuildStr,LowerCaseRep(MessageStr))>0 Then
       Form1.Say(Richedit1,'hey '+CustomizeName(UserName),False,False,False);
   If PosRep('hey '+BuildStr,LowerCaseRep(MessageStr))>0 Then
       Form1.Say(Richedit1,'hey '+CustomizeName(UserName),False,False,False);
   If PosRep('hello '+BuildStr,LowerCaseRep(MessageStr))>0 Then
       Form1.Say(Richedit1,'hey '+CustomizeName(UserName),False,False,False);
   End;
 End;


  //add buddy
End;


Procedure F6Key;
Begin
 If Form20.Edit1.Text<>'' Then
  Begin
   Form1.SendText(Form1.JoinRoom(Loggedinname,Form20.Edit1.Text));
   Form1.Panel10.Caption:='Attempting to join: '+Form20.Edit1.Text;
  End;
End;



Procedure F7Key;
Begin
 If Form20.Edit2.Text<>'' Then
  Begin
//     Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
   Form1.SendText(Form1.JoinRoom(Loggedinname,Form20.Edit2.Text));
   Form1.Panel10.Caption:='Attempting to join: '+Form20.Edit2.Text;
  End;
End;

Procedure F8Key;
Begin
 If Form20.Edit3.Text<>'' Then
  Begin
//   Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
   Form1.SendText(Form1.JoinRoom(Loggedinname,Form20.Edit3.Text));
   Form1.Panel10.Caption:='Attempting to join: '+Form20.Edit3.Text;
  End;
End;

Procedure F9Key;
Begin
 If Form20.Edit4.Text<>'' Then
  Begin
//     Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
   Form1.SendText(Form1.JoinRoom(Loggedinname,Form20.Edit4.Text));
   Form1.Panel10.Caption:='Attempting to join: '+Form20.Edit4.Text;
  End;
End;

Procedure F11Key;
Begin
 If InviteRoom<>'' Then
    Form1.SendText(Form1.JoinRoom(Loggedinname,InviteRoom));
  InviteRoom:='';
End;

Procedure Tform1.VoiceLockProc;
Begin
 Form1.Button9.OnClick(Nil);
End;

Procedure F10Key;
Var
 N: Integer;
Begin
 If Form1.Visible=True Then
  Begin
   Form1.Visible:=False;
   ShowWindow(Application.Handle, SW_HIDE);
   Form1.spTrayIcon1.IconVisible:=False;
  End
    Else
  Begin
   Form1.Visible:=True;
   ShowWindow(Application.Handle, SW_Show);
   Form1.spTrayIcon1.IconVisible:=Form10.CheckBox49.Checked;
  End;
End;


procedure TForm1.WMHotKey(var Msg: TWMHotKey);
begin
 case MSG.HotKey of
    F6_HotKey: F6Key;
    F7_HotKey: F7Key;
    F8_HotKey: F8Key;
    F9_HotKey: F9Key;
    F10_HotKey: F10Key;
    F11_HotKey: F11Key;
   End;
End;

Function Tform1.WinampHandle: Hwnd;
 var
  wnd: hwnd;
  i1 : integer;
  s1,s2 : string;
begin
 wnd:=findwindow('winamp',nil);
 If Wnd=0 Then
   wnd:=findwindow('winamp v1.x',nil);
 If Wnd=0 Then
   wnd:=findwindow('STUDIO',nil);
 Result:=Wnd;
End;


Procedure Tform1.DoStatsUserLeave(S: String);
var
 ListItem: TListItem;
 N,N2,R: Integer;
begin
// Form31.ListView1.Clear;
// For N:=1 to users Do
//  Begin
//If Form31.Visible=False Then Exit;
If Trim(S)='' Then
 Begin
  S:=S;
  Exit;
 End;
 N:=Form1.ChatterNum(S);
R:=-1;
 For N2:=Form31.ListView1.Items.Count-1 downto 0 do
  Begin
    ListItem:=Form31.ListView1.Items[N2];
    If ListItem<>Nil Then
     Begin
        If ListItem.Caption=S Then
         Begin
           R:=N2;
           Break;
         End;
     End;
  End;
  If R<>-1 Then
   Begin
    ListItem.Delete;
   End;
End;

Procedure Tform1.DoStats(S: String);
var
 ListItem: TListItem;
 Year,Year2,Month,Day: Word;
 N,N2,R: Integer;
begin
// Form31.ListView1.Clear;
// For N:=1 to users Do
//  Begin
//If Form31.Visible=False Then Exit;
//If Form31.Visible=False Then Exit;

DecodeDate(Now,Year,Month,Day);
If Trim(S)='' Then
 Begin
  S:=S;
  Exit;
 End;
 N:=Form1.ChatterNum(S);
R:=-1;
 For N2:=Form31.ListView1.Items.Count-1 downto 0 do
  Begin
    ListItem:=Form31.ListView1.Items[N2];
    If ListItem<>Nil Then
     Begin
        If LowerCaseRep(ListItem.Caption)=LowerCaseRep(S) Then
         Begin
           R:=N2;
           Break;
         End;
     End;
  End;
  If R<>-1 Then
   Begin
    ListItem := Form31.ListView1.Items[R];
    ListItem.SubItems.Clear;
    ListItem.Caption:=Chatters[N].UserName;
    ListItem.SubItems.Add(Chatters[N].Nick);
    ListItem.SubItems.Add(IntToStr(Chatters[N].TotalBlock));
    ListItem.SubItems.Add(IntToStr(Chatters[N].NumLinesPosted));
    ListItem.SubItems.Add(Chatters[N].ChatClient);
    ListItem.SubItems.Add(Chatters[N].Age);
    ListItem.SubItems.Add(Chatters[N].Location);
    ListItem.SubItems.Add(UserGender(Chatters[N].Extra));
    DecodeDate(Chatters[N].LocalTime,Year2,Month,Day);
    If (Year2=Year) Or (Year2+1=Year) or (Year2-1=Year) Then
       ListItem.SubItems.Add(DateTimeToStr((Chatters[N].LocalTime)));
   End
    else
   Begin
    ListItem := Form31.ListView1.Items.Add;
    ListItem.Caption:=Chatters[N].UserName;
    ListItem.SubItems.Add(Chatters[N].Nick);
    ListItem.SubItems.Add(IntToStr(Chatters[N].TotalBlock));
    ListItem.SubItems.Add(IntToStr(Chatters[N].NumLinesPosted));
    ListItem.SubItems.Add(Chatters[N].ChatClient);
    ListItem.SubItems.Add(Chatters[N].Age);
    ListItem.SubItems.Add(Chatters[N].Location);
    ListItem.SubItems.Add(UserGender(Chatters[N].Extra));
    DecodeDate(Chatters[N].LocalTime,Year2,Month,Day);
    If (Year2=Year) Or (Year2+1=Year) or (Year2-1=Year) Then
        ListItem.SubItems.Add(DateTimeToStr((Chatters[N].LocalTime)));
   End;
//  End;
{
 GlobalListItem ,LocalListItem: TlistItem;
 begin
 GlobalListItem := ListView2.Items[0];
 LocalListItem := ListView1.Items.Add;
 LocalListItem.Assign(GlobalListItem);
}

// ListItem := ListView1.Items.Add;
{ ListItem.Caption := 'Test!';
 ListItem.SubItems.Add('New Something!');
 ListItem.SubItems.Add('New Somethin2');}

// ListItem := ListView1.Items[0];
// ListItem.SubItems.Add('Uhm Testing!');
//  ListItem.Caption:='uhm?';
// ListItem.SubItems.Add('Something!');
// ListItem.SubItems.Add('Something ELse!');
// ListItem.Caption:='uhm?';
End;




function Tform1.instr(subs,searchstr: string; donde: integer): integer;
 var
   newstr: string;
begin
   newstr:=searchstr;
    If PosRep(Subs,NewStr)>0 Then
     Begin
      delete(newstr,1,donde);
      instr:=PosRep(subs,newstr)+donde-1
     End
    else
   Instr:=0;
end;

{procedure TForm1.AppMessage (var Msg: TMsg; var Handled: boolean);
Const
 WM_WSAASYNC = WM_USER + $0001;
begin
If Msg.message=WM_Char Then
 Msg:=Msg;
  if (Msg.Message = WM_WSAASYNC) then
   Begin
    //  Form1.Panel10.Caption:='Window Message: '+IntToStr(Msg.lParam);
{    If Msg.lParam=FD_Read Then
      If CalledAppProcess=True Then
        Handled := true;}
    // End;
//end;}
                  

{Procedure Tform1.MyProcessMessages(WindowHandle: Hwnd);
var Msg : TMsg;
    Msg2: Tmessage;
begin
 while PeekMessage(Msg, WindowHandle, 0, 0, PM_REMOVE ) do begin
 if  Msg.Message = 0 then
  begin // WM_QUIT
   PostQuitMessage(msg.wparam);
   Application.Terminate;
   Exit;
  end
else
 begin
//  TranslateMessage(Msg);
 // DispatchMessage(Msg);
//   DefWindowProc(WindowHandle, Msg.message, Msg.wParam, Msg.lParam);
 end;
end;
// Sleep(1);
end;}


{Procedure Tform1.MyApplicationProcess;
Const
 WM_WSAASYNC = WM_USER + $0001;
Var
 Wmsg: Tmsg;
begin
IF  PeekMessage(WMsg,Form1.Handle,0,0,PM_NOREMOVE)=True Then
 Begin
 //  GetMessage(Wmsg,Form1.Handle,0,0);
If WMsg.message=WM_Char Then
 WMsg:=WMsg;
  if (WMsg.Message = WM_CHAR) then
   Begin
    //  Form1.Panel10.Caption:='Window Message: '+IntToStr(Msg.lParam);
    If WMsg.WParam<>$0D Then
       Application.ProcessMEssages;
  End;
 End;
// Form1.Memo1.WindowProc(
End;}


{Procedure Tform1.MyApplicationProcess(wnd: Hwnd);
Var
 Wmsg: Tmessage;
Begin
IF  PeekMessage(WMsg,Form1.Handle,0,0,PM_NOREMOVE) Then
 Begin
   GetMessage(Wmsg,Form1.Handle,0,0);

 End;
// Form1.Memo1.WindowProc(Wmsg);
End;}



Function GetColStr(Str: String): String;
Var
 N,N2,P1,P2: Integer;
 Col,Tmp: String;
Begin
  Tmp:=Str;
  P1:=PosRep(#$1b+'[',Tmp);
  P2:=Form1.Instr('m',Tmp,p1);
  N:=Form1.ScanIt(#$1b+'[',Tmp);
//   While (P1>0) And (P2>0) Do
  For N2:=1 to N Do
    Begin
     P2:=Form1.Instr('m',Tmp,p1);
     Col:=Col+Copy(Tmp,P1,P2-P1+2);
     If (P1>0) and (P1<P2) and (P2>0) Then
       Delete(Tmp,P1,P2-P1+2);
     P1:=PosRep(#$1b+'[',Tmp);
     P2:=Form1.Instr('m',Tmp,p1);
    End;
  Result:=Col;
End;

Function Tform1.CryptPassword(S: String; Key: Integer): String;
Var
 N: Integer;
 I: Integer;
 BuildStr: String;
Begin
 For N:=1 to Length(S) do
  Begin
    I:=Ord(S[n]);
    I:=I+N+Key;
    BuildStr:=BuildStr+Chr(I);
  End;
   Result:=BuildStr;
End;

Function Tform1.DecryptPassword(S: String; Key: Integer): String;
Var
 N: Integer;
 I: Integer;
 BuildStr: String;
Begin
 For N:=1 to Length(S) do
  Begin
    I:=Ord(S[n]);
    I:=I-N-Key;
    BuildStr:=BuildStr+Chr(I);
  End;
 Result:=BuildStr;
End;


Function Tform1.ScrollText(sometext: String): String;
Var
 Tmp: String;
 Tmp_chr: Char;
 N,Len: Integer;
Begin
  tmp:=SomeText;
  len:=length(tmp);
  tmp_chr:=tmp[1];
  for n:=1 to len-1 do
     begin
        tmp[n]:=tmp[n+1];
     end;
   tmp[len]:=tmp_chr;
 Result:=Tmp;
End;


procedure TForm1.ScrollToEnd(display: TMyRichedit);
Var
  theWparam: Integer;
  ScrollInfo1: TScrollInfo;
begin
 ScrollInfo1.cbSize := SizeOf(TScrollInfo);
 ScrollInfo1.fMask := SIF_RANGE;
 GetScrollInfo(display.Handle,SB_VERT, ScrollInfo1);
 theWparam := MAKELONG(SB_THUMBPOSITION, ScrollInfo1.nMax);
 display.Perform(WM_VSCROLL,theWparam,0);
end;

procedure TForm1.ScrollMemo(display: TMemo);
Var
  theWparam: Integer;
  ScrollInfo1: TScrollInfo;
begin
 display.Perform(WM_VSCROLL,theWparam,0);
end;


{Function Tform1.insertbmp2(bmpnum: integer): Hbitmap;
 var
   pict: TBitMap;
begin
  Pict := TBitMap.Create;
  Form1.ImageList1.GetBitmap(bmpnum,Pict);
  Result:=Pict.Handle;
 // Form1.Richedit1.InsertPictureBmp(Hbitmap(Pict));
  Pict.Free;
end;}

function Tform1.instr2(start: integer; ToSearch,ToFind: string): integer;
begin
 if start>1 then
   Delete(ToSearch,1,start-1);
 result:=PosRep(ToFind,ToSearch);
 if (result>0) and (start>1) then
   inc(result,start);
end;


function Tform1.HowAlike(s1,s2:string):Integer;
var l1,l2,pass,position,size,foundpos,maxscore:integer;
    score,scored,string1pos,string2pos,bestmatchpos:single;
    swapstring,searchblock:string;
begin
 s1:=Uppercase(trim(s1));
 s2:=Uppercase(trim(s2));
 score:=0;
 maxscore:=0;
 scored:=0;
 //deal with zero length strings...
 if (s1='') and (s2='') then
   begin
    result:=1;
    exit;
   end
 else
 if (s1='') or (s2='') then
    begin
     result:=0;
     exit;
    end;
  //why perform any mathematics is the result is clear?
   if s1=s2 then
    begin
     result:=1;
     exit;
   end;
   //make two passes,
   //     with s1 and s2 each way round to ensure
   //     consistent results
   for pass:=1 to 2 do
     begin
      l1:=length(s1);
      l2:=length(s2);
       for size:=l1 downto 1 do
        begin
         for position:=1 to (l1-size+1) do
           begin
      //try to find implied block in the other string
      //Big blocks score much better than small blocks
            searchblock:=copy(s1,position,size);
            foundpos:=PosRep(searchblock,s2);
            if size=l1 then
                string1pos:=0.5
              else
                string1pos:=(position-1)/(l1-size);
           if foundpos>0 then
              begin
      //the string is in somewhere in there
     //    - find the 'closest' one.
              bestmatchpos:=-100; //won't find anything that far away!
              repeat
              if size=l2 then
              string2pos:=0.5
            else
              string2pos:=(foundpos-1)/(l2-size);
       //If this closer than the previous best?
            if abs(string2pos-string1pos)<abs(bestmatchpos-string1pos) then
            bestmatchpos:=string2pos;
            foundpos:=instr2(foundpos+1,s2,searchblock);
            until foundpos=0; //loop while foundpos>0..
        //The closest position is now known: Score it!
       //Score as follows: (1-distance of best match)
       score:=score+(1-abs(string1pos-bestmatchpos));
     end;
   //Keep track if the maximum possible score
  //BE CAREFUL IF CHANGING THIS FUNCTION!!!
 //maxscore:=maxscore+1;
    inc(maxscore);
    end; //for position..
   end; //for size..
  if pass=1 then
  begin
  //swap the strings around
   swapstring:=s1;
   s1:=s2;
   s2:=swapstring;
  end;
//Each pass is weighted equally
   scored:=scored+(0.5*(score/maxscore));
   score:=0;
   maxscore:=0;
 end; //for pass..
//HowAlike=score/maxscore
 result:=Trunc(scored*100);
end;


function Tform1.GetCPUSpeed: Double;
const 
  DelayTime = 500; 
var 
  TimerHi, TimerLo: DWORD; 
  PriorityClass, Priority: Integer; 
begin 
  PriorityClass := GetPriorityClass(GetCurrentProcess); 
  Priority      := GetThreadPriority(GetCurrentThread);

  SetPriorityClass(GetCurrentProcess, REALTIME_PRIORITY_CLASS); 
  SetThreadPriority(GetCurrentThread, THREAD_PRIORITY_TIME_CRITICAL); 

  Sleep(10); 
  asm 
    dw 310Fh 
    mov TimerLo, eax 
    mov TimerHi, edx 
  end; 
  Sleep(DelayTime); 
  asm
    dw 310Fh 
    sub eax, TimerLo 
    sbb edx, TimerHi 
    mov TimerLo, eax 
    mov TimerHi, edx 
  end; 

  SetThreadPriority(GetCurrentThread, Priority);
  SetPriorityClass(GetCurrentProcess, PriorityClass); 

  Result := TimerLo / (1000 * DelayTime);
end;


Function TForm1.ValidFileName(FN: String): Boolean;
Var
 Ok,N: Integer;
Begin
 Result:=False;
 IF (Length(FN)<30) and (Length(FN)>0) Then Result:=True;
 If Result=True Then
  Begin
   OK:=0;
   For N:=1 to Length(FN) Do
     If Fn[N] in ['a'..'z','A'..'Z','0'..'9','.','!','$','-','_','(',')','+','~','&','[',']'] Then
       Inc(OK);
     If OK<>Length(FN) Then
      Result:=False;
  End;
End;

Function DealWithAvaInfo(Ava,FromWho: String): String;
Var
 AvaName,AvaType: String;
Begin
{CH\avaname   ( http://www.chat-help.co.uk/~ymlite/identitar_pgg/avas/avaname.jpg )
CC\avaname    ( http://avatars.cheetachat.com/avatar/avaname.jpg )}
 If PosRep('\',Ava)>0 Then
  Begin
   AvaType:=LowerCaseRep(Copy(Ava,1,PosRep('\',Ava)-1));
   Delete(Ava,1,Length(AvaType)+1);
   AvaName:=LowerCaseRep(Ava);
  End
   else
  Exit;

If Length(Avaname)<2 Then
 Exit;

 If AvaType='ch' Then
  Begin
   If Form1.ValidFileName(AvaName) Then
     If (FileExists(Path+'identitar\'+LowerCaseRep(AvaName)+'.jpg')=False) and (FileExists(Path+'identitar\'+AvaName+'.bmp.$$$')=False) Then
        TIdentitarDownload.Create(AvaName+'.jpg',Nil);

{    If Form1.EnableAnimations1.Checked=True Then
     If (FileExists(Path+'identitar\'+LowerCaseRep(AvaName)+'.gif')=False) and (FileExists(Path+'identitar\'+AvaName+'.gif.$$$')=False) Then
        TIdentitarDownload.Create(AvaName+'.gif',Nil);}

     Chatters[form1.ChatterNum(FromWho)].Ident:='CH\'+AvaName;
     Result:=AvaName;
   End;

 If AvaType='cc' Then
  Begin
     If Form1.ValidFileName(AvaName) Then
     If (FileExists(Path+'cheeta_avs\'+AvaName+'.jpg')=False) and (FileExists(Path+'cheeta_avs\'+AvaName+'.jpg.$$$')=False) Then
       TcheetaDownload.Create(AvaName);
     Chatters[form1.ChatterNum(FromWho)].Ident:='CC\'+AvaName;
    Result:=AvaName;
   End;

end;

Procedure Tform1.InfHandler(Msg,FromWho: String);
Var
 ID: String;
 IDStr: String;
 CNum: Integer;
 Dv: Dword;
 T: TEncrypt;
Begin
 ID:=Trim(Copy(Msg,1,PosRep(':',Msg)-1));
 Delete(Msg,1,Length(ID)+1);
 IDStr:=Trim(Msg);
 If IdStr='' Then Exit;
 If ID='' Then Exit;

//<font INF ID:JAM VER:5.1.9 AVA:jam SUM:a3129eff>

 CNum:=Form1.ChatterNum(FromWho);
 If Id='id' Then
  Begin
   If IdStr<>'' Then
    Chatters[Cnum].ChatClient:=IdStr;
   IdStr:=LowerCaseRep(IdStr);
   If IdStr='ymlite' Then Chatters[Cnum].ChatClient:='Y!mLite';
   If Copy(IdStr,1,2)='yz' Then Chatters[Cnum].ChatClient:='Yazak Chat';
   If IdStr='yhlt' Then Chatters[Cnum].ChatClient:='YahElite';
   If IdStr='yhlt ~' Then Chatters[Cnum].ChatClient:='YahElite';
   If IdStr='jam' Then Chatters[Cnum].ChatClient:='JAM';
   Chatters[Cnum].CustomData:=Chatters[Cnum].CustomData+'Chat Client '+Chatters[Cnum].ChatClient+CrLf;
   Exit;
  End;

 If Id='ver' Then
  Begin
   Chatters[Cnum].CustomData:=Chatters[Cnum].CustomData+'Client Ver '+IdStr+CrLf;
   Chatters[Cnum].Version:=IDStr;
   Exit;
  End;

  If Id='station' Then
    Begin
     T:=TEncrypt.Create;
     If (Pos('http',LowerCaseRep(IdStr))>0) Or (Pos('www.',LowerCaseRep(idstr))>0) Then
        Chatters[Cnum].Station:=IDStr
         else
        Chatters[Cnum].Station:=T.DecryptStr(IDStr);
     Chatters[Cnum].CustomData:=Chatters[Cnum].CustomData+'Y!mLite Radio Stream '+Chatters[Cnum].Station+CrLf;
     T.Free;
     Exit;
    End;

 If Id='prot' Then
  Begin
   Chatters[Cnum].CustomData:=Chatters[Cnum].CustomData+'Protocol  '+IdStr+CrLf;
   Chatters[Cnum].Proto:=IDStr;
   Exit;
  End;

 If Id='ava' Then
  Begin
   If IdStr='' Then Exit;
   Chatters[Cnum].CustomData:=Chatters[Cnum].CustomData+'Avatar '+IdStr+CrLf;
   DealWithAvaInfo(IdStr,FromWho);
   Chatters[Cnum].Ident:=IDStr;
   Exit;
  End;

 If Id='sum' Then
  Begin
   Chatters[Cnum].CustomData:=Chatters[Cnum].CustomData+ID+' = '+IdStr+CrLf;
   Chatters[Cnum].CheckSum:=IDStr;
   Exit;
  End;

 Try
   If Id='ltime' Then
    Begin
     Chatters[Cnum].CustomData:=Chatters[Cnum].CustomData+'Time '+TimeToStr(StrToFloat(IDStr))+CrLf;
     Chatters[Cnum].LocalTime:=StrToFloat(IDStr);
     Exit;
    End;
  Except
 End;

 Try
 If (Id='lp')  Then
  Begin
   Chatters[Cnum].CustomData:=Chatters[Cnum].CustomData+'Posts Made '+IdStr+CrLf;
   Chatters[Cnum].YLinePost:=StrToInt(IDStr);
   Exit;
  End;
  Except
 End;


 If Id='nick' Then
  Begin
   Chatters[Cnum].CustomData:=Chatters[Cnum].CustomData+'NickName '+IdStr+CrLf;
   Chatters[Cnum].Nick:=IDStr;
   Exit;
  End;

 { If Id='uc' Then
  Begin
   If Chatters[Cnum].UcaseUsed=True Then Exit;
   Chatters[Cnum].CustomData:=Chatters[Cnum].CustomData+'Ucase '+IdStr+CrLf;
   Try
     Dv:=StrToInt('$'+IdStr);
     Chatters[Cnum].UcaseV:=DV;
     Chatters[Cnum].UcaseUsed:=True;
    Except
   End;
   Exit;
  End;}

 If Id='idc' Then
  Begin
   Chatters[Cnum].CustomData:=Chatters[Cnum].CustomData+'ID Color  '+IdStr+CrLf;
   Chatters[Cnum].ColIDStr:=IDStr;
   Exit;
  End;

 Try
 If (Id='igs')  Then
  Begin
   Chatters[Cnum].CustomData:=Chatters[Cnum].CustomData+'Total Ignores '+IdStr+CrLf;
   Chatters[Cnum].Iggies:=StrToInt(IDStr);
   Exit;
  End;
  Except
 End;


  Chatters[Cnum].CustomData:=Chatters[Cnum].CustomData+ID+'* '+IdStr+CrLf;
//  Chatters[Cnum].CustomData:=Chatters[Cnum].CustomData+'* Denote Unknown Data';
//If Id='id' Then Chatters[Cnum].ChatClient:=IDStr;

End;

Function TForm1.DoInfTag(Msg,FromWho: String): String;
Var
 N: Integer;
 Tmp,Tmp2: String;
Begin
Result:=Msg;

If PosRep('<font inf',LowerCaseRep(Msg))=0 Then
  Exit;

 Tmp:=Form1.ExtractBetweenString('<font INF','>',Msg,True);
 For N:=1 to ScanIt(' ',Tmp) do
  Begin
   Tmp2:=Copy(Tmp,1,PosRep(' ',Tmp)-1);
   Delete(Tmp,1,Length(Tmp2)+1);
   Form1.InfHandler(LowerCaseRep(Tmp2),FromWho);
//   Form1.Richedit1.Lines.Add(Tmp2);
  End;
  Tmp2:=Tmp;
  Form1.InfHandler(LowerCaseRep(Tmp2),FromWho);
//  Form1.Richedit1.Lines.Add(Tmp2);

 Msg:=Form1.Remove2(Msg,'<font INF','>');
 Result:=Msg;

//   <font INF ID:JAM VER:5.1.9 AVA:jam SUM:a3129eff>

end;

Function Tform1.DoIdTag(Msg,FromWho: String): String;
 Var
  Avatar,Client,Tmp,Tmp2,ExtraInfo: String;
  N: Integer;
Begin

 Result:=Msg;

If (PosRep('<',Msg)=0) And (PosRep('>',Msg)=0) Then
  Exit;

  If PosRep('<font YmLite',Msg)>0 Then
    Begin
      ExtraInfo:=Form1.ExtractBetweenString('<font YmLite','>',Msg,True);
      Chatters[ChatterNum(FromWho)].Ident:='CH\'+LowerCaseRep(ExtraInfo);
        If (Trim(ExtraInfo)<>'')  And (Form1.On1.Checked) Then
         Begin
          If ValidFileName(ExtraInfo) Then
           If (FileExists(Path+'identitar\'+LowerCaseRep(ExtraInfo)+'.bmp')=False) and (FileExists(Path+'identitar\'+ExtraInfo+'.bmp.$$$')=False) Then
              TIdentitarDownload.Create(ExtraInfo+'.bmp',Nil);
         End;
      Msg:=Form1.Remove2(Msg,'<font YmLite','>');
      Chatters[form1.ChatterNum(FromWho)].ChatClient:='Y!mLite';
      Result:=Msg;
    End;


    If (PosRep('<font YahEh',Msg)>0) Then
    Begin
      ExtraInfo:=Form1.ExtractBetweenString('<font YahEh','>',Msg,True);
      Msg:=Form1.Remove2(Msg,'<font YahEh','>');
      Chatters[ChatterNum(FromWho)].ExtendedInfo:=ExtraInfo;
      Chatters[form1.ChatterNum(FromWho)].ChatClient:='YahEh';
      Result:=Msg;
    End;


 If PosRep('<font tm',LowerCaseRep(Msg))>0 Then
  Begin
   ExtraInfo:=Form1.ExtractBetweenString('<font tm','>',Msg,True);
   Chatters[ChatterNum(FromWho)].ExtendedInfo:=ExtraInfo;
   Msg:=Form1.Remove2(Msg,'<font tm','>');
  End;

   If PosRep('<font ltime',Msg)>0 Then
    Begin
      ExtraInfo:=Form1.ExtractBetweenString('<font ltime','>',Msg,True);
//      If PosRep('<font YmLite',Msg)>0 Then
      Try
        Chatters[ChatterNum(FromWho)].LocalTime:=StrToFloat(ExtraInfo);
         Except
      End;
      Msg:=Form1.Remove2(Msg,'<font ltime','>');
      Result:=Msg;
    End;

   If PosRep('<font line',Msg)>0 Then
    Begin
      ExtraInfo:=Form1.ExtractBetweenString('<font line#','>',Msg,True);
      Try
        Chatters[ChatterNum(FromWho)].YLinePost:=StrToInt(ExtraInfo);
         Except
      End;
      Msg:=Form1.Remove2(Msg,'<font line','>');
      Result:=Msg;
    End;


    If PosRep('<font YHLT',Msg)>0 Then
    Begin
      ExtraInfo:=Form1.ExtractBetweenString('<font YHLT','>',Msg,True);
      Chatters[ChatterNum(FromWho)].ExtendedInfo:=ExtraInfo;
      Msg:=Form1.Remove2(Msg,'<font YHLT','>');
      Chatters[form1.ChatterNum(FromWho)].ChatClient:='YahElite';
      Result:=Msg;
    End;


    If (PosRep('<font Yzak',Msg)>0) or (PosRep('<font Yza',Msg)>0) Then
    Begin
      Msg:=Form1.Remove2(Msg,'<font Yzak','>');
      Msg:=Form1.Remove2(Msg,'<font Yza','>');
      Chatters[form1.ChatterNum(FromWho)].ChatClient:='Yazak Chat';
      Result:=Msg;
    End;



   If (PosRep('<font yimg',Msg)>0) Then
    Begin
      ExtraInfo:=Form1.ExtractBetweenString('<font yimg','>',Msg,True);
      If Trim(ExtraInfo)<>'' Then
        Chatters[ChatterNum(FromWho)].ExtendedInfo:=ExtraInfo;
      Msg:=Form1.Remove2(Msg,'<font yimg','>');
      Chatters[form1.ChatterNum(FromWho)].ChatClient:='Y!Tunnel';
      Result:=Msg;
    End;

   If PosRep('<font ext',Msg)>0 Then
    Begin
      Avatar:=''; ExtraInfo:='';
      ExtraInfo:=Form1.ExtractBetweenString('<font ext','>',Msg,True);
      Chatters[ChatterNum(FromWho)].ExtendedInfo:=ExtraInfo;
      Msg:=Form1.Remove2(Msg,'<font ext','>');
      Chatters[form1.ChatterNum(FromWho)].ChatClient:='Cheeta Chat';
      Avatar:=ExtraInfo;
      Delete(Avatar,1,PosRep(';',Avatar));
      If PosRep(';',Avatar)>0 Then
        Avatar:=Copy(Avatar,1,PosRep(';',avatar)-1);
       If (Trim(Avatar)<>'') And (Form1.On1.Checked) Then
         Begin
          If ValidFileName(Avatar) Then
           If (FileExists(Path+'cheeta_avs\'+Avatar+'.jpg')=False) and (FileExists(Path+'cheeta_avs\'+Avatar+'.jpg.$$$')=False) Then
              TcheetaDownload.Create(Avatar);
           Chatters[form1.ChatterNum(FromWho)].Ident:='CC\'+Avatar;
         End;
       Result:=Msg;
    End;


{    If PosRep('<ALT ID=YmLite',Msg)>0 Then
    Begin
      ExtraInfo:=Form1.ExtractBetweenString('<ALT ID=YmLite','>',Msg,True);
      Chatters[ChatterNum(FromWho)].Identitar:=ExtraInfo;
      Msg:=Form1.Remove2(Msg,'<ALT ID=YmLite','>');
      Chatters[form1.ChatterNum(FromWho)].ChatClient:='Y!mLite';
      Result:=Msg;
      Exit;
    End;}

   Msg:=DoInfTag(Msg,FromWho);
   If  Chatters[Form1.ChatterNum(FromWho)].CustomData<>'' Then
     Chatters[Form1.ChatterNum(FromWho)].CustomData:='ID '+FromWho+CrLf+Chatters[Form1.ChatterNum(FromWho)].CustomData;

  Tmp:=Msg;
  Tmp2:=LowerCaseRep(Tmp2);
  Tmp2:=Form1.ExtractBetweenString('<font','>',LowerCaseRep(Tmp),True);
   For N:=1 to Form1.ScanIT('<font',LowerCaseRep(Tmp)) Do
   Begin
    If Form1.ScanIt('<font',LowerCaseRep(tmp))>=2 Then
     Begin
      Delete(Tmp,1,PosRep('<font '+Tmp2,LowerCaseRep(tmp))+Length('<font '+tmp2));
      Tmp2:=Form1.ExtractBetweenString('<font','>',LowerCaseRep(Tmp),True);
     End;
   If (PosRep('"',Tmp2)=0) and (PosRep('face',Tmp2)=0) and (PosRep('size',LowerCaseRep(Tmp2))=0) and (PosRep('color',LowerCaseRep(Tmp2))=0) Then
    Begin
      ExtraInfo:=Tmp2;
      If PosRep(' ',Tmp2)>0 Then
        Client:=Copy(Tmp2,1,PosRep(' ',Tmp2)-1)
         else
        Client:=Tmp2;
      If PosRep(' ',Tmp2)>0 Then
        Begin
         Delete(Tmp2,1,PosRep(' ',Tmp2));
         ExtraInfo:=Tmp2;
        End
          else
         ExtraInfo:='';
      Chatters[ChatterNum(FromWho)].ExtendedInfo:=ExtraInfo;
      Chatters[form1.ChatterNum(FromWho)].ChatClient:=Client;
      Msg:=Form1.Remove2(Msg,'<font '+client,'>');
    End;
  End;

  Result:=Msg;
End;

Function RemoveDoubleSpaces(S: String): String;
Begin
  While PosRep('  ',S)>0 do
   Delete(S,PosRep('  ',S),1);
  Result:=S;
End;

Procedure ExtractDetails(Chatter: String);
Var
 BuildStr,Tmp: String;
 N: Integer;
Begin
  Form1.CreateSkin(Form23);
  Form23.Memo1.Clear;
  Form23.Show;
  Chatter:=Trim(Chatter);
  N:=0;
// For N:=0 to Form1.Richedit1.Lines.Count-1 do
 While N<Form1.Richedit1.Lines.Count-1 do
  Begin
    BuildStr:='';
    Inc(N);
    Tmp:=Form1.Richedit1.Lines[n];
    If Copy(Tmp,1,1)='Æ' Then
      Delete(Tmp,1,2);
   If Copy(Tmp,1,1)=' ' Then
      Delete(Tmp,1,2);
    Chatter:=LowerCaseRep(Chatter);
    If (LowerCaseRep(Chatter)=Copy(LowerCaseRep(Tmp),1,PosRep(':',Tmp)-1)) or ((LowerCaseRep(Chatter)=Copy(LowerCaseRep(Tmp),1,PosRep('*:',Tmp)-1))) or ((LowerCaseRep(Chatter)=Copy(LowerCaseRep(Tmp),1,PosRep(' ',Tmp)-1))) or ((LowerCaseRep(Chatter)=Copy(LowerCaseRep(Tmp),1,PosRep('*',Tmp)-1))) Then
     Begin
      BuildStr:=Tmp;
      While PosRep(#$0d,Tmp)=0 do
       Begin
        Inc(N);
        Tmp:=Form1.Richedit1.Lines[n];
        BuildStr:=BuildStr+Tmp;
       End;
     End;
      If Trim(BuildStr)<>'' Then
        Form23.Memo1.Lines.Add(BuildStr);
   End;
  //Until N=Form1.Richedit1.Lines.Count-1;
End;

Procedure TForm1.MySelText(RichHand: Thandle;S: String);
begin
//  Form1.Richedit1.SelAttributes.Color:=ClRed;
  SendMessage(RichHand, WM_SETTEXT, 0 , LongInt(PChar(s)));
End;

function CoolJansText(sentence2: string): string;
 var
  Sentence,HC,BuildStr: String;
  N,N2: Integer;
begin
 BuildStr:='';
  For N:=1 to Length(Sentence2) DO
   Case Random(2)+1 Of
     1: BuildStr:=BuildStr+Sentence2[n];
     2: buildStr:=BuildStr+UpCase(Sentence2[N]);
    End;
 Result:=BuildStr;
End;

function HackersCode(sentence2: string): string;
 var
  Sentence,HC,BuildStr: String;
  N,N2: Integer;
begin
 BuildStr:='';
 Sentence:=LowerCaseRep(Sentence2);
 For N:=1 to Length(Sentence) do
   Begin
     For N2:=Hd.Count-1 downto 0 do
       Begin
         Hc:=Hd.Strings[N2];
         HC:=LowerCaseRep(HC);
          If Sentence[n]=Hc[1] then
            BuildStr:=BuildStr+copy(Hc,2,length(hc));
       End;
        if Sentence[n]=' ' then
          BuildStr:=BuildStr+' ';
   End;
 HackersCode:=buildstr;
end;


Function RemoveSpaces(S: String): String;
Var
  I: Integer;
  BS: String;
Begin
 For I:=1 To Length(S) DO
   If S[I]<>' ' Then
     BS:=BS+S[i];
  Result:=BS;
End;


Function RemoveChar(S: String; C: Char): String;
Var
  I: Integer;
  BS: String;
Begin
 For I:=1 To Length(S) DO
   If S[I]<>C Then
     BS:=BS+S[i];
  Result:=BS;
End;

Function Tform1.Toc080(S: String): String;
Begin
 Result:=Copy(S,1,PosRep(Chr($c0)+Chr($80),S)-1);
End;


Function Tform1.To01(S: String): String;
Begin
 Result:=Copy(S,1,PosRep(Chr($01),S)-1);
End;


Function TForm1.Cut01(S: String;N: Integer): String;
Var
 I: Integer;
 Tmp: String;
Begin
 Tmp:=S;
For I:=1 to N Do
  Delete(Tmp,1,PosRep(#$01,Tmp)+1);
 Result:=Tmp;
End;


Function TForm1.CutC080(S: String;N: Integer): String;
Var
 I: Integer;
 Tmp: String;
Begin
 Tmp:=S;
For I:=1 to N Do
  Delete(Tmp,1,PosRep(#$C0+#$80,Tmp)+1);
 Result:=Tmp;
End;

Function ToDelimiterSPRT(S: String): String;
Begin
 Result:=Copy(S,1,PosRep(Delim,S)-1);
End;

Function CutToDelimiterSPRT(S: String;N: Integer): String;
Var
 I: Integer;
 Tmp: String;
Begin
 Tmp:=S;
For I:=1 to N Do
  Delete(Tmp,1,PosRep(Delim,Tmp)+1);
 Result:=Tmp;
End;


{Function Tform1.ExtractPacketDetailsSprt(S,PacketT: String): String;
Var
 Code,Tmp2: String;
Begin
 Tmp2:=S;
 Result:='';
 While Form1.ScanIt(Delim,Tmp2)>0 do
  Begin
   If Copy(Tmp2,1,3)=Copy(Tmp2,4,3) Then
     Delete(Tmp2,1,3);
   Tmp2:=CutToDelimiterSprt(Tmp2,1);
   Code:=toDelimiterSprt(Tmp2);
    If Code=PacketT Then
      Begin
        Tmp2:=CutToDelimiterSprt(Tmp2,1);
        If PosRep(Delim,Tmp2)>0 Then
         Result:=ToDelimiterSprt(Tmp2)
         else
        Result:=Tmp2;
       Break;
      End;
  End;
End;}


{Function Tform1.ExtractPacketDetailsSprt(S,PacketT: String): String;
Var
 Code,Tmp2: String;
Begin
 Tmp2:=S;
 Result:='';
 While Form1.ScanIt(Delim,Tmp2)>0 do
  Begin
   If Copy(Tmp2,1,3)=Copy(Tmp2,4,3) Then
     Delete(Tmp2,1,3);
   Tmp2:=CutToDelimiterSprt(Tmp2,1);
   Code:=toDelimiterSprt(Tmp2);
    If Code=PacketT Then
      Begin
        Tmp2:=CutToDelimiterSprt(Tmp2,1);
        If PosRep(Delim,Tmp2)>0 Then
         Result:=ToDelimiterSprt(Tmp2)
         else
        Result:=Tmp2;
       Break;
      End;
  End;
End;}


Function Tform1.ExtractPacketDetailsSprt(S,PacketT: String): String;
Var
 PacketStr,Code,Tmp2: String;
 P1: Integer;
Begin
 Tmp2:=S;
 Result:='';
 PacketStr:=Delim+PacketT;
 P1:=PosRep(PacketStr,Tmp2);
 If P1=0 Then
   Exit;
 Delete(Tmp2,1,P1+Length(PacketStr)+1);
 If PosRep(Delim,Tmp2)>0 Then
   Result:=ToDelimiterSprt(Tmp2)
    else
   Result:=Tmp2;
End;


Function Tform1.IsRunningNT: Boolean;
Begin
Result:=False;
 if GetVersion and $80000000 = 0 then
    Result:=True;
End;

Procedure Tform1.ReleaseMemory;
Begin
If Form1.IsRunningNT Then
  SetProcessWorkingSetSize(GetCurrentProcess,$ffffffff,$ffffffff);
End;

Procedure UpdateStats(S: String);
Var
 Against: String;
 Ks,Diff: Integer;
Begin
 LPacketS:=LPacketS+Length(S);
 Inc(RecvK,Length(S));
 If (RecvK div 1024)>0 Then
 Begin
   IF Form1.BooterAlert=False Then
     Form1.Panel16.Caption:='Recv: '+InTToStr((RecvK div 1024))+'K BR:'+IntToStr(Form1.BootResist)
      else
      Begin
       Against:=IntToStr(Trunc(Form1.MaxDownloadSpeed));
       Ks:=Form1.AverageDataKS div 1024;
       Form1.Panel16.Caption:='Recv: '+InTToStr((RecvK div 1024))+'K '+IntToStr(Form1.AverageDataKS div 1024)+' k/s ('+Against+'k/s Max) BR:'+IntToStr(Form1.BootResist);
      End;
  End
   else
  Begin
   IF Form1.BooterAlert=False Then
     Form1.Panel16.Caption:='Recv: '+InTToStr((RecvK))+' Bytes BR:'+IntToStr(Form1.BootResist)
      else
     Form1.Panel16.Caption:='Recv: '+InTToStr((RecvK))+' Bytes '+IntToStr(Form1.AverageDataKS div 1024)+' k/s BR:'+IntToStr(Form1.BootResist);
  End;
   If Form1.BooterAlert=False Then
    Form1.Panel16.Caption:=Form1.Panel16.Caption+' ('+IntToStr(Form1.MsProcessTime)+')'+' Bp/s:'+IntToStr(Form1.AverageDataKS)
     else
   Form1.Panel16.Caption:=Form1.Panel16.Caption+' ('+IntToStr(Form1.MsProcessTime)+')';
End;

Function SplitWords(S: String): String;
Var
 Tmp,Tmp2: String;
Begin
Tmp2:=S;
If Length(Tmp2)>0 Then
 Tmp2:=Tmp2+' ';
If PosRep(' ',Tmp2)>0 Then
 Begin
 Tmp2:=S;
 Words.Clear;
  While PosRep(' ',Tmp2)>0 Do
   Begin
     Tmp:=Tmp2;
     Tmp:=Copy(tmp2,1,PosRep(' ',Tmp)-1);
     Words.Add(Tmp);
     Delete(Tmp2,1,Length(Tmp)+1);
   End;
  Words.Add(Trim(Tmp2));
 End;
End;




Function DidUserSwear(S: String): Boolean;
Var
  N: Integer;
Begin
  DidUserSwear:=False;
  For N:=1 to High(SwearWordList) Do
    If PosRep(LowerCaseRep(SwearWordList[N]),LowerCaseRep(S))>0 Then
       DidUserSwear:=True;
End;

Function Tform1.CheckFont(S: String): String;
Begin
 If Form1.spSkinFontComboBox1.Items.IndexOf(S)=-1 Then
   S:='Arial';
  Result:=S;
End;


Procedure Tform1.DoFace(RichCont: TMyRichedit;Str: String);
Var
 CharS: TFontcharSet;
 Fname: TFontName;
 TFS: TfontStyles;
 Fcol: Tcolor;
 Tmp: String;
 T: System.Text;
 SInfo: PSmileyInfo;
 P: Integer;
Begin
 //Path:='smileys\';
 //bottleneck

 If SmileyCount<Form10.SpinEdit7.Value Then
  Begin
   Inc(SmileyCount);
   TFS:=RichCont.SelAttributes.Style;
   Fname:=RichCont.SelAttributes.Name;
   CharS:=RichCont.SelAttributes.Charset;
   Fcol:=RichCont.SelAttributes.Color;
   If Smileys.Find(Str,TObject(Sinfo))=True Then
     DoRtfFace(RichCont,Sinfo.FileName);
{   If P<>-1 Then
    Begin
      Sinfo:=PSmileyInfo(Smileys.Objects[P]);
      DoRtfFace(RichCont,Sinfo.FileName);
    End;}
 Str:=LowerCaseRep(Str);
 FaceUsed:=True;

{  If Str=':)' Then
    Form1.DoRtfFace(RichCont,'1.');}

  RichCont.SelAttributes.Style:=Tfs;
  RichCont.SelAttributes.Color:=Fcol;
  RichCont.SelAttributes.Charset:=CharS;
  RichCont.SelAttributes.Name:=Fname;
 End
  else
  RichCont.SelText:=Str;
{Cow = 51 alien = 48  ZZZ = 82  Stop = 81
?mark = 83 clown = 88  ? cool = 108  ?
Angel = 78   ? monkey = 118   ?Straight = 154  :|}
End;

Function MirrorCode(S: String): String;
Var
 N: Integer;
 S2: String;
Begin
 For N:=Length(S) downto 0 do
   S2:=S2+S[N];
 Result:=S2;
End;


Procedure Tform1.JpgToBmpCheeta(FN: String);
 var
  Bmp : TBitmap;
  Jpg : TJpegImage;
begin
 Bmp:= TBitmap.Create;
 Jpg := TJpegImage.Create;
 If (GetFileSize(Path+'cheeta_avs\'+Fn+'.jpg')>300) and (FileExists(Path+'cheeta_avs\'+Fn+'.jpg')) and (FileExists(Path+'cheeta_avs\'+Fn+'.jpg.$$$')=False) Then
  Begin
  Jpg.LoadFromFile(Path+'cheeta_avs\'+Fn+'.jpg');
  Bmp.Assign(Jpg);
  Bmp.SaveToFile(Path+'cheeta_avs\'+Fn+'.bmp');
 End;
 Bmp.free;
 Jpg.Free;
End;



function EditStreamInCallback(dwCookie: Longint; pbBuff: PByte;
   cb: Longint; var pcb: Longint): DWORD; stdcall;
var
 theStream: TStream;
 dataAvail: LongInt;
begin
theStream := TStream(dwCookie);
 with theStream do
begin
 dataAvail := Size - Position;
  Result := 0;
 if dataAvail <= cb then
  begin
    pcb := read(pbBuff^, dataAvail);
    if pcb <> dataAvail then
    Result := UINT(E_FAIL);
   end
else
  begin
   pcb := read(pbBuff^, cb);
    if pcb <> cb then
     Result := UINT(E_FAIL);
   end;
 end;
end;

procedure PutRTFSelection(RichEdit: TCustomRichedit; SourceStream: TStream);
 var
EditStream: TEditStream;
begin
with EditStream do
 begin
  dwCookie := Longint(SourceStream);
  dwError := 0;
  pfnCallback := EditStreamInCallBack;
 end;
RichEdit.Perform(EM_STREAMIN, SF_RTF or SFF_SELECTION, Longint(@EditStream));
end;

Procedure Tform1.AddNewSmiley(str,fn: String);
Var
 T: System.Text;
Begin
If FileExists(Path+'rtfimages\smileyref.txt') Then
 Begin
  System.Assign(T,Path+'rtfimages\smileyref.txt');
  System.Append(T);
  Writeln(T,Str+' '+Fn);
  System.Close(T);
 End; 
End;

Procedure Tform1.DoRtfFace(RichCont: TCustomRichedit; FN: String);
var
 Ms2: TmemoryStream;
 S: TFileStream;
 N: Integer;
Begin

If FileExists(Path+'rtfimages\'+Fn+'bmp')=True Then
 Begin
   Form1.ConvertBmpToRtf(Path+'rtfimages\'+Fn+'bmp',Path+'rtfimages\'+Fn+'');
   DeleteFile(Path+'rtfimages\'+Fn+'bmp');
 End;
  If FileExists(Path+'rtfimages\'+Fn)=True Then
   Begin
    If FileExistS(Path+'rtfimages\'+Fn) Then
     Begin
      S := TFileStream.Create(Path+'rtfimages\'+Fn, fmOpenRead or fmShareDenyNone);
      Ms2:=TmemoryStream.Create;
      Ms2.LoadFromStream(S);
      PutRtfSelection(RichCont,Ms2);
    {  Ms2.LoadFromFile(Path+'rtfimages\'+Fn);
      PutRtfSelection(RichCont,Ms2);}
      Ms2.Free;
      S.Free;
     End
      Else
     Begin

     End;
   End;
End;


Procedure Tform1.DoNewRtfFace(RichCont: TMyRichedit; FN: String);
var
 Ms2: TmemoryStream;
 S: TFileStream; 
 N: Integer;
begin

If FileExists(Path+'rtfimages\'+Fn+'bmp')=True Then
 Begin
   Form1.ConvertBmpToRtf(Path+'rtfimages\'+Fn+'bmp',Path+'rtfimages\'+Fn+'');
   DeleteFile(Path+'rtfimages\'+Fn+'bmp');
 End;
  If FileExists(Path+'rtfimages\'+Fn)=True Then
   Begin
    If FileExistS(Path+'rtfimages\'+Fn) Then
     Begin
      S := TFileStream.Create(Path+'rtfimages\'+Fn, fmOpenRead or fmShareDenyNone);
      Ms2:=TmemoryStream.Create;
      Ms2.LoadFromStream(S);
      PutRtfSelection(RichCont,Ms2);
{      Ms2.LoadFromFile(Path+'rtfimages\'+Fn);
      PutRtfSelection(RichCont,Ms2);}
      S.Free;
      Ms2.Free;
     End
      Else
     Begin

     End;
   End;
End;


Procedure Tform1.ConvertBmpToRtf(Fn1,Fn2: String);
 Var
  Tmp: String;
  cMYRichedit1: TMyRichedit;
  T: System.Text;
Begin
   Tmp:='';
   System.Assign(T,Fn2);
   System.Rewrite(T);
   Try
   Tmp:=Form1.BitmapToRTF(Fn1);
   Writeln(T,Tmp);
    Except
   End;
   System.Close(T);
End;

Procedure Tform1.ConvertGiftoBmp(Fn1,Fn2: String);
var
  GIF			: TGIFImage;
  Bitmap		: TBitmap;
begin
   GIF := TGIFImage.Create;
   GIF.LoadFromFile(FN1);
   Bitmap := TBitmap.Create;
   Bitmap.Assign(GIF);
   Bitmap.SaveToFile(FN2);
   Bitmap.Free;
   GIF.Free;
end;


Procedure Tform1.DoAvatar(RichCont: TMyRichedit; FN: String);
var
 Ms2: TmemoryStream;
 S: TFileStream;
 AvaType: String;
 Fn2: String;
begin
 If Fn='' Then Exit;

  If PosRep('\',Fn)>0 Then
  Begin
   AvaType:=LowerCaseRep(Copy(Fn,1,PosRep('\',Fn)-1));
   Delete(Fn,1,Length(Avatype)+1);

   If Form1.ValidFileName(FN)=False Then
      Exit;

   If AvaType='cc' Then
    Fn:=Path+'cheeta_avs\'+Fn;
   If AvaType='ch' Then
    Fn:=Path+'identitar\'+Fn;
  End;

If Fn<>'' Then
 Begin
   If FileExists(Fn+'.jpg')=True Then
    If FileExists(Fn+'.')=False Then
      Begin
       ConvertBmpToRtf(Fn+'.bmp',Fn+'.');
//       DeleteFile(Path+'identitar\'+Fn+'.bmp');
      End;

{ If Fn<>'' Then
  Begin
   If Form1.EnableAnimations1.Checked=True Then
     If FileExists(Fn+'.gif')=True Then
    Begin
      RichCont.InsertAnimatedSmiley(Fn+'.gif',RichCont);
      Exit;
    End;
  End;}

  If (FileExists(Fn+'.')=True) and (GetFileSize(Fn+'.')>100) Then
   Begin
     RichCont.SelStart:=-1;
     S:=TFileStream.Create(Fn+'.',fmOpenRead or fmShareDenyNone);
     Ms2:=TmemoryStream.Create;
     Ms2.LoadFromStream(S);
//     Ms2.LoadFromFile(Fn+'.');
     PutRtfSelection(RichCont,Ms2);
     Ms2.Free;
     S.Free;
     RichCont.SelText:=' ';
     RichCont.SelStart:=-1;
   End
    else
   Begin
    If Fn<>'' Then
     Begin
      RichCont.SelAttributes.Color:=ClRed;
      RichCont.SelAttributes.Style:=[FsItalic];
     // RichCont.SelText:='Æ ';
     End;
   End;
  End;
End;


function GetMasterMute(
  Mixer: hMixerObj;
  var Control: TMixerControl): MMResult;
  // Returns True on success
var 
  Line: TMixerLine; 
  Controls: TMixerLineControls; 
begin 
  ZeroMemory(@Line, SizeOf(Line));
  Line.cbStruct := SizeOf(Line);
//  Line.dwComponentType := MIXERLINE_COMPONENTTYPE_DST_SPEAKERS;
  Line.dwComponentType:=MIXERLINE_COMPONENTTYPE_SRC_WAVEOUT;
  Result := mixerGetLineInfo(Mixer, @Line,
    MIXER_GETLINEINFOF_COMPONENTTYPE);
  if Result = MMSYSERR_NOERROR then 
  begin 
    ZeroMemory(@Controls, SizeOf(Controls)); 
    Controls.cbStruct := SizeOf(Controls); 
    Controls.dwLineID := Line.dwLineID; 
    Controls.cControls := 1; 
    Controls.dwControlType := MIXERCONTROL_CONTROLTYPE_MUTE; 
    Controls.cbmxctrl := SizeOf(Control); 
    Controls.pamxctrl := @Control; 
    Result := mixerGetLineControls(Mixer, @Controls,
      MIXER_GETLINECONTROLSF_ONEBYTYPE); 
  end;
end; 

procedure Tform1.SetMasterMuteValue( 
  Mixer: hMixerObj;
  Value: Boolean);
var
  MasterMute: TMixerControl;
  Details: TMixerControlDetails;
  BoolDetails: TMixerControlDetailsBoolean;
  Code: MMResult;
begin
  Code := GetMasterMute(0, MasterMute);
  if Code = MMSYSERR_NOERROR then
  begin
    with Details do
    begin 
      cbStruct := SizeOf(Details);
      dwControlID := MasterMute.dwControlID; 
      cChannels := 1; 
      cMultipleItems := 0; 
      cbDetails := SizeOf(BoolDetails);
      paDetails := @BoolDetails; 
    end;
    LongBool(BoolDetails.fValue) := Value; 
    Code := mixerSetControlDetails(0, @Details, 
MIXER_SETCONTROLDETAILSF_VALUE);
  end;
  if Code <> MMSYSERR_NOERROR then
    raise Exception.CreateFmt('SetMasterMuteValue failure, '+
      'multimedia system error #%d', [Code]);
end;

Procedure Tform1.DownloadFile(url: String);
Var
 Obj: TForm39;
Begin
 If Pos('.skn',LowerCaseRep(Url))>0 Then
  Begin
   TFileDownload.Create(Url,'','80',0,Nil,False,False,True,False);
   Exit;
  End;

  If Pos('.ypf',LowerCaseRep(Url))>0 Then
  Begin
   TFileDownload.Create(Url,'','80',0,Nil,False,False,True,False);
   Exit;
  End;

 Obj:=Form1.CreateDownloadWindow(Url);
 If Obj<>Nil Then
   Obj.ThreadObj:=TFileDownload.Create(UrL,'','80',0,Obj,False,False,True,False);
End;

Procedure tform1.ConnectToYahooYMSG(LoggedInName,RoomName,LoggedInPassword: String);
Begin
 Form1.Ymsg.Active:=False;
  Case Random(5)+1 Of
   1: Form1.Ymsg.Port:=23;
   2: Form1.Ymsg.Port:=5050;
   3: Form1.Ymsg.Port:=119;
   4: Form1.Ymsg.Port:=25;
   5: Form1.Ymsg.Port:=20;      
  End;

  If Form2.RadioPort80CheckBox.Checked=True Then
      Form1.Ymsg.Port:=80;

//  RndServ:=Random(2)+1;
  Inc(RndServ);
  If RndServ>3 Then
     RndServ:=1;
  Case RndServ Of
   1: Form1.Ymsg.Host:='cs41.msg.dcn.yahoo.com';
   2: Form1.Ymsg.Host:='scsc.msg.yahoo.com';
   3: Form1.Ymsg.Host:='scsa.msg.yahoo.com';  //logs in that's it!
  End;
                //     216.155.192.209
{  Form1.Ymsg.Host:='216.155.192.107';
  Form1.Ymsg.Port:=5050;}

{  If Form2.CheckBox5.checked=true Then
    Begin
     Form1.Ymsg.Host:='127.0.0.1';
     Form1.Ymsg.Port:=5050;
    End;}

 If Form1.WorkingDetails.Server<>'' Then
  Begin
   Form1.Ymsg.Host:=Form1.WorkingDetails.Server;
   Form1.Ymsg.Port:=Form1.WorkingDetails.Port;
  End;

  If Form2.RadioPort80CheckBox.Checked=True Then
    Form1.Ymsg.Port:=80;


 Form1.Richedit1.SelStart:=-1;
 If Form10.CheckBox3.Checked=True Then
  Begin
   Form1.Richedit1.SelText:='Attempting Proxy Connection: '+Form10.Edit3.Text+':'+Form10.Edit4.Text+' For connection with: '+Form1.Ymsg.Host+' On Port: ';
   Form1.Richedit1.SelText:=IntToStr(Form1.Ymsg.port);
   Form1.Richedit1.Lines.Add('');
   Form2.ProxyYMSGConnect;
   Form1.ScrollToEnd(FOrm1.Richedit1);
  End
    else
  Begin
   Form1.Richedit1.Lines.Add('Attempting Connection With: '+Form1.Ymsg.Host+' On Port: '+IntToStr(Form1.Ymsg.port));
   Form1.Richedit1.Lines.Add('');
   Form1.ScrollToEnd(FOrm1.Richedit1);
   Form1.Ymsg.Active:=True;
  End;
  Form1.Richedit1.SelStart:=-1;
   If Form1.Scroll1.Checked=True Then Form1.ScrollToEnd(Form1.Richedit1);
End;


//\cf1\b tcjdelphi\cf2\b0 : \cf1\b\i wh\cf283 at t\cf284 yp\cf285 e \cf286 of b\cf287 ut\cf288 to\cf289 ns a\cf290 nd w\cf291 ha\cf292 t'\cf293 s \cf294 wi\cf3 th t\cf293 he t\cf291 hi\cf295 nk\cf290 s?  \par



Procedure Tform1.InsertRtfText(RichCont: TMyRichedit; Text: String; Vis: Boolean);
var
 Ms2: TmemoryStream;
 Txt: TstringList;
begin
  Ms2:=TmemoryStream.Create;
  Txt:=TstringList.Create;
  Txt.Text:=Text;
  Txt.SaveToStream(Ms2);
//  Ms2.Read(Text,Length(Text));
  PutRtfSelection(RichCont,Ms2);
  Ms2.Free;
  Txt.Free;
End;


{Procedure Tform1.DoRtfFace(RichCont: Trichedit; FN: String);
var
 ms : TMemoryStream;
 tmp : TStringList;
begin
  ms := TMemoryStream.create;
  Tmp:=Tstringlist.Create;
  Ms.LoadFromFile(Fn);
  //
   tmp.assign(richEdit1.lines);
   tmp.saveToStream(ms);
  //
  richcont.Lines.loadFromStream(ms);
  ms.free;
  tmp.free;
End;}


Function TForm1.ReverseColor(ColStr: String): Tcolor;
Var
 MyC,Tmp: String;
 MyColor: TColor;
Begin
  Result:=ClWhite;
  Tmp:=ColStr;
Try
  R:=StrToInt('$'+Copy(Tmp,1,2));
  G:=StrToInt('$'+Copy(Tmp,3,2));
  B:=StrToInt('$'+Copy(Tmp,5,2));
  MyC:='$'+IntToHex(B,2)+IntToHex(G,2)+IntToHex(R,2);
  MyColor:=StringToColor(MyC);
  Result:=MYColor;
 Except
 End;
  // '$'+Tcols[N]
End;


Function IsCustomName(userID: String): String;
Var
 R,N: Integer;
 Tmp,Tmp2: String;
Begin
 R:=-1;
 Tmp2:='';
 Result:='';
  For N:=FriendsAlias.Count-1 downto 0 do
    Begin
       Tmp:=LowerCaseRep(FriendsAlias.Strings[n]);
       If Copy(Tmp,1,PosRep(',',tmp)-1)=LowerCaseRep(UserID) Then
        Begin
         R:=N;
         Delete(Tmp,1,PosRep(',',tmp));
         Tmp2:=Tmp;
        End;
    End;
  If R<>-1 then
    Result:=Tmp2;
End;


{Procedure ReIndexChatters;
Var
 N: Integer;
Begin
//  Cn:=Form1.ChatterNum(Chatter);
If Assigned(FriendsAliasesLookUp) Then
  FriendsAliasesLookUp.Clear;
 For N:=1 to High(Chatters) Do
  Begin
   IF Chatters[N].UserName<>'' Then
    Begin
     Chatters[N].CustomName:=CustomName(Chatters[N].UserName);
     FriendsAliasesLookUp.AddObject(Chatters[N].UserName,@Chatters[N]);
    End;
  End;
End;


Function LoadCustomName(Chatter: String): Boolean;
Var
 Cn: Integer;
Begin
  Cn:=Form1.ChatterNum(Chatter);
  Chatters[CN].CustomName:=CustomName(Chatter);
  FriendsAliasesLookUp.AddObject(Chatter,@Chatters[Cn]);
End;

Function DeleteCustomName(Chatter: String): Boolean;
Var
 Cn: Integer;
Begin
  Cn:=FriendsAliasesLookUp.IndexOf(Chatter);
  If CN<>-1 Then
    FriendsAliasesLookUp.Delete(CN);
End;


Function IsCustomName(UserID: String): String;
Var
  N: Integer;
  Rec: PUserData2;
Begin
 N:=FriendsAliasesLookUp.IndexOf(UserID);
 If N<>-1 Then
   Begin
    Rec:=PUserData2(FriendsAliasesLookUp.Objects[N]);
    Result:=Rec^.CustomName;
   End
    else
   Result:='';
End; }


Function IsCustomNamePos(userID: String): Integer;
Var
 R,N: Integer;
 Tmp: String;
Begin
 R:=-1;
 Result:=-1;
  For N:=FriendsAlias.Count-1 downto 0 do
    Begin
       Tmp:=LowerCaseRep(FriendsAlias.Strings[n]);
       If Copy(Tmp,1,PosRep(',',tmp)-1)=LowerCaseRep(UserID) Then
         R:=N;
    End;
  If R<>-1 then
    Result:=R;
End;


Function AddCustomName(UserID,customName: String): Boolean;
Begin
 Result:=False;
 CustomName:=LowerCaseRep(CustomName);
 If IsCustomName(UserId)='' Then
  Begin
   If (Length(CustomName)>0) and (Length(UserId)>0) Then
    Begin
      FriendsAlias.Add(userId+','+customName);
      Result:=True;
      Form1.Richedit1.Lines.Add('User ID: '+UserID+' Will now be called "'+CustomName+'"');
      Chatters[Form1.ChatterNum(UserID)].AssignedCustomName:=CustomName;
      Form1.ScrollToEnd(FOrm1.Richedit1);      
//      LoadCustomName(UserID);
    End;
  End
   Else
 Begin
   If (Length(CustomName)>0) and (Length(UserId)>0) Then
    Begin
      FriendsAlias.Strings[IsCustomNamePos(LowerCaseRep(UserID))]:=userId+','+customName;
      Result:=True;
      Form1.Richedit1.Lines.Add('User ID: '+UserID+' Will now be called "'+CustomName+'"');
      Chatters[Form1.ChatterNum(UserID)].AssignedCustomName:=CustomName;
      Form1.ScrollToEnd(FOrm1.Richedit1);
//      DeleteCustomName(UserID);
//      LoadCustomName(UserID);
    End;
 End;
   Form1.ScrollToEnd(Form1.Richedit1);
End;

Procedure Tform1.PmImUser(ToUser: String);
Var
 MessageStr: String;
begin
if InputQuery('IM: '+ToUser,'Message To User '+ToUser, messagestr) then
 if Length(messagestr) > 0 then
  Begin
   Form1.SayPm(ToUser,LoggedInName,messagestr);
   Form1.Richedit1.SelAttributes.Style:=[FSBold];
   Form1.Richedit1.SelAttributes.color:=$DD0000;
   Form1.Richedit1.seltext:='You tell '+touser+': ';
   Form1.Richedit1.SelAttributes.Style:=[];
   Form1.Richedit1.SelAttributes.color:=clpurple;
   Form1.Richedit1.seltext:=messagestr;
   Form1.Richedit1.lines.add('');
   Form1.ScrollToEnd(Form1.Richedit1);
  End;
End;



Function LastChance(S: String): String;
Var
 BuildStr: String;
 N: Integer;
 StopBuilding: Boolean;
Begin
LastChance:='';
StopBuilding:=False;
If Length(S)>0 Then
 Begin
 For N:=1 to Length(S) Do
  If S[n] in ['a'..'z', 'A'..'Z'] Then
   Begin
     if S[n] in ['0'..'9'] Then
       StopBuilding:=True;
     If StopBuilding=False Then
        BuildStr:=BuildStr+S[N];
   End;
  End;
 LastChance:=BuildStr;
End;

Function ExtractName(UserName: String): String;
Var
 BuildStr2,TmpStr: String;
 StrList: TstringList;
 I,num: Integer;
Begin
 StrList:=TstringList.Create;
    TmpStr:=UserName;
    BuildStr2:='';
    Num:=0;
     While Num<Length(TmpStr) Do
      Begin
        BuildStr2:='';
        Delete(TmpStr,1,Num);
        Num:=0;
         repeat
          inc(num);
          if (tmpstr[num] in ['a'..'z', 'A'..'Z']) then
             buildstr2:=buildstr2+tmpstr[num];
          until (tmpstr[num]='_') or (tmpstr[num] in ['0'..'9']) or (tmpstr[num]=' ') or (tmpstr[num]='.') or (num>=length(tmpstr)) or (tmpstr[num] in ['0'..'9']) Or (Num>=Length(TmpStr));
         StrList.Add(LowerCaseRep(BuildStr2));
       End;
     TmpStr:='';
     StrList.Sort;
      For I:=0 to Strlist.Count-1 do
        If (Length(StrList[I])>Length(TmpStr)) Then
         If (StrList[I]<>'the') or (StrList[I]<>'and') and (Length(StrList[I])<5) Then
             TmpStr:=StrList[I];
  StrList.Free;
  ExtractName:=TmpStr;
End;


function TForm1.customizename(nametoplaywith: string): string;
 var
   oldname,newname: string;
   buildstr2: string;
   TmpStr: String;
begin
 tmpstr:='';
 Newname:='';
 If Chatters[Form1.Chatternum(NameToPlayWith)].AssignedCustomName<>'' Then
   Begin
     Result:=Chatters[Form1.Chatternum(NameToPlayWith)].AssignedCustomName;
     If Length(Result)>=1 Then
      Result[1]:=upcase(Result[1]);
     Exit;
   End;
 oldName:=NameToPlayWith;
 NameToPlayWith:=LowerCaseRep(NameToPlayWith);
 TmpStr:=NametoPlayWith;
 if length(tmpstr)>0 then
  begin
    BuildStr2:=ExtractName(NameToPlayWith);
     If IsCustomName(NameToPlayWith)<>'' Then
       BuildStr2:=IsCustomName(NameToPlayWith);
    if (Length(NameToPlayWith)>4) and (buildstr2=nametoplaywith) Then
     Begin
      BuildStr2:='';//MatchWord(NameToPlayWith);
      If BuildStr2='' Then
        BuildStr2:=Copy(NameToPlayWith,1,4);
     End;
 if length(buildstr2)<2 then
  Begin
   If LastChance(NameToPlayWith)<>'' Then
      NameToPlayWith:=LastChance(NameToPlayWith);
   NameToPlayWith[1]:=NametoPlaywith[1];
   Result:=NameToPlayWith;
   Chatters[Form1.Chatternum(NameToPlayWith)].AssignedCustomName:=Result;
  end
    else
   begin
//    If MatchWord(BuildStr2)<>'' Then
 //     BuildStr2:=MatchWord(BuildStr2);
    buildstr2[1]:=upcase(buildstr2[1]);
    Result:=buildstr2;
    Chatters[Form1.Chatternum(NameToPlayWith)].AssignedCustomName:=Result;
   end;
  end;
end;


Function IsBuddyOnLine(Buddy: String): Boolean;
Var
  N,R: Integer;
Begin
R:=-1;
Result:=False;
For N:=Form12.ListBox1.Items.Count-1 downto 0 do
  Begin
    If Form12.ListBox1.Items[N]=Buddy Then
       R:=N;
  End;
 If R<>-1 Then
   Result:=True;
End;


Function IsUserPmIgnored(UserName: String): Boolean;
Begin
 Result:=False;
 IF PmIgnore.IndexOf(LowerCaseRep(UserName))<>-1 Then
   Result:=True;
End;


///could do with optimiziation

Function Tform1.ReplaceStr(S,WhatStr,WithStr: String): String;
Var
 Tmp: String;
 P1: Integer;
Begin
 Tmp:=S;
 Result:=Tmp;
If LowerCaseRep(WhatStr)=LowerCaseRep(WithStr) Then
    Exit;
While PosRep(LowerCaseRep(WhatStr),LowerCaseRep(Tmp))>0 Do
 Begin
  P1:=PosRep(LowerCaseRep(WhatStr),LowerCaseRep(Tmp));
  Delete(Tmp,P1,Length(WhatStr));
  Insert(WithStr,Tmp,P1);
 End;
  Result:=Tmp;
End;



Function Tform1.ReplaceFromToStr(S,StartStr,EndStr,WithStr: String): String;
Var
 Tmp: String;
 P1,P2,P3: Integer;
Begin
  Tmp:=S;
  P2:=PosRep(StartStr,Tmp);
  P3:=PosRep(EndStr,Tmp);
  While (P2<P3) And (P2>0) and (P3>0) Do
   Begin
     P1:=PosRep(StartStr,Tmp);
     //Tmp:=Remove2(Tmp,StartStr,EndStr);
     Delete(Tmp,P2,P3-p2+1);
     Insert(WithStr,Tmp,P1);
     P2:=PosRep(StartStr,Tmp);
     P3:=PosRep(EndStr,Tmp);
   End;
  Result:=Tmp; 
End;



Function Tform1.RemoveStr(WithStr,S: String): String;
Var
 Tmp: String;
 P1: Integer;
Begin
  Tmp:=S;
While PosRep(LowerCaseRep(WithStr),LowerCaseRep(Tmp))>0 Do
 Begin
  P1:=PosRep(LowerCaseRep(WithStr),LowerCaseRep(Tmp));
  Delete(Tmp,P1,Length(WithStr));
 End;
  Result:=Tmp;
End;


function TForm1.Remove2(text: String; from,too: String): String;
var
  Len,mypos, count,Count1: Integer;
  temp: String;
begin
  Result:=Text;
  temp:=text;
 If (PosRep(LowerCaseRep(Too),LowerCaseRep(Text))>0) and (PosRep(LowerCaseRep(From),LowerCaseRep(Text))>0) Then
   Begin
    while PosRep(LowerCaseRep(from),LowerCaseRep(temp)) > 0 do
     begin
       mypos:=PosRep(LowerCaseRep(from),LowerCaseRep(temp));
       count1:=mypos;
       Count:=Count1;
       Len:=Length(Temp)-1;
       while (temp[count] <> too) And (Count<=Len)do
        Inc(count);
        Inc(Count);
      Delete(temp,mypos,count-mypos);
    end;
    Result:=temp;
  End;
end;


Function Tform1.IsItemIn(LB: TlistBox; Str: String): Integer;
Var
 N: Integer;
Begin
 Result:=Lb.Items.IndexOf(Str);
End;

Function Tform1.IsItemInX(LB: TSpSkinlistBox; Str: String): Integer;
Var
 N: Integer;
Begin
 Result:=Lb.Items.IndexOf(Str);
End;


Function Tform1.IsItemIn2(LB: TSpSkincomboBox; Str: String): Integer;
Begin
 Result:=Lb.Items.IndexOf(Str);
End;



Procedure Tform1.SaveLoginData;
Var
 Hold: String;
Begin
 Hold:=Form2.ComboBox1.Text;
 If IsItemIn2(Form2.ComboBox1,Form2.ComboBox1.Text)=-1 Then
   Form2.ComboBox1.Items.Insert(0,Form2.ComboBox1.Text);

 Form2.ComboBox1.Items.SaveToFile(Path+'set1.dat');
 Form2.RoomBox.Items.SaveToFile(Path+'newset3.dat');
 Form8.ServComboBox.Items.SaveToFile(Path+'serverroomlist.txt');
End;

Procedure Tform1.LoadLoginData;
Begin
If FileExists(Path+'set1.dat') Then
 Form2.ComboBox1.Items.LoadFromFile(Path+'set1.dat');

If FileExists(Path+'newset3.dat') Then
 Form2.RoomBox.Items.LoadFromFile(Path+'newset3.dat');


// Form2.ComboBox3.Text:=Form2.ComboBox3.Items[0];
// LoggedInName:=Form2.ComBoBox1.Text;
// RoomName:=Form2.ComBoBox3.Text;
// LoggedInPassword:=Form2.Edit1.Text;
End;



Function Tform1.ExtractBetweenString(StartS,EndS,S: String; Tr: Boolean): String;
Var
 Tmp,Tmp2: String;
 Res,P1,P2: Integer;
Begin
  Result:=S;
  Tmp:=S;
  If Starts='' Then Exit; If EndS='' Then Exit;
  P1:=PosRep(LowerCaseRep(StartS),LowerCaseRep(Tmp));
  P2:=Instr(LowerCaseRep(EndS),LowerCaseRep(Tmp),P1);
  If (P1>0) And (P2>0) Then
   Begin
    Inc(P1,Length(StartS));
  //  Inc(P2,Length(EndS));
    Inc(P2);
    Res:=P2-P1;
   End;
  If (P1>0) And (P2>0) Then
   If P1<=P2 Then
    Begin
     If Tr=True Then
      Tmp2:=Trim(Copy(Tmp,P1,Res))
         else
      Tmp2:=Copy(Tmp,P1,Res);
      Result:=Tmp2;
    End;
End;


Function Tform1.ExtractBetweenString2(StartS,EndS,S: String; Tr: Boolean): String;
Var
 Tmp,Tmp2: String;
 Res,P1,P2: Integer;
Begin
  Tmp:=S;
  If Starts='' Then Exit; If EndS='' Then Exit;
  P1:=PosRep(LowerCaseRep(StartS),LowerCaseRep(Tmp));
  P2:=Instr(LowerCaseRep(EndS),LowerCaseRep(Tmp),P1);
  If (P1>0) And (P2>0) Then
   Begin
    Inc(P1,Length(StartS));
  //  Inc(P2,Length(EndS));
    Inc(P2);
    Res:=P2-P1;
   End;
  If (P1>0) And (P2>0) Then
   If P1<=P2 Then
    Begin
     If Tr=True Then
      Tmp2:=Trim(Copy(Tmp,P1,Res))
         else
      Tmp2:=Copy(Tmp,P1,Res);
      Result:=Tmp2;
    End;
End;


Function Tform1.ExtractString(StartS,EndS,S: String): String;
Var
 Tmp,Tmp2: String;
 Res,P1,P2: Integer;
Begin
  Result:='';
  Tmp:=S;
  P1:=PosRep(LowerCaseRep(StartS),LowerCaseRep(Tmp));
  P2:=Instr(LowerCaseRep(EndS),LowerCaseRep(Tmp),P1);
  If (P1>0) And (P2>0) Then
    Res:=P2-P1+1;
  If (P1>0) And (P2>0) Then
   If P1<=P2 Then
    Begin
      Tmp2:=Trim(Copy(Tmp,P1,Res));
      Result:=Tmp2;
    End;
End;

Function TForm1.MyRemove(Text,Str: String): String;
Var
 N,C,P1,P2: Integer;
 tmp: String;
Begin
 P1:=PosRep(Str,Text);
 If P1<>0 Then
   Delete(Text,P1,Length(Str));
 Result:=Text;
End;


function TForm1.Remove(text: String; from,too: Char): String;
var
  Len,mypos, count,Count1: Integer;
  temp: String;
begin
  Result:=Text;
  temp:=text;
 If (PosRep(Too,Text)>0) and (PosRep(From,Text)>0) Then
   Begin
    while PosRep(from,temp) > 0 do
     begin
       mypos:=PosRep(from,temp);
       count1:=mypos;
       Count:=Count1;
       Len:=Length(Temp)-1;
       while (temp[count] <> too) And (Count<=Len)do
        Inc(count);
        Inc(Count);
      Delete(temp,mypos,count-mypos);
    end;
    Result:=temp;
  End;
end;


{Function UrlHttpStr(Str,Url: String): String;
Var
 P1,P2: Integer;
 N: Integer;
 Col,TmpStr: String;
Begin
 TmpStr:=Str;
 P1:=PosRep(Url,Str);
 Col:=GetColStr(TmpStr);
 Insert(YBlue+YNoBold+YUn,TmpStr,P1);
 P1:=PosRep(Url,TmpStr);
 P2:=P1+Length(Url);
 Insert(YnoBold+YnoUn+Col,TmpStr,P2+1);
 Result:=TmpStr;
End;}


Function Tform1.RicheditBold(RichCont: TMyRichedit; Msg: String): String;
Var
 FoundTag: Boolean;
 P1,P2,N: Integer;
 Msg3,Msg2,Col: String;
Begin
//RichCont.Lines.BeginUpdate;
 Bo:=False;
 I:=False;
 U:=False;
RichCont.SelStart:=-1;
N:=0;
Msg3:=Msg;
Msg2:=Msg+' ';
// GetTxt(Msg,'#$1B','m');
{If PosRep(#$1b,Msg)=0 Then
  RichCont.SelAttributes.Color:=ClBlue;}
RichCont.SelAttributes.Style:=[];
   P1:=PosRep(#$1b,Msg);
   P2:=Instr('m',Msg,p1);
 While (P2>=P1) and (P1>0) And (N<=Length(Msg)) and (Length(Msg)>0)  Do
  Begin
   //RichCont.SelText:=Msg;
{   For N:=1 to Length(Msg) do
    Begin}
    Inc(N);
    foundtag:=False;
     If Msg[n]=#$1B Then
      Begin
        P1:=PosRep(#$1b,Msg);
    //    Delete(Msg,1,p1-1);
        P2:=Instr('m',Msg,p1);
        Col:=Copy(Msg,P1,P2-P1+2);
        Delete(Msg,P1,P2-P1+2);
        If Col=Ybold Then
         Begin
          foundtag:=True;
          RichCont.SelAttributes.Style:=RichCont.SelAttributes.Style+[FsBold];
          BO:=True;
         End;
        If Col=Yitalic Then
         Begin
          RichCont.SelAttributes.Style:=RichCont.SelAttributes.Style+[Fsitalic];
          foundtag:=True;
          I:=True;
         End;
        If Col=Yun Then
         Begin
          RichCont.SelAttributes.Style:=RichCont.SelAttributes.Style+[FsUnderline];
          foundtag:=True;
          U:=True;
         End;
        If Col=Ynobold Then
         Begin
          foundtag:=True;
          RichCont.SelAttributes.Style:=RichCont.SelAttributes.Style-[FsBold];
         End;
        If Col=Ynoi Then
         Begin
          foundtag:=True;
          RichCont.SelAttributes.Style:=RichCont.SelAttributes.Style-[FsItalic];
         End;
        If Col=Ynoun Then
         Begin
          foundtag:=True;
          RichCont.SelAttributes.Style:=RichCont.SelAttributes.Style-[FsUnderLine];
         End;
          N:=0;
      End;
{      If Length(Msg)>0 Then
       Begin
       If Msg[N]<>#$1B Then
        Begin
         RichCont.SelText:=Msg[n];
         Delete(msg,n,1);
        End;
         N:=0;
       End;
    End;}
  End;
   Result:=Msg;
// RichCont.Lines.EndUpdate;
 Form1.ScrollToEnd(Form1.Richedit1);
End;


function TForm1.ScanIt(tosearchfor,scanstring: string): integer;
var
 scancounter: integer;
 p1: integer;
 tsf,ss: string;
begin
ss:=scanstring;
tsf:=tosearchfor;
scancounter:=0;
 repeat
  p1:=PosRep(LowerCaseRep(tsf),LowerCaseRep(ss));
  if p1>0 then
   inc(scancounter);
   delete(ss,1,p1+length(tsf));
  until p1=0;
 scanit:=scancounter;
end;

Function Tform1.MakeEmote(TmpfStr,UserName: String): String;
Begin
 TmpFstr:=YBlue+TmpFstr;
 TmpFstr:=Form1.ReplaceStr(TmpFstr,'%AutoIgnore',YPurple+' {Auto Ignore}'+Yblue);
 TmpFstr:=Form1.ReplaceStr(TmpFstr,'<username>',Yred+UserName+Yblue);
 TmpFstr:=Form1.ReplaceStr(TmpFstr,'%s',Yred+UserName+Yblue);
 TmpFstr:=Form1.ReplaceStr(TmpFstr,'%time',Ygreen+DateTimeToStr(Now)+Yblue);
 TmpFstr:=Form1.ReplaceStr(TmpFstr,'%lastignored',Yred+Form1.BuildTime(SecondsBetween(Now,Form1.LastIgnored))+Yblue);
 TmpFstr:=Form1.ReplaceStr(TmpFstr,'%build',ymlitelogo+' '+ClientVer+Yblue);
 TmpFstr:=Form1.ReplaceStr(TmpFstr,'%ignored',Yred+InttoStr(Ignored.Count)+Yblue);
 TmpFstr:=Form1.ReplaceStr(TmpFstr,'%users',Yred+InttoStr(Users)+Yblue);
 TmpFstr:=Form1.ReplaceStr(TmpFstr,'%roomignored',Yred+InttoStr(Form1.Listbox2.Items.Count)+Yblue);
 Result:=TmpFstr;
End;

function TForm1.HTTPEncode(const AStr: string): string;
const
 NoConversion = ['A'..'Z', 'a'..'z', '*', '@', '.', '_', '-'];
var
 Sp, Rp: PChar;
begin
  SetLength(Result, Length(AStr) * 3);
  Sp := PChar(AStr);
  Rp := PChar(Result);
  while Sp^ <> #0 do
    begin
      if Sp^ in NoConversion then
       Rp^ := Sp^
        else if Sp^ = ' ' then
       Rp^ := '+'
      else
   begin
    FormatBuf(Rp^, 3, '%%%.2x', 6, [Ord(Sp^)]);
    Inc(Rp, 2);
   end;
 Inc(Rp);
 Inc(Sp);
end;
SetLength(Result, Rp - PChar(Result));
end;

Function EncodeUrl(S: String): String;
Begin
 Result:=Form1.HTTPEncode(S);
End;


Function Tform1.MakeMacro(TmpfStr: String): String;
Begin
If PosRep('%',TmpFstr)>0 Then
 Begin
  If L1WhoIsSelected<>'' Then
    TmpFstr:=Form1.ReplaceStr(TmpFstr,'%s',L1WhoIsSelected);
  TmpFstr:=Form1.ReplaceStr(TmpFstr,'%time',DateTimeToStr(Now));
  TmpFstr:=Form1.ReplaceStr(TmpFstr,'%build',ymlitelogo+' '+ClientVer);
  TmpFstr:=Form1.ReplaceStr(TmpFstr,'%ignored',InttoStr(Ignored.Count));
  TmpFstr:=Form1.ReplaceStr(TmpFstr,'%users',InttoStr(Users));
  TmpFstr:=Form1.ReplaceStr(TmpFstr,'%roomignored',InttoStr(Form1.Listbox2.Items.Count));
 End;
 Result:=TmpFstr;
End;


Procedure Tform1.JpgToBmpYmlite(FN: String);
 var
  Bmp : TBitmap;
  Jpg : TJpegImage;
begin
 Bmp:= TBitmap.Create;
 Jpg := TJpegImage.Create;
 If (FileExists(Path+'identitar\'+Fn)=True) And (FileExists(Path+'identitar\'+Fn+'.bmp')=False) Then
  Begin
   Jpg.LoadFromFile(Path+'identitar\'+Fn);
   Bmp.Assign(Jpg);
   If PosRep('.jpg',Fn)>0 Then
     Delete(Fn,Length(Fn)-3,4);
   Bmp.SaveToFile(Path+'identitar\'+Fn+'.bmp');
  End;
 Bmp.free;
 Jpg.Free;
End;


Procedure Tform1.JpgToRtf(FN: String);
 var
  Bmp : TBitmap;
  Jpg : TJpegImage;
begin
 Bmp:= TBitmap.Create;
 Jpg := TJpegImage.Create;
 If (FileExists(Path+'rtfimages\'+Fn+'.jpg')=True) And (FileExists(Path+'identitar\'+Fn+'.bmp')=False) Then
  Begin
   Try
     Jpg.LoadFromFile(Path+'rtfimages\'+Fn+'.jpg');
     Bmp.Assign(Jpg);
     Bmp.SaveToFile(Path+'rtfimages\'+Fn+'.bmp');
     Form1.ConvertBmpToRtf(Path+'rtfimages\'+Fn+'.bmp',Path+'rtfimages\'+Fn);
   Except
  End;
  End;
 Bmp.free;
 Jpg.Free;
End;


Procedure ChatDisplayIgnore(Username: String);
Begin
 If Form10.CheckBOx48.Checked=True Then
  Begin
   Form1.ScrollToEnd(Form1.Richedit1);
   Form1.RichEdit1.SelAttributes.Color:=ClRed;
   Form1.Richedit1.SelText:=Username+' ';
   Form1.RichEdit1.SelAttributes.Color:=ClBlack;
   Form1.Richedit1.SelText:='Ignored, Remove From Ignore Just Double Click ';
   Form1.RichEdit1.SelAttributes.Color:=ClBlue;
   Form1.Richedit1.SelAttributes.Style:=[fsUnderline];
   Form1.Richedit1.SelText:='<'+Username+'>';
   Form1.Richedit1.SelAttributes.Style:=[];
   Form1.RichEdit1.SelAttributes.Color:=ClBLack;
   Form1.Richedit1.Lines.ADD('');
   Form1.ScrollToEnd(Form1.Richedit1);
  End; 
End;

Procedure Tform1.IgnoreUser(UserName: String; Silent,Snd,AutoIgnore,RoomEnter: Boolean);
Var
 Obj: Tobject;
Begin
UserName:=LowerCaseRep(Username);
If (Trim(Username)<>'') and (UserName<>LowerCaseRep(LoggedInName)) and (Ignored.Find(UserName,Obj)=False) and (NeverIgnore.IndexOf(Username)=-1) Then
 Begin
   If (Form1.YmLiteGeneralSounds1.Checked=True) And (Snd=True) Then
     Form1.StartSound('Ignore.wav',False,False);
  Ignored.Add(UserName,Obj);
  If Form18.CheckBox1.Checked=True Then
   Begin
    If (Form1.ListBox1.Items.IndexOf(UserName)<>-1) Or (TmpLeave.IndexOf(wordstr)<>-1) or (TmpLeave.IndexOf(UserName)<>-1) Then
     If Silent=False Then
      Begin
        If AutoIgnore=False Then
          Form1.Say(Form1.Richedit1,MakeEmote(Form18.Edit2.text,UserName),false,True,False)
           else
         If Form10.CheckBox34.Checked = True Then
             Form1.Say(Form1.Richedit1,MakeEmote(Form18.Edit2.text+' %AutoIgnore',UserName),false,True,False)
              else
             ChatDisplayIgnore(UserName);
       End;
   End
     Else
     If RoomEnter=False Then
       ChatDisplayIgnore(UserName);

 If (Form1.ListBox1.Items.IndexOf(UserName)<>-1) and (LoggedInName<>UseRName) And (NeverIgnore.IndexOf(Username)=-1) Then
 Begin
  Form1.ListBox1.Items.Delete(Form1.ListBox1.Items.IndexOf(UserName));
  If Form1.ListBox2.Items.IndexOf(UserName)=-1 Then
    Form1.ListBox2.Items.Add(UserName);
 End;
End;
  Form1.LastIgnored:=Now;
End;

Function Tform1.RemoveIgnoredUser(UserName: String): Boolean;
Var
  I: Integer;
  Obj: TObject;
Begin
IF Trim(Username)<>'' Then
 Begin
 Result:=False;
  If Ignored.Find(LowerCaseRep(UserName),Obj)=True Then
   Begin
     Ignored.Delete(LowerCaseRep(UserName));
     Result:=True;
   End;
   If Form18.CheckBox2.Checked=True Then
    Begin
     Form1.Say(Form1.Richedit1,MakeEmote(Form18.Edit3.text,UserName),false,True,False);
    End;
  End;
End;


Function ColourCount(Str: String): Integer;
Var
 P1,N: Integer;
 tmp,TmpCol: String;
Begin
 N:=0;
 Tmp:=Str;
  Tmp:=Tmp+',';
  While PosRep(',',Tmp)>0 do
   Begin
    P1:=PosRep(',',Tmp);
    TmpCol:=Copy(Tmp,1,p1-1);
    Delete(Tmp,1,P1);
    Inc(N);
   End;
 Result:=N;
End;

Function IsSmile(Str: String): Integer;
 Var
   N: Integer;
Begin
 Result:=-1;
 If Smileys.Find(Str,Tobject(Result))=True then
   Result:=1;
End;

Function DoTattooTag(S: String): String;
Var
 Err,N,CTo,P1,P2,P3: Integer;
 BckTmp,Tmp,Tmp2: String;
 Remv: Boolean;
Begin
// S:=RemoveDoubleSpaces(S);
 Result:=S;
 BckTmp:=S;
 Tmp2:=S;
 //<font face="ariel black">
P1:=PosRep('<font face="',LowerCaseRep(S));
P2:=PosRep('<font size="',LowerCaseRep(S));
If (P2<P1) and (P2<>0) Then
 P1:=P2;
 If P1>0 Then
 Begin
  P2:=Form1.InsTr('>',S,P1);
  Tmp:=Copy(S,P1,P2-P1+2);
  If (PosRep('tattoo',LowerCaseRep(Tmp))>0) or (PosRep('tat',LowerCaseRep(Tmp))>0) or (PosRep('ta2',LowerCaseRep(Tmp))>0) Then
   Begin
     P1:=PosRep('<font',S);
     P2:=Form1.InsTr('<font',S,P1);
     P3:=Form1.InsTr('<fade',S,P1);
     If (P3>P1) and (P3<P2) Then
      P2:=P3;
     If P2>P1 Then
      Delete(S,1,P2);
     Result:=S;
  End;
 End; 
End;

Function DoFontTag(S: String): String;
Var
 Err,N,CTo,P1,P2: Integer;
 BckTmp,Tmp,Tmp2: String;
 Remv: Boolean;
Begin
// S:=RemoveDoubleSpaces(S);
 Result:=S;
 BckTmp:=S;
 Tmp2:=S;
 //<font face="ariel black">
 CTo:=Form1.ScanIt('<font face="',LowerCaseRep(S));
For N:=1 to Cto Do
 Begin
P1:=PosRep('<font face="',LowerCaseRep(S));
 If P1>0 Then
 Begin
  P2:=Form1.InsTr('>',S,P1);
  Tmp:=Copy(S,P1,P2-P1+2);
  Delete(S,P1,Length(Tmp));
  P1:=PosRep('"',Tmp);
  P2:=Form1.InsTr('"',Tmp,P1);
  Tmp:=Copy(Tmp,P1+1,P2-P1);
  FontFaceTag:=Tmp;
   FontSizeTag:=10;
  ////<font size="15">
  P1:=PosRep('size="',LowerCaseRep(S));
  P2:=Form1.InsTr('>',S,P1);
  Tmp:=Copy(S,P1,P2-P1+1);
  Delete(S,P1,Length(Tmp));
  P1:=PosRep('"',Tmp);
  P2:=Form1.InsTr('"',Tmp,P1);
  Tmp:=Copy(Tmp,P1+1,P2-P1);
  Val(Tmp,FontSizeTag,Err);
   If Err<>0 Then
   FontSizeTag:=10;

   If Form10.RadioButton6.Checked=True Then
     If FontSizeTag>Form10.SpinEdit4.Value Then
       FontSizeTag:=Form10.SpinEdit4.Value;


  If FontSizeTag>20 Then
   If Form10.RadioButton9.Checked=False Then
     FontSizeTag:=20
      else
     FontSizeTag:=Form10.Spinedit4.Value;

  If FontSizeTag<9 Then
     FontSizeTag:=10;
  P1:=PosRep('<font',S);
  P2:=Form1.InsTr('>',S,P1);
  Delete(S,P1,P2-P1+2);
  Result:=S;
  End;
 End;
End;

function GetFileT(Text: String): String;
Begin
 Result:='';
 If LowerCaseRep(Copy(Text,1,7))='file://' Then
  Begin
   Delete(Text,1,7);
   Result:=Text;
  End;
End;

Function Tform1.IsItAnIP(Str: String): Boolean;
Begin
 Result:=False;
 Str:=LowerCaseRep(Str);
 If Form1.ScanIt('.',Str)=4 Then
  If PosRep('.com',Str)=0 Then
    If PosRep('.net',Str)=0 Then
      If PosRep('.co.uk',Str)=0 Then
        If PosRep('.org',Str)=0 Then
           Result:=True;
End;

Function Tform1.GetFirstUrl(Text: String): String;
var
  index: Integer;
  Tmp,foundtext: String;
  P1,P2: Integer;
begin
  Text:=Text+' ';
    Result:='';
    foundtext:='';
    P1:=PosRep('http://',LowerCaseRep(Text));
    P2:=PosRep('www.',LowerCaseRep(Text));


    if  (P1>0) And (P1<P2) then
      foundtext:='http://'
    else
    if  (P2>0) And (P2<P1) then
      foundtext:='www.';

    If FoundText='' Then
     Begin
      If P1>0 Then
       foundtext:='http://';
      If P2>0 Then
       foundtext:='www.';
     End;

    if foundtext <> '' then
    begin
      index:=PosRep(foundtext,Text);
      if index > 1 then
        Text:=Copy(Text,index,Length(Text) - index)
      else
        Text:=Copy(Text,index,Length(Text) - index + 1);
      if PosRep(' ',Text) > 0 then
        Result:=Copy(Text,1,PosRep(' ',Text)-1)
      else
        Result:=Text;
    end;
End;

function Tform1.GetURL(Text: String; IgnoreIPs: Boolean): String;
Var
 Url,Tmp2,Tmp: String;
Begin
 Tmp:=Text;
 Tmp2:=Tmp;
 Url:=GetFirstUrl(Tmp2);
 If IgnoreIPs=True Then
   While IsItAnIP(Url)=True Do
     Begin
       Delete(Tmp2,1,PosRep(Url,Tmp2)+Length(Url)-1);
       Url:=GetFirstUrl(Tmp2);
     End;
 Result:=Url;
end;

Procedure Tform1.BuildPacketFromStr(SPayLoad: String);
Var
 functionType: Char;
 Tmp2,PayLoad,Data,Tmp: String;
 HM,N,BH,Len: Integer;
 FillArr: String;
 BuildStr,Token1,Token2,Token3: String;
Begin
 Token1:=Copy(SPayLoad,1,PosRep(' ',SPayLoad)-1);
 Delete(SpayLoad,1,PosRep(' ',SPayLoad));

 If PosRep('\\',SPayLoad)>0 Then
  Begin
   Token2:=Copy(SPayLoad,1,PosRep('\\',SPayLoad)-1);
   Delete(SpayLoad,1,PosRep('\\',SPayLoad)+1);
  End
    else
  Begin
   Token2:=SpayLoad;
   SpayLoad:='';
  End;

 If SPayLoad<>'' Then
   Token3:=SPayLoad;

  SpayLoad:='';


 If Length(Token1)>1 Then
  Begin
   Delete(Token1,1,1);
   BH:=StrToInt('$'+Token1);
   functionType:=Chr(Bh);
  End;

 BuildStr:='';
  While (Length(Token2)>0) Do
   Begin
    If PosRep('/',Token2)=0 Then
     Begin
      Tmp:=Token2;
      Token2:='';
      End
     else
    Tmp:=Copy(Token2,1,PosRep('/',Token2)-1);

    If Length(Tmp)>=1 Then
     Begin
      If Tmp[1]<>'%' Then
        BuildStr:=BuildStr+Tmp
         else
       Begin
         If Tmp='%del' Then
             BuildStr:=BuildStr+Co80s;
        If Tmp='%id' Then
           BuildStr:=BuildStr+LoggedInName;
        If Tmp='%voice' Then
           BuildStr:=BuildStr+Form22.edit4.Text;
        If Tmp='%roomext' Then
           BuildStr:=BuildStr+Form22.edit9.Text;
        If Tmp='%cam' Then
           BuildStr:=BuildStr+Form22.edit8.Text;
        If Tmp='%rmspace' Then
           BuildStr:=BuildStr+Form22.edit3.Text;
        If Tmp='%conf' Then
           BuildStr:=BuildStr+Form22.edit2.Text;
        If Tmp='%room' Then
           BuildStr:=BuildStr+GPRoomName;
        If Tmp='%pwd' Then
           BuildStr:=BuildStr+Form2.Edit1.Text;
        If Tmp='%key' Then
           BuildStr:=BuildStr+Key;
        If Copy(Tmp,1,5)='%fill' Then
         Begin
           Delete(Tmp,1,6);
           HM:=StrToInt(Copy(Tmp,1,PosRep(':',Tmp)-1));
           SetLength(FillArr,Hm);
           FillChar(FillArr[1],Hm,Tmp[Length(Tmp)]);
           BuildStr:=BuildStr+FillArr;
         End;
       End;
     End;
    Delete(Token2,1,PosRep('/',Token2));
   End;



 If Form2.RadioButton1.Checked=True Then
  Begin
//   Payload:='11'+co80s+LoggedInName+co80s;
   PayLoad:=BuildStr;
   Len:=Length(PayLoad);
   Tmp:='YMSG'+#$00+GVN+#$0+#$0+LengthToStr(Len)+#$0+FunctionType+#$0+#$0+#$0+#$0+Key;
   Tmp:=Tmp+PayLoad;
   If Token3<>'' Then
    Begin
     For N:=1 to StrToInt(Token3) Do
      Begin
       Form1.Delay(StrToInt(Form10.Edit7.Text));
       Form1.SendText(Tmp);
      End;
     End
      else
     Form1.SendText(Tmp);
  End;


End;

Function Tform1.ConvertPacketToStr(S: String): String;
Var
 N: Integer;
 C: Char;
 BuildStr,Tmp,Tmp2: String;
 Ex: Boolean;
Begin
 S:=' '+S;
 Ex:=False;
 Tmp:=S;
 Tmp:=Form1.ReplaceStr(Tmp,#$0d+#$0a,' ');
 BuildSTR:='';
 Repeat
  If (Form1.Instr(' ',tmp,2)=3) and (Tmp[1]=' ') Then
   Begin
     Delete(Tmp,1,1);
     Tmp2:=Copy(Tmp,1,2);
     Delete(Tmp,1,2);
     Try
       C:=Chr(StrToInt('$'+tmp2));
       Except
     End;
    BuildStr:=BuildStr+C;
   End
    else
   Delete(Tmp,1,1);
 Until (Ex=True) Or (Length(Tmp)<=0);
 Result:=BuildStr;
End;


Function TForm1.PacketToPktStr(S: String): String;
Var
 BuildStr,Tmp2,Tmp: String;
 PktType: Char;
 Field,FieldVal,Code: String;
Begin
   IF Copy(S,1,4)='YMSG' Then
    Begin
     If Length(S)>11 Then
       PktType:=S[12]
        else
       Exit;
     BuildStr:='/pkt #'+IntToHex(Ord(PktType),2)+' ';
     Delete(S,1,20);
     Tmp2:=S;
     While ScanIt(Co80S,Tmp2)>0 do
      Begin
       FieldVal:=Form1.ToC080(Tmp2);
       Tmp2:=Form1.CutC080(Tmp2,1);
       Field:=Form1.ToC080(Tmp2);
       Tmp2:=Form1.CutC080(Tmp2,1);
       If Length(Field)>0 Then
         If Field[Length(Field)]='/' Then
           SetLength(Field,Length(Field)-1);
       If (Trim(Field)<>'') and (Trim(FieldVal)<>'') Then
         BuildStr:=BuildStr+FieldVal+'/%del/'+Field+'/%del/';
      End;
      SetLength(BuildStr,Length(BuildStr)-1);
      BuildStr:=BuildStr+'\\';
    End;

   If Copy(S,1,4)='YCHT' Then
    Begin
     If Length(S)>11 Then
        PktType:=S[12]
         else
        Exit;
      Tmp2:=S;
      BuildStr:='/pkt #'+IntToHex(Ord(PktType),2)+' ';
      Delete(Tmp2,1,16);
      While ScanIt(Co80S,Tmp2)>0 do
       Begin
       Field:=Form1.ToC080(Tmp2);
       Tmp2:=Form1.CutC080(Tmp2,1);
       If Trim(Field)<>'' Then
         BuildStr:=BuildStr+Field+'/%del/';
      End;
       If Trim(Tmp2)<>'' Then
         BuildStr:=BuildStr+Tmp2+'/%del/';
      SetLength(BuildStr,Length(BuildStr)-1);
      BuildStr:=BuildStr+'\\';
    End;
  Result:=BuildStr;
End;



Function Tform1.CheckAndPlaceSmileys(Richcont: TMyRichedit; Tmp: String): String;
Var
  FF1,FF2,FF3: Boolean;
Begin
     FF1:=False;
     FF2:=False;
     FF3:=False;
        If (IsSmile(LowerCaseRep(Copy(Tmp,1,4)))>0) And (FF2=False) And (FF3=False) Then
            Begin
             If Length(Tmp)>=4 Then
              Begin
               DoFace(RichCont,Copy(LowerCaseRep(Tmp),1,4));
               Delete(Tmp,1,4);
               FF3:=True;
              End;
            End;
          If (IsSmile(LowerCaseRep(Copy(Tmp,1,3)))>0) and (FF1=False) and (FF2=False) Then
           Begin
           If Length(Tmp)>=3 Then
             Begin
              DoFace(RichCont,Copy(Tmp,1,3));
              Delete(Tmp,1,3);
              FF2:=True;
             End;
           End;
        If (IsSmile(LowerCaseRep(Copy(Tmp,1,2)))>0) Then
          Begin
          If Length(Tmp)>=2 Then
            Begin
             DoFace(RichCont,Copy(Tmp,1,2));
             Delete(Tmp,1,2);
             FF1:=True;
            End;
        End;
  Result:=Tmp;
End;



function Tform1.BitmapToRTF(S: String): string;
var
  bi, bb, rtf: string;
  bis, bbs: Cardinal;
  achar: ShortString;
  hexpict: string;
  I: Integer;
  pict: Tbitmap; //proc
begin
 IF FileExists(S)=True Then
  Begin
   pict:=Tbitmap.Create;
   pict.LoadFromFile(s);
 //  Pict:=MyBmp.
   GetDIBSizes(pict.Handle, bis, bbs);
   SetLength(bi, bis);
   SetLength(bb, bbs);
   GetDIB(pict.Handle, {pict.Palette}0, PChar(bi)^, PChar(bb)^);
   rtf := '{\rtf1\pict\dibitmap ';
   SetLength(hexpict, (Length(bb) + Length(bi)) * 2);
   I := 2;
   for bis := 1 to Length(bi) do
   begin
     achar := Format('%x', [Integer(bi[bis])]);
     if Length(achar) = 1 then
       achar := '0' + achar;
     hexpict[I - 1] := achar[1];
     hexpict[I] := achar[2];
     Inc(I, 2);
   end;
   for bbs := 1 to Length(bb) do
   begin
     achar := Format('%x', [Integer(bb[bbs])]);
     if Length(achar) = 1 then
       achar := '0' + achar;
     hexpict[I - 1] := achar[1];
     hexpict[I] := achar[2];
     Inc(I, 2);
   end;
   rtf := rtf + hexpict + ' }}';
   Result := rtf;
   Pict.Free;
 End;
end;

Procedure Tform1.RicheditAltWriteWTag(RichCont: TMyRichedit; Colours,Msg: String);
Var
 Col,Col2: Tcolor;
 ColTagS: TStringList;
 TmpCol,TmpCol2,Tmp,Tmp2: String;
 N,N2: Integer;
 TempChar: Char;
 FF1,FF2,FF3: Boolean;
 WordCount,Rcmp,GCmp,BCmp,RS,GS,BS,RF,GF,BF,P1,P2: Integer;
 NewR,NewB,NewG: Integer;
 MyC,MyC2: String;
Begin
// Msg:=Remove(Msg,'<','>');
 RichCont.SelStart:=-1;
// RichCont.Lines.BeginUpdate;
 ColTags:=TStringList.Create;
 NewR:=0; NewB:=0; NewG:=0; RS:=0; GS:=0; BS:=0;
 RF:=0; GF:=0; BF:=0; P1:=0; P2:=0;
 //Msg:=Remove(Msg,#$1b,'m');
 Msg:=RicheditBold(RichCont,Msg);
 WordCount:=ScanIt(' ',Msg);
 ColCount:=ColourCount(Colours);
 Tmp2:=Msg;
 Tmp:=Colours+',';
  While PosRep(',',Tmp)>0 do
   Begin
    NewR:=0; NewB:=0; NewG:=0; RS:=0; GS:=0; BS:=0;
    RF:=0; GF:=0; BF:=0; P1:=0; P2:=0;
    P1:=PosRep(',',Tmp);
    TmpCol:=Copy(Tmp,1,p1-1);
    Delete(TmpCol,1,1);
    Try
     Tmp2:=ColorToString(ReverseColor(TmpCol));
     Except
    End; 
    ColTags.Add(Tmp2);
    Delete(Tmp,1,P1);
   End;
   N:=0;
  Tmp:=Msg+' ';
 If tmp<>'' Then
  Begin
  Try
 While ScanIt(' ',Tmp)>0 Do
    Begin
     Tmp2:=Tmp;
     Tmp:=CheckAndPlaceSmileys(RichCont,Tmp);
     If Tmp=Tmp2 Then
        Begin
         N2:=N Mod ColCount;
         Inc(N);
         Col:=StringToColor(ColTags[N2]);
         RichCont.SelAttributes.Color:=Col;
         Tmp2:=Copy(Tmp,1,PosRep(' ',Tmp));
         For N2:=1 To Length(Tmp2) Do
           RichCont.SelText:=Tmp2[n2];
         Delete(Tmp,1,Length(Tmp2));
       End;
      End;
    Except
    End;
  End;
 ColTags.Free;
// RichCont.Lines.EndUpdate;
 Form1.ScrollToEnd(Form1.Richedit1);
End;



Function DoFontSize(S: String; Fs: Integer): String;
Var
 Err,P1,P2: Integer;
 BckTmp,Tmp,Tmp2: String;
Begin
 BckTmp:=S;
 Tmp2:=S;
 S:=Tmp2;
 P1:=PosRep('<font size="',LowerCaseRep(S));
If P1>0 Then
 Begin
  P2:=Form1.InsTr('>',S,P1);
  Tmp:=Copy(S,P1,P2-P1+2);
  Delete(S,P1,Length(Tmp));
  P1:=PosRep('"',Tmp);
  P2:=Form1.InsTr('"',Tmp,P1);
  Tmp:=Copy(Tmp,P1+1,P2-P1);
//  Tmp:=Copy(Tmp,1,PosRep('"',Tmp)-1);
 If FS<>0 Then FontSizeTag:=FS
  else
 Begin
  Val(Tmp,FontSizeTag,Err);
   If Err<>0 Then
   FontSizeTag:=10;

   If Form10.RadioButton6.Checked=True Then
     If FontSizeTag>Form10.SpinEdit4.Value Then
       FontSizeTag:=Form10.SpinEdit4.Value;


   If FontSizeTag>20 Then
   If Form10.RadioButton9.Checked=False Then
     FontSizeTag:=20
      else
    FontSizeTag:=Form10.Spinedit4.Value;
    If FontSizeTag<9 Then
     FontSizeTag:=10;
  End;
  Result:=S;
 End
  Else
 Begin
  If FS<>0 Then FontSizeTag:=FS;
  Result:=BckTmp;
 End;
End;

Function YmliteLogoStr(msg: String): String;
Var
 P1,P2: Integer;
 GetOut: Boolean;
 Col,Tmp: String;
 CharS: TFontcharSet;
 Fname: TFontName;
 TFS: TfontStyles;
 Fcol: Tcolor;
Begin
Tmp:=Msg;
 Col:='';
 Col:=GetColStr(Msg);
 Msg:=Form1.ReplaceStr(Msg,'y!mlite',ymlitelogo+Col);
{ If GetUrl(Msg)='' Then
  Begin
 P1:=PosRep('ymlite',LowerCaseRep(Msg));
  If P1>0 Then
   Begin
   If (P1>=1) and (P1<7) Then
    Msg:=ReplaceStr(Msg,'ymlite',ymlitelogo2+Col)
     else
    If (Msg[p1-1]<>'/') Then
   Msg:=ReplaceStr(Msg,'ymlite',ymlitelogo+Col);
  End;
 End; }
 Result:=Msg;
End;


{Function Checkin(Who: String; Check: Boolean): Boolean;
Var
 N,R: Integer;
Begin
 Checkin:=False;
 R:=-1;
  If Ignored.IndexOf(Who)<>-1 Then
    Begin
     Result:=True;
     Exit;
    end;

  For N:=LastIn.Count-1 Downto 0 do
    IF LowerCaseRep(LowerCaseRep(LastIn[N]))=LowerCaseRep(Who) Then
     Begin
       R:=N;
       Break;
     End;

  IF (R<>-1) Then
   If (LowerCaseRep(LastIn[r])<>LowerCaseRep(LoggedINName)) Then
   Begin
    Checkin:=True;
    If Check=False Then
     Begin
//      Form1.Panel10.Font.Color:=ColSelect.AlertColor;
      Form1.Panel10.Caption:=Who+': Room Enter Message Blocked (possible spammer)...';
      AddBlockMessage(Form1.Panel10.Caption);
     End;
   End;

 If (Check=False) And (LowerCaseRep(Who)<>LowerCaseRep(LoggedInName)) Then
 Begin
  If R=-1 Then
   Begin
    LastIn.Insert(0,Who);
    If LastIn.Count>Form10.SpinEdit6.Value Then
      LastIn.Delete(LastIn.Count-1);
   End;
 End;
End;}

{Function CheckOut(Who: String; Check: Boolean): Boolean;
Var
 N,R: Integer;
Begin
 CheckOut:=False;
   If Ignored.IndexOf(Who)<>-1 Then
    Begin
     CheckOut:=True;
     Exit;
    end;
  R:=-1;
   For N:=LastOut.Count-1 Downto 0 do
    IF LowerCaseRep(LowerCaseRep(LastOut[N]))=LowerCaseRep(Who) Then
     Begin
       R:=N;
       Break;
     End;

 IF (R<>-1) Then
  If (LowerCaseRep(LastOut[r])<>LowerCaseRep(LoggedINName)) Then
   Begin
    CheckOut:=True;
   If Check=False Then
    Begin
//     Form1.Panel10.Font.Color:=ColSelect.AlertColor;
     Form1.Panel10.Caption:=Who+': Blocked Room Leave Message "possible spammer..."';
     AddBlockMessage(Form1.Panel10.Caption);
    End;
   End;

 If (R=-1) And (LowerCaseRep(Who)<>LowerCaseRep(LoggedInName)) And (Check=False) Then
   Begin
     LastOut.Insert(0,Who);
     If LastOut.Count>Form10.SpinEdit6.Value Then
      LastOut.Delete(LastOut.Count-1);
   End;
End;}

function bubblesort(strtosort: string): string;
 var
   num1,num2,bs1,bs2: byte;
   tmpstr2: string;
begin
 tmpstr2:=strtosort;
 for bs1:=1 to length(tmpstr2) do
  begin
    for bs2:=1 to length(tmpstr2)-1 do
       begin
          num1:=ord(tmpstr2[bs2]);
          num2:=ord(tmpstr2[bs2+1]);
          if num1>num2 then
            begin
              tmpstr2[bs2+1]:=chr(num1);
              tmpstr2[bs2]:=chr(num2);
            end;
       end;
   end;
  bubblesort:=tmpstr2;
end;

function MatchStr (str1, str2: pchar) : integer;
var
  letters : array [0..1, #$00..#$ff] of cardinal;
  n, len : cardinal;
  c : char;
begin
ZeroMemory(@letters, sizeof(letters));
n := 0; // count number of each letter in str1
while str1[n] > #0 do begin
  inc(letters[0][str1[n]]);
  inc(n);
end;
len := n; // save length of str1
n := 0; // count number of each letter in str2
while str2[n] > #0 do begin
  inc(letters[1][str2[n]]);
  inc(n);
end;
if n > len then len := n; // if str1 is longer than str2 then save length of str2 instead of str1
if len = 0 then begin // if length of longest string is 0 then (result = 0) and exit
  result := 0;
  exit;
end;
n := 0; // calculate difference
for c := #$00 to #$ff do begin
  if letters[0][c] < letters[1][c] then
    n := n + letters[0][c]
  else
    n := n + letters[1][c];
end;
result := trunc(n / len * 100);
end;



{Function MatchStr(Str1,Str2: String): Integer;
Var
  C,N,N2: Integer;
  OStr1,OStr2,Tmp1,Tmp2,Tmp: String;
Begin
 Result:=0;
 C:=0;
// If (Length(Str1)>0) and (Length(str2)>0) Then
 Ostr1:=Str1;
 Ostr2:=Str2;
 For N:=1 to Length(Str1) Do
  For N2:=1 To Length(Str2) DO
   If (Str1[N]=Str2[N2]) And (Str1[N]<>#0) And (Str2[N2]<>#0) Then
    Begin
     Str1[N]:=#0;
     Str2[N2]:=#0;
     Inc(C);
    End;
  Str1:=OStr1;
  Str2:=Ostr2;
 Try
   Begin
    If Length(Str1)>Length(Str2) Then
       ResBlock:=(C/Length(Str1))*100
      Else
       ResBlock:=(C/Length(Str2))*100;
   End;
  Except
 ResBlock:=0;
 End;
 Result:=Trunc(ResBlock);
End;}


Procedure Tform1.ShowWebPage;
Begin
{ If ProfileWindow=Nil Then
    ProfileWindow:=TForm16.Create(Self);
  Form1.CreateSkin(ProfileWindow);
  ProfileWindow.Show;}
  ShellExecute(handle,'open',Pchar(Path+'Cache\profile.html'),'','',0);
  Form1.ReleaseMemory;
//  ProfileWindow.WebBrowser1.Navigate(Path+'Cache\profile.html');
End;


Function DoAltTag(S: String): String;
Var
 CI,Ci2,P1,P2: Integer;
 BckTmp,Tmp3,Tmp,Tmp2: String;
Begin
 //<FADE #ff0000,#00ff00,#0000ff>hello</FADE>
 BckTmp:=S;
 Tmp3:=S;
 Result:=BckTmp;
 P1:=PosRep('<alt #',LowerCaseRep(S));
 P2:=PosRep('</alt>',LowerCaseRep(S));
 Ci2:=0;
 CI:=Form1.ScanIT('<alt',LowerCaseRep(S));
While (P1>0)and (P2>0) And (CI2<=CI) Do
 Begin
 Inc(Ci2);
 P1:=PosRep('<alt ',LowerCaseRep(S));
 P2:=PosRep('</alt>',LowerCaseRep(S));
If (P1>0) and (P2>0) Then
 Begin
  P2:=Form1.InsTr('t>',LowerCaseRep(S),P1)+1;
  Tmp:=Copy(S,P1,P2-P1+2);
  Delete(S,P1,Length(Tmp));
  Tmp2:=Tmp;
  P1:=PosRep('#',Tmp);
  P2:=Form1.InsTr('>',Tmp,P1);
  Tmp:=Copy(Tmp,P1,P2-P1+1);
  AltTag:=Tmp;
  Tmp:=bcktmp;
  P1:=PosRep('<alt',LowerCaseRep(Tmp));
  P2:=Form1.InsTr('>',Tmp,P1);
  Delete(Tmp,P1,p2-P1+2);
  Tmp:=Form1.RemoveStr('</alt>',Tmp);
  AltTagText:=Tmp;
  If (AltTagText<>'') and (AltTag<>'') Then
     AltIn:=True
      else
    AltIn:=False;
  P1:=PosRep('<alt',LowerCaseRep(Tmp3));
  P2:=Form1.Instr('t>',LowerCaseRep(Tmp3),P1);
  Delete(Tmp3,p1,P2-P1+3);
  Tmp3:=Tmp3;
  If AltIn=True Then
    Tmp3:='';
  Result:=Tmp3;
  End;
 End;
End;


Function DoAltWTag(S: String): String;
Var
 P1,P2,P3: Integer;
 Tmp,Tmp2,Tmp3: String;
Begin
 //<ALT #ff0000,#0000ff>he was..</ALT>
 Tmp3:=S;
 P1:=PosRep('<alw #',LowerCaseRep(S));
 If P1>0 Then
 Begin
  Tmp:=S;
  Tmp2:=S;
  P1:=PosRep('#',Tmp);
  P2:=Form1.InsTr('>',Tmp,P1);
  Tmp:=Copy(Tmp,P1,P2-P1+1);
  Delete(Tmp2,1,length(Tmp)+6);
  Tmp2:=Copy(tmp2,1,PosRep('<',Tmp2)-1);
  AltWTagText:=Tmp2;
  AltWTag:=Tmp;
  Tmp3:=Form1.RemoveStr('<alw '+AltWTag+'>',Tmp3);
  If (AltWTagText<>'') and (AltWTag<>'') And (P2>0) Then
     AltWIn:=True
      else
     AltWIn:=False;
{  P1:=PosRep('<alt',LowerCaseRep(Tmp3));
  P2:=Instr('t>',LowerCaseRep(Tmp3),P1);
  Delete(Tmp3,p1,P2-P1+3);
  Tmp3:=Tmp3;}
 End;
  Result:=Tmp3;
End;

Procedure Tform1.SortCustomTag;
Var
 N: Integer;
Begin
FadeData.Fade:=False;
FadeData.Alt:=False;
FadeData.AltW:=False;

 If Form9.RadioButton1.Checked=True Then
  Begin
   CustomTag:='<fade ';
   Form1.FadeData.Fade:=True;
  End;

 If Form9.RadioButton2.Checked=True Then
  Begin
   CustomTag:='<alt ';
   Form1.FadeData.Alt:=True;
  End;

 If Form9.RadioButton3.Checked=True Then
  Begin
   CustomTag:='<alw ';
   Form1.FadeData.AltW:=True;
  End;

 For N:=0 to Tcols.Count-1 do
   Begin
      CustomTag:=CustomTag+'#'+Tcols[N]+',';
   End;

  CustomTag:=Copy(CustomTag,1,Length(CustomTag)-1);
  CustomTag:=CustomTag+'>';
  Form1.FadeData.TCols.Assign(Tcols);
  Form1.FadeData.CustomTag:=CustomTag;
End;


{Procedure Tform1.SortCustomTag;
Var
 N: Integer;
Begin
   If Form9.RadioButton1.Checked=True Then
  CustomTag:='<FADE ';
 If Form9.RadioButton2.Checked=True Then
  CustomTag:='<ALT ';
 If Form9.RadioButton3.Checked=True Then
  CustomTag:='<ALW ';

 For N:=0 to Tcols.Count-1 do
   Begin
       CustomTag:=CustomTag+'#'+Tcols[N]+',';
   End;
  CustomTag:=Copy(CustomTag,1,Length(CustomTag)-1);
  CustomTag:=CustomTag+'>';
End;}

Function DoFontColor(S: String): String;
Var
 P1,P2,P3: Integer;
 Tmp,Tmp2,Tmp3: String;
Begin
 //<ALT ID=YmLite>
 Tmp3:=S;
 P1:=PosRep('<font color',LowerCaseRep(S));
 If P1>0 Then
 Begin
  P2:=Form1.InsTr('>',LowerCaseRep(S),P1);
  P3:=P1;
  Tmp:=Copy(S,P1,P2-P1+2);
  Delete(S,P1,Length(Tmp));
  Tmp2:=Tmp;
  P1:=PosRep('or=',LowerCaseRep(Tmp));
  P2:=Form1.InsTr('>',Tmp,P1);
  Tmp:=Copy(Tmp,P1+3,P2-P1-3);
  Tmp3:=Form1.RemoveStr(Tmp2,Tmp3);
 End;
  Result:=Tmp3;
End;


Function Tform1.RemoveHtmlTag(S: String): String;
Var
 P1,P2: Integer;
 Tmp: String;
Begin
{ Tmp:=S;
 P1:=PosRep('</',S);
 P2:=Instr('>',s,P1);
 If (P1>0) and (P2>0) Then
  Begin
    Delete(S,P1,P2-P1+2);
    Result:=S;
  End
   else     }
  Tmp:=S;
  Tmp:=Form1.Remove2(Tmp,'</','>');
  Result:=Tmp;
End;


Function TObjPersonality.LoadPersonality(Fn: String): Boolean;
Var
 Txt: TextFile;
 P1,P2,Tmp: String;
 C: Integer;
Begin
 C:=0;
  Result:=False;
  SetLength(Personalitys,2000);
  PersonalitySearch.Clear;
 If FileExists(Fn) Then
  Begin
    System.Assign(Txt,Fn);
    System.Reset(Txt);
    Repeat
     Readln(Txt,Tmp);
     If Length(Tmp)>0 Then
      Begin
       If (Tmp[1]<>'*') and (Tmp[1]<>'#') Then
        Begin
         P1:=Copy(Tmp,1,PosRep('|',Tmp)-1);
         Delete(Tmp,1,Length(P1)+1);
         P2:=Tmp;
         Personalitys[C].OldWord:=P1;
         Personalitys[C].NewWord:=P2;
         PersonalitySearch.AddObject(P1,@Personalitys[C]);
         Form1.Panel10.Caption:='Loading in line #'+IntTOStr(C);
         Inc(C);
        End;
      End;
    Until Eof(Txt);
    SetLength(Personalitys,C+1);
   System.Close(Txt);
  End;
 IF C>0 Then
  Result:=True;
 Form1.Panel10.Caption:='Personality File '+FN+' Loaded ('+IntToStr(C)+' Lines)';
 PersonalityLoaded:=True;
End;

Function TObjPersonality.TextToPersonality(S: String): String;
Var
  Wc,N: Integer;
  NewW,BuildStr,Txt,New1: String;
Begin
 Txt:=S;
  If PersonalityLoaded=False Then
    Result:=S
     else
    Result:='';
  WC:=0;
  If (PersonalityLoaded=True) and (Txt<>'') Then
    Begin
     Words.Clear;
     SplitWords(Txt);
      While Wc<=Words.Count-1 Do
        Begin
         NewW:='';
           If Wc+2<=Words.Count-1 Then
           Begin
            New1:=Words[Wc]+' '+Words[Wc+1]+' '+Words[Wc+2];
            NewW:=GetPersonalityWord(New1);
            If NewW<>'' Then
              Begin
               BuildStr:=BuildStr+NewW+' ';
               Inc(Wc,3);
               End;
            End;

          If (Wc+1<=Words.Count-1) And (NewW='') Then
           Begin
            New1:=Words[Wc]+' '+Words[Wc+1];
            NewW:=GetPersonalityWord(New1);
              If NewW<>'' Then
               Begin
                BuildStr:=BuildStr+NewW+' ';
                Inc(Wc,2);
              End;
            End;

          If (Wc<=Words.Count-1) And (NewW='') Then
           Begin
            New1:=Words[Wc];
            NewW:=GetPersonalityWord(New1);
              If NewW<>'' Then
               Begin
                BuildStr:=BuildStr+NewW+' ';
                Inc(Wc,1);
              End;
            End;
          If NewW='' Then
           Begin
            BuildStr:=BuildStr+Words[WC]+' ';
            Inc(WC);
           End;
        End;
     Result:=Trim(BuildStr);
    End;
End;

Function TObjPersonality.GetPersonalityWord(S: String): String;
Var
 N: Integer;
 Rec: PPersonality;
Begin
 N:=PersonalitySearch.IndexOf(S);
 IF N<>-1 Then
  Begin
   Rec:=PPersonality(PersonalitySearch.Objects[N]);
   Result:=Rec.NewWord;
  End;
End;

constructor TObjPersonality.Create;
begin
 PersonalityLoaded:=False;
 PersonalitySearch:=TStringList.Create;
end;

procedure TObjPersonality.Clear;
begin
 SetLength(Personalitys,0);
 Self.PersonalityLoaded:=False;
 PersonalitySearch.Clear;
end;

destructor TObjPersonality.Destroy;
begin
 SetLength(Personalitys,0);
 PersonalitySearch.Free;
 Inherited;
end;


Procedure TObjPersonality.TestLoad;
Begin
  LoadPersonality(path+'valley.ypf');
  GetPersonalityWord('like');
end;

Function DoFadeTag(S,UserName: String): String;
Var
 CI,Ci2,P1,P2: Integer;
 BckTmp,Tmp3,Tmp,Tmp2: String;
Begin
 //<FADE #ff0000,#00ff00,#0000ff>hello</FADE>
 BckTmp:=S;
 Tmp3:=S;
 Result:=BckTmp;
 P1:=PosRep('<fade #',LowerCaseRep(S));
 P2:=PosRep('</fade>',LowerCaseRep(S));
 Ci2:=0;
 If (PosRep('<fade ',S)>0) And (P1=0) Then
  Begin
   S:=Form1.Remove2(S,'<fade','>');
   If P2>0 Then
     S:=Form1.Remove2(S,'</fade>','>');
    Result:=S;
  End;
 CI:=Form1.ScanIT('<fade',LowerCaseRep(S));
While (P1>0)and (P2>0) And (CI2<=CI) Do
 Begin
 Inc(Ci2);
 P1:=PosRep('<fade ',LowerCaseRep(S));
 P2:=PosRep('</fade>',LowerCaseRep(S));
If (P1>0) and (P2>0) Then
 Begin
  P2:=Form1.InsTr('e>',LowerCaseRep(S),P1)+1;
  Tmp:=Copy(S,P1,P2-P1+2);
  Delete(S,P1,Length(Tmp));
  Tmp2:=Tmp;
  P1:=PosRep('#',Tmp);
  P2:=Form1.InsTr('>',Tmp,P1);
  Tmp:=Copy(Tmp,P1,P2-P1+1);
  FadeTag:=Tmp;
  Tmp:=bcktmp;
  P1:=PosRep('<fade',LowerCaseRep(Tmp));
  P2:=Form1.InsTr('>',Tmp,P1);
  Delete(Tmp,P1,p2-P1+2);
  Tmp:=Form1.RemoveStr('</fade>',Tmp);
  FadeTagText:=Tmp;
  If (FadeTagText<>'') and (FadeTag<>'') Then
     FadeIn:=True
      else
    FadeIn:=False;
  P1:=PosRep('<fade',LowerCaseRep(Tmp3));
  P2:=Form1.Instr('e>',LowerCaseRep(Tmp3),P1);
  Delete(Tmp3,p1,P2-P1+3);
  Tmp3:=Tmp3;
  If FadeIn=True Then
    Tmp3:='';
  Result:=Tmp3;
  End;
 End;
End;




Function SmileCount(Str: String): Integer;
Var
 SMC: Integer;
 BuildStr,Ts: String;
 F1,F2,F3: Boolean;
Begin
 TS:=Str;
 SMC:=0;
    While Length(TS)>0 Do
     Begin
      F1:=False; F2:=False; F3:=False;
      If IsSmile(LowerCaseRep(Copy(Ts,1,4)))<>-1 Then
       Begin
        Delete(Ts,1,4);
        Inc(Smc);
        F1:=True;
       End;
      If IsSmile(LowerCaseRep(Copy(Ts,1,3)))<>-1 Then
       Begin
        Delete(Ts,1,3);
        Inc(Smc);
        F2:=True;
       End;
      If IsSmile(LowerCaseRep(Copy(Ts,1,2)))<>-1 Then
       Begin
        Delete(Ts,1,2);
        Inc(Smc);
        F3:=True;
       End;
      If (F1=False) And (F2=False) And (F3=False) Then
       Begin
         If Length(TS)>0 Then
          Begin
           BuildStr:=BuildStr+Ts[1];
           Delete(Ts,1,1);
          End;
       End;
     End;
  Result:=SMC;
End;

Function IsSmilePos(Str: String): Integer;
 Var
   P,R,LD,N: Integer;
   FF1,FF2,FF3: Boolean;
   NewW,Tmp: String;
Begin
 Result:=-1;
 P:=0;
 Tmp:=Str;
 If Trim(Tmp)='' Then Exit;
 For N:=1 to Length(Tmp) Do
  Begin
     Inc(P);
     FF1:=False;
     FF2:=False;
     FF3:=False;
        If (IsSmile(LowerCaseRep(Copy(Tmp,P,4)))>0) And (FF2=False) And (FF3=False) Then
            Begin
             Result:=P;
             Break;
            End;
          If (IsSmile(LowerCaseRep(Copy(Tmp,P,3)))>0) and (FF1=False) and (FF2=False) Then
           Begin
             Result:=P;
             Break;
           End;
        If (IsSmile(LowerCaseRep(Copy(Tmp,P,2)))>0) Then
          Begin
            Result:=P;
            Break;
          End;
  //  Delete(Tmp,1,1);
End;
{ LD:=Length(Str);
 R:=High(Smiles);
 If Ld=1 Then
  Ld:=-1;
 IsSmilePos:=-1;
 Str:=LowerCaseRep(Str);
 For N:=1 to High(Smiles) DO
  Begin
    If PosRep(Smiles[N].KeyCombo,Str)>0
     Begin
       If PosRep(Smiles[N].KeyCombo,Str)<LD Then
        If PosRep(Smiles[N].KeyCombo,Str)<=R Then
          R:=PosRep(Smiles[N].KeyCombo,Str);
     End;
  End;            //bottleneck}
End;





Procedure RenderTextFade(RichCont: TMyRichedit; ColCode,Text: String; Buddy: Boolean);
Const
 Header: String = '{\rtf1\ansi\ansicpg1252\deff0\deflang3081{\fonttbl{\f0\fnil\fcharset0 Comic Sans MS;}{\f1\f %S;}}'+#$0d+#$0a;
 ColorTbl: String = '{{\colortbl %s;}'+#$0d+#$0a;
 MainStr: String = '\viewkind4\uc1\pard\Cf1%s}'+#$0d+#$0a;
 Var
  BuildStr,BuildStr2,TmpCol,C1,C2,S: String;
  Col,Col1,Col2: TColor;
  FontSize,N,R,G,B,I: Integer;
Begin
 FontSize:=10;
 Try
  C1:=Copy(ColCode,2,Form1.Instr('$',ColCode,2)-1);
  Delete(ColCode,1,Form1.Instr('$',ColCode,2)+1);
  C2:=ColCode;
  Col1:=StrToInt(C1);
  Col2:=StrToInt(C2);
 For I:=1 to Length(Text) Do
  Begin
   Col:=ColorGradient(Col1,Col2,Length(Text),I-1);
   TmpCol:=IntToHex(Col,6);
   B:=StrTOInt('$'+Copy(TmpCol,1,2));
   G:=StrTOInt('$'+Copy(TmpCol,3,2));
   R:=StrTOInt('$'+Copy(TmpCol,5,2));
   BuildStr:=BuildStr+';'+'\red'+IntToStr(Trunc(R))+'\green'+IntToStr(Trunc(G))+'\blue'+IntToStr(Trunc(B))+'';
  End;
  S:=BuildStr;
   BuildStr:=Format(Header,['Arial']);
   BuildStr:=BuildStr+Format(ColorTbl,[S]);
   If Buddy=True Then BuildStr2:=BuildStr2+'\i';
   BuildStr2:=BuildStr2+'\b';
   BuildStr2:=BuildStr2+'\f0\fs'+IntToStr(FontSize*2)+' ';//+Ts[1];
   For N:=1 to Length(Text) do
     BuildStr2:=BuildStr2+Format('\cf%d %s',[N,Text[N]]);
   BuildStr2:=BuildStr2+'}';
   BuildStr:=BuildStr+Format(MainStr,[BuildStr2]);
   Form1.SetSelectionRtf(RichCont,buildStr);
 //S:=RicheditFadeStr(FT,Ts2);  //working one
 Except
  RichCont.SelText:=Text;
 End;
End;
//RenderTextFade(Chatters[Form1.ChatterNum(FromWho)].ColIDStr,FromWho+'*')

Function ConverTToRGB(StrCol: String): Boolean;
Var
 TmpCol: String;
Begin
 Result:=False;
If StrCol<>'' Then
 Begin
  Result:=True;
  TmpCol:=StrCol;
  Try
   R:=StrToInt('$'+Copy(TmpCol,2,2));
   G:=StrToInt('$'+Copy(TmpCol,4,2));
   B:=StrToInt('$'+Copy(TmpCol,6,2));
    Except
   End;
 End;
End;


Function IsColorToBright(StrCol: String): Boolean;
Var
 TmpCol: String;
 MR,Mg,Mb: Integer;
Begin
 Result:=False;
If StrCol<>'' Then
 Begin
  Result:=True;
  TmpCol:=StrCol;
  Try
   MR:=StrToInt(Copy(TmpCol,2,2));
   mG:=StrToInt(Copy(TmpCol,4,2));
   mB:=StrToInt(Copy(TmpCol,6,2));
    Except
   End;
 End;

   If (Mr>220) and (Mg>220) Then
     Result:=True;
End;


Function TForm1.TcolToYcol(TheCol: Tcolor): String;
Var
 TmpCol: String;
 MyR,MyG,MyB: Integer;
Begin
 TmpCol:=IntToHex(TheCol,6);
  {B G R}
Result:='';
If TmpCol<>'' Then
 Begin
   Try
   MyR:=StrToInt('$'+Copy(TmpCol,5,2));
   MyG:=StrToInt('$'+Copy(TmpCol,3,2));
   MyB:=StrToInt('$'+Copy(TmpCol,1,2));
    Except
   End;
 End;
//  ClGreen
 Result:=Ycustom+'#'+IntToHex(MyR,2)+IntToHex(MyG,2)+IntToHex(MyB,2)+'m';
End;



Function CreateRTFFadeStr(Colours,Msg: String): String;
Var
 OldCol,BuildStr,TmpCol2,TmpCol,Tmp: String;
 ColorCount,Step,N,P1,P2,CharCount: Integer;
 ResCol,Col1,Col2: TColor;
 L,SR,SG,SB: Integer;
Begin
 BuildStr:='';
 ColorCount:=0;
  CharCount:=Length(Msg);
  Tmp:=Colours+',';
  For N:=1 to Length(Tmp) do
    If Tmp[N]=',' Then
      Inc(ColorCount);
  Step:=CharCount div ColorCount;
  N:=0;
  l:=0;
  While (PosRep(',',Tmp)>0) do
   Begin
    P1:=PosRep(',',Tmp);
    TmpCol:=Copy(Tmp,1,p1-1);
    Delete(Tmp,1,P1); //TmpCol = First ColorString (e=g #FF0000)
    P1:=PosRep(',',Tmp);
    TmpCol2:=Copy(Tmp,1,p1-1);
    If TmpCol2='' Then Exit;
   // Delete(Tmp,1,P1);  //TmpCol2 = Second ColorString (eg #00FF00)
    If Msg<>'' Then
      Begin
       Col1:=StrToInt('$'+Copy(TmpCol,2,Length(TmpCol)-1));
        If TmpCol2<>'' Then
       Col2:=StrToInt('$'+Copy(TmpCol2,2,Length(TmpCol2)-1));

       // new code
        If L=0 Then
        Begin
          TmpCol:=IntToHex(Col1,6);
          SR:=StrToInt('$'+Copy(TmpCol,1,2));
          SG:=StrToInt('$'+Copy(TmpCol,3,2));
          SB:=StrToInt('$'+Copy(TmpCol,5,2));
          BuildStr:=BuildStr+';'+'\red'+IntToStr(SR)+'\green'+IntToStr(SG)+'\blue'+IntToStr(SB)+'';
          L:=1;
        End;
       //

       For N:=1 to Step Do
        Begin
           ResCol:=ColorGradient(Col1,Col2,Step,N);
           TmpCol:=IntToHex(ResCol,6);
           SR:=StrToInt('$'+Copy(TmpCol,1,2));
           SG:=StrToInt('$'+Copy(TmpCol,3,2));
           SB:=StrToInt('$'+Copy(TmpCol,5,2));
           BuildStr:=BuildStr+';'+'\red'+IntToStr(SR)+'\green'+IntToStr(SG)+'\blue'+IntToStr(SB)+'';
        End;
     End;
     OldCol:=TmpCol;
     TmpCol:='';
     TmpCol2:='';
     Result:=BuildStr;
  End;
End;

Procedure ColorText(RichCont: TMyRichedit;FindStr: String; Col: Tcolor);
Var
 P1,Len: Integer;
 TmpStr: String;
begin
{ RichCont.SelStart:=0;}
 TmpStr:=RichCont.Text;
 P1:=0;
While Form1.Instr(LowerCaseRep(FindStr),LowerCaseRep(TmpStr),P1)>0 Do
 Begin
   P1:=Form1.Instr(LowerCaseRep(FindStr),LowerCaseRep(TmpStr),P1)+1;
   Len:=Length(FindStr);
   RichCont.SelStart:=P1-1;
   RichCont.SelLength :=Len;
   RichCont.SelAttributes.Color:=Col;
 End;
// RichCont.Lines.EndUpdate;
End;


Function ColourOf(Col: String): Tcolor;
Var
 P1,P2: Integer;
 Res,MyC: String;
Begin
 Result:=-1;
 If Col=Yblack then Result:=ClBlack;
 If Col=Ypurple then Result:=ClPurple;
 If Col=yBlue then Result:=CLblue;
 If Col=yPink then Result:=clFuchsia;
 If Col=yLime then Result:=ClLime;
 If Col=YRed then Result:=ClRed;
 If Col=yCyan then Result:=ClTeal;
 If Col=yGray then Result:=ClGray;
 If Col=yGreen then Result:=ClGreen;
 If Col=yGreen then Result:=ClGreen;
 If Col=yOrange then Result:=ClOlive;
 Try
   Res:='#'+IntToHex(Result,6);
   R:=StrToInt('$'+Copy(Res,2,2));
   G:=StrToInt('$'+Copy(Res,4,2));
   B:=StrToInt('$'+Copy(Res,6,2));
  Except
 End;

 If Length(Col)>5 Then
  Begin
    P1:=PosRep('[',col)+1;
    P2:=PosRep('m',col)-1;
    Col:=Copy(Col,p1,P2-P1+1);
    Try
     R:=StrToInt('$'+Copy(Col,6,2));
     G:=StrToInt('$'+Copy(Col,4,2));
     B:=StrToInt('$'+Copy(Col,2,2));
     MyC:='$'+IntToHex(B,2)+IntToHex(G,2)+IntToHex(R,2);
     Result:=StringToColor(MyC);
      Except
      End;
  End
End;

Function Tform1.LengthtoStr(Num: Integer): String;
Begin
   Result:='';
   Result:=chr(Num Div 256)+Chr(Num Mod 256);
End;

Function LengthtoStr2(Num: Integer): String;
 Var
  R,I: integer;
  Str: String;
Begin
 R:=Num;
 I:=0;
 str:='  ';
  While R>255 Do
     begin
       dec(R,256);
       inc(i);
     end;
    Str[1]:=chr(i);
    Str[2]:=chr(R);
  Result:=Str; //+' ('+inttohex(i,2)+' '+inttohex(r,2)+')';    //-1 for offest?
End;


Function TForm1.Pm(ToWho,WhoFrom,Msg: String): String;
Var
 Data,Tmp: String;
 Len: Integer;
Begin
 Len:=$10+Length(ToWho)+Length(WhoFrom)+Length(Msg);
 Tmp:='YMSG'+#$00+GVN+#$0+#$0+LengthToStr(len)+#$0;//LengthToStr(Length(Data)-11);
 Data:=#$06+#$5A+#$55+#$AA+#$55+key+#$31+#$C0+#$80+WhoFrom+#$C0+#$80+#$35+#$C0+#$80+ToWho+#$C0+#$80+#$31+#$34+#$C0+#$80+Msg+#$C0+#$80;
 Tmp:=Tmp+Data;
 Result:=Tmp;
End;

Function TForm1.GetToken(FromWho: String): String;
Var
 PayLoad,Data,Tmp: String;
 ActLen,Len: Integer;
Begin
Form1.MyCam:=False;
If Form2.RadioButton1.Checked=True Then
 Begin
  Payload:='1'+co80s+LoggedInName+co80s+'5'+co80s+FromWho+co80s;
  ActLen:=Length(PayLoad);
  Tmp:='YMSG'+#$00+GVN+#$0+#$0+LengthToStr(ActLen)+#$0+#$50+#$0+#$0+#$0+#$0+Key;
  Tmp:=Tmp+PayLoad;
  Result:=Tmp;
 End;
End;

Function TForm1.GetWebCamToken: String;
Var
 PayLoad,Data,Tmp: String;
 ActLen,Len: Integer;
Begin
 Form1.MyCam:=True;
If Form2.RadioButton1.Checked=True Then
 Begin
  Payload:='11'+co80s+LoggedInName+co80s;
  ActLen:=Length(PayLoad);
  Tmp:='YMSG'+#$00+GVN+#$0+#$0+LengthToStr(ActLen)+#$0+#$50+#$0+#$0+#$0+#$0+Key;
  Tmp:=Tmp+PayLoad;
  Result:=Tmp;
 End;
End;



Function TForm1.InviteToViewCam(Who: String): String;
Var
 PayLoad,Data,Tmp: String;
 ActLen,Len: Integer;
Begin
If Form2.RadioButton1.Checked=True Then
 Begin
//  Payload:=co80s+'5'+co80s+Who+co80s+'4'+co80s+LoggedInName+co80s+'14'+co80s+'13'+co80s+'0'+co80s+'49'+co80s+'WEBCAMINVITE'+co80s;
  PayLoad:='49'+Co80s+'WEBCAMINVITE'+co80s+'14'+co80s+' '+co80s+'13'+co80s+'0'+co80s+'1'+co80s+LoggedInName+co80s+'5'+co80s+who+co80s+#0;
  ActLen:=Length(PayLoad);
  Tmp:='YMSG'+#$00+GVN+#$0+#$0+LengthToStr(ActLen)+#$0+#$4B+#$0+#$0+#$0+#$0+Key;
  Tmp:=Tmp+PayLoad;
  Result:=Tmp;
 End;
End;

Function TForm1.InviteToViewCamBoot(Who: String): String;
Var
 PayLoad,Data,Tmp,Tmp2,Tmp3: String;
 ActLen,Len: Integer;
 Filler: String;
Begin
If Form2.RadioButton1.Checked=True Then
 Begin
  Tmp2:=Who;
  Tmp3:=Who;
  For N:=1 to 5 do
   Tmp2:=Tmp2+Who+',';
    SetLength(Tmp2,Length(Tmp2)-1);
   Who:=Tmp2;
// Who:=Tmp3;
 SetLength(Filler,824);
 FillChar(Filler[1],824,Ord('?'));
//  PayLoad:='49'+Co80s+'WEBCAMINVITE'+co80s+'14'+co80s+' '+co80s+'13'+co80s+'0'+co80s+'1'+co80s+LoggedInName+co80s+'5'+co80s+who+co80s+#0;
  PayLoad:='49'+Co80s+Filler+co80s+'14'+co80s+' '+co80s+'13'+co80s+'0'+co80s+'1'+co80s+LoggedInName+co80s+'5'+co80s+who+co80s+#0;  
  ActLen:=Length(PayLoad);
  Tmp:='YMSG'+#$00+GVN+#$0+#$0+LengthToStr(ActLen)+#$0+#$4B+#$0+#$0+#$0+#$0+Key;
  Tmp:=Tmp+PayLoad;
  Result:=Tmp;
 End;
End;

{Function TForm1.InviteToViewCam(Who: String): String;
Var
 PayLoad,Data,Tmp: String;
 ActLen,Len: Integer;
Begin
If Form2.RadioButton1.Checked=True Then
 Begin
//  Payload:=co80s+'5'+co80s+Who+co80s+'4'+co80s+LoggedInName+co80s+'14'+co80s+'13'+co80s+'0'+co80s+'49'+co80s+'WEBCAMINVITE'+co80s;
  PayLoad:='49'+Co80s+'WEBCAMINVITE'+co80s+'14'+co80s+' '+co80s+'13'+co80s+'0'+co80s+'1'+co80s+LoggedInName+co80s+'5'+co80s+who+co80s+#0;
  ActLen:=Length(PayLoad);
  Tmp:='YMSG'+#$00+GVN+#$0+#$0+LengthToStr(ActLen)+#$0+#$4B+#$0+#$0+#$0+#$0+Key;
  Tmp:=Tmp+PayLoad;
  Result:=Tmp;
 End;
End;}


Procedure Tform1.UpdateWindows(Refresh: Boolean);
 Var
  N: Integer;
  Chk: Boolean;
Begin
{If Refresh=False Then
 Begin
 For N:=Form50.CheckListBox1.Items.Count-1 downto 0 do
  Begin
   Chk:=Form50.CheckListBox1.Checked[N];
    If Form50.CheckListBox1.Items[N]='Programmable Buttons' Then Form50.CheckListBox1.Checked[N]:=Form1.DfsToolBar1.Visible;
//    If Form50.CheckListBox1.Items[N]='Users Ignored' Then Form50.CheckListBox1.Checked[N]:=Form1.Panel8.Visible;
    If Form50.CheckListBox1.Items[N]='Dock Site (Top)' Then Form50.CheckListBox1.Checked[N]:=Form1.SpSkinControlBar1.Visible;
    If Form50.CheckListBox1.Items[N]='Dock Site (Bottom)' Then Form50.CheckListBox1.Checked[N]:=Form1.SpSkinControlBar2.Visible;
    If Form50.CheckListBox1.Items[N]='Alert Bar' Then Form50.CheckListBox1.Checked[N]:=Form1.Panel3.Visible;
  End;
 End;
  If Refresh=True Then
   Begin
 For N:=Form50.CheckListBox1.Items.Count-1 downto 0 do
  Begin
   Chk:=Form50.CheckListBox1.Checked[N];
    If Form50.CheckListBox1.Items[N]='Programmable Buttons' Then Form1.DfsToolBar1.Visible:=Chk;
//    If Form50.CheckListBox1.Items[N]='Users Ignored' Then Form1.Panel8.Visible:=Chk;
    If Form50.CheckListBox1.Items[N]='Dock Site (Top)' Then Form1.SpSkinControlBar1.Visible:=Chk;
    If Form50.CheckListBox1.Items[N]='Dock Site (Bottom)' Then Form1.SpSkinControlBar2.Visible:=Chk;
    If Form50.CheckListBox1.Items[N]='Alert Bar' Then Form1.Panel3.Visible:=Chk;
  End;
 End;}
End;



Function TForm1.PmFake(ToWho,WhoFrom,Msg: String): String;
Var
 PayLoad,Data,Tmp: String;
 Len: Integer;
Begin


If Form2.RadioButton1.Checked=True Then
 Begin
  Payload:='1'+#$C0+#$80+WhoFrom+#$C0+#$80+'5'+#$C0+#$80+ToWho+#$C0+#$80+'14'+#$C0+#$80+Msg+#$C0+#$80+'97'+co80s+'1'+co80s+'63'+co80s+#$3B+#$30+co80s+'64'+co80s+'0'+co80s;
  Len:=Length(PayLoad);
  Tmp:='YMSG'+#$00+GVN+#$0+#$0+LengthToStr(Len)+#$0+#$06+#$5A+#$55+#$AA+#$56+Key;
  Tmp:=Tmp+PayLoad;
 End;

If Form2.RadioButton4.Checked=True Then
 Begin
  PayLoad:=Delim+'32'+Delim+ToWho+Delim+'31'+Delim+WhoFrom+Delim+'41'+Delim+Msg;
  Len:=Length(PayLoad);
  Tmp:='SPRT'+#0+#0+#0+#0+Key+LengthToStr(Len)+#$30;
  Tmp:=Tmp+PayLoad;
  Result:=Tmp;
 End;

 PmFake:=Tmp;
End;

Function TForm1.Stealth: String;
Var
 PayLoad,Tmp,Tmp2: String;
 ActLen: Integer;
Begin
 Payload:='1'+#$C0+#$80+LoggedInName+#$C0+#$80+'62'+#$C0+#$80+'0'+#$C0+#$80+'104'+#$C0+#$80+GPRoomName+#$C0+#$80+'109'+#$C0+#$80+LoggedInName;
 ActLen:=Length(PayLoad);
 Tmp:='YMSG'+#$00+GVN+#$0+#$0+LengthToStr(ActLen)+#$0+#$9B+#$0+#$0+#$0+#$0+Key;
 Tmp2:=Tmp+PayLoad;


 Payload:='1'+#$C0+#$80+LoggedInName+#$C0+#$80+'62'+#$C0+#$80+'0'+#$C0+#$80+'104'+#$C0+#$80+GPRoomName+#$C0+#$80;
 ActLen:=Length(PayLoad);
 Tmp:='YMSG'+#$00+GVN+#$0+#$0+LengthToStr(ActLen)+#$0+#$98+#$0+#$0+#$0+#$0+Key;
 Tmp:=Tmp2+Tmp+PayLoad;

 Result:=Tmp;

End;

function TForm1.InviteUser(WhoFrom, ToWho,RoomName: String; CalcLag,GotoUser,GotoUserAccepted: Boolean): String;
Var
 PayLoad,Tmp: String;
 Len: Integer;
Begin
CLagTime:=Now;
If Form2.RadioButton1.Checked=True Then
 Begin
  If CalcLag=True Then
    Payload:='1'+#$C0+#$80+whofrom+#$C0+#$80+'118'+#$C0+#$80+ToWho+#$C0+#$80+'104'+#$C0+#$80+RoomName+#$c0+#$80+'117'+#$c0+#$80'Lag Time.'+#$c0+#$80+'129'+#$c0+#$80+Form22.Edit3.text+#$c0+#$80
      else
    Payload:='1'+#$C0+#$80+whofrom+#$C0+#$80+'118'+#$C0+#$80+ToWho+#$C0+#$80+'104'+#$C0+#$80+RoomName+#$c0+#$80+'117'+#$c0+#$80'You have Been Invited to Join '+RoomName+#$c0+#$80+'129'+#$c0+#$80+Form22.Edit3.text+#$c0+#$80;

   If GotoUser=True Then
    Begin
     Form1.GenerateInviteKey;
     Payload:='1'+#$C0+#$80+whofrom+#$C0+#$80+'118'+#$C0+#$80+ToWho+#$C0+#$80+'104'+#$C0+#$80+RoomName+#$c0+#$80+'117'+#$c0+#$80'Goto Request:'+Form1.InviteKey+':'+RoomName+'::'+Form22.Edit3.text+#$c0+#$80+'129'+#$c0+#$80+Form22.Edit3.text+#$c0+#$80;
    End;

   If GotoUserAccepted=True Then
     Payload:='1'+#$C0+#$80+whofrom+#$C0+#$80+'118'+#$C0+#$80+ToWho+#$C0+#$80+'104'+#$C0+#$80+RoomName+#$c0+#$80+'117'+#$c0+#$80'Goto Accepted:'+Form1.InviteKey+#$c0+#$80+'129'+#$c0+#$80+Form22.Edit3.text+#$c0+#$80;

  Len:=Length(PayLoad);
  Tmp:='YMSG'+#$00+GVN+#$0+#$0+LengthToStr(Len)+#$0+#$9D+#$0+#$0+#$0+#$0+Key;
 End;


 If Form2.RadioButton4.Checked=True Then
  Begin
   PayLoad:=Delim+'41'+Delim+'Please Join Me'+Delim+'32'+Delim+ToWho+Delim+'31'+LoggedInName;
   Len:=Length(PayLoad);
   Tmp:='SPRT'+#0+#0+#0+#0+Key+LengthToStr(Len)+#$25;
  End;

 Tmp:=Tmp+PayLoad;
 InviteUser:=Tmp;
end;


function TForm1.RequestFile(WhoFrom, ToWho,RoomName: String): String;
Var
 PayLoad,Tmp: String;
 Len: Integer;
Begin
 Payload:='5'+#$C0+#$80+whofrom+#$C0+#$80+'49'+#$C0+#$80+'FILEXFER'+#$C0+#$80+'1'+#$C0+#$80+LoggedInName+#$c0+#$80+'13'+#$c0+#$80+'1'+#$c0+#$80+'27'+#$c0+#$80'+update.txt+'+#$c0+#$80+'28'+co80s+'4452'+co80s+'20'+'http://127.0.0.1'+co80s+'14'+co80s+co80s+'53'+co80s+'Messenger';
 Len:=Length(PayLoad);
 Tmp:='YMSG'+#$00+GVN+#$0+#$0+LengthToStr(Len)+#$0+#$4D+#$0+#$0+#$0+#$0+Key;
 Tmp:=Tmp+PayLoad;
 RequestFile:=Tmp;
 Form1.SendText(Tmp);
end;

Procedure tform1.CleanSmileyFile(F: String);
Var
  T: TstringList;
  N: Integer;
Begin
If FileExists(F) Then
 Begin
  T:=TstringList.Create;
  T.LoadFromFile(F);
   For N:=T.Count-1 Downto 0 do
    If Trim(T.Strings[N])='' Then
      T.Delete(N);
  T.SaveToFile(F);
  T.Free;
 End;
End;

Function CheckAndMergeNewFile: Boolean;
Var
  T,T2: TstringList;
  N: Integer;
Begin
If (FileExists(path+'rtfimages\smileyref.txt')) and (FileExists(path+'rtfimages\smileyext.txt')) Then
 Begin
  Result:=False;
  T:=TstringList.Create;
  T2:=TstringList.Create;
  T.LoadFromFile(Path+'rtfimages\smileyext.txt');
  T2.LoadFromFile(Path+'rtfimages\smileyref.txt');
   For N:=0 to T.Count-1 do
    If Trim(T.Strings[N])<>'' Then
       T2.Add(T.Strings[N]);
  T2.SaveToFile(Path+'rtfimages\smileyref.txt');
  T2.Free;
  T.Free;
  DeleteFile(Path+'rtfimages\smileyext.txt');
  Result:=True;
 End;
End;

Function TForm1.ContactInfo(ToWho,FromWho: String): String;
Var
 PayLoad,Tmp: String;
 ActLen: Integer;
Begin
 Payload:='49'+#$C0+#$80+'CONTACTINFO'+#$C0+#$80+'1'+#$C0+#$80+fromwho+#$C0+#$80+'14'+#$C0+#$80+'Your Master'+#$C0+#$80+'0'+#$C0+#$80+'13'+#$C0+#$80+'0'+#$C0+#$80+'5'+#$C0+#$80+ToWho+#$C0+#$80;
 ActLen:=Length(PayLoad);
 Tmp:='YMSG'+#$00+GVN+#$0+#$0+LengthToStr(ActLen)+#$0+#$4B+#$0+#$0+#$0+#$0+Key;
 Tmp:=Tmp+PayLoad;
 ContactInfo:=Tmp;
End;

Procedure Tform1.Invite(Username: String; CalcLag,GotoUser,GotoUserAccepted: Boolean);
Begin
 Form1.Richedit1.SelStart:=-1;
 Form1.SendText(Form1.InviteUser(LoggedInName,username,GproomName,CalcLag,GotoUser,GotoUserAccepted));
 //Form1.Richedit1.Lines.adD('Invited '+UserName+' to join us!');
 Form1.ScrollToEnd(Form1.Richedit1);
End;


Procedure TForm1.SendText(Str: String);
Var
 N: Integer;
Begin
{ If PingP<>'' Then
  Begin
   Str:=Str+PingP;
   PingP:='';
  End;}

 Inc(SentK,Length(Str));
 If (Form1.YMSG.Active=True) or (Form1.SPRT.Active=True) Then
  Begin
//   Form15.Edit1.Text:=InTToStr(SentK div 1024)+'K ('+IntToStr(SentK)+' Bytes)';
    If (SentK div 1024)>0 Then
     Begin
      Panel16.Caption:='Sent: '+InTToStr(SentK div 1024)+'K';
     End
       Else
     Begin
       Panel16.Caption:='Sent: '+InTToStr(SentK)+' Bytes';
     End;


    If Form2.RadioButton1.Checked=True Then
       Form1.YMSG.Socket.SendText(Str);


{     For N:=1 to Length(Str) Do
      Begin
       Form1.YMSG.Socket.SendText(Str[N]);
      End;}


    If Form2.RadioButton4.Checked=True Then
       Form1.SPRT.Socket.SendText(Str);

       Form1.DebugPacket(Str,0);
  End;
End;

Function ByteAdder(B1,B2: Byte): Integer;
 Var
  R: integer;
Begin
 R:=(B1*256)+B2;
 ByteAdder:=R;    //-1 for offest?
End;

Function Tform1.LoadButtonInfo(Cpt,QS,Dta: String): String;
 Var
  T: TFasTiniFile;
Begin
 T:=TFastiniFile.Create(Path+'Buttons.ini');
  Result:=T.ReadString(Cpt,QS,'');
 T.Free;
End;

Function AddSprtBuddy(UserName,Who: String): String;
Var
 Tmp,PayLoad: String;
 Len: Integer;
Begin
  PayLoad:=Delim+'32'+Delim+Who+Delim+'31'+Delim+UserName+Delim+'122'+Delim+'1';
  Len:=Length(PayLoad);
  Tmp:='SPRT'+#0+#0+#0+#0+Key+Form1.LengthToStr(Len)+#$27;
  Tmp:=Tmp+PayLoad;
  Result:=Tmp;
  Friends.Add(UserName,Nil);
  If Form27.ListBox1.Items.IndexOf(UserName)=-1 Then
     Form27.ListBox1.Items.Add(UserName);
  If Form12.ListBox1.Items.IndexOf(UserName)=-1 Then
     Form12.ListBox1.Items.Add(UserName);     
End;

Function RemoveSprtBuddy(UserName,Who: String): String;
Var
 Tmp,PayLoad: String;
 Len: Integer;
Begin
  PayLoad:=Delim+'32'+Delim+Who+Delim+'31'+Delim+UserName+Delim+'122'+Delim+'2';
  Len:=Length(PayLoad);
  Tmp:='SPRT'+#0+#0+#0+#0+Key+Form1.LengthToStr(Len)+#$27;
  Tmp:=Tmp+PayLoad;
  Result:=Tmp;
End;

//'Buttons' 'Name' 'Fred';
//'Buttons' 'Color' 'Pink';
//'Buttons' 'command 'do this!';

Function Tform1.SaveButtonInfo(V: Integer; QS,Dta: String): String;
 Var
  T: TFastiniFile;
Begin
 T:=TFastiniFile.Create(Path+'Buttons.ini');
 T.WriteString(IntToStr(V),Qs,Dta);
 T.Free;
End;


Procedure Tform1.CreateButtons;
Var
 N: Integer;
 State: Boolean;
begin
 State:=SpSkinPanel2.Visible;
 SpSkinPanel2.Visible:=False;
// Panel14.Height:=SpSkinPanel2.Height-4;
 SetLength(ProgButtons,11);
 For N:=9 downto 0 do
  Begin
   If ProgButtons[N]=Nil Then
    Begin
     ProgButtons[N]:=TspSkinButton.Create(Nil);
      With ProgButtons[n] Do
       Begin
         Application.ProcessMessages;
         DoubleBuffered:=False;
//         Visible:=False;
         Parent:=Form1.SpSkinPanel2;
//         Width:=(Form1.Width-28-Panel14.Width) div 10;  //73
         ProgButtons[N].Width:=(Form1.SpSkinPanel2.Width-SpSkinSpinEdit1.Width) div 10;  //73
         ProgButtons[N].Left:=N*ProgButtons[N].Width;
//         Color:=Form10.ColorBox5.ColorValue;
//         Font.Color:=Form10.ColorBox6.ColorValue;
         ConStraints.MaxHeight:=22;
         Caption:=IntToStr(N+1)+'.'+Form1.LoadButtonInfo(IntToStr(N+1),'Name',IntToStr(N+1)); //IntToStr(N);
         Constraints.MinWidth:=20;
         OnClick:=Form1.UserButton;
         OnMouseDown:=UserKeyDown;
         OnMouseMove:=UserMouseMove;
         SkinData:=spSkinData1;
    //     TfadeWindow.Create(ProgButtons[n],Form10.ColorBox5.ColorValue,ClBlue,20,100*N);
        End;
     End
      else
        ProgButtons[N].Caption:=FloatToStr(N+Form1.SpSkinSpinEdit1.Value)+'.'+Form1.LoadButtonInfo(FloatToStr(N+SpSkinSpinEdit1.Value),'Name',FloatToStr(N+SpSkinSpinEdit1.Value));
{       If Form1.SpinEdit1.Value<=10 Then
         ProgButtons[N].Caption:=IntToStr(N+Form1.SpinEdit1.Value)+'.'+Form1.LoadButtonInfo(IntToStr(N+Spinedit1.Value),'Name',IntToStr(N+SpinEdit1.Value)) //IntToStr(N)
          else
         ProgButtons[N].Caption:=IntToStr(N)+'.'+Form1.LoadButtonInfo(IntToStr(N),'Name',IntToStr(N)); //IntToStr(N)}
    End;
 SpSkinPanel2.Visible:=State;
 Form1.ViewButtons1.Visible:=False;
End;

Procedure Tform1.ViewButtons;
Var
 N: Integer;
 State: Boolean;
begin
 For N:=9 downto 0 do
  Begin
   If ProgButtons[N]<>Nil Then
        ProgButtons[N].Caption:=FloatToStr(N+Form1.SpSkinSpinEdit1.Value)+'.'+Form1.LoadButtonInfo(FloatToStr(N+SpSkinSpinEdit1.Value),'Name',FloatToStr(N+SpSkinSpinEdit1.Value));
  End;
End;

Procedure Tform1.ResizeButtons;
Var
 N: Integer;
 State: Boolean;
begin
 For N:=9 downto 0 do
  Begin
   If ProgButtons[N]<>Nil Then
    Begin
      ProgButtons[N].Width:=(Form1.SpSkinPanel2.Width-SpSkinSpinEdit1.Width) div 10;  //73
      ProgButtons[N].Left:=N*ProgButtons[N].Width;
     End;
  End;
End;





Function DebugKnownType(S: String): String;
Var
 Ptype: Integer;
Begin
If Length(S)>12 Then
 Begin
 Ptype:=Ord(S[12]);
  Case Ptype Of
  //    0: DebugKnownType:='Packet 0';
      1: DebugKnownType:='Login Packet';
      2: DebugKnownType:='Logoff Packet';
      3: DebugKnownType:='Messenger Away';
      4: DebugKnownType:='Available';
      6: DebugKnownType:='PM YMSG';
    $18: DebugKnownType:='Invite To Conference';
    $20: DebugKnownType:='PM YCHT';
    $A8: DebugKnownType:='Chat Packet Main Room';
    $9B: DebugKnownType:='Someone Just Left Chat Room';
    $9D: DebugKnownType:='Room Invite';
    $96: DebugKnownType:='Init Room Login';
    $55: DebugKnownType:='Friends OnLine.';
    $54: DebugKnownType:='Sign In';
    $0B: DebugKnownType:='Mail Notify';
    $0F: DebugKnownType:='Request to  be a yahoo buddy!';
    $97: DebugKnownType:='Goto User';
    $98: DebugKnownType:='Enter Room Event';
    $A0: DebugKnownType:='Leave Room Event';
    $0A: DebugKnownType:='Buddy Status';
    $A1: DebugKnownType:='Ping Packet';
    $4B: DebugKnownType:='User Typing Message';
    $57: DebugKnownType:='Sending Login ID';
    $83: DebugKnownType:='Confirmation of Add Buddy';
    $84: DebugKnownType:='Confirmation of Remove Buddy';
   // $31: DebugKnownType:='Room List...';
     Else
    DebugKnownType:='Unknown...';
   End;
 End;
End;

Function Tform1.GetandSaveData(Func: Integer; url,filename: String): Boolean;
Begin
End;


Function TForm1.LoginString(UserName: String): String;
Var
 ActLen: integer;
 PayLoad,Tmp: String;
Begin
 Payload:=#$31+#$C0+#$80+UserName+#$C0+#$80;
 ActLen:=Length(PayLoad);
 Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(ActLen)+#$00+#$57+#$00+#$00+#$00+#$00+#$00+#$00+#$00+#$00;
// ActLen2:=Length(Tmp);  //20!
 Tmp:=Tmp+PayLoad;
 LoginString:=Tmp;
End;

Function TForm1.LoginString2(UserName: String; Mode: Byte): String;
Var
 ActLen: integer;
 PayLoad,Tmp: String;
Begin
 Form1.BootResist:=Mode;
 Payload:=#$31+#$C0+#$80+UserName+#$C0+#$80;
 ActLen:=Length(PayLoad);
  Case Mode Of
   0: Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(ActLen)+#$00+#$57+#$00+#$00+#$00+#$00+#$00+#$00+#$00+#$00;
   1: Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(ActLen)+#$00+#$57+#$00+#$00+#$00+#$00+#$00+#$00+#$00+#$00;
   2: Tmp:='YMSG'+#$00+#$0A+#$0+#$0+Form1.LengthToStr(ActLen)+#$00+#$57+#$00+#$00+#$00+#$00+#$00+#$00+#$00+#$00;
  End; 
// ActLen2:=Length(Tmp);  //20!
 Tmp:=Tmp+PayLoad;
 LoginString2:=Tmp;
End;

{Procedure Tform1.RemoveBuddy(UserName,BuddyName,SubHead: String);
Var
  Payload,Tmp: String;
  ActLen: Integer;
Begin
 Payload:='1'+#$C0+#$80+UserName+#$C0+#$80+'7'+#$C0+#$80+buddyname+#$C0+#$80+'14'+#$c0+#$80+Subhead+#$c0+#$80;
 ActLen:=Length(PayLoad);
 Tmp:='YMSG'+#$0a+#$0+#$0+#$0+LengthToStr(ActLen)+#$0+#$86+#$0+#$0+#$0+#$0+Key;
 Tmp:=Tmp+PayLoad;
 Form1.SendText(Tmp);
End;

Procedure Tform1.AddBuddy(UserName,BuddyName,Subhead: String);
Var
  Payload,Tmp: String;
  ActLen: Integer;
Begin
 Payload:='1'+#$C0+#$80+UserName+#$C0+#$80+'7'+#$C0+#$80+buddyname+#$C0+#$80+'14'+#$C0+#$80+#$c0+#$80+'65'+#$c0+#$80+Subhead+#$c0+#$80;
 ActLen:=Length(PayLoad);
 Tmp:='YMSG'+#$00+#$0+#$0+#$0A+LengthToStr(ActLen)+#$0+#$83+#$0+#$0+#$0+#$0+Key;
 Tmp:=Tmp+PayLoad;
 Form1.SendText(Tmp);
 Payload:='1'+#$C0+#$80+UserName+#$C0+#$80;
 ActLen:=Length(PayLoad);
 Tmp:='YMSG'+#$00+GVN+#$0+#$0A+LengthToStr(ActLen)+#$0+#$12+#$0+#$0+#$0+#$0+Key;
 Tmp:=Tmp+PayLoad;
 Form1.SendText(Tmp);
End;}


Procedure Tform1.StopTyping(whoto: String);
Var
  Payload,Tmp: String;
  ActLen: Integer;
Begin
 Payload:='5'+#$C0+#$80+whoto+#$C0+#$80+'4'+#$C0+#$80+whoto+#$C0+#$80+'14'+#$C0+#$80+#$20+#$c0+#$80+'13'+#$c0+#$80+'0'+#$c0+#$80+'49'+#$c0+#$80+'TYPING'+#$c0+#$80;
 ActLen:=Length(PayLoad);
 Tmp:='YMSG'+#$00+GVN+#$0+#$0+LengthToStr(ActLen)+#$0+#$4B+#$0+#$0+#$0+#$0+Key;
 Tmp:=Tmp+PayLoad;
 Form1.SendText(Tmp);
End;


Procedure Tform1.StartTyping(whoto: String);
Var
  Payload,Tmp: String;
  ActLen: Integer;
Begin
 Payload:='5'+#$C0+#$80+whoto+#$C0+#$80+'4'+#$C0+#$80+whoto+#$C0+#$80+'14'+#$C0+#$80+#$20+#$c0+#$80+'13'+#$c0+#$80+'0'+#$c0+#$80+'49'+#$c0+#$80+'TYPING'+#$C0+#$80;
 ActLen:=Length(PayLoad);
 Tmp:='YMSG'+#$00+GVN+#$0+#$0+LengthToStr(ActLen)+#$0+#$4B+#$0+#$0+#$0+#$0+Key;
 Tmp:=Tmp+PayLoad;
 Form1.SendText(Tmp);
End;


Function Tform1.ChatterExist(UserName: String): Integer;
Var
 N: Integer;
Begin
 Result:=-1;
 For N:=1 to High(Chatters) Do
  Begin
    if Chatters[n].UserName=UserName Then
     Begin
      Result:=N;
      Break;
     End;
  End;
End;

Function RoomAck(UserName,UserOnline: String): String;
Var
  Payload,Tmp: String;
  ActLen: Integer;
Begin
   Payload:='109'+#$C0+#$80+UserName+#$C0+#$80+'1'+#$C0+#$80+UserName+#$C0+#$80+'6'+#$C0+#$80+'abcde'+#$c0+#$80+'98'+co80s+'us'+co80s+'135'+co80s+'ym8, 0, 0, 1250'+co80s;
   ActLen:=Length(PayLoad);
   Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(ActLen)+#$0+#$96+#$0+#$0+#$0+#$0+Key;
   Tmp:=Tmp+PayLoad;
   Result:=Tmp;
end;

Function RoomAck2(UserName,UserOnline: String): String;
Var
  Payload,Tmp: String;
  ActLen: Integer;
Begin
   Payload:='109'+#$C0+#$80+UserName+#$C0+#$80+'1'+#$C0+#$80+UserName+#$C0+#$80+'6'+#$C0+#$80+'abcde'+#$c0+#$80+'98'+co80s+'us'+co80s+'135'+co80s+'ym8, 0, 0, 1250'+co80s;
   ActLen:=Length(PayLoad);
   Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(ActLen)+#$0+#$96+#$0+#$0+#$0+#$0+#$0+#$0+#$0+#$0;
   Tmp:=Tmp+PayLoad;
   Result:=Tmp;
end;

{Function Tform1.JoinRoomYMSG(UserName,RoomName: String): String;
Var
 ActLen: Integer;
 Payload,Tmp: String;
Begin
// Form1.ListBox1.Items.Clear;
   Payload:=#$31+#$C0+#$80+UserName+#$C0+#$80+'104'+#$C0+#$80+RoomName+#$C0+#$80+'62'+#$C0+#$80+'2'+#$C0+#$80;
   ActLen:=Length(PayLoad);
   Tmp:='YMSG'+#$00+GVN+#$0+#$0+LengthToStr(ActLen)+#$0+#$98+#$0+#$0+#$0+#$0+key;
   Tmp:=Tmp+PayLoad;
   JoinRoomYMSG:=Tmp;
//   Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
   Form1.Panel10.Caption:='Entered Chat Room..';
   If Form7.ItemIn(RoomName)=False Then
     Form7.ListBox1.Items.Add(RoomName);
   ExtractedRoomList:=False;
End;}

Procedure Tform1.UserKeyDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
Var
 Cr,St,Cmd: String;
 N: Integer;
Begin
 Cr:=Tbutton(Sender).Caption;
 Delete(Cr,1,PosRep('.',Cr)-1);
  If Shift=[SSAlt,SSCtrl,SSLeft] Then
   Begin
    Form46.Bn:=StrToInt(Copy(Tpanel(Sender).Caption,1,PosRep('.',Tpanel(Sender).Caption)-1));
    Form46.Bt:=Sender;
    Form1.CreateSkin(Form46);
    Form46.ShowModal;
  End
End;

procedure TForm1.UserMouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
begin

end;


Procedure Tform1.UserButton(Sender: Tobject);
Var
 Cr,St,Cmd: String;
 N: Integer;
Begin
 IF SecondsBetween(Now,Form1.LastClick)<2 Then Exit;
// Tpanel(Sender).BevelOuter:=BvLowered;
 Form1.LastClick:=Now;
// If (KnightRider=False) Then
//   TfadeWindow.Create(Tpanel(Sender),Form10.ColorBox5.ColorValue,ClBlue,20,0);
 Cr:=Tbutton(Sender).Caption;
 Delete(Cr,1,PosRep('.',Cr)-1);
 If Length(Cr)=1 Then
  Begin
    Form46.Bn:=StrToInt(Copy(Tbutton(Sender).Caption,1,PosRep('.',Tbutton(Sender).Caption)-1));
    Form46.Bt:=Sender;
    Form1.CreateSkin(Form46);
    Form46.Show;
  End
   else
  Begin
    ST:=Copy(Tbutton(Sender).Caption,1,PosRep('.',Tbutton(Sender).Caption)-1);
    Cmd:=Form1.LoadButtonInfo(ST,'Command','');
    Cr:=Form1.LoadButtonInfo(ST,'Cr','');
    Form1.richedit2.SelText:=Cmd;
    If Cr='True' Then
      Form1.Button1.OnClick(nil);
    Cmd:=Cmd;
  End;
// ShowMessage(TButton(Sender).caption + ' Pressed');
End;

Function Tform1.GotoUserP2(UserName,UserOnline: String): String;
Var
 Payload,Tmp: String;
 ActLen: Integer;
Begin
If Form2.RadioButton1.Checked=True Then
 Begin
   Payload:='109'+#$C0+#$80+UserOnline+#$C0+#$80+'1'+#$C0+#$80+UserName+#$C0+#$80+'62'+#$C0+#$80+'2'+#$C0+#$80;
   ActLen:=Length(PayLoad);
   Tmp:='YMSG'+#$00+GVN+#$0+#$0+LengthToStr(ActLen)+#$0+#$97+#$0+#$0+#$0+#$0+Key;
   Tmp:=Tmp+PayLoad;
 End;
 If Form2.RadioButton4.Checked=True then
  Begin
   PayLoad:=Delim+'32'+Delim+UserOnline;
   ActLen:=Length(PayLoad);
   Tmp:='SPRT'+#0+#0+#0+#0+Key+LengthToStr(ActLen)+#$23;
   Tmp:=Tmp+Payload;
   Result:=Tmp;
  End;

 ExtractedRoomList:=False;
 GotoUserP2:=Tmp;
End;



Function YMSGMessyPing(UserName: String): String;
Var
 PayLoad,Data,Tmp: String;
 Len: Integer;
Begin
If Form2.RadioButton1.Checked=True Then
 Begin
  Len:=7+Length(UserName);
  Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(len)+#$0;
  Data:=Tmp+#$12+#$0+#$0+#$0+#$0+key+'109'+#$C0+#$80+UserName+#$C0+#$80;
  Result:=Data;
 End;
End;

function Tform1.KillDll(aDllName: string): Boolean;
var
  hDLL: THandle;
  aName: array[0..10] of char;
  FoundDLL: Boolean;
begin
  StrPCopy(aName, aDllName);
  FoundDLL := False;
  repeat
    hDLL := GetModuleHandle(aName);
    if hDLL = 0 then
      Break;
    FoundDLL := True;
    FreeLibrary(hDLL);
  until False;
  if FoundDLL then
    MessageDlg('Success!', mtInformation, [mbOK], 0)
  else
    MessageDlg('DLL not found!', mtInformation, [mbOK], 0);
end;

Function Ping(UserName: String): String;
Var
 PayLoad,Data,Tmp: String;
 Len: Integer;
Begin
If Form2.RadioButton1.Checked=True Then
 Begin
  Len:=7+Length(UserName);
  Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(len)+#$0;
  Data:=Tmp+#$A1+#$0+#$0+#$0+#$0+key+'109'+#$C0+#$80+UserName+
  #$C0+#$80;
  Ping:=Data;
  {
     Len:=7+Length(UserName);
     Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(len)+#$0;
     Data:=Tmp+#$12+#$0+#$0+#$0+#$0+key+'109'+#$C0+#$80+UserName+#$C0+#$80;
     Result:=Data;
  }
 End;
 If Form2.RadioButton4.Checked=True Then
 Begin
  PayLoad:='';
  Len:=Length(PayLoad);
  Tmp:='SPRT'+#0+#0+#0+#0+Key+Form1.LengthToStr(Len)+#$36;
  Tmp:=Tmp+PayLoad;
  Result:=Tmp;
 End;
End;



Function Tform1.JoinRoom(UserName,RoomName: String): String;
Var
 ActLen: Integer;
 Payload,RoomCat,Cut,Tmp: String;
Begin
// Form1.ListBox1.Items.Clear;
 IF Trim(RoomName)='' Then
  Begin
   ShowMessage('Please Specify What Room!');
   Exit;
  End;
  RoomCat:='0';
  BumpRoom:=RoomName;
  LastJoinRoom:=RoomName;

  If Pos('::',RoomName)>0 Then
   If Form2.RoomBox.Items.IndexOf(RoomName)=-1 Then
      Form2.RoomBox.Items.Add(RoomName);

 If PosRep('::',RoomName)>0 then
  Begin
    Tmp:=RoomName;
    RoomName:=Copy(Tmp,1,pos('::',Tmp)-1);
    Delete(Tmp,1,Length(RoomName)+2);
    RoomCat:=Tmp;
   End;

 RoomName:=Trim(RoomName);
 JoinSent:=Now;
 RoomJoinWait:=True;

  if Form2.RadioButton1.Checked=True Then
   Begin
    If Assigned(Knock)=False Then
      Form1.Timer7.Enabled:=True;
     JoinSent:=Now;
   End; 


{ if Form2.RadioButton1.Checked=True Then
 Begin
   Payload:=#$31+#$C0+#$80+UserName+#$C0+#$80+'104'+#$C0+#$80+RoomName+#$C0+#$80;
   ActLen:=Length(PayLoad);
   Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(ActLen)+#$0+#$98+#$0+#$0+#$0+#$0+key;
   Tmp:=Tmp+PayLoad;
  End;}

 if Form2.RadioButton1.Checked=True Then
 Begin
  If RoomCat='0' Then
   Payload:='1'+#$C0+#$80+UserName+#$C0+#$80+'104'+#$C0+#$80+RoomName+#$C0+#$80+'62'+CO80S+'2'+CO80S//+'999'+#$C0+#$80+'Hello'+#$C0+#$80
    else
   Payload:='1'+#$C0+#$80+UserName+#$C0+#$80+'104'+#$C0+#$80+RoomName+#$C0+#$80+'129'+CO80S+roomCat+CO80S+'62'+CO80S+'2'+CO80S;
   ActLen:=Length(PayLoad);
   Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(ActLen)+#$0+#$98+#$0+#$0+#$0+#$0+key;
   Tmp:=Tmp+PayLoad;
  End;


If Form2.RadioButton4.Checked=True Then
 Begin
  PayLoad:=Delim+'104'+Delim+RoomName;
  ActLen:=Length(PayLoad);
  Tmp:='SPRT'+#0+#0+#0+#0+Key+Form1.LengthToStr(ActLen)+#$24;
  Tmp:=Tmp+Payload;
 End;

  JoinRoom:=Tmp;
//  Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
//  Form1.Panel10.Caption:='Entered Chat Room..';

  If RoomCat='0' Then
    If Form7.ListBox1.Items.IndexOf(RoomName)=-1 Then
     Form7.ListBox1.Items.Add(RoomName);

   If RoomCat<>'0' Then
    If Form7.ListBox1.Items.IndexOf(RoomName+'::'+RoomCat)=-1 Then
      Form7.ListBox1.Items.Add(RoomName+'::'+RoomCat);

  ExtractedRoomList:=False;
End;



Function Tform1.CreateRoom(UserName,RoomName,RoomId,Description: String; Voice,Pubpriv: Boolean): String;
Var
 ActLen: Integer;
 Payload,Tmp: String;
Begin
// Form1.ListBox1.Items.Clear;
 If Form2.RadioButton1.Checked=True Then
 Begin
   Payload:=#$31+#$C0+#$80+UserName+#$C0+#$80+'128'+#$C0+#$80+RoomiD+#$C0+#$80+'104'+#$C0+#$80+RoomName+#$C0+#$80+'129'+#$C0+#$80+RoomID+#$C0+#$80+'105'+#$C0+#$80+Description+#$C0+#$80+'126'#$C0+#$80+'0'+#$C0+#$80+'62'+#$C0+#$80+'2'+#$C0+#$80;
   ActLen:=Length(PayLoad);
   Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(ActLen)+#$0+#$A9+#$0+#$0+#$0+#$0+key;
   Tmp:=Tmp+PayLoad;
 End;
   SendText(Tmp);
   CreateRoom:=Tmp;
   ExtractedRoomList:=False;
//   Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
   Form1.Panel10.Caption:='Entered Chat Room..';
   If Form7.ItemIn(RoomName)=False Then
     Form7.ListBox1.Items.Add(RoomName);
End;




Function RemoveDoubles(S: String): String;
Var
  I: Integer;
  BS: String;
Begin
BS:=S[1];
 For I:=1 To Length(S) DO
   If BS[Length(BS)]<>S[I] Then
     BS:=BS+S[i];
  Result:=BS;
End;

Function Tform1.L1WhoIsSelected: String;
Var
  N: Integer;
begin
For N:=Form1.ListBox1.Items.Count-1 Downto 0 do
  If Form1.ListBox1.Selected[n]=True Then
     L1WhoIsSelected:=Form1.ListBox1.Items[n];
End;

Function L1WhoIsSelectedNum: Integer;
Var
  N: Integer;
begin
For N:=Form1.ListBox1.Items.Count-1 Downto 0 do
  If Form1.ListBox1.Selected[n]=True Then
   Result:=n;
End;


Function L2WhoIsSelected: String;
Var
  N: Integer;
begin
For N:=Form1.ListBox2.Items.Count-1 Downto 0 do
  If Form1.ListBox2.Selected[n]=True Then
   L2WhoIsSelected:=Form1.ListBox2.Items[n];
End;

Function L2WhoIsSelectedNum: Integer;
Var
  N: Integer;
begin
For N:=Form1.ListBox2.Items.Count-1 Downto 0 do
  If Form1.ListBox2.Selected[n]=True Then
    L2WhoIsSelectedNum:=n;
End;


Function Tform1.RemoveRicheditBold(RichCont: TMyRichedit; Msg: String): String;
Var
 FoundTag: Boolean;
 P1,P2,N: Integer;
 Msg3,Msg2,Col: String;
Begin
N:=0;
Msg3:=Msg;
Msg2:=Msg+' ';
// GetTxt(Msg,'#$1B','m');
{If PosRep(#$1b,Msg)=0 Then
  RichCont.SelAttributes.Color:=ClBlue;}
RichCont.SelAttributes.Style:=[];
 While (PosRep(#$1B,Msg)>0) Do
  Begin
   //RichCont.SelText:=Msg;
{   For N:=1 to Length(Msg) do
    Begin}
    Inc(N);
    foundtag:=False;
     If Msg[n]=#$1B Then
      Begin
        P1:=PosRep(#$1b,Msg);
    //    Delete(Msg,1,p1-1);
        P2:=Form1.Instr('m',Msg,p1);
        Col:=Copy(Msg,P1,P2-P1+2);
        Delete(Msg,P1,P2-P1+2);
      End;
   End;
   Result:=Msg;
End;



Function CreateChatter(UserName,Nick: String): Integer;
Var
 NewR,R,N,N2: Integer;
Begin
Result:=-1;
R:=-1;
  For N:=1 to High(Chatters) do
    Begin
      If (Chatters[n].UserName='') Or (LowerCaseRep(Chatters[N].UserName)=LowerCaseRep(UserName)) Then
       Begin
        R:=N;
        Break;
       End;
    End;

 If (R>=High(Chatters)) Or (R=-1) Then
  Begin
   If R=-1 Then
     R:=High(Chatters);
     SetLength(Chatters,High(Chatters)+2);
//   ReIndexChatters;
  End;


 If R<>-1 Then
  Begin
  FillChar(Chatters[R],SizeOf(Chatters[R]),#0);
  Chatters[r].UserName:=UserName;
  Chatters[R].SaidYourName:=False;
  Chatters[R].PostNum:=0;
  Chatters[R].LastPost:=Now;
  Chatters[R].Joined:=Now;
  Chatters[R].Nick:=Nick;
  Chatters[R].CustomData:='';
  Chatters[R].NumLinesPosted:=0;
  Chatters[R].BlockCount:=0;
  Chatters[R].TotalBlock:=0;
  Chatters[R].NumLinesPosted:=0;
  Chatters[R].BotPCount:=0;
  Chatters[R].AssignedCustomName:=IsCustomName(UserName);
/// LoadCustomName(UserName);
//  LoadCustomName(UserName);
  Result:=R;
 End;
End;


Procedure GotoP(S: String);
Var
  SaveStr,Tmp,Code,Code2,RoomName: String;
Begin
 Form1.Richedit1.SelStart:=-1;
 Code:=Copy(s,21,3);
 Tmp:=S;
 Delete(S,1,25);
 RoomName:=Copy(S,1,PosRep(Chr($c0)+Chr($80),S)-1);
 Delete(S,1,PosRep(Chr($c0)+Chr($80),S)+1);
 Code2:=Copy(S,1,PosRep(#$C0,S)-1);
 Delete(S,1,Length(code2)+2);
 If Copy(S,1,2)='11' Then
  Form1.Richedit1.Lines.Add('User Is Not Online....');

 SaveStr:=S;
 Form1.ScrollToEnd(Form1.Richedit1);
End;

Procedure BuddyListP(S: String);
Var
  Friend,Tmp,Code,Code2,RoomName: String;
  N: Integer;
  Obj: TObject;
Begin
//If PosRep('domain',LowerCaseRep(S))>0 Then
  //   S:='';
 SmileyPic:=0;
 Tmp:=S;
 Delete(Tmp,1,20);
// Tmp:=Co80s+Tmp;

 Form27.ListBox1.Clear;

If FileExists(Path+'localfriends.txt')=False Then
 Begin
//   Friends.Clear;
   Delete(S,1,20);
   S:=CO80S+S;
   S:=Form1.ExtractPacketDetails(S,'87');
   Delete(S,1,PosRep(':',LowerCaseRep(S)));
   Tmp:=S;
   If PosRep(#$0a,Tmp)>0 Then
     Tmp:=Form1.ReplaceFromToStr(Tmp,#$0a,':',',');
   While Form1.ScanIt(',',Tmp)>0 DO
    Begin
     Friend:=Copy(Tmp,1,PosRep(',',tmp)-1);
     Delete(Tmp,1,PosRep(',',Tmp));
     If Trim(Friend)<>'' Then
//       If Friends.IndexOf(Friend)=-1 Then
       If Friends.Find(Friend,Obj)=False Then
          Friends.Add(Friend,Obj);
//        Form27.ListBox1.Items.Add(Friend);
     End;
  End
   else
    Form1.LoadFromFile(Friends,Path+'localfriends.txt');
 // Friends.LoadFromFile(Path+'localfriends.txt');

  If FileExists(Path+'localfriends.txt')=False Then
    Form1.SaveToFile(Friends,Path+'localfriends.txt');
    
//    Friends.SaveToFile(Path+'localfriends.txt');
 //  Form27.ListBox1.Items.Text:=Friends.Text;
End;

Procedure BuddyListSprt(S: String);
Var
 Msg,Room,Tmp,Tmp2: String;
 Friend,FriendsList: String;
 PT,Code2,Code: String;
 Obj: Tobject;
 C,N,Uc: Integer;
Begin
// Delete(S,1,15);
Tmp:=S;
 Pt:=Form1.ExtractPacketDetailsSprt(Tmp,'120');
 Code:=Form1.ExtractPacketDetailsSprt(Tmp,'100');
 Code2:=Form1.ExtractPacketDetailsSprt(Tmp,'200');
 If (PT='')  Then
  Begin
   If Code<>'' Then
     Form1.Richedit1.Lines.Add('Buddy Server Message, Success: '+Code);
   If Code2<>'' Then
     Form1.Richedit1.Lines.Add('Buddy Server Message, Error: '+Code2);
    Form1.ScrollToEnd(FOrm1.Richedit1);  
    Exit;
  End;
 If Trim(PT)='' Then Exit;
 FriendsList:=Form1.ExtractPacketDetailsSprt(Tmp,'121');
 Case PT[1] of
  '1': Begin
//     Friends.Clear;
     Tmp:=FriendsList;
     C:=Form1.Scanit(',',Tmp)+1;
     For N:=1 to C do
       Begin
        If PosRep(',',Tmp)>0 Then
         Friend:=Copy(Tmp,1,PosRep(',',tmp)-1)
          else
         Friend:=Tmp;
        Delete(Tmp,1,PosRep(',',Tmp));
        If Trim(Friend)<>'' Then
          Begin
           If Friends.Find(Friend,Obj)=False Then
             Begin
              Friends.Add(Friend,Obj);
//              Form27.ListBox1.Items.Add(Friend);
             End;
          End;
       End;
    End;
    '2': Begin
      OnlineFriends.Clear;
     Tmp:=FriendsList;
     C:=Form1.Scanit(',',Tmp)+1;
     For N:=1 to C do
       Begin
        If PosRep(',',Tmp)>0 Then
         Friend:=Copy(Tmp,1,PosRep(',',tmp)-1)
          else
         Friend:=Tmp;
        Delete(Tmp,1,PosRep(',',Tmp));
        If Trim(Friend)<>'' Then
          Begin
           If OnlineFriends.IndexOf(Friend)=-1 Then
             Begin
              OnlineFriends.Add(Friend);
              Form12.ListBox1.Items.Add(Friend);
             End;
          End;
        End;
     End;
    '3': Begin
        Friend:=FriendsList;
        If Trim(Friend)<>'' Then
        Begin
         If OnlineFriends.IndexOf(Friend)=-1 Then
          Begin
            OnlineFriends.Add(Friend);
            Form12.ListBox1.Items.Add(Friend);
           End;
        End;
    End;
    '4': Begin
     Friend:=FriendsList;
       If OnlineFriends.IndexOf(Friend)<>-1 Then
         Begin
           OnlineFriends.Delete(OnlineFriends.IndexOf(Friend));
           Form12.ListBox1.Items.Delete(Form12.ListBox1.Items.IndexOf(Friend));
         End;
    End;
 End;
 //  Form27.ListBox1.Items.Text:=Friends.Text;
End;


Procedure WhosOnLineP(S: String);
Var
  SaveStr,Tmp,Code,Code2,RoomName: String;
Begin
 Code:=Copy(s,21,3);
 Tmp:=S;
 Delete(S,1,25);
 RoomName:=Copy(S,1,PosRep(Chr($c0)+Chr($80),S)-1);
 Delete(S,1,PosRep(Chr($c0)+Chr($80),S)+1);
 Code2:=Copy(S,1,PosRep(#$C0,S)-1);
 Delete(S,1,Length(code2)+2);
 SaveStr:=S;
End;

Procedure OffLineP(S: String);
Var
  Tmp: String;
  Code,UserOffLine: String;
Begin
    Tmp:=S;
    Delete(Tmp,1,20);
    Tmp:=Co80s+Tmp;
    UserOffLine:=Form1.ExtractPacketDetails(Tmp,'7');
    If OnLineFriends.IndexOf(UserOffLine)<>-1 Then
      Begin
        Form12.ListBox1.Items.Delete(Form12.ListBox1.Items.IndexOf(UserOffLine));
        OnLineFriends.Delete(OnLineFriends.IndexOf(UserOffLine));
      End;
//    Form1.Panel10.Font.Color:=ColSelect.AlertColor;
    Form1.Panel10.Caption:='Messenger buddy: '+UserOffLine+' Has just gone offline in Messenger';
//    RichCont.Lines.Add('User '+UserOffLine+' Now Offline');
End;

Function QuickInfo: String;
Var
 BuildSTR: String;
Begin
  Result:='PM''s: '+BoolStr[Form10.CheckBox17.Checked]+', BR Mode: '+IntToStr(Form1.BootResist)+' Emote Ignore: '+BoolStr[Form18.CheckBox1.Checked]+', Knocking: '+BoolStr[Form10.CheckBox29.Checked]+', Spell Chcker: '+BoolStr[Form1.SpellChecker1.Checked]+', Alert Sounds: '+BoolStr[Form1.YmLiteAlertSoundsBootersetc1.Checked]+', Clone Scanning: '+BoolStr[Form10.CheckBox12.Checked]+' AvgCPUtime: '+IntToStr(Form1.AvgProcessTime);
End;


Procedure LoginP(S: String);
Var
 Tmp,Tmp2: String;
 BuddyCount,YourID,Buddy,UserOnline,ToWho: String;
 Code: String;
Begin
{If Key='' Then
 Begin
  Key:=Copy(S,17,4);
  Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
  Form1.Panel10.Caption:='Successful Login To Messenger Server....';
  If Form1.YmLiteMessageSounds1.Checked=True Then
    Form1.StartSound('connected.wav');
  Form1.LoginToRoom;
 End;}
Delete(S,1,20);
S:=Co80s+S;
Tmp:=S;
YourID:=Form1.ExtractPacketDetails(Tmp,'0');
BuddyCount:=Form1.ExtractPacketDetails(Tmp,'8');
//7 is all friends..
If BuddyCount<>'' Then
While Form1.ScanIt(co80s+'7',Tmp)>0 Do
 Begin
  Tmp2:=Form1.ExtractBlockPacketDetails(Tmp,'7','13');
  Delete(Tmp,1,PosRep(Tmp2,Tmp)+Length(Tmp2)+3);
  Buddy:=Form1.ExtractPacketDetails(Tmp2,'7');
  If OnLineFriends.IndexOf(Buddy)=-1 Then
   Begin
     OnLineFriends.Add(Buddy);
     Form12.ListBox1.Items.Add(Buddy);
   End;
 End
  else
 Begin
  Tmp2:=Form1.ExtractBlockPacketDetails(Tmp,'7','13');
  Buddy:=Form1.ExtractPacketDetails(Tmp2,'7');
  If Buddy<>'' Then
   If OnLineFriends.IndexOf(Buddy)=-1 Then
   Begin
     OnLineFriends.Add(Buddy);
     Form12.ListBox1.Items.Add(Buddy);
//     Form1.Panel10.Font.Color:=ColSelect.AlertColor;
     Form1.Panel10.Caption:='Messenger buddy: '+Buddy+' has just come on Messenger';
    End;
 End;
End;


procedure Tform1.Delay(msecs:integer);
var
   FirstTickCount: Dword;
begin
     FirstTickCount:=GetTickCount;
     repeat
//        Sleep(1);
        Application.ProcessMessages;
     until (GetTickCount-FirstTickCount) >= Dword(msecs);
end;

Function Tform1.ExtractPacketDetails(S,PacketT: String): String;
Var
 PacketStr,Code,Tmp2: String;
 P1: Integer;
Begin
 Tmp2:=S;
 Result:='';
 PacketStr:=Co80s+PacketT;
 P1:=PosRep(PacketStr,Tmp2);
 If P1=0 Then
   Exit;
 Delete(Tmp2,1,P1+Length(PacketStr)+1);
 If PosRep(co80s,Tmp2)>0 Then
   Result:=Form1.ToC080(Tmp2)
    else
   Result:=Tmp2;
End;   

{Function Tform1.ExtractPacketDetails(S,PacketT: String): String;
Var
 PacketStr,Code,Tmp2: String;
 P1: Integer;
Begin
 Tmp2:=S;
 Result:='';
 PacketStr:=Co80s+PacketT+Co80s;
 P1:=PosRep(PacketStr,Tmp2);
 If P1=0 Then
   Exit;
 Delete(Tmp2,1,P1+Length(PacketStr)-1);
 If PosRep(co80s,Tmp2)>0 Then
   Result:=Form1.ToC080(Tmp2)
    else
   Result:=Tmp2;
End;}

Function Tform1.ExtractBlockPacketDetails(S,PacketT,PacketT2: String): String;
Var
 Block,Tmp2: String;
Begin
 Tmp2:=S;
 While ScanIt(Co80S,Tmp2)>0 do
  Begin
   Tmp2:=Form1.CutC080(Tmp2,1);
    If Copy(Tmp2,1,Length(PacketT))=PacketT Then
      Begin
       // Tmp2:=Form1.Cut080(Tmp2,1);
       // Result:=Form1.ToC080(Tmp2);
         If PosRep(Co80s+PacketT2,Tmp2)>0 Then
          Block:=Co80s+Copy(Tmp2,1,PosRep(Co80s+PacketT2,Tmp2)-1)
           else
          Block:=Tmp2;
        Break;
      End;
  End;
   Result:=Block;
End;

{Procedure TestSpeech(S: String);
Var
 Data: String;
 Tmp: String;
 Len: Integer;
 Ts: String;
Begin
 TS:='';
 Data:=#$31+#$C0+#$80+Loggedinname+#$C0+#$80+'104'+#$C0+#$80+RoomName+#$C0+#$80+'117'+#$C0+#$80+Ybold+YPurple+S+#$C0+#$80+'124'+#$c0+#$80+#$31+TS+#$C0+#$80;
 Len:=Length(Data);
 Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(len)+#$0+#$A8+#0+#0+#0+#0+key;//Form1.LengthToStr(Length(Data)-11);
 Tmp:=Tmp+Data;
 Form1.SendText(Tmp);
End;}

Procedure TestSpeech(S: String);
Var
 Data: String;
 Tmp: String;
 Len: Integer;
 Ts: String;
Begin
 TS:='';
 Data:=#$31+#$C0+#$80+Loggedinname+#$C0+#$80+'104'+#$C0+#$80+GpRoomName+#$C0+#$80+'117'+#$C0+#$80+Ybold+YPurple+S+#$C0+#$80+'124'+#$c0+#$80+#$31+TS+#$C0+#$80;
 Len:=Length(Data);
 Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(len)+#$0+#$A8+#0+#0+#0+#0+key;//Form1.LengthToStr(Length(Data)-11);
 Tmp:=Tmp+Data;
 Form1.SendText(Tmp);
End;

Procedure TestSpeech2(S: String);
Var
 Data: String;
 Tmp: String;
 Len: Integer;
 Ts: String;
Begin
// Data:=#$31+#$C0+#$80+LoggedInName+#$C0+#$80+'104'+#$C0+#$80+RoomName+#$C0+#$80+'117'+#$C0+#$80+S+#$C0+#$80;
 Data:=#$31+#$C0+#$80+LoggedInName+#$C0+#$80+'104'+#$C0+#$80+GPRoomName+#$C0+#$80+'117'+#$C0+#$80+S+#$C0+#$80+'124'+#$c0+#$80+#$31+''+#$C0+#$80;
 Len:=Length(Data);
 Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(len)+#$0+#$A8+#0+#0+#0+#0+key;//Form1.LengthToStr(Length(Data)-11);
 Tmp:=Tmp+Data;
 Form1.SendText(Tmp);
End;

Procedure Tform1.AwayMsg(RichCont: TMyRichedit; LoginName,RoomName,Msg: String);
Var
 Len: Integer;
 FullStr,Url,FontS,Tmp2,Col,ColStr,Data,OM,Msg2,msg3,Tmp: String;
 SaveCol: TColor;
Begin
 If Form2.RadioButton1.Checked=True Then
  Begin
   Data:=#$31+#$C0+#$80+LoginName+#$C0+#$80+'104'+#$C0+#$80+RoomName+#$C0+#$80+'117'+#$C0+#$80+Msg+#$C0+#$80+'124'+#$c0+#$80+#$32+#$C0+#$80;
   Len:=Length(Data);
   Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(len)+#$0+#$A8+#0+#0+#0+#0+key;//Form1.LengthToStr(Length(Data)-11);
   Tmp:=Tmp+Data;
   Form1.SendText(Tmp);
  end;

  RichCont.SelAttributes.Name:='Arial';
  RichCont.SelAttributes.Size:=10;
  RichCont.SelAttributes.Style:=[FsBold];
  RichCont.SelAttributes.Color:=Form10.ColorBox1.ColorValue;
  RichCont.SelText:=LoginName;
  RichCont.SelAttributes.Size:=UserFontSize;
  RichCont.SelAttributes.Color:=ClRed;
  RichCont.SelAttributes.Style:=[];
  RichCont.SelText:=' '+Msg;
  RichCont.Lines.Add('');
End;

Procedure FinishDisplay(RichCont: TMyRichedit; SD: Boolean);
Begin
  RichCont.SelText:=' ';
     RichCont.Lines.add('');
     RichCont.SelAttributes.Style:=[];
     RichCont.SelAttributes.Size:=UserFontSize;
     RichCont.SelAttributes.Name:='Arial';
     SentText:=False;
     Form1.spSkinCheckRadioBox1.Checked:=SD;
//     CalledAppProcess:=False;
//     Form1.Ymsg.OnRead:=Form1.YmsgRead;
     CalledAppProcess:=False;
     Form1.ScrollToEnd(Form1.Richedit1);
End;


Function FadeIDStr: String;
Begin
 If Form10.CheckBox35.Checked=True Then
    Result:='$'+IntToHex(Form10.ColorpickCombo11.ColorValue,6)
    else
  Result:='$0';
End;

Function Tform1.BuildinfStr(Identitar: String): String;
Var
 Mp3Station: String;
 T: TEncrypt;
begin
 T:=TEncrypt.Create;
 If Identitar<>'' Then
   Result:=DecStr(FontInf,52)+Identitar+DecStr('Tª™¦n',52)+ClientVer+' lp:'+IntToStr(ChatLines)+' IDc:'+FadeIDStr+' BR:'+IntToStr(Form1.BootResist)+'>'
    else
   Result:=DecStr(FontInf,52)+DecStr('Tª™¦n',52)+ClientVer+' lp:'+IntToStr(ChatLines)+' IDc:'+FadeIDStr+' BR:'+IntToStr(Form1.BootResist)+'>';
   T.Free;
 //<font '+Form10.ComboBox1.Text+' '+Identitar+'><font ltime '+FloatToStr(Now)+'>'
End;

Function Tform1.DecStr(Msg: String; EncKey: Integer): String;
Var
 N: Integer;
Begin
 If EncKey<>0 Then
   Begin
    If Length(Msg)>0 Then
     For N:=1 to Length(Msg) Do
       Msg[N]:=Chr(Ord(Msg[N])-EncKey);
   End;
 Result:=Msg;
End;

Function Tform1.EncStr(Msg: String; EncKey: Integer): String;
Var
 N,Tval,EncVal: Integer;
Begin
 Result:=Msg;
 EncVal:=0;
// If Form1.TextEncryptForYmLiteers1.Checked=True Then
//  Begin
   IF Length(Msg)>0 Then
    For N:=1 to Length(Msg) Do
     Msg[N]:=Chr(Ord(Msg[N])+EncKey);
//  End;
 Result:=Msg;
End;


Function GossipSpeech(RichCont: TMyRichedit;LoginName,RoomName,Msg,Colours: String; Plain,Emote,Test: Boolean): String;
Var
 Tmp,Data: String;
 Len: Integer;
Begin
 Data:=Delim+'31'+delim+LoggedInName+delim+'41'+Delim+Msg+Delim+'124'+Delim+'1';
// If Form1.RequestEchoChat1.Checked=True Then
 Data:=Data+Delim+'70'+delim+'1';
 Len:=Length(Data);
 Tmp:='SPRT'+#0+#0+#0+#0+Key+Form1.LengthToStr(Len)+#$22;
 Tmp:=Tmp+Data;
 GossipSpeech:=Tmp;

End;


Function Speech(RichCont: TMyRichedit;LoginName,RoomName,Msg,Colours: String; Plain,Emote,Test: Boolean): String;
Var
 EMsg,FullStr,Url,FontS,Tmp2,Col,ColStr,Data,OM,Msg2,msg3,Msg5,Tmp: String;
 SaveCol: TColor;
 Tfs: TfontStyles;
 SD,FF1,FF2,FF3: Boolean;
 P1,P2,N: Integer;
 fns,S: String;
 EncVal: String;
 ScreenState,FoundTag: Boolean;
 ISP,Len: Integer;
 tf: TextFile;
Begin
// Msg:=YmLiteLogoStr(Msg);
//ScreenState:=ScreenPaused;
//CalledAppProcess:=True;
//Form1.Ymsg.OnRead:=Nil;
 If Form1.Silent=True Then
   Emote:=True;

OM:=Msg;
SmileyCount:=0;
 RichCont.SelStart:=-1;
 Form1.ScrollToEnd(Form1.Richedit1);
CalledAppProcess:=True;
Form1.SortCustomTag;
Msg:=Form1.DoHtmlColTag(RichCont,Msg);
Msg:=Form1.RemoveTags(Msg);



 Url:=Form1.GetUrl(Msg,False);

  If Form10.CheckBox23.Checked=True Then
    Form1.WriteLogData(LoggedInName,'',Msg,True);


  If URL<>'' Then
 Form5.ListBox1.Items.Insert(0,Url);
SD:=Form1.spSkinCheckRadioBox1.Checked;
If emote=True Then
  Form1.spSkinCheckRadioBox1.Checked:=False;
IF Emote=True Then
 Begin
  Plain:=False;
  Msg:=Yblue+Msg;
 End;
 Msg2:=Msg;
 RichCont.SelStart:=-1;
If (Plain=False) and (emote=False) Then
 Begin
  If ColsTr='' Then
   Begin
    If Form1.BoldP.checked=true Then
      ColStr:=YBold;
    If Form1.ItalicP.checked=true Then
      ColStr:=ColStr+YItalic;
    If Form1.UnderLineP.checked=true Then
      ColStr:=ColStr+Yun;
  //  ColStr:=ColStr+Form1.TcolToYcol(Form1.ColorBox1.Selected);
    ColStr:=ColStr+Form1.TcolToYcol(Form1.ColorBox1.ColorValue);
   { If Form1.ColorBox1.Selected=clMaroon Then ColStr:=ColStr+Form1.TcolToYcol(ClMaroon);
    If Form1.ColorBox1.Selected=clGreen Then ColStr:=ColStr+YGreen;
    If Form1.ColorBox1.Selected=clOlive Then ColStr:=ColStr+Form1.TcolToYcol(clOlive);
    If Form1.ColorBox1.Selected=clNavy Then ColStr:=ColStr+Form1.TcolToYcol(ClNavy);
    If Form1.ColorBox1.Selected=clPurple Then ColStr:=ColStr+YPurple;
    If Form1.ColorBox1.Selected=clTeal Then ColStr:=ColStr+Form1.TcolToYcol(ClTeal);
    If Form1.ColorBox1.Selected=clGray Then ColStr:=ColStr+YGray;
    If Form1.ColorBox1.Selected=clSilver Then ColStr:=ColStr+Form1.TcolToYcol(ClSilver);
    If Form1.ColorBox1.Selected=clRed Then ColStr:=ColStr+YRed;
    If Form1.ColorBox1.Selected=clLime Then ColStr:=ColStr+Form1.TcolToYcol(ClLime);
    If Form1.ColorBox1.Selected=clYellow Then ColStr:=ColStr+Form1.TcolToYcol(ClYellow);
    If Form1.ColorBox1.Selected=clBlue Then ColStr:=ColStr+Yblue;
    If Form1.ColorBox1.Selected=clFuchsia Then ColStr:=ColStr+Ypink;
    If Form1.ColorBox1.Selected=clAqua Then ColStr:=ColStr+Form1.TcolToYcol(ClAqua);}
  End;
End;
If (Plain=False) and (emote=False) and (Form1.spSkinCheckRadioBox1.Checked=True) Then
 Begin
  If CloneTag=True Then
   Begin
     If PosRep('fade',LowerCaseRep(ClonedTag))>0 Then
      Begin
       Form9.RadioButton1.Checked:=True;
       Msg:='<'+ClonedTag+'>'+ColStr+Msg+'</FADE>';
       EMsg:='<'+ClonedTag+'>'+ColStr+EMsg+'</FADE>';
      End
       else
      Begin
       Form9.RadioButton2.Checked:=True;
       Msg:='<'+ClonedTag+'>'+ColStr+Msg+'</ALT>';
       EMsg:='<'+ClonedTag+'>'+ColStr+EMsg+'</ALT>';
      End;
   End
    else
   Begin
  If Form9.RadioButton1.Checked=True Then
   Begin
    Msg:=ColStr+CustomTag+Msg+'</FADE>';
    EMsg:=ColStr+CustomTag+EMsg+'</FADE>';
   End;
  If Form9.RadioButton2.Checked=True Then
   Begin
    Msg:=ColStr+CustomTag+Msg+'</ALT>';
    EMsg:=ColStr+CustomTag+EMsg+'</FADE>';
   End;
  If Form9.RadioButton3.Checked=True Then
   Begin
    Msg:=ColStr+CustomTag+Msg+'</ALW>';
    EMsg:=ColStr+CustomTag+EMsg+'</ALW>';
   End;
   End;
 End;
If (Form1.spSkinCheckRadioBox1.Checked=False) and (plain=false) Then
 Begin
  Msg3:=ColStr+Msg;
  Msg5:=ColStr+Emsg;
  Msg3:=YmLiteLogoStr(Msg3);
 End
  else
 Begin
  msg3:=Msg;
  Msg5:=EMsg;
  ColStr:='';
 End;
 FontS:='<font face="'+Form1.SpSkinFontComboBox1.Text+'" size="'+Form1.SpSkinComboBox2.Text+'">';
 FullStr:=FontS+Msg3;
 If Length(FullStr)>290 Then
  Begin
    Plain:=True;
    Emote:=True;
   End;
 If Form2.RadioButton1.Checked=True Then
  Begin
    If Emote=False Then
      Data:=#$31+#$C0+#$80+LoginName+#$C0+#$80+'104'+#$C0+#$80+RoomName+#$C0+#$80+'117'+#$C0+#$80+Copy(Form1.BuildinfStr(Identitar)+FontS+Msg3,1,300)+#$C0+#$80+'124'+#$c0+#$80+#$31+#$C0+#$80
        else
      Data:=#$31+#$C0+#$80+LoginName+#$C0+#$80+'104'+#$C0+#$80+RoomName+#$C0+#$80+'117'+#$C0+#$80+Copy(Form1.BuildinfStr(Identitar)+FontS+Msg3,1,300)+#$C0+#$80+'124'+#$c0+#$80+#$32+#$C0+#$80;

   If Plain=True Then
      Data:=#$31+#$C0+#$80+LoginName+#$C0+#$80+'104'+#$C0+#$80+RoomName+#$C0+#$80+'117'+#$C0+#$80+Copy(Msg2,1,300)+#$C0+#$80+'124'+#$c0+#$80+#$31+#$C0+#$80;

   Len:=Length(Data);
   Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(len)+#$0+#$A8+#0+#0+#0+#0+key;//Form1.LengthToStr(Length(Data)-11);
  End;


 If Form2.RadioButton4.Checked=True Then
  Begin
    If Emote=False Then
     Begin
      Data:=Delim+'31'+delim+LoggedInName+delim+'41'+Delim+Form1.BuildinfStr(Identitar)+FontS+Msg3+Delim+'124'+Delim+'1';
       If Form1.RequestEchoChat1.Checked=True Then
         Data:=Data+Delim+'70'+delim+'1';
       Len:=Length(Data);
       Tmp:='SPRT'+#0+#0+#0+#0+Key+Form1.LengthToStr(Len)+#$21;
     End
    else
     Begin
       Data:=Delim+'31'+delim+LoggedInName+delim+'41'+Delim+Form1.BuildinfStr(Identitar)+FontS+Msg3+Delim+'124'+Delim+'2';
       If Form1.RequestEchoChat1.Checked=True Then
         Data:=Data+Delim+'70'+delim+'1';
       Len:=Length(Data);
       Tmp:='SPRT'+#0+#0+#0+#0+Key+Form1.LengthToStr(Len)+#$21;
     End;
  End;

 If LoggedInName2='' Then
   LoggedInName2:=LoggedInName; 
 LoginName:=LoggedInName2;

 Tmp:=Tmp+Data;
 Speech:=Tmp;
 //RichCont.Lines.Add(LoginName+': '+Msg);
//    RichCont.SelStart:=-1;
//   RichCont.Lines.BeginUpdate;
    If Form1.On1.Checked=True Then
      Form1.DoAvatar(Form1.Richedit1,Identitar);
    RichCont.SelAttributes.Name:='Arial';
    RichCont.SelAttributes.Size:=10;
    RichCont.SelAttributes.Style:=[FsBold];
    RichCont.SelAttributes.Color:=Form10.ColorBox1.ColorValue;
    If Form10.checkbox35.Checked=True Then
     Begin
       RichCont.SelAttributes.Color:=Form10.ColorPickCombo11.ColorValue;
       RichCont.SelText:=LoginName;
     End
       else
      RichCont.SelText:=LoginName;
    RichCont.SelAttributes.Size:=UserFontSize;
    RichCont.SelAttributes.Color:=ClBlack;
    RichCont.SelAttributes.Style:=[];
    If Emote=False Then RichCont.SelText:=': '
       else  RichCont.SelText:=' ';

    If Form10.CheckBox28.Checked=True Then
       RichCont.SelText:='['+DateTimeToStr(Now)+'] ';

    RichCont.SelAttributes.Name:=Form1.SpSkinFontComboBox1.FontName;
    Try
     RichCont.SelAttributes.Size:=StrToInt(Form1.SpSkinComboBox2.Text);
     Except
      RichCont.SelAttributes.Size:=UserFontSize;
    End;
     If Form10.Radiobutton9.Checked=True Then
       RichCont.SelAttributes.Size:=Form10.SpinEdit4.Value;
     If Form10.Radiobutton11.Checked=True Then
       Plain:=True;
   If (Plain=False) and (emote=False) Then
    Begin
    RichCont.SelAttributes.Color:=Form1.ColorBox1.ColorValue;
    Bo:=False; I:=False; U:=False;
   If Form1.BoldP.checked=true Then
       RichCont.SelAttributes.Style:=RichCont.SelAttributes.Style+[FsBold];
    IF Form1.ItalicP.checked=true Then
       RichCont.SelAttributes.Style:=RichCont.SelAttributes.Style+[FsItalic];
    If Form1.UnderLineP.checked=true Then
       RichCont.SelAttributes.Style:=RichCont.SelAttributes.Style+[FsUnderline];
     End;
    If Plain=True Then
     Begin
       RichCont.SelAttributes.Style:=[];
       RichCont.SelAttributes.Color:=ClBlue;
     End;
  IF Plain=False Then
   Begin
    If Form1.spSkinCheckRadioBox1.Checked=True Then
     Begin
     If Form9.RadioButton1.Checked=True Then
      Begin
       DoFadeTag(Msg,LoggedInName);
       FadeTagText:=form1.RicheditBold(RichCont,FadeTagText);
       FullStr:=form1.RicheditBold(RichCont,FullStr);
//       form1.RicheditFadeWriteTag(RichCont,FadeTag,FadeTagText);
       S:=Form1.BuildRTFStr(RichCont,FullStr,FadeTagText,Form1.SpSkinFontComboBox1.FontName,StrToInt(Form1.SpSkinComboBox2.Text),Bo,I,U,True,True);
       Form1.SetSelectionRtf(RichCont,S);
       Msg:='';
       msg3:='';
       FinishDisplay(RichCont,SD);
       Exit;
      End;
   If Form9.RadioButton2.Checked=True Then
      Begin
       DoAltTag(Msg);
     //  Form1.RicheditAltWriteTag(RichCont,AltTag,AltTagText);
       AltTagText:=form1.RicheditBold(RichCont,AltTagText);
       FullStr:=form1.RicheditBold(RichCont,FullStr);
       S:=Form1.BuildRTFStr(RichCont,FullStr,AltTagText,Form1.SpSkinFontComboBox1.FontName,StrToInt(Form1.SpSkinComboBox2.Text),Bo,I,U,True,True);
       Form1.SetSelectionRtf(RichCont,S);
       Msg:='';
       Msg3:='';
       FinishDisplay(RichCont,SD);
       Exit;
      End;
    If Form9.RadioButton3.Checked=True Then
      Begin
       DoAltWTag(Msg);
       form1.RicheditAltWriteWTag(RichCont,AltWTag,AltWTagText);
       Msg:='';
       Msg3:='';
       FinishDisplay(RichCont,SD);
       Exit;
      End;
     End;
    End;
//  RichLen:=-1;
  Msg:=Msg3;
//  Msg:=DoAltIdTag(Msg);
//  If Form1.GetURL(Msg)<>'' Then
//    Msg:=URlHttpStr(Msg,Form1.GetUrl(Msg));
  If Plain=False Then
   Begin
    FullStr:=form1.RicheditBold(RichCont,Msg);
    S:=Form1.BuildRTFStr(RichCont,Msg,Msg,Form1.SpSkinFontComboBox1.FontName,StrToInt(Form1.SpSkinComboBox2.Text),BO,I,U,True,True);
    Form1.SetSelectionRtf(RichCont,S);
    FinishDisplay(RichCont,SD);
    Exit;
   End;

   If Plain=True Then
    Begin
       Msg:=Form1.Remove(msg,'<','>');
       msg:=form1.RicheditBold(RichCont,Msg);
       RichCont.SelText:=Msg;
       Msg:='';
       FinishDisplay(RichCont,SD);
    End;
End;


Function DoFadeTagE(S: String): String;
Var
 CI,Ci2,P1,P2: Integer;
 FadeTag,BckTmp,Tmp3,Tmp,Tmp2: String;
Begin
 //<FADE #ff0000,#00ff00,#0000ff>hello</FADE>
 BckTmp:=S;
 Tmp3:=S;
 Result:=BckTmp;
 P1:=PosRep('<fade #',LowerCaseRep(S));
 P2:=PosRep('</fade>',LowerCaseRep(S));
 Ci2:=0;
 CI:=Form1.ScanIT('<fade',LowerCaseRep(S));
While (P1>0)and (P2>0) And (CI2<=CI) Do
 Begin
 Inc(Ci2);
 P1:=PosRep('<fade ',LowerCaseRep(S));
 P2:=PosRep('</fade>',LowerCaseRep(S));
If (P1>0) and (P2>0) Then
 Begin
  P2:=Form1.InsTr('e>',LowerCaseRep(S),P1)+1;
  Tmp:=Copy(S,P1,P2-P1+2);
  Delete(S,P1,Length(Tmp));
  Tmp2:=Tmp;
  P1:=PosRep('#',Tmp);
  P2:=Form1.InsTr('>',Tmp,P1);
  Tmp:=Copy(Tmp,P1,P2-P1+1);
  FadeTag:=Tmp;
  Tmp:=bcktmp;
  P1:=PosRep('<fade',LowerCaseRep(Tmp));
  P2:=Form1.InsTr('>',Tmp,P1);
  Delete(Tmp,P1,p2-P1+2);
  Result:=FadeTag;
   End;
 End;
End;


Function DoAltTagE(S: String): String;
Var
 CI,Ci2,P1,P2: Integer;
 FadeTag,BckTmp,Tmp3,Tmp,Tmp2: String;
Begin
 //<FADE #ff0000,#00ff00,#0000ff>hello</FADE>
 BckTmp:=S;
 Tmp3:=S;
 Result:=BckTmp;
 P1:=PosRep('<alt #',LowerCaseRep(S));
 P2:=PosRep('</alt>',LowerCaseRep(S));
 Ci2:=0;
 CI:=Form1.ScanIT('<alt',LowerCaseRep(S));
While (P1>0)and (P2>0) And (CI2<=CI) Do
 Begin
 Inc(Ci2);
 P1:=PosRep('<alt ',LowerCaseRep(S));
 P2:=PosRep('</alt>',LowerCaseRep(S));
If (P1>0) and (P2>0) Then
 Begin
  P2:=Form1.InsTr('t>',LowerCaseRep(S),P1)+1;
  Tmp:=Copy(S,P1,P2-P1+2);
  Delete(S,P1,Length(Tmp));
  Tmp2:=Tmp;
  P1:=PosRep('#',Tmp);
  P2:=Form1.InsTr('>',Tmp,P1);
  Tmp:=Copy(Tmp,P1,P2-P1+1);
  FadeTag:=Tmp;
  Tmp:=bcktmp;
  P1:=PosRep('<alt',LowerCaseRep(Tmp));
  P2:=Form1.InsTr('>',Tmp,P1);
  Delete(Tmp,P1,p2-P1+2);
  Result:=FadeTag;
   End;
 End;
End;


Function Tform1.RicheditAltWTagStr(Colours,Msg: String): String;
Var
 Col,Col2: Tcolor;
 ColTagS: TStringList;
 BuildStr,TmpCol,TmpCol2,Tmp,Tmp2: String;
 ColCount,N,N2: Integer;
 TempChar: Char;
 FF1,FF2,FF3: Boolean;
 WordCount,Rcmp,GCmp,BCmp,RS,GS,BS,RF,GF,BF,P1,P2: Integer;
 NewR,NewB,NewG: Integer;
 MyC,MyC2: String;
Begin
// Msg:=Remove(Msg,'<','>');
 ColTags:=TStringList.Create;
 NewR:=0; NewB:=0; NewG:=0; RS:=0; GS:=0; BS:=0;
 RF:=0; GF:=0; BF:=0; P1:=0; P2:=0;
 //Msg:=Remove(Msg,#$1b,'m');
 WordCount:=ScanIt(' ',Msg);
 ColCount:=ColourCount(Colours);
 Tmp2:=Msg;
 Tmp:=Colours+',';
  While PosRep(',',Tmp)>0 do
   Begin
    NewR:=0; NewB:=0; NewG:=0; RS:=0; GS:=0; BS:=0;
    RF:=0; GF:=0; BF:=0; P1:=0; P2:=0;
    P1:=PosRep(',',Tmp);
    TmpCol:=Copy(Tmp,1,p1-1);
    Delete(TmpCol,1,1);
    Try
     Tmp2:=ColorToString(ReverseColor(TmpCol));
     Except
    End;
    ColTags.Add(Tmp2);
    Delete(Tmp,1,P1);
   End;
   N:=0;
  Tmp:=Msg+' ';
 If tmp<>'' Then
  Begin
  Try
 While ScanIt(' ',Tmp)>0 Do
    Begin
     Tmp2:=Tmp;
         N2:=N Mod ColCount;
         Inc(N);
//         Col:=StringToColor(ColTags[N2]);
//         RichCont.SelAttributes.Color:=Col;
         Tmp2:=Copy(Tmp,1,PosRep(' ',Tmp));
//         For N2:=1 To Length(Tmp2) Do
//           RichCont.SelText:=Tmp2[n2];
          TmpCol:=ColTags[N2];
          If ConvertToRGB('#'+TmpCol)=True Then
             Begin
              RF:=R;
              GF:=G;
              BF:=B;
             End;
          BuildStr:=BuildStr+';'+'\red'+IntToStr(r)+'\green'+IntToStr(g)+'\blue'+IntToStr(b)+'';
          Delete(Tmp,1,Length(Tmp2));
       End;
    Except
    End;
  End;
 Result:=BuildStr;
 ColTags.Free;
End;


Function Tform1.RicheditAltTagStr(Colours,Msg: String): String;
Var
 Col: Tcolor;
 ColTagS: TStringList;
 BuildStr,TmpCol,Tmp,Tmp2: String;
 ColCount,N,N2: Integer;
 FF1,FF2,FF3: Boolean;
 WordCount,RS,GS,BS,RF,GF,BF,P1: Integer;
 NewR,NewB,NewG: Integer;
 MyC,MyC2: String;
Begin
// Msg:=Remove(Msg,'<','>');
 ColTags:=TStringList.Create;
 NewR:=0; NewB:=0; NewG:=0; RS:=0; GS:=0; BS:=0;
 RF:=0; GF:=0; BF:=0; P1:=0;
 //Msg:=Remove(Msg,#$1b,'m');
 WordCount:=ScanIt(' ',Msg);
 ColCount:=ColourCount(Colours);
 Tmp2:=Msg;
 Tmp:=Colours+',';
  While PosRep(',',Tmp)>0 do
   Begin
    NewR:=0; NewB:=0; NewG:=0; RS:=0; GS:=0; BS:=0;
    RF:=0; GF:=0; BF:=0; P1:=0;
    P1:=PosRep(',',Tmp);
    TmpCol:=Copy(Tmp,1,p1-1);
    Delete(TmpCol,1,1);
    ColTags.Add(TmpCol);
    Delete(Tmp,1,P1);
   End;
   N:=0;
  Tmp:=Msg;
 If tmp<>'' Then
  Begin
  Try
   Tmp:=Tmp+' ';
   While Length(Tmp)>0 do
    Begin
     Tmp2:=Tmp;
        Begin
          N2:=N Mod ColCount;
          Inc(N);
          //Col:=StringToColor(ColTags[N2]);
           TmpCol:=ColTags[N2];
            If ConvertToRGB('#'+TmpCol)=True Then
             Begin
              RF:=R;
              GF:=G;
              BF:=B;
             End;
          BuildStr:=BuildStr+';'+'\red'+IntToStr(r)+'\green'+IntToStr(g)+'\blue'+IntToStr(b)+'';
          Delete(Tmp,1,1);
         End;
       End;
      Except
    End;
  End;
 ColTags.Free;
 Result:=BuildStr;
End;



function AdjustGamma(Color: double): Integer;
const Gamma = 0.25; //(0...10) - smooth transition effect
begin
     if Color <= 0 then result := 0    else
     if Color > 255 then result := 255 else
//     result := round(Color);
     result := round(255 * Power(Color/255, Gamma) );
end;

function Palette (i: integer): TColor;
var R, G, B: double;
    R1,R2,G1,G2,B1,B2: integer;
    v1, v2, delta: double;
    i1,i2,k1,k2: integer;
    C1,C2: TColor;
    ch:char;
begin
     //note: total PaletteSteps are distributed between NColors
     // i-some position between 1 <= ii <= PaletteSteps
     // get mix colors

     k1:=trunc( (NColors-1) * (i-1) / (PaletteSteps-1) );
     k2:=k1+1; if k2 > Ncolors-1 then k2:=Ncolors-1;

     v1:=k1 * (PaletteSteps-1) / (NColors-1);
     v2:=k2 * (PaletteSteps-1) / (NColors-1);

     C1:=AColors[k1];
     C2:=AColors[k2];

     R1:=GetRValue(C1); G1:=GetGValue(C1); B1:=GetBValue(C1);
     R2:=GetRValue(C2); G2:=GetGValue(C2); B2:=GetBValue(C2);

     //2-color transition C1->C2
     delta := V2 - V1;
     R := R1 + (R2-R1) * (i-v1) / delta;
     G := G1 + (G2-G1) * (i-v1) / delta;
     B := B1 + (B2-B1) * (i-v1) / delta;

     result:=RGB( AdjustGamma(R), AdjustGamma(G), AdjustGamma(B) );

end;
//------------------------------------------------------------

function RicheditFadeStrOld(Msg: String): string;
Var i, L, pClr, pClr_bak: integer;
    Clr: TColor;
    RS: string;
Begin
    // we shell limit color table to some PalletteSteps
    // there would be no more then PaletteSteps color in color table
    // create clortable

{    PaletteSteps:=32;

    If Length(Msg)<32 Then
       PaletteSteps:=Length(Msg);}

    PaletteSteps:=Length(Msg);

//    PaletteSteps:=Length(Msg) Div NColors;


    for i:=0 to PaletteSteps-1 do begin
      Clr:= Palette(i);
      RS:=RS+ ';\red'+IntToStr(GetBValue(Clr))+'\green'+IntToStr(GetGValue(Clr))+'\blue'+IntToStr(GetRValue(Clr));

//   BuildStr:=BuildStr+';'+'\red'+IntToStr(NewR)+'\green'+IntToStr(NewG)+'\blue'+IntToStr(NewB)+'';
    end;
    L:=Length(msg);

    //stuff string with color modifiers when needed
    pClr_bak:=-1;

{    for i:=0  to L-1 do begin
      pClr:=round(1+(PaletteSteps-1) * i / (L-1) ); //find a new color edge

      if pClr <> pClr_bak then //edge found
      begin
        RS:=RS+ '\cf'+IntToStr(pClr)+' '+copy(msg,i+1,1);
        pClr_bak:=pClr;
      end
      else //no color modifier - use current color
        RS:=RS+copy(msg,i+1,1);

    end;

    //finalize}
//    RS:=RS+'\cf0\par}'; // reset to default color +LF+CR

    result:=RS;
End;

procedure SetColors2(S: string);
var TmpCol,s1: string;
    P1,i,i1,i2: integer;
    Strings: TStringList;
begin
//    if S = '' then exit;

    //separate ColorString into substrings (colors)
    Strings:=TStringList.Create;
    S:=S+','; //add terminator
    NColors:=0; //number of colors found
    i1:=0; i2:=0;
    While PosRep(',',S)>0 do
     Begin
       P1:=PosRep(',',S);
       TmpCol:=Copy(S,1,p1-1);
       Delete(TmpCol,1,1);
       Strings.Add('$'+TmpCol);
       Inc(NColors);
       Delete(S,1,P1);
    end;

    SetLength(Acolors, NColors); //set dimension of colors array

    //define colors
    for i:=0 to NColors-1 do
      Acolors[i]:=StringToColor(Strings[i]);

    Strings.Free;
end;

Function Tform1.RicheditFadeStr(Colours,Msg: String): String;
Var
 Col,Col2: Tcolor;
 BlendCol: Array Of TColor;
 BlendSetFlag: Array Of Boolean;
 ActUsedColours: Array Of Integer;
 UsedBands, NumChars, X1 ,Y1, X2, Y2: Integer;
 P1,CharCount,N,Rs,Gs,Bs,Re,Ge,Be,colval: Integer;
 SplitRange, R,G,B, R2,G2,B2: Real;
 JumpR,JumpG,JumpB: Real;
 Gradient,CharsPerBlend2: Integer;
 CharsPerBlend,I, BandCount, LoopStart, LoopEnd, CharNum: Integer;
 TmpCol,Tmp,BuildStr,BuildStr2,HexVal: string;
Begin
 BuildStr:='';
 CharCount:=Length(Msg);
 NumChars:=CharCount;
 ColCount:=ColourCount(Colours);
 Tmp:=Colours+',';
 UsedBands:=0;
 SetLength(BlendCol,UsedBands+2);
 SetLength(BlendSetFlag,UsedBands+2);
  While (PosRep(',',Tmp)>0) do
   Begin
    P1:=PosRep(',',Tmp);
    TmpCol:=Copy(Tmp,2,p1-1);
    Delete(Tmp,1,PosRep(',',Tmp));
    BlendCol[UsedBands]:=ReverseColor(TmpCol);
    BlendSetFlag[UsedBands]:=True;
    Inc(UsedBands);
    SetLength(BlendCol,UsedBands+2);
    SetLength(BlendSetFlag,UsedBands+2);
   End;
  If UsedBands = 1 Then   // Solid Colour
    Begin
      // Character Colours
      Rs := GetRValue(BlendCol[0]);    // Start Color R
      Gs := GetGValue(BlendCol[0]);    // Start Color G
      Bs := GetBValue(BlendCol[0]);    // Start Color B
      R := Rs; G := Gs; B := Bs;
      CharNum := 0;
      For I := 0 to NumChars-1 do  // Loop through chars in each blend range
        Begin
          R := ABS(R);  G := ABS(G);  B := ABS(B);
          HexVal:='$'+IntToHex(Trunc(B),2)+IntToHex(Trunc(G),2)+IntToHex(Trunc(R),2);
//          CharColArray[Charnum] := HexVal; // Array holding each characters hex colour (base 0)
          Inc(CharNum);
          BuildStr:=BuildStr+';'+'\red'+IntToStr(Trunc(R))+'\green'+IntToStr(Trunc(G))+'\blue'+IntToStr(Trunc(B))+'';
        End;
    End
  Else
    Begin  // Blend Range Possible (Number = UsedColours-1)
      // Character Colours
      If ColCount-1 = 0 Then
        CharsPerBlend := CharCount
      Else
        CharsPerBlend := CharCount DIV (ColCount-1);
      If CharsPerBlend <1 Then CharsPerBlend := 1;
      CharNum := 0;
      For Gradient := 0 To ColCount-2 Do // 3 colours = 2 gradients (0 to 1)
        Begin
          Rs := GetRValue(BlendCol[Gradient]);    // Start Color R
          Gs := GetGValue(BlendCol[Gradient]);    // Start Color G
          Bs := GetBValue(BlendCol[Gradient]);    // Start Color B
          Re := GetRValue(BlendCol[Gradient+1]);  // Next Color R
          Ge := GetGValue(BlendCol[Gradient+1]);  // Next Color G
          Be := GetBValue(BlendCol[Gradient+1]);  // Next Color B
          R := Rs; G := Gs; B := Bs;
          // Now Calculate Shades for this band
          JumpR := (Re-Rs) / CharsPerBlend;
          JumpG := (Ge-Gs) / CharsPerBlend;
          JumpB := (Be-Bs) / CharsPerBlend;

          LoopStart := gradient * CharsPerBlend;
          LoopEnd := (Gradient+1) * CharsPerBlend-1;
          For I := LoopStart to LoopEnd do  // Loop through chars in each blend range
            Begin
              R := ABS(R);  G := ABS(G);  B := ABS(B);
              HexVal:='$'+IntToHex(Trunc(B),2)+IntToHex(Trunc(G),2)+IntToHex(Trunc(R),2);
//              CharColArray[Charnum] := HexVal; // Array holding each characters hex colour (base 0)
              Inc(CharNum);
              BuildStr:=BuildStr+';'+'\red'+IntToStr(Trunc(R))+'\green'+IntToStr(Trunc(G))+'\blue'+IntToStr(Trunc(B))+'';
              R:=R+JumpR;    // Trunc()
              G:=G+JumpG;
              B:=B+JumpB;
            End;
        End;
          If CharCount > 1 Then
            Begin
              Re := GetRValue(BlendCol[ColCount-1]);  // Next Color R
              Ge := GetGValue(BlendCol[ColCount-1]);  // Next Color G
              Be := GetBValue(BlendCol[ColCount-1]);  // Next Color B
              R := Re; G := Ge; B := Be;
              R := ABS(R);  G := ABS(G);  B := ABS(B);
              BuildStr:=BuildStr+';'+'\red'+IntToStr(Trunc(R))+'\green'+IntToStr(Trunc(G))+'\blue'+IntToStr(Trunc(B))+'';
            End;
    End;
  Result:=BuildStr;
End;




Function Tform1.FaceRtfStr(Str: String): String;
Var
 CharS: TFontcharSet;
 Tmp: String;
 T: System.Text;
 P: Integer;
 SInfo: PSmileyInfo;
 Ms2: TmemoryStream;
 S: TFileStream;
 BR: Integer;
Begin
Result:='';


If SmileyCount<Form10.SpinEdit7.Value Then
 Begin
  Result:='';
  Inc(SmileyCount);
  Tmp:='';
  If Smileys.Find(Str,Tobject(Sinfo))=True Then
      Tmp:=Sinfo.FileName;
//      DoRtfFace(RichCont,Sinfo.FileName);


{  If FileExists(Path+'rtfimages\'+tmp+'bmp')=True Then
   Begin
    Form1.ConvertBmpToRtf(Path+'rtfimages\'+tmp+'bmp',Path+'rtfimages\'+tmp+'');
    DeleteFile(Path+'rtfimages\'+tmp+'bmp');
   End;}


If FileExists(Path+'rtfimages\'+Tmp+'bmp')=True Then
 Begin
   Form1.ConvertBmpToRtf(Path+'rtfimages\'+Tmp+'bmp',Path+'rtfimages\'+Tmp+'');
   DeleteFile(Path+'rtfimages\'+Tmp+'bmp');
 End;

 IF FileExists(Path+'rtfimages\'+Tmp) Then
  Begin
      S := TFileStream.Create(Path+'rtfimages\'+Tmp, fmOpenRead or fmShareDenyNone);
      SetLength(Result,S.Size);
      FillChar(Result[1],S.Size,#0);
      Br:=S.Read(Result[1],S.Size);

      If PosRep(#$0d+#$0a,Result)>0 Then
          Result:=Copy(Result,1,PosRep(#$0d+#$0a,Result)-1);
      S.Free;

    End
   else
 Begin
  Tmp:=Copy(tmp,1,PosRep('.',tmp)-1);

  Exit;
 End;

 If Copy(Result,1,6)='{\rtf1' Then
     Delete(Result,1,PosRep(' ',Result));
 If (Result[Length(Result)]='}') and (Result[Length(Result)-1]='}') Then
     Result:=Copy(Result,1,Length(result)-1);
  End;
End;

Function Tform1.RemoveSmiles(S: String): String;
Var
 C: Integer;
 BuildStr,Ts: String;
 F1,F2,F3: Boolean;
Begin
 TS:=S;
    While Length(TS)>0 Do
     Begin
      Inc(C);
      F1:=False; F2:=False; F3:=False;
      If IsSmile(LowerCaseRep(Copy(Ts,1,4)))<>-1 Then
       Begin
        Delete(Ts,1,4);
        F1:=True;
       End;
      If IsSmile(LowerCaseRep(Copy(Ts,1,3)))<>-1 Then
       Begin
        Delete(Ts,1,3);
        F2:=True;
       End;
      If IsSmile(LowerCaseRep(Copy(Ts,1,2)))<>-1 Then
       Begin
        Delete(Ts,1,2);
        F3:=True;
       End;
      If (F1=False) And (F2=False) And (F3=False) Then
       Begin
         If Length(TS)>0 Then
          Begin
           BuildStr:=BuildStr+Ts[1];
           Delete(Ts,1,1);
          End;
       End;
     End;
  Result:=BuildStr;
End;

Function CreateColorTblString(S1,S2: String): String;
Var
 N: Integer;
 Tmp1,Tmp2: String;
 ScreenState,FoundTag: Boolean;
 F1,F2,F3: Boolean;
 P1,P2: Integer;
 NewR,NewG,NewB: Integer;
 BuildStr,TmpCol,msg,Msg3,Msg2,Col,OldCol: String;
 WMsg: TMsg;
 ISP: Integer;
Begin
//   BuildStr:=BuildStr+';'+'\red'+IntToStr(NewR)+'\green'+IntToStr(NewG)+'\blue'+IntToStr(NewB)+'';
//   Richedit1.Lines.Add('R: '+IntToStr(NewR)+' G: '+IntToStr(NewG)+' b: '+IntToStr(NewB));
 Tmp1:=S1;
 Msg:=S2;
 N:=0;
  While (Length(msg)>0) Do
  Begin
    Inc(N);
    foundtag:=False;
     If Msg[1]=#$1B Then
      Begin
        P1:=PosRep(#$1b,Msg);
        Delete(Msg,1,p1-1);
        P2:=Form1.Instr('m',Msg,p1);
        col:='';
        Col:=Copy(Msg,P1,P2-P1+2);
        Delete(Msg,P1,P2-P1+2);
        If Col=Ybold Then
          foundtag:=True;
        If Col=Ynobold Then
          foundtag:=True;
        If Col=Ynoi Then
          foundtag:=True;
        If Col=Ynoun Then
          foundtag:=True;
        If Col=Yitalic Then
          foundtag:=True;
        If Col=Yun Then
          foundtag:=True;
       If (FoundTag=False) And (Col<>'') Then
        Begin
          TmpCol:=Col;
          ColourOf(Col);
          NewR:=B;
          NewG:=G;
          NewB:=R;
//          BuildStr:=BuildStr+';'+'\red'+IntToStr(NewR)+'\green'+IntToStr(NewG)+'\blue'+IntToStr(NewB)+'';
          BuildStr:=BuildStr;
        End;
//         RichCont.SelAttributes.Color:=ColourOf(Col);
      End;
   If Length(Msg)>0 Then
    Begin
       If Msg[1]<>#$1B Then
        Begin
          F1:=False;
          F2:=False;
          F3:=False;
         If IsSmile(LowerCaseRep(Copy(Msg,1,4)))<>-1 Then
           Begin
            Delete(Msg,1,4);
            F1:=True;
           End;
         If IsSmile(LowerCaseRep(Copy(Msg,1,3)))<>-1 Then
           Begin
            Delete(Msg,1,3);
            F2:=True;
           End;
         If IsSmile(LowerCaseRep(Copy(Msg,1,2)))<>-1 Then
           Begin
            Delete(Msg,1,2);
            F3:=True;
           End;
           If (F1=False) And (F2=False) And (F3=False) Then
             Begin
              Inc(RichLen);
              Delete(Msg,1,1);
              BuildStr:=BuildStr+';'+'\red'+IntToStr(NewR)+'\green'+IntToStr(NewG)+'\blue'+IntToStr(NewB)+'';
             End;
          End;
       End;
    End;
  Result:=BuildStr;
//  End;
  //
  //
//  CalledAppProcess:=False;
//  Form1.Ymsg.OnRead:=Form1.YmsgRead;
   CalledAppProcess:=False;
End;

Function TForm1.GetMousePos: TCords;
var
 Pos: dword;
begin
 Pos:=GetMessagePos();
 Result.Y:=hiword(Pos);
 Result.X:=loword(Pos);
End;

Function Tform1.BuildRTFStr(RichCont: TCustomRichedit; S,TextSt,Font: String; FontSize: Integer; B,I,U,OVR,ShowSmileys: Boolean): String;
Const
 Header: String = '{\rtf1\ansi\ansicpg1252\deff0\deflang3081{\fonttbl{\f0\fnil\fcharset0 Comic Sans MS;}{\f1\f %S;}}'+#$0d+#$0a;
 ColorTbl: String = '{{\colortbl %s;}'+#$0d+#$0a;
 MainStr: String = '\viewkind4\uc1\pard\Cf1%s}'+#$0d+#$0a;
Var
 Tmp: String;
 F1,F2,F3: Boolean;
 P1,P2,OfType,C,N: Integer;
 Col,BuildStr2,BuildStr,FadeT,TS2,TS,FT: String;
Begin
 Ft:=S;
 BuildStr:='';
 BuildStr2:='';
 If OVR=False Then
  Begin
  FT:=DoFontTag(FT);
  FT:=DoFontSize(FT,FontSize);
  If Font<>'' Then
   FontFaceTag:=Font;

   If Form10.RadioButton6.Checked=True Then
    If FontSizeTag>Form10.SpinEdit4.Value Then
     FontSizeTag:=Form10.SpinEdit4.Value;

   If (FontSizeTag<10) or (FontSizeTag>20) Then
     FontSizeTag:=FontSize;
 End
  else
 Begin
  FontSizeTag:=FontSize;
  FontFaceTag:=Font;
 End;
 OfType:=-1;
 If PosRep('<fade',LowerCaseRep(Ft))>0 Then OfTYpe:=0;
 If PosRep('<alt',LowerCaseRep(Ft))>0 Then OfTYpe:=1;
 If OfType=-1 Then
   OfType:=2;
// Ts:=Form1.ExtractBetweenString('>','</',Ft,False);
{If ShowSmileys=True Then
 Ts:=Form1.Remove2(FT,'<','>')
  else}
 TS:=TextSt;

Case OfType Of
 0: Begin  //Normal Fade
 If FT<>'' Then
  Begin
    C:=0;
    FT:=DoFadeTagE(FT);
    If ShowSmileys=True Then
      TS2:=Form1.RemoveSmiles(TS)
       else
     Ts2:=TS;
    Ts2:=Form1.Remove2(Ts2,'<font','>'); 
    S:=RicheditFadeStr(FT,Ts2);  //working one
 //   S:=CreateRTFFadeStr(FT,Ts2);  //two fade string
//    SetColors2(FT); // new one
//    S:=RicheditFadeStrold(TS); //new one
//    SetSelectionRtf(RichCont,S);
//    Delay(10000);
    BuildStr:=Format(Header,[font]);
    BuildStr:=BuildStr+Format(ColorTbl,[S]);
    If B=True Then BuildStr2:=BuildStr2+'\b';
    If i=True Then BuildStr2:=BuildStr2+'\i';
    If u=True Then BuildStr2:=BuildStr2+'\ul';
    BuildStr2:=BuildStr2+'\f0\fs'+IntToStr(FontSize*2)+' ';//+Ts[1];
   // For N:=1 to Length(Ts) Do
   While Length(TS)>0 Do
     Begin
      Inc(C);
      F1:=False; F2:=False; F3:=False;
     If ShowSmileys=True Then
      Begin
      If IsSmile(LowerCaseRep(Copy(Ts,1,4)))<>-1 Then
       Begin
        BuildStr2:=BuildStr2+FaceRtfStr(LowerCaseRep(Copy(Ts,1,4)));
        Delete(Ts,1,4);
        F1:=True;
       End;
      If IsSmile(LowerCaseRep(Copy(Ts,1,3)))<>-1 Then
       Begin
        BuildStr2:=BuildStr2+FaceRtfStr(LowerCaseRep(Copy(Ts,1,3)));
        Delete(Ts,1,3);
        F2:=True;
       End;
      If IsSmile(LowerCaseRep(Copy(Ts,1,2)))<>-1 Then
       Begin
        BuildStr2:=BuildStr2+FaceRtfStr(LowerCaseRep(Copy(Ts,1,2)));
        Delete(Ts,1,2);
        F3:=True;
       End;
      End;
      If (F1=False) And (F2=False) And (F3=False) Then
       Begin
        If (Ts[1]='\')  Then
         BuildStr2:=BuildStr2+Format('\cf%d %s\',[C,Ts[1]])
          else
        If (Ts[1]='{') or (Ts[1]='}') Then
        BuildStr2:=BuildStr2+Format('\%s',[Ts[1]])
         else
        BuildStr2:=BuildStr2+Format('\cf%d %s',[C,Ts[1]]);
         Delete(Ts,1,1);
       End;
     End;
    BuildStr2:=BuildStr2+'}';
    BuildStr:=BuildStr+Format(MainStr,[BuildStr2]);
  //  BuildStr:=BuildStr+BuildStr2;
  End;
 End;
 1: Begin  //  Alternating Fade
    C:=0;
 If FT<>'' Then
  Begin
    FT:=DoAltTagE(FT);
//    TS2:=Form1.RemoveSmiles(TS);
    Ts:=Form1.Remove2(Ts,'<font','>');
    S:=RicheditAltTagStr(FT,TS);
    BuildStr:=Format(Header,[font]);
    BuildStr:=BuildStr+Format(ColorTbl,[S]);
    If B=True Then BuildStr2:=BuildStr2+'\b';
    If i=True Then BuildStr2:=BuildStr2+'\i';
    If u=True Then BuildStr2:=BuildStr2+'\ul';
    BuildStr2:=BuildStr2+'\f0\fs'+IntToStr(FontSize*2)+' ';//+Ts[1];
   // For N:=1 to Length(Ts) Do
   While Length(TS)>0 Do
     Begin
      Inc(C);
      F1:=False; F2:=False; F3:=False;
      If ShowSmileys=True Then
      Begin
      If IsSmile(LowerCaseRep(Copy(Ts,1,4)))<>-1 Then
       Begin
        BuildStr2:=BuildStr2+FaceRtfStr(LowerCaseRep(Copy(Ts,1,4)));
        Delete(Ts,1,4);
        F1:=True;
       End;
      If IsSmile(LowerCaseRep(LowerCaseRep(Copy(Ts,1,3))))<>-1 Then
       Begin
        BuildStr2:=BuildStr2+FaceRtfStr(LowerCaseRep(Copy(Ts,1,3)));
        Delete(Ts,1,3);
        F2:=True;
       End;
      If IsSmile(LowerCaseRep(Copy(Ts,1,2)))<>-1 Then
       Begin
        BuildStr2:=BuildStr2+FaceRtfStr(LowerCaseRep(Copy(Ts,1,2)));
        Delete(Ts,1,2);
        F3:=True;
       End;
      End;
     If Length(TS)>0 Then
      If (F1=False) And (F2=False) And (F3=False) Then
       Begin
        If (Ts[1]='\')  Then
         BuildStr2:=BuildStr2+Format('\cf%d %s\',[C,Ts[1]])
          else
        If (Ts[1]='{') or (Ts[1]='}') Then
        BuildStr2:=BuildStr2+Format('\%s',[Ts[1]])
         else
        BuildStr2:=BuildStr2+Format('\cf%d %s',[C,Ts[1]]);
        Delete(Ts,1,1);
       End;
     End;
    BuildStr2:=BuildStr2+'}';
    BuildStr:=BuildStr+Format(MainStr,[BuildStr2]);
//    BuildStr:=BuildStr+BuildStr2;
    End;
 End;
 2: Begin
  C:=0;
 If FT<>'' Then
  Begin
 //    TS2:=Form1.RemoveSmiles(TS);
    P1:=0;
    BuildStr:=Format(Header,[font]);
    S:=CreateColorTblString(FT,TS);
    BuildStr:=BuildStr+Format(ColorTbl,[S]);
    If B=True Then BuildStr2:=BuildStr2+'\b';
    If i=True Then BuildStr2:=BuildStr2+'\i';
    If u=True Then BuildStr2:=BuildStr2+'\ul';
    BuildStr2:=BuildStr2+'\f0\fs'+IntToStr(FontSize*2)+' ';//+Ts[1];
   // For N:=1 to Length(Ts) Do
   While Length(TS)>0 Do
     Begin
      //
     If Length(TS)>0 Then
      If TS[1]=#$1B Then
      Begin
        P1:=PosRep(#$1b,TS);
        Delete(TS,1,p1-1);
        P2:=Form1.Instr('m',TS,p1);
        Col:=Copy(TS,P1,P2-P1+2);
        Delete(TS,P1,P2-P1+2);
        If Col=Ybold Then
          BuildStr2:=BuildStr2+'\b ';
        If Col=Ynobold Then
          BuildStr2:=BuildStr2+'\b0 ';
        If Col=Ynoi Then
          BuildStr2:=BuildStr2+'\i0 ';
        If Col=Ynoun Then
          BuildStr2:=BuildStr2+'\ulnone ';
        If Col=Yitalic Then
          BuildStr2:=BuildStr2+'\i ';
        If Col=Yun Then
          BuildStr2:=BuildStr2+'\ul ';
       End;
      //
      F1:=False; F2:=False; F3:=False;

    If Length(TS)>0 Then
     If (ShowSmileys=True) And (Ts[1]<>#$1B)  Then
      Begin
      If IsSmile(LowerCaseRep(Copy(Ts,1,4)))<>-1 Then
       Begin
        BuildStr2:=BuildStr2+FaceRtfStr(LowerCaseRep(Copy(Ts,1,4)));
        Delete(Ts,1,4);
        F1:=True;
       End;
      If IsSmile(LowerCaseRep(Copy(Ts,1,3)))<>-1 Then
       Begin
        BuildStr2:=BuildStr2+FaceRtfStr(LowerCaseRep(Copy(Ts,1,3)));
        Delete(Ts,1,3);
        F2:=True;
       End;
      If IsSmile(LowerCaseRep(Copy(Ts,1,2)))<>-1 Then
       Begin
        BuildStr2:=BuildStr2+FaceRtfStr(LowerCaseRep(Copy(Ts,1,2)));
        Delete(Ts,1,2);
        F3:=True;
       End;
      End;

      If Length(TS)>0 Then
       Begin
        If (F1=False) And (F2=False) And (F3=False) And (Ts[1]<>#$1B) Then
         Begin
            //
          Inc(C);
          If (Ts[1]='\')  Then
           BuildStr2:=BuildStr2+Format('\cf%d %s\',[C,Ts[1]])
            else
           If (Ts[1]='{') or (Ts[1]='}') Then
            BuildStr2:=BuildStr2+Format('\%s',[Ts[1]])
           else
           BuildStr2:=BuildStr2+Format('\cf%d %s',[C,Ts[1]]);
           Delete(Ts,1,1);
         End;
       End;
    End;
            //
    BuildStr2:=BuildStr2+'}';
    BuildStr:=BuildStr+Format(MainStr,[BuildStr2]);
//    BuildStr:=BuildStr+BuildStr2;
    End;
   //

   End;
 End;
 Result:=BuildStr;
 Tmp:=S;
End;



Function Tform1.IsBuddy(Buddy: String): Boolean;
Var
 R: Integer;
 Obj: Tobject;
Begin
 Result:=Friends.Find(Buddy,Obj);
End;

Procedure Tform1.UpdateConsole;
Begin
  Form1.CreateSkin(Form44);
  Form44.Show;
End;

Procedure Tform1.Say(RichCont: TMyRichedit;S: String; Plain,Emote,Test: Boolean);
Var
  S2: String;
Begin
// S:=S+'<ALT ID=YmLite>';
//S:=DelphiSyntax(S);
//Repeat Form1.MyApplicationProcess; Until CalledAppProcess=False;
ClearSaidYourName;
RichCont.SelStart:=-1;
 Inc(ChatLines);
// Form1.RichEdit1.Lines.BeginUpdate;
 If Length(S)>=MaxChatPacketSize Then
   Begin
   While Length(S)>=MaxChatPacketSize do
    Begin
     s2:=Copy(S,1,MaxChatPacketSize);
     Delete(S,1,Length(s2));
     If (form1.InChat=True) Then
       Form1.SendText(Speech(RichCont,LoggedInName,GpRoomName,S2,'',plain,Emote,False));
     Form1.Delay(StrToInt(Form10.Edit7.Text));
    End;
      If (InChat=True) Then
       Begin
        Form1.SendText(Speech(RichCont,LoggedInName,GpRoomName,S,'',plain,Emote,False));
       End;
   end
    else
   If (InChat=True) Then
    Begin
      Form1.SendText(Speech(RichCont,LoggedInName,GpRoomName,S,Ybold+Ypurple,Plain,Emote,False));
    End;
 //Form1.RichEdit1.Lines.EndUpdate;
End;


Procedure Tform1.SayPm(ToUser,FromWho,S: String);
Var
 FNS,S2: String;
 N: Integer;
 Tf: TExtfile;
Begin
{ If Friends.indexOf(ToUser)=-1 Then
     Friends.Add(ToUser);}

 If Length(S)>=MaxPmPacketSize Then
   Begin
   While Length(S)>=MaxPmPacketSize do
    Begin
     s2:=Copy(S,1,MaxPmPacketSize);
     Delete(S,1,Length(s2));
     Form1.SendText(Form1.PmFake(ToUser,FromWho,S2));
     Form1.Delay(300);
    End;
     Form1.SendText(Form1.PmFake(ToUser,FromWho,S));
   end
    else
     Form1.SendText(Form1.PmFake(ToUser,FromWho,S));


End;


Procedure TForm1.DebugPacket(S: String; Code: Integer);
Begin
  If (Form3.Visible=True) And (Form3.DebugUser='') Then
    TDebugDisplay.Create(S,Code)
End;


Function Tform1.IsOnlineBuddy(UserName: String): Boolean;
Var
 R,N: Integer;
 Obj: Tobject;
Begin
 Result:=Friends.Find(Username,Obj);
End;


Function TheyShouting(UserName,MessageStr: String): Boolean;
 var
  Num,Num1: Integer;
Begin
 TheyShouting:=False;
 num1:=0;
 for num:=1 to length(MessageStr) do
  if (MessageStr[num] in ['A'..'Z','?','!','''',' ','@','.',')','(']) then
    inc(num1);
 if num1=length(MessageStr) then
   if num1>2 then
     TheyShouting:=True;
end;

Function ExtractSpam(S,ext: String): String;
Var
 N, R: Integer;
 Tmp: String;
Begin
 Result:='';
 R:=0;
 IF Length(S)>0 Then
 For N:=1 to Length(S) Do
   If S[N]=' ' Then
     R:=N;
  If R<>0 Then
   Begin
     Tmp:=S;
     Delete(Tmp,1,R);
     Result:=Copy(Tmp,1,PosRep(Ext,Tmp)+Length(Ext));
   End;
End;


Function ValidText(RestOfmsg,UserN: String): Boolean;
Var
 P1,P2,N,NumCount: Integer;
 Version,R,Badchars: Integer;
 Obj: Tobject;
 TheClient,NewS,S,Tmp,TestStr: String;
 Label GetOut;
Begin
Badchars:=0;
SplitWords(RestOfMsg);
ValidText:=True;
If Form10.RadioButton8.Checked=True Then
  Exit;

If Form10.CheckBox26.Checked=False Then
 If Friends.Find(UserN,Obj)=False Then
    Exit;


NewS:='';
NumCount:=0;
If Form10.CheckBox7.Checked=true then
 Begin
 SetLength(News,Length(RestOfMsg));
 If Length(RestOfMsg)>2 Then
 For N:=1 to Length(RestOfMsg) Do
  Begin
    If RestofMsg[N] in ['0'..'9'] Then
     Begin
      Inc(NumCount);
      News[NumCount]:=RestOfMsg[N];
     End;
   End;
    SetLength(News,NumCount);
    If Length(News)>2 Then
    If MatchStr(Pchar(News),Pchar(RestOfMsg))>Form10.SpinEdit2.Value Then
     Begin
      ValidText:=False;
      Exit;
     End;
End;

If Form10.CheckBox11.Checked=False Then
 Begin
  S:=Form10.Edit5.Text;
  For N:=1 to Form1.Scanit(',',S)+1 Do
  Begin
     If PosRep(',',S)>0 Then
     Tmp:=Trim(Copy(S,1,PosRep(',',S)-1))
      else
     Tmp:=S;
     If PosRep(',',S)>0 Then
       Delete(S,1,Length(Tmp)+1);
     If Trim(Tmp)<>'' Then
     If PosRep(LowerCaseRep(Tmp),LowerCaseRep(RestOfMsg))>0 Then
         ValidText:=False;
  End;
End;

If Form10.CheckBox25.Checked=True Then
  Begin
    If SmileCount(RestOfMsg)>Form10.SpinEdit12.value Then
      ValidText:=False;
  End;


Case FilterLevel Of
  0: Begin
       If Trim(RestOfMsg)='' Then
         ValidText:=False;
    End;
  1: Begin
     If Trim(RestOfMsg)='' Then
       ValidText:=False;
     TestStr:=Copy(RestOfMsg,1,3);
     If Form1.ScanIt(TestStr,RestOfMsg)>15 Then
     ValidText:=False;
     End;
   2: Begin
      If Trim(RestOfMsg)='' Then
         ValidText:=False;
        TestStr:=Copy(RestOfMsg,1,3);
       If Form1.ScanIt(TestStr,RestOfMsg)>15 Then
         ValidText:=False;
         TestStr:=Copy(RestOfMsg,(Length(RestofMsg) div 2),3);
         If Form1.ScanIt(TestStr,RestOfMsg)>13 Then
          ValidText:=False;
      End;
    3: Begin
        If Trim(RestOfMsg)='' Then
        ValidText:=False;
        TestStr:=Copy(RestOfMsg,1,3);
        If Form1.ScanIt(TestStr,RestOfMsg)>13 Then
           ValidText:=False;
        TestStr:=Copy(RestOfMsg,(Length(RestofMsg) div 2),3);
         If Form1.ScanIt(TestStr,RestOfMsg)>13 Then
          ValidText:=False;
         TestStr:=Copy(RestOfMsg,(Length(RestofMsg)-5),3);
         If Form1.ScanIt(TestStr,RestOfMsg)>13 Then
           ValidText:=False;
           If Words.Count>0 Then
             If Form1.ScanIT(Words[0],RestOfMsg)>13 Then
               ValidText:=False;
         If MatchStr(Pchar(LastThingSaid),Pchar(RestofMsg))>Form10.SpinEdit2.Value Then
           ValidText:=False;
        End;
    4: Begin
         If Trim(RestOfMsg)='' Then
        ValidText:=False;
        TestStr:=Copy(RestOfMsg,1,4);
         If Form1.ScanIt(TestStr,RestOfMsg)>13 Then
           ValidText:=False;
        TestStr:=Copy(RestOfMsg,(Length(RestofMsg) div 2),2);
         If Form1.ScanIt(TestStr,RestOfMsg)>13 Then
          ValidText:=False;
         TestStr:=Copy(RestOfMsg,(Length(RestofMsg)-5),2);
         If Form1.ScanIt(TestStr,RestOfMsg)>13 Then
          ValidText:=False;
      For N:=1 to Length(RestOfMsg) Do
        If (Ord(RestOfMsg[N])>30) and (Ord(RestOfMsg[N])<127) Then
          Inc(Badchars)
              else
       IF (Ord(RestOfMsg[N])=163) or (Ord(RestOfMsg[N])=166) or (Ord(RestOfMsg[N])=168) or (Ord(RestOfMsg[N])=174) or (Ord(RestOfMsg[N])=$0D) or (Ord(RestOfMsg[N])=$0A) or (Ord(RestOfMsg[N])=145) or (Ord(RestOfMsg[N])=163)  or (Ord(RestOfMsg[N])=$166) or (Ord(RestOfMsg[N])=$1B) or (Ord(RestOfMsg[N])=Ord('"')) or (Ord(RestOfMsg[N])=Ord('{')) or (Ord(RestOfMsg[N])=Ord('}')) Then
        Inc(Badchars);
         //bug
       Badchars:=Length(RestOfMsg)-Badchars;
       If Badchars>5 Then
          ValidText:=False;
       If MatchStr(Pchar(LastThingSaid),Pchar(RestofMsg))>Form10.SpinEdit2.Value Then
          ValidText:=False;
{        If Words<>nil Then
         Begin
          If ScanIT(Words[0],RestOfMsg)>9 Then
           ValidText:=False;
         End;}
     End;
  End;
End;



Procedure BuddyP(S: String);
Var
 NumMsgs,FromUser,EmailAddy,Header: String;
Begin
 IF Form1.BooterAlert=True Then
   Exit;
  Form1.ScrollToEnd(Form1.Richedit1);
  Delete(S,1,20);
  S:=Co80s+S;
  FromUser:=Form1.ExtractPacketDetails(S,'3');
  If Form1.AutoRejectAddBuddy1.Checked=False Then
   { If FromUser<>'' Then
     Begin
       If MessageDlg('User '+FromUser+' Has Requested That You Should Be His or Her Buddy, Do You Accept?',MtConfirmation,[mbyes,mbno],1)=IdYes Then
       Form1.AddBuddy(LoggedinName,FromUser,'chat')
      else
       Form1.RemoveBuddy(LoggedinName,FromUser,'Chat');
    End;}
End;


Procedure MailP(S: String);
Var
 NumMsgs,FromUser,EmailAddy,Header: String;
Begin
If (Form1.BooterAlert=True) or (Form1.RejectMailInvites1.Checked=True) Then
   Exit;
  Form1.ScrollToEnd(Form1.Richedit1);
  Delete(S,1,20);
  S:=Co80s+S;
  FromUser:=Form1.ExtractPacketDetails(S,'43');
  If FromUser<>'' Then
   Begin
    EmailAddy:=Form1.ExtractPacketDetails(S,'42');
    Header:=Form1.ExtractPacketDetails(S,'18');
    NumMsgs:=Form1.ExtractPacketDetails(S,'9');
    Form1.Richedit1.SelAttributes.Style:=[FsBold,FsItalic];
    Form1.Richedit1.SelAttributes.Color:=ClRed;
    Form1.Richedit1.SelText:='Email Message From: ';
    Form1.Richedit1.SelAttributes.Color:=ClGreen;
    Form1.Richedit1.SelText:=FromUser;
    Form1.Richedit1.SelAttributes.Color:=ClBlack;
    Form1.Richedit1.SelText:=' (';
    Form1.Richedit1.SelAttributes.Color:=ClBlue;
    Form1.Richedit1.SelText:=EmailAddy;
    Form1.Richedit1.SelAttributes.Color:=ClBlack;
    Form1.Richedit1.SelText:=') ';
    Form1.Richedit1.SelAttributes.Color:=ClGreen;
    Form1.Richedit1.SelText:=' - '+Header;
    Form1.Richedit1.SelAttributes.Color:=ClRed;
    Form1.Richedit1.SelText:=' Mail Messages, '+NumMsgs;
    Form1.Richedit1.SelText:=' http://mail.yahoo.com';
    Form1.Richedit1.SelAttributes.Color:=ClBlack;
    Form1.Richedit1.Lines.Add('');
    BufferRichedit(Form1.Richedit1,0);
    Form1.ScrollToEnd(Form1.Richedit1);
  End;
End;

Procedure TForm1.DestroyPmwindow(Who: String);
Var
 N: Integer;
 Obj: TForm4;
Begin
 N:=Form1.PmWindows.IndexOf(Who);
 If N<>-1 Then
  Begin
    Obj:=TForm4(Form1.PmWindows.Objects[N]);
    Obj.Free;
    Obj:=Nil;
    Form1.PmWindows.Delete(N);
  End;
End;

Procedure TForm1.DestroyAllPmwindow;
Var
 N: Integer;
 Obj: TForm4;
Begin
 For N:=Form1.PmWindows.Count-1 downto 0 do
  Begin
    Obj:=TForm4(Form1.PmWindows.Objects[N]);
    If Obj<>Nil Then
     Begin
      Obj.Free;
      Obj:=Nil;
     End;
   End;
End;

Function Tform1.GetPmWindow(Who: String): TForm4;
Var
 N: Integer;
Begin
 Result:=Nil;
 If Form1.PmWindows.IndexOf(Who)=-1 Then
  Begin
   Result:=Tform4.Create(Nil);
   Form1.PmWindows.AddObject(Who,Result);
   SendMessage(Result.Richedit1.Handle, EM_AUTOURLDETECT, Longint(True), 0);
   Result.spSkinCheckComboBox1.Text:=Who;
   Result.Caption:='IM - '+Who;
   Result.spSkinCheckComboBox2.Text:=LoggedinName;
   Result.ToUser:=Who;
   Result.Visible:=True;
   Result.BoldP.Checked:=Form1.BoldP.Checked;
   Result.ItalicP.Checked:=Form1.ItalicP.Checked;
   Result.UnderlineP.Checked:=Form1.UnderlineP.Checked;
   Result.spSkinCheckRadioBox1.Checked:=Form1.spSkinCheckRadioBox1.Checked;
   FlashWindow(Result.Handle,True);
   Result.RichEdit2.SetFocus;
  End
   else
  Begin
    N:=Form1.PmWindows.IndexOf(Who);
    Result:=Tform4(Form1.PmWindows.Objects[N]);
    FlashWindow(Result.Handle,True);
    Result.Visible:=True;
//    Result.Show;
   // Result.MyRichEdit2.SetFocus;
  End;
End;


Procedure Tform1.LoginToRoom2;
Begin
 If InChat=False Then
  Begin
//     Timer7.Enabled:=True;
     If Form2.spSkinCheckRadioBox1.Checked=True Then
        Exit;
     RoomJoinWait:=False;
     RoomAckWait:=True;
     Form1.Timer7.Enabled:=True;
     Form1.Richedit1.SelText:='Room Ack Sent.....Waiting for Acknowledgment';
     Form1.SendText(RoomAck(LoggedInName,GpRoomName)); //marker1
  End
   else
  Begin

  End;
End;


Procedure LoginP2(S: String);
Var
 Tmp,Tmp2: String;
 BuddyCount,YourID,Buddy,UserOnline,ToWho: String;
 OwnBuddieCount: Integer;
 Code: String;
 Obj: TObject;
Begin
 Delete(S,1,20);
 S:=Co80s+S;
 Tmp:=S;
 YourID:=Form1.ExtractPacketDetails(Tmp,'0');
 BuddyCount:=Form1.ExtractPacketDetails(Tmp,'318');
 OwnBuddieCount:=Form1.ScanIt('À€319À€7À€',S);
// OnlineFriends.Clear;
//7 is all friends..    //friends not ONLINE ONES!
While Form1.ScanIt(co80s+'7',Tmp)>0 Do
 Begin
  Tmp2:=Form1.ExtractBlockPacketDetails(Tmp,'300','301');
  Delete(Tmp,1,PosRep(Tmp2,Tmp)+Length(Tmp2)+4);
  Buddy:=Form1.ExtractPacketDetails(Tmp2,'7');
  If Trim(Buddy)<>'' Then
   If Friends.Find(Buddy,Obj)=False Then
     Friends.Add(LowerCase(Buddy),Obj);
 End;    
End;


Procedure BuddyOnlineP(S: String);
Var
 Tmp,Tmp2: String;
 BuddyCount,YourID,Buddy,UserOnline,ToWho: String;
 OwnBuddieCount: Integer;
 Code: String;
Begin
 Delete(S,1,20);
 S:=Co80s+S;
 Tmp:=S;
 While Form1.ScanIt(co80s+'7',Tmp)>0 Do
 Begin
  Tmp2:=Form1.ExtractBlockPacketDetails(Tmp,'300','302');
  Delete(Tmp,1,PosRep(Tmp2,Tmp)+Length(Tmp2)+4);
  Buddy:=Form1.ExtractPacketDetails(Tmp2,'7');
  If Trim(Buddy)<>'' Then
   If OnLineFriends.IndexOf(Buddy)=-1 Then
     Begin
      OnLineFriends.Add(Buddy);
      Form12.ListBox1.Items.Add(Buddy);
      Form1.Panel10.Caption:=Buddy+' Is online';
      Form1.Richedit1.SelAttributes.Color:=ClBlue;
      Form1.Richedit1.Seltext:='*Yahoo Status Message - ';
      Form1.Richedit1.SelAttributes.Color:=ClGReen;
      Form1.Richedit1.Seltext:=Buddy+' Is online';
      Form1.Richedit1.SelAttributes.Color:=ClBlack;
      Form1.ScrollToEnd(Form1.Richedit1);
      Form1.Richedit1.Lines.Add('');
     End;
 End;

End;

Procedure BuddyOfflineP(S: String);
Var
 Tmp,Tmp2: String;
 BuddyCount,YourID,Buddy,UserOnline,ToWho: String;
 OwnBuddieCount: Integer;
 Code: String;
Begin
 Delete(S,1,20);
 S:=Co80s+S;
 Tmp:=S;
 Buddy:=Form1.ExtractPacketDetails(Tmp2,'7');
 If OnLineFriends.IndexOf(Buddy)=-1 Then
  Begin
   OnLineFriends.Add(Buddy);
   Form12.ListBox1.Items.Add(Buddy);
   Form1.Panel10.Caption:=Buddy+' Has just come online';
  End;
End;


Procedure OffLineP2(S: String);
Var
  Tmp: String;
  Code,UserOffLine: String;
Begin
    Tmp:=S;
    Delete(Tmp,1,20);
    Tmp:=Co80s+Tmp;
    UserOffLine:=Form1.ExtractPacketDetails(Tmp,'7');
    If OnLineFriends.IndexOf(UserOffLine)<>-1 Then
      Begin
        Form12.ListBox1.Items.Delete(Form12.ListBox1.Items.IndexOf(UserOffLine));
        OnLineFriends.Delete(OnLineFriends.IndexOf(UserOffLine));
        Form1.Richedit1.SelAttributes.Color:=ClBlue;
        Form1.Richedit1.Seltext:='*Yahoo Status Message - ';
        Form1.Richedit1.SelAttributes.Color:=ClRed;
        Form1.Richedit1.Seltext:=UserOffline+' has just gone offline.';
        Form1.Richedit1.SelAttributes.Color:=ClBlack;
        Form1.Richedit1.Lines.Add('');
        Form1.ScrollToEnd(Form1.Richedit1);
      End;
//    Form1.Panel10.Font.Color:=ColSelect.AlertColor;
    Form1.Panel10.Caption:='Messenger buddy: '+UserOffLine+' has just gone offline in Messenger';
//    RichCont.Lines.Add('User '+UserOffLine+' Now Offline');
End;

Procedure BuddyListP2(S: String);
Var
  Tmp2,Friend,Tmp,Code,Code2,RoomName: String;
  N: Integer;
  Uf: TUserFields2;
  Obj: Tobject;
Begin
//If PosRep('domain',LowerCaseRep(S))>0 Then
  //   S:='';
 Uf:=TUserFields2.Create;
 Uf.SplitFields(S);
{ ToUser:=Uf.GetField('5'); //Form1.ToC080(Tmp2); //Form1.ExtractPacketDetails(Tmp2,'5');
 FromWho:=Uf.GetField('4');
 Msg:=Uf.GetField('14');
 AwayState:=Uf.GetField('10');}
 SmileyPic:=0;
 Tmp:=S;
// Tmp:=Co80s+Tmp;
  If (Form1.ExtractPacketDetails(S,'59')<>'') Then
   Begin
    Cookie:=Uf.GetField('59');
    Delete(Cookie,1,Pos(#9,Cookie));
    Cookie:=Trim(Copy(Cookie,1,PosRep('expires',Cookie)-1));
    Tmp2:=Trim(Uf.GetField('59'));
    Delete(Tmp2,1,Pos(#9,Tmp2));
    Cookie:=Cookie+' '+Trim(Copy(Tmp2,1,PosRep('expires',Tmp2)-1));
    Cookie:=Cookie+' '+Trim(Uf.GetField('59'));
    Uf.Free;
   End;
 Tmp:=S;
 Delete(Tmp,1,20);   
 //getroomlist;
 Form27.ListBox1.Clear;
 Delete(S,1,20);
 S:=CO80S+S;
 S:=Form1.ExtractPacketDetails(S,'87');
 Delete(S,1,PosRep(':',LowerCaseRep(S)));
 Tmp:=S;
 If PosRep(#$0a,Tmp)>0 Then
   Tmp:=Form1.ReplaceFromToStr(Tmp,#$0a,':',',');
 While Form1.ScanIt(',',Tmp)>0 DO
  Begin
   Friend:=Copy(Tmp,1,PosRep(',',tmp)-1);
   Delete(Tmp,1,PosRep(',',Tmp));
   If Trim(Friend)<>'' Then
    Begin
     If Friends.Find(Friend,Obj)=False Then
       Begin
        Friends.Add(Friend,Obj);
//        Form27.ListBox1.Items.Add(Friend);
       End;
   End;
 End;
 //  Form27.ListBox1.Items.Text:=Friends.Text;
End;

Function IsUserIgnored(UserName: String): Boolean;
Var
 Obj: TObject;
Begin
 Result:=Ignored.Find(LowerCaseRep(UserName),Obj);
End;


Procedure WebCamP(S: String);
Var
  TmpKey,Tmp,FromWho,Token: String;
Begin
Delete(S,1,20);
S:=Co80s+S;
Tmp:=S;
 FromWho:=Form1.ExtractPacketDetails(S,'5');
 Token:=Form1.ExtractPacketDetails(S,'61');
 Form38.Edit3.Text:=Token;
End;

Procedure InviteP2(S: String);
Var
  WantedRoom,FromWho,RoomName2,Nick,ToWho,FromUser,RoomCat,TmpKey,Tmp,Code,Code2,Code3,Description: String;
Begin
IF Form1.BooterAlert=True Then
  Exit;
Delete(S,1,20);
S:=Co80s+S;
Tmp:=S;
FromWho:=Form1.ExtractPacketDetails(S,'119');
If FromWho='' Then
  Exit;
IF IsUserIgnored(FromWho)=True Then
   Exit;
RoomName2:=Form1.ExtractPacketDetails(S,'104');
RoomCat:=Form1.ExtractPacketDetails(S,'129');
ToWho:=Form1.ExtractPacketDetails(S,'118');
Nick:=Form1.ExtractPacketDetails(S,'141');
Description:=Form1.ExtractPacketDetails(S,'117');


 If FromWho=LoggedInName Then
   Begin
    If Description='Lag Time.' Then
     Begin
       Form1.Say(Form1.Richedit1,yRed+'The Lag Time '+YBlack+'Is '+IntTOStr(SecondsBetween(Form1.CLagTime,Now))+' Seconds.',False,True,False);
       BufferRichedit(Form1.Richedit1,0);
       Form1.ScrollToEnd(Form1.Richedit1);
     End;
    Exit;
   End;


   If Copy(Description,1,12)='Goto Request' Then
      Begin
       Form1.Panel10.Caption:=FromWho+': is attempting a /goto (follow) you. Right mouse click to ignore this person to stop them trying again. ';
       AddBlockMessage(Form1.Panel10.Caption);
       If Form10.GotoBox.Checked=True Then
         If Form1.IsBuddy(FromWho)=False Then
            Exit;
        Tmp:=Description;
        Delete(Tmp,1,13);
        If Tmp<>'' Then
         Begin
          Form1.InviteKey:=Tmp;
          Form1.Invite(FromWho,False,False,True);
         End;
          Exit;
       End;

      If Copy(Description,1,13)='Goto Accepted' Then
      Begin
       If Form10.GotoBox.Checked=True Then
         If Form1.IsBuddy(FromWho)=False Then
            Exit;
        Tmp:=Description;
        Delete(Tmp,1,14);
        If PosRep(':',Tmp)>0 Then
         Begin
          TmpKey:=Copy(Tmp,1,PosRep(':',Tmp)-1);
          Delete(Tmp,1,PosRep(':',Tmp));
          Wantedroom:=Tmp; //Room with Cat if Needed!
          Tmp:=TmpKey;
         End;
        If Tmp=Form1.InviteKey Then
         Begin
          Form1.InviteKey:='####';
          Form1.SendText(Form1.JoinRoom(Loggedinname,RoomName2+'::'+RoomCat));
         End;
         Exit;
       End;

  If Form10.CheckBox20.Checked=True Then
   Begin
 //    Form1.Panel10.Font.Color:=ColSelect.AlertColor;
    Form1.Panel10.Caption:='Room Invite Deflected, User '+FromWho+' Invited to: '+GpRoomName+' Instead!';
    Form1.Invite(FromWho,False,False,False)
   End
 Else
  Begin
//   Form1.Panel10.Font.Color:=ColSelect.AlertColor;
   Form1.Panel10.Caption:='Invited to join '+RoomName2+' By '+FromWho+' Description: '+Description+' To Join Press F11';
   InviteRoom:=RoomName2;
  End;

End;


Procedure PmP2(S: String);
Var
  Code,Code2,FromWho,ToUser,Msg,Tmp: String;
  MadeIt,NotSaidBefore,FadeRoutine: Boolean;
  AwayState,Tmp2,LM,Stars,Url,Msg3,Msg2,Msg4: String;
  N2,N: integer;
  FNs,XferBytes,XferHost,XferFileName: String;
  PlainText,MyIp,UserN2,TStamp,ChatClient: String;
  TF: TextFile;
  Obj: Tform4;
  Uf: TUserFields2;
  FullStr: String;
  Obj2: Tobject;
Begin
 If (Form1.BooterAlert=True) or (Form1.BooterAlert=True) Then
    Exit;

 MadeIt:=False;
 Form1.Richedit1.SelStart:=-1;
 Code:=S[20];
 Tmp:=S;
 Delete(S,1,20); //20

 Uf:=TUserFields2.Create;
 Uf.SplitFields(S);
 ToUser:=Uf.GetField('5'); //Form1.ToC080(Tmp2); //Form1.ExtractPacketDetails(Tmp2,'5');
 FromWho:=Uf.GetField('4');
 Msg:=Uf.GetField('14');
 AwayState:=Uf.GetField('10');
 Uf.Free;

 If Trim(FromWho)='' Then
   Exit;

 if IsUserPmIgnored(FromWho)=True Then
   Exit;

IF IsUserIgnored(FromWho)=True Then
   Exit;

 PlainText:=Form1.Remove(Msg,'<','>');
 PlainText:=Form1.Remove(PlainText,#$1B,'m');

 If (Msg=PingRes) and (LowerCaseRep(FromWho)=LowerCaseRep(LoggedInName)) Then
 Begin
  If Msg=PingRes Then
   Begin
     Form1.Say(Form1.Richedit1,'Ping Time is: '+FloatToStr((GetTickCount-PingT)/1000)+' Seconds',False,False,False);
     Exit;
   End;
 end;

  If Form10.CheckBox23.Checked=True Then
    Form1.WriteLogData(Fromwho,ToUser,PlainText,False);



 If Form10.CheckBox17.Checked=False Then
   Exit;

  If Form10.CheckBox41.Checked=True Then
   If (RoomTime<6) And (Form1.InChat=True) Then
    Begin
     Form1.Panel10.Caption:='PM From '+FromWho+' '+Copy(Msg,1,15)+'..'+' Blocked (Pmed within 5 seconds of joining a room)';
     AddBlockMessage(Form1.Panel10.Caption);
     Exit;
    End;


  If Form10.CheckBox16.Checked=True Then
     If Friends.Find(FromWho,Obj2)=False Then
      Begin
        Form1.Panel10.Caption:='Blocked PM '+FromWho+': '+PlainText+' (Pm From Buddies Only [PmSettings])';
        AddBlockMessage(Form1.Panel10.Caption);
        Exit;
      End;

    If Form1.PmWindows.IndexOf(FromWho)=-1 Then
     If PmCounter<StrToInt(Form10.Edit8.Text) Then
       Begin
        Form1.Panel10.Caption:='Blocked PM ('+Form10.Edit8.Text+' Seconds Must Pass Before New PM Window) '+FromWho+': '+PlainText;
        AddBlockMessage(Form1.Panel10.Caption);
        Exit;
       End;

If ValidText(PlainText,FromWho)=True Then
  begin
   Form1.RtfPatch(Msg);
   Obj:=Form1.GetPmWindow(FromWho);
   Obj.Funcs.Packet(Msg,Obj.SpSkinCheckComboBox1.Text,True,Form10.ColorBox2.ColorValue,Obj.Richedit1,False,False,True);
   Obj.Funcs.ScrollToEnd(Obj.Richedit1);
   Obj.LastPmMessage:=PlainText;
   FlashWindow(obj.Handle,True);
  End
   else
  Begin
    Form1.Panel10.Caption:='PM From '+FromWho+' '+PlainText+' Blocked';
    AddBlockMessage(Form1.Panel10.Caption);
    Exit;
  End;
  Application.ProcessMessages;
End;


Procedure Tform1.RemoveBuddy(UserName,BuddyName,SubHead: String);
Var
  Payload,Tmp: String;
  ActLen: Integer;
Begin
 Payload:='1'+#$C0+#$80+UserName+#$C0+#$80+'7'+#$C0+#$80+buddyname+#$C0+#$80+'65'+#$c0+#$80+Subhead+#$c0+#$80;
 ActLen:=Length(PayLoad);
 Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(ActLen)+#$0+#$84+#$0+#$0+#$0+#$0+Key;
 Tmp:=Tmp+PayLoad;
 Form1.SendText(Tmp);
 Payload:='1'+#$C0+#$80+UserName+#$C0+#$80;
 ActLen:=Length(PayLoad);
 Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(ActLen)+#$0+#$55+#$0+#$0+#$0+#$0+Key;
 Tmp:=Tmp+PayLoad;
 Form1.SendText(Tmp);
End;

Procedure Tform1.AddBuddy(UserName,BuddyName,Subhead: String);
Var
  Payload,Tmp: String;
  ActLen: Integer;
Begin
 Payload:='1'+#$C0+#$80+UserName+#$C0+#$80+'7'+#$C0+#$80+buddyname+#$C0+#$80+'14'+#$C0+#$80+#$c0+#$80+'65'+#$c0+#$80+Subhead+#$c0+#$80;
 ActLen:=Length(PayLoad);
 Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(ActLen)+#$0+#$83+#$0+#$0+#$0+#$0+Key;
 Tmp:=Tmp+PayLoad;
 Form1.SendText(Tmp);
 Payload:='1'+#$C0+#$80+UserName+#$C0+#$80;
 ActLen:=Length(PayLoad);
 Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(ActLen)+#$0+#$12+#$0+#$0+#$0+#$0+Key;
 Tmp:=Tmp+PayLoad;
 Form1.SendText(Tmp);
End;


{Procedure BuddyP2(S: String);
Var
 NumMsgs,FromUser,EmailAddy,Header: String;
Begin
 If Form1.InChat=False Then
   Form1.LoginToRoom2;

If Form1.BooterAlert=True Then
  Exit;
  Form1.ScrollToEnd(Form1.Richedit1);
  Delete(S,1,20);
  S:=Co80s+S;
  FromUser:=Form1.ExtractPacketDetails(S,'3');
  If Form1.AutoRejectAddBuddy1.Checked=False Then
    If FromUser<>'' Then
     Begin
       Form1.Richedit1.Lines.Add('Menu > Format > Filters > Auto Reject Add Buddy, allows you to turn the popup request off');
       If MessageDlg('User '+FromUser+' Has Requested That You Should Be His or Her Buddy, Do You Accept?',MtConfirmation,[mbyes,mbno],1)=IdYes Then
         Form1.AddBuddy(LoggedinName,FromUser,'chat')
          else
         Form1.RemoveBuddy(LoggedinName,FromUser,'Chat');
     BufferRichedit(Form1.Richedit1,0);
     Form1.ScrollToEnd(Form1.Richedit1);
    End;
End;}

Procedure GotoP2(S: String);
Var
  SaveStr,Tmp,Code,Code2,RoomName: String;
Begin
 Form1.Richedit1.SelStart:=-1;
 Code:=Copy(s,21,3);
 Tmp:=S;
 Delete(S,1,25);
 RoomName:=Copy(S,1,PosRep(Chr($c0)+Chr($80),S)-1);
 Delete(S,1,PosRep(Chr($c0)+Chr($80),S)+1);
 Code2:=Copy(S,1,PosRep(#$C0,S)-1);
 Delete(S,1,Length(code2)+2);
 If Copy(S,1,2)='11' Then
  Form1.Richedit1.Lines.Add('User Is Not Online....');
 SaveStr:=S;
 BufferRichedit(Form1.Richedit1,0);
 Form1.ScrollToEnd(Form1.Richedit1);

End;


//YMSG END BLOCK



function GetTxt(text: String; from,too: String): String;
var
 P1,P2: Integer;
 tmp,Tmp2: String;
Begin
  Tmp2:='';
  Tmp:=Text;
  P1:=PosRep(From,Tmp);
  P2:=PosRep(Too,Tmp);
  If (P1>0) and (P2>0) Then
   Begin
    Tmp2:=Copy(Tmp,P1,P2-P1);
   End;
 Result:=Tmp2;
End;

Procedure SaveChatText;
Begin
 Form1.SaveDialog1.Execute;
 Form1.Richedit1.Lines.SaveToFile(Form1.SaveDialog1.filename);
End;

Procedure TForm1.SaveIniConfig;
Var
 IniFile: TFastiniFile;
 N: Integer;
 Chk: Boolean;
Begin
  IniFile:=TFastiniFile.Create(Path+'config.ini');
  IniFile.WriteBool('Settings','protocol',Form2.RadioButton1.Checked);
//   If Form1.Panel19.Height<1 Then Form1.Panel19.Height:=1;
  //
//   iniFile.WriteBool('Sparta','Enabled',Form2.SpSkinCheckRadioBox3.Checked);
//   IniFile.WriteBool('Mail','CheckMail',Form48.checkBox1.Checked);
   IniFile.WriteBool('Settings','Logging',Form10.CheckBox23.Checked);
   IniFile.WriteBool('Settings','TimeStamping',Form10.CheckBox28.Checked);
//   IniFile.WriteBool('Settings','AntiBooter',Form2.BootResistant1.Checked);
//   IniFile.WriteString('Settings','username2',Form2.SpSkinEdit1.text);
//   IniFile.WriteString('Settings','password2',Form1.CryptPassword(Form2.SpSkinPasswordEdit2.text,10));
//   IniFile.WriteBool('Settings','YaheliteTrick',Form1.YaheliteMemoryTrick1.Checked);
   IniFile.WriteDateTime('Settings','LastIgnored',Form1.LastIgnoreD);
//   IniFile.WriteBool('Layout','Auth1',Form2.spSkinCheckRadioBox1.Checked);
//   IniFile.WriteReal('Settings','BandwithSpeed',Form1.MaxDownloadSpeed);
//   IniFile.WriteBool('Layout','Auth2',Form2.spSkinCheckRadioBox2.Checked);
   IniFile.WriteBool('Settings','Description',Form10.CheckBox43.Checked);
   IniFile.WriteInteger('Settings','TimeTyping_',ActualTimeTyping);
   IniFile.WriteDateTime('Settings','TimeLoggedTyping',TimeLoggedTyping);
   IniFile.WriteBool('Settings','FancyInterface',FancyMenuInterface1.Checked);
//   IniFile.WriteBool('Settings','Animation',Form1.EnableAnimations1.Checked);
 //   Inifile.WriteString('Sparta','Username',Form2.SpSkinEdit1.text);
   IniFile.WriteString('Mp3Path','Path',Form1.LastPath);
//   IniFile.WriteString('Sparta','Password',Form2.spSkinPasswordEdit1.Text);
{    DfsToolBar1.Visible:=IniFile.ReadBool('Visible','dfstoolbar',False);
  SpSkinControlBar1.Visible:=IniFile.ReadBool('Visible','SpSkinControlBar1',False);
  SpSkinControlBar2.Visible:=IniFile.ReadBool('Visible','SpSkinControlBar2',False);
  SpSkinControlBar3.Visible:=IniFile.ReadBool('Visible','SpSkinControlBar3',True);
  SpSkinMainMenuBar1.Visible:=IniFile.ReadBool('Visible','SpSkinMainMenuBar1',False);
  SpSkinExPanel1.Visible:=IniFile.ReadBool('Visible','SpSkinExPanel1',True);
  SpSkinExPanel2.Visible:=IniFile.ReadBool('Visible','SpSkinExPanel2',True);
  SpSkinExPanel3.Visible:=IniFile.ReadBool('Visible','SpSkinExPanel3',True);
  SpSkinExPanel4.Visible:=IniFile.ReadBool('Visible','SpSkinExPanel4',True);
  SpSkinExPanel5.Visible:=IniFile.ReadBool('Visible','SpSkinExPanel5',True);}
//  IniFile.WriteBool('Eye','EyeEnabled',Form2.EyeCheckBox.Checked);
//  IniFile.WriteBool('Settings','Bump',Form2.BumpingCheckbox.Checked);
//  IniFile.WriteString('Eye','Username',Form2.SpSkinEdit1.Text);
//  IniFile.WriteString('Eye','Password',Form2.SpSkinPasswordEdit1.Text);
  IniFile.WriteBool('Layout','5SecondRule',Form10.CheckBox41.Checked);
  IniFile.WriteBool('Colors','YFadeID',Form10.CheckBox35.Checked);
  IniFile.WriteInteger('Colors','InputBox',Form10.ColorPickCombo6.ColorValue);
  IniFile.WriteBool('Colors','TFadeID',Form10.CheckBox40.Checked);
  IniFile.WriteBool('SpellChecker','SpellCheck',Form1.SpellChecker1.Checked);
  IniFile.WriteBool('Visible','DfsToolBar1',SpSkinPanel2.Visible);
  IniFile.WriteBool('Visible','SpSkinControlBar1',SpSkinControlBar1.Visible);
  SpSkinControlBar2.Visible:=True;
//  IniFile.WriteBool('Visible','SpSkinControlBar2',SpSkinControlBar2.Visible);
//  IniFile.WriteBool('Visible','SpSkinControlBar3',SpSkinControlBar3.Visible);
  IniFile.WriteBool('Visible','Mp3Bar',Panel1.Visible);
  IniFile.WriteBool('Visible','SpSkinMainMenuBar1',SpSkinMainMenuBar1.Visible);
  IniFile.WriteBool('Visible','SpSkinExPanel1',SpSkinExPanel1.Visible);
  IniFile.WriteBool('Visible','SpSkinExPanel2',SpSkinExPanel2.Visible);
  IniFile.WriteBool('Visible','SpSkinExPanel3',SpSkinExPanel3.Visible);
  IniFile.WriteBool('Visible','SpSkinExPanel4',SpSkinExPanel4.Visible);
//  IniFile.WriteBool('Visible','SpSkinExPanel5',SpSkinExPanel5.Visible);
  IniFile.WriteBool('Visible','SpSkinScrollPanel1',SpSkinScrollPanel1.Visible);
  IniFile.WriteBool('Settings','MailNotifications',RejectMailInvites1.Checked);
  IniFile.WriteBool('Visible','panel3',panel3.Visible);
//  IniFile.WriteString('Settings','PMBossMode',Form10.Edit14.Text);
  //panel3
//   SpSkinScrollPanel1.Visible:=IniFile.ReadBool('Visible','SpSkinScrollPanel1',True);
   //   IniFile.WriteString('Settings','Pm
  //
//  IniFile.WriteInteger('Settings','AlphaVal',Form10.TrackBar1.Position);
//  INiFile.WriteBool('Settings','CheckBox28',Form10.CheckBox28.Checked);
  IniFile.WriteInteger('Settings','PCount',TClickCount);
//  IniFile.WriteInteger('Settings','Panel8',Form1.Panel8.Height);
  IniFile.WriteBool('Settings','AliciaBot',Form10.CheckBox46.Checked);
  IniFile.WriteBool('Settings','GirlyFilter',Form1.GirlyFilter1.Checked);
  IniFile.WriteString('Settings','skinname',SkinName);
  IniFile.WriteInteger('Settings','ScreenWidth',Form1.Width);
  IniFile.WriteInteger('Settings','ScreenHeight',Form1.Height);
  IniFile.WriteBool('Settings','httpdownloader',HttpFileDownloader1.Checked);
//  Inifile.WriteBool('Settings','GoogleAds',Form10.CheckBox35.Checked);
//  IniFile.WriteString('Settings','PmRejectMsg',Form10.Edit9.Text);
//  IniFile.WriteString('Settings','PmRejectDisabledMsg',Form10.Edit10.Text);
//  IniFile.WriteString('Settings','VoiceNick',Form10.Edit15.Text);
  IniFile.WriteBool('Alerts','GraphicalAva',Form10.CheckBox42.Checked);
  IniFile.WriteBool('Settings','LoveRoomBots',Form10.CheckBox36.Checked);
  IniFile.WriteBool('Settings','CheckBox37',Form10.CheckBox37.Checked);
//  IniFile.WriteBool('Settings','CheckBox38',Form10.CheckBox38.Checked);
//  IniFile.WriteBool('Settings','CheckBox39',Form10.CheckBox39.Checked);

//  Form53.CheckBox1.Checked:=IniFile.ReadBool('Settings','wallpaper',False);
  IniFile.WriteBool('Settings','Wallpaper',Form53.checkbox1.Checked);
  IniFile.WriteString('Settings','WallpaperImage',Form53.FileImage);

  IniFile.WriteBool('Settings','aa1BotFilter',Form10.aa1BotFilter.Checked);
  IniFile.WriteBool('Settings','YMSG',Form2.RadioButton1.Checked);
  IniFile.WriteDateTime('Settings','LastMerge',LastMerge);
//  IniFile.WriteBool('Settings','Maximized',Form1.ScreenMaximized);
   IniFile.WriteInteger('Settings','formtop',Form1.top);
   IniFile.WriteInteger('Settings','formleft',Form1.Left);

   If Form1.Panel3.Align=AlTop Then
    IniFile.WriteInteger('Alignment','Panel3',1)
     else
    IniFile.WriteInteger('Alignment','Panel3',0);

  If Form1.spSkinControlBar1.Align=AlTop Then
    IniFile.WriteString('Settings','ControlBar1','Top');
  If Form1.spSkinControlBar1.Align=AlBottom Then
    IniFile.WriteString('Settings','ControlBar1','Bottom');

  If Form1.SpSkinScrollPAnel1.Align=AlRight Then
    IniFile.WriteString('Settings','UserListPanelAllign','Right')
     else
    IniFile.WriteString('Settings','UserListPanelAllign','Left');


  If Form1.spSkinControlBar2.Align=AlTop Then
    IniFile.WriteString('Settings','ControlBar2','Top');
  If Form1.spSkinControlBar2.Align=AlBottom Then
    IniFile.WriteString('Settings','ControlBar2','Bottom');

  If Form1.SpSkinPanel2.Align=AlTop Then
    IniFile.WriteString('Layout','SpSkinPanel2','Top');
  If Form1.SpSkinPanel2.Align=AlBottom Then
    IniFile.WriteString('Layout','SpSkinPanel2','Bottom');


//  IniFile.WriteString('Settings','PmGender',Form10.ComboBox2.Text);
  IniFile.WriteBool('Settings','CheckBox31',Form10.CheckBox31.Checked);
  IniFile.WriteBool('Settings','CheckBox32',Form10.CheckBox32.Checked);
//  IniFile.WriteBool('Settings','StayOnTop',Form1.StayOnTop1.Checked);
  IniFile.WriteString('Settings','AlphaImage',Form10.Edit13.Text);
  IniFile.WriteInteger('Settings','AlphaBlend',Form10.SpinEdit13.Value);

//  IniFile.WriteBool('Settings','WantSprt.8',True);


  IniFile.WriteBool('Settings','DoubleClickPM',Form10.CheckBox18.Checked);
  IniFile.WriteBool('Settings','InvertCheckBox19',Form10.CheckBox19.Checked);
  IniFile.WriteBool('Settings','CheckBox30',Form10.CheckBox30.Checked);
  IniFile.WriteInteger('Settings','TotalTime',TotalTime);
  IniFile.WriteBool('Settings','CloneEnterLeaveFilter',Form10.CheckBox27.Checked);
  IniFile.WriteBool('Settings','HiddenTextFilter',Form10.HiddenTextBot.Checked);  
//  IniFile.WriteBool('Settings','AutoAllowFriendsAccess',Form1.AutoAllowFriendsAccess1.Checked);
//  IniFile.WriteBool('Settings','AutoCookie',Form2.CheckBox4.Checked);
  IniFile.WriteBool('Settings','ClientIgnore',Form10.CheckBox24.Checked);
  IniFile.WriteString('Settings','ClientIgnoreList',Form10.Edit11.Text);
  IniFile.WriteInteger('Settings','BuddyColour',Form10.ColorBox4.ColorValue);
//  IniFile.WriteInteger('Settings','YchtStart',Form10.ColorPickCombo9.ColorValue);
//  IniFile.WriteInteger('Settings','YchtEnd',Form10.ColorPickCombo10.ColorValue);
  IniFile.WriteInteger('Settings','ColFadeS',Form10.ColorPickCombo11.ColorValue);
//  IniFile.WriteInteger('Settings','ColFadeE',Form10.ColorPickCombo12.ColorValue);

  IniFile.WriteInteger('Settings','ListBoxFadeS',Form10.ColorPickCombo10.ColorValue);
  IniFile.WriteInteger('Settings','ListBoxFadeE',Form10.ColorPickCombo9.ColorValue);

{   Form10.ColorPickCombo10.ColorValue:=IniFile.ReadInteger('Settings','ListBoxFadeS',ClLightBlue);
  Form10.ColorPickCombo9.ColorValue:=IniFile.ReadInteger('Settings','ListBoxFadeE',ClLightPink);}





  //ColorBoxes!
  IniFile.WriteInteger('Settings','MaleColor',Form10.ColorPickCombo1.ColorValue);
  IniFile.WriteInteger('Settings','FemaleColor',Form10.ColorPickCombo2.ColorValue);
  IniFile.WriteInteger('Settings','MaleCam',Form10.ColorPickCombo3.ColorValue);
  IniFile.WriteInteger('Settings','FemaleCam',Form10.ColorPickCombo4.ColorValue);
  IniFile.WriteInteger('Settings','BackChatterColor',Form10.ColorPickCombo5.ColorValue);
//  INiFile.WriteBool('Settings','AntiBooterID',Form2.spSkinCheckRadioBox3.Checked);
  //
  IniFile.WriteFloat('Settings','CrashBurnLevel',CrashBurnLevel);
  IniFile.WriteString('Settings','PmWindowtime',Form10.Edit8.Text);
  IniFile.WriteBool('Settings','FlashWindow',Form1.FlashWindowOnID1.Checked);
  IniFile.WriteInteger('Settings','UserListPanel',Form1.SpSkinScrollPAnel1.Width);
  IniFile.WriteInteger('Settings','VideoPanel',Form1.Panel1.Width);
  IniFile.WriteInteger('Settings','Panel5h',Form1.Panel5.Height);
  IniFile.WriteBool('Settings','SPRTMODE',Form2.RadioButton4.Checked);
  IniFile.WriteString('Settings','LastServerCmb',Form8.ServComboBox.Text);
  IniFile.WriteBool('Settings','AutoCheckForNewBuild',Form13.CheckBox1.Checked);
//  IniFile.WriteBool('Settings','AutoIncCounter',Form13.CheckBox3.Checked);
  IniFile.WriteBool('Settings','AutoCheckSmileys',Form13.CheckBox2.Checked);
  IniFile.WriteString('Settings','SendSpeed',Form10.Edit7.text);
  IniFile.WriteString('Settings','KnockSpeed',Form10.Edit12.text);
//  IniFile.WriteBool('Settings','StripFontTags',Form1.StripFontTags1.Checked);
  IniFile.WriteBool('Settings','ProcessGamesMessages1',ProcessGamesMessages1.Checked);
  IniFile.WriteBool('Settings','GotoCommand',Form10.GotoBox.Checked);
//  IniFile.WriteBool('Settings','Mosaic',Form1.Image1.Mosaic);
//  IniFile.WriteBool('Settings','Stretch',Form1.Image1.Stretch);
//  IniFile.WriteBool('Settings','Center',Form1.Image1.Center);
  IniFile.WriteString('Settings','PictureF',Picture);
//  IniFile.WriteBool('Settings','DebugWindow',DebugConsoleWindow1.Checked);
  IniFile.WriteString('Settings','CustomAway',Form28.Memo1.text);
//  IniFile.WriteString('Docking','Parent',Form1.ToolBar1.Parent.Name);
//  IniFile.WriteInteger('Docking','ToolBar1L',Form1.ToolBar1.Left);
//  IniFile.WriteInteger('Docking','ToolBar2L',Form1.ToolBar2.Left);
//  IniFile.WriteInteger('Docking','ToolBar3L',Form1.ToolBar3.Left);
//  IniFile.WriteInteger('Docking','ToolBar4L',Form1.ToolBar4.Left);
  IniFile.WriteInteger('Settings','ReconnectT',Form10.SpinEdit3.Value);
  IniFile.WriteInteger('Settings','EmSettings',EmZoom);
//    Form16.checkBox1.Checked:=IniFile.ReadBool('ShoutBox','SavePassword',True);
{  IniFile.WriteInteger('Docking','ToolBar1T',Form1.ToolBar1.Top);
  IniFile.WriteInteger('Docking','ToolBar2T',Form1.ToolBar2.Top);
  IniFile.WriteInteger('Docking','ToolBar3T',Form1.ToolBar3.Top);
  IniFile.WriteInteger('Docking','ToolBar4T',Form1.ToolBar4.Top);}
//  IniFile.WriteString('Docking','Parent',ToolBar1.Parent.ClassName);
//  IniFile.WriteInteger('Settings','Panel19',Form1.Panel19.Height);
//  IniFile.WriteInteger('Settings','Panel5',Form1.Panel5.Height);
//   If Form1.Panel3.Height<1 Then Form1.Panel3.Height:=1;
//  IniFile.WriteInteger('Settings','Panel3',Form1.Panel3.Height);
  IniFile.WriteInteger('Settings','MainPanelHeight',MainPanel.Height);
//  IniFile.WriteInteger('Settings','Splitter2T',Form1.Splitter2.Top);
  IniFile.WriteBool('Settings','FirstPostURLIgnore',Form10.CheckBox14.Checked);
  IniFile.WriteBool('Settings','CloneScan',Form10.CheckBox12.Checked);
  IniFile.WriteBool('Settings','AutoSave',Form10.CheckBox9.Checked);
  IniFile.WriteBool('Settings','SpamIgnore',Form10.CheckBox11.Checked);
  IniFile.WriteBool('Settings','UserIDIgnore',Form10.CheckBox15.Checked);
  IniFile.WriteBool('Settings','SmartFilterX',Form10.CheckBox10.Checked);
  IniFile.WriteString('Settings','FilterString',Form10.Edit5.Text);
  IniFile.WriteString('Settings','FilterIDString',Form10.Edit6.Text);
//  IniFile.WriteBool('Settings','CodeCatcher',Form1.CodeCatcher1.Checked);
  If Form2.StoreUsername.Checked=True Then
    IniFile.WriteString('Settings','UserName',Form2.ComboBox1.Text)
     else
    IniFile.WriteString('Settings','UserName','');
  IniFile.WriteString('Settings','Cookie',Cookie);
  IniFile.WriteString('Settings','NewLastRoom',Form2.RoomBox.Text);
  Inifile.WriteBool('Sounds','YmLiteGeneralSounds',Form1.YmLiteGeneralSounds1.Checked);
  Inifile.WriteBool('Sounds','YmLiteAlertSounds',Form1.YmLiteAlertSoundsBootersetc1.Checked);
  IniFile.WriteBool('Settings','IgnoreBuddyClone',Form10.CheckBox13.Checked);
//  IniFile.WriteBool('Settings','CrashBurnFilter',Form10.CheckBox24.Checked);
  IniFile.WriteBool('Settings','SmileyBlock',Form10.CheckBox25.Checked);
  IniFile.WriteBool('Settings','YaheliteSpamBots',Form10.CheckBox44.Checked);
//  IniFile.WriteBool('Settings','JitterBotFilter',Form10.CheckBox45.Checked);

  IniFile.WriteBool('Settings','AutoKnock',Form10.CheckBox29.Checked);
  IniFile.WriteBool('Settings','AllEqual',Form10.CheckBox26.Checked);
  IniFile.WriteInteger('Settings','SmileyBlockLevel',Form10.SpinEdit12.Value);
  IniFile.WriteInteger('Settings','ListBoxSettings',Form10.SpinEdit10.Value);
  IniFile.WriteInteger('Settings','SpinEdit14',Form10.SpinEdit14.Value);
  IniFile.WriteBool('Settings','ShowBuddyEnterLeave',Form10.CheckBox22.Checked);
  IniFile.WriteBool('Settings','AutoReject',Form1.AutoRejectAddBuddy1.Checked);
  IniFile.WriteBool('Settings','AutoRejectCamMsg',Form1.AutoRejectViewCamMEssages1.Checked);
//  IniFile.WriteBool('Settings','CosyChat',Form1.CosyChat1.Checked);
  IniFile.WriteBool('Settings','Invisible',Form2.CheckBox3.Checked);
//  IniFile.WriteBool('Settings','Checkforcheetaavatars',Form1.Checkforcheetaavatars1.Checked);
  IniFile.WriteBool('Settings','RememberPassword',Form2.CheckBox1.Checked);
  IniFile.WriteBool('Settings','RememberUsername',Form2.StoreUsername.Checked);  
  IniFile.WriteBool('Settings','AutoIgnore',Form10.CheckBox8.Checked);
  IniFile.WriteBool('Settings','DisplayTattoos',Form10.CheckBox33.Checked);
  IniFile.WriteBool('Settings','AutoIgnoreEmote',Form10.CheckBox34.Checked);
  IniFile.WriteBool('Settings','AntiAutoIgnoreEmote',Form10.CheckBox47.Checked);
  IniFile.WriteBool('Settings','RemoveIgnoredOption',Form10.CheckBox48.Checked);
  IniFile.WriteBool('Settings','YmLiteTrayIcon',Form10.CheckBox49.Checked);
  IniFile.WriteBool('Settings','CheetaSounds',Form10.CheckBox50.Checked);

  IniFile.WriteInteger('Settings','AutoIgnoreLimit',Form10.SpinEdit8.Value);
  IniFile.WriteInteger('Settings','UrlCount',Form5.SpinEdit1.Value);
  IniFile.WriteInteger('Settings','IDGapTime',Form10.SpinEdit6.Value);
   IniFile.WriteInteger('Settings','OldPanelLength',OldPanelLength);
//  IniFile.WriteInteger('Settings','SmartFilterCount',Form10.SpinEdit9.Value);
  IniFile.WriteBool('Settings','EnterLeaveMessages',Form1.RoomEnterLeaveMessages1.Checked);
//  IniFile.WriteBool('Settings','V10',Form2.RadioButton1.Checked);
//  IniFile.WriteBool('Settings','V11',Form2.RadioButton2.Checked);
  IniFile.WriteBool('Settings','AutoLogin',Form2.CheckBox2.Checked);
  IniFile.WriteInteger('Settings','RicheditColor',Form1.Richedit1.Color);
  IniFile.WriteBool('Settings','Boss Key',Form1.EnableBossKeyF101.Checked);
  IniFile.WriteBool('Settings','RadioButton10',Form10.RadioButton10.Checked);
  IniFile.WriteBool('Settings','RadioButton9',Form10.RadioButton9.Checked);
  IniFile.WriteBool('Settings','RadioButton11',Form10.RadioButton11.Checked);
  IniFile.WriteBool('Settings','RadioButton6',Form10.RadioButton6.Checked);
  IniFile.WriteInteger('Colors','Alert ID',Form10.ColorBox3.ColorValue);
  IniFile.WriteString('Emotes','LeaveRoom',Form28.Edit3.Text);
  IniFile.WriteString('Emotes','EnterRoom',Form28.Edit4.Text);
  IniFile.WriteBool('Emotes','CheckBox3',Form28.CheckBox3.Checked);
  IniFile.WriteBool('Emotes','CheckBox4',Form28.CheckBox4.Checked);
  IniFile.WriteBool('Emotes','CheckBox7',Form28.CheckBox7.Checked);
  IniFile.WriteString('Settings','StartCommand',Form28.Edit5.Text);
  IniFile.WriteBool('Interface','PMSEnabled',Form10.CheckBox17.Checked);
  IniFile.WriteBool('Interface','AutoWB',Form1.AutoReplytowb1.Checked);
  IniFile.WriteBool('Interface','AutoHi',Form1.Replytothanks1.Checked);
  IniFile.WriteBool('Interface','DeflectInvite',Form10.CheckBox20.Checked);
  IniFile.WriteBool('Interface','AutoVoiceIgnore',Form10.CheckBox21.Checked);
  IniFile.WriteBool('Interface','MessengerStyleEmotes',Form1.MessengerStyleEmotes1.Checked);
//  IniFile.WriteBool('Interface','Auto Identitar Check',Form1.AutoCheckforIdentitars1.Checked);
  IniFile.WriteBool('Interface','Custom Idiot Filter',Form10.CheckBox7.Checked);
  IniFile.WriteBool('Interface','Force To Lowercase Text',Form1.Forcetexttolowercase1.Checked);
  IniFile.WriteBool('Interface','Stop Bright Color',Form1.Brightcolorfiltr1.Checked);
//  IniFile.WriteBool('Interface','onEnterGreetFriends',Form1.onEnterGreetFriends1.Checked);
  IniFile.WriteBool('Settings','Greetbuddywhentheyenter',Form1.Greetbuddywhentheyenter1.Checked);
  IniFile.WriteString('Settings','Part1',Form24.Edit1.Text);
  IniFile.WriteString('Settings','Part2',Form24.Edit2.Text);
  IniFile.WriteString('Settings','Part3',Form24.Edit3.Text);
  IniFile.WriteString('Settings','Part4',Form24.Edit4.Text);
  IniFile.WriteString('Settings','Part5',Form24.Edit5.Text);
  //Form9.RadioButton3.Checked:=IniFile.ReadBool('Settings','Fade3',True);
  IniFile.WriteBool('Settings','Fade1',Form9.RadioButton1.Checked);
  IniFile.WriteBool('Settings','Fade2',Form9.RadioButton2.Checked);
  IniFile.WriteBool('Settings','Fade3',Form9.RadioButton3.Checked);
//  IniFile.WriteBool('Interface','FTP Server',Form1.EnableFTPserver1.Checked);
  IniFile.WriteString('Interface','FTP Server Path',FtpPath);
  If Form2.CheckBox1.Checked=True Then
    IniFile.WriteString('Settings','Password',Form1.CryptPassword(Form2.Edit1.Text,10))
     else
    IniFile.WriteString('Settings','Password',Form1.CryptPassword('',10));

  IniFile.WriteInteger('Settings','MaleColor',Form10.ColorPickCombo1.ColorValue);
  IniFile.WriteInteger('Settings','FemaleColor',Form10.ColorPickCombo2.ColorValue);
  IniFile.WriteInteger('Settings','MaleCam',Form10.ColorPickCombo3.ColorValue);
  IniFile.WriteInteger('Settings','FemaleCam',Form10.ColorPickCombo4.ColorValue);
  IniFile.WriteInteger('Settings','BackChatterColor',Form10.ColorPickCombo5.ColorValue);
  IniFile.Free;
End;


Function Tform1.DisplayAlphaImage(FileName: String): Boolean;
Begin
Result:=False;
If FileExists(FileName) Then
  Begin
   Result:=True;
   Form17.Image1.Picture.LoadFromFile(FileName);
   Form17.Show;
//   Form1.SetTransparentForm(Form1.Handle,Form10.SpinEdit13.Value);
   Form1.spDynamicSkinForm1.AlphaBlendValue:=Form10.SpinEdit13.Value;
   Form1.spDynamicSkinForm1.AlphaBlend:=True;
   Form1.BringToFront;
   Form10.Visible:=False;
  End;
End;



Procedure TForm1.LoadIniConfig;
Var
 Tf: Boolean;
 N: Integer;
 VoicePath,Tmp: String;
 IniFile: TFastiniFile;
 ExStyle: Longint;
Begin
  IniFile:=TFastiniFile.Create(Path+'config.ini');

  CrashBurnLevel:=IniFile.ReadFloat('Settings','CrashBurnLevel',0);

  Startup:=IniFile.ReadBool('Startup','Startup',True);
  If Startup=True Then
     IniFile.WriteBool('Startup','Startup',False);

  Form1.OldPanelLength:=IniFile.ReadInteger('Settings','OldPanelLength',280);
  If Form1.OldPanelLength>=Form1.Width-20 Then
    Form1.OldPanelLength:=280;

  Form1.Panel1.Width:=OldPanelLength;

  If IniFile.ReadInteger('Alignment','Panel3',1) = 1 Then
    Form1.Panel3.Align:=AlTop
     else
    Form1.Panel3.Align:=AlBottom;

  SpSkinPanel2.Visible:=IniFile.ReadBool('Visible','dfstoolbar1',False);
  SpSkinControlBar1.Visible:=IniFile.ReadBool('Visible','SpSkinControlBar1',False);
//  SpSkinControlBar2.Visible:=IniFile.ReadBool('Visible','SpSkinControlBar2',True);
//  SpSkinControlBar3.Visible:=IniFile.ReadBool('Visible','SpSkinControlBar3',True);

  Panel1.Visible:=IniFile.ReadBool('Visible','Mp3Bar',False);
  If Panel1.Visible=True Then
    InitMp3
     else
   SpSkinSplitter1.Visible:=False;


 //   IniFile.WriteString('Mp3Path','Path',Form1.LastPath);
  Form10.CheckBox23.Checked:=IniFile.ReadBool('Settings','Logging',False);
  Form10.CheckBox28.Checked:=IniFile.ReadBool('Settings','TimeStamping',False);
  LastPath:=IniFile.ReadString('Mp3Path','Path','c:\');
  SpSkinMainMenuBar1.Visible:=IniFile.ReadBool('Visible','SpSkinMainMenuBar1',True);
  SpSkinExPanel1.Visible:=IniFile.ReadBool('Visible','SpSkinExPanel1',True);
  SpSkinExPanel2.Visible:=IniFile.ReadBool('Visible','SpSkinExPanel2',True);
  SpSkinExPanel3.Visible:=IniFile.ReadBool('Visible','SpSkinExPanel3',True);
  SpSkinExPanel4.Visible:=IniFile.ReadBool('Visible','SpSkinExPanel4',True);
//  SpSkinExPanel5.Visible:=IniFile.ReadBool('Visible','SpSkinExPanel5',True);
  SpSkinScrollPanel1.Visible:=IniFile.ReadBool('Visible','SpSkinScrollPanel1',True);
  panel3.Visible:=IniFile.ReadBool('Visible','panel3',False);

  Form10.CheckBox41.Checked:=IniFile.ReadBool('Layout','5SecondRule',True);
 //  IniFile.WriteBool('Layout','5SecondRule',Form10.CheckBox41.Checked);

{  Form2.SpSkinCheckRadioBox3.Checked:=iniFile.ReadBool('Sparta','Enabled',False);
  If Form2.SpSkinCheckRadioBox3.Checked=False Then
    Form2.ClientHeight:=411 else
     Form2.ClientHeight:=466;}

//   IniFile.WriteBool('Settings','Description',Form10.CheckBox43.Checked);
 Form10.CheckBox43.Checked:=IniFile.ReadBool('Settings','Description',True);
  //panel3
//    IniFile.WriteBool('SpellChecker','SpellCheck',Form1.SpellChecker1.Checked);
  If IniFile.ReadBool('SpellChecker','SpellCheck',False)=True Then
    Form1.SpellChecker1.OnClick(Nil);
//   IniFile.WriteBool('Settings','AntiBooter',Form2.BootResistant1.Checked);

//  IniFile.WriteBool('Settings','Bumping',Form2.BumpCheckbox.Checked);
//  Form2.BumpingCheckbox.Checked:=IniFile.ReadBoolean('Settings','Bump',False);
//  Form2.BootResistant1.Checked:=IniFile.ReadBool('Settings','AntiBooter',False);
  Form1.LastIgnored:=IniFile.ReadDateTime('Settings','LastIgnored',Now);
  Form10.SpinEdit13.Value:=IniFile.ReadInteger('Settings','AlphaBlend',220);
  Form10.Edit13.Text:=IniFile.ReadString('Settings','AlphaImage','');
  Form10.CheckBox31.Checked:=IniFile.ReadBool('Settings','CheckBox31',False);
  Form10.CheckBox32.Checked:=IniFile.ReadBool('Settings','CheckBox32',False);
  RejectMailInvites1.Checked:=iniFile.ReadBool('Settings','MailNotifications',True);
//  Form2.EyeCheckBox.Checked:=IniFile.ReadBoolean('Eye','EyeEnabled',False);
//  IF Form2.EyeCheckBox.Checked=True Then
//     Form2.Height:=Form2.SpSkinPasswordEdit1.top+Form2.SpSkinPasswordEdit1.Height+45;
//  Form2.SpSkinEdit1.Text:=IniFile.ReadString('Eye','Username','');
//  Form2.SpSkinPasswordEdit1.Text:=IniFile.ReadString('Eye','Password','');

//     IniFile.WriteReal('Settings','BandwithSpeed',Form1.MaxDownloadSpeed);

  If IniFile.ReadBool('Settings','FancyInterface',False)=True Then
     FancyMenuInterface1.OnClick(Self);

  Form10.CheckBox36.Checked:=IniFile.ReadBool('Settings','LoveRoomBots',True);
  Form10.CheckBox37.Checked:=IniFile.ReadBool('Settings','CheckBox37',True);
  Form10.ColorPickCombo6.ColorValue:=IniFile.ReadInteger('Colors','InputBox',ClWhite);
//  Form1.YaheliteMemoryTrick1.Checked:=IniFile.ReadBool('Settings','YaheliteTrick',False);

  Form1.RichEdit2.Color:=Form10.ColorPickCombo6.ColorValue;

{ If CountDown<>0 Then
  Form1.WebBrowser1.Navigate('http://ymlitechat.com/ymlite/index.html#label');}

//  IniFile.WriteBool('Settings','WantSprt',True);
  {   IniFile.WriteBool('Layout','Auth1',Form2.spSkinCheckRadioBox1.Checked);
   IniFile.WriteBool('Layout','Auth2',Form2.spSkinCheckRadioBox2.Checked);
}
//   IniFile.WriteInteger('Settings','TimeTyping',ActualTimeTyping);
  ActualTimeTyping:=IniFile.ReadInteger('Settings','TimeTyping_',0);
//  Form2.spSkinCheckRadioBox1.Checked:=IniFile.ReadBool('Layout','Auth1',True);
//  Form2.spSkinCheckRadioBox2.Checked:=IniFile.ReadBool('Layout','Auth2',True);
  Form53.CheckBox1.Checked:=IniFile.ReadBool('Settings','wallpaper',False);
  Form53.FileImage:=IniFile.ReadString('Settings','WallpaperImage','');
//  IniFile.WriteBool('Settings','GotoCommand',Form10.GotoBox.Checked);
  Form10.GotoBox.Checked:=IniFile.ReadBool('Settings','GotoCommand',False);
  //  Form48.CheckBox1.Checked:=IniFile.ReadBool('Mail','CheckMail',True);

   If IniFile.ReadBool('Layout','NewBuilds',False)=False Then
    Begin
      IF FileExists(Path+'chatdata.dat')=True Then
          DeleteFile(Path+'chatdata.dat');
      IniFile.WriteBool('Layout','NewBuilds',True);
    End;


  Form2.RadioButton1.Checked:=IniFile.ReadBool('Settings','YMSG',True);

  TClickCount:=IniFile.ReadInteger('Settings','PCount',0);
//  Form10.Edit14.text:=IniFile.ReadString('Settings','PMBossMode','I''m currently Busy right now, try again later....');

  Form1.GirlyFilter1.Checked:=IniFile.ReadBool('Settings','GirlyFilter',False);
  If Form1.GirlyFilter1.Checked=True Then
  If FileExists(Path+'girlyfilter.ypf')=True Then
    GirlyFilter.LoadPersonality(Path+'girlyfilter.ypf')
      else
    GirlyFilter1.Checked:=False;

  Form1.Width:=IniFile.ReadInteger('Settings','ScreenWidth',770);
  Form1.Height:=IniFile.ReadInteger('Settings','ScreenHeight',362);
//  Form1.StayOnTop1.Checked:=IniFile.ReadBool('Settings','StayOnTop',False);
{  If IniFile.ReadBool('Settings','ScreenMaximized',True)=True Then
     Form1.WindowState:=wsMaximized;}
//  ScreenMaximized

  TotalTime:=IniFile.ReadInteger('Settings','TotalTime',0);
 { IniFile.WriteBool('Settings','CheckBox18',False);
  IniFile.WriteBool('Settings','CheckBox119',False);}
  form10.CheckBox18.Checked:=IniFile.ReadBool('Settings','DoubleClickPM',False);
  form10.CheckBox19.Checked:=IniFile.ReadBool('Settings','InvertCheckBox19',True);
  form10.CheckBox30.Checked:=IniFile.ReadBool('Settings','CheckBox30',False);

//  IniFile.WriteInteger('Settings','Splitter1',Form1.spSkinSplitter1.Left);
//  IniFile.WriteBool('Settings','ShoutBox',Form1.SpSkinCheckRadioBox2.Checked);

  Form1.Top:=IniFile.ReadInteger('Settings','formtop',1);
  Form1.Left:=IniFile.ReadInteger('Settings','formleft',1);
  Form1.HttpFileDownloader1.Checked:=IniFile.ReadBool('Settings','httpdownloader',False);

 If IniFile.ReadString('Settings','ControlBar1','Top')='Top' Then
   Form1.spSkinControlBar1.Align:=AlTop;

 If IniFile.ReadString('Settings','ControlBar1','Top')='Bottom' Then
   Form1.spSkinControlBar1.Align:=AlBottom;

 If IniFile.ReadString('Settings','ControlBar2','Bottom')='Top' Then
   Form1.spSkinControlBar2.Align:=AlTop;
 If IniFile.ReadString('Settings','ControlBar2','Bottom')='Bottom' Then
   Form1.spSkinControlBar2.Align:=AlBottom;


 If IniFile.ReadString('Layout','SpSkinPanel2','Top')='Top' Then
   Form1.SpSkinPanel2.Align:=AlTop;
 If IniFile.ReadString('Layout','SpSkinPanel2','Top')='Bottom' Then
   Form1.SpSkinPanel2.Align:=AlBottom;


 If IniFile.ReadString('Settings','UserListPanelAllign','Right')='Right' Then
   Begin
     Form1.SpSkinScrollPAnel1.Align:=AlRight;
     Form1.SpSkinSplitter2.Align:=AlRight;
   End
    else
   Begin
     Form1.SpSkinScrollPAnel1.Align:=AlLeft;
     Form1.SpSkinSplitter2.Align:=AlLeft;
//     Form1.Splitter1.Align:=AlLeft;
   End;


// SpSkinSplitter3.Top:=SpSkinControlBar4.Top+5;;
  Form9.RadioButton1.Checked:=IniFile.ReadBool('Settings','Fade1',True);
  Form9.RadioButton2.Checked:=IniFile.ReadBool('Settings','Fade2',False);
  Form9.RadioButton3.Checked:=IniFile.ReadBool('Settings','Fade3',False);
//  Form1.AutoAllowFriendsAccess1.Checked:=IniFile.ReadBool('Settings','AutoAllowFriendsAccess',True);
  Form10.Edit11.Text:=IniFile.ReadString('Settings','ClientIgnoreList','');
  Form10.SpinEdit14.Value:=IniFile.ReadInteger('Settings','SpinEdit14',60);
  Form10.CheckBox24.Checked:=IniFile.ReadBool('Settings','ClientIgnore',False);
  Form10.HiddenTextBot.Checked:=IniFile.ReadBool('Settings','HiddenTextFilter',True);
//  Form2.CheckBox4.Checked:=IniFile.ReadBool('Settings','AutoCookie',True);
  Form10.ColorBox4.ColorValue:=IniFile.ReadInteger('Settings','BuddyColour',ClNavy);
  Form10.CheckBox42.Checked:=IniFile.ReadBool('Alerts','GraphicalAva',True);
//  Form10.ColorPickCombo9.ColorValue:=IniFile.ReadInteger('Settings','YchtStart',ClRed);
//  Form10.ColorPickCombo10.ColorValue:=IniFile.ReadInteger('Settings','YchtEnd',ClBlue);
  Form10.ColorPickCombo11.ColorValue:=IniFile.ReadInteger('Settings','ColFadeS',ClRed);
//  Form10.ColorPickCombo12.ColorValue:=IniFile.ReadInteger('Settings','ColFadeE',ClBlue);
  Form10.ColorPickCombo10.ColorValue:=IniFile.ReadInteger('Settings','ListBoxFadeS',ClLightBlue);
  Form10.ColorPickCombo9.ColorValue:=IniFile.ReadInteger('Settings','ListBoxFadeE',ClLightPink);

  Form10.CheckBox35.Checked:=IniFile.ReadBool('Colors','YFadeID',False);
  Form10.CheckBox40.Checked:=IniFile.ReadBool('Colors','TFadeID',True);
  TimeLoggedTyping:=IniFile.ReadDateTime('Settings','TimeLoggedTyping',Now);

//
//  Form10.ColorBox6.ColorValue:=IniFile.ReadInteger('Settings','ButtonFontColor',clBlack);
  Form10.Edit8.Text:=IniFile.ReadString('Settings','PmWindowTime','7');
  Form10.SpinEdit12.Value:=IniFile.ReadInteger('Settings','SmileyBlockLevel',5);
  Form10.SpinEdit10.Value:=IniFile.ReadInteger('Settings','ListBoxSettings',10);

  Form2.RadioButton4.Checked:=IniFile.ReadBool('Settings','SPRTMODE',False);
//  Form1.DebugConsoleWindow1.Checked:=IniFile.ReadBool('Settings','DebugWindow',False);
  Form10.CheckBox17.Checked:=IniFile.ReadBool('Interface','PMSEnabled',True);
//  Form10.CheckBox24.Checked:=IniFile.ReadBool('Settings','CrashBurnFilter',False);
  Form10.CheckBox25.Checked:=IniFile.ReadBool('Settings','SmileyBlock',True);
  Form10.CheckBox44.Checked:=IniFile.ReadBool('Settings','YaheliteSpamBots',True);
  Form10.CheckBox46.Checked:=IniFile.ReadBool('Settings','AliciaBot',True);
//    IniFile.WriteBool('Settings','AliciaBot',Form10.CheckBox46.Checked);
//  Form10.CheckBox45.Checked:=IniFile.ReadBool('Settings','JitterBotFilter',True);
  Form10.CheckBox29.Checked:=IniFile.ReadBool('Settings','AutoKnock',True);
  Form10.CheckBox26.Checked:=IniFile.ReadBool('Settings','AllEqual',True);
  Form10.CheckBox27.Checked:=IniFile.ReadBool('Settings','CloneEnterLeaveFilter',True);
  Form1.FlashWindowOnID1.Checked:=IniFile.ReadBool('Settings','FlashWindow',False);
  Form1.Panel5.Height:=IniFile.ReadInteger('Settings','Panel5h',30);




   //  IniFile.WriteInteger('Settings','VideoPanel',Form1.Panel1.Width);
  Form1.ProcessGamesMessages1.Checked:=IniFile.ReadBool('Settings','ProcessGamesMessages1',True);
  Form8.ServComboBox.Text:=IniFile.ReadString('Settings','LastServerCmb','insider.msg.yahoo.com');
  Form13.CheckBox1.Checked:=IniFile.ReadBool('Settings','AutoCheckForNewBuild',True);
  Form13.CheckBox2.Checked:=IniFile.ReadBool('Settings','AutoCheckSmileys',True);
//  IniFile.WriteString('Settings','SendSpeed',Form10.Edit7.text);
  Form10.Edit7.Text:=IniFile.ReadString('Settings','SendSpeed','450');
  Form10.Edit12.Text:=IniFile.ReadString('Settings','KnockSpeed','3300');
  Picture:=IniFile.ReadString('Settings','PictureF','');
  Form10.SpinEdit3.Value:=IniFile.ReadInteger('Settings','ReconnectT',5);
  EmZoom:=IniFile.ReadInteger('Settings','EmSettings',64);

  Form28.Memo1.Text:=IniFile.ReadString('Settings','CustomAway','I am away so please don''t bother me!');
  Form10.CheckBox12.Checked:=IniFile.ReadBool('Settings','CloneScan',True);
  Form1.SpSkinScrollPAnel1.Width:=IniFile.ReadInteger('Settings','UserListPanel',200);
  If Form1.SpSkinScrollPAnel1.Width<5 Then Form1.SpSkinScrollPAnel1.Width:=8;


  Form10.aa1BotFilter.Checked:=IniFile.ReadBool('Settings','aa1BotFilter',True);
  Form10.CheckBox14.Checked:=IniFile.ReadBool('Settings','FirstPostURLIgnore',True);
  Form10.CheckBox9.Checked:=IniFile.ReadBool('Settings','AutoSave',False);
  Form10.CheckBox11.Checked:=IniFile.ReadBool('Settings','SpamIgnore',False);
  Form10.CheckBox15.Checked:=IniFile.ReadBool('Settings','UserIDIgnore',False);
  Form10.Edit5.Text:=IniFile.ReadString('Settings','FilterString','');
  Form10.Edit6.Text:=IniFile.ReadString('Settings','FilterIDString','');
  LoggedInName:=IniFile.ReadString('Settings','UserName','Username');
  Form2.ComboBox1.Text:=LoggedInName;
//  Form1.CodeCatcher1.Checked:=IniFile.ReadBool('Settings','CodeCatcher',False);
  Cookie:=IniFile.ReadString('Settings','Cookie','');
  GpRoomName:=IniFile.ReadString('Settings','NewLastRoom','Yahoo! Chat Help:1::1600326597');
  Form1.LastCat:=IniFile.ReadString('Settings','LastCat','0');
  Form2.RoomBox.Text:=GpRoomName;
  Form1.YmLiteGeneralSounds1.Checked:=iniFile.ReadBool('Sounds','YmLiteGeneralSounds',True);
  Form1.YmLiteAlertSoundsBootersetc1.Checked:=iniFile.ReadBool('Sounds','YmLiteAlertSounds',True);
  {
    Inifile.WriteBool('Sounds','YmLiteGeneralSounds',Form1.YmLiteGeneralSounds1.Checked);
  Inifile.WriteBool('Sounds','YmLiteAlertSounds',Form1.YmLiteAlertSoundsBootersetc1.Checked);
 }

  Form10.CheckBox13.Checked:=IniFile.ReadBool('Settings','IgnoreBuddyClone',False);
  Form10.CheckBox22.Checked:=IniFile.ReadBool('Settings','ShowBuddyEnterLeave',False);
  Form1.AutoRejectAddBuddy1.Checked:=IniFile.ReadBool('Settings','AutoReject',True);
  Form1.AutoRejectViewCamMessages1.Checked:=IniFile.ReadBool('Settings','AutoRejectCamMsg',True);
//  Form1.CosyChat1.Checked:=IniFile.ReadBool('Settings','CosyChat',False);
  Form2.CheckBox3.Checked:=IniFile.ReadBool('Settings','Invisible',False);
//  Form1.Checkforcheetaavatars1.Checked:=IniFile.ReadBool('Settings','Checkforcheetaavatars',false);
  Form2.CheckBox1.Checked:=IniFile.ReadBool('Settings','RememberPassword',True);
  Form2.StoreUsername.Checked:=IniFile.ReadBool('Settings','RememberUsername',True);

  Form10.SpinEdit8.Value:=IniFile.ReadInteger('Settings','AutoIgnoreLimit',3);
  Form10.CheckBox8.Checked:=IniFile.ReadBool('Settings','AutoIgnore',True);
  Form10.CheckBox10.Checked:=IniFile.ReadBool('Settings','SmartFilterX',True);
  Form10.CheckBox33.Checked:=IniFile.ReadBool('Settings','DisplayTattoos',False);
  Form10.CheckBox47.Checked:=IniFile.ReadBool('Settings','AntiAutoIgnoreEmote',False);
  Form10.CheckBox48.Checked:=IniFile.ReadBool('Settings','RemoveIgnoredOption',True);
  Form10.CheckBox49.Checked:=IniFile.ReadBool('Settings','YmLiteTrayIcon',True);
  Form10.CheckBox50.Checked:=IniFile.ReadBool('Settings','CheetaSounds',True);
  Form1.spTrayIcon1.IconVisible:=Form10.CheckBox49.Checked;
  Form10.CheckBox34.Checked:=IniFile.ReadBool('Settings','AutoIgnoreEmote',False);
  Form5.SpinEdit1.Value:=IniFile.ReadInteger('Settings','UrlCount',200);
  Form1.EnableBossKeyF101.Checked:=IniFile.ReadBool('Settings','Boss Key',True);
  Form1.RoomEnterLeaveMessages1.Checked:=IniFile.ReadBool('Settings','EnterLeaveMessages',True);
  Form1.Richedit1.Color:=IniFile.ReadInteger('Settings','RicheditColor',ClWhite);
  Form10.ColorPickCombo7.ColorValue:=Form1.Richedit1.Color;
  Form10.RadioButton10.Checked:=IniFile.ReadBool('Settings','RadioButton10',True);
  Form10.RadioButton9.Checked:=IniFile.ReadBool('Settings','RadioButton9',False);
  Form10.RadioButton11.Checked:=IniFile.ReadBool('Settings','RadioButton11',False);
  Form10.RadioButton6.Checked:=IniFile.ReadBool('Settings','RadioButton6',False);
  Form10.SpinEdit6.Value:=IniFile.ReadInteger('Settings','IDGapTime',500);
//  Form10.SpinEdit9.Value:=IniFile.ReadInteger('Settings','SmartFilterCount',20);
  Form28.Edit3.Text:=IniFile.ReadString('Emotes','LeaveRoom','default');
  Form28.Edit4.Text:=IniFile.ReadString('Emotes','EnterRoom','default');
  Form28.CheckBox3.Checked:=IniFile.ReadBool('Emotes','CheckBox3',false);
  Form28.CheckBox4.Checked:=IniFile.ReadBool('Emotes','CheckBox4',false);
  Form28.CheckBox7.Checked:=IniFile.ReadBool('Emotes','CheckBox7',false);
  Form28.Edit5.Text:=IniFile.ReadString('Settings','StartCommand','/budlist');
  Form1.AutoReplytowb1.Checked:=IniFile.ReadBool('Interface','AutoWB',False);
  Form1.Replytothanks1.Checked:=IniFile.ReadBool('Interface','AutoHi',false);
  Form10.CheckBox20.Checked:=IniFile.ReadBool('Interface','DeflectInvite',False);
  Form10.CheckBox21.Checked:=IniFile.ReadBool('Interface','AutoVoiceIgnore',True);
  Form1.MessengerStyleEmotes1.Checked:=IniFile.ReadBool('Interface','MessengerStyleEmotes',True);
//  Form1.AutoCheckforIdentitars1.Checked:=IniFile.ReadBool('Interface','Auto Identitar Check',False);
  Form10.CheckBox7.Checked:=IniFile.ReadBool('Interface','Custom Idiot Filter',True);
  Form1.Forcetexttolowercase1.Checked:=IniFile.ReadBool('Interface','Force To Lowercase Text',False);
  Form1.Brightcolorfiltr1.Checked:=IniFile.ReadBool('Interface','Stop Bright Color',False);
  Form10.ColorBox3.ColorValue:=IniFile.ReadInteger('Colors','Alert ID',ClTeal);
  MainPanel.Height:=IniFile.ReadInteger('Settings','MainPanelHeight',40);
//  Form2.RadioButton1.Checked:=IniFile.ReadBool('Settings','V10',False);
//  Form2.RadioButton2.Checked:=IniFile.ReadBool('Settings','V11',True);
  Form2.CheckBox2.Checked:=IniFile.ReadBool('Settings','AutoLogin',False);
  Form1.Greetbuddywhentheyenter1.Checked:=IniFile.ReadBool('Settings','Greetbuddywhentheyenter',False);
  Form1.CustomMessagesSetup1.Checked:=IniFile.ReadBool('Settings','CustomMessagesSetup',False);
//  Form1.onEnterGreetFriends1.Checked:=IniFile.ReadBool('Interface','onEnterGreetFriends',False);
  {For N:=Form50.CheckListBox1.Items.Count-1 downto 0 do
     If Form50.CheckListBox1.Items[N]='Programmable Buttons'=True Then
       Form50.CheckListBox1.Checked[N]:=IniFile.ReadBool('Settings',Form50.CheckListBox1.Items[N],False)
         else
        Form50.CheckListBox1.Checked[N]:=IniFile.ReadBool('Settings',Form50.CheckListBox1.Items[N],True);}
  Form1.UpdateWindows(True);
  Form24.Edit1.Text:=IniFile.ReadString('Settings','Part1','Hey there');
  Form24.Edit2.Text:=IniFile.ReadString('Settings','Part2','how you all doing?');
  Form24.Edit3.Text:=IniFile.ReadString('Settings','Part3','bye');
  Form24.Edit4.Text:=IniFile.ReadString('Settings','Part4','');
  Form24.Edit5.Text:=IniFile.ReadString('Settings','Part5','How''s it going');
  Form2.Edit1.Text:=Form1.DecryptPassword(IniFile.ReadString('Settings','Password',''),10);
  FtpPath:=IniFile.ReadString('Interface','FTP Server Path','C:\FileShare');
  LastMerge:=IniFile.ReadDateTime('Settings','LastMerge',Now);
  If Startup=True Then
   Begin
     TFileDownload.Create('http://ymlitechat.com/ymlite/botstrings.txt',Path+'botmergestrings.txt','80',0,Nil,False,True,True,False);
     LastMerge:=Now;
   End;
  SkinName:=IniFile.ReadString('Settings','skinname','');
  Application.ProcessMessages;
   If SkinName<>'' Then
    If FileExists(SkinName) Then
     Begin
     Form1.SpSkinData1.LoadFromCompressedFile(SkinName);
     Form1.Panel3.Height:=Panel10.Height;
     End;


 { If IniFile.ReadBool('Settings','YmLite2934',False)=False Then
    Begin
      ShowMessage('As of 293.4, Y!mLite''s Filters have been strongly upgraded, Press ok To Upgrade The Filter File.');
      TFileDownload.Create('http://ymlitechat.com/ymlite/botstrings.txt',Path+'botmergestrings.txt','80',0,Nil,False,True,True,False);
      PornBotTracker.CleanUp;
      ShowMessage('Thank you for using Y!mLite, Filters Now Upgraded...');
      IniFile.WriteBool('Settings','YmLite2934',True);
    End;}

{  If IniFile.ReadString('Settings','StartupMessage1',True)=True Then
   Begin
     IniFile.WriteString('Settings','StartupMessage1,False);
     MessageBox('If you need help with y!mlite
   End;}

{   If IniFile.ReadBool('Settings','YmliteForu',True)=True Then
   Begin
     IniFile.WriteBool('Settings','NewYahooChanges',False);
     IF MessageDlg('IMPORTANT new Yahoo! changes as of the 1st of November, These changes could affect you, Click yes to read more... ',MtConfirmation,[MbYes,MBNo],0)=IDYes Then
        Form1.shellExecute(handle,'open',pchar('http://ymlitechat.com'),'','',0);
   End;}


 { If IniFile.ReadBool('Startup','StartupMessage1',True)=True Then
   Begin
     IniFile.WriteBool('Startup','StartupMessage1',False);
     IF MessageDlg('Would you like to the Y!mLite Guest Map? Press NO if you have already seen it or don''t wish to see it.. ',MtConfirmation,[MbYes,MBNo],0)=IDYes Then
      Begin
        If ProfileWindow=Nil Then
         ProfileWindow:=TForm16.Create(Self);
       Form1.CreateSkin(ProfileWindow);
       ProfileWindow.CastingVote:=True;
       ProfileWindow.Show;
       ProfileWindow.Height:=Profilewindow.Height+60;
       ProfileWindow.WebBrowser1.Navigate('http://pub12.bravenet.com/guestmap/show.php?usernum=945276253&icons=1');
      End;
   End;}

{  If IniFile.ReadBool('Startup','NewFilters1',True)=True Then
   Begin
     IniFile.WriteBool('Startup','NewFilters1',False);
     ShowMessage('Welcome to Y!mLite Build 277.2 and Higher, Due to New Filters, We have To Upgrade Your Existing Data, Press OK - This may take a few seconds.');
     PornBotTracker.CleanBotList;
   End;}


   //http://pub12.bravenet.com/guestmap/show.php?usernum=945276253

//     Form1.spSkinData1.LoadFromFile(SkinName);
//  IniFile.WriteString('Settings','skinname',ExtractFilePath(Form1.spCompressedStoredSkin1.FileName));
{  If IniFile.ReadBool('Settings','WantSprt.8',False)=False Then
    Begin
     IF MessageDlg('Would you like to try the non Yahoo Chat Server? no missing posts and it''s moderated, aka the SPRT protocol, which can be selected manually if you select no...',MtConfirmation,[MbYes,MBNo],0)=IDYes Then
         Form2.RadioButton4.Checked:=True;
    End;}
 ///load in color values

   //ColorBoxes!

{    If IniFile.ReadBool('Webpage','Visit',False)=False Then
    Begin
      If MessageDlg('As a thank you for using Y!mLite, we have made MindFeeder which was previously not free... FREE as our Chistmas Gift to you, you can find this and other cool stuff at our home page , Have a merry Christmas.. Press Yes To Visit The'+' Y!mLite Webpage (P.S Click The Ads To Keep Y!mLite Free!)',MTconfirmation,[MBYES,MBNO],0)=IDYes Then
       Begin
          ShellExecute(Handle,'OPEN',Pchar('http://www.ymlitechat.com'),Pchar(''),'',SW_Show);
          Form1.Releaseanyfreememory1.OnClick(Self);
        End;
      IniFile.WriteBool('Webpage','Visit',True);
    End;}

   { If IniFile.ReadBool('Sparta','NewSpartaMessenger',False)=False Then
    Begin
      If MessageDlg('Due to all the increasing yahoo problems, We''ve re-launched Sparta Messenger Press Yes if you''d like to try it, It is an alternative to yahoo chat which gives Custom Rooms / Chat Support without Bots or Lag (It Runs with Y!mLite and Yahoo Messenger) ',MTconfirmation,[MBYES,MBNO],0)=IDYes Then
           Form13.Button6.OnClick(Self);
      IniFile.WriteBool('Sparta','NewSpartaMessenger',True);
    End;}


   If YmLiteAlertSoundsBootersetc1.Checked=False Then
    If IniFile.ReadBool('Questions','Sounds',False)=False Then
    Begin
      If MessageDlg('Y!mLite has Detected your Y!mLite Alert Sounds as Off..., Press YES to Enable Voice Alerts Again, No to keep Alerts Off.',MTconfirmation,[MBYES,MBNO],0)=IDYes Then
        YmLiteAlertSoundsBootersetc1.Checked:=True;
      IniFile.WriteBool('Questions','Sounds',True);
    End;

  Form10.ColorPickCombo1.ColorValue:=IniFile.ReadInteger('Settings','MaleColor',ClBlue);
  Form10.ColorPickCombo2.ColorValue:=IniFile.ReadInteger('Settings','FemaleColor',clFuchsia);
  Form10.ColorPickCombo3.ColorValue:=IniFile.ReadInteger('Settings','MaleCam',clMaroon);
  Form10.ColorPickCombo4.ColorValue:=IniFile.ReadInteger('Settings','FemaleCam',clRed);
  Form10.ColorPickCombo5.ColorValue:=IniFile.ReadInteger('Settings','BackChatterColor',clWhite);
  Form1.ListBox3.Color:=Form10.ColorPickCombo5.ColorValue;

{  Form2.spSkinEdit1.Text:=IniFile.ReadString('Sparta','Username','');
  Form2.spSkinPasswordEdit1.Text:=IniFile.ReadString('Sparta','Password','');}


{  If Form2.spSkinCheckRadioBox3.Checked=True Then
   If Form2.spSkinEdit1.Text='' Then
     Begin
      ShowMessage('Dual Login Yahoo/Sparta now possible, if you do not want this, close and disable the option in the menu');
      TGetIPAdd.Create('');
      Form1.CreateSkin(Form51);
      Form51.ShowModal;
     End;}

  IniFile.Free;
  Form1.ReleaseMemory;
{  IF Form10.CheckBox31.Checked=True Then
     Form1.SetTransparentForm(Form1.Handle,Form10.SpinEdit13.Value);

  If Form10.CheckBox32.Checked=True Then
     Form1.DisplayAlphaImage(Form10.Edit13.Text);}
End;

Procedure Tform1.SaveLayOut;
Var
  ExStyle: Longint;
  Startup: Boolean;
  Tf: Boolean;
  N: Integer;
  VoicePath,Tmp: String;
  IniFile: TFastiniFile;
Begin
 Form1.SaveIniConfig;
 IniFile:=TFastiniFile.Create(Path+'chatdata.ini');
// Form1.HotKeysEnabled1.Checked:=Not IniFile.ReadBool('Settings','HotKeys',True);
 IniFile.WriteBool('Settings','HotKeys',Form1.HotKeysEnabled1.Checked);
 IniFile.WriteInteger('Layout','AC',Form1.ColorBox1.ColorValue);
 IniFile.WriteBool('Layout','B',Form1.BoldP.Checked);
 IniFile.WriteBool('Layout','U',Form1.UnderLineP.Checked);
 IniFile.WriteBool('Layout','I',Form1.ItalicP.Checked);
 IniFile.WriteInteger('Layout','UFS',UserFontSize);
 IniFile.WriteBool('Layout','NoFonts',Form10.RadioButton10.Checked);
 IniFile.WriteString('Layout','Ident',Identitar);
 IniFile.WriteBool('Layout','Fader',Form1.spSkinCheckRadioBox1.Checked);
 IniFile.WriteBool('Layout','AI',Form1.EnableAi1.Checked);
 IniFile.WriteBool('Layout','SweardWordFilter',Form1.EnableSwearWordFilter1.Checked);
 IniFile.WriteBool('Layout','OtronTechnology1',Form1.OtronTechnology1.Checked);
 IniFile.WriteString('Layout','FontName',Form1.SpSkinFontComboBox1.FontName);
 IniFile.WriteString('Layout','FontSize',Form1.SpSkinComboBox2.Text);
 IniFile.WriteBool('Layout','PmsFromFriends',Form10.CheckBox16.Checked);
 IniFile.WriteBool('Layout','IggyEmote',Form18.CheckBox1.Checked);
 IniFile.WriteBool('Layout','IggyEmote2',Form18.CheckBox2.Checked);
 IniFile.WriteString('Layout','IggyEmoteText',Form18.Edit2.Text);
 IniFile.WriteString('Layout','IggyEmoteText2',Form18.Edit3.Text);
 IniFile.WriteBool('Layout','DingOnID',Form1.DingOnID1.Checked);
 IniFile.WriteBool('Layout','IdentsOn',Form1.On1.Checked);
 IniFile.WriteString('Layout','mp3dir',Form10.Edit2.Text);
 IniFile.WriteInteger('Layout','FloodLevel',Form10.SpinEdit1.Value);
 IniFile.WriteBool('Layout','YIDCheck',Form10.CheckBox2.Checked);
 IniFile.WriteInteger('Layout','FloodMatch',Form10.SpinEdit2.Value);
// IniFile.WriteInteger('Layout','CloneMatch',Form10.SpinEdit3.Value);
 IniFile.WriteInteger('Layout','CustomFontSize',Form10.SpinEdit4.Value);
 IniFile.WriteInteger('Layout','YID',Form10.SpinEdit5.Value);
 IniFile.WriteInteger('Layout','MaxSmiley',Form10.SpinEdit7.Value);

 IniFile.WriteString('Layout','ProxyAdd',Form10.Edit3.Text);
 IniFile.WriteString('Layout','ProxyPort',Form10.Edit4.Text);
 IniFile.WriteBool('Layout','ProxyEnabled',Form10.CheckBox3.Checked);
 IniFile.WriteBool('Layout','AutoConnectS',Form10.CheckBox6.Checked);
 IniFile.WriteBool('Layout','UseBrackets',Form10.CheckBox1.Checked);
 IniFile.WriteInteger('Layout','YourIdColor',Form10.ColorBox1.ColorValue);
 IniFile.WriteInteger('Layout','ThierIdColor',Form10.ColorBox2.ColorValue);
 IniFile.WriteBool('Layout','Cloneoutput',Form10.CheckBox5.Checked);
 IniFile.WriteInteger('Layout','MaxLines',MaxLines);
// IniFile.WriteBool('Layout','RejectFirstUrl',Form10.CheckBox4.Checked);
// IniFile.WriteString('Layout','FilterString',Form10.Edit5.Text);
// IniFile.WriteInteger('Layout','FilterLevel',FilterLevel);

 IniFile.WriteInteger('Layout','AntiFlood',FilterLevel);

// IniFile.WriteInteger('Layout','BarCol',Form10.ColorPickCombo8.ColorValue);
// IniFile.WriteInteger('Layout','BarFontCol',Form10.ColorPickCombo13.ColorValue);
 IniFile.WriteString('Layout','LastRoom',GpRoomName);
 IniFile.WriteString('Settings','LastCat',LastCat);
 IniFile.Free;
End;


Procedure Tform1.LoadLayOut;
Var
  ExStyle: Longint;
  Startup: Boolean;
  Tf: Boolean;
  N: Integer;
  VoicePath,Tmp: String;
  IniFile: TFastiniFile;
Begin
 IniFile:=TFastiniFile.Create(Path+'chatdata.ini');
 Form1.ColorBox1.ColorValue:=IniFile.ReadInteger('layout','AC',ClBlack);
 Form1.BoldP.Checked:=IniFile.ReadBool('layout','B',False);
 Form1.UnderLineP.Checked:=IniFile.ReadBool('layout','U',False);
 Form1.ItalicP.Checked:=IniFile.ReadBool('layout','I',False);
 UserFontSize:=IniFile.ReadInteger('layout','UFS',10);
 Form10.RadioButton10.Checked:=IniFile.ReadBool('layout','NoFonts',False);
 Identitar:=IniFile.ReadString('layout','ident','');

 If Copy(Trim(LowerCaseRep(Identitar)),1,3)<>'ch\' Then
   Identitar:='CH\'+Identitar;
// If IniFile.ReadBool('layout','OnIdent',False)=True Then
//   Form1.On1.Click else  Form1.Off1.Click;
 Form1.spSkinCheckRadioBox1.Checked:=INiFile.ReadBool('layout','Fader',False);
 Form1.EnableAi1.Checked:=IniFile.ReadBool('Layout','AI',True);
 Form1.EnableSwearWordFilter1.Checked:=IniFile.ReadBool('Layout','SweardWordFilter',False);
 Form1.OtronTechnology1.Checked:=IniFile.ReadBool('Layout','OtronTechnology1',False);
 Form1.SpSkinFontComboBox1.FontName:=IniFile.ReadString('Layout','FontName','Arial');
 Form1.SpSkinComboBox2.Text:=IniFile.ReadString('layout','FontSize','10');
 Form10.CheckBox16.Checked:=IniFile.ReadBool('Layout','PmsFromFriends',False);
 Form18.CheckBox1.Checked:=IniFile.ReadBool('Layout','IggyEmote',False);
 Form18.CheckBox2.Checked:=IniFile.ReadBool('Layout','IggyEmote2',False);
 Form18.Edit2.Text:=IniFile.ReadString('Layout','IggyEmoteText','You have been ignored %s');
 Form18.Edit3.Text:=IniFile.ReadString('Layout','IggyEmoteText2','You have been removed from ignore %s');
 Form1.DingOnID1.Checked:=IniFile.ReadBool('Layout','DingOnID',False);
 Form10.Edit2.Text:=IniFile.ReadString('Layout','mp3dir','c:\mp3');
 Form10.SpinEdit1.Value:=IniFile.ReadInteger('Layout','FloodLevel',3);
 Form10.CheckBox2.Checked:=IniFile.ReadBool('Layout','YIDCheck',True);
 Form10.SpinEdit2.Value:=IniFile.ReadInteger('Layout','FloodMatch',85);
// Form10.SpinEdit3.Value:=IniFile.ReadInteger('Layout','CloneMatch',85);
 Form10.SpinEdit4.Value:=IniFile.ReadInteger('Layout','CustomFontSize',10);
 Form10.SpinEdit5.Value:=IniFile.ReadInteger('Layout','YID',4);
 Form10.SpinEdit7.Value:=IniFile.ReadInteger('Layout','MaxSmiley',7);
 Form10.Edit3.Text:=IniFile.ReadString('Layout','ProxyAdd','127.0.0.1');
 Form10.Edit4.Text:=IniFile.ReadString('Layout','ProxyPort','80');
 Form10.CheckBox3.Checked:=IniFile.ReadBool('Layout','ProxyEnabled',False);
 Form10.CheckBox6.Checked:=IniFile.ReadBool('Layout','AutoConnectS',True);
 Form10.CheckBox1.Checked:=IniFile.ReadBool('Layout','UseBrackets',False);
 Form10.ColorBox1.ColorValue:=IniFile.ReadInteger('Layout','YourIdColor',ClMaroon);
 Form10.ColorBox2.ColorValue:=IniFile.ReadInteger('Layout','ThierIdColor',ClGreen);
 Form10.CheckBox5.Checked:=IniFile.ReadBool('Layout','Cloneoutput',False);
 Form1.HotKeysEnabled1.Checked:=Not IniFile.ReadBool('Settings','HotKeys',True);
 Form1.HotKeysEnabled1.OnClick(Self);
 MaxLines:=INiFile.ReadInteger('Layout','MaxLines',300);
 If (MaxLines>600) Or (MaxLines<1) Then
   MaxLines:=200;
 Form10.Edit1.Text:=IntToStr(MaxLines);
// Form10.CheckBox4.Checked:=IniFile.ReadBool('Layout','RejectFirstUrl',True);
// Form10.Edit5.Text:=IniFile.ReadString('layout','FilterString','');

 FilterLevel:=IniFile.ReadInteger('layout','AntiFlood',4);

 If FilterLevel>5 Then
    FilterLevel:=4;

 Case FilterLevel of
     0: Form10.RadioButton8.Checked:=True;
     1: Form10.RadioButton5.Checked:=True;
     2: Form10.RadioButton4.Checked:=True;
     3: Form10.RadioButton3.Checked:=True;
     4: Form10.RadioButton13.Checked:=True;
    End;
  GpRoomName:=IniFile.ReadString('Layout','LastRoom','');
  // IniFile.WriteBool('Layout','IdentsOn',Form1.On1.Checked);
  Form1.On1.Checked:=IniFile.ReadBool('Layout','IdentsOn',True);
 SetRichedit2;
 IniFile.Free;
 Form1.LoadIniConfig;
End;


Function TForm1.TestForBot(S: String): Boolean;
Var
 P,EndP: Integer;
 LS: Integer;
Begin
  EndP:=Length(S);
  If (EndP<1) Or (EndP<4) Or (EndP>50) Then Exit;
  If Scanit('.',S)>=2 Then Exit;
  If Scanit('?',S)>=2 Then Exit;
  P:=PosRep('.',S);
  If P>1 Then
    If S[P-1]=' ' Then
      Exit;
  Ls:=LastCharPos2(' ',S,EndP);
  If (P>0) And (P<EndP) And (Ls>P) Then
   Begin
    Result:=True;
    Exit;
   End;
  P:=PosRep('?',S);
  If P>1 Then
    If S[P-1]=' ' Then
      Exit;
  If (P>0) And (P<EndP) And (Ls>P) Then
    Result:=True;
End;



Function ChatterSaidYourName(Chatter: String): boolean;
Var
 N2,N,R: Integer;
Begin
Result:=False;
 R:=-1;
 For N:=1 to High(Chatters) Do
  Begin
    if LowerCaseRep(Chatters[n].UserName)=LowerCaseRep(Chatter) Then
     Begin
      R:=N;
      Break;
     End;
  End;
  If R<>-1 Then
    Begin
      Result:=Chatters[r].SaidYourName;
    End;
End;


Function UserSaidYourName(Chatter: String): boolean;
Var
 N2,N,R: Integer;
Begin
Result:=True;
 R:=-1;
 For N:=1 to High(Chatters) Do
  Begin
    if LowerCaseRep(Chatters[n].UserName)=LowerCaseRep(Chatter) Then
     Begin
      R:=N;
      Break;
     End;
  End;
  If R<>-1 Then
    Begin
      Chatters[r].SaidYourName:=True;
    End
     else
    Begin
      R:=CreateChatter(Chatter,'');
      Chatters[r].SaidYourName:=True;
    End;
End;


Function TForm1.LastString(Chatter,LastStr: String): Boolean;
Var
 N2,N,R: Integer;
 ResblockH: Real;
Begin
  If LowercaseRep(LastThingSaid)=LowerCaseRep(LastStr) Then
    Begin
      Result:=False;
      Exit;
    End;
Result:=True;
 R:=-1;
 For N:=1 to High(Chatters) Do
  Begin
    if Chatters[n].UserName=Chatter Then
     Begin
      R:=N;
      Break;
     End;
  End;
  If R<>-1 Then
    Begin
      For N2:=1 to FilterLevel do
       Begin
        If LowerCaseRep(LastStr)=LowerCaseRep(Chatters[R].LastThingsSaid[N2]) Then
         Result:=False;
           //bug filter
        End;
   //      MatchStr(
    ResBlockH:=0;
       For N2:=1 to FilterLevel do
       Begin
        ResBlock:=MatchStr(Pchar(LowerCaseRep(LastStr)),Pchar(LowerCaseRep(Chatters[R].LastThingsSaid[N2])));
          If ResBlock>=Form10.SpinEdit2.Value Then
           Begin
             Result:=False;
             If ResBlock>ResBlockH Then
               ResBlockH:=ResBlock;
            // Break;
           End;
        End;
      ResBlock:=ResBlockH;
   //
       End
     else
    CreateChatter(Chatter,'');
End;

Procedure ChangeLastString(Chatter,Str: String);
Var
 N,R: Integer;
Begin
 R:=-1;
 For N:=1 to High(Chatters) Do
  Begin
    if Chatters[n].UserName=Chatter Then
     Begin
      R:=N;
      Break;
     End;
  End;
  If R<>-1 Then
   Begin
    Inc(Chatters[R].PostNum);
    If Chatters[R].PostNum>FilterLevel Then
      Chatters[R].PostNum:=1;
    Chatters[R].LastThingsSaid[Chatters[R].PostNum]:=Str
   End
     else
    CreateChatter(Chatter,'');
End;


Procedure ChangeLastPost(Chatter: String);
Var
 N,R: Integer;
Begin
 R:=-1;
 For N:=1 to High(Chatters) Do
  Begin
    if Chatters[n].UserName=Chatter Then
     Begin
      R:=N;
      Break;
     End;
  End;
  If R<>-1 Then
   Begin
    Chatters[R].LastPost:=now;
   End
     else
    CreateChatter(Chatter,'');
End;

Function Tform1.ChatterNum2(Chatter: String): Integer;
Var
 N,R: Integer;
Begin
 R:=-1;
 For N:=1 to High(Chatters) Do
  Begin
    if LowerCaseRep(Chatters[n].UserName)=LowerCaseRep(Chatter) Then
     Begin
      R:=N;
      Break;
     End;
  End;
   Result:=R;
End;

Function Tform1.ChatterNum(Chatter: String): Integer;
Var
 N,R: Integer;
Begin
 R:=-1;
 For N:=1 to High(Chatters) Do
  Begin
    if LowerCaseRep(Chatters[n].UserName)=LowerCaseRep(Chatter) Then
     Begin
      R:=N;
      Break;
     End;
  End;
  If R=-1 Then
   Begin
    CreateChatter(Chatter,'');
    Result:=Form1.ChatterNum(Chatter);
   End
    else
   Result:=R;
End;

Function GetLastPost(Chatter: String): TdateTime;
Var
 N,R: Integer;
Begin
 R:=-1;
 For N:=1 to High(Chatters) Do
  Begin
    if Chatters[n].UserName=Chatter Then
     Begin
      R:=N;
      Break;
     End;
  End;
  If R<>-1 Then
   Begin
    Result:=Chatters[R].LastPost;
   End
     else
    CreateChatter(Chatter,'');
End;

Function ChatterJoined(Chatter: String): TdateTime;
Var
 N,R: Integer;
Begin
 R:=-1;
 For N:=1 to High(Chatters) Do
  Begin
    if Chatters[n].UserName=Chatter Then
     Begin
      R:=N;
      Break;
     End;
  End;
  If R<>-1 Then
   Begin
    Result:=Chatters[R].Joined;
   End
     else
    CreateChatter(Chatter,'');
End;


Procedure DeleteChatter(Chatter: String);
Var
 N2,N,R: Integer;
Begin
 R:=-1;
 For N:=1 to High(Chatters) Do
  Begin
    if LowerCaseRep(Chatters[n].UserName)=LowerCaseRep(Chatter) Then
     Begin
      R:=N;
      Break;
     End;
  End;
  If R<>-1 Then
   Begin
//     DeleteCustomName(Chatters[R].UserName);
     FillChar(Chatters[R],SizeOf(Chatters[R]),#0);
   End;
End;

Procedure Tform1.ClearMessages;
Var
 N2,N: Integer;
Begin
{ If FriendsAliasesLookUp<>Nil Then
   FriendsAliasesLookUp.Clear;}
 // FillChar(Chatters,SizeOf(Chatters),0);
  SetLEngth(Chatters,2);
End;


Procedure Tform1.ClearSaidYourName;
Var
 N2,N: Integer;
Begin
 For N:=1 to High(Chatters) Do
    Chatters[n].SaidYourName:=False;
End;


Function Tform1.RemoveTags(Str: String): String;
Var
 Tmp,BuildStr: String;
Begin
// BuildStr:=RemoveStr('hello <aba> </aba> <aba>','<aba>');
  BuildStr:='';

  Tmp:=Form1.ExtractBetweenString2('<#','>',Str,True);
  If Tmp<>'' Then
   Begin
    Str:=Form1.Remove2(Str,'<#','>');
    BuildStr:=BuildStr+Ycustom+'#'+Tmp;
   End;

  If PosRep('<gray>',LowerCaseRep(Str))>0 Then
   Begin Str:=RemoveStr('<gray>',Str); Str:=RemoveStr('</gray>',Str); BuildStr:=BuildStr+Ygray; End;


  If PosRep('<grey>',LowerCaseRep(Str))>0 Then
   Begin Str:=RemoveStr('<grey>',Str); Str:=RemoveStr('</gray>',Str); BuildStr:=BuildStr+Ygray; End;


  If PosRep('<pink>',LowerCaseRep(Str))>0 Then
   Begin Str:=RemoveStr('<pink>',Str); Str:=RemoveStr('</pink>',Str); BuildStr:=BuildStr+Ypink; End;

  If PosRep('<red>',LowerCaseRep(Str))>0 Then
   Begin Str:=RemoveStr('<red>',Str); Str:=RemoveStr('</red>',Str); BuildStr:=BuildStr+YRed; End;

  If PosRep('<blue>',LowerCaseRep(Str))>0 Then
   Begin Str:=RemoveStr('<blue>',Str); Str:=RemoveStr('</blue>',Str); BuildStr:=BuildStr+YBlue; End;

  If PosRep('<green>',LowerCaseRep(Str))>0 Then
   Begin Str:=RemoveStr('<green>',Str); Str:=RemoveStr('</green>',Str); BuildStr:=BuildStr+Ygreen; End;

  If PosRep('<purple>',LowerCaseRep(Str))>0 Then
   Begin Str:=RemoveStr('<purple>',Str); Str:=RemoveStr('</purple>',Str); BuildStr:=BuildStr+YPurple; End;

  If PosRep('<lime>',LowerCaseRep(Str))>0 Then
   Begin Str:=RemoveStr('<lime>',Str); Str:=RemoveStr('</lime>',Str); BuildStr:=BuildStr+Ylime; End;

  If PosRep('<red>',LowerCaseRep(Str))>0 Then
   Begin Str:=RemoveStr('<red>',Str); Str:=RemoveStr('</red>',Str); BuildStr:=BuildStr+YRed; End;

  If PosRep('<black>',LowerCaseRep(Str))>0 Then
   Begin Str:=RemoveStr('<black>',Str); Str:=RemoveStr('</Black>',Str); BuildStr:=BuildStr+YBlack; End;

  If PosRep('<cyan>',LowerCaseRep(Str))>0 Then
   Begin Str:=RemoveStr('<cyan>',Str); Str:=RemoveStr('</cyan>',Str); BuildStr:=BuildStr+Ycyan; End;

  If PosRep('<orange>',LowerCaseRep(Str))>0 Then
   Begin Str:=RemoveStr('<orange>',Str); Str:=RemoveStr('</orange>',Str); BuildStr:=BuildStr+Yorange; End;

  If PosRep('<green>',LowerCaseRep(Str))>0 Then
   Begin Str:=RemoveStr('<green>',Str); Str:=RemoveStr('</green>',Str); BuildStr:=BuildStr+Ygreen; End;

  If PosRep('<yellow>',LowerCaseRep(Str))>0 Then
   Begin Str:=RemoveStr('<yellow>',Str); Str:=RemoveStr('</green>',Str); BuildStr:=BuildStr; End;

  If PosRep('<b>',LowerCaseRep(Str))>0 Then
   Begin Str:=RemoveStr('<b>',Str); Str:=RemoveStr('</b>',Str); BuildStr:=BuildStr+Ybold; End;

  If PosRep('<i>',LowerCaseRep(Str))>0 Then
   Begin Str:=RemoveStr('<i>',Str); Str:=RemoveStr('</i>',Str); BuildStr:=BuildStr+Yitalic; End;

  If PosRep('<u>',LowerCaseRep(Str))>0 Then
   Begin Str:=RemoveStr('<u>',Str); Str:=RemoveStr('</u>',Str); BuildStr:=BuildStr+Yun; End;

  If PosRep('</font>',LowerCaseRep(Str))>0 Then
   Str:=RemoveStr('</font>',Str);

 TagText:=BuildStr;
 Result:=TagText+Str;
End;


Function Tform1.GetFriends: String;
Var
 N: Integer;
 Obj: Tobject;
 BuildStr: string;
Begin
    For n:=Form1.ListBox1.Items.count-1 downto 0 do
      Begin
       If Friends.Find(Form1.ListBox1.Items[N],Obj)=True Then
          BuildStr:=BuildStr+Form1.customizename(Form1.ListBox1.Items[N])+', ';
      End;
     BuildStr:=Copy(BuildStr,1,Length(BuildStr)-2);
     Result:=BuildStr;
End;

Function MyBeep(P: Pointer): Longint; StdCall;
Begin
 Beep;
End;

Function Flasher(P: Pointer): Longint; StdCall;
Begin
 IF IsIconic(Application.Handle) Then
  Begin
   FlashWindow(Application.Handle,True);
   Sleep(1000);
   FlashWindow(Application.Handle,False);
 End;
End;

Function Tform1.DoHtmlColTag(RichCont: TMyRichedit; S: String): String;
Var
 Tmp,Tmp2: String;
 P1,P2: Integer;
Begin
//#$1B[#00c000m
// <#904c42>      s
 P1:=PosRep('<#',S);
 P2:=PosRep('>',S);
 Result:=S;
  If (P1>0) and (P2>0) Then
   If P2>P1 Then
      Result:=Form1.Remove2(Result,'<#','>');
End;

Function IsHiddenTextBot(Str: String): Boolean;
Var
 Tmp: String;
 P: Integer;
Begin
  Result:=False;
  P:=PosRep('[#ffffffm',Str);
  If P>0 Then
   Begin
    Delete(Str,1,P-1);
     IF PosRep(' ',Str)=0 Then
       Result:=True;
    End; 
End;

Function CopyToDefined(Str: String; Strt: Integer): String;
Var
 Tmp: String;
 P,P2: Integer;
 C: Char;
Begin
 Result:='';
 IF Str='' Then
   Exit;
 Delete(Str,1,Strt);
 Tmp:=Str;
 P:=1;
 While (P<Length(Str)) do
   Begin
    C:=Str[P];
    IF (C=' ') Or (C='!') Then
     Begin
      Result:=Copy(Tmp,1,P-1);
      Exit;
     End;
    Inc(P);
   End;
End;

Function IsAa1BotText(ID,Str: String): Boolean;
Var
 Tmp2,Tmp: String;
 N2,N,P: Integer;
Begin
 Id:=LowerCaseRep(ID);
 Str:=LowerCaseRep(Id);
 Result:=False;
 Tmp:=' '+Copy(ID,1,3);
 P:=PosRep(Tmp,Str);
 If P>0 Then
   Begin
     Tmp2:=CopyToDefined(Str,P);
     If Tmp2<>'' Then
       If PosRep(Tmp2,ID)>0 Then
          Begin
           Result:=True;
           Exit;
          End;
    End;
End;

{Function IsAa1BotText(ID,Str: String): Boolean;
Var
 Tmp: String;
 N2,N,P: Integer;
Begin
 Result:=False;
  For N2:=1 to 2 do
  Begin
    For N:=0 to 3 do
    Begin
      If N2=1 Then
        Tmp:=' '+Copy(ID,1,4+N)+'!';
       If N2=2 Then
        Tmp:=' '+Copy(ID,1,4+N)+' ';
       IF PosRep(Tmp,Str)>0 Then
         Begin
          Result:=True;
          Exit;
         End;
      End;
    End;
End;}


Function StripFeFeFe(Str: String): String;
Var
 P: Integer;
 C,N: Integer;
 Tmp2,Tmp: String;
Begin
 Result:=Str;
  While PosRep('[#fefefem',Result)>0 do
    Result:=Form1.MyRemove(Result,'[#fefefem');
  While PosRep('[#ffffffm',Result)>0 do
    Result:=Form1.MyRemove(Result,'[#ffffffm');
End;


Procedure Tform1.RtFPatch(Var Msg: String);
Var
 P1: Integer;
Begin
  P1:=1;
  While P1>0 Do
  Begin
   P1:=PosRep('\rtf',LowerCaseRep(Msg));
     If P1>0 then
       Msg[P1]:='/';
   End;
End;

Procedure Tform1.DisplayUsername(RichCont: TRichedit; Fromwho: String; Emote: Boolean; PRoomName: String);
Var
 Buddy: Boolean;
Begin
    RichCont.SelAttributes.Name:='Arial';
    RichCont.SelAttributes.Style:=[FsBold];
    //RichCont.Lines.Add(FromWho+': '+Msg);

    If ChatterSaidYourName(LowerCaseRep(FromWho))=True Then
     Begin
       If Form10.CheckBox42.Checked=True Then
        Begin
         Form1.DoRtfFace(RichCont,'alertava.');
         RichCont.SelAttributes.Style:=[FsBold];
         RichCont.SelAttributes.Name:='Arial';
        End;
     //  RE_SetCharFormat(RichEdit1, CFU_UNDERLINETHICK);
       RichCont.SelAttributes.Color:=Form10.ColorBox3.ColorValue;
     End
   else
   Begin
    If  Form1.IsBuddy(FromWho)=True Then
     RichCont.SelAttributes.Color:=Form10.ColorBox4.ColorValue
      else
     RichCont.SelAttributes.Color:=Form10.ColorBox2.ColorValue;
   End;


{   If PornBotTracker.CheckBot(UserName)=True Then
     Begin
      //PornBot
      RichCont.SelAttributes.Style:=RichCont.SelAttributes.Style+[fsUnderline];
      RichCont.SelAttributes.Color:=clFuchsia;
     End;}

   If Form1.IsBuddy(FromWho)=True Then
     Begin
      RichCont.SelAttributes.Style:=RichCont.SelAttributes.Style+[FsItalic];
      Buddy:=True;
     End
      else
     Buddy:=False;
//      RichCont.SelText:='('+Form1.ChattersNick(LoginName)+')'+LoginName;

/// here

{  If Chatters[Form1.ChatterNum(FromWho)].UcaseUsed=True Then
    FromWho:=Form1.DwordToUsername(Chatters[Form1.ChatterNum(FromWho)].UCaseV,FromWho);}
     //binary uppercase inf tag

    If Chatters[Form1.ChatterNum(FromWho)].ChatClient='Y!mLite' then
     Begin
    {  if Form1.ChattersNick(FromWho)<>'' Then
         RichCont.SelText:='('+Form1.ChattersNick(FromWho)+') '+FromWho+'*'
          else}
          If (Form10.CheckBox40.Checked=True) And (Form1.Scanit('$',Chatters[Form1.ChatterNum(FromWho)].ColIDStr)=1) And (Chatters[Form1.ChatterNum(FromWho)].ColIDStr<>'$0') Then
           Begin
            RichCont.SelAttributes.Color:=StrToInt(Chatters[Form1.ChatterNum(FromWho)].ColIDStr);
            RichCont.SelText:=FromWho+'*';
           End
            else
           RichCont.SelText:=FromWho+'*';
      End
       else
     Begin
{      if Form1.ChattersNick(FromWho)<>'' Then
        RichCont.SelText:='('+Form1.ChattersNick(FromWho)+') '+FromWho
         else}
        If (Form10.CheckBox40.Checked=True) And (Form1.Scanit('$',Chatters[Form1.ChatterNum(FromWho)].ColIDStr)=1) Then
         Begin
          RichCont.SelAttributes.Color:=StrToInt(Chatters[Form1.ChatterNum(FromWho)].ColIDStr);
          RichCont.SelText:=FromWho+'*';
         End
          else
         RichCont.SelText:=FromWho;
     End;


    RE_SetCharFormat(RichCont, CFU_UNDERLINENONE);
    RichCont.SelAttributes.Color:=ClBlack;
    RichCont.SelAttributes.Style:=[];

    If Emote=False Then
      RichCont.SelText:=': '
       else
      RichCont.SelText:=' ';
    {If PRoomName<>BckRoomName Then
         RichCont.SelText:='['+RoomName+'] ';}
    RichCont.SelAttributes.Size:=FontSizeTag;

    If Form10.CheckBox28.Checked=True Then
      RichCont.SelText:='['+DateTimeToStr(Now)+'] ';
End;

Procedure TForm1.ChatP(RichCont: TMyRichedit; S,Username,RoomName2,YchtMsg: String; YCHT, EmoteP: Boolean);
Var
  Dealt,NotSaidBefore,FadeRoutine: Boolean;
  CCSound,EmoteT,PlainText,LM,Stars,Url,MsgYCHT,Msg3,Msg2,Msg4,Code,Code2,FromWho,Msg,Tmp: String;
  Buddy,Emote, ScrState: Boolean;
  N3,NumP,N2,N: integer;
  Th2,th: THandle;
  TF: TextFile;
  IdTagTmp: String;
  TS,TE: Longint;
  Res: Real;
  Obj: Tobject;
  Version,EncKey: Integer;
  TheWord: Tstruct;
  F: TStringStream;
  FNS,RoomName,RoomName3,FullStr,MsgTime,ChatClient: String;
  TmpS: String;
  Anonomyly: String;
  uf: TUserFields2;
  EStr,Str: String;
  P2,P1: Integer;
  Enc: TEncrypt;
Begin
 TmpS:=S;
 Form1.ScrollToEnd(Form1.Richedit1);
 RichCont.SelStart:=-1;

 If Ycht=False Then
  Begin
   Code:=S[20];
   Tmp:=S;
   Delete(S,1,20);
   Uf:=TUserFields2.Create;
   Uf.SplitFields(S);
   FromWho:=Uf.GetField('109');
   FromWho:=Trim(FromWho);
   RoomName:=Uf.GetField('104');
   Msg:=Uf.GetField('117');
   EmoteT:=Uf.GetField('124');
   Uf.Free;
   If Trim(EmoteT)<>'' Then
    Begin
    If EmoteT[1]='1' Then
     Emote:=False;
   If EmoteT[1]='2' Then
     Emote:=True;
   If EmoteT[1]='3' Then
     Emote:=True;
    Delete(EmoteT,1,1);
     End;

   End
   else
  Begin
   FromWho:=UserName;
   Msg:=YchtMsg;
   RoomName:=RoomName2;
  End;

 Chatters[Form1.ChatterNum(FromWho)].DebugStr:=TmpS;
 Chatters[Form1.ChatterNum(FromWho)].CustomData:='';




 PlainText:=StripFeFeFe(Msg);
 PlainText:=Remove(PlainText,#$1B,'m');
 PlainText:=ReplaceStr(PlainText,#$0D+#$0A,' ');
 PlainText:=Form1.Remove2(PlainText,'<fade','>');
 PlainText:=Form1.Remove2(PlainText,'<font','>');
 PlainText:=Form1.Remove2(PlainText,'<alt','>');
 PlainText:=Form1.Remove2(PlainText,'</','>');
 PlainText:=Form1.Remove2(PlainText,'<#','>');
 PlainText:=Form1.Remove2(PlainText,'<b','>');
 PlainText:=Form1.MyRemove(PlainText,'ï»');
 PlainText:=Form1.RemoveTags(PlainText);
// PlainText:=Trim(Form1.Remove2(PlainText,'<','>'));
 If FullDuplex=True Then
   Form1.SendExtCmd(Fromwho+': '+PlainText);

  RoomName3:=Chatters[Form1.ChatterNum(LoggedInName)].RoomName;

{ IF (LowerCaseRep(RoomName)<>LowerCaseRep(RoomName3)) and (LoggedInName<>FromWho) Then
  Begin
   Form1.Panel10.Caption:='Rogue Chat Packet ('+RoomName+') - '+FromWho+': '+PlainText+' ;
   AddBlockMessage(Form1.Panel10.Caption);
    IF Form1.ChatterNum2(FromWho)<>-1 Then
        DeleteChatter(FromWho);
   Exit;
  End;}


  If Form10.CheckBox23.Checked=True Then
    Form1.WriteLogData(FromWho,'',PlainText,True);

//when yahoo gets hacked again!r




  If (Form10.CheckBox46.Checked=True) Then
    If (PlainText<>'') And (Length(PlainText)>8) And (PosRep('yahoo.com',PlainText)=0) Then
      If PornBotTracker.ChatP(FromWho,Trim(PlainText))=True Then
         Exit;


 If FromWho='Yahoo' Then
  Begin
    If Pos('verify',PlainText)>0 Then
     Begin
      Form1.Richedit1.SelAttributes.Color:=ClRed;
      Form1.Richedit1.SelText:='You must Verify The Captcha Code First..';
      Form1.Richedit1.SelAttributes.Color:=ClBlack;
      SendMessage(Form1.Handle,Wm_User+115,0,0);
      Form1.Richedit1.Lines.Add('');
 //     ShellExecute(Form1.Handle,'open',Pchar(Form1.GetURL(PlainText,False)),'','',0);
//      Form1.Richedit1.Lines.Add(PlainText);
      End
      else
    Begin
      Form1.Richedit1.SelAttributes.Color:=ClRed;
      Form1.Richedit1.SelText:=PlainText;
      Form1.Richedit1.Lines.Add('');
     End;
     Form1.Richedit1.SelAttributes.Color:=ClBlack;
     BufferRichedit(Form1.Richedit1,0);
     Form1.ScrollToEnd(Form1.Richedit1);
     Exit;
  End;

IF IsUserIgnored(FromWho)=True Then
   Exit;

  If Form10.CheckBox37.Checked=True Then
    If PosRep('yahoo.com/'+fromWho,LowerCaseRep(PlainText))>0 Then
     Begin
      Form1.Panel10.Caption:=FromWho+' Ignored for being a "Profile Spam Bot" Msg: '+plainText;
      AddBlockMessage(Form1.Panel10.Caption);
      Form1.IgnoreUser(FromWho,false,True,True,False);
      Exit;
     End;

 RtfPatch(Msg);

// Form1.ReplaceStr(Msg,'\rtf','/rtf');
// ReplaceStr(TmpFstr,'<username>',Yred+UserName+Yblue);

 If  Form10.CheckBox36.Checked=True Then
    If (Form1.ScanIt('[#fefefe',LowerCaseRep(Msg))>=2) Or (Form1.ScanIt('[#ffffff',LowerCaseRep(Msg))>=2) Then
     Begin
       Form1.Panel10.Caption:=FromWho+' Has been ignored and detected as a Love room Spam Bot  '+PlainText;
       AddBlockMessage(Form1.Panel10.Caption);
       Form1.IgnoreUser(FromWho,false,True,True,False);
     End;

  If Form10.HiddenTextBot.Checked=True Then
      If IsHiddenTextBot(LowerCaseRep(Msg))=True Then
        Begin
         Form1.Panel10.Caption:=FromWho+' Has been ignored and detected as a Spam Bot (Hidden Text Filter) '+PlainText;
         AddBlockMessage(Form1.Panel10.Caption);
         Form1.IgnoreUser(FromWho,false,True,True,False);
        End;


    If Form10.aa1BotFilter.Checked=True Then
     If Chatters[Form1.ChatterNum(FromWho)].NumLinesPosted=0 Then
       If IsAa1BotText(FromWho,LowerCaseRep(Msg))=True Then
        Begin
         Form1.Panel10.Caption:=FromWho+': '+PLainText+' Has been ignored and detected as an aa1 spam bot...';
         AddBlockMessage(Form1.Panel10.Caption);
         Form1.IgnoreUser(FromWho,false,True,True,False);
        End;



  If Form10.CheckBox47.Checked=True Then
    If PosRep('{Auto Ignore}',PlainText)>0 Then
     Begin
      Form1.Panel10.Caption:=FromWho+'''s Auto Ignore Emote Rejected Msg: '+plainText;
      AddBlockMessage(Form1.Panel10.Caption);
      Exit;
     End;


  If Trim(PlainText)='' Then
   Begin
     Form1.Panel10.Caption:=FromWho+': '+PlainText+' Blocked For Flooding';
     AddBlockMessage(Form1.Panel10.Caption);
     Exit;
   End;


{ If Form1.CosyChat1.Checked=True Then
   If Friends.IndexOf(FromWho)=-1 Then
       Exit;}

If (Form10.CheckBox14.Checked=True) and (friends.Find(FromWho,Obj)=False) Then
 If Trim(Form1.GetUrl(PlainText,False))<>'' Then
  Begin
   If Chatters[Form1.ChatterNum(FromWho)].NumLinesPosted=0 Then
    Begin
     Inc(Chatters[Form1.ChatterNum(FromWho)].TotalBlock,1);
     Inc(Chatters[Form1.ChatterNum(FromWho)].BlockCount,1);
     If (Chatters[Form1.ChatterNum(FromWho)].BlockCount>=Form10.SpinEdit8.Value) Or (Form10.CheckBox14.Checked=True) Then
      Begin
       Form1.Panel10.Caption:=FromWho+' Has been ignored for posting on First Post URL  '+PlainText;
       AddBlockMessage(Form1.Panel10.Caption);
       Form1.IgnoreUser(FromWho,false,True,True,False);
      End;
     Exit;
   End;
 End;

Inc(Chatters[Form1.ChatterNum(FromWho)].NumLinesPosted,1);


// If LowerCaseRep(RoomName)=LowerCaseRep(Chatters[Form1.ChatterNum(LoggedInName)].RoomName) Then
 // Begin
 If trim(fromwho)<>'' then
 If (Form1.ListBox1.Items.IndexOf(FromWho)=-1) and (Form1.ListBox2.Items.IndexOf(FromWho)=-1) Then
  Begin
    If (IsUserIgnored(FromWho)=False) Then
     Begin
      Form1.ListBox1.Items.Add(FromWho);
      Inc(Users);
      CreateChatter(FromWho,'');
      Form1.SpSkinScrollPanel1.Caption:='Users: '+IntToStr(Users);
     End
 else
    If Form1.ListBox2.Items.IndexOf(FromWho)=-1 Then
     Begin
       Form1.ListBox2.Items.Add(FromWho);
       Inc(Users);
       CreateChatter(FromWho,'');
       Form1.SpSkinScrollPanel1.Caption:='Users: '+IntToStr(Users);
     End;
  End;


// Msg:=Form1.ExtractPacketDetails(S,'117');


 If Ycht=True Then
   Msg:=YCHTMSG;
 // Chatters[form1.ChatterNum(FromWho)].ChatClient:='';
 Form1.Caption:='Y!mLite - '+LoggedinName+' You Are In: '+RoomName;

  FontSizeTag:=10;
  TagText:='';  AltTagText:='';  FadeTagText:='';
  AltTag:='';  AltWTag:='';  AltWTagText:='';
  AltWin:=False;  FadeTag:='';  AltIDTag:='';
  AltIn:=False;  FadeIn:=False;  FontFaceTag:='';
  TagText:='';  ChatClient:='';  SmileyCount:=0;
  FontFaceTag:='Arial';

  ResBlock:=0;
  Msg:=YmLiteLogoStr(Msg);
 If Length(Msg)>0 Then
  Begin
   Msg:=Form1.RemoveTags(Msg);
   Msg3:=Msg;
   //<font face=" , <font size=" ,
//   Msg:=DoFontTag(Msg);
   Dealt:=False;

  // PlainText:=Remove(Msg,'<','>');
  If Length(PlainText)>=1 Then
   Begin
    For n:=1 to length(PlainText) do
      If PlainText[n] in ['<','>'] Then
        PlainText[N]:=' ';
   End
    else
   Begin
     Form1.Panel10.Caption:=FromWho+': '+PlainText+' Blocked For Flooding';
     AddBlockMessage(Form1.Panel10.Caption);
     Exit;
   End;

If (form10.CheckBox11.Checked=True) And (NeverIgnore.IndexOf(FromWho)=-1) Then
 Begin
  S:=Form10.Edit5.Text;
  For N:=1 to Form1.Scanit(',',S)+1 Do
   Begin
    If PosRep(',',S)>0 Then
    Tmp:=Trim(Copy(S,1,PosRep(',',S)-1))
     else
    Tmp:=S;
    If PosRep(',',S)>0 Then
      Delete(S,1,Length(Tmp)+1);
    If Trim(Tmp)<>'' Then
     If PosRep(LowerCaseRep(Tmp),LowerCaseRep(PlainText))>0 Then
      Begin
        Form1.IgnoreUser(FromWho,false,true,True,False);
        Form1.Panel10.Caption:=Fromwho+': Ignored for saying "'+Plaintext+'" which contained "'+tmp+'"';
        AddBlockMessage(Form1.Panel10.Caption);
      End;
   End;
 End;

   Msg:=DoIDTag(Msg,FromWho);   //alt id=Y!mLite>....>


 If Form10.CheckBox44.Checked=True Then
 If Chatters[Form1.ChatterNum(FromWho)].ChatClient='YahElite' Then
   Begin
    Version:=0;
    Try
      Version:=StrToInt(Chatters[Form1.ChatterNum(FromWho)].Version);
     Except
      Version:=0;
     End;
      If Version<>0 Then
       If Version<=306 Then
         Begin
           Form1.Panel10.Caption:=FromWho+': '+PlainText+' Ignored for being a Yahelite Porn Bot';
           AddBlockMessage(Form1.Panel10.Caption);
           Form1.IgnoreUser(FromWho,false,True,True,False);
           Exit;
         End;
     End;


   If ValidText(PlainText,FromWho)=False Then
    Begin
       Inc(Chatters[Form1.ChatterNum(FromWho)].BlockCount,1);
       Inc(Chatters[Form1.ChatterNum(FromWho)].TotalBlock,1);
       Chatters[Form1.ChatterNum(FromWho)].LastBlock:=TimeToStr(Now);
        If Form10.CheckBox8.Checked=true Then
         If Chatters[Form1.ChatterNum(FromWho)].BlockCount>=Form10.SpinEdit8.Value Then
          Begin
           Form1.IgnoreUser(FromWho,false,True,True,False);
          End;
       Form1.DoStats(FromWho);
       Form1.Panel10.Caption:=FromWho+': '+PlainText+' Blocked For Flooding '+IntToStr(Chatters[Form1.ChatterNum(FromWho)].BlockCount);
       AddBlockMessage(Form1.Panel10.Caption);
       Exit;
    End;

//   Chatters[Form1.ChatterNum(FromWho)].CustomData:=ExtraInfo(FromWho);


   IdTagTmp:=LowerCaseRep(Chatters[ChatterNum(FromWho)].ChatClient);
   If (Form10.CheckBox24.Checked=True) and (Trim(IdTagTmp)<>'') Then
    Begin
     S:=LowerCaseRep(Form10.Edit11.Text);
     For N:=1 to Form1.Scanit(',',S)+1 Do
     Begin
      If PosRep(',',S)>0 Then
      Tmp:=Trim(Copy(S,1,PosRep(',',S)-1))
       else
      Tmp:=S;
      If PosRep(',',S)>0 Then
        Delete(S,1,Length(Tmp)+1);
      If Trim(Tmp)<>'' Then
        If Tmp=IdTagTmp Then
          Begin
            Form1.IgnoreUser(FromWho,False,True,True,False);
            Form1.Panel10.Caption:=FromWho+': Ignored for using an ID tag of '+Tmp;
            AddBlockMessage(Form1.Panel10.Caption);
            Exit;
          End;
      End;
    End;


 If (Form10.CheckBox50.Checked=True) And (CCInstalled=True) Then
    Begin
 //       Form1.ExtractBetweenString('<','>',FullStr,True);
      If CCinstalled=True Then
        Begin
         If PosRep('<aud="',Msg)>0 Then
          Begin
           CCsound:=Form1.ExtractBetweenString('<aud="','">',Msg,True);
           CCsound:='c:\program files\cheetachat\sounds\'+CCsound+'.wav';
           If FileExists(CCsound) Then
              StartSound(CCsound,True,False);
//           <aud="yahoo"> (Yahoo)
           End;
        End;
     End;

  Msg:=ReplaceStr(Msg,#$0D+#$0A,' ');
  Msg:=RemoveDoubleSpaces(Msg);


    NotSaidBefore:=True;
   //
      NotSaidBefore:=Form1.LastString(FromWho,Trim(LowerCaseRep(PlainText)));
      ChangeLastString(FromWho,LowerCaseRep(Trim(PlainText)));
      ChangeLastPost(FromWho);
     //on said your ID!
     If NotSaidBefore=False Then
      Begin
       Inc(Chatters[Form1.ChatterNum(FromWho)].BlockCount,1);
       Inc(Chatters[Form1.ChatterNum(FromWho)].TotalBlock,1);
       If ResBlock<>0 Then
       Form1.Panel10.Caption:=FromWho+': '+PlainText+' Blocked for Repeated Posts '+IntToStr(Trunc(ResBlock))+'% Match '
        else
       Form1.Panel10.Caption:=FromWho+': '+PlainText+' Blocked for Repeated Posts ';
       AddBlockMessage(Form1.Panel10.Caption);
       If Form10.CheckBox8.Checked=true Then
        Begin
         N3:=Chatters[Form1.ChatterNum(FromWho)].BlockCount;
         If N3>=Form10.SpinEdit8.Value Then
         Begin
          Form1.IgnoreUser(FromWho,false,True,True,False);
         End;
       Exit;
       End;
      End
      else
    Chatters[Form1.ChatterNum(FromWho)].BlockCount:=0;


     If MilliSecondsBetween(LastChatP,Now)<200 Then
        BufferRichedit(Form1.Richedit1,100);
 {    begin
       DisplayUsername(Form1.Richedit1,FromWho,Emote);
       Richedit1.SelText:=PlainText;
       Richedit1.Lines.Add('');
       BufferRichedit(Form1.Richedit1,100);
       Form1.ScrollToEnd(Form1.Richedit1);
       Exit;
     End; }


  If (IsUserIgnored(FromWho)=False) Then
   If (PosRep(LowerCaseRep(LoggedInName),LowerCaseRep(PlainText))>0) Or (PosRep(LowerCaseRep(CustomizeName(LowerCaseRep(LoggedInName))),LowerCaseRep(Msg))>0) Then
    Begin
     Dealt:=True;
     If Form1.DingOnID1.Checked=True Then
      CreateThread(Nil,0,@MyBeep,Nil,0,Th);
      // MyBeep;
   //  CreateThread(Nil,0,@Flasher,Nil,0,Th2);
     UserSaidYourName(FromWho);
     MsgTime:=FromWho+' @ '+DateTimeToStr(Now);
     Form25.ListBox1.Items.Add(MsgTime);
     Nump:=Form25.ListBox1.Items.IndexOf(MsgTime);

    If Nump<>-1 Then
     Begin
      SetLength(SaidYourName,Nump+1);
      SaidYourName[NumP].When:=Now;
      SaidYourName[NumP].Who:=FromWho;
      SaidYourName[Nump].What:=PlainText;
//      SaidYourName[Nump].What:=Remove(SaidYourName[Nump].What,'<','>');
//      SaidYourName[Nump].What:=Remove(SaidYourName[Nump].What,#$1B,'m');
      If (Form25.ListBox1.Items.Count>=Form10.SpinEdit5.Value) and (Form10.CheckBox2.Checked=True) Then
       Begin
        Form1.CreateSkin(Form25);
        Form25.Show;
        Form1.RichEdit2.SetFocus;
       End;
     End;
    End;


  Str:=Msg;
  P1:=PosRep('[yurl]',Str);
  If P1>0 Then
  Begin
    If Enc<>Nil Then Enc:=TEncrypt.Create;
    P2:=PosRep('[/yurl]',Str);
    If (P1>0) and (P2>0) and (P2>P1) Then
     Begin
      Delete(Str,1,PosRep(']',Str));
      Str:=Copy(Str,1,PosRep('[/yurl]',Str)-1);
     End;
     EStr:='[yurl]'+Str+'[/yurl]';
     Str:=Enc.DecryptStr(Str);
     Msg:=ReplaceStr(Msg,EStr,Str);
     Enc.Free;
   End;

    If DidUserSwear(Msg)=True Then
    Begin
    If Form1.GirlyFilter1.Enabled=True Then
      If GirlyFilter.PersonalityLoaded=True Then
       Begin
        Tmp:=PlainText;
        Tmp:=GirlyFilter.TextToPersonality(Tmp);
        Msg:=Form1.ReplaceStr(Msg,PlainText,Tmp);
       End;



    If Form1.EnableSwearWordFilter1.Checked=True Then
     Begin
     For N:=1 to High(SwearWordList) Do
       If PosRep(LowerCaseRep(SwearWordList[N]),LowerCaseRep(Msg))>0 Then
        Begin
         SetLength(TmpStr,Length(SwearWordList[N]));
         FillChar(TmpStr[1],Length(SwearWordList[N]),'*');
         Msg:=Form1.ReplaceStr(Msg,SwearWordList[N],TmpStr);
        End;
      End;
    End;



   LastChatP:=Now;

   If Form10.RadioButton11.Checked=True Then
     Msg:=PlainText;
   If Form10.CheckBox33.Checked=False Then
     Msg:=DoTattooTag(Msg);
   Msg:=DoFontTag(Msg);
   Msg:=DoFontSize(Msg,0);
   FullStr:=Msg;
   Msg:=DoFadeTag(Msg,FromWho);
   If FadeIn=True Then
     Chatters[Form1.ChatterNum(FromWho)].FadeTag:=Form1.ExtractBetweenString('<','>',FullStr,True);
   Msg:=DoAltTag(Msg);
   If AltIn=True Then
     Chatters[Form1.ChatterNum(FromWho)].AltTag:=Form1.ExtractBetweenString('<','>',FullStr,True);
   Msg:=DoAltWTag(Msg);  //<graphics
   Msg:=Form1.RemoveHtmlTag(Msg);
   Msg:=DoFontColor(Msg);
//   FullStr:=Form1.RemoveHtmlTag(FullStr);
   FullStr:=DoFontColor(FullStr);


//   Msg:=Form1.Remove2(Msg,'<font','>');
//   Msg:=Form1.Remove2(Msg,'<fade','>');
//   Msg:=Form1.Remove(Msg,#$1B,'m');

   If Form10.RadioButton9.Checked=True Then
     FontSizeTag:=Form10.SpinEdit4.Value;


   If Form1.Forcetexttolowercase1.Checked=true then
      Msg:=LowerCaseRep(msg);


   N:=ScanIt('font color',LowerCaseRep(fadetagtext));
    If N>0 Then
    For N2:=1 to n Do
      FadeTagText:=DoFontColor(fadetagtext);

     N:=ScanIt('font size=',LowerCaseRep(msg));
   If N>0 Then
    For N2:=1 to n Do
      Msg:=DoFontSize(Msg,0);

// If Form1.StripFontTags1.Checked=True Then
    Msg:=Form1.Remove2(Msg,'<font','>');


{  If (ValidText(Msg)=True) and (IsUserIgnored(FromWho)=False) Then
   If (Dealt=False) And (PosRep(LowerCaseRep(CustomizeName(LowerCaseRep(LoggedInName))),LowerCaseRep(Msg))>0) and (ValidText(Msg)=True) Then
    Begin
     If Form1.DingOnID1.Checked=True Then
       MyBeep;
     UserSaidYourName(LowerCaseRep(FromWho));
     MsgTime:=FromWho+' @ '+DateTimeToStr(Now);
     Form25.ListBox1.Items.Add(MsgTime);
     Nump:=Form25.ListBox1.Items.IndexOf(MsgTime);
     If Nump<>-1 Then
      Begin
       SetLength(SaidYourName,Nump+1);
       SaidYourName[NumP].When:=Now;
       SaidYourName[NumP].Who:=FromWho;
       SaidYourName[Nump].What:=Msg;
       SaidYourName[Nump].What:=Remove(SaidYourName[Nump].What,'<','>');
       SaidYourName[Nump].What:=Remove(SaidYourName[Nump].What,#$1B,'m');
       If (Form25.ListBox1.Items.Count>=Form10.SpinEdit5.Value) and (Form10.CheckBox2.Checked=True) Then
        Form25.Show;
      End;
    End;}

   If Form10.RadioButton6.Checked=True Then
     If FontSizeTag>Form10.SpinEdit4.Value Then
       FontSizeTag:=Form10.SpinEdit4.Value;


    Msg:=Form1.DoHtmlColTag(RichCont,Msg);
    If FontSizeTag>20 Then
    If Form10.RadioButton9.Checked=False Then
     FontSizeTag:=20
      else
     FontSizeTag:=Form10.Spinedit4.Value;

   //Msg:=Remove(Msg,'<','>');
   Msg2:=Msg;
   Msg2:=Remove(Msg,#$1B,'m');
  End;
   If Trim(Msg2)='' Then
     If AltIn=True Then
      Begin
       NotSaidBefore:=True;
       Msg2:=form1.RicheditBold(Form1.Richedit1,AltTagText);
       Msg:=Msg2;
      End;

   If Trim(Msg2)='' Then
     If FadeIn=True Then
      Begin
       NotSaidBefore:=True;
       Msg2:=form1.RicheditBold(Form1.Richedit1,FadeTagText);
       Msg:=Msg2;
      End;
  Msg3:=Msg2;
  Msg2:=Msg2+' ';
  Url:=Form1.GetUrl(Msg2,False);
  If URL<>'' Then
   Begin
    If Form5.ListBox1.Items.IndexOf(Url)=-1 Then
     Begin
       Form5.ListBox1.Items.Insert(0,Url);
       While Form5.ListBox1.Items.Count>Form5.SpinEdit1.Value do
          Form5.ListBox1.Items.Delete(Form5.ListBox1.Items.Count-1);
        Chatters[Form1.ChatterNum(FromWho)].LastUrl:=Url;
     End;
   End;
  Msg:=RemoveDoubleSpaces(Msg); //contains font tag

  Msg2:=Remove(Msg,#$1B,'m');
  Msg2:=ReplaceStr(Msg2,#$0D+#$0A,' ');
  Msg2:=Form1.Remove2(Msg2,'<fade','>');
  Msg2:=Form1.Remove2(Msg2,'<font','>');
  Msg2:=Form1.Remove2(Msg2,'<alt','>');
  Msg2:=Form1.Remove2(Msg2,'</','>');

  //msg2 = contains text without font tag

  //1exception
  //  Msg2:=Trim(Msg2);

{   If Form1.AutoRemoveSpaces1.Checked=True Then
    Begin
      Msg:=ReplaceStr(Msg,#$0D+#$0A,' ');
      Msg:=RemoveDoubleSpaces(Msg);
    End;}
    Msg2:=Msg2+' ';
    Msg3:=Msg2;
    Msg2:=Msg; //Bug?S


//


///
{ IF  (CheckOut(FromWho,True)=True) And (CheckIn(FromWho,True)=True) Then
  Begin
     If Form10.CheckBox14.Checked=True Then
     Begin
//      SmartFilter.Insert(0,Copy(PlainText,1,Length(PlainText) div 2));
     If Length(PlainText)>10 Then
      Begin
        SmartFilter.Insert(0,PlainText);
//        Form1.Panel10.Caption:='Learning Mode Activated: '+PlainText;
//        AddBlockMessage(Form1.Panel10.Caption);
       If SmartFilter.Count-1>Form10.SpinEdit9.Value Then
        SmartFilter.Delete(SmartFilter.Count-1);
       End;
     End;
  End;}

// d LastThingSaid<>PlainText

//   Msg2:=Msg3;
  If (NotSaidBefore=True)  and (Form1.ListBox2.Items.IndexOf(FromWho)=-1) and (LastThingSaid<>PlainText) and (length(msg2)>0) Then
   Begin
//     If URL<>'' Then
 //     Msg:=URlHttpStr(Msg,Form1.GetUrl(Msg));
    If Copy(Msg,Length(Msg)-2,2)=#$0d+#$0a Then
      Delete(Msg,Length(Msg),2);
//    BufferRichedit(Form1.Richedit1);
    {ScrState:=ScreenPaused;
    ScreenPaused:=True;}
//    Form1.Richedit1.Lines.BeginUpdate;
    If Form1.On1.Checked=True Then
      Form1.DoAvatar(Form1.Richedit1,Chatters[Form1.ChatterNum(FromWho)].Ident);

   Form1.DisplayUsername(RichCont,FromWho,Emote,RoomName);

    If FadeIn=True Then
      Begin
       Form1.Richedit1.SelAttributes.Size:=10;
       If FontFaceTag<>'' Then
         RichCont.SelAttributes.Name:=CheckFont(FontFaceTag);
        FullStr:=form1.RicheditBold(Form1.Richedit1,FullStr);
        FadeTagText:=form1.RicheditBold(Form1.Richedit1,FadeTagText);
        S:=Form1.BuildRTFStr(RichCont,FullStr,FadeTagText,FontFaceTag,FontSizeTag,BO,I,U,True,True);
        SetSelectionRtf(RichCont,S);
       // form1.RicheditFadeWriteTag(Form1.Richedit1,FadeTag,FadeTagText);
        LastThingSaid:=FadeTagText;
      End;
    If AltIn=True Then
     Begin
      Form1.Richedit1.SelAttributes.Size:=10;
      If FontFaceTag<>'' Then
        RichCont.SelAttributes.Name:=CheckFont(FontFaceTag);
        FullStr:=form1.RicheditBold(Form1.Richedit1,FullStr);
        AltTagText:=form1.RicheditBold(Form1.Richedit1,AltTagText);
        S:=Form1.BuildRTFStr(RichCont,FullStr,AltTagText,FontFaceTag,FontSizeTag,BO,I,U,True,True);
        SetSelectionRtf(RichCont,S);
       LastThingSaid:=AltTagText;
     End;
   If AltWin=True Then
     Begin
      Form1.Richedit1.SelAttributes.Size:=10;
      If FontFaceTag<>'' Then
        RichCont.SelAttributes.Name:=CheckFont(FontFaceTag);
      altWtagText:=form1.RicheditBold(Form1.Richedit1,AltWTagText);
      form1.RicheditAltWriteWTag(Form1.Richedit1,AltWTag,AltWTagText);
      LastThingSaid:=AltWTagText;
     End;

 If (AltWin=False) and (AltIn=False) and (FadeIn=False) Then
   Begin
     If FontFaceTag<>'' Then
       RichCont.SelAttributes.Name:=CheckFont(FontFaceTag);
     TS:=GetTickCount;
    //  Form1.RicheditWrite(Form1.Richedit1,Msg);  //ChatP
     FullStr:=form1.RicheditBold(RichCont,FullStr);
     S:=Form1.BuildRTFStr(RichCont,FullStr,Msg,FontFaceTag,FontSizeTag,BO,I,U,True,True);
     SetSelectionRtf(RichCont,S);
     TE:=GetTickCount;
     LastThingSaid:=PlainText;
{       If Form10.CheckBox24.Checked=True Then
       Begin
        If CrashBurnLevel>0 Then
         Begin
          Res:=((TE-TS)/1000);
          If Res>CrashBurnLevel Then
           Begin
            Form1.IgnoreUser(FromWho,False,True);
            AddBlockMessage(FromWho+': '+PlainText+' Ignored for attempted DOS attack! (Crash Burn Filter!)');
            Form1.Panel10.Caption:=FromWho+': Ignored for attempted DOS attack! (Crash Burn Filter!)';
           End;
         End
          else
         Form10.CheckBox24.Checked:=False;
       End;}
   End;
  // RichCont.SelText:=Msg;
     RichCont.Lines.add('');
     RichCont.SelAttributes.Name:='Arial';
     RichCont.SelAttributes.Size:=UserFontSize;
     RichCont.SelAttributes.Style:=[];
     Form1.UserSpoke(FromWho,PlainText);
    End;
  Form1.DoStats(FromWho);
  BufferRichedit(Form1.Richedit1,0);
  Form1.ScrollToEnd(Form1.Richedit1);
End;

Procedure DoTempUsers(LeftRoom: String);
Begin
 If TmpLeave.Count>300 Then
   TmpLeave.Delete(TmpLeave.Count-1);
  TmpLeave.Add(LeftRoom);
End;

Procedure UserEnterMessage(Richcont: TMyRichedit; JoinRoom: String);
Var
 BuildStr: String;
 Silent: Boolean;
 Obj: TObject;
Begin
  Silent:=Not Form1.RoomEnterLeaveMessages1.Checked;

 If (Form10.CheckBox22.Checked=True) And (Silent=True) Then
     If Friends.Find(JoinRoom,Obj)=True Then
        Silent:=False;

 If (Silent=False)  Then
  Begin
    RichCont.SelStart:=-1;
//    Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
    Form1.Panel10.Caption:=JoinRoom+': Has Joined The Room...';
    RichCont.SelAttributes.Style:=[FsItalic];
    RichCont.SelAttributes.Color:=ClBlue;
    RichCont.SelText:='User '+JoinRoom+' Has Joined The Room...';
    If FullDuplex=True Then
      Form1.SendExtCmd('User '+JoinRoom+' Has Joined The Room...');
    RichCont.SelAttributes.Color:=ClBlack;
    BuildStr:=ExtraInfo(JoinRoom);
    RichCont.SelText:=BuildStr;
    RichCont.SelAttributes.Style:=[];
    RichCont.Lines.Add('');
    RichCont.SelStart:=-1;
    Form1.ScrollToEnd(FOrm1.Richedit1);
  End
   else
  Begin
//    Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
    Form1.Panel10.Caption:=JoinRoom+': Blocked Of Joining the room..';
//    AddBlockMessage(Form1.Panel10.Caption);
  End;
End;


Procedure UserLeaveMessage(RichCont: TMyRichedit; LeftRoom: String);
Var
 Silent: Boolean;
 Obj: TObject;
Begin
 Silent:=Not Form1.RoomEnterLeaveMessages1.Checked;

 If (Silent=True) And (Form10.CheckBox22.checked=True) Then
     If Friends.Find(LeftRoom,Obj)=True Then
        Silent:=False;

 If Silent=False Then
  Begin
   RichCont.SelStart:=-1;
//   Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
   RichCont.SelAttributes.Color:=ClRed;
   RichCont.SelAttributes.Style:=[];
   RichCont.SelText:='User '+LeftRoom+' Has Left The Room...';
   If FullDuplex=True Then
    Form1.SendExtCmd('User '+LeftRoom+' Has Left The Room...');
   Form1.Panel10.Caption:=LeftRoom+': Has left The Room...';
   RichCont.SelAttributes.Color:=ClBlack;
   RichCont.SelAttributes.Style:=[];
   RichCont.Lines.Add('');
   RichCont.SelStart:=-1;
   Form1.ScrollToEnd(FOrm1.Richedit1);
  End
   else
  Begin
 //    Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
    Form1.Panel10.Caption:=LeftRoom+': Blocked Leaving Room..';
{    If Form1.RoomEnterLeaveMessages1.Checked=True Then
     AddBlockMessage(Form1.Panel10.Caption);}
  End;
End;

Procedure LeftChatP(RichCont: TMyRichedit;S,Who: String; Ycht: Boolean);
Var
  FirstTime,Blocked,Displayed: boolean;
  HAlike,TmpUsers: Integer;
  RoomName,Code,Code2,LeftRoom,Description,Tmp: String;
  TimeDif: Longint;
Begin
 Form1.Richedit1.SelStart:=-1;
 Tmp:=S;
 If Ycht=False Then
  Begin
   Delete(S,1,20);
   S:=Co80s+S;
   RoomName:=Form1.ExtractPacketDetails(S,'104');
   LeftRoom:=Form1.ExtractPacketDetails(S,'109');
  End
   else
  LeftRoom:=Who;



 Form1.UserLeft(LeftRoom);
 Form1.DoStatsUserLeave(LeftRoom);
 DoTempUsers(LeftRoom);
 TmpUSers:=Users;
 Displayed:=False;
 Blocked:=False;

 IF IsUserIgnored(LeftRoom)=True Then
   Blocked:=True;

 If (Form1.ListBox1.Items.IndexOf(LeftRoom)=-1) And (Form1.ListBox2.Items.IndexOf(LeftRoom)=-1) Then
   Blocked:=True;


 If (Form10.CheckBox10.Checked=True) and (Blocked=False) and (LeftRoom<>LoggedInName) Then
   Begin
    TimeDif:=MilliSecondsBetween(Form1.IDGapTimeLeft,Now);
    IF TimeDif<Form10.SpinEdit6.Value Then
     Begin
      Form1.Panel10.Caption:=LeftRoom+' Blocked Room Leave Message ID Left within '+IntToStr(TimeDif)+' Of ('+LastPersonLeave+') Time Specified Limit '+IntToStr(Form10.SpinEdit6.Value)+' ms';
      AddBlockMessage(Form1.Panel10.Caption);
      Blocked:=True;
      End;
    End;



// FirstTime:=CheckOut(LeftRoom,True);
// Blocked:=CheckOut(LeftRoom,False); //True  blocked

{ If (Blocked=False) And Form10.CheckBox27.Checked=True Then
  Begin
    If Form1.HowAlike(LastPersonLeave,LeftRoom)>Form10.SpinEdit14.Value Then
      Blocked:=True;
    //lastpersonleave = leftoom
  End;}

  If (Blocked=False) And (Form10.CheckBox27.Checked=True) Then
   Begin
     HAlike:=Form1.HowAlike(lastpersonleave,LeftRoom);
    If HAlike>Form10.SpinEdit14.Value Then
     Begin
      Blocked:=True;
//      Form1.Panel10.Font.Color:=ColSelect.AlertColor;
      Form1.Panel10.Caption:=' Clone Filter Enabled "'+lastpersonleave+'" Matched Against "'+LeftRoom+' '+IntToStr(HaLike)+'% Blocked Room Leave Message';
      AddBlockMessage(Form1.Panel10.Caption);
     End;
  End;


  IF (Blocked=False) Then //if option on
   Begin
     UserLeaveMessage(RichCont,LeftRoom);
     Displayed:=True;
   End;


{ IF (Form1.RoomEnterLeaveMessages1.Checked=True) And (Displayed=False) And (Blocked=False) Then
    TRoomEnterLeaveFilter.Create(LeftRoom,2,RichCont,3000);}


//   Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;

//  If (FollowUser=True) and (Following=LeftRoom) Then
 //   Form1.SendText(Form1.GotoUserP2(LoggedInName,LeftRoom));
//  If Form1.Wherethewindblows1.Checked=True Then
//    Form1.SendText(Form1.GotoUserP2(LoggedInName,LeftRoom));

  If Form1.ListBox2.Items.IndexOf(LeftRoom)>=0 Then
   Begin
    Form1.ListBox2.Items.Delete(Form1.ListBox2.Items.IndexOf(LeftRoom));
    DeleteChatter(LeftRoom);
    Dec(Users);
//    SetLength(Chatters,Users+2);
    Form1.SpSkinScrollPanel1.Caption:='Users: '+IntToStr(Users);
   End;

  If Form1.ListBox1.Items.IndexOf(LeftRoom)>=0 Then
    Begin
      DeleteChatter(LeftRoom);
      Form1.ListBox1.items.Delete(Form1.ListBox1.Items.IndexOf(LeftRoom));
      Dec(Users);
//      SetLength(Chatters,Users+2);
//      will continue to fail as well unless you organise chatters
      Form1.SpSkinScrollPanel1.Caption:='Users: '+IntToStr(Users);
     End;

 If Form1.ChatterNum2(LeftRoom)<>-1 Then
   DeleteChatter(LeftRoom);

 Form1.ScrollToEnd(RichCont);
 LastPersonLeave:=LeftRoom;
 If TmpUsers=Users Then
   TmpUsers:=TmpUsers;

 Form1.IdGapTimeLeft:=Now;

 BufferRichedit(Form1.Richedit1,0);
 Form1.ScrollToEnd(Form1.Richedit1);

// Form1.ColorArray2;
End;

function ByteToBits( b : byte ) : string;
var
   i : integer;
   m : byte;
begin
   SetLength( Result, 8 );
   m := 128;
   i := 1;
   while i <= 8 do begin
      if ( b and m ) = m then
         Result[ i ] := cOne
      else
         Result[ i ] := cZero;
      inc( i );
      m := m shr 1;
   end;
end;

function BitsToByte(Str :String ):Byte;
var
 b: Byte;
 N: Integer;
  I: Byte;
begin
 I:=128;
 B:=B xor b;
 For N:=1 to Length(Str) do
  Begin
    If Str[N]='1' Then
      B:=B Or I;
   I:=I Shr 1;
  End;
 Result:=B;
end;

Function SetByteBit(B: Byte; P: Integer; BValue: Boolean): Byte;
var
 BStr: String;
begin
 BStr:=ByteToBits(B);
 If P<=Length(BStr) then
  Case BValue OF
    True: BStr[P]:='1';
    False: BStr[P]:='0';
  End;
 Result:=BitsToByte(BStr);
End;

Function GetByteBit(B: Byte; P: Integer): Char;
var
 BStr: String;
begin
 Result:='E';
 BStr:=ByteToBits(B);
 If P<=Length(BStr) then
   Result:=BStr[P];
End;

function DWordToBits( b : dword ) : string;
var
   i : integer;
   m : DWord;
begin
   SetLength( Result, 32 );
   m := 2147483648;
   i := 1;
   while i <= 32 do begin
      if ( b and m ) = m then
         Result[ i ] := cOne
      else
         Result[ i ] := cZero;
      inc( i );
      m := m shr 1;
   end;
end;

function BitsToDWord(Str :String ): DWord;
var
 b: DWord;
 N: Integer;
  I: DWord;
begin
 I:=2147483648;
 B:=B xor b;
 For N:=1 to Length(Str) do
  Begin
    If Str[N]='1' Then
      B:=B Or I;
   I:=I Shr 1;
  End;
 Result:=B;
end;


Function Tform1.DwordToUsername(Value: Dword; Str: String): String;
Var
 BitStr: String;
 N: Integer;
Begin
 Result:=str;
 If Length(Str)>32 Then Exit;
 BitStr:=DWordToBits(Value);
 Str:=LowerCaseRep(Str);
 For N:=1 to Length(Str) Do
  Begin
    If BitStr[N]='1' Then
      Str[N]:=UpCase(Str[N]);
  End;
 Result:=Str; 
End;

Function TForm1.UsernametoDWord(Str: String): DWord;
Var
 N: Integer;
 BitStr: String;
begin
 If Length(Str)>32 Then Exit;
 SetLength(BitStr,32);
 FillChar(BitStr[1],32,Ord('0'));
  For N:=1 to Length(Str) Do
   Begin
    If IsCharUpper(Str[N])=True Then
       BitStr[N]:='1' else
         BitStr[N]:='0';
   End;
  Result:=BitsToDWord(BitStr);
End;


Function UserList(Tmp: String): String;
Var
 UserID,Nick,Block,S,BuildStr,JoinRoom2,Tmp2: String;
 Location,Age,Extra: String;
 N,N2: Integer;
 Uf: TUserFields2;
Begin
//  Users:=Form1.ListBox1.Items.Count;
  S:=Tmp;
  Tmp2:=Tmp;
 N:=Form1.ScanIt(Co80S+'109',Tmp2);
 For N2:=1 to n+1 Do
  Begin
   UserId:=''; Nick:=''; Location:=''; Age:=''; Location:=''; Extra:='';
   Block:=Form1.ExtractBlockPacketDetails(Tmp2,'109','109');
//   If Copy(Block,1,2)<>Co80s Then
 //    Block:=co80s+Block;
   If Copy(Block,1,2)=Co80s Then
     Delete(Block,1,2);
   Delete(Tmp2,1,PosRep(Block,Tmp2)+Length(Block)-1);

   Uf:=TUserFields2.Create;
   Uf.SplitFields(Block);
   UserID:=Uf.GetField('109');
   Nick:=Uf.GetField('141');
   Location:=Uf.GetField('142');
   Age:=Uf.GetField('110');
   Extra:=Uf.GetField('113');
   Uf.Free;
   //Block:=co80s+Block;   
   Chatters[Form1.ChatterNum(UserID)].Location:=Location;
   Chatters[Form1.ChatterNum(UserID)].Nick:=Nick;
   Chatters[Form1.ChatterNum(UserID)].Age:=Age;
   Chatters[Form1.ChatterNum(UserID)].Extra:=Extra;
     If Trim(UserID)<>'' Then
       Begin
//        If PosRep('aa1',UserID)>0 Then
        If Form10.CheckBox15.Checked=True Then
          Form1.ScanForIllegals(UserID,True);

        IF Form10.aa1BotFilter.Checked=True Then
          If Form1.IsAa1Bot(UserID)=True Then
            Form1.IgnoreUser(UserID,False,False,False,False);

       If (Form1.ListBox1.Items.IndexOf(UserID)=-1) and (Form1.ListBox2.Items.IndexOf(UserID)=-1) Then
        Begin
         If (IsUserIgnored(UserID)=False) Then
           Form1.ListBox1.Items.Add(UserID)
          else
         If Form1.ListBox2.Items.IndexOf(UserID)=-1 Then
           Form1.ListBox2.Items.Add(UserID);
         Inc(Users);
         BuildStr:=BuildStr+UserID+', ';
        End;
       End;
    // Tmp2:=Form1.CutC080(Tmp2,1);
  End;
 Form1.SpSkinScrollPanel1.Caption:='Users In Room: '+IntToStr(Users);
 JoinRoom2:=Copy(S,1,PosRep(Chr($c0)+Chr($80),S)-1);
 BuildStr:=Copy(BuildStr,1,length(BuildStr)-2);
 UserList:=BuildStr;
End;

Procedure UserJoinedDetails(RichCont: TMyRichedit; RoomName,UserName,Nick,Gender: String);
Var
 Blocked,Displayed,UserJoined,RoomList: Boolean;
 Txt,JoinRoom: String;
 Obj: Tobject;
 Halike: Integer;
 TimeDif: Longint;
Begin
//
       RoomList:=False;
       UserJoined:=True;
       JoinRoom:=UserName;


       If Trim(JoinRoom)<>'' Then
         If Form28.CheckBox7.Checked=True Then
          Begin
           Form28.CheckBox3.Checked:=False;
           If JoinRoom=LoggedInName Then
            Begin
//             Form1.richedit2.SelText:=Form28.Edit5.Text;
//             Form1.Button1.Click;
             //
               Txt:=Form28.Edit5.Text;
               Txt:=Trim(Form1.CheckCommands(Form1.Richedit1,Txt));
          {     If Form1.SimpleAutoCorrect1.Checked=True Then
                If Length(Txt)<400 Then}
//                If Form1.SoundEXSpellChecker1.Checked=True Then
        {       If Length(Txt)<400 Then
                Txt:=Form1.CorrectString2(Txt);}
                If Length(Txt)<600 Then
               Txt:=Form1.MakeMacro(Txt);
            //    Txt:=Trim(CheckCommands(Form1.Richedit1,Txt));
             IF Form1.HackersCode1.Checked=True Then
             Txt:=HackersCode(Txt);
             If Form1.CoolJansText1.Checked=True Then
              Txt:=CoolJansText(Txt);
             IF Form1.Mirroryourtext1.Checked=True Then
                Txt:=MirrorCode(Txt);
              If Length(Txt)>0 Then
              If Length(txt)<400 Then
               Form1.Say(Form1.Richedit1,Txt,False,False,False)
                 else
               Form1.Say(Form1.Richedit1,Txt,True,False,False);
             //
            End;
          End;

         If Form28.CheckBox3.Checked=True Then
         If JoinRoom=LoggedInName Then
           Form1.Say(Form1.Richedit1,Form28.Edit3.Text,False,False,False);
      //
          Displayed:=False;


        Blocked:=False;
//      Blocked:=Checkin(JoinRoom,False);

      IF IsUserIgnored(JoinRoom)=True Then
        Blocked:=True;


      If (Form10.CheckBox10.Checked=True) And (Blocked=False) And (LoggedInName<>JoinRoom) Then
       Begin
        TimeDif:=MilliSecondsBetween(Form1.IDGapTimeJoin,Now);
        IF TimeDif<Form10.SpinEdit6.Value Then
         Begin
//          Form1.Panel10.Caption:=JoinRoom+' Blocked Room Enter Message Joined within '+IntToStr(TimeDif)+' Limit '+IntToStr(Form10.SpinEdit6.Value);
          Form1.Panel10.Caption:=JoinRoom+' Blocked Room Enter Message ID Joined within '+IntToStr(TimeDif)+' Of ('+LastPersonJoined+') Time Specified Limit '+IntToStr(Form10.SpinEdit6.Value)+' ms';
          AddBlockMessage(Form1.Panel10.Caption);
          Blocked:=True;
         End;
        End;


        If (Blocked=False) And (Form10.CheckBox27.Checked=True) Then
         Begin
          HAlike:=Form1.HowAlike(LastPersonJoined,JoinRoom);
          If HAlike>Form10.SpinEdit14.Value Then
           Begin
            Blocked:=True;
//            Form1.Panel10.Font.Color:=ColSelect.AlertColor;
            Form1.Panel10.Caption:=' Clone Filter Enabled "'+LastPersonJoined+'" Matched Against "'+JoinRoom+' '+IntToStr(HaLike)+'% Blocked Room Enter Message';
            AddBlockMessage(Form1.Panel10.Caption);
           End;
         End;

       IF (Blocked=False) Then
          Begin
           UserEnterMessage(RichCont,JoinRoom);
           Displayed:=True;
         End;


    //Modification

        If Form1.ListBox2.Items.IndexOf(JoinRoom)>-1 Then
          Exit;

        If Form1.ListBox1.Items.IndexOf(JoinRoom)=-1 Then
          If Trim(JoinRoom)<>'' Then
           Begin
           //Friends.Strings[n]
         If IsUserIgnored(JoinRoom)=False Then
              Begin
               Form1.ListBox1.Items.Add(JoinRoom);
               Form1.UserJoined(JoinRoom,Nick,Gender);
                If (Form1.OtronTechnology1.Checked=True) or (Form1.Greetbuddywhentheyenter1.Checked=True) Then
                  if Friends.Find(JoinRoom,Obj)=True Then
                   if (JoinRoom<>loggedinname)  Then
                     If (PosRep(LowerCaseRep(JoinRoom+':'),Form1.Richedit1.Text)>=1) or (PosRep(LowerCaseRep(JoinRoom+'*:'),Form1.Richedit1.Text)>=1) Then
                       Begin
                        If (Form1.OtronTechnology1.Checked=True) Then
                        Form1.Say(form1.Richedit1,'wb '+Form1.CustomizeName(JoinRoom),False,False,False);
                      End
                         else
                      Begin
                      If (Form1.Greetbuddywhentheyenter1.Checked=True) Then
                       Form1.Say(form1.Richedit1,Form24.Edit5.Text+' '+Form1.CustomizeName(JoinRoom),False,False,False)
                      End;
                    End
              else
                 If Form1.ListBox2.Items.IndexOf(JoinRoom)=-1 Then
                 Begin
                   Form1.ListBox2.Items.Add(JoinRoom);
                   Form1.UserJoined(JoinRoom,Nick,Gender);
                 End;
            Inc(Users);
            Form1.SpSkinScrollPanel1.Caption:='Users: '+IntToStr(Users);
          End;
   //    End;
   LastPersonJoined:=JoinRoom;
   Form1.IDGapTimeJoin:=Now;   
//
End;


Procedure DisconnectVoiceAndConnect;
Begin
If InVoice=True Then
 Begin
  Form1.SpSkinSpeedButton2.OnClick(Nil);
  Form1.Delay(500);
  Form1.SpSkinSpeedButton2.OnClick(Nil);
 End;
End;

Procedure GetAlphaCode(Url: String);
Begin
 TGetAlphaCode.Create(Url,False,'');
End;

Procedure JoinChatP(RichCont: TMyRichedit;S: String);
Var
 UserJoined,RoomList: Boolean;
 Err,UserCount: Integer;
 Txt,BuildStr: String;
 JoinedRoom,RoomCount,RoomCat,RoomExt,Voice,Cam,EC,Age,Extra,Nick,Location,WhoJoined,JoinRoom,Description,Tmp: String;
 Blocked,Displayed: Boolean;
 B1,B2: Byte;
 TS,TE: Real;
 UF: TUserFields2;
Begin
 //  Form1.DebugPacket(S,1);
  RichCont.SelStart:=-1;
  Tmp:=S;
  Delete(Tmp,1,20);
//  Tmp:=co80s+Tmp;
//  TS:=GetTickCount/1000;

  Uf:=TUserFields2.Create;
  UF.SplitFields(Tmp);
  Description:=Uf.GetField('105');
  RoomCat:=Uf.GetField('129');
  RoomExt:=Uf.GetField('126');
  JoinRoom:=Uf.GetField('104');
  EC:=Uf.GetField('114');
  Voice:=Uf.GetField('130');
  Cam:=Uf.GetField('61');
  Nick:=Uf.GetField('141');
  Age:=Uf.GetField('110');
  Extra:=Uf.GetField('113');
  WhoJoined:=Uf.GetField('109');
  Location:=Uf.GetField('142');
  GpRoomName:=JoinRoom;
  Uf.Free;

 UserCount:=Form1.ScanIt(Co80S+'109'+Co80s,Tmp);


//    EC:=Form1.ExtractPacketDetails(Tmp,'114');
//  Voice:=Form1.ExtractPacketDetails(Tmp,'130');
//  Cam:=Form1.ExtractPacketDetails(Tmp,'61');
//  Nick:=Form1.ExtractPacketDetails(Tmp,'141');
//  Location:=Form1.ExtractPacketDetails(Tmp,'142');
//  Age:=Form1.ExtractPacketDetails(Tmp,'110');
//  Extra:=Form1.ExtractPacketDetails(Tmp,'113');
//  RoomName:=Form1.ExtractPacketDetails(Tmp,'104');


//  Description:=Form1.ExtractPacketDetails(Tmp,'105');
//  RoomCat:=Form1.ExtractPacketDetails(Tmp,'129');
//  RoomExt:=Form1.ExtractPacketDetails(Tmp,'126');
//  JoinRoom:=Form1.ExtractPacketDetails(Tmp,'104');
//  TE:=(GeTTickCount/1000)-TS;
//  Form1.Richedit1.Lines.Add('Taken: '+FloatToStr(TE));
//  Application.ProcessMessages;
  If RoomExt<>'' Then
   Form22.Edit9.Text:=RoomExt;
  If Voice<>'' Then
    Form22.Edit4.Text:=Voice;
  If Cam<>'' Then
    Form22.Edit8.Text:=Cam;

  If (UserCount>0) And (GpRoomName<>'') And (RoomExt<>'')  Then
    Begin
      If Assigned(Form1.Knock)=True Then
        Begin
         Form1.Knock.StopKnock;
         Form1.Knock.Free;
         Form1.Knock:=Nil;
        End;
       Form1.Timer7.Enabled:=False;
       Form1.RoomJoinWait:=False;
       Form1.RoomAckWait:=False;
       Form1.Richedit1.Lines.Add('');
       Form1.ListBox1.Items.Clear;
       Form1.ListBox2.Items.Clear;
       ChatLines:=0;
       Form1.ClearMessages;
       Users:=0;
       Storing:=0;
       RoomList:=True;
       UserJoined:=False;
       Tmp:=co80s+Tmp;
       UserList(Tmp);
       ///If Form2.ComboBox3.Items.IndexOf(RoomName)=-1 Then
       {If Form1.IsItemIn2(Form2.RoomBox,RoomName)=-1 Then
        If RoomName<>'' Then
         Form2.RoomBox.Items.Insert(0,RoomName);}
       RichCont.SelAttributes.Color:=ClRed;
       RichCont.SelAttributes.Style:=[FsBold];
       RoomCount:=Form1.ExtractPacketDetails(Tmp,'108');
       Form22.Edit3.Text:=RoomCat;
       Val(RoomCount,RoomCount2,Err);
       RoomTime:=0;
       GpRoomName:=JoinRoom;
       Form1.BumpKnocks:=0;
       Form1.timer7.Enabled:=False;
       Form1.WorkingDetails.Port:=Form1.Ymsg.Port;
       Form1.WorkingDetails.Server:=Form1.Ymsg.Host;
       RichCont.SelText:='You are now in: '+JoinRoom+' (Room Count: '+IntToStr(UserCount)+'/'+IntToStr(roomCount2)+')'+#$0d+#$0a;
       //
      If Pos('captcha',description)>0 Then
       Begin
        Form1.Richedit1.SelAttributes.Color:=ClRed;
        Form1.Richedit1.SelText:='Yahoo Spam Protection ';
        Form1.Richedit1.SelAttributes.Color:=ClBlack;
        Form1.Richedit1.Lines.Add('');
        FormCaptcha.Show;
        Form1.CaptchaImageStr:=Form1.GetURL(description,False);
        GetAlphaCode(Form1.CaptchaImageStr);
        //ShellExecute(Form1.Handle,'open',Pchar(Form1.GetURL(description,False)),'','',0);
      End;
//      Form1.Richedit1.Lines.Add(PlainText);
       //

//       RichCont.SelText:=Description;
       Form1.InChat:=True;

       If UserCount>=StrToInt(RoomCount) Then
{         If Form2.BootResistant1.Checked=True Then
            Form1.SendText(Form1.LoginString2(LoggedInName,1));}


//       RichCont.Lines.Add('');
       DisconnectVoiceAndConnect;
       Chatters[Form1.ChatterNum(LoggedInName)].RoomName:=GpRoomName;
       Form2.RoomBox.Text:=GpRoomName+'::'+RoomCat;
       Form31.ListView1.Items.Clear;
       Form1.Caption:='Y!mLite - '+Form2.ComboBox1.text+' You Are In: '+GpRoomName;
       RichCont.Lines.Add('');
       Form1.JoinTimeReq:=SecondsBetween(Form1.JoinSent,Now);
       Form1.RichEdit1.Lines.Add('Packet Processing Delay of '+IntTOStr(Form1.JoinTimeReq)+' Seconds To Join The Room');
{       If Form1.joinTimeReq>20 Then
         If Form2.BumpingCheckbox.checked=True Then
          Begin
           ShowMessage('Y!mLite has Detected Lag, Bumping has been disabled to enabled Bumping again click on the "bump" option on the login window.');
           Form2.BumpingCheckbox.Checked:=False;
          End;}
       RichCont.SelAttributes.Color:=ClBlack;
       RichCont.SelAttributes.Style:=[FsBold];
       If Form10.CheckBox43.Checked=True Then
          Description:=Copy(Description,1,PosRep('[',Description)-1);
       RichCont.SelText:=Description;
       RichCont.Lines.Add('');
       RichCont.SelAttributes.Color:=ClBlack;
       RichCont.SelAttributes.Style:=[];
       Form1.ScrollToEnd(Form1.Richedit1);
       Form22.Edit1.Text:=LoggedInName;
       Form22.Edit2.Text:=GPRoomName;
       Form22.Edit7.Text:=key;
       Exit;
    End;


    If (UserCount>1) and (Description='')  Then
      Begin
       Tmp:=co80s+Tmp;
       UserList(Tmp);
       Form1.BumpKnocks:=0;
       Form1.timer7.Enabled:=False;
       Form1.RoomAckWait:=False;
       Form1.RoomJoinWait:=False;

{       If Form2.BootResistant1.Checked=True Then
            Form1.SendText(Form1.LoginString2(LoggedInName,1));}
       Exit;
      End;

    If (GPRoomName<>'') And (UserCount=1) And (RoomExt='') and (RoomCat='')  Then
     Begin
     //   Delete(Tmp,1,20);
      {  Uf:=TUserFields2.Create;
        UF.SplitFields(Tmp);
        WhoJoined:=Uf.GetField('109');
        Nick:=Uf.GetField('141');
        Location:=Uf.GetField('142');
        Age:=Uf.GetField('110');
        Extra:=Uf.GetField('113');
        Uf.Free;}
//        JoinRoom:=Form1.ExtractPacketDetails(Tmp,'109');
//        Nick:=Form1.ExtractPacketDetails(Tmp,'141');
//        Location:=Form1.ExtractPacketDetails(Tmp,'142');
//        Age:=Form1.ExtractPacketDetails(Tmp,'110');
//        Extra:=Form1.ExtractPacketDetails(Tmp,'113');
//        LoadCustomName(JoinRoom);
        Chatters[Form1.ChatterNum(WhoJoined)].UserName:=WhoJoined;
        Chatters[Form1.ChatterNum(WhoJoined)].Location:=Location;
        Chatters[Form1.ChatterNum(WhoJoined)].Nick:=Nick;
        Chatters[Form1.ChatterNum(WhoJoined)].Age:=Age;
        Chatters[Form1.ChatterNum(WhoJoined)].Extra:=Extra;
        Chatters[Form1.ChatterNum(WhoJoined)].RoomName:=RoomName;
        Chatters[Form1.ChatterNum(WhoJoined)].AssignedCustomName:=IsCustomName(WhoJoined);
        If WhoJoined=LoggedInName Then
           UserJoinedDetails(Form1.Richedit1,RoomName,WhoJoined,Nick,Extra)
            else
        If (Form1.ListBox1.Items.IndexOf(WhoJoined)=-1) And (Form1.ListBox2.Items.IndexOf(WhoJoined)=-1) Then
           UserJoinedDetails(Form1.Richedit1,RoomName,WhoJoined,Nick,Extra);
     End;

  If EC<>'' Then
   Begin
    Ec:=Copy(Ec,1,2);
    Form1.RoomAckWait:=False;
    Form1.RoomJoinWait:=False;
    Form1.Timer7.Enabled:=False;
    If Ec='-1' Then
      Form1.Richedit1.Lines.Add('Room Denied - Click on "Need Help?" At The Top for Help Regarding this (Usally, waiting 20 - 30 minutes helps then try and join again)... Error Code: '+Ec);

    If Ec='-3' Then
     Begin
       Form1.Panel10.Caption:='Room Full'+Ec;
       Form1.Richedit1.Lines.Add('Room FULL, try another room!');
       IF Form10.CheckBox29.Checked=True Then
        If (Assigned(Form1.Knock)=False) And (LowerCaseRep(Form1.LastJoinRoom)<>LowerCaseRep(RoomName)) Then
         If MessageDlg('Would you like to use /knock on this room? (Please remember, this may get a temp ID ban, use at own risk)',MtConfirmation,[MBYES,MBNO],0)=IDYes Then
          Begin
            Form1.Knock:=TKnock.Create(Form1.LastJoinRoom,(60*1000)*3,StrToInt(Form10.Edit12.Text));
            Form1.Knock.StartKnocking;
          End;

{       If InChatRoom=False Then
        Begin
         Form1.YmLiteInChatSupport1.OnClick(Nil);
         Form1.Richedit1.Lines.Add('The Client Has Detected You Are Not Yet In Chat, so Redirection has taken place');
         Exit;
        End;}

     End;
    If Ec='-11' Then
      Form1.Panel10.Caption:='User not online: '+Ec;
    If Ec='-35' Then
      Form1.Panel10.Caption:='Room is Full: '+Ec;
    If Ec='16' Then
     Begin
       Form1.JoinTimeReq:=SecondsBetween(Form1.JoinSent,Now);
       Form1.Panel10.Caption:='You are already in the room: '+Ec;
       IF Assigned(Form1.Knock)=True Then
         Begin
          Form1.Knock.StopKnock;
          Form1.Knock.Free;
          Form1.Knock:=Nil;
         End;
     End;
    If Ec='-6' Then
      Form1.Richedit1.Lines.Add('The room you are trying to join has incorrect spelling');
    If Ec='-32' Then
     Begin
       Form1.Richedit1.Lines.Add('Room Error Code: '+Ec);
//       Form1.SendText(Form1.JoinRoom(Loggedinname,Form10.Edit14.Text));
     End;
    If (Ec<>'-11') And (Ec<>'-1') And (Ec<>'-35') And (Ec<>'16') And (Ec<>'32') And (Ec<>'11') and (EC<>'-3') Then
       Form1.Panel10.Caption:='Error Code unknown: '+Ec;
  //   Exit;
   // AddBlockMessage(Form1.Panel10.Caption);
   End;
   RoomName2:=RoomName;
   BufferRichedit(Form1.Richedit1,0);
   Form1.ScrollToEnd(Form1.Richedit1);
End;


Function Convert(Ch: Char; S: String): String;
begin
  while PosRep(ch, S) > 0 do
    S[PosRep(ch, S)] := ' ';
  Convert:=S;
end;

function TForm1.parseout(text: String; from: String; too: String):String;
Var
 P1,P2: Integer;
begin
  P1:=PosRep(From,Text);
  P2:=PosRep(Too,Text);
  Result:=Copy(Text,P1,P2-P1+Length(Too));
end;

Procedure RoomInitP(S: String);
//  ToUser: String;
 Var
 Tmp,Tmp2: String;
 BuddyCount,YourID,Buddy,UserOnline,ToWho: String;
 Code: String;
Begin
{If Key='' Then
 Begin
  Key:=Copy(S,17,4);
  Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
  Form1.Panel10.Caption:='Successful Login To Messenger Server....';
   Form1.StartSound('connected.wav',False);
  Form1.LoginToRoom;
 End;}
Delete(S,1,21);
//S:=Co80s+S;
Tmp:=S;
YourID:=Form1.ExtractPacketDetails(Tmp,'0');
BuddyCount:=Form1.ExtractPacketDetails(Tmp,'8');
//7 is all friends..
If BuddyCount<>'' Then
While Form1.ScanIt(co80s+'7',Tmp)>0 Do
 Begin
  Tmp2:=Form1.ExtractBlockPacketDetails(Tmp,'7','13');
  Delete(Tmp,1,PosRep(Tmp2,Tmp)+Length(Tmp2)+3);
  Buddy:=Form1.ExtractPacketDetails(Tmp2,'7');
  If OnLineFriends.IndexOf(Buddy)=-1 Then
   Begin
     OnLineFriends.Add(Buddy);
     Form12.ListBox1.Items.Add(Buddy);
   End;
 End
  else
 Begin
  Tmp2:=Form1.ExtractBlockPacketDetails(Tmp,'7','13');
  Buddy:=Form1.ExtractPacketDetails(Tmp2,'7');
  If Buddy<>'' Then
   If OnLineFriends.IndexOf(Buddy)=-1 Then
   Begin
     OnLineFriends.Add(Buddy);
     Form12.ListBox1.Items.Add(Buddy);
//     Form1.Panel10.Font.Color:=ColSelect.AlertColor;
     Form1.Panel10.Caption:='Messenger buddy: '+Buddy+' Has just come on Messenger';
    End;
 End;
End;


Function TForm1.AcceptCamInvite(FromWho: String): String;
Var
 PayLoad,Data,Tmp: String;
 ActLen,Len: Integer;
Begin
If Form2.RadioButton1.Checked=True Then
 Begin
  Payload:='1'+Co80s+LoggedInName+co80s+'5'+co80s+FromWho+co80s;
  ActLen:=Length(PayLoad);
  Tmp:='YMSG'+#$00+GVN+#$0+#$0+LengthToStr(ActLen)+#$0+#$50+#$0+#$0+#$0+#$0+Key;
  Tmp:=Tmp+PayLoad;
  Result:=Tmp;
 End;
End;

Procedure UserMsg(S: String);
Var
  StrC,Code,Code2,Code4,ToUser,FromUser,SaveStr: String;
Begin
//  Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
If Form1.BooterAlert=True Then
 Exit;
Delete(S,1,20);
S:=Co80s+S;
//49 = typing
FromUser:=Form1.ExtractPacketDetails(S,'4');
ToUser:=Form1.ExtractPacketDetails(S,'5');
Code:=Form1.ExtractPacketDetails(S,'13');
Code2:=Form1.ExtractPacketDetails(S,'49');
//S:=Form1.CutC080(S,2);
//Code:=Form1.ExtractPacketDetails(S,'49');
 IF IsUserIgnored(FromUser)=True Then
     Exit;
  
If Code2='TYPING' Then
 Begin
  If Code='1' Then
    Form1.Panel10.Caption:=FromUser+': '+'is now typing out a message to you as a PM/IM Window...';
  If Code='0' Then
    Form1.Panel10.Caption:=FromUser+': '+'has now stopped typing to you in a PM/IM Window...';
 End;

If Code2='GAME' Then
 Begin
  Code:=Form1.ExtractPacketDetails(S,'14');
  StrC:=Code;
  Delete(StrC,1,PosRep('ante?',StrC)-1);
  Code:=Copy(StrC,1,PosRep(#$9,StrC)-1);
  Delete(StrC,1,PosRep(#$9,StrC));
  If Form1.ProcessGamesMessages1.Checked=True Then
   If Code='1' Then
    Form1.Richedit1.Lines.Add(FromUser+': Has Left Yahoo Games!')
     else
    Form1.Richedit1.Lines.Add(FromUser+': '+'Is having a game.. '+StrC+' http://games.yahoo.com/games/'+Code);
  Exit;
  BufferRichedit(Form1.Richedit1,0);
  Form1.ScrollToEnd(Form1.Richedit1);
 End;

 If Form1.AutoRejectViewCamMessages1.Checked=False Then
  If Code2='WEBCAMINVITE' Then
   Begin
    If MessageDlg('You got an invite from '+FromUser+' To See Their Cam, you Accept? ',MtConfirmation,[MbYes,MBNo],0)=IDYes Then
     Begin
       Form1.SendText(Form1.AcceptCamInvite(FromUser));
       Form1.ViewCam(FromUser);
      End;
   End;
//  'Thank You, now please don''t try to pm me again!'
//  'You''re Pm Will Only Be Ignored So Stop Typing...'
{ If (Form10.CheckBox22.Checked=True) Then
   If Friends.IndexOf(FromUser)=-1 Then
    Begin
     If Code='1' Then
       Form1.SendText(Form1.Pm(FromUser,LoggedInName,'Your Pm Will Only Be Ignored, So Stop Trying...'));
     If Code='0' Then
       Form1.SendText(Form1.Pm(FromUser,LoggedInName,'Thank You, now please don''t try to pm me again!'));
    End;}
End;

Procedure AckBuddyAccept(S: String);
Var
  UserConfrenceID,Code,ToUser,FromUser,SaveStr: String;
  Obj: TObject;
Begin
If Form1.BooterAlert=True Then
   Exit;

Delete(S,1,20);
S:=Co80s+S;
ToUser:=Form1.ExtractPacketdetails(S,'1');
FromUser:=Form1.ExtractPacketdetails(S,'7');
Code:=Form1.ExtractPacketdetails(S,'66');
If code='3' Then
 Begin
  If Friends.find(FromUser,Obj)=False Then
   Begin
     Friends.Add(FromUser,Obj);
     Form27.ListBox1.Items.Add(FromUser);
   End;
 End;
If code='0' Then
 Begin
  If Friends.Find(FromUser,Obj)=False Then
   Begin
     Friends.Add(FromUser,Obj);
     OnLineFriends.Add(FromUser);
     Form12.ListBox1.Items.Add(FromUser);
     Form27.ListBox1.Items.Add(FromUser);
   End;
 End;

//Form27.ListBox1.Items.Text:=Friends.Text;
End;

Procedure AckBuddyRemove(S: String);
Var
  UserConfrenceID,Code,ToUser,FromUser,SaveStr: String;
  R: Integer;
  Obj: Tobject;
Begin
If Form1.BooterAlert=True Then
   Exit;
Delete(S,1,23);
ToUser:=Copy(S,1,PosRep(Chr($c0)+Chr($80),S)-1);
Delete(S,1,Length(ToUser)+6);
S:=Form1.CutC080(S,2);
FromUser:=Form1.ToC080(S);
If Friends.Find(FromUser,Obj)=True Then
  Friends.Delete(FromUser);
  Form12.ListBox1.Items.Delete(Form12.ListBox1.Items.IndexOf(FromUser));
//Form27.ListBox1.Items.Text:=Friends.Text;
End;



Procedure ConfrenceP(S: String);
Var
  Description,UserConfrenceID,Code,ToUser,FromUser,SaveStr: String;
Begin
If Form1.BooterAlert=True Then
   Exit;
 Delete(S,1,20);
 S:=Co80S+s;
 ToUser:=Form1.ExtractPacketDetails(S,'52');
 FromUser:=Form1.ExtractPacketDetails(S,'50');
 UserConfrenceID:=Form1.ExtractPacketDetails(S,'57');
 Description:=Form1.ExtractPacketDetails(S,'58');
 Code:=Form1.ExtractPacketDetails(S,'13');
End;



Function LeaveRoom(UserName: String; BP: Char): String;
Var
 PayLoad,Data,Tmp: String;
 Len: Integer;
Begin
If Form2.RadioButton1.Checked=True Then
 Begin
  Len:=5+Length(UserName);
  Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(len)+#$0;//Form1.LengthToStr(Length(Data)-11);
  Data:=Tmp+#$A0+#$0+#$0+#$0+#$0+key+#$31+#$C0+#$80+UserName+#$C0+#$80;
  LeaveRoom:=Data;
 End;
 Form1.InChat:=False;
// Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
// Form1.Panel10.Caption:='Left Chat Room..';
End;


Procedure LogOffp(S: String);
Var
  Code,Code2,Code3,Tmp: String;
  Username: String;
Begin
 Code:=S[20];
 Tmp:=S;
 Delete(S,1,23);
 Code:=Form1.ExtractPacketDetails(S,'20');
 Code3:=Form1.ExtractPacketDetails(S,'66');

 If pos('/img',code)>0  Then
   Begin
     Form1.Richedit1.SelAttributes.Color:=ClRed;
     Form1.Richedit1.SelText:='Your account has been locked, now launching Yahoo''s Unlocker Page.. (Just Enter your Yahoo Password and Username then Validate your Email Address)';
     ShellExecute(Form1.Handle,'open',Pchar('http://edit.yahoo.com'),'','',0);
     Form1.Richedit1.Lines.ADD('');
     Exit;
   End;

 If (Code3='3') Then
  Begin
  // If Random(2)=1 then TryAgain:=False;
//   Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
   Form1.Richedit1.Lines.Add('Your Password Is Invalid.');
   Form1.ScrollToEnd(Form1.Richedit1);
   Form1.BumpKnocks:=0;
   Form1.RoomAckWait:=False;
   Form1.RoomJoinWait:=False;
   Form1.Disconnecting:=False;
   Form1.Timer7.Enabled:=False;
   Form1.Ymsg.Active:=False;
 End;

  If (Code3='13') Then
  Begin
   Form1.Richedit1.Lines.Add('You have been Logged Off Yahoo Chat.');
   Form1.ScrollToEnd(Form1.Richedit1);
   Form1.BumpKnocks:=0;
   Form1.RoomAckWait:=False;
   Form1.RoomJoinWait:=False;
   Form1.Disconnecting:=False;
   Form1.Timer7.Enabled:=False;
   Form1.Ymsg.Active:=False;
 End;
 BufferRichedit(Form1.Richedit1,0);
 Form1.ScrollToEnd(Form1.Richedit1);
End;





Procedure RoomListSPRTP(RichCont: TMyRichedit; S: String);
Var
 Tmp,Tmp2: String;
 OnlineUsers,Susers,Msg,ChatterList: String;
 Code: String;
 BuildStr,UserID,Username: String;
 UC,N: Integer;
 RoomList: Boolean;
Begin
 Delete(S,1,15);
 RoomName:=Form1.ExtractPacketDetailsSprt(S,'104');
 ChatterList:=Form1.ExtractPacketDetailsSprt(S,'257');
 SUsers:=Form1.ExtractPacketDetailsSprt(S,'256');
 Users:=StrToInt(Susers);
 OnlineUsers:=Form1.ExtractPacketDetailsSprt(S,'255');
   //Extract Users
     //
        UserID:=tmp;
     //user Joined
       Form1.ListBox1.Items.Clear;
       Form1.ListBox2.Items.Clear;
       Form1.ClearMessages;
       ChatLines:=0;
       Users:=0;
       Storing:=0;
       RoomList:=True;
       ///If Form2.ComboBox3.Items.IndexOf(RoomName)=-1 Then
{       If Form1.IsItemIn2(Form2.RoomBox,RoomName)=-1 Then
        If RoomName<>'' Then
         Form2.RoomBox.Items.Insert(0,RoomName);}
       RichCont.SelAttributes.Color:=ClRed;
       RichCont.SelAttributes.Style:=[FsBold];
       RoomTime:=0;
       Form1.InChat:=True;
       Form1.RoomAckWait:=False;
       Form1.RoomJoinWait:=False;
       RichCont.SelText:='You are now in: '+RoomName+' (Server R/Count: '+Susers+')';
//       RichCont.Lines.Add('');
       DisconnectVoiceAndConnect;
       Chatters[Form1.ChatterNum(UserID)].RoomName:=RoomName;
       Form1.SpSkinScrollPanel1.Caption:='Users In Room: '+IntToStr(Users);
       Form2.RoomBox.Text:=RoomName;
       If Form1.IsItemInX(Form1.ListBox2,RoomName)=-1 Then
         Form2.RoomBox.Items.Insert(0,RoomName);
       Form31.ListView1.Items.Clear;

       Chatters[Form1.ChatterNum(LoggedInName)].RoomName:=RoomName;
       Form1.Caption:='Y!mLite - '+LoggedinName+' You Are In: '+RoomName;
       RichCont.Lines.Add('');
//       RichCont.SelAttributes.Color:=ClBlack;
//       RichCont.SelAttributes.Style:=[FsBold];
//       RichCont.SelText:=Descript;
//       RichCont.Lines.Add('');
       RichCont.SelAttributes.Color:=ClBlack;
       RichCont.SelAttributes.Style:=[];
       Form1.ScrollToEnd(Form1.Richedit1);
       Form22.Edit1.Text:=LoggedInName;
       Form22.Edit2.Text:=RoomName;
       Form22.Edit7.Text:=key;
     //

   Uc:=Form1.ScanIt(',',ChatterList);
   For N:=1 to Uc+1 Do
    Begin
     //
      If PosRep(',',ChatterList)>0 Then
       UserID:=Copy(ChatterList,1,PosRep(',',ChatterList)-1)
        else
       UserId:=ChatterList;
       Delete(ChatterList,1,PosRep(',',ChatterList));
        If Trim(UserID)<>'' Then
         Begin
         If (Form1.ListBox1.Items.IndexOf(UserID)=-1) and (Form1.ListBox2.Items.IndexOf(UserID)=-1) Then
          Begin
           If (IsUserIgnored(UserID)=False) Then
             Form1.ListBox1.Items.Add(UserID)
            else
           If Form1.ListBox2.Items.IndexOf(UserID)=-1 Then
             Form1.ListBox2.Items.Add(UserID);
           Inc(users);
           BuildStr:=BuildStr+UserID+', ';
           End;
         End;
      BuildStr:=Copy(BuildStr,1,length(BuildStr)-2);
     //
    End;
  Tmp:=Tmp;
  Form1.SpSkinScrollPanel1.Caption:='Users In Room: '+IntToStr(Users);

// Form1.Richedit1.Lines.Add('You are now in: '+Roomname+' Users: '+Users);
// Form1.Richedit1.Lines.Add('You see: '+ChatterList);
End;

Procedure ChatSPRTP(richcont: TMyRichedit; S: String);
Var
 Tmp,Tmp2: String;
 WhoTo,Msg,WhoFrom,RoomName: String;
 Code: String;
 UF: TUserFields;
Begin
 Delete(S,1,15);
 Uf:=TUserFields.Create;
 UF.SplitFields(S);
 WhoFrom:=Uf.GetField('31');
 WhoTo:=Uf.GetField('32');
 Msg:=Uf.GetField('41');
 RoomName:=Uf.GetField('104');
 Uf.Free;
 Form1.ChatP(Form1.Richedit1,Msg,WhoFrom,RoomName,Msg,True,False);
End;


Procedure GossipSPRTP(richcont: TMyRichedit; S: String);
Var
 Tmp,Tmp2: String;
 WhoTo,Msg,WhoFrom,RoomName: String;
 Code: String;
 UF: TUserFields;
Begin
 Uf:=TUserFields.Create;
 UF.SplitFields(S);
 Delete(S,1,15);
 WhoFrom:=Uf.GetField('31');
 WhoTo:=Uf.GetField('32');
 Msg:=Uf.GetField('41');
 RoomName:=Uf.GetField('104');
 Uf.Free;
 Form1.Richedit1.Lines.Add('Gossip: '+Msg);
//Form1.ChatP(Form1.Richedit1,Msg,WhoFrom,RoomName,Msg,True,False);
End;


Procedure LoginSPRTP(S: String);
Var
 Tmp,Tmp2: String;
 ServerMsg: String;
 Code: String;
Begin
Delete(S,1,15);
ServerMsg:=Form1.ExtractPacketDetailsSprt(S,'41');
Form1.Richedit1.Lines.Add(ServerMsg);
Tmp:=S;
End;


Procedure ServerSPRTP(S: String);
Var
 Tmp,Tmp2: String;
 ServerMsg: String;
 Code: String;
Begin
Delete(S,1,15);
ServerMsg:=Form1.ExtractPacketDetailsSprt(S,'200');
Form1.Richedit1.Lines.Add('Server Message: '+ServerMsg);
Tmp:=S;
End;

Procedure LeftChatSPRTP(RichCont: TMyRichedit; S: String);
Var
 Room,Tmp,Tmp2: String;
 WhoLeft,ServerMsg: String;
 Code: String;
Begin
Delete(S,1,15);
WhoLeft:=Form1.ExtractPacketDetailsSprt(S,'32');
Room:=Form1.ExtractPacketDetailsSprt(S,'104');
//Form1.Richedit1.Lines.Add(WhoLeft+' has left the '+Room+'  room!');
LeftChatP(RichCont,'',WhoLeft,True);
Tmp:=S;
End;

Procedure JoinChatSPRTP(RichCont: TMyRichedit; S: String);
Var
 Room,Tmp,Tmp2: String;
 WhoJoin,ServerMsg: String;
 Code: String;
Begin
Delete(S,1,15);
WhoJoin:=Form1.ExtractPacketDetailsSprt(S,'32');
Room:=Form1.ExtractPacketDetailsSprt(S,'104');
//Form1.Richedit1.Lines.Add(WhoJoin+' has Joined the '+Room+' room!');
UserJoinedDetails(Form1.Richedit1,Room,WhoJoin,'','');
Tmp:=S;
End;


Procedure InviteSPRTP(S: String);
Var
 FromWho,Nick,ToWho,FromUser,RoomCat,Tmp,Code,Code2,Code3,Description: String;
 Msg,Room,Tmp2: String;
 RoomName2,WhoInvite,ServerMsg: String;
Begin
Delete(S,1,15);
FromWho:=Form1.ExtractPacketDetailsSprt(S,'31');
ToWho:=Form1.ExtractPacketDetailsSprt(S,'32');
Msg:=Form1.ExtractPacketDetailsSprt(S,'41');
RoomName2:=Form1.ExtractPacketDetailsSprt(S,'104');
//Form1.Richedit1.Lines.Add('User '+whoinvite+' invited you to '+Room+' "'+Msg+'"');

If FromWho<>'' Then
 Begin
  If Form10.CheckBox20.Checked=True Then
   Begin
//    Form1.Panel10.Font.Color:=ColSelect.AlertColor;
    Form1.Panel10.Caption:='Room Invite Deflected, User '+FromWho+' Invited to: '+RoomName+' Instead!';
    Form1.Invite(FromWho,False,False,False)
   End
 Else
  Begin
//   Form1.Panel10.Font.Color:=ColSelect.AlertColor;
   Form1.Panel10.Caption:='Invited to join '+RoomName2+' By '+FromWho+' Description: '+Msg+' To Join Press F11';
   InviteRoom:=RoomName2;
  End;
 End;


Tmp:=S;
End;

Procedure PmSPRTP(S: String);
Var
 Msg,Room,Tmp,Tmp2: String;
 WhoTo,RoomN,WhoPm,ServerMsg: String;
 Code: String;
Begin
Delete(S,1,15);
WhoPm:=Form1.ExtractPacketDetailsSprt(S,'31');
WhoTo:=Form1.ExtractPacketDetailsSprt(S,'32');
Msg:=Form1.ExtractPacketDetailsSprt(S,'41');
//PmP2(S,LoggedInName,WhoPm,Msg,True,False);
//Form1.Richedit1.Lines.Add('User '+WhoPm+' Pmed you with '+Room+' "'+Msg+'"');
Tmp:=S;
End;


Procedure SprtRoomList(S: String);
Var
 Msg,Room,Tmp,Tmp2: String;
 UserID,RoomList,RoomN,WhoPm,ServerMsg: String;
 Code: String;
 N,Uc: Integer;
Begin
// Delete(S,1,15);
 Form8.ListBox2.Clear;
 RoomList:=Form1.ExtractPacketDetailsSprt(S,'41');
 Uc:=Form1.ScanIt(',',RoomList);
 Form8.Show;
   For N:=1 to Uc+1 Do
    Begin
     //
      If PosRep(',',RoomList)>0 Then
       RoomN:=Copy(RoomList,1,PosRep(',',RoomList)-1)
        else
       RoomN:=RoomList;
       Form8.ListBox2.Items.Add(RoomN);
      Delete(RoomList,1,PosRep(',',RoomList));
    End;
End;

Procedure CreateuserSPRT(S: String);
Var
 Msg,Room,Tmp,Tmp2: String;
 RoomN,WhoPm,ServerMsg: String;
 Code: String;
Begin
Delete(S,1,15);
Msg:=Form1.ExtractPacketDetailsSprt(S,'100');
Form1.Richedit1.Lines.Add(Msg);
Tmp:=S;
End;

Procedure FingerSPRTP(S: String);
Var
 NickN,Msg,Room,Tmp,Tmp2: String;
 UserType,TimeJ,RoomN,WhoFrom,ServerMsg: String;
 Code: String;
Begin
Delete(S,1,15);
WhoFrom:=Form1.ExtractPacketDetailsSprt(S,'32');
TimeJ:=Form1.ExtractPacketDetailsSprt(S,'43');
RoomN:=Form1.ExtractPacketDetailsSprt(S,'104');
NickN:=Form1.ExtractPacketDetailsSprt(S,'46');
UserType:=Form1.ExtractPacketDetailsSprt(S,'261');
Form1.Richedit1.Lines.Add('User '+WhoFrom+' is in '+RoomN+' and has been logged in since: '+TimeJ+' User Level: '+UserType);
Tmp:=S;
End;

Procedure ServStatsSPRTP(S: String);
Var
 SStarted,KilledUsers,UsersOn,PreConnects,InvL,TC: String;
 Code: String;
Begin
Delete(S,1,15);
TC:=Form1.ExtractPacketDetailsSprt(S,'301');
InvL:=Form1.ExtractPacketDetailsSprt(S,'302');
SStarted:=Form1.ExtractPacketDetailsSprt(S,'303');
KilledUsers:=Form1.ExtractPacketDetailsSprt(S,'304');
UsersON:=Form1.ExtractPacketDetailsSprt(S,'305');
PreConnects:=Form1.ExtractPacketDetailsSprt(S,'306');
Form1.Richedit1.Lines.Add('Total Connections: '+Tc+' Invalid Logins: '+InvL+' ServerStarted: '+SStarted+' Killed Connections '+KilledUsers+' Users Online: '+UsersOn+' PreConnections: '+PreConnects);
End;

Procedure AdminSPRTP(S: String);
Var
 IpAdd,NickN,Msg,Room,Tmp,Tmp2: String;
 TimeJ,RoomN,InfoOn,ServerMsg: String;
 Code: String;
Begin
Delete(S,1,15);
InfoOn:=Form1.ExtractPacketDetailsSprt(S,'32');
TimeJ:=Form1.ExtractPacketDetailsSprt(S,'43');
RoomN:=Form1.ExtractPacketDetailsSprt(S,'104');
IpAdd:=Form1.ExtractPacketDetailsSprt(S,'47');
ServerMsg:=Form1.ExtractPacketDetailsSprt(S,'160');
Form1.Richedit1.Lines.Add('User '+InfoOn+' is in '+RoomN+' and has been logged in since: '+TimeJ+' IP: '+Ipadd+' ('+ServerMsg+')');
Tmp:=S;
End;






Procedure TForm1.DealWithSPRTPacket(S: String);
Var
 Eop,TmpLen: Integer;
 S1,S2,Ptype: Byte;
 Tmp2,Back,Tmp: String;
Begin
 Tmp:=S;
  Back:=S;
  While (Length(Tmp)>=14) and (Copy(Tmp,1,4)='SPRT') Do
  Begin
   S:='';
   s1:=0; s2:=0;
   S1:=Ord(Tmp[13]);
   S2:=Ord(Tmp[14]);
   Eop:=ByteAdder(S1,S2);
   S:=Copy(Tmp,1,Eop+15);
   If Eop+15>Length(Tmp) Then
     Begin
      ChatBuffer:=S;
      Exit;
     End;
   Ptype:=Ord(S[15]);
     Case Ptype Of
        1:   LoginSPRTP(S);
        $AB:   ServerSPRTP(S);
        $30: PmSPRTP(S);
        $31: RoomListSPRTP(Form1.RichEdit1,S);
        $21: ChatSPRTP(Form1.Richedit1,S);
        $22: GossipSPRTP(Form1.Richedit1,S);
        $33: LeftChatSPRTP(Form1.Richedit1,S);
        $32: JoinChatSPRTP(Form1.Richedit1,S);
        $40: FingerSPRTP(S);
        $25: InviteSPRTP(S);
        $A0: AdminSPRTP(S);
        $AC: ServStatsSPRTP(S);
        $FF: CreateUserSPRT(S);
        $43: SprtRoomList(S);
        $27: BuddyListSPRT(S);
       End;
       Delete(Tmp,1,Eop+15);
  End;
  If Tmp<>'' Then
    Begin
     Tmp:=Tmp;
     ChatBuffer:=Tmp;
    End;

 BufferRichedit(Form1.Richedit1,0);
 Form1.ScrollToEnd(Form1.Richedit1);
End;

Function FingerStr(UserN: String): String;
 Var
   Head,PayLoad,S: String;
   Pay: Integer;
begin
 PayLoad:=Delim+'32'+Delim+UserN;
 Pay:=Length(PayLoad);
 Head:='SPRT'+#0+#0+#0+#0+Key+Form1.LengthToStr(Pay)+#$40;
  Result:=Head+Payload;
End;

Procedure Tform1.SendExtCmd(Cut: String);
Var
  MMsg: TCopyDataStruct;
Begin
   If ExtWnd<>0 Then
    Begin
     MMsg.dwData:=UWI; //49611; // User Defined
     MMsg.cbData:=Length(Cut)+1; // Size of data pointed to
     Cut:=Cut+#0;
     MMsg.lpData:=@cut[1];
     SendMessage(ExtWnd, WM_COPYDATA,  WPARAM (Form1.Handle), LPARAM (@MMsg));
    End;
End;

Function ServStatsStr(UserN: String): String;
 Var
   Head,PayLoad,S: String;
   Pay: Integer;
begin
 PayLoad:='';
 Pay:=Length(PayLoad);
 Head:='SPRT'+#0+#0+#0+#0+Key+Form1.LengthToStr(Pay)+#$AC;
 Result:=Head+Payload;
End;


Function Tform1.GetRoomList: String;
Var
   Head,PayLoad,S: String;
   Pay: Integer;
begin
 PayLoad:='';
 Pay:=Length(PayLoad);
 Head:='SPRT'+#0+#0+#0+#0+Key+Form1.LengthToStr(Pay)+#$43;
 S:=Head+Payload;
 Result:=s;
End;


Function AdminStr(UserN: String): String;
 Var
   Head,PayLoad,S: String;
   Pay: Integer;
begin
PayLoad:=Delim+'32'+Delim+UserN;
 Pay:=Length(PayLoad);
 Head:='SPRT'+#0+#0+#0+#0+Key+Form1.LengthToStr(Pay)+#$A0;
 Result:=Head+Payload;
End;

Function BanIPStr(IPS: String): String;
 Var
   Head,PayLoad,S: String;
   Pay: Integer;
begin
 PayLoad:=Delim+'260'+Delim+'7'+Delim+'270'+Delim+IPS;
 Pay:=Length(PayLoad);
 Head:='SPRT'+#0+#0+#0+#0+Key+Form1.LengthToStr(Pay)+#$A0;
 Result:=Head+Payload;
End;


Function KickUser(UserN: String): String;
Var
   Head,PayLoad,S: String;
   Pay: Integer;
begin
 PayLoad:=Delim+'32'+Delim+UserN+Delim+'260'+Delim+'1';
 Pay:=Length(PayLoad);
 Head:='SPRT'+#0+#0+#0+#0+Key+Form1.LengthToStr(Pay)+#$A0;
 Result:=Head+Payload;
End;


Function UnBanUser(UserN: String): String;
Var
   Head,PayLoad,S: String;
   Pay: Integer;
begin
 PayLoad:=Delim+'32'+Delim+UserN+Delim+'260'+Delim+'4';
 Pay:=Length(PayLoad);
 Head:='SPRT'+#0+#0+#0+#0+Key+Form1.LengthToStr(Pay)+#$A0;
 Result:=Head+Payload;
End;

Function MakeUserAdmin(UserN: String): String;
Var
   Head,PayLoad,S: String;
   Pay: Integer;
begin
 PayLoad:=Delim+'32'+Delim+UserN+Delim+'260'+Delim+'5';
 Pay:=Length(PayLoad);
 Head:='SPRT'+#0+#0+#0+#0+Key+Form1.LengthToStr(Pay)+#$A0;
 Result:=Head+Payload;
End;

Function MakeUserMod(UserN: String): String;
Var
   Head,PayLoad,S: String;
   Pay: Integer;
begin
 PayLoad:=Delim+'32'+Delim+UserN+Delim+'260'+Delim+'6';
 Pay:=Length(PayLoad);
 Head:='SPRT'+#0+#0+#0+#0+Key+Form1.LengthToStr(Pay)+#$A0;
 Result:=Head+Payload;
End;

Function KillUser2(UserN: String): String;
Var
   Head,PayLoad,S: String;
   Pay: Integer;
begin
 PayLoad:=Delim+'32'+Delim+UserN+Delim+'260'+Delim+'2';
 Pay:=Length(PayLoad);
 Head:='SPRT'+#0+#0+#0+#0+Key+Form1.LengthToStr(Pay)+#$A0;
 Result:=Head+Payload;
End;


Function TForm1.MyMod(X,Y: Longint): Longint;
Begin
 Result:=X-(Trunc(X / Y))*Y;
End;

Procedure TForm1.AuthAck(S: String);
Var
 PayLoad,RecAuth1,RecAuth2,BckStr,Tmp,Tmp2: String;
 ActLen: Integer;
 Keys: TKeys;
Begin
If Key='' Then
  Key:=Copy(S,17,4);

If Form1.InChat=False Then
   Form1.LoginToRoom2;

If Inchat=False Then
 Begin
  Form1.Panel10.Caption:='Successful Login To Messenger Server....';
  Form1.StartSound('connected.wav',False,False);
 End; 

 If (InChat=True) And (Form1.BooTResist=0) Then
  Begin
   LoginStage:=3;
   RecAuth1:=Form1.ExtractPacketDetails(S,'94');
   Key:=Copy(S,17,4);
   If Form2.RadioButton1.Checked=True Then
     Keys:=EncryptString(LoggedInName,LoggedInPassword,RecAuth1);

   PayLoad:='6'+Co80s+Keys[1]+Co80s+'96'+co80s+Keys[2]+Co80s;
   PayLoad:=PayLoad+'0'+co80s+LoggedInName+co80s+'2'+Co80s+LoggedInName+Co80s+'1'+co80s+LoggedInName+Co80s+'135'+Co80s+'8, 0, 0, 506'+co80s+'148'+co80s+'360'+co80s;
   ActLen:=Length(PayLoad);
   If Form2.CheckBox3.Checked=False Then // not invisible
      Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(ActLen)+#$0+#$54+#$5A+#$55+#$AA+#$55+Key
        else
      Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(ActLen)+#0+#$54+#$00+#$00+#$00+#$0C+Key;
   Tmp:=Tmp+PayLoad;
   Key:='';
   Form1.ymsg.Socket.SendText(Tmp);
   Form1.DebugPacket(Tmp,0);
  End; 
End;

Procedure TForm1.RoomInitP2(S: String);
Begin
 RoomAckWait:=False;
 If InChat=False Then
  Begin
   RoomJoinWait:=True;
   Form1.Richedit1.Lines.Add('');
   Form1.Richedit1.Seltext:='Room Ack Received, Please Wait For Chat Room Listing....';
   Form1.SendText(JoinRoom(LoggedInName,RoomName));; //marker2
   BufferRichedit(Form1.Richedit1,0);
   Form1.ScrollToEnd(Form1.Richedit1);
  End;
End;

Procedure TForm1.GenerateInviteKey;
Var
  N: Integer;
Begin
 SetLength(Form1.InviteKey,4);
 For N:=1 to 4 do
   Form1.InviteKey[N]:=Char(Random(25)+65);
End;

Procedure Tform1.DealWithYMSGPacket(S: String);
Var
 Eop,TmpLen: Integer;
 Ptype: Byte;
 Tmp2,Back,Tmp: String;
 Label DontProcess;
Begin
 Tmp:=S;
  Back:=S;
  While (Length(Tmp)>9) and (Copy(Tmp,1,4)='YMSG') Do
  Begin
   ConstructPacket:=0;
   S:='';
   s1:=0; s2:=0;
   S1:=Ord(Tmp[9]);
   S2:=Ord(Tmp[10]);
   Eop:=ByteAdder(S1,S2);
   S:=Copy(Tmp,1,Eop+20);
   If Eop+20>Length(Tmp) Then
     Begin
      OldLoginStage:=LoginStage;
      LoginStage:=99;
      ChatBuffer:=Tmp;
      Exit;
     End;
    Ptype:=Ord(S[12]);
       Case Ptype Of
        $F1:   LoginP2(S);
        $F0:  BuddyOnlineP(S);
        2:   OffLineP2(S);
        6:   PmP2(S);
        $57: AuthAck(S);
        $0B: MailP(S);
     //   $F1: BuddyP2(S);
        $20: PmP2(S); //ycht ??
        $54: LogOffP(S);
        $A8: Form1.ChatP(Form1.Richedit1,S,'','','',False,False);
        $9B: LeftChatP(Form1.Richedit1,S,'',False);
        $98: JoinChatP(Form1.Richedit1,S);
        $97: GotoP2(S);
        $9D: InviteP2(S);
        $50: WebcamP(S);
        $96: RoomInitP2(S);
        $55: BuddyListP2(S);
        $4B: UserMsg(S); //and webcam!
        $18: ConfrenceP(S);
        $83: AckBuddyAccept(S);
        $84: AckBuddyRemove(S);
       End;
     Delete(Tmp,1,Eop+20);
  End;

 If Tmp<>'' Then
    Begin
     ChatBuffer:=Tmp;
     OldLoginStage:=LoginStage;
     LoginStage:=99;
     s:='';
   End;
End;

{function  Tform1.BuildTime(TimeVal: Int64): string;
var
  BuildStr:      string;
  RunTime:       Int64;
  RSec,Rhours,
  Rmins,Rdays:   Int64;
begin
  BuildStr := '';
  RunTime := TimeVal;
  RDays := Trunc(RunTime/60/60/24);
  if (Rdays=1) then
    BuildStr := BuildStr+' '+IntToStr(Rdays)+' day, '
  else
    BuildStr := BuildStr+' '+IntToStr(Rdays)+' days, ';
  RHours := Trunc(RunTime/60/60) mod 24;
  if (RHours=1) then
    BuildStr := BuildStr+IntToStr(Rhours)+' Hour, '
  else
    BuildStr := BuildStr+IntToStr(Rhours)+' Hours, ';
  RMins := Trunc(RunTime/60) mod 60;
  if (RMins=1) then
    BuildStr := BuildStr+IntToStr(RMins)+' Minute, '
  else
    BuildStr := BuildStr+IntToStr(RMins)+' Minutes, ';
  RSec := Trunc(RunTime/1) mod 60;
  if (RSec=1) then
    BuildStr := BuildStr+IntToStr(RSec)+' Second.'
  else
    BuildStr := BuildStr+IntToStr(RSec)+' Seconds.';
  Result := BuildStr;
end;}


function  Tform1.BuildTime(TimeVal: Int64): string;
var
  BuildStr: String;
  RunTime: Int64;
  Rweeks,RMonths, RYears, RSec,Rhours,Rmins,Rdays: Int64;
begin
  BuildStr := '';
  RunTime := TimeVal;
  RMonths:=0; RWeeks:=0;
  RYears:=Trunc(RunTime/60/60/24/365);
//  RMonths:=Trunc(Runtime/60/60/24/7/4) mod 12;
 // RWeeks:=Trunc(Runtime/60/60/24/7) mod 4;
  RDays:=Trunc(RunTime/60/60/24) mod 365;
  RHours:=Trunc(RunTime/60/60) mod 24;
  RMins:=Trunc(RunTime/60) mod 60;
  RSec:=Trunc(RunTime/1) mod 60;

If (Ryears>0) Then
 if (Ryears=1) then
    BuildStr := BuildStr+' '+IntToStr(Ryears)+' Year, '
  else
    BuildStr := BuildStr+' '+IntToStr(Ryears)+' Years, ';


If (RMonths>0) Then
  if (RMonths=1) then
    BuildStr := BuildStr+' '+IntToStr(RMonths)+' Month, '
  else
    BuildStr := BuildStr+' '+IntToStr(RMonths)+' Months, ';


If (Rweeks>0) Then
  if (Rweeks=1) then
    BuildStr := BuildStr+' '+IntToStr(Rweeks)+' Week, '
  else
    BuildStr := BuildStr+' '+IntToStr(Rweeks)+' Weeks, ';



If (Rdays>0) Then
  if (Rdays=1) then
    BuildStr := BuildStr+' '+IntToStr(Rdays)+' day, '
  else
    BuildStr := BuildStr+' '+IntToStr(Rdays)+' days, ';

If (RHours>0) Then
  if (RHours=1) then
    BuildStr := BuildStr+IntToStr(Rhours)+' Hour, '
  else
    BuildStr := BuildStr+IntToStr(Rhours)+' Hours, ';

If (RMins>0) Then
  if (RMins=1) then
    BuildStr := BuildStr+IntToStr(RMins)+' Minute And '
  else
    BuildStr := BuildStr+IntToStr(RMins)+' Minutes And ';

 if (RSec=1) then
    BuildStr := BuildStr+IntToStr(RSec)+' Second'
  else
    BuildStr := BuildStr+IntToStr(RSec)+' Seconds';

 Result:=BuildStr;
end;



function GetOsInfo: String;
var
 dwSize:DWORD;
 hReg:HKey;
 tmp1, keyChar:Integer;
 i, x:Integer;
 Inf1,Inf2,Inf3,Inf4,Key: String;
 TimeVal: DWord;
 TimeV: TDateTime;
begin
 Result:='';
 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows NT\CurrentVersion', 0, KEY_READ, hReg ) <> ERROR_SUCCESS) then
   exit;

 SetLength( Result, 512 );
 dwSize := 512;
 If RegQueryValueEx( hReg, 'CurrentType', 0, 0, PByte( Pchar( Result ) ), @dwSize ) <> ERROR_SUCCESS Then
   Begin
    Result:='';
    Exit;
   End;
 Inf1:=Copy(Result,1,DwSize-1);

 SetLength( Result, 512 );
 dwSize := 512;
 RegQueryValueEx( hReg, 'ProductName', 0, 0, PByte( Pchar( Result ) ), @dwSize );
 Inf2:=Copy(Result,1,DwSize-1);

 SetLength( Result, 512 );
 dwSize := 512;
 RegQueryValueEx( hReg, 'SourcePath', 0, 0, PByte( Pchar( Result ) ), @dwSize );
 Inf3:=Copy(Result,1,DwSize-1);


 DwSize:=SizeOf(TimeVal);
 RegQueryValueEx( hReg, 'InstallDate', 0, 0, @TimeVal , @dwSize );
 //DateTimeToUnix
  TimeV:=UnixToDateTime(TimeVal);
// TimeV:=SystemTimeToDateTime(TimeVal);
// Inf4:=FormatDateTime('" Was installed on " dddd, mmmm d, yyyy, " at " hh:mm AM/PM', TimeV {+ 0.125});
// Inf4:='was installed '+IntToStr(WeeksBetween(Now,TimeV))+' Weeks / '+IntToStr(DaysBetween(Now,TimeV))+' Days ago.';
  Inf4:='Has Been Installed For '+Form1.BuildTime(secondsBetween(Now,TimeV));
 Result:=Inf2+' '+Inf4+' CPU Type - '+Inf1;
 //1982

 RegCloseKey( hReg );
end;                   


function GetOsKey: String;
var
 dwSize:DWORD;
 hReg:HKey;
 tmp1, keyChar:Integer;
 i, x:Integer;
 Key:String;
const
 Characters:String = 'BCDFGHJKMPQRTVWXY2346789';
begin
 if (RegOpenKeyEx( HKEY_LOCAL_MACHINE, 'Software\Microsoft\Windows NT\CurrentVersion', 0, KEY_READ, hReg ) <> ERROR_SUCCESS) then
   exit;
 SetLength( Result, 512 );
 dwSize := 512;
 RegQueryValueEx( hReg, 'DigitalProductId', 0, 0, PByte( Pchar( Result ) ), @dwSize );
 RegCloseKey( hReg );
 Key := Copy( Result, $35, 15 );
 Result := '';
 i := 29;
 while ( i > 0 ) do
 begin
   if ( (i mod 6) = 0 ) then
   begin
     Result := '-' + Result;
     dec( i );
     continue;
   end;
   tmp1 := 0;
   x := 15;
   while ( x > 0 ) do
   begin
     keyChar := ( tmp1 shl 8 ) or Byte( Key[x] );
     tmp1 := keyChar mod 24;
     Key[x] := Char( keyChar div 24 );
     dec( x );
   end;
   Result := Characters[ tmp1 + 1] + Result;
   dec( i );
 end;
end;

Function CreatePipeThread(P: Pointer): Longint; Stdcall;
Var
 Cut2: String;
 BuildStr: String;
Begin
 Cut2:=String(P^);
 Form1.ResultStr:=Form1.PipeOutCommand(Cut2);
 If Trim(Form1.ResultStr)<>'' Then
   SendMessage(Form1.Handle,wm_User+666,0,0);
// Form1.Say(Form1.Richedit1,Form1.Panel10.Caption,False,False,False);
End;

Function Tform1.CheckCommands(RichCont: TMyRichedit;Cmds: String): String;
Type TClist = Record
  CN: String;
  CC: Integer;
End;
Var
 Th: Thandle;
 Tmp1: String;
 memory: TMemoryStatus;
// memory: _MEMORYSTATUS;
 Tmp,RootPath : String;
 FreeAvail,TotalSpace: Int64;
 TotalFree: PLargeInteger;
 Cr,Cmd,FromWho,Tmp3,CalcStr,Tmp2,BuildStr: String;
 RunTime: Real;
 T1,T2,Cn: String;
 Srv: String;
 TimeV: TDateTime;
 CList: Array Of TClist;
 IgC,Rsec,Rhours,Rmins,Rdays,F,U2,U,M,N2,N: Integer;
 Year, Month, Day, Hour, Min, Sec, MSec: Word;
 Mins: LongInt;
 TD: TuserData2;
 D,D1: TdateTime;
 Nowtime,Mytime,Sendtime: Ttime;
 X,Y: Longint;
 Wp1,Mon: Word;
 Hr,Hr1,Min1,Sec1,msec1: Word;
 ParamStr: String;
Begin
 Cut:=Cmds;

  if copy(cut,1,6)='/ping2' then
   begin
     Cut:='';
     Form1.SendText(Ping(loggedinname));
   End;


  if copy(cut,1,7)='/update' then
   begin
     Delete(Cut,1,8);
     Form13.ParamStr:=Cut;
     Form13.Button1.OnClick(Self);
     Cut:='';
   End;



if copy(cut,1,7)='/sparta' then
   begin
     Delete(Cut,1,7);
     Form13.ParamStr:=Cut;
     Form13.Button6.OnClick(Self);
     Cut:='';
   End;

  if copy(cut,1,10)='/protoinfo' then
   begin
    Cut:='';
    BuildStr:='';
    If Form2.RadioButton1.Checked=True Then
      BuildStr:='Running on the YMSG (Messenger) Protocol';
     BuildStr:=' '+BuildStr+' Total Sent Chat Data: '+InTToStr(SentK div 1024)+'K'+' Total Received Chat Data: '+InTToStr(RecvK div 1024)+'K';
    Form1.Say(Form1.Richedit1,BuildStr,False,False,False);
   End;


  if copy(cut,1,6)='/oskey' then
   begin
     Cut:='';
     Form1.Richedit1.Lines.Add('Your CD Serial key for Win2K/XP is: '+GetOsKey);
   End;

  if copy(cut,1,9)='/cpuspeed' then
   begin
     Cut:='';
     BuildStr:='My Estimated CPU Speed Is: '+IntToStr(Trunc(GetCpuSpeed))+'Mhz';
     Form1.Say(Form1.Richedit1,BuildStr,False,False,False);
   End;


  if copy(cut,1,3)='/os' then
   begin
     Cut:='';
     memory.dwLength := SizeOf(memory);
     GlobalMemoryStatus(memory);
     //GetOsInfo
     BuildStr:=GetOsInfo;
     If BuildStr<>'' Then
       BuildStr:=' Extended Info '+BuildStr;
     Form1.Say(Form1.Richedit1,'Running on Windows: '+IntToStr (Win32MajorVersion)+'.'+IntToStr (Win32MinorVersion)+' (Build '+IntToStr (Win32BuildNumber)+') '+' update: '+Win32CSDVersion+' Total Memory: '+IntToSTr(memory.dwTotalPhys div 1024 Div 1024)+' Meg / '+'Available memory: '+IntToStr(memory.dwAvailPhys div 1024 Div 1024)+' Meg'+BuildStr,False,False,False);
   End;


  if copy(cut,1,12)='/maxsecurity' then
   begin
     Cut:='';
     Form10.Button3.OnClick(Self);
//     Form1.Richedit1.Lines.Add('Security Set... Please Reconnect To Take Effect....');
   End;


{   If Copy(cut,1,10)='/diskspace' Then
    Begin
      Delete(Cut,1,11);
      If Trim(Cut)<>'' Then
       RootPath:=Cut
      Else
      RootPath:='C:\';
     GetDiskFreeSpaceEx(Pchar(RootPath),FreeAvail,TotalSpace,TotalFree);
     Form1.Say(Form1.Richedit1,'RootPath : ' + RootPath+'''s Info, Free Meg : ' + IntToStr(FreeAvail div 1024 div 1024)+' Total Meg : ' + IntToStr(TotalSpace div 1024 div 1024),False,False,False);
     Cut:='';
    End;}

  if copy(cut,1,6)='/clear' then
   begin
     Cut:='';
     Form1.Richedit1.Clear;
     Form1.Richedit2.Clear;
     Form40.ListBox1.Clear;
     Form1.Panel10.Caption:='';
   End;

  if copy(cut,1,11)='/whatismyip' then
   begin
     Cut:='';
     TwhatIsMyIp.Create('','',0);
   End;


  if copy(cut,1,5)='/wipe' then
   begin
     Cut:='';
     Form40.ListBox1.Clear;
     Form1.Panel10.Caption:='';
   End;


 if copy(cut,1,7)='/finger' then
   begin
     M:=0; F:=0; U:=0;
     Delete(Cut,1,8);
     SendText(FingerStr(Cut));
     Cut:='';
   End;

 if copy(cut,1,10)='/servstats' then
   begin
     M:=0; F:=0; U:=0;
     Delete(Cut,1,11);
     SendText(ServStatsStr(Cut));
     Cut:='';
   End;


 if copy(cut,1,6)='/admin' then
   begin
     M:=0; F:=0; U:=0;
     Delete(Cut,1,7);
     SendText(AdminStr(Cut));
     Cut:='';
   End;

 if copy(cut,1,6)='/banip' then
   begin
     M:=0; F:=0; U:=0;
     Delete(Cut,1,7);
     SendText(BanIPStr(Cut));
     Cut:='';
   End;


 if copy(cut,1,5)='/kick' then
   begin
     M:=0; F:=0; U:=0;
     Delete(Cut,1,6);
     SendText(Kickuser(Cut));
     Cut:='';
   End;

  if copy(cut,1,7)='/gossip' then
   begin
     M:=0; F:=0; U:=0;
     Delete(Cut,1,8);
     Form1.SendText(GossipSpeech(RichCont,LoggedInName,RoomName,Cut,'',True,True,False));
     Cut:='';
   End;

 if copy(cut,1,6)='/unban' then
   begin
     M:=0; F:=0; U:=0;
     Delete(Cut,1,7);
     SendText(UnbanUser(Cut));
     Cut:='';
   End;

 if copy(cut,1,10)='/makeadmin' then
   begin
     M:=0; F:=0; U:=0;
     Delete(Cut,1,11);
     SendText(MakeUserAdmin(Cut));
     Cut:='';
   End;

 if copy(cut,1,8)='/makemod' then
   begin
     M:=0; F:=0; U:=0;
     Delete(Cut,1,9);
     SendText(MakeUserMod(Cut));
     Cut:='';
   End;


 if copy(cut,1,8)='/banuser' then
   begin
     M:=0; F:=0; U:=0;
     Delete(Cut,1,9);
     SendText(Killuser2(Cut));
     Cut:='';
   End;

  if copy(cut,1,6)='/info2' then
   begin
     M:=0; F:=0; U:=0;
     Delete(Cut,1,7);
     If Form1.ListBox1.Items.IndexOf(Cut)<>-1 Then
      Begin
       BuildStr:=ExtraInfo(Cut);
       BuildStr:='User: '+Cut+'''s info '+BuildStr;
       TimeV:=Chatters[Form1.Chatternum(Cut)].Joined;
//       BuildStr:=BuildStr+' Joined the room '+IntToStr(HoursBetween(Now,TimeV))+' hours, and '+IntToStr(MinutesBetween(Now,TimeV) mod 60)+' minutes ago.';
       BuildStr:=BuildStr+' has been in the room '+Form1.BuildTime(SecondsBetween(Now,TimeV));
       N:=Form1.ChatterNum(Cut);
       DecodeDate(Chatters[N].LocalTime,Year,Mon,Day);
       If Year>2000 Then
          BuildStr:=BuildStr+' Local Time, '+FormatDateTime('" " dddd, mmmm d, yyyy, " at " hh:mm AM/PM', Chatters[N].LocalTime {+ 0.125});
       BuildStr:=BuildStr+' Posts Made: '+IntToStr(Chatters[Form1.Chatternum(Cut)].NumLinesPosted);
       BuildStr:=BuildStr+' Total Posts Blocked: '+IntToStr(Chatters[Form1.Chatternum(Cut)].TotalBlock);
       Form1.Say(Form1.Richedit1,BuildStr,False,False,False);
      End;
     Cut:='';
   End;


  if copy(cut,1,5)='/info' then
   begin
     M:=0; F:=0; U:=0;
     Delete(Cut,1,6);
     If Form1.ListBox1.Items.IndexOf(Cut)<>-1 Then
      Begin
       BuildStr:=ExtraInfo(Cut);
       BuildStr:='User: '+Cut+'''s info '+BuildStr;
       TimeV:=Chatters[Form1.Chatternum(Cut)].Joined;
//       BuildStr:=BuildStr+' Joined the room '+IntToStr(HoursBetween(Now,TimeV))+' hours, and '+IntToStr(MinutesBetween(Now,TimeV) mod 60)+' minutes ago.';
       BuildStr:=BuildStr+' has been in the room '+Form1.BuildTime(SecondsBetween(Now,TimeV));
       N:=Form1.ChatterNum(Cut);
       DecodeDate(Chatters[N].LocalTime,Year,Mon,Day);
       If Year>2000 Then
          BuildStr:=BuildStr+' Local Time, '+FormatDateTime('" " dddd, mmmm d, yyyy, " at " hh:mm AM/PM', Chatters[N].LocalTime {+ 0.125});
       BuildStr:=BuildStr+' Posts Made: '+IntToStr(Chatters[Form1.Chatternum(Cut)].NumLinesPosted);
       BuildStr:=BuildStr+' Total Posts Blocked: '+IntToStr(Chatters[Form1.Chatternum(Cut)].TotalBlock);
       Form1.Richedit1.Lines.Add('Info for '+Cut+' '+BuildStr);
       bufferrichedit(Form1.Richedit1,0);
       Form1.ScrollToEnd(Form1.Richedit1);
    //   Form1.Say(Form1.Richedit1,BuildStr,False,False,False);
      End;
     Cut:='';
   End;


 if copy(cut,1,6)='/calc2' then
   Begin
    Form1.Richedit1.SelAttributes.Color:=ClRed;
    Delete(Cut,1,7);
    Form1.Richedit1.Lines.Add(Cut+' = '+Calculate(Cut,''));
    Cut:='';
    Form1.Richedit1.SelAttributes.Color:=ClBlack;
   End;

  if copy(cut,1,5)='/diag' then
   Begin
    Form1.Richedit1.SelAttributes.Color:=ClRed;
    Delete(Cut,1,7);
    Form1.Say(Form1.Richedit1,QuickInfo,False,False,False);
 //   Form1.Richedit1.Lines.Add(QuickInfo);
    Cut:='';
    Form1.Richedit1.SelAttributes.Color:=ClBlack;
   End;


  if copy(cut,1,5)='/calc' then
   Begin
    Form1.Richedit1.SelAttributes.Color:=ClRed;
    Delete(Cut,1,6);
    Form1.Say(Form1.Richedit1,Cut+' = '+Calculate(Cut,''),False,False,False);
    Cut:='';
   End;

  if copy(cut,1,8)='/tagline' then
   Begin
    Form1.Richedit1.SelAttributes.Color:=ClRed;
    Form1.Say(Form1.Richedit1,Form1.GetTagLine,False,False,False);
    Cut:='';
   End;

  if copy(cut,1,7)='/gender' then
   begin
     M:=0; F:=0; U:=0;
     Cut:='';
     For N:=Form1.ListBox1.Items.Count-1 downto 0 Do
      Begin
      If (Chatters[Form1.ChatterNum(Form1.ListBox1.Items[N])].UserName<>'') and (Chatters[Form1.ChatterNum(Form1.ListBox1.Items[N])].Extra<>'') Then
       Begin
        If UserGender(Chatters[Form1.ChatterNum(Form1.ListBox1.Items[N])].Extra)='Male' Then Inc(M);
        If UserGender(Chatters[Form1.ChatterNum(Form1.ListBox1.Items[N])].Extra)='Female' Then Inc(F);
        If UserGender(Chatters[Form1.ChatterNum(Form1.ListBox1.Items[N])].Extra)='Unknown' Then Inc(U);
       End;
      End;
     Form1.Say(Form1.Richedit1,'There are: '+IntToStr(M)+' Males and '+IntToStr(F)+' Females in this room... ('+IntToStr(U)+' Unknown?) ('+IntToStr(Form1.ListBox2.Items.Count)+' ignored)',False,False,False);
   End;

  if copy(cut,1,14)='/list females' then
   begin
     BuildStr:='';
     M:=0; F:=0; U:=0;
     Cut:='';
     For N:=Form1.ListBox1.Items.Count-1 downto 0 Do
      If (Chatters[Form1.ChatterNum(Form1.ListBox1.Items[N])].UserName<>'') and (Chatters[Form1.ChatterNum(Form1.ListBox1.Items[N])].Extra<>'') Then
        If UserGender(Chatters[Form1.ChatterNum(Form1.ListBox1.Items[N])].Extra)='Female' Then BuildStr:=BuildStr+' '+Chatters[Form1.ChatterNum(Form1.ListBox1.Items[N])].UserName+', ';
     BuildStr:=Copy(BuildStr,1,Length(BuildStr)-2);
     Form1.Say(Form1.Richedit1,'All the Females: '+BuildStr,False,False,False);
   End;


  if copy(cut,1,13)='/list clients' then
   begin
     BuildStr:='';
     Cut:='';
     U:=0;
     SetLength(CList,2);
     Clist[1].CN:='Y!mLite';
     Clist[1].CC:=1;
     For N:=Form1.ListBox1.Items.Count-1 downto 0 Do
      If (Chatters[Form1.ChatterNum(Form1.ListBox1.Items[N])].UserName<>'') Then
      Begin
       CN:=Chatters[Form1.ChatterNum(Form1.ListBox1.Items[N])].ChatClient;
       If Cn<>'' Then
         Begin
          R:=-1;
            For N2:=1 to High(Clist) Do
             If Clist[N2].CN=CN Then
              Begin
                R:=N2;
                Break;
              End;
           If R<>-1 Then
             Inc(Clist[R].CC)
           else
            Begin
              SetLength(Clist,High(Clist)+2);
              Clist[High(Clist)].CN:=Cn;
              Clist[High(Clist)].CC:=1;
            End;
         End
          Else
           If Chatters[Form1.ChatterNum(Form1.ListBox1.Items[N])].NumLinesPosted=0 Then
            Inc(U)
             else
            Inc(U2);
       End;
     For N:=1 to High(Clist) Do 
      If Trim(Clist[N].CN)<>'' Then
        BuildStr:=BuildStr+Clist[N].CN+': '+IntToStr(Clist[N].CC)+' , ';
     Clist:=Nil;
     BuildStr:=Copy(BuildStr,1,Length(BuildStr)-3);
     If Trim(BuildStr)<>'' Then
       Form1.Say(Form1.Richedit1,'Client Count, '+BuildStr+', Unknown: '+IntToStr(u2)+', To Detect, '+IntToStr(U-1),False,False,False);
   End;

  if copy(cut,1,12)='/list males' then
   begin
     BuildStr:='';
     M:=0; F:=0; U:=0;
     Cut:='';
     For N:=Form1.ListBox1.Items.Count-1 downto 0 Do
      If (Chatters[Form1.ChatterNum(Form1.ListBox1.Items[N])].UserName<>'') and (Chatters[Form1.ChatterNum(Form1.ListBox1.Items[N])].Extra<>'') Then
        If UserGender(Chatters[Form1.ChatterNum(Form1.ListBox1.Items[N])].Extra)='Male' Then BuildStr:=BuildStr+' '+Chatters[Form1.ChatterNum(Form1.ListBox1.Items[N])].UserName+', ';
     BuildStr:=Copy(BuildStr,1,Length(BuildStr)-2);
     Form1.Say(Form1.Richedit1,'All the Males: '+BuildStr,False,False,False);
   End;


   if copy(cut,1,14)='/list unknowns' then
   begin
     BuildStr:='';
     M:=0; F:=0; U:=0;
     Cut:='';
     For N:=Form1.ListBox1.Items.Count-1 downto 0 Do
      If (Chatters[Form1.ChatterNum(Form1.ListBox1.Items[N])].UserName<>'') and (Chatters[Form1.ChatterNum(Form1.ListBox1.Items[N])].Extra<>'') Then
        If UserGender(Chatters[Form1.ChatterNum(Form1.ListBox1.Items[N])].Extra)='Unknown' Then BuildStr:=BuildStr+' '+Chatters[Form1.ChatterNum(Form1.ListBox1.Items[N])].UserName+', ';
     BuildStr:=Copy(BuildStr,1,Length(BuildStr)-2);
     Form1.Say(Form1.Richedit1,'All the Unknowns: '+BuildStr,False,False,False);
   End;

   if copy(cut,1,8)='/blocked' then
   begin
     Cut:='';
     Form1.Say(Form1.Richedit1,Form1.Panel10.Caption,False,False,False);
   End;


  if copy(cut,1,5)='/time' then
   begin
     Cut:='';
     Form1.Say(Form1.Richedit1, FormatDateTime('"Today is " dddd, mmmm d, yyyy, " at " hh:mm AM/PM', Now {+ 0.125}),False,False,False);
   End;

 If Copy(Cut,1,5)='/pipe' Then
  Begin
   Delete(Cut,1,6);
   CreateThread(Nil,0,@CreatePipeThread,@Cut,0,Th);
   Form1.Delay(10);
   Cut:='';
  End;

  if copy(Cut,1,5)='/fork' Then
   Begin
    Cut:='';
    WinExec(Pchar(Application.ExeName),Sw_Normal);
   End;

  if copy(cut,1,4)='/cmd' then
   begin
     Delete(Cut,1,5);
     If PosRep(' ',Cut)>0 Then
      Begin
       Tmp1:=Copy(Cut,1,PosRep(' ',Cut)-1);
       Delete(Cut,1,Length(Tmp1)+1);
      End
       else
      Begin
       Tmp1:=Cut;
       Cut:='';
      End;
     ShellExecute(Handle,'OPEN',Pchar(Tmp1),Pchar(Cut),'',SW_Show);
     Cut:='';
   End;

  if copy(cut,1,4)='/pkt' then
   begin
     Delete(Cut,1,5);
     BuildPacketFromStr(Cut);
     Cut:='';
   End;


  if copy(cut,1,6)='/dayna' then
   begin
     Cut:='';
     D1:=EncodeDateTime(2002,9,10,3,23,1,0);
  //   WeekDays[DayOfTheWeek(D1)]+') '+DateToStr(D1)+' and now '+DateToStr(Now)+' the difference between the two dates are: '+IntToStr(DaysBetween(Now,D1))+' Days or '+IntToStr(MinutesBetween(Now,D1))+' Minutes :)');
     Form1.Say(Form1.Richedit1,'Dayna is '+Form1.BuildTime(SecondsBetween(Now,D1))+' Old :)',False,False,False);
   End;

  if copy(cut,1,4)='/url' then
   begin
     Delete(Cut,1,5);
     TConvertURLsToIps.Create(Cut);
     Cut:='';
   End;


  if copy(cut,1,6)='/knock' then
   begin
    Delete(Cut,1,7);
    Cut:=Trim(Cut);
    IF (Cut<>'') And (LowerCaseRep(Cut)<>LowerCaseRep(RoomName)) Then
       If Assigned(Knock)=False Then
        Begin
          Knock:=TKnock.Create(Cut,(60*1000)*3,StrToInt(Form10.Edit12.Text));
          Knock.StartKnocking;
         End;
      If Cut='' Then
       Begin
         If Knock<>Nil Then
          Begin
           Form1.RoomJoinWait:=False;
           Knock.StopKnock;
           Knock.Free;
           Knock:=Nil;
          End; 
       End;
    Cut:='';
   End;

{  if copy(cut,1,3)='/kn' then
   Begin
    Cut:='';
     If KnightRider=Nil Then
       KnightRider:=TKnightRider.Create(PaintBox1,ClRed,ClBlack,25,200,50)
        else
       KnightRider.Free;
   End;}

    if copy(cut,1,4)='/egg' then
   begin
    if Form17.LightSpeed1.Active=False Then
     Begin
     Form17.Image1.picture:=nil;
     Form17.LightSpeed1.Active:=True;
     Form10.SpinEdit13.Value:=155;
     Form1.spDynamicSkinForm1.AlphaBlendValue:=155;
     Form1.SpDynamicSkinForm1.AlphaBlend:=True;
     Form17.LightSpeed1.Visible:=True;
//     Form1.SetTransparentForm(Form1.Handle,Form10.SpinEdit13.Value);
     Form17.Show;
     Form1.BringToFront;
     Cut:='';
     End
      else
     Begin
      Form17.LightSpeed1.Active:=False;
      Form17.Hide;
      //        Form1.SetTransparentForm(Form1.Handle,Form10.SpinEdit13.Value)
//       else
      //        Form1.SetTransparentForm(Form1.Handle,255);
      Form1.SpDynamicSkinForm1.AlphaBlendValue:=Form10.SpinEdit13.Value;
      Form1.SpDynamicSkinForm1.AlphaBlend:=False;
      Cut:='';
     End;
   End;


   {  If SWF=Nil Then
         Begin
          Try
            SwF:=TShockWaveFlash.Create(form1);
             except
            ShowMessage('Flash 9 is Required');
            Exit;
            End;
          End;
       Panel1.Align:=AlLeft;
       SpSkinButton13.Align:=AlBottom;
       SpSkinComboBox5.Align:=AlBottom;
       SpSkinSplitter1.Visible:=True;
       SpSkinSplitter1.Left:=Panel1.Width+1;
        If Form1.OldPanelLength>=Form1.Width-20 Then
             Form1.OldPanelLength:=280;
        Panel1.Width:=Form1.OldPanelLength;
       swf.Visible:=true;
       swf.SAlign:='15';
       Swf.Align:=AlClient;
       Swf.Height:=Panel1.Height-SpSkinButton13.Height-SpSkinComboBox5.Height-3;
       Swf.Width:=Swf.Width;
       swf.ParentWindow:=form1.Panel1.Handle;
       swf.LoadMovie(0,'http://www.youtube.com/v/46LQd9dXFRU');
       Swf.Tag:=1;}


 { if copy(cut,1,5)='/egg3' then
   begin
    if Form17.Timer2.Enabled=False Then
     Begin
     Form17.Timer2.Interval:=60;
     Form17.Image1.picture:=nil;
     Form17.Timer2.Enabled:=True;
     Form10.SpinEdit13.Value:=175;
     Form1.SetTransparentForm(Form1.Handle,Form10.SpinEdit13.Value);
     Form17.Show;
     Form1.BringToFront;
     Cut:='';
     End
      else
     Begin
      Form17.Timer2.Enabled:=False;
      Form17.Hide;
      If Form10.CheckBox31.Checked=True Then
        Form1.SetTransparentForm(Form1.Handle,Form10.SpinEdit13.Value)
          else
        Form1.SetTransparentForm(Form1.Handle,255);
       Cut:='';
     End;
   End;}


{   if copy(cut,1,5)='/egg' then
   begin
    If KnightRider=False Then
     Begin
       EggColor:=ClRed;
       For N:=10 downto 0 do
        If ProgButtons[N]<>Nil Then
          ProgButtons[N].Font.Color:=TColor($F0FBFF);
       KnightRider:=True;
      End
        else
       Begin
        KnightRider:=False;
        Delay(2000);
         For N:=10 downto 0 do
          Begin
           If ProgButtons[N]<>Nil Then
            Begin
              ProgButtons[N].Font.Color:=Form10.ColorBox6.ColorValue;
              TfadeWindow.Create(ProgButtons[n],Form10.ColorBox5.ColorValue,ClBlue,20,900-(N*100));
            End;
          End;
       End;
     KnC:=0;
     Cut:='';
   End;}



  if copy(cut,1,5)='/xmas' then
   begin
     Cut:='';
     DecodeDate(Now, Year, Month, Day);
     If (Month=12) and (Day>25) Then
       Inc(Year);
     D1:=EncodeDateTime(Year,12,25,0,0,1,0);
     Form1.Say(Form1.Richedit1,IntToStr(DaysBetween(Now,D1))+' Days or '+IntToStr(HoursBetween(Now,D1))+' hours until christmas day :)',False,False,False);
   End;


  if copy(cut,1,8)='/newyear' then
   begin
     Cut:='';
     DecodeDate(Now, Year, Month, Day);
     D1:=EncodeDateTime(Year+1,1,1,0,0,1,0);
     Form1.Say(Form1.Richedit1,IntToStr(DaysBetween(Now,D1))+' Days or '+IntToStr(HoursBetween(Now,D1))+' hours until new year''s day :)',False,False,False);
   End;


  if copy(cut,1,8)='/time to' then
   begin
     Delete(Cut,1,9);
     //Now+D1:=EncodeTime(2002,9,10,3,23,1,0);
   // WeekDays[DayOfTheWeek(D1)]+') '+DateToStr(D1)+' and now '+DateToStr(Now)+' the difference between the two dates are: '+IntToStr(DaysBetween(Now,D1))+' Days or '+IntToStr(MinutesBetween(Now,D1))+' Minutes :)');
   End;


{  if PosRep('days from: [',restofmsg)>0 then
begin
  D1:=0;
  Day:=0;
  Month:=0;
  where:=PosRep('m: [',restofmsg)+4;
  num1:=PosRep(']',restofmsg)-where;
  calcst:=copy(restofmsg,where,num1);
  BuildStr:='';
if where>0 then
  begin
      Tmp:=Copy(CalcSt,1,PosRep(',',CalcSt)-1);
      Delete(CalcSt,1,Length(Tmp)+1);
      Val(Tmp,Year,Err);
      If Err=0 Then
       Begin
         Tmp:=Copy(CalcSt,1,PosRep(',',Calcst)-1);
         Delete(CalcSt,1,Length(Tmp)+1);
         Val(Tmp,Month,Err);
         If Month>12 Then
           Err:=1;
          If Err=0 Then
           Begin
             Val(Calcst,Day,Err);
              If Err<>0 Then
                BuildStr:=BuildStr+' Error with Day ';
           end
            else
             BuildStr:=BuildStr+' Error With Month..(YYYY/MM/DD)';
         End
        else
      BuildStr:=BuildStr+'Error With Year';
       If BuildStr='' Then
         Begin
           If (day>0) and (month>0) and (year>0) and (year<=9999) and (day<=LastDayOfMonth(Month,Year)) Then
             Begin
             Try
              D1:=EncodeDate(Year,Month,Day);
                Except;
              End;
              Say('Between (Which btw is a '+WeekDays[DayOfTheWeek(D1)]+') '+DateToStr(D1)+' and now '+DateToStr(Now)+' the difference between the two dates are: '+IntToStr(DaysBetween(Now,D1))+' Days or '+IntToStr(MinutesBetween(Now,D1))+' Minutes :)');
             End
               else
              Say('Use it correctly! with days from: [YYYY,MM,DD]');
         End
          else
      Say(BuildStr);
     end;
   End;}



  if copy(cut,1,7)='/uptime' then
   begin
     BuildStr:='';
     Cut:='';
     BuildStr:=BuildTime(Trunc(GetTickCount/1000));
     Form1.Say(Form1.Richedit1,'This computer has been up for '+BuildStr,false,False,False);
  end;

   if copy(cut,1,9)='/typetime' then
   begin
     BuildStr:='';
     Cut:='';
     Form1.Say(Form1.Richedit1,'Time Spent Typing: '+BuildTime(ActualTimeTyping)+' Since '+DateTimeToStr(TimeLoggedTyping),false,False,False);
  end;


  if copy(cut,1,11)='/ymlitetime' then
   begin
     BuildStr:=BuildTime(TotalTime);
      Cut:='';
     Form1.Say(Form1.Richedit1,'Y!mLite''s Global Uptime has been '+BuildStr,false,False,False);
  end;


  If Copy(Cut,1,5)='/ping' Then
    Begin
      Cut:='';
      PingT:=GetTickCount;
      PingRes:='[y!mlite ping]'+IntToStr(Random(65535));
    //  Delay(10);
      Form1.SayPm(LoggedInName,LoggedInName,PingRes);
    End;


  if copy(cut,1,9)='/roomtime' then
   begin
     Cut:='';
     RunTime:=RoomTime;
     BuildStr:=BuildTime(RoomTime);
     Form1.Say(Form1.Richedit1,'I have been in this chat room ( '+RoomName+' ) for '+BuildStr,false,False,False);
  end;

  if copy(cut,1,8)='/runtime' then
   begin
    Cut:='';
    Form1.Say(Form1.Richedit1,YmLiteLogo+' Has been running for: '+BuildTime(RunningTime),false,False,False);
  end;

   if copy(cut,1,11)='/igemoteoff' then
   begin
    Form18.CheckBox1.Checked:=False;
    Form18.CheckBox2.Checked:=False;
    Form1.Richedit1.Lines.Add('Ignore Emotes Now Off!');
    Cut:='';
   end;

   if copy(cut,1,10)='/igemoteon' then
   begin
    Form18.CheckBox1.Checked:=True;
    Form18.CheckBox2.Checked:=True;
    Form1.Richedit1.Lines.Add('Ignore Emotes Now On!');
    Cut:='';
   end;


   if copy(cut,1,8)='/ignorec' then
   begin
    Cut:='';
     For N:=Form1.ListBox2.Items.Count-1 Downto 0 do
       BuildStr:=BuildStr+Form1.ListBox2.Items[N]+' , ';
      BuildStr:=Copy(BuildStr,1,Length(BuildStr)-3);
    Form1.Say(Form1.Richedit1,'Users Ignored: '+BuildStr,false,False,False);
  end;

  If Copy(Cut,1,6)='/butt:' Then
   Begin
     Delete(Cut,1,6);
     If Trim(Cut)<>'' Then
      Begin
      Form1.Richedit2.Text:='';
      Cmd:=Form1.LoadButtonInfo(cut,'Command','');
      Cr:=Form1.LoadButtonInfo(cut,'Cr','');
      Form1.richedit2.SelText:=Cmd;
      If Cr='True' Then
       Form1.Button1.OnClick(nil);
      Cut:=''
     End;
   End;

  if copy(cut,1,8)='/budlist' then
   begin
     Cut:='';
     BuildStr:=Form1.GetFriends;
     Form1.Say(Form1.Richedit1,Form24.Edit1.Text+' '+BuildStr+' '+Form24.Edit2.Text,False,False,False);
  end;

  if copy(cut,1,9)='/byebuds' then
   begin
    Cut:='';
    BuildStr:=Form1.GetFriends;
    Form1.Say(Form1.Richedit1,Form24.Edit3.Text+' '+BuildStr+' '+Form24.Edit4.Text,False,False,False);
  end;


 if copy(cut,1,13)='/buildmp3list' then
  Begin
   Cut:='';
   If MessageDlg('Options (Menu > Yahoo > Y!options > [Misc Tab]) Indicates your mp3 path is '+Form10.Edit2.Text,MtConfirmation,[mbyes,mbno],0)=IdYes Then
     Mp3Control.BuildMp3FileDb;
  End;


 if copy(cut,1,11)='/random mp3' then
   begin
    Delete(Cut,1,12);
    Mp3Control.PlayPartialMatch(Cut);
    //    Mp3Control.PlayRandomMp3;
//    PlayRandomMp3(Cut);
    Cut:='';
  end;


  if copy(cut,1,7)='/browse' then
   begin
    Delete(Cut,1,8);
//    If ProfileWindow=Nil Then
 //     ProfileWindow:=TForm16.Create(Self);
  //  Form1.CreateSkin(ProfileWindow);
 //   ProfileWindow.Show;
 //   ProfileWindow.WebBrowser1.Navigate(Cut);
      ShellExecute(handle,'open',Pchar(Cut),'','',0);
    Cut:='';
   end;



  if copy(cut,1,7)='/winamp' then
   begin
    Delete(Cut,1,7);
    Form1.Richedit1.SelAttributes.Color:=ClRed;
    Form1.Say(Form1.Richedit1,Form1.Mp3Control.Winamp+Cut,False,False,False);
    Cut:='';
    Form1.Richedit1.SelAttributes.Color:=ClBlack;
   end;

  if copy(cut,1,8)='/smp3amp' then
   begin
    Delete(Cut,1,9);
    Form1.Richedit1.SelAttributes.Color:=ClRed;
    Form1.Say(Form1.Richedit1,Form1.Mp3Control.SMP3PlayerString+Cut,False,False,False);
    Cut:='';
    Form1.Richedit1.SelAttributes.Color:=ClBlack;
   end;

  if copy(cut,1,5)='/yamp' then
   begin
    IF YampList=Nil Then Exit;
    Delete(Cut,1,6);
    Form1.Richedit1.SelAttributes.Color:=ClRed;
    Cut:='';
    Form1.Say(Form1.Richedit1,'Y!mLite Amp is Playing: '+ExtractFileName(YampList.Strings[YampTrack])+'  '+Cut,False,False,False);
    Form1.Richedit1.SelAttributes.Color:=ClBlack;
   end;

  if copy(cut,1,8)='/playmp3' then
   begin
    Delete(Cut,1,9);
    Form1.PlayMp3(Cut);
     Cut:='';
   end;


  if copy(cut,1,6)='/ultra' then
   begin
    Delete(Cut,1,7);
    Form1.Richedit1.SelAttributes.Color:=ClRed;
    Form1.Say(Form1.Richedit1,Mp3Control.UltraMP3PlayerString+Cut,False,False,False);
    Cut:='';
    Form1.Richedit1.SelAttributes.Color:=ClBlack;
   end;


  if copy(cut,1,8)='/mplayer' then
   begin
    Delete(Cut,1,9);
    Form1.Richedit1.SelAttributes.Color:=ClRed;
    Form1.Say(Form1.Richedit1,Mp3Control.MediaPlayerString+Cut,False,False,False);
    Cut:='';
    Form1.Richedit1.SelAttributes.Color:=ClBlack;
   end;


  if copy(cut,1,3)='/im' then
   begin
    Delete(Cut,1,4);
    Form1.PmImUser(Trim(Cut));
    Cut:='';
   end;

  if copy(cut,1,5)='/norm' then
   begin
    GVN:=#$0F;
    Form1.SendText(Form1.LoginString2(LoggedInName,0));
    Form1.Richedit1.Lines.Add('Messenger Mode Returned To Normal... (p.s since the new yahoo upgrades, this no longer works but i left it in anyway)');
//    Key:='';
    Cut:='';
   end;

   if copy(cut,1,6)='/cmode' then
   begin
    Form1.Richedit1.Lines.Add('Standard Unbootable Mode Entered (but no pms /norm to return)');
    GVN:=#$0F;
    Form1.SendText(Form1.LoginString2(LoggedInName,1));
    Cut:='';
   end;

  if copy(cut,1,5)='/gawd' then
   begin
    Form1.SendText(Form1.LoginString2(LoggedInName,2));
    Form1.Richedit1.Lines.Add('Gawd Mode Experimental - /cmode to come out of it.');
    GVN:=#$0A;
    Cut:='';
   end;

   if copy(cut,1,5)='/ack2' then
   begin
    Form1.Richedit1.Lines.Add('Room Ack Sent');
    Form1.SendText(RoomAck2(LoggedInName,RoomName)); //marker1
    Cut:='';
   end;

   if copy(cut,1,6)='/leave' then
   begin
    Form1.Richedit1.Lines.Add('Room Leave Sent');
    Form1.SendText(LeaveRoom(LoggedInName,GVN));
    Cut:='';
   end;



  if copy(cut,1,4)='/ack' then
   begin
    Form1.Richedit1.Lines.Add('Room Ack Sent');
    Form1.SendText(RoomAck(LoggedInName,RoomName)); //marker1
    Cut:='';
   end;



  if copy(cut,1,3)='/ts' then
   begin
    Delete(Cut,1,4);
    TestSpeech(Cut);
    Cut:='';
   end;

  if copy(cut,1,3)='/pm' then
   begin
    Delete(Cut,1,4);
    Form1.PmImUser(Trim(Cut));
    Cut:='';
   end;

 if copy(cut,1,7)='/ignore' then
  begin
   IgC:=0;
   Delete(Cut,1,8);
   Tmp2:=Cut;
   If PosRep('*',Cut)>0 Then
   Begin
   Tmp2:=Copy(Cut,1,PosRep('*',Cut)-1);
    If MessageDlg('Would you like to add "'+Tmp2+'" to the permanent filter (That is ignore anyone who enters the room which contains "'+Tmp2+'" in their ID)',MtConfirmation,[mbyes,mbno],0)=IDYEs Then
     Begin
     If Form10.Edit6.Text='' Then
        Form10.Edit6.Text:=Tmp2
         else
       If PosRep(','+tmp2,Form10.Edit6.Text)=0 Then
         Form10.Edit6.Text:=Form10.Edit6.Text+','+Tmp2;
      End;
     For N:=Form1.ListBox1.Items.Count-1 Downto 0 do
      Begin
       If (PosRep(LowerCaseRep(Tmp2),LowerCaseRep(Form1.ListBox1.Items[N]))>0) And (NeverIgnore.IndexOf(Form1.ListBox1.Items[N])=-1) Then
        Begin
         Inc(IgC);
         Cut:=Form1.ListBox1.Items[N];
         Form1.IgnoreUser(cut,True,False,False,False);
        End;
      End;
     If IgC=1 Then
      Begin
      If NeverIgnore.IndexOf(Cut)=-1 Then
         Form1.Say(Form1.Richedit1,Form1.MakeEmote(Form18.Edit2.text,Cut),false,True,False);
      End;
     If IgC>1 Then
      Begin
         Form1.Say(Form1.Richedit1,IntToStr(IGc)+' Users Ignored From The Room Matching with "'+Tmp2+'" In the ID.',False,False,False);
      End;
   End
  else
   Begin
     Form1.IgnoreUser(cut,false,False,False,False);
   End;
   Cut:='';
  End;

 if copy(cut,1,4)='/cls' then
   begin
    RichCont.Clear;
    RichCont.Paragraph.Alignment:=taLeftJustify;
    SendMessage(Richedit1.Handle,EM_SETZOOM,EMZoom,64);
    Cut:='';
   end;

{ if copy(cut,1,4)='/key' then
   begin
     Delete(Cut,1,5);
     Key:=#$FF+#$FF+#$FF+#$FF;
     Cut:='';
   end;}


  If Copy(Cut,1,5)='/help' then
    Begin
     Form1.richedit1.Lines.Add(Form1.spSkinComboBox1.Items.Text);
     Cut:='';
    End;


 if copy(cut,1,4)='/ver' then
   begin
    Cut:='';
     If Form1.spSkinCheckRadioBox1.Checked=True Then
      Begin
      Form1.spSkinCheckRadioBox1.Checked:=False;
      Form1.Say(Form1.Richedit1,'******Y!mLite Build '+ClientVer+'******',False,False,False);
      Form1.spSkinCheckRadioBox1.Checked:=True;
     End
      else
    Form1.Say(Form1.Richedit1,'******Y!mLite Build '+ClientVer+'******',False,False,False);
   end;

If Copy(Cut,1,7)='/extend' Then
  Begin
   Delete(Cut,1,8);
   Tmp1:=Copy(Cut,1,PosRep(' ',cut)-1);
   Delete(Cut,1,Length(Tmp1)+1);
   Tmp2:=Cut;
   Cut:='';
   UWI:=RegisterWindowMessage('WM_YahELiteExt');
   ExtWnd:=FindWindow(Pchar(Tmp1),Pchar(Tmp2));
   If Extwnd<>0 Then
     Form1.Richedit1.Lines.Add('Extension Active')
      else
     Form1.Richedit1.Lines.Add('Extension Not Found!');
  End;

  if copy(cut,1,5)='/exit' then
  begin
    Cut:='';
    Form1.Close;
  end;

 If Copy(Cut,1,3)='/ex' Then
  Begin
   Delete(Cut,1,4);
   Form1.SendExtCmd(Cut);
   Cut:='';
  End;


{ if copy(cut,1,4)='/eye' then
   begin
     Form1.Richedit1.Lines.add('Eye is Disabled for now....');
     Exit;
     Form1.Eye.Port:=Form1.Ymsg.Port;
     form1.Eye.Host:=Form1.Ymsg.Host;
     Form1.Eye.UserName:=Form2.SpSkinEdit1.Text;
     Form1.Eye.Password:=Form2.SpSkinPasswordEdit1.Text;
     Form1.Eye.RoomName:=Form2.ComboBox3.Text;
     Form1.Eye.Connect;
     Cut:='';
   End;}

 if copy(cut,1,5)='/join' then
   begin
     delete(cut,1,6);
     If (Cut='') And (BumpRoom<>'') Then
        Form1.SendText(Form1.JoinRoom(Loggedinname,BumpRoom))
         else
     Form1.SendText(Form1.JoinRoom(Loggedinname,Cut));
     Cut:='';
   end;

if copy(cut,1,8)='/refresh' then
   begin
     delete(cut,1,6);
     Form1.SendText(Form1.Stealth);
     Cut:='';
   end;


if copy(cut,1,4)='/log' then
   begin
     delete(cut,1,5);
     ExtractDetails(Cut);
     Cut:='';
   end;



if copy(cut,1,8)='/alphacs' then
   begin
     Cut:='';
//     Form2.BumpingCheckbox.Checked:=False;
//     Form2.BootResistant1.checked:=False;
     Form1.WorkingDetails.Server:='alphacs1.msg.dcn.yahoo.com';
     Form1.WorkingDetails.Port:=5050;
     Form2.BitBtn3.OnClick(self);
     Cut:='';
   end;


 if copy(cut,1,5)='/ych1' then
   begin
//     Form2.BumpingCheckbox.Checked:=False;
//     Form2.BootResistant1.checked:=False;
     Form1.WorkingDetails.Server:='alphacs1.msg.dcn.yahoo.com';
     Form2.RoomBox.Text:='Yahoo! Chat Help:1::1600326597';
     Form1.WorkingDetails.Port:=5050;
     Form2.BitBtn3.OnClick(self);
     Cut:='';
   end;

 if copy(cut,1,5)='/ych2' then
   begin
//     Form2.BumpingCheckbox.Checked:=False;
//     Form2.BootResistant1.checked:=False;
     Form1.WorkingDetails.Server:='alphacs1.msg.dcn.yahoo.com';
     Form2.RoomBox.Text:='Yahoo! Chat Help:2::1600326597';
     Form1.WorkingDetails.Port:=5050;
     Form2.BitBtn3.OnClick(self);
     Cut:='';
   end;


   
if copy(cut,1,8)='/connect' then
   begin
     delete(cut,1,9);
     If Cut='' Then
      Begin
       Form1.WorkingDetails.Server:='';
       Form1.Richedit1.Lines.Add('Override disabled');
       Exit;
      End;
//     Form2.BumpingCheckbox.Checked:=True;
//     Form2.BootResistant1.checked:=False;
     Wp1:=PosRep(':',Cut);
     Tmp:=Copy(Cut,1,Wp1-1);
     Delete(Cut,1,Wp1);
     Form1.WorkingDetails.Server:=Tmp;
     Form1.WorkingDetails.Port:=StrToInt(Cut);
     ///connect alphacs1.msg.dcn.yahoo.com:5050
     Form2.BitBtn3.OnClick(self);
     Cut:='';
   end;


if copy(cut,1,6)='/merge' then
   begin
     Cut:='';
     TFileDownload.Create('http://ymlitechat.com/ymlite/botstrings.txt',Path+'botmergestrings.txt','80',0,Nil,False,True,True,False);
   end;

if copy(cut,1,6)='/halfp' then
   begin
   If PingP<>'' Then
     Begin
      Form1.SendText(PingP);
      PingP:='';
      Tmp2:='';
      Exit;
     End;
     Cut:='';
     PingP:=Ping(loggedinname);
    // PingP:='123456';
     Tmp2:=Copy(PingP,1,Length(PingP)-3);
     Delete(PingP,1,Length(Tmp2));
     Form1.SendText(Tmp2);
   end;


if copy(cut,1,9)='/savelist' then
   begin
     Cut:='';
     Form1.PornBotTracker.SaveStringsList;
     Form1.Richedit1.Lines.Add('Tracker List Saved');
   End;

if copy(cut,1,9)='/iggylist' then
   begin
     Cut:='';
     Form1.ListBox2.Items.SaveToFile(Path+'localiggy.txt');
     Form1.Richedit1.Lines.Add('Local Iggy Saved');
   End;



if copy(cut,1,10)='/caminvite' then
   begin
     delete(cut,1,10);
     Form1.Richedit1.lines.Add('You have invited '+Cut+' To view your cam!');
     Form1.InviteToViewCam(Cut);
     Cut:='';
   end;


if copy(cut,1,7)='/invite' then
   begin
     delete(cut,1,8);
     Form1.Richedit1.lines.Add('You have invited '+Cut+' To chat with you..');
     Form1.Invite(Cut,False,False,False);
     Cut:='';
   end;

   if copy(cut,1,8)='/lagtime' then
   begin
     delete(cut,1,9);
     Form1.Say(Form1.Richedit1,yRed+'Calculating '+YBlue+'Lag Time'+YBlack+'.... ',False,True,False);
     Form1.Invite(LoggedInName,True,False,False);
     Cut:='';
   end;

{   if copy(cut,1,5)='/goto' then
   begin
     delete(cut,1,6);
     Form1.SendText(Form1.GotoUserP2(Loggedinname,Cut));
     Cut:='';
   end;}

   if (copy(cut,1,11)='/voicelocal') or (copy(cut,1,11)='/localvoice')then
    Begin
       VoiceLocal:=Not VoiceLocal;
       If VoiceLocal=True Then
           Form1.Richedit1.Lines.Add('Voice Host Set to 127.0.0.1')
            else
          Form1.Richedit1.Lines.Add('Voice Override Disabled');
       cut:='';
       Exit;
    End;


  if copy(cut,1,5)='/goto' then
   begin
     delete(cut,1,6);
     //Form1.Say(Form1.Richedit1,yRed+'Attempting to goto '+YBlue+Cut+YBlack+'... ',False,True,False);
     Form1.Richedit1.Lines.Add('Attempting to goto '+Cut);
     Form1.Invite(Cut,False,True,False);
     Cut:='';
   end;


   if copy(cut,1,6)='/think' then
   begin
     delete(cut,1,7);
     Form1.Say(Form1.Richedit1,yBlue+'. o 0 ( '+Cut+' )',False,True,False);
//     Form1.Say(Form1.Richedit1,yBlue+Cut,False,True);
     Cut:='';
   end;

if copy(cut,1,5)='/save' then
   begin
     SaveChatText;
     Cut:='';
   end;


if copy(cut,1,1)=':' then
 begin
 If Form1.MessengerStyleEmotes1.Checked=False Then
    Begin
      If (IsSmilePos(Cut)>0) and (IsSmilePos(Cut)<3) And (IsSmilePos(Cut)<>-1) And (Length(Cut)<5) Then
         Begin
          Form1.Say(Form1.Richedit1,Cut,False,False,False);
          Cut:='';
         End
           Else
        Begin
         delete(cut,1,1);
         Form1.Say(Form1.Richedit1,yBlue+Cut,False,True,False);
         Cut:='';
        End;
    End
      Else
    Begin
    //IsSmilePos(Cut)<3
     If (IsSmilePos(Cut)<>1) Then
         Begin
          delete(cut,1,1);
          Form1.Say(Form1.Richedit1,yBlue+Cut,False,True,False);
          Cut:='';
         End
       else
         Begin
          Form1.Say(Form1.Richedit1,Cut,False,False,False);
          Cut:='';
        End;
    End;
end;

 If Copy(Cut,1,11)='/fullduplex' Then
  Begin
   FullDuplex:=Not fullDuplex;
   Case FullDuplex Of
     True:  Form1.SendExtCmd('FullDuplex Mode On.');
     False: Form1.SendExtCmd('FullDuplex Mode Off.');
    End;
   Cut:='';  
  End;


 FromWho:=LoggedInName;


  If Copy(Cut,1,7)='/lpfoff' Then
  Begin
   Personality.Clear;
   Cut:='';
  End;


 If Copy(Cut,1,4)='/lpf' Then
  Begin
   Delete(Cut,1,5);
   If FileExists(Path+Cut+'.ypf') Then
    Begin
      Personality.LoadPersonality(Path+Cut+'.ypf');
    End;
   Cut:='';
  End;




 If Copy(Cut,1,3)='/mf' Then
  Begin
   Delete(Cut,1,4);
   Form1.Say(Form1.Richedit1,'The name "'+Cut+'" has been classed to be '+BoyGirl(Cut),True,False,False); BoyGirl(Cut);
   Cut:='';
  End;

   If Copy(Cut,1,7)='/silent' Then
  Begin
   Form1.Silent:=Not Form1.Silent;
   Cut:='';
  End;

 If (Copy(Cut,1,16)='/news headlines') or (Copy(Cut,1,10)='/headline>') Then
  Begin
   Delete(Cut,1,1);
   TGetNewsHeadlines.Create(Trim(Cut));
   Cut:='';
  End;

 If Copy(Cut,1,11)='/uk weather' Then
  Begin
   Delete(Cut,1,1);
   TWeather.Create(FromWho,Trim(Cut));
   Cut:='';
  End;

 If Copy(Cut,1,9)='/weather>' Then
  Begin
   Delete(Cut,1,1);
   TWeather.Create(FromWho,Trim(Cut));
   Cut:='';
  End;



 If (Copy(Cut,1,9)='/profile>') Then
  Begin
   Delete(Cut,1,9);
{    If ProfileWindow=Nil Then
     ProfileWindow:=TForm16.Create(Self);
   Form1.CreateSkin(ProfileWindow);
   ProfileWindow.WebBrowser1.Navigate('http://profiles.yahoo.com/'+Cut);
   ProfileWindow.Visible:=True;}
   ShellExecute(handle,'open',Pchar('http://profiles.yahoo.com/'+cut+'?warn=1'),'','',0);
   Cut:='';
  End;


  Form44.Memo1.Lines.Add('');
  Result:=Cut;
  Form1.ScrollToEnd(Form1.Richedit1);
End;


Function TForm1.LastCharPos2(Ch: Char; Str: String; StPos: Integer): Integer;
Var
 R,N: Integer;
Begin
If Str='' Then Exit;
 Result:=1;
  For N:=StPos Downto 0 do
    If Ch=Str[N] Then
     Begin
       LastCharPos2:=N;
       Break;
     End;
End;

procedure TForm1.Exit1Click(Sender: TObject);
begin
 Close;
end;


Function LoginSprtStr: String;
Var
   Key,PayLoad,S: String;
   Pay: Integer;
   Head: String;
begin
  Key:=#0+#0+#0+#0;
  Pay:=Length(Delim+'1'+delim+loggedInName+delim+'81'+Delim+LoggedInPassword+Delim+'104'+Delim+RoomName);
  PayLoad:=Form1.LengthToStr(Pay);
  S:='SPRT'+#0+#0+#0+#0+Key+Payload+#01+Delim+'1'+delim+loggedInName+delim+'81'+Delim+LoggedInPassword+Delim+'104'+Delim+RoomName;
  Result:=S;
End;


Function LoginSprtStrMessenger: String;
Var
   Key,PayLoad,S: String;
   Pay: Integer;
   Head: String;
begin
  Key:=#0+#0+#0+#0;
  Pay:=Length(Delim+'1'+delim+loggedInName+delim+'81'+Delim+LoggedInPassword+Delim+'104'+Delim+RoomName);
  PayLoad:=Form1.LengthToStr(Pay);
  S:='SPRT'+#0+#0+#0+#0+Key+Payload+#00+Delim+'1'+delim+loggedInName+delim+'81'+Delim+LoggedInPassword+Delim+'104'+Delim+RoomName;
  Result:=S;
End;


procedure TForm1.Login1Click(Sender: TObject);
begin
 GVN:=#$0F;
 BumpKnocks:=0;
 LastChatP:=Now;
 Timer5.Enabled:=False;
 Form1.RoomAckWait:=False;
 Form1.RoomJoinWait:=False;
 Form1.Disconnecting:=False;
 Timer7.Enabled:=True;
 Form1.InChat:=False;
 If Key<>'' Then
   Form1.SendText(LeaveRoom(LoggedInName,GVN));
 Key:='';
 If Form2.Visible=True Then
   Form2.Visible:=False;
Form12.ListBox1.Items.Clear;
// If RoomName<>'' Then
//  Form2.ComboBox3.Text:=RoomName;
 Form1.YMSG.Active:=False;
 Form1.SPRT.Active:=False;
 Form1.BooTResist:=0;
 Form2.ShowModal;
end;

Procedure TForm1.OnTimerProc(Sender: TObject);
Begin
 If (TimeStoppedTyping<3) Then
  Begin
   Inc(ActualTimeTyping);
   Inc(TimeStoppedTyping);
   Exit;
  End;

 Inc(TimeStoppedTyping);
  If TimeStoppedTyping>2 Then
   Begin
    ChatTimer.Enabled:=False;
    Dec(ActualTimeTyping,3);
   End;

If Form1.TimeSpentTyping1.Checked Then
   Form1.Panel10.Caption:='Time Spent Typing: '+BuildTime(ActualTimeTyping)+' Since '+DateTimeToStr(TimeLoggedTyping);
End;


procedure TForm1.FormCreate(Sender: TObject);
Var
// Tmp: String;
 N: Integer;
begin
  MyJPG:=TMemoryStream.create;
  GVN:=#$0F;
  VoiceLocal:=False;
  Form1.GenerateInviteKey;
  Form1.RoomAckWait:=False;
  Form1.RoomJoinWait:=False;
  Form1.BooTResist:=0;
  StealthMode:=False;
// Form1.SfFlashPlayer1.LoadMovie(0,'tempbanner.swf');
// Form1.SfFlashPlayer1.Play;
//  Debug:=False;
  DragAcceptFiles(Form1.handle,True);
  AllowVoiceList:=TStringList.Create;
  AllowVoiceList.Sorted:=True;
  AllowVoiceList.Duplicates:=dupIgnore;
  If FileExists(Path+'voicelist.txt') Then
    AllowVoiceList.LoadFromFile(Path+'voicelist.txt');
  FillChar(Form1.WorkingDetails,SizeOf(WorkingDetails),#0);
  RndServ:=0;
  FadeData.TCols:=TStringList.Create;
  PmWindows:=TStringList.Create;
  PmWindows.sorted:=True;
  ShowWindow(Application.Handle, SW_HIDE);
  SetWindowLong(Application.Handle, GWL_EXSTYLE,
  GetWindowLong(Application.Handle, GWL_EXSTYLE));
  ShowWindow(Application.Handle, SW_SHOW);
//  Application.Minimize;
//  HookAPI('WS2_32.dll', 'recv', @recvCallback, @recvNext);
{ If Form1.IsRunningNT=True Then
  CPUMonitor:=TGetCPuTime.Create(Tlabel(Form1.SpSkinLabel3))
   else
  Form1.spSkinLabel3.Free;}
// SetWindowLong(Application.Handle, GWL_EXSTYLE, GetWindowLong(Application.Handle,GWL_EXSTYLE) and not WS_EX_APPWINDOW or WS_EX_TOOLWINDOW);
 CCInstalled:=DirectoryExists('C:\program files\cheetachat\sounds');
 PornBotTracker:=TPornBots.Create;
 VoiceGaurd:=False;
 Form1.IDGapTimeLeft:=Now;
 Form1.IDGapTimeJoin:=Now;
// Form1.SpSkinLabel1.Hint:='Left = Time In Room '+CrLf+'Right = Average Disconnect Time'+CrLf+'S = Seconds M = Minutes';
 YahAvDCTime:=0;
 YahTotalDcTime:=0;
 ChatTimer:=TTimer.Create(Nil);
 ChatTimer.Interval:=1000;
 ChatTimer.OnTimer:=OnTimerProc;
 TimeStoppedTyping:=3;
 ChatTimer.Enabled:=True;
 FileDownloadWindows:=TList.Create;
//Tmp:=' ';
// MatchStr(pchar(tmp),pchar(tmp));
Form1.ReconnectIn:=5;
AverageDataKS:=1;
BootCount:=1;
Form1.Disconnecting:=False;
Form1.TrackList:=TStringList.Create;
TracKList.Sorted:=True;
Form1.InChat:=False;
//Form1.spSkinExPanel1.RollState:=True;
NClickCount:=0;
LastClick:=0;
Randomize;

 Gupdate:=False;
 DeleteBadIdentitars;
 If FileExists(Path+'ymlitenew.exe') Then
  DeleteFile(Path+'ymlitenew.exe');
 Richedit1.Font.Size:=10;
 Richedit1.ScrollBars:=SSVertical;
// Richedit2.ScrollBars:=ssNone;
 SkinList:=TList.Create;
 FullDuplex:=False;
 Nowrunning:=False;
 StyleMode:=0;
 SetLength(Chatters,2);
// ReIndexChatters;
 Mp3Control:=TMp3Library.Create;
// Application.OnMessage:=Form1.AppMessage;
 OrStyle:=GetWindowLong(Form1.Handle,GWL_EXSTYLE);
 Exiting:=False;
 DetectYaheliteUser:=False;
 IpAddress:='127.0.0.1';
 Egg:=False;
 Tc:=-1;
 InVoice:=False;
// DebugWindow:=Tform48.Create(Nil);
 VoiceList:=TStringList.Create;
 VoiceList.Sorted:=True;
 Smileys:=TStringHashTrie.Create;
 Smileys.CaseSensitive:=True;
// PersonalitySearch:=TStringList.Create;
// PersonalitySearch.Sorted:=True;
 Personality:=TobjPersonality.Create;
 GirlyFilter:=TobjPersonality.Create;
 Form1.ListBox1.DoubleBuffered:=True;
// Form1.RichEdit1.:=True;
 ConstructPacket:=0;
 TmpLeave:=TStringList.Create;
 TmpLeave.Sorted:=True;
 extractSmileyList;
 RestofDetails:=False;
 PingRes:='[y!mlite ping]'+IntToStr(Random(65535));
 ExtractedRoomList:=False;
 Randomize;
// FontComboBox1.Items.Assign(Screen.Fonts);
 UserFontSize:=10;
 Form1.ClearMessages;
 SetLength(SaidYourName,1);

 Hd:=TstringList.Create;
 If DirectoryExists(Path+'logs')=False Then
  CreateDir(Path+'logs');
// Path:=ExtractFilePath('hackersdict.txt');
 If FileExists(path+'HackersDict.Txt') Then
  Hd.LoadFromFile(path+'hackersdict.txt');
 CalledAppProcess:=False;
 ColBck:=$010000;
// Form1.ATouchofBlue1.Click;
 ChatBuffer:='';
 ScreenPaused:=False;
 FOleInterface := TREOleCallBack.Create;
 REOleSetCallback (Richedit1, FOleInterface);
// FOleInterface := TREOleCallBack.Create;
// REOleSetCallback (Richedit2, FOleInterface);
 MemoChanged:=True;
 Form1.Richedit1.SelStart:=-1;
 FaceCount:=0;
 SentK:=0;
 RecvK:=0;
 Form1.Richedit1.Clear;
// RichCont.SelAttributes.Protected:=True;
// SpSkinFontComboBox1.FontName:=FontComBoBox1.items[1];
 Words:=TStringList.Create;
 Friends:=TStringHashTrie.Create;
 Friends.CaseSensitive:=True;
 
 Buddies:=TStringList.Create;
 Buddies.Sorted:=True;
 OnlineBuddies:=TStringList.Create;
 OnlineBuddies.Sorted:=True;
  YmLiteLogo:=YRed+'Y'+yblue+'!'+ygreen+'m'+YRed+'L'+Yorange+'i'+Ygreen+'t'+ygreen+'e'+yblack;
 YmLiteLogo2:=YRed+'Y'+ygreen+'m'+YRed+'L'+Yorange+'i'+Ygreen+'t'+ygreen+'e'+yblack;
// N:=AddFontResource(Pchar('emoticon.fon'));
// SendMessage(HWND_BROADCAST,WM_FONTCHANGE,0,0);
 SendMessage(Form1.Richedit1.Handle, EM_AUTOURLDETECT, Longint(True), 0);
 N:=0;
 Test:=Test;
 UserFontSize:=10;
 Ignored:=TStringHashTrie.Create;
 Ignored.CaseSensitive:=True;
 NeverIgnore:=TStringList.Create;
 NeverIgnore.Sorted:=True;
 Tcols:=TStringList.Create;
 If FileExists(path+'Fade.Text')=True Then
 Begin
   Tcols.LoadfromFile(path+'Fade.Text');
   DeleteFile(Path+'Fade.Text');
   Tcols.SaveToFile(Path+'Fade.Txt');
  End;

 If FileExists(path+'Fade.Txt')=True Then
   Tcols.LoadfromFile(path+'Fade.Txt')
    else
   Begin
     Tcols.Add('FF0000');
     Tcols.Add('00FF00');
     Tcols.Add('0000FF');
   End;

 If FileExists(Path+'NeverIgnore.txt')=True Then
    NeverIgnore.LoadFromFile(path+'NeverIgnore.txt');
 FriendsAlias:=TStringList.Create;
// FriendsAliasesLookUp:=TStringList.Create;
// FriendsAliasesLookUp.Sorted:=True;
  If FileExists(Path+'FriendsAlias.txt')=True Then
   FriendsAlias.LoadFromFile(path+'FriendsAlias.txt')
  else
  Begin
   If FileExists(Path+'FriendsList.txt')=True Then
      Begin
        FriendsAlias.LoadFromFile(Path+'FriendsList.txt');
        DeleteFile(Path+'friendslist.txt');
      End;
   FriendsAlias.SaveToFile(Path+'FriendsAlias.txt');
  End;
 PUserNames:=TStringList.Create;
 OnLineFriends:=TStringList.Create;
 Pmignore:=TStringList.Create;
 If FileExists(Path+'Ignored.txt')=True Then
   Form1.LoadFromFile(Ignored,Path+'Ignored.txt');
//  Ignored.LoadFromFile(Path+'ignored.txt');
 RoomName:='';
// Form1.WindowState:=WsMaximized;
 Form1.ListBox1.Sorted:=True;
 Form1.ListBox2.Sorted:=True;
 ChatLines:=0;
 Form1.Richedit1.SelStart:=-1;
 RegisterHotKey(Handle,F10_HotKey,0,VK_F10);
 
// RegisterHotKey(Handle,F11_HotKey,0,VK_F11);
 Form1.richedit1.Paragraph.Alignment:=taCenter;
 Form1.Richedit1.Lines.Add('Welcome to Y!mLite!.. Build '+ClientVer+' Today is: '+DateTimeToStr(Now));
 Form1.Richedit1.Lines.Add(' ');
 Form1.Richedit1.Lines.Add('To PAUSE (so you can scroll up) The Chat Screen, simply highlight some Chat Text with the Left Mouse Button Click and Drag');
 Form1.Richedit1.SelAttributes.Color:=clGreen;
 Form1.Richedit1.Lines.Add('If you want more Skins for Y!mlite go here http://www.almdev.com/prods/skins/skins.htm Just save them into the Y!mLite\Skins folder.');
 Form1.Richedit1.SelAttributes.Color:=clRed;
 Form1.Richedit1.SelAttributes.Color:=clFuchsia;
 Form1.Richedit1.SelText:='To Turn of the Ignore Emote Sound click on Format > Y!mLite General Sounds (At The Top Of The Screen)';
 Form1.Richedit1.Lines.Add('');
  Form1.Richedit1.SelAttributes.Style:=[];
 Form1.Richedit1.SelAttributes.Color:=ClBlack;
 Form1.Richedit1.Lines.Add(''); 
 IF FileExists(Path+'Ymlite.jpg') Then
  Begin
   If DirectoryExists(Path+'rtfimages')=False Then
      CreateDir(Path+'rtfimages');
   MoveFile(Pchar(Path+'ymlite.jpg'),Pchar(Path+'rtfimages\ymlite.jpg'));
   DeleteFile(Pchar(Path+'Ymlite.jpg'));
  End;
  Form1.JpgToRtf('ymlite');
  Form1.DoRtfFace(Richedit1,'ymlite.');
  If FileExists(Path+'localfriends.txt') Then
    Form1.LoadFromFile(Friends,Path+'localfriends.txt');
//   Friends.LoadFromFile(Path+'localfriends.txt');
  If Win32MajorVersion>=5 Then
    Form1.ReleaseMemory;
  AuxGetDevCaps(NumAux,  @AuxCaps, sizeof(AuxCaps));
   If DirectoryExists(Path+'skins')=False Then
      CreateDir(Path+'skins');
   If DirectoryExists(Path+'identitar')=False Then
      CreateDir(Path+'identitar');
 OnlineBuddies.Clear;
 Buddies.Clear;
 //      Form1.ViewButtons;
//  Form1.Panel4.ParentWindow:=Form1.Handle;
{ SetWindowLong(Richedit1.Handle, GWL_EXSTYLE, WS_EX_TRANSPARENT);
 Richedit1.Brush.Style:=BsClear;}
// SetProcessWorkingSetSize(GetCurrentProcess,$ffffffff,$ffffffff);
end;

procedure TForm1.ViewYPackets1Click(Sender: TObject);
begin
   Form1.CreateSkin(Form3);
   Form3.FormStyle:=FsStayOnTop;
   Form3.Show;
end;



procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
Var
 State: Boolean;
 Free: Integer;
 strm : TFileStream;
 PmC: Integer;
 Wnd: Hwnd;
begin
// DfSToolBar1.Visible:=False;
 Exiting:=True;
 MyJPG.Free;
// CPUMonitor.Terminate;

Try
 Form1.SaveLoginData;
// If Form1.Modified=True Then
 SaveLayOut;
 SaveUserData;
Except
  ShowMessage('Debug Error, SaveLogin Data');
End;  


Try
 If MediaPlayer21<>Nil Then
   MediaPlayer21.Free;
 Form1.DestroyAllPmwindow;
 Form1.YMSG.Active:=False;
 Form1.SPRT.Active:=False;


 If Form28.CheckBox4.Checked=True Then
  Form1.Say(Form1.Richedit1,Form28.Edit4.Text,False,False,False);

 Egg:=False;

 If Assigned(Friends)=True Then
     Form1.SaveToFile(Friends,Path+'localfriends.txt');


 If InVoice=True Then
  Begin
   //   Form1.YAcs1.leaveConference;
     Form1.SpSkinSpeedButton2.OnClick(Nil);
     InVoice:=False;
    End;

   Except
    ShowMessage('Debug Error Message: Pre Free');
  End;


  Stop:=True;
 {  strm := TFileStream.Create('myform.DAT', Classes.fmCreate);
  strm.WriteComponent(Form1.Menu);
  strm.Free;}
 StopSound;
 Timer1.Enabled:=False;
 Timer2.Enabled:=False;
 Timer3.Enabled:=False;

 UnregisterHotKey(Handle,F10_HotKey);


 Try
   If TrackList<>Nil Then
    TrackList.Free;
   If Hd<>Nil Then
     Hd.Free;
   If PUserNames<>Nil Then
   PUserNames.Free;
   If Words<>Nil Then
    Words.Free;
   If Friends<>Nil Then
   Friends.Free;
  Except
    ShowMessage('Debug Error Message: Block1');
  End;
Try
   If PmIgnore<>Nil Then
   PmIgnore.Free;
   If Ignored<>Nil Then
   Ignored.Free;
   If Tcols<>Nil Then
   Tcols.Free;
   If TmpLeave<>Nil Then
   TmpLeave.Free;
   If Mp3Control<>Nil Then
   Mp3Control.Free;
   If NeverIgnore<>Nil Then
    NeverIgnore.Free;
   If OnlineBuddies<>Nil Then
    OnLineBuddies.Free;
Except
 ShowMessage('Debug Error Message: Block2');
End;


Try
 For Free:=0 to High(ProgButtons) Do
   If ProgButtons[Free]<>Nil Then
     ProgButtons[Free].Free;

   If FriendsAlias<>Nil Then
    FriendsAlias.Free;
   If Buddies<>Nil Then
    Buddies.Free;
   If GirlyFilter<>Nil Then
    GirlyFilter.Free;
   If Personality<>Nil Then
    Personality.Free;
   If SkinList<>Nil Then
    SkinList.Free;
   If ChatLogger<>Nil Then
    ChatLogger.Free;
   If PmLogger<>Nil Then
    PmLogger.Free;
   If OnLineFriends<>Nil Then
   OnLineFriends.Free;
   If PmWindows<>Nil Then
     PmWindows.Free;
   If FileDownloadWindows<>Nil Then
     FileDownloadWindows.Free;
   If Form10.CheckBox21.Checked=True Then
       allowVoiceList.SaveToFile(Path+'voicelist.txt');
   AllowVoiceList.Free;
  Except
 ShowMessage('Debug Error Message: Block3');
 End;

Try
 If Smileys<>Nil Then
  Smileys.Free;
 If VoiceList<>Nil Then
  VoiceList.Free;
 Except
  ShowMessage('Debug Error Message: Block4');
 End;


Try
  If ChatTimer<>Nil Then
   ChatTimer.Free;
    If Lsm<>Nil Then
      Lsm.Free;
    If PornBotTracker<>Nil Then
       PornBotTracker.Free;
   Except
  ShowMessage('Debug Error Message: Block4');
 End;
// SetLength(Chatters,0);

end;

Procedure Tform1.ProduceSmiles;
var
 N: Integer;
 Ms2: TmemoryStream;
 SmileyList,SmileT: TstringList;
begin
 SmileT:=TStringList.Create;
 SmileyList:=TStringList.Create;
For N:=1 to 48 Do
  Begin
   SmileT.LoadFromFile(IntToStr(N)+'.');
   SmileyList.Add(SmileT.Text);
  End;
 SmileyList.SaveToFile('Smiles.');
 SmileT.Free;
 SmileyList.Free;
End;


procedure TForm1.Disconnect1Click(Sender: TObject);
begin
 RoomJoinWait:=False;
 RoomAckWait:=False;
 Form1.Timer7.Enabled:=False;
 If Assigned(Eye.Sock) Then
    Form1.Eye.Disconnect(True);
 Form1.Disconnecting:=True;
 If Key<>'' Then
   Form1.SendText(LeaveRoom(LoggedInName,GVN));
 Key:='';
 Form1.SPRT.Active:=False;
 Form1.ymsg.Active:=False;
end;

Procedure WriteRichEdit(Myrich: TMyRichedit; Str: String);
Begin
// RichCont.SelText
End;

procedure TForm1.RichEdit1Change(Sender: TObject);
begin
//RichEdit.Perform(EM_LINEFROMCHAR,RichEdit.SelStart,0);
//Form1.Panel10.Caption:='||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA';
{
 for n:=1 to 100 do
  Begin
   RichCont.Lines.add('dfklfjf');
  DoFace(':P');
   DoFace(':O');
  End;
}
 If Form1.Scroll1.Checked=True Then
  Begin
//    RichEdit1.Perform(EM_Scroll, SB_PAGEDOWN, 0);
//    ScrollToEnd(Richedit1);
//    RichEdit1.Perform(EM_SCROLL,SB_LINEDOWN,0);
//    RichCont.SelStart:=-1;
//    SendMessage(Richedit1.Handle, EM_SCROLLCARET,0,0);
  End;

// Panel9.Caption:=IntToStr(ChatLines);
end;

procedure TForm1.ClearChatText1Click(Sender: TObject);
begin
 Form1.Richedit1.Clear;
 Form1.Richedit1.Paragraph.Alignment:=taLeftJustify;
 SendMessage(Richedit1.Handle,EM_SETZOOM,EMZoom,64);
 ChatLines:=0;
end;

procedure TForm1.InstantMessage1Click(Sender: TObject);
Var
 ToUser,MessageStr: String;
begin
 touser:=L1WhoisSelected;
 if InputQuery('IM: '+ToUser,'Message To User '+ToUser, messagestr) then
if Length(messagestr) > 0 then
 Begin
 Form1.SayPm(ToUser,LoggedInName,messagestr);
 Form1.Richedit1.SelAttributes.Style:=[FSBold];
 Form1.Richedit1.SelAttributes.color:=$DD0000;
 Form1.Richedit1.seltext:='You tell '+touser+': ';
 Form1.Richedit1.SelAttributes.Style:=[];
 Form1.Richedit1.SelAttributes.color:=clpurple;
 Form1.Richedit1.seltext:=messagestr;
 Form1.Richedit1.lines.add('');
 Form1.ScrollToEnd(Form1.Richedit1);
End;
end;

procedure TForm1.IgnoreUser1Click(Sender: TObject);
begin
If L1WhoIsSelected<>loggedinname Then
 Begin
  Form1.IgnoreUser(L1WhoIsSelected,false,True,False,False);
  If InVoice=True Then
   If Assigned(Form1.Yacs1) Then
    Form1.Yacs1.muteSource(Chatters[Form1.ChatterNum(L1WhoIsSelected)].SourceID,L1WhoIsSelected);
 End;
end;

procedure TForm1.ViewURLS1Click(Sender: TObject);
begin
 Form1.CreateSkin(Form5);
 Form5.Show;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
If Exiting=True Then Exit;



if Form1.InChat=True Then
 Begin
//  Form1.SaveLayOut;
  Form1.SendText(Ping(loggedinname));
 { If Form2.RadioButton1.Checked=True Then
    Form1.SendText(YMSGMessyPing(loggedinname));}
  If Form10.CheckBox9.Checked=True Then
   Begin
    Form1.SaveLayOut;
    Form1.SaveLoginData;
    SaveUserData;
    Form1.Panel10.Caption:='AutoSave Of Ignore List....';
   End;
 End;
   
end;

procedure TForm1.Credits1Click(Sender: TObject);
begin
 Form1.CreateSkin(Form6);
 Form6.Show;
end;

procedure TForm1.PutNameInTextArea1Click(Sender: TObject);
begin
 Richedit2.Text:=Richedit2.Text+''+L1WhoIsSelected+' ';
end;

procedure TForm1.ListBox1DblClick(Sender: TObject);
Var
 But,Ex: Word;
 Obj: Tobject;
begin
//mouse_event(MOUSEEVENTF_LEFTTDOWN,0,0,but,ex);
//ListBox1.Perform(WM_MBUTTONDOWN,0,0);
IF (Form10.CheckBox18.Checked=True) Then
 Begin
  If (L1WhoIsSelected<>loggedinname) And (Friends.Find(L1WhoIsSelected,Obj)=False) Then
    Begin
     If InVoice=True Then
     If Assigned(Form1.Yacs1) Then
       Form1.yacs1.muteSource(Chatters[Form1.ChatterNum(L1WhoIsSelected)].SourceID,L1WhoIsSelected);
      Form1.IgnoreUser(L1WhoIsSelected,false,True,False,False);
     End
      else
     Form1.GetPmWindow(L1WhoIsSelected);
   End
     Else
   Form1.GetPmWindow(L1WhoIsSelected);
end;

procedure TForm1.SelectAll1Click(Sender: TObject);
begin
 Form1.Richedit1.SetFocus;
 ScreenPaused:=True;
 Form1.Richedit1.SelectAll;
end;

procedure TForm1.Copy1Click(Sender: TObject);
begin
 Form1.Richedit1.CopyToClipboard;
end;

procedure TForm1.YOptions1Click(Sender: TObject);
begin
 Form1.CreateSkin(Form10);
 Form10.Show;
end;

procedure TForm1.ViewUsersIgnored1Click(Sender: TObject);
begin
 Form1.CreateSkin(Form11);
 Form11.ListBox1.Clear;
 Ignored.Traverse(Form11.ListBox1,TraverseMethList);
// Form11.ListBox1.Items.AddStrings(Ignored);
 Form11.Show;
end;

procedure TForm1.ViewOnlineFriends1Click(Sender: TObject);
begin
 Form12.Show;
 Form1.CreateSkin(Form12);
end;

procedure TForm1.Scroll1Click(Sender: TObject);
Var
 PktT: Byte;
begin
 If Form1.Scroll1.Checked=True Then
  Begin
   Form1.Scroll1.Checked:=False;
   Form1.Richedit2.SetFocus;
  End
    Else
  Begin
   Form1.Scroll1.Checked:=True;
//   Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
   Form1.Panel10.Caption:='Scroll On... (Pause Off)';
   If ChatBuffer<>'' Then
    Begin
     If Form2.RadioButton1.Checked=True Then
      DealWithYmsgPacket(ChatBuffer);
      ChatBuffer:='';
      Form1.Richedit2.SetFocus;
    End;
  End;
end;

procedure TForm1.Form12GotoUser1Click(Sender: TObject);
Var
 R,N: Integer;
 ToUser,MessageStr: String;
begin
R:=-1;
 For N:=Form12.ListBox1.Items.Count-1 Downto 0 do
   Begin
    If Form12.ListBox1.Selected[n]=True Then
      R:=N;
   End;
If R<>-1 Then
 Begin
   Form1.SendText(Form1.GotoUserP2(Loggedinname,Form12.ListBox1.Items[R]));
 End;
end;

procedure TForm1.InstantMessage2Click(Sender: TObject);
Var
 R,N: Integer;
 ToUser,MessageStr: String;
begin
R:=-1;
 For N:=Form12.ListBox1.Items.Count-1 Downto 0 do
   Begin
    If Form12.ListBox1.Selected[n]=True Then
      R:=N;
   End;
If R<>-1 Then
 Begin
   touser:=Form12.ListBox1.Items[R];
   if InputQuery('IM: '+ToUser,'Message To User '+ToUser, messagestr) then
      if Length(messagestr) > 0 then
    Begin
     Form1.SayPm(ToUser,LoggedInName,messagestr);
     Form1.Richedit1.SelAttributes.Style:=[FSBold];
     Form1.Richedit1.SelAttributes.color:=$DD0000;
     Form1.Richedit1.seltext:='You tell '+touser+': '+messagestr;
     Form1.Richedit1.lines.add('');
     Form1.Richedit1.SelAttributes.Style:=[];
     Form1.Richedit1.SelAttributes.color:=clpurple;
     Form1.ScrollToEnd(Form1.Richedit1);
   End;
 End;
end;

procedure TForm1.About2Click(Sender: TObject);
begin
 ShowMessage('Y!mLite Ver '+ClientVer+'.');
end;

procedure TForm1.EnableSwearWordFilter1Click(Sender: TObject);
begin
If EnableSwearWordFilter1.Checked=True Then
 EnableSwearWordFilter1.Checked:=False
  else
 EnableSwearWordFilter1.Checked:=True;
end;

procedure TForm1.Updates1Click(Sender: TObject);
begin
 Form1.CreateSkin(Form13);
 Form13.ShowModal;
end;


procedure TForm1.Richedit1MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
{ If MilliSecondsBetween(TBC,now)>400 Then
   Begin
    If (Form1.ListBox1.Items.IndexOf(WordStr)<>-1) Or (Form1.ListBox2.Items.IndexOf(WordStr)<>-1) Or (TmpLeave.IndexOf(WordStr)<>-1) Then
       Form1.IgnoreUser(Wordstr,false,True,False);
   End;}
 mousepressed:=false;
// Form1.Panel10.Caption:='';
{  If MousePressed=False Then
 Begin
   ScreenPaused:=False;
   Form1.Panel10.Caption:='Pause Off..';
 End;}
end;

procedure TForm1.RoomEnterLeaveMessages1Click(Sender: TObject);
begin
 RoomEnterLeaveMessages1.Checked:=Not Form1.RoomEnterLeaveMessages1.Checked;
end;

procedure TForm1.PostHomePage1Click(Sender: TObject);
begin
 If Form1.spSkinCheckRadioBox1.Checked=True Then
 Begin
 Form1.spSkinCheckRadioBox1.Checked:=False;
  Say(Form1.Richedit1,YItalic+YGreen+YBold+YmLiteLogo+YGreen+' b-) http://ymlitechat.com The Skinnable chat client, it makes the '+Ygray+'others '+YGreen+'look '+yGray+'old'+yGray+' and '+yGray+'boring. b-) '+YRed+' ',False,False,False);
   Form1.spSkinCheckRadioBox1.Checked:=True;
 End
  else
  Say(Form1.Richedit1,YItalic+YGreen+YBold+YmLiteLogo+YGreen+' b-) http://ymlitechat.com The Skinnable chat client, it makes the '+Ygray+'others '+YGreen+'look '+yGray+'old'+yGray+' and '+yGray+'boring. b-) '+YRed+' ',False,False,False);
end;

procedure TForm1.RxTrayIcon1Click(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
If Button=MbLeft Then
 Begin
  If Form1.Visible=True Then
    Form1.Visible:=False
       else
    Form1.Visible:=True;
 End;
end;

procedure TForm1.Exist1Click(Sender: TObject);
begin
 Form1.Close;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
Var
 Icon: Ticon;
begin
 //DisplayFreeResources;
 If Exiting=True Then Exit;
 
 If Length(Form1.Panel10.Caption)>190 Then
  Form1.Panel10.Caption:=ScrollText(Form1.Panel10.Caption);


{ If Length(Form1.SpSkinLabel2.Caption)>23 Then
  Begin
   Form1.SpSkinLabel2.Caption:=ScrollText(Form1.SpSkinLabel2.Caption);
  End;}

 If Length(Form1.SpSkinComboBox5.Text)>23 Then
  Form1.SpSkinComboBox5.Text:=ScrollText(Form1.SpSkinComboBox5.Text);

 {If ImageNum>=4 Then
   ImageNum:=0;
  Icon:=Ticon.Create;
  Form1.ImageList2.GetIcon(ImageNum,Icon);
  Form1.Icon:=Icon;
  Icon.Free;
  Inc(ImageNum);}
  If (InVoice=False) And (Button8.Enabled=True) Then
   Begin
    Button8.Enabled:=False;
    Button9.Enabled:=False;
   End;
end;

procedure TForm1.AddBuddy1Click(Sender: TObject);
Var
 Obj: Tobject;
 Buddy: String;
begin
 if InputQuery('Please enter a users ID for your friends list','ID of username: ',Buddy) then
  if Length(Buddy) > 0 then
    Begin
{     If Form2.RadioButton2.Checked=True Then
        TeditBudList.Create(Buddy,True);
     If Form2.RadioButton1.Checked=True Then
        AddBuddy(LoggedInName,Buddy,'chat');
     If Form2.RadioButton3.Checked=True Then
        TeditBudList.Create(Buddy,True);}
     If Form2.RadioButton4.Checked=True Then
      Begin
        SendText(AddSprtBuddy(LoggedInName,Buddy));
        Exit;
      End;
      Friends.Add(Buddy,Obj);
      Form1.Richedit1.Lines.Add('Request Sent For '+Buddy+' To be added as a friend!');
      Form1.ScrollToEnd(Form1.Richedit1);
    End;
end;

procedure TForm1.DeleteBuddy1Click(Sender: TObject);
Var
 Buddy: String;
 Obj: Tobject;
begin
 if InputQuery('Please enter the user''s ID to be removed from your friends list','ID of username: ',Buddy) then
  if Length(Buddy) > 0 then
    Begin
  {    If Form2.RadioButton2.Checked=True Then
       TeditBudList.Create(Buddy,False);
      If Form2.RadioButton1.Checked=True Then
        RemoveBuddy(LoggedInName,buddy,'chat');
      If Form2.RadioButton3.Checked=True Then
        TeditBudList.Create(Buddy,False);}
     If Form2.RadioButton4.Checked=True Then
      Begin
        SendText(RemoveSprtBuddy(LoggedInName,Buddy));
        Exit;
       End;
       If Friends.Find(Buddy,Obj)=True Then
         Friends.Delete(Buddy);
    //  Form1.Richedit1.Lines.Add('Chat buddy: '+Buddy+' Has now been removed!');
      Form1.ScrollToEnd(Form1.Richedit1);
   End;
end;

procedure TForm1.Panel16eMouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
   linenum, mypos, count, linepos, mysel: Integer;
   temp, url: String;
begin
     mousepressed:=true;
     url:='';
     mysel:=RichEdit1.SelStart;
     linenum:=SendMessage(RichEdit1.Handle,EM_LINEFROMCHAR,RichEdit1.SelStart,0);
     linepos:=mysel-(SendMessage(RichEdit1.Handle,EM_LINEINDEX,linenum,0))+1;
     temp:=RichEdit1.Lines.Strings[linenum];
     mypos:=PosRep('http://',temp);
     if mypos > 0 then
     begin
          count:=mypos;
          while (temp[count]<>' ')or((Length(temp)-count)=0) do
                Inc(count);
          if (linepos>=mypos)and(linepos<=count) then
             url:=copy(temp,mypos,count-mypos);
     end
     else
     begin
          mypos:=PosRep('www.',temp);
          if mypos > 0 then
          begin
               count:=mypos;
               while (temp[count]<>' ')or((Length(temp)-count)=0) do
                     Inc(count);
               if (linepos>=mypos)and(linepos<=count) then
                  url:=copy(temp,mypos,count-mypos);
          end;
     end;
     if (url <> '')  then
       RichEdit1.cursor:=crhandpoint
         else
       RichEdit1.cursor:=crDefault;

     if (url <> '') and (mousepressed=true) and (RichEdit1.cursor=crhandpoint) then
      begin
        RichEdit1.cursor:=crdefault;
//        Form1.NewWindow(PChar(url));
      end;
 mousepressed:=false;
end;

procedure TForm1.RichEdit1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
     var
N,iCharIndex, iLineIndex, iCharOffset, i, j: Integer;
Pt: TPoint;
s: string;
begin
TBC:=Now;
Form1.Scroll1.Checked:=False;
  If Button=MBRight Then
  Begin
   If PosRep('*:',WordStr)>0 Then
     WordStr:=Copy(WordStr,1,PosRep('*:',WordStr)-1);
   If PosRep('*',WordStr)>0 Then
     WordStr:=Copy(WordStr,1,PosRep('*',WordStr)-1);
   If PosRep(':',WordStr)>0 Then
     WordStr:=Copy(WordStr,1,PosRep(':',WordStr)-1);
   WordStr2:=WordStr;  
    IF (Length(WordStr)>1) Then
     Begin
       If (WordStr[Length(WordStr)]=',') or (WordStr[Length(WordStr)]='.') Then
        Begin
          WordStr:=Copy(WordStr,1,Length(WordStr)-1);
        End;

       If (Form1.ListBox1.Items.IndexOf(WordStr)<>-1) Or (Form1.ListBox2.Items.IndexOf(WordStr)<>-1) Or (TmpLeave.IndexOf(WordStr)<>-1) Then
        Begin
         If Form1.ListBox1.Items.IndexOf(WordStr)=-1 Then
             Form1.PopupMenu4.Items[0].Caption:='Action for user '+WordStr+' (Not in Room)'
              else
             Form1.PopupMenu4.Items[0].Caption:='Action for user '+WordStr;
           Form1.PopupMenu4.Popup(GetMousePos.X,GetMousePos.Y);
        End
         else
          Begin
//           Form1.PopupMenu4.Items[0].Caption:='Action for user '+wordstr;
           Form1.PopupMenu7.Popup(GetMousePos.X,GetMousePos.Y);
//           Form1.PopupMenu4.Popup(GetMousePos.X+15,GetMousePos.Y);
          End;
     End;
  End;

 If Button=MBLeft Then
  Begin
   with TRichEdit(Sender) do
    begin
     mousepressed:=true;
     Pt := Point(X, Y);
  // Get Character Index from word under the cursor
    iCharIndex := Perform(Messages.EM_CHARFROMPOS, 0, Integer(@Pt));
    if iCharIndex < 0 then Exit;
   // Get line Index
    iLineIndex  := Perform(EM_EXLINEFROMCHAR, 0, iCharIndex);
    iCharOffset := iCharIndex - Perform(EM_LINEINDEX, iLineIndex, 0);
   if Lines.Count - 1 < iLineIndex then Exit;
  // store the current line in a variable
   s := Lines[iLineIndex];
  // Search the beginning of the word
   i := iCharOffset + 1;
   while (i > 0) and (s[i] <> ' ') do Dec(i);
  // Search the end of the word
   j := iCharOffset + 1;
   while (j <= Length(s)) and (s[j] <> ' ') do Inc(j);
  // Display Text under Cursor
    WordStr := Trim(Copy(s, i, j - i));
    If WordStr='<SpartaMessenger>' Then
     Begin
       ShowMessage('Thanks for trying out Sparta Messenger :)');
       Form13.Button6.OnClick(Self);
     End;
    If GetUrl(WordStr,False)<>'' Then
     Begin
      For N:=0 To Form5.ListBox1.Items.Count-1 do
        If PosRep(WordStr,Form5.ListBox1.Items[N])>0 Then
         Begin
           WordStr:=Form5.ListBox1.Items[N];
           Break;
         End;
         If SSShift in Shift Then
          Begin
           Form1.DownloadFile(WordStr);
           Form1.Richedit1.SelStart:=-1;
          End
           else
         Begin
          Form1.CreateSkin(Form35);
          Form35.Edit1.Text:=WordStr;
          Form35.showModal;
          Form1.Richedit1.SelStart:=-1;
          Richedit2.SetFocus;
         End;
      End;
    End;
  End;
end;

Procedure Tform1.UpdateInputDisplay(RichCont: TcustomRichedit);
Var
 S: String;
 ColStr,BuildStr: String;
 Kpos,N: Integer;
Begin
If Length(Richcont.Text)>300 Then Exit;
 
 BO:=False; I:=False; U:=False;
   If Form1.BoldP.checked=true Then
      BO:=True;
  IF Form1.ItalicP.checked=true Then
      I:=True;
  If Form1.UnderLineP.checked=true Then
      U:=True;
If Form1.spSkinCheckRadioBox1.Checked=True Then
   Begin
    If TmpStr<>RichCont.Text Then
     Begin
    //   Form1.RichCont.Lines.BeginUpdate;
       ColStr:='';
       TmpStr:=RichCont.Text;
       Kpos:=RichCont.SelStart;
       For N:=0 to Tcols.Count-1 do
         ColStr:=ColStr+'#'+Tcols[N]+',';
        RichCont.Clear;
       If CloneTag=True Then
         Begin
          ColStr:=ClonedTag;
          Delete(ColStr,1,PosRep('#',ColStr)-1);
          If PosRep('fade',LowerCaseRep(ClonedTag))>0 Then
            S:=Form1.BuildRTFStr(RichCont,'<'+ClonedTag+'>'+TmpStr+'</FADE>',TmpStr,Form1.SpSkinFontComboBox1.FontName,StrToInt(SpSkinComboBox2.Text),Bo,I,U,False,False)
          else
            S:=Form1.BuildRTFStr(RichCont,'<'+ClonedTag+'>'+TmpStr+'</ALT>',TmpStr,Form1.SpSkinFontComboBox1.FontName,StrToInt(SpSkinComboBox2.Text),Bo,I,U,False,False);
            SetSelectionRtf(RichCont,S);
          End
       else
         Begin
         If Form9.RadioButton1.Checked=True Then
          Begin
            S:=Form1.BuildRTFStr(RichCont,Form9.Edit4.Text+TmpStr+'</FADE>',TmpStr,Form1.SpSkinFontComboBox1.FontName,StrToInt(SpSkinComboBox2.Text),Bo,I,U,False,False);
            SetSelectionRtf(RichCont,S);
          End;
         If Form9.RadioButton2.Checked=True Then
          Begin
            S:=Form1.BuildRTFStr(RichCont,Form9.Edit4.Text+TmpStr+'</ALT>',TmpStr,Form1.SpSkinFontComboBox1.FontName,StrToInt(SpSkinComboBox2.Text),Bo,I,U,False,False);
            SetSelectionRtf(RichCont,S);
          End;
         End;
       TmpStr:=RichCont.Text;
       RichCont.SelStart:=Kpos;
//       Form1.Richedit1.lines.Add(GetSelectionrtf(RichCont));
     End;
   End;
End;

{Procedure Tform1.CloseAds;
Begin
If Assigned(Form1.WebBrowser1)=False Then
   Exit;

 If (SecondsBetween(Now,LastClick)>10) Then
      WebBrowser1.Enabled:=True;

 If (CountDown<1) or ((TotalTime div 60 div 60)<20) Or (TClickCount>=100) Then
   Begin
    IF Assigned(Form1.WebBrowser1) Then
      Begin
       Form1.WebBrowser1.Free;
       Form1.WebBrowser1:=Nil;
       Form1.SpSkinSplitter1.Free;
       Form1.SpSkinSplitter1:=Nil;
       ReleaseMemory;
       Form1.GadPanel.Visible:=False;
      End;
   End;
End;}

Function TForm1.ToShortTime(Time: Longint): String;
Begin
  If (Time>1) And (Time<61) Then
    Result:=IntToStr(Time)+' S';
  If (Time>60) Then
    Result:=IntToStr(Time Div 60)+' M';
//IntToStr(YahAvDCTime Div 60)+'M / '+IntToStr(RoomTime Div 60)+'M'
End;

procedure TForm1.Timer3Timer(Sender: TObject);
Var
  BuildStr: String;
begin
 If Exiting=True Then Exit;
 Inc(PmCounter);

{ IF Form1.Button9.Caption='UnLock' Then
 Begin
 Inc(VoiceCounter);
 Form1.Label1.Caption:=IntTOStr(VoiceCounter);
 If VoiceCounter>10 Then
    If Assigned(Yacs1) Then
      Begin
        Yacs1.stopTransmit;
        Delay(100);
        Yacs1.startTransmit;
        VoiceCounter:=0;
      End;
 End;}


 If (RoomAckWait=True) or (RoomJoinWait=True) Then
   Begin
     If InChat=False Then
      Begin
       Form1.RichEdit1.SelAttributes.Style:=[FSBold];
       Form1.Richedit1.SelText:='.';
       Form1.RichEdit1.SelAttributes.Style:=[];
      End;
  End;

 If (CalledAppProcess=False) And (Form1.Richedit1.Focused=False)  Then
  Begin
   If Form1.Scroll1.Checked=False Then
    Begin
      Form1.Scroll1.Checked:=True;
      Form1.ScrollToEnd(Form1.Richedit1);
    End;
   If ScreenPaused=True Then
    Begin
      ScreenPaused:=False;
    End;
  End;



 Inc(NotTouched);
 Inc(TotalTime);
{ If Form1.GadPanel.Visible=True Then
  Begin
   If CountDown>-1 Then
     Dec(CountDown);
   MinStr:=IntToStr(CountDown mod 60);
   If Length(MinStr)=1 Then
     Insert('0',MinStr,1);
  IF StopCounter=False Then
   Begin
   If Odd(CountDown) Then
     Form1.spSkinLabel1.Caption:='Ads close in: '+IntToStr(CountDown div 60)+':'+MinStr+' Minutes'
      else
     Form1.spSkinLabel1.Caption:='Right Click Here For Options';
   End;
  End;}

{ If StopCounter=False Then
    CloseAds;}

 If InChat=True Then
   Inc(RoomTime);
 Inc(RunningTime);
   BuildStr:='';
//   ++IntToStr(RMins)+' Minute(s), '+IntToStr(RSec)+' Second(s).'


 UpdateInputDisplay(richedit2);

 Inc(TsrEconnect);

//   SpSkinLabel1.Caption:=ToShortTime(RoomTime)+' / '+ToShortTime(YahAvDcTime);

end;

procedure TForm1.GetCPUSpeed1Click(Sender: TObject);
begin
 ShowMessage('Your estimated CPU speed is: '+IntToStr(Trunc(GetCpuSpeed))+'Mhz');
end;

procedure TForm1.Emotes1Click(Sender: TObject);
begin
 Form1.CreateSkin(Form18);
 Form18.Show;
end;

procedure TForm1.MailLogin1Click(Sender: TObject);
begin
 ShellExecute(handle,'open',Pchar('http://mail.yahoo.com'),'','',0);
 Form1.ReleaseMemory;
end;

function Tform1.CopyFileWithFileStream(sourcefilename,targetfilename: String): boolean;
Var
 S: TFileStream;
 T: TMemoryStream;
 bReturn: Boolean;
Begin
bReturn:=False;
try
 S := TFileStream.Create( sourcefilename, fmOpenRead or fmShareDenyNone);
 except
  Result :=False;
  Exit;
 end;
 try
  T := TMemoryStream.Create();
  T.CopyFrom(S, 0);                            //This raise an exception
  S.free;
  T.SaveToFile(targetfilename);
  T.free;
 except
  Result :=False;
  Exit;
 end;
Result:=bReturn;
End;




function REGetTextRange(RichEdit: TMyRichedit; BeginPos,
        MaxLength: Integer): string;
 {RichEdit - RichEdit control
 BeginPos - absolute  index of first char
 MaxLength - maximum chars to retrieve}
var
  TextRange: TTextRange;
 begin
  if MaxLength>0 then
  begin
     SetLength(Result, MaxLength);
     with TextRange do
     begin
       chrg.cpMin := BeginPos;
       chrg.cpMax := BeginPos+MaxLength;
       lpstrText := PChar(Result);
     end;
     SetLength(Result, SendMessage(RichEdit.Handle,
               EM_GETTEXTRANGE, 0, longint(@TextRange)));
  end
   else Result:='';
 end;

function RECharIndexByPos(RichEdit: TMyRichedit;
         X, Y: Integer): Integer;
 { function returns absolute character position }
 { for given cursor coordinates }
var
  P: TPoint;
begin
  P := Point(X, Y);
  Result := SendMessage(RichEdit.Handle,
              EM_CHARFROMPOS, 0, longint(@P));
end;


function REExtractWordFromPos(RichEdit: TMyRichedit;
         X,  Y:  Integer): string;
 { X, Y - point coordinates in rich edit control }
 {returns word , under current cursor position}
 var
  BegPos, EndPos: Integer;
 begin
   BegPos := RECharIndexByPos(RichEdit, X,  Y);
  if (BegPos < 0)  or
   (SendMessage(RichEdit.Handle,EM_FINDWORDBREAK,
          WB_CLASSIFY,BegPos) and
          (WBF_BREAKLINE or WBF_ISWHITE) <> 0 )      then
   begin
      result:='';
      exit;
  end;

 if SendMessage(RichEdit.Handle, EM_FINDWORDBREAK,
          WB_CLASSIFY,  BegPos - 1) and
      (WBF_BREAKLINE or WBF_ISWHITE)  =  0  then
         BegPos  :=  SendMessage(RichEdit.Handle,
                EM_FINDWORDBREAK, WB_MOVEWORDLEFT, BegPos);
  EndPos  :=  SendMessage(RichEdit.Handle,
                EM_FINDWORDBREAK, WB_MOVEWORDRIGHT, BegPos);
  Result  :=  TrimRight(REGetTextRange(RichEdit, BegPos,
         EndPos - BegPos));

End;

procedure TForm1.QuickRoomHotkeys1Click(Sender: TObject);
begin
 Form1.CreateSkin(Form20);
 Form20.ShowModal;
end;

procedure TForm1.Richedit1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
iCharIndex, iLineIndex, iCharOffset, i, j: Integer;
Pt: TPoint;
s: string;
WordStr2: String;
begin

//Form1.Caption:=REExtractWordFromPos(Form1.Richedit1,X,Y);

If MousePressed=True Then
 Begin
//   Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
   ScreenPaused:=True;
   Form1.Panel10.Caption:='Pause On..';
 End;

 with TRichEdit(Sender) do
begin
 Pt := Point(X, Y);
// Get Character Index from word under the cursor
 iCharIndex := Perform(Messages.EM_CHARFROMPOS, 0, Integer(@Pt));
 if iCharIndex < 0 then Exit;
// Get line Index
 iLineIndex  := Perform(EM_EXLINEFROMCHAR, 0, iCharIndex);
 iCharOffset := iCharIndex - Perform(EM_LINEINDEX, iLineIndex, 0);
 if Lines.Count - 1 < iLineIndex then Exit;
// store the current line in a variable
s := Lines[iLineIndex];
// Search the beginning of the word
 i := iCharOffset + 1;
 If I<Length(S) then
  Begin
   while (i > 0) and (s[i] <> ' ') do Dec(i);
// Search the end of the word
 j := iCharOffset + 1;
 while (j <= Length(s)) and (s[j] <> ' ') do Inc(j);
// Display Text under Cursor
  WordStr := Trim(Copy(s, i, j - i));
 End
  else
   WordStr:='';
  End;

  If Copy(WordStr,1,1)='<' Then
     Form1.RichEdit1.Cursor:=crHandPoint
    else
     Form1.RichEdit1.Cursor:=crDefault;

  WordStr2:=WordStr;
 If PosRep('*',WordStr2)>0 Then
     WordStr2:=Copy(WordStr2,1,PosRep('*',WordStr2)-1);
   If PosRep('*:',WordStr2)>0 Then
     WordStr2:=Copy(WordStr2,1,PosRep('*:',WordStr2)-1);
   If PosRep(':',WordStr2)>0 Then
     WordStr2:=Copy(WordStr2,1,PosRep(':',WordStr2)-1);

  If WordStr2<>'' Then
   If Form1.ListBox1.Items.IndexOf(WordStr2)<>-1 Then
      Form1.Richedit1.Hint:=Chatters[Form1.ChatterNum(WordStr2)].CustomData
       else
      Form1.RichEdit1.Hint:='';

end;

procedure TForm1.IMuser1Click(Sender: TObject);
Var
 ToUser,MessageStr: String;
begin
 touser:=wordstr;
 if InputQuery('IM: '+ToUser,'Message To User '+ToUser, messagestr) then
    if Length(messagestr) > 0 then
 Begin
  Form1.SayPm(ToUser,LoggedInName,messagestr);
  Form1.Richedit1.SelAttributes.Style:=[FSBold];
  Form1.Richedit1.SelAttributes.color:=$DD0000;
  Form1.Richedit1.seltext:='You tell '+touser+': ';
  Form1.Richedit1.SelAttributes.Style:=[];
  Form1.Richedit1.SelAttributes.color:=clpurple;
  Form1.Richedit1.seltext:=messagestr;
  Form1.Richedit1.lines.add('');
  Form1.ScrollToEnd(Form1.Richedit1);
 End;
end;

procedure TForm1.IgnoreUser2Click(Sender: TObject);
begin
If wordstr2<>loggedinname Then
 Begin
  If InVoice=True Then
    If Assigned(Form1.Yacs1) Then
      Form1.yacs1.muteSource(Chatters[Form1.ChatterNum(wordstr2)].SourceID,wordstr2);
  Form1.IgnoreUser(wordstr2,false,True,False,False);
 End;
end;

procedure TForm1.ViewProfile2Click(Sender: TObject);
begin
 ShellExecute(handle,'open',Pchar('http://profiles.yahoo.com/'+wordstr2+'?warn=1'),'','',0);
 Form1.ReleaseMemory;
//GetAndSaveData(0,'http://profiles.yahoo.com/'+wordstr2,'profile.html');
// TgetProfile.Create(wordstr2,False);
end;

procedure TForm1.UserIdClick(Sender: TObject);
begin
Form1.Richedit1.SelStart:=-1;
end;

procedure TForm1.ExpDetails1Click(Sender: TObject);
begin
 Form1.CreateSkin(Form22);
 Form22.ShowModal;
end;

procedure TForm1.AssignCustomName1Click(Sender: TObject);
Var
 ToUser,MessageStr: String;
begin
 touser:=L1WhoisSelected;
 if InputQuery('Assign Custom Name For '+ToUser+'?','Custom name for example "x0x0calry0ee" "carly"', messagestr) then
if Length(messagestr) > 0 then
 Begin
   AddCustomName(ToUser,MessageStr);
 End;
end;

procedure TForm1.AssignCustomName2Click(Sender: TObject);
Var
 ToUser,MessageStr: String;
begin
 touser:=wordstr2;
 if InputQuery('Assign Custom Name For '+ToUser+'?','Custom name for example "x0x0calry0ee" "carly"', messagestr) then
if Length(messagestr) > 0 then
 Begin
   AddCustomName(ToUser,MessageStr);
 End;
end;

procedure TForm1.EnableAi1Click(Sender: TObject);
begin
 IF EnableAi1.Checked=True Then
   EnableAi1.Checked:=False Else
    EnableAi1.Checked:=True
end;

procedure TForm1.HackersCode1Click(Sender: TObject);
begin
IF Form1.HackersCode1.Checked=True Then
   Form1.HackersCode1.Checked:=False
    Else
  Form1.HackersCode1.Checked:=True;
end;

procedure TForm1.HotKeysEnabled1Click(Sender: TObject);
begin
IF Form1.HotKeysEnabled1.Checked=True Then
 Begin
   Form1.HotKeysEnabled1.Checked:=False;
   UnregisterHotKey(Handle,F6_HotKey);
   UnregisterHotKey(Handle,F7_HotKey);
   UnregisterHotKey(Handle,F8_HotKey);
   UnregisterHotKey(Handle,F9_HotKey);
 End
    Else
  Begin
   Form1.HotKeysEnabled1.Checked:=True;
   RegisterHotKey(Handle,F6_HotKey,0,VK_F6);
   RegisterHotKey(Handle,F7_HotKey,0,VK_F7);
   RegisterHotKey(Handle,F8_HotKey,0,VK_F8);
   RegisterHotKey(Handle,F9_HotKey,0,VK_F9);
  End;
end;

procedure TForm1.LogUser1Click(Sender: TObject);
Var
 ToUser: String;
Begin
 touser:=L1WhoisSelected;
 ExtractDetails(ToUser);
end;

procedure TForm1.LogUser2Click(Sender: TObject);
Var
 ToUser: String;
begin
 touser:=wordstr2;
 ExtractDetails(ToUser);
end;


procedure TForm1.UerswhosaidyourID1Click(Sender: TObject);
begin
  Form1.CreateSkin(Form25);
    If Form25.Visible=True Then
      Form25.Visible:=False
       else
      Form25.Visible:=True;
end;

procedure TForm1.AllOnlineFriends1Click(Sender: TObject);
Var
 P: Pointer;
begin
// Form27.ListBox1.Items.Text:=Friends.Text;
 Form1.CreateSkin(Form27);
 Form27.Show;
 Form27.ListBox1.Clear;
 Friends.Traverse(Form27.ListBox1,TraverseMethList);
// TraverseMethList(Form27.ListBox1);
end;

procedure TForm1.FindDialog1Find(Sender: TObject);
var
  FoundAt: longint;
  SearchType: TSearchTypes;
  SearchStart: integer;
begin
 finddialog1.CloseDialog;
 Richedit1.SelStart:=0;
 with Richedit1 do
   begin
    if frWholeWord in FindDialog1.Options then
    SearchType:=[stWholeWord]
 else
  SearchType:=[];
if SelLength > 0 then
  SearchStart:=SelStart + SelLength//1
else
 SearchStart:=SelStart;
 Screen.Cursor:=crHourGlass;
 Application.ProcessMessages;
 FoundAt:=FindText(FindDialog1.FindText, SearchStart,
 Length(Text)-SearchStart,
 SearchType);
 Screen.Cursor:=crDefault;
 Application.ProcessMessages;
if FoundAt < 1 then
  MessageDlg('Unable to find "'+ FindDialog1.FindText +
'"', mtInformation, [mbOK], 0)
 else
  begin
    SetFocus;
    SelStart:=FoundAt;
    SelLength:=Length(FindDialog1.FindText);
   end;
 end;
  FindDialog1.Execute;
end;

procedure TForm1.Find1Click(Sender: TObject);
begin
 FindDialog1.Execute;
end;

procedure TForm1.FindDialog1Close(Sender: TObject);
begin
 Richedit1.SelStart:=-1;
end;

procedure TForm1.ListBox1MouseMove(Sender: TObject; Shift: TShiftState; X,
  Y: Integer);
var
 Lp: TdateTime;
 Pon : TPoint;
 ItemNum: Integer;
begin
 Pon.x := X;
 Pon.y := Y;
 If Form1.ListBox1.Items.Count>0 Then
  Begin
//    Lp:=GetLastPost(ListBox1.Items[ListBox1.ItemAtPos(Pon,True)]);
     ItemNum:=ListBox1.ItemAtPos(Pon,True);
     If ItemNum<>-1 Then
      Begin
      If Chatters[Form1.ChatterNum(ListBox1.Items[ItemNum])].CustomData<>'' Then
         ListBox1.Hint:=Chatters[Form1.ChatterNum(ListBox1.Items[ItemNum])].CustomData
          else
         ListBox1.Hint:='';
      End;
//   ListBox1.ShowHint;
//   Form1.Panel11.Caption:=ListBox1.Items[ListBox1.ItemAtPos(Pon,True)]+' '+IntToStr(SecondsBetween(now,Lp));
  End;
end;

procedure TForm1.AwayIMPMSettings1Click(Sender: TObject);
begin
  Form1.CreateSkin(Form28);
 If Form28.Visible=False Then
     Form28.Show
      else
     Form28.Hide;
end;

procedure TForm1.RemoveBuddy1Click(Sender: TObject);
Var
 R,N: Integer;
 ToUser,MessageStr: String;
begin
R:=-1;
 For N:=Form12.ListBox1.Items.Count-1 Downto 0 do
   Begin
    If Form12.ListBox1.Selected[n]=True Then
      R:=N;
   End;
  If R<>-1 Then
    Friends.Delete(Form12.ListBox1.Items[R]);
end;

procedure TForm1.EditNick1Click(Sender: TObject);
begin
 ShellExecute(handle,'open',Pchar('http://edit.profiles.yahoo.com/config/seinn?.idname='+LoggedInName),'','',0);
 Form1.ReleaseMemory;
end;

procedure TForm1.YMSGPingTime1Click(Sender: TObject);
begin
PingT:=GetTickCount;
PingRes:='[y!mlite ping]'+IntToStr(Random(65535));
Form1.SayPm(LoggedInName,LoggedInName,PingRes);
end;


procedure TForm1.UserIDCheck1Click(Sender: TObject);
begin
 Form1.CreateSkin(Form30);
 Form30.ShowModal;
end;

procedure TForm1.AddAsFriend1Click(Sender: TObject);
Var
 obj: Tobject;
begin
 // If Form2.RadioButton2.Checked=True Then
//    TeditBudList.Create(L1WhoIsSelected,True);
//  If Form2.RadioButton1.Checked=True Then
//    AddBuddy(LoggedInName,L1WhoIsSelected,'chat');
   Friends.Add(L1WhoIsSelected,Obj);
   
   Form1.Richedit1.Lines.Add('Request Sent For '+L1WhoIsSelected+' To be added as a friend!');
   Form1.ScrollToEnd(Form1.Richedit1);
end;

procedure TForm1.On1Click(Sender: TObject);
begin
 If On1.Checked=False Then
  Begin
   Form1.On1.Checked:=True;
  End
   else
  Begin
   Form1.On1.Checked:=False;
   Identitar:='';
  End;

end;

procedure TForm1.DingOnID1Click(Sender: TObject);
begin
  If Form1.DingOnID1.Checked=False Then
    Form1.DingOnID1.Checked:=True Else
      Form1.DingOnID1.Checked:=False;
end;

procedure TForm1.IMPMallusersonlist1Click(Sender: TObject);
Var
 ToUser,MessageStr: String;
 N: Integer;
begin
 touser:=wordstr2;
 if InputQuery('Message To Send','Message To Send To Users ', messagestr) then
  if Length(messagestr) > 0 then
   Begin
    For N:=Form27.ListBox1.Items.Count-1 Downto 0 do
     Begin
      Form1.SayPm(Form27.ListBox1.Items[N],LoggedInName,MessageStr);
      Delay(400);
     End;
   End;
end;

procedure TForm1.RemoveBuddy2Click(Sender: TObject);
Var
 ToUser,MessageStr: String;
 N,R: Integer;
 Obj: Tobject;
begin
 R:=Form27.ListBox1.ItemIndex;
 If R=-1 Then Exit;

   If Friends.Find(Form27.ListBox1.Items[R],Obj)=True Then
     Friends.Delete(Form27.ListBox1.Items[R]);
   Form1.Richedit1.Lines.Add('Chat buddy: '+Form27.ListBox1.Items[R]+' Has now been removed!');
   Form27.ListBox1.Items.Delete(R);
   Form1.ScrollToEnd(Form1.Richedit1);

end;

procedure TForm1.GroupIM1Click(Sender: TObject);
Var
 ToUser,MessageStr: String;
 N: Integer;
begin
 touser:=wordstr2;
 if InputQuery('Message To Send','Message To Send To Users ', messagestr) then
  if Length(messagestr) > 0 then
   Begin
    For N:=Form12.ListBox1.Items.Count-1 Downto 0 do
     Begin
      Form1.SayPm(Form12.ListBox1.Items[N],LoggedInName,MessageStr);
      Delay(400);
     End;
   End;
end;

procedure TForm1.AutoReplytowb1Click(Sender: TObject);
begin
IF Form1.AutoReplytowb1.Checked=True Then
   Form1.AutoReplytowb1.Checked:=False
    Else
  Form1.AutoReplytowb1.Checked:=True;
end;

procedure TForm1.Replytothanks1Click(Sender: TObject);
begin
IF Form1.Replytothanks1.Checked=True Then
   Form1.Replytothanks1.Checked:=False
    Else
  Form1.Replytothanks1.Checked:=True;
end;

procedure TForm1.MessengerStyleEmotes1Click(Sender: TObject);
begin
If Form1.MessengerStyleEmotes1.Checked=True Then
   Form1.MessengerStyleEmotes1.Checked:=False
    else
   Form1.MessengerStyleEmotes1.Checked:=True;
end;

procedure TForm1.IggyRoulette1Click(Sender: TObject);
 Var
  N: Integer;
  UserName: String;
begin
 N:=0;
 Randomize;
 If Form1.ListBox1.Items.Count>0 Then
  Begin
    N:=Random(Form1.ListBox1.Items.Count)-1;
   While Form1.ListBox1.Items[n]=LoggedInName Do
      N:=Random(Form1.ListBox1.Items.Count)-1;
 UserNAme:=Form1.ListBox1.Items[n];
// Form1.IgnoreUser(Form1.ListBox1.Items[n]);
 If Form1.ListBox1.Items.IndexOf(UserNAme)<>-1 Then
   Form1.IgnoreUser(UserNAme,false,True,False,False);
 End;
end;

procedure TForm1.AvatarConnect(Sender: TObject; Socket: TCustomWinSocket);
begin

End;
  ///~ymlite/identitar/20267.bmp


procedure TForm1.Event1Click(Sender: TObject);
begin
 Form1.CreateSkin(Form24);
 Form24.ShowModal;
end;

procedure TForm1.Forcetexttolowercase1Click(Sender: TObject);
begin
 if Form1.Forcetexttolowercase1.Checked=False Then
   Form1.Forcetexttolowercase1.Checked:=True
     else
   Form1.Forcetexttolowercase1.Checked:=False;
end;

procedure TForm1.Brightcolorfiltr1Click(Sender: TObject);
begin
ShowMessage('Working on this routine, when finished 130 will be up, any suggestions on how i would determine if a color is "too" bright, give me a shout :)');
if Form1.Brightcolorfiltr1.Checked=False Then
   Form1.Brightcolorfiltr1.Checked:=True
     else
   Form1.Brightcolorfiltr1.Checked:=False;
end;

procedure TForm1.EnableBossKeyF101Click(Sender: TObject);
begin
 If EnableBossKeyF101.Checked=False Then
  Begin
   EnableBossKeyF101.Checked:=True;
   RegisterHotKey(Handle,F10_HotKey,0,VK_F10);
  End
   else
  Begin
   EnableBossKeyF101.Checked:=False;
   UnregisterHotKey(Handle,F10_HotKey);
  End;
end;

procedure TForm1.FormActivate(Sender: TObject);
Begin
{Application.Minimize;
Application.Restore;}
end;

procedure TForm1.Releaseanyfreememory1Click(Sender: TObject);
begin
 Form1.ReleaseMemory;
end;

procedure TForm1.Splitter3Moved(Sender: TObject);
begin
//Button1.Top:=Panel6.Top-1;
//Button1.Left:=Panel6.Left-1;
Button1.Width:=Panel6.Width;
Button1.Height:=Panel6.Height;
//Edit2.Text:=IntToStr(Splitter5.Left)+' '+IntToStr(Splitter5.Top);
end;

procedure TForm1.OnEnterGreetFriends1Click(Sender: TObject);
begin
// Form1.onEnterGreetFriends1.Checked:=Not onEnterGreetFriends1.Checked;
end;

procedure TForm1.Greetbuddywhentheyenter1Click(Sender: TObject);
begin
Form1.Greetbuddywhentheyenter1.Checked:=Not Greetbuddywhentheyenter1.Checked;
end;

procedure TForm1.CustomMessagesSetup1Click(Sender: TObject);
begin
 Form1.CreateSkin(Form24);
 Form24.ShowModal;
end;

procedure TForm1.Lockout1Click(Sender: TObject);
begin
 If MessageDlg('You Sure',MtConfirmation,[MBYes,MBNo],0)=IDYes Then
  Begin
   Form1.Enabled:=False;
   Form29.ShowModal;
  End; 
end;

procedure TForm1.PopupMenu1Popup(Sender: TObject);
begin
  Form1.PopupMenu1.Items[0].Caption:='Action for user '+L1WhoIsSelected;
end;

procedure TForm1.AddNewSmileyFace1Click(Sender: TObject);
Var
 Fn,Des: String;
 N: Integer;
 T: TStringList;
begin
 CleanSmileyFile(path+'rtfimages\smileyext.txt');
 CleanSmileyFile(path+'rtfimages\smileyref.txt');
 If CheckAndMergeNewFile=True Then
  Begin
   ExtractSmileyList;
   ShowMessage('New Smileys Added!');
   Exit;
  End;
 Des:=InputBox('New Smiley.','Enter Text For Smiley eg :$@',Des);
 Fn:=InputBox('New Smiley.','Enter FileName (eg mybmp.bmp) ',Fn);
 If (Trim(Fn)<>'') and (Trim(Des)<>'') Then
  Begin
   Des:=LowerCaseRep(Des);
   Form1.AddNewSmiley(Des,Copy(Fn,1,PosRep('.',Fn)));
   ExtractSmileyList;
   ShowMessage('Update Complete!');
  End
   else
 ExtractSmileyList;
end;


procedure TForm1.Mirroryourtext1Click(Sender: TObject);
begin
 MirrorYourText1.Checked:=Not MirrorYourText1.Checked;
end;

procedure TForm1.UserReport1Click(Sender: TObject);
begin
 Form1.CreateSkin(Form31);
 Form31.FormStyle:=FsStayOnTop;
 Form31.Show;
end;

procedure TForm1.PacketConstructor1Click(Sender: TObject);
begin
 Form1.CreateSkin(Form32);
 Form32.show;
end;

procedure TForm1.AutoRejectAddBuddy1Click(Sender: TObject);
begin
 AutoRejectAddBuddy1.Checked:=Not AutoRejectAddBuddy1.Checked;
end;

Function TodayFileN(ChatP: Boolean): String;
Var
 N: Integer;
Begin
 If chatP=True Then
   Result:=Path+'logs\'+DateToStr(now)+'.txt'
    else
   Result:=Path+'logs\PML'+DateToStr(now)+'.txt';
   For n:=1 to length(Result) do
     If Result[n]='/' then
       Result[N]:='@';
End;

Procedure TForm1.WriteLogData(Who,WhoFrom,MsgStr: String; Chatp: Boolean);
Var
 Fn: String;
 DataStr: String;
Begin
 If ChatP=True Then
   DataStr:=DateTimeToStr(Now)+' '+Who+': '+MsgStr+CrLf
    else
   DataStr:=DateTimeToStr(Now)+' '+Who+' To '+WhoFrom+': '+MsgStr+CrLf;    
 If Chatp=True Then
  Begin
   //
    If Assigned(Form1.ChatLogger)=False Then
      Begin
        Fn:=TodayFileN(ChatP);
        If FileExistS(Fn)=True Then
         Begin
          Form1.ChatLogger:=TFileStream.Create(Fn,fmOpenReadWrite  or fmShareDenyNone);
          Form1.ChatLogger.Seek(0,soFromEnd);
         End
        else
          Form1.ChatLogger:=TFileStream.Create(Fn,Classes.fmCreate or fmOpenWrite);
        Form1.ChatLogger.Write(DataStr[1],Length(dataStr));
        Exit;
      End;
    If Assigned(ChatLogger)=True Then
      Form1.ChatLogger.Write(DataStr[1],Length(dataStr));
    //
  End;


  If Chatp=False Then
  Begin
   //
   If Assigned(Form1.PmLogger)=False Then
      Begin
        Fn:=TodayFileN(ChatP);
        If FileExistS(Fn)=True Then
         Begin
          Form1.PmLogger:=TFileStream.Create(Fn,fmOpenReadWrite  or fmShareDenyNone);
          Form1.PmLogger.Seek(0,soFromEnd);
         End
           else
          Form1.PmLogger:=TFileStream.Create(Fn,Classes.fmCreate or fmOpenWrite);
       Form1.PmLogger.Write(DataStr[1],Length(dataStr));
       Exit;
      End;
    If Assigned(PmLogger)=True Then
      Form1.PmLogger.Write(DataStr[1],Length(dataStr));
    //
  End;

End;

procedure TForm1.YaheliteIgnoreImport1Click(Sender: TObject);
Var
 Tmp: String;
 T: System.Text;
 StartT,StopT: Longint;
 Found: Boolean;
 YIgnores: TStringList;
 SF: String;
Begin
Found:=False;
Form34.ListBox1.Clear;
Form1.OpenDialog1.Execute;
SF:=Form1.OpenDialog1.FileName;
YIgnores:=TStringList.Create;
  If FileExists(SF) Then
   Begin
    System.Assign(T,SF);
    System.Reset(T);
    Startt:=GetTickCount;
    Repeat
      ReadLn(T,Tmp);
      If Found=False Then
        If LowerCaseRep(Tmp)='[ignore]' Then
         Begin
          ReadLn(T,Tmp);
          Found:=True;
         End;
      If Found=True Then
        Repeat
         ReadLn(T,Tmp);
        If Trim(Tmp)<>'' Then
         Begin
          If Tmp[1]='[' Then
            Break;
         If Tmp[1]<>'[' Then
          Begin
            Delete(Tmp,1,PosRep('=',Tmp));
            Tmp:=Copy(Tmp,1,PosRep(',0x',Tmp)-1);
            If Trim(Tmp)<>'' Then
               Form34.ListBox1.Items.Add(Tmp);
           End;
         End;
        Until (Eof(T));
      If Found=True Then Break;
    Until Eof(T);
    System.Close(T);
    StopT:=GetTickCount;
    ShowMessage('Loaded '+IntToStr(Form34.ListBox1.Items.Count)+' Users From Yahelite''s Ignore List Time Taken: '+FloatToStr((StopT-StartT)/1000)+' Seconds..');
    Form34.Caption:='Yahelite''s Ignore List...';
    Form34.ShowModal;
    Form1.CreateSkin(Form34);
    YIgnores.Free;
    Exit;
   End
    else
      ShowMessage('Yahelite Not Detected!');
end;

procedure TForm1.CheetaChat657IgnoreImport1Click(Sender: TObject);
Var
 N2,N: Integer;
 T: System.Text;
 Tmp2,Tmp: String;
 StartT,StopT: Longint;
begin
Tmp:='';
Tmp2:='';
Form34.ListBox1.Clear;
 If FileEXists('c:\program files\cheetachat\cignore.dat') Then
  Begin
    System.Assign(t,'c:\program files\cheetachat\cignore.dat');
    System.Reset(T);
    Startt:=GetTickCount;
    Repeat
     ReadLn(T,Tmp2);
     Tmp:=Tmp+Tmp2;
    until Eof(T);
    System.Close(T);
    Tmp2:=Tmp;
    N2:=ScanIt(#$2+'1',Tmp);
      For N:=1 to N2 Do
       Begin
       Tmp:=Copy(Tmp2,1,PosRep(#$2+'1',Tmp2)-1);
       Delete(Tmp2,1,Length(Tmp)+3);
        If Trim(Tmp)<>'' Then
          Form34.ListBox1.Items.Add(Tmp);
      End;
    StopT:=GetTickCount;
    ShowMessage('Loaded '+IntToStr(Form34.ListBox1.Items.Count)+' Users From Cheeta Chats''s Ignore List Time Taken: '+FloatToStr((StopT-StartT)/1000)+' Seconds..');
    Form34.Caption:='Cheeta > Y!mLite Ignore List Merge..';
    Form34.ShowModal;
  End
   else     
   ShowMessage('Cheeta Chat Not Found!');
end;

procedure TForm1.SmileyEditor1Click(Sender: TObject);
begin
 If FileExists(Path+'rtfimages\smileyref.txt') Then
   Form36.Memo1.Lines.LoadFromFile(Path+'rtfimages\smileyref.txt');
 Form1.CreateSkin(Form36);   
 Form36.ShowModal;   
end;




procedure TForm1.richedit2KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
Var
   NewW,Msg2,Tmp,Tmp2,Txt: String;
   P1,P2,P3,N: Word;
   TheStr: String;
   TheWord: Tstruct;
   Sp: Dword;
   Obj: TBadEnglish;
   InfNFade: Integer;
   PktT: Byte;
begin
 SystemParametersInfo(Spi_setBeep,0,0,0);
 Typing:=True;
 ChatTimer.Enabled:=True;
 if key=vk_return then
  Begin
    Richedit2.SelStart:=-1;
  End;

 If (CalledAppProcess=False) and (ScreenPaused=True) Then
  Begin
   Form1.Scroll1.Checked:=True;
   Form1.Richedit1.SelStart:=-1;
   ScreenPaused:=False;
   If ChatBuffer<>'' Then
    Begin
     If Form2.RadioButton1.Checked=True Then
      DealWithYmsgPacket(ChatBuffer);
     If Form2.RadioButton4.Checked=True Then
      DealWithSPRTPacket(ChatBuffer);
     ChatBuffer:='';
    End;
  End;

If (Key=Vk_Right) and (length(Richedit2.text)>0) Then
 Begin
 If (MemoChanged=True)  Then
  Begin
   RCount:=0;
//   Richedit2.Text:=Richedit2.Text+' ';
  //  Richedit1.Lines.add(IntToStr(Memo1.SelStart));
   PUsernames.Clear;
   Tmp:=Richedit2.Text;
   Delay(10);
   P1:=Richedit2.SelStart;
   P1:=Richedit2.SelStart;
   P2:=LastCharPos2(' ',Tmp,P1);
    If P2>1 Then
     Delete(Tmp,1,P2);
   P3:=InsTr(' ',Tmp,P1);
   If P3=0 Then P3:=Length(Tmp);
   Tmp:=Copy(Tmp,1,P3);
  // Tmp:=copy(Tmp2,1,PosRep(' ',Tmp2)-1);
   For N:=ListBox1.Items.Count-1 Downto 0 do
    Begin
    Tmp2:=ListBox1.Items[n];
      If (PosRep(LowerCaseRep(Tmp),LowerCaseRep(Tmp2))>0) and (LowerCaseRep(Tmp[1])=LowerCaseRep(Tmp2[1])) Then
        IF Form1.EnableAI1.Checked=True Then
          PuserNames.Add(CustomizeName(Tmp2))
           else
          PuserNames.Add(Tmp2);
    End;
     If Rcount<=PuserNames.Count-1 Then
      Begin
       Sv1:=P1-Length(Tmp);
       Sv2:=Length(Tmp);
       Richedit2.SelStart:=SV1;
       Richedit2.SelLength:=Sv2;
       If Form10.CheckBox1.Checked=True Then
        Begin
         Richedit2.SelText:='('+PuserNames[RCount]+') ';
         Sv2:=Length('('+PuserNames[RCount]+') ');
        End
         else
        Begin
         Richedit2.SelText:=PuserNames[RCount]+' ';
         Sv2:=Length(PuserNames[RCount]+' ');
        End;
       MemoChanged:=False;
     End;
//       Memo1.text:='('+Form1.ListBox1.Items[N]+') ';
  End
   Else
  Begin
     Inc(RCount);
     Richedit2.SelStart:=SV1;
     Richedit2.SelLength:=Sv2;
   If Form10.CheckBox1.Checked=True Then
    Begin
      Richedit2.SelText:='('+PuserNames[Rcount mod PuserNames.Count]+') ';
      Sv2:=Length('('+PuserNames[Rcount mod PuserNames.Count]+') ');
     End
   else
     Begin
       Richedit2.SelText:=PuserNames[Rcount mod PuserNames.Count]+' ';
       Sv2:=Length(PuserNames[Rcount mod PuserNames.Count]+' ');
     End;
  End;
    UpdateInputDisplay(richedit2);
//   Key:=0;
 End;



 If Key=Vk_Back Then
   MemoChanged:=True;

 If Key=Vk_Delete Then
   MemoChanged:=True;

 If Key=Vk_Space Then
   MemoChanged:=True;

 if key=vk_return then
  begin
   If Form28.Away=True Then
    Begin
     Form1.AwayMsg(Form1.Richedit1,LoggedInName,RoomName,'is back');
     Form28.Away:=False;
    End;
    MemoChanged:=True;
      Richedit2.SelStart:=Length(Richedit2.Text);
      txt:=Richedit2.Text;
      If Length(Txt)<600 Then
         Txt:=Form1.MakeMacro(Txt);
      Txt:=Trim(Form1.CheckCommands(Form1.Richedit1,Txt));
      Txt:=Personality.TextToPersonality(Txt);
      IF Form1.HackersCode1.Checked=True Then
        Txt:=HackersCode(Txt);
      If Form1.CoolJansText1.Checked=True Then
        Txt:=CoolJansText(Txt);
      IF Form1.Mirroryourtext1.Checked=True Then
        Txt:=MirrorCode(Txt);
      If Form1.BadEnglishGenerator1.Checked=True Then
        Begin
          Obj:=TBadEnglish.Create;
          Txt:=Obj.TextToBadEnglish(Txt);
          Obj.Free;
        End;
      If Form10.RadioButton2.Checked=True Then
        Begin
       If Length(Txt)>0 Then
        If Length(txt)<555 Then
         Say(Form1.Richedit1,Txt,False,False,False)
          else
         Say(Form1.Richedit1,Txt,True,False,False);
        End;
      Form25.ListBox1.Clear;
      BufferRichedit(Richedit1,0);
      Form1.ScrollToEnd(Form1.Richedit1);
     If Form10.Radiobutton2.Checked=True Then
       Form1.richedit2.Clear;
  End;

 SetRichedit2;
If Form1.spSkinCheckRadioBox1.Checked=True Then
 Begin
//  Form1.RichEdit2.SelStart:=Kpos;
 End;
// Key:=0;

end;


Procedure Tform1.HighlightWord2(MyRich: TMyRichedit);
Var
Cf2: CHARFORMAT2;
CCh: Charrange;
Struc: Tstruct;
begin
// initialize the CHARFORMAT2 structure to modify the underline type
//memset(&cf2, 0, sizeof(cf2));
 CCh.cpMax:=-1;
 CCh.cpMin:=-1;
 SendMessage(MyRich.handle,EM_EXSETSEL,0,Integer(@CCh));
 FillChar(Cf2,SizeOf(Cf2),#0);
 cf2.cbSize:=sizeof(cf2);
 cf2.dwMask:=CFM_UNDERLINETYPE;
 Cf2.crBackColor:=ClGreen;
 cf2.bUnderlineType:=8 or $40; //$40;//red?
 SendMessage(MyRich.Handle, EM_SETCHARFORMAT, SCF_SELECTION or SCF_WORD , Lparam(@cf2));
 CCh.cpMax:=CCh.cpMax+1;
 CCh.cpMin:=CCh.cpMin+1;
 cf2.bUnderlineType:=0;//red?
 SendMessage(MyRich.handle,EM_EXSETSEL,0,Integer(@CCh));
// SendMessage(MyRich.Handle, EM_SETCHARFORMAT, SCF_SELECTION or SCF_WORD , Lparam(@cf2));
End;


Procedure Tform1.HighlightWord(MyRich: TCustomRichedit; Struc: Tstruct);
Var
Cf2: CHARFORMAT2;
CCh: Charrange;
begin
// initialize the CHARFORMAT2 structure to modify the underline type
//memset(&cf2, 0, sizeof(cf2));
 CCh.cpMax:=Struc.Max-1;
 CCh.cpMin:=Struc.Min-1;
 SendMessage(MyRich.handle,EM_EXSETSEL,0,Integer(@CCh));
 FillChar(Cf2,SizeOf(Cf2),#0);
 cf2.cbSize:=sizeof(cf2);
 cf2.dwMask:=CFM_UNDERLINETYPE;
 Cf2.crBackColor:=ClRed;
 cf2.bUnderlineType:=8 or $40; //$40;//red?
 SendMessage(MyRich.Handle, EM_SETCHARFORMAT, SCF_SELECTION or SCF_WORD , Lparam(@cf2));
 CCh.cpMax:=CCh.cpMax+1;
 CCh.cpMin:=CCh.cpMin+1;
 cf2.bUnderlineType:=0;//red?
 SendMessage(MyRich.handle,EM_EXSETSEL,0,Integer(@CCh));
// SendMessage(MyRich.Handle, EM_SETCHARFORMAT, SCF_SELECTION or SCF_WORD , Lparam(@cf2));
End;

Procedure Tform1.UnHighlightWord(MyRich: TCustomRichedit; Struc: Tstruct);
Var
Cf2: CHARFORMAT2;
CCh: Charrange;
begin
// initialize the CHARFORMAT2 structure to modify the underline type
//memset(&cf2, 0, sizeof(cf2));
 CCh.cpMax:=Struc.Max-1;
 CCh.cpMin:=Struc.Min-1;
 SendMessage(MyRich.handle,EM_EXSETSEL,0,Integer(@CCh));
 FillChar(Cf2,SizeOf(Cf2),#0);
 cf2.cbSize:=sizeof(cf2);
 cf2.dwMask:=CFM_UNDERLINETYPE;
 cf2.bUnderlineType:=0;//red?
 SendMessage(MyRich.Handle, EM_SETCHARFORMAT, SCF_SELECTION or SCF_WORD , Lparam(@cf2));
 CCh.cpMax:=CCh.CpMax+1;
 CCh.cpMin:=CCh.CpMin+1;
 cf2.bUnderlineType:=0;//red?
 SendMessage(MyRich.handle,EM_EXSETSEL,0,Integer(@CCh));
 SendMessage(MyRich.Handle, EM_SETCHARFORMAT, SCF_SELECTION or SCF_WORD , Lparam(@cf2));
End;


Function Tform1.GetWordAtCursor(RichEd: TCustomRichedit): TStruct;
Var
  CCh: Charrange;
  TheWord: String;
  N,R: Integer;
Begin
 Result.TheWord:='';
   SendMessage(RichEd.handle,EM_EXGETSEL,0,Integer(@CCh));
//   Pos:=Cch.cpMax;
  Result.Min:=CCh.cpMin;
  Result.Max:=Cch.cpMax;
   TheWord:=RichEd.Text;
   N:=1;
   While N<CCh.cpMin do
    Begin
      If TheWord[N]=' ' Then
        R:=N;
     Inc(N);
    End;
    Delete(TheWord,1,R);
    CCh.cpMin:=CCh.cpMin-R;
    If PosRep(' ',TheWord)>0 Then
      TheWord:=Copy(TheWord,1,PosRep(' ',TheWord)-1);
  Result.TheWord:=TheWord;
End;

procedure TForm1.richedit2KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
  Var
   InfNFade: Integer;
begin
 Typing:=False;
 TimeStoppedTyping:=0;
 If Key=VK_return Then
   Begin
    If Form10.RadioButton2.Checked=True Then
      Richedit2.clear;
   End;

 InfNFade:=Length(BuildinfStr(Identitar))+45;
 If Form1.SpSkinCheckRadioBox1.Checked=True Then
   InfNFade:=InfNFade+Length(Form9.Edit4.Text+'</FADE>');
 InfNFade:=(300)-InfNfade-Length(Richedit2.Text);
 Form1.Panel16.Caption:='Chars Left: '+IntToStr(InfNFade);
  SystemParametersInfo(Spi_setBeep,1,0,0);
end;

procedure TForm1.richedit2MouseDown(Sender: TObject;
  Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
Var
 PktT: Byte;
begin
//  Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
 If (CalledAppProcess=False) and (ScreenPaused=True) Then
  Begin
   Form1.Richedit1.SelStart:=-1;
   ScreenPaused:=False;
   Form1.Panel10.Caption:='Pause Off..';
   If ChatBuffer<>'' Then
    Begin
      If Form2.RadioButton1.Checked=True Then
      DealWithYmsgPacket(ChatBuffer);
     ChatBuffer:='';
    End;
  End;
end;

procedure TForm1.richedit2MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
var
iCharIndex, iLineIndex, iCharOffset, i, j: Integer;
Pt: TPoint;
s: string;
WordStr2: String;
begin

with TRichEdit(Sender) do
begin
 Pt := Point(X, Y);
// Get Character Index from word under the cursor
 iCharIndex := Perform(Messages.EM_CHARFROMPOS, 0, Integer(@Pt));
 if iCharIndex < 0 then Exit;
// Get line Index
 iLineIndex  := Perform(EM_EXLINEFROMCHAR, 0, iCharIndex);
 iCharOffset := iCharIndex - Perform(EM_LINEINDEX, iLineIndex, 0);
 if Lines.Count - 1 < iLineIndex then Exit;
// store the current line in a variable
s := Lines[iLineIndex];
// Search the beginning of the word
 i := iCharOffset + 1;
 If I<Length(S) then
  Begin
   while (i > 0) and (s[i] <> ' ') do Dec(i);
// Search the end of the word
 j := iCharOffset + 1;
 while (j <= Length(s)) and (s[j] <> ' ') do Inc(j);
// Display Text under Cursor
  WordStr3 := Trim(Copy(s, i, j - i));
 End;
End;


end;


{ TAvatarDownload }

constructor TIdentitarDownload.Create(Sfn1: String; ImageObj: Timage);
begin
 Fn1:=Sfn1;
 FreeOnTerminate:=True;
 Image:=ImageObj;
 Self.FreeOnTerminate:=True;
 Inherited Create(false)
end;

procedure TIdentitarDownload.Execute;
Var
  ProxyString: String;
  N,L2: Integer;
begin
//
If (Form1.ValidFileName(Fn1)=False)  Then Exit;
 If Form10.CheckBox3.Checked=True Then
 Begin
  Data:='';
  Fn1:=LowerCaseRep(Fn1);
//  Server:='chat-help.co.uk';
  Server:='ymlitechat.com';
  Port:='80';
  Fn1:=ExtractFileName(Fn1);
  //HttpStr:='GET /~ymlite/identitar_pgg/avas/'+fn1+'.jpg'+' HTTP/1.0'+#$0D+#$0A+'Host: '+Socket.RemoteHost+#$0D#$0A#$0D#$0A;
  Socket:=TDCBSock.Create(nil);
  Socket.BlockMode:=BmBlocking;
  Socket.RemoteHost:=Form10.Edit3.Text;
  Socket.RemotePort:=Form10.Edit4.Text;
  Socket.Connect;
  Sleep(40);
  HttpStr:='GET /idents/'+fn1+' HTTP/1.0'+#$0D+#$0A+'Host: '+Socket.RemoteHost+#$0D#$0A#$0D#$0A;
  ProxyString:=Format(ProxyConnectStr,[Server,StrToInt(Port),Server]);
  If Socket.Connected=True Then
  Try
    Socket.Sendln(ProxyString);
     if (Socket.WaitForData(10000)) Then
      Begin
       S:=Socket.Receiveln();
       If (PosRep('302',S)<>0) and (PosRep('403',S)<>0) and (PosRep('404',S)<>0) Then
           Socket.Disconnect;
      End;
   Except;
  End;
 End
  else
Begin
  Data:='';
  Fn1:=LowerCaseRep(Fn1);
  Socket:=TDCBSock.Create(nil);
  Socket.BlockMode:=BmBlocking;
//  Form1.GetandSaveData(1,'http://www.chat-help.co.uk/~ymlite/identitar/'+MissingIdentitars.Strings[n]+ '.bmp',Path+'Identitar\'+MissingIdentitars.Strings[n]+'.bmp');
//  Socket.RemoteHost:='www.chat-help.co.uk';
  Socket.RemoteHost:='ymlitechat.com';
  Socket.RemotePort:='80';
  Fn1:=ExtractFileName(Fn1);
//  HttpStr:='GET /~ymlite/identitar_pgg/avas/'+fn1+'.jpg'+' HTTP/1.0'+#$0D+#$0A+'Host: '+Socket.RemoteHost+#$0D#$0A#$0D#$0A;
  HttpStr:='GET /idents/'+fn1+' HTTP/1.0'+#$0D+#$0A+'Host: '+Socket.RemoteHost+#$0D#$0A#$0D#$0A;
  Socket.Connect;
  Sleep(40);
 End;
//

 If Socket.Connected=True Then
  Try
    Socket.Sendln(HttpStr);
    Data:='';
     While (Socket.WaitForData(10000)) Do
      Begin
         Br:=Socket.PeekBuf(Buf,SizeOf(Buf));
         Sleep(40);
         Socket.ReceiveBuf(Buf,Br);
//         BR:=Socket.BytesReceived;
         SetLength(S,Br);
         For N:=0 To Br Do
           S[N+1]:=Buf[N];
        Data:=Data+S;
        Application.ProcessMessages;
       End;
     OnDisconnect;
   Except
    Socket.Disconnect;
   End;
 Socket.Free;
end;

procedure TIdentitarDownload.OnDisconnect;
Var
   F: File;
   P: Integer;
begin
 If DirectoryExists(Path+'identitar')=False Then
   CreateDir(Path+'identitar');
 ExtendedInfo:=Path+'identitar\'+Fn1;
 HttpGrabData:=Data;
 Delete(Data,1,PosRep(#$0d+#$0a+#$0d+#$0a,HttpGrabData)+3);
// HttpGrabData:=Copy(HttpGrabData,1,PosRep('<td width="1%" valign=top>',HttpGrabData)-1);}
//  Form1.GetandSaveData(1,'http://lagmaster.net/~ymlite/identitars/20267.bmp',Path+'Identitar\'+'20267'+'.bmp');
  P:=PosRep(#$0d+#$0a+#$0d+#$0a,Data);
Try
   If (PosRep('403',Data)=0) And (PosRep('404',Data)=0) and (PosRep('400',Data)=0) And (Length(Data)>3) and  (PosRep('301',Data)=0) Then
    Begin
     System.Assign(f,ExtendedInfo);
     Try
     System.Rewrite(F,1);
     BlockWrite(F,Data[1],Length(Data));
      Except
     End;
     System.Close(F);
//     Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
     Form1.Panel10.Caption:='New Identitar Downloaded!';
     Form1.JpgToBmpYmlite(FN1);
     If Assigned(Image) Then
       Image.Picture.LoadFromFile(Path+'identitar\'+Fn1);
    End
     else
    Begin
     System.Assign(f,ExtendedInfo+'.$$$');
     Try
     System.Rewrite(F,1);
      Except
     End;
     System.Close(F);
  //   Form1.Panel10.Caption:='Identitar Failed To Download!';
  End;
   Except
  End;
end;

{ TCheetaDownload }

constructor TCheetaDownload.Create(Sfn1: String);
begin
 Fn1:=Sfn1;
 Self.FreeOnTerminate:=True;
 Inherited Create(false)
end;

procedure TCheetaDownload.Execute;
Var
  N,L2: Integer;
  Fn2: String;
begin
If (Form1.ValidFileName(Fn1)=False) Then Exit;
  Data:='';
  Socket:=TDCBSock.Create(nil);
  Socket.BlockMode:=BmBlocking;
  Socket.RemoteHost:='avatars.cheetachat.com';
  Socket.RemotePort:='80';
  Fn2:=Fn1+'.jpg';
  //GET /avatar/f.jpg HTTP/1.1..Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, */*..Accept-Language: en-au..Accept-Encoding: gzip, deflate..User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)..Host: avatars.cheetachat.com..Connection: Close..Cookie: phpbb2mysql_data=a%3A2%3A%7Bs%3A11%3A%22autologinid%22%3Bs%3A32%3A%22%241%24qTlkQctb%24FgY5iALGcyJfWqGLOYaj%22%3Bs%3A6%3A%22userid%22%3Bi%3A300856%3B%7D....
  HttpStr:='GET /avatar/'+Fn2+' HTTP/1.0'+crlf+'Accept: image/jpeg, */*'+crlf+'Accept-Language: en-us'+crlf+'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)'+crlf+'Host: avatars.cheetachat.com'+crlf+'Connection: Close'+crlf+crlf;
  Socket.Connect;
  Sleep(40);
  If Socket.Connected=True Then
   Try
     Socket.Sendln(HttpStr);
     Data:='';
      While (Socket.WaitForData(10000)) Do
       Begin
          Br:=Socket.PeekBuf(Buf,SizeOf(Buf));
          Sleep(40);
          Socket.ReceiveBuf(Buf,Br);
          SetLength(S,Br);
 //         ZeroMemory(@Buf[L2],SizeOf(Buf)-L2);
          For N:=0 To Br Do
            S[N+1]:=Buf[N];
         Data:=Data+S;
         Application.ProcessMessages;
        End;
      OnDisconnect;
    Except
     Socket.Disconnect;
    End;
  Socket.Free;
end;




procedure TCheetaDownload.OnDisconnect;
Var
   F: File;
   P: Integer;
begin
 If DirectoryExists(Path+'cheeta_avs')=False Then
   CreateDir(Path+'cheeta_avs');
 ExtendedInfo:=Path+'cheeta_avs\'+Fn1+'.jpg';
 HttpGrabData:=Data;
 If PosRep('301 Moved',Data)>0 Then
  Begin
   Data:=Form1.ExtractBetweenString('Avatar/','.',Data,True);
   TcheetaDownload.Create(Data);
   Exit;
  End;
 Delete(Data,1,PosRep(#$0d+#$0a+#$0d+#$0a,HttpGrabData)+3);
// HttpGrabData:=Copy(HttpGrabData,1,PosRep('<td width="1%" valign=top>',HttpGrabData)-1);}
//  Form1.GetandSaveData(1,'http://lagmaster.net/~ymlite/identitars/20267.bmp',Path+'Identitar\'+'20267'+'.bmp');
  P:=PosRep(#$0d+#$0a+#$0d+#$0a,Data);
 If (PosRep('403',Data)=0) And (PosRep('404',Data)=0) and (PosRep('400',Data)=0) and (Length(Data)>3) and  (PosRep('301',Data)=0) Then
  Begin
   System.Assign(f,ExtendedInfo);
   try
   System.Rewrite(F,1);
   BlockWrite(F,Data[1],Length(Data));
    Except
   End;
   System.Close(F);
//   Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
   Form1.Panel10.Caption:='New Avatar Downloaded!';
   Form1.JpgToBmpCheeta(Fn1);
  End
   else
  Begin
   System.Assign(f,ExtendedInfo+'.$$$');
   Try
   System.Rewrite(F,1);
    Except
   End;
   System.Close(F);
//   Form1.Panel10.Caption:='Identitar Failed To Download!';
  End;
end;

Procedure TForm1.ViewCam(Who: String);
Begin
 Form1.SendText(Form1.GetToken(Who));
 Form1.CreateSkin(Form38);
 Form38.RadioButton2.Caption:=LoggedInName;
 Form38.Edit2.Text:=Who;
 Form38.Edit3.Text:='';
 Form38.ShowModal;
End;

procedure TForm1.ViewWebCam1Click(Sender: TObject);
begin
 Form1.SendText(Form1.GetToken(L1WhoIsSelected));
 Form1.CreateSkin(Form38);
 Form38.RadioButton2.Caption:=LoggedInName;
 Form38.Edit2.Text:=L1WhoIsSelected;
 Form38.ShowModal;
end;

procedure TForm1.ViewWebCam2Click(Sender: TObject);
begin
 Form1.SendText(Form1.GetToken(wordstr2));
 Form1.CreateSkin(Form38);
 Form38.RadioButton2.Caption:=LoggedInName;
 Form38.Edit2.Text:=wordstr2;
 Form38.ShowModal;
end;


procedure TForm1.Removeyourselffromothersfriendslist1Click(
  Sender: TObject);
Var
 Buddy: String;
begin
  if InputQuery('User''s ID to be removed from','ID of username: ',Buddy) then
  if Length(Buddy) > 0 then
    Begin
       TRemoveBuddyFromOthers.Create(Buddy);
    End;
end;

{ TRemoveBuddyFromOthers }

constructor TRemoveBuddyFromOthers.Create(SUser: String);
begin
 User:=Suser;
 Self.FreeOnTerminate:=True;; 
 Inherited Create(false);
end;

procedure TRemoveBuddyFromOthers.Execute;
Begin
 Data:='';
 Socket:=TDCBSock.Create(nil);
 Socket.BlockMode:=BmBlocking;
 Socket.RemoteHost:='216.136.227.7';
 Socket.RemotePort:='80';
// '+CrLF+'

 HttpStr:='POST /config/set_buddygrp HTTP/1.1'+CrLF+'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, */*'+CrLF+'Referer: http://www.nhyrvana.com/nobud2.html'+CrLF+'Accept-Language: en-au'+CrLF+'Content-Type: application/x-www-form-urlencoded'+CrLF+'Accept-Encoding: gzip, deflate'+CrLF+'User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'+CrLF+'Host: edit.yahoo.com'+CrLF
 +'Content-Length: 68'+CrLF+'Connection: Close'+CrLF+'Cache-Control: no-cache'+CrLF+'Cookie: '+Cookie+CrLf+CrLF+'.src=bl&.cmd=u&.login=&.id='+LoggedInName+'&.bdl='+User+'&.amsg=Buh-bye'+CrLf;
 Form1.Panel10.Caption:='Attempting to remove '+LoggedInName+' from user "'+User+'''s " friends list.'; 
 Socket.Connect;
 Sleep(40);
 If Socket.Connected=True Then
  Try
    Socket.Sendln(HttpStr);
    Data:='';
     While (Socket.WaitForData(10000)) Do
      Begin
        S:=Socket.Receiveln;
        BR:=Socket.BytesReceived;
        Data:=Data+S;
//        Form1.Panel10.Caption:='Connected reading data in... '+IntToStr(Length(Data))+' Bytes... ';
        Application.ProcessMessages;
       End;
     OnDisconnect;
   Except
    Socket.Disconnect;
   End;
 Socket.Free;
end;

procedure TRemoveBuddyFromOthers.OnDisconnect;
begin
  If PosRep('ERROR',Data)=0 Then
   Begin
    If PosRep('OK',Data)>0 Then
      Form1.Richedit1.Lines.Add('You have Been Succesfully Removed From Their ('+User+'''s) List! ');
   End
 else
   Begin
    Delete(Data,1,PosRep('ERROR',Data)+5);
    Form1.Richedit1.Lines.Add('Error: '+Data);
   End;
end;



procedure TForm1.YMSGConnect(Sender: TObject; Socket: TCustomWinSocket);
begin
// ConnectAttempt:=0;
 LoginStage:=0;
 Form12.ListBox1.Clear;
 Form27.ListBox1.Clear;
 OnLineFriends.Clear;
// Friends.Clear;
 ProxyString:=ProxyString;
 If Form10.CheckBox3.Checked=True Then
   Socket.SendText(ProxyString)
    else
 Begin
  Timer2.Enabled:=True;
//  Panel10.Font.Color:=ColSelect.Label10FontCol;
//  Form1.Panel10.Color:=ClGreen;
 // TfadeWindow2.Create(Form1.Panel10,Form1.Panel10.Color,ClGreen,30);
//  Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
  Panel10.Caption:='Connecting to Y!Messenger Serv';
  LoginStage:=1;
  SendText(LoginString(LoggedInName));
 End;
end;

procedure TForm1.YMSGConnecting(Sender: TObject; Socket: TCustomWinSocket);
begin
// TfadeWindow2.Create(Form1.Panel10,Form1.Panel10.Color,ClYellow,30);
// Form1.panel10.color:=ClYellow;
end;

{Procedure Tform1.LaunchBot;
Begin
 If Bot=Nil Then
  Begin
   If  (Form2.SpSkinPasswordEdit2.Text='') or (Form2.spSkinEdit1.Text='') Then Exit;
   Bot:=TYmsg.Create(Self);
   Bot.UserName:=Form2.spSkinEdit1.Text; //'bl0atedmidget';
   Bot.Password:=Form2.SpSkinPasswordEdit2.Text; //'bloatbot';
   Bot.RoomName:=RoomName;
   Bot.Host:='cs42.msg.dcn.yahoo.com';
   Bot.OnLoginSuccess:=OnLoginSuccess;
   Bot.Port:=5050;
   Bot.Connect;

  End;
End;}

procedure TForm1.YMSGDisconnect(Sender: TObject; Socket: TCustomWinSocket);
begin
{ DCBooter:=BooterAlert;
 IF DCBooter=True Then
 If Form2.spSkinCheckRadioBox3.Checked=True Then
   Begin
     Form1.Richedit1.Lines.Add('Starting AntiBooter Mode Please ReLogin...');
     Form1.ScrollToEnd(Form1.Richedit1);
     LaunchBot;
     Key:='';
     InChat:=False;
     Exit;
    End;}

 if (BooterAlert=True) or (Inchat=True) Then
  if (Form10.CheckBox6.Checked=True) Then
     Begin
      Form1.Timer5.Enabled:=True;
      Form1.ReconnectIn:=Form10.SpinEdit3.value;
     End;

 AverageDataKS:=0;
 BooterAlert:=False;


 If Key<>'' Then
    Socket.SendText(LeaveRoom(LoggedInName,GVN));

   If Exiting=True Then Exit;
   Form1.Richedit1.SelStart:=-1;
   Timer2.Enabled:=False;
   Key:='';
   Form1.ScrollToEnd(Form1.Richedit1);
   Inc(YahTotalDcTime);
   YahAvDCTime:=RoomTime+YahAvDcTime Div YahTotalDCTime;
   Form1.Panel10.Caption:='Disconnected!';

   Form1.InChat:=False;
   RoomAckWait:=False;
   RoomJoinWait:=False;
   Form1.Richedit1.Lines.Add('You have been Disconnected From Chat!');
   Form1.ScrollToEnd(Form1.Richedit1);
   GVN:=#$0F;   
end;

procedure TForm1.YMSGError(Sender: TObject; Socket: TCustomWinSocket;
  ErrorEvent: TErrorEvent; var ErrorCode: Integer);
begin
 Key:='';
 RoomAckWait:=False;
 RoomJoinWait:=False;
 StartSound('Error.wav',False,True);
 Form1.Richedit1.SelStart:=-1;
 Timer2.Enabled:=False;
// TfadeWindow2.Create(Form1.Panel10,Form1.Panel10.Color,ClRed,30);
 Panel10.Caption:='Error! '+IntToStr(ErrorCode);
 Form1.Richedit1.Lines.Add('Serious Error - You have been Cut Off... (Check ISP/Yahoo for Server Crash, That or you just got Disconnected from the Internet.)');
// Form1.Timer5.Enabled:=True;
// Form2.Show;
 ErrorCode:=0;
 if (BooterAlert=True) or (Inchat=True) Then
   If (Form10.CheckBox6.Checked=True) Then
     Begin
      Form1.Timer5.Enabled:=True;
      Form1.ReconnectIn:=Form10.SpinEdit3.value;
     End;
 AverageDataKS:=0;
 BooterAlert:=False;     
 Form1.ScrollToEnd(Form1.Richedit1);
end;

procedure TForm1.YMSGRead(Sender: TObject; Socket: TCustomWinSocket);
Var
 RecAuth1,RecAuth2,BckStr,Tmp2,S: String;
 Ptype,S1,S2: Byte;
 Bufferit: Boolean;
 ActLen,Eop2,N,AL,Eop,Len: Integer;
 Tmp,PayLoad: String;
 Keys: TKeys;
 UnbootableStr: String;
begin
 Form1.MsProcessTime:=GetTickCount;
 BufferIt:=False;
 Len:=YMSG.Socket.ReceiveLength;
 S:=Socket.ReceiveText;

{ If (LoginStage=3) and (Copy(S,1,4)<>'YMSG') Then
 Begin
    If (PosRep('YMSG'+#0,S)>0) and (ConstructPacket>=3) Then
      Begin
       Delete(S,1,PosRep('YMSG'+#0,S)-1);
       ConstructPacket:=0;
       NotFullLen:=False;
       S:=ChatBuffer+S;
       ChatBuffer:='';
      End
       else
      Inc(ConstructPacket);
 End;}

// Move(Buff[0],S,Len);
// S:=Ymsg.Socket.ReceiveText;
 If LoginStage=0 Then
  Begin
   If (PosRep('502',S)>0) or (PosRep('403',s)>0) Then
     Form1.Richedit1.Lines.Add('Proxy unable to carry out request...')
      else
   Begin
    S:=S;
//    Panel10.Font.Color:=ColSelect.Label10FontCol;
//    TfadeWindow2.Create(Form1.Panel10,Form1.Panel10.Color,ColSelect.Label10Col,30);
//    Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
      Panel10.Caption:='Connecting to Y!Messenger Serv';
      LoginStage:=1;
      SendText(LoginString(LoggedInName));
//    Delay(400);
   End;
     Exit;
  End;


 If (LoginStage=99) And (LoginStage>0) Then
  Begin
   If ChatBuffer<>'' Then
     S:=ChatBuffer+S;
     ChatBuffer:='';
    LoginStage:=OldLoginStage;
  End;


  Al:=Length(S);
  If (AL<11) Then
  Begin
    ChatBuffer:=S;
    S:='';
    OldLoginStage:=LoginStage;
    LoginStage:=99;
    Exit;
  End;

  BckStr:=S;
  Len:=Ymsg.Socket.ReceiveLength;

 //maybe more is happening
// If Copy(S,1,4)<>'YMSG' Then
//    S:=S;


If (ScreenPaused=False) Then
 Begin
  If ChatBuffer<>'' Then
   Begin
    Form1.Scroll1.Checked:=False;
    BufferIt:=True;
    S:=ChatBuffer+S;
    ChatBuffer:='';
   End;
End;


 If (ScreenPaused=True)  Then
 Begin
    ChatBuffer:=ChatBuffer+S;
    S:='';
    Exit;
 End;

 If (LoginStage=1) or (LoginStage=2) Then
 Begin
   LoginStage:=3;
   RecAuth1:=Form1.ExtractPacketDetails(S,'94');
   Key:=Copy(S,17,4);
   Keys:=EncryptString(LoggedInName,LoggedInPassword,RecAuth1);
   PayLoad:='6'+Co80s+Keys[1]+Co80s+'96'+co80s+Keys[2]+Co80s;
   PayLoad:=PayLoad+'0'+co80s+LoggedInName+co80s+'2'+Co80s+'1'+Co80s+'1'+co80s+LoggedInName+Co80s+'135'+Co80s+'9.1.0.402'+co80s+'148'+co80s+'300'+co80s;
//   PayLoad:=PayLoad+'0'+co80s+LoggedInName+co80s+'2'+Co80s+LoggedInName+Co80s+'1'+co80s+LoggedInName+Co80s+'135'+Co80s+'8, 0, 0, 506'+co80s+'148'+co80s+'360'+co80s;
   ActLen:=Length(PayLoad);
   If Form2.CheckBox3.Checked=False Then // not invisible
      Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(ActLen)+#$0+#$54+#$5A+#$55+#$AA+#$55+Key
        else
      Tmp:='YMSG'+#$00+GVN+#$0+#$0+Form1.LengthToStr(ActLen)+#0+#$54+#$00+#$00+#$00+#$0C+Key;
   Tmp:=Tmp+PayLoad;
   Key:='';
   Form1.ymsg.Socket.SendText(Tmp);
   Form1.DebugPacket(Tmp,0);
 end;



If LogInstage=3 Then
  Begin
   If Copy(S,1,4)='YMSG' Then
   Begin
    S1:=Ord(S[9]);
    S2:=Ord(S[10]);
    Eop:=ByteAdder(S1,S2)+20;
    Ptype:=Ord(S[12]);
    Eop2:=Length(S);
   If EOP>Eop2 Then
      Begin
       ChatBuffer:=S;
       S:='';
       OldLoginStage:=LoginStage;
       LoginStage:=99;
       Exit;
      End;
    ChatBuffer:='';
    Form1.DebugPacket(S,1);
    DealWithYmsgPacket(S);
    MsProcessTime:=GettickCount-MsProcessTime;
   { IF Ptype=$A8 Then
      If (Form1.InChat=True) And (MsProcessTime<>0) Then
        Begin
         Inc(TotalPackets);
         Inc(TotalProcessTime,MsProcessTime);
         AvgProcessTime:=TotalProcessTime div Form1.TotalPackets;
         Form1.Richedit1.Lines.Add(IntTOStr(AvgProcessTime));
        End;}
    UpdateStats(S);
 //   Form1.Panel10.Caption:='MS PRocess Time '+FloatToStr((GettickCount-MsProcessTime))+' ms';
    S:='';
   End;
 End;

 If BufferIt=True Then
  Begin
   Form1.Scroll1.Checked:=True;
   BufferIt:=False;
  End;
end;


procedure TForm1.HandyPocketConverter1Click(Sender: TObject);
begin

end;


{ TWhatIsMyIP }

constructor TWhatIsMyIP.Create;
begin
 Self.FreeOnTerminate:=True;;
 Inherited Create(false);
end;

procedure TWhatIsMyIP.Execute;
Var
 S: String;
 N,Br: Integer;
begin
 Data:='';
 Socket:=TDCBSock.Create(Nil);
 Socket.BlockMode:=BmBlocking;
 Socket.RemoteHost:='www.whatismyip.com';
 Socket.RemotePort:='80';
// '+CrLF+'
 //GET /search?q=search+engine&ie=ISO-8859-1&hl=en&meta= HTTP/1.1..Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, */*..Referer: http://www.google.com.au/..Accept-Language: en-au..Accept-Encoding: gzip, deflate..User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)..Host: www.google.com.au..Connection: Close..Cookie: PREF=ID=12cb036939e5efa1:LD=en:TM=1040212520:LM=1040212520:S=SllEKRos_vXCwr0G....
// HttpStr:='GET /search?q='+SearchStr+'&ie=ISO-8859-1&hl=en&meta= HTTP/1.0'+CrLf+'Accept: */*'+CrLF+CrLF;           //+CrLf+'Content-Type: application/x-www-form-urlencodedAccept-Encoding: gzip, deflate'+CrLf+'User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'+CrLf+Socket.RemoteHost+CrLf+'Connection: Close'+CrLf+'Cache-Control: no-cache'+CrLf+CrLf;
 HttpStr:='GET / HTTP/1.1'+CrLf+'Accept: */*'+CrLf+'Accept-Language: en-us'+CrLf+'Host: www.whatismyip.com'+CrLf+'Connection: close'+CrLf+CrLf;
 Socket.Connect;
 Sleep(40);
 If Socket.Connected=True Then
  Try
    Socket.Sendln(HttpStr);
    Data:='';
     While (Socket.WaitForData(10000)) Do
      Begin
        S:=Socket.Receiveln;
        BR:=Socket.BytesReceived;
        Data:=Data+S;
//        Form1.Panel10.Caption:='Connected reading data in... '+IntToStr(Length(Data))+' Bytes... ';
        Application.ProcessMessages;
       End;
     OnDisconnect;
   Except
    Socket.Disconnect;
   End;
 Socket.Free;
end;

procedure TWhatIsMyIP.OnDisconnect;
Var
 Title,Des,Url,BuildStr,TmpStr: String;
 C,P1,P2: Integer;
begin
  C:=0;
  TmpStr:=Data;
//  Form1.Memo2.Text:=TmpStr;
  If Data='' Then Exit;
  BuildStr:=Form1.ExtractBetweenString('<TITLE>','</TITLE>',Data,True);
  Form1.Richedit1.Lines.Add(BuildStr);
    If Trim(GmyIP)='' Then
      If MessageDlg('Want to set this IP to the Global IP Address? ',MtConfirmation,[mbyes,mbno],0)=IDYes Then
      Begin
        Delete(BuildStr,1,11);
        BuildStr:=Copy(BuildStr,1,PosRep(' ',BuildStr)-1);
        GMyIp:=BuildStr;
      End;
   //  Form1.Memo2.Text:=Data;
end;

{ TGetIdentList }

constructor TGetIdentList.Create(Limit: Integer; SSender: Tobject);
begin
 Sender:=SSender;
 AvaList:=TStringList.Create;
 SOck:=TDCBSock.create(Nil);
 Self.FreeOnTerminate:=True;
 Inherited Create(False);
end;

destructor TGetIdentList.Destroy;
begin
 AvaList.Free;
 Sock.Free;
 Inherited;
end;

Function TGetIdentList.ExtractIdent(S: String): String;
Var
 FileN,FileS: String;
Begin
While PosRep(#$0a,S)>0 do
 Begin
  FileN:=Copy(S,1,PosRep(#9,S)-1);
  Delete(S,1,Length(FileN)+1);
  FileS:=Copy(S,1,PosRep(#9,S)-1);
  Delete(S,1,PosRep(#$0A,S));
  If (FileN<>'') And (FileS<>'') Then
   Begin
 //   Form1.Richedit1.Lines.Add(FileN+': '+FileS);
    If PosRep('.',FileN)>0 Then
      FileN:=Copy(FileN,1,PosRep('.',FileN)-1);
    If Trim(FileN)<>'' Then
     AvaList.Add(FileN);
   End;  
 End;
 Result:=S;
End;

procedure TGetIdentList.Execute;
Var
 BR: Integer;
 Data: String;
 Stage: Integer;
 TotalData: String;
begin
 TotalData:='';
 Stage:=0;
 Sock.RemotePort:='80';
 Sock.RemoteHost:='ymlitechat.com';
 Sock.Connect;
 SetLength(Data,2048);
 If Sock.Connected=True Then
  Begin
   Sock.Sendln('GET /idents/identlist.php HTTP/1.1'+#$0D+#$0A+'Accept: */*'+#$0D+#$0A+'Accept-Language: en-us'+#$0D+#$0A+'Accept-Encoding: gzip, deflate'+#$0D+#$0A+'Userr-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; .NET   CLR 1.0.3705)'+#$0D+#$0A+'Host: ymlitechat.com'+#$0D+#$0A+'Connection: Close'+#$0D+#$0A+#$0D+#$0A);
    While (Sock.WaitForData(8000)=True) And (Exiting=False) do
      Begin
       BR:=Sock.ReceiveBuf(Data[1],Length(Data));
       SetLength(Data,BR);
       If Stage=0 Then
        Begin
         Stage:=1;
         Delete(Data,1,PosRep(#$0d+#$0a+#$0d+#$0a,Data)+3);
         Delete(Data,1,PosRep(#$0d+#$0a,Data)+1);
        End;
        TotalData:=TotalData+Data;
       TForm47(Sender).Label2.Caption:=IntToStr(Length(TotalData));
       SetLength(Data,4048);
      End;
    Sock.Disconnect;
    IF Stage=1 Then
     Begin
      ExtractIdent(TotalData);
      TForm47(Sender).ListBox1.Items.Text:=AvaList.Text;
      TForm47(Sender).Label2.Caption:=IntToStr(AvaList.Count)+' Identitars in the Database!';
     End;
   //Disconnect;
  End;
   If Stage=0 Then
     Begin
      TForm47(Sender).Label2.Caption:='Connection Failed!';
     End;
end;


{ TUkWeather }

constructor TWeather.Create(Suser,SSearchStr: String);
begin
 UserName:=Suser;
 SearchStr:=SSearchStr;
 Self.FreeOnTerminate:=True;;
 Inherited Create(False);
end;

procedure TWeather.Execute;
Var
 S: String;
begin
 Data:='';
 Socket:=TDCBSock.Create(Nil);
 Socket.BlockMode:=BmBlocking;
 Socket.RemoteHost:='wap.ananova.com';
 Socket.RemotePort:='80';
 Code:=0;
 If Copy(SearchStr,1,10)='uk weather' Then
    HttpStr:='GET /weather/story/sm_763573/0/ HTTP/1.1'+CrLF+'Accept: text/html, text/vnd.wap.wml, image/gif, image/jpeg, image/vnd.wap.wbmp'+CrLF+'Accept-Language: en'+CrLF+'User-Agent: Nokia7110 (DeckIt/1.2.3)'+CrLF+'Host: '+Socket.RemoteHost+CrLf+CrLF
  else
 IF Copy(SearchStr,1,8)='weather>' Then
    Begin
     Code:=1;
     Delete(SearchStr,1,8);
     HttpStr:='GET /weather/scripts/world.wml?l='+SearchStr+' HTTP/1.1'+CrLF+'Accept: text/html, text/vnd.wap.wml, image/gif, image/jpeg, image/vnd.wap.wbmp'+CrLF+'Accept-Language: en'+CrLF+'User-Agent: Nokia7110 (DeckIt/1.2.3)'+CrLF+'Host: '+Socket.RemoteHost+CrLF+CrLF;
     End
   else
      Exit;
 Socket.Connect;
 Sleep(40);
 If Socket.Connected=True Then
  Try
    Socket.Sendln(HttpStr);
    Data:='';
     While (Socket.WaitForData(10000)) Do
      Begin
        S:=Socket.Receiveln;
        BR:=Socket.BytesReceived;
        Data:=Data+S;
//        Form1.Panel10.Caption:='Connected reading data in... '+IntToStr(Length(Data))+' Bytes... ';
        Application.ProcessMessages;
       End;
     OnDisconnect;
   Except
    Socket.Disconnect;
   End;
 Socket.Free;
end;

procedure TWeather.OnDisconnect;
Var
 TmpStr: String;
 N: Integer;
begin
Synchronize(form1.UpdateConsole);
TmpStr:=Data;
 Case Code Of
  0: Begin
    Delete(TmpStr,1,PosRep('<p>'+#$0a,TmpStr)+3);
    TmpStr:=Copy(TmpStr,1,PosRep('<br/><br/>',TmpStr)-1);
    TmpStr:=Form1.RemoveStr('<br/>',TmpStr);
    TmpStr:=RemoveChar(TmpStr,#$0d);
    TmpStr:=RemoveChar(TmpStr,#$09);
    TmpStr:=RemoveChar(TmpStr,#$0a);
    Form44.Memo1.Lines.Add('The Summary for uk weather: '+TmpStr);
  End;
  1: Begin
    Delete(TmpStr,1,PosRep('<p>'+#$0a,TmpStr)+4);
    TmpStr:=Copy(TmpStr,1,PosRep('<a href=',TmpStr)-1);
    If Length(TmpStr)>5 Then
     Begin
     TmpStr:=Form1.RemoveStr('<br/>',TmpStr);
     For N:=1 to Length(TmpStr) do
       if TmpStr[N] in [#$0d,#$0a,#$9,'°'] Then
          TmpStr[N]:=' ';
      Form44.Memo1.Lines.Add('Search For "'+SearchStr+'" results: '+TmpStr);
    End
     else
    Form44.Memo1.Lines.Add('Search For "'+SearchStr+'" Found nothing');
  End;
 End;
end;



Function Tform1.URLDecode(Value : String) : String;
Const HexChars = '0123456789ABCDEF';
Var I        : Integer;
    Ch,H1,H2 : Char;
Begin
   Result := '';
   I := 1;
   While I <= Length(Value) Do
      Begin
         Ch := Value[I];
         Case Ch Of
            '%' : Begin
                     H1 := Value[I+1];
                     H2 := Value[I+2];
                     Inc(I, 2);
                     Result := Result + Chr(((PosRep(H1, HexChars) - 1) * 16) + (PosRep(H2, HexChars) - 1));
                  End;
            '+' : Result := Result + ' ';
            '&' : Result := Result + #13+#10;
            Else Result := Result + Ch;
         End;
         Inc(I);
      End;
End;




Procedure TForm1.WallPaper(S: String);
Var
 B: Tbitmap;
Begin
 If FileExists(S) Then
  Begin
   B:=TbitMap.Create;
   B.LoadFromFile(S);
   Form1.SpSkinControlBar1.Picture.Assign(B);
   Form1.SpSkinControlBar2.Picture.Assign(B);
   B.Free;
  End;
End;


constructor TGetNewsHeadlines.Create(SSearchStr: String);
begin
  SearchStr:=SSearchStr;
 Self.FreeOnTerminate:=True;;  
  Inherited Create(False);
end;

procedure TGetNewsHeadlines.Execute;
Var
 S: String;
begin
 Data:='';
 Socket:=TDCBSock.Create(Nil);
 Socket.BlockMode:=BmBlocking;
 Socket.RemoteHost:='mobile.sky.com';
 Socket.RemotePort:='80';
// '+CrLF+'
 Code:=0;
 If Copy(SearchStr,1,15)='news headlines' Then
    HttpStr:='GET /news_headlines.asp HTTP/1.0'+CrLF+'Host: '+Socket.RemoteHost+CrLf+CrLf
  else
 IF Copy(SearchStr,1,9)='headline>' Then
    Begin
     Code:=1;
     Delete(SearchStr,1,9);
     If Length(SearchStr)=0 Then Exit;
     If SearchStr[1] in ['1'..'5'] Then
      HttpStr:='GET /news_headlines_story.asp?net=&xmlfilename=story'+SearchStr+'&i=11&x=1 HTTP/1.0'+CrLF+'Host: '+Socket.RemoteHost+CrLf+CrLf
    else
      Exit;
    End;
 Socket.Connect;
 Sleep(40);
 If Socket.Connected=True Then
  Try
    Socket.Sendln(HttpStr);
    Data:='';
     While (Socket.WaitForData(10000)) Do
      Begin
        S:=Socket.Receiveln;
        BR:=Socket.BytesReceived;
        Data:=Data+S;
//        Form1.Panel10.Caption:='Connected reading data in... '+IntToStr(Length(Data))+' Bytes... ';
        Application.ProcessMessages;
       End;
     OnDisconnect;
   Except
    Socket.Disconnect;
   End;
 Socket.Free;
end;

procedure TGetNewsHeadlines.OnDisconnect;
Var
 P1,P2,N: Integer;
 BuildStr,TmpStr,TmpStr2: String;
begin
 Synchronize(form1.UpdateConsole);
 Data:=Data;
 TmpStr:=Data;
 TmpStr:=RemoveDoubleSpaces(TmpStr);
 Case Code Of
   0: Begin
        N:=0;
         TmpStr:=LowerCaseRep(TmpStr);
          While Form1.ScanIt('''>',TmpStr)>0 Do
         Begin
           P1:=PosRep('''>',TmpStr);
           Delete(TmpStr,1,P1+1);
           P2:=PosRep('</a>',TmpStr);
//           If (Length(Copy(TmpStr,1,P2-1))<50) Then
           Inc(N);
           If N<6 Then
             BuildStr:=BuildStr+Copy(TmpStr,1,P2-1)+'['+inttostr(n)+'], ';
         End;
        BuildStr:=Copy(BuildStr,1,Length(BuildStr)-2);
        Form44.Memo1.Lines.Add('UK headlines: '+BuildStr);
   End;
   1: Begin
       Delete(TmpStr,1,PosRep('<b>',TmpStr)+2);
       TmpStr2:=Copy(TmpStr,1,PosRep('</b>',TmpStr)-1);
       Delete(TmpStr,1,PosRep('</b><br/><br/>',TmpStr)+13);
       TmpStr:=Copy(TmpStr,1,PosRep('<br/><a',TmpStr)-1);
       TmpStr:=RemoveChar(TmpStr,#$0d);
       TmpStr:=RemoveChar(TmpStr,#$09);
       TmpStr:=RemoveChar(TmpStr,#$0a);
       Form44.Memo1.Lines.Add(TmpStr2+': '+TmpStr);
   End;
 End;
end;


procedure TForm1.NeverIgnoreList1Click(Sender: TObject);
begin
 Form1.CreateSkin(Form45);
 Form45.ListBox1.Items.Text:=NeverIgnore.Text;
 Form45.Show;
end;

procedure TForm1.Splitter1Moved(Sender: TObject);
begin
// Edit2.Text:=IntToStr(Splitter1.Left)+' '+IntToStr(Splitter1.Top);
end;

procedure TForm1.SelectWallpaperBMP1Click(Sender: TObject);
begin
// Form1.OpenPictureDialog1.Execute;
// Form1.WallPaper(Form1.OpenPictureDialog1.FileName);
 Form1.CreateSkin(Form53);
 Form53.ShowModal;
end;

procedure TForm1.AddtoNeverIgnore1Click(Sender: TObject);
begin
 If MessageDlg('You sure you want to add '+L1WhoIsSelected+' to the never ignore list?',MtConfirmation,[mbYes,MbNo],0)=IDYes Then
  Begin
   If NeverIgnore.IndexOf(L1WhoIsSelected)=-1 Then
      NeverIgnore.Add(L1WhoIsSelected);
  End;
end;

procedure TForm1.AddToNeverIgnore2Click(Sender: TObject);
begin
 If MessageDlg('You sure you want to add '+wordstr2+' to the never ignore list?',MtConfirmation,[mbYes,MbNo],0)=IDYes Then
  Begin
   If NeverIgnore.IndexOf(wordstr2)=-1 Then
      NeverIgnore.Add(wordstr2);
  End;
end;

procedure TForm1.RemoveBuddy3Click(Sender: TObject);
Var
 Obj: Tobject;
begin
{ If Form2.RadioButton2.Checked=True Then
  TeditBudList.Create(L1WhoIsSelected,False);
 If Form2.RadioButton1.Checked=True Then
  RemoveBuddy(LoggedInName,L1WhoIsSelected,'chat');
 If Form2.RadioButton3.Checked=True Then
  TeditBudList.Create(L1WhoIsSelected,False);}
 If Form2.RadioButton4.Checked=True Then
   Begin
     SendText(RemoveSprtBuddy(LoggedInName,L1WhoIsSelected));
     Exit;
   End;
  If Friends.Find(L1WhoIsSelected,Obj)=True Then
    Friends.Delete(L1WhoIsSelected);

 Form1.ScrollToEnd(Form1.Richedit1);
end;

procedure TForm1.ViewButtons1Click(Sender: TObject);
begin
 CreateButtons;
end;

procedure TForm1.DumpFriendsList1Click(Sender: TObject);
begin
 Form1.SaveDialog1.Execute;
 Form27.ListBox1.Items.SaveToFile(Form1.SaveDialog1.FileName);
end;

procedure TForm1.Timer4Timer(Sender: TObject);
begin
If (Exiting=True) Then Exit;
  Inc(BootCount);
 AverageDataKS:=+LPacketS Div BootCount;
// Form1.Panel10.Caption:='throughput: '+IntTOStr(AverageDataKS);
 If AverageDataKS>5500 Then
   Begin
      If BooterAlert=False Then
      Begin
         //
        //
//       Form1.CreateSound('Booter Detected, Enabling Maximum Security','BooterAlert.wav');
       StartSound('BooterAlert.wav',False,True);
       Form1.Panel10.Caption:='Booter Detected!, Enabling Maximum Security '+IntTOStr(AverageDataKS)+' Throughput';
       AddBlockMessage(Form1.Panel10.Caption);
{       If Form1.RoomEnterLeaveMessages1.Checked=True Then
           Form1.Richedit1.Lines.Add('As a result of the Booter / Boot Attack,  Enter / Leave room messages have been disabled, Menu > View > Room Enter / Leave Messages to show them again.');}

       Form10.CheckBox16.Checked:=True;
//       Form10.CheckBox18.Checked:=False;
//       Form10.CheckBox21.Checked:=False;
//       Form10.CheckBox19.Checked:=False;
       Form10.RadioButton13.Checked:=True;
       FilterLevel:=4;
      End;
     BooterAlert:=True;
   End
    else
  Begin
   If BooterAlert=True Then
    Begin
//     Form1.CreateSound('The Booter Has Stopped Attacking.','BooterAlertOver.wav');
     StartSound('BooterAlertOver.wav',False,True);
     Form1.Panel10.Caption:='The Booter Has Stopped Attacking. ';
     AddBlockMessage(Form1.Panel10.Caption);
    End;
   BooterAlert:=False;
  End;
  If BootCount>3 Then
   Begin
      BootCount:=1;
      LPacketS:=1;
   End;
end;

procedure TForm1.LaunchVoice1Click(Sender: TObject);
 Var
  Wnd: Hwnd;
begin
  If FileEXists(Path+'Iexplorer.exe')=True Then
  Begin
//      Form1.Richedit1.Lines.Add('Sending String '+'-+-'+LoggedInName+'-+-'+RoomName+'-+-'+Form22.Edit3.Text+'-+-'+Form22.Edit4.Text+'-+-');
      ShellExecute(handle, 'open', Pchar(Path+'Iexplorer.exe'), Pchar('-+-'+LoggedInName+'-+-'+RoomName+'-+-'+Form22.Edit3.Text+'-+-'+Form22.Edit4.Text+'-+-'), '',  sw_Normal);
      Exit;
  End;
  If FileEXists(Path+'YPager.exe')=True Then
      ShellExecute(handle, 'open', Pchar(Path+'YPager.exe'), Pchar('-+-'+LoggedInName+'-+-'+RoomName+'-+-'+Form22.Edit3.Text+'-+-'+Form22.Edit4.Text+'-+-'), '',  sw_Normal);
end;

procedure TForm1.ProcessGamesMessages1Click(Sender: TObject);
begin
 ProcessGamesMessages1.Checked:=Not ProcessGamesMessages1.checked;
end;


procedure TForm1.ControlBar1UnDock(Sender: TObject; Client: TControl;
  NewTarget: TWinControl; var Allow: Boolean);
begin
 If SpSkinControlBar1.DockClientCount<1 Then
   SpSkinControlBar1.Visible:=False;
end;

procedure TForm1.OtronTechnology1Click(Sender: TObject);
begin
IF Form1.OtronTechnology1.Checked=True Then
   Form1.OtronTechnology1.Checked:=False
    Else
  Form1.OtronTechnology1.Checked:=True;
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
 Dec(EmZoom);
 SendMessage(Richedit1.Handle,EM_SETZOOM,EMZoom,64);
end;

{ TgetRoomList }

constructor TgetRoomList.Create(SServ,SGetType,Scookie,SRmCat: String; SLB: TListBox);
begin
  Serv:=SServ;
  CCookie:=Scookie;
  rmCat:=SrmCat;
  LB:=SLB;
  GetType:=SgetType;
  Self.FreeOnTerminate:=True;;
  Inherited Create(false);
end;

procedure TgetRoomList.Execute;
Var
 BR: Integer;
 Data: String;
 Buff: Array[0..2048] of Char;
begin
 Socket:=TDCBSock.Create(Nil);
 Socket.BlockMode:=BmBlocking;
 Socket.RemoteHost:=Serv;
 Socket.RemotePort:='80';
// Socket.OnError:=OnError;
 Socket.Connect;
 Sleep(100);
  If Socket.Connected=True Then
   Begin
   //'+CrLf+'
    Form8.Panel1.Caption:='Reading..';
    If GetType='RoomCat' Then
      Socket.Sendln('GET /c/roomlist/catfeed.html HTTP/1.0'+CrLf+'Referer: http://chat.yahoo.com'+CrLf+'Host: '+Socket.RemoteHost+CrLf+'Accept-Language: en..Accept: */*'+CrLf+'User-Agent: Mozilla/4.0 [en] (Y!mLite) '+CrLf+'Cache-Control: no-cache'+CrLf+'Connection: Keep-Alive'+CrLf+'Cookie: '+CCookie+' CHT=chid='+LoggedInNAme+'&face='+CrLf+CrLf);
    If GetType='RoomList' Then
      Socket.Sendln('GET /c/roomlist/feed.html?.rmcat='+RmCat+'&chat_client=Voice HTTP/1.0'+CrLf+'Referer: http://chat.yahoo.com'+CrLf+'Host: '+Socket.RemoteHost+''+CrLf+'Accept-Language: en'+CrLf+'Accept: */*'+CrLf+'User-Agent: Mozilla/4.0 [en] (Y!mLite) '+CrLf+'Cache-Control: no-cache'+CrLf+'Connection: Keep-Alive'+CrLf+'Cookie: '+CCookie+' CHT=chid='+LoggedInName+'&face='+CrLf+CrLF);
    Try
     While (Socket.WaitForData(5000)=True) And (Terminated=False) Do
      Begin
       BR:=Socket.PeekBuf(Buff,SizeOf(Buff));
       Socket.ReceiveBuf(Buff,Br);
       Data:=Data+Buff;
       Form8.Panel1.Caption:='Reading..'+IntToStr(Length(Data));
       Application.ProcessMessages;
      End;
       OnDisconnect(data);
      Except
      //
       Socket.Disconnect;
     End;
   End;
  Form8.Button1.Enabled:=True;
  Socket.Free;
 // Form1.Richedit1.Lines.Add('Free Socket!');
end;

procedure TgetRoomList.OnDisconnect(Data: String);
Var
   VoiceUsers,TotalUSers,RoomNumber,Tmp3,TmpS,BuildStr,RRoomName,IDRoom,Stemp,TMp: string;
   N2,N,P2,p1: Integer;
   PrvRooms: Boolean;
   IdCode: Char;
begin
 Form8.Panel1.Caption:='Finished Reading Room List!!';
 Delete(Data,1,PosRep(#$0d+#$0a+#$0d+#$0a,Data)+3);
 If GetType='RoomCat' Then
   Begin
    Tmp:=Data;
    Lb.Items.Clear;
//    Form1.Richedit1.Lines.Add(Tmp);
//  While (PosRep(#$09,Tmp)>0) Do
  N2:=Form1.ScanIt(#$9,Tmp);
  For N:=1 to N2 Do
    Begin
       S:=Copy(Tmp,1,PosRep(#$0A,Tmp));
       Stemp:=S;
       P1:=PosRep(#$09,Tmp);
       If p1=0 Then Break;
       IdCode:=Tmp[p1+1];
       IdRoom:=Copy(S,1,P1-1);
       Delete(s,1,P1+2);
       RRoomName:=Copy(S,1,PosRep(#$0a,S)-1);
       Delete(Tmp,1,Length(Stemp));
   If Trim(IDRoom)<>'' Then
    Begin
     If IdCode=#$31 Then
         LB.Items.Add(' '+IdRoom+':'+RRoomName);
     If IdCode=#$32 Then
         LB.Items.Add('|_ '+IdRoom+':'+RRoomName);
     If IdCode=#$33 Then
         LB.Items.Add('|__ '+IdRoom+':'+RRoomName);
     If IdCode=#$34 Then
         LB.Items.Add('|___ '+IdRoom+':'+RRoomName);
     If IdCode=#$35 Then
         LB.Items.Add('|____ '+IdRoom+':'+RRoomName);
       End;
    End;
     Data:='';
   End;
   //
 If GetType='RoomList' Then
   Begin
    Tmp:=Data;
    PrvRooms:=False;
    Form8.ListBox2.Items.Clear;
     Tmp:=Tmp;
    While (PosRep(#$0A,Tmp)>0) Do
     Begin
      If Copy(Tmp,1,Length('PRIVATE_ROOMS'+#$0A))='PRIVATE_ROOMS'+#$0A Then
       Begin
          Form8.ListBox2.Items.Add('Private Rooms...');
          Delete(Tmp,1,Length('PRIVATE_ROOMS'+#$0A));
          PrvRooms:=True;
       End;
        If PrvRooms=True Then
          PrvRooms:=True;
        BuilDStr:='';
        P1:=PosRep(#$0A,Tmp);
        S:=Copy(Tmp,1,P1);
        TmpS:=S;
        RoomId:=Copy(S,1,PosRep(#$09,tmp)-1);
        Delete(S,1,length(RoomID)+1);
        If PrvRooms=False Then
          RoomName:=Copy(s,1,PosRep(#$09+#$09,S)-1)
           else
          RoomName:=Copy(s,1,PosRep(#$09,S)-1);
        Delete(S,1,Length(RoomName)+4);
        P2:=PosRep(',',S);
        While P2>0 DO
          Begin
            BuildStr:=RoomID+':'+RoomName;
            Tmp3:=Copy(S,1,P2-1);
            RoomNumber:=Copy(tmp3,1,PosRep(':',Tmp3)-1);
            Delete(Tmp3,1,Length(RoomNumber)+1);
            TotaLusers:=Copy(tmp3,1,PosRep(':',Tmp3)-1);
            Delete(Tmp3,1,Length(TotaLusers)+1);
            VoiceUsers:=Tmp3;
         //   Tmp3:='';
            BuildStr:=BuildStr+':'+RoomNumber+' ( '+'Users: '+TotalUsers+' V Users: '+VoiceUsers+')';
            Form8.ListBox2.ITems.Add(BuildStr);
            Delete(S,1,PosRep(',',S));
            P2:=PosRep(',',S);
          End;
        BuildStr:=RoomID+':'+RoomName;
        If PrvRooms=False Then
          RoomNumber:=Copy(S,1,PosRep(':',S)-1);
        Delete(S,1,Length(RoomNumber)+1);
        TotaLusers:=Copy(S,1,PosRep(':',S)-1);
        Delete(S,1,Length(TotaLusers)+1);
        VoiceUsers:=Copy(S,1,Length(S)-1);
        BuildStr:=BuildStr+':'+RoomNumber+' ( '+'Users: '+TotalUsers+' V Users: '+VoiceUsers+')';
        If Length(BuildStr)>24 Then
           Form8.ListBox2.ITems.Add(BuildStr);
        Delete(tmp,1,Length(TmpS));
      End;
   End;
end;

procedure TgetRoomList.OnError(Sender: Tobject; ErrorCode: Integer);
begin
  Form8.Panel1.Caption:='Error! '+IntToStr(ErrorCode);
end;

{ TgetRoomList2 }

constructor TgetRoomList2.Create(SServ,SGetType,Scookie,SRmCat: String);
begin
  Serv:=SServ;
  CCookie:=Scookie;
  rmCat:=SrmCat;
  GetType:=SgetType;
  Self.FreeOnTerminate:=True;;  
  Inherited Create(false);
end;

procedure TgetRoomList2.Execute;
Var
 BR: Integer;
 Data: String;
 Buff: Array[0..2048] of Char;
begin
 Socket:=TDCBSock.Create(Nil);
 Socket.BlockMode:=BmBlocking;
 Socket.RemoteHost:=Serv;
 Socket.RemotePort:='80';
// Socket.OnError:=OnError;
 Socket.Connect;
 Sleep(100);
  If Socket.Connected=True Then
   Begin
   //'+CrLf+'
    Form8.Panel1.Caption:='Reading..';

{    If GetType='RoomList' Then
      Socket.Sendln('GET /c/roomlist/feed.html?.rmcat='+RmCat+'&chat_client=Voice HTTP/1.0'+CrLf+'Referer: http://chat.yahoo.com'+CrLf+'Host: '+Socket.RemoteHost+''+CrLf+'Accept-Language: en'+CrLf+'Accept: */*'+CrLf+'User-Agent: Mozilla/4.0 [en] (Y!mLite) '+CrLf+'Cache-Control: no-cache'+CrLf+'Connection: Keep-Alive'+CrLf+'Cookie: '+CCookie+' CHT=chid='+LoggedInName+'&face='+CrLf+CrLF);}

   If GetType='RoomCat' Then
     Socket.Sendln('GET /ycontent/?chatcat&intl='+Form8.ComboBox1.Text+' HTTP/1.0'+#$0D+#$0A+'Host: '+Serv+#$0D+#$0A+'Accept-Language: en'+#$0D+#$0A+'Accept: */*'+#$0D+#$0A+'User-Agent: Mozilla/4.0 (compatible; Y!mLite) '+#$0D+#$0A+'Cache-Control: no-cache'+#$0D+#$0A+'Connection: close'+#$0D+#$0A+'Referer: '+Serv+#$0D+#$0A+'Cookie: '+Cookie+' +CHT=chid='+LoggedInName+'&face='+#$0D+#$0A+#$0D+#$0A);

    If GetType='RoomList' Then
      Socket.Sendln('GET /ycontent/?chatroom_'+RmCat+' HTTP/1.0'+CrLf+'Host: '+Serv+':80'+CrLf+'Accept-Language: en'+CrLf+'Accept: */*'+CrLf+'User-Agent: Mozilla/4.0 (compatible; Y!mLite 289) '+CrLf+'Cache-Control: no-cache'+CrLf+'Connection: close'+CrLF+'Referer: http://insider.msg.yahoo.com'+CrLf+'Cookie: '+Cookie+'CHT=chid='+LoggedInName+'&face='+Crlf+Crlf);

    Try
     While (Socket.WaitForData(5000)=True) And (Terminated=False) Do
      Begin
       BR:=Socket.PeekBuf(Buff,SizeOf(Buff));
       Socket.ReceiveBuf(Buff,Br);
       Data:=Data+Buff;

       Form8.Panel1.Caption:='Reading..'+IntToStr(Length(Data));
       Application.ProcessMessages;
      End;
       OnDisconnect(data);
      Except
      //
       Socket.Disconnect;
     End;
   End;
  Form8.Button1.Enabled:=True;
  Socket.Free;
 // Form1.Richedit1.Lines.Add('Free Socket!');
end;


procedure TgetRoomList2.OnDisconnect(Data: String);
Var
   Lusers,LCount,Lvoice,Lcams,RoomType,Extra,VoiceUsers: String;
   TotalUSers,RoomNumber,Tmp3,Tmp2: string;
   TmpS,BuildStr,RRoomName,IDRoom: string;
   Stemp,TMp: string;
   N2,N,P2,p1: Integer;
   Extract,PrvRooms: Boolean;
   IdCode: Char;
begin
 Form8.Panel1.Caption:='Disconnected!';
 Delete(Data,1,PosRep(#$0d+#$0a+#$0d+#$0a,Data)+3);
{ Extra:=Data;
 P1:=PosRep('</chatCategories>',Extra);
 Delete(Extra,1,P1-1);}
 If GetType='RoomCat' Then
   Begin
    Form1.ReplaceStr(Data,'&apos;','''');
    P1:=PosRep('</chatCategories>',Data);
    Tmp:=Copy(Data,1,P1-1);
    Tmp2:='<chatCategories>'+#$0a;
    Delete(Tmp,1,PosRep(Tmp2,Tmp)+Length(Tmp2)-1);
    While PosRep(#$0a,Tmp)>0 Do
      Begin
       P1:=PosRep(#$0A+'</category>'+#$0a,Tmp);
       Tmp2:=Copy(Tmp,1,P1-1);
       Delete(Tmp,1,P1+12);
       If Copy(Tmp2,1,12)='</category>'+#$0a Then
         Delete(Tmp2,1,12);
        While PosRep(#$0a,Tmp2)>0 Do
         Begin
         IdRoom:=Form1.ExtractBetweenString('category id="','" ',Tmp2,True);
         RRoomName:=Form1.ExtractBetweenString('name="','">',Tmp2,True);
         RRoomName:=Form1.ReplaceStr(RRoomName,'&amp;','and');
         RRoomName:=Form1.ReplaceStr(RRoomName,'&'#3#1'amp;','and');
         Tmp3:=Form1.ExtractBetweenString('','">',Tmp2,True);
      //idcode = indentation
         Form8.ListBox1.Items.Add(' '+IdRoom+':'+Form1.URLDecode(RRoomName));
         Delete(Tmp2,1,PosRep(#$0a,Tmp2));
         End;
        IdRoom:=Form1.ExtractBetweenString('category id="','" ',Tmp2,True);
        RRoomName:=Form1.ExtractBetweenString('name="','">',Tmp2,True);
        RRoomName:=Form1.ReplaceStr(RRoomName,'&amp;','and');
        RRoomName:=Form1.ReplaceStr(RRoomName,'&'#3#1'amp;','and');
        Tmp3:=Form1.ExtractBetweenString('','">',Tmp2,True);
      //idcode = indentation
        Form8.ListBox1.Items.Add(' '+IdRoom+':'+Form1.URLDecode(RRoomName));
        Delete(Tmp2,1,PosRep(#$0a,Tmp2));
      //     Form1.Richedit1.Lines.Add(Tmp);
      End;
   End;
   //
 If GetType='RoomList' Then
   Begin
    Tmp:=Data;
    Data:=Form1.ReplaceStr(Tmp,'&apos;','''');
    P1:=PosRep('</chatRooms>',Data);
    Tmp:=Copy(Data,1,P1-1);
    Delete(Tmp,1,PosRep('<chatRooms>',Tmp)+10);
     While PosRep('</room>'+#$0A,Tmp)>0 Do
       Begin
        P1:=PosRep('</room>'+#$0A,Tmp);
        Tmp2:=Copy(Tmp,1,P1-2);
        Delete(Tmp,1,P1+7);
        RoomType:=Form1.ExtractBetweenString('room type="','" ',Tmp2,True);
        RoomNumber:=Form1.ExtractBetweenString('id="','" ',Tmp2,True);
        RRoomName:=Form1.ExtractBetweenString('name="','" ',Tmp2,True);
        RRoomName:=Form1.URLDecode(RRoomName);
//        RRoomName:=Form1.ExtractBetweenString('name="','" ',Tmp2,True);
//        RRoomName:=Form1.ReplaceFromToStr(RRoomName,'&',';','and');
//        RRoomName:=Form1.ReplaceStr(RRoomName,'&'+#$3+#$1+'amp;','&');
        Delete(Tmp2,1,PosRep('>'+#$0a,Tmp2)+2);
        While PosRep('/>',Tmp2)>0 do
          Begin
           P1:=PosRep('/>',tmp2);
           Tmp3:=Copy(Tmp2,1,P1+1);
           Delete(Tmp2,1,P1+2);
           If PosRep(#$3+#$1,Tmp3)>0 Then
             Tmp3:=Form1.RemoveStr(#$3+#$1,Tmp3);
           Lcount:=Form1.ExtractBetweenString('lobby count="','" ',Tmp3,True);
           Lusers:=Form1.ExtractBetweenString('users="','" ',Tmp3,True);
           LVoice:=Form1.ExtractBetweenString('voices="','" ',Tmp3,True);
           Lcams:=Form1.ExtractBetweenString('webcams="','" ',Tmp3,True);
           Form8.ListBox2.Items.Add(RoomNumber+':'+RRoomName+':'+Lcount+' (Users: '+Lusers+' Voice: '+LVoice+' Cams: '+LCams);
          End;
       End;
   End;
end;

procedure TgetRoomList2.OnError(Sender: Tobject; ErrorCode: Integer);
begin
  Form8.Panel1.Caption:='Error! '+IntToStr(ErrorCode);
end;


procedure TForm1.YmLiteScreenShot1Click(Sender: TObject);
Var
  DeskTopDC: HDc;
  DeskTopCanvas: TCanvas;
  DeskTopRect: TRect;
  Bitmap: TBitmap;
  ExStyle: Longint;
  k   :  INTEGER;
  node:  pRGBTriple;
  Jpg: TJpegImage;
  Loc: String;
begin
  Egg:=True;
//  Image1.Stretch:=True;
//  DeskTopDC := GetWindowDC(Richedit1.Handle);
  DeskTopDC := GetWindowDC(Form1.Handle);
  DeskTopCanvas := TCanvas.Create;
  DeskTopCanvas.Handle := DeskTopDC;
//  DeskTopRect := Rect(0,0,Form1.Richedit1.Width,Form1.Richedit1.Height);
  DeskTopRect := Rect(0,0,Form1.Width,Form1.Height);
  Bitmap := TBitmap.Create;
  with Bitmap do
  begin
    Width := Screen.Width;
    Height:= Screen.Height;
    PixelFormat := pfDevice;
  end;
 Bitmap.Canvas.CopyRect(DeskTopRect,DeskTopCanvas,DeskTopRect);
// with Form1.Image1.Canvas do CopyRect (DeskTopRect, DeskTopCanvas, DeskTopRect);
 //Richedit1.Visible:=False;
  if InputQuery('Save Image As','FileName: ', Loc) then
    if Length(Loc) > 0 then
 Begin
  Jpg:=TjpegImage.Create;
  Jpg.Assign(Bitmap);
  If DirectoryExists(Path+'screenshots')=False Then
    CreateDir(Path+'screenshots');
  Jpg.SaveToFile(Path+'screenshots\'+Loc+'.jpg');
  Jpg.Free;
 End;
 Bitmap.Free;
 DesktopCanvas.Free;
 ReleaseDC(GetDeskTopWindow,DeskTopDC);
end;

procedure TForm1.SPRTConnect(Sender: TObject; Socket: TCustomWinSocket);
begin
 LoginStage:=0;
 Form12.ListBox1.Clear;
 Form27.ListBox1.Clear;
 OnLineFriends.Clear;
// Friends.Clear;
 ProxyString:=ProxyString;
 If Form10.CheckBox3.Checked=True Then
   Socket.SendText(ProxyString)
    else
 Begin
  Timer2.Enabled:=True;
//  Panel10.Font.Color:=ColSelect.Label10FontCol;
//  TfadeWindow2.Create(Form1.Panel10,Form1.Panel10.Color,ColSelect.Label10Col,30);
//  Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
  Panel10.Caption:='Connecting to SPRT Serv';
  LoginStage:=1;
  Form1.SendText(LoginSprtStr);
//  Form1.SendText(LoginSprtStrMessenger);
 End;
end;

procedure TForm1.SPRTConnecting(Sender: TObject; Socket: TCustomWinSocket);
begin
// TfadeWindow2.Create(Form1.Panel10,Form1.Panel10.Color,ClYellow,30);
// Form1.panel10.color:=ClYellow;
end;

Procedure Tform1.CustomSayStr;
Begin
 Form1.Say(Form1.Richedit1,ResultStr,false,false,False);
End;

procedure TForm1.SPRTDisconnect(Sender: TObject; Socket: TCustomWinSocket);
begin
 If Exiting=True Then Exit;
// Form1.CreateSound('You have been Disconnected '+LoggedInName,'disconnected.wav');
// StartSound('uhoh.wav',False);
  StartSound('disconnected.wav',False,False);
 Form1.Richedit1.SelStart:=-1;
  Timer2.Enabled:=False;
// TfadeWindow2.Create(Form1.Panel10,Form1.Panel10.Color,ClOlive,30);
// Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
   If Key<>'' Then
     Form1.SendText(LeaveRoom(LoggedInName,GVN));
   Form1.InChat:=False;
   Key:='';
    Form1.ScrollToEnd(Form1.Richedit1);
    Form1.Panel10.Caption:='Disconnected!';
    Form1.Richedit1.Lines.Add('You have been Disconnected From Chat!');
end;

constructor TConvertURLsToIps.Create(FStr: String);
begin
 Self.FreeOnTerminate:=True;;
 inherited Create(false);
 Str:=FStr;
end;


Function TConvertURlsToIps.GetHostFromStr(S: String): String;
Var
 Ip,Host,Url,Url2,Tmp: String;
 P1,P2,N: Integer;
Begin
 Result:='';
 Tmp:=S;
 Url:=Form1.GetURL(Tmp,True);
 Url2:=Url;
  If Copy(Url,1,10)='http://www' Then
   Delete(Url,1,11);
 If Copy(Url,1,7)='http://' Then
   Delete(Url,1,7);
 If Copy(Url,1,4)='www.' Then
   Delete(Url,1,4);
 If Length(Url)>0 Then
  Begin
   P1:=PosRep('/',Url);
   If P1>0 Then
    Host:=Copy(Url,1,P1-1)
     else
    Host:=Url;
    Result:=Host;
  End;
End;

procedure TConvertURLsToIps.Execute;
Var
 Host: String;
 Ip,Tmp: String;
 T: Integer;
begin
 Tmp:=Str;
 Host:=Tmp;
 While Host<>'' Do
  Begin
   Host:=GetHostFromStr(Tmp);
   If Trim(Host)<>'' Then
    Begin
     Ip:=HostToIp(Host);
     Tmp:=Form1.ReplaceStr(Tmp,Host,Ip);
    End;
  End;
 Tmp:=Form1.ReplaceStr(Tmp,'http://','');
 Tmp:=Form1.ReplaceStr(Tmp,'www.','http://');
 Form1.ResultStr:=Tmp;
 Synchronize(form1.CustomSayStr);
// Form44.Memo1.Lines.Add(Tmp);  s
// Form1.Say(Form1.Richedit1,Tmp,false,false,False);
end;

function TconvertUrlsToIps.HostToIP(Host: String): String;
var
  temp: Integer;
  addr: PChar;
  FHostEnt: PHostEnt;
begin
  Result:='';
  if Host <> '' then
  begin
    temp:=inet_addr(PChar(Host));
    if temp = -1 then
    begin
      FHostEnt:=gethostbyname(PChar(Host));
      if Assigned(FHostEnt) then
      begin
        addr:=FHostEnt^.h_addr_list^;
        if Assigned(addr) then
          Result:=Format('%d.%d.%d.%d',[byte(addr[0]),byte(addr[1]),byte(addr[2]),byte(addr[3])]);
      end;
    end;
  end;
end;


procedure TForm1.SPRTRead(Sender: TObject; Socket: TCustomWinSocket);
Var
 RecAuth1,RecAuth2,BckStr,Tmp2,S: String;
 Ptype,S1,S2: Byte;
 Bufferit: Boolean;
 Eop2,N,AL,Eop,Len: Integer;
 Buff: Array [0..8068] of char;
begin
 Form1.MsProcessTime:=GetTickCount;
 BufferIt:=False;
 Len:=SPRT.Socket.ReceiveLength;
 S:=Socket.ReceiveText;

 If LoginStage=0 Then
  Begin
   If (PosRep('502',S)>0) or (PosRep('403',s)>0) Then
     Form1.Richedit1.Lines.Add('Proxy unable to carry out request...')
      else
   Begin
    S:=S;
//    Panel10.Font.Color:=ColSelect.Label10FontCol;
//    TfadeWindow2.Create(Form1.Panel10,Form1.Panel10.Color,ColSelect.Label10Col,30);
//    Form1.Panel10.Font.Color:=ColSelect.Label10FontCol;
    Panel10.Caption:='Connecting to Y!Messenger Serv';
    LoginStage:=1;
    Form1.SPRT.Socket.SendText(LoginSPRTStr);
//    Delay(400);
   End;
     Exit;
  End;
  //

  If (LoginStage=99) And (LoginStage>0) Then
  Begin
   If ChatBuffer<>'' Then
     S:=ChatBuffer+S;
     ChatBuffer:='';
   If Length(S)>=BufferLength Then
     LogInStage:=1
       else
     Begin
      ChatBuffer:=S;
      S:='';
      Exit;
     End;
  End;

If (ScreenPaused=False) Then
 Begin
  If ChatBuffer<>'' Then
   Begin
    Form1.Scroll1.Checked:=False;
    BufferIt:=True;
    S:=ChatBuffer+S;
    ChatBuffer:='';
   End;
End;

 If (ScreenPaused=True)  Then
 Begin
    ChatBuffer:=ChatBuffer+S;
    S:='';
    Exit;
 End;


{  If ChatBuffer<>'' Then
   Begin
     S:=ChatBuffer+S;
     ChatBuffer:='';
   End;}


 If LoginStage=1 Then
  Begin
  If Copy(S,1,4)='SPRT' Then
   Begin
    If Key='' Then
     Key:=Copy(S,9,4);
    S1:=Ord(S[13]);
    S2:=Ord(S[14]);
    Eop:=ByteAdder(S1,S2)+15;
    Ptype:=Ord(S[12]);
    Eop2:=Length(S);
    If EOP>Eop2 Then
      Begin
       ChatBuffer:=S;
       BufferLength:=Eop;
       S:='';
       LoginStage:=99;
       Exit;
      End;
    ChatBuffer:='';
    Form1.DebugPacket(S,1);
    dealwithSPRTpacket(S);
    MsProcessTime:=GettickCount-MsProcessTime;
    UpdateStats(S);
  //  Form1.Panel10.Caption:='MS PRocess Time '+FloatToStr((GettickCount-MsProcessTime))+' ms';
    S:='';
   End;
  End;

 If (ChatBuffer='') And (S<>'') Then
   Begin
    If (PosRep('YMSG'+#0,S)>0) Then
     Begin
       Delete(S,1,PosRep('YMSG'+#0,S)-1);
       ChatBuffer:=S;
     End;
   End;
End;

procedure TForm1.RequestEchoChat1Click(Sender: TObject);
begin
 TMenuItem(Sender).Checked:=Not TmenuItem(Sender).Checked;
end;

{ TGetIPAdd }

constructor TGetIPAdd.Create(SSearchStr: String);
begin
 If SsearchStr='C' Then
   CreateAccount:=True
    else
   CreateAccount:=False;
 Self.FreeOnTerminate:=True;
 Inherited Create(False);
end;

procedure TGetIPAdd.Execute;
Var
 S: String;
begin
 Data:='';
 Socket:=TDCBSock.Create(Nil);
 Socket.BlockMode:=BmBlocking;
 Socket.RemoteHost:='ymlitechat.com';
 Socket.RemotePort:='80';
// '+CrLF+'
 Code:=0;
 HttpStr:='GET /ymlite/servip.txt HTTP/1.0'+CrLF+'Host: '+Socket.RemoteHost+CrLF+'Cache-Control: no-cache'+CrLf+'Content-Type: text'+CrLf+CrLf;
//    HttpStr:='GET /~ymlite/servip.txt HTTP/1.0'+CrLF+'Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, */*'+CrLF+'Accept-Language: en-au'+CrLF+'Accept-Encoding: gzip, deflate'+CrLF+'User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'+CrLF+'Host: '+Socket.RemoteHost+CrLF+'Cache-Control: no-cache'+CrLf+'Connection: Close'+CrLF+Crlf;
 Socket.Connect;
 Sleep(40);
 If Socket.Connected=True Then
  Try
    Socket.Sendln(HttpStr);
    Data:='';
     While (Socket.WaitForData(10000)) Do
      Begin
        S:=Socket.Receiveln;
        BR:=Socket.BytesReceived;
        Data:=Data+S;
//        Form1.Panel10.Caption:='Connected reading data in... '+IntToStr(Length(Data))+' Bytes... ';
        Application.ProcessMessages;
       End;
     OnDisconnect;
   Except
    Socket.Disconnect;
   End;
 Socket.Free;
end;

procedure TGetIPAdd.OnDisconnect;
Var
 TheIP: String;
begin
{If  PosRep('Connection: close',data)>0 Then
  Delete(Data,1,PosRep('Connection: close',data)+16);

If PosRep('content-type: text/plain',LowerCaseRep(Data))>0 Then
  Delete(Data,1,PosRep('content-type: text/plain',LowerCaseRep(Data))+23);}

 If PosRep('$IP$',Data)>0 Then
   Delete(Data,1,PosRep('$IP$',Data)+3);

 TheIP:=Data;
 IpAddress:=TheIP;
// Form2.Edit2.Text:=TheIP;
//   Form2.BitBtn3.Enabled:=True;
// SendMessage(Form2.edit2.Handle,wm_settext,0,Integer(TheIP));
end;

{ TCreateAccount }

constructor TCreateAccount.Create(SUser, Spassword, SGender, SLocation,ShomePage, SEmailAdd, SAge: String; SCP: Boolean);
begin
If SCP=False Then
 Begin
  User:=sUser;
  Password:=Spassword;
  Gender:=Sgender;
  location:=Slocation;
  HomePage:=ShomePage;
  EmailAdd:=SemailAdd;
  age:=Sage;
 End
  else
 Begin
   CP:=SCP;
   User:=Suser;
   OldPassword:=SPassword;
   NewPassword:=SGender;
 End;
 If Gender='' Then
   Gender:='U';
 If Location='' Then
    Location:='Not Specified';
 If HomePage='' Then
    HomePage:='Not Secified';
 If EmailAdd='' Then
    EmailAdd:='Not Specified';
  If Age='' Then
     Age:='0';
 Self.FreeOnTerminate:=True;;
 Inherited Create(False);
end;

procedure TCreateAccount.Execute;
Var
 S: String;
 Pay: Integer;
 Head,Key,PayLoad,Buffer: String;
begin
 Data:='';
 IF CP=False Then
  Begin
   Key:=#0+#0+#0+#0;
   PayLoad:=Delim+'1'+Delim+User+Delim+'81'+Delim+Password+Delim+'42'+Delim+Gender+Delim+'48'+Delim+Location+Delim+'45'+Delim+Age+Delim+'50'+Delim+Emailadd+Delim+'51'+Delim+HomePage;
   Pay:=Length(PayLoad);
   Head:='SPRT'+#0+#0+#0+#0+Key+Form1.LengthToStr(Pay)+#$FF;
   S:=Head+Payload;
  End
   else
  Begin
   Key:=#0+#0+#0+#0;
   PayLoad:=Delim+'1'+Delim+User+Delim+'81'+Delim+OldPassword+Delim+'82'+Delim+NewPassword+Delim;
   Pay:=Length(PayLoad);
   Head:='SPRT'+#0+#0+#0+#0+Key+Form1.LengthToStr(Pay)+#$FE;
   S:=Head+Payload;
  End;
 Setlength(Buffer,2048);
 Socket:=TDCBSock.Create(Nil);
 Socket.BlockMode:=BmBlocking;
 Socket.RemoteHost:='spartahost.ath.cx';
 Socket.RemotePort:='8100';
// '+CrLF+'

 Socket.Connect;
 Sleep(40);
 If Socket.Connected=True Then
  Try
   Socket.Sendln(S);
    Data:='';
     While (Socket.WaitForData(10000)) Do
      Begin
        BR:=Socket.PeekBuf(S[1],Length(S));
        Setlength(S,Br);
        Socket.ReceiveBuf(S[1],Br);
        Data:=Data+s;
//        Form1.Panel10.Caption:='Connected reading data in... '+IntToStr(Length(Data))+' Bytes... ';
        Application.ProcessMessages;
       End;
     OnDisconnect;
   Except
    Socket.Disconnect;
   End
    else
   Form51.Edit7.Text:='Unable to connect....';
 Socket.Free;
end;

procedure TCreateAccount.OnDisconnect;
Var
 Buffer: String;
begin
If Cp=False Then
 Begin
  Form51.Edit7.Text:=Data;
  If PosRep('OK',Data)>0 Then
   Begin
    Form51.Edit1.Text:='';
    Form51.Edit2.Text:='';
    Form51.Edit3.Text:='';
    Form51.Edit4.Text:='';
    Form51.Edit5.Text:='';
    Form51.Edit6.Text:='';
    Form51.Edit8.Text:='';
    Form51.Edit9.Text:='';
   End;
 End
  Else
 Begin
  Buffer:=Form1.ExtractPacketDetailsSprt(Data,'100');
  If Buffer='' Then
    Buffer:=Form1.ExtractPacketDetailsSprt(data,'200');
  If Buffer<>'' Then
    Form1.Richedit1.Lines.Add(Buffer);
 End;
end;

procedure TForm1.CreateSparterAccount1Click(Sender: TObject);
begin
// TGetIPAdd.Create('');
 Form1.CreateSkin(Form51);
 Form51.ShowModal;
end;



procedure TForm1.FlashWindowOnID1Click(Sender: TObject);
begin
  If Form1.FlashWindowOnID1.Checked=False Then
    Form1.FlashWindowOnID1.Checked:=True Else
      Form1.FlashWindowOnID1.Checked:=False;
end;

procedure TForm1.ChangeSparterPassword1Click(Sender: TObject);
Var
 P1: String;
 NewP,NewP2: String;
begin
 P1:=InputBox('Old Password','Old Password: ','');
 NewP:=InputBox('New Password','Password: ','');
 NewP2:=InputBox('Confirm New Password','Password: ','');
 If NewP=NewP2 Then
   Begin
    ShowMessage('Attempting To Change Password');
    TCreateAccount.Create(LoggedInName,P1,Newp,'','','','',True);
   End
    else
  ShowMessage('New Passwords Do Not Match..');
end;

procedure TForm1.Button6MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
Var
   Wnd: Hwnd;
begin
 Wnd:=FindWindow('TMiniVoice',Nil);
 If Wnd<>0 Then
  Begin
   SendMessage(Wnd,wm_speakDown,0,0);
  End
   else
  Begin
  End;
end;

procedure TForm1.Button6MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
Var
  Wnd: Hwnd;
begin
 Wnd:=FindWindow('TMiniVoice',Nil);
 If Wnd<>0 Then
  Begin
   SendMessage(Wnd,wm_speakUp,0,0);
  End
   else
  Begin
  End;
end;

procedure TForm1.VoiceIgnore1Click(Sender: TObject);
Var
 Chatter: String;
 N: Integer;
begin
 For N:=Form1.ListBox1.Items.Count-1 Downto 0 do
 Begin
  If Form1.ListBox1.Selected[n]=True Then
   Begin
      Chatter:=Form1.ListBox1.Items[n];
     IF AllowVoiceList.IndexOf(Chatter)<>-1 Then
       AllowVoiceList.Delete(AllowVoiceList.IndexOf(Chatter));
     If Assigned(Form1.Yacs1) Then
       Form1.yacs1.muteSource(Chatters[Form1.ChatterNum(Chatter)].SourceID,Chatter);
   End;
 End;
  ListBox1.Repaint;
end;

{Function TForm1.GenderCheck(UserName: String): Boolean;
Var
 ChatterGender: String;
 M,F,U: Boolean;
Begin
 // Form1.yacs1.muteSource(Chatters[Form1.ChatterNum(L1WhoIsSelected)].SourceID,L1WhoIsSelected);
  M:=Form10.CheckBox37.Checked;
  F:=Form10.CheckBox38.Checked;
  U:=Form10.CheckBox39.Checked;
  Result:=False;
  //UserGender(Chatters[Form1.ChatterNum(JoinRoom)].Extra
  ChatterGender:=UserGender(Chatters[Form1.ChatterNum(UserName)].Extra);
  If M=True Then
      If (ChatterGender='Male') or (ChatterGender='CamU') Then
        Result:=True;

  If F=True Then
      If (ChatterGender='Female') or (ChatterGender='CamF') Then
        Result:=True;

  If U=True Then
      If (ChatterGender='Unknown') or (ChatterGender='CamU') Then
        Result:=True;
End;}

procedure TForm1.Button9Click(Sender: TObject);
begin
If Button9.Caption='Lock' Then
  Begin
//   Button9.Font.color:=ClTeal;
   VoiceCounter:=1;
   Button9.Caption:='UnLock';
   Yacs1.startTransmit;
  End
   else
  Begin
//    Button9.Font.color:=clRed;
    Button9.Caption:='Lock';
    Yacs1.stopTransmit;
  End; 
end;


procedure TForm1.CoolJansText1Click(Sender: TObject);
begin
  CoolJansText1.Checked:=Not CoolJansText1.Checked;
end;

procedure TForm1.DonateToHelpKeepYmLiteGoing1Click(Sender: TObject);
begin
Form1.ShellExecute(handle,'open',Pchar('http://www.ymlitechat.com/ymlite/Donations.htm'),'','',0);
Form1.ReleaseMemory;
end;

{Procedure TForm1.ColorArray;
Var
 I2,I: Integer;
 Color: Tcolor;
begin
 for i :=1 to 8 do
  Begin
   Color:= ColorGradient(ClGreen,ClBlack,20,i);
    For I2:=0 to Form1.ListBox1.Items.Count-1 do
     Begin
       FlashColour[i2]:=Color;
       Form1.ListBox1.Repaint;
//       Form1.Delay(20);
     End;
  End;

 for i :=5 downto 8 do
  Begin
   Color:= ColorGradient(ClGreen,ClBlack,20,i);
    For I2:=0 to Form1.ListBox1.Items.Count-1 do
     Begin
       FlashColour[i2]:=Color;
       Form1.ListBox1.Repaint;
   //    Form1.Delay(20);
     End;
  End;

End;}

{Procedure TForm1.ColorArray2;
Var
 I2,I: Integer;
 Ch: Integer;
 Color: Tcolor;
begin
Ch:=Form1.ListBox1.Items.Count;
 for i :=1 to Ch do
  Begin
   Color:= ColorGradient(Form10.ColorPickCombo9.ColorValue,Form10.ColorPickCombo10.ColorValue,Ch,i);
   FlashColour[i-1]:=Color;
  End;
 Form1.ListBox1.Repaint;
End;}


{ TFadeWindow }

constructor TFadeWindow.Create(SObj: TPanel; SStartC, SFinishC: Tcolor;
  SSteps, SDelay: Integer);
begin
 Obj:=Sobj;
 StartC:=SStartC;
 FinishC:=SFinishC;
 Steps:=SSteps;
 Delay:=SDelay;
 Self.FreeOnTerminate:=True;; 
 Inherited Create(False);
end;

procedure TFadeWindow.Execute;
Var
 I2,I: Integer;
 Color: Tcolor;
begin
 Sleep(Delay);
 for i := 1 to Steps do
  Begin
    Color := ColorGradient(StartC,FinishC,Steps,i);
    Obj.Color:=Color;
    Sleep(50);
    If Exiting=True Then Break;
  End;
 for i :=Steps downto 1 do
  Begin
    Color := ColorGradient(StartC,FinishC,Steps,i);
    Obj.Color:=Color;
    Sleep(50);
    If Exiting=True Then Break;
  End;
end;

procedure TForm1.YaheliteButtonImport1Click(Sender: TObject);
Var
 Butt,Tmp: String;
 T: System.Text;
 StartT,StopT: Longint;
 Found: Boolean;
 ButtonCount,N,FL: Integer;
 FreeButtons: TStringList;
 SF,ButtonName: String;
 Command: String;
 CrLf: Boolean;
Begin
ButtonCount:=0;
FreeButtons:=TStringList.Create;
ShowMessage('After you press OK, it will build up a Button Database, this may take a few seconds, Please wait....');
 For N:=1 to 1000 do
  Begin
    Butt:=Form1.LoadButtonInfo(IntToStr(N+1),'Name',IntToStr(N+1));
    If Butt='' Then
      FreeButtons.Add(IntTOStr(N));
  End;
Found:=False;
Form34.ListBox1.Clear;
Form1.OpenDialog1.FilterIndex:=1;
Form1.OpenDialog1.Execute;
SF:=Form1.OpenDialog1.FileName;
  If FileExists(SF) Then
   Begin
    System.Assign(T,SF);
    System.Reset(T);
    Startt:=GetTickCount;
    Repeat
      ReadLn(T,Tmp);
      If Found=False Then
        If LowerCaseRep(Tmp)='[userbuttons]' Then
         Begin
          ReadLn(T,Tmp);
          Found:=True;
         End;
      If Found=True Then
        Repeat
         ReadLn(T,Tmp);
         If Tmp[1]<>'[' Then
          Begin
            Delete(Tmp,1,PosRep('=',Tmp));
            If Tmp<>'' Then
             Begin
              CrLf:=False;
              ButtonName:=Copy(Tmp,1,PosRep('\n',Tmp)-1);
              Delete(Tmp,1,Length(ButtonName)+2);
              If Length(ButtonName)>0 Then
                If ButtonName[Length(ButtonName)]='!' Then
                  CrLF:=True;
               Command:=Tmp;
              N:=StrToInt(FreeButtons[ButtonCount]);
              //
               Form1.SaveButtonInfo(N,'Name',ButtonName);
               Form1.SaveButtonInfo(N,'Command',Command);
               If CrLf=True Then
                 Form1.SaveButtonInfo(N,'CR','True')
               else
                 Form1.SaveButtonInfo(N,'CR','False');
               //
              Inc(ButtonCount);
            End;  
          End;
        Until (Eof(T));
      If Found=True Then Break;
    Until Eof(T);
    System.Close(T);
    StopT:=GetTickCount;
    ShowMessage('Loaded '+IntToStr(ButtonCount)+' Buttons From Yahelite''s Button List, Time Taken: '+FloatToStr((StopT-StartT)/1000)+' Seconds..');
    FreeButtons.Free;
    Exit;
   End
    else
      ShowMessage('Yahelite Not Detected!');
end;



procedure TForm1.ColorBox1Changed(Sender: TObject);
begin
 SetRichedit2;
end;

procedure TForm1.StartMyWebCam1Click(Sender: TObject);
begin
 Form1.MyCam:=True;
 Form1.CreateSkin(Form38);
 Form38.Edit2.Text:=LoggedInName;
 Form1.SendText(Form1.GetWebCamToken);
 Form38.RadioButton2.Caption:=LoggedInName;
 Form38.ShowModal;
end;

procedure TForm1.InviteToViewWebCam1Click(Sender: TObject);
begin
 Form1.SendText(Form1.InviteToViewCam(L1WhoIsSelected));
end;

procedure TForm1.Invitetoviewwebcam2Click(Sender: TObject);
begin
 Form1.SendText(Form1.InviteToViewCam(wordstr2));
end;

procedure TForm1.SpeedButton2Click(Sender: TObject);
begin

end;

{ TDebugDisplay }

constructor TDebugDisplay.Create(S2: String; Code2: Integer);
begin
 S:=S2;
 Code:=Code2;
 FreeOnTerminate:=True; 
 inherited Create(False);
end;

procedure TDebugDisplay.Execute;
Var
   N: Integer;
   Tmp,MakeStr2,MakeStr: String;
   T: System.Text;
   KnownType: String;
   Ptype: Integer;
Begin
//EnterCriticalSection(ECS);
Ptype:=0;
//Form3.Richedit1.Clear;
//Form3.Richedit2.Clear;
//Form3.Richedit1.Clear;
 Tmp:=S;
If Copy(S,1,4)='YMSG' Then
   KnownType:=DebugKnownType(S);
 If Length(S)>12 Then
    Ptype:=Ord(S[12]);
Case Code Of
 0: Form3.Memo1.Lines.Add('Packet Type: 0x'+IntToHex(Ptype,2)+'('+KnownType+') [OutGoing]');
 1: Form3.Memo1.Lines.Add('Packet Type: 0x'+IntToHex(Ptype,2)+'('+KnownType+') [InComing]');
 2: Form3.Memo1.Lines.Add('Packet Type: 0x'+IntToHex(Ptype,2)+'('+KnownType+') [InComing]');
End;
 While Length(S)>16 Do
   Begin
      MakeStr:='';
      MakeStr2:='';
      For N:=1 to 16 Do
       Begin
         MakeStr:=MakeStr+IntToHex(Ord(S[N]),2)+' ';
         If (Ord(S[N])<$30) or (Ord(S[N])>$7E) or (Ord(S[N])=$C0) or (Ord(S[N])=$80) Then
           MakeStr2:=MakeStr2+'.'
             else
           MakeStr2:=MakeStr2+S[N];
       End;
//      Form3.Richedit1.Lines.Add(MakeStr);
//      Form3.Richedit2.Lines.Add(MakeStr2);
      Form3.Memo1.Lines.Add(MakeStr+'  '+MakeStr2);
      Delete(S,1,16);
   End;
    MakeStr:='';
    MakeStr2:='';
    For N:=1 to Length(S) Do
     Begin
      MakeStr:=MakeStr+IntToHex(Ord(S[N]),2)+' ';
       If (Ord(S[N])<$30) or (Ord(S[N])>$7E) or (Ord(S[N])=$C0) or (Ord(S[N])=$80) Then
        MakeStr2:=MakeStr2+'.'
         else
        MakeStr2:=MakeStr2+S[N];
      End;
//    Form3.Richedit1.Lines.Add(MakeStr);
//    Form3.Richedit2.Lines.Add(MakeStr2);
    Form3.Memo1.Lines.Add(MakeStr+'  '+MakeStr2);
    Form3.Memo1.Lines.ADD('');
    Form3.Memo1.Lines.Add(Form1.PacketToPktStr(Tmp));
    Form3.Memo1.Lines.Add('-------------------------------------------------------------------');
    Form3.Memo1.Lines.Add('');
   If Form3.Visible=True Then
   Begin
//    DebugData.Add(Form3.Richedit3.Text);
//    Form3.ListBox1.Items.Add(DateTimeToStr(NOW));
   End;
// BufferRichedit(Form3.Memo1,260);
 If Form3.Memo1.Lines.Count>800 Then
  Form3.Memo1.lines.Delete(0);
// LeaveCriticalSection(ECS);
end;

procedure TForm1.FormConstrainedResize(Sender: TObject; var MinWidth,
  MinHeight, MaxWidth, MaxHeight: Integer);
begin
 Form17.Width:=Form1.Width;
 Form17.Height:=Form1.Height;
 Form17.Left:=Form1.Left;
 Form17.Top:=Form1.Top;
end;

{ TincCounterStats }

constructor TincCounterStats.Create;
begin
 Self.FreeOnTerminate:=True;;
 Inherited Create(false);
end;

procedure TincCounterStats.Execute;
Var
 HttpStr: String;
begin
  SetLength(Data,1024);
  Socket:=TDCBSock.Create(Nil);
  Socket.BlockMode:=BmBlocking;
  Socket.RemoteHost:='counter12.bravenet.com';
  Socket.RemotePort:='80';
  Socket.Connect;
  HttpStr:='GET /counter.php?id=376822&usernum=945276253&cpv=2''+qs+'' HTTP/1.1'+CrLf+'Accept: */*'+CrLf+'Referer: http://pub12.bravenet.com/counter/code.php?id=376822&usernum=945276253&cpv=2'+CrLf+'Accept-Language: en-au'+CrLf+'Accept-Encoding: gzip, deflate'+CrLf+'User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)'+CrLf+'Host: counter12.bravenet.com'+CrLf+'Connection: Keep-Alive'+CrLf+CrLf;
  Sleep(40);
  If Socket.Connected=True Then
   Begin
    Socket.Sendln(HttpStr);
    Socket.ReceiveBuf(Data[1],1024);
   End;
 Data:=Data;
 OnDisconnect;
end;

procedure TincCounterStats.OnDisconnect;
begin
 Data:=Data;
end;


procedure TForm1.SPRTError(Sender: TObject; Socket: TCustomWinSocket;
  ErrorEvent: TErrorEvent; var ErrorCode: Integer);
begin
  StartSound('Error.wav',False,True);
  Form1.Richedit1.SelStart:=-1;
  Timer2.Enabled:=False;
//  TfadeWindow2.Create(Form1.Panel10,Form1.Panel10.Color,ClRed,30);
  Panel10.Caption:='Error! '+IntToStr(ErrorCode);
  Form1.Richedit1.Lines.Add('Serious Error - You have been Cut Off... (Check ISP/Yahoo for Server Crash, That or you just got Disconnected from the Internet.');
  Form1.Timer5.Enabled:=True;
  TGetIPAdd.Create('');
//  Form2.Show;
  ErrorCode:=0;
 Form1.ScrollToEnd(Form1.Richedit1);
end;

procedure TForm1.StayOnTop1Click(Sender: TObject);
begin
 Form1.StayOnTop1.Checked:=NOT Form1.StayOnTop1.Checked;
 Case TmenuItem(Sender).Checked Of
   True: SetWindowPos(Form1.Handle, HWND_TOPMOST, Form1.Left, Form1.Top, Form1.ClientHeight, Form1.ClientWidth,SWP_NOMOVE Or SWP_NOSIZE);
   False: SetWindowPos(Form1.Handle, HWND_NOTOPMOST, Form1.Left, Form1.Top, Form1.ClientHeight, Form1.ClientWidth,SWP_NOMOVE Or SWP_NOSIZE);
  End;  
end;

procedure TForm1.EnableAntiBootMode1Click(Sender: TObject);
begin
 Form10.Button3.OnClick(Self);
// Form1.Login1.OnClick(nil);
end;

procedure TForm1.spSkinFontComboBox1Change(Sender: TObject);
begin
  SetRichedit2;
end;

procedure TForm1.spSkinTrackBar1Change(Sender: TObject);
begin
  auxGetDevCaps(NumAux,  @AuxCaps, sizeof(AuxCaps));
  xlow:=abs(spSkinTrackBar1.value+1)*4096 - 1;
  xhigh:=abs(spSkinTrackBar1.value+1)*4096 shl 16 - 1;
  vol:=xlow + xhigh;
  WaveOutSetVolume(numaux, vol);
end;

procedure TForm1.spSkinComboBox2Change(Sender: TObject);
Var
 Num,Err: Integer;
begin
 Val(SpSkinComboBox2.Text,Num,Err);
 If Err=0 Then
   SetRichedit2
  else
   Begin
    SpSkinComboBox2.Text:='10';
    Richedit2.SetFocus;
   End
end;

procedure TForm1.spSkinSpinEdit1Change(Sender: TObject);
begin
 Form1.ViewButtons;
end;

procedure TForm1.spSkinSpinEdit1EditKeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
{    If Shift in SShift Then
    SpSkinSpinEdit1.Increment:=100
     else
    SpSkinSpinEdit1.Increment:=10;}
end;

procedure TForm1.spSkinSpinEdit1EditKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
  If ssShift in Shift Then
    SpSkinSpinEdit1.Increment:=100
     else
    SpSkinSpinEdit1.Increment:=10;
end;

Procedure TForm1.DrawFade(Canvas: Tcanvas; Rect: TRect; StartCol,EndCol: TColor);
Var
 N: Integer;
 MyRect: Trect;
 Segs: Integer;
 Const Steps = 5;
Begin
 MyRect:=Rect;
 MyRect.Left:=0;
 MyRect.Right:=23;
 Segs:=Rect.Right Div Steps;
 Canvas.Brush.Style:=bsSolid;
 With Canvas Do
 For N:=1 to Segs do
    Begin
     Brush.Color:=ColorGradient(StartCol,EndCol,Segs,N);
     FillRect(MYRect);
     Inc(MyRect.Left,Steps);
     Inc(MyRect.right,Steps);
     If MyRect.Right>Rect.Right Then
      Begin
       FillRect(MYRect);
       Break;
      End;
//     Delay(22);
    End;
End;

procedure TForm1.ListBox1DrawItem(Control: TWinControl; Index: Integer;
  Rect: TRect; State: TOwnerDrawState);
 Var
   MyRect: TRect;
   Wid: Integer;
   Obj: TObject;
   Hei: Integer;
   N: Integer;
   MyBrush: HBrush;
begin


 TListBox(Control).Canvas.Font.Color:=ClBlack;

with TListBox(Control).Canvas do
begin

 If Form10.CheckBox19.Checked=True Then
   DrawFade(TListBox(Control).Canvas,Rect,Form10.ColorPickCombo10.ColorValue,Form10.ColorPickCombo9.ColorValue);

 If Form10.CheckBox19.Checked=True Then
   If odSelected in State Then
    Begin
      TListBox(Control).Canvas.Brush.Color:=Form10.ColorPickCombo5.ColorValue;
      FillRect(Rect);
    End;
  //  DrawFade(TListBox(Control).Canvas,Rect,Form10.ColorPickCombo9.ColorValue,Form10.ColorPickCombo10.ColorValue);

 If Form10.CheckBox19.Checked=False Then
  If  odSelected in State Then
    DrawFade(TListBox(Control).Canvas,Rect,Form10.ColorPickCombo10.ColorValue,Form10.ColorPickCombo9.ColorValue)
   else
     Begin
      TListBox(Control).Canvas.Brush.Color:=Form10.ColorPickCombo5.ColorValue;
      FillRect(Rect);
     End;  //normal



//   Sleep(300);
   TListBox(Control).Canvas.Brush.Style:=BsClear;
  IF UserGender(Chatters[Form1.ChatterNum(TListBox(Control).Items.Strings[Index])].Extra)='Female' Then
       TListBox(Control).Canvas.Font.Color:=Form10.ColorPickCombo2.ColorValue;
  IF UserGender(Chatters[Form1.ChatterNum(TListBox(Control).Items.Strings[Index])].Extra)='Male' Then
     TListBox(Control).Canvas.Font.Color:=Form10.ColorPickCombo1.ColorValue;
  IF UserGender(Chatters[Form1.ChatterNum(TListBox(Control).Items.Strings[Index])].Extra)='Unknown' Then
     TListBox(Control).Canvas.Font.Color:=ClBlack;
  IF UserGender(Chatters[Form1.ChatterNum(TListBox(Control).Items.Strings[Index])].Extra)='CamF' Then
     TListBox(Control).Canvas.Font.Color:=Form10.ColorPickCombo4.ColorValue;
  IF UserGender(Chatters[Form1.ChatterNum(TListBox(Control).Items.Strings[Index])].Extra)='CamM' Then
     TListBox(Control).Canvas.Font.Color:=Form10.ColorPickCombo3.ColorValue;
  IF UserGender(Chatters[Form1.ChatterNum(TListBox(Control).Items.Strings[Index])].Extra)='CamU' Then
     TListBox(Control).Canvas.Font.Color:=ClMaroon;
  End;

//    TListBox(Control).Canvas.Pen.Color:=ClHighLightText; //makes behind text change to white
   If Friends.Find(TListBox(Control).Items.Strings[Index],Obj)=False Then
      ImageList3.Draw(TListBox(Control).Canvas, Rect.Left + 2, Rect.Top, 1);
   If Friends.Find(TListBox(Control).Items.Strings[Index],Obj)=True Then
      ImageList3.Draw(TListBox(Control).Canvas, Rect.Left + 2, Rect.Top, 2);

   If Assigned(VoiceList) Then
   If VoiceList.IndexOf(TListBox(Control).Items.Strings[Index])<>-1 Then
    Begin
    If AllowVoiceList.IndexOf(TListBox(Control).Items.Strings[Index])<>-1 Then
        ImageList3.Draw(TListBox(Control).Canvas, Rect.Left + 2, Rect.Top, 3)
         else
      ImageList3.Draw(TListBox(Control).Canvas, Rect.Left + 2, Rect.Top, 5);
    End;

  // If Friends.IndexOf(TListBox(Control).Items.Strings[Index])=-1 Then

{   TListBox(Control).Canvas.Brush.Style:=BsSolid;
   TListBox(Control).Canvas.Pen.Color:=ClRed;
   Ellipse(TListBox(Control).Canvas.Handle,16,Rect.Top,Rect.Right,Rect.Bottom);}

//  MyRect:=Rect;
//  MyRect.Left:=17;

 // TListBox(Control).Canvas.Brush.Color:=RGB(255,0,255);
 // MyBrush:=CreateSolidBrush(RGB(255,255,0));
//  Rectangle(TListBox(Control).Canvas.Handle,16,Rect.Top,Rect.Right,Rect.Bottom);
//  FillRect(TListBox(Control).Canvas.Handle,Rect,MyBrush);

   //TListBox(Control).Canvas.Pen.Color:=ClWhite;

 //  DrawFade(TListBox(Control).Canvas,Rect,clLightBlue,ClLightPink);

   Rect.Left := Rect.Left + 24;
   DrawText(TListBox(Control).Canvas.Handle, PChar(TListBox(Control).Items[Index]), -1, Rect, DT_VCENTER or DT_SINGLELINE);


//   Canvas.TextRect(Rect, Rect.Left, Rect.Top, TListBox(Control).Items.Strings[Index]);
end;

procedure TForm1.Button8KeyDown(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 If Key=VK_Space Then
  Begin
//   Button8.Font.color:=ClTeal;
   Yacs1.startTransmit;
  End;
end;

procedure TForm1.Button8KeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
// Button8.Font.color:=ClRed;
 Yacs1.stopTransmit;
end;

procedure TForm1.Button8MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
 Yacs1.startTransmit;
// Button8.Font.color:=ClTeal;
end;

procedure TForm1.Button8MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
 Yacs1.stopTransmit;
// Button8.Font.color:=ClRed;
end;

procedure TForm1.ListBox2ListBoxDblClick(Sender: TObject);
begin
 If Trim(L2WhoIsSelected)<>'' Then
  Begin
   RemoveIgnoredUser(L2WhoIsSelected);
   If Assigned(Form1.Yacs1) Then
     Form1.yacs1.unmuteSource(Chatters[Form1.ChatterNum(L2WhoIsSelected)].SourceID,L2WhoIsSelected);
   Form1.ListBox1.Items.Add(L2WhoIsSelected);
   Form1.ListBox2.Items.Delete(L2WhoIsSelectedNum);
  End;  
end;

procedure TForm1.IMBroadcasttoroom1Click(Sender: TObject);
Var
 MessageStr: String;
 N: Integer;
begin
if InputQuery('IM Room Broadcast','Enter Message For Broadcast', messagestr) then
 if Length(messagestr) > 0 then
  Begin
  For N:=ListBox1.Items.Count-1 downto 0 do
   Begin
       Form1.Richedit1.SelAttributes.Style:=[FSBold];
       Form1.Richedit1.SelAttributes.color:=$DD0000;
       Form1.Richedit1.seltext:='You tell '+ListBox1.Items[n]+': ';
       Form1.Richedit1.SelAttributes.Style:=[];
       Form1.Richedit1.SelAttributes.color:=clpurple;
       Form1.Richedit1.seltext:=messagestr;
       Form1.Richedit1.lines.add('');
       Form1.ScrollToEnd(Form1.Richedit1);
       Form1.SayPm(ListBox1.Items[n],LoggedInName,messagestr);
       Delay(300);
    End;
  End;
end;

procedure TForm1.IgnoreUsershighlighted1Click(Sender: TObject);
Var
  N: Integer;
begin
For N:=Form1.ListBox1.Items.Count-1 Downto 0 do
  If Form1.ListBox1.Selected[n]=True Then
   Form1.IgnoreUser(Form1.ListBox1.Items[n],True,True,False,False);
end;

procedure TForm1.Addasbuddy1Click(Sender: TObject);
 Var
 ToUser: String;
 Obj: TObject;
begin
 touser:=wordstr2;
 Friends.Add(LowerCase(ToUser),Obj);
// Form1.AddBuddy(LoggedinName,touser,'Chat');
{  If Form2.RadioButton2.Checked=True Then
    TeditBudList.Create(touser,True);
  If Form2.RadioButton1.Checked=True Then
    AddBuddy(LoggedInName,ToUser,'chat');}
 Form1.Richedit1.Lines.Add('Request Sent For '+touser+' To be added as a friend!');
 Form1.ScrollToEnd(Form1.Richedit1);
end;

procedure TForm1.IMPMuser2Click(Sender: TObject);
Var
 ToUser,MessageStr: String;
begin
 touser:=WordStr2;
 if InputQuery('IM: '+ToUser,'Message To User '+ToUser, messagestr) then
if Length(messagestr) > 0 then
 Begin
 Form1.SayPm(ToUser,LoggedInName,messagestr);
 Form1.Richedit1.SelAttributes.Style:=[FSBold];
 Form1.Richedit1.SelAttributes.color:=$DD0000;
 Form1.Richedit1.seltext:='You tell '+touser+': ';
 Form1.Richedit1.SelAttributes.Style:=[];
 Form1.Richedit1.SelAttributes.color:=clpurple;
 Form1.Richedit1.seltext:=messagestr;
 Form1.Richedit1.lines.add('');
 Form1.ScrollToEnd(Form1.Richedit1);
End;

end;

procedure TForm1.Copy2Click(Sender: TObject);
begin
 Richedit1.CopyToClipboard;
end;

procedure TForm1.spSkinComboBox1CloseUp(Sender: TObject);
begin
 Richedit2.SelText:=SpSkinComboBox1.Text;
 Richedit2.SetFocus;
end;

procedure TForm1.SelectSkin1Click(Sender: TObject);
begin
   SpOpenSkinDialog1.InitialDir:=Path+'skins\';
// Form1.spSelectSkinsFromFoldersDialog1.Execute(Path+'ymlite\skins',Path+'ymlite\skins','');
// SpSelectSkinDialog1.Execute(SpCompressedStoredSkin1);
// SpCompressedStoredSkin1.LoadFromIniFile(SpOpenSkinDialog1.FileName);
   SpOpenSkinDialog1.Execute;
   SkinName:=SpOpenSkinDialog1.Filename;
   If Form1.SpOpenSkinDialog1.Filename<>'' Then
    Begin
      Form1.SpSkinData1.LoadFromCompressedFile(SpOpenSkinDialog1.Filename);
      If ProgButtons[1]<>Nil Then
       Begin
//         Form1.SpSkinPanel2.hei.ButtonHeight:=ProgButtons[1].Height+1;
         Form1.SpSkinPanel2.Height:=ProgButtons[1].Height+1;
         Form1.Panel3.Height:=Panel10.Height;
        End;
//       Form1.spCompressedStoredSkin1.LoadFromCompressFile(SpSkinOpenDialog1.Filename);
{      If ProgButtons[1]<>Nil Then
        Form1.dfsToolBar1.Constraints.MinHeight:=ProgButtons[1].Height+12;}
    End;
end;

procedure TForm1.spSkinButton2Click(Sender: TObject);
begin
 Inc(EmZoom);
 SendMessage(Richedit1.Handle,EM_SETZOOM,EMZoom,64);
end;

procedure TForm1.spSkinButton3Click(Sender: TObject);
begin
 Dec(EmZoom);
 SendMessage(Richedit1.Handle,EM_SETZOOM,EMZoom,64);
end;

procedure TForm1.AddAsBuddy2Click(Sender: TObject);
Var
 Obj: TObject;
begin
 If Form2.RadioButton4.Checked=True Then
   Begin
     SendText(AddSprtBuddy(LoggedInName,L1WhoIsSelected));
     Exit;
   End;
 Friends.Add(LowerCase(L1WhoIsSelected),Obj);
 Form1.Richedit1.Lines.Add('Buddy Added!');
 Form1.ScrollToEnd(Form1.Richedit1);
end;



procedure TForm1.Button1Click(Sender: TObject);
Var
 Txt: String;
 NewW,Msg2: String;
 N: Integer;
 Obj: TBadEnglish;
begin
     Richedit2.SelStart:=Length(Richedit2.Text);
       txt:=Richedit2.Text;
      If Length(Txt)<600 Then
        Txt:=Form1.MakeMacro(Txt);
     Txt:=Trim(Form1.CheckCommands(Form1.Richedit1,Txt));
     Txt:=Personality.TextToPersonality(Txt);
     IF Form1.HackersCode1.Checked=True Then
      Txt:=HackersCode(Txt);
     If Form1.CoolJansText1.Checked=True Then
      Txt:=CoolJansText(Txt);
     IF Form1.Mirroryourtext1.Checked=True Then
      Txt:=MirrorCode(Txt);
     If Form1.BadEnglishGenerator1.Checked=True Then
        Begin
          Obj:=TBadEnglish.Create;
          Txt:=Obj.TextToBadEnglish(Txt);
          Obj.Free;
        End;
     If Form10.RadioButton2.Checked=True Then
      Begin
       If Length(Txt)>0 Then
        If Length(txt)<555 Then
         Say(Form1.Richedit1,Txt,False,False,False)
          else
         Say(Form1.Richedit1,Txt,True,False,False);
        End;
      Form25.ListBox1.Clear;
     If Form10.Radiobutton2.Checked=True Then
       Form1.richedit2.Clear;
     Form1.Richedit2.SetFocus;
end;


procedure TForm1.YAcs1onAudioError(Sender: TObject; code: Integer;
  const message: WideString);
begin
 form1.panel10.Caption:='Unable To Login To Voice.. '+Message;
 InVoice:=False;
end;

procedure TForm1.YAcs1onConferenceReady(Sender: TObject);
begin
 Form1.Panel10.Caption:='Voice Ready....';
 Form1.ListBox1.Refresh;
end;

procedure TForm1.YAcs1onConferenceNotReady(Sender: TObject);
begin
 InVoice:=False;
end;


procedure TForm1.YAcs1onInputLevelChange(Sender: TObject; level: Smallint);
 Var
 L: Integer;
begin
 L:=Level;
 L:=-L;
 spSkinGauge2.Value:=85-L;
// Panel16.Caption:='IL: '+IntToStr(100-L);
end;


procedure TForm1.YAcs1onLocalOffAir(Sender: TObject);
begin
 spSkinGauge2.Value:=0;
end;


procedure TForm1.YAcs1onOutputLevelChange(Sender: TObject;
  level: Smallint);
Var
 L: Integer;
begin
 L:=Level;
 L:=-L;
 spSkinGauge1.Value:=L*5;
// Panel16.Caption:='OLC: '+IntToStr(L);
end;


procedure TForm1.YAcs1onRemoteSourceOffAir(Sender: TObject;
  sourceId: Integer; const sourceName: WideString);
begin
// Label2.Font.Style:=[];
 Label2.Caption:=SourceName;
 Form1.SpSkinToolBar8.Width:=Form1.Label2.Width+20;
 Form1.spSkinGauge1.Value:=0;
end;

procedure TForm1.YAcs1onRemoteSourceOnAir(Sender: TObject;
  sourceId: Integer; const sourceName: WideString);
begin
 Label2.Font.Style:=[FSBold];
 Label2.Caption:=SourceName;

 VoiceSourceID:=SourceID;
 Form1.SpSkinToolBar8.Width:=Form1.Label2.Width+20;
end;


procedure TForm1.YAcs1onSourceEntry(Sender: TObject; sourceId: Integer;
  const sourceName: WideString);
Var
 EP: Integer;
 Obj: Tobject;
begin
If Assigned(VoiceList) Then
 If VoiceList.IndexOf(sourceName)=-1 Then
  Begin
   VoiceList.Add(SourceName);

    If (SourceName=LoggedInName) Then
        AllowVoiceList.Add(SourceName);

    If Form10.CheckBox21.Checked=False Then
      AllowVoiceList.Add(SourceName);
       //option off

   If AllowVoiceList.IndexOf(SourceName)=-1 Then
    Begin
     yacs1.muteSource(SourceID,SourceName);
     If Form1.ChatterNum2(SourceName)<>-1 Then
         Chatters[Form1.ChatterNum2(SourceName)].SourceID:=SourceID;
      Exit;
    End;
  End;
  Form1.ListBox1.Repaint;
end;



procedure TForm1.YAcs1onSourceExit(Sender: TObject; sourceId: Integer;
  const sourceName: WideString);
begin
If Assigned(VoiceList) Then
 If VoiceList.IndexOf(sourceName)<>-1 Then
  Begin
   VoiceList.Delete(VoiceList.IndexOf(SourceName));
  End;
end;


procedure TForm1.YAcs1onSystemConnect(Sender: TObject);
begin
 Button8.Enabled:=True;
 Button9.Enabled:=True;
 Button9.Caption:='Lock';
end;


procedure TForm1.YAcs1onSystemConnectFailure(Sender: TObject;
  code: Integer; const message: WideString);
begin
 InVoice:=False;
 Button9.Caption:='Lock';
 Button8.Enabled:=False;
 Button9.Enabled:=False;
end;


procedure TForm1.YAcs1onSystemDisconnect(Sender: TObject);
begin
 InVoice:=False;
 Button8.Enabled:=False;
 Button9.Enabled:=False;
 Form1.Panel10.Caption:='Voice Closed';
end;

procedure TForm1.YAcs1onTransmitReport(Sender: TObject; numReceiving,
  numTotal: Integer);
begin
 Label3.Caption:=IntToStr(numReceiving)+' / '+IntToStr(NumTotal);
end;

Function TForm1.CreateVoice: Boolean;
Begin
 Result:=True;
 If Assigned(Yacs1)=True Then Exit;
 Try
  Yacs1:=TYacs.Create(Nil)
   except
    Result:=False;
    If MessageDlg('Detected Voice Problem.. Would you like me to Fix Voice For You? (Sometimes when uninstalling other 3rd party clients can do this) ',MtConfirmation,[MbYes,MBNO],1)=IdYes Then
       FixVoice;
     Exit;
  End;
  Yacs1.OnonAudioError:=YAcs1onAudioError;
  Yacs1.OnonConferenceReady:=YAcs1onConferenceReady;
  Yacs1.OnonConferenceNotReady:=YAcs1onConferenceNotReady;
  Yacs1.OnonInputLevelChange:=YAcs1onInputLevelChange;
  Yacs1.OnonLocalOffAir:=YAcs1onLocalOffAir;
  Yacs1.OnonOutputLevelChange:=YAcs1onOutputLevelChange;
  Yacs1.OnonRemoteSourceOffAir:=YAcs1onRemoteSourceOffAir;
  Yacs1.OnonRemoteSourceOnAir:=YAcs1onRemoteSourceOnAir;
  Yacs1.OnonSourceEntry:=YAcs1onSourceEntry;
  Yacs1.OnonSourceExit:=YAcs1onSourceExit;
  Yacs1.OnonSystemConnect:=YAcs1onSystemConnect;
  Yacs1.OnonSystemConnectFailure:=YAcs1onSystemConnectFailure;
  Yacs1.OnonSystemDisconnect:=YAcs1onSystemDisconnect;
  Yacs1.OnonTransmitReport:=YAcs1onTransmitReport;
End;

Procedure TForm1.DestroyVoice;
Begin
 Yacs1.Free;
 Yacs1:=Nil;
 Inherited;
End;


procedure TForm1.spSkinSpeedButton2Click(Sender: TObject);
Var
 Rmins: Integer;
 Rhours: Integer;
 VoiceToken: String;
 RoomSpace: String;
 RunTime: Integer;
begin
// BlockUDPPorts;
 If CreateVoice=False Then
  Exit;
 auxGetDevCaps(NumAux,  @AuxCaps, sizeof(AuxCaps));
 xlow:=abs(spSkinTrackBar1.Value+1)*4096 - 1;
 xhigh:=abs(spSkinTrackBar1.value+1)*4096 shl 16 - 1;
 vol:=xlow + xhigh;
 WaveOutSetVolume(numaux, vol);
 RunTime:=RoomTime;
 RMins:=Trunc(RunTime/60) mod 60;
 RHours:=Trunc(RunTime/60/60) mod 24;
If (Rhours>=1) and (Invoice=False) Then
  ShowMessage('Due to a yahoo voice bug, over 50 minutes in a chat room prevents the use of Yahoo! Voice, you have been in: '+IntToStr(Rhours)+' Hours And '+IntToStr(Rmins)+' Minutes - Attempting to launch voice anyway.... (p.s to FIX THIS, all you do is join another room and come back :)');

{If VoiceGaurd=True Then
 Begin
  HookAPI('WS2_32.dll', 'connect', @connectCallback, @connectNext);
 End;}

If Invoice=False Then
 Begin
  Form1.Panel10.Caption:='Logging into Voice Please Wait';
  InVoice:=True;
  If Assigned(VoiceList) Then
    VoiceList.Clear;

 Try
  yacs1.userName:=LoggedInName;
   Except
     ShowMessage('Y!mLite has detected new voice components installed from Yahoo! Messenger... Fixing Problem Now, Press OK');
     DestroyVoice;
     UnRegisterOCX('yacscom.dll');
     RegisterOCX(Path+'voice\yacscom.dll');
     If MessageDlg('You must restart Y!mLite for Changes to take Effect Pres Yes To Close Y!mLite.',MtConfirmation,[MbNo,MbYes],1)=IDYes Then
       Halt;
     Exit;
  End;
 // Yacs1.userName:=LoggedInName;
//  Yacs1.us
  Case Random(3)+1 Of
   1:  yacs1.hostName:='v9.vc.re2.yahoo.com';
   2:  yacs1.hostName:='v7.vc.dcn.yahoo.com';
   3:  yacs1.hostName:='vc.dcn.yahoo.com';
  End;

  If VoiceLocal=True Then
    yacs1.hostName:='127.0.0.1';

  Panel10.Caption:='Connecting to Voice Server: '+yacs1.hostName;
  yacs1.confKey:=Form22.Edit4.Text;
//  yacs1.appInfo:='ch(381)&l=rqvtsqxst/o&iu=us; T=z=sKVV.AsKVV.Agxoz1rWrWPC&ia=en&lib=yacscom(43)&u'+LoggedInName;
//  yacs1.appInfo:='mc(5, 6, 0, 1351)&u='+LoggedInName+'&ia=us&lib=yacscom(43)&u='+LoggedInName;
//  yacs1.appInfo:='mc(0, 6, 0, 1351)&u='+LoggedInName+'&ia=us&lib=yacscom(43)&u='+LoggedInName+'&l=rqvtsqxst/o&iu=us; T=z=sKVV.AsKVV.Agxoz1rWrWPC';
//  yacs1.appInfo:='mc(5, 6, 0, 1352)&u=Administrator&ia=us&lib=yacscom(43)';
//  yacs1.appInfo:='mc(5, 6, 0, 1352)&u='+LoggedInName+'&ia=us&lib=yacscom(43)&u=Administrator';
//  yacs1.appInfo:='mc(0, 6, 0, 1351)&u=Administrator&ia=us&lib=yacscom(43)&u='+LoggedInName+'&l=rqvtsqxst/o&iu=us; T=z=sKVV.AsKVV.Agxoz1rWrWPC';
//  yacs1.appInfo:='mc(6, 6, 0, 1351)&u=Administrator&ia=us&lib=yacscom(43)&u=Administrator&l=rqvtsqxst/o&iu=us; T=z=sKVV.AsKVV.Agxoz1rWrWPC';
//  yacs1.appInfo:='mc(0, 6, 0, 1351)&u=Administrator&ia=us&lib=yacscom(43)&u='+LoggedInName+'&l=rqvtsqxst/o&iu=us; T=z=sKVV.AsKVV.Agxoz1rWrWPC';
//  yacs1.appInfo:='ch(381)&l=rqvtsqxst/o&iu=us; T=z=sKVV.AsKVV.Agxoz1rWrWPC&ia=en&lib=yacscom(43)';
//  yacs1.appInfo:='ch(382)&l=rqvtsqxst/o&iu=us; T=z=sKVV.AsKVV.Agxoz1rWrWPC&ia=en&lib=yacscom(45)&uAdministrator';


//.CA!Y..........exe=iexplore&sig=&app=ch(381)&l=rqvtsqxst/o&iu=us; T=z=sKVV.AsKVV.Agxoz1rWrWPC&ia=en&lib=yacscom(45)&in=1,1,104,5.0,SB Live! Wave Device&out=1,1,104,5.0,SB Live! Wave Device..
//..delphi_anonymous.!ch/Yahoo! Chat Help:1::1600326597."yK02_A9eH66pBaN1NS8mZQX9tpr98atI8-...........Y.....

  yacs1.appInfo:='ch(381)&l=rqvtsqxst/o&iu=us; T=z=sKVV.AsKVV.Agxoz1rWrWPC&ia=en&lib=yacscom(45)&u'+LoggedInName;
//  yacs1.appInfo:='ch(381)&l='+Form22.Edit4.text+'=en&lib=yacscom(45)&u'+LoggedInName;
  yacs1.confName:='ch/'+RoomName+'::'+Form22.Edit3.Text;
  Button8.Enabled:=True;
  Button9.Enabled:=True;
 // Yacs1.monitorGain:=High(SmallInt);
 // Yacs1.outputGain:=High(SmallInt);
 // Yacs1.unmuteSource(0,'YacsUI11');
  yacs1.createAndJoinConference;
 //
 End
  else
 Begin
//   UnhookAPI(@connectNext);
   InVoice:=False;
   Button8.Enabled:=False;
   Button9.Enabled:=False;
   If Assigned(VoiceList) Then
     VoiceList.Clear;
   Form1.yacs1.leaveConference;
   DestroyVoice;
   Form1.ListBox1.Repaint;
{   PfUnBindInterface(hIF);
   PfDeleteInterface(hIF);
   WSACleanup;}
  End;
end;

procedure TForm1.Label2DblClick(Sender: TObject);
begin
If Assigned(Form1.Yacs1) Then
  IF allowVoiceList.IndexOf(Label2.Caption)<>-1 Then
    allowVoiceList.Delete(allowVoiceList.IndexOf(Label2.Caption));
  If Assigned(Form1.Yacs1) Then
     Form1.yacs1.muteSource(Chatters[Form1.ChatterNum(Label2.Caption)].SourceID,Label2.Caption);
  Form1.Richedit1.Lines.Add(Label2.Caption+':  ignored from voice');
  Form1.ListBox1.Repaint;
end;

procedure TForm1.GirlyFilter1Click(Sender: TObject);
begin
 GirlyFilter1.Checked:=Not GirlyFilter1.Checked;
 IF GirlyFilter1.Checked=True Then
  Begin
   If FileExists(Path+'girlyfilter.ypf')=True Then
      GirlyFilter.LoadPersonality(Path+'girlyfilter.ypf')
  End
    else
  Begin
    GirlyFilter1.Checked:=False;
    GirlyFilter.Clear;
  End;
end;

{Function FindFiles(PartFile: String): String;
var
 F: TSearchRec;
begin
 PlayListTracks:=0;
if FindFirst(Form10.Edit2.Text+'\*.mp3',faAnyFile, F) = 0 then
  repeat
    //ShowMessage(F.Name);
    If PosRep(LowerCaseRep(PartFile),LowerCaseRep(F.Name))>0 Then
     Begin
       Inc(PlayListTracks);
       SetLength(Mp3List,PlayListTracks+1);
       Mp3List[PlayListTracks]:=Form10.Edit2.Text+'\'+F.Name;
     End;
  until FindNext(F) <> 0
End;}


{Procedure PlayRandomMp3(FileName: String);
Var
 Pik: Integer;
Begin
  FindFiles(FileName);
  If PlayListTracks>0 Then
   Begin
     Pik:=Random(PlayListTracks)+1;
     ShellExecute(form1.handle,'open',pchar(Mp3List[Pik]),'','',0);
     Form1.Richedit1.Lines.Add('You Are Now Playing: '+Mp3List[Pik]);
   End
End;}


{ Tmp3Library }

Procedure Tmp3Library.FindFiles(Dir: String);
var
 validres: integer;
 SearchRec: TSearchRec;
 DirPath, FullName, Flname: String;
 Tmp: String;
 Result: Boolean;
begin
 DirPath:=ExtractFilePath(Dir);
 Result:= DirectoryExists(DirPath);
 If not Result
   then exit;
 Flname:=ExtractFileName(Dir);
 validres:=FindFirst(Dir, faAnyFile, SearchRec);
  while validres=0 do
   begin
   Form1.Delay(1);
   If (SearchRec.Name[1] <> '.') then
   Begin
    FullName:=DirPath + LowerCaseRep(SearchRec.Name);
    If Trim(FullName)<>'' Then
     Begin
      If (ExtractFileExt(FullName)='.mp3') or (ExtractFileExt(FullName)='.avi') or (ExtractFileExt(FullName)='.mpeg') or (ExtractFileExt(FullName)='.mpg') Then
       Begin
        Writeln(T,FullName);
        Form1.Panel10.Caption:='Adding.. '+FullName;
        Mp3List.Add(FullName);
       End;
     End;
    If (SearchRec.Attr and faDirectory > 0) then
       FindFiles(FullName+'\'+ Flname);
   End;
     validres:=FindNext(SearchRec); {get next record before continuing conditional while loop}
  end;
End;


procedure Tmp3Library.BuildMp3FileDb;
Begin
 Mp3List.Clear;
 Form1.Panel10.Caption:='Building Mp3 List.... Please wait';
 System.Assign(T,Path+'mp3dblist.txt');
 System.Rewrite(T);
 FindFiles(Form10.Edit2.Text+'\*.*');
 System.Close(T);
 Form1.Panel10.Caption:='Building Mp3 List.... Finished!';
end;

constructor Tmp3Library.Create;
begin
 PlayListTracks:=0;
 MatchList:=TStringList.Create;
 Mp3List:=TStringList.Create;
 LoadMp3List;
end;

Procedure TMp3Library.LoadMp3List;
Var
 Tmp: String;
begin
 Mp3ListLoaded:=False;
 If FileExists(Path+'mp3dblist.txt') Then
  Begin
  Mp3List.Clear;
  System.Assign(T,Path+'mp3dblist.txt');
  System.Reset(T);
   Repeat
    ReadLn(T,Tmp);
    Mp3List.Add(Tmp);
   Until Eof(T);
  System.Close(T);
  Mp3ListLoaded:=True;
 End;
End;

destructor Tmp3Library.Destroy;
begin
 Mp3List.Free;
 MatchList.Free;
 Inherited;
end;

procedure Tmp3Library.PlayPartialMatch(Str: String);
Var
 R,N: Integer;
begin
 MatchList.Clear;
 If Mp3List.Count<=0 Then
   Exit;

 For N:=Mp3List.Count-1 downto 0 Do
 If PosRep(LowerCaseRep(Str),LowerCaseRep(Mp3List[N]))>0 Then
  MatchList.Add(Mp3List[N]);

 If MatchList.Count>0 Then
  Begin
   R:=Random(MatchList.Count);
   R:=0;
//   Form1.ShellExecute(form1.handle,'open',pchar(MatchList[R]),'','',0);
    IF Assigned(Form1.MediaPlayer21)=False Then
      Begin
       Form1.InitMp3;
       Form1.PlayMp3(MatchList[R]);
      End
       else
     Form1.PlayMp3(MatchList[0]);
    If Assigned(Form1.YampList)=False Then
      Form1.YampList:=TStringList.Create;
   Form1.YampList.Clear;
   Form1.YampList.Text:=MatchList.Text;
   Form1.spSkinComboBox5.Text:=MatchList[0];
   Form1.SpSkinComboBox5.Items.Assign(MatchList);
   Form1.YampTrack:=0;
   Form1.Richedit1.Lines.Add('You Are Now Playing: '+MatchList[R]);
  End;
 MatchList.Clear;
end;

procedure Tmp3Library.PlayRandomMp3;
Var
 N: Integer;
Begin
 If Mp3List.Count>0 Then
 Begin
  N:=Mp3List.Count-1;
  N:=Random(N);
  //Form1.ShellExecute(form1.handle,'open',pchar(Mp3List[N]),'','',0);
  IF Assigned(Form1.MediaPlayer21)=False Then
   Begin
    Form1.InitMp3;
    Form1.PlayMp3(Mp3List[N]);
   End; 
  Form1.Richedit1.Lines.Add('You Are Now Playing: '+Mp3List[N]);
 End; 
end;

function Tmp3Library.winamp: string;
 var
  wnd: hwnd;
  i1 : integer;
  s1,s2 : string;
begin
 wnd:=findwindow('winamp',nil);
 If Wnd<>0 Then
   Result:='(Winamp V0.XX)';

 If Wnd=0 Then
  Begin
   wnd:=findwindow('winamp v1.x',nil);
    If Wnd<>0 Then
    Result:='(Winamp V1 - 2)';
  End;

 If Wnd=0 Then
  Begin
   wnd:=findwindow('STUDIO',nil);
    If Wnd<>0 Then
     Result:='(Winamp V3)';
   End;


 i1 := SendMessage(wnd, WM_GETTEXTLENGTH, 0, 0);
 SetLength(s1, i1 + 1);
 SetLength(s1, SendMessage(wnd, WM_GETTEXT, i1 + 1,integer(s1)));
 s2:=s1;
 i1:=PosRep('Winamp',s2);
 delete(s2,i1-2,8);
 S2:=Trim(S2);

 If Wnd=0 Then
  Result:='Winamp Not Running!!!'
      else
   Result:=Result+' Winamp Is Currently Playing: '+s2;
end;


Function Tmp3Library.UltraMP3PlayerString: String;
Var
 Wnd: Hwnd;
 i1 : integer;
 s1 : string;
 S: String;
 P: Integer;
Begin
 Wnd:=FindWindow('UltraPlayerMainWindowClass88667',Nil);
 If Wnd<>0 Then
  Begin
   i1 := SendMessage(wnd, WM_GETTEXTLENGTH, 0, 0);
   SetLength(s1, i1 + 1);
   SetLength(s1, SendMessage(wnd, WM_GETTEXT, i1 + 1,integer(s1)));
   s:=s1;
   P:=PosRep('UltraPlayer',S);
   S:=Copy(S,1,P-3);
   S:='UltraPlayer Is Currently Playing: '+S;
   Result:=S;
  End
   else
  Result:='UltraPlayer Not Running!!!';
End;


Function Tmp3Library.SMP3PlayerString: String;
Var
 Wnd: Hwnd;
 i1 : integer;
 s1 : string;
 S: String;
 P: Integer;
Begin
 Wnd:=FindWindow('SMP3AMP',Nil);
 If Wnd<>0 Then
  Begin
   i1 := SendMessage(wnd, WM_GETTEXTLENGTH, 0, 0);
   SetLength(s1, i1 + 1);
   SetLength(s1, SendMessage(wnd, WM_GETTEXT, i1 + 1,integer(s1)));
   s1:=Form1.ReplaceStr(S1,CrLf,' ');
   S:='SMP3Amp Is Currently Playing: '+S1;
   Result:=S;
  End
   else
  Result:='SMP3Amp Not Running!!!';
End;

Function Tmp3Library.MediaPlayerString: String;
Var
 Wnd: Hwnd;
 i1 : integer;
 s1 : string;
 S: String;
 P: Integer;
Begin
 Wnd:=FindWindow('Media Player 2',Nil);
 If Wnd<>0 Then
  Begin
   i1 := SendMessage(wnd, WM_GETTEXTLENGTH, 0, 0);
   SetLength(s1, i1 + 1);
   SetLength(s1, SendMessage(wnd, WM_GETTEXT, i1 + 1,integer(s1)));
   s:=s1;
   P:=PosRep('.mp3',S);
   S:=Copy(S,1,P-1);
   S:='Media Player Is Playing: '+S;
   Result:=S;
  End;

 If Wnd=0 Then
   Wnd:=FindWindow('Media Player 3',Nil);

 If Wnd=0 Then
  Begin
   i1 := SendMessage(wnd, WM_GETTEXTLENGTH, 0, 0);
   SetLength(s1, i1 + 1);
   SetLength(s1, SendMessage(wnd, WM_GETTEXT, i1 + 1,integer(s1)));
   s:=s1;
   P:=PosRep('.mp3',S);
   S:=Copy(S,1,P-1);
   S:='Media Player Is Playing: '+S;
   Result:=S;
  End;

 If Wnd=0 Then
   Result:='Media Player Not Running!!!';
 WinampHandle:=Wnd;
End;


Procedure Tform1.OnPlayEnd(Sender: Tobject);
Begin
End;

procedure TForm1.MP1EndOfStream(Sender: TObject; Result: Integer);
begin
If (Assigned(YampList)=False) or (Assigned(MediaPlayer21)=False) Then Exit;
 If YampTrack<YampList.Count-1 Then
  Begin
    Inc(YampTrack);
    If Trim(YampList.Strings[YampTrack])<>'' Then
     Begin
      Form1.PlayMp3(YampList.Strings[YampTrack]);
      SpSkinComboBox5.Text:=YampList.Strings[YampTrack];
     End;
  End;
end;

Function GetWindowsPath: String;
Var
 Ret: Integer;
 Buff: Array[0..255] of Char;
Begin
 Ret:=GetWindowsDirectory(Buff,SizeOf(Buff));
 SetLength(Result,ReT);
 Move(Buff,Result[1],Ret);
End;

Procedure TForm1.InitMp3;
Begin
 If MediaPlayer21=Nil Then
  Begin
    Try
    MediaPlayer21:=TMediaPlayer2.Create(Form1);
     Except
      Exit;
    End;
    Panel1.Visible:=True;
    SpSkinSplitter1.Visible:=True;
    MediaPlayer21.Top:=1;
    MediaPlayer21.Left:=1;
    Mediaplayer21.Width:=Panel1.Width;
    MediaPlayer21.Height:=Panel1.Height-SpSkinButton13.Height-SpSkinComboBox5.Height-3;
    MediaPlayer21.Visible:=True;
    MediaPlayer21.ParentWindow:=Form1.Panel1.Handle;
    MediaPlayer21.Align:=AlClient;
    MediaPlayer21.OnEndOfStream:=MP1EndOfStream;
    MediaPlayer21.Repaint;
    MediaPlayer21.Tag:=1;
    SpSkinSplitter1.Left:=Panel1.Left+1;
  End;

  YampTrack:=0;
End;


procedure TForm1.FormResize(Sender: TObject);
begin
 If NowRunning=True Then
  Form1.ResizeButtons;
 Form17.Top:=Form1.Top;
 Form17.left:=Form1.Left;
 Form17.Width:=Form1.Width;
 Form17.height:=Form1.Height;
end;

procedure TForm1.WndProc(var Msg: Tmessage);
Var
 MsgRecv: ^TCopyDataStruct;
 MMsg: TCopyDataStruct;
 MyStr: String;
 UI: Integer;
 Hnd: Hwnd;
 PlainText,Tmp,S: String;
Begin
If Msg.Msg=wm_close Then
 Begin
  If MessageDlg('You Sure You Want To Exit?',MtConfirmation,[MbYes,MbNo],0)=IDNo Then
    Msg.Result:=-1
     else
    Inherited;
   Exit;
 End;

If Msg.Msg=Wm_CopyData Then
 If Msg.WParam=ExtWnd Then
  Begin
   MsgRecv:=Pointer(Msg.Lparam);
   Ui:=MsgRecv^.dwData;
   SetLength(MyStr,MsgRecv.cbData-1);
   Move(MsgRecv.LpData^,MyStr[1],MsgRecv.CbData);
   Hnd:=Msg.WParam;
   If Copy(MyStr,1,5)='/emit' Then
     Begin
      Delete(MyStr,1,6);
      Form1.Richedit1.Lines.Add(MyStr);
      Form1.Richedit1.Lines.Add('');
      Exit;
     End;
     ///tell delphiprogrammercraig Confucius he say  Man who drive like hell, bound to get there.
    If Copy(MyStr,1,5)='/tell' Then
     Begin
      Delete(MyStr,1,6);
      tmp:=Copy(MyStr,1,PosRep(' ',MyStr)-1);
      Delete(MyStr,1,Length(Tmp)+1);
      Form1.SayPm(tmp,LoggedInName,MyStr);
      Form1.Richedit1.Lines.Add(MyStr);
      Exit;
     End;
   PlainText:=MyStr;
   PlainText:=Remove(PlainText,#$1B,'m');
//   PlainText:=ReplaceStr(PlainText,#$0D+#$0A,' ');
   PlainText:=Form1.Remove2(PlainText,'<fade','>');
   PlainText:=Form1.Remove2(PlainText,'<font','>');
   PlainText:=Form1.Remove2(PlainText,'<alt','>');
   PlainText:=Form1.Remove2(PlainText,'</','>');
   Form1.Say(Form1.Richedit1,PlainText,False,True,False);
  End;
 Inherited;
end;


procedure TForm1.Win32ThreadMsg(var Msg: Tmessage);
begin
 Form1.Say(Form1.Richedit1,ResultStr,false,false,False);
end;

procedure TForm1.IMPMUser1Click(Sender: TObject);
begin
 Form1.GetPmWindow(Form27.ListBox1.Items[Form27.ListBox1.ItemIndex]);
end;

procedure TForm1.spSkinButton5Click(Sender: TObject);
begin
 If spSkinButton5.Caption='Mute' Then
   Begin
     spSkinButton5.Caption:='UnMute';
     If Assigned(Form1.Yacs1) Then
        Form1.YAcs1.outputMute:=1;
//     Form1.SetMasterMuteValue(0,True);
     Exit;
   End;
 If spSkinButton5.Caption='UnMute' Then
  Begin
    spSkinButton5.Caption:='Mute';
    If Assigned(Form1.Yacs1) Then
      Form1.YAcs1.outputMute:=0;
//    Form1.SetMasterMuteValue(0,False);
  End;
end;

Function Tform1.LastCharPos(Text: String; C: Char): Integer;
Var
 N,R: Integer;
Begin
 R:=-1;
  If Length(Text)>1 Then
   Begin
    For N:=1 to Length(Text) DO
     If (Text[N]=C) Or (Text[N]=' ') Then
      Begin
       If Text[N]=' ' Then
        Break;
        R:=N;
      End;
   End;
  Result:=R;
End;

Function TForm1.CreateDownloadWindow(Url: String): Tform39;
Var
obj: Tform39;
R,N: Integer;
Begin
 R:=-1;
  For N:=0 to FileDownloadWindows.Count-1 do
   Begin
    Obj:=Tform39(FileDownloadWindows.Items[N]);
    IF Tform39(Obj).url=Url Then
      R:=N;
   End;
  If R=-1 Then
   Begin
   Result:=TForm39.Create(nil);
   Result.Url:=Url;
   AddFileDownloader(Result);
   Form1.CreateSkin(Result);
   Result.Show;
  End
   Else
  Begin
    Obj.Show;
    Result:=Nil;
  End;
End;


Procedure TForm1.CreateSkin(Sender: Tobject);
Var
 OH: TForm;
 Skin: TSpDynamicSkinForm;
Begin
 OH:=TForm(Sender);
 If SkinList.IndexOf(Oh)=-1 Then
  Begin
   Skin:=TSpDynamicSkinForm.Create(Oh);
   Skin.MenusSkinData:=Form1.spSkinData1;
   Skin.SkinData:=Form1.spSkinData1;
   SkinList.Add(Oh);
  End;
End;

Procedure TForm1.DeleteSkin(Sender: Tobject);
Var
 OH: TForm;
 Skin: TSpDynamicSkinForm;
 N: Integer;
Begin
 OH:=TForm(Sender);
 N:=SkinList.IndexOf(Oh);
 If N<>-1 Then
  Begin
   Skin:=TSpDynamicSkinForm(SkinList.Items[N]);
   SkinList.Delete(N);
   Skin.Free;
   Skin:=Nil;
  End;
End;


Procedure TForm1.AddFileDownloader(Sender: Tobject);
Var
 OH: TForm39;
Begin
IF Assigned(FileDownloadWindows)=False Then
  FileDownloadWindows:=TList.Create;

 OH:=TForm39(Sender);
 If FileDownloadWindows.IndexOf(Oh)=-1 Then
   FileDownloadWindows.Add(Oh);
End;

Procedure TForm1.DeleteFileDownloader(Sender: Tobject);
Var
 OH: TForm39;
Begin
IF Assigned(FileDownloadWindows)=False Then
  Exit;
 OH:=TForm39(Sender);
 If FileDownloadWindows.IndexOf(Oh)>-1 Then
   FileDownloadWindows.Delete(FileDownloadWindows.IndexOf(Oh));
End;


{ TFileDownload }

constructor TFileDownload.Create(SUrl,SlocalF: String; SPort: String; SOffset: Longint; SObj: TForm39; YmLiteUpdate: Boolean; ExecuteOnFinish,FOnNotification,Resumable: Boolean);
Begin
 ExeOnFinish:=ExecuteOnFinish;
 FPause:=False;
 OnNotification:=FOnNotification;
 ymUpdate:=YmliteUpdate;
// Self.Resume:=Resumable;
 Port:=Sport;
 Url:=SUrl;
 LocalF:=SLocalF;
 Offset:=SOffset;
 Obj:=SObj;
 Form1.Panel3.Visible:=True;
 Self.FreeOnTerminate:=True;; 
 Inherited Create(False);
end;

procedure TFileDownload.Go;
begin
 FPause:=False;
End;

procedure TFileDownload.Pause;
begin
 FPause:=True;
end;


{procedure TFileDownload.Execute;
Var
 FPath,Ext,Tmp,Url2,Serv,ProxyPort,Un,HttpStr,S: String;
 ABW,TargetFS,N2,R,N,BW,P,Step,Bs: Integer;
 TCL,TL,SP,FilePos,ContentLength: Longint;
 Buff: Array[0..12024] of char;
 Buff2: String;
 F: File;
 Kp: String;
 Started,Continue,DataAvail: Boolean;
 Br: Longint;
 Cancel: Boolean;
Begin
 Started:=False;
 Cancel:=False;

 If DirectoryExists(Path+'downloads')=False Then
   CreateDir(Path+'downloads');

 If Assigned(Obj)=True Then
   Begin
     Obj.spSkinGauge1.Value:=0;
     Obj.spSkinEdit1.Text:=Url;
   End;

  N:=Form1.LastCharPos(Url,'.');
  Ext:=Copy(Url,N,Length(Url)-N+1);
  Url2:=Trim(URl);
  Url:=Form1.GetURL(Url,False);
  If Length(Url)>1 Then
   If (Url[Length(Url)]<>'/')  Then
     Url:=Url+'/';
  If Trim(Url)='' Then
     Exit;

   If Copy(LowerCaseRep(Url),1,7)='http://' Then
    Begin
      Delete(Url,1,7);
      Serv:=Copy(Url,1,PosRep('/',Url)-1)
    End
     else
    Begin
      Serv:=Copy(Url,1,PosRep('/',Url)-1)
    end;
   Delete(Url,1,PosRep('/',Url)-1);
   If Length(URL)>1 Then
    If Url[Length(Url)]='/' Then
      Delete(Url,Length(Url),1);

   If LocalF='' Then
    Begin
     For N:=1 to Length(Url) Do
       If Url[N]='/' Then
         R:=N;
      Tmp:=Url;
      Delete(Tmp,1,R);
      //LocalF:=Form4.Edit1.Text+'\'+ExtractFileName(LocalFileName);
      LocalF:=Path+'Downloads'+'\'+Tmp;
      If ExeOnFinish=True Then
        LocalF:=Path+Tmp;
    End;

    If Trim(LocalF)='' Then Exit;
    If Trim(Serv)='' Then Exit;

 If (Assigned(Obj)=True) And (Self.Terminated=False) Then
  Obj.Timer1.Enabled:=True;

  If Resume=True Then
   Begin
   System.Assign(F,LocalF+'.yml');
   If FileExists(LocalF+'.yml')=True Then
    Begin
     System.Reset(F,1);
     FilePos:=FileSize(F);
     Seek(F,FilePos);
     Offset:=FilePos;
     Tl:=0;
     TCl:=FilePos;
     If YmUpdate=True Then
      Form1.Panel10.Caption:='Resuming Y!mLite Download';
     If Assigned(Obj)=True Then
       Obj.spSkinEdit2.Text:='Resuming Download For '+LocalF;
     End
   else
    Begin
     Tl:=0;
     System.Rewrite(F,1);
     If YmUpdate=True Then
       Form1.Panel10.Caption:='Starting Y!mLite Download';
     If Assigned(Obj)=True Then
       Obj.spSkinEdit2.Text:='Starting Download For '+LocalF;
//   Form1.Panel10.Caption:='Starting Download For '+LocalF;
    End;
  End;

   If Resume=False Then
   Begin
     Tl:=0;
     System.Assign(F,LocalF+'.yml');
     System.Rewrite(F,1);
     If YmUpdate=True Then
       Form1.Panel10.Caption:='Starting Y!mLite Download';
     If Assigned(Obj)=True Then
       Obj.spSkinEdit2.Text:='Starting Download For '+LocalF;
//   Form1.Panel10.Caption:='Starting Download For '+LocalF;
   End;

 //Accept-Encoding:gzip,deflate..Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7



 If Resume=True Then
   HttpStr:='GET '+URL+' HTTP/1.0'+CrLf+'Host: '+Serv+CrLf+'Connection: Close'+CrLF+'Cache-Control: no-cache'+CrLf+'Range: bytes='+IntToStr(Offset)+'-'+CrLf+'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4'+CrLf+'Accept: application/x-shockwave-flash,text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*'+CrLf+Crlf
    else
   HttpStr:='GET '+URL+' HTTP/1.0'+CrLf+'Host: '+Serv+CrLf+'Connection: Close'+CrLF+'Cache-Control: no-cache'+CrLf+'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4'+CrLf+'Accept: application/x-shockwave-flash,text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*'+CrLf+Crlf;

//    HttpStr:='GET '+URL+' HTTP/1.0'+CrLf+'Host: '+Serv+CrLf+'Connection: Close'+CrLF+'Cache-Control: no-cache'+CrLf+'Range: bytes='+IntToStr(Offset)+'-'+CrLf+'If-Range: "3640a2-20b1e6-4560a260"'+CrLf+'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4'+CrLf+'Accept: application/x-shockwave-flash,text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*'+CrLf+Crlf;

//  GET /ymlite/ymlitefull.exe HTTP/1.1..Host: www.ymlitechat.com..User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4..Accept: application/x-shockwave-flash,text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5..Accept-Language: en-us,en;q=0.5..Accept-Encoding: gzip,deflate..Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7..Keep-Alive: 300..Connection: keep-alive..Range: bytes=32248-..If-Range: "3640a2-20b1e6-4560a260".............
//  HTTP/1.1..Host: www.ymlitechat.com..User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.8) Gecko/20050511 Firefox/1.0.4..Accept: application/x-shockwave-flash,text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5..Accept-Language: en-us,en;q=0.5..Accept-Encoding: gzip,deflate..Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7..Keep-Alive: 300..Connection: keep-alive..Range: bytes=32248-
//  HttpStr:='GET '+URL+' HTTP/1.0'+#$0D+#$0A+'Host: '+Serv+CrLf+'Accept-Language: en..Accept: */*'+CrLf+'User-Agent: Mozilla/4.0 [en] (Y!mLite) '+CrLf+'Cache-Control: no-cache'+CrLf+CrLf;

  Sock:=TDCBSock.Create(nil);
  Sock.BlockMode:=BmBlocking;
  Sock.RemoteHost:=Serv;
  Sock.RemotePort:=Port;
  Sock.Connect;
  Sleep(40);
  If Sock.Connected=True Then
  Begin
   //
    Sock.Sendln(HttpStr);
    Sock.WaitForData(2000);
    Bs:=Sock.PeekBuf(Buff,SizeOf(Buff));
    SetLength(Buff2,Bs);
    Sock.ReceiveBuf(Buff2[1],bS);
   If (Copy(Buff2,1,12)='HTTP/1.1 206') Or (Copy(Buff2,1,12)='HTTP/1.1 200') or (Copy(Buff2,1,12)='HTTP/1.0 206') Or (Copy(Buff2,1,12)='HTTP/1.0 200') Then
     Begin
      If (Copy(Buff2,1,12)='HTTP/1.1 200') or (Copy(Buff2,1,12)='HTTP/1.0 200') Then
       Begin
        Tcl:=0;
        System.Rewrite(F,1);
       End;
      Delete(Buff2,1,PosRep('Content-Length:',Buff2)+15);
      ContentLength:=StrToInt(Copy(Buff2,1,PosRep(#$0d+#$0a,Buff2)-1));
      Delete(Buff2,1,PosRep(Crlf+CrLf,buff2)+3);
      BlockWrite(F,Buff2[1],Length(Buff2),ABW);
      Inc(TL,Length(Buff2));
       If (Assigned(Obj)=True) And (Self.Terminated=False) Then
        Begin
         Obj.spSkinGauge1.Value:=0;
         Obj.spSkinGauge1.MaxValue:=(TCL+ContentLength) Div 1024;
         Obj.spSkinGauge1.MinValue:=1;
         Obj.spSkinEdit2.Text:='Downloaded '+IntTOStr(TCL+Tl)+' / '+IntToStr(TCL+ContentLength);
        End;
        //writeout ot file
     End
      Else
      Begin
       //maybe file does not exist!
      If (Assigned(Obj)=True) And (Self.Terminated=False) Then
        Begin
         Obj.spSkinEdit2.Text:=Copy(Buff2,1,PosRep(CrLf,Buff2)-1);
         Obj.spSkinButton2.Caption:='Close';
        End;
       CloseFile(F);
       DeleteFile(LocalF+'.yml');
       Exit;
      End;

   While (Sock.WaitForData(2000)=True) and (Sock.Connected=True) And (Exiting=False) And (Cancel=False) And (Terminated=False)  Do
     Begin
      While (FPause=True) and (Self.Terminated=False) and Assigned(Obj)=True Do
        Sleep(1);
       If Started=False Then
        Begin
         If Assigned(Obj)=True Then
            Obj.FileTCount:=1;
          Started:=True;
        End;
      Bs:=Sock.PeekBuf(Buff,SizeOf(Buff));
      Sock.ReceiveBuf(Buff,bS);
      BlockWrite(F,Buff,Bs,ABW);
      Inc(TL,Bs);

     If (Assigned(Obj)=True) And (Self.Terminated=False) Then
       Begin
        Kp:=FloatToStr((Tl/Obj.FileTCount)/1024);
        Form1.MaxDownloadSpeed:=(Tl/Obj.FileTCount)/1024;
        Kp:=Copy(Kp,1,PosRep('.',Kp)+2);
        Obj.spSkinEdit2.Text:='Downloaded '+IntTOStr((TCL+Tl) Div 1024)+'K / '+IntToStr((TCL+ContentLength) div 1024)+'K';
        Obj.SpSkinEdit3.Text:=Kp+'K/s ';
        Obj.spSkinGauge1.Value:=(TCL+Tl) Div 1024;
       End;

      If YmUpdate=True Then
       Form1.Panel10.Caption:='Downloaded '+IntTOStr((TCL+Tl) Div 1024)+'K / '+IntToStr((TCL+ContentLength) div 1024)+'K of the Y!mLite Update.'
        else
       Form1.Panel10.Caption:='Downloaded '+IntTOStr((TCL+Tl) Div 1024)+'K / '+IntToStr((TCL+ContentLength) div 1024)+'K of '+LocalF+'.';
     End;
   //finish reading data
   System.Close(F);
   If TL=ContentLength Then
    Begin
     If FileExists(LocalF)=True Then
      DeleteFile(LocalF);
     RenameFile(LocalF+'.yml',LocalF);
     If (Assigned(Obj)=True) And (Self.Terminated=False) Then
      Begin
       Obj.spSkinEdit2.Text:=LocalF+' Succesfully Downloaded!';
       Obj.spSkinButton1.Enabled:=True;
       Obj.FileName:=LocalF;
       Obj.spSkinButton2.Caption:='Close';
      End;
    If YmUpdate=True Then
       SendMessage(Form1.Handle,Wm_User+113,Integer(Self),99);
    If ExeOnFinish=True Then
     If Pos('.exe',LowerCaseRep(LocalF))>0 Then
        Form1.ShellExecute(Form1.Handle,'open',Pchar(LocalF),Nil,Nil,sw_show);
    If OnNotification=True Then
     Begin
      Form1.NotificationStr:=ExtractFileName(LocalF);
      Form1.FullNotificationStr:=LocalF;      
      SendMessage(Form1.Handle,Wm_User+114,0,0);
     End;
    End;
    //
  End
else
  Begin
    If (Assigned(Obj)=True) And (Self.Terminated=False) Then
     Begin
      Obj.spSkinEdit2.Text:='Server Not Found!';
      Obj.spSkinButton2.Caption:='Close';
     End;
     System.Close(F);
  End;
End;}


procedure TFileDownload.Execute;
Var
 FPath,Ext,Tmp,Url2,Serv,ProxyPort,Un,HttpStr,S: String;
 ABW,TargetFS,N2,R,N,BW,P,Step,Bs: Integer;
 TCL,TL,SP,FilePos,ContentLength: Longint;
 Buff: Array[0..12024] of char;
 Buff2: String;
 F: TMemoryStream;
 Kp: String;
 Started,Continue,DataAvail: Boolean;
 Br: Longint;
 Cancel: Boolean;
Begin
 Started:=False;
 Cancel:=False;

 If DirectoryExists(Path+'downloads')=False Then
   CreateDir(Path+'downloads');

 If Assigned(Obj)=True Then
   Begin
     Obj.spSkinGauge1.Value:=0;
     Obj.spSkinEdit1.Text:=Url;
   End;

  N:=Form1.LastCharPos(Url,'.');
  Ext:=Copy(Url,N,Length(Url)-N+1);
  Url2:=Trim(URl);
  Url:=Form1.GetURL(Url,False);
  If Length(Url)>1 Then
   If (Url[Length(Url)]<>'/')  Then
     Url:=Url+'/';
  If Trim(Url)='' Then
     Exit;

   If Copy(LowerCaseRep(Url),1,7)='http://' Then
    Begin
      Delete(Url,1,7);
      Serv:=Copy(Url,1,PosRep('/',Url)-1)
    End
     else
    Begin
      Serv:=Copy(Url,1,PosRep('/',Url)-1)
    end;
   Delete(Url,1,PosRep('/',Url)-1);
   If Length(URL)>1 Then
    If Url[Length(Url)]='/' Then
      Delete(Url,Length(Url),1);

    If LocalF='' Then
    Begin
     For N:=1 to Length(Url) Do
       If Url[N]='/' Then
         R:=N;
      Tmp:=Url;
      Delete(Tmp,1,R);
      //LocalF:=Form4.Edit1.Text+'\'+ExtractFileName(LocalFileName);
      LocalF:=Path+'Downloads'+'\'+Tmp;
      If ExeOnFinish=True Then
        LocalF:=Path+Tmp;
    End;

    If Trim(LocalF)='' Then Exit;
    If Trim(Serv)='' Then Exit;

 If (Assigned(Obj)=True) And (Self.Terminated=False) Then
  Obj.Timer1.Enabled:=True;

     Tl:=0;
//     F:=TFileStream.Create(LocalF+'.yml',fmCreate);
       F:=TMemoryStream.Create;
 //    F.Seek(0,soFromBeginning);
//     System.Rewrite(F,1);
     If YmUpdate=True Then
       Form1.Panel10.Caption:='Starting Y!mLite Download';
     If Assigned(Obj)=True Then
       Obj.spSkinEdit2.Text:='Starting Download For '+LocalF;
//   Form1.Panel10.Caption:='Starting Download For '+LocalF;

     Tl:=0;
  //   If FileExists(LocalF+'.yml') Then
//       F:=TFileStream.Create(LocalF+'.yml',fmCreate);
       F:=TMemoryStream.Create;
//     F.Seek(0,soFromBeginning);
//     System.Assign(F,LocalF+'.yml');
//     System.Rewrite(F,1);
     If YmUpdate=True Then
       Form1.Panel10.Caption:='Starting Y!mLite Download';
     If Assigned(Obj)=True Then
       Obj.spSkinEdit2.Text:='Starting Download For '+LocalF;

  HttpStr:='GET '+URL+' HTTP/1.0'+CrLf+'Host: '+Serv+CrLf+'Connection: Close'+CrLF+'Cache-Control: no-cache'+CrLf+'Accept: application/x-shockwave-flash,text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*'+CrLf+Crlf;

  Sock:=TDCBSock.Create(nil);
  Sock.BlockMode:=BmBlocking;
  Sock.RemoteHost:=Serv;
  Sock.RemotePort:=Port;
  Sock.Connect;
  Sleep(40);
  If Sock.Connected=True Then
  Begin
   //
    Sock.Sendln(HttpStr);
    Sock.WaitForData(2000);
    Bs:=Sock.PeekBuf(Buff,SizeOf(Buff));
    SetLength(Buff2,Bs);
    Sock.ReceiveBuf(Buff2[1],bS);
    //Buff2:='HTTP/1.1 200 OK'+#$0D+#$0A+'Server: Microsoft-IIS/5.0'+#$0D+#$0A+'X-Powered-By: ASP.NET'+#$0D+#$0A+'MicrosoftOfficeWebServer: 5.0_Pub'+#$0D+#$0A+'Date: Fri, 07 Sep 2007 04:19:43 GMT'+#$0D+#$0A+'Content-Type: application/octet-stream'+#$0D+#$0A+'Accept-Ranges: bytes'+#$0D+#$0A+'Last-Modified: Fri, 07 Sep 2007 02:58:48 GMT'+#$0D+#$0A+'ETag: "472f663fbf0c71:bc27"'+#$0D+#$0A+'Content-length: 974336'+#$0D+#$0A+'Connection: close'+#$0D+#$0A+'Age: 0'+#$0D+#$0A+#$0D+#$0A+'MZP'+#$00+#$02+#$00+#$00+#$00+#$04+#$00+#$0F+#$00+#$FF+#$FF+#$00+#$00+#$B8+#$00+#$00+#$00+#$00+#$00+#$00;
   If (Copy(Buff2,1,12)='HTTP/1.1 206') Or (Copy(Buff2,1,12)='HTTP/1.1 200') or (Copy(Buff2,1,12)='HTTP/1.0 206') Or (Copy(Buff2,1,12)='HTTP/1.0 200') Then
     Begin
      If (Copy(Buff2,1,12)='HTTP/1.1 200') or (Copy(Buff2,1,12)='HTTP/1.0 200') Then
       Begin
        Tcl:=0;
        F.Seek(0,soFromBeginning);
//        System.Rewrite(F,1);
       End;                         //Content-Length:
                                    //Content-length:
     If PosRep('Content-length:',Buff2)>0 Then
        Delete(Buff2,1,Pos(#$0D+#$0A+'Content-length:',Buff2)+17)
         else
        Delete(Buff2,1,Pos(#$0D+#$0A+'Content-Length:',Buff2)+17);
     ContentLength:=StrToInt(Copy(Buff2,1,PosRep(#$0d+#$0a,Buff2)-1));
     Delete(Buff2,1,PosRep(Crlf+CrLf,buff2)+3);
    //  BlockWrite(F,Buff2[1],Length(Buff2),ABW);
      F.WriteBuffer(Buff2[1],Length(Buff2));
      Inc(TL,Length(Buff2));
       If (Assigned(Obj)=True) And (Self.Terminated=False) Then
        Begin
         Obj.spSkinGauge1.Value:=0;
         Obj.spSkinGauge1.MaxValue:=(TCL+ContentLength) Div 1024;
         Obj.spSkinGauge1.MinValue:=1;
         Obj.spSkinEdit2.Text:='Downloaded '+IntTOStr(TCL+Tl)+' / '+IntToStr(TCL+ContentLength);
        End;
        //writeout ot file
     End
      Else
      Begin
       //maybe file does not exist!
      If (Assigned(Obj)=True) And (Self.Terminated=False) Then
        Begin
         Obj.spSkinEdit2.Text:=Copy(Buff2,1,PosRep(CrLf,Buff2)-1);
         Obj.spSkinButton2.Caption:='Close';
        End;
//       CloseFile(F);
       F.SaveToFile(LocalF+'.yml');
       F.Free;
       DeleteFile(LocalF+'.yml');
       Exit;
      End;

   While (Sock.WaitForData(2000)=True) and (Sock.Connected=True) And (Exiting=False) And (Cancel=False) And (Terminated=False)  Do
     Begin
      While (FPause=True) and (Self.Terminated=False) and Assigned(Obj)=True Do
        Sleep(1);
       If Started=False Then
        Begin
         If Assigned(Obj)=True Then
            Obj.FileTCount:=1;
          Started:=True;
        End;
    //  Bs:=Sock.PeekBuf(Buff,SizeOf(Buff));
      Bs:=Sock.ReceiveBuf(Buff,SizeOf(Buff));
      F.WriteBuffer(Buff,bs);
//      BlockWrite(F,Buff,Bs,ABW);
      Inc(TL,Bs);

     If (Assigned(Obj)=True) And (Self.Terminated=False) Then
       Begin
        Kp:=FloatToStr((Tl/Obj.FileTCount)/1024);
        Form1.MaxDownloadSpeed:=(Tl/Obj.FileTCount)/1024;
        Kp:=Copy(Kp,1,PosRep('.',Kp)+2);
        Obj.spSkinEdit2.Text:='Downloaded '+IntTOStr((TCL+Tl) Div 1024)+'K / '+IntToStr((TCL+ContentLength) div 1024)+'K';
        Obj.SpSkinEdit3.Text:=Kp+'K/s ';
        Obj.spSkinGauge1.Value:=(TCL+Tl) Div 1024;
       End;

      If YmUpdate=True Then
       Form1.Panel10.Caption:='Downloaded '+IntTOStr((TCL+Tl) Div 1024)+'K / '+IntToStr((TCL+ContentLength) div 1024)+'K of the Y!mLite Update.'
        else
       Form1.Panel10.Caption:='Downloaded '+IntTOStr((TCL+Tl) Div 1024)+'K / '+IntToStr((TCL+ContentLength) div 1024)+'K of '+LocalF+'.';
     End;
   //finish reading data
//   System.Close(F);
     F.SaveToFile(LocalF+'.yml');
   F.free;
   If TL=ContentLength Then
    Begin
     If FileExists(LocalF)=True Then
      DeleteFile(LocalF);
     RenameFile(LocalF+'.yml',LocalF);
     If (Assigned(Obj)=True) And (Self.Terminated=False) Then
      Begin
       Obj.spSkinEdit2.Text:=LocalF+' Succesfully Downloaded!';
       Obj.spSkinButton1.Enabled:=True;
       Obj.FileName:=LocalF;
       Obj.spSkinButton2.Caption:='Close';
      End;
    If YmUpdate=True Then
       SendMessage(Form1.Handle,Wm_User+113,Integer(Self),99);
    If ExeOnFinish=True Then
     If Pos('.exe',LowerCaseRep(LocalF))>0 Then
        Form1.ShellExecute(Form1.Handle,'open',Pchar(LocalF),Nil,Nil,sw_show);
    If OnNotification=True Then
     Begin
      Form1.NotificationStr:=ExtractFileName(LocalF);
      Form1.FullNotificationStr:=LocalF;      
      SendMessage(Form1.Handle,Wm_User+114,0,0);
     End;
    End;
    //
  End
else
  Begin
    If (Assigned(Obj)=True) And (Self.Terminated=False) Then
     Begin
      Obj.spSkinEdit2.Text:='Server Not Found!';
      Obj.spSkinButton2.Caption:='Close';
     End;
     F.Free;
  End;
End;


procedure TForm1.HTTPFileDownloader1Click(Sender: TObject);
begin
 HttpFileDownloader1.Checked:=Not HttpFileDownloader1.Checked;
end;

procedure TForm1.FreeWindowProc(var Msg: Tmessage);
Var
 Obj: TForm39;
begin
If Msg.LParam=99 Then
 Begin
  Obj:=TForm39(Msg.Wparam);
  DeleteSkin(Obj);
  DeleteFileDownloader(Obj);
  Obj:=Nil;
 End;
end;

procedure TForm1.FinishedUpdating(var Msg: Tmessage);
Var
 Obj: TComponent;
begin
If Msg.LParam=99 Then
 Begin
  GUpdate:=True;
  Form1.Close;
 End;
end;

procedure TForm1.Copy4Click(Sender: TObject);
begin
  Richedit2.CopyToClipboard;
end;

procedure TForm1.Paste2Click(Sender: TObject);
begin
 Richedit2.PasteFromClipboard;
end;

procedure TForm1.ViewIdentitars1Click(Sender: TObject);
begin
 Form1.CreateSkin(Form47);
 If Form47.ListBox1.Items.Text='' Then
   Form47.Button1.Click;
 Form47.Show;
end;

procedure TForm1.UploadIdentitar1Click(Sender: TObject);
begin
 ShellExecute(Form1.Handle,'open','http://ymlitechat.com/idents/upload.php',Nil,'',SW_Show);
end;


procedure TForm1.ViewLastPacket1Click(Sender: TObject);
Var
 ToUser: String;
begin
 touser:=L1WhoisSelected;
 Form1.CreateSkin(Form3);
 Form3.Visible:=True;
 Form3.BringToFront;
 Form3.DebugUser:=ToUser;
 TDebugDisplay.Create(Chatters[Form1.ChatterNum(ToUser)].DebugStr,1);
end;

procedure TForm1.ViewLastPacket2Click(Sender: TObject);
Var
 ToUser: String;
begin
 Touser:=WordStr2;;
 Form1.CreateSkin(Form3);
 Form3.Visible:=True;
 Form3.BringToFront;
 Form3.DebugUser:=ToUser;
 TDebugDisplay.Create(Chatters[Form1.ChatterNum(ToUser)].DebugStr,1);
end;

procedure TForm1.DropMailMessage3Click(Sender: TObject);
begin
end;

{Function IESpamWindow(Sender: TObject;
  const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
  Headers: OleVariant; var Cancel: WordBool): IWebBrowser2;
Begin
  IESpamWindow := CreateOleObject('InternetExplorer.Application') as IWebBrowser2;
  IESpamWindow.Left := 100;
  IESpamWindow.Top := 100;
  IESpamWindow.Width := 640;
  IESpamWindow.Height := 500;
  IESpamWindow.MenuBar := True;
  IESpamWindow.AddressBar := True;
  IESpamWindow.Resizable := True;
  IESpamWindow.StatusBar := True;
  IESpamWindow.ToolBar := 1;
  IESpamWindow.Navigate2(Url,Flags,TargetFrameName,PostData,Headers);
  IESpamWindow.Visible := true;
End;

Procedure TestSpam;
  Var
   IE2: IWebBrowser2;
Begin
//   Ie2:=IESpamWindow(nil,PDisp,URL,Flags,TargetFrameName,PostData,Headers,Cancel);
   Form1.Delay(3000);
   Ie2.Quit;
End;}

{procedure TForm1.WebBrowser1BeforeNavigate2(Sender: TObject;
  const pDisp: IDispatch; var URL, Flags, TargetFrameName, PostData,
  Headers: OleVariant; var Cancel: WordBool);
begin
//  Form1.Richedit1.Lines.Add(Headers);
  If (PosRep('iclk?',Url)>0) And (SecondsBetween(Now,LastClick)>30) Then
    Begin
     If NClickCount<3 Then
      Begin
       Inc(TClickCount);
       Inc(NClickCount);
       SpSkinLabel2.Caption:='Total Clicks: '+IntToStr(TClickCount)+'/100';
       LastClick:=Now;
       WebBrowser1.Enabled:=False;
      End
       Else
      Cancel:=True;
    End;
  //http://pagead2.googlesyndication.com/pagead/iclk?
//  Cancel:=True;
end;

procedure TForm1.WebBrowser1NavigateComplete2(Sender: TObject;
  const pDisp: IDispatch; var URL: OleVariant);
begin
//Form1.Richedit1.Lines.Add(URL);
 WebBrowser1.enabled:=True;
end;}

procedure TForm1.YmLiteAdPerkTheirInterest1Click(Sender: TObject);
begin
 If Form1.spSkinCheckRadioBox1.Checked=True Then
 Begin
 Form1.spSkinCheckRadioBox1.Checked:=False;
 Say(Form1.Richedit1,YnoI+YGreen+YBold+'Want '+yNoI+yred+'sexy'+ynoi+ygreen+' chat? ;) Click the link '+YItalic+YRed+' http://ymlitechat.com',False,False,False);
   Form1.spSkinCheckRadioBox1.Checked:=True;
 End
  else
 Say(Form1.Richedit1,YnoI+YGreen+YBold+'Want '+yNoI+yred+'sexy'+ynoi+ygreen+' chat? ;) Click the link '+YItalic+YRed+' http://ymlitechat.com',False,False,False);
end;

procedure TForm1.spSkinExPanel1ChangeRollState(Sender: TObject);
begin
 //Form1.spSkinScrollPanel1.Repaint;
//  SpSkinExPanel1.Repaint;
 If SpSkinExPanel1.RollState=True Then
   SpSkinExPanel1.Align:=alBottom
    else
   SpSkinExPanel1.Align:=alClient;

end;

procedure TForm1.spSkinExPanel4ChangeRollState(Sender: TObject);
Begin
 If SpSkinExPanel4.RollState=False Then
  Form1.ListBox3.Items.Text:=form18.ListBox1.Items.Text;
end;

procedure TForm1.ListBox3DblClick(Sender: TObject);
Var
 strtofnme,endofname,R2,R,N: Integer;
 UserName,TmpFstr,Part1,Part2: String;
begin
R:=-1;
R2:=-1;
 For N:=ListBox3.Items.Count-1 Downto 0 do
  If ListBox3.Selected[N]=True Then
    R:=N;
 For N:=ListBox1.Items.Count-1 Downto 0 do
  If ListBox1.Selected[N]=True Then
    R2:=N;

  If (R<>-1) and (R2<>-1) Then
   Begin
       TmpFstr:=ListBox3.Items[R];
       UserName:=ListBox1.Items[R2];
   //    part1:=copy(tmpfstr,1,strtofnme-1);
   //    part2:=copy(tmpfstr,endofname+1,length(tmpfstr)-endofname+1);
//       tmpfstr:=part1+Yred+UserName+Yblue+part2;
       TmpFstr:=Form1.MakeEmote(TmpFstr,UserName);
       Form1.Say(Form1.Richedit1,TmpFstr,False,True,False);
    End
     else
    Begin
      TmpFstr:=ListBox3.Items[R];
      Form1.Say(Form1.Richedit1,TmpFstr,False,True,False);
    End;
end;

procedure TForm1.MenuBar1Click(Sender: TObject);
begin
 If (SpSkinControlBar2.Visible=False) And (MenuBar1.Checked=True) Then
   MenuBar1.Checked:=False;
 MenuBar1.Checked:=Not MenuBar1.Checked;
 SpSkinControlBar2.Visible:=MenuBar1.Checked;
// Form1.CreateSkin(Form50);
// Form50.Show;
end;

procedure TForm1.spSkinXFormButton2Click(Sender: TObject);
begin

end;

{ TYahooNews }

constructor TYahooNews.Create();
begin
 FreeOnTerminate:=True;
 Inherited Create(False);
end;

procedure TYahooNews.Execute;
Var
 S: String;
 N,Br: Integer;
begin
 Data:='';
 Socket:=TDCBSock.Create(Nil);
 Socket.BlockMode:=BmBlocking;
 Socket.RemoteHost:='ymlitechat.com';
 Socket.RemotePort:='80';
// '+CrLF+'
 //GET /search?q=search+engine&ie=ISO-8859-1&hl=en&meta= HTTP/1.1..Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/vnd.ms-excel, application/msword, */*..Referer: http://www.google.com.au/..Accept-Language: en-au..Accept-Encoding: gzip, deflate..User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)..Host: www.google.com.au..Connection: Close..Cookie: PREF=ID=12cb036939e5efa1:LD=en:TM=1040212520:LM=1040212520:S=SllEKRos_vXCwr0G....
// HttpStr:='GET /search?q='+SearchStr+'&ie=ISO-8859-1&hl=en&meta= HTTP/1.0'+CrLf+'Accept: */*'+CrLF+CrLF;           //+CrLf+'Content-Type: application/x-www-form-urlencodedAccept-Encoding: gzip, deflate'+CrLf+'User-Agent: Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)'+CrLf+Socket.RemoteHost+CrLf+'Connection: Close'+CrLf+'Cache-Control: no-cache'+CrLf+CrLf;
 HttpStr:='GET /ymlite/news.txt HTTP/1.1'+CrLf+'Accept: */*'+CrLf+'Accept-Language: en-us'+CrLf+'Host: www.ymlitechat.com'+CrLf+'Connection: close'+CrLf+CrLf;
 Socket.Connect;
 Sleep(40);
 If Socket.Connected=True Then
  Try
    Socket.Sendln(HttpStr);
    Data:='';
     While (Socket.WaitForData(10000)) And (Exiting=False) Do
      Begin
        S:=Socket.Receiveln;
        BR:=Socket.BytesReceived;
        Data:=Data+S;
//        Form1.Panel10.Caption:='Connected reading data in... '+IntToStr(Length(Data))+' Bytes... ';
   //     Application.ProcessMessages;
       End;
    If Exiting=True Then Exit;
    Delete(Data,1,PosRep(CrLf+CrLf,Data)+3);
    Form1.Richedit1.SelAttributes.Color:=ClRed;
    Form1.Richedit1.Lines.Add('');
    Form1.Richedit1.SelText:='***Yahoo News Latest Issues... - ';
    Form1.Richedit1.SelAttributes.Color:=ClBlue;
    Form1.Richedit1.SelText:=Data;
    Form1.Richedit1.SelAttributes.Color:=ClBlack;
    Form1.Richedit1.Lines.Add('');    
   Except
    Socket.Disconnect;
   End;
 Socket.Free;
end;



function TForm1.RemoveStrv(WithStr, S: String): String;
begin

end;

procedure TForm1.YmLiteInChatSupport1Click(Sender: TObject);
begin

end;

{ TBadEnglish }

Function TBadEnglish.JumbleChars(S: String): String;
Var
 Jc,R,N: Integer;
 Tmp2: String;
 TmpC: Char;
Begin

 If (Length(S)>=8) And (Length(S)<30) Then
   JC:=4;

 If (Length(S)>=5) And (Length(S)<8) Then
   JC:=3;

 If Length(S)<=3 Then
   Jc:=1;

 For N:=1 to Jc Do
   Begin
    R:=Random(Length(S)-1)+1;
    TmpC:=S[R];
    S[R]:=S[R+1];
    S[R+1]:=TmpC;
   End;
 Result:=S;
End;

function TBadEnglish.TextToBadEnglish(S: String): String;
Var
  N2,Wc,N: Integer;
  Jchars,Tmp: String;
Begin
 WC:=0;
 Words.Clear;
 SplitWords(S);
 Randomize;

  For N:=0 to Words.Count-1 Do
  Begin
   JChars:='';
   Tmp:=Words[N];
   If Length(Tmp)>=4 Then
     Begin
       For N2:=2 to Length(Tmp)-1 Do
        JChars:=JChars+Tmp[N2];
       Delete(Tmp,2,Length(Tmp)-2);
       JChars:=JumbleChars(Jchars);
       Insert(Jchars,Tmp,2);
       Words[N]:=Tmp;
     End;
  End;


 For N:=0 to Words.Count-1 do
   Result:=Result+Words[N]+' ';
end;

procedure TForm1.BadEnglishGenerator1Click(Sender: TObject);
begin
 BadEnglishGenerator1.Checked:=Not BadEnglishGenerator1.Checked;
end;


{ TUserFields }

constructor TUserFields.Create;
begin
  Fields:=TStringList.Create;
end;

destructor TUserFields.Destroy;
begin
  Fields.Free;
  Inherited;
end;

function TUserFields.GetField(S: String): String;
Var
 N: Integer;
 Tmp: String;
begin
  For N:=Fields.Count-1 Downto 0 do
   Begin
     Tmp:=Fields[N];
     If Copy(Tmp,1,PosRep(',',Tmp)-1)=S Then
      Begin
       Delete(Tmp,1,PosRep(',',Tmp));
       Result:=Tmp;
       Fields.Delete(N);
       Break;
      End;
   End;
end;

procedure TUserFields.SplitFields(S: String);
Var
 Code,Tmp2: String;
Begin
 Tmp2:=S;
 While Form1.ScanIt(Delim,Tmp2)>0 do
  Begin
   If Copy(Tmp2,1,3)=Copy(Tmp2,4,3) Then
     Delete(Tmp2,1,3);
   Tmp2:=CutToDelimiterSprt(Tmp2,1);
   Code:=toDelimiterSprt(Tmp2);
   Tmp2:=CutToDelimiterSprt(Tmp2,1);
   If PosRep(Delim,Tmp2)>0 Then
      Fields.Add(Code+','+ToDelimiterSprt(Tmp2))
       else
      Fields.Add(Code+','+Tmp2);
  End;
end;


{ TUserFields2 }

constructor TUserFields2.Create;
begin
  Fields:=TStringList.Create;
end;

destructor TUserFields2.Destroy;
begin
  Fields.Free;
  Inherited;
end;

function TUserFields2.GetField(S: String): String;
Var
 N: Integer;
 Tmp: String;
begin
  For N:=0 to Fields.Count-1  do
   Begin
     Tmp:=Fields[N];
     If Copy(Tmp,1,PosRep(',',Tmp)-1)=S Then
      Begin
       Delete(Tmp,1,PosRep(',',Tmp));
       Result:=Tmp;
       Fields.Delete(N);
       Break;
      End;
   End;
end;

{
Function Tform1.ExtractPacketDetails(S,PacketT: String): String;
Var
 PacketStr,Code,Tmp2: String;
 P1: Integer;
Begin
 Tmp2:=S;
 Result:='';
 PacketStr:=Co80s+PacketT;
 P1:=PosRep(PacketStr,Tmp2);
 If P1=0 Then
   Exit;
 Delete(Tmp2,1,P1+Length(PacketStr)+1);
 If PosRep(co80s,Tmp2)>0 Then
   Result:=Form1.ToC080(Tmp2)
    else
   Result:=Tmp2;
End;   
   function ToC080(S: String): String;
     function CutC080(S: String; N: Integer): String;
}

procedure TUserFields2.SplitFields(S: String);
Var
 Code,Tmp2: String;
Begin
 Tmp2:=S;
 While Form1.ScanIt(CO80S,Tmp2)>0 do
  Begin
   Code:=Form1.ToC080(Tmp2);
   Tmp2:=Form1.CutC080(Tmp2,1);
   If PosRep(CO80S,Tmp2)>0 Then
      Fields.Add(Code+','+Form1.ToC080(Tmp2))
       else
      Fields.Add(Code+','+Tmp2);
   Tmp2:=Form1.CutC080(Tmp2,1);
  End;
end;


Function TForm1.RawVoiceConnect(User:String; Room: String; RoomSpace: String; VoiceToken: string):string;
 Var
   Packet: Array[1..2]of String;
   Reaper: String;
begin
 Reaper:= #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0+ #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0;
 Packet[1]:= #$0 + #$0 + 'É' + #$0 + '0' + Reaper + '€Ì';
 Packet[2]:= #$0 + #$0 + #$0 + #$0 + 'CA!Y' + #$0 + #$01 + #$0 + #$0 + #$0 + #$0 + #$0 + #$01 + 'd' + #$02 + #$0 + #$02 + 'e' + #$02 + #$0 + #$05;
 Packet[2]:= Packet[2] + #$02 + chr(length(User)) + User + #$03 + chr(length(('ch/' + Room + '::' + Roomspace))) + 'ch/' + Room + '::' + Roomspace;
 Packet[2]:= Packet[2] + #$07 + chr(length(VoiceToken)) + VoiceToken + #$06 + #$0 + #$05 + #$02 + #$0 + #$19 + #$8 + #$04;
 Result:= #$0 + chr(length(Packet[1] + Packet[2])+4) + Packet[1] + #$0 + chr(Length(Packet[2])+4) + Packet[2];
End;

Function TForm1.RawAudioConnect(User:string;Buff:String; MV: Integer):String;
 Var
  Packets: Array[1..2] of string;
  Reaper,Droped: string;
begin
 Reaper:= #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0+ #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0;
 Packets[1]:= #$0 + #$0 + 'É' + #$0 + '0' + #$4 + Buff + Reaper + '€Ì';
 Packets[2]:= #$0 + #$0 + #$0 + #$0 + 'CA!Y' + #$0 + #$7 + #$0 + #$0 + #$0 + #$0 + #$0 + #$0 + #$B + Chr(length(Droped)+153) + 'exe=YPager&sig=&app=mc(6, 0, 0, 1643)&u=' + User + '&ia=us&lib=yacscom(45)&in=2,1,104,5.10,Intel(r) Integrated Audio&out=2,1,104,5.10,Intel(r) Integrated Audio.';
 Result := #$0 + chr(Length(Packets[1] + Packets[2]) + 3) + Packets[1] + #$0 + Chr(Length(Packets[2]) + 3) + Packets[2];
End;


procedure TForm1.ConvertIt1Click(Sender: TObject);
begin
 Form1.CreateSkin(Fconverter);
 Fconverter.FormStyle:=FsStayOnTop;
 Fconverter.Show;
end;

procedure TForm1.TheYmLiteFourm1Click(Sender: TObject);
begin
 ShellExecute(Handle,'OPEN',Pchar('http://www.ymlite.us'),Pchar(''),'',SW_Show);
 Form1.ReleaseMemory;
end;

procedure TForm1.Move1Click(Sender: TObject);
begin
 ReleaseCapture;
// SendMessage(Form1.Handle,WM_LBUTTONDOWN,0,0);
end;

procedure TForm1.ViewGSCams1Click(Sender: TObject);
Var
 CG,MessageStr: String;
 N: Integer;
begin
 For N:=Form1.ListBox1.Items.Count-1 Downto 0 do
   CG:=UserGender(Chatters[Form1.ChatterNum(ListBox1.Items[n])].Extra);
    If (PosRep('CamF',CG)>0) Or (CG='Female') Then
     Begin
      Form1.ViewCam(ListBox1.Items[n]);
      Delay(300);
     End;
end;

procedure TForm1.InviteBuddy1Click(Sender: TObject);
Var
 ToUser,MessageStr: String;
 N,R: Integer;
begin
   Form1.Invite(Form27.ListBox1.items[Form27.ListBox1.itemindex],False,False,False);
end;

procedure TForm1.PostLinkToFourms1Click(Sender: TObject);
begin
 If Form1.spSkinCheckRadioBox1.Checked=True Then
 Begin
 Form1.spSkinCheckRadioBox1.Checked:=False;
  Say(Form1.Richedit1,YItalic+YGreen+YBold+'Forum Help: http://www.ymlite.us for all your Y!mLite/Sparta Messenger Needs.',False,False,False);
   Form1.spSkinCheckRadioBox1.Checked:=True;
 End
  else
 Say(Form1.Richedit1,YItalic+YGreen+YBold+'Forum Help: www.ymlite.us for all your Y!mLite/Sparta Messenger Needs.',False,False,False);
end;

procedure TForm1.YTunnelIgnoreListImport1Click(Sender: TObject);
Var
 Len,Err: Integer;
 Tmp2,Tmp: String;
 F: File;
 StartT,StopT: Longint;
 Found: Boolean;
 YIgnores: TStringList;
 Username: String;
 SF: String;
Begin
Found:=False;
Form34.ListBox1.Clear;
Form1.OpenDialog1.FilterIndex:=2;
Form1.OpenDialog1.Execute;
SF:=Form1.OpenDialog1.FileName;
YIgnores:=TStringList.Create;
  If FileExists(SF) Then
   Begin
    System.Assign(F,SF);
    System.Reset(F,1);
    Startt:=GetTickCount;
    Repeat
      //ReadLn(T,Tmp);
      SetLength(Tmp,125);
      BlockRead(F,Tmp[1],6,Err);
      Len:=Ord(Tmp[6]);
      SetLength(Username,Len+1);
      BlockRead(F,Username[1],Len,Err);
      SetLength(Username,Len);
      If Trim(UserName)<>'' Then
          Form34.ListBox1.Items.Add(UserName);
      BlockRead(F,Tmp[1],8,Err);
    Until Eof(F);
    System.Close(F);
    StopT:=GetTickCount;
    ShowMessage('Loaded '+IntToStr(Form34.ListBox1.Items.Count)+' Users From Yahelite''s Ignore List Time Taken: '+FloatToStr((StopT-StartT)/1000)+' Seconds..');
    Form34.Caption:='Y!Tunnels''s Ignore List...';
    Form34.ShowModal;
    Form1.CreateSkin(Form34);
    YIgnores.Free;
    Exit;
   End
    else
      ShowMessage('Y!Tunnel Ignore List Not Detected!');
end;

{ TStartSound }

Procedure TForm1.StartSound(Fn: String; Ext,AlertSound: Boolean);
Begin
 TStartSound.Create(FN,Ext,AlertSound);
End;

constructor TStartSound.Create(FileName: String; Ext: Boolean; FAlertSound: Boolean);
begin
 FExt:=Ext;
 FreeOnTerminate:=True;
 AfileName:=FileName;
 Self.FreeOnTerminate:=True;
 AlertSound:=FAlertSound;
 Inherited Create(False);
end;

procedure TStartSound.execute;
begin
//TTTSDownload.Create('You have been disconnected','c:\waves\Female.wav',True,'Female','British');
If FExt=True Then
  SndPlaySound(Pchar(AFileName),SND_SYNC)
 Else
 Begin
   If Form1.YmLiteGeneralSounds1.Checked=True Then
      If (FileExists(Path+'sounds\'+AFileName)) And (AlertSound=False) Then
        SndPlaySound(Pchar(Path+'sounds\'+AFileName),SND_SYNC);

   If Form1.YmLiteAlertSoundsBootersetc1.Checked=True Then
      If (FileExists(Path+'sounds\'+AFileName)) And (AlertSound=True) Then
        SndPlaySound(Pchar(Path+'sounds\'+AFileName),SND_SYNC);
  End;
end;

Procedure TForm1.StartupSpellChecker;
Begin
{ If Assigned(AddictSpell) Then
  Begin
   AddictSpell:=TAddictSpell3.Create(Nil);
   AddictSpell.ConfigUseMSWordCustom:=True;
   AddictSpell.ConfigDictionaryDir.Strings[0]:='%AppDir%\Dictionaries';
   AddictSpell.SuggestionsLearning:=True;
   AddictSpell.PhoneticSuggestions:=True;
  End;}

{ If Assigned(Richedit3)=False Then
  Begin
    Richedit3:=TAddictRichEdit.Create(nil);
    Richedit3.AddictSpell:=SpellModual;
    Richedit3.OnKeyDown:=richedit2KeyDown;
    Richedit3.OnKeyUp:=richedit2KeyUp;
    Richedit3.OnMouseDown:=richedit2MouseDown;
    Richedit3.OnMouseMove:=richedit2MouseMove;
    Richedit3.ParentWindow:=Form1.Panel5.Handle;
    Richedit3.Top:=Richedit2.Top;
    Richedit3.Left:=Richedit2.Left;
    Richedit3.Width:=Richedit2.Width;
    Richedit3.Height:=Richedit2.Height;
    Richedit3.LiveMenuOptions:=[spDialog, spAutoCorrect, spChangeAll, spAdd, spIgnoreAll, spIgnore, spReplace];
    Richedit3.Align:=AlClient;
    Richedit3.LiveSpelling:=True;
    Richedit3.LiveSpellingReadOnly:=False;
    Richedit3.Visible:=True;
    Richedit2.Visible:=False;
  End;}

End;

Procedure TForm1.CloseSpellChecker;
Begin
End;

procedure TForm1.SpellChecker1Click(Sender: TObject);
begin
 SpellChecker1.Checked:=Not SpellChecker1.Checked;
 If SpellChecker1.Checked=True Then
  Begin
    If FileExists(Path+'American.adm')=False Then
     Begin
      IF MessageDlg('Dictionary not found, would you like to download it? ',MtConfirmation,[mbyes,mbno],1)=IDyes Then
        TFileDownload.Create('http://ymlitechat.com/ymlite/American.adm','','80',0,Nil,False,True,True,False);
       SpellChecker1.Checked:=False;
       Lsm.Free;
       Lsm:=Nil;
       Exit;
      End
     Else
      Begin
        If Assigned(Lsm)=False Then
         Begin
          Lsm:=TAddictAutoLiveSpell.Create(Form1);
          Lsm.ConfigDictionaryDir.Strings[0]:='%AppDir%';
          Lsm.LiveControl:=Richedit2;
          Richedit2.AddictSpell:=LSM;
         End;
        //  Form1.LiveSpellModual.LiveControl:=Richedit2;
      End;
    //American.adm
  End
   else
    Begin
      Lsm.Free;
      Lsm:=Nil;
     End;
end;

procedure TForm1.Profiles1Click(Sender: TObject);
begin
 ShellExecute(handle,'open',Pchar('http://profiles.yahoo.com/'+L1WhoIsSelected+'?warn=1'),'','',0);
 Form1.ReleaseMemory;
end;

Function TForm1.UserNameToNode(S: String; Offset: Boolean): TTreeNode;
Var
 N: Integer;
Begin
 Result:=Nil;
 IF Buddies<>Nil Then
   Begin
    N:=Buddies.IndexOf(S);
    IF N<>-1 Then
      Result:=TTreeNode(Buddies.objects[N]);
   End;
End;

{Function TForm1.UserNameToNode(S: String; Offset: Boolean): TTreeNode;
var
  CurItem: TTreeNode;
begin
 Result:=Nil;
  CurItem := SpartaBox.SpSkinTreeView1.Items.GetFirstNode;
  while CurItem <> nil do
  begin
    //ListBox1.Items.Add(CurItem.Text);
    If LowerCaseRep(CurItem.Text)=LowerCaseRep(S) Then
     Begin
       Result:=CurItem;
       Exit;
     End;
    CurItem := CurItem.GetNext;
  end;
End;}

Function Tform1._DeleteBuddy(Who: String): Integer;
Var
 N: Integer;
Begin
 N:=Buddies.IndexOf(Who);
 If N>-1 Then
    Buddies.Delete(N);

 N:=OnlineBuddies.IndexOf(Who);
 If N>-1 Then
    OnlineBuddies.Delete(N);
 Result:=N;
End;

Function Tform1._AddOnlineBuddy(Who: String; Node: TTreeNode): Integer;
Begin
 If OnlineBuddies.IndexOf(Who)=-1 Then
    OnlineBuddies.AddObject(Who,Node);
End;

Function Tform1._AddBuddy(Who: String; Node: TTreeNode): Integer;
Begin
 If Buddies.IndexOf(Who)=-1 Then
    Buddies.AddObject(Who,Node);
End;

procedure TForm1.SpartaClient1ServerMessage(Sender: TObject;
  ServerMessage: String);
begin
 

end;

{Function Tform1.AddRootNode(Caption: String): TTreeNode;
Var
 TempNode : TTreeNode;
 RNode: TTreeNode;
Begin
// TempNode := SpSkinTreeView1.Items.AddChild(Node, SearchRec.Name);
   RNode := SpartaBox.SpSkinTreeView1.Items.Add(nil,Caption);
   RNode.ImageIndex:=2;
   RNode.SelectedIndex:=2;
   Result:=RNode;
End;

Function Tform1.AddChildNode(Caption: String; Node: TTreeNode): TTreeNode;
Var
 TempNode : TTreeNode;
Begin
   TempNode:=SpartaBox.SpSkinTreeView1.Items.AddChild(Node,Caption);
   TempNode.ImageIndex:=0;
   TempNode.SelectedIndex:=0;
   Result:=TempNode;
End;}


procedure TForm1.MemoryStats1Click(Sender: TObject);
begin
 DisplayStats;
end;


procedure TForm1.GetMETAFromNet(Sender: TObject; Content : string);
begin
end;

procedure TForm1.spSkinButton13Click(Sender: TObject);
begin
  InitMp3;
  YampTrack:=0;
  If Assigned(YampList)=False Then
    Form1.YampList:=TStringList.Create;
    IF DirectoryExists(LastPath)=True Then
      IF LastPath<>'' Then
       SpSkinOpenDialog1.InitialDir:=LastPath;
  SpSkinOpenDialog1.FileName:='';
  SpSkinOpenDialog1.Execute;
  SpSkinComboBox5.Text:=ExtractFileName(SpSkinOpenDialog1.FileName);
  If SpSkinOpenDialog1.FileName<>'' Then
   Begin
   YampTrack:=0;
    YampList:=SpSkinOpenDialog1.Files;
//    BassPlayer.Open(SpSkinOpenDialog1.FileName);
    Form1.PlayMp3(SpSkinOpenDialog1.FileName);
    Form1.SpSkinComboBOx5.Text:=ExtractFileName(YampList[0]);
    Form1.spSkinComboBox5.Items.Text:=YampList.Text;
//    Form1.SpSkinLabel2.Caption:=BassPlayer.StreamInfo.Artist+' - '+BassPlayer.StreamInfo.Title;
    LastPath:=ExtractFilePath(SpSkinOpenDialog1.FileName);
   End;
//   ShowMessage('Mp3 Support Not Enabled');
end;

procedure TForm1.Button3Click(Sender: TObject);
Var
 Fn: String;
 DataStr: String;
// Logger: TFileStream;
 Obj: Tform4;
Begin

// PornBotTracker.CleanBotList;
// ListBox2.Items
// If IsAa1Bot('aa1aucontrairef8_43')=True Then
// If Form1.GetURL('htrhghttp://ddd.com spam',true)<>'' Then
//    ShowMessage('True');
// Obj:=Form1.GetPmWindow('Craig22');

//WriteLogData('Craig','whofrom','Hello There',True);
//WriteLogData('Craig','whofrom','Hello There',false);

 // form1.Thesaurus31.LookupWord('idiot'); //.LookupWord('idiot');



{ DynamicWindow('sfdsd','sdf','fsdsdaf','',false);
  Delay(1300);
  DynamicWindow('sdfsdf','sdf2','ffdsdaf','',false);
  Delay(1300);
  DynamicWindow('ssdaffd3','sd3f3','f3sdaf','',false);}
// Form1.spDynamicSkinForm1.AnimateStart('spskinxformbutton1');
// PornBotTracker.checkString('dog','hello there!');
//ValidText('°2àè¶¹*×@Ð+Ì=e1-Á©¦+~\ÖQá¦+ùí8Ûi£ÊÑÚÃ+çC+7u+`Âqà-¢ƒ¨Ù[ã?\IâÆ¦EL{½æ"p¦/Är>+	¤¡ðfªó±Þc«ë;ÔÝS¯÷:mÈÏöêé¦-ÍUέJ<¼ÉiVÉÒ,ûYê³Ôs}Çø+Å+WZRj_¦!À¸¾BTb9¦ +î3>ñ0Gïz%gÕÕkòË^¥X¤ª(_AøI¦hئºß4}ú¬+M3-+nìýÓ|dg_w-Or-HDôaoF-Pþ','ddd');
//YampList.Add('FSDG');
//  Form1.YampList.Add('dgfsf');
// Form1.TestForBot(' eglu mmmm, hi honey. oyowh');
//LastCharPos2(' ',' ',1);
//  Form1.panel10.caption:='gkldfgkldfjgkldjfglkdfgdflkjgdflkjgodiujtgoidfujgoidsjfgoidjfgiojsdfigojsdifogjdosifjgodisfjgodisfjgoisdfjgiodsjgoijsdfgoijdfsoigjdsfoigjdosifjgodisfjgoisdfjgiosdjfgodisjfgoisdfjgoisdfjgodisfjgsdfoigjosdifjgosdifjgosdfigiosdfjg';
// DealWithAvaInfo('ch\help','gears');
//Form1.DoAvatar(Form1.Richedit1,'ch\help');
 //Form1.DoRtfFace(Richedit1,'alertava.');
// ShowMessage(DecryptPassword('}m{>AFys|†LHO',10));
// ShowMessage(DecryptPassword('oqss}svD',10));
// ShowMessage(TimeToStr(Now+UnixToDateTime(53532)));
end;

Procedure TForm1.OnTime(Sender: TObject; Time: TDateTime; EncodedStr: String);
Begin

End;

Procedure TForm1.OnFail(Sender: Tobject);
Begin

End;

procedure TForm1.spSkinComboBox4CloseUp(Sender: TObject);
begin
{ If (SpSkinComboBox4.Text<>'') and (SpSkinComboBox4.Text<>'World Zones') Then
     Form1.Richedit2.Text:=SpSkinComboBox4.Text;
 Form1.Richedit2.SetFocus;}
end;

procedure TForm1.Timer5Timer(Sender: TObject);
begin
 If Exiting=True Then Exit;
 Dec(Form1.ReconnectIn);
 Form1.Panel10.Caption:='Attempting To Reconnect In... '+IntToStr(Form1.ReconnectIn);
 If Form1.ReconnectIn<=1 Then
  Begin
    BumpKnocks:=0;
    Timer5.Enabled:=False;
    Form1.RoomAckWait:=True;
    Form1.RoomJoinWait:=False;
    Form1.Disconnecting:=False;
    Timer7.Enabled:=True;
    ReconnectIn:=4;
    Form2.BitBtn3.OnClick(Self);
    Form1.Timer5.Enabled:=False;
  End;
end;

procedure TForm1.SelectJpgIdent1Click(Sender: TObject);
begin
 Form1.OpenPictureDialog1.Filter:=' Files|*.Jpg';
  Form1.OpenPictureDialog1.InitialDir:=Path+'identitar\';
 Form1.OpenPictureDialog1.Execute;
 Identitar:=ExtractFileName(Form1.OpenPictureDialog1.FileName);
 Identitar:=Copy(Identitar,1,PosRep('.',Identitar)-1);
 Form1.JpgToBmpYmlite(Identitar);
 Chatters[Form1.ChatterNum(LoggedInName)].Ident:='CH\'+Identitar;
 Identitar:='CH\'+Identitar;
end;

procedure TForm1.TimeSpentTyping1Click(Sender: TObject);
begin
 TMenuItem(Sender).Checked:=Not  TMenuItem(Sender).Checked;
end;

procedure TForm1.Panel10Click(Sender: TObject);
begin
 Form1.CreateSkin(Form40);
 Form40.FormStyle:=FsStayOnTop;
 Form40.Show;
end;


procedure TForm1.SpartaClient1ChatPacket(Sender: TObject; RoomName,
  FromWho, Msg, FullMsg: String);
Var
 Len: Integer;
 S: String;
begin
end;

procedure TForm1.YmLiteVoiceShield2KXPOnly1Click(Sender: TObject);
begin
If FileExists(Path+'udpblocker.exe')=False Then
   Begin
    TFileDownload.Create('http://ymlitechat.com/ymlite/udpblocker.exe','','80',0,Nil,False,True,False,False);
    ShowMessage('[DO NOT CLOSE VOICE GAURD (BLACK BOX) UNTIL YOU CONNECT TO VOICE] When the Voice Gaurd has closed off UDP ports 5000 - 5010 Close/Rerun Voice (minivoice/inbuilt voice) This will protect you from UDP lag packets.');
   End
 else
   Begin
    VoiceGaurd:=True;
    WinExec(Pchar(Path+'udpblocker.exe'),SW_Show);
    ShowMessage('[DO NOT CLOSE VOICE GAURD (BLACK BOX) UNTIL YOU CONNECT TO VOICE] When the Voice Gaurd has closed off UDP ports 5000 - 5010 Close/Rerun Voice (minivoice/inbuilt voice) This will protect you from UDP lag packets.');
   End;

// http://ymlitechat.com/ymlite/udpblocker.exe

end;

procedure TForm1.ServerSocket1ClientConnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
 ShowMessage('Voice Proxy Enabled');
end;

{ TKnock }

constructor TKnock.Create(Room: String; Timeout,Interval: Integer);
begin
 Timer:=TTimer.Create(Nil);
 Timer.Interval:=Interval;
 Timer.OnTimer:=OnTimer;
 Timer.Enabled:=False;
 FInterval:=Interval;
 FKnockRoom:=Trim(Room);
 FTimeOut:=TimeOut;
end;

destructor TKnock.Destroy;
begin
 If Timer<>Nil Then
  Begin
    Timer.Free;
    Timer:=Nil;
  End;
end;

procedure TKnock.OnTimer(Sender: Tobject);
begin
 Inc(Counter);
 Inc(KnockAttempt);
{ If Counter>=5 Then
  Begin
   Timer.Enabled:=False;
   Form1.Richedit1.Lines.Add('As a safety precaution, Knock has a 3 minute time out, please /knock again if you wish to continue');
   Self.Destroy;
   Exit;
  End;}
 Form1.SendText(Form1.JoinRoom(LoggedInName,FKnockRoom));
 Form1.Richedit1.Lines.Add('('+IntTOStr(KnockAttempt)+') Knocking room '+FKnockRoom+' To Disable Knocking type in /knock at any time to stop it');
end;

procedure TKnock.StartKnocking;
begin
  KnockAttempt:=0;
  Counter:=0;
  Timer.Enabled:=True;
  Form1.Richedit1.Lines.Add('Knocking For Room '+FKnockRoom+' has began. '+' Interval  = '+IntToStr(FInterVal div 1000)+' Seconds');  
end;

procedure TKnock.StopKnock;
begin
  Timer.Enabled:=False;
  Form1.Richedit1.Lines.Add('Knocking For Room '+FKnockRoom+' Stopped');
end;

procedure TForm1.RichEdit1DoubleClick(Sender: TObject);
Var
 Username: String;
 P: Integer;
begin
   If PosRep('*',WordStr)>0 Then
    WordStr:=Copy(WordStr,1,PosRep('*',WordStr)-1);
   If PosRep('*:',WordStr)>0 Then
     WordStr:=Copy(WordStr,1,PosRep('*:',WordStr)-1);
   If PosRep(':',WordStr)>0 Then
     WordStr:=Copy(WordStr,1,PosRep(':',WordStr)-1);

  If (Form1.ListBox1.Items.IndexOf(WordStr)<>-1) Or (Form1.ListBox2.Items.IndexOf(WordStr)<>-1) Or (TmpLeave.IndexOf(WordStr)<>-1) Then
   Begin
     Form1.Richedit1.SelStart:=65535;
     Form1.IgnoreUser(Wordstr,false,True,False,False);
     Richedit2.SetFocus;
   End;

  If Copy(WordStr,1,1)='<' Then
   Begin
    Delete(WordStr,1,1);
    Username:=WordStr;
    Username:=Copy(WordStr,1,Length(Username)-1);
    If Username<>'<' Then
     Begin
      P:=Form1.ListBox2.Items.IndexOF(Username);
      If P<>-1 Then
       Begin
         RemoveIgnoredUser(Username);
         If Assigned(Form1.Yacs1) Then
            Form1.yacs1.unmuteSource(Chatters[Form1.ChatterNum(Username)].SourceID,Username);
         Form1.ListBox1.Items.Add(Username);
         Form1.ListBox2.Items.Delete(P);
         Form1.ScrollToEnd(Form1.Richedit1);
         Form1.Richedit1.Lines.Add('');
         Form1.Richedit1.SelAttributes.Color:=ClBlue;
         Form1.Richedit1.SelText:=Username;
         Form1.Richedit1.SelAttributes.Color:=ClBlack;
         Form1.Richedit1.SelText:=' Has been removed from The Ignore Bin';
         Form1.Richedit1.Lines.Add('');
         Form1.ScrollToEnd(Form1.Richedit1);
       End;
     End;
   End;
end;

{ TPornBots }

procedure TPornBots.AddBotString(Str: String);
begin
 If BotStrings.Find(Str,Obj)=False Then
   BotStrings.Add(Str,Obj);
end;

Function TPornBots.DealWithBot(Username,Str: String): Boolean;
Begin
 Result:=False;
   //Might be a bot, add warning
   If IsUserIgnored(UserName)=False Then
    Begin
      Result:=True;
      Form1.Panel10.Caption:=UserName+': Possible Spam Bot from Alicia Group  '+Str+ ' / '+IntToStr(Chatters[Form1.ChatterNum(UserName)].BotPCount);
      AddBlockMessage(Form1.Panel10.Caption);
       If (Chatters[Form1.ChatterNum(Username)].BotPCount>=3) Then
           Form1.IgnoreUser(Username,false,True,True,False);
     End;
End;

Procedure TPornBots.Clear;
Var
 N: Integer;
 Tmp: String;
Begin
 BotStrings.Free;
 BotList.Free;
 BotStrings:=TStringHashTrie.Create;
 BotList:=TStringHashTrie.Create;
 BotStrings.CaseSensitive:=True;
 SaveStringsList;
End;


function TPornBots.ChatP(UserName, Str: String): Boolean;
begin
Result:=False;
If (Length(Str)<255) And (Trim(Str)<>'') And (Length(Str)>8) Then
  Begin
   Str:=Trim(Form1.RemoveSmiles(Str));
  // Chatters[Form1.ChatterNum(FromWho)].BlockCount
   If Self.CheckBot(UserName)=True Then  //*
     Begin
       //if is on botlist and string is not in db
        If Self.CheckString(UserName,Str)=False Then
         Begin
          Inc(Chatters[Form1.ChatterNum(UserName)].BotPCount);
          Self.AddBotString(Str);
          Result:=Self.DealWithBot(UserName,Str);
         End
          Else
         Begin
         //if on botlist and string IS in DB.
          If IsUserIgnored(UserName)=False Then
            Begin
             Inc(Chatters[Form1.ChatterNum(UserName)].BotPCount);
             Form1.Panel10.Caption:=UserName+': Possible Spam Bot from Alicia Group  '+Str+ ' / '+IntToStr(Chatters[Form1.ChatterNum(UserName)].BotPCount);
             AddBlockMessage(Form1.Panel10.Caption);
             Form1.IgnoreUser(Username,false,True,True,False);
            End;
         End;
     End
 Else
     Begin //Otherwise, not tracking, do we need to?
        If Self.CheckString(UserName,Str)=True Then  //*
         Begin
          Inc(Chatters[Form1.ChatterNum(UserName)].BotPCount);
          If Chatters[Form1.ChatterNum(UserName)].BotPCount=1 Then
             Begin
              Result:=True;
              Form1.Panel10.Caption:=UserName+': Possible Spam Bot from Alicia Group  '+Str+ ' / '+IntToStr(Chatters[Form1.ChatterNum(UserName)].BotPCount);
              AddBlockMessage(Form1.Panel10.Caption);
              Exit;
             End;
          If (Chatters[Form1.ChatterNum(Username)].BotPCount=2) Then
              Self.TrackBot(Username);
          Result:=Self.DealWithBot(UserName,Str);
         End;
     End;
  End;

end;

function TPornBots.CheckBot(UserName: String): Boolean;
Var
 I: Integer;
begin
 Result:=Self.BotList.Find(UserName,Obj);
end;

function TPornBots.CheckString(Username, Str: String): Boolean;
begin
  Result:=BotStrings.Find(Str,Obj);
end;

constructor TPornBots.Create;
begin
 Inherited Create;
 BotList:=TStringHashTrie.Create;
 BotStrings:=TStringHashTrie.Create;
 BotStrings.CaseSensitive:=True;
 IF FileExists(Path+'BotList.txt')=True Then
    Form1.LoadFromFile(BotList,Path+'BotList.txt');
//    BotList.LoadFromFile(Path+'BotList.txt');
 IF FileExists(Path+'BotStrings.txt')=True Then
    Form1.LoadFromFile(BotStrings,Path+'BotStrings.txt');
//    BotStrings.LoadFromFile(Path+'BotStrings.txt');
end;

Procedure TPornBots.SaveStringsList;
Begin
 Form1.SaveToFile(BotList,Path+'BotList.txt');
 Form1.SaveToFile(BotStrings,Path+'BotStrings.txt');
//  BotList.SaveToFile(Path+'BotList.txt');
//  BotStrings.SaveToFile(Path+'BotStrings.txt');
End;



destructor TPornBots.Destroy;
begin
  inherited destroy;
  Form1.SaveToFile(BotList,Path+'BotList.txt');
  Form1.SaveToFile(BotStrings,Path+'BotStrings.txt');
//  BotList.SaveToFile(Path+'BotList.txt');
//  BotStrings.SaveToFile(Path+'BotStrings.txt');
  BotList.Free;
  BotStrings.Free;
end;



function TPornBots.TrackBot(UserName: String): Integer;
begin
 If BotList.Find(UserName,Obj)=False Then
   BotList.Add(UserName,Obj);
end;

function TPornBots.DeleteBot(UserName: String): Integer;
Var
 N: Integer;
begin
 BotList.Delete(UserName);
 Result:=0;
end;

procedure TForm1.FlagAsBotLearn1Click(Sender: TObject);
begin

 If Form1.PornBotTracker.CheckBot(WordStr2)=False Then
  Begin
   Form1.PornBotTracker.TrackBot(WordStr2);
   ShowMessage('You are now Tracking Bot '+WordStr2+' To Stop Tracking This ID again Select "Flag as bot" ');
  End
   Else
  Begin
   Form1.PornBotTracker.DeleteBot(WordStr2);
   ShowMessage('You are no longer Tracking Bot '+WordStr2);
  End;
end;

Procedure TForm1.MergeBotFile(Fn: String);
Var
 T: TextFile;
 Tmp: String;
 Mc: Integer;
Begin
  Mc:=0;
  System.Assign(T,Fn);
  System.Reset(T);
  While Not(Eof(T)) Do
   Begin
    Readln(T,Tmp);
    Tmp:=Trim(Tmp);
    If Assigned(PornBotTracker) Then
       If PornBotTracker.CheckString('',Tmp)=False Then
        Begin
          If (Length(Tmp)>7) Then
           Begin
            Inc(Mc);
            Form1.Panel10.Caption:='Merging String '+IntToStr(MC)+' Data: '+Tmp;
            PornBotTracker.BotStrings.Add(Tmp,PornBotTracker.Obj);
           End;
        End;
   End;
   ShowMessage('Merged '+IntToStr(MC)+' Bot String(s) into Y!mLite''s Own Database for greater bot protection');
   System.Close(T);
End;


Procedure TForm1.MoveAndUseYPF(Fn: String);
Var
 YpfName: String;
Begin
 If FileExists(Fn)=True Then
   Begin
      YpfName:=Path+ExtractFileName(FN);
      If FileExists(YpfName)=True Then
        DeleteFile(YpfName);
      MoveFile(Pchar(Fn),Pchar(YpfName));
      Personality.LoadPersonality(YpfName);
   End;
End;


Procedure TForm1.MoveAndUseSkin(Fn: String);
Begin
 If FileExists(Fn)=True Then
   Begin
      SkinName:=Path+'Skins\'+ExtractFileName(FN);
      If FileExists(SkinName)=True Then
        DeleteFile(SkinName);
      MoveFile(Pchar(Fn),Pchar(SkinName));
      Form1.SpSkinData1.LoadFromCompressedFile(SkinName);
      If ProgButtons[1]<>Nil Then
       Begin
         Form1.SpSkinPanel2.Height:=ProgButtons[1].Height+1;
         Form1.Panel3.Height:=Panel10.Height;
       End;
   End;
End;

procedure TForm1.DownloadNotifcation(var Msg: Tmessage);
begin
 If Pos('.skn',LowerCaseRep(NotificationStr))>0 Then
    MoveAndUseSkin(FullNotificationStr);
 If Pos('.ypf',LowerCaseRep(NotificationStr))>0 Then
    MoveAndUseYPF(FullNotificationStr);
 If NotificationStr='American.adm' Then
   SpellChecker1.OnClick(Self);
 If NotificationStr='yacscom.dll' Then
   Form1.spSkinSpeedButton2.OnClick(Self);

//   SpSkinButton4.OnClick(Self);
{ If NotificationStr='bandwithwarn.wav' Then
    Form1.BooterCalibrationTest1.OnClick(Self);
 If NotificationStr='highlander.mp3' Then
    ShowMessage('Your Download Bandwith Speed Measured: '+FloatToStr(Form1.MaxDownloadSpeed)+' K/S When a booter reaches this figure, you''ll be warned that you could be booted');}
 If NotificationStr='ymsg.dll' Then
   Form2.RadioButton1.Enabled:=True;
 If NotificationStr='botmergestrings.txt' Then
    MergeBotFile(Path+'botmergestrings.txt');

end;

procedure TForm1.AutoRejectViewCamMessages1Click(Sender: TObject);
begin
 AutoRejectViewCamMessages1.Checked:=Not AutoRejectViewCamMessages1.Checked;
end;

procedure TForm1.FancyMenuInterface1Click(Sender: TObject);
begin
 FancyMenuInterface1.Checked:=Not FancyMenuInterface1.Checked;
 SpDynamicSkinForm1.MenusAlphaBlend:=FancyMenuInterface1.Checked;
 SpDynamicSkinForm1.MenusAlphaBlendAnimation:=FancyMenuInterface1.Checked;
// SpDynamicSkinForm1.menu
end;

procedure TForm1.ChangeRooms1Click(Sender: TObject);
begin
  spSkinImagesMenu1ImagesItems7Click(Self);
end;



procedure TForm1.SendCheetaSound1Click(Sender: TObject);
Var
 Sf: String;
begin
 If CCInstalled=True Then
  Begin
    Form1.OpenDialog1.FilterIndex:=3;
    Form1.OpenDialog1.InitialDir:='c:\program files\cheetachat\sounds';
    Form1.OpenDialog1.Execute;
    StartSound(Form1.OpenDialog1.FileName,True,False);
    SF:=ExtractFileName(Form1.OpenDialog1.FileName);
    Sf:=Copy(Sf,1,PosRep('.',SF)-1);
    SF:=' <aud="'+SF+'"> ('+SF+')';
    Form1.Say(Form1.Richedit1,SF,True,True,False);
    Form1.ReleaseMemory;
  //  form1.RichEdit2.SelText:=SF;
  End
   Else
  ShowMessage('You Need CheetaChat 7.5 Installed TO Use This Feature');
end;


procedure TForm1.Richedit2MouseUp(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
begin
 MousePressed:=False;
end;

procedure TForm1.NeedaDrinksTrayHolder1Click(Sender: TObject);
var
  mci: TMCI_Open_Parms;
begin
  ShowMessage('Press OK, Getting Your Drinks Holder Ready, Grab a Coke :P ');
  FillChar(mci, SizeOf(mci), #0);
  mci.lpstrDeviceType := PChar('CDAudio');
  mciSendCommand(0, mci_Open, mci_Open_Type, Longint(@mci));
  mciSendCommand(mci.wDeviceID, mci_Set, 256*(Byte(False)+1), 0);
  ShowMessage('Only Kidding :P');
  mciSendCommand(mci.wDeviceID, mci_Set, 256*(Byte(True)+1), 0);
  { MCI_SET_DOOR_OPEN = 256 }
  { MCI_SET_DOOR_CLOSED = 512 }
end;

procedure TForm1.ListBox1MouseDown(Sender: TObject; Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
 Pon : TPoint;
 Pos: Integer;
begin
 {If SSShift in Shift Then
     Exit;}
 If Shift=[ssRight] Then
  Begin
   Pon.x := X;
   Pon.y := Y;
    If (Form1.ListBox1.SelCount<=1) Then
      Begin
        Form1.ListBox1.MultiSelect:=False;
        Form1.ListBox1.MultiSelect:=True;
        Pos:=ListBox1.ItemAtPos(Pon,True);
        ListBox1.ItemIndex :=Pos;
        ListBox1.Selected[Pos]:=True;
       End;
   End;    
end;

procedure TForm1.AllowVoice1Click(Sender: TObject);
Var
 Chatter: String;
 N: Integer;
begin
 For N:=Form1.ListBox1.Items.Count-1 Downto 0 do
 Begin
  If Form1.ListBox1.Selected[n]=True Then
   Begin
    Chatter:=Form1.ListBox1.Items[n];
    If AllowVoiceList.indexOf(Chatter)=-1 Then
       AllowVoiceList.Add(Chatter);
    If Assigned(Form1.Yacs1) Then
      Form1.yacs1.UnmuteSource(Chatters[Form1.ChatterNum(Chatter)].SourceID,Chatter);
    End;
  End;
  ListBox1.Repaint;  
end;

Procedure TForm1.FixVoice;
Begin
 IF (FileExists(Path+'voice\yacscom.dll')=False) Then
   Begin
    if DirectoryExists(Path+'voice')=False then
         CreateDir(Path+'voice');
     IF MessageDlg('Yacscom.dll needs to be downloaded in order for voice to work press yes to install it.. ',MtConfirmation,[mbyes,mbno],1)=IDyes Then
       TFileDownload.Create('http://ymlitechat.com/ymlite/yacscom.dll',Path+'voice\yacscom.dll','80',0,Nil,False,True,True,False);
   End
   else
 Begin
   RegisterOCX(Path+'voice\yacscom.dll');
   ShowMessage('Correction Made To Registry Entry To Fix Voice, Please Try voice Again.');
 End;
End;

Procedure TForm1.RegisterMP;
Var
 SI: TStartupInfo;
 PI: TProcessInformation;
 Path2: String;
begin
 Path2:=ShortFileName(Path);
 ShellExecute(form1.handle,'open',Pchar('regsvr32'),Pchar('/s '+Path2+'msdxm.ocx'),'',sw_hide);
 ShowMessage('Correction Made To Registry Entry To Fix Voice, Please Try voice Again.');
End;

procedure TForm1.VoiceProblemFixClick1Click(Sender: TObject);
Begin
 Form1.FixVoice;
end;


procedure TForm1.spSkinImagesMenu1ImagesItems14Click(Sender: TObject);
begin
 SpSkinControlBar1.Visible:=Not SpSkinControlBar1.Visible;
 If SpSkinControlBar1.Visible=True Then
     If InVoice=False Then
       SpSkinSpeedButton2.OnClick(Self);
 If SpSkinControlBar1.Visible=False Then
    If InVoice=True Then
       SpSkinSpeedButton2.OnClick(Self);
end;

procedure TForm1.spSkinImagesMenu1ImagesItems12Click(Sender: TObject);
begin
  SpSkinPanel2.Visible:=Not SpSkinPanel2.Visible;
end;

procedure TForm1.spSkinImagesMenu1ImagesItems11Click(Sender: TObject);
begin
 Panel3.Visible:=Not Panel3.Visible;
end;

procedure TForm1.spSkinImagesMenu1ImagesItems10Click(Sender: TObject);
begin
  SpSkinScrollPanel1.Visible:=Not SpSkinScrollPanel1.Visible;
 If SpSkinScrollPanel1.Visible=True Then
  Begin
   If SpSkinScrollPanel1.Align=AlRight Then
      SpSkinSplitter2.Left:=SpSkinScrollPanel1.Left-1;
   If SpSkinScrollPanel1.Align=AlLeft Then
      SpSkinSplitter2.Align:=AlLeft;
   End;

end;

procedure TForm1.spSkinImagesMenu1ImagesItems9Click(Sender: TObject);
begin
 SpSkinMainMenuBar1.Visible:=Not SpSkinMainMenuBar1.Visible;
end;

procedure TForm1.spSkinImagesMenu1ImagesItems8Click(Sender: TObject);
begin
 Form1.SpSkinExPanel1.Visible:=True;
 Form1.SpSkinExPanel2.Visible:=True;
 Form1.SpSkinExPanel3.Visible:=True;
 Form1.SpSkinExPanel4.Visible:=True;
end;

procedure TForm1.spSkinImagesMenu1ImagesItems7Click(Sender: TObject);
begin
  Form1.CreateSkin(Form7);
  Form7.Show;
end;

procedure TForm1.spSkinImagesMenu1ImagesItems6Click(Sender: TObject);
begin
 Form14.Obj:=Richedit2;
 Form14.Show;
end;

procedure TForm1.spSkinImagesMenu1ImagesItems5Click(Sender: TObject);
begin
If Panel1.Visible=False Then
 InitMp3
  Else
 Begin
  If MediaPlayer21<>Nil Then
   Begin
    MediaPlayer21.Free;
    MediaPlayer21:=Nil;
    SpSkinSplitter1.Visible:=False;
    Panel1.Visible:=False;
   End;
  //free mp3
 End;

 
{ If (Form1.spSkinControlBar1.Align=AlBottom) and (Form1.spSkinControlBar2.Align=AlBottom) Then
  StyleMode:=1;
 Inc(StyleMode);
 If StyleMode>6 Then
   StyleMode:=1;
 Case StyleMode Of
   1: Begin
    Form1.spSkinControlBar1.Align:=AlBottom;
    Form1.spSkinControlBar2.Align:=AlBottom;
   End;
   2: Begin
    Form1.spSkinControlBar1.Align:=AlTop;
    Form1.spSkinControlBar2.Align:=AlBottom;
   End;
   3: Begin
    Form1.spSkinControlBar1.Align:=AlTop;
    Form1.spSkinControlBar2.Align:=AlTop;
   End;
   4: Begin
    Form1.spSkinControlBar1.Align:=AlBottom;
    Form1.spSkinControlBar2.Align:=AlTop;
   End;
   5: Begin
     Form1.spSkinScrollPanel1.Align:=AlLeft;
     Form1.SpSkinSplitter2.Align:=AlLeft;
   End;
   6: Begin
     Form1.spSkinScrollPanel1.Align:=AlRight;
     Form1.SpSkinSplitter2.Align:=AlRight;
   End;
  End;}
end;

procedure TForm1.spSkinImagesMenu1ImagesItems3Click(Sender: TObject);
Var
 YUrl: String;
 Enc: TEncrypt; 
begin
 YUrl:=InputBox('Enter URL You wish to be YUrl''ed','URL Address: ','');
 If Trim(Yurl)='' Then Exit;
 Enc:=TEncrypt.Create;
 YUrl:=Enc.EncryptStr(YUrl);
 YUrl:='[yurl]'+YUrl+'[/yurl]';
 form1.RichEdit2.SelText:=YUrl;
 Enc.Free;
end;

procedure TForm1.spSkinImagesMenu1ImagesItems2Click(Sender: TObject);
begin
   Form1.AllOnlineFriends1Click(Self);
end;

procedure TForm1.spSkinImagesMenu1ImagesItems0Click(Sender: TObject);
begin
 Form1.SelectSkin1Click(Self);
end;

procedure TForm1.spSkinImagesMenu1ImagesItems1Click(Sender: TObject);
begin
 CloneTag:=False;
 Form1.spSkinCheckRadioBox1.Checked:=True;
 Form1.CreateSkin(Form9);
 Form9.ShowModal;
end;

procedure TForm1.Panel1Resize(Sender: TObject);
begin
 If MediaPlayer21<>Nil Then
  Begin
   If MediaPlayer21.Tag=1 Then
    Begin
      MediaPlayer21.Width:=Panel1.Width;
      MediaPlayer21.Height:=Panel1.Height-SpSkinButton13.Height-SpSkinComboBox5.Height-3;
      OldPanelLength:=Panel1.Width;
    End;
  End;

end;


Procedure Tform1.PlayMp3(Mp3: String);
Begin
 If FileExists(mp3)=False Then
  Begin
   ShowMessage('File '+Mp3+' Does not exist');
   Exit;
  End;
If Assigned(MediaPlayer21) Then
  Begin
    MediaPlayer21.Visible:=True;
      If (Pos('.mp3',LowerCaseRep(Mp3))>0) Or (Pos('.mid',LowerCaseRep(Mp3))>0) Then
      Begin
       MediaPlayer21.Tag:=2;
       OldPanelLength:=Panel1.Width;
       Panel1.Align:=AlBottom;
       Panel1.Height:=45;
       MediaPlayer21.top:=0;
       MediaPlayer21.Height:=45;
       MediaPlayer21.Left:=1;
       MediaPlayer21.Width:=290;
       SpSkinButton13.Align:=AlNone;
       SpSkinComboBox5.Align:=AlNone;
       SpSkinButton13.Top:=0;
       SpSkinButton13.Left:=295;
       SpSkinButton13.Width:=100;
       SpSkinComboBox5.Top:=0;
       SpSkinComboBox5.Left:=400;
       SpSkinComboBox5.Width:=350;
       SpSkinSplitter1.Visible:=False;
       MediaPlayer21.Repaint;
      End;

    {  If (Pos('www',LowerCase(Mp3))>0) Or (Pos('.swf',LowerCase(Mp3))>0) or (Pos('.swv',LowerCase(Mp3))>0) Then
      Begin
        MediaPlayer21.Visible:=False;
        If SWF=Nil Then
         Begin
          Try
            SwF:=TShockWaveFlash.Create(form1);
             except
            ShowMessage('Flash 9 is Required');
            Exit;
            End;
          End;
       Panel1.Align:=AlLeft;
       SpSkinButton13.Align:=AlBottom;
       SpSkinComboBox5.Align:=AlBottom;
       SpSkinSplitter1.Visible:=True;
       SpSkinSplitter1.Left:=Panel1.Width+1;
        If Form1.OldPanelLength>=Form1.Width-20 Then
             Form1.OldPanelLength:=280;
        Panel1.Width:=Form1.OldPanelLength;
       swf.Visible:=true;
       swf.SAlign:='15';
       Swf.Align:=AlClient;
       Swf.Height:=Panel1.Height-SpSkinButton13.Height-SpSkinComboBox5.Height-3;
       Swf.Width:=Swf.Width;
       swf.ParentWindow:=form1.Panel1.Handle;
       swf.LoadMovie(0,'http://www.youtube.com/v/46LQd9dXFRU');
       Swf.Tag:=1;
       Exit;
      End;}


     If (Pos('.avi',LowerCase(Mp3))>0) or (Pos('.mpg',LowerCase(Mp3))>0) or (Pos('.mpeg',LowerCase(Mp3))>0) or (Pos('.wmv',LowerCase(Mp3))>0) or (Pos('.mpeg',LowerCase(Mp3))>0) Then
      Begin
        Panel1.Align:=AlLeft;
        SpSkinButton13.Align:=AlBottom;
        SpSkinComboBox5.Align:=AlBottom;
        MediaPlayer21.Align:=AlClient;
        MediaPlayer21.Height:=Panel1.Height-SpSkinButton13.Height-SpSkinComboBox5.Height-3;
        SpSkinSplitter1.Visible:=True;
        SpSkinSplitter1.Left:=Panel1.Width+1;
        If Form1.OldPanelLength>=Form1.Width-20 Then
             Form1.OldPanelLength:=280;
        Panel1.Width:=Form1.OldPanelLength;
        MediaPlayer21.Width:=Panel1.Width;
        MediaPlayer21.Tag:=1;
       End;

   Try
     MediaPlayer21.Open(Mp3);
     MediaPlayer21.Play;
     Except
    End;
     //
   End;
End;

procedure TForm1.spSkinComboBox5CloseUp(Sender: TObject);
begin
 YampTrack:=SpSkinComboBox5.ItemIndex;
 PlayMp3(SpSkinComboBox5.Text);
end;

procedure TForm1.RejectMailInvites1Click(Sender: TObject);
begin
 Form1.RejectMailInvites1.Checked:=Not Form1.RejectMailInvites1.Checked;
end;

procedure TForm1.DroppedFiles(var Msg: TMessage);
Var
 Wnd: HWnd;
 Buffer: Array[0..3028] of Char;
 FileS: String;
 Bs: Integer;
begin
 Wnd:=Msg.WParam;
 Bs:=DragQueryFile(Wnd,0,Buffer,SizeOf(Buffer));
 SetLength(FileS,BS);
 FileS:=String(Buffer);
 If Form1.MediaPlayer21<>Nil Then
   Form1.PlayMp3(FileS)
    else
   Begin
     InitMp3;
     Form1.PlayMp3(FileS);
   End;
 If YampList=Nil Then
   YampList:=TStringList.Create;
 YampTrack:=0;
 YampList.Clear;
 Form1.SpSkinComboBox5.Items.Clear;
 Form1.spSkinComboBox5.Items.Add(FileS);
 Form1.SpSkinComboBOx5.Text:=ExtractFileName(FileS);
 YampList.Add(FileS);
end;

procedure TForm1.spSkinImagesMenu1ImagesItems13Click(Sender: TObject);
begin
 ShellExecute(Handle,'OPEN',Pchar('http://www.ymlitechat.com'),Pchar(''),'',SW_Show);
 Form1.Releaseanyfreememory1.OnClick(Self);
end;

procedure TForm1.ResetFlagAsBotFilter1Click(Sender: TObject);
begin
 IF MessageDlg('Are you sure you wish to reset this bot list?',MtConfirmation,[mbyes,mbno],1)=Idyes Then
  Begin
   Form1.PornBotTracker.Clear;
   TFileDownload.Create('http://ymlitechat.com/ymlite/botstrings.txt',Path+'botmergestrings.txt','80',0,Nil,False,True,True,False);
  End;
end;

procedure TForm1.YmLiteGeneralSounds1Click(Sender: TObject);
begin
  YmLiteGeneralSounds1.Checked:=Not YmLiteGeneralSounds1.Checked;
end;

procedure TForm1.YmLiteAlertSoundsBootersetc1Click(Sender: TObject);
begin
 YmLiteAlertSoundsBootersetc1.Checked:=Not YmLiteAlertSoundsBootersetc1.Checked;
end;

procedure TForm1.ViewDownloadsDirectory1Click(Sender: TObject);
begin
If DirectoryExists(Path+'downloads')=False Then
  CreateDir(Path+'downloads');
 WinExec(Pchar('explorer '+Path+'downloads'),sw_normal);
end;

procedure TForm1.RoomInitP(S: String);
begin

end;

procedure TForm1.spSkinButton1Click(Sender: TObject);
begin
 Form14.Obj:=Richedit2;
 Form14.Show;
end;



procedure TForm1.EyeDisconnect(DisconnectMsg: String);
begin
 Form1.Richedit1.Lines.Add('Eye Disconnected');
end;

procedure TForm1.EyeLoginSuccess(Sender: TObject);
begin
 Form1.Richedit1.Lines.Add('Eye Login Success...');
end;

procedure TForm1.TraverseMethList(UserData: Pointer; const Value: string;
  Data: TObject; var Done: Boolean);
Var
  Lb: TSpSkinCustomListBox;
begin
 Lb:=TSpSkinCustomListBox(UserData);
 Lb.Items.Add(String(Value));
end;

procedure TForm1.TraverseMeth(UserData: Pointer; const Value: string;
  Data: TObject; var Done: Boolean);
type
  PTextFile = ^TextFile;
begin
  writeln(PTextFile(UserData)^,Value);
end;

{ TGetAlphaCode }

constructor TGetAlphaCode.Create(Url: String; Send: Boolean; KeyStr: String);
begin
 HttpStr:=Url;
 FSend:=Send;
 FKeyStr:=KeyStr;
 Self.FreeOnTerminate:=True;
 Socket:=TDCBSock.Create(Nil);
 Inherited Create(false)
end;

Procedure TGetAlphaCode.GetCode;
Var
 S: String;
 Buff: String;
 Abytes,Pr,Br: Integer;
 Tmp: String;
 Img: string;
 F: File;
 Res: Integer;
begin
 Img:=Tmp;
// System.Assign(F,path+'tmpcaptchaimg.jpg');
// System.Rewrite(F,1);
 Tmp:=HttpStr;
 Delete(Tmp,1,posrep('/img/',Tmp)+4);
 Img:=Copy(Tmp,1,pos('.jpg',tmp)+3);
 Tmp:='GET /img/'+Img+#$0d+#$0a+'HTTP/1.0'+#$0D+#$0A+'Host: ab.login.yahoo.com'+#$0D+#$0A+'Accept-Language: en'+#$0D+#$0A+'Accept: */*'+#$0D+#$0A+'User-Agent: Mozilla/4.0 (compatible; Y!mLite) '+#$0D+#$0A+'Cache-Control: no-cache'+#$0D+#$0A+'Connection: close'+#$0D+#$0A+'Referer: http://ab.login.yahoo.com'+#$0D+#$0A+#$0D+#$0A;

 //'http://captcha.chat.yahoo.com/go/captchat/?img=http://ab.login.yahoo.com/img/YsF0HuVZFell7J0RVcDarXLJ8nr3pU8Xm3MqLu45Pq37noteVA.05vYkuGgK4nI5yZO2Epx6gimI3TmZ.jpg&.intl=us'
// Socket.RemoteHost:='captcha.chat.yahoo.com';
 Socket.RemoteHost:='ab.login.yahoo.com';
 Socket.RemotePort:='80';
 Socket.Connect;
 Socket.Sendln(Tmp);
 Form1.MyJpg.Clear;
  SetLength(Buff,1500);
//  Buff:='E4'+#$F2+#$C1+#$11+'$:w'+#$02+#$EE+#$BF+' '+#$07+#$EC+#$B2+#$A7+#$B2+'Z'+#$EA+'k}'+#$B6+'{}4'+#$B5+'Z'+#$E5+#$F1+'_'+#$10+'.'+#$D7+#$A6+#$CA+#$CE+'kZ'+#$C6+#$86+#$B4+#$00+#$D1+#$D0+#$00+':'+#$05+#$F5+#$11+'|sC'+#$9A+'Z'+#$E0+#$08+'='+#$08+'>k'+#$C2+#$9A+#$82+#$8E+#$8B+#$9B+#$D9+'i '+#$83+#$98+#$ED+#$DE+#$14+'a'+#$BB+#$F9+#$E8+','+#$84+'DDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDEConnection: close'+#$0D+#$0A+#$FF+#$D9;
  While (Socket.WaitForData(100000)) and (Socket.Connected) and (Exiting=False) Do
      Begin
        Br:=Socket.ReceiveBuf(Buff[1],Length(Buff));
        Pr:=PosRep('Connection: close',Buff);
        If Pr>0 Then
         Begin
           Buff:=Form1.RemoveStr('Connection: close'+#$0D+#$0A,Buff);
           Form1.MyJpg.WriteBuffer(Buff[1],Length(Buff));
         End
          else
        Form1.MyJpg.WriteBuffer(Buff[1],Br);

       End;
//     OnDisconnect;
    Socket.Disconnect;
    SendMessage(Form1.Handle,Wm_User+115,0,0);
End;


Procedure TGetAlphaCode.SendCode;
Var
 S: String;
 Br: Integer;
 Img,Tmp: String;
 Answer,Question: String;
begin
 Tmp:=HttpStr;
 Delete(Tmp,1,posrep('/img/',Tmp)+4);
 Img:=Copy(Tmp,1,pos('.jpg',tmp)+3); //done

 Answer:='question=http%3A//ab.login.yahoo.com/img/'+Img+'&.intl=us&answer='+FkeyStr;
 Question:='POST /captcha1 HTTP/1.0'+#$0D+#$0A+'Host: captchaes1.chat.dcn.yahoo.com'+#$0D+#$0A+'Accept-Language: en'+#$0D+#$0A+'Accept: */*'+#$0D+#$0A+'User-Agent: Mozilla/4.0 (compatible; Y!mLite) '+#$0D+#$0A+'Cache-Control: no-cache'+#$0D+#$0A+'Connection: close'+#$0D+#$0A+'Referer: http://captchaes1.chat.dcn.yahoo.com'+#$0D+#$0A+'Content-Type: application/x-www-form-urlencoded'+#$0D+#$0A+'Content-Length: '+IntToStr(Length(Answer))+#$0D+#$0A+#$0D+#$0A;

 Tmp:=HttpStr;
 Delete(Tmp,1,posrep('/img/',Tmp)+4);
 Tmp:='GET /img/'+Img+#$0d+#$0a+'HTTP/1.0'+#$0D+#$0A+'Host: ab.login.yahoo.com'+#$0D+#$0A+'Accept-Language: en'+#$0D+#$0A+'Accept: */*'+#$0D+#$0A+'User-Agent: Mozilla/4.0 (compatible; Y!mLite) '+#$0D+#$0A+'Cache-Control: no-cache'+#$0D+#$0A+'Connection: close'+#$0D+#$0A+'Referer: http://ab.login.yahoo.com'+#$0D+#$0A+#$0D+#$0A;

 //'http://captcha.chat.yahoo.com/go/captchat/?img=http://ab.login.yahoo.com/img/YsF0HuVZFell7J0RVcDarXLJ8nr3pU8Xm3MqLu45Pq37noteVA.05vYkuGgK4nI5yZO2Epx6gimI3TmZ.jpg&.intl=us'
// Socket.RemoteHost:='captcha.chat.yahoo.com';
 Socket.RemoteHost:='captchaes1.chat.dcn.yahoo.com';
 Socket.RemotePort:='80';
 Socket.Connect;
 Socket.Sendln(Question);
 Sleep(50);
 Socket.Sendln(Answer);
// Socket.BytesReceived
   While (Socket.WaitForData(10000)) Do
      Begin
        S:=Socket.Receiveln;
        BR:=Socket.BytesReceived;
        Data:=Data+S;
//        Form1.Panel10.Caption:='Connected reading data in... '+IntToStr(Length(Data))+' Bytes... ';
       End;

    Socket.Disconnect;
{    Socket.Free;
    Socket:=Nil;}
//     OnDisconnect;
   If Copy(Data,1,12)='HTTP/1.1 301' Then
    Begin
     Tmp:=Data;
     IF Pos('?tryagain',tmp)>0 Then
      Begin
      //<A HREF="http://captcha.chat.yahoo.com/go/captchat/?tryagain=1&amp;img=http://ab.login.yahoo.com/img/tcUpuuVZFenJDRg4jq8cVgKfN4IBp84XLcF0HJ.kWbcudM.YQJh89VQug7O5vrfDY6w4.MxOiENqOBC0T2kzmX15KV19ng--.jpg&amp;.i
      //str 'http://captcha.chat.yahoo.com/go/captchat/?img=http://ab.login.yahoo.com/img/AhYfB.VZFekBnW.GlE7sCgNgBYOzAVEkSEOaetLB30KF_8ZvieiUZKhWqcvOzHApXDi9ybSlUcQ5oN9I925T43csCFMJyg--.jpg&.intl=us'
      //normal
      //'http://captcha.chat.yahoo.com/go/captchat/?img=http://ab.login.yahoo.com/img/5KjUdeVZFem4FAqCDulNsi000U5ue4MV_9Lgg7Gbo9SvH14bjESy_.Upgi3uQRHlAprfoLR7UPxlu4.RcnArWYyNI35PXus-.jpg&.intl=us'
      Form1.CaptchaImageStr:=Form1.ExtractBetweenString('HREF="','">',tmp,True);
       Form1.CaptchaImageStr:=Form1.RemoveStr('tryagain=1&amp;',Form1.CaptchaImageStr);
      //tryagain=1&amp;
//      Delete(Form1.CaptchaImageStr,1,PosRep('img=',Form1.CaptchaImageStr)+3);
          Delete(Tmp,1,posrep('img=',Tmp)+3);
          If Pos('?tryagain',tmp)>0 Then
           Delete(Tmp,1,posrep('img=',Tmp)+3);

         Tmp:=Form1.GetURL(tmp,False);
         Delete(Tmp,1,PosRep('/img/',tmp)+4);
         Tmp:=Copy(Tmp,1,PosRep('.jpg',Tmp)+3);
      //CaptchaImageStr
         Form1.CaptchaImg:=Tmp;
       //  SendMessage(Form1.Handle,Wm_User+115,0,0);
         SendMessage(Form1.Handle,Wm_User+115,0,2);

       End;
     End;


End;

procedure TGetAlphaCode.Execute;
Begin
  If FSend=False Then
   GetCode;
  If FSend=True Then
    SendCode;
end;

procedure TForm1.AlphaNotifcation(var Msg: Tmessage);
Var
 TheJpg: TCustomJPEGImage;
begin
//FormCaptcha.image1.picture:=Nil;
 TheJpg:=TCustomJPEGImage.Create(self);
 If Msg.Lparam=0 Then
  Begin
   FormCaptcha.Show;
   TheJpg.LoadFromStream(MyJpg);

//   FormCaptcha.Image1.Canvas.Draw(1,1,TGraphic(TheJpg));
  FormCaptcha.Image1.LoadFromStream(MyJpg);
  End;

//  FormCaptcha.image1.canvas.Draw(1,1,MyJPG.);

 If Msg.Lparam=1 Then
  Begin
   Form1.Richedit1.Lines.add('Verification Code Sent...');
  End;

 If Msg.Lparam=2 Then
  Begin
    FormCaptcha.Show;
    GetAlphaCode(Form1.CaptchaImageStr);
//    TGetAlphaCode.Create(Form1.CaptchaImg,False,'');
  End;

 TheJpg.Free;
end;

procedure TForm1.GotoUser2Click(Sender: TObject);
begin
 //Form1.Say(Form1.Richedit1,yRed+'Attempting to goto '+YBlue+Cut+YBlack+'... ',False,True,False);
   Form1.Richedit1.Lines.Add('Attempting to goto '+Form27.ListBox1.Items[Form27.ListBox1.ItemIndex]);
   Form1.Invite(Form27.ListBox1.Items[Form27.ListBox1.ItemIndex],False,True,False);
   Cut:='';
end;

End.