Event based plugin support now added

This commit is contained in:
RaidMax 2015-08-20 14:23:13 -05:00
parent 73aa001d79
commit ec7bed8e11
10 changed files with 236 additions and 74 deletions

View File

@ -143,7 +143,9 @@
<Content Include="lib\SQLite.Interop.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="plugins\SamplePlugin.dll" />
<Content Include="plugins\SamplePlugin.dll">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="version.txt">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Content>

View File

@ -9,6 +9,7 @@ namespace IW4MAdmin
public class PluginImporter
{
public static List<Command> potentialPlugins = new List<Command>();
public static List<EventNotify> potentialNotifies = new List<EventNotify>();
public static bool Load()
{
@ -46,15 +47,24 @@ namespace IW4MAdmin
Type[] types = Plugin.GetTypes();
foreach(Type assemblyType in types)
{
if(assemblyType.IsClass && assemblyType.BaseType.Name == "Command")
if(assemblyType.IsClass && assemblyType.BaseType.Name == "EventNotify")
{
Object notifyObject = Activator.CreateInstance(assemblyType);
EventNotify newNotify = (EventNotify)notifyObject;
potentialNotifies.Add(newNotify);
Program.getManager().mainLog.Write("Loaded event plugin \"" + assemblyType.Name + "\"", Log.Level.All);
}
else if (assemblyType.IsClass && assemblyType.BaseType.Name == "Command")
{
Object commandObject = Activator.CreateInstance(assemblyType);
Command newCommand = (Command)commandObject;
potentialPlugins.Add(newCommand);
Program.getManager().mainLog.Write("Loaded command plugin \"" + newCommand.Name + "\"", Log.Level.All);
}
else
Program.getManager().mainLog.Write("Ignoring invalid command plugin \"" + assemblyType.Name + "\"", Log.Level.All);
Program.getManager().mainLog.Write("Ignoring invalid plugin \"" + assemblyType.Name + "\"", Log.Level.All);
}
}
}

View File

@ -18,10 +18,6 @@ namespace IW4MAdmin
commandQueue = new Queue<string>();
}
public override void initAbstractObj()
{
throw new NotImplementedException();
}
override public void getAliases(List<Player> returnPlayers, Player Origin)
{
if (Origin == null)
@ -126,6 +122,8 @@ namespace IW4MAdmin
aliasDB.updatePlayer(NewPlayer.Alias);
clientDB.updatePlayer(NewPlayer);
events.Enqueue(new Event(Event.GType.Connect, "", NewPlayer, null, this));
if (NewPlayer.Level == Player.Permission.Banned) // their guid is already banned so no need to check aliases
{
@ -240,6 +238,7 @@ namespace IW4MAdmin
statDB.updatePlayer(Leaving);
Log.Write("Client at " + cNum + " disconnecting...", Log.Level.Debug);
events.Enqueue(new Event(Event.GType.Disconnect, "", Leaving, null, this));
lock (players)
{
players[cNum] = null;
@ -410,10 +409,16 @@ namespace IW4MAdmin
while(isRunning)
{
if (events.Count > 0)
processEvent(events.Dequeue());
{
Event curEvent = events.Peek();
processEvent(curEvent);
foreach (EventNotify E in PluginImporter.potentialNotifies)
E.onEvent(curEvent);
events.Dequeue();
}
if (commandQueue.Count > 0)
lastCommandPointer = Utilities.executeCommand(PID, commandQueue.Dequeue(), lastCommandPointer);
Thread.Sleep(350);
Thread.Sleep(300);
}
}
@ -556,7 +561,7 @@ namespace IW4MAdmin
}
oldLines = lines;
l_size = logFile.getSize();
Thread.Sleep(350);
Thread.Sleep(300);
}
#if DEBUG == false
catch (Exception E)
@ -701,6 +706,7 @@ namespace IW4MAdmin
totalKills++;
Log.Write(E.Origin.Name + " killed " + E.Target.Name + " with a " + E.Data, Log.Level.Debug);
events.Enqueue(new Event(Event.GType.Death, E.Data, E.Target, null, this));
}
else // suicide/falling

