示例#1
0
        private void Client_OnPacketArrived(ServerClient sender, IDeserializedPacket packet)
        {
            if (packet is AuthenticateServerPacket)
            {
                var authPacket = (AuthenticateServerPacket)packet;
                (sender as ISClient).SetWordServerInfo(authPacket.WorldServerInfo);
            }

            // World serber requests keys of loginc client.
            if (packet is AesKeyRequestPacket)
            {
                var aesRequestPacket = (AesKeyRequestPacket)packet;
                LoginClients.TryGetValue(aesRequestPacket.Guid, out var loginClient);
                ISPacketFactory.SendAuthentication(sender, loginClient);

                // Remove login client as soon as it's sent. We don't need it anymore.
                LoginClients.TryRemove(loginClient.Id, out var removed);
            }
        }
示例#2
0
        private static void Main(string[] args)
        {
            if (args.Length == 1 && args[0].ToLower() == "setup" || !File.Exists(Application.ExecutablePath + "WvsLogin.ini"))
            {
                WvsLoginSetup.Run();
            }

            Worlds  = new Worlds();
            Clients = new LoginClients();

            Log.Entitle("Destiny - Login Server v.{0}.{1}", Application.MapleVersion, Application.PatchVersion);

            try
            {
                Settings.Initialize(Application.ExecutablePath + "WvsLogin.ini");

                Database.Test();
                Database.Analyze(false);

                RequireStaffIP = Settings.GetBool("Server/RequireStaffIP");
                Log.Inform("Staff will{0}be required to connect through a staff IP.", RequireStaffIP ? " " : " not ");

                AutoRegister = Settings.GetBool("Server/AutoRegister");
                Log.Inform("Automatic registration {0}.", AutoRegister ? "enabled" : "disabled");

                RequestPin = Settings.GetBool("Server/RequestPin");
                Log.Inform("Pin will{0}be requested upon login.", RequestPin ? " " : " not ");

                RequestPic = Settings.GetBool("Server/RequestPic");
                Log.Inform("Pic will{0}be requested upon character selection.", RequestPic ? " " : " not ");

                MaxCharacters = Settings.GetInt("Server/MaxCharacters");
                Log.Inform("Maximum of {0} characters per account.", MaxCharacters);

                for (byte i = 0; i < Settings.GetByte("Server/Worlds"); i++)
                {
                    Worlds.Add(new World(i));
                }

                isAlive = true;
            }
            catch (Exception e)
            {
                Log.Error(e);
            }

            if (IsAlive)
            {
                CenterConnectionDone.Reset();

                new Thread(new ThreadStart(LoginToCenterServer.Main)).Start();

                CenterConnectionDone.WaitOne();
            }
            else
            {
                Log.SkipLine();
                Log.Inform("Could not start server because of errors.");
            }

            while (IsAlive)
            {
                AcceptDone.Reset();
                Listener.BeginAcceptSocket(new AsyncCallback(OnAcceptSocket), null);
                AcceptDone.WaitOne();
            }

            foreach (LoginClient client in Clients)
            {
                client.Stop();
            }

            Dispose();

            Log.SkipLine();
            Log.Warn("Server stopped.");

            Console.Read();
        }