Exemple #1
0
        public override void OnUserSay(string nick, string message,
                                       int length, ref string[] args)
        {
            Channel channel  = p_manager.GetChannel();
            string  hostmask = channel.GetUserData(nick).hostmask;

            switch (args[0])
            {
            case "$join":
                if (hostmask != G.settings["owner_hostmask"])
                {
                    channel.Say(nick + ": who are you?");
                    return;
                }
                if (args[1] != "")
                {
                    E.Join(args[1]);
                }
                break;

            case "$part":
                if (hostmask != G.settings["owner_hostmask"])
                {
                    channel.Say(nick + ": who are you?");
                    return;
                }
                if (args[1] != "")
                {
                    E.Part(args[1]);
                }
                break;
            }
        }
Exemple #2
0
        public override void OnUserLeave(string nick)
        {
            Channel      channel = p_manager.GetChannel();
            LGameChannel game    = GetLChannel(channel.GetName());

            if (game == null || !game.RemovePlayer(nick))
            {
                return;                 // Player was not part of the round
            }
            if (game.players.Count < 3 && game.is_active)
            {
                lchans.Remove(game);
                game = null;
                GC.Collect();
                channel.Say("Game ended.");
                return;
            }
            if (game.is_active)
            {
                channel.Say(nick + " left the game. Next player: " + game.GetPlayer().nick);
                return;
            }
            channel.Say(nick + " left the game.");

            if (game.players.Count == 0)
            {
                lchans.Remove(game);
                game = null;
                GC.Collect();                 // Force calling LGPlayer::~LGPlayer
            }
        }
Exemple #3
0
        void Cmd_start(string nick, string message)
        {
            Channel      channel = p_manager.GetChannel();
            LGameChannel game    = GetLChannel(channel.GetName());

            if (game == null || game.GetPlayer(nick) == null)
            {
                E.Notice(nick, "You are not part of the game.");
                return;
            }

            if (game.is_active)
            {
                E.Notice(nick, "The game is already running.");
                return;
            }

            int total_players = game.players.Count;

            if (total_players < 3)
            {
                channel.Say(nick + ": At least 3 players are required to start the game.");
                return;
            }

            var cards = new List <string>();

            foreach (string card in CARD_TYPES)
            {
                int amount = (card == "Q") ? 3 : 4;
                while (amount > 0)
                {
                    cards.Add(card);
                    amount--;
                }
            }
            Utils.Shuffle(ref cards);

            foreach (string card in cards)
            {
                game.NextPlayer().cards.Add(card);
            }

            game.is_active = true;

            foreach (LGPlayer n in game.players)
            {
                E.Notice(n.nick, "Your cards: " + FormatCards(n.cards, true));
                Thread.Sleep(300);
            }
            game.CleanStack();

            channel.Say("Game started! Player " + game.GetPlayer().nick +
                        " can play the first card using \"$add <'main card'> <card nr.> [<card nr.> [<card nr.>]]\"" +
                        " (Card nr. from your hand)");

            CheckCards();
        }
Exemple #4
0
        public bool RemovePlayer(Channel channel, string nick)
        {
            UnoPlayer player = GetPlayer(nick);

            if (player == null)
            {
                return(false);
            }

            if (current_player == player.name)
            {
                TurnNext();
            }

            if (is_active && player.cards.Count == 0)
            {
                int score = 0;
                foreach (UnoPlayer up in players)
                {
                    if (up != player)
                    {
                        score += up.GetCardsValue();
                    }
                }

                string log = player.name + " finishes the game and gains "
                             + score + " points";
                if (CheckMode(UnoMode.RANKED))
                {
                    player.Win(players, initial_player_count);

                    foreach (UnoPlayer up in players)
                    {
                        m_settings.Set(up.name, up);
                    }

                    log += ". Elo: " + player.ShowElo(false);
                }
                channel.Say(log);
            }
            else
            {
                channel.Say(player.name + " left this UNO game.");
            }

            players.Remove(player);
            if (!is_active)
            {
                initial_player_count = players.Count;
            }
            return(true);
        }
Exemple #5
0
        void Cmd_update(string nick, string message)
        {
            Channel channel = p_manager.GetChannel();

            if (channel.GetUserData(nick).hostmask != G.settings["owner_hostmask"])
            {
                channel.Say(nick + ": Permission denied");
                return;
            }

            LoadGithubProjects();
            channel.Say(nick + ": Updated! Got in total " +
                        github_projects.Count + " Github projects to check.");
        }
