57 lines
1.5 KiB
Python
Executable File
57 lines
1.5 KiB
Python
Executable File
#! /usr/bin/env python3
|
|
|
|
import socket
|
|
import threading
|
|
import settings
|
|
from ConnectionWorker import ConnectionWorker
|
|
from WorldManager import WorldManager
|
|
import threading
|
|
|
|
|
|
class Server(threading.Thread):
|
|
|
|
def __init__(self, wm: 'WorldManager', hostname: str, port: int):
|
|
self.wm = wm
|
|
self.hostname = hostname
|
|
self.port = port
|
|
super(Server, self).__init__()
|
|
|
|
def runMainServerThread(self, hostname: str, port: int):
|
|
assert port >= 1024 and port <= 65535
|
|
|
|
# TODO: here will be the main thread listening for new connections
|
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
|
s.bind((hostname, port))
|
|
s.listen()
|
|
while True:
|
|
conn, addr = s.accept()
|
|
|
|
# create a new worker thread for this connection
|
|
worker = ConnectionWorker(conn, addr, self.wm)
|
|
worker.start()
|
|
|
|
def run(self):
|
|
print("starting main server thread")
|
|
self.runMainServerThread(self.hostname, self.port)
|
|
|
|
|
|
def main():
|
|
raw_noise_cell_size = 32
|
|
raw_noise_chunk_size = 4
|
|
world_seed = 42
|
|
|
|
# create world:
|
|
wm = WorldManager(raw_noise_cell_size=raw_noise_cell_size,
|
|
raw_noise_chunk_size=raw_noise_chunk_size,
|
|
world_seed=world_seed)
|
|
|
|
wm.createEmptyChunk(0, 0, 0)
|
|
wm.applyPerlinToChunk(0, 0, 0)
|
|
|
|
server = Server(wm, settings.SERVER_HOST, settings.SERVER_PORT)
|
|
server.start()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|