[Request] So that only a certain amount of people can join your server.

12/19/2008 02:15 justprownage#1
Can someone help me make it so that only a certain # of people can join my server? Is there a way to make it work for LOTF?
12/19/2008 04:11 tao4229#2
Do you mean a player cap? Or do you mean a certain number of accounts registered?
Either one isn't that hard..
12/19/2008 08:26 turk55#3
Code:
 if (World.AllChars.Count == 70)
                                        {
                                            Console.WriteLine("Server is now full last space = " + MyChar.Name);
                                            World.SendMsgToAll(MyChar.Name + " Got the last space The Server is now full", "SYSTEM", 2011);
                                        }

                                        if (World.AllChars.Count >= 71)
                                        {
                                            SendPacket(General.MyPackets.SendMsg(MessageId, "SYSTEM", MyChar.Name, "The server is full please try later", 2000));
                                            Console.WriteLine(MyChar.Name + " Attempted to login server full");
                                            MyChar.MyClient.Drop();
                                        }
EDIT : 70 players is just an example you could change that if you like to ^^
12/19/2008 08:39 felipeboladao#4
My Code To Max Players On ..

Code:
public void AuthPacketHandler(object Sender, HybridSocket Socket)
        {
            try
            {
                Socket Sock = Socket.WinSock;
                IPEndPoint IPE = (IPEndPoint)Sock.RemoteEndPoint;
                string Ip = Convert.ToString(IPE.Address);
                int Port = IPE.Port;

                byte[] Data = Socket.Packet;

                AuthBinder AB = (AuthBinder)AuthServerClients[Ip + ":" + Port];
                Client TheClient = AB.Client;

                if (Data.Length == 52)
                    TheClient.Crypto.Decrypt(ref Data);

                if (Data[0] == 0x34 && Data[1] == 0x00 && Data[2] == 0x1b && Data[3] == 0x04)
                {
                    try
                    {
                        int read = 0x04;
                        string ThisAcc = "";
                        string ThisPass = "";

                        while (read < 0x14 && Data[read] != 0x00)
                        {
                            ThisAcc += Convert.ToChar(Data[read]);
                            read += 1;
                        }
                        [COLOR="Red"]if (World.AllChars.Count <= 130)[/COLOR]

                        read = 0x14;

                        while (read < 36 && Data[read] != 0)
                        {
                            ThisPass += (Convert.ToString(Data[read], 16)).PadLeft(2, '0');
                            read += 1;
                        }

                        byte Auth = DataBase.Authenticate(ThisAcc, ThisPass);

                        if (Auth != 0)
                        {
                            General.WriteLine("Account: " + ThisAcc + " IP: " + Ip);
                            AB.Auth = Auth;
                            AB.Acc = ThisAcc;
                            AB.Client.Account = ThisAcc;

                            ulong TheKeys = (uint)(Rand.Next(0x98968) << 32);
                            TheKeys = TheKeys << 32;
                            TheKeys = (uint)(TheKeys | (uint)Rand.Next(10000000));

                            KeyClients.Add(TheKeys, AB);

                            byte[] Key1 = new byte[4];
                            byte[] Key2 = new byte[4];

                            Key1[0] = (byte)((ulong)(TheKeys & 0xff00000000000000L) >> 56);
                            Key1[1] = (byte)((TheKeys & 0xff000000000000) >> 48);
                            Key1[2] = (byte)((TheKeys & 0xff0000000000) >> 40);
                            Key1[3] = (byte)((TheKeys & 0xff00000000) >> 32);
                            Key2[0] = (byte)((TheKeys & 0xff000000) >> 24);
                            Key2[1] = (byte)((TheKeys & 0xff0000) >> 16);
                            Key2[2] = (byte)((TheKeys & 0xff00) >> 8);
                            Key2[3] = (byte)(TheKeys & 0xff);

                            try
                            {
                                byte[] Pack = MyPackets.AuthResponse(ServerIP, Key1, Key2);
                                TheClient.Crypto.Encrypt(ref Pack);
                                Sock.Send(Pack);

                                byte[] Pack1 = MyPackets.AuthResponse(ServerIP2, Key1, Key2);
                                TheClient.Crypto.Encrypt(ref Pack);
                                Sock.Send(Pack);
                            }
                            catch { }

                            Socket.Disconnect();
                            AuthServerClients.Remove(Ip + ":" + Port);
                        }
                        else
                        {
                            TheClient.SendPacket(General.MyPackets.SendMsg(TheClient.MessageId, "SYSTEM", "ALLUSERS", "Wrong username or password! Try Again!", 2101));
                            Socket.Disconnect();
                            AuthServerClients.Remove(Ip + ":" + Port);
                        }
                    }
                    catch (Exception Exc) { WriteLine(Convert.ToString(Exc)); }
                }
            }
            catch (Exception Exc) { WriteLine(Exc.ToString()); }
        }
12/19/2008 09:13 turk55#5
Quote:
Originally Posted by felipeboladao View Post
My Code To Max Players On ..

Code:
public void AuthPacketHandler(object Sender, HybridSocket Socket)
        {
            try
            {
                Socket Sock = Socket.WinSock;
                IPEndPoint IPE = (IPEndPoint)Sock.RemoteEndPoint;
                string Ip = Convert.ToString(IPE.Address);
                int Port = IPE.Port;

                byte[] Data = Socket.Packet;

                AuthBinder AB = (AuthBinder)AuthServerClients[Ip + ":" + Port];
                Client TheClient = AB.Client;

                if (Data.Length == 52)
                    TheClient.Crypto.Decrypt(ref Data);

                if (Data[0] == 0x34 && Data[1] == 0x00 && Data[2] == 0x1b && Data[3] == 0x04)
                {
                    try
                    {
                        int read = 0x04;
                        string ThisAcc = "";
                        string ThisPass = "";

                        while (read < 0x14 && Data[read] != 0x00)
                        {
                            ThisAcc += Convert.ToChar(Data[read]);
                            read += 1;
                        }
                        [COLOR="Red"]if (World.AllChars.Count <= 130)[/COLOR]

                        read = 0x14;

                        while (read < 36 && Data[read] != 0)
                        {
                            ThisPass += (Convert.ToString(Data[read], 16)).PadLeft(2, '0');
                            read += 1;
                        }

                        byte Auth = DataBase.Authenticate(ThisAcc, ThisPass);

                        if (Auth != 0)
                        {
                            General.WriteLine("Account: " + ThisAcc + " IP: " + Ip);
                            AB.Auth = Auth;
                            AB.Acc = ThisAcc;
                            AB.Client.Account = ThisAcc;

                            ulong TheKeys = (uint)(Rand.Next(0x98968) << 32);
                            TheKeys = TheKeys << 32;
                            TheKeys = (uint)(TheKeys | (uint)Rand.Next(10000000));

                            KeyClients.Add(TheKeys, AB);

                            byte[] Key1 = new byte[4];
                            byte[] Key2 = new byte[4];

                            Key1[0] = (byte)((ulong)(TheKeys & 0xff00000000000000L) >> 56);
                            Key1[1] = (byte)((TheKeys & 0xff000000000000) >> 48);
                            Key1[2] = (byte)((TheKeys & 0xff0000000000) >> 40);
                            Key1[3] = (byte)((TheKeys & 0xff00000000) >> 32);
                            Key2[0] = (byte)((TheKeys & 0xff000000) >> 24);
                            Key2[1] = (byte)((TheKeys & 0xff0000) >> 16);
                            Key2[2] = (byte)((TheKeys & 0xff00) >> 8);
                            Key2[3] = (byte)(TheKeys & 0xff);

                            try
                            {
                                byte[] Pack = MyPackets.AuthResponse(ServerIP, Key1, Key2);
                                TheClient.Crypto.Encrypt(ref Pack);
                                Sock.Send(Pack);

                                byte[] Pack1 = MyPackets.AuthResponse(ServerIP2, Key1, Key2);
                                TheClient.Crypto.Encrypt(ref Pack);
                                Sock.Send(Pack);
                            }
                            catch { }

                            Socket.Disconnect();
                            AuthServerClients.Remove(Ip + ":" + Port);
                        }
                        else
                        {
                            TheClient.SendPacket(General.MyPackets.SendMsg(TheClient.MessageId, "SYSTEM", "ALLUSERS", "Wrong username or password! Try Again!", 2101));
                            Socket.Disconnect();
                            AuthServerClients.Remove(Ip + ":" + Port);
                        }
                    }
                    catch (Exception Exc) { WriteLine(Convert.ToString(Exc)); }
                }
            }
            catch (Exception Exc) { WriteLine(Exc.ToString()); }
        }
i bet mine is less space lol
12/19/2008 10:49 _Emme_#6
I did post this in another thread, but just as turk55 got from KinshiCO source, lol. Copy+Paste ftw huh?

anyways, this is how you do it:
Search for the login text of the server, probably under Main() shit. Add a bool,
if (!World.AllChar.Count >= AMOUNT OF PLAYER)
{
Rest of the code here, e.g send packets to surrond players/you, etc etc
}

If you want the player's client to give a message before logging in, like instead of "Currupted blabla" it can say "Server is full" , I also posted that. Use search funcion.


Goodluck
12/19/2008 11:09 YukiXian#7
How to send a Error message? Like when the server is offline, You get a message that the server is undegoing a Servermaintenance or something,
12/19/2008 11:19 _Emme_#8
I posted it in a thread.
12/19/2008 12:45 YukiXian#9
Quote:
Originally Posted by EmmeTheCoder View Post
I posted it in a thread.
Where? You'f got a link?
12/19/2008 13:07 _Emme_#10
Nope, cant remember which thread, =P
12/19/2008 13:50 turk55#11
Quote:
Originally Posted by EmmeTheCoder View Post
I did post this in another thread, but just as turk55 got from KinshiCO source, lol. Copy+Paste ftw huh?

hell no i didnt got it from kinshico source, i just remembered ure treath about it >_>
i added that into the source im using now and copy+paste it then ffs....
12/19/2008 14:06 _Emme_#12
Ohh yeah, thats mine, forgot, looks simular to kinshi's one, either he took mine or I made a similuar to his. LOL!
12/19/2008 22:19 tao4229#13
Quote:
Originally Posted by YukiXian View Post
How to send a Error message? Like when the server is offline, You get a message that the server is undegoing a Servermaintenance or something,
It's a chat type, but you can only send it before the client sets location(before the client loads the map and crap).

Chattype 0x835 or 2101.(0x835 is 2101 in hex)
12/20/2008 12:42 Korvacs#14
Why do people come up with idiotic ways of doing things, in your connection class there will be an array of active connections, CAP THE ARRAY >_>
12/20/2008 15:05 tanelipe#15
They wouldn't know this because they're using infs socket system so copy+paste ftw again.