Beispiel #1
0
        private MainMessage RoomEnter(ulong msgId, ulong clientId, RoomEnter roomEnter)
        {
            _log.Debug("In RoomEnter method.");
            int roomId = (int)roomEnter.RoomId;

            if (roomId >= _roomList.Count || _roomList[roomId] == null)
            {
                return(ISystemService.CreateErrorMessage(msgId, 0, 0, "There is no such room with this ID."));
            }
            lock (_roomList[roomId])
            {
                Room room = _roomList[roomId];
                if (room.Capacity <= room.Players.Count)
                {
                    return(ISystemService.CreateErrorMessage(msgId, 0, 0, "Room is full."));
                }
                ulong?userId = _api.Services.User.GetUserIdByClientId(clientId);
                if (!userId.HasValue)
                {
                    return(ISystemService.CreateErrorMessage(msgId, 0, 0, "Unable to match client ID to any user."));
                }
                room.Players.Add(userId.Value);
                room.LastActivity        = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();
                _user2Room[userId.Value] = (uint?)roomId;
                OnUserConnected(userId.Value, room.Id);
                _log.Info($"User with id '{userId.Value}' entered room '{room.Name}'.");
                MainMessage response = new MainMessage();
                response.RoomMsg            = new RoomMsg();
                response.RoomMsg.RoomDetail = room.ToNetworkModel();
                return(response);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Connects to a Steam Lobby then kicks off connection to the lobby owner's SteamId
        /// </summary>
        /// <param name="lobbyToJoin">The <see cref="Steamworks.Data.Lobby"/> to join</param>
        /// <param name="pendCreates">Set the NetWorker::PendCreates to true</param>
        private async void ConnectToLobbyAsync(Steamworks.Data.Lobby lobbyToJoin, bool pendCreates)
        {
            RoomEnter roomEnter = await lobbyToJoin.Join();

            if (roomEnter != RoomEnter.Success)
            {
                return;
            }
            Lobby = lobbyToJoin;
            Connect(Lobby.Owner.Id, pendCreates);
        }
    /// <summary>
    /// Connect to the selected steam lobby
    /// On successful connection, starts a new FacepunchP2PClient for connection to the lobby owner's FacepunchP2PServer
    /// </summary>
    private async Task ConnectToLobby()
    {
        RoomEnter roomEnter = await lobbyToJoin.Join();

        if (roomEnter != RoomEnter.Success)
        {
            BMSLog.Log("Error connecting to lobby returned: " + roomEnter.ToString());
            return;
        }

        this.lobby = lobbyToJoin;
        ConnectToServer(lobbyToJoin.Owner.Id);
    }
    private async Task JoinLobby(Steamworks.Data.Lobby lobbyToJoin)
    {
        RoomEnter roomEnter = await lobbyToJoin.Join();

        if (roomEnter != RoomEnter.Success)
        {
            BMSLog.Log("Error connecting to lobby returned: " + roomEnter.ToString());
            return;
        }
        this.lobby = lobbyToJoin;
        BMSLog.Log("Connected to lobby, owner.Id = " + lobbyToJoin.Owner.Id.Value);
        ConnectToHost(lobbyToJoin.Owner.Id, null);
    }