PageRenderTime 87ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 2ms

/Forms/FormMain.cs

https://github.com/SkyFire/icechat
C# | 5902 lines | 4742 code | 622 blank | 538 comment | 1083 complexity | 8ee8a60ee574ed4551d6a56ec918084b MD5 | raw file
Possible License(s): AGPL-1.0
  1. /******************************************************************************\
  2. * IceChat 9 Internet Relay Chat Client
  3. *
  4. * Copyright (C) 2011 Paul Vanderzee <snerf@icechat.net>
  5. * <www.icechat.net>
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2, or (at your option)
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  19. *
  20. * Please consult the LICENSE.txt file included with this project for
  21. * more details
  22. *
  23. \******************************************************************************/
  24. using System;
  25. using System.Collections.Generic;
  26. using System.Collections;
  27. using System.ComponentModel;
  28. using System.Data;
  29. using System.Drawing.Drawing2D;
  30. using System.Drawing;
  31. using System.Text;
  32. using System.Text.RegularExpressions;
  33. using System.Windows.Forms;
  34. using System.Xml.Serialization;
  35. using System.IO;
  36. using System.Reflection;
  37. using System.Runtime.InteropServices;
  38. using IceChatPlugin;
  39. namespace IceChat
  40. {
  41. public partial class FormMain : Form
  42. {
  43. public static FormMain Instance;
  44. private string optionsFile;
  45. private string messagesFile;
  46. private string fontsFile;
  47. private string colorsFile;
  48. private string soundsFile;
  49. private string favoriteChannelsFile;
  50. private string serversFile;
  51. private string aliasesFile;
  52. private string popupsFile;
  53. private string pluginsFile;
  54. private string currentFolder;
  55. private string logsFolder;
  56. private string pluginsFolder;
  57. private string emoticonsFile;
  58. private string scriptsFolder;
  59. private string soundsFolder;
  60. private string picturesFolder;
  61. private List<LanguageItem> languageFiles;
  62. private LanguageItem currentLanguageFile;
  63. private StreamWriter errorFile;
  64. private IceChatOptions iceChatOptions;
  65. private IceChatColors iceChatColors;
  66. private IceChatMessageFormat iceChatMessages;
  67. private IceChatFontSetting iceChatFonts;
  68. private IceChatAliases iceChatAliases;
  69. private IceChatPopupMenus iceChatPopups;
  70. private IceChatEmoticon iceChatEmoticons;
  71. private IceChatLanguage iceChatLanguage;
  72. private IceChatSounds iceChatSounds;
  73. private IceChatPluginFile iceChatPlugins;
  74. //private System.Threading.Mutex mutex;
  75. private List<IPluginIceChat> loadedPlugins;
  76. private IdentServer identServer;
  77. private TabPage nickListTab;
  78. private TabPage serverListTab;
  79. private TabPage channelListTab;
  80. private TabPage buddyListTab;
  81. private delegate IceTabPage AddWindowDelegate(IRCConnection connection, string windowName, IceTabPage.WindowType windowType);
  82. private delegate void CurrentWindowDelegate(string data, int color);
  83. private delegate void WindowMessageDelegate(IRCConnection connection, string name, string data, int color, bool scrollToBottom);
  84. private delegate void CurrentWindowMessageDelegate(IRCConnection connection, string data, int color, bool scrollToBottom);
  85. private System.Timers.Timer flashTrayIconTimer;
  86. private int flashTrayCount;
  87. private System.Timers.Timer flashTaskBarIconTimer;
  88. private int flashTaskBarCount;
  89. private System.Media.SoundPlayer player;
  90. private bool muteAllSounds;
  91. [StructLayout(LayoutKind.Sequential)]
  92. private struct OSVERSIONINFOEX
  93. {
  94. public int dwOSVersionInfoSize;
  95. public int dwMajorVersion;
  96. public int dwMinorVersion;
  97. public int dwBuildNumber;
  98. public int dwPlatformId;
  99. [MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
  100. public string szCSDVersion;
  101. public short wServicePackMajor;
  102. public short wServicePackMinor;
  103. public short wSuiteMask;
  104. public byte wProductType;
  105. public byte wReserved;
  106. }
  107. [DllImport("kernel32.dll")]
  108. private static extern bool GetVersionEx(ref OSVERSIONINFOEX osVersionInfo);
  109. private const int VER_NT_WORKSTATION = 1;
  110. private const int VER_NT_DOMAIN_CONTROLLER = 2;
  111. private const int VER_NT_SERVER = 3;
  112. private const int VER_SUITE_SMALLBUSINESS = 1;
  113. private const int VER_SUITE_ENTERPRISE = 2;
  114. private const int VER_SUITE_TERMINAL = 16;
  115. private const int VER_SUITE_DATACENTER = 128;
  116. private const int VER_SUITE_SINGLEUSERTS = 256;
  117. private const int VER_SUITE_PERSONAL = 512;
  118. private const int VER_SUITE_BLADE = 1024;
  119. public const string ProgramID = "IceChat 9";
  120. public const string VersionID = "Release Candidate 2.5";
  121. /// <summary>
  122. /// All the Window Message Types used for Coloring the Tab Text for Different Events
  123. /// </summary>
  124. internal enum ServerMessageType
  125. {
  126. Default = 0,
  127. Message = 1,
  128. Action = 2,
  129. JoinChannel = 3,
  130. PartChannel = 4,
  131. QuitServer = 5,
  132. ServerMessage = 6,
  133. Other = 7
  134. }
  135. public FormMain(string[] args, Form splash)
  136. {
  137. FormMain.Instance = this;
  138. player = new System.Media.SoundPlayer();
  139. bool forceCurrentFolder = false;
  140. if (args.Length > 0)
  141. {
  142. string prevArg = "";
  143. foreach (string arg in args)
  144. {
  145. if (prevArg.Length == 0)
  146. prevArg = arg;
  147. else
  148. {
  149. switch (prevArg.ToLower())
  150. {
  151. case "-profile":
  152. currentFolder = arg;
  153. //check if the folder exists, ir not, create it
  154. if (!Directory.Exists(currentFolder))
  155. Directory.CreateDirectory(currentFolder);
  156. forceCurrentFolder = true;
  157. break;
  158. }
  159. prevArg = "";
  160. }
  161. }
  162. }
  163. //mutex = new System.Threading.Mutex(true, "IceChatMutex");
  164. #region Settings Files
  165. //check if the xml settings files exist in current folder
  166. if (currentFolder == null)
  167. currentFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
  168. if (!File.Exists(currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatServer.xml") && !forceCurrentFolder)
  169. {
  170. if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + Path.DirectorySeparatorChar + "IceChat Networks" + Path.DirectorySeparatorChar + "IceChat"))
  171. Directory.CreateDirectory(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + Path.DirectorySeparatorChar + "IceChat Networks" + Path.DirectorySeparatorChar + "IceChat");
  172. currentFolder = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + Path.DirectorySeparatorChar + "IceChat Networks" + Path.DirectorySeparatorChar + "IceChat";
  173. }
  174. //load all files from the Local AppData folder, unless it exist in the current folder
  175. serversFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatServer.xml";
  176. optionsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatOptions.xml";
  177. messagesFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatMessages.xml";
  178. fontsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatFonts.xml";
  179. colorsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatColors.xml";
  180. soundsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatSounds.xml";
  181. favoriteChannelsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatChannels.xml";
  182. aliasesFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatAliases.xml";
  183. popupsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatPopups.xml";
  184. pluginsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "IceChatPlugins.xml";
  185. emoticonsFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "Emoticons" + System.IO.Path.DirectorySeparatorChar + "IceChatEmoticons.xml";
  186. logsFolder = currentFolder + System.IO.Path.DirectorySeparatorChar + "Logs";
  187. scriptsFolder = currentFolder + System.IO.Path.DirectorySeparatorChar + "Scripts";
  188. soundsFolder = currentFolder + System.IO.Path.DirectorySeparatorChar + "Sounds";
  189. picturesFolder = currentFolder + System.IO.Path.DirectorySeparatorChar + "Pictures";
  190. //pluginsFolder = currentFolder + System.IO.Path.DirectorySeparatorChar + "Plugins";
  191. pluginsFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + System.IO.Path.DirectorySeparatorChar + "Plugins";
  192. //pluginsFolder = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location);
  193. if (!Directory.Exists(pluginsFolder))
  194. Directory.CreateDirectory(pluginsFolder);
  195. if (!Directory.Exists(scriptsFolder))
  196. Directory.CreateDirectory(scriptsFolder);
  197. if (!Directory.Exists(soundsFolder))
  198. Directory.CreateDirectory(soundsFolder);
  199. if (!Directory.Exists(picturesFolder))
  200. Directory.CreateDirectory(picturesFolder);
  201. #endregion
  202. languageFiles = new List<LanguageItem>();
  203. DirectoryInfo languageDirectory = null;
  204. languageDirectory = new DirectoryInfo(currentFolder + System.IO.Path.DirectorySeparatorChar + "Languages");
  205. if (!Directory.Exists(currentFolder + System.IO.Path.DirectorySeparatorChar + "Languages"))
  206. Directory.CreateDirectory(currentFolder + System.IO.Path.DirectorySeparatorChar + "Languages");
  207. if (languageDirectory != null)
  208. {
  209. // scan the language directory for xml files and make LanguageItems for each file
  210. FileInfo[] langFiles = languageDirectory.GetFiles("*.xml");
  211. foreach (FileInfo fi in langFiles)
  212. {
  213. string langFile = languageDirectory.FullName + System.IO.Path.DirectorySeparatorChar + fi.Name;
  214. LanguageItem languageItem = LoadLanguageItem(langFile);
  215. if (languageItem != null) languageFiles.Add(languageItem);
  216. }
  217. if (languageFiles.Count == 0)
  218. {
  219. currentLanguageFile = new LanguageItem();
  220. languageFiles.Add(currentLanguageFile); // default language English
  221. }
  222. }
  223. LoadOptions();
  224. LoadColors();
  225. LoadSounds();
  226. // use the language saved in options if availlable,
  227. // if not (e.g. user deleted xml file) default is used
  228. foreach (LanguageItem li in languageFiles)
  229. {
  230. if (li.LanguageName == iceChatOptions.Language)
  231. {
  232. currentLanguageFile = li;
  233. break;
  234. }
  235. }
  236. LoadLanguage(); // The language class MUST be loaded before any GUI component is created
  237. //check if we have any servers/settings saved, if not, load firstrun
  238. if (!File.Exists(serversFile))
  239. {
  240. FormFirstRun firstRun = new FormFirstRun(currentFolder);
  241. firstRun.ShowDialog(this);
  242. }
  243. InitializeComponent();
  244. //load icons from Embedded Resources
  245. this.toolStripQuickConnect.Image = StaticMethods.LoadResourceImage("quick.png");
  246. this.toolStripSettings.Image = StaticMethods.LoadResourceImage("settings.png");
  247. this.toolStripColors.Image = StaticMethods.LoadResourceImage("colors.png");
  248. this.toolStripEditor.Image = StaticMethods.LoadResourceImage("editor.png");
  249. this.toolStripAway.Image = StaticMethods.LoadResourceImage("away.png");
  250. this.toolStripSystemTray.Image = StaticMethods.LoadResourceImage("system-tray.png");
  251. this.toolStripUpdate.Image = StaticMethods.LoadResourceImage("update.png");
  252. //disable this by default
  253. this.toolStripUpdate.Visible = false;
  254. this.minimizeToTrayToolStripMenuItem.Image = StaticMethods.LoadResourceImage("new-tray-icon.ico");
  255. this.debugWindowToolStripMenuItem.Image = StaticMethods.LoadResourceImage("window-icon.ico");
  256. this.exitToolStripMenuItem.Image = StaticMethods.LoadResourceImage("disconected.png");
  257. this.iceChatSettingsToolStripMenuItem.Image = StaticMethods.LoadResourceImage("settings.png");
  258. this.iceChatColorsToolStripMenuItem.Image = StaticMethods.LoadResourceImage("colors.png");
  259. this.iceChatEditorToolStripMenuItem.Image = StaticMethods.LoadResourceImage("editormenu.png");
  260. this.codePlexPageToolStripMenuItem.Image = StaticMethods.LoadResourceImage("codeplex.ico");
  261. this.forumsToolStripMenuItem.Image = StaticMethods.LoadResourceImage("smf.ico");
  262. this.facebookFanPageToolStripMenuItem.Image = StaticMethods.LoadResourceImage("facebook.png");
  263. this.checkForUpdateToolStripMenuItem.Image = StaticMethods.LoadResourceImage("update-menu.png");
  264. this.iceChatHomePageToolStripMenuItem.Image = StaticMethods.LoadResourceImage("home.png");
  265. this.downloadPluginsToolStripMenuItem.Image = StaticMethods.LoadResourceImage("plug-icon.png");
  266. this.pluginsToolStripMenuItem.Image = StaticMethods.LoadResourceImage("plug-icon.png");
  267. //this.muteAllSoundsToolStripMenuItem.Image = StaticMethods.LoadResourceImage("mute.png");
  268. //this.browseDataFolderToolStripMenuItem.Image = StaticMethods.LoadResourceImage("folder.ico");
  269. this.notifyIcon.Icon = System.Drawing.Icon.FromHandle(StaticMethods.LoadResourceImage("new-tray-icon.ico").GetHicon());
  270. this.Icon = System.Drawing.Icon.FromHandle(StaticMethods.LoadResourceImage("new-tray-icon.ico").GetHicon());
  271. this.toolStripMain.VisibleChanged += new EventHandler(toolStripMain_VisibleChanged);
  272. serverListToolStripMenuItem.Checked = iceChatOptions.ShowServerTree;
  273. panelDockLeft.Visible = serverListToolStripMenuItem.Checked;
  274. splitterLeft.Visible = serverListToolStripMenuItem.Checked;
  275. nickListToolStripMenuItem.Checked = iceChatOptions.ShowNickList;
  276. panelDockRight.Visible = nickListToolStripMenuItem.Checked;
  277. splitterRight.Visible = nickListToolStripMenuItem.Checked;
  278. statusBarToolStripMenuItem.Checked = iceChatOptions.ShowStatusBar;
  279. statusStripMain.Visible = statusBarToolStripMenuItem.Checked;
  280. toolBarToolStripMenuItem.Checked = iceChatOptions.ShowToolBar;
  281. toolStripMain.Visible = toolBarToolStripMenuItem.Checked;
  282. serverTree = new ServerTree();
  283. serverTree.Dock = DockStyle.Fill;
  284. this.Text = ProgramID + " :: " + VersionID + " :: September 14 2011";
  285. this.notifyIcon.Text = ProgramID + " :: " + VersionID;
  286. if (!Directory.Exists(logsFolder))
  287. Directory.CreateDirectory(logsFolder);
  288. try
  289. {
  290. errorFile = new StreamWriter(logsFolder + System.IO.Path.DirectorySeparatorChar + "errors.log");
  291. }
  292. catch (IOException io)
  293. {
  294. System.Diagnostics.Debug.WriteLine("Can not create errors.log:" + io.Message);
  295. }
  296. if (!iceChatOptions.TimeStamp.EndsWith(" "))
  297. iceChatOptions.TimeStamp += " ";
  298. if (iceChatOptions.WindowSize != null)
  299. {
  300. if (iceChatOptions.WindowSize.Width != 0)
  301. this.Size = iceChatOptions.WindowSize;
  302. else
  303. {
  304. Rectangle r = System.Windows.Forms.Screen.PrimaryScreen.WorkingArea;
  305. this.Width = r.Width;
  306. this.Height = r.Height;
  307. }
  308. }
  309. if (iceChatOptions.WindowLocation != null)
  310. this.Location = iceChatOptions.WindowLocation;
  311. statusStripMain.Visible = iceChatOptions.ShowStatusBar;
  312. inputPanel.ShowColorPicker = iceChatOptions.ShowColorPicker;
  313. inputPanel.ShowEmoticonPicker = iceChatOptions.ShowEmoticonPicker;
  314. inputPanel.ShowSearchPanel = false;
  315. LoadAliases();
  316. LoadPopups();
  317. LoadEmoticons();
  318. LoadMessageFormat();
  319. LoadFonts();
  320. if (iceChatOptions.CurrentTheme == null)
  321. iceChatOptions.CurrentTheme = "Default";
  322. else
  323. {
  324. //load in the new color theme, if it not Default
  325. if (iceChatOptions.CurrentTheme != "Default")
  326. {
  327. string themeFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "Colors-" + iceChatOptions.CurrentTheme + ".xml";
  328. if (File.Exists(themeFile))
  329. {
  330. XmlSerializer deserializer = new XmlSerializer(typeof(IceChatColors));
  331. TextReader textReader = new StreamReader(themeFile);
  332. iceChatColors = (IceChatColors)deserializer.Deserialize(textReader);
  333. textReader.Close();
  334. textReader.Dispose();
  335. colorsFile = themeFile;
  336. }
  337. else
  338. {
  339. System.Diagnostics.Debug.WriteLine("Color Theme File not found:" + themeFile);
  340. }
  341. themeFile = currentFolder + System.IO.Path.DirectorySeparatorChar + "Messages-" + iceChatOptions.CurrentTheme + ".xml";
  342. if (File.Exists(themeFile))
  343. {
  344. XmlSerializer deserializer = new XmlSerializer(typeof(IceChatMessageFormat));
  345. TextReader textReader = new StreamReader(themeFile);
  346. iceChatMessages = (IceChatMessageFormat)deserializer.Deserialize(textReader);
  347. textReader.Close();
  348. textReader.Dispose();
  349. messagesFile = themeFile;
  350. }
  351. else
  352. {
  353. System.Diagnostics.Debug.WriteLine("Messages Theme File not found:" + themeFile);
  354. }
  355. }
  356. }
  357. if (iceChatOptions.Themes == null)
  358. {
  359. iceChatOptions.Themes = new string[1];
  360. iceChatOptions.Themes[0] = "Default";
  361. }
  362. channelList = new ChannelList();
  363. channelList.Dock = DockStyle.Fill;
  364. buddyList = new BuddyList();
  365. buddyList.Dock = DockStyle.Fill;
  366. toolStripMain.BackColor = IrcColor.colors[iceChatColors.ToolbarBackColor];
  367. menuMainStrip.BackColor = IrcColor.colors[iceChatColors.MenubarBackColor];
  368. statusStripMain.BackColor = IrcColor.colors[iceChatColors.StatusbarBackColor];
  369. toolStripStatus.ForeColor = IrcColor.colors[iceChatColors.StatusbarForeColor];
  370. inputPanel.SetInputBoxColors();
  371. channelList.SetListColors();
  372. buddyList.SetListColors();
  373. nickList = new NickList();
  374. nickList.Header = iceChatLanguage.consoleTabTitle;
  375. nickList.Dock = DockStyle.Fill;
  376. serverListTab = new TabPage("Favorite Servers");
  377. Panel serverPanel = new Panel();
  378. serverPanel.Dock = DockStyle.Fill;
  379. serverPanel.Controls.Add(serverTree);
  380. serverListTab.Controls.Add(serverPanel);
  381. serverListTab.BackColor = IrcColor.colors[iceChatColors.PanelHeaderBG1];
  382. serverListTab.ForeColor = IrcColor.colors[iceChatColors.PanelHeaderForeColor];
  383. this.panelDockLeft.TabControl.TabPages.Add(serverListTab);
  384. nickListTab = new TabPage("Nick List");
  385. Panel nickPanel = new Panel();
  386. nickPanel.Dock = DockStyle.Fill;
  387. nickPanel.Controls.Add(nickList);
  388. nickListTab.Controls.Add(nickPanel);
  389. nickListTab.BackColor = IrcColor.colors[iceChatColors.PanelHeaderBG1];
  390. nickListTab.ForeColor = IrcColor.colors[iceChatColors.PanelHeaderForeColor];
  391. this.panelDockRight.TabControl.TabPages.Add(nickListTab);
  392. channelListTab = new TabPage("Favorite Channels");
  393. Panel channelPanel = new Panel();
  394. channelPanel.Dock = DockStyle.Fill;
  395. channelPanel.Controls.Add(channelList);
  396. channelListTab.Controls.Add(channelPanel);
  397. channelListTab.BackColor = IrcColor.colors[iceChatColors.PanelHeaderBG1];
  398. channelListTab.ForeColor = IrcColor.colors[iceChatColors.PanelHeaderForeColor];
  399. this.panelDockRight.TabControl.TabPages.Add(channelListTab);
  400. buddyListTab = new TabPage("Buddy List");
  401. Panel buddyPanel = new Panel();
  402. buddyPanel.Dock = DockStyle.Fill;
  403. buddyPanel.Controls.Add(buddyList);
  404. buddyListTab.Controls.Add(buddyPanel);
  405. buddyListTab.BackColor = IrcColor.colors[iceChatColors.PanelHeaderBG1];
  406. buddyListTab.ForeColor = IrcColor.colors[iceChatColors.PanelHeaderForeColor];
  407. this.panelDockRight.TabControl.TabPages.Add(buddyListTab);
  408. panelDockLeft.Width = iceChatOptions.LeftPanelWidth;
  409. panelDockLeft.TabControl.Alignment = TabAlignment.Left;
  410. panelDockRight.Width = iceChatOptions.RightPanelWidth;
  411. panelDockRight.TabControl.Alignment = TabAlignment.Right;
  412. nickList.Font = new Font(iceChatFonts.FontSettings[3].FontName, iceChatFonts.FontSettings[3].FontSize);
  413. serverTree.Font = new Font(iceChatFonts.FontSettings[4].FontName, iceChatFonts.FontSettings[4].FontSize);
  414. inputPanel.OnCommand +=new InputPanel.OnCommandDelegate(inputPanel_OnCommand);
  415. inputPanel.InputBoxFont = new Font(iceChatFonts.FontSettings[5].FontName, iceChatFonts.FontSettings[5].FontSize);
  416. mainTabControl.SelectedIndexChanged += new IceTabControl.TabEventHandler(TabSelectedIndexChanged);
  417. mainTabControl.OnTabClosed += new IceTabControl.TabClosedDelegate(mainTabControl_OnTabClosed);
  418. panelDockLeft.Initialize();
  419. panelDockRight.Initialize();
  420. //menuMainStrip.Font = new Font(iceChatFonts.FontSettings[7].FontName, iceChatFonts.FontSettings[7].FontSize);
  421. serverTree.NewServerConnection += new NewServerConnectionDelegate(NewServerConnection);
  422. serverTree.SaveDefault += new ServerTree.SaveDefaultDelegate(OnDefaultServerSettings);
  423. CreateDefaultConsoleWindow();
  424. this.FormClosing += new FormClosingEventHandler(FormMainClosing);
  425. this.Resize += new EventHandler(FormMainResize);
  426. if (iceChatOptions.IdentServer)
  427. identServer = new IdentServer();
  428. loadedPlugins = new List<IPluginIceChat>();
  429. if (iceChatLanguage.LanguageName != "English") ApplyLanguage(); // ApplyLanguage can first be called after all child controls are created
  430. WindowMessage(null, "Console", "Data Folder: " + currentFolder, 4, true);
  431. WindowMessage(null, "Console", "Plugins Folder: " + pluginsFolder, 4, true);
  432. //check for an update
  433. System.Threading.Thread checkThread = new System.Threading.Thread(checkForUpdate);
  434. checkThread.Name = "CheckUpdateThread";
  435. checkThread.Start();
  436. //check for router ip
  437. if (iceChatOptions.DCCLocalIP == null || iceChatOptions.DCCLocalIP.Length == 0)
  438. {
  439. System.Threading.Thread thread = new System.Threading.Thread(getLocalIPAddress);
  440. thread.Name = "DCCIP";
  441. thread.Start();
  442. }
  443. splash.Close();
  444. splash.Dispose();
  445. //load any plugin addons
  446. LoadPlugins();
  447. //load the plugin settings file
  448. LoadPluginFiles();
  449. //set any plugins as disabled
  450. //add any items top the pluginsFile if they do not exist, or remove any that do not
  451. foreach (IPluginIceChat ipc in FormMain.Instance.IceChatPlugins)
  452. {
  453. bool found = false;
  454. for (int i = 0; i < iceChatPlugins.listPlugins.Count; i++)
  455. {
  456. if (iceChatPlugins.listPlugins[i].PluginFile.Equals(ipc.FileName))
  457. {
  458. found = true;
  459. //check if the plugin is enabled or not
  460. if (iceChatPlugins.listPlugins[i].Enabled == false)
  461. {
  462. WindowMessage(null, "Console", "Disabled Plugin - " + ipc.Name + " v" + ipc.Version, 4, true);
  463. foreach (ToolStripMenuItem t in pluginsToolStripMenuItem.DropDownItems)
  464. if (t.ToolTipText.ToLower() == ipc.FileName.ToLower())
  465. t.Image = StaticMethods.LoadResourceImage("CloseButton.png");
  466. ipc.Enabled = false;
  467. }
  468. }
  469. }
  470. if (found == false)
  471. {
  472. //plugin file not found in plugin Items file, add it
  473. PluginItem item = new PluginItem();
  474. item.Enabled = true;
  475. item.PluginFile = ipc.FileName;
  476. iceChatPlugins.AddPlugin(item);
  477. SavePluginFiles();
  478. }
  479. //fire the event that the program has fully loaded
  480. if (ipc.Enabled == true)
  481. ipc.MainProgramLoaded();
  482. }
  483. if (iceChatPlugins.listPlugins.Count != loadedPlugins.Count)
  484. {
  485. //find the file that is missing
  486. List<int> removeItems = new List<int>();
  487. for (int i = 0; i < iceChatPlugins.listPlugins.Count; i++)
  488. {
  489. bool found = false;
  490. foreach (IPluginIceChat ipc in FormMain.Instance.IceChatPlugins)
  491. {
  492. if (iceChatPlugins.listPlugins[i].PluginFile.Equals(ipc.FileName))
  493. found = true;
  494. }
  495. if (found == false)
  496. removeItems.Add(i);
  497. }
  498. if (removeItems.Count > 0)
  499. {
  500. try
  501. {
  502. foreach (int i in removeItems)
  503. iceChatPlugins.listPlugins.Remove(iceChatPlugins.listPlugins[i]);
  504. }
  505. catch { }
  506. SavePluginFiles();
  507. }
  508. }
  509. this.Activated += new EventHandler(FormMainActivated);
  510. nickList.ShowNickButtons = iceChatOptions.ShowNickButtons;
  511. serverTree.ShowServerButtons = iceChatOptions.ShowServerButtons;
  512. this.flashTrayIconTimer = new System.Timers.Timer(2000);
  513. this.flashTrayIconTimer.Enabled = false;
  514. this.flashTrayIconTimer.Elapsed += new System.Timers.ElapsedEventHandler(flashTrayIconTimer_Elapsed);
  515. this.notifyIcon.Tag = "off";
  516. this.flashTrayCount = 0;
  517. this.flashTaskBarIconTimer = new System.Timers.Timer(2000);
  518. this.flashTaskBarIconTimer.Enabled = false;
  519. this.flashTaskBarIconTimer.Elapsed += new System.Timers.ElapsedEventHandler(flashTaskBarIconTimer_Elapsed);
  520. this.Tag = "off";
  521. this.flashTrayCount = 0;
  522. ToolStripMenuItem closeWindow = new ToolStripMenuItem(StaticMethods.LoadResourceImage("CloseButton.png"));
  523. closeWindow.Alignment = ToolStripItemAlignment.Right;
  524. closeWindow.Click += new EventHandler(closeWindow_Click);
  525. menuMainStrip.Items.Add(closeWindow);
  526. }
  527. private void closeWindow_Click(object sender, EventArgs e)
  528. {
  529. //close the current window
  530. mainTabControl.CloseCurrentTab();
  531. }
  532. private void UpdateIcon(string iconName, string tag)
  533. {
  534. this.Invoke((MethodInvoker)delegate()
  535. {
  536. this.Icon = System.Drawing.Icon.FromHandle(StaticMethods.LoadResourceImage(iconName).GetHicon());
  537. this.Tag = tag;
  538. });
  539. }
  540. private void UpdateTrayIcon(string iconName, string tag)
  541. {
  542. this.Invoke((MethodInvoker)delegate()
  543. {
  544. this.notifyIcon.Icon = System.Drawing.Icon.FromHandle(StaticMethods.LoadResourceImage(iconName).GetHicon());
  545. this.notifyIcon.Tag = tag;
  546. });
  547. }
  548. private void flashTaskBarIconTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  549. {
  550. if (this.WindowState == FormWindowState.Minimized)
  551. {
  552. if (this.Tag.Equals("on"))
  553. {
  554. UpdateIcon("new-tray-icon.ico", "off");
  555. }
  556. else
  557. {
  558. UpdateIcon("tray-icon-flash.ico", "on");
  559. }
  560. flashTaskBarCount++;
  561. if (flashTaskBarCount == 10)
  562. {
  563. this.flashTaskBarIconTimer.Stop();
  564. UpdateIcon("new-tray-icon.ico", "off");
  565. flashTaskBarCount = 0;
  566. }
  567. }
  568. else
  569. {
  570. this.flashTaskBarIconTimer.Stop();
  571. UpdateIcon("new-tray-icon.ico", "off");
  572. }
  573. }
  574. private void flashTrayIconTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
  575. {
  576. if (this.notifyIcon.Visible == true)
  577. {
  578. if (this.notifyIcon.Tag.Equals("on"))
  579. {
  580. UpdateTrayIcon("new-tray-icon.ico", "off");
  581. }
  582. else
  583. {
  584. UpdateTrayIcon("tray-icon-flash.ico", "on");
  585. }
  586. flashTrayCount++;
  587. if (flashTrayCount == 10)
  588. {
  589. this.flashTrayIconTimer.Stop();
  590. UpdateTrayIcon("new-tray-icon.ico", "off");
  591. flashTrayCount = 0;
  592. }
  593. }
  594. else
  595. {
  596. this.flashTrayIconTimer.Stop();
  597. UpdateTrayIcon("new-tray-icon.ico", "off");
  598. }
  599. }
  600. private void FormMainActivated(object sender, EventArgs e)
  601. {
  602. if (iceChatOptions.IsOnTray == true)
  603. {
  604. minimizeToTrayToolStripMenuItem.PerformClick();
  605. }
  606. //auto start any Auto Connect Servers
  607. foreach (ServerSetting s in serverTree.ServersCollection.listServers)
  608. {
  609. if (s.AutoStart)
  610. {
  611. NewServerConnection(s);
  612. }
  613. }
  614. //remove the event handler, because it only needs to be run once, on startup
  615. this.Activated -= FormMainActivated;
  616. }
  617. private void FormMainResize(object sender, EventArgs e)
  618. {
  619. if (this.WindowState == FormWindowState.Minimized)
  620. {
  621. if (iceChatOptions.MinimizeToTray)
  622. {
  623. this.notifyIcon.Visible = true;
  624. this.Hide();
  625. }
  626. }
  627. }
  628. private void toolStripMain_VisibleChanged(object sender, EventArgs e)
  629. {
  630. toolBarToolStripMenuItem.Checked =toolStripMain.Visible;
  631. }
  632. /// <summary>
  633. /// Save Default Server Settings
  634. /// </summary>
  635. private void OnDefaultServerSettings()
  636. {
  637. SaveOptions();
  638. }
  639. #region Load Language File
  640. private LanguageItem LoadLanguageItem(string languageFileName)
  641. {
  642. if (File.Exists(languageFileName))
  643. {
  644. LanguageItem languageItem = null;
  645. XmlSerializer deserializer = new XmlSerializer(typeof(LanguageItem));
  646. TextReader textReader = new StreamReader(languageFileName);
  647. try
  648. {
  649. languageItem = (LanguageItem)deserializer.Deserialize(textReader);
  650. languageItem.LanguageFile = languageFileName;
  651. }
  652. catch
  653. {
  654. languageItem = null;
  655. }
  656. finally
  657. {
  658. textReader.Close();
  659. textReader.Dispose();
  660. }
  661. return languageItem;
  662. }
  663. else
  664. {
  665. return null;
  666. }
  667. }
  668. private void LoadLanguage()
  669. {
  670. if (File.Exists(currentLanguageFile.LanguageFile))
  671. {
  672. XmlSerializer deserializer = new XmlSerializer(typeof(IceChatLanguage));
  673. TextReader textReader = new StreamReader(currentLanguageFile.LanguageFile);
  674. iceChatLanguage = (IceChatLanguage)deserializer.Deserialize(textReader);
  675. textReader.Close();
  676. textReader.Dispose();
  677. }
  678. else
  679. {
  680. iceChatLanguage = new IceChatLanguage();
  681. //write the language file
  682. XmlSerializer serializer = new XmlSerializer(typeof(IceChatLanguage));
  683. TextWriter textWriter = new StreamWriter(currentFolder + Path.DirectorySeparatorChar + "Languages" + Path.DirectorySeparatorChar + "English.xml");
  684. serializer.Serialize(textWriter,iceChatLanguage);
  685. textWriter.Close();
  686. textWriter.Dispose();
  687. }
  688. }
  689. private void ApplyLanguage()
  690. {
  691. mainToolStripMenuItem.Text = iceChatLanguage.mainToolStripMenuItem;
  692. minimizeToTrayToolStripMenuItem.Text = iceChatLanguage.minimizeToTrayToolStripMenuItem;
  693. debugWindowToolStripMenuItem.Text = iceChatLanguage.debugWindowToolStripMenuItem;
  694. exitToolStripMenuItem.Text = iceChatLanguage.exitToolStripMenuItem;
  695. optionsToolStripMenuItem.Text = iceChatLanguage.optionsToolStripMenuItem;
  696. iceChatSettingsToolStripMenuItem.Text = iceChatLanguage.iceChatSettingsToolStripMenuItem;
  697. iceChatColorsToolStripMenuItem.Text = iceChatLanguage.iceChatColorsToolStripMenuItem;
  698. iceChatEditorToolStripMenuItem.Text = iceChatLanguage.iceChatEditorToolStripMenuItem;
  699. pluginsToolStripMenuItem.Text = iceChatLanguage.pluginsToolStripMenuItem;
  700. viewToolStripMenuItem.Text = iceChatLanguage.viewToolStripMenuItem;
  701. serverListToolStripMenuItem.Text = iceChatLanguage.serverListToolStripMenuItem;
  702. nickListToolStripMenuItem.Text = iceChatLanguage.nickListToolStripMenuItem;
  703. statusBarToolStripMenuItem.Text = iceChatLanguage.statusBarToolStripMenuItem;
  704. toolBarToolStripMenuItem.Text = iceChatLanguage.toolBarToolStripMenuItem;
  705. helpToolStripMenuItem.Text = iceChatLanguage.helpToolStripMenuItem;
  706. codePlexPageToolStripMenuItem.Text = iceChatLanguage.codePlexPageToolStripMenuItem;
  707. iceChatHomePageToolStripMenuItem.Text = iceChatLanguage.iceChatHomePageToolStripMenuItem;
  708. forumsToolStripMenuItem.Text = iceChatLanguage.forumsToolStripMenuItem;
  709. aboutToolStripMenuItem.Text = iceChatLanguage.aboutToolStripMenuItem;
  710. toolStripQuickConnect.Text = iceChatLanguage.toolStripQuickConnect;
  711. toolStripSettings.Text = iceChatLanguage.toolStripSettings;
  712. toolStripColors.Text = iceChatLanguage.toolStripColors;
  713. toolStripEditor.Text = iceChatLanguage.toolStripEditor;
  714. toolStripAway.Text = iceChatLanguage.toolStripAway;
  715. toolStripSystemTray.Text = iceChatLanguage.toolStripSystemTray;
  716. toolStripStatus.Text = iceChatLanguage.toolStripStatus;
  717. channelListTab.Text = iceChatLanguage.tabPageFaveChannels;
  718. nickListTab.Text = iceChatLanguage.tabPageNicks;
  719. serverListTab.Text = iceChatLanguage.serverTreeHeader;
  720. channelList.ApplyLanguage();
  721. nickList.ApplyLanguage();
  722. serverTree.ApplyLanguage();
  723. inputPanel.ApplyLanguage();
  724. mainTabControl.Invalidate(); // repaint tabs to apply changes to user drawn tabs
  725. }
  726. #endregion
  727. private void FormMainClosing(object sender, FormClosingEventArgs e)
  728. {
  729. //check if there are any connections open
  730. foreach (IRCConnection c in serverTree.ServerConnections.Values)
  731. {
  732. if (c.IsConnected)
  733. {
  734. DialogResult dr = MessageBox.Show("You are connected to a Server(s), are you sure you want to close IceChat?", "Close IceChat", MessageBoxButtons.OKCancel);
  735. if (e.CloseReason == CloseReason.UserClosing && dr == DialogResult.Cancel)
  736. {
  737. e.Cancel = true;
  738. return;
  739. }
  740. else
  741. break;
  742. }
  743. }
  744. if (identServer != null)
  745. {
  746. identServer.Stop();
  747. identServer = null;
  748. }
  749. foreach (IPluginIceChat ipc in loadedPlugins)
  750. ipc.Dispose();
  751. //unload and dispose of all the plugins
  752. foreach (IPluginIceChat ipc in loadedPlugins)
  753. {
  754. //AppDomain.Unload(ipc.domain);
  755. ipc.Dispose();
  756. }
  757. for (int i = 0; i < loadedPlugins.Count; i++)
  758. {
  759. loadedPlugins.RemoveAt(i);
  760. }
  761. //disconnect all the servers
  762. foreach (IRCConnection c in serverTree.ServerConnections.Values)
  763. {
  764. if (c.IsConnected)
  765. {
  766. c.AttemptReconnect = false;
  767. ParseOutGoingCommand(c, "//quit " + c.ServerSetting.QuitMessage);
  768. }
  769. }
  770. if (iceChatOptions.SaveWindowPosition)
  771. {
  772. //save the window position , as long as its not minimized
  773. if (this.WindowState != FormWindowState.Minimized && this.notifyIcon.Visible == false)
  774. {
  775. iceChatOptions.WindowLocation = this.Location;
  776. iceChatOptions.WindowSize = this.Size;
  777. if (!panelDockRight.IsDocked)
  778. iceChatOptions.RightPanelWidth = panelDockRight.Width;
  779. if (!panelDockLeft.IsDocked)
  780. iceChatOptions.LeftPanelWidth = panelDockLeft.Width;
  781. }
  782. iceChatOptions.IsOnTray = this.notifyIcon.Visible;
  783. SaveOptions();
  784. }
  785. //mutex.ReleaseMutex();
  786. if (errorFile != null)
  787. {
  788. errorFile.Close();
  789. errorFile.Dispose();
  790. }
  791. }
  792. /// <summary>
  793. /// Play the specified sound file (currently only supports WAV files)
  794. /// </summary>
  795. /// <param name="sound"></param>
  796. internal void PlaySoundFile(string key)
  797. {
  798. IceChatSounds.SoundEntry sound = IceChatSounds.getSound(key);
  799. if (sound != null && !muteAllSounds)
  800. {
  801. string file = sound.getSoundFile();
  802. if (file != null && file.Length > 0)
  803. {
  804. try
  805. {
  806. if (iceChatOptions.SoundUseExternalCommand && iceChatOptions.SoundExternalCommand.Length > 0)
  807. ParseOutGoingCommand(inputPanel.CurrentConnection, iceChatOptions.SoundExternalCommand + " " + file);
  808. else
  809. ParseOutGoingCommand(inputPanel.CurrentConnection, "/play " + file);
  810. //player.SoundLocation = @file;
  811. //player.Play();
  812. }
  813. catch { }
  814. }
  815. }
  816. }
  817. /// <summary>
  818. /// Create a Default Tab for showing Welcome Information
  819. /// </summary>
  820. private void CreateDefaultConsoleWindow()
  821. {
  822. IceTabPage p = new IceTabPage(IceTabPage.WindowType.Console, "Console");
  823. p.AddConsoleTab(iceChatLanguage.consoleTabWelcome);
  824. mainTabControl.TabPages.Add(p);
  825. WindowMessage(null, "Console", "\x00034Welcome to " + ProgramID + " " + VersionID, 1, false);
  826. WindowMessage(null, "Console", "\x00034** This is a Release Candidate version, fully functional, not all the options are added **", 1, false);
  827. WindowMessage(null, "Console", "\x00033If you want a fully working version of \x0002IceChat\x0002, visit http://www.icechat.net and download IceChat 7.70", 1, false);
  828. WindowMessage(null, "Console", "\x00034Please visit \x00030,4#icechat\x0003 on \x00030,2irc://irc.quakenet.org/icechat\x0003 if you wish to help with this project", 1, true);
  829. }
  830. #region Internal Properties
  831. /// <summary>
  832. /// Gets the instance of the Nick List
  833. /// </summary>
  834. internal NickList NickList
  835. {
  836. get { return nickList; }
  837. }
  838. /// <summary>
  839. /// Gets the instance of the Server Tree
  840. /// </summary>
  841. internal ServerTree ServerTree
  842. {
  843. get { return serverTree; }
  844. }
  845. /// <summary>
  846. /// Gets the instance of the Main Tab Control
  847. /// </summary>
  848. internal IceTabControl TabMain
  849. {
  850. get { return mainTabControl; }
  851. }
  852. /// <summary>
  853. /// Gets the instance of the InputPanel
  854. /// </summary>
  855. internal InputPanel InputPanel
  856. {
  857. get
  858. {
  859. return this.inputPanel;
  860. }
  861. }
  862. internal IceChatOptions IceChatOptions
  863. {
  864. get
  865. {
  866. return this.iceChatOptions;
  867. }
  868. }
  869. internal IceChatMessageFormat MessageFormats
  870. {
  871. get
  872. {
  873. return this.iceChatMessages;
  874. }
  875. }
  876. internal IceChatFontSetting IceChatFonts
  877. {
  878. get
  879. {
  880. return this.iceChatFonts;
  881. }
  882. }
  883. internal IceChatColors IceChatColors
  884. {
  885. get
  886. {
  887. return this.iceChatColors;
  888. }
  889. }
  890. internal IceChatSounds IceChatSounds
  891. {
  892. get
  893. {
  894. return this.iceChatSounds;
  895. }
  896. }
  897. internal IceChatAliases IceChatAliases
  898. {
  899. get
  900. {
  901. return iceChatAliases;
  902. }
  903. set
  904. {
  905. iceChatAliases = value;
  906. //save the aliases
  907. SaveAliases();
  908. }
  909. }
  910. internal IceChatPopupMenus IceChatPopupMenus
  911. {
  912. get
  913. {
  914. return iceChatPopups;
  915. }
  916. set
  917. {
  918. iceChatPopups = value;
  919. //save the popups
  920. SavePopups();
  921. }
  922. }
  923. internal IceChatEmoticon IceChatEmoticons
  924. {
  925. get
  926. {
  927. return iceChatEmoticons;
  928. }
  929. set
  930. {
  931. iceChatEmoticons = value;
  932. //save the Emoticons
  933. SaveEmoticons();
  934. }
  935. }
  936. internal IceChatLanguage IceChatLanguage
  937. {
  938. get
  939. {
  940. return iceChatLanguage;
  941. }
  942. }
  943. internal List<LanguageItem> IceChatLanguageFiles
  944. {
  945. get
  946. {
  947. return languageFiles;
  948. }
  949. }
  950. internal LanguageItem IceChatCurrentLanguageFile
  951. {
  952. get
  953. {
  954. return currentLanguageFile;
  955. }
  956. set
  957. {
  958. if (currentLanguageFile != value)
  959. {
  960. currentLanguageFile = value;
  961. LoadLanguage();
  962. ApplyLanguage();
  963. }
  964. }
  965. }
  966. internal string FavoriteChannelsFile
  967. {
  968. get
  969. {
  970. return favoriteChannelsFile;
  971. }
  972. }
  973. internal BuddyList BuddyList
  974. {
  975. get
  976. {
  977. return this.buddyList;
  978. }
  979. }
  980. internal string MessagesFile
  981. {
  982. get
  983. {
  984. return messagesFile;
  985. }
  986. set
  987. {
  988. messagesFile = value;
  989. }
  990. }
  991. internal string ColorsFile
  992. {
  993. get
  994. {
  995. return colorsFile;
  996. }
  997. set
  998. {
  999. colorsFile = value;
  1000. }
  1001. }
  1002. internal string ServersFile
  1003. {
  1004. get
  1005. {
  1006. return serversFile;
  1007. }
  1008. }
  1009. internal string AliasesFile
  1010. {
  1011. get
  1012. {
  1013. return aliasesFile;
  1014. }
  1015. }
  1016. internal string PopupsFile
  1017. {
  1018. get
  1019. {
  1020. return popupsFile;
  1021. }
  1022. }
  1023. internal List<IPluginIceChat> IceChatPlugins
  1024. {
  1025. get
  1026. {
  1027. return loadedPlugins;
  1028. }
  1029. }
  1030. public string LogsFolder
  1031. {
  1032. get
  1033. {
  1034. return logsFolder;
  1035. }
  1036. }
  1037. public string CurrentFolder
  1038. {
  1039. get
  1040. {
  1041. return currentFolder;
  1042. }
  1043. }
  1044. internal string EmoticonsFolder
  1045. {
  1046. get
  1047. {
  1048. return System.IO.Path.GetDirectoryName(emoticonsFile);
  1049. }
  1050. }
  1051. internal void StatusText(string data)
  1052. {
  1053. try
  1054. {
  1055. this.Invoke((MethodInvoker)delegate()
  1056. {
  1057. toolStripStatus.Text = "Status: " + data;
  1058. });
  1059. }
  1060. catch { }
  1061. }
  1062. #endregion
  1063. #region Private Properties
  1064. /// <summary>
  1065. /// Set focus to the Input Panel
  1066. /// </summary>
  1067. internal void FocusInputBox()
  1068. {
  1069. inputPanel.FocusTextBox();
  1070. }
  1071. /// <summary>
  1072. /// Sends a Message to a Named Window
  1073. /// </summary>
  1074. /// <param name="connection">Which Connection to use</param>
  1075. /// <param name="name">Name of the Window</param>
  1076. /// <param name="data">Message to send</param>
  1077. /// <param name="color">Color number of the message</param>
  1078. internal void WindowMessage(IRCConnection connection, string name, string data, int color, bool scrollToBottom)
  1079. {
  1080. if (this.InvokeRequired)
  1081. {
  1082. WindowMessageDelegate w = new WindowMessageDelegate(WindowMessage);
  1083. this.Invoke(w, new object[] { connection, name, data, color, scrollToBottom} );
  1084. }
  1085. else
  1086. {
  1087. if (name == "Console")
  1088. {
  1089. mainTabControl.GetTabPage("Console").AddText(connection, data, color, scrollToBottom);
  1090. if (connection != null)
  1091. if (connection.IsFullyConnected)
  1092. if (!connection.ServerSetting.DisableSounds)
  1093. PlaySoundFile("conmsg");
  1094. }
  1095. else
  1096. {
  1097. foreach (IceTabPage t in mainTabControl.TabPages)
  1098. {
  1099. if (t.TabCaption == name)
  1100. {
  1101. if (t.Connection == connection)
  1102. {
  1103. t.TextWindow.AppendText(data, color);
  1104. if (scrollToBottom)
  1105. t.TextWindow.ScrollToBottom();
  1106. return;
  1107. }
  1108. }
  1109. }
  1110. WindowMessage(connection, "Console", data, color, scrollToBottom);
  1111. }
  1112. }
  1113. }
  1114. /// <summary>
  1115. /// Send a Message to the Current Window
  1116. /// </summary>
  1117. /// <param name="connection">Which Connection to use</param>
  1118. /// <param name="data">Message to send</param>
  1119. /// <param name="color">Color number of the message</param>
  1120. internal void CurrentWindowMessage(IRCConnection connection, string data, int color, bool scrollToBottom)
  1121. {
  1122. if (this.InvokeRequired)
  1123. {
  1124. CurrentWindowMessageDelegate w = new CurrentWindowMessageDelegate(CurrentWindowMessage);
  1125. this.Invoke(w, new object[] { connection, data, color, scrollToBottom });
  1126. }
  1127. else
  1128. {
  1129. //check what type the current window is
  1130. if (CurrentWindowType == IceTabPage.WindowType.ChannelList)
  1131. {
  1132. //do nothing, send it to the console
  1133. mainTabControl.GetTabPage("Console").AddText(connection, data, color, false);
  1134. }
  1135. else if (CurrentWindowType != IceTabPage.WindowType.Console)
  1136. {
  1137. IceTabPage t = mainTabControl.CurrentTab;
  1138. if (t != null)
  1139. {
  1140. if (t.Connection == connection)
  1141. {
  1142. t.TextWindow.AppendText(data, color);
  1143. }
  1144. else
  1145. {
  1146. WindowMessage(connection, "Console", data, color, scrollToBottom);
  1147. }
  1148. }
  1149. }
  1150. else
  1151. {
  1152. //console window is current window
  1153. mainTabControl.GetTabPage("Console").AddText(connection, data, color, false);
  1154. }
  1155. }
  1156. }
  1157. /// <summary>
  1158. /// Gets a Tab Window
  1159. /// </summary>
  1160. /// <param name="connection">Which Connection to use</param>
  1161. /// <param name="name">Name of the Window</param>
  1162. /// <param name="windowType">The Window Type</param>
  1163. /// <returns></returns>
  1164. internal IceTabPage GetWindow(IRCConnection connection, string sCaption, IceTabPage.WindowType windowType)
  1165. {
  1166. foreach (IceTabPage t in mainTabControl.TabPages)
  1167. {
  1168. if (t.TabCaption.ToLower() == sCaption.ToLower() && t.WindowStyle == windowType)
  1169. {
  1170. if (t.Connection == null && windowType == IceTabPage.WindowType.DCCFile)
  1171. return t;
  1172. else if (t.Connection == null && windowType == IceTabPage.WindowType.Debug)
  1173. return t;
  1174. else if (t.Connection == connection)
  1175. return t;
  1176. }
  1177. else if (t.WindowStyle == windowType && windowType == IceTabPage.WindowType.ChannelList)
  1178. {
  1179. return t;
  1180. }
  1181. }
  1182. return null;
  1183. }
  1184. /// <summary>
  1185. /// Get the Current Tab Window
  1186. /// </summary>
  1187. internal IceTabPage CurrentWindow
  1188. {
  1189. get
  1190. {
  1191. return mainTabControl.CurrentTab;
  1192. }
  1193. }
  1194. /// <summary>
  1195. /// Get the Current Window Type
  1196. /// </summary>
  1197. internal IceTabPage.WindowType CurrentWindowType
  1198. {
  1199. get
  1200. {
  1201. if (mainTabControl.CurrentTab != null)
  1202. return mainTabControl.CurrentTab.WindowStyle;
  1203. else
  1204. {
  1205. System.Diagnostics.Debug.WriteLine("CurrentWindowType Null:" + mainTabControl.TabPages.Count);
  1206. return IceTabPage.WindowType.Console;
  1207. }
  1208. }
  1209. }
  1210. #endregion
  1211. #region Private Methods
  1212. /// <summary>
  1213. /// Send a Message through the IRC Connection to the Server
  1214. /// </summary>
  1215. /// <param name="connection">Which Connection to use</param>
  1216. /// <param name="data">RAW IRC Message to send</param>
  1217. private void SendData(IRCConnection connection, string data)
  1218. {
  1219. if (connection != null)
  1220. {
  1221. if (connection.IsConnected)
  1222. {
  1223. if (connection.IsFullyConnected)
  1224. connection.SendData(data);
  1225. else
  1226. //add to a command queue, which gets run once fully connected, after autoperform/autojoin
  1227. connection.AddToCommandQueue(data);
  1228. }
  1229. else
  1230. {
  1231. if (CurrentWindowType == IceTabPage.WindowType.Console)
  1232. WindowMessage(connection, "Console", "Error: Not Connected to Server (" + data + ")", 4, true);
  1233. else if (CurrentWindow.WindowStyle != IceTabPage.WindowType.ChannelList && CurrentWindow.WindowStyle != IceTabPage.WindowType.DCCFile)
  1234. {
  1235. CurrentWindow.TextWindow.AppendText("Error: Not Connected to Server (" + data + ")", 4);
  1236. CurrentWindow.TextWindow.ScrollToBottom();
  1237. }
  1238. else
  1239. {
  1240. WindowMessage(connection, "Console", "Error: Not Connected to Server (" + data + ")", 4, true);
  1241. }
  1242. }
  1243. }
  1244. }
  1245. #endregion
  1246. private void NewConnection2(Object setting)
  1247. {
  1248. ServerSetting serverSetting = (ServerSetting)setting;
  1249. IRCConnection c = new IRCConnection(serverSetting);
  1250. c.ChannelMessage += new ChannelMessageDelegate(OnChannelMessage);
  1251. c.ChannelAction += new ChannelActionDelegate(OnChannelAction);
  1252. c.QueryMessage += new QueryMessageDelegate(OnQueryMessage);
  1253. c.QueryAction += new QueryActionDelegate(OnQueryAction);
  1254. c.ChannelNotice += new ChannelNoticeDelegate(OnChannelNotice);
  1255. c.ChangeNick += new ChangeNickDelegate(OnChangeNick);
  1256. c.ChannelKick += new ChannelKickDelegate(OnChannelKick);
  1257. c.OutGoingCommand += new OutGoingCommandDelegate(OutGoingCommand);
  1258. c.JoinChannel += new JoinChannelDelegate(OnChannelJoin);
  1259. c.PartChannel += new PartChannelDelegate(OnChannelPart);
  1260. c.QuitServer += new QuitServerDelegate(OnServerQuit);
  1261. c.JoinChannelMyself += new JoinChannelMyselfDelegate(OnChannelJoinSelf);
  1262. c.PartChannelMyself += new PartChannelMyselfDelegate(OnChannelPartSelf);
  1263. c.ChannelKickSelf += new ChannelKickSelfDelegate(OnChannelKickSelf);
  1264. c.ChannelTopic += new ChannelTopicDelegate(OnChannelTopic);
  1265. c.ChannelMode += new ChannelModeChangeDelegate(OnChannelMode);
  1266. c.UserMode += new UserModeChangeDelegate(OnUserMode);
  1267. c.ChannelInvite += new ChannelInviteDelegate(OnChannelInvite);
  1268. c.ServerMessage += new ServerMessageDelegate(OnServerMessage);
  1269. c.ServerError += new ServerErrorDelegate(OnServerError);
  1270. c.ServerMOTD += new ServerMOTDDelegate(OnServerMOTD);
  1271. c.WhoisData += new WhoisDataDelegate(OnWhoisData);
  1272. c.UserNotice += new UserNoticeDelegate(OnUserNotice);
  1273. c.CtcpMessage += new CtcpMessageDelegate(OnCtcpMessage);
  1274. c.CtcpReply += new CtcpReplyDelegate(OnCtcpReply);
  1275. c.GenericChannelMessage += new GenericChannelMessageDelegate(OnGenericChannelMessage);
  1276. c.ServerNotice += new ServerNoticeDelegate(OnServerNotice);
  1277. c.ChannelListStart += new ChannelListStartDelegate(OnChannelListStart);
  1278. c.ChannelList += new ChannelListDelegate(OnChannelList);
  1279. c.DCCChat += new DCCChatDelegate(OnDCCChat);
  1280. c.DCCFile += new DCCFileDelegate(OnDCCFile);
  1281. c.DCCPassive += new DCCPassiveDelegate(OnDCCPassive);
  1282. c.UserHostReply += new UserHostReplyDelegate(OnUserHostReply);
  1283. c.IALUserData += new IALUserDataDelegate(OnIALUserData);
  1284. c.IALUserChange += new IALUserChangeDelegate(OnIALUserChange);
  1285. c.IALUserPart += new IALUserPartDelegate(OnIALUserPart);
  1286. c.IALUserQuit += new IALUserQuitDelegate(OnIALUserQuit);
  1287. c.BuddyListData += new BuddyListDelegate(OnBuddyList);
  1288. c.BuddyListClear += new BuddyListClearDelegate(OnBuddyListClear);
  1289. c.RawServerIncomingData += new RawServerIncomingDataDelegate(OnRawServerData);
  1290. c.RawServerOutgoingData += new RawServerOutgoingDataDelegate(OnRawServerOutgoingData);
  1291. c.AutoJoin += new AutoJoinDelegate(OnAutoJoin);
  1292. c.AutoRejoin += new AutoRejoinDelegate(OnAutoRejoin);
  1293. c.AutoPerform += new AutoPerformDelegate(OnAutoPerform);
  1294. c.EndofNames += new EndofNamesDelegate(OnEndofNames);
  1295. c.EndofWhoReply += new EndofWhoReplyDelegate(OnEndofWhoReply);
  1296. c.WhoReply += new WhoReplyDelegate(OnWhoReply);
  1297. c.ChannelUserList += new ChannelUserListDelegate(OnChannelUserList);
  1298. c.StatusText += new IceChat.StatusTextDelegate(OnStatusText);
  1299. c.RefreshServerTree += new RefreshServerTreeDelegate(OnRefreshServerTree);
  1300. c.ServerReconnect += new ServerReconnectDelegate(OnServerReconnect);
  1301. c.ServerDisconnect += new ServerReconnectDelegate(OnServerDisconnect);
  1302. c.ServerConnect += new ServerConnectDelegate(OnServerConnect);
  1303. c.ServerForceDisconnect += new ServerForceDisconnectDelegate(OnServerForceDisconnect);
  1304. c.ServerPreConnect += new ServerPreConnectDelegate(OnServerPreConnect);
  1305. c.UserInfoWindowExists += new UserInfoWindowExistsDelegate(OnUserInfoWindowExists);
  1306. c.UserInfoHostFullName += new UserInfoHostFullnameDelegate(OnUserInfoHostFullName);
  1307. c.UserInfoIdleLogon += new UserInfoIdleLogonDelegate(OnUserInfoIdleLogon);
  1308. c.UserInfoAddChannels += new UserInfoAddChannelsDelegate(OnUserInfoAddChannels);
  1309. c.ChannelInfoWindowExists += new ChannelInfoWindowExistsDelegate(OnChannelInfoWindowExists);
  1310. c.ChannelInfoAddBan += new ChannelInfoAddBanDelegate(OnChannelInfoAddBan);
  1311. c.ChannelInfoAddException += new ChannelInfoAddExceptionDelegate(OnChannelInfoAddException);
  1312. c.ChannelInfoTopicSet += new ChannelInfoTopicSetDelegate(OnChannelInfoTopicSet);
  1313. c.WriteErrorFile += new WriteErrorFileDelegate(OnWriteErrorFile);
  1314. OnAddConsoleTab(c);
  1315. mainTabControl.SelectTab(mainTabControl.GetTabPage("Console"));
  1316. inputPanel.CurrentConnection = c;
  1317. serverTree.AddConnection(c);
  1318. c.ConnectSocket();
  1319. }
  1320. /// <summary>
  1321. /// Create a new Server Connection
  1322. /// </summary>
  1323. /// <param name="serverSetting">Which ServerSetting to use</param>
  1324. private void NewServerConnection(ServerSetting serverSetting)
  1325. {
  1326. //System.Threading.ParameterizedThreadStart threadStart = new System.Threading.ParameterizedThreadStart(NewConnection);
  1327. //System.Threading.Thread thread = new System.Threading.Thread(threadStart);
  1328. //thread.IsBackground = true;
  1329. //thread.Start(serverSetting);
  1330. IRCConnection c = new IRCConnection(serverSetting);
  1331. c.ChannelMessage += new ChannelMessageDelegate(OnChannelMessage);
  1332. c.ChannelAction += new ChannelActionDelegate(OnChannelAction);
  1333. c.QueryMessage += new QueryMessageDelegate(OnQueryMessage);
  1334. c.QueryAction += new QueryActionDelegate(OnQueryAction);
  1335. c.ChannelNotice += new ChannelNoticeDelegate(OnChannelNotice);
  1336. c.ChangeNick += new ChangeNickDelegate(OnChangeNick);
  1337. c.ChannelKick += new ChannelKickDelegate(OnChannelKick);
  1338. c.OutGoingCommand += new OutGoingCommandDelegate(OutGoingCommand);
  1339. c.JoinChannel += new JoinChannelDelegate(OnChannelJoin);
  1340. c.PartChannel += new PartChannelDelegate(OnChannelPart);
  1341. c.QuitServer += new QuitServerDelegate(OnServerQuit);
  1342. c.JoinChannelMyself += new JoinChannelMyselfDelegate(OnChannelJoinSelf);
  1343. c.PartChannelMyself += new PartChannelMyselfDelegate(OnChannelPartSelf);
  1344. c.ChannelKickSelf += new ChannelKickSelfDelegate(OnChannelKickSelf);
  1345. c.ChannelTopic += new ChannelTopicDelegate(OnChannelTopic);
  1346. c.ChannelMode += new ChannelModeChangeDelegate(OnChannelMode);
  1347. c.UserMode += new UserModeChangeDelegate(OnUserMode);
  1348. c.ChannelInvite += new ChannelInviteDelegate(OnChannelInvite);
  1349. c.ServerMessage += new ServerMessageDelegate(OnServerMessage);
  1350. c.ServerError += new ServerErrorDelegate(OnServerError);
  1351. c.ServerMOTD += new ServerMOTDDelegate(OnServerMOTD);
  1352. c.WhoisData += new WhoisDataDelegate(OnWhoisData);
  1353. c.UserNotice += new UserNoticeDelegate(OnUserNotice);
  1354. c.CtcpMessage += new CtcpMessageDelegate(OnCtcpMessage);
  1355. c.CtcpReply += new CtcpReplyDelegate(OnCtcpReply);
  1356. c.GenericChannelMessage += new GenericChannelMessageDelegate(OnGenericChannelMessage);
  1357. c.ServerNotice += new ServerNoticeDelegate(OnServerNotice);
  1358. c.ChannelListStart += new ChannelListStartDelegate(OnChannelListStart);
  1359. c.ChannelList += new ChannelListDelegate(OnChannelList);
  1360. c.DCCChat += new DCCChatDelegate(OnDCCChat);
  1361. c.DCCFile += new DCCFileDelegate(OnDCCFile);
  1362. c.DCCPassive += new DCCPassiveDelegate(OnDCCPassive);
  1363. c.UserHostReply += new UserHostReplyDelegate(OnUserHostReply);
  1364. c.IALUserData += new IALUserDataDelegate(OnIALUserData);
  1365. c.IALUserChange += new IALUserChangeDelegate(OnIALUserChange);
  1366. c.IALUserPart += new IALUserPartDelegate(OnIALUserPart);
  1367. c.IALUserQuit += new IALUserQuitDelegate(OnIALUserQuit);
  1368. c.BuddyListData += new BuddyListDelegate(OnBuddyList);
  1369. c.BuddyListClear += new BuddyListClearDelegate(OnBuddyListClear);
  1370. c.RawServerIncomingData += new RawServerIncomingDataDelegate(OnRawServerData);
  1371. c.RawServerOutgoingData += new RawServerOutgoingDataDelegate(OnRawServerOutgoingData);
  1372. c.AutoJoin += new AutoJoinDelegate(OnAutoJoin);
  1373. c.AutoRejoin += new AutoRejoinDelegate(OnAutoRejoin);
  1374. c.AutoPerform += new AutoPerformDelegate(OnAutoPerform);
  1375. c.EndofNames += new EndofNamesDelegate(OnEndofNames);
  1376. c.EndofWhoReply += new EndofWhoReplyDelegate(OnEndofWhoReply);
  1377. c.WhoReply += new WhoReplyDelegate(OnWhoReply);
  1378. c.ChannelUserList += new ChannelUserListDelegate(OnChannelUserList);
  1379. c.StatusText += new IceChat.StatusTextDelegate(OnStatusText);
  1380. c.RefreshServerTree += new RefreshServerTreeDelegate(OnRefreshServerTree);
  1381. c.ServerReconnect += new ServerReconnectDelegate(OnServerReconnect);
  1382. c.ServerDisconnect += new ServerReconnectDelegate(OnServerDisconnect);
  1383. c.ServerConnect += new ServerConnectDelegate(OnServerConnect);
  1384. c.ServerForceDisconnect += new ServerForceDisconnectDelegate(OnServerForceDisconnect);
  1385. c.ServerPreConnect += new ServerPreConnectDelegate(OnServerPreConnect);
  1386. c.UserInfoWindowExists += new UserInfoWindowExistsDelegate(OnUserInfoWindowExists);
  1387. c.UserInfoHostFullName += new UserInfoHostFullnameDelegate(OnUserInfoHostFullName);
  1388. c.UserInfoIdleLogon += new UserInfoIdleLogonDelegate(OnUserInfoIdleLogon);
  1389. c.UserInfoAddChannels += new UserInfoAddChannelsDelegate(OnUserInfoAddChannels);
  1390. c.ChannelInfoWindowExists += new ChannelInfoWindowExistsDelegate(OnChannelInfoWindowExists);
  1391. c.ChannelInfoAddBan += new ChannelInfoAddBanDelegate(OnChannelInfoAddBan);
  1392. c.ChannelInfoAddException += new ChannelInfoAddExceptionDelegate(OnChannelInfoAddException);
  1393. c.ChannelInfoTopicSet += new ChannelInfoTopicSetDelegate(OnChannelInfoTopicSet);
  1394. c.WriteErrorFile += new WriteErrorFileDelegate(OnWriteErrorFile);
  1395. OnAddConsoleTab(c);
  1396. mainTabControl.SelectTab(mainTabControl.GetTabPage("Console"));
  1397. inputPanel.CurrentConnection = c;
  1398. serverTree.AddConnection(c);
  1399. c.ConnectSocket();
  1400. }
  1401. #region Tab Events and Methods
  1402. /// <summary>
  1403. /// Add a new Connection Tab to the Console
  1404. /// </summary>
  1405. /// <param name="connection">Which Connection to add</param>
  1406. private void OnAddConsoleTab(IRCConnection connection)
  1407. {
  1408. mainTabControl.GetTabPage("Console").AddConsoleTab(connection);
  1409. }
  1410. /// <summary>
  1411. /// Add a new Tab Window to the Main Tab Control
  1412. /// </summary>
  1413. /// <param name="connection">Which Connection it came from</param>
  1414. /// <param name="windowName">Window Name of the New Tab</param>
  1415. /// <param name="windowType">Window Type of the New Tab</param>
  1416. internal IceTabPage AddWindow(IRCConnection connection, string windowName, IceTabPage.WindowType windowType)
  1417. {
  1418. if (this.InvokeRequired)
  1419. {
  1420. AddWindowDelegate a = new AddWindowDelegate(AddWindow);
  1421. return (IceTabPage)this.Invoke(a, new object[] { connection, windowName, windowType });
  1422. }
  1423. else
  1424. {
  1425. IceTabPage page;
  1426. if (windowType == IceTabPage.WindowType.DCCFile)
  1427. page = new IceTabPageDCCFile(IceTabPage.WindowType.DCCFile, windowName);
  1428. else
  1429. {
  1430. page = new IceTabPage(windowType, windowName);
  1431. page.Connection = connection;
  1432. }
  1433. if (page.WindowStyle == IceTabPage.WindowType.Channel)
  1434. {
  1435. page.TextWindow.Font = new Font(iceChatFonts.FontSettings[1].FontName, iceChatFonts.FontSettings[1].FontSize);
  1436. page.TopicWindow.Font = new Font(iceChatFonts.FontSettings[1].FontName, iceChatFonts.FontSettings[1].FontSize);
  1437. //send the message
  1438. string msg = GetMessageFormat("Self Channel Join");
  1439. msg = msg.Replace("$nick", connection.ServerSetting.NickName).Replace("$channel", windowName);
  1440. if (FormMain.Instance.IceChatOptions.LogChannel)
  1441. page.TextWindow.SetLogFile();
  1442. page.TextWindow.AppendText(msg, 1);
  1443. }
  1444. else if (page.WindowStyle == IceTabPage.WindowType.Query)
  1445. {
  1446. page.TextWindow.Font = new Font(iceChatFonts.FontSettings[2].FontName, iceChatFonts.FontSettings[2].FontSize);
  1447. if (FormMain.Instance.IceChatOptions.LogQuery)
  1448. page.TextWindow.SetLogFile();
  1449. }
  1450. else if (page.WindowStyle == IceTabPage.WindowType.Debug)
  1451. {
  1452. page.TextWindow.NoColorMode = true;
  1453. page.TextWindow.Font = new Font("Verdana", 10);
  1454. page.TextWindow.SetLogFile();
  1455. page.TextWindow.SetDebugWindow();
  1456. }
  1457. //find the last window index for this connection
  1458. int index = 0;
  1459. if (page.WindowStyle == IceTabPage.WindowType.Channel || page.WindowStyle == IceTabPage.WindowType.Query || page.WindowStyle == IceTabPage.WindowType.DCCChat || page.WindowStyle == IceTabPage.WindowType.DCCFile)
  1460. {
  1461. for (int i = 1; i < mainTabControl.TabPages.Count; i++)
  1462. {
  1463. if (mainTabControl.TabPages[i].Connection == connection)
  1464. index = i + 1;
  1465. }
  1466. }
  1467. if (index == 0)
  1468. mainTabControl.TabPages.Add(page);
  1469. else
  1470. mainTabControl.TabPages.Insert(index, page);
  1471. if (page.WindowStyle == IceTabPage.WindowType.Query && !iceChatOptions.NewQueryForegound)
  1472. {
  1473. mainTabControl.SelectTab(mainTabControl.CurrentTab);
  1474. serverTree.SelectTab(mainTabControl.CurrentTab, false);
  1475. }
  1476. else
  1477. {
  1478. mainTabControl.SelectTab(page);
  1479. nickList.CurrentWindow = page;
  1480. serverTree.SelectTab(page, false);
  1481. }
  1482. if (page.WindowStyle == IceTabPage.WindowType.Query && iceChatOptions.WhoisNewQuery)
  1483. ParseOutGoingCommand(page.Connection, "/whois " + page.TabCaption);
  1484. return page;
  1485. }
  1486. }
  1487. /// <summary>
  1488. /// Remove a Tab Window from the Main Tab Control
  1489. /// </summary>
  1490. /// <param name="connection">Which Connection it is for</param>
  1491. /// <param name="channel">The Channel/Query Window Name</param>
  1492. internal void RemoveWindow(IRCConnection connection, string windowCaption, IceTabPage.WindowType windowType)
  1493. {
  1494. this.Invoke((MethodInvoker)delegate()
  1495. {
  1496. IceTabPage t = GetWindow(connection, windowCaption, IceTabPage.WindowType.Channel);
  1497. if (t != null)
  1498. {
  1499. mainTabControl.Controls.Remove(t);
  1500. return;
  1501. }
  1502. IceTabPage c = GetWindow(connection, windowCaption, IceTabPage.WindowType.Query);
  1503. if (c != null)
  1504. {
  1505. mainTabControl.Controls.Remove(c);
  1506. return;
  1507. }
  1508. IceTabPage dcc = GetWindow(connection, windowCaption, IceTabPage.WindowType.DCCChat);
  1509. if (dcc != null)
  1510. {
  1511. mainTabControl.Controls.Remove(dcc);
  1512. return;
  1513. }
  1514. IceTabPage cl = GetWindow(connection, "", IceTabPage.WindowType.ChannelList);
  1515. if (cl != null)
  1516. {
  1517. mainTabControl.Controls.Remove(cl);
  1518. return;
  1519. }
  1520. IceTabPage de = GetWindow(null, "Debug", IceTabPage.WindowType.Debug);
  1521. if (de != null)
  1522. mainTabControl.Controls.Remove(de);
  1523. });
  1524. }
  1525. /// <summary>
  1526. /// Close All Channels/Query Tabs for specified Connection
  1527. /// </summary>
  1528. /// <param name="connection">Which Connection it is for</param>
  1529. internal void CloseAllWindows(IRCConnection connection)
  1530. {
  1531. for (int i = mainTabControl.TabPages.Count - 1; i > 0; i--)
  1532. {
  1533. if (mainTabControl.TabPages[i].Connection == connection)
  1534. mainTabControl.TabPages.Remove(mainTabControl.TabPages[i]);
  1535. }
  1536. mainTabControl.Invalidate();
  1537. }
  1538. internal string GetMessageFormat(string MessageName)
  1539. {
  1540. foreach (ServerMessageFormatItem msg in iceChatMessages.MessageSettings)
  1541. {
  1542. if (msg.MessageName.ToLower() == MessageName.ToLower())
  1543. return msg.FormattedMessage;
  1544. }
  1545. return null;
  1546. }
  1547. /// <summary>
  1548. /// A New Tab was Selected for the Main Tab Control
  1549. /// Update the Input Panel with the Current Connection
  1550. /// Change the Status text for the Status Bar
  1551. /// </summary>
  1552. /// <param name="sender"></param>
  1553. /// <param name="e"></param>
  1554. private void TabSelectedIndexChanged(object sender, TabEventArgs e)
  1555. {
  1556. this.Invoke((MethodInvoker)delegate()
  1557. {
  1558. if (mainTabControl.CurrentTab.WindowStyle != IceTabPage.WindowType.Console)
  1559. {
  1560. //System.Diagnostics.Debug.WriteLine("TabSelected:" + mainTabControl.CurrentTab.TabCaption);
  1561. if (mainTabControl.CurrentTab != null)
  1562. {
  1563. IceTabPage t = mainTabControl.CurrentTab;
  1564. if (t.TextWindow != null)
  1565. t.TextWindow.resetUnreadMarker();
  1566. nickList.RefreshList(t);
  1567. inputPanel.CurrentConnection = t.Connection;
  1568. string network = "";
  1569. if (CurrentWindowType != IceTabPage.WindowType.Debug && CurrentWindowType != IceTabPage.WindowType.DCCFile && CurrentWindowType != IceTabPage.WindowType.Window && t.Connection.ServerSetting.NetworkName.Length > 0)
  1570. network = " (" + t.Connection.ServerSetting.NetworkName + ")";
  1571. if (CurrentWindowType == IceTabPage.WindowType.Channel)
  1572. StatusText(t.Connection.ServerSetting.NickName + " in channel " + t.TabCaption + " [" + t.ChannelModes + "] {" + t.Connection.ServerSetting.RealServerName + "}" + network);
  1573. else if (CurrentWindowType == IceTabPage.WindowType.Query)
  1574. StatusText(t.Connection.ServerSetting.NickName + " in private chat with " + t.TabCaption + " {" + t.Connection.ServerSetting.RealServerName + "}" + network);
  1575. else if (CurrentWindowType == IceTabPage.WindowType.DCCChat)
  1576. StatusText(t.Connection.ServerSetting.NickName + " in DCC chat with " + t.TabCaption + " {" + t.Connection.ServerSetting.RealServerName + "}" + network);
  1577. else if (CurrentWindowType == IceTabPage.WindowType.ChannelList)
  1578. StatusText(t.Connection.ServerSetting.NickName + " in Channel List for {" + t.Connection.ServerSetting.RealServerName + "}" + network);
  1579. CurrentWindow.LastMessageType = ServerMessageType.Default;
  1580. t = null;
  1581. if (!e.IsHandled)
  1582. serverTree.SelectTab(mainTabControl.CurrentTab, false);
  1583. }
  1584. }
  1585. else
  1586. {
  1587. //make sure the 1st tab is not selected
  1588. nickList.RefreshList();
  1589. nickList.Header = iceChatLanguage.consoleTabTitle;
  1590. if (mainTabControl.GetTabPage("Console").ConsoleTab.SelectedIndex != 0)
  1591. {
  1592. inputPanel.CurrentConnection = mainTabControl.GetTabPage("Console").CurrentConnection;
  1593. string network = "";
  1594. if (inputPanel.CurrentConnection.ServerSetting.NetworkName.Length > 0)
  1595. network = " (" + inputPanel.CurrentConnection.ServerSetting.NetworkName + ")";
  1596. if (inputPanel.CurrentConnection.IsConnected)
  1597. {
  1598. if (inputPanel.CurrentConnection.ServerSetting.UseBNC)
  1599. StatusText(inputPanel.CurrentConnection.ServerSetting.NickName + " connected to " + inputPanel.CurrentConnection.ServerSetting.BNCIP);
  1600. else
  1601. StatusText(inputPanel.CurrentConnection.ServerSetting.NickName + " connected to " + inputPanel.CurrentConnection.ServerSetting.RealServerName + network);
  1602. }
  1603. else
  1604. {
  1605. if (inputPanel.CurrentConnection.ServerSetting.UseBNC)
  1606. StatusText(inputPanel.CurrentConnection.ServerSetting.NickName + " disconnected from " + inputPanel.CurrentConnection.ServerSetting.BNCIP);
  1607. else
  1608. StatusText(inputPanel.CurrentConnection.ServerSetting.NickName + " disconnected from " + inputPanel.CurrentConnection.ServerSetting.ServerName + network);
  1609. }
  1610. if (!e.IsHandled)
  1611. serverTree.SelectTab(mainTabControl.GetTabPage("Console").CurrentConnection.ServerSetting, false);
  1612. }
  1613. else
  1614. {
  1615. inputPanel.CurrentConnection = null;
  1616. StatusText("Welcome to " + ProgramID + " " + VersionID);
  1617. }
  1618. }
  1619. inputPanel.FocusTextBox();
  1620. });
  1621. }
  1622. /// <summary>
  1623. /// Closes the Tab selected
  1624. /// </summary>
  1625. /// <param name="tab">Which tab to Close</param>
  1626. private void mainTabControl_OnTabClosed(int nIndex)
  1627. {
  1628. if (mainTabControl.GetTabPage(nIndex).WindowStyle == IceTabPage.WindowType.Channel)
  1629. {
  1630. foreach (IRCConnection c in serverTree.ServerConnections.Values)
  1631. {
  1632. if (c == mainTabControl.GetTabPage(nIndex).Connection)
  1633. {
  1634. //check if connected
  1635. if (c.IsConnected)
  1636. ParseOutGoingCommand(c, "/part " + mainTabControl.GetTabPage(nIndex).TabCaption);
  1637. else
  1638. RemoveWindow(c, mainTabControl.GetTabPage(nIndex).TabCaption, mainTabControl.GetTabPage(nIndex).WindowStyle);
  1639. return;
  1640. }
  1641. }
  1642. }
  1643. else if (mainTabControl.GetTabPage(nIndex).WindowStyle == IceTabPage.WindowType.Query)
  1644. {
  1645. mainTabControl.Controls.Remove(mainTabControl.GetTabPage(nIndex));
  1646. }
  1647. else if (mainTabControl.GetTabPage(nIndex).WindowStyle == IceTabPage.WindowType.ChannelList)
  1648. {
  1649. mainTabControl.Controls.Remove(mainTabControl.GetTabPage(nIndex));
  1650. }
  1651. else if (mainTabControl.GetTabPage(nIndex).WindowStyle == IceTabPage.WindowType.DCCChat)
  1652. {
  1653. mainTabControl.Controls.Remove(mainTabControl.GetTabPage(nIndex));
  1654. }
  1655. else if (mainTabControl.GetTabPage(nIndex).WindowStyle == IceTabPage.WindowType.DCCFile)
  1656. {
  1657. mainTabControl.Controls.Remove(mainTabControl.GetTabPage(nIndex));
  1658. }
  1659. else if (mainTabControl.GetTabPage(nIndex).WindowStyle == IceTabPage.WindowType.Window)
  1660. {
  1661. mainTabControl.Controls.Remove(mainTabControl.GetTabPage(nIndex));
  1662. }
  1663. else if (mainTabControl.GetTabPage(nIndex).WindowStyle == IceTabPage.WindowType.Debug)
  1664. {
  1665. mainTabControl.Controls.Remove(mainTabControl.GetTabPage(nIndex));
  1666. }
  1667. }
  1668. #endregion
  1669. #region InputPanel Events
  1670. /// <summary>
  1671. /// Parse out command written in Input Box or sent from Plugin
  1672. /// </summary>
  1673. /// <param name="connection">Which Connection it is for</param>
  1674. /// <param name="data">The Message to Parse</param>
  1675. public void ParseOutGoingCommand(IRCConnection connection, string data)
  1676. {
  1677. try
  1678. {
  1679. data = data.Replace("&#x3;", ((char)3).ToString());
  1680. PluginArgs args = new PluginArgs(connection);
  1681. args.Command = data;
  1682. foreach (IPluginIceChat ipc in loadedPlugins)
  1683. {
  1684. if (ipc.Enabled == true)
  1685. args = ipc.InputText(args);
  1686. }
  1687. data = args.Command;
  1688. if (data.Length == 0)
  1689. return;
  1690. if (data.StartsWith("//"))
  1691. {
  1692. //parse out identifiers
  1693. ParseOutGoingCommand(connection, ParseIdentifiers(connection, data, data));
  1694. return;
  1695. }
  1696. if (data.StartsWith("/"))
  1697. {
  1698. int indexOfSpace = data.IndexOf(" ");
  1699. string command = "";
  1700. string temp = "";
  1701. if (indexOfSpace > 0)
  1702. {
  1703. command = data.Substring(0, indexOfSpace);
  1704. data = data.Substring(command.Length + 1);
  1705. }
  1706. else
  1707. {
  1708. command = data;
  1709. data = "";
  1710. }
  1711. //check for aliases
  1712. foreach (AliasItem a in iceChatAliases.listAliases)
  1713. {
  1714. if (a.AliasName == command)
  1715. {
  1716. if (a.Command.Length == 1)
  1717. {
  1718. data = ParseIdentifierValue(a.Command[0], data);
  1719. ParseOutGoingCommand(connection, ParseIdentifiers(connection, data, data));
  1720. }
  1721. else
  1722. {
  1723. //it is a multulined alias, run multiple commands
  1724. foreach (string c in a.Command)
  1725. {
  1726. data = ParseIdentifierValue(c, data);
  1727. ParseOutGoingCommand(connection, ParseIdentifiers(connection, data, data));
  1728. }
  1729. }
  1730. return;
  1731. }
  1732. }
  1733. switch (command.ToLower())
  1734. {
  1735. case "/makeexception":
  1736. throw new Exception("IceChat 9 Test Exception Error");
  1737. case "/addlines":
  1738. for (int i = 0; i < 250; i++)
  1739. {
  1740. string msg = i.ToString() + ". The quick brown fox jumps over the lazy dog and gets away with it";
  1741. CurrentWindowMessage(connection, msg, 4, true);
  1742. }
  1743. break;
  1744. case "/background":
  1745. case "/bg": //change background image for a window(s)
  1746. if (data.Length > 0)
  1747. {
  1748. //bg windowtype imagefile
  1749. //bg windowtype windowname imagefile
  1750. //if imagefile is blank, erase background image
  1751. string window = data.Split(' ')[0];
  1752. string file = "";
  1753. if (data.IndexOf(' ') > -1)
  1754. file = data.Substring(window.Length + 1);
  1755. switch (window.ToLower())
  1756. {
  1757. case "nicklist":
  1758. break;
  1759. case "serverlist":
  1760. break;
  1761. case "console":
  1762. //check if the file is a URL
  1763. if (file.StartsWith("http://"))
  1764. {
  1765. System.Net.HttpWebRequest myRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(file);
  1766. myRequest.Method = "GET";
  1767. System.Net.HttpWebResponse myResponse = (System.Net.HttpWebResponse)myRequest.GetResponse();
  1768. mainTabControl.GetTabPage("Console").CurrentConsoleWindow().BackGroundImageURL = myResponse.GetResponseStream();
  1769. }
  1770. else
  1771. {
  1772. if (file.Length > 0 && File.Exists(picturesFolder + System.IO.Path.DirectorySeparatorChar + file))
  1773. mainTabControl.GetTabPage("Console").CurrentConsoleWindow().BackGroundImage = (picturesFolder + System.IO.Path.DirectorySeparatorChar + file);
  1774. else
  1775. mainTabControl.GetTabPage("Console").CurrentConsoleWindow().BackGroundImage = "";
  1776. }
  1777. break;
  1778. case "channel":
  1779. //get the channel name
  1780. if (file.IndexOf(' ') > -1)
  1781. {
  1782. string channel = file.Split(' ')[0];
  1783. //if channel == "all" do it for all
  1784. file = file.Substring(channel.Length + 1);
  1785. if (channel.ToLower() == "all")
  1786. {
  1787. foreach (IceTabPage t in mainTabControl.TabPages)
  1788. {
  1789. if (t.WindowStyle == IceTabPage.WindowType.Channel)
  1790. {
  1791. if (file.StartsWith("http://"))
  1792. {
  1793. System.Net.HttpWebRequest myRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(file);
  1794. myRequest.Method = "GET";
  1795. System.Net.HttpWebResponse myResponse = (System.Net.HttpWebResponse)myRequest.GetResponse();
  1796. t.TextWindow.BackGroundImageURL = myResponse.GetResponseStream();
  1797. }
  1798. else
  1799. {
  1800. if (File.Exists(picturesFolder + System.IO.Path.DirectorySeparatorChar + file))
  1801. t.TextWindow.BackGroundImage = (picturesFolder + System.IO.Path.DirectorySeparatorChar + file);
  1802. else
  1803. t.TextWindow.BackGroundImage = "";
  1804. }
  1805. }
  1806. }
  1807. }
  1808. else
  1809. {
  1810. IceTabPage t = GetWindow(connection, channel, IceTabPage.WindowType.Channel);
  1811. if (t != null)
  1812. {
  1813. if (file.StartsWith("http://"))
  1814. {
  1815. System.Net.HttpWebRequest myRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(file);
  1816. myRequest.Method = "GET";
  1817. System.Net.HttpWebResponse myResponse = (System.Net.HttpWebResponse)myRequest.GetResponse();
  1818. t.TextWindow.BackGroundImageURL = myResponse.GetResponseStream();
  1819. }
  1820. else
  1821. {
  1822. if (File.Exists(picturesFolder + System.IO.Path.DirectorySeparatorChar + file))
  1823. t.TextWindow.BackGroundImage = (picturesFolder + System.IO.Path.DirectorySeparatorChar + file);
  1824. else
  1825. t.TextWindow.BackGroundImage = "";
  1826. }
  1827. }
  1828. }
  1829. }
  1830. else
  1831. {
  1832. //only a channel name specified, no file, erase the image
  1833. //if file == "all" clear em all
  1834. if (file.ToLower() == "all")
  1835. {
  1836. foreach (IceTabPage t in mainTabControl.TabPages)
  1837. {
  1838. if (t.WindowStyle == IceTabPage.WindowType.Channel)
  1839. t.TextWindow.BackGroundImage = "";
  1840. }
  1841. }
  1842. else
  1843. {
  1844. IceTabPage t = GetWindow(connection, file, IceTabPage.WindowType.Channel);
  1845. if (t != null)
  1846. t.TextWindow.BackGroundImage = "";
  1847. }
  1848. }
  1849. break;
  1850. case "query":
  1851. break;
  1852. case "window":
  1853. if (file.IndexOf(' ') > -1)
  1854. {
  1855. string windowName = file.Split(' ')[0];
  1856. file = file.Substring(windowName.Length + 1);
  1857. IceTabPage t = GetWindow(connection, windowName, IceTabPage.WindowType.Window);
  1858. if (t != null)
  1859. {
  1860. if (file.StartsWith("http://"))
  1861. {
  1862. System.Net.HttpWebRequest myRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(file);
  1863. myRequest.Method = "GET";
  1864. System.Net.HttpWebResponse myResponse = (System.Net.HttpWebResponse)myRequest.GetResponse();
  1865. t.TextWindow.BackGroundImageURL = myResponse.GetResponseStream();
  1866. }
  1867. else
  1868. {
  1869. if (File.Exists(picturesFolder + System.IO.Path.DirectorySeparatorChar + file))
  1870. t.TextWindow.BackGroundImage = (picturesFolder + System.IO.Path.DirectorySeparatorChar + file);
  1871. else
  1872. t.TextWindow.BackGroundImage = "";
  1873. }
  1874. }
  1875. }
  1876. else
  1877. {
  1878. IceTabPage t = GetWindow(connection, file, IceTabPage.WindowType.Window);
  1879. if (t != null)
  1880. t.TextWindow.BackGroundImage = "";
  1881. }
  1882. break;
  1883. }
  1884. }
  1885. break;
  1886. case "/unloadplugin":
  1887. if (data.Length > 0)
  1888. {
  1889. //get the plugin name, and look for it in the menu items
  1890. ToolStripMenuItem menuItem = null;
  1891. foreach (ToolStripMenuItem t in pluginsToolStripMenuItem.DropDownItems)
  1892. if (t.ToolTipText.ToLower() == data.ToLower())
  1893. menuItem = t;
  1894. if (menuItem != null)
  1895. {
  1896. //match
  1897. IPluginIceChat plugin = (IPluginIceChat)menuItem.Tag;
  1898. plugin.OnCommand -= new OutGoingCommandHandler(Plugin_OnCommand);
  1899. loadedPlugins.Remove(plugin);
  1900. menuItem.Click -= new EventHandler(OnPluginMenuItemClick);
  1901. pluginsToolStripMenuItem.DropDownItems.Remove(menuItem);
  1902. //AppDomain.Unload(plugin.domain);
  1903. //plugin.domain = null;
  1904. plugin.Dispose();
  1905. WindowMessage(null, "Console", "Unloaded Plugin - " + plugin.Name, 4, true);
  1906. }
  1907. }
  1908. break;
  1909. case "/statusplugin":
  1910. if (data.Length > 0 && data.IndexOf(' ') > 0)
  1911. {
  1912. string[] values = data.Split(new char[] { ' ' }, 2);
  1913. ToolStripMenuItem menuItem = null;
  1914. foreach (ToolStripMenuItem t in pluginsToolStripMenuItem.DropDownItems)
  1915. if (t.ToolTipText.ToLower() == values[1].ToLower())
  1916. menuItem = t;
  1917. if (menuItem != null)
  1918. {
  1919. //match
  1920. IPluginIceChat plugin = (IPluginIceChat)menuItem.Tag;
  1921. plugin.Enabled = Convert.ToBoolean(values[0]);
  1922. if (plugin.Enabled == true)
  1923. {
  1924. WindowMessage(null, "Console", "Enabled Plugin - " + plugin.Name + " v" + plugin.Version, 4, true);
  1925. //remove the icon
  1926. menuItem.Image = null;
  1927. }
  1928. else
  1929. {
  1930. WindowMessage(null, "Console", "Disabled Plugin - " + plugin.Name + " v" + plugin.Version, 4, true);
  1931. menuItem.Image = StaticMethods.LoadResourceImage("CloseButton.png");
  1932. }
  1933. }
  1934. }
  1935. break;
  1936. case "/loadplugin":
  1937. if (data.Length > 0)
  1938. {
  1939. loadPlugin(pluginsFolder + System.IO.Path.DirectorySeparatorChar + data);
  1940. }
  1941. break;
  1942. case "/reload":
  1943. if (data.Length > 0)
  1944. {
  1945. switch (data)
  1946. {
  1947. case "alias":
  1948. case "aliases":
  1949. CurrentWindowMessage(connection, "Aliases file reloaded", 4, true);
  1950. LoadAliases();
  1951. break;
  1952. case "popup":
  1953. case "popups":
  1954. CurrentWindowMessage(connection, "Popups file reloaded", 4, true);
  1955. LoadPopups();
  1956. break;
  1957. case "emoticon":
  1958. case "emoticons":
  1959. CurrentWindowMessage(connection, "Emoticons file reloaded", 4, true);
  1960. LoadEmoticons();
  1961. break;
  1962. case "sound":
  1963. case "sounds":
  1964. CurrentWindowMessage(connection, "Sounds file reloaded", 4, true);
  1965. LoadSounds();
  1966. break;
  1967. case "color":
  1968. case "colors":
  1969. CurrentWindowMessage(connection, "Colors file reloaded", 4, true);
  1970. LoadColors();
  1971. toolStripMain.BackColor = IrcColor.colors[iceChatColors.ToolbarBackColor];
  1972. menuMainStrip.BackColor = IrcColor.colors[iceChatColors.MenubarBackColor];
  1973. statusStripMain.BackColor = IrcColor.colors[iceChatColors.StatusbarBackColor];
  1974. toolStripStatus.ForeColor = IrcColor.colors[iceChatColors.StatusbarForeColor];
  1975. inputPanel.SetInputBoxColors();
  1976. channelList.SetListColors();
  1977. buddyList.SetListColors();
  1978. break;
  1979. case "font":
  1980. case "fonts":
  1981. CurrentWindowMessage(connection, "Fonts file reloaded", 4, true);
  1982. LoadFonts();
  1983. nickList.Font = new Font(iceChatFonts.FontSettings[3].FontName, iceChatFonts.FontSettings[3].FontSize);
  1984. serverTree.Font = new Font(iceChatFonts.FontSettings[4].FontName, iceChatFonts.FontSettings[4].FontSize);
  1985. menuMainStrip.Font = new Font(iceChatFonts.FontSettings[7].FontName, iceChatFonts.FontSettings[7].FontSize);
  1986. break;
  1987. }
  1988. }
  1989. break;
  1990. /*
  1991. case "/reloadplugin":
  1992. if (data.Length > 0)
  1993. {
  1994. //get the plugin name, and look for it in the menu items
  1995. ToolStripMenuItem menuItem = null;
  1996. foreach (ToolStripMenuItem t in pluginsToolStripMenuItem.DropDownItems)
  1997. if (t.ToolTipText.ToLower() == data.ToLower())
  1998. menuItem = t;
  1999. if (menuItem != null)
  2000. {
  2001. //match
  2002. IPluginIceChat plugin = (IPluginIceChat)menuItem.Tag;
  2003. plugin.OnCommand -= new OutGoingCommandHandler(Plugin_OnCommand);
  2004. loadedPlugins.Remove(plugin);
  2005. plugin.Dispose();
  2006. Type ObjType = null;
  2007. Assembly ass = null;
  2008. try
  2009. {
  2010. //reload the plugin
  2011. ass = Assembly.LoadFile(pluginsFolder + System.IO.Path.DirectorySeparatorChar + menuItem.ToolTipText);
  2012. //System.Diagnostics.Debug.WriteLine(ass.ToString());
  2013. if (ass != null)
  2014. {
  2015. ObjType = ass.GetType("IceChatPlugin.Plugin");
  2016. }
  2017. else
  2018. {
  2019. System.Diagnostics.Debug.WriteLine("assembly is null");
  2020. }
  2021. }
  2022. catch (Exception ex)
  2023. {
  2024. WriteErrorFile(connection, "ReLoadPlugins Cast:", ex);
  2025. }
  2026. try
  2027. {
  2028. // OK Lets create the object as we have the Report Type
  2029. if (ObjType != null)
  2030. {
  2031. //System.Diagnostics.Debug.WriteLine("create instance of " + args);
  2032. IPluginIceChat ipi = (IPluginIceChat)Activator.CreateInstance(ObjType);
  2033. ipi.MainForm = this;
  2034. ipi.MainMenuStrip = this.MainMenuStrip;
  2035. ipi.CurrentFolder = currentFolder;
  2036. WindowMessage(null, "Console", "Re-Loaded Plugin - " + ipi.Name + " v" + ipi.Version + " by " + ipi.Author, 4, true);
  2037. menuItem.Tag = ipi;
  2038. ipi.OnCommand += new OutGoingCommandHandler(Plugin_OnCommand);
  2039. ipi.Initialize();
  2040. loadedPlugins.Add(ipi);
  2041. }
  2042. else
  2043. {
  2044. System.Diagnostics.Debug.WriteLine("obj type is null:" + menuItem.ToolTipText);
  2045. }
  2046. }
  2047. catch (Exception ex)
  2048. {
  2049. WriteErrorFile(connection, "ReLoadPlugins", ex);
  2050. }
  2051. }
  2052. }
  2053. break;
  2054. */
  2055. case "/addtext":
  2056. if (data.Length > 0)
  2057. {
  2058. inputPanel.AppendText(data);
  2059. FocusInputBox();
  2060. }
  2061. break;
  2062. case "/ame": //me command for all channels
  2063. if (connection != null && data.Length > 0)
  2064. {
  2065. foreach (IceTabPage t in FormMain.Instance.TabMain.TabPages)
  2066. {
  2067. if (t.WindowStyle == IceTabPage.WindowType.Channel)
  2068. {
  2069. if (t.Connection == connection)
  2070. {
  2071. SendData(connection, "PRIVMSG " + t.TabCaption + " :ACTION " + data + "");
  2072. string msg = GetMessageFormat("Self Channel Action");
  2073. msg = msg.Replace("$nick", t.Connection.ServerSetting.NickName).Replace("$channel", t.TabCaption);
  2074. msg = msg.Replace("$message", data);
  2075. t.TextWindow.AppendText(msg, 1);
  2076. t.TextWindow.ScrollToBottom();
  2077. t.LastMessageType = ServerMessageType.Action;
  2078. }
  2079. }
  2080. }
  2081. }
  2082. break;
  2083. case "/amsg": //send a message to all channels
  2084. if (connection != null && data.Length > 0)
  2085. {
  2086. foreach (IceTabPage t in FormMain.Instance.TabMain.TabPages)
  2087. {
  2088. if (t.WindowStyle == IceTabPage.WindowType.Channel)
  2089. {
  2090. if (t.Connection == connection)
  2091. {
  2092. SendData(connection, "PRIVMSG " + t.TabCaption + " :" + data);
  2093. string msg = GetMessageFormat("Self Channel Message");
  2094. msg = msg.Replace("$nick", t.Connection.ServerSetting.NickName).Replace("$channel", t.TabCaption);
  2095. //assign $color to the nickname
  2096. if (msg.Contains("$color"))
  2097. {
  2098. User u = CurrentWindow.GetNick(t.Connection.ServerSetting.NickName);
  2099. for (int i = 0; i < u.Level.Length; i++)
  2100. {
  2101. if (u.Level[i])
  2102. {
  2103. if (connection.ServerSetting.StatusModes[0][i] == 'v')
  2104. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelVoiceColor.ToString("00"));
  2105. else if (connection.ServerSetting.StatusModes[0][i] == 'h')
  2106. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelHalfOpColor.ToString("00"));
  2107. else if (connection.ServerSetting.StatusModes[0][i] == 'o')
  2108. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelOpColor.ToString("00"));
  2109. else if (connection.ServerSetting.StatusModes[0][i] == 'a')
  2110. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelAdminColor.ToString("00"));
  2111. else if (connection.ServerSetting.StatusModes[0][i] == 'q')
  2112. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelOwnerColor.ToString("00"));
  2113. else
  2114. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelOwnerColor.ToString("00"));
  2115. break;
  2116. }
  2117. }
  2118. if (msg.Contains("$color"))
  2119. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelRegularColor.ToString("00"));
  2120. }
  2121. msg = msg.Replace("$status", CurrentWindow.GetNick(t.Connection.ServerSetting.NickName).ToString().Replace(t.Connection.ServerSetting.NickName, ""));
  2122. msg = msg.Replace("$message", data);
  2123. t.TextWindow.AppendText(msg, 1);
  2124. t.TextWindow.ScrollToBottom();
  2125. t.LastMessageType = ServerMessageType.Message;
  2126. }
  2127. }
  2128. }
  2129. }
  2130. break;
  2131. case "/anick":
  2132. if (data.Length > 0)
  2133. {
  2134. foreach (IRCConnection c in serverTree.ServerConnections.Values)
  2135. if (c.IsConnected)
  2136. SendData(c, "NICK " + data);
  2137. }
  2138. break;
  2139. case "/autojoin":
  2140. if (connection != null)
  2141. {
  2142. if (data.Length == 0)
  2143. {
  2144. if (connection.ServerSetting.AutoJoinChannels != null)
  2145. {
  2146. foreach (string chan in connection.ServerSetting.AutoJoinChannels)
  2147. {
  2148. if (!chan.StartsWith(";"))
  2149. SendData(connection, "JOIN " + chan);
  2150. }
  2151. }
  2152. }
  2153. else
  2154. {
  2155. if (connection.ServerSetting.AutoJoinChannels == null)
  2156. {
  2157. //we have no autojoin channels, so just add it
  2158. connection.ServerSetting.AutoJoinChannels = new string[1];
  2159. connection.ServerSetting.AutoJoinChannels[0] = data;
  2160. CurrentWindowMessage(connection, data + " is added to the Autojoin List", 7, true);
  2161. serverTree.SaveServers(serverTree.ServersCollection);
  2162. }
  2163. else
  2164. {
  2165. //check if it is in the list first
  2166. bool Exists = false;
  2167. bool Disabled = false;
  2168. string[] oldAutoJoin = new string[connection.ServerSetting.AutoJoinChannels.Length];
  2169. int i = 0;
  2170. foreach (string chan in connection.ServerSetting.AutoJoinChannels)
  2171. {
  2172. if (chan.ToLower() == data.ToLower())
  2173. {
  2174. //already in the list
  2175. Exists = true;
  2176. oldAutoJoin[i] = chan;
  2177. CurrentWindowMessage(connection, data + " is already in the Autojoin List", 7, true);
  2178. }
  2179. else if (chan.ToLower() == (";" + data.ToLower()))
  2180. {
  2181. //already in the list, but disabled
  2182. //so lets enable it
  2183. Disabled = true;
  2184. oldAutoJoin[i] = chan.Substring(1);
  2185. CurrentWindowMessage(connection, data + " is enabled in the Autojoin List", 7, true);
  2186. }
  2187. else
  2188. oldAutoJoin[i] = chan;
  2189. i++;
  2190. }
  2191. if (!Exists)
  2192. {
  2193. //add a new item
  2194. connection.ServerSetting.AutoJoinChannels = new string[connection.ServerSetting.AutoJoinChannels.Length + 1];
  2195. i = 0;
  2196. foreach (string chan in oldAutoJoin)
  2197. {
  2198. connection.ServerSetting.AutoJoinChannels[i] = chan;
  2199. i++;
  2200. }
  2201. connection.ServerSetting.AutoJoinChannels[i] = data;
  2202. CurrentWindowMessage(connection, data + " is added to the Autojoin List", 7, true);
  2203. serverTree.SaveServers(serverTree.ServersCollection);
  2204. }
  2205. else if (Disabled)
  2206. {
  2207. connection.ServerSetting.AutoJoinChannels = new string[connection.ServerSetting.AutoJoinChannels.Length];
  2208. i = 0;
  2209. foreach (string chan in oldAutoJoin)
  2210. {
  2211. connection.ServerSetting.AutoJoinChannels[i] = chan;
  2212. }
  2213. serverTree.SaveServers(serverTree.ServersCollection);
  2214. }
  2215. }
  2216. }
  2217. }
  2218. break;
  2219. case "/autoperform":
  2220. if (connection != null)
  2221. {
  2222. if (connection.ServerSetting.AutoPerform != null)
  2223. {
  2224. foreach (string ap in connection.ServerSetting.AutoPerform)
  2225. {
  2226. string autoCommand = ap.Replace("\r", String.Empty);
  2227. if (!autoCommand.StartsWith(";"))
  2228. ParseOutGoingCommand(connection, autoCommand);
  2229. }
  2230. }
  2231. }
  2232. break;
  2233. case "/aaway":
  2234. foreach (IRCConnection c in serverTree.ServerConnections.Values)
  2235. {
  2236. if (c.IsConnected)
  2237. {
  2238. ParseOutGoingCommand(c, "/away " + data);
  2239. }
  2240. }
  2241. break;
  2242. case "/away":
  2243. if (connection != null)
  2244. {
  2245. if (connection.ServerSetting.Away)
  2246. {
  2247. connection.ServerSetting.Away = false;
  2248. ParseOutGoingCommand(connection, "/nick " + connection.ServerSetting.DefaultNick);
  2249. TimeSpan t = DateTime.Now.Subtract(connection.ServerSetting.AwayStart);
  2250. string s = t.Seconds.ToString() + " secs";
  2251. if (t.Minutes > 0)
  2252. s = t.Minutes.ToString() + " mins " + s;
  2253. if (t.Hours > 0)
  2254. s = t.Hours.ToString() + " hrs " + s;
  2255. if (t.Days > 0)
  2256. s = t.Days.ToString() + " days " + s;
  2257. ParseOutGoingCommand(connection, "/ame is no longer away : Gone for " + s);
  2258. }
  2259. else
  2260. {
  2261. connection.ServerSetting.Away = true;
  2262. connection.ServerSetting.DefaultNick = connection.ServerSetting.NickName;
  2263. connection.ServerSetting.AwayStart = System.DateTime.Now;
  2264. ParseOutGoingCommand(connection, "/nick " + connection.ServerSetting.AwayNickName);
  2265. if (data.Length == 0)
  2266. ParseOutGoingCommand(connection, "/ame is set as away");
  2267. else
  2268. ParseOutGoingCommand(connection, "/ame is set as away : Reason(" + data + ")");
  2269. }
  2270. }
  2271. break;
  2272. case "/ban": // /ban #channel nick|address /mode #channel +b host
  2273. if (connection != null && data.IndexOf(' ') > 0)
  2274. {
  2275. string channel = data.Split(' ')[0];
  2276. string host = data.Split(' ')[1];
  2277. ParseOutGoingCommand(connection, "/mode " + channel + " +b " + host);
  2278. }
  2279. break;
  2280. case "/browser":
  2281. if (data.Length > 0)
  2282. {
  2283. if (data.StartsWith("http"))
  2284. System.Diagnostics.Process.Start(data);
  2285. else
  2286. System.Diagnostics.Process.Start("http://" + data);
  2287. }
  2288. break;
  2289. case "/buddylist":
  2290. case "/notify":
  2291. //add a nickname to the buddy list
  2292. if (connection != null && data.Length > 0 && data.IndexOf(" ") == -1)
  2293. {
  2294. //check if the nickname is already in the buddy list
  2295. if (connection.ServerSetting.BuddyList != null)
  2296. {
  2297. foreach (BuddyListItem buddy in connection.ServerSetting.BuddyList)
  2298. {
  2299. if (!buddy.Nick.StartsWith(";"))
  2300. if (buddy.Nick.ToLower() == data.ToLower())
  2301. return;
  2302. else
  2303. if (buddy.Nick.Substring(1).ToLower() == data.ToLower())
  2304. return;
  2305. }
  2306. }
  2307. //add in the new buddy list item
  2308. BuddyListItem b = new BuddyListItem();
  2309. b.Nick = data;
  2310. BuddyListItem[] buddies = connection.ServerSetting.BuddyList;
  2311. Array.Resize(ref buddies, buddies.Length + 1);
  2312. buddies[buddies.Length - 1] = b;
  2313. connection.ServerSetting.BuddyList = buddies;
  2314. serverTree.SaveServers(serverTree.ServersCollection);
  2315. connection.BuddyListCheck();
  2316. }
  2317. break;
  2318. case "/chaninfo":
  2319. if (connection != null)
  2320. {
  2321. if (data.Length > 0)
  2322. {
  2323. IceTabPage t = GetWindow(connection, data, IceTabPage.WindowType.Channel);
  2324. if (t != null)
  2325. {
  2326. FormChannelInfo fci = new FormChannelInfo(t);
  2327. SendData(connection, "MODE " + t.TabCaption + " +b");
  2328. //check if mode (e) exists for Exception List
  2329. if (connection.ServerSetting.ChannelModeParam.Contains("e"))
  2330. SendData(connection, "MODE " + t.TabCaption + " +e");
  2331. SendData(connection, "TOPIC :" + t.TabCaption);
  2332. fci.ShowDialog(this);
  2333. }
  2334. }
  2335. else
  2336. {
  2337. //check if current window is channel
  2338. if (CurrentWindowType == IceTabPage.WindowType.Channel)
  2339. {
  2340. FormChannelInfo fci = new FormChannelInfo(CurrentWindow);
  2341. SendData(connection, "MODE " + CurrentWindow.TabCaption + " +b");
  2342. //check if mode (e) exists for Exception List
  2343. if (connection.ServerSetting.ChannelModeParam.Contains("e"))
  2344. SendData(connection, "MODE " + CurrentWindow.TabCaption + " +e");
  2345. SendData(connection, "TOPIC :" + CurrentWindow.TabCaption);
  2346. fci.ShowDialog(this);
  2347. }
  2348. }
  2349. }
  2350. break;
  2351. case "/clear":
  2352. if (data.Length == 0)
  2353. {
  2354. if (CurrentWindowType != IceTabPage.WindowType.Console)
  2355. CurrentWindow.TextWindow.ClearTextWindow();
  2356. else
  2357. {
  2358. //find the current console tab window
  2359. mainTabControl.GetTabPage("Console").CurrentConsoleWindow().ClearTextWindow();
  2360. }
  2361. }
  2362. else
  2363. {
  2364. //find a match
  2365. if (data == "Console")
  2366. {
  2367. mainTabControl.GetTabPage("Console").CurrentConsoleWindow().ClearTextWindow();
  2368. return;
  2369. }
  2370. else if (data.ToLower() == "all console")
  2371. {
  2372. //clear all the console windows and channel/queries
  2373. foreach (ConsoleTab c in mainTabControl.GetTabPage("Console").ConsoleTab.TabPages)
  2374. ((TextWindow)c.Controls[0]).ClearTextWindow();
  2375. }
  2376. IceTabPage t = GetWindow(connection, data, IceTabPage.WindowType.Channel);
  2377. if (t != null)
  2378. t.TextWindow.ClearTextWindow();
  2379. else
  2380. {
  2381. IceTabPage q = GetWindow(connection, data, IceTabPage.WindowType.Query);
  2382. if (q != null)
  2383. {
  2384. q.TextWindow.ClearTextWindow();
  2385. return;
  2386. }
  2387. IceTabPage dcc = GetWindow(connection, data, IceTabPage.WindowType.DCCChat);
  2388. if (dcc != null)
  2389. dcc.TextWindow.ClearTextWindow();
  2390. }
  2391. }
  2392. break;
  2393. case "/clearall":
  2394. //clear all the text windows
  2395. for (int i = mainTabControl.TabPages.Count - 1; i >= 0; i--)
  2396. {
  2397. if (mainTabControl.TabPages[i].WindowStyle == IceTabPage.WindowType.Channel || mainTabControl.TabPages[i].WindowStyle == IceTabPage.WindowType.Query)
  2398. {
  2399. mainTabControl.TabPages[i].TextWindow.ClearTextWindow();
  2400. }
  2401. else if (mainTabControl.TabPages[i].WindowStyle == IceTabPage.WindowType.Console)
  2402. {
  2403. //clear all console windows
  2404. foreach (ConsoleTab c in mainTabControl.GetTabPage("Console").ConsoleTab.TabPages)
  2405. {
  2406. ((TextWindow)c.Controls[0]).ClearTextWindow();
  2407. }
  2408. }
  2409. }
  2410. break;
  2411. case "/close":
  2412. if (connection != null && data.Length > 0)
  2413. {
  2414. //check if it is a channel list window
  2415. if (data == "Channels")
  2416. {
  2417. IceTabPage c = GetWindow(connection, "", IceTabPage.WindowType.ChannelList);
  2418. if (c != null)
  2419. RemoveWindow(connection, "", IceTabPage.WindowType.ChannelList);
  2420. return;
  2421. }
  2422. //check if it is a query window
  2423. IceTabPage q = GetWindow(connection, data, IceTabPage.WindowType.Query);
  2424. if (q != null)
  2425. {
  2426. RemoveWindow(connection, q.TabCaption, IceTabPage.WindowType.Query);
  2427. return;
  2428. }
  2429. //check if it is a dcc chat window
  2430. IceTabPage dcc = GetWindow(connection, data, IceTabPage.WindowType.DCCChat);
  2431. if (dcc != null)
  2432. RemoveWindow(connection, dcc.TabCaption, IceTabPage.WindowType.DCCChat);
  2433. }
  2434. else if (connection != null)
  2435. {
  2436. //check if current window is channel/query/dcc chat
  2437. if (CurrentWindowType == IceTabPage.WindowType.Query)
  2438. RemoveWindow(connection, CurrentWindow.TabCaption, CurrentWindow.WindowStyle);
  2439. else if (CurrentWindowType == IceTabPage.WindowType.DCCChat)
  2440. RemoveWindow(connection, CurrentWindow.TabCaption, CurrentWindow.WindowStyle);
  2441. else if (CurrentWindowType == IceTabPage.WindowType.Channel)
  2442. {
  2443. SendData(connection, "PART " + CurrentWindow.TabCaption);
  2444. RemoveWindow(connection, CurrentWindow.TabCaption, CurrentWindow.WindowStyle);
  2445. }
  2446. }
  2447. else
  2448. {
  2449. //check if the current window is the debug window
  2450. if (CurrentWindowType == IceTabPage.WindowType.Debug)
  2451. {
  2452. RemoveWindow(null, "Debug", IceTabPage.WindowType.Debug);
  2453. }
  2454. }
  2455. break;
  2456. case "/closequery":
  2457. if (connection != null)
  2458. {
  2459. for (int i = mainTabControl.TabPages.Count - 1; i >= 0; i--)
  2460. {
  2461. if (mainTabControl.TabPages[i].WindowStyle == IceTabPage.WindowType.Query)
  2462. {
  2463. if (mainTabControl.TabPages[i].Connection == connection)
  2464. {
  2465. RemoveWindow(connection, mainTabControl.TabPages[i].TabCaption, IceTabPage.WindowType.Query);
  2466. }
  2467. }
  2468. }
  2469. }
  2470. break;
  2471. case "/closeallquery":
  2472. if (connection != null)
  2473. {
  2474. for (int i = mainTabControl.TabPages.Count - 1; i >= 0; i--)
  2475. {
  2476. if (mainTabControl.TabPages[i].WindowStyle == IceTabPage.WindowType.Query)
  2477. {
  2478. RemoveWindow(connection, mainTabControl.TabPages[i].TabCaption, IceTabPage.WindowType.Query);
  2479. }
  2480. }
  2481. }
  2482. break;
  2483. case "/ctcp":
  2484. if (connection != null && data.IndexOf(' ') > 0)
  2485. {
  2486. //ctcp nick ctcptype
  2487. string nick = data.Substring(0, data.IndexOf(' '));
  2488. //get the message
  2489. string ctcp = data.Substring(data.IndexOf(' ') + 1);
  2490. string msg = GetMessageFormat("Ctcp Send");
  2491. msg = msg.Replace("$nick", nick); ;
  2492. msg = msg.Replace("$ctcp", ctcp.ToUpper());
  2493. CurrentWindowMessage(connection, msg, 7, true);
  2494. if (ctcp.ToUpper() == "PING")
  2495. SendData(connection, "PRIVMSG " + nick + " :" + ctcp.ToUpper() + " " + System.Environment.TickCount.ToString() + "");
  2496. else
  2497. SendData(connection, "PRIVMSG " + nick + " " + ctcp.ToUpper() + "");
  2498. }
  2499. break;
  2500. case "/dcc":
  2501. if (connection != null && data.IndexOf(' ') > 0)
  2502. {
  2503. //get the type of dcc
  2504. string dccType = data.Substring(0, data.IndexOf(' ')).ToUpper();
  2505. //get who it is being sent to
  2506. string nick = data.Substring(data.IndexOf(' ') + 1);
  2507. switch (dccType)
  2508. {
  2509. case "CHAT":
  2510. //start a dcc chat
  2511. if (nick.IndexOf(' ') == -1) //make sure no space in the nick name
  2512. {
  2513. //check if we already have a dcc chat open with this person
  2514. if (!mainTabControl.WindowExists(connection, nick, IceTabPage.WindowType.DCCChat))
  2515. {
  2516. //create a new window
  2517. AddWindow(connection, nick, IceTabPage.WindowType.DCCChat);
  2518. IceTabPage t = GetWindow(connection, nick, IceTabPage.WindowType.DCCChat);
  2519. if (t != null)
  2520. {
  2521. t.RequestDCCChat();
  2522. string msg = GetMessageFormat("DCC Chat Outgoing");
  2523. msg = msg.Replace("$nick", nick);
  2524. t.TextWindow.AppendText(msg, 1);
  2525. t.TextWindow.ScrollToBottom();
  2526. }
  2527. }
  2528. else
  2529. {
  2530. mainTabControl.SelectTab(GetWindow(connection, nick, IceTabPage.WindowType.DCCChat));
  2531. serverTree.SelectTab(mainTabControl.CurrentTab, false);
  2532. //see if it is connected or not
  2533. IceTabPage dcc = GetWindow(connection, nick, IceTabPage.WindowType.DCCChat);
  2534. if (dcc != null)
  2535. {
  2536. if (!dcc.IsConnected)
  2537. {
  2538. dcc.RequestDCCChat();
  2539. string msg = GetMessageFormat("DCC Chat Outgoing");
  2540. msg = msg.Replace("$nick", nick);
  2541. dcc.TextWindow.AppendText(msg, 1);
  2542. dcc.TextWindow.ScrollToBottom();
  2543. }
  2544. }
  2545. }
  2546. }
  2547. break;
  2548. case "SEND":
  2549. //was a filename specified, if not try and select one
  2550. string file;
  2551. if (nick.IndexOf(' ') > 0)
  2552. {
  2553. file = nick.Substring(nick.IndexOf(' ') + 1);
  2554. nick = nick.Substring(0,nick.IndexOf(' '));
  2555. //see if the file exists
  2556. if (!File.Exists(file))
  2557. {
  2558. //file does not exists, just quit
  2559. //try from the dccsend folder
  2560. if (File.Exists(iceChatOptions.DCCSendFolder + Path.DirectorySeparatorChar + file))
  2561. file=iceChatOptions.DCCSendFolder + Path.DirectorySeparatorChar + file;
  2562. else
  2563. return;
  2564. }
  2565. }
  2566. else
  2567. {
  2568. //ask for a file name
  2569. OpenFileDialog dialog = new OpenFileDialog();
  2570. dialog.InitialDirectory = iceChatOptions.DCCSendFolder;
  2571. dialog.CheckFileExists = true;
  2572. dialog.CheckPathExists = true;
  2573. if (dialog.ShowDialog() == DialogResult.OK)
  2574. {
  2575. //returns the full path
  2576. System.Diagnostics.Debug.WriteLine(dialog.FileName);
  2577. file = dialog.FileName;
  2578. }
  2579. else
  2580. return;
  2581. }
  2582. //more to it, maybe a file to send
  2583. if (!mainTabControl.WindowExists(null, "DCC Files", IceTabPage.WindowType.DCCFile))
  2584. AddWindow(null, "DCC Files", IceTabPage.WindowType.DCCFile);
  2585. IceTabPage tt = GetWindow(null, "DCC Files", IceTabPage.WindowType.DCCFile);
  2586. if (tt != null)
  2587. ((IceTabPageDCCFile)tt).RequestDCCFile(connection, nick, file);
  2588. break;
  2589. }
  2590. }
  2591. break;
  2592. case "/describe": //me command for a specific channel
  2593. if (connection != null && data.IndexOf(' ') > 0)
  2594. {
  2595. //get the channel name
  2596. string channel = data.Substring(0, data.IndexOf(' '));
  2597. //get the message
  2598. string message = data.Substring(data.IndexOf(' ') + 1);
  2599. //check for the channel
  2600. IceTabPage t = GetWindow(connection, channel, IceTabPage.WindowType.Channel);
  2601. if (t != null)
  2602. {
  2603. SendData(connection, "PRIVMSG " + t.TabCaption + " :ACTION " + message + "");
  2604. string msg = GetMessageFormat("Self Channel Action");
  2605. msg = msg.Replace("$nick", inputPanel.CurrentConnection.ServerSetting.NickName).Replace("$channel", t.TabCaption);
  2606. msg = msg.Replace("$message", message);
  2607. t.TextWindow.AppendText(msg, 1);
  2608. t.TextWindow.ScrollToBottom();
  2609. t.LastMessageType = ServerMessageType.Action;
  2610. }
  2611. }
  2612. break;
  2613. case "/dns":
  2614. if (data.Length > 0)
  2615. {
  2616. if (data.IndexOf(".") > 0)
  2617. {
  2618. //dns a host
  2619. try
  2620. {
  2621. System.Net.IPAddress[] addresslist = System.Net.Dns.GetHostAddresses(data);
  2622. ParseOutGoingCommand(connection, "/echo " + data + " resolved to " + addresslist.Length + " address(es)");
  2623. foreach (System.Net.IPAddress address in addresslist)
  2624. ParseOutGoingCommand(connection, "/echo -> " + address.ToString());
  2625. }
  2626. catch (Exception)
  2627. {
  2628. ParseOutGoingCommand(connection, "/echo " + data + " does not resolve (unknown address)");
  2629. }
  2630. }
  2631. else
  2632. {
  2633. //dns a nickname (send a userhost)
  2634. SendData(connection, "USERHOST " + data);
  2635. }
  2636. }
  2637. break;
  2638. case "/echo":
  2639. //currently just echo to the current window
  2640. if (data.Length > 0)
  2641. {
  2642. if (CurrentWindowType == IceTabPage.WindowType.Channel || CurrentWindowType == IceTabPage.WindowType.Query)
  2643. {
  2644. string msg = GetMessageFormat("User Echo");
  2645. msg = msg.Replace("$message", data);
  2646. CurrentWindow.TextWindow.AppendText(msg, 1);
  2647. }
  2648. else if (CurrentWindowType == IceTabPage.WindowType.Console)
  2649. {
  2650. string msg = GetMessageFormat("User Echo");
  2651. msg = msg.Replace("$message", data);
  2652. mainTabControl.GetTabPage("Console").CurrentConsoleWindow().AppendText(msg, 1);
  2653. }
  2654. else if (CurrentWindowType == IceTabPage.WindowType.DCCChat)
  2655. {
  2656. string msg = GetMessageFormat("User Echo");
  2657. msg = msg.Replace("$message", data);
  2658. CurrentWindow.TextWindow.AppendText(msg, 1);
  2659. }
  2660. }
  2661. break;
  2662. case "/flash":
  2663. //used to flash a specific channel or query
  2664. if (connection != null && data.Length > 0)
  2665. {
  2666. string window = data;
  2667. bool flashWindow = true;
  2668. if (data.IndexOf(" ") > 0)
  2669. {
  2670. window = data.Substring(0, data.IndexOf(' '));
  2671. string t = data.Substring(data.IndexOf(' ') + 1);
  2672. if (t.ToLower() == "off")
  2673. flashWindow = false;
  2674. }
  2675. //check if it is a channel window
  2676. IceTabPage c = GetWindow(connection, window, IceTabPage.WindowType.Channel);
  2677. if (c != null)
  2678. {
  2679. c.FlashTab = flashWindow;
  2680. mainTabControl.Invalidate();
  2681. serverTree.Invalidate();
  2682. }
  2683. else
  2684. {
  2685. //check if it is a query
  2686. IceTabPage q = GetWindow(connection, window, IceTabPage.WindowType.Query);
  2687. if (q != null)
  2688. {
  2689. q.FlashTab = flashWindow;
  2690. mainTabControl.Invalidate();
  2691. serverTree.Invalidate();
  2692. }
  2693. }
  2694. }
  2695. break;
  2696. case "/flashtray":
  2697. //check if we are minimized
  2698. if (this.WindowState == FormWindowState.Minimized)
  2699. {
  2700. this.flashTaskBarIconTimer.Enabled = true;
  2701. this.flashTaskBarIconTimer.Start();
  2702. }
  2703. if (this.notifyIcon.Visible == true)
  2704. {
  2705. this.flashTrayIconTimer.Enabled = true;
  2706. this.flashTrayIconTimer.Start();
  2707. //show a message in a balloon
  2708. if (data.Length > 0)
  2709. {
  2710. this.notifyIcon.BalloonTipTitle = "IceChat 9";
  2711. this.notifyIcon.BalloonTipText = data;
  2712. this.notifyIcon.ShowBalloonTip(1000);
  2713. }
  2714. }
  2715. break;
  2716. case "/font":
  2717. //change the font of the current window
  2718. //check if data is a channel
  2719. if (connection != null && data.Length > 0)
  2720. {
  2721. if (data.IndexOf(' ') == -1)
  2722. {
  2723. IceTabPage t = GetWindow(connection, data, IceTabPage.WindowType.Channel);
  2724. if (t != null)
  2725. {
  2726. //bring up a font dialog
  2727. FontDialog fd = new FontDialog();
  2728. //load the current font
  2729. fd.Font = t.TextWindow.Font;
  2730. if (fd.ShowDialog() != DialogResult.Cancel && fd.Font.Style == FontStyle.Regular)
  2731. {
  2732. t.TextWindow.Font = fd.Font;
  2733. }
  2734. }
  2735. }
  2736. }
  2737. break;
  2738. case "/forcequit":
  2739. if (connection != null)
  2740. {
  2741. connection.AttemptReconnect = false;
  2742. connection.ForceDisconnect();
  2743. }
  2744. break;
  2745. case "/google":
  2746. if (data.Length > 0)
  2747. System.Diagnostics.Process.Start("http://www.google.com/search?q=" + data);
  2748. else
  2749. System.Diagnostics.Process.Start("http://www.google.com");
  2750. break;
  2751. case "/hop":
  2752. if (connection != null && data.Length == 0)
  2753. {
  2754. if (CurrentWindowType == IceTabPage.WindowType.Channel)
  2755. {
  2756. temp = CurrentWindow.TabCaption;
  2757. SendData(connection, "PART " + temp);
  2758. ParseOutGoingCommand(connection, "/timer joinhop 1 1 /join " + temp);
  2759. }
  2760. }
  2761. else
  2762. {
  2763. IceTabPage t = GetWindow(connection, data, IceTabPage.WindowType.Channel);
  2764. if (t != null)
  2765. {
  2766. SendData(connection, "PART " + t.TabCaption);
  2767. ParseOutGoingCommand(connection, "/timer joinhop 1 1 /join " + t.TabCaption);
  2768. }
  2769. }
  2770. break;
  2771. case "/icechat":
  2772. if (connection != null)
  2773. ParseOutGoingCommand(connection, "/me is using " + ProgramID + " " + VersionID);
  2774. else
  2775. ParseOutGoingCommand(connection, "/echo using " + ProgramID + " " + VersionID);
  2776. break;
  2777. case "/icepath":
  2778. //To get current Folder and paste it into /me
  2779. if (connection != null)
  2780. ParseOutGoingCommand(connection, "/me Build Path = " + Directory.GetCurrentDirectory());
  2781. else
  2782. ParseOutGoingCommand(connection, "/echo Build Path = " + Directory.GetCurrentDirectory());
  2783. break;
  2784. case "/ignore":
  2785. if (connection != null)
  2786. {
  2787. if (data.Length > 0)
  2788. {
  2789. //check if just a nick/host , no extra params
  2790. if (data.IndexOf(" ") == -1)
  2791. {
  2792. //check if already in ignore list or not
  2793. for (int i = 0; i < connection.ServerSetting.IgnoreList.Length;i++ )
  2794. {
  2795. string checkNick = connection.ServerSetting.IgnoreList[i];
  2796. if (connection.ServerSetting.IgnoreList[i].StartsWith(";"))
  2797. checkNick = checkNick.Substring(1);
  2798. if (checkNick.ToLower() == data.ToLower())
  2799. {
  2800. if (connection.ServerSetting.IgnoreList[i].StartsWith(";"))
  2801. connection.ServerSetting.IgnoreList[i] = checkNick;
  2802. else
  2803. connection.ServerSetting.IgnoreList[i] = ";" + checkNick;
  2804. serverTree.SaveServers(serverTree.ServersCollection);
  2805. return;
  2806. }
  2807. }
  2808. //no match found, add the new item to the IgnoreList
  2809. string[] ignores = connection.ServerSetting.IgnoreList;
  2810. Array.Resize(ref ignores, ignores.Length + 1);
  2811. ignores[ignores.Length - 1] = data;
  2812. connection.ServerSetting.IgnoreList = ignores;
  2813. serverTree.SaveServers(serverTree.ServersCollection);
  2814. }
  2815. }
  2816. }
  2817. break;
  2818. case "/join":
  2819. if (connection != null && data.Length > 0)
  2820. SendData(connection, "JOIN " + data);
  2821. break;
  2822. case "/kick":
  2823. if (connection != null && data.Length > 0)
  2824. {
  2825. //kick #channel nick reason
  2826. if (data.IndexOf(' ') > 0)
  2827. {
  2828. //get the channel
  2829. temp = data.Substring(0, data.IndexOf(' '));
  2830. //check if temp is a channel or not
  2831. if (Array.IndexOf(connection.ServerSetting.ChannelTypes, temp[0]) == -1)
  2832. {
  2833. //temp is not a channel, substitute with current channel
  2834. //make sure we are in a channel
  2835. if (CurrentWindow.WindowStyle == IceTabPage.WindowType.Channel)
  2836. {
  2837. temp = CurrentWindow.TabCaption;
  2838. if (data.IndexOf(' ') > 0)
  2839. {
  2840. //there is a kick reason
  2841. string msg = data.Substring(data.IndexOf(' ') + 1);
  2842. data = data.Substring(0, data.IndexOf(' '));
  2843. SendData(connection, "KICK " + temp + " " + data + " :" + msg);
  2844. }
  2845. else
  2846. {
  2847. SendData(connection, "KICK " + temp + " " + data);
  2848. }
  2849. }
  2850. }
  2851. else
  2852. {
  2853. data = data.Substring(temp.Length + 1);
  2854. if (data.IndexOf(' ') > 0)
  2855. {
  2856. //there is a kick reason
  2857. string msg = data.Substring(data.IndexOf(' ') + 1);
  2858. data = data.Substring(0, data.IndexOf(' '));
  2859. SendData(connection, "KICK " + temp + " " + data + " :" + msg);
  2860. }
  2861. else
  2862. {
  2863. SendData(connection, "KICK " + temp + " " + data);
  2864. }
  2865. }
  2866. }
  2867. }
  2868. break;
  2869. case "/me":
  2870. //check if in channel, query, etc
  2871. if (connection != null && data.Length > 0)
  2872. {
  2873. if (CurrentWindowType == IceTabPage.WindowType.Channel || CurrentWindowType == IceTabPage.WindowType.Query)
  2874. {
  2875. SendData(connection, "PRIVMSG " + CurrentWindow.TabCaption + " :ACTION " + data + "");
  2876. string msg = GetMessageFormat("Self Channel Action");
  2877. msg = msg.Replace("$nick", inputPanel.CurrentConnection.ServerSetting.NickName).Replace("$channel", CurrentWindow.TabCaption);
  2878. msg = msg.Replace("$message", data);
  2879. CurrentWindow.TextWindow.AppendText(msg, 1);
  2880. CurrentWindow.TextWindow.ScrollToBottom();
  2881. CurrentWindow.LastMessageType = ServerMessageType.Action;
  2882. }
  2883. else if (CurrentWindowType == IceTabPage.WindowType.DCCChat)
  2884. {
  2885. IceTabPage c = GetWindow(connection, CurrentWindow.TabCaption, IceTabPage.WindowType.DCCChat);
  2886. if (c != null)
  2887. {
  2888. c.SendDCCData("ACTION " + data + "");
  2889. string msg = GetMessageFormat("DCC Chat Action");
  2890. msg = msg.Replace("$nick", inputPanel.CurrentConnection.ServerSetting.NickName);
  2891. msg = msg.Replace("$message", data);
  2892. CurrentWindow.TextWindow.AppendText(msg, 1);
  2893. CurrentWindow.TextWindow.ScrollToBottom();
  2894. CurrentWindow.LastMessageType = ServerMessageType.Action;
  2895. }
  2896. }
  2897. }
  2898. break;
  2899. case "/mode":
  2900. if (connection != null && data.Length > 0)
  2901. SendData(connection, "MODE " + data);
  2902. break;
  2903. case "/modex":
  2904. if (connection != null)
  2905. SendData(connection, "MODE " + connection.ServerSetting.NickName + " +x");
  2906. break;
  2907. case "/motd":
  2908. if (connection != null)
  2909. {
  2910. connection.ServerSetting.ForceMOTD = true;
  2911. SendData(connection, "MOTD");
  2912. }
  2913. break;
  2914. case "/msg":
  2915. if (connection != null && data.IndexOf(' ') > -1)
  2916. {
  2917. string nick = data.Substring(0, data.IndexOf(' '));
  2918. string msg2 = data.Substring(data.IndexOf(' ') + 1);
  2919. if (nick.StartsWith("="))
  2920. {
  2921. //send to a dcc chat window
  2922. nick = nick.Substring(1);
  2923. IceTabPage c = GetWindow(connection, nick, IceTabPage.WindowType.DCCChat);
  2924. if (c != null)
  2925. {
  2926. c.SendDCCData(data);
  2927. string msg = GetMessageFormat("Self DCC Chat Message");
  2928. msg = msg.Replace("$nick", c.Connection.ServerSetting.NickName).Replace("$message", data);
  2929. c.TextWindow.AppendText(msg, 1);
  2930. }
  2931. }
  2932. else
  2933. {
  2934. SendData(connection, "PRIVMSG " + nick + " :" + msg2);
  2935. //get the color for the private message
  2936. string msg = GetMessageFormat("Self Channel Message");
  2937. msg = msg.Replace("$nick", connection.ServerSetting.NickName).Replace("$channel", nick);
  2938. if (msg.StartsWith("&#x3;"))
  2939. {
  2940. //get the color
  2941. string color = msg.Substring(0, 6);
  2942. int result;
  2943. if (Int32.TryParse(msg.Substring(6, 1), out result))
  2944. color += msg.Substring(6, 1);
  2945. msg = color + "*" + nick + "* " + data.Substring(data.IndexOf(' ') + 1); ;
  2946. }
  2947. //check if the nick has a query window open
  2948. IceTabPage q = GetWindow(connection, nick, IceTabPage.WindowType.Query);
  2949. if (q != null)
  2950. {
  2951. string nmsg = GetMessageFormat("Self Private Message");
  2952. nmsg = nmsg.Replace("$nick", connection.ServerSetting.NickName).Replace("$message", msg2);
  2953. q.TextWindow.AppendText(nmsg, 1);
  2954. q.LastMessageType = ServerMessageType.Message;
  2955. if (q != CurrentWindow)
  2956. CurrentWindowMessage(connection, msg, 1, true);
  2957. }
  2958. else
  2959. CurrentWindowMessage(connection, msg, 1, true);
  2960. }
  2961. }
  2962. break;
  2963. case "/nick":
  2964. if (connection != null && data.Length > 0)
  2965. SendData(connection, "NICK " + data);
  2966. break;
  2967. case "/notice":
  2968. if (connection != null && data.IndexOf(' ') > -1)
  2969. {
  2970. string nick = data.Substring(0, data.IndexOf(' '));
  2971. string msg = data.Substring(data.IndexOf(' ') + 1);
  2972. SendData(connection, "NOTICE " + nick + " :" + msg);
  2973. string nmsg = GetMessageFormat("Self Notice");
  2974. nmsg = nmsg.Replace("$nick", nick).Replace("$message", msg);
  2975. CurrentWindowMessage(connection, nmsg, 1, true);
  2976. }
  2977. break;
  2978. case "/part":
  2979. if (connection != null && data.Length > 0)
  2980. {
  2981. //check if it is a query window
  2982. IceTabPage q = GetWindow(connection, data, IceTabPage.WindowType.Query);
  2983. if (q != null)
  2984. {
  2985. RemoveWindow(connection, q.TabCaption, IceTabPage.WindowType.Query);
  2986. return;
  2987. }
  2988. else if (CurrentWindowType == IceTabPage.WindowType.Query)
  2989. {
  2990. RemoveWindow(connection, CurrentWindow.TabCaption, IceTabPage.WindowType.Query);
  2991. return;
  2992. }
  2993. //is there a part message
  2994. if (data.IndexOf(' ') > -1)
  2995. {
  2996. //check if channel is a valid channel
  2997. if (Array.IndexOf(connection.ServerSetting.ChannelTypes, data[0]) != -1)
  2998. {
  2999. SendData(connection, "PART " + data.Substring(0, data.IndexOf(' ')) + " :" + data.Substring(data.IndexOf(' ') + 1));
  3000. RemoveWindow(connection, data.Substring(0, data.IndexOf(' ')), IceTabPage.WindowType.Channel);
  3001. }
  3002. else
  3003. {
  3004. //not a valid channel, use the current window
  3005. if (CurrentWindowType == IceTabPage.WindowType.Channel)
  3006. {
  3007. SendData(connection, "PART " + CurrentWindow.TabCaption + " :" + data);
  3008. RemoveWindow(connection, CurrentWindow.TabCaption, IceTabPage.WindowType.Channel);
  3009. }
  3010. }
  3011. }
  3012. else
  3013. {
  3014. //see if data is a valid channel;
  3015. if (Array.IndexOf(connection.ServerSetting.ChannelTypes, data[0]) != -1)
  3016. {
  3017. SendData(connection, "PART " + data);
  3018. RemoveWindow(connection, data, IceTabPage.WindowType.Channel);
  3019. }
  3020. else
  3021. {
  3022. if (CurrentWindowType == IceTabPage.WindowType.Channel)
  3023. {
  3024. SendData(connection, "PART " + CurrentWindow.TabCaption + " :" + data);
  3025. RemoveWindow(connection, CurrentWindow.TabCaption, IceTabPage.WindowType.Channel);
  3026. }
  3027. }
  3028. }
  3029. }
  3030. else if (connection != null)
  3031. {
  3032. //check if current window is channel
  3033. if (CurrentWindowType == IceTabPage.WindowType.Channel)
  3034. {
  3035. SendData(connection, "PART " + CurrentWindow.TabCaption);
  3036. RemoveWindow(connection, CurrentWindow.TabCaption, IceTabPage.WindowType.Channel);
  3037. }
  3038. else if (CurrentWindowType == IceTabPage.WindowType.Query)
  3039. {
  3040. RemoveWindow(connection, CurrentWindow.TabCaption, IceTabPage.WindowType.Query);
  3041. }
  3042. }
  3043. break;
  3044. case "/partall":
  3045. if (connection != null)
  3046. {
  3047. for (int i = mainTabControl.TabPages.Count - 1; i >= 0; i--)
  3048. {
  3049. if (mainTabControl.TabPages[i].WindowStyle == IceTabPage.WindowType.Channel)
  3050. {
  3051. if (mainTabControl.TabPages[i].Connection == connection)
  3052. {
  3053. SendData(connection, "PART " + mainTabControl.TabPages[i].TabCaption);
  3054. RemoveWindow(connection, mainTabControl.TabPages[i].TabCaption, IceTabPage.WindowType.Channel);
  3055. }
  3056. }
  3057. }
  3058. }
  3059. break;
  3060. case "/ping":
  3061. if (connection != null && data.Length > 0 && data.IndexOf(' ') == -1)
  3062. {
  3063. //ctcp nick ping
  3064. string msg = GetMessageFormat("Ctcp Send");
  3065. msg = msg.Replace("$nick", data); ;
  3066. msg = msg.Replace("$ctcp", "PING");
  3067. CurrentWindowMessage(connection, msg, 7, true);
  3068. SendData(connection, "PRIVMSG " + data + " :PING " + System.Environment.TickCount.ToString() + "");
  3069. }
  3070. break;
  3071. case "/play": //play a WAV sound
  3072. if (data.Length > 4 && data.ToLower().EndsWith(".wav"))
  3073. {
  3074. //check if the WAV file exists in the Sounds Folder
  3075. if (File.Exists(soundsFolder + System.IO.Path.DirectorySeparatorChar + data))
  3076. {
  3077. try
  3078. {
  3079. player.SoundLocation = soundsFolder + System.IO.Path.DirectorySeparatorChar + data;
  3080. player.Play();
  3081. }
  3082. catch { }
  3083. }
  3084. //check if the entire path was passed for the sound file
  3085. else if (File.Exists(data))
  3086. {
  3087. try
  3088. {
  3089. player.SoundLocation = @data;
  3090. player.Play();
  3091. }
  3092. catch { }
  3093. }
  3094. }
  3095. break;
  3096. case "/query":
  3097. if (connection != null && data.Length > 0)
  3098. {
  3099. string nick = "";
  3100. string msg = "";
  3101. if (data.IndexOf(" ") > 0)
  3102. {
  3103. //check if there is a message added
  3104. nick = data.Substring(0, data.IndexOf(' '));
  3105. msg = data.Substring(data.IndexOf(' ') + 1);
  3106. }
  3107. else
  3108. nick = data;
  3109. if (!mainTabControl.WindowExists(connection, nick, IceTabPage.WindowType.Query))
  3110. AddWindow(connection, nick, IceTabPage.WindowType.Query);
  3111. mainTabControl.SelectTab(GetWindow(connection, nick, IceTabPage.WindowType.Query));
  3112. serverTree.SelectTab(mainTabControl.CurrentTab, false);
  3113. if (msg.Length > 0)
  3114. {
  3115. SendData(connection, "PRIVMSG " + nick + " :" + msg);
  3116. string nmsg = GetMessageFormat("Self Private Message");
  3117. nmsg = nmsg.Replace("$nick", inputPanel.CurrentConnection.ServerSetting.NickName).Replace("$message", msg);
  3118. CurrentWindow.TextWindow.AppendText(nmsg, 1);
  3119. CurrentWindow.LastMessageType = ServerMessageType.Message;
  3120. }
  3121. }
  3122. break;
  3123. case "/quit":
  3124. if (connection != null)
  3125. {
  3126. connection.AttemptReconnect = false;
  3127. if (data.Length > 0)
  3128. SendData(connection, "QUIT :" + data);
  3129. else
  3130. SendData(connection, "QUIT :" + ParseIdentifiers(connection, connection.ServerSetting.QuitMessage, ""));
  3131. }
  3132. break;
  3133. case "/aquit":
  3134. case "/quitall":
  3135. foreach (IRCConnection c in serverTree.ServerConnections.Values)
  3136. {
  3137. if (c.IsConnected)
  3138. {
  3139. c.AttemptReconnect = false;
  3140. if (data.Length > 0)
  3141. SendData(c, "QUIT :" + data);
  3142. else
  3143. SendData(c, "QUIT :" + ParseIdentifiers(connection, c.ServerSetting.QuitMessage, ""));
  3144. }
  3145. }
  3146. break;
  3147. case "/redrawtree":
  3148. System.Diagnostics.Debug.WriteLine(mainTabControl.CurrentTab.TabCaption);
  3149. this.serverTree.Invalidate();
  3150. break;
  3151. case "/run":
  3152. if (data.Length > 0)
  3153. {
  3154. if (data.IndexOf("'") == -1)
  3155. System.Diagnostics.Process.Start(data);
  3156. else
  3157. {
  3158. string cmd = data.Substring(0, data.IndexOf("'"));
  3159. string arg = data.Substring(data.IndexOf("'") + 1);
  3160. System.Diagnostics.Process p = System.Diagnostics.Process.Start(cmd, arg);
  3161. }
  3162. }
  3163. break;
  3164. case "/say":
  3165. if (connection != null && data.Length > 0)
  3166. {
  3167. if (CurrentWindowType == IceTabPage.WindowType.Channel)
  3168. {
  3169. SendData(connection, "PRIVMSG " + CurrentWindow.TabCaption + " :" + data);
  3170. string msg = GetMessageFormat("Self Channel Message");
  3171. string nick = inputPanel.CurrentConnection.ServerSetting.NickName;
  3172. msg = msg.Replace("$nick", nick).Replace("$channel", CurrentWindow.TabCaption);
  3173. //assign $color to the nickname
  3174. if (msg.Contains("$color"))
  3175. {
  3176. User u = CurrentWindow.GetNick(nick);
  3177. for (int i = 0; i < u.Level.Length; i++)
  3178. {
  3179. if (u.Level[i])
  3180. {
  3181. if (connection.ServerSetting.StatusModes[0][i] == 'v')
  3182. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelVoiceColor.ToString("00"));
  3183. else if (connection.ServerSetting.StatusModes[0][i] == 'h')
  3184. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelHalfOpColor.ToString("00"));
  3185. else if (connection.ServerSetting.StatusModes[0][i] == 'o')
  3186. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelOpColor.ToString("00"));
  3187. else if (connection.ServerSetting.StatusModes[0][i] == 'a')
  3188. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelAdminColor.ToString("00"));
  3189. else if (connection.ServerSetting.StatusModes[0][i] == 'q')
  3190. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelOwnerColor.ToString("00"));
  3191. else
  3192. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelOwnerColor.ToString("00"));
  3193. break;
  3194. }
  3195. }
  3196. if (msg.Contains("$color"))
  3197. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelRegularColor.ToString("00"));
  3198. }
  3199. msg = msg.Replace("$status", CurrentWindow.GetNick(nick).ToString().Replace(nick, ""));
  3200. msg = msg.Replace("$message", data);
  3201. CurrentWindow.TextWindow.AppendText(msg, 1);
  3202. CurrentWindow.LastMessageType = ServerMessageType.Message;
  3203. }
  3204. else if (CurrentWindowType == IceTabPage.WindowType.Query)
  3205. {
  3206. SendData(connection, "PRIVMSG " + CurrentWindow.TabCaption + " :" + data);
  3207. string msg = GetMessageFormat("Self Private Message");
  3208. msg = msg.Replace("$nick", inputPanel.CurrentConnection.ServerSetting.NickName).Replace("$message", data);
  3209. CurrentWindow.TextWindow.AppendText(msg, 1);
  3210. CurrentWindow.LastMessageType = ServerMessageType.Message;
  3211. }
  3212. else if (CurrentWindowType == IceTabPage.WindowType.DCCChat)
  3213. {
  3214. CurrentWindow.SendDCCData(data);
  3215. string msg = GetMessageFormat("Self DCC Chat Message");
  3216. msg = msg.Replace("$nick", inputPanel.CurrentConnection.ServerSetting.NickName).Replace("$message", data);
  3217. CurrentWindow.TextWindow.AppendText(msg, 1);
  3218. }
  3219. else if (CurrentWindowType == IceTabPage.WindowType.Console)
  3220. {
  3221. WindowMessage(connection, "Console", data, 4, true);
  3222. }
  3223. }
  3224. break;
  3225. case "/joinserv": //joinserv irc.server.name #channel
  3226. if (data.Length > 0 && data.IndexOf(' ') > 0)
  3227. {
  3228. //check if default nick name has been set
  3229. if (iceChatOptions.DefaultNick == null || iceChatOptions.DefaultNick.Length == 0)
  3230. {
  3231. CurrentWindowMessage(connection, "No Default Nick Name Assigned. Go to Server Settings and set one under the Default Server Settings section.",4 , false);
  3232. }
  3233. else
  3234. {
  3235. ServerSetting s = new ServerSetting();
  3236. //get the server name
  3237. //if there is a port name. extract it
  3238. string server = data.Substring(0,data.IndexOf(' '));
  3239. string channel = data.Substring(data.IndexOf(' ')+1);
  3240. if (server.Contains(":"))
  3241. {
  3242. s.ServerName = server.Substring(0, server.IndexOf(':'));
  3243. s.ServerPort = server.Substring(server.IndexOf(':') + 1);
  3244. if (s.ServerPort.IndexOf(' ') > 0)
  3245. {
  3246. s.ServerPort = s.ServerPort.Substring(0, s.ServerPort.IndexOf(' '));
  3247. }
  3248. //check for + in front of port, SSL Connection
  3249. if (s.ServerPort.StartsWith("+"))
  3250. {
  3251. s.ServerPort = s.ServerPort.Substring(1);
  3252. s.UseSSL = true;
  3253. }
  3254. }
  3255. else
  3256. {
  3257. s.ServerName = server;
  3258. s.ServerPort = "6667";
  3259. }
  3260. s.NickName = iceChatOptions.DefaultNick;
  3261. s.AltNickName = iceChatOptions.DefaultNick + "_";
  3262. s.AwayNickName = iceChatOptions.DefaultNick + "[A]";
  3263. s.FullName = iceChatOptions.DefaultFullName;
  3264. s.QuitMessage = iceChatOptions.DefaultQuitMessage;
  3265. s.IdentName = iceChatOptions.DefaultIdent;
  3266. s.IAL = new Hashtable();
  3267. s.AutoJoinChannels = new string[] { channel };
  3268. s.AutoJoinEnable = true;
  3269. Random r = new Random();
  3270. s.ID = r.Next(50000, 99999);
  3271. NewServerConnection(s);
  3272. }
  3273. }
  3274. break;
  3275. case "/server":
  3276. if (data.Length > 0)
  3277. {
  3278. //check if default nick name has been set
  3279. if (iceChatOptions.DefaultNick == null || iceChatOptions.DefaultNick.Length == 0)
  3280. {
  3281. CurrentWindowMessage(connection, "No Default Nick Name Assigned. Go to Server Settings and set one under the Default Server Settings section.", 4, false);
  3282. }
  3283. else if (data.StartsWith("id="))
  3284. {
  3285. string serverID = data.Substring(3);
  3286. foreach (ServerSetting s in serverTree.ServersCollection.listServers)
  3287. {
  3288. if (s.ID.ToString() == serverID)
  3289. {
  3290. NewServerConnection(s);
  3291. break;
  3292. }
  3293. }
  3294. }
  3295. else
  3296. {
  3297. ServerSetting s = new ServerSetting();
  3298. //get the server name
  3299. //if there is a port name. extract it
  3300. if (data.Contains(" "))
  3301. {
  3302. s.ServerName = data.Substring(0, data.IndexOf(' '));
  3303. s.ServerPort = data.Substring(data.IndexOf(' ') + 1);
  3304. if (s.ServerPort.IndexOf(' ') > 0)
  3305. {
  3306. s.ServerPort = s.ServerPort.Substring(0, s.ServerPort.IndexOf(' '));
  3307. }
  3308. //check for + in front of port, SSL Connection
  3309. if (s.ServerPort.StartsWith("+"))
  3310. {
  3311. s.ServerPort = s.ServerPort.Substring(1);
  3312. s.UseSSL = true;
  3313. s.SSLAcceptInvalidCertificate = true;
  3314. }
  3315. }
  3316. else if (data.Contains(":"))
  3317. {
  3318. s.ServerName = data.Substring(0, data.IndexOf(':'));
  3319. s.ServerPort = data.Substring(data.IndexOf(':') + 1);
  3320. if (s.ServerPort.IndexOf(' ') > 0)
  3321. {
  3322. s.ServerPort = s.ServerPort.Substring(0, s.ServerPort.IndexOf(' '));
  3323. }
  3324. //check for + in front of port, SSL Connection
  3325. if (s.ServerPort.StartsWith("+"))
  3326. {
  3327. s.ServerPort = s.ServerPort.Substring(1);
  3328. s.UseSSL = true;
  3329. s.SSLAcceptInvalidCertificate = true;
  3330. }
  3331. }
  3332. else
  3333. {
  3334. s.ServerName = data;
  3335. s.ServerPort = "6667";
  3336. }
  3337. s.NickName = iceChatOptions.DefaultNick;
  3338. s.AltNickName = iceChatOptions.DefaultNick + "_";
  3339. s.AwayNickName = iceChatOptions.DefaultNick + "[A]";
  3340. s.FullName = iceChatOptions.DefaultFullName;
  3341. s.QuitMessage = iceChatOptions.DefaultQuitMessage;
  3342. s.IdentName = iceChatOptions.DefaultIdent;
  3343. s.IAL = new Hashtable();
  3344. Random r = new Random();
  3345. s.ID = r.Next(50000, 99999);
  3346. NewServerConnection(s);
  3347. }
  3348. }
  3349. break;
  3350. case "/timers":
  3351. if (connection != null)
  3352. {
  3353. if (connection.IRCTimers.Count == 0)
  3354. OnServerMessage(connection, "No Timers");
  3355. else
  3356. {
  3357. foreach (IrcTimer timer in connection.IRCTimers)
  3358. OnServerMessage(connection, "[ID=" + timer.TimerID + "] [Interval=" + timer.TimerInterval + "] [Reps=" + timer.TimerRepetitions + "] [Count=" + timer.TimerCounter + "] [Command=" + timer.TimerCommand + "]");
  3359. }
  3360. }
  3361. break;
  3362. case "/timer":
  3363. if (connection != null)
  3364. {
  3365. if (data.Length != 0)
  3366. {
  3367. string[] param = data.Split(' ');
  3368. if (param.Length == 2)
  3369. {
  3370. //check for /timer ID off
  3371. if (param[1].ToLower() == "off")
  3372. {
  3373. connection.DestroyTimer(param[0]);
  3374. break;
  3375. }
  3376. }
  3377. else if (param.Length > 3)
  3378. {
  3379. // param[0] = TimerID
  3380. // param[1] = Repetitions
  3381. // param[2] = Interval
  3382. // param[3+] = Command
  3383. string timerCommand = String.Join(" ", param, 3, param.GetUpperBound(0) - 2);
  3384. connection.CreateTimer(param[0], Convert.ToDouble(param[1]), Convert.ToInt32(param[2]), timerCommand);
  3385. }
  3386. else
  3387. {
  3388. string msg = GetMessageFormat("User Error");
  3389. msg = msg.Replace("$message", "/timer [ID] [INTERVAL] [REPS] [COMMAND]");
  3390. CurrentWindowMessage(connection, msg, 4, true);
  3391. }
  3392. }
  3393. else
  3394. {
  3395. string msg = GetMessageFormat("User Error");
  3396. msg = msg.Replace("$message", "/timer [ID] [INTERVAL] [REPS] [COMMAND]");
  3397. CurrentWindowMessage(connection, msg, 4, true);
  3398. }
  3399. }
  3400. break;
  3401. case "/topic":
  3402. if (connection != null)
  3403. {
  3404. if (data.Length == 0)
  3405. {
  3406. if (CurrentWindowType == IceTabPage.WindowType.Channel)
  3407. SendData(connection, "TOPIC :" + CurrentWindow.TabCaption);
  3408. }
  3409. else
  3410. {
  3411. //check if a channel name was passed
  3412. string word = "";
  3413. if (data.IndexOf(' ') > -1)
  3414. word = data.Substring(0, data.IndexOf(' '));
  3415. else
  3416. word = data;
  3417. if (Array.IndexOf(connection.ServerSetting.ChannelTypes, word[0]) != -1)
  3418. {
  3419. IceTabPage t = GetWindow(connection, word, IceTabPage.WindowType.Channel);
  3420. if (t != null)
  3421. {
  3422. if (data.IndexOf(' ') > -1)
  3423. SendData(connection, "TOPIC " + t.TabCaption + " :" + data.Substring(data.IndexOf(' ') + 1));
  3424. else
  3425. SendData(connection, "TOPIC :" + t.TabCaption);
  3426. }
  3427. }
  3428. else
  3429. {
  3430. if (CurrentWindowType == IceTabPage.WindowType.Channel)
  3431. SendData(connection, "TOPIC " + CurrentWindow.TabCaption + " :" + data);
  3432. }
  3433. }
  3434. }
  3435. break;
  3436. case "/update":
  3437. checkForUpdate();
  3438. break;
  3439. case "/userinfo":
  3440. if (connection != null && data.Length > 0)
  3441. {
  3442. FormUserInfo fui = new FormUserInfo(connection);
  3443. //find the user
  3444. fui.NickName(data);
  3445. fui.ShowDialog(this);
  3446. }
  3447. break;
  3448. case "/version":
  3449. if (connection != null && data.Length > 0)
  3450. {
  3451. string msg = GetMessageFormat("Ctcp Send");
  3452. msg = msg.Replace("$nick", data); ;
  3453. msg = msg.Replace("$ctcp", "VERSION");
  3454. CurrentWindowMessage(connection, msg, 7, true);
  3455. SendData(connection, "PRIVMSG " + data + " VERSION");
  3456. }
  3457. else
  3458. SendData(connection, "VERSION");
  3459. break;
  3460. case "/who":
  3461. if (connection != null && data.Length > 0)
  3462. SendData(connection, "WHO " + data);
  3463. break;
  3464. case "/whois":
  3465. if (connection != null && data.Length > 0)
  3466. SendData(connection, "WHOIS " + data);
  3467. break;
  3468. case "/aline": //for adding lines to @windows
  3469. if (data.Length > 0 && data.IndexOf(" ") > -1)
  3470. {
  3471. string window = data.Substring(0, data.IndexOf(' '));
  3472. string msg = data.Substring(data.IndexOf(' ') + 1);
  3473. if (GetWindow(null, window, IceTabPage.WindowType.Window) == null)
  3474. AddWindow(null, window, IceTabPage.WindowType.Window);
  3475. IceTabPage t = GetWindow(null, window, IceTabPage.WindowType.Window);
  3476. if (t != null)
  3477. t.TextWindow.AppendText(msg, 1);
  3478. }
  3479. break;
  3480. case "/window":
  3481. if (data.Length > 0)
  3482. {
  3483. if (data.StartsWith("@") && data.IndexOf(" ") == -1)
  3484. {
  3485. if (GetWindow(null, data, IceTabPage.WindowType.Window) == null)
  3486. AddWindow(null, data, IceTabPage.WindowType.Window);
  3487. }
  3488. }
  3489. break;
  3490. case "/quote":
  3491. case "/raw":
  3492. if (connection != null && connection.IsConnected)
  3493. connection.SendData(data);
  3494. break;
  3495. default:
  3496. //parse the outgoing data
  3497. if (connection != null)
  3498. SendData(connection, command.Substring(1) + " " + data);
  3499. break;
  3500. }
  3501. }
  3502. else
  3503. {
  3504. //sends a message to the channel
  3505. if (inputPanel.CurrentConnection != null)
  3506. {
  3507. if (inputPanel.CurrentConnection.IsConnected)
  3508. {
  3509. //check if the current window is a Channel/Query, etc
  3510. if (CurrentWindowType == IceTabPage.WindowType.Channel)
  3511. {
  3512. SendData(connection, "PRIVMSG " + CurrentWindow.TabCaption + " :" + data);
  3513. //check if we got kicked out of the channel or not, and the window is still open
  3514. if (CurrentWindow.IsFullyJoined)
  3515. {
  3516. string msg = GetMessageFormat("Self Channel Message");
  3517. string nick = inputPanel.CurrentConnection.ServerSetting.NickName;
  3518. msg = msg.Replace("$nick", nick).Replace("$channel", CurrentWindow.TabCaption);
  3519. //assign $color to the nickname
  3520. if (msg.Contains("$color"))
  3521. {
  3522. User u = CurrentWindow.GetNick(nick);
  3523. for (int i = 0; i < u.Level.Length; i++)
  3524. {
  3525. if (u.Level[i])
  3526. {
  3527. if (connection.ServerSetting.StatusModes[0][i] == 'v')
  3528. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelVoiceColor.ToString("00"));
  3529. else if (connection.ServerSetting.StatusModes[0][i] == 'h')
  3530. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelHalfOpColor.ToString("00"));
  3531. else if (connection.ServerSetting.StatusModes[0][i] == 'o')
  3532. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelOpColor.ToString("00"));
  3533. else if (connection.ServerSetting.StatusModes[0][i] == 'a')
  3534. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelAdminColor.ToString("00"));
  3535. else if (connection.ServerSetting.StatusModes[0][i] == 'q')
  3536. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelOwnerColor.ToString("00"));
  3537. else
  3538. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelOwnerColor.ToString("00"));
  3539. break;
  3540. }
  3541. }
  3542. if (msg.Contains("$color"))
  3543. msg = msg.Replace("$color", ((char)3).ToString() + iceChatColors.ChannelRegularColor.ToString("00"));
  3544. }
  3545. msg = msg.Replace("$status", CurrentWindow.GetNick(nick).ToString().Replace(nick, ""));
  3546. msg = msg.Replace("$message", data);
  3547. CurrentWindow.TextWindow.AppendText(msg, 1);
  3548. CurrentWindow.LastMessageType = ServerMessageType.Message;
  3549. }
  3550. }
  3551. else if (CurrentWindowType == IceTabPage.WindowType.Query)
  3552. {
  3553. SendData(connection, "PRIVMSG " + CurrentWindow.TabCaption + " :" + data);
  3554. string msg = GetMessageFormat("Self Private Message");
  3555. msg = msg.Replace("$nick", inputPanel.CurrentConnection.ServerSetting.NickName).Replace("$message", data);
  3556. CurrentWindow.TextWindow.AppendText(msg, 1);
  3557. CurrentWindow.LastMessageType = ServerMessageType.Message;
  3558. }
  3559. else if (CurrentWindowType == IceTabPage.WindowType.DCCChat)
  3560. {
  3561. CurrentWindow.SendDCCData(data);
  3562. string msg = GetMessageFormat("Self DCC Chat Message");
  3563. msg = msg.Replace("$nick", inputPanel.CurrentConnection.ServerSetting.NickName).Replace("$message", data);
  3564. CurrentWindow.TextWindow.AppendText(msg, 1);
  3565. }
  3566. else if (CurrentWindowType == IceTabPage.WindowType.Console)
  3567. {
  3568. WindowMessage(connection, "Console", data, 4, true);
  3569. }
  3570. }
  3571. else
  3572. {
  3573. WindowMessage(connection, "Console", "Error: Not Connected", 4, true);
  3574. WindowMessage(connection, "Console", data, 4, true);
  3575. }
  3576. }
  3577. else
  3578. {
  3579. if (CurrentWindowType == IceTabPage.WindowType.Window)
  3580. CurrentWindow.TextWindow.AppendText(data, 1);
  3581. else
  3582. WindowMessage(null, "Console", data, 4, true);
  3583. }
  3584. }
  3585. }
  3586. catch (Exception e)
  3587. {
  3588. WriteErrorFile(connection, "ParseOutGoingCommand", e);
  3589. }
  3590. }
  3591. /// <summary>
  3592. /// Input Panel Text Box had Entered Key Pressed or Send Button Pressed
  3593. /// </summary>
  3594. /// <param name="sender"></param>
  3595. /// <param name="data"></param>
  3596. private void inputPanel_OnCommand(object sender, string data)
  3597. {
  3598. if (data.Length > 0)
  3599. {
  3600. ParseOutGoingCommand(inputPanel.CurrentConnection, data);
  3601. if (CurrentWindowType == IceTabPage.WindowType.Console)
  3602. mainTabControl.CurrentTab.CurrentConsoleWindow().ScrollToBottom();
  3603. else if (CurrentWindowType != IceTabPage.WindowType.DCCFile && CurrentWindowType != IceTabPage.WindowType.ChannelList)
  3604. CurrentWindow.TextWindow.ScrollToBottom();
  3605. }
  3606. }
  3607. #endregion
  3608. /// <summary>
  3609. /// Get the Host from the Full User Host, including Ident
  3610. /// </summary>
  3611. /// <param name="host">Full User Host (user!ident@host)</param>
  3612. /// <returns></returns>
  3613. private string HostFromFullHost(string host)
  3614. {
  3615. if (host.IndexOf("!") > -1)
  3616. return host.Substring(host.LastIndexOf("!") + 1);
  3617. else
  3618. return host;
  3619. }
  3620. /// <summary>
  3621. /// Return the Nick Name from the Full User Host
  3622. /// </summary>
  3623. /// <param name="host"></param>
  3624. /// <returns></returns>
  3625. private string NickFromFullHost(string host)
  3626. {
  3627. if (host.StartsWith(":"))
  3628. host = host.Substring(1);
  3629. if (host.IndexOf("!") > 0)
  3630. return host.Substring(0, host.LastIndexOf("!"));
  3631. else
  3632. return host;
  3633. }
  3634. private string ParseIdentifier(IRCConnection connection, string data)
  3635. {
  3636. //match all words starting with a $
  3637. string identMatch = "\\$\\b[a-zA-Z_0-9.]+\\b";
  3638. Regex ParseIdent = new Regex(identMatch);
  3639. Match m = ParseIdent.Match(data);
  3640. while (m.Success)
  3641. {
  3642. switch (m.Value)
  3643. {
  3644. case "$me":
  3645. if (connection != null)
  3646. data = ReplaceFirst(data, m.Value, connection.ServerSetting.NickName);
  3647. else
  3648. data = ReplaceFirst(data, m.Value, "$null");
  3649. break;
  3650. case "$altnick":
  3651. if (connection != null)
  3652. data = ReplaceFirst(data, m.Value, connection.ServerSetting.AltNickName);
  3653. else
  3654. data = ReplaceFirst(data, m.Value, "$null");
  3655. break;
  3656. case "$ident":
  3657. if (connection != null)
  3658. data = ReplaceFirst(data, m.Value, connection.ServerSetting.IdentName);
  3659. else
  3660. data = ReplaceFirst(data, m.Value, "$null");
  3661. break;
  3662. case "$host":
  3663. if (connection != null)
  3664. data = ReplaceFirst(data, m.Value, connection.ServerSetting.LocalHost);
  3665. else
  3666. data = ReplaceFirst(data, m.Value, "$null");
  3667. break;
  3668. case "$fullhost":
  3669. if (connection != null)
  3670. data = ReplaceFirst(data, m.Value, connection.ServerSetting.NickName + "!" + connection.ServerSetting.LocalHost);
  3671. else
  3672. data = ReplaceFirst(data, m.Value, "$null");
  3673. break;
  3674. case "$fullname":
  3675. if (connection != null)
  3676. data = ReplaceFirst(data, m.Value, connection.ServerSetting.FullName);
  3677. else
  3678. data = ReplaceFirst(data, m.Value, "$null");
  3679. break;
  3680. case "$ip":
  3681. if (connection != null)
  3682. data = ReplaceFirst(data, m.Value, connection.ServerSetting.LocalIP.ToString());
  3683. else
  3684. data = ReplaceFirst(data, m.Value, "$null");
  3685. break;
  3686. case "$network":
  3687. if (connection != null)
  3688. data = ReplaceFirst(data, m.Value, connection.ServerSetting.NetworkName);
  3689. else
  3690. data = ReplaceFirst(data, m.Value, "$null");
  3691. break;
  3692. case "$port":
  3693. if (connection != null)
  3694. data = ReplaceFirst(data, m.Value, connection.ServerSetting.ServerPort);
  3695. else
  3696. data = ReplaceFirst(data, m.Value, "$null");
  3697. break;
  3698. case "$quitmessage":
  3699. if (connection != null)
  3700. data = ReplaceFirst(data, m.Value, connection.ServerSetting.QuitMessage);
  3701. else
  3702. data = ReplaceFirst(data, m.Value, "$null");
  3703. break;
  3704. case "$servermode":
  3705. data = ReplaceFirst(data, m.Value, string.Empty);
  3706. break;
  3707. case "$serverid":
  3708. if (connection != null)
  3709. data = ReplaceFirst(data, m.Value, connection.ServerSetting.ID.ToString());
  3710. else
  3711. data = ReplaceFirst(data, m.Value, "$null");
  3712. break;
  3713. case "$server":
  3714. if (connection != null)
  3715. {
  3716. if (connection.ServerSetting.RealServerName.Length > 0)
  3717. data = ReplaceFirst(data, m.Value, connection.ServerSetting.RealServerName);
  3718. else
  3719. data = ReplaceFirst(data, m.Value, connection.ServerSetting.ServerName);
  3720. }
  3721. else
  3722. data = ReplaceFirst(data, m.Value, "$null");
  3723. break;
  3724. case "$online":
  3725. if (connection != null)
  3726. {
  3727. //check the datediff
  3728. TimeSpan online = DateTime.Now.Subtract(connection.ServerSetting.ConnectedTime);
  3729. data = ReplaceFirst(data, m.Value, GetDuration((int)online.TotalSeconds));
  3730. }
  3731. else
  3732. data = ReplaceFirst(data, m.Value, "$null");
  3733. break;
  3734. case "$serverip":
  3735. if (connection != null)
  3736. data = ReplaceFirst(data, m.Value, connection.ServerSetting.ServerIP);
  3737. else
  3738. data = ReplaceFirst(data, m.Value, "$null");
  3739. break;
  3740. case "$localip":
  3741. if (connection != null)
  3742. data = ReplaceFirst(data, m.Value, connection.ServerSetting.LocalIP.ToString());
  3743. else
  3744. data = ReplaceFirst(data, m.Value, "$null");
  3745. break;
  3746. //identifiers that do not require a connection
  3747. case "$theme":
  3748. data = ReplaceFirst(data, m.Value, iceChatOptions.CurrentTheme);
  3749. break;
  3750. case "$colors":
  3751. data = ReplaceFirst(data, m.Value, colorsFile);
  3752. break;
  3753. case "$appdata":
  3754. data = ReplaceFirst(data, m.Value, Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData).ToString());
  3755. break;
  3756. case "$ossp":
  3757. data = ReplaceFirst(data, m.Value, Environment.OSVersion.ServicePack.ToString());
  3758. break;
  3759. case "$osbuild":
  3760. data = ReplaceFirst(data, m.Value, Environment.OSVersion.Version.Build.ToString());
  3761. break;
  3762. case "$osplatform":
  3763. data = ReplaceFirst(data, m.Value, Environment.OSVersion.Platform.ToString());
  3764. break;
  3765. case "$osbits":
  3766. //8 on 64bit -- AMD64
  3767. string arch = System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE").ToString();
  3768. switch (arch)
  3769. {
  3770. case "x86":
  3771. string arch2 = System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432").ToString();
  3772. if (arch2 == "AMD64")
  3773. data = ReplaceFirst(data, m.Value, "64bit");
  3774. else
  3775. data = ReplaceFirst(data, m.Value, "32bit");
  3776. break;
  3777. case "AMD64":
  3778. case "IA64":
  3779. data = ReplaceFirst(data, m.Value, "64bit");
  3780. break;
  3781. }
  3782. //System.Diagnostics.Debug.WriteLine(System.Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE").ToString());
  3783. //System.Diagnostics.Debug.WriteLine(IntPtr.Size);
  3784. break;
  3785. case "$os":
  3786. data = ReplaceFirst(data, m.Value, GetOperatingSystemName());
  3787. break;
  3788. case "$icepath":
  3789. case "$icechatexedir":
  3790. data = ReplaceFirst(data, m.Value, Directory.GetCurrentDirectory());
  3791. break;
  3792. case "$aliasfile":
  3793. data = ReplaceFirst(data, m.Value,aliasesFile);
  3794. break;
  3795. case "$serverfile":
  3796. data = ReplaceFirst(data, m.Value, serversFile);
  3797. break;
  3798. case "$popupfile":
  3799. data = ReplaceFirst(data, m.Value, popupsFile);
  3800. break;
  3801. case "$icechatver":
  3802. data = ReplaceFirst(data, m.Value, VersionID);
  3803. break;
  3804. case "$version":
  3805. data = ReplaceFirst(data, m.Value, ProgramID + " " + VersionID);
  3806. break;
  3807. case "$icechatdir":
  3808. data = ReplaceFirst(data, m.Value, currentFolder);
  3809. break;
  3810. case "$icechathandle":
  3811. data = ReplaceFirst(data, m.Value, this.Handle.ToString());
  3812. break;
  3813. case "$icechat":
  3814. data = ReplaceFirst(data, m.Value, ProgramID + " " + VersionID + " http://www.icechat.net");
  3815. break;
  3816. case "$logdir":
  3817. data = ReplaceFirst(data, m.Value, logsFolder);
  3818. break;
  3819. case "$randquit":
  3820. Random rand = new Random();
  3821. int rq = rand.Next(0, QuitMessages.RandomQuitMessages.Length);
  3822. data = ReplaceFirst(data, m.Value, QuitMessages.RandomQuitMessages[rq]);
  3823. break;
  3824. case "$randcolor":
  3825. Random randcolor = new Random();
  3826. int rc = randcolor.Next(0, (IrcColor.colors.Length-1));
  3827. data = ReplaceFirst(data, m.Value, rc.ToString());
  3828. break;
  3829. case "$tickcount":
  3830. data = ReplaceFirst(data, m.Value, System.Environment.TickCount.ToString());
  3831. break;
  3832. case "$totalwindows":
  3833. data = ReplaceFirst(data, m.Value, mainTabControl.TabCount.ToString());
  3834. break;
  3835. case "$framework":
  3836. data = ReplaceFirst(data, m.Value, System.Environment.Version.ToString());
  3837. break;
  3838. case "$uptime2":
  3839. int systemUpTime = System.Environment.TickCount / 1000;
  3840. TimeSpan ts = TimeSpan.FromSeconds(systemUpTime);
  3841. data = ReplaceFirst(data, m.Value, GetDuration(ts.TotalSeconds));
  3842. break;
  3843. case "$uptime":
  3844. System.Diagnostics.PerformanceCounter pc = new System.Diagnostics.PerformanceCounter("System", "System Up Time");
  3845. pc.NextValue();
  3846. TimeSpan ts2 = TimeSpan.FromSeconds(pc.NextValue());
  3847. data = ReplaceFirst(data, m.Value, GetDuration(ts2.TotalSeconds));
  3848. break;
  3849. case "$mono":
  3850. if (StaticMethods.IsRunningOnMono())
  3851. data = ReplaceFirst(data, m.Value, (string)typeof(object).Assembly.GetType("Mono.Runtime").InvokeMember("GetDisplayName", BindingFlags.InvokeMethod | BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.DeclaredOnly | BindingFlags.ExactBinding, null, null, null));
  3852. else
  3853. data = ReplaceFirst(data, m.Value, "Mono.Runtime not detected");
  3854. break;
  3855. }
  3856. m = m.NextMatch();
  3857. }
  3858. return data;
  3859. }
  3860. private string GetOperatingSystemName()
  3861. {
  3862. string OSName = "Unknown";
  3863. System.OperatingSystem osInfo = System.Environment.OSVersion;
  3864. if (osInfo.Platform == PlatformID.Unix)
  3865. {
  3866. return Environment.OSVersion.ToString();
  3867. }
  3868. OSVERSIONINFOEX osVersionInfo = new OSVERSIONINFOEX();
  3869. osVersionInfo.dwOSVersionInfoSize = Marshal.SizeOf(typeof(OSVERSIONINFOEX));
  3870. if (!GetVersionEx(ref osVersionInfo))
  3871. {
  3872. return OSName;
  3873. }
  3874. switch (osInfo.Platform)
  3875. {
  3876. case PlatformID.Win32NT:
  3877. switch (osInfo.Version.Major)
  3878. {
  3879. case 3:
  3880. OSName = "Windows NT 3.51";
  3881. break;
  3882. case 4:
  3883. OSName = "Windows NT 4.0";
  3884. break;
  3885. case 5:
  3886. switch (osInfo.Version.Minor)
  3887. {
  3888. case 0:
  3889. OSName = "Windows 2000";
  3890. break;
  3891. case 1:
  3892. OSName = "Windows XP";
  3893. break;
  3894. case 2:
  3895. OSName = "Windows Server 2003";
  3896. break;
  3897. default:
  3898. break;
  3899. }
  3900. break;
  3901. case 6:
  3902. switch (osInfo.Version.Minor)
  3903. {
  3904. case 0:
  3905. //producttype == VER_NT_WORKSTATION
  3906. if (osVersionInfo.dwPlatformId != VER_NT_WORKSTATION)
  3907. OSName = "Windows Vista";
  3908. else
  3909. //producttype != VER_NT_WORKSTATION
  3910. OSName = "Windows Server 2008";
  3911. break;
  3912. case 1:
  3913. //producttype != VER_NT_WORKSTATION
  3914. if (osVersionInfo.dwPlatformId == VER_NT_WORKSTATION)
  3915. OSName = "Windws Server 2008 R2";
  3916. else
  3917. //producttype == VER_NT_WORKSTATION
  3918. OSName = "Windows 7";
  3919. break;
  3920. }
  3921. break;
  3922. default:
  3923. OSName = "Unknown Win32NT Windows";
  3924. break;
  3925. }
  3926. break;
  3927. case PlatformID.Win32S:
  3928. break;
  3929. case PlatformID.Win32Windows:
  3930. switch (osInfo.Version.Major)
  3931. {
  3932. case 0:
  3933. OSName = "Windows 95";
  3934. break;
  3935. case 10:
  3936. if (osInfo.Version.Revision.ToString() == "2222A")
  3937. OSName = "Windows 98 Second Edition";
  3938. else
  3939. OSName = "Windows 98";
  3940. break;
  3941. case 90:
  3942. OSName = "Windows ME";
  3943. break;
  3944. default:
  3945. OSName = "Unknown Win32 Windows";
  3946. break;
  3947. }
  3948. break;
  3949. case PlatformID.WinCE:
  3950. break;
  3951. default:
  3952. break;
  3953. }
  3954. return OSName;
  3955. }
  3956. private string ParseIdentifierValue(string data, string dataPassed)
  3957. {
  3958. //split up the data into words
  3959. string[] parsedData = data.Split(' ');
  3960. //the data that was passed for parsing identifiers
  3961. string[] passedData = dataPassed.Split(' ');
  3962. //will hold the updates message/data after identifiers are parsed
  3963. string[] changedData = data.Split(' ');
  3964. int count = -1;
  3965. //search for identifiers that are numbers
  3966. //used for replacing values passed to the function
  3967. foreach (string word in parsedData)
  3968. {
  3969. count++;
  3970. if (word.StartsWith("//") && count == 0)
  3971. changedData[count] = word.Substring(1);
  3972. //parse out identifiers (start with a $)
  3973. if (word.StartsWith("$"))
  3974. {
  3975. switch (word)
  3976. {
  3977. case "$+":
  3978. break;
  3979. default:
  3980. //search for identifiers that are numbers
  3981. //used for replacing values passed to the function
  3982. int result;
  3983. int z = 1;
  3984. while (z < word.Length)
  3985. {
  3986. if (Int32.TryParse(word.Substring(z, 1), out result))
  3987. z++;
  3988. else
  3989. break;
  3990. }
  3991. //check for - after numbered identifier
  3992. if (z > 1)
  3993. {
  3994. //get the numbered identifier value
  3995. int identVal = Int32.Parse(word.Substring(1, z - 1));
  3996. if (identVal <= passedData.Length)
  3997. {
  3998. //System.Diagnostics.Debug.WriteLine(identVal + ":" + passedData[identVal - 1]);
  3999. //System.Diagnostics.Debug.WriteLine(z + ":" + word.Length);
  4000. //System.Diagnostics.Debug.WriteLine(word.Substring(z,1));
  4001. if (word.Length > z)
  4002. if (word.Substring(z, 1) == "-")
  4003. {
  4004. //System.Diagnostics.Debug.WriteLine("change - " + identVal + ":" + passedData.Length);
  4005. changedData[count] = String.Join(" ", passedData, identVal - 1, passedData.Length - identVal + 1);
  4006. continue;
  4007. }
  4008. //System.Diagnostics.Debug.WriteLine("change normal ");
  4009. changedData[count] = passedData[identVal - 1];
  4010. }
  4011. else
  4012. changedData[count] = "";
  4013. }
  4014. break;
  4015. }
  4016. }
  4017. }
  4018. return String.Join(" ",changedData);
  4019. }
  4020. /// <summary>
  4021. /// Parse out $identifiers for outgoing commands
  4022. /// </summary>
  4023. /// <param name="connection">Which Connection it is for</param>
  4024. /// <param name="data">The data to be parsed</param>
  4025. /// <returns></returns>
  4026. private string ParseIdentifiers(IRCConnection connection, string data, string dataPassed)
  4027. {
  4028. string[] changedData = null;
  4029. try
  4030. {
  4031. //parse the initial identifiers
  4032. data = ParseIdentifier(connection, data);
  4033. //parse out the $1,$2.. identifiers
  4034. data = ParseIdentifierValue(data, dataPassed);
  4035. //$+ is a joiner identifier, great for joining 2 words together
  4036. data = data.Replace(" $+ ", string.Empty);
  4037. //split up the data into words
  4038. string[] parsedData = data.Split(' ');
  4039. //the data that was passed for parsing identifiers
  4040. string[] passedData = dataPassed.Split(' ');
  4041. //will hold the updates message/data after identifiers are parsed
  4042. changedData = data.Split(' ');
  4043. int count = -1;
  4044. string extra = "";
  4045. bool askExtra = false;
  4046. foreach (string word in parsedData)
  4047. {
  4048. count++;
  4049. if (word.StartsWith("//") && count == 0)
  4050. changedData[count] = word.Substring(1);
  4051. if (askExtra)
  4052. {
  4053. //continueing a $?=
  4054. extra += " " + word;
  4055. changedData[count] = null;
  4056. if (extra[extra.Length - 1] == extra[0])
  4057. {
  4058. askExtra = false;
  4059. //ask the question
  4060. InputBoxDialog i = new InputBoxDialog();
  4061. i.FormCaption = "Enter Value";
  4062. i.FormPrompt = extra.Substring(1,extra.Length-2);
  4063. i.ShowDialog();
  4064. if (i.InputResponse.Length > 0)
  4065. changedData[count] = i.InputResponse;
  4066. i.Dispose();
  4067. }
  4068. }
  4069. //parse out identifiers (start with a $)
  4070. if (word.StartsWith("$"))
  4071. {
  4072. switch (word)
  4073. {
  4074. default:
  4075. int result;
  4076. if (word.StartsWith("$?=") && word.Length > 5)
  4077. {
  4078. //check for 2 quotes (single or double)
  4079. string ask = word.Substring(3);
  4080. //check what kind of a quote it is
  4081. char quote = ask[0];
  4082. if (quote == ask[ask.Length - 1])
  4083. {
  4084. //ask the question
  4085. extra = ask;
  4086. InputBoxDialog i = new InputBoxDialog();
  4087. i.FormCaption = "Enter Value";
  4088. i.FormPrompt = extra.Substring(1, extra.Length - 2);
  4089. i.ShowDialog();
  4090. if (i.InputResponse.Length > 0)
  4091. changedData[count] = i.InputResponse;
  4092. else
  4093. changedData[count] = null;
  4094. i.Dispose();
  4095. }
  4096. else
  4097. {
  4098. //go to the next word until we find a quote at the end
  4099. extra = ask;
  4100. askExtra = true;
  4101. changedData[count] = null;
  4102. }
  4103. }
  4104. if (word.StartsWith("$md5(") && word.IndexOf(')') > word.IndexOf('('))
  4105. {
  4106. string input = ReturnBracketValue(word);
  4107. changedData[count] = MD5(input);
  4108. }
  4109. if (word.StartsWith("$read(") && word.IndexOf(')') > word.IndexOf('('))
  4110. {
  4111. string file = ReturnBracketValue(word);
  4112. //check if we have passed a path or just a filename
  4113. if (file.IndexOf(System.IO.Path.DirectorySeparatorChar) > -1)
  4114. {
  4115. //its a full folder
  4116. if (File.Exists(file))
  4117. {
  4118. //count the number of lines in the file
  4119. //load the file in and read a random line from it
  4120. string[] lines = File.ReadAllLines(file);
  4121. if (lines.Length > 0)
  4122. {
  4123. //pick a random line
  4124. Random r = new Random();
  4125. int line = r.Next(0, lines.Length - 1);
  4126. changedData[count] = lines[line];
  4127. }
  4128. else
  4129. changedData[count] = "$null";
  4130. }
  4131. }
  4132. else
  4133. {
  4134. //just check in the Scripts Folder
  4135. if (File.Exists(scriptsFolder + System.IO.Path.DirectorySeparatorChar + file))
  4136. {
  4137. //load the file in and read a random line from it
  4138. string[] lines = File.ReadAllLines(scriptsFolder + System.IO.Path.DirectorySeparatorChar + file);
  4139. if (lines.Length > 0)
  4140. {
  4141. //pick a random line
  4142. Random r = new Random();
  4143. int line = r.Next(0, lines.Length - 1);
  4144. changedData[count] = lines[line];
  4145. }
  4146. else
  4147. changedData[count] = "$null";
  4148. }
  4149. }
  4150. }
  4151. if (connection != null)
  4152. {
  4153. if (word.StartsWith("$ial(") && word.IndexOf(')') > word.IndexOf('('))
  4154. {
  4155. string nick = ReturnBracketValue(word);
  4156. string prop = ReturnPropertyValue(word);
  4157. InternalAddressList ial = (InternalAddressList)connection.ServerSetting.IAL[nick];
  4158. if (ial != null)
  4159. {
  4160. if (prop.Length == 0)
  4161. changedData[count] = ial.Nick;
  4162. else
  4163. {
  4164. switch (prop.ToLower())
  4165. {
  4166. case "nick":
  4167. changedData[count] = ial.Nick;
  4168. break;
  4169. case "host":
  4170. changedData[count] = ial.Host;
  4171. break;
  4172. }
  4173. }
  4174. }
  4175. else
  4176. changedData[count] = "$null";
  4177. }
  4178. if (word.StartsWith("$nick(") && word.IndexOf(')') > word.IndexOf('('))
  4179. {
  4180. //get the value between and after the brackets
  4181. string values = ReturnBracketValue(word);
  4182. if (values.Split(',').Length == 2)
  4183. {
  4184. string channel = values.Split(',')[0];
  4185. string nickvalue = values.Split(',')[1];
  4186. string prop = ReturnPropertyValue(word);
  4187. // $nick(#,N)
  4188. //find then channel
  4189. IceTabPage t = GetWindow(connection, channel, IceTabPage.WindowType.Channel);
  4190. if (t != null)
  4191. {
  4192. User u = null;
  4193. if (Int32.TryParse(nickvalue, out result))
  4194. {
  4195. if (Convert.ToInt32(nickvalue) == 0)
  4196. changedData[count] = t.Nicks.Count.ToString();
  4197. else
  4198. u = t.GetNick(Convert.ToInt32(nickvalue));
  4199. }
  4200. else
  4201. {
  4202. u = t.GetNick(nickvalue);
  4203. }
  4204. if (prop.Length == 0 && u != null)
  4205. {
  4206. changedData[count] = u.NickName;
  4207. }
  4208. else if (u != null)
  4209. {
  4210. //$nick(#channel,1).op , .voice, .halfop, .admin,.owner.
  4211. //.mode, .host, .nick,.ident
  4212. InternalAddressList ial = (InternalAddressList)connection.ServerSetting.IAL[u.NickName];
  4213. switch (prop.ToLower())
  4214. {
  4215. case "host":
  4216. if (ial != null && ial.Host != null && ial.Host.Length > 0)
  4217. changedData[count] = ial.Host.Substring(ial.Host.IndexOf('@') + 1);
  4218. break;
  4219. case "ident":
  4220. if (ial != null && ial.Host != null && ial.Host.Length > 0)
  4221. changedData[count] = ial.Host.Substring(0,ial.Host.IndexOf('@'));
  4222. break;
  4223. case "nick":
  4224. changedData[count] = u.NickName;
  4225. break;
  4226. case "mode":
  4227. changedData[count] = u.ToString().Replace(u.NickName, "");
  4228. break;
  4229. case "op":
  4230. for (int i = 0; i < u.Level.Length; i++)
  4231. {
  4232. if (connection.ServerSetting.StatusModes[0][i] == 'o')
  4233. {
  4234. if (u.Level[i] == true)
  4235. changedData[count] = "$true";
  4236. else
  4237. changedData[count] = "$false";
  4238. }
  4239. }
  4240. break;
  4241. case "voice":
  4242. for (int i = 0; i < u.Level.Length; i++)
  4243. {
  4244. if (connection.ServerSetting.StatusModes[0][i] == 'v')
  4245. {
  4246. if (u.Level[i] == true)
  4247. changedData[count] = "$true";
  4248. else
  4249. changedData[count] = "$false";
  4250. }
  4251. }
  4252. break;
  4253. }
  4254. ial = null;
  4255. }
  4256. }
  4257. }
  4258. }
  4259. if (word.StartsWith("$chan(") && word.IndexOf(')') > word.IndexOf('('))
  4260. {
  4261. //get the value between and after the brackets
  4262. string channel = ReturnBracketValue(word);
  4263. string prop = ReturnPropertyValue(word);
  4264. //find then channel
  4265. IceTabPage t = GetWindow(connection, channel, IceTabPage.WindowType.Channel);
  4266. if (t != null)
  4267. {
  4268. if (prop.Length == 0)
  4269. {
  4270. //replace with channel name
  4271. changedData[count] = t.TabCaption;
  4272. }
  4273. else
  4274. {
  4275. switch (prop.ToLower())
  4276. {
  4277. case "mode":
  4278. changedData[count] = t.ChannelModes;
  4279. break;
  4280. case "count":
  4281. changedData[count] = t.Nicks.Count.ToString();
  4282. break;
  4283. default:
  4284. break;
  4285. }
  4286. }
  4287. }
  4288. }
  4289. if (word.StartsWith("$timer(") && word.IndexOf(')') > word.IndexOf('('))
  4290. {
  4291. //get the value between and after the brackets
  4292. string timerid = ReturnBracketValue(word);
  4293. string prop = ReturnPropertyValue(word);
  4294. //find the timer
  4295. foreach (IrcTimer timer in connection.IRCTimers)
  4296. {
  4297. if (timer.TimerID == timerid)
  4298. {
  4299. if (prop.Length == 0)
  4300. {
  4301. //replace with timer id
  4302. changedData[count] = timer.TimerID;
  4303. }
  4304. else
  4305. {
  4306. switch (prop.ToLower())
  4307. {
  4308. case "id":
  4309. changedData[count] = timer.TimerID;
  4310. break;
  4311. case "reps":
  4312. changedData[count] = timer.TimerRepetitions.ToString();
  4313. break;
  4314. case "count":
  4315. changedData[count] = timer.TimerCounter.ToString();
  4316. break;
  4317. case "command":
  4318. changedData[count] = timer.TimerCommand;
  4319. break;
  4320. case "interval":
  4321. changedData[count] = timer.TimerInterval.ToString();
  4322. break;
  4323. default:
  4324. break;
  4325. }
  4326. }
  4327. }
  4328. }
  4329. }
  4330. if (word.StartsWith("$mask(") && word.IndexOf(')') > word.IndexOf('('))
  4331. {
  4332. //$mask($host,2)
  4333. //get the value between and after the brackets
  4334. string values = ReturnBracketValue(word);
  4335. string prop = ReturnPropertyValue(word);
  4336. if (values.Split(',').Length == 2)
  4337. {
  4338. string full_host = values.Split(',')[0];
  4339. string mask_value = values.Split(',')[1];
  4340. if (full_host.Length == 0) break;
  4341. if (mask_value.Length == 0) break;
  4342. if (full_host.IndexOf("@") == -1) break;
  4343. if (full_host.IndexOf("!") == -1) break;
  4344. switch (mask_value)
  4345. {
  4346. case "0": // *!user@host
  4347. changedData[count] = "*!" + full_host.Substring(full_host.IndexOf("!") + 1);
  4348. break;
  4349. case "1": // *!*user@host
  4350. changedData[count] = "*!*" + full_host.Substring(full_host.IndexOf("!") + 1);
  4351. break;
  4352. case "2": // *!*user@*.host
  4353. changedData[count] = "*!*" + full_host.Substring(full_host.IndexOf("@"));
  4354. break;
  4355. case "3": // *!*user@*.host
  4356. break;
  4357. case "4": // *!*@*.host
  4358. break;
  4359. case "5": // nick!user@host
  4360. changedData[count] = full_host;
  4361. break;
  4362. case "6": // nick!*user@host
  4363. break;
  4364. case "7": // nick!*@host
  4365. break;
  4366. case "8": // nick!*user@*.host
  4367. break;
  4368. case "9": // nick!*@*.host
  4369. break;
  4370. case "10": // nick!*@*
  4371. changedData[count] = full_host.Substring(0, full_host.IndexOf("!")) + "!*@*";
  4372. break;
  4373. case "11": // *!user@*
  4374. break;
  4375. }
  4376. }
  4377. }
  4378. }
  4379. break;
  4380. }
  4381. }
  4382. }
  4383. }
  4384. catch (Exception e)
  4385. {
  4386. WriteErrorFile(connection, "ParseIdentifiers" + data, e);
  4387. }
  4388. //return String.Join(" ", changedData);
  4389. return JoinString(changedData);
  4390. }
  4391. //rejoin an arrayed string into a single string, not adding null values
  4392. private string JoinString(string[] joinString)
  4393. {
  4394. string joined = "";
  4395. foreach (string j in joinString)
  4396. {
  4397. if (j != null)
  4398. joined += j + " ";
  4399. }
  4400. if (joined.Length > 0)
  4401. joined = joined.Substring(0, joined.Length - 1);
  4402. return joined;
  4403. }
  4404. private string ReturnBracketValue(string data)
  4405. {
  4406. //return what is between ( ) brackets
  4407. string d = data.Substring(data.IndexOf('(') + 1);
  4408. return d.Substring(0,d.IndexOf(')'));
  4409. }
  4410. private string ReturnPropertyValue(string data)
  4411. {
  4412. if (data.IndexOf('.') == -1)
  4413. return "";
  4414. else
  4415. return data.Substring(data.LastIndexOf('.') + 1);
  4416. }
  4417. //replace 1st occurence of a string inside another string
  4418. private string ReplaceFirst(string haystack, string needle, string replacement)
  4419. {
  4420. int pos = haystack.IndexOf(needle);
  4421. if (pos < 0) return haystack;
  4422. return haystack.Substring(0, pos) + replacement + haystack.Substring(pos + needle.Length);
  4423. }
  4424. private string GetDuration(double seconds)
  4425. {
  4426. TimeSpan t = new TimeSpan(0, 0,(int)seconds);
  4427. string s = t.Seconds.ToString() + " secs";
  4428. if (t.Minutes > 0)
  4429. s = t.Minutes.ToString() + " mins " + s;
  4430. if (t.Hours > 0)
  4431. s = t.Hours.ToString() + " hrs " + s;
  4432. if (t.Days > 0)
  4433. s = t.Days.ToString() + " days " + s;
  4434. return s;
  4435. }
  4436. private string MD5(string password)
  4437. {
  4438. byte[] textBytes = System.Text.Encoding.Default.GetBytes(password);
  4439. try
  4440. {
  4441. System.Security.Cryptography.MD5CryptoServiceProvider cryptHandler;
  4442. cryptHandler = new System.Security.Cryptography.MD5CryptoServiceProvider();
  4443. byte[] hash = cryptHandler.ComputeHash(textBytes);
  4444. string ret = "";
  4445. foreach (byte a in hash)
  4446. {
  4447. if (a < 16)
  4448. ret += "0" + a.ToString("x");
  4449. else
  4450. ret += a.ToString("x");
  4451. }
  4452. return ret;
  4453. }
  4454. catch
  4455. {
  4456. throw;
  4457. }
  4458. }
  4459. #region Menu and ToolStrip Items
  4460. /// <summary>
  4461. /// Close the Application
  4462. /// </summary>
  4463. /// <param name="sender"></param>
  4464. /// <param name="e"></param>
  4465. private void exitToolStripMenuItem_Click(object sender, EventArgs e)
  4466. {
  4467. this.Close();
  4468. }
  4469. private void iceChatChannelStripMenuItem_Click(object sender, System.EventArgs e)
  4470. {
  4471. ParseOutGoingCommand(null, "/joinserv irc.quakenet.org #icechat2009");
  4472. }
  4473. private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
  4474. {
  4475. //show the about box
  4476. FormAbout fa = new FormAbout();
  4477. fa.ShowDialog(this);
  4478. }
  4479. private void minimizeToTrayToolStripMenuItem_Click(object sender, EventArgs e)
  4480. {
  4481. this.Hide();
  4482. this.notifyIcon.Visible = true;
  4483. }
  4484. private void NotifyIconMouseDoubleClick(object sender, MouseEventArgs e)
  4485. {
  4486. this.iceChatOptions.IsOnTray = false;
  4487. this.Show();
  4488. this.WindowState = FormWindowState.Normal;
  4489. this.notifyIcon.Visible = false;
  4490. }
  4491. private void iceChatSettingsToolStripMenuItem_Click(object sender, EventArgs e)
  4492. {
  4493. //bring up a very basic settings form
  4494. FormSettings fs = new FormSettings(iceChatOptions, iceChatFonts, iceChatEmoticons, iceChatSounds);
  4495. fs.SaveOptions += new FormSettings.SaveOptionsDelegate(fs_SaveOptions);
  4496. fs.ShowDialog(this);
  4497. }
  4498. private void fs_SaveOptions()
  4499. {
  4500. SaveOptions();
  4501. SaveFonts();
  4502. SaveSounds();
  4503. //implement the new Font Settings
  4504. //do all the Console Tabs Windows
  4505. foreach (ConsoleTab c in mainTabControl.GetTabPage("Console").ConsoleTab.TabPages)
  4506. {
  4507. ((TextWindow)c.Controls[0]).Font = new Font(iceChatFonts.FontSettings[0].FontName, iceChatFonts.FontSettings[0].FontSize);
  4508. if (((TextWindow)c.Controls[0]).MaximumTextLines != iceChatOptions.MaximumTextLines)
  4509. ((TextWindow)c.Controls[0]).MaximumTextLines = iceChatOptions.MaximumTextLines;
  4510. }
  4511. //do all the Channel and Query Tabs Windows
  4512. foreach (IceTabPage t in mainTabControl.TabPages)
  4513. {
  4514. if (t.WindowStyle == IceTabPage.WindowType.Channel)
  4515. t.TextWindow.Font = new Font(iceChatFonts.FontSettings[1].FontName, iceChatFonts.FontSettings[1].FontSize);
  4516. if (t.WindowStyle == IceTabPage.WindowType.Query)
  4517. t.TextWindow.Font = new Font(iceChatFonts.FontSettings[2].FontName, iceChatFonts.FontSettings[2].FontSize);
  4518. if (t.WindowStyle == IceTabPage.WindowType.DCCChat)
  4519. t.TextWindow.Font = new Font(iceChatFonts.FontSettings[2].FontName, iceChatFonts.FontSettings[2].FontSize);
  4520. if (t.WindowStyle == IceTabPage.WindowType.Window)
  4521. t.TextWindow.Font = new Font(iceChatFonts.FontSettings[1].FontName, iceChatFonts.FontSettings[1].FontSize);
  4522. if (t.WindowStyle != IceTabPage.WindowType.Console)
  4523. {
  4524. //check if value is different
  4525. if (t.TextWindow.MaximumTextLines != iceChatOptions.MaximumTextLines)
  4526. t.TextWindow.MaximumTextLines = iceChatOptions.MaximumTextLines;
  4527. }
  4528. }
  4529. //change the server list
  4530. serverTree.Font = new Font(iceChatFonts.FontSettings[4].FontName, iceChatFonts.FontSettings[4].FontSize);
  4531. serverTree.ShowServerButtons = iceChatOptions.ShowServerButtons;
  4532. //change the nick list
  4533. nickList.Font = new Font(iceChatFonts.FontSettings[3].FontName, iceChatFonts.FontSettings[3].FontSize);
  4534. nickList.ShowNickButtons = iceChatOptions.ShowNickButtons;
  4535. //change the fonts for the Left and Right Dock Panels
  4536. panelDockLeft.Initialize();
  4537. panelDockRight.Initialize();
  4538. //change the main Menu Bar Font
  4539. menuMainStrip.Font = new Font(iceChatFonts.FontSettings[7].FontName, iceChatFonts.FontSettings[7].FontSize);
  4540. //change the inputbox font
  4541. inputPanel.InputBoxFont = new Font(iceChatFonts.FontSettings[5].FontName, iceChatFonts.FontSettings[5].FontSize);
  4542. //set if Emoticon Picker/Color Picker is Visible
  4543. inputPanel.ShowEmoticonPicker = iceChatOptions.ShowEmoticonPicker;
  4544. inputPanel.ShowColorPicker = iceChatOptions.ShowColorPicker;
  4545. //set if Status Bar is Visible
  4546. statusStripMain.Visible = iceChatOptions.ShowStatusBar;
  4547. }
  4548. private void serverListToolStripMenuItem_Click(object sender, EventArgs e)
  4549. {
  4550. splitterLeft.Visible = serverListToolStripMenuItem.Checked;
  4551. panelDockLeft.Visible = serverListToolStripMenuItem.Checked;
  4552. iceChatOptions.ShowServerTree = serverListToolStripMenuItem.Checked;
  4553. }
  4554. private void nickListToolStripMenuItem_Click(object sender, EventArgs e)
  4555. {
  4556. splitterRight.Visible = nickListToolStripMenuItem.Checked;
  4557. panelDockRight.Visible = nickListToolStripMenuItem.Checked;
  4558. iceChatOptions.ShowNickList = nickListToolStripMenuItem.Checked;
  4559. }
  4560. private void statusBarToolStripMenuItem_Click(object sender, EventArgs e)
  4561. {
  4562. statusStripMain.Visible = statusBarToolStripMenuItem.Checked;
  4563. iceChatOptions.ShowStatusBar = statusBarToolStripMenuItem.Checked;
  4564. }
  4565. private void toolBarToolStripMenuItem_Click(object sender, EventArgs e)
  4566. {
  4567. toolStripMain.Visible = toolBarToolStripMenuItem.Checked;
  4568. iceChatOptions.ShowToolBar = toolBarToolStripMenuItem.Checked;
  4569. }
  4570. private void codePlexPageToolStripMenuItem_Click(object sender, EventArgs e)
  4571. {
  4572. try
  4573. {
  4574. ParseOutGoingCommand(null, "/browser http://icechat.codeplex.com");
  4575. }
  4576. catch { }
  4577. }
  4578. private void forumsToolStripMenuItem_Click(object sender, EventArgs e)
  4579. {
  4580. try
  4581. {
  4582. ParseOutGoingCommand(null, "/browser http://www.icechat.net/forums");
  4583. }
  4584. catch { }
  4585. }
  4586. private void iceChatHomePageToolStripMenuItem_Click(object sender, EventArgs e)
  4587. {
  4588. try
  4589. {
  4590. ParseOutGoingCommand(null, "/browser http://www.icechat.net/");
  4591. }
  4592. catch { }
  4593. }
  4594. private void facebookFanPageToolStripMenuItem_Click(object sender, EventArgs e)
  4595. {
  4596. try
  4597. {
  4598. ParseOutGoingCommand(null, "/browser http://www.facebook.com/IceChat");
  4599. }
  4600. catch { }
  4601. }
  4602. private void downloadPluginsToolStripMenuItem_Click(object sender, EventArgs e)
  4603. {
  4604. try
  4605. {
  4606. ParseOutGoingCommand(null, "/browser http://www.icechat.net/site/downloads/?category=4");
  4607. }
  4608. catch { }
  4609. }
  4610. private void iceChatColorsToolStripMenuItem_Click(object sender, EventArgs e)
  4611. {
  4612. //bring up a very basic settings form
  4613. FormColors fc = new FormColors(iceChatMessages, iceChatColors);
  4614. fc.SaveColors += new FormColors.SaveColorsDelegate(fc_SaveColors);
  4615. fc.ShowDialog(this);
  4616. }
  4617. private void fc_SaveColors(IceChatColors colors, IceChatMessageFormat messages)
  4618. {
  4619. this.iceChatColors = colors;
  4620. SaveColors();
  4621. this.iceChatMessages = messages;
  4622. SaveMessageFormat();
  4623. toolStripMain.BackColor = IrcColor.colors[iceChatColors.ToolbarBackColor];
  4624. menuMainStrip.BackColor = IrcColor.colors[iceChatColors.MenubarBackColor];
  4625. statusStripMain.BackColor = IrcColor.colors[iceChatColors.StatusbarBackColor];
  4626. toolStripStatus.ForeColor = IrcColor.colors[iceChatColors.StatusbarForeColor];
  4627. serverListTab.BackColor = IrcColor.colors[iceChatColors.PanelHeaderBG1];
  4628. serverListTab.ForeColor = IrcColor.colors[iceChatColors.PanelHeaderForeColor];
  4629. nickListTab.BackColor = IrcColor.colors[iceChatColors.PanelHeaderBG1];
  4630. nickListTab.ForeColor = IrcColor.colors[iceChatColors.PanelHeaderForeColor];
  4631. channelListTab.BackColor = IrcColor.colors[iceChatColors.PanelHeaderBG1];
  4632. channelListTab.ForeColor = IrcColor.colors[iceChatColors.PanelHeaderForeColor];
  4633. buddyListTab.BackColor = IrcColor.colors[iceChatColors.PanelHeaderBG1];
  4634. buddyListTab.ForeColor = IrcColor.colors[iceChatColors.PanelHeaderForeColor];
  4635. inputPanel.SetInputBoxColors();
  4636. channelList.SetListColors();
  4637. buddyList.SetListColors();
  4638. nickList.Invalidate();
  4639. serverTree.Invalidate();
  4640. mainTabControl.Invalidate();
  4641. //update all the console windows
  4642. foreach (ConsoleTab c in mainTabControl.GetTabPage("Console").ConsoleTab.TabPages)
  4643. {
  4644. ((TextWindow)c.Controls[0]).IRCBackColor = iceChatColors.ConsoleBackColor;
  4645. }
  4646. //update all the Channel and Query Tabs Windows
  4647. foreach (IceTabPage t in mainTabControl.TabPages)
  4648. {
  4649. if (t.WindowStyle == IceTabPage.WindowType.Channel)
  4650. t.TextWindow.IRCBackColor = iceChatColors.ChannelBackColor;
  4651. if (t.WindowStyle == IceTabPage.WindowType.Query)
  4652. t.TextWindow.IRCBackColor = iceChatColors.QueryBackColor;
  4653. }
  4654. }
  4655. private void toolStripSettings_Click(object sender, EventArgs e)
  4656. {
  4657. iceChatSettingsToolStripMenuItem.PerformClick();
  4658. }
  4659. private void toolStripColors_Click(object sender, EventArgs e)
  4660. {
  4661. iceChatColorsToolStripMenuItem.PerformClick();
  4662. }
  4663. private void toolStripQuickConnect_Click(object sender, EventArgs e)
  4664. {
  4665. //popup a small dialog asking for basic server settings
  4666. QuickConnect qc = new QuickConnect();
  4667. qc.QuickConnectServer += new QuickConnect.QuickConnectServerDelegate(OnQuickConnectServer);
  4668. qc.ShowDialog(this);
  4669. }
  4670. private void toolStripAway_Click(object sender, EventArgs e)
  4671. {
  4672. //check if away or not
  4673. if (FormMain.Instance.InputPanel.CurrentConnection != null)
  4674. {
  4675. if (inputPanel.CurrentConnection.ServerSetting.Away)
  4676. {
  4677. ParseOutGoingCommand(inputPanel.CurrentConnection, "/away");
  4678. }
  4679. else
  4680. {
  4681. //ask for an away reason
  4682. InputBoxDialog i = new InputBoxDialog();
  4683. i.FormCaption = "Enter your away Reason";
  4684. i.FormPrompt = "Away Reason";
  4685. i.ShowDialog();
  4686. if (i.InputResponse.Length > 0)
  4687. ParseOutGoingCommand(inputPanel.CurrentConnection, "/away " + i.InputResponse);
  4688. i.Dispose();
  4689. }
  4690. }
  4691. }
  4692. private void toolStripUpdate_Click(object sender, EventArgs e)
  4693. {
  4694. //update is available, start the updater
  4695. CurrentWindowMessage(inputPanel.CurrentConnection, "There is a newer version of IceChat available", 4, true);
  4696. DialogResult result = MessageBox.Show("Would you like to update to the newer version of IceChat?", "IceChat Update available", MessageBoxButtons.YesNo);
  4697. if (result == DialogResult.Yes)
  4698. {
  4699. System.Diagnostics.Process.Start(Application.StartupPath + System.IO.Path.DirectorySeparatorChar + "IceChatUpdater.exe", "\"" + currentFolder + "\"");
  4700. }
  4701. }
  4702. private void OnQuickConnectServer(ServerSetting s)
  4703. {
  4704. s.NickName = iceChatOptions.DefaultNick;
  4705. s.AltNickName = iceChatOptions.DefaultNick + "_";
  4706. s.AwayNickName = iceChatOptions.DefaultNick + "[A]";
  4707. s.FullName = iceChatOptions.DefaultFullName;
  4708. s.QuitMessage = iceChatOptions.DefaultQuitMessage;
  4709. s.IdentName = iceChatOptions.DefaultIdent;
  4710. s.IAL = new Hashtable();
  4711. Random r = new Random();
  4712. s.ID = r.Next(50000, 99999);
  4713. NewServerConnection(s);
  4714. }
  4715. private void hideToolStripMenuItem_Click(object sender, EventArgs e)
  4716. {
  4717. toolStripMain.Visible = false;
  4718. }
  4719. private void iceChatEditorToolStripMenuItem_Click(object sender, EventArgs e)
  4720. {
  4721. FormEditor fe = new FormEditor();
  4722. fe.ShowDialog(this);
  4723. }
  4724. private void toolStripSystemTray_Click(object sender, EventArgs e)
  4725. {
  4726. minimizeToTrayToolStripMenuItem.PerformClick();
  4727. }
  4728. private void toolStripEditor_Click(object sender, EventArgs e)
  4729. {
  4730. iceChatEditorToolStripMenuItem.PerformClick();
  4731. }
  4732. private void debugWindowToolStripMenuItem_Click(object sender, EventArgs e)
  4733. {
  4734. //add the debug window, if it does not exist
  4735. if (GetWindow(null, "Debug", IceTabPage.WindowType.Debug) == null)
  4736. AddWindow(null, "Debug", IceTabPage.WindowType.Debug);
  4737. mainTabControl.SelectTab(mainTabControl.GetTabPage("Debug"));
  4738. serverTree.Invalidate();
  4739. }
  4740. private void restoreToolStripMenuItem_Click(object sender, EventArgs e)
  4741. {
  4742. iceChatOptions.IsOnTray = false;
  4743. this.Show();
  4744. this.notifyIcon.Visible = false;
  4745. }
  4746. private void exitToolStripMenuItem1_Click(object sender, EventArgs e)
  4747. {
  4748. this.exitToolStripMenuItem.PerformClick();
  4749. }
  4750. private void OnPluginMenuItemClick(object sender, EventArgs e)
  4751. {
  4752. //show plugin information
  4753. FormPluginInfo pi = new FormPluginInfo((IPluginIceChat)((ToolStripMenuItem)sender).Tag, (ToolStripMenuItem)sender);
  4754. pi.ShowDialog(this);
  4755. }
  4756. #endregion
  4757. //http://www.codeproject.com/KB/cs/dynamicpluginmanager.aspx
  4758. private void loadPlugin(string fileName)
  4759. {
  4760. string args = fileName.Substring(fileName.LastIndexOf("\\") + 1);
  4761. args = args.Substring(0, args.Length - 4);
  4762. AppDomainSetup setup = new AppDomainSetup();
  4763. setup.ApplicationName = args;
  4764. setup.ApplicationBase = AppDomain.CurrentDomain.BaseDirectory;
  4765. setup.PrivateBinPath = "Plugins";
  4766. //setup.PrivateBinPath = AppDomain.CurrentDomain.BaseDirectory;
  4767. //setup.CachePath = pluginsFolder + Path.DirectorySeparatorChar + "cache";
  4768. //setup.ShadowCopyFiles = "true";
  4769. //setup.ShadowCopyDirectories = pluginsFolder;
  4770. //AppDomain appDomain = AppDomain.CreateDomain(args + "_AppDomain", null, setup);
  4771. //Type loaderType = typeof(AssemblyLoader);
  4772. //AssemblyLoader l = (AssemblyLoader)appDomain.CreateInstance(Assembly.GetExecutingAssembly().FullName, loaderType.FullName).Unwrap();
  4773. Type ObjType = null;
  4774. try
  4775. {
  4776. //System.Diagnostics.Debug.WriteLine(fileName);
  4777. //Assembly ass = l.LoadAssembly(args);
  4778. //Assembly ass = l.LoadAssembly(fileName);
  4779. //ObjType = l.LoadAssembly(fileName);
  4780. //System.Diagnostics.Debug.WriteLine(ObjType.Asse);
  4781. Assembly ass = null;
  4782. ass = Assembly.LoadFile(fileName);
  4783. if (ass != null)
  4784. {
  4785. ObjType = ass.GetType("IceChatPlugin.Plugin");
  4786. }
  4787. else
  4788. {
  4789. System.Diagnostics.Debug.WriteLine("assembly is null");
  4790. return;
  4791. }
  4792. }
  4793. catch (Exception ex)
  4794. {
  4795. WriteErrorFile(inputPanel.CurrentConnection, "LoadPlugin Error ", ex);
  4796. return;
  4797. }
  4798. try
  4799. {
  4800. // OK Lets create the object as we have the Report Type
  4801. if (ObjType != null)
  4802. {
  4803. IPluginIceChat ipi = (IPluginIceChat)Activator.CreateInstance(ObjType);
  4804. ipi.MainForm = this;
  4805. ipi.MainMenuStrip = menuMainStrip;
  4806. ipi.CurrentFolder = currentFolder;
  4807. ipi.BottomPanel = panelDockBottom;
  4808. ipi.FileName = fileName.Substring(fileName.LastIndexOf("\\") + 1);
  4809. ipi.LeftPanel = panelDockLeft.TabControl;
  4810. ipi.RightPanel = panelDockRight.TabControl;
  4811. //ipi.domain = appDomain;
  4812. ipi.domain = null;
  4813. ipi.Enabled = true; //enable it by default
  4814. WindowMessage(null, "Console", "Loaded Plugin - " + ipi.Name + " v" + ipi.Version + " by " + ipi.Author, 4, true);
  4815. //add the menu items
  4816. ToolStripMenuItem t = new ToolStripMenuItem(ipi.Name);
  4817. t.Tag = ipi;
  4818. t.ToolTipText = fileName.Substring(fileName.LastIndexOf("\\") + 1);
  4819. t.Click += new EventHandler(OnPluginMenuItemClick);
  4820. pluginsToolStripMenuItem.DropDownItems.Add(t);
  4821. ipi.OnCommand += new OutGoingCommandHandler(Plugin_OnCommand);
  4822. ipi.Initialize();
  4823. loadedPlugins.Add(ipi);
  4824. }
  4825. else
  4826. {
  4827. System.Diagnostics.Debug.WriteLine("obj type is null:" + args);
  4828. }
  4829. }
  4830. catch (Exception ex)
  4831. {
  4832. WriteErrorFile(inputPanel.CurrentConnection, "LoadPlugin Error", ex);
  4833. }
  4834. }
  4835. private void LoadPlugins()
  4836. {
  4837. string[] pluginFiles = Directory.GetFiles(pluginsFolder, "*.dll");
  4838. for (int i = 0; i < pluginFiles.Length; i++)
  4839. {
  4840. //string args = pluginFiles[i].Substring(pluginFiles[i].LastIndexOf("\\") + 1);
  4841. //args = args.Substring(0, args.Length - 4);
  4842. loadPlugin(pluginFiles[i]);
  4843. }
  4844. }
  4845. private void Plugin_OnCommand(PluginArgs e)
  4846. {
  4847. if (e.Command != null)
  4848. {
  4849. if (e.Connection != null)
  4850. ParseOutGoingCommand(e.Connection, e.Command);
  4851. else
  4852. {
  4853. if (e.Extra == "current")
  4854. ParseOutGoingCommand(inputPanel.CurrentConnection, e.Command);
  4855. else
  4856. ParseOutGoingCommand(null, e.Command);
  4857. }
  4858. }
  4859. }
  4860. internal void UnloadPlugin(ToolStripMenuItem menuItem)
  4861. {
  4862. ParseOutGoingCommand(null, "/unloadplugin " + menuItem.ToolTipText);
  4863. }
  4864. internal void StatusPlugin(ToolStripMenuItem menuItem, bool enable)
  4865. {
  4866. for (int i = 0; i < iceChatPlugins.listPlugins.Count; i++)
  4867. {
  4868. if (((PluginItem)iceChatPlugins.listPlugins[i]).PluginFile.Equals(menuItem.ToolTipText))
  4869. {
  4870. ((PluginItem)iceChatPlugins.listPlugins[i]).Enabled = enable;
  4871. SavePluginFiles();
  4872. }
  4873. }
  4874. ParseOutGoingCommand(null, "/statusplugin " + enable.ToString() + " " + menuItem.ToolTipText);
  4875. }
  4876. /// <summary>
  4877. /// Write out to the errors file, specific to the Connection
  4878. /// </summary>
  4879. /// <param name="connection"></param>
  4880. /// <param name="method"></param>
  4881. /// <param name="e"></param>
  4882. internal void WriteErrorFile(IRCConnection connection, string method, Exception e)
  4883. {
  4884. System.Diagnostics.Debug.WriteLine(e.Message + ":" + e.StackTrace);
  4885. System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(e, true);
  4886. WindowMessage(connection, "Console", "Error:" + method + ":" + e.Message + ":" + e.StackTrace, 4, true);
  4887. if (errorFile != null)
  4888. {
  4889. try
  4890. {
  4891. errorFile.WriteLine(DateTime.Now.ToString("G") + ":" + method + ":" + e.Message + ":" + e.StackTrace + ":" + trace.GetFrame(0).GetFileLineNumber());
  4892. }
  4893. catch { }
  4894. finally
  4895. {
  4896. //errorFile.Flush();
  4897. }
  4898. }
  4899. }
  4900. /// <summary>
  4901. /// Write out to the errors file, not Connection Specific
  4902. /// </summary>
  4903. /// <param name="method"></param>
  4904. /// <param name="e"></param>
  4905. internal void WriteErrorFile(string method, FileNotFoundException e)
  4906. {
  4907. System.Diagnostics.Debug.WriteLine(e.Message + ":" + e.StackTrace);
  4908. System.Diagnostics.StackTrace trace = new System.Diagnostics.StackTrace(e, true);
  4909. WindowMessage(inputPanel.CurrentConnection, "Console", "Error:" + method + ":" + e.Message + ":" + e.StackTrace + ":" + trace.GetFrame(0).GetFileLineNumber(), 4, true);
  4910. if (errorFile != null)
  4911. {
  4912. errorFile.WriteLine(DateTime.Now.ToString("G") + ":" + method + ":" + e.Message + ":" + e.StackTrace + ":" + trace.GetFrame(0).GetFileLineNumber());
  4913. errorFile.Flush();
  4914. }
  4915. }
  4916. private void getLocalIPAddress()
  4917. {
  4918. //find your internet IP Address
  4919. System.Net.WebRequest request = System.Net.WebRequest.Create("http://www.icechat.net/_ipaddress.php");
  4920. System.Net.WebResponse response = request.GetResponse();
  4921. StreamReader stream = new StreamReader(response.GetResponseStream());
  4922. string data = stream.ReadToEnd();
  4923. stream.Close();
  4924. response.Close();
  4925. //remove any linefeeds and such
  4926. data = data.Replace("\n", "");
  4927. iceChatOptions.DCCLocalIP = data.Trim();
  4928. //save the settings
  4929. SaveOptions();
  4930. }
  4931. private void checkForUpdate()
  4932. {
  4933. //check for newer version
  4934. System.Diagnostics.FileVersionInfo fv = System.Diagnostics.FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location);
  4935. double currentVersion = Convert.ToDouble(fv.FileVersion.Replace(".", String.Empty));
  4936. try
  4937. {
  4938. System.Net.WebClient webClient = new System.Net.WebClient();
  4939. webClient.DownloadFile("http://www.icechat.net/update.xml", currentFolder + System.IO.Path.DirectorySeparatorChar + "update.xml");
  4940. System.Xml.XmlDocument xmlDoc = new System.Xml.XmlDocument();
  4941. xmlDoc.Load(currentFolder + System.IO.Path.DirectorySeparatorChar + "update.xml");
  4942. System.Xml.XmlNodeList version = xmlDoc.GetElementsByTagName("version");
  4943. System.Xml.XmlNodeList versiontext = xmlDoc.GetElementsByTagName("versiontext");
  4944. if (Convert.ToDouble(version[0].InnerText) > currentVersion)
  4945. {
  4946. this.toolStripUpdate.Visible = true;
  4947. }
  4948. else
  4949. {
  4950. this.toolStripUpdate.Visible = false;
  4951. CurrentWindowMessage(inputPanel.CurrentConnection, "You are running the latest version of IceChat (" + fv.FileVersion + ") -- Version Online = " + versiontext[0].InnerText, 4, true);
  4952. }
  4953. }
  4954. catch (Exception ex)
  4955. {
  4956. CurrentWindowMessage(inputPanel.CurrentConnection, "Error checking for update:" + ex.Message, 4, true);
  4957. }
  4958. }
  4959. private void checkForUpdateToolStripMenuItem_Click(object sender, EventArgs e)
  4960. {
  4961. ParseOutGoingCommand(null, "/update");
  4962. }
  4963. private void tabControl_DoubleClick(object sender, EventArgs e)
  4964. {
  4965. TabControl t = (TabControl)sender;
  4966. if (t.SelectedTab.Controls[0].GetType() == typeof(Panel))
  4967. {
  4968. Panel p = (Panel)t.SelectedTab.Controls[0];
  4969. UnDockPanel(p);
  4970. }
  4971. }
  4972. /// <summary>
  4973. /// Undock the Specified Panel to a Floating Window
  4974. /// </summary>
  4975. /// <param name="p">The panel to remove and add to a Floating Window</param>
  4976. internal void UnDockPanel(Panel p)
  4977. {
  4978. if (p.Parent.GetType() == typeof(TabPage))
  4979. {
  4980. //System.Diagnostics.Debug.WriteLine(panel1.Parent.Name);
  4981. //remove the tab from the tabStrip
  4982. TabControl t = (TabControl)p.Parent.Parent;
  4983. TabPage tp = (TabPage)p.Parent;
  4984. ((TabControl)p.Parent.Parent).TabPages.Remove((TabPage)p.Parent);
  4985. ((TabPage)p.Parent).Controls.Remove(p);
  4986. if (t.TabPages.Count == 0)
  4987. {
  4988. //hide the splitter bar along with the panel
  4989. if (t.Parent == panelDockLeft)
  4990. splitterLeft.Visible = false;
  4991. else if (t.Parent == panelDockRight)
  4992. splitterRight.Visible = false;
  4993. t.Parent.Visible = false;
  4994. }
  4995. FormFloat formFloat = new FormFloat(ref p, this, tp.Text);
  4996. formFloat.Show();
  4997. if (Cursor.Position.X - (formFloat.Width / 2) > 0)
  4998. formFloat.Left = Cursor.Position.X - (formFloat.Width / 2);
  4999. else
  5000. formFloat.Left = 0;
  5001. formFloat.Top = Cursor.Position.Y;
  5002. }
  5003. }
  5004. /// <summary>
  5005. /// Re-Dock the Panel checking whether it is closer to the right or left
  5006. /// </summary>
  5007. /// <param name="panel">The panel to re-dock</param>
  5008. /// <param name="formLocation">Current Location of the Floating Form</param>
  5009. /// <param name="tabName">The panels caption</param>
  5010. internal void SetPanel(ref Panel panel, Point formLocation, string tabName)
  5011. {
  5012. if (formLocation.X < (this.Left + 200))
  5013. {
  5014. TabPage p = new TabPage(tabName);
  5015. p.Controls.Add(panel);
  5016. panel.Dock = DockStyle.Fill;
  5017. this.panelDockLeft.TabControl.TabPages.Add(p);
  5018. this.panelDockLeft.TabControl.Visible = true;
  5019. panelDockLeft.Visible = true;
  5020. splitterLeft.Visible = true;
  5021. this.panelDockLeft.TabControl.SelectedTab = p;
  5022. }
  5023. else
  5024. {
  5025. TabPage p = new TabPage(tabName);
  5026. p.Controls.Add(panel);
  5027. panel.Dock = DockStyle.Fill;
  5028. this.panelDockRight.TabControl.TabPages.Add(p);
  5029. this.panelDockRight.TabControl.Visible = true;
  5030. panelDockRight.Visible = true;
  5031. splitterRight.Visible = true;
  5032. this.panelDockRight.TabControl.SelectedTab = p;
  5033. }
  5034. }
  5035. private void browseDataFolderToolStripMenuItem_Click(object sender, EventArgs e)
  5036. {
  5037. ParseOutGoingCommand(null, "/run " + currentFolder);
  5038. }
  5039. private void browsePluginsFolderToolStripMenuItem_Click(object sender, EventArgs e)
  5040. {
  5041. ParseOutGoingCommand(null, "/run " + pluginsFolder);
  5042. }
  5043. private void closeCurrentWindowToolStripMenuItem_Click(object sender, EventArgs e)
  5044. {
  5045. //close the current window
  5046. mainTabControl.CloseCurrentTab();
  5047. }
  5048. private void selectNickListToolStripMenuItem_Click(object sender, EventArgs e)
  5049. {
  5050. //give the nick list the current focus
  5051. nickList.Focus();
  5052. }
  5053. private void selectServerTreeToolStripMenuItem_Click(object sender, EventArgs e)
  5054. {
  5055. //give the server tree the current focus
  5056. serverTree.Focus();
  5057. }
  5058. private void selectInputBoxToolStripMenuItem_Click(object sender, EventArgs e)
  5059. {
  5060. FocusInputBox();
  5061. }
  5062. private void muteAllSoundsToolStripMenuItem_Click(object sender, EventArgs e)
  5063. {
  5064. //mute all sounds
  5065. muteAllSounds = !muteAllSounds;
  5066. muteAllSoundsToolStripMenuItem.Checked = muteAllSounds;
  5067. }
  5068. private void loadAPluginToolStripMenuItem_Click(object sender, EventArgs e)
  5069. {
  5070. //bring up a dialog box to open a new Plugin DLL File
  5071. FileDialog fd = new OpenFileDialog();
  5072. fd.DefaultExt = ".dll";
  5073. fd.CheckFileExists = true;
  5074. fd.CheckPathExists = true;
  5075. fd.AddExtension = true;
  5076. fd.AutoUpgradeEnabled = true;
  5077. fd.Filter = "Plugin file (*.dll)|*.dll";
  5078. fd.Title = "Which plugin file do you want to open?";
  5079. fd.InitialDirectory = pluginsFolder;
  5080. if (fd.ShowDialog() == DialogResult.OK)
  5081. {
  5082. //currentScript = fd.FileName;
  5083. //need to make sure the plugin is not already loaded
  5084. foreach (ToolStripItem item in pluginsToolStripMenuItem.DropDownItems)
  5085. {
  5086. if (item.ToolTipText.ToLower() == System.IO.Path.GetFileName(fd.FileName).ToLower())
  5087. {
  5088. return;
  5089. }
  5090. }
  5091. //System.Diagnostics.Debug.WriteLine(fd.FileName);
  5092. loadPlugin(fd.FileName);
  5093. }
  5094. }
  5095. private void bottomPanelToolStripMenuItem_Click(object sender, EventArgs e)
  5096. {
  5097. splitterBottom.Visible = bottomPanelToolStripMenuItem.Checked;
  5098. panelDockBottom.Visible = bottomPanelToolStripMenuItem.Checked;
  5099. }
  5100. }
  5101. #region IceDockPanel Class
  5102. //custom panel class for docking
  5103. internal class IceDockPanel : Panel
  5104. {
  5105. private TabControl _tabControl;
  5106. private bool _docked;
  5107. private int _oldDockWidth;
  5108. public IceDockPanel()
  5109. {
  5110. _tabControl = new TabControl();
  5111. _tabControl.Dock = DockStyle.Fill;
  5112. _tabControl.Multiline = true;
  5113. _tabControl.TabStop = false;
  5114. _tabControl.SizeMode = TabSizeMode.Fixed;
  5115. _tabControl.ItemSize = new Size(150, 20);
  5116. _tabControl.DrawMode = TabDrawMode.OwnerDrawFixed;
  5117. _tabControl.Alignment = TabAlignment.Left;
  5118. _tabControl.DrawItem += new DrawItemEventHandler(OnDrawItem);
  5119. _tabControl.DoubleClick += new EventHandler(OnDoubleClick);
  5120. _tabControl.MouseDown += new MouseEventHandler(OnMouseDown);
  5121. _tabControl.MouseHover += new EventHandler(OnMouseHover);
  5122. _tabControl.MouseLeave += new EventHandler(OnMouseLeave);
  5123. this.Controls.Add(_tabControl);
  5124. }
  5125. private void OnDrawItem(object sender, DrawItemEventArgs e)
  5126. {
  5127. Rectangle tabRect = _tabControl.GetTabRect(e.Index);
  5128. Brush textBrush = new SolidBrush(Color.Black);
  5129. Graphics g = e.Graphics;
  5130. Pen p = new Pen(Color.Gray);
  5131. g.DrawRectangle(p, tabRect);
  5132. if (_tabControl.Alignment == TabAlignment.Left)
  5133. {
  5134. g.TranslateTransform(tabRect.Left, tabRect.Height + tabRect.Top);
  5135. g.RotateTransform(270);
  5136. g.DrawString(_tabControl.TabPages[e.Index].Text, _tabControl.Font, textBrush, 10, 0);
  5137. }
  5138. else
  5139. {
  5140. g.TranslateTransform(tabRect.Left, tabRect.Top);
  5141. g.RotateTransform(90);
  5142. g.DrawString(_tabControl.TabPages[e.Index].Text, _tabControl.Font, textBrush, 10, -20);
  5143. }
  5144. g.ResetTransform();
  5145. }
  5146. private void OnMouseDown(object sender, MouseEventArgs e)
  5147. {
  5148. if (_docked)
  5149. {
  5150. this.Width = _oldDockWidth;
  5151. if (this.Dock == DockStyle.Left)
  5152. FormMain.Instance.splitterLeft.Visible = true;
  5153. else
  5154. FormMain.Instance.splitterRight.Visible = true;
  5155. _docked = false;
  5156. }
  5157. }
  5158. private void OnMouseLeave(object sender, EventArgs e)
  5159. {
  5160. if (_docked)
  5161. this.Width = 24;
  5162. }
  5163. private void OnMouseHover(object sender, EventArgs e)
  5164. {
  5165. if (_docked)
  5166. this.Width = _oldDockWidth;
  5167. }
  5168. internal bool IsDocked
  5169. {
  5170. get { return _docked; }
  5171. }
  5172. internal void DockControl()
  5173. {
  5174. if (!_docked)
  5175. {
  5176. _docked = true;
  5177. _oldDockWidth = this.Width;
  5178. this.Width = 24;
  5179. if (this.Dock == DockStyle.Left)
  5180. FormMain.Instance.splitterLeft.Visible = false;
  5181. else
  5182. FormMain.Instance.splitterRight.Visible = false;
  5183. }
  5184. }
  5185. internal TabControl TabControl
  5186. {
  5187. get { return _tabControl; }
  5188. }
  5189. private void OnResize(object sender, EventArgs e)
  5190. {
  5191. //throw new NotImplementedException();
  5192. //System.Diagnostics.Debug.WriteLine(_tabControl.Width + ":" + _tabControl.ItemSize.Width + ":" + _tabControl.RowCount + ":" + (_tabControl.Width - _tabControl.DisplayRectangle.Width));
  5193. }
  5194. private void OnDoubleClick(object sender, EventArgs e)
  5195. {
  5196. if (_tabControl.SelectedTab.Controls[0].GetType() == typeof(Panel))
  5197. {
  5198. Panel p = (Panel)_tabControl.SelectedTab.Controls[0];
  5199. UnDockPanel(p);
  5200. }
  5201. }
  5202. /// <summary>
  5203. /// Setup the Tabs Font to the setting
  5204. /// </summary>
  5205. internal void Initialize()
  5206. {
  5207. //_tabControl.Font = new System.Drawing.Font(FormMain.Instance.IceChatFonts.FontSettings[6].FontName, FormMain.Instance.IceChatFonts.FontSettings[6].FontSize, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
  5208. _tabControl.Font = new Font(FormMain.Instance.IceChatFonts.FontSettings[6].FontName, 10);
  5209. _tabControl.ForeColor = System.Drawing.SystemColors.ControlText;
  5210. _tabControl.Appearance = TabAppearance.Normal;
  5211. }
  5212. /// <summary>
  5213. /// Undock the Specified Panel to a Floating Window
  5214. /// </summary>
  5215. /// <param name="p">The panel to remove and add to a Floating Window</param>
  5216. internal void UnDockPanel(Panel p)
  5217. {
  5218. if (p.Parent.GetType() == typeof(TabPage))
  5219. {
  5220. //remove the tab from the tabStrip
  5221. TabPage tp = (TabPage)p.Parent;
  5222. _tabControl.TabPages.Remove((TabPage)p.Parent);
  5223. ((TabPage)p.Parent).Controls.Remove(p);
  5224. if (_tabControl.TabPages.Count == 0)
  5225. {
  5226. //hide the splitter bar along with the panel
  5227. if (this.Dock == DockStyle.Left)
  5228. FormMain.Instance.splitterLeft.Visible = false;
  5229. else
  5230. FormMain.Instance.splitterRight.Visible = false;
  5231. this.Visible = false;
  5232. }
  5233. FormFloat formFloat = new FormFloat(ref p, FormMain.Instance, tp.Text);
  5234. formFloat.Show();
  5235. formFloat.Left = Cursor.Position.X - (formFloat.Width / 2);
  5236. formFloat.Top = Cursor.Position.Y;
  5237. }
  5238. }
  5239. }
  5240. #endregion
  5241. public class AssemblyLoader : MarshalByRefObject
  5242. {
  5243. public Assembly LoadAssembly(string assemblyName)
  5244. {
  5245. return Assembly.Load(assemblyName);
  5246. //works but loads twice
  5247. //byte[] assemblyFileBuffer = File.ReadAllBytes(assemblyName);
  5248. //return Assembly.Load(assemblyFileBuffer);
  5249. }
  5250. }
  5251. }