Why does it display teh stuff?
#1
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:
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 Smile
(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

Reply

#2
The 'invalid' command is because you don't actually add the command to the game itself (mostly known as CMD_AddCommand) and does not recognize it. Yet the way your plugin handles the command it *should* seem to work correctly.

Ever thought of just intercepting the print to console? Don't know if it's possible though with the current 'sdk' you are using.



Oh how this...unoptimized code kills me
[Image: b_560_95_1.png]
Reply

#3
Fixed.
(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

Reply



Possibly Related Threads…
Thread Author Replies Views Last Post
  Infected Stuff is semi broken DidUknowiPwn 2 5,050 09-21-2013, 20:22
Last Post: surtek
  Help My Server Doesn't Display DarkyPwnz 2 3,988 06-16-2013, 17:25
Last Post: DarkyPwnz
Photo Help color blue(display) [HARD] Tony. 2 3,499 04-06-2013, 14:16
Last Post: Nekochan
  Your favorite stuff Nekochan 19 12,640 01-18-2013, 08:48
Last Post: AZUMIKKEL
  Help Easiest Way To Thread a Display Icon? DidUknowiPwn 1 3,374 01-04-2013, 13:02
Last Post: Yamato
  te gusta o no? (gaming stuff) Arteq 10 7,809 10-24-2012, 08:57
Last Post: d0h!
  [Request] Defferent text display for clan members and others islamsaab 7 5,726 09-20-2012, 20:22
Last Post: DidUknowiPwn
  [News] Black ops 2 Interesting stuff kokole 4 4,348 05-03-2012, 11:13
Last Post: surtek
Music JariZ's music stuff JariZ 2 4,370 05-02-2012, 11:52
Last Post: Arteq
  Never Finished Stuff 4FunPlayin 9 7,312 04-10-2012, 21:31
Last Post: 4FunPlayin

Forum Jump:


Users browsing this thread:
1 Guest(s)

Forum Powered By MyBB, Theme by © 2002-2026 Melroy van den Berg.