Skip to content

Commit

Permalink
Updated server.py
Browse files Browse the repository at this point in the history
  • Loading branch information
lapismyt committed Sep 3, 2023
1 parent 21a3574 commit c890068
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
21 changes: 18 additions & 3 deletions piebedrock/server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pieraknet import Server as RakNetServer
from pieraknet.packets.game_packet import GamePacket
from pieraknet.connection import Connection
from pieraknet.connection import Connection as RakNetConnection
import logging
import os
import time
Expand All @@ -22,6 +22,7 @@ def __init__(self, hostname="0.0.0.0", port=19132, logger=logging.getLogger("Pie
self.motd2 = "Server"
self.players_online = 0
self.max_players = 20
self.players = []
self._gamemode_map = {
"survival": ("Survival", 1),
"creative": ("Creative", 2),
Expand All @@ -46,14 +47,14 @@ def __init__(self, hostname="0.0.0.0", port=19132, logger=logging.getLogger("Pie
def set_gamemode(self, gamemode):
gm = gamemode.lower()
if (gm in self._gamemode_map.keys()):
self.gamemode = self._gamemode_map(gamemode)
self.gamemode = self._gamemode_map[gm]
else:
raise KeyError(f"Gamemode {str(gamemode)} not exists")

def update_server_status(self):
self.server_status = ";".join([
self.edition,
self.motd,
self.motd1,
str(self.protocol_version),
self.version_name,
str(self.players_online),
Expand All @@ -65,3 +66,17 @@ def update_server_status(self):
str(self.port),
str(self.port_v6),
])

def on_new_incoming_connection(self, connection: RakNetConnection):
self.logger.info(f"New Incoming Connection: {str(connection.address)}")

def on_disconnect(self, connection: RakNetConnection):
self.logger.info(f"Disconnected: {str(connection.address)}")

def start(self):
self.running = True
self.raknet_server.start()

if __name__ == "__main__":
server = BedrockServer()
server.start()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def readme():

setup(
name='PieBedrock',
version='1.0.0',
version='1.0.2',
author='lapismyt',
author_email='[email protected]',
description='Minecraft: Bedrock Edition network protocol implementation, written in Python. Created for PieMC.',
Expand Down

1 comment on commit c890068

@andiricum2
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

version 1.0.1 doesnt exist 😥

Please sign in to comment.