//玩家退出游戏 public IAsyncResult BeginPlayerQuit(string playerID, AsyncCallback callback, object state) { IAsyncResult iAsyncResult = new CompletedAsyncResult <string>("player not in hall, exit hall with no ops!"); //如果玩家处于离线状态,则不要将其退出 if (this.SessionIDGameRoom.ContainsKey(playerID)) { GameRoom gameRoom = this.SessionIDGameRoom[playerID]; if (gameRoom.CurrentRoomState.CurrentGameState.Players.Exists(p => p != null && p.PlayerId == playerID)) { PlayerEntity player = gameRoom.CurrentRoomState.CurrentGameState.Players.Single(p => p != null && p.PlayerId == playerID); if (player.IsOffline && (DateTime.Now - player.OfflineSince).TotalSeconds <= gameRoom.CurrentRoomState.roomSetting.secondsToWaitForReenter) { return(iAsyncResult); } } } if (PlayerToIP.ContainsKey(playerID) && !this.PlayerToIP.ContainsValue(PlayerToIP[playerID])) { return(iAsyncResult); } PlayerExitRoom(playerID); string result = PlayerExitHall(playerID); return(new CompletedAsyncResult <string>(result)); }
private string PlayerExitHall(string playerID) { PlayerToIP.Remove(playerID); PlayersProxy.Remove(playerID); string result = string.Format("player {0} quit.", playerID); log.Debug(result); Thread.Sleep(500); Thread thr = new Thread(new ThreadStart(this.UpdateGameHall)); thr.Start(); return(result); }