Exemple #6
0
        void Cmd_EloTop(string nick, string message)
        {
            Channel channel = p_manager.GetChannel();

            var leaderboard = new Dictionary <string, int>();
            var dummy       = new UnoPlayer(null, null);

            foreach (string key in m_settings.IterateKeys())
            {
                if (!m_settings.Get(key, ref dummy))
                {
                    continue;
                }
                leaderboard.Add(key, dummy.GetElo());
            }
            int    n   = 0;
            string val = "";

            foreach (var record in leaderboard.OrderByDescending(i => i.Value))
            {
                if (n > 0)
                {
                    val += ", ";
                }

                val += record.Key + " (" + record.Value + ")";
                if (++n == 5)
                {
                    break;
                }
            }
            channel.Say("[UNO] Top 5 leaderboard: " + val);
        }
Exemple #7
0
        public override void OnUserSay(string nick, string message,
                                       int length, ref string[] args)
        {
            if (args[0] != "$" && args[0] != "$lua")
            {
                return;
            }

            if (lua_timer.IsRunning)
            {
                return;
            }

            string str = String.Join(" ", args, 1, length - 1);

            if (str.Length < 5)
            {
                E.Notice(nick, "Too short input text.");
                return;
            }
            lua_timer.Start();

            // Optional p_manager.Fork() because this
            // OnUserSay already runs within its own thread
            Channel channel = p_manager.GetChannel();

            channel.Say(LuaRun(nick, channel, str));
        }
Exemple #8
0
        void Cmd_Deal(string nick, string message)
        {
            Channel    channel = p_manager.GetChannel();
            UnoChannel uno     = GetUnoChannel(channel.GetName());
            UnoPlayer  nplayer = uno != null?uno.GetPlayer(nick) : null;

            if (nplayer == null || uno.is_active)
            {
                E.Notice(nick, "You are either not part of the game or " +
                         " another is already ongoing.");
                return;
            }

            if (uno.players.Count < 2)
            {
                channel.Say("At least two player are required to start the game.");
                return;
            }

            foreach (UnoPlayer player in uno.players)
            {
                player.DrawCards(11, 2);
            }

            uno.top_card  = nplayer.cards[0];
            uno.is_active = true;
            TellGameStatus(channel);
        }
Exemple #9
0
        void TellGameStatus(Channel channel, UnoPlayer player = null)
        {
            UnoChannel uno = GetUnoChannel(channel.GetName());

            if (uno == null)
            {
                return;
            }

            // No specific player. Take current one
            var current = uno.GetPlayer();

            if (player == null)
            {
                player = current;
            }

            var sb = new System.Text.StringBuilder();

            sb.Append("[UNO] " + uno.current_player);
            sb.Append(" (" + current.cards.Count + " cards) - ");
            sb.Append("Top card: " + FormatCards(new List <Card> {
                uno.top_card
            }));
            if (uno.draw_count > 0)
            {
                sb.Append("- draw count: " + uno.draw_count);
            }

            channel.Say(sb.ToString());

            E.Notice(player.name, "Your cards: " + FormatCards(player.cards));
        }
Exemple #10
0
        void Cmd_join(string nick, string message)
        {
            Channel      channel = p_manager.GetChannel();
            LGameChannel game    = GetLChannel(channel.GetName());

            if (game != null && game.is_active)
            {
                channel.Say(nick + ": Please wait for " + game.GetPlayer() +
                            " to finish their game.");
                return;
            }

            if (game != null && game.GetPlayer(nick) != null)
            {
                E.Notice(nick, "You already joined the game.");
                return;
            }

            if (game == null)
            {
                game = new LGameChannel(channel.GetName());
                lchans.Add(game);
            }

            UserData user = channel.GetUserData(nick);

            user.cmd_scope = m_subcommand;
            game.players.Add(new LGPlayer(nick, user));

            int    count = game.players.Count;
            string text  = "Player " + nick + " joined the game. Total " + count + " players ready.";

            if (count > 2)
            {
                text += " If you want to start the game, use \"$start\"";
            }
            else if (count == 1)
            {
                text += " At least 3 players are required to start the game.";
            }
            channel.Say(text);
        }
