Beispiel #1
0
        public PlayerServer CreateNewPlayer()
        {
            //Assign id based on the next spot in the gameObjectDict.
            int id = gameObjectDict.Count();

            //Create two players, one to send as an active player to client. Other to keep track of on server.
            PlayerServer newPlayer = matchHandler.AddPlayer();

            newPlayer.Register();
            playerServerList.Add(newPlayer);

            //Create the active player with the same id as the newPlayer.
            PlayerServer newActivePlayer = new PlayerServer(newPlayer.Team)
            {
                ObjectType = ObjectType.ACTIVE_PLAYER,
                Id         = newPlayer.Id
            };

            newActivePlayer.Transform.Position = newPlayer.Transform.Position;

            CreatePlayerPacket objPacket = (CreatePlayerPacket)ServerPacketFactory.NewCreatePacket(newPlayer);

            // Sending this new packet before the new client joins.
            networkServer.SendAll(PacketUtil.Serialize(objPacket));

            return(newActivePlayer);
        }
Beispiel #2
0
        /// <summary>
        /// Sends all the game objects that exist within the game world to
        /// a client
        /// </summary>
        /// <param name="clientSocket">
        /// The client to send all the game objects in the world to
        /// </param>
        private void SendWorldToClient(Socket clientSocket)
        {
            List <byte>             allWorldPackets = new List <byte>();
            List <GameObjectServer> world           = GameServer.instance.GetGameObjectList();

            foreach (GameObjectServer val in world)
            {
                BasePacket packetToSend = ServerPacketFactory.NewCreatePacket(val);
                allWorldPackets.AddRange(PacketUtil.Serialize(packetToSend));
            }

            clientSocket.Send(allWorldPackets.ToArray());
        }
Beispiel #3
0
        /// <summary>
        /// Creates a new player in the game, sends it out to all the clients,
        /// and then sends that active player to the clientSocket that is
        /// specified
        /// </summary>
        /// <param name="clientSocket">
        /// The socket that needs an active player
        /// </param>
        private void ProcessNewPlayer(Socket clientSocket)
        {
            PlayerServer player = GameServer.instance.CreateNewPlayer();

            //Associate player's id with with the socket.
            playerDictionary.Add(clientSocket, player.Id);

            BasePacket createPlayPack = ServerPacketFactory.NewCreatePacket(player);

            // Create createObjectPacket, send to client
            byte[] data = PacketUtil.Serialize(createPlayPack);
            Send(clientSocket, data);
            MatchStartPacket informStart =
                new MatchStartPacket(MatchHandler.instance.GetMatch().GetTimeElapsed().Milliseconds);

            Send(clientSocket, PacketUtil.Serialize(informStart));
        }