public static bool ReloadFilters(User u)
            {
                if (u.IsAdmin)
                {
                    try
                    {
                        // Website Blacklist
                        string blacklistPath = @"blacklist.txt";
                        if (!File.Exists(blacklistPath)) using (File.Create(blacklistPath)) { };

                        using (StreamReader sr = new StreamReader(blacklistPath))
                        {
                            string s = null;
                            while (null != (s = sr.ReadLine())) WebsiteFilters.Add(new WebsiteFilter(s, WebsiteFilter.FilterType.BLACKLIST));
                        }

                        // Website Blacklist
                        string whitelistPath = @"whitelist.txt";
                        if (!File.Exists(whitelistPath)) using (File.Create(whitelistPath)) { };
                        using (StreamReader sr = new StreamReader(whitelistPath))
                        {
                            string s = null;
                            while (null != (s = sr.ReadLine())) WebsiteFilters.Add(new WebsiteFilter(s, WebsiteFilter.FilterType.WHITELIST));
                        }
                    }
                    catch (System.IO.IOException e)
                    {
                        ExitWithError(e, "blacklist/whitelist");
                        return false;
                    }
                }
                return true;
            }
 public static bool SetGoal(User u, string msg) {
     /*if (u.IsAdmin)
     {
         _logform.SetAdminGoal(u, msg);
         return true;
     }*/ // Disable mod permission to bypass set goal restriction
     return _logform.SetGoal(u, msg); 
 }
 public static bool ClearGoal(User u) {
     string msg = "[EXPLETIVE DELETED]";
     if (u.IsAdmin)
     {
         _logform.ClearAdminGoal(u, msg);
         return true;
     }
     lock (Users.ClearGoal)
     {
         if (!Users.ClearGoal.Contains(u)) Users.ClearGoal.Add(u);
     }
     return _logform.ClearGoal(new User("Majority vote"), msg); 
 }
 public static void SetLiveMode(User u, bool live)
 {
     if (u.IsAdmin)
     {
         if (live)
         {
             GameMode = User.ModeType.ANARCHY;
             SendIRCNotice("Twippy wants anarchy!");
         }
         else {
             GameMode = User.ModeType.DEMOCRACY;
             SendIRCNotice("Twippy wants TwitchPlays.");
         }  
     }
 }
 public bool SetGoal(User u, string msg)
 {
     if (_canSetGoal)
     {
         SetAdminGoal(u, msg);
         return true;
     }
     return false;
 }
 public static bool SaveState(User u)
 {
     if (u.IsAdmin)
     {
         // TODO
         //SendIRCNotice("The goal is: " + _logform.Goal);
         return true;
     }
     return false;
 }
 public static bool BlameGoal(User u)
 {
     if (u.IsAdmin)
     {
         SendIRCNotice(_logform.GoalSetter + " last touched the goal.");
         return true;
     }
     return false;
 }
 public static bool SetAprilFools(User u)
 {
     if (u.IsAdmin && !Program.IsAprilFools)
     {
         Program.IsAprilFools = true;
         april_fools();
         return true;
     }
     return false;
 }
 public static bool SetQuietMode(User u)
 {
     if (u.IsAdmin)
     {
         Program.ProductionMode = false;
         return true;
     }
     return false;
 }
 public static bool GetUptime(User u)
 {
     if (u.IsAdmin)
     {
         SendIRCNotice("Last restart was " + (DateTime.Now - _executionTime).ToString(@"d'd 'h'h 'm'm 's's'") + " ago.");
         return true;
     }
     return false;
 }
        public void ClearAdminGoal(User u, string msg)
        {
            lock (Users.ClearGoal)
            {
                Users.ClearGoal.Clear();
            }

            if (this.InvokeRequired) // TODO macro this
            {
                this.Invoke(new Action(
                    () =>
                    {
                        lblGoal.Text = msg;
                    }
                    )
                );
            }
            else if (Program.IsMainThread)
            {
                lblGoal.Text = msg;
            }

            GoalSetter = u.Name;
            Program.SendIRCNotice(GoalSetter + " has cleared the goal.");

            if (goal_thread != null && goal_thread.IsAlive)
            {
                goal_thread.Interrupt();
                goal_thread = new Thread(() => ResetGoal(1));
                goal_thread.Start();
            }
        }
 public void SetAdminGoal(User u, string msg)
 {
     if (_canSetGoal)
     {
         _canSetGoal = false;
         goal_thread = new Thread(() => ResetGoal(5));
         goal_thread.Start();
     }
     if (this.InvokeRequired) // TODO macro this
     {
         this.Invoke(new Action(
            () =>
            {
                lblGoal.Text = msg;
            }
            )
        );
     }
     else if (Program.IsMainThread)
     {
         lblGoal.Text = msg;
     }
     GoalSetter = u.Name;
     Program.SendIRCNotice(GoalSetter + " has set the goal to: '" + msg + "'");
 }
 private static void BanUser(User u, bool timeout, string reason)
 {
     if (!u.IsAdmin)
     {
         if (timeout)
         {
             SendIRCMessage(".timeout " + u.Name);
             Thread.Sleep(1000);
             SendIRCMessage("/timeout " + u.Name);
             Log("[BAN] Put " + u.Name + " in timeout for " + reason);
         }
         else
         {
             SendIRCMessage(".ban " + u.Name);
             Thread.Sleep(1000);
             SendIRCMessage("/ban " + u.Name);
             Log("[BAN] Banned " + u.Name + " for " + reason);
         }
     }
     else Log("[BAN] Cannot ban admin or mod " + u.Name + " for " + reason);
 }
 public static bool GetGoal(User u)
 {
     if (u.IsAdmin)
     {
         SendIRCNotice("The goal is: " + _logform.Goal);
         return true;
     }
     else
     {
         if ((DateTime.Now - _lastGoal).TotalMinutes >= 1)
         {
             SendIRCNotice("The goal is: " + _logform.Goal);
             _lastGoal = DateTime.Now;
             return true;
         }
     }
     return false;
 }
        public static void ConnectIRC(LogForm _form) {
            if (_form != null) _logform = _form;

            if (Thread.CurrentThread.Name == null)
            {
                Thread.CurrentThread.Name = "IRC Thread";

                irc.Encoding = System.Text.Encoding.UTF8;
                irc.SendDelay = 200;
                irc.ActiveChannelSyncing = true;
                irc.AutoRetry = true;

                //irc.OnQueryMessage += new IrcEventHandler(OnQueryMessage);
                irc.OnError += new Meebey.SmartIrc4net.ErrorEventHandler(OnError);
                //irc.OnPong += new PongEventHandler(DetermineMode);
                irc.OnJoin += new JoinEventHandler(OnJoin);
                irc.OnPart += new PartEventHandler(OnPart);
                irc.OnOp += new OpEventHandler(OnOp);
                irc.OnDeop += new DeopEventHandler(OnDeop);
                irc.OnNames += new NamesEventHandler(OnNames);
                //irc.OnRawMessage += new IrcEventHandler(OnRawMessage);
                irc.OnChannelMessage += new IrcEventHandler(OnChannelMessage);
                irc.OnConnected += new EventHandler(OnConnected);
                irc.OnDisconnected += new EventHandler(OnDisconnected);

                //if (GameMode == User.ModeType.NONE) GameMode = User.ModeType.ANARCHY;

                // KeyMap
                keyMap.Add("HOLD", KeyType.HOLD);
                keyMap.Add("STAY", KeyType.HOLD);
                keyMap.Add("STOP", KeyType.HOLD);
                keyMap.Add("START", KeyType.START);
                keyMap.Add("SELECT", KeyType.SELECT);
                keyMap.Add("UP", KeyType.UP);
                keyMap.Add("NORTH", KeyType.UP);
                keyMap.Add("DOWN", KeyType.DOWN);
                keyMap.Add("SOUTH", KeyType.DOWN);
                keyMap.Add("LEFT", KeyType.LEFT);
                keyMap.Add("WEST", KeyType.LEFT);
                keyMap.Add("RIGHT", KeyType.RIGHT);
                keyMap.Add("EAST", KeyType.RIGHT);
                keyMap.Add("A", KeyType.A);
                keyMap.Add("B", KeyType.B);

                User u = new User("Command-line Argument");
                u.IsAdmin = true;
                ModFunctions.ReloadFilters(u);
            }

            // Connect
            if (username == null || password == null) ExitWithMsg("Username or password has not been set!");

            string[] serverlist;
            serverlist = new string[] { server };
            
            try
            {
                irc.Connect(serverlist, port);
            }
            catch (Exception e)
            {
                //ExitWithError(e, "Couldn't connect.");
            }
        }
 private void btnSetAdminGoal_Click(object sender, EventArgs e)
 {
     User u = new User("ADMIN CONSOLE");
     SetAdminGoal(u, txtAdminGoal.Text);
 }
 public bool ClearGoal(User u, string msg)
 {
     if (!_canSetGoal)
     {
         int _cleargoal_count = 0;
         lock (Users.ClearGoal) {
             _cleargoal_count = Users.ClearGoal.Count;
         }
         int _usersactive_count = 0;
         lock (Users.All)
         {
             _usersactive_count = Users.All.Count;
         }
         if (_cleargoal_count * 2 > _usersactive_count)
         {
             ClearAdminGoal(u, msg);
             return true;
         }
     }
     return false;
 }
 public static bool ReloadGame(User u) {
     if (u.IsAdmin)
     {
         _logform.ReloadGame();
         return true;
     }
     return false;
 }
 public static bool SaveGame(User u)
 {
     if (u.IsAdmin)
     {
         _logform.SaveGame();
         return true;
     }
     return false;
 }
 public static User CreateUser(string name, bool admin)
 {
     lock (Users.All)
     {
         User u = Users.All.Find(x => x.Name.Equals(name.ToLower()));
         if (u == null)
         {
             u = new User(name.ToLower());
             u.IsAdmin = admin;
             Users.All.Add(u);
             return u;
         }
         u.IsAdmin = admin;
         return u;
     }
 }
 public void OnGameMode(User.ModeType mode)
 {
     if (this.InvokeRequired) // TODO macro this
     {
         this.Invoke(new Action(
                 () =>
                 {
                     switch (mode)
                     {
                         case User.ModeType.ANARCHY:
                             {
                                 lblVoteResult.Text = "ANARCHY";
                                 lblVoteResult.ForeColor = Color.Crimson;
                                 lblVoteResult.Location = new Point(7, 138);
                                 chatBox.Location = new Point(11, 158);
                                 chatBox.Size = new Size(306, 308);
                                 pbModeForeground.Image = global::TwitchPlays.Properties.Resources.alert32; // left-facing sprite
                                 chatBox.Items.Clear();
                                 Program.TallyTime = DateTime.Now;
                             }
                             break;
                         case User.ModeType.DEMOCRACY:
                             {
                                 lblVoteResult.Text = "DEMOCRACY";
                                 lblVoteResult.ForeColor = Color.DodgerBlue;
                                 lblVoteResult.Location = new Point(7, 179);
                                 chatBox.Location = new Point(11, 256);
                                 chatBox.Size = new Size(306, 210);
                                 pbModeForeground.Image = global::TwitchPlays.Properties.Resources.alert32; // right-facing sprite
                                 chatBox.Items.Clear();
                             }
                             break;
                     }
                 })
             );
     }
     else if (Program.IsMainThread)
     {
         switch (mode)
         {
             case User.ModeType.ANARCHY:
                 {
                     lblVoteResult.Text = "ANARCHY";
                     lblVoteResult.ForeColor = Color.Crimson;
                     lblVoteResult.Location = new Point(7, 138);
                     chatBox.Location = new Point(11, 158);
                     chatBox.Size = new Size(306, 308);
                     pbModeForeground.Image = global::TwitchPlays.Properties.Resources.alert32; // left-facing sprite
                     chatBox.Items.Clear();
                     Program.TallyTime = DateTime.Now;
                 }
                 break;
             case User.ModeType.DEMOCRACY:
                 {
                     lblVoteResult.Text = "DEMOCRACY";
                     lblVoteResult.ForeColor = Color.DodgerBlue;
                     lblVoteResult.Location = new Point(7, 179);
                     chatBox.Location = new Point(11, 256);
                     chatBox.Size = new Size(306, 210);
                     pbModeForeground.Image = global::TwitchPlays.Properties.Resources.alert32; // right-facing sprite
                     chatBox.Items.Clear();
                 }
                 break;
         }
     }
 }