Exemple #11
0
        void Cmd_Join(string nick, string message)
        {
            Channel    channel = p_manager.GetChannel();
            UnoChannel uno     = GetUnoChannel(channel.GetName());

            if (uno != null && uno.is_active)
            {
                channel.Say(nick + ": Please wait for " + uno.current_player +
                            " to finish their game.");
                return;
            }

            if (uno != null && uno.GetPlayer(nick) != null)
            {
                E.Notice(nick, "You already joined the game.");
                return;
            }

            // Create a new UnoChannel
            if (uno == null)
            {
                string modes_s = Chatcommand.GetNext(ref message);

                byte modes = 0x03;
                try {
                    modes = Convert.ToByte(modes_s, 16);
                } catch { }
                uno = new UnoChannel(modes);
                m_channels[channel.GetName()] = uno;
            }

            UserData user = channel.GetUserData(nick);

            user.cmd_scope = m_subcommand;
            uno.players.Add(new UnoPlayer(nick, user));
            uno.current_player = nick;

            channel.Say("[UNO] " + uno.players.Count +
                        " player(s) are waiting for a new UNO game. " +
                        string.Format("Modes: 0x{0:X2}", uno.modes));
        }
Exemple #12
0
        void Cmd_Elo(string nick, string message)
        {
            Channel channel = p_manager.GetChannel();
            string  who     = Chatcommand.GetNext(ref message);

            if (who.Length == 0)
            {
                who = nick;
            }

            var player = new UnoPlayer(who, null);

            if (!m_settings.Get(who, ref player))
            {
                channel.Say("[UNO] " + who + ": No information available");
            }
            else
            {
                channel.Say("[UNO] " + who + ": " + player.ShowElo(true));
            }
        }
Exemple #13
0
        public bool RemovePlayer(Channel channel, string nick)
        {
            UnoPlayer player = GetPlayer(nick);

            if (player == null)
            {
                return(false);
            }

            if (current_player == player.name)
            {
                TurnNext();
            }

            if (is_active && player.cards.Count == 0)
            {
                int score = 0;
                foreach (UnoPlayer up in players)
                {
                    if (up != player)
                    {
                        score += up.GetCardsValue();
                    }
                }

                channel.Say(player.name + " finishes the game and gains " + score + " points");
            }
            else
            {
                channel.Say(player.name + " left this UNO game.");
            }

            players.Remove(player);
            player = null;             // So that GC works
            GC.Collect();
            return(true);
        }
Exemple #14
0
        void Cmd_cutwire(string nick, string message)
        {
            Channel chan    = p_manager.GetChannel();
            string  channel = chan.GetName();

            if (!m_timers.ContainsKey(channel))
            {
                chan.Say("There's no timebomb to disarm.");
                return;
            }
            var data = m_timers[channel];

            if (data.nick != nick)
            {
                chan.Say(nick + ": You may not help to disarm the bomb.");
                return;
            }

            int color_i = Array.IndexOf(colors, Chatcommand.GetNext(ref message));

            if (color_i < 0)
            {
                chan.Say(nick + ": Unknown or missing wire color.");
                return;
            }

            if (data.color != colors[color_i])
            {
                // Explode instantly
                BoomTimerElapsed(channel);
                return;
            }
            // Disarmed
            m_timers.Remove(channel);
            chan.Say(nick + ": You successfully disarmed the bomb.");
        }
Exemple #15
0
        public override void OnUserSay(string nick, string message,
                                       int length, ref string[] args)
        {
            if (args[0] != G.settings["prefix"] && args[0] != G.settings["prefix"] + "lua")
            {
                return;
            }

            if (lua_timer.IsRunning)
            {
                return;
            }

            string str = "";

            for (int i = 1; i < length; i++)
            {
                if (i + 1 < length)
                {
                    str += args[i] + ' ';
                }
                else
                {
                    str += args[i];
                }
            }
            if (str.Length < 5)
            {
                E.Notice(nick, "Too short input text.");
                return;
            }
            Channel channel = p_manager.GetChannel();

            lua_timer.Start();
            lua_thread = new Thread(delegate() {
                channel.Say(LuaRun(nick, channel, str));
            });
            lua_thread.Start();
        }
