public void OpenedChannelsReceiveData()
        {
            Acceptor.Start();
            for (int i = 0; i < Clients.Length; i++)
            {
                StartClientConnect(i);
            }

            byte[] testData = new byte[5000];
            for (int i = 0; i < testData.Length; i++)
            {
                testData[i] = (byte)(i * i);
            }

            WaitForConnections(Clients.Length);
            foreach (Socket client in Clients)
            {
                client.Send(testData);
            }

            foreach (Socket socket in OpenedConnections)
            {
                byte[] rcvData   = new byte[6000];
                int    byteCount = 0;

                while ((byteCount += socket.Receive(rcvData, byteCount, rcvData.Length - byteCount, SocketFlags.None)) < testData.Length)
                {
                    // receive in loop
                }

                Assert.Equal(testData.Length, byteCount);
                Array.Resize(ref rcvData, byteCount);
                Assert.True(testData.SequenceEqual(rcvData));
            }
        }
        static void Main(string[] args)
        {
            string s = " ";
            Packet p = new Packet();

            p.WriteString(s);

            try
            {
                MyReceiver receiver = new MyReceiver();

                var            maxConnect = 1024;
                AsyncIOManager netserver  = new AsyncIOManager(4, receiver, 1024, maxConnect, 512);

                AsyncSocket prototype = AsyncSocket.GetPrototype();
                AsyncSocket.InitUIDAllocator(1, maxConnect);

                Acceptor acceptor = new Acceptor(netserver, prototype, "192.168.0.79", 3210);
                acceptor.Start();

                while (true)
                {
                    // 이 예제는 연결된 클라이언트들에게 2초마다 뭔가를 날려줍니다요~
                    System.Threading.Thread.Sleep(2000);
                    receiver.Process();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                Console.ReadLine();
            }
        }
        public void OpenedChannelsSendData()
        {
            Acceptor.Start();
            for (int i = 0; i < Clients.Length; i++)
            {
                StartClientConnect(i);
            }

            byte[] testData = new byte[5000];
            for (int i = 0; i < testData.Length; i++)
            {
                testData[i] = (byte)(i * i);
            }

            WaitForConnections(Clients.Length);
            foreach (Socket connection in OpenedConnections)
            {
                connection.Send(testData);
            }

            WaitForData(testData.Length * Clients.Length);

            foreach (Socket client in Clients)
            {
                VerifyOtherEndData(client, testData);
            }
        }
        static void Main(string[] args)
        {
            var userkey = new byte[] //europe maplestory key
            {
                0x13, 0x00, 0x00, 0x00,
                0x08, 0x00, 0x00, 0x00,
                0x06, 0x00, 0x00, 0x00,
                0xB4, 0x00, 0x00, 0x00,
                0x1B, 0x00, 0x00, 0x00,
                0x0F, 0x00, 0x00, 0x00,
                0x33, 0x00, 0x00, 0x00,
                0x52, 0x00, 0x00, 0x00
            };

            var aes = new AesCipher(userkey);

            var info = new ServerInfo()
            {
                Version    = 97,
                Subversion = "1",
                Locale     = 9
            };

            using (var acceptor = new Acceptor(info, aes, 8484))
            {
                acceptor.OnClientAccepted += OnClientAccepted;
                acceptor.Start();

                Console.ReadLine();
            }
        }
Exemple #5
0
        public bool Run()
        {
            if (!InitialiseWorld())
            {
                return(false);
            }

            m_acceptor.Start();
            Logger.WriteLog(Logger.LogTypes.HEmi, "HellEmissary		- {0}.", m_acceptor.Port);
            return(true);
        }
Exemple #6
0
    public void Start()
    {
        acceptor = new Acceptor();
        acceptor.Start();
        decoder          = new DefaultSocketDecoder();
        encoder          = new DefaultSocketEncoder();
        httpDecoder      = new DefaultDecoder();
        httpEncoder      = new DefaultEncoder();
        heartBeatPackage = new Msg(BaseCodeMap.BaseCmd.CMD_HEART_BEAT);
        SessionConfig sessionConfig = new SessionConfig(10, 10);

        gameSrvClient = getClient(null, onMsgPush, sessionConfig);
    }
Exemple #7
0
        private static void Configurate()
        {
            using (Config config = new Config(@"..\DataSvr\" + Program.ConfigurationFile))
            {
                Name      = Program.ConfigurationFile.Replace(".img", "");
                Port      = config.GetUShort("", "port");
                AdminPort = config.GetUShort("", "adminPort");

                IPAddress ipAddress;
                string    ipString = config.GetString("", "PublicIP");

                if (!IPAddress.TryParse(ipString, out ipAddress))
                {
                    ipAddress = Dns.GetHostEntry(ipString).AddressList[0];
                }

                PublicIP = ipAddress;

                PrivateIP = IPAddress.Parse(config.GetString("", "PrivateIP"));

                List <string> worldNames = config.GetBlocks("center", true);

                foreach (string worldName in worldNames)
                {
                    World world = new World();

                    world.Name     = worldName;
                    world.ID       = config.GetByte(worldName, "world");
                    world.Channels = config.GetByte(worldName, "channelNo");

                    Worlds.Add(world.ID, world);
                }
            }

            using (Config config = new Config(@"..\DataSvr\Database.img"))
            {
                string host     = config.GetString("", "Host");
                string schema   = config.GetString("", "Schema");
                string username = config.GetString("", "Username");
                string password = config.GetString("", "Password");

                Database = new Database(username, password, schema, host);
            }

            LoginAcceptor = new Acceptor(Port);
            LoginAcceptor.OnClientAccepted += new Action <Socket>(OnClientConnected);
            LoginAcceptor.Start();
        }
Exemple #8
0
        private static void Configurate()
        {
            using (Config config = new Config(@"..\DataSvr\" + Program.ConfigurationFile))
            {
                // NOTE: Properties.

                Name    = Program.ConfigurationFile.Replace(".img", "");
                Port    = config.GetUShort("", "port");
                WorldID = config.GetByte("", "gameWorldId");

                IPAddress ipAddress;
                string    ipString = config.GetString("", "PublicIP");

                if (!IPAddress.TryParse(ipString, out ipAddress))
                {
                    ipAddress = Dns.GetHostEntry(ipString).AddressList[0];
                }

                PublicIP = ipAddress;

                PrivateIP = IPAddress.Parse(config.GetString("", "PrivateIP"));

                // NOTE: Center Block.

                CenterIP   = IPAddress.Parse(config.GetString("center", "ip"));
                CenterPort = config.GetUShort("center", "port");
                WorldName  = config.GetString("center", "worldName");

                // NOTE: Hacking Auto Block Block.
            }

            using (Config config = new Config(@"..\DataSvr\Database.img"))
            {
                string host     = config.GetString("", "Host");
                string schema   = config.GetString("", "Schema");
                string username = config.GetString("", "Username");
                string password = config.GetString("", "Password");

                Database = new Database(username, password, schema, host);
            }

            GameAcceptor = new Acceptor(Port);
            GameAcceptor.OnClientAccepted += new Action <Socket>(OnClientConnected);
            GameAcceptor.Start();
        }
        public void RespectsBacklogSize()
        {
            Acceptor.MaxPendingConnections = 5;

            ManualResetEventSlim acceptorBarrier = new ManualResetEventSlim();

            AcceptorPool.Barrier = acceptorBarrier;
            lock (acceptorBarrier)
            {
                Task.Factory.StartNew(() => Acceptor.Start());

                Monitor.Wait(acceptorBarrier);
            }

            for (int i = 0; i < 9; i++)
            {
                StartClientConnect(i);
            }

            WaitForErrorsOnOtherSide(4);      // first we get 4 rejects
            WaitForConnectionsOnOtherSide(5); // others are also immediately accepted

            Assert.Equal(4, Exceptions.Count);
            Assert.Equal(5, Connections.Count);

            Assert.Throws <InvalidOperationException>(() => WaitForErrorsOnOtherSide(5)); // nothing more happens
            Assert.Throws <InvalidOperationException>(() => WaitForConnectionsOnOtherSide(6));

            // release the lock and wait for other connections
            acceptorBarrier.Set();

            WaitForConnections(5);

            Assert.Equal(5, OpenedConnections.Count);
            Assert.True(OpenedConnections[0].Connected);

            WaitForServerConnections(5);
            Assert.Equal(5, ConnectionCount);

            // no more connections
            Assert.Throws <InvalidOperationException>(() => WaitForConnections(6));
            Assert.Throws <InvalidOperationException>(() => WaitForErrors(1)); // and we don't see errors from here
        }
        private void StartAndCheckConnections(int connectionCount)
        {
            Acceptor.Start();

            for (int i = 0; i < connectionCount; i++)
            {
                StartClientConnect(i);
            }

            WaitForConnections(connectionCount);

            Assert.Equal(connectionCount, OpenedConnections.Count);
            Assert.True(OpenedConnections[0].Connected);

            WaitForServerConnections(connectionCount);
            Assert.Equal(connectionCount, ConnectionCount);

            Assert.Throws <InvalidOperationException>(() => WaitForErrors(1));
        }
Exemple #11
0
        /*public static void DisableTunnel() {
         *  List<string> iPList = new List<string>();
         *  iPList.Add("8.31.99.133");
         *  iPList.Add("8.31.99.134");
         *  iPList.Add("8.31.99.135");
         *  iPList.Add("8.31.99.136");
         *  iPList.Add("8.31.99.137");
         *  iPList.Add("8.31.99.138");
         *  iPList.Add("8.31.99.139");
         *  iPList.Add("8.31.99.140");
         *  iPList.Add("8.31.99.141");
         *  //iPList.Add("8.31.99.142");
         *  //iPList.Add("8.31.99.143");
         *  iPList.Add("8.31.99.144");
         *  iPList.Add("8.31.99.145");
         *  iPList.Add("8.31.99.146");
         *  iPList.Add("8.31.99.200");
         *  iPList.Add("8.31.99.201");
         *  iPList.Add("8.31.99.244");
         *
         *  foreach (string ip in iPList) {
         *      new Process {
         *          StartInfo = {
         *              FileName = "netsh",
         *              Arguments = "int ip delete addr 1 " + ip,
         *              CreateNoWindow = true,
         *              UseShellExecute = false
         *          }
         *      }.Start();
         *  }
         * }
         *
         * public bool AdapterChecks() {
         *  List<string> iPList = new List<string>();
         *  /*iPList.Add("8.31.99.133");
         *  iPList.Add("8.31.99.134");
         *  iPList.Add("8.31.99.135");
         *  iPList.Add("8.31.99.136");
         *  iPList.Add("8.31.99.137");
         *  iPList.Add("8.31.99.138");
         *  iPList.Add("8.31.99.139");
         *  iPList.Add("8.31.99.140");
         *  iPList.Add("8.31.99.141");*/
        /*iPList.Add("8.31.99.142");
        *  iPList.Add("8.31.99.143");
        *  /*iPList.Add("8.31.99.144");
        *  iPList.Add("8.31.99.145");
        *  iPList.Add("8.31.99.146");
        *  iPList.Add("8.31.99.200");
        *  iPList.Add("8.31.99.201");
        *  iPList.Add("8.31.99.244");*/
        /*this.AddIpToAdapter(iPList);
         * return true;
         * }
         *
         * public void AddIpToAdapter(List<string> IPList) {
         * new Process {
         *  StartInfo = {
         *      FileName = "netsh",
         *      Arguments = "interface ip set dns \"Loopback Pseudo-Interface 1\" dhcp",
         *      CreateNoWindow = true,
         *      UseShellExecute = false
         *  }
         * }.Start();
         *
         * foreach (string ip in IPList) {
         *  new Process {
         *      StartInfo = {
         *          FileName = "netsh",
         *          Arguments = "int ip add addr 1 " + ip + " st=ac",
         *          CreateNoWindow = true,
         *          UseShellExecute = false
         *      }
         *  }.Start();
         * }
         * }
         *
         * public void StartTunnels() {
         * //AdapterChecks();
         *
         * ServerInfo info = new ServerInfo() {
         *  Version = 166,
         *  Locale = 8,
         *  Subversion = "1"
         * };
         * Acceptor acceptor = new Acceptor(info, aesCipher, port);
         * acceptor.OnClientAccepted += new EventHandler<Session>(OnClientAccepted);
         * acceptor.Start();
         * /*try {
         *  ushort lowPort = 8484;
         *  ushort highPort = 8888;
         *  string toIP = Program.toIP;
         *  if (Program.checkIP(toIP)) {
         *      ushort num5;
         *      if (false) {
         *          LinkServer server = new LinkServer(8484, toIP);
         *          ushort num3 = (ushort)(highPort - lowPort);
         *          for (ushort i = 0; i <= num3; i = (ushort)(num5 + 1)) {
         *              LinkServer server2 = new LinkServer((ushort)(lowPort + i), toIP);
         *              num5 = i;
         *          }
         *      } else {
         *          Listener listener = new Listener();
         *          Debug.WriteLine("Listening on 8484");
         *          listener.OnClientConnected += new Listener.ClientConnectedHandler(this.listener_OnClientConnected);
         *          listener.Listen(8484);
         *          LinkServer server3 = new LinkServer(8789, toIP);
         *          ushort num6 = (ushort)(highPort - lowPort);
         *          for (ushort j = 0; j <= num6; j = (ushort)(num5 + 1)) {
         *              Listener listener2 = new Listener();
         *              listener2.OnClientConnected += new Listener.ClientConnectedHandler(this.listener_OnClientConnected);
         *              listener2.Listen((ushort)(lowPort + j));
         *              Debug.WriteLine("Listening on " + ((lowPort + j)).ToString());
         *              this.Listeners.Add((ushort)(lowPort + j), listener2);
         *              num5 = j;
         *          }
         *      }
         *  }
         * } catch {
         * }
         * }*/

        public void Listen()
        {
            ServerInfo info = new ServerInfo()
            {
                Version    = 166,
                Locale     = 8,
                Subversion = "1"
            };
            Acceptor acceptor = new Acceptor(info, aesCipher, port);

            acceptor.OnClientAccepted += new EventHandler <Session>(OnClientAccepted);
            acceptor.Start();

            /*Process maple = new Process();
             * if (!File.Exists("C:/Nexon/Maplestory/MapleStory.exe")) {
             *  Debug.WriteLine("Maple doesnt exist...");
             *  Application.Exit();
             * }
             * maple.StartInfo.FileName = "C:/Nexon/Maplestory/MapleStory.exe";
             * maple.StartInfo.Arguments = "GameLaunching";
             * maple.Start();*/
        }
        public void RespectsMaxSimultaneousConnections()
        {
            Acceptor.MaxSimultaneousConnections = 5;
            Acceptor.Start();

            for (int i = 0; i < Clients.Length; i++)
            {
                StartClientConnect(i);
            }

            WaitForConnections(5);
            Assert.Throws <InvalidOperationException>(() => WaitForConnections(6));       // no more than 5 are connected
            Assert.Throws <InvalidOperationException>(() => WaitForErrors(1));            // no errors
            Assert.Throws <InvalidOperationException>(() => WaitForErrorsOnOtherSide(1)); // no errors on other side

            // simulate one of the connections closing
            Acceptor.ReleaseOpenConnectionSlot();

            WaitForConnections(6);
            Assert.Throws <InvalidOperationException>(() => WaitForConnections(7));       // no more than 5 are connected
            Assert.Throws <InvalidOperationException>(() => WaitForErrors(1));            // no errors
            Assert.Throws <InvalidOperationException>(() => WaitForErrorsOnOtherSide(1)); // no errors on other side
        }
Exemple #13
0
 public void Run()
 {
     m_acceptor.Start();
     Logger.WriteLog(Logger.LogTypes.Info, "LListener		   - {0}.", m_acceptor.Port);
 }
Exemple #14
0
        private static void Configurate()
        {
            using (Config config = new Config(@"..\DataSvr\" + Program.ConfigurationFile))
            {
                Port      = config.GetUShort("", "port");
                AdminPort = config.GetUShort("", "adminPort");

                List <string> serverNames = config.GetBlocksFromBlock("", 1);

                foreach (string serverName in serverNames)
                {
                    ServerType type = ServerType.Unknown;

                    switch (serverName)
                    {
                    case "login":
                        type = ServerType.Login;
                        break;

                    case "game":
                        type = ServerType.Game;
                        break;

                    case "shop":
                        type = ServerType.Shop;
                        break;

                    case "mapgen":
                        type = ServerType.MapGen;
                        break;

                    case "claim":
                        type = ServerType.Claim;
                        break;

                    case "itc":
                        type = ServerType.ITC;
                        break;
                    }

                    if (type == ServerType.Unknown)
                    {
                        MessageBox.Show("Unable to parse block '" + serverName + "'.");
                        return;
                    }

                    if (type == ServerType.Claim)
                    {
                        Server server = new Server();

                        server.Type      = type;
                        server.Name      = "claim";
                        server.Port      = config.GetUShort("claim", "port");
                        server.PublicIP  = IPAddress.Parse(config.GetString("claim", "PublicIP"));
                        server.PrivateIP = IPAddress.Parse(config.GetString("claim", "PrivateIP"));

                        Servers.Add(server.Name, server);
                    }
                    else
                    {
                        List <string> serverBlock = config.GetBlocks(serverName, true);

                        foreach (string childServer in serverBlock)
                        {
                            Server server = new Server();

                            server.Type      = type;
                            server.Name      = childServer;
                            server.Port      = config.GetUShort(childServer, "port");
                            server.PublicIP  = IPAddress.Parse(config.GetString(childServer, "PublicIP"));
                            server.PrivateIP = IPAddress.Parse(config.GetString(childServer, "PrivateIP"));

                            Servers.Add(server.Name, server);
                        }
                    }
                }
            }

            CenterAcceptor = new Acceptor(Port);
            CenterAcceptor.OnClientAccepted += new Action <Socket>(OnClientConnected);
            CenterAcceptor.Start();
        }
Exemple #15
0
 public virtual void Start()
 {
     mAcceptor.Start();
 }