Author Topic: Is there a way to exec music onto a dedi? + Any way to remove datablocks?  (Read 967 times)

The dedicated server in question that I want to exec new music on tends to suffer a lot of event issues on hard reset so I'd like to know if there's a way to add music like one can add addons. Thanks.
« Last Edit: October 22, 2015, 02:31:56 PM by Conan »

To add music onto a server, you have to create new datablocks. If the players on the server don't have the datablocks that you loaded in, they will crash. To do this anyways, you do transmitDatablocks(); after executing the script file. The uiname tables will not be updated until you restart the server, so you can only interact with the datablock using script and the datablocks name. There are multiple other pitfalls and downsides I can't remember right now, too.

Noone will crash and there are no downsides if you do it properly.

The code would look about like this:

Code: server.cs (20 lines)
function addNewMusicFile(%filename)
{
    %base = fileBase(%filename);
    %uiName = strreplace(%base, "_", " ");
    %varName = getSafeVariableName(%base);
    %dbName = "musicData_" @ %varName;

    //Can't dynamically create db without eval
    %command = "datablock AudioProfile(" @ %dbName @ ") {"
    @ "filename = \"" @ %filename @ "\";"
    @ "description = AudioMusicLooping3d;"
    @ "preload = true;"
    @ "uiName = \"" @ %uiName @ "\";"
    @ "};";

    eval(%command);

    //Enable for next time you start the server
    $Music__[%varName] = true;
}


After that, call these:

createUINameTable();
transmitDatablocks();


After datablocks have been transmitted, call this to update the ui:

commandToAll('Wrench_LoadMenus');

Players that don't already have the new music won't hear anything until they rejoin, though. I've no idea what happens if you run the last 2 while people are loading, might have to change it if that needs to be allowed
« Last Edit: October 22, 2015, 08:27:42 AM by Zeblote »

I've no idea what happens if you run the last 2 while people are loading, might have to change it if that needs to be allowed
I think it just freezes their loading.

Don't have to worry about people being on server/loading; right now its passworded. Thanks zeblote :D

Nice little addition to make sure it preserves the load on next reset. Probably should make a similar function for exec'ing addons.



On the other hand, is there any way to properly remove datablocks from a server with eval? I've been able to override scripts by replacing the functions with blank space, but I may need to unload datablocks like Vehicle_Ferris_Wheel and such.

You used to be able to datablock.delete() but that's blocked now. You should just be able to set the uiName to blank, then reload the ui names

If your server has any problems with restarting it might make more sense to solve these first.

You are actually restarting it (by typing quit(); and then creating a new one), right? Changing the gamemode or similar crap like I see people do only works half the time because it only removes packages and datablocks, but not variables.

If your server has any problems with restarting it might make more sense to solve these first.

You are actually restarting it (by typing quit(); and then creating a new one), right? Changing the gamemode or similar crap like I see people do only works half the time because it only removes packages and datablocks, but not variables.
server being unable to restart isn't the issue. its when we load the last autosave that we find all the complex (~>10 lines) events are missing a line or two, or maybe even 10. gets really annoying to fix every time on reset. can't be arsed to figure out a solution unless the server goes down for some reason (halloweenfest).

we haven't done much to identify what the issue may be, but magus suspects its the farlands build. i'm not so sure, since we're using vis' autosaver mod which literally iterates through every single brick and pulls out every single event, so im unsure as to why events would just suddenly disappear. said events are things like "onBotSpawn > Bot > SetWeapon > [some mask item]" or "onActivate > self > playsound > brickMove", things which aren't non-default or VCE (though that seems to break as well).

That sounds like the autosaver you're using is broken and the events are never correctly saved. Do you have an example file where events on a default brick are missing that you can post?

That sounds like the autosaver you're using is broken and the events are never correctly saved. Do you have an example file where events on a default brick are missing that you can post?
the events are correctly saved for evented bricks that have < 10 events, so its not a systematic error. the lines that disappear and number of them also seem to change occasionally, esp as the build gets bigger and more events are added.

i was planning to look into the save file and see if the events really are screwed up on save, or if they're not loading right, so i'll get back to you on that.

EDIT: so. it looks like both the autosave and the manual saves both do not save the events correctly. the worst example is one brick has over 15 events missing. know of anything that would break saving that badly?

EDIT2: figured it out. farlands bricks. go figure.
« Last Edit: October 23, 2015, 12:04:31 AM by Conan »

lol farlands breaks everything

I think it just freezes their loading.

You can prevent this as follows:

function transmitDataBlocksSafe()
{
  %count = ClientGroup.getCount();

  for (%i = 0; %i < %count; %i++) {
    %client = ClientGroup.getObject(%i);

    if (%client.hasSpawnedOnce) {
      %client.transmitDataBlocks(0);
    }
  }
}


In some special cases you might need to take extra care if a client has passed the "loading datablocks" phase but has not yet spawned when this function runs.
You could store whether or not this is the case on a per-client basis and run GameConnection::transmitDataBlocks for them when they spawn if that is the case.

That might not catch everything either, if you change a datablock while a client is currently loading datablocks then you have to call transmit again when he's done