Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Seperated classes - Added support for loops - Running the timecheck loop in a different thread - Added support for saving sidechat to logfile
- Loading branch information
Showing
9 changed files
with
224 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using BattleNET; | ||
|
||
namespace ServerMessages | ||
{ | ||
public static class beConn | ||
{ | ||
public static BattlEyeClient b { get; set; } | ||
|
||
static beConn() | ||
{ | ||
b = new BattlEyeClient(settings.loginCredentials); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
05:46:45~Example 1 msg | ||
14:05:00~Example 2 msg | ||
05:46:45~Example 1 msg~no-loop | ||
14:05:00~Example 2 msg~loop-2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
host=127.0.0.1 | ||
port=2302 | ||
pass=rconpassword | ||
pass=rconpassword | ||
savechat=true | ||
split=50 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
|
||
namespace ServerMessages | ||
{ | ||
class publicMethods | ||
{ | ||
public static void sayGlobal(String saystr) | ||
{ | ||
// This method sends messages via BE to all players (globally) | ||
if (!beConn.b.Connected) | ||
beConn.b.Connect(); | ||
beConn.b.SendCommand("Say -1 " + saystr); | ||
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " Said global: " + saystr); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.IO; | ||
using System.Net; | ||
using BattleNET; | ||
|
||
namespace ServerMessages | ||
{ | ||
class settings | ||
{ | ||
// This class reads the settings.cfg and puts everything into variables for later use. | ||
public static string hostRcon = getSetting(1, 5); | ||
public static string portRcon = getSetting(2, 5); | ||
public static string passRcon = getSetting(3, 5); | ||
public static string saveChat = getSetting(4, 9); | ||
public static string splitChatLogAt = getSetting(5, 6); | ||
|
||
public static BattlEyeLoginCredentials loginCredentials = new BattlEyeLoginCredentials(host: IPAddress.Parse(hostRcon), port: Convert.ToInt16(portRcon), password: passRcon); | ||
|
||
private static String getSetting(int x, int remChar) | ||
{ | ||
using (var sr = new StreamReader(@"settings.cfg")) | ||
{ | ||
if (File.ReadLines(@"settings.cfg").Count() < 5) | ||
{ | ||
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " Your settings.cfg is incorrectly formatted. Press ENTER to exit."); | ||
Console.ReadLine(); | ||
Environment.Exit(0); | ||
} | ||
for (int i = 1; i < x; i++) | ||
sr.ReadLine(); | ||
string returnedLine = sr.ReadLine().Remove(0, remChar); | ||
sr.Close(); | ||
return returnedLine; | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading; | ||
using System.IO; | ||
|
||
namespace ServerMessages | ||
{ | ||
class timeChecker | ||
{ | ||
public void Check() | ||
{ | ||
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " Reading messages..."); | ||
string messagesFile = File.ReadAllText(@"messages.cfg"); | ||
string[] messages = messagesFile.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); | ||
|
||
int timeLoop = 0; | ||
while (true) | ||
{ | ||
// If it has been +-10min since last read of messages file, read again | ||
if (timeLoop > 599) | ||
{ | ||
Console.WriteLine(DateTime.Now.ToString("HH:mm:ss") + " Reading messages..."); | ||
messagesFile = File.ReadAllText(@"messages.cfg"); | ||
messages = messagesFile.Split(Environment.NewLine.ToCharArray(), StringSplitOptions.RemoveEmptyEntries); | ||
timeLoop = 0; | ||
} | ||
|
||
// For each message, check if time specified equals current time, if so say message globally. | ||
foreach (string x in messages) | ||
{ | ||
string[] messageThis = x.Split('~'); | ||
int typeLoop = 0; | ||
if (messageThis[2] != "no-loop") | ||
typeLoop = Convert.ToInt16(messageThis[2].Remove(0, 5)); | ||
DateTime checkDateTime = DateTime.ParseExact(messageThis[0], "HH:mm:ss", null); | ||
|
||
if (typeLoop == 0) | ||
{ | ||
if (checkDateTime.ToString("HH:mm:ss") == DateTime.Now.ToString("HH:mm:ss")) | ||
publicMethods.sayGlobal(messageThis[1]); | ||
} | ||
else | ||
{ | ||
DateTime originalDateTime = checkDateTime; | ||
do | ||
{ | ||
checkDateTime = checkDateTime.AddHours(typeLoop); | ||
if (checkDateTime.ToString("HH:mm:ss") == DateTime.Now.ToString("HH:mm:ss")) | ||
publicMethods.sayGlobal(messageThis[1]); | ||
} while (checkDateTime.ToString("HH:mm:ss") != originalDateTime.ToString("HH:mm:ss")); | ||
} | ||
} | ||
|
||
timeLoop++; | ||
Thread.Sleep(1000); | ||
} | ||
} | ||
} | ||
} |