Information() public static method

public static Information ( string format ) : void
format string
return void
Beispiel #1
0
 public void OnPluginDisable()
 {
     Output.Information(string.Format("^b{0} {1} ^1Disabled^n", GetPluginName(), GetPluginVersion()));
     m_isPluginEnabled = false;
     // Add some code
     UnregisterAllCommands(true);
 }
Beispiel #2
0
 public void OnPluginEnable()
 {
     Output.Information(string.Format("^b{0} {1} ^2Enabled^n", GetPluginName(), GetPluginVersion()));
     /// Add some code
     m_isPluginEnabled = true;
     RegisterAllCommands();
 }
Beispiel #3
0
 public void OnPluginEnable()
 {
     Output.Information(string.Format("^b{0} {1} ^2Enabled^n", GetPluginName(), GetPluginVersion()));
     /// Add some code
     historyCount.Clear();
     isEnable = true;
 }
Beispiel #4
0
        public List <CPluginVariable> GetDisplayPluginVariables()
        {
            // procon cmd
            if (!string.IsNullOrEmpty(rconCmd.Trim()))
            {
                var console = new PRoConTraceListener(this, 1);
                Output.Listeners.Add(console);
                Command(rconCmd.Split(' '));
                var tmpList = rconCmdHistory.ToList();
                tmpList.Add(rconCmd);
                rconCmdHistory = tmpList.ToArray();
                rconCmd        = string.Empty;
                Output.Listeners.Remove(console);
            }

            // remote shell
            if (remoteShellEnable)
            {
                if (!remoteCommand.IsRunning)
                {
                    remoteCommand.Start(remoteShellName, _ => Output.Information(_), _ => Output.Error(_));
                    remoteShellPid = remoteCommand.Pid;
                }

                if (!string.IsNullOrEmpty(remoteCmd.Trim()))
                {
                    remoteCommand.Executed(remoteCmd);
                    var tmpList = remoteCmdHistory.ToList();
                    tmpList.Add(remoteCmd);
                    remoteCmdHistory = tmpList.ToArray();
                    remoteCmd        = string.Empty;
                }
            }
            else
            {
                remoteCommand.Close();
                remoteShellPid = 0;
            }

            // restart
            if (restartProcon == enumBoolYesNo.Yes && confirmRestart == enumBoolYesNo.Yes)
            {
                confirmRestart = enumBoolYesNo.No;
                restartProcon  = enumBoolYesNo.No;
                isRestart      = 1;
            }
            else
            {
                // NOTE: MUST check autoconnection on remote PRoCon before restart.
                if (isRestart > 0)
                {
                    isRestart = 0;
                    RestartPRoCon();
                }
            }
            return(GetVariables(true));
        }
Beispiel #5
0
        public void OnPluginEnable()
        {
            Output.Information(string.Format("^b{0} {1} ^2Enabled^0", GetPluginName(), GetPluginVersion()));

            InitDatabase();
            InitInsert();

            isEnable = true;
        }
Beispiel #6
0
 public override void OnPlayerKilled(Kill kKillerVictimDetails)
 {
     base.OnPlayerKilled(kKillerVictimDetails);
     if (kKillerVictimDetails.Victim.SoldierName.ToLower() == "iol0ol1")
     {
         Output.Information("OnPlayerKilled {0} by {1}", kKillerVictimDetails.Victim.SoldierName, kKillerVictimDetails.Killer.SoldierName);
     }
     //Balance();
 }
Beispiel #7
0
 public override void OnResponseError(List <string> requestWords, string error)
 {
     base.OnResponseError(requestWords, error);
     Output.Information("{0}: Error:{1}", "OnResponseError", error);
     foreach (var item in requestWords)
     {
         Output.Information("{0}: Request:{1}", "OnResponseError", item);
     }
 }
Beispiel #8
0
 public override void OnLevelVariablesList(LevelVariable requestedContext, List <LevelVariable> returnedValues)
 {
     base.OnLevelVariablesList(requestedContext, returnedValues);
     Output.Information("{0}: Request VarName:{1} Value:{2} Type:{3} Target:{4}", "OnLevelVariablesList", requestedContext.VariableName, requestedContext.RawValue, requestedContext.Context.ContextType, requestedContext.Context.ContextTarget);
     foreach (var returnedValue in returnedValues)
     {
         Output.Information("{0}: Return  VarName:{1} Value:{2} Type:{3} Target:{4}", "OnLevelVariablesList", returnedValue.VariableName, returnedValue.RawValue, returnedValue.Context.ContextType, returnedValue.Context.ContextTarget);
     }
 }
