// True if connected to a hub // false if attempted to connect to a leaf ( but has certainly retrieved many hubs ) public bool TryConnect() { try { bool success = false; G2Log.Write("GHandshake : Try to connect to " + remote_host.ToString()); var isConnected = tcp.Connect(); if (!isConnected) { return(false); } OnConnected(); success = OnResponse(); if (success) { //bool connected = tcp.CheckConnection(); //Log.Write("GHandshake : Connected ? " + connected); OnReply(); } else { tcp.Close(); } return(success); } catch (Exception e) { tcp.Close(); return(false); } }
public PacketIn ProcessPacket(TCPConnection con, byte[] buf, int start, int size) { PacketIn packet = new PacketIn(buf, start, size); switch (packet.ID) { case 72: // TS_AC_AES_KEY_IV var pAES = new AUTH_PACKETS.AES_KEY_IV(packet); m_pAES_KEY = m_cRSA.PrivateDecrypt(pAES.nKey, OpenSSL.Crypto.RSA.Padding.PKCS1); GenerateLoginPacket(m_pAES_KEY, con); break; case 10000: // TS_AC_RESULT var pResult = new AUTH_PACKETS.RESULT(packet.ReadUInt16(), packet.ReadUInt16(), packet.ReadInt32()); if (pResult.nLoginFlag == 1) { PacketOut o = new PacketOut(10021); con.SendTCP(o); } else { m_cAuthConnection.Disconnect(); XLog.Log("Login failed. Result: {0} - Disconnecting...", pResult.nResult); } m_szPassword = string.Empty; break; case 10022: // TS_AC_SERVER_LIST m_iAuthServerList = new AUTH_PACKETS.SERVER_LIST(packet); XLog.Log("Server selection. Please use /select ID to connect to one of the listed servers below."); for (int i = 0; i < m_iAuthServerList.count; i++) { XLog.Log(string.Format("-> Server {0}: {1}", i + 1, m_iAuthServerList.list[i].server_name)); } break; case 10024: // TS_AC_SELECT_SERVER con.Disconnect(); var pSelectServer = new AUTH_PACKETS.SELECT_SERVER(packet, ref m_pAES_KEY); Config.ConfigNet conf = new Config.ConfigNet(); conf.Port = m_iAuthServerList.list[m_nSelectedServerIdx].server_port; conf.ListenIp = System.Net.IPAddress.Parse(m_iAuthServerList.list[m_nSelectedServerIdx].server_ip); PacketOut oEncrypt = new PacketOut(2005); oEncrypt.FillString(m_szName, 61); oEncrypt.Write(pSelectServer.encrypted_data, 0, pSelectServer.encrypted_data.Length); oEncrypt.FinalizeLengthAndChecksum(); con.Close(); m_cClientBase.CreateGameServerSession(oEncrypt, conf, m_szName); break; default: break; } return(packet); }
static void Main(string[] args) { TCPConnection connection = new TCPConnection(); connection.State = new TCPStateListen(); connection.Open(); connection.State = new TCPStateEstablished(); connection.Open(); connection.Close(); }