Beispiel #1
0
        public void PlayerCreated(object sender, PlayerCreatedEventArgs pcea)
        {
            Peer peer     = (Peer)sender;
            int  playerID = pcea.Message.PlayerID;
            PlayerInformation playerInfo = peer.GetPeerInformation(playerID);

            // See if the player that was just created is us
            if (playerInfo.Local)
            {
                localPlayer.ID   = playerID;
                localPlayer.Name = playerInfo.Name;
            }
            // If not, create a remote player
            else
            {
                Ship newShip = new Ship(this);
                newShip.HostName     = playerInfo.Name.ToUpper();
                newShip.State        = (int)ShipState.Normal;
                newShip.ScreenBounds = this.windowBounds;
                RemotePlayer newPlayer = new RemotePlayer(playerID, playerInfo.Name, newShip);
                lock (otherPlayers) {
                    otherPlayers.Add(playerID, newPlayer);
                }
            }
        }
Beispiel #2
0
        public void PlayerCreated(object sender, PlayerCreatedEventArgs pcea)
        {
            Peer peer1    = (Peer)sender;
            int  playerID = pcea.Message.PlayerID;
            PlayerInformation playerInfo = peer1.GetPeerInformation(playerID);


            if (playerInfo.Local)
            {
                ID   = playerID;
                Name = playerInfo.Name;
            }
            else
            {
                Heli.Helicopter h         = new Heli.Helicopter(playerInfo.Name + playerID, @"dane\heliData.xml", true);
                RemotePlayer    newPlayer = new RemotePlayer(playerID, playerInfo.Name, h);


                curLevel.AddObject(h);

                factory.InsertObject(h);
                lock (otherPlayers)
                {
                    otherPlayers.Add(playerID, newPlayer);
                }
            }
        }
 private void OnPlayerCreated(object sender, PlayerCreatedEventArgs e)
 {
     try
     {
         string playerName = ((Server)sender).GetClientInformation(e.Message.PlayerID).Name;
         NewPlayerList.Add(playerName);
     }
     catch { /* Ignore this, probably the server */ }
 }
 /// <summary>
 // These are the events the app will handle
 // when DPlay fires them.
 /// </summary>
 private void PlayerCreated(object sender, PlayerCreatedEventArgs dpMessage)
 {
     // Get the PlayerInformation and store it
     PlayerInformation dpPeer = peerObject.GetPeerInformation(dpMessage.Message.PlayerID);
     Players oPlayer = new Players(dpMessage.Message.PlayerID,dpPeer.Name);
     // We lock the data here since it is shared across multiple threads.
     lock (PlayerList) {
         PlayerList.Add(oPlayer);
     }
     // Save this player id if it's ourselves
     if (dpPeer.Local)
         LocalPlayerID = dpMessage.Message.PlayerID;
 }
    /// <summary>
    // These are the events the app will handle
    // when DPlay fires them.
    /// </summary>
    private void PlayerCreated(object sender, PlayerCreatedEventArgs dpMessage)
    {
        // Get the PlayerInformation and store it
        PlayerInformation dpPeer  = peerObject.GetPeerInformation(dpMessage.Message.PlayerID);
        Players           oPlayer = new Players(dpMessage.Message.PlayerID, dpPeer.Name);

        // We lock the data here since it is shared across multiple threads.
        lock (PlayerList) {
            PlayerList.Add(oPlayer);
        }
        // Save this player id if it's ourselves
        if (dpPeer.Local)
        {
            LocalPlayerID = dpMessage.Message.PlayerID;
        }
    }
Beispiel #6
0
 private void OnPlayerCreated(object sender, PlayerCreatedEventArgs e)
 {
     try
     {
         Shared.SharedCode.EnemyPlayer.Name = ((Server)sender).GetClientInformation(e.Message.PlayerID).Name;
         MessageBox.Show(string.Format("Установлено новое соединение с {0}", Shared.SharedCode.EnemyPlayer.Name), "", MessageBoxButtons.OK, MessageBoxIcon.Information);
         connected = true;
         playerID  = e.Message.PlayerID;
         if (statusConnection != null)
         {
             statusConnection(connected);
         }
     }
     catch
     {
     }
 }
Beispiel #7
0
        /// <summary>
        /// A player was created
        /// </summary>
        private void PlayerCreated(object sender, PlayerCreatedEventArgs e)
        {
            // Get the PlayerInformation and store it
            PlayerInformation peerInfo = peerObject.GetPeerInformation(e.Message.PlayerID);
            Players           oPlayer  = new Players(e.Message.PlayerID, peerInfo.Name);

            // We lock the data here since it is shared across multiple threads.
            lock (playerList)
            {
                playerList.Add(oPlayer);
                // Update our number of players and our button
                lblUsers.Text = playerList.Count.ToString();
            }
            // Save this player id if it's ourselves
            if (peerInfo.Local)
            {
                localPlayerId = e.Message.PlayerID;
            }
        }
Beispiel #8
0
    //  These routines handle the communication between the game peers.


    private void PlayerCreated(object sender, PlayerCreatedEventArgs dpMessage)
    {
        // Get the PlayerInformation and store it
        int playerID              = dpMessage.Message.PlayerID;
        PlayerInformation dpPeer  = peerObject.GetPeerInformation(playerID);
        Players           oPlayer = new Players(playerID, dpPeer.Name.ToUpper(), true);

        // Save this player id if it's ourselves
        if (dpPeer.Local)
        {
            localPlayerID = dpMessage.Message.PlayerID;
        }
        else
        {
            // We lock the data here since it is shared across multiple threads.
            lock (this) {
                remotePlayer = oPlayer;
            }
            game.RemotePlayerJoined(oPlayer.Name);
        }
    }
