Skip to content

Commit

Permalink
Add Report feature
Browse files Browse the repository at this point in the history
  • Loading branch information
silentbaws committed Jun 17, 2020
1 parent ea1ba5c commit 2081aa6
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 8 deletions.
2 changes: 1 addition & 1 deletion ExamplePlugin/ExamplePlugin.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>..\XLMultiplayerServerConsoleApp\bin\Release\Plugins\ExamplePlugin\</OutputPath>
<OutputPath>..\XLMultiplayerServerConsoleApp\bin\Debug\Plugins\ExamplePlugin\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
Expand Down
7 changes: 7 additions & 0 deletions XLMultiplayer/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,13 @@ static bool OnToggle(UnityModManager.ModEntry modEntry, bool value) {
File.Copy(modEntry.Path + "System.Runtime.CompilerServices.Unsafe.dll", directory + "\\System.Runtime.CompilerServices.Unsafe.dll", true);
} catch (Exception) { }

var mod = UnityModManager.FindMod("blendermf.XLShredMenu");
if (mod != null) {
modEntry.CustomRequirements = $"Mod {mod.Info.DisplayName} incompatible";
enabled = false;
return false;
}

//Patch the replay editor
harmonyInstance = new Harmony(modEntry.Info.Id);
harmonyInstance.PatchAll(Assembly.GetExecutingAssembly());
Expand Down
2 changes: 1 addition & 1 deletion XLMultiplayer/MultiplayerController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -950,7 +950,7 @@ public void SendChatMessage(string msg) {
string afterMarkup = RemoveMarkup(msg);

if(afterMarkup.Length > 0) {
chatMessages.Add(this.playerController.username + "<b><color=\"blue\"> (You): </color></b>" + afterMarkup);
if (!afterMarkup.StartsWith("/")) chatMessages.Add(this.playerController.username + "<b><color=\"blue\"> (You): </color></b>" + afterMarkup);
this.SendBytes(OpCode.Chat, ASCIIEncoding.ASCII.GetBytes(afterMarkup), true);
}
}
Expand Down
2 changes: 2 additions & 0 deletions XLMultiplayerServer/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class Player {

public Stopwatch timeoutWatch = new Stopwatch();

public List<string> previousMessages = new List<string>();

public Player(byte pID, uint conn, Address addr) {
this.playerID = pID;
this.connection = conn;
Expand Down
47 changes: 41 additions & 6 deletions XLMultiplayerServer/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,12 +377,12 @@ public void ProcessMessage(byte[] buffer, byte fromID, NetworkingSockets server)
}
break;
case OpCode.Animation:
if(players[fromID] != null) {
if (players[fromID] != null) {
bool reliable = buffer[buffer.Length - 1] == (byte)1 ? true : false;
buffer[buffer.Length - 1] = fromID;

foreach (Player player in players) {
if(player != null && player.playerID != fromID) {
if (player != null && player.playerID != fromID) {
ConnectionStatus status = new ConnectionStatus();
if (server.GetQuickConnectionStatus(player.connection, ref status)) {
int bytesPending = status.pendingReliable + status.sentUnackedReliable;
Expand Down Expand Up @@ -412,17 +412,52 @@ public void ProcessMessage(byte[] buffer, byte fromID, NetworkingSockets server)
case OpCode.Chat:
string contents = ASCIIEncoding.ASCII.GetString(buffer, 1, buffer.Length - 1);
LogMessageCallback("Chat Message from {0} saying: {1}", ConsoleColor.White, fromID, contents);
if (LogChatMessageCallback != null) LogChatMessageCallback($"{RemoveMarkup(players[fromID].username)}({fromID}): {contents}");
LogChatMessageCallback?.Invoke($"{RemoveMarkup(players[fromID].username)}({fromID}): {contents}");

byte[] sendBuffer = new byte[buffer.Length + 1];
Array.Copy(buffer, 0, sendBuffer, 0, buffer.Length);
sendBuffer[buffer.Length] = fromID;

if (contents.StartsWith("/")) {
if (contents.StartsWith("/report ", StringComparison.CurrentCultureIgnoreCase)) {
string[] splitContents = contents.Split(new char[] { ' ' }, 2);
if (splitContents.Length == 2) {
int reportedID = -1;
if (Int32.TryParse(splitContents[1], out reportedID)) {
if (players[reportedID] != null) {
StreamWriter writer = new StreamWriter($"Report {((ulong)DateTime.Now.ToBinary()).ToString()}.txt");
writer.WriteLine($"Player {RemoveMarkup(players[reportedID].username)} with the IP: {players[reportedID].ipAddr.GetIP()} was reported following these messages");
foreach (string msg in players[reportedID].previousMessages) {
writer.WriteLine(msg);
writer.Flush();
}
writer.Close();

foreach (Player player in players) {
if(player != null) {
server.SendMessageToConnection(player.connection, sendBuffer, SendFlags.Reliable);
byte[] response = ProcessMessageCommand($"msg:5:ff0 Successfully reported player {players[reportedID].username}");
server.SendMessageToConnection(players[fromID].connection, response, SendFlags.Reliable);
break;
}
}
}

byte[] invalidReport = ProcessMessageCommand($"msg:5:f00 Improperly formatted report message or player with given ID does not exist");
server.SendMessageToConnection(players[fromID].connection, invalidReport, SendFlags.Reliable);
break;
}

byte[] invalidCommand = ProcessMessageCommand($"msg:5:f00 Given command does not exist");
server.SendMessageToConnection(players[fromID].connection, invalidCommand, SendFlags.Reliable);
break;
} else {
players[fromID].previousMessages.Add(contents);
if (players[fromID].previousMessages.Count > 10) players[fromID].previousMessages.RemoveAt(0);
foreach (Player player in players) {
if (player != null) {
server.SendMessageToConnection(player.connection, sendBuffer, SendFlags.Reliable);
}
}
}

break;
case OpCode.MapVote:
if (ENFORCE_MAPS) {
Expand Down

0 comments on commit 2081aa6

Please sign in to comment.