public void Start() { // initial load LoadConfig().Wait(); _taskScheduler.ScheduleOnInterval(async() => { if (_isRequestingNow) { return; } _isRequestingNow = true; try { await LoadConfig(); } finally { _isRequestingNow = false; } _logger.Info($"Received {_serverList.Count()} server info records"); }, _config.Value.ServerInfoListUpdateIntervalMs, _config.Value.ServerInfoListUpdateIntervalMs); _logger.Info($"RouterServerInfoProvider started"); }
private void Listen() { foreach (var listener in PeerListeners) { listener.Listen(); Logger.Info($"Listening started on port: {listener.GetListenPort()}"); } }
public async Task <JoinRoomResult> CreateRoom(Guid groupId, Dictionary <Guid, Dictionary <byte, object> > players, Dictionary <byte, object> roomProperties) { //create room //var server = _serversCollection.GetLessLoadedServer(); var server = _serverProvider.GetLessLoadedServer(); if (server == null) { return new JoinRoomResult { Result = RoomOperationResult.ServerNotFound } } ; _logger.Info($"MmGroup: creating room on {server.Identity}"); //prepare players dict to send to room var playersToSendToRoom = new Dictionary <Guid, Dictionary <byte, object> >(); //move player from inner collection to new list foreach (var player in players) { //add additional property playersToSendToRoom.Add(player.Key, player.Value); } var room = RegisterRoom(groupId, roomProperties, Guid.NewGuid(), server, playersToSendToRoom); try { var url = UrlHelper.GetUrl(server.HttpPort, server.HttpsPort, server.Address); await _roomApiProvider.CreateRoom(url, room.Id, roomProperties, playersToSendToRoom); //add to queue lock (_roomQueueSync) { _roomsQueue.Enqueue(room); } var port = server.GetLessLoadedPort(); return(new JoinRoomResult { Address = server.Address, Port = port, RoomId = room.Id, Result = RoomOperationResult.OK }); } catch { DeregisterRoom(room.Id); return(new JoinRoomResult { Result = RoomOperationResult.CreateRoomError }); } }
public void Remove(Guid peerId) { lock (_syncCollection) { if (!_players.ContainsKey(peerId)) { _logger.Info($"Matchmaker.PlayerCollection error: Trying to delete non-existing player"); return; } var player = _players[peerId]; if (_playerToMmGroup.ContainsKey(peerId)) { var groupIds = _playerToMmGroup[peerId]; foreach (var groupId in groupIds) { if (_mmGroupToPlayer.ContainsKey(groupId)) { _mmGroupToPlayer[groupId].RemoveAll(p => p.Id == peerId); } } _playerToMmGroup.Remove(peerId); } _players.Remove(peerId); _mmMetrics.TrackPlayerRemoved(); } }
public void AddServer(ServerInfo serverInfo) { lock (_mutex) { serverInfo.Id = GetIndex(); _gameServerList.Add(serverInfo); _logger.Info($"Registered game server: {serverInfo.Identity}"); } }
private void CheckRoomsState() { foreach (var room in _rooms) { var roomValue = room.Value; if (roomValue.IsGameFinished() || IsTimeToForceRoomDestroy(roomValue)) { _logger.Error($"Room destroy with peers count {roomValue.GetPeerCount()}"); DeleteRoom(roomValue.GetRoomId()); } } _logger.Info($"Rooms state: Room count {GetRoomsCount()}, peers count {GetPlayersCount()}"); }
public void AddPlayerToMatchMaking(MatchMakingPlayer player) { lock (_mutex) { var groups = GetMatchmakingGroupIds(player.Properties); if (groups == null || groups.Count == 0) { _logger.Info($"AddPlayerToMatchMaking error: no groups for player"); groups = new List <Guid>(); groups.Add(AddMatchMakingGroup(player.Properties)); } _playersManager.Add(player, groups); } }
private async Task Load() { var requestNumber = _getBackendsListRequestCount++; //request backends list var serverInfos = await _routerClient.GetServerInfoList(false); if (!serverInfos.Any()) { return; } var meList = serverInfos.Where(s => s.Identity.Equals(_serverIdentity)).ToArray(); if (!meList.Any()) { _logger.Error($"BackendProvider.Load error: can not find me({_serverIdentity}) in serve list"); return; } if (meList.Length > 1) { _logger.Error($"BackendProvider.Load attention: more than 1 servers matched me - (record ids: {string.Join<int>(",",meList.Select(m=>m.Id))}) in serve list"); } _me = meList.First(); var backends = serverInfos.Where(s => s.ServerRole == ServerRole.BackEnd && s.Region == _me.Region && s.IsApproved && s.AreVersionsIntersect(_me)).ToList(); if (!backends.Any()) { _logger.Error($"Received 0 backends from Router!"); } else { if (requestNumber == 1) { _logger.Info($"Received {backends.Count} backends from Router"); } _backends = backends; } }
public virtual bool OnNewClientConnect(IPEndPoint endPoint) { _logger.Info($"Connected: {endPoint.Address} : {endPoint.Port}"); try { if (_protectionManager.IsBanned(endPoint)) { return(false); } _protectionManager.PeerConnected(endPoint); //add peer to collection PeerCollection.Add(endPoint, _reliableSocket); return(true); } catch (Exception e) { _logger.Error($"OnNewClientConnect error: {e}"); return(false); } }
private async Task GetList() { if (_isRequestingNow) { return; } _isRequestingNow = true; try { _serverList = await _routerClient.GetServerInfoList(false); _gameServerList = BuildGameServersList(); _logger.Info($"MatchMakerServerInfoProvider.GetServerInfoListResponse: i have {_gameServerList.Count()} game servers"); } finally { _isRequestingNow = false; } }
protected void LogInfo(string message) { Logger.Info("Router.Web", $"{ControllerContext.ActionDescriptor.ControllerName}.{ControllerContext.ActionDescriptor.ActionName}", message); }
private void OnDisconnected(IDisconnectInfo disconnectInfo) { _logger.Info($"Disconnected from server: {disconnectInfo.Reason}"); OnDisconnectedFromServer?.Invoke(disconnectInfo); }