private bool HandleCommand(string part, ChatWindow selectedTab) { var cmd = part.Substring(1).ToLower(); switch(cmd) { case "me": if (selectedTab == null) { WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "No channel Selected.")); return false; } var isTeam = selectedTab.Name == MessageType.Team.ToString(); Program.ChatServer.SendMessage(isTeam ? MessageType.Team : MessageType.Message, CommandType.Me, selectedTab.Name, ChatInput.Text.Substring(part.Length + 1)); break; case "join": JoinChannel(ChatInput.Text.Substring(part.Length).Trim()); break; case "leave": if (selectedTab == null) { return false; } if (selectedTab.isprivate) { ChannelTabs.TabPages.Remove(selectedTab); } else { LeaveChannel(selectedTab.Name); } break; case "users": WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "There's " + _userData.Count + " users online.")); break; case "ping": Program.ChatServer.PingRequest = DateTime.Now; Program.ChatServer.SendPacket("PING"); break; case "pinggame": Program.ServerConnection.pingrequest = DateTime.Now; Program.ServerConnection.SendPacket(ServerPackets.Ping); break; case "autoscroll": autoscroll = !autoscroll; WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, (autoscroll ? "AutoScroll Enabled." : "AutoScroll Disabled."))); break; case "help": WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "-- Basic Commands --")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/admin - Get admin list")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/users - Get user count")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/me - Displays Username + Message")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/join - Join a other channel")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/leave - Leave the current channel")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/autoscroll - Enable/Disable autoscroll")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/ping - Ping the chat server")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/pinggame - Ping the game server")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/help - Displays this list your reading now")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/uptime - Displays how long the server has been online")); if (Program.UserInfo.Rank != 0) { WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "-- Donator Commands --")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "[red][/red] [blue][/blue] [green][/green]- Color tags, wrap your text with them to change its color")); } if (Program.UserInfo.Rank > 0) { WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "-- Level 1 Commands --")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/kick username reason - Kick a user")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/msg - Send a server message")); } if (Program.UserInfo.Rank > 1) { WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "-- Level 2 Commands --")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/ban username reason - Ban a user")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/unban username - Unban a user")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/ip username - Get a users IP")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/banip ip - Ban a IP")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/unbanip ip - Unbans IP")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/getbanlist - Get ban list")); } if (Program.UserInfo.Rank == 99) { WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "-- Level 99 Commands --")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/op username level - Set a users level")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/addpoints amount of DevPoints - Give a user DevPoints")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/removepoints amount of DevPoints - Remove DevPoints from a user")); } if (Program.UserInfo.TeamRank >= 0 && Program.UserInfo.Team != string.Empty) { WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "-- Team Commands --")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/leaveteam - leave the team")); } if (Program.UserInfo.TeamRank >= 1) { WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "-- Team User Level 1 Commands --")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/teamadd username - add a user to the team")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/teamremove username - remove a user from the team")); } if (Program.UserInfo.TeamRank == 99) { WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "-- Team User Level 99 Commands --")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/teamdisband - disbands the team")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/teamop username level - promote user in the team")); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "/teamchangeleader username - change the leader of a team")); } break; case "teamdisband": if (MessageBox.Show("Are you sure?", "Confirm team disband", MessageBoxButtons.YesNo) == DialogResult.Yes) { Program.ChatServer.SendPacket("ADMIN||" + cmd.ToUpper() + "||" + ChatInput.Text.Substring(part.Length).Trim()); } break; case "admin": string admins = string.Join(", ", _userData.Where(x => x.Value.Rank > 0).Select(x => x.Key)); WriteMessage(new ChatMessage(MessageType.System, CommandType.None, null, "The following admins are online: " + admins + ".")); break; default: Program.ChatServer.SendPacket("ADMIN||" + cmd.ToUpper() + "||" + ChatInput.Text.Substring(part.Length).Trim()); break; } return true; }
public void WriteMessage(ChatMessage message) { if (InvokeRequired) { Invoke(new Action<ChatMessage>(WriteMessage), message); return; } if(message.From != null && IgnoreList.Items.Contains(message.From.Username)) { return; } ChatWindow window = null; if (message.Type == MessageType.Server || message.Type == MessageType.System) { window = (ChatWindow)ChannelTabs.SelectedTab; if (window == null) { window = new ChatWindow(message.Type.ToString(), true) { issystemtab = true}; ChannelTabs.TabPages.Add(window); } } else if (message.Type == MessageType.Join || message.Type == MessageType.Leave || message.Channel == null) { window = GetChatWindow(message.Channel) ?? (ChatWindow)ChannelTabs.SelectedTab; if (window == null) { window = new ChatWindow(message.Type.ToString(), true) { issystemtab = true }; ChannelTabs.TabPages.Add(window); } } else if (message.Type == MessageType.PrivateMessage && Program.Config.PmWindows) { if (_pmWindows.ContainsKey(message.Channel)) { _pmWindows[message.Channel].WriteMessage(message); } else { _pmWindows.Add(message.Channel, new PmWindow_frm(message.Channel, true, Program.ChatServer)); _pmWindows[message.Channel].WriteMessage(message); _pmWindows[message.Channel].Show(); _pmWindows[message.Channel].FormClosed += Chat_frm_FormClosed; } } else if (message.Type == MessageType.Team) { window = GetChatWindow(message.Type.ToString()); if (window == null) { window = new ChatWindow(message.Type.ToString(), message.Type == MessageType.PrivateMessage); ChannelTabs.TabPages.Add(window); } } window = window ?? GetChatWindow(message.Channel); if(window == null) { window = new ChatWindow(message.Channel, message.Type == MessageType.PrivateMessage); ChannelTabs.TabPages.Add(window); } window.WriteMessage(message, autoscroll); }