Binary file not shown.

Binary file not shown.

View File

@ -5,6 +5,7 @@ VisualStudioVersion = 12.0.30723.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "IW4M ADMIN", "Admin\IW4M ADMIN.csproj", "{DD5DCDA2-51DB-4B1A-922F-5705546E6115}"
ProjectSection(ProjectDependencies) = postProject
{4785AB75-66F3-4391-985D-63A5A049A0FA} = {4785AB75-66F3-4391-985D-63A5A049A0FA}
{D51EECEB-438A-47DA-870F-7D7B41BC24D6} = {D51EECEB-438A-47DA-870F-7D7B41BC24D6}
EndProjectSection
EndProject

View File

@ -38,6 +38,17 @@ namespace SamplePlugin
}
}
public class SampleEvent : EventNotify
{
public override void onEvent(Event E)
{
E.Owner.Broadcast("An event occured of type: ^1" + E.Type);
if (E.Data != null)
E.Origin.Tell(E.Data);
}
}
public class InvalidCommandExample
{
private void doNotDoThis() { }

View File

@ -46,6 +46,9 @@
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>copy /Y "$(TargetDir)$(TargetName).dll" "$(SolutionDir)Admin\plugins\$(TargetName).dll"</PostBuildEvent>
</PropertyGroup>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">

View File

@ -82,14 +82,17 @@ namespace SharedLibrary
String eventType = line[0].Substring(line[0].Length - 1);
eventType = eventType.Trim();
if (eventType == "J")
return new Event(GType.Connect, null, SV.clientFromEventLine(line, 2), null, SV);
if (eventType == "Q")
return new Event(GType.Disconnect, null, SV.clientFromEventLine(line, 2), null, SV);
if (eventType == "K")
return new Event(GType.Kill, line[9], SV.clientFromEventLine(line, 6), SV.clientFromEventLine(line, 2), SV);
{
StringBuilder Data = new StringBuilder();
if (line.Length > 9)
{
for (int i = 9; i < line.Length; i++)
Data.Append(line[i] + ";");
}
return new Event(GType.Kill, Data.ToString(), SV.clientFromEventLine(line, 6), SV.clientFromEventLine(line, 2), SV);
}
if (line[0].Substring(line[0].Length - 3).Trim() == "say")
{
@ -99,10 +102,10 @@ namespace SharedLibrary
}
if (eventType == ":")
return new Event(GType.MapEnd, line[0], new Player("WORLD", "WORLD", 0, 0), null, null);
return new Event(GType.MapEnd, line[0], new Player("WORLD", "WORLD", 0, 0), null, SV);
if (line[0].Split('\\').Length > 5) // blaze it
return new Event(GType.MapChange, line[0], new Player("WORLD", "WORLD", 0, 0), null, null);
return new Event(GType.MapChange, line[0], new Player("WORLD", "WORLD", 0, 0), null, SV);
return null;
@ -123,4 +126,9 @@ namespace SharedLibrary
public Player Target;
public Server Owner;
}
public abstract class EventNotify
{
public abstract void onEvent(Event E);
}
}

View File

