Ejemplo n.º 1
0
        private void Player_Exited(object sender, Networking.Common.Peer e)
        {
            ServerPlayer sp = e as ServerPlayer;

            if (sp == null || !PlayerList.Contains(sp))
            {
                return;
            }

            lock (PlayerList)
                PlayerList.Remove(sp);

            MsgRemovePlayer exit = new MsgRemovePlayer();

            exit.PlayerID = sp.PlayerID;
            SendToAll(exit, false);

            if (Teams.ContainsKey(sp.ActualTeam))
            {
                Teams[sp.ActualTeam].Remove(sp);
            }
        }
Ejemplo n.º 2
0
 protected static bool SimpleSpawn(ServerPlayer player, GameWorld map, ref Vector3F position, ref float rotation)
 {
     return(map.GetSpawn(ref player.Info.LastSpawnState.Position, ref player.Info.LastSpawnState.Azimuth));
 }
Ejemplo n.º 3
0
        public void KillPlayer(ServerPlayer player, KilledEventArgs args)
        {
            if (args == null || player == null)
            {
                return;
            }

            if (!player.Info.Alive)
            {
                Logger.Log0("Player " + player.Callsign + " killed while dead");
            }

            player.Info.Alive = false;

            PlayerKilled?.Invoke(this, args);

            Logger.Log4("Player " + player.Callsign + " killed by " + args.KillInfo.Reason.ToString());

            bool wasFromAFlag = false;

            switch (args.KillInfo.Reason)
            {
            case BlowedUpReasons.GotKilledMsg:
                break;

            case BlowedUpReasons.GotShot:
                wasFromAFlag = true;
                Shots.RemoveShotForDeath(player, args.KillInfo.KillerID, args.KillInfo.ShotID);

                if (args.Shot != null)    // tell the flag it took a hit
                {
                    Flags.HandlePlayerTakeHit(player, args.Killer, args.Shot);
                }
                break;

            case BlowedUpReasons.GotRunOver:
                wasFromAFlag = true;
                break;

            case BlowedUpReasons.GotCaptured:
                break;

            case BlowedUpReasons.GenocideEffect:
                break;

            case BlowedUpReasons.SelfDestruct:
                break;

            case BlowedUpReasons.WaterDeath:
                break;

            case BlowedUpReasons.DeathTouch:
                break;

            case BlowedUpReasons.LastReason:
            case BlowedUpReasons.Unknown:
                Logger.Log0("Player " + player.Callsign + " killed by a method that should not happen");
                break;
            }

            if (wasFromAFlag)   // tell the flag it killed
            {
                Flags.HandlePlayerDoDamage(player, args.Killer, FlagTypeList.GetFromAbriv(args.KillInfo.FlagAbreviation));
            }

            // process any scores
            PlayerInfo.ScoreInfo vicScores    = new PlayerInfo.ScoreInfo();
            PlayerInfo.ScoreInfo killerScores = new PlayerInfo.ScoreInfo();
            if (ComputeScores(args.Victim, ref vicScores, args.Killer, ref killerScores, args.KillInfo.Reason))
            {
                args.Victim.Info.Score.ApplyScore(vicScores);
                if (args.Killer != null)
                {
                    args.Killer.Info.Score.ApplyScore(killerScores);
                }

                MsgScore scoreMessage = new MsgScore();
                if (!vicScores.Empty)
                {
                    Logger.Log3("Player " + player.Callsign + " score updated by " + vicScores.ToString());

                    ScoreUpdated?.Invoke(this, args.Victim);
                    args.Victim.Info.Score.Pack(args.Victim.PlayerID, scoreMessage);
                }

                if (args.Killer != null && !killerScores.Empty)
                {
                    Logger.Log3("Player " + player.Callsign + " score updated by " + killerScores.ToString());

                    ScoreUpdated?.Invoke(this, args.Killer);
                    args.Killer.Info.Score.Pack(args.Killer.PlayerID, scoreMessage);
                }

                if (scoreMessage.Scores.Count > 0)
                {
                    SendToAll(scoreMessage, false);
                }
            }

            MsgKilled killedMessage = new MsgKilled();

            killedMessage.VictimID        = args.Victim.PlayerID;
            killedMessage.KillerID        = args.Killer != null ? args.Killer.PlayerID : PlayerConstants.ServerPlayerID;
            killedMessage.ShotID          = args.Shot != null ? args.Shot.PlayerShotID : -1;
            killedMessage.Reason          = args.KillInfo.Reason;
            killedMessage.FlagAbreviation = (args.Shot != null && args.Shot.SourceFlag != null) ? args.Shot.SourceFlag.FlagAbbv : string.Empty;
            killedMessage.PhysicsDriverID = args.KillInfo.PhysicsDriverID;

            SendToAll(killedMessage, false);
        }
