Geyser/connector/src/main/java/org/geysermc/connector/network/ConnectorServerEventHandler...

75 lines
3.0 KiB
Java
Raw Normal View History

2019-07-08 23:35:32 +00:00
/*
2019-07-11 21:30:35 +00:00
* Copyright (c) 2019 GeyserMC. http://geysermc.org
2019-07-08 23:35:32 +00:00
*
2019-07-11 21:30:35 +00:00
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
2019-07-08 23:35:32 +00:00
*
2019-07-11 21:30:35 +00:00
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
2019-07-08 23:35:32 +00:00
*
* @author GeyserMC
* @link https://github.com/GeyserMC/Geyser
*/
package org.geysermc.connector.network;
2019-07-08 23:35:32 +00:00
import com.nukkitx.protocol.bedrock.BedrockPong;
import com.nukkitx.protocol.bedrock.BedrockServerEventHandler;
import com.nukkitx.protocol.bedrock.BedrockServerSession;
import com.nukkitx.protocol.bedrock.v361.Bedrock_v361;
2019-07-08 23:35:32 +00:00
import org.geysermc.connector.GeyserConnector;
import org.geysermc.connector.configuration.GeyserConfiguration;
import org.geysermc.connector.network.session.GeyserSession;
2019-07-08 23:35:32 +00:00
import java.net.InetSocketAddress;
public class ConnectorServerEventHandler implements BedrockServerEventHandler {
2019-07-08 23:35:32 +00:00
private GeyserConnector connector;
public ConnectorServerEventHandler(GeyserConnector connector) {
2019-07-08 23:35:32 +00:00
this.connector = connector;
}
@Override
public boolean onConnectionRequest(InetSocketAddress inetSocketAddress) {
System.out.println(inetSocketAddress + " tried to connect!");
2019-07-08 23:35:32 +00:00
return true;
}
@Override
public BedrockPong onQuery(InetSocketAddress inetSocketAddress) {
GeyserConfiguration config = connector.getConfig();
BedrockPong pong = new BedrockPong();
pong.setEdition("MCPE");
pong.setMotd(config.getBedrock().getMotd1());
pong.setSubMotd(config.getBedrock().getMotd2());
pong.setPlayerCount(1);
2019-07-08 23:35:32 +00:00
pong.setMaximumPlayerCount(config.getMaxPlayers());
pong.setGameType("Default");
pong.setNintendoLimited(false);
pong.setProtocolVersion(GeyserConnector.BEDROCK_PACKET_CODEC.getProtocolVersion());
return pong;
}
@Override
public void onSessionCreation(BedrockServerSession bedrockServerSession) {
bedrockServerSession.setLogging(true);
bedrockServerSession.setPacketHandler(new UpstreamPacketHandler(connector, new GeyserSession(connector, bedrockServerSession)));
bedrockServerSession.setPacketCodec(Bedrock_v361.V361_CODEC);
2019-07-08 23:35:32 +00:00
}
2019-07-08 23:35:32 +00:00
}