Exemple #16
0
        void Cmd_tell(string nick, string message)
        {
            Channel channel  = p_manager.GetChannel();
            string  dst_nick = Chatcommand.GetNext(ref message);

            if (dst_nick.Length < 3)
            {
                channel.Say(nick + ": Expected arguments: <nick> <text ..>");
                return;
            }

            if (message.Length < 7)
            {
                E.Notice(nick, "Too short input text.");
                return;
            }
            if (message.Length > byte.MaxValue - 5)
            {
                E.Notice(nick, "Too long input text.");
                return;
            }
            if (message == tell_last)
            {
                E.Notice(nick, "Text too repetitive.");
                return;
            }
            foreach (TellInfo info in tell_text)
            {
                if (info.text == message && CheckSimilar(info.dst_nick, dst_nick))
                {
                    E.Notice(nick, "That message is already in the queue.");
                    return;
                }
            }

            tell_last = message;

            var    in_channel  = new List <Channel>();
            string user_normal = null;

            foreach (Channel chan in p_manager.UnsafeGetChannels())
            {
                string found = chan.FindNickname(dst_nick);
                if (found != null)
                {
                    user_normal = found;
                    in_channel.Add(chan);
                }
            }

            if (in_channel.Count > 0)
            {
                foreach (Channel chan in in_channel)
                {
                    if (chan.GetUserData(nick) != null)
                    {
                        E.Notice(nick, "Found " + user_normal + " in channel " +
                                 chan.GetName() + $". No need to use {G.settings["prefix"]}tell.");
                        return;
                    }
                }
                in_channel[0].Say(user_normal + ": TELL from " + nick + ": " + message);
                E.Notice(nick, "Message directly sent to " + user_normal +
                         " in channel " + in_channel[0].GetName() + ".");
                return;
            }

            tell_text.Add(new TellInfo {
                dst_nick = dst_nick,
                src_nick = nick,
                datetime = DateTime.UtcNow.ToString("s"),
                text     = message
            });
            channel.Say(nick + ": meh okay. I'll look out for that user.");
            TellSave(true);
        }
Exemple #17
0
        void Cmd_check(string nick, string message)
        {
            Channel      channel = p_manager.GetChannel();
            LGameChannel game    = GetLChannel(channel.GetName());

            #region Sanity check
            if (game == null || !game.is_active)
            {
                E.Notice(nick, "There's no game or it did not start yet.");
                return;
            }

            LGPlayer player = game.GetPlayer(nick);
            if (player == null)
            {
                E.Notice(nick, "You are not part of the game.");
                return;
            }
            if (player != game.GetPlayer())
            {
                E.Notice(nick, "It's not your turn yet. Please wait for " +
                         game.GetPlayer().nick);
                return;
            }
            if (game.main_card == "")
            {
                E.Notice(nick, "You cannot check an empty stack.");
                return;
            }
            #endregion

            player = null;
            string main_card        = game.main_card;
            bool   contains_invalid = game.stack_top.FindIndex(item => item != main_card) >= 0;

            string card_msg = "";
            if (contains_invalid)
            {
                card_msg = "One or more top cards were not a [" + main_card + "]. ";
            }
            else
            {
                card_msg = "The top cards were correct! ";

                game.NextPlayer();
            }

            card_msg += "(" + FormatCards(game.stack_top) + ") ";

            // Add cards to previous player
            game.GetPlayer(-1).cards.AddRange(game.stack_all);
            game.CleanStack();
            CheckCards();

            // "channel" reference is not updated after deleting the channel!
            if (GetLChannel(channel.GetName()) == null)
            {
                channel.Say(card_msg);
                return;
            }

            var prev_player = game.GetPlayer(-1);
            var curr_player = game.GetPlayer(0);

            card_msg += "Complete stack goes to " + prev_player.nick + ". " +
                        curr_player.nick + " can start with an empty stack.";

            channel.Say(card_msg);
            E.Notice(prev_player.nick, FormatCards(prev_player.cards, true));
            E.Notice(curr_player.nick, FormatCards(curr_player.cards, true));
        }
