mirror of
https://github.com/RaidMax/IW4M-Admin.git
synced 2025-06-30 17:10:20 -05:00
Kayak works how I want it :) 'secure' authentication
This commit is contained in:
268
Stats Plugin/Main.cs
Normal file
268
Stats Plugin/Main.cs
Normal file
@ -0,0 +1,268 @@
|
||||
using System;
|
||||
using SharedLibrary;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
|
||||
namespace SamplePlugin
|
||||
{
|
||||
#if SAMPLE_CODE
|
||||
public class SampleCommand : Command
|
||||
{
|
||||
public SampleCommand() : base("testplugin", "sample plugin command. syntax !testplugin", "tp", Player.Permission.User, 0, false) { }
|
||||
|
||||
public override void Execute(Event E)
|
||||
{
|
||||
Player clientWhoSent = E.Origin;
|
||||
Server originatingServer = E.Owner;
|
||||
|
||||
String[] messageToClient = {
|
||||
String.Format("The command {0} was requested by ^3{1}", Name, clientWhoSent.Name),
|
||||
String.Format("The command was request on server ^1{0}", originatingServer.getName())
|
||||
};
|
||||
|
||||
foreach (String Line in messageToClient)
|
||||
clientWhoSent.Tell(Line);
|
||||
}
|
||||
}
|
||||
|
||||
public class AnotherSampleCommand : Command
|
||||
{
|
||||
public AnotherSampleCommand() : base("scream", "broadcast your message. syntax !scream <message>", "s", Player.Permission.Moderator, 1, false) { }
|
||||
|
||||
public override void Execute(Event E)
|
||||
{
|
||||
Server originatingServer = E.Owner;
|
||||
String Message = E.Data;
|
||||
String Sender = E.Origin.Name;
|
||||
|
||||
for (int i = 0; i < 10; i++)
|
||||
originatingServer.Broadcast(String.Format("^7{0}: ^{1}{2}^7", Sender, i, Message));
|
||||
|
||||
originatingServer.Log.Write("This line is coming from the plugin " + this.Name, Log.Level.Production);
|
||||
}
|
||||
}
|
||||
|
||||
public class SampleEvent : EventNotify
|
||||
{
|
||||
public override void onLoad()
|
||||
{
|
||||
Console.WriteLine("The sample event plugin was loaded!");
|
||||
}
|
||||
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() { }
|
||||
}
|
||||
#endif
|
||||
|
||||
public class StatCommand : Command
|
||||
{
|
||||
public StatCommand() : base("stats", "view your stats. syntax !stats", "xlrstats", Player.Permission.User, 0, false) { }
|
||||
|
||||
public override void Execute(Event E)
|
||||
{
|
||||
PlayerStats pStats = Stats.playerStats.getStats(E.Origin);
|
||||
String statLine = String.Format("^5{0} ^7KILLS | ^5{1} ^7DEATHS | ^5{2} ^7KDR | ^5{3} ^7SKILL", pStats.Kills, pStats.Deaths, pStats.KDR, pStats.Skill);
|
||||
E.Origin.Tell(statLine);
|
||||
}
|
||||
}
|
||||
|
||||
public class Stats : Plugin
|
||||
{
|
||||
public static StatsDB playerStats { get; private set; }
|
||||
|
||||
public override void onEvent(Event E)
|
||||
{
|
||||
if (E.Type == Event.GType.Kill)
|
||||
{
|
||||
Player Killer = E.Origin;
|
||||
PlayerStats killerStats = playerStats.getStats(Killer);
|
||||
|
||||
if (Killer != E.Target)
|
||||
{
|
||||
killerStats.Kills++;
|
||||
|
||||
if (killerStats.Deaths == 0)
|
||||
killerStats.KDR = killerStats.Kills;
|
||||
else
|
||||
killerStats.KDR = killerStats.Kills / killerStats.Deaths;
|
||||
|
||||
playerStats.updateStats(Killer, killerStats);
|
||||
|
||||
killerStats.killStreak++;
|
||||
killerStats.deathStreak = 0;
|
||||
}
|
||||
|
||||
Killer.Tell(messageOnStreak(killerStats.killStreak, killerStats.deathStreak));
|
||||
}
|
||||
|
||||
if (E.Type == Event.GType.Death)
|
||||
{
|
||||
Player Victim = E.Origin;
|
||||
PlayerStats victimStats = playerStats.getStats(Victim);
|
||||
|
||||
victimStats.Deaths++;
|
||||
victimStats.KDR = victimStats.Kills / victimStats.Deaths;
|
||||
|
||||
playerStats.updateStats(Victim, victimStats);
|
||||
|
||||
victimStats.deathStreak++;
|
||||
victimStats.killStreak = 0;
|
||||
|
||||
Victim.Tell(messageOnStreak(victimStats.killStreak, victimStats.deathStreak));
|
||||
}
|
||||
}
|
||||
|
||||
public override void onLoad()
|
||||
{
|
||||
playerStats = new StatsDB("stats.rm");
|
||||
}
|
||||
|
||||
public override void onUnload()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private String messageOnStreak(int killStreak, int deathStreak)
|
||||
{
|
||||
String Message = "";
|
||||
switch (killStreak)
|
||||
{
|
||||
case 5:
|
||||
Message = "Great job! You're on a ^55 killstreak!";
|
||||
break;
|
||||
case 10:
|
||||
Message = "Amazing! ^510 ^7kills without dying!";
|
||||
break;
|
||||
}
|
||||
|
||||
switch (deathStreak)
|
||||
{
|
||||
case 5:
|
||||
Message = "Pick it up soldier, you've died 5 times in a row...";
|
||||
break;
|
||||
case 10:
|
||||
Message = "Seriously? ^510 ^7deaths without getting a kill?";
|
||||
break;
|
||||
}
|
||||
|
||||
return Message;
|
||||
}
|
||||
|
||||
public override string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Basic Stats";
|
||||
}
|
||||
}
|
||||
|
||||
public override float Version
|
||||
{
|
||||
get
|
||||
{
|
||||
return 0.1f;
|
||||
}
|
||||
}
|
||||
|
||||
public override string Author
|
||||
{
|
||||
get
|
||||
{
|
||||
return "RaidMax";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class StatsDB : Database
|
||||
{
|
||||
public StatsDB(String FN) : base(FN) { }
|
||||
|
||||
public override void Init()
|
||||
{
|
||||
if (!File.Exists(FileName))
|
||||
{
|
||||
String Create = "CREATE TABLE [STATS] ( [npID] TEXT, [KILLS] INTEGER DEFAULT 0, [DEATHS] INTEGER DEFAULT 0, [KDR] REAL DEFAULT 0, [SKILL] REAL DEFAULT 0, [MEAN] REAL DEFAULT 0, [DEV] REAL DEFAULT 0 );";
|
||||
ExecuteNonQuery(Create);
|
||||
}
|
||||
}
|
||||
|
||||
public void addPlayer(Player P)
|
||||
{
|
||||
Dictionary<String, object> newPlayer = new Dictionary<String, object>();
|
||||
|
||||
newPlayer.Add("npID", P.npID);
|
||||
newPlayer.Add("KILLS", 0);
|
||||
newPlayer.Add("DEATHS", 0);
|
||||
newPlayer.Add("KDR", 0);
|
||||
newPlayer.Add("SKILL", 0);
|
||||
|
||||
Insert("STATS", newPlayer);
|
||||
}
|
||||
|
||||
public PlayerStats getStats(Player P)
|
||||
{
|
||||
String Query = String.Format("SELECT * FROM STATS WHERE npID = '{0}'", P.npID);
|
||||
DataTable Result = GetDataTable(Query);
|
||||
|
||||
if (Result != null && Result.Rows.Count > 0)
|
||||
{
|
||||
DataRow ResponseRow = Result.Rows[0];
|
||||
return new PlayerStats(
|
||||
Convert.ToInt32(ResponseRow["KILLS"]),
|
||||
Convert.ToInt32(ResponseRow["DEATHS"]),
|
||||
Convert.ToDouble(ResponseRow["KDR"]),
|
||||
Convert.ToDouble(ResponseRow["SKILL"])
|
||||
);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
addPlayer(P);
|
||||
return getStats(P);
|
||||
}
|
||||
}
|
||||
|
||||
public void updateStats(Player P, PlayerStats S)
|
||||
{
|
||||
Dictionary<String, object> updatedPlayer = new Dictionary<String, object>();
|
||||
|
||||
updatedPlayer.Add("KILLS", S.Kills);
|
||||
updatedPlayer.Add("DEATHS", S.Deaths);
|
||||
updatedPlayer.Add("KDR", Math.Round(S.KDR, 2));
|
||||
updatedPlayer.Add("SKILL", S.Skill);
|
||||
|
||||
Update("STATS", updatedPlayer, String.Format("npID = '{0}'", P.npID));
|
||||
}
|
||||
}
|
||||
|
||||
public struct PlayerStats
|
||||
{
|
||||
public PlayerStats(int K, int D, double DR, double S)
|
||||
{
|
||||
Kills = K;
|
||||
Deaths = D;
|
||||
KDR = DR;
|
||||
Skill = S;
|
||||
deathStreak = 0;
|
||||
killStreak = 0;
|
||||
}
|
||||
|
||||
public int Kills;
|
||||
public int Deaths;
|
||||
public double KDR;
|
||||
public double Skill;
|
||||
public int deathStreak;
|
||||
public int killStreak;
|
||||
}
|
||||
}
|
36
Stats Plugin/Properties/AssemblyInfo.cs
Normal file
36
Stats Plugin/Properties/AssemblyInfo.cs
Normal file
@ -0,0 +1,36 @@
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
// General Information about an assembly is controlled through the following
|
||||
// set of attributes. Change these attribute values to modify the information
|
||||
// associated with an assembly.
|
||||
[assembly: AssemblyTitle("SamplePlugin")]
|
||||
[assembly: AssemblyDescription("")]
|
||||
[assembly: AssemblyConfiguration("")]
|
||||
[assembly: AssemblyCompany("")]
|
||||
[assembly: AssemblyProduct("SamplePlugin")]
|
||||
[assembly: AssemblyCopyright("Copyright © 2015")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
|
||||
// Setting ComVisible to false makes the types in this assembly not visible
|
||||
// to COM components. If you need to access a type in this assembly from
|
||||
// COM, set the ComVisible attribute to true on that type.
|
||||
[assembly: ComVisible(false)]
|
||||
|
||||
// The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
[assembly: Guid("1d848d36-bf25-4bc0-acdd-67db2d014d45")]
|
||||
|
||||
// Version information for an assembly consists of the following four values:
|
||||
//
|
||||
// Major Version
|
||||
// Minor Version
|
||||
// Build Number
|
||||
// Revision
|
||||
//
|
||||
// You can specify all the values or you can default the Build and Revision Numbers
|
||||
// by using the '*' as shown below:
|
||||
// [assembly: AssemblyVersion("1.0.*")]
|
||||
[assembly: AssemblyVersion("1.0.0.0")]
|
||||
[assembly: AssemblyFileVersion("1.0.0.0")]
|
59
Stats Plugin/Stats Plugin.csproj
Normal file
59
Stats Plugin/Stats Plugin.csproj
Normal file
@ -0,0 +1,59 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectGuid>{4785AB75-66F3-4391-985D-63A5A049A0FA}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SamplePlugin</RootNamespace>
|
||||
<AssemblyName>SamplePlugin</AssemblyName>
|
||||
<TargetFrameworkVersion>v4.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="SharedLibary">
|
||||
<HintPath>..\SharedLibary\bin\Release\SharedLibary.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
<Reference Include="System.Data.DataSetExtensions" />
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Main.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<PropertyGroup>
|
||||
<PostBuildEvent>copy /Y "$(TargetDir)$(TargetName).dll" "$(SolutionDir)Admin\plugins\SimpleStatsPlugin.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">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
Reference in New Issue
Block a user