Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Conquer Online 2 > CO2 Private Server
You last visited: Today at 19:34

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



[Request]Organized chat.cs?

Discussion on [Request]Organized chat.cs? within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Mar 2013
Posts: 44
Received Thanks: 2
Question [Closed]Organized chat.cs?

ROFL Fixed it!..
Wasn't so hard after all xD
xScylez is offline  
Thanks
1 User
Old 03/05/2013, 12:15   #2
 
abdoumatrix's Avatar
 
elite*gold: 0
Join Date: Jul 2008
Posts: 874
Received Thanks: 238
u mean like this

abdoumatrix is offline  
Old 03/05/2013, 12:42   #3
 
_DreadNought_'s Avatar
 
elite*gold: 28
Join Date: Jun 2010
Posts: 2,226
Received Thanks: 868
Don't do == use >= for that.

That way GMs can use player commands without making a copy of the command for them.
_DreadNought_ is offline  
Old 03/05/2013, 13:04   #4
 
nTL3fTy's Avatar
 
elite*gold: 0
Join Date: Jun 2005
Posts: 692
Received Thanks: 353
You could always re-implement the way commands work, but that's probably asking too much...

Code:
[Command("test")]
public class TestCommand : CommandBase
{
    public TestCommand(GameUser user, string command)
        : base(user, command)
    {
    }

    protected override bool CanHandle { get { return !(_user.Permission < UserPermissionLevel.PM); } }

    protected override bool HandleImpl()
    {
        _user.SendSystemMsg("Congratulations! You have enough permissions to run this command.");
        return true;
    }
}
nTL3fTy is offline  
Old 03/05/2013, 15:09   #5
 
_DreadNought_'s Avatar
 
elite*gold: 28
Join Date: Jun 2010
Posts: 2,226
Received Thanks: 868
That's very similar to how public mine craft emulators do it - It's a nice way.

Nice to add a description in if you use the command incorrectly.
_DreadNought_ is offline  
Old 03/05/2013, 16:32   #6
 
elite*gold: 0
Join Date: Feb 2013
Posts: 51
Received Thanks: 22
i guess if u divided them into voids would be much organized, something like

public bool GmCommand(byte State ,string Msg)
{
if (State<PlayerStates.Gm) return false;
//your commands here
}


public bool PmCommand(byte State ,string Msg)
{
if (State<PlayerStates.Pm) return false;
//your commands here
}


public bool PlayerCommand(byte State ,string Msg)
{
//your commands here
}
EgyptianMano is offline  
Old 03/05/2013, 23:06   #7
 
abdoumatrix's Avatar
 
elite*gold: 0
Join Date: Jul 2008
Posts: 874
Received Thanks: 238
ur old one

try to adjust this as u like
abdoumatrix is offline  
Old 03/06/2013, 01:46   #8
 
elite*gold: 0
Join Date: Mar 2013
Posts: 44
Received Thanks: 2
Quote:
Originally Posted by abdoumatrix View Post
ur old one

try to adjust this as u like
ohh, yea thanks! I'll try this
xScylez is offline  
Old 03/06/2013, 02:16   #9
 
Spirited's Avatar
 
elite*gold: 12
Join Date: Jul 2011
Posts: 8,283
Received Thanks: 4,192
I would just like to point out how horrible that snippet of code is.
Code:
if (Cmd[0] == "/vp")
                            GC.LocalMessage(2000, "You have " + GC.MyChar.VP + " virtue points.");
                        if (Cmd[0] == "/map")
                            GC.LocalMessage(2000, "The ID of the map you are on is " + GC.MyChar.Loc.Map);
If you continue programming like that, you'll be executing a lot of code per command (increasing your cpu significantly more than it would be executing a command normally). Right now, you're checking if the command is "/vp", and if it is, it'll check for if the command is "/map" (and every single command you have under that) anyways. That's an issue. You need to have each command in a switch statement or at least have "else if" for every command after the first comparison.

I would also have the types of commands in different functions so if the command is found as a GM function, it will return true and not try to find the command in the PM region... Not that you two care what-so-*******-ever. You both probably don't have a clue on how to program (especially since you learn conditionals in the first week of learning programming and what you have shown above is a MAJOR mistake).

