04-29-2012, 20:19
(This post was last modified: 04-29-2012, 20:21 by DidUknowiPwn.)
Forgot to include the fixed source here it is!
This for banning
This is for kicking
This for banning
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Addon;
namespace ClassLibrary1
{
public class Class1 : CPlugin
{
string file = "forbidden.txt";
List<string> fwords = new List<string>();
public override void OnServerLoad()
{
ServerPrint("BadNames Plugin By OzonE V3 -fixed by DidUknowiPwn and master131 Loaded!");
try
{
ServerPrint("Forbidden Names: ");
refreshwords();
}
catch { ServerPrint(file + " not found"); }
}
public override void OnPlayerConnect(ServerClient Client)
{
string[] cn = Client.Name.Split(' ');
foreach (string x in cn)
{
if (fwords.Contains(x))
{
ServerSay("^1Prevented connection of a ^5Badnamed player!", true);
ServerCommand("banclient " + Client.ClientNum);
}
}
}
public override ChatType OnSay(string Message, ServerClient Client)
{
string[] msg = Message.Split(' ');
try
{
if (msg[0] == "!badname" && !fwords.Contains(msg[1]))
{
string old = ReadFile(file);
WriteFile(file, old + " " + msg[1]);
TellClient(Client.ClientNum, msg[1] + " added.", true);
refreshwords();
return ChatType.ChatNone;
}
if (msg[0] == "!show")
printwords();
}
catch { ServerSay(file + " File Is Not Found", true); }
return ChatType.ChatAll;
}
void refreshwords()
{
try
{
string[] words = ReadFile(file).Split(' ');
foreach (string x in words)
{
ServerPrint(x + "\n");
fwords.Add(x);
}
}
catch { ServerPrint(file + " Not Found"); }
}
void printwords()
{
ServerSay("Forbidden Names: ", true);
foreach (string x in fwords)
{
ServerSay(x, true);
}
}
public string ReadFile(String sFilename) //
{
string sContent = "";
if (File.Exists(sFilename))
{
StreamReader myFile = new StreamReader(sFilename, System.Text.Encoding.Default);
sContent = myFile.ReadToEnd();
myFile.Close();
}
return sContent;
}
public void WriteFile(String sFilename, String sLines)
{
StreamWriter myFile = new StreamWriter(sFilename);
myFile.Write(sLines);
myFile.Close();
}
}
}
This is for kicking
Code:
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using Addon;
namespace ClassLibrary1
{
public class Class1 : CPlugin
{
string file = "forbidden.txt";
List<string> fwords = new List<string>();
public override void OnServerLoad()
{
ServerPrint("BadNames Plugin By OzonE V3 -fixed by DidUknowiPwn and master131 Loaded!");
try
{
ServerPrint("Forbidden Names: ");
refreshwords();
}
catch { ServerPrint(file + " not found"); }
}
public override void OnPlayerConnect(ServerClient Client)
{
string[] cn = Client.Name.Split(' ');
foreach (string x in cn)
{
if (fwords.Contains(x))
{
ServerSay("^1Prevented connection of a ^5Badnamed player!", true);
ServerCommand("dropclient " + Client.ClientNum);
}
}
}
public override ChatType OnSay(string Message, ServerClient Client)
{
string[] msg = Message.Split(' ');
try
{
if (msg[0] == "!badname" && !fwords.Contains(msg[1]))
{
string old = ReadFile(file);
WriteFile(file, old + " " + msg[1]);
TellClient(Client.ClientNum, msg[1] + " added.", true);
refreshwords();
return ChatType.ChatNone;
}
if (msg[0] == "!show")
printwords();
}
catch { ServerSay(file + " File Is Not Found", true); }
return ChatType.ChatAll;
}
void refreshwords()
{
try
{
string[] words = ReadFile(file).Split(' ');
foreach (string x in words)
{
ServerPrint(x + "\n");
fwords.Add(x);
}
}
catch { ServerPrint(file + " Not Found"); }
}
void printwords()
{
ServerSay("Forbidden Names: ", true);
foreach (string x in fwords)
{
ServerSay(x, true);
}
}
public string ReadFile(String sFilename) //
{
string sContent = "";
if (File.Exists(sFilename))
{
StreamReader myFile = new StreamReader(sFilename, System.Text.Encoding.Default);
sContent = myFile.ReadToEnd();
myFile.Close();
}
return sContent;
}
public void WriteFile(String sFilename, String sLines)
{
StreamWriter myFile = new StreamWriter(sFilename);
myFile.Write(sLines);
myFile.Close();
}
}
}