Ejemplo n.º 1
0
        private void OnClientAuthenticated(NetPeer peer, NetEventArgs args)
        {
            PacketAuth message = PacketBase.Read <PacketAuth>((NetDataReader)(args.Data));

            PlayerManager.SetIdentity(new Player(message.ID, username));
            NetEventManager.Trigger(NetEventType.Authenticated, null);
        }
Ejemplo n.º 2
0
        private void OnConnect(NetPeer peer, NetEventArgs args)
        {
            NetEventManager.Trigger(NetEventType.Connected, args);
            PacketBase message = new PacketAuth(0, username, 0);

            GameClient.CurrentState = ClientState.Connected;
            GameClient.Send(message);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Calls the disconnect procedure from the network client and triggers a disconnection event.
        /// The function iterates through every resettable component, invoking the reset method.
        /// </summary>
        public static void Disconnect()
        {
            foreach (IResettable comp in instance.gameObject.GetComponents <IResettable>())
            {
                comp.Reset();
            }
            instance.baseClient.Disconnect();
            DisconnectInfo info = new DisconnectInfo();

            info.Reason = DisconnectReason.DisconnectPeerCalled;
            NetEventManager.Trigger(NetEventType.Disconnected, new NetEventArgs(info));
        }
Ejemplo n.º 4
0
        private void OnPlayerReady(NetPeer peer, NetEventArgs args)
        {
            if (GameClient.CurrentState == ClientState.Game)
            {
                return;
            }
            PacketPlayerReady message = PacketBase.Read <PacketPlayerReady>((NetDataReader)(args.Data));
            Player            player  = null;

            if (players.TryGetValue(message.Sender, out player))
            {
                player.SetReady(message.Value);
                NetEventManager.Trigger(NetEventType.PlayerReady, args);
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Handler for "player enter" packets.
        /// </summary>
        /// <param name="peer">server</param>
        /// <param name="args">raw data containing the player packet</param>
        private void OnPlayerEnter(NetPeer peer, NetEventArgs args)
        {
            if (GameClient.CurrentState == ClientState.Game)
            {
                return;
            }

            PacketPlayerEnter message = PacketBase.Read <PacketPlayerEnter>((NetDataReader)(args.Data));

            if (message.Player.ID == identity.ID)
            {
                SetIdentity(message.Player);
            }
            Add(message.Player);
            NetEventManager.Trigger(NetEventType.PlayerEnter, args);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Handler for 'player leaving' packets.
        /// Removes the player if the game is not started yet, otherwise mark him as 'disconnected'.
        /// </summary>
        /// <param name="peer">server</param>
        /// <param name="args">wrapper around raw data containing the packet</param>
        private void OnPlayerLeave(NetPeer peer, NetEventArgs args)
        {
            PacketPlayerEnter message = PacketBase.Read <PacketPlayerEnter>((NetDataReader)(args.Data));

            if (message.Player.ID == Identity.ID)
            {
                UnityEngine.Debug.LogWarning("Dafuq, I can't leave myself!");
                return;
            }
            if (GameClient.CurrentState != ClientState.Game)
            {
                Remove(message.Player);
            }
            else
            {
                SetDisconnected(message.Player.ID);
                LockstepLogic.Instance.UpdatePlayersCount(activePlayers, message.Player.ID);
            }
            NetEventManager.Trigger(NetEventType.PlayerLeave, args);
        }
Ejemplo n.º 7
0
 private void OnReceiveGameInfo(NetPeer peer, NetEventArgs args)
 {
     //TODO deserialize game info
     NetEventManager.Trigger(NetEventType.LoggedIn, null);
     GameClient.CurrentState = ClientState.Lobby;
 }
Ejemplo n.º 8
0
 public void LeaveLobby()
 {
     NetEventManager.Trigger(NetEventType.LoggedOut, null);
     GameClient.Disconnect();
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Function called on receiving a network error.
 /// </summary>
 /// <param name="args">object containing the error code</param>
 private void OnNetworkError(NetPeer peer, NetEventArgs args)
 {
     NetEventManager.Trigger(NetEventType.NetworkError, args);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Function called when losing connection from the server.
 /// </summary>
 /// <param name="args">object containing data about the disconnection</param>
 private void OnDisconnect(NetPeer peer, NetEventArgs args)
 {
     PlayerManager.Instance.Reset();
     NetEventManager.Trigger(NetEventType.Disconnected, args);
 }