示例#1
0
	/**
	 * Sends message to server
	 * 
	 * @param Message
	 * @param isAutomatic
	 * @return Returns True if successful, False if otherwise
	 */
	public boolean sendToServer(String Message, boolean isAutomatic) {
		if (Message.length() > 0) {
			if (Message.toLowerCase().equals("/revive")) {
				try {
					new ClientStatusPacket(reader).Write(CLIENT_STATUS.PERFORM_RESPAWN);
					sendmsg("�espawn requested");
					return true;
				} catch (IOException e) {
					return false;
				}
			} else {
				if (this.sock != null) {
					ChatEvent e = new ChatEvent(bot, Message, true);
					storage.pluginManager.invokeEvent(e, bot.getAllowedPlugins());
					if (e.isCancelled()) {
						return true;
					}
					if (Message.length() >= 100) {
						String[] msgs = splitter(Message, 100);
						for (String m : msgs) {
							sendToServerRaw(m, isAutomatic);
						}
						return true;
					} else {
						sendToServerRaw(Message, isAutomatic);
						return true;
					}
				}
			}
		}
		return false;
	}
示例#2
0
	private void processpacket(int pid, int len, ByteBuffer buf, packetStruct packet) throws Exception {
		Event e = null;
		switch (pid) {
		// default:
		// sendmsg("�Unhandled packet " + pid);
		// new Ignored_Packet(len, reader).Read();
		// break;
		/*
		 * case EntityStatusPacket.ID: e = new EntityStatusPacket(reader,
		 * buf).Read(); break;
		 */

			


			case SignUpdatePacket.ID:
				e = new SignUpdatePacket(buf, reader).Read();
			break;

			case TimeUpdatePacket.ID:
				new TimeUpdatePacket(buf, reader).Read();
			break;

			case UpdateHealthPacket.ID:
				UpdateHealthEvent upheal = new UpdateHealthPacket(reader, buf).Read();
				this.Health = upheal.getHealth();
				this.Food = upheal.getFood();
				this.Satur = upheal.getSaturation();
				bot.updateHealth(this.Health, this.Food, this.Satur);
			break;

			case PlayerPositionAndLookPacket.ID:
				PlayerPositionAndLookEvent ppal = new PlayerPositionAndLookPacket(reader, buf).Read();
				this.pos_x = (int) ppal.getX();
				this.pos_y = (int) ppal.getY();
				this.pos_z = (int) ppal.getZ();
				bot.updateposition(this.pos_x, this.pos_y, this.pos_z);
			break;

			case TabCompletePacket.ID:
				TabCompletePacket tabpack = new TabCompletePacket(reader, buf);
				TabCompleteEvent tabev = tabpack.Read();
				tabcomp.setNames(tabev.getNames());
				tabcomp.getNext();
				e = tabev;
			break;

			case KeepAlivePacket.ID:
				// Keep us alive
				KeepAlivePacket keepalivepack = new KeepAlivePacket(reader, buf);
				keepalivepack.Read();
				keepalivepack.Write();
			break;

			case JoinGamePacket.ID:
				// join game
				JoinGameEvent joingameevent = new JoinGamePacket(buf, reader).Read();
				if (joingameevent.getMaxPlayers() > 25 && joingameevent.getMaxPlayers() < 50) {
					// 2 Columns 20 rows
					settablesize(2, 20);
				} else if (joingameevent.getMaxPlayers() >= 50 && joingameevent.getMaxPlayers() < 70) {
					// 3 Columns 20 rows
					settablesize(3, 20);
				} else if (joingameevent.getMaxPlayers() >= 70) {
					// 4 Columns 20 rows
					settablesize(4, 20);
				} else {
					// 1 Columns 20 rows
					settablesize(1, 20);
				}
				e = joingameevent;
			break;

			case ChatPacket.ID:
				// Chat
				ChatEvent event = new ChatPacket(buf, reader).Read();
				if (!event.isIgnored()) {
					String msg = event.getFormatedMessage();
					sendChatMsg(msg);
					tryandsendlogin();
				}
				e = event;
			break;

			case SpawnPositionPacket.ID:
				new SpawnPositionPacket(buf, reader).Read();
			break;

			case RespawnPacket.ID:
				new RespawnPacket(buf, reader).Read();
			break;

			case PlayerListItemPacket.ID:
				PlayerListItemPacket playerlistitem = new PlayerListItemPacket(buf, reader);
				PlayerListEvent plevent = playerlistitem.Read(Tablist, Tablist_nicks);
				if (servePlayerList(plevent, Tablist, Tablist_nicks)) {
					this.refreshTablist();
				}
				e = plevent;
			break;

			case DisplayScoreBoardPacket.ID:
				// Scoreboard display
				new DisplayScoreBoardPacket(buf, reader).Read();
			break;

			case SetCompressionPacket.ID2:
				new SetCompressionPacket(buf, reader).Read();
				sendmsg("Compression activated");
				// compack.Write();
				reader.compression = true;
			break;

			case TeamPacket.ID:
				// Teams
				this.handleteam(new TeamPacket(buf, reader).Read());
			break;

			case PluginMessagePacket.ID:
			// Plugin message
			// PluginMessageEvent plmsge = new PluginMessagePacket(buf,
			// reader).Read();
			// e = plmsge;
			// sendmsg("Channel: " + plmsge.getChannel() + " Message: " +
			// plmsge.getMessageAsString());
			break;

			case ConnectionResetPacket.ID:
				ConnectionResetEvent dcevent = new ConnectionResetPacket(buf, reader).Read();
				sendmsg("�erver closed connection. (" + dcevent.getReason() + ")");
			break;
		}
		if (e != null) {
			storage.pluginManager.invokeEvent(e, bot.getAllowedPlugins());
		}
	}