Ejemplo n.º 1
0
        /// <summary>
        ///     this is ran when IRSE starts the server and the server is ready for plugins to run code.
        /// </summary>
        public override void Init()
        {
            try
            {
                if (!MyConfig.Settings.Enabled)
                {
                    GetLogger.Warn("IRSEDiscordChatBot: Plugin Disabled");
                    return;
                }

                if (string.IsNullOrEmpty(MyConfig.Settings.DiscordToken) ||
                    MyConfig.Settings.DiscordToken == "discordtokenhere" ||
                    string.IsNullOrEmpty(MyConfig.Settings.MainChannelID.ToString()))
                {
                    GetLogger.Warn("IRSEDiscordChatBot: Configuration is wrong, please correct the settings for Discord Chat Relay Plugin.");
                    return;
                }

                if (DiscordClient.Instance == null)
                {
                    new DiscordClient();

                    DiscordClient.SocketClient.MessageReceived += SocketClient_MessageReceived;

                    DiscordClient.Instance.Start();
                }
            }
            catch (Exception ex1)
            {
                GetLogger.Warn(ex1, "IRSEDiscordChatBot Discord Initialization failed.");
                Console.WriteLine(ex1.ToString());
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Should be called once a Framework Construction is finished and we want to build it and
        /// start our application
        /// </summary>
        /// <param name="construction">The construction</param>
        /// <param name="logStarted">Specifies if the Framework Started message should be logged</param>
        public static void Build(this FrameworkConstruction construction, bool logStarted = true)
        {
            // Build the service provider
            construction.Build();

            // Log the startup complete
            if (logStarted)
            {
                GetLogger.LogCriticalSource($"Framework started...");
            }
        }
Ejemplo n.º 3
0
        public void TestSpawnEvent(GenericEvent evnt)
        {
            PlayerSpawnRequest hesse = evnt.Data as PlayerSpawnRequest;
            Player             p     = GetPluginHelper.getPlayerFromGuid(hesse.Sender);

            if (p == null)
            {
                GetLogger.Error("Error! Player Not Found E:55");
                return;
            }
            GetPluginHelper.SendMessageToServer(p.Name + " has joined the server!");
            GetPluginHelper.SendMessageToClient(p, "Welcome to the server " + p.Name + "!");
            GetPluginHelper.SendMessageToClient(p, "Use /help for all commands");
        }
Ejemplo n.º 4
0
        //// dont use constructors, use OnLoad
        //public PluginMain(){}

        /// <summary>
        /// this is ran when IRSE loads plugins, construct your stuff here!
        /// </summary>
        /// <param name="directory">this is the plugin directory</param>
        public override void OnLoad(string directory)
        {
            try
            {
                MyConfig.FileName = Path.Combine(directory, "Config.xml");
                MyConfig          = new MyConfig();

                debugMode = MyConfig.Settings.DebugMode;
            }
            catch (Exception ex)
            {
                GetLogger.Warn(ex, "IRSEDiscordChatBot Initialization failed.");
                Console.WriteLine(ex.ToString());
            }
        }
Ejemplo n.º 5
0
        public void OnPacketChatMessage(GenericEvent data)
        {
            if (!MyConfig.Settings.Enabled)
            {
                return;
            }

            if (MyConfig.Instance.Settings.MessageSentToDiscord.StartsWith("null"))
            {
                return;
            }

            try
            {
                Player player = ServerInstance.Instance.Handlers
                                .PlayerHandler.Players.GetPlayerByConnectionId((long)data.Data.OriginalMessage.SenderConnectionId);

                string name    = player.Name;
                string message = ((ClientChatMessage)data.Data.DeserializedObject).message;

                if (debugMode)
                {
                    Console.WriteLine($"<- Sending Message To Discord");
                }

                string outMsg = MyConfig.Instance.Settings.MessageSentToDiscord.Replace("(%PlayerName%)", name).Replace("(%ChatMessage%)", message).Replace("(%CurrentDateTime%)", DateTime.Now.ToString())
                                ?? $"Game Server - {name}: {message} ";

                DiscordClient.SendMessageToMainChannel(outMsg);

                if (MyConfig.Instance.Settings.PrintDiscordChatToConsole)
                {
                    Console.WriteLine(outMsg);
                }
            }
            catch (Exception ex)
            {
                GetLogger.Error(ex.ToString());
            }
        }
Ejemplo n.º 6
0
 public override void OnEnable()
 {
     GetLogger.Info("Loading CyberCore Plugin!");
 }
Ejemplo n.º 7
0
 public NugetPackageSourceManipulator(GetLogger getLogger)
 {
     _getLogger = () => getLogger();
 }