My first try on C# and I have a problem with my mw2 plugin. the OnSay function checks the things that get typed in the chat, whenever I type "/register" it tells me: "Usage: '/register [PASSWORD]'" which is what it is supposed to do, but whenever I say "/login" it gives me: "Usage: '/login [PASSWORD]'" but it also says "Invalid command" ? lolwut
here's the code:
Don't troll me if the code sucks, its my first try
here's the code:
Code:
using System;
using System.IO;
using System.Text;
using System.ComponentModel;
using System.Threading;
using APE;
using aIW;
namespace CustomPlayerData
{
public class CustomPlayerData : AdminPluginBase
{
private bool plugin_initialized = false;
private string databasePath = Directory.GetCurrentDirectory() + "/plugins/passdb.txt";
public override void OnFrame()
{
if( !plugin_initialized )
{
//AdminPluginExtended.OnConnect += new AdminPluginExtended.OnQuitConnectHandler( this._OnConnect );
if( GetDvar( "sv_admins" ) == "" || GetDvar( "sv_admins" ) == null )
ExecuteCommand( String.Format( "set \"{0}\" \"{1}\";", "sv_admins", "11000018E896AB5" ) );
Log.Info( "DEBUG: " + GetDvar("sv_admins") );
try
{
if ( !File.Exists( databasePath ) )
{
File.Create( databasePath );
string[] db_header = { "// Password database", "// Created by CustomPlayerData v0.1", "// Do not modify!" };
File.WriteAllLines( databasePath, db_header );
}
}
catch( Exception exeption )
{
Log.Info( "ERROR: COULD NOT CREATE DATABASE" );
Log.Error( "ERROR INFO: " + exeption.ToString() );
}
string[] admins = GetDvar( "sv_admins" ).Split( new char[]{ ',' } );
Log.Info( admins.Length + " admins registered" );
Log.Info( "CustomPlayerData v0.1 by iAegle" );
plugin_initialized = true;
}
}
public override EventEat OnSay( AdminClient client, string message )
{
if( message.StartsWith( "/" ) )
{
if( message.StartsWith( "/login" ) )
{
if( message.Length <= 7 )
RawSayTo( client, "Usage: '/login [PASSWORD]'" );
else
{
string password = message.Substring( 7 );
if ( IsServerAdmin( client ) && password == "skip" )
{
Log.Info( "Admin: " + client.Name + " skipped the login process" );
}
else if( password == GetClientPassword( client ) || GetClientPassword( client ) == "none" )
{
RawSayTo( client, "^2You succesfully logged in!" );
Log.Info("DEBUG: " + client.Name + " logged in with password: " + password);
}
else
{
RawSayTo( client, "^1Password is not correct!" );
Log.Info("DEBUG: " + client.Name + " entered the wrong password: " + password);
}
}
}
if( message.StartsWith( "/register" ) )
{
if ( message.Length <= 10 )
RawSayTo( client, "Usage: '/register [PASSWORD]'" );
else
{
string password = message.Substring( 10 );
using ( StreamWriter file = new StreamWriter( databasePath, true ) )
file.WriteLine( client.GUID.ToString() + "," + password );
Log.Info("DEBUG: " + "Player " + client.Name + " registered with xuid: " + client.GUID.ToString());
}
}
else
{
RawSayTo( client, "^1Invalid command" );
}
return EventEat.EatGame;
}
return EventEat.EatNone;
}
public string GetClientPassword( AdminClient client )
{
foreach( string line in File.ReadAllLines( databasePath ) )
if( !line.StartsWith( "//" ) )
if( line.Split( new char[] { ',' } )[0] == client.GUID.ToString() )
return line.Split( new char[] { ',' } )[1];
return "none";
}
public bool IsServerAdmin( AdminClient client )
{
if ( GetDvar("sv_admins") == "" || GetDvar("sv_admins") == null )
return false;
if ( GetDvar( "sv_admins" ).Contains( "," ) )
{
string[] admins = GetDvar("sv_admins").Split( new char[] { ',' } );
foreach ( string admin in admins )
if ( admin.ToLower() == client.GUID.ToString().ToLower() )
return true;
}
else
if ( GetDvar("sv_admins") == client.GUID.ToString() )
return true;
return false;
}
}
}Don't troll me if the code sucks, its my first try
(08-10-2011, 12:58)Pozzuh Wrote:Se7en Wrote:Stealed, from cod4 mod ...look who's talking
[Release] Old School Mod v2.2
[Release] Scroll menu

