The online racing simulator
#1 - ab12
Insim.NET - kick command
Good morning. I want to add kick command in my insim but I have a little problem. The command is: !kick username reason.The command work but don't write the reason in chat.
Any help please? Smile

if (MSO.UserType == UserType.MSO_PREFIX) {

var Conn = Connections[GetConnIdx(MSO.UCID)];
string Text = MSO.Msg.Substring(MSO.TextStart, (MSO.Msg.Length - MSO.TextStart));
string[] command = Text.Split(' ');
command[0] = command[0].ToLower();

switch(command[0]) {

case "!kick":
{
string Username = Text.Remove(0, command[0].Length + command[1].Length + 2);
insim.Send("^1----------Kick----------");
insim.Send(Conn.Playername + " ^8(" + command[0] + ") ^1was kicked!");
insim.Send("^1Reason: " + command[1]);
insim.Send("^1------------------------");
}
break; }}

Input: !kick ab12 is AFK for long time

Output: ----------Kick----------
Ali (ab12) was kicked!
Reason: is
------------------------

It's simple. You're splitting the text by every space.

That means that "!kick username reason" will become:
command[0] = !kick
command[1] = username
command[2] = reason

Learn how to use a simple array and its indexes.

However, you're gonna have a problem when you're filling in usernames that have spaces in them. Smile

edit: Why would you use Conn.playername in the line to show who was kicked? It clearly says in a few lines above that Conn is the connection who typed the message, and not the one that was kicked.
#3 - ab12
Quote from Bose321 : It clearly says in a few lines above that Conn is the connection who typed the message, and not the one that was kicked.

I tested it only on me and of course works perfect because i typed and insim showed me my name xD
But how i can know who was kicked and no who typed the message ?
Quote from ab12 :
But how i can know who was kicked and no who typed the message ?

But you already printed out the kick`ees username? Do you want to find the user's screen name and not their user name?

As Bose points out, this is probably not a very good solution as any user with a name that contains a space in it would either break everything or cause something else funny. You would be much better off searching your connection list for an exact match that the kick-command contains. If you have ever heard of pattern matching or regular expressions, this would be the place to employ them.

How about the admin-side of things? Do you want to specifically limit your admin to use usernames and not screen names? How about the following: When a kick command comes in
  1. Go through your connection list entry by entry
  2. Compare each connection's Playername or username to the content of the kick command
  3. If they match remove the matching playername from the kick command string
  4. Kick the player in question
#5 - ab12
Can you be more explicit, please? I'm not English and I don't understand very well Shrug

FGED GREDG RDFGDR GSFDG