当前位置: 首页>>代码示例>>Java>>正文


Java Packet类代码示例

本文整理汇总了Java中lt.ekgame.bancho.api.packets.Packet的典型用法代码示例。如果您正苦于以下问题:Java Packet类的具体用法?Java Packet怎么用?Java Packet使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Packet类属于lt.ekgame.bancho.api.packets包,在下文中一共展示了Packet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handlePacket

import lt.ekgame.bancho.api.packets.Packet; //导入依赖的package包/类
@Override
public void handlePacket(Packet packet) {
	if (packet instanceof PacketRoomUpdate && isHost()) {
		PacketRoomUpdate update = (PacketRoomUpdate) packet;
		if (update.room.matchId == getMatchId()) {
			currentRoom = update.room;
		}
	}
	
	if (packet instanceof PacketRoomJoined) {
		PacketRoomJoined roomUpdate = (PacketRoomJoined) packet;
		currentRoom = roomUpdate.room;
		clientHandler.changeStatus().setStatus(UserState.MULTIPLAYER).send();
	}
	
	if (packet instanceof PacketRoomEveryoneLoaded) {
		bancho.sendPacket(new PacketRoomFinishMap());
		clientHandler.changeStatus().setStatus(UserState.MULTIPLAYING).send();
	}
	
	if (packet instanceof PacketRoomEveryoneFinished) {
		clientHandler.changeStatus().setStatus(UserState.MULTIPLAYER).send();
		setReady(false);
	}
}
 
开发者ID:ekgame,项目名称:bancho-api,代码行数:26,代码来源:MultiplayerHandler.java

示例2: test

import lt.ekgame.bancho.api.packets.Packet; //导入依赖的package包/类
@Test
public void test() {
	int numPackets = 10;
	int delay = 1000;
	long startTime = System.currentTimeMillis();
	
	RateLimiter limiter = new RateLimiterImpl(delay);
	for (int i = 0; i < numPackets; i++)
		limiter.sendPacket(new PacketTest());
	
	Packet packet;
	while (limiter.hasQueuedPackets()) {
		packet = limiter.getOutgoingPacket();
		if (packet != null)
			System.out.println(System.currentTimeMillis());
	}
	
	if (System.currentTimeMillis() - startTime < delay*(numPackets-1))
		fail("Rate not limited enough.");
}
 
开发者ID:ekgame,项目名称:bancho-api,代码行数:21,代码来源:TestRateLimiter.java

示例3: handle

import lt.ekgame.bancho.api.packets.Packet; //导入依赖的package包/类
@Override
public void handle(Packet packet) {
	if (packet instanceof PacketChat) {
		PacketChat msg = (PacketChat) packet;
		if (!msg.channel.startsWith("#"))
			System.out.println(msg.sender + ": " + msg.message);
		
		if (msg.message.trim().startsWith(commandPrefix)) {
			String command = msg.message.trim().substring(1);
			String[] rawArgs = command.split(" ");
			if (rawArgs.length == 0)
				return;
			
			String label = rawArgs[0].toLowerCase();
			List<String> args = new ArrayList<>();
			for (int i = 1; i < rawArgs.length; i++)
				args.add(rawArgs[i]);
			handle(msg.channel, msg.sender, msg.userId, label, args);
		}
	}
}
 
开发者ID:ekgame,项目名称:bancho-client,代码行数:22,代码来源:CommandHandler.java

示例4: handlePacket

import lt.ekgame.bancho.api.packets.Packet; //导入依赖的package包/类
@Override
public void handlePacket(Packet packet) {
	if (packet instanceof PacketProtocolVersion)
		protocolVersion = ((PacketProtocolVersion) packet).protocolVersion;
	
	if (packet instanceof PacketLoginReply) {
		PacketLoginReply reply = (PacketLoginReply) packet;
		if (reply.userId < 0)
			bancho.onLoginFailed(reply.getStatus());
		else {
			bancho.onLoginSuccess(reply.userId);
			userId = reply.userId;
		}
		//bancho.sendPacket(new PacketRequestUpdate());
	}
	
	if (packet instanceof PacketReceivingFinished) {
		setUserStatus(StatusImpl.DEFAULT);
		bancho.dispatchEvent(new EventFinishedLoading());
		isConnected = true;
	}
	
	if (packet instanceof PacketSilenceInfo) {
		PacketSilenceInfo silenceInfo = (PacketSilenceInfo) packet;
		isSilenced = silenceInfo.silenceLength > 0;
		if (isSilenced)
			System.out.println("This account is silenced for " + silenceInfo.silenceLength + " minutes(?)");
	}
}
 
