protected void UpdatePosition(bool ForceTp) { byte changed = 0; //Denotes what has changed (x,y,z, rotation-x, rotation-y) int diffX = Pos.x - oldPos.x; int diffZ = Pos.z - oldPos.z; int diffY = Pos.y - oldPos.y; int diffR0 = Rot[0] - oldRot[0]; int diffR1 = Rot[1] - oldRot[1]; if (ForceTp) changed = 4; else { //TODO rewrite local pos change code if (diffX == 0 && diffY == 0 && diffZ == 0 && diffR0 == 0 && diffR1 == 0) { return; //No changes } if (Math.Abs(diffX) > 100 || Math.Abs(diffY) > 100 || Math.Abs(diffZ) > 100) { changed = 4; //Teleport Required } else if (diffR0 == 0 && diffR1 == 0) { changed = 1; //Pos Update Required } else { changed += 2; //Rot Update Required if (diffX != 0 || diffY != 0 || diffZ != 0) { changed += 1; } } } oldPos = Pos; oldRot = Rot; packet pa = new packet(); switch (changed) { case 1: //Pos Change pa.Add((byte)10); pa.Add(id); pa.Add((sbyte)(diffX)); pa.Add((sbyte)(diffY)); pa.Add((sbyte)(diffZ)); break; case 2: //Rot Change pa.Add((byte)11); pa.Add(id); //pa.Add(new byte[2] { 128, 128 }); pa.Add(Rot); break; case 3: //Pos AND Rot Change pa.Add((byte)9); pa.Add(id); pa.Add((sbyte)(Pos.x - oldPos.x)); pa.Add((sbyte)(Pos.y - oldPos.y)); pa.Add((sbyte)(Pos.z - oldPos.z)); //pa.Add(new byte[2] { 128, 128 }); pa.Add(Rot); break; case 4: //Teleport Required pa.Add((byte)8); pa.Add(id); pa.Add(Pos.x); pa.Add(Pos.y); pa.Add(Pos.z); //pa.Add(new byte[2] { 128, 128 }); pa.Add(Rot); break; } foreach (Player p in Server.Players.ToArray()) { if (p != this && p.level == level && p.isLoggedIn && !p.isLoading) { p.SendPacket(pa); } } }
protected void HandleLogin(byte[] message) { try { if (isLoggedIn) return; byte version = message[0]; USERNAME = enc.GetString(message, 1, 64).Trim(); string verify = enc.GetString(message, 65, 32).Trim(); byte type = message[129]; if (!VerifyAccount(USERNAME, verify)) return; if (version != ServerSettings.version) { SKick("Wrong Version!."); return; } //TODO Database Stuff Server.Log("[System]: " + ip + " logging in as " + USERNAME + ".", ConsoleColor.Green, ConsoleColor.Black); CheckDuplicatePlayers(USERNAME); SendMotd(); isLoading = true; SendMap(); if (!isOnline) return; isLoggedIn = true; id = FreeId(); UpgradeConnectionToPlayer(); //Do we want the same-ip-new-account code? //ushort x = (ushort)((0.5 + level.SpawnPos.x) * 32); //ushort y = (ushort)((1 + level.SpawnPos.y) * 32); //ushort z = (ushort)((0.5 + level.SpawnPos.z) * 32); short x = (short)((0.5 + level.SpawnPos.x) * 32); short y = (short)((1 + level.SpawnPos.y) * 32); short z = (short)((0.5 + level.SpawnPos.z) * 32); //x = (ushort)Math.Abs(x); //y = (ushort)Math.Abs(y); //z = (ushort)Math.Abs(z); Pos = new Point3(x, z, y); Rot = level.SpawnRot; oldPos = Pos; oldRot = Rot; SpawnThisPlayerToOtherPlayers(); SpawnOtherPlayersForThisPlayer(); SendSpawn(this); isLoading = false; } catch (Exception e) { Server.Log(e); } }
public void CatchBlock(Player p, ushort x, ushort z, ushort y, byte NewType, bool placed, object DataPass) { Point3 FirstBlock = new Point3(x, z, y); p.SendMessage("Please place another block..."); p.CatchNextBlockchange(new Player.BlockChangeDelegate(CatchBlock2), (object)FirstBlock); }
public void CatchBlock2(Player p, ushort x, ushort z, ushort y, byte NewType, bool placed, object DataPass) { Point3 FirstBlock = (Point3)DataPass; Point3 SecondBlock = new Point3(x, z, y); p.SendMessage("This is where we would initiate a Cuboid!"); }
private Level(Point3 size) { Size = size; //data = new byte[Size.x, Size.z, Size.y]; data = new byte[TotalBlocks]; }
public static Level CreateLevel(Point3 size, LevelTypes type) { Level newlevel = new Level(size); switch(type) { case LevelTypes.Flat: newlevel.CreateFlatLevel(); break; } return newlevel; }
void SetBlock(Point3 pos, byte block) { SetBlock(pos.x, pos.z, pos.y, block); }
void SetBlock(Point3 pos, Blocks.Types block) { SetBlock(pos.x, pos.z, pos.y, (byte)block); }
public byte GetBlock(Point3 pos) { return GetBlock(pos.x, pos.z, pos.y); }
public void CreateFlatLevel() { int middle = Size.y / 2; ForEachBlockXYZ(delegate(int x, int z, int y) { if (y < middle) { SetBlock((ushort)x, (ushort)z, (ushort)y, Blocks.Types.dirt); return; } if(y==middle) { SetBlock((ushort)x, (ushort)z, (ushort)y, Blocks.Types.grass); return; } }); SpawnPos = new Point3((short)(Size.x / 2), (short)(Size.z / 2), (short)(Size.y)); SpawnRot = new byte[2]{0, 0}; }
public static string GetName(Point3 pos) { return GetName(pos.x, pos.z, pos.y); }