Exemple #18
0
        void Cmd_timebomb(string nick, string message)
        {
            Channel chan = p_manager.GetChannel();

            if (chan.IsPrivate())
            {
                return;
            }

            string channel = chan.GetName();

            if (m_timers.ContainsKey(channel))
            {
                chan.Say("Only one timebomb is allowed at a time.");
                return;
            }
            if (m_cooldown.ContainsKey(channel))
            {
                chan.Say("Assembling a new bomb. Please wait... (" +
                         (int)(m_cooldown[channel].GetRemaining() / 1000.0) + "s)");
                return;
            }

            string dst_name = Chatcommand.GetNext(ref message);

            dst_name = chan.FindNickname(dst_name, false);
            if (dst_name == null)
            {
                chan.Say(nick + ": Unknown or invalid nickname specified.");
                return;
            }

            if (dst_name == G.settings["nickname"])
            {
                E.Notice(nick, "You fell for it, fool! Thunder Cross Split Attack!");
                dst_name = nick;
            }

            // Take a random amount from "colors"
            string[] choices    = new string[Utils.random.Next(2, 5)];
            string   choice_str = "";

            for (int i = 0; i < choices.Length; ++i)
            {
                choices[i] = (string)Utils.RandomIn(colors);
                // Format chat output
                choice_str += choices[i];
                if (i < choices.Length - 1)
                {
                    choice_str += ", ";
                }
            }
            string color = (string)Utils.RandomIn(choices);

            var data = new DisarmData(dst_name, color, Utils.random.Next(50, 90) * 1000.0);

            data.timer.Elapsed += delegate {
                BoomTimerElapsed(channel);
            };

            m_timers[channel] = data;
            chan.Say(dst_name + ": Tick tick.. " + (int)(data.timer.Interval / 1000.0) +
                     "s until explosion. Try $cutwire <color> from one of these colors: " + choice_str);
        }
Exemple #19
0
        void Cmd_add(string nick, string message)
        {
            Channel      channel = p_manager.GetChannel();
            LGameChannel game    = GetLChannel(channel.GetName());
            LGPlayer     player  = game != null?game.GetPlayer(nick) : null;

            #region Sanity check
            if (player == null || !game.is_active)
            {
                E.Notice(nick, "There's no game ongoing yet. Join & start to begin.");
                return;
            }

            if (player != game.GetPlayer())
            {
                E.Notice(nick, "It's not your turn yet. Please wait for " +
                         game.GetPlayer().nick);
                return;
            }
            #endregion

            string card       = Chatcommand.GetNext(ref message);
            string card_upper = card.ToUpper();
            string main_card  = game.main_card;

            // Check for valid card, correct name
            bool   valid_main_card = false;
            string cards           = "";
            for (int i = 0; i < CARD_TYPES.Length; i++)
            {
                string l_card = CARD_TYPES[i].ToUpper();
                if (l_card == card_upper)
                {
                    valid_main_card = true;
                    // Correct spelling
                    card = CARD_TYPES[i];
                    break;
                }
                if (l_card != "Q")
                {
                    cards += CARD_TYPES[i] + " ";
                }
            }

            // $lg <fake> <c1> <c2>
            if (main_card != "" && main_card != card)
            {
                channel.Say(nick + ": Wrong card type! Please pretend to place a card of type [" + main_card + "]!");
                return;
            }

            if (card_upper == "Q")
            {
                channel.Say(nick + ": The Queen is the bad card and can not be used as the main card of a stack.");
                return;
            }

            if (!valid_main_card)
            {
                channel.Say(nick + ": There is no such card type. Valid types: " + cards);
                return;
            }

            if (main_card == "")
            {
                main_card = card;
            }

            string[] card_mirror = player.cards.ToArray();

            var card_add = new List <int>();
            for (int n = 0; true; n++)
            {
                string index_s = Chatcommand.GetNext(ref message);
                if (index_s == "" && n == 0)
                {
                    channel.Say(nick + ": Expected arguments <'main card'> <index> [<index> ..]" +
                                "(Blue number: card value, Black number: index)");
                    return;
                }
                if (index_s == "")
                {
                    break;
                }

                int index_i = Utils.toInt(index_s) - 1;
                if (index_i < 0 || index_i >= card_mirror.Length)
                {
                    E.Notice(nick, "Invalid card index \"" + index_s + "\". Play one between 1 and " +
                             card_mirror.Length + " from your hand.");
                    return;
                }

                if (!card_add.Contains(index_i))
                {
                    card_add.Add(index_i);
                }
            }

            game.stack_top.Clear();
            foreach (int card_i in card_add)
            {
                string l_card = card_mirror[card_i];

                game.stack_all.Add(l_card);
                game.stack_top.Add(l_card);
                bool success = player.cards.Remove(l_card);
                if (!success)
                {
                    L.Log("m_lGame::$ladd, failed to remove cards", true);
                }
            }

            game.main_card = main_card;
            player         = game.NextPlayer();

            channel.Say("[LGame] Main card: [" + main_card + "]" +
                        ", Stack height: " + game.stack_all.Count +
                        ", Next player: " + player.nick);
            Thread.Sleep(300);
            E.Notice(player.nick, FormatCards(player.cards, true));

            CheckCards(nick);
        }
