Esempio n. 1
0
        static int Main(string[] args)
        {
            /*
             * - you bet the minimum *number of people who will survive through the next wave without dying
             * - the next wave will spawn the same amount of bosses than the *number bet
             * - if the bet is won, every player will earn a *number of random vices
             */
            /*
             * the events to catch are:
             * - player_connect:
             *     - Check if an instance of Player corresponding to the player exists
             *     - If not, create one and add it to connected_players
             *     - Otherwise, move the corresponding Player from disconnected_players to connected_players
             * - player_disconnect:
             *     - Set the Player as dead
             *     - Update the Bet (if one) with the Player
             *     - Move the Player from connected_players to disconnected_players
             * - player_spawn:
             *     - Set the Player as alive
             * - player_death:
             *     - Set the Player as dead
             *     - Update the Bet (if one) with the Player
             * - survival_get_vice:
             *     - Get profile and new vice
             *     - Search for the Player with the corresponding profile
             *     - Update its vices with the new vice
             * - survival_use_vice:
             *     - Get profile and vice used
             *     - Search for the Player with the corresponding profile
             *     - Update its vices with vice used
             * - survival_new_wave:
             *     - Stop checking for vote in chat for next Bet
             *     - Set Vote of all connected_players to NOTHING
             *     - Set Players in Bet with connected_players
             *     - Decide if next Bet is accepted or not depending on Vote of Players
             *     - If accepted, set is_bet_flag_unlocked to true
             *     - If not accepted, set is_bet_flag_unlocked to false and set next Bet to null
             *     - Check if current Bet is won
             *     - If yes, for each Player in connected_players:
             *         - Get the vices from Bet
             *         - Update the Player's vices
             *         - Send request to update the player's vices
             *     - Replace current Bet by next Bet
             * - survival_flag_unlocked:
             *     - Check is_bet_flag_unlocked
             *     - If true, for each enemies in Bet:
             *         - Send request to spawn the enemy
             * - chat_message:
             *     - Check if next Bet exists
             *     - If yes, check if !vote <yes/no> has been written:
             *         - Get profile from Player
             *         - For the Player in connected_players with the same profile, set its Vote
             *         - Check if Players in connected_players all have a Vote to either YES or NO
             *         - If yes, check if next Bet is valid:
             *             - Set Vote of all connected_players to NOTHING
             *             - Set Players in Bet with connected_players
             *             - If valid, set is_bet_flag_unlocked to true
             *             - If not valid, set is_bet_flag_unlocked to false and set next Bet to null
             *     - If no, create new next Bet with <number>
             */
            lib.ILogger logger = new lib.ConsoleLogger();
            logger.StartWriting();
            try
            {
                Betmode betmode = new Betmode();
                betmode.Start(logger);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.WriteLine("Something went wrong in the main.");
            }

            logger.StopWriting();

            // press 'Enter' to exit the console
            Console.Read();

            return(0);
        }
Esempio n. 2
0
        static int Main(string[] args)
        {
            lib.ILogger logger = new lib.ConsoleLogger();
            logger.StopWriting();
            try
            {
                /*
                 * Example on how to use the BM rcon lib
                 * The program reads from the chat.
                 * If in the chat is written "!bigtext Hello",
                 * it will call the "eventtext" command with "Hello" as string in red.
                 * If a player taunts, the program will stops.
                 */
                string body        = passwd;
                string bigtext_cmd = "!bigtext";
                // init rcon object with address, port and password
                lib.RCON_Client rcon_obj = new lib.RCON_Client(addr, port, body, logger);
                // connect the rcon client to addr:port with body
                rcon_obj.Connect();
                Console.WriteLine("");

                // enable mutators on server if not enabled
                // sendRequest(rcon_obj, RequestType.command, "enablemutators");

                lib.RCON_Event evt;
                while (true)
                {
                    // receive the latest event
                    evt = rcon_obj.ReceiveEvent();
                    Console.WriteLine("");

                    // check if somebody type something in the chat
                    if (evt.EventID == (short)lib.EventType.chat_message)
                    {
                        // get the message
                        String msg = evt.JsonAsObj.Message.ToString();

                        // check if "!bigtext" is in the message
                        int index = msg.IndexOf(bigtext_cmd);
                        if (index != -1)
                        {
                            // get the text to display
                            string bigtext = msg.Substring(index + bigtext_cmd.Length);
                            // send a request which is the command "eventtext" with its parameters
                            sendRequest(rcon_obj, RequestType.command, $"eventtext \"{bigtext}\" \"255\"");
                        }
                    }

                    // if the server ping the rcon client,
                    // ping it back to keep the connection alive
                    if (evt.EventID == (short)lib.EventType.rcon_ping)
                    {
                        sendRequest(rcon_obj, RequestType.ping, "I pinged");
                    }
                    // if a player taunts, stop the loop
                    if (evt.EventID == (short)lib.EventType.player_taunt)
                    {
                        break;
                    }
                }

                // avoid sending to oblivion the last request made
                Thread.Sleep(160);

                // disconnect the rcon client
                rcon_obj.Disconnect();
            }
            // if something goes wrong, you will end up here
            catch (Exception e)
            {
                Console.WriteLine(e.ToString());
                Console.WriteLine("Something went wrong in the main.");
            }

            logger.StopWriting();

            // press 'Enter' to exit the console
            Console.Read();
            return(0);
        }