예제 #1
0
        public LoginClient(TcpClient client)
        {
            netstream = client.GetStream();
            //this.IPAddress = ((IPEndPoint)client.Client.RemoteEndPoint).Address;

            timer = new Stopwatch();

            byte[] message = new byte[4096];
            int    msgsize = 0;

            while (true)
            {
                timer.Start();
                try { msgsize = netstream.Read(message, 0, 4096); }
                catch { break; } //socket error

                if (msgsize == 0)
                {
                    break; //client disconnected
                }

                //message received
                HandlePacket(message.Take(msgsize).ToArray());
            }

            LoginServer.PlayerCount--;
            LConsole.WriteStatus("User '{0}' disconnected.", this.UserID);

            client.Close();
        }
예제 #2
0
        public LoginGSClient(TcpClient client)
        {
            LoginServer.GameServerList.Add(this);

            netstream = client.GetStream();

            byte[] message = new byte[4096];
            int    msgsize = 0;

            while (true)
            {
                try { msgsize = netstream.Read(message, 0, 4096); }
                catch { break; } //socket error

                if (msgsize == 0)
                {
                    LConsole.WriteError("Lost connection to gameserver.");
                    break; // lost connection to gameserver.
                }

                //message received
                HandlePacket(message.Take(msgsize).ToArray());
            }

            LConsole.WriteError("Lost connection to gameserver.");

            client.Close();
        }
예제 #3
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();
        }
예제 #4
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);
        }
예제 #5
0
        public void CreatePC(CLCreatePC packet)
        {
            Packet answer;

            ErrorID dbres = ErrorID.None;

            if (packet.PCType == PCType.SLAYER)
            {
                dbres = DBManager.CreatePCSlayer(packet.Name, packet.GetSex(), packet.STR, packet.DEX, packet.INT,
                                                 packet.GetHairStyle(), packet.ColorHair, packet.ColorSkin);
            }
            else if (packet.PCType == PCType.VAMPIRE)
            {
                dbres = DBManager.CreatePCVampire(packet.Name, packet.GetSex(), packet.ColorSkin);
            }
            else if (packet.PCType == PCType.OUSTER)
            {
                dbres = DBManager.CreatePCOuster(packet.Name, packet.STR, packet.DEX, packet.INT, packet.ColorHair);
            }

            if (dbres == ErrorID.None)
            {
                DBManager.AssignPCToPlayer(this.UserID, packet.Name, packet.Slot);

                answer = new LCCreatePCOK();
            }
            else
            {
                answer = new LCCreatePCError();

                ((LCCreatePCError)(answer)).ErrorID = dbres;
            }

            answer.Write(ref netstream);

            LConsole.WriteStatus("Created PC with name '{0}', race '{1}', sex '{2}' and hairstyle '{3}'", packet.Name, packet.PCType, packet.GetSex(), packet.GetHairStyle());
        }
예제 #6
0
 public void IncomingConnection(GLIncomingConnection packet)
 {
     LConsole.WriteStatus("Received GLIncomingConnection {0}:{1}", packet.UserID, packet.AuthKey);
     LoginServer.AuthPlayers.Add(packet.AuthKey, packet.UserID);
 }