private static async Task StartServer() { Log.Print(LogType.Lobby, "Starting LobbyServer"); WebSocketListener server = new WebSocketListener(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 6060)); server.Standards.RegisterStandard(new WebSocketFactoryRfc6455()); // Server doesnt start if i await StartAsync... #pragma warning disable CS4014 server.StartAsync(); #pragma warning restore CS4014 Log.Print(LogType.Lobby, "Started LobbyServer on '0.0.0.0:6060'"); LobbyQueueManager.GetInstance(); while (true) { Log.Print(LogType.Lobby, "Waiting for clients to connect..."); WebSocket socket = await server.AcceptWebSocketAsync(CancellationToken.None); Log.Print(LogType.Lobby, "Client connected"); LobbyServerConnection newClient = new LobbyServerConnection(socket); newClient.OnDisconnect += NewClient_OnDisconnect; ConnectedClients.Add(newClient); new Thread(newClient.HandleConnection).Start(); } }
public static LobbyQueueManager GetInstance() { if (Instance == null) { Instance = new LobbyQueueManager(); } return(Instance); }
/// <summary> /// Creates a new game and puts all players in the pending games queue /// </summary> /// <param name="gameInfo"></param> /// <param name="teamInfo"></param> public static void CreateGame(LobbyGameInfo gameInfo, LobbyTeamInfo teamInfo) { Log.Print(LogType.Debug, "Creating Game for playes:"); foreach (var a in teamInfo.TeamPlayerInfo) { Log.Print(LogType.Debug, $" player {a.Handle} in team {a.TeamId.ToString()}"); } gameInfo.GameStatus = GameStatus.Assembling; LobbyQueueManager.GetInstance().PendingGames.Add(new PendingGame(gameInfo, teamInfo)); }
public async static Task OnJoinMatchmakingQueue(LobbyServerConnection client, JoinMatchmakingQueueRequest request) { await client.SendMessage(new JoinMatchmakingQueueResponse() { ResponseId = request.RequestId }); //Log.Print(LogType.Lobby, $"{client.PlayerInfo.GetHandle()} joined Matchmaking queue"); //client.PlayerInfo.SetGameType(request.GameType); client.AllyBotDifficulty = request.AllyBotDifficulty; client.EnemyBotDifficulty = request.EnemyBotDifficulty; LobbyQueueManager.AddPlayerToQueue(client); }