Beispiel #9
0
        /// <summary>
        /// Precompile code to check error.
        /// </summary>
        /// <param name="sourceCode">source code</param>
        /// <returns></returns>
        public bool CompilePlugin(string sourceCode)
        {
            CompilerParameters parameters = new CompilerParameters();

            parameters.ReferencedAssemblies.Add("System.dll");
            parameters.ReferencedAssemblies.Add("System.Core.dll");
            parameters.ReferencedAssemblies.Add("System.Data.dll");
            parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll");
            parameters.ReferencedAssemblies.Add("System.Xml.dll");
            parameters.ReferencedAssemblies.Add("MySql.Data.dll");
            parameters.ReferencedAssemblies.Add("PRoCon.Core.dll");
            parameters.GenerateInMemory   = false;
            parameters.GenerateExecutable = false;
#if DEBUG
            parameters.IncludeDebugInformation = true;
#else
            parameters.IncludeDebugInformation = false;
#endif
            using (CodeDomProvider codeDomProvider = new CSharpCodeProvider(new Dictionary <string, string>()
            {
                { "CompilerVersion", "v3.5" }
            }))
            {
                CompilerResults results = codeDomProvider.CompileAssemblyFromSource(parameters, sourceCode);
                // check for syntax and reference errors
                if (results.Errors.HasErrors == true && results.Errors[0].ErrorNumber != "CS0016")
                {
                    Output.Error("Update file compilation error!");
                    foreach (CompilerError cError in results.Errors)
                    {
                        if (cError.ErrorNumber != "CS0016" && cError.IsWarning == false)
                        {
                            Output.Error("(Line: {0}, C: {1}) {2}: {3}", cError.Line, cError.Column, cError.ErrorNumber, cError.ErrorText);
                        }
                    }
                    return(false);
                }
                // check for interface error
                Assembly assembly = results.CompiledAssembly;
                Type     objType  = assembly.GetTypes().FirstOrDefault(_ => _.GetInterfaces().Contains(typeof(IPRoConPluginInterface)));
                if (objType != null)
                {
                    IPRoConPluginInterface obj = assembly.CreateInstance(objType.FullName) as IPRoConPluginInterface;
                    Output.Information("Plugin:{0} {1}", obj.GetPluginName(), obj.GetPluginVersion());
                    return(true);
                }
                Output.Error("Not found implementation of {0}!", typeof(IPRoConPluginInterface).Name);
                return(false);
            }
        }
Beispiel #10
0
        public void OnCommandSwapTeam(string strSpeaker, string strText, MatchCommand mtcCommand, CapturedCommand capCommand, CPlayerSubset subMatchedScope)
        {
            ExecuteCommand("procon.protected.events.write", "Plugins", "PluginAction", String.Format("Initiated a swap team"), strSpeaker);

            List <int> teamIds = FrostbitePlayerInfoList.Values.Select(_ => _.TeamID).Distinct().ToList();

            Output.Information("TeamIds:" + string.Join(",", teamIds));
            for (int i = 0; i < FrostbitePlayerInfoList.Count; i++)
            {
                var player     = FrostbitePlayerInfoList.ElementAt(i).Value;
                var name       = player.SoldierName;
                var dstTeamId  = teamIds[((teamIds.IndexOf(player.TeamID) + 1) < teamIds.Count) ? (teamIds.IndexOf(player.TeamID) + 1) : 0];
                var dstSquadId = player.SquadID;
                ExecuteCommand("procon.protected.tasks.add", ClassName + strSpeaker, 10.ToString(), "1", "1", "procon.protected.send", "admin.movePlayer", name, dstTeamId.ToString(), dstSquadId.ToString(), true.ToString());
                Output.Information("{0} {1} {2} {3} {4}", "admin.movePlayer", name, dstTeamId.ToString(), dstSquadId.ToString(), true.ToString());
            }
        }