Beispiel #9
0
        public void PlayerCreated(object sender, PlayerCreatedEventArgs pcea)
        {
            Peer peer     = (Peer)sender;
            int  playerID = pcea.Message.PlayerID;
            PlayerInformation playerInfo = peer.GetPeerInformation(playerID);


            if (playerInfo.Local)
            {
                ID   = playerID;
                Name = playerInfo.Name;
            }
            else
            {
                RemotePlayer newPlayer = new RemotePlayer(playerID, playerInfo.Name);
                lock (otherPlayers)
                {
                    otherPlayers.Add(playerID, newPlayer);
                }
            }
        }
 //  These routines handle the communication between the game peers.
 private void PlayerCreated(object sender, PlayerCreatedEventArgs dpMessage)
 {
     // Get the PlayerInformation and store it
     int playerID = dpMessage.Message.PlayerID;
     PlayerInformation dpPeer = peerObject.GetPeerInformation(playerID);
     Players oPlayer = new Players(playerID, dpPeer.Name.ToUpper(), true);
     // Save this player id if it's ourselves
     if (dpPeer.Local)
         localPlayerID = dpMessage.Message.PlayerID;
     else
     {
         // We lock the data here since it is shared across multiple threads.
         lock (this)
         {
             remotePlayer = oPlayer;
         }
         game.RemotePlayerJoined(oPlayer.Name);
     }
 }
 private void peer_PlayerCreated(object sender, PlayerCreatedEventArgs e)
 {
     PlayerInformation peerInfo = peer.GetPeerInformation(e.Message.PlayerID);
     //Players oPlayer = new Players(e.Message.PlayerID,peerInfo.Name);
     // We lock the data here since it is shared across multiple threads.
     lock(playerList)
     {
         playerList[e.Message.PlayerID] = peerInfo;
     }
     if (peerInfo.Local)
     {
         localPlayerId = e.Message.PlayerID;
     }
     if(PlayerChanged != null)
     {
         PlayerChanged(this);
     }
 }
        public void PlayerCreated(object sender, PlayerCreatedEventArgs pcea)
        {
            Peer peer = (Peer) sender;
            int playerID = pcea.Message.PlayerID;
            PlayerInformation playerInfo = peer.GetPeerInformation(playerID);

            // See if the player that was just created is us
            if (playerInfo.Local) {
                localPlayer.ID = playerID;
                localPlayer.Name = playerInfo.Name;
            }
                // If not, create a remote player
            else {
                Ship newShip = new Ship(this);
                newShip.HostName = playerInfo.Name.ToUpper();
                newShip.State = (int)ShipState.Normal;
                newShip.ScreenBounds = this.windowBounds;
                RemotePlayer newPlayer = new RemotePlayer(playerID, playerInfo.Name, newShip);
                lock (otherPlayers) {
                    otherPlayers.Add(playerID, newPlayer);
                }
            }
        }
Beispiel #13
0
        private void onPlayerCreated(object sender, PlayerCreatedEventArgs e)
        {
            if (serverId == 0)
            {
                // this is not a real player, just the server starting
                serverId = e.Message.PlayerID;
                return;
            }
            else if (server.Groups.Count == 0)
            {
                // this is the first player to connect, therefore it becomes the hosting player
                hostingPlayerId = e.Message.PlayerID;
            }
            else
            {
                // add this player to all existing groups of "other players"
                foreach (int groupId in server.Groups)
                {
                    server.AddPlayerToGroup(groupId, e.Message.PlayerID, 0);
                }
                // send a notification to the NAT traversal server
                if (natTraversalSession.Enabled)
                {
                    using (Address playerAddress = server.GetClientAddress(e.Message.PlayerID)) {
                        string playerIpAsString = playerAddress.GetComponentString(Address.KeyHostname);
                        Regex  ipAddressRegex   = new Regex(@"^(?<1>\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})", RegexOptions.Singleline);
                        Match  ipAddressMatch   = ipAddressRegex.Match(playerIpAsString);
                        if (ipAddressMatch.Success)
                        {
                            IPAddress playerIp   = IPAddress.Parse(ipAddressMatch.Groups[1].Value);
                            int       playerPort = playerAddress.GetComponentInteger(Address.KeyPort);
                            NatResolver.NotifyPlayerHasJoined(natTraversalSession, playerIp, playerPort);
                        }
                    }
                }
            }

            // link the newly created player's context to the new "other players" group
            PlayerContext playerAndGroupContext = new PlayerContext();

            playerAndGroupContext.AllOtherPlayersGroupId = e.Message.PlayerID;                  // to be passed to onGroupCreated
            e.Message.PlayerContext = playerAndGroupContext;

            // create a new "other players" group for this player
            server.CreateGroup(new GroupInformation(), SyncFlags.CreateGroup, playerAndGroupContext, null);

            // add all players except the owner to this "other players" group
            foreach (int playerId in server.Players)
            {
                if (playerId != e.Message.PlayerID && playerId != serverId)
                {
                    server.AddPlayerToGroup(playerAndGroupContext.AllOtherPlayersGroupId, playerId, 0);
                }
            }

            // notify host
            if (e.Message.PlayerID != hostingPlayerId)
            {
                using (NetworkPacket packet = new NetworkPacket(5)) {
                    packet.Write((byte)ReservedMessageType.PlayerWantsToJoin);
                    packet.Write(e.Message.PlayerID);
                    server.SendTo(hostingPlayerId, packet, 0, SendFlags.Guaranteed | SendFlags.Coalesce | SendFlags.PriorityHigh);
                }
            }
        }