[Question]Ban for 5165

02/19/2010 17:29 copz1337#1
I've been thinking of making a ban command for my 5165 server but I don't know where I should put the code (not the command but the actual function code). So if anyone knows, step up blez.
02/19/2010 22:02 Arcо#2
Quote:
Originally Posted by copz1337 View Post
I've been thinking of making a ban command for my 5165 server but I don't know where I should put the code (not the command but the actual function code). So if anyone knows, step up blez.
Try making a definition in character.cs and then adding it to the save/load/create char sequences.
Code:
public byte Ban = 0;
Then make a command somewhat like this:
Code:
                    if (Cmd[0] == "/ban")
                    {
                        Game.Character C = Game.World.CharacterFromName(Cmd[1]);
                        if (C != null)
                            C.Ban += 1;
                    }
Then go to the load char sequence and under C.Loaded = true;
put something like if (C.Ban >0) C.Disconnect;
get it?
02/19/2010 22:32 copz1337#3
kk i'll try
02/19/2010 22:41 LetterX#4
Quote:
Originally Posted by .Arco View Post
Try making a definition in character.cs and then adding it to the save/load/create char sequences.
Code:
public byte Ban = 0;
Then make a command somewhat like this:
Code:
                    if (Cmd[0] == "/ban")
                    {
                        Game.Character C = Game.World.CharacterFromName(Cmd[1]);
                        if (C != null)
                            C.Ban += 1;
                    }
Then go to the load char sequence and under C.Loaded = true;
put something like if (C.Ban >0) C.Disconnect;
get it?
Or, to be more efficient, only add the "Ban=" (or whatever) string in the Character file once you use "/ban <name>". And then let the Auth thread check if the character is banned when it is checking acc/pass. More efficient than the auth okaying acc and then game loads all the stats and then finally reads that and then has to end the client's connection. X.x
02/19/2010 22:43 Arcо#5
Quote:
Originally Posted by LetterX View Post
Or, to be more efficient, only add the "Ban=" (or whatever) string in the Character file once you use "/ban <name>". And then let the Auth thread check if the character is banned when it is checking acc/pass. More efficient than the auth okaying acc and then game loads all the stats and then finally reads that and then ends the client connection. X.x
Gotta point :/
Didn't really think of that.
02/19/2010 22:51 copz1337#6
k confused @ this now
02/19/2010 23:21 ramix#7
me too xD
02/20/2010 00:33 Korvacs#8
LetterX is quite rightly saying that if you modified AuthWorker.cs, specifically:

Code:
                        if (Info.LogonType != 255)
                        {

                            byte[] IV = new byte[8];
                            for (int i = 0; i < 8; i++)
                                IV[i] = (byte)Rnd.Next(255);

                            KeyedClients.Add(BitConverter.ToUInt64(IV, 0), Info);


                            AC.Send(Packets.SendAuthentication(GameIP, IV));
                            //AC.Disconnect();
                        }
                        else
                        {
                            AC.Send(Packets.WrongAuth());
                            //AC.Disconnect();
                        }
Then you could do this for example:

Code:
                        if (Info.LogonType != 255)
                        {
                            if (Info.LogonType == 3)//Banned
                            {
                                AC.Send(Packets.BannedAuth());//Example!
                                AC.Disconnect();
                            }
                            byte[] IV = new byte[8];
                            for (int i = 0; i < 8; i++)
                                IV[i] = (byte)Rnd.Next(255);

                            KeyedClients.Add(BitConverter.ToUInt64(IV, 0), Info);


                            AC.Send(Packets.SendAuthentication(GameIP, IV));
                            //AC.Disconnect();
                        }
                        else
                        {
                            AC.Send(Packets.WrongAuth());
                            //AC.Disconnect();
                        }
This would require modifiying the layout of the .usr files to incorporate a bool (banned/not banned), and modifying the database backend so that durring authorization:

Code:
                        AuthInfo Info = Database.Authenticate(Account, Password);
The server would check this bool and return 3 for the LogonType if banned.
02/20/2010 02:11 spare2#9
Okay, make sure you following the directions below step by step and carefully.
First go to Database.cs and put the following code inside the Database class.
Code:
        public static bool CheckBan(string Name)
        {
            if (File.Exists(@"C:\OldCODB\banname.txt"))
            {
                TextReader tr = new StreamReader(@"C:\OldCODB\banname.txt");//You can change to where ever your OldCODB is
                string name;
                while ((name = tr.ReadLine()) != null)
                {
                    if (name == Name)
                    {
                        return true;
                    }
                }
                tr.Close();
            }
            return false;
        }
        public static void AddBan(string Name)
        {
            if (!CheckBan(Name))
            {
                TextWriter tw = new StreamWriter(@"C:\OldCODB\banname.txt");//You can change to where ever your OldCODB is
                tw.WriteLine(Name);
                tw.Close();
            }

        }
Then find the following line in your project:
Code:
GC.Soc = StO.Sock;
And put this code under it:
Code:
                                if (GC.AuthInfo.LogonType == 3)
                                {
                                    GC.AddSend(Packets.SystemMessage(GC.MessageID, "You are banned!"));
                                }
Then find
Code:
public bool Ghost = false;
Put this below it
Code:
public string AccountName;
Next, find
Code:
if (Game.World.H_Chars.Contains(GC.MyChar.EntityID))
And place this above it
Code:
GC.MyChar.AccountName = Acc;
Then find the following line (make sure you don't use the one that's commented)
Code:
Info.LogonType = 1;
Place this under
Code:
                        if (CheckBan(RealAccount))
                            Info.LogonType = 3;
Finally place this command in the chat commands
Code:
                        if (Cmd[0] == "/ban")
                        {
                            Game.Character C = Game.World.CharacterFromName(Cmd[1]);
                            if (C != null)
                                Database.AddBan(C.AccountName);
                                C.MyClient.Disconnect();
                        }
I have tested it personally.
02/20/2010 02:14 Korvacs#10
You forgot to use your CheckBan method spare =o
02/20/2010 02:16 PeTe Ninja#11
he used once in the AddBan function
02/20/2010 02:18 spare2#12
Yea I forgot to put it in the post, I edited it now. Thanks Korvacs.
02/20/2010 02:32 copz1337#13
alright how do i unban then
02/20/2010 02:33 Arcо#14
Quote:
Originally Posted by copz1337 View Post
alright how do i unban then
Delete them from the text file.
02/20/2010 02:35 spare2#15
Quote:
Originally Posted by copz1337 View Post
alright how do i unban then
Find the person's account name and delete that entire line.