private void ReceiveOtherClientStatus(Protocol.BaseProtocol protocol) { Protocol.StatusProtocol status = protocol as Protocol.StatusProtocol; if (status.IsType(Protocol.StatusProtocol.Type.Client)) { if (status.ok) { currentGamePlayers.Add(nextLobbyId, new Client(status.from_client)); ++nextLobbyId; } else { foreach (KeyValuePair <int, Client> kp in currentGamePlayers) { if (kp.Value.nickname == status.from_client) { currentGamePlayers.Remove(kp.Key); PlayerDisconnected?.Invoke(kp.Key); break; } } } } GameInfoUpdated?.Invoke(); }
public void RemovePlayer(Player player) { lock (State) { var newPlayers = State.Players.ToList(); newPlayers.RemoveAll(x => x.Id == player.Id); State.Players = newPlayers.ToArray(); //IN-TESTING //Remove the player from any matches they were in /*var match = State.Matches.FirstOrDefault(x => x.Players.Contains(player)); * if (match != null) * { * match.Players = match.Players.Where(x => x != player).ToArray(); * UpdateMatch(match); * }*/ } NotifyPropertyChanged(nameof(State)); var @event = new Event(); @event.Type = Event.EventType.PlayerLeft; @event.ChangedObject = player; BroadcastToAllClients(new Packet(@event)); PlayerDisconnected?.Invoke(player); }
public void Disconnect() { if (isConnected) { GameManager.HandleClientDisconnect(); isConnected = false; tcp.Disconnect(); tcp = null; udp.Disconnect(); udp = null; ServerManagerTCP.Disconnect(); ServerManagerTCP = null; UnityEngine.Debug.Log("Disconnected from server."); OnConnectionChanged(new ClientConnectionEventArgs() { Success = !isConnected, Type = ClientConnectionEvent.Disconnect }); PlayerDisconnected?.Invoke(this, EventArgs.Empty); } }
public async Task RemovePlayer(Player player) { lock (State) { var playerToRemove = State.Players.FirstOrDefault(x => x.User.UserEquals(player.User)); State.Players.Remove(playerToRemove); } var @event = new Event { player_left_event = new Event.PlayerLeftEvent { Player = player } }; await Broadcast(new Packet { Event = @event }); if (PlayerDisconnected != null) { await PlayerDisconnected.Invoke(player); } }
private void PlayerDisconnected_Internal(NetworkPlayer player) { lock (players) { players.Remove(player); } PlayerDisconnected?.Invoke(player); }
public void RemovePlayer(string playPath, Guid sessionId) { if (Players.TryGetValue(playPath, out var players)) { players.Remove(sessionId); PlayerDisconnected?.Invoke(this, new RtmpEventArgs(sessionId, playPath)); } }
private void RemovePlayerRecieved(Player player) { var newPlayers = State.Players.ToList(); newPlayers.RemoveAll(x => x.Id == player.Id); State.Players = newPlayers.ToArray(); NotifyPropertyChanged(nameof(State)); PlayerDisconnected?.Invoke(player); }
internal void DeregisterPlayer(ulong playerId) { IMyPlayer player; if (players.TryGetValue(playerId, out player)) { players.Remove(playerId); player.IdentityChanged -= Player_IdentityChanged; } PlayerDisconnected?.Invoke(playerId, player); }
private void RemovePlayerReceived(Player player) { // TODO: This is garbage var newPlayers = State.Players.ToList(); newPlayers.RemoveAll(x => x.Id == player.Id); State.Players.Clear(); State.Players.AddRange(newPlayers); NotifyPropertyChanged(nameof(State)); PlayerDisconnected?.Invoke(player); }
protected override void ClientDisconnected(int clientId, string reason) { Console.Print(OutputLevel.Standard, "server", $"client disconnected. cid={clientId} addr={NetworkServer.ClientEndPoint(clientId)} reason='{reason}'"); if (Clients[clientId].State >= ServerClientState.Ready) { Clients[clientId].Quitting = true; PlayerDisconnected?.Invoke(clientId, reason); } Clients[clientId].State = ServerClientState.Empty; }
/// <summary> /// Method called when the server sends a message that another player disconnected /// </summary> /// <param name="parts"></param> private void PlayerDisconnectResolve(string[] parts) { PlayerColor disconnectedPlayer = Enum.Parse <PlayerColor>(parts[1]); PlayerInfos.Remove(disconnectedPlayer); if (_playerOrder != null) { _playerOrder.Remove(disconnectedPlayer); } if (_orderManager != null) { _orderManager.Properties.Remove(disconnectedPlayer); PlacesChanged?.Invoke(this, EventArgs.Empty); } PlayerDisconnected?.Invoke(this, disconnectedPlayer); }
void ViScPlayerDisconnected(long identityId) { try { IMyPlayer player = null; int playerIdx = -1; // don't use Utils.GetPlayerByIdentityId() because we need the safety of the local OnlinePlayers cache list. for (int i = 0; i < OnlinePlayers.Count; i++) { IMyPlayer p = OnlinePlayers[i]; if (p.IdentityId == identityId) { player = p; playerIdx = i; break; } } if (player == null) { ulong steamId = MyAPIGateway.Players.TryGetSteamId(identityId); Log.Info($"Unknown player disconnected, identityId={identityId.ToString()}; alternate identifier: '{Utils.PrintPlayerName(Utils.GetPlayerByIdentityId(identityId))}' (steamId={steamId.ToString()})"); return; } OnlinePlayers.RemoveAt(playerIdx); if (DebugLog) { Log.Info($"DEBUG: PlayerHandler :: {Utils.PrintPlayerName(player)} disconnected."); } try { PlayerDisconnected?.Invoke(player); } catch (Exception e) { Log.Error(e); } } catch (Exception e) { Log.Error(e); } }
private void OnDisconnected(SocketEndpoint obj) { string playerId = string.Empty; lock (playerIds) { if (playerIds.ContainsKey(obj.Address)) { playerId = playerIds[obj.Address]; } } if (playerId != string.Empty) { PlayerDisconnected?.Invoke(playerId); } }
private void SendCallback(IAsyncResult ar) { NetworkPlayer player = (NetworkPlayer)ar.AsyncState; try { // Retrieve the socket from the state object. var handler = player.workSocket; // Complete sending the data to the remote device. int bytesSent = handler.EndSend(ar); } catch (Exception e) { Console.WriteLine(e.ToString()); player.flagForRemoval = true; PlayerDisconnected?.Invoke(player); } }
public void Send(int playerId, byte[] data) { var player = players.First(x => x.id == playerId); try { //Get the socket for the specified playerId var socket = player.workSocket; // Begin sending the data to the remote device. socket.BeginSend(data, 0, data.Length, 0, new AsyncCallback(SendCallback), player); } catch (Exception e) { Console.WriteLine(e.ToString()); player.flagForRemoval = true; PlayerDisconnected?.Invoke(player); } }
void HandleInboundMessage(UdpMessage message) { switch (message.Event) { case "connected": Connected?.Invoke(); break; case "position": PositionUpdate?.Invoke(Deserialize <PositionUpdate>(message.Data.ToString())); break; case "newplayer": NewPlayer?.Invoke(new Guid(message.Data.ToString())); break; case "playerdisconnected": PlayerDisconnected?.Invoke(new Guid(message.Data.ToString())); break; case "newnetobj": NewNetObj?.Invoke(Deserialize <NetObj>(message.Data.ToString())); break; case "destroynetobj": NetObjDestroyed?.Invoke(new Guid(message.Data.ToString())); break; case "owner-changed": OwnerChanged?.Invoke(new Guid(message.Data.ToString())); break; default: Debug.LogError("Received invalid inbound message event: " + message.Event); break; } }
/// <summary> /// Disconnects player with given color. /// </summary> /// <param name="color">Color of the player</param> public void DisconnectPlayer(PlayerColor color) { if (CurrentState == ServerState.IN_LOBBY) { lock (MessageHandlerThread) { if (PlayersInGame.TryGetValue(color, out ClientHandlerSocket chs)) { chs.SendMessage(new ServerResponse() { Type = ServerResponseType.DISCONNECT }); chs.Stop(); PlayersInGame.Remove(color); PlayersNames.Remove(color); PlayerDisconnected.Invoke(color); } } } }
private void OnDataRetrieved(AbstractDatagram datagram) { switch (datagram.GetDatagramId()) { case RequestIdentifiers.PlayerConnected: { var userInfo = (datagram as PlayerConnectedRequestBody).UserInformation; PlayerConnected?.Invoke(userInfo); break; } case RequestIdentifiers.PlayerDisconnected: { var id = (datagram as PlayerDisconnectedRequestBody).UserIdentifier; PlayerDisconnected?.Invoke(id); } break; default: throw new ArgumentOutOfRangeException(); } }
private void ControllerCheckTimer_Elapsed(object sender, ElapsedEventArgs e) { if (!players.Contains(-1)) { players.Add(-1); PlayerConnected?.Invoke(new KeyboardController(-1)); } for (int i = 0; i < GamePad.MaximumGamePadCount; i++) { if (GamePad.GetState(i).IsConnected) { if (!players.Contains(i)) { players.Add(i); PlayerConnected?.Invoke(new GamepadController(i)); } } else if (players.Contains(i)) { PlayerDisconnected?.Invoke(i); } } }
protected virtual void Socket_ClientDisconnected(ClientHandlerSocket socket) { Console.WriteLine("Client disconnected."); // Find the player (if only spectator, do nothing) var disconnectedPlayer = PlayersInGame.FirstOrDefault(k => k.Value == socket); if (disconnectedPlayer.Value == null) { return; } // Disconnect the player PlayersInGame.Remove(disconnectedPlayer.Key); PlayerDisconnected.Invoke(disconnectedPlayer.Key); // Check if the game is still running and pause the game if (CurrentState == ServerState.IN_GAME) { PauseGame(); Restart(); } }
protected virtual void OnPlayerDisconnected(Player plr) { PlayerDisconnected?.Invoke(this, new PlayerEventArgs(plr)); }
public void HandleDisconnect() { PlayerDisconnected?.Invoke(this, EventArgs.Empty); GameObject.Destroy(this.gameObject); }
private void talker_SpringEvent(object sender, Talker.SpringEventArgs e) { try { switch (e.EventType) { case Talker.SpringEventType.PLAYER_JOINED: var entry = Context?.GetOrAddPlayer(e.PlayerName); if (entry != null) { entry.IsIngame = true; } PlayerJoined?.Invoke(this, new SpringLogEventArgs(e.PlayerName)); break; case Talker.SpringEventType.PLAYER_LEFT: entry = Context?.GetOrAddPlayer(e.PlayerName); if (entry != null) { entry.IsIngame = false; entry.QuitTime = (int)DateTime.UtcNow.Subtract(Context.IngameStartTime ?? Context.StartTime).TotalSeconds; } if (e.Param == 0) { PlayerDisconnected?.Invoke(this, new SpringLogEventArgs(e.PlayerName)); } PlayerLeft?.Invoke(this, new SpringLogEventArgs(e.PlayerName)); break; case Talker.SpringEventType.GAME_LUAMSG: HandleSpecialMessages(e); break; case Talker.SpringEventType.PLAYER_CHAT: if (e.Param == 255) { HandleSpecialMessages(e); } else { AddToLogs(e); } if ((PlayerSaid != null) && !string.IsNullOrEmpty(e.PlayerName)) { SpringChatLocation location = SpringChatLocation.Private; if (((e.Param == Talker.TO_EVERYONE) || (e.Param == Talker.TO_EVERYONE_LEGACY))) { location = SpringChatLocation.Public; } if (e.Param == Talker.TO_ALLIES) { location = SpringChatLocation.Allies; } if (e.Param == Talker.TO_SPECTATORS) { location = SpringChatLocation.Spectators; } PlayerSaid(this, new SpringChatEventArgs(e.PlayerName, e.Text, location)); } break; case Talker.SpringEventType.PLAYER_DEFEATED: MarkPlayerDead(e.PlayerName, true); if (PlayerLost != null) { PlayerLost(this, new SpringLogEventArgs(e.PlayerName)); } break; case Talker.SpringEventType.SERVER_GAMEOVER: if (!Context.GameEndedOk) // server gameover runs multiple times { foreach (var p in Context.ActualPlayers) { if (!p.IsIngame && !p.IsSpectator) { MarkPlayerDead(p.Name, true); } p.IsIngame = false; } // set victory team for all allied with currently alive if (e.winningAllyTeams.Length > 0) { foreach (var ally in e.winningAllyTeams) { foreach (var p in Context.ActualPlayers.Where(x => !x.IsSpectator && (x.AllyNumber == ally))) { p.IsVictoryTeam = true; } } } else // Fallback, shouldn't happen { foreach (var p in Context.ActualPlayers.Where(x => !x.IsSpectator && (x.LoseTime == null))) { foreach (var q in Context.ActualPlayers.Where(x => !x.IsSpectator && (x.AllyNumber == p.AllyNumber))) { q.IsVictoryTeam = true; } } } if (Context.IngameStartTime != null) { Context.GameEndedOk = true; Context.Duration = (int)DateTime.UtcNow.Subtract(Context.IngameStartTime ?? Context.StartTime).TotalSeconds; GameOver?.Invoke(this, new SpringLogEventArgs(e.PlayerName)); } else { Trace.TraceWarning("recieved GAMEOVER before STARTPLAYING!"); } Task.Delay(10000).ContinueWith(x => ExitGame()); } break; case Talker.SpringEventType.PLAYER_READY: if (e.Param == 1) { entry = Context.GetOrAddPlayer(e.PlayerName); if (entry != null) { entry.IsIngameReady = true; } } break; case Talker.SpringEventType.SERVER_STARTPLAYING: Context.ReplayName = e.ReplayFileName; Context.EngineBattleID = e.GameID; Context.IngameStartTime = DateTime.UtcNow; Context.PlayersUnreadyOnStart = Context.ActualPlayers.Where(x => !x.IsSpectator && !(x.IsIngameReady && x.IsIngame)).Select(x => x.Name).ToList(); foreach (var p in Context.ActualPlayers.Where(x => !x.IsSpectator)) { p.IsIngameReady = true; } process.PriorityClass = ProcessPriorityClass.High; BattleStarted(this, Context); break; case Talker.SpringEventType.SERVER_QUIT: if (LobbyStartContext != null) { foreach (var p in Context.ActualPlayers) { p.IsIngame = false; } } //if (GameOver != null) GameOver(this, new SpringLogEventArgs(e.PlayerName)); break; } } catch (Exception ex) { Trace.TraceError("Error processing spring message:{0}", ex); } }
private void Player_Disconnected(object sender, PlayerDisconnectedEventArgs e) { PlayerDisconnected?.Invoke(sender, e); }
public override void OnPhotonPlayerDisconnected(PhotonPlayer player) { PlayerDisconnected?.Invoke(); }
public virtual void OnPlayerDisconnect(Entity player) { Players.Remove(player); PlayerDisconnected?.Invoke(player); }
private static void OnPlayerDisconnected(PlayerIndex index) { PlayerDisconnected?.Invoke(index, currentGamePadState[(int)index]); }
public void PlayerHasDisconnected(CPlayer player) { PlayerDisconnected?.Invoke(this, player); }