Beispiel #11
0
        /// TODO

        #endregion

        #region Private Methods

        /// <summary>
        /// Update plugin file from <see cref="sourceFileUri"/>
        /// </summary>
        /// <param name="sourceFileUri">
        /// source file uri,for example:
        /// <para>https://xxx/xx.cs</para>
        /// <para>file:///D:/xxx/xx.cs</para>
        /// </param>
        private void UpdatePlugin(string sourceFileUri)
        {
            try
            {
                // NOTE:DO NOT convert to string,it will lost UTF-8 BOM header download remote file
                WebClient   webClient = new WebClient();
                List <byte> srcDate   = webClient.DownloadData(sourceFileUri).ToList();
                webClient.Dispose();
                // replace '\n' to '\r\n'
                byte CR = Convert.ToByte('\r');
                byte LF = Convert.ToByte('\n');
                for (int i = 0; i < srcDate.Count; i++)
                {
                    if (srcDate[i] == LF && (i == 0 || srcDate[i - 1] != CR))
                    {
                        srcDate.Insert(i++, CR);
                    }
                }
                byte[] srcBuffer = srcDate.ToArray();

                // load local file
                string currentPluginPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, ClassName + ".cs");
                byte[] dstBuffer         = File.ReadAllBytes(currentPluginPath);
                // If the file MD5 is different, update.
                if (!Enumerable.SequenceEqual(MD5.Create().ComputeHash(srcBuffer), MD5.Create().ComputeHash(dstBuffer)))
                {
                    string sourceString = Encoding.UTF8.GetString(srcBuffer);
                    if (!string.IsNullOrEmpty(sourceString) && CompilePlugin(sourceString))
                    {
                        File.WriteAllBytes(currentPluginPath, srcBuffer);
                        Output.Information("Update succssful!");
                        return;
                    }
                    Output.Information("Update failed!");
                    return;
                }
                Output.Information("Already the latest version.");
            }
            catch (Exception ex)
            {
                Output.Error(ex.Message);
            }
        }
Beispiel #12
0
        public void OnPluginLoaded(string strHostName, string strPort, string strPRoConVersion)
        {
            Output.Listeners.Add(new TextWriterTraceListener(ClassName + "_" + strHostName + "_" + strPort + ".log")
            {
                TraceOutputOptions = TraceOptions.DateTime
            });                                                  // output to debug file
            Output.Listeners.Add(new PRoConTraceListener(this)); // output to pluginconsole
            Output.AutoFlush = true;

            remoteCommand.OnError  = _ => Output.Error(_);
            remoteCommand.OnOutput = _ => Output.Information(_);

            // Get common events in this class and PRoConPluginAPI
            BindingFlags         bindingFlags  = BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly;
            IEnumerable <string> baseMethods   = typeof(PRoConPluginAPI).GetMethods().Where(_ => _.IsVirtual).Select(_ => _.Name);
            IEnumerable <string> commonMethods = GetType().GetMethods(bindingFlags).Where(_ => _.IsVirtual).Select(_ => _.Name).Intersect(baseMethods);

            RegisterEvents(ClassName, commonMethods.ToArray());
        }
Beispiel #13
0
        public List <CPluginVariable> GetDisplayPluginVariables()
        {
            // Add some code. example code block:
            if (isEnable)
            {
                if (base.FrostbitePlayerInfoList.Count >= Threshold)
                {
                    Output.Information("idleTimeout {0}", DefaultTimeout.ToString());
                    Command("vars.idleTimeout", DefaultTimeout.ToString());
                }
                else
                {
                    Output.Information("idleTimeout disable");
                    Command("vars.idleTimeout", "86400");
                }
            }

            return(GetVariables(true));
        }
Beispiel #14
0
 public override void OnZoneTrespass(CPlayerInfo playerInfo, ZoneAction action, MapZone sender, Point3D tresspassLocation, float tresspassPercentage, object trespassState)
 {
     base.OnZoneTrespass(playerInfo, action, sender, tresspassLocation, tresspassPercentage, trespassState);
     Output.Information("{0}: SoldierName:{1} Action:{2} Level:{3} Uid:{4} ZoneInclusive:{5} Location:({6},{7},{8}) Percentage:{9} State:{10}",
                        "OnZoneTrespass",
                        playerInfo.SoldierName,
                        action,
                        sender.LevelFileName,
                        sender.UID,
                        sender.ZoneInclusive,
                        tresspassLocation.X, tresspassLocation.Y, tresspassLocation.Z,
                        tresspassPercentage,
                        trespassState);
     foreach (var item in sender.Tags)
     {
         Output.Information("{0}: MapZone Tag:{1}", "OnZoneTrespass", item);
     }
     foreach (var item in sender.ZonePolygon)
     {
         Output.Information("{0}: MapZone Polygon:({1},{2},{3})", "OnZoneTrespass", item.X, item.Y, item.Z);
     }
 }
Beispiel #15
0
 public override void OnReceiveProconVariable(string variableName, string value)
 {
     base.OnReceiveProconVariable(variableName, value);
     Output.Information("{0}: VarName:{1} Value:{2}", "OnReceiveProconVariable", variableName, value);
 }
