Exemplo n.º 1
0
	private void mainloop() {
		// Main loop
		try {
			sendmsg("�onnecting");
			if (protocolversion == 4 || protocolversion == 5) {
				this.maxpacketid = 0x40;
			} else if (protocolversion == 47) {
				this.maxpacketid = 0x49;
			}

			BotInitEvent botinitevent = new BotInitEvent(bot);
			storage.pluginManager.invokeEvent(botinitevent, bot.getAllowedPlugins());

			Tablist = new ArrayList<String>();
			Tablist_nicks = new HashMap<String, String>();
			playerTeams = new HashMap<String, String>();
			TeamsByNames = new HashMap<String, team_struct>();

			haslogged = false;
			encryptiondecided = false;
			sock = null;
			bot.seticon(ICONSTATE.CONNECTING);

			if (bot.useProxy()) {
				Proxy proxy = bot.getProxyAddress();
				if (proxy != null) {
					sock = new Socket(proxy);
					sock.connect(bot.getServerAddress());
				} else {
					bot.logmsg("�nvalid proxy");
					this.reconnect = false;
					return;
				}
			} else {
				sock = new Socket(bot.serverip, bot.serverport);
			}
			cin = sock.getInputStream();
			cout = sock.getOutputStream();
			reader = new packet(bot, cin, cout);
			reader.ProtocolVersion = protocolversion;
			// definepackets(reader);
			storage.changemenuitems();
			// First, we must send HandShake and hope for good response
			new HandShakePacket(reader).Write(bot.serverip, bot.serverport);
			new LoginStartPacket(reader).Write(bot.username);
			connecttime = System.currentTimeMillis() / 1000;
			// Init routine
			communicationavailable = true;
			int pid;
			int len = 0;
			boolean connectedicon = true;
			// Connection established, time to create AntiAFK
			this.afkter = new AntiAFK(this);
			this.afkter.start();
			// The loop
			while (communicationavailable) {
				packetStruct packet = reader.readNexter();
				if (packet == null) {
					continue;
				}
				len = packet.packetLength;
				pid = packet.packetID;
				int datalen = packet.dataLength;
				// TODO: Debug part
				// System.out.println("PID: " + Integer.toHexString(pid) +
				// " LEN: " + len);
				if (pid > maxpacketid) {
					sendmsg("Received packet id " + pid + " (Length: " + len + ",Compression: " + reader.compression + ", Encryption: " + reader.isEncrypted() + ")");
					sendmsg("�alformed communication");
					break;
				}
				if (connectedicon) {
					bot.seticon(ICONSTATE.CONNECTED);
				}
				PacketReceiveEvent packevent = new PacketReceiveEvent(bot, packet, !encryptiondecided);
				storage.pluginManager.invokeEvent(packevent, bot.getAllowedPlugins());
				if (packevent.isCancelled()) {
					continue;
				}
				if (datalen > 0) {
					ByteBuffer buf = packet.generateBuffer();
					if (encryptiondecided) {
						processpacket(pid, datalen, buf, packet);
					} else {
						processpreloginpacket(pid, datalen, buf);
					}
				}
			}
		} catch (UnknownHostException e) {
			sendmsg("�o such host is known.");
		} catch (SerialException e) {
		} catch (IllegalArgumentException e) {
			if (!storage.reportthis(e)) {
				sendmsg("�ata stream error happened. Error log written into main tab. Please report this.");
				e.printStackTrace();
			}
		} catch (NullPointerException e) {
			if (!storage.reportthis(e)) {
				sendmsg("�trange error happened. Please report this.");
				e.printStackTrace();
			}
		} catch (SocketException e) {
		} catch (IOException e) {
			if (!storage.reportthis(e)) {
				e.printStackTrace();
			}
		} catch (RuntimeException e) {
			if (!storage.reportthis(e)) {
				sendmsg("�rror happened. Error log written into main tab. Please report this.");
				e.printStackTrace();
			}
		} catch (Exception e) {
			if (!storage.reportthis(e)) {
				sendmsg("�rror happened. Error log written into main tab. Please report this.");
				e.printStackTrace();
			}
		}
	}
Exemplo n.º 2
0
	private void sendrawmsg(String message) {
		bot.logmsg(message);
	}