Esempio n. 1
0
		public bool SetBlock(Player player,short x,short y,short z,byte type) {
			if (this[x,y,z]==type) { return false; }
			BlockArgs e = new BlockArgs(player,x,y,z,type);
			BlockEvent.Raise(server,this,e);
			if (e.Abort) { return false; }
			this[x,y,z] = type;
			Protocol.BlockPacket(x,y,z,type).Send(this);
			return true;
		}
Esempio n. 2
0
 public void Send(IEnumerable<Player> players,Player except)
 {
     foreach (Packet packet in packets) packet.Send(players,except);
 }
Esempio n. 3
0
 public void Send(Player player)
 {
     foreach (Packet packet in packets) packet.Send(player);
 }
Esempio n. 4
0
 public void Send(Level level,Player except)
 {
     Send(new List<Player>(level.Players),except);
 }
Esempio n. 5
0
		public void Cuboid(Player player,Region region,byte type) {
			Cuboid(player,region,type,DrawMode.Solid);
		}
Esempio n. 6
0
		private void PlayerCommand(Player player,string message,bool byPlayer) {
			if (byPlayer) { Log(player.Name+" used /"+message+"."); }
			string cmd = message.Split(new char[]{' '},2)[0];
			Command command = Commands.Search(ref message);
			if (command==null) { throw new CommandException("The command '"+cmd+"' doesn't exist."); }
			else if (player.Group.Commands.Contains(command) || !byPlayer) {
				command.use.Raise(this,command,player,message);
			} else { throw new CommandException("You're not allowed to use '"+command.Name+"'."); }
		}
Esempio n. 7
0
		private void PlayerLogin(Player player,byte version,string name,string verify) {
			if (version!=Protocol.version) { player.Kick("Wrong version"); }
			else if (!RegexHelper.IsValidName(name)) { player.Kick("Invalid name"); }
			else if (!(Accounts[name]==null ? Groups.Standard : Accounts[name].Group).CanJoinFull && players.Count>=Slots) {
				player.Kick("Server is full");
			} else if (!Verify && player.IP!="127.0.0.1" &&
			           (verify == "--" || !verify.Equals(
			           	BitConverter.ToString(
			           		md5.ComputeHash(Encoding.ASCII.GetBytes(salt+name))).
			           	Replace("-","").TrimStart('0'),StringComparison.OrdinalIgnoreCase))) {
				player.Kick("Login failed! Try again");
			} else if (!(Accounts[name]==null ? Groups.Standard : Accounts[name].Group).CanJoin) {
				player.Kick("You're not allowed to join");
			} else {
				players.ForEach(delegate(Player found) {
				                	if (found.Name.Equals(name,StringComparison.OrdinalIgnoreCase))
				                		found.Kick("Someone logged in as you");
				                });
				Log(player.IP+" logged in as "+name+".");
				connections.Remove(player);
				players.Add(player);
				player.account = Accounts.Login(player,name);
				player.level = level;
				PlayerLoginEvent.Raise(this,player,name);
			}
		}
Esempio n. 8
0
 public void Use(Player player,string message)
 {
     use(this,player,message);
 }
Esempio n. 9
0
		public void SphereHollow(Player player,int x,int y,int z,int radius,int hollow,byte type) {
			for (int xx=-radius;xx<radius;xx++)
				for (int yy=-radius;yy<radius;yy++)
					for (int zz=-radius;zz<radius;zz++) {
				double distance = Math.Sqrt(Math.Pow(xx,2)+Math.Pow(yy,2)+Math.Pow(zz,2))+0.5;
				if (distance<=radius && distance>hollow &&
				    x+xx>=0 && y+yy>=0 && z+zz>=0 && x+xx<width && y+yy<depth && z+zz<height)
					SetBlock(player,(short)(xx+x),(short)(yy+y),(short)(zz+z),type);
			}
		}
Esempio n. 10
0
		public void Sphere(Player player,int x,int y,int z,int radius,byte type,DrawMode mode) {
			switch (mode) {
				case DrawMode.Solid:
					for (int xx=-radius;xx<radius;xx++)
						for (int yy=-radius;yy<radius;yy++)
							for (int zz=-radius;zz<radius;zz++)
								if (Math.Sqrt(Math.Pow(xx,2)+Math.Pow(yy,2)+Math.Pow(zz,2))+0.5<=radius &&
								    x+xx>=0 && y+yy>=0 && z+zz>=0 && x+xx<width && y+yy<depth && z+zz<height)
									SetBlock(player,(short)(xx+x),(short)(yy+y),(short)(zz+z),type);
					break;
				case DrawMode.Hollow:
					SphereHollow(player,x,y,z,radius,radius-1,type);
					break;
				case DrawMode.Wireframe:
					throw new NotImplementedException();
			}
		}
Esempio n. 11
0
		public void Sphere(Player player,int x,int y,int z,int radius,byte type) {
			Sphere(player,x,y,z,radius,type,DrawMode.Solid);
		}
