Custom Module failing in situations:

Post here your questions about Actionscript and Java server side extensions development.

Moderators: Lapo, Bax

Post Reply
stelarfox
Posts: 34
Joined: 06 Aug 2021, 14:33
Location: Argentina, BsAs

Custom Module failing in situations:

Post by stelarfox »

Ok i am in windows and i am using stand alone version to test. (so if this fails in this mode just is that)

I did what is said in this page :
https://docs2x.smartfoxserver.com/Getti ... s#appendix
but it simply does not work.
I have everything in the corresponding folder (in SmartFoxServer_2X\SFS2X\extensions\__lib__) what i called KekeCustomModule.jar which has the class named : KekeDynamicConstantsManagerReqHandler.java and the important part is this:

Code: Select all

package KekeCustomModule;

import com.smartfoxserver.v2.admin.handlers.requests.BaseAdminModuleReqHandler;
import com.smartfoxserver.v2.annotations.Instantiation;
import com.smartfoxserver.v2.annotations.Instantiation.InstantiationMode;
import com.smartfoxserver.v2.annotations.MultiHandler;
import com.smartfoxserver.v2.entities.User;
import com.smartfoxserver.v2.entities.data.ISFSObject;
import com.smartfoxserver.v2.extensions.SFSExtension;

@MultiHandler
@Instantiation(InstantiationMode.SINGLE_INSTANCE)
public class KekeDynamicConstantsManagerReqHandler extends BaseAdminModuleReqHandler
{
    public static final String MODULE_ID = "KekeDynamicConstantsManager";
    private static final String COMMANDS_PREFIX = "KPDCM_JS";
 
    public KekeDynamicConstantsManagerReqHandler()
    {
        super(COMMANDS_PREFIX, MODULE_ID);
    }
   
