|
|
|
|
@ -28,6 +28,8 @@
|
|
|
|
|
#include "log.h"
|
|
|
|
|
#include "AmUtils.h"
|
|
|
|
|
#include <math.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <time.h>
|
|
|
|
|
|
|
|
|
|
#include "DSMSession.h"
|
|
|
|
|
#include "AmSession.h"
|
|
|
|
|
@ -59,6 +61,8 @@ DSMAction* SCUtilsModule::getAction(const string& from_str) {
|
|
|
|
|
DEF_CMD("utils.playCountLeft", SCUPlayCountLeftAction);
|
|
|
|
|
DEF_CMD("utils.getNewId", SCGetNewIdAction);
|
|
|
|
|
DEF_CMD("utils.spell", SCUSpellAction);
|
|
|
|
|
DEF_CMD("utils.rand", SCURandomAction);
|
|
|
|
|
DEF_CMD("utils.srand", SCUSRandomAction);
|
|
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
|
}
|
|
|
|
|
@ -145,6 +149,27 @@ EXEC_ACTION_START(SCGetNewIdAction) {
|
|
|
|
|
sc_sess->var[d]=AmSession::getNewId();
|
|
|
|
|
} EXEC_ACTION_END;
|
|
|
|
|
|
|
|
|
|
CONST_ACTION_2P(SCURandomAction, ',', true);
|
|
|
|
|
EXEC_ACTION_START(SCURandomAction) {
|
|
|
|
|
string varname = resolveVars(par1, sess, sc_sess, event_params);
|
|
|
|
|
string modulo_str = resolveVars(par2, sess, sc_sess, event_params);
|
|
|
|
|
|
|
|
|
|
unsigned int modulo = 0;
|
|
|
|
|
if (modulo_str.length())
|
|
|
|
|
str2i(modulo_str, modulo);
|
|
|
|
|
|
|
|
|
|
if (modulo)
|
|
|
|
|
sc_sess->var[varname]=int2str(rand()%modulo);
|
|
|
|
|
else
|
|
|
|
|
sc_sess->var[varname]=int2str(rand());
|
|
|
|
|
|
|
|
|
|
DBG("Generated random $%s=%s\n", varname.c_str(), sc_sess->var[varname].c_str());
|
|
|
|
|
} EXEC_ACTION_END;
|
|
|
|
|
|
|
|
|
|
EXEC_ACTION_START(SCUSRandomAction) {
|
|
|
|
|
srand(time(0));
|
|
|
|
|
} EXEC_ACTION_END;
|
|
|
|
|
|
|
|
|
|
CONST_ACTION_2P(SCUSpellAction, ',', true);
|
|
|
|
|
EXEC_ACTION_START(SCUSpellAction) {
|
|
|
|
|
string basedir = resolveVars(par2, sess, sc_sess, event_params);
|
|
|
|
|
|