Esempio n. 12
0
		public void Cuboid(Player player,int x1,int y1,int z1,int x2,int y2,int z2,byte type,DrawMode mode) {
			x1 = Math.Max(x1,0); y1 = Math.Max(y1,0); z1 = Math.Max(z1,0);
			x2 = Math.Min(x2,width); y2 = Math.Min(y2,depth); z2 = Math.Min(z2,height);
			switch (mode) {
				case DrawMode.Solid:
					for (int x=x1;x<x2;x++)
						for (int y=y1;y<y2;y++)
							for (int z=z1;z<z2;z++)
								SetBlock(player,(short)x,(short)y,(short)z,type);
					break;
				case DrawMode.Hollow:
					for (int x=x1;x<x2;x++)
						for (int y=y1;y<y2;y++) {
						SetBlock(player,(short)x,(short)y,(short)z1,type);
						SetBlock(player,(short)x,(short)y,(short)(z2-1),type);
					} for (int y=y1;y<y2;y++)
						for (int z=z1+1;z<z2-1;z++) {
						SetBlock(player,(short)x1,(short)y,(short)z,type);
						SetBlock(player,(short)(x2-1),(short)y,(short)z,type);
					} for (int x=x1+1;x<x2-1;x++)
						for (int z=z1+1;z<z2-1;z++) {
						SetBlock(player,(short)x,(short)y1,(short)z,type);
						SetBlock(player,(short)x,(short)(y2-1),(short)z,type);
					} break;
				case DrawMode.Wireframe:
					for (int x=x1;x<x2;x++) {
						SetBlock(player,(short)x,(short)y1,(short)z1,type);
						SetBlock(player,(short)x,(short)y1,(short)(z2-1),type);
						SetBlock(player,(short)x,(short)(y2-1),(short)z1,type);
						SetBlock(player,(short)x,(short)(y2-1),(short)(z2-1),type);
					} for (int y=y1+1;y<y2-1;y++) {
						SetBlock(player,(short)x1,(short)y,(short)z1,type);
						SetBlock(player,(short)x1,(short)y,(short)(z2-1),type);
						SetBlock(player,(short)(x2-1),(short)y,(short)z1,type);
						SetBlock(player,(short)(x2-1),(short)y,(short)(z2-1),type);
					} for (int z=z1+1;z<z2-1;z++) {
						SetBlock(player,(short)x1,(short)y1,(short)z,type);
						SetBlock(player,(short)x1,(short)(y2-1),(short)z,type);
						SetBlock(player,(short)(x2-1),(short)y1,(short)z,type);
						SetBlock(player,(short)(x2-1),(short)(y2-1),(short)z,type);
					} break;
			}
			
		}
Esempio n. 13
0
		public void Cuboid(Player player,int x1,int y1,int z1,int x2,int y2,int z2,byte type) {
			Cuboid(player,x1,y1,z1,x2,y2,z2,type,DrawMode.Solid);
		}
Esempio n. 14
0
		public void Cuboid(Player player,Region region,byte type,DrawMode mode) {
			Cuboid(player,region.X1,region.Y1,region.Z1,
			       region.X2,region.Y2,region.Z2,type);
		}
Esempio n. 15
0
 public void Send(Level level,Player except)
 {
     foreach (Packet packet in packets) packet.Send(level,except);
 }
Esempio n. 16
0
 internal Account Login(Player player,string name)
 {
     Account account;
     if (accounts.ContainsKey(name.ToLower())) {
         account = accounts[name.ToLower()];
         if (account.Online) { throw new Exception("Account is already used by another player."); }
         string filename = "accounts/"+name+"."+host.Extension;
         if (File.Exists(filename) && File.GetLastWriteTime(filename)>account.fileModified) {
             Account a = Account.Load(groups,name);
             if (a!=null) { accounts[name.ToLower()] = a; account = a; }
         }
     } else {
         account = new Account(name);
         account.group = groups.Standard;
         accounts.Add(name.ToLower(),account);
     } account.player = player;
     account.lastIP = player.IP;
     account.logins++;
     account.lastLogin = DateTime.Now;
     return account;
 }
Esempio n. 17
0
		internal void PlayerSetBlock(Player player,short x,short y,short z,byte type) {
			byte before = this[x,y,z];
			BlockArgs e = new BlockArgs(player,x,y,z,type);
			BlockEvent.Raise(server,this,e);
			if (before==this[x,y,z]) {
				if (e.Abort) { Protocol.BlockPacket(x,y,z,before).Send(player); }
				else { this[x,y,z] = type; Protocol.BlockPacket(x,y,z,type).Send(this,player); }
			}
		}
Esempio n. 18
0
		private void Accept(Socket socket) {
			Player player = new Player(this,new Protocol(socket));
			connections.Add(player);
			player.LoginEvent += PlayerLogin;
			player.InternalBlockEvent += PlayerBlock;
			player.CommandEvent += PlayerCommand;
			player.DisconnectedEvent += PlayerDisconnected;
			Log(player.IP+" connected.");
		}
Esempio n. 19
0
 public void Send(Player player)
 {
     player.Send(buffer);
 }
Esempio n. 20
0
		private void PlayerBlock(Player player,BlockArgs e,bool sendPlayer) {
			if (sendPlayer) {
				if (!player.level.SetBlock(player,e.X,e.Y,e.Z,e.Type))
					Protocol.BlockPacket(e.X,e.Y,e.Z,player.level[e.X,e.Y,e.Z]).Send(player);
			} else { player.level.PlayerSetBlock(player,e.X,e.Y,e.Z,e.Type); }
		}
Esempio n. 21
0
 public void Send(IEnumerable<Player> players,Player except)
 {
     foreach (Player player in players)
         if (player!=except) { Send(player); }
 }
Esempio n. 22
0
		private void PlayerDisconnected(Player player,string message) {
			if (player.Status>=Player.OnlineStatus.Identified) {
				Log(player.Name+" disconnected"+(message==null?"":" ("+message+")")+".");
				players.Remove(player);
				Accounts.Logout(player.account);
			} else {
				Log(player.IP+" disconnected"+(message==null?"":" ("+message+")")+".");
				connections.Remove(player);
			}
		}
Esempio n. 23
0
 public BlockArgs(Player origin,short x,short y,short z,byte type)
 {
     this.origin = origin;
     this.x = x; this.y = y; this.z = z;
     this.type = type;
 }