示例#1
0
        public Server()
        {
            Console.Title         = "Minerva Login Server";
            Console.CursorVisible = false;

            var start = Environment.TickCount;

            Util.Info.PrintLogo();
            Console.WriteLine();

            AppDomain.CurrentDomain.UnhandledException += UnhandledException;

            Log.Start("Login"); // Start logging service

            Log.Message("Registering events...", Log.DefaultFG);
            clients = new HashSet <ClientHandler>();
            events  = new EventHandler();
            events.OnClientDisconnect += (sender, client) => { Log.Notice("Client {0} disconnected from Login Server", client.RemoteEndPoint); clients.Remove(client); };
            events.OnError            += (sender, message) => Log.Error(message);
            events.OnReceivePacket    += (sender, e) => Log.Received(e.Name, e.Opcode, e.Length);
            events.OnSendPacket       += (sender, e) => Log.Sent(e.Name, e.Opcode, e.Length);

            Log.Message("Compiling and registering scripts...", Log.DefaultFG);
            scripts = new ScriptHandler();
            scripts.Concatenate("Events", new string[] { "mscorlib" });
            scripts.Run("Events");
            scripts.CreateInstance("Events");
            var result = scripts.Invoke("_init_", events);

            try
            {
                Log.Message("Reading configuration...", Log.DefaultFG);
                Configuration.Load();

                Log.Message("Registering packets...", Log.DefaultFG);
                packets = new PacketHandler("login", new PacketProtocol().GetType(), events);

                RSA.GenerateKeyPair();

                listener = new TcpListener(Configuration.IP, Configuration.Port);
                thread   = new Thread(Listen);
                thread.Start();

                syncServer = new SyncReceiver(Configuration.MasterIP, Configuration.MasterPort);

                Log.Notice("Minerva started in: {0} seconds", (Environment.TickCount - start) / 1000.0f);
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
                #if DEBUG
                throw e;
                #endif
            }
        }
示例#2
0
        public Server()
        {
            Console.Title         = "Minerva Login Server";
            Console.CursorVisible = false;

            int start = Environment.TickCount;

            Util.Info.PrintLogo();
            Console.WriteLine();
            Util.Info.PrintInfo();
            Console.WriteLine();

            AppDomain.CurrentDomain.UnhandledException += UnhandledException;

            Log.Start("Login"); // start logging service

            clients = new HashSet <ClientHandler>();

            Log.Message("Reading configuration...", Log.DefaultFG);
            conf = new Configuration();

            Log.Message("Registering events...", Log.DefaultFG);
            events = new EventHandler();

            events.OnClientDisconnect += (sender, client) =>
            {
                Log.Notice("Client {0} disconnected from Login Server", client.RemoteEndPoint);

                // temporary disabled
                //if (client.AccountID > 0 && syncServer != null)
                //    Authentication.UpdateOnline(syncServer, client.AccountID, false);

                clients.Remove(client);
            };

            events.OnError         += (sender, message) => Log.Error(message);
            events.OnReceivePacket += (sender, e) => Log.Received(e.Name, e.Opcode, e.Length);
            events.OnSendPacket    += (sender, e) => Log.Sent(e.Name, e.Opcode, e.Length);

            events.OnIPCReceivePacket += (sender, e) => Log.IPC_Received(e.Opcode, e.Length);
            events.OnIPCSendPacket    += (sender, e) => Log.IPC_Sent(e.Opcode, e.Length);

            Log.Message("Compiling and registering scripts...", Log.DefaultFG);
            scripts = new ScriptHandler();
            scripts.Concatenate("Events", new string[] { "mscorlib" });
            scripts.Run("Events");
            scripts.CreateInstance("Events");
            scripts.Invoke("_init_", events);

            Log.Message("Registering packets...", Log.DefaultFG);
            packets = new PacketHandler("login", new PacketProtocol().GetType(), events);

            Log.Level = conf.LogLevel;

            try
            {
                listener = new TcpListener(conf.ListenIp, conf.ListenPort);
                thread   = new Thread(Listen);
                thread.Start();
                // fixme
                syncServer = new SyncReceiver(conf.MasterIp.ToString(), conf.MasterPort, events);

                Log.Notice("Debugging mode: {0}", conf.Debug ? "on" : "off");
                Log.Notice("Whitelist: {0}", conf.WhiteList ? "on" : "off");
                Log.Notice("Minerva started in: {0} seconds", (Environment.TickCount - start) / 1000.0f);
            }
            catch (Exception e)
            {
                Log.FatalError(e.Message);
                #if DEBUG
                throw e;
                #endif
            }
        }
示例#3
0
        public Server()
        {
            Console.Title         = ".:: Minerva - Cabal Online Sandbox - Login Server ::.";
            Console.CursorVisible = false;

            int start = Environment.TickCount;

            Log.Start();                // Start logging service

            clients = new HashSet <ClientHandler>();
            events  = new EventHandler();
            events.OnClientDisconnect += (sender, client) => { Log.Notice("Client {0} disconnected from Login Server", client.RemoteEndPoint); clients.Remove(client); };
            events.OnError            += (sender, message) => Log.Error(message);
            events.OnReceivePacket    += (sender, e) => Log.Received(e.Name, e.Opcode, e.Length);
            events.OnSendPacket       += (sender, e) => Log.Sent(e.Name, e.Opcode, e.Length);

            Util.Info.PrintLogo();
            Console.WriteLine();
            Util.Info.PrintInfo();
            Console.WriteLine();
            Console.ForegroundColor = Log.DefaultFG;

            Log.Message("Compiling and registering scripts...", Log.DefaultFG);
            scripts = new ScriptHandler();
            scripts.Concatenate("Events", new string[] { "mscorlib" });
            scripts.Run("Events");
            scripts.CreateInstance("Events");
            dynamic result = scripts.Invoke("_init_", events);

            try
            {
                Log.Message("Reading configuration...", Log.DefaultFG);
                Configuration.Load("Login");

                Log.Message("Registering packets...", Log.DefaultFG);
                packets = new PacketHandler("login", Configuration.Protocol, events);

                var factory = new ChannelFactory <ILoginContracts>(new NetTcpBinding(SecurityMode.None),
                                                                   new EndpointAddress(String.Format("net.tcp://{0}:9001/Login", Configuration.MasterIP)));
                proxy = factory.CreateChannel();

                var dbfactory = new ChannelFactory <IDatabaseContracts>(new NetTcpBinding(SecurityMode.None),
                                                                        new EndpointAddress(String.Format("net.tcp://{0}:9004/Database", Configuration.MasterIP)));
                database = dbfactory.CreateChannel();

                Log.Notice("Created IPC channels");

                var ads = Dns.GetHostEntry(Dns.GetHostName()).AddressList;

                foreach (var a in ads)
                {
                    if (a.AddressFamily == System.Net.Sockets.AddressFamily.InterNetworkV6)
                    {
                        continue;
                    }

                    lan = BitConverter.ToUInt32(a.GetAddressBytes(), 0);
                }

                listener = new TcpListener(IPAddress.Any, Configuration.Port);
                thread   = new Thread(Listen);
                thread.Start();

                Log.Notice("Minerva started in: {0} seconds", (float)(Environment.TickCount - start) / 1000.0f);
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
#if DEBUG
                throw e;
#endif
            }
        }