protected override void OnUpdateFrame(FrameEventArgs e) { heartbeatTime += e.Time; //n.OnUpdateFrame(e); nm.update(e); if (heartbeatTime > 30 && conn.Bw != null) { try { Client.PacketWriter.sendClientHeartbeat(conn.Bw); heartbeatTime = 0; } catch { } } if (!screenChange) { if (!active.loaded) { active.OnLoad(null); active.loaded = true; active.switched = true; } else if (!active.switched && active.loaded) { active.onSwitched(); active.switched = true; } } if (displayUsers) { userScreen.OnUpdateFrame(e); } pbox.OnUpdateFrame(e); sleepCount++; if (sleepCount >= 10) { //need to work out a good way to use this to limit the cpu usage, or find another way to do it //skipFrame = true; sleepCount = 0; } if (verRemind) { System.Windows.Forms.MessageBox.Show("Client version (" + Config.Version + ") out of date! Latest (" + serverVer + ") available on the updater."); verRemind = false; } if (pressedKey.Contains(Key.F3) && userToggle) { userToggle = false; displayUsers = !displayUsers; if (displayUsers) { if (ircl != null) { string userss = ""; foreach (string i in ircl.pulseUsers) { userss += i.Split('|')[1] + ";"; } // Console.WriteLine(userss); Client.PacketWriter.sendUserRequest(Game.conn.Bw, userss); } } } else if (!pressedKey.Contains(Key.F3)) { userToggle = true; } if (Keyboard[OpenTK.Input.Key.AltLeft] && Keyboard[OpenTK.Input.Key.F4]) { this.Exit(); } if (toasts.Count > 0 && activeToast == null) { activeToast = toasts.Dequeue(); t.Update(activeToast.text); } if (activeToast != null) { if (activeToast.y < 0 && activeToast.DisplayTime > 0) { activeToast.y += 2; toasttexture.Bounds = new Rectangle(0, activeToast.y, Config.ResWidth, 50); t.Location = new Point(50, activeToast.y); } if (activeToast.y == 0) { activeToast.DisplayTime--; } if (activeToast.DisplayTime <= 0) { activeToast.y -= 2; toasttexture.Bounds = new Rectangle(0, activeToast.y, Config.ResWidth, 50); t.Location = new Point(50, activeToast.y); } if (activeToast.y <= -50) { activeToast = null; toasttexture.Bounds = new Rectangle(0, 0, Config.ResWidth, 50); t.Location = new Point(50, 0); } } base.OnUpdateFrame(e); time += e.Time; if (Config.DisplayFps) { if (time > 0.25) { time = 0; fpsText.Update("fps: " + frameCount * 4); frameCount = 0; } } if (volumeLife > 0) { volumeLife -= (int)(e.Time * 1000); if (volumeTexture.Bounds.Y > 730) { volumeTexture.Bounds = new Rectangle(volumeTexture.Bounds.X, volumeTexture.Bounds.Y - 5, volumeTexture.Bounds.Width, volumeTexture.Bounds.Height); volumeRect.Bounds = new Rectangle(volumeRect.Bounds.X, volumeRect.Bounds.Y - 5, volumeRect.Bounds.Width, volumeRect.Bounds.Height); } } if (volumeLife <= 0 && volumeTexture.Bounds.Y < 768) { volumeTexture.Bounds = new Rectangle(volumeTexture.Bounds.X, volumeTexture.Bounds.Y + 5, volumeTexture.Bounds.Width, volumeTexture.Bounds.Height); volumeRect.Bounds = new Rectangle(volumeRect.Bounds.X, volumeRect.Bounds.Y + 5, volumeRect.Bounds.Width, volumeRect.Bounds.Height); } lock (ircLock) { if (ircl != null) { while (ircl.recieved.Count > 0) { Client.irc.IrcMessage msg = ircl.recieved.Dequeue(); string now = DateTime.Now.Hour.ToString("D2") + ":" + DateTime.Now.Minute.ToString("D2") + " "; if (msg.HLed) { if (!pbox.expanded) { addToast("You have received a highlight, press F2 to open chat"); } pbox.addLine((msg.timestamp ? now : "") + msg.Msg, Color.Green, msg.Target); if (Config.ChatSounds) { Skin.ChatSound.play(true); } if (pbox.tabs.ContainsKey(" " + msg.Target + " ")) { pbox.tabs[msg.Target].Alert = true; } if (!pbox.tabs.ContainsKey("#highlight")) { pbox.addTab("#highlight"); } pbox.addLine((msg.timestamp ? now : "") + "(" + msg.Target + ") " + msg.Msg, col, "#highlight"); pbox.tabs["#highlight"].Alert = true; } else { if (msg.Target.Equals(ircl.realNick) && !game.Focused && Config.ChatSounds) { if (!pbox.expanded) { addToast("You have recieved a private message, press F2 to open chat"); } Skin.ChatSound.play(true); } if (msg.customColor) { pbox.addLine((msg.timestamp ? now : "") + msg.Msg, msg.col, msg.Target); } else { string toadd = (msg.timestamp ? now : "") + msg.Msg; if (!string.IsNullOrEmpty(msg.sender)) { Dictionary <Pair <int, int>, Color> colors = new Dictionary <Pair <int, int>, Color>(); int index = toadd.IndexOf(msg.sender); colors.Add(new Pair <int, int>(0, index), col); colors.Add(new Pair <int, int>(index, index + msg.sender.Length), msg.sendercolor); colors.Add(new Pair <int, int>(index + msg.sender.Length, toadd.Length), col); pbox.addLine(toadd, colors, msg.Target); } else { /* if (msg.Msg.Length > 115) * { * Dictionary<Pair<int, int>, Color> colors = new Dictionary<Pair<int, int>, Color>(); * colors.Add(new Pair<int, int>(0, 100), Color.White); * colors.Add(new Pair<int, int>(100, 110), Color.Blue); * colors.Add(new Pair<int, int>(110, msg.Msg.Length), Color.White); * pbox.addLine(toadd, colors, msg.Target); * } * else * {*/ pbox.addLine(toadd, col, msg.Target); //} } } if (pbox.activeTab.Title != msg.Target && pbox.tabs.ContainsKey(msg.Target)) { pbox.tabs[msg.Target].Alert = true; } } } } } if (!Config.DisableMousewheel) { float nowMouse = Mouse.WheelPrecise; float delta = nowMouse - previousMouse; if (delta != 0) { previousMouse = nowMouse; if (Active != screens["selectScreen"] && active != screens["editScreen"] && !pbox.expanded) { delta *= 15; int result = volumeRect.Bounds.Width + (int)delta; if (result < 0) { result = 0; } else if (result > 370) { result = 370; } volumeRect.Bounds = new Rectangle(volumeRect.Bounds.X, volumeRect.Bounds.Y, result, volumeRect.Bounds.Height); int percent = (int)((result / 370d) * 100); Config.Volume = percent; volumeLife = 1000; } } } if (active != null && active.Enabled) { active.OnUpdateFrame(e); } if (screenChange && !transIn) { screenChange = false; active.Hide(); if (active.Music != null && !(tempScreen is MenuScreen)) { active.Music.stop(); } Active = tempScreen; tempScreen = null; active.Show(); } if (transitioning) { if (transIn) { blackOverlay.Alpha += 0.1f; if (blackOverlay.Alpha >= 1f) { transIn = false; } } else { blackOverlay.Alpha -= 0.1f; if (blackOverlay.Alpha <= 0f) { transitioning = false; transIn = true; } } } if (m.Enabled) { m.onUpdateFrame(e); } lClickFrame = false; }
IrcMessage processMessage(string input) { string[] splitted = input.Split(' '); if (splitted[1].Equals("PRIVMSG")) { string temp = input.Substring(splitted[0].Length + 1 + splitted[1].Length + 1 + splitted[2].Length + 1).Substring(1); //get rid of first ':' and return rest of text string nick = splitted[0].Substring(1).Split('!')[0]; //get rid of ':' and split to get actual nick string target = splitted[2]; if (splitted[2].Equals(NICK)) //private message { //nick += "|pm"; target = nick; } /* else if (splitted[2] != CHANNEL) //splitted 2 is the channel { return ""; }*/ char soh = (char)1; string tosend = "<" + nick + "> " + temp; bool isme = false; if (temp[0] == soh) // /me message, soh is start of header or something { string temp2 = temp.Substring(temp.IndexOf("ACTION") + 6); tosend = "*" + nick + temp2.Remove(temp2.Length - 1); isme = true; } IrcMessage msg = new IrcMessage(target, tosend); msg.sender = !isme? "<" + nick + ">" : "*"+nick; msg.sendercolor = System.Drawing.Color.SteelBlue; if (users.ContainsKey(nick)) { if (users[nick].ContainsKey(target)) { if (users[nick][target] > UserLevel.VOICE) { msg.sendercolor = System.Drawing.Color.Orange; } } } msg.timestamp = true; foreach (string s in HL) { if (temp.ToLower(Config.cultureEnglish).Contains(s.ToLower(Config.cultureEnglish))) { msg.HLed = true; // Game.game. //IntPtr hw = Game.game.getHandle(); //Console.WriteLine(hw.ToString()); // Console.WriteLine(FlashWindow.Flash(Game.game.getHandle())); //FlashWindow.Flash() } } if (temp.ToLower(Config.cultureEnglish).Contains(NICK.ToLower(Config.cultureEnglish))) { msg.HLed = true; } return msg; } else if (splitted[1].Equals("353")) { parseUsers(splitted[4], input); /*string[] s2 = input.Split(':'); s2 = s2[2].Split(' '); string n; string r; for (int x = 1; x < s2.Length - 1; x++) { r = ""; if (!char.IsLetter(s2[x][0])) { n = s2[x].Substring(1); r = "" + s2[x][0]; } else { n = s2[x]; } IrcUser temp = new IrcUser() { name = n, channel = splitted[4], role = r }; //users.Add(temp); }*/ } else if (splitted[1].Equals("433")) //nick in use, sent if next nick change fails so random is safe { Console.WriteLine("this had 433 " + input); if (hbs) { Console.WriteLine("now attempting to ghost"); writer.WriteLine("NICK " + (this.NICK + new Random().Next())); sendPm("nickserv", "ghost " + this.NICK + " " + this.NICK + Config.SongLibraryHash); } writer.WriteLine("NICK " + this.NICK); sendPm("nickserv", "identify " + this.NICK + Config.SongLibraryHash); writer.WriteLine("JOIN " + CHANNEL); } else if (splitted[0].Equals("PING")) { writer.WriteLine("PONG " + splitted[1]); } else if (splitted[1] == "319") //whois channel list { string user = splitted[3]; string noinit = input.Substring(1); string text = noinit.Substring(noinit.IndexOf(':') + 1); string[] channels = text.Split(' '); foreach (string s in from i in channels where !string.IsNullOrWhiteSpace(i) select i) { UserLevel toAdd = UserLevel.NORMAL; switch (s[0]) { case '+': toAdd = UserLevel.VOICE; break; case '%': toAdd = UserLevel.HOP; break; case '@': toAdd = UserLevel.OP; break; case '~': toAdd = UserLevel.OWNER; break; case '&': toAdd = UserLevel.ADMIN; break; } string channame = s; if (toAdd != UserLevel.NORMAL) { channame = channame.Substring(1); //getrid of symbol if special status if (users.ContainsKey(user)) { if (users[user].ContainsKey(channame)) { users[user][channame] = toAdd; } else { users[user].Add(channame, toAdd); } } else { users.Add(user, new Dictionary<string, UserLevel>()); users[user].Add(channame, toAdd); } } else { if (users.ContainsKey(user)) { if (users[user].ContainsKey(channame)) { users[user].Remove(channame); if (users[user].Count == 0) { users.Remove(user); } } } } } } else if (splitted.Length > 4 && splitted[1] == "MODE") { writer.WriteLine("WHOIS " + splitted[4]); } else if (splitted[1].Equals("JOIN")) { string channelname = splitted[2].Substring(1); string nick = splitted[0].Substring(1).Split('!')[0]; //get rid of ':' and split to get actual nick if (!nick.Equals(NICK)) //only respond if is the current nick, otherwise is someone else joining { if (channelname == CHANNEL && nick.StartsWith("pulse|") && !pulseUsers.Contains(nick)) { pulseUsers.Add(nick); } return new IrcMessage(UI.PTextBox.baseChannel, input); } else { return new IrcMessage(channelname, "Now talking on " + channelname + "!"); } /* if (!Game.pbox.tabs.ContainsKey(channelname)) //GLcontexts, doesn't work { Game.pbox.addTab(channelname); Game.pbox.addLine("Now talking on " + channelname + "!", System.Drawing.Color.SteelBlue, channelname); }*/ } else if (splitted[1].Equals("PART")) { string channelname = splitted[2]; string nick = splitted[0].Substring(1).Split('!')[0]; //get rid of ':' and split to get actual nick if (!nick.Equals(NICK)) { if (channelname == CHANNEL && nick.StartsWith("pulse|") && pulseUsers.Contains(nick)) { pulseUsers.Remove(nick); lock (User.users) User.users.Remove(nick.Split('|')[1].ToLower()); } } } else if (splitted[1].Equals("QUIT")) { string nick = splitted[0].Substring(1).Split('!')[0]; //get rid of ':' and split to get actual nick if (nick.StartsWith("pulse|") && pulseUsers.Contains(nick)) { pulseUsers.Remove(nick); lock (User.users) User.users.Remove(nick.Split('|')[1].ToLower()); } } else if (splitted[1].Equals("KICK")) { if (splitted[3].Equals(NICK)) { string channel = splitted[2]; if (Game.pbox.tabs.ContainsKey(channel)) { Game.pbox.closeTab(channel); } IrcMessage msg = new IrcMessage(UI.PTextBox.baseChannel, "You have been kicked from " + channel); msg.customColor = true; msg.col = System.Drawing.Color.Red; return msg; } else { string nick = splitted[3]; if (nick.StartsWith("pulse|")) { pulseUsers.Remove(nick); lock (User.users) User.users.Remove(nick.Split('|')[1].ToLower()); } } } else { if (Game.pbox.ircverbose && !isMOTD(input)) { return new IrcMessage(UI.PTextBox.baseChannel, input); } // meh flood } return null; }
IrcMessage processMessage(string input) { string[] splitted = input.Split(' '); if (splitted[1].Equals("PRIVMSG")) { string temp = input.Substring(splitted[0].Length + 1 + splitted[1].Length + 1 + splitted[2].Length + 1).Substring(1); //get rid of first ':' and return rest of text string nick = splitted[0].Substring(1).Split('!')[0]; //get rid of ':' and split to get actual nick string target = splitted[2]; if (splitted[2].Equals(NICK)) //private message { //nick += "|pm"; target = nick; } /* * else if (splitted[2] != CHANNEL) //splitted 2 is the channel * { * return ""; * }*/ char soh = (char)1; string tosend = "<" + nick + "> " + temp; bool isme = false; if (temp[0] == soh) // /me message, soh is start of header or something { string temp2 = temp.Substring(temp.IndexOf("ACTION") + 6); tosend = "*" + nick + temp2.Remove(temp2.Length - 1); isme = true; } IrcMessage msg = new IrcMessage(target, tosend); msg.sender = !isme? "<" + nick + ">" : "*" + nick; msg.sendercolor = System.Drawing.Color.SteelBlue; if (users.ContainsKey(nick)) { if (users[nick].ContainsKey(target)) { if (users[nick][target] > UserLevel.VOICE) { msg.sendercolor = System.Drawing.Color.Orange; } } } msg.timestamp = true; foreach (string s in HL) { if (temp.ToLower(Config.cultureEnglish).Contains(s.ToLower(Config.cultureEnglish))) { msg.HLed = true; // Game.game. //IntPtr hw = Game.game.getHandle(); //Console.WriteLine(hw.ToString()); // Console.WriteLine(FlashWindow.Flash(Game.game.getHandle())); //FlashWindow.Flash() } } if (temp.ToLower(Config.cultureEnglish).Contains(NICK.ToLower(Config.cultureEnglish))) { msg.HLed = true; } return(msg); } else if (splitted[1].Equals("353")) { parseUsers(splitted[4], input); /*string[] s2 = input.Split(':'); * s2 = s2[2].Split(' '); * string n; * string r; * for (int x = 1; x < s2.Length - 1; x++) * { * r = ""; * if (!char.IsLetter(s2[x][0])) * { * n = s2[x].Substring(1); * r = "" + s2[x][0]; * } * else * { * n = s2[x]; * } * IrcUser temp = new IrcUser() * { * name = n, * channel = splitted[4], * role = r * }; * //users.Add(temp); * }*/ } else if (splitted[1].Equals("433")) //nick in use, sent if next nick change fails so random is safe { Console.WriteLine("this had 433 " + input); if (hbs) { Console.WriteLine("now attempting to ghost"); writer.WriteLine("NICK " + (this.NICK + new Random().Next())); sendPm("nickserv", "ghost " + this.NICK + " " + this.NICK + Config.SongLibraryHash); } writer.WriteLine("NICK " + this.NICK); sendPm("nickserv", "identify " + this.NICK + Config.SongLibraryHash); writer.WriteLine("JOIN " + CHANNEL); } else if (splitted[0].Equals("PING")) { writer.WriteLine("PONG " + splitted[1]); } else if (splitted[1] == "319") //whois channel list { string user = splitted[3]; string noinit = input.Substring(1); string text = noinit.Substring(noinit.IndexOf(':') + 1); string[] channels = text.Split(' '); foreach (string s in from i in channels where !string.IsNullOrWhiteSpace(i) select i) { UserLevel toAdd = UserLevel.NORMAL; switch (s[0]) { case '+': toAdd = UserLevel.VOICE; break; case '%': toAdd = UserLevel.HOP; break; case '@': toAdd = UserLevel.OP; break; case '~': toAdd = UserLevel.OWNER; break; case '&': toAdd = UserLevel.ADMIN; break; } string channame = s; if (toAdd != UserLevel.NORMAL) { channame = channame.Substring(1); //getrid of symbol if special status if (users.ContainsKey(user)) { if (users[user].ContainsKey(channame)) { users[user][channame] = toAdd; } else { users[user].Add(channame, toAdd); } } else { users.Add(user, new Dictionary <string, UserLevel>()); users[user].Add(channame, toAdd); } } else { if (users.ContainsKey(user)) { if (users[user].ContainsKey(channame)) { users[user].Remove(channame); if (users[user].Count == 0) { users.Remove(user); } } } } } } else if (splitted.Length > 4 && splitted[1] == "MODE") { writer.WriteLine("WHOIS " + splitted[4]); } else if (splitted[1].Equals("JOIN")) { string channelname = splitted[2].Substring(1); string nick = splitted[0].Substring(1).Split('!')[0]; //get rid of ':' and split to get actual nick if (!nick.Equals(NICK)) //only respond if is the current nick, otherwise is someone else joining { if (channelname == CHANNEL && nick.StartsWith("pulse|") && !pulseUsers.Contains(nick)) { pulseUsers.Add(nick); } return(new IrcMessage(UI.PTextBox.baseChannel, input)); } else { return(new IrcMessage(channelname, "Now talking on " + channelname + "!")); } /* if (!Game.pbox.tabs.ContainsKey(channelname)) //GLcontexts, doesn't work * { * Game.pbox.addTab(channelname); * Game.pbox.addLine("Now talking on " + channelname + "!", System.Drawing.Color.SteelBlue, channelname); * }*/ } else if (splitted[1].Equals("PART")) { string channelname = splitted[2]; string nick = splitted[0].Substring(1).Split('!')[0]; //get rid of ':' and split to get actual nick if (!nick.Equals(NICK)) { if (channelname == CHANNEL && nick.StartsWith("pulse|") && pulseUsers.Contains(nick)) { pulseUsers.Remove(nick); lock (User.users) User.users.Remove(nick.Split('|')[1].ToLower()); } } } else if (splitted[1].Equals("QUIT")) { string nick = splitted[0].Substring(1).Split('!')[0]; //get rid of ':' and split to get actual nick if (nick.StartsWith("pulse|") && pulseUsers.Contains(nick)) { pulseUsers.Remove(nick); lock (User.users) User.users.Remove(nick.Split('|')[1].ToLower()); } } else if (splitted[1].Equals("KICK")) { if (splitted[3].Equals(NICK)) { string channel = splitted[2]; if (Game.pbox.tabs.ContainsKey(channel)) { Game.pbox.closeTab(channel); } IrcMessage msg = new IrcMessage(UI.PTextBox.baseChannel, "You have been kicked from " + channel); msg.customColor = true; msg.col = System.Drawing.Color.Red; return(msg); } else { string nick = splitted[3]; if (nick.StartsWith("pulse|")) { pulseUsers.Remove(nick); lock (User.users) User.users.Remove(nick.Split('|')[1].ToLower()); } } } else { if (Game.pbox.ircverbose && !isMOTD(input)) { return(new IrcMessage(UI.PTextBox.baseChannel, input)); } // meh flood } return(null); }