PS: You are also repeating commands, and thus the commands are going to run twice (and so on). The code above is absolutely horrible, very bugged, and very costly. I tutor people in Computer Science every day as my job and I've never seen such major errors. This community continues to amaze me.
Spirited is offline  
Old 03/06/2013, 05:30   #10
 
elite*gold: 0
Join Date: Feb 2013
Posts: 51
Received Thanks: 22
i would do it like that

Code:
public class Chat
    {
        public static void Handle(Main.GameClient GC, byte[] Data)
        {
            MemoryStream MS = new MemoryStream(Data);
            BinaryReader BR = new BinaryReader(MS);
            BR.ReadBytes(8);
            ushort ChatType = (ushort)BR.ReadUInt32();
            BR.ReadBytes(13);
            string From = Encoding.ASCII.GetString(BR.ReadBytes(BR.ReadByte()));
            string To = Encoding.ASCII.GetString(BR.ReadBytes(BR.ReadByte()));
            BR.ReadByte();
            string Message = Encoding.ASCII.GetString(BR.ReadBytes(BR.ReadByte()));
            BR.Close();
            MS.Close();
            #region BadWords
            Message = Message.Replace("damn", "****");
            Message = Message.Replace("fuck", "****");
            Message = Message.Replace("shit", "****");
            Message = Message.Replace("stupid", "******");
            Message = Message.Replace("wtf", "***");
            Message = Message.Replace("idiot", "*****");
            Message = Message.Replace("fucker", "******");
            #endregion
            if (ChatType == 2104 && GC.MyChar.MyShop != null)
                GC.MyChar.MyShop.Hawk = Message;
            try
            {
                if (Message[0] == '/')
                {
                    string[] Cmd = Message.Split(' ');
                    if (!GMCommand(GC, Cmd)) if (!PMCommand(GC, Cmd)) if (!PlayerCommand(GC, Cmd))
                                Game.World.Chat(GC.MyChar, ChatType, From, To, Message);
//you can ofcourse use the && to merge that three conditions in one statement but i prefer it like that
                }
                else
                    Game.World.Chat(GC.MyChar, ChatType, From, To, Message);
            }
            catch { }
        }
        public static bool GMCommand(Main.GameClient GC, string[] Msg)
        {
            if (GC.AuthInfo.Status != "[GM]") return false;
            switch (Msg[0])
            {
                case "/vp":
                    {
                        //do ur codes here
                        return true;
                    }
                case "/map":
                    {
                        //do ur codes here
                        return true;
                    }
            }
            return false;
        }
        public static bool PMCommand(Main.GameClient GC, string[] Msg)
        {
            if (GC.AuthInfo.Status != "[GM]" && GC.AuthInfo.Status != "[PM]") return false;
            switch (Msg[0])
            {
                case "/vp":
                    {
                        //do ur codes here
                        return true;
                    }
                case "/map":
                    {
                        //do ur codes here
                        return true;
                    }
            }
            return false;
        }
        public static bool PlayerCommand(Main.GameClient GC, string[] Msg)
        {
            switch (Msg[0])
            {
                case "/vp":
                    {
                        //do ur codes here
                        return true;
                    }
                case "/map":
                    {
                        //do ur codes here
                        return true;
                    }
            }
            return false;
        }
    }
that way u can add any commands anytime without needs to check the Gm and Pm again , just put the commands at the target bool function
EgyptianMano is offline  
Thanks
1 User
Old 03/06/2013, 05:56   #11
 
Spirited's Avatar
 
elite*gold: 12
Join Date: Jul 2011
Posts: 8,283
Received Thanks: 4,192
@EgyptianMano, yah - that's better. The only things wrong that I see with that are some very minor stylistic issues...

if (!GMCommand(GC, Cmd)) if (!PMCommand(GC, Cmd)) if (!PlayerCommand(GC, Cmd))
should be... (stylistically)
if (!PMCommand(GC, Cmd) && !GMCommand(GC, Cmd) && !PlayerCommand(GC, Cmd))

...and a few logic errors with duplicate commands. Much better. Btw, PM is better than GM. The PM is the project manager (like the administrator) and a GM is a game master (like a moderator).
Spirited is offline  
Thanks
1 User
Old 03/06/2013, 13:02   #12
 