开发者ID:ekgame,项目名称:bancho-api,代码行数:30,代码来源:BanchoClientManager.java

示例5: getOutgoingPacket

import lt.ekgame.bancho.api.packets.Packet; //导入依赖的package包/类
@Override
public Packet getOutgoingPacket() {
	if (System.currentTimeMillis() - lastSentTime > delay) {
		synchronized (outgoing) {
			Packet packet = outgoing.poll();
			if (packet != null)
				lastSentTime = System.currentTimeMillis();
			return packet;
		}
	}
	return null;
}
 
开发者ID:ekgame,项目名称:bancho-api,代码行数:13,代码来源:RateLimiterImpl.java

示例6: getPresenceRequestPacket

import lt.ekgame.bancho.api.packets.Packet; //导入依赖的package包/类
private Packet getPresenceRequestPacket() {
	synchronized (requestedUserUpdates) {
		if (requestedUserUpdates.size() > 256) {
			requestedUserUpdates.clear();
			client.sendPacket(new PacketRequestPresenceAll(0));
		}
		else if (requestedUserUpdates.size() > 0) {
			Packet packet = new PacketRequestPresence(requestedUserUpdates);
			requestedUserUpdates.clear();
			return packet;
		}
	}
	return null;
}
 
开发者ID:ekgame,项目名称:bancho-api,代码行数:15,代码来源:ChannelManagerImpl.java

示例7: sendMessagePacket

import lt.ekgame.bancho.api.packets.Packet; //导入依赖的package包/类
@Override
public void sendMessagePacket(Packet packet) {
	if (client.getClientManager().isConnected() && !client.getClientManager().isSilenced())
		messageLimiter.sendPacket(packet);
	else
		System.out.println("You can't send messages right now.");
}
 
开发者ID:ekgame,项目名称:bancho-api,代码行数:8,代码来源:ChannelManagerImpl.java

示例8: AutoHost

import lt.ekgame.bancho.api.packets.Packet; //导入依赖的package包/类
public AutoHost(String... args) throws IOException, URISyntaxException, LoginException, ObjectMappingException {
	if (args.length == 0) {
		System.err.println("You must specify a settings file.");
		return;
	}
	
	instance = this;
	
	settings = new Settings(args[0]);
	perms = new Permissions(settings.operatorIds);
	
	bancho = new BanchoClient(settings.username, settings.password, false, true);
	bancho.getCommandHandler().addExecutor(new CommandsGeneral(this));
	bancho.getCommandHandler().addExecutor(new CommandsRoom(this, settings.osuApi));
	bancho.registerHandler(roomHandler = new RoomHandler(this));
	bancho.registerHandler((Packet packet) -> {
		if (packet instanceof PacketReceivingFinished) {
			System.out.println("Creating room...");
			MultiplayerHandler mp = bancho.getMultiplayerHandler();
			mp.enableMultiplayer();
			mp.createRoom(settings.roomName, settings.roomPassword, settings.roomSlots);
			if (settings.freemodsEnabled)
				mp.setFreeMods(true);
		}
		if (packet instanceof PacketRoomJoined) {
			System.out.println("Room created!");
		}
	});
	
	System.out.println("Running client...");
	bancho.connect();
	System.out.println("Authanticated, starting...");
	bancho.start();
	System.out.println("Started.");
}
 
开发者ID:ekgame,项目名称:osu-auto-host,代码行数:36,代码来源:AutoHost.java

示例9: handle

import lt.ekgame.bancho.api.packets.Packet; //导入依赖的package包/类
@Override
public void handle(Packet packet) {
	if (packet instanceof PacketRoomUpdate && isHost()) {
		PacketRoomUpdate update = (PacketRoomUpdate) packet;
		if (update.room.matchId == getMatchId()) {
			currentRoom = update.room;
		}
	}
	
	if (packet instanceof PacketRoomJoined) {
		PacketRoomJoined roomUpdate = (PacketRoomJoined) packet;
		currentRoom = roomUpdate.room;
		clientHandler.setStatus(UserStatus.MULTIPLAYER);
		clientHandler.sendStatusUpdate();
	}
	
	if (packet instanceof PacketRoomEveryoneLoaded) {
		bancho.sendPacket(new PacketRoomFinishMap());
		clientHandler.setStatus(UserStatus.MULTIPLAYING);
		clientHandler.sendStatusUpdate();
	}
	
	if (packet instanceof PacketRoomEveryoneFinished) {
		clientHandler.setStatus(UserStatus.MULTIPLAYER);
		clientHandler.sendStatusUpdate();
		setReady(false);
	}
}
 
