public static void Data(NetIncomingMessage msg, Server server)
        {
            Console.WriteLine(msg.ReadString() + " |MSG TYPE: " + msg.MessageType + " msg.Length: " + msg.LengthBytes);

            SecureMessageEncoder sem = new SecureMessageEncoder(server.netServer, msg.SenderConnection);

            /*
             * sem.WriteBytes(Encoding.ASCII.GetBytes("Big Boi ass whip"));
             *
             * sem.WriteBytes(Encoding.ASCII.GetBytes("Heelo i am jack"));
             * sem.WriteBytes(Encoding.ASCII.GetBytes("type and scrambled it to make a type " +
             *                                     "specimen book. It has survived not only five centuries, " +
             *                                     "but also the leap into electronic typesetting, remaining essentially " +
             *                                     "unchanged. It was popularised in the 1960s with the release of Letraset " +
             *                                     "sheets containing Lorem Ipsum passages, and more recently with desktop " +
             *                                     "publishing software like Aldus PageMaker including versions of Lorem Ipsum"));
             * sem.WriteBytes(Encoding.ASCII.GetBytes("f**k you"));
             * sem.WriteBytes(Encoding.ASCII.GetBytes("Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of  (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum,, comes from a line in section 1.10.32."));
             */

            byte[] dhpk  = server.ecdhrsaProvider.GetECDHPublicKey();
            byte[] sh    = server.ecdhrsaProvider.GetSignedHash();
            byte[] rsapk = server.ecdhrsaProvider.GetRSAPublicKey();

            Console.WriteLine("dh: " + dhpk.Length);
            Console.WriteLine("sh: " + sh.Length);
            Console.WriteLine("rsa: " + rsapk.Length);
            Console.WriteLine("the complete length: " + (dhpk.Length + sh.Length + rsapk.Length));

            sem.WriteBytes(dhpk);
            sem.WriteBytes(sh);
            sem.WriteBytes(rsapk);
            sem.PackAndSend();
        }
Esempio n. 2
0
        public Client(string ip, int port)
        {
            try
            {
                ecdhrsaProvider = new ECDHRSAProvider();

                NetPeerConfiguration config = new NetPeerConfiguration("GJABD_GAME");
                config.EnableUPnP   = true;
                config.LocalAddress = IPAddress.Any;

                /* FOR PRODUCTION
                 * config.PingInterval = 5f;
                 * config.ConnectionTimeout = 10f;
                 * config.ResendHandshakeInterval = 1f;
                 * config.MaximumHandshakeAttempts = 2;
                 */

                netPeer = new NetPeer(config);
                netPeer.Start(); // needed for initialization

                Console.WriteLine("started peer");

                NetOutgoingMessage sendMsg = netPeer.CreateMessage();
                sendMsg.Write("RELEASE_GAME_WEB");
                sendMsg.Write(ClientConstants.version.ToString());

                //send authentication public key and verifications.
                SecureMessageEncoder sem = new SecureMessageEncoder(sendMsg);
                sem.WriteBytes(ecdhrsaProvider.GetECDHPublicKey());
                sem.WriteBytes(ecdhrsaProvider.GetSignedHash());
                sem.WriteBytes(ecdhrsaProvider.GetRSAPublicKey());
                sendMsg = sem.PackAndGet();


                IPEndPoint    ipEnd      = new IPEndPoint(IPAddress.Parse(ip), port);
                NetConnection connection = netPeer.Connect(ipEnd, sendMsg);

                Console.WriteLine("connected to server");

                // in your separate thread
                while (netPeer.MessageReceivedEvent.WaitOne())
                {
                    NetIncomingMessage msg = netPeer.ReadMessage();
                    CMessageParseManager.parseMessage(msg, this);
                    netPeer.Recycle(msg);
                    Console.WriteLine("Unique identifier is " + NetUtility.ToHexString(netPeer.UniqueIdentifier));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }