/// <summary> /// Authecate the user to join /// </summary> private static bool Auth(string _Username, string _Password) { WebClient Client = new WebClient(); string returns; try { Debug("Connecting to minecraft.net...\n"); PostData post = new PostData("http://minecraft.net/game/getversion.jsp"); post.Add("user", _Username); post.Add("password", _Password); post.Add("version", "12"); returns = post.GetResult(true); } catch { SMPInterface.LastError = "Could not connect to minecraft.net"; return(false); } SMPInterface.Debug("Authecation: " + returns + "\n"); if (returns != "Bad login" && returns != "Old version" && returns != "Error") { string[] Bits = returns.Split(":".ToCharArray()); SessionHash = Bits[1]; CaseUsername = Bits[2]; SessionID = Bits[3]; return(true); } else { SMPInterface.LastError = returns; return(false); } }
public static bool AuthConnect(string _Username, string _ServerID) { string returns = ""; try { PostData post = new PostData("http://www.minecraft.net/game/joinserver.jsp"); post.Add("user", _Username); post.Add("sessionId", SessionID); post.Add("serverId", _ServerID); returns = post.GetResult(true); } catch { SMPInterface.LastError = "Could not connect to minecraft.net"; return(false); } SMPInterface.Debug("Connect Authecation: " + returns + "\n"); if (returns == "OK") { return(true); } else { return(false); } }
public static void Disconnect() { SMPInterface.Debug("Disconnected " + CaseUsername + "\n"); PacketResponder.Abort(); Reader.Close(); Writer.Close(); }
private void btnConnect_Click(object sender, EventArgs e) { foreach (Control ctrl in this.Controls) { errorProvider.SetError(ctrl, ""); } bool berror = false; if (this.txtUsername.Text == "") { errorProvider.SetError(txtUsername, "Username not specified"); berror = true; } if (this.txtPassword.Text == "") { errorProvider.SetError(txtPassword, "Password not specified"); berror = true; } if (this.txtServerIP.Text == "") { errorProvider.SetError(txtServerIP, "Server not specified"); berror = true; } if (berror) { return; } btnConnect.Text = "Connecting..."; btnConnect.Enabled = false; if ( SMPInterface.Connect(txtServerIP.Text, txtUsername.Text, txtPassword.Text, txtSrvPassword.Text) ) { this.Close(); } else { btnConnect.Text = "Connect"; btnConnect.Enabled = true; errorProvider.SetError(btnConnect, SMPInterface.LastError); } }
/// <summary> /// Send the shit down the toilet /// </summary> public void Flush() { byte[] BufferSend = new byte[Pointer]; for (int i = 0; i < Pointer; i++) { BufferSend[i] = Buffer[i]; //char[] Stuff = Buffer[i].ToString("X8").ToCharArray(); //SMPInterface.Debug(Stuff[6].ToString() + Stuff[7].ToString() + " "); } //SMPInterface.Debug("\n"); try { Writer.Write(BufferSend); } catch (Exception ex) { SMPInterface.Debug(ex.Message); } // Reset Buffer Buffer = new byte[1024]; Pointer = 0; }
/// <summary> /// Tries loading the chunk at the specified position. This is done automatically /// when an area is requested. /// </summary> public Chunk?LoadChunk(Point <int> Pos) { Chunk?chunk; if (SMPInterface.IsSMP) { chunk = SMPInterface.GetChunk(Pos, this._Trans); } else if (!this._Chunks.TryGetValue(Pos, out chunk)) { long regionX = (long)Math.Floor((decimal)Pos.X / 32); long regionZ = (long)Math.Floor((decimal)Pos.Y / 32); string file = this._Source + Path.DirectorySeparatorChar + "region" + Path.DirectorySeparatorChar + "r." + Convert.ToString(regionX) + "." + Convert.ToString(regionZ) + ".mca"; if (File.Exists(file)) { try { using (FileStream fs = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) //File.OpenRead(file)) { NBTNamedTag <INBTData> dat = NBT.ReadChunk(fs, Pos); NBTCompound level = (NBTCompound)(((NBTCompound)dat.Data).Data["Level"]).Data; this._Chunks.Add(Pos, chunk = ParseChunkFromNBT(level) ); } } catch { this._Chunks.Add(Pos, null); } } else { this._Chunks.Add(Pos, null); } } return(chunk); }
private void tmrSpin_Tick(object sender, EventArgs e) { float movement = 11; rotation = (rotation + movement) % 360f; if (rotation % 2 == 0) { PacketHandler h = SMPInterface.Handler; h.SetOperationCode(SMPInterface.PacketTypes.PlayerPosition); double x = SMPInterface.PlayerX; double y = 126.0; double z = SMPInterface.PlayerZ; x += Math.Cos((rotation / 1.0) * Math.PI * 2.0) * 10.0; z += Math.Sin((rotation / 1.0) * Math.PI * 2.0) * 10.0; h.Write(SMPInterface.SwapByteOrder(x)); h.Write(SMPInterface.SwapByteOrder(y)); h.Write(SMPInterface.SwapByteOrder(y + 0.5)); h.Write(SMPInterface.SwapByteOrder(z)); h.Write(false); h.Flush(); } else { float x = rotation; float y = 0f; // horizontal? PacketHandler h = SMPInterface.Handler; h.SetOperationCode(SMPInterface.PacketTypes.PlayerLook); h.Write(SMPInterface.SwapByteOrder(x)); h.Write(SMPInterface.SwapByteOrder(y)); h.Write(false); h.Flush(); } }
private void disconnectToolStripMenuItem_Click(object sender, EventArgs e) { SMPInterface.Disconnect(); }
/// <summary> /// Set the operation code (0x01 etc...) /// </summary> public void SetOperationCode(SMPInterface.PacketTypes OpCode) { Buffer[0] = (byte)OpCode; Pointer++; Flush(); Pointer = 0; // 0; }