Jump to content

Random Characters Only?


Recommended Posts

Hey fellow DST peeps!

As some might know I am the owner of all "Strictly Unprofessional" Servers.

I have one simple question: is there a mod that upon character selection only allows you to select random character (therefore makes server all-random mode)? 

I kinda wanted to use this mod to add some variety to mundane Beta servers.

Thanks for any help or pointers!

Link to comment
https://forums.kleientertainment.com/forums/topic/70716-random-characters-only/
Share on other sites

2 hours ago, artemiyME said:

I have one simple question: is there a mod that upon character selection only allows you to select random character (therefore makes server all-random mode)?

Well, since doing anything on the client side is bad for enforcing a server ruleset I won't go the obvious route of stating to change the character select widget.
From scripts/mainfunctions.lua:1265-1284::

Spoiler

local function OnUserPickedCharacter(char, skin_base, clothing_body, clothing_hand, clothing_legs, clothing_feet)
    local function doSpawn()
        TheFrontEnd:PopScreen()
        TheNet:SendSpawnRequestToServer(char, skin_base, clothing_body, clothing_hand, clothing_legs, clothing_feet)
    end

    TheFrontEnd:Fade(FADE_OUT, 1, doSpawn, nil, nil, "white")
end

function ResumeRequestLoadComplete(success)
    --If successful then don't do anything, game will automatically
    --activate and fade in once the user's player is downloaded
    if not success then
        TheNet:DeleteUserSession(TheNet:GetUserID())
        local LobbyScreen = require "screens/lobbyscreen"
        TheFrontEnd:PushScreen(LobbyScreen(Profile, OnUserPickedCharacter, false))
        TheFrontEnd:Fade(FADE_IN, 1, nil, nil, nil, "white")
        TheWorld:PushEvent("entercharacterselect")
    end
end

 

Uses TheNet:SendSpawnRequestToServer for its decision to send to the server.

This function goes into C-land of the program which does a check for valid characters and then shoots back into LUA with a check from ValidateSpawnPrefabRequest.

scripts/networking.lua:188-233::

Spoiler

function ValidateSpawnPrefabRequest(user_id, prefab_name, skin_base, clothing_body, clothing_hand, clothing_legs, clothing_feet)
    local in_mod_char_list = table.contains(MODCHARACTERLIST, prefab_name)

    local valid_chars = ExceptionArrays(DST_CHARACTERLIST, MODCHARACTEREXCEPTIONS_DST)
    local in_valid_char_list = table.contains(valid_chars, prefab_name)

    local validated_prefab = prefab_name
    local validated_skin_base = nil
    local validated_clothing_body = nil
    local validated_clothing_hand = nil
    local validated_clothing_legs = nil
    local validated_clothing_feet = nil

    if in_valid_char_list then
        if skin_base == prefab_name.."_none" then
            -- If default skin, we do not need to check
            validated_skin_base = skin_base
        elseif TheInventory:CheckClientOwnership(user_id, skin_base) then
            --check if the skin_base actually belongs to the prefab
            if table.contains( PREFAB_SKINS[prefab_name], skin_base ) and not Prefabs[skin_base].disabled then
                validated_skin_base = skin_base
            end
        end
    elseif in_mod_char_list then
        --if mod character, don't use a skin
    elseif table.getn(valid_chars) > 0 then
        validated_prefab = valid_chars[1]
    else
        validated_prefab = DST_CHARACTERLIST[1]
    end

    if clothing_body ~= "" and TheInventory:CheckClientOwnership(user_id, clothing_body) and CLOTHING[clothing_body] and not CLOTHING[clothing_body].disabled then
        validated_clothing_body = clothing_body 
    end
    if clothing_hand ~= "" and TheInventory:CheckClientOwnership(user_id, clothing_hand) and CLOTHING[clothing_hand] and not CLOTHING[clothing_hand].disabled then
        validated_clothing_hand = clothing_hand 
    end
    if clothing_legs ~= "" and TheInventory:CheckClientOwnership(user_id, clothing_legs) and CLOTHING[clothing_legs] and not CLOTHING[clothing_legs].disabled then
        validated_clothing_legs = clothing_legs 
    end
    if clothing_feet ~= "" and TheInventory:CheckClientOwnership(user_id, clothing_feet) and CLOTHING[clothing_feet] and not CLOTHING[clothing_feet].disabled then
        validated_clothing_feet = clothing_feet 
    end
	
    return validated_prefab, validated_skin_base, validated_clothing_body, validated_clothing_hand, validated_clothing_legs, validated_clothing_feet
end

 

After this is confirmed valid then in the C-side it creates the entity prefab and sends a callback method in LUA to denote the action happened called SpawnNewPlayerOnServerFromSim.

scripts/networking.lua:235-253::

Spoiler

function SpawnNewPlayerOnServerFromSim(player_guid, skin_base, clothing_body, clothing_hand, clothing_legs, clothing_feet)
    local player = Ents[player_guid]
    if player ~= nil then
        local skinner = player.components.skinner
        skinner:SetClothing(clothing_body)
        skinner:SetClothing(clothing_hand)
        skinner:SetClothing(clothing_legs)
        skinner:SetClothing(clothing_feet)
        skinner:SetSkinName(skin_base)
        skinner:SetSkinMode("normal_skin")

        if player.OnNewSpawn ~= nil then
            player:OnNewSpawn()
            player.OnNewSpawn = nil
        end
        TheWorld.components.playerspawner:SpawnAtNextLocation(TheWorld, player)
        SerializeUserSession(player, true)
    end
end

 

As you can see there's nothing the server can do in the LUA side to forbid a client from actually choosing a character if the client sends the TheNet:SendSpawnRequestToServer manually, which someone will inevitably do once they see they can go around any client-sided based approach.

 

 

@V2C Could there be an overrideable function in the LUA side so that server operators may make edits to the player prefab "request"?

It would probably be after the server log portion with 'Spawn request:' and 'Skin request:' but before the LUA call to 'ValidateSpawnPrefabRequest'.

Ideally it would be some easily hooked into function that the C-side calls to the LUA-side, such as:

function OverrideSpawnPrefabRequest(user_id, prefab_name)
    return user_id, prefab_name
end

So that way modders would be able to do a hook there for changing the prefab_name on a per-user_id basis if they so choose.

I didn't include the skin details in this overrider because the server shouldn't be able to mess with skin content- it is the client's and shouldn't be controlled by the server.

@CarlZalph thanks for your elaboration! And yes... it sucks you cant do that from forward approach of removing them. But lets try a backward approach...

Say instead of removing the icons for characters in Selecton Screen, can game automatically switch to "Random" character and after that disable/hide button links to other characters? So technically characters are still there but you cant switch to them. 

Archived

This topic is now archived and is closed to further replies.

Please be aware that the content of this thread may be outdated and no longer applicable.

×
  • Create New...