private void OnJoin(JoinPacket packet, NetPeer peer)
        {
            Debug.Log("[S] Join packet received: " + packet.UserName);

            var serverCharacter = new ServerCharacter(packet.UserName, peer, Gameconfig.StartingPoint[peer.Id]);

            _serverManager.AddCharadcter((byte)peer.Id, serverCharacter);

            //Send join accept
            var ja = new JoinAcceptPacket {
                Id = (byte)peer.Id, UserName = packet.UserName, ServerTick = _serverTick
            };

            peer.Send(WritePacket(ja), SendType.ReliableOrdered);

            // 들어온 친구한테 기존 정보 다 보내줌
            var pj = new CharacterJoinedPacket {
                UserName        = packet.UserName,
                NewCharacter    = true,
                CharacterPacket = serverCharacter.CharacterPacket,
                ServerTick      = _serverTick
            };

            _netManager.SendToAll(WritePacket(pj), SendType.ReliableOrdered, peer);

            // 이전 유저들에게 정보 다 보내줌
            pj.NewCharacter = false;
            foreach (var pair in _serverManager.Characters.Where(pair => pair.Key != (byte)peer.Id))
            {
                pj.UserName        = pair.Value._data.Name;
                pj.CharacterPacket = pair.Value.CharacterPacket;
                peer.Send(WritePacket(pj), SendType.ReliableOrdered);
            }
        }
Example #2
0
        private void OnJoinAccept(JoinAcceptPacket packet)
        {
            Debug.Log("[C] Join accept. Received player id: " + packet.Id);
            var clientPlayer = new ClientPlayer(this, _playerManager, _userName, packet.Id);
            var view         = ClientPlayerView.Create(_clientPlayerViewPrefab, clientPlayer);

            _playerManager.AddClientPlayer(clientPlayer, view);
        }
Example #3
0
        private void OnJoinAccept(JoinAcceptPacket packet)
        {
            Id = packet.Id;
            Debug.Log("[Client] OnJoinAccept : " + packet.Id);
            _lastServerTick = packet.ServerTick;
            var clientCharacter = new ClientCharacter(packet.Id, packet.UserName);

            _clientManager.AddCharadcter(packet.Id, clientCharacter);
        }
Example #4
0
        private void OnJoinReceived(JoinPacket joinPacket, NetPeer peer)
        {
            Debug.Log("[S] Join packet received: " + joinPacket.UserName);
            var player = new ServerPlayer(_playerManager, joinPacket.UserName, peer);

            _playerManager.AddPlayer(player);

            player.Spawn(new Vector2(Random.Range(-2f, 2f), Random.Range(-2f, 2f)));

            //Send join accept
            var ja = new JoinAcceptPacket {
                Id = player.Id, ServerTick = _serverTick
            };

            peer.Send(WritePacket(ja), DeliveryMethod.ReliableOrdered);

            //Send to old players info about new player
            var pj = new PlayerJoinedPacket
            {
                UserName           = joinPacket.UserName,
                NewPlayer          = true,
                InitialPlayerState = player.NetworkState,
                ServerTick         = _serverTick
            };

            _netManager.SendToAll(WritePacket(pj), DeliveryMethod.ReliableOrdered, peer);

            //Send to new player info about old players
            pj.NewPlayer = false;
            foreach (ServerPlayer otherPlayer in _playerManager)
            {
                if (otherPlayer == player)
                {
                    continue;
                }
                pj.UserName           = otherPlayer.Name;
                pj.InitialPlayerState = otherPlayer.NetworkState;
                peer.Send(WritePacket(pj), DeliveryMethod.ReliableOrdered);
            }
        }