Exemplo n.º 1
0
        public CreateJoinRoom()
        {
            var response = new ChannelResponse().Get(new Error()
            {
                ErrorCode = (int)ErrorCode.UnsupportedMethod
            });

            this.Post[$"/api/{Channel}"] = _ => {
                var createJoinRoomArgs   = Serializer.Deserialize <CreateJoinRoomArgs>(this.Request.Body);
                var createJoinRoomOutput = new CreateJoinRoomOutput();

                var playerToken = PlayerToken.Decode(this.Request.Headers["playertoken"].FirstOrDefault());
                switch (playerToken.State)
                {
                case PlayerTokenState.Invalid: return(new ChannelResponse().Get(new Error()
                    {
                        ErrorCode = (int)ErrorCode.InternalError, Message = "The specified PlayerToken is invalid."
                    }));

                case PlayerTokenState.Expired: return(new ChannelResponse().Get(new Error()
                    {
                        ErrorCode = (int)ErrorCode.InternalError, Message = "The specified PlayerToken has expired."
                    }));
                }

                createJoinRoomOutput.JoinKey   = new JoinKey(playerToken.ConnectUserId, createJoinRoomArgs.ServerType, createJoinRoomArgs.RoomId).Encode();
                createJoinRoomOutput.Endpoints = new[] { new ServerEndpoint()
                                                         {
                                                             Address = "127.0.0.1", Port = 8184
                                                         } };

                return(new ChannelResponse().Get(createJoinRoomOutput, this.Request.Headers["playertoken"].First()));
            };
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a multiplayer room (if it doesn't exists already), and joins it.
        /// </summary>
        /// <param name="roomId">The ID of the room you wish to (create and then) join.</param>
        /// <param name="serverType">If the room doesn't exists: The name of the room type you wish to run the room as. This value should match one of the 'RoomType(...)' attributes of your uploaded code. A room type of 'bounce' is always available.</param>
        /// <param name="visible">If the room doesn't exists: Determines (upon creation) if the room should be visible when listing rooms with GetRooms.</param>
        /// <param name="roomData">If the room doesn't exists: The data to initialize the room with (upon creation).</param>
        /// <param name="joinData">Data to send to the room with additional information about the join.</param>
        /// <returns>A new instance of Connection if connecting to the room was successful.</returns>
        public Connection CreateJoinRoom(string roomId, string serverType, bool visible, Dictionary <string, string> roomData, Dictionary <string, string> joinData)
        {
            var createJoinRoomArg = new CreateJoinRoomArgs {
                RoomId = roomId, ServerType = serverType, Visible = visible, RoomData = Converter.Convert(roomData), JoinData = Converter.Convert(joinData), IsDevRoom = DevServer != null
            };
            CreateJoinRoomOutput createJoinRoomOutput = _channel.Request <CreateJoinRoomArgs, CreateJoinRoomOutput, PlayerIOError>(27, createJoinRoomArg);
            ServerEndpoint       devServer            = DevServer;
            ServerEndpoint       serverEndpoint       = devServer;

            if (devServer == null)
            {
                serverEndpoint = Converter.Convert(createJoinRoomOutput.Endpoints[0])
                ;
            }
            return(new Connection(serverEndpoint, createJoinRoomOutput.JoinKey));
        }