// Form events private async void Form1_Load(object sender, EventArgs e) { this.Text = "STALK-IRC Client " + Application.ProductVersion; if (await CheckUpdate(false)) { return; } name = (string)REGISTRY.GetValue("Name", null); faction = Regex.Replace((string)REGISTRY.GetValue("Faction", "Loners"), " ", ""); timeout = (string)REGISTRY.GetValue("Timeout", "10000"); chatKey = (string)REGISTRY.GetValue("ChatKey", "DIK_APOSTROPHE"); sendDeaths = (string)REGISTRY.GetValue("SendDeaths", "True") == "True"; receiveDeaths = (string)REGISTRY.GetValue("ReceiveDeaths", "True") == "True"; muhAtmospheres = (string)REGISTRY.GetValue("MuhAtmospheres", "False") == "True"; SIStrings.Populate(); if (name == null) { name = SIStrings.GenerateName().Replace(' ', '_'); REGISTRY.SetValue("Name", name); } string lastVersion = (string)REGISTRY.GetValue("Version", null); if (lastVersion != Application.ProductVersion) { string previousGames = (string)REGISTRY.GetValue("GameList", ""); if (previousGames != "") { new ReinstallForm(previousGames).ShowDialog(); } else { MessageBox.Show("Thank you for downloading STALK-IRC " + Application.ProductVersion + ".\nDue to the update, remember to re-install the mod component for each of your games before use.", "Update!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } } REGISTRY.SetValue("Version", Application.ProductVersion); irc.Encoding = Encoding.UTF8; irc.SendDelay = 200; irc.ActiveChannelSyncing = true; irc.OnRawMessage += new IrcEventHandler(OnRawMessage); irc.OnChannelMessage += new IrcEventHandler(OnChannelMessage); irc.OnJoin += new JoinEventHandler(OnJoin); irc.OnNickChange += new NickChangeEventHandler(OnNickChange); irc.OnQueryMessage += new IrcEventHandler(OnChannelMessage); irc.Connect(SERVER, 6667); irc.Login(name, "STALK-IRC Client " + Application.ProductVersion); irc.RfcJoin(CHANNEL); ircListen = new Thread(irc.Listen); ircListen.Start(); timer1_Tick(null, null); }
// Name - Random private void button1_Click(object sender, EventArgs e) { textBox1.Text = SIStrings.GenerateName(); }
// Checking for input from games every second private void timer2_Tick(object sender, EventArgs e) { if (doClose) { Close(); } foreach (string path in games.Values) { List <string> lines = new List <string>(); if (socData.ContainsKey(path)) { string[] logLines = { }; FileTryLoop(() => logLines = File.ReadAllLines(socData[path].logPath, RUENCODING)); if (logLines.Length < socData[path].lastLines) { socData[path].lastLines = 0; } for (int index = socData[path].lastLines; index != logLines.Length; index++) { Match match = Regex.Match(logLines[index], "~#stalk-irc (.+)"); if (match.Success) { lines.Add(match.Groups[1].Value); } } socData[path].lastLines = logLines.Length; } else { string[] lineArray = { }; FileTryLoop(() => { lineArray = File.ReadAllLines(path + OUTPUT, RUENCODING); File.WriteAllText(path + OUTPUT, "", RUENCODING); }); foreach (string line in lineArray) { lines.Add(line); } } foreach (string line in lines) { if (line.Length > 0) { Match match = Regex.Match(line, "([^/]+)/?(.*)"); string command = match.Groups[1].Value; string arguments = match.Groups[2].Value; string game, message; switch (command) { case "1": // Settings request SendCommand(path, 1, "timeout", timeout); SendCommand(path, 1, "chatkey", chatKey); SendCommand(path, 1, "atmospheres", muhAtmospheres.ToString()); break; case "2": // Normal message Match messageMatch = Regex.Match(arguments, "([^/]+)/(.+)"); game = messageMatch.Groups[1].Value; lastGame = game; message = messageMatch.Groups[2].Value; Match cmdMatch = Regex.Match(message, "^/([^ ]+) ?(.*)"); string result; if (cmdMatch.Success) { result = ProcessCommand(cmdMatch, true); if (result != "") { AddOneGameMsg(path, "Information", result); } } else { irc.SendMessage(SendType.Message, CHANNEL, faction + "/" + game + METADELIM + message); AddClientMsg(irc.Nickname, message, Color.Black, Color.DimGray); AddGameMsg(irc.Nickname, message, faction, game); } break; case "3": // Death message if (sendDeaths) { Match deathMatch = Regex.Match(arguments, "([^/]+)/([^/]+)/([^/]+)/(.+)"); game = deathMatch.Groups[1].Value; lastGame = game; string level = deathMatch.Groups[2].Value; string section = deathMatch.Groups[3].Value; string classType = deathMatch.Groups[4].Value; string randName = SIStrings.GenerateName(); message = SIStrings.BuildSentence(irc.Nickname, level, section, classType); irc.SendMessage(SendType.Message, CHANNEL, randName + FAKEDELIM + "Loners/" + game + METADELIM + message); AddClientMsg(randName, message, Color.DarkRed); AddGameMsg(randName, message, "Loners", game); } break; default: AddClientLine("Error: Client got bad command. Path: " + path + " | Line: " + line, Color.LimeGreen); AddGameMsg("Error: Client got bad command.", "Path: " + path + " | Line: " + line); break; } } } } }