abdoumatrix's Avatar
 
elite*gold: 0
Join Date: Jul 2008
Posts: 874
Received Thanks: 238
Quote:
Originally Posted by Fаng View Post
I would just like to point out how horrible that snippet of code is.
Code:
if (Cmd[0] == "/vp")
                            GC.LocalMessage(2000, "You have " + GC.MyChar.VP + " virtue points.");
                        if (Cmd[0] == "/map")
                            GC.LocalMessage(2000, "The ID of the map you are on is " + GC.MyChar.Loc.Map);
If you continue programming like that, you'll be executing a lot of code per command (increasing your cpu significantly more than it would be executing a command normally). Right now, you're checking if the command is "/vp", and if it is, it'll check for if the command is "/map" (and every single command you have under that) anyways. That's an issue. You need to have each command in a switch statement or at least have "else if" for every command after the first comparison.

I would also have the types of commands in different functions so if the command is found as a GM function, it will return true and not try to find the command in the PM region... Not that you two care what-so-fucking-ever. You both probably don't have a clue on how to program (especially since you learn conditionals in the first week of learning programming and what you have shown above is a MAJOR mistake).

PS: You are also repeating commands, and thus the commands are going to run twice (and so on). The code above is absolutely horrible, very bugged, and very costly. I tutor people in Computer Science every day as my job and I've never seen such major errors. This community continues to amaze me.
i just show him the (fastest)easiest way(may be isn't right)

ty for info's and advise

Quote:
Originally Posted by EgyptianMano View Post
i would do it like that

Code:
public class Chat
    {
        public static void Handle(Main.GameClient GC, byte[] Data)
        {
            MemoryStream MS = new MemoryStream(Data);
            BinaryReader BR = new BinaryReader(MS);
            BR.ReadBytes(8);
            ushort ChatType = (ushort)BR.ReadUInt32();
            BR.ReadBytes(13);
            string From = Encoding.ASCII.GetString(BR.ReadBytes(BR.ReadByte()));
            string To = Encoding.ASCII.GetString(BR.ReadBytes(BR.ReadByte()));
            BR.ReadByte();
            string Message = Encoding.ASCII.GetString(BR.ReadBytes(BR.ReadByte()));
            BR.Close();
            MS.Close();
            #region BadWords
            Message = Message.Replace("damn", "****");
            Message = Message.Replace("fuck", "****");
            Message = Message.Replace("shit", "****");
            Message = Message.Replace("stupid", "******");
            Message = Message.Replace("wtf", "***");
            Message = Message.Replace("idiot", "*****");
            Message = Message.Replace("fucker", "******");
            #endregion
            if (ChatType == 2104 && GC.MyChar.MyShop != null)
                GC.MyChar.MyShop.Hawk = Message;
            try
            {
                if (Message[0] == '/')
                {
                    string[] Cmd = Message.Split(' ');
                    if (!GMCommand(GC, Cmd)) if (!PMCommand(GC, Cmd)) if (!PlayerCommand(GC, Cmd))
                                Game.World.Chat(GC.MyChar, ChatType, From, To, Message);
//you can ofcourse use the && to merge that three conditions in one statement but i prefer it like that
                }
                else
                    Game.World.Chat(GC.MyChar, ChatType, From, To, Message);
            }
            catch { }
        }
        public static bool GMCommand(Main.GameClient GC, string[] Msg)
        {
            if (GC.AuthInfo.Status != "[GM]") return false;
            switch (Msg[0])
            {
                case "/vp":
                    {
                        //do ur codes here
                        return true;
                    }
                case "/map":
                    {
                        //do ur codes here
                        return true;
                    }
            }
            return false;
        }
        public static bool PMCommand(Main.GameClient GC, string[] Msg)
        {
            if (GC.AuthInfo.Status != "[GM]" && GC.AuthInfo.Status != "[PM]") return false;
            switch (Msg[0])
            {
                case "/vp":
                    {
                        //do ur codes here
                        return true;
                    }
                case "/map":
                    {
                        //do ur codes here
                        return true;
                    }
            }
            return false;
        }
        public static bool PlayerCommand(Main.GameClient GC, string[] Msg)
        {
            switch (Msg[0])
            {
                case "/vp":
                    {
                        //do ur codes here
                        return true;
                    }
                case "/map":
                    {
                        //do ur codes here
                        return true;
                    }
            }
            return false;
        }
    }
that way u can add any commands anytime without needs to check the Gm and Pm again , just put the commands at the target bool function
Nice job
abdoumatrix is offline  
Thanks
1 User
Old 03/06/2013, 16:05   #13
 
elite*gold: 0
Join Date: Mar 2013
Posts: 44
Received Thanks: 2
Correct me if i'm wrong:

GM and PM:

ONLY PM:

ONLY NORMAL(Or all normal, gm and pm?):

Thank you all for taking your time helping me out :-)
xScylez is offline  
Old 03/06/2013, 18:36   #14
 
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,380
Quote:
Originally Posted by xScylez View Post
Correct me if i'm wrong:

