protected virtual void OnPlayerDisconnected(PlayerDisconnectedEventArgs e) { EventHandler<PlayerDisconnectedEventArgs> handler = this.PlayerDisconnected; if (handler != null) { handler(this, e); } }
private void HandlePlayerDisconnected(object sender, PlayerDisconnectedEventArgs e) { //message written to the server console window when the palyer disconnects Console.WriteLine(e.Name + " has disconnected."); //house cleaning on disconnect! lock (playerLock) { for (int i = 0; i < players.Count; i++) { if (players[i].Equals((Player)sender)) { //let's remove those pesky event handlers since the player disconnected this.players[i].PlayerConnected -= HandlePlayerConnected; this.players[i].PlayerDisconnected -= HandlePlayerDisconnected; //and remove the player from the list this.players.RemoveAt(i); //and stop his thread //TODO: this is the "ungraceful" way. figure out how to do this better this.playerThreadList[i].Abort(); //then remove the thread from the list this.playerThreadList.RemoveAt(i); break; } } } }
private void HandlePlayerDisconnected(object sender, PlayerDisconnectedEventArgs e) { this.writeToClient(e.Name + " has disconnected.\r\n"); lock (playerlock) { if (this.players.Contains((Player)sender)) { this.players[this.players.IndexOf((Player)sender)].PlayerConnected -= this.HandlePlayerConnected; this.players[this.players.IndexOf((Player)sender)].PlayerMoved -= this.HandlePlayerMoved; this.players[this.players.IndexOf((Player)sender)].PlayerDisconnected -= this.HandlePlayerDisconnected; this.players[this.players.IndexOf((Player)sender)].PlayerFled -= this.HandlePlayerFled; this.players[this.players.IndexOf((Player)sender)].PlayerFleeFail -= this.HandlePlayerFleeFail; } } }