Exemple #20
0
        void Cmd_cutewire(string nick, string message)
        {
            Channel chan = p_manager.GetChannel();

            chan.Say(nick + ": Are you stupid or what? Try better next time.");
        }
Exemple #21
0
        void OnUserSay(string nick, string message)
        {
            #region CTCP
            string message_l = message.ToLower();
            if (message_l == "\x01version\x01")
            {
                Notice(nick, "\x01VERSION " + G.settings["identifier"] + "\0x01");
                L.Log("E::OnChatMessage, sending version to " + nick);
                return;
            }
            if (message_l == "\x01time\x01")
            {
                Notice(nick, "\x01TIME " + DateTime.UtcNow.ToString("s") + "\0x01");
                L.Log("E::OnChatMessage, sending time to " + nick);
                return;
            }
            #endregion

            Channel chan = manager.GetChannel();
            L.Log(chan.GetName() + "\t <" + nick + "> " + message);

            #region Args
            {
                string to_replace = G.settings["nickname"] + ": ";
                if (message.StartsWith(to_replace, StringComparison.OrdinalIgnoreCase))
                {
                    message = message.Substring(to_replace.Length).Trim();
                    if (message.Length > 0 && message[0] != '$')
                    {
                        message = '$' + message;
                    }
                }
            }

            string[] args   = Chatcommand.Split(message);
            int      length = args.Length;

            if (args.Length < 10)
            {
                Array.Resize(ref args, 10);
            }

            for (int i = length; i < args.Length; i++)
            {
                args[i] = "";
            }
            #endregion

            #region Handle NickServ + return
            if (nick == "NickServ" && length >= 3)
            {
                if (Utils.isYes(G.settings["nickserv_acc"]) == 1)
                {
                    if (args[1] == "ACC")
                    {
                        manager.ReceivedUserStatus(args[1], args[2][0] - '0');
                        return;
                    }
                }
                else
                {
                    if (args[0] == "STATUS")
                    {
                        manager.ReceivedUserStatus(args[1], args[2][0] - '0');
                        return;
                    }
                }
                // Add more here?

                return;
            }
            #endregion

            if (args[0] == ".bots")
            {
                chan.Say(G.settings["identifier"]);
                return;
            }

            if (message.Length < 2 || message[0] != '$')
            {
                return;
            }

            manager.Fork("E::OnUserSay", message, delegate() {
                manager.OnUserSay(nick, message, length, ref args);
            });
        }
Exemple #22
0
        void Cmd_Join(string nick, string message)
        {
            Channel    channel = p_manager.GetChannel();
            UnoChannel uno     = GetUnoChannel(channel.GetName());

            if (uno != null && uno.is_active)
            {
                channel.Say(nick + ": Please wait for " + uno.current_player +
                            " to finish their game.");
                return;
            }

            if (uno != null && uno.GetPlayer(nick) != null)
            {
                E.Notice(nick, "You already joined the game.");
                return;
            }

            // Create a new UnoChannel
            if (uno == null)
            {
                string modes_s = Chatcommand.GetNext(ref message);

                byte modes = 0x87;
                try {
                    modes = Convert.ToByte(modes_s, 16);
                } catch { }
                uno = new UnoChannel(modes, m_settings);
            }

            if (uno.CheckMode(UnoMode.RANKED) &&
                p_manager.GetUserStatus(nick) != 3)
            {
                E.Notice(nick, "You must be logged in to play ranked UNO.");
                return;
            }

            m_channels[channel.GetName()] = uno;             // For new channels

            UserData user = channel.GetUserData(nick);

            user.cmd_scope = m_subcommand;

            var player = new UnoPlayer(nick, user);

            m_settings.Get(nick, ref player);
            uno.AddPlayer(player);

            // Human readable modes
            var modes_list = new List <string>();

            for (int i = 1; i < byte.MaxValue; i <<= 1)
            {
                if ((uno.modes & i) > 0)
                {
                    modes_list.Add(FormatMode((UnoMode)(uno.modes & i)));
                }
            }

            channel.Say("[UNO] " + uno.players.Count +
                        " player(s) are waiting for a new UNO game. " +
                        string.Format("Modes: [0x{0:X2}] ", uno.modes) + string.Join(", ", modes_list));
        }
