public static MCAccountInfo GetInfo(string username, string password) { MCAccountInfo accountInfo = new MCAccountInfo(); StringBuilder sb = new StringBuilder(); byte[] buf = new byte[256]; // should be largely sufficient for the string it's going to send us HttpWebRequest request; HttpWebResponse response; try { request = (HttpWebRequest)WebRequest.Create(string.Format("http://www.minecraft.net/game/getversion.jsp?user={0}&password={1}&version=255", username, password)); response = (HttpWebResponse)request.GetResponse(); } catch { return null; } string tempString; int count = 0; do { count = response.GetResponseStream().Read(buf, 0, buf.Length); if (count != 0) { tempString = Encoding.ASCII.GetString(buf, 0, count); sb.Append(tempString); } } while (count > 0); string[] split = sb.ToString().Split(":".ToCharArray()); if (split.Length == 5) { accountInfo.GameVersion = split[0]; accountInfo.DownloadTicket = split[1]; accountInfo.Name = split[2]; accountInfo.Session = split[3]; return accountInfo; } return null; }
public MCClient(string server, int port, string username, string password, string serverpassword, bool useauth) { m_Client = new MCRawClient(server, port); m_Username = username; m_Password = password; m_ServerPassword = serverpassword; m_UseAuth = useauth; if (m_UseAuth) { m_AccountInfo = MCLogin.GetInfo(m_Username, m_Password); if (m_AccountInfo == null) throw new Exception("Invalid credentials or bot is outdated."); } m_SelectedItem = MCBlockType.Air; m_Position = new Point3D(); m_ItemInv = null; m_CraftInv = null; m_EquipInv = null; m_Players = new List<MCPlayer>(); Time = 0; SpawnPoint = new Point3D(); m_Yaw = 0f; m_Pitch = 0f; m_Client.OnDisconnect += new DisconnectEventHandler(m_Client_OnDisconnect); m_Client.OnHandshake += new HandshakeEventHandler(m_Client_OnHandshake); m_Client.OnLogin += new LoginEventHandler(m_Client_OnLogin); m_Client.OnUpdateTime += new UpdateTimeEventHandler(m_Client_OnUpdateTime); m_Client.OnPlayerMoveLook += new PlayerMoveLookEventHandler(m_Client_OnPlayerMoveLook); m_Client.OnAddInventory += new AddInventoryEventHandler(m_Client_OnAddInventory); m_Client.OnPlayerInventory += new PlayerInventoryEventHandler(m_Client_OnPlayerInventory); m_Client.OnSpawnPosition += new SpawnPositionEventHandler(m_Client_OnSpawnPosition); m_Client.OnNamedEntitySpawn += new NamedEntitySpawnEventHandler(m_Client_OnNamedEntitySpawn); m_Client.OnChat += new ChatEventHandler(m_Client_OnChat); m_Client.OnAddVehicle += new AddVehicleEventHandler(m_Client_OnAddVehicle); }