Skip to content

Commit 72f9dc0

Browse files
committed
Initial commit
0 parents  commit 72f9dc0

File tree

8 files changed

+607
-0
lines changed

8 files changed

+607
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.vs/

Essentials.LogCommands.sln

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.23107.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Essentials.LogCommands", "Essentials.LogCommands\Essentials.LogCommands.csproj", "{3FD50C42-A124-4D97-9282-F149A5C016DA}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{3FD50C42-A124-4D97-9282-F149A5C016DA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{3FD50C42-A124-4D97-9282-F149A5C016DA}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{3FD50C42-A124-4D97-9282-F149A5C016DA}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{3FD50C42-A124-4D97-9282-F149A5C016DA}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
EndGlobal

Essentials.LogCommands/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
lib/
2+
bin/
3+
obj/
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
4+
<PropertyGroup>
5+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
6+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
7+
<ProjectGuid>{3FD50C42-A124-4D97-9282-F149A5C016DA}</ProjectGuid>
8+
<OutputType>Library</OutputType>
9+
<AppDesignerFolder>Properties</AppDesignerFolder>
10+
<RootNamespace>Essentials.LogCommands</RootNamespace>
11+
<AssemblyName>Essentials.LogCommands</AssemblyName>
12+
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
13+
<FileAlignment>512</FileAlignment>
14+
</PropertyGroup>
15+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
16+
<DebugSymbols>true</DebugSymbols>
17+
<DebugType>full</DebugType>
18+
<Optimize>false</Optimize>
19+
<OutputPath>bin\Debug\</OutputPath>
20+
<DefineConstants>DEBUG;TRACE</DefineConstants>
21+
<ErrorReport>prompt</ErrorReport>
22+
<WarningLevel>4</WarningLevel>
23+
</PropertyGroup>
24+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
25+
<DebugType>pdbonly</DebugType>
26+
<Optimize>true</Optimize>
27+
<OutputPath>bin\Release\</OutputPath>
28+
<DefineConstants>TRACE</DefineConstants>
29+
<ErrorReport>prompt</ErrorReport>
30+
<WarningLevel>4</WarningLevel>
31+
</PropertyGroup>
32+
<ItemGroup>
33+
<Reference Include="Assembly-CSharp">
34+
<HintPath>lib\Assembly-CSharp.dll</HintPath>
35+
</Reference>
36+
<Reference Include="Rocket.API">
37+
<HintPath>lib\Rocket.API.dll</HintPath>
38+
</Reference>
39+
<Reference Include="Rocket.Core">
40+
<HintPath>lib\Rocket.Core.dll</HintPath>
41+
</Reference>
42+
<Reference Include="Rocket.Unturned">
43+
<HintPath>lib\Rocket.Unturned.dll</HintPath>
44+
</Reference>
45+
<Reference Include="uEssentials">
46+
<HintPath>lib\uEssentials.dll</HintPath>
47+
</Reference>
48+
<Reference Include="UnityEngine">
49+
<HintPath>lib\UnityEngine.dll</HintPath>
50+
</Reference>
51+
<Reference Include="System" />
52+
<Reference Include="System.Core" />
53+
<Reference Include="System.Xml.Linq" />
54+
<Reference Include="System.Data.DataSetExtensions" />
55+
<Reference Include="System.Data" />
56+
<Reference Include="System.Xml" />
57+
</ItemGroup>
58+
<ItemGroup>
59+
<Compile Include="src\LogCommands.cs" />
60+
<Compile Include="Properties\AssemblyInfo.cs" />
61+
</ItemGroup>
62+
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
63+
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
64+
Other similar extension points exist, see Microsoft.Common.targets.
65+
<Target Name="BeforeBuild">
66+
</Target>
67+
<Target Name="AfterBuild">
68+
</Target>
69+
-->
70+
</Project>
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
// General Information about an assembly is controlled through the following
5+
// set of attributes. Change these attribute values to modify the information
6+
// associated with an assembly.
7+
[assembly: AssemblyTitle("EssTestModule")]
8+
[assembly: AssemblyDescription("")]
9+
[assembly: AssemblyConfiguration("")]
10+
[assembly: AssemblyCompany("")]
11+
[assembly: AssemblyProduct("TestModule")]
12+
[assembly: AssemblyCopyright("Copyright © 2015")]
13+
[assembly: AssemblyTrademark("")]
14+
[assembly: AssemblyCulture("")]
15+
16+
// Setting ComVisible to false makes the types in this assembly not visible
17+
// to COM components. If you need to access a type in this assembly from
18+
// COM, set the ComVisible attribute to true on that type.
19+
[assembly: ComVisible(false)]
20+
21+
// The following GUID is for the ID of the typelib if this project is exposed to COM
22+
[assembly: Guid("3fd50c42-a124-4d97-9282-f149a5c016da")]
23+
24+
// Version information for an assembly consists of the following four values:
25+
//
26+
// Major Version
27+
// Minor Version
28+
// Build Number
29+
// Revision
30+
//
31+
// You can specify all the values or you can default the Build and Revision Numbers
32+
// by using the '*' as shown below:
33+
// [assembly: AssemblyVersion("1.0.*")]
34+
[assembly: AssemblyVersion("1.0.0.0")]
35+
[assembly: AssemblyFileVersion("1.0.0.0")]
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
1+
/*
2+
* This file is part of uEssentials project.
3+
* https://uessentials.github.io/
4+
*
5+
* Copyright (C) 2015-2016 Leonardosc
6+
*
7+
* This program is free software; you can redistribute it and/or modify
8+
* it under the terms of the GNU General Public License as published by
9+
* the Free Software Foundation; either version 2 of the License, or
10+
* (at your option) any later version.
11+
*
12+
* This program is distributed in the hope that it will be useful,
13+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
* GNU General Public License for more details.
16+
*
17+
* You should have received a copy of the GNU General Public License along
18+
* with this program; if not, write to the Free Software Foundation, Inc.,
19+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20+
*/
21+
22+
using System;
23+
using System.Collections.Generic;
24+
using System.IO;
25+
using System.Linq;
26+
using System.Text;
27+
using System.Threading;
28+
using Essentials.Api.Event;
29+
using Essentials.Api.Events;
30+
using Essentials.Api.Module;
31+
using Essentials.Common;
32+
33+
namespace Essentials.LogCommands
34+
{
35+
[ModuleInfo(
36+
Name = "LogCommands",
37+
Author = "Leonardosc",
38+
Version = "1.0.0",
39+
Flags = ModuleFlags.AUTO_REGISTER_EVENTS
40+
)]
41+
public class TestModule : EssModule
42+
{
43+
public static Dictionary<ulong, List<string>> Cache { get; } = new Dictionary<ulong, List<string>>();
44+
public static TestModule Instance { get; private set; }
45+
private int _checks;
46+
private char DirSep = Path.DirectorySeparatorChar;
47+
public string LogFolder
48+
{
49+
get
50+
{
51+
var path = $"{Folder}{DirSep}logs{DirSep}";
52+
if ( !Directory.Exists(path) )
53+
{
54+
Directory.CreateDirectory( path );
55+
}
56+
return path;
57+
}
58+
}
59+
60+
public override void OnLoad()
61+
{
62+
Instance = this;
63+
}
64+
65+
public override void OnUnload()
66+
{
67+
}
68+
69+
[SubscribeEvent(EventType.ESSENTIALS_COMMAND_POS_EXECUTED)]
70+
private void OnCommandExecuted( CommandPosExecuteEvent e )
71+
{
72+
if ( e.Source.IsConsole ) return;
73+
if ( Cache.Count >= 15 || (_checks > 20 && CheckValues()) )
74+
{
75+
SaveCache();
76+
_checks = 0;
77+
}
78+
else
79+
{
80+
_checks++;
81+
}
82+
var playerId = ulong.Parse(e.Source.Id);
83+
var sb = new StringBuilder();
84+
85+
sb.Append( $"[{DateTime.Now}] " )
86+
.Append( $"[{e.Result.Type}" )
87+
.Append( string.IsNullOrEmpty(e.Result.Message) ? "] " : $"({e.Result.Message})] " )
88+
.Append( e.Source.DisplayName )
89+
.Append( ": " )
90+
.Append( $"\"/{e.Command.Name}" )
91+
.Append( e.Arguments.IsEmpty ? "\"" : $" {e.Arguments.Join(0)}\"" );
92+
var text = sb.ToString();
93+
if ( Cache.ContainsKey( playerId ) )
94+
{
95+
Cache[playerId].Add( text );
96+
}
97+
else
98+
{
99+
Cache.Add( playerId, new List<string>{ text } );
100+
}
101+
}
102+
103+
private void SaveCache()
104+
{
105+
var contents = new Dictionary<ulong, List<String>>(Cache);
106+
Cache.Clear();
107+
108+
new Thread(() => {
109+
var text = new StringBuilder();
110+
contents.ForEach((k) => {
111+
var playerFolder = $"{LogFolder}{k.Key}{DirSep}";
112+
var commandsFile = $"{playerFolder}commands.txt";
113+
114+
if ( !Directory.Exists( playerFolder ) )
115+
{
116+
Directory.CreateDirectory( playerFolder );
117+
}
118+
if ( !File.Exists( commandsFile ) )
119+
{
120+
File.Create( commandsFile ).Close();
121+
}
122+
123+
k.Value.ForEach(t => text.Append( t ).Append( Environment.NewLine ) );
124+
File.AppendAllText( commandsFile, text.ToString() );
125+
});
126+
}).Start();
127+
}
128+
129+
/*
130+
Sum all commands in cache, return true if > 100
131+
*/
132+
private bool CheckValues()
133+
{
134+
return Cache.Values.Sum(a => a.Count) > 100;
135+
}
136+
}
137+
}

0 commit comments

Comments
 (0)