public bool TryJoinLobby(int id, string password)
        {
            var request = new WithoutLobbyRequest();
            var message = new JoinLobbyRequest();

            message.Password         = password;
            message.LobbyId          = id;
            request.JoinLobbyRequest = message;

            System.Console.WriteLine($"Joining lobby {id}");

            request.WriteDelimitedTo(stream);

            var response = JoinLobbyResponse.Parser.ParseDelimitedFrom(stream);

            if (response.LobbyInfo != null)
            {
                System.Console.WriteLine($"Successfully joined lobby: {response.LobbyInfo}");
                this.state        = Tcp_State.PeerWithinLobby;
                this.joined_lobby = response.LobbyInfo;
                return(true);
            }

            this.state = Tcp_State.WithoutLobby;
            return(false);
        }
        public bool TryCreateLobby(string password)
        {
            var request = new WithoutLobbyRequest();
            var message = new CreateLobbyRequest();

            message.Password           = password;
            message.Capacity           = 2;
            request.CreateLobbyRequest = message;

            System.Console.WriteLine($"Creating lobby {id}");

            request.WriteDelimitedTo(stream);

            var response = CreateLobbyResponse.Parser.ParseDelimitedFrom(stream);

            if (response.LobbyId != 0)
            {
                System.Console.WriteLine($"Successfully created lobby {response.LobbyId}");
                this.state        = Tcp_State.HostWithinLobby;
                this.joined_lobby = new LobbyInfo
                {
                    HostId   = id,
                    LobbyId  = response.LobbyId,
                    Capacity = message.Capacity
                };
                return(true);
            }

            this.state = Tcp_State.WithoutLobby;
            return(false);
        }
        public AddressInfoMessage GetMyAddressInfo()
        {
            if (state != Tcp_State.WithoutLobby)
            {
                throw new System.Exception("Must be without lobby to request my address");
            }
            var request = new WithoutLobbyRequest();
            var message = new MyAddressInfoRequest();

            request.MyAddressInfoRequest = message;
            request.WriteDelimitedTo(stream);
            var response = AddressInfoMessage.Parser.ParseDelimitedFrom(stream);

            return(response);
        }