예제 #1
0
파일: Server.cs 프로젝트: lKnuckles/minerva
        public Server(int server, int channel)
        {
            this.server  = server;
            this.channel = channel;

            Console.Title         = "Minerva Channel Server";
            Console.CursorVisible = false;

            int start = Environment.TickCount;

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

            AppDomain.CurrentDomain.UnhandledException += UnhandledException;


            Log.Start(string.Format("Channel_{0}_{1}", server, channel));    // Start logging service

            clients = new Dictionary <ulong, ClientHandler>();
            events  = new EventHandler();
            events.OnClientDisconnect += (sender, client) => { Log.Notice("Client {0} disconnected from Channel Server", client.RemoteEndPoint); clients.Remove((ulong)client.Metadata["magic"]); };
            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.OnWarp             += (sender, client, map, x, y) => { client.Metadata["map"] = maps[map]; maps[map].MoveClient(client, x / 16, y / 16); maps[map].UpdateCells(client); };

            /*Console.WriteLine("Compiling and registering scripts...");
             * 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(String.Format("Channel_{0}_{1}", server, channel)); Ported to Global.Global.Config)
                Global.Config.LoadChannel(server, channel);

                mapLoader = new MapLoader();
                maps      = mapLoader.LoadMaps();

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

                //listener = new TcpListener(System.Net.IPAddress.Any, Configuration.Port); Ported to Global.Global.Config
                listener = new TcpListener(System.Net.IPAddress.Any, Global.Config.getChannelPort(server, channel));
                thread   = new Thread(Listen);
                thread.Start();

                //syncServer = new SyncReceiver(Configuration.MasterIP, Configuration.MasterPort); Ported to Global.Global.Config
                syncServer = new SyncReceiver(Global.Config.MasterIP.ToString(), Global.Config.MasterPort);
                syncServer.OnSyncSuccess += (sender, e) =>
                {
                    //var aa = Configuration.IP.GetAddressBytes(); Ported to Global.Global.Config
                    var aa      = Global.Config.IP.GetAddressBytes();
                    var address = BitConverter.ToUInt32(aa, 0);
                    //Authentication.RegisterChannel(syncServer, server, channel, 0, address, Configuration.Port, 100); Ported to Global.Global.Config
                    Authentication.RegisterChannel(syncServer, server, channel, 0, address, Global.Config.getChannelPort(server, channel), 100);
                };

                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(int server, int channel)
        {
            this.server  = server;
            this.channel = channel;

            Console.Title         = "Minerva Channel Server";
            Console.CursorVisible = false;

            int start = Environment.TickCount;

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

            AppDomain.CurrentDomain.UnhandledException += UnhandledException;

            Configuration.Load(string.Format("Channel_{0}_{1}", server, channel));
            Log.Start(string.Format("Channel_{0}_{1}", server, channel), Configuration.channelLog, Configuration.channelLogLvl);    // Start logging service

            clients = new Dictionary <ulong, ClientHandler>();
            events  = new EventHandler();

            events.OnClientDisconnect += (sender, client) => {
                if (client.RemoteEndPoint != null)
                {
                    Log.Notice("Client {0} disconnected from Channel Server", client.RemoteEndPoint);
                    if (client.AccountID > 0 && syncServer != null)
                    {
                        Authentication.UpdateOnline(syncServer, client.AccountID, false);
                    }
                    clients.Remove((ulong)client.Metadata["magic"]);
                }
            };

            events.OnError         += (sender, message) => { Log.Error(message, "[Channel::Server::" + sender.GetType() + "()]"); };
            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.OnWarp          += (sender, client, map, x, y) => { client.Metadata["map"] = maps[map]; maps[map].MoveClient(client, x / 16, y / 16); maps[map].UpdateCells(client); };

            /*Console.WriteLine("Compiling and registering scripts...");
             * 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);

                mapLoader = new MapLoader();
                maps      = mapLoader.LoadMaps();

                skillLoader = new SkillLoader();
                SkillData   = skillLoader.LoadSkills();

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

                var aa      = Configuration.channelIp;
                var address = BitConverter.ToUInt32(aa.GetAddressBytes(), 0);
                var port    = Configuration.channelPort;

                listener = new TcpListener(aa, port);
                thread   = new Thread(Listen);
                thread.Start();

                syncServer = new SyncReceiver(Configuration.masterIP, Configuration.masterPort, events);
                syncServer.OnSyncSuccess += (sender, e) =>
                {
                    var type       = Configuration.channelType;
                    var maxPlayers = Configuration.maxPlayers;
                    Authentication.RegisterChannel(syncServer, server, channel, type, address, port, maxPlayers);
                };

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