@ -106,16 +106,40 @@ namespace SharedLibrary
return this.PID;
}
/// <summary>
/// Get any know aliases ( name or ip based ) from the database
/// </summary>
/// <param name="returnPlayers">List of aliases matching given player</param>
/// <param name="Origin">Player to scan for aliases</param>
abstract public void getAliases(List<Player> returnPlayers, Player Origin);
//Add player object p to `players` list
/// <summary>
/// Add a player to the server's player list
/// </summary>
/// <param name="P">Player pulled from memory reading</param>
/// <returns>True if player added sucessfully, false otherwise</returns>
abstract public bool addPlayer(Player P);
//Remove player by CLIENT NUMBER
/// <summary>
/// Remove player by client number
/// </summary>
/// <param name="cNum">Client ID of player to be removed</param>
/// <returns>true if removal succeded, false otherwise</returns>
abstract public bool removePlayer(int cNum);
/// <summary>
/// Get the player from the server's list by line from game long
/// </summary>
/// <param name="L">Game log line containing event</param>
/// <param name="cIDPos">Position in the line where the cliet ID is written</param>
/// <returns>Matching player if found</returns>
abstract public Player clientFromEventLine(String[] L, int cIDPos);
/// <summary>
/// Get a player by name
/// </summary>
/// <param name="pName">Player name to search for</param>
/// <returns>Matching player if found</returns>
public Player clientFromName(String pName)
{
lock (players)
@ -130,32 +154,63 @@ namespace SharedLibrary
return null;
}
//Check ban list for every banned player and return ban if match is found
/// <summary>
/// Check ban list for every banned player and return ban if match is found
/// </summary>
/// <param name="C">Player to check if banned</param>
/// <returns>Matching ban if found</returns>
abstract public Ban isBanned(Player C);
//Procses requested command correlating to an event
/// <summary>
/// Process requested command correlating to an event
/// </summary>
/// <param name="E">Event parameter</param>
/// <param name="C">Command requested from the event</param>
/// <returns></returns>
abstract public Command processCommand(Event E, Command C);
//push a new event into the queue
private void addEvent(Event E)
{
events.Enqueue(E);
}
/// <summary>
/// Execute a command on the server
/// </summary>
/// <param name="CMD">Command to execute</param>
abstract public void executeCommand(String CMD);
/// <summary>
/// Retrieve a Dvar from the server
/// </summary>
/// <param name="DvarName">Name of Dvar to retrieve</param>
/// <returns>Dvar if found</returns>
abstract public dvar getDvar(String DvarName);
/// <summary>
/// Set a Dvar on the server
/// </summary>
/// <param name="Dvar">Name of the</param>
/// <param name="Value"></param>
abstract public void setDvar(String Dvar, String Value);
//Starts the monitoring process
/// <summary>
/// Main loop for the monitoring processes of the server ( handles events and connects/disconnects )
/// </summary>
abstract public void Monitor();
/// <summary>
/// Set up the basic variables ( base path / hostname / etc ) that allow the monitor thread to work
/// </summary>
/// <returns>True if no issues initializing, false otherwise</returns>
abstract public bool intializeBasics();
//Process any server event
/// <summary>
/// Process any server event
/// </summary>
/// <param name="E">Event</param>
/// <returns>True on sucess</returns>
abstract public bool processEvent(Event E);
/// <summary>
/// Reloads all the server configurations
/// </summary>
/// <returns>True on sucess</returns>
public bool Reload()
{
try
@ -178,56 +233,30 @@ namespace SharedLibrary
}
}
//THESE MAY NEED TO BE MOVED
/// <summary>
/// Send a message to all players
/// </summary>
/// <param name="Message">Message to be sent to all players</param>
public void Broadcast(String Message)
{
executeCommand("sayraw " + Message);
}
/// <summary>
/// Send a message to a particular players
/// </summary>
/// <param name="Message">Message to send</param>
/// <param name="Target">Player to send message to</param>
public void Tell(String Message, Player Target)
{
if (Target.clientID > -1)
executeCommand("tellraw " + Target.clientID + " " + Message + "^7");
}
public void Kick(String Message, Player Target)
{
if (Target.clientID > -1)
executeCommand("clientkick " + Target.clientID + " \"" + Message + "^7\"");
}
abstract public void Ban(String Message, Player Target, Player Origin);
abstract public bool Unban(String GUID, Player Target);
public void fastRestart(int delay)
{
Utilities.Wait(delay);
executeCommand("fast_restart");
}
public void mapRotate(int delay)
{
Utilities.Wait(delay);
executeCommand("map_rotate");
}
public void tempBan(String Message, Player Target)
{
executeCommand("tempbanclient " + Target.clientID + " \"" + Message + "\"");
}
public void mapRotate()
{
mapRotate(0);
}
public void Map(String mapName)
{
executeCommand("map " + mapName);
}
/// <summary>
/// Send a message to all admins on the server
/// </summary>
/// <param name="message">Message to send out</param>
public void ToAdmins(String message)
{
lock (players) // threading can modify list while we do this
@ -246,11 +275,89 @@ namespace SharedLibrary
}
}
/// <summary>
/// Alert a player via gsc implementation
/// </summary>
/// <param name="P"></param>
public void Alert(Player P)
{
executeCommand("admin_lastevent alert;" + P.npID + ";0;mp_killstreak_nuclearstrike");
}
/// <summary>
/// Kick a player from the server
/// </summary>
/// <param name="Reason">Reason for kicking</param>
/// <param name="Target">Player to kick</param>
public void Kick(String Reason, Player Target)
{
if (Target.clientID > -1)
executeCommand("clientkick " + Target.clientID + " \"" + Reason + "^7\"");
}
/// <summary>
/// Temporarily ban a player ( default 1 hour ) from the server
/// </summary>
/// <param name="Reason">Reason for banning the player</param>
/// <param name="Target">The player to ban</param>
public void tempBan(String Reason, Player Target)
{
executeCommand("tempbanclient " + Target.clientID + " \"" + Reason + "\"");
}
/// <summary>
/// Perm ban a player from the server
/// </summary>
/// <param name="Reason">The reason for the ban</param>
/// <param name="Target">The person to ban</param>
/// <param name="Origin">The person who banned the target</param>
abstract public void Ban(String Reason, Player Target, Player Origin);
/// <summary>
/// Unban a player by npID / GUID
/// </summary>
/// <param name="npID">npID of the player</param>
/// <param name="Target">I don't remember what this is for</param>
/// <returns></returns>
abstract public bool Unban(String npID, Player Target);
/// <summary>
/// Fast restart the server with a specified delay
/// </summary>
/// <param name="delay"></param>
public void fastRestart(int delay)
{
Utilities.Wait(delay);
executeCommand("fast_restart");
}
/// <summary>
/// Rotate the server to the next map with specified delay
/// </summary>
/// <param name="delay"></param>
public void mapRotate(int delay)
{
Utilities.Wait(delay);
executeCommand("map_rotate");
}
/// <summary>
/// Map rotate without delay
/// </summary>
public void mapRotate()
{
mapRotate(0);
}
/// <summary>
/// Change the current searver map
/// </summary>
/// <param name="mapName">Non-localized map name</param>
public void Map(String mapName)
{
executeCommand("map " + mapName);
}
public void webChat(Player P, String Message)
{
DateTime requestTime = DateTime.Now;
@ -269,8 +376,14 @@ namespace SharedLibrary
}
}
/// <summary>
/// Initalize the macro variables
/// </summary>
abstract public void initMacros();
/// <summary>
/// Read the map configuration
/// </summary>
private void initMaps()
{
maps = new List<Map>();
@ -294,6 +407,9 @@ namespace SharedLibrary
Log.Write("Maps configuration appears to be empty - skipping...", Log.Level.All);
}
/// <summary>
/// Initialize the messages to be broadcasted
/// </summary>
private void initMessages()
{
messages = new List<String>();
@ -328,6 +444,9 @@ namespace SharedLibrary
// messages.Add("^5IW4M Admin ^7is outdated. Please ^5update ^7to version " + Program.latestVersion);
}
/// <summary>
/// Initialize the rules configuration
/// </summary>
private void initRules()
{
rules = new List<String>();
@ -349,8 +468,10 @@ namespace SharedLibrary
ruleFile.Close();
}
/// <summary>
/// Load up the built in commands
/// </summary>
abstract public void initCommands();
abstract public void initAbstractObj();
//Objects
public Log Log;