GM and PM:

ONLY PM:

ONLY NORMAL(Or all normal, gm and pm?):

Thank you all for taking your time helping me out :-)
This has always bothered me...

One cannot be 'both' a GM and a PM. PM outranked a GM and therefor already has all the permissions that a GM would have.

This is why you use a enumerated value for account permissions. Behind the scenes it's a number which you can then use simple operators on.

If you must be at least a Moderator to use a command then you do user.Permission >= PermissionType.Moderator and you can auto use the command if you're a moderator, GM or PM. It saves doing multiple checks like you're describing and has no legitimate drawbacks.

I cannot think of a single case where a higher permission account should not be able to use a lower permission command. This is why consistently naming your commands comes into play and should never pose a serious issue.
pro4never is offline  
Old 03/06/2013, 18:45   #15
 
elite*gold: 0
Join Date: Mar 2013
Posts: 44
Received Thanks: 2
Quote:
Originally Posted by pro4never View Post
This has always bothered me...

One cannot be 'both' a GM and a PM. PM outranked a GM and therefor already has all the permissions that a GM would have.

This is why you use a enumerated value for account permissions. Behind the scenes it's a number which you can then use simple operators on.

If you must be at least a Moderator to use a command then you do user.Permission >= PermissionType.Moderator and you can auto use the command if you're a moderator, GM or PM. It saves doing multiple checks like you're describing and has no legitimate drawbacks.

I cannot think of a single case where a higher permission account should not be able to use a lower permission command. This is why consistently naming your commands comes into play and should never pose a serious issue.
ohh, ok! I understand

1 More question: I have 94errors:
Code:
The name "Cmd" does not exist in the current context

Here is an example where the error comes:
Code:
case "/robot":
                    {
                        string Account = "";
                        string Name = Cmd[1];

                        if (Game.World.CharacterFromName(Name) == null)
                        {
                            Game.Robot R = Database.LoadAsRobot(Name, ref Account);
                            if (R != null)
                                R.Init(Account);
                        }
                        return true;
                    }
On the
Code:
string Name = Cmd[1];
, i have the error on "Cmd"
xScylez is offline  
Reply

Tags
.cs, 5165, chat, conquer, organized


Similar Threads Similar Threads
Get the Section organized.
07/14/2013 - Need for Speed World - 37 Replies
Hello everyone. I would like to ask you all, what do you think about getting the section divided in two; so that we could have a Main section, to discuss about the game, have general questions and so on, and a Hacks sub-section in which we can have just releases there? I have been thinking about this, to get everything even more centralized, as well, we could avoid double posts/malware/spam in general. So any comments, leave them below, and definitely, vote.
Elo boost service the best, fast and most organized
01/29/2013 - League of Legends Trading - 5 Replies
Hi, we are 3 players from 2.3 , 2.1, and 2,05k elo we are starting to boost we already boosted not for money, just a few friends it worked now they are at 1600 elo. First of all this are our prices are all negociable 0 -1250 10 € per 100 elo 1250-1400 15 € per 100 elo 1400-1600 20 € per 100 elo
(request) chat filter
12/01/2009 - GunZ - 0 Replies
i've looked all over and all i want it just the chat filter. does anyone have just the chat filter?



All times are GMT +1. The time now is 19:37.


Powered by vBulletin®
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2026 elitepvpers All Rights Reserved.