Skip to content

Commit a32647b

Browse files
Fixed botcmd.txt
- Fixed error with botcmd.txt being locked when server is running - Moved test functions to dedicated DebugFunctions.cs
1 parent 7571153 commit a32647b

File tree

4 files changed

+65
-31
lines changed

4 files changed

+65
-31
lines changed

BotCommands.cs

+8-29
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using RoR2.Stats;
1313
using UnityEngine.Networking;
1414
using System.Threading.Tasks;
15-
using Console = RoR2.Console;
1615
using Debug = UnityEngine.Debug;
1716
using Path = System.IO.Path;
1817

@@ -21,7 +20,7 @@ namespace BotCMDs
2120
{
2221
[BepInDependency("com.bepis.r2api")]
2322
[BepInPlugin("com.Rayss.BotCommands", "BotCommands", "0.3.0")]
24-
public class BotCommands : BaseUnityPlugin
23+
public partial class BotCommands : BaseUnityPlugin
2524
{
2625
// Config
2726
private static ConfigEntry<string> Cmdpath { get; set; }
@@ -65,13 +64,19 @@ private void Start()
6564
{
6665
StartHooks();
6766
Reading();
67+
68+
// These are only called if built in debug mode
6869
OpenExe();
70+
RandomString();
6971
}
7072

7173
private async void Reading()
7274
{
7375
// Create botcmd.txt if it doesn't exist yet
7476
using (StreamWriter w = File.AppendText(_botcmdPath))
77+
{
78+
w.Close();
79+
}
7580

7681
using (StreamReader reader = new StreamReader(new FileStream(_botcmdPath,
7782
FileMode.Open, FileAccess.Read, FileShare.ReadWrite)))
@@ -241,33 +246,7 @@ private static void GetStats(NetworkUser user)
241246
Log.LogError("BotCommands: Unable to find executable file!");
242247
}
243248
}
244-
245-
// Used for debugging database
246-
[Conditional("DEBUG")]
247-
private static void OpenExe()
248-
{
249-
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
250-
ProcessStartInfo startInfo = new ProcessStartInfo();
251-
startInfo.CreateNoWindow = true;
252-
startInfo.UseShellExecute = false;
253-
startInfo.FileName = path + @"\BotCommands_Dynamo.exe";
254-
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
255-
startInfo.Arguments = "server9 123456789 100 100 100 100 100 100 100 100";
256-
257-
try
258-
{
259-
// Start the process with the info we specified.
260-
using (Process exeProcess = Process.Start(startInfo))
261-
{
262-
Log.LogWarning("BotCommands: Updating stats database!");
263-
}
264-
}
265-
catch
266-
{
267-
Log.LogError("BotCommands: Unable to find executable file!");
268-
}
269-
}
270-
249+
271250
// Borrowed from R2DSEssentials.Util.Networking
272251
private static NetworkUser FindNetworkUserForConnectionServer(NetworkConnection connection)
273252
{

DebugFunctions.cs

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System;
2+
using System.Diagnostics;
3+
using System.IO;
4+
using System.Reflection;
5+
using BepInEx;
6+
7+
namespace BotCMDs
8+
{
9+
public partial class BotCommands : BaseUnityPlugin
10+
{
11+
// Used for debugging database
12+
[Conditional("DEBUG")]
13+
private static void OpenExe()
14+
{
15+
var path = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
16+
ProcessStartInfo startInfo = new ProcessStartInfo();
17+
startInfo.CreateNoWindow = true;
18+
startInfo.UseShellExecute = false;
19+
startInfo.FileName = path + @"\BotCommands_Dynamo.exe";
20+
startInfo.WindowStyle = ProcessWindowStyle.Hidden;
21+
startInfo.Arguments = "serverTest 123456789 100 100 100 100 100 100 100 100";
22+
23+
try
24+
{
25+
// Start the process with the info we specified.
26+
using (Process exeProcess = Process.Start(startInfo))
27+
{
28+
Log.LogWarning("BotCommands: Updating stats database!");
29+
}
30+
}
31+
catch
32+
{
33+
Log.LogError("BotCommands: Unable to find executable file!");
34+
}
35+
}
36+
37+
// Outputs a random string on launch
38+
[Conditional("DEBUG")]
39+
private static void RandomString()
40+
{
41+
var random = new Random();
42+
const string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
43+
var stringChars = new char[8];
44+
45+
for (var i = 0; i < stringChars.Length; i++)
46+
{
47+
stringChars[i] = chars[random.Next(chars.Length)];
48+
}
49+
50+
var finalString = new string(stringChars);
51+
Log.LogWarning(finalString);
52+
}
53+
}
54+
}

Dynamo/DynamoMain.cs

-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ public static partial class Dynamo
1616
private static Table statsTable;
1717
private static readonly CancellationTokenSource source = new CancellationTokenSource();
1818
private static readonly CancellationToken token = source.Token;
19-
2019
private static Document stats_record;
2120

2221
//Used to tell if we errored and need to exit
@@ -40,7 +39,6 @@ public static void Main(string[] args)
4039
var purchases = Convert.ToInt32(Math.Round(Convert.ToDouble(args[9])));
4140

4241
//Variables used for DynamoDB table
43-
//Will later be called "server1" or "server2" etc
4442
const string dbTableName = "BotCommands_Stats";
4543
var itemAttributes = new List<AttributeDefinition>
4644
{

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ If you want to build from source:
2626
- Self-Contained .exe file will be located: `repo_directory\bin\Release\netcoreapp3.1\win-x64\publish`
2727

2828
## Version History
29+
### 0.3.1
30+
- Fixed error with botcmd.txt being locked when server is running
31+
- Moved test functions to dedicated DebugFunctions.cs
2932
### 0.3.0
3033
- Implemented stat tracking directly into the plugin!
3134
- BotCommands_Dynamo.exe is called from the plugin file when a player leaves the server to update the stats database

0 commit comments

Comments
 (0)