public void OnStateFluxGameInstanceLeft(GameInstanceLeftMessage message) { DebugLog($"Player {message.Player.Name} left {message.GameName}:{message.InstanceName}"); if (message.Player.Name == LastUsername) { // we are no longer hosting a game, because we left it _hostingGame = false; } }
public void LeaveGameInstance(LeaveGameInstanceMessage message) { var currentPlayer = _websocket.GetCurrentSessionPlayer(); Assert.ThrowIfNull(currentPlayer, "requires a user session", _websocket); var game = Server.Instance.Games.FirstOrDefault(g => g.Name == message.GameName); Assert.ThrowIfNull(game, $"game {game.Name} not found", _websocket); var gameInstance = game.Instances.FirstOrDefault(g => g.Name == message.InstanceName); Assert.ThrowIfNull(gameInstance, $"game instance {game.Name}:{message.InstanceName} not found", _websocket); if (gameInstance != null) { Server.Instance.LeaveGameInstance(gameInstance, _websocket.GetCurrentSessionPlayer()); _websocket.LogMessage($"Player left game instance '{message.GameName}:{message.InstanceName}'"); var broadcastMessage = new GameInstanceLeftMessage() { Player = currentPlayer, GameName = message.GameName, InstanceName = message.InstanceName }; _websocket.Broadcast(broadcastMessage, null, true); } }
IEnumerator ReceiveAndDispatchMessages() { while (!connection.SocketOpenWithIdentity) { foreach (var listener in listeners) { listener.OnStateFluxWaitingToConnect(); } yield return(new WaitForSeconds(1)); } while (true) { openWithIdentity = connection.SocketOpenWithIdentity; if (!connected && openWithIdentity) { connected = true; userName = connection.UserName; foreach (var listener in listeners) { listener.OnStateFluxConnect(); } } else if (connected && !openWithIdentity) { connected = false; userName = ""; foreach (var listener in listeners) { listener.OnStateFluxDisconnect(); } } bool draining = true; int drainingCount = 50; while (draining && (drainingCount--) > 0) { StateFlux.Model.Message message = connection.ReceiveResponse(); draining = (message != null); if (draining) { if (message.MessageType == MessageTypeNames.HostStateChanged) { // FIXME: convert all the others to linq method ForEach listeners.ForEach(l => l.OnStateFluxHostStateChanged((HostStateChangedMessage)message)); } else if (message.MessageType == MessageTypeNames.MiceChanged) { MiceChangedMessage msg = (MiceChangedMessage)message; foreach (var listener in listeners) { listener.OnStateFluxMiceChanged(msg); } } else if (message.MessageType == MessageTypeNames.HostCommandChanged) { HostCommandChangedMessage msg = (HostCommandChangedMessage)message; foreach (var listener in listeners) { listener.OnStateFluxHostCommandChanged(msg); } } else if (message.MessageType == MessageTypeNames.GuestCommandChanged) { GuestCommandChangedMessage msg = (GuestCommandChangedMessage)message; foreach (var listener in listeners) { listener.OnStateFluxGuestCommandChanged(msg); } } else if (message.MessageType == MessageTypeNames.GuestInputChanged) { GuestInputChangedMessage msg = (GuestInputChangedMessage)message; foreach (var listener in listeners) { listener.OnStateFluxGuestInputChanged(msg); } } else if (message.MessageType == MessageTypeNames.PlayerListing) { PlayerListingMessage msg = (PlayerListingMessage)message; foreach (var listener in listeners) { listener.OnStateFluxPlayerListing(msg); } } else if (message.MessageType == MessageTypeNames.GameInstanceCreated) { GameInstanceCreatedMessage msg = (GameInstanceCreatedMessage)message; foreach (var listener in listeners) { listener.OnStateFluxGameInstanceCreated(msg); } } else if (message.MessageType == MessageTypeNames.GameInstanceListing) { GameInstanceListingMessage msg = (GameInstanceListingMessage)message; foreach (var listener in listeners) { listener.OnStateFluxGameInstanceListing(msg); } } else if (message.MessageType == MessageTypeNames.GameInstanceJoined) { GameInstanceJoinedMessage msg = (GameInstanceJoinedMessage)message; foreach (var listener in listeners) { listener.OnStateFluxGameInstanceJoined(msg); } } else if (message.MessageType == MessageTypeNames.GameInstanceStart) { GameInstanceStartMessage msg = (GameInstanceStartMessage)message; Debug.Log($"Game start message, host is {msg.Host.Name}"); Debug.Log($"Current player name is {connection.CurrentPlayer.Name}"); isHosting = (msg.Host.Name == connection.CurrentPlayer.Name); foreach (var listener in listeners) { listener.OnStateFluxGameInstanceStart(msg); } } else if (message.MessageType == MessageTypeNames.GameInstanceStopped) { GameInstanceStoppedMessage msg = (GameInstanceStoppedMessage)message; Debug.Log($"Game stopped message, host is {msg.Host.Name}"); Debug.Log($"Current player name is {connection.CurrentPlayer.Name}"); isHosting = (msg.Host.Name == connection.CurrentPlayer.Name); foreach (var listener in listeners) { listener.OnStateFluxGameInstanceStopped(msg); } } else if (message.MessageType == MessageTypeNames.GameInstanceLeft) { GameInstanceLeftMessage msg = (GameInstanceLeftMessage)message; Debug.Log($"Player {msg.Player.Name} left {msg.GameName}:{msg.InstanceName}"); Debug.Log($"Current player name is {connection.CurrentPlayer.Name}"); foreach (var listener in listeners) { listener.OnStateFluxGameInstanceLeft(msg); } } else if (message.MessageType == MessageTypeNames.ChatSaid) { ChatSaidMessage msg = (ChatSaidMessage)message; foreach (var listener in listeners) { listener.OnStateFluxChatSaid(msg); } } else if (message.MessageType == MessageTypeNames.ServerError) { ServerErrorMessage msg = (ServerErrorMessage)message; foreach (var listener in listeners) { listener.OnStateFluxServerError(msg); } } else { foreach (var listener in listeners) { listener.OnStateFluxOtherMessage(message); } } } } yield return(null); } }
public void OnStateFluxGameInstanceLeft(GameInstanceLeftMessage message) { }