Exemple #23
0
        void OnUserSay(string nick, string message)
        {
            #region CTCP
            string message_l = message.ToLower();
            if (message_l == "\x01version\x01")
            {
                Notice(nick, "\x01VERSION " + G.settings["identifier"] + "\0x01");
                L.Log("E::OnChatMessage, sending version to " + nick);
                return;
            }
            if (message_l == "\x01time\x01")
            {
                Notice(nick, "\x01TIME " + DateTime.UtcNow.ToString("s") + "\0x01");
                L.Log("E::OnChatMessage, sending time to " + nick);
                return;
            }
            #endregion

            Channel chan = manager.GetChannel();
            L.Log(chan.GetName() + "\t <" + nick + "> " + message);

            #region Args
            {
                string to_replace = G.settings["nickname"] + ": ";
                if (message.StartsWith(to_replace, StringComparison.OrdinalIgnoreCase))
                {
                    message = message.Substring(to_replace.Length).Trim();
                    if (message.Length > 0 && !message.StartsWith(G.settings["prefix"]))
                    {
                        message = G.settings["prefix"] + message;
                    }
                }
            }

            string[] args   = Chatcommand.Split(message);
            int      length = args.Length;

            if (args.Length < 10)
            {
                Array.Resize(ref args, 10);
            }

            for (int i = length; i < args.Length; i++)
            {
                args[i] = "";
            }
            #endregion

            #region Handle NickServ + return
            if (nick == "NickServ" && length >= 3)
            {
                // NickServ can send different kinds of answers
                m_Lua module = (m_Lua)manager.GetModule("Lua");

                if (Utils.isYes(G.settings["nickserv_acc"]) == 1)
                {
                    if (args[1] == "ACC" && module != null)
                    {
                        module.userstatus_queue[args[0]] = args[2][0] - '0';
                        return;
                    }
                }
                else
                {
                    if (args[0] == "STATUS" && module != null)
                    {
                        module.userstatus_queue[args[1]] = args[2][0] - '0';
                        return;
                    }
                }
                // Add more here?

                return;
            }
            #endregion

            if (args[0] == ".bots")
            {
                chan.Say(G.settings["identifier"]);
                return;
            }

            if (message.Length < 2 || !message.StartsWith(G.settings["prefix"]))
            {
                return;
            }

            manager.OnUserSay(nick, message, length, ref args);
        }
Exemple #24
0
        void CheckCards(string nick = null)
        {
            Channel      chan = p_manager.GetChannel();
            LGameChannel game = GetLChannel(chan.GetName());

            if (game == null || !game.is_active)
            {
                return;
            }

            List <string> player_remove = new List <string>();

            foreach (LGPlayer player in game.players)
            {
                int amount = player.cards.Count;

                if (amount >= 4)
                {
                    // Count cards
                    var cards = new Dictionary <string, int>();
                    foreach (string card in player.cards)
                    {
                        if (cards.ContainsKey(card))
                        {
                            cards[card]++;
                        }
                        else
                        {
                            cards.Add(card, 1);
                        }
                    }

                    // Discard pairs
                    var discarded = new List <string>();
                    foreach (KeyValuePair <string, int> card in cards)
                    {
                        if (card.Value >= 4)
                        {
                            player.cards.RemoveAll(item => item == card.Key);
                            discarded.Add(card.Key);
                        }
                    }
                    if (discarded.Count > 0)
                    {
                        chan.Say(player.nick + " can discard four " + FormatCards(discarded) +
                                 " cards. Left cards: " + player.cards.Count);
                        Thread.Sleep(300);
                    }
                }

                if (amount == 0)
                {
                    if (nick == null || (nick != null && nick != player.nick))
                    {
                        chan.Say(player.nick + " has no cards left. Congratulations, you're a winner!");
                        player_remove.Add(player.nick);
                    }
                    else
                    {
                        chan.Say(player.nick + " played " + Utils.Colorize("their last card", IRC_Color.ORANGE) + "!");
                    }
                }
                else if (amount <= 3)
                {
                    if (nick != null && nick == player.nick)
                    {
                        chan.Say(player.nick + " has " +
                                 Utils.Colorize("only " + amount + " cards", IRC_Color.ORANGE) + " left!");
                    }
                }
            }

            foreach (string player in player_remove)
            {
                OnUserLeave(player);
            }
        }