-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
Callback structure, important interfaces/classes
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
2023-12-11T20:25:22+0100 [teamprojekt_competition_server.client.client.COMPClient#info] Inizialized agent: 140432192338960 | ||
2023-12-11T20:25:22+0100 [teamprojekt_competition_server.client.client.COMPClient#info] version: 1 | ||
2023-12-11T20:25:22+0100 [teamprojekt_competition_server.client.client.COMPClient#info] Connected with token HelloWorldToken | ||
2023-12-11T20:25:23+0100 [teamprojekt_competition_server.client.client.COMPClient#info] Inizialized agent: 140183568677904 | ||
2023-12-11T20:25:23+0100 [teamprojekt_competition_server.client.client.COMPClient#info] version: 1 | ||
2023-12-11T20:25:23+0100 [teamprojekt_competition_server.client.client.COMPClient#info] Connected with token HelloWorldToken | ||
2023-12-11T20:33:44+0100 [teamprojekt_competition_server.client.client.COMPClient#info] Inizialized agent: 140671271353360 | ||
2023-12-11T20:33:44+0100 [teamprojekt_competition_server.client.client.COMPClient#info] version: 1 | ||
2023-12-11T20:33:44+0100 [teamprojekt_competition_server.client.client.COMPClient#info] Connected with token HelloWorldToken | ||
2023-12-11T20:33:46+0100 [teamprojekt_competition_server.client.client.COMPClient#info] Inizialized agent: 140397980761104 | ||
2023-12-11T20:33:46+0100 [teamprojekt_competition_server.client.client.COMPClient#info] version: 1 | ||
2023-12-11T20:33:46+0100 [teamprojekt_competition_server.client.client.COMPClient#info] Connected with token HelloWorldToken |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
2023-12-11T20:33:44+0100 [teamprojekt_competition_server.client.client_protocol.COMPClientProtocol#info] Initialized protocol: 140671236286992 with agent: 140671271353360, token: 140671262383408 | ||
2023-12-11T20:33:46+0100 [teamprojekt_competition_server.client.client_protocol.COMPClientProtocol#info] Initialized protocol: 140397948106592 with agent: 140397980761104, token: 140397969693744 | ||
2023-12-11T20:33:46+0100 [teamprojekt_competition_server.client.client_protocol.COMPClientProtocol#info] Receive StartGame command, game_id: 222 | ||
2023-12-11T20:33:46+0100 [teamprojekt_competition_server.client.client_protocol.COMPClientProtocol#info] Receive StartGame command, game_id: 222 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
2023-12-11T20:25:19+0100 [teamprojekt_competition_server.server.game_manager.GameManager#info] Initialized GameManager -> 140477668476768 | ||
2023-12-11T20:25:22+0100 [teamprojekt_competition_server.server.game_manager.GameManager#info] Added player with id: 0 | ||
2023-12-11T20:25:22+0100 [teamprojekt_competition_server.server.game_manager.GameManager#info] added player with id: 0 to queue | ||
2023-12-11T20:25:23+0100 [teamprojekt_competition_server.server.game_manager.GameManager#info] Added player with id: 1 | ||
2023-12-11T20:25:23+0100 [teamprojekt_competition_server.server.game_manager.GameManager#info] Matched two players: player1 0, player2 1 | ||
2023-12-11T20:25:23+0100 [teamprojekt_competition_server.server.game_manager.GameManager#info] Started game: 140477668480752 | ||
2023-12-11T20:33:24+0100 [teamprojekt_competition_server.server.game_manager.GameManager#info] Initialized GameManager -> 140512021235168 | ||
2023-12-11T20:33:44+0100 [teamprojekt_competition_server.server.game_manager.GameManager#info] Added player with id: 0 | ||
2023-12-11T20:33:44+0100 [teamprojekt_competition_server.server.game_manager.GameManager#info] added player with id: 0 to queue | ||
2023-12-11T20:33:46+0100 [teamprojekt_competition_server.server.game_manager.GameManager#info] Added player with id: 1 | ||
2023-12-11T20:33:46+0100 [teamprojekt_competition_server.server.game_manager.GameManager#info] Matched two players: player1 0, player2 1 | ||
2023-12-11T20:33:46+0100 [teamprojekt_competition_server.server.game_manager.GameManager#info] Started game: 140512021239152 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
2023-12-11T20:25:22+0100 [teamprojekt_competition_server.server.protocol.COMPServerProtocol#info] Initialized Protocol: 140477668478352 | ||
2023-12-11T20:25:23+0100 [teamprojekt_competition_server.server.protocol.COMPServerProtocol#info] Initialized Protocol: 140477668480416 | ||
2023-12-11T20:33:44+0100 [teamprojekt_competition_server.server.protocol.COMPServerProtocol#info] Initialized Protocol: 140512021236752 | ||
2023-12-11T20:33:46+0100 [teamprojekt_competition_server.server.protocol.COMPServerProtocol#info] Initialized Protocol: 140512021238816 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
2023-12-11T20:25:19+0100 [teamprojekt_competition_server.server.server.COMPServer#info] COMPServer 140477692281472 initialized with factory: 140477692281520 | ||
2023-12-11T20:25:19+0100 [teamprojekt_competition_server.server.server.COMPServer#info] Server: 140477692281472 now listening to localhost:1234 | ||
2023-12-11T20:25:27+0100 [teamprojekt_competition_server.server.server.COMPServer#info] Reactor running | ||
2023-12-11T20:33:24+0100 [teamprojekt_competition_server.server.server.COMPServer#info] COMPServer 140512046928736 initialized with factory: 140512046928496 | ||
2023-12-11T20:33:24+0100 [teamprojekt_competition_server.server.server.COMPServer#info] Server: 140512046928736 now listening to localhost:1234 | ||
2023-12-11T20:33:51+0100 [teamprojekt_competition_server.server.server.COMPServer#info] Reactor running |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
""" Hello World """ | ||
|
||
from twisted.internet.interfaces import IAddress | ||
from twisted.internet.protocol import Protocol, ServerFactory | ||
|
||
from .protocol import COMPServerProtocol | ||
from .player import COMPPlayer | ||
from .game_manager import game_manager | ||
|
||
|
||
class COMPServerFactory(ServerFactory): | ||
"""factory for COMP servers""" | ||
|
||
def buildProtocol(self, addr: IAddress) -> Protocol | None: | ||
"""builds the protocoll""" | ||
protocol: COMPServerProtocol = COMPServerProtocol() | ||
|
||
new_player = COMPPlayer(protocol) | ||
game_manager.add_player(new_player) | ||
|
||
return protocol |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
"""Structure which handles multiple games""" | ||
|
||
import logging as log | ||
from typing import Type | ||
|
||
from .interfaces import IPlayer, IGame | ||
|
||
|
||
class GameManager: | ||
"""manager for the games""" | ||
|
||
def __init__(self) -> None: | ||
self.players: list[IPlayer] = [] | ||
self.queue: list[int] = [] | ||
self.games: list[IGame] = [] | ||
self.GameClass: Type[IGame] | ||
|
||
def add_player(self, player: IPlayer) -> None: | ||
"""adds a player to the player list and gives it its index as id | ||
Args: | ||
player (IPlayer): player to add | ||
""" | ||
self.players.append(player) | ||
|
||
player.id = len(self.players) - 1 | ||
|
||
def add_player_to_queue(self, player_id: int): | ||
"""adds a player to the queue | ||
Args: | ||
player_id (int): id of the player | ||
""" | ||
if len(self.queue) > 0: | ||
player1 = self.players[self.queue.pop(0)] | ||
player2 = self.players[player_id] | ||
log.debug(f"matched two players: player {player1.id}, player {player2.id}") | ||
new_game = self.GameClass(players=[player1, player2]) | ||
self.games.append(new_game) | ||
new_game.start() | ||
else: | ||
self.queue.append(player_id) | ||
log.debug(f"added player to queue. ID: {player_id}") | ||
|
||
|
||
game_manager = GameManager() |