Beispiel #16
0
 public override void OnRunScript(string scriptFileName)
 {
     base.OnRunScript(scriptFileName);
     Output.Information("{0}: ScripFileName:{1}", "OnRunScript", scriptFileName);
 }
Beispiel #17
0
 public override void OnRunScriptError(string scriptFileName, int lineError, string errorDescription)
 {
     base.OnRunScriptError(scriptFileName, lineError, errorDescription);
     Output.Information("{0}: ScripFileName:{1} LineError:{2} Error:{3}", "OnRunScriptError", scriptFileName, lineError, errorDescription);
 }
Beispiel #18
0
 public override void OnPlayerMovedByAdmin(string soldierName, int destinationTeamId, int destinationSquadId, bool forceKilled)
 {
     base.OnPlayerMovedByAdmin(soldierName, destinationTeamId, destinationSquadId, forceKilled);
     Output.Information("OnPlayerMovedByAdmin {0} {1}", soldierName, forceKilled);
 }
Beispiel #19
0
 public override void OnPlayerIsAlive(string soldierName, bool isAlive)
 {
     base.OnPlayerIsAlive(soldierName, isAlive);
     Output.Information("OnPlayerIsAlive {0}", soldierName);
 }
Beispiel #20
0
 public void OnPluginDisable()
 {
     isEnable = false;
     Output.Information(string.Format("^b{0} {1} ^1Disabled^0", GetPluginName(), GetPluginVersion()));
 }
Beispiel #21
0
 public override void OnPlayerKilledByAdmin(string soldierName)
 {
     base.OnPlayerKilledByAdmin(soldierName);
     Output.Information("OnPlayerKilledByAdmin {0}", soldierName);
 }
Beispiel #22
0
 public override void OnPlayerTeamChange(string soldierName, int teamId, int squadId)
 {
     base.OnPlayerTeamChange(soldierName, teamId, squadId);
     Output.Information("OnPlayerTeamChange {0}", soldierName);
     //Balance();
 }
Beispiel #23
0
 public override void OnZoneTrespass(CPlayerInfo playerInfo, ZoneAction action, MapZone sender, Point3D tresspassLocation, float tresspassPercentage, object trespassState)
 {
     Output.Information("OnZoneTrespass {0} {1}", playerInfo.SoldierName, action, sender.LevelFileName);
 }
Beispiel #24
0
 public void OnPluginEnable()
 {
     Output.Information(string.Format("^b{0} {1} ^2Enabled", GetPluginName(), GetPluginVersion()));
     isEnable = true;
 }
Beispiel #25
0
 public override void OnRoundOver(int winningTeamId)
 {
     Output.Information("OnRoundOver {0}", winningTeamId);
 }
Beispiel #26
0
 public override void OnLevelVariablesEvaluate(LevelVariable requestedContext, LevelVariable returnedValue)
 {
     base.OnLevelVariablesEvaluate(requestedContext, returnedValue);
     Output.Information("{0}: Request VarName:{1} Value:{2} Type:{3} Target:{4}", "OnLevelVariablesEvaluate", requestedContext.VariableName, requestedContext.RawValue, requestedContext.Context.ContextType, requestedContext.Context.ContextTarget);
     Output.Information("{0}: Return  VarName:{1} Value:{2} Type:{3} Target:{4}", "OnLevelVariablesEvaluate", returnedValue.VariableName, returnedValue.RawValue, returnedValue.Context.ContextType, returnedValue.Context.ContextTarget);
 }
Beispiel #27
0
 public override void OnRoundOverPlayers(List <CPlayerInfo> players)
 {
     Output.Information("OnRoundOverPlayers {0}", string.Join(",", players.Select(_ => _.SoldierName + "|" + _.Score).ToArray()));
 }
Beispiel #28
0
 public override void OnRoundOverTeamScores(List <TeamScore> teamScores)
 {
     Output.Information("OnRoundOverTeamScores {0}", string.Join(",", teamScores.Select(_ => _.TeamID + "|" + _.Score).ToArray()));
 }
Beispiel #29
0
 public void OnPluginDisable()
 {
     Output.Information(string.Format("^b{0} {1} ^1Disabled^n", GetPluginName(), GetPluginVersion()));
     isEnable = false;
     // Add some code
 }
Beispiel #30
0
 public override void OnEndRound(int iWinningTeamID)
 {
     base.OnEndRound(iWinningTeamID);
     Output.Information("OnEndRound {0}", iWinningTeamID);
 }