开发者ID:ekgame,项目名称:bancho-client,代码行数:29,代码来源:MultiplayerHandler.java

示例10: handlePacket

import lt.ekgame.bancho.api.packets.Packet; //导入依赖的package包/类
private void handlePacket(Packet packet) {
	if (packet instanceof PacketReceivingFinished) {
		isConnected = true;
	}
	
	for (PacketHandler handler : packetHandlers)
		handler.handle(packet);
}
 
开发者ID:ekgame,项目名称:bancho-client,代码行数:9,代码来源:BanchoClient.java

示例11: handle

import lt.ekgame.bancho.api.packets.Packet; //导入依赖的package包/类
@Override
public void handle(Packet packet) {
	if (packet instanceof PacketProtocolVersion)
		protocolVersion = ((PacketProtocolVersion) packet).protocolVersion;
	
	if (packet instanceof PacketUserId)
		userId = ((PacketUserId) packet).userId;
	
	if (packet instanceof PacketReceivingFinished) {
		sendStatusUpdate();
		isConnected = true;
	}
}
 
开发者ID:ekgame,项目名称:bancho-client,代码行数:14,代码来源:ClientHandler.java

示例12: handlePacket

import lt.ekgame.bancho.api.packets.Packet; //导入依赖的package包/类
private void handlePacket(Packet packet) {
	synchronized (packetHandlers) {
		for (PacketHandler handler : packetHandlers)
			handler.handlePacket(packet);
	}
}
 
开发者ID:ekgame,项目名称:bancho-api,代码行数:7,代码来源:BanchoClientImpl.java

示例13: sendPacket

import lt.ekgame.bancho.api.packets.Packet; //导入依赖的package包/类
@Override
public void sendPacket(Packet packet) {
	synchronized (outgoingPackets) {
		outgoingPackets.add(packet);
	}
}
 
开发者ID:ekgame,项目名称:bancho-api,代码行数:7,代码来源:BanchoClientImpl.java

示例14: sendPacket

import lt.ekgame.bancho.api.packets.Packet; //导入依赖的package包/类
@Override
public void sendPacket(Packet packet) {
	synchronized (outgoing) {
		outgoing.add(packet);
	}
}
 
开发者ID:ekgame,项目名称:bancho-api,代码行数:7,代码来源:RateLimiterImpl.java

示例15: handle

import lt.ekgame.bancho.api.packets.Packet; //导入依赖的package包/类
@Override
public void handle(Packet packet) {
	MultiplayerHandler mp = bot.bancho.getMultiplayerHandler();
	
	if (packet instanceof PacketRoomJoined) {
		bot.beatmaps.reset();
		mp.setBeatmap(bot.beatmaps.nextBeatmap());
		timer = new TimerThread(this);
		timer.start();
	}
	
	if (packet instanceof PacketRoomUpdate && mp.isHost()) {
		PacketRoomUpdate update = (PacketRoomUpdate) packet;
		if (update.room.matchId == mp.getMatchId()) {
			byte[] status = update.room.slotStatus;
			String statuses = "";
			slotsTaken = 0;
			int slotsReady = 0;
			for (int i = 0; i < 16; i++)  {
				statuses += status[i] + " ";
				if (status[i] != 1 && status[i] != 2) {
					if (update.room.slotId[i] != bot.bancho.getClientHandler().getUserId()) {
						slotsTaken++;
						if (status[i] == 8)
							slotsReady++;
					}
				}
			}
			//System.out.println(statuses);
			if (slotsTaken > 0 && slotsTaken == slotsReady) {
				startGame();
				timer.skipEvents();
			}
		}
	}
	
	if (packet instanceof PacketRoomEveryoneFinished) {
		resetVoteSkip();
		mp.setBeatmap(bot.beatmaps.nextBeatmap());
		onBeatmapChange();
	}
}
 
开发者ID:ekgame,项目名称:osu-auto-host,代码行数:43,代码来源:RoomHandler.java


注:本文中的lt.ekgame.bancho.api.packets.Packet类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。