public void RemoveSpectator(ISpectator spectator) { for (int i = _spectators.Count; i >= 0; i--) { _spectators.Remove(spectator); } }
public void TestResumeGameIsOnGameResumedCalled() { IServer server = CreateServerWithHost(); server.StartServer(); IPlayer player1 = _factory.CreatePlayer(0, "player1", new CountCallTetriNETCallback()); IPlayer player2 = _factory.CreatePlayer(1, "player2", new CountCallTetriNETCallback()); ISpectator spectator1 = _factory.CreateSpectator(0, "spectator1", new CountCallTetriNETCallback()); ISpectator spectator2 = _factory.CreateSpectator(1, "spectator2", new CountCallTetriNETCallback()); _host.PlayerManager.Add(player1); _host.PlayerManager.Add(player2); _host.SpectatorManager.Add(spectator1); _host.SpectatorManager.Add(spectator2); server.StartGame(); server.PauseGame(); server.ResumeGame(); Assert.AreEqual(server.State, ServerStates.GameStarted); Assert.AreEqual((player1.Callback as CountCallTetriNETCallback).GetCallCount("OnGameResumed"), 1); Assert.AreEqual((player2.Callback as CountCallTetriNETCallback).GetCallCount("OnGameResumed"), 1); Assert.AreEqual((spectator1.Callback as CountCallTetriNETCallback).GetCallCount("OnGameResumed"), 1); Assert.AreEqual((spectator2.Callback as CountCallTetriNETCallback).GetCallCount("OnGameResumed"), 1); }
public void AddSpectator(ISpectator spectator) { if (!_spectators.Contains(spectator)) { _spectators.Add(spectator); } }
public void TestStopGameModificationOnServerAndPlayersAndSpectators() { IServer server = CreateServerWithHost(); server.StartServer(); IPlayer player1 = _factory.CreatePlayer(0, "player1", new CountCallTetriNETCallback()); IPlayer player2 = _factory.CreatePlayer(1, "player2", new CountCallTetriNETCallback()); ISpectator spectator1 = _factory.CreateSpectator(0, "spectator1", new CountCallTetriNETCallback()); ISpectator spectator2 = _factory.CreateSpectator(1, "spectator2", new CountCallTetriNETCallback()); _host.PlayerManager.Add(player1); _host.PlayerManager.Add(player2); _host.SpectatorManager.Add(spectator1); _host.SpectatorManager.Add(spectator2); server.StartGame(); server.StopGame(); Assert.AreEqual(server.State, ServerStates.WaitingStartGame); Assert.IsTrue(_host.PlayerManager.Players.All(x => x.State == PlayerStates.Registered)); Assert.AreEqual((player1.Callback as CountCallTetriNETCallback).GetCallCount("OnGameFinished"), 1); Assert.AreEqual((player2.Callback as CountCallTetriNETCallback).GetCallCount("OnGameFinished"), 1); Assert.AreEqual((spectator1.Callback as CountCallTetriNETCallback).GetCallCount("OnGameFinished"), 1); Assert.AreEqual((spectator2.Callback as CountCallTetriNETCallback).GetCallCount("OnGameFinished"), 1); }
public void TestResetWinListAreOnPublishServerMessageAndOnWinListModifiedCalled() { IServer server = CreateServerWithHost(); server.StartServer(); CountCallTetriNETCallback playerCallback1 = new CountCallTetriNETCallback(); CountCallTetriNETCallback playerCallback2 = new CountCallTetriNETCallback(); IPlayer player1 = _factory.CreatePlayer(0, "player1", playerCallback1); IPlayer player2 = _factory.CreatePlayer(1, "player2", playerCallback2); CountCallTetriNETCallback spectatorCallback1 = new CountCallTetriNETCallback(); CountCallTetriNETCallback spectatorCallback2 = new CountCallTetriNETCallback(); ISpectator spectator1 = _factory.CreateSpectator(0, "spectator1", spectatorCallback1); ISpectator spectator2 = _factory.CreateSpectator(1, "spectator2", spectatorCallback2); _host.PlayerManager.Add(player1); _host.PlayerManager.Add(player2); _host.SpectatorManager.Add(spectator1); _host.SpectatorManager.Add(spectator2); server.StartGame(); _host.GameLost(player1.Callback); // player has lost _actionQueue.Process(); // --> stop game because only one alive player left --> gene server.ResetWinList(); Assert.AreEqual(server.WinList.Count, 0); Assert.AreEqual(playerCallback1.GetCallCount("OnPublishServerMessage"), 1); Assert.AreEqual(playerCallback2.GetCallCount("OnPublishServerMessage"), 1); Assert.AreEqual(playerCallback1.GetCallCount("OnWinListModified"), 2); Assert.AreEqual(playerCallback2.GetCallCount("OnWinListModified"), 2); }
public GameManager(AppSettings settings, IReplayContextSetter contextSetter, ISpectator spectator, IGameController gameController, IObsController obsController) { this.settings = settings ?? throw new ArgumentNullException(nameof(settings)); this.contextSetter = contextSetter ?? throw new ArgumentNullException(nameof(contextSetter)); this.spectator = spectator ?? throw new ArgumentNullException(nameof(spectator)); this.gameController = gameController ?? throw new ArgumentNullException(nameof(gameController)); this.obsController = obsController ?? throw new ArgumentNullException(nameof(obsController)); }
private void OnPublishSpectatorMessage(ISpectator spectator, string msg) { Log.Default.WriteLine(LogLevels.Info, "PublishSpectatorMessage:{0}:{1}", spectator.Name, msg); // Send message to players and spectators foreach (IEntity entity in Entities) { entity.OnPublishPlayerMessage(spectator.Name, msg); } }
public bool Remove(ISpectator spectator) { for (int i = 0; i < MaxSpectators; i++) { if (_spectators[i] == spectator) { _spectators[i] = null; return(true); } } return(false); }
private static async void RunMatch(ISpectator spectator) { var ai0 = new Delayed(new SimpleAi.SimpleAi("A", "0")); var ai1 = new Delayed(new SimpleAi.SimpleAi("B", "0")); var ai2 = new Delayed(new SimpleAi.SimpleAi("C", "0")); var ai3 = new Delayed(new SimpleAi.SimpleAi("D", "0")); //var ai0 = new Delayed(new KanAi()); //var ai1 = new Delayed(new KanAi()); //var ai2 = new Delayed(new KanAi()); //var ai3 = new Delayed(new KanAi()); await Match.Start(ai0, ai1, ai2, ai3, spectator); }
private static void ResolveDependencies() { _leagueInfo = Container.Resolve <IGetLeagueInfo>(); _connection = Container.Resolve <IConnection>(); _summoner = Container.Resolve <IGetSummoner>(); _masters = Container.Resolve <IGetMasters>(); _leagueOfSummoner = Container.Resolve <IGetLeagueOfSummonerInformation>(); _serverService = Container.Resolve <IServerService>(); _summonerGame = Container.Resolve <IGetSummonerGame>(); _spectator = Container.Resolve <ISpectator>(); _lastGames = Container.Resolve <IGetLastGames>(); _printMethods = Container.Resolve <IPrintMethods>(); _dateHandler = Container.Resolve <IDateHandler>(); }
public void TestHostSpectatorLeftCalledOnDisconnection() { IHost host = CreateHost(); int count = 0; host.HostSpectatorLeft += (spectator1, reason) => count++; host.RegisterSpectator(new RaiseExceptionTetriNETCallback(), _clientVersion, "spectator1"); ISpectator spectator = host.SpectatorManager["spectator1"]; spectator.OnGamePaused(); // -> raise an exception -> disconnecting spectator Assert.AreEqual(count, 1); }
private static async Task Start(Decider decider, Board board, Wall wall, ISpectator spectator) { State state = new Start(); var spectatorBoard = new VisibleBoard(board); while (!state.IsFinal) { state.Update(board, wall); spectator.Updated(spectatorBoard); await state.Decide(board, decider); state = state.Advance(); } spectator.Updated(spectatorBoard); }
public virtual void HeartbeatSpectator(ITetriNETCallback callback) { //Log.Default.WriteLine(LogLevels.Debug, "Heartbeat"); ISpectator spectator = SpectatorManager[callback]; if (spectator != null) { //Log.Default.WriteLine("Heartbeat from {0}", player.Name); spectator.ResetTimeout(); // player alive } else { Log.Default.WriteLine(LogLevels.Warning, "HeartbeatSpectator from unknown spectator"); } }
public virtual void UnregisterSpectator(ITetriNETCallback callback) { Log.Default.WriteLine(LogLevels.Debug, "UnregisterPlayer"); ISpectator spectator = SpectatorManager[callback]; if (spectator != null) { // spectator.ResetTimeout(); // player alive // HostSpectatorUnregistered?.Invoke(spectator); } else { Log.Default.WriteLine(LogLevels.Warning, "UnregisterSpectator from unknown spectator"); } }
public bool Add(ISpectator spectator) { if (_spectators.Count >= MaxSpectators) { Log.Default.WriteLine(LogLevels.Warning, "Too many spectators"); return(false); } if (_spectators.ContainsKey(spectator.Callback)) { Log.Default.WriteLine(LogLevels.Warning, "{0} already registered", spectator.Name); return(false); } // _spectators.Add(spectator.Callback, spectator); // return(true); }
public virtual void PublishSpectatorMessage(ITetriNETCallback callback, string msg) { Log.Default.WriteLine(LogLevels.Debug, "PublishMessage {0}", msg); ISpectator spectator = SpectatorManager[callback]; if (spectator != null) { // spectator.ResetTimeout(); // player alive // HostSpectatorMessagePublished?.Invoke(spectator, msg); } else { Log.Default.WriteLine(LogLevels.Warning, "OnSpectatorMessagePublished from unknown spectator"); } }
private void OnRegisterSpectator(ISpectator spectator, int spectatorId) { Log.Default.WriteLine(LogLevels.Info, "New spectator:[{0}]{1}", spectatorId, spectator.Name); // Send spectator id back to spectator spectator.OnSpectatorRegistered(RegistrationResults.RegistrationSuccessful, Version, spectatorId, State == ServerStates.GameStarted || State == ServerStates.GamePaused, Options); // Inform new spectator about players foreach (IPlayer p in _playerManager.Players) { spectator.OnPlayerJoined(p.Id, p.Name, p.Team); } // Inform new spectator about other spectators foreach (ISpectator s in _spectatorManager.Spectators.Where(x => x != spectator)) { spectator.OnSpectatorJoined(s.Id, s.Name); } // Inform players and other spectators about new spectator connected foreach (IEntity entity in Entities.Where(x => x != spectator)) { entity.OnSpectatorJoined(spectatorId, spectator.Name); } // If game is running, send grid for playing player and game lost for dead player if (State == ServerStates.GamePaused || State == ServerStates.GameStarted) { foreach (IPlayer p in _playerManager.Players) { if (p.State == PlayerStates.Playing) { spectator.OnGridModified(p.Id, p.Grid); } else if (p.State == PlayerStates.GameLost) { spectator.OnPlayerLost(p.Id); } } } // Send win list spectator.OnWinListModified(_winList); }
public TenhouClient(IPlayer player, ISpectator spectator) { _player = player; _spectator = spectator; _lobby = _player.Lobby; _playerId = _player.Id; var folderName = MakeFolderName(_playerId); _directory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "TenhouAi", folderName); if (!Directory.Exists(_directory)) { Directory.CreateDirectory(_directory); } _sessionLogFileName = Path.Combine(_directory, Path.GetRandomFileName() + ".txt"); _wall = new FakeWall(); _board = new Board(_wall); _visibleBoard = new VisibleBoard(_board); }
public bool Add(ISpectator spectator) { bool alreadyExists = _spectators.Any(x => x != null && (x == spectator || x.Name == spectator.Name)); if (!alreadyExists) { // insert in first empty slot for (int i = 0; i < MaxSpectators; i++) { if (_spectators[i] == null) { _spectators[i] = spectator; return(true); } } } else { Log.Default.WriteLine(LogLevels.Warning, "{0} already registered", spectator.Name); } return(false); }
private void OnSpectatorLeft(ISpectator spectator, LeaveReasons reason) { Log.Default.WriteLine(LogLevels.Info, "Spectator left:{0} {1}", spectator.Name, reason); // Remove from spectator lock (_spectatorManager.LockObject) { // Remove spectator from spectator list _spectatorManager.Remove(spectator); } // Clean host tables foreach (IHost host in _hosts) { host.RemoveSpectator(spectator); } // Inform players and spectators except disconnected spectator foreach (IEntity entity in Entities.Where(x => x != spectator)) { entity.OnSpectatorLeft(spectator.Id, spectator.Name, reason); } }
public virtual void OnChatMessage(ISpectator spectator, string message) { }
void ISessionEventListener.OnChatMessage(ISpectator spectator, string message) { ConsoleHelper.SessionEvent("Chat: {0}: {1}", spectator.Name, message); }
public virtual void OnSpectatorJoinedSession(ISpectator spectator) { }
public virtual void OnSpectatorLeftSession(ISpectator spectator) { }
public bool Remove(ISpectator spectator) { return(_spectators.Remove(spectator.Callback)); }
public void OnSpectatorLeftSession(ISpectator spectator) { foreach(ISessionEventListener listener in mainListeners.ToArray()) listener.OnSpectatorLeftSession(spectator); }
private SpectatorNode GetSpectatorNode(ISpectator spectator) { int spectatorId = spectator.ID; try { return spectatorNodes[spectatorId]; } catch(KeyNotFoundException) { return spectatorNodes[spectatorId] = new SpectatorNode(spectator); } }
public override void OnChatMessage(ISpectator spectator, string message) { Gdk.Threads.Enter(); Gtk.TextBuffer buffer = parent.chatView.Buffer; Gtk.TextIter ti = buffer.EndIter; buffer.InsertWithTagsByName(ref ti, spectator.Name + ": ", "spectator"); buffer.Insert(ref ti, message + "\n"); parent.NotifyUrgent(); Gdk.Threads.Leave(); }
void ISessionEventListener.OnChatMessage(ISpectator spectator, string message) { }
public override void RemoveSpectator(ISpectator spectator) { // NOP }
private void OnUnregisterSpectator(ISpectator spectator) { Log.Default.WriteLine(LogLevels.Info, "Unregister spectator:{0}", spectator.Name); OnSpectatorLeft(spectator, LeaveReasons.Disconnected); }
void ISessionEventListener.OnSpectatorLeftSession(ISpectator spectator) { }
void ISessionEventListener.OnSpectatorJoinedSession(ISpectator spectator) { }
void ISessionEventListener.OnSpectatorJoinedSession(ISpectator spectator) { ConsoleHelper.SessionEvent("Spectator #{0} '{1}' joined the session.", spectator.ID, spectator.Name); }
private void RemoveSpectatorNode(ISpectator spectator) { int spectatorId = spectator.ID; spectatorNodes.Remove(spectatorId); }
void ISessionEventListener.OnSpectatorLeftSession(ISpectator spectator) { ConsoleHelper.SessionEvent("Spectator #{0} '{1}' left the session.", spectator.ID, spectator.Name); }
public override void OnSpectatorLeftSession(ISession session, ISpectator spectator) { if(session == parent.session) { Gdk.Threads.Enter(); SpectatorNode node = parent.GetSpectatorNode(spectator); parent.spectatorStore.RemoveNode(node); parent.RemoveSpectatorNode(spectator); node.Dispose(); Gdk.Threads.Leave(); } }
public abstract void RemoveSpectator(ISpectator spectator);
public SpectatorNode(ISpectator spectator) { this.spectator = spectator; Update(); }
public virtual void RegisterSpectator(ITetriNETCallback callback, Versioning clientVersion, string spectatorName) { Log.Default.WriteLine(LogLevels.Debug, "RegisterSpectator {0}", spectatorName); // TODO: check ban list RegistrationResults result = RegistrationResults.RegistrationSuccessful; ISpectator spectator = null; int id = -1; bool added = false; // TODO: smarter compatibility check if (clientVersion == null || (_serverVersion.Major != clientVersion.Major && _serverVersion.Minor != clientVersion.Minor)) { result = RegistrationResults.IncompatibleVersion; } else { lock (SpectatorManager.LockObject) { if (String.IsNullOrEmpty(spectatorName) || spectatorName.Length > 20) { result = RegistrationResults.RegistrationFailedInvalidName; Log.Default.WriteLine(LogLevels.Warning, "Cannot register {0} because name is invalid", spectatorName); } else if (SpectatorManager[spectatorName] != null || PlayerManager[spectatorName] != null) { result = RegistrationResults.RegistrationFailedPlayerAlreadyExists; Log.Default.WriteLine(LogLevels.Warning, "Cannot register {0} because it already exists", spectatorName); } else if (SpectatorManager.SpectatorCount >= SpectatorManager.MaxSpectators) { result = RegistrationResults.RegistrationFailedTooManyPlayers; Log.Default.WriteLine(LogLevels.Warning, "Cannot register {0} because too many spectators are already connected", spectatorName); } else { id = SpectatorManager.FirstAvailableId; if (id != -1) { spectator = Factory.CreateSpectator(id, spectatorName, callback); // spectator.ConnectionLost += OnEntityConnectionLost; // added = SpectatorManager.Add(spectator); } } } } if (added && id != -1 && result == RegistrationResults.RegistrationSuccessful) { // spectator.ResetTimeout(); // spectator alive // HostSpectatorRegistered?.Invoke(spectator, id); } else { Log.Default.WriteLine(LogLevels.Info, "Register failed for spectator {0}", spectatorName); // callback.OnSpectatorRegistered(result, _serverVersion, -1, false, null); } }
public static async Task Start(IPlayer p0, IPlayer p1, IPlayer p2, IPlayer p3, ISpectator spectator) { var wall = new Wall(); var board = new Board(wall); var decider = new Decider(board, new[] { p0, p1, p2, p3 }); await Start(decider, board, wall, spectator); }
void IServerEventListener.OnSpectatorLeftSession(ISession session, ISpectator spectator) { ConsoleHelper.ServerEvent("Spectator #{0} '{1}' left session #{2}.", spectator.ID, spectator.Name, session.ID); }
public void OnChatMessage(ISpectator spectator, string message) { foreach(ISessionEventListener listener in mainListeners.ToArray()) listener.OnChatMessage(spectator, message); }