public void OnPlayerDisconnected(Session session, SessionPlayer player) { List<IServerEventListener> listeners = new List<IServerEventListener>(this.listeners); foreach(IServerEventListener l in listeners) sender.SendEvent(li => { li.OnPlayerDisconnected(session, player); }, l); }
public Player(Game game, SessionPlayer parent, Role role, CharacterType character) { this.game = game; this.parent = parent; control = new PlayerControl(this); this.role = role; this.character = Character.GetCharacter(this, character); additionalCharacters = new List<CharacterType>(); lifePoints = MaxLifePoints; hand = new List<Card>(); table = new List<TableCard>(); isAlive = true; isWinner = false; bangsPlayed = 0; turnsPlayed = 0; privateView = new PrivatePlayerViewProxy(this); }
public SessionPlayerControl(SessionPlayer player) { this.player = player; }
public Session(Server server, BinaryReader reader) { admin = new SessionAdmin(this); this.server = server; id = reader.ReadInt32(); try { BinaryFormatter bf = new BinaryFormatter(); data = (CreateSessionData)bf.Deserialize(reader.BaseStream); } catch(InvalidCastException) { throw new FormatException(); } catch(SerializationException) { throw new FormatException(); } try { state = (SessionState)reader.ReadInt32(); } catch(InvalidCastException) { throw new FormatException(); } if(state == SessionState.Playing) state = SessionState.GameFinished; creatorId = reader.ReadInt32(); gamesPlayed = reader.ReadInt32(); int playerCount = reader.ReadInt32(); if(playerCount < 0) throw new FormatException(); playerList = new List<SessionPlayer>(playerCount); players = new Dictionary<int, SessionPlayer>(playerCount); for(int i = 0; i < playerCount; i++) { bool isAI = reader.ReadBoolean(); SessionPlayer player = new SessionPlayer(this, reader); if(isAI && player.ID != creatorId) player.RegisterListener(new AI.AIPlayer()); playerList.Add(player); players.Add(player.ID, player); } spectatorList = new List<SessionSpectator>(); spectators = new Dictionary<int, SessionSpectator>(); eventMgr = new SessionEventManager(this); int currentSheriffId = reader.ReadInt32(); if(currentSheriffId != 0) { sheriffEnumerator = playerList.GetEnumerator(); do { if(!sheriffEnumerator.MoveNext()) throw new FormatException(); } while(sheriffEnumerator.Current.ID != currentSheriffId); } int remCharCount = reader.ReadInt32(); if(playerCount < 0) throw new FormatException(); remainingCharacters = new List<CharacterType>(remCharCount); for(int i = 0; i < remCharCount; i++) remainingCharacters.Add((CharacterType)reader.ReadInt32()); eventMgr.StartPolling(); }
public void RemovePlayer(SessionPlayer player) { lock(Lock) { player.UnregisterListener(); player.Control.Disconnect(); if(state != SessionState.WaitingForPlayers || player.IsCreator) { player.ResetControl(); eventMgr.OnPlayerDisconnected(player); return; } players.Remove(player.ID); playerList.Remove(player); eventMgr.OnPlayerLeftSession(player); player.Disconnect(); server.SaveState(); } }
public void Join(Password password, CreatePlayerData data, IPlayerSessionEventListener listener) { if(state == SessionState.Ended) throw new BadSessionStateException(); lock(Lock) { if(state != SessionState.WaitingForPlayers) throw new BadSessionStateException(); if(players.Count >= this.data.MaxPlayers) throw new TooManyPlayersException(); if(!this.data.PlayerPassword.CheckPassword(password)) throw new BadSessionPasswordException(); int id = players.GenerateID(); if(creatorId == 0) creatorId = id; SessionPlayer player = new SessionPlayer(id, this, data); players.Add(id, player); playerList.Add(player); player.RegisterListener(listener); eventMgr.SendController(player); eventMgr.OnPlayerJoinedSession(player); server.SaveState(); } }