    @Override
    protected void handleAdminRequest(User sender, ISFSObject params)
    {
        trace("KekeDynamicConstantsConsoleManager: " + sender.getName() + "," + params.toJson());
.....

Then i have this line in the admintool.xml:

Code: Select all

      <module id="KekeDynamicConstantsManager" name="Keke Dynamic Constants Manager" description="Keke Dynamic Constants Config Manager auto generated" className="KekeCustomModule.KekeDynamicConstantsManagerReqHandler"/>


And the following 2 files in : SmartFoxServer_2X\SFS2X\www\ROOT\admin\modules\keke-dynamic-constants-manager.html
and : SmartFoxServer_2X\SFS2X\www\ROOT\admin\assets\js\custom-modules

with the html code :

Code: Select all

<style>
    keke-dynamic-constants-manager-module {
        padding: 1rem;
    }

    .kpdcm-output {
        padding: 1rem;
        margin-top: 1rem;
        background-color: #ddd;
        border-radius: .5rem;
    }

    .kpdcm-button {
        padding: 1rem;
        margin-top: 1rem;
        background-color: #ddd;
        border-radius: .2rem;
    }
</style>
<keke-dynamic-constants-manager-module class='module'>
    <div>
        <h2>keke-dynamic-constants-manager</h2>
        <label for="kpdcm-PROGRAM_PATH">Program Path : </label>
        <input type="text" id="kpdcm-PROGRAM_PATH" name="kpdcm-PROGRAM_PATH"><br>
        <label for="kpdcm-MAIN_DB">Main Db : </label>
        <input type="text" id="kpdcm-MAIN_DB" name="kpdcm-MAIN_DB"><br>
        <label for="kpdcm-ADD_DB">Add Db : </label>
        <input type="text" id="kpdcm-ADD_DB" name="kpdcm-ADD_DB"><br>
        <input type="checkbox" id="kpdcm-debug" name="kpdcm-debug" />       
        <label for="kpdcm-debug">debug : </label><br>
        <input type="checkbox" id="kpdcm-roomSaveToDb" name="kpdcm-roomSaveToDb" />       
        <label for="kpdcm-roomSaveToDb">roomsavetodb : </label><br>
        <label for="kpdcm-USER_GIFT_GOLD">User Gift Gold : </label>
        <input type="number" id="kpdcm-USER_GIFT_GOLD" name="kpdcm-USER_GIFT_GOLD"><br>
        <label for="kpdcm-CFG_EMAIL_FROM">Cfg Email From : </label>
        <input type="text" id="kpdcm-CFG_EMAIL_FROM" name="kpdcm-CFG_EMAIL_FROM"><br>
        <label for="kpdcm-INVITATION_TIMEOUT">Invitation Timeout : </label>
        <input type="number" id="kpdcm-INVITATION_TIMEOUT" name="kpdcm-INVITATION_TIMEOUT"><br>
        <label for="kpdcm-INVITATION_TIMEOUT_MILI">Invitation Timeout Mili : </label>
        <input type="number" id="kpdcm-INVITATION_TIMEOUT_MILI" name="kpdcm-INVITATION_TIMEOUT_MILI"><br>
        <label for="kpdcm-ELO_MIN">Elo Min : </label>
        <input type="number" id="kpdcm-ELO_MIN" name="kpdcm-ELO_MIN"><br>
        <label for="kpdcm-ELO_DEFAULT">Elo Default : </label>
        <input type="number" id="kpdcm-ELO_DEFAULT" name="kpdcm-ELO_DEFAULT"><br>
        <label for="kpdcm-ELO_MAX">Elo Max : </label>
        <input type="number" id="kpdcm-ELO_MAX" name="kpdcm-ELO_MAX"><br>
        <label for="kpdcm-ELO_EASY">Elo Easy : </label>
        <input type="number" id="kpdcm-ELO_EASY" name="kpdcm-ELO_EASY"><br>
        <label for="kpdcm-ELO_MEDIUM">Elo Medium : </label>
        <input type="number" id="kpdcm-ELO_MEDIUM" name="kpdcm-ELO_MEDIUM"><br>
        <label for="kpdcm-ELO_MATCH_RANGE">Elo Match Range : </label>
        <input type="number" id="kpdcm-ELO_MATCH_RANGE" name="kpdcm-ELO_MATCH_RANGE"><br>
        <label for="kpdcm-ELO_EASY_K">Elo Easy K : </label>
        <input type="number" id="kpdcm-ELO_EASY_K" name="kpdcm-ELO_EASY_K"><br>
        <label for="kpdcm-MEDIUM_K">Medium K : </label>
        <input type="number" id="kpdcm-MEDIUM_K" name="kpdcm-MEDIUM_K"><br>
        <label for="kpdcm-ELO_HARD_K">Elo Hard K : </label>
        <input type="number" id="kpdcm-ELO_HARD_K" name="kpdcm-ELO_HARD_K"><br>
        <label for="kpdcm-AVATAR_DEFAULT">Avatar Default : </label>
        <input type="text" id="kpdcm-AVATAR_DEFAULT" name="kpdcm-AVATAR_DEFAULT"><br>
        <label for="kpdcm-COINS_WIN_GAME">Coins Win Game : </label>
        <input type="number" id="kpdcm-COINS_WIN_GAME" name="kpdcm-COINS_WIN_GAME"><br>
        <label for="kpdcm-COINS_TIED">Coins Tied : </label>
        <input type="number" id="kpdcm-COINS_TIED" name="kpdcm-COINS_TIED"><br>
        <label for="kpdcm-COINS_LOST">Coins Lost : </label>
        <input type="number" id="kpdcm-COINS_LOST" name="kpdcm-COINS_LOST"><br>
        <button id="kpdcm-SaveDataToKekeProd" type="button" class="kpdcm-button">Save Constants Change to KekeProd</button>
    </div>
    <div id="kpdcm-outputArea" class="kpdcm-output">Click on a button.</div>
</keke-dynamic-constants-manager-module>


and the java code:

Code: Select all

export default class KekeDynamicConstantsManager extends BaseModule
{
    constructor()
    {
        super('KPDCM_JS');
    }
 
    initialize(idData, shellController)
    {
        // Call super method
        super.initialize(idData, shellController);
        document.getElementById('kpdcm-SaveDataToKekeProd').addEventListener('click', () => this.OnSend());
        document.getElementById('kpdcm-outputArea').innerHTML = "Loading please wait!";
        params.putUtfString("extensionName", "DynamicConstants");
        this.sendExtensionRequest("Retrieve");
    }
 
    destroy()
    {
        // Call super method
        super.destroy();
    }
 
    LoadFromParams(data) {
        document.getElementById('kpdcm-PROGRAM_PATH').value = data.getUtfString('PROGRAM_PATH');
        document.getElementById('kpdcm-MAIN_DB').value = data.getUtfString('MAIN_DB');
        document.getElementById('kpdcm-ADD_DB').value = data.getUtfString('ADD_DB');
        document.getElementById('kpdcm-debug').checked = data.getBool('debug');
        document.getElementById('kpdcm-roomSaveToDb').checked = data.getBool('roomSaveToDb');
        document.getElementById('kpdcm-USER_GIFT_GOLD').valueAsNumber = data.getInt('USER_GIFT_GOLD');
        document.getElementById('kpdcm-CFG_EMAIL_FROM').value = data.getUtfString('CFG_EMAIL_FROM');
        document.getElementById('kpdcm-INVITATION_TIMEOUT').valueAsNumber = data.getInt('INVITATION_TIMEOUT');
        document.getElementById('kpdcm-INVITATION_TIMEOUT_MILI').valueAsNumber = data.getLong('INVITATION_TIMEOUT_MILI');
        document.getElementById('kpdcm-ELO_MIN').valueAsNumber = data.getInt('ELO_MIN');
        document.getElementById('kpdcm-ELO_DEFAULT').valueAsNumber = data.getInt('ELO_DEFAULT');
        document.getElementById('kpdcm-ELO_MAX').valueAsNumber = data.getInt('ELO_MAX');
        document.getElementById('kpdcm-ELO_EASY').valueAsNumber = data.getInt('ELO_EASY');
        document.getElementById('kpdcm-ELO_MEDIUM').valueAsNumber = data.getInt('ELO_MEDIUM');
        document.getElementById('kpdcm-ELO_MATCH_RANGE').valueAsNumber = data.getInt('ELO_MATCH_RANGE');
        document.getElementById('kpdcm-ELO_EASY_K').valueAsNumber = data.getInt('ELO_EASY_K');
        document.getElementById('kpdcm-MEDIUM_K').valueAsNumber = data.getInt('MEDIUM_K');
        document.getElementById('kpdcm-ELO_HARD_K').valueAsNumber = data.getInt('ELO_HARD_K');
        document.getElementById('kpdcm-AVATAR_DEFAULT').value = data.getUtfString('AVATAR_DEFAULT');
        document.getElementById('kpdcm-COINS_WIN_GAME').valueAsNumber = data.getInt('COINS_WIN_GAME');
        document.getElementById('kpdcm-COINS_TIED').valueAsNumber = data.getInt('COINS_TIED');
        document.getElementById('kpdcm-COINS_LOST').valueAsNumber = data.getInt('COINS_LOST');
    }
 
    onExtensionCommand(cmd, data)
    {
        if (cmd=="DataRetrieved") {
            this.LoadFromParams(data);
            document.getElementById('kpdcm-outputArea').innerHTML = 'Received';
        }
        else {
            let showOutput= 'Saved without errors!';
            if (data!=null) {
                if (data.containsKey('error'))
                showOutput = 'Errors:' + data.getUtfString('error');
            }
            document.getElementById('kpdcm-outputArea').innerHTML = showOutput;
        }
    }
    OnSend() {
        const params = new SFS2X.SFSObject();
        auxStr=document.getElementById('kpdcm-PROGRAM_PATH').value;
        if (auxStr !== null)
            params.putUtfString('PROGRAM_PATH', auxStr);
        auxStr=document.getElementById('kpdcm-MAIN_DB').value;
        if (auxStr !== null)
            params.putUtfString('MAIN_DB', auxStr);
        auxStr=document.getElementById('kpdcm-ADD_DB').value;
        if (auxStr !== null)
            params.putUtfString('ADD_DB', auxStr);
        auxBool = document.getElementById('kpdcm-debug').checked;
        if (auxBool !== null)
            params.putBool('debug', auxBool);
        auxBool = document.getElementById('kpdcm-roomSaveToDb').checked;
        if (auxBool !== null)
            params.putBool('roomSaveToDb', auxBool);
        auxNumber = document.getElementById('kpdcm-USER_GIFT_GOLD').valueAsNumber;
        if (auxNumber !== null)
            params.putInt('USER_GIFT_GOLD', auxNumber);
        auxStr=document.getElementById('kpdcm-CFG_EMAIL_FROM').value;
        if (auxStr !== null)
            params.putUtfString('CFG_EMAIL_FROM', auxStr);
        auxNumber = document.getElementById('kpdcm-INVITATION_TIMEOUT').valueAsNumber;
        if (auxNumber !== null)
            params.putInt('INVITATION_TIMEOUT', auxNumber);
        auxNumber = document.getElementById('kpdcm-INVITATION_TIMEOUT_MILI').valueAsNumber;
        if (auxNumber !== null)
            params.putLong('INVITATION_TIMEOUT_MILI', auxNumber);
        auxNumber = document.getElementById('kpdcm-ELO_MIN').valueAsNumber;
        if (auxNumber !== null)
            params.putInt('ELO_MIN', auxNumber);
        auxNumber = document.getElementById('kpdcm-ELO_DEFAULT').valueAsNumber;
        if (auxNumber !== null)
            params.putInt('ELO_DEFAULT', auxNumber);
        auxNumber = document.getElementById('kpdcm-ELO_MAX').valueAsNumber;
        if (auxNumber !== null)
            params.putInt('ELO_MAX', auxNumber);
        auxNumber = document.getElementById('kpdcm-ELO_EASY').valueAsNumber;
        if (auxNumber !== null)
            params.putInt('ELO_EASY', auxNumber);
        auxNumber = document.getElementById('kpdcm-ELO_MEDIUM').valueAsNumber;
        if (auxNumber !== null)
            params.putInt('ELO_MEDIUM', auxNumber);
        auxNumber = document.getElementById('kpdcm-ELO_MATCH_RANGE').valueAsNumber;
        if (auxNumber !== null)
            params.putInt('ELO_MATCH_RANGE', auxNumber);
        auxNumber = document.getElementById('kpdcm-ELO_EASY_K').valueAsNumber;
        if (auxNumber !== null)
            params.putInt('ELO_EASY_K', auxNumber);
        auxNumber = document.getElementById('kpdcm-MEDIUM_K').valueAsNumber;
        if (auxNumber !== null)
            params.putInt('MEDIUM_K', auxNumber);
        auxNumber = document.getElementById('kpdcm-ELO_HARD_K').valueAsNumber;
        if (auxNumber !== null)
            params.putInt('ELO_HARD_K', auxNumber);
        auxStr=document.getElementById('kpdcm-AVATAR_DEFAULT').value;
        if (auxStr !== null)
            params.putUtfString('AVATAR_DEFAULT', auxStr);
        auxNumber = document.getElementById('kpdcm-COINS_WIN_GAME').valueAsNumber;
        if (auxNumber !== null)
            params.putInt('COINS_WIN_GAME', auxNumber);
        auxNumber = document.getElementById('kpdcm-COINS_TIED').valueAsNumber;
        if (auxNumber !== null)
            params.putInt('COINS_TIED', auxNumber);
        auxNumber = document.getElementById('kpdcm-COINS_LOST').valueAsNumber;
        if (auxNumber !== null)
            params.putInt('COINS_LOST', auxNumber);
        params.putUtfString("extensionName", "DynamicConstants");
        this.sendExtensionRequest("UpdateConstants", params);
        document.getElementById('kpdcm-outputArea').innerHTML = 'Processing...';
    }
}


And my problem is this : "Keke Dynamic Constants Manager custom module's controller (js) couldn't be loaded."
And cannot figure out what the problem is.
Things I check "KekeDynamicConstantsManager" is the id and keke-dynamic-constants-manager-module is set as name, so not understanding the problem

Thanks in advance.
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Custom Module failing in situations:

Post by Bax »

Hello. Before digging into your code, we have to ask if you tested the custom module example linked in the documentation page.
If it works, it can be a good starting point to understand why the JavaScript controller of your module can't be loaded.
Paolo Bax
The SmartFoxServer Team
stelarfox
Posts: 34
Joined: 06 Aug 2021, 14:33
Location: Argentina, BsAs

Re: Custom Module failing in situations:

Post by stelarfox »

The example works, mine does not and as far as i can notice i am following it to perfectly.
In fact i was able to run part of it using F12 and placing a breakpoint in the JS, and I noticed is manages to get into the constructor, It goes inside the Supper and out, but when the constructor finishes, it crashed there into jQuery, and ends up saying the error i said.
So it looks as if the library were not working but i do not manage to understands why, unless the problem is name too long. (but will that make sense?)
stelarfox
Posts: 34
Joined: 06 Aug 2021, 14:33
Location: Argentina, BsAs

Re: Custom Module failing in situations:

Post by stelarfox »

Found the error, if the javascript has errors in any other line, it may fail and say that. not just the constructor. Weird because to give that error should have actually "Entered" the place and it had a debug to stop it before the actual error but may what happen is that because of the syntax error i had, the entire method was not found and then crashed there.
So you know just "remove parts of the code" until it works and then you find the error. (not nice but is as it works)
Thanks, I mean when you explained to check the original and it worked out, mean the error was somehow there.
User avatar
Bax
Site Admin
Posts: 4626
Joined: 29 Mar 2005, 09:50
Location: Italy
Contact:

Re: Custom Module failing in situations:

Post by Bax »

Glad you fixed it.
Out of curiosity, what is the purpose of your custom module?
Paolo Bax
The SmartFoxServer Team
Post Reply