예제 #1
0
        /// <summary>
        ///     Wrapper function that creates a NetworkStream that is already authenticated with the server.
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="port"></param>
        /// <param name="id"></param>
        /// <param name="asmVersion"></param>
        /// <returns></returns>
        private static NetworkStream GetNetworkStream(string ip, int port, int id, Version asmVersion)
        {
            TcpClient tcpC;

            try
            {
                tcpC = new TcpClient(ip, port);

                Debug.Log(-1, "Connecting to Network Listener");
                if (!tcpC.Connected)
                {
                    return(null);
                }
                Debug.Log(-1, "Connected.");
            }
            catch (Exception)
            {
                Debug.Log(Debug.AdlWarningMask, "Could not connect to server.");
                return(null);
            }


            //Authentication
            Stream str = tcpC.GetStream();
            var    ap  = AuthPacket.Create(id, asmVersion);

            var l = ap.Serialize();

            str.Write(l, 0, l.Length);
            //Authentication End

            return(tcpC.GetStream());
        }