Beispiel #1
0
        public static void Initialize(IPAddress ip, int port)
        {
            IPAddressLogin = ip;

            AuthPlayers = new Dictionary <int, string>();

            // Initialize TCPListener
            tcpListener = new TcpListener(ip, port);
            tcpListener.Start();

            // Initialize Worlds
            WorldInfoList = DBManager.GetWorldInfoList();
            LConsole.WriteStatus("Initializing {0} worlds.", WorldInfoList.Count);

            // Initialize ServerGroups
            GameServerList = new List <LoginGSClient>();

            foreach (WorldInfo w in WorldInfoList)
            {
                w.ServerGroupInfoList = DBManager.GetServerGroupInfoList(w.ID);

                LConsole.WriteStatus("Initializing world '{0}' with {1} server groups.", w.Name, w.ServerGroupInfoList.Count);
                LConsole.WriteStatus("Waiting for GameServer at '{0}'", w.IPAddress);

                bool loop = true;

                while (loop)
                {
                    TcpClient tcp = tcpListener.AcceptTcpClient();

                    IPEndPoint endpoint = (tcp.Client.RemoteEndPoint as IPEndPoint);

                    if (endpoint.Address.ToString() == w.IPAddress)
                    {
                        Thread gsClient = new Thread(new ParameterizedThreadStart(HandleGSClient));
                        gsClient.Start(tcp);

                        loop = false;
                    }
                    else
                    {
                        LConsole.WriteWarning("Refusing connection from {0}:{1}, waiting for gameserver.", endpoint.Address, endpoint.Port);
                    }
                }

                LConsole.WriteStatus("Initialized world '{0}'", w.Name);
            }

            tListen = new Thread(new ThreadStart(ListenClients));
            tListen.Start();
        }
Beispiel #2
0
        public void Login(CLLogin packet)
        {
            Packet answer;

            int result = DBManager.CheckPlayerLogin(packet.UserID, packet.Password);

            if (result == 0) // LoginOK
            {
                answer = new LCLoginOK();

                answer.Write(ref netstream);

                LConsole.WriteStatus("User '{0}' logged in ", packet.UserID);

                this.UserID = packet.UserID;
            }
            else
            {
                answer = new LCLoginError();

                if (result == 1) // Wrong UserID or Password
                {
                    ((LCLoginError)answer).ErrorID = ErrorID.WrongUserOrPassword;

                    LConsole.WriteWarning("User '{0}' failed to log in with password '{1}'", packet.UserID, packet.Password);

                    answer.Write(ref netstream);
                }
                else if (result == 2) // Access Denied
                {
                    ((LCLoginError)answer).ErrorID = ErrorID.AccessDenied;

                    LConsole.WriteWarning("Banned user '{0}' tried to log in but was rejected.", packet.ID);
                }
            }

            answer.Write(ref netstream);
        }