Ejemplo n.º 4
0
        public virtual bool AddPlayer(ServerPlayer player)
        {
            player.Exited       += Player_Exited;
            player.Disconnected += Player_Exited;

            ServerHost.PreAddPlayer(player);

            if (player.ActualTeam == TeamColors.NoTeam)
            {
                return(false);
            }

            player.Info = new PlayerInfo();

            lock (PlayerList)
                PlayerList.Add(player);

            Logger.Log2("Player " + player.Callsign + " assigned to team " + player.ActualTeam.ToString());

            lock (Teams)
            {
                if (!Teams.ContainsKey(player.ActualTeam))
                {
                    TeamInfo team = new TeamInfo();
                    team.Team           = player.ActualTeam;
                    team.PlayerAdded   += Team_PlayerAdded;
                    team.PlayerRemoved += Team_PlayerRemoved;
                    Teams.Add(player.ActualTeam, team);
                }

                Teams[player.ActualTeam].Add(player);
                if (Teams[player.ActualTeam].Members.Count == 1)
                {
                    TeamInited?.Invoke(this, Teams[player.ActualTeam]);
                }
            }

            Flags.SendInitialFlagUpdate(player);

            // tell them about everyone except them
            ServerPlayer[] locals = null;

            lock (PlayerList)
                locals = PlayerList.ToArray();

            MsgPlayerInfo info = new MsgPlayerInfo();

            foreach (ServerPlayer peer in locals)
            {
                if (peer == player)
                {
                    continue;
                }

                player.SendMessage(true, BuildPlayerAdd(peer));
                info.PlayerUpdates.Add(GetPlayerInfo(peer));
            }
            player.SendMessage(true, info);

            TeamInfo[] teams = null;
            lock (Teams)
                teams = Teams.Values.ToArray();

            MsgTeamUpdate tUpd = new MsgTeamUpdate();

            foreach (var team in teams)
            {
                if (team.Team == player.ActualTeam) // the event already sent this
                {
                    continue;
                }

                MsgTeamUpdate.TeamUpdate u = new MsgTeamUpdate.TeamUpdate();
                u.TeamID = team.Team;
                u.Size   = team.Size();
                u.Wins   = team.Wins;
                u.Losses = team.Losses;
                tUpd.TeamUpdates.Add(u);
            }
            player.SendMessage(tUpd);

            // tell everyone they joined
            SendToAll(BuildPlayerAdd(player), false);

            // send info bits to everyone
            info = new MsgPlayerInfo();
            info.PlayerUpdates.Add(GetPlayerInfo(player));
            SendToAll(info, false);

            ServerHost.PostAddPlayer(player);

            if (player.ActualTeam == TeamColors.ObserverTeam)
            {
                Chat.SendChatToUser(null, player, Resources.ObserverModeNotificatioMessage, false);
            }

            return(true);
        }
Ejemplo n.º 5
0
 public ShotHitArgs(ShotInfo s, ServerPlayer p)
 {
     Shot = s; Target = p;
 }
