Change console.cs

Aug 3, 2013 at 6:28 AM
Edited Aug 5, 2013 at 1:45 AM
how i change my console.cs to recive the username
i want put like this
[admin][system] hello
i change the code and recive this [][system] Hello
i using xna 4.0
can someone help -me
Aug 5, 2013 at 5:14 PM
Hi Lancha,

To do this you will need to make a few changes to the console.cs file, as you already worked out.

First change is to change the struct ConsoleMessage to the following
public struct ConsoleMessage
    public string Text;
    public byte Channel;
    public DateTime Time;
    public string Sender;

    public ConsoleMessage(string sender, string text, byte channel)
        this.Text = text;
        this.Channel = channel;
        this.Time = DateTime.Now;
        this.Sender = sender;
This will allow you to add a Sender string, this can be your Username

Next change the enum ConsoleMessageFormats, to the following, this will allow you to toggle use of the Sender field
public enum ConsoleMessageFormats
    None = 0x00,
    ChannelName = 0x01,
    TimeStamp = 0x02,
    Sender = 0x03,
    All = Sender | ChannelName | TimeStamp
Next add the following Property and field to the Console class
private string sender;

public string Sender
    get { return sender; }
    set { sender = value; }
Next you will need to add the following if statement to the method ClientArea_Draw

Place the if above, in between or below the current if statements, this will affect where the name appears.
if ((messageFormat & ConsoleMessageFormats.Sender) == ConsoleMessageFormats.Sender)
    pre += string.Format("[{0}]", ((ConsoleMessage)b[i]).Sender);
The final change is to add the sender to the message. This is done in the Method SendMessage

below the line: x.Handled = true;
ConsoleMessageEventArgs me = new ConsoleMessageEventArgs(new ConsoleMessage(sender, message, ch.Index));

buffer.Add(new ConsoleMessage(sender, me.Message.Text, me.Message.Channel));
You will now need to assign the Sender Property on the Console instance, to the Username.

Aug 5, 2013 at 11:51 PM
thanks but i find other hay
i create a label to recive the username and in method of send Message i put like message so for username