static void Main(string[] args)
        {
            TcpClient tcpClient = new TcpClient();

            tcpClient.Connect("127.0.0.1", 8000);

            NetworkStream clientStream = tcpClient.GetStream();

            Packet loginPac = new Packet("login");

            loginPac["username"] = "******";
            loginPac["password"] = "******";

            loginPac.Build(clientStream);

            Packet returnPac = new Packet();

            returnPac.Parse(clientStream);

            string credential = (string)returnPac["credential"];

            Console.WriteLine(returnPac["status"] + "   " + credential);

            connect(8002, credential);
            connect(8003, credential);
            connect(8001, credential);

            Console.ReadLine();
        }
        static void connect(int port, string credential)
        {
            TcpClient tcpClient = new TcpClient();

            tcpClient.Connect("127.0.0.1", port);

            NetworkStream clientStream = tcpClient.GetStream();

            Packet serverLogin = new Packet("login");

            serverLogin["credential"] = credential;

            serverLogin.Build(clientStream);

            Packet Return = new Packet();

            Return.Parse(clientStream);

            Console.WriteLine(port.ToString() + "       " + Return["status"]);
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Client");

            TcpClient tcpClient = new TcpClient();

            tcpClient.Connect("127.0.0.1", 8000);

            NetworkStream clientStream = tcpClient.GetStream();

            Packet pac = new Packet();

            Hacker hacker = new Hacker();

            pac["HEADER"] = "";
            pac["test", typeof(Hacker)] = hacker;

            pac.Build(clientStream);

            Console.ReadLine();
        }
        private static void GetCredential(TcpClient tcpClient)
        {
            NetworkStream clientStream = tcpClient.GetStream();

            clientStream.ReadTimeout = 200;

            bool timedOut = false;

            Packet loginInformation = new Packet();

            try
            {
                loginInformation.Parse(clientStream);
            }

            catch
            {
                timedOut = true;

                Console.WriteLine("[LoginServer] Timed out!");
            }

            Packet returnInfo = new Packet("loginStatus");

            bool loginOK = false;

            if (!timedOut)
            {
                string username = (string)loginInformation["username"];
                string password = (string)loginInformation["password"];

                loginOK = true; // TODO: the login method for the mysql database should be added

                if (loginOK)
                {
                    Random rand = new Random();

                    string credential = rand.Next(100000000, 199999999).ToString();

                    Player player = new Player();

                    player.Credential = credential;

                    LoginPlayerList.Add(player);

                    returnInfo["status"] = "loggedIn";
                    returnInfo["credential"] = credential;

                    Console.WriteLine("[LoginServer] Player logged in with credential " + credential);
                }

                else
                {
                    returnInfo["status"] = "failed";
                }

            }

            else
            {
                returnInfo["status"] = "timedOut";

                loginOK = false;
            }

            returnInfo.Build(clientStream);
        }
示例#5
0
		private void SendPacket(Packet.Packet packet)
		{
			byte[] buffer = packet.Build();

			Logger.Trace("Client packet: " + Packet.Utils.prettyHex(buffer));

			System.IO.BinaryWriter bw = new System.IO.BinaryWriter(Connection.GetStream());
			bw.Write((Int16)(buffer.Length + 2));
			bw.Write(Blowfish.Encrypt(buffer));
		}
        private static void CheckCredential(TcpClient tcpClient)
        {
            NetworkStream clientStream = tcpClient.GetStream();

            clientStream.ReadTimeout = 200;

            bool timedOut = false;

            string credential = "";

            Packet credentialPacket = new Packet();

            try
            {
                credentialPacket.Parse(clientStream);
            }

            catch
            {
                timedOut = true;

                Console.WriteLine("[ChatServer] Timed out!");
            }

            Packet returnInfo = new Packet("loginStatus");

            if (!timedOut)
            {
                credential = (string)credentialPacket["credential"];

                bool playerFound = false;

                foreach (Player player in LoginServer.LoginPlayerList)
                {
                    if (player.Credential == credential)
                    {
                        player.ChatTcpClient = tcpClient;

                        player.ChatClientStream = clientStream;

                        player.LoggedIn = true;

                        playerFound = true;

                        returnInfo["status"] = "loggedIn";

                        Console.WriteLine("[ChatServer] Player logged in");
                    }
                }

                if (!playerFound)
                {
                    returnInfo["status"] = "failed";
                }
            }

            else
            {
                returnInfo["status"] = "timedOut";
            }

            returnInfo.Build(clientStream);
        }