Ejemplo n.º 6
0
        public void UpdateShot(ShotInfo shot, Vector3F postion, Vector3F velocity, float delta, ServerPlayer target)
        {
            if (shot == null || target == null)
            {
                return;
            }

            shot.UpdateTimestamp = GameTime.Now;
            shot.UpdatePostion   = postion;
            shot.UpdateVector    = velocity;

            ShotUpdatedEventArgs args = new ShotUpdatedEventArgs();

            args.Shot   = shot;
            args.Target = target;

            ShotPreUpdate?.Invoke(this, args);

            MsgGMUpdate update = new MsgGMUpdate();

            if (shot.Owner != null)
            {
                update.PlayerID = shot.Owner.PlayerID;
            }
            else
            {
                update.PlayerID = PlayerConstants.ServerPlayerID;
            }

            update.ShotID    = shot.PlayerShotID;
            update.TargetID  = args.Target.PlayerID;
            update.Position  = shot.UpdatePostion;
            update.Velocity  = shot.UpdateVector;
            update.DeltaTime = delta;
            update.Team      = shot.TeamColor;

            Players.SendToAll(update, false);
            ShotUpdated?.Invoke(this, shot);
        }
Ejemplo n.º 7
0
        public void HandleChatMessage(ServerPlayer sender, MsgMessage message)
        {
            // check all the ways we can ingore this
            if (message == null)
            {
                return;
            }

            bool isAction = IsMeCommand(message);

            if (!isAction)
            {
                if (AcceptTextCommand != null && AcceptTextCommand(sender, message))
                {
                    return;
                }
            }
            else if (message.MessageText.Length < 5)
            {
                return;
            }

            if (!sender.Allowances.AllowChat)
            {
                return;
            }

            ChatMessageEventArgs inChat = new ChatMessageEventArgs();

            inChat.To       = null;
            inChat.Allow    = true;
            inChat.Filtered = false;
            inChat.From     = sender;
            inChat.Action   = isAction;
            if (isAction)
            {
                inChat.MessageText = message.MessageText.Substring(3);
            }
            else
            {
                inChat.MessageText = message.MessageText;
            }

            if (message.To <= PlayerConstants.MaxUseablePlayerID)
            {
                inChat.To = Players.GetPlayerByID(message.To);
                if (inChat.To == null)
                {
                    return;
                }
                inChat.ToTeam   = inChat.To.ActualTeam;
                inChat.ChatType = ChatMessageEventArgs.ChatMessageTypes.PrivateMessage;
            }
            else if (message.To == PlayerConstants.AllPlayersID)
            {
                inChat.ChatType = ChatMessageEventArgs.ChatMessageTypes.PublicMessage;
            }
            else if (message.To >= PlayerConstants.FirstTeamID && message.To <= PlayerConstants.LastTeamID)
            {
                TeamColors toTeam = PlayerConstants.GetTeamColorFromID(message.To);

                if (toTeam != sender.ActualTeam || Players.GetTeamPlayerCount(toTeam) == 0)
                {
                    return;
                }

                inChat.ToTeam   = toTeam;
                inChat.ChatType = ChatMessageEventArgs.ChatMessageTypes.TeamMessage;
            }
            else
            {
                foreach (var group in GetGroups())
                {
                    if (message.To == group.BroadcastID)
                    {
                        inChat.To       = null;
                        inChat.ToGroup  = group;
                        inChat.ChatType = ChatMessageEventArgs.ChatMessageTypes.GroupMessage;
                    }
                }
            }

            if (inChat.ChatType == ChatMessageEventArgs.ChatMessageTypes.Unknown)
            {
                return;
            }

            MessageReceived?.Invoke(this, inChat);
            if (!inChat.Allow)
            {
                return;
            }

            PushMessageToFilter(inChat);
        }
Ejemplo n.º 8
0
 private void Jail_ReleasePlayer(object sender, BZFlag.Game.Host.Players.ServerPlayer e)
 {
     throw new NotImplementedException();
 }