예제 #1
0
파일: Level.cs 프로젝트: welterde/obsidian
		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;
		}
예제 #2
0
 public void Send(IEnumerable<Player> players,Player except)
 {
     foreach (Packet packet in packets) packet.Send(players,except);
 }
예제 #3
0
 public void Send(Player player)
 {
     foreach (Packet packet in packets) packet.Send(player);
 }
예제 #4
0
파일: Packet.cs 프로젝트: welterde/obsidian
 public void Send(Level level,Player except)
 {
     Send(new List<Player>(level.Players),except);
 }
예제 #5
0
파일: Level.cs 프로젝트: welterde/obsidian
		public void Cuboid(Player player,Region region,byte type) {
			Cuboid(player,region,type,DrawMode.Solid);
		}
예제 #6
0
파일: Server.cs 프로젝트: welterde/obsidian
		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+"'."); }
		}
예제 #7
0
파일: Server.cs 프로젝트: welterde/obsidian
		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);
			}
		}
예제 #8
0
 public void Use(Player player,string message)
 {
     use(this,player,message);
 }
예제 #9
0
파일: Level.cs 프로젝트: welterde/obsidian
		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);
			}
		}
예제 #10
0
파일: Level.cs 프로젝트: welterde/obsidian
		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();
			}
		}
예제 #11
0
파일: Level.cs 프로젝트: welterde/obsidian
		public void Sphere(Player player,int x,int y,int z,int radius,byte type) {
			Sphere(player,x,y,z,radius,type,DrawMode.Solid);
		}
예제 #12
0
파일: Level.cs 프로젝트: welterde/obsidian
		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;
			}
			
		}
예제 #13
0
파일: Level.cs 프로젝트: welterde/obsidian
		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);
		}
예제 #14
0
파일: Level.cs 프로젝트: welterde/obsidian
		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);
		}
예제 #15
0
 public void Send(Level level,Player except)
 {
     foreach (Packet packet in packets) packet.Send(level,except);
 }
예제 #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;
 }
예제 #17
0
파일: Level.cs 프로젝트: welterde/obsidian
		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); }
			}
		}
예제 #18
0
파일: Server.cs 프로젝트: welterde/obsidian
		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.");
		}
예제 #19
0
파일: Packet.cs 프로젝트: welterde/obsidian
 public void Send(Player player)
 {
     player.Send(buffer);
 }
예제 #20
0
파일: Server.cs 프로젝트: welterde/obsidian
		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); }
		}
예제 #21
0
파일: Packet.cs 프로젝트: welterde/obsidian
 public void Send(IEnumerable<Player> players,Player except)
 {
     foreach (Player player in players)
         if (player!=except) { Send(player); }
 }
예제 #22
0
파일: Server.cs 프로젝트: welterde/obsidian
